Linux Kernel  3.7.1
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
ide-scan-pci.c
Go to the documentation of this file.
1 /*
2  * support for probing IDE PCI devices in the PCI bus order
3  *
4  * Copyright (c) 1998-2000 Andre Hedrick <[email protected]>
5  * Copyright (c) 1995-1998 Mark Lord
6  *
7  * May be copied or modified under the terms of the GNU General Public License
8  */
9 
10 #include <linux/kernel.h>
11 #include <linux/init.h>
12 #include <linux/module.h>
13 #include <linux/ide.h>
14 
15 /*
16  * Module interfaces
17  */
18 
19 static int pre_init = 1; /* Before first ordered IDE scan */
20 static LIST_HEAD(ide_pci_drivers);
21 
22 /*
23  * __ide_pci_register_driver - attach IDE driver
24  * @driver: pci driver
25  * @module: owner module of the driver
26  *
27  * Registers a driver with the IDE layer. The IDE layer arranges that
28  * boot time setup is done in the expected device order and then
29  * hands the controllers off to the core PCI code to do the rest of
30  * the work.
31  *
32  * Returns are the same as for pci_register_driver
33  */
34 
36  const char *mod_name)
37 {
38  if (!pre_init)
39  return __pci_register_driver(driver, module, mod_name);
40  driver->driver.owner = module;
41  list_add_tail(&driver->node, &ide_pci_drivers);
42  return 0;
43 }
45 
55 static int __init ide_scan_pcidev(struct pci_dev *dev)
56 {
57  struct list_head *l;
58  struct pci_driver *d;
59 
60  list_for_each(l, &ide_pci_drivers) {
61  d = list_entry(l, struct pci_driver, node);
62  if (d->id_table) {
63  const struct pci_device_id *id =
64  pci_match_id(d->id_table, dev);
65 
66  if (id != NULL && d->probe(dev, id) >= 0) {
67  dev->driver = d;
68  pci_dev_get(dev);
69  return 1;
70  }
71  }
72  }
73  return 0;
74 }
75 
84 static int __init ide_scan_pcibus(void)
85 {
86  struct pci_dev *dev = NULL;
87  struct pci_driver *d;
88  struct list_head *l, *n;
89 
90  pre_init = 0;
91  for_each_pci_dev(dev)
92  ide_scan_pcidev(dev);
93 
94  /*
95  * Hand the drivers over to the PCI layer now we
96  * are post init.
97  */
98 
99  list_for_each_safe(l, n, &ide_pci_drivers) {
100  list_del(l);
101  d = list_entry(l, struct pci_driver, node);
102  if (__pci_register_driver(d, d->driver.owner,
103  d->driver.mod_name))
104  printk(KERN_ERR "%s: failed to register %s driver\n",
105  __func__, d->driver.mod_name);
106  }
107 
108  return 0;
109 }
110 
111 module_init(ide_scan_pcibus);