1 #include "qemu/osdep.h"
2 #include "hw/pci/slotid_cap.h"
3 #include "hw/pci/pci.h"
4 #include "qemu/error-report.h"
5 #include "qapi/error.h"
7 #define SLOTID_CAP_LENGTH 4
8 #define SLOTID_NSLOTS_SHIFT ctz32(PCI_SID_ESR_NSLOTS)
10 int slotid_cap_init(PCIDevice
*d
, int nslots
,
18 error_setg(errp
, "Bridge chassis not specified. Each bridge is required"
19 " to be assigned a unique chassis id > 0.");
22 if (nslots
< 0 || nslots
> (PCI_SID_ESR_NSLOTS
>> SLOTID_NSLOTS_SHIFT
)) {
23 /* TODO: error report? */
27 cap
= pci_add_capability(d
, PCI_CAP_ID_SLOTID
, offset
,
28 SLOTID_CAP_LENGTH
, errp
);
32 /* We make each chassis unique, this way each bridge is First in Chassis */
33 d
->config
[cap
+ PCI_SID_ESR
] = PCI_SID_ESR_FIC
|
34 (nslots
<< SLOTID_NSLOTS_SHIFT
);
35 d
->cmask
[cap
+ PCI_SID_ESR
] = 0xff;
36 d
->config
[cap
+ PCI_SID_CHASSIS_NR
] = chassis
;
37 /* Note: Chassis number register is non-volatile,
38 so we don't reset it. */
39 /* TODO: store in eeprom? */
40 d
->wmask
[cap
+ PCI_SID_CHASSIS_NR
] = 0xff;
42 d
->cap_present
|= QEMU_PCI_CAP_SLOTID
;
46 void slotid_cap_cleanup(PCIDevice
*d
)
48 /* TODO: cleanup config space? */
49 d
->cap_present
&= ~QEMU_PCI_CAP_SLOTID
;