U-Boot Archive on lore.kernel.org
 help / color / mirror / Atom feed
From: Simon Glass <sjg@chromium.org>
To: U-Boot Mailing List <u-boot@lists.denx.de>
Cc: Ilias Apalodimas <ilias.apalodimas@linaro.org>,
	Tom Rini <trini@konsulko.com>,
	Julius Werner <jwerner@chromium.org>,
	Dan Handley <dan.handley@arm.com>,
	Jose Marinho <jose.marinho@arm.com>,
	Simon Glass <sjg@chromium.org>, Bin Meng <bmeng.cn@gmail.com>,
	Nikhil M Jain <n-jain1@ti.com>
Subject: [PATCH 05/14] bloblist: Access record hdr_size and tag via a function
Date: Tue, 25 Jul 2023 15:36:17 -0600	[thread overview]
Message-ID: <20230725213634.255345-6-sjg@chromium.org> (raw)
In-Reply-To: <20230725213634.255345-1-sjg@chromium.org>

These values currently use a simple field. With spec v0.9 they have moved
to a packed format. Convert most accesses to use functions, so this change
can be accomodated.

Signed-off-by: Simon Glass <sjg@chromium.org>
---

 common/bloblist.c | 38 +++++++++++++++++++++++++-------------
 1 file changed, 25 insertions(+), 13 deletions(-)

diff --git a/common/bloblist.c b/common/bloblist.c
index b9332c03ca7..0def7fc9b2f 100644
--- a/common/bloblist.c
+++ b/common/bloblist.c
@@ -73,13 +73,23 @@ static struct bloblist_rec *bloblist_first_blob(struct bloblist_hdr *hdr)
 	return (struct bloblist_rec *)((void *)hdr + hdr->hdr_size);
 }
 
+static inline uint rec_hdr_size(struct bloblist_rec *rec)
+{
+	return rec->hdr_size;
+}
+
+static inline uint rec_tag(struct bloblist_rec *rec)
+{
+	return rec->tag;
+}
+
 static ulong bloblist_blob_end_ofs(struct bloblist_hdr *hdr,
 				   struct bloblist_rec *rec)
 {
 	ulong offset;
 
 	offset = (void *)rec - (void *)hdr;
-	offset += rec->hdr_size + ALIGN(rec->size, BLOBLIST_ALIGN);
+	offset += rec_hdr_size(rec) + ALIGN(rec->size, BLOBLIST_ALIGN);
 
 	return offset;
 }
@@ -108,7 +118,7 @@ static struct bloblist_rec *bloblist_findrec(uint tag)
 		return NULL;
 
 	foreach_rec(rec, hdr) {
-		if (rec->tag == tag)
+		if (rec_tag(rec) == tag)
 			return rec;
 	}
 
@@ -147,7 +157,7 @@ static int bloblist_addrec(uint tag, int size, int align_log2,
 	rec->spare = 0;
 
 	/* Zero the record data */
-	memset((void *)rec + rec->hdr_size, '\0', rec->size);
+	memset((void *)rec + rec_hdr_size(rec), '\0', rec->size);
 
 	hdr->alloced = new_alloced;
 	*recp = rec;
@@ -188,7 +198,7 @@ void *bloblist_find(uint tag, int size)
 	if (size && size != rec->size)
 		return NULL;
 
-	return (void *)rec + rec->hdr_size;
+	return (void *)rec + rec_hdr_size(rec);
 }
 
 void *bloblist_add(uint tag, int size, int align_log2)
@@ -198,7 +208,7 @@ void *bloblist_add(uint tag, int size, int align_log2)
 	if (bloblist_addrec(tag, size, align_log2, &rec))
 		return NULL;
 
-	return (void *)rec + rec->hdr_size;
+	return (void *)rec + rec_hdr_size(rec);
 }
 
 int bloblist_ensure_size(uint tag, int size, int align_log2, void **blobp)
@@ -209,7 +219,7 @@ int bloblist_ensure_size(uint tag, int size, int align_log2, void **blobp)
 	ret = bloblist_ensurerec(tag, &rec, size, align_log2);
 	if (ret)
 		return ret;
-	*blobp = (void *)rec + rec->hdr_size;
+	*blobp = (void *)rec + rec_hdr_size(rec);
 
 	return 0;
 }
@@ -221,7 +231,7 @@ void *bloblist_ensure(uint tag, int size)
 	if (bloblist_ensurerec(tag, &rec, size, 0))
 		return NULL;
 
-	return (void *)rec + rec->hdr_size;
+	return (void *)rec + rec_hdr_size(rec);
 }
 
 int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp)
@@ -234,7 +244,7 @@ int bloblist_ensure_size_ret(uint tag, int *sizep, void **blobp)
 		*sizep = rec->size;
 	else if (ret)
 		return ret;
