diff mbox series

[U-Boot,v2,3/4] arm: socfpga: stratix10: Add Stratix10 FPGA into FPGA device table

Message ID 1538992107-37855-4-git-send-email-chee.hong.ang@intel.com
State Superseded
Delegated to: Marek Vasut
Headers show
Series Stratix10 FPGA reconfiguration support | expand

Commit Message

Ang, Chee Hong Oct. 8, 2018, 9:48 a.m. UTC
From: "Ang, Chee Hong" <chee.hong.ang@intel.com>

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@intel.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(+)

Comments

Marek Vasut Oct. 8, 2018, 9:57 a.m. UTC | #1
On 10/08/2018 11:48 AM, chee.hong.ang@intel.com wrote:
> From: "Ang, Chee Hong" <chee.hong.ang@intel.com>
> 
> 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@intel.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 ?

It should be defined always, with a sane default implementation.
Ang, Chee Hong Oct. 8, 2018, 3:10 p.m. UTC | #2
On Mon, 2018-10-08 at 11:57 +0200, Marek Vasut wrote:
> On 10/08/2018 11:48 AM, chee.hong.ang@intel.com wrote:
> > 
> > From: "Ang, Chee Hong" <chee.hong.ang@intel.com>
> > 
> > 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@intel.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 ?
> 
> 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?
Marek Vasut Oct. 8, 2018, 8:32 p.m. UTC | #3
On 10/08/2018 05:10 PM, Ang, Chee Hong wrote:
> On Mon, 2018-10-08 at 11:57 +0200, Marek Vasut wrote:
>> On 10/08/2018 11:48 AM, chee.hong.ang@intel.com wrote:
>>>
>>> From: "Ang, Chee Hong" <chee.hong.ang@intel.com>
>>>
>>> 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@intel.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 ?
>>
>> 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?

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 ...
Ang, Chee Hong Oct. 9, 2018, 3:03 a.m. UTC | #4
On Mon, 2018-10-08 at 22:32 +0200, Marek Vasut wrote:
> On 10/08/2018 05:10 PM, Ang, Chee Hong wrote:
> > 
> > On Mon, 2018-10-08 at 11:57 +0200, Marek Vasut wrote:
> > > 
> > > On 10/08/2018 11:48 AM, chee.hong.ang@intel.com wrote:
> > > > 
> > > > 
> > > > From: "Ang, Chee Hong" <chee.hong.ang@intel.com>
> > > > 
> > > > 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@intel.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 ?
> > > 
> > > 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?
> 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.

> 
> 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 ...
>
Marek Vasut Oct. 9, 2018, 12:48 p.m. UTC | #5
On 10/09/2018 05:03 AM, Ang, Chee Hong wrote:
> On Mon, 2018-10-08 at 22:32 +0200, Marek Vasut wrote:
>> On 10/08/2018 05:10 PM, Ang, Chee Hong wrote:
>>>
>>> On Mon, 2018-10-08 at 11:57 +0200, Marek Vasut wrote:
>>>>
>>>> On 10/08/2018 11:48 AM, chee.hong.ang@intel.com wrote:
>>>>>
>>>>>
>>>>> From: "Ang, Chee Hong" <chee.hong.ang@intel.com>
>>>>>
>>>>> 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@intel.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 ?
>>>>
>>>> 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?
>> 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

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

> 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.

