From: Russell King - ARM Linux <linux@arm.linux.org.uk>
To: linux-arm-kernel@lists.infradead.org, Tony Lindgren <tony@atomide.com>
Cc: linux-omap@vger.kernel.org
Subject: Re: [RFC] Initial attempt to make ARM use LMB
Date: Sat, 22 May 2010 22:58:48 +0100 [thread overview]
Message-ID: <20100522215848.GB29889@n2100.arm.linux.org.uk> (raw)
In-Reply-To: <20100325233248.GM24984@n2100.arm.linux.org.uk>
I'm going to take a slightly different approach to LMB given the
(unique) problems that OMAP has with converting over to LMB. I've
been re-ordering my patchset so that we do as many changes as
possible to sanitize the code before introducing LMB.
So, below is a patch to sanitize the code in arch/arm/plat-omap/fb.c.
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. I suggest this should be validated
well before the next merge window.
I'm sure with the SDRAM code simplified like this, the SRAM code can be
cleaned up and some of the complex helper functions killed off.
diff --git a/arch/arm/plat-omap/fb.c b/arch/arm/plat-omap/fb.c
index d3eea4f..97db493 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,
return 0;
}
+static int valid_sdram(unsigned long addr, unsigned long size)
+{
+ struct bootmem_data *bdata = NODE_DATA(0)->bdata;
+ unsigned long sdram_start, sdram_end;
+
+ sdram_start = bdata->node_min_pfn << PAGE_SHIFT;
+ sdram_end = bdata->node_low_pfn << PAGE_SHIFT;
+
+ return addr >= sdram_start && sdram_end - addr >= size;
+}
+
+static int reserve_sdram(unsigned long addr, unsigned long size)
+{
+ return reserve_bootmem(addr, size, BOOTMEM_EXCLUSIVE);
+}
+
/*
* Called from map_io. We need to call to this early enough so that we
* can reserve the fixed SDRAM regions before VM could get hold of them.
*/
void __init omapfb_reserve_sdram(void)
{
- struct bootmem_data *bdata;
- unsigned long sdram_start, sdram_size;
- unsigned long reserved;
- int i;
+ unsigned long reserved = 0;
+ int i;
if (config_invalid)
return;
- bdata = NODE_DATA(0)->bdata;
- sdram_start = bdata->node_min_pfn << PAGE_SHIFT;
- sdram_size = (bdata->node_low_pfn << PAGE_SHIFT) - sdram_start;
- reserved = 0;
for (i = 0; ; i++) {
- struct omapfb_mem_region rg;
+ struct omapfb_mem_region rg;
if (get_fbmem_region(i, &rg) < 0)
break;
+
if (i == OMAPFB_PLANE_NUM) {
- printk(KERN_ERR
- "Extraneous FB mem configuration entries\n");
+ pr_err("Extraneous FB mem configuration entries\n");
config_invalid = 1;
return;
}
+
/* Check if it's our memory type. */
- if (set_fbmem_region_type(&rg, OMAPFB_MEMTYPE_SDRAM,
- sdram_start, sdram_size) < 0 ||
- (rg.type != OMAPFB_MEMTYPE_SDRAM))
+ if (rg.type != OMAPFB_MEMTYPE_SDRAM)
continue;
- BUG_ON(omapfb_config.mem_desc.region[i].size);
- if (check_fbmem_region(i, &rg, sdram_start, sdram_size) < 0) {
+
+ /* Check if the region falls within SDRAM */
+ if (rg.paddr && !valid_sdram(rg.paddr, rg.size))
+ continue;
+
+ if (rg.size == 0) {
+ pr_err("Zero size for FB region %d\n", i);
config_invalid = 1;
return;
}
+
if (rg.paddr) {
- reserve_bootmem(rg.paddr, rg.size, BOOTMEM_DEFAULT);
+ if (reserve_sdram(rg.paddr, rg.size)) {
+ pr_err("Trying to use reserved memory for FB region %d\n",
+ i);
+ config_invalid = 1;
+ return;
+ }
reserved += rg.size;
}
+
+ if (omapfb_config.mem_desc.region[i].size) {
+ pr_err("FB region %d already set\n", i);
+ config_invalid = 1;
+ return;
+ }
+
omapfb_config.mem_desc.region[i] = rg;
configured_regions++;
}
next prev parent reply other threads:[~2010-05-22 21:59 UTC|newest]
Thread overview: 40+ messages / expand[flat|nested] mbox.gz Atom feed top
2010-03-25 23:32 [RFC] Initial attempt to make ARM use LMB Russell King - ARM Linux
2010-03-31 6:43 ` Jeremy Kerr
2010-04-01 9:47 ` Tony Lindgren
2010-04-09 11:13 ` Russell King - ARM Linux
2010-04-08 15:32 ` Rabin Vincent
2010-04-08 18:27 ` Russell King - ARM Linux
2010-04-09 11:11 ` Russell King - ARM Linux
2010-04-10 3:42 ` Rabin Vincent
2010-04-10 7:03 ` Russell King - ARM Linux
2010-04-10 11:56 ` Rabin Vincent
2010-04-14 7:34 ` Benjamin Herrenschmidt
2010-05-05 15:02 ` Russell King - ARM Linux
2010-05-13 17:40 ` Russell King - ARM Linux
2010-05-13 21:19 ` Tony Lindgren
2010-05-13 21:58 ` Russell King - ARM Linux
2010-05-13 22:01 ` Tony Lindgren
2010-05-13 22:12 ` Russell King - ARM Linux
2010-05-14 7:24 ` Shilimkar, Santosh
2010-05-14 10:11 ` Grazvydas Ignotas
2010-05-14 10:16 ` Russell King - ARM Linux
2010-05-17 9:38 ` Grazvydas Ignotas
2010-05-17 9:44 ` Russell King - ARM Linux
2010-05-17 10:26 ` Tomi Valkeinen
2010-05-17 17:37 ` Tony Lindgren
2010-05-18 7:47 ` Tomi Valkeinen
2010-05-18 8:40 ` Russell King - ARM Linux
2010-05-18 8:58 ` Tomi Valkeinen
2010-05-14 15:22 ` Tony Lindgren
2010-05-14 15:32 ` Shilimkar, Santosh
2010-05-14 15:43 ` Tony Lindgren
2010-05-22 21:58 ` Russell King - ARM Linux [this message]
2010-05-26 0:44 ` Tony Lindgren
2010-05-26 7:50 ` Russell King - ARM Linux
2010-05-26 13:51 ` Tony Lindgren
2010-05-26 21:40 ` Russell King - ARM Linux
2010-05-27 8:52 ` Tomi Valkeinen
2010-05-27 9:25 ` Russell King - ARM Linux
2010-05-27 9:47 ` Tomi Valkeinen
2010-05-28 14:32 ` Russell King - ARM Linux
2010-05-31 8:04 ` Tony Lindgren
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20100522215848.GB29889@n2100.arm.linux.org.uk \
--to=linux@arm.linux.org.uk \
--cc=linux-arm-kernel@lists.infradead.org \
--cc=linux-omap@vger.kernel.org \
--cc=tony@atomide.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).