mirror of
https://xff.cz/git/u-boot/
synced 2025-10-18 08:23:24 +02:00
bloblist: Allow custom alignment for blobs
Some blobs need a larger alignment than the default. For example, ACPI tables often start at a 4KB boundary. Add support for this. Update the size of the test blob to allow these larger records. Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
@@ -83,18 +83,25 @@ static struct bloblist_rec *bloblist_findrec(uint tag)
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static int bloblist_addrec(uint tag, int size, struct bloblist_rec **recp)
|
||||
static int bloblist_addrec(uint tag, int size, int align,
|
||||
struct bloblist_rec **recp)
|
||||
{
|
||||
struct bloblist_hdr *hdr = gd->bloblist;
|
||||
struct bloblist_rec *rec;
|
||||
int data_start, new_alloced;
|
||||
|
||||
if (!align)
|
||||
align = BLOBLIST_ALIGN;
|
||||
|
||||
/* Figure out where the new data will start */
|
||||
data_start = hdr->alloced + sizeof(*rec);
|
||||
data_start = ALIGN(data_start, BLOBLIST_ALIGN);
|
||||
data_start = map_to_sysmem(hdr) + hdr->alloced + sizeof(*rec);
|
||||
|
||||
/* Align the address and then calculate the offset from ->alloced */
|
||||
data_start = ALIGN(data_start, align) - map_to_sysmem(hdr);
|
||||
|
||||
/* Calculate the new allocated total */
|
||||
new_alloced = data_start + ALIGN(size, BLOBLIST_ALIGN);
|
||||
new_alloced = data_start + ALIGN(size, align);
|
||||
|
||||
if (new_alloced >= hdr->size) {
|
||||
log(LOGC_BLOBLIST, LOGL_ERR,
|
||||
"Failed to allocate %x bytes size=%x, need size=%x\n",
|
||||
@@ -117,7 +124,8 @@ static int bloblist_addrec(uint tag, int size, struct bloblist_rec **recp)
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int bloblist_ensurerec(uint tag, struct bloblist_rec **recp, int size)
|
||||
static int bloblist_ensurerec(uint tag, struct bloblist_rec **recp, int size,
|
||||
int align)
|
||||
{
|
||||
struct bloblist_rec *rec;
|
||||
|
||||
@@ -130,7 +138,7 @@ static int bloblist_ensurerec(uint tag, struct bloblist_rec **recp, int size)
|
||||
} else {
|
||||
int ret;
|
||||
|
||||
ret = bloblist_addrec(tag, size, &rec);
|
||||
ret = bloblist_addrec(tag, size, align, &rec);
|
||||
if (ret)
|
||||
return ret;
|
||||
}
|
||||
@@ -152,22 +160,22 @@ void *bloblist_find(uint tag, int size)
|
||||
return (void *)rec + rec->hdr_size;
|
||||
}
|
||||
|
||||
void *bloblist_add(uint tag, int size)
|
||||
void *bloblist_add(uint tag, int size, int align)
|
||||
{
|
||||
struct bloblist_rec *rec;
|
||||
|
||||
if (bloblist_addrec(tag, size, &rec))
|
||||
if (bloblist_addrec(tag, size, align, &rec))
|
||||
return NULL;
|
||||
|
||||
return (void *)rec + rec->hdr_size;
|
||||
}
|
||||
|
||||
int bloblist_ensure_size(uint tag, int size, void **blobp)
|
||||
int bloblist_ensure_size(uint tag, int size, int align, void **blobp)
|
||||
{
|
||||
struct bloblist_rec *rec;
|
||||
int ret;
|
||||
|
||||
ret = bloblist_ensurerec(tag, &rec, size);
|
||||
ret = bloblist_ensurerec(tag, &rec, size, align);
|
||||
if (ret)
|
||||
return ret;
|
||||
*blobp = (void *)rec + rec->hdr_size;
|
||||
@@ -179,7 +187,7 @@ void *bloblist_ensure(uint tag, int size)
|
||||
{
|
||||
struct bloblist_rec *rec;
|
||||
|
||||
if (bloblist_ensurerec(tag, &rec, size))
|
||||
if (bloblist_ensurerec(tag, &rec, size, 0))
|
||||
return NULL;
|
||||
|
||||
return (void *)rec + rec->hdr_size;
|
||||
@@ -190,7 +198,7 @@ int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp)
|
||||
struct bloblist_rec *rec;
|
||||
int ret;
|
||||
|
||||
ret = bloblist_ensurerec(tag, &rec, *sizep);
|
||||
ret = bloblist_ensurerec(tag, &rec, *sizep, 0);
|
||||
if (ret == -ESPIPE)
|
||||
*sizep = rec->size;
|
||||
else if (ret)
|
||||
|
Reference in New Issue
Block a user