[BACK]Return to jornada_machdep.c.test CVS log [TXT][DIR] Up to [local] / sys / arch / jornada / jornada

Annotation of sys/arch/jornada/jornada/jornada_machdep.c.test, Revision 1.1.1.1

1.1       nbrk        1: /*     $OpenBSD: armish_machdep.c,v 1.10 2007/05/19 15:49:05 miod Exp $ */
                      2: /*     $NetBSD: lubbock_machdep.c,v 1.2 2003/07/15 00:25:06 lukem Exp $ */
                      3:
                      4: /*
                      5:  * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
                      6:  * All rights reserved.
                      7:  *
                      8:  * Written by Jason R. Thorpe for Wasabi Systems, Inc.
                      9:  *
                     10:  * Redistribution and use in source and binary forms, with or without
                     11:  * modification, are permitted provided that the following conditions
                     12:  * are met:
                     13:  * 1. Redistributions of source code must retain the above copyright
                     14:  *    notice, this list of conditions and the following disclaimer.
                     15:  * 2. Redistributions in binary form must reproduce the above copyright
                     16:  *    notice, this list of conditions and the following disclaimer in the
                     17:  *    documentation and/or other materials provided with the distribution.
                     18:  * 3. All advertising materials mentioning features or use of this software
                     19:  *    must display the following acknowledgement:
                     20:  *     This product includes software developed for the NetBSD Project by
                     21:  *     Wasabi Systems, Inc.
                     22:  * 4. The name of Wasabi Systems, Inc. may not be used to endorse
                     23:  *    or promote products derived from this software without specific prior
                     24:  *    written permission.
                     25:  *
                     26:  * THIS SOFTWARE IS PROVIDED BY WASABI SYSTEMS, INC. ``AS IS'' AND
                     27:  * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED
                     28:  * TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR
                     29:  * PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL WASABI SYSTEMS, INC
                     30:  * BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
                     31:  * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
                     32:  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
                     33:  * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
                     34:  * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
                     35:  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
                     36:  * POSSIBILITY OF SUCH DAMAGE.
                     37:  */
                     38:
                     39: /*
                     40:  * Copyright (c) 1997,1998 Mark Brinicombe.
                     41:  * Copyright (c) 1997,1998 Causality Limited.
                     42:  * All rights reserved.
                     43:  *
                     44:  * Redistribution and use in source and binary forms, with or without
                     45:  * modification, are permitted provided that the following conditions
                     46:  * are met:
                     47:  * 1. Redistributions of source code must retain the above copyright
                     48:  *    notice, this list of conditions and the following disclaimer.
                     49:  * 2. Redistributions in binary form must reproduce the above copyright
                     50:  *    notice, this list of conditions and the following disclaimer in the
                     51:  *    documentation and/or other materials provided with the distribution.
                     52:  * 3. All advertising materials mentioning features or use of this software
                     53:  *    must display the following acknowledgement:
                     54:  *     This product includes software developed by Mark Brinicombe
                     55:  *     for the NetBSD Project.
                     56:  * 4. The name of the company nor the name of the author may be used to
                     57:  *    endorse or promote products derived from this software without specific
                     58:  *    prior written permission.
                     59:  *
                     60:  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
                     61:  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
                     62:  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
                     63:  * IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
                     64:  * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
                     65:  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
                     66:  * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
                     67:  * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
                     68:  * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
                     69:  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
                     70:  * SUCH DAMAGE.
                     71:  *
                     72:  * Machine dependant functions for kernel setup for Intel IQ80321 evaluation
                     73:  * boards using RedBoot firmware.
                     74:  */
                     75:
                     76: /*
                     77:  * DIP switches:
                     78:  *
                     79:  * S19: no-dot: set RB_KDB.  enter kgdb session.
                     80:  * S20: no-dot: set RB_SINGLE. don't go multi user mode.
                     81:  */
                     82:
                     83: #include <sys/param.h>
                     84: #include <sys/device.h>
                     85: #include <sys/systm.h>
                     86: #include <sys/kernel.h>
                     87: #include <sys/exec.h>
                     88: #include <sys/proc.h>
                     89: #include <sys/msgbuf.h>
                     90: #include <sys/reboot.h>
                     91: #include <sys/termios.h>
                     92: #include <sys/kcore.h>
                     93:
                     94: #include <uvm/uvm_extern.h>
                     95:
                     96: #include <sys/conf.h>
                     97: #include <sys/queue.h>
                     98: #include <sys/device.h>
                     99: #include <dev/cons.h>
                    100:
                    101: #include <machine/db_machdep.h>
                    102: #include <ddb/db_sym.h>
                    103: #include <ddb/db_extern.h>
                    104:
                    105: #include <machine/bootconfig.h>
                    106: #include <machine/bus.h>
                    107: #include <machine/cpu.h>
                    108: #include <machine/frame.h>
                    109: #include <arm/kcore.h>
                    110: #include <arm/undefined.h>
                    111: #include <arm/machdep.h>
                    112:
                    113: #include <arm/sa11x0/sa11x0_reg.h>
                    114: #include <arm/sa11x0/sa11x0_var.h>
                    115: #include <machine/jornada_reg.h>
                    116:
                    117: #include "sacom.h"
                    118: #if NSACOM > 0
                    119: int    sacomcnattach(bus_space_tag_t bust, bus_addr_t busa, int speed);
                    120: void   sacomfakecnattach(void);
                    121: #endif
                    122:
                    123: #include "jfb.h"
                    124: #if NJFB > 0
                    125: #include <arch/jornada/dev/jfbreg.h>
                    126: void   jfbfakecnattach(bus_addr_t addr);
                    127: int    jfbcnattach(bus_space_tag_t bust, bus_addr_t busa);
                    128: #endif /* NJFB */
                    129:
                    130: /* Kernel text starts 2MB in from the bottom of the kernel address space. */
                    131: #define        KERNEL_TEXT_BASE        (KERNEL_BASE + 0x00200000)
                    132: #define        KERNEL_VM_BASE          (KERNEL_BASE + 0x10000000)
                    133:
                    134: /*
                    135:  * The range 0xc1000000 - 0xcfffffff is available for kernel VM space
                    136:  * Core-logic registers and I/O mappings occupy 0xfd000000 - 0xffffffff
                    137:  */
                    138: #define KERNEL_VM_SIZE         0x20000000
                    139:
                    140:
                    141: /*
                    142:  * Address to call from cpu_reset() to reset the machine.
                    143:  * This is machine architecture dependant as it varies depending
                    144:  * on where the ROM appears when you turn the MMU off.
                    145:  */
                    146:
                    147: u_int cpu_reset_address = 0;
                    148:
                    149: /* Define various stack sizes in pages */
                    150: #define IRQ_STACK_SIZE 1
                    151: #define ABT_STACK_SIZE 1
                    152: #ifdef IPKDB
                    153: #define UND_STACK_SIZE 2
                    154: #else
                    155: #define UND_STACK_SIZE 1
                    156: #endif
                    157:
                    158: BootConfig bootconfig;         /* Boot config storage */
                    159: char *boot_args = NULL;
                    160: char *boot_file = NULL;
                    161:
                    162: paddr_t physical_start;
                    163: paddr_t physical_freestart;
                    164: paddr_t physical_freeend;
                    165: paddr_t physical_end;
                    166: u_int free_pages;
                    167: paddr_t pagetables_start;
                    168: int physmem = 0;
                    169:
                    170: /*int debug_flags;*/
                    171: #ifndef PMAP_STATIC_L1S
                    172: int max_processes = 64;                        /* Default number */
                    173: #endif /* !PMAP_STATIC_L1S */
                    174:
                    175: /* Physical and virtual addresses for some global pages */
                    176: pv_addr_t systempage;
                    177: pv_addr_t irqstack;
                    178: pv_addr_t undstack;
                    179: pv_addr_t abtstack;
                    180: extern pv_addr_t kernelstack;
                    181: pv_addr_t minidataclean;
                    182:
                    183: paddr_t msgbufphys;
                    184:
                    185: extern u_int data_abort_handler_address;
                    186: extern u_int prefetch_abort_handler_address;
                    187: extern u_int undefined_handler_address;
                    188:
                    189: #ifdef PMAP_DEBUG
                    190: extern int pmap_debug_level;
                    191: #endif
                    192:
                    193: #define KERNEL_PT_SYS          0       /* L2 table for mapping zero page */
                    194:
                    195: #define KERNEL_PT_KERNEL       1       /* L2 table for mapping kernel */
                    196: #define        KERNEL_PT_KERNEL_NUM    8
                    197:
                    198:                                        /* L2 table for mapping i80312 */
                    199: #define        KERNEL_PT_IOPXS         (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
                    200:
                    201:                                        /* L2 tables for mapping kernel VM */
                    202: #define KERNEL_PT_VMDATA       (KERNEL_PT_IOPXS + 1)
                    203: //#define KERNEL_PT_VMDATA     (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
                    204: #define        KERNEL_PT_VMDATA_NUM    8       /* start with 16MB of KVM */
                    205: #define NUM_KERNEL_PTS         (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
                    206:
                    207: pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
                    208:
                    209: extern struct user *proc0paddr;
                    210:
                    211: /* Prototypes */
                    212:
                    213: #define        BOOT_STRING_MAGIC 0x4f425344
                    214:
                    215: char   bootargs[MAX_BOOT_STRING];
                    216: void   process_kernel_args(char *);
                    217:
                    218: void   consinit(void);
                    219: void   fakecninit(bus_addr_t paddr);
                    220:
                    221: #include "com.h"
                    222: #if NCOM > 0
                    223: #include <dev/ic/comreg.h>
                    224: #include <dev/ic/comvar.h>
                    225: #endif
                    226:
                    227: #ifndef CONSPEED
                    228: #define CONSPEED B115200       /* What RedBoot uses */
                    229: #endif
                    230: #ifndef CONMODE
                    231: #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8 | CLOCAL) /* 8N1 */
                    232: #endif
                    233:
                    234: int comcnspeed = CONSPEED;
                    235: int comcnmode = CONMODE;
                    236:
                    237:
                    238: /*
                    239:  * void boot(int howto, char *bootstr)
                    240:  *
                    241:  * Reboots the system
                    242:  *
                    243:  * Deal with any syncing, unmounting, dumping and shutdown hooks,
                    244:  * then reset the CPU.
                    245:  */
                    246: void   board_reset(void);
                    247: void   board_powerdown(void);
                    248: void
                    249: boot(int howto)
                    250: {
                    251:        /*
                    252:         * If we are still cold then hit the air brakes
                    253:         * and crash to earth fast
                    254:         */
                    255:        if (cold) {
                    256:                doshutdownhooks();
                    257:                if ((howto & (RB_HALT | RB_USERREQ)) != RB_USERREQ) {
                    258:                        printf("The operating system has halted.\n");
                    259:                        printf("Please press any key to reboot.\n\n");
                    260:                        cngetc();
                    261:                }
                    262:                printf("rebooting...\n");
                    263:                delay(60000);
                    264:                cpu_reset();
                    265:                printf("reboot failed; spinning\n");
                    266:                while(1);
                    267:                /*NOTREACHED*/
                    268:        }
                    269:
                    270:        /* Disable console buffering */
                    271: /*     cnpollc(1);*/
                    272:
                    273:        /*
                    274:         * If RB_NOSYNC was not specified sync the discs.
                    275:         * Note: Unless cold is set to 1 here, syslogd will die during the
                    276:         * unmount.  It looks like syslogd is getting woken up only to find
                    277:         * that it cannot page part of the binary in as the filesystem has
                    278:         * been unmounted.
                    279:         */
                    280:        if (!(howto & RB_NOSYNC))
                    281:                bootsync(howto);
                    282:
                    283:        /* Say NO to interrupts */
                    284:        splhigh();
                    285:
                    286:        /* Do a dump if requested. */
                    287:        if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
                    288:                dumpsys();
                    289:
                    290:        /* Run any shutdown hooks */
                    291:        doshutdownhooks();
                    292:
                    293:        /* Make sure IRQ's are disabled */
                    294:        IRQdisable;
                    295:
                    296:        if (howto & RB_HALT) {
                    297:                if (howto & RB_POWERDOWN) {
                    298:                        /* TODO */
                    299:                        //board_powerdown();
                    300:                        printf("WARNING: powerdown failed!\n");
                    301:                }
                    302:
                    303:                printf("The operating system has halted.\n");
                    304:                printf("Please press any key to reboot.\n\n");
                    305:                cngetc();
                    306:        }
                    307:
                    308:        printf("rebooting...\n");
                    309:
                    310: /* TODO */
                    311: //     board_reset();
                    312:        cpu_reset();
                    313:        printf("reboot failed; spinning\n");
                    314:        while(1);
                    315:        /*NOTREACHED*/
                    316: }
                    317:
                    318: /*
                    319:  * Mapping table for core kernel memory. These areas are mapped in
                    320:  * init time at fixed virtual address with section mappings.
                    321:  */
                    322: const struct pmap_devmap jornada_devmap[] = {
                    323:     /*
                    324:      * Map the on-board devices VA == PA so that we can access them
                    325:      * with the MMU on or off.
                    326:      */
                    327:     {
                    328:        SACOM3_BASE,
                    329:        SACOM3_HW_BASE,
                    330:        0x24 /* SACOM3_SIZE, */,
                    331:        VM_PROT_READ|VM_PROT_WRITE,
                    332:        PTE_NOCACHE,
                    333:     },
                    334:     {
                    335:        SAIPIC_VBASE,
                    336:        SAIPIC_BASE,
                    337:        0x24 /* SAIPIC_SIZE, */,
                    338:        VM_PROT_READ|VM_PROT_WRITE,
                    339:        PTE_NOCACHE,
                    340:     },
                    341:     {
                    342:        JFB_VBASE,
                    343:        JFB_BASE,
                    344:        JFB_SIZE,
                    345:        VM_PROT_READ|VM_PROT_WRITE,
                    346:        PTE_NOCACHE,
                    347:     },
                    348:     {0, 0, 0, 0, 0}
                    349: };
                    350:
                    351:
                    352: /*
                    353:  * u_int initarm(...)
                    354:  *
                    355:  * Initial entry point on startup. This gets called before main() is
                    356:  * entered.
                    357:  * It should be responsible for setting up everything that must be
                    358:  * in place when main is called.
                    359:  * This includes
                    360:  *   Taking a copy of the boot configuration structure.
                    361:  *   Initialising the physical console so characters can be printed.
                    362:  *   Setting up page tables for the kernel
                    363:  *   Relocating the kernel to the bottom of physical memory
                    364:  */
                    365: u_int
                    366: initarm(void *arg)
                    367: {
                    368:        extern cpu_kcore_hdr_t cpu_kcore_hdr;
                    369:        int loop;
                    370:        int loop1;
                    371:        u_int l1pagetable;
                    372:        pv_addr_t kernel_l1pt;
                    373:        paddr_t memstart;
                    374:        psize_t memsize;
                    375:        extern u_int32_t esym;  /* &_end if no symbols are loaded */
                    376:
                    377:        /* get ready for splfoo() */
                    378:        sa11x0_intr_bootstrap(SAIPIC_BASE);
                    379:
                    380:        pmap_devmap_register(jornada_devmap);
                    381:
                    382:        /* setup a serial console for very early boot */
                    383: #ifdef CONSOLE_COM
                    384:        fakecninit(SACOM3_HW_BASE);
                    385: #else
                    386:        fakecninit(JFB_BASE);
                    387: #endif
                    388:
                    389:        /*
                    390:         * Heads up ... Setup the CPU / MMU / TLB functions
                    391:         */
                    392:        if (set_cpufuncs())
                    393:                panic("cpu not recognized!");
                    394:
                    395:        /*
                    396:         * Examine the boot args string for options we need to know about
                    397:         * now.
                    398:         */
                    399:        /* XXX should really be done after setting up the console, but we
                    400:         * XXX need to parse the console selection flags right now. */
                    401:        process_kernel_args((char *)0xc0200000 - MAX_BOOT_STRING - 1);
                    402: #ifdef RAMDISK_HOOKS
                    403:         boothowto |= RB_DFLTROOT;
                    404: #endif /* RAMDISK_HOOKS */
                    405:
                    406:        /* Talk to the user */
                    407:        printf("\nOpenBSD/jornada booting ...\n");
                    408:
                    409: #define VERBOSE_INIT_ARM
                    410:
                    411:        /* Ugly hardcode DRAM bounds */
                    412:        /* TODO */
                    413:        memstart = (paddr_t)0xc0000000;
                    414:        memsize = (psize_t)32 * 1024 * 1024;
                    415:
                    416: #define DEBUG
                    417: #ifdef DEBUG
                    418:        printf("initarm: Configuring system ...\n");
                    419: #endif
                    420:
                    421:        /* Fake bootconfig structure for the benefit of pmap.c */
                    422:        /* XXX must make the memory description h/w independant */
                    423:        bootconfig.dramblocks = 1;
                    424:        bootconfig.dram[0].address = memstart;
                    425:        bootconfig.dram[0].pages = memsize / PAGE_SIZE;
                    426:
                    427:        /*
                    428:         * Set up the variables that define the availablilty of
                    429:         * physical memory.  For now, we're going to set
                    430:         * physical_freestart to 0xc0200000 (where the kernel
                    431:         * was loaded), and allocate the memory we need downwards.
                    432:         * If we get too close to the page tables that RedBoot
                    433:         * set up, we will panic.  We will update physical_freestart
                    434:         * and physical_freeend later to reflect what pmap_bootstrap()
                    435:         * wants to see.
                    436:         *
                    437:         * XXX pmap_bootstrap() needs an enema.
                    438:         */
                    439:        physical_start = bootconfig.dram[0].address;
                    440:        physical_end = physical_start + (bootconfig.dram[0].pages * PAGE_SIZE);
                    441:
                    442:        physical_freestart = 0xc0200000UL;
                    443: //     physical_freeend = 0xc0200000UL;
                    444:        physical_freeend = physical_end;
                    445:
                    446:        physmem = (physical_end - physical_start) / PAGE_SIZE;
                    447:
                    448: #if defined(DEBUG) || defined(VERBOSE_INIT_ARM)
                    449:        /* Tell the user about the memory */
                    450:        printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
                    451:            physical_start, physical_end - 1);
                    452: #endif
                    453:
                    454:        /*
                    455:         * Okay, the kernel starts 2MB in from the bottom of physical
                    456:         * memory.  We are going to allocate our bootstrap pages downwards
                    457:         * from there.
                    458:         *
                    459:         * We need to allocate some fixed page tables to get the kernel
                    460:         * going.  We allocate one page directory and a number of page
                    461:         * tables and store the physical addresses in the kernel_pt_table
                    462:         * array.
                    463:         *
                    464:         * The kernel page directory must be on a 16K boundary.  The page
                    465:         * tables must be on 4K boundaries.  What we do is allocate the
                    466:         * page directory on the first 16K boundary that we encounter, and
                    467:         * the page tables on 4K boundaries otherwise.  Since we allocate
                    468:         * at least 3 L2 page tables, we are guaranteed to encounter at
                    469:         * least one 16K aligned region.
                    470:         */
                    471:
                    472: #ifdef VERBOSE_INIT_ARM
                    473:        printf("Allocating page tables\n");
                    474: #endif
                    475:
                    476:        free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
                    477:
                    478: #ifdef VERBOSE_INIT_ARM
                    479:        printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
                    480:               physical_freestart, free_pages, free_pages);
                    481: #endif
                    482:
                    483:        /* Define a macro to simplify memory allocation */
                    484: #define        valloc_pages(var, np)                           \
                    485:        alloc_pages((var).pv_pa, (np));                 \
                    486:        (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
                    487:
                    488: #define alloc_pages(var, np)                           \
                    489:        physical_freeend -= ((np) * PAGE_SIZE);         \
                    490:        if (physical_freeend < physical_freestart)      \
                    491:                panic("initarm: out of memory");        \
                    492:        (var) = physical_freeend;                       \
                    493:        free_pages -= (np);                             \
                    494:        memset((char *)(var), 0, ((np) * PAGE_SIZE));
                    495:
                    496:        loop1 = 0;
                    497:        kernel_l1pt.pv_pa = 0;
                    498:        for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
                    499:                /* Are we 16KB aligned for an L1 ? */
                    500:                if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
                    501:                    && kernel_l1pt.pv_pa == 0) {
                    502:                        valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
                    503:                } else {
                    504:                        valloc_pages(kernel_pt_table[loop1],
                    505:                            L2_TABLE_SIZE / PAGE_SIZE);
                    506:                        ++loop1;
                    507:                }
                    508:        }
                    509:
                    510:        /* This should never be able to happen but better confirm that. */
                    511:        if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
                    512:                panic("initarm: Failed to align the kernel page directory");
                    513:
                    514:        /*
                    515:         * Allocate a page for the system page mapped to V0x00000000
                    516:         * This page will just contain the system vectors and can be
                    517:         * shared by all processes.
                    518:         */
                    519:        alloc_pages(systempage.pv_pa, 1);
                    520:
                    521:        /* Allocate stacks for all modes */
                    522:        valloc_pages(irqstack, IRQ_STACK_SIZE);
                    523:        valloc_pages(abtstack, ABT_STACK_SIZE);
                    524:        valloc_pages(undstack, UND_STACK_SIZE);
                    525:        valloc_pages(kernelstack, UPAGES);
                    526:
                    527: #ifdef VERBOSE_INIT_ARM
                    528:        printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
                    529:            irqstack.pv_va);
                    530:        printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
                    531:            abtstack.pv_va);
                    532:        printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
                    533:            undstack.pv_va);
                    534:        printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
                    535:            kernelstack.pv_va);
                    536: #endif
                    537:
                    538:        /*
                    539:         * XXX Defer this to later so that we can reclaim the memory
                    540:         * XXX used by the RedBoot page tables.
                    541:         */
                    542:        alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
                    543:
                    544:        /*
                    545:         * Ok we have allocated physical pages for the primary kernel
                    546:         * page tables
                    547:         */
                    548:
                    549: #ifdef VERBOSE_INIT_ARM
                    550:        printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
                    551: #endif
                    552:
                    553:        /*
                    554:         * Now we start construction of the L1 page table
                    555:         * We start by mapping the L2 page tables into the L1.
                    556:         * This means that we can replace L1 mappings later on if necessary
                    557:         */
                    558:        l1pagetable = kernel_l1pt.pv_pa;
                    559:
                    560: #ifdef HIGH_VECT
                    561:        /* Map the L2 pages tables in the L1 page table */
                    562:        pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
                    563:            &kernel_pt_table[KERNEL_PT_SYS]);
                    564: #else
                    565:        /* Map the L2 pages tables in the L1 page table */
                    566:        pmap_link_l2pt(l1pagetable, 0x00000000,
                    567:            &kernel_pt_table[KERNEL_PT_SYS]);
                    568: #endif
                    569:        for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
                    570:                pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
                    571:                    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
                    572:
                    573:        for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
                    574:                pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
                    575:                    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
                    576:
                    577:        /* link devices */
                    578:        pmap_link_l2pt(l1pagetable, 0xfd000000/* IQ80321_IOPXS_VBASE */,
                    579:            &kernel_pt_table[KERNEL_PT_IOPXS]);
                    580:
                    581:        /* update the top of the kernel VM */
                    582:        pmap_curmaxkvaddr =
                    583:            KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
                    584:
                    585: #ifdef VERBOSE_INIT_ARM
                    586:        printf("Mapping kernel\n");
                    587: #endif
                    588:
                    589:        /* Now we fill in the L2 pagetable for the kernel static code/data
                    590:         * and the symbol table. */
                    591:        {
                    592:                extern char etext[];
                    593: #ifdef VERBOSE_INIT_ARM
                    594:                extern char _end[];
                    595: #endif
                    596:                size_t textsize = (u_int32_t) etext - KERNEL_TEXT_BASE;
                    597:                size_t totalsize = esym - KERNEL_TEXT_BASE;
                    598:                u_int logical;
                    599:
                    600: #ifdef VERBOSE_INIT_ARM
                    601:                printf("kernelsize text %x total %x end %x esym %x\n",
                    602:                    textsize, totalsize, _end, esym);
                    603: #endif
                    604:
                    605:                textsize = round_page(textsize);
                    606:                totalsize = round_page(totalsize);
                    607:
                    608:                logical = 0x00200000;   /* offset of kernel in RAM */
                    609:
                    610:                /* Update dump information */
                    611:                cpu_kcore_hdr.kernelbase = KERNEL_BASE;
                    612:                cpu_kcore_hdr.kerneloffs = logical;
                    613:                cpu_kcore_hdr.staticsize = totalsize;
                    614:
                    615:                logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
                    616:                    physical_start + logical, textsize,
                    617:                    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
                    618:                pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
                    619:                    physical_start + logical, totalsize - textsize,
                    620:                    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
                    621:        }
                    622:
                    623: #ifdef VERBOSE_INIT_ARM
                    624:        printf("Constructing L2 page tables\n");
                    625: #endif
                    626:
                    627:        /* Map the stack pages */
                    628:        pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
                    629:            IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
                    630:        pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
                    631:            ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
                    632:        pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
                    633:            UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
                    634:        pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
                    635:            UPAGES * PAGE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_CACHE);
                    636:
                    637:        pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
                    638:            L1_TABLE_SIZE, VM_PROT_READ | VM_PROT_WRITE, PTE_PAGETABLE);
                    639:
                    640:        for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
                    641:                pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
                    642:                    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
                    643:                    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
                    644:        }
                    645:
                    646:        /* Map the vector page. */
                    647: #ifdef HIGH_VECT
                    648:        pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
                    649:            VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
                    650: #else
                    651:         pmap_map_entry(l1pagetable, vector_page, systempage.pv_pa,
                    652:            VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
                    653: #endif
                    654:
                    655:        /* XXX XXX */
                    656:        pmap_devmap_bootstrap(l1pagetable, jornada_devmap);
                    657:
                    658:        /*
                    659:         * Now we have the real page tables in place so we can switch to them.
                    660:         * Once this is done we will be running with the REAL kernel page
                    661:         * tables.
                    662:         */
                    663:
                    664:        /*
                    665:         * Update the physical_freestart/physical_freeend/free_pages
                    666:         * variables.
                    667:         */
                    668:        {
                    669:                physical_freestart = physical_start - KERNEL_BASE +
                    670:                    round_page(esym);
                    671:                physical_freeend = physical_end;
                    672:                free_pages =
                    673:                    (physical_freeend - physical_freestart) / PAGE_SIZE;
                    674:        }
                    675: #ifdef VERBOSE_INIT_ARM
                    676:        printf("physical_freestart %x end %x\n", physical_freestart,
                    677:            physical_freeend);
                    678: #endif
                    679:
                    680:        /* be a client to all domains */
                    681:        //cpu_domains(0x55555555);
                    682:        /* Switch tables */
                    683: #ifdef VERBOSE_INIT_ARM
                    684:        printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
                    685:               physical_freestart, free_pages, free_pages);
                    686:        printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
                    687: #endif
                    688:
                    689:        /* set new intc register address so that splfoo() doesn't
                    690:                touch illegal address.  */
                    691:        sa11x0_intr_bootstrap(SAIPIC_VBASE);
                    692:
                    693: #if 0
                    694:        int i;
                    695:        for (i = 0; i < 1000; i++)
                    696:                *(uint32_t *)(JFB_VBASE + 0x20 + i * 4) = 0x00ff00ff;
                    697:        cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
                    698:        for (i = 0; i < 1000; i++)
                    699:                *(uint32_t *)(JFB_VBASE + 0x20 + i * 4) = 0x0f000f00;
                    700:        setttb(kernel_l1pt.pv_pa);
                    701:        for (i = 0; i < 1000; i++)
                    702:                *(uint32_t *)(JFB_VBASE + 0x20 + i * 4) = 0x00f000f0;
                    703:        cpu_tlb_flushID();
                    704:        for (i = 0; i < 1000; i++)
                    705:                *(uint32_t *)(JFB_VBASE + 0x20 + i * 4) = 0x000f000f;
                    706:        cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
                    707:        for (i = 0; i < 1000; i++)
                    708:                *(uint32_t *)(JFB_VBASE + 0x20 + i * 4) = 0xffffffff;
                    709: #endif /* 0 */
                    710:        //jfbcnattach(&sa11x0_bs_tag, JFB_VBASE);
                    711:        /*
                    712:         * Moved from cpu_startup() as data_abort_handler() references
                    713:         * this during uvm init
                    714:         */
                    715:        proc0paddr = (struct user *)kernelstack.pv_va;
                    716:        proc0.p_addr = proc0paddr;
                    717:
                    718: #ifdef VERBOSE_INIT_ARM
                    719:        printf("bootstrap done.\n");
                    720: #endif
                    721:
                    722: #ifdef HIGH_VECT
                    723:        arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
                    724: #else
                    725:        arm32_vector_init(ARM_VECTORS_LOW, ARM_VEC_ALL);
                    726: #endif
                    727:
                    728:        /*
                    729:         * Pages were allocated during the secondary bootstrap for the
                    730:         * stacks for different CPU modes.
                    731:         * We must now set the r13 registers in the different CPU modes to
                    732:         * point to these stacks.
                    733:         * Since the ARM stacks use STMFD etc. we must set r13 to the top end
                    734:         * of the stack memory.
                    735:         */
                    736: #ifdef VERBOSE_INIT_ARM
                    737:        printf("init subsystems: stacks ");
                    738: #endif
                    739:
                    740:        set_stackptr(PSR_IRQ32_MODE,
                    741:            irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
                    742:        set_stackptr(PSR_ABT32_MODE,
                    743:            abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
                    744:        set_stackptr(PSR_UND32_MODE,
                    745:            undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
                    746:
                    747:        /*
                    748:         * Well we should set a data abort handler.
                    749:         * Once things get going this will change as we will need a proper
                    750:         * handler.
                    751:         * Until then we will use a handler that just panics but tells us
                    752:         * why.
                    753:         * Initialisation of the vectors will just panic on a data abort.
                    754:         * This just fills in a slightly better one.
                    755:         */
                    756: #ifdef VERBOSE_INIT_ARM
                    757:        printf("vectors ");
                    758: #endif
                    759:        data_abort_handler_address = (u_int)data_abort_handler;
                    760:        prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
                    761:        undefined_handler_address = (u_int)undefinedinstruction_bounce;
                    762:
                    763:        /* Initialise the undefined instruction handlers */
                    764: #ifdef VERBOSE_INIT_ARM
                    765:        printf("undefined ");
                    766: #endif
                    767:        undefined_init();
                    768:
                    769:        /* Load memory into UVM. */
                    770: #ifdef VERBOSE_INIT_ARM
                    771:        printf("page ");
                    772: #endif
                    773:        uvm_setpagesize();      /* initialize PAGE_SIZE-dependent variables */
                    774:        uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
                    775:            atop(physical_freestart), atop(physical_freeend),
                    776:            VM_FREELIST_DEFAULT);
                    777:
                    778:        /* Boot strap pmap telling it where the kernel page table is */
                    779: #ifdef VERBOSE_INIT_ARM
                    780:        printf("pmap ");
                    781: #endif
                    782:        pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
                    783:            KERNEL_VM_BASE + KERNEL_VM_SIZE);
                    784:
                    785:        /* Update dump information */
                    786:        cpu_kcore_hdr.pmap_kernel_l1 = (u_int32_t)pmap_kernel()->pm_l1;
                    787:        cpu_kcore_hdr.pmap_kernel_l2 = (u_int32_t)&(pmap_kernel()->pm_l2);
                    788:
                    789:        cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
                    790:        setttb(kernel_l1pt.pv_pa);
                    791:        cpu_tlb_flushID();
                    792:        cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
                    793:        /* Enable MMU, I-cache, D-cache, write buffer. */
                    794:        cpufunc_control(0x337f, 0x107d);
                    795:
                    796:
                    797:        /* TODO */
                    798:        //cn_tab = NULL;
                    799:        fakecninit(JFB_VBASE);
                    800:
                    801:        /* Setup the IRQ system */
                    802: #ifdef VERBOSE_INIT_ARM
                    803:        printf("irq ");
                    804: #endif
                    805:        //i80321intc_intr_init();
                    806:        sa11x0_init_interrupt_masks();
                    807:
                    808: #ifdef VERBOSE_INIT_ARM
                    809:        printf("done.\n");
                    810: #endif
                    811:
                    812: #ifdef DDB
                    813:        db_machine_init();
                    814:
                    815:        /* Firmware doesn't load symbols. */
                    816:        ddb_init();
                    817:
                    818:        if (boothowto & RB_KDB)
                    819:                Debugger();
                    820: #endif
                    821:
                    822:        /* We return the new stack pointer address */
                    823:        return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
                    824: }
                    825:
                    826: void
                    827: process_kernel_args(char *args)
                    828: {
                    829:        char *cp = args;
                    830:
                    831:        if (cp == NULL || *(int *)cp != BOOT_STRING_MAGIC) {
                    832:                boothowto = RB_AUTOBOOT;
                    833:                return;
                    834:        }
                    835:
                    836:        /* Eat the cookie */
                    837:        *(int *)cp = 0;
                    838:        cp += sizeof(int);
                    839:
                    840:        boothowto = 0;
                    841:
                    842:        /* Make a local copy of the bootargs */
                    843:        strncpy(bootargs, cp, MAX_BOOT_STRING - sizeof(int));
                    844:
                    845:        cp = bootargs;
                    846:        boot_file = bootargs;
                    847:
                    848:        /* Skip the kernel image filename */
                    849:        while (*cp != ' ' && *cp != 0)
                    850:                ++cp;
                    851:
                    852:        if (*cp != 0)
                    853:                *cp++ = 0;
                    854:
                    855:        while (*cp == ' ')
                    856:                ++cp;
                    857:
                    858:        boot_args = cp;
                    859:
                    860: #if 0
                    861:        printf("bootfile: %s\n", boot_file);
                    862:        printf("bootargs: %s\n", boot_args);
                    863: #endif
                    864:
                    865:        /* Setup pointer to boot flags */
                    866:        while (*cp != '-')
                    867:                if (*cp++ == '\0')
                    868:                        return;
                    869:
                    870:        for (;*++cp;) {
                    871:                int fl;
                    872:
                    873:                fl = 0;
                    874:                switch(*cp) {
                    875:                case 'a':
                    876:                        fl |= RB_ASKNAME;
                    877:                        break;
                    878:                case 'c':
                    879:                        fl |= RB_CONFIG;
                    880:                        break;
                    881:                case 'd':
                    882:                        fl |= RB_KDB;
                    883:                        break;
                    884:                case 's':
                    885:                        fl |= RB_SINGLE;
                    886:                        break;
                    887:                default:
                    888:                        printf("unknown option `%c'\n", *cp);
                    889:                        break;
                    890:                }
                    891:                boothowto |= fl;
                    892:        }
                    893: }
                    894:
                    895:
                    896: void
                    897: consinit(void)
                    898: {
                    899: #if 0
                    900: #if NSACOM > 0
                    901:        static const bus_addr_t sacomcnaddrs[] = {
                    902:                SACOM3_HW_BASE
                    903:        };
                    904:
                    905:        static int consinit_called;
                    906:
                    907:        if (consinit_called != 0)
                    908:                return;
                    909:
                    910:        consinit_called = 1;
                    911:
                    912:        /*
                    913:         * Console devices are mapped VA==PA.  Our devmap reflects
                    914:         * this, so register it now so drivers can map the console
                    915:         * device.
                    916:         */
                    917:        pmap_devmap_register(jornada_devmap);
                    918:
                    919:        if (sacomcnattach(&sa11x0_bs_tag, sacomcnaddrs[0], 115200))
                    920:                panic("can't init serial console @%lx", sacomcnaddrs[0]);
                    921: #endif
                    922: #endif /* 0 */
                    923: }
                    924:
                    925: void
                    926: fakecninit(bus_addr_t addr)
                    927: {
                    928:        /*
                    929:         * Early console initialization.
                    930:         */
                    931:        switch(addr) {
                    932:                case SACOM3_HW_BASE:
                    933:                case SACOM3_BASE:
                    934: #if NSACOM > 0
                    935:                        sacomfakecnattach();
                    936: #endif
                    937:                        break;
                    938:                case JFB_BASE:
                    939:                case JFB_VBASE:
                    940: #if NJFB > 0
                    941:                        jfbfakecnattach(addr);
                    942: #endif
                    943:                        break;
                    944:                default:
                    945:                        panic("serial console not configured");
                    946:        }
                    947: }
                    948:
                    949: void
                    950: board_startup(void)
                    951: {
                    952:         if (boothowto & RB_CONFIG) {
                    953: #ifdef BOOT_CONFIG
                    954:                user_config();
                    955: #else
                    956:                printf("kernel does not support -c; continuing..\n");
                    957: #endif
                    958:        }
                    959: }

CVSweb