1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21#include "hw/pci/pcie_port.h"
22
23void pcie_port_init_reg(PCIDevice *d)
24{
25
26
27 pci_set_word(d->config + PCI_STATUS, 0);
28 pci_set_word(d->config + PCI_SEC_STATUS, 0);
29
30
31 pci_set_word(d->wmask + PCI_BRIDGE_CONTROL,
32 PCI_BRIDGE_CTL_PARITY |
33 PCI_BRIDGE_CTL_ISA |
34 PCI_BRIDGE_CTL_VGA |
35 PCI_BRIDGE_CTL_SERR |
36 PCI_BRIDGE_CTL_BUS_RESET);
37}
38
39
40
41
42struct PCIEChassis {
43 uint8_t number;
44
45 QLIST_HEAD(, PCIESlot) slots;
46 QLIST_ENTRY(PCIEChassis) next;
47};
48
49static QLIST_HEAD(, PCIEChassis) chassis = QLIST_HEAD_INITIALIZER(chassis);
50
51static struct PCIEChassis *pcie_chassis_find(uint8_t chassis_number)
52{
53 struct PCIEChassis *c;
54 QLIST_FOREACH(c, &chassis, next) {
55 if (c->number == chassis_number) {
56 break;
57 }
58 }
59 return c;
60}
61
62void pcie_chassis_create(uint8_t chassis_number)
63{
64 struct PCIEChassis *c;
65 c = pcie_chassis_find(chassis_number);
66 if (c) {
67 return;
68 }
69 c = g_malloc0(sizeof(*c));
70 c->number = chassis_number;
71 QLIST_INIT(&c->slots);
72 QLIST_INSERT_HEAD(&chassis, c, next);
73}
74
75static PCIESlot *pcie_chassis_find_slot_with_chassis(struct PCIEChassis *c,
76 uint8_t slot)
77{
78 PCIESlot *s;
79 QLIST_FOREACH(s, &c->slots, next) {
80 if (s->slot == slot) {
81 break;
82 }
83 }
84 return s;
85}
86
87PCIESlot *pcie_chassis_find_slot(uint8_t chassis_number, uint16_t slot)
88{
89 struct PCIEChassis *c;
90 c = pcie_chassis_find(chassis_number);
91 if (!c) {
92 return NULL;
93 }
94 return pcie_chassis_find_slot_with_chassis(c, slot);
95}
96
97int pcie_chassis_add_slot(struct PCIESlot *slot)
98{
99 struct PCIEChassis *c;
100 c = pcie_chassis_find(slot->chassis);
101 if (!c) {
102 return -ENODEV;
103 }
104 if (pcie_chassis_find_slot_with_chassis(c, slot->slot)) {
105 return -EBUSY;
106 }
107 QLIST_INSERT_HEAD(&c->slots, slot, next);
108 return 0;
109}
110
111void pcie_chassis_del_slot(PCIESlot *s)
112{
113 QLIST_REMOVE(s, next);
114}
115