xref: /netbsd/sys/arch/mvmeppc/mvmeppc/machdep.c (revision 6550d01e)
1 /*	$NetBSD: machdep.c,v 1.27 2010/12/20 00:25:39 matt Exp $	*/
2 
3 /*
4  * Copyright (C) 1995, 1996 Wolfgang Solfrank.
5  * Copyright (C) 1995, 1996 TooLs GmbH.
6  * All rights reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  * 1. Redistributions of source code must retain the above copyright
12  *    notice, this list of conditions and the following disclaimer.
13  * 2. Redistributions in binary form must reproduce the above copyright
14  *    notice, this list of conditions and the following disclaimer in the
15  *    documentation and/or other materials provided with the distribution.
16  * 3. All advertising materials mentioning features or use of this software
17  *    must display the following acknowledgement:
18  *	This product includes software developed by TooLs GmbH.
19  * 4. The name of TooLs GmbH may not be used to endorse or promote products
20  *    derived from this software without specific prior written permission.
21  *
22  * THIS SOFTWARE IS PROVIDED BY TOOLS GMBH ``AS IS'' AND ANY EXPRESS OR
23  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
24  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
25  * IN NO EVENT SHALL TOOLS GMBH BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
26  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
27  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS;
28  * OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY,
29  * WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR
30  * OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
31  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
32  */
33 
34 #include <sys/cdefs.h>
35 __KERNEL_RCSID(0, "$NetBSD: machdep.c,v 1.27 2010/12/20 00:25:39 matt Exp $");
36 
37 #include "opt_compat_netbsd.h"
38 #include "opt_mvmetype.h"
39 #include "opt_ddb.h"
40 
41 #include <sys/param.h>
42 #include <sys/buf.h>
43 #include <sys/conf.h>
44 #include <sys/device.h>
45 #include <sys/exec.h>
46 #include <sys/extent.h>
47 #include <sys/kernel.h>
48 #include <sys/malloc.h>
49 #include <sys/mbuf.h>
50 #include <sys/mount.h>
51 #include <sys/msgbuf.h>
52 #include <sys/proc.h>
53 #include <sys/reboot.h>
54 #include <sys/syscallargs.h>
55 #include <sys/syslog.h>
56 #include <sys/systm.h>
57 
58 #include <sys/sysctl.h>
59 
60 #include <net/netisr.h>
61 
62 #include <machine/autoconf.h>
63 #include <machine/bootinfo.h>
64 #include <machine/bus.h>
65 #include <machine/intr.h>
66 #include <machine/pmap.h>
67 #include <machine/platform.h>
68 #include <machine/powerpc.h>
69 #include <machine/trap.h>
70 
71 #include <powerpc/oea/bat.h>
72 
73 #include <dev/cons.h>
74 
75 #if 0
76 #include "vga.h"
77 #if (NVGA > 0)
78 #include <dev/ic/mc6845reg.h>
79 #include <dev/ic/pcdisplayvar.h>
80 #include <dev/ic/vgareg.h>
81 #include <dev/ic/vgavar.h>
82 #endif
83 
84 #include "pckbc.h"
85 #if (NPCKBC > 0)
86 #include <dev/isa/isareg.h>
87 #include <dev/ic/i8042reg.h>
88 #include <dev/ic/pckbcvar.h>
89 #endif
90 #endif
91 
92 #include "com.h"
93 #if (NCOM > 0)
94 #include <sys/termios.h>
95 #include <dev/ic/comreg.h>
96 #include <dev/ic/comvar.h>
97 #endif
98 
99 void initppc(u_long, u_long, void *);
100 
101 /*
102  * Global variables used here and there
103  */
104 struct mvmeppc_bootinfo bootinfo;
105 vaddr_t prep_intr_reg;	/* PReP-compatible  interrupt vector register */
106 uint32_t prep_intr_reg_off = INTR_VECTOR_REG;
107 struct mem_region physmemr[2], availmemr[2];
108 paddr_t avail_end;			/* XXX temporary */
109 struct pic_ops *isa_pic;
110 
111 void
112 initppc(u_long startkernel, u_long endkernel, void *btinfo)
113 {
114 	/*
115 	 * Copy bootinfo.
116 	 */
117 	memcpy(&bootinfo, btinfo, sizeof(bootinfo));
118 
119 	/*
120 	 * Figure out the board family/type.
121 	 */
122 	ident_platform();
123 
124 	if (platform == NULL) {
125 		extern void _mvmeppc_unsup_board(const char *, const char *);
126 		char msg[80];
127 
128 		sprintf(msg, "Unsupported model: MVME%04x",
129 		    bootinfo.bi_modelnumber);
130 		_mvmeppc_unsup_board(msg, &msg[strlen(msg)]);
131 		/* NOTREACHED */
132 	}
133 
134 	/*
135 	 * Set memory region
136 	 */
137 	physmemr[0].start = 0;
138 	physmemr[0].size = bootinfo.bi_memsize & ~PGOFSET;
139 	availmemr[0].start = (endkernel + PGOFSET) & ~PGOFSET;
140 	availmemr[0].size = bootinfo.bi_memsize - availmemr[0].start;
141 	avail_end = physmemr[0].start + physmemr[0].size;    /* XXX temporary */
142 
143 	/*
144 	 * Set CPU clock
145 	 */
146 	{
147 		extern u_long ticks_per_sec, ns_per_tick;
148 
149 		ticks_per_sec = bootinfo.bi_clocktps;
150 		ns_per_tick = 1000000000 / ticks_per_sec;
151 	}
152 
153 	prep_initppc(startkernel, endkernel, boothowto);
154 
155 	(*platform->pic_setup)();
156 }
157 
158 /*
159  * Machine dependent startup code.
160  */
161 void
162 cpu_startup(void)
163 {
164 	char modelbuf[256];
165 
166 	/*
167 	 * Mapping PReP-compatible interrput vector register.
168 	 */
169 	prep_intr_reg = (vaddr_t) mapiodev(MVMEPPC_INTR_REG, PAGE_SIZE);
170 	if (!prep_intr_reg)
171 		panic("startup: no room for interrupt register");
172 
173 	sprintf(modelbuf, "%s\nCore Speed: %dMHz, Bus Speed: %dMHz\n",
174 	    platform->model,
175 	    bootinfo.bi_mpuspeed/1000000,
176 	    bootinfo.bi_busspeed/1000000);
177 	oea_startup(modelbuf);
178 
179 	/*
180 	 * Now allow hardware interrupts.
181 	 */
182 	{
183 		int msr;
184 
185 		splraise(-1);
186 		__asm volatile ("mfmsr %0; ori %0,%0,%1; mtmsr %0"
187 			      : "=r"(msr) : "K"(PSL_EE));
188 	}
189 
190 	bus_space_mallocok();
191 }
192 
193 /*
194  * consinit
195  * Initialize system console.
196  */
197 void
198 consinit(void)
199 {
200 	static int initted = 0;
201 
202 	if (initted)
203 		return;
204 	initted = 1;
205 
206 #if 0
207 
208 #if (NPFB > 0)
209 	if (!strcmp(consinfo->devname, "fb")) {
210 		pfb_cnattach(consinfo->addr);
211 #if (NPCKBC > 0)
212 		pckbc_cnattach(&mvmeppc_isa_io_space_tag, IO_KBD, KBCMDP,
213 		    PCKBC_KBD_SLOT);
214 #endif
215 		return;
216 	}
217 #endif
218 
219 #if (NVGA > 0) || (NGTEN > 0)
220 	if (!strcmp(consinfo->devname, "vga")) {
221 #if (NGTEN > 0)
222 		if (!gten_cnattach(&mvmeppc_mem_space_tag))
223 			goto dokbd;
224 #endif
225 #if (NVGA > 0)
226 		if (!vga_cnattach(&mvmeppc_io_space_tag, &mvmeppc_mem_space_tag,
227 				-1, 1))
228 			goto dokbd;
229 #endif
230 dokbd:
231 #if (NPCKBC > 0)
232 		pckbc_cnattach(&mvmeppc_isa_io_space_tag, IO_KBD, KBCMDP,
233 		    PCKBC_KBD_SLOT);
234 #endif
235 		return;
236 	}
237 #endif /* PC | VGA */
238 
239 #endif
240 
241 #if (NCOM > 0)
242 	if (!strcmp(bootinfo.bi_consoledev, "PC16550")) {
243 		bus_space_tag_t tag = &genppc_isa_io_space_tag;
244 		static const bus_addr_t caddr[2] = {0x3f8, 0x2f8};
245 		int rv;
246 		rv = comcnattach(tag, caddr[bootinfo.bi_consolechan],
247 		    bootinfo.bi_consolespeed, COM_FREQ, COM_TYPE_NORMAL,
248 		    bootinfo.bi_consolecflag);
249 		if (rv)
250 			panic("can't init serial console");
251 
252 		return;
253 	}
254 #endif
255 	panic("invalid console device %s", bootinfo.bi_consoledev);
256 }
257 
258 /*
259  * Halt or reboot the machine after syncing/dumping according to howto.
260  */
261 void
262 cpu_reboot(int howto, char *what)
263 {
264 	static int syncing;
265 
266 	if (cold) {
267 		howto |= RB_HALT;
268 		goto halt_sys;
269 	}
270 
271 	boothowto = howto;
272 	if ((howto & RB_NOSYNC) == 0 && syncing == 0) {
273 		syncing = 1;
274 		vfs_shutdown();		/* sync */
275 		resettodr();		/* set wall clock */
276 	}
277 
278 	/* Disable intr */
279 	splhigh();
280 
281 	/* Do dump if requested */
282 	if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
283 		oea_dumpsys();
284 
285 halt_sys:
286 	doshutdownhooks();
287 
288 	pmf_system_shutdown(boothowto);
289 
290 	if (howto & RB_HALT) {
291                 printf("\n");
292                 printf("The operating system has halted.\n");
293                 printf("Please press any key to reboot.\n\n");
294                 cnpollc(1);	/* for proper keyboard command handling */
295                 cngetc();
296                 cnpollc(0);
297 	}
298 
299 	printf("rebooting...\n\n");
300 
301 	(*platform->reset)();
302 
303 	printf("Oops! Board reset failed!\n");
304 
305 	for (;;)
306 		continue;
307 	/* NOTREACHED */
308 }
309