-	*blobp = (void *)rec + rec->hdr_size;
+	*blobp = (void *)rec + rec_hdr_size(rec);
 
 	return 0;
 }
@@ -270,7 +280,7 @@ static int bloblist_resize_rec(struct bloblist_hdr *hdr,
 
 	/* Zero the new part of the blob */
 	if (expand_by > 0) {
-		memset((void *)rec + rec->hdr_size + rec->size, '\0',
+		memset((void *)rec + rec_hdr_size(rec) + rec->size, '\0',
 		       new_size - rec->size);
 	}
 
@@ -304,8 +314,9 @@ static u32 bloblist_calc_chksum(struct bloblist_hdr *hdr)
 	chksum = crc32(0, (unsigned char *)hdr,
 		       offsetof(struct bloblist_hdr, chksum));
 	foreach_rec(rec, hdr) {
-		chksum = crc32(chksum, (void *)rec, rec->hdr_size);
-		chksum = crc32(chksum, (void *)rec + rec->hdr_size, rec->size);
+		chksum = crc32(chksum, (void *)rec, rec_hdr_size(rec));
+		chksum = crc32(chksum, (void *)rec + rec_hdr_size(rec),
+			       rec->size);
 	}
 
 	return chksum;
@@ -413,8 +424,9 @@ void bloblist_show_list(void)
 	for (rec = bloblist_first_blob(hdr); rec;
 	     rec = bloblist_next_blob(hdr, rec)) {
 		printf("%08lx  %8x  %4x %s\n",
-		       (ulong)map_to_sysmem((void *)rec + rec->hdr_size),
-		       rec->size, rec->tag, bloblist_tag_name(rec->tag));
+		       (ulong)map_to_sysmem((void *)rec + rec_hdr_size(rec)),
+		       rec->size, rec_tag(rec),
+		       bloblist_tag_name(rec_tag(rec)));
 	}
 }
 
-- 
2.41.0.487.g6d72f3e995-goog


  parent reply	other threads:[~2023-07-25 21:37 UTC|newest]

Thread overview: 29+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-07-25 21:36 [PATCH 00/14] bloblist: Align to firmware handoff Simon Glass
2023-07-25 21:36 ` [PATCH 01/14] bloblist: Update the tag numbering Simon Glass
2023-07-26 20:16   ` Julius Werner
2023-07-28  8:51     ` Ilias Apalodimas
2023-07-28 21:56       ` Julius Werner
2023-08-02 10:14   ` Jose Marinho
2023-07-25 21:36 ` [PATCH 02/14] bloblist: Adjust API to align in powers of 2 Simon Glass
2023-08-02 10:24   ` Jose Marinho
2023-07-25 21:36 ` [PATCH 03/14] bloblist: Change the magic value Simon Glass
2023-07-25 21:36 ` [PATCH 04/14] bloblist: Set version to 1 Simon Glass
2023-07-25 21:36 ` Simon Glass [this message]
2023-07-25 21:36 ` [PATCH 06/14] bloblist: Drop the flags value Simon Glass
2023-07-25 21:36 ` [PATCH 07/14] bloblist: Drop the spare values Simon Glass
2023-07-25 21:36 ` [PATCH 08/14] bloblist: Change the checksum algorithm Simon Glass
2023-07-25 21:36 ` [PATCH 09/14] bloblist: Checksum the entire bloblist Simon Glass
2023-07-25 21:36 ` [PATCH 10/14] bloblist: Handle alignment with a void entry Simon Glass
2023-07-26 20:17   ` Julius Werner
2023-07-25 21:36 ` [PATCH 11/14] bloblist: Reduce blob-header size Simon Glass
2023-07-26 20:20   ` Julius Werner
2023-07-25 21:36 ` [PATCH 12/14] bloblist: Reduce bloblist header size Simon Glass
2023-08-02 10:15   ` Jose Marinho
2023-08-02 21:31     ` Simon Glass
2023-07-25 21:36 ` [PATCH 13/14] bloblist: Add alignment to bloblist_new() Simon Glass
2023-07-26 20:20   ` Julius Werner
2023-07-25 21:36 ` [PATCH 14/14] bloblist: Update documentation and header comment Simon Glass
2023-07-26 20:55   ` Julius Werner
2023-09-06 12:22 ` [PATCH 00/14] bloblist: Align to firmware handoff Michal Simek
2023-10-28  5:35   ` Simon Glass
2023-10-30  7:53     ` Michal Simek

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=20230725213634.255345-6-sjg@chromium.org \
    --to=sjg@chromium.org \
    --cc=bmeng.cn@gmail.com \
    --cc=dan.handley@arm.com \
    --cc=ilias.apalodimas@linaro.org \
    --cc=jose.marinho@arm.com \
    --cc=jwerner@chromium.org \
    --cc=n-jain1@ti.com \
    --cc=trini@konsulko.com \
    --cc=u-boot@lists.denx.de \
    /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