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

Subversion Repositories c0or1k

[/] [c0or1k/] [trunk/] [conts/] [posix/] [mm0/] [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 <lib/bit.h>
8
#include <l4/macros.h>
9
#include <l4/types.h>
10
#include INC_GLUE(memory.h)
11
#include <lib/addr.h>
12
#include <stdio.h>
13
 
14
/*
15
 * Initializes an address pool, but uses an already
16
 * allocated id pool for it.
17
 */
18
int address_pool_init_with_idpool(struct address_pool *pool,
19
                                  struct id_pool *idpool,
20
                                  unsigned long start, unsigned long end)
21
{
22
        pool->idpool = idpool;
23
        pool->start = start;
24
        pool->end = end;
25
 
26
        return 0;
27
}
28
 
29
int address_pool_init(struct address_pool *pool, unsigned long start, unsigned long end)
30
{
31
        if ((pool->idpool = id_pool_new_init(__pfn(end - start))) < 0)
32
                return (int)pool->idpool;
33
        pool->start = start;
34
        pool->end = end;
35
        return 0;
36
}
37
 
38
void *address_new(struct address_pool *pool, int npages)
39
{
40
        unsigned int pfn;
41
 
42
        if ((int)(pfn = ids_new_contiguous(pool->idpool, npages)) < 0)
43
                return 0;
44
 
45
        return (void *)__pfn_to_addr(pfn) + pool->start;
46
}
47
 
48
int address_del(struct address_pool *pool, void *addr, int npages)
49
{
50
        unsigned long pfn = __pfn(page_align(addr) - pool->start);
51
 
52
        if (ids_del_contiguous(pool->idpool, pfn, npages) < 0) {
53
                printf("%s: Invalid address range returned to "
54
                       "virtual address pool.\n", __FUNCTION__);
55
                return -1;
56
        }
57
        return 0;
58
}
59
 

powered by: WebSVN 2.1.0

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