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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [libl4/] [src/] [lib/] [addr.c] - Blame information for rev 2

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 2 drasko
/*
2
 * This module allocates an unused address range from
3
 * a given memory region defined as the pool range.
4
 *
5
 * Copyright (C) 2007 Bahadir Balban
6
 */
7
#include <l4lib/lib/addr.h>
8
#include <stdio.h>
9
 
10
/*
11
 * Initializes an address pool, but uses an already
12
 * allocated id pool for it.
13
 */
14
int address_pool_init(struct address_pool *pool,
15
                      struct id_pool *idpool,
16
                      unsigned long start, unsigned long end)
17
{
18
        pool->idpool = idpool;
19
        pool->start = start;
20
        pool->end = end;
21
 
22
        id_pool_init(idpool, __pfn(end - start));
23
 
24
        return 0;
25
}
26
 
27
/*
28
 * Allocates an id pool and initializes it
29
 */
30
int address_pool_alloc_init(struct address_pool *pool,
31
                            unsigned long start, unsigned long end,
32
                             unsigned int size)
33
{
34
        if ((pool->idpool = id_pool_new_init(__pfn(end - start) )) < 0)
35
                return (int)pool->idpool;
36
        pool->start = start;
37
        pool->end = end;
38
        return 0;
39
}
40
 
41
void *address_new(struct address_pool *pool, int nitems, int size)
42
{
43
        unsigned int idx;
44
 
45
        if ((int)(idx = ids_new_contiguous(pool->idpool, nitems)) < 0)
46
                return 0;
47
 
48
        return (void *)(idx * size) + pool->start;
49
}
50
 
51
int address_del(struct address_pool *pool, void *addr, int nitems, int size)
52
{
53
        unsigned long idx = (addr - (void *)pool->start) / size;
54
 
55
        if (ids_del_contiguous(pool->idpool, idx, nitems) < 0) {
56
                printf("%s: Invalid address range returned to "
57
                       "virtual address pool.\n", __FUNCTION__);
58
                return -1;
59
        }
60
        return 0;
61
}
62
 

powered by: WebSVN 2.1.0

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