PCI: helpers for BSD
authorBarret Rhoden <brho@cs.berkeley.edu>
Thu, 15 Jan 2015 23:49:17 +0000 (15:49 -0800)
committerBarret Rhoden <brho@cs.berkeley.edu>
Sun, 1 Mar 2015 14:35:59 +0000 (09:35 -0500)
Including CARDBUS versions!

kern/arch/x86/pci.c
kern/arch/x86/pci.h

index da5fc99..cf9ba33 100644 (file)
@@ -501,3 +501,45 @@ uintptr_t pci_get_membar(struct pci_device *pcidev, int bir)
                pcidev->bar[bir].mmio_base64 :
                pcidev->bar[bir].mmio_base32);
 }
+
+uint16_t pci_get_vendor(struct pci_device *pcidev)
+{
+       return pcidev->ven_id;
+}
+
+uint16_t pci_get_device(struct pci_device *pcidev)
+{
+       return pcidev->dev_id;
+}
+
+uint16_t pci_get_subvendor(struct pci_device *pcidev)
+{
+       uint8_t header_type = pcidev_read8(pcidev, PCI_HEADER_REG) & 0x7c;
+       switch (header_type) {
+               case 0x00: /* STD_PCI_DEV */
+                       return pcidev_read16(pcidev, PCI_SUBSYSVEN_STD);
+               case 0x01: /* PCI2PCI */
+                       return -1;
+               case 0x02: /* PCI2CARDBUS */
+                       return pcidev_read16(pcidev, PCI_SUBVENID_CB);
+               default:
+                       warn("Unknown Header Type, %d", header_type);
+       }
+       return -1;
+}
+
+uint16_t pci_get_subdevice(struct pci_device *pcidev)
+{
+       uint8_t header_type = pcidev_read8(pcidev, PCI_HEADER_REG) & 0x7c;
+       switch (header_type) {
+               case 0x00: /* STD_PCI_DEV */
+                       return pcidev_read16(pcidev, PCI_SUBSYSID_STD);
+               case 0x01: /* PCI2PCI */
+                       return -1;
+               case 0x02: /* PCI2CARDBUS */
+                       return pcidev_read16(pcidev, PCI_SUBDEVID_CB);
+               default:
+                       warn("Unknown Header Type, %d", header_type);
+       }
+       return -1;
+}
index beb8b05..2082880 100644 (file)
@@ -406,6 +406,10 @@ void pci_set_bus_master(struct pci_device *pcidev);
 void pci_clr_bus_master(struct pci_device *pcidev);
 struct pci_device *pci_match_tbdf(int tbdf);
 uintptr_t pci_get_membar(struct pci_device *pcidev, int bir);
+uint16_t pci_get_vendor(struct pci_device *pcidev);
+uint16_t pci_get_device(struct pci_device *pcidev);
+uint16_t pci_get_subvendor(struct pci_device *pcidev);
+uint16_t pci_get_subdevice(struct pci_device *pcidev);
 
 /* MSI functions, msi.c */
 int pci_msi_enable(struct pci_device *p, uint64_t vec);