Пример #1
0
/**
 * The server entry point.
 */
void
clock_init(void)
{
    int r = 0;
    void *device;
    okl4_env_segment_t *timer_seg;

    /*
     * Setup resources for driver init - this should probably be weaved
     */
    resources[r].type = MEMORY_RESOURCE;
    timer_seg = okl4_env_get_segment("MAIN_TIMER_MEM0");

    if (timer_seg == NULL) {
        printf("couldn't find timer memory mapping\n");
        return;
    }
    resources[r++].resource.mem = (mem_space_t) timer_seg->virt_addr;

    struct okl4_env_device_irqs * timer_irqs = (struct okl4_env_device_irqs *)okl4_env_get("TIMER_DEV_IRQ_LIST");
    if (timer_irqs == NULL) {
        printf("couldn't find timer irq list\n");
        return;
    }

    /* Nano can only handle one interrupt anyway */
    resources[r].type = INTERRUPT_RESOURCE;
    resources[r++].resource.interrupt = timer_irqs->irqs[0];
    CLOCK_IRQ = timer_irqs->irqs[0];

    for (/*none*/; r < 8; r++)
    {
        resources[r].type = NO_RESOURCE;
    }
    
    /*
     * Allocate memory for the device
     */
    device = malloc(TIMER_DRIVER.size);
    if (device == NULL) {
        free(device);
        return;
    }
   
    /* Initialise the device state */
    {
        timer_device.resources = resources;
    }
    
    /* Create and enable the device */
    timer_device.di = setup_device_instance(&TIMER_DRIVER, device);
    device_setup(timer_device.di, timer_device.resources);
    
    timer_device.ti = (struct timer_interface *)device_get_interface(timer_device.di, 0);
    device_enable(timer_device.di);
    
    timer_device.frequency = timer_get_tick_frequency(timer_device.ti);
}
Пример #2
0
/* Initialise attribute object to default values */
void
okl4_virtmem_pool_attr_init(okl4_virtmem_pool_attr_t * attr)
{
    okl4_virtmem_pool_t * pool = NULL;

    assert(attr != NULL);

    OKL4_SETUP_MAGIC(attr, OKL4_MAGIC_VIRTMEM_POOL_ATTR);
    okl4_allocator_attr_init(&attr->range);
    okl4_allocator_attr_setsize(&attr->range, 0);
    pool = (okl4_virtmem_pool_t *)okl4_env_get("MAIN_VIRTMEM_POOL");
    attr->parent = pool;
}
Пример #3
0
okl4_env_segment_t *
okl4_env_get_segment(const char *name)
{
    okl4_env_segments_t *segment_table;
    okl4_word_t *idx;

    segment_table = OKL4_ENV_GET_SEGMENTS("SEGMENTS");
    idx = okl4_env_get(name);

    if (idx == NULL || segment_table == NULL) {
        return NULL;
    }

    return &segment_table->segments[*idx];
}
Пример #4
0
END_TEST

/**
 * Weaved allocation of the kclist id allocator
 */
