marvell_machdep.c revision 1.1.2.2 1 1.1.2.2 yamt /* $NetBSD: marvell_machdep.c,v 1.1.2.2 2010/10/09 03:31:44 yamt Exp $ */
2 1.1.2.2 yamt /*
3 1.1.2.2 yamt * Copyright (c) 2007, 2008, 2010 KIYOHARA Takashi
4 1.1.2.2 yamt * All rights reserved.
5 1.1.2.2 yamt *
6 1.1.2.2 yamt * Redistribution and use in source and binary forms, with or without
7 1.1.2.2 yamt * modification, are permitted provided that the following conditions
8 1.1.2.2 yamt * are met:
9 1.1.2.2 yamt * 1. Redistributions of source code must retain the above copyright
10 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer.
11 1.1.2.2 yamt * 2. Redistributions in binary form must reproduce the above copyright
12 1.1.2.2 yamt * notice, this list of conditions and the following disclaimer in the
13 1.1.2.2 yamt * documentation and/or other materials provided with the distribution.
14 1.1.2.2 yamt *
15 1.1.2.2 yamt * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1.2.2 yamt * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 1.1.2.2 yamt * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 1.1.2.2 yamt * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 1.1.2.2 yamt * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 1.1.2.2 yamt * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 1.1.2.2 yamt * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1.2.2 yamt * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 1.1.2.2 yamt * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 1.1.2.2 yamt * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1.2.2 yamt * POSSIBILITY OF SUCH DAMAGE.
26 1.1.2.2 yamt */
27 1.1.2.2 yamt #include <sys/cdefs.h>
28 1.1.2.2 yamt __KERNEL_RCSID(0, "$NetBSD: marvell_machdep.c,v 1.1.2.2 2010/10/09 03:31:44 yamt Exp $");
29 1.1.2.2 yamt
30 1.1.2.2 yamt #include "opt_evbarm_boardtype.h"
31 1.1.2.2 yamt #include "opt_ddb.h"
32 1.1.2.2 yamt #include "opt_pci.h"
33 1.1.2.2 yamt #include "opt_mvsoc.h"
34 1.1.2.2 yamt #include "com.h"
35 1.1.2.2 yamt #include "gtpci.h"
36 1.1.2.2 yamt #include "mvpex.h"
37 1.1.2.2 yamt
38 1.1.2.2 yamt #include <sys/param.h>
39 1.1.2.2 yamt #include <sys/kernel.h>
40 1.1.2.2 yamt #include <sys/reboot.h>
41 1.1.2.2 yamt #include <sys/systm.h>
42 1.1.2.2 yamt #include <sys/termios.h>
43 1.1.2.2 yamt
44 1.1.2.2 yamt #include <prop/proplib.h>
45 1.1.2.2 yamt
46 1.1.2.2 yamt #include <dev/cons.h>
47 1.1.2.2 yamt #include <dev/md.h>
48 1.1.2.2 yamt
49 1.1.2.2 yamt #include <dev/marvell/marvellreg.h>
50 1.1.2.2 yamt #include <dev/marvell/marvellvar.h>
51 1.1.2.2 yamt #include <dev/pci/pcireg.h>
52 1.1.2.2 yamt #include <dev/pci/pcivar.h>
53 1.1.2.2 yamt
54 1.1.2.2 yamt #include <machine/autoconf.h>
55 1.1.2.2 yamt #include <machine/bootconfig.h>
56 1.1.2.2 yamt #include <machine/pci_machdep.h>
57 1.1.2.2 yamt
58 1.1.2.2 yamt #include <uvm/uvm_extern.h>
59 1.1.2.2 yamt
60 1.1.2.2 yamt #include <arm/db_machdep.h>
61 1.1.2.2 yamt #include <arm/undefined.h>
62 1.1.2.2 yamt #include <arm/arm32/machdep.h>
63 1.1.2.2 yamt
64 1.1.2.2 yamt #include <arm/marvell/mvsocreg.h>
65 1.1.2.2 yamt #include <arm/marvell/mvsocvar.h>
66 1.1.2.2 yamt #include <arm/marvell/orionreg.h>
67 1.1.2.2 yamt #include <arm/marvell/kirkwoodreg.h>
68 1.1.2.2 yamt #include <arm/marvell/mvsocgppvar.h>
69 1.1.2.2 yamt
70 1.1.2.2 yamt #include <evbarm/marvell/marvellreg.h>
71 1.1.2.2 yamt #include <evbarm/marvell/marvellvar.h>
72 1.1.2.2 yamt
73 1.1.2.2 yamt #include <ddb/db_extern.h>
74 1.1.2.2 yamt #include <ddb/db_sym.h>
75 1.1.2.2 yamt
76 1.1.2.2 yamt #include "ksyms.h"
77 1.1.2.2 yamt
78 1.1.2.2 yamt
79 1.1.2.2 yamt /* Kernel text starts 2MB in from the bottom of the kernel address space. */
80 1.1.2.2 yamt #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00000000)
81 1.1.2.2 yamt #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
82 1.1.2.2 yamt
83 1.1.2.2 yamt /*
84 1.1.2.2 yamt * The range 0xc1000000 - 0xccffffff is available for kernel VM space
85 1.1.2.2 yamt * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
86 1.1.2.2 yamt */
87 1.1.2.2 yamt #define KERNEL_VM_SIZE 0x0c000000
88 1.1.2.2 yamt
89 1.1.2.2 yamt /*
90 1.1.2.2 yamt * Address to call from cpu_reset() to reset the machine.
91 1.1.2.2 yamt * This is machine architecture dependant as it varies depending
92 1.1.2.2 yamt * on where the ROM appears when you turn the MMU off.
93 1.1.2.2 yamt */
94 1.1.2.2 yamt
95 1.1.2.2 yamt u_int cpu_reset_address = 0xffff0000;
96 1.1.2.2 yamt
97 1.1.2.2 yamt /* Define various stack sizes in pages */
98 1.1.2.2 yamt #define IRQ_STACK_SIZE 1
99 1.1.2.2 yamt #define ABT_STACK_SIZE 1
100 1.1.2.2 yamt #ifdef IPKDB
101 1.1.2.2 yamt #define UND_STACK_SIZE 2
102 1.1.2.2 yamt #else
103 1.1.2.2 yamt #define UND_STACK_SIZE 1
104 1.1.2.2 yamt #endif
105 1.1.2.2 yamt
106 1.1.2.2 yamt BootConfig bootconfig; /* Boot config storage */
107 1.1.2.2 yamt char *boot_args = NULL;
108 1.1.2.2 yamt
109 1.1.2.2 yamt vm_offset_t physical_start;
110 1.1.2.2 yamt vm_offset_t physical_freestart;
111 1.1.2.2 yamt vm_offset_t physical_freeend;
112 1.1.2.2 yamt vm_offset_t physical_end;
113 1.1.2.2 yamt u_int free_pages;
114 1.1.2.2 yamt int physmem = 0;
115 1.1.2.2 yamt
116 1.1.2.2 yamt /* Physical and virtual addresses for some global pages */
117 1.1.2.2 yamt pv_addr_t systempage;
118 1.1.2.2 yamt pv_addr_t irqstack;
119 1.1.2.2 yamt pv_addr_t undstack;
120 1.1.2.2 yamt pv_addr_t abtstack;
121 1.1.2.2 yamt pv_addr_t kernelstack;
122 1.1.2.2 yamt
123 1.1.2.2 yamt vm_offset_t msgbufphys;
124 1.1.2.2 yamt
125 1.1.2.2 yamt extern u_int data_abort_handler_address;
126 1.1.2.2 yamt extern u_int prefetch_abort_handler_address;
127 1.1.2.2 yamt extern u_int undefined_handler_address;
128 1.1.2.2 yamt
129 1.1.2.2 yamt extern char _end[];
130 1.1.2.2 yamt
131 1.1.2.2 yamt #define KERNEL_PT_SYS 0 /* Page table for mapping proc0 zero page */
132 1.1.2.2 yamt #define KERNEL_PT_KERNEL 1 /* Page table for mapping kernel */
133 1.1.2.2 yamt #define KERNEL_PT_KERNEL_NUM 4
134 1.1.2.2 yamt #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
135 1.1.2.2 yamt /* Page tables for mapping kernel VM */
136 1.1.2.2 yamt #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
137 1.1.2.2 yamt #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
138 1.1.2.2 yamt
139 1.1.2.2 yamt pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
140 1.1.2.2 yamt
141 1.1.2.2 yamt /*
142 1.1.2.2 yamt * Macros to translate between physical and virtual for a subset of the
143 1.1.2.2 yamt * kernel address space. *Not* for general use.
144 1.1.2.2 yamt */
145 1.1.2.2 yamt #define KERNEL_BASE_PHYS physical_start
146 1.1.2.2 yamt #define KERN_VTOPHYS(va) \
147 1.1.2.2 yamt ((paddr_t)((vaddr_t)va - KERNEL_BASE + KERNEL_BASE_PHYS))
148 1.1.2.2 yamt #define KERN_PHYSTOV(pa) \
149 1.1.2.2 yamt ((vaddr_t)((paddr_t)pa - KERNEL_BASE_PHYS + KERNEL_BASE))
150 1.1.2.2 yamt
151 1.1.2.2 yamt
152 1.1.2.2 yamt #include "com.h"
153 1.1.2.2 yamt #if NCOM > 0
154 1.1.2.2 yamt #include <dev/ic/comreg.h>
155 1.1.2.2 yamt #include <dev/ic/comvar.h>
156 1.1.2.2 yamt #endif
157 1.1.2.2 yamt
158 1.1.2.2 yamt #ifndef CONSPEED
159 1.1.2.2 yamt #define CONSPEED B115200 /* It's a setting of the default of u-boot */
160 1.1.2.2 yamt #endif
161 1.1.2.2 yamt #ifndef CONMODE
162 1.1.2.2 yamt #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
163 1.1.2.2 yamt
164 1.1.2.2 yamt int comcnspeed = CONSPEED;
165 1.1.2.2 yamt int comcnmode = CONMODE;
166 1.1.2.2 yamt #endif
167 1.1.2.2 yamt
168 1.1.2.2 yamt #include "opt_kgdb.h"
169 1.1.2.2 yamt #ifdef KGDB
170 1.1.2.2 yamt #include <sys/kgdb.h>
171 1.1.2.2 yamt #endif
172 1.1.2.2 yamt
173 1.1.2.2 yamt static void marvell_device_register(device_t, void *);
174 1.1.2.2 yamt #if NGTPCI > 0 || NMVPEX > 0
175 1.1.2.2 yamt static void marvell_startend_by_tag(int, uint64_t *, uint64_t *);
176 1.1.2.2 yamt #endif
177 1.1.2.2 yamt
178 1.1.2.2 yamt
179 1.1.2.2 yamt void
180 1.1.2.2 yamt cpu_reboot(int howto, char *bootstr)
181 1.1.2.2 yamt {
182 1.1.2.2 yamt
183 1.1.2.2 yamt /*
184 1.1.2.2 yamt * If we are still cold then hit the air brakes
185 1.1.2.2 yamt * and crash to earth fast
186 1.1.2.2 yamt */
187 1.1.2.2 yamt if (cold) {
188 1.1.2.2 yamt doshutdownhooks();
189 1.1.2.2 yamt printf("The operating system has halted.\r\n");
190 1.1.2.2 yamt printf("Please press any key to reboot.\r\n");
191 1.1.2.2 yamt cngetc();
192 1.1.2.2 yamt printf("rebooting...\r\n");
193 1.1.2.2 yamt cpu_reset();
194 1.1.2.2 yamt }
195 1.1.2.2 yamt
196 1.1.2.2 yamt /*
197 1.1.2.2 yamt * If RB_NOSYNC was not specified sync the discs.
198 1.1.2.2 yamt * Note: Unless cold is set to 1 here, syslogd will die during the
199 1.1.2.2 yamt * unmount. It looks like syslogd is getting woken up only to find
200 1.1.2.2 yamt * that it cannot page part of the binary in as the filesystem has
201 1.1.2.2 yamt * been unmounted.
202 1.1.2.2 yamt */
203 1.1.2.2 yamt if (!(howto & RB_NOSYNC))
204 1.1.2.2 yamt bootsync();
205 1.1.2.2 yamt
206 1.1.2.2 yamt /* Say NO to interrupts */
207 1.1.2.2 yamt splhigh();
208 1.1.2.2 yamt
209 1.1.2.2 yamt /* Do a dump if requested. */
210 1.1.2.2 yamt if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
211 1.1.2.2 yamt dumpsys();
212 1.1.2.2 yamt
213 1.1.2.2 yamt /* Run any shutdown hooks */
214 1.1.2.2 yamt doshutdownhooks();
215 1.1.2.2 yamt
216 1.1.2.2 yamt /* Make sure IRQ's are disabled */
217 1.1.2.2 yamt IRQdisable;
218 1.1.2.2 yamt
219 1.1.2.2 yamt if (howto & RB_HALT) {
220 1.1.2.2 yamt printf("The operating system has halted.\r\n");
221 1.1.2.2 yamt printf("Please press any key to reboot.\r\n");
222 1.1.2.2 yamt cngetc();
223 1.1.2.2 yamt }
224 1.1.2.2 yamt
225 1.1.2.2 yamt printf("rebooting...\r\n");
226 1.1.2.2 yamt cpu_reset();
227 1.1.2.2 yamt
228 1.1.2.2 yamt /*NOTREACHED*/
229 1.1.2.2 yamt }
230 1.1.2.2 yamt
231 1.1.2.2 yamt static inline
232 1.1.2.2 yamt pd_entry_t *
233 1.1.2.2 yamt read_ttb(void)
234 1.1.2.2 yamt {
235 1.1.2.2 yamt long ttb;
236 1.1.2.2 yamt
237 1.1.2.2 yamt __asm volatile("mrc p15, 0, %0, c2, c0, 0" : "=r" (ttb));
238 1.1.2.2 yamt
239 1.1.2.2 yamt return (pd_entry_t *)(ttb & ~((1<<14)-1));
240 1.1.2.2 yamt }
241 1.1.2.2 yamt
242 1.1.2.2 yamt /*
243 1.1.2.2 yamt * Static device mappings. These peripheral registers are mapped at
244 1.1.2.2 yamt * fixed virtual addresses very early in initarm() so that we can use
245 1.1.2.2 yamt * them while booting the kernel, and stay at the same address
246 1.1.2.2 yamt * throughout whole kernel's life time.
247 1.1.2.2 yamt *
248 1.1.2.2 yamt * We use this table twice; once with bootstrap page table, and once
249 1.1.2.2 yamt * with kernel's page table which we build up in initarm().
250 1.1.2.2 yamt *
251 1.1.2.2 yamt * Since we map these registers into the bootstrap page table using
252 1.1.2.2 yamt * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
253 1.1.2.2 yamt * registers segment-aligned and segment-rounded in order to avoid
254 1.1.2.2 yamt * using the 2nd page tables.
255 1.1.2.2 yamt */
256 1.1.2.2 yamt #define _A(a) ((a) & ~L1_S_OFFSET)
257 1.1.2.2 yamt #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
258 1.1.2.2 yamt
259 1.1.2.2 yamt static const struct pmap_devmap marvell_devmap[] = {
260 1.1.2.2 yamt {
261 1.1.2.2 yamt MARVELL_INTERREGS_VBASE,
262 1.1.2.2 yamt _A(MARVELL_INTERREGS_PBASE),
263 1.1.2.2 yamt _S(MARVELL_INTERREGS_SIZE),
264 1.1.2.2 yamt VM_PROT_READ|VM_PROT_WRITE,
265 1.1.2.2 yamt PTE_NOCACHE,
266 1.1.2.2 yamt },
267 1.1.2.2 yamt
268 1.1.2.2 yamt { 0, 0, 0, 0, 0 }
269 1.1.2.2 yamt };
270 1.1.2.2 yamt
271 1.1.2.2 yamt #undef _A
272 1.1.2.2 yamt #undef _S
273 1.1.2.2 yamt
274 1.1.2.2 yamt
275 1.1.2.2 yamt /*
276 1.1.2.2 yamt * u_int initarm(...)
277 1.1.2.2 yamt *
278 1.1.2.2 yamt * Initial entry point on startup. This gets called before main() is
279 1.1.2.2 yamt * entered.
280 1.1.2.2 yamt * It should be responsible for setting up everything that must be
281 1.1.2.2 yamt * in place when main is called.
282 1.1.2.2 yamt * This includes
283 1.1.2.2 yamt * Taking a copy of the boot configuration structure.
284 1.1.2.2 yamt * Initialising the physical console so characters can be printed.
285 1.1.2.2 yamt * Setting up page tables for the kernel
286 1.1.2.2 yamt * Relocating the kernel to the bottom of physical memory
287 1.1.2.2 yamt */
288 1.1.2.2 yamt u_int
289 1.1.2.2 yamt initarm(void *arg)
290 1.1.2.2 yamt {
291 1.1.2.2 yamt uint32_t target, attr, base, size;
292 1.1.2.2 yamt u_int l1pagetable;
293 1.1.2.2 yamt int loop, pt_index, cs, memtag = 0, iotag = 0, window;
294 1.1.2.2 yamt
295 1.1.2.2 yamt /* map some peripheral registers */
296 1.1.2.2 yamt pmap_devmap_bootstrap((vaddr_t)read_ttb(), marvell_devmap);
297 1.1.2.2 yamt
298 1.1.2.2 yamt mvsoc_bootstrap(MARVELL_INTERREGS_VBASE);
299 1.1.2.2 yamt
300 1.1.2.2 yamt /* Get ready for splfoo() */
301 1.1.2.2 yamt switch (mvsoc_model()) {
302 1.1.2.2 yamt #ifdef ORION
303 1.1.2.2 yamt case MARVELL_ORION_1_88F1181:
304 1.1.2.2 yamt case MARVELL_ORION_1_88F5082:
305 1.1.2.2 yamt case MARVELL_ORION_1_88F5180N:
306 1.1.2.2 yamt case MARVELL_ORION_1_88F5181:
307 1.1.2.2 yamt case MARVELL_ORION_1_88F5182:
308 1.1.2.2 yamt case MARVELL_ORION_1_88F6082:
309 1.1.2.2 yamt case MARVELL_ORION_1_88F6183:
310 1.1.2.2 yamt case MARVELL_ORION_1_88W8660:
311 1.1.2.2 yamt case MARVELL_ORION_2_88F1281:
312 1.1.2.2 yamt case MARVELL_ORION_2_88F5281:
313 1.1.2.2 yamt orion_intr_bootstrap();
314 1.1.2.2 yamt
315 1.1.2.2 yamt memtag = ORION_TAG_PEX0_MEM;
316 1.1.2.2 yamt iotag = ORION_TAG_PEX0_IO;
317 1.1.2.2 yamt nwindow = ORION_MLMB_NWINDOW;
318 1.1.2.2 yamt nremap = ORION_MLMB_NREMAP;
319 1.1.2.2 yamt
320 1.1.2.2 yamt orion_getclks(MARVELL_INTERREGS_VBASE);
321 1.1.2.2 yamt if (mvTclk == 166666667) /* 166MHz */
322 1.1.2.2 yamt mvTclk = 166664740; /* ???? */
323 1.1.2.2 yamt break;
324 1.1.2.2 yamt #endif /* ORION */
325 1.1.2.2 yamt
326 1.1.2.2 yamt #ifdef KIRKWOOD
327 1.1.2.2 yamt case MARVELL_KIRKWOOD_88F6180:
328 1.1.2.2 yamt case MARVELL_KIRKWOOD_88F6192:
329 1.1.2.2 yamt case MARVELL_KIRKWOOD_88F6281:
330 1.1.2.2 yamt kirkwood_intr_bootstrap();
331 1.1.2.2 yamt
332 1.1.2.2 yamt memtag = KIRKWOOD_TAG_PEX_MEM;
333 1.1.2.2 yamt iotag = KIRKWOOD_TAG_PEX_IO;
334 1.1.2.2 yamt nwindow = KIRKWOOD_MLMB_NWINDOW;
335 1.1.2.2 yamt nremap = KIRKWOOD_MLMB_NREMAP;
336 1.1.2.2 yamt
337 1.1.2.2 yamt kirkwood_getclks(MARVELL_INTERREGS_VBASE);
338 1.1.2.2 yamt break;
339 1.1.2.2 yamt #endif /* KIRKWOOD */
340 1.1.2.2 yamt
341 1.1.2.2 yamt #ifdef MV78XX0
342 1.1.2.2 yamt case MARVELL_MV78XX0_MV78100:
343 1.1.2.2 yamt case MARVELL_MV78XX0_MV78200:
344 1.1.2.2 yamt mv78xx0_intr_bootstrap();
345 1.1.2.2 yamt
346 1.1.2.2 yamt memtag = MV78XX0_TAG_PEX_MEM;
347 1.1.2.2 yamt iotag = MV78XX0_TAG_PEX_IO;
348 1.1.2.2 yamt nwindow = MV78XX0_MLMB_NWINDOW;
349 1.1.2.2 yamt nremap = MV78XX0_MLMB_NREMAP;
350 1.1.2.2 yamt
351 1.1.2.2 yamt mv78xx0_getclks(MARVELL_INTERREGS_VBASE);
352 1.1.2.2 yamt break;
353 1.1.2.2 yamt #endif /* MV78XX0 */
354 1.1.2.2 yamt
355 1.1.2.2 yamt default:
356 1.1.2.2 yamt /* We can't output console here yet... */
357 1.1.2.2 yamt panic("unknown model...\n");
358 1.1.2.2 yamt
359 1.1.2.2 yamt /* NOTREACHED */
360 1.1.2.2 yamt }
361 1.1.2.2 yamt
362 1.1.2.2 yamt /* Reset PCI-Express space to window register. */
363 1.1.2.2 yamt window = mvsoc_target(memtag, &target, &attr, NULL, NULL);
364 1.1.2.2 yamt write_mlmbreg(MVSOC_MLMB_WCR(window),
365 1.1.2.2 yamt MVSOC_MLMB_WCR_WINEN |
366 1.1.2.2 yamt MVSOC_MLMB_WCR_TARGET(target) |
367 1.1.2.2 yamt MVSOC_MLMB_WCR_ATTR(attr) |
368 1.1.2.2 yamt MVSOC_MLMB_WCR_SIZE(MARVELL_PEXMEM_SIZE));
369 1.1.2.2 yamt write_mlmbreg(MVSOC_MLMB_WBR(window),
370 1.1.2.2 yamt MARVELL_PEXMEM_PBASE & MVSOC_MLMB_WBR_BASE_MASK);
371 1.1.2.2 yamt #ifdef PCI_NETBSD_CONFIGURE
372 1.1.2.2 yamt if (window < nremap) {
373 1.1.2.2 yamt write_mlmbreg(MVSOC_MLMB_WRLR(window),
374 1.1.2.2 yamt MARVELL_PEXMEM_PBASE & MVSOC_MLMB_WRLR_REMAP_MASK);
375 1.1.2.2 yamt write_mlmbreg(MVSOC_MLMB_WRHR(window), 0);
376 1.1.2.2 yamt }
377 1.1.2.2 yamt #endif
378 1.1.2.2 yamt window = mvsoc_target(iotag, &target, &attr, NULL, NULL);
379 1.1.2.2 yamt write_mlmbreg(MVSOC_MLMB_WCR(window),
380 1.1.2.2 yamt MVSOC_MLMB_WCR_WINEN |
381 1.1.2.2 yamt MVSOC_MLMB_WCR_TARGET(target) |
382 1.1.2.2 yamt MVSOC_MLMB_WCR_ATTR(attr) |
383 1.1.2.2 yamt MVSOC_MLMB_WCR_SIZE(MARVELL_PEXIO_SIZE));
384 1.1.2.2 yamt write_mlmbreg(MVSOC_MLMB_WBR(window),
385 1.1.2.2 yamt MARVELL_PEXIO_PBASE & MVSOC_MLMB_WBR_BASE_MASK);
386 1.1.2.2 yamt #ifdef PCI_NETBSD_CONFIGURE
387 1.1.2.2 yamt if (window < nremap) {
388 1.1.2.2 yamt write_mlmbreg(MVSOC_MLMB_WRLR(window),
389 1.1.2.2 yamt MARVELL_PEXIO_PBASE & MVSOC_MLMB_WRLR_REMAP_MASK);
390 1.1.2.2 yamt write_mlmbreg(MVSOC_MLMB_WRHR(window), 0);
391 1.1.2.2 yamt }
392 1.1.2.2 yamt #endif
393 1.1.2.2 yamt
394 1.1.2.2 yamt /*
395 1.1.2.2 yamt * Heads up ... Setup the CPU / MMU / TLB functions
396 1.1.2.2 yamt */
397 1.1.2.2 yamt if (set_cpufuncs())
398 1.1.2.2 yamt panic("cpu not recognized!");
399 1.1.2.2 yamt
400 1.1.2.2 yamt /*
401 1.1.2.2 yamt * U-Boot doesn't use the virtual memory.
402 1.1.2.2 yamt *
403 1.1.2.2 yamt * Physical Address Range Description
404 1.1.2.2 yamt * ----------------------- ----------------------------------
405 1.1.2.2 yamt * 0x00000000 - 0x0fffffff SDRAM Bank 0 (max 256MB)
406 1.1.2.2 yamt * 0x10000000 - 0x1fffffff SDRAM Bank 1 (max 256MB)
407 1.1.2.2 yamt * 0x20000000 - 0x2fffffff SDRAM Bank 2 (max 256MB)
408 1.1.2.2 yamt * 0x30000000 - 0x3fffffff SDRAM Bank 3 (max 256MB)
409 1.1.2.2 yamt * 0xf1000000 - 0xf10fffff SoC Internal Registers
410 1.1.2.2 yamt */
411 1.1.2.2 yamt
412 1.1.2.2 yamt cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
413 1.1.2.2 yamt
414 1.1.2.2 yamt consinit();
415 1.1.2.2 yamt
416 1.1.2.2 yamt /* Talk to the user */
417 1.1.2.2 yamt #define BDSTR(s) _BDSTR(s)
418 1.1.2.2 yamt #define _BDSTR(s) #s
419 1.1.2.2 yamt printf("\nNetBSD/evbarm (" BDSTR(EVBARM_BOARDTYPE) ") booting ...\n");
420 1.1.2.2 yamt
421 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
422 1.1.2.2 yamt printf("initarm: Configuring system ...\n");
423 1.1.2.2 yamt #endif
424 1.1.2.2 yamt
425 1.1.2.2 yamt bootconfig.dramblocks = 0;
426 1.1.2.2 yamt physical_end = physmem = 0;
427 1.1.2.2 yamt for (cs = MARVELL_TAG_SDRAM_CS0; cs <= MARVELL_TAG_SDRAM_CS3; cs++) {
428 1.1.2.2 yamt mvsoc_target(cs, &target, &attr, &base, &size);
429 1.1.2.2 yamt if (size == 0)
430 1.1.2.2 yamt continue;
431 1.1.2.2 yamt
432 1.1.2.2 yamt bootconfig.dram[bootconfig.dramblocks].address = base;
433 1.1.2.2 yamt bootconfig.dram[bootconfig.dramblocks].pages = size / PAGE_SIZE;
434 1.1.2.2 yamt
435 1.1.2.2 yamt if (base != physical_end)
436 1.1.2.2 yamt panic("memory hole not support");
437 1.1.2.2 yamt
438 1.1.2.2 yamt physical_end += size;
439 1.1.2.2 yamt physmem += size / PAGE_SIZE;
440 1.1.2.2 yamt
441 1.1.2.2 yamt bootconfig.dramblocks++;
442 1.1.2.2 yamt }
443 1.1.2.2 yamt
444 1.1.2.2 yamt /*
445 1.1.2.2 yamt * Set up the variables that define the availablilty of
446 1.1.2.2 yamt * physical memory. For now, we're going to set
447 1.1.2.2 yamt * physical_freestart to 0xa0008000 (where the kernel
448 1.1.2.2 yamt * was loaded), and allocate the memory we need downwards.
449 1.1.2.2 yamt * If we get too close to the L1 table that we set up, we
450 1.1.2.2 yamt * will panic. We will update physical_freestart and
451 1.1.2.2 yamt * physical_freeend later to reflect what pmap_bootstrap()
452 1.1.2.2 yamt * wants to see.
453 1.1.2.2 yamt *
454 1.1.2.2 yamt * XXX pmap_bootstrap() needs an enema.
455 1.1.2.2 yamt */
456 1.1.2.2 yamt physical_start = bootconfig.dram[0].address;
457 1.1.2.2 yamt
458 1.1.2.2 yamt /*
459 1.1.2.2 yamt * Our kernel is at the beginning of memory, so set our free space to
460 1.1.2.2 yamt * all the memory after the kernel.
461 1.1.2.2 yamt */
462 1.1.2.2 yamt physical_freestart = KERN_VTOPHYS(round_page((vaddr_t)_end));
463 1.1.2.2 yamt physical_freeend = physical_end;
464 1.1.2.2 yamt
465 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
466 1.1.2.2 yamt /* Tell the user about the memory */
467 1.1.2.2 yamt printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
468 1.1.2.2 yamt physical_start, physical_end - 1);
469 1.1.2.2 yamt #endif
470 1.1.2.2 yamt
471 1.1.2.2 yamt /*
472 1.1.2.2 yamt * Okay, the kernel starts 8kB in from the bottom of physical
473 1.1.2.2 yamt * memory. We are going to allocate our bootstrap pages upwards
474 1.1.2.2 yamt * from physical_freestart.
475 1.1.2.2 yamt *
476 1.1.2.2 yamt * We need to allocate some fixed page tables to get the kernel
477 1.1.2.2 yamt * going. We allocate one page directory and a number of page
478 1.1.2.2 yamt * tables and store the physical addresses in the kernel_pt_table
479 1.1.2.2 yamt * array.
480 1.1.2.2 yamt *
481 1.1.2.2 yamt * The kernel page directory must be on a 16K boundary. The page
482 1.1.2.2 yamt * tables must be on 4K bounaries. What we do is allocate the
483 1.1.2.2 yamt * page directory on the first 16K boundary that we encounter, and
484 1.1.2.2 yamt * the page tables on 4K boundaries otherwise. Since we allocate
485 1.1.2.2 yamt * at least 3 L2 page tables, we are guaranteed to encounter at
486 1.1.2.2 yamt * least one 16K aligned region.
487 1.1.2.2 yamt */
488 1.1.2.2 yamt
489 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
490 1.1.2.2 yamt printf("Allocating page tables\n");
491 1.1.2.2 yamt #endif
492 1.1.2.2 yamt
493 1.1.2.2 yamt free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
494 1.1.2.2 yamt
495 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
496 1.1.2.2 yamt printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
497 1.1.2.2 yamt physical_freestart, free_pages, free_pages);
498 1.1.2.2 yamt #endif
499 1.1.2.2 yamt
500 1.1.2.2 yamt /*
501 1.1.2.2 yamt * Define a macro to simplify memory allocation. As we allocate the
502 1.1.2.2 yamt * memory, make sure that we don't walk over our temporary first level
503 1.1.2.2 yamt * translation table.
504 1.1.2.2 yamt */
505 1.1.2.2 yamt #define valloc_pages(var, np) \
506 1.1.2.2 yamt (var).pv_pa = physical_freestart; \
507 1.1.2.2 yamt physical_freestart += ((np) * PAGE_SIZE); \
508 1.1.2.2 yamt if (physical_freestart > (physical_freeend - L1_TABLE_SIZE)) \
509 1.1.2.2 yamt panic("initarm: out of memory"); \
510 1.1.2.2 yamt free_pages -= (np); \
511 1.1.2.2 yamt (var).pv_va = KERN_PHYSTOV((var).pv_pa); \
512 1.1.2.2 yamt memset((char *)(var).pv_va, 0, ((np) * PAGE_SIZE));
513 1.1.2.2 yamt
514 1.1.2.2 yamt pt_index = 0;
515 1.1.2.2 yamt kernel_l1pt.pv_pa = 0;
516 1.1.2.2 yamt kernel_l1pt.pv_va = 0;
517 1.1.2.2 yamt for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
518 1.1.2.2 yamt /* Are we 16KB aligned for an L1 ? */
519 1.1.2.2 yamt if ((physical_freestart & (L1_TABLE_SIZE - 1)) == 0 &&
520 1.1.2.2 yamt kernel_l1pt.pv_pa == 0) {
521 1.1.2.2 yamt valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
522 1.1.2.2 yamt } else {
523 1.1.2.2 yamt valloc_pages(kernel_pt_table[pt_index],
524 1.1.2.2 yamt L2_TABLE_SIZE / PAGE_SIZE);
525 1.1.2.2 yamt ++pt_index;
526 1.1.2.2 yamt }
527 1.1.2.2 yamt }
528 1.1.2.2 yamt
529 1.1.2.2 yamt /* This should never be able to happen but better confirm that. */
530 1.1.2.2 yamt if (!kernel_l1pt.pv_pa ||
531 1.1.2.2 yamt (kernel_l1pt.pv_pa & (L1_TABLE_SIZE - 1)) != 0)
532 1.1.2.2 yamt panic("initarm: Failed to align the kernel page directory");
533 1.1.2.2 yamt
534 1.1.2.2 yamt /*
535 1.1.2.2 yamt * Allocate a page for the system page mapped to V0x00000000
536 1.1.2.2 yamt * This page will just contain the system vectors and can be
537 1.1.2.2 yamt * shared by all processes.
538 1.1.2.2 yamt */
539 1.1.2.2 yamt valloc_pages(systempage, 1);
540 1.1.2.2 yamt systempage.pv_va = 0x00000000;
541 1.1.2.2 yamt
542 1.1.2.2 yamt /* Allocate stacks for all modes */
543 1.1.2.2 yamt valloc_pages(irqstack, IRQ_STACK_SIZE);
544 1.1.2.2 yamt valloc_pages(abtstack, ABT_STACK_SIZE);
545 1.1.2.2 yamt valloc_pages(undstack, UND_STACK_SIZE);
546 1.1.2.2 yamt valloc_pages(kernelstack, UPAGES);
547 1.1.2.2 yamt
548 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
549 1.1.2.2 yamt printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
550 1.1.2.2 yamt irqstack.pv_va);
551 1.1.2.2 yamt printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
552 1.1.2.2 yamt abtstack.pv_va);
553 1.1.2.2 yamt printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
554 1.1.2.2 yamt undstack.pv_va);
555 1.1.2.2 yamt printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
556 1.1.2.2 yamt kernelstack.pv_va);
557 1.1.2.2 yamt #endif
558 1.1.2.2 yamt
559 1.1.2.2 yamt /* Allocate the message buffer. */
560 1.1.2.2 yamt {
561 1.1.2.2 yamt pv_addr_t msgbuf;
562 1.1.2.2 yamt
563 1.1.2.2 yamt valloc_pages(msgbuf, round_page(MSGBUFSIZE) / PAGE_SIZE);
564 1.1.2.2 yamt msgbufphys = msgbuf.pv_pa;
565 1.1.2.2 yamt }
566 1.1.2.2 yamt
567 1.1.2.2 yamt /*
568 1.1.2.2 yamt * Ok we have allocated physical pages for the primary kernel
569 1.1.2.2 yamt * page tables
570 1.1.2.2 yamt */
571 1.1.2.2 yamt
572 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
573 1.1.2.2 yamt printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
574 1.1.2.2 yamt #endif
575 1.1.2.2 yamt
576 1.1.2.2 yamt /*
577 1.1.2.2 yamt * Now we start construction of the L1 page table
578 1.1.2.2 yamt * We start by mapping the L2 page tables into the L1.
579 1.1.2.2 yamt * This means that we can replace L1 mappings later on if necessary
580 1.1.2.2 yamt */
581 1.1.2.2 yamt l1pagetable = kernel_l1pt.pv_va;
582 1.1.2.2 yamt
583 1.1.2.2 yamt /* Map the L2 pages tables in the L1 page table */
584 1.1.2.2 yamt pmap_link_l2pt(l1pagetable, 0x00000000,
585 1.1.2.2 yamt &kernel_pt_table[KERNEL_PT_SYS]);
586 1.1.2.2 yamt for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
587 1.1.2.2 yamt pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
588 1.1.2.2 yamt &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
589 1.1.2.2 yamt for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
590 1.1.2.2 yamt pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
591 1.1.2.2 yamt &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
592 1.1.2.2 yamt
593 1.1.2.2 yamt /* update the top of the kernel VM */
594 1.1.2.2 yamt pmap_curmaxkvaddr =
595 1.1.2.2 yamt KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
596 1.1.2.2 yamt
597 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
598 1.1.2.2 yamt printf("Mapping kernel\n");
599 1.1.2.2 yamt #endif
600 1.1.2.2 yamt
601 1.1.2.2 yamt /* Now we fill in the L2 pagetable for the kernel static code/data */
602 1.1.2.2 yamt {
603 1.1.2.2 yamt extern char etext[], _end[];
604 1.1.2.2 yamt size_t textsize = (uintptr_t)etext - KERNEL_TEXT_BASE;
605 1.1.2.2 yamt size_t totalsize = (uintptr_t)_end - KERNEL_TEXT_BASE;
606 1.1.2.2 yamt u_int logical;
607 1.1.2.2 yamt
608 1.1.2.2 yamt textsize = (textsize + PGOFSET) & ~PGOFSET;
609 1.1.2.2 yamt totalsize = (totalsize + PGOFSET) & ~PGOFSET;
610 1.1.2.2 yamt
611 1.1.2.2 yamt logical = 0x00000000; /* offset of kernel in RAM */
612 1.1.2.2 yamt
613 1.1.2.2 yamt logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
614 1.1.2.2 yamt physical_start + logical, textsize,
615 1.1.2.2 yamt VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
616 1.1.2.2 yamt logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
617 1.1.2.2 yamt physical_start + logical, totalsize - textsize,
618 1.1.2.2 yamt VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
619 1.1.2.2 yamt }
620 1.1.2.2 yamt
621 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
622 1.1.2.2 yamt printf("Constructing L2 page tables\n");
623 1.1.2.2 yamt #endif
624 1.1.2.2 yamt
625 1.1.2.2 yamt /* Map the stack pages */
626 1.1.2.2 yamt pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
627 1.1.2.2 yamt IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
628 1.1.2.2 yamt pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
629 1.1.2.2 yamt ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
630 1.1.2.2 yamt pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
631 1.1.2.2 yamt UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
632 1.1.2.2 yamt pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
633 1.1.2.2 yamt UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
634 1.1.2.2 yamt
635 1.1.2.2 yamt pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
636 1.1.2.2 yamt L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
637 1.1.2.2 yamt
638 1.1.2.2 yamt for (loop = 0; loop < NUM_KERNEL_PTS; ++loop)
639 1.1.2.2 yamt pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
640 1.1.2.2 yamt kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
641 1.1.2.2 yamt VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
642 1.1.2.2 yamt
643 1.1.2.2 yamt /* Map the vector page. */
644 1.1.2.2 yamt pmap_map_entry(l1pagetable, ARM_VECTORS_LOW, systempage.pv_pa,
645 1.1.2.2 yamt VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
646 1.1.2.2 yamt
647 1.1.2.2 yamt /*
648 1.1.2.2 yamt * Map integrated peripherals at same address in first level page
649 1.1.2.2 yamt * table so that we can continue to use console.
650 1.1.2.2 yamt */
651 1.1.2.2 yamt pmap_devmap_bootstrap(l1pagetable, marvell_devmap);
652 1.1.2.2 yamt
653 1.1.2.2 yamt /*
654 1.1.2.2 yamt * Now we have the real page tables in place so we can switch to them.
655 1.1.2.2 yamt * Once this is done we will be running with the REAL kernel page
656 1.1.2.2 yamt * tables.
657 1.1.2.2 yamt */
658 1.1.2.2 yamt
659 1.1.2.2 yamt /* Switch tables */
660 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
661 1.1.2.2 yamt printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
662 1.1.2.2 yamt #endif
663 1.1.2.2 yamt
664 1.1.2.2 yamt cpu_setttb(kernel_l1pt.pv_pa);
665 1.1.2.2 yamt cpu_tlb_flushID();
666 1.1.2.2 yamt cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
667 1.1.2.2 yamt
668 1.1.2.2 yamt /*
669 1.1.2.2 yamt * Moved from cpu_startup() as data_abort_handler() references
670 1.1.2.2 yamt * this during uvm init.
671 1.1.2.2 yamt */
672 1.1.2.2 yamt uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
673 1.1.2.2 yamt
674 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
675 1.1.2.2 yamt printf("bootstrap done.\n");
676 1.1.2.2 yamt #endif
677 1.1.2.2 yamt
678 1.1.2.2 yamt arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
679 1.1.2.2 yamt
680 1.1.2.2 yamt /*
681 1.1.2.2 yamt * Pages were allocated during the secondary bootstrap for the
682 1.1.2.2 yamt * stacks for different CPU modes.
683 1.1.2.2 yamt * We must now set the r13 registers in the different CPU modes to
684 1.1.2.2 yamt * point to these stacks.
685 1.1.2.2 yamt * Since the ARM stacks use STMFD etc. we must set r13 to the top end
686 1.1.2.2 yamt * of the stack memory.
687 1.1.2.2 yamt */
688 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
689 1.1.2.2 yamt printf("init subsystems: stacks ");
690 1.1.2.2 yamt #endif
691 1.1.2.2 yamt
692 1.1.2.2 yamt set_stackptr(PSR_IRQ32_MODE,
693 1.1.2.2 yamt irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
694 1.1.2.2 yamt set_stackptr(PSR_ABT32_MODE,
695 1.1.2.2 yamt abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
696 1.1.2.2 yamt set_stackptr(PSR_UND32_MODE,
697 1.1.2.2 yamt undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
698 1.1.2.2 yamt
699 1.1.2.2 yamt /*
700 1.1.2.2 yamt * Well we should set a data abort handler.
701 1.1.2.2 yamt * Once things get going this will change as we will need a proper
702 1.1.2.2 yamt * handler.
703 1.1.2.2 yamt * Until then we will use a handler that just panics but tells us
704 1.1.2.2 yamt * why.
705 1.1.2.2 yamt * Initialisation of the vectors will just panic on a data abort.
706 1.1.2.2 yamt * This just fills in a slightly better one.
707 1.1.2.2 yamt */
708 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
709 1.1.2.2 yamt printf("vectors ");
710 1.1.2.2 yamt #endif
711 1.1.2.2 yamt data_abort_handler_address = (u_int)data_abort_handler;
712 1.1.2.2 yamt prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
713 1.1.2.2 yamt undefined_handler_address = (u_int)undefinedinstruction_bounce;
714 1.1.2.2 yamt
715 1.1.2.2 yamt /* Initialise the undefined instruction handlers */
716 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
717 1.1.2.2 yamt printf("undefined ");
718 1.1.2.2 yamt #endif
719 1.1.2.2 yamt undefined_init();
720 1.1.2.2 yamt
721 1.1.2.2 yamt /* Load memory into UVM. */
722 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
723 1.1.2.2 yamt printf("page ");
724 1.1.2.2 yamt #endif
725 1.1.2.2 yamt uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
726 1.1.2.2 yamt uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
727 1.1.2.2 yamt atop(physical_freestart), atop(physical_freeend),
728 1.1.2.2 yamt VM_FREELIST_DEFAULT);
729 1.1.2.2 yamt
730 1.1.2.2 yamt /* Boot strap pmap telling it where the kernel page table is */
731 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
732 1.1.2.2 yamt printf("pmap ");
733 1.1.2.2 yamt #endif
734 1.1.2.2 yamt pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
735 1.1.2.2 yamt
736 1.1.2.2 yamt #ifdef VERBOSE_INIT_ARM
737 1.1.2.2 yamt printf("done.\n");
738 1.1.2.2 yamt #endif
739 1.1.2.2 yamt
740 1.1.2.2 yamt #ifdef __HAVE_MEMORY_DISK__
741 1.1.2.2 yamt md_root_setconf(memory_disk, sizeof memory_disk);
742 1.1.2.2 yamt #endif
743 1.1.2.2 yamt
744 1.1.2.2 yamt #ifdef BOOTHOWTO
745 1.1.2.2 yamt boothowto |= BOOTHOWTO;
746 1.1.2.2 yamt #endif
747 1.1.2.2 yamt
748 1.1.2.2 yamt #ifdef KGDB
749 1.1.2.2 yamt if (boothowto & RB_KDB) {
750 1.1.2.2 yamt kgdb_debug_init = 1;
751 1.1.2.2 yamt kgdb_connect(1);
752 1.1.2.2 yamt }
753 1.1.2.2 yamt #endif
754 1.1.2.2 yamt
755 1.1.2.2 yamt #if NKSYMS || defined(DDB) || defined(LKM)
756 1.1.2.2 yamt /* Firmware doesn't load symbols. */
757 1.1.2.2 yamt ksyms_init();
758 1.1.2.2 yamt #endif
759 1.1.2.2 yamt
760 1.1.2.2 yamt #ifdef DDB
761 1.1.2.2 yamt db_machine_init();
762 1.1.2.2 yamt if (boothowto & RB_KDB)
763 1.1.2.2 yamt Debugger();
764 1.1.2.2 yamt #endif
765 1.1.2.2 yamt
766 1.1.2.2 yamt /* we've a specific device_register routine */
767 1.1.2.2 yamt evbarm_device_register = marvell_device_register;
768 1.1.2.2 yamt
769 1.1.2.2 yamt /* We return the new stack pointer address */
770 1.1.2.2 yamt return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
771 1.1.2.2 yamt }
772 1.1.2.2 yamt
773 1.1.2.2 yamt void
774 1.1.2.2 yamt consinit(void)
775 1.1.2.2 yamt {
776 1.1.2.2 yamt static int consinit_called = 0;
777 1.1.2.2 yamt
778 1.1.2.2 yamt if (consinit_called != 0)
779 1.1.2.2 yamt return;
780 1.1.2.2 yamt
781 1.1.2.2 yamt consinit_called = 1;
782 1.1.2.2 yamt
783 1.1.2.2 yamt #if NCOM > 0
784 1.1.2.2 yamt {
785 1.1.2.2 yamt extern int mvuart_cnattach(bus_space_tag_t, bus_addr_t, int,
786 1.1.2.2 yamt uint32_t, int);
787 1.1.2.2 yamt
788 1.1.2.2 yamt if (mvuart_cnattach(&mvsoc_bs_tag,
789 1.1.2.2 yamt MARVELL_INTERREGS_VBASE + MVSOC_COM0_BASE,
790 1.1.2.2 yamt comcnspeed, mvTclk, comcnmode))
791 1.1.2.2 yamt panic("can't init serial console");
792 1.1.2.2 yamt }
793 1.1.2.2 yamt #else
794 1.1.2.2 yamt panic("serial console not configured");
795 1.1.2.2 yamt #endif
796 1.1.2.2 yamt }
797 1.1.2.2 yamt
798 1.1.2.2 yamt
799 1.1.2.2 yamt static void
800 1.1.2.2 yamt marvell_device_register(device_t dev, void *aux)
801 1.1.2.2 yamt {
802 1.1.2.2 yamt prop_dictionary_t dict = device_properties(dev);
803 1.1.2.2 yamt
804 1.1.2.2 yamt #if NCOM > 0
805 1.1.2.2 yamt if (device_is_a(dev, "com") &&
806 1.1.2.2 yamt device_is_a(device_parent(dev), "mvsoc"))
807 1.1.2.2 yamt prop_dictionary_set_uint32(dict, "frequency", mvTclk);
808 1.1.2.2 yamt #endif
809 1.1.2.2 yamt if (device_is_a(dev, "gtidmac")) {
810 1.1.2.2 yamt prop_dictionary_set_uint32(dict,
811 1.1.2.2 yamt "dmb_speed", mvTclk * sizeof(uint32_t)); /* XXXXXX */
812 1.1.2.2 yamt prop_dictionary_set_uint32(dict,
813 1.1.2.2 yamt "xore-irq-begin", ORION_IRQ_XOR0);
814 1.1.2.2 yamt }
815 1.1.2.2 yamt #if NGTPCI > 0 && defined(ORION)
816 1.1.2.2 yamt if (device_is_a(dev, "gtpci")) {
817 1.1.2.2 yamt extern struct bus_space
818 1.1.2.2 yamt orion_pci_io_bs_tag, orion_pci_mem_bs_tag;
819 1.1.2.2 yamt extern struct arm32_pci_chipset arm32_gtpci_chipset;
820 1.1.2.2 yamt
821 1.1.2.2 yamt prop_data_t io_bs_tag, mem_bs_tag, pc;
822 1.1.2.2 yamt prop_array_t int2gpp;
823 1.1.2.2 yamt prop_number_t gpp;
824 1.1.2.2 yamt uint64_t start, end;
825 1.1.2.2 yamt int i, j;
826 1.1.2.2 yamt static struct {
827 1.1.2.2 yamt const char *boardtype;
828 1.1.2.2 yamt int pin[PCI_INTERRUPT_PIN_MAX];
829 1.1.2.2 yamt } hints[] = {
830 1.1.2.2 yamt { "kuronas_x4",
831 1.1.2.2 yamt { 11, PCI_INTERRUPT_PIN_NONE } },
832 1.1.2.2 yamt
833 1.1.2.2 yamt { NULL,
834 1.1.2.2 yamt { PCI_INTERRUPT_PIN_NONE } },
835 1.1.2.2 yamt };
836 1.1.2.2 yamt
837 1.1.2.2 yamt arm32_gtpci_chipset.pc_conf_v = device_private(dev);
838 1.1.2.2 yamt arm32_gtpci_chipset.pc_intr_v = device_private(dev);
839 1.1.2.2 yamt
840 1.1.2.2 yamt io_bs_tag = prop_data_create_data_nocopy(
841 1.1.2.2 yamt &orion_pci_io_bs_tag, sizeof(struct bus_space));
842 1.1.2.2 yamt KASSERT(io_bs_tag != NULL);
843 1.1.2.2 yamt prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
844 1.1.2.2 yamt prop_object_release(io_bs_tag);
845 1.1.2.2 yamt mem_bs_tag = prop_data_create_data_nocopy(
846 1.1.2.2 yamt &orion_pci_mem_bs_tag, sizeof(struct bus_space));
847 1.1.2.2 yamt KASSERT(mem_bs_tag != NULL);
848 1.1.2.2 yamt prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
849 1.1.2.2 yamt prop_object_release(mem_bs_tag);
850 1.1.2.2 yamt
851 1.1.2.2 yamt pc = prop_data_create_data_nocopy(&arm32_gtpci_chipset,
852 1.1.2.2 yamt sizeof(struct arm32_pci_chipset));
853 1.1.2.2 yamt KASSERT(pc != NULL);
854 1.1.2.2 yamt prop_dictionary_set(dict, "pci-chipset", pc);
855 1.1.2.2 yamt prop_object_release(pc);
856 1.1.2.2 yamt
857 1.1.2.2 yamt marvell_startend_by_tag(ORION_TAG_PCI_IO, &start, &end);
858 1.1.2.2 yamt prop_dictionary_set_uint64(dict, "iostart", start);
859 1.1.2.2 yamt prop_dictionary_set_uint64(dict, "ioend", end);
860 1.1.2.2 yamt marvell_startend_by_tag(ORION_TAG_PCI_MEM, &start, &end);
861 1.1.2.2 yamt prop_dictionary_set_uint64(dict, "memstart", start);
862 1.1.2.2 yamt prop_dictionary_set_uint64(dict, "memend", end);
863 1.1.2.2 yamt prop_dictionary_set_uint32(dict,
864 1.1.2.2 yamt "cache-line-size", arm_dcache_align);
865 1.1.2.2 yamt
866 1.1.2.2 yamt /* Setup the hint for interrupt-pin. */
867 1.1.2.2 yamt #define BDSTR(s) _BDSTR(s)
868 1.1.2.2 yamt #define _BDSTR(s) #s
869 1.1.2.2 yamt #define THIS_BOARD(str) (strcmp(str, BDSTR(EVBARM_BOARDTYPE)) == 0)
870 1.1.2.2 yamt for (i = 0; hints[i].boardtype != NULL; i++)
871 1.1.2.2 yamt if (THIS_BOARD(hints[i].boardtype))
872 1.1.2.2 yamt break;
873 1.1.2.2 yamt if (hints[i].boardtype == NULL)
874 1.1.2.2 yamt return;
875 1.1.2.2 yamt
876 1.1.2.2 yamt int2gpp =
877 1.1.2.2 yamt prop_array_create_with_capacity(PCI_INTERRUPT_PIN_MAX + 1);
878 1.1.2.2 yamt
879 1.1.2.2 yamt /* first set dummy */
880 1.1.2.2 yamt gpp = prop_number_create_integer(0);
881 1.1.2.2 yamt prop_array_add(int2gpp, gpp);
882 1.1.2.2 yamt prop_object_release(gpp);
883 1.1.2.2 yamt
884 1.1.2.2 yamt for (j = 0; hints[i].pin[j] != PCI_INTERRUPT_PIN_NONE; j++) {
885 1.1.2.2 yamt gpp = prop_number_create_integer(hints[i].pin[j]);
886 1.1.2.2 yamt prop_array_add(int2gpp, gpp);
887 1.1.2.2 yamt prop_object_release(gpp);
888 1.1.2.2 yamt }
889 1.1.2.2 yamt prop_dictionary_set(dict, "int2gpp", int2gpp);
890 1.1.2.2 yamt }
891 1.1.2.2 yamt #endif /* NGTPCI > 0 && defined(ORION) */
892 1.1.2.2 yamt #if NMVPEX > 0
893 1.1.2.2 yamt if (device_is_a(dev, "mvpex")) {
894 1.1.2.2 yamt #ifdef ORION
895 1.1.2.2 yamt extern struct bus_space
896 1.1.2.2 yamt orion_pex0_io_bs_tag, orion_pex0_mem_bs_tag,
897 1.1.2.2 yamt orion_pex1_io_bs_tag, orion_pex1_mem_bs_tag;
898 1.1.2.2 yamt #endif
899 1.1.2.2 yamt #ifdef KIRKWOOD
900 1.1.2.2 yamt extern struct bus_space
901 1.1.2.2 yamt kirkwood_pex_io_bs_tag, kirkwood_pex_mem_bs_tag;
902 1.1.2.2 yamt #endif
903 1.1.2.2 yamt extern struct arm32_pci_chipset
904 1.1.2.2 yamt arm32_mvpex0_chipset, arm32_mvpex1_chipset;
905 1.1.2.2 yamt
906 1.1.2.2 yamt struct marvell_attach_args *mva = aux;
907 1.1.2.2 yamt struct bus_space *mvpex_io_bs_tag, *mvpex_mem_bs_tag;
908 1.1.2.2 yamt struct arm32_pci_chipset *arm32_mvpex_chipset;
909 1.1.2.2 yamt prop_data_t io_bs_tag, mem_bs_tag, pc;
910 1.1.2.2 yamt uint64_t start, end;
911 1.1.2.2 yamt int iotag, memtag;
912 1.1.2.2 yamt
913 1.1.2.2 yamt switch (mvsoc_model()) {
914 1.1.2.2 yamt #ifdef ORION
915 1.1.2.2 yamt case MARVELL_ORION_1_88F5180N:
916 1.1.2.2 yamt case MARVELL_ORION_1_88F5181:
917 1.1.2.2 yamt case MARVELL_ORION_1_88F5182:
918 1.1.2.2 yamt case MARVELL_ORION_1_88W8660:
919 1.1.2.2 yamt case MARVELL_ORION_2_88F5281:
920 1.1.2.2 yamt if (mva->mva_offset == MVSOC_PEX_BASE) {
921 1.1.2.2 yamt mvpex_io_bs_tag = &orion_pex0_io_bs_tag;
922 1.1.2.2 yamt mvpex_mem_bs_tag = &orion_pex0_mem_bs_tag;
923 1.1.2.2 yamt arm32_mvpex_chipset = &arm32_mvpex0_chipset;
924 1.1.2.2 yamt iotag = ORION_TAG_PEX0_IO;
925 1.1.2.2 yamt memtag = ORION_TAG_PEX0_MEM;
926 1.1.2.2 yamt } else {
927 1.1.2.2 yamt mvpex_io_bs_tag = &orion_pex1_io_bs_tag;
928 1.1.2.2 yamt mvpex_mem_bs_tag = &orion_pex1_mem_bs_tag;
929 1.1.2.2 yamt arm32_mvpex_chipset = &arm32_mvpex1_chipset;
930 1.1.2.2 yamt iotag = ORION_TAG_PEX1_IO;
931 1.1.2.2 yamt memtag = ORION_TAG_PEX1_MEM;
932 1.1.2.2 yamt }
933 1.1.2.2 yamt break;
934 1.1.2.2 yamt #endif
935 1.1.2.2 yamt
936 1.1.2.2 yamt #ifdef KIRKWOOD
937 1.1.2.2 yamt case MARVELL_KIRKWOOD_88F6180:
938 1.1.2.2 yamt case MARVELL_KIRKWOOD_88F6192:
939 1.1.2.2 yamt case MARVELL_KIRKWOOD_88F6281:
940 1.1.2.2 yamt mvpex_io_bs_tag = &kirkwood_pex_io_bs_tag;
941 1.1.2.2 yamt mvpex_mem_bs_tag = &kirkwood_pex_mem_bs_tag;
942 1.1.2.2 yamt arm32_mvpex_chipset = &arm32_mvpex0_chipset;
943 1.1.2.2 yamt iotag = KIRKWOOD_TAG_PEX_IO;
944 1.1.2.2 yamt memtag = KIRKWOOD_TAG_PEX_MEM;
945 1.1.2.2 yamt break;
946 1.1.2.2 yamt #endif
947 1.1.2.2 yamt
948 1.1.2.2 yamt default:
949 1.1.2.2 yamt return;
950 1.1.2.2 yamt }
951 1.1.2.2 yamt
952 1.1.2.2 yamt arm32_mvpex_chipset->pc_conf_v = device_private(dev);
953 1.1.2.2 yamt arm32_mvpex_chipset->pc_intr_v = device_private(dev);
954 1.1.2.2 yamt
955 1.1.2.2 yamt io_bs_tag = prop_data_create_data_nocopy(
956 1.1.2.2 yamt mvpex_io_bs_tag, sizeof(struct bus_space));
957 1.1.2.2 yamt KASSERT(io_bs_tag != NULL);
958 1.1.2.2 yamt prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
959 1.1.2.2 yamt prop_object_release(io_bs_tag);
960 1.1.2.2 yamt mem_bs_tag = prop_data_create_data_nocopy(
961 1.1.2.2 yamt mvpex_mem_bs_tag, sizeof(struct bus_space));
962 1.1.2.2 yamt KASSERT(mem_bs_tag != NULL);
963 1.1.2.2 yamt prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
964 1.1.2.2 yamt prop_object_release(mem_bs_tag);
965 1.1.2.2 yamt
966 1.1.2.2 yamt pc = prop_data_create_data_nocopy(arm32_mvpex_chipset,
967 1.1.2.2 yamt sizeof(struct arm32_pci_chipset));
968 1.1.2.2 yamt KASSERT(pc != NULL);
969 1.1.2.2 yamt prop_dictionary_set(dict, "pci-chipset", pc);
970 1.1.2.2 yamt prop_object_release(pc);
971 1.1.2.2 yamt
972 1.1.2.2 yamt marvell_startend_by_tag(iotag, &start, &end);
973 1.1.2.2 yamt prop_dictionary_set_uint64(dict, "iostart", start);
974 1.1.2.2 yamt prop_dictionary_set_uint64(dict, "ioend", end);
975 1.1.2.2 yamt marvell_startend_by_tag(memtag, &start, &end);
976 1.1.2.2 yamt prop_dictionary_set_uint64(dict, "memstart", start);
977 1.1.2.2 yamt prop_dictionary_set_uint64(dict, "memend", end);
978 1.1.2.2 yamt prop_dictionary_set_uint32(dict,
979 1.1.2.2 yamt "cache-line-size", arm_dcache_align);
980 1.1.2.2 yamt }
981 1.1.2.2 yamt #endif
982 1.1.2.2 yamt }
983 1.1.2.2 yamt
984 1.1.2.2 yamt #if NGTPCI > 0 || NMVPEX > 0
985 1.1.2.2 yamt static void
986 1.1.2.2 yamt marvell_startend_by_tag(int tag, uint64_t *start, uint64_t *end)
987 1.1.2.2 yamt {
988 1.1.2.2 yamt uint32_t base, size;
989 1.1.2.2 yamt int win;
990 1.1.2.2 yamt
991 1.1.2.2 yamt win = mvsoc_target(tag, NULL, NULL, &base, &size);
992 1.1.2.2 yamt if (size != 0) {
993 1.1.2.2 yamt if (win < nremap)
994 1.1.2.2 yamt *start = read_mlmbreg(MVSOC_MLMB_WRLR(win)) |
995 1.1.2.2 yamt ((read_mlmbreg(MVSOC_MLMB_WRHR(win)) << 16) << 16);
996 1.1.2.2 yamt else
997 1.1.2.2 yamt *start = base;
998 1.1.2.2 yamt *end = *start + size - 1;
999 1.1.2.2 yamt }
1000 1.1.2.2 yamt }
1001 1.1.2.2 yamt #endif
1002