diff options
author | Simon Glass | 2023-12-27 13:07:00 -0800 |
---|---|---|
committer | Simon Glass | 2023-12-31 07:21:02 -0700 |
commit | 1a2e02f955f98395142415d7c6cc14e4df903969 (patch) | |
tree | 59f3057b5cede46f4dcccf2fa9ecdcea6facf032 /common | |
parent | e748e4b780057872b4a7192db87476adaa8b501c (diff) |
bloblist: Adjust API to align in powers of 2
The updated bloblist structure stores the alignment as a power-of-two
value in its structures. Adjust the API to use this, to avoid needing to
calling ilog2().
Update the bloblist alignment from 16 bytes to 8 bytes.
Drop a stale comment while we are here.
Signed-off-by: Simon Glass <sjg@chromium.org>
Co-developed-by: Raymond Mao <raymond.mao@linaro.org>
Signed-off-by: Raymond Mao <raymond.mao@linaro.org>
Reviewed-by: Simon Glass <sjg@chromium.org>
Reviewed-by: Ilias Apalodimas <ilias.apalodimas@linaro.org>
Diffstat (limited to 'common')
-rw-r--r-- | common/bloblist.c | 24 |
1 files changed, 11 insertions, 13 deletions
diff --git a/common/bloblist.c b/common/bloblist.c index 5606487f5bf..1e78a3d4b3e 100644 --- a/common/bloblist.c +++ b/common/bloblist.c @@ -26,8 +26,6 @@ * start address of the data in each blob is aligned as required. Note that * each blob's *data* is aligned to BLOBLIST_ALIGN regardless of the alignment * of the bloblist itself or the blob header. - * - * So far, only BLOBLIST_ALIGN alignment is supported. */ DECLARE_GLOBAL_DATA_PTR; @@ -128,24 +126,24 @@ static struct bloblist_rec *bloblist_findrec(uint tag) return NULL; } -static int bloblist_addrec(uint tag, int size, int align, +static int bloblist_addrec(uint tag, int size, int align_log2, struct bloblist_rec **recp) { struct bloblist_hdr *hdr = gd->bloblist; struct bloblist_rec *rec; int data_start, new_alloced; - if (!align) - align = BLOBLIST_ALIGN; + if (!align_log2) + align_log2 = BLOBLIST_ALIGN_LOG2; /* Figure out where the new data will start */ 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); + data_start = ALIGN(data_start, 1U << align_log2) - map_to_sysmem(hdr); /* Calculate the new allocated total */ - new_alloced = data_start + ALIGN(size, align); + new_alloced = data_start + ALIGN(size, 1U << align_log2); if (new_alloced > hdr->size) { log_err("Failed to allocate %x bytes size=%x, need size=%x\n", @@ -169,7 +167,7 @@ static int bloblist_addrec(uint tag, int size, int align, } static int bloblist_ensurerec(uint tag, struct bloblist_rec **recp, int size, - int align) + int align_log2) { struct bloblist_rec *rec; @@ -182,7 +180,7 @@ static int bloblist_ensurerec(uint tag, struct bloblist_rec **recp, int size, } else { int ret; - ret = bloblist_addrec(tag, size, align, &rec); + ret = bloblist_addrec(tag, size, align_log2, &rec); if (ret) return ret; } @@ -204,22 +202,22 @@ void *bloblist_find(uint tag, int size) return (void *)rec + rec->hdr_size; } -void *bloblist_add(uint tag, int size, int align) +void *bloblist_add(uint tag, int size, int align_log2) { struct bloblist_rec *rec; - if (bloblist_addrec(tag, size, align, &rec)) + if (bloblist_addrec(tag, size, align_log2, &rec)) return NULL; return (void *)rec + rec->hdr_size; } -int bloblist_ensure_size(uint tag, int size, int align, void **blobp) +int bloblist_ensure_size(uint tag, int size, int align_log2, void **blobp) { struct bloblist_rec *rec; int ret; - ret = bloblist_ensurerec(tag, &rec, size, align); + ret = bloblist_ensurerec(tag, &rec, size, align_log2); if (ret) return ret; *blobp = (void *)rec + rec->hdr_size; |