>>
>> 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 ^
Ang, Chee Hong Oct. 10, 2018, 5:30 a.m. UTC | #6
On Tue, 2018-10-09 at 14:48 +0200, Marek Vasut wrote:
> On 10/09/2018 05:03 AM, Ang, Chee Hong wrote:
> > 
> > On Mon, 2018-10-08 at 22:32 +0200, Marek Vasut wrote:
> > > 
> > > On 10/08/2018 05:10 PM, Ang, Chee Hong wrote:
> > > > 
> > > > 
> > > > On Mon, 2018-10-08 at 11:57 +0200, Marek Vasut wrote:
> > > > > 
> > > > > 
> > > > > On 10/08/2018 11:48 AM, chee.hong.ang@intel.com wrote:
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > From: "Ang, Chee Hong" <chee.hong.ang@intel.com>
> > > > > > 
> > > > > > 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@intel.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 ?
> > > > > 
> > > > > 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?
> > > 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
> 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 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.
> 
> > 
> > > 
> > > 
> > > 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.
Marek Vasut Oct. 10, 2018, 10:27 a.m. UTC | #7
On 10/10/2018 07:30 AM, Ang, Chee Hong wrote:
> On Tue, 2018-10-09 at 14:48 +0200, Marek Vasut wrote:
>> On 10/09/2018 05:03 AM, Ang, Chee Hong wrote:
>>>
>>> On Mon, 2018-10-08 at 22:32 +0200, Marek Vasut wrote:
>>>>
>>>> On 10/08/2018 05:10 PM, Ang, Chee Hong wrote:
>>>>>
>>>>>
>>>>> On Mon, 2018-10-08 at 11:57 +0200, Marek Vasut wrote:
>>>>>>
>>>>>>
>>>>>> On 10/08/2018 11:48 AM, chee.hong.ang@intel.com wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> From: "Ang, Chee Hong" <chee.hong.ang@intel.com>
>>>>>>>
>>>>>>> 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@intel.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 ?
>>>>>>
>>>>>> 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?
>>>> 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
>> 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.

>>>> 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.

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/ ...

> 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.

> 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 ?
Ang, Chee Hong Oct. 11, 2018, 6:21 a.m. UTC | #8
On Wed, 2018-10-10 at 12:27 +0200, Marek Vasut wrote:
> On 10/10/2018 07:30 AM, Ang, Chee Hong wrote:
> > 
> > On Tue, 2018-10-09 at 14:48 +0200, Marek Vasut wrote:
> > > 
> > > On 10/09/2018 05:03 AM, Ang, Chee Hong wrote:
> > > > 
> > > > 
> > > > On Mon, 2018-10-08 at 22:32 +0200, Marek Vasut wrote:
> > > > > 
> > > > > 
> > > > > On 10/08/2018 05:10 PM, Ang, Chee Hong wrote:
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > On Mon, 2018-10-08 at 11:57 +0200, Marek Vasut wrote:
> > > > > > > 
> > > > > > > 
> > > > > > > 
> > > > > > > On 10/08/2018 11:48 AM, chee.hong.ang@intel.com wrote:
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > From: "Ang, Chee Hong" <chee.hong.ang@intel.com>
> > > > > > > > 
> > > > > > > > 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@intel.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 ?
> > > > > > > 
> > > > > > > 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?
> > > > > 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
> > > 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.
> 
> > 
> > > 
> > > > 
> > > > > 
> > > > > 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.
> 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/ ...
> 
> > 
> > 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.
> 
> > 
> > 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 ?
> 
OK.
Marek Vasut Oct. 11, 2018, 10:03 a.m. UTC | #9
On 10/11/2018 08:21 AM, Ang, Chee Hong wrote:
> On Wed, 2018-10-10 at 12:27 +0200, Marek Vasut wrote:
>> On 10/10/2018 07:30 AM, Ang, Chee Hong wrote:
>>>
>>> On Tue, 2018-10-09 at 14:48 +0200, Marek Vasut wrote:
>>>>
>>>> On 10/09/2018 05:03 AM, Ang, Chee Hong wrote:
>>>>>
>>>>>
>>>>> On Mon, 2018-10-08 at 22:32 +0200, Marek Vasut wrote:
>>>>>>
>>>>>>
>>>>>> On 10/08/2018 05:10 PM, Ang, Chee Hong wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Mon, 2018-10-08 at 11:57 +0200, Marek Vasut wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 10/08/2018 11:48 AM, chee.hong.ang@intel.com wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> From: "Ang, Chee Hong" <chee.hong.ang@intel.com>
>>>>>>>>>
>>>>>>>>> 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@intel.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 ?
>>>>>>>>
>>>>>>>> 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?
>>>>>> 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
>>>> 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.

I was hoping to turn this into __weak function.

>>>>>> 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.
>> 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/ ...
>>
>>>
>>> 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.
>>
>>>
>>> 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 ?
>>
> OK.