START_TEST(KCLISTID0600)
{
    int ret;
    okl4_kclistid_t id;
    okl4_kclistid_pool_t *kclistid_pool = NULL;
    kclistid_pool = okl4_env_get("MAIN_CLIST_ID_POOL");
    assert(kclistid_pool != NULL);
    fail_unless(kclistid_pool != NULL, "couldn't find the weaved kclist id pool");

    ret = okl4_kclistid_allocany(kclistid_pool, &id);
    fail_unless(ret == OKL4_OK, "Failed to allocate any clist id.");

    okl4_kclistid_free(kclistid_pool, id);
}
Пример #5
0
void okl4_env_lookup_address(const char *name, unsigned long *addr)
{
    word_t *seg;
    okl4_env_segments_t *segs;
    int i;

    seg = (word_t *)okl4_env_get(name);
    segs = OKL4_ENV_GET_SEGMENTS("SEGMENTS");
    if (!seg || !segs)
        goto nosegs;
    for (i = 0; i < segs->num_segments; i++) {
        if (segs->segments[i].segment == *seg) {
            *addr = segs->segments[i].virt_addr;
            break;
        }
    }

    if (i == segs->num_segments) {
nosegs:
        panic("Could not find %s", name);
        *addr = 0;
    }
}
Пример #6
0
int
main(void)
{
    int i = 0;
    int res = 1;
    L4_SpaceId_t space;
    okl4_allocator_attr_t attr;
    L4_Word_t end, result;
    L4_CapId_t sender;
    L4_MsgTag_t tag;
    L4_Msg_t msg;
    struct okl4_bitmap_allocator *spaceid_pool = okl4_env_get("MAIN_SPACE_ID_POOL");

    HEAP_EXHAUSTION_CLIST = L4_ClistId(*(OKL4_ENV_GET_MAIN_CLISTID("MAIN_CLIST_ID")));
    while(res == 1)
    {
        result = okl4_kspaceid_allocany(spaceid_pool, &space);
        if (result != OKL4_OK) {
            printf("Failed to allocate space id\n");
        }
        res = create_address_space(space,
                                   L4_Fpage(0xb10000, 0x1000));

        if (res != 1) {
            printf("SpaceControl failed, space id=%lu, Error code: %lu\n", space.space_no, L4_ErrorCode());
            break;
        }
        /* 2gb mapping of 512k pages*/
        res = map_series(space, 0x80000, 4096, 0, 0);
        i++;
    }

    printf("Created %d address spaces\n", i);
    if (i == 0) {
        okl4_kspaceid_free(spaceid_pool, space);
        res = 0;
        goto ipc_ktest;
    }

    /* clean up */
    okl4_kspaceid_getattribute(spaceid_pool, &attr);
    end = attr.base + attr.size;
    for (i = attr.base; i < end; i++)
    {
        L4_SpaceId_t id = L4_SpaceId(i);
        if (okl4_kspaceid_isallocated(spaceid_pool, id))
        {
            L4_SpaceControl(id, L4_SpaceCtrl_delete,
                            HEAP_EXHAUSTION_CLIST, L4_Nilpage, 0, NULL);
            okl4_kspaceid_free(spaceid_pool, id);
        }
    }
    res = 1;

ipc_ktest:
    tag = L4_Wait(&sender);
    L4_MsgClear(&msg);
    L4_MsgAppendWord(&msg, (L4_Word_t)res);
    L4_MsgLoad(&msg);
    L4_Reply(sender);
    assert(L4_IpcSucceeded(tag));

    L4_WaitForever();
}
Пример #7
0
int
main(int argc, char **argv)
{
    int error;
    okl4_word_t i;
    okl4_word_t pings;
    void *stacks[THREADS];
    okl4_kthread_t threads[THREADS];
    okl4_kcap_t caps[THREADS];
    okl4_kthread_t *root_thread;

#if defined(OKL4_KERNEL_MICRO)
    okl4_kclist_t *root_kclist;
    okl4_kspace_t *root_kspace;
    struct okl4_utcb_item *utcb_item[THREADS];
    struct okl4_kcap_item *kcap_item[THREADS];
#endif

    okl4_init_thread();

#if defined(NANOKERNEL)
    {
        okl4_kthread_t _root_thread;
        _root_thread.cap = okn_syscall_thread_myself();
        root_thread = &_root_thread;
    }
#else
    root_kspace = okl4_env_get("MAIN_KSPACE");
    assert(root_kspace != NULL);
    root_thread = root_kspace->kthread_list;
    assert(root_thread != NULL);
    root_kclist = root_kspace->kclist;
    assert(root_kclist != NULL);
#endif

    if (argc == 1)
        pings = atoi(argv[0]);
    else
        pings = 10;
    printf("Ping-Pong will do %d pings\n", (int)pings);

    for (i = 0; i < THREADS; i++)
    {
        okl4_kthread_attr_t kthread_attr;

#if defined(OKL4_KERNEL_MICRO)
        /* Allocate the utcb structure */
        utcb_item[i] = malloc(sizeof(struct okl4_utcb_item));
        assert(utcb_item[i]);

        /* Get any utcb for the thread from the root kspace utcb area */
        // XXX: We need an accessor method for a kspace's utcb_area
        error = okl4_utcb_allocany(root_kspace->utcb_area, utcb_item[i]);
        assert(error == OKL4_OK);

        /* Allocate a cap for the kthread from the root clist */
        kcap_item[i] = malloc(sizeof(struct okl4_kcap_item));
        assert(kcap_item[i]);
        error = okl4_kclist_kcap_allocany(root_kclist, kcap_item[i]);
        assert(error == OKL4_OK);
#endif

        stacks[i] = malloc(STACK_SIZE);
        assert(stacks[i]);

        okl4_kthread_attr_init(&kthread_attr);
        okl4_kthread_attr_setspip(&kthread_attr,
                (okl4_word_t)stacks[i] + STACK_SIZE,
                (okl4_word_t)pingpong);
#if defined(OKL4_KERNEL_MICRO)
        okl4_kthread_attr_setspace(&kthread_attr, root_kspace);
        okl4_kthread_attr_setutcbitem(&kthread_attr, utcb_item[i]);
        okl4_kthread_attr_setcapitem(&kthread_attr, kcap_item[i]);
#endif
        error = okl4_kthread_create(&threads[i], &kthread_attr);
        assert(!error);
        caps[i] = okl4_kthread_getkcap(&threads[i]);
        okl4_kthread_start(&threads[i]);
    }

    // Message child threads to start the ping pong
    for (i = 0; i < THREADS; i++)
    {
        struct args args;
        args.id = i;
        args.parent = okl4_kthread_getkcap(root_thread);
        args.peers = caps;
        args.pings = pings;
        error = okl4_message_send(caps[i], &args, sizeof(args));
        assert(!error);
    }

    // Wait for the child threads to finish
    for (i = 0; i < THREADS; i++)
    {
        okl4_word_t pings_done;
        error = okl4_message_wait(&pings_done, sizeof(pings_done), NULL, NULL);
        assert(!error);
        assert(pings_done == pings);
    }

    /* Delete the thread and free resources. */
    for (i = 0; i < THREADS; i++)
    {
#if defined(OKL4_KERNEL_MICRO)
        okl4_kthread_delete(&threads[i]);
        okl4_kclist_kcap_free(root_kclist, kcap_item[i]);
        free(kcap_item[i]);
        // XXX: We need an accessor method for a kspace's utcb_area
        okl4_utcb_free(root_kspace->utcb_area, utcb_item[i]);
        free(utcb_item[i]);
#else
        okl4_kthread_join(&threads[i]);
#endif
        free(stacks[i]);
    }

    printf("Ping-Pong complete. Exiting...");
    /* Finished */
#if defined(NANOKERNEL)
    okl4_kthread_exit();
#else
    while(1);
#endif
}
Пример #8
0
/*
 * Setup L4 architecture requirements:
 *   kip_area, utcb_area, physical memory, current,
 * Init user address space, ramdisk, console, early consle
 */
