OpenCores
URL https://opencores.org/ocsvn/c0or1k/c0or1k/trunk

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [src/] [generic/] [bootmem.c] - Blame information for rev 7

Go to most recent revision | Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * Boot memory allocator
3
 *
4
 * Copyright (C) 2009 Bahadir Balban
5
 */
6
 
7
 
8
#include INC_ARCH(linker.h)
9
#include INC_GLUE(memory.h)
10
#include <l4/lib/printk.h>
11
#include <l4/generic/space.h>
12
 
13
/*
14
 * All memory allocated here is discarded after boot.
15
 * Increase this size if bootmem allocations fail.
16
 */
17
#define BOOTMEM_SIZE            (SZ_4K * 4)
18
SECTION(".init.bootmem") char bootmem[BOOTMEM_SIZE];
19
struct address_space init_space;
20
 
21
static unsigned long cursor = (unsigned long)&bootmem;
22
 
23
unsigned long bootmem_free_pages(void)
24
{
25
        return BOOTMEM_SIZE - (page_align_up(cursor) - (unsigned long)&bootmem);
26
}
27
 
28
void *alloc_bootmem(int size, int alignment)
29
{
30
        void *ptr;
31
 
32
        /* If alignment is required */
33
        if (alignment) {
34
                /* And cursor is not aligned */
35
                if (!is_aligned(cursor, alignment))
36
                        /* Align the cursor to alignment */
37
                        cursor = align_up(cursor, alignment);
38
        /* Align to 4 byte by default */
39
        } else if (size >= 4) {
40
                /* And cursor is not aligned */
41
                if (!is_aligned(cursor, 4))
42
                        /* Align the cursor to alignment */
43
                        cursor = align_up(cursor, 4);
44
        }
45
 
46
        /* Allocate from cursor */
47
        ptr = (void *)cursor;
48
 
49
        /* Update cursor */
50
        cursor += size;
51
 
52
        /* Check if cursor is passed bootmem area */
53
        if (cursor >= (unsigned long)&bootmem[BOOTMEM_SIZE]) {
54
                printk("Fatal: Insufficient boot memory.\n");
55
                BUG();
56
        }
57
 
58
        return ptr;
59
}
60
 
61
pmd_table_t *alloc_boot_pmd(void)
62
{
63
        return alloc_bootmem(sizeof(pmd_table_t), sizeof(pmd_table_t));
64
}
65
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.