mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* improve device parameter types
@ 2017-04-10  7:14 Sascha Hauer
  2017-04-10  7:14 ` [PATCH 01/10] ARM: socfpga: change param_type struct name Sascha Hauer
                   ` (9 more replies)
  0 siblings, 10 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-04-10  7:14 UTC (permalink / raw)
  To: Barebox List

This series improves the device parameter types and also the
global/nv variables. So far we only had 'int' both for signed
and unsigned variables. This series adds support for explicitly
signed or unsigned variables.
Until now the globalvars were all read/write, but some should really
be readonly (like the barebox version for example). This series
adds support for readonly globalvars.

----------------------------------------------------------------
Sascha Hauer (10):
      ARM: socfpga: change param_type struct name
      parameter: Give device parameters types
      lib: implement simple_strtoll
      console: Use dev_add_param_string
      mtd: nand: use dev_add_param_enum
      mtd: use dev_add_param_string
      net: use dev_add_param_string
      param: make parameter functions more consistent
      globalvar: make globalvar functions more consistent
      param: remove unnecessary device_d * argument

 arch/arm/boards/at91sam9m10ihd/hw_version.c      |   4 +-
 arch/arm/boards/at91sam9x5ek/hw_version.c        |   4 +-
 arch/arm/boards/beaglebone/board.c               |   2 +-
 arch/arm/boards/crystalfontz-cfa10036/hwdetect.c |   2 +-
 arch/arm/boards/phytec-som-imx6/board.c          |   2 +-
 arch/arm/boards/sama5d3xek/hw_version.c          |   4 +-
 arch/arm/boards/vscom-baltos/board.c             |   7 +-
 arch/arm/mach-socfpga/include/mach/sequencer.h   |   2 +-
 arch/ppc/boards/pcm030/eeprom.c                  |   4 +-
 commands/devinfo.c                               |   3 +-
 common/boot.c                                    |   2 +-
 common/bootchooser.c                             |   4 +-
 common/bootm.c                                   |   2 +-
 common/console.c                                 |  52 +++--
 common/console_common.c                          |   6 +-
 common/globalvar.c                               |  42 ++--
 common/partitions/dos.c                          |   2 +-
 common/password.c                                |   2 +-
 common/reset_source.c                            |   2 +-
 common/state/state_variables.c                   |   4 +-
 drivers/amba/bus.c                               |   2 +-
 drivers/efi/efi-device.c                         |  10 +-
 drivers/input/qt1070.c                           |   4 +-
 drivers/mtd/core.c                               |  30 +--
 drivers/mtd/nand/nand_base.c                     |  34 ++-
 drivers/mtd/peb.c                                |   6 +-
 drivers/mtd/ubi/build.c                          |  22 +-
 drivers/net/phy/mdio_bus.c                       |   4 +-
 drivers/pwm/core.c                               |   4 +-
 drivers/usb/core/usb.c                           |  16 +-
 drivers/usb/gadget/udc-core.c                    |   4 +-
 drivers/video/backlight.c                        |   2 +-
 drivers/video/imx-ipu-fb.c                       |   2 +-
 drivers/video/imx.c                              |   2 +-
 include/console.h                                |   2 +-
 include/globalvar.h                              | 109 ++++++++--
 include/linux/kernel.h                           |   1 +
 include/linux/mtd/mtd.h                          |   1 +
 include/linux/mtd/nand.h                         |   1 +
 include/param.h                                  | 195 +++++++++++++----
 lib/parameter.c                                  | 254 +++++++++++------------
 lib/strtox.c                                     |   8 +
 net/net.c                                        |  11 +-
 43 files changed, 541 insertions(+), 335 deletions(-)

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 01/10] ARM: socfpga: change param_type struct name
  2017-04-10  7:14 improve device parameter types Sascha Hauer
@ 2017-04-10  7:14 ` Sascha Hauer
  2017-04-10  7:14 ` [PATCH 02/10] parameter: Give device parameters types Sascha Hauer
                   ` (8 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-04-10  7:14 UTC (permalink / raw)
  To: Barebox List

We are going to introduce a "enum param_type" in barebox, so
rename the struct type of the same name in the socfpga sequencer
code.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/mach-socfpga/include/mach/sequencer.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/arch/arm/mach-socfpga/include/mach/sequencer.h b/arch/arm/mach-socfpga/include/mach/sequencer.h
index dd0378af34..d2da21d13f 100644
--- a/arch/arm/mach-socfpga/include/mach/sequencer.h
+++ b/arch/arm/mach-socfpga/include/mach/sequencer.h
@@ -369,7 +369,7 @@ static const uint32_t ac_rom_init[];
 
 /* parameter variable holder */
 
-typedef struct param_type {
+typedef struct sequencer_param_type {
 	t_btfld dm_correct_mask;
 	t_btfld read_correct_mask;
 	t_btfld read_correct_mask_vg;
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 02/10] parameter: Give device parameters types
  2017-04-10  7:14 improve device parameter types Sascha Hauer
  2017-04-10  7:14 ` [PATCH 01/10] ARM: socfpga: change param_type struct name Sascha Hauer
