[PATCH 0/5] lmb: documentation and clean up

Add the LMB library to the HTML documenation. Start cleaning up the library.
Heinrich Schuchardt (5): lmb: remove lmb_is_nomap() from include doc: add include/lmb.h to the HTML documentation lmb: remove extern keyword in lmb.h lmb: drop unused lmb_size_bytes() lmb: fix typo 'commun'
doc/api/index.rst | 1 + doc/api/lmb.rst | 7 +++++ include/lmb.h | 72 +++++++++++++++++++---------------------------- lib/Kconfig | 2 +- test/lib/lmb.c | 5 ++++ 5 files changed, 43 insertions(+), 44 deletions(-) create mode 100644 doc/api/lmb.rst

Defining static functions in includes should be avoided. Function lmb_is_nomap() is only used in the unit test. So move it to the unit test.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- include/lmb.h | 7 ------- test/lib/lmb.c | 5 +++++ 2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/include/lmb.h b/include/lmb.h index 1984291132..ee5b938e19 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -124,13 +124,6 @@ void board_lmb_reserve(struct lmb *lmb); void arch_lmb_reserve(struct lmb *lmb); void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, ulong end, ulong align);
-/* Low level functions */ - -static inline bool lmb_is_nomap(struct lmb_property *m) -{ - return m->flags & LMB_NOMAP; -} - #endif /* __KERNEL__ */
#endif /* _LINUX_LMB_H */ diff --git a/test/lib/lmb.c b/test/lib/lmb.c index b2c2b99ef1..157c26394d 100644 --- a/test/lib/lmb.c +++ b/test/lib/lmb.c @@ -12,6 +12,11 @@ #include <test/test.h> #include <test/ut.h>
+static inline bool lmb_is_nomap(struct lmb_property *m) +{ + return m->flags & LMB_NOMAP; +} + static int check_lmb(struct unit_test_state *uts, struct lmb *lmb, phys_addr_t ram_base, phys_size_t ram_size, unsigned long num_reserved,

On Sun, 14 Nov 2021 at 11:03, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
Defining static functions in includes should be avoided. Function lmb_is_nomap() is only used in the unit test. So move it to the unit test.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
include/lmb.h | 7 ------- test/lib/lmb.c | 5 +++++ 2 files changed, 5 insertions(+), 7 deletions(-)
diff --git a/include/lmb.h b/include/lmb.h index 1984291132..ee5b938e19 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -124,13 +124,6 @@ void board_lmb_reserve(struct lmb *lmb); void arch_lmb_reserve(struct lmb *lmb); void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, ulong end, ulong align);
-/* Low level functions */
-static inline bool lmb_is_nomap(struct lmb_property *m) -{
return m->flags & LMB_NOMAP;
-}
#endif /* __KERNEL__ */
#endif /* _LINUX_LMB_H */ diff --git a/test/lib/lmb.c b/test/lib/lmb.c index b2c2b99ef1..157c26394d 100644 --- a/test/lib/lmb.c +++ b/test/lib/lmb.c @@ -12,6 +12,11 @@ #include <test/test.h> #include <test/ut.h>
+static inline bool lmb_is_nomap(struct lmb_property *m) +{
return m->flags & LMB_NOMAP;
+}
static int check_lmb(struct unit_test_state *uts, struct lmb *lmb, phys_addr_t ram_base, phys_size_t ram_size, unsigned long num_reserved, -- 2.32.0
Acked-by: Ilias Apalodimas ilias.apalodimas@linaro.org

Correct Sphinx style comments in include/lmb.h
Add the logical memory block API to the HTML documentation.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- doc/api/index.rst | 1 + doc/api/lmb.rst | 7 +++++++ include/lmb.h | 23 ++++++++++++----------- 3 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 doc/api/lmb.rst
diff --git a/doc/api/index.rst b/doc/api/index.rst index 281d1dca96..806c7385a6 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -10,6 +10,7 @@ U-Boot API documentation efi getopt linker_lists + lmb logging pinctrl rng diff --git a/doc/api/lmb.rst b/doc/api/lmb.rst new file mode 100644 index 0000000000..2095bfa161 --- /dev/null +++ b/doc/api/lmb.rst @@ -0,0 +1,7 @@ +.. SPDX-License-Identifier: GPL-2.0+ + +Logical memory blocks +===================== + +.. kernel-doc:: include/lmb.h + :internal: diff --git a/include/lmb.h b/include/lmb.h index ee5b938e19..5efdf9d2e8 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -25,8 +25,9 @@ enum lmb_flags { /** * struct lmb_property - Description of one region. * - * @base: Base address of the region. - * @size: Size of the region + * @base: Base address of the region. + * @size: Size of the region + * @flags: memory region attributes */ struct lmb_property { phys_addr_t base; @@ -83,11 +84,11 @@ extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size); /** * lmb_reserve_flags - Reserve one region with a specific flags bitfield. * - * @lmb the logical memory block struct - * @base base address of the memory region - * @size size of the memory region - * @flags flags for the memory region - * @return 0 if OK, > 0 for coalesced region or a negative error code. + * @lmb: the logical memory block struct + * @base: base address of the memory region + * @size: size of the memory region + * @flags: flags for the memory region + * Return: 0 if OK, > 0 for coalesced region or a negative error code. */ long lmb_reserve_flags(struct lmb *lmb, phys_addr_t base, phys_size_t size, enum lmb_flags flags); @@ -103,10 +104,10 @@ extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr); /** * lmb_is_reserved_flags - test if tha address is in reserved region with a bitfield flag * - * @lmb the logical memory block struct - * @addr address to be tested - * @flags flags bitfied to be tested - * @return 0 if not reserved or reserved without the requested flag else 1 + * @lmb: the logical memory block struct + * @addr: address to be tested + * @flags: flags bitfied to be tested + * Return: if not reserved or reserved without the requested flag else 1 */ int lmb_is_reserved_flags(struct lmb *lmb, phys_addr_t addr, int flags); extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size);

