mirror of
https://github.com/u-boot/u-boot.git
synced 2025-04-25 06:46:00 +00:00
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>
This commit is contained in:
parent
e748e4b780
commit
1a2e02f955
4 changed files with 22 additions and 21 deletions
|
@ -16,6 +16,7 @@
|
||||||
#include <asm/mpspec.h>
|
#include <asm/mpspec.h>
|
||||||
#include <asm/tables.h>
|
#include <asm/tables.h>
|
||||||
#include <asm/coreboot_tables.h>
|
#include <asm/coreboot_tables.h>
|
||||||
|
#include <linux/log2.h>
|
||||||
|
|
||||||
DECLARE_GLOBAL_DATA_PTR;
|
DECLARE_GLOBAL_DATA_PTR;
|
||||||
|
|
||||||
|
@ -104,7 +105,7 @@ int write_tables(void)
|
||||||
if (!gd->arch.table_end)
|
if (!gd->arch.table_end)
|
||||||
gd->arch.table_end = rom_addr;
|
gd->arch.table_end = rom_addr;
|
||||||
rom_addr = (ulong)bloblist_add(table->tag, size,
|
rom_addr = (ulong)bloblist_add(table->tag, size,
|
||||||
table->align);
|
ilog2(table->align));
|
||||||
if (!rom_addr)
|
if (!rom_addr)
|
||||||
return log_msg_ret("bloblist", -ENOBUFS);
|
return log_msg_ret("bloblist", -ENOBUFS);
|
||||||
|
|
||||||
|
|
|
@ -26,8 +26,6 @@
|
||||||
* start address of the data in each blob is aligned as required. Note that
|
* 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
|
* each blob's *data* is aligned to BLOBLIST_ALIGN regardless of the alignment
|
||||||
* of the bloblist itself or the blob header.
|
* of the bloblist itself or the blob header.
|
||||||
*
|
|
||||||
* So far, only BLOBLIST_ALIGN alignment is supported.
|
|
||||||
*/
|
*/
|
||||||
|
|
||||||
DECLARE_GLOBAL_DATA_PTR;
|
DECLARE_GLOBAL_DATA_PTR;
|
||||||
|
@ -128,24 +126,24 @@ static struct bloblist_rec *bloblist_findrec(uint tag)
|
||||||
return NULL;
|
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_rec **recp)
|
||||||
{
|
{
|
||||||
struct bloblist_hdr *hdr = gd->bloblist;
|
struct bloblist_hdr *hdr = gd->bloblist;
|
||||||
struct bloblist_rec *rec;
|
struct bloblist_rec *rec;
|
||||||
int data_start, new_alloced;
|
int data_start, new_alloced;
|
||||||
|
|
||||||
if (!align)
|
if (!align_log2)
|
||||||
align = BLOBLIST_ALIGN;
|
align_log2 = BLOBLIST_ALIGN_LOG2;
|
||||||
|
|
||||||
/* Figure out where the new data will start */
|
/* Figure out where the new data will start */
|
||||||
data_start = map_to_sysmem(hdr) + hdr->alloced + sizeof(*rec);
|
data_start = map_to_sysmem(hdr) + hdr->alloced + sizeof(*rec);
|
||||||
|
|
||||||
/* Align the address and then calculate the offset from ->alloced */
|
/* 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 */
|
/* 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) {
|
if (new_alloced > hdr->size) {
|
||||||
log_err("Failed to allocate %x bytes size=%x, need size=%x\n",
|
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,
|
static int bloblist_ensurerec(uint tag, struct bloblist_rec **recp, int size,
|
||||||
int align)
|
int align_log2)
|
||||||
{
|
{
|
||||||
struct bloblist_rec *rec;
|
struct bloblist_rec *rec;
|
||||||
|
|
||||||
|
@ -182,7 +180,7 @@ static int bloblist_ensurerec(uint tag, struct bloblist_rec **recp, int size,
|
||||||
} else {
|
} else {
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = bloblist_addrec(tag, size, align, &rec);
|
ret = bloblist_addrec(tag, size, align_log2, &rec);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
@ -204,22 +202,22 @@ void *bloblist_find(uint tag, int size)
|
||||||
return (void *)rec + rec->hdr_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;
|
struct bloblist_rec *rec;
|
||||||
|
|
||||||
if (bloblist_addrec(tag, size, align, &rec))
|
if (bloblist_addrec(tag, size, align_log2, &rec))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
return (void *)rec + rec->hdr_size;
|
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;
|
struct bloblist_rec *rec;
|
||||||
int ret;
|
int ret;
|
||||||
|
|
||||||
ret = bloblist_ensurerec(tag, &rec, size, align);
|
ret = bloblist_ensurerec(tag, &rec, size, align_log2);
|
||||||
if (ret)
|
if (ret)
|
||||||
return ret;
|
return ret;
|
||||||
*blobp = (void *)rec + rec->hdr_size;
|
*blobp = (void *)rec + rec->hdr_size;
|
||||||
|
|
|
@ -76,7 +76,9 @@
|
||||||
enum {
|
enum {
|
||||||
BLOBLIST_VERSION = 0,
|
BLOBLIST_VERSION = 0,
|
||||||
BLOBLIST_MAGIC = 0xb00757a3,
|
BLOBLIST_MAGIC = 0xb00757a3,
|
||||||
BLOBLIST_ALIGN = 16,
|
|
||||||
|
BLOBLIST_ALIGN_LOG2 = 3,
|
||||||
|
BLOBLIST_ALIGN = 1 << BLOBLIST_ALIGN_LOG2,
|
||||||
};
|
};
|
||||||
|
|
||||||
/* Supported tags - add new ones to tag_name in bloblist.c */
|
/* Supported tags - add new ones to tag_name in bloblist.c */
|
||||||
|
@ -254,11 +256,11 @@ void *bloblist_find(uint tag, int size);
|
||||||
*
|
*
|
||||||
* @tag: Tag to add (enum bloblist_tag_t)
|
* @tag: Tag to add (enum bloblist_tag_t)
|
||||||
* @size: Size of the blob
|
* @size: Size of the blob
|
||||||
* @align: Alignment of the blob (in bytes), 0 for default
|
* @align_log2: Alignment of the blob (in bytes log2), 0 for default
|
||||||
* Return: pointer to the newly added block, or NULL if there is not enough
|
* Return: pointer to the newly added block, or NULL if there is not enough
|
||||||
* space for the blob
|
* space for the blob
|
||||||
*/
|
*/
|
||||||
void *bloblist_add(uint tag, int size, int align);
|
void *bloblist_add(uint tag, int size, int align_log2);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bloblist_ensure_size() - Find or add a blob
|
* bloblist_ensure_size() - Find or add a blob
|
||||||
|
@ -268,11 +270,11 @@ void *bloblist_add(uint tag, int size, int align);
|
||||||
* @tag: Tag to add (enum bloblist_tag_t)
|
* @tag: Tag to add (enum bloblist_tag_t)
|
||||||
* @size: Size of the blob
|
* @size: Size of the blob
|
||||||
* @blobp: Returns a pointer to blob on success
|
* @blobp: Returns a pointer to blob on success
|
||||||
* @align: Alignment of the blob (in bytes), 0 for default
|
* @align_log2: Alignment of the blob (in bytes log2), 0 for default
|
||||||
* Return: 0 if OK, -ENOSPC if it is missing and could not be added due to lack
|
* Return: 0 if OK, -ENOSPC if it is missing and could not be added due to lack
|
||||||
* of space, or -ESPIPE it exists but has the wrong size
|
* of space, or -ESPIPE it exists but has the wrong 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);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* bloblist_ensure() - Find or add a blob
|
* bloblist_ensure() - Find or add a blob
|
||||||
|
|
|
@ -336,7 +336,7 @@ static int bloblist_test_align(struct unit_test_state *uts)
|
||||||
|
|
||||||
/* Check larger alignment */
|
/* Check larger alignment */
|
||||||
for (i = 0; i < 3; i++) {
|
for (i = 0; i < 3; i++) {
|
||||||
int align = 32 << i;
|
int align = 5 - i;
|
||||||
|
|
||||||
data = bloblist_add(3 + i, i * 4, align);
|
data = bloblist_add(3 + i, i * 4, align);
|
||||||
ut_assertnonnull(data);
|
ut_assertnonnull(data);
|
||||||
|
@ -351,7 +351,7 @@ static int bloblist_test_align(struct unit_test_state *uts)
|
||||||
ut_assertok(bloblist_new(TEST_ADDR + BLOBLIST_ALIGN, TEST_BLOBLIST_SIZE,
|
ut_assertok(bloblist_new(TEST_ADDR + BLOBLIST_ALIGN, TEST_BLOBLIST_SIZE,
|
||||||
0));
|
0));
|
||||||
|
|
||||||
data = bloblist_add(1, 5, BLOBLIST_ALIGN * 2);
|
data = bloblist_add(1, 5, BLOBLIST_ALIGN_LOG2 + 1);
|
||||||
ut_assertnonnull(data);
|
ut_assertnonnull(data);
|
||||||
addr = map_to_sysmem(data);
|
addr = map_to_sysmem(data);
|
||||||
ut_asserteq(0, addr & (BLOBLIST_ALIGN * 2 - 1));
|
ut_asserteq(0, addr & (BLOBLIST_ALIGN * 2 - 1));
|
||||||
|
|
Loading…
Add table
Reference in a new issue