summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorTom Rini <[email protected]>2024-12-30 13:22:15 -0600
committerTom Rini <[email protected]>2024-12-30 13:22:15 -0600
commita3d3d869b6f5860660718d05ee9b4d040d938e0f (patch)
tree7568cb0d3cf66d65e53aa1dc908b7c19c05a9105 /include
parent793e21b83dc83c118940602caa4eb973f6ccb566 (diff)
parent1a25191bc1381f320a359a5dc9c835dde4658175 (diff)
Merge patch series "Cleanup the LMB subsystem"
Ilias Apalodimas <[email protected]> says: The LMB subsystem was used opportunistically for a number of years. A while back Sughosh merged it with the EFI subsystem in order to have a common allocator and avoid subsystems overwriting memory they shouldn't. This is an initial cleanup of all the crud we gathered over the years. There's no functional change expected from the patches as they just cleanup some abstraction functions and rename a few variables to make more sense. I plan to make even bigger changes -- e.g I don't see the point of having *_alloc() and *_reserve() versions of the functions since they do the same thing and just cause confusion. lmb_alloc_addr_flags() returning the base address on success makes little sense since we already *request* the address on the function arguments, etc. Since this patchset grew enough already, I'd like to get it in before more refactoring happens. It's worth noting that although some patches slightly increase the code size due to an extra flags argument being carried around, the final result is eventually smaller. # qemu_arm64_lwip_defconfig (version string adds another 20b) add/remove: 0/5 grow/shrink: 15/1 up/down: 568/-628 (-60) Function old new delta lmb_alloc_base 80 324 +244 lmb_alloc_addr 8 144 +136 lmb_reserve 8 96 +88 version_string 50 70 +20 boot_relocate_fdt 488 508 +20 boot_ramdisk_high 268 284 +16 lmb_add_region_flags 696 704 +8 boot_fdt_reserve_region 100 108 +8 load_serial 548 552 +4 lmb_alloc 8 12 +4 image_setup_libfdt 368 372 +4 do_load 728 732 +4 do_bootz 332 336 +4 do_booti 520 524 +4 bootm_run_states 2176 2180 +4 lmb_alloc_addr_flags 4 - -4 boot_fdt_add_mem_rsv_regions 284 280 -4 lmb_alloc_base_flags 76 - -76 lmb_reserve_flags 96 - -96 _lmb_alloc_addr 144 - -144 _lmb_alloc_base 304 - -304 Total: Before=1020102, After=1020042, chg -0.01% # sandbox_defconfig (version string adds another 20b) add/remove: 0/3 grow/shrink: 24/3 up/down: 523/-501 (22) Function old new delta lmb_alloc_base 48 299 +251 lmb_alloc_addr 4 92 +88 lmb_reserve 4 58 +54 test_alloc_addr 2933 2963 +30 version_string 50 70 +20 lib_test_lmb_overlapping_reserve 1018 1030 +12 lmb_add_region_flags 600 610 +10 test_multi_alloc.constprop 3034 3042 +8 test_get_unreserved_size 1032 1038 +6 boot_relocate_fdt 599 605 +6 boot_fdt_reserve_region 67 73 +6 lmb_alloc 4 9 +5 lmb_free_flags 190 194 +4 wget_handler 1530 1533 +3 tftp_handler 1190 1192 +2 test_noreserved 1207 1209 +2 test_bigblock 911 913 +2 load_serial 946 948 +2 lib_test_lmb_flags 2101 2103 +2 do_spi_flash 3150 3152 +2 do_bootz 526 528 +2 do_bootm_linux 2067 2069 +2 bootm_run_states 5275 5277 +2 _fs_read.lto_priv 331 333 +2 lmb_dump_region.lto_priv 356 353 -3 lmb_add 59 52 -7 efi_allocate_pages.part 303 249 -54 lmb_reserve_flags 65 - -65 _lmb_alloc_addr.lto_priv 92 - -92 _lmb_alloc_base.lto_priv 280 - -280 Total: Before=2492722, After=2492744, chg +0.00% Link: https://lore.kernel.org/r/[email protected]
Diffstat (limited to 'include')
-rw-r--r--include/lmb.h60
1 files changed, 23 insertions, 37 deletions
diff --git a/include/lmb.h b/include/lmb.h
index 03d5fac6aa7..d9d7435a431 100644
--- a/include/lmb.h
+++ b/include/lmb.h
@@ -19,18 +19,17 @@
#define LMB_ALIST_INITIAL_SIZE 4
/**
- * enum lmb_flags - Definition of memory region attributes
- * @LMB_NONE: No special request
- * @LMB_NOMAP: Don't add to MMU configuration
- * @LMB_NOOVERWRITE: The memory region cannot be overwritten/re-reserved
- * @LMB_NONOTIFY: Do not notify other modules of changes to this memory region
- */
-enum lmb_flags {
- LMB_NONE = 0,
- LMB_NOMAP = BIT(1),
- LMB_NOOVERWRITE = BIT(2),
- LMB_NONOTIFY = BIT(3),
-};
+ * DOC: Memory region attribute flags.
+ *
+ * %LMB_NONE: No special request
+ * %LMB_NOMAP: Don't add to MMU configuration
+ * %LMB_NOOVERWRITE: The memory region cannot be overwritten/re-reserved
+ * %LMB_NONOTIFY: Do not notify other modules of changes to this memory region
+ */
+#define LMB_NONE 0
+#define LMB_NOMAP BIT(0)
+#define LMB_NOOVERWRITE BIT(1)
+#define LMB_NONOTIFY BIT(2)
/**
* struct lmb_region - Description of one region
@@ -41,17 +40,17 @@ enum lmb_flags {
struct lmb_region {
phys_addr_t base;
phys_size_t size;
- enum lmb_flags flags;
+ u32 flags;
};
/**
* struct lmb - The LMB structure
- * @free_mem: List of free memory regions
+ * @available_mem: List of memory available to LMB
* @used_mem: List of used/reserved memory regions
* @test: Is structure being used for LMB tests
*/
struct lmb {
- struct alist free_mem;
+ struct alist available_mem;
struct alist used_mem;
bool test;
};
@@ -81,16 +80,7 @@ void lmb_add_memory(void);
long lmb_add(phys_addr_t base, phys_size_t size);
/**
- * lmb_reserve() - Reserve a memory region (with no special flags)
- * @base: Base address of the memory region
- * @size: Size of the memory region
- *
- * Return: 0 on success, negative error code on failure.
- */
-long lmb_reserve(phys_addr_t base, phys_size_t size);
-
-/**
- * lmb_reserve_flags() - Reserve one region with a specific flags bitfield
+ * lmb_reserve() - Reserve one region with a specific flags bitfield
* @base: Base address of the memory region
* @size: Size of the memory region
* @flags: Flags for the memory region
@@ -100,16 +90,13 @@ long lmb_reserve(phys_addr_t base, phys_size_t size);
* * %-EEXIST - The region is already added, and flags != LMB_NONE
* * %-1 - Failure
*/
-long lmb_reserve_flags(phys_addr_t base, phys_size_t size,
- enum lmb_flags flags);
+long lmb_reserve(phys_addr_t base, phys_size_t size, u32 flags);
phys_addr_t lmb_alloc(phys_size_t size, ulong align);
-phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr);
-phys_addr_t lmb_alloc_addr(phys_addr_t base, phys_size_t size);
phys_size_t lmb_get_free_size(phys_addr_t addr);
/**
- * lmb_alloc_base_flags() - Allocate specified memory region with specified
+ * lmb_alloc_base() - Allocate specified memory region with specified
* attributes
* @size: Size of the region requested
* @align: Alignment of the memory region requested
@@ -122,12 +109,12 @@ phys_size_t lmb_get_free_size(phys_addr_t addr);
*
* Return: Base address on success, 0 on error.
*/
-phys_addr_t lmb_alloc_base_flags(phys_size_t size, ulong align,
- phys_addr_t max_addr, uint flags);
+phys_addr_t lmb_alloc_base(phys_size_t size, ulong align, phys_addr_t max_addr,
+ uint flags);
/**
- * lmb_alloc_addr_flags() - Allocate specified memory address with specified
- * attributes
+ * lmb_alloc_addr() - Allocate specified memory address with specified attributes
+ *
* @base: Base Address requested
* @size: Size of the region requested
* @flags: Memory region attributes to be set
@@ -138,8 +125,7 @@ phys_addr_t lmb_alloc_base_flags(phys_size_t size, ulong align,
*
* Return: Base address on success, 0 on error.
*/
-phys_addr_t lmb_alloc_addr_flags(phys_addr_t base, phys_size_t size,
- uint flags);
+phys_addr_t lmb_alloc_addr(phys_addr_t base, phys_size_t size, u32 flags);
/**
* lmb_is_reserved_flags() - Test if address is in reserved region with flag
@@ -177,7 +163,7 @@ void lmb_pop(struct lmb *store);
static inline int lmb_read_check(phys_addr_t addr, phys_size_t len)
{
- return lmb_alloc_addr(addr, len) == addr ? 0 : -1;
+ return lmb_alloc_addr(addr, len, LMB_NONE) == addr ? 0 : -1;
}
/**