On Sun, 14 Nov 2021 at 11:03, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
Correct Sphinx style comments in include/lmb.h
Add the logical memory block API to the HTML documentation.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
doc/api/index.rst | 1 + doc/api/lmb.rst | 7 +++++++ include/lmb.h | 23 ++++++++++++----------- 3 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 doc/api/lmb.rst
diff --git a/doc/api/index.rst b/doc/api/index.rst index 281d1dca96..806c7385a6 100644 --- a/doc/api/index.rst +++ b/doc/api/index.rst @@ -10,6 +10,7 @@ U-Boot API documentation efi getopt linker_lists
- lmb logging pinctrl rng
diff --git a/doc/api/lmb.rst b/doc/api/lmb.rst new file mode 100644 index 0000000000..2095bfa161 --- /dev/null +++ b/doc/api/lmb.rst @@ -0,0 +1,7 @@ +.. SPDX-License-Identifier: GPL-2.0+
+Logical memory blocks +=====================
+.. kernel-doc:: include/lmb.h
- :internal:
diff --git a/include/lmb.h b/include/lmb.h index ee5b938e19..5efdf9d2e8 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -25,8 +25,9 @@ enum lmb_flags { /**
- struct lmb_property - Description of one region.
- @base: Base address of the region.
- @size: Size of the region
- @base: Base address of the region.
- @size: Size of the region
*/
- @flags: memory region attributes
struct lmb_property { phys_addr_t base; @@ -83,11 +84,11 @@ extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size); /**
- lmb_reserve_flags - Reserve one region with a specific flags bitfield.
- @lmb the logical memory block struct
- @base base address of the memory region
- @size size of the memory region
- @flags flags for the memory region
- @return 0 if OK, > 0 for coalesced region or a negative error code.
- @lmb: the logical memory block struct
- @base: base address of the memory region
- @size: size of the memory region
- @flags: flags for the memory region
*/
- Return: 0 if OK, > 0 for coalesced region or a negative error code.
long lmb_reserve_flags(struct lmb *lmb, phys_addr_t base, phys_size_t size, enum lmb_flags flags); @@ -103,10 +104,10 @@ extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr); /**
- lmb_is_reserved_flags - test if tha address is in reserved region with a bitfield flag
- @lmb the logical memory block struct
- @addr address to be tested
- @flags flags bitfied to be tested
- @return 0 if not reserved or reserved without the requested flag else 1
- @lmb: the logical memory block struct
- @addr: address to be tested
- @flags: flags bitfied to be tested
*/
- Return: if not reserved or reserved without the requested flag else 1
int lmb_is_reserved_flags(struct lmb *lmb, phys_addr_t addr, int flags); extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size); -- 2.32.0
Acked-by: Ilias Apalodimas ilias.apalodimas@linaro.org

