aboutsummaryrefslogtreecommitdiffstats
path: root/package/network/utils/wwan/files/data/1199-6808
blob: 497aff248d1b05348133e158dcc3e0fe882c881e (plain)
1
2
3
4
5
' href='#n27'>27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370
/*
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 *
 * Copyright (C) IBM Corp. 2005, 2006
 *
 * Authors: Jimi Xenidis <jimix@watson.ibm.com>
 */

#include <xen/config.h>
#include <xen/init.h>
#include <xen/lib.h>
#include <xen/cpumask.h>
#include <xen/sched.h>
#include <xen/multiboot.h>
#include <xen/serial.h>
#include <xen/softirq.h>
#include <xen/console.h>
#include <xen/trace.h>
#include <xen/mm.h>
#include <xen/domain.h>
#include <xen/gdbstub.h>
#include <xen/symbols.h>
#include <xen/keyhandler.h>
#include <acm/acm_hooks.h>
#include <public/version.h>
#include <asm/processor.h>
#include <asm/desc.h>
#include <asm/cache.h>
#include <asm/debugger.h>
#include <asm/delay.h>
#include "exceptions.h"
#include "of-devtree.h"

#define DEBUG
unsigned long xenheap_phys_end;

/* opt_noht: If true, Hyperthreading is ignored. */
int opt_noht = 0;
boolean_param("noht", opt_noht);

int opt_earlygdb = 0;
boolean_param("earlygdb", opt_earlygdb);

u32 tlbflush_clock = 1U;
u32 tlbflush_time[NR_CPUS];

unsigned int watchdog_on;
unsigned long wait_init_idle;
ulong oftree;
ulong oftree_len;

cpumask_t cpu_sibling_map[NR_CPUS] __read_mostly;
cpumask_t cpu_online_map; /* missing ifdef in schedule.c */

/* XXX get this from ISA node in device tree */
ulong isa_io_base;
struct ns16550_defaults ns16550;

extern void idle_loop(void);

/* move us to a header file */
extern void initialize_keytable(void);

int is_kernel_text(unsigned long addr)
{
    if (addr >= (unsigned long) &_start &&
        addr <= (unsigned long) &_etext)
        return 1;
    return 0;
}

unsigned long kernel_text_end(void)
{
    return (unsigned long) &_etext;
}

void idle_loop(void)
{
    int cpu = smp_processor_id();

    for ( ; ; )
    {
        while (!softirq_pending(cpu)) {
            void sleep(void);
            page_scrub_schedule_work();
            sleep();
        }
        do_softirq();
    }
}

static void __init do_initcalls(void)
{
    initcall_t *call;
    for (call = &__initcall_start; call < &__initcall_end; call++) {
        (*call)();
    }
}

static void hw_probe_attn(unsigned char key, struct cpu_user_regs *regs)
{
    /* To continue the probe will step over the ATTN instruction.  The
     * NOP is there to make sure there is something sane to "step
     * over" to. */
    asm volatile(".long 0x00000200; nop");
}

static void __init start_of_day(void)
{
    struct domain *idle_domain;

    init_IRQ();

    scheduler_init();

    /* create idle domain */
    idle_domain = domain_create(IDLE_DOMAIN_ID);
    if ((idle_domain == NULL) || (alloc_vcpu(idle_domain, 0, 0) == NULL))
        BUG();
    set_current(idle_domain->vcpu[0]);
    idle_vcpu[0] = current;

    /* for some reason we need to set our own bit in the thread map */
    cpu_set(0, cpu_sibling_map[0]);

    initialize_keytable();
    /* Register another key that will allow for the the Harware Probe
     * to be contacted, this works with RiscWatch probes and should
     * work with Chronos and FSPs */
    register_irq_keyhandler('^', hw_probe_attn,   "Trap to Hardware Probe");

    timer_init();
    serial_init_postirq();
    do_initcalls();
    schedulers_start();
}

void startup_cpu_idle_loop(void)
{
    struct vcpu *v = current;

    ASSERT(is_idle_vcpu(v));
    cpu_set(smp_processor_id(), v->domain->domain_dirty_cpumask);
    cpu_set(smp_processor_id(), v->vcpu_dirty_cpumask);

    /* Finally get off the boot stack. */
    reset_stack_and_jump(idle_loop);
}

