From: Bjorn Helgaas <bjorn.helgaas@hp.com>
To: Jesse Barnes <jbarnes@virtuousgeek.org>
Cc: Len Brown <lenb@kernel.org>,
Linus Torvalds <torvalds@linux-foundation.org>,
Frans Pop <elendil@planet.nl>,
Rene Herman <rene.herman@keyaccess.nl>,
"Rafael J. Wysocki" <rjw@sisk.pl>,
linux-kernel@vger.kernel.org, linux-pci@vger.kernel.org,
linux-acpi@vger.kernel.org, Adam Belay <abelay@mit.edu>,
Avuton Olrich <avuton@gmail.com>,
Karl Bellve <karl.bellve@umassmed.edu>,
Willem Riede <wriede@riede.org>,
Matthew Hall <mhall@mhcomputing.net>
Subject: [patch 1/2] PCI: add pci_resource_enabled()
Date: Mon, 29 Sep 2008 09:56:56 -0600 [thread overview]
Message-ID: <200809290956.57727.bjorn.helgaas@hp.com> (raw)
In-Reply-To: <200809290953.56565.bjorn.helgaas@hp.com>
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 */
next prev parent reply other threads:[~2008-09-29 15:57 UTC|newest]
Thread overview: 33+ messages / expand[flat|nested] mbox.gz Atom feed top
2008-09-29 15:53 [patch 0/2] don't check disabled PCI BARs for conflicts with PNP devices Bjorn Helgaas
2008-09-29 15:56 ` Bjorn Helgaas [this message]
2008-09-29 15:57 ` [patch 2/2] PNP: don't check disabled PCI BARs for conflicts in quirk_system_pci_resources() Bjorn Helgaas
2008-09-29 16:34 ` Linus Torvalds
2008-09-29 18:31 ` Rene Herman
2008-09-29 19:13 ` Linus Torvalds
2008-09-30 9:19 ` Rene Herman
2008-09-30 14:48 ` Linus Torvalds
2008-09-30 15:57 ` Rene Herman
2008-09-30 16:29 ` Linus Torvalds
2008-09-30 17:10 ` Linus Torvalds
2008-09-30 17:21 ` Linus Torvalds
2008-09-30 19:29 ` Rene Herman
2008-09-30 19:37 ` Rene Herman
2008-09-30 19:44 ` Linus Torvalds
2008-09-30 20:48 ` Rene Herman
2008-09-30 19:38 ` Ingo Molnar
2008-09-30 19:51 ` Linus Torvalds
2008-09-30 19:54 ` Arjan van de Ven
2008-09-30 20:01 ` Ingo Molnar
2008-10-01 6:13 ` Grant Grundler
2008-10-01 8:26 ` Ingo Molnar
2008-10-06 5:34 ` Grant Grundler
2008-10-01 15:14 ` Linus Torvalds
2008-10-01 16:21 ` Yinghai Lu
2008-09-30 20:05 ` Rolf Eike Beer
2008-10-01 8:52 ` Ingo Molnar
2008-09-30 18:01 ` Linus Torvalds
2008-09-30 18:13 ` Linus Torvalds
2008-09-30 19:51 ` Rene Herman
2008-09-30 19:16 ` Bjorn Helgaas
2008-09-30 19:12 ` Bjorn Helgaas
2008-10-01 20:18 ` Bjorn Helgaas
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=200809290956.57727.bjorn.helgaas@hp.com \
--to=bjorn.helgaas@hp.com \
--cc=abelay@mit.edu \
--cc=avuton@gmail.com \
--cc=elendil@planet.nl \
--cc=jbarnes@virtuousgeek.org \
--cc=karl.bellve@umassmed.edu \
--cc=lenb@kernel.org \
--cc=linux-acpi@vger.kernel.org \
--cc=linux-kernel@vger.kernel.org \
--cc=linux-pci@vger.kernel.org \
--cc=mhall@mhcomputing.net \
--cc=rene.herman@keyaccess.nl \
--cc=rjw@sisk.pl \
--cc=torvalds@linux-foundation.org \
--cc=wriede@riede.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.