[BACK]Return to tsarm_machdep.c CVS log [TXT][DIR] Up to [cvs.NetBSD.org] / src / sys / arch / evbarm / tsarm

Annotation of src/sys/arch/evbarm/tsarm/tsarm_machdep.c, Revision 1.3.4.1

1.3.4.1 ! rpaulo      1: /*     $NetBSD: tsarm_machdep.c,v 1.4 2006/05/17 04:22:46 mrg Exp $    */
1.1       joff        2:
                      3: /*
                      4:  * Copyright (c) 2001, 2002, 2003 Wasabi Systems, Inc.
                      5:  * All rights reserved.
                      6:  *
                      7:  * Based on code written by Jason R. Thorpe and Steve C. Woodford for
                      8:  * 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 Iyonix.
                     73:  */
                     74:
                     75: #include <sys/cdefs.h>
1.3.4.1 ! rpaulo     76: __KERNEL_RCSID(0, "$NetBSD: tsarm_machdep.c,v 1.4 2006/05/17 04:22:46 mrg Exp $");
1.1       joff       77:
                     78: #include "opt_ddb.h"
                     79: #include "opt_kgdb.h"
                     80: #include "opt_pmap_debug.h"
                     81:
                     82: #include <sys/param.h>
                     83: #include <sys/device.h>
                     84: #include <sys/systm.h>
                     85: #include <sys/kernel.h>
                     86: #include <sys/exec.h>
                     87: #include <sys/proc.h>
                     88: #include <sys/msgbuf.h>
                     89: #include <sys/reboot.h>
                     90: #include <sys/termios.h>
                     91: #include <sys/ksyms.h>
                     92:
                     93: #include <uvm/uvm_extern.h>
                     94:
                     95: #include <dev/cons.h>
                     96:
                     97: #include <machine/db_machdep.h>
                     98: #include <ddb/db_sym.h>
                     99: #include <ddb/db_extern.h>
                    100:
                    101: #include <acorn32/include/bootconfig.h>
                    102: #include <machine/bus.h>
                    103: #include <machine/cpu.h>
                    104: #include <machine/frame.h>
                    105: #include <arm/undefined.h>
                    106:
                    107: #include <arm/arm32/machdep.h>
                    108:
                    109: #include <arm/ep93xx/ep93xxreg.h>
                    110: #include <arm/ep93xx/ep93xxvar.h>
                    111:
                    112: #include <dev/ic/comreg.h>
                    113: #include <dev/ic/comvar.h>
                    114:
                    115: #include "epcom.h"
                    116: #if NEPCOM > 0
                    117: #include <arm/ep93xx/epcomvar.h>
                    118: #endif
                    119:
                    120: #include "isa.h"
                    121: #if NISA > 0
                    122: #include <dev/isa/isareg.h>
                    123: #include <dev/isa/isavar.h>
                    124: #endif
                    125:
                    126: #include <machine/isa_machdep.h>
                    127:
                    128: #include <evbarm/tsarm/tsarmreg.h>
                    129:
                    130: #include "opt_ipkdb.h"
                    131: #include "ksyms.h"
                    132:
                    133: /* Kernel text starts 2MB in from the bottom of the kernel address space. */
                    134: #define        KERNEL_TEXT_BASE        (KERNEL_BASE + 0x00200000)
                    135: #define        KERNEL_VM_BASE          (KERNEL_BASE + 0x01000000)
                    136:
                    137: /*
                    138:  * The range 0xc1000000 - 0xccffffff is available for kernel VM space
                    139:  * Core-logic registers and I/O mappings occupy 0xf0000000 - 0xffffffff
                    140:  */
                    141: #define KERNEL_VM_SIZE         0x0C000000
                    142:
                    143: /*
                    144:  * Address to call from cpu_reset() to reset the machine.
                    145:  * This is machine architecture dependant as it varies depending
                    146:  * on where the ROM appears when you turn the MMU off.
                    147:  */
                    148:
                    149: u_int cpu_reset_address = 0x00000000;
                    150:
                    151: /* Define various stack sizes in pages */
                    152: #define IRQ_STACK_SIZE 8
                    153: #define ABT_STACK_SIZE 8
                    154: #ifdef IPKDB
                    155: #define UND_STACK_SIZE 16
                    156: #else
                    157: #define UND_STACK_SIZE 8
                    158: #endif
                    159:
                    160: struct bootconfig bootconfig;          /* Boot config storage */
                    161: char *boot_args = NULL;
                    162: char *boot_file = NULL;
                    163:
                    164: vm_offset_t physical_start;
                    165: vm_offset_t physical_freestart;
                    166: vm_offset_t physical_freeend;
                    167: vm_offset_t physical_freeend_low;
                    168: vm_offset_t physical_end;
                    169: u_int free_pages;
                    170: int physmem = 0;
                    171:
                    172: /* Physical and virtual addresses for some global pages */
                    173: pv_addr_t systempage;
                    174: pv_addr_t irqstack;
                    175: pv_addr_t undstack;
                    176: pv_addr_t abtstack;
                    177: pv_addr_t kernelstack;
                    178:
                    179: vm_offset_t msgbufphys;
                    180:
                    181: static struct arm32_dma_range tsarm_dma_ranges[4];
                    182:
                    183: #if NISA > 0
                    184: extern void isa_tsarm_init(u_int, u_int);
                    185: #endif
                    186:
                    187: extern u_int data_abort_handler_address;
                    188: extern u_int prefetch_abort_handler_address;
                    189: extern u_int undefined_handler_address;
                    190:
                    191: #ifdef PMAP_DEBUG
                    192: extern int pmap_debug_level;
                    193: #endif
                    194:
                    195: #define KERNEL_PT_SYS          0       /* L2 table for mapping vectors page */
                    196:
                    197: #define KERNEL_PT_KERNEL       1       /* L2 table for mapping kernel */
                    198: #define        KERNEL_PT_KERNEL_NUM    4
                    199:                                        /* L2 tables for mapping kernel VM */
                    200: #define KERNEL_PT_VMDATA       (KERNEL_PT_KERNEL + KERNEL_PT_KERNEL_NUM)
                    201:
                    202: #define        KERNEL_PT_VMDATA_NUM    4       /* start with 16MB of KVM */
                    203: #define NUM_KERNEL_PTS         (KERNEL_PT_VMDATA + KERNEL_PT_VMDATA_NUM)
                    204:
                    205: pv_addr_t kernel_pt_table[NUM_KERNEL_PTS];
                    206:
                    207: struct user *proc0paddr;
                    208:
                    209: /* Prototypes */
                    210:
                    211: void   consinit(void);
                    212: /*
                    213:  * Define the default console speed for the machine.
                    214:  */
                    215: #ifndef CONSPEED
                    216: #define CONSPEED B115200
                    217: #endif /* ! CONSPEED */
                    218:
                    219: #ifndef CONMODE
                    220: #define CONMODE ((TTYDEF_CFLAG & ~(CSIZE | CSTOPB | PARENB)) | CS8) /* 8N1 */
                    221: #endif
                    222:
                    223: int comcnspeed = CONSPEED;
                    224: int comcnmode = CONMODE;
                    225:
                    226: #if KGDB
                    227: #ifndef KGDB_DEVNAME
                    228: #error Must define KGDB_DEVNAME
                    229: #endif
                    230: const char kgdb_devname[] = KGDB_DEVNAME;
                    231:
                    232: #ifndef KGDB_DEVADDR
                    233: #error Must define KGDB_DEVADDR
                    234: #endif
                    235: unsigned long kgdb_devaddr = KGDB_DEVADDR;
                    236:
                    237: #ifndef KGDB_DEVRATE
                    238: #define KGDB_DEVRATE   CONSPEED
                    239: #endif
                    240: int kgdb_devrate = KGDB_DEVRATE;
                    241:
                    242: #ifndef KGDB_DEVMODE
                    243: #define KGDB_DEVMODE   CONMODE
                    244: #endif
                    245: int kgdb_devmode = KGDB_DEVMODE;
                    246: #endif /* KGDB */
                    247:
                    248: /*
                    249:  * void cpu_reboot(int howto, char *bootstr)
                    250:  *
                    251:  * Reboots the system
                    252:  *
                    253:  * Deal with any syncing, unmounting, dumping and shutdown hooks,
                    254:  * then reset the CPU.
                    255:  */
                    256: void
                    257: cpu_reboot(int howto, char *bootstr)
                    258: {
                    259:
                    260:        /*
                    261:         * If we are still cold then hit the air brakes
                    262:         * and crash to earth fast
                    263:         */
                    264:        if (cold) {
                    265:                doshutdownhooks();
                    266:                printf("\r\n");
                    267:                printf("The operating system has halted.\r\n");
                    268:                printf("Please press any key to reboot.\r\n");
                    269:                cngetc();
                    270:                printf("\r\nrebooting...\r\n");
                    271:                goto reset;
                    272:        }
                    273:
                    274:        /* Disable console buffering */
                    275:
                    276:        /*
                    277:         * If RB_NOSYNC was not specified sync the discs.
                    278:         * Note: Unless cold is set to 1 here, syslogd will die during the
                    279:         * unmount.  It looks like syslogd is getting woken up only to find
                    280:         * that it cannot page part of the binary in as the filesystem has
                    281:         * been unmounted.
                    282:         */
                    283:        if (!(howto & RB_NOSYNC))
                    284:                bootsync();
                    285:
                    286:        /* Say NO to interrupts */
                    287:        splhigh();
                    288:
                    289:        /* Do a dump if requested. */
                    290:        if ((howto & (RB_DUMP | RB_HALT)) == RB_DUMP)
                    291:                dumpsys();
                    292:
                    293:        /* Run any shutdown hooks */
                    294:        doshutdownhooks();
                    295:
                    296:        /* Make sure IRQ's are disabled */
                    297:        IRQdisable;
                    298:
                    299:        if (howto & RB_HALT) {
                    300:                printf("\r\n");
                    301:                printf("The operating system has halted.\r\n");
                    302:                printf("Please press any key to reboot.\r\n");
                    303:                cngetc();
                    304:        }
                    305:
                    306:        printf("\r\nrebooting...\r\n");
                    307:  reset:
                    308:        /*
                    309:         * Make really really sure that all interrupts are disabled,
                    310:         * and poke the Internal Bus and Peripheral Bus reset lines.
                    311:         */
                    312:        (void) disable_interrupts(I32_bit|F32_bit);
                    313:
                    314:        {
                    315:                u_int32_t feed, ctrl;
                    316:
                    317:                feed = TS7XXX_IO16_VBASE + TS7XXX_WDOGFEED;
                    318:                ctrl = TS7XXX_IO16_VBASE + TS7XXX_WDOGCTRL;
                    319:
1.3       perry     320:                __asm volatile (
1.1       joff      321:                        "mov r0, #0x5\n"
                    322:                        "mov r1, #0x1\n"
                    323:                        "strh r0, [%0]\n"
                    324:                        "strh r1, [%1]\n"
                    325:                        :
                    326:                        : "r" (feed), "r" (ctrl)
                    327:                        : "r0", "r1"
                    328:                );
                    329:        }
                    330:
                    331:        for (;;);
                    332: }
                    333:
                    334: /* Static device mappings. */
                    335: static const struct pmap_devmap tsarm_devmap[] = {
                    336:     {
                    337:        EP93XX_AHB_VBASE,
                    338:        EP93XX_AHB_HWBASE,
                    339:        EP93XX_AHB_SIZE,
                    340:        VM_PROT_READ|VM_PROT_WRITE,
                    341:        PTE_NOCACHE,
                    342:     },
                    343:
                    344:     {
                    345:        EP93XX_APB_VBASE,
                    346:        EP93XX_APB_HWBASE,
                    347:        EP93XX_APB_SIZE,
                    348:        VM_PROT_READ|VM_PROT_WRITE,
                    349:        PTE_NOCACHE,
                    350:     },
                    351:
                    352:        /*
                    353:         * IO8 and IO16 space *must* be mapped contiguously with
                    354:         * IO8_VA == IO16_VA - 64 Mbytes.  ISA busmap driver depends
                    355:         * on that!
                    356:         */
                    357:     {
                    358:        TS7XXX_IO8_VBASE,
                    359:        TS7XXX_IO8_HWBASE,
                    360:        TS7XXX_IO8_SIZE,
                    361:        VM_PROT_READ|VM_PROT_WRITE,
                    362:        PTE_NOCACHE,
                    363:     },
                    364:
                    365:     {
                    366:        TS7XXX_IO16_VBASE,
                    367:        TS7XXX_IO16_HWBASE,
                    368:        TS7XXX_IO16_SIZE,
                    369:        VM_PROT_READ|VM_PROT_WRITE,
                    370:        PTE_NOCACHE,
                    371:     },
                    372:
                    373:    {
                    374:        0,
                    375:        0,
                    376:        0,
                    377:        0,
                    378:        0,
                    379:     }
                    380: };
                    381:
                    382: /*
                    383:  * u_int initarm(...)
                    384:  *
                    385:  * Initial entry point on startup. This gets called before main() is
                    386:  * entered.
                    387:  * It should be responsible for setting up everything that must be
                    388:  * in place when main is called.
                    389:  * This includes
                    390:  *   Taking a copy of the boot configuration structure.
                    391:  *   Initialising the physical console so characters can be printed.
                    392:  *   Setting up page tables for the kernel
                    393:  *   Initialising interrupt controllers to a sane default state
                    394:  */
                    395: u_int
                    396: initarm(void *arg)
                    397: {
                    398: #ifdef FIXME
                    399:        struct bootconfig *passed_bootconfig = arg;
                    400:        extern char _end[];
                    401: #endif
                    402:        int loop;
                    403:        int loop1;
                    404:        u_int l1pagetable;
                    405:        pv_addr_t kernel_l1pt;
                    406:        paddr_t memstart;
                    407:        psize_t memsize;
                    408:
                    409: #ifdef FIXME
                    410:        /* Calibrate the delay loop. */
                    411:        i80321_calibrate_delay();
                    412: #endif
                    413:
                    414:        /*
                    415:         * Since we map the on-board devices VA==PA, and the kernel
                    416:         * is running VA==PA, it's possible for us to initialize
                    417:         * the console now.
                    418:         */
                    419:        consinit();
                    420:
                    421: #ifdef VERBOSE_INIT_ARM
                    422:        /* Talk to the user */
                    423:        printf("\nNetBSD/tsarm booting ...\n");
                    424: #endif
                    425:
                    426:        /*
                    427:         * Heads up ... Setup the CPU / MMU / TLB functions
                    428:         */
                    429:        if (set_cpufuncs())
                    430:                panic("cpu not recognized!");
                    431:
                    432:        /*
                    433:         * We are currently running with the MMU enabled
                    434:         */
                    435:
                    436: #ifdef FIXME
                    437:        /*
                    438:         * Fetch the SDRAM start/size from the i80321 SDRAM configuration
                    439:         * registers.
                    440:         */
                    441:        i80321_sdram_bounds(&obio_bs_tag, VERDE_PMMR_BASE + VERDE_MCU_BASE,
                    442:            &memstart, &memsize);
                    443: #else
                    444:        memstart = 0x0;
                    445:        memsize = 0x2000000;
                    446: #endif
                    447:
                    448: #ifdef VERBOSE_INIT_ARM
                    449:        printf("initarm: Configuring system ...\n");
                    450: #endif
                    451:
                    452:        /* Fake bootconfig structure for the benefit of pmap.c */
                    453:        /* XXX must make the memory description h/w independant */
                    454:        bootconfig.dramblocks = 4;
                    455:        bootconfig.dram[0].address = 0x0UL;
                    456:        bootconfig.dram[0].pages = 0x800000UL / PAGE_SIZE;
                    457:        bootconfig.dram[1].address = 0x1000000UL;
                    458:        bootconfig.dram[1].pages = 0x800000UL / PAGE_SIZE;
                    459:        bootconfig.dram[2].address = 0x4000000UL;
                    460:        bootconfig.dram[2].pages = 0x800000UL / PAGE_SIZE;
                    461:        bootconfig.dram[3].address = 0x5000000UL;
                    462:        bootconfig.dram[3].pages = 0x800000UL / PAGE_SIZE;
                    463:
                    464:        /*
                    465:         * Set up the variables that define the availablilty of
                    466:         * physical memory.  For now, we're going to set
                    467:         * physical_freestart to 0x00200000 (where the kernel
                    468:         * was loaded), and allocate the memory we need downwards.
                    469:         * If we get too close to the L1 table that we set up, we
                    470:         * will panic.  We will update physical_freestart and
                    471:         * physical_freeend later to reflect what pmap_bootstrap()
                    472:         * wants to see.
                    473:         *
                    474:         * XXX pmap_bootstrap() needs an enema.
                    475:         */
                    476:        physical_start = bootconfig.dram[0].address;
                    477:        physical_end = bootconfig.dram[0].address +
                    478:                (bootconfig.dram[0].pages * PAGE_SIZE);
                    479:
                    480:        physical_freestart = 0x00009000UL;
                    481:        physical_freeend = 0x00200000UL;
                    482:
                    483:        physmem = (physical_end - physical_start) / PAGE_SIZE;
                    484:
                    485: #ifdef VERBOSE_INIT_ARM
                    486:        /* Tell the user about the memory */
                    487:        printf("physmemory: %d pages at 0x%08lx -> 0x%08lx\n", physmem,
                    488:            physical_start, physical_end - 1);
                    489: #endif
                    490:
                    491:        /*
                    492:         * Okay, the kernel starts 2MB in from the bottom of physical
                    493:         * memory.  We are going to allocate our bootstrap pages downwards
                    494:         * from there.
                    495:         *
                    496:         * We need to allocate some fixed page tables to get the kernel
                    497:         * going.  We allocate one page directory and a number of page
                    498:         * tables and store the physical addresses in the kernel_pt_table
                    499:         * array.
                    500:         *
                    501:         * The kernel page directory must be on a 16K boundary.  The page
                    502:         * tables must be on 4K bounaries.  What we do is allocate the
                    503:         * page directory on the first 16K boundary that we encounter, and
                    504:         * the page tables on 4K boundaries otherwise.  Since we allocate
                    505:         * at least 3 L2 page tables, we are guaranteed to encounter at
                    506:         * least one 16K aligned region.
                    507:         */
                    508:
                    509: #ifdef VERBOSE_INIT_ARM
                    510:        printf("Allocating page tables\n");
                    511: #endif
                    512:
                    513:        free_pages = (physical_freeend - physical_freestart) / PAGE_SIZE;
                    514:
                    515: #ifdef VERBOSE_INIT_ARM
                    516:        printf("freestart = 0x%08lx, free_pages = %d (0x%08x)\n",
                    517:               physical_freestart, free_pages, free_pages);
                    518: #endif
                    519:
                    520:        /* Define a macro to simplify memory allocation */
                    521: #define        valloc_pages(var, np)                           \
                    522:        alloc_pages((var).pv_pa, (np));                 \
                    523:        (var).pv_va = KERNEL_BASE + (var).pv_pa - physical_start;
                    524:
                    525: #define alloc_pages(var, np)                           \
                    526:        physical_freeend -= ((np) * PAGE_SIZE);         \
                    527:        if (physical_freeend < physical_freestart)      \
                    528:                panic("initarm: out of memory");        \
                    529:        (var) = physical_freeend;                       \
                    530:        free_pages -= (np);                             \
                    531:        memset((char *)(var), 0, ((np) * PAGE_SIZE));
                    532:
                    533:        loop1 = 0;
                    534:        kernel_l1pt.pv_pa = 0;
1.3.4.1 ! rpaulo    535:        kernel_l1pt.pv_va = 0;
1.1       joff      536:        for (loop = 0; loop <= NUM_KERNEL_PTS; ++loop) {
                    537:                /* Are we 16KB aligned for an L1 ? */
                    538:                if (((physical_freeend - L1_TABLE_SIZE) & (L1_TABLE_SIZE - 1)) == 0
                    539:                    && kernel_l1pt.pv_pa == 0) {
                    540:                        valloc_pages(kernel_l1pt, L1_TABLE_SIZE / PAGE_SIZE);
                    541:                } else {
                    542:                        valloc_pages(kernel_pt_table[loop1],
                    543:                            L2_TABLE_SIZE / PAGE_SIZE);
                    544:                        ++loop1;
                    545:                }
                    546:        }
                    547:
                    548:        /* This should never be able to happen but better confirm that. */
                    549:        if (!kernel_l1pt.pv_pa || (kernel_l1pt.pv_pa & (L1_TABLE_SIZE-1)) != 0)
                    550:                panic("initarm: Failed to align the kernel page directory");
                    551:
                    552:        /*
                    553:         * Allocate a page for the system vectors page
                    554:         */
                    555:        alloc_pages(systempage.pv_pa, 1);
                    556:
                    557:        /* Allocate stacks for all modes */
                    558:        valloc_pages(irqstack, IRQ_STACK_SIZE);
                    559:        valloc_pages(abtstack, ABT_STACK_SIZE);
                    560:        valloc_pages(undstack, UND_STACK_SIZE);
                    561:        valloc_pages(kernelstack, UPAGES);
                    562:
                    563: #ifdef VERBOSE_INIT_ARM
                    564:        printf("IRQ stack: p0x%08lx v0x%08lx\n", irqstack.pv_pa,
                    565:            irqstack.pv_va);
                    566:        printf("ABT stack: p0x%08lx v0x%08lx\n", abtstack.pv_pa,
                    567:            abtstack.pv_va);
                    568:        printf("UND stack: p0x%08lx v0x%08lx\n", undstack.pv_pa,
                    569:            undstack.pv_va);
                    570:        printf("SVC stack: p0x%08lx v0x%08lx\n", kernelstack.pv_pa,
                    571:            kernelstack.pv_va);
                    572: #endif
                    573:
                    574:        alloc_pages(msgbufphys, round_page(MSGBUFSIZE) / PAGE_SIZE);
                    575:
                    576:        /*
                    577:         * Ok we have allocated physical pages for the primary kernel
                    578:         * page tables.  Save physical_freeend for when we give whats left
                    579:         * of memory below 2Mbyte to UVM.
                    580:         */
                    581:
                    582:        physical_freeend_low = physical_freeend;
                    583:
                    584: #ifdef VERBOSE_INIT_ARM
                    585:        printf("Creating L1 page table at 0x%08lx\n", kernel_l1pt.pv_pa);
                    586: #endif
                    587:
                    588:        /*
                    589:         * Now we start construction of the L1 page table
                    590:         * We start by mapping the L2 page tables into the L1.
                    591:         * This means that we can replace L1 mappings later on if necessary
                    592:         */
                    593:        l1pagetable = kernel_l1pt.pv_pa;
                    594:
                    595:        /* Map the L2 pages tables in the L1 page table */
                    596:        pmap_link_l2pt(l1pagetable, ARM_VECTORS_HIGH & ~(0x00400000 - 1),
                    597:            &kernel_pt_table[KERNEL_PT_SYS]);
                    598:        for (loop = 0; loop < KERNEL_PT_KERNEL_NUM; loop++)
                    599:                pmap_link_l2pt(l1pagetable, KERNEL_BASE + loop * 0x00400000,
                    600:                    &kernel_pt_table[KERNEL_PT_KERNEL + loop]);
                    601:        for (loop = 0; loop < KERNEL_PT_VMDATA_NUM; loop++)
                    602:                pmap_link_l2pt(l1pagetable, KERNEL_VM_BASE + loop * 0x00400000,
                    603:                    &kernel_pt_table[KERNEL_PT_VMDATA + loop]);
                    604:
                    605:        /* update the top of the kernel VM */
                    606:        pmap_curmaxkvaddr =
                    607:            KERNEL_VM_BASE + (KERNEL_PT_VMDATA_NUM * 0x00400000);
                    608:
                    609: #ifdef VERBOSE_INIT_ARM
                    610:        printf("Mapping kernel\n");
                    611: #endif
                    612:
                    613:        /* Now we fill in the L2 pagetable for the kernel static code/data */
                    614:        {
                    615:                extern char etext[], _end[];
                    616:                size_t textsize = (uintptr_t) etext - KERNEL_TEXT_BASE;
                    617:                size_t totalsize = (uintptr_t) _end - KERNEL_TEXT_BASE;
                    618:                u_int logical;
                    619:
                    620:                textsize = (textsize + PGOFSET) & ~PGOFSET;
                    621:                totalsize = (totalsize + PGOFSET) & ~PGOFSET;
                    622:
                    623:                logical = 0x00200000;   /* offset of kernel in RAM */
                    624:                logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
                    625:                    physical_start + logical, textsize,
                    626:                    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
                    627:                logical += pmap_map_chunk(l1pagetable, KERNEL_BASE + logical,
                    628:                    physical_start + logical, totalsize - textsize,
                    629:                    VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
                    630:        }
                    631:
                    632: #ifdef VERBOSE_INIT_ARM
                    633:        printf("Constructing L2 page tables\n");
                    634: #endif
                    635:
                    636:        /* Map the stack pages */
                    637:        pmap_map_chunk(l1pagetable, irqstack.pv_va, irqstack.pv_pa,
                    638:            IRQ_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
                    639:        pmap_map_chunk(l1pagetable, abtstack.pv_va, abtstack.pv_pa,
                    640:            ABT_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
                    641:        pmap_map_chunk(l1pagetable, undstack.pv_va, undstack.pv_pa,
                    642:            UND_STACK_SIZE * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
                    643:        pmap_map_chunk(l1pagetable, kernelstack.pv_va, kernelstack.pv_pa,
                    644:            UPAGES * PAGE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
                    645:
                    646:        pmap_map_chunk(l1pagetable, kernel_l1pt.pv_va, kernel_l1pt.pv_pa,
                    647:            L1_TABLE_SIZE, VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
                    648:
                    649:        for (loop = 0; loop < NUM_KERNEL_PTS; ++loop) {
                    650:                pmap_map_chunk(l1pagetable, kernel_pt_table[loop].pv_va,
                    651:                    kernel_pt_table[loop].pv_pa, L2_TABLE_SIZE,
                    652:                    VM_PROT_READ|VM_PROT_WRITE, PTE_PAGETABLE);
                    653:        }
                    654:
                    655:        /* Map the vector page. */
                    656:        pmap_map_entry(l1pagetable, ARM_VECTORS_HIGH, systempage.pv_pa,
                    657:            VM_PROT_READ|VM_PROT_WRITE, PTE_CACHE);
                    658:
                    659:        /* Map the statically mapped devices. */
                    660:        pmap_devmap_bootstrap(l1pagetable, tsarm_devmap);
                    661:
                    662:        /*
                    663:         * Update the physical_freestart/physical_freeend/free_pages
                    664:         * variables.
                    665:         */
                    666:        {
                    667:                extern char _end[];
                    668:
                    669:                physical_freestart = physical_start +
                    670:                    (((((uintptr_t) _end) + PGOFSET) & ~PGOFSET) -
                    671:                     KERNEL_BASE);
                    672:                physical_freeend = physical_end;
                    673:                free_pages =
                    674:                    (physical_freeend - physical_freestart) / PAGE_SIZE;
                    675:        }
                    676:
                    677:        /*
                    678:         * Now we have the real page tables in place so we can switch to them.
                    679:         * Once this is done we will be running with the REAL kernel page
                    680:         * tables.
                    681:         */
                    682:
                    683:        /* Switch tables */
                    684: #ifdef VERBOSE_INIT_ARM
                    685:        printf("freestart = 0x%08lx, free_pages = %d (0x%x)\n",
                    686:               physical_freestart, free_pages, free_pages);
                    687:        printf("switching to new L1 page table  @%#lx...", kernel_l1pt.pv_pa);
                    688: #endif
                    689:        cpu_domains((DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2)) | DOMAIN_CLIENT);
                    690:        setttb(kernel_l1pt.pv_pa);
                    691:        cpu_tlb_flushID();
                    692:        cpu_domains(DOMAIN_CLIENT << (PMAP_DOMAIN_KERNEL*2));
                    693:
                    694:        /*
                    695:         * Moved from cpu_startup() as data_abort_handler() references
                    696:         * this during uvm init
                    697:         */
                    698:        proc0paddr = (struct user *)kernelstack.pv_va;
                    699:        lwp0.l_addr = proc0paddr;
                    700:
                    701: #ifdef VERBOSE_INIT_ARM
                    702:        printf("done!\n");
                    703: #endif
                    704:
                    705: #ifdef VERBOSE_INIT_ARM
                    706:        printf("bootstrap done.\n");
                    707: #endif
                    708:
                    709:        arm32_vector_init(ARM_VECTORS_HIGH, ARM_VEC_ALL);
                    710:
                    711:        /*
                    712:         * Pages were allocated during the secondary bootstrap for the
                    713:         * stacks for different CPU modes.
                    714:         * We must now set the r13 registers in the different CPU modes to
                    715:         * point to these stacks.
                    716:         * Since the ARM stacks use STMFD etc. we must set r13 to the top end
                    717:         * of the stack memory.
                    718:         */
                    719: #ifdef VERBOSE_INIT_ARM
                    720:        printf("init subsystems: stacks ");
                    721: #endif
                    722:
                    723:        set_stackptr(PSR_IRQ32_MODE,
                    724:            irqstack.pv_va + IRQ_STACK_SIZE * PAGE_SIZE);
                    725:        set_stackptr(PSR_ABT32_MODE,
                    726:            abtstack.pv_va + ABT_STACK_SIZE * PAGE_SIZE);
                    727:        set_stackptr(PSR_UND32_MODE,
                    728:            undstack.pv_va + UND_STACK_SIZE * PAGE_SIZE);
                    729:
                    730:        /*
                    731:         * Well we should set a data abort handler.
                    732:         * Once things get going this will change as we will need a proper
                    733:         * handler.
                    734:         * Until then we will use a handler that just panics but tells us
                    735:         * why.
                    736:         * Initialisation of the vectors will just panic on a data abort.
                    737:         * This just fills in a slightly better one.
                    738:         */
                    739: #ifdef VERBOSE_INIT_ARM
                    740:        printf("vectors ");
                    741: #endif
                    742:        data_abort_handler_address = (u_int)data_abort_handler;
                    743:        prefetch_abort_handler_address = (u_int)prefetch_abort_handler;
                    744:        undefined_handler_address = (u_int)undefinedinstruction_bounce;
                    745:
                    746:        /* Initialise the undefined instruction handlers */
                    747: #ifdef VERBOSE_INIT_ARM
                    748:        printf("undefined ");
                    749: #endif
                    750:        undefined_init();
                    751:
                    752:        /* Load memory into UVM. */
                    753: #ifdef VERBOSE_INIT_ARM
                    754:        printf("page ");
                    755: #endif
                    756:        uvm_setpagesize();      /* initialize PAGE_SIZE-dependent variables */
                    757:        uvm_page_physload(atop(physical_freestart), atop(physical_freeend),
                    758:            atop(physical_freestart), atop(physical_freeend),
                    759:            VM_FREELIST_DEFAULT);
                    760:        uvm_page_physload(0, atop(physical_freeend_low),
                    761:            0, atop(physical_freeend_low),
                    762:            VM_FREELIST_DEFAULT);
                    763:        /*
                    764:         * There is 32 Mb of memory on the TS-7200 in 4 8Mb chunks, so far
                    765:         * we've only been working with the first one mapped at 0x0.  Tell
                    766:         * UVM about the others.
                    767:         */
                    768:        uvm_page_physload(atop(0x1000000), atop(0x1800000),
                    769:            atop(0x1000000), atop(0x1800000),
                    770:            VM_FREELIST_DEFAULT);
                    771:        uvm_page_physload(atop(0x4000000), atop(0x4800000),
                    772:            atop(0x4000000), atop(0x4800000),
                    773:            VM_FREELIST_DEFAULT);
                    774:        uvm_page_physload(atop(0x5000000), atop(0x5800000),
                    775:            atop(0x5000000), atop(0x5800000),
                    776:            VM_FREELIST_DEFAULT);
                    777:
                    778:        physmem = 0x2000000 / PAGE_SIZE;
                    779:
                    780:
                    781:        /* Boot strap pmap telling it where the kernel page table is */
                    782: #ifdef VERBOSE_INIT_ARM
                    783:        printf("pmap ");
                    784: #endif
                    785:        pmap_bootstrap((pd_entry_t *)kernel_l1pt.pv_va, KERNEL_VM_BASE,
                    786:            KERNEL_VM_BASE + KERNEL_VM_SIZE);
                    787:
                    788:        /* Setup the IRQ system */
                    789: #ifdef VERBOSE_INIT_ARM
                    790:        printf("irq ");
                    791: #endif
                    792:        ep93xx_intr_init();
                    793: #if NISA > 0
                    794:        isa_intr_init();
                    795:
                    796: #ifdef VERBOSE_INIT_ARM
                    797:        printf("isa ");
                    798: #endif
                    799:        isa_tsarm_init(TS7XXX_IO16_VBASE + TS7XXX_ISAIO,
                    800:                TS7XXX_IO16_VBASE + TS7XXX_ISAMEM);
                    801: #endif
                    802:
                    803: #ifdef VERBOSE_INIT_ARM
                    804:        printf("done.\n");
                    805: #endif
                    806:
                    807: #ifdef BOOTHOWTO
                    808:        boothowto = BOOTHOWTO;
                    809: #endif
                    810:
                    811: #ifdef IPKDB
                    812:        /* Initialise ipkdb */
                    813:        ipkdb_init();
                    814:        if (boothowto & RB_KDB)
                    815:                ipkdb_connect(0);
                    816: #endif
                    817:
                    818: #if NKSYMS || defined(DDB) || defined(LKM)
                    819:        /* Firmware doesn't load symbols. */
                    820:        ksyms_init(0, NULL, NULL);
                    821: #endif
                    822:
                    823: #ifdef DDB
                    824:        db_machine_init();
                    825:        if (boothowto & RB_KDB)
                    826:                Debugger();
                    827: #endif
                    828:
                    829:        /* We return the new stack pointer address */
                    830:        return(kernelstack.pv_va + USPACE_SVC_STACK_TOP);
                    831: }
                    832:
                    833: void
                    834: consinit(void)
                    835: {
                    836:        static int consinit_called;
                    837:        bus_space_handle_t ioh;
                    838:
                    839:        if (consinit_called != 0)
                    840:                return;
                    841:
                    842:        consinit_called = 1;
                    843:
                    844:        /*
                    845:         * Console devices are already mapped in VA.  Our devmap reflects
                    846:         * this, so register it now so drivers can map the console
                    847:         * device.
                    848:         */
                    849:        pmap_devmap_register(tsarm_devmap);
                    850: #if 0
                    851:        isa_tsarm_init(TS7XXX_IO16_VBASE + TS7XXX_ISAIO,
                    852:                TS7XXX_IO16_VBASE + TS7XXX_ISAMEM);
                    853:
                    854:         if (comcnattach(&isa_io_bs_tag, 0x3e8, comcnspeed,
                    855:             COM_FREQ, COM_TYPE_NORMAL, comcnmode))
                    856:         {
                    857:                 panic("can't init serial console");
                    858:         }
                    859: #endif
                    860:
                    861: #if NEPCOM > 0
                    862:        bus_space_map(&ep93xx_bs_tag, EP93XX_APB_HWBASE + EP93XX_APB_UART1,
                    863:                EP93XX_APB_UART_SIZE, 0, &ioh);
                    864:         if (epcomcnattach(&ep93xx_bs_tag, EP93XX_APB_HWBASE + EP93XX_APB_UART1,
                    865:                ioh, comcnspeed, comcnmode))
                    866:        {
                    867:                panic("can't init serial console");
                    868:        }
                    869: #else
                    870:        panic("serial console not configured");
                    871: #endif
                    872: #if KGDB
                    873: #if NEPCOM > 0
                    874:        if (strcmp(kgdb_devname, "epcom") == 0) {
                    875:                com_kgdb_attach(&ep93xx_bs_tag, kgdb_devaddr, kgdb_devrate,
                    876:                        kgdb_devmode);
                    877:        }
                    878: #endif /* NEPCOM > 0 */
                    879: #endif /* KGDB */
                    880: }
                    881:
                    882:
                    883: bus_dma_tag_t
                    884: ep93xx_bus_dma_init(struct arm32_bus_dma_tag *dma_tag_template)
                    885: {
                    886:        int i;
                    887:        struct arm32_bus_dma_tag *dmat;
                    888:
                    889:        for (i = 0; i < bootconfig.dramblocks; i++) {
                    890:                tsarm_dma_ranges[i].dr_sysbase = bootconfig.dram[i].address;
                    891:                tsarm_dma_ranges[i].dr_busbase = bootconfig.dram[i].address;
                    892:                tsarm_dma_ranges[i].dr_len = bootconfig.dram[i].pages *
                    893:                        PAGE_SIZE;
                    894:        }
                    895:
                    896:        dmat = dma_tag_template;
                    897:
                    898:        dmat->_ranges = tsarm_dma_ranges;
                    899:        dmat->_nranges = bootconfig.dramblocks;
                    900:
                    901:        return dmat;
                    902: }

CVSweb <webmaster@jp.NetBSD.org>