static void __init __start_xen(multiboot_info_t *mbi)
{
    char *cmdline;
    module_t *mod = (module_t *)((ulong)mbi->mods_addr);
    ulong heap_start;
    ulong modules_start, modules_size;
    ulong eomem = 0;
    ulong heap_size = 0;
    ulong bytes = 0;
    ulong freemem = (ulong)_end;
    ulong oftree_end;

    memcpy(0, exception_vectors, exception_vectors_end - exception_vectors);
    synchronize_caches(0, exception_vectors_end - exception_vectors);

    ticks_per_usec = timebase_freq / 1000000ULL;

    /* Parse the command-line options. */
    if ((mbi->flags & MBI_CMDLINE) && (mbi->cmdline != 0))
        cmdline_parse(__va((ulong)mbi->cmdline));

    ns16550_init(0, &ns16550);
    serial_init_preirq();

    init_console();
#ifdef CONSOLE_SYNC
    console_start_sync();
#endif

    /* Check that we have at least one Multiboot module. */
    if (!(mbi->flags & MBI_MODULES) || (mbi->mods_count == 0)) {
        panic("FATAL ERROR: Require at least one Multiboot module.\n");
    }

    if (!(mbi->flags & MBI_MEMMAP)) {
        panic("FATAL ERROR: Bootloader provided no memory information.\n");
    }

    /* mark the begining of images */
    modules_start = mod[0].mod_start;
    modules_size = mod[mbi->mods_count-1].mod_end - mod[0].mod_start;

    /* OF dev tree is the last module */
    oftree = mod[mbi->mods_count-1].mod_start;
    oftree_end = mod[mbi->mods_count-1].mod_end;
    oftree_len = oftree_end - oftree;

    /* remove it from consideration */
    mod[mbi->mods_count-1].mod_start = 0;
    mod[mbi->mods_count-1].mod_end = 0;
    --mbi->mods_count;

    printk("Physical RAM map:\n");

    /* lets find out how much memory there is */
    while (bytes < mbi->mmap_length) {
        u64 end;
        u64 addr;
        u64 size;

        memory_map_t *map = (memory_map_t *)((ulong)mbi->mmap_addr + bytes);
        addr = ((u64)map->base_addr_high << 32) | (u64)map->base_addr_low;
        size = ((u64)map->length_high << 32) | (u64)map->length_low;
        end = addr + size;

        printk(" %016lx - %016lx (usable)\n", addr, end);

        if (addr > eomem) {
            printk("found a hole skipping remainder of memory at:\n"
                   " %016lx and beyond\n", addr);
            break;
        }
        if (end > eomem) {
            eomem = end;
        }
        bytes += map->size + 4;
    }

    printk("System RAM: %luMB (%lukB)\n", eomem >> 20, eomem >> 10);

    max_page = PFN_DOWN(ALIGN_DOWN(eomem, PAGE_SIZE));
    total_pages = max_page;

    /* skip the exception handlers */
    heap_start = init_boot_allocator(4 << PAGE_SHIFT);

    /* move the modules to just after _end */
    if (modules_start) {
        printk("modules at: %016lx - %016lx\n", modules_start,
                modules_start + modules_size);
        freemem = ALIGN_UP(freemem, PAGE_SIZE);
        memmove((void *)freemem, (void *)modules_start, modules_size);

        oftree -= modules_start - freemem;
        modules_start = freemem;
        freemem += modules_size;
        printk("  moved to: %016lx - %016lx\n", modules_start,
                modules_start + modules_size);
    }

#ifdef OF_DEBUG
    printk("ofdump:\n");
    /* make sure the OF devtree is good */
    ofd_walk((void *)oftree, OFD_ROOT, ofd_dump_props, OFD_DUMP_ALL);
#endif

    /* mark all memory from modules onward as unused */
    init_boot_pages(freemem, eomem);

    init_frametable();
    end_boot_allocator();

    /* place the heap from after the allocator bitmap to _start */
    xenheap_phys_end = (ulong)_start;
    init_xenheap_pages(heap_start, xenheap_phys_end);
    heap_size = xenheap_phys_end - heap_start;

    printk("Xen heap: %luMB (%lukB)\n", heap_size >> 20, heap_size >> 10);

    cpu_initialize();

#ifdef CONFIG_GDB
    initialise_gdb();
    if (opt_earlygdb)
        debugger_trap_immediate();
#endif

    start_of_day();

    /* Create initial domain 0. */
    dom0 = domain_create(0);
    if ((dom0 == NULL) || (alloc_vcpu(dom0, 0, 0) == NULL))
        panic("Error creating domain 0\n");

    set_bit(_DOMF_privileged, &dom0->domain_flags);
    /* post-create hooks sets security label */
    acm_post_domain0_create(dom0->domain_id);

    cmdline = (char *)(mod[0].string ? __va((ulong)mod[0].string) : NULL);

    /* scrub_heap_pages() requires IRQs enabled, and we're post IRQ setup... */
    local_irq_enable();
    /* Scrub RAM that is still free and so may go to an unprivileged domain. */
    scrub_heap_pages();

    /*
     * We're going to setup domain0 using the module(s) that we
     * stashed safely above our heap. The second module, if present,
     * is an initrd ramdisk.  The last module is the OF devtree.
     */
    if (construct_dom0(dom0,
                       modules_start, 
                       mod[0].mod_end-mod[0].mod_start,
                       (mbi->mods_count == 1) ? 0 :
                       modules_start + 
                       (mod[1].mod_start-mod[0].mod_start),
                       (mbi->mods_count == 1) ? 0 :
                       mod[mbi->mods_count-1].mod_end - mod[1].mod_start,
                       cmdline) != 0) {
        panic("Could not set up DOM0 guest OS\n");
    }

    init_trace_bufs();

    console_endboot();

    /* Hide UART from DOM0 if we're using it */
    serial_endboot();

    domain_unpause_by_systemcontroller(dom0);

    startup_cpu_idle_loop();
}

void __init __start_xen_ppc(
    ulong r3, ulong r4, ulong r5, ulong r6, ulong r7, ulong orig_msr)
{
    multiboot_info_t *mbi = NULL;

    /* clear bss */
    memset(__bss_start, 0, (ulong)_end - (ulong)__bss_start);

    if (r5 > 0) {
        /* we were booted by OpenFirmware */
        mbi = boot_of_init(r3, r4, r5, r6, r7, orig_msr);

    } else {
        /* booted by someone else that hopefully has a trap handler */
        trap();
    }

    __start_xen(mbi);

}

extern void arch_get_xen_caps(xen_capabilities_info_t info);
void arch_get_xen_caps(xen_capabilities_info_t info)
{
}

/*
 * Local variables:
 * mode: C
 * c-set-style: "BSD"
 * c-basic-offset: 4
 * tab-width: 4
 * indent-tabs-mode: nil
 * End:
 */