diff options
author | Russell King <rmk+kernel@arm.linux.org.uk> | 2010-05-22 18:53:45 -0400 |
---|---|---|
committer | Russell King <rmk+kernel@arm.linux.org.uk> | 2010-07-16 06:06:41 -0400 |
commit | a1af0fbbbaac595b5bdf5495578d8ddbc6c17e6d (patch) | |
tree | 5bfc1ca15beece917020b3b598a90aafb93e42c5 /arch/arm/plat-omap/fb.c | |
parent | 98c672cf1fa2a56f6f43e3f48b1208b83845582c (diff) |
ARM: OMAP: Cleanup OMAP FB SDRAM reservation
The logic in this file is rather convoluted, but essentially:
1. region type 0 is SDRAM
2. referring to the code fragment
if (set_fbmem_region_type(&rg, OMAPFB_MEMTYPE_SDRAM,
sdram_start, sdram_size) < 0 ||
(rg.type != OMAPFB_MEMTYPE_SDRAM))
continue;
- if rg.type is not OMAPFB_MEMTYPE_SDRAM, set_fbmem_region_type()
returns zero immediately (since rg.type is non-zero), and so we
'continue'.
- if rg.type is OMAPFB_MEMTYPE_SDRAM, and rg.paddr is zero,
we fall through.
- if rg.type is OMAPFB_MEMTYPE_SDRAM, and the region lies within
SDRAM, we fall through.
- if rg.type is OMAPFB_MEMTYPE_SDRAM, and the region is not within
SDRAM, we 'continue'.
3. check_fbmem_region seems unnecessary.
- we know rg.type is OMAPFB_MEMTYPE_SDRAM
- we can check rg.size independently
- bootmem_reserve() can check for overlapping reservations itself
- we've already validated that the requested region lies within SDRAM.
4. avoid BUG()ing if the region entry is already set; print an error,
and mark the configuration invalid - at least we'll continue booting
so the error message has a chance of being logged/visible via serial
console.
With these changes in place, it makes the code much easier to understand
and hence easier to convert to LMB.
Signed-off-by: Russell King <rmk+kernel@arm.linux.org.uk>
Diffstat (limited to 'arch/arm/plat-omap/fb.c')
-rw-r--r-- | arch/arm/plat-omap/fb.c | 61 |
1 files changed, 44 insertions, 17 deletions
diff --git a/arch/arm/plat-omap/fb.c b/arch/arm/plat-omap/fb.c index d3eea4f47533..97db493904fa 100644 --- a/arch/arm/plat-omap/fb.c +++ b/arch/arm/plat-omap/fb.c | |||
@@ -171,49 +171,76 @@ static int check_fbmem_region(int region_idx, struct omapfb_mem_region *rg, | |||
171 | return 0; | 171 | return 0; |
172 | } | 172 | } |
173 | 173 | ||
174 | static int valid_sdram(unsigned long addr, unsigned long size) | ||
175 | { | ||
176 | struct bootmem_data *bdata = NODE_DATA(0)->bdata; | ||
177 | unsigned long sdram_start, sdram_end; | ||
178 | |||
179 | sdram_start = bdata->node_min_pfn << PAGE_SHIFT; | ||
180 | sdram_end = bdata->node_low_pfn << PAGE_SHIFT; | ||
181 | |||
182 | return addr >= sdram_start && sdram_end - addr >= size; | ||
183 | } | ||
184 | |||
185 | static int reserve_sdram(unsigned long addr, unsigned long size) | ||
186 | { | ||
187 | return reserve_bootmem(addr, size, BOOTMEM_EXCLUSIVE); | ||
188 | } | ||
189 | |||
174 | /* | 190 | /* |
175 | * Called from map_io. We need to call to this early enough so that we | 191 | * Called from map_io. We need to call to this early enough so that we |
176 | * can reserve the fixed SDRAM regions before VM could get hold of them. | 192 | * can reserve the fixed SDRAM regions before VM could get hold of them. |
177 | */ | 193 | */ |
178 | void __init omapfb_reserve_sdram(void) | 194 | void __init omapfb_reserve_sdram(void) |
179 | { | 195 | { |
180 | struct bootmem_data *bdata; | 196 | unsigned long reserved = 0; |
181 | unsigned long sdram_start, sdram_size; | 197 | int i; |
182 | unsigned long reserved; | ||
183 | int i; | ||
184 | 198 | ||
185 | if (config_invalid) | 199 | if (config_invalid) |
186 | return; | 200 | return; |
187 | 201 | ||
188 | bdata = NODE_DATA(0)->bdata; | ||
189 | sdram_start = bdata->node_min_pfn << PAGE_SHIFT; | ||
190 | sdram_size = (bdata->node_low_pfn << PAGE_SHIFT) - sdram_start; | ||
191 | reserved = 0; | ||
192 | for (i = 0; ; i++) { | 202 | for (i = 0; ; i++) { |
193 | struct omapfb_mem_region rg; | 203 | struct omapfb_mem_region rg; |
194 | 204 | ||
195 | if (get_fbmem_region(i, &rg) < 0) | 205 | if (get_fbmem_region(i, &rg) < 0) |
196 | break; | 206 | break; |
207 | |||
197 | if (i == OMAPFB_PLANE_NUM) { | 208 | if (i == OMAPFB_PLANE_NUM) { |
198 | printk(KERN_ERR | 209 | pr_err("Extraneous FB mem configuration entries\n"); |
199 | "Extraneous FB mem configuration entries\n"); | ||
200 | config_invalid = 1; | 210 | config_invalid = 1; |
201 | return; | 211 | return; |
202 | } | 212 | } |
213 | |||
203 | /* Check if it's our memory type. */ | 214 | /* Check if it's our memory type. */ |
204 | if (set_fbmem_region_type(&rg, OMAPFB_MEMTYPE_SDRAM, | 215 | if (rg.type != OMAPFB_MEMTYPE_SDRAM) |
205 | sdram_start, sdram_size) < 0 || | ||
206 | (rg.type != OMAPFB_MEMTYPE_SDRAM)) | ||
207 | continue; | 216 | continue; |
208 | BUG_ON(omapfb_config.mem_desc.region[i].size); | 217 | |
209 | if (check_fbmem_region(i, &rg, sdram_start, sdram_size) < 0) { | 218 | /* Check if the region falls within SDRAM */ |
219 | if (rg.paddr && !valid_sdram(rg.paddr, rg.size)) | ||
220 | continue; | ||
221 | |||
222 | if (rg.size == 0) { | ||
223 | pr_err("Zero size for FB region %d\n", i); | ||
210 | config_invalid = 1; | 224 | config_invalid = 1; |
211 | return; | 225 | return; |
212 | } | 226 | } |
227 | |||
213 | if (rg.paddr) { | 228 | if (rg.paddr) { |
214 | reserve_bootmem(rg.paddr, rg.size, BOOTMEM_DEFAULT); | 229 | if (reserve_sdram(rg.paddr, rg.size)) { |
230 | pr_err("Trying to use reserved memory for FB region %d\n", | ||
231 | i); | ||
232 | config_invalid = 1; | ||
233 | return; | ||
234 | } | ||
215 | reserved += rg.size; | 235 | reserved += rg.size; |
216 | } | 236 | } |
237 | |||
238 | if (omapfb_config.mem_desc.region[i].size) { | ||
239 | pr_err("FB region %d already set\n", i); | ||
240 | config_invalid = 1; | ||
241 | return; | ||
242 | } | ||
243 | |||
217 | omapfb_config.mem_desc.region[i] = rg; | 244 | omapfb_config.mem_desc.region[i] = rg; |
218 | configured_regions++; | 245 | configured_regions++; |
219 | } | 246 | } |