From ad291c52945e7c1c9d549027d7dbfa32648ba41f Mon Sep 17 00:00:00 2001 From: Stefan Lankes Date: Sat, 13 Dec 2014 17:53:42 +0100 Subject: [PATCH] add new function to determin if a device supports MMIO --- arch/x86/include/asm/pci.h | 9 +++++++-- arch/x86/kernel/pci.c | 10 +++++++++- 2 files changed, 16 insertions(+), 3 deletions(-) diff --git a/arch/x86/include/asm/pci.h b/arch/x86/include/asm/pci.h index ae74ba9..949c01b 100644 --- a/arch/x86/include/asm/pci.h +++ b/arch/x86/include/asm/pci.h @@ -42,12 +42,17 @@ extern "C" { #endif typedef struct { + uint32_t slot, bus; uint32_t base[6]; uint32_t size[6]; - uint32_t irq; + uint8_t type[6]; + uint8_t irq; } pci_info_t; /** @brief Initialize the PCI environment + * + * return + * - 0 on success */ int pci_init(void); @@ -59,7 +64,7 @@ int pci_init(void); * * @return * - 0 on success - * - -EINVAL (-22) on failure + * - -EINVAL on failure */ int pci_get_device_info(uint32_t vendor_id, uint32_t device_id, pci_info_t* info); diff --git a/arch/x86/kernel/pci.c b/arch/x86/kernel/pci.c index 6fcdc37..ee1fff3 100644 --- a/arch/x86/kernel/pci.c +++ b/arch/x86/kernel/pci.c @@ -98,7 +98,7 @@ static uint32_t pci_conf_read(uint32_t bus, uint32_t slot, uint32_t off) return data; } -static inline uint32_t pci_what_irq(uint32_t bus, uint32_t slot) +static inline uint8_t pci_what_irq(uint32_t bus, uint32_t slot) { return pci_conf_read(bus, slot, PCI_CFIT) & 0xFF; } @@ -108,6 +108,11 @@ static inline uint32_t pci_what_iobase(uint32_t bus, uint32_t slot, uint32_t nr) return pci_conf_read(bus, slot, PCI_CBIO + nr*4) & 0xFFFFFFFC; } +static inline uint32_t pci_what_type(uint32_t bus, uint32_t slot, uint32_t nr) +{ + return pci_conf_read(bus, slot, PCI_CBIO + nr*4) & 0x1; +} + static inline uint32_t pci_what_size(uint32_t bus, uint32_t slot, uint32_t nr) { uint32_t tmp, ret; @@ -151,8 +156,11 @@ int pci_get_device_info(uint32_t vendor_id, uint32_t device_id, pci_info_t* info if (adapters[bus][slot] != -1) { if (((adapters[bus][slot] & 0xffff) == vendor_id) && (((adapters[bus][slot] & 0xffff0000) >> 16) == device_id)) { + info->slot = slot; + info->bus = bus; for(i=0; i<6; i++) { info->base[i] = pci_what_iobase(bus, slot, i); + info->type[i] = pci_what_type(bus, slot, i); info->size[i] = (info->base[i]) ? pci_what_size(bus, slot, i) : 0; } info->irq = pci_what_irq(bus, slot);