Skip to contentSkip to conversation

A few little patches

PATCH Superseded Simon Glass 5 participants 16 messages Apr 8, 2020 – Apr 26, 2020

Subsystems (3)

v5 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v5 cover A few little patches

This series collects together a few patches I have been carrying for a while.

The first two pathces are split out of the acpi series since they don't really relate to ACPI.

Changes in v5:
- Drop change to FAT
- Add new tests for copying an empty string
- Use size_t instead of int, require caller to use SIZE_MAX
- Update the algorithm to avoid dealing with -1

Changes in v4:
- Add a new patch with some string tests
- Add a new patch to convert a string to upper case

Simon Glass (6):
test: Add the beginnings of some string tests
lib: Add a function to convert a string to upper case
usb: Update struct usb_device to indicate speed enum
uuid: Use const char * where possible
pci: Add a macro to convert BDF from linux to U-Boot
dm: mmc: Update mmc_get_mmc_dev() to use const *

 drivers/mmc/mmc-uclass.c |   2 +-
 include/mmc.h            |   2 +-
 include/pci.h            |   3 +
 include/test/suites.h    |   1 +
 include/usb.h            |   2 +-
 include/uuid.h           |   8 ++-
 include/vsprintf.h       |  12 ++++
 lib/strto.c              |   8 +++
 lib/uuid.c               |   6 +-
 test/Makefile            |   1 +
 test/cmd_ut.c            |   5 ++
 test/str_ut.c            | 115 +++++++++++++++++++++++++++++++++++++++
 12 files changed, 157 insertions(+), 8 deletions(-)
 create mode 100644 test/str_ut.c
Signature · 1 line
2.26.0.292.g33ef6b2f38-goog
#1 lore raw

PATCH v5 1/6 test: Add the beginnings of some string tests

There are quite a few string functions in U-Boot with no tests. Make a start by adding a test for strtoul().

---

Changes in v5: None
Changes in v4:
- Add a new patch with some string tests

 include/test/suites.h |  1 +
 test/Makefile         |  1 +
 test/cmd_ut.c         |  5 ++++
 test/str_ut.c         | 67 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 74 insertions(+)
 create mode 100644 test/str_ut.c
