[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-Id: <200809290956.57727.bjorn.helgaas@hp.com>
Date: Mon, 29 Sep 2008 09:56:56 -0600
From: Bjorn Helgaas <bjorn.helgaas@...com>
To: Jesse Barnes <jbarnes@...tuousgeek.org>
Cc: Len Brown <lenb@...nel.org>,
Linus Torvalds <torvalds@...ux-foundation.org>,
Frans Pop <elendil@...net.nl>,
Rene Herman <rene.herman@...access.nl>,
"Rafael J. Wysocki" <rjw@...k.pl>, linux-kernel@...r.kernel.org,
linux-pci@...r.kernel.org, linux-acpi@...r.kernel.org,
Adam Belay <abelay@....edu>, Avuton Olrich <avuton@...il.com>,
Karl Bellve <karl.bellve@...ssmed.edu>,
Willem Riede <wriede@...de.org>,
Matthew Hall <mhall@...omputing.net>
Subject: [patch 1/2] PCI: add pci_resource_enabled()
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@...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 */
--
To unsubscribe from this list: send the line "unsubscribe linux-kernel" in
the body of a message to majordomo@...r.kernel.org
More majordomo info at http://vger.kernel.org/majordomo-info.html
Please read the FAQ at http://www.tux.org/lkml/
Powered by blists - more mailing lists