All of lore.kernel.org
 help / color / mirror / Atom feed
From: Andre Przywara <andre.przywara@arm.com>
To: Mark Rutland <mark.rutland@arm.com>
Cc: linux-arm-kernel@lists.infradead.org, Jaxson.Han@arm.com,
	robin.murphy@arm.com, vladimir.murzin@arm.com, Wei.Chen@arm.com
Subject: Re: [bootwrapper PATCH v2 03/13] aarch64: add system register accessors
Date: Fri, 14 Jan 2022 15:32:27 +0000	[thread overview]
Message-ID: <20220114153227.3f2a2d09@donnerap.cambridge.arm.com> (raw)
In-Reply-To: <20220114105653.3003399-4-mark.rutland@arm.com>

On Fri, 14 Jan 2022 10:56:43 +0000
Mark Rutland <mark.rutland@arm.com> wrote:

Hi Mark,

> We open code the use of mrs/msr for specific registers, which is
> somewhat tedious. Add macros to do this generically, along with a helper
> to extract a specific register field. Existing C usage is converted to
> the new helpers, and register definitions moved to a common location.
> 
> There should be no functional change as a result of this patch.
> 
> Signed-off-by: Mark Rutland <mark.rutland@arm.com>

Stared at and verified the architecture bits used in here:

Reviewed-by: Andre Przywara <andre.przywara@arm.com>

Cheers,
Andre

> ---
>  arch/aarch64/include/asm/cpu.h    | 41 ++++++++++++++++++++++---------
>  arch/aarch64/include/asm/gic-v3.h | 10 +++-----
>  2 files changed, 32 insertions(+), 19 deletions(-)
> 
> diff --git a/arch/aarch64/include/asm/cpu.h b/arch/aarch64/include/asm/cpu.h
> index 63eb1c3..1053414 100644
> --- a/arch/aarch64/include/asm/cpu.h
> +++ b/arch/aarch64/include/asm/cpu.h
> @@ -9,10 +9,14 @@
>  #ifndef __ASM_AARCH64_CPU_H
>  #define __ASM_AARCH64_CPU_H
>  
> +#include <bits.h>
> +
>  #define MPIDR_ID_BITS		0xff00ffffff
>  
>  #define CURRENTEL_EL3		(3 << 2)
>  
> +#define ID_AA64PFR0_EL1_GIC	BITS(27, 24)
> +
>  /*
>   * RES1 bits,  little-endian, caches and MMU off, no alignment checking,
>   * no WXN.
> @@ -29,6 +33,12 @@
>  
>  #define CPTR_EL3_EZ		(1 << 8)
>  
> +#define ICC_SRE_EL2		S3_4_C12_C9_5
> +#define ICC_SRE_EL3		S3_6_C12_C12_5
> +#define ICC_CTLR_EL1		S3_0_C12_C12_4
> +#define ICC_CTLR_EL3		S3_6_C12_C12_4
> +#define ICC_PMR_EL1		S3_0_C4_C6_0
> +
>  #define ZCR_EL3			s3_6_c1_c2_0
>  #define ZCR_EL3_LEN_MASK	0x1ff
>  
> @@ -50,20 +60,27 @@
>  
>  #define sevl()		asm volatile ("sevl\n" : : : "memory")
>  
> -static inline unsigned long read_mpidr(void)
> -{
> -	unsigned long mpidr;
> +#define __str(def)	#def
>  
> -	asm volatile ("mrs	%0, mpidr_el1\n" : "=r" (mpidr));
> -	return mpidr & MPIDR_ID_BITS;
> -}
> +#define mrs(reg)							\
> +({									\
> +	unsigned long __mrs_val;					\
> +	asm volatile("mrs %0, " __str(reg) : "=r" (__mrs_val));		\
> +	__mrs_val;							\
> +})
>  
> -static inline uint64_t read_id_aa64pfr0(void)
> -{
> -	uint64_t val;
> +#define msr(reg, val)							\
> +do {									\
> +	unsigned long __msr_val = val;					\
> +	asm volatile("msr " __str(reg) ", %0" : : "r" (__msr_val));	\
> +} while (0)
> +
> +#define mrs_field(reg, field) \
> +	BITS_EXTRACT(mrs(reg), (reg##_##field))
>  
> -	asm volatile ("mrs	%0, id_aa64pfr0_el1\n" : "=r" (val));
> -	return val;
> +static inline unsigned long read_mpidr(void)
> +{
> +	return mrs(mpidr_el1) & MPIDR_ID_BITS;
>  }
>  
>  static inline void iciallu(void)
> @@ -73,7 +90,7 @@ static inline void iciallu(void)
>  
>  static inline int has_gicv3_sysreg(void)
>  {
> -	return !!((read_id_aa64pfr0() >> 24) & 0xf);
> +	return !!mrs_field(ID_AA64PFR0_EL1, GIC);
>  }
>  
>  #endif /* !__ASSEMBLY__ */
> diff --git a/arch/aarch64/include/asm/gic-v3.h b/arch/aarch64/include/asm/gic-v3.h
> index 5b32380..2447480 100644
> --- a/arch/aarch64/include/asm/gic-v3.h
> +++ b/arch/aarch64/include/asm/gic-v3.h
> @@ -9,20 +9,16 @@
>  #ifndef __ASM_AARCH64_GICV3_H
>  #define __ASM_AARCH64_GICV3_H
>  
> -#define ICC_SRE_EL2	"S3_4_C12_C9_5"
> -#define ICC_SRE_EL3	"S3_6_C12_C12_5"
> -#define ICC_CTLR_EL1	"S3_0_C12_C12_4"
> -#define ICC_CTLR_EL3	"S3_6_C12_C12_4"
> -#define ICC_PMR_EL1	"S3_0_C4_C6_0"
> +#include <asm/cpu.h>
>  
>  static inline void gic_write_icc_sre(uint32_t val)
>  {
> -	asm volatile ("msr " ICC_SRE_EL3 ", %0" : : "r" (val));
> +	msr(ICC_SRE_EL3, val);
>  }
>  
>  static inline void gic_write_icc_ctlr(uint32_t val)
>  {
> -	asm volatile ("msr " ICC_CTLR_EL3 ", %0" : : "r" (val));
> +	msr(ICC_CTLR_EL3, val);
>  }
>  
>  #endif


