|
|
1.1 root 1: /*
2: * Mach Operating System
3: * Copyright (c) 1993-1989 Carnegie Mellon University
4: * All Rights Reserved.
5: *
6: * Permission to use, copy, modify and distribute this software and its
7: * documentation is hereby granted, provided that both the copyright
8: * notice and this permission notice appear in all copies of the
9: * software, derivative works or modified versions, and any portions
10: * thereof, and that both notices appear in supporting documentation.
11: *
12: * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13: * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14: * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15: *
16: * Carnegie Mellon requests users of this software to return to
17: *
18: * Software Distribution Coordinator or [email protected]
19: * School of Computer Science
20: * Carnegie Mellon University
21: * Pittsburgh PA 15213-3890
22: *
23: * any improvements or extensions that they make and grant Carnegie Mellon
24: * the rights to redistribute these changes.
25: */
26: /*
27: * File: busses.c
28: * Author: Alessandro Forin, Carnegie Mellon University
29: * Date: 4/90
30: *
31: * Generic autoconfiguration functions,
32: * usable to probe and attach devices
33: * on any bus that suits the generic bus
34: * structure, such as VME, TURBOChannel,
35: * and all the VAX busses.
36: *
37: */
38:
39: #include <mach/boolean.h>
40: #include <mach/std_types.h>
41: #include <chips/busses.h>
42:
43:
44:
45:
46: /*
47: * configure_bus_master
48: *
49: * Given the name of a bus_ctlr, look it up in the
50: * init table. If found, probe it. If there can be
51: * slaves attached, walk the device's init table
52: * for those that might be attached to this controller.
53: * Call the 'slave' function on each one to see if
54: * ok, then the 'attach' one.
55: *
56: * Returns 0 if the controller is not there.
57: *
58: */
59: boolean_t configure_bus_master(
60: char *name,
61: vm_offset_t virt,
62: vm_offset_t phys,
63: int adpt_no,
64: char *bus_name)
65: {
66: register struct bus_device *device;
67: register struct bus_ctlr *master;
68: register struct bus_driver *driver;
69:
70: int found = 0;
71:
72: /*
73: * Match the name in the table, then pick the entry that has the
74: * right adaptor number, or one that has it wildcarded. Entries
75: * already allocated are marked alive, skip them.
76: */
77: for (master = bus_master_init; master->driver; master++) {
78: if (master->alive)
79: continue;
80: if (((master->adaptor == adpt_no) || (master->adaptor == '?')) &&
81: (strcmp(master->name, name) == 0)) {
82: found = 1;
83: break;
84: }
85: }
86:
87: if (!found)
88: return FALSE;
89:
90: /*
91: * Found a match, probe it
92: */
93: driver = master->driver;
94: if ((*driver->probe) (virt, master) == 0)
95: return FALSE;
96:
97: master->alive = 1;
98: master->adaptor = adpt_no;
99:
100: /*
101: * Remember which controller this device is attached to
102: */
103: driver->minfo[master->unit] = master;
104:
105: printf("%s%d: at %s%d\n", master->name, master->unit, bus_name, adpt_no);
106:
107: /*
108: * Now walk all devices to check those that might be attached to this
109: * controller. We match the unallocated ones that have the right
110: * controller number, or that have a widcarded controller number.
111: */
112: for (device = bus_device_init; device->driver; device++) {
113: int ctlr;
114: if (device->alive || device->driver != driver ||
115: (device->adaptor != '?' && device->adaptor != adpt_no))
116: continue;
117: ctlr = device->ctlr;
118: if (ctlr == '?') device->ctlr = master->unit;
119: /*
120: * A matching entry. See if the slave-probing routine is
121: * happy.
122: */
123: if ((device->ctlr != master->unit) ||
124: ((*driver->slave) (device, virt) == 0)) {
125: device->ctlr = ctlr;
126: continue;
127: }
128:
129: device->alive = 1;
130: device->adaptor = adpt_no;
131: device->ctlr = master->unit;
132:
133: /*
134: * Save a backpointer to the controller
135: */
136: device->mi = master;
137:
138: /*
139: * ..and to the device
140: */
141: driver->dinfo[device->unit] = device;
142:
143: if (device->slave >= 0)
144: printf(" %s%d: at %s%d slave %d",
145: device->name, device->unit,
146: driver->mname, master->unit, device->slave);
147: else
148: printf(" %s%d: at %s%d",
149: device->name, device->unit,
150: driver->mname, master->unit);
151:
152: /*
153: * Now attach this slave
154: */
155: (*driver->attach) (device);
156: printf("\n");
157: }
158: return TRUE;
159: }
160:
161: /*
162: * configure_bus_device
163: *
164: * Given the name of a bus_device, look it up in the
165: * init table. If found, probe it. If it is present,
166: * call the driver's 'attach' function.
167: *
168: * Returns 0 if the device is not there.
169: *
170: */
171: boolean_t configure_bus_device(
172: char *name,
173: vm_offset_t virt,
174: vm_offset_t phys,
175: int adpt_no,
176: char *bus_name)
177: {
178: register struct bus_device *device;
179: register struct bus_driver *driver;
180:
181: int found = 0;
182:
183: /*
184: * Walk all devices to find one with the right name
185: * and adaptor number (or wildcard). The entry should
186: * be unallocated, and also the slave number should
187: * be wildcarded.
188: */
189: for (device = bus_device_init; device->driver; device++) {
190: if (device->alive)
191: continue;
192: if (((device->adaptor == adpt_no) || (device->adaptor == '?')) &&
193: (device->slave == -1) &&
194: ((!device->phys_address) ||
195: ((device->phys_address == phys) && (device->address == virt))) &&
196: (strcmp(device->name, name) == 0)) {
197: found = 1;
198: break;
199: }
200: }
201:
202: if (!found)
203: return FALSE;
204:
205: /*
206: * Found an entry, probe the device
207: */
208: driver = device->driver;
209: if ((*driver->probe) (virt, (struct bus_ctlr *)device) == 0)
210: return FALSE;
211:
212: device->alive = 1;
213: device->adaptor = adpt_no;
214:
215: printf("%s%d: at %s%d", device->name, device->unit, bus_name, adpt_no);
216:
217: /*
218: * Remember which driver this device is attached to
219: */
220: driver->dinfo[device->unit] = device;
221:
222: /*
223: * Attach the device
224: */
225: (*driver->attach) (device);
226: printf("\n");
227:
228: return TRUE;
229: }
230:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.