Skip to contentSkip to conversation

Export redesign

PATCH Superseded Simon Glass 3 participants 6 messages Jan 26, 2015 Generic include/asm header files

v5 of 7 Superseded Latest is v7 →

lore
Share & tools
lore
#0 lore raw

PATCH v5 1/1 Export redesign

From: Martin Dorwig <[email protected]>

this is an atempt to make the export of functions typesafe.
I replaced the jumptable void ** by a struct (jt_funcs) with function pointers. The EXPORT_FUNC macro now has 3 fixed parameters and one
variadic parameter
The first is the name of the exported function,
the rest of the parameters are used to format a functionpointer
in the jumptable,

the EXPORT_FUNC macros are expanded three times,
1. to declare the members of the struct
2. to initialize the structmember pointers
3. to call the functions in stubs.c

(resending to the list since my tweaks are not quite trivial)

---

Changes in v5:
- Update to deal with I2C moving to driver model

 arch/blackfin/cpu/cpu.c           |  3 +-
 board/BuS/eb_cpux9k2/cpux9k2.c    |  2 +-
 common/cmd_load.c                 |  2 +-
 common/console.c                  | 20 ++++----
 common/exports.c                  | 29 ++----------
 doc/README.standalone             | 41 +++++++++++-----
 examples/standalone/stubs.c       | 64 +++++++++++++------------
 include/_exports.h                | 99 +++++++++++++++++++++++++++------------
 include/asm-generic/global_data.h |  2 +-
 include/exports.h                 | 20 ++++----
 10 files changed, 162 insertions(+), 120 deletions(-)
arch/blackfin/cpu/cpu.c +2 -1
index b7f1188..91aa5cc 100644
@@ -24,6 +24,7 @@
 
 #include "cpu.h"
 #include "initcode.h"
+#include "exports.h"
 
 ulong bfin_poweron_retx;
 DECLARE_GLOBAL_DATA_PTR;
@@ -121,7 +122,7 @@ static void display_global_data(void)
 	printf(" |-ram_size: %lx\n", gd->ram_size);
 	printf(" |-env_addr: %lx\n", gd->env_addr);
 	printf(" |-env_valid: %lx\n", gd->env_valid);
-	printf(" |-jt(%p): %p\n", gd->jt, *(gd->jt));
+	printf(" |-jt(%p): %p\n", gd->jt, gd->jt->get_version);
 	printf(" \\-bd: %p\n", gd->bd);
 	printf("   |-bi_boot_params: %lx\n", bd->bi_boot_params);
 	printf("   |-bi_memstart: %lx\n", bd->bi_memstart);
board/BuS/eb_cpux9k2/cpux9k2.c +1 -1
index 5e4778e..76ad7c4 100644
@@ -98,7 +98,7 @@ int misc_init_r(void)
 				puts("Error: invalid MAC at EEPROM\n");
 		}
 	}
-	gd->jt[XF_do_reset] = (void *) do_reset;
+	gd->jt->do_reset = do_reset;
 
 #ifdef CONFIG_STATUS_LED
 	status_led_set(STATUS_LED_BOOT, STATUS_LED_BLINKING);
common/cmd_load.c +1 -1
index f6e522c..d043e6d 100644
@@ -222,7 +222,7 @@ static int read_record(char *buf, ulong len)
 		}
 
 	    /* Check for the console hangup (if any different from serial) */
-	    if (gd->jt[XF_getc] != getc) {
+	    if (gd->jt->getc != getc) {
 		if (ctrlc()) {
 		    return (-1);
 		}
common/console.c +10 -10
index fc1963b..3f25e76 100644
@@ -125,13 +125,13 @@ static int console_setfile(int file, struct stdio_dev * dev)
 		 */
 		switch (file) {
 		case stdin:
-			gd->jt[XF_getc] = getc;
-			gd->jt[XF_tstc] = tstc;
+			gd->jt->getc = getc;
+			gd->jt->tstc = tstc;
 			break;
 		case stdout:
-			gd->jt[XF_putc] = putc;
-			gd->jt[XF_puts] = puts;
-			gd->jt[XF_printf] = printf;
+			gd->jt->putc  = putc;
+			gd->jt->puts  = puts;
+			gd->jt->printf = printf;
 			break;
 		}
 		break;
@@ -758,11 +758,11 @@ int console_init_r(void)
 #endif
 
 	/* set default handlers at first */
-	gd->jt[XF_getc] = serial_getc;
-	gd->jt[XF_tstc] = serial_tstc;
-	gd->jt[XF_putc] = serial_putc;
-	gd->jt[XF_puts] = serial_puts;
-	gd->jt[XF_printf] = serial_printf;
+	gd->jt->getc  = serial_getc;
+	gd->jt->tstc  = serial_tstc;
+	gd->jt->putc  = serial_putc;
+	gd->jt->puts  = serial_puts;
+	gd->jt->printf = serial_printf;
 
 	/* stdin stdout and stderr are in environment */
 	/* scan for it */
common/exports.c +3 -26
index 459e18c..333107c 100644
@@ -1,6 +1,7 @@
 #include <common.h>
 #include <exports.h>
 #include <spi.h>
+#include <i2c.h>
 
 DECLARE_GLOBAL_DATA_PTR;
 
@@ -13,34 +14,10 @@ unsigned long get_version(void)
 	return XF_VERSION;
 }
 
-/* Reuse _exports.h with a little trickery to avoid bitrot */
-#define EXPORT_FUNC(sym) gd->jt[XF_##sym] = (void *)sym;
-
-#if !defined(CONFIG_X86) && !defined(CONFIG_PPC)
-# define install_hdlr      dummy
-# define free_hdlr         dummy
-#else /* kludge for non-standard function naming */
-# define install_hdlr      irq_install_handler
-# define free_hdlr         irq_free_handler
-#endif
-#if !defined(CONFIG_CMD_I2C) || \
-	(defined(CONFIG_DM_I2C) && !defined(CONFIG_DM_I2C_COMPAT))
-# define i2c_write         dummy
-# define i2c_read          dummy
-#endif
-#if !defined(CONFIG_CMD_SPI) || defined(CONFIG_DM_SPI)
-# define spi_init          dummy
-# define spi_setup_slave   dummy
-# define spi_free_slave    dummy
-#endif
-#ifndef CONFIG_CMD_SPI
-# define spi_claim_bus     dummy
-# define spi_release_bus   dummy
-# define spi_xfer          dummy
-#endif
+#define EXPORT_FUNC(f, a, x, ...)  gd->jt->x = f;
 
 void jumptable_init(void)
 {
-	gd->jt = malloc(XF_MAX * sizeof(void *));
+	gd->jt = malloc(sizeof(struct jt_funcs));
 #include <_exports.h>
 }
doc/README.standalone +30 -11

75 lines not on this page · raw message

examples/standalone/stubs.c +33 -31

234 lines not on this page · raw message

include/_exports.h +70 -29

102 lines not on this page · raw message

include/asm-generic/global_data.h +1 -1
index 3d14d5f..6747619 100644
@@ -73,7 +73,7 @@ typedef struct global_data {
 	const void *fdt_blob;	/* Our device tree, NULL if none */
 	void *new_fdt;		/* Relocated FDT */
 	unsigned long fdt_size;	/* Space reserved for relocated FDT */
-	void **jt;		/* jump table */
+	struct jt_funcs *jt;		/* jump table */
 	char env_buf[32];	/* buffer for getenv() before reloc. */
 #ifdef CONFIG_TRACE
 	void		*trace_buff;	/* The trace buffer */
include/exports.h +11 -9
index 41d5085..b918b34 100644
@@ -3,6 +3,8 @@
 
 #ifndef __ASSEMBLY__
 
+struct spi_slave;
+
 /* These are declarations of exported functions available in C code */
 unsigned long get_version(void);
 int  getc(void);
@@ -10,22 +12,23 @@ int  tstc(void);
 void putc(const char);
 void puts(const char*);
 int printf(const char* fmt, ...);
-void install_hdlr(int, void (*interrupt_handler_t)(void *), void*);
+void install_hdlr(int, interrupt_handler_t, void*);
 void free_hdlr(int);
 void *malloc(size_t);
 void free(void*);
 void __udelay(unsigned long);
 unsigned long get_timer(unsigned long);
 int vprintf(const char *, va_list);
-unsigned long simple_strtoul(const char *cp,char **endp,unsigned int base);
+unsigned long simple_strtoul(const char *cp, char **endp, unsigned int base);
 int strict_strtoul(const char *cp, unsigned int base, unsigned long *res);
 char *getenv (const char *name);
 int setenv (const char *varname, const char *varvalue);
-long simple_strtol(const char *cp,char **endp,unsigned int base);
-int strcmp(const char * cs,const char * ct);
+long simple_strtol(const char *cp, char **endp, unsigned int base);
+int strcmp(const char *cs, const char *ct);
 unsigned long ustrtoul(const char *cp, char **endp, unsigned int base);
 unsigned long long ustrtoull(const char *cp, char **endp, unsigned int base);
-#if defined(CONFIG_CMD_I2C)
+#if defined(CONFIG_CMD_I2C) && \
+		(!defined(CONFIG_DM_I2C) || defined(CONFIG_DM_I2C_COMPAT))
 int i2c_write (uchar, uint, int , uchar* , int);
 int i2c_read (uchar, uint, int , uchar* , int);
 #endif
@@ -34,14 +37,13 @@ void app_startup(char * const *);
 
 #endif    /* ifndef __ASSEMBLY__ */
 
-enum {
-#define EXPORT_FUNC(x) XF_ ## x ,
+struct jt_funcs {
+#define EXPORT_FUNC(impl, res, func, ...) res(*func)(__VA_ARGS__);
 #include <_exports.h>
 #undef EXPORT_FUNC
-
-	XF_MAX
 };
 
+
 #define XF_VERSION	6
 
 #if defined(CONFIG_X86)
Signature · 1 line
2.2.0.rc0.207.ga3a616c
#1 lore raw

PATCH v5 1/1 Export redesign

Dear Simon,

Quoted 15 lines · In message <[email protected]> you wrote:

From: Martin Dorwig <[email protected]>

this is an atempt to make the export of functions typesafe.
I replaced the jumptable void ** by a struct (jt_funcs) with function pointers. The EXPORT_FUNC macro now has 3 fixed parameters and one
variadic parameter
The first is the name of the exported function,
the rest of the parameters are used to format a functionpointer
in the jumptable,

the EXPORT_FUNC macros are expanded three times,
1. to declare the members of the struct
2. to initialize the structmember pointers
3. to call the functions in stubs.c

Quoted 5 lines

(resending to the list since my tweaks are not quite trivial)

Is this a 100% binary compatible change? If not, should we not also increment XF_VERSION ?

Best regards,

Wolfgang Denk

Signature · 5 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
Where people stand is not as important as which way they face.
        - Terry Pratchett & Stephen Briggs, _The Discworld Companion_
#2 lore raw

PATCH v5 1/1 Export redesign

Hi Wolfgang,

Quoted 18 lines · Wolfgang Denk

Dear Simon,

Quoted 15 lines · In message <[email protected]> you wrote:

From: Martin Dorwig <[email protected]>

this is an atempt to make the export of functions typesafe.
I replaced the jumptable void ** by a struct (jt_funcs) with function pointers. The EXPORT_FUNC macro now has 3 fixed parameters and one
variadic parameter
The first is the name of the exported function,
the rest of the parameters are used to format a functionpointer
in the jumptable,

the EXPORT_FUNC macros are expanded three times,
1. to declare the members of the struct
2. to initialize the structmember pointers
3. to call the functions in stubs.c

Quoted 8 lines
Quoted 5 lines

(resending to the list since my tweaks are not quite trivial)

Is this a 100% binary compatible change? If not, should we not also increment XF_VERSION ?

If a board has move to driver model and doesn't use CONFIG_DM_I2C_COMPAT (and this should ideally not be used) then the I2C functions are not present. I tested the compatibility to a basic degree.

Perhaps we should increment it anyway, given it is such a major code change?

Regards,
Simon

#3 lore raw

PATCH v5 1/1 Export redesign

Dear Simon,

Quoted 8 lines · In message <CAPnjgZ1wzmspVjB8dqDJBZDu2Dpu+JLSS=CmAdDPkhptYRHQJQ@mail.gmail.com>…
Quoted 3 lines

Is this a 100% binary compatible change? If not, should we not also increment XF_VERSION ?

If a board has move to driver model and doesn't use CONFIG_DM_I2C_COMPAT (and this should ideally not be used) then the I2C functions are not present. I tested the compatibility to a basic degree.

Maybe I'm misreading the code, but would an old standalone application image, compiled for the old jumptable format, really still run on a system with your patch applied? Only in this case we can leave the version unchanged.

Quoted 1 line

Perhaps we should increment it anyway, given it is such a major code change?

It would not hurt, ideed.

Best regards,

Wolfgang Denk

Signature · 8 lines
DENX Software Engineering GmbH,      Managing Director: Wolfgang Denk
HRB 165235 Munich, Office: Kirchenstr.5, D-82194 Groebenzell, Germany
Phone: (+49)-8142-66989-10 Fax: (+49)-8142-66989-80 Email: wd at denx.de
The manager will be continually amazed that policies he took for com-
mon knowledge are totally unknown by some member of his  team.  Since
his fundamental job is to keep everybody going in the same direction,
his chief daily task will be communication, not decision-making.
                              - Fred Brooks, "The Mythical Man Month"
#4 lore raw

PATCH v5 1/1 Export redesign

Hi Wolfgang,

Quoted 12 lines · Wolfgang Denk

Dear Simon,

Quoted 8 lines · In message <CAPnjgZ1wzmspVjB8dqDJBZDu2Dpu+JLSS=CmAdDPkhptYRHQJQ@mail.gmail.com>…
Quoted 3 lines

Is this a 100% binary compatible change? If not, should we not also increment XF_VERSION ?

If a board has move to driver model and doesn't use CONFIG_DM_I2C_COMPAT (and this should ideally not be used) then the I2C functions are not present. I tested the compatibility to a basic degree.

Quoted 8 lines

Maybe I'm misreading the code, but would an old standalone application image, compiled for the old jumptable format, really still run on a system with your patch applied? Only in this case we can leave the version unchanged.

Quoted 1 line

Perhaps we should increment it anyway, given it is such a major code change?

It would not hurt, ideed.

OK I'll do that.

Regards,
Simon

#5 lore raw

PATCH v5 1/1 Export redesign

In reply to Wolfgang Denk

Am Montag, 26. Januar 2015, 15:45:31 schrieb Wolfgang Denk:

Quoted 3 lines

Is this a 100% binary compatible change? If not, should we not also increment XF_VERSION ?

Yes it is .
The function pointers declared in _export.h are in the same sequence as they were before.

Regards
Martin