mail archive of the barebox mailing list
 help / color / mirror / Atom feed
* [PATCH 1/2] vsprintf: Add support for %pa
@ 2016-01-15 14:34 Sascha Hauer
  2016-01-15 14:34 ` [PATCH 2/2] Convert users of PRINTF_CONVERSION_RESOURCE to %pa Sascha Hauer
  0 siblings, 1 reply; 2+ messages in thread
From: Sascha Hauer @ 2016-01-15 14:34 UTC (permalink / raw)
  To: Barebox List

Add support for the %pa format specifier to print phys_addr_t,
dma_addr_t and resource_size_t.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 lib/vsprintf.c | 27 +++++++++++++++++++++++++++
 1 file changed, 27 insertions(+)

diff --git a/lib/vsprintf.c b/lib/vsprintf.c
index 9b8e8cf..00b8863 100644
--- a/lib/vsprintf.c
+++ b/lib/vsprintf.c
@@ -237,6 +237,29 @@ char *uuid_string(char *buf, char *end, const u8 *addr, int field_width,
 	return string(buf, end, uuid, field_width, precision, flags);
 }
 
+static noinline_for_stack
+char *address_val(char *buf, char *end, const void *addr,
+		int field_width, int precision, int flags, const char *fmt)
+{
+	unsigned long long num;
+
+	flags |= SPECIAL | SMALL | ZEROPAD;
+
+	switch (fmt[1]) {
+	case 'd':
+		num = *(const dma_addr_t *)addr;
+		field_width = sizeof(dma_addr_t) * 2 + 2;
+		break;
+	case 'p':
+	default:
+		num = *(const phys_addr_t *)addr;
+		field_width = sizeof(phys_addr_t) * 2 + 2;
+		break;
+	}
+
+	return number(buf, end, num, 16, field_width, precision, flags);
+}
+
 /*
  * Show a '%p' thing.  A kernel extension is that the '%p' is followed
  * by an extra set of alphanumeric characters that are extended format
@@ -256,6 +279,8 @@ char *uuid_string(char *buf, char *end, const u8 *addr, int field_width,
  *             [0][1][2][3]-[4][5]-[6][7]-[8][9]-[10][11][12][13][14][15]
  *           little endian output byte order is:
  *             [3][2][1][0]-[5][4]-[7][6]-[8][9]-[10][11][12][13][14][15]
+ * - 'a[pd]' For address types [p] phys_addr_t, [d] dma_addr_t and derivatives
+ *           (default assumed to be phys_addr_t, passed by reference)
  *
  * Note: The difference between 'S' and 'F' is that on ia64 and ppc64
  * function pointers are really function descriptors, which contain a
@@ -270,6 +295,8 @@ static char *pointer(const char *fmt, char *buf, char *end, void *ptr, int field
 		if (IS_ENABLED(CONFIG_PRINTF_UUID))
 			return uuid_string(buf, end, ptr, field_width, precision, flags, fmt);
 		break;
+	case 'a':
+		return address_val(buf, end, ptr, field_width, precision, flags, fmt);
 	}
 	flags |= SMALL;
 	if (field_width == -1) {
-- 
2.6.4


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

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

* [PATCH 2/2] Convert users of PRINTF_CONVERSION_RESOURCE to %pa
  2016-01-15 14:34 [PATCH 1/2] vsprintf: Add support for %pa Sascha Hauer
@ 2016-01-15 14:34 ` Sascha Hauer
  0 siblings, 0 replies; 2+ messages in thread
From: Sascha Hauer @ 2016-01-15 14:34 UTC (permalink / raw)
  To: Barebox List

printf now supports printing resource_size_t directly, convert
all users of the previously used PRINTF_CONVERSION_RESOURCE over
to %pa.

Signed-off-by: Sascha Hauer <s.hauer@pengutronix.de>
---
 commands/devinfo.c     |  8 +++++---
 commands/iomemport.c   |  6 +++---
 common/bootm.c         | 12 ++++++------
 common/uimage.c        |  7 +++----
 drivers/of/platform.c  |  7 +++++--
 include/linux/ioport.h |  6 ------
 6 files changed, 22 insertions(+), 24 deletions(-)

diff --git a/commands/devinfo.c b/commands/devinfo.c
index c78efcb..9d5e8b8 100644
--- a/commands/devinfo.c
+++ b/commands/devinfo.c
@@ -77,13 +77,15 @@ static int do_devinfo(int argc, char *argv[])
 		if (dev->num_resources)
 			printf("Resources:\n");
 		for (i = 0; i < dev->num_resources; i++) {
+			resource_size_t size;
 			res = &dev->resource[i];
+			size = resource_size(res);
 			printf("  num: %d\n", i);
 			if (res->name)
 				printf("  name: %s\n", res->name);
-			printf("  start: " PRINTF_CONVERSION_RESOURCE "\n"
-				   "  size: "  PRINTF_CONVERSION_RESOURCE "\n",
-			       res->start, resource_size(res));
+			printf("  start: %pa\n"
+				   "  size: %pa\n",
+			       &res->start, &size);
 		}
 
 		if (dev->driver)