void __init
setup_arch (char **command_line)
{
    unsigned long base, area;

#if defined(CONFIG_IGUANA)
    setup_tls(1);
#endif

    /* Return the command line to the rest of the kernel */
    boot_command_line[COMMAND_LINE_SIZE-1] = '\0';
    *command_line = boot_command_line;

    if (L4_UtcbIsKernelManaged()) {
        utcb_area = L4_Nilpage;
    } else {
        /* Currently hardcoded to 1024 L4 threads per linux
         * user address space */
        area = L4_GetUtcbSize() * 1024;

        /*
             * Find some area to put the utcb in outside user's
             * area.  When the KIP was present, 16 pages were
             * reserved for it, so keep the same spacing here
             * because the equation is not fully understood.
             */
        base = PAGE_ALIGN(TASK_SIZE) + 16 * PAGE_SIZE  + area;
        /* Round address to the 'area' boundary. */
        base = (base + (area-1)) & (~(area-1));

        utcb_area = L4_Fpage(base, L4_GetUtcbSize() * 1024);
    }

    /* Initialise our machine name */
    setup_machine_name();

    /* FIXME: (why?) */
    start_phys_mem = __pa(start_phys_mem);
    end_phys_mem = __pa(end_phys_mem);

    /* Initialise paging */
    paging_init();

    /* Thread info setup. */
    /* FIXME:  remember for SMP startup */
    current_tinfo(smp_processor_id()) =
        (unsigned long)&init_thread_union.thread_info;
    task_thread_info(current)->user_tid = L4_nilthread;
    task_thread_info(current)->user_handle = L4_nilthread;

#ifdef CONFIG_EARLY_PRINTK
    /* early console initialisation */
    enable_early_printk();
#endif

    /* Ramdisk setup */
#ifdef CONFIG_BLK_DEV_INITRD
    /* Board specific code should have set up initrd_start and initrd_end */
    ROOT_DEV = Root_RAM0;
    /* FIXME! */
    initrd_start = 0; //naming_lookup("ramdisk");
    initrd_end = 0; //naming_lookup("ramdisk_end");
    printk("end: %lx\n", initrd_end);
    initrd_below_start_ok = 1;

    if (initrd_start) {
        unsigned long initrd_size =
            ((unsigned char *)initrd_end) -
            ((unsigned char *)initrd_start);
        printk("Initial ramdisk at: 0x%p (%lu bytes)\n",
               (void *)initrd_start, initrd_size);
    }
#endif /* CONFIG_BLK_DEV_INITRD  */

#ifdef CONFIG_VT
#if defined(CONFIG_VGA_CONSOLE)
    __setup_vga();
    conswitchp = &vga_con;
#elif defined(CONFIG_DUMMY_CONSOLE)
    conswitchp = &dummy_con;
#endif /* CONFIG_VGA_CONSOLE */
    screen_info.lfb_base	= 0xe000000;
    screen_info.lfb_size	= 600*800;
    screen_info.lfb_height	= 600;
    screen_info.lfb_width	= 800;
#endif /* CONFIG_VT */

    panic_timeout = 1;

#if defined(CONFIG_CELL)
    /* L4-specific -gl,cvs */
    {
        extern unsigned long TIMER_BASE, SERIAL_BASE;
        okl4_env_lookup_address("MAIN_TIMER_MEM0", &TIMER_BASE);
        okl4_env_lookup_address("MAIN_SERIAL_MEM0", &SERIAL_BASE);
    }
#if defined(CONFIG_VERSATILE)
    {
        extern unsigned long ETH_BASE, CLCD_BASE, VERSATILE_SYS_BASE,
               KMI0_BASE, KMI1_BASE;
        okl4_env_lookup_address("MAIN_ETH_MEM0", &ETH_BASE);
        okl4_env_lookup_address("MAIN_VERSATILESYS_MEM0", &VERSATILE_SYS_BASE);
        okl4_env_lookup_address("MAIN_CLCD_MEM0", &CLCD_BASE);
        okl4_env_lookup_address("MAIN_KMI0_MEM0", &KMI0_BASE);
        okl4_env_lookup_address("MAIN_KMI1_MEM0", &KMI1_BASE);
    }
#endif
#if defined(CONFIG_ARCH_GUMSTIX)
    {
        extern unsigned long GPIO_BASE, DMAC_BASE;
        extern unsigned long PXA_CS1_PHYS, PXA_CS1_DMA;
        extern unsigned long PXA_CS2_PHYS, PXA_CS2_DMA;
        okl4_env_lookup_address("MAIN_GPIO_MEM0", &GPIO_BASE);
        okl4_env_lookup_address("MAIN_DMA_MEM0", &DMAC_BASE);
        okl4_env_lookup_address("MAIN_CS_MEM1", &PXA_CS1_PHYS);
        okl4_env_lookup_address("MAIN_CS_MEM2", &PXA_CS2_PHYS);

        PXA_CS1_DMA = *((unsigned long *)okl4_env_get("cs_mem1_physical"));
        PXA_CS2_DMA = *((unsigned long *)okl4_env_get("cs_mem2_physical"));
    }
#endif

#endif	/*CELL*/
}