def express_slot()

in pci_lib/pci_lib.py [0:0]


    def express_slot(self):
        """
        Retrieve PCI-Express slot information.

        Returns None if this is not a PCIe slot, otherwise returns a
        PCIExpressSlot

        The 'power' field will be a bool indicating this slot's current power
        setting if it has power control capability, otherwise the 'power' field
        will be set to None.
        """
        with closing(PCIConfigSpace.get(self.device_name)) as config:
            express = find_capability(config, PCI_CAP_EXPRESS)
            if express is None:
                return None
            flags = read_u16(config, express + PCI_CAP_FLAGS)
            if (flags & PCI_EXPRESS_FLAG_SLOT) == 0:
                return None
            slotcap = read_u32(config, express + PCI_EXP_SLTCAP)
            slotstatus = read_u32(config, express + PCI_EXP_SLTSTA)
            slotctl = read_u32(config, express + PCI_EXP_SLTCTL)

            slotnum = slotcap >> 19
            presence = (slotstatus & PCI_EXP_SLOT_PRESENCE) != 0

            if slotcap & PCI_EXP_SLOT_CAP_ATTN_LED != 0:
                attn_led = PCI_EXP_SLOT_CTL_ATTN_LED_VALUES.get(
                    slotctl & PCI_EXP_SLOT_CTL_ATTN_LED_MASK, 'off')
            else:
                attn_led = 'unsupported'

            power = None
            if (slotcap & PCI_EXP_SLOT_CAP_POWER) != 0:
                # 1 is powered -off-, 0 is powered -on-
                power = (slotctl & PCI_EXP_SLOT_CTL_POWER) == 0
            return PCIExpressSlot(slotnum, presence, power, attn_led)