diff mbox series

[1/3] riscv: define function set_gd()

Message ID 20200910110048.21446-2-xypron.glpk@gmx.de
State Accepted, archived
Commit 6b9966e1aa362e97e9b33b7b82ff713f2ddea2c1
Delegated to: Heinrich Schuchardt
Headers show
Series efi_loader: save global data pointer on RISC-V | expand

Commit Message

Heinrich Schuchardt Sept. 10, 2020, 11 a.m. UTC
Function set_gd() is needed in the UEFI sub-system if the global data
pointer is stored in a register.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
---
 arch/riscv/include/asm/global_data.h | 9 +++++++++
 1 file changed, 9 insertions(+)

--
2.28.0

Comments

Sean Anderson Sept. 10, 2020, 11:04 a.m. UTC | #1
On 9/10/20 7:00 AM, Heinrich Schuchardt wrote:
> Function set_gd() is needed in the UEFI sub-system if the global data
> pointer is stored in a register.
> 
> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
> ---
>  arch/riscv/include/asm/global_data.h | 9 +++++++++
>  1 file changed, 9 insertions(+)
> 
> diff --git a/arch/riscv/include/asm/global_data.h b/arch/riscv/include/asm/global_data.h
> index 2eb14815bc..b711fcc44d 100644
> --- a/arch/riscv/include/asm/global_data.h
> +++ b/arch/riscv/include/asm/global_data.h
> @@ -39,4 +39,13 @@ struct arch_global_data {
> 
>  #define DECLARE_GLOBAL_DATA_PTR register gd_t *gd asm ("gp")
> 
> +static inline void set_gd(volatile gd_t *gd_ptr)
> +{
> +#ifdef CONFIG_64BIT
> +	asm volatile("ld gp, %0\n" : : "m"(gd_ptr));
> +#else
> +	asm volatile("lw gp, %0\n" : : "m"(gd_ptr));
> +#endif
> +}
> +
>  #endif /* __ASM_GBL_DATA_H */
> --
> 2.28.0
> 

Can't we just use arch_setup_gd?

--Sean
Heinrich Schuchardt Sept. 10, 2020, 11:56 a.m. UTC | #2
On 10.09.20 13:04, Sean Anderson wrote:
> On 9/10/20 7:00 AM, Heinrich Schuchardt wrote:
>> Function set_gd() is needed in the UEFI sub-system if the global data
>> pointer is stored in a register.
>>
>> Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
>> ---
>>  arch/riscv/include/asm/global_data.h | 9 +++++++++
>>  1 file changed, 9 insertions(+)
>>
>> diff --git a/arch/riscv/include/asm/global_data.h b/arch/riscv/include/asm/global_data.h
>> index 2eb14815bc..b711fcc44d 100644
>> --- a/arch/riscv/include/asm/global_data.h
>> +++ b/arch/riscv/include/asm/global_data.h
>> @@ -39,4 +39,13 @@ struct arch_global_data {
>>
>>  #define DECLARE_GLOBAL_DATA_PTR register gd_t *gd asm ("gp")
>>
>> +static inline void set_gd(volatile gd_t *gd_ptr)
>> +{
>> +#ifdef CONFIG_64BIT
>> +	asm volatile("ld gp, %0\n" : : "m"(gd_ptr));
>> +#else
>> +	asm volatile("lw gp, %0\n" : : "m"(gd_ptr));
>> +#endif
>> +}
>> +
>>  #endif /* __ASM_GBL_DATA_H */
>> --
>> 2.28.0
>>
>
> Can't we just use arch_setup_gd?

The variables that we use to store gd have been defined as volatile to
ensure that the compiler does not optimize them away. See lib/trace.c)
and lib/efi_loader/efi_boottime.c. (A further patch for lib/trace.c will
be needed if we want to trace UEFI API calls on RISC-V.)

arch_setup_gd() does not take a volatile variable.

I looked at using WRITE_ONCE() instead of volatile variables. But if gd
is a register, &gd is undefined and WRITE_ONCE() is not usable.

Best regards

Heinrich

>
> --Sean
>
diff mbox series

Patch

diff --git a/arch/riscv/include/asm/global_data.h b/arch/riscv/include/asm/global_data.h
index 2eb14815bc..b711fcc44d 100644
--- a/arch/riscv/include/asm/global_data.h
+++ b/arch/riscv/include/asm/global_data.h
@@ -39,4 +39,13 @@  struct arch_global_data {

 #define DECLARE_GLOBAL_DATA_PTR register gd_t *gd asm ("gp")

+static inline void set_gd(volatile gd_t *gd_ptr)
+{
+#ifdef CONFIG_64BIT
+	asm volatile("ld gp, %0\n" : : "m"(gd_ptr));
+#else
+	asm volatile("lw gp, %0\n" : : "m"(gd_ptr));
+#endif
+}
+
 #endif /* __ASM_GBL_DATA_H */