Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Standard PCI Bridge Device |
| 3 | * |
| 4 | * Copyright (c) 2011 Red Hat Inc. Author: Michael S. Tsirkin <mst@redhat.com> |
| 5 | * |
| 6 | * http://www.pcisig.com/specifications/conventional/pci_to_pci_bridge_architecture/ |
| 7 | * |
| 8 | * This program is free software; you can redistribute it and/or modify |
| 9 | * it under the terms of the GNU General Public License as published by |
| 10 | * the Free Software Foundation; either version 2 of the License, or |
| 11 | * (at your option) any later version. |
| 12 | * |
| 13 | * This program is distributed in the hope that it will be useful, |
| 14 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | * GNU General Public License for more details. |
| 17 | * |
| 18 | * You should have received a copy of the GNU General Public License along |
| 19 | * with this program; if not, see <http://www.gnu.org/licenses/>. |
| 20 | */ |
| 21 | |
Peter Maydell | 97d5408 | 2016-01-26 18:17:15 +0000 | [diff] [blame] | 22 | #include "qemu/osdep.h" |
Markus Armbruster | da34e65 | 2016-03-14 09:01:28 +0100 | [diff] [blame] | 23 | #include "qapi/error.h" |
Markus Armbruster | 0b8fa32 | 2019-05-23 16:35:07 +0200 | [diff] [blame] | 24 | #include "qemu/module.h" |
Paolo Bonzini | 83c9f4c | 2013-02-04 15:40:22 +0100 | [diff] [blame] | 25 | #include "hw/pci/pci_bridge.h" |
| 26 | #include "hw/pci/pci_ids.h" |
| 27 | #include "hw/pci/msi.h" |
| 28 | #include "hw/pci/shpc.h" |
| 29 | #include "hw/pci/slotid_cap.h" |
Markus Armbruster | a27bd6c | 2019-08-12 07:23:51 +0200 | [diff] [blame] | 30 | #include "hw/qdev-properties.h" |
Paolo Bonzini | 022c62c | 2012-12-17 18:19:49 +0100 | [diff] [blame] | 31 | #include "exec/memory.h" |
Paolo Bonzini | 83c9f4c | 2013-02-04 15:40:22 +0100 | [diff] [blame] | 32 | #include "hw/pci/pci_bus.h" |
Igor Mammedov | 5d26870 | 2014-02-05 16:36:50 +0100 | [diff] [blame] | 33 | #include "hw/hotplug.h" |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 34 | |
Gerd Hoffmann | eb6c6a6 | 2015-06-18 12:17:29 +0200 | [diff] [blame] | 35 | #define TYPE_PCI_BRIDGE_DEV "pci-bridge" |
| 36 | #define TYPE_PCI_BRIDGE_SEAT_DEV "pci-bridge-seat" |
Andreas Färber | 57524e1 | 2013-07-12 19:16:46 +0200 | [diff] [blame] | 37 | #define PCI_BRIDGE_DEV(obj) \ |
| 38 | OBJECT_CHECK(PCIBridgeDev, (obj), TYPE_PCI_BRIDGE_DEV) |
| 39 | |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 40 | struct PCIBridgeDev { |
Andreas Färber | 57524e1 | 2013-07-12 19:16:46 +0200 | [diff] [blame] | 41 | /*< private >*/ |
| 42 | PCIBridge parent_obj; |
| 43 | /*< public >*/ |
| 44 | |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 45 | MemoryRegion bar; |
| 46 | uint8_t chassis_nr; |
Cao jin | 69b205b | 2016-06-20 14:13:38 +0800 | [diff] [blame] | 47 | #define PCI_BRIDGE_DEV_F_SHPC_REQ 0 |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 48 | uint32_t flags; |
Cao jin | 69b205b | 2016-06-20 14:13:38 +0800 | [diff] [blame] | 49 | |
| 50 | OnOffAuto msi; |
Jing Liu | 6755e61 | 2018-08-21 11:18:07 +0800 | [diff] [blame] | 51 | |
| 52 | /* additional resources to reserve */ |
| 53 | PCIResReserve res_reserve; |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 54 | }; |
| 55 | typedef struct PCIBridgeDev PCIBridgeDev; |
| 56 | |
Mao Zhongyi | 344475e | 2017-06-27 14:16:53 +0800 | [diff] [blame] | 57 | static void pci_bridge_dev_realize(PCIDevice *dev, Error **errp) |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 58 | { |
Andreas Färber | f055e96 | 2013-07-11 17:13:43 +0200 | [diff] [blame] | 59 | PCIBridge *br = PCI_BRIDGE(dev); |
Andreas Färber | 57524e1 | 2013-07-12 19:16:46 +0200 | [diff] [blame] | 60 | PCIBridgeDev *bridge_dev = PCI_BRIDGE_DEV(dev); |
Alex Williamson | f90c2bc | 2012-07-03 22:39:27 -0600 | [diff] [blame] | 61 | int err; |
Cao jin | 1108b2f | 2016-06-20 14:13:39 +0800 | [diff] [blame] | 62 | Error *local_err = NULL; |
Alex Williamson | f90c2bc | 2012-07-03 22:39:27 -0600 | [diff] [blame] | 63 | |
Cao jin | 9cfaa00 | 2016-01-15 10:23:32 +0800 | [diff] [blame] | 64 | pci_bridge_initfn(dev, TYPE_PCI_BUS); |
| 65 | |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 66 | if (bridge_dev->flags & (1 << PCI_BRIDGE_DEV_F_SHPC_REQ)) { |
| 67 | dev->config[PCI_INTERRUPT_PIN] = 0x1; |
| 68 | memory_region_init(&bridge_dev->bar, OBJECT(dev), "shpc-bar", |
| 69 | shpc_bar_size(dev)); |
Mao Zhongyi | 344475e | 2017-06-27 14:16:53 +0800 | [diff] [blame] | 70 | err = shpc_init(dev, &br->sec_bus, &bridge_dev->bar, 0, errp); |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 71 | if (err) { |
| 72 | goto shpc_error; |
| 73 | } |
| 74 | } else { |
| 75 | /* MSI is not applicable without SHPC */ |
Cao jin | 69b205b | 2016-06-20 14:13:38 +0800 | [diff] [blame] | 76 | bridge_dev->msi = ON_OFF_AUTO_OFF; |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 77 | } |
Cao jin | 52ea63d | 2016-06-10 17:54:23 +0800 | [diff] [blame] | 78 | |
Mao Zhongyi | 344475e | 2017-06-27 14:16:53 +0800 | [diff] [blame] | 79 | err = slotid_cap_init(dev, 0, bridge_dev->chassis_nr, 0, errp); |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 80 | if (err) { |
| 81 | goto slotid_error; |
| 82 | } |
Cao jin | 52ea63d | 2016-06-10 17:54:23 +0800 | [diff] [blame] | 83 | |
Cao jin | 1108b2f | 2016-06-20 14:13:39 +0800 | [diff] [blame] | 84 | if (bridge_dev->msi != ON_OFF_AUTO_OFF) { |
| 85 | /* it means SHPC exists, because MSI is needed by SHPC */ |
| 86 | |
| 87 | err = msi_init(dev, 0, 1, true, true, &local_err); |
| 88 | /* Any error other than -ENOTSUP(board's MSI support is broken) |
| 89 | * is a programming error */ |
| 90 | assert(!err || err == -ENOTSUP); |
| 91 | if (err && bridge_dev->msi == ON_OFF_AUTO_ON) { |
| 92 | /* Can't satisfy user's explicit msi=on request, fail */ |
| 93 | error_append_hint(&local_err, "You have to use msi=auto (default) " |
| 94 | "or msi=off with this machine type.\n"); |
Mao Zhongyi | 344475e | 2017-06-27 14:16:53 +0800 | [diff] [blame] | 95 | error_propagate(errp, local_err); |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 96 | goto msi_error; |
| 97 | } |
Cao jin | 1108b2f | 2016-06-20 14:13:39 +0800 | [diff] [blame] | 98 | assert(!local_err || bridge_dev->msi == ON_OFF_AUTO_AUTO); |
| 99 | /* With msi=auto, we fall back to MSI off silently */ |
| 100 | error_free(local_err); |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 101 | } |
Cao jin | 52ea63d | 2016-06-10 17:54:23 +0800 | [diff] [blame] | 102 | |
Jing Liu | 6755e61 | 2018-08-21 11:18:07 +0800 | [diff] [blame] | 103 | err = pci_bridge_qemu_reserve_cap_init(dev, 0, |
| 104 | bridge_dev->res_reserve, errp); |
| 105 | if (err) { |
| 106 | goto cap_error; |
| 107 | } |
| 108 | |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 109 | if (shpc_present(dev)) { |
| 110 | /* TODO: spec recommends using 64 bit prefetcheable BAR. |
| 111 | * Check whether that works well. */ |
| 112 | pci_register_bar(dev, 0, PCI_BASE_ADDRESS_SPACE_MEMORY | |
| 113 | PCI_BASE_ADDRESS_MEM_TYPE_64, &bridge_dev->bar); |
| 114 | } |
Mao Zhongyi | 344475e | 2017-06-27 14:16:53 +0800 | [diff] [blame] | 115 | return; |
Cao jin | 52ea63d | 2016-06-10 17:54:23 +0800 | [diff] [blame] | 116 | |
Jing Liu | 6755e61 | 2018-08-21 11:18:07 +0800 | [diff] [blame] | 117 | cap_error: |
| 118 | msi_uninit(dev); |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 119 | msi_error: |
| 120 | slotid_cap_cleanup(dev); |
| 121 | slotid_error: |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 122 | if (shpc_present(dev)) { |
| 123 | shpc_cleanup(dev, &bridge_dev->bar); |
| 124 | } |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 125 | shpc_error: |
Alex Williamson | f90c2bc | 2012-07-03 22:39:27 -0600 | [diff] [blame] | 126 | pci_bridge_exitfn(dev); |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 127 | } |
| 128 | |
Alex Williamson | f90c2bc | 2012-07-03 22:39:27 -0600 | [diff] [blame] | 129 | static void pci_bridge_dev_exitfn(PCIDevice *dev) |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 130 | { |
Andreas Färber | 57524e1 | 2013-07-12 19:16:46 +0200 | [diff] [blame] | 131 | PCIBridgeDev *bridge_dev = PCI_BRIDGE_DEV(dev); |
Jing Liu | 6755e61 | 2018-08-21 11:18:07 +0800 | [diff] [blame] | 132 | |
| 133 | pci_del_capability(dev, PCI_CAP_ID_VNDR, sizeof(PCIBridgeQemuCap)); |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 134 | if (msi_present(dev)) { |
| 135 | msi_uninit(dev); |
| 136 | } |
| 137 | slotid_cap_cleanup(dev); |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 138 | if (shpc_present(dev)) { |
| 139 | shpc_cleanup(dev, &bridge_dev->bar); |
| 140 | } |
Alex Williamson | f90c2bc | 2012-07-03 22:39:27 -0600 | [diff] [blame] | 141 | pci_bridge_exitfn(dev); |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 142 | } |
| 143 | |
Paolo Bonzini | 5cd5e70 | 2015-02-12 21:39:20 +0100 | [diff] [blame] | 144 | static void pci_bridge_dev_instance_finalize(Object *obj) |
| 145 | { |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 146 | /* this function is idempotent and handles (PCIDevice.shpc == NULL) */ |
Paolo Bonzini | 5cd5e70 | 2015-02-12 21:39:20 +0100 | [diff] [blame] | 147 | shpc_free(PCI_DEVICE(obj)); |
| 148 | } |
| 149 | |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 150 | static void pci_bridge_dev_write_config(PCIDevice *d, |
| 151 | uint32_t address, uint32_t val, int len) |
| 152 | { |
| 153 | pci_bridge_write_config(d, address, val, len); |
| 154 | if (msi_present(d)) { |
| 155 | msi_write_config(d, address, val, len); |
| 156 | } |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 157 | if (shpc_present(d)) { |
| 158 | shpc_cap_write_config(d, address, val, len); |
| 159 | } |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 160 | } |
| 161 | |
| 162 | static void qdev_pci_bridge_dev_reset(DeviceState *qdev) |
| 163 | { |
Andreas Färber | 57524e1 | 2013-07-12 19:16:46 +0200 | [diff] [blame] | 164 | PCIDevice *dev = PCI_DEVICE(qdev); |
Jan Kiszka | cbd2d43 | 2012-05-15 20:09:56 -0300 | [diff] [blame] | 165 | |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 166 | pci_bridge_reset(qdev); |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 167 | if (shpc_present(dev)) { |
| 168 | shpc_reset(dev); |
| 169 | } |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 170 | } |
| 171 | |
| 172 | static Property pci_bridge_dev_properties[] = { |
| 173 | /* Note: 0 is not a legal chassis number. */ |
Laszlo Ersek | 3cf0ecb | 2015-06-19 04:40:10 +0200 | [diff] [blame] | 174 | DEFINE_PROP_UINT8(PCI_BRIDGE_DEV_PROP_CHASSIS_NR, PCIBridgeDev, chassis_nr, |
| 175 | 0), |
Cao jin | 69b205b | 2016-06-20 14:13:38 +0800 | [diff] [blame] | 176 | DEFINE_PROP_ON_OFF_AUTO(PCI_BRIDGE_DEV_PROP_MSI, PCIBridgeDev, msi, |
| 177 | ON_OFF_AUTO_AUTO), |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 178 | DEFINE_PROP_BIT(PCI_BRIDGE_DEV_PROP_SHPC, PCIBridgeDev, flags, |
Marcel Apfelbaum | 2fa3566 | 2017-05-11 13:25:29 +0300 | [diff] [blame] | 179 | PCI_BRIDGE_DEV_F_SHPC_REQ, true), |
Jing Liu | 6755e61 | 2018-08-21 11:18:07 +0800 | [diff] [blame] | 180 | DEFINE_PROP_UINT32("bus-reserve", PCIBridgeDev, |
| 181 | res_reserve.bus, -1), |
| 182 | DEFINE_PROP_SIZE("io-reserve", PCIBridgeDev, |
| 183 | res_reserve.io, -1), |
| 184 | DEFINE_PROP_SIZE("mem-reserve", PCIBridgeDev, |
| 185 | res_reserve.mem_non_pref, -1), |
| 186 | DEFINE_PROP_SIZE("pref32-reserve", PCIBridgeDev, |
| 187 | res_reserve.mem_pref_32, -1), |
| 188 | DEFINE_PROP_SIZE("pref64-reserve", PCIBridgeDev, |
| 189 | res_reserve.mem_pref_64, -1), |
| 190 | |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 191 | DEFINE_PROP_END_OF_LIST(), |
| 192 | }; |
| 193 | |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 194 | static bool pci_device_shpc_present(void *opaque, int version_id) |
| 195 | { |
| 196 | PCIDevice *dev = opaque; |
| 197 | |
| 198 | return shpc_present(dev); |
| 199 | } |
| 200 | |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 201 | static const VMStateDescription pci_bridge_dev_vmstate = { |
| 202 | .name = "pci_bridge", |
Peter Xu | 9d6b9db | 2018-02-06 15:39:33 +0800 | [diff] [blame] | 203 | .priority = MIG_PRI_PCI_BUS, |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 204 | .fields = (VMStateField[]) { |
Andreas Färber | 57524e1 | 2013-07-12 19:16:46 +0200 | [diff] [blame] | 205 | VMSTATE_PCI_DEVICE(parent_obj, PCIBridge), |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 206 | SHPC_VMSTATE(shpc, PCIDevice, pci_device_shpc_present), |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 207 | VMSTATE_END_OF_LIST() |
| 208 | } |
| 209 | }; |
| 210 | |
David Hildenbrand | 62b7656 | 2018-12-12 10:16:21 +0100 | [diff] [blame] | 211 | void pci_bridge_dev_plug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, |
| 212 | Error **errp) |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 213 | { |
| 214 | PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev); |
| 215 | |
| 216 | if (!shpc_present(pci_hotplug_dev)) { |
| 217 | error_setg(errp, "standard hotplug controller has been disabled for " |
David Hildenbrand | 62b7656 | 2018-12-12 10:16:21 +0100 | [diff] [blame] | 218 | "this %s", object_get_typename(OBJECT(hotplug_dev))); |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 219 | return; |
| 220 | } |
David Hildenbrand | 851fedf | 2018-12-12 10:16:14 +0100 | [diff] [blame] | 221 | shpc_device_plug_cb(hotplug_dev, dev, errp); |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 222 | } |
| 223 | |
David Hildenbrand | 8f560cd | 2018-12-12 10:16:22 +0100 | [diff] [blame] | 224 | void pci_bridge_dev_unplug_cb(HotplugHandler *hotplug_dev, DeviceState *dev, |
| 225 | Error **errp) |
| 226 | { |
| 227 | PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev); |
| 228 | |
| 229 | g_assert(shpc_present(pci_hotplug_dev)); |
| 230 | shpc_device_unplug_cb(hotplug_dev, dev, errp); |
| 231 | } |
| 232 | |
David Hildenbrand | 62b7656 | 2018-12-12 10:16:21 +0100 | [diff] [blame] | 233 | void pci_bridge_dev_unplug_request_cb(HotplugHandler *hotplug_dev, |
| 234 | DeviceState *dev, Error **errp) |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 235 | { |
| 236 | PCIDevice *pci_hotplug_dev = PCI_DEVICE(hotplug_dev); |
| 237 | |
| 238 | if (!shpc_present(pci_hotplug_dev)) { |
| 239 | error_setg(errp, "standard hotplug controller has been disabled for " |
David Hildenbrand | 62b7656 | 2018-12-12 10:16:21 +0100 | [diff] [blame] | 240 | "this %s", object_get_typename(OBJECT(hotplug_dev))); |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 241 | return; |
| 242 | } |
David Hildenbrand | 851fedf | 2018-12-12 10:16:14 +0100 | [diff] [blame] | 243 | shpc_device_unplug_request_cb(hotplug_dev, dev, errp); |
Laszlo Ersek | 4e5c9bf | 2015-06-19 04:40:13 +0200 | [diff] [blame] | 244 | } |
| 245 | |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 246 | static void pci_bridge_dev_class_init(ObjectClass *klass, void *data) |
| 247 | { |
| 248 | DeviceClass *dc = DEVICE_CLASS(klass); |
| 249 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
Igor Mammedov | 5d26870 | 2014-02-05 16:36:50 +0100 | [diff] [blame] | 250 | HotplugHandlerClass *hc = HOTPLUG_HANDLER_CLASS(klass); |
| 251 | |
Mao Zhongyi | 344475e | 2017-06-27 14:16:53 +0800 | [diff] [blame] | 252 | k->realize = pci_bridge_dev_realize; |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 253 | k->exit = pci_bridge_dev_exitfn; |
| 254 | k->config_write = pci_bridge_dev_write_config; |
Paolo Bonzini | 5c03a25 | 2012-12-13 10:19:38 +0100 | [diff] [blame] | 255 | k->vendor_id = PCI_VENDOR_ID_REDHAT; |
| 256 | k->device_id = PCI_DEVICE_ID_REDHAT_BRIDGE; |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 257 | k->class_id = PCI_CLASS_BRIDGE_PCI; |
David Gibson | 91f4c99 | 2019-05-13 16:19:38 +1000 | [diff] [blame] | 258 | k->is_bridge = true; |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 259 | dc->desc = "Standard PCI Bridge"; |
| 260 | dc->reset = qdev_pci_bridge_dev_reset; |
| 261 | dc->props = pci_bridge_dev_properties; |
| 262 | dc->vmsd = &pci_bridge_dev_vmstate; |
Marcel Apfelbaum | 125ee0e | 2013-07-29 17:17:45 +0300 | [diff] [blame] | 263 | set_bit(DEVICE_CATEGORY_BRIDGE, dc->categories); |
David Hildenbrand | 851fedf | 2018-12-12 10:16:14 +0100 | [diff] [blame] | 264 | hc->plug = pci_bridge_dev_plug_cb; |
David Hildenbrand | 8f560cd | 2018-12-12 10:16:22 +0100 | [diff] [blame] | 265 | hc->unplug = pci_bridge_dev_unplug_cb; |
David Hildenbrand | 851fedf | 2018-12-12 10:16:14 +0100 | [diff] [blame] | 266 | hc->unplug_request = pci_bridge_dev_unplug_request_cb; |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 267 | } |
| 268 | |
Andreas Färber | 8c43a6f | 2013-01-10 16:19:07 +0100 | [diff] [blame] | 269 | static const TypeInfo pci_bridge_dev_info = { |
Paolo Bonzini | 5cd5e70 | 2015-02-12 21:39:20 +0100 | [diff] [blame] | 270 | .name = TYPE_PCI_BRIDGE_DEV, |
| 271 | .parent = TYPE_PCI_BRIDGE, |
| 272 | .instance_size = sizeof(PCIBridgeDev), |
| 273 | .class_init = pci_bridge_dev_class_init, |
| 274 | .instance_finalize = pci_bridge_dev_instance_finalize, |
Igor Mammedov | 5d26870 | 2014-02-05 16:36:50 +0100 | [diff] [blame] | 275 | .interfaces = (InterfaceInfo[]) { |
| 276 | { TYPE_HOTPLUG_HANDLER }, |
Eduardo Habkost | fd3b02c | 2017-09-27 16:56:34 -0300 | [diff] [blame] | 277 | { INTERFACE_CONVENTIONAL_PCI_DEVICE }, |
Igor Mammedov | 5d26870 | 2014-02-05 16:36:50 +0100 | [diff] [blame] | 278 | { } |
| 279 | } |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 280 | }; |
| 281 | |
Gerd Hoffmann | eb6c6a6 | 2015-06-18 12:17:29 +0200 | [diff] [blame] | 282 | /* |
| 283 | * Multiseat bridge. Same as the standard pci bridge, only with a |
| 284 | * different pci id, so we can match it easily in the guest for |
| 285 | * automagic multiseat configuration. See docs/multiseat.txt for more. |
| 286 | */ |
| 287 | static void pci_bridge_dev_seat_class_init(ObjectClass *klass, void *data) |
| 288 | { |
| 289 | DeviceClass *dc = DEVICE_CLASS(klass); |
| 290 | PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); |
| 291 | |
| 292 | k->device_id = PCI_DEVICE_ID_REDHAT_BRIDGE_SEAT; |
| 293 | dc->desc = "Standard PCI Bridge (multiseat)"; |
| 294 | } |
| 295 | |
| 296 | static const TypeInfo pci_bridge_dev_seat_info = { |
| 297 | .name = TYPE_PCI_BRIDGE_SEAT_DEV, |
| 298 | .parent = TYPE_PCI_BRIDGE_DEV, |
| 299 | .instance_size = sizeof(PCIBridgeDev), |
| 300 | .class_init = pci_bridge_dev_seat_class_init, |
| 301 | }; |
| 302 | |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 303 | static void pci_bridge_dev_register(void) |
| 304 | { |
| 305 | type_register_static(&pci_bridge_dev_info); |
Gerd Hoffmann | eb6c6a6 | 2015-06-18 12:17:29 +0200 | [diff] [blame] | 306 | type_register_static(&pci_bridge_dev_seat_info); |
Michael S. Tsirkin | 4eb812f | 2011-07-03 16:00:09 +0300 | [diff] [blame] | 307 | } |
| 308 | |
| 309 | type_init(pci_bridge_dev_register); |