~ubuntu-branches/ubuntu/trusty/linux-linaro-omap/trusty

« back to all changes in this revision

Viewing changes to lib/genalloc.c

  • Committer: Package Import Robot
  • Author(s): John Rigby, John Rigby
  • Date: 2011-09-26 10:44:23 UTC
  • Revision ID: package-import@ubuntu.com-20110926104423-57i0gl3v99b3lkfg
Tags: 3.0.0-1007.9
[ John Rigby ]

Enable crypto modules and remove crypto-modules from
exclude-module files
LP: #826021

Show diffs side-by-side

added added

removed removed

Lines of Context:
39
39
EXPORT_SYMBOL(gen_pool_create);
40
40
 
41
41
/**
42
 
 * gen_pool_add - add a new chunk of special memory to the pool
 
42
 * gen_pool_add_virt - add a new chunk of special memory to the pool
43
43
 * @pool: pool to add new memory chunk to
44
 
 * @addr: starting address of memory chunk to add to pool
 
44
 * @virt: virtual starting address of memory chunk to add to pool
 
45
 * @phys: physical starting address of memory chunk to add to pool
45
46
 * @size: size in bytes of the memory chunk to add to pool
46
47
 * @nid: node id of the node the chunk structure and bitmap should be
47
48
 *       allocated on, or -1
48
49
 *
49
50
 * Add a new chunk of special memory to the specified pool.
 
51
 *
 
52
 * Returns 0 on success or a -ve errno on failure.
50
53
 */
51
 
int gen_pool_add(struct gen_pool *pool, unsigned long addr, size_t size,
52
 
                 int nid)
 
54
int gen_pool_add_virt(struct gen_pool *pool, unsigned long virt, phys_addr_t phys,
 
55
                 size_t size, int nid)
53
56
{
54
57
        struct gen_pool_chunk *chunk;
55
58
        int nbits = size >> pool->min_alloc_order;
58
61
 
59
62
        chunk = kmalloc_node(nbytes, GFP_KERNEL | __GFP_ZERO, nid);
60
63
        if (unlikely(chunk == NULL))
61
 
                return -1;
 
64
                return -ENOMEM;
62
65
 
63
66
        spin_lock_init(&chunk->lock);
64
 
        chunk->start_addr = addr;
65
 
        chunk->end_addr = addr + size;
 
67
        chunk->phys_addr = phys;
 
68
        chunk->start_addr = virt;
 
69
        chunk->end_addr = virt + size;
66
70
 
67
71
        write_lock(&pool->lock);
68
72
        list_add(&chunk->next_chunk, &pool->chunks);
70
74
 
71
75
        return 0;
72
76
}
73
 
EXPORT_SYMBOL(gen_pool_add);
 
77
EXPORT_SYMBOL(gen_pool_add_virt);
 
78
 
 
79
/**
 
80
 * gen_pool_virt_to_phys - return the physical address of memory
 
81
 * @pool: pool to allocate from
 
82
 * @addr: starting address of memory
 
83
 *
 
84
 * Returns the physical address on success, or -1 on error.
 
85
 */
 
86
phys_addr_t gen_pool_virt_to_phys(struct gen_pool *pool, unsigned long addr)
 
87
{
 
88
        struct list_head *_chunk;
 
89
        struct gen_pool_chunk *chunk;
 
90
 
 
91
        read_lock(&pool->lock);
 
92
        list_for_each(_chunk, &pool->chunks) {
 
93
                chunk = list_entry(_chunk, struct gen_pool_chunk, next_chunk);
 
94
 
 
95
                if (addr >= chunk->start_addr && addr < chunk->end_addr)
 
96
                        return chunk->phys_addr + addr - chunk->start_addr;
 
97
        }
 
98
        read_unlock(&pool->lock);
 
99
 
 
100
        return -1;
 
101
}
 
102
EXPORT_SYMBOL(gen_pool_virt_to_phys);
74
103
 
75
104
/**
76
105
 * gen_pool_destroy - destroy a special memory pool