include/test/suites.h +1 -0
index 0748185eaf7..6d4270fa33b 100644
@@ -32,6 +32,7 @@ int do_ut_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 int do_ut_lib(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 int do_ut_optee(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+int do_ut_str(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 int do_ut_unicode(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
test/Makefile +1 -0
index 2fe41f489c3..917e54a3fcc 100644
@@ -8,6 +8,7 @@ obj-$(CONFIG_UNIT_TEST) += ut.o
 obj-$(CONFIG_SANDBOX) += command_ut.o
 obj-$(CONFIG_SANDBOX) += compression.o
 obj-$(CONFIG_SANDBOX) += print_ut.o
+obj-$(CONFIG_SANDBOX) += str_ut.o
 obj-$(CONFIG_UT_TIME) += time_ut.o
 obj-$(CONFIG_UT_UNICODE) += unicode_ut.o
 obj-$(CONFIG_$(SPL_)LOG) += log/
test/cmd_ut.c +5 -0
index a3a9d49f7ec..b342c35e68e 100644
@@ -71,6 +71,8 @@ static cmd_tbl_t cmd_ut_sub[] = {
 			 "", ""),
 	U_BOOT_CMD_MKENT(bloblist, CONFIG_SYS_MAXARGS, 1, do_ut_bloblist,
 			 "", ""),
+	U_BOOT_CMD_MKENT(str, CONFIG_SYS_MAXARGS, 1, do_ut_str,
+			 "", ""),
 #endif
 };
 
@@ -131,6 +133,9 @@ static char ut_help_text[] =
 #ifdef CONFIG_UT_OVERLAY
 	"ut overlay [test-name]\n"
 #endif
+#ifdef CONFIG_SANDBOX
+	"ut str - Basic test of string functions\n"
+#endif
 #ifdef CONFIG_UT_TIME
 	"ut time - Very basic test of time functions\n"
 #endif
test/str_ut.c new file +67 -0

67 lines not on this page · raw message

Signature · 1 line
2.26.0.292.g33ef6b2f38-goog
#2 lore raw

PATCH v5 1/6 test: Add the beginnings of some string tests

Quoted 34 lines · Simon Glass

There are quite a few string functions in U-Boot with no tests. Make a start by adding a test for strtoul().

---

Changes in v5: None
Changes in v4:
- Add a new patch with some string tests

 include/test/suites.h |  1 +
 test/Makefile         |  1 +
 test/cmd_ut.c         |  5 ++++
 test/str_ut.c         | 67 +++++++++++++++++++++++++++++++++++++++++++
 4 files changed, 74 insertions(+)
 create mode 100644 test/str_ut.c
include/test/suites.h +1 -0
index 0748185eaf7..6d4270fa33b 100644
@@ -32,6 +32,7 @@ int do_ut_env(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 int do_ut_lib(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 int do_ut_optee(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 int do_ut_overlay(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
+int do_ut_str(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[]);
 int do_ut_time(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 int do_ut_unicode(cmd_tbl_t *cmdtp, int flag, int argc, char * const argv[]);
 
test/Makefile +0 -0
index 2fe41f489c3..917e54a3fcc 100644

test/Makefile obj-$(CONFIG_UNIT_TEST) += ut.o · line 11

Quoted 4 lines
test/Makefile +1 -0
@@ -8,6 +8,7 @@ obj-$(CONFIG_UNIT_TEST) += ut.o
 obj-$(CONFIG_SANDBOX) += command_ut.o
 obj-$(CONFIG_SANDBOX) += compression.o
 obj-$(CONFIG_SANDBOX) += print_ut.o
+obj-$(CONFIG_SANDBOX) += str_ut.o

Why should this test suite be restricted to the sandbox?

It runs fine on qemu_arm64_defconfig if enabled.

Best regards

Heinrich

Quoted 100 lines
test/Makefile +0 -0
 obj-$(CONFIG_UT_TIME) += time_ut.o
 obj-$(CONFIG_UT_UNICODE) += unicode_ut.o
 obj-$(CONFIG_$(SPL_)LOG) += log/
test/cmd_ut.c +5 -0
index a3a9d49f7ec..b342c35e68e 100644
@@ -71,6 +71,8 @@ static cmd_tbl_t cmd_ut_sub[] = {
 			 "", ""),
 	U_BOOT_CMD_MKENT(bloblist, CONFIG_SYS_MAXARGS, 1, do_ut_bloblist,
 			 "", ""),
+	U_BOOT_CMD_MKENT(str, CONFIG_SYS_MAXARGS, 1, do_ut_str,
+			 "", ""),
 #endif
 };
 
@@ -131,6 +133,9 @@ static char ut_help_text[] =
 #ifdef CONFIG_UT_OVERLAY
 	"ut overlay [test-name]\n"
 #endif
+#ifdef CONFIG_SANDBOX
+	"ut str - Basic test of string functions\n"
+#endif
 #ifdef CONFIG_UT_TIME
 	"ut time - Very basic test of time functions\n"
 #endif
test/str_ut.c new file +67 -0
new file mode 100644
index 00000000000..fab8de595cb
@@ -0,0 +1,67 @@
+// SPDX-License-Identifier: GPL-2.0+
+/*
+ * Copyright 2020 Google LLC
+ */
+
+#include <common.h>
+#include <vsprintf.h>
+#include <test/suites.h>
+#include <test/test.h>
+#include <test/ut.h>
+
+/* This is large enough for any of the test strings */
+#define TEST_STR_SIZE	200
+
+static const char str1[] = "I'm sorry I'm late.";
+static const char str2[] = "1099abNo, don't bother apologising.";
+static const char str3[] = "0xbI'm sorry you're alive.";
+
+/* Declare a new str test */
+#define STR_TEST(_name, _flags)		UNIT_TEST(_name, _flags, str_test)
+
+static int run_strtoul(struct unit_test_state *uts, const char *str, int base,
+		       ulong expect_val, int expect_endp_offset)
+{
+	char *endp;
+	ulong val;
+
+	val = simple_strtoul(str, &endp, base);
+	ut_asserteq(expect_val, val);
+	ut_asserteq(expect_endp_offset, endp - str);
+
+	return 0;
+}
+
+static int str_simple_strtoul(struct unit_test_state *uts)
+{
+	/* Base 10 and base 16 */
+	ut_assertok(run_strtoul(uts, str2, 10, 1099, 4));
+	ut_assertok(run_strtoul(uts, str2, 16, 0x1099ab, 6));
+
+	/* Invalid string */
+	ut_assertok(run_strtoul(uts, str1, 10, 0, 0));
+
+	/* Base 0 */
+	ut_assertok(run_strtoul(uts, str1, 0, 0, 0));
+	ut_assertok(run_strtoul(uts, str2, 0, 1099, 4));
+	ut_assertok(run_strtoul(uts, str3, 0, 0xb, 3));
+
+	/* Base 2 */
+	ut_assertok(run_strtoul(uts, str1, 2, 0, 0));
+	ut_assertok(run_strtoul(uts, str2, 2, 2, 2));
+
+	/* Check endp being NULL */
+	ut_asserteq(1099, simple_strtoul(str2, NULL, 0));
+
+	return 0;
+}
+STR_TEST(str_simple_strtoul, 0);
+
+int do_ut_str(cmd_tbl_t *cmdtp, int flag, int argc, char *const argv[])
+{
+	struct unit_test *tests = ll_entry_start(struct unit_test,
+						 str_test);
+	const int n_ents = ll_entry_count(struct unit_test, str_test);
+
+	return cmd_ut_category("str", "str_", tests, n_ents, argc, argv);
+}
#3 lore raw

PATCH v5 1/6 test: Add the beginnings of some string tests

In reply to Simon Glass
Quoted 4 lines · Simon Glass

There are quite a few string functions in U-Boot with no tests. Make a start by adding a test for strtoul().

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200426/e15caf1c/attachment.sig>
#4 lore raw

PATCH v5 2/6 lib: Add a function to convert a string to upper case

In reply to Simon Glass

Add a helper function for this operation. Update the strtoul() tests to check upper case as well.

---

Changes in v5:
- Drop change to FAT
- Add new tests for copying an empty string
- Use size_t instead of int, require caller to use SIZE_MAX
- Update the algorithm to avoid dealing with -1

Changes in v4:
- Add a new patch to convert a string to upper case

 include/vsprintf.h | 12 +++++++
 lib/strto.c        |  8 +++++
 test/str_ut.c      | 78 +++++++++++++++++++++++++++++++++++++---------
 3 files changed, 83 insertions(+), 15 deletions(-)
include/vsprintf.h +12 -0
index 56844dd2de8..d9fb68add0c 100644
@@ -222,4 +222,16 @@ bool str2long(const char *p, ulong *num);
  * @hz: Value to convert
  */
 char *strmhz(char *buf, unsigned long hz);
+
+/**
+ * str_to_upper() - Convert a string to upper case
+ *
+ * This simply uses toupper() on each character of the string.
+ *
+ * @in: String to convert (must be large enough to hold the output string)
+ * @out: Buffer to put converted string
+ * @len: Number of bytes available in @out (SIZE_MAX for all)
+ */
+void str_to_upper(const char *in, char *out, size_t len);
+
 #endif
lib/strto.c +8 -0
index 55ff9f7437d..c00bb5895df 100644
@@ -163,3 +163,11 @@ long trailing_strtol(const char *str)
 {
 	return trailing_strtoln(str, NULL);
 }
+
+void str_to_upper(const char *in, char *out, size_t len)
+{
+	for (; len > 0 && *in; len--)
+		*out++ = toupper(*in++);
+	if (len)
+		*out = '\0';
+}
test/str_ut.c +63 -15

99 lines not on this page · raw message

Signature · 1 line
2.26.0.292.g33ef6b2f38-goog
#5 lore raw

PATCH v5 2/6 lib: Add a function to convert a string to upper case

Quoted 5 lines · Simon Glass

Add a helper function for this operation. Update the strtoul() tests to check upper case as well.

Quoted 158 lines

---

Changes in v5:
- Drop change to FAT
- Add new tests for copying an empty string
- Use size_t instead of int, require caller to use SIZE_MAX
- Update the algorithm to avoid dealing with -1

Changes in v4:
- Add a new patch to convert a string to upper case

 include/vsprintf.h | 12 +++++++
 lib/strto.c        |  8 +++++
 test/str_ut.c      | 78 +++++++++++++++++++++++++++++++++++++---------
 3 files changed, 83 insertions(+), 15 deletions(-)
include/vsprintf.h +12 -0
index 56844dd2de8..d9fb68add0c 100644
@@ -222,4 +222,16 @@ bool str2long(const char *p, ulong *num);
  * @hz: Value to convert
  */
 char *strmhz(char *buf, unsigned long hz);
+
+/**
+ * str_to_upper() - Convert a string to upper case
+ *
+ * This simply uses toupper() on each character of the string.
+ *
+ * @in: String to convert (must be large enough to hold the output string)
+ * @out: Buffer to put converted string
+ * @len: Number of bytes available in @out (SIZE_MAX for all)
+ */
+void str_to_upper(const char *in, char *out, size_t len);
+
 #endif
lib/strto.c +8 -0
index 55ff9f7437d..c00bb5895df 100644
@@ -163,3 +163,11 @@ long trailing_strtol(const char *str)
 {
 	return trailing_strtoln(str, NULL);
 }
+
+void str_to_upper(const char *in, char *out, size_t len)
+{
+	for (; len > 0 && *in; len--)
+		*out++ = toupper(*in++);
+	if (len)
+		*out = '\0';
+}
test/str_ut.c +63 -15
index fab8de595cb..7c8015050ad 100644
@@ -19,36 +19,84 @@ static const char str3[] = "0xbI'm sorry you're alive.";
 /* Declare a new str test */
 #define STR_TEST(_name, _flags)		UNIT_TEST(_name, _flags, str_test)
 
+static int str_test_upper(struct unit_test_state *uts)
+{
+	char out[TEST_STR_SIZE];
+
+	/* Make sure it adds a terminator */
+	out[strlen(str1)] = 'a';
+	str_to_upper(str1, out, SIZE_MAX);
+	ut_asserteq_str("I'M SORRY I'M LATE.", out);
+
+	/* In-place operation */
+	strcpy(out, str2);
+	str_to_upper(out, out, SIZE_MAX);
+	ut_asserteq_str("1099ABNO, DON'T BOTHER APOLOGISING.", out);
+
+	/* Limited length */
+	str_to_upper(str1, out, 7);
+	ut_asserteq_str("I'M SORO, DON'T BOTHER APOLOGISING.", out);
+
+	/* In-place with limited length */
+	strcpy(out, str2);
+	str_to_upper(out, out, 7);
+	ut_asserteq_str("1099ABNo, don't bother apologising.", out);
+
+	/* Copy an empty string to a buffer with space*/
+	out[1] = 0x7f;
+	str_to_upper("", out, SIZE_MAX);
+	ut_asserteq('\0', *out);
+	ut_asserteq(0x7f, out[1]);
+
+	/* Copy an empty string to a buffer with no space*/
+	out[0] = 0x7f;
+	str_to_upper("", out, 0);
+	ut_asserteq(0x7f, out[0]);
+
+	return 0;
+}
+STR_TEST(str_test_upper, 0);
+
 static int run_strtoul(struct unit_test_state *uts, const char *str, int base,
-		       ulong expect_val, int expect_endp_offset)
+		       ulong expect_val, int expect_endp_offset, bool upper)
 {
+	char out[TEST_STR_SIZE];
 	char *endp;
 	ulong val;
 
-	val = simple_strtoul(str, &endp, base);
+	strcpy(out, str);
+	if (upper)
+		str_to_upper(out, out, -1);
+
+	val = simple_strtoul(out, &endp, base);
 	ut_asserteq(expect_val, val);
-	ut_asserteq(expect_endp_offset, endp - str);
+	ut_asserteq(expect_endp_offset, endp - out);
 
 	return 0;
 }
 
 static int str_simple_strtoul(struct unit_test_state *uts)
 {
-	/* Base 10 and base 16 */
-	ut_assertok(run_strtoul(uts, str2, 10, 1099, 4));
-	ut_assertok(run_strtoul(uts, str2, 16, 0x1099ab, 6));
+	int upper;
+
+	/* Check that it is case-insentive */
+	for (upper = 0; upper < 2; upper++) {
+		/* Base 10 and base 16 */
+		ut_assertok(run_strtoul(uts, str2, 10, 1099, 4, upper));
+		ut_assertok(run_strtoul(uts, str2, 16, 0x1099ab, 6, upper));
 
-	/* Invalid string */
-	ut_assertok(run_strtoul(uts, str1, 10, 0, 0));
+		/* Invalid string */
+		ut_assertok(run_strtoul(uts, str1, 10, 0, 0, upper));
 
-	/* Base 0 */
-	ut_assertok(run_strtoul(uts, str1, 0, 0, 0));
-	ut_assertok(run_strtoul(uts, str2, 0, 1099, 4));
-	ut_assertok(run_strtoul(uts, str3, 0, 0xb, 3));
+		/* Base 0 */
+		ut_assertok(run_strtoul(uts, str1, 0, 0, 0, upper));
+		ut_assertok(run_strtoul(uts, str2, 0, 1099, 4, upper));
+		ut_assertok(run_strtoul(uts, str3, 0, 0xb, 3, upper));
 
-	/* Base 2 */
-	ut_assertok(run_strtoul(uts, str1, 2, 0, 0));
-	ut_assertok(run_strtoul(uts, str2, 2, 2, 2));
+		/* Base 2 */
+		ut_assertok(run_strtoul(uts, str1, 2, 0, 0, upper));
+		ut_assertok(run_strtoul(uts, str2, 2, 2, 2, upper));
+	}
 
 	/* Check endp being NULL */
 	ut_asserteq(1099, simple_strtoul(str2, NULL, 0));
#6 lore raw

PATCH v5 2/6 lib: Add a function to convert a string to upper case

In reply to Simon Glass
Quoted 6 lines · Simon Glass

Add a helper function for this operation. Update the strtoul() tests to check upper case as well.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200426/911b7f7a/attachment.sig>
#7 lore raw

PATCH v5 3/6 usb: Update struct usb_device to indicate speed enum

In reply to Simon Glass

The speed member actually uses an enum, so add this to the comment.

---

Changes in v5: None
Changes in v4: None

 include/usb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/usb.h +1 -1
index efb67ea33ff..7fa8182ba86 100644
@@ -103,7 +103,7 @@ enum {
  */
 struct usb_device {
 	int	devnum;			/* Device number on USB bus */
-	int	speed;			/* full/low/high */
+	int	speed;			/* enum usb_device_speed */
 	char	mf[32];			/* manufacturer */
 	char	prod[32];		/* product */
 	char	serial[32];		/* serial number */
Signature · 1 line
2.26.0.292.g33ef6b2f38-goog
#8 lore raw

PATCH v5 3/6 usb: Update struct usb_device to indicate speed enum

Quoted 17 lines · Simon Glass

The speed member actually uses an enum, so add this to the comment.

---

Changes in v5: None
Changes in v4: None

 include/usb.h | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
include/usb.h +0 -0
index efb67ea33ff..7fa8182ba86 100644

include/usb.h enum { · line 109

Quoted 8 lines
include/usb.h +1 -1
@@ -103,7 +103,7 @@ enum {
  */
 struct usb_device {
 	int	devnum;			/* Device number on USB bus */
-	int	speed;			/* full/low/high */
+	int	speed;			/* enum usb_device_speed */
 	char	mf[32];			/* manufacturer */
 	char	prod[32];		/* product */
 	char	serial[32];		/* serial number */

Why don't you then use the enum in this structure ?

#9 lore raw

PATCH v5 4/6 uuid: Use const char * where possible

In reply to Simon Glass

Update the arguments of these functions so they can be called from code which uses constant strings.

---

Changes in v5: None
Changes in v4: None

 include/uuid.h | 8 +++++---
 lib/uuid.c     | 6 ++++--
 2 files changed, 9 insertions(+), 5 deletions(-)
include/uuid.h +5 -3
index abcc325eae9..73c5a89ec7c 100644
@@ -35,11 +35,13 @@ struct uuid {
 #define UUID_VARIANT		0x1
 
 int uuid_str_valid(const char *uuid);
-int uuid_str_to_bin(char *uuid_str, unsigned char *uuid_bin, int str_format);
-void uuid_bin_to_str(unsigned char *uuid_bin, char *uuid_str, int str_format);
+int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin,
+		    int str_format);
+void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str,
+		     int str_format);
 #ifdef CONFIG_PARTITION_TYPE_GUID
 int uuid_guid_get_bin(const char *guid_str, unsigned char *guid_bin);
-int uuid_guid_get_str(unsigned char *guid_bin, char *guid_str);
+int uuid_guid_get_str(const unsigned char *guid_bin, char *guid_str);
 #endif
 void gen_rand_uuid(unsigned char *uuid_bin);
 void gen_rand_uuid_str(char *uuid_str, int str_format);
lib/uuid.c +4 -2
index 3d3c7abcaea..03edaf8b6cf 100644
@@ -143,7 +143,8 @@ int uuid_guid_get_str(unsigned char *guid_bin, char *guid_str)
  * @param uuid_bin - pointer to allocated array for big endian output [16B]
  * @str_format     - UUID string format: 0 - UUID; 1 - GUID
  */
-int uuid_str_to_bin(char *uuid_str, unsigned char *uuid_bin, int str_format)
+int uuid_str_to_bin(const char *uuid_str, unsigned char *uuid_bin,
+		    int str_format)
 {
 	uint16_t tmp16;
 	uint32_t tmp32;
@@ -194,7 +195,8 @@ int uuid_str_to_bin(char *uuid_str, unsigned char *uuid_bin, int str_format)
  * @str_format:		bit 0: 0 - UUID; 1 - GUID
  *			bit 1: 0 - lower case; 2 - upper case
  */
-void uuid_bin_to_str(unsigned char *uuid_bin, char *uuid_str, int str_format)
+void uuid_bin_to_str(const unsigned char *uuid_bin, char *uuid_str,
+		     int str_format)
 {
 	const u8 uuid_char_order[UUID_BIN_LEN] = {0, 1, 2, 3, 4, 5, 6, 7, 8,
 						  9, 10, 11, 12, 13, 14, 15};
Signature · 1 line
2.26.0.292.g33ef6b2f38-goog
#10 lore raw

PATCH v5 4/6 uuid: Use const char * where possible

Quoted 4 lines · Simon Glass

Update the arguments of these functions so they can be called from code which uses constant strings.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200426/4e6ea73d/attachment.sig>
#11 lore raw

PATCH v5 5/6 pci: Add a macro to convert BDF from linux to U-Boot

In reply to Simon Glass

U-Boot's BDF format has its bits in the same position as the device tree PCI definition.

Some x86 devices use linux format in their register format and it is useful to be able to convert to U-Boot format. Add a macro for this.

---

Changes in v5: None
Changes in v4: None

 include/pci.h | 3 +++
 1 file changed, 3 insertions(+)
include/pci.h +3 -0
index 174ddd4460d..aff56b24f92 100644
@@ -543,6 +543,9 @@ typedef int pci_dev_t;
 #define PCI_VENDEV(v, d)	(((v) << 16) | (d))
 #define PCI_ANY_ID		(~0)
 
+/* Convert from Linux format to U-Boot format */
+#define PCI_TO_BDF(val)		((val) << 8)
+
 struct pci_device_id {
 	unsigned int vendor, device;	/* Vendor and device ID or PCI_ANY_ID */
 	unsigned int subvendor, subdevice; /* Subsystem ID's or PCI_ANY_ID */
Signature · 1 line
2.26.0.292.g33ef6b2f38-goog
#12 lore raw

PATCH v5 5/6 pci: Add a macro to convert BDF from linux to U-Boot

Quoted 7 lines · Simon Glass

U-Boot's BDF format has its bits in the same position as the device tree PCI definition.

Some x86 devices use linux format in their register format and it is useful to be able to convert to U-Boot format. Add a macro for this.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200426/cec0c231/attachment.sig>
#13 lore raw

PATCH v5 6/6 dm: mmc: Update mmc_get_mmc_dev() to use const *

In reply to Simon Glass

This function does not modify the device to change it to use const *, so that callers with a const udevice * can call it without a cast.

---

Changes in v5: None
Changes in v4: None

 drivers/mmc/mmc-uclass.c | 2 +-
 include/mmc.h            | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/mmc-uclass.c +1 -1
index c75892a72c1..88fc7d79f8e 100644
@@ -223,7 +223,7 @@ int mmc_of_parse(struct udevice *dev, struct mmc_config *cfg)
 	return 0;
 }
 
-struct mmc *mmc_get_mmc_dev(struct udevice *dev)
+struct mmc *mmc_get_mmc_dev(const struct udevice *dev)
 {
 	struct mmc_uclass_priv *upriv;
 
include/mmc.h +1 -1
index e83c22423bf..0f9184b9714 100644
@@ -374,7 +374,7 @@ struct mmc_uclass_priv {
  * @dev:	Device
  * @return associated mmc struct pointer if available, else NULL
  */
-struct mmc *mmc_get_mmc_dev(struct udevice *dev);
+struct mmc *mmc_get_mmc_dev(const struct udevice *dev);
 
 /* End of driver model support */
 
Signature · 1 line
2.26.0.292.g33ef6b2f38-goog
#14 lore raw

PATCH v5 6/6 dm: mmc: Update mmc_get_mmc_dev() to use const *

Quoted 4 lines · Simon Glass

This function does not modify the device to change it to use const *, so that callers with a const udevice * can call it without a cast.

Best Regards,
Jaehoon Chung

Quoted 36 lines

---

Changes in v5: None
Changes in v4: None

 drivers/mmc/mmc-uclass.c | 2 +-
 include/mmc.h            | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
drivers/mmc/mmc-uclass.c +1 -1
index c75892a72c1..88fc7d79f8e 100644
@@ -223,7 +223,7 @@ int mmc_of_parse(struct udevice *dev, struct mmc_config *cfg)
 	return 0;
 }
 
-struct mmc *mmc_get_mmc_dev(struct udevice *dev)
+struct mmc *mmc_get_mmc_dev(const struct udevice *dev)
 {
 	struct mmc_uclass_priv *upriv;
 
include/mmc.h +1 -1
index e83c22423bf..0f9184b9714 100644
@@ -374,7 +374,7 @@ struct mmc_uclass_priv {
  * @dev:	Device
  * @return associated mmc struct pointer if available, else NULL
  */
-struct mmc *mmc_get_mmc_dev(struct udevice *dev);
+struct mmc *mmc_get_mmc_dev(const struct udevice *dev);
 
 /* End of driver model support */
 
#15 lore raw

PATCH v5 6/6 dm: mmc: Update mmc_get_mmc_dev() to use const *

In reply to Simon Glass
Quoted 5 lines · Simon Glass

This function does not modify the device to change it to use const *, so that callers with a const udevice * can call it without a cast.

Applied to u-boot/master, thanks!

Signature · 8 lines
Tom
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 659 bytes
Desc: not available
URL: <https://lists.denx.de/pipermail/u-boot/attachments/20200426/bc468712/attachment.sig>