From: Nikos Nikoleris <nikos.nikoleris@arm.com>
To: Andrew Jones <drjones@redhat.com>,
Alexandru Elisei <alexandru.elisei@arm.com>
Cc: kvm@vger.kernel.org, mark.rutland@arm.com, jade.alglave@arm.com,
luc.maranget@inria.fr, andre.przywara@arm.com
Subject: Re: [kvm-unit-tests PATCH 2/2] arm64: Check if the configured translation granule is supported
Date: Tue, 3 Nov 2020 18:14:53 +0000 [thread overview]
Message-ID: <cdfbfe16-ac54-aba0-4aa3-4933759175dc@arm.com> (raw)
In-Reply-To: <20201103173604.az5ymaw576uz6645@kamzik.brq.redhat.com>
On 03/11/2020 17:36, Andrew Jones wrote:
> On Tue, Nov 03, 2020 at 05:03:15PM +0000, Alexandru Elisei wrote:
>>> +}
>>> +
>>> +static inline bool system_supports_granule(size_t granule)
>>> +{
>>> + u64 mmfr0 = get_id_aa64mmfr0_el1();
>>> +
>>> + return ((granule == SZ_4K && ((mmfr0 >> 28) & 0xf) == 0) ||
>>> + (granule == SZ_64K && ((mmfr0 >> 24) & 0xf) == 0) ||
>>> + (granule == SZ_16K && ((mmfr0 >> 20) & 0xf) == 1));
>>> +}
>>
>> Or we can turn it into a switch statement and keep all the field defines. Either
>> way looks good to me (funny how tgran16 stands out).
>>
>
> Keeping the defines is probably a good idea. Whether the function uses
> a switch or an expression like above doesn't matter to me much. Keeping
> LOC down in the lib/ code is a goal of kvm-unit-tests, but so is
> readabilty. If the switch looks better, then let's go that way.
>
I liked Drew's version in that it was very concise. The new version will
be much longer. If you think it's more readable I'll use that instead.
diff --git a/lib/arm64/asm/processor.h b/lib/arm64/asm/processor.h
index 02665b8..430ded3 100644
--- a/lib/arm64/asm/processor.h
+++ b/lib/arm64/asm/processor.h
@@ -117,5 +117,38 @@ static inline u64 get_ctr(void)
extern u32 dcache_line_size;
+static inline unsigned long get_id_aa64mmfr0_el1(void)
+{
+ return read_sysreg(id_aa64mmfr0_el1);
+}
+
+#define ID_AA64MMFR0_TGRAN4_SHIFT 28
+#define ID_AA64MMFR0_TGRAN64_SHIFT 24
+#define ID_AA64MMFR0_TGRAN16_SHIFT 20
+
+#define ID_AA64MMFR0_TGRAN4_SUPPORTED 0x0
+#define ID_AA64MMFR0_TGRAN64_SUPPORTED 0x0
+#define ID_AA64MMFR0_TGRAN16_SUPPORTED 0x1
+
+static inline bool system_supports_granule(size_t granule)
+{
+ u32 shift;
+ u32 val;
+ u64 mmfr0 = get_id_aa64mmfr0_el1();
+ if (granule == SZ_4K) {
+ shift = ID_AA64MMFR0_TGRAN4_SHIFT;
+ val = ID_AA64MMFR0_TGRAN4_SUPPORTED;
+ } else if (granule == SZ_16K) {
+ shift = ID_AA64MMFR0_TGRAN16_SHIFT;
+ val = ID_AA64MMFR0_TGRAN16_SUPPORTED;
+ } else {
+ assert(granule == SZ_64K);
+ shift = ID_AA64MMFR0_TGRAN64_SHIFT;
+ val = ID_AA64MMFR0_TGRAN64_SUPPORTED;
+ }
+
+ return ((mmfr0 >> shift) & 0xf) == val;
+}
+
#endif /* !__ASSEMBLY__ */
#endif /* _ASMARM64_PROCESSOR_H_ */
Thanks,
Nikos
> Thanks,
> drew
>
next prev parent reply other threads:[~2020-11-03 18:14 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2020-11-02 11:34 [kvm-unit-tests PATCH 0/2] arm64: Add support for configuring the translation granule Nikos Nikoleris
2020-11-02 11:34 ` [kvm-unit-tests PATCH 1/2] " Nikos Nikoleris
2020-11-03 13:04 ` Andrew Jones
2020-11-03 15:49 ` Nikos Nikoleris
2020-11-03 16:10 ` Andrew Jones
2020-11-03 16:25 ` Alexandru Elisei
2020-11-03 16:39 ` Andrew Jones
2020-11-03 16:46 ` Alexandru Elisei
2020-11-03 16:21 ` Alexandru Elisei
2020-11-03 17:14 ` Nikos Nikoleris
2020-11-02 11:34 ` [kvm-unit-tests PATCH 2/2] arm64: Check if the configured translation granule is supported Nikos Nikoleris
2020-11-03 10:02 ` Andrew Jones
2020-11-03 10:21 ` Nikos Nikoleris
2020-11-03 17:03 ` Alexandru Elisei
2020-11-03 17:36 ` Andrew Jones
2020-11-03 18:14 ` Nikos Nikoleris [this message]
2020-11-03 18:23 ` Andrew Jones
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=cdfbfe16-ac54-aba0-4aa3-4933759175dc@arm.com \
--to=nikos.nikoleris@arm.com \
--cc=alexandru.elisei@arm.com \
--cc=andre.przywara@arm.com \
--cc=drjones@redhat.com \
--cc=jade.alglave@arm.com \
--cc=kvm@vger.kernel.org \
--cc=luc.maranget@inria.fr \
--cc=mark.rutland@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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).