Skip to contentSkip to conversation

Stratix10 FPGA reconfiguration support

PATCH Superseded chee.hong.ang at intel.com 3 participants 18 messages Oct 8, 2018 – Nov 15, 2018

Subsystems (4)

v2 of 8 Superseded Latest is v8 →

lore
Share & tools
lore
#0 lore raw

v2 cover Stratix10 FPGA reconfiguration support

From: "Ang, Chee Hong" <[email protected]>

Summary of v2 changes:
- Addressed review comments in drivers/fpga/stratix10.c
- Update SPDX tag in drivers/fpga/stratix10.c
- Add parentheses in macro functions
- Define default empty socfpga_fpga_add()

v1 patchsets:
https://lists.denx.de/pipermail/u-boot/2018-October/343256.html

Ang, Chee Hong (4):
arm: socfpga: stratix10: Add macros for mailbox's arguments
arm: socfpga: stratix10: Add Stratix 10 FPGA Reconfiguration Driver
arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table
arm: socfpga: stratix10: Enable Stratix10 FPGA Reconfiguration

 arch/arm/mach-socfpga/include/mach/mailbox_s10.h |   6 +
 arch/arm/mach-socfpga/misc.c                     |  29 +++
 arch/arm/mach-socfpga/misc_s10.c                 |   2 +
 configs/socfpga_stratix10_defconfig              |   1 +
 drivers/fpga/Kconfig                             |  11 +
 drivers/fpga/Makefile                            |   1 +
 drivers/fpga/altera.c                            |   6 +
 drivers/fpga/stratix10.c                         | 288 +++++++++++++++++++++++
 include/altera.h                                 |   8 +
 9 files changed, 352 insertions(+)
 create mode 100644 drivers/fpga/stratix10.c
Signature · 1 line
2.7.4
#1 lore raw

PATCH v2 1/4 arm: socfpga: stratix10: Add macros for mailbox's arguments

From: "Ang, Chee Hong" <[email protected]>

Add macros for specifying number of arguments in mailbox command.

---
 arch/arm/mach-socfpga/include/mach/mailbox_s10.h | 6 ++++++
 1 file changed, 6 insertions(+)
arch/arm/mach-socfpga/include/mach/mailbox_s10.h +6 -0
index 660df35..ae728a5 100644
@@ -107,6 +107,12 @@ enum ALT_SDM_MBOX_RESP_CODE {
 #define RECONFIG_STATUS_PIN_STATUS			2
 #define RECONFIG_STATUS_SOFTFUNC_STATUS			3
 
+/* Macros for specifying number of arguments in mailbox command */
+#define MBOX_NUM_ARGS(n, b)				(((n) & 0xFF) << (b))
+#define MBOX_DIRECT_COUNT(n)				MBOX_NUM_ARGS((n), 0)
+#define MBOX_ARG_DESC_COUNT(n)				MBOX_NUM_ARGS((n), 8)
+#define MBOX_RESP_DESC_COUNT(n)				MBOX_NUM_ARGS((n), 16)
+
 #define MBOX_CFGSTAT_STATE_IDLE				0x00000000
 #define MBOX_CFGSTAT_STATE_CONFIG			0x10000000
 #define MBOX_CFGSTAT_STATE_FAILACK			0x08000000
Signature · 1 line
2.7.4
#2 lore raw

PATCH v2 2/4 arm: socfpga: stratix10: Add Stratix 10 FPGA Reconfiguration Driver

In reply to chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

Enable FPGA reconfiguration support for Stratix 10 SoC.

---
 drivers/fpga/Kconfig     |  11 ++
 drivers/fpga/Makefile    |   1 +
 drivers/fpga/stratix10.c | 288 +++++++++++++++++++++++++++++++++++++++++++++++
 include/altera.h         |   4 +
 4 files changed, 304 insertions(+)
 create mode 100644 drivers/fpga/stratix10.c
drivers/fpga/Kconfig +11 -0
index 50e9019..8f59193 100644
@@ -31,6 +31,17 @@ config FPGA_CYCLON2
 	  Enable FPGA driver for loading bitstream in BIT and BIN format
 	  on Altera Cyclone II device.
 
+config FPGA_STRATIX10
+	bool "Enable Altera FPGA driver for Stratix 10"
+	depends on TARGET_SOCFPGA_STRATIX10
+	select FPGA_ALTERA
+	help
+	  Say Y here to enable the Altera Stratix 10 FPGA specific driver
+
+	  This provides common functionality for Altera Stratix 10 devices.
+	  Enable FPGA driver for writing bitstream into Altera Stratix10
+	  device.
+
 config FPGA_XILINX
 	bool "Enable Xilinx FPGA drivers"
 	select FPGA
drivers/fpga/Makefile +1 -0
index 97d7d5d..5a778c1 100644
@@ -17,6 +17,7 @@ obj-$(CONFIG_FPGA_ACEX1K) += ACEX1K.o
 obj-$(CONFIG_FPGA_CYCLON2) += cyclon2.o
 obj-$(CONFIG_FPGA_STRATIX_II) += stratixII.o
 obj-$(CONFIG_FPGA_STRATIX_V) += stratixv.o
+obj-$(CONFIG_FPGA_STRATIX10) += stratix10.o
 obj-$(CONFIG_FPGA_SOCFPGA) += socfpga.o
 obj-$(CONFIG_TARGET_SOCFPGA_GEN5) += socfpga_gen5.o
 obj-$(CONFIG_TARGET_SOCFPGA_ARRIA10) += socfpga_arria10.o
drivers/fpga/stratix10.c new file +288 -0

288 lines not on this page · raw message

include/altera.h +4 -0
index ead5d3d..233b467 100644
@@ -116,4 +116,8 @@ int socfpga_load(Altera_desc *desc, const void *rbf_data, size_t rbf_size);
 int stratixv_load(Altera_desc *desc, const void *rbf_data, size_t rbf_size);
 #endif
 
+#ifdef CONFIG_FPGA_STRATIX10
+int stratix10_load(Altera_desc *desc, const void *rbf_data, size_t rbf_size);
+#endif
+
 #endif /* _ALTERA_H_ */
Signature · 1 line
2.7.4
#3 lore raw

PATCH v2 3/4 arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table

In reply to chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

Enable 'fpga' command in u-boot. User will be able to use the fpga command to program the FPGA on Stratix10 SoC.

---
 arch/arm/mach-socfpga/misc.c     | 29 +++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/misc_s10.c |  2 ++
 drivers/fpga/altera.c            |  6 ++++++
 include/altera.h                 |  4 ++++
 4 files changed, 41 insertions(+)
arch/arm/mach-socfpga/misc.c +29 -0
index a4f6d5c..7986b58 100644
@@ -88,6 +88,27 @@ int overwrite_console(void)
 #endif
 
 #ifdef CONFIG_FPGA
+#ifdef CONFIG_FPGA_STRATIX10
+/*
+ * FPGA programming support for SoC FPGA Stratix 10
+ */
+static Altera_desc altera_fpga[] = {
+	{
+		/* Family */
+		Intel_FPGA_Stratix10,
+		/* Interface type */
+		secure_device_manager_mailbox,
+		/* No limitation as additional data will be ignored */
+		-1,
+		/* No device function table */
+		NULL,
+		/* Base interface address specified in driver */
+		NULL,
+		/* No cookie implementation */
+		0
+	},
+};
+#else
 /*
  * FPGA programming support for SoC FPGA Cyclone V
  */
@@ -107,6 +128,7 @@ static Altera_desc altera_fpga[] = {
 		0
 	},
 };
+#endif
 
 /* add device descriptor to FPGA device table */
 void socfpga_fpga_add(void)
@@ -116,6 +138,13 @@ void socfpga_fpga_add(void)
 	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
 		fpga_add(fpga_altera, &altera_fpga[i]);
 }
+
+#else
+
+__weak void socfpga_fpga_add(void)
+{
+}
+
 #endif
 
 int arch_cpu_init(void)
arch/arm/mach-socfpga/misc_s10.c +2 -0
index 918baac..f23c0dc 100644
@@ -124,6 +124,8 @@ int arch_misc_init(void)
 
 int arch_early_init_r(void)
 {
+	socfpga_fpga_add();
+
 	return 0;
 }
 
drivers/fpga/altera.c +6 -0
index 9605554..7c8f518 100644
@@ -39,6 +39,9 @@ static const struct altera_fpga {
 #if defined(CONFIG_FPGA_STRATIX_V)
 	{ Altera_StratixV, "StratixV", stratixv_load, NULL, NULL },
 #endif
+#if defined(CONFIG_FPGA_STRATIX10)
+	{ Intel_FPGA_Stratix10, "Stratix10", stratix10_load, NULL, NULL },
+#endif
 #if defined(CONFIG_FPGA_SOCFPGA)
 	{ Altera_SoCFPGA, "SoC FPGA", socfpga_load, NULL, NULL },
 #endif
@@ -154,6 +157,9 @@ int altera_info(Altera_desc *desc)
 	case fast_passive_parallel_security:
 		printf("Fast Passive Parallel with Security (FPPS)\n");
 		break;
+	case secure_device_manager_mailbox:
+		puts("Secure Device Manager (SDM) Mailbox\n");
+		break;
 		/* Add new interface types here */
 	default:
 		printf("Unsupported interface type, %d\n", desc->iface);
include/altera.h +4 -0
index 233b467..22d55cf 100644
@@ -39,6 +39,8 @@ enum altera_iface {
 	fast_passive_parallel,
 	/* fast passive parallel with security (FPPS) */
 	fast_passive_parallel_security,
+	/* secure device manager (SDM) mailbox */
+	secure_device_manager_mailbox,
 	/* insert all new types before this */
 	max_altera_iface_type,
 };
@@ -54,6 +56,8 @@ enum altera_family {
 	Altera_StratixII,
 	/* StratixV Family */
 	Altera_StratixV,
+	/* Stratix10 Family */
+	Intel_FPGA_Stratix10,
 	/* SoCFPGA Family */
 	Altera_SoCFPGA,
 
Signature · 1 line
2.7.4
#4 lore raw

PATCH v2 3/4 arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table

Quoted 54 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

Enable 'fpga' command in u-boot. User will be able to use the fpga command to program the FPGA on Stratix10 SoC.

---
 arch/arm/mach-socfpga/misc.c     | 29 +++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/misc_s10.c |  2 ++
 drivers/fpga/altera.c            |  6 ++++++
 include/altera.h                 |  4 ++++
 4 files changed, 41 insertions(+)
arch/arm/mach-socfpga/misc.c +22 -0
index a4f6d5c..7986b58 100644
@@ -88,6 +88,27 @@ int overwrite_console(void)
 #endif
 
 #ifdef CONFIG_FPGA
+#ifdef CONFIG_FPGA_STRATIX10
+/*
+ * FPGA programming support for SoC FPGA Stratix 10
+ */
+static Altera_desc altera_fpga[] = {
+	{
+		/* Family */
+		Intel_FPGA_Stratix10,
+		/* Interface type */
+		secure_device_manager_mailbox,
+		/* No limitation as additional data will be ignored */
+		-1,
+		/* No device function table */
+		NULL,
+		/* Base interface address specified in driver */
+		NULL,
+		/* No cookie implementation */
+		0
+	},
+};
+#else
 /*
  * FPGA programming support for SoC FPGA Cyclone V
  */
@@ -107,6 +128,7 @@ static Altera_desc altera_fpga[] = {
 		0
 	},
 };
+#endif
 
 /* add device descriptor to FPGA device table */
 void socfpga_fpga_add(void)

arch/arm/mach-socfpga/misc.c void socfpga_fpga_add(void) · line 146

Quoted 9 lines
arch/arm/mach-socfpga/misc.c +6 -0
@@ -116,6 +138,13 @@ void socfpga_fpga_add(void)
 	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
 		fpga_add(fpga_altera, &altera_fpga[i]);
 }
+
+#else
+
+__weak void socfpga_fpga_add(void)
+{
+}

Why is a __weak function defined only in else-statement ?

It should be defined always, with a sane default implementation.

Signature · 2 lines
Best regards,
Marek Vasut
#5 lore raw

PATCH v2 3/4 arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table

Quoted 70 lines · Marek Vasut
Quoted 58 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

Enable 'fpga' command in u-boot. User will be able to use the fpga command to program the FPGA on Stratix10 SoC.

---
 arch/arm/mach-socfpga/misc.c     | 29
+++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/misc_s10.c |  2 ++
 drivers/fpga/altera.c            |  6 ++++++
 include/altera.h                 |  4 ++++

 4 files changed, 41 insertions(+)
arch/arm/mach- renamed from arch/arm/mach-socfpga/misc.c +0 -0

socfpga/misc.c
index a4f6d5c..7986b58 100644

arch/arm/mach-socfpga/misc.c +0 -0
@@ -88,6 +88,27 @@ int overwrite_console(void)
  #endif


 #ifdef CONFIG_FPGA

arch/arm/mach-socfpga/misc.c +11 -0
+#ifdef CONFIG_FPGA_STRATIX10
+/*
+ * FPGA programming support for SoC FPGA Stratix 10
+ */
+static Altera_desc altera_fpga[] = {
+	{
+		/* Family */
+		Intel_FPGA_Stratix10,
+		/* Interface type */
+		secure_device_manager_mailbox,
+		/* No limitation as additional data will be

ignored */

arch/arm/mach-socfpga/misc.c +10 -0
+		-1,
+		/* No device function table */
+		NULL,
+		/* Base interface address specified in driver */
+		NULL,
+		/* No cookie implementation */
+		0
+	},
+};
+#else

 /*
  * FPGA programming support for SoC FPGA Cyclone V */

arch/arm/mach-socfpga/misc.c +0 -0
@@ -107,6 +128,7 @@ static Altera_desc altera_fpga[] = {

  0
  },
 };
+#endif

 /* add device descriptor to FPGA device table */
 void socfpga_fpga_add(void)

arch/arm/mach-socfpga/misc.c void socfpga_fpga_add(void) · line 146

Quoted 9 lines
arch/arm/mach-socfpga/misc.c +6 -0
@@ -116,6 +138,13 @@ void socfpga_fpga_add(void)
  	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
  		fpga_add(fpga_altera, &altera_fpga[i]);
  }
+
+#else
+
+__weak void socfpga_fpga_add(void)
+{
+}

Why is a __weak function defined only in else-statement ?

Quoted 1 line

It should be defined always, with a sane default implementation.

I will remove the empty function in #else-statement and define the default function like this :

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)
{

#ifdef CONFIG_FPGA
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);

#endif
}

Is that OK?

#6 lore raw

PATCH v2 3/4 arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table

Quoted 84 lines · Chee Hong
Quoted 70 lines · Marek Vasut
Quoted 58 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

Enable 'fpga' command in u-boot. User will be able to use the fpga command to program the FPGA on Stratix10 SoC.

---
 arch/arm/mach-socfpga/misc.c     | 29
+++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/misc_s10.c |  2 ++
 drivers/fpga/altera.c            |  6 ++++++
 include/altera.h                 |  4 ++++

 4 files changed, 41 insertions(+)
arch/arm/mach- renamed from arch/arm/mach-socfpga/misc.c +0 -0

socfpga/misc.c
index a4f6d5c..7986b58 100644

arch/arm/mach-socfpga/misc.c +0 -0
@@ -88,6 +88,27 @@ int overwrite_console(void)
  #endif


 #ifdef CONFIG_FPGA

arch/arm/mach-socfpga/misc.c +11 -0
+#ifdef CONFIG_FPGA_STRATIX10
+/*
+ * FPGA programming support for SoC FPGA Stratix 10
+ */
+static Altera_desc altera_fpga[] = {
+	{
+		/* Family */
+		Intel_FPGA_Stratix10,
+		/* Interface type */
+		secure_device_manager_mailbox,
+		/* No limitation as additional data will be

ignored */

arch/arm/mach-socfpga/misc.c +10 -0
+		-1,
+		/* No device function table */
+		NULL,
+		/* Base interface address specified in driver */
+		NULL,
+		/* No cookie implementation */
+		0
+	},
+};
+#else

 /*
  * FPGA programming support for SoC FPGA Cyclone V */

arch/arm/mach-socfpga/misc.c +0 -0
@@ -107,6 +128,7 @@ static Altera_desc altera_fpga[] = {

  0
  },
 };
+#endif

 /* add device descriptor to FPGA device table */
 void socfpga_fpga_add(void)

arch/arm/mach-socfpga/misc.c void socfpga_fpga_add(void) · line 146

Quoted 9 lines
arch/arm/mach-socfpga/misc.c +6 -0
@@ -116,6 +138,13 @@ void socfpga_fpga_add(void)
  	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
  		fpga_add(fpga_altera, &altera_fpga[i]);
  }
+
+#else
+
+__weak void socfpga_fpga_add(void)
+{
+}

Why is a __weak function defined only in else-statement ?

Quoted 1 line

It should be defined always, with a sane default implementation.

I will remove the empty function in #else-statement and define the default function like this :

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)
{

#ifdef CONFIG_FPGA
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);
Quoted 4 lines

#endif
}

Is that OK?

Can't you have __weak empty implementation of socfpga_fpga_add() and implement a version per platform ? Would that work and make sense ?

btw. the best solution would be to fix this proper and implement a DM/DT based probing of the FPGA, including a proper driver(s) in drivers/fpga/ instead of putting all the crud into arch/arm/mach-socfpga ...

Signature · 2 lines
Best regards,
Marek Vasut
#7 lore raw

PATCH v2 3/4 arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table

Quoted 92 lines · Marek Vasut
Quoted 91 lines · Chee Hong
Quoted 74 lines · Marek Vasut
Quoted 61 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

Enable 'fpga' command in u-boot. User will be able to use the fpga
command to program the FPGA on Stratix10 SoC.

---
 arch/arm/mach-socfpga/misc.c     | 29
+++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/misc_s10.c |  2 ++
 drivers/fpga/altera.c            |  6 ++++++
 include/altera.h                 |  4 ++++

 4 files changed, 41 insertions(+)
arch/arm/mach- renamed from arch/arm/mach-socfpga/misc.c +0 -0

socfpga/misc.c
index a4f6d5c..7986b58 100644

arch/arm/mach-socfpga/misc.c +0 -0
@@ -88,6 +88,27 @@ int overwrite_console(void)
  #endif


 #ifdef CONFIG_FPGA

arch/arm/mach-socfpga/misc.c +11 -0
+#ifdef CONFIG_FPGA_STRATIX10
+/*
+ * FPGA programming support for SoC FPGA Stratix 10
+ */
+static Altera_desc altera_fpga[] = {
+	{
+		/* Family */
+		Intel_FPGA_Stratix10,
+		/* Interface type */
+		secure_device_manager_mailbox,
+		/* No limitation as additional data will be

ignored */

arch/arm/mach-socfpga/misc.c +4 -0
+		-1,
+		/* No device function table */
+		NULL,
+		/* Base interface address specified in driver

*/

arch/arm/mach-socfpga/misc.c +6 -0
+		NULL,
+		/* No cookie implementation */
+		0
+	},
+};
+#else

 /*
  * FPGA programming support for SoC FPGA Cyclone V */

arch/arm/mach-socfpga/misc.c +0 -0
@@ -107,6 +128,7 @@ static Altera_desc altera_fpga[] = {

  0
  },
 };
+#endif

 /* add device descriptor to FPGA device table */
 void socfpga_fpga_add(void)

arch/arm/mach-socfpga/misc.c void socfpga_fpga_add(void) · line 146

Quoted 9 lines
arch/arm/mach-socfpga/misc.c +6 -0
@@ -116,6 +138,13 @@ void socfpga_fpga_add(void)
  	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
  		fpga_add(fpga_altera, &altera_fpga[i]);
  }
+
+#else
+
+__weak void socfpga_fpga_add(void)
+{
+}

Why is a __weak function defined only in else-statement ?

Quoted 1 line

It should be defined always, with a sane default implementation.

I will remove the empty function in #else-statement and define the default function like this :

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)
{

#ifdef CONFIG_FPGA
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);

#endif
}

Quoted 3 lines
Quoted 1 line

Is that OK?

Can't you have __weak empty implementation of socfpga_fpga_add() and implement a version per platform ? Would that work and make sense ?

socfpga_fpga_add() as shown above is a generic function for adding FPGA devices to FPGA driver which applies to all our platforms. This is the reason why it is defined in misc.c instead of misc_<platform_name>.c.

It turned out we already have this defined in misc.h:
#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {} #endif

So I don't think I need to make any changes to socfpga_fpga_add() in misc.c. I just have to remove ifdef CONFIG_FPGA in misc_s10.c because it was unnecessary. I will submit v3 for this patch and you can comment further. The v3 patch will be simpler. Thanks.

Quoted 7 lines

btw. the best solution would be to fix this proper and implement a DM/DT
based probing of the FPGA, including a proper driver(s) in drivers/fpga/
instead of putting all the crud into arch/arm/mach-socfpga ...

#8 lore raw

PATCH v2 3/4 arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table

Quoted 100 lines · Chee Hong
Quoted 92 lines · Marek Vasut
Quoted 91 lines · Chee Hong
Quoted 74 lines · Marek Vasut
Quoted 61 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

Enable 'fpga' command in u-boot. User will be able to use the fpga
command to program the FPGA on Stratix10 SoC.

---
 arch/arm/mach-socfpga/misc.c     | 29
+++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/misc_s10.c |  2 ++
 drivers/fpga/altera.c            |  6 ++++++
 include/altera.h                 |  4 ++++

 4 files changed, 41 insertions(+)
arch/arm/mach- renamed from arch/arm/mach-socfpga/misc.c +0 -0

socfpga/misc.c
index a4f6d5c..7986b58 100644

arch/arm/mach-socfpga/misc.c +0 -0
@@ -88,6 +88,27 @@ int overwrite_console(void)
  #endif


 #ifdef CONFIG_FPGA

arch/arm/mach-socfpga/misc.c +11 -0
+#ifdef CONFIG_FPGA_STRATIX10
+/*
+ * FPGA programming support for SoC FPGA Stratix 10
+ */
+static Altera_desc altera_fpga[] = {
+	{
+		/* Family */
+		Intel_FPGA_Stratix10,
+		/* Interface type */
+		secure_device_manager_mailbox,
+		/* No limitation as additional data will be

ignored */

arch/arm/mach-socfpga/misc.c +4 -0
+		-1,
+		/* No device function table */
+		NULL,
+		/* Base interface address specified in driver

*/

arch/arm/mach-socfpga/misc.c +6 -0
+		NULL,
+		/* No cookie implementation */
+		0
+	},
+};
+#else

 /*
  * FPGA programming support for SoC FPGA Cyclone V */

arch/arm/mach-socfpga/misc.c +0 -0
@@ -107,6 +128,7 @@ static Altera_desc altera_fpga[] = {

  0
  },
 };
+#endif

 /* add device descriptor to FPGA device table */
 void socfpga_fpga_add(void)

arch/arm/mach-socfpga/misc.c void socfpga_fpga_add(void) · line 146

Quoted 9 lines
arch/arm/mach-socfpga/misc.c +6 -0
@@ -116,6 +138,13 @@ void socfpga_fpga_add(void)
  	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
  		fpga_add(fpga_altera, &altera_fpga[i]);
  }
+
+#else
+
+__weak void socfpga_fpga_add(void)
+{
+}

Why is a __weak function defined only in else-statement ?

Quoted 1 line

It should be defined always, with a sane default implementation.

I will remove the empty function in #else-statement and define the default function like this :

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)
{

#ifdef CONFIG_FPGA
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);

#endif
}

Quoted 3 lines
Quoted 1 line

Is that OK?

Can't you have __weak empty implementation of socfpga_fpga_add() and implement a version per platform ? Would that work and make sense ?

socfpga_fpga_add() as shown above is a generic function for adding FPGA devices to FPGA driver which applies to all our platforms. This is the reason why it is defined in misc.c instead of misc_<platform_name>.c.

Quoted 6 lines

It turned out we already have this defined in misc.h:
#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {} #endif

Right, if you had one socfpga_fpga_add() per platform + generic empty one, you could drop that whole thing ^.

Quoted 4 lines

So I don't think I need to make any changes to socfpga_fpga_add() in misc.c. I just have to remove ifdef CONFIG_FPGA in misc_s10.c because it was unnecessary. I will submit v3 for this patch and you can comment further. The v3 patch will be simpler. Thanks.

Please don't submit stuff before the discussion concluded, it's pointless.

Quoted 6 lines
Quoted 6 lines

btw. the best solution would be to fix this proper and implement a DM/DT
based probing of the FPGA, including a proper driver(s) in drivers/fpga/
instead of putting all the crud into arch/arm/mach-socfpga ...

What do you think about this ^

Signature · 2 lines
Best regards,
Marek Vasut
#9 lore raw

PATCH v2 3/4 arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table

Quoted 116 lines · Marek Vasut
Quoted 115 lines · Chee Hong
Quoted 101 lines · Marek Vasut
Quoted 99 lines · Chee Hong
Quoted 79 lines · Marek Vasut
Quoted 65 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

Enable 'fpga' command in u-boot. User will be able to use the
fpga
command to program the FPGA on Stratix10 SoC.

---
 arch/arm/mach-socfpga/misc.c     | 29
+++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/misc_s10.c |  2 ++
 drivers/fpga/altera.c            |  6 ++++++
 include/altera.h                 |  4 ++++

 4 files changed, 41 insertions(+)
arch/arm/mach- renamed from arch/arm/mach-socfpga/misc.c +0 -0

socfpga/misc.c
index a4f6d5c..7986b58 100644

arch/arm/mach-socfpga/misc.c +0 -0
@@ -88,6 +88,27 @@ int overwrite_console(void)
  #endif


 #ifdef CONFIG_FPGA

arch/arm/mach-socfpga/misc.c +11 -0
+#ifdef CONFIG_FPGA_STRATIX10
+/*
+ * FPGA programming support for SoC FPGA Stratix 10
+ */
+static Altera_desc altera_fpga[] = {
+	{
+		/* Family */
+		Intel_FPGA_Stratix10,
+		/* Interface type */
+		secure_device_manager_mailbox,
+		/* No limitation as additional data will

be
ignored */

arch/arm/mach-socfpga/misc.c +4 -0
+		-1,
+		/* No device function table */
+		NULL,
+		/* Base interface address specified in

driver
*/

arch/arm/mach-socfpga/misc.c +6 -0
+		NULL,
+		/* No cookie implementation */
+		0
+	},
+};
+#else

 /*
  * FPGA programming support for SoC FPGA Cyclone V */

arch/arm/mach-socfpga/misc.c +0 -0
@@ -107,6 +128,7 @@ static Altera_desc altera_fpga[] = {

  0
  },
 };
+#endif

 /* add device descriptor to FPGA device table */
 void socfpga_fpga_add(void)

arch/arm/mach-socfpga/misc.c void socfpga_fpga_add(void) · line 146

Quoted 9 lines
arch/arm/mach-socfpga/misc.c +6 -0
@@ -116,6 +138,13 @@ void socfpga_fpga_add(void)
  	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
  		fpga_add(fpga_altera, &altera_fpga[i]);
  }
+
+#else
+
+__weak void socfpga_fpga_add(void)
+{
+}

Why is a __weak function defined only in else-statement ?

Quoted 2 lines

It should be defined always, with a sane default
implementation.

I will remove the empty function in #else-statement and define the
default function like this :

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)
{

#ifdef CONFIG_FPGA
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);

#endif
}

Quoted 5 lines
Quoted 1 line

Is that OK?

Can't you have __weak empty implementation of socfpga_fpga_add() and
implement a version per platform ? Would that work and make sense ?

socfpga_fpga_add() as shown above is a generic function for adding FPGA
devices to FPGA driver which applies to all our platforms. This is the
reason why it is defined in misc.c instead of misc_<platform_name>.c.

Quoted 8 lines
Quoted 6 lines

It turned out we already have this defined in misc.h:
#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {} #endif

Right, if you had one socfpga_fpga_add() per platform + generic empty one, you could drop that whole thing ^.

Yes. It's being addressed in v3 patch:
https://lists.denx.de/pipermail/u-boot/2018-October/343561.html

Quoted 11 lines
Quoted 9 lines

So I don't think I need to make any changes to socfpga_fpga_add() in
misc.c. I just have to remove ifdef CONFIG_FPGA in misc_s10.c because
it was unnecessary. I will submit v3 for this patch and you can comment
further. The v3 patch will be simpler. Thanks.

Please don't submit stuff before the discussion concluded, it's pointless.

OK.

Quoted 4 lines
Quoted 4 lines
Quoted 4 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

btw. the best solution would be to fix this proper and implement a
DM/DT
based probing of the FPGA, including a proper driver(s) in drivers/fpga/
instead of putting all the crud into arch/arm/mach-socfpga ...

What do you think about this ^

I do agree DM/DT is the proper way to implement driver.
But right now those FPGA drivers in drivers/fpga need to be at least call fpga_add() to add themselves into FPGA device table so that their callback functions can be invoked correctly when user issue 'fpga load', 'fpga info' at the command prompt.
So in other words, all drivers in drivers/fpga rely on drivers/fpga/fpga.c (FPGA core driver) to work.

We already have all our fpga drivers in drivers/fpga :
drivers/fpga/stratix10.c (NEW. In this patchset) drivers/fpga/stratixII.c (upstreamed) drivers/fpga/strixv.c (upstreamed) drivers/fpga/cyclon2.c (upstreamed)
and others...

We only define the FPGA device structure in arch/arm/mach- socfpga/misc.c and call fpga_add() to add our FPGA device driver into the global FPGA device table then FPGA core driver will handle the FPGA operations by invoking the FPGA driver's callback functions.

So for proper DM/DT implementation, drivers/fpga/fpga.c need to be changed as well because this is the core of the FPGA driver.I think changing the core of the FPGA driver to support DM/DT would make more sense than I only change my FPGA driver to extract info from DTB file into a device structure then specifically call fpga_add() again to add the device structure to the FPGA core driver.

#10 lore raw

PATCH v2 3/4 arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table

Quoted 123 lines · Chee Hong
Quoted 122 lines · Marek Vasut
Quoted 121 lines · Chee Hong
Quoted 101 lines · Marek Vasut
Quoted 99 lines · Chee Hong
Quoted 79 lines · Marek Vasut
Quoted 65 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

Enable 'fpga' command in u-boot. User will be able to use the
fpga
command to program the FPGA on Stratix10 SoC.

---
 arch/arm/mach-socfpga/misc.c     | 29
+++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/misc_s10.c |  2 ++
 drivers/fpga/altera.c            |  6 ++++++
 include/altera.h                 |  4 ++++

 4 files changed, 41 insertions(+)
arch/arm/mach- renamed from arch/arm/mach-socfpga/misc.c +0 -0

socfpga/misc.c
index a4f6d5c..7986b58 100644

arch/arm/mach-socfpga/misc.c +0 -0
@@ -88,6 +88,27 @@ int overwrite_console(void)
  #endif


 #ifdef CONFIG_FPGA

arch/arm/mach-socfpga/misc.c +11 -0
+#ifdef CONFIG_FPGA_STRATIX10
+/*
+ * FPGA programming support for SoC FPGA Stratix 10
+ */
+static Altera_desc altera_fpga[] = {
+	{
+		/* Family */
+		Intel_FPGA_Stratix10,
+		/* Interface type */
+		secure_device_manager_mailbox,
+		/* No limitation as additional data will

be
ignored */

arch/arm/mach-socfpga/misc.c +4 -0
+		-1,
+		/* No device function table */
+		NULL,
+		/* Base interface address specified in

driver
*/

arch/arm/mach-socfpga/misc.c +6 -0
+		NULL,
+		/* No cookie implementation */
+		0
+	},
+};
+#else

 /*
  * FPGA programming support for SoC FPGA Cyclone V */

arch/arm/mach-socfpga/misc.c +0 -0
@@ -107,6 +128,7 @@ static Altera_desc altera_fpga[] = {

  0
  },
 };
+#endif

 /* add device descriptor to FPGA device table */
 void socfpga_fpga_add(void)

arch/arm/mach-socfpga/misc.c void socfpga_fpga_add(void) · line 146

Quoted 9 lines
arch/arm/mach-socfpga/misc.c +6 -0
@@ -116,6 +138,13 @@ void socfpga_fpga_add(void)
  	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
  		fpga_add(fpga_altera, &altera_fpga[i]);
  }
+
+#else
+
+__weak void socfpga_fpga_add(void)
+{
+}

Why is a __weak function defined only in else-statement ?

Quoted 2 lines

It should be defined always, with a sane default
implementation.

I will remove the empty function in #else-statement and define the
default function like this :

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)
{

#ifdef CONFIG_FPGA
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);

#endif
}

Quoted 5 lines
Quoted 1 line

Is that OK?

Can't you have __weak empty implementation of socfpga_fpga_add() and
implement a version per platform ? Would that work and make sense ?

socfpga_fpga_add() as shown above is a generic function for adding FPGA
devices to FPGA driver which applies to all our platforms. This is the
reason why it is defined in misc.c instead of misc_<platform_name>.c.

It turned out we already have this defined in misc.h:
#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {} #endif

Quoted 4 lines
Quoted 2 lines

Right, if you had one socfpga_fpga_add() per platform + generic empty one, you could drop that whole thing ^.

Yes. It's being addressed in v3 patch:
https://lists.denx.de/pipermail/u-boot/2018-October/343561.html

So where did the function go in there ? I don't see any __weak anything.

Quoted 8 lines
Quoted 8 lines
Quoted 6 lines
Quoted 6 lines

btw. the best solution would be to fix this proper and implement a
DM/DT
based probing of the FPGA, including a proper driver(s) in drivers/fpga/
instead of putting all the crud into arch/arm/mach-socfpga ...

What do you think about this ^

Quoted 7 lines

I do agree DM/DT is the proper way to implement driver.
But right now those FPGA drivers in drivers/fpga need to be at least call fpga_add() to add themselves into FPGA device table so that their callback functions can be invoked correctly when user issue 'fpga load', 'fpga info' at the command prompt.
So in other words, all drivers in drivers/fpga rely on drivers/fpga/fpga.c (FPGA core driver) to work.

Well, that should be fixed so that they probe from DT, just like any other driver. I'm not fond of adding stuff to arch/arm/ ...

Quoted 11 lines

We already have all our fpga drivers in drivers/fpga :
drivers/fpga/stratix10.c (NEW. In this patchset) drivers/fpga/stratixII.c (upstreamed) drivers/fpga/strixv.c (upstreamed) drivers/fpga/cyclon2.c (upstreamed)
and others...

We only define the FPGA device structure in arch/arm/mach- socfpga/misc.c and call fpga_add() to add our FPGA device driver into the global FPGA device table then FPGA core driver will handle the FPGA operations by invoking the FPGA driver's callback functions.

Right, which should be moved to drivers too and which should use DT.

Quoted 6 lines

So for proper DM/DT implementation, drivers/fpga/fpga.c need to be changed as well because this is the core of the FPGA driver.I think changing the core of the FPGA driver to support DM/DT would make more sense than I only change my FPGA driver to extract info from DTB file into a device structure then specifically call fpga_add() again to add the device structure to the FPGA core driver.

Yes, can you add it to your list once we flesh out this patchset ?

Signature · 2 lines
Best regards,
Marek Vasut
#11 lore raw

PATCH v2 3/4 arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table

Quoted 141 lines · Marek Vasut
Quoted 140 lines · Chee Hong
Quoted 138 lines · Marek Vasut
Quoted 136 lines · Chee Hong
Quoted 111 lines · Marek Vasut
Quoted 108 lines · Chee Hong
Quoted 86 lines · Marek Vasut
Quoted 70 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

Enable 'fpga' command in u-boot. User will be able to use
the
fpga
command to program the FPGA on Stratix10 SoC.

---
 arch/arm/mach-socfpga/misc.c     | 29
+++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/misc_s10.c |  2 ++
 drivers/fpga/altera.c            |  6 ++++++
 include/altera.h                 |  4 ++++

 4 files changed, 41 insertions(+)
arch/arm/mach- renamed from arch/arm/mach-socfpga/misc.c +0 -0

socfpga/misc.c
index a4f6d5c..7986b58 100644

arch/arm/mach-socfpga/misc.c +0 -0
@@ -88,6 +88,27 @@ int overwrite_console(void)
  #endif


 #ifdef CONFIG_FPGA

arch/arm/mach-socfpga/misc.c +11 -0
+#ifdef CONFIG_FPGA_STRATIX10
+/*
+ * FPGA programming support for SoC FPGA Stratix 10
+ */
+static Altera_desc altera_fpga[] = {
+	{
+		/* Family */
+		Intel_FPGA_Stratix10,
+		/* Interface type */
+		secure_device_manager_mailbox,
+		/* No limitation as additional data

will
be
ignored */

arch/arm/mach-socfpga/misc.c +4 -0
+		-1,
+		/* No device function table */
+		NULL,
+		/* Base interface address specified in

driver
*/

arch/arm/mach-socfpga/misc.c +6 -0
+		NULL,
+		/* No cookie implementation */
+		0
+	},
+};
+#else

 /*
  * FPGA programming support for SoC FPGA Cyclone V */

arch/arm/mach-socfpga/misc.c +0 -0
@@ -107,6 +128,7 @@ static Altera_desc altera_fpga[] =
 {

  0
  },
 };
+#endif

 /* add device descriptor to FPGA device table */
 void socfpga_fpga_add(void)

arch/arm/mach-socfpga/misc.c void socfpga_fpga_add(void) · line 147

Quoted 10 lines
arch/arm/mach-socfpga/misc.c +6 -0
@@ -116,6 +138,13 @@ void socfpga_fpga_add(void)
  	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
  		fpga_add(fpga_altera,
 &altera_fpga[i]);
  }
+
+#else
+
+__weak void socfpga_fpga_add(void)
+{
+}

Why is a __weak function defined only in else-statement ?

Quoted 2 lines

It should be defined always, with a sane default
implementation.

I will remove the empty function in #else-statement and define
the
default function like this :

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)
{

#ifdef CONFIG_FPGA
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);

#endif
}

Quoted 7 lines
Quoted 1 line

Is that OK?

Can't you have __weak empty implementation of socfpga_fpga_add()
and
implement a version per platform ? Would that work and make sense
?

socfpga_fpga_add() as shown above is a generic function for adding
FPGA
devices to FPGA driver which applies to all our platforms. This is
the
reason why it is defined in misc.c instead of misc_<platform_name>.c.

It turned out we already have this defined in misc.h:
#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {} #endif

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Right, if you had one socfpga_fpga_add() per platform + generic empty
one, you could drop that whole thing ^.

Yes. It's being addressed in v3 patch:
https://lists.denx.de/pipermail/u-boot/2018-October/343561.html

So where did the function go in there ? I don't see any __weak anything.

I don't have to add anything in my v3 patchsets to make this work. It's already taken care by arch/arm/mach-socfpga/include/mach/misc.h as shown below:

#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {}
#endif

An empty default socfpga_fpga_add() will be defined if CONFIG_FPGA is not defined.

Quoted 53 lines
Quoted 15 lines
Quoted 13 lines
Quoted 5 lines
Quoted 5 lines
Quoted 8 lines
Quoted 8 lines

btw. the best solution would be to fix this proper and implement
a
DM/DT
based probing of the FPGA, including a proper driver(s) in drivers/fpga/
instead of putting all the crud into arch/arm/mach-socfpga
...

Quoted 2 lines

What do you think about this ^

Quoted 9 lines

I do agree DM/DT is the proper way to implement driver. But right now those FPGA drivers in drivers/fpga need to be at least
call fpga_add() to add themselves into FPGA device table so that their
callback functions can be invoked correctly when user issue 'fpga load', 'fpga info' at the command prompt.
So in other words, all drivers in drivers/fpga rely on drivers/fpga/fpga.c (FPGA core driver) to work.

Well, that should be fixed so that they probe from DT, just like any other driver. I'm not fond of adding stuff to arch/arm/ ...

Quoted 8 lines

We already have all our fpga drivers in drivers/fpga :
drivers/fpga/stratix10.c (NEW. In this patchset) drivers/fpga/stratixII.c (upstreamed) drivers/fpga/strixv.c (upstreamed) drivers/fpga/cyclon2.c (upstreamed)
and others...

Quoted 6 lines

We only define the FPGA device structure in arch/arm/mach- socfpga/misc.c and call fpga_add() to add our FPGA device driver into
the global FPGA device table then FPGA core driver will handle the FPGA
operations by invoking the FPGA driver's callback functions.

Right, which should be moved to drivers too and which should use DT.

Quoted 10 lines

So for proper DM/DT implementation, drivers/fpga/fpga.c need to be changed as well because this is the core of the FPGA driver.I think changing the core of the FPGA driver to support DM/DT would make more
sense than I only change my FPGA driver to extract info from DTB file
into a device structure then specifically call fpga_add() again to add
the device structure to the FPGA core driver.

Quoted 2 lines

Yes, can you add it to your list once we flesh out this patchset ?

OK.

#12 lore raw

PATCH v2 3/4 arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table

Quoted 153 lines · Chee Hong
Quoted 141 lines · Marek Vasut
Quoted 140 lines · Chee Hong
Quoted 138 lines · Marek Vasut
Quoted 136 lines · Chee Hong
Quoted 111 lines · Marek Vasut
Quoted 108 lines · Chee Hong
Quoted 86 lines · Marek Vasut
Quoted 70 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

Enable 'fpga' command in u-boot. User will be able to use
the
fpga
command to program the FPGA on Stratix10 SoC.

---
 arch/arm/mach-socfpga/misc.c     | 29
+++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/misc_s10.c |  2 ++
 drivers/fpga/altera.c            |  6 ++++++
 include/altera.h                 |  4 ++++

 4 files changed, 41 insertions(+)
arch/arm/mach- renamed from arch/arm/mach-socfpga/misc.c +0 -0

socfpga/misc.c
index a4f6d5c..7986b58 100644

arch/arm/mach-socfpga/misc.c +0 -0
@@ -88,6 +88,27 @@ int overwrite_console(void)
  #endif


 #ifdef CONFIG_FPGA

arch/arm/mach-socfpga/misc.c +11 -0
+#ifdef CONFIG_FPGA_STRATIX10
+/*
+ * FPGA programming support for SoC FPGA Stratix 10
+ */
+static Altera_desc altera_fpga[] = {
+	{
+		/* Family */
+		Intel_FPGA_Stratix10,
+		/* Interface type */
+		secure_device_manager_mailbox,
+		/* No limitation as additional data

will
be
ignored */

arch/arm/mach-socfpga/misc.c +4 -0
+		-1,
+		/* No device function table */
+		NULL,
+		/* Base interface address specified in

driver
*/

arch/arm/mach-socfpga/misc.c +6 -0
+		NULL,
+		/* No cookie implementation */
+		0
+	},
+};
+#else

 /*
  * FPGA programming support for SoC FPGA Cyclone V */

arch/arm/mach-socfpga/misc.c +0 -0
@@ -107,6 +128,7 @@ static Altera_desc altera_fpga[] =
 {

  0
  },
 };
+#endif

 /* add device descriptor to FPGA device table */
 void socfpga_fpga_add(void)

arch/arm/mach-socfpga/misc.c void socfpga_fpga_add(void) · line 147

Quoted 10 lines
arch/arm/mach-socfpga/misc.c +6 -0
@@ -116,6 +138,13 @@ void socfpga_fpga_add(void)
  	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
  		fpga_add(fpga_altera,
 &altera_fpga[i]);
  }
+
+#else
+
+__weak void socfpga_fpga_add(void)
+{
+}

Why is a __weak function defined only in else-statement ?

Quoted 2 lines

It should be defined always, with a sane default
implementation.

I will remove the empty function in #else-statement and define
the
default function like this :

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)
{

#ifdef CONFIG_FPGA
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);

#endif
}

Quoted 7 lines
Quoted 1 line

Is that OK?

Can't you have __weak empty implementation of socfpga_fpga_add()
and
implement a version per platform ? Would that work and make sense
?

socfpga_fpga_add() as shown above is a generic function for adding
FPGA
devices to FPGA driver which applies to all our platforms. This is
the
reason why it is defined in misc.c instead of misc_<platform_name>.c.

It turned out we already have this defined in misc.h:
#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {} #endif

Quoted 7 lines
Quoted 5 lines
Quoted 3 lines

Right, if you had one socfpga_fpga_add() per platform + generic empty
one, you could drop that whole thing ^.

Yes. It's being addressed in v3 patch:
https://lists.denx.de/pipermail/u-boot/2018-October/343561.html

So where did the function go in there ? I don't see any __weak anything.

I don't have to add anything in my v3 patchsets to make this work. It's already taken care by arch/arm/mach-socfpga/include/mach/misc.h as shown below:

Quoted 8 lines

#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {}
#endif

An empty default socfpga_fpga_add() will be defined if CONFIG_FPGA is not defined.

I was hoping to turn this into __weak function.

Quoted 48 lines
Quoted 48 lines
Quoted 10 lines
Quoted 10 lines
Quoted 8 lines
Quoted 8 lines

btw. the best solution would be to fix this proper and implement
a
DM/DT
based probing of the FPGA, including a proper driver(s) in drivers/fpga/
instead of putting all the crud into arch/arm/mach-socfpga
...

What do you think about this ^

Quoted 9 lines

I do agree DM/DT is the proper way to implement driver. But right now those FPGA drivers in drivers/fpga need to be at least
call fpga_add() to add themselves into FPGA device table so that their
callback functions can be invoked correctly when user issue 'fpga load', 'fpga info' at the command prompt.
So in other words, all drivers in drivers/fpga rely on drivers/fpga/fpga.c (FPGA core driver) to work.

Well, that should be fixed so that they probe from DT, just like any other driver. I'm not fond of adding stuff to arch/arm/ ...

Quoted 8 lines

We already have all our fpga drivers in drivers/fpga :
drivers/fpga/stratix10.c (NEW. In this patchset) drivers/fpga/stratixII.c (upstreamed) drivers/fpga/strixv.c (upstreamed) drivers/fpga/cyclon2.c (upstreamed)
and others...

Quoted 6 lines

We only define the FPGA device structure in arch/arm/mach- socfpga/misc.c and call fpga_add() to add our FPGA device driver into
the global FPGA device table then FPGA core driver will handle the FPGA
operations by invoking the FPGA driver's callback functions.

Right, which should be moved to drivers too and which should use DT.

Quoted 10 lines

So for proper DM/DT implementation, drivers/fpga/fpga.c need to be changed as well because this is the core of the FPGA driver.I think changing the core of the FPGA driver to support DM/DT would make more
sense than I only change my FPGA driver to extract info from DTB file
into a device structure then specifically call fpga_add() again to add
the device structure to the FPGA core driver.

Quoted 3 lines
Quoted 2 lines

Yes, can you add it to your list once we flesh out this patchset ?

OK.

Thanks

Signature · 2 lines
Best regards,
Marek Vasut
#13 lore raw

PATCH v2 3/4 arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table

Quoted 182 lines · Marek Vasut
Quoted 181 lines · Chee Hong
Quoted 160 lines · Marek Vasut
Quoted 158 lines · Chee Hong
Quoted 155 lines · Marek Vasut
Quoted 152 lines · Chee Hong
Quoted 124 lines · Marek Vasut
Quoted 120 lines · Chee Hong
Quoted 97 lines · Marek Vasut
Quoted 78 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

Enable 'fpga' command in u-boot. User will be able to
use
the
fpga
command to program the FPGA on Stratix10 SoC.

com>
---
 arch/arm/mach-socfpga/misc.c     | 29
+++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/misc_s10.c |  2 ++
 drivers/fpga/altera.c            |  6 ++++++
 include/altera.h                 |  4 ++++

 4 files changed, 41 insertions(+)
arch/arm/mach- renamed from arch/arm/mach-socfpga/misc.c +0 -0

socfpga/misc.c
index a4f6d5c..7986b58 100644

arch/arm/mach-socfpga/misc.c +0 -0
@@ -88,6 +88,27 @@ int overwrite_console(void)
  #endif


 #ifdef CONFIG_FPGA

arch/arm/mach-socfpga/misc.c +3 -0
+#ifdef CONFIG_FPGA_STRATIX10
+/*
+ * FPGA programming support for SoC FPGA Stratix

10
+ */

arch/arm/mach-socfpga/misc.c +7 -0
+static Altera_desc altera_fpga[] = {
+	{
+		/* Family */
+		Intel_FPGA_Stratix10,
+		/* Interface type */
+		secure_device_manager_mailbox,
+		/* No limitation as additional

data
will
be
ignored */

arch/arm/mach-socfpga/misc.c +4 -0
+		-1,
+		/* No device function table */
+		NULL,
+		/* Base interface address

specified in
driver
*/

arch/arm/mach-socfpga/misc.c +6 -0
+		NULL,
+		/* No cookie implementation */
+		0
+	},
+};
+#else

 /*
  * FPGA programming support for SoC FPGA Cyclone V */

arch/arm/mach-socfpga/misc.c +0 -0
@@ -107,6 +128,7 @@ static Altera_desc

altera_fpga[] =
{
  0
  },
 };
+#endif

 /* add device descriptor to FPGA device table */
 void socfpga_fpga_add(void)

arch/arm/mach-socfpga/misc.c +0 -0
@@ -116,6 +138,13 @@ void socfpga_fpga_add(void)
  	for (i = 0; i < ARRAY_SIZE(altera_fpga);

arch/arm/mach-socfpga/misc.c void socfpga_fpga_add(void) · line 148

Quoted 10 lines
arch/arm/mach-socfpga/misc.c +6 -0
 i++)
  		fpga_add(fpga_altera,
 &altera_fpga[i]);
  }
+
+#else
+
+__weak void socfpga_fpga_add(void)
+{
+}

Why is a __weak function defined only in else-
statement ?

Quoted 2 lines

It should be defined always, with a sane default
implementation.

I will remove the empty function in #else-statement and define
the
default function like this :

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)
{

#ifdef CONFIG_FPGA
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);

#endif
}

Quoted 8 lines
Quoted 1 line

Is that OK?

Can't you have __weak empty implementation of socfpga_fpga_add()
and
implement a version per platform ? Would that work and make
sense
?

socfpga_fpga_add() as shown above is a generic function for adding
FPGA
devices to FPGA driver which applies to all our platforms. This
is
the
reason why it is defined in misc.c instead of misc_<platform_name>.c.

It turned out we already have this defined in misc.h:
#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {} #endif

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Right, if you had one socfpga_fpga_add() per platform + generic
empty
one, you could drop that whole thing ^.

Yes. It's being addressed in v3 patch:
https://lists.denx.de/pipermail/u-boot/2018-October/343561.html

So where did the function go in there ? I don't see any __weak anything.

I don't have to add anything in my v3 patchsets to make this work. It's already taken care by arch/arm/mach- socfpga/include/mach/misc.h as
shown below:

#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {}
#endif

Quoted 4 lines
Quoted 3 lines

An empty default socfpga_fpga_add() will be defined if CONFIG_FPGA is
not defined.

I was hoping to turn this into __weak function.

Below are the new changes for new patch:
Empty weak function in arch/arm/mach-socfpga/misc.c:

/* add device descriptor to FPGA device table */
__weak void socfpga_fpga_add(void)
{
}

In arch/arm/mach-socfpga/misc_aria10.c and arch/arm/mach- socfpga/misc_gen5.c:

#ifdef CONFIG_FPGA
/*
 * FPGA programming support for SoC FPGA Cyclone V */

static Altera_desc altera_fpga[] = {
	{
		/* Family */
		Altera_SoCFPGA,
		/* Interface type */
		fast_passive_parallel,
		/* No limitation as additional data will be ignored */
		-1,
		/* No device function table */
		NULL,
		/* Base interface address specified in driver */
		NULL,
		/* No cookie implementation */
		0
	},
};

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)

{
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);
}

#endif

In arch/arm/mach-socfpga/misc_s10.c:

#ifdef CONFIG_FPGA
/*
 * FPGA programming support for SoC FPGA Stratix 10 */

static Altera_desc altera_fpga[] = {
	{
		/* Family */
		Intel_FPGA_Stratix10,
		/* Interface type */
		secure_device_manager_mailbox,
		/* No limitation as additional data will be ignored */
		-1,
		/* No device function table */
		NULL,
		/* Base interface address specified in driver */
		NULL,
		/* No cookie implementation */
		0
	},
};

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)

{
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);
}

#endif

With this new implementation, each platform overrides the 'socfpga_fpga_add' to add its own fpga device. The problem here is since our aria10 and gen5 are adding same fpga device, there will be duplication of code for these 2 platforms.
What do you think ?
If you are OK with this implementation, I can submit a new patch for review again. Thanks.

Quoted 79 lines
Quoted 70 lines
Quoted 70 lines
Quoted 19 lines
Quoted 17 lines
Quoted 7 lines
Quoted 7 lines
Quoted 10 lines
Quoted 10 lines

btw. the best solution would be to fix this proper and implement
a
DM/DT
based probing of the FPGA, including a proper driver(s) in
drivers/fpga/
instead of putting all the crud into arch/arm/mach- socfpga
...

Quoted 2 lines

What do you think about this ^

Quoted 11 lines

I do agree DM/DT is the proper way to implement driver. But right now those FPGA drivers in drivers/fpga need to be at least
call fpga_add() to add themselves into FPGA device table so that
their
callback functions can be invoked correctly when user issue 'fpga
load', 'fpga info' at the command prompt.
So in other words, all drivers in drivers/fpga rely on drivers/fpga/fpga.c (FPGA core driver) to work.

Well, that should be fixed so that they probe from DT, just like any
other driver. I'm not fond of adding stuff to arch/arm/ ...

Quoted 9 lines

We already have all our fpga drivers in drivers/fpga :
drivers/fpga/stratix10.c (NEW. In this patchset) drivers/fpga/stratixII.c (upstreamed) drivers/fpga/strixv.c (upstreamed) drivers/fpga/cyclon2.c (upstreamed)
and others...

Quoted 8 lines

We only define the FPGA device structure in arch/arm/mach- socfpga/misc.c and call fpga_add() to add our FPGA device driver
into
the global FPGA device table then FPGA core driver will handle the
FPGA
operations by invoking the FPGA driver's callback functions.

Right, which should be moved to drivers too and which should use DT.

Quoted 16 lines

So for proper DM/DT implementation, drivers/fpga/fpga.c need to be
changed as well because this is the core of the FPGA driver.I think
changing the core of the FPGA driver to support DM/DT would make
more
sense than I only change my FPGA driver to extract info from DTB
file
into a device structure then specifically call fpga_add() again to
add
the device structure to the FPGA core driver.

Quoted 4 lines
Quoted 3 lines

Yes, can you add it to your list once we flesh out this patchset ?

OK.

Thanks

--
Best regards,
Marek Vasut

#14 lore raw

PATCH v2 3/4 arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table

Quoted 263 lines · Chee Hong
Quoted 182 lines · Marek Vasut
Quoted 181 lines · Chee Hong
Quoted 160 lines · Marek Vasut
Quoted 158 lines · Chee Hong
Quoted 155 lines · Marek Vasut
Quoted 152 lines · Chee Hong
Quoted 124 lines · Marek Vasut
Quoted 120 lines · Chee Hong
Quoted 97 lines · Marek Vasut
Quoted 78 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

Enable 'fpga' command in u-boot. User will be able to
use
the
fpga
command to program the FPGA on Stratix10 SoC.

com>
---
 arch/arm/mach-socfpga/misc.c     | 29
+++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/misc_s10.c |  2 ++
 drivers/fpga/altera.c            |  6 ++++++
 include/altera.h                 |  4 ++++

 4 files changed, 41 insertions(+)
arch/arm/mach- renamed from arch/arm/mach-socfpga/misc.c +0 -0

socfpga/misc.c
index a4f6d5c..7986b58 100644

arch/arm/mach-socfpga/misc.c +0 -0
@@ -88,6 +88,27 @@ int overwrite_console(void)
  #endif


 #ifdef CONFIG_FPGA

arch/arm/mach-socfpga/misc.c +3 -0
+#ifdef CONFIG_FPGA_STRATIX10
+/*
+ * FPGA programming support for SoC FPGA Stratix

10
+ */

arch/arm/mach-socfpga/misc.c +7 -0
+static Altera_desc altera_fpga[] = {
+	{
+		/* Family */
+		Intel_FPGA_Stratix10,
+		/* Interface type */
+		secure_device_manager_mailbox,
+		/* No limitation as additional

data
will
be
ignored */

arch/arm/mach-socfpga/misc.c +4 -0
+		-1,
+		/* No device function table */
+		NULL,
+		/* Base interface address

specified in
driver
*/

arch/arm/mach-socfpga/misc.c +6 -0
+		NULL,
+		/* No cookie implementation */
+		0
+	},
+};
+#else

 /*
  * FPGA programming support for SoC FPGA Cyclone V */

arch/arm/mach-socfpga/misc.c +0 -0
@@ -107,6 +128,7 @@ static Altera_desc

altera_fpga[] =
{
  0
  },
 };
+#endif

 /* add device descriptor to FPGA device table */
 void socfpga_fpga_add(void)

arch/arm/mach-socfpga/misc.c +0 -0
@@ -116,6 +138,13 @@ void socfpga_fpga_add(void)
  	for (i = 0; i < ARRAY_SIZE(altera_fpga);

arch/arm/mach-socfpga/misc.c void socfpga_fpga_add(void) · line 148

Quoted 10 lines
arch/arm/mach-socfpga/misc.c +6 -0
 i++)
  		fpga_add(fpga_altera,
 &altera_fpga[i]);
  }
+
+#else
+
+__weak void socfpga_fpga_add(void)
+{
+}

Why is a __weak function defined only in else-
statement ?

Quoted 2 lines

It should be defined always, with a sane default
implementation.

I will remove the empty function in #else-statement and define
the
default function like this :

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)
{

#ifdef CONFIG_FPGA
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);

#endif
}

Quoted 8 lines
Quoted 1 line

Is that OK?

Can't you have __weak empty implementation of socfpga_fpga_add()
and
implement a version per platform ? Would that work and make
sense
?

socfpga_fpga_add() as shown above is a generic function for adding
FPGA
devices to FPGA driver which applies to all our platforms. This
is
the
reason why it is defined in misc.c instead of misc_<platform_name>.c.

It turned out we already have this defined in misc.h:
#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {} #endif

Quoted 8 lines
Quoted 6 lines
Quoted 4 lines

Right, if you had one socfpga_fpga_add() per platform + generic
empty
one, you could drop that whole thing ^.

Yes. It's being addressed in v3 patch:
https://lists.denx.de/pipermail/u-boot/2018-October/343561.html

So where did the function go in there ? I don't see any __weak anything.

I don't have to add anything in my v3 patchsets to make this work. It's already taken care by arch/arm/mach- socfpga/include/mach/misc.h as
shown below:

#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {}
#endif

Quoted 4 lines
Quoted 3 lines

An empty default socfpga_fpga_add() will be defined if CONFIG_FPGA is
not defined.

I was hoping to turn this into __weak function.

Below are the new changes for new patch:
Empty weak function in arch/arm/mach-socfpga/misc.c:

/* add device descriptor to FPGA device table */
__weak void socfpga_fpga_add(void)
{
}

In arch/arm/mach-socfpga/misc_aria10.c and arch/arm/mach- socfpga/misc_gen5.c:

#ifdef CONFIG_FPGA
/*
 * FPGA programming support for SoC FPGA Cyclone V */

static Altera_desc altera_fpga[] = {
	{
		/* Family */
		Altera_SoCFPGA,
		/* Interface type */
		fast_passive_parallel,
		/* No limitation as additional data will be ignored */
		-1,
		/* No device function table */
		NULL,
		/* Base interface address specified in driver */
		NULL,
		/* No cookie implementation */
		0
	},
};

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)

{
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);
}

#endif

In arch/arm/mach-socfpga/misc_s10.c:

#ifdef CONFIG_FPGA
/*
 * FPGA programming support for SoC FPGA Stratix 10 */

static Altera_desc altera_fpga[] = {
	{
		/* Family */
		Intel_FPGA_Stratix10,
		/* Interface type */
		secure_device_manager_mailbox,
		/* No limitation as additional data will be ignored */
		-1,
		/* No device function table */
		NULL,
		/* Base interface address specified in driver */
		NULL,
		/* No cookie implementation */
		0
	},
};

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)

{
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);
}
Quoted 7 lines

#endif

With this new implementation, each platform overrides the 'socfpga_fpga_add' to add its own fpga device. The problem here is since our aria10 and gen5 are adding same fpga device, there will be duplication of code for these 2 platforms.
What do you think ?

I think you can create a common code for Gen5 somehow, right ?

Quoted 2 lines

If you are OK with this implementation, I can submit a new patch for review again. Thanks.

Submit the patches, yes.

Signature · 2 lines
Best regards,
Marek Vasut
#15 lore raw

PATCH v2 3/4 arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table

Quoted 293 lines · Marek Vasut
Quoted 292 lines · Chee Hong
Quoted 208 lines · Marek Vasut
Quoted 206 lines · Chee Hong
Quoted 185 lines · Marek Vasut
Quoted 182 lines · Chee Hong
Quoted 178 lines · Marek Vasut
Quoted 164 lines · Chee Hong
Quoted 139 lines · Marek Vasut
Quoted 130 lines · Chee Hong
Quoted 107 lines · Marek Vasut
Quoted 91 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]

Quoted 1 line

Enable 'fpga' command in u-boot. User will be
able
to
use
the
fpga
command to program the FPGA on Stratix10 SoC.

tel.
com>
---
 arch/arm/mach-socfpga/misc.c     | 29
+++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/misc_s10.c |  2 ++
 drivers/fpga/altera.c            |  6 ++++++
 include/altera.h                 |  4 ++++

 4 files changed, 41 insertions(+)
arch/arm/mach- renamed from arch/arm/mach-socfpga/misc.c +0 -0

socfpga/misc.c
index a4f6d5c..7986b58 100644

arch/arm/mach-socfpga/misc.c +0 -0
@@ -88,6 +88,27 @@ int overwrite_console(void)
  #endif


 #ifdef CONFIG_FPGA

arch/arm/mach-socfpga/misc.c +3 -0
+#ifdef CONFIG_FPGA_STRATIX10
+/*
+ * FPGA programming support for SoC FPGA

Stratix
10
+ */

arch/arm/mach-socfpga/misc.c +7 -0
+static Altera_desc altera_fpga[] = {
+	{
+		/* Family */
+		Intel_FPGA_Stratix10,
+		/* Interface type */
+		secure_device_manager_mailbox,
+		/* No limitation as additional

data
will
be
ignored */

arch/arm/mach-socfpga/misc.c +4 -0
+		-1,
+		/* No device function table */
+		NULL,
+		/* Base interface address

specified in
driver
*/

arch/arm/mach-socfpga/misc.c +6 -0
+		NULL,
+		/* No cookie implementation */
+		0
+	},
+};
+#else

 /*
  * FPGA programming support for SoC FPGA
Cyclone V
  */

arch/arm/mach-socfpga/misc.c +0 -0
@@ -107,6 +128,7 @@ static Altera_desc

altera_fpga[] =
{
  0
  },
 };
+#endif

 /* add device descriptor to FPGA device table
*/
 void socfpga_fpga_add(void)

arch/arm/mach-socfpga/misc.c +0 -0
@@ -116,6 +138,13 @@ void
 socfpga_fpga_add(void)

  for (i = 0; i <
ARRAY_SIZE(altera_fpga);
i++)
  fpga_add(fpga_altera,
&altera_fpga[i]);
 }

arch/arm/mach-socfpga/misc.c

Quoted 6 lines
arch/arm/mach-socfpga/misc.c +6 -0
+
+#else
+
+__weak void socfpga_fpga_add(void)
+{
+}

Why is a __weak function defined only in else-
statement ?

Quoted 2 lines

It should be defined always, with a sane default
implementation.

I will remove the empty function in #else-statement and
define
the
default function like this :

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)
{

#ifdef CONFIG_FPGA
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);
Quoted 4 lines

#endif
}

Is that OK?

Quoted 8 lines

Can't you have __weak empty implementation of socfpga_fpga_add()
and
implement a version per platform ? Would that work and
make
sense
?

socfpga_fpga_add() as shown above is a generic function for
adding
FPGA
devices to FPGA driver which applies to all our platforms.
This
is
the
reason why it is defined in misc.c instead of misc_<platform_name>.c.

Quoted 6 lines

It turned out we already have this defined in misc.h:
#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {} #endif

Right, if you had one socfpga_fpga_add() per platform + generic
empty
one, you could drop that whole thing ^.

Quoted 6 lines
Quoted 3 lines

Yes. It's being addressed in v3 patch:
https://lists.denx.de/pipermail/u-boot/2018-October/343561.
html

So where did the function go in there ? I don't see any __weak
anything.

I don't have to add anything in my v3 patchsets to make this work.
It's already taken care by arch/arm/mach- socfpga/include/mach/misc.h as
shown below:

#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {}
#endif

Quoted 5 lines
Quoted 4 lines

An empty default socfpga_fpga_add() will be defined if CONFIG_FPGA
is
not defined.

I was hoping to turn this into __weak function.

Below are the new changes for new patch:
Empty weak function in arch/arm/mach-socfpga/misc.c:

/* add device descriptor to FPGA device table */
__weak void socfpga_fpga_add(void)
{
}

In arch/arm/mach-socfpga/misc_aria10.c and arch/arm/mach- socfpga/misc_gen5.c:

#ifdef CONFIG_FPGA
/*
 * FPGA programming support for SoC FPGA Cyclone V */

static Altera_desc altera_fpga[] = {
	{
		/* Family */
		Altera_SoCFPGA,
		/* Interface type */
		fast_passive_parallel,
		/* No limitation as additional data will be ignored */
		-1,
		/* No device function table */
		NULL,
		/* Base interface address specified in driver */
		NULL,
		/* No cookie implementation */
		0
	},
};

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)

{
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);
}

#endif

In arch/arm/mach-socfpga/misc_s10.c:

#ifdef CONFIG_FPGA
/*
 * FPGA programming support for SoC FPGA Stratix 10 */

static Altera_desc altera_fpga[] = {
	{
		/* Family */
		Intel_FPGA_Stratix10,
		/* Interface type */
		secure_device_manager_mailbox,
		/* No limitation as additional data will be ignored */
		-1,
		/* No device function table */
		NULL,
		/* Base interface address specified in driver */
		NULL,
		/* No cookie implementation */
		0
	},
};

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)

{
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);
}

#endif

Quoted 7 lines
Quoted 6 lines

With this new implementation, each platform overrides the 'socfpga_fpga_add' to add its own fpga device. The problem here is since our aria10 and gen5 are adding same fpga device, there will be
duplication of code for these 2 platforms.
What do you think ?

I think you can create a common code for Gen5 somehow, right ?