diff --git a/commands/iomemport.c b/commands/iomemport.c
index 5294c13..6d97c57 100644
--- a/commands/iomemport.c
+++ b/commands/iomemport.c
@@ -22,14 +22,14 @@
 static void __print_resources(struct resource *res, int indent)
 {
 	struct resource *r;
+	resource_size_t size = resource_size(res);
 	int i;
 
 	for (i = 0; i < indent; i++)
 		printf("  ");
 
-	printf(PRINTF_CONVERSION_RESOURCE " - " PRINTF_CONVERSION_RESOURCE
-			" (size " PRINTF_CONVERSION_RESOURCE ") %s\n",
-			res->start, res->end, resource_size(res), res->name);
+	printf("%pa - %pa (size %pa) %s\n",
+			&res->start, &res->end, &size, res->name);
 
 	list_for_each_entry(r, &res->children, sibling)
 		__print_resources(r, indent + 1);
diff --git a/common/bootm.c b/common/bootm.c
index 08125e7..ec6e899 100644
--- a/common/bootm.c
+++ b/common/bootm.c
@@ -326,9 +326,9 @@ static int bootm_open_oftree(struct image_data *data)
 static void bootm_print_info(struct image_data *data)
 {
 	if (data->os_res)
-		printf("OS image is at " PRINTF_CONVERSION_RESOURCE "-" PRINTF_CONVERSION_RESOURCE "\n",
-				data->os_res->start,
-				data->os_res->end);
+		printf("OS image is at %pa-%pa\n",
+				&data->os_res->start,
+				&data->os_res->end);
 	else
 		printf("OS image not yet relocated\n");
 
@@ -343,9 +343,9 @@ static void bootm_print_info(struct image_data *data)
 			printf(", multifile image %d", data->initrd_num);
 		printf("\n");
 		if (data->initrd_res)
-			printf("initrd is at " PRINTF_CONVERSION_RESOURCE "-" PRINTF_CONVERSION_RESOURCE "\n",
-				data->initrd_res->start,
-				data->initrd_res->end);
+			printf("initrd is at %pa-%pa\n",
+				&data->initrd_res->start,
+				&data->initrd_res->end);
 		else
 			printf("initrd image not yet relocated\n");
 	}
diff --git a/common/uimage.c b/common/uimage.c
index a7011a7..59d7b65 100644
--- a/common/uimage.c
+++ b/common/uimage.c
@@ -354,10 +354,9 @@ static int uimage_sdram_flush(void *buf, unsigned int len)
 		uimage_resource = request_sdram_region("uimage",
 				start, size);
 		if (!uimage_resource) {
-			printf("unable to request SDRAM "
-					PRINTF_CONVERSION_RESOURCE "-"
-					PRINTF_CONVERSION_RESOURCE "\n",
-				start, start + size - 1);
+			resource_size_t prsize = start + size - 1;
+			printf("unable to request SDRAM %pa - %pa\n",
+				&start, &prsize);
 			return -ENOMEM;
 		}
 	}
diff --git a/drivers/of/platform.c b/drivers/of/platform.c
index 2c075db..3f848a4 100644
--- a/drivers/of/platform.c
+++ b/drivers/of/platform.c
@@ -123,6 +123,7 @@ struct device_d *of_platform_device_create(struct device_node *np,
 {
 	struct device_d *dev;
 	struct resource *res = NULL, temp_res;
+	resource_size_t resinval;
 	int i, j, ret, num_reg = 0, match;
 
 	if (!of_device_is_available(np))
@@ -183,9 +184,11 @@ struct device_d *of_platform_device_create(struct device_node *np,
 	dev->num_resources = num_reg;
 	of_device_make_bus_id(dev);
 
-	debug("%s: register device %s, io=" PRINTF_CONVERSION_RESOURCE "\n",
+	resinval = (-1);
+
+	debug("%s: register device %s, io=%pa\n",
 			__func__, dev_name(dev),
-		(num_reg) ? dev->resource[0].start : (-1));
+		(num_reg) ? &dev->resource[0].start : &resinval);
 
 	ret = platform_device_register(dev);
 	if (!ret)
diff --git a/include/linux/ioport.h b/include/linux/ioport.h
index 9b35a30..3d375a8 100644
--- a/include/linux/ioport.h
+++ b/include/linux/ioport.h
@@ -26,12 +26,6 @@ struct resource {
 	struct list_head sibling;
 };
 
-#ifdef CONFIG_PHYS_ADDR_T_64BIT
-#define PRINTF_CONVERSION_RESOURCE	"0x%016llx"
-#else
-#define PRINTF_CONVERSION_RESOURCE	"0x%08x"
-#endif
-
 /*
  * IO resources have these defined flags.
  */
-- 
2.6.4


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

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

end of thread, other threads:[~2016-01-15 14:34 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-15 14:34 [PATCH 1/2] vsprintf: Add support for %pa Sascha Hauer
2016-01-15 14:34 ` [PATCH 2/2] Convert users of PRINTF_CONVERSION_RESOURCE to %pa Sascha Hauer

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