marvell_machdep.c revision 1.21 1 1.21 matt /* $NetBSD: marvell_machdep.c,v 1.21 2012/12/12 00:03:11 matt Exp $ */
2 1.1 kiyohara /*
3 1.1 kiyohara * Copyright (c) 2007, 2008, 2010 KIYOHARA Takashi
4 1.1 kiyohara * All rights reserved.
5 1.1 kiyohara *
6 1.1 kiyohara * Redistribution and use in source and binary forms, with or without
7 1.1 kiyohara * modification, are permitted provided that the following conditions
8 1.1 kiyohara * are met:
9 1.1 kiyohara * 1. Redistributions of source code must retain the above copyright
10 1.1 kiyohara * notice, this list of conditions and the following disclaimer.
11 1.1 kiyohara * 2. Redistributions in binary form must reproduce the above copyright
12 1.1 kiyohara * notice, this list of conditions and the following disclaimer in the
13 1.1 kiyohara * documentation and/or other materials provided with the distribution.
14 1.1 kiyohara *
15 1.1 kiyohara * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
16 1.1 kiyohara * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
17 1.1 kiyohara * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
18 1.1 kiyohara * DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
19 1.1 kiyohara * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
20 1.1 kiyohara * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
21 1.1 kiyohara * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 1.1 kiyohara * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
23 1.1 kiyohara * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
24 1.1 kiyohara * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
25 1.1 kiyohara * POSSIBILITY OF SUCH DAMAGE.
26 1.1 kiyohara */
27 1.1 kiyohara #include <sys/cdefs.h>
28 1.21 matt __KERNEL_RCSID(0, "$NetBSD: marvell_machdep.c,v 1.21 2012/12/12 00:03:11 matt Exp $");
29 1.1 kiyohara
30 1.1 kiyohara #include "opt_evbarm_boardtype.h"
31 1.1 kiyohara #include "opt_ddb.h"
32 1.1 kiyohara #include "opt_pci.h"
33 1.1 kiyohara #include "opt_mvsoc.h"
34 1.1 kiyohara #include "com.h"
35 1.1 kiyohara #include "gtpci.h"
36 1.1 kiyohara #include "mvpex.h"
37 1.1 kiyohara
38 1.1 kiyohara #include <sys/param.h>
39 1.1 kiyohara #include <sys/kernel.h>
40 1.1 kiyohara #include <sys/reboot.h>
41 1.1 kiyohara #include <sys/systm.h>
42 1.1 kiyohara #include <sys/termios.h>
43 1.1 kiyohara
44 1.1 kiyohara #include <prop/proplib.h>
45 1.1 kiyohara
46 1.1 kiyohara #include <dev/cons.h>
47 1.1 kiyohara #include <dev/md.h>
48 1.1 kiyohara
49 1.1 kiyohara #include <dev/marvell/marvellreg.h>
50 1.1 kiyohara #include <dev/marvell/marvellvar.h>
51 1.1 kiyohara #include <dev/pci/pcireg.h>
52 1.1 kiyohara #include <dev/pci/pcivar.h>
53 1.1 kiyohara
54 1.1 kiyohara #include <machine/autoconf.h>
55 1.1 kiyohara #include <machine/bootconfig.h>
56 1.1 kiyohara #include <machine/pci_machdep.h>
57 1.1 kiyohara
58 1.1 kiyohara #include <uvm/uvm_extern.h>
59 1.1 kiyohara
60 1.1 kiyohara #include <arm/db_machdep.h>
61 1.1 kiyohara #include <arm/undefined.h>
62 1.1 kiyohara #include <arm/arm32/machdep.h>
63 1.1 kiyohara
64 1.1 kiyohara #include <arm/marvell/mvsocreg.h>
65 1.1 kiyohara #include <arm/marvell/mvsocvar.h>
66 1.1 kiyohara #include <arm/marvell/orionreg.h>
67 1.1 kiyohara #include <arm/marvell/kirkwoodreg.h>
68 1.1 kiyohara #include <arm/marvell/mvsocgppvar.h>
69 1.1 kiyohara
70 1.1 kiyohara #include <evbarm/marvell/marvellreg.h>
71 1.1 kiyohara #include <evbarm/marvell/marvellvar.h>
72 1.1 kiyohara
73 1.1 kiyohara #include <ddb/db_extern.h>
74 1.1 kiyohara #include <ddb/db_sym.h>
75 1.1 kiyohara
76 1.1 kiyohara #include "ksyms.h"
77 1.1 kiyohara
78 1.1 kiyohara
79 1.1 kiyohara /* Kernel text starts 2MB in from the bottom of the kernel address space. */
80 1.1 kiyohara #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00000000)
81 1.16 kiyohara #define KERNEL_VM_BASE (KERNEL_BASE + 0x02000000)
82 1.1 kiyohara
83 1.1 kiyohara /*
84 1.18 matt * The range 0xc2000000 - 0xdfffffff is available for kernel VM space
85 1.16 kiyohara * Core-logic registers and I/O mappings occupy 0xfe000000 - 0xffffffff
86 1.1 kiyohara */
87 1.18 matt #define KERNEL_VM_SIZE 0x1e000000
88 1.1 kiyohara
89 1.1 kiyohara BootConfig bootconfig; /* Boot config storage */
90 1.4 jakllsch static char bootargs[MAX_BOOT_STRING];
91 1.1 kiyohara char *boot_args = NULL;
92 1.1 kiyohara
93 1.17 matt extern int KERNEL_BASE_phys[];
94 1.1 kiyohara extern char _end[];
95 1.1 kiyohara
96 1.1 kiyohara /*
97 1.1 kiyohara * Macros to translate between physical and virtual for a subset of the
98 1.1 kiyohara * kernel address space. *Not* for general use.
99 1.1 kiyohara */
100 1.1 kiyohara #define KERNEL_BASE_PHYS physical_start
101 1.1 kiyohara #define KERN_VTOPHYS(va) \
102 1.1 kiyohara ((paddr_t)((vaddr_t)va - KERNEL_BASE + KERNEL_BASE_PHYS))
103 1.1 kiyohara #define KERN_PHYSTOV(pa) \
104 1.1 kiyohara ((vaddr_t)((paddr_t)pa - KERNEL_BASE_PHYS + KERNEL_BASE))
105 1.1 kiyohara
106 1.1 kiyohara
107 1.1 kiyohara #include "com.h"
108 1.1 kiyohara #if NCOM > 0
109 1.1 kiyohara #include <dev/ic/comreg.h>
110 1.1 kiyohara #include <dev/ic/comvar.h>
111 1.1 kiyohara #endif
112 1.1 kiyohara
113 1.1 kiyohara #ifndef CONSPEED
114 1.1 kiyohara #define CONSPEED B115200 /* It's a setting of the default of u-boot */
115 1.1 kiyohara #endif
116 1.1 kiyohara #ifndef CONMODE
117 1.1 kiyohara #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
118 1.1 kiyohara
119 1.1 kiyohara int comcnspeed = CONSPEED;
120 1.1 kiyohara int comcnmode = CONMODE;
121 1.1 kiyohara #endif
122 1.1 kiyohara
123 1.1 kiyohara #include "opt_kgdb.h"
124 1.1 kiyohara #ifdef KGDB
125 1.1 kiyohara #include <sys/kgdb.h>
126 1.1 kiyohara #endif
127 1.1 kiyohara
128 1.1 kiyohara static void marvell_device_register(device_t, void *);
129 1.1 kiyohara #if NGTPCI > 0 || NMVPEX > 0
130 1.1 kiyohara static void marvell_startend_by_tag(int, uint64_t *, uint64_t *);
131 1.1 kiyohara #endif
132 1.1 kiyohara
133 1.3 jakllsch static void
134 1.3 jakllsch marvell_system_reset(void)
135 1.3 jakllsch {
136 1.3 jakllsch /* unmask soft reset */
137 1.3 jakllsch write_mlmbreg(MVSOC_MLMB_RSTOUTNMASKR,
138 1.3 jakllsch MVSOC_MLMB_RSTOUTNMASKR_SOFTRSTOUTEN);
139 1.3 jakllsch /* assert soft reset */
140 1.3 jakllsch write_mlmbreg(MVSOC_MLMB_SSRR, MVSOC_MLMB_SSRR_SYSTEMSOFTRST);
141 1.3 jakllsch /* if we're still running, jump to the reset address */
142 1.17 matt cpu_reset_address = 0;
143 1.17 matt cpu_reset_address_paddr = 0xffff0000;
144 1.3 jakllsch cpu_reset();
145 1.3 jakllsch /*NOTREACHED*/
146 1.3 jakllsch }
147 1.1 kiyohara
148 1.1 kiyohara static inline
149 1.1 kiyohara pd_entry_t *
150 1.1 kiyohara read_ttb(void)
151 1.1 kiyohara {
152 1.1 kiyohara long ttb;
153 1.1 kiyohara
154 1.1 kiyohara __asm volatile("mrc p15, 0, %0, c2, c0, 0" : "=r" (ttb));
155 1.1 kiyohara
156 1.1 kiyohara return (pd_entry_t *)(ttb & ~((1<<14)-1));
157 1.1 kiyohara }
158 1.1 kiyohara
159 1.1 kiyohara /*
160 1.1 kiyohara * Static device mappings. These peripheral registers are mapped at
161 1.1 kiyohara * fixed virtual addresses very early in initarm() so that we can use
162 1.1 kiyohara * them while booting the kernel, and stay at the same address
163 1.1 kiyohara * throughout whole kernel's life time.
164 1.1 kiyohara *
165 1.1 kiyohara * We use this table twice; once with bootstrap page table, and once
166 1.1 kiyohara * with kernel's page table which we build up in initarm().
167 1.1 kiyohara *
168 1.1 kiyohara * Since we map these registers into the bootstrap page table using
169 1.1 kiyohara * pmap_devmap_bootstrap() which calls pmap_map_chunk(), we map
170 1.1 kiyohara * registers segment-aligned and segment-rounded in order to avoid
171 1.1 kiyohara * using the 2nd page tables.
172 1.1 kiyohara */
173 1.1 kiyohara #define _A(a) ((a) & ~L1_S_OFFSET)
174 1.1 kiyohara #define _S(s) (((s) + L1_S_SIZE - 1) & ~(L1_S_SIZE-1))
175 1.1 kiyohara
176 1.1 kiyohara static const struct pmap_devmap marvell_devmap[] = {
177 1.1 kiyohara {
178 1.1 kiyohara MARVELL_INTERREGS_VBASE,
179 1.1 kiyohara _A(MARVELL_INTERREGS_PBASE),
180 1.1 kiyohara _S(MARVELL_INTERREGS_SIZE),
181 1.1 kiyohara VM_PROT_READ|VM_PROT_WRITE,
182 1.1 kiyohara PTE_NOCACHE,
183 1.1 kiyohara },
184 1.1 kiyohara
185 1.1 kiyohara { 0, 0, 0, 0, 0 }
186 1.1 kiyohara };
187 1.1 kiyohara
188 1.1 kiyohara #undef _A
189 1.1 kiyohara #undef _S
190 1.1 kiyohara
191 1.4 jakllsch extern uint32_t *u_boot_args[];
192 1.1 kiyohara
193 1.1 kiyohara /*
194 1.1 kiyohara * u_int initarm(...)
195 1.1 kiyohara *
196 1.1 kiyohara * Initial entry point on startup. This gets called before main() is
197 1.1 kiyohara * entered.
198 1.1 kiyohara * It should be responsible for setting up everything that must be
199 1.1 kiyohara * in place when main is called.
200 1.1 kiyohara * This includes
201 1.1 kiyohara * Taking a copy of the boot configuration structure.
202 1.1 kiyohara * Initialising the physical console so characters can be printed.
203 1.1 kiyohara * Setting up page tables for the kernel
204 1.1 kiyohara * Relocating the kernel to the bottom of physical memory
205 1.1 kiyohara */
206 1.1 kiyohara u_int
207 1.1 kiyohara initarm(void *arg)
208 1.1 kiyohara {
209 1.1 kiyohara uint32_t target, attr, base, size;
210 1.17 matt int cs, memtag = 0, iotag = 0, window;
211 1.1 kiyohara
212 1.17 matt /* Use the mapped reset routine! */
213 1.17 matt cpu_reset_address = marvell_system_reset;
214 1.15 matt
215 1.14 matt mvsoc_bootstrap(MARVELL_INTERREGS_VBASE);
216 1.14 matt
217 1.1 kiyohara /* map some peripheral registers */
218 1.1 kiyohara pmap_devmap_bootstrap((vaddr_t)read_ttb(), marvell_devmap);
219 1.1 kiyohara
220 1.1 kiyohara /* Get ready for splfoo() */
221 1.1 kiyohara switch (mvsoc_model()) {
222 1.1 kiyohara #ifdef ORION
223 1.1 kiyohara case MARVELL_ORION_1_88F1181:
224 1.1 kiyohara case MARVELL_ORION_1_88F5082:
225 1.1 kiyohara case MARVELL_ORION_1_88F5180N:
226 1.1 kiyohara case MARVELL_ORION_1_88F5181:
227 1.1 kiyohara case MARVELL_ORION_1_88F5182:
228 1.1 kiyohara case MARVELL_ORION_1_88F6082:
229 1.1 kiyohara case MARVELL_ORION_1_88F6183:
230 1.1 kiyohara case MARVELL_ORION_1_88W8660:
231 1.1 kiyohara case MARVELL_ORION_2_88F1281:
232 1.1 kiyohara case MARVELL_ORION_2_88F5281:
233 1.1 kiyohara orion_intr_bootstrap();
234 1.1 kiyohara
235 1.1 kiyohara memtag = ORION_TAG_PEX0_MEM;
236 1.1 kiyohara iotag = ORION_TAG_PEX0_IO;
237 1.1 kiyohara nwindow = ORION_MLMB_NWINDOW;
238 1.1 kiyohara nremap = ORION_MLMB_NREMAP;
239 1.1 kiyohara
240 1.1 kiyohara orion_getclks(MARVELL_INTERREGS_VBASE);
241 1.1 kiyohara break;
242 1.1 kiyohara #endif /* ORION */
243 1.1 kiyohara
244 1.1 kiyohara #ifdef KIRKWOOD
245 1.1 kiyohara case MARVELL_KIRKWOOD_88F6180:
246 1.1 kiyohara case MARVELL_KIRKWOOD_88F6192:
247 1.1 kiyohara case MARVELL_KIRKWOOD_88F6281:
248 1.9 kiyohara case MARVELL_KIRKWOOD_88F6282:
249 1.1 kiyohara kirkwood_intr_bootstrap();
250 1.1 kiyohara
251 1.1 kiyohara memtag = KIRKWOOD_TAG_PEX_MEM;
252 1.1 kiyohara iotag = KIRKWOOD_TAG_PEX_IO;
253 1.1 kiyohara nwindow = KIRKWOOD_MLMB_NWINDOW;
254 1.1 kiyohara nremap = KIRKWOOD_MLMB_NREMAP;
255 1.1 kiyohara
256 1.1 kiyohara kirkwood_getclks(MARVELL_INTERREGS_VBASE);
257 1.1 kiyohara break;
258 1.1 kiyohara #endif /* KIRKWOOD */
259 1.1 kiyohara
260 1.1 kiyohara #ifdef MV78XX0
261 1.1 kiyohara case MARVELL_MV78XX0_MV78100:
262 1.1 kiyohara case MARVELL_MV78XX0_MV78200:
263 1.1 kiyohara mv78xx0_intr_bootstrap();
264 1.1 kiyohara
265 1.1 kiyohara memtag = MV78XX0_TAG_PEX_MEM;
266 1.1 kiyohara iotag = MV78XX0_TAG_PEX_IO;
267 1.1 kiyohara nwindow = MV78XX0_MLMB_NWINDOW;
268 1.1 kiyohara nremap = MV78XX0_MLMB_NREMAP;
269 1.1 kiyohara
270 1.1 kiyohara mv78xx0_getclks(MARVELL_INTERREGS_VBASE);
271 1.1 kiyohara break;
272 1.1 kiyohara #endif /* MV78XX0 */
273 1.1 kiyohara
274 1.1 kiyohara default:
275 1.1 kiyohara /* We can't output console here yet... */
276 1.1 kiyohara panic("unknown model...\n");
277 1.1 kiyohara
278 1.1 kiyohara /* NOTREACHED */
279 1.1 kiyohara }
280 1.1 kiyohara
281 1.1 kiyohara /* Reset PCI-Express space to window register. */
282 1.1 kiyohara window = mvsoc_target(memtag, &target, &attr, NULL, NULL);
283 1.1 kiyohara write_mlmbreg(MVSOC_MLMB_WCR(window),
284 1.1 kiyohara MVSOC_MLMB_WCR_WINEN |
285 1.1 kiyohara MVSOC_MLMB_WCR_TARGET(target) |
286 1.1 kiyohara MVSOC_MLMB_WCR_ATTR(attr) |
287 1.1 kiyohara MVSOC_MLMB_WCR_SIZE(MARVELL_PEXMEM_SIZE));
288 1.1 kiyohara write_mlmbreg(MVSOC_MLMB_WBR(window),
289 1.1 kiyohara MARVELL_PEXMEM_PBASE & MVSOC_MLMB_WBR_BASE_MASK);
290 1.1 kiyohara #ifdef PCI_NETBSD_CONFIGURE
291 1.1 kiyohara if (window < nremap) {
292 1.1 kiyohara write_mlmbreg(MVSOC_MLMB_WRLR(window),
293 1.1 kiyohara MARVELL_PEXMEM_PBASE & MVSOC_MLMB_WRLR_REMAP_MASK);
294 1.1 kiyohara write_mlmbreg(MVSOC_MLMB_WRHR(window), 0);
295 1.1 kiyohara }
296 1.1 kiyohara #endif
297 1.1 kiyohara window = mvsoc_target(iotag, &target, &attr, NULL, NULL);
298 1.1 kiyohara write_mlmbreg(MVSOC_MLMB_WCR(window),
299 1.1 kiyohara MVSOC_MLMB_WCR_WINEN |
300 1.1 kiyohara MVSOC_MLMB_WCR_TARGET(target) |
301 1.1 kiyohara MVSOC_MLMB_WCR_ATTR(attr) |
302 1.1 kiyohara MVSOC_MLMB_WCR_SIZE(MARVELL_PEXIO_SIZE));
303 1.1 kiyohara write_mlmbreg(MVSOC_MLMB_WBR(window),
304 1.1 kiyohara MARVELL_PEXIO_PBASE & MVSOC_MLMB_WBR_BASE_MASK);
305 1.1 kiyohara #ifdef PCI_NETBSD_CONFIGURE
306 1.1 kiyohara if (window < nremap) {
307 1.1 kiyohara write_mlmbreg(MVSOC_MLMB_WRLR(window),
308 1.1 kiyohara MARVELL_PEXIO_PBASE & MVSOC_MLMB_WRLR_REMAP_MASK);
309 1.1 kiyohara write_mlmbreg(MVSOC_MLMB_WRHR(window), 0);
310 1.1 kiyohara }
311 1.1 kiyohara #endif
312 1.1 kiyohara
313 1.1 kiyohara /*
314 1.1 kiyohara * Heads up ... Setup the CPU / MMU / TLB functions
315 1.1 kiyohara */
316 1.1 kiyohara if (set_cpufuncs())
317 1.1 kiyohara panic("cpu not recognized!");
318 1.1 kiyohara
319 1.1 kiyohara /*
320 1.1 kiyohara * U-Boot doesn't use the virtual memory.
321 1.1 kiyohara *
322 1.1 kiyohara * Physical Address Range Description
323 1.1 kiyohara * ----------------------- ----------------------------------
324 1.1 kiyohara * 0x00000000 - 0x0fffffff SDRAM Bank 0 (max 256MB)
325 1.1 kiyohara * 0x10000000 - 0x1fffffff SDRAM Bank 1 (max 256MB)
326 1.1 kiyohara * 0x20000000 - 0x2fffffff SDRAM Bank 2 (max 256MB)
327 1.1 kiyohara * 0x30000000 - 0x3fffffff SDRAM Bank 3 (max 256MB)
328 1.1 kiyohara * 0xf1000000 - 0xf10fffff SoC Internal Registers
329 1.1 kiyohara */
330 1.1 kiyohara
331 1.1 kiyohara cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
332 1.1 kiyohara
333 1.1 kiyohara consinit();
334 1.1 kiyohara
335 1.1 kiyohara /* Talk to the user */
336 1.8 kiyohara #ifndef EVBARM_BOARDTYPE
337 1.8 kiyohara #define EVBARM_BOARDTYPE Marvell
338 1.8 kiyohara #endif
339 1.1 kiyohara #define BDSTR(s) _BDSTR(s)
340 1.1 kiyohara #define _BDSTR(s) #s
341 1.1 kiyohara printf("\nNetBSD/evbarm (" BDSTR(EVBARM_BOARDTYPE) ") booting ...\n");
342 1.1 kiyohara
343 1.12 kiyohara /* copy command line U-Boot gave us, if args is valid. */
344 1.12 kiyohara if (u_boot_args[3] != 0) /* XXXXX: need more check?? */
345 1.12 kiyohara strncpy(bootargs, (char *)u_boot_args[3], sizeof(bootargs));
346 1.4 jakllsch
347 1.1 kiyohara #ifdef VERBOSE_INIT_ARM
348 1.1 kiyohara printf("initarm: Configuring system ...\n");
349 1.1 kiyohara #endif
350 1.1 kiyohara
351 1.1 kiyohara bootconfig.dramblocks = 0;
352 1.21 matt paddr_t segment_end;
353 1.21 matt segment_end = physmem = 0;
354 1.1 kiyohara for (cs = MARVELL_TAG_SDRAM_CS0; cs <= MARVELL_TAG_SDRAM_CS3; cs++) {
355 1.1 kiyohara mvsoc_target(cs, &target, &attr, &base, &size);
356 1.1 kiyohara if (size == 0)
357 1.1 kiyohara continue;
358 1.1 kiyohara
359 1.1 kiyohara bootconfig.dram[bootconfig.dramblocks].address = base;
360 1.1 kiyohara bootconfig.dram[bootconfig.dramblocks].pages = size / PAGE_SIZE;
361 1.1 kiyohara
362 1.21 matt if (base != segment_end)
363 1.1 kiyohara panic("memory hole not support");
364 1.1 kiyohara
365 1.21 matt segment_end += size;
366 1.1 kiyohara physmem += size / PAGE_SIZE;
367 1.1 kiyohara
368 1.1 kiyohara bootconfig.dramblocks++;
369 1.1 kiyohara }
370 1.1 kiyohara
371 1.21 matt arm32_bootmem_init(0, segment_end, (uintptr_t) KERNEL_BASE_phys);
372 1.19 matt arm32_kernel_vm_init(KERNEL_VM_BASE, ARM_VECTORS_HIGH, 0,
373 1.17 matt marvell_devmap, false);
374 1.1 kiyohara
375 1.1 kiyohara /* we've a specific device_register routine */
376 1.1 kiyohara evbarm_device_register = marvell_device_register;
377 1.1 kiyohara
378 1.20 msaitoh /* parse bootargs from U-Boot */
379 1.20 msaitoh boot_args = bootargs;
380 1.20 msaitoh parse_mi_bootargs(boot_args);
381 1.20 msaitoh
382 1.17 matt return initarm_common(KERNEL_VM_BASE, KERNEL_VM_SIZE, NULL, 0);
383 1.1 kiyohara }
384 1.1 kiyohara
385 1.1 kiyohara void
386 1.1 kiyohara consinit(void)
387 1.1 kiyohara {
388 1.1 kiyohara static int consinit_called = 0;
389 1.1 kiyohara
390 1.1 kiyohara if (consinit_called != 0)
391 1.1 kiyohara return;
392 1.1 kiyohara
393 1.1 kiyohara consinit_called = 1;
394 1.1 kiyohara
395 1.1 kiyohara #if NCOM > 0
396 1.1 kiyohara {
397 1.1 kiyohara extern int mvuart_cnattach(bus_space_tag_t, bus_addr_t, int,
398 1.1 kiyohara uint32_t, int);
399 1.1 kiyohara
400 1.1 kiyohara if (mvuart_cnattach(&mvsoc_bs_tag,
401 1.1 kiyohara MARVELL_INTERREGS_VBASE + MVSOC_COM0_BASE,
402 1.1 kiyohara comcnspeed, mvTclk, comcnmode))
403 1.1 kiyohara panic("can't init serial console");
404 1.1 kiyohara }
405 1.1 kiyohara #else
406 1.1 kiyohara panic("serial console not configured");
407 1.1 kiyohara #endif
408 1.1 kiyohara }
409 1.1 kiyohara
410 1.1 kiyohara
411 1.1 kiyohara static void
412 1.1 kiyohara marvell_device_register(device_t dev, void *aux)
413 1.1 kiyohara {
414 1.1 kiyohara prop_dictionary_t dict = device_properties(dev);
415 1.1 kiyohara
416 1.1 kiyohara #if NCOM > 0
417 1.1 kiyohara if (device_is_a(dev, "com") &&
418 1.1 kiyohara device_is_a(device_parent(dev), "mvsoc"))
419 1.1 kiyohara prop_dictionary_set_uint32(dict, "frequency", mvTclk);
420 1.1 kiyohara #endif
421 1.13 kiyohara if (device_is_a(dev, "gtidmac"))
422 1.1 kiyohara prop_dictionary_set_uint32(dict,
423 1.1 kiyohara "dmb_speed", mvTclk * sizeof(uint32_t)); /* XXXXXX */
424 1.1 kiyohara #if NGTPCI > 0 && defined(ORION)
425 1.1 kiyohara if (device_is_a(dev, "gtpci")) {
426 1.1 kiyohara extern struct bus_space
427 1.1 kiyohara orion_pci_io_bs_tag, orion_pci_mem_bs_tag;
428 1.1 kiyohara extern struct arm32_pci_chipset arm32_gtpci_chipset;
429 1.1 kiyohara
430 1.1 kiyohara prop_data_t io_bs_tag, mem_bs_tag, pc;
431 1.1 kiyohara prop_array_t int2gpp;
432 1.1 kiyohara prop_number_t gpp;
433 1.1 kiyohara uint64_t start, end;
434 1.1 kiyohara int i, j;
435 1.1 kiyohara static struct {
436 1.1 kiyohara const char *boardtype;
437 1.1 kiyohara int pin[PCI_INTERRUPT_PIN_MAX];
438 1.1 kiyohara } hints[] = {
439 1.1 kiyohara { "kuronas_x4",
440 1.1 kiyohara { 11, PCI_INTERRUPT_PIN_NONE } },
441 1.1 kiyohara
442 1.1 kiyohara { NULL,
443 1.1 kiyohara { PCI_INTERRUPT_PIN_NONE } },
444 1.1 kiyohara };
445 1.1 kiyohara
446 1.1 kiyohara arm32_gtpci_chipset.pc_conf_v = device_private(dev);
447 1.1 kiyohara arm32_gtpci_chipset.pc_intr_v = device_private(dev);
448 1.1 kiyohara
449 1.1 kiyohara io_bs_tag = prop_data_create_data_nocopy(
450 1.1 kiyohara &orion_pci_io_bs_tag, sizeof(struct bus_space));
451 1.1 kiyohara KASSERT(io_bs_tag != NULL);
452 1.1 kiyohara prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
453 1.1 kiyohara prop_object_release(io_bs_tag);
454 1.1 kiyohara mem_bs_tag = prop_data_create_data_nocopy(
455 1.1 kiyohara &orion_pci_mem_bs_tag, sizeof(struct bus_space));
456 1.1 kiyohara KASSERT(mem_bs_tag != NULL);
457 1.1 kiyohara prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
458 1.1 kiyohara prop_object_release(mem_bs_tag);
459 1.1 kiyohara
460 1.1 kiyohara pc = prop_data_create_data_nocopy(&arm32_gtpci_chipset,
461 1.1 kiyohara sizeof(struct arm32_pci_chipset));
462 1.1 kiyohara KASSERT(pc != NULL);
463 1.1 kiyohara prop_dictionary_set(dict, "pci-chipset", pc);
464 1.1 kiyohara prop_object_release(pc);
465 1.1 kiyohara
466 1.1 kiyohara marvell_startend_by_tag(ORION_TAG_PCI_IO, &start, &end);
467 1.1 kiyohara prop_dictionary_set_uint64(dict, "iostart", start);
468 1.1 kiyohara prop_dictionary_set_uint64(dict, "ioend", end);
469 1.1 kiyohara marvell_startend_by_tag(ORION_TAG_PCI_MEM, &start, &end);
470 1.1 kiyohara prop_dictionary_set_uint64(dict, "memstart", start);
471 1.1 kiyohara prop_dictionary_set_uint64(dict, "memend", end);
472 1.1 kiyohara prop_dictionary_set_uint32(dict,
473 1.1 kiyohara "cache-line-size", arm_dcache_align);
474 1.1 kiyohara
475 1.1 kiyohara /* Setup the hint for interrupt-pin. */
476 1.1 kiyohara #define BDSTR(s) _BDSTR(s)
477 1.1 kiyohara #define _BDSTR(s) #s
478 1.1 kiyohara #define THIS_BOARD(str) (strcmp(str, BDSTR(EVBARM_BOARDTYPE)) == 0)
479 1.1 kiyohara for (i = 0; hints[i].boardtype != NULL; i++)
480 1.1 kiyohara if (THIS_BOARD(hints[i].boardtype))
481 1.1 kiyohara break;
482 1.1 kiyohara if (hints[i].boardtype == NULL)
483 1.1 kiyohara return;
484 1.1 kiyohara
485 1.1 kiyohara int2gpp =
486 1.1 kiyohara prop_array_create_with_capacity(PCI_INTERRUPT_PIN_MAX + 1);
487 1.1 kiyohara
488 1.1 kiyohara /* first set dummy */
489 1.1 kiyohara gpp = prop_number_create_integer(0);
490 1.1 kiyohara prop_array_add(int2gpp, gpp);
491 1.1 kiyohara prop_object_release(gpp);
492 1.1 kiyohara
493 1.1 kiyohara for (j = 0; hints[i].pin[j] != PCI_INTERRUPT_PIN_NONE; j++) {
494 1.1 kiyohara gpp = prop_number_create_integer(hints[i].pin[j]);
495 1.1 kiyohara prop_array_add(int2gpp, gpp);
496 1.1 kiyohara prop_object_release(gpp);
497 1.1 kiyohara }
498 1.1 kiyohara prop_dictionary_set(dict, "int2gpp", int2gpp);
499 1.1 kiyohara }
500 1.1 kiyohara #endif /* NGTPCI > 0 && defined(ORION) */
501 1.1 kiyohara #if NMVPEX > 0
502 1.1 kiyohara if (device_is_a(dev, "mvpex")) {
503 1.1 kiyohara #ifdef ORION
504 1.1 kiyohara extern struct bus_space
505 1.1 kiyohara orion_pex0_io_bs_tag, orion_pex0_mem_bs_tag,
506 1.1 kiyohara orion_pex1_io_bs_tag, orion_pex1_mem_bs_tag;
507 1.1 kiyohara #endif
508 1.1 kiyohara #ifdef KIRKWOOD
509 1.1 kiyohara extern struct bus_space
510 1.9 kiyohara kirkwood_pex_io_bs_tag, kirkwood_pex_mem_bs_tag,
511 1.9 kiyohara kirkwood_pex1_io_bs_tag, kirkwood_pex1_mem_bs_tag;
512 1.1 kiyohara #endif
513 1.7 tsutsui extern struct arm32_pci_chipset arm32_mvpex0_chipset;
514 1.9 kiyohara #if defined(ORION) || defined(KIRKWOOD)
515 1.7 tsutsui extern struct arm32_pci_chipset arm32_mvpex1_chipset;
516 1.1 kiyohara
517 1.1 kiyohara struct marvell_attach_args *mva = aux;
518 1.7 tsutsui #endif
519 1.1 kiyohara struct bus_space *mvpex_io_bs_tag, *mvpex_mem_bs_tag;
520 1.1 kiyohara struct arm32_pci_chipset *arm32_mvpex_chipset;
521 1.1 kiyohara prop_data_t io_bs_tag, mem_bs_tag, pc;
522 1.1 kiyohara uint64_t start, end;
523 1.1 kiyohara int iotag, memtag;
524 1.1 kiyohara
525 1.1 kiyohara switch (mvsoc_model()) {
526 1.1 kiyohara #ifdef ORION
527 1.1 kiyohara case MARVELL_ORION_1_88F5180N:
528 1.1 kiyohara case MARVELL_ORION_1_88F5181:
529 1.1 kiyohara case MARVELL_ORION_1_88F5182:
530 1.1 kiyohara case MARVELL_ORION_1_88W8660:
531 1.1 kiyohara case MARVELL_ORION_2_88F5281:
532 1.1 kiyohara if (mva->mva_offset == MVSOC_PEX_BASE) {
533 1.1 kiyohara mvpex_io_bs_tag = &orion_pex0_io_bs_tag;
534 1.1 kiyohara mvpex_mem_bs_tag = &orion_pex0_mem_bs_tag;
535 1.1 kiyohara arm32_mvpex_chipset = &arm32_mvpex0_chipset;
536 1.1 kiyohara iotag = ORION_TAG_PEX0_IO;
537 1.1 kiyohara memtag = ORION_TAG_PEX0_MEM;
538 1.1 kiyohara } else {
539 1.1 kiyohara mvpex_io_bs_tag = &orion_pex1_io_bs_tag;
540 1.1 kiyohara mvpex_mem_bs_tag = &orion_pex1_mem_bs_tag;
541 1.1 kiyohara arm32_mvpex_chipset = &arm32_mvpex1_chipset;
542 1.1 kiyohara iotag = ORION_TAG_PEX1_IO;
543 1.1 kiyohara memtag = ORION_TAG_PEX1_MEM;
544 1.1 kiyohara }
545 1.1 kiyohara break;
546 1.1 kiyohara #endif
547 1.1 kiyohara
548 1.1 kiyohara #ifdef KIRKWOOD
549 1.9 kiyohara case MARVELL_KIRKWOOD_88F6282:
550 1.9 kiyohara if (mva->mva_offset != MVSOC_PEX_BASE) {
551 1.9 kiyohara mvpex_io_bs_tag = &kirkwood_pex1_io_bs_tag;
552 1.9 kiyohara mvpex_mem_bs_tag = &kirkwood_pex1_mem_bs_tag;
553 1.9 kiyohara arm32_mvpex_chipset = &arm32_mvpex1_chipset;
554 1.9 kiyohara iotag = KIRKWOOD_TAG_PEX1_IO;
555 1.9 kiyohara memtag = KIRKWOOD_TAG_PEX1_MEM;
556 1.9 kiyohara break;
557 1.9 kiyohara }
558 1.9 kiyohara
559 1.9 kiyohara /* FALLTHROUGH */
560 1.9 kiyohara
561 1.1 kiyohara case MARVELL_KIRKWOOD_88F6180:
562 1.1 kiyohara case MARVELL_KIRKWOOD_88F6192:
563 1.1 kiyohara case MARVELL_KIRKWOOD_88F6281:
564 1.1 kiyohara mvpex_io_bs_tag = &kirkwood_pex_io_bs_tag;
565 1.1 kiyohara mvpex_mem_bs_tag = &kirkwood_pex_mem_bs_tag;
566 1.1 kiyohara arm32_mvpex_chipset = &arm32_mvpex0_chipset;
567 1.1 kiyohara iotag = KIRKWOOD_TAG_PEX_IO;
568 1.1 kiyohara memtag = KIRKWOOD_TAG_PEX_MEM;
569 1.1 kiyohara break;
570 1.1 kiyohara #endif
571 1.1 kiyohara
572 1.1 kiyohara default:
573 1.1 kiyohara return;
574 1.1 kiyohara }
575 1.1 kiyohara
576 1.1 kiyohara arm32_mvpex_chipset->pc_conf_v = device_private(dev);
577 1.1 kiyohara arm32_mvpex_chipset->pc_intr_v = device_private(dev);
578 1.1 kiyohara
579 1.1 kiyohara io_bs_tag = prop_data_create_data_nocopy(
580 1.1 kiyohara mvpex_io_bs_tag, sizeof(struct bus_space));
581 1.1 kiyohara KASSERT(io_bs_tag != NULL);
582 1.1 kiyohara prop_dictionary_set(dict, "io-bus-tag", io_bs_tag);
583 1.1 kiyohara prop_object_release(io_bs_tag);
584 1.1 kiyohara mem_bs_tag = prop_data_create_data_nocopy(
585 1.1 kiyohara mvpex_mem_bs_tag, sizeof(struct bus_space));
586 1.1 kiyohara KASSERT(mem_bs_tag != NULL);
587 1.1 kiyohara prop_dictionary_set(dict, "mem-bus-tag", mem_bs_tag);
588 1.1 kiyohara prop_object_release(mem_bs_tag);
589 1.1 kiyohara
590 1.1 kiyohara pc = prop_data_create_data_nocopy(arm32_mvpex_chipset,
591 1.1 kiyohara sizeof(struct arm32_pci_chipset));
592 1.1 kiyohara KASSERT(pc != NULL);
593 1.1 kiyohara prop_dictionary_set(dict, "pci-chipset", pc);
594 1.1 kiyohara prop_object_release(pc);
595 1.1 kiyohara
596 1.1 kiyohara marvell_startend_by_tag(iotag, &start, &end);
597 1.1 kiyohara prop_dictionary_set_uint64(dict, "iostart", start);
598 1.1 kiyohara prop_dictionary_set_uint64(dict, "ioend", end);
599 1.1 kiyohara marvell_startend_by_tag(memtag, &start, &end);
600 1.1 kiyohara prop_dictionary_set_uint64(dict, "memstart", start);
601 1.1 kiyohara prop_dictionary_set_uint64(dict, "memend", end);
602 1.1 kiyohara prop_dictionary_set_uint32(dict,
603 1.1 kiyohara "cache-line-size", arm_dcache_align);
604 1.1 kiyohara }
605 1.1 kiyohara #endif
606 1.1 kiyohara }
607 1.1 kiyohara
608 1.1 kiyohara #if NGTPCI > 0 || NMVPEX > 0
609 1.1 kiyohara static void
610 1.1 kiyohara marvell_startend_by_tag(int tag, uint64_t *start, uint64_t *end)
611 1.1 kiyohara {
612 1.1 kiyohara uint32_t base, size;
613 1.1 kiyohara int win;
614 1.1 kiyohara
615 1.1 kiyohara win = mvsoc_target(tag, NULL, NULL, &base, &size);
616 1.1 kiyohara if (size != 0) {
617 1.1 kiyohara if (win < nremap)
618 1.1 kiyohara *start = read_mlmbreg(MVSOC_MLMB_WRLR(win)) |
619 1.1 kiyohara ((read_mlmbreg(MVSOC_MLMB_WRHR(win)) << 16) << 16);
620 1.1 kiyohara else
621 1.1 kiyohara *start = base;
622 1.1 kiyohara *end = *start + size - 1;
623 1.1 kiyohara }
624 1.1 kiyohara }
625 1.1 kiyohara #endif
626