I think I will add a new file arch/arm/mach-socfpga/fpga_devices.c and put the common code in it so that different platforms can share the common implementation which override the weak 'socfpga_fpga_add' function. The new file will have the following code:

#ifdef CONFIG_FPGA_STRATIX10
/*
 * FPGA programming support for SoC FPGA Stratix 10 */

static Altera_desc altera_fpga[] = {
	{
		/* Family */
		Intel_FPGA_Stratix10,
		/* Interface type */
		secure_device_manager_mailbox,
		/* No limitation as additional data will be ignored */
		-1,
		/* No device function table */
		NULL,
		/* Base interface address specified in driver */
		NULL,
		/* No cookie implementation */
		0
	},
};

#else
/*
 * FPGA programming support for SoC FPGA Cyclone V */

static Altera_desc altera_fpga[] = {
	{
		/* Family */
		Altera_SoCFPGA,
		/* Interface type */
		fast_passive_parallel,
		/* No limitation as additional data will be ignored */
		-1,
		/* No device function table */
		NULL,
		/* Base interface address specified in driver */
		NULL,
		/* No cookie implementation */
		0
	},
};

#endif

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)

{
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);
}
Quoted 7 lines
Quoted 5 lines

If you are OK with this implementation, I can submit a new patch for
review again. Thanks.

Submit the patches, yes.

#16 lore raw

PATCH v2 3/4 arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table

Quoted 348 lines · Chee Hong
Quoted 293 lines · Marek Vasut
Quoted 292 lines · Chee Hong
Quoted 208 lines · Marek Vasut
Quoted 206 lines · Chee Hong
Quoted 185 lines · Marek Vasut
Quoted 182 lines · Chee Hong
Quoted 178 lines · Marek Vasut
Quoted 164 lines · Chee Hong
Quoted 139 lines · Marek Vasut
Quoted 130 lines · Chee Hong
Quoted 107 lines · Marek Vasut
Quoted 97 lines · chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]

Enable 'fpga' command in u-boot. User will be
able
to
use
the
fpga
command to program the FPGA on Stratix10 SoC.

Signed-off-by: Ang, Chee Hong <chee.hong.ang@in
tel.
com>
---
 arch/arm/mach-socfpga/misc.c     | 29
+++++++++++++++++++++++++++++
 arch/arm/mach-socfpga/misc_s10.c |  2 ++
 drivers/fpga/altera.c            |  6 ++++++
 include/altera.h                 |  4 ++++
 4 files changed, 41 insertions(+)

diff --git a/arch/arm/mach-socfpga/misc.c
b/arch/arm/mach-
socfpga/misc.c
index a4f6d5c..7986b58 100644
--- a/arch/arm/mach-socfpga/misc.c
+++ b/arch/arm/mach-socfpga/misc.c
@@ -88,6 +88,27 @@ int overwrite_console(void)
 #endif

 #ifdef CONFIG_FPGA
+#ifdef CONFIG_FPGA_STRATIX10
+/*
+ * FPGA programming support for SoC FPGA
Stratix
10
+ */
+static Altera_desc altera_fpga[] = {
+ {
+ /* Family */
+ Intel_FPGA_Stratix10,
+ /* Interface type */
+ secure_device_manager_mailbox,
+ /* No limitation as additional
data
will
be
ignored */
+ -1,
+ /* No device function table */
+ NULL,
+ /* Base interface address
specified in
driver
*/
+ NULL,
+ /* No cookie implementation */
+ 0
+ },
+};
+#else
 /*
  * FPGA programming support for SoC FPGA
Cyclone V
  */
@@ -107,6 +128,7 @@ static Altera_desc
altera_fpga[] =
{
  0
  },
 };
+#endif

 /* add device descriptor to FPGA device table
*/
 void socfpga_fpga_add(void)
@@ -116,6 +138,13 @@ void
socfpga_fpga_add(void)
  for (i = 0; i <
ARRAY_SIZE(altera_fpga);
i++)
  fpga_add(fpga_altera,
&altera_fpga[i]);
 }
+
+#else
+
+__weak void socfpga_fpga_add(void)
+{
+}

Why is a __weak function defined only in else-
statement ?

Quoted 2 lines

It should be defined always, with a sane default
implementation.

I will remove the empty function in #else-statement and
define
the
default function like this :

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)
{

#ifdef CONFIG_FPGA
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);
Quoted 4 lines

#endif
}

Is that OK?

Quoted 8 lines

Can't you have __weak empty implementation of socfpga_fpga_add()
and
implement a version per platform ? Would that work and
make
sense
?

socfpga_fpga_add() as shown above is a generic function for
adding
FPGA
devices to FPGA driver which applies to all our platforms.
This
is
the
reason why it is defined in misc.c instead of misc_<platform_name>.c.

Quoted 6 lines

It turned out we already have this defined in misc.h:
#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {} #endif

Right, if you had one socfpga_fpga_add() per platform + generic
empty
one, you could drop that whole thing ^.

Quoted 6 lines
Quoted 3 lines

Yes. It's being addressed in v3 patch:
https://lists.denx.de/pipermail/u-boot/2018-October/343561.
html

So where did the function go in there ? I don't see any __weak
anything.

I don't have to add anything in my v3 patchsets to make this work.
It's already taken care by arch/arm/mach- socfpga/include/mach/misc.h as
shown below:

#ifdef CONFIG_FPGA
void socfpga_fpga_add(void);
#else
static inline void socfpga_fpga_add(void) {}
#endif

Quoted 5 lines
Quoted 4 lines

An empty default socfpga_fpga_add() will be defined if CONFIG_FPGA
is
not defined.

I was hoping to turn this into __weak function.

Below are the new changes for new patch:
Empty weak function in arch/arm/mach-socfpga/misc.c:

/* add device descriptor to FPGA device table */
__weak void socfpga_fpga_add(void)
{
}

In arch/arm/mach-socfpga/misc_aria10.c and arch/arm/mach- socfpga/misc_gen5.c:

#ifdef CONFIG_FPGA
/*
 * FPGA programming support for SoC FPGA Cyclone V */

static Altera_desc altera_fpga[] = {
	{
		/* Family */
		Altera_SoCFPGA,
		/* Interface type */
		fast_passive_parallel,
		/* No limitation as additional data will be ignored */
		-1,
		/* No device function table */
		NULL,
		/* Base interface address specified in driver */
		NULL,
		/* No cookie implementation */
		0
	},
};

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)

{
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);
}

#endif

In arch/arm/mach-socfpga/misc_s10.c:

#ifdef CONFIG_FPGA
/*
 * FPGA programming support for SoC FPGA Stratix 10 */

static Altera_desc altera_fpga[] = {
	{
		/* Family */
		Intel_FPGA_Stratix10,
		/* Interface type */
		secure_device_manager_mailbox,
		/* No limitation as additional data will be ignored */
		-1,
		/* No device function table */
		NULL,
		/* Base interface address specified in driver */
		NULL,
		/* No cookie implementation */
		0
	},
};

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)

{
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);
}

#endif

Quoted 7 lines
Quoted 6 lines

With this new implementation, each platform overrides the 'socfpga_fpga_add' to add its own fpga device. The problem here is since our aria10 and gen5 are adding same fpga device, there will be
duplication of code for these 2 platforms.
What do you think ?

I think you can create a common code for Gen5 somehow, right ?

I think I will add a new file arch/arm/mach-socfpga/fpga_devices.c and put the common code in it so that different platforms can share the common implementation which override the weak 'socfpga_fpga_add' function. The new file will have the following code:

#ifdef CONFIG_FPGA_STRATIX10
/*
 * FPGA programming support for SoC FPGA Stratix 10 */

static Altera_desc altera_fpga[] = {
	{
		/* Family */
		Intel_FPGA_Stratix10,
		/* Interface type */
		secure_device_manager_mailbox,
		/* No limitation as additional data will be ignored */
		-1,
		/* No device function table */
		NULL,
		/* Base interface address specified in driver */
		NULL,
		/* No cookie implementation */
		0
	},
};

#else
/*
 * FPGA programming support for SoC FPGA Cyclone V */

static Altera_desc altera_fpga[] = {
	{
		/* Family */
		Altera_SoCFPGA,
		/* Interface type */
		fast_passive_parallel,
		/* No limitation as additional data will be ignored */
		-1,
		/* No device function table */
		NULL,
		/* Base interface address specified in driver */
		NULL,
		/* No cookie implementation */
		0
	},
};

#endif

Quoted 9 lines

/* add device descriptor to FPGA device table */
void socfpga_fpga_add(void)

{
	int i;
	fpga_init();
	for (i = 0; i < ARRAY_SIZE(altera_fpga); i++)
		fpga_add(fpga_altera, &altera_fpga[i]);
}

Better submit the whole patch, it's hard to review pieces.

Signature · 2 lines
Best regards,
Marek Vasut
#17 lore raw

PATCH v2 4/4 arm: socfpga: stratix10: Enable Stratix10 FPGA Reconfiguration

In reply to chee.hong.ang at intel.com

From: "Ang, Chee Hong" <[email protected]>

Enable Stratix10 FPGA reconfiguration support in defconfig.

---
 configs/socfpga_stratix10_defconfig | 1 +
 1 file changed, 1 insertion(+)
configs/socfpga_stratix10_defconfig +1 -0
index 5f3d733..155c406 100644
@@ -10,6 +10,7 @@ CONFIG_NR_DRAM_BANKS=1
 CONFIG_BOOTDELAY=5
 CONFIG_SPL_SPI_LOAD=y
 CONFIG_HUSH_PARSER=y
+CONFIG_FPGA_STRATIX10=y
 CONFIG_SYS_PROMPT="SOCFPGA_STRATIX10 # "
 CONFIG_CMD_MEMTEST=y
 # CONFIG_CMD_FLASH is not set
Signature · 1 line
2.7.4