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