2 * Generic PCI Express Root Port emulation
4 * Copyright (C) 2017 Red Hat Inc
7 * Marcel Apfelbaum <marcel@redhat.com>
9 * This work is licensed under the terms of the GNU GPL, version 2 or later.
10 * See the COPYING file in the top-level directory.
13 #include "qemu/osdep.h"
14 #include "qapi/error.h"
15 #include "hw/pci/msix.h"
16 #include "hw/pci/pcie_port.h"
18 #define TYPE_GEN_PCIE_ROOT_PORT "pcie-root-port"
20 #define GEN_PCIE_ROOT_PORT_AER_OFFSET 0x100
21 #define GEN_PCIE_ROOT_PORT_MSIX_NR_VECTOR 1
23 typedef struct GenPCIERootPort
{
31 static uint8_t gen_rp_aer_vector(const PCIDevice
*d
)
36 static int gen_rp_interrupts_init(PCIDevice
*d
, Error
**errp
)
40 rc
= msix_init_exclusive_bar(d
, GEN_PCIE_ROOT_PORT_MSIX_NR_VECTOR
, 0, errp
);
43 assert(rc
== -ENOTSUP
);
45 msix_vector_use(d
, 0);
51 static void gen_rp_interrupts_uninit(PCIDevice
*d
)
53 msix_uninit_exclusive_bar(d
);
56 static bool gen_rp_test_migrate_msix(void *opaque
, int version_id
)
58 GenPCIERootPort
*rp
= opaque
;
60 return rp
->migrate_msix
;
63 static const VMStateDescription vmstate_rp_dev
= {
64 .name
= "pcie-root-port",
66 .minimum_version_id
= 1,
67 .post_load
= pcie_cap_slot_post_load
,
68 .fields
= (VMStateField
[]) {
69 VMSTATE_PCI_DEVICE(parent_obj
.parent_obj
.parent_obj
, PCIESlot
),
70 VMSTATE_STRUCT(parent_obj
.parent_obj
.parent_obj
.exp
.aer_log
,
71 PCIESlot
, 0, vmstate_pcie_aer_log
, PCIEAERLog
),
72 VMSTATE_MSIX_TEST(parent_obj
.parent_obj
.parent_obj
.parent_obj
,
74 gen_rp_test_migrate_msix
),
79 static Property gen_rp_props
[] = {
80 DEFINE_PROP_BOOL("x-migrate-msix", GenPCIERootPort
, migrate_msix
, true),
81 DEFINE_PROP_END_OF_LIST()
84 static void gen_rp_dev_class_init(ObjectClass
*klass
, void *data
)
86 DeviceClass
*dc
= DEVICE_CLASS(klass
);
87 PCIDeviceClass
*k
= PCI_DEVICE_CLASS(klass
);
88 PCIERootPortClass
*rpc
= PCIE_ROOT_PORT_CLASS(klass
);
90 k
->vendor_id
= PCI_VENDOR_ID_REDHAT
;
91 k
->device_id
= PCI_DEVICE_ID_REDHAT_PCIE_RP
;
92 dc
->desc
= "PCI Express Root Port";
93 dc
->vmsd
= &vmstate_rp_dev
;
94 dc
->props
= gen_rp_props
;
95 rpc
->aer_vector
= gen_rp_aer_vector
;
96 rpc
->interrupts_init
= gen_rp_interrupts_init
;
97 rpc
->interrupts_uninit
= gen_rp_interrupts_uninit
;
98 rpc
->aer_offset
= GEN_PCIE_ROOT_PORT_AER_OFFSET
;
101 static const TypeInfo gen_rp_dev_info
= {
102 .name
= TYPE_GEN_PCIE_ROOT_PORT
,
103 .parent
= TYPE_PCIE_ROOT_PORT
,
104 .instance_size
= sizeof(GenPCIERootPort
),
105 .class_init
= gen_rp_dev_class_init
,
108 static void gen_rp_register_types(void)
110 type_register_static(&gen_rp_dev_info
);
112 type_init(gen_rp_register_types
)