Hi Oliver, Ricardo, On Thu, Aug 25, 2022 at 9:58 AM Oliver Upton <oliver.upton@xxxxxxxxx> wrote: > > On Thu, Aug 25, 2022 at 09:52:53AM -0700, Ricardo Koller wrote: > > On Thu, Aug 25, 2022 at 09:48:35AM -0700, Oliver Upton wrote: > > > Hi Reiji, > > > > > > On Wed, Aug 24, 2022 at 10:08:38PM -0700, Reiji Watanabe wrote: > > > > Introduce helpers to extract a field of an ID register. > > > > Subsequent patches will use those helpers. > > > > > > > > Signed-off-by: Reiji Watanabe <reijiw@xxxxxxxxxx> > > > > --- > > > > .../selftests/kvm/include/aarch64/processor.h | 2 ++ > > > > .../testing/selftests/kvm/lib/aarch64/processor.c | 15 +++++++++++++++ > > > > 2 files changed, 17 insertions(+) > > > > > > > > diff --git a/tools/testing/selftests/kvm/include/aarch64/processor.h b/tools/testing/selftests/kvm/include/aarch64/processor.h > > > > index a8124f9dd68a..a9b4b4e0e592 100644 > > > > --- a/tools/testing/selftests/kvm/include/aarch64/processor.h > > > > +++ b/tools/testing/selftests/kvm/include/aarch64/processor.h > > > > @@ -193,4 +193,6 @@ void smccc_hvc(uint32_t function_id, uint64_t arg0, uint64_t arg1, > > > > > > > > uint32_t guest_get_vcpuid(void); > > > > > > > > +int cpuid_get_sfield(uint64_t val, int field_shift); > > > > +unsigned int cpuid_get_ufield(uint64_t val, int field_shift); > > > > #endif /* SELFTEST_KVM_PROCESSOR_H */ > > > > diff --git a/tools/testing/selftests/kvm/lib/aarch64/processor.c b/tools/testing/selftests/kvm/lib/aarch64/processor.c > > > > index 6f5551368944..0b2ad46e7ff5 100644 > > > > --- a/tools/testing/selftests/kvm/lib/aarch64/processor.c > > > > +++ b/tools/testing/selftests/kvm/lib/aarch64/processor.c > > > > @@ -528,3 +528,18 @@ void smccc_hvc(uint32_t function_id, uint64_t arg0, uint64_t arg1, > > > > [arg4] "r"(arg4), [arg5] "r"(arg5), [arg6] "r"(arg6) > > > > : "x0", "x1", "x2", "x3", "x4", "x5", "x6", "x7"); > > > > } > > > > + > > > > +/* Helpers to get a signed/unsigned feature field from ID register value */ > > > > +int cpuid_get_sfield(uint64_t val, int field_shift) > > > > +{ > > > > + int width = 4; > > > > + > > > > + return (int64_t)(val << (64 - width - field_shift)) >> (64 - width); > > > > +} > > > > > > I don't believe this helper is ever used. I thought I was going to use this in the selftest for my ID register series. (So, I originally would like to have similar helpers in cpufeture.h) But, you are right. That test only extracts unsigned fields... > > > > > > > +unsigned int cpuid_get_ufield(uint64_t val, int field_shift) > > > > +{ > > > > + int width = 4; > > > > + > > > > + return (uint64_t)(val << (64 - width - field_shift)) >> (64 - width); > > > > +} > > > > > > I would recommend not open-coding this and instead make use of > > > ARM64_FEATURE_MASK(). You could pull in linux/bitfield.h to tools, or do > > > something like this: > > > > > > #define ARM64_FEATURE_GET(ftr, val) \ > > > ((ARM64_FEATURE_MASK(ftr) & val) >> ftr##_SHIFT) > > > > > > Slight preference for FIELD_{GET,SET}() as it matches the field > > > extraction in the kernel as well. > > > > Was doing that with this commit: > > > > [PATCH v5 05/13] tools: Copy bitfield.h from the kernel sources > > > > Maybe you could just use it given that it's already reviewed. > > Oops, thanks for the reminder Ricardo! Yeah, let's go that route then. Thank you for the information. I will use that instead. Thank you, Reiji