Thanks
Ang, Chee Hong Nov. 14, 2018, 7:09 a.m. UTC | #10
On Thu, 2018-10-11 at 10:03 +0000, Marek Vasut wrote:
> On 10/11/2018 08:21 AM, Ang, Chee Hong wrote:
> > 
> > On Wed, 2018-10-10 at 12:27 +0200, Marek Vasut wrote:
> > > 
> > > On 10/10/2018 07:30 AM, Ang, Chee Hong wrote:
> > > > 
> > > > 
> > > > On Tue, 2018-10-09 at 14:48 +0200, Marek Vasut wrote:
> > > > > 
> > > > > 
> > > > > On 10/09/2018 05:03 AM, Ang, Chee Hong wrote:
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > On Mon, 2018-10-08 at 22:32 +0200, Marek Vasut wrote:
> > > > > > > 
> > > > > > > 
> > > > > > > 
> > > > > > > On 10/08/2018 05:10 PM, Ang, Chee Hong wrote:
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > On Mon, 2018-10-08 at 11:57 +0200, Marek Vasut wrote:
> > > > > > > > > 
> > > > > > > > > 
> > > > > > > > > 
> > > > > > > > > 
> > > > > > > > > On 10/08/2018 11:48 AM, chee.hong.ang@intel.com
> > > > > > > > > wrote:
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > From: "Ang, Chee Hong" <chee.hong.ang@intel.com>
> > > > > > > > > > 
> > > > > > > > > > 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@intel.
> > > > > > > > > > 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 ?
> > > > > > > > > 
> > > > > > > > > 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?
> > > > > > > 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
> > > > > 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.
> 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.
> 
> > 
> > > 
> > > > 
> > > > > 
> > > > > > 
> > > > > > > 
> > > > > > > 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.
> > > 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/ ...
> > > 
> > > > 
> > > > 
> > > > 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.
> > > 
> > > > 
> > > > 
> > > > 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
> > > ?
> > > 
> > OK.
> Thanks
> 
> -- 
> Best regards,
> Marek Vasut
Marek Vasut Nov. 14, 2018, 11:52 a.m. UTC | #11
On 11/14/2018 08:09 AM, Ang, Chee Hong wrote:
> On Thu, 2018-10-11 at 10:03 +0000, Marek Vasut wrote:
>> On 10/11/2018 08:21 AM, Ang, Chee Hong wrote:
>>>
>>> On Wed, 2018-10-10 at 12:27 +0200, Marek Vasut wrote:
>>>>
>>>> On 10/10/2018 07:30 AM, Ang, Chee Hong wrote:
>>>>>
>>>>>
>>>>> On Tue, 2018-10-09 at 14:48 +0200, Marek Vasut wrote:
>>>>>>
>>>>>>
>>>>>> On 10/09/2018 05:03 AM, Ang, Chee Hong wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Mon, 2018-10-08 at 22:32 +0200, Marek Vasut wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 10/08/2018 05:10 PM, Ang, Chee Hong wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Mon, 2018-10-08 at 11:57 +0200, Marek Vasut wrote:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 10/08/2018 11:48 AM, chee.hong.ang@intel.com
>>>>>>>>>> wrote:
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> From: "Ang, Chee Hong" <chee.hong.ang@intel.com>
>>>>>>>>>>>
>>>>>>>>>>> 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@intel.
>>>>>>>>>>> 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 ?
>>>>>>>>>>
>>>>>>>>>> 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?
>>>>>>>> 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
>>>>>> 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.
>> 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 ?

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

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

Submit the patches, yes.
Ang, Chee Hong Nov. 15, 2018, 7:13 a.m. UTC | #12
On Wed, 2018-11-14 at 12:52 +0100, Marek Vasut wrote:
> On 11/14/2018 08:09 AM, Ang, Chee Hong wrote:
> > 
> > On Thu, 2018-10-11 at 10:03 +0000, Marek Vasut wrote:
> > > 
> > > On 10/11/2018 08:21 AM, Ang, Chee Hong wrote:
> > > > 
> > > > 
> > > > On Wed, 2018-10-10 at 12:27 +0200, Marek Vasut wrote:
> > > > > 
> > > > > 
> > > > > On 10/10/2018 07:30 AM, Ang, Chee Hong wrote:
> > > > > > 
> > > > > > 
> > > > > > 
> > > > > > On Tue, 2018-10-09 at 14:48 +0200, Marek Vasut wrote:
> > > > > > > 
> > > > > > > 
> > > > > > > 
> > > > > > > On 10/09/2018 05:03 AM, Ang, Chee Hong wrote:
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > 
> > > > > > > > On Mon, 2018-10-08 at 22:32 +0200, Marek Vasut wrote:
> > > > > > > > > 
> > > > > > > > > 
> > > > > > > > > 
> > > > > > > > > 
> > > > > > > > > On 10/08/2018 05:10 PM, Ang, Chee Hong wrote:
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > 
> > > > > > > > > > On Mon, 2018-10-08 at 11:57 +0200, Marek Vasut
> > > > > > > > > > wrote:
> > > > > > > > > > > 
> > > > > > > > > > > 
> > > > > > > > > > > 
> > > > > > > > > > > 
> > > > > > > > > > > 
> > > > > > > > > > > On 10/08/2018 11:48 AM, chee.hong.ang@intel.com
> > > > > > > > > > > wrote:
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > 
> > > > > > > > > > > > From: "Ang, Chee Hong" <chee.hong.ang@intel.com
> > > > > > > > > > > > >
> > > > > > > > > > > > 
> > > > > > > > > > > > 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 ?
> > > > > > > > > > > 
> > > > > > > > > > > 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?
> > > > > > > > > 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
> > > > > > > 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.
> > > 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 ?
> 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]);
}

> 
> > 
> > If you are OK with this implementation, I can submit a new patch
> > for
> > review again. Thanks.
> Submit the patches, yes.
>
Marek Vasut Nov. 15, 2018, 1:40 p.m. UTC | #13
On 11/15/2018 08:13 AM, Ang, Chee Hong wrote:
> On Wed, 2018-11-14 at 12:52 +0100, Marek Vasut wrote:
>> On 11/14/2018 08:09 AM, Ang, Chee Hong wrote:
>>>
>>> On Thu, 2018-10-11 at 10:03 +0000, Marek Vasut wrote:
>>>>
>>>> On 10/11/2018 08:21 AM, Ang, Chee Hong wrote:
>>>>>
>>>>>
>>>>> On Wed, 2018-10-10 at 12:27 +0200, Marek Vasut wrote:
>>>>>>
>>>>>>
>>>>>> On 10/10/2018 07:30 AM, Ang, Chee Hong wrote:
>>>>>>>
>>>>>>>
>>>>>>>
>>>>>>> On Tue, 2018-10-09 at 14:48 +0200, Marek Vasut wrote:
>>>>>>>>
>>>>>>>>
>>>>>>>>
>>>>>>>> On 10/09/2018 05:03 AM, Ang, Chee Hong wrote:
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>>
>>>>>>>>> On Mon, 2018-10-08 at 22:32 +0200, Marek Vasut wrote:
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>>
>>>>>>>>>> On 10/08/2018 05:10 PM, Ang, Chee Hong wrote:
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>>
>>>>>>>>>>> On Mon, 2018-10-08 at 11:57 +0200, Marek Vasut
>>>>>>>>>>> wrote:
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>>
>>>>>>>>>>>> On 10/08/2018 11:48 AM, chee.hong.ang@intel.com
>>>>>>>>>>>> wrote:
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> From: "Ang, Chee Hong" <chee.hong.ang@intel.com
>>>>>>>>>>>>>>
>>>>>>>>>>>>>
>>>>>>>>>>>>> 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 ?
>>>>>>>>>>>>
>>>>>>>>>>>> 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?
>>>>>>>>>> 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
>>>>>>>> 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.
>>>> 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 ?
>> 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]);
> }
> 

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

Patch

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)
+{
+}
+
 #endif
 
 int arch_cpu_init(void)
diff --git a/arch/arm/mach-socfpga/misc_s10.c b/arch/arm/mach-socfpga/misc_s10.c
index 918baac..f23c0dc 100644
--- a/arch/arm/mach-socfpga/misc_s10.c
+++ b/arch/arm/mach-socfpga/misc_s10.c
@@ -124,6 +124,8 @@  int arch_misc_init(void)
 
 int arch_early_init_r(void)
 {
+	socfpga_fpga_add();
+
 	return 0;
 }
 
diff --git a/drivers/fpga/altera.c b/drivers/fpga/altera.c
index 9605554..7c8f518 100644
--- a/drivers/fpga/altera.c
+++ b/drivers/fpga/altera.c
@@ -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);
diff --git a/include/altera.h b/include/altera.h
index 233b467..22d55cf 100644
--- a/include/altera.h
+++ b/include/altera.h
@@ -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,