From b6e83826ef1f4d04d350e4d2c03e3b28ab1b0ae4 Mon Sep 17 00:00:00 2001 From: Simon Glass Date: Wed, 27 Dec 2023 13:07:07 -0800 Subject: bloblist: Reduce blob-header size The v0.9 spec provides for an 8-byte header for each blob, with fewer fields. The blob data start address should be aligned to the alignment specified by the bloblist header. Update the implementation to match this. Signed-off-by: Simon Glass Co-developed-by: Raymond Mao Signed-off-by: Raymond Mao --- common/bloblist.c | 23 +++++++++++++++-------- 1 file changed, 15 insertions(+), 8 deletions(-) (limited to 'common/bloblist.c') diff --git a/common/bloblist.c b/common/bloblist.c index 73dbbc01c08..1c97d61e4aa 100644 --- a/common/bloblist.c +++ b/common/bloblist.c @@ -87,12 +87,14 @@ static struct bloblist_rec *bloblist_first_blob(struct bloblist_hdr *hdr) static inline uint rec_hdr_size(struct bloblist_rec *rec) { - return rec->hdr_size; + return (rec->tag_and_hdr_size & BLOBLISTR_HDR_SIZE_MASK) >> + BLOBLISTR_HDR_SIZE_SHIFT; } static inline uint rec_tag(struct bloblist_rec *rec) { - return rec->tag; + return (rec->tag_and_hdr_size & BLOBLISTR_TAG_MASK) >> + BLOBLISTR_TAG_SHIFT; } static ulong bloblist_blob_end_ofs(struct bloblist_hdr *hdr, @@ -101,7 +103,13 @@ static ulong bloblist_blob_end_ofs(struct bloblist_hdr *hdr, ulong offset; offset = (void *)rec - (void *)hdr; - offset += rec_hdr_size(rec) + ALIGN(rec->size, BLOBLIST_ALIGN); + /* + * The data section of next TE should start from an address aligned + * to 1 << hdr->align_log2. + */ + offset += rec_hdr_size(rec) + rec->size; + offset = round_up(offset + rec_hdr_size(rec), 1 << hdr->align_log2); + offset -= rec_hdr_size(rec); return offset; } @@ -145,7 +153,7 @@ static int bloblist_addrec(uint tag, int size, int align_log2, int data_start, aligned_start, new_alloced; if (!align_log2) - align_log2 = BLOBLIST_ALIGN_LOG2; + align_log2 = BLOBLIST_BLOB_ALIGN_LOG2; /* Figure out where the new data will start */ data_start = map_to_sysmem(hdr) + hdr->alloced + sizeof(*rec); @@ -178,8 +186,7 @@ static int bloblist_addrec(uint tag, int size, int align_log2, } rec = (void *)hdr + hdr->alloced; - rec->tag = tag; - rec->hdr_size = sizeof(struct bloblist_rec); + rec->tag_and_hdr_size = tag | sizeof(*rec) << BLOBLISTR_HDR_SIZE_SHIFT; rec->size = size; /* Zero the record data */ @@ -283,8 +290,8 @@ static int bloblist_resize_rec(struct bloblist_hdr *hdr, int new_alloced; /* New value for @hdr->alloced */ ulong next_ofs; /* Offset of the record after @rec */ - expand_by = ALIGN(new_size - rec->size, BLOBLIST_ALIGN); - new_alloced = ALIGN(hdr->alloced + expand_by, BLOBLIST_ALIGN); + expand_by = ALIGN(new_size - rec->size, BLOBLIST_BLOB_ALIGN); + new_alloced = ALIGN(hdr->alloced + expand_by, BLOBLIST_BLOB_ALIGN); if (new_size < 0) { log_debug("Attempt to shrink blob size below 0 (%x)\n", new_size); -- cgit v1.2.3