xref: /netbsd/sys/arch/cesfic/cesfic/autoconf.c (revision bf9ec67e)
1 /*	$NetBSD: autoconf.c,v 1.2 2001/07/26 15:45:51 drochner Exp $	*/
2 
3 /*
4  * Copyright (c) 1997, 1999
5  *	Matthias Drochner.  All rights reserved.
6  *
7  * Redistribution and use in source and binary forms, with or without
8  * modification, are permitted provided that the following conditions
9  * are met:
10  * 1. Redistributions of source code must retain the above copyright
11  *    notice, this list of conditions and the following disclaimer.
12  * 2. Redistributions in binary form must reproduce the above copyright
13  *    notice, this list of conditions and the following disclaimer in the
14  *    documentation and/or other materials provided with the distribution.
15  *
16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21  * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22  * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23  * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25  * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26  *
27  */
28 
29 #include <sys/param.h>
30 #include <sys/systm.h>
31 #include <sys/buf.h>
32 #include <sys/conf.h>
33 #include <sys/device.h>
34 #include <sys/device.h>
35 #include <sys/disklabel.h>
36 #include <sys/malloc.h>
37 #include <sys/map.h>
38 #include <sys/mount.h>
39 #include <sys/queue.h>
40 #include <sys/reboot.h>
41 #include <sys/tty.h>
42 #include <sys/kernel.h>
43 
44 #include <uvm/uvm_extern.h>
45 
46 #include <machine/autoconf.h>
47 #include <machine/vmparam.h>
48 #include <machine/cpu.h>
49 #include <machine/pmap.h>
50 #include <machine/pte.h>
51 
52 #include <cesfic/cesfic/isr.h>
53 
54 struct	device *booted_device;
55 int	booted_partition;
56 
57 u_int	bootdev;
58 
59 struct evcnt evcnt_fpsp_unimp, evcnt_fpsp_unsupp;
60 
61 int	mainbusmatch __P((struct device *, struct cfdata *, void *));
62 void	mainbusattach __P((struct device *, struct device *, void *));
63 int	mainbussearch __P((struct device *, struct cfdata *, void *));
64 
65 struct cfattach mainbus_ca = {
66 	sizeof(struct device), mainbusmatch, mainbusattach
67 };
68 
69 int
70 mainbusmatch(parent, match, aux)
71 	struct device *parent;
72 	struct cfdata *match;
73 	void *aux;
74 {
75 	static int mainbus_matched = 0;
76 
77 	/* Allow only one instance. */
78 	if (mainbus_matched)
79 		return (0);
80 
81 	mainbus_matched = 1;
82 	return (1);
83 }
84 
85 void
86 mainbusattach(parent, self, aux)
87 	struct device *parent, *self;
88 	void *aux;
89 {
90 
91 	printf("\n");
92 
93 #ifdef FPSP /* XXX this shouldn't be here but in a "cpu" node */
94 	evcnt_attach(self, "fpuni", &evcnt_fpsp_unimp);
95 	evcnt_attach(self, "fpund", &evcnt_fpsp_unsupp);
96 #endif
97 
98 	/* Search for and attach children. */
99 	config_search(mainbussearch, self, NULL);
100 }
101 
102 int
103 mainbussearch(parent, cf, aux)
104 	struct device *parent;
105 	struct cfdata *cf;
106 	void *aux;
107 {
108 
109 	if ((*cf->cf_attach->ca_match)(parent, cf, NULL) > 0)
110 		config_attach(parent, cf, NULL, NULL);
111 	return (0);
112 }
113 
114 int
115 mainbus_map(physaddr, size, cacheable, virtaddr)
116 	u_long physaddr;
117 	int size;
118 	int cacheable;
119 	void ** virtaddr;
120 {
121 
122 	u_long pa, endpa;
123 	vm_offset_t va;
124 
125 	pa = m68k_trunc_page(physaddr);
126 	endpa = m68k_round_page(physaddr + size);
127 
128 #ifdef DIAGNOSTIC
129 	if (endpa <= pa)
130 		panic("bus_mem_add_mapping: overflow");
131 #endif
132 
133 	va = uvm_km_valloc(kernel_map, endpa - pa);
134 	if (va == 0)
135 		return (ENOMEM);
136 
137 	*virtaddr = (void*)(va + (physaddr & PGOFSET));
138 	for (; pa < endpa; pa += NBPG, va += NBPG) {
139 		pmap_kenter_pa(va, pa, VM_PROT_READ | VM_PROT_WRITE);
140 		if (!cacheable) {
141 			pt_entry_t *pte = kvtopte(va);
142 			*pte |= PG_CI;
143 			*pte &= ~PG_CCB;
144 		}
145 	}
146 
147 	return (0);
148 }
149 
150 void
151 cpu_configure()
152 {
153 
154 	isrinit();
155 
156 	(void)splhigh();
157 	if (config_rootfound("mainbus", "mainbus") == NULL)
158 		panic("no mainbus found");
159 
160 	(void)spl0();
161 	cold = 0;
162 
163 	isrprintlevels();
164 }
165 
166 void
167 cpu_rootconf()
168 {
169 	setroot(0, 0);
170 }
171