@ 2017-04-10  7:14 ` Sascha Hauer
  2017-04-10  7:14 ` [PATCH 03/10] lib: implement simple_strtoll Sascha Hauer
                   ` (7 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-04-10  7:14 UTC (permalink / raw)
  To: Barebox List

This adds a variable type enum and adds this to the device parameters.
This information gives the user a hint which values a parameter expects
and also helps to organize the parameters better internally.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/devinfo.c |  3 ++-
 include/param.h    | 15 +++++++++++++++
 lib/parameter.c    | 30 +++++++++++++++++++++++++++++-
 3 files changed, 46 insertions(+), 2 deletions(-)

diff --git a/commands/devinfo.c b/commands/devinfo.c
index 9d5e8b86eb..cd69d2e5f8 100644
--- a/commands/devinfo.c
+++ b/commands/devinfo.c
@@ -103,7 +103,8 @@ static int do_devinfo(int argc, char *argv[])
 				printf("Parameters:\n");
 				first = false;
 			}
-			printf("  %s: %s", param->name, dev_get_param(dev, param->name));
+			printf("  %s: %s (type: %s)", param->name, dev_get_param(dev, param->name),
+			       get_param_type(param));
 			if (param->info) {
 				param->info(param);
 			}
diff --git a/include/param.h b/include/param.h
index f9f3398cae..2eb040fea4 100644
--- a/include/param.h
+++ b/include/param.h
@@ -10,6 +10,19 @@
 struct device_d;
 typedef uint32_t          IPaddr_t;
 
+enum param_type {
+	PARAM_TYPE_STRING = 0,
+	PARAM_TYPE_INT32,
+	PARAM_TYPE_UINT32,
+	PARAM_TYPE_INT64,
+	PARAM_TYPE_UINT64,
+	PARAM_TYPE_BOOL,
+	PARAM_TYPE_ENUM,
+	PARAM_TYPE_BITMASK,
+	PARAM_TYPE_IPV4,
+	PARAM_TYPE_MAC,
+};
+
 struct param_d {
 	const char* (*get)(struct device_d *, struct param_d *param);
 	int (*set)(struct device_d *, struct param_d *param, const char *val);
@@ -20,9 +33,11 @@ struct param_d {
 	struct device_d *dev;
 	void *driver_priv;
 	struct list_head list;
+	enum param_type type;
 };
 
 #ifdef CONFIG_PARAMETER
+const char *get_param_type(struct param_d *param);
 const char *dev_get_param(struct device_d *dev, const char *name);
 int dev_set_param(struct device_d *dev, const char *name, const char *val);
 struct param_d *get_param_by_name(struct device_d *dev, const char *name);
diff --git a/lib/parameter.c b/lib/parameter.c
index 65d6c7c0df..6456779e71 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -31,6 +31,24 @@
 #include <globalvar.h>
 #include <linux/err.h>
 
+static const char *param_type_string[] = {
+	[PARAM_TYPE_STRING] = "string",
+	[PARAM_TYPE_INT32] = "int32",
+	[PARAM_TYPE_UINT32] = "uint32",
+	[PARAM_TYPE_INT64] = "int64",
+	[PARAM_TYPE_UINT64] = "uint64",
+	[PARAM_TYPE_BOOL] = "bool",
+	[PARAM_TYPE_ENUM] = "enum",
+	[PARAM_TYPE_BITMASK] = "bitmask",
+	[PARAM_TYPE_IPV4] = "ipv4",
+	[PARAM_TYPE_MAC] = "MAC",
+};
+
+const char *get_param_type(struct param_d *param)
+{
+	return param_type_string[param->type];
+}
+
 struct param_d *get_param_by_name(struct device_d *dev, const char *name)
 {
 	struct param_d *p;
@@ -284,6 +302,7 @@ struct param_d *dev_add_param_string(struct device_d *dev, const char *name,
 	ps->get = get;
 	p = &ps->param;
 	p->driver_priv = priv;
+	p->type = PARAM_TYPE_STRING;
 
 	ret = __dev_add_param(p, dev, name, param_string_set, param_string_get, 0);
 	if (ret) {
@@ -384,6 +403,7 @@ struct param_d *dev_add_param_int(struct device_d *dev, const char *name,
 	pi->get = get;
 	p = &pi->param;
 	p->driver_priv = priv;
+	p->type = PARAM_TYPE_INT32;
 
 	ret = __dev_add_param(p, dev, name, param_int_set, param_int_get, 0);
 	if (ret) {
@@ -465,7 +485,7 @@ static void param_enum_info(struct param_d *p)
 	if (pe->num_names <= 1)
 		return;
 
-	printf(" (");
+	printf(" (values: ");
 
 	for (i = 0; i < pe->num_names; i++) {
 		if (!pe->names[i] || !*pe->names[i])
@@ -493,6 +513,7 @@ struct param_d *dev_add_param_enum(struct device_d *dev, const char *name,
 	pe->num_names = num_names;
 	p = &pe->param;
 	p->driver_priv = priv;
+	p->type = PARAM_TYPE_ENUM;
 
 	ret = __dev_add_param(p, dev, name, param_enum_set, param_enum_get, 0);
 	if (ret) {
@@ -622,6 +643,7 @@ struct param_d *dev_add_param_bitmask(struct device_d *dev, const char *name,
 	pb->num_names = max;
 	p = &pb->param;
 	p->driver_priv = priv;
+	p->type = PARAM_TYPE_BITMASK;
 
 	for (i = 0; i < pb->num_names; i++)
 		if (pb->names[i])
@@ -666,6 +688,8 @@ struct param_d *dev_add_param_bool(struct device_d *dev, const char *name,
 	if (IS_ERR(p))
 		return p;
 
+	p->type = PARAM_TYPE_BOOL;
+
 	pi = to_param_int(p);
 	pi->flags |= PARAM_INT_FLAG_BOOL;
 
@@ -698,6 +722,7 @@ struct param_d *dev_add_param_int_ro(struct device_d *dev, const char *name,
 		return ERR_PTR(ret);
 	}
 
+	piro->param.type = PARAM_TYPE_INT32;
 	piro->param.value = basprintf(format, value);
 
 	return &piro->param;
@@ -724,6 +749,7 @@ struct param_d *dev_add_param_llint_ro(struct device_d *dev, const char *name,
 		return ERR_PTR(ret);
 	}
 
+	piro->param.type = PARAM_TYPE_INT64;
 	piro->param.value = basprintf(format, value);
 
 	return &piro->param;
@@ -795,6 +821,7 @@ struct param_d *dev_add_param_ip(struct device_d *dev, const char *name,
 	pi->set = set;
 	pi->get = get;
 	pi->param.driver_priv = priv;
+	pi->param.type = PARAM_TYPE_IPV4;
 
 	ret = __dev_add_param(&pi->param, dev, name,
 			param_ip_set, param_ip_get, 0);
@@ -882,6 +909,7 @@ struct param_d *dev_add_param_mac(struct device_d *dev, const char *name,
 	pm->get = get;
 	pm->param.driver_priv = priv;
 	pm->param.value = pm->mac_str;
+	pm->param.type = PARAM_TYPE_MAC;
 
 	ret = __dev_add_param(&pm->param, dev, name,
 			param_mac_set, param_mac_get, 0);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 03/10] lib: implement simple_strtoll
  2017-04-10  7:14 improve device parameter types Sascha Hauer
  2017-04-10  7:14 ` [PATCH 01/10] ARM: socfpga: change param_type struct name Sascha Hauer
  2017-04-10  7:14 ` [PATCH 02/10] parameter: Give device parameters types Sascha Hauer
@ 2017-04-10  7:14 ` Sascha Hauer
  2017-04-10 12:44   ` Sam Ravnborg
  2017-04-10  7:14 ` [PATCH 04/10] console: Use dev_add_param_string Sascha Hauer
                   ` (6 subsequent siblings)
  9 siblings, 1 reply; 13+ messages in thread
From: Sascha Hauer @ 2017-04-10  7:14 UTC (permalink / raw)
  To: Barebox List

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 include/linux/kernel.h | 1 +
 lib/strtox.c           | 8 ++++++++
 2 files changed, 9 insertions(+)

diff --git a/include/linux/kernel.h b/include/linux/kernel.h
index 945e063f02..b4d2f09081 100644
--- a/include/linux/kernel.h
+++ b/include/linux/kernel.h
@@ -92,6 +92,7 @@ void __noreturn panic(const char *fmt, ...);
 extern unsigned long simple_strtoul(const char *,char **,unsigned int);
 extern long simple_strtol(const char *,char **,unsigned int);
 extern unsigned long long simple_strtoull(const char *,char **,unsigned int);
+extern long long simple_strtoll(const char *,char **,unsigned int);
 
 /*
  * min()/max()/clamp() macros that also do
diff --git a/lib/strtox.c b/lib/strtox.c
index cfe61240cc..ba183c1dd3 100644
--- a/lib/strtox.c
+++ b/lib/strtox.c
@@ -65,3 +65,11 @@ unsigned long long simple_strtoull (const char *cp, char **endp, unsigned int ba
 	return result;
 }
 EXPORT_SYMBOL(simple_strtoull);
+
+long long simple_strtoll(const char *cp,char **endp,unsigned int base)
+{
+	if(*cp=='-')
+		return -simple_strtoull(cp + 1, endp, base);
+	return simple_strtoull(cp, endp, base);
+}
+EXPORT_SYMBOL(simple_strtoll);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 04/10] console: Use dev_add_param_string
  2017-04-10  7:14 improve device parameter types Sascha Hauer
                   ` (2 preceding siblings ...)
  2017-04-10  7:14 ` [PATCH 03/10] lib: implement simple_strtoll Sascha Hauer
@ 2017-04-10  7:14 ` Sascha Hauer
  2017-04-10  7:14 ` [PATCH 05/10] mtd: nand: use dev_add_param_enum Sascha Hauer
                   ` (5 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-04-10  7:14 UTC (permalink / raw)
  To: Barebox List

dev_add_param_string allows to pass a priv * so that the device_d *
argument is not needed and can be removed later.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/console.c  | 50 ++++++++++++++++++++++++--------------------------
 include/console.h |  2 +-
 2 files changed, 25 insertions(+), 27 deletions(-)

diff --git a/common/console.c b/common/console.c
index 74fb684b2c..1bcb13fa0b 100644
--- a/common/console.c
+++ b/common/console.c
@@ -94,7 +94,7 @@ int console_close(struct console_device *cdev)
 
 int console_set_active(struct console_device *cdev, unsigned flag)
 {
-	int ret, i;
+	int ret;
 
 	if (!cdev->getc)
 		flag &= ~CONSOLE_STDIN;
@@ -119,18 +119,6 @@ int console_set_active(struct console_device *cdev, unsigned flag)
 
 	cdev->f_active = flag;
 
-	if (IS_ENABLED(CONFIG_PARAMETER)) {
-		i = 0;
-
-		if (flag & CONSOLE_STDIN)
-			cdev->active[i++] = 'i';
-		if (flag & CONSOLE_STDOUT)
-			cdev->active[i++] = 'o';
-		if (flag & CONSOLE_STDERR)
-			cdev->active[i++] = 'e';
-		cdev->active[i] = 0;
-	}
-
 	if (initialized < CONSOLE_INIT_FULL) {
 		char ch;
 		initialized = CONSOLE_INIT_FULL;
@@ -150,30 +138,39 @@ unsigned console_get_active(struct console_device *cdev)
 	return cdev->f_active;
 }
 
-static int console_active_set(struct device_d *dev, struct param_d *param,
-		const char *val)
+static int console_active_set(struct param_d *param, void *priv)
 {
-	struct console_device *cdev = to_console_dev(dev);
+	struct console_device *cdev = priv;
 	unsigned int flag = 0;
+	int ret;
 
-	if (val) {
-		if (strchr(val, 'i'))
+	if (cdev->active_string) {
+		if (strchr(cdev->active_string, 'i'))
 			flag |= CONSOLE_STDIN;
-		if (strchr(val, 'o'))
+		if (strchr(cdev->active_string, 'o'))
 			flag |= CONSOLE_STDOUT;
-		if (strchr(val, 'e'))
+		if (strchr(cdev->active_string, 'e'))
 			flag |= CONSOLE_STDERR;
 	}
 
-	return console_set_active(cdev, flag);
+	ret = console_set_active(cdev, flag);
+	if (ret)
+		return ret;
+
+	return 0;
 }
 
-static const char *console_active_get(struct device_d *dev,
-		struct param_d *param)
+static int console_active_get(struct param_d *param, void *priv)
 {
-	struct console_device *cdev = to_console_dev(dev);
+	struct console_device *cdev = priv;
+	unsigned int flag = cdev->f_active;
 
-	return cdev->active;
+	free(cdev->active_string);
+	cdev->active_string = basprintf("%s%s%s",
+					flag & CONSOLE_STDIN ? "i" : "",
+					flag & CONSOLE_STDOUT ? "o" : "",
+					flag & CONSOLE_STDERR ? "e" : "");
+	return 0;
 }
 
 int console_set_baudrate(struct console_device *cdev, unsigned baudrate)
@@ -340,7 +337,8 @@ int console_register(struct console_device *newcdev)
 
 	newcdev->open_count = 0;
 
-	dev_add_param(dev, "active", console_active_set, console_active_get, 0);
+	dev_add_param_string(dev, "active", console_active_set, console_active_get,
+			     &newcdev->active_string, newcdev);
 
 	if (IS_ENABLED(CONFIG_CONSOLE_ACTIVATE_FIRST)) {
 		if (list_empty(&console_list))
diff --git a/include/console.h b/include/console.h
index 126c2e8aa3..724168e07c 100644
--- a/include/console.h
+++ b/include/console.h
@@ -53,7 +53,7 @@ struct console_device {
 	struct list_head list;
 
 	unsigned char f_active;
-	char active[4];
+	char *active_string;
 
 	unsigned int open_count;
 
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 05/10] mtd: nand: use dev_add_param_enum
  2017-04-10  7:14 improve device parameter types Sascha Hauer
                   ` (3 preceding siblings ...)
  2017-04-10  7:14 ` [PATCH 04/10] console: Use dev_add_param_string Sascha Hauer
@ 2017-04-10  7:14 ` Sascha Hauer
  2017-04-10  7:14 ` [PATCH 06/10] mtd: use dev_add_param_string Sascha Hauer
                   ` (4 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-04-10  7:14 UTC (permalink / raw)
  To: Barebox List

dev_add_param_enum allows to pass a priv * so that the device_d *
argument is not needed and can be removed later.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/nand/nand_base.c | 34 ++++++++++++++++++++++++++--------
 include/linux/mtd/nand.h     |  1 +
 2 files changed, 27 insertions(+), 8 deletions(-)

diff --git a/drivers/mtd/nand/nand_base.c b/drivers/mtd/nand/nand_base.c
index ceb2bb7215..d9f79474cd 100644
--- a/drivers/mtd/nand/nand_base.c
+++ b/drivers/mtd/nand/nand_base.c
@@ -3853,25 +3853,40 @@ static int mtd_set_erasebad(struct param_d *param, void *priv)
 	return 0;
 }
 
-static const char *mtd_get_bbt_type(struct device_d *dev, struct param_d *p)
+enum bbt_type {
+	BBT_TYPE_NONE = 0,
+	BBT_TYPE_FLASHBASED,
+	BBT_TYPE_MEMORYBASED,
+};
+
+static const char *bbt_type_strings[] = {
+	[BBT_TYPE_NONE] = "none",
+	[BBT_TYPE_FLASHBASED] = "flashbased",
+	[BBT_TYPE_MEMORYBASED] = "memorybased",
+};
+
+static int mtd_get_bbt_type(struct param_d *p, void *priv)
 {
-	struct mtd_info *mtd = container_of(dev, struct mtd_info, class_dev);
+	struct mtd_info *mtd = priv;
 	struct nand_chip *chip = mtd->priv;
-	const char *str;
+	enum bbt_type type;
 
 	if (!chip->bbt)
-		str = "none";
+		type = BBT_TYPE_NONE;
 	else if ((chip->bbt_td && chip->bbt_td->pages[0] != -1) ||
 				(chip->bbt_md && chip->bbt_md->pages[0] != -1))
-		str = "flashbased";
+		type = BBT_TYPE_FLASHBASED;
 	else
-		str = "memorybased";
+		type = BBT_TYPE_MEMORYBASED;
+
+	chip->bbt_type = type;
 
-	return str;
+	return 0;
 }
 
 int add_mtd_nand_device(struct mtd_info *mtd, char *devname)
 {
+	struct nand_chip *chip = mtd->priv;
 	int ret;
 
 	ret = add_mtd_device(mtd, devname, DEVICE_ID_DYNAMIC);
@@ -3882,7 +3897,10 @@ int add_mtd_nand_device(struct mtd_info *mtd, char *devname)
 		dev_add_param_bool(&mtd->class_dev, "erasebad", mtd_set_erasebad,
 			NULL, &mtd->p_allow_erasebad, mtd);
 
-	dev_add_param(&mtd->class_dev, "bbt", NULL, mtd_get_bbt_type, 0);
+	dev_add_param_enum(&mtd->class_dev, "bbt", NULL, mtd_get_bbt_type,
+			   &chip->bbt_type, bbt_type_strings,
+			   ARRAY_SIZE(bbt_type_strings),
+			   mtd);
 
 	return ret;
 }
diff --git a/include/linux/mtd/nand.h b/include/linux/mtd/nand.h
index 66c936ee70..27538c3f42 100644
--- a/include/linux/mtd/nand.h
+++ b/include/linux/mtd/nand.h
@@ -540,6 +540,7 @@ struct nand_chip {
 	struct nand_bbt_descr *badblock_pattern;
 
 	void *priv;
+	unsigned int bbt_type;
 };
 
 /*
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 06/10] mtd: use dev_add_param_string
  2017-04-10  7:14 improve device parameter types Sascha Hauer
                   ` (4 preceding siblings ...)
  2017-04-10  7:14 ` [PATCH 05/10] mtd: nand: use dev_add_param_enum Sascha Hauer
@ 2017-04-10  7:14 ` Sascha Hauer
  2017-04-10  7:14 ` [PATCH 07/10] net: " Sascha Hauer
                   ` (3 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-04-10  7:14 UTC (permalink / raw)
  To: Barebox List

dev_add_param_string allows to pass a priv * so that the device_d *
argument is not needed and can be removed later.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 drivers/mtd/core.c      | 22 +++++++++++-----------
 include/linux/mtd/mtd.h |  1 +
 2 files changed, 12 insertions(+), 11 deletions(-)

diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index 1eb8dd36d8..f071373501 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -449,13 +449,13 @@ static struct file_operations mtd_ops = {
 	.lseek  = dev_lseek_default,
 };
 
-static int mtd_partition_set(struct device_d *dev, struct param_d *p, const char *val)
+static int mtd_partition_set(struct param_d *p, void *priv)
 {
-	struct mtd_info *mtd = container_of(dev, struct mtd_info, class_dev);
+	struct mtd_info *mtd = priv;
 	struct mtd_info *mtdpart, *tmp;
 	int ret;
 
-	if (!val)
+	if (!mtd->partition_string)
 		return -EINVAL;
 
 	list_for_each_entry_safe(mtdpart, tmp, &mtd->partitions, partitions_entry) {
@@ -464,7 +464,7 @@ static int mtd_partition_set(struct device_d *dev, struct param_d *p, const char
 			return ret;
 	}
 
-	return cmdlinepart_do_parse(mtd->cdev.name, val, mtd->size, CMDLINEPART_ADD_DEVNAME);
+	return cmdlinepart_do_parse(mtd->cdev.name, mtd->partition_string, mtd->size, CMDLINEPART_ADD_DEVNAME);
 }
 
 static char *print_size(uint64_t s)
@@ -530,18 +530,18 @@ static int print_parts(char *buf, int bufsize, struct mtd_info *mtd)
 	return ret;
 }
 
-static const char *mtd_partition_get(struct device_d *dev, struct param_d *p)
+static int mtd_partition_get(struct param_d *p, void *priv)
 {
-	struct mtd_info *mtd = container_of(dev, struct mtd_info, class_dev);
+	struct mtd_info *mtd = priv;
 	int len = 0;
 
-	free(p->value);
+	free(mtd->partition_string);
 
 	len = print_parts(NULL, 0, mtd);
-	p->value = xzalloc(len + 1);
-	print_parts(p->value, len + 1, mtd);
+	mtd->partition_string = xzalloc(len + 1);
+	print_parts(mtd->partition_string, len + 1, mtd);
 
-	return p->value;
+	return 0;
 }
 
 static int mtd_part_compare(struct list_head *a, struct list_head *b)
@@ -667,7 +667,7 @@ int add_mtd_device(struct mtd_info *mtd, const char *devname, int device_id)
 		mtd->cdev_bb = mtd_add_bb(mtd, NULL);
 
 	if (mtd->parent && !mtd->master) {
-		dev_add_param(&mtd->class_dev, "partitions", mtd_partition_set, mtd_partition_get, 0);
+		dev_add_param_string(&mtd->class_dev, "partitions", mtd_partition_set, mtd_partition_get, &mtd->partition_string, mtd);
 		of_parse_partitions(&mtd->cdev, mtd->parent->device_node);
 		if (IS_ENABLED(CONFIG_OFDEVICE) && mtd->parent->device_node) {
 			mtd->of_path = xstrdup(mtd->parent->device_node->full_name);
diff --git a/include/linux/mtd/mtd.h b/include/linux/mtd/mtd.h
index fa35c7ef39..16725ac4bc 100644
--- a/include/linux/mtd/mtd.h
+++ b/include/linux/mtd/mtd.h
@@ -226,6 +226,7 @@ struct mtd_info {
 
 	struct list_head partitions;
 	struct list_head partitions_entry;
+	char *partition_string;
 
 	char *of_path;
 	unsigned int of_binding;
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 07/10] net: use dev_add_param_string
  2017-04-10  7:14 improve device parameter types Sascha Hauer
                   ` (5 preceding siblings ...)
  2017-04-10  7:14 ` [PATCH 06/10] mtd: use dev_add_param_string Sascha Hauer
@ 2017-04-10  7:14 ` Sascha Hauer
  2017-04-10  7:14 ` [PATCH 08/10] param: make parameter functions more consistent Sascha Hauer
                   ` (2 subsequent siblings)
  9 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-04-10  7:14 UTC (permalink / raw)
  To: Barebox List

dev_add_param_string allows to pass a priv * so that the device_d *
argument is not needed and can be removed later.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 net/net.c | 11 +++++++++--
 1 file changed, 9 insertions(+), 2 deletions(-)

diff --git a/net/net.c b/net/net.c
index 3c0e715601..19b081f6cf 100644
--- a/net/net.c
+++ b/net/net.c
@@ -573,6 +573,9 @@ static struct device_d net_device = {
 	.id = DEVICE_ID_SINGLE,
 };
 
+static char *net_nameserver;
+static char *net_domainname;
+
 static int net_init(void)
 {
 	int i;
@@ -581,8 +584,12 @@ static int net_init(void)
 		NetRxPackets[i] = net_alloc_packet();
 
 	register_device(&net_device);
-	dev_add_param(&net_device, "nameserver", NULL, NULL, 0);
-	dev_add_param(&net_device, "domainname", NULL, NULL, 0);
+	net_nameserver = xstrdup("");
+	dev_add_param_string(&net_device, "nameserver", NULL, NULL,
+			     &net_nameserver, NULL);
+	net_domainname = xstrdup("");
+	dev_add_param_string(&net_device, "domainname", NULL, NULL,
+			     &net_domainname, NULL);
 
 	return 0;
 }
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 08/10] param: make parameter functions more consistent
  2017-04-10  7:14 improve device parameter types Sascha Hauer
                   ` (6 preceding siblings ...)
  2017-04-10  7:14 ` [PATCH 07/10] net: " Sascha Hauer
@ 2017-04-10  7:14 ` Sascha Hauer
  2017-04-10  7:14 ` [PATCH 09/10] globalvar: make globalvar " Sascha Hauer
  2017-04-10  7:14 ` [PATCH 10/10] param: remove unnecessary device_d * argument Sascha Hauer
  9 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-04-10  7:14 UTC (permalink / raw)
  To: Barebox List

This patch creates a consitent set of device parameter functions.

With this we have: dev_add_param_<type><access>

"type" is one of: int32, uint32, int64, uint64, string, mac, ipv4, enum, bitmask
The improvement here is that we now can exactly specify the width of the
int type parameters and also correctly distinguish between signed and
unsigned variables which means that a variable no longer ends up with
INT_MAX when it's assigned -1.

"access" can be empty for regular read/write parameter, "_ro" for readonly
parameters which get their value from a variable pointer in the
background or "_fixed" for parameters which are set to a fixed value
(without a pointer in the background).

Some more exotic types are not (yet) implemented, like
dev_add_param_ip_ro.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/at91sam9m10ihd/hw_version.c |   4 +-
 arch/arm/boards/at91sam9x5ek/hw_version.c   |   4 +-
 arch/arm/boards/sama5d3xek/hw_version.c     |   4 +-
 common/console.c                            |   2 +-
 common/partitions/dos.c                     |   2 +-
 common/state/state_variables.c              |   4 +-
 drivers/amba/bus.c                          |   2 +-
 drivers/efi/efi-device.c                    |  10 +-
 drivers/input/qt1070.c                      |   4 +-
 drivers/mtd/core.c                          |   8 +-
 drivers/mtd/ubi/build.c                     |  22 ++--
 drivers/net/phy/mdio_bus.c                  |   4 +-
 drivers/pwm/core.c                          |   4 +-
 drivers/usb/core/usb.c                      |  16 +--
 drivers/usb/gadget/udc-core.c               |   4 +-
 drivers/video/backlight.c                   |   2 +-
 drivers/video/imx-ipu-fb.c                  |   2 +-
 drivers/video/imx.c                         |   2 +-
 include/param.h                             | 169 +++++++++++++++++++------
 lib/parameter.c                             | 190 ++++++++++++----------------
 20 files changed, 260 insertions(+), 199 deletions(-)

diff --git a/arch/arm/boards/at91sam9m10ihd/hw_version.c b/arch/arm/boards/at91sam9m10ihd/hw_version.c
index 96fb02d801..cab26b0ac4 100644
--- a/arch/arm/boards/at91sam9m10ihd/hw_version.c
+++ b/arch/arm/boards/at91sam9m10ihd/hw_version.c
@@ -195,8 +195,8 @@ static void at91sam9m10ihd_devices_detect_one(const char *name)
 	dev_add_param_fixed(dev, "board", info.board_name);
 	sprintf(str, "%.2s", info.vendor_country);
 	dev_add_param_fixed(dev, "country", str);
-	dev_add_param_int_ro(dev, "year", info.year, "%d");
-	dev_add_param_int_ro(dev, "week", info.week, "%d");
+	dev_add_param_uint32_fixed(dev, "year", info.year, "%u");
+	dev_add_param_uint32_fixed(dev, "week", info.week, "%u");
 	sprintf(str, "%c", info.revision_code);
 	dev_add_param_fixed(dev, "revision_code", str);
 	sprintf(str, "%c", info.revision_id);
diff --git a/arch/arm/boards/at91sam9x5ek/hw_version.c b/arch/arm/boards/at91sam9x5ek/hw_version.c
index d1ca036fe9..10563cf98b 100644
--- a/arch/arm/boards/at91sam9x5ek/hw_version.c
+++ b/arch/arm/boards/at91sam9x5ek/hw_version.c
@@ -221,8 +221,8 @@ static void at91sam9x5ek_devices_detect_one(const char *name)
 	dev_add_param_fixed(dev, "board", info.board_name);
 	sprintf(str, "%.2s", info.vendor_country);
 	dev_add_param_fixed(dev, "country", str);
-	dev_add_param_int_ro(dev, "year", info.year, "%d");
-	dev_add_param_int_ro(dev, "week", info.week, "%d");
+	dev_add_param_uint32_fixed(dev, "year", info.year, "%u");
+	dev_add_param_uint32_fixed(dev, "week", info.week, "%u");
 	sprintf(str, "%c", info.revision_code);
 	dev_add_param_fixed(dev, "revision_code", str);
 	sprintf(str, "%c", info.revision_id);
diff --git a/arch/arm/boards/sama5d3xek/hw_version.c b/arch/arm/boards/sama5d3xek/hw_version.c
index c809c37742..e5077854e3 100644
--- a/arch/arm/boards/sama5d3xek/hw_version.c
+++ b/arch/arm/boards/sama5d3xek/hw_version.c
@@ -227,8 +227,8 @@ static void at91sama5d3xek_devices_detect_one(const char *name)
 	dev_add_param_fixed(dev, "board", bname);
 	sprintf(str, "%.2s", info.vendor_country);
 	dev_add_param_fixed(dev, "country", str);
-	dev_add_param_int_ro(dev, "year", info.year, "%d");
-	dev_add_param_int_ro(dev, "week", info.week, "%d");
+	dev_add_param_uint32_fixed(dev, "year", info.year, "%u");
+	dev_add_param_uint32_fixed(dev, "week", info.week, "%u");
 	sprintf(str, "%c", info.revision_board);
 	dev_add_param_fixed(dev, "revision_board", str);
 	sprintf(str, "%c", info.revision_schema);
diff --git a/common/console.c b/common/console.c
index 1bcb13fa0b..f4c799fa54 100644
--- a/common/console.c
+++ b/common/console.c
@@ -328,7 +328,7 @@ int console_register(struct console_device *newcdev)
 		if (ret)
 			return ret;
 		newcdev->baudrate_param = newcdev->baudrate = CONFIG_BAUDRATE;
-		dev_add_param_int(dev, "baudrate", console_baudrate_set,
+		dev_add_param_uint32(dev, "baudrate", console_baudrate_set,
 			NULL, &newcdev->baudrate_param, "%u", newcdev);
 	}
 
diff --git a/common/partitions/dos.c b/common/partitions/dos.c
index 5f08e253ee..91b5399079 100644
--- a/common/partitions/dos.c
+++ b/common/partitions/dos.c
@@ -251,7 +251,7 @@ static void dos_partition(void *buf, struct block_device *blk,
 	 * signature and pp is a zero-filled hex representation of the 1-based
 	 * partition number.
 	 */
-	dev_add_param_int(blk->dev, "nt_signature",
+	dev_add_param_uint32(blk->dev, "nt_signature",
 			dos_set_disk_signature, dos_get_disk_signature,
 			&dsp->signature, "%08x", dsp);
 }
diff --git a/common/state/state_variables.c b/common/state/state_variables.c
index 5b8e6284d9..56bcd9590a 100644
--- a/common/state/state_variables.c
+++ b/common/state/state_variables.c
@@ -108,7 +108,7 @@ static struct state_variable *state_uint8_create(struct state *state,
 
 	su32 = xzalloc(sizeof(*su32));
 
-	param = dev_add_param_int(&state->dev, name, state_uint8_set,
+	param = dev_add_param_uint32(&state->dev, name, state_uint8_set,
 				  NULL, &su32->value, "%u", &su32->var);
 	if (IS_ERR(param)) {
 		free(su32);
@@ -136,7 +136,7 @@ static struct state_variable *state_uint32_create(struct state *state,
 
 	su32 = xzalloc(sizeof(*su32));
 
-	param = dev_add_param_int(&state->dev, name, state_set_dirty,
+	param = dev_add_param_uint32(&state->dev, name, state_set_dirty,
 				  NULL, &su32->value, "%u", &su32->var);
 	if (IS_ERR(param)) {
 		free(su32);
diff --git a/drivers/amba/bus.c b/drivers/amba/bus.c
index ddd9661806..ae5df13c96 100644
--- a/drivers/amba/bus.c
+++ b/drivers/amba/bus.c
@@ -155,7 +155,7 @@ int amba_device_add(struct amba_device *dev)
 	if (ret)
 		goto err_release;
 
-	dev_add_param_int_ro(&dev->dev, "periphid", dev->periphid, "0x%08x");
+	dev_add_param_uint32_fixed(&dev->dev, "periphid", dev->periphid, "0x%08x");
 
 	return ret;
  err_release:
diff --git a/drivers/efi/efi-device.c b/drivers/efi/efi-device.c
index e9b03cb02a..77802fcb95 100644
--- a/drivers/efi/efi-device.c
+++ b/drivers/efi/efi-device.c
@@ -404,11 +404,11 @@ static int efi_init_devices(void)
 	dev_add_param_fixed(efi_bus.dev, "fw_vendor", fw_vendor);
 	free(fw_vendor);
 
-	dev_add_param_int_ro(efi_bus.dev, "major", sys_major, "%u");
-	dev_add_param_int_ro(efi_bus.dev, "minor", sys_minor, "%u");
-	dev_add_param_int_ro(efi_bus.dev, "fw_revision", efi_sys_table->fw_revision, "%u");
-	dev_add_param_int_ro(efi_bus.dev, "secure_boot", secure_boot, "%d");
-	dev_add_param_int_ro(efi_bus.dev, "secure_mode",
+	dev_add_param_uint32_fixed(efi_bus.dev, "major", sys_major, "%u");
+	dev_add_param_uint32_fixed(efi_bus.dev, "minor", sys_minor, "%u");
+	dev_add_param_uint32_fixed(efi_bus.dev, "fw_revision", efi_sys_table->fw_revision, "%u");
+	dev_add_param_bool_fixed(efi_bus.dev, "secure_boot", secure_boot, "%u");
+	dev_add_param_bool_fixed(efi_bus.dev, "secure_mode",
 			     secure_boot & setup_mode, "%u");
 
 	efi_bus.dev->info = efi_businfo;
diff --git a/drivers/input/qt1070.c b/drivers/input/qt1070.c
index 1ee868dfdd..d81a8fa401 100644
--- a/drivers/input/qt1070.c
+++ b/drivers/input/qt1070.c
@@ -238,8 +238,8 @@ static int qt1070_probe(struct device_d *dev)
 		goto err;
 	}
 
-	dev_add_param_int_ro(dev, "fw_version", fw_version, "0x%x");
-	dev_add_param_int_ro(dev, "chip_ip", chip_id, "0x%x");
+	dev_add_param_uint32_fixed(dev, "fw_version", fw_version, "0x%x");
+	dev_add_param_uint32_fixed(dev, "chip_ip", chip_id, "0x%x");
 
 	memcpy(data->code, default_code, sizeof(int) * ARRAY_SIZE(default_code));
 
diff --git a/drivers/mtd/core.c b/drivers/mtd/core.c
index f071373501..1950ee87ee 100644
--- a/drivers/mtd/core.c
+++ b/drivers/mtd/core.c
@@ -637,10 +637,10 @@ int add_mtd_device(struct mtd_info *mtd, const char *devname, int device_id)
 	mtd->cdev.mtd = mtd;
 
 	if (IS_ENABLED(CONFIG_PARAMETER)) {
-		dev_add_param_llint_ro(&mtd->class_dev, "size", mtd->size, "%llu");
-		dev_add_param_int_ro(&mtd->class_dev, "erasesize", mtd->erasesize, "%u");
-		dev_add_param_int_ro(&mtd->class_dev, "writesize", mtd->writesize, "%u");
-		dev_add_param_int_ro(&mtd->class_dev, "oobsize", mtd->oobsize, "%u");
+		dev_add_param_uint64_ro(&mtd->class_dev, "size", &mtd->size, "%llu");
+		dev_add_param_uint32_ro(&mtd->class_dev, "erasesize", &mtd->erasesize, "%u");
+		dev_add_param_uint32_ro(&mtd->class_dev, "writesize", &mtd->writesize, "%u");
+		dev_add_param_uint32_ro(&mtd->class_dev, "oobsize", &mtd->oobsize, "%u");
 	}
 
 	ret = devfs_create(&mtd->cdev);
diff --git a/drivers/mtd/ubi/build.c b/drivers/mtd/ubi/build.c
index 2ea66ed067..40fa890c9e 100644
--- a/drivers/mtd/ubi/build.c
+++ b/drivers/mtd/ubi/build.c
@@ -656,17 +656,17 @@ int ubi_attach_mtd_dev(struct mtd_info *mtd, int ubi_num,
 	ubi_msg(ubi, "available PEBs: %d, total reserved PEBs: %d, PEBs reserved for bad PEB handling: %d",
 		ubi->avail_pebs, ubi->rsvd_pebs, ubi->beb_rsvd_pebs);
 
-	dev_add_param_int_ro(&ubi->dev, "peb_size", ubi->peb_size, "%d");
-	dev_add_param_int_ro(&ubi->dev, "leb_size", ubi->leb_size, "%d");
-	dev_add_param_int_ro(&ubi->dev, "vid_header_offset", ubi->vid_hdr_offset, "%d");
-	dev_add_param_int_ro(&ubi->dev, "min_io_size", ubi->min_io_size, "%d");
-	dev_add_param_int_ro(&ubi->dev, "sub_page_size", ubi->hdrs_min_io_size, "%d");
-	dev_add_param_int_ro(&ubi->dev, "good_peb_count", ubi->good_peb_count, "%d");
-	dev_add_param_int_ro(&ubi->dev, "bad_peb_count", ubi->bad_peb_count, "%d");
-	dev_add_param_int_ro(&ubi->dev, "max_erase_counter", ubi->max_ec, "%d");
-	dev_add_param_int_ro(&ubi->dev, "mean_erase_counter", ubi->mean_ec, "%d");
-	dev_add_param_int_ro(&ubi->dev, "available_pebs", ubi->avail_pebs, "%d");
-	dev_add_param_int_ro(&ubi->dev, "reserved_pebs", ubi->rsvd_pebs, "%d");
+	dev_add_param_uint32_ro(&ubi->dev, "peb_size", &ubi->peb_size, "%u");
+	dev_add_param_uint32_ro(&ubi->dev, "leb_size", &ubi->leb_size, "%u");
+	dev_add_param_uint32_ro(&ubi->dev, "vid_header_offset", &ubi->vid_hdr_offset, "%u");
+	dev_add_param_uint32_ro(&ubi->dev, "min_io_size", &ubi->min_io_size, "%u");
+	dev_add_param_uint32_ro(&ubi->dev, "sub_page_size", &ubi->hdrs_min_io_size, "%u");
+	dev_add_param_uint32_ro(&ubi->dev, "good_peb_count", &ubi->good_peb_count, "%u");
+	dev_add_param_uint32_ro(&ubi->dev, "bad_peb_count", &ubi->bad_peb_count, "%u");
+	dev_add_param_uint32_ro(&ubi->dev, "max_erase_counter", &ubi->max_ec, "%u");
+	dev_add_param_uint32_ro(&ubi->dev, "mean_erase_counter", &ubi->mean_ec, "%u");
+	dev_add_param_uint32_ro(&ubi->dev, "available_pebs", &ubi->avail_pebs, "%u");
+	dev_add_param_uint32_ro(&ubi->dev, "reserved_pebs", &ubi->rsvd_pebs, "%u");
 
 	ubi_devices[ubi_num] = ubi;
 
diff --git a/drivers/net/phy/mdio_bus.c b/drivers/net/phy/mdio_bus.c
index 41bf018141..012b90e834 100644
--- a/drivers/net/phy/mdio_bus.c
+++ b/drivers/net/phy/mdio_bus.c
@@ -330,8 +330,8 @@ static int mdio_bus_probe(struct device_d *_dev)
 	of_set_phy_supported(dev);
 	dev->advertising = dev->supported;
 
-	dev_add_param_int_ro(&dev->dev, "phy_addr", dev->addr, "%d");
-	dev_add_param_int_ro(&dev->dev, "phy_id", dev->phy_id, "0x%08x");
+	dev_add_param_uint32_ro(&dev->dev, "phy_addr", &dev->addr, "%u");
+	dev_add_param_uint32_ro(&dev->dev, "phy_id", &dev->phy_id, "0x%08x");
 
 	dev->cdev.name = xasprintf("mdio%d-phy%02x",
 				   dev->bus->dev.id,
diff --git a/drivers/pwm/core.c b/drivers/pwm/core.c
index ee65619c4e..80fade0611 100644
--- a/drivers/pwm/core.c
+++ b/drivers/pwm/core.c
@@ -99,12 +99,12 @@ int pwmchip_add(struct pwm_chip *chip, struct device_d *dev)
 
 	list_add_tail(&pwm->node, &pwm_list);
 
-	p = dev_add_param_int(&pwm->dev, "duty_ns", set_duty_period_ns,
+	p = dev_add_param_uint32(&pwm->dev, "duty_ns", set_duty_period_ns,
 			NULL, &pwm->chip->duty_ns, "%u", pwm);
 	if (IS_ERR(p))
 		return PTR_ERR(p);
 
-	p = dev_add_param_int(&pwm->dev, "period_ns", set_duty_period_ns,
+	p = dev_add_param_uint32(&pwm->dev, "period_ns", set_duty_period_ns,
 			NULL, &pwm->chip->period_ns, "%u", pwm);
 	if (IS_ERR(p))
 		return PTR_ERR(p);
diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
index aba2da0ad3..9170ba4d53 100644
--- a/drivers/usb/core/usb.c
+++ b/drivers/usb/core/usb.c
@@ -447,19 +447,19 @@ int usb_new_device(struct usb_device *dev)
 		goto err_out;
 	}
 
-	dev_add_param_int_ro(&dev->dev, "iManufacturer",
-			dev->descriptor->iManufacturer, "%d");
-	dev_add_param_int_ro(&dev->dev, "iProduct",
-			dev->descriptor->iProduct, "%d");
-	dev_add_param_int_ro(&dev->dev, "iSerialNumber",
-			dev->descriptor->iSerialNumber, "%d");
+	dev_add_param_uint32_fixed(&dev->dev, "iManufacturer",
+			dev->descriptor->iManufacturer, "%u");
+	dev_add_param_uint32_fixed(&dev->dev, "iProduct",
+			dev->descriptor->iProduct, "%u");
+	dev_add_param_uint32_fixed(&dev->dev, "iSerialNumber",
+			dev->descriptor->iSerialNumber, "%u");
 	dev_add_param_fixed(&dev->dev, "iSerialNumber", str);
 	dev_add_param_fixed(&dev->dev, "Manufacturer", dev->mf);
 	dev_add_param_fixed(&dev->dev, "Product", dev->prod);
 	dev_add_param_fixed(&dev->dev, "SerialNumber", dev->serial);
-	dev_add_param_int_ro(&dev->dev, "idVendor",
+	dev_add_param_uint32_fixed(&dev->dev, "idVendor",
 			dev->descriptor->idVendor, "%04x");
-	dev_add_param_int_ro(&dev->dev, "idProduct",
+	dev_add_param_uint32_fixed(&dev->dev, "idProduct",
 			dev->descriptor->idProduct, "%04x");
 	list_add_tail(&dev->list, &usb_device_list);
 	dev_count++;
diff --git a/drivers/usb/gadget/udc-core.c b/drivers/usb/gadget/udc-core.c
index 4f001e102f..ed99b53df7 100644
--- a/drivers/usb/gadget/udc-core.c
+++ b/drivers/usb/gadget/udc-core.c
@@ -187,9 +187,9 @@ int usb_add_gadget_udc_release(struct device_d *parent, struct usb_gadget *gadge
 	if (ret)
 		goto err2;
 
-	dev_add_param_int(&gadget->dev, "product", NULL, NULL,
+	dev_add_param_uint32(&gadget->dev, "product", NULL, NULL,
 			&gadget->product_id, "0x%04x", NULL);
-	dev_add_param_int(&gadget->dev, "vendor", NULL, NULL,
+	dev_add_param_uint32(&gadget->dev, "vendor", NULL, NULL,
 			&gadget->vendor_id, "0x%04x", NULL);
 	gadget->manufacturer = xstrdup("barebox");
 	dev_add_param_string(&gadget->dev, "manufacturer", NULL, NULL,
diff --git a/drivers/video/backlight.c b/drivers/video/backlight.c
index ddde6f8523..09c0e47af6 100644
--- a/drivers/video/backlight.c
+++ b/drivers/video/backlight.c
@@ -70,7 +70,7 @@ int backlight_register(struct backlight_device *bl)
 	if (ret)
 		return ret;
 
-	dev_add_param_int(&bl->dev, "brightness", backlight_brightness_set,
+	dev_add_param_uint32(&bl->dev, "brightness", backlight_brightness_set,
 			NULL, &bl->brightness, "%d", bl);
 
 	list_add_tail(&bl->list, &backlights);
diff --git a/drivers/video/imx-ipu-fb.c b/drivers/video/imx-ipu-fb.c
index 7c3a800149..9cc7a911ea 100644
--- a/drivers/video/imx-ipu-fb.c
+++ b/drivers/video/imx-ipu-fb.c
@@ -978,7 +978,7 @@ static int sdc_fb_register_overlay(struct ipu_fb_info *fbi, void *fb)
 		return ret;
 	}
 
-	dev_add_param_int(&overlay->dev, "alpha", sdc_alpha_set,
+	dev_add_param_uint32(&overlay->dev, "alpha", sdc_alpha_set,
 			NULL, &fbi->alpha, "%u", overlay);
 
 	return 0;
diff --git a/drivers/video/imx.c b/drivers/video/imx.c
index 78cb5c0ca2..947f8d5349 100644
--- a/drivers/video/imx.c
+++ b/drivers/video/imx.c
@@ -530,7 +530,7 @@ static int imxfb_register_overlay(struct imxfb_info *fbi, void *fb)
 		return ret;
 	}
 
-	dev_add_param_int(&overlay->dev, "alpha", imxfb_alpha_set,
+	dev_add_param_uint32(&overlay->dev, "alpha", imxfb_alpha_set,
 			NULL, &fbi->alpha, "%u", overlay);
 
 	return 0;
diff --git a/include/param.h b/include/param.h
index 2eb040fea4..be4cca7b68 100644
--- a/include/param.h
+++ b/include/param.h
@@ -52,15 +52,10 @@ struct param_d *dev_add_param_string(struct device_d *dev, const char *name,
 		int (*get)(struct param_d *p, void *priv),
 		char **value, void *priv);
 
-struct param_d *dev_add_param_int(struct device_d *dev, const char *name,
+struct param_d *__dev_add_param_int(struct device_d *dev, const char *name,
 		int (*set)(struct param_d *p, void *priv),
 		int (*get)(struct param_d *p, void *priv),
-		int *value, const char *format, void *priv);
-
-struct param_d *dev_add_param_bool(struct device_d *dev, const char *name,
-		int (*set)(struct param_d *p, void *priv),
-		int (*get)(struct param_d *p, void *priv),
-		int *value, void *priv);
+		void *value, enum param_type type, const char *format, void *priv);
 
 struct param_d *dev_add_param_enum(struct device_d *dev, const char *name,
 		int (*set)(struct param_d *p, void *priv),
@@ -72,12 +67,6 @@ struct param_d *dev_add_param_bitmask(struct device_d *dev, const char *name,
 		int (*get)(struct param_d *p, void *priv),
 		unsigned long *value, const char * const *names, int max, void *priv);
 
-struct param_d *dev_add_param_int_ro(struct device_d *dev, const char *name,
-		int value, const char *format);
-
-struct param_d *dev_add_param_llint_ro(struct device_d *dev, const char *name,
-		long long value, const char *format);
-
 struct param_d *dev_add_param_ip(struct device_d *dev, const char *name,
 		int (*set)(struct param_d *p, void *priv),
 		int (*get)(struct param_d *p, void *priv),
@@ -88,7 +77,7 @@ struct param_d *dev_add_param_mac(struct device_d *dev, const char *name,
 		int (*get)(struct param_d *p, void *priv),
 		u8 *mac, void *priv);
 
-int dev_add_param_fixed(struct device_d *dev, const char *name, const char *value);
+struct param_d *dev_add_param_fixed(struct device_d *dev, const char *name, const char *value);
 
 void dev_remove_param(struct param_d *p);
 
@@ -129,10 +118,10 @@ static inline struct param_d *dev_add_param_string(struct device_d *dev, const c
 	return ERR_PTR(-ENOSYS);
 }
 
-static inline struct param_d *dev_add_param_int(struct device_d *dev, const char *name,
+static inline struct param_d *__dev_add_param_int(struct device_d *dev, const char *name,
 		int (*set)(struct param_d *p, void *priv),
 		int (*get)(struct param_d *p, void *priv),
-		int *value, const char *format, void *priv)
+		void *value, enum param_type type, const char *format, void *priv)
 {
 	return ERR_PTR(-ENOSYS);
 }
@@ -154,56 +143,162 @@ static inline struct param_d *dev_add_param_bitmask(struct device_d *dev, const
 	return ERR_PTR(-ENOSYS);
 }
 
-static inline struct param_d *dev_add_param_bool(struct device_d *dev, const char *name,
+static inline struct param_d *dev_add_param_ip(struct device_d *dev, const char *name,
 		int (*set)(struct param_d *p, void *priv),
 		int (*get)(struct param_d *p, void *priv),
-		int *value, void *priv)
+		IPaddr_t *ip, void *priv)
 {
 	return ERR_PTR(-ENOSYS);
 }
 
-static inline struct param_d *dev_add_param_int_ro(struct device_d *dev, const char *name,
-		int value, const char *format)
+static inline struct param_d *dev_add_param_mac(struct device_d *dev, const char *name,
+		int (*set)(struct param_d *p, void *priv),
+		int (*get)(struct param_d *p, void *priv),
+		u8 *mac, void *priv)
 {
 	return ERR_PTR(-ENOSYS);
 }
 
-static inline struct param_d *dev_add_param_llint_ro(struct device_d *dev, const char *name,
-		long long value, const char *format)
+static inline struct param_d *dev_add_param_fixed(struct device_d *dev, const char *name,
+						  const char *value)
 {
 	return ERR_PTR(-ENOSYS);
 }
 
-static inline struct param_d *dev_add_param_ip(struct device_d *dev, const char *name,
+static inline void dev_remove_param(struct param_d *p) {}
+
+static inline void dev_remove_parameters(struct device_d *dev) {}
+
+static inline int dev_param_set_generic(struct device_d *dev, struct param_d *p,
+		const char *val)
+{
+	return 0;
+}
+#endif
+
+int param_set_readonly(struct param_d *p, void *priv);
+
+/*
+ * dev_add_param_int
+ * dev_add_param_int32
+ * dev_add_param_uint32
+ * dev_add_param_int64
+ * dev_add_param_uint64
+ */
+#define DECLARE_PARAM_INT(intname, inttype, paramtype) \
+	static inline struct param_d *dev_add_param_##intname(struct device_d *dev, const char *name,	\
+			int (*set)(struct param_d *p, void *priv),					\
+			int (*get)(struct param_d *p, void *priv),					\
+			inttype *value, const char *format, void *priv)					\
+	{												\
+		return __dev_add_param_int(dev, name, set, get, value, paramtype, format, priv);	\
+	}
+
+DECLARE_PARAM_INT(int, int, PARAM_TYPE_INT32)
+DECLARE_PARAM_INT(int32, int32_t, PARAM_TYPE_INT32)
+DECLARE_PARAM_INT(uint32, uint32_t, PARAM_TYPE_UINT32)
+DECLARE_PARAM_INT(int64, int64_t, PARAM_TYPE_INT64)
+DECLARE_PARAM_INT(uint64, uint64_t, PARAM_TYPE_UINT64)
+
+/*
+ * dev_add_param_int_fixed
+ * dev_add_param_int32_fixed
+ * dev_add_param_uint32_fixed
+ * dev_add_param_int64_fixed
+ * dev_add_param_uint64_fixed
+ */
+#define DECLARE_PARAM_INT_FIXED(intname, inttype, paramtype) \
+	static inline struct param_d *dev_add_param_##intname##_fixed(struct device_d *dev, const char *name,	\
+			inttype value, const char *format)							\
+	{													\
+		return __dev_add_param_int(dev, name, ERR_PTR(-EROFS), NULL, &value, paramtype, format, NULL);	\
+	}
+
+DECLARE_PARAM_INT_FIXED(int, int, PARAM_TYPE_INT32)
+DECLARE_PARAM_INT_FIXED(int32, int32_t, PARAM_TYPE_INT32)
+DECLARE_PARAM_INT_FIXED(uint32, uint32_t, PARAM_TYPE_UINT32)
+DECLARE_PARAM_INT_FIXED(int64, int64_t, PARAM_TYPE_INT64)
+DECLARE_PARAM_INT_FIXED(uint64, uint64_t, PARAM_TYPE_UINT64)
+
+/*
+ * dev_add_param_int_ro
+ * dev_add_param_int32_ro
+ * dev_add_param_uint32_ro
+ * dev_add_param_int64_ro
+ * dev_add_param_uint64_ro
+ */
+#define DECLARE_PARAM_INT_RO(intname, inttype, paramtype) \
+	static inline struct param_d *dev_add_param_##intname##_ro(struct device_d *dev, const char *name,		\
+			inttype *value, const char *format)								\
+	{														\
+		return __dev_add_param_int(dev, name, param_set_readonly, NULL, value, paramtype, format, NULL);	\
+	}
+
+DECLARE_PARAM_INT_RO(int, int, PARAM_TYPE_INT32)
+DECLARE_PARAM_INT_RO(int32, int32_t, PARAM_TYPE_INT32)
+DECLARE_PARAM_INT_RO(uint32, uint32_t, PARAM_TYPE_UINT32)
+DECLARE_PARAM_INT_RO(int64, int64_t, PARAM_TYPE_INT64)
+DECLARE_PARAM_INT_RO(uint64, uint64_t, PARAM_TYPE_UINT64)
+
+static inline struct param_d *dev_add_param_bool(struct device_d *dev, const char *name,
 		int (*set)(struct param_d *p, void *priv),
 		int (*get)(struct param_d *p, void *priv),
-		IPaddr_t *ip, void *priv)
+		uint32_t *value, void *priv)
 {
-	return ERR_PTR(-ENOSYS);
+	return __dev_add_param_int(dev, name, set, get, value, PARAM_TYPE_BOOL, "%u", priv);
 }
 
-static inline struct param_d *dev_add_param_mac(struct device_d *dev, const char *name,
+static inline struct param_d *dev_add_param_bool_fixed(struct device_d *dev, const char *name,
+		uint32_t value)
+{
+	return __dev_add_param_int(dev, name, ERR_PTR(-EROFS), NULL, &value, PARAM_TYPE_BOOL,
+				   "%u", NULL);
+}
+
+static inline struct param_d *dev_add_param_bool_ro(struct device_d *dev, const char *name,
+		uint32_t *value)
+{
+	return __dev_add_param_int(dev, name, param_set_readonly, NULL, value, PARAM_TYPE_BOOL,
+				   "%u", NULL);
+}
+
+static inline struct param_d *dev_add_param_string_ro(struct device_d *dev, const char *name,
 		int (*set)(struct param_d *p, void *priv),
 		int (*get)(struct param_d *p, void *priv),
-		u8 *mac, void *priv)
+		char **value, void *priv)
 {
-	return ERR_PTR(-ENOSYS);
+	return dev_add_param_string(dev, name, param_set_readonly, NULL, value, NULL);
 }
 
-static inline int dev_add_param_fixed(struct device_d *dev, const char *name, const char *value)
+static inline struct param_d *dev_add_param_string_fixed(struct device_d *dev, const char *name,
+		char *value)
 {
-	return 0;
+	return dev_add_param_fixed(dev, name, value);
 }
 
-static inline void dev_remove_param(struct param_d *p) {}
-
-static inline void dev_remove_parameters(struct device_d *dev) {}
+static inline struct param_d *dev_add_param_enum_ro(struct device_d *dev, const char *name,
+		int *value, const char * const *names, int max)
+{
+	return dev_add_param_enum(dev, name, param_set_readonly, NULL,
+				  value, names, max, NULL);
+}
 
-static inline int dev_param_set_generic(struct device_d *dev, struct param_d *p,
-		const char *val)
+static inline struct param_d *dev_add_param_bitmask_ro(struct device_d *dev, const char *name,
+		int (*set)(struct param_d *p, void *priv),
+		int (*get)(struct param_d *p, void *priv),
+		unsigned long *value, const char * const *names, int max, void *priv)
 {
-	return 0;
+	return dev_add_param_bitmask(dev, name, param_set_readonly, NULL,
+				     value, names, max, NULL);
 }
-#endif
 
+/*
+ * unimplemented:
+ * dev_add_param_enum_fixed
+ * dev_add_param_bitmask_fixed
+ * dev_add_param_ip_ro
+ * dev_add_param_ip_fixed
+ * dev_add_param_mac_ro
+ * dev_add_param_mac_fixed
+ */
 #endif /* PARAM_H */
diff --git a/lib/parameter.c b/lib/parameter.c
index 6456779e71..a21b8fa4a4 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -218,7 +218,7 @@ struct param_d *dev_add_param(struct device_d *dev, const char *name,
  * @param name	The name of the parameter
  * @param value	The value of the parameter
  */
-int dev_add_param_fixed(struct device_d *dev, const char *name, const char *value)
+struct param_d *dev_add_param_fixed(struct device_d *dev, const char *name, const char *value)
 {
 	struct param_d *param;
 	int ret;
@@ -228,12 +228,12 @@ int dev_add_param_fixed(struct device_d *dev, const char *name, const char *valu
 	ret = __dev_add_param(param, dev, name, NULL, NULL, PARAM_FLAG_RO);
 	if (ret) {
 		free(param);
-		return ret;
+		return ERR_PTR(ret);
 	}
 
 	param->value = strdup(value);
 
-	return 0;
+	return param;
 }
 
 struct param_string {
@@ -315,10 +315,9 @@ struct param_d *dev_add_param_string(struct device_d *dev, const char *name,
 
 struct param_int {
 	struct param_d param;
-	int *value;
+	void *value;
+	int dsize;
 	const char *format;
-#define PARAM_INT_FLAG_BOOL (1 << 0)
-	unsigned flags;
 	int (*set)(struct param_d *p, void *priv);
 	int (*get)(struct param_d *p, void *priv);
 };
@@ -331,18 +330,32 @@ static inline struct param_int *to_param_int(struct param_d *p)
 static int param_int_set(struct device_d *dev, struct param_d *p, const char *val)
 {
 	struct param_int *pi = to_param_int(p);
-	int value_save = *pi->value;
+	u8 value_save[pi->dsize];
 	int ret;
 
 	if (!val)
 		return -EINVAL;
 
-	if (pi->flags & PARAM_INT_FLAG_BOOL) {
+	memcpy(value_save, pi->value, pi->dsize);
+
+	switch (p->type) {
+	case PARAM_TYPE_BOOL:
 		ret = strtobool(val, pi->value);
-		if (ret)
-			return ret;
-	} else {
-		*pi->value = simple_strtol(val, NULL, 0);
+		break;
+	case PARAM_TYPE_INT32:
+		*(uint32_t *)pi->value = simple_strtol(val, NULL, 0);
+		break;
+	case PARAM_TYPE_UINT32:
+		*(int32_t *)pi->value = simple_strtoul(val, NULL, 0);
+		break;
+	case PARAM_TYPE_INT64:
+		*(int64_t *)pi->value = simple_strtoll(val, NULL, 0);
+		break;
+	case PARAM_TYPE_UINT64:
+		*(uint64_t *)pi->value = simple_strtoull(val, NULL, 0);
+		break;
+	default:
+		return -EINVAL;
 	}
 
 	if (!pi->set)
@@ -350,7 +363,7 @@ static int param_int_set(struct device_d *dev, struct param_d *p, const char *va
 
 	ret = pi->set(p, p->driver_priv);
 	if (ret)
-		*pi->value = value_save;
+		memcpy(pi->value, value_save, pi->dsize);
 
 	return ret;
 }
@@ -367,11 +380,28 @@ static const char *param_int_get(struct device_d *dev, struct param_d *p)
 	}
 
 	free(p->value);
-	p->value = basprintf(pi->format, *pi->value);
+	switch (p->type) {
+	case PARAM_TYPE_BOOL:
+	case PARAM_TYPE_INT32:
+	case PARAM_TYPE_UINT32:
+		p->value = basprintf(pi->format, *(int32_t *)pi->value);
+		break;
+	case PARAM_TYPE_INT64:
+	case PARAM_TYPE_UINT64:
+		p->value = basprintf(pi->format, *(int64_t *)pi->value);
+		break;
+	default:
+		return NULL;
+	}
 
 	return p->value;
 }
 
+int param_set_readonly(struct param_d *p, void *priv)
+{
+	return -EROFS;
+}
+
 /**
  * dev_add_param_int - add an integer parameter to a device
  * @param dev	The device
@@ -379,6 +409,7 @@ static const char *param_int_get(struct device_d *dev, struct param_d *p)
  * @param set	set function
  * @param get	get function
  * @param value	pointer to the integer containing the value of the parameter
+ * @param type  The variable type
  * @param format the printf format used to print the value
  * @param priv	user private data, will be passed to get/set
  *
@@ -387,23 +418,51 @@ static const char *param_int_get(struct device_d *dev, struct param_d *p)
  * The set function can be used as a notifer when the variable is about
  * to be written. Can also be used to limit the value.
  */
-struct param_d *dev_add_param_int(struct device_d *dev, const char *name,
+struct param_d *__dev_add_param_int(struct device_d *dev, const char *name,
 		int (*set)(struct param_d *p, void *priv),
 		int (*get)(struct param_d *p, void *priv),
-		int *value, const char *format, void *priv)
+		void *value, enum param_type type, const char *format, void *priv)
 {
 	struct param_int *pi;
 	struct param_d *p;
-	int ret;
+	int ret, dsize;
+
+	switch (type) {
+	case PARAM_TYPE_BOOL:
+		dsize = sizeof(uint32_t);
+		break;
+	case PARAM_TYPE_INT32:
+		dsize = sizeof(int32_t);
+		break;
+	case PARAM_TYPE_UINT32:
+		dsize = sizeof(uint32_t);
+		break;
+	case PARAM_TYPE_INT64:
+		dsize = sizeof(int64_t);
+		break;
+	case PARAM_TYPE_UINT64:
+		dsize = sizeof(uint64_t);
+		break;
+	default:
+		return ERR_PTR(-EINVAL);
+	}
 
 	pi = xzalloc(sizeof(*pi));
-	pi->value = value;
+
+	if (IS_ERR(set)) {
+		pi->value = xmemdup(value, dsize);
+		set = param_set_readonly;
+	} else {
+		pi->value = value;
+	}
+
+	pi->dsize = dsize;
 	pi->format = format;
 	pi->set = set;
 	pi->get = get;
 	p = &pi->param;
 	p->driver_priv = priv;
-	p->type = PARAM_TYPE_INT32;
+	p->type = type;
 
 	ret = __dev_add_param(p, dev, name, param_int_set, param_int_get, 0);
 	if (ret) {
@@ -662,99 +721,6 @@ struct param_d *dev_add_param_bitmask(struct device_d *dev, const char *name,
 	return &pb->param;
 }
 
-/**
- * dev_add_param_bool - add an boolean parameter to a device
- * @param dev	The device
- * @param name	The name of the parameter
- * @param set	set function
- * @param get	get function
- * @param value	pointer to the integer containing the value of the parameter
- * @param priv	user private data, will be passed to get/set
- *
- * The get function can be used as a notifier when the variable is about
- * to be read.
- * The set function can be used as a notifer when the variable is about
- * to be written. Can also be used to limit the value.
- */
-struct param_d *dev_add_param_bool(struct device_d *dev, const char *name,
-		int (*set)(struct param_d *p, void *priv),
-		int (*get)(struct param_d *p, void *priv),
-		int *value, void *priv)
-{
-	struct param_int *pi;
-	struct param_d *p;
-
-	p = dev_add_param_int(dev, name, set, get, value, "%d", priv);
-	if (IS_ERR(p))
-		return p;
-
-	p->type = PARAM_TYPE_BOOL;
-
-	pi = to_param_int(p);
-	pi->flags |= PARAM_INT_FLAG_BOOL;
-
-	return p;
-}
-
-struct param_int_ro {
-	struct param_d param;
-	char *value;
-};
-
-/**
- * dev_add_param_int_ro - add a read only integer parameter to a device
- * @param dev	The device
- * @param name	The name of the parameter
- * @param value	The value of the parameter
- * @param format the printf format used to print the value
- */
-struct param_d *dev_add_param_int_ro(struct device_d *dev, const char *name,
-		int value, const char *format)
-{
-	struct param_int *piro;
-	int ret;
-
-	piro = xzalloc(sizeof(*piro));
-
-	ret = __dev_add_param(&piro->param, dev, name, NULL, NULL, PARAM_FLAG_RO);
-	if (ret) {
-		free(piro);
-		return ERR_PTR(ret);
-	}
-
-	piro->param.type = PARAM_TYPE_INT32;
-	piro->param.value = basprintf(format, value);
-
-	return &piro->param;
-}
-
-/**
- * dev_add_param_llint_ro - add a read only long long parameter to a device
- * @param dev	The device
- * @param name	The name of the parameter
- * @param value	The value of the parameter
- * @param format the printf format used to print the value
- */
-struct param_d *dev_add_param_llint_ro(struct device_d *dev, const char *name,
-		long long value, const char *format)
-{
-	struct param_int *piro;
-	int ret;
-
-	piro = xzalloc(sizeof(*piro));
-
-	ret = __dev_add_param(&piro->param, dev, name, NULL, NULL, PARAM_FLAG_RO);
-	if (ret) {
-		free(piro);
-		return ERR_PTR(ret);
-	}
-
-	piro->param.type = PARAM_TYPE_INT64;
-	piro->param.value = basprintf(format, value);
-
-	return &piro->param;
-}
-
 struct param_ip {
 	struct param_d param;
 	IPaddr_t *ip;
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 09/10] globalvar: make globalvar functions more consistent
  2017-04-10  7:14 improve device parameter types Sascha Hauer
                   ` (7 preceding siblings ...)
  2017-04-10  7:14 ` [PATCH 08/10] param: make parameter functions more consistent Sascha Hauer
@ 2017-04-10  7:14 ` Sascha Hauer
  2017-04-10  7:14 ` [PATCH 10/10] param: remove unnecessary device_d * argument Sascha Hauer
  9 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-04-10  7:14 UTC (permalink / raw)
  To: Barebox List

Similar to the device parameter functions also make the globalvar
functions more consistent. This also adds support for readonly
globalvars and changes several existing globalvars which should
really be readonly to readonly.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 arch/arm/boards/beaglebone/board.c               |   2 +-
 arch/arm/boards/crystalfontz-cfa10036/hwdetect.c |   2 +-
 arch/arm/boards/phytec-som-imx6/board.c          |   2 +-
 arch/arm/boards/vscom-baltos/board.c             |   7 +-
 arch/ppc/boards/pcm030/eeprom.c                  |   4 +-
 common/boot.c                                    |   2 +-
 common/bootchooser.c                             |   4 +-
 common/bootm.c                                   |   2 +-
 common/console_common.c                          |   6 +-
 common/globalvar.c                               |  28 ++----
 common/password.c                                |   2 +-
 common/reset_source.c                            |   2 +-
 drivers/mtd/peb.c                                |   6 +-
 include/globalvar.h                              | 109 ++++++++++++++++++++---
 14 files changed, 123 insertions(+), 55 deletions(-)

diff --git a/arch/arm/boards/beaglebone/board.c b/arch/arm/boards/beaglebone/board.c
index 5717c45020..18a9a10a86 100644
--- a/arch/arm/boards/beaglebone/board.c
+++ b/arch/arm/boards/beaglebone/board.c
@@ -87,7 +87,7 @@ static int beaglebone_devices_init(void)
 
 	defaultenv_append_directory(defaultenv_beaglebone);
 
-	globalvar_add_simple("board.variant", black ? "boneblack" : "bone");
+	globalvar_add_simple_string_fixed("board.variant", black ? "boneblack" : "bone");
 
 	printf("detected 'BeagleBone %s'\n", black ? "Black" : "White");
 
diff --git a/arch/arm/boards/crystalfontz-cfa10036/hwdetect.c b/arch/arm/boards/crystalfontz-cfa10036/hwdetect.c
index c94cb355e2..d0907c11f0 100644
--- a/arch/arm/boards/crystalfontz-cfa10036/hwdetect.c
+++ b/arch/arm/boards/crystalfontz-cfa10036/hwdetect.c
@@ -105,7 +105,7 @@ void cfa10036_detect_hw(void)
 		return;
 	}
 
-	globalvar_add_simple("board.variant", board_name);
+	globalvar_add_simple_string_fixed("board.variant", board_name);
 
 	pr_info("Booting on a CFA10036 with %s\n", board_name);
 }
diff --git a/arch/arm/boards/phytec-som-imx6/board.c b/arch/arm/boards/phytec-som-imx6/board.c
index ed9453bdda..31b2761024 100644
--- a/arch/arm/boards/phytec-som-imx6/board.c
+++ b/arch/arm/boards/phytec-som-imx6/board.c
@@ -152,7 +152,7 @@ static int physom_imx6_devices_init(void)
 		phyflex_err006282_workaround();
 
 		pfla02_module_revision = get_module_rev();
-		globalvar_add_simple_int("board.revision", &pfla02_module_revision, "%u");
+		globalvar_add_simple_uint32_fixed("board.revision", pfla02_module_revision, "%u");
 		pr_info("Module Revision: %u\n", pfla02_module_revision);
 
 		barebox_set_hostname("phyFLEX-i.MX6");
diff --git a/arch/arm/boards/vscom-baltos/board.c b/arch/arm/boards/vscom-baltos/board.c
index 39f40a6061..1a4dc30936 100644
--- a/arch/arm/boards/vscom-baltos/board.c
+++ b/arch/arm/boards/vscom-baltos/board.c
@@ -64,7 +64,7 @@ static int baltos_read_eeprom(void)
 {
 	struct bsp_vs_hwparam hw_param;
 	size_t size;
-	char *buf, var_buf[32];
+	char *buf;
 	int rc;
 	unsigned char mac_addr[6];
 
@@ -107,8 +107,7 @@ static int baltos_read_eeprom(void)
 		hw_param.SystemId = 0;
 	}
 
-	sprintf(var_buf, "%d", hw_param.SystemId);
-	globalvar_add_simple("board.id", var_buf);
+	globalvar_add_simple_uint32_fixed("board.id", hw_param.SystemId, "%u");
 
 	/* enable mPCIe slot */
 	gpio_direction_output(100, 1);
@@ -131,7 +130,7 @@ static int baltos_devices_init(void)
 	if (!of_machine_is_compatible("vscom,onrisc"))
 		return 0;
 
-	globalvar_add_simple("board.variant", "baltos");
+	globalvar_add_simple_string_fixed("board.variant", "baltos");
 
 	if (bootsource_get() == BOOTSOURCE_MMC)
 		omap_set_bootmmc_devname("mmc0");
diff --git a/arch/ppc/boards/pcm030/eeprom.c b/arch/ppc/boards/pcm030/eeprom.c
index aa00f361cd..34bce85b94 100644
--- a/arch/ppc/boards/pcm030/eeprom.c
+++ b/arch/ppc/boards/pcm030/eeprom.c
@@ -53,7 +53,7 @@ static void pcm030_read_factory_data(const struct pcm030_eeprom *buf)
 			continue;
 		board = xstrndup(&buf->product[u], l);
 		u += l + 1;
-		globalvar_add_simple("model.type", board);
+		globalvar_add_simple_string_fixed("model.type", board);
 		free(board);
 	}
 
@@ -62,7 +62,7 @@ static void pcm030_read_factory_data(const struct pcm030_eeprom *buf)
 			continue;
 		serial = xstrndup(&buf->product[u], l);
 		u += l + 1;
-		globalvar_add_simple("model.serial", serial);
+		globalvar_add_simple_string_fixed("model.serial", serial);
 		free(serial);
 	}
 
diff --git a/common/boot.c b/common/boot.c
index cef3d5e514..a2d27d1593 100644
--- a/common/boot.c
+++ b/common/boot.c
@@ -123,7 +123,7 @@ void boot_set_watchdog_timeout(unsigned int timeout)
 
 static int init_boot_watchdog_timeout(void)
 {
-	return globalvar_add_simple_int("boot.watchdog_timeout",
+	return globalvar_add_simple_uint32("boot.watchdog_timeout",
 			&boot_watchdog_timeout, "%u");
 }
 late_initcall(init_boot_watchdog_timeout);
diff --git a/common/bootchooser.c b/common/bootchooser.c
index 455f290fa2..f6d99d130b 100644
--- a/common/bootchooser.c
+++ b/common/bootchooser.c
@@ -907,8 +907,8 @@ static int bootchooser_init(void)
 	globalvar_add_simple_bool("bootchooser.retry", &retry);
 	globalvar_add_simple_string("bootchooser.targets", &available_targets);
 	globalvar_add_simple_string("bootchooser.state_prefix", &state_prefix);
-	globalvar_add_simple_int("bootchooser.default_attempts", &global_default_attempts, "%u");
-	globalvar_add_simple_int("bootchooser.default_priority", &global_default_priority, "%u");
+	globalvar_add_simple_uint32("bootchooser.default_attempts", &global_default_attempts, "%u");
+	globalvar_add_simple_uint32("bootchooser.default_priority", &global_default_priority, "%u");
 	globalvar_add_simple_bitmask("bootchooser.reset_attempts", &reset_attempts,
 				  reset_attempts_names, ARRAY_SIZE(reset_attempts_names));
 	globalvar_add_simple_bitmask("bootchooser.reset_priorities", &reset_priorities,
diff --git a/common/bootm.c b/common/bootm.c
index 81625d9157..92cfeb6c32 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -668,7 +668,7 @@ static int bootm_init(void)
 	if (IS_ENABLED(CONFIG_BOOTM_FORCE_SIGNED_IMAGES))
 		bootm_verify_mode = BOOTM_VERIFY_SIGNATURE;
 
-	globalvar_add_simple_int("bootm.verbose", &bootm_verbosity, "%u");
+	globalvar_add_simple_uint32("bootm.verbose", &bootm_verbosity, "%u");
 
 	globalvar_add_simple_enum("bootm.verify", (unsigned int *)&bootm_verify_mode,
 				  bootm_verify_names, ARRAY_SIZE(bootm_verify_names));
diff --git a/common/console_common.c b/common/console_common.c
index d051458de4..b36b3ff083 100644
--- a/common/console_common.c
+++ b/common/console_common.c
@@ -148,10 +148,10 @@ int dev_printf(int level, const struct device_d *dev, const char *format, ...)
 static int loglevel_init(void)
 {
 	if (IS_ENABLED(CONFIG_LOGBUF))
-		globalvar_add_simple_int("log_max_messages",
-				&barebox_log_max_messages, "%d");
+		globalvar_add_simple_uint32("log_max_messages",
+				&barebox_log_max_messages, "%u");
 
-	return globalvar_add_simple_int("loglevel", &barebox_loglevel, "%d");
+	return globalvar_add_simple_uint32("loglevel", &barebox_loglevel, "%u");
 }
 device_initcall(loglevel_init);
 
diff --git a/common/globalvar.c b/common/globalvar.c
index 32ca6a24db..2f65ca805f 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -424,7 +424,7 @@ int globalvar_add_simple(const char *name, const char *value)
 	return 0;
 }
 
-int globalvar_add_simple_string(const char *name, char **value)
+int __globalvar_add_simple_string(const char *name, char **value)
 {
 	struct param_d *p;
 
@@ -439,28 +439,14 @@ int globalvar_add_simple_string(const char *name, char **value)
 	return 0;
 }
 
-int globalvar_add_simple_int(const char *name, int *value,
-			     const char *format)
+int __globalvar_add_simple_int(const char *name, void *value,
+				      enum param_type type,
+				      const char *format)
 {
 	struct param_d *p;
 
-	p = dev_add_param_int(&global_device, name, NULL, NULL,
-		value, format, NULL);
-
-	if (IS_ERR(p))
-		return PTR_ERR(p);
-
-	globalvar_nv_sync(name);
-
-	return 0;
-}
-
-int globalvar_add_simple_bool(const char *name, int *value)
-{
-	struct param_d *p;
-
-	p = dev_add_param_bool(&global_device, name, NULL, NULL,
-		value, NULL);
+	p = __dev_add_param_int(&global_device, name, NULL, NULL,
+		value, type, format, NULL);
 
 	if (IS_ERR(p))
 		return PTR_ERR(p);
@@ -522,7 +508,7 @@ static int globalvar_init(void)
 	if (IS_ENABLED(CONFIG_NVVAR))
 		register_device(&nv_device);
 
-	globalvar_add_simple("version", UTS_RELEASE);
+	globalvar_add_simple_string_fixed("version", UTS_RELEASE);
 
 	return 0;
 }
diff --git a/common/password.c b/common/password.c
index 74d328f4b2..5e6bfc53e7 100644
--- a/common/password.c
+++ b/common/password.c
@@ -443,7 +443,7 @@ static int login_global_init(void)
 {
 	login_fail_command = xstrdup("boot");
 
-	globalvar_add_simple_int("login.timeout", &login_timeout, "%d");
+	globalvar_add_simple_uint32("login.timeout", &login_timeout, "%u");
 	globalvar_add_simple_string("login.fail_command", &login_fail_command);
 
 	return 0;
diff --git a/common/reset_source.c b/common/reset_source.c
index 06e2ca85f5..e18bf6db68 100644
--- a/common/reset_source.c
+++ b/common/reset_source.c
@@ -54,7 +54,7 @@ EXPORT_SYMBOL(reset_source_set_priority);
 
 static int reset_source_init(void)
 {
-	globalvar_add_simple_enum("system.reset", (unsigned int *)&reset_source,
+	globalvar_add_simple_enum_ro("system.reset", (unsigned int *)&reset_source,
 			reset_src_names, ARRAY_SIZE(reset_src_names));
 
 	return 0;
diff --git a/drivers/mtd/peb.c b/drivers/mtd/peb.c
index c35b63f2fd..0e64fe1671 100644
--- a/drivers/mtd/peb.c
+++ b/drivers/mtd/peb.c
@@ -76,11 +76,11 @@ static int mtd_peb_emulate_erase_failure(void)
 #ifdef CONFIG_MTD_PEB_DEBUG
 static int mtd_peb_debug_init(void)
 {
-	globalvar_add_simple_int("mtd_peb.mtd_peb_emulate_bitflip",
+	globalvar_add_simple_uint32("mtd_peb.mtd_peb_emulate_bitflip",
 				 &__mtd_peb_emulate_bitflip, "%u");
-	globalvar_add_simple_int("mtd_peb.mtd_peb_emulate_write_failure",
+	globalvar_add_simple_uint32("mtd_peb.mtd_peb_emulate_write_failure",
 				 &__mtd_peb_emulate_write_failure, "%u");
-	globalvar_add_simple_int("mtd_peb.mtd_peb_emulate_erase_failures",
+	globalvar_add_simple_uint32("mtd_peb.mtd_peb_emulate_erase_failures",
 				 &__mtd_peb_emulate_erase_failures, "%u");
 	globalvar_add_simple_bool("mtd_peb.mtd_peb_chk_io",
 				 &__mtd_peb_chk_io);
diff --git a/include/globalvar.h b/include/globalvar.h
index df43f1fe66..aea43b193d 100644
--- a/include/globalvar.h
+++ b/include/globalvar.h
@@ -15,10 +15,9 @@ void globalvar_remove(const char *name);
 char *globalvar_get_match(const char *match, const char *separator);
 void globalvar_set_match(const char *match, const char *val);
 
-int globalvar_add_simple_string(const char *name, char **value);
-int globalvar_add_simple_int(const char *name, int *value,
-			     const char *format);
-int globalvar_add_simple_bool(const char *name, int *value);
+int __globalvar_add_simple_string(const char *name, char **value);
+int __globalvar_add_simple_int(const char *name, void *value,
+			       enum param_type type, const char *format);
 int globalvar_add_simple_enum(const char *name,	int *value,
 			      const char * const *names, int max);
 int globalvar_add_simple_bitmask(const char *name, unsigned long *value,
@@ -39,19 +38,13 @@ static inline int globalvar_add_simple(const char *name, const char *value)
 	return 0;
 }
 
-static inline int globalvar_add_simple_string(const char *name, char **value)
+static inline int __globalvar_add_simple_int(const char *name, void *value,
+			       enum param_type type, const char *format)
 {
 	return 0;
 }
 
-static inline int globalvar_add_simple_int(const char *name,
-		int *value, const char *format)
-{
-	return 0;
-}
-
-static inline int globalvar_add_simple_bool(const char *name,
-		int *value)
+static inline int __globalvar_add_simple_string(const char *name, char **value)
 {
 	return 0;
 }
@@ -115,6 +108,96 @@ static inline void dev_param_init_from_nv(struct device_d *dev, const char *name
 
 #endif
 
+#define DECLARE_GLOBALVAR_INT(intname, inttype, paramtype) \
+	static inline int globalvar_add_simple_##intname(const char *name,	\
+						      inttype *value,		\
+						      const char *format)	\
+	{									\
+		return __globalvar_add_simple_int(name, value,			\
+						  paramtype,			\
+						  format);			\
+	}
+
+DECLARE_GLOBALVAR_INT(uint32, uint32_t, PARAM_TYPE_UINT32)
+DECLARE_GLOBALVAR_INT(int32, int32_t, PARAM_TYPE_INT32)
+DECLARE_GLOBALVAR_INT(uint64, uint64_t, PARAM_TYPE_UINT64)
+DECLARE_GLOBALVAR_INT(int64, int64_t, PARAM_TYPE_INT64)
+
+static inline int globalvar_add_simple_bool(const char *name, uint32_t *value)
+{
+	return __globalvar_add_simple_int(name, value, PARAM_TYPE_BOOL, "%u");
+}
+
+static inline int globalvar_add_simple_string(const char *name, char **value)
+{
+	return __globalvar_add_simple_string(name, value);
+}
+
+#define DECLARE_GLOBALVAR_INT_RO(intname, inttype, paramtype) \
+	static inline int globalvar_add_simple_##intname##_ro(const char *name,	\
+						      inttype *value,		\
+						      const char *format)	\
+	{									\
+		return PTR_ERR_OR_ZERO(__dev_add_param_int(&global_device, name,\
+							   param_set_readonly,	\
+							   NULL, value,		\
+							   paramtype,		\
+							   format, NULL));	\
+	}
+
+DECLARE_GLOBALVAR_INT_RO(uint32, uint32_t, PARAM_TYPE_UINT32)
+DECLARE_GLOBALVAR_INT_RO(int32, int32_t, PARAM_TYPE_INT32)
+DECLARE_GLOBALVAR_INT_RO(uint64, uint64_t, PARAM_TYPE_UINT64)
+DECLARE_GLOBALVAR_INT_RO(int64, int64_t, PARAM_TYPE_INT64)
+
+static inline int globalvar_add_simple_bool_ro(const char *name, uint32_t *value)
+{
+	return PTR_ERR_OR_ZERO(__dev_add_param_int(&global_device, name,
+						   param_set_readonly, NULL,
+						   value, PARAM_TYPE_BOOL, "%u",
+						   NULL));
+}
+
+static inline int globalvar_add_simple_string_ro(const char *name, char **value)
+{
+	return __globalvar_add_simple_string(name, value);
+}
+
+#define DECLARE_GLOBALVAR_INT_FIXED(intname, inttype, paramtype) \
+	static inline int globalvar_add_simple_##intname##_fixed(const char *name,	\
+								 inttype value,		\
+								 const char *format)	\
+	{										\
+		return PTR_ERR_OR_ZERO(__dev_add_param_int(&global_device, name,	\
+							   ERR_PTR(-EROFS), NULL,	\
+							   &value, paramtype,		\
+							   format, NULL));		\
+	}
+
+DECLARE_GLOBALVAR_INT_FIXED(uint32, uint32_t, PARAM_TYPE_UINT32)
+DECLARE_GLOBALVAR_INT_FIXED(int32, int32_t, PARAM_TYPE_INT32)
+DECLARE_GLOBALVAR_INT_FIXED(uint64, uint64_t, PARAM_TYPE_UINT64)
+DECLARE_GLOBALVAR_INT_FIXED(int64, int64_t, PARAM_TYPE_INT64)
+
+static inline int globalvar_add_simple_bool_fixed(const char *name, uint32_t value)
+{
+	return PTR_ERR_OR_ZERO(__dev_add_param_int(&global_device, name, ERR_PTR(-EROFS),
+						   NULL, &value, PARAM_TYPE_BOOL, "%u",
+						   NULL));
+}
+
+static inline int globalvar_add_simple_string_fixed(const char *name, char *value)
+{
+	return PTR_ERR_OR_ZERO(dev_add_param_string_fixed(&global_device, name, value));
+}
+
+static inline int globalvar_add_simple_enum_ro(const char *name, int *value,
+					       const char * const *names, int max)
+{
+	return PTR_ERR_OR_ZERO(dev_add_param_enum_ro(&global_device, name, value, names,
+						     max));
+}
+
 void nv_var_set_clean(void);
 int nvvar_save(void);
 int nv_global_complete(struct string_list *sl, char *instr);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* [PATCH 10/10] param: remove unnecessary device_d * argument
  2017-04-10  7:14 improve device parameter types Sascha Hauer
                   ` (8 preceding siblings ...)
  2017-04-10  7:14 ` [PATCH 09/10] globalvar: make globalvar " Sascha Hauer
@ 2017-04-10  7:14 ` Sascha Hauer
  9 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-04-10  7:14 UTC (permalink / raw)
  To: Barebox List

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 common/globalvar.c | 14 +++++++-------
 include/param.h    | 11 +++++------
 lib/parameter.c    | 44 ++++++++++++++++++++++----------------------
 3 files changed, 34 insertions(+), 35 deletions(-)

diff --git a/common/globalvar.c b/common/globalvar.c
index 2f65ca805f..d33bc64a13 100644
--- a/common/globalvar.c
+++ b/common/globalvar.c
@@ -163,7 +163,7 @@ static int nvvar_device_dispatch(const char *name, struct device_d **dev,
 	return 1;
 }
 
-static int nv_set(struct device_d *dev, struct param_d *p, const char *val)
+static int nv_set(struct param_d *p, const char *val)
 {
 	struct param_d *g;
 	int ret;
@@ -184,16 +184,16 @@ static int nv_set(struct device_d *dev, struct param_d *p, const char *val)
 	return 0;
 }
 
-static const char *nv_param_get(struct device_d *dev, struct param_d *p)
+static const char *nv_param_get(struct param_d *p)
 {
 	return p->value ? p->value : "";
 }
 
-static int nv_param_set(struct device_d *dev, struct param_d *p, const char *val)
+static int nv_param_set(struct param_d *p, const char *val)
 {
 	int ret;
 
-	ret = nv_set(dev, p, val);
+	ret = nv_set(p, val);
 	if (ret)
 		return ret;
 
@@ -216,7 +216,7 @@ static int __nvvar_add(const char *name, const char *value)
 	}
 
 	if (value)
-		return nv_set(&nv_device, p, value);
+		return nv_set(p, value);
 
 	value = dev_get_param(&global_device, name);
 	if (value) {
@@ -370,7 +370,7 @@ void globalvar_set_match(const char *match, const char *val)
 	}
 }
 
-static int globalvar_simple_set(struct device_d *dev, struct param_d *p, const char *val)
+static int globalvar_simple_set(struct param_d *p, const char *val)
 {
 	struct device_d *rdev;
 	const char *pname = NULL;
@@ -388,7 +388,7 @@ static int globalvar_simple_set(struct device_d *dev, struct param_d *p, const c
 	}
 
 	/* Pass to the generic function we have overwritten */
-	return dev_param_set_generic(dev, p, val);
+	return dev_param_set_generic(p, val);
 }
 
 static void globalvar_nv_sync(const char *name)
diff --git a/include/param.h b/include/param.h
index be4cca7b68..50bca62588 100644
--- a/include/param.h
+++ b/include/param.h
@@ -24,8 +24,8 @@ enum param_type {
 };
 
 struct param_d {
-	const char* (*get)(struct device_d *, struct param_d *param);
-	int (*set)(struct device_d *, struct param_d *param, const char *val);
+	const char* (*get)(struct param_d *param);
+	int (*set)(struct param_d *param, const char *val);
 	void (*info)(struct param_d *param);
 	unsigned int flags;
 	char *name;
@@ -43,8 +43,8 @@ int dev_set_param(struct device_d *dev, const char *name, const char *val);
 struct param_d *get_param_by_name(struct device_d *dev, const char *name);
 
 struct param_d *dev_add_param(struct device_d *dev, const char *name,
-		int (*set)(struct device_d *dev, struct param_d *p, const char *val),
-		const char *(*get)(struct device_d *, struct param_d *p),
+		int (*set)(struct param_d *p, const char *val),
+		const char *(*get)(struct param_d *p),
 		unsigned long flags);
 
 struct param_d *dev_add_param_string(struct device_d *dev, const char *name,
@@ -83,8 +83,7 @@ void dev_remove_param(struct param_d *p);
 
 void dev_remove_parameters(struct device_d *dev);
 
-int dev_param_set_generic(struct device_d *dev, struct param_d *p,
-		const char *val);
+int dev_param_set_generic(struct param_d *p, const char *val);
 
 #else
 static inline const char *dev_get_param(struct device_d *dev, const char *name)
diff --git a/lib/parameter.c b/lib/parameter.c
index a21b8fa4a4..ab36b15591 100644
--- a/lib/parameter.c
+++ b/lib/parameter.c
@@ -76,7 +76,7 @@ const char *dev_get_param(struct device_d *dev, const char *name)
 		return NULL;
 	}
 
-	return param->get(dev, param);
+	return param->get(param);
 }
 
 /**
@@ -107,7 +107,7 @@ int dev_set_param(struct device_d *dev, const char *name, const char *val)
 		return -EACCES;
 	}
 
-	ret = param->set(dev, param, val);
+	ret = param->set(param, val);
 	if (ret)
 		errno = -ret;
 
@@ -125,7 +125,7 @@ int dev_set_param(struct device_d *dev, const char *name, const char *val)
  * used during deregistration of the parameter to free the alloctated
  * memory.
  */
-int dev_param_set_generic(struct device_d *dev, struct param_d *p,
+int dev_param_set_generic(struct param_d *p,
 		const char *val)
 {
 	free(p->value);
@@ -137,7 +137,7 @@ int dev_param_set_generic(struct device_d *dev, struct param_d *p,
 	return p->value ? 0 : -ENOMEM;
 }
 
-static const char *param_get_generic(struct device_d *dev, struct param_d *p)
+static const char *param_get_generic(struct param_d *p)
 {
 	return p->value ? p->value : "";
 }
@@ -151,8 +151,8 @@ static int compare(struct list_head *a, struct list_head *b)
 }
 
 static int __dev_add_param(struct param_d *param, struct device_d *dev, const char *name,
-		int (*set)(struct device_d *dev, struct param_d *p, const char *val),
-		const char *(*get)(struct device_d *dev, struct param_d *p),
+		int (*set)(struct param_d *p, const char *val),
+		const char *(*get)(struct param_d *p),
 		unsigned long flags)
 {
 	if (get_param_by_name(dev, name))
@@ -194,8 +194,8 @@ static int __dev_add_param(struct param_d *param, struct device_d *dev, const ch
  * not use static arrays when using the generic functions.
  */
 struct param_d *dev_add_param(struct device_d *dev, const char *name,
-		int (*set)(struct device_d *dev, struct param_d *p, const char *val),
-		const char *(*get)(struct device_d *dev, struct param_d *param),
+		int (*set)(struct param_d *p, const char *val),
+		const char *(*get)(struct param_d *param),
 		unsigned long flags)
 {
 	struct param_d *param;
@@ -248,7 +248,7 @@ static inline struct param_string *to_param_string(struct param_d *p)
 	return container_of(p, struct param_string, param);
 }
 
-static int param_string_set(struct device_d *dev, struct param_d *p, const char *val)
+static int param_string_set(struct param_d *p, const char *val)
 {
 	struct param_string *ps = to_param_string(p);
 	int ret;
@@ -273,7 +273,7 @@ static int param_string_set(struct device_d *dev, struct param_d *p, const char
 	return ret;
 }
 
-static const char *param_string_get(struct device_d *dev, struct param_d *p)
+static const char *param_string_get(struct param_d *p)
 {
 	struct param_string *ps = to_param_string(p);
 	int ret;
@@ -327,7 +327,7 @@ static inline struct param_int *to_param_int(struct param_d *p)
 	return container_of(p, struct param_int, param);
 }
 
-static int param_int_set(struct device_d *dev, struct param_d *p, const char *val)
+static int param_int_set(struct param_d *p, const char *val)
 {
 	struct param_int *pi = to_param_int(p);
 	u8 value_save[pi->dsize];
@@ -368,7 +368,7 @@ static int param_int_set(struct device_d *dev, struct param_d *p, const char *va
 	return ret;
 }
 
-static const char *param_int_get(struct device_d *dev, struct param_d *p)
+static const char *param_int_get(struct param_d *p)
 {
 	struct param_int *pi = to_param_int(p);
 	int ret;
@@ -487,7 +487,7 @@ static inline struct param_enum *to_param_enum(struct param_d *p)
 	return container_of(p, struct param_enum, param);
 }
 
-static int param_enum_set(struct device_d *dev, struct param_d *p, const char *val)
+static int param_enum_set(struct param_d *p, const char *val)
 {
 	struct param_enum *pe = to_param_enum(p);
 	int value_save = *pe->value;
@@ -515,7 +515,7 @@ static int param_enum_set(struct device_d *dev, struct param_d *p, const char *v
 	return ret;
 }
 
-static const char *param_enum_get(struct device_d *dev, struct param_d *p)
+static const char *param_enum_get(struct param_d *p)
 {
 	struct param_enum *pe = to_param_enum(p);
 	int ret;
@@ -599,7 +599,7 @@ static inline struct param_bitmask *to_param_bitmask(struct param_d *p)
 	return container_of(p, struct param_bitmask, param);
 }
 
-static int param_bitmask_set(struct device_d *dev, struct param_d *p, const char *val)
+static int param_bitmask_set(struct param_d *p, const char *val)
 {
 	struct param_bitmask *pb = to_param_bitmask(p);
 	void *value_save;
@@ -645,7 +645,7 @@ out:
 	return ret;
 }
 
-static const char *param_bitmask_get(struct device_d *dev, struct param_d *p)
+static const char *param_bitmask_get(struct param_d *p)
 {
 	struct param_bitmask *pb = to_param_bitmask(p);
 	int ret, bit;
@@ -734,7 +734,7 @@ static inline struct param_ip *to_param_ip(struct param_d *p)
 	return container_of(p, struct param_ip, param);
 }
 
-static int param_ip_set(struct device_d *dev, struct param_d *p, const char *val)
+static int param_ip_set(struct param_d *p, const char *val)
 {
 	struct param_ip *pi = to_param_ip(p);
 	IPaddr_t ip_save = *pi->ip;
@@ -757,7 +757,7 @@ static int param_ip_set(struct device_d *dev, struct param_d *p, const char *val
 	return ret;
 }
 
-static const char *param_ip_get(struct device_d *dev, struct param_d *p)
+static const char *param_ip_get(struct param_d *p)
 {
 	struct param_ip *pi = to_param_ip(p);
 	int ret;
@@ -816,7 +816,7 @@ static inline struct param_mac *to_param_mac(struct param_d *p)
 	return container_of(p, struct param_mac, param);
 }
 
-static int param_mac_set(struct device_d *dev, struct param_d *p, const char *val)
+static int param_mac_set(struct param_d *p, const char *val)
 {
 	struct param_mac *pm = to_param_mac(p);
 	char mac_save[6];
@@ -845,7 +845,7 @@ out:
 	return ret;
 }
 
-static const char *param_mac_get(struct device_d *dev, struct param_d *p)
+static const char *param_mac_get(struct param_d *p)
 {
 	struct param_mac *pm = to_param_mac(p);
 	int ret;
@@ -894,7 +894,7 @@ struct param_d *dev_add_param_mac(struct device_d *dev, const char *name,
  */
 void dev_remove_param(struct param_d *p)
 {
-	p->set(p->dev, p, NULL);
+	p->set(p, NULL);
 	list_del(&p->list);
 	free(p->name);
 	free(p);
@@ -910,7 +910,7 @@ void dev_remove_parameters(struct device_d *dev)
 	struct param_d *p, *n;
 
 	list_for_each_entry_safe(p, n, &dev->parameters, list) {
-		p->set(dev, p, NULL);
+		p->set(p, NULL);
 		list_del(&p->list);
 		free(p->name);
 		free(p);
-- 
2.11.0


_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 03/10] lib: implement simple_strtoll
  2017-04-10  7:14 ` [PATCH 03/10] lib: implement simple_strtoll Sascha Hauer
@ 2017-04-10 12:44   ` Sam Ravnborg
  2017-04-11  6:42     ` Sascha Hauer
  0 siblings, 1 reply; 13+ messages in thread
From: Sam Ravnborg @ 2017-04-10 12:44 UTC (permalink / raw)
  To: Sascha Hauer; +Cc: Barebox List

Hi Sascha.

Nitpick mode...

> --- a/lib/strtox.c
> +++ b/lib/strtox.c
> @@ -65,3 +65,11 @@ unsigned long long simple_strtoull (const char *cp, char **endp, unsigned int ba
>  	return result;
>  }
>  EXPORT_SYMBOL(simple_strtoull);
> +
> +long long simple_strtoll(const char *cp,char **endp,unsigned int base)
> +{
> +	if(*cp=='-')

It hurts my eyes to see the missing space between if  and "(".

simple_strtol() suffer from the same issue, but in the rest of the file
there is a space between if and "("

And on top I did not see simple_strtoull() used in the patch series.
But then I may have missed it as I just skimmed the patches.
Everything else I saw looked good.

	Sam

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

* Re: [PATCH 03/10] lib: implement simple_strtoll
  2017-04-10 12:44   ` Sam Ravnborg
@ 2017-04-11  6:42     ` Sascha Hauer
  0 siblings, 0 replies; 13+ messages in thread
From: Sascha Hauer @ 2017-04-11  6:42 UTC (permalink / raw)
  To: Sam Ravnborg; +Cc: Barebox List

On Mon, Apr 10, 2017 at 02:44:48PM +0200, Sam Ravnborg wrote:
> Hi Sascha.
> 
> Nitpick mode...
> 
> > --- a/lib/strtox.c
> > +++ b/lib/strtox.c
> > @@ -65,3 +65,11 @@ unsigned long long simple_strtoull (const char *cp, char **endp, unsigned int ba
> >  	return result;
> >  }
> >  EXPORT_SYMBOL(simple_strtoull);
> > +
> > +long long simple_strtoll(const char *cp,char **endp,unsigned int base)
> > +{
> > +	if(*cp=='-')
> 
> It hurts my eyes to see the missing space between if  and "(".

You're right. The whitespace placing throughout the file doesn't help
reading it. I just sent a patch cleaning it up and also fixed the
whitespaces in this patch.

> And on top I did not see simple_strtoull() used in the patch series.
> But then I may have missed it as I just skimmed the patches.

I'm pretty sure it's used ;)

Sascha


-- 
Pengutronix e.K.                           |                             |
Industrial Linux Solutions                 | http://www.pengutronix.de/  |
Peiner Str. 6-8, 31137 Hildesheim, Germany | Phone: +49-5121-206917-0    |
Amtsgericht Hildesheim, HRA 2686           | Fax:   +49-5121-206917-5555 |

_______________________________________________
barebox mailing list
barebox@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/barebox

^ permalink raw reply	[flat|nested] 13+ messages in thread

end of thread, other threads:[~2017-04-11  6:42 UTC | newest]

Thread overview: 13+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2017-04-10  7:14 improve device parameter types Sascha Hauer
2017-04-10  7:14 ` [PATCH 01/10] ARM: socfpga: change param_type struct name Sascha Hauer
2017-04-10  7:14 ` [PATCH 02/10] parameter: Give device parameters types Sascha Hauer
2017-04-10  7:14 ` [PATCH 03/10] lib: implement simple_strtoll Sascha Hauer
2017-04-10 12:44   ` Sam Ravnborg
2017-04-11  6:42     ` Sascha Hauer
2017-04-10  7:14 ` [PATCH 04/10] console: Use dev_add_param_string Sascha Hauer
2017-04-10  7:14 ` [PATCH 05/10] mtd: nand: use dev_add_param_enum Sascha Hauer
2017-04-10  7:14 ` [PATCH 06/10] mtd: use dev_add_param_string Sascha Hauer
2017-04-10  7:14 ` [PATCH 07/10] net: " Sascha Hauer
2017-04-10  7:14 ` [PATCH 08/10] param: make parameter functions more consistent Sascha Hauer
2017-04-10  7:14 ` [PATCH 09/10] globalvar: make globalvar " Sascha Hauer
2017-04-10  7:14 ` [PATCH 10/10] param: remove unnecessary device_d * argument Sascha Hauer

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox