Annotation of sys/arch/mvme68k/mvme68k/autoconf.c, Revision 1.1.1.1
1.1 nbrk 1: /* $OpenBSD: autoconf.c,v 1.40 2007/06/15 01:19:08 deraadt Exp $ */
2:
3: /*
4: * Copyright (c) 1995 Theo de Raadt
5: *
6: * Redistribution and use in source and binary forms, with or without
7: * modification, are permitted provided that the following conditions
8: * are met:
9: * 1. Redistributions of source code must retain the above copyright
10: * notice, this list of conditions and the following disclaimer.
11: * 2. Redistributions in binary form must reproduce the above copyright
12: * notice, this list of conditions and the following disclaimer in the
13: * documentation and/or other materials provided with the distribution.
14: *
15: * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS
16: * OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17: * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18: * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY
19: * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25: * SUCH DAMAGE.
26: *
27: * Copyright (c) 1988 University of Utah.
28: * Copyright (c) 1982, 1986, 1990, 1993
29: * The Regents of the University of California. All rights reserved.
30: *
31: * This code is derived from software contributed to Berkeley by
32: * the Systems Programming Group of the University of Utah Computer
33: * Science Department.
34: *
35: * Redistribution and use in source and binary forms, with or without
36: * modification, are permitted provided that the following conditions
37: * are met:
38: * 1. Redistributions of source code must retain the above copyright
39: * notice, this list of conditions and the following disclaimer.
40: * 2. Redistributions in binary form must reproduce the above copyright
41: * notice, this list of conditions and the following disclaimer in the
42: * documentation and/or other materials provided with the distribution.
43: * 3. Neither the name of the University nor the names of its contributors
44: * may be used to endorse or promote products derived from this software
45: * without specific prior written permission.
46: *
47: * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
48: * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
49: * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
50: * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
51: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
52: * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
53: * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
54: * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
55: * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
56: * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
57: * SUCH DAMAGE.
58: *
59: * from: Utah $Hdr: autoconf.c 1.36 92/12/20$
60: *
61: * @(#)autoconf.c 8.2 (Berkeley) 1/12/94
62: */
63:
64: /*
65: * Setup the system to run on the current machine.
66: *
67: * cpu_configure() is called at boot time. Available
68: * devices are determined (from possibilities mentioned in ioconf.c),
69: * and the drivers are initialized.
70: */
71:
72: #include <sys/param.h>
73: #include <sys/systm.h>
74: #include <sys/extent.h>
75: #include <sys/malloc.h>
76: #include <sys/buf.h>
77: #include <sys/dkstat.h>
78: #include <sys/conf.h>
79: #include <sys/reboot.h>
80: #include <sys/device.h>
81: #include <sys/disklabel.h>
82:
83: #include <machine/vmparam.h>
84: #include <machine/autoconf.h>
85: #include <machine/cpu.h>
86: #include <machine/pte.h>
87:
88: #include <uvm/uvm_extern.h>
89:
90: #include <scsi/scsi_all.h>
91: #include <scsi/scsiconf.h>
92: #include <dev/cons.h>
93:
94: int mainbus_print(void *, const char *);
95: int mainbus_scan(struct device *, void *, void *);
96:
97: extern void init_intrs(void);
98: extern void dumpconf(void);
99:
100: /* boot device information */
101: paddr_t bootaddr;
102: int bootctrllun, bootdevlun, bootpart;
103: struct device *bootdv;
104:
105: /*
106: * XXX some storage space must be allocated statically because of
107: * early console init
108: */
109: char extiospace[EXTENT_FIXED_STORAGE_SIZE(8)];
110:
111: struct extent *extio;
112: extern vaddr_t extiobase;
113:
114: void mainbus_attach(struct device *, struct device *, void *);
115: int mainbus_match(struct device *, void *, void *);
116:
117: struct cfattach mainbus_ca = {
118: sizeof(struct device), mainbus_match, mainbus_attach
119: };
120:
121: struct cfdriver mainbus_cd = {
122: NULL, "mainbus", DV_DULL
123: };
124:
125: int
126: mainbus_match(parent, cf, args)
127: struct device *parent;
128: void *cf;
129: void *args;
130: {
131: return (1);
132: }
133:
134: int
135: mainbus_print(args, bus)
136: void *args;
137: const char *bus;
138: {
139: struct confargs *ca = args;
140:
141: if (ca->ca_paddr != (paddr_t)-1)
142: printf(" addr 0x%x", (u_int32_t)ca->ca_paddr);
143: return (UNCONF);
144: }
145:
146: int
147: mainbus_scan(parent, child, args)
148: struct device *parent;
149: void *child, *args;
150: {
151: struct cfdata *cf = child;
152: struct confargs oca;
153:
154: bzero(&oca, sizeof oca);
155: oca.ca_paddr = cf->cf_loc[0];
156: oca.ca_vaddr = (vaddr_t)-1;
157: oca.ca_ipl = -1;
158: oca.ca_bustype = BUS_MAIN;
159: oca.ca_name = cf->cf_driver->cd_name;
160: if ((*cf->cf_attach->ca_match)(parent, cf, &oca) == 0)
161: return (0);
162: config_attach(parent, cf, &oca, mainbus_print);
163: return (1);
164: }
165:
166: void
167: mainbus_attach(parent, self, args)
168: struct device *parent, *self;
169: void *args;
170: {
171: printf("\n");
172:
173: /* XXX
174: * should have a please-attach-first list for mainbus,
175: * to ensure that the pcc/vme2/mcc chips are attached
176: * first.
177: */
178:
179: (void)config_search(mainbus_scan, self, args);
180: }
181:
182: /*
183: * Determine mass storage and memory configuration for a machine.
184: */
185: void
186: cpu_configure()
187: {
188: init_intrs();
189:
190: extio = extent_create("extio",
191: (u_long)extiobase, (u_long)extiobase + ctob(EIOMAPSIZE),
192: M_DEVBUF, extiospace, sizeof(extiospace), EX_NOWAIT);
193:
194: if (config_rootfound("mainbus", NULL) == NULL)
195: panic("autoconfig failed, no root");
196:
197: printf("boot device: %s\n",
198: (bootdv) ? bootdv->dv_xname : "<unknown>");
199: cold = 0;
200: }
201:
202: void
203: diskconf(void)
204: {
205: setroot(bootdv, bootpart, RB_USERREQ);
206: dumpconf();
207: }
208:
209: /*
210: * Allocate/deallocate a cache-inhibited range of kernel virtual address
211: * space mapping the indicated physical address range [pa - pa+size)
212: */
213: vaddr_t
214: mapiodev(pa, size)
215: paddr_t pa;
216: int size;
217: {
218: int error;
219: paddr_t base;
220: vaddr_t va, iova;
221:
222: if (size <= 0)
223: return NULL;
224:
225: base = pa & PAGE_MASK;
226: pa = trunc_page(pa);
227: size = round_page(base + size);
228:
229: error = extent_alloc(extio, size, EX_NOALIGN, 0, EX_NOBOUNDARY,
230: EX_NOWAIT | EX_MALLOCOK, &iova);
231:
232: if (error != 0)
233: return NULL;
234:
235: va = iova;
236: while (size != 0) {
237: pmap_kenter_cache(va, pa, PG_RW | PG_CI);
238: size -= PAGE_SIZE;
239: va += PAGE_SIZE;
240: pa += PAGE_SIZE;
241: }
242: pmap_update(pmap_kernel());
243: return (iova + base);
244: }
245:
246: void
247: unmapiodev(kva, size)
248: vaddr_t kva;
249: int size;
250: {
251: int error;
252: vaddr_t va;
253:
254: #ifdef DEBUG
255: if (kva < extiobase || kva + size >= extiobase + ctob(EIOMAPSIZE))
256: panic("unmapiodev: bad address");
257: #endif
258:
259: va = trunc_page(kva);
260: size = round_page(kva + size) - va;
261: pmap_kremove(va, size);
262: pmap_update(pmap_kernel());
263:
264: error = extent_free(extio, va, size, EX_NOWAIT);
265: #ifdef DIAGNOSTIC
266: if (error != 0)
267: printf("unmapiodev: extent_free failed\n");
268: #endif
269: }
270:
271: void
272: device_register(struct device *dev, void *aux)
273: {
274: if (bootpart == -1) /* ignore flag from controller driver? */
275: return;
276:
277: /*
278: * scsi: sd,cd
279: */
280: if (strncmp("sd", dev->dv_xname, 2) == 0 ||
281: strncmp("cd", dev->dv_xname, 2) == 0) {
282: struct scsi_attach_args *sa = aux;
283: int target, lun;
284: #ifdef MVME147
285: /*
286: * The 147 can only boot from the built-in scsi controller,
287: * and stores the scsi id as the controller number.
288: */
289: if (cputyp == CPU_147) {
290: target = bootctrllun;
291: lun = 0;
292: } else
293: #endif
294: {
295: target = bootdevlun >> 4;
296: lun = bootdevlun & 0x0f;
297: }
298:
299: if (sa->sa_sc_link->target == target &&
300: sa->sa_sc_link->lun == lun) {
301: bootdv = dev;
302: return;
303: }
304: }
305:
306: /*
307: * ethernet: ie,le
308: */
309: else if (strncmp("ie", dev->dv_xname, 2) == 0 ||
310: strncmp("le", dev->dv_xname, 2) == 0) {
311: struct confargs *ca = aux;
312:
313: if (ca->ca_paddr == bootaddr) {
314: bootdv = dev;
315: return;
316: }
317: }
318: }
319:
320: struct nam2blk nam2blk[] = {
321: { "sd", 4 },
322: { "st", 7 },
323: { "rd", 9 },
324: { NULL, -1 }
325: };
CVSweb