diff options
author | Julius Werner <jwerner@chromium.org> | 2021-04-16 16:48:32 -0700 |
---|---|---|
committer | Julius Werner <jwerner@chromium.org> | 2021-04-21 02:06:26 +0000 |
commit | c893197352acc9b53c1beef5082cbc0271f63688 (patch) | |
tree | b975712387bd54bd0101a736adbb2a6fe5b824bb /tests/commonlib | |
parent | b03e497ef16e9e38ba9220d31131a6bfdef35390 (diff) |
commonlib/region: Turn addrspace_32bit into a more official API
We had the addrspace_32bit rdev in prog_loaders.c for a while to help
represent memory ranges as an rdev, and we've found it useful for a
couple of things that have nothing to do with program loading. This
patch moves the concept straight into commonlib/region.c so it is no
longer anchored in such a weird place, and easier to use in unit tests.
Also expand the concept to the whole address space (there's no real need
to restrict it to 32 bits in 64-bit environments) and introduce an
rdev_chain_mem() helper function to make it a bit easier to use. Replace
some direct uses of struct mem_region_device with this new API where it
seems to make sense.
Signed-off-by: Julius Werner <jwerner@chromium.org>
Change-Id: Ie4c763b77f77d227768556a9528681d771a08dca
Reviewed-on: https://review.coreboot.org/c/coreboot/+/52533
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Diffstat (limited to 'tests/commonlib')
-rw-r--r-- | tests/commonlib/region-test.c | 23 |
1 files changed, 12 insertions, 11 deletions
diff --git a/tests/commonlib/region-test.c b/tests/commonlib/region-test.c index 545463e1dd..fab5961173 100644 --- a/tests/commonlib/region-test.c +++ b/tests/commonlib/region-test.c @@ -333,32 +333,33 @@ static void test_mem_rdev(void **state) u8 backing[size]; u8 scratch[size]; int i; - struct mem_region_device mem = MEM_REGION_DEV_RW_INIT(backing, size); + struct region_device mem; + rdev_chain_mem_rw(&mem, backing, size); /* Test writing to and reading from full mapping. */ memset(backing, 0xa5, size); - u8 *mapping = rdev_mmap_full(&mem.rdev); + u8 *mapping = rdev_mmap_full(&mem); assert_non_null(mapping); for (i = 0; i < size; i++) assert_int_equal(mapping[i], 0xa5); memset(mapping, 0x5a, size); for (i = 0; i < size; i++) assert_int_equal(backing[i], 0x5a); - assert_int_equal(rdev_munmap(&mem.rdev, mapping), 0); + assert_int_equal(rdev_munmap(&mem, mapping), 0); /* Test read/write/erase of single bytes. */ for (i = 0; i < size; i++) { u8 val = i + 0xaa; scratch[0] = val; - assert_int_equal(rdev_writeat(&mem.rdev, &scratch, i, 1), 1); + assert_int_equal(rdev_writeat(&mem, &scratch, i, 1), 1); assert_int_equal(backing[i], val); assert_int_equal(scratch[0], val); val = i + 0x55; backing[i] = val; - assert_int_equal(rdev_readat(&mem.rdev, &scratch, i, 1), 1); + assert_int_equal(rdev_readat(&mem, &scratch, i, 1), 1); assert_int_equal(scratch[0], val); assert_int_equal(backing[i], val); - assert_int_equal(rdev_eraseat(&mem.rdev, i, 1), 1); + assert_int_equal(rdev_eraseat(&mem, i, 1), 1); assert_int_equal(backing[i], 0); } @@ -368,25 +369,25 @@ static void test_mem_rdev(void **state) memset(backing, 0, size); memset(scratch, 0, size); memset(scratch + offs, 0x39, chunk); - assert_int_equal(rdev_writeat(&mem.rdev, scratch + offs, offs, chunk), chunk); + assert_int_equal(rdev_writeat(&mem, scratch + offs, offs, chunk), chunk); assert_memory_equal(backing, scratch, size); memset(backing, 0, size); - assert_int_equal(rdev_readat(&mem.rdev, scratch + offs, offs, chunk), chunk); + assert_int_equal(rdev_readat(&mem, scratch + offs, offs, chunk), chunk); assert_memory_equal(backing, scratch, size); memset(scratch + offs + 1, 0, chunk - 1); - assert_int_equal(rdev_eraseat(&mem.rdev, offs + 1, chunk - 1), chunk - 1); + assert_int_equal(rdev_eraseat(&mem, offs + 1, chunk - 1), chunk - 1); assert_memory_equal(backing, scratch, size); /* Test mapping of larger chunk. */ memset(backing, 0, size); - mapping = rdev_mmap(&mem.rdev, offs, chunk); + mapping = rdev_mmap(&mem, offs, chunk); assert_non_null(mapping); memset(scratch, 0x93, size); memcpy(mapping, scratch, chunk); memset(scratch, 0, size); memset(scratch + offs, 0x93, chunk); assert_memory_equal(backing, scratch, size); - assert_int_equal(rdev_munmap(&mem.rdev, mapping), 0); + assert_int_equal(rdev_munmap(&mem, mapping), 0); assert_memory_equal(backing, scratch, size); } |