[Xen-devel] [PATCH v4 10/16] firmware: port built-in section to linker table

2016-08-19 Thread mcgrof
From: "Luis R. Rodriguez" 

This ports built-in firmware to use linker tables,
this replaces the custom section solution with a
generic solution.

This also demos the use of the .rodata (SECTION_RO)
linker tables.

Tested with 0 built-in firmware, 1 and 2 built-in
firmwares successfully.

v4:

o work around c6x toolchain bug by using SECTION_TBL_RO

o fix compilation on blackfin

v3:
o explicitly include tables.h as we no longer include
  tables.h from sections.h

o use new section_tbl_asmtype() helper on firmware/Makefile
  to enable having to unfold things on our own.

v2: introduced this file in this version of the series

Cc: Barry Song 
Cc: Mike Frysinger 
Cc: Steven Miao 
Cc: Michael Matz 
Cc: Guenter Roeck 
Cc: Fengguang Wu 
Signed-off-by: Luis R. Rodriguez 
---
 arch/x86/kernel/cpu/microcode/core.c |  8 
 drivers/base/firmware_class.c| 12 ++--
 firmware/Makefile|  3 ++-
 include/asm-generic/vmlinux.lds.h|  7 ---
 4 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/core.c 
b/arch/x86/kernel/cpu/microcode/core.c
index df04b2d033f6..3e7c08d99601 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -91,15 +92,14 @@ static bool __init check_loader_disabled_bsp(void)
return *res;
 }
 
