hdlg_machdep.c revision 1.1.2.2 1 1.1.2.2 elad /* $NetBSD: hdlg_machdep.c,v 1.1.2.2 2006/04/19 02:32:22 elad Exp $ */
2 1.1.2.2 elad
3 1.1.2.2 elad /*
4 1.1.2.2 elad * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
5 1.1.2.2 elad * All rights reserved.
6 1.1.2.2 elad *
7 1.1.2.2 elad * Written by Jason R. Thorpe and Steve C. Woodford for Wasabi Systems, Inc.
8 1.1.2.2 elad *
9 1.1.2.2 elad * Redistribution and use in source and binary forms, with or without
10 1.1.2.2 elad * modification, are permitted provided that the following conditions
11 1.1.2.2 elad * are met:
12 1.1.2.2 elad * 1. Redistributions of source code must retain the above copyright
13 1.1.2.2 elad * notice, this list of conditions and the following disclaimer.
14 1.1.2.2 elad * 2. Redistributions in binary form must reproduce the above copyright
15 1.1.2.2 elad * notice, this list of conditions and the following disclaimer in the
16 1.1.2.2 elad * documentation and/or other materials provided with the distribution.
17 1.1.2.2 elad * 3. All advertising materials mentioning features or use of this software
18 1.1.2.2 elad * must display the following acknowledgement:
19 1.1.2.2 elad * This product includes software developed for the NetBSD Project by
20 1.1.2.2 elad * Wasabi Systems, Inc.
21 1.1.2.2 elad * 4. The name of Wasabi Systems, Inc. may not be used to endorse
22 1.1.2.2 elad * or promote products derived from this software without specific prior
23 1.1.2.2 elad * written permission.
24 1.1.2.2 elad *
25 1.1.2.2 elad * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
26 1.1.2.2 elad * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
27 1.1.2.2 elad * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
28 1.1.2.2 elad * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL WASABI SYSTEMS, INC
29 1.1.2.2 elad * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
30 1.1.2.2 elad * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
31 1.1.2.2 elad * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 1.1.2.2 elad * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 1.1.2.2 elad * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
34 1.1.2.2 elad * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
35 1.1.2.2 elad * POSSIBILITY OF SUCH DAMAGE.
36 1.1.2.2 elad */
37 1.1.2.2 elad
38 1.1.2.2 elad /*
39 1.1.2.2 elad * Copyright (c) 1997,1998 Mark Brinicombe.
40 1.1.2.2 elad * Copyright (c) 1997,1998 Causality Limited.
41 1.1.2.2 elad * All rights reserved.
42 1.1.2.2 elad *
43 1.1.2.2 elad * Redistribution and use in source and binary forms, with or without
44 1.1.2.2 elad * modification, are permitted provided that the following conditions
45 1.1.2.2 elad * are met:
46 1.1.2.2 elad * 1. Redistributions of source code must retain the above copyright
47 1.1.2.2 elad * notice, this list of conditions and the following disclaimer.
48 1.1.2.2 elad * 2. Redistributions in binary form must reproduce the above copyright
49 1.1.2.2 elad * notice, this list of conditions and the following disclaimer in the
50 1.1.2.2 elad * documentation and/or other materials provided with the distribution.
51 1.1.2.2 elad * 3. All advertising materials mentioning features or use of this software
52 1.1.2.2 elad * must display the following acknowledgement:
53 1.1.2.2 elad * This product includes software developed by Mark Brinicombe
54 1.1.2.2 elad * for the NetBSD Project.
55 1.1.2.2 elad * 4. The name of the company nor the name of the author may be used to
56 1.1.2.2 elad * endorse or promote products derived from this software without specific
57 1.1.2.2 elad * prior written permission.
58 1.1.2.2 elad *
59 1.1.2.2 elad * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
60 1.1.2.2 elad * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
61 1.1.2.2 elad * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
62 1.1.2.2 elad * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
63 1.1.2.2 elad * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
64 1.1.2.2 elad * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
65 1.1.2.2 elad * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
66 1.1.2.2 elad * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
67 1.1.2.2 elad * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
68 1.1.2.2 elad * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
69 1.1.2.2 elad * SUCH DAMAGE.
70 1.1.2.2 elad *
71 1.1.2.2 elad * Machine dependant functions for kernel setup for GigaLANDISK
72 1.1.2.2 elad * using RedBoot firmware.
73 1.1.2.2 elad */
74 1.1.2.2 elad
75 1.1.2.2 elad #include <sys/cdefs.h>
76 1.1.2.2 elad __KERNEL_RCSID(0, "$NetBSD: hdlg_machdep.c,v 1.1.2.2 2006/04/19 02:32:22 elad Exp $");
77 1.1.2.2 elad
78 1.1.2.2 elad #include "opt_ddb.h"
79 1.1.2.2 elad #include "opt_kgdb.h"
80 1.1.2.2 elad #include "opt_pmap_debug.h"
81 1.1.2.2 elad
82 1.1.2.2 elad #include <sys/param.h>
83 1.1.2.2 elad #include <sys/device.h>
84 1.1.2.2 elad #include <sys/systm.h>
85 1.1.2.2 elad #include <sys/kernel.h>
86 1.1.2.2 elad #include <sys/exec.h>
87 1.1.2.2 elad #include <sys/proc.h>
88 1.1.2.2 elad #include <sys/msgbuf.h>
89 1.1.2.2 elad #include <sys/reboot.h>
90 1.1.2.2 elad #include <sys/termios.h>
91 1.1.2.2 elad #include <sys/ksyms.h>
92 1.1.2.2 elad
93 1.1.2.2 elad #include <uvm/uvm_extern.h>
94 1.1.2.2 elad
95 1.1.2.2 elad #include <dev/cons.h>
96 1.1.2.2 elad
97 1.1.2.2 elad #include <machine/db_machdep.h>
98 1.1.2.2 elad #include <ddb/db_sym.h>
99 1.1.2.2 elad #include <ddb/db_extern.h>
100 1.1.2.2 elad
101 1.1.2.2 elad #include <machine/bootconfig.h>
102 1.1.2.2 elad #include <machine/bus.h>
103 1.1.2.2 elad #include <machine/cpu.h>
104 1.1.2.2 elad #include <machine/frame.h>
105 1.1.2.2 elad #include <arm/undefined.h>
106 1.1.2.2 elad
107 1.1.2.2 elad #include <arm/arm32/machdep.h>
108 1.1.2.2 elad
109 1.1.2.2 elad #include <arm/xscale/i80321reg.h>
110 1.1.2.2 elad #include <arm/xscale/i80321var.h>
111 1.1.2.2 elad
112 1.1.2.2 elad #include <dev/pci/ppbreg.h>
113 1.1.2.2 elad
114 1.1.2.2 elad #include <evbarm/hdl_g/hdlgreg.h>
115 1.1.2.2 elad #include <evbarm/hdl_g/hdlgvar.h>
116 1.1.2.2 elad #include <evbarm/hdl_g/obiovar.h>
117 1.1.2.2 elad
118 1.1.2.2 elad #include "opt_ipkdb.h"
119 1.1.2.2 elad #include "ksyms.h"
120 1.1.2.2 elad
121 1.1.2.2 elad /* Kernel text starts 2MB in from the bottom of the kernel address space. */
122 1.1.2.2 elad #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
123 1.1.2.2 elad #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
124 1.1.2.2 elad
125 1.1.2.2 elad /*
126 1.1.2.2 elad * The range 0xc1000000 - 0xccffffff is available for kernel VM space
127 1.1.2.2 elad * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
128 1.1.2.2 elad */
129 1.1.2.2 elad #define KERNEL_VM_SIZE 0x0C000000
130 1.1.2.2 elad
131 1.1.2.2 elad /*
132 1.1.2.2 elad * Address to call from cpu_reset() to reset the machine.
133 1.1.2.2 elad * This is machine architecture dependant as it varies depending
134 1.1.2.2 elad * on where the ROM appears when you turn the MMU off.
135 1.1.2.2 elad *
136 1.1.2.2 elad * XXX Not actually used on hdlg -- clean up the generic
137 1.1.2.2 elad * ARM code.
138 1.1.2.2 elad */
139 1.1.2.2 elad u_int cpu_reset_address = 0x00000000;
140 1.1.2.2 elad
141 1.1.2.2 elad /* Define various stack sizes in pages */
142 1.1.2.2 elad #define IRQ_STACK_SIZE 1
143 1.1.2.2 elad #define ABT_STACK_SIZE 1
144 1.1.2.2 elad #ifdef IPKDB
145 1.1.2.2 elad #define UND_STACK_SIZE 2
146 1.1.2.2 elad #else
147 1.1.2.2 elad #define UND_STACK_SIZE 1
148 1.1.2.2 elad #endif
149 1.1.2.2 elad
150 1.1.2.2 elad BootConfig bootconfig; /* Boot config storage */
151 1.1.2.2 elad char *boot_args = NULL;
152 1.1.2.2 elad char *boot_file = NULL;
153 1.1.2.2 elad
154 1.1.2.2 elad vm_offset_t physical_start;
155 1.1.2.2 elad vm_offset_t physical_freestart;
156 1.1.2.2 elad vm_offset_t physical_freeend;
157 1.1.2.2 elad vm_offset_t physical_end;
158 1.1.2.2 elad u_int free_pages;
159 1.1.2.2 elad vm_offset_t pagetables_start;
160 1.1.2.2 elad int physmem = 0;
161 1.1.2.2 elad
162 1.1.2.2 elad /*int debug_flags;*/
163 1.1.2.2 elad #ifndef PMAP_STATIC_L1S
164 1.1.2.2 elad int max_processes = 64; /* Default number */
165 1.1.2.2 elad #endif /* !PMAP_STATIC_L1S */
166 1.1.2.2 elad
167 1.1.2.2 elad /* Physical and virtual addresses for some global pages */
168 1.1.2.2 elad pv_addr_t systempage;
169 1.1.2.2 elad pv_addr_t irqstack;
170 1.1.2.2 elad pv_addr_t undstack;
171 1.1.2.2 elad pv_addr_t abtstack;
172 1.1.2.2 elad pv_addr_t kernelstack;
173 1.1.2.2 elad pv_addr_t minidataclean;
174 1.1.2.2 elad
175 1.1.2.2 elad vm_offset_t msgbufphys;
176 1.1.2.2 elad
177 1.1.2.2 elad extern u_int data_abort_handler_address;
178 1.1.2.2 elad extern u_int prefetch_abort_handler_address;
179 1.1.2.2 elad extern u_int undefined_handler_address;
180 1.1.2.2 elad
181 1.1.2.2 elad #ifdef PMAP_DEBUG
182 1.1.2.2 elad extern int pmap_debug_level;
183 1.1.2.2 elad #endif
184 1.1.2.2 elad
185 1.1.2.2 elad #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
186 1.1.2.2 elad
187 1.1.2.2 elad #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
188 1.1.2.2 elad #define KERNEL_PT_KERNEL_NUM 4
189 1.1.2.2 elad
190 1.1.2.2 elad /* L2 table for mapping i80321 */
191 1.1.2.2 elad #define KERNEL_PT_IOPXS (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
192 1.1.2.2 elad
193 1.1.2.2 elad /* L2 tables for mapping kernel VM */
194 1.1.2.2 elad #define KERNEL_PT_VMDATA (KERNEL_PT_IOPXS + 1)
195 1.1.2.2 elad #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
196 1.1.2.2 elad #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
197 1.1.2.2 elad
198 1.1.2.2 elad pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
199 1.1.2.2 elad
200 1.1.2.2 elad struct user *proc0paddr;
201 1.1.2.2 elad
202 1.1.2.2 elad /* Prototypes */
203 1.1.2.2 elad void consinit(void);
204 1.1.2.2 elad
205 1.1.2.2 elad /* Static device mappings. */
206 1.1.2.2 elad static const struct pmap_devmap hdlg_devmap[] = {
207 1.1.2.2 elad /*
208 1.1.2.2 elad * Map the on-board devices VA == PA so that we can access them
209 1.1.2.2 elad * with the MMU on or off.
210 1.1.2.2 elad */
211 1.1.2.2 elad {
212 1.1.2.2 elad HDLG_OBIO_BASE,
213 1.1.2.2 elad HDLG_OBIO_BASE,
214 1.1.2.2 elad HDLG_OBIO_SIZE,
215 1.1.2.2 elad VM_PROT_READ|VM_PROT_WRITE,
216 1.1.2.2 elad PTE_NOCACHE,
217 1.1.2.2 elad },
218 1.1.2.2 elad
219 1.1.2.2 elad {
220 1.1.2.2 elad HDLG_IOW_VBASE,
221 1.1.2.2 elad VERDE_OUT_XLATE_IO_WIN0_BASE,
222 1.1.2.2 elad VERDE_OUT_XLATE_IO_WIN_SIZE,
223 1.1.2.2 elad VM_PROT_READ|VM_PROT_WRITE,
224 1.1.2.2 elad PTE_NOCACHE,
225 1.1.2.2 elad },
226 1.1.2.2 elad
227 1.1.2.2 elad {
228 1.1.2.2 elad HDLG_80321_VBASE,
229 1.1.2.2 elad VERDE_PMMR_BASE,
230 1.1.2.2 elad VERDE_PMMR_SIZE,
231 1.1.2.2 elad VM_PROT_READ|VM_PROT_WRITE,
232 1.1.2.2 elad PTE_NOCACHE,
233 1.1.2.2 elad },
234 1.1.2.2 elad
235 1.1.2.2 elad {
236 1.1.2.2 elad 0,
237 1.1.2.2 elad 0,
238 1.1.2.2 elad 0,
239 1.1.2.2 elad 0,
240 1.1.2.2 elad 0,
241 1.1.2.2 elad }
242 1.1.2.2 elad };
243 1.1.2.2 elad
244 1.1.2.2 elad static void
245 1.1.2.2 elad hardclock_hook(void)
246 1.1.2.2 elad {
247 1.1.2.2 elad
248 1.1.2.2 elad /* Nothing to do */
249 1.1.2.2 elad }
250 1.1.2.2 elad
251 1.1.2.2 elad /*
252 1.1.2.2 elad * u_int initarm(...)
253 1.1.2.2 elad *
254 1.1.2.2 elad * Initial entry point on startup. This gets called before main() is
255 1.1.2.2 elad * entered.
256 1.1.2.2 elad * It should be responsible for setting up everything that must be
257 1.1.2.2 elad * in place when main is called.
258 1.1.2.2 elad * This includes
259 1.1.2.2 elad * Taking a copy of the boot configuration structure.
260 1.1.2.2 elad * Initialising the physical console so characters can be printed.
261 1.1.2.2 elad * Setting up page tables for the kernel
262 1.1.2.2 elad * Relocating the kernel to the bottom of physical memory
263 1.1.2.2 elad */
264 1.1.2.2 elad u_int
265 1.1.2.2 elad initarm(void *arg)
266 1.1.2.2 elad {
267 1.1.2.2 elad extern vaddr_t xscale_cache_clean_addr;
268 1.1.2.2 elad #ifdef DIAGNOSTIC
269 1.1.2.2 elad extern vsize_t xscale_minidata_clean_size;
270 1.1.2.2 elad #endif
271 1.1.2.2 elad int loop;
272 1.1.2.2 elad int loop1;
273 1.1.2.2 elad u_int l1pagetable;
274 1.1.2.2 elad pv_addr_t kernel_l1pt;
275 1.1.2.2 elad paddr_t memstart;
276 1.1.2.2 elad psize_t memsize;
277 1.1.2.2 elad
278 1.1.2.2 elad /* Calibrate the delay loop. */
279 1.1.2.2 elad i80321_calibrate_delay();
280 1.1.2.2 elad i80321_hardclock_hook = hardclock_hook;
281 1.1.2.2 elad
282 1.1.2.2 elad /*
283 1.1.2.2 elad * Since we map the on-board devices VA==PA, and the kernel
284 1.1.2.2 elad * is running VA==PA, it's possible for us to initialize
285 1.1.2.2 elad * the console now.
286 1.1.2.2 elad */
287 1.1.2.2 elad consinit();
288 1.1.2.2 elad
289 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
290 1.1.2.2 elad /* Talk to the user */
291 1.1.2.2 elad printf("\nNetBSD/hdlg booting ...\n");
292 1.1.2.2 elad #endif
293 1.1.2.2 elad
294 1.1.2.2 elad /*
295 1.1.2.2 elad * Heads up ... Setup the CPU / MMU / TLB functions
296 1.1.2.2 elad */
297 1.1.2.2 elad if (set_cpufuncs())
298 1.1.2.2 elad panic("CPU not recognized!");
299 1.1.2.2 elad
300 1.1.2.2 elad /*
301 1.1.2.2 elad * We are currently running with the MMU enabled and the
302 1.1.2.2 elad * entire address space mapped VA==PA, except for the
303 1.1.2.2 elad * first 64M of RAM is also double-mapped at 0xc0000000.
304 1.1.2.2 elad * There is an L1 page table at 0xa0004000.
305 1.1.2.2 elad */
306 1.1.2.2 elad
307 1.1.2.2 elad /*
308 1.1.2.2 elad * Fetch the SDRAM start/size from the i80321 SDRAM configuration
309 1.1.2.2 elad * registers.
310 1.1.2.2 elad */
311 1.1.2.2 elad i80321_sdram_bounds(&obio_bs_tag, VERDE_PMMR_BASE + VERDE_MCU_BASE,
312 1.1.2.2 elad &memstart, &memsize);
313 1.1.2.2 elad
314 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
315 1.1.2.2 elad printf("initarm: Configuring system ...\n");
316 1.1.2.2 elad #endif
317 1.1.2.2 elad
318 1.1.2.2 elad /* Fake bootconfig structure for the benefit of pmap.c */
319 1.1.2.2 elad /* XXX must make the memory description h/w independant */
320 1.1.2.2 elad bootconfig.dramblocks = 1;
321 1.1.2.2 elad bootconfig.dram[0].address = memstart;
322 1.1.2.2 elad bootconfig.dram[0].pages = memsize / PAGE_SIZE;
323 1.1.2.2 elad
324 1.1.2.2 elad /*
325 1.1.2.2 elad * Set up the variables that define the availablilty of
326 1.1.2.2 elad * physical memory. For now, we're going to set
327 1.1.2.2 elad * physical_freestart to 0xa0200000 (where the kernel
328 1.1.2.2 elad * was loaded), and allocate the memory we need downwards.
329 1.1.2.2 elad * If we get too close to the L1 table that we set up, we
330 1.1.2.2 elad * will panic. We will update physical_freestart and
331 1.1.2.2 elad * physical_freeend later to reflect what pmap_bootstrap()
332 1.1.2.2 elad * wants to see.
333 1.1.2.2 elad *
334 1.1.2.2 elad * XXX pmap_bootstrap() needs an enema.
335 1.1.2.2 elad */
336 1.1.2.2 elad physical_start = bootconfig.dram[0].address;
337 1.1.2.2 elad physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
338 1.1.2.2 elad
339 1.1.2.2 elad physical_freestart = 0xa0009000UL;
340 1.1.2.2 elad physical_freeend = 0xa0200000UL;
341 1.1.2.2 elad
342 1.1.2.2 elad physmem = (physical_end - physical_start) / PAGE_SIZE;
343 1.1.2.2 elad
344 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
345 1.1.2.2 elad /* Tell the user about the memory */
346 1.1.2.2 elad printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
347 1.1.2.2 elad physical_start, physical_end - 1);
348 1.1.2.2 elad #endif
349 1.1.2.2 elad
350 1.1.2.2 elad /*
351 1.1.2.2 elad * Okay, the kernel starts 2MB in from the bottom of physical
352 1.1.2.2 elad * memory. We are going to allocate our bootstrap pages downwards
353 1.1.2.2 elad * from there.
354 1.1.2.2 elad *
355 1.1.2.2 elad * We need to allocate some fixed page tables to get the kernel
356 1.1.2.2 elad * going. We allocate one page directory and a number of page
357 1.1.2.2 elad * tables and store the physical addresses in the kernel_pt_table
358 1.1.2.2 elad * array.
359 1.1.2.2 elad *
360 1.1.2.2 elad * The kernel page directory must be on a 16K boundary. The page
361 1.1.2.2 elad * tables must be on 4K boundaries. What we do is allocate the
362 1.1.2.2 elad * page directory on the first 16K boundary that we encounter, and
363 1.1.2.2 elad * the page tables on 4K boundaries otherwise. Since we allocate
364 1.1.2.2 elad * at least 3 L2 page tables, we are guaranteed to encounter at
365 1.1.2.2 elad * least one 16K aligned region.
366 1.1.2.2 elad */
367 1.1.2.2 elad
368 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
369 1.1.2.2 elad printf("Allocating page tables\n");
370 1.1.2.2 elad #endif
371 1.1.2.2 elad
372 1.1.2.2 elad free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
373 1.1.2.2 elad
374 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
375 1.1.2.2 elad printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
376 1.1.2.2 elad physical_freestart, free_pages, free_pages);
377 1.1.2.2 elad #endif
378 1.1.2.2 elad
379 1.1.2.2 elad /* Define a macro to simplify memory allocation */
380 1.1.2.2 elad #define valloc_pages(var, np) \
381 1.1.2.2 elad alloc_pages((var).pv_pa, (np)); \
382 1.1.2.2 elad (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
383 1.1.2.2 elad
384 1.1.2.2 elad #define alloc_pages(var, np) \
385 1.1.2.2 elad physical_freeend -= ((np) * PAGE_SIZE); \
386 1.1.2.2 elad if (physical_freeend < physical_freestart) \
387 1.1.2.2 elad panic("initarm: out of memory"); \
388 1.1.2.2 elad (var) = physical_freeend; \
389 1.1.2.2 elad free_pages -= (np); \
390 1.1.2.2 elad memset((char *)(var), 0, ((np) * PAGE_SIZE));
391 1.1.2.2 elad
392 1.1.2.2 elad loop1 = 0;
393 1.1.2.2 elad kernel_l1pt.pv_pa = 0;
394 1.1.2.2 elad for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
395 1.1.2.2 elad /* Are we 16KB aligned for an L1 ? */
396 1.1.2.2 elad if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
397 1.1.2.2 elad && kernel_l1pt.pv_pa == 0) {
398 1.1.2.2 elad valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
399 1.1.2.2 elad } else {
400 1.1.2.2 elad valloc_pages(kernel_pt_table[loop1],
401 1.1.2.2 elad L2_TABLE_SIZE / PAGE_SIZE);
402 1.1.2.2 elad ++loop1;
403 1.1.2.2 elad }
404 1.1.2.2 elad }
405 1.1.2.2 elad
406 1.1.2.2 elad /* This should never be able to happen but better confirm that. */
407 1.1.2.2 elad if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
408 1.1.2.2 elad panic("initarm: Failed to align the kernel page directory");
409 1.1.2.2 elad
410 1.1.2.2 elad /*
411 1.1.2.2 elad * Allocate a page for the system page mapped to V0x00000000
412 1.1.2.2 elad * This page will just contain the system vectors and can be
413 1.1.2.2 elad * shared by all processes.
414 1.1.2.2 elad */
415 1.1.2.2 elad alloc_pages(systempage.pv_pa, 1);
416 1.1.2.2 elad
417 1.1.2.2 elad /* Allocate stacks for all modes */
418 1.1.2.2 elad valloc_pages(irqstack, IRQ_STACK_SIZE);
419 1.1.2.2 elad valloc_pages(abtstack, ABT_STACK_SIZE);
420 1.1.2.2 elad valloc_pages(undstack, UND_STACK_SIZE);
421 1.1.2.2 elad valloc_pages(kernelstack, UPAGES);
422 1.1.2.2 elad
423 1.1.2.2 elad /* Allocate enough pages for cleaning the Mini-Data cache. */
424 1.1.2.2 elad KASSERT(xscale_minidata_clean_size <= PAGE_SIZE);
425 1.1.2.2 elad valloc_pages(minidataclean, 1);
426 1.1.2.2 elad
427 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
428 1.1.2.2 elad printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
429 1.1.2.2 elad irqstack.pv_va);
430 1.1.2.2 elad printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
431 1.1.2.2 elad abtstack.pv_va);
432 1.1.2.2 elad printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
433 1.1.2.2 elad undstack.pv_va);
434 1.1.2.2 elad printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
435 1.1.2.2 elad kernelstack.pv_va);
436 1.1.2.2 elad #endif
437 1.1.2.2 elad
438 1.1.2.2 elad /*
439 1.1.2.2 elad * XXX Defer this to later so that we can reclaim the memory
440 1.1.2.2 elad * XXX used by the RedBoot page tables.
441 1.1.2.2 elad */
442 1.1.2.2 elad alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
443 1.1.2.2 elad
444 1.1.2.2 elad /*
445 1.1.2.2 elad * Ok we have allocated physical pages for the primary kernel
446 1.1.2.2 elad * page tables
447 1.1.2.2 elad */
448 1.1.2.2 elad
449 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
450 1.1.2.2 elad printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
451 1.1.2.2 elad #endif
452 1.1.2.2 elad
453 1.1.2.2 elad /*
454 1.1.2.2 elad * Now we start construction of the L1 page table
455 1.1.2.2 elad * We start by mapping the L2 page tables into the L1.
456 1.1.2.2 elad * This means that we can replace L1 mappings later on if necessary
457 1.1.2.2 elad */
458 1.1.2.2 elad l1pagetable = kernel_l1pt.pv_pa;
459 1.1.2.2 elad
460 1.1.2.2 elad /* Map the L2 pages tables in the L1 page table */
461 1.1.2.2 elad pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
462 1.1.2.2 elad &kernel_pt_table[KERNEL_PT_SYS]);
463 1.1.2.2 elad for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
464 1.1.2.2 elad pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
465 1.1.2.2 elad &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
466 1.1.2.2 elad pmap_link_l2pt(l1pagetable, HDLG_IOPXS_VBASE,
467 1.1.2.2 elad &kernel_pt_table[KERNEL_PT_IOPXS]);
468 1.1.2.2 elad for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
469 1.1.2.2 elad pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
470 1.1.2.2 elad &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
471 1.1.2.2 elad
472 1.1.2.2 elad /* update the top of the kernel VM */
473 1.1.2.2 elad pmap_curmaxkvaddr =
474 1.1.2.2 elad KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
475 1.1.2.2 elad
476 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
477 1.1.2.2 elad printf("Mapping kernel\n");
478 1.1.2.2 elad #endif
479 1.1.2.2 elad
480 1.1.2.2 elad /* Now we fill in the L2 pagetable for the kernel static code/data */
481 1.1.2.2 elad {
482 1.1.2.2 elad extern char etext[], _end[];
483 1.1.2.2 elad size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
484 1.1.2.2 elad size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
485 1.1.2.2 elad u_int logical;
486 1.1.2.2 elad
487 1.1.2.2 elad textsize = (textsize + PGOFSET) & ~PGOFSET;
488 1.1.2.2 elad totalsize = (totalsize + PGOFSET) & ~PGOFSET;
489 1.1.2.2 elad
490 1.1.2.2 elad logical = 0x00200000; /* offset of kernel in RAM */
491 1.1.2.2 elad
492 1.1.2.2 elad logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
493 1.1.2.2 elad physical_start + logical, textsize,
494 1.1.2.2 elad VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
495 1.1.2.2 elad logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
496 1.1.2.2 elad physical_start + logical, totalsize - textsize,
497 1.1.2.2 elad VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
498 1.1.2.2 elad }
499 1.1.2.2 elad
500 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
501 1.1.2.2 elad printf("Constructing L2 page tables\n");
502 1.1.2.2 elad #endif
503 1.1.2.2 elad
504 1.1.2.2 elad /* Map the stack pages */
505 1.1.2.2 elad pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
506 1.1.2.2 elad IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
507 1.1.2.2 elad pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
508 1.1.2.2 elad ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
509 1.1.2.2 elad pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
510 1.1.2.2 elad UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
511 1.1.2.2 elad pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
512 1.1.2.2 elad UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
513 1.1.2.2 elad
514 1.1.2.2 elad pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
515 1.1.2.2 elad L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
516 1.1.2.2 elad
517 1.1.2.2 elad for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
518 1.1.2.2 elad pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
519 1.1.2.2 elad kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
520 1.1.2.2 elad VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
521 1.1.2.2 elad }
522 1.1.2.2 elad
523 1.1.2.2 elad /* Map the Mini-Data cache clean area. */
524 1.1.2.2 elad xscale_setup_minidata(l1pagetable, minidataclean.pv_va,
525 1.1.2.2 elad minidataclean.pv_pa);
526 1.1.2.2 elad
527 1.1.2.2 elad /* Map the vector page. */
528 1.1.2.2 elad pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
529 1.1.2.2 elad VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
530 1.1.2.2 elad
531 1.1.2.2 elad /* Map the statically mapped devices. */
532 1.1.2.2 elad pmap_devmap_bootstrap(l1pagetable, hdlg_devmap);
533 1.1.2.2 elad
534 1.1.2.2 elad /*
535 1.1.2.2 elad * Give the XScale global cache clean code an appropriately
536 1.1.2.2 elad * sized chunk of unmapped VA space starting at 0xff000000
537 1.1.2.2 elad * (our device mappings end before this address).
538 1.1.2.2 elad */
539 1.1.2.2 elad xscale_cache_clean_addr = 0xff000000U;
540 1.1.2.2 elad
541 1.1.2.2 elad /*
542 1.1.2.2 elad * Now we have the real page tables in place so we can switch to them.
543 1.1.2.2 elad * Once this is done we will be running with the REAL kernel page
544 1.1.2.2 elad * tables.
545 1.1.2.2 elad */
546 1.1.2.2 elad
547 1.1.2.2 elad /*
548 1.1.2.2 elad * Update the physical_freestart/physical_freeend/free_pages
549 1.1.2.2 elad * variables.
550 1.1.2.2 elad */
551 1.1.2.2 elad {
552 1.1.2.2 elad extern char _end[];
553 1.1.2.2 elad
554 1.1.2.2 elad physical_freestart = physical_start +
555 1.1.2.2 elad (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
556 1.1.2.2 elad KERNEL_BASE);
557 1.1.2.2 elad physical_freeend = physical_end;
558 1.1.2.2 elad free_pages =
559 1.1.2.2 elad (physical_freeend - physical_freestart) / PAGE_SIZE;
560 1.1.2.2 elad }
561 1.1.2.2 elad
562 1.1.2.2 elad /* Switch tables */
563 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
564 1.1.2.2 elad printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
565 1.1.2.2 elad physical_freestart, free_pages, free_pages);
566 1.1.2.2 elad printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
567 1.1.2.2 elad #endif
568 1.1.2.2 elad cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
569 1.1.2.2 elad setttb(kernel_l1pt.pv_pa);
570 1.1.2.2 elad cpu_tlb_flushID();
571 1.1.2.2 elad cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
572 1.1.2.2 elad
573 1.1.2.2 elad /*
574 1.1.2.2 elad * Moved from cpu_startup() as data_abort_handler() references
575 1.1.2.2 elad * this during uvm init
576 1.1.2.2 elad */
577 1.1.2.2 elad proc0paddr = (struct user *)kernelstack.pv_va;
578 1.1.2.2 elad lwp0.l_addr = proc0paddr;
579 1.1.2.2 elad
580 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
581 1.1.2.2 elad printf("done!\n");
582 1.1.2.2 elad #endif
583 1.1.2.2 elad
584 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
585 1.1.2.2 elad printf("bootstrap done.\n");
586 1.1.2.2 elad #endif
587 1.1.2.2 elad
588 1.1.2.2 elad arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
589 1.1.2.2 elad
590 1.1.2.2 elad /*
591 1.1.2.2 elad * Pages were allocated during the secondary bootstrap for the
592 1.1.2.2 elad * stacks for different CPU modes.
593 1.1.2.2 elad * We must now set the r13 registers in the different CPU modes to
594 1.1.2.2 elad * point to these stacks.
595 1.1.2.2 elad * Since the ARM stacks use STMFD etc. we must set r13 to the top end
596 1.1.2.2 elad * of the stack memory.
597 1.1.2.2 elad */
598 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
599 1.1.2.2 elad printf("init subsystems: stacks ");
600 1.1.2.2 elad #endif
601 1.1.2.2 elad
602 1.1.2.2 elad set_stackptr(PSR_IRQ32_MODE,
603 1.1.2.2 elad irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
604 1.1.2.2 elad set_stackptr(PSR_ABT32_MODE,
605 1.1.2.2 elad abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
606 1.1.2.2 elad set_stackptr(PSR_UND32_MODE,
607 1.1.2.2 elad undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
608 1.1.2.2 elad
609 1.1.2.2 elad /*
610 1.1.2.2 elad * Well we should set a data abort handler.
611 1.1.2.2 elad * Once things get going this will change as we will need a proper
612 1.1.2.2 elad * handler.
613 1.1.2.2 elad * Until then we will use a handler that just panics but tells us
614 1.1.2.2 elad * why.
615 1.1.2.2 elad * Initialisation of the vectors will just panic on a data abort.
616 1.1.2.2 elad * This just fills in a slightly better one.
617 1.1.2.2 elad */
618 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
619 1.1.2.2 elad printf("vectors ");
620 1.1.2.2 elad #endif
621 1.1.2.2 elad data_abort_handler_address = (u_int)data_abort_handler;
622 1.1.2.2 elad prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
623 1.1.2.2 elad undefined_handler_address = (u_int)undefinedinstruction_bounce;
624 1.1.2.2 elad
625 1.1.2.2 elad /* Initialise the undefined instruction handlers */
626 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
627 1.1.2.2 elad printf("undefined ");
628 1.1.2.2 elad #endif
629 1.1.2.2 elad undefined_init();
630 1.1.2.2 elad
631 1.1.2.2 elad /* Load memory into UVM. */
632 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
633 1.1.2.2 elad printf("page ");
634 1.1.2.2 elad #endif
635 1.1.2.2 elad uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
636 1.1.2.2 elad uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
637 1.1.2.2 elad atop(physical_freestart), atop(physical_freeend),
638 1.1.2.2 elad VM_FREELIST_DEFAULT);
639 1.1.2.2 elad
640 1.1.2.2 elad /* Boot strap pmap telling it where the kernel page table is */
641 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
642 1.1.2.2 elad printf("pmap ");
643 1.1.2.2 elad #endif
644 1.1.2.2 elad pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
645 1.1.2.2 elad KERNEL_VM_BASE + KERNEL_VM_SIZE);
646 1.1.2.2 elad
647 1.1.2.2 elad /* Setup the IRQ system */
648 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
649 1.1.2.2 elad printf("irq ");
650 1.1.2.2 elad #endif
651 1.1.2.2 elad i80321_intr_init();
652 1.1.2.2 elad
653 1.1.2.2 elad #ifdef VERBOSE_INIT_ARM
654 1.1.2.2 elad printf("done.\n");
655 1.1.2.2 elad #endif
656 1.1.2.2 elad
657 1.1.2.2 elad #ifdef BOOTHOWTO
658 1.1.2.2 elad boothowto = BOOTHOWTO;
659 1.1.2.2 elad #endif
660 1.1.2.2 elad
661 1.1.2.2 elad #ifdef IPKDB
662 1.1.2.2 elad /* Initialise ipkdb */
663 1.1.2.2 elad ipkdb_init();
664 1.1.2.2 elad if (boothowto & RB_KDB)
665 1.1.2.2 elad ipkdb_connect(0);
666 1.1.2.2 elad #endif
667 1.1.2.2 elad
668 1.1.2.2 elad #if NKSYMS || defined(DDB) || defined(LKM)
669 1.1.2.2 elad /* Firmware doesn't load symbols. */
670 1.1.2.2 elad ksyms_init(0, NULL, NULL);
671 1.1.2.2 elad #endif
672 1.1.2.2 elad
673 1.1.2.2 elad #ifdef DDB
674 1.1.2.2 elad db_machine_init();
675 1.1.2.2 elad if (boothowto & RB_KDB)
676 1.1.2.2 elad Debugger();
677 1.1.2.2 elad #endif
678 1.1.2.2 elad
679 1.1.2.2 elad /* We return the new stack pointer address */
680 1.1.2.2 elad return (kernelstack.pv_va + USPACE_SVC_STACK_TOP);
681 1.1.2.2 elad }
682 1.1.2.2 elad
683 1.1.2.2 elad /*
684 1.1.2.2 elad * void cpu_reboot(int howto, char *bootstr)
685 1.1.2.2 elad *
686 1.1.2.2 elad * Reboots the system
687 1.1.2.2 elad *
688 1.1.2.2 elad * Deal with any syncing, unmounting, dumping and shutdown hooks,
689 1.1.2.2 elad * then reset the CPU.
690 1.1.2.2 elad */
691 1.1.2.2 elad void
692 1.1.2.2 elad cpu_reboot(int howto, char *bootstr)
693 1.1.2.2 elad {
694 1.1.2.2 elad
695 1.1.2.2 elad /*
696 1.1.2.2 elad * If we are still cold then hit the air brakes
697 1.1.2.2 elad * and crash to earth fast
698 1.1.2.2 elad */
699 1.1.2.2 elad if (cold) {
700 1.1.2.2 elad *(volatile uint8_t *)HDLG_LEDCTRL |= LEDCTRL_STAT_RED;
701 1.1.2.2 elad howto |= RB_HALT;
702 1.1.2.2 elad goto haltsys;
703 1.1.2.2 elad }
704 1.1.2.2 elad
705 1.1.2.2 elad /* Disable console buffering */
706 1.1.2.2 elad
707 1.1.2.2 elad /*
708 1.1.2.2 elad * If RB_NOSYNC was not specified sync the discs.
709 1.1.2.2 elad * Note: Unless cold is set to 1 here, syslogd will die during the
710 1.1.2.2 elad * unmount. It looks like syslogd is getting woken up only to find
711 1.1.2.2 elad * that it cannot page part of the binary in as the filesystem has
712 1.1.2.2 elad * been unmounted.
713 1.1.2.2 elad */
714 1.1.2.2 elad if ((howto & RB_NOSYNC) == 0) {
715 1.1.2.2 elad bootsync();
716 1.1.2.2 elad /*resettodr();*/
717 1.1.2.2 elad }
718 1.1.2.2 elad
719 1.1.2.2 elad /* wait 1s */
720 1.1.2.2 elad delay(1 * 1000 * 1000);
721 1.1.2.2 elad
722 1.1.2.2 elad /* Say NO to interrupts */
723 1.1.2.2 elad splhigh();
724 1.1.2.2 elad
725 1.1.2.2 elad /* Do a dump if requested. */
726 1.1.2.2 elad if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP) {
727 1.1.2.2 elad dumpsys();
728 1.1.2.2 elad }
729 1.1.2.2 elad
730 1.1.2.2 elad haltsys:
731 1.1.2.2 elad /* Run any shutdown hooks */
732 1.1.2.2 elad doshutdownhooks();
733 1.1.2.2 elad
734 1.1.2.2 elad /* Make sure IRQ's are disabled */
735 1.1.2.2 elad IRQdisable;
736 1.1.2.2 elad
737 1.1.2.2 elad if (howto & RB_HALT) {
738 1.1.2.2 elad *(volatile uint8_t *)HDLG_PWRMNG = PWRMNG_POWOFF;
739 1.1.2.2 elad delay(3 * 1000 * 1000); /* wait 3s */
740 1.1.2.2 elad
741 1.1.2.2 elad printf("SHUTDOWN FAILED!\n");
742 1.1.2.2 elad printf("The operating system has halted.\n");
743 1.1.2.2 elad printf("Please press any key to reboot.\n\n");
744 1.1.2.2 elad cngetc();
745 1.1.2.2 elad }
746 1.1.2.2 elad
747 1.1.2.2 elad printf("rebooting...\n\r");
748 1.1.2.2 elad
749 1.1.2.2 elad (void)disable_interrupts(I32_bit|F32_bit);
750 1.1.2.2 elad cpu_idcache_wbinv_all();
751 1.1.2.2 elad cpu_drain_writebuf();
752 1.1.2.2 elad
753 1.1.2.2 elad *(volatile uint8_t *)HDLG_PWRMNG = PWRMNG_RESET;
754 1.1.2.2 elad delay(1 * 1000 * 1000); /* wait 1s */
755 1.1.2.2 elad
756 1.1.2.2 elad /* ...and if that didn't work, just croak. */
757 1.1.2.2 elad printf("RESET FAILED!\n");
758 1.1.2.2 elad for (;;) {
759 1.1.2.2 elad continue;
760 1.1.2.2 elad }
761 1.1.2.2 elad }
762 1.1.2.2 elad
763 1.1.2.2 elad /*
764 1.1.2.2 elad * console
765 1.1.2.2 elad */
766 1.1.2.2 elad #include "com.h"
767 1.1.2.2 elad #if NCOM > 0
768 1.1.2.2 elad #include <dev/ic/comreg.h>
769 1.1.2.2 elad #include <dev/ic/comvar.h>
770 1.1.2.2 elad #endif
771 1.1.2.2 elad
772 1.1.2.2 elad /*
773 1.1.2.2 elad * Define the default console speed for the board. This is generally
774 1.1.2.2 elad * what the firmware provided with the board defaults to.
775 1.1.2.2 elad */
776 1.1.2.2 elad #ifndef CONSPEED
777 1.1.2.2 elad #define CONSPEED B115200
778 1.1.2.2 elad #endif /* ! CONSPEED */
779 1.1.2.2 elad
780 1.1.2.2 elad #ifndef CONUNIT
781 1.1.2.2 elad #define CONUNIT 0
782 1.1.2.2 elad #endif
783 1.1.2.2 elad
784 1.1.2.2 elad #ifndef CONMODE
785 1.1.2.2 elad #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
786 1.1.2.2 elad #endif
787 1.1.2.2 elad
788 1.1.2.2 elad int comcnspeed = CONSPEED;
789 1.1.2.2 elad int comcnmode = CONMODE;
790 1.1.2.2 elad int comcnunit = CONUNIT;
791 1.1.2.2 elad
792 1.1.2.2 elad #if KGDB
793 1.1.2.2 elad #ifndef KGDB_DEVNAME
794 1.1.2.2 elad #error Must define KGDB_DEVNAME
795 1.1.2.2 elad #endif
796 1.1.2.2 elad const char kgdb_devname[] = KGDB_DEVNAME;
797 1.1.2.2 elad
798 1.1.2.2 elad #ifndef KGDB_DEVADDR
799 1.1.2.2 elad #error Must define KGDB_DEVADDR
800 1.1.2.2 elad #endif
801 1.1.2.2 elad unsigned long kgdb_devaddr = KGDB_DEVADDR;
802 1.1.2.2 elad
803 1.1.2.2 elad #ifndef KGDB_DEVRATE
804 1.1.2.2 elad #define KGDB_DEVRATE CONSPEED
805 1.1.2.2 elad #endif
806 1.1.2.2 elad int kgdb_devrate = KGDB_DEVRATE;
807 1.1.2.2 elad
808 1.1.2.2 elad #ifndef KGDB_DEVMODE
809 1.1.2.2 elad #define KGDB_DEVMODE CONMODE
810 1.1.2.2 elad #endif
811 1.1.2.2 elad int kgdb_devmode = KGDB_DEVMODE;
812 1.1.2.2 elad #endif /* KGDB */
813 1.1.2.2 elad
814 1.1.2.2 elad void
815 1.1.2.2 elad consinit(void)
816 1.1.2.2 elad {
817 1.1.2.2 elad static const bus_addr_t comcnaddrs[] = {
818 1.1.2.2 elad HDLG_UART1, /* com0 */
819 1.1.2.2 elad };
820 1.1.2.2 elad static int consinit_called;
821 1.1.2.2 elad
822 1.1.2.2 elad if (consinit_called)
823 1.1.2.2 elad return;
824 1.1.2.2 elad consinit_called = 1;
825 1.1.2.2 elad
826 1.1.2.2 elad /*
827 1.1.2.2 elad * Console devices are mapped VA==PA. Our devmap reflects
828 1.1.2.2 elad * this, so register it now so drivers can map the console
829 1.1.2.2 elad * device.
830 1.1.2.2 elad */
831 1.1.2.2 elad pmap_devmap_register(hdlg_devmap);
832 1.1.2.2 elad
833 1.1.2.2 elad #if NCOM > 0
834 1.1.2.2 elad if (comcnattach(&obio_bs_tag, comcnaddrs[comcnunit], comcnspeed,
835 1.1.2.2 elad COM_FREQ, COM_TYPE_NORMAL, comcnmode))
836 1.1.2.2 elad panic("can't init serial console @%lx", comcnaddrs[comcnunit]);
837 1.1.2.2 elad #else
838 1.1.2.2 elad panic("serial console @%lx not configured", comcnaddrs[comcnunit]);
839 1.1.2.2 elad #endif
840 1.1.2.2 elad #if KGDB
841 1.1.2.2 elad #if NCOM > 0
842 1.1.2.2 elad if (strcmp(kgdb_devname, "com") == 0) {
843 1.1.2.2 elad com_kgdb_attach(&obio_bs_tag, kgdb_devaddr, kgdb_devrate,
844 1.1.2.2 elad COM_FREQ, COM_TYPE_NORMAL, kgdb_devmode);
845 1.1.2.2 elad }
846 1.1.2.2 elad #endif /* NCOM > 0 */
847 1.1.2.2 elad #endif /* KGDB */
848 1.1.2.2 elad }
849