Commit 3119cfff authored by Linus Torvalds's avatar Linus Torvalds

Merge bk://kernel.bkbits.net/gregkh/linux/pci-2.5

into home.transmeta.com:/home/torvalds/v2.5/linux
parents e6d3a689 13ce7788
......@@ -1429,10 +1429,10 @@ W: http://www.ife.ee.ethz.ch/~sailer/linux/pciaudio.html
S: Maintained
PCI SUBSYSTEM
P: Martin Mares
M: mj@ucw.cz
P: Greg Kroah-Hartman
M: greg@kroah.com
L: linux-kernel@vger.kernel.org
S: Odd Fixes
S: Supported
PCI HOTPLUG CORE
P: Greg Kroah-Hartman
......
......@@ -23,7 +23,24 @@ unsigned int pci_probe = PCI_PROBE_BIOS | PCI_PROBE_CONF1 | PCI_PROBE_CONF2;
int pcibios_last_bus = -1;
struct pci_bus *pci_root_bus = NULL;
struct pci_ops *pci_root_ops = NULL;
struct pci_raw_ops *raw_pci_ops;
static int pci_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
{
return raw_pci_ops->read(0, bus->number, PCI_SLOT(devfn),
PCI_FUNC(devfn), where, size, value);
}
static int pci_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
{
return raw_pci_ops->write(0, bus->number, PCI_SLOT(devfn),
PCI_FUNC(devfn), where, size, value);
}
struct pci_ops pci_root_ops = {
.read = pci_read,
.write = pci_write,
};
/*
* legacy, numa, and acpi all want to call pcibios_scan_root
......@@ -115,7 +132,7 @@ struct pci_bus * __devinit pcibios_scan_root(int busnum)
printk("PCI: Probing PCI hardware (bus %02x)\n", busnum);
return pci_scan_bus(busnum, pci_root_ops, NULL);
return pci_scan_bus(busnum, &pci_root_ops, NULL);
}
extern u8 pci_cache_line_size;
......@@ -124,7 +141,7 @@ static int __init pcibios_init(void)
{
struct cpuinfo_x86 *c = &boot_cpu_data;
if (!pci_root_ops) {
if (!raw_pci_ops) {
printk("PCI: System does not support PCI\n");
return 0;
}
......
......@@ -13,7 +13,7 @@
#define PCI_CONF1_ADDRESS(bus, dev, fn, reg) \
(0x80000000 | (bus << 16) | (dev << 11) | (fn << 8) | (reg & ~3))
static int __pci_conf1_read (int seg, int bus, int dev, int fn, int reg, int len, u32 *value)
static int pci_conf1_read (int seg, int bus, int dev, int fn, int reg, int len, u32 *value)
{
unsigned long flags;
......@@ -41,7 +41,7 @@ static int __pci_conf1_read (int seg, int bus, int dev, int fn, int reg, int len
return 0;
}
static int __pci_conf1_write (int seg, int bus, int dev, int fn, int reg, int len, u32 value)
static int pci_conf1_write (int seg, int bus, int dev, int fn, int reg, int len, u32 value)
{
unsigned long flags;
......@@ -71,19 +71,7 @@ static int __pci_conf1_write (int seg, int bus, int dev, int fn, int reg, int le
#undef PCI_CONF1_ADDRESS
static int pci_conf1_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
{
return __pci_conf1_read(0, bus->number, PCI_SLOT(devfn),
PCI_FUNC(devfn), where, size, value);
}
static int pci_conf1_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
{
return __pci_conf1_write(0, bus->number, PCI_SLOT(devfn),
PCI_FUNC(devfn), where, size, value);
}
struct pci_ops pci_direct_conf1 = {
struct pci_raw_ops pci_direct_conf1 = {
.read = pci_conf1_read,
.write = pci_conf1_write,
};
......@@ -95,7 +83,7 @@ struct pci_ops pci_direct_conf1 = {
#define PCI_CONF2_ADDRESS(dev, reg) (u16)(0xC000 | (dev << 8) | reg)
static int __pci_conf2_read (int seg, int bus, int dev, int fn, int reg, int len, u32 *value)
static int pci_conf2_read (int seg, int bus, int dev, int fn, int reg, int len, u32 *value)
{
unsigned long flags;
......@@ -129,7 +117,7 @@ static int __pci_conf2_read (int seg, int bus, int dev, int fn, int reg, int len
return 0;
}
static int __pci_conf2_write (int seg, int bus, int dev, int fn, int reg, int len, u32 value)
static int pci_conf2_write (int seg, int bus, int dev, int fn, int reg, int len, u32 value)
{
unsigned long flags;
......@@ -165,19 +153,7 @@ static int __pci_conf2_write (int seg, int bus, int dev, int fn, int reg, int le
#undef PCI_CONF2_ADDRESS
static int pci_conf2_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
{
return __pci_conf2_read(0, bus->number, PCI_SLOT(devfn),
PCI_FUNC(devfn), where, size, value);
}
static int pci_conf2_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
{
return __pci_conf2_write(0, bus->number, PCI_SLOT(devfn),
PCI_FUNC(devfn), where, size, value);
}
static struct pci_ops pci_direct_conf2 = {
static struct pci_raw_ops pci_direct_conf2 = {
.read = pci_conf2_read,
.write = pci_conf2_write,
};
......@@ -193,38 +169,30 @@ static struct pci_ops pci_direct_conf2 = {
* This should be close to trivial, but it isn't, because there are buggy
* chipsets (yes, you guessed it, by Intel and Compaq) that have no class ID.
*/
static int __devinit pci_sanity_check(struct pci_ops *o)
static int __devinit pci_sanity_check(struct pci_raw_ops *o)
{
u32 x = 0;
int retval = 0;
struct pci_bus *bus; /* Fake bus and device */
struct pci_dev *dev;
int devfn;
if (pci_probe & PCI_NO_CHECKS)
return 1;
bus = kmalloc(sizeof(*bus), GFP_ATOMIC);
dev = kmalloc(sizeof(*dev), GFP_ATOMIC);
if (!bus || !dev) {
printk(KERN_ERR "Out of memory in %s\n", __FUNCTION__);
goto exit;
for (devfn = 0; devfn < 0x100; devfn++) {
if (o->read(0, 0, PCI_SLOT(devfn), PCI_FUNC(devfn),
PCI_CLASS_DEVICE, 2, &x))
continue;
if (x == PCI_CLASS_BRIDGE_HOST || x == PCI_CLASS_DISPLAY_VGA)
return 1;
if (o->read(0, 0, PCI_SLOT(devfn), PCI_FUNC(devfn),
PCI_VENDOR_ID, 2, &x))
continue;
if (x == PCI_VENDOR_ID_INTEL || x == PCI_VENDOR_ID_COMPAQ)
return 1;
}
bus->number = 0;
dev->bus = bus;
for(dev->devfn=0; dev->devfn < 0x100; dev->devfn++)
if ((!o->read(bus, dev->devfn, PCI_CLASS_DEVICE, 2, &x) &&
(x == PCI_CLASS_BRIDGE_HOST || x == PCI_CLASS_DISPLAY_VGA)) ||
(!o->read(bus, dev->devfn, PCI_VENDOR_ID, 2, &x) &&
(x == PCI_VENDOR_ID_INTEL || x == PCI_VENDOR_ID_COMPAQ))) {
retval = 1;
goto exit;
}
DBG("PCI: Sanity check failed\n");
exit:
kfree(dev);
kfree(bus);
return retval;
return 0;
}
static int __init pci_direct_init(void)
......@@ -247,9 +215,9 @@ static int __init pci_direct_init(void)
local_irq_restore(flags);
printk(KERN_INFO "PCI: Using configuration type 1\n");
if (!request_region(0xCF8, 8, "PCI conf1"))
pci_root_ops = NULL;
raw_pci_ops = NULL;
else
pci_root_ops = &pci_direct_conf1;
raw_pci_ops = &pci_direct_conf1;
return 0;
}
outl (tmp, 0xCF8);
......@@ -267,9 +235,9 @@ static int __init pci_direct_init(void)
local_irq_restore(flags);
printk(KERN_INFO "PCI: Using configuration type 2\n");
if (!request_region(0xCF8, 4, "PCI conf2"))
pci_root_ops = NULL;
raw_pci_ops = NULL;
else
pci_root_ops = &pci_direct_conf2;
raw_pci_ops = &pci_direct_conf2;
return 0;
}
}
......
......@@ -23,9 +23,9 @@ static void __devinit pci_fixup_i450nx(struct pci_dev *d)
pci_read_config_byte(d, reg++, &subb);
DBG("i450NX PXB %d: %02x/%02x/%02x\n", pxb, busno, suba, subb);
if (busno)
pci_scan_bus(busno, pci_root_ops, NULL); /* Bus A */
pci_scan_bus(busno, &pci_root_ops, NULL); /* Bus A */
if (suba < subb)
pci_scan_bus(suba+1, pci_root_ops, NULL); /* Bus B */
pci_scan_bus(suba+1, &pci_root_ops, NULL); /* Bus B */
}
pcibios_last_bus = -1;
}
......@@ -39,7 +39,7 @@ static void __devinit pci_fixup_i450gx(struct pci_dev *d)
u8 busno;
pci_read_config_byte(d, 0x4a, &busno);
printk(KERN_INFO "PCI: i440KX/GX host bridge %s: secondary bus %02x\n", d->slot_name, busno);
pci_scan_bus(busno, pci_root_ops, NULL);
pci_scan_bus(busno, &pci_root_ops, NULL);
pcibios_last_bus = -1;
}
......
......@@ -107,7 +107,7 @@ static void __init pirq_peer_trick(void)
* It might be a secondary bus, but in this case its parent is already
* known (ascending bus order) and therefore pci_scan_bus returns immediately.
*/
if (busmap[i] && pci_scan_bus(i, pci_root_bus->ops, NULL))
if (busmap[i] && pci_scan_bus(i, &pci_root_ops, NULL))
printk(KERN_INFO "PCI: Discovered primary peer bus %02x [IRQ]\n", i);
pcibios_last_bus = -1;
}
......
......@@ -31,14 +31,14 @@ static void __devinit pcibios_fixup_peer_bridges(void)
if (pci_bus_exists(&pci_root_buses, n))
continue;
bus->number = n;
bus->ops = pci_root_ops;
bus->ops = &pci_root_ops;
dev->bus = bus;
for (dev->devfn=0; dev->devfn<256; dev->devfn += 8)
if (!pci_read_config_word(dev, PCI_VENDOR_ID, &l) &&
l != 0x0000 && l != 0xffff) {
DBG("Found device at %02x:%02x [%04x]\n", n, dev->devfn, l);
printk(KERN_INFO "PCI: Discovered peer bus %02x\n", n);
pci_scan_bus(n, pci_root_ops, NULL);
pci_scan_bus(n, &pci_root_ops, NULL);
break;
}
}
......@@ -49,7 +49,7 @@ static void __devinit pcibios_fixup_peer_bridges(void)
static int __init pci_legacy_init(void)
{
if (!pci_root_ops) {
if (!raw_pci_ops) {
printk("PCI: System does not support PCI\n");
return 0;
}
......
......@@ -13,7 +13,7 @@
#define PCI_CONF1_MQ_ADDRESS(bus, dev, fn, reg) \
(0x80000000 | (BUS2LOCAL(bus) << 16) | (dev << 11) | (fn << 8) | (reg & ~3))
static int __pci_conf1_mq_read (int seg, int bus, int dev, int fn, int reg, int len, u32 *value)
static int pci_conf1_mq_read (int seg, int bus, int dev, int fn, int reg, int len, u32 *value)
{
unsigned long flags;
......@@ -41,7 +41,7 @@ static int __pci_conf1_mq_read (int seg, int bus, int dev, int fn, int reg, int
return 0;
}
static int __pci_conf1_mq_write (int seg, int bus, int dev, int fn, int reg, int len, u32 value)
static int pci_conf1_mq_write (int seg, int bus, int dev, int fn, int reg, int len, u32 value)
{
unsigned long flags;
......@@ -71,19 +71,7 @@ static int __pci_conf1_mq_write (int seg, int bus, int dev, int fn, int reg, int
#undef PCI_CONF1_MQ_ADDRESS
static int pci_conf1_mq_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
{
return __pci_conf1_mq_read(0, bus->number, PCI_SLOT(devfn),
PCI_FUNC(devfn), where, size, value);
}
static int pci_conf1_mq_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
{
return __pci_conf1_mq_write(0, bus->number, PCI_SLOT(devfn),
PCI_FUNC(devfn), where, size, value);
}
static struct pci_ops pci_direct_conf1_mq = {
static struct pci_raw_ops pci_direct_conf1_mq = {
.read = pci_conf1_mq_read,
.write = pci_conf1_mq_write
};
......@@ -106,9 +94,9 @@ static void __devinit pci_fixup_i450nx(struct pci_dev *d)
pci_read_config_byte(d, reg++, &subb);
DBG("i450NX PXB %d: %02x/%02x/%02x\n", pxb, busno, suba, subb);
if (busno)
pci_scan_bus(QUADLOCAL2BUS(quad,busno), pci_root_ops, NULL); /* Bus A */
pci_scan_bus(QUADLOCAL2BUS(quad,busno), &pci_root_ops, NULL); /* Bus A */
if (suba < subb)
pci_scan_bus(QUADLOCAL2BUS(quad,suba+1), pci_root_ops, NULL); /* Bus B */
pci_scan_bus(QUADLOCAL2BUS(quad,suba+1), &pci_root_ops, NULL); /* Bus B */
}
pcibios_last_bus = -1;
}
......@@ -121,7 +109,7 @@ static int __init pci_numa_init(void)
{
int quad;
pci_root_ops = &pci_direct_conf1_mq;
raw_pci_ops = &pci_direct_conf1_mq;
if (pcibios_scanned++)
return 0;
......@@ -132,7 +120,7 @@ static int __init pci_numa_init(void)
printk("Scanning PCI bus %d for quad %d\n",
QUADLOCAL2BUS(quad,0), quad);
pci_scan_bus(QUADLOCAL2BUS(quad,0),
pci_root_ops, NULL);
&pci_root_ops, NULL);
}
}
return 0;
......
......@@ -172,7 +172,7 @@ static int __devinit pci_bios_find_device (unsigned short vendor, unsigned short
return (int) (ret & 0xff00) >> 8;
}
static int __pci_bios_read (int seg, int bus, int dev, int fn, int reg, int len, u32 *value)
static int pci_bios_read (int seg, int bus, int dev, int fn, int reg, int len, u32 *value)
{
unsigned long result = 0;
unsigned long flags;
......@@ -227,7 +227,7 @@ static int __pci_bios_read (int seg, int bus, int dev, int fn, int reg, int len,
return (int)((result & 0xff00) >> 8);
}
static int __pci_bios_write (int seg, int bus, int dev, int fn, int reg, int len, u32 value)
static int pci_bios_write (int seg, int bus, int dev, int fn, int reg, int len, u32 value)
{
unsigned long result = 0;
unsigned long flags;
......@@ -282,24 +282,12 @@ static int __pci_bios_write (int seg, int bus, int dev, int fn, int reg, int len
return (int)((result & 0xff00) >> 8);
}
static int pci_bios_read(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
{
return __pci_bios_read(0, bus->number, PCI_SLOT(devfn),
PCI_FUNC(devfn), where, size, value);
}
static int pci_bios_write(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
{
return __pci_bios_write(0, bus->number, PCI_SLOT(devfn),
PCI_FUNC(devfn), where, size, value);
}
/*
* Function table for BIOS32 access
*/
static struct pci_ops pci_bios_access = {
static struct pci_raw_ops pci_bios_access = {
.read = pci_bios_read,
.write = pci_bios_write
};
......@@ -308,7 +296,7 @@ static struct pci_ops pci_bios_access = {
* Try to find PCI BIOS.
*/
static struct pci_ops * __devinit pci_find_bios(void)
static struct pci_raw_ops * __devinit pci_find_bios(void)
{
union bios32 *check;
unsigned char sum;
......@@ -484,7 +472,7 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
static int __init pci_pcbios_init(void)
{
if ((pci_probe & PCI_PROBE_BIOS)
&& ((pci_root_ops = pci_find_bios()))) {
&& ((raw_pci_ops = pci_find_bios()))) {
pci_probe |= PCI_BIOS_SORT;
pci_bios_present = 1;
}
......
......@@ -37,7 +37,7 @@ int pcibios_enable_resources(struct pci_dev *, int);
extern int pcibios_last_bus;
extern struct pci_bus *pci_root_bus;
extern struct pci_ops *pci_root_ops;
extern struct pci_ops pci_root_ops;
/* pci-irq.c */
......
......@@ -59,7 +59,7 @@ struct pci_fixup pcibios_fixups[1];
static int
__pci_sal_read (int seg, int bus, int dev, int fn, int reg, int len, u32 *value)
pci_sal_read (int seg, int bus, int dev, int fn, int reg, int len, u32 *value)
{
int result = 0;
u64 data = 0;
......@@ -75,7 +75,7 @@ __pci_sal_read (int seg, int bus, int dev, int fn, int reg, int len, u32 *value)
}
static int
__pci_sal_write (int seg, int bus, int dev, int fn, int reg, int len, u32 value)
pci_sal_write (int seg, int bus, int dev, int fn, int reg, int len, u32 value)
{
if ((seg > 255) || (bus > 255) || (dev > 31) || (fn > 7) || (reg > 255))
return -EINVAL;
......@@ -83,28 +83,33 @@ __pci_sal_write (int seg, int bus, int dev, int fn, int reg, int len, u32 value)
return ia64_sal_pci_config_write(PCI_SAL_ADDRESS(seg, bus, dev, fn, reg), len, value);
}
struct pci_raw_ops pci_sal_ops = {
.read = pci_sal_read,
.write = pci_sal_write
};
struct pci_raw_ops *raw_pci_ops = &pci_sal_ops; /* default to SAL */
static int
pci_sal_read (struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
pci_read (struct pci_bus *bus, unsigned int devfn, int where, int size, u32 *value)
{
return __pci_sal_read(pci_domain_nr(bus), bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn),
where, size, value);
return raw_pci_ops->read(pci_domain_nr(bus), bus->number,
PCI_SLOT(devfn), PCI_FUNC(devfn), where, size, value);
}
static int
pci_sal_write (struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
pci_write (struct pci_bus *bus, unsigned int devfn, int where, int size, u32 value)
{
return __pci_sal_write(pci_domain_nr(bus), bus->number, PCI_SLOT(devfn), PCI_FUNC(devfn),
where, size, value);
return raw_pci_ops->write(pci_domain_nr(bus), bus->number,
PCI_SLOT(devfn), PCI_FUNC(devfn), where, size, value);
}
struct pci_ops pci_sal_ops = {
.read = pci_sal_read,
.write = pci_sal_write
static struct pci_ops pci_root_ops = {
.read = pci_read,
.write = pci_write,
};
struct pci_ops *pci_root_ops = &pci_sal_ops; /* default to SAL */
static int __init
pci_acpi_init (void)
{
......@@ -307,7 +312,7 @@ pcibios_scan_root (void *handle, int seg, int bus)
info.name = name;
acpi_walk_resources(handle, METHOD_NAME__CRS, add_window, &info);
return scan_root_bus(bus, pci_root_ops, controller);
return scan_root_bus(bus, &pci_root_ops, controller);
out3:
kfree(controller->window);
......
......@@ -69,8 +69,6 @@ static int acpi_irq_irq = 0;
static OSD_HANDLER acpi_irq_handler = NULL;
static void *acpi_irq_context = NULL;
extern struct pci_ops *pci_root_ops;
acpi_status
acpi_os_initialize(void)
{
......@@ -79,7 +77,7 @@ acpi_os_initialize(void)
* it while walking the namespace (bus 0 and root bridges w/ _BBNs).
*/
#ifdef CONFIG_ACPI_PCI
if (!pci_root_ops) {
if (!raw_pci_ops) {
printk(KERN_ERR PREFIX "Access to PCI configuration space unavailable\n");
return AE_NULL_ENTRY;
}
......@@ -446,15 +444,9 @@ acpi_os_write_memory(
#ifdef CONFIG_ACPI_PCI
acpi_status
acpi_os_read_pci_configuration (
struct acpi_pci_id *pci_id,
u32 reg,
void *value,
u32 width)
acpi_os_read_pci_configuration (struct acpi_pci_id *pci_id, u32 reg, void *value, u32 width)
{
int result = 0;
int size = 0;
struct pci_bus bus;
int result, size;
if (!value)
return AE_BAD_PARAMETER;
......@@ -470,27 +462,19 @@ acpi_os_read_pci_configuration (
size = 4;
break;
default:
BUG();
return AE_ERROR;
}
bus.number = pci_id->bus;
result = pci_root_ops->read(&bus, PCI_DEVFN(pci_id->device,
pci_id->function),
reg, size, value);
result = raw_pci_ops->read(pci_id->segment, pci_id->bus,
pci_id->device, pci_id->function, reg, size, value);
return (result ? AE_ERROR : AE_OK);
}
acpi_status
acpi_os_write_pci_configuration (
struct acpi_pci_id *pci_id,
u32 reg,
acpi_integer value,
u32 width)
acpi_os_write_pci_configuration (struct acpi_pci_id *pci_id, u32 reg, acpi_integer value, u32 width)
{
int result = 0;
int size = 0;
struct pci_bus bus;
int result, size;
switch (width) {
case 8:
......@@ -503,13 +487,12 @@ acpi_os_write_pci_configuration (
size = 4;
break;
default:
BUG();
return AE_ERROR;
}
bus.number = pci_id->bus;
result = pci_root_ops->write(&bus, PCI_DEVFN(pci_id->device,
pci_id->function),
reg, size, value);
result = raw_pci_ops->write(pci_id->segment, pci_id->bus,
pci_id->device, pci_id->function, reg, size, value);
return (result ? AE_ERROR : AE_OK);
}
......
......@@ -44,8 +44,6 @@ ACPI_MODULE_NAME ("pci_root")
#define ACPI_PCI_ROOT_DRIVER_NAME "ACPI PCI Root Bridge Driver"
#define ACPI_PCI_ROOT_DEVICE_NAME "PCI Root Bridge"
extern struct pci_ops *pci_root_ops;
static int acpi_pci_root_add (struct acpi_device *device);
static int acpi_pci_root_remove (struct acpi_device *device, int type);
......
......@@ -93,7 +93,11 @@ void __devinit pci_bus_add_devices(struct pci_bus *bus)
continue;
device_add(&dev->dev);
spin_lock(&pci_bus_lock);
list_add_tail(&dev->global_list, &pci_devices);
spin_unlock(&pci_bus_lock);
pci_proc_attach_device(dev);
pci_create_sysfs_dev_files(dev);
......@@ -108,7 +112,9 @@ void __devinit pci_bus_add_devices(struct pci_bus *bus)
* it and then scan for unattached PCI devices.
*/
if (dev->subordinate && list_empty(&dev->subordinate->node)) {
spin_lock(&pci_bus_lock);
list_add_tail(&dev->subordinate->node, &dev->bus->children);
spin_unlock(&pci_bus_lock);
pci_bus_add_devices(dev->subordinate);
}
}
......
......@@ -173,6 +173,24 @@ int pci_visit_dev (struct pci_visit *fn, struct pci_dev_wrapped *wrapped_dev,
}
EXPORT_SYMBOL(pci_visit_dev);
static void pci_destroy_dev(struct pci_dev *dev)
{
pci_proc_detach_device(dev);
device_unregister(&dev->dev);
/* Remove the device from the device lists, and prevent any further
* list accesses from this device */
spin_lock(&pci_bus_lock);
list_del(&dev->bus_list);
list_del(&dev->global_list);
dev->bus_list.next = dev->bus_list.prev = NULL;
dev->global_list.next = dev->global_list.prev = NULL;
spin_unlock(&pci_bus_lock);
pci_free_resources(dev);
pci_dev_put(dev);
}
/**
* pci_remove_device_safe - remove an unused hotplug device
* @dev: the device to remove
......@@ -186,11 +204,7 @@ int pci_remove_device_safe(struct pci_dev *dev)
{
if (pci_dev_driver(dev))
return -EBUSY;
device_unregister(&dev->dev);
list_del(&dev->bus_list);
list_del(&dev->global_list);
pci_free_resources(dev);
pci_proc_detach_device(dev);
pci_destroy_dev(dev);
return 0;
}
EXPORT_SYMBOL(pci_remove_device_safe);
......@@ -237,17 +251,15 @@ void pci_remove_bus_device(struct pci_dev *dev)
pci_remove_behind_bridge(dev);
pci_proc_detach_bus(b);
spin_lock(&pci_bus_lock);
list_del(&b->node);
spin_unlock(&pci_bus_lock);
kfree(b);
dev->subordinate = NULL;
}
device_unregister(&dev->dev);
list_del(&dev->bus_list);
list_del(&dev->global_list);
pci_free_resources(dev);
pci_proc_detach_device(dev);
pci_put_dev(dev);
pci_destroy_dev(dev);
}
/**
......
......@@ -138,10 +138,10 @@ static int pci_device_probe(struct device * dev)
drv = to_pci_driver(dev->driver);
pci_dev = to_pci_dev(dev);
pci_get_dev(pci_dev);
pci_dev_get(pci_dev);
error = __pci_device_probe(drv, pci_dev);
if (error)
pci_put_dev(pci_dev);
pci_dev_put(pci_dev);
return error;
}
......@@ -156,7 +156,7 @@ static int pci_device_remove(struct device * dev)
drv->remove(pci_dev);
pci_dev->driver = NULL;
}
pci_put_dev(pci_dev);
pci_dev_put(pci_dev);
return 0;
}
......@@ -448,18 +448,18 @@ static int pci_bus_match(struct device * dev, struct device_driver * drv)
}
/**
* pci_get_dev - increments the reference count of the pci device structure
* pci_dev_get - increments the reference count of the pci device structure
* @dev: the device being referenced
*
* Each live reference to a device should be refcounted.
*
* Drivers for PCI devices should normally record such references in
* their probe() methods, when they bind to a device, and release
* them by calling pci_put_dev(), in their disconnect() methods.
* them by calling pci_dev_put(), in their disconnect() methods.
*
* A pointer to the device with the incremented reference counter is returned.
*/
struct pci_dev *pci_get_dev (struct pci_dev *dev)
struct pci_dev *pci_dev_get(struct pci_dev *dev)
{
struct device *tmp;
......@@ -474,13 +474,13 @@ struct pci_dev *pci_get_dev (struct pci_dev *dev)
}
/**
* pci_put_dev - release a use of the pci device structure
* pci_dev_put - release a use of the pci device structure
* @dev: device that's been disconnected
*
* Must be called when a user of a device is finished with it. When the last
* user of the device calls this function, the memory of the device is freed.
*/
void pci_put_dev(struct pci_dev *dev)
void pci_dev_put(struct pci_dev *dev)
{
if (dev)
put_device(&dev->dev);
......@@ -504,5 +504,5 @@ EXPORT_SYMBOL(pci_register_driver);
EXPORT_SYMBOL(pci_unregister_driver);
EXPORT_SYMBOL(pci_dev_driver);
EXPORT_SYMBOL(pci_bus_type);
EXPORT_SYMBOL(pci_get_dev);
EXPORT_SYMBOL(pci_put_dev);
EXPORT_SYMBOL(pci_dev_get);
EXPORT_SYMBOL(pci_dev_put);
......@@ -18,12 +18,6 @@
#include "pci.h"
#if BITS_PER_LONG == 32
#define LONG_FORMAT "\t%08lx"
#else
#define LONG_FORMAT "\t%16lx"
#endif
/* show configuration fields */
#define pci_config_attr(field, format_string) \
static ssize_t \
......@@ -36,11 +30,11 @@ show_##field (struct device *dev, char *buf) \
} \
static DEVICE_ATTR(field, S_IRUGO, show_##field, NULL);
pci_config_attr(vendor, "%04x\n");
pci_config_attr(device, "%04x\n");
pci_config_attr(subsystem_vendor, "%04x\n");
pci_config_attr(subsystem_device, "%04x\n");
pci_config_attr(class, "%06x\n");
pci_config_attr(vendor, "0x%04x\n");
pci_config_attr(device, "0x%04x\n");
pci_config_attr(subsystem_vendor, "0x%04x\n");
pci_config_attr(subsystem_device, "0x%04x\n");
pci_config_attr(class, "0x%06x\n");
pci_config_attr(irq, "%u\n");
/* show resources */
......@@ -50,9 +44,13 @@ pci_show_resources(struct device * dev, char * buf)
struct pci_dev * pci_dev = to_pci_dev(dev);
char * str = buf;
int i;
int max = 7;
if (pci_dev->subordinate)
max = DEVICE_COUNT_RESOURCE;
for (i = 0; i < DEVICE_COUNT_RESOURCE && pci_resource_start(pci_dev,i); i++) {
str += sprintf(str,LONG_FORMAT LONG_FORMAT LONG_FORMAT "\n",
for (i = 0; i < max; i++) {
str += sprintf(str,"0x%016lx 0x%016lx 0x%016lx\n",
pci_resource_start(pci_dev,i),
pci_resource_end(pci_dev,i),
pci_resource_flags(pci_dev,i));
......
......@@ -58,3 +58,6 @@ struct pci_visit {
extern int pci_visit_dev(struct pci_visit *fn,
struct pci_dev_wrapped *wrapped_dev,
struct pci_bus_wrapped *wrapped_parent);
/* Lock for read/write access to pci device and bus lists */
extern spinlock_t pci_bus_lock;
......@@ -524,7 +524,7 @@ pci_scan_device(struct pci_bus *bus, int devfn)
}
device_initialize(&dev->dev);
dev->dev.release = pci_release_dev;
pci_get_dev(dev);
pci_dev_get(dev);
pci_name_device(dev);
......
......@@ -308,39 +308,45 @@ static struct file_operations proc_bus_pci_operations = {
/* iterator */
static void *pci_seq_start(struct seq_file *m, loff_t *pos)
{
struct list_head *p = &pci_devices;
struct pci_dev *dev = NULL;
loff_t n = *pos;
/* XXX: surely we need some locking for traversing the list? */
dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
while (n--) {
p = p->next;
if (p == &pci_devices)
return NULL;
dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
if (dev == NULL)
goto exit;
}
return p;
exit:
return dev;
}
static void *pci_seq_next(struct seq_file *m, void *v, loff_t *pos)
{
struct list_head *p = v;
struct pci_dev *dev = v;
(*pos)++;
return p->next != &pci_devices ? (void *)p->next : NULL;
dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, dev);
return dev;
}
static void pci_seq_stop(struct seq_file *m, void *v)
{
/* release whatever locks we need */
if (v) {
struct pci_dev *dev = v;
pci_dev_put(dev);
}
}
static int show_device(struct seq_file *m, void *v)
{
struct list_head *p = v;
const struct pci_dev *dev;
const struct pci_dev *dev = v;
const struct pci_driver *drv;
int i;
if (p == &pci_devices)
if (dev == NULL)
return 0;
dev = pci_dev_g(p);
drv = pci_dev_driver(dev);
seq_printf(m, "%02x%02x\t%04x%04x\t%x",
dev->bus->number,
......@@ -383,7 +389,8 @@ int pci_proc_attach_device(struct pci_dev *dev)
return -EACCES;
if (!(de = bus->procdir)) {
sprintf(name, "%02x", bus->number);
if (pci_name_bus(name, bus))
return -EEXIST;
de = bus->procdir = proc_mkdir(name, proc_bus_pci_dir);
if (!de)
return -ENOMEM;
......@@ -451,19 +458,18 @@ int pci_proc_detach_bus(struct pci_bus* bus)
*/
static int show_dev_config(struct seq_file *m, void *v)
{
struct list_head *p = v;
struct pci_dev *dev;
struct pci_dev *dev = v;
struct pci_dev *first_dev;
struct pci_driver *drv;
u32 class_rev;
unsigned char latency, min_gnt, max_lat, *class;
int reg;
if (p == &pci_devices) {
first_dev = pci_get_device(PCI_ANY_ID, PCI_ANY_ID, NULL);
if (dev == first_dev)
seq_puts(m, "PCI devices found:\n");
return 0;
}
pci_dev_put(first_dev);
dev = pci_dev_g(p);
drv = pci_dev_driver(dev);
pci_read_config_dword(dev, PCI_CLASS_REVISION, &class_rev);
......
/*
* PCI searching functions.
*
* Copyright 1993 -- 1997 Drew Eckhardt, Frederic Potter,
* David Mosberger-Tang
* Copyright 1997 -- 2000 Martin Mares <mj@ucw.cz>
* Copyright 2003 -- Greg Kroah-Hartman <greg@kroah.com>
*/
#include <linux/pci.h>
#include <linux/module.h>
spinlock_t pci_bus_lock = SPIN_LOCK_UNLOCKED;
static struct pci_bus *
pci_do_find_bus(struct pci_bus* bus, unsigned char busnr)
{
......@@ -52,11 +63,15 @@ pci_find_bus(unsigned char busnr)
struct pci_bus *
pci_find_next_bus(const struct pci_bus *from)
{
struct list_head *n = from ? from->node.next : pci_root_buses.next;
struct list_head *n;
struct pci_bus *b = NULL;
WARN_ON(irqs_disabled());
spin_lock(&pci_bus_lock);
n = from ? from->node.next : pci_root_buses.next;
if (n != &pci_root_buses)
b = pci_bus_b(n);
spin_unlock(&pci_bus_lock);
return b;
}
......@@ -97,24 +112,36 @@ pci_find_slot(unsigned int bus, unsigned int devfn)
* device structure is returned. Otherwise, %NULL is returned.
* A new search is initiated by passing %NULL to the @from argument.
* Otherwise if @from is not %NULL, searches continue from next device on the global list.
*
* NOTE: Do not use this function anymore, use pci_get_subsys() instead, as
* the pci device returned by this function can disappear at any moment in
* time.
*/
struct pci_dev *
pci_find_subsys(unsigned int vendor, unsigned int device,
unsigned int ss_vendor, unsigned int ss_device,
const struct pci_dev *from)
{
struct list_head *n = from ? from->global_list.next : pci_devices.next;
struct list_head *n;
struct pci_dev *dev;
WARN_ON(irqs_disabled());
spin_lock(&pci_bus_lock);
n = from ? from->global_list.next : pci_devices.next;
while (n != &pci_devices) {
struct pci_dev *dev = pci_dev_g(n);
while (n && (n != &pci_devices)) {
dev = pci_dev_g(n);
if ((vendor == PCI_ANY_ID || dev->vendor == vendor) &&
(device == PCI_ANY_ID || dev->device == device) &&
(ss_vendor == PCI_ANY_ID || dev->subsystem_vendor == ss_vendor) &&
(ss_device == PCI_ANY_ID || dev->subsystem_device == ss_device))
return dev;
goto exit;
n = n->next;
}
return NULL;
dev = NULL;
exit:
spin_unlock(&pci_bus_lock);
return dev;
}
/**
......@@ -128,6 +155,10 @@ pci_find_subsys(unsigned int vendor, unsigned int device,
* returned. Otherwise, %NULL is returned.
* A new search is initiated by passing %NULL to the @from argument.
* Otherwise if @from is not %NULL, searches continue from next device on the global list.
*
* NOTE: Do not use this function anymore, use pci_get_device() instead, as
* the pci device returned by this function can disappear at any moment in
* time.
*/
struct pci_dev *
pci_find_device(unsigned int vendor, unsigned int device, const struct pci_dev *from)
......@@ -135,6 +166,77 @@ pci_find_device(unsigned int vendor, unsigned int device, const struct pci_dev *
return pci_find_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from);
}
/**
* pci_get_subsys - begin or continue searching for a PCI device by vendor/subvendor/device/subdevice id
* @vendor: PCI vendor id to match, or %PCI_ANY_ID to match all vendor ids
* @device: PCI device id to match, or %PCI_ANY_ID to match all device ids
* @ss_vendor: PCI subsystem vendor id to match, or %PCI_ANY_ID to match all vendor ids
* @ss_device: PCI subsystem device id to match, or %PCI_ANY_ID to match all device ids
* @from: Previous PCI device found in search, or %NULL for new search.
*
* Iterates through the list of known PCI devices. If a PCI device is
* found with a matching @vendor, @device, @ss_vendor and @ss_device, a pointer to its
* device structure is returned, and the reference count to the device is
* incremented. Otherwise, %NULL is returned. A new search is initiated by
* passing %NULL to the @from argument. Otherwise if @from is not %NULL,
* searches continue from next device on the global list.
* The reference count for @from is always decremented if it is not %NULL.
*/
struct pci_dev *
pci_get_subsys(unsigned int vendor, unsigned int device,
unsigned int ss_vendor, unsigned int ss_device,
struct pci_dev *from)
{
struct list_head *n;
struct pci_dev *dev;
WARN_ON(irqs_disabled());
spin_lock(&pci_bus_lock);
n = from ? from->global_list.next : pci_devices.next;
while (n && (n != &pci_devices)) {
dev = pci_dev_g(n);
if ((vendor == PCI_ANY_ID || dev->vendor == vendor) &&
(device == PCI_ANY_ID || dev->device == device) &&
(ss_vendor == PCI_ANY_ID || dev->subsystem_vendor == ss_vendor) &&
(ss_device == PCI_ANY_ID || dev->subsystem_device == ss_device))
goto exit;
n = n->next;
}
dev = NULL;
exit:
pci_dev_put(from);
dev = pci_dev_get(dev);
spin_unlock(&pci_bus_lock);
return dev;
}
/**
* pci_get_device - begin or continue searching for a PCI device by vendor/device id
* @vendor: PCI vendor id to match, or %PCI_ANY_ID to match all vendor ids
* @device: PCI device id to match, or %PCI_ANY_ID to match all device ids
* @from: Previous PCI device found in search, or %NULL for new search.
*
* Iterates through the list of known PCI devices. If a PCI device is
* found with a matching @vendor and @device, a pointer to its device structure is
* returned. Otherwise, %NULL is returned.
* A new search is initiated by passing %NULL to the @from argument.
* Otherwise if @from is not %NULL, searches continue from next device on the global list.
*
* Iterates through the list of known PCI devices. If a PCI device is
* found with a matching @vendor and @device, the reference count to the
* device is incremented and a pointer to its device structure is returned.
* Otherwise, %NULL is returned. A new search is initiated by passing %NULL
* to the @from argument. Otherwise if @from is not %NULL, searches continue
* from next device on the global list. The reference count for @from is
* always decremented if it is not %NULL.
*/
struct pci_dev *
pci_get_device(unsigned int vendor, unsigned int device, struct pci_dev *from)
{
return pci_get_subsys(vendor, device, PCI_ANY_ID, PCI_ANY_ID, from);
}
/**
* pci_find_device_reverse - begin or continue searching for a PCI device by vendor/device id
......@@ -151,16 +253,24 @@ pci_find_device(unsigned int vendor, unsigned int device, const struct pci_dev *
struct pci_dev *
pci_find_device_reverse(unsigned int vendor, unsigned int device, const struct pci_dev *from)
{
struct list_head *n = from ? from->global_list.prev : pci_devices.prev;
struct list_head *n;
struct pci_dev *dev;
while (n != &pci_devices) {
struct pci_dev *dev = pci_dev_g(n);
WARN_ON(irqs_disabled());
spin_lock(&pci_bus_lock);
n = from ? from->global_list.prev : pci_devices.prev;
while (n && (n != &pci_devices)) {
dev = pci_dev_g(n);
if ((vendor == PCI_ANY_ID || dev->vendor == vendor) &&
(device == PCI_ANY_ID || dev->device == device))
return dev;
goto exit;
n = n->prev;
}
return NULL;
dev = NULL;
exit:
spin_unlock(&pci_bus_lock);
return dev;
}
......@@ -179,15 +289,22 @@ pci_find_device_reverse(unsigned int vendor, unsigned int device, const struct p
struct pci_dev *
pci_find_class(unsigned int class, const struct pci_dev *from)
{
struct list_head *n = from ? from->global_list.next : pci_devices.next;
struct list_head *n;
struct pci_dev *dev;
while (n != &pci_devices) {
struct pci_dev *dev = pci_dev_g(n);
spin_lock(&pci_bus_lock);
n = from ? from->global_list.next : pci_devices.next;
while (n && (n != &pci_devices)) {
dev = pci_dev_g(n);
if (dev->class == class)
return dev;
goto exit;
n = n->next;
}
return NULL;
dev = NULL;
exit:
spin_unlock(&pci_bus_lock);
return dev;
}
EXPORT_SYMBOL(pci_find_bus);
......@@ -196,3 +313,5 @@ EXPORT_SYMBOL(pci_find_device);
EXPORT_SYMBOL(pci_find_device_reverse);
EXPORT_SYMBOL(pci_find_slot);
EXPORT_SYMBOL(pci_find_subsys);
EXPORT_SYMBOL(pci_get_device);
EXPORT_SYMBOL(pci_get_subsys);
......@@ -194,6 +194,18 @@ pcibios_resource_to_bus(struct pci_dev *dev, struct pci_bus_region *region,
#define pci_domain_nr(bus) ((struct pci_controller *)(bus)->sysdata)->index
/* Bus number == domain number until we get above 256 busses */
static inline int pci_name_bus(char *name, struct pci_bus *bus)
{
int domain = pci_domain_nr(bus)
if (domain < 256) {
sprintf(name, "%02x", domain);
} else {
sprintf(name, "%04x:%02x", domain, bus->number);
}
return 0;
}
#endif /* __KERNEL__ */
/* Values for the `which' argument to sys_pciconfig_iobase. */
......
......@@ -102,6 +102,16 @@ struct pci_controller {
#define PCI_CONTROLLER(busdev) ((struct pci_controller *) busdev->sysdata)
#define pci_domain_nr(busdev) (PCI_CONTROLLER(busdev)->segment)
static inline int pci_name_bus(char *name, struct pci_bus *bus)
{
if (pci_domain_nr(bus) == 0) {
sprintf(name, "%02x", bus->number);
} else {
sprintf(name, "%04x:%02x", pci_domain_nr(bus), bus->number);
}
return 0;
}
/* generic pci stuff */
#include <asm-generic/pci.h>
......
......@@ -269,6 +269,13 @@ pci_dac_dma_sync_single(struct pci_dev *pdev, dma64_addr_t dma_addr, size_t len,
/* Return the index of the PCI controller for device PDEV. */
#define pci_domain_nr(bus) ((struct pci_controller *)(bus)->sysdata)->index
/* Set the name of the bus as it appears in /proc/bus/pci */
static inline int pci_name_bus(char *name, struct pci_bus *bus)
{
sprintf(name, "%02x", bus->number);
return 0;
}
/* Map a range of PCI memory or I/O space for a device into user space */
int pci_mmap_page_range(struct pci_dev *pdev, struct vm_area_struct *vma,
enum pci_mmap_state mmap_state, int write_combine);
......
......@@ -88,6 +88,13 @@ static inline int pci_dma_supported(struct pci_dev *hwdev, u64 mask)
extern int pci_domain_nr(struct pci_bus *bus);
/* Set the name of the bus as it appears in /proc/bus/pci */
static inline int pci_name_bus(char *name, struct pci_bus *bus)
{
sprintf(name, "%02x", bus->number);
return 0;
}
struct vm_area_struct;
/* Map a range of PCI memory or I/O space for a device into user space */
int pci_mmap_page_range(struct pci_dev *pdev, struct vm_area_struct *vma,
......
......@@ -191,6 +191,13 @@ pci_dac_dma_sync_single(struct pci_dev *pdev, dma64_addr_t dma_addr, size_t len,
extern int pci_domain_nr(struct pci_bus *bus);
/* Set the name of the bus as it appears in /proc/bus/pci */
static inline int pci_name_bus(char *name, struct pci_bus *bus)
{
sprintf(name, "%02x", bus->number);
return 0;
}
/* Platform support for /proc/bus/pci/X/Y mmap()s. */
#define HAVE_PCI_MMAP
......
......@@ -486,6 +486,13 @@ struct pci_ops {
int (*write)(struct pci_bus *bus, unsigned int devfn, int where, int size, u32 val);
};
struct pci_raw_ops {
int (*read)(int dom, int bus, int dev, int func, int reg, int len, u32 *val);
int (*write)(int dom, int bus, int dev, int func, int reg, int len, u32 val);
};
extern struct pci_raw_ops *raw_pci_ops;
struct pci_bus_region {
unsigned long start;
unsigned long end;
......@@ -549,8 +556,8 @@ char *pci_class_name(u32 class);
void pci_read_bridge_bases(struct pci_bus *child);
struct resource *pci_find_parent_resource(const struct pci_dev *dev, struct resource *res);
int pci_get_interrupt_pin(struct pci_dev *dev, struct pci_dev **bridge);
extern struct pci_dev *pci_get_dev(struct pci_dev *dev);
extern void pci_put_dev(struct pci_dev *dev);
extern struct pci_dev *pci_dev_get(struct pci_dev *dev);
extern void pci_dev_put(struct pci_dev *dev);
extern void pci_remove_bus_device(struct pci_dev *dev);
......@@ -566,6 +573,10 @@ struct pci_dev *pci_find_slot (unsigned int bus, unsigned int devfn);
int pci_find_capability (struct pci_dev *dev, int cap);
struct pci_bus * pci_find_next_bus(const struct pci_bus *from);
struct pci_dev *pci_get_device (unsigned int vendor, unsigned int device, struct pci_dev *from);
struct pci_dev *pci_get_subsys (unsigned int vendor, unsigned int device,
unsigned int ss_vendor, unsigned int ss_device,
struct pci_dev *from);
int pci_bus_read_config_byte (struct pci_bus *bus, unsigned int devfn, int where, u8 *val);
int pci_bus_read_config_word (struct pci_bus *bus, unsigned int devfn, int where, u16 *val);
int pci_bus_read_config_dword (struct pci_bus *bus, unsigned int devfn, int where, u32 *val);
......@@ -688,6 +699,13 @@ static inline struct pci_dev *pci_find_subsys(unsigned int vendor, unsigned int
unsigned int ss_vendor, unsigned int ss_device, const struct pci_dev *from)
{ return NULL; }
static inline struct pci_dev *pci_get_device (unsigned int vendor, unsigned int device, struct pci_dev *from)
{ return NULL; }
static inline struct pci_dev *pci_get_subsys (unsigned int vendor, unsigned int device,
unsigned int ss_vendor, unsigned int ss_device, struct pci_dev *from)
{ return NULL; }
static inline void pci_set_master(struct pci_dev *dev) { }
static inline int pci_enable_device(struct pci_dev *dev) { return -EIO; }
static inline void pci_disable_device(struct pci_dev *dev) { }
......@@ -743,6 +761,20 @@ static inline int pci_module_init(struct pci_driver *drv)
return rc;
}
/*
* PCI domain support. Sometimes called PCI segment (eg by ACPI),
* a PCI domain is defined to be a set of PCI busses which share
* configuration space.
*/
#ifndef CONFIG_PCI_DOMAINS
static inline int pci_domain_nr(struct pci_bus *bus) { return 0; }
static inline int pci_name_bus(char *name, struct pci_bus *bus)
{
sprintf(name, "%02x", bus->number);
return 0;
}
#endif
#endif /* !CONFIG_PCI */
/* these helpers provide future and backwards compatibility
......@@ -800,15 +832,5 @@ extern int pci_pci_problems;
#define PCIPCI_VSFX 16
#define PCIPCI_ALIMAGIK 32
/*
* PCI domain support. Sometimes called PCI segment (eg by ACPI),
* a PCI domain is defined to be a set of PCI busses which share
* configuration space.
*/
#ifndef CONFIG_PCI_DOMAINS
static inline int pci_domain_nr(struct pci_bus *bus) { return 0; }
#endif
#endif /* __KERNEL__ */
#endif /* LINUX_PCI_H */
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment