integrator_machdep.c revision 1.71 1 1.71 matt /* $NetBSD: integrator_machdep.c,v 1.71 2012/08/16 18:22:43 matt Exp $ */
2 1.1 rearnsha
3 1.1 rearnsha /*
4 1.23 rearnsha * Copyright (c) 2001,2002 ARM Ltd
5 1.1 rearnsha * All rights reserved.
6 1.1 rearnsha *
7 1.1 rearnsha * Redistribution and use in source and binary forms, with or without
8 1.1 rearnsha * modification, are permitted provided that the following conditions
9 1.1 rearnsha * are met:
10 1.1 rearnsha * 1. Redistributions of source code must retain the above copyright
11 1.1 rearnsha * notice, this list of conditions and the following disclaimer.
12 1.1 rearnsha * 2. Redistributions in binary form must reproduce the above copyright
13 1.1 rearnsha * notice, this list of conditions and the following disclaimer in the
14 1.1 rearnsha * documentation and/or other materials provided with the distribution.
15 1.1 rearnsha * 3. The name of the company may not be used to endorse or promote
16 1.1 rearnsha * products derived from this software without specific prior written
17 1.1 rearnsha * permission.
18 1.1 rearnsha *
19 1.23 rearnsha * THIS SOFTWARE IS PROVIDED BY ARM LTD ``AS IS'' AND
20 1.23 rearnsha * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
21 1.23 rearnsha * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
22 1.23 rearnsha * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL ARM LTD
23 1.23 rearnsha * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
24 1.23 rearnsha * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
25 1.23 rearnsha * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
26 1.23 rearnsha * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
27 1.23 rearnsha * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
28 1.23 rearnsha * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
29 1.23 rearnsha * POSSIBILITY OF SUCH DAMAGE.
30 1.23 rearnsha */
31 1.23 rearnsha
32 1.23 rearnsha /*
33 1.1 rearnsha * Copyright (c) 1997,1998 Mark Brinicombe.
34 1.1 rearnsha * Copyright (c) 1997,1998 Causality Limited.
35 1.1 rearnsha * All rights reserved.
36 1.1 rearnsha *
37 1.1 rearnsha * Redistribution and use in source and binary forms, with or without
38 1.1 rearnsha * modification, are permitted provided that the following conditions
39 1.1 rearnsha * are met:
40 1.1 rearnsha * 1. Redistributions of source code must retain the above copyright
41 1.1 rearnsha * notice, this list of conditions and the following disclaimer.
42 1.1 rearnsha * 2. Redistributions in binary form must reproduce the above copyright
43 1.1 rearnsha * notice, this list of conditions and the following disclaimer in the
44 1.1 rearnsha * documentation and/or other materials provided with the distribution.
45 1.1 rearnsha * 3. All advertising materials mentioning features or use of this software
46 1.1 rearnsha * must display the following acknowledgement:
47 1.1 rearnsha * This product includes software developed by Mark Brinicombe
48 1.1 rearnsha * for the NetBSD Project.
49 1.1 rearnsha * 4. The name of the company nor the name of the author may be used to
50 1.1 rearnsha * endorse or promote products derived from this software without specific
51 1.1 rearnsha * prior written permission.
52 1.1 rearnsha *
53 1.1 rearnsha * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
54 1.1 rearnsha * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
55 1.1 rearnsha * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
56 1.1 rearnsha * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
57 1.1 rearnsha * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
58 1.1 rearnsha * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
59 1.1 rearnsha * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
60 1.1 rearnsha * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
61 1.1 rearnsha * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
62 1.1 rearnsha * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
63 1.1 rearnsha * SUCH DAMAGE.
64 1.1 rearnsha *
65 1.67 wiz * Machine dependent functions for kernel setup for integrator board
66 1.1 rearnsha *
67 1.1 rearnsha * Created : 24/11/97
68 1.1 rearnsha */
69 1.43 lukem
70 1.43 lukem #include <sys/cdefs.h>
71 1.71 matt __KERNEL_RCSID(0, "$NetBSD: integrator_machdep.c,v 1.71 2012/08/16 18:22:43 matt Exp $");
72 1.1 rearnsha
73 1.1 rearnsha #include "opt_ddb.h"
74 1.1 rearnsha #include "opt_pmap_debug.h"
75 1.1 rearnsha
76 1.1 rearnsha #include <sys/param.h>
77 1.1 rearnsha #include <sys/device.h>
78 1.1 rearnsha #include <sys/systm.h>
79 1.1 rearnsha #include <sys/kernel.h>
80 1.1 rearnsha #include <sys/exec.h>
81 1.1 rearnsha #include <sys/proc.h>
82 1.1 rearnsha #include <sys/msgbuf.h>
83 1.1 rearnsha #include <sys/reboot.h>
84 1.1 rearnsha #include <sys/termios.h>
85 1.32 ragge #include <sys/ksyms.h>
86 1.1 rearnsha
87 1.31 thorpej #include <uvm/uvm_extern.h>
88 1.31 thorpej
89 1.1 rearnsha #include <dev/cons.h>
90 1.1 rearnsha
91 1.1 rearnsha #include <machine/db_machdep.h>
92 1.1 rearnsha #include <ddb/db_sym.h>
93 1.1 rearnsha #include <ddb/db_extern.h>
94 1.1 rearnsha
95 1.1 rearnsha #include <machine/bootconfig.h>
96 1.68 dyoung #include <sys/bus.h>
97 1.1 rearnsha #include <machine/cpu.h>
98 1.1 rearnsha #include <machine/frame.h>
99 1.1 rearnsha #include <machine/intr.h>
100 1.6 thorpej #include <arm/undefined.h>
101 1.1 rearnsha
102 1.23 rearnsha #include <arm/arm32/machdep.h>
103 1.23 rearnsha
104 1.1 rearnsha #include <evbarm/integrator/integrator_boot.h>
105 1.1 rearnsha
106 1.1 rearnsha #include "pci.h"
107 1.32 ragge #include "ksyms.h"
108 1.1 rearnsha
109 1.1 rearnsha void ifpga_reset(void) __attribute__((noreturn));
110 1.36 thorpej
111 1.36 thorpej /* Kernel text starts 2MB in from the bottom of the kernel address space. */
112 1.36 thorpej #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
113 1.39 thorpej #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
114 1.40 thorpej
115 1.40 thorpej /*
116 1.40 thorpej * The range 0xc1000000 - 0xccffffff is available for kernel VM space
117 1.40 thorpej * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
118 1.40 thorpej */
119 1.40 thorpej #define KERNEL_VM_SIZE 0x0C000000
120 1.36 thorpej
121 1.1 rearnsha BootConfig bootconfig; /* Boot config storage */
122 1.1 rearnsha char *boot_args = NULL;
123 1.1 rearnsha char *boot_file = NULL;
124 1.1 rearnsha
125 1.1 rearnsha vm_offset_t physical_start;
126 1.1 rearnsha vm_offset_t physical_end;
127 1.1 rearnsha
128 1.1 rearnsha /*int debug_flags;*/
129 1.1 rearnsha #ifndef PMAP_STATIC_L1S
130 1.1 rearnsha int max_processes = 64; /* Default number */
131 1.1 rearnsha #endif /* !PMAP_STATIC_L1S */
132 1.1 rearnsha
133 1.1 rearnsha vm_offset_t msgbufphys;
134 1.1 rearnsha
135 1.1 rearnsha #ifdef PMAP_DEBUG
136 1.1 rearnsha extern int pmap_debug_level;
137 1.1 rearnsha #endif
138 1.1 rearnsha
139 1.23 rearnsha #define KERNEL_PT_SYS 0 /* L2 table for mapping zero page */
140 1.23 rearnsha
141 1.23 rearnsha #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
142 1.23 rearnsha #define KERNEL_PT_KERNEL_NUM 2
143 1.23 rearnsha /* L2 tables for mapping kernel VM */
144 1.23 rearnsha #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
145 1.17 chris #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
146 1.1 rearnsha #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
147 1.1 rearnsha
148 1.14 thorpej pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
149 1.1 rearnsha
150 1.1 rearnsha /* Prototypes */
151 1.1 rearnsha
152 1.23 rearnsha static void integrator_sdram_bounds (paddr_t *, psize_t *);
153 1.1 rearnsha
154 1.23 rearnsha void consinit(void);
155 1.1 rearnsha
156 1.1 rearnsha /* A load of console goo. */
157 1.1 rearnsha #include "vga.h"
158 1.23 rearnsha #if NVGA > 0
159 1.1 rearnsha #include <dev/ic/mc6845reg.h>
160 1.1 rearnsha #include <dev/ic/pcdisplayvar.h>
161 1.1 rearnsha #include <dev/ic/vgareg.h>
162 1.1 rearnsha #include <dev/ic/vgavar.h>
163 1.1 rearnsha #endif
164 1.1 rearnsha
165 1.1 rearnsha #include "pckbc.h"
166 1.23 rearnsha #if NPCKBC > 0
167 1.1 rearnsha #include <dev/ic/i8042reg.h>
168 1.1 rearnsha #include <dev/ic/pckbcvar.h>
169 1.1 rearnsha #endif
170 1.1 rearnsha
171 1.1 rearnsha #include "com.h"
172 1.23 rearnsha #if NCOM > 0
173 1.1 rearnsha #include <dev/ic/comreg.h>
174 1.1 rearnsha #include <dev/ic/comvar.h>
175 1.1 rearnsha #ifndef CONCOMADDR
176 1.1 rearnsha #define CONCOMADDR 0x3f8
177 1.1 rearnsha #endif
178 1.1 rearnsha #endif
179 1.1 rearnsha
180 1.23 rearnsha /*
181 1.23 rearnsha * Define the default console speed for the board. This is generally
182 1.23 rearnsha * what the firmware provided with the board defaults to.
183 1.23 rearnsha */
184 1.30 mycroft #ifndef CONSPEED
185 1.1 rearnsha #define CONSPEED B115200
186 1.1 rearnsha #endif
187 1.1 rearnsha #ifndef CONMODE
188 1.1 rearnsha #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
189 1.1 rearnsha #endif
190 1.1 rearnsha
191 1.1 rearnsha int comcnspeed = CONSPEED;
192 1.1 rearnsha int comcnmode = CONMODE;
193 1.1 rearnsha
194 1.1 rearnsha #include "plcom.h"
195 1.1 rearnsha #if (NPLCOM > 0)
196 1.1 rearnsha #include <evbarm/dev/plcomreg.h>
197 1.1 rearnsha #include <evbarm/dev/plcomvar.h>
198 1.1 rearnsha
199 1.1 rearnsha #include <evbarm/ifpga/ifpgamem.h>
200 1.1 rearnsha #include <evbarm/ifpga/ifpgareg.h>
201 1.1 rearnsha #include <evbarm/ifpga/ifpgavar.h>
202 1.1 rearnsha #endif
203 1.1 rearnsha
204 1.1 rearnsha #ifndef CONSDEVNAME
205 1.1 rearnsha #define CONSDEVNAME "plcom"
206 1.1 rearnsha #endif
207 1.1 rearnsha
208 1.1 rearnsha #ifndef PLCONSPEED
209 1.1 rearnsha #define PLCONSPEED B38400
210 1.1 rearnsha #endif
211 1.1 rearnsha #ifndef PLCONMODE
212 1.1 rearnsha #define PLCONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
213 1.1 rearnsha #endif
214 1.1 rearnsha #ifndef PLCOMCNUNIT
215 1.1 rearnsha #define PLCOMCNUNIT -1
216 1.1 rearnsha #endif
217 1.1 rearnsha
218 1.1 rearnsha int plcomcnspeed = PLCONSPEED;
219 1.1 rearnsha int plcomcnmode = PLCONMODE;
220 1.1 rearnsha
221 1.1 rearnsha #if 0
222 1.1 rearnsha extern struct consdev kcomcons;
223 1.1 rearnsha static void kcomcnputc(dev_t, int);
224 1.1 rearnsha #endif
225 1.1 rearnsha
226 1.1 rearnsha /*
227 1.1 rearnsha * void cpu_reboot(int howto, char *bootstr)
228 1.1 rearnsha *
229 1.1 rearnsha * Reboots the system
230 1.1 rearnsha *
231 1.1 rearnsha * Deal with any syncing, unmounting, dumping and shutdown hooks,
232 1.1 rearnsha * then reset the CPU.
233 1.1 rearnsha */
234 1.1 rearnsha void
235 1.23 rearnsha cpu_reboot(int howto, char *bootstr)
236 1.1 rearnsha {
237 1.1 rearnsha
238 1.1 rearnsha /*
239 1.1 rearnsha * If we are still cold then hit the air brakes
240 1.1 rearnsha * and crash to earth fast
241 1.1 rearnsha */
242 1.1 rearnsha if (cold) {
243 1.1 rearnsha doshutdownhooks();
244 1.59 dyoung pmf_system_shutdown(boothowto);
245 1.1 rearnsha printf("The operating system has halted.\n");
246 1.1 rearnsha printf("Please press any key to reboot.\n\n");
247 1.1 rearnsha cngetc();
248 1.1 rearnsha printf("rebooting...\n");
249 1.1 rearnsha ifpga_reset();
250 1.1 rearnsha /*NOTREACHED*/
251 1.1 rearnsha }
252 1.1 rearnsha
253 1.1 rearnsha /* Disable console buffering */
254 1.1 rearnsha
255 1.1 rearnsha /*
256 1.1 rearnsha * If RB_NOSYNC was not specified sync the discs.
257 1.23 rearnsha * Note: Unless cold is set to 1 here, syslogd will die during the
258 1.23 rearnsha * unmount. It looks like syslogd is getting woken up only to find
259 1.23 rearnsha * that it cannot page part of the binary in as the filesystem has
260 1.23 rearnsha * been unmounted.
261 1.1 rearnsha */
262 1.1 rearnsha if (!(howto & RB_NOSYNC))
263 1.1 rearnsha bootsync();
264 1.1 rearnsha
265 1.1 rearnsha /* Say NO to interrupts */
266 1.1 rearnsha splhigh();
267 1.1 rearnsha
268 1.1 rearnsha /* Do a dump if requested. */
269 1.1 rearnsha if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
270 1.1 rearnsha dumpsys();
271 1.1 rearnsha
272 1.1 rearnsha /* Run any shutdown hooks */
273 1.1 rearnsha doshutdownhooks();
274 1.1 rearnsha
275 1.59 dyoung pmf_system_shutdown(boothowto);
276 1.59 dyoung
277 1.1 rearnsha /* Make sure IRQ's are disabled */
278 1.1 rearnsha IRQdisable;
279 1.1 rearnsha
280 1.1 rearnsha if (howto & RB_HALT) {
281 1.1 rearnsha printf("The operating system has halted.\n");
282 1.1 rearnsha printf("Please press any key to reboot.\n\n");
283 1.1 rearnsha cngetc();
284 1.1 rearnsha }
285 1.1 rearnsha
286 1.1 rearnsha printf("rebooting...\n");
287 1.1 rearnsha ifpga_reset();
288 1.1 rearnsha /*NOTREACHED*/
289 1.1 rearnsha }
290 1.1 rearnsha
291 1.42 thorpej /* Statically mapped devices. */
292 1.42 thorpej static const struct pmap_devmap integrator_devmap[] = {
293 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
294 1.23 rearnsha {
295 1.23 rearnsha UART0_BOOT_BASE,
296 1.23 rearnsha IFPGA_IO_BASE + IFPGA_UART0,
297 1.23 rearnsha 1024 * 1024,
298 1.23 rearnsha VM_PROT_READ|VM_PROT_WRITE,
299 1.23 rearnsha PTE_NOCACHE
300 1.23 rearnsha },
301 1.23 rearnsha
302 1.23 rearnsha {
303 1.23 rearnsha UART1_BOOT_BASE,
304 1.23 rearnsha IFPGA_IO_BASE + IFPGA_UART1,
305 1.23 rearnsha 1024 * 1024,
306 1.23 rearnsha VM_PROT_READ|VM_PROT_WRITE,
307 1.23 rearnsha PTE_NOCACHE
308 1.23 rearnsha },
309 1.1 rearnsha #endif
310 1.1 rearnsha #if NPCI > 0
311 1.23 rearnsha {
312 1.23 rearnsha IFPGA_PCI_IO_VBASE,
313 1.23 rearnsha IFPGA_PCI_IO_BASE,
314 1.23 rearnsha IFPGA_PCI_IO_VSIZE,
315 1.23 rearnsha VM_PROT_READ|VM_PROT_WRITE,
316 1.23 rearnsha PTE_NOCACHE
317 1.23 rearnsha },
318 1.23 rearnsha
319 1.23 rearnsha {
320 1.23 rearnsha IFPGA_PCI_CONF_VBASE,
321 1.23 rearnsha IFPGA_PCI_CONF_BASE,
322 1.23 rearnsha IFPGA_PCI_CONF_VSIZE,
323 1.23 rearnsha VM_PROT_READ|VM_PROT_WRITE,
324 1.42 thorpej PTE_NOCACHE
325 1.42 thorpej },
326 1.1 rearnsha #endif
327 1.1 rearnsha
328 1.23 rearnsha {
329 1.23 rearnsha 0,
330 1.23 rearnsha 0,
331 1.23 rearnsha 0,
332 1.23 rearnsha 0,
333 1.23 rearnsha 0
334 1.23 rearnsha }
335 1.1 rearnsha };
336 1.1 rearnsha
337 1.1 rearnsha /*
338 1.23 rearnsha * u_int initarm(...)
339 1.1 rearnsha *
340 1.1 rearnsha * Initial entry point on startup. This gets called before main() is
341 1.1 rearnsha * entered.
342 1.1 rearnsha * It should be responsible for setting up everything that must be
343 1.1 rearnsha * in place when main is called.
344 1.1 rearnsha * This includes
345 1.1 rearnsha * Taking a copy of the boot configuration structure.
346 1.1 rearnsha * Initialising the physical console so characters can be printed.
347 1.1 rearnsha * Setting up page tables for the kernel
348 1.1 rearnsha * Relocating the kernel to the bottom of physical memory
349 1.1 rearnsha */
350 1.1 rearnsha
351 1.1 rearnsha u_int
352 1.23 rearnsha initarm(void *arg)
353 1.1 rearnsha {
354 1.1 rearnsha int loop;
355 1.1 rearnsha int loop1;
356 1.1 rearnsha u_int l1pagetable;
357 1.55 perry extern char etext __asm ("_etext");
358 1.55 perry extern char end __asm ("_end");
359 1.23 rearnsha paddr_t memstart;
360 1.23 rearnsha psize_t memsize;
361 1.47 rearnsha vm_offset_t physical_freestart;
362 1.47 rearnsha vm_offset_t physical_freeend;
363 1.1 rearnsha
364 1.71 matt cpu_reset_address = ifpga_reset;
365 1.71 matt
366 1.1 rearnsha /*
367 1.1 rearnsha * Heads up ... Setup the CPU / MMU / TLB functions
368 1.1 rearnsha */
369 1.1 rearnsha if (set_cpufuncs())
370 1.50 wiz panic("CPU not recognized!");
371 1.1 rearnsha
372 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
373 1.1 rearnsha /*
374 1.1 rearnsha * Initialise the diagnostic serial console
375 1.1 rearnsha * This allows a means of generating output during initarm().
376 1.1 rearnsha * Once all the memory map changes are complete we can call consinit()
377 1.1 rearnsha * and not have to worry about things moving.
378 1.1 rearnsha */
379 1.1 rearnsha
380 1.1 rearnsha if (PLCOMCNUNIT == 0) {
381 1.69 skrll static struct bus_space plcom_bus_space;
382 1.69 skrll static struct plcom_instance ifpga_pi0 = {
383 1.69 skrll .pi_type = PLCOM_TYPE_PL010,
384 1.69 skrll .pi_iot = &plcom_bus_space,
385 1.69 skrll .pi_size = IFPGA_UART_SIZE,
386 1.69 skrll .pi_iobase = 0x0
387 1.69 skrll };
388 1.69 skrll
389 1.1 rearnsha ifpga_create_io_bs_tag(&plcom_bus_space, (void*)0xfd600000);
390 1.69 skrll plcomcnattach(&ifpga_pi0, plcomcnspeed, IFPGA_UART_CLK,
391 1.69 skrll plcomcnmode, PLCOMCNUNIT);
392 1.1 rearnsha } else if (PLCOMCNUNIT == 1) {
393 1.69 skrll static struct bus_space plcom_bus_space;
394 1.69 skrll static struct plcom_instance ifpga_pi1 = {
395 1.69 skrll .pi_type = PLCOM_TYPE_PL010,
396 1.69 skrll .pi_iot = &plcom_bus_space,
397 1.69 skrll .pi_size = IFPGA_UART_SIZE,
398 1.69 skrll .pi_iobase = 0x0
399 1.69 skrll };
400 1.69 skrll
401 1.1 rearnsha ifpga_create_io_bs_tag(&plcom_bus_space, (void*)0xfd700000);
402 1.69 skrll plcomcnattach(&ifpga_pi1, plcomcnspeed, IFPGA_UART_CLK,
403 1.69 skrll plcomcnmode, PLCOMCNUNIT);
404 1.1 rearnsha }
405 1.1 rearnsha #endif
406 1.1 rearnsha
407 1.38 thorpej #ifdef VERBOSE_INIT_ARM
408 1.1 rearnsha /* Talk to the user */
409 1.23 rearnsha printf("\nNetBSD/evbarm (Integrator) booting ...\n");
410 1.38 thorpej #endif
411 1.1 rearnsha
412 1.1 rearnsha /*
413 1.23 rearnsha * Fetch the SDRAM start/size from the CM configuration registers.
414 1.1 rearnsha */
415 1.23 rearnsha integrator_sdram_bounds(&memstart, &memsize);
416 1.1 rearnsha
417 1.38 thorpej #ifdef VERBOSE_INIT_ARM
418 1.1 rearnsha printf("initarm: Configuring system ...\n");
419 1.38 thorpej #endif
420 1.1 rearnsha
421 1.23 rearnsha /* Fake bootconfig structure for the benefit of pmap.c */
422 1.23 rearnsha /* XXX must make the memory description h/w independent */
423 1.23 rearnsha bootconfig.dramblocks = 1;
424 1.23 rearnsha bootconfig.dram[0].address = memstart;
425 1.31 thorpej bootconfig.dram[0].pages = memsize / PAGE_SIZE;
426 1.47 rearnsha bootconfig.dram[0].flags = BOOT_DRAM_CAN_DMA | BOOT_DRAM_PREFER;
427 1.23 rearnsha
428 1.1 rearnsha /*
429 1.1 rearnsha * Set up the variables that define the availablilty of
430 1.23 rearnsha * physical memory. For now, we're going to set
431 1.23 rearnsha * physical_freestart to 0x00200000 (where the kernel
432 1.23 rearnsha * was loaded), and allocate the memory we need downwards.
433 1.23 rearnsha * If we get too close to the L1 table that we set up, we
434 1.23 rearnsha * will panic. We will update physical_freestart and
435 1.23 rearnsha * physical_freeend later to reflect what pmap_bootstrap()
436 1.23 rearnsha * wants to see.
437 1.23 rearnsha *
438 1.47 rearnsha * We assume that the kernel is loaded into bank[0].
439 1.47 rearnsha *
440 1.23 rearnsha * XXX pmap_bootstrap() needs an enema.
441 1.1 rearnsha */
442 1.23 rearnsha physical_start = bootconfig.dram[0].address;
443 1.47 rearnsha physical_end = 0;
444 1.1 rearnsha
445 1.47 rearnsha /* Update the address of the first free 16KB chunk of physical memory */
446 1.47 rearnsha physical_freestart = ((uintptr_t) &end - KERNEL_BASE + PGOFSET)
447 1.47 rearnsha & ~PGOFSET;
448 1.47 rearnsha if (physical_freestart < bootconfig.dram[0].address)
449 1.47 rearnsha physical_freestart = bootconfig.dram[0].address;
450 1.47 rearnsha physical_freeend = bootconfig.dram[0].address +
451 1.47 rearnsha bootconfig.dram[0].pages * PAGE_SIZE;
452 1.47 rearnsha
453 1.47 rearnsha for (loop = 0, physmem = 0; loop < bootconfig.dramblocks; loop++) {
454 1.47 rearnsha paddr_t memoryblock_end;
455 1.47 rearnsha
456 1.47 rearnsha memoryblock_end = bootconfig.dram[loop].address +
457 1.47 rearnsha bootconfig.dram[loop].pages * PAGE_SIZE;
458 1.47 rearnsha if (memoryblock_end > physical_end)
459 1.47 rearnsha physical_end = memoryblock_end;
460 1.47 rearnsha if (bootconfig.dram[loop].address < physical_start)
461 1.47 rearnsha physical_start = bootconfig.dram[loop].address;
462 1.47 rearnsha
463 1.47 rearnsha physmem += bootconfig.dram[loop].pages;
464 1.47 rearnsha }
465 1.1 rearnsha
466 1.38 thorpej #ifdef VERBOSE_INIT_ARM
467 1.1 rearnsha /* Tell the user about the memory */
468 1.1 rearnsha printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
469 1.1 rearnsha physical_start, physical_end - 1);
470 1.38 thorpej #endif
471 1.1 rearnsha
472 1.1 rearnsha /*
473 1.23 rearnsha * Okay, the kernel starts 2MB in from the bottom of physical
474 1.23 rearnsha * memory. We are going to allocate our bootstrap pages downwards
475 1.23 rearnsha * from there.
476 1.1 rearnsha *
477 1.23 rearnsha * We need to allocate some fixed page tables to get the kernel
478 1.23 rearnsha * going. We allocate one page directory and a number of page
479 1.23 rearnsha * tables and store the physical addresses in the kernel_pt_table
480 1.23 rearnsha * array.
481 1.23 rearnsha *
482 1.23 rearnsha * The kernel page directory must be on a 16K boundary. The page
483 1.53 abs * tables must be on 4K boundaries. What we do is allocate the
484 1.23 rearnsha * page directory on the first 16K boundary that we encounter, and
485 1.23 rearnsha * the page tables on 4K boundaries otherwise. Since we allocate
486 1.23 rearnsha * at least 3 L2 page tables, we are guaranteed to encounter at
487 1.23 rearnsha * least one 16K aligned region.
488 1.1 rearnsha */
489 1.1 rearnsha
490 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
491 1.1 rearnsha printf("Allocating page tables\n");
492 1.1 rearnsha #endif
493 1.1 rearnsha
494 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
495 1.47 rearnsha printf("freestart = 0x%08lx, free pages = %d (0x%08x)\n",
496 1.47 rearnsha physical_freestart, physmem, physmem);
497 1.1 rearnsha #endif
498 1.1 rearnsha
499 1.1 rearnsha /* Define a macro to simplify memory allocation */
500 1.23 rearnsha #define valloc_pages(var, np) \
501 1.23 rearnsha alloc_pages((var).pv_pa, (np)); \
502 1.47 rearnsha (var).pv_va = KERNEL_BASE + (var).pv_pa;
503 1.23 rearnsha
504 1.23 rearnsha #define alloc_pages(var, np) \
505 1.47 rearnsha (var) = physical_freestart; \
506 1.47 rearnsha physical_freestart += ((np) * PAGE_SIZE); \
507 1.23 rearnsha if (physical_freeend < physical_freestart) \
508 1.23 rearnsha panic("initarm: out of memory"); \
509 1.31 thorpej memset((char *)(var), 0, ((np) * PAGE_SIZE));
510 1.1 rearnsha
511 1.1 rearnsha loop1 = 0;
512 1.1 rearnsha for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
513 1.1 rearnsha /* Are we 16KB aligned for an L1 ? */
514 1.47 rearnsha if ((physical_freestart & (L1_TABLE_SIZE - 1)) == 0
515 1.1 rearnsha && kernel_l1pt.pv_pa == 0) {
516 1.31 thorpej valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
517 1.1 rearnsha } else {
518 1.33 thorpej valloc_pages(kernel_pt_table[loop1],
519 1.33 thorpej L2_TABLE_SIZE / PAGE_SIZE);
520 1.23 rearnsha ++loop1;
521 1.1 rearnsha }
522 1.1 rearnsha }
523 1.1 rearnsha
524 1.1 rearnsha /* This should never be able to happen but better confirm that. */
525 1.21 thorpej if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
526 1.28 provos panic("initarm: Failed to align the kernel page directory");
527 1.1 rearnsha
528 1.1 rearnsha /*
529 1.1 rearnsha * Allocate a page for the system page mapped to V0x00000000
530 1.1 rearnsha * This page will just contain the system vectors and can be
531 1.1 rearnsha * shared by all processes.
532 1.1 rearnsha */
533 1.1 rearnsha alloc_pages(systempage.pv_pa, 1);
534 1.1 rearnsha
535 1.1 rearnsha /* Allocate stacks for all modes */
536 1.1 rearnsha valloc_pages(irqstack, IRQ_STACK_SIZE);
537 1.1 rearnsha valloc_pages(abtstack, ABT_STACK_SIZE);
538 1.1 rearnsha valloc_pages(undstack, UND_STACK_SIZE);
539 1.1 rearnsha valloc_pages(kernelstack, UPAGES);
540 1.1 rearnsha
541 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
542 1.23 rearnsha printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
543 1.23 rearnsha irqstack.pv_va);
544 1.23 rearnsha printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
545 1.23 rearnsha abtstack.pv_va);
546 1.23 rearnsha printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
547 1.23 rearnsha undstack.pv_va);
548 1.23 rearnsha printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
549 1.23 rearnsha kernelstack.pv_va);
550 1.1 rearnsha #endif
551 1.1 rearnsha
552 1.31 thorpej alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
553 1.1 rearnsha
554 1.1 rearnsha /*
555 1.1 rearnsha * Ok we have allocated physical pages for the primary kernel
556 1.1 rearnsha * page tables
557 1.1 rearnsha */
558 1.1 rearnsha
559 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
560 1.23 rearnsha printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
561 1.1 rearnsha #endif
562 1.1 rearnsha
563 1.1 rearnsha /*
564 1.23 rearnsha * Now we start construction of the L1 page table
565 1.1 rearnsha * We start by mapping the L2 page tables into the L1.
566 1.1 rearnsha * This means that we can replace L1 mappings later on if necessary
567 1.1 rearnsha */
568 1.1 rearnsha l1pagetable = kernel_l1pt.pv_pa;
569 1.1 rearnsha
570 1.1 rearnsha /* Map the L2 pages tables in the L1 page table */
571 1.11 thorpej pmap_link_l2pt(l1pagetable, 0x00000000,
572 1.14 thorpej &kernel_pt_table[KERNEL_PT_SYS]);
573 1.23 rearnsha for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
574 1.23 rearnsha pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
575 1.23 rearnsha &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
576 1.23 rearnsha for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
577 1.11 thorpej pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
578 1.14 thorpej &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
579 1.17 chris
580 1.17 chris /* update the top of the kernel VM */
581 1.19 thorpej pmap_curmaxkvaddr =
582 1.19 thorpej KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
583 1.1 rearnsha
584 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
585 1.1 rearnsha printf("Mapping kernel\n");
586 1.1 rearnsha #endif
587 1.1 rearnsha
588 1.1 rearnsha /* Now we fill in the L2 pagetable for the kernel static code/data */
589 1.1 rearnsha {
590 1.1 rearnsha size_t textsize = (uintptr_t) &etext - KERNEL_TEXT_BASE;
591 1.1 rearnsha size_t totalsize = (uintptr_t) &end - KERNEL_TEXT_BASE;
592 1.23 rearnsha u_int logical;
593 1.1 rearnsha
594 1.23 rearnsha textsize = (textsize + PGOFSET) & ~PGOFSET;
595 1.1 rearnsha totalsize = (totalsize + PGOFSET) & ~PGOFSET;
596 1.23 rearnsha
597 1.23 rearnsha logical = 0x00200000; /* offset of kernel in RAM */
598 1.23 rearnsha
599 1.23 rearnsha logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
600 1.47 rearnsha logical, textsize, VM_PROT_READ | VM_PROT_WRITE,
601 1.47 rearnsha PTE_CACHE);
602 1.23 rearnsha logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
603 1.47 rearnsha logical, totalsize - textsize,
604 1.47 rearnsha VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
605 1.1 rearnsha }
606 1.1 rearnsha
607 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
608 1.1 rearnsha printf("Constructing L2 page tables\n");
609 1.1 rearnsha #endif
610 1.1 rearnsha
611 1.1 rearnsha /* Map the stack pages */
612 1.14 thorpej pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
613 1.31 thorpej IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
614 1.14 thorpej pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
615 1.31 thorpej ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
616 1.14 thorpej pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
617 1.31 thorpej UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
618 1.14 thorpej pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
619 1.31 thorpej UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
620 1.13 thorpej
621 1.33 thorpej pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
622 1.33 thorpej L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
623 1.1 rearnsha
624 1.33 thorpej for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
625 1.33 thorpej pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
626 1.44 rearnsha kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
627 1.33 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
628 1.33 thorpej }
629 1.1 rearnsha
630 1.20 thorpej /* Map the vector page. */
631 1.1 rearnsha #if 1
632 1.1 rearnsha /* MULTI-ICE requires that page 0 is NC/NB so that it can download
633 1.1 rearnsha the cache-clean code there. */
634 1.51 rearnsha pmap_map_entry(l1pagetable, ARM_VECTORS_LOW, systempage.pv_pa,
635 1.10 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_NOCACHE);
636 1.1 rearnsha #else
637 1.51 rearnsha pmap_map_entry(l1pagetable, ARM_VECTORS_LOW, systempage.pv_pa,
638 1.20 thorpej VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
639 1.1 rearnsha #endif
640 1.1 rearnsha
641 1.42 thorpej /* Map the statically mapped devices. */
642 1.42 thorpej pmap_devmap_bootstrap(l1pagetable, integrator_devmap);
643 1.1 rearnsha
644 1.1 rearnsha /*
645 1.1 rearnsha * Now we have the real page tables in place so we can switch to them.
646 1.23 rearnsha * Once this is done we will be running with the REAL kernel page
647 1.23 rearnsha * tables.
648 1.23 rearnsha */
649 1.23 rearnsha
650 1.1 rearnsha /* Switch tables */
651 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
652 1.1 rearnsha printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
653 1.1 rearnsha #endif
654 1.33 thorpej cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
655 1.66 uebayasi cpu_setttb(kernel_l1pt.pv_pa);
656 1.23 rearnsha cpu_tlb_flushID();
657 1.33 thorpej cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
658 1.33 thorpej
659 1.33 thorpej /*
660 1.33 thorpej * Moved from cpu_startup() as data_abort_handler() references
661 1.33 thorpej * this during uvm init
662 1.33 thorpej */
663 1.64 rmind uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
664 1.1 rearnsha
665 1.1 rearnsha #ifdef PLCONSOLE
666 1.1 rearnsha /*
667 1.1 rearnsha * The IFPGA registers have just moved.
668 1.1 rearnsha * Detach the diagnostic serial port and reattach at the new address.
669 1.1 rearnsha */
670 1.1 rearnsha plcomcndetach();
671 1.1 rearnsha #endif
672 1.1 rearnsha
673 1.1 rearnsha /*
674 1.1 rearnsha * XXX this should only be done in main() but it useful to
675 1.1 rearnsha * have output earlier ...
676 1.1 rearnsha */
677 1.1 rearnsha consinit();
678 1.1 rearnsha
679 1.1 rearnsha #ifdef VERBOSE_INIT_ARM
680 1.1 rearnsha printf("bootstrap done.\n");
681 1.1 rearnsha #endif
682 1.1 rearnsha
683 1.20 thorpej arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
684 1.1 rearnsha
685 1.1 rearnsha /*
686 1.1 rearnsha * Pages were allocated during the secondary bootstrap for the
687 1.1 rearnsha * stacks for different CPU modes.
688 1.1 rearnsha * We must now set the r13 registers in the different CPU modes to
689 1.1 rearnsha * point to these stacks.
690 1.1 rearnsha * Since the ARM stacks use STMFD etc. we must set r13 to the top end
691 1.1 rearnsha * of the stack memory.
692 1.1 rearnsha */
693 1.38 thorpej #ifdef VERBOSE_INIT_ARM
694 1.1 rearnsha printf("init subsystems: stacks ");
695 1.38 thorpej #endif
696 1.1 rearnsha
697 1.31 thorpej set_stackptr(PSR_IRQ32_MODE,
698 1.31 thorpej irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
699 1.31 thorpej set_stackptr(PSR_ABT32_MODE,
700 1.31 thorpej abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
701 1.31 thorpej set_stackptr(PSR_UND32_MODE,
702 1.31 thorpej undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
703 1.1 rearnsha
704 1.1 rearnsha /*
705 1.1 rearnsha * Well we should set a data abort handler.
706 1.23 rearnsha * Once things get going this will change as we will need a proper
707 1.23 rearnsha * handler.
708 1.1 rearnsha * Until then we will use a handler that just panics but tells us
709 1.1 rearnsha * why.
710 1.1 rearnsha * Initialisation of the vectors will just panic on a data abort.
711 1.52 abs * This just fills in a slightly better one.
712 1.1 rearnsha */
713 1.38 thorpej #ifdef VERBOSE_INIT_ARM
714 1.1 rearnsha printf("vectors ");
715 1.38 thorpej #endif
716 1.1 rearnsha data_abort_handler_address = (u_int)data_abort_handler;
717 1.1 rearnsha prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
718 1.1 rearnsha undefined_handler_address = (u_int)undefinedinstruction_bounce;
719 1.1 rearnsha
720 1.1 rearnsha /* Initialise the undefined instruction handlers */
721 1.38 thorpej #ifdef VERBOSE_INIT_ARM
722 1.1 rearnsha printf("undefined ");
723 1.38 thorpej #endif
724 1.1 rearnsha undefined_init();
725 1.1 rearnsha
726 1.25 thorpej /* Load memory into UVM. */
727 1.38 thorpej #ifdef VERBOSE_INIT_ARM
728 1.25 thorpej printf("page ");
729 1.38 thorpej #endif
730 1.25 thorpej uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
731 1.47 rearnsha
732 1.47 rearnsha /* Round the start up and the end down to a page. */
733 1.47 rearnsha physical_freestart = (physical_freestart + PGOFSET) & ~PGOFSET;
734 1.47 rearnsha physical_freeend &= ~PGOFSET;
735 1.47 rearnsha
736 1.47 rearnsha for (loop = 0; loop < bootconfig.dramblocks; loop++) {
737 1.47 rearnsha paddr_t block_start = (paddr_t) bootconfig.dram[loop].address;
738 1.47 rearnsha paddr_t block_end = block_start +
739 1.47 rearnsha (bootconfig.dram[loop].pages * PAGE_SIZE);
740 1.47 rearnsha
741 1.47 rearnsha if (loop == 0) {
742 1.47 rearnsha block_start = physical_freestart;
743 1.47 rearnsha block_end = physical_freeend;
744 1.47 rearnsha }
745 1.47 rearnsha
746 1.47 rearnsha
747 1.47 rearnsha uvm_page_physload(atop(block_start), atop(block_end),
748 1.47 rearnsha atop(block_start), atop(block_end),
749 1.47 rearnsha (bootconfig.dram[loop].flags & BOOT_DRAM_PREFER) ?
750 1.47 rearnsha VM_FREELIST_DEFAULT : VM_FREELIST_DEFAULT + 1);
751 1.47 rearnsha }
752 1.25 thorpej
753 1.1 rearnsha /* Boot strap pmap telling it where the kernel page table is */
754 1.38 thorpej #ifdef VERBOSE_INIT_ARM
755 1.1 rearnsha printf("pmap ");
756 1.38 thorpej #endif
757 1.58 matt pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
758 1.1 rearnsha
759 1.1 rearnsha /* Setup the IRQ system */
760 1.38 thorpej #ifdef VERBOSE_INIT_ARM
761 1.1 rearnsha printf("irq ");
762 1.38 thorpej #endif
763 1.48 rearnsha ifpga_intr_init();
764 1.1 rearnsha
765 1.38 thorpej #ifdef VERBOSE_INIT_ARM
766 1.1 rearnsha printf("done.\n");
767 1.38 thorpej #endif
768 1.1 rearnsha
769 1.1 rearnsha #ifdef DDB
770 1.1 rearnsha db_machine_init();
771 1.1 rearnsha if (boothowto & RB_KDB)
772 1.1 rearnsha Debugger();
773 1.1 rearnsha #endif
774 1.1 rearnsha
775 1.1 rearnsha /* We return the new stack pointer address */
776 1.1 rearnsha return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
777 1.1 rearnsha }
778 1.1 rearnsha
779 1.1 rearnsha void
780 1.1 rearnsha consinit(void)
781 1.1 rearnsha {
782 1.1 rearnsha static int consinit_called = 0;
783 1.1 rearnsha #if 0
784 1.1 rearnsha char *console = CONSDEVNAME;
785 1.1 rearnsha #endif
786 1.1 rearnsha
787 1.1 rearnsha if (consinit_called != 0)
788 1.1 rearnsha return;
789 1.1 rearnsha
790 1.1 rearnsha consinit_called = 1;
791 1.1 rearnsha
792 1.1 rearnsha #if NPLCOM > 0 && defined(PLCONSOLE)
793 1.1 rearnsha if (PLCOMCNUNIT == 0) {
794 1.69 skrll static struct bus_space plcom_bus_space;
795 1.69 skrll static struct plcom_instance ifpga_pi1 = {
796 1.69 skrll .pi_type = PLCOM_TYPE_PL010,
797 1.69 skrll .pi_iot = &plcom_bus_space,
798 1.69 skrll .pi_size = IFPGA_UART_SIZE,
799 1.69 skrll .pi_iobase = 0x0
800 1.69 skrll };
801 1.69 skrll
802 1.1 rearnsha ifpga_create_io_bs_tag(&plcom_bus_space,
803 1.1 rearnsha (void*)UART0_BOOT_BASE);
804 1.69 skrll
805 1.69 skrll if (plcomcnattach(&ifpga_pi1, plcomcnspeed, IFPGA_UART_CLK,
806 1.69 skrll plcomcnmode, PLCOMCNUNIT))
807 1.1 rearnsha panic("can't init serial console");
808 1.1 rearnsha return;
809 1.1 rearnsha } else if (PLCOMCNUNIT == 1) {
810 1.69 skrll static struct bus_space plcom_bus_space;
811 1.69 skrll static struct plcom_instance ifpga_pi1 = {
812 1.69 skrll .pi_type = PLCOM_TYPE_PL010,
813 1.69 skrll .pi_iot = &plcom_bus_space,
814 1.69 skrll .pi_size = IFPGA_UART_SIZE,
815 1.69 skrll .pi_iobase = 0x0
816 1.69 skrll };
817 1.69 skrll
818 1.1 rearnsha ifpga_create_io_bs_tag(&plcom_bus_space,
819 1.1 rearnsha (void*)UART0_BOOT_BASE);
820 1.69 skrll
821 1.69 skrll if (plcomcnattach(&ifpga_pi1, plcomcnspeed, IFPGA_UART_CLK,
822 1.69 skrll plcomcnmode, PLCOMCNUNIT))
823 1.1 rearnsha panic("can't init serial console");
824 1.1 rearnsha return;
825 1.1 rearnsha }
826 1.1 rearnsha #endif
827 1.1 rearnsha #if (NCOM > 0)
828 1.1 rearnsha if (comcnattach(&isa_io_bs_tag, CONCOMADDR, comcnspeed,
829 1.41 thorpej COM_FREQ, COM_TYPE_NORMAL, comcnmode))
830 1.1 rearnsha panic("can't init serial console @%x", CONCOMADDR);
831 1.1 rearnsha return;
832 1.1 rearnsha #endif
833 1.1 rearnsha panic("No serial console configured");
834 1.23 rearnsha }
835 1.23 rearnsha
836 1.23 rearnsha static void
837 1.23 rearnsha integrator_sdram_bounds(paddr_t *memstart, psize_t *memsize)
838 1.23 rearnsha {
839 1.23 rearnsha volatile unsigned long *cm_sdram
840 1.23 rearnsha = (volatile unsigned long *)0x10000020;
841 1.46 rearnsha volatile unsigned long *cm_stat
842 1.46 rearnsha = (volatile unsigned long *)0x10000010;
843 1.23 rearnsha
844 1.46 rearnsha *memstart = *cm_stat & 0x00ff0000;
845 1.23 rearnsha
846 1.46 rearnsha /*
847 1.46 rearnsha * Although the SSRAM overlaps the SDRAM, we can use the wrap-around
848 1.46 rearnsha * to access the entire bank.
849 1.46 rearnsha */
850 1.23 rearnsha switch ((*cm_sdram >> 2) & 0x7)
851 1.23 rearnsha {
852 1.23 rearnsha case 0:
853 1.23 rearnsha *memsize = 16 * 1024 * 1024;
854 1.23 rearnsha break;
855 1.23 rearnsha case 1:
856 1.23 rearnsha *memsize = 32 * 1024 * 1024;
857 1.23 rearnsha break;
858 1.23 rearnsha case 2:
859 1.23 rearnsha *memsize = 64 * 1024 * 1024;
860 1.23 rearnsha break;
861 1.23 rearnsha case 3:
862 1.23 rearnsha *memsize = 128 * 1024 * 1024;
863 1.23 rearnsha break;
864 1.23 rearnsha case 4:
865 1.46 rearnsha /* With 256M of memory there is no wrap-around. */
866 1.46 rearnsha *memsize = 256 * 1024 * 1024 - *memstart;
867 1.23 rearnsha break;
868 1.23 rearnsha default:
869 1.23 rearnsha printf("CM_SDRAM retuns unknown value, using 16M\n");
870 1.23 rearnsha *memsize = 16 * 1024 * 1024;
871 1.23 rearnsha break;
872 1.23 rearnsha }
873 1.1 rearnsha }
874