diff options
author | Peter Schiffer <pschiffe@redhat.com> | 2013-09-10 17:36:14 +0200 |
---|---|---|
committer | Peter Schiffer <pschiffe@redhat.com> | 2013-09-24 15:52:00 +0200 |
commit | 2e20f92522b659b206c907007d6f5757b406bb61 (patch) | |
tree | eaaa6d440a2a7a16a8dd61d80a8518d31f2190da /src/hardware/LMI_PCIDeviceProvider.c | |
parent | 4df9822196d53a1aaeba3ec0709c86389133bd5a (diff) | |
download | openlmi-providers-2e20f92522b659b206c907007d6f5757b406bb61.tar.gz openlmi-providers-2e20f92522b659b206c907007d6f5757b406bb61.tar.xz openlmi-providers-2e20f92522b659b206c907007d6f5757b406bb61.zip |
Hardware: Move PCI bus initialization to the Initialize() function
Move initialize and cleanup code to the Initialize() and Cleanup() functions.
Diffstat (limited to 'src/hardware/LMI_PCIDeviceProvider.c')
-rw-r--r-- | src/hardware/LMI_PCIDeviceProvider.c | 40 |
1 files changed, 18 insertions, 22 deletions
diff --git a/src/hardware/LMI_PCIDeviceProvider.c b/src/hardware/LMI_PCIDeviceProvider.c index cc6adc8..e2a159b 100644 --- a/src/hardware/LMI_PCIDeviceProvider.c +++ b/src/hardware/LMI_PCIDeviceProvider.c @@ -27,8 +27,19 @@ static const CMPIBroker* _cb = NULL; +struct pci_access *acc_dev = NULL; + static void LMI_PCIDeviceInitialize() { + if (init_pci_access(&acc_dev, PCI_FILL_IDENT + | PCI_FILL_IRQ + | PCI_FILL_BASES + | PCI_FILL_ROM_BASE + | PCI_FILL_CLASS + | PCI_FILL_CAPS) != 0) { + error("Failed to access the PCI bus."); + abort(); + } } static CMPIStatus LMI_PCIDeviceCleanup( @@ -36,6 +47,8 @@ static CMPIStatus LMI_PCIDeviceCleanup( const CMPIContext* cc, CMPIBoolean term) { + cleanup_pci_access(&acc_dev); + CMReturn(CMPI_RC_OK); } @@ -62,7 +75,6 @@ static CMPIStatus LMI_PCIDeviceEnumInstances( CMPIUint16 pci_cap; u8 rev, cache_line; u16 svid, subid, status, command_reg; - struct pci_access *acc; struct pci_dev *dev; struct pci_cap *cap; char vendor_buf[NAME_BUF_SIZE], *vendor_name; @@ -72,36 +84,22 @@ static CMPIStatus LMI_PCIDeviceEnumInstances( char device_id_str[PCI_DEVID_STR_SIZE]; char instance_id[INSTANCE_ID_LEN]; - if (!(acc = pci_alloc())) { - KReturn2(_cb, ERR_FAILED, "Cannot access the PCI bus."); - } - pci_init(acc); - pci_scan_bus(acc); - - for (dev = acc->devices; dev; dev = dev->next) { - pci_fill_info(dev, - PCI_FILL_IDENT - | PCI_FILL_IRQ - | PCI_FILL_BASES - | PCI_FILL_ROM_BASE - | PCI_FILL_CLASS - | PCI_FILL_CAPS); - + for (dev = acc_dev->devices; dev; dev = dev->next) { /* Ignore PCI Bridges */ /* Throw away the lower 8 bits denoting the subclass */ if (((dev->device_class) >> 8) == LMI_PCIDevice_ClassCode_Bridge) { continue; } - vendor_name = pci_lookup_name(acc, vendor_buf, NAME_BUF_SIZE, + vendor_name = pci_lookup_name(acc_dev, vendor_buf, NAME_BUF_SIZE, PCI_LOOKUP_VENDOR, dev->vendor_id); - device_name = pci_lookup_name(acc, device_buf, NAME_BUF_SIZE, + device_name = pci_lookup_name(acc_dev, device_buf, NAME_BUF_SIZE, PCI_LOOKUP_DEVICE, dev->vendor_id, dev->device_id); get_subid(dev, &svid, &subid); - subsys_name = pci_lookup_name(acc, subsys_buf, NAME_BUF_SIZE, + subsys_name = pci_lookup_name(acc_dev, subsys_buf, NAME_BUF_SIZE, PCI_LOOKUP_DEVICE | PCI_LOOKUP_SUBSYSTEM, dev->vendor_id, dev->device_id, svid, subid); - svendor_name = pci_lookup_name(acc, svendor_buf, NAME_BUF_SIZE, + svendor_name = pci_lookup_name(acc_dev, svendor_buf, NAME_BUF_SIZE, PCI_LOOKUP_VENDOR | PCI_LOOKUP_SUBSYSTEM, svid); status = pci_read_word(dev, PCI_STATUS); rev = pci_read_byte(dev, PCI_REVISION_ID); @@ -265,8 +263,6 @@ static CMPIStatus LMI_PCIDeviceEnumInstances( KReturnInstance(cr, lmi_dev); } - pci_cleanup(acc); - CMReturn(CMPI_RC_OK); } |