_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel

  reply	other threads:[~2022-01-14 15:33 UTC|newest]

Thread overview: 43+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2022-01-14 10:56 [bootwrapper PATCH v2 00/13] Cleanups and improvements Mark Rutland
2022-01-14 10:56 ` [bootwrapper PATCH v2 01/13] Document entry requirements Mark Rutland
2022-01-14 10:56 ` [bootwrapper PATCH v2 02/13] Add bit-field macros Mark Rutland
2022-01-17 12:11   ` Steven Price
2022-01-17 13:28     ` Mark Rutland
2022-01-14 10:56 ` [bootwrapper PATCH v2 03/13] aarch64: add system register accessors Mark Rutland
2022-01-14 15:32   ` Andre Przywara [this message]
2022-01-14 10:56 ` [bootwrapper PATCH v2 04/13] aarch32: add coprocessor accessors Mark Rutland
2022-01-14 10:56 ` [bootwrapper PATCH v2 05/13] aarch64: add mov_64 macro Mark Rutland
2022-01-14 15:50   ` Andre Przywara
2022-01-14 10:56 ` [bootwrapper PATCH v2 06/13] aarch64: initialize SCTLR_ELx for the boot-wrapper Mark Rutland
2022-01-14 18:12   ` Andre Przywara
2022-01-17 12:15     ` Mark Rutland
2022-01-17 13:05       ` Mark Rutland
2022-01-18 12:37         ` Andre Przywara
2022-01-25 13:32           ` Mark Rutland
2022-01-19 12:42       ` Mark Rutland
2022-01-14 10:56 ` [bootwrapper PATCH v2 07/13] Rework common init C code Mark Rutland
2022-01-17 16:23   ` Andre Przywara
2022-01-14 10:56 ` [bootwrapper PATCH v2 08/13] Announce boot-wrapper mode / exception level Mark Rutland
2022-01-17 14:39   ` Andre Przywara
2022-01-17 15:50     ` Mark Rutland
2022-01-14 10:56 ` [bootwrapper PATCH v2 09/13] aarch64: move the bulk of EL3 initialization to C Mark Rutland
2022-01-17 14:31   ` Andre Przywara
2022-01-17 18:08     ` Mark Rutland
2022-01-17 18:31       ` Andre Przywara
2022-01-18 16:50         ` Mark Brown
2022-01-19 15:22           ` Mark Rutland
2022-01-14 10:56 ` [bootwrapper PATCH v2 10/13] aarch32: move the bulk of Secure PL1 " Mark Rutland
2022-01-17 14:52   ` Andre Przywara
2022-01-14 10:56 ` [bootwrapper PATCH v2 11/13] Announce locations of memory objects Mark Rutland
2022-01-14 15:30   ` Andre Przywara
2022-01-14 16:04     ` Robin Murphy
2022-01-14 16:30       ` Mark Rutland
2022-01-14 16:21     ` Mark Rutland
2022-01-17 14:59   ` Andre Przywara
2022-01-14 10:56 ` [bootwrapper PATCH v2 12/13] Rework bootmethod initialization Mark Rutland
2022-01-17 17:43   ` Andre Przywara
2022-01-25 14:00     ` Mark Rutland
2022-01-14 10:56 ` [bootwrapper PATCH v2 13/13] Unify start_el3 & start_no_el3 Mark Rutland
2022-01-17 17:43   ` Andre Przywara
2022-01-14 15:09 ` [bootwrapper PATCH v2 00/13] Cleanups and improvements Andre Przywara
2022-01-14 15:23   ` Mark Rutland

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20220114153227.3f2a2d09@donnerap.cambridge.arm.com \
    --to=andre.przywara@arm.com \
    --cc=Jaxson.Han@arm.com \
    --cc=Wei.Chen@arm.com \
    --cc=linux-arm-kernel@lists.infradead.org \
    --cc=mark.rutland@arm.com \
    --cc=robin.murphy@arm.com \
    --cc=vladimir.murzin@arm.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.