-extern struct builtin_fw __start_builtin_fw[];
-extern struct builtin_fw __end_builtin_fw[];
+DECLARE_LINKTABLE_RO(struct builtin_fw, builtin_fw);
 
 bool get_builtin_firmware(struct cpio_data *cd, const char *name)
 {
 #ifdef CONFIG_FW_LOADER
-   struct builtin_fw *b_fw;
+   const struct builtin_fw *b_fw;
 
-   for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) {
+   LINKTABLE_FOR_EACH(b_fw, builtin_fw) {
if (!strcmp(name, b_fw->name)) {
cd->size = b_fw->size;
cd->data = b_fw->data;
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 22d1760a4278..8fbf03c3e4c2 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -43,15 +44,14 @@ MODULE_LICENSE("GPL");
 
 #ifdef CONFIG_FW_LOADER
 
-extern struct builtin_fw __start_builtin_fw[];
-extern struct builtin_fw __end_builtin_fw[];
+DEFINE_LINKTABLE_RO(struct builtin_fw, builtin_fw);
 
 static bool fw_get_builtin_firmware(struct firmware *fw, const char *name,
void *buf, size_t size)
 {
-   struct builtin_fw *b_fw;
+   const struct builtin_fw *b_fw;
 
-   for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) {
+   LINKTABLE_FOR_EACH(b_fw, builtin_fw) {
if (strcmp(name, b_fw->name) == 0) {
fw->size = b_fw->size;
fw->data = b_fw->data;
@@ -67,9 +67,9 @@ static bool fw_get_builtin_firmware(struct firmware *fw, 
const char *name,
 
 static bool fw_is_builtin_firmware(const struct firmware *fw)
 {
-   struct builtin_fw *b_fw;
+   const struct builtin_fw *b_fw;
 
-   for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++)
+   LINKTABLE_FOR_EACH(b_fw, builtin_fw)
if (fw->data == b_fw->data)
return true;
 
diff --git a/firmware/Makefile b/firmware/Makefile
index fa3e81c2a97b..9e701bf4ced2 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -155,6 +155,7 @@ quiet_cmd_fwbin = MK_FW   $@
  ASM_ALIGN=$(if $(CONFIG_64BIT),3,2);   \
  PROGBITS=$(if $(CONFIG_ARM),%,@)progbits;  \
  echo "/* Generated by firmware/Makefile */"   > $@;\
+ echo "\#include "   >>$@;\
  echo ".section .rodata"   >>$@;\
  echo ".p2align $${ASM_ALIGN}" >>$@;\
  echo "_fw_$${FWSTR}_bin:" >>$@;\
@@ -164,7 +165,7 @@ quiet_cmd_fwbin = MK_FW   $@
  echo ".p2align $${ASM_ALIGN}" >>$@;\
  echo "_fw_$${FWSTR}_name:">>$@;\
  echo ".string \"$$FWNAME\""   >>$@;\
- echo ".section .builtin_fw,\"a\",$${PROGBITS}">>$@;\
+ echo "set_section_tbl_type(SECTION_TBL_RO, builtin_fw, 
SECTION_ORDER_ANY, a,$${PROGBITS})" >>$@;\
  echo ".p2align $${ASM_ALIGN}" >>$@;\
  echo "$${ASM_WORD} _fw_$${FWSTR}_name">>$@;\
  echo "$${ASM_WORD} 

[Xen-devel] [PATCH v4 10/16] firmware: port built-in section to linker table

2016-08-19 Thread mcgrof
From: "Luis R. Rodriguez" 

This ports built-in firmware to use linker tables,
this replaces the custom section solution with a
generic solution.

This also demos the use of the .rodata (SECTION_RO)
linker tables.

Tested with 0 built-in firmware, 1 and 2 built-in
firmwares successfully.

v4:

o work around c6x toolchain bug by using SECTION_TBL_RO

o fix compilation on blackfin

v3:
o explicitly include tables.h as we no longer include
  tables.h from sections.h

o use new section_tbl_asmtype() helper on firmware/Makefile
  to enable having to unfold things on our own.

v2: introduced this file in this version of the series

Cc: Barry Song 
Cc: Mike Frysinger 
Cc: Steven Miao 
Cc: Michael Matz 
Cc: Guenter Roeck 
Cc: Fengguang Wu 
Signed-off-by: Luis R. Rodriguez 
---
 arch/x86/kernel/cpu/microcode/core.c |  8 
 drivers/base/firmware_class.c| 12 ++--
 firmware/Makefile|  3 ++-
 include/asm-generic/vmlinux.lds.h|  7 ---
 4 files changed, 12 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/core.c 
b/arch/x86/kernel/cpu/microcode/core.c
index df04b2d033f6..3e7c08d99601 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -31,6 +31,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 #include 
@@ -91,15 +92,14 @@ static bool __init check_loader_disabled_bsp(void)
return *res;
 }
 
-extern struct builtin_fw __start_builtin_fw[];
-extern struct builtin_fw __end_builtin_fw[];
+DECLARE_LINKTABLE_RO(struct builtin_fw, builtin_fw);
 
 bool get_builtin_firmware(struct cpio_data *cd, const char *name)
 {
 #ifdef CONFIG_FW_LOADER
-   struct builtin_fw *b_fw;
+   const struct builtin_fw *b_fw;
 
-   for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) {
+   LINKTABLE_FOR_EACH(b_fw, builtin_fw) {
if (!strcmp(name, b_fw->name)) {
cd->size = b_fw->size;
cd->data = b_fw->data;
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 22d1760a4278..8fbf03c3e4c2 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -30,6 +30,7 @@
 #include 
 #include 
 #include 
+#include 
 
 #include 
 
@@ -43,15 +44,14 @@ MODULE_LICENSE("GPL");
 
 #ifdef CONFIG_FW_LOADER
 
-extern struct builtin_fw __start_builtin_fw[];
-extern struct builtin_fw __end_builtin_fw[];
+DEFINE_LINKTABLE_RO(struct builtin_fw, builtin_fw);
 
 static bool fw_get_builtin_firmware(struct firmware *fw, const char *name,
void *buf, size_t size)
 {
-   struct builtin_fw *b_fw;
+   const struct builtin_fw *b_fw;
 
-   for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) {
+   LINKTABLE_FOR_EACH(b_fw, builtin_fw) {
if (strcmp(name, b_fw->name) == 0) {
fw->size = b_fw->size;
fw->data = b_fw->data;
@@ -67,9 +67,9 @@ static bool fw_get_builtin_firmware(struct firmware *fw, 
const char *name,
 
 static bool fw_is_builtin_firmware(const struct firmware *fw)
 {
-   struct builtin_fw *b_fw;
+   const struct builtin_fw *b_fw;
 
-   for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++)
+   LINKTABLE_FOR_EACH(b_fw, builtin_fw)
if (fw->data == b_fw->data)
return true;
 
diff --git a/firmware/Makefile b/firmware/Makefile
index fa3e81c2a97b..9e701bf4ced2 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -155,6 +155,7 @@ quiet_cmd_fwbin = MK_FW   $@
  ASM_ALIGN=$(if $(CONFIG_64BIT),3,2);   \
  PROGBITS=$(if $(CONFIG_ARM),%,@)progbits;  \
  echo "/* Generated by firmware/Makefile */"   > $@;\
+ echo "\#include "   >>$@;\
  echo ".section .rodata"   >>$@;\
  echo ".p2align $${ASM_ALIGN}" >>$@;\
  echo "_fw_$${FWSTR}_bin:" >>$@;\
@@ -164,7 +165,7 @@ quiet_cmd_fwbin = MK_FW   $@
  echo ".p2align $${ASM_ALIGN}" >>$@;\
  echo "_fw_$${FWSTR}_name:">>$@;\
  echo ".string \"$$FWNAME\""   >>$@;\
- echo ".section .builtin_fw,\"a\",$${PROGBITS}">>$@;\
+ echo "set_section_tbl_type(SECTION_TBL_RO, builtin_fw, 
SECTION_ORDER_ANY, a,$${PROGBITS})" >>$@;\
  echo ".p2align $${ASM_ALIGN}" >>$@;\
  echo "$${ASM_WORD} _fw_$${FWSTR}_name">>$@;\
  echo "$${ASM_WORD}