summaryrefslogtreecommitdiffstats
path: root/common
diff options
context:
space:
mode:
authorSascha Hauer <s.hauer@pengutronix.de>2012-05-24 08:52:22 +0200
committerSascha Hauer <s.hauer@pengutronix.de>2012-07-01 08:18:53 +0200
commit5f03074ea98b64b55c133b35ee144fdc909e6d69 (patch)
tree1a61fd84a5a44d98297014486eca663221ff4cbc /common
parent20addb80f65076b3a81c7d778f7b93d445a96841 (diff)
downloadbarebox-5f03074ea98b64b55c133b35ee144fdc909e6d69.tar.gz
resource: store 'end' instead of 'size' in struct resource
Storing the size instead of the resource end in struct resource was a mistake. 'size' ranges from 0 to UINT[32|64]_MAX + 1 which obviously leads to problems. 'end' on the other hand will never exceed UINT[32|64]_MAX. Also this way we can express a iomem region covering the whole address space. Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
Diffstat (limited to 'common')
-rw-r--r--common/memory.c4
-rw-r--r--common/resource.c30
-rw-r--r--common/uimage.c6
3 files changed, 22 insertions, 18 deletions
diff --git a/common/memory.c b/common/memory.c
index 3b4a5ef..f04cfac 100644
--- a/common/memory.c
+++ b/common/memory.c
@@ -122,7 +122,7 @@ void barebox_add_memory_bank(const char *name, resource_size_t start,
struct memory_bank *bank = xzalloc(sizeof(*bank));
struct device_d *dev;
- bank->res = request_iomem_region(name, start, size);
+ bank->res = request_iomem_region(name, start, start + size - 1);
BUG_ON(!bank->res);
@@ -146,7 +146,7 @@ struct resource *request_sdram_region(const char *name, resource_size_t start,
for_each_memory_bank(bank) {
struct resource *res;
- res = request_region(bank->res, name, start, size);
+ res = request_region(bank->res, name, start, start + size - 1);
if (res)
return res;
}
diff --git a/common/resource.c b/common/resource.c
index 63e9c49..ce5aa27 100644
--- a/common/resource.c
+++ b/common/resource.c
@@ -42,16 +42,20 @@ static int init_resource(struct resource *res, const char *name)
*/
struct resource *request_region(struct resource *parent,
const char *name, resource_size_t start,
- resource_size_t size)
+ resource_size_t end)
{
struct resource *r, *new;
+ if (end < start) {
+ debug("%s: request region 0x%08x:0x%08x: end < start\n",
+ __func__, start, end);
+ return NULL;
+ }
+
/* outside parent resource? */
- if (start < parent->start ||
- start + size > parent->start + parent->size) {
+ if (start < parent->start || end > parent->end) {
debug("%s: 0x%08x:0x%08x outside parent resource 0x%08x:0x%08x\n",
- __func__, start, size, parent->start,
- parent->size);
+ __func__, start, end, parent->start, parent->end);
return NULL;
}
@@ -60,22 +64,22 @@ struct resource *request_region(struct resource *parent,
* us searching for conflicts here.
*/
list_for_each_entry(r, &parent->children, sibling) {
- if (start + size <= r->start)
+ if (end < r->start)
goto ok;
- if (start >= r->start + r->size)
+ if (start > r->end)
continue;
debug("%s: 0x%08x:0x%08x conflicts with 0x%08x:0x%08x\n",
- __func__, start, size, r->start, r->size);
+ __func__, start, end, r->start, r->end);
return NULL;
}
ok:
- debug("%s ok: 0x%08x 0x%08x\n", __func__, start, size);
+ debug("%s ok: 0x%08x:0x%08x\n", __func__, start, end);
new = xzalloc(sizeof(*new));
init_resource(new, name);
new->start = start;
- new->size = size;
+ new->end = end;
new->parent = parent;
list_add_tail(&new->sibling, &r->sibling);
@@ -100,16 +104,16 @@ int release_region(struct resource *res)
/* The root resource for the whole io space */
struct resource iomem_resource = {
.start = 0,
- .size = ~0,
+ .end = 0xffffffff,
};
/*
* request a region inside the io space
*/
struct resource *request_iomem_region(const char *name,
- resource_size_t start, resource_size_t size)
+ resource_size_t start, resource_size_t end)
{
- return request_region(&iomem_resource, name, start, size);
+ return request_region(&iomem_resource, name, start, end);
}
static int iomem_init(void)
diff --git a/common/uimage.c b/common/uimage.c
index 945f3d6..43878b5 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -354,9 +354,9 @@ static struct resource *uimage_resource;
static int uimage_sdram_flush(void *buf, unsigned int len)
{
- if (uimage_size + len > uimage_resource->size) {
- resource_size_t start = uimage_resource->start;
- resource_size_t size = uimage_resource->size + len;
+ if (uimage_size + len > resource_size(uimage_resource)) {
+ resource_size_t start = resource_size(uimage_resource);
+ resource_size_t size = resource_size(uimage_resource) + len;
release_sdram_region(uimage_resource);
uimage_resource = request_sdram_region("uimage",