Subversion Repositories shark

Rev

Rev 430 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
430 giacomo 1
#include <linuxcomp.h>
2
 
428 giacomo 3
#include <linux/pci.h>
4
#include <linux/module.h>
5
#include "pci.h"
6
 
440 giacomo 7
#define DEBUG
428 giacomo 8
 
9
#ifdef DEBUG
10
#define DBG(x...) printk(x)
11
#else
12
#define DBG(x...)
13
#endif
14
 
15
static void pci_free_resources(struct pci_dev *dev)
16
{
17
        int i;
18
 
19
        for (i = 0; i < PCI_NUM_RESOURCES; i++) {
20
                struct resource *res = dev->resource + i;
21
                if (res->parent)
22
                        release_resource(res);
23
        }
24
}
25
 
26
static void pci_destroy_dev(struct pci_dev *dev)
27
{
28
        pci_proc_detach_device(dev);
29
        device_unregister(&dev->dev);
30
 
31
        /* Remove the device from the device lists, and prevent any further
32
         * list accesses from this device */
33
        spin_lock(&pci_bus_lock);
34
        list_del(&dev->bus_list);
35
        list_del(&dev->global_list);
36
        dev->bus_list.next = dev->bus_list.prev = NULL;
37
        dev->global_list.next = dev->global_list.prev = NULL;
38
        spin_unlock(&pci_bus_lock);
39
 
40
        pci_free_resources(dev);
41
        pci_dev_put(dev);
42
}
43
 
44
/**
45
 * pci_remove_device_safe - remove an unused hotplug device
46
 * @dev: the device to remove
47
 *
48
 * Delete the device structure from the device lists and
49
 * notify userspace (/sbin/hotplug), but only if the device
50
 * in question is not being used by a driver.
51
 * Returns 0 on success.
52
 */
53
int pci_remove_device_safe(struct pci_dev *dev)
54
{
55
        if (pci_dev_driver(dev))
56
                return -EBUSY;
57
        pci_destroy_dev(dev);
58
        return 0;
59
}
60
EXPORT_SYMBOL(pci_remove_device_safe);
61
 
62
/**
63
 * pci_remove_bus_device - remove a PCI device and any children
64
 * @dev: the device to remove
65
 *
66
 * Remove a PCI device from the device lists, informing the drivers
67
 * that the device has been removed.  We also remove any subordinate
68
 * buses and children in a depth-first manner.
69
 *
70
 * For each device we remove, delete the device structure from the
71
 * device lists, remove the /proc entry, and notify userspace
72
 * (/sbin/hotplug).
73
 */
74
void pci_remove_bus_device(struct pci_dev *dev)
75
{
76
        if (dev->subordinate) {
77
                struct pci_bus *b = dev->subordinate;
78
 
79
                pci_remove_behind_bridge(dev);
80
                pci_proc_detach_bus(b);
81
 
82
                spin_lock(&pci_bus_lock);
83
                list_del(&b->node);
84
                spin_unlock(&pci_bus_lock);
85
 
86
                kfree(b);
87
                dev->subordinate = NULL;
88
        }
89
 
90
        pci_destroy_dev(dev);
91
}
92
 
93
/**
94
 * pci_remove_behind_bridge - remove all devices behind a PCI bridge
95
 * @dev: PCI bridge device
96
 *
97
 * Remove all devices on the bus, except for the parent bridge.
98
 * This also removes any child buses, and any devices they may
99
 * contain in a depth-first manner.
100
 */
101
void pci_remove_behind_bridge(struct pci_dev *dev)
102
{
103
        struct list_head *l, *n;
104
 
105
        if (dev->subordinate) {
106
                list_for_each_safe(l, n, &dev->subordinate->devices) {
107
                        struct pci_dev *dev = pci_dev_b(l);
108
 
109
                        pci_remove_bus_device(dev);
110
                }
111
        }
112
}
113
 
114
EXPORT_SYMBOL(pci_remove_bus_device);
115
EXPORT_SYMBOL(pci_remove_behind_bridge);