at91bus.c revision 1.14 1 /* $NetBSD: at91bus.c,v 1.14 2012/09/01 14:48:06 matt Exp $ */
2
3 /*
4 * Copyright (c) 2007 Embedtronics Oy
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 * 1. Redistributions of source code must retain the above copyright
11 * notice, this list of conditions and the following disclaimer.
12 * 2. Redistributions in binary form must reproduce the above copyright
13 * notice, this list of conditions and the following disclaimer in the
14 * documentation and/or other materials provided with the distribution.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS
17 * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
18 * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
19 * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS
20 * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
21 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
22 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
23 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
24 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
25 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
26 * POSSIBILITY OF SUCH DAMAGE.
27 */
28
29 #include <sys/cdefs.h>
30 __KERNEL_RCSID(0, "$NetBSD: at91bus.c,v 1.14 2012/09/01 14:48:06 matt Exp $");
31
32 #include "opt_ddb.h"
33 #include "opt_kgdb.h"
34 #include "opt_pmap_debug.h"
35
36 /* Define various stack sizes in pages */
37 #define IRQ_STACK_SIZE 8
38 #define ABT_STACK_SIZE 8
39 #ifdef IPKDB
40 #define UND_STACK_SIZE 16
41 #else
42 #define UND_STACK_SIZE 8
43 #endif
44
45 #include <sys/param.h>
46 #include <sys/device.h>
47 #include <sys/systm.h>
48 #include <sys/kernel.h>
49 #include <sys/exec.h>
50 #include <sys/proc.h>
51 #include <sys/msgbuf.h>
52 #include <sys/reboot.h>
53 #include <sys/termios.h>
54 #include <sys/ksyms.h>
55
56 #include <machine/bootconfig.h>
57 #include <uvm/uvm_extern.h>
58
59 #include <dev/cons.h>
60
61 #include <machine/db_machdep.h>
62 #include <ddb/db_sym.h>
63 #include <ddb/db_extern.h>
64
65 #include <sys/bus.h>
66 #include <machine/cpu.h>
67 #include <machine/frame.h>
68 #include <arm/undefined.h>
69
70 #include <arm/arm32/machdep.h>
71 #include <arm/cpufunc.h>
72
73 #include <arm/at91/at91var.h>
74 #include <arm/at91/at91busvar.h>
75 #include <arm/at91/at91dbgureg.h>
76
77 //#include <dev/cons.h>
78 #include <sys/termios.h>
79
80 #include "locators.h"
81
82 /* console stuff: */
83 #ifndef CONSPEED
84 #define CONSPEED B115200
85 #endif
86
87 #ifndef CONMODE
88 #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
89 #endif
90
91 int cnspeed = CONSPEED;
92 int cnmode = CONMODE;
93
94
95 /* kernel mapping: */
96 #define KERNEL_BASE_PHYS 0x20200000
97 #define KERNEL_TEXT_BASE (KERNEL_BASE + 0x00200000)
98 #define KERNEL_VM_BASE (KERNEL_BASE + 0x01000000)
99 #define KERNEL_VM_SIZE 0x0C000000
100
101
102
103 /* boot configuration: */
104 vm_offset_t physical_start;
105 vm_offset_t physical_freestart;
106 vm_offset_t physical_freeend;
107 vm_offset_t physical_freeend_low;
108 vm_offset_t physical_end;
109 u_int free_pages;
110
111 vm_offset_t msgbufphys;
112
113 //static struct arm32_dma_range dma_ranges[4];
114
115 #ifdef PMAP_DEBUG
116 extern int pmap_debug_level;
117 #endif
118
119 #define KERNEL_PT_SYS 0 /* L2 table for mapping vectors page */
120
121 #define KERNEL_PT_KERNEL 1 /* L2 table for mapping kernel */
122 #define KERNEL_PT_KERNEL_NUM 4
123 /* L2 tables for mapping kernel VM */
124 #define KERNEL_PT_VMDATA (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
125
126 #define KERNEL_PT_VMDATA_NUM 4 /* start with 16MB of KVM */
127 #define NUM_KERNEL_PTS (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
128
129 pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
130
131 /* prototypes: */
132 void consinit(void);
133 static int at91bus_match(device_t, cfdata_t, void *);
134 static void at91bus_attach(device_t, device_t, void *);
135 static int at91bus_search(device_t, cfdata_t,
136 const int *, void *);
137 static int at91bus_print(void *, const char *);
138 static int at91bus_submatch(device_t, cfdata_t,
139 const int *, void *);
140
141
142 CFATTACH_DECL_NEW(at91bus, sizeof(struct at91bus_softc),
143 at91bus_match, at91bus_attach, NULL, NULL);
144
145 struct at91bus_clocks at91bus_clocks = {0};
146 struct at91bus_softc *at91bus_sc = NULL;
147
148 #include "opt_at91types.h"
149
150 #ifdef AT91RM9200
151 #include <arm/at91/at91rm9200busvar.h>
152 #endif
153
154 #ifdef AT91SAM9260
155 #include <arm/at91/at91sam9260busvar.h>
156 #endif
157
158 #ifdef AT91SAM9261
159 #include <arm/at91/at91sam9261busvar.h>
160 #endif
161
162 static const struct {
163 u_int32_t cidr;
164 const char * name;
165 const struct at91bus_machdep *machdep;
166 } at91_types[] = {
167 {
168 DBGU_CIDR_AT91RM9200,
169 "AT91RM9200"
170 #ifdef AT91RM9200
171 , &at91rm9200bus
172 #endif
173 },
174 {
175 DBGU_CIDR_AT91SAM9260,
176 "AT91SAM9260"
177 #ifdef AT91SAM9260
178 , &at91sam9260bus
179 #endif
180 },
181 {
182 DBGU_CIDR_AT91SAM9260,
183 "AT91SAM9261"
184 #ifdef AT91SAM9261
185 , &at91sam9261bus
186 #endif
187 },
188 {
189 DBGU_CIDR_AT91SAM9263,
190 "AT91SAM9263"
191 },
192 {
193 0,
194 0,
195 0
196 }
197 };
198
199 u_int32_t at91_chip_id;
200 static int at91_chip_ndx = -1;
201 struct at91bus_machdep at91bus_machdep = { 0 };
202 at91bus_tag_t at91bus_tag = 0;
203
204 static int
205 match_cid(void)
206 {
207 u_int32_t cidr;
208 int i;
209
210 /* get chip id */
211 cidr = DBGUREG(DBGU_CIDR);
212 at91_chip_id = cidr;
213
214 /* do we know it? */
215 for (i = 0; at91_types[i].name; i++) {
216 if (cidr == at91_types[i].cidr)
217 return i;
218 }
219
220 return -1;
221 }
222
223 int
224 at91bus_init(void)
225 {
226 int i = at91_chip_ndx = match_cid();
227
228 if (i < 0)
229 panic("%s: unknown chip", __FUNCTION__);
230
231 if (!at91_types[i].machdep)
232 panic("%s: %s is not supported", __FUNCTION__, at91_types[i].name);
233
234 memcpy(&at91bus_machdep, at91_types[i].machdep, sizeof(at91bus_machdep));
235 at91bus_tag = &at91bus_machdep;
236
237 return 0;
238 }
239
240 u_int
241 at91bus_setup(BootConfig *mem)
242 {
243 int loop;
244 int loop1;
245 u_int l1pagetable;
246
247 consinit();
248
249 #ifdef VERBOSE_INIT_ARM
250 printf("\nNetBSD/AT91 booting ...\n");
251 #endif
252
253 // setup the CPU / MMU / TLB functions:
254 if (set_cpufuncs())
255 panic("%s: cpu not recognized", __FUNCTION__);
256
257 #ifdef VERBOSE_INIT_ARM
258 printf("%s: configuring system...\n", __FUNCTION__);
259 #endif
260
261 /*
262 * Setup the variables that define the availability of
263 * physical memory.
264 */
265 physical_start = mem->dram[0].address;
266 physical_end = mem->dram[0].address + mem->dram[0].pages * PAGE_SIZE;
267
268 physical_freestart = mem->dram[0].address + 0x9000ULL;
269 physical_freeend = KERNEL_BASE_PHYS;
270 physmem = (physical_end - physical_start) / PAGE_SIZE;
271
272 #ifdef VERBOSE_INIT_ARM
273 printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
274 physical_start, physical_end - 1);
275 #endif
276
277 free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
278
279 #ifdef VERBOSE_INIT_ARM
280 printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
281 physical_freestart, free_pages, free_pages);
282 #endif
283 /* Define a macro to simplify memory allocation */
284 #define valloc_pages(var, np) \
285 alloc_pages((var).pv_pa, (np)); \
286 (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
287
288 #define alloc_pages(var, np) \
289 physical_freeend -= ((np) * PAGE_SIZE); \
290 if (physical_freeend < physical_freestart) \
291 panic("initarm: out of memory"); \
292 (var) = physical_freeend; \
293 free_pages -= (np); \
294 memset((char *)(var), 0, ((np) * PAGE_SIZE));
295
296 loop1 = 0;
297 for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
298 /* Are we 16KB aligned for an L1 ? */
299 if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
300 && kernel_l1pt.pv_pa == 0) {
301 valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
302 } else {
303 valloc_pages(kernel_pt_table[loop1],
304 L2_TABLE_SIZE / PAGE_SIZE);
305 ++loop1;
306 }
307 }
308
309 /* This should never be able to happen but better confirm that. */
310 if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
311 panic("initarm: Failed to align the kernel page directory");
312
313 /*
314 * Allocate a page for the system vectors page
315 */
316 valloc_pages(systempage, 1);
317 systempage.pv_va = 0x00000000;
318
319 /* Allocate stacks for all modes */
320 valloc_pages(irqstack, IRQ_STACK_SIZE);
321 valloc_pages(abtstack, ABT_STACK_SIZE);
322 valloc_pages(undstack, UND_STACK_SIZE);
323 valloc_pages(kernelstack, UPAGES);
324
325 #ifdef VERBOSE_INIT_ARM
326 printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
327 irqstack.pv_va);
328 printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
329 abtstack.pv_va);
330 printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
331 undstack.pv_va);
332 printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
333 kernelstack.pv_va);
334 #endif
335
336 alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
337
338 /*
339 * Ok we have allocated physical pages for the primary kernel
340 * page tables. Save physical_freeend for when we give whats left
341 * of memory below 2Mbyte to UVM.
342 */
343
344 physical_freeend_low = physical_freeend;
345
346 #ifdef VERBOSE_INIT_ARM
347 printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
348 #endif
349
350 /*
351 * Now we start construction of the L1 page table
352 * We start by mapping the L2 page tables into the L1.
353 * This means that we can replace L1 mappings later on if necessary
354 */
355 l1pagetable = kernel_l1pt.pv_pa;
356
357 /* Map the L2 pages tables in the L1 page table */
358 pmap_link_l2pt(l1pagetable, 0x00000000, &kernel_pt_table[KERNEL_PT_SYS]);
359 for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
360 pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
361 &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
362 for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
363 pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
364 &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
365
366 /* update the top of the kernel VM */
367 pmap_curmaxkvaddr =
368 KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
369
370 #ifdef VERBOSE_INIT_ARM
371 printf("Mapping kernel\n");
372 #endif
373
374 /* Now we fill in the L2 pagetable for the kernel static code/data */
375 {
376 extern char etext[], _end[];
377 size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
378 size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
379 u_int logical;
380
381 textsize = (textsize + PGOFSET) & ~PGOFSET;
382 totalsize = (totalsize + PGOFSET) & ~PGOFSET;
383
384 logical = KERNEL_BASE_PHYS - mem->dram[0].address; /* offset of kernel in RAM */
385 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
386 physical_start + logical, textsize,
387 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
388 logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
389 physical_start + logical, totalsize - textsize,
390 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
391 }
392
393 #ifdef VERBOSE_INIT_ARM
394 printf("Constructing L2 page tables\n");
395 #endif
396
397 /* Map the stack pages */
398 pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
399 IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
400 pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
401 ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
402 pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
403 UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
404 pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
405 UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
406
407 pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
408 L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
409
410 for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
411 pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
412 kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
413 VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
414 }
415
416 /* Map the vector page. */
417 pmap_map_entry(l1pagetable, ARM_VECTORS_LOW, systempage.pv_pa,
418 VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
419
420 /* Map the statically mapped devices. */
421 pmap_devmap_bootstrap(l1pagetable, at91_devmap());
422
423 /*
424 * Update the physical_freestart/physical_freeend/free_pages
425 * variables.
426 */
427 {
428 extern char _end[];
429
430 physical_freestart = physical_start +
431 (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
432 KERNEL_BASE);
433 physical_freeend = physical_end;
434 free_pages =
435 (physical_freeend - physical_freestart) / PAGE_SIZE;
436 }
437
438 /*
439 * Now we have the real page tables in place so we can switch to them.
440 * Once this is done we will be running with the REAL kernel page
441 * tables.
442 */
443
444 /* Switch tables */
445 #ifdef VERBOSE_INIT_ARM
446 printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
447 physical_freestart, free_pages, free_pages);
448 printf("switching to new L1 page table @%#lx...", kernel_l1pt.pv_pa);
449 #endif
450 cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
451 cpu_setttb(kernel_l1pt.pv_pa);
452 cpu_tlb_flushID();
453 cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
454
455 /*
456 * Moved from cpu_startup() as data_abort_handler() references
457 * this during uvm init
458 */
459 uvm_lwp_setuarea(&lwp0, kernelstack.pv_va);
460
461 #ifdef VERBOSE_INIT_ARM
462 printf("done!\n");
463 #endif
464
465 #ifdef VERBOSE_INIT_ARM
466 printf("bootstrap done.\n");
467 #endif
468
469 /* @@@@ check this out: @@@ */
470 arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
471
472 /*
473 * Pages were allocated during the secondary bootstrap for the
474 * stacks for different CPU modes.
475 * We must now set the r13 registers in the different CPU modes to
476 * point to these stacks.
477 * Since the ARM stacks use STMFD etc. we must set r13 to the top end
478 * of the stack memory.
479 */
480 #ifdef VERBOSE_INIT_ARM
481 printf("init subsystems: stacks ");
482 #endif
483
484 set_stackptr(PSR_IRQ32_MODE,
485 irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
486 set_stackptr(PSR_ABT32_MODE,
487 abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
488 set_stackptr(PSR_UND32_MODE,
489 undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
490
491 /*
492 * Well we should set a data abort handler.
493 * Once things get going this will change as we will need a proper
494 * handler.
495 * Until then we will use a handler that just panics but tells us
496 * why.
497 * Initialisation of the vectors will just panic on a data abort.
498 * This just fills in a slightly better one.
499 */
500 #ifdef VERBOSE_INIT_ARM
501 printf("vectors ");
502 #endif
503 data_abort_handler_address = (u_int)data_abort_handler;
504 prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
505 undefined_handler_address = (u_int)undefinedinstruction_bounce;
506
507 /* Initialise the undefined instruction handlers */
508 #ifdef VERBOSE_INIT_ARM
509 printf("undefined ");
510 #endif
511 undefined_init();
512
513 /* Load memory into UVM. */
514 #ifdef VERBOSE_INIT_ARM
515 printf("page ");
516 #endif
517 uvm_setpagesize(); /* initialize PAGE_SIZE-dependent variables */
518 uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
519 atop(physical_freestart), atop(physical_freeend),
520 VM_FREELIST_DEFAULT);
521 uvm_page_physload(atop(physical_start), atop(physical_freeend_low),
522 atop(physical_start), atop(physical_freeend_low),
523 VM_FREELIST_DEFAULT);
524
525 /* Boot strap pmap telling it where the kernel page table is */
526 #ifdef VERBOSE_INIT_ARM
527 printf("pmap ");
528 #endif
529 pmap_bootstrap(KERNEL_VM_BASE, KERNEL_VM_BASE + KERNEL_VM_SIZE);
530
531 /* Setup the IRQ system */
532 #ifdef VERBOSE_INIT_ARM
533 printf("irq ");
534 #endif
535 at91_intr_init();
536
537 #ifdef VERBOSE_INIT_ARM
538 printf("done.\n");
539 #endif
540
541 #ifdef BOOTHOWTO
542 boothowto = BOOTHOWTO;
543 #endif
544 boothowto = AB_VERBOSE | AB_DEBUG; // @@@@
545
546 #ifdef IPKDB
547 /* Initialise ipkdb */
548 ipkdb_init();
549 if (boothowto & RB_KDB)
550 ipkdb_connect(0);
551 #endif
552
553 #ifdef DDB
554 db_machine_init();
555 if (boothowto & RB_KDB)
556 Debugger();
557 #endif
558 #if 0
559 printf("test data abort...\n");
560 *((volatile uint32_t*)(0x1234567F)) = 0xdeadbeef;
561 #endif
562
563 #ifdef VERBOSE_INIT_ARM
564 printf("%s: returning new stack pointer 0x%lX\n", __FUNCTION__, (kernelstack.pv_va + USPACE_SVC_STACK_TOP));
565 #endif
566
567 /* We return the new stack pointer address */
568 return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
569 }
570
571 static int
572 at91bus_match(device_t parent, cfdata_t match, void *aux)
573 {
574 // we could detect the device here...
575 if (strcmp(match->cf_name, "at91bus") == 0)
576 return 1;
577 return 0;
578 }
579
580 static device_t
581 at91bus_found(device_t self, bus_addr_t addr, int pid)
582 {
583 int locs[AT91BUSCF_NLOCS];
584 struct at91bus_attach_args sa;
585 struct at91bus_softc *sc;
586
587 memset(&locs, 0, sizeof(locs));
588 memset(&sa, 0, sizeof(sa));
589
590 locs[AT91BUSCF_ADDR] = addr;
591 locs[AT91BUSCF_PID] = pid;
592
593 sc = device_private(self);
594 sa.sa_iot = sc->sc_iot;
595 sa.sa_dmat = sc->sc_dmat;
596 sa.sa_addr = addr;
597 sa.sa_size = 1;
598 sa.sa_pid = pid;
599
600 return config_found_sm_loc(self, "at91bus", locs, &sa,
601 at91bus_print, at91bus_submatch);
602 }
603
604 static void
605 at91bus_attach(device_t parent, device_t self, void *aux)
606 {
607 struct at91bus_softc *sc;
608
609 if (at91_chip_ndx < 0)
610 panic("%s: at91bus_init() has not been called!", __FUNCTION__);
611
612 sc = device_private(self);
613
614 /* initialize bus space and bus dma things... */
615 sc->sc_iot = &at91_bs_tag;
616 sc->sc_dmat = at91_bus_dma_init(&at91_bd_tag);
617
618 if (at91bus_sc == NULL)
619 at91bus_sc = sc;
620
621 printf(": %s, sclk %u.%03u kHz, mclk %u.%03u MHz, pclk %u.%03u MHz, mstclk %u.%03u, plla %u.%03u, pllb %u.%03u MHz\n",
622 at91_types[at91_chip_ndx].name,
623 AT91_SCLK / 1000U, AT91_SCLK % 1000U,
624 AT91_MCLK / 1000000U, (AT91_MCLK / 1000U) % 1000U,
625 AT91_PCLK / 1000000U, (AT91_PCLK / 1000U) % 1000U,
626 AT91_MSTCLK / 1000000U, (AT91_MSTCLK / 1000U) % 1000U,
627 AT91_PLLACLK / 1000000U, (AT91_PLLACLK / 1000U) % 1000U,
628 AT91_PLLBCLK / 1000000U, (AT91_PLLBCLK / 1000U) % 1000U);
629
630 /*
631 * Attach devices
632 */
633 at91_search_peripherals(self, at91bus_found);
634
635
636 struct at91bus_attach_args sa;
637 memset(&sa, 0, sizeof(sa));
638 sa.sa_iot = sc->sc_iot;
639 sa.sa_dmat = sc->sc_dmat;
640 config_search_ia(at91bus_search, self, "at91bus", &sa);
641 }
642
643 int
644 at91bus_submatch(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
645 {
646 struct at91bus_attach_args *sa = aux;
647
648 if (cf->cf_loc[AT91BUSCF_ADDR] == ldesc[AT91BUSCF_ADDR]
649 && cf->cf_loc[AT91BUSCF_PID] == ldesc[AT91BUSCF_PID]) {
650 sa->sa_addr = cf->cf_loc[AT91BUSCF_ADDR];
651 sa->sa_size = cf->cf_loc[AT91BUSCF_SIZE];
652 sa->sa_pid = cf->cf_loc[AT91BUSCF_PID];
653 return (config_match(parent, cf, aux));
654 } else
655 return (0);
656 }
657
658 int
659 at91bus_search(device_t parent, cfdata_t cf, const int *ldesc, void *aux)
660 {
661 struct at91bus_attach_args *sa = aux;
662
663 sa->sa_addr = cf->cf_loc[AT91BUSCF_ADDR];
664 sa->sa_size = cf->cf_loc[AT91BUSCF_SIZE];
665 sa->sa_pid = cf->cf_loc[AT91BUSCF_PID];
666
667 if (config_match(parent, cf, aux) > 0)
668 config_attach(parent, cf, aux, at91bus_print);
669
670 return (0);
671 }
672
673 static int
674 at91bus_print(void *aux, const char *name)
675 {
676 struct at91bus_attach_args *sa = (struct at91bus_attach_args*)aux;
677
678 if (name)
679 aprint_normal("%s at %s", sa->sa_pid >= 0 ? at91_peripheral_name(sa->sa_pid) : "device", name);
680
681 if (sa->sa_size)
682 aprint_normal(" at addr 0x%lx", sa->sa_addr);
683 if (sa->sa_size > 1)
684 aprint_normal("-0x%lx", sa->sa_addr + sa->sa_size - 1);
685 if (sa->sa_pid >= 0)
686 aprint_normal(" pid %d", sa->sa_pid);
687
688 return (UNCONF);
689 }
690
691 void consinit(void)
692 {
693 static int consinit_called;
694
695 if (consinit_called != 0)
696 return;
697
698 consinit_called = 1;
699
700 if (at91_chip_ndx < 0)
701 panic("%s: at91_init() has not been called!", __FUNCTION__);
702
703 // call machine specific bus initialization code
704 (*at91bus_tag->init)(&at91bus_clocks);
705
706 // attach console
707 (*at91bus_tag->attach_cn)(&at91_bs_tag, cnspeed, cnmode);
708 }
709