Merge branch 'master' of git://github.com/illumos/illumos-gate
[unleashed.git] / usr / src / grub / grub-0.97 / netboot / config.c
blob39f70c474d55bb8efa930b6ae03dcdc619f9c54e
1 /*
2 * This program is free software; you can redistribute it and/or
3 * modify it under the terms of the GNU General Public License as
4 * published by the Free Software Foundation; either version 2, or (at
5 * your option) any later version.
6 */
8 #include "grub.h"
9 #include "pci.h"
10 #include "isa.h"
11 #include "nic.h"
13 #ifdef CONFIG_PCI
14 static int pci_probe(struct dev *dev, const char *type_name)
17 * NIC probing is in pci device order, followed by the
18 * link order of the drivers. A driver that matches
19 * on vendor and device id will supersede a driver
20 * that matches on pci class.
22 * If you want to probe for another device behind the same pci
23 * device just increment index. And the previous probe call
24 * will be repeated.
26 struct pci_probe_state *state = &dev->state.pci;
27 printf("Probing pci %s...\n", type_name);
28 if (dev->how_probe == PROBE_FIRST) {
29 state->advance = 1;
30 state->dev.driver = 0;
31 state->dev.bus = 0;
32 state->dev.devfn = 0;
33 dev->index = -1;
35 for(;;) {
36 if ((dev->how_probe != PROBE_AWAKE) && state->advance) {
37 find_pci(dev->type, &state->dev);
38 dev->index = -1;
40 state->advance = 1;
42 if (state->dev.driver == 0)
43 break;
45 #if 0
46 /* FIXME the romaddr code needs a total rethought to be useful */
47 if (state->dev.romaddr != ((unsigned long) rom.rom_segment << 4)) {
48 continue;
50 #endif
51 if (dev->how_probe != PROBE_AWAKE) {
52 dev->type_index++;
54 dev->devid.bus_type = PCI_BUS_TYPE;
55 dev->devid.vendor_id = htons(state->dev.vendor);
56 dev->devid.device_id = htons(state->dev.dev_id);
57 /* FIXME how do I handle dev->index + PROBE_AGAIN?? */
59 printf("[%s]", state->dev.name);
60 if (state->dev.driver->probe(dev, &state->dev)) {
61 state->advance = (dev->index == -1);
62 return PROBE_WORKED;
64 putchar('\n');
66 return PROBE_FAILED;
68 #endif
70 #ifdef CONFIG_ISA
71 static int isa_probe(struct dev *dev, const char *type_name)
74 * NIC probing is in the order the drivers were linked togeter.
75 * If for some reason you want to change the order,
76 * just change the order you list the drivers in.
78 struct isa_probe_state *state = &dev->state.isa;
79 printf("Probing isa %s...\n", type_name);
80 if (dev->how_probe == PROBE_FIRST) {
81 state->advance = 0;
82 state->driver = isa_drivers;
83 dev->index = -1;
85 for(;;)
87 if ((dev->how_probe != PROBE_AWAKE) && state->advance) {
88 state->driver++;
89 dev->index = -1;
91 state->advance = 1;
93 if (state->driver >= isa_drivers_end)
94 break;
96 if (state->driver->type != dev->type)
97 continue;
99 if (dev->how_probe != PROBE_AWAKE) {
100 dev->type_index++;
102 printf("[%s]", state->driver->name);
103 dev->devid.bus_type = ISA_BUS_TYPE;
104 /* FIXME how do I handle dev->index + PROBE_AGAIN?? */
105 /* driver will fill in vendor and device IDs */
106 if (state->driver->probe(dev, state->driver->ioaddrs)) {
107 state->advance = (dev->index == -1);
108 return PROBE_WORKED;
110 putchar('\n');
112 return PROBE_FAILED;
114 #else
115 #define isa_probe(d,tn) (PROBE_FAILED)
116 #endif
117 static const char *driver_name[] = {
118 "nic",
119 "disk",
120 "floppy",
122 int probe(struct dev *dev)
124 const char *type_name;
126 EnterFunction("probe");
128 type_name = "";
129 if ((dev->type >= 0) &&
130 (dev->type < sizeof(driver_name)/sizeof(driver_name[0]))) {
131 type_name = driver_name[dev->type];
133 if (dev->how_probe == PROBE_FIRST) {
134 dev->to_probe = PROBE_PCI;
135 memset(&dev->state, 0, sizeof(dev->state));
137 if (dev->to_probe == PROBE_PCI) {
138 dev->how_probe = pci_probe(dev, type_name);
139 if (dev->how_probe == PROBE_FAILED) {
140 dev->to_probe = PROBE_ISA;
143 if (dev->to_probe == PROBE_ISA) {
144 dev->how_probe = isa_probe(dev, type_name);
145 if (dev->how_probe == PROBE_FAILED) {
146 dev->to_probe = PROBE_NONE;
149 if ((dev->to_probe != PROBE_PCI) &&
150 (dev->to_probe != PROBE_ISA)) {
151 dev->how_probe = PROBE_FAILED;
155 LeaveFunction("probe");
156 return dev->how_probe;
159 void disable(struct dev *dev)
161 if (dev->disable) {
162 dev->disable(dev);
163 dev->disable = 0;