1 #include "hw/pci/slotid_cap.h"
2 #include "hw/pci/pci.h"
4 #define SLOTID_CAP_LENGTH 4
5 #define SLOTID_NSLOTS_SHIFT (ffs(PCI_SID_ESR_NSLOTS) - 1)
7 int slotid_cap_init(PCIDevice *d, int nslots,
13 error_report("Bridge chassis not specified. Each bridge is required "
14 "to be assigned a unique chassis id > 0.");
17 if (nslots < 0 || nslots > (PCI_SID_ESR_NSLOTS >> SLOTID_NSLOTS_SHIFT)) {
18 /* TODO: error report? */
22 cap = pci_add_capability(d, PCI_CAP_ID_SLOTID, offset, SLOTID_CAP_LENGTH);
26 /* We make each chassis unique, this way each bridge is First in Chassis */
27 d->config[cap + PCI_SID_ESR] = PCI_SID_ESR_FIC |
28 (nslots << SLOTID_NSLOTS_SHIFT);
29 d->cmask[cap + PCI_SID_ESR] = 0xff;
30 d->config[cap + PCI_SID_CHASSIS_NR] = chassis;
31 /* Note: Chassis number register is non-volatile,
32 so we don't reset it. */
33 /* TODO: store in eeprom? */
34 d->wmask[cap + PCI_SID_CHASSIS_NR] = 0xff;
36 d->cap_present |= QEMU_PCI_CAP_SLOTID;
40 void slotid_cap_cleanup(PCIDevice *d)
42 /* TODO: cleanup config space? */
43 d->cap_present &= ~QEMU_PCI_CAP_SLOTID;