Deduplicate driver initialization code
Subsystems (4)
Samuel Holland
maintainerv2 cover Deduplicate driver initialization code
Upstreaming support for some of SiFive's security and power management features will require adding some new driver subsystems (e.g. caches, WorldGuard gadgets, power management domains, etc.). To avoid copy-and- pasting the FDT-based driver matching code to each new subsystem, this series refactors it into some efficient and easily-reusable helper functions.
Version 2 of this series converts everything but the irqchip subsystem to use the new helpers. Once the irqchip subsystem is converted, the old fdt_find_match() helper can be removed. The following series prepares the irqchip subsystem for conversion to use the fdt_driver helpers:
http://lists.infradead.org/pipermail/opensbi/2024-November/007555.html
Changes in v2:
- Shell script cleanup in carray.sh
- Update carray.sh to support embedding struct fdt_driver
- Add conversion of gpio drivers
- Add conversion of ipi drivers
- Add conversion of regmap drivers
- Add conversion of timer drivers
Samuel Holland (11):
treewide: Make carray arrays const and NULL-terminated
lib: utils/fdt: Add helpers for generic driver initialization scripts/carray.sh: Avoid useless use of cat scripts/carray.sh: Allow referencing a struct member
lib: utils/gpio: Use fdt_driver for initialization
lib: utils/i2c: Use fdt_driver for initialization
lib: utils/ipi: Use fdt_driver for initialization
lib: utils/regmap: Use fdt_driver for initialization
lib: utils/reset: Use fdt_driver for initialization
lib: utils/serial: Use fdt_driver for initialization
lib: utils/timer: Use fdt_driver for initialization
include/sbi_utils/fdt/fdt_driver.h | 59 +++++++++++++++ include/sbi_utils/gpio/fdt_gpio.h | 5 +- include/sbi_utils/gpio/gpio.h | 2 +- include/sbi_utils/i2c/fdt_i2c.h | 8 +- include/sbi_utils/ipi/fdt_ipi.h | 6 +- include/sbi_utils/regmap/fdt_regmap.h | 8 +- include/sbi_utils/reset/fdt_reset.h | 15 +--- include/sbi_utils/serial/fdt_serial.h | 6 +- include/sbi_utils/timer/fdt_timer.h | 6 +- lib/sbi/sbi_ecall.c | 5 +- lib/sbi/tests/sbi_unit_test.c | 5 +- lib/utils/fdt/fdt_driver.c | 80 ++++++++++++++++++++ lib/utils/fdt/objects.mk | 1 + lib/utils/gpio/fdt_gpio.c | 28 +------ lib/utils/gpio/fdt_gpio_designware.c | 10 ++- lib/utils/gpio/fdt_gpio_drivers.carray | 4 +- lib/utils/gpio/fdt_gpio_sifive.c | 10 ++- lib/utils/gpio/fdt_gpio_starfive.c | 10 ++- lib/utils/i2c/fdt_i2c.c | 31 +------- lib/utils/i2c/fdt_i2c_adapter_drivers.carray | 2 +- lib/utils/i2c/fdt_i2c_dw.c | 2 +- lib/utils/i2c/fdt_i2c_sifive.c | 2 +- lib/utils/ipi/fdt_ipi.c | 43 +---------- lib/utils/ipi/fdt_ipi_drivers.carray | 2 +- lib/utils/ipi/fdt_ipi_mswi.c | 4 +- lib/utils/ipi/fdt_ipi_plicsw.c | 4 +- lib/utils/irqchip/fdt_irqchip.c | 5 +- lib/utils/regmap/fdt_regmap.c | 29 +------ lib/utils/regmap/fdt_regmap_drivers.carray | 2 +- lib/utils/regmap/fdt_regmap_syscon.c | 2 +- lib/utils/reset/fdt_reset.c | 37 +-------- lib/utils/reset/fdt_reset_atcwdt200.c | 2 +- lib/utils/reset/fdt_reset_drivers.carray | 2 +- lib/utils/reset/fdt_reset_gpio.c | 4 +- lib/utils/reset/fdt_reset_htif.c | 2 +- lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c | 2 +- lib/utils/reset/fdt_reset_sunxi_wdt.c | 2 +- lib/utils/reset/fdt_reset_syscon.c | 4 +- lib/utils/serial/fdt_serial.c | 53 ++----------- lib/utils/serial/fdt_serial_cadence.c | 2 +- lib/utils/serial/fdt_serial_drivers.carray | 2 +- lib/utils/serial/fdt_serial_gaisler.c | 2 +- lib/utils/serial/fdt_serial_htif.c | 2 +- lib/utils/serial/fdt_serial_litex.c | 2 +- lib/utils/serial/fdt_serial_renesas_scif.c | 2 +- lib/utils/serial/fdt_serial_shakti.c | 2 +- lib/utils/serial/fdt_serial_sifive.c | 2 +- lib/utils/serial/fdt_serial_uart8250.c | 2 +- lib/utils/serial/fdt_serial_xlnx_uartlite.c | 2 +- lib/utils/timer/fdt_timer.c | 40 +--------- lib/utils/timer/fdt_timer_drivers.carray | 2 +- lib/utils/timer/fdt_timer_mtimer.c | 4 +- lib/utils/timer/fdt_timer_plmt.c | 4 +- platform/generic/platform.c | 5 +- platform/generic/sifive/fu740.c | 9 ++- platform/generic/starfive/jh7110.c | 9 ++- scripts/carray.sh | 22 ++++-- 57 files changed, 267 insertions(+), 352 deletions(-) create mode 100644 include/sbi_utils/fdt/fdt_driver.h create mode 100644 lib/utils/fdt/fdt_driver.c
Signature · 1 line
2.45.1
Samuel Holland
maintainerPATCH v2 1/11 treewide: Make carray arrays const and NULL-terminated
This allows the compiler to generate significantly better code, because it does not have to maintain either the loop counter or loop limit. Plus there are half as many symbols to relocate. This also simplifies passing carray arrays to helper functions.
---
(no changes since v1)
lib/sbi/sbi_ecall.c | 5 ++--- lib/sbi/tests/sbi_unit_test.c | 5 ++--- lib/utils/gpio/fdt_gpio.c | 5 ++--- lib/utils/i2c/fdt_i2c.c | 5 ++--- lib/utils/ipi/fdt_ipi.c | 5 ++--- lib/utils/irqchip/fdt_irqchip.c | 5 ++--- lib/utils/regmap/fdt_regmap.c | 5 ++--- lib/utils/reset/fdt_reset.c | 5 ++--- lib/utils/serial/fdt_serial.c | 7 +++---- lib/utils/timer/fdt_timer.c | 5 ++--- platform/generic/platform.c | 5 ++--- scripts/carray.sh | 7 +++---- 12 files changed, 26 insertions(+), 38 deletions(-)
lib/sbi/sbi_ecall.c +2 -3
@@ -13,8 +13,7 @@#include <sbi/sbi_error.h> #include <sbi/sbi_trap.h> -extern struct sbi_ecall_extension *sbi_ecall_exts[]; -extern unsigned long sbi_ecall_exts_size; +extern struct sbi_ecall_extension *const sbi_ecall_exts[];u16 sbi_ecall_version_major (void ) {
@@ -148,7 +147,7 @@ int sbi_ecall_init(void)struct sbi_ecall_extension *ext;unsigned long i; -for (i =0 ; i < sbi_ecall_exts_size; i++) { +for (i =0 ; sbi_ecall_exts[i]; i++) { ext = sbi_ecall_exts[i]; ret =SBI_ENODEV ;
lib/sbi/tests/sbi_unit_test.c +2 -3
@@ -11,8 +11,7 @@#define ANSI_COLOR_RED "\x1b[31m"#define ANSI_COLOR_RESET "\x1b[0m" -extern struct sbiunit_test_suite *sbi_unit_tests[]; -extern unsigned long sbi_unit_tests_size; +extern struct sbiunit_test_suite *const sbi_unit_tests[];static void run_test_suite (struct sbiunit_test_suite *suite) {
@@ -48,6 +47,6 @@ void run_all_tests(void)sbi_printf ("\n# Running SBIUNIT tests #\n" ); -for (i =0 ; i < sbi_unit_tests_size; i++) +for (i =0 ; sbi_unit_tests[i]; i++)run_test_suite (sbi_unit_tests[i]); }
lib/utils/gpio/fdt_gpio.c +2 -3
@@ -13,8 +13,7 @@#include <sbi_utils/gpio/fdt_gpio.h> /* List of FDT gpio drivers generated at compile time */ -extern struct fdt_gpio *fdt_gpio_drivers[]; -extern unsigned long fdt_gpio_drivers_size; +extern struct fdt_gpio *const fdt_gpio_drivers[];static int fdt_gpio_init (const void *fdt,int nodeoff) {
@@ -27,7 +26,7 @@ static int fdt_gpio_init(const void *fdt, int nodeoff)return SBI_EINVAL ;/* Try all GPIO drivers one-by-one */ -for (pos =0 ; pos < fdt_gpio_drivers_size; pos++) { +for (pos =0 ; fdt_gpio_drivers[pos]; pos++) { drv = fdt_gpio_drivers[pos]; match =fdt_match_node (fdt, nodeoff, drv->match_table);
lib/utils/i2c/fdt_i2c.c +2 -3
@@ -17,8 +17,7 @@#include <sbi_utils/i2c/fdt_i2c.h> /* List of FDT i2c adapter drivers generated at compile time */ -extern struct fdt_i2c_adapter *fdt_i2c_adapter_drivers[]; -extern unsigned long fdt_i2c_adapter_drivers_size; +extern struct fdt_i2c_adapter *const fdt_i2c_adapter_drivers[];static int fdt_i2c_adapter_init (const void *fdt,int nodeoff) {
@@ -27,7 +26,7 @@ static int fdt_i2c_adapter_init(const void *fdt, int nodeoff)const struct fdt_match *match;/* Try all I2C drivers one-by-one */ -for (pos =0 ; pos < fdt_i2c_adapter_drivers_size; pos++) { +for (pos =0 ; fdt_i2c_adapter_drivers[pos]; pos++) { drv = fdt_i2c_adapter_drivers[pos]; match =fdt_match_node (fdt, nodeoff, drv->match_table);if (match && drv->init) {
lib/utils/ipi/fdt_ipi.c +2 -3
@@ -13,8 +13,7 @@#include <sbi_utils/ipi/fdt_ipi.h> /* List of FDT ipi drivers generated at compile time */ -extern struct fdt_ipi *fdt_ipi_drivers[]; -extern unsigned long fdt_ipi_drivers_size; +extern struct fdt_ipi *const fdt_ipi_drivers[];int fdt_ipi_init (void ) {
@@ -23,7 +22,7 @@ int fdt_ipi_init(void)const struct fdt_match *match;const void *fdt =fdt_get_address (); -for (pos =0 ; pos < fdt_ipi_drivers_size; pos++) { +for (pos =0 ; fdt_ipi_drivers[pos]; pos++) { drv = fdt_ipi_drivers[pos]; noff =-1 ;
lib/utils/irqchip/fdt_irqchip.c +2 -3
@@ -13,8 +13,7 @@#include <sbi_utils/irqchip/fdt_irqchip.h> /* List of FDT irqchip drivers generated at compile time */ -extern struct fdt_irqchip *fdt_irqchip_drivers[]; -extern unsigned long fdt_irqchip_drivers_size; +extern struct fdt_irqchip *const fdt_irqchip_drivers[];#define FDT_IRQCHIP_MAX_DRIVERS 8
@@ -55,7 +54,7 @@ static int fdt_irqchip_cold_init(void)const struct fdt_match *match;const void *fdt =fdt_get_address (); -for (pos =0 ; pos < fdt_irqchip_drivers_size; pos++) { +for (pos =0 ; fdt_irqchip_drivers[pos]; pos++) { drv = fdt_irqchip_drivers[pos]; noff =-1 ;
lib/utils/regmap/fdt_regmap.c +2 -3
@@ -13,8 +13,7 @@#include <sbi_utils/regmap/fdt_regmap.h> /* List of FDT regmap drivers generated at compile time */ -extern struct fdt_regmap *fdt_regmap_drivers[]; -extern unsigned long fdt_regmap_drivers_size; +extern struct fdt_regmap *const fdt_regmap_drivers[];static int fdt_regmap_init (const void *fdt,int nodeoff) {
@@ -23,7 +22,7 @@ static int fdt_regmap_init(const void *fdt, int nodeoff)const struct fdt_match *match;/* Try all I2C drivers one-by-one */ -for (pos =0 ; pos < fdt_regmap_drivers_size; pos++) { +for (pos =0 ; fdt_regmap_drivers[pos]; pos++) { drv = fdt_regmap_drivers[pos]; match =fdt_match_node (fdt, nodeoff, drv->match_table);if (match && drv->init) {
lib/utils/reset/fdt_reset.c +2 -3
@@ -14,8 +14,7 @@#include <sbi_utils/reset/fdt_reset.h> /* List of FDT reset drivers generated at compile time */ -extern struct fdt_reset *fdt_reset_drivers[]; -extern unsigned long fdt_reset_drivers_size; +extern struct fdt_reset *const fdt_reset_drivers[];int fdt_reset_driver_init (const void *fdt,struct fdt_reset *drv) {
@@ -46,6 +45,6 @@ void fdt_reset_init(const void *fdt) {int pos; -for (pos =0 ; pos < fdt_reset_drivers_size; pos++) +for (pos =0 ; fdt_reset_drivers[pos]; pos++)fdt_reset_driver_init (fdt, fdt_reset_drivers[pos]); }
lib/utils/serial/fdt_serial.c +3 -4
@@ -14,8 +14,7 @@#include <sbi_utils/serial/fdt_serial.h> /* List of FDT serial drivers generated at compile time */ -extern struct fdt_serial *fdt_serial_drivers[]; -extern unsigned long fdt_serial_drivers_size; +extern struct fdt_serial *const fdt_serial_drivers[];int fdt_serial_init (const void *fdt) {
@@ -46,7 +45,7 @@ int fdt_serial_init(const void *fdt) }/* First check DT node pointed by stdout-path */ -for (pos =0 ; pos < fdt_serial_drivers_size &&-1 < noff; pos++) { +for (pos =0 ; fdt_serial_drivers[pos] &&-1 < noff; pos++) { drv = fdt_serial_drivers[pos]; match =fdt_match_node (fdt, noff, drv->match_table);
@@ -64,7 +63,7 @@ int fdt_serial_init(const void *fdt) }/* Lastly check all DT nodes */ -for (pos =0 ; pos < fdt_serial_drivers_size; pos++) { +for (pos =0 ; fdt_serial_drivers[pos]; pos++) { drv = fdt_serial_drivers[pos]; noff =-1 ;
lib/utils/timer/fdt_timer.c +2 -3
@@ -13,8 +13,7 @@#include <sbi_utils/timer/fdt_timer.h> /* List of FDT timer drivers generated at compile time */ -extern struct fdt_timer *fdt_timer_drivers[]; -extern unsigned long fdt_timer_drivers_size; +extern struct fdt_timer *const fdt_timer_drivers[];int fdt_timer_init (void ) {
@@ -23,7 +22,7 @@ int fdt_timer_init(void)const struct fdt_match *match;const void *fdt =fdt_get_address (); -for (pos =0 ; pos < fdt_timer_drivers_size; pos++) { +for (pos =0 ; fdt_timer_drivers[pos]; pos++) { drv = fdt_timer_drivers[pos]; noff =-1 ;
platform/generic/platform.c +2 -3
@@ -30,8 +30,7 @@#include <sbi_utils/serial/semihosting.h> /* List of platform override modules generated at compile time */ -extern const struct platform_override *platform_override_modules[]; -extern unsigned long platform_override_modules_size; +extern const struct platform_override *const platform_override_modules[];static const struct platform_override *generic_plat =NULL ;static const struct fdt_match *generic_plat_match =NULL ;
@@ -42,7 +41,7 @@ static void fw_platform_lookup_special(const void *fdt, int root_offset)const struct fdt_match *match;int pos; -for (pos =0 ; pos < platform_override_modules_size; pos++) { +for (pos =0 ; platform_override_modules[pos]; pos++) { plat = platform_override_modules[pos];if (!plat->match_table)continue ;
scripts/carray.sh +3 -4
@@ -69,10 +69,9 @@ for VAR in ${VAR_LIST}; do done printf "\n" -printf "%s *%s[] = {\n" "${TYPE_NAME}" "${ARRAY_NAME}" +printf "%s *const %s[] = {\n" "${TYPE_NAME}" "${ARRAY_NAME}" for VAR in ${VAR_LIST}; do printf "\t&%s,\n" "${VAR}" done -printf "};\n\n" - -printf "unsigned long %s_size = sizeof(%s) / sizeof(%s *);\n" "${ARRAY_NAME}" "${ARRAY_NAME}" "${TYPE_NAME}" + printf "\tNULL\n" +printf "};\n"
Signature · 1 line
2.45.1
PATCH v2 1/11 treewide: Make carray arrays const and NULL-terminated
Quoted 7 lines · On Tue, Nov 12, 2024 at 3:33?AM Samuel Holland <[email protected]>…
This allows the compiler to generate significantly better code, because it does not have to maintain either the loop counter or loop limit. Plus there are half as many symbols to relocate. This also simplifies passing carray arrays to helper functions.
Signed-off-by Samuel Holland <[email protected]>
LGTM.
Regards,
Anup
Quoted 304 lines
---
(no changes since v1)
lib/sbi/sbi_ecall.c | 5 ++--- lib/sbi/tests/sbi_unit_test.c | 5 ++--- lib/utils/gpio/fdt_gpio.c | 5 ++--- lib/utils/i2c/fdt_i2c.c | 5 ++--- lib/utils/ipi/fdt_ipi.c | 5 ++--- lib/utils/irqchip/fdt_irqchip.c | 5 ++--- lib/utils/regmap/fdt_regmap.c | 5 ++--- lib/utils/reset/fdt_reset.c | 5 ++--- lib/utils/serial/fdt_serial.c | 7 +++---- lib/utils/timer/fdt_timer.c | 5 ++--- platform/generic/platform.c | 5 ++--- scripts/carray.sh | 7 +++---- 12 files changed, 26 insertions(+), 38 deletions(-)lib/sbi/sbi_ecall.c +2
-3@@ -13,8 +13,7 @@#include <sbi/sbi_error.h> #include <sbi/sbi_trap.h> -extern struct sbi_ecall_extension *sbi_ecall_exts[]; -extern unsigned long sbi_ecall_exts_size; +extern struct sbi_ecall_extension *const sbi_ecall_exts[];u16 sbi_ecall_version_major (void ) {@@ -148,7 +147,7 @@ int sbi_ecall_init(void)struct sbi_ecall_extension *ext;unsigned long i; -for (i =0 ; i < sbi_ecall_exts_size; i++) { +for (i =0 ; sbi_ecall_exts[i]; i++) { ext = sbi_ecall_exts[i]; ret =SBI_ENODEV ;lib/sbi/tests/sbi_unit_test.c +2
-3@@ -11,8 +11,7 @@#define ANSI_COLOR_RED "\x1b[31m"#define ANSI_COLOR_RESET "\x1b[0m" -extern struct sbiunit_test_suite *sbi_unit_tests[]; -extern unsigned long sbi_unit_tests_size; +extern struct sbiunit_test_suite *const sbi_unit_tests[];static void run_test_suite (struct sbiunit_test_suite *suite) {@@ -48,6 +47,6 @@ void run_all_tests(void)sbi_printf ("\n# Running SBIUNIT tests #\n" ); -for (i =0 ; i < sbi_unit_tests_size; i++) +for (i =0 ; sbi_unit_tests[i]; i++)run_test_suite (sbi_unit_tests[i]); }lib/utils/gpio/fdt_gpio.c +2
-3@@ -13,8 +13,7 @@#include <sbi_utils/gpio/fdt_gpio.h> /* List of FDT gpio drivers generated at compile time */ -extern struct fdt_gpio *fdt_gpio_drivers[]; -extern unsigned long fdt_gpio_drivers_size; +extern struct fdt_gpio *const fdt_gpio_drivers[];static int fdt_gpio_init (const void *fdt,int nodeoff) {@@ -27,7 +26,7 @@ static int fdt_gpio_init(const void *fdt, int nodeoff)return SBI_EINVAL ;/* Try all GPIO drivers one-by-one */ -for (pos =0 ; pos < fdt_gpio_drivers_size; pos++) { +for (pos =0 ; fdt_gpio_drivers[pos]; pos++) { drv = fdt_gpio_drivers[pos]; match =fdt_match_node (fdt, nodeoff, drv->match_table);lib/utils/i2c/fdt_i2c.c +2
-3@@ -17,8 +17,7 @@#include <sbi_utils/i2c/fdt_i2c.h> /* List of FDT i2c adapter drivers generated at compile time */ -extern struct fdt_i2c_adapter *fdt_i2c_adapter_drivers[]; -extern unsigned long fdt_i2c_adapter_drivers_size; +extern struct fdt_i2c_adapter *const fdt_i2c_adapter_drivers[];static int fdt_i2c_adapter_init (const void *fdt,int nodeoff) {@@ -27,7 +26,7 @@ static int fdt_i2c_adapter_init(const void *fdt, int nodeoff)const struct fdt_match *match;/* Try all I2C drivers one-by-one */ -for (pos =0 ; pos < fdt_i2c_adapter_drivers_size; pos++) { +for (pos =0 ; fdt_i2c_adapter_drivers[pos]; pos++) { drv = fdt_i2c_adapter_drivers[pos]; match =fdt_match_node (fdt, nodeoff, drv->match_table);if (match && drv->init) {lib/utils/ipi/fdt_ipi.c +2
-3@@ -13,8 +13,7 @@#include <sbi_utils/ipi/fdt_ipi.h> /* List of FDT ipi drivers generated at compile time */ -extern struct fdt_ipi *fdt_ipi_drivers[]; -extern unsigned long fdt_ipi_drivers_size; +extern struct fdt_ipi *const fdt_ipi_drivers[];int fdt_ipi_init (void ) {@@ -23,7 +22,7 @@ int fdt_ipi_init(void)const struct fdt_match *match;const void *fdt =fdt_get_address (); -for (pos =0 ; pos < fdt_ipi_drivers_size; pos++) { +for (pos =0 ; fdt_ipi_drivers[pos]; pos++) { drv = fdt_ipi_drivers[pos]; noff =-1 ;lib/utils/irqchip/fdt_irqchip.c +2
-3@@ -13,8 +13,7 @@#include <sbi_utils/irqchip/fdt_irqchip.h> /* List of FDT irqchip drivers generated at compile time */ -extern struct fdt_irqchip *fdt_irqchip_drivers[]; -extern unsigned long fdt_irqchip_drivers_size; +extern struct fdt_irqchip *const fdt_irqchip_drivers[];#define FDT_IRQCHIP_MAX_DRIVERS 8@@ -55,7 +54,7 @@ static int fdt_irqchip_cold_init(void)const struct fdt_match *match;const void *fdt =fdt_get_address (); -for (pos =0 ; pos < fdt_irqchip_drivers_size; pos++) { +for (pos =0 ; fdt_irqchip_drivers[pos]; pos++) { drv = fdt_irqchip_drivers[pos]; noff =-1 ;lib/utils/regmap/fdt_regmap.c +2
-3@@ -13,8 +13,7 @@#include <sbi_utils/regmap/fdt_regmap.h> /* List of FDT regmap drivers generated at compile time */ -extern struct fdt_regmap *fdt_regmap_drivers[]; -extern unsigned long fdt_regmap_drivers_size; +extern struct fdt_regmap *const fdt_regmap_drivers[];static int fdt_regmap_init (const void *fdt,int nodeoff) {@@ -23,7 +22,7 @@ static int fdt_regmap_init(const void *fdt, int nodeoff)const struct fdt_match *match;/* Try all I2C drivers one-by-one */ -for (pos =0 ; pos < fdt_regmap_drivers_size; pos++) { +for (pos =0 ; fdt_regmap_drivers[pos]; pos++) { drv = fdt_regmap_drivers[pos]; match =fdt_match_node (fdt, nodeoff, drv->match_table);if (match && drv->init) {lib/utils/reset/fdt_reset.c +2
-3@@ -14,8 +14,7 @@#include <sbi_utils/reset/fdt_reset.h> /* List of FDT reset drivers generated at compile time */ -extern struct fdt_reset *fdt_reset_drivers[]; -extern unsigned long fdt_reset_drivers_size; +extern struct fdt_reset *const fdt_reset_drivers[];int fdt_reset_driver_init (const void *fdt,struct fdt_reset *drv) {@@ -46,6 +45,6 @@ void fdt_reset_init(const void *fdt) {int pos; -for (pos =0 ; pos < fdt_reset_drivers_size; pos++) +for (pos =0 ; fdt_reset_drivers[pos]; pos++)fdt_reset_driver_init (fdt, fdt_reset_drivers[pos]); }lib/utils/serial/fdt_serial.c +3
-4@@ -14,8 +14,7 @@#include <sbi_utils/serial/fdt_serial.h> /* List of FDT serial drivers generated at compile time */ -extern struct fdt_serial *fdt_serial_drivers[]; -extern unsigned long fdt_serial_drivers_size; +extern struct fdt_serial *const fdt_serial_drivers[];int fdt_serial_init (const void *fdt) {@@ -46,7 +45,7 @@ int fdt_serial_init(const void *fdt) }/* First check DT node pointed by stdout-path */ -for (pos =0 ; pos < fdt_serial_drivers_size &&-1 < noff; pos++) { +for (pos =0 ; fdt_serial_drivers[pos] &&-1 < noff; pos++) { drv = fdt_serial_drivers[pos]; match =fdt_match_node (fdt, noff, drv->match_table);@@ -64,7 +63,7 @@ int fdt_serial_init(const void *fdt) }/* Lastly check all DT nodes */ -for (pos =0 ; pos < fdt_serial_drivers_size; pos++) { +for (pos =0 ; fdt_serial_drivers[pos]; pos++) { drv = fdt_serial_drivers[pos]; noff =-1 ;lib/utils/timer/fdt_timer.c +2
-3@@ -13,8 +13,7 @@#include <sbi_utils/timer/fdt_timer.h> /* List of FDT timer drivers generated at compile time */ -extern struct fdt_timer *fdt_timer_drivers[]; -extern unsigned long fdt_timer_drivers_size; +extern struct fdt_timer *const fdt_timer_drivers[];int fdt_timer_init (void ) {@@ -23,7 +22,7 @@ int fdt_timer_init(void)const struct fdt_match *match;const void *fdt =fdt_get_address (); -for (pos =0 ; pos < fdt_timer_drivers_size; pos++) { +for (pos =0 ; fdt_timer_drivers[pos]; pos++) { drv = fdt_timer_drivers[pos]; noff =-1 ;platform/generic/platform.c +2
-3@@ -30,8 +30,7 @@#include <sbi_utils/serial/semihosting.h> /* List of platform override modules generated at compile time */ -extern const struct platform_override *platform_override_modules[]; -extern unsigned long platform_override_modules_size; +extern const struct platform_override *const platform_override_modules[];static const struct platform_override *generic_plat =NULL ;static const struct fdt_match *generic_plat_match =NULL ;@@ -42,7 +41,7 @@ static void fw_platform_lookup_special(const void *fdt, int root_offset)const struct fdt_match *match;int pos; -for (pos =0 ; pos < platform_override_modules_size; pos++) { +for (pos =0 ; platform_override_modules[pos]; pos++) { plat = platform_override_modules[pos];if (!plat->match_table)continue ;scripts/carray.sh +3
-5@@ -69,10 +69,9 @@ for VAR in ${VAR_LIST}; do done printf "\n" -printf "%s *%s[] = {\n" "${TYPE_NAME}" "${ARRAY_NAME}" +printf "%s *const %s[] = {\n" "${TYPE_NAME}" "${ARRAY_NAME}" for VAR in ${VAR_LIST}; do printf "\t&%s,\n" "${VAR}" done -printf "};\n\n" - -printf "unsigned long %s_size = sizeof(%s) / sizeof(%s *);\n" "${ARRAY_NAME}" "${ARRAY_NAME}" "${TYPE_NAME}" + printf "\tNULL\n" +printf "};\n" --2.45.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Samuel Holland
maintainerPATCH v2 2/11 lib: utils/fdt: Add helpers for generic driver initialization
In reply to Samuel HollandCurrently, each driver subsystem contains its own code for matching drivers against the platform's devicetree blob. This bloats firmware size because the several FDT scanning loops are almost exact copies of each other, and is confusing because the loops do have some subtle differences. Furthermore, the existing match algorithm is inefficient:
it scans the FDT structure separately for each driver in the list. A faster algorithm scans the FDT blob only once, matching all drivers in the list for each compatible property seen.
Add new helpers implementing this faster algorithm. Since they must iterate through the list of drivers, the driver structure cannot be opaque. However, since the driver list is an array of pointers, the struct fdt_driver can be embedded in a subsystem-specific driver structure if needed. These three helpers cover all existing use cases for driver initialization within OpenSBI.
An additional benefit of centralized driver initialization is the consistent use of fdt_node_is_enabled().
---
(no changes since v1)
include/sbi_utils/fdt/fdt_driver.h | 59 ++++++++++++++++++++++ lib/utils/fdt/fdt_driver.c | 80 ++++++++++++++++++++++++++++++ lib/utils/fdt/objects.mk | 1 + 3 files changed, 140 insertions(+) create mode 100644 include/sbi_utils/fdt/fdt_driver.h create mode 100644 lib/utils/fdt/fdt_driver.c
include/sbi_utils/fdt/fdt_driver.h new file +59 -0
@@ -0,0 +1,59 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* fdt_driver.h - Generic support for initializing drivers from DT nodes. +* +* Copyright (c) 2024 SiFive +*/ + +#ifndef __FDT_DRIVER_H__ +#define __FDT_DRIVER_H__ + +#include <sbi_utils/fdt/fdt_helper.h> + +struct fdt_driver { +const struct fdt_match *match_table; +int (*init)(const void *fdt,int nodeoff, +const struct fdt_match *match); +}; + +/** +* Initialize a driver instance for a specific DT node +* +* @param fdt devicetree blob +* @param nodeoff offset of a node in the devicetree blob +* @param drivers NULL-terminated array of drivers to match against this node +* +* @return 0 if a driver was matched and successfully initialized or a negative +* error code on failure +*/ +int fdt_driver_init_by_offset (const void *fdt,int nodeoff, +const struct fdt_driver *const *drivers); + +/** +* Initialize a driver instance for each DT node that matches any of the +* provided drivers +* +* @param fdt devicetree blob +* @param drivers NULL-terminated array of drivers to match against each node +* +* @return 0 if drivers for all matches (if any) were successfully initialized +* or a negative error code on failure +*/ +int fdt_driver_init_all (const void *fdt, +const struct fdt_driver *const *drivers); + +/** +* Initialize a driver instance for the first DT node that matches any of the +* provided drivers +* +* @param fdt devicetree blob +* @param drivers NULL-terminated array of drivers to match against each node +* +* @return 0 if a driver was matched and successfully initialized or a negative +* error code on failure +*/ +int fdt_driver_init_one (const void *fdt, +const struct fdt_driver *const *drivers); + +#endif /* __FDT_DRIVER_H__ */
lib/utils/fdt/fdt_driver.c new file +80 -0
80 lines not on this page · raw message
lib/utils/fdt/objects.mk +1 -0
@@ -7,4 +7,5 @@ libsbiutils-objs-$(CONFIG_FDT_DOMAIN) += fdt/fdt_domain.o libsbiutils-objs-$(CONFIG_FDT_PMU) += fdt/fdt_pmu.o libsbiutils-objs-$(CONFIG_FDT) += fdt/fdt_helper.o +libsbiutils-objs-$(CONFIG_FDT) += fdt/fdt_driver.o libsbiutils-objs-$(CONFIG_FDT) += fdt/fdt_fixup.o
Signature · 1 line
2.45.1
PATCH v2 2/11 lib: utils/fdt: Add helpers for generic driver initialization
Quoted 17 lines · On Tue, Nov 12, 2024 at 3:33?AM Samuel Holland <[email protected]>…
Currently, each driver subsystem contains its own code for matching drivers against the platform's devicetree blob. This bloats firmware size because the several FDT scanning loops are almost exact copies of each other, and is confusing because the loops do have some subtle differences. Furthermore, the existing match algorithm is inefficient:
it scans the FDT structure separately for each driver in the list. A faster algorithm scans the FDT blob only once, matching all drivers in the list for eachcompatibleproperty seen.Add new helpers implementing this faster algorithm. Since they must iterate through the list of drivers, the driver structure cannot be opaque. However, since the driver list is an array of pointers, the
struct fdt_drivercan be embedded in a subsystem-specific driver structure if needed. These three helpers cover all existing use cases for driver initialization within OpenSBI.
Quoted 4 lines
An additional benefit of centralized driver initialization is the consistent use of
fdt_node_is_enabled().Signed-off-by Samuel Holland <[email protected]>
LGTM.
Regards,
Anup
Quoted 180 lines
---
(no changes since v1)
include/sbi_utils/fdt/fdt_driver.h | 59 ++++++++++++++++++++++ lib/utils/fdt/fdt_driver.c | 80 ++++++++++++++++++++++++++++++ lib/utils/fdt/objects.mk | 1 + 3 files changed, 140 insertions(+) create mode 100644 include/sbi_utils/fdt/fdt_driver.h create mode 100644 lib/utils/fdt/fdt_driver.cinclude/sbi_utils/fdt/fdt_driver.h new file +59
-0@@ -0,0 +1,59 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* fdt_driver.h - Generic support for initializing drivers from DT nodes. +* +* Copyright (c) 2024 SiFive +*/ + +#ifndef __FDT_DRIVER_H__ +#define __FDT_DRIVER_H__ + +#include <sbi_utils/fdt/fdt_helper.h> + +struct fdt_driver { +const struct fdt_match *match_table; +int (*init)(const void *fdt,int nodeoff, +const struct fdt_match *match); +}; + +/** +* Initialize a driver instance for a specific DT node +* +* @param fdt devicetree blob +* @param nodeoff offset of a node in the devicetree blob +* @param drivers NULL-terminated array of drivers to match against this node +* +* @return 0 if a driver was matched and successfully initialized or a negative +* error code on failure +*/ +int fdt_driver_init_by_offset (const void *fdt,int nodeoff, +const struct fdt_driver *const *drivers); + +/** +* Initialize a driver instance for each DT node that matches any of the +* provided drivers +* +* @param fdt devicetree blob +* @param drivers NULL-terminated array of drivers to match against each node +* +* @return 0 if drivers for all matches (if any) were successfully initialized +* or a negative error code on failure +*/ +int fdt_driver_init_all (const void *fdt, +const struct fdt_driver *const *drivers); + +/** +* Initialize a driver instance for the first DT node that matches any of the +* provided drivers +* +* @param fdt devicetree blob +* @param drivers NULL-terminated array of drivers to match against each node +* +* @return 0 if a driver was matched and successfully initialized or a negative +* error code on failure +*/ +int fdt_driver_init_one (const void *fdt, +const struct fdt_driver *const *drivers); + +#endif /* __FDT_DRIVER_H__ */ lib/utils/fdt/fdt_driver.c new file +80
-0@@ -0,0 +1,80 @@ +/* +* SPDX-License-Identifier: BSD-2-Clause +* +* Copyright (c) 2024 SiFive +*/ + +#include <libfdt.h> +#include <sbi/sbi_console.h> +#include <sbi/sbi_error.h> +#include <sbi_utils/fdt/fdt_driver.h> +#include <sbi_utils/fdt/fdt_helper.h> + +int fdt_driver_init_by_offset (const void *fdt,int nodeoff, +const struct fdt_driver *const *drivers) +{ +const struct fdt_driver *driver; +const struct fdt_match *match; +const void *prop; +int len, rc; + +if (!fdt_node_is_enabled (fdt, nodeoff)) +return SBI_ENODEV ; + + prop =fdt_getprop (fdt, nodeoff,"compatible" , &len); +if (!prop) +return SBI_ENODEV ; + +while ((driver = *drivers++)) { +for (match = driver->match_table; match->compatible; match++) { +if (!fdt_stringlist_contains (prop, len, match->compatible)) +continue ; + + rc = driver->init (fdt, nodeoff, match); +if (rc <0 ) { +const char *name; + + name =fdt_get_name (fdt, nodeoff,NULL ); +sbi_printf ("%s: %s (%s) init failed: %d\n" , + __func__, name, match->compatible, rc); + } + +return rc; + } + } + +return SBI_ENODEV ; +} + +static int fdt_driver_init_scan (const void *fdt, +const struct fdt_driver *const *drivers, +bool one) +{ +int nodeoff, rc; + +for (nodeoff =fdt_next_node (fdt,-1 ,NULL ); + nodeoff >=0 ; + nodeoff =fdt_next_node (fdt, nodeoff,NULL )) { + rc =fdt_driver_init_by_offset (fdt, nodeoff, drivers); +if (rc ==SBI_ENODEV ) +continue ; +if (rc <0 ) +return rc; +if (one) +return 0 ; + } + +return one ?SBI_ENODEV :0 ; +} + +int fdt_driver_init_all (const void *fdt, +const struct fdt_driver *const *drivers) +{ +return fdt_driver_init_scan (fdt, drivers, false); +} + +int fdt_driver_init_one (const void *fdt, +const struct fdt_driver *const *drivers) +{ +return fdt_driver_init_scan (fdt, drivers, true); +}lib/utils/fdt/objects.mk +1
-1@@ -7,4 +7,5 @@ libsbiutils-objs-$(CONFIG_FDT_DOMAIN) += fdt/fdt_domain.o libsbiutils-objs-$(CONFIG_FDT_PMU) += fdt/fdt_pmu.o libsbiutils-objs-$(CONFIG_FDT) += fdt/fdt_helper.o +libsbiutils-objs-$(CONFIG_FDT) += fdt/fdt_driver.o libsbiutils-objs-$(CONFIG_FDT) += fdt/fdt_fixup.o --2.45.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Samuel Holland
maintainerPATCH v2 3/11 scripts/carray.sh: Avoid useless use of cat
In reply to Samuel Hollandawk(1) takes input files as positional arguments, so there is no need to read the file with cat(1).
---
Changes in v2:
- New patch for v2
scripts/carray.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)
scripts/carray.sh +3 -3
@@ -43,19 +43,19 @@ if [ ! -f "${CONFIG_FILE}" ]; then usage fi -TYPE_HEADER=`cat ${CONFIG_FILE} | awk '{ if ($1 == "HEADER:") { printf $2; exit 0; } }'` +TYPE_HEADER=$(awk '{ if ($1 == "HEADER:") { printf $2; exit 0; } }' "${CONFIG_FILE}") if [ -z "${TYPE_HEADER}" ]; then echo "Must specify HEADER: in input config file" usage fi -TYPE_NAME=`cat ${CONFIG_FILE} | awk '{ if ($1 == "TYPE:") { printf $2; for (i=3; i<=NF; i++) printf " %s", $i; exit 0; } }'` +TYPE_NAME=$(awk '{ if ($1 == "TYPE:") { printf $2; for (i=3; i<=NF; i++) printf " %s", $i; exit 0; } }' "${CONFIG_FILE}") if [ -z "${TYPE_NAME}" ]; then echo "Must specify TYPE: in input config file" usage fi -ARRAY_NAME=`cat ${CONFIG_FILE} | awk '{ if ($1 == "NAME:") { printf $2; exit 0; } }'` +ARRAY_NAME=$(awk '{ if ($1 == "NAME:") { printf $2; exit 0; } }' "${CONFIG_FILE}") if [ -z "${ARRAY_NAME}" ]; then echo "Must specify NAME: in input config file" usage
Signature · 1 line
2.45.1
PATCH v2 3/11 scripts/carray.sh: Avoid useless use of cat
Quoted 29 lines · Samuel Holland
awk(1) takes input files as positional arguments, so there is no need to read the file with cat(1).
Signed-off-by Samuel Holland <[email protected]>---
Changes in v2:
- New patch for v2scripts/carray.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)scripts/carray.sh +2
-2@@ -43,19 +43,19 @@ if [ ! -f "${CONFIG_FILE}" ]; then usage fi -TYPE_HEADER=`cat ${CONFIG_FILE} | awk '{ if ($1 == "HEADER:") { printf $2; exit 0; } }'` +TYPE_HEADER=$(awk '{ if ($1 == "HEADER:") { printf $2; exit 0; } }' "${CONFIG_FILE}") if [ -z "${TYPE_HEADER}" ]; then echo "Must specify HEADER: in input config file" usage fi -TYPE_NAME=`cat ${CONFIG_FILE} | awk '{ if ($1 == "TYPE:") { printf $2; for (i=3; i<=NF; i++) printf " %s", $i; exit 0; } }'` +TYPE_NAME=$(awk '{ if ($1 == "TYPE:") { printf $2; for (i=3; i<=NF; i++) printf " %s", $i; exit 0; } }' "${CONFIG_FILE}")
scripts/carray.sh if [ ! -f "${CONFIG_FILE}" ]; then · line 61
Quoted 10 lines
scripts/carray.sh +1
-1if [ -z "${TYPE_NAME}" ]; then echo "Must specify TYPE: in input config file" usage fi -ARRAY_NAME=`cat ${CONFIG_FILE} | awk '{ if ($1 == "NAME:") { printf $2; exit 0; } }'` +ARRAY_NAME=$(awk '{ if ($1 == "NAME:") { printf $2; exit 0; } }' "${CONFIG_FILE}") if [ -z "${ARRAY_NAME}" ]; then echo "Must specify NAME: in input config file" usage
Looks good to me.
Signature · 4 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html
PATCH v2 3/11 scripts/carray.sh: Avoid useless use of cat
Quoted 13 lines · Ben Dooks
Quoted 12 lines · Samuel Holland
awk(1) takes input files as positional arguments, so there is no need to read the file with cat(1).
Signed-off-by Samuel Holland <[email protected]>---
Changes in v2:
? - New patch for v2?
scripts/carray.sh| 6 +++---
? 1 file changed, 3 insertions(+), 3 deletions(-)
Quoted 15 lines
Quoted 7 lines
scripts/carray.sh +0
-0@@ -43,19 +43,19 @@ if [ ! -f "${CONFIG_FILE}" ]; then????? usage
? fiQuoted 8 lines
-TYPE_HEADER=
cat ${CONFIG_FILE} | awk '{ if ($1 == "HEADER:") { printf $2; exit 0; } }'
+TYPE_HEADER=$(awk '{ if ($1 == "HEADER:") { printf $2; exit 0; } }' "${CONFIG_FILE}")
? if [ -z "${TYPE_HEADER}" ]; then
????? echo "Must specify HEADER: in input config file" ????? usage
? fi
Thinking about this, we could just change the entire .sh to an .awk file, with a few minor changes to argument passing. Patch is sort of done as follows. I think it would be a reasonable change, so could send this as a patch pre or post your work, or as a patch to integrate:
#!/usr/bin/awk -f
function usage()
{
echo "Usage:"
echo " $0 [options]"
echo "Options:"
echo " -h Display help or usage"
echo " -l <variable_list> List of variables in the array
(Optional)"
exit 1; }
BEGIN {
VAR_LIST[0] = ""; delete VAR_LIST[0]
for (ArgIndex = 1; ArgIndex < ARGC; ArgIndex++) {
Arg = ARGV[ArgIndex];
if (Arg !~ /^-./) { continue; }
ARGV[ArgIndex] = "";
if (Arg == "-h") {
usage();
} else if (Arg == "-l") {
ArgIndex++;
split(ARGV[ArgIndex], Args," ")
for (A in Args) {
VAR_LIST[length(VAR_LIST)] = Args[A];
}
ARGV[ArgIndex] = "";
} else {
usage() > "/dev/stderr"
}
}
}/^HEADER:/ { TYPE_HEADER = $2 }
/^TYPE:/ { for (i = 2; i <= NF; i++) { TYPE_NAME = TYPE_NAME " " $i } }
/^NAME:/ { ARRAY_NAME = $2}
END {
if (0 == 1) {
print "ARRAY_NAME " ARRAY_NAME
print "TYPE_HEADER " TYPE_HEADER
print "TYPE_NAME " TYPE_NAME
print length(VAR_LIST)
for (v in VAR_LIST) {
print "VAR_LIST " v " = " VAR_LIST[v]
}
}
if (length(ARRAY_NAME) == 0) {
print "Must specify NAME: in input config file" > "/dev/stderr"
usage() > "/dev/stderr"
}
if (length(TYPE_NAME) == 0) {
print "Must specify TYPE: in input config file" > "/dev/stderr"
usage() > "/dev/stderr"
}
if (length(TYPE_HEADER) == 0) {
print "Must specify HEADER: in input config file" > "/dev/stderr"
usage() > "/dev/stderr"
}
printf "// Generated with %s from %s\n", SCRIPT_NAME, CONFIG_FILE
printf("#include <%s>\n\n", TYPE_HEADER)
for (v in VAR_LIST) {
printf("extern%s %s;\n", TYPE_NAME, VAR_LIST[v])
}
print ""
printf("%s *%s[] = {\n", TYPE_NAME, ARRAY_NAME)
for (v in VAR_LIST) {
printf("\t&%s,\n", VAR_LIST[v])
}
printf("\tNULL,\n");
printf("};\n\n");
}Signature · 4 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html
PATCH 1/1 scripts/carray: change to using single .awk script to generate .c
The shell script makes multiple call-outs to awk to get information from the configuration file. It would be easier to just write the whole thing in one .awk script and have the makefile altered to call that.
There should be no functional diffences to this other than the way the script is called, to make it more awk efficient.
--- Makefile | 8 ++--- scripts/carray.awk | 90 ++++++++++++++++++++++++++++++++++++++++++++++ scripts/carray.sh | 78 ---------------------------------------- 3 files changed, 94 insertions(+), 82 deletions(-) create mode 100755 scripts/carray.awk delete mode 100755 scripts/carray.sh
Makefile +4 -4
@@ -502,7 +502,7 @@ compile_d2c = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ compile_carray = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " CARRAY $(subst $(build_dir)/,,$(1))"; \ $(eval CARRAY_VAR_LIST := $(carray-$(subst .carray.c,,$(shell basename $(1)))-y)) \ - $(src_dir)/scripts/carray.sh -i $(2) -l "$(CARRAY_VAR_LIST)" > $(1) + $(src_dir)/scripts/carray.awk -v "SCRIPT_NAME=scripts/carray.awk" -v "CONFIG_FILE=$(2)" -- -l "$(CARRAY_VAR_LIST)" < $(2) > $(1) compile_gen_dep = $(CMD_PREFIX)mkdir -p `dirname $(1)`; \ echo " GEN-DEP $(subst $(build_dir)/,,$(1))"; \ echo "$(1:.dep=$(2)): $(3)" >> $(1)
@@ -531,7 +531,7 @@ $(build_dir)/%.dep: $(src_dir)/%.carray $(KCONFIG_AUTOHEADER) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_AUTOHEADER)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) -$(build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.sh +$(build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.awk $(call compile_carray,$@,$<) $(build_dir)/%.dep: $(src_dir)/%.c $(KCONFIG_AUTOHEADER)
@@ -559,7 +559,7 @@ $(platform_build_dir)/%.dep: $(platform_src_dir)/%.carray $(KCONFIG_AUTOHEADER) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_AUTOHEADER)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) -$(platform_build_dir)/%.carray.c: $(platform_src_dir)/%.carray $(src_dir)/scripts/carray.sh +$(platform_build_dir)/%.carray.c: $(platform_src_dir)/%.carray $(src_dir)/scripts/carray.awk $(call compile_carray,$@,$<) $(platform_build_dir)/%.dep: $(platform_src_dir)/%.c $(KCONFIG_AUTOHEADER)
@@ -602,7 +602,7 @@ $(platform_build_dir)/%.dep: $(src_dir)/%.carray $(KCONFIG_AUTOHEADER) $(call compile_gen_dep,$@,.c,$< $(KCONFIG_AUTOHEADER)) $(call compile_gen_dep,$@,.o,$(@:.dep=.c)) -$(platform_build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.sh +$(platform_build_dir)/%.carray.c: $(src_dir)/%.carray $(src_dir)/scripts/carray.awk $(call compile_carray,$@,$<) $(platform_build_dir)/%.dep: $(src_dir)/%.c $(KCONFIG_AUTOHEADER)
scripts/carray.awk new file +90 -0
90 lines not on this page · raw message
scripts/carray.sh deleted +0 -78
78 lines not on this page · raw message
Signature · 1 line
2.37.2.352.g3c44437643
PATCH v2 3/11 scripts/carray.sh: Avoid useless use of cat
In reply to Samuel HollandQuoted 5 lines · On Tue, Nov 12, 2024 at 3:33?AM Samuel Holland <[email protected]>…
awk(1) takes input files as positional arguments, so there is no need to read the file with cat(1).
Signed-off-by Samuel Holland <[email protected]>
LGTM.
Regards,
Anup
Quoted 43 lines
---
Changes in v2:
- New patch for v2scripts/carray.sh | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-)scripts/carray.sh +3
-4@@ -43,19 +43,19 @@ if [ ! -f "${CONFIG_FILE}" ]; then usage fi -TYPE_HEADER=`cat ${CONFIG_FILE} | awk '{ if ($1 == "HEADER:") { printf $2; exit 0; } }'` +TYPE_HEADER=$(awk '{ if ($1 == "HEADER:") { printf $2; exit 0; } }' "${CONFIG_FILE}") if [ -z "${TYPE_HEADER}" ]; then echo "Must specify HEADER: in input config file" usage fi -TYPE_NAME=`cat ${CONFIG_FILE} | awk '{ if ($1 == "TYPE:") { printf $2; for (i=3; i<=NF; i++) printf " %s", $i; exit 0; } }'` +TYPE_NAME=$(awk '{ if ($1 == "TYPE:") { printf $2; for (i=3; i<=NF; i++) printf " %s", $i; exit 0; } }' "${CONFIG_FILE}") if [ -z "${TYPE_NAME}" ]; then echo "Must specify TYPE: in input config file" usage fi -ARRAY_NAME=`cat ${CONFIG_FILE} | awk '{ if ($1 == "NAME:") { printf $2; exit 0; } }'` +ARRAY_NAME=$(awk '{ if ($1 == "NAME:") { printf $2; exit 0; } }' "${CONFIG_FILE}") if [ -z "${ARRAY_NAME}" ]; then echo "Must specify NAME: in input config file" usage --2.45.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
PATCH v2 3/11 scripts/carray.sh: Avoid useless use of cat
Quoted 6 lines · Anup Patel
Quoted 4 lines · On Tue, Nov 12, 2024 at 3:33?AM Samuel Holland <[email protected]>…
awk(1) takes input files as positional arguments, so there is no need to read the file with cat(1).
Quoted 9 lines
Quoted 1 line
Signed-off-by Samuel Holland <[email protected]>LGTM.
Reviewed-by Anup Patel <[email protected]>Regards,
Anup
Should I follow up with my patch to just make this one awk script?
Signature · 4 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html
PATCH v2 3/11 scripts/carray.sh: Avoid useless use of cat
Quoted 12 lines · On Thu, Nov 28, 2024 at 6:05?PM Ben Dooks <[email protected]> wrote:
Quoted 10 lines · Anup Patel
Quoted 5 lines · On Tue, Nov 12, 2024 at 3:33?AM Samuel Holland <[email protected]>…
awk(1) takes input files as positional arguments, so there is no need to read the file with cat(1).
Signed-off-by Samuel Holland <[email protected]>LGTM.
Quoted 7 lines
Quoted 5 lines
Reviewed-by Anup Patel <[email protected]>Regards,
AnupShould I follow up with my patch to just make this one awk script?
Yes, please rebase and send v2 of your patch.
Thanks,
Anup
Quoted 6 lines
--
Ben Dooks http://www.codethink.co.uk/
Senior Engineer Codethink - Providing Genius
PATCH v2 3/11 scripts/carray.sh: Avoid useless use of cat
Quoted 15 lines · Anup Patel
Quoted 14 lines · On Thu, Nov 28, 2024 at 6:05?PM Ben Dooks <[email protected]> wrote:
Quoted 12 lines · Anup Patel
Quoted 5 lines · On Tue, Nov 12, 2024 at 3:33?AM Samuel Holland <[email protected]>…
awk(1) takes input files as positional arguments, so there is no need to read the file with cat(1).
Signed-off-by Samuel Holland <[email protected]>LGTM.
Reviewed-by Anup Patel <[email protected]>
Quoted 7 lines
Quoted 5 lines
Quoted 3 lines
Regards,
AnupShould I follow up with my patch to just make this one awk script?
Yes, please rebase and send v2 of your patch.
Ok, I've been having a test with latest git, got the fixups and changes for the work Samuel did done and a diff against PLATFORM=generic build done to check the build didn't get broken.
I'll probably put a new version out tomorrow
Signature · 4 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html
Samuel Holland
maintainerPATCH v2 4/11 scripts/carray.sh: Allow referencing a struct member
In reply to Samuel HollandIt can be useful to embed the objects referenced by a carray inside another struct. To avoid type punning, the generated carray code must use the correct type for the enclosing struct and member access to compute the desired object address.
---
Changes in v2:
- New patch for v2
scripts/carray.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)
scripts/carray.sh +9 -2
@@ -61,6 +61,13 @@ if [ -z "${ARRAY_NAME}" ]; then usage fi +MEMBER_NAME=$(awk '{ if ($1 == "MEMBER-NAME:") { printf $2; exit 0; } }' "${CONFIG_FILE}") +MEMBER_TYPE=$(awk '{ if ($1 == "MEMBER-TYPE:") { printf $2; for (i=3; i<=NF; i++) printf " %s", $i; exit 0; } }' "${CONFIG_FILE}") +if [ -n "${MEMBER_NAME}" ] && [ -z "${MEMBER_TYPE}" ]; then + echo "Must specify MEMBER-TYPE: when using MEMBER-NAME:" + usage +fi + printf "// Generated with $(basename $0) from $(basename ${CONFIG_FILE})\n" printf "#include <%s>\n\n" "${TYPE_HEADER}"
@@ -69,9 +76,9 @@ for VAR in ${VAR_LIST}; do done printf "\n" -printf "%s *const %s[] = {\n" "${TYPE_NAME}" "${ARRAY_NAME}" +printf "%s *const %s[] = {\n" "${MEMBER_TYPE:-${TYPE_NAME}}" "${ARRAY_NAME}" for VAR in ${VAR_LIST}; do - printf "\t&%s,\n" "${VAR}" + printf "\t&%s,\n" "${VAR}${MEMBER_NAME:+.}${MEMBER_NAME}" done printf "\tNULL\n" printf "};\n"
Signature · 1 line
2.45.1
PATCH v2 4/11 scripts/carray.sh: Allow referencing a struct member
Quoted 7 lines · On Tue, Nov 12, 2024 at 3:33?AM Samuel Holland <[email protected]>…
It can be useful to embed the objects referenced by a carray inside another struct. To avoid type punning, the generated carray code must use the correct type for the enclosing struct and member access to compute the desired object address.
Signed-off-by Samuel Holland <[email protected]>
LGTM.
Regards,
Anup
Quoted 46 lines
---
Changes in v2:
- New patch for v2scripts/carray.sh | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-)scripts/carray.sh +9
-3@@ -61,6 +61,13 @@ if [ -z "${ARRAY_NAME}" ]; then usage fi +MEMBER_NAME=$(awk '{ if ($1 == "MEMBER-NAME:") { printf $2; exit 0; } }' "${CONFIG_FILE}") +MEMBER_TYPE=$(awk '{ if ($1 == "MEMBER-TYPE:") { printf $2; for (i=3; i<=NF; i++) printf " %s", $i; exit 0; } }' "${CONFIG_FILE}") +if [ -n "${MEMBER_NAME}" ] && [ -z "${MEMBER_TYPE}" ]; then + echo "Must specify MEMBER-TYPE: when using MEMBER-NAME:" + usage +fi + printf "// Generated with $(basename $0) from $(basename ${CONFIG_FILE})\n" printf "#include <%s>\n\n" "${TYPE_HEADER}"@@ -69,9 +76,9 @@ for VAR in ${VAR_LIST}; do done printf "\n" -printf "%s *const %s[] = {\n" "${TYPE_NAME}" "${ARRAY_NAME}" +printf "%s *const %s[] = {\n" "${MEMBER_TYPE:-${TYPE_NAME}}" "${ARRAY_NAME}" for VAR in ${VAR_LIST}; do - printf "\t&%s,\n" "${VAR}" + printf "\t&%s,\n" "${VAR}${MEMBER_NAME:+.}${MEMBER_NAME}" done printf "\tNULL\n" printf "};\n" --2.45.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Samuel Holland
maintainerPATCH v2 5/11 lib: utils/gpio: Use fdt_driver for initialization
In reply to Samuel HollandFDT gpio drivers have an extra .xlate operation, so they need to embed the struct fdt_driver inside the subsystem-specific type. The gpio subsystem always initializes the driver for a specific DT node.
---
Changes in v2:
- New patch for v2
include/sbi_utils/gpio/fdt_gpio.h | 5 ++--- include/sbi_utils/gpio/gpio.h | 2 +- lib/utils/gpio/fdt_gpio.c | 27 ++++---------------------- lib/utils/gpio/fdt_gpio_designware.c | 10 ++++++---- lib/utils/gpio/fdt_gpio_drivers.carray | 4 +++- lib/utils/gpio/fdt_gpio_sifive.c | 10 ++++++---- lib/utils/gpio/fdt_gpio_starfive.c | 10 ++++++---- 7 files changed, 28 insertions(+), 40 deletions(-)
include/sbi_utils/gpio/fdt_gpio.h +2 -3
@@ -10,18 +10,17 @@#ifndef __FDT_GPIO_H__#define __FDT_GPIO_H__ +#include <sbi_utils/fdt/fdt_driver.h> #include <sbi_utils/gpio/gpio.h> struct fdt_phandle_args ;/** FDT based GPIO driver */ struct fdt_gpio { -const struct fdt_match *match_table; +struct fdt_driver driver;int (*xlate)(struct gpio_chip *chip,const struct fdt_phandle_args *pargs,struct gpio_pin *out_pin); -int (*init)(const void *fdt,int nodeoff, -const struct fdt_match *match); };/** Get a GPIO pin using "gpios" DT property of client DT node */
include/sbi_utils/gpio/gpio.h +1 -1
@@ -40,7 +40,7 @@ struct gpio_pin {/** Representation of a GPIO chip */ struct gpio_chip {/** Pointer to GPIO driver owning this GPIO chip */ -void *driver; +const void *driver;/** Uniquie ID of the GPIO chip assigned by the driver */ unsigned int id;/** Number of GPIOs supported by the GPIO chip */
lib/utils/gpio/fdt_gpio.c +4 -23
@@ -13,34 +13,15 @@#include <sbi_utils/gpio/fdt_gpio.h> /* List of FDT gpio drivers generated at compile time */ -extern struct fdt_gpio *const fdt_gpio_drivers[]; +extern const struct fdt_driver *const fdt_gpio_drivers[];static int fdt_gpio_init (const void *fdt,int nodeoff) { -int pos, rc; -struct fdt_gpio *drv; -const struct fdt_match *match; -/* Check "gpio-controller" property */ -if (!fdt_getprop (fdt, nodeoff,"gpio-controller" , &rc)) +if (!fdt_getprop (fdt, nodeoff,"gpio-controller" ,NULL ))return SBI_EINVAL ; -/* Try all GPIO drivers one-by-one */ -for (pos =0 ; fdt_gpio_drivers[pos]; pos++) { - drv = fdt_gpio_drivers[pos]; - - match =fdt_match_node (fdt, nodeoff, drv->match_table); -if (match && drv->init) { - rc = drv->init (fdt, nodeoff, match); -if (rc ==SBI_ENODEV ) -continue ; -if (rc) -return rc; -return 0 ; - } - } - -return SBI_ENOSYS ; +return fdt_driver_init_by_offset (fdt, nodeoff, fdt_gpio_drivers); } static int fdt_gpio_chip_find(const void *fdt, int nodeoff,
@@ -71,7 +52,7 @@ int fdt_gpio_pin_get(const void *fdt, int nodeoff, int index, struct gpio_pin *out_pin) {int rc; -struct fdt_gpio *drv; +const struct fdt_gpio *drv;struct gpio_chip *chip =NULL ;struct fdt_phandle_args pargs;
lib/utils/gpio/fdt_gpio_designware.c +6 -4
@@ -30,7 +30,7 @@ struct dw_gpio_chip {struct gpio_chip chip; }; -extern struct fdt_gpio fdt_gpio_designware; +const struct fdt_gpio fdt_gpio_designware;#define pin_to_chip (__p) container_of((__p)->chip, struct dw_gpio_chip, chip);
@@ -132,8 +132,10 @@ static const struct fdt_match dw_gpio_match[] = { { }, }; -struct fdt_gpio fdt_gpio_designware = { - .match_table = dw_gpio_match, +const struct fdt_gpio fdt_gpio_designware = { + .driver = { + .match_table = dw_gpio_match, + .init = dw_gpio_init_bank, + }, .xlate = fdt_gpio_simple_xlate, - .init = dw_gpio_init_bank, };
lib/utils/gpio/fdt_gpio_drivers.carray +3 -1
@@ -1,3 +1,5 @@ HEADER: sbi_utils/gpio/fdt_gpio.h -TYPE: struct fdt_gpio +TYPE: const struct fdt_gpio NAME: fdt_gpio_drivers +MEMBER-NAME: driver +MEMBER-TYPE: const struct fdt_driver
lib/utils/gpio/fdt_gpio_sifive.c +6 -4
@@ -60,7 +60,7 @@ static void sifive_gpio_set(struct gpio_pin *gp, int value)writel (v, (volatile void *)(chip->addr +SIFIVE_GPIO_OUTVAL )); } -extern struct fdt_gpio fdt_gpio_sifive; +const struct fdt_gpio fdt_gpio_sifive;static int sifive_gpio_init (const void *fdt,int nodeoff,const struct fdt_match *match)
@@ -99,8 +99,10 @@ static const struct fdt_match sifive_gpio_match[] = { { }, }; -struct fdt_gpio fdt_gpio_sifive = { - .match_table = sifive_gpio_match, +const struct fdt_gpio fdt_gpio_sifive = { + .driver = { + .match_table = sifive_gpio_match, + .init = sifive_gpio_init, + }, .xlate = fdt_gpio_simple_xlate, - .init = sifive_gpio_init, };
lib/utils/gpio/fdt_gpio_starfive.c +6 -4
@@ -69,7 +69,7 @@ static void starfive_gpio_set(struct gpio_pin *gp, int value)writel (val, (void *)(reg_addr +STARFIVE_GPIO_OUTVAL )); } -extern struct fdt_gpio fdt_gpio_starfive; +const struct fdt_gpio fdt_gpio_starfive;static int starfive_gpio_init (const void *fdt,int nodeoff,const struct fdt_match *match)
@@ -109,8 +109,10 @@ static const struct fdt_match starfive_gpio_match[] = { { }, }; -struct fdt_gpio fdt_gpio_starfive = { - .match_table = starfive_gpio_match, +const struct fdt_gpio fdt_gpio_starfive = { + .driver = { + .match_table = starfive_gpio_match, + .init = starfive_gpio_init, + }, .xlate = fdt_gpio_simple_xlate, - .init = starfive_gpio_init, };
Signature · 1 line
2.45.1
PATCH v2 5/11 lib: utils/gpio: Use fdt_driver for initialization
Quoted 6 lines · On Tue, Nov 12, 2024 at 3:33?AM Samuel Holland <[email protected]>…
FDT gpio drivers have an extra .xlate operation, so they need to embed the
struct fdt_driverinside the subsystem-specific type. The gpio subsystem always initializes the driver for a specific DT node.Signed-off-by Samuel Holland <[email protected]>
LGTM.
Regards,
Anup
Quoted 203 lines
---
Changes in v2:
- New patch for v2include/sbi_utils/gpio/fdt_gpio.h | 5 ++--- include/sbi_utils/gpio/gpio.h | 2 +- lib/utils/gpio/fdt_gpio.c | 27 ++++---------------------- lib/utils/gpio/fdt_gpio_designware.c | 10 ++++++---- lib/utils/gpio/fdt_gpio_drivers.carray | 4 +++- lib/utils/gpio/fdt_gpio_sifive.c | 10 ++++++---- lib/utils/gpio/fdt_gpio_starfive.c | 10 ++++++---- 7 files changed, 28 insertions(+), 40 deletions(-)include/sbi_utils/gpio/fdt_gpio.h +2
-3@@ -10,18 +10,17 @@#ifndef __FDT_GPIO_H__#define __FDT_GPIO_H__ +#include <sbi_utils/fdt/fdt_driver.h> #include <sbi_utils/gpio/gpio.h> struct fdt_phandle_args ;/** FDT based GPIO driver */ struct fdt_gpio { -const struct fdt_match *match_table; +struct fdt_driver driver;int (*xlate)(struct gpio_chip *chip,const struct fdt_phandle_args *pargs,struct gpio_pin *out_pin); -int (*init)(const void *fdt,int nodeoff, -const struct fdt_match *match); };/** Get a GPIO pin using "gpios" DT property of client DT node */ include/sbi_utils/gpio/gpio.h +1
-1@@ -40,7 +40,7 @@ struct gpio_pin {/** Representation of a GPIO chip */ struct gpio_chip {/** Pointer to GPIO driver owning this GPIO chip */ -void *driver; +const void *driver;/** Uniquie ID of the GPIO chip assigned by the driver */ unsigned int id;/** Number of GPIOs supported by the GPIO chip */ lib/utils/gpio/fdt_gpio.c +4
-23@@ -13,34 +13,15 @@#include <sbi_utils/gpio/fdt_gpio.h> /* List of FDT gpio drivers generated at compile time */ -extern struct fdt_gpio *const fdt_gpio_drivers[]; +extern const struct fdt_driver *const fdt_gpio_drivers[];static int fdt_gpio_init (const void *fdt,int nodeoff) { -int pos, rc; -struct fdt_gpio *drv; -const struct fdt_match *match; -/* Check "gpio-controller" property */ -if (!fdt_getprop (fdt, nodeoff,"gpio-controller" , &rc)) +if (!fdt_getprop (fdt, nodeoff,"gpio-controller" ,NULL ))return SBI_EINVAL ; -/* Try all GPIO drivers one-by-one */ -for (pos =0 ; fdt_gpio_drivers[pos]; pos++) { - drv = fdt_gpio_drivers[pos]; - - match =fdt_match_node (fdt, nodeoff, drv->match_table); -if (match && drv->init) { - rc = drv->init (fdt, nodeoff, match); -if (rc ==SBI_ENODEV ) -continue ; -if (rc) -return rc; -return 0 ; - } - } - -return SBI_ENOSYS ; +return fdt_driver_init_by_offset (fdt, nodeoff, fdt_gpio_drivers); } static int fdt_gpio_chip_find(const void *fdt, int nodeoff,@@ -71,7 +52,7 @@ int fdt_gpio_pin_get(const void *fdt, int nodeoff, int index, struct gpio_pin *out_pin) {int rc; -struct fdt_gpio *drv; +const struct fdt_gpio *drv;struct gpio_chip *chip =NULL ;struct fdt_phandle_args pargs;lib/utils/gpio/fdt_gpio_designware.c +6
-4@@ -30,7 +30,7 @@ struct dw_gpio_chip {struct gpio_chip chip; }; -extern struct fdt_gpio fdt_gpio_designware; +const struct fdt_gpio fdt_gpio_designware;#define pin_to_chip (__p) container_of((__p)->chip, struct dw_gpio_chip, chip);@@ -132,8 +132,10 @@ static const struct fdt_match dw_gpio_match[] = { { }, }; -struct fdt_gpio fdt_gpio_designware = { - .match_table = dw_gpio_match, +const struct fdt_gpio fdt_gpio_designware = { + .driver = { + .match_table = dw_gpio_match, + .init = dw_gpio_init_bank, + }, .xlate = fdt_gpio_simple_xlate, - .init = dw_gpio_init_bank, };lib/utils/gpio/fdt_gpio_drivers.carray +3
-1@@ -1,3 +1,5 @@ HEADER: sbi_utils/gpio/fdt_gpio.h -TYPE: struct fdt_gpio +TYPE: const struct fdt_gpio NAME: fdt_gpio_drivers +MEMBER-NAME: driver +MEMBER-TYPE: const struct fdt_driverlib/utils/gpio/fdt_gpio_sifive.c +6
-4@@ -60,7 +60,7 @@ static void sifive_gpio_set(struct gpio_pin *gp, int value)writel (v, (volatile void *)(chip->addr +SIFIVE_GPIO_OUTVAL )); } -extern struct fdt_gpio fdt_gpio_sifive; +const struct fdt_gpio fdt_gpio_sifive;static int sifive_gpio_init (const void *fdt,int nodeoff,const struct fdt_match *match)@@ -99,8 +99,10 @@ static const struct fdt_match sifive_gpio_match[] = { { }, }; -struct fdt_gpio fdt_gpio_sifive = { - .match_table = sifive_gpio_match, +const struct fdt_gpio fdt_gpio_sifive = { + .driver = { + .match_table = sifive_gpio_match, + .init = sifive_gpio_init, + }, .xlate = fdt_gpio_simple_xlate, - .init = sifive_gpio_init, };lib/utils/gpio/fdt_gpio_starfive.c +6
-5@@ -69,7 +69,7 @@ static void starfive_gpio_set(struct gpio_pin *gp, int value)writel (val, (void *)(reg_addr +STARFIVE_GPIO_OUTVAL )); } -extern struct fdt_gpio fdt_gpio_starfive; +const struct fdt_gpio fdt_gpio_starfive;static int starfive_gpio_init (const void *fdt,int nodeoff,const struct fdt_match *match)@@ -109,8 +109,10 @@ static const struct fdt_match starfive_gpio_match[] = { { }, }; -struct fdt_gpio fdt_gpio_starfive = { - .match_table = starfive_gpio_match, +const struct fdt_gpio fdt_gpio_starfive = { + .driver = { + .match_table = starfive_gpio_match, + .init = starfive_gpio_init, + }, .xlate = fdt_gpio_simple_xlate, - .init = starfive_gpio_init, }; --2.45.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Samuel Holland
maintainerPATCH v2 6/11 lib: utils/i2c: Use fdt_driver for initialization
In reply to Samuel HollandThe i2c driver subsystem does not need any extra data, so it can use struct fdt_driver directly. It always initializes the driver for a specific DT node.
---
(no changes since v1)
include/sbi_utils/i2c/fdt_i2c.h | 8 +----- lib/utils/i2c/fdt_i2c.c | 30 ++------------------ lib/utils/i2c/fdt_i2c_adapter_drivers.carray | 2 +- lib/utils/i2c/fdt_i2c_dw.c | 2 +- lib/utils/i2c/fdt_i2c_sifive.c | 2 +- 5 files changed, 7 insertions(+), 37 deletions(-)
include/sbi_utils/i2c/fdt_i2c.h +1 -7
@@ -10,15 +10,9 @@#ifndef __FDT_I2C_H__#define __FDT_I2C_H__ +#include <sbi_utils/fdt/fdt_driver.h> #include <sbi_utils/i2c/i2c.h> -/** FDT based I2C adapter driver */ -struct fdt_i2c_adapter { -const struct fdt_match *match_table; -int (*init)(const void *fdt,int nodeoff, -const struct fdt_match *match); -}; -/** Get I2C adapter identified by nodeoff */ int fdt_i2c_adapter_get (const void *fdt,int nodeoff,struct i2c_adapter **out_adapter);
lib/utils/i2c/fdt_i2c.c +3 -27
@@ -11,36 +11,11 @@* Anup Patel <[email protected]> */ -#include <libfdt.h> #include <sbi/sbi_error.h> -#include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/i2c/fdt_i2c.h> /* List of FDT i2c adapter drivers generated at compile time */ -extern struct fdt_i2c_adapter *const fdt_i2c_adapter_drivers[]; - -static int fdt_i2c_adapter_init (const void *fdt,int nodeoff) -{ -int pos, rc; -struct fdt_i2c_adapter *drv; -const struct fdt_match *match; - -/* Try all I2C drivers one-by-one */ -for (pos =0 ; fdt_i2c_adapter_drivers[pos]; pos++) { - drv = fdt_i2c_adapter_drivers[pos]; - match =fdt_match_node (fdt, nodeoff, drv->match_table); -if (match && drv->init) { - rc = drv->init (fdt, nodeoff, match); -if (rc ==SBI_ENODEV ) -continue ; -if (rc) -return rc; -return 0 ; - } - } - -return SBI_ENOSYS ; -} +extern const struct fdt_driver *const fdt_i2c_adapter_drivers[];static int fdt_i2c_adapter_find (const void *fdt,int nodeoff,struct i2c_adapter **out_adapter)
@@ -50,7 +25,8 @@ static int fdt_i2c_adapter_find(const void *fdt, int nodeoff,if (!adapter) {/* I2C adapter not found so initialize matching driver */ - rc =fdt_i2c_adapter_init (fdt, nodeoff); + rc =fdt_driver_init_by_offset (fdt, nodeoff, + fdt_i2c_adapter_drivers);if (rc)return rc;
lib/utils/i2c/fdt_i2c_adapter_drivers.carray +1 -1
@@ -1,3 +1,3 @@ HEADER: sbi_utils/i2c/fdt_i2c.h -TYPE: struct fdt_i2c_adapter +TYPE: const struct fdt_driver NAME: fdt_i2c_adapter_drivers
lib/utils/i2c/fdt_i2c_dw.c +1 -1
@@ -49,7 +49,7 @@ static const struct fdt_match fdt_dw_i2c_match[] = { { }, }; -struct fdt_i2c_adapter fdt_i2c_adapter_dw = { +const struct fdt_driver fdt_i2c_adapter_dw = { .match_table = fdt_dw_i2c_match, .init = fdt_dw_i2c_init, };
lib/utils/i2c/fdt_i2c_sifive.c +1 -1
@@ -265,7 +265,7 @@ static const struct fdt_match sifive_i2c_match[] = { { }, }; -struct fdt_i2c_adapter fdt_i2c_adapter_sifive = { +const struct fdt_driver fdt_i2c_adapter_sifive = { .match_table = sifive_i2c_match, .init = sifive_i2c_init, };
Signature · 1 line
2.45.1
PATCH v2 6/11 lib: utils/i2c: Use fdt_driver for initialization
Quoted 6 lines · On Tue, Nov 12, 2024 at 3:33?AM Samuel Holland <[email protected]>…
The i2c driver subsystem does not need any extra data, so it can use
struct fdt_driverdirectly. It always initializes the driver for a specific DT node.Signed-off-by Samuel Holland <[email protected]>
LGTM.
Regards,
Anup
Quoted 127 lines
---
(no changes since v1)
include/sbi_utils/i2c/fdt_i2c.h | 8 +----- lib/utils/i2c/fdt_i2c.c | 30 ++------------------ lib/utils/i2c/fdt_i2c_adapter_drivers.carray | 2 +- lib/utils/i2c/fdt_i2c_dw.c | 2 +- lib/utils/i2c/fdt_i2c_sifive.c | 2 +- 5 files changed, 7 insertions(+), 37 deletions(-)include/sbi_utils/i2c/fdt_i2c.h +1
-7@@ -10,15 +10,9 @@#ifndef __FDT_I2C_H__#define __FDT_I2C_H__ +#include <sbi_utils/fdt/fdt_driver.h> #include <sbi_utils/i2c/i2c.h> -/** FDT based I2C adapter driver */ -struct fdt_i2c_adapter { -const struct fdt_match *match_table; -int (*init)(const void *fdt,int nodeoff, -const struct fdt_match *match); -}; -/** Get I2C adapter identified by nodeoff */ int fdt_i2c_adapter_get (const void *fdt,int nodeoff,struct i2c_adapter **out_adapter);lib/utils/i2c/fdt_i2c.c +3
-27@@ -11,36 +11,11 @@* Anup Patel <[email protected]> */ -#include <libfdt.h> #include <sbi/sbi_error.h> -#include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/i2c/fdt_i2c.h> /* List of FDT i2c adapter drivers generated at compile time */ -extern struct fdt_i2c_adapter *const fdt_i2c_adapter_drivers[]; - -static int fdt_i2c_adapter_init (const void *fdt,int nodeoff) -{ -int pos, rc; -struct fdt_i2c_adapter *drv; -const struct fdt_match *match; - -/* Try all I2C drivers one-by-one */ -for (pos =0 ; fdt_i2c_adapter_drivers[pos]; pos++) { - drv = fdt_i2c_adapter_drivers[pos]; - match =fdt_match_node (fdt, nodeoff, drv->match_table); -if (match && drv->init) { - rc = drv->init (fdt, nodeoff, match); -if (rc ==SBI_ENODEV ) -continue ; -if (rc) -return rc; -return 0 ; - } - } - -return SBI_ENOSYS ; -} +extern const struct fdt_driver *const fdt_i2c_adapter_drivers[];static int fdt_i2c_adapter_find (const void *fdt,int nodeoff,struct i2c_adapter **out_adapter)@@ -50,7 +25,8 @@ static int fdt_i2c_adapter_find(const void *fdt, int nodeoff,if (!adapter) {/* I2C adapter not found so initialize matching driver */ - rc =fdt_i2c_adapter_init (fdt, nodeoff); + rc =fdt_driver_init_by_offset (fdt, nodeoff, + fdt_i2c_adapter_drivers);if (rc)return rc;lib/utils/i2c/fdt_i2c_adapter_drivers.carray +1
-1@@ -1,3 +1,3 @@ HEADER: sbi_utils/i2c/fdt_i2c.h -TYPE: struct fdt_i2c_adapter +TYPE: const struct fdt_driver NAME: fdt_i2c_adapter_driverslib/utils/i2c/fdt_i2c_dw.c +1
-1@@ -49,7 +49,7 @@ static const struct fdt_match fdt_dw_i2c_match[] = { { }, }; -struct fdt_i2c_adapter fdt_i2c_adapter_dw = { +const struct fdt_driver fdt_i2c_adapter_dw = { .match_table = fdt_dw_i2c_match, .init = fdt_dw_i2c_init, };lib/utils/i2c/fdt_i2c_sifive.c +1
-2@@ -265,7 +265,7 @@ static const struct fdt_match sifive_i2c_match[] = { { }, }; -struct fdt_i2c_adapter fdt_i2c_adapter_sifive = { +const struct fdt_driver fdt_i2c_adapter_sifive = { .match_table = sifive_i2c_match, .init = sifive_i2c_init, }; --2.45.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Samuel Holland
maintainerPATCH v2 7/11 lib: utils/ipi: Use fdt_driver for initialization
In reply to Samuel HollandThe ipi driver subsystem does not need any extra data, so it can use struct fdt_driver directly. The generic fdt_ipi_init() performs a best-effort initialization of all matching DT nodes.
---
Changes in v2:
- New patch for v2
include/sbi_utils/ipi/fdt_ipi.h | 6 +--- lib/utils/ipi/fdt_ipi.c | 42 +++------------------------- lib/utils/ipi/fdt_ipi_drivers.carray | 2 +- lib/utils/ipi/fdt_ipi_mswi.c | 4 +-- lib/utils/ipi/fdt_ipi_plicsw.c | 4 +-- 5 files changed, 10 insertions(+), 48 deletions(-)
include/sbi_utils/ipi/fdt_ipi.h +1 -5
@@ -11,14 +11,10 @@#define __FDT_IPI_H__#include <sbi/sbi_types.h> +#include <sbi_utils/fdt/fdt_driver.h> #ifdef CONFIG_FDT_IPI -struct fdt_ipi { -const struct fdt_match *match_table; -int (*cold_init)(const void *fdt,int nodeoff,const struct fdt_match *match); -}; -int fdt_ipi_init (void );#else
lib/utils/ipi/fdt_ipi.c +4 -38
54 lines not on this page · raw message
lib/utils/ipi/fdt_ipi_drivers.carray +1 -1
@@ -1,3 +1,3 @@ HEADER: sbi_utils/ipi/fdt_ipi.h -TYPE: struct fdt_ipi +TYPE: const struct fdt_driver NAME: fdt_ipi_drivers
lib/utils/ipi/fdt_ipi_mswi.c +2 -2
@@ -61,7 +61,7 @@ static const struct fdt_match ipi_mswi_match[] = { { }, }; -struct fdt_ipi fdt_ipi_mswi = { +const struct fdt_driver fdt_ipi_mswi = { .match_table = ipi_mswi_match, - .cold_init = ipi_mswi_cold_init, + .init = ipi_mswi_cold_init, };
lib/utils/ipi/fdt_ipi_plicsw.c +2 -2
@@ -39,7 +39,7 @@ static const struct fdt_match ipi_plicsw_match[] = { {}, }; -struct fdt_ipi fdt_ipi_plicsw = { +const struct fdt_driver fdt_ipi_plicsw = { .match_table = ipi_plicsw_match, - .cold_init = fdt_plicsw_cold_ipi_init, + .init = fdt_plicsw_cold_ipi_init, };
Signature · 1 line
2.45.1
PATCH v2 7/11 lib: utils/ipi: Use fdt_driver for initialization
Quoted 6 lines · On Tue, Nov 12, 2024 at 3:33?AM Samuel Holland <[email protected]>…
The ipi driver subsystem does not need any extra data, so it can use
struct fdt_driverdirectly. The genericfdt_ipi_init()performs a best-effort initialization of all matching DT nodes.Signed-off-by Samuel Holland <[email protected]>
LGTM.
Regards,
Anup
Quoted 136 lines
---
Changes in v2:
- New patch for v2include/sbi_utils/ipi/fdt_ipi.h | 6 +--- lib/utils/ipi/fdt_ipi.c | 42 +++------------------------- lib/utils/ipi/fdt_ipi_drivers.carray | 2 +- lib/utils/ipi/fdt_ipi_mswi.c | 4 +-- lib/utils/ipi/fdt_ipi_plicsw.c | 4 +-- 5 files changed, 10 insertions(+), 48 deletions(-)include/sbi_utils/ipi/fdt_ipi.h +1
-5@@ -11,14 +11,10 @@#define __FDT_IPI_H__#include <sbi/sbi_types.h> +#include <sbi_utils/fdt/fdt_driver.h> #ifdef CONFIG_FDT_IPI -struct fdt_ipi { -const struct fdt_match *match_table; -int (*cold_init)(const void *fdt,int nodeoff,const struct fdt_match *match); -}; -int fdt_ipi_init (void );#else lib/utils/ipi/fdt_ipi.c +4
-38@@ -7,50 +7,16 @@* Anup Patel <[email protected]> */ -#include <sbi/sbi_error.h> -#include <sbi/sbi_scratch.h> -#include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/ipi/fdt_ipi.h> /* List of FDT ipi drivers generated at compile time */ -extern struct fdt_ipi *const fdt_ipi_drivers[]; +extern const struct fdt_driver *const fdt_ipi_drivers[];int fdt_ipi_init (void ) { -int pos, noff, rc; -struct fdt_ipi *drv; -const struct fdt_match *match; -const void *fdt =fdt_get_address (); - -for (pos =0 ; fdt_ipi_drivers[pos]; pos++) { - drv = fdt_ipi_drivers[pos]; - - noff =-1 ; -while ((noff =fdt_find_match (fdt, noff, - drv->match_table, &match)) >=0 ) { -if (!fdt_node_is_enabled (fdt, noff)) -continue ; - -/* drv->cold_init must not be NULL */ -if (drv->cold_init ==NULL ) -return SBI_EFAIL ; - - rc = drv->cold_init (fdt, noff, match); -if (rc ==SBI_ENODEV ) -continue ; -if (rc) -return rc; - -/* -* We will have multiple IPI devices on multi-die or -* multi-socket systems so we cannot break here. -*/ - } - } -/* -* On some single-hart system there is no need for ipi, -* so we cannot return a failure here +* On some single-hart system there is no need for IPIs, +* so do not return a failure if no device is found. */ -return 0 ; +return fdt_driver_init_all (fdt_get_address (), fdt_ipi_drivers); }lib/utils/ipi/fdt_ipi_drivers.carray +1
-1@@ -1,3 +1,3 @@ HEADER: sbi_utils/ipi/fdt_ipi.h -TYPE: struct fdt_ipi +TYPE: const struct fdt_driver NAME: fdt_ipi_driverslib/utils/ipi/fdt_ipi_mswi.c +2
-2@@ -61,7 +61,7 @@ static const struct fdt_match ipi_mswi_match[] = { { }, }; -struct fdt_ipi fdt_ipi_mswi = { +const struct fdt_driver fdt_ipi_mswi = { .match_table = ipi_mswi_match, - .cold_init = ipi_mswi_cold_init, + .init = ipi_mswi_cold_init, };lib/utils/ipi/fdt_ipi_plicsw.c +2
-3@@ -39,7 +39,7 @@ static const struct fdt_match ipi_plicsw_match[] = { {}, }; -struct fdt_ipi fdt_ipi_plicsw = { +const struct fdt_driver fdt_ipi_plicsw = { .match_table = ipi_plicsw_match, - .cold_init = fdt_plicsw_cold_ipi_init, + .init = fdt_plicsw_cold_ipi_init, }; --2.45.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Samuel Holland
maintainerPATCH v2 8/11 lib: utils/regmap: Use fdt_driver for initialization
In reply to Samuel HollandThe regmap driver subsystem does not need any extra data, so it can use struct fdt_driver directly. It always initializes the driver for a specific DT node.
---
Changes in v2:
- New patch for v2
include/sbi_utils/regmap/fdt_regmap.h | 8 +------ lib/utils/regmap/fdt_regmap.c | 28 +++------------------- lib/utils/regmap/fdt_regmap_drivers.carray | 2 +- lib/utils/regmap/fdt_regmap_syscon.c | 2 +- 4 files changed, 6 insertions(+), 34 deletions(-)
include/sbi_utils/regmap/fdt_regmap.h +1 -7
@@ -10,17 +10,11 @@#ifndef __FDT_REGMAP_H__#define __FDT_REGMAP_H__ +#include <sbi_utils/fdt/fdt_driver.h> #include <sbi_utils/regmap/regmap.h> struct fdt_phandle_args ; -/** FDT based regmap driver */ -struct fdt_regmap { -const struct fdt_match *match_table; -int (*init)(const void *fdt,int nodeoff, -const struct fdt_match *match); -}; -/** Get regmap instance based on phandle */ int fdt_regmap_get_by_phandle (const void *fdt,u32 phandle,struct regmap **out_rmap);
lib/utils/regmap/fdt_regmap.c +3 -25
@@ -13,30 +13,7 @@#include <sbi_utils/regmap/fdt_regmap.h> /* List of FDT regmap drivers generated at compile time */ -extern struct fdt_regmap *const fdt_regmap_drivers[]; - -static int fdt_regmap_init (const void *fdt,int nodeoff) -{ -int pos, rc; -struct fdt_regmap *drv; -const struct fdt_match *match; - -/* Try all I2C drivers one-by-one */ -for (pos =0 ; fdt_regmap_drivers[pos]; pos++) { - drv = fdt_regmap_drivers[pos]; - match =fdt_match_node (fdt, nodeoff, drv->match_table); -if (match && drv->init) { - rc = drv->init (fdt, nodeoff, match); -if (rc ==SBI_ENODEV ) -continue ; -if (rc) -return rc; -return 0 ; - } - } - -return SBI_ENOSYS ; -} +extern const struct fdt_driver *const fdt_regmap_drivers[];static int fdt_regmap_find (const void *fdt,int nodeoff,struct regmap **out_rmap)
@@ -46,7 +23,8 @@ static int fdt_regmap_find(const void *fdt, int nodeoff,if (!rmap) {/* Regmap not found so initialize matching driver */ - rc =fdt_regmap_init (fdt, nodeoff); + rc =fdt_driver_init_by_offset (fdt, nodeoff, + fdt_regmap_drivers);if (rc)return rc;
lib/utils/regmap/fdt_regmap_drivers.carray +1 -1
@@ -1,3 +1,3 @@ HEADER: sbi_utils/regmap/fdt_regmap.h -TYPE: struct fdt_regmap +TYPE: const struct fdt_driver NAME: fdt_regmap_drivers
lib/utils/regmap/fdt_regmap_syscon.c +1 -1
@@ -263,7 +263,7 @@ static const struct fdt_match regmap_syscon_match[] = { { }, }; -struct fdt_regmap fdt_regmap_syscon = { +const struct fdt_driver fdt_regmap_syscon = { .match_table = regmap_syscon_match, .init = regmap_syscon_init, };
Signature · 1 line
2.45.1
PATCH v2 8/11 lib: utils/regmap: Use fdt_driver for initialization
Quoted 6 lines · On Tue, Nov 12, 2024 at 3:33?AM Samuel Holland <[email protected]>…
The regmap driver subsystem does not need any extra data, so it can use
struct fdt_driverdirectly. It always initializes the driver for a specific DT node.Signed-off-by Samuel Holland <[email protected]>
LGTM.
Regards,
Anup
Quoted 110 lines
---
Changes in v2:
- New patch for v2include/sbi_utils/regmap/fdt_regmap.h | 8 +------ lib/utils/regmap/fdt_regmap.c | 28 +++------------------- lib/utils/regmap/fdt_regmap_drivers.carray | 2 +- lib/utils/regmap/fdt_regmap_syscon.c | 2 +- 4 files changed, 6 insertions(+), 34 deletions(-)include/sbi_utils/regmap/fdt_regmap.h +1
-7@@ -10,17 +10,11 @@#ifndef __FDT_REGMAP_H__#define __FDT_REGMAP_H__ +#include <sbi_utils/fdt/fdt_driver.h> #include <sbi_utils/regmap/regmap.h> struct fdt_phandle_args ; -/** FDT based regmap driver */ -struct fdt_regmap { -const struct fdt_match *match_table; -int (*init)(const void *fdt,int nodeoff, -const struct fdt_match *match); -}; -/** Get regmap instance based on phandle */ int fdt_regmap_get_by_phandle (const void *fdt,u32 phandle,struct regmap **out_rmap);lib/utils/regmap/fdt_regmap.c +3
-25@@ -13,30 +13,7 @@#include <sbi_utils/regmap/fdt_regmap.h> /* List of FDT regmap drivers generated at compile time */ -extern struct fdt_regmap *const fdt_regmap_drivers[]; - -static int fdt_regmap_init (const void *fdt,int nodeoff) -{ -int pos, rc; -struct fdt_regmap *drv; -const struct fdt_match *match; - -/* Try all I2C drivers one-by-one */ -for (pos =0 ; fdt_regmap_drivers[pos]; pos++) { - drv = fdt_regmap_drivers[pos]; - match =fdt_match_node (fdt, nodeoff, drv->match_table); -if (match && drv->init) { - rc = drv->init (fdt, nodeoff, match); -if (rc ==SBI_ENODEV ) -continue ; -if (rc) -return rc; -return 0 ; - } - } - -return SBI_ENOSYS ; -} +extern const struct fdt_driver *const fdt_regmap_drivers[];static int fdt_regmap_find (const void *fdt,int nodeoff,struct regmap **out_rmap)@@ -46,7 +23,8 @@ static int fdt_regmap_find(const void *fdt, int nodeoff,if (!rmap) {/* Regmap not found so initialize matching driver */ - rc =fdt_regmap_init (fdt, nodeoff); + rc =fdt_driver_init_by_offset (fdt, nodeoff, + fdt_regmap_drivers);if (rc)return rc;lib/utils/regmap/fdt_regmap_drivers.carray +1
-1@@ -1,3 +1,3 @@ HEADER: sbi_utils/regmap/fdt_regmap.h -TYPE: struct fdt_regmap +TYPE: const struct fdt_driver NAME: fdt_regmap_driverslib/utils/regmap/fdt_regmap_syscon.c +1
-2@@ -263,7 +263,7 @@ static const struct fdt_match regmap_syscon_match[] = { { }, }; -struct fdt_regmap fdt_regmap_syscon = { +const struct fdt_driver fdt_regmap_syscon = { .match_table = regmap_syscon_match, .init = regmap_syscon_init, }; --2.45.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Samuel Holland
maintainerPATCH v2 9/11 lib: utils/reset: Use fdt_driver for initialization
In reply to Samuel HollandThe reset driver subsystem does not need any extra data, so it can use struct fdt_driver directly. The generic fdt_reset_init() performs a best-effort initialization of all matching DT nodes. Platform-specific logic expects exactly one DT node to match a single driver. This is accomplished by using fdt_driver_init_one() with a local list containing that one driver.
---
(no changes since v1)
include/sbi_utils/reset/fdt_reset.h | 15 +------- lib/utils/reset/fdt_reset.c | 36 ++------------------ lib/utils/reset/fdt_reset_atcwdt200.c | 2 +- lib/utils/reset/fdt_reset_drivers.carray | 2 +- lib/utils/reset/fdt_reset_gpio.c | 4 +-- lib/utils/reset/fdt_reset_htif.c | 2 +- lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c | 2 +- lib/utils/reset/fdt_reset_sunxi_wdt.c | 2 +- lib/utils/reset/fdt_reset_syscon.c | 4 +-- platform/generic/sifive/fu740.c | 9 +++-- platform/generic/starfive/jh7110.c | 9 +++-- 11 files changed, 26 insertions(+), 61 deletions(-)
include/sbi_utils/reset/fdt_reset.h +1 -14
@@ -11,19 +11,10 @@#define __FDT_RESET_H__#include <sbi/sbi_types.h> - -struct fdt_reset { -const struct fdt_match *match_table; -int (*init)(const void *fdt,int nodeoff,const struct fdt_match *match); -}; +#include <sbi_utils/fdt/fdt_driver.h> #ifdef CONFIG_FDT_RESET -/** -* fdt_reset_driver_init() - initialize reset driver based on the device-tree -*/ -int fdt_reset_driver_init (const void *fdt,struct fdt_reset *drv); -/** * fdt_reset_init() - initialize reset drivers based on the device-tree *
@@ -33,10 +24,6 @@ void fdt_reset_init(const void *fdt);#else -static inline int fdt_reset_driver_init (const void *fdt,struct fdt_reset *drv) -{ -return 0 ; -}static inline void fdt_reset_init (const void *fdt) { }#endif
lib/utils/reset/fdt_reset.c +2 -34
@@ -7,44 +7,12 @@* Anup Patel <[email protected]> */ -#include <sbi/sbi_console.h> -#include <sbi/sbi_error.h> -#include <sbi/sbi_scratch.h> -#include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/reset/fdt_reset.h> /* List of FDT reset drivers generated at compile time */ -extern struct fdt_reset *const fdt_reset_drivers[]; - -int fdt_reset_driver_init (const void *fdt,struct fdt_reset *drv) -{ -int noff, rc, cnt =0 ; -const struct fdt_match *match; - - noff =-1 ; -while ((noff =fdt_find_match (fdt, noff, - drv->match_table, &match)) >=0 ) { -if (!fdt_node_is_enabled (fdt, noff)) -continue ; - -if (drv->init) { - rc = drv->init (fdt, noff, match); -if (!rc) - cnt++; -else if (rc !=SBI_ENODEV ) { -sbi_printf ("%s: %s init failed, %d\n" , - __func__, match->compatible, rc); - } - } - } - -return cnt >0 ?0 :SBI_ENODEV ; -} +extern const struct fdt_driver *const fdt_reset_drivers[];void fdt_reset_init (const void *fdt) { -int pos; - -for (pos =0 ; fdt_reset_drivers[pos]; pos++) -fdt_reset_driver_init (fdt, fdt_reset_drivers[pos]); +fdt_driver_init_all (fdt, fdt_reset_drivers); }
lib/utils/reset/fdt_reset_atcwdt200.c +1 -1
@@ -111,7 +111,7 @@ static const struct fdt_match atcwdt200_reset_match[] = { {}, }; -struct fdt_reset fdt_reset_atcwdt200 = { +const struct fdt_driver fdt_reset_atcwdt200 = { .match_table = atcwdt200_reset_match, .init = atcwdt200_reset_init, };
lib/utils/reset/fdt_reset_drivers.carray +1 -1
@@ -1,3 +1,3 @@ HEADER: sbi_utils/reset/fdt_reset.h -TYPE: struct fdt_reset +TYPE: const struct fdt_driver NAME: fdt_reset_drivers
lib/utils/reset/fdt_reset_gpio.c +2 -2
@@ -153,7 +153,7 @@ static const struct fdt_match gpio_poweroff_match[] = { { }, }; -struct fdt_reset fdt_poweroff_gpio = { +const struct fdt_driver fdt_poweroff_gpio = { .match_table = gpio_poweroff_match, .init = gpio_reset_init, };
@@ -163,7 +163,7 @@ static const struct fdt_match gpio_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_gpio = { +const struct fdt_driver fdt_reset_gpio = { .match_table = gpio_reset_match, .init = gpio_reset_init, };
lib/utils/reset/fdt_reset_htif.c +1 -1
@@ -32,7 +32,7 @@ static const struct fdt_match htif_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_htif = { +const struct fdt_driver fdt_reset_htif = { .match_table = htif_reset_match, .init = htif_reset_init };
lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c +1 -1
@@ -108,7 +108,7 @@ static const struct fdt_match sg2042_mcu_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_sg2042_mcu = { +const struct fdt_driver fdt_reset_sg2042_mcu = { .match_table = sg2042_mcu_reset_match, .init = sg2042_mcu_reset_init, };
lib/utils/reset/fdt_reset_sunxi_wdt.c +1 -1
@@ -71,7 +71,7 @@ static const struct fdt_match sunxi_wdt_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_sunxi_wdt = { +const struct fdt_driver fdt_reset_sunxi_wdt = { .match_table = sunxi_wdt_reset_match, .init = sunxi_wdt_reset_init, };
lib/utils/reset/fdt_reset_syscon.c +2 -2
@@ -151,7 +151,7 @@ static const struct fdt_match syscon_poweroff_match[] = { { }, }; -struct fdt_reset fdt_syscon_poweroff = { +const struct fdt_driver fdt_syscon_poweroff = { .match_table = syscon_poweroff_match, .init = syscon_reset_init, };
@@ -161,7 +161,7 @@ static const struct fdt_match syscon_reboot_match[] = { { }, }; -struct fdt_reset fdt_syscon_reboot = { +const struct fdt_driver fdt_syscon_reboot = { .match_table = syscon_reboot_match, .init = syscon_reset_init, };
platform/generic/sifive/fu740.c +7 -2
@@ -209,11 +209,16 @@ static const struct fdt_match da9063_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_da9063 = { +const struct fdt_driver fdt_reset_da9063 = { .match_table = da9063_reset_match, .init = da9063_reset_init, }; +static const struct fdt_driver *const sifive_fu740_reset_drivers[] = { + &fdt_reset_da9063, +NULL +}; +static u64 sifive_fu740_tlbr_flush_limit (const struct fdt_match *match) {/*
@@ -232,7 +237,7 @@ static int sifive_fu740_final_init(bool cold_boot, void *fdt,int rc;if (cold_boot) { - rc =fdt_reset_driver_init (fdt, &fdt_reset_da9063); + rc =fdt_driver_init_one (fdt, sifive_fu740_reset_drivers);if (rc)sbi_printf ("%s: failed to find da9063 for reset\n" , __func__);
platform/generic/starfive/jh7110.c +7 -2
@@ -227,11 +227,16 @@ static const struct fdt_match pm_reset_match[] = { { }, }; -static struct fdt_reset fdt_reset_pmic = { +static const struct fdt_driver fdt_reset_pmic = { .match_table = pm_reset_match, .init = pm_reset_init, }; +static const struct fdt_driver *const starfive_jh7110_reset_drivers[] = { + &fdt_reset_pmic, +NULL +}; +static int starfive_jh7110_inst_init (const void *fdt) {int noff, rc =0 ;
@@ -281,7 +286,7 @@ static int starfive_jh7110_final_init(bool cold_boot, void *fdt, const struct fdt_match *match) {if (cold_boot) { -fdt_reset_driver_init (fdt, &fdt_reset_pmic); +fdt_driver_init_one (fdt, starfive_jh7110_reset_drivers); }return 0 ;
Signature · 1 line
2.45.1
PATCH v2 9/11 lib: utils/reset: Use fdt_driver for initialization
Quoted 9 lines · On Tue, Nov 12, 2024 at 3:33?AM Samuel Holland <[email protected]>…
The reset driver subsystem does not need any extra data, so it can use
struct fdt_driverdirectly. The genericfdt_reset_init()performs a best-effort initialization of all matching DT nodes. Platform-specific logic expects exactly one DT node to match a single driver. This is accomplished by usingfdt_driver_init_one()with a local list containing that one driver.Signed-off-by Samuel Holland <[email protected]>
LGTM.
Regards,
Anup
Quoted 279 lines
---
(no changes since v1)
include/sbi_utils/reset/fdt_reset.h | 15 +------- lib/utils/reset/fdt_reset.c | 36 ++------------------ lib/utils/reset/fdt_reset_atcwdt200.c | 2 +- lib/utils/reset/fdt_reset_drivers.carray | 2 +- lib/utils/reset/fdt_reset_gpio.c | 4 +-- lib/utils/reset/fdt_reset_htif.c | 2 +- lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c | 2 +- lib/utils/reset/fdt_reset_sunxi_wdt.c | 2 +- lib/utils/reset/fdt_reset_syscon.c | 4 +-- platform/generic/sifive/fu740.c | 9 +++-- platform/generic/starfive/jh7110.c | 9 +++-- 11 files changed, 26 insertions(+), 61 deletions(-)include/sbi_utils/reset/fdt_reset.h +1
-14@@ -11,19 +11,10 @@#define __FDT_RESET_H__#include <sbi/sbi_types.h> - -struct fdt_reset { -const struct fdt_match *match_table; -int (*init)(const void *fdt,int nodeoff,const struct fdt_match *match); -}; +#include <sbi_utils/fdt/fdt_driver.h> #ifdef CONFIG_FDT_RESET -/** -* fdt_reset_driver_init() - initialize reset driver based on the device-tree -*/ -int fdt_reset_driver_init (const void *fdt,struct fdt_reset *drv); -/** * fdt_reset_init() - initialize reset drivers based on the device-tree * @@ -33,10 +24,6 @@ void fdt_reset_init(const void *fdt);#else -static inline int fdt_reset_driver_init (const void *fdt,struct fdt_reset *drv) -{ -return 0 ; -}static inline void fdt_reset_init (const void *fdt) { }#endif lib/utils/reset/fdt_reset.c +2
-34@@ -7,44 +7,12 @@* Anup Patel <[email protected]> */ -#include <sbi/sbi_console.h> -#include <sbi/sbi_error.h> -#include <sbi/sbi_scratch.h> -#include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/reset/fdt_reset.h> /* List of FDT reset drivers generated at compile time */ -extern struct fdt_reset *const fdt_reset_drivers[]; - -int fdt_reset_driver_init (const void *fdt,struct fdt_reset *drv) -{ -int noff, rc, cnt =0 ; -const struct fdt_match *match; - - noff =-1 ; -while ((noff =fdt_find_match (fdt, noff, - drv->match_table, &match)) >=0 ) { -if (!fdt_node_is_enabled (fdt, noff)) -continue ; - -if (drv->init) { - rc = drv->init (fdt, noff, match); -if (!rc) - cnt++; -else if (rc !=SBI_ENODEV ) { -sbi_printf ("%s: %s init failed, %d\n" , - __func__, match->compatible, rc); - } - } - } - -return cnt >0 ?0 :SBI_ENODEV ; -} +extern const struct fdt_driver *const fdt_reset_drivers[];void fdt_reset_init (const void *fdt) { -int pos; - -for (pos =0 ; fdt_reset_drivers[pos]; pos++) -fdt_reset_driver_init (fdt, fdt_reset_drivers[pos]); +fdt_driver_init_all (fdt, fdt_reset_drivers); }lib/utils/reset/fdt_reset_atcwdt200.c +1
-1@@ -111,7 +111,7 @@ static const struct fdt_match atcwdt200_reset_match[] = { {}, }; -struct fdt_reset fdt_reset_atcwdt200 = { +const struct fdt_driver fdt_reset_atcwdt200 = { .match_table = atcwdt200_reset_match, .init = atcwdt200_reset_init, };lib/utils/reset/fdt_reset_drivers.carray +1
-1@@ -1,3 +1,3 @@ HEADER: sbi_utils/reset/fdt_reset.h -TYPE: struct fdt_reset +TYPE: const struct fdt_driver NAME: fdt_reset_driverslib/utils/reset/fdt_reset_gpio.c +2
-2@@ -153,7 +153,7 @@ static const struct fdt_match gpio_poweroff_match[] = { { }, }; -struct fdt_reset fdt_poweroff_gpio = { +const struct fdt_driver fdt_poweroff_gpio = { .match_table = gpio_poweroff_match, .init = gpio_reset_init, };@@ -163,7 +163,7 @@ static const struct fdt_match gpio_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_gpio = { +const struct fdt_driver fdt_reset_gpio = { .match_table = gpio_reset_match, .init = gpio_reset_init, };lib/utils/reset/fdt_reset_htif.c +1
-1@@ -32,7 +32,7 @@ static const struct fdt_match htif_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_htif = { +const struct fdt_driver fdt_reset_htif = { .match_table = htif_reset_match, .init = htif_reset_init };lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c +1
-1@@ -108,7 +108,7 @@ static const struct fdt_match sg2042_mcu_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_sg2042_mcu = { +const struct fdt_driver fdt_reset_sg2042_mcu = { .match_table = sg2042_mcu_reset_match, .init = sg2042_mcu_reset_init, };lib/utils/reset/fdt_reset_sunxi_wdt.c +1
-1@@ -71,7 +71,7 @@ static const struct fdt_match sunxi_wdt_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_sunxi_wdt = { +const struct fdt_driver fdt_reset_sunxi_wdt = { .match_table = sunxi_wdt_reset_match, .init = sunxi_wdt_reset_init, };lib/utils/reset/fdt_reset_syscon.c +2
-2@@ -151,7 +151,7 @@ static const struct fdt_match syscon_poweroff_match[] = { { }, }; -struct fdt_reset fdt_syscon_poweroff = { +const struct fdt_driver fdt_syscon_poweroff = { .match_table = syscon_poweroff_match, .init = syscon_reset_init, };@@ -161,7 +161,7 @@ static const struct fdt_match syscon_reboot_match[] = { { }, }; -struct fdt_reset fdt_syscon_reboot = { +const struct fdt_driver fdt_syscon_reboot = { .match_table = syscon_reboot_match, .init = syscon_reset_init, };platform/generic/sifive/fu740.c +7
-2@@ -209,11 +209,16 @@ static const struct fdt_match da9063_reset_match[] = { { }, }; -struct fdt_reset fdt_reset_da9063 = { +const struct fdt_driver fdt_reset_da9063 = { .match_table = da9063_reset_match, .init = da9063_reset_init, }; +static const struct fdt_driver *const sifive_fu740_reset_drivers[] = { + &fdt_reset_da9063, +NULL +}; +static u64 sifive_fu740_tlbr_flush_limit (const struct fdt_match *match) {/* @@ -232,7 +237,7 @@ static int sifive_fu740_final_init(bool cold_boot, void *fdt,int rc;if (cold_boot) { - rc =fdt_reset_driver_init (fdt, &fdt_reset_da9063); + rc =fdt_driver_init_one (fdt, sifive_fu740_reset_drivers);if (rc)sbi_printf ("%s: failed to find da9063 for reset\n" , __func__);platform/generic/starfive/jh7110.c +7
-3@@ -227,11 +227,16 @@ static const struct fdt_match pm_reset_match[] = { { }, }; -static struct fdt_reset fdt_reset_pmic = { +static const struct fdt_driver fdt_reset_pmic = { .match_table = pm_reset_match, .init = pm_reset_init, }; +static const struct fdt_driver *const starfive_jh7110_reset_drivers[] = { + &fdt_reset_pmic, +NULL +}; +static int starfive_jh7110_inst_init (const void *fdt) {int noff, rc =0 ;@@ -281,7 +286,7 @@ static int starfive_jh7110_final_init(bool cold_boot, void *fdt, const struct fdt_match *match) {if (cold_boot) { -fdt_reset_driver_init (fdt, &fdt_reset_pmic); +fdt_driver_init_one (fdt, starfive_jh7110_reset_drivers); }return 0 ; --2.45.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Samuel Holland
maintainerPATCH v2 10/11 lib: utils/serial: Use fdt_driver for initialization
In reply to Samuel HollandThe serial driver subsystem does not need any extra data, so it can use struct fdt_driver directly. The generic fdt_serial_init() first attempts to match the chosen stdout device, and upon failure matches the first available serial device in the DT. It is a fatal error if no such device is found. This matches the behavior of fdt_driver_init_one().
---
(no changes since v1)
include/sbi_utils/serial/fdt_serial.h | 6 +-- lib/utils/serial/fdt_serial.c | 52 +++------------------ lib/utils/serial/fdt_serial_cadence.c | 2 +- lib/utils/serial/fdt_serial_drivers.carray | 2 +- lib/utils/serial/fdt_serial_gaisler.c | 2 +- lib/utils/serial/fdt_serial_htif.c | 2 +- lib/utils/serial/fdt_serial_litex.c | 2 +- lib/utils/serial/fdt_serial_renesas_scif.c | 2 +- lib/utils/serial/fdt_serial_shakti.c | 2 +- lib/utils/serial/fdt_serial_sifive.c | 2 +- lib/utils/serial/fdt_serial_uart8250.c | 2 +- lib/utils/serial/fdt_serial_xlnx_uartlite.c | 2 +- 12 files changed, 18 insertions(+), 60 deletions(-)
include/sbi_utils/serial/fdt_serial.h +1 -5
@@ -11,14 +11,10 @@#define __FDT_SERIAL_H__#include <sbi/sbi_types.h> +#include <sbi_utils/fdt/fdt_driver.h> #ifdef CONFIG_FDT_SERIAL -struct fdt_serial { -const struct fdt_match *match_table; -int (*init)(const void *fdt,int nodeoff,const struct fdt_match *match); -}; -int fdt_serial_init (const void *fdt);#else
lib/utils/serial/fdt_serial.c +7 -45
76 lines not on this page · raw message
lib/utils/serial/fdt_serial_cadence.c +1 -1
@@ -30,7 +30,7 @@ static const struct fdt_match serial_cadence_match[] = { { }, }; -struct fdt_serial fdt_serial_cadence = { +const struct fdt_driver fdt_serial_cadence = { .match_table = serial_cadence_match, .init = serial_cadence_init };
lib/utils/serial/fdt_serial_drivers.carray +1 -1
@@ -1,3 +1,3 @@ HEADER: sbi_utils/serial/fdt_serial.h -TYPE: struct fdt_serial +TYPE: const struct fdt_driver NAME: fdt_serial_drivers
lib/utils/serial/fdt_serial_gaisler.c +1 -1
@@ -29,7 +29,7 @@ static const struct fdt_match serial_gaisler_match[] = { {}, }; -struct fdt_serial fdt_serial_gaisler = { +const struct fdt_driver fdt_serial_gaisler = { .match_table = serial_gaisler_match, .init = serial_gaisler_init };
lib/utils/serial/fdt_serial_htif.c +1 -1
@@ -41,7 +41,7 @@ static int serial_htif_init(const void *fdt, int nodeoff,return htif_serial_init (custom, fromhost_addr, tohost_addr); } -struct fdt_serial fdt_serial_htif = { +const struct fdt_driver fdt_serial_htif = { .match_table = serial_htif_match, .init = serial_htif_init };
lib/utils/serial/fdt_serial_litex.c +1 -1
@@ -33,7 +33,7 @@ static const struct fdt_match serial_litex_match[] = { { }, }; -struct fdt_serial fdt_serial_litex = { +const struct fdt_driver fdt_serial_litex = { .match_table = serial_litex_match, .init = serial_litex_init };
lib/utils/serial/fdt_serial_renesas_scif.c +1 -1
@@ -25,7 +25,7 @@ static const struct fdt_match serial_renesas_scif_match[] = { {/* sentinel */ } }; -struct fdt_serial fdt_serial_renesas_scif = { +const struct fdt_driver fdt_serial_renesas_scif = { .match_table = serial_renesas_scif_match, .init = serial_renesas_scif_init };
lib/utils/serial/fdt_serial_shakti.c +1 -1
@@ -27,7 +27,7 @@ static const struct fdt_match serial_shakti_match[] = { { }, }; -struct fdt_serial fdt_serial_shakti = { +const struct fdt_driver fdt_serial_shakti = { .match_table = serial_shakti_match, .init = serial_shakti_init };
lib/utils/serial/fdt_serial_sifive.c +1 -1
@@ -30,7 +30,7 @@ static const struct fdt_match serial_sifive_match[] = { { }, }; -struct fdt_serial fdt_serial_sifive = { +const struct fdt_driver fdt_serial_sifive = { .match_table = serial_sifive_match, .init = serial_sifive_init };
lib/utils/serial/fdt_serial_uart8250.c +1 -1
@@ -33,7 +33,7 @@ static const struct fdt_match serial_uart8250_match[] = { { }, }; -struct fdt_serial fdt_serial_uart8250 = { +const struct fdt_driver fdt_serial_uart8250 = { .match_table = serial_uart8250_match, .init = serial_uart8250_init, };
lib/utils/serial/fdt_serial_xlnx_uartlite.c +1 -1
@@ -29,7 +29,7 @@ static const struct fdt_match serial_xlnx_uartlite_match[] = { { }, }; -struct fdt_serial fdt_serial_xlnx_uartlite = { +const struct fdt_driver fdt_serial_xlnx_uartlite = { .match_table = serial_xlnx_uartlite_match, .init = serial_xlnx_uartlite_init, };
Signature · 1 line
2.45.1
PATCH v2 10/11 lib: utils/serial: Use fdt_driver for initialization
Quoted 8 lines · On Tue, Nov 12, 2024 at 3:33?AM Samuel Holland <[email protected]>…
The serial driver subsystem does not need any extra data, so it can use
struct fdt_driverdirectly. The genericfdt_serial_init()first attempts to match the chosen stdout device, and upon failure matches the first available serial device in the DT. It is a fatal error if no such device is found. This matches the behavior offdt_driver_init_one().Signed-off-by Samuel Holland <[email protected]>
LGTM.
Regards,
Anup
Quoted 254 lines
---
(no changes since v1)
include/sbi_utils/serial/fdt_serial.h | 6 +-- lib/utils/serial/fdt_serial.c | 52 +++------------------ lib/utils/serial/fdt_serial_cadence.c | 2 +- lib/utils/serial/fdt_serial_drivers.carray | 2 +- lib/utils/serial/fdt_serial_gaisler.c | 2 +- lib/utils/serial/fdt_serial_htif.c | 2 +- lib/utils/serial/fdt_serial_litex.c | 2 +- lib/utils/serial/fdt_serial_renesas_scif.c | 2 +- lib/utils/serial/fdt_serial_shakti.c | 2 +- lib/utils/serial/fdt_serial_sifive.c | 2 +- lib/utils/serial/fdt_serial_uart8250.c | 2 +- lib/utils/serial/fdt_serial_xlnx_uartlite.c | 2 +- 12 files changed, 18 insertions(+), 60 deletions(-)include/sbi_utils/serial/fdt_serial.h +1
-5@@ -11,14 +11,10 @@#define __FDT_SERIAL_H__#include <sbi/sbi_types.h> +#include <sbi_utils/fdt/fdt_driver.h> #ifdef CONFIG_FDT_SERIAL -struct fdt_serial { -const struct fdt_match *match_table; -int (*init)(const void *fdt,int nodeoff,const struct fdt_match *match); -}; -int fdt_serial_init (const void *fdt);#else lib/utils/serial/fdt_serial.c +7
-45@@ -9,19 +9,16 @@#include <libfdt.h> #include <sbi/sbi_error.h> -#include <sbi/sbi_scratch.h> #include <sbi_utils/fdt/fdt_helper.h> #include <sbi_utils/serial/fdt_serial.h> /* List of FDT serial drivers generated at compile time */ -extern struct fdt_serial *const fdt_serial_drivers[]; +extern const struct fdt_driver *const fdt_serial_drivers[];int fdt_serial_init (const void *fdt) {const void *prop; -struct fdt_serial *drv; -const struct fdt_match *match; -int pos, noff =-1 , len, coff, rc; +int noff =-1 , len, coff, rc;/* Find offset of node pointed to by stdout-path */ coff =fdt_path_offset (fdt,"/chosen" );@@ -38,50 +35,15 @@ int fdt_serial_init(const void *fdt)else noff =fdt_path_offset (fdt, prop); } -if (-1 < noff) { -if (!fdt_node_is_enabled (fdt, noff)) - noff =-1 ; - } }/* First check DT node pointed by stdout-path */ -for (pos =0 ; fdt_serial_drivers[pos] &&-1 < noff; pos++) { - drv = fdt_serial_drivers[pos]; - - match =fdt_match_node (fdt, noff, drv->match_table); -if (!match) -continue ; - -/* drv->init must not be NULL */ -if (drv->init ==NULL ) -return SBI_EFAIL ; - - rc = drv->init (fdt, noff, match); -if (rc ==SBI_ENODEV ) -continue ; -return rc; - } - -/* Lastly check all DT nodes */ -for (pos =0 ; fdt_serial_drivers[pos]; pos++) { - drv = fdt_serial_drivers[pos]; - - noff =-1 ; -while ((noff =fdt_find_match (fdt, noff, - drv->match_table, &match)) >=0 ) { -if (!fdt_node_is_enabled (fdt, noff)) -continue ; - -/* drv->init must not be NULL */ -if (drv->init ==NULL ) -return SBI_EFAIL ; - - rc = drv->init (fdt, noff, match); -if (rc ==SBI_ENODEV ) -continue ; +if (-1 < noff) { + rc =fdt_driver_init_by_offset (fdt, noff, fdt_serial_drivers); +if (rc !=SBI_ENODEV )return rc; - } } -return SBI_ENODEV ; +/* Lastly check all DT nodes */ +return fdt_driver_init_one (fdt, fdt_serial_drivers); }lib/utils/serial/fdt_serial_cadence.c +1
-1@@ -30,7 +30,7 @@ static const struct fdt_match serial_cadence_match[] = { { }, }; -struct fdt_serial fdt_serial_cadence = { +const struct fdt_driver fdt_serial_cadence = { .match_table = serial_cadence_match, .init = serial_cadence_init };lib/utils/serial/fdt_serial_drivers.carray +1
-1@@ -1,3 +1,3 @@ HEADER: sbi_utils/serial/fdt_serial.h -TYPE: struct fdt_serial +TYPE: const struct fdt_driver NAME: fdt_serial_driverslib/utils/serial/fdt_serial_gaisler.c +1
-1@@ -29,7 +29,7 @@ static const struct fdt_match serial_gaisler_match[] = { {}, }; -struct fdt_serial fdt_serial_gaisler = { +const struct fdt_driver fdt_serial_gaisler = { .match_table = serial_gaisler_match, .init = serial_gaisler_init };lib/utils/serial/fdt_serial_htif.c +1
-1@@ -41,7 +41,7 @@ static int serial_htif_init(const void *fdt, int nodeoff,return htif_serial_init (custom, fromhost_addr, tohost_addr); } -struct fdt_serial fdt_serial_htif = { +const struct fdt_driver fdt_serial_htif = { .match_table = serial_htif_match, .init = serial_htif_init };lib/utils/serial/fdt_serial_litex.c +1
-1@@ -33,7 +33,7 @@ static const struct fdt_match serial_litex_match[] = { { }, }; -struct fdt_serial fdt_serial_litex = { +const struct fdt_driver fdt_serial_litex = { .match_table = serial_litex_match, .init = serial_litex_init };lib/utils/serial/fdt_serial_renesas_scif.c +1
-1@@ -25,7 +25,7 @@ static const struct fdt_match serial_renesas_scif_match[] = { {/* sentinel */ } }; -struct fdt_serial fdt_serial_renesas_scif = { +const struct fdt_driver fdt_serial_renesas_scif = { .match_table = serial_renesas_scif_match, .init = serial_renesas_scif_init };lib/utils/serial/fdt_serial_shakti.c +1
-1@@ -27,7 +27,7 @@ static const struct fdt_match serial_shakti_match[] = { { }, }; -struct fdt_serial fdt_serial_shakti = { +const struct fdt_driver fdt_serial_shakti = { .match_table = serial_shakti_match, .init = serial_shakti_init };lib/utils/serial/fdt_serial_sifive.c +1
-1@@ -30,7 +30,7 @@ static const struct fdt_match serial_sifive_match[] = { { }, }; -struct fdt_serial fdt_serial_sifive = { +const struct fdt_driver fdt_serial_sifive = { .match_table = serial_sifive_match, .init = serial_sifive_init };lib/utils/serial/fdt_serial_uart8250.c +1
-1@@ -33,7 +33,7 @@ static const struct fdt_match serial_uart8250_match[] = { { }, }; -struct fdt_serial fdt_serial_uart8250 = { +const struct fdt_driver fdt_serial_uart8250 = { .match_table = serial_uart8250_match, .init = serial_uart8250_init, };lib/utils/serial/fdt_serial_xlnx_uartlite.c +1
-2@@ -29,7 +29,7 @@ static const struct fdt_match serial_xlnx_uartlite_match[] = { { }, }; -struct fdt_serial fdt_serial_xlnx_uartlite = { +const struct fdt_driver fdt_serial_xlnx_uartlite = { .match_table = serial_xlnx_uartlite_match, .init = serial_xlnx_uartlite_init, }; --2.45.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Samuel Holland
maintainerPATCH v2 11/11 lib: utils/timer: Use fdt_driver for initialization
In reply to Samuel HollandThe timer driver subsystem does not need any extra data, so it can use struct fdt_driver directly. The generic fdt_timer_init() performs a best-effort initialization of all matching DT nodes.
---
Changes in v2:
- New patch for v2
include/sbi_utils/timer/fdt_timer.h | 6 +--- lib/utils/timer/fdt_timer.c | 39 +++--------------------- lib/utils/timer/fdt_timer_drivers.carray | 2 +- lib/utils/timer/fdt_timer_mtimer.c | 4 +-- lib/utils/timer/fdt_timer_plmt.c | 4 +-- 5 files changed, 10 insertions(+), 45 deletions(-)
include/sbi_utils/timer/fdt_timer.h +1 -5
@@ -11,14 +11,10 @@#define __FDT_TIMER_H__#include <sbi/sbi_types.h> +#include <sbi_utils/fdt/fdt_driver.h> #ifdef CONFIG_FDT_TIMER -struct fdt_timer { -const struct fdt_match *match_table; -int (*cold_init)(const void *fdt,int nodeoff,const struct fdt_match *match); -}; -int fdt_timer_init (void );#else
lib/utils/timer/fdt_timer.c +4 -35
@@ -13,44 +13,13 @@#include <sbi_utils/timer/fdt_timer.h> /* List of FDT timer drivers generated at compile time */ -extern struct fdt_timer *const fdt_timer_drivers[]; +extern const struct fdt_driver *const fdt_timer_drivers[];int fdt_timer_init (void ) { -int pos, noff, rc; -struct fdt_timer *drv; -const struct fdt_match *match; -const void *fdt =fdt_get_address (); - -for (pos =0 ; fdt_timer_drivers[pos]; pos++) { - drv = fdt_timer_drivers[pos]; - - noff =-1 ; -while ((noff =fdt_find_match (fdt, noff, - drv->match_table, &match)) >=0 ) { -if (!fdt_node_is_enabled (fdt, noff)) -continue ; - -/* drv->cold_init must not be NULL */ -if (drv->cold_init ==NULL ) -return SBI_EFAIL ; - - rc = drv->cold_init (fdt, noff, match); -if (rc ==SBI_ENODEV ) -continue ; -if (rc) -return rc; - -/* -* We will have multiple timer devices on multi-die or -* multi-socket systems so we cannot break here. -*/ - } - } -/* -* We can't fail here since systems with Sstc might not provide -* mtimer/clint DT node in the device tree. +* Systems with Sstc might not provide any node in the FDT, +* so do not return a failure if no device is found. */ -return 0 ; +return fdt_driver_init_all (fdt_get_address (), fdt_timer_drivers); }
lib/utils/timer/fdt_timer_drivers.carray +1 -1
@@ -1,3 +1,3 @@ HEADER: sbi_utils/timer/fdt_timer.h -TYPE: struct fdt_timer +TYPE: const struct fdt_driver NAME: fdt_timer_drivers
lib/utils/timer/fdt_timer_mtimer.c +2 -2
@@ -162,7 +162,7 @@ static const struct fdt_match timer_mtimer_match[] = { { }, }; -struct fdt_timer fdt_timer_mtimer = { +const struct fdt_driver fdt_timer_mtimer = { .match_table = timer_mtimer_match, - .cold_init = timer_mtimer_cold_init, + .init = timer_mtimer_cold_init, };
lib/utils/timer/fdt_timer_plmt.c +2 -2
@@ -43,7 +43,7 @@ static const struct fdt_match timer_plmt_match[] = { {}, }; -struct fdt_timer fdt_timer_plmt = { +const struct fdt_driver fdt_timer_plmt = { .match_table = timer_plmt_match, - .cold_init = fdt_plmt_cold_timer_init, + .init = fdt_plmt_cold_timer_init, };
Signature · 1 line
2.45.1
PATCH v2 11/11 lib: utils/timer: Use fdt_driver for initialization
Quoted 6 lines · On Tue, Nov 12, 2024 at 4:45?AM Samuel Holland <[email protected]>…
The timer driver subsystem does not need any extra data, so it can use
struct fdt_driverdirectly. The genericfdt_timer_init()performs a best-effort initialization of all matching DT nodes.Signed-off-by Samuel Holland <[email protected]>
LGTM.
Regards,
Anup
Quoted 130 lines
---
Changes in v2:
- New patch for v2include/sbi_utils/timer/fdt_timer.h | 6 +--- lib/utils/timer/fdt_timer.c | 39 +++--------------------- lib/utils/timer/fdt_timer_drivers.carray | 2 +- lib/utils/timer/fdt_timer_mtimer.c | 4 +-- lib/utils/timer/fdt_timer_plmt.c | 4 +-- 5 files changed, 10 insertions(+), 45 deletions(-)include/sbi_utils/timer/fdt_timer.h +1
-5@@ -11,14 +11,10 @@#define __FDT_TIMER_H__#include <sbi/sbi_types.h> +#include <sbi_utils/fdt/fdt_driver.h> #ifdef CONFIG_FDT_TIMER -struct fdt_timer { -const struct fdt_match *match_table; -int (*cold_init)(const void *fdt,int nodeoff,const struct fdt_match *match); -}; -int fdt_timer_init (void );#else lib/utils/timer/fdt_timer.c +4
-35@@ -13,44 +13,13 @@#include <sbi_utils/timer/fdt_timer.h> /* List of FDT timer drivers generated at compile time */ -extern struct fdt_timer *const fdt_timer_drivers[]; +extern const struct fdt_driver *const fdt_timer_drivers[];int fdt_timer_init (void ) { -int pos, noff, rc; -struct fdt_timer *drv; -const struct fdt_match *match; -const void *fdt =fdt_get_address (); - -for (pos =0 ; fdt_timer_drivers[pos]; pos++) { - drv = fdt_timer_drivers[pos]; - - noff =-1 ; -while ((noff =fdt_find_match (fdt, noff, - drv->match_table, &match)) >=0 ) { -if (!fdt_node_is_enabled (fdt, noff)) -continue ; - -/* drv->cold_init must not be NULL */ -if (drv->cold_init ==NULL ) -return SBI_EFAIL ; - - rc = drv->cold_init (fdt, noff, match); -if (rc ==SBI_ENODEV ) -continue ; -if (rc) -return rc; - -/* -* We will have multiple timer devices on multi-die or -* multi-socket systems so we cannot break here. -*/ - } - } -/* -* We can't fail here since systems with Sstc might not provide -* mtimer/clint DT node in the device tree. +* Systems with Sstc might not provide any node in the FDT, +* so do not return a failure if no device is found. */ -return 0 ; +return fdt_driver_init_all (fdt_get_address (), fdt_timer_drivers); }lib/utils/timer/fdt_timer_drivers.carray +1
-1@@ -1,3 +1,3 @@ HEADER: sbi_utils/timer/fdt_timer.h -TYPE: struct fdt_timer +TYPE: const struct fdt_driver NAME: fdt_timer_driverslib/utils/timer/fdt_timer_mtimer.c +2
-2@@ -162,7 +162,7 @@ static const struct fdt_match timer_mtimer_match[] = { { }, }; -struct fdt_timer fdt_timer_mtimer = { +const struct fdt_driver fdt_timer_mtimer = { .match_table = timer_mtimer_match, - .cold_init = timer_mtimer_cold_init, + .init = timer_mtimer_cold_init, };lib/utils/timer/fdt_timer_plmt.c +2
-3@@ -43,7 +43,7 @@ static const struct fdt_match timer_plmt_match[] = { {}, }; -struct fdt_timer fdt_timer_plmt = { +const struct fdt_driver fdt_timer_plmt = { .match_table = timer_plmt_match, - .cold_init = fdt_plmt_cold_timer_init, + .init = fdt_plmt_cold_timer_init, }; --2.45.1
--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
Anup Patel
Appliedv2 cover Deduplicate driver initialization code
In reply to Samuel HollandQuoted 22 lines · On Tue, Nov 12, 2024 at 3:33?AM Samuel Holland <[email protected]>…
Upstreaming support for some of SiFive's security and power management features will require adding some new driver subsystems (e.g. caches, WorldGuard gadgets, power management domains, etc.). To avoid copy-and- pasting the FDT-based driver matching code to each new subsystem, this series refactors it into some efficient and easily-reusable helper functions.
Version 2 of this series converts everything but the irqchip subsystem to use the new helpers. Once the irqchip subsystem is converted, the old
fdt_find_match()helper can be removed. The following series prepares the irqchip subsystem for conversion to use thefdt_driverhelpers:
http://lists.infradead.org/pipermail/opensbi/2024-November/007555.htmlChanges in v2:
- Shell script cleanup incarray.sh
- Updatecarray.shto support embedding structfdt_driver
- Add conversion of gpio drivers
- Add conversion of ipi drivers
- Add conversion of regmap drivers
- Add conversion of timer drivers
Quoted 12 lines
Samuel Holland (11):
treewide: Make carray arrays const and NULL-terminated
lib: utils/fdt: Add helpers for generic driver initializationscripts/carray.sh: Avoid useless use of catscripts/carray.sh: Allow referencing a struct member
lib: utils/gpio: Usefdt_driverfor initialization
lib: utils/i2c: Usefdt_driverfor initialization
lib: utils/ipi: Usefdt_driverfor initialization
lib: utils/regmap: Usefdt_driverfor initialization
lib: utils/reset: Usefdt_driverfor initialization
lib: utils/serial: Usefdt_driverfor initialization
lib: utils/timer: Usefdt_driverfor initialization
Very nice improvements !
Great work !
Applied this series to the riscv/opensbi repo.
Thanks,
Anup
Quoted 70 lines
include/sbi_utils/fdt/fdt_driver.h | 59 +++++++++++++++ include/sbi_utils/gpio/fdt_gpio.h | 5 +- include/sbi_utils/gpio/gpio.h | 2 +- include/sbi_utils/i2c/fdt_i2c.h | 8 +- include/sbi_utils/ipi/fdt_ipi.h | 6 +- include/sbi_utils/regmap/fdt_regmap.h | 8 +- include/sbi_utils/reset/fdt_reset.h | 15 +--- include/sbi_utils/serial/fdt_serial.h | 6 +- include/sbi_utils/timer/fdt_timer.h | 6 +- lib/sbi/sbi_ecall.c | 5 +- lib/sbi/tests/sbi_unit_test.c | 5 +- lib/utils/fdt/fdt_driver.c | 80 ++++++++++++++++++++ lib/utils/fdt/objects.mk | 1 + lib/utils/gpio/fdt_gpio.c | 28 +------ lib/utils/gpio/fdt_gpio_designware.c | 10 ++- lib/utils/gpio/fdt_gpio_drivers.carray | 4 +- lib/utils/gpio/fdt_gpio_sifive.c | 10 ++- lib/utils/gpio/fdt_gpio_starfive.c | 10 ++- lib/utils/i2c/fdt_i2c.c | 31 +------- lib/utils/i2c/fdt_i2c_adapter_drivers.carray | 2 +- lib/utils/i2c/fdt_i2c_dw.c | 2 +- lib/utils/i2c/fdt_i2c_sifive.c | 2 +- lib/utils/ipi/fdt_ipi.c | 43 +---------- lib/utils/ipi/fdt_ipi_drivers.carray | 2 +- lib/utils/ipi/fdt_ipi_mswi.c | 4 +- lib/utils/ipi/fdt_ipi_plicsw.c | 4 +- lib/utils/irqchip/fdt_irqchip.c | 5 +- lib/utils/regmap/fdt_regmap.c | 29 +------ lib/utils/regmap/fdt_regmap_drivers.carray | 2 +- lib/utils/regmap/fdt_regmap_syscon.c | 2 +- lib/utils/reset/fdt_reset.c | 37 +-------- lib/utils/reset/fdt_reset_atcwdt200.c | 2 +- lib/utils/reset/fdt_reset_drivers.carray | 2 +- lib/utils/reset/fdt_reset_gpio.c | 4 +- lib/utils/reset/fdt_reset_htif.c | 2 +- lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c | 2 +- lib/utils/reset/fdt_reset_sunxi_wdt.c | 2 +- lib/utils/reset/fdt_reset_syscon.c | 4 +- lib/utils/serial/fdt_serial.c | 53 ++----------- lib/utils/serial/fdt_serial_cadence.c | 2 +- lib/utils/serial/fdt_serial_drivers.carray | 2 +- lib/utils/serial/fdt_serial_gaisler.c | 2 +- lib/utils/serial/fdt_serial_htif.c | 2 +- lib/utils/serial/fdt_serial_litex.c | 2 +- lib/utils/serial/fdt_serial_renesas_scif.c | 2 +- lib/utils/serial/fdt_serial_shakti.c | 2 +- lib/utils/serial/fdt_serial_sifive.c | 2 +- lib/utils/serial/fdt_serial_uart8250.c | 2 +- lib/utils/serial/fdt_serial_xlnx_uartlite.c | 2 +- lib/utils/timer/fdt_timer.c | 40 +--------- lib/utils/timer/fdt_timer_drivers.carray | 2 +- lib/utils/timer/fdt_timer_mtimer.c | 4 +- lib/utils/timer/fdt_timer_plmt.c | 4 +- platform/generic/platform.c | 5 +- platform/generic/sifive/fu740.c | 9 ++- platform/generic/starfive/jh7110.c | 9 ++- scripts/carray.sh | 22 ++++-- 57 files changed, 267 insertions(+), 352 deletions(-) create mode 100644 include/sbi_utils/fdt/fdt_driver.h create mode 100644 lib/utils/fdt/fdt_driver.c--
2.45.1--
opensbi mailing list
opensbi at lists.infradead.org
http://lists.infradead.org/mailman/listinfo/opensbi
v2 cover Deduplicate driver initialization code
In reply to Samuel HollandQuoted 7 lines · Samuel Holland
Upstreaming support for some of SiFive's security and power management features will require adding some new driver subsystems (e.g. caches, WorldGuard gadgets, power management domains, etc.). To avoid copy-and- pasting the FDT-based driver matching code to each new subsystem, this series refactors it into some efficient and easily-reusable helper functions.
Quoted 5 lines
Version 2 of this series converts everything but the irqchip subsystem to use the new helpers. Once the irqchip subsystem is converted, the old
fdt_find_match()helper can be removed. The following series prepares the irqchip subsystem for conversion to use thefdt_driverhelpers:
http://lists.infradead.org/pipermail/opensbi/2024-November/007555.html
Is there a branch with this on?
Quoted 82 lines
Changes in v2:
- Shell script cleanup incarray.sh
- Updatecarray.shto support embedding structfdt_driver
- Add conversion of gpio drivers
- Add conversion of ipi drivers
- Add conversion of regmap drivers
- Add conversion of timer driversSamuel Holland (11):
treewide: Make carray arrays const and NULL-terminated
lib: utils/fdt: Add helpers for generic driver initializationscripts/carray.sh: Avoid useless use of catscripts/carray.sh: Allow referencing a struct member
lib: utils/gpio: Usefdt_driverfor initialization
lib: utils/i2c: Usefdt_driverfor initialization
lib: utils/ipi: Usefdt_driverfor initialization
lib: utils/regmap: Usefdt_driverfor initialization
lib: utils/reset: Usefdt_driverfor initialization
lib: utils/serial: Usefdt_driverfor initialization
lib: utils/timer: Usefdt_driverfor initializationinclude/sbi_utils/fdt/fdt_driver.h | 59 +++++++++++++++ include/sbi_utils/gpio/fdt_gpio.h | 5 +- include/sbi_utils/gpio/gpio.h | 2 +- include/sbi_utils/i2c/fdt_i2c.h | 8 +- include/sbi_utils/ipi/fdt_ipi.h | 6 +- include/sbi_utils/regmap/fdt_regmap.h | 8 +- include/sbi_utils/reset/fdt_reset.h | 15 +--- include/sbi_utils/serial/fdt_serial.h | 6 +- include/sbi_utils/timer/fdt_timer.h | 6 +- lib/sbi/sbi_ecall.c | 5 +- lib/sbi/tests/sbi_unit_test.c | 5 +- lib/utils/fdt/fdt_driver.c | 80 ++++++++++++++++++++ lib/utils/fdt/objects.mk | 1 + lib/utils/gpio/fdt_gpio.c | 28 +------ lib/utils/gpio/fdt_gpio_designware.c | 10 ++- lib/utils/gpio/fdt_gpio_drivers.carray | 4 +- lib/utils/gpio/fdt_gpio_sifive.c | 10 ++- lib/utils/gpio/fdt_gpio_starfive.c | 10 ++- lib/utils/i2c/fdt_i2c.c | 31 +------- lib/utils/i2c/fdt_i2c_adapter_drivers.carray | 2 +- lib/utils/i2c/fdt_i2c_dw.c | 2 +- lib/utils/i2c/fdt_i2c_sifive.c | 2 +- lib/utils/ipi/fdt_ipi.c | 43 +---------- lib/utils/ipi/fdt_ipi_drivers.carray | 2 +- lib/utils/ipi/fdt_ipi_mswi.c | 4 +- lib/utils/ipi/fdt_ipi_plicsw.c | 4 +- lib/utils/irqchip/fdt_irqchip.c | 5 +- lib/utils/regmap/fdt_regmap.c | 29 +------ lib/utils/regmap/fdt_regmap_drivers.carray | 2 +- lib/utils/regmap/fdt_regmap_syscon.c | 2 +- lib/utils/reset/fdt_reset.c | 37 +-------- lib/utils/reset/fdt_reset_atcwdt200.c | 2 +- lib/utils/reset/fdt_reset_drivers.carray | 2 +- lib/utils/reset/fdt_reset_gpio.c | 4 +- lib/utils/reset/fdt_reset_htif.c | 2 +- lib/utils/reset/fdt_reset_sg2042_hwmon_mcu.c | 2 +- lib/utils/reset/fdt_reset_sunxi_wdt.c | 2 +- lib/utils/reset/fdt_reset_syscon.c | 4 +- lib/utils/serial/fdt_serial.c | 53 ++----------- lib/utils/serial/fdt_serial_cadence.c | 2 +- lib/utils/serial/fdt_serial_drivers.carray | 2 +- lib/utils/serial/fdt_serial_gaisler.c | 2 +- lib/utils/serial/fdt_serial_htif.c | 2 +- lib/utils/serial/fdt_serial_litex.c | 2 +- lib/utils/serial/fdt_serial_renesas_scif.c | 2 +- lib/utils/serial/fdt_serial_shakti.c | 2 +- lib/utils/serial/fdt_serial_sifive.c | 2 +- lib/utils/serial/fdt_serial_uart8250.c | 2 +- lib/utils/serial/fdt_serial_xlnx_uartlite.c | 2 +- lib/utils/timer/fdt_timer.c | 40 +--------- lib/utils/timer/fdt_timer_drivers.carray | 2 +- lib/utils/timer/fdt_timer_mtimer.c | 4 +- lib/utils/timer/fdt_timer_plmt.c | 4 +- platform/generic/platform.c | 5 +- platform/generic/sifive/fu740.c | 9 ++- platform/generic/starfive/jh7110.c | 9 ++- scripts/carray.sh | 22 ++++-- 57 files changed, 267 insertions(+), 352 deletions(-)create mode 100644
include/sbi_utils/fdt/fdt_driver.hcreate mode 100644lib/utils/fdt/fdt_driver.c
Signature · 4 lines
Ben Dooks http://www.codethink.co.uk/ Senior Engineer Codethink - Providing Genius https://www.codethink.co.uk/privacy.html