Commit 4ee2f161 authored by Greg Kroah-Hartman's avatar Greg Kroah-Hartman

PCI: add pci_get_dev() and pci_put_dev()

Move the PCI core to start using these, enabling proper reference counting
on struct pci_dev.
parent 07ca08b1
......@@ -92,7 +92,7 @@ void __devinit pci_bus_add_devices(struct pci_bus *bus)
if (!list_empty(&dev->global_list))
continue;
device_register(&dev->dev);
device_add(&dev->dev);
list_add_tail(&dev->global_list, &pci_devices);
#ifdef CONFIG_PROC_FS
pci_proc_attach_device(dev);
......
......@@ -275,7 +275,7 @@ void pci_remove_bus_device(struct pci_dev *dev)
pci_proc_detach_device(dev);
#endif
kfree(dev);
pci_put_dev(dev);
}
/**
......
......@@ -199,6 +199,45 @@ static int pci_bus_match(struct device * dev, struct device_driver * drv)
return 0;
}
/**
* pci_get_dev - 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.
*
* A pointer to the device with the incremented reference counter is returned.
*/
struct pci_dev *pci_get_dev (struct pci_dev *dev)
{
struct device *tmp;
if (!dev)
return NULL;
tmp = get_device(&dev->dev);
if (tmp)
return to_pci_dev(tmp);
else
return NULL;
}
/**
* pci_put_dev - 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)
{
if (dev)
put_device(&dev->dev);
}
struct bus_type pci_bus_type = {
.name = "pci",
.match = pci_bus_match,
......@@ -217,3 +256,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);
......@@ -462,6 +462,21 @@ int pci_setup_device(struct pci_dev * dev)
return 0;
}
/**
* pci_release_dev - free a pci device structure when all users of it are finished.
* @dev: device that's been disconnected
*
* Will be called only by the device core when all users of this pci device are
* done.
*/
static void pci_release_dev(struct device *dev)
{
struct pci_dev *pci_dev;
pci_dev = to_pci_dev(dev);
kfree(pci_dev);
}
/*
* Read the config data for a PCI device, sanity-check it
* and fill in the dev structure...
......@@ -506,6 +521,9 @@ pci_scan_device(struct pci_bus *bus, int devfn)
kfree(dev);
return NULL;
}
device_initialize(&dev->dev);
dev->dev.release = pci_release_dev;
pci_get_dev(dev);
pci_name_device(dev);
......
......@@ -556,6 +556,8 @@ 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_setup_device(struct pci_dev *dev);
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);
/* Generic PCI functions exported to card drivers */
......
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