lkml.org 
[lkml]   [2008]   [Sep]   [29]   [last100]   RSS Feed
Views: [wrap][no wrap]   [headers]  [forward] 
 
Messages in this thread
Patch in this message
/
From
Subject[patch 1/2] PCI: add pci_resource_enabled()
Date
Add pci_resource_enabled() to determine whether a PCI BAR is
enabled. Sometimes firmware leaves PCI BARs unconfigured, and
this interface is a way for the OS to identify that situation.

This is based on section 3.5 of the PCI Firmware spec, which says:

Since not all devices may be configured prior to the operating
system handoff, the operating system needs to know whether a
specific BAR register has been configured by firmware. The operating
system makes the determination by checking the I/O Enable, and
Memory Enable bits in the device's command register, and Expansion
ROM BAR enable bits. If the enable bit is set, then the corresponding
resource register has been configured.

Signed-off-by: Bjorn Helgaas <bjorn.helgaas@hp.com>

diff --git a/drivers/pci/setup-res.c b/drivers/pci/setup-res.c
index 1a5fc83..c4c90f8 100644
--- a/drivers/pci/setup-res.c
+++ b/drivers/pci/setup-res.c
@@ -26,6 +26,32 @@
#include "pci.h"


+int pci_resource_enabled(struct pci_dev *dev, int bar)
+{
+ u16 command = 0;
+ u32 addr = 0;
+
+ /*
+ * Based on section 3.5, "Device State at Firmware/Operating System
+ * Handoff," in the PCI Firmware spec.
+ */
+ pci_read_config_word(dev, PCI_COMMAND, &command);
+
+ if (pci_resource_flags(dev, bar) & IORESOURCE_IO)
+ return command & PCI_COMMAND_IO;
+
+ if (command & PCI_COMMAND_MEMORY) {
+ if (bar == PCI_ROM_RESOURCE) {
+ pci_read_config_dword(dev, dev->rom_base_reg, &addr);
+ return addr & PCI_ROM_ADDRESS_ENABLE;
+ }
+
+ return 1;
+ }
+
+ return 0;
+}
+
void pci_update_resource(struct pci_dev *dev, struct resource *res, int resno)
{
struct pci_bus_region region;
diff --git a/include/linux/pci.h b/include/linux/pci.h
index c0e1400..28ec520 100644
--- a/include/linux/pci.h
+++ b/include/linux/pci.h
@@ -796,6 +796,8 @@ static inline int pci_proc_domain(struct pci_bus *bus)
}
#endif /* CONFIG_PCI_DOMAINS */

+extern int pci_resource_enabled(struct pci_dev *dev, int bar);
+
#else /* CONFIG_PCI is not enabled */

/*
@@ -976,6 +978,9 @@ static inline struct pci_dev *pci_get_bus_and_slot(unsigned int bus,
unsigned int devfn)
{ return NULL; }

+static inline int pci_resource_enabled(struct pci_dev *dev, int bar)
+{ return 0; }
+
#endif /* CONFIG_PCI */

/* Include architecture-dependent settings and functions */

\
 
 \ /
  Last update: 2008-09-29 18:01    [W:0.063 / U:0.576 seconds]
©2003-2020 Jasper Spaans|hosted at Digital Ocean and TransIP|Read the blog|Advertise on this site