On Sun, 14 Nov 2021 at 02:03, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
Correct Sphinx style comments in include/lmb.h
Add the logical memory block API to the HTML documentation.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
doc/api/index.rst | 1 + doc/api/lmb.rst | 7 +++++++ include/lmb.h | 23 ++++++++++++----------- 3 files changed, 20 insertions(+), 11 deletions(-) create mode 100644 doc/api/lmb.rst
At last, thank you!
Reviewed-by: Simon Glass sjg@chromium.org

The extern keyword is not needed in include/lmb.h to declare functions. Remove it.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- include/lmb.h | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/include/lmb.h b/include/lmb.h index 5efdf9d2e8..6182054f68 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -74,13 +74,12 @@ struct lmb { #endif };
-extern void lmb_init(struct lmb *lmb); -extern void lmb_init_and_reserve(struct lmb *lmb, struct bd_info *bd, - void *fdt_blob); -extern void lmb_init_and_reserve_range(struct lmb *lmb, phys_addr_t base, - phys_size_t size, void *fdt_blob); -extern long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size); -extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size); +void lmb_init(struct lmb *lmb); +void lmb_init_and_reserve(struct lmb *lmb, struct bd_info *bd, void *fdt_blob); +void lmb_init_and_reserve_range(struct lmb *lmb, phys_addr_t base, + phys_size_t size, void *fdt_blob); +long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size); +long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size); /** * lmb_reserve_flags - Reserve one region with a specific flags bitfield. * @@ -92,15 +91,14 @@ extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size); */ long lmb_reserve_flags(struct lmb *lmb, phys_addr_t base, phys_size_t size, enum lmb_flags flags); -extern phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align); -extern phys_addr_t lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align, - phys_addr_t max_addr); -extern phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align, - phys_addr_t max_addr); -extern phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base, - phys_size_t size); -extern phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr); -extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr); +phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align); +phys_addr_t lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align, + phys_addr_t max_addr); +phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align, + phys_addr_t max_addr); +phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base, phys_size_t size); +phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr); +int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr); /** * lmb_is_reserved_flags - test if tha address is in reserved region with a bitfield flag * @@ -110,10 +108,10 @@ extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr); * Return: if not reserved or reserved without the requested flag else 1 */ int lmb_is_reserved_flags(struct lmb *lmb, phys_addr_t addr, int flags); -extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size); +long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size);
-extern void lmb_dump_all(struct lmb *lmb); -extern void lmb_dump_all_force(struct lmb *lmb); +void lmb_dump_all(struct lmb *lmb); +void lmb_dump_all_force(struct lmb *lmb);
static inline phys_size_t lmb_size_bytes(struct lmb_region *type, unsigned long region_nr)

On Sun, 14 Nov 2021 at 11:03, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
The extern keyword is not needed in include/lmb.h to declare functions. Remove it.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
include/lmb.h | 36 +++++++++++++++++------------------- 1 file changed, 17 insertions(+), 19 deletions(-)
diff --git a/include/lmb.h b/include/lmb.h index 5efdf9d2e8..6182054f68 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -74,13 +74,12 @@ struct lmb { #endif };
-extern void lmb_init(struct lmb *lmb); -extern void lmb_init_and_reserve(struct lmb *lmb, struct bd_info *bd,
void *fdt_blob);
-extern void lmb_init_and_reserve_range(struct lmb *lmb, phys_addr_t base,
phys_size_t size, void *fdt_blob);
-extern long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size); -extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size); +void lmb_init(struct lmb *lmb); +void lmb_init_and_reserve(struct lmb *lmb, struct bd_info *bd, void *fdt_blob); +void lmb_init_and_reserve_range(struct lmb *lmb, phys_addr_t base,
phys_size_t size, void *fdt_blob);
+long lmb_add(struct lmb *lmb, phys_addr_t base, phys_size_t size); +long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size); /**
- lmb_reserve_flags - Reserve one region with a specific flags bitfield.
@@ -92,15 +91,14 @@ extern long lmb_reserve(struct lmb *lmb, phys_addr_t base, phys_size_t size); */ long lmb_reserve_flags(struct lmb *lmb, phys_addr_t base, phys_size_t size, enum lmb_flags flags); -extern phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align); -extern phys_addr_t lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
phys_addr_t max_addr);
-extern phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
phys_addr_t max_addr);
-extern phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base,
phys_size_t size);
-extern phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr); -extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr); +phys_addr_t lmb_alloc(struct lmb *lmb, phys_size_t size, ulong align); +phys_addr_t lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
phys_addr_t max_addr);
+phys_addr_t __lmb_alloc_base(struct lmb *lmb, phys_size_t size, ulong align,
phys_addr_t max_addr);
+phys_addr_t lmb_alloc_addr(struct lmb *lmb, phys_addr_t base, phys_size_t size); +phys_size_t lmb_get_free_size(struct lmb *lmb, phys_addr_t addr); +int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr); /**
- lmb_is_reserved_flags - test if tha address is in reserved region with a bitfield flag
@@ -110,10 +108,10 @@ extern int lmb_is_reserved(struct lmb *lmb, phys_addr_t addr);
- Return: if not reserved or reserved without the requested flag else 1
*/ int lmb_is_reserved_flags(struct lmb *lmb, phys_addr_t addr, int flags); -extern long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size); +long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size);
-extern void lmb_dump_all(struct lmb *lmb); -extern void lmb_dump_all_force(struct lmb *lmb); +void lmb_dump_all(struct lmb *lmb); +void lmb_dump_all_force(struct lmb *lmb);
static inline phys_size_t lmb_size_bytes(struct lmb_region *type, unsigned long region_nr) -- 2.32.0
Acked-by: Ilias Apalodimas ilias.apalodimas@linaro.org

lmb_size_bytes() is unused.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- include/lmb.h | 6 ------ 1 file changed, 6 deletions(-)
diff --git a/include/lmb.h b/include/lmb.h index 6182054f68..ab277ca800 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -113,12 +113,6 @@ long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size); void lmb_dump_all(struct lmb *lmb); void lmb_dump_all_force(struct lmb *lmb);
-static inline phys_size_t -lmb_size_bytes(struct lmb_region *type, unsigned long region_nr) -{ - return type->region[region_nr].size; -} - void board_lmb_reserve(struct lmb *lmb); void arch_lmb_reserve(struct lmb *lmb); void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, ulong end, ulong align);

On Sun, 14 Nov 2021 at 11:03, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
lmb_size_bytes() is unused.
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
include/lmb.h | 6 ------ 1 file changed, 6 deletions(-)
diff --git a/include/lmb.h b/include/lmb.h index 6182054f68..ab277ca800 100644 --- a/include/lmb.h +++ b/include/lmb.h @@ -113,12 +113,6 @@ long lmb_free(struct lmb *lmb, phys_addr_t base, phys_size_t size); void lmb_dump_all(struct lmb *lmb); void lmb_dump_all_force(struct lmb *lmb);
-static inline phys_size_t -lmb_size_bytes(struct lmb_region *type, unsigned long region_nr) -{
return type->region[region_nr].size;
-}
void board_lmb_reserve(struct lmb *lmb); void arch_lmb_reserve(struct lmb *lmb); void arch_lmb_reserve_generic(struct lmb *lmb, ulong sp, ulong end, ulong align); -- 2.32.0
Acked-by: Ilias Apalodimas ilias.apalodimas@linaro.org

%s/commun/common/
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com --- lib/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/Kconfig b/lib/Kconfig index 70bf8e7a46..807a4c6ade 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -793,7 +793,7 @@ config LMB Support the library logical memory blocks.
config LMB_USE_MAX_REGIONS - bool "Use a commun number of memory and reserved regions in lmb lib" + bool "Use a common number of memory and reserved regions in lmb lib" depends on LMB default y help

On Sun, 14 Nov 2021 at 11:03, Heinrich Schuchardt heinrich.schuchardt@canonical.com wrote:
%s/commun/common/
Signed-off-by: Heinrich Schuchardt heinrich.schuchardt@canonical.com
lib/Kconfig | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/lib/Kconfig b/lib/Kconfig index 70bf8e7a46..807a4c6ade 100644 --- a/lib/Kconfig +++ b/lib/Kconfig @@ -793,7 +793,7 @@ config LMB Support the library logical memory blocks.
config LMB_USE_MAX_REGIONS
bool "Use a commun number of memory and reserved regions in lmb lib"
bool "Use a common number of memory and reserved regions in lmb lib" depends on LMB default y help
-- 2.32.0
Acked-by: Ilias Apalodimas ilias.apalodimas@linaro.org
participants (3)
-
Heinrich Schuchardt
-
Ilias Apalodimas
-
Simon Glass