.. | .. |
---|
| 1 | +// SPDX-License-Identifier: GPL-2.0-only |
---|
1 | 2 | /* |
---|
2 | 3 | * Common CPM code |
---|
3 | 4 | * |
---|
.. | .. |
---|
11 | 12 | * Copyright (c) 2000 MontaVista Software, Inc (source@mvista.com) |
---|
12 | 13 | * 2006 (c) MontaVista Software, Inc. |
---|
13 | 14 | * Vitaly Bordug <vbordug@ru.mvista.com> |
---|
14 | | - * |
---|
15 | | - * This program is free software; you can redistribute it and/or modify |
---|
16 | | - * it under the terms of version 2 of the GNU General Public License as |
---|
17 | | - * published by the Free Software Foundation. |
---|
18 | 15 | */ |
---|
19 | 16 | #include <linux/genalloc.h> |
---|
20 | 17 | #include <linux/init.h> |
---|
.. | .. |
---|
35 | 32 | |
---|
36 | 33 | struct muram_block { |
---|
37 | 34 | struct list_head head; |
---|
38 | | - unsigned long start; |
---|
| 35 | + s32 start; |
---|
39 | 36 | int size; |
---|
40 | 37 | }; |
---|
41 | 38 | |
---|
.. | .. |
---|
49 | 46 | { |
---|
50 | 47 | struct device_node *np; |
---|
51 | 48 | struct resource r; |
---|
52 | | - u32 zero[OF_MAX_ADDR_CELLS] = {}; |
---|
| 49 | + __be32 zero[OF_MAX_ADDR_CELLS] = {}; |
---|
53 | 50 | resource_size_t max = 0; |
---|
54 | 51 | int i = 0; |
---|
55 | 52 | int ret = 0; |
---|
.. | .. |
---|
113 | 110 | * @algo: algorithm for alloc. |
---|
114 | 111 | * @data: data for genalloc's algorithm. |
---|
115 | 112 | * |
---|
116 | | - * This function returns an offset into the muram area. |
---|
| 113 | + * This function returns a non-negative offset into the muram area, or |
---|
| 114 | + * a negative errno on failure. |
---|
117 | 115 | */ |
---|
118 | | -static unsigned long cpm_muram_alloc_common(unsigned long size, |
---|
119 | | - genpool_algo_t algo, void *data) |
---|
| 116 | +static s32 cpm_muram_alloc_common(unsigned long size, |
---|
| 117 | + genpool_algo_t algo, void *data) |
---|
120 | 118 | { |
---|
121 | 119 | struct muram_block *entry; |
---|
122 | | - unsigned long start; |
---|
| 120 | + s32 start; |
---|
123 | 121 | |
---|
124 | | - if (!muram_pool && cpm_muram_init()) |
---|
125 | | - goto out2; |
---|
126 | | - |
---|
127 | | - start = gen_pool_alloc_algo(muram_pool, size, algo, data); |
---|
128 | | - if (!start) |
---|
129 | | - goto out2; |
---|
130 | | - start = start - GENPOOL_OFFSET; |
---|
131 | | - memset_io(cpm_muram_addr(start), 0, size); |
---|
132 | 122 | entry = kmalloc(sizeof(*entry), GFP_ATOMIC); |
---|
133 | 123 | if (!entry) |
---|
134 | | - goto out1; |
---|
| 124 | + return -ENOMEM; |
---|
| 125 | + start = gen_pool_alloc_algo(muram_pool, size, algo, data); |
---|
| 126 | + if (!start) { |
---|
| 127 | + kfree(entry); |
---|
| 128 | + return -ENOMEM; |
---|
| 129 | + } |
---|
| 130 | + start = start - GENPOOL_OFFSET; |
---|
| 131 | + memset_io(cpm_muram_addr(start), 0, size); |
---|
135 | 132 | entry->start = start; |
---|
136 | 133 | entry->size = size; |
---|
137 | 134 | list_add(&entry->head, &muram_block_list); |
---|
138 | 135 | |
---|
139 | 136 | return start; |
---|
140 | | -out1: |
---|
141 | | - gen_pool_free(muram_pool, start, size); |
---|
142 | | -out2: |
---|
143 | | - return (unsigned long)-ENOMEM; |
---|
144 | 137 | } |
---|
145 | 138 | |
---|
146 | 139 | /* |
---|
.. | .. |
---|
148 | 141 | * @size: number of bytes to allocate |
---|
149 | 142 | * @align: requested alignment, in bytes |
---|
150 | 143 | * |
---|
151 | | - * This function returns an offset into the muram area. |
---|
| 144 | + * This function returns a non-negative offset into the muram area, or |
---|
| 145 | + * a negative errno on failure. |
---|
152 | 146 | * Use cpm_dpram_addr() to get the virtual address of the area. |
---|
153 | 147 | * Use cpm_muram_free() to free the allocation. |
---|
154 | 148 | */ |
---|
155 | | -unsigned long cpm_muram_alloc(unsigned long size, unsigned long align) |
---|
| 149 | +s32 cpm_muram_alloc(unsigned long size, unsigned long align) |
---|
156 | 150 | { |
---|
157 | | - unsigned long start; |
---|
| 151 | + s32 start; |
---|
158 | 152 | unsigned long flags; |
---|
159 | 153 | struct genpool_data_align muram_pool_data; |
---|
160 | 154 | |
---|
.. | .. |
---|
171 | 165 | * cpm_muram_free - free a chunk of multi-user ram |
---|
172 | 166 | * @offset: The beginning of the chunk as returned by cpm_muram_alloc(). |
---|
173 | 167 | */ |
---|
174 | | -int cpm_muram_free(unsigned long offset) |
---|
| 168 | +void cpm_muram_free(s32 offset) |
---|
175 | 169 | { |
---|
176 | 170 | unsigned long flags; |
---|
177 | 171 | int size; |
---|
178 | 172 | struct muram_block *tmp; |
---|
| 173 | + |
---|
| 174 | + if (offset < 0) |
---|
| 175 | + return; |
---|
179 | 176 | |
---|
180 | 177 | size = 0; |
---|
181 | 178 | spin_lock_irqsave(&cpm_muram_lock, flags); |
---|
.. | .. |
---|
189 | 186 | } |
---|
190 | 187 | gen_pool_free(muram_pool, offset + GENPOOL_OFFSET, size); |
---|
191 | 188 | spin_unlock_irqrestore(&cpm_muram_lock, flags); |
---|
192 | | - return size; |
---|
193 | 189 | } |
---|
194 | 190 | EXPORT_SYMBOL(cpm_muram_free); |
---|
195 | 191 | |
---|
.. | .. |
---|
197 | 193 | * cpm_muram_alloc_fixed - reserve a specific region of multi-user ram |
---|
198 | 194 | * @offset: offset of allocation start address |
---|
199 | 195 | * @size: number of bytes to allocate |
---|
200 | | - * This function returns an offset into the muram area |
---|
| 196 | + * This function returns @offset if the area was available, a negative |
---|
| 197 | + * errno otherwise. |
---|
201 | 198 | * Use cpm_dpram_addr() to get the virtual address of the area. |
---|
202 | 199 | * Use cpm_muram_free() to free the allocation. |
---|
203 | 200 | */ |
---|
204 | | -unsigned long cpm_muram_alloc_fixed(unsigned long offset, unsigned long size) |
---|
| 201 | +s32 cpm_muram_alloc_fixed(unsigned long offset, unsigned long size) |
---|
205 | 202 | { |
---|
206 | | - unsigned long start; |
---|
| 203 | + s32 start; |
---|
207 | 204 | unsigned long flags; |
---|
208 | 205 | struct genpool_data_fixed muram_pool_data_fixed; |
---|
209 | 206 | |
---|