From nobody Mon Oct 21 12:24:21 2024 X-Original-To: dev-commits-src-main@mlmmj.nyi.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mlmmj.nyi.freebsd.org (Postfix) with ESMTP id 4XXDyF5p69z5YwtG; Mon, 21 Oct 2024 12:24:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256 client-signature RSA-PSS (4096 bits) client-digest SHA256) (Client CN "mxrelay.nyi.freebsd.org", Issuer "R11" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XXDyF4cwcz4DYZ; Mon, 21 Oct 2024 12:24:21 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729513461; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FovurKEwWI9abme7bA1Sid/+aH19aoz/MH//Ah0ILvY=; b=ARkcMzJciyvMBsoC0CGV1ENllMN+0kV+eqowhY5XHrhLmai+TFa0K4vR6RbjZf0h9CN4U2 PCZheB4x8CqwCo1zc4hpHTMGfpordOxwcx8gyDH8xfx9WouUTKFFU9t4KEaI2K9OSE2AVu B3lemSCUfAirB5uMST3y38b94Ckx0CEoBrnpe8K+Bps1SUUmn1XESD/Cz05sPC2y7pzmVs gZNpVD4JJYG9YPktcdZ6Df2cKw/D1HznUEpA8WIB32OSrRlw6pk3KAhLKkT3jMJJL0Nczi gtMG/0RCmWVQ3mg/az5YiWwlW9hF+GLYverjT1U8eKSONKOepGp7S5OkLS2B+Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1729513461; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding; bh=FovurKEwWI9abme7bA1Sid/+aH19aoz/MH//Ah0ILvY=; b=URgFuHXzvr1Cr6Nf3Dai9QRs6hkyzxOUk5gVk3IsiblB8koLXx8DbJ9fKxTD/0T6+74syi YFgSI9DYzQzkebA5O+Z865tI1GiTf7nx53UIr7XwqEyzp++MmHn8THo/1pClFjXZEe0PL5 XqXRCk1ZsJQ+0x5VQZUeQQcvXjARHu0FCls59ueEdfFrnDkhmV7THs8XebkfCGP96xkxUC 2zmhtCohZV1ukgngtdTPPaZu6TcxKaTHApTzL5aw4WLx15np0oHwJJI2Od69BO5m/pZsH0 mtC+JOk2sA3LLnVkZrPzvv9Ufad3Lg3W94AOXVPp0JEzc4pbUC9GYypX/LfafA== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1729513461; a=rsa-sha256; cv=none; b=xO0Vhi82xM9IIAkFknCgvJMAWsIv6wHVajsnCALXNqdM3Lwjzk9iR0Cjk7LksZ2hlwJGLv efd1F4Ta4VbQkJ1x6bjGkIIrtR8ds/1jiOOeS0BFZV3wdUXN2dEPVqcacMtmOTfUX0somc bYUJPpgOTMYnABOFheGbk0UjZfRPdLs5WMPLn8Z877Zfe7FxgG2tRmL3dQQ/nXQvjA8wPg AQU5zR0Rnw1im14o3EoP/ZPH3dpwJSAXqUXsCERnHnVqeKavpaQFYRGNfTRckijQ6+coVa d6pgAExQVOScUwdI29W7lrlcywT23Dja8ZnzR4xotwlC+qEYhGQzyZo0MgZVbg== Received: from gitrepo.freebsd.org (gitrepo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:5]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id 4XXDyF466dzVr7; Mon, 21 Oct 2024 12:24:21 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.18.1/8.18.1) with ESMTP id 49LCOLXv049163; Mon, 21 Oct 2024 12:24:21 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 49LCOLUs049160; Mon, 21 Oct 2024 12:24:21 GMT (envelope-from git) Date: Mon, 21 Oct 2024 12:24:21 GMT Message-Id: <202410211224.49LCOLUs049160@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Andrew Turner Subject: git: a090372f38f1 - main - arm64: Decode CTR_EL0 via a table List-Id: Commit messages for the main branch of the src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-main List-Help: List-Post: List-Subscribe: List-Unsubscribe: X-BeenThere: dev-commits-src-main@freebsd.org Sender: owner-dev-commits-src-main@FreeBSD.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: andrew X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: a090372f38f1cc136323599f92d0acecfca5b40e Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=a090372f38f1cc136323599f92d0acecfca5b40e commit a090372f38f1cc136323599f92d0acecfca5b40e Author: Andrew Turner AuthorDate: 2024-10-18 09:17:08 +0000 Commit: Andrew Turner CommitDate: 2024-10-21 12:23:15 +0000 arm64: Decode CTR_EL0 via a table Use the same method to decode CTR_EL0 as for the ID registers. This will allow us to create a common view over all CPUs. This will also allow us to create a common view for userspace and the kernel if we detect a difference on some CPUs, or to handle errata. Reviewed by: imp Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D47124 --- sys/arm64/arm64/identcpu.c | 118 ++++++++++++++++++++++++++++++--------------- sys/arm64/include/armreg.h | 11 +++++ 2 files changed, 91 insertions(+), 38 deletions(-) diff --git a/sys/arm64/arm64/identcpu.c b/sys/arm64/arm64/identcpu.c index 126df01edfa3..7c5fdc04fdc7 100644 --- a/sys/arm64/arm64/identcpu.c +++ b/sys/arm64/arm64/identcpu.c @@ -337,6 +337,28 @@ struct mrs_field_value { MRS_FIELD_VALUE(14ul<< _reg ## _ ## _field ## _SHIFT, "15 "_desc "s"), \ MRS_FIELD_VALUE(15ul<< _reg ## _ ## _field ## _SHIFT, "16 "_desc "s") +/* + * Used for printing I/D cache line sizes & CWG/ERG, as 0 is a special case + * in some cases the decoded string needs to be passed in. + */ +#define MRS_FIELD_VALUE_CACHE(_reg, _field, _0desc, _desc) \ + MRS_FIELD_VALUE(0ul << _reg ## _ ## _field ## _SHIFT, _0desc), \ + MRS_FIELD_VALUE(1ul << _reg ## _ ## _field ## _SHIFT, "8 " _desc), \ + MRS_FIELD_VALUE(2ul << _reg ## _ ## _field ## _SHIFT, "16 " _desc), \ + MRS_FIELD_VALUE(3ul << _reg ## _ ## _field ## _SHIFT, "32 " _desc), \ + MRS_FIELD_VALUE(4ul << _reg ## _ ## _field ## _SHIFT, "64 " _desc), \ + MRS_FIELD_VALUE(5ul << _reg ## _ ## _field ## _SHIFT, "128 " _desc), \ + MRS_FIELD_VALUE(6ul << _reg ## _ ## _field ## _SHIFT, "256 " _desc), \ + MRS_FIELD_VALUE(7ul << _reg ## _ ## _field ## _SHIFT, "512 " _desc), \ + MRS_FIELD_VALUE(8ul << _reg ## _ ## _field ## _SHIFT, "1k " _desc), \ + MRS_FIELD_VALUE(9ul << _reg ## _ ## _field ## _SHIFT, "2k " _desc), \ + MRS_FIELD_VALUE(10ul<< _reg ## _ ## _field ## _SHIFT, "4k " _desc), \ + MRS_FIELD_VALUE(11ul<< _reg ## _ ## _field ## _SHIFT, "8k " _desc), \ + MRS_FIELD_VALUE(12ul<< _reg ## _ ## _field ## _SHIFT, "16k " _desc), \ + MRS_FIELD_VALUE(13ul<< _reg ## _ ## _field ## _SHIFT, "32k " _desc), \ + MRS_FIELD_VALUE(14ul<< _reg ## _ ## _field ## _SHIFT, "64k " _desc), \ + MRS_FIELD_VALUE(15ul<< _reg ## _ ## _field ## _SHIFT, "128k "_desc) + #define MRS_FIELD_VALUE_END { .desc = NULL } struct mrs_field_hwcap { @@ -393,6 +415,62 @@ struct mrs_field { #define MRS_FIELD_END { .type = MRS_INVALID, } +/* CTR_EL0 */ +static const struct mrs_field_value ctr_dic[] = { + MRS_FIELD_VALUE_NONE_IMPL(CTR, DIC, NONE, IMPL), + MRS_FIELD_VALUE_END, +}; + +static const struct mrs_field_value ctr_idc[] = { + MRS_FIELD_VALUE_NONE_IMPL(CTR, IDC, NONE, IMPL), + MRS_FIELD_VALUE_END, +}; + +static const struct mrs_field_value ctr_cwg[] = { + MRS_FIELD_VALUE_CACHE(CTR, CWG, "Unknown CWG", + "byte CWG"), + MRS_FIELD_VALUE_END, +}; + +static const struct mrs_field_value ctr_erg[] = { + MRS_FIELD_VALUE_CACHE(CTR, ERG, "Unknown ERG", + "byte ERG"), + MRS_FIELD_VALUE_END, +}; + +static const struct mrs_field_value ctr_dline[] = { + MRS_FIELD_VALUE_CACHE(CTR, DLINE, "4 byte D-cacheline", + "byte D-cacheline"), + MRS_FIELD_VALUE_END, +}; + +static const struct mrs_field_value ctr_l1ip[] = { + MRS_FIELD_VALUE(CTR_L1IP_VIPT, "VIPT I-cache"), + MRS_FIELD_VALUE(CTR_L1IP_PIPT, "PIPT I-cache"), + MRS_FIELD_VALUE_END, +}; + +static const struct mrs_field_value ctr_iline[] = { + MRS_FIELD_VALUE_CACHE(CTR, ILINE, "4 byte I-cacheline", + "byte I-cacheline"), + MRS_FIELD_VALUE_END, +}; + +static const struct mrs_field ctr_fields[] = { + /* Bit 31 is RES1 */ + MRS_FIELD_RES1(1, 31), + MRS_FIELD(CTR, DIC, false, MRS_LOWER, MRS_USERSPACE, ctr_dic), + MRS_FIELD(CTR, IDC, false, MRS_LOWER, MRS_USERSPACE, ctr_idc), + MRS_FIELD(CTR, CWG, false, MRS_HIGHER_OR_ZERO, MRS_USERSPACE, ctr_cwg), + MRS_FIELD(CTR, ERG, false, MRS_HIGHER_OR_ZERO, MRS_USERSPACE, ctr_erg), + MRS_FIELD(CTR, DLINE, false, MRS_LOWER, MRS_USERSPACE, ctr_dline), + /* If the ICache types are different report the safe option */ + MRS_FIELD(CTR, L1IP, false, MRS_EXACT_IF_DIFFERENT | + MRS_SAFE(CTR_L1IP_VIPT >> CTR_L1IP_SHIFT), MRS_USERSPACE, + ctr_l1ip), + MRS_FIELD(CTR, ILINE, false, MRS_LOWER, MRS_USERSPACE, ctr_iline), + MRS_FIELD_END, +}; /* ID_AA64AFR0_EL1 */ static const struct mrs_field id_aa64afr0_fields[] = { @@ -2497,40 +2575,6 @@ parse_cpu_features_hwcap32(void) } #endif /* COMPAT_FREEBSD32 */ -static void -print_ctr_fields(struct sbuf *sb, uint64_t reg, const void *arg __unused) -{ - - sbuf_printf(sb, "%u byte D-cacheline,", CTR_DLINE_SIZE(reg)); - sbuf_printf(sb, "%u byte I-cacheline,", CTR_ILINE_SIZE(reg)); - reg &= ~(CTR_DLINE_MASK | CTR_ILINE_MASK); - - switch(CTR_L1IP_VAL(reg)) { - case CTR_L1IP_VIPT: - sbuf_printf(sb, "VIPT"); - break; - case CTR_L1IP_PIPT: - sbuf_printf(sb, "PIPT"); - break; - } - sbuf_printf(sb, " ICache,"); - reg &= ~CTR_L1IP_MASK; - - sbuf_printf(sb, "%d byte ERG,", CTR_ERG_SIZE(reg)); - sbuf_printf(sb, "%d byte CWG", CTR_CWG_SIZE(reg)); - reg &= ~(CTR_ERG_MASK | CTR_CWG_MASK); - - if (CTR_IDC_VAL(reg) != 0) - sbuf_printf(sb, ",IDC"); - if (CTR_DIC_VAL(reg) != 0) - sbuf_printf(sb, ",DIC"); - reg &= ~(CTR_IDC_MASK | CTR_DIC_MASK); - reg &= ~CTR_RES1; - - if (reg != 0) - sbuf_printf(sb, ",%lx", reg); -} - static void print_register(struct sbuf *sb, const char *reg_name, uint64_t reg, void (*print_fields)(struct sbuf *, uint64_t, const void *), @@ -2754,10 +2798,8 @@ print_cpu_features(u_int cpu, struct cpu_desc *desc, (prev_desc == NULL || desc->_reg != prev_desc->_reg) /* Cache Type Register */ - if (SHOULD_PRINT_REG(ctr)) { - print_register(sb, "Cache Type", - desc->ctr, print_ctr_fields, NULL); - } + if (SHOULD_PRINT_REG(ctr)) + print_id_register(sb, "Cache Type", desc->ctr, ctr_fields); /* AArch64 Instruction Set Attribute Register 0 */ if (SHOULD_PRINT_REG(id_aa64isar0)) diff --git a/sys/arm64/include/armreg.h b/sys/arm64/include/armreg.h index 7d2fffb28779..e26f9859947e 100644 --- a/sys/arm64/include/armreg.h +++ b/sys/arm64/include/armreg.h @@ -368,29 +368,40 @@ #define CTR_TminLine_MASK (UL(0x3f) << CTR_TminLine_SHIFT) #define CTR_TminLine_VAL(reg) ((reg) & CTR_TminLine_MASK) #define CTR_DIC_SHIFT 29 +#define CTR_DIC_WIDTH 1 #define CTR_DIC_MASK (0x1 << CTR_DIC_SHIFT) #define CTR_DIC_VAL(reg) ((reg) & CTR_DIC_MASK) +#define CTR_DIC_NONE (0x0 << CTR_DIC_SHIFT) +#define CTR_DIC_IMPL (0x1 << CTR_DIC_SHIFT) #define CTR_IDC_SHIFT 28 +#define CTR_IDC_WIDTH 1 #define CTR_IDC_MASK (0x1 << CTR_IDC_SHIFT) #define CTR_IDC_VAL(reg) ((reg) & CTR_IDC_MASK) +#define CTR_IDC_NONE (0x0 << CTR_IDC_SHIFT) +#define CTR_IDC_IMPL (0x1 << CTR_IDC_SHIFT) #define CTR_CWG_SHIFT 24 +#define CTR_CWG_WIDTH 4 #define CTR_CWG_MASK (0xf << CTR_CWG_SHIFT) #define CTR_CWG_VAL(reg) ((reg) & CTR_CWG_MASK) #define CTR_CWG_SIZE(reg) (4 << (CTR_CWG_VAL(reg) >> CTR_CWG_SHIFT)) #define CTR_ERG_SHIFT 20 +#define CTR_ERG_WIDTH 4 #define CTR_ERG_MASK (0xf << CTR_ERG_SHIFT) #define CTR_ERG_VAL(reg) ((reg) & CTR_ERG_MASK) #define CTR_ERG_SIZE(reg) (4 << (CTR_ERG_VAL(reg) >> CTR_ERG_SHIFT)) #define CTR_DLINE_SHIFT 16 +#define CTR_DLINE_WIDTH 4 #define CTR_DLINE_MASK (0xf << CTR_DLINE_SHIFT) #define CTR_DLINE_VAL(reg) ((reg) & CTR_DLINE_MASK) #define CTR_DLINE_SIZE(reg) (4 << (CTR_DLINE_VAL(reg) >> CTR_DLINE_SHIFT)) #define CTR_L1IP_SHIFT 14 +#define CTR_L1IP_WIDTH 2 #define CTR_L1IP_MASK (0x3 << CTR_L1IP_SHIFT) #define CTR_L1IP_VAL(reg) ((reg) & CTR_L1IP_MASK) #define CTR_L1IP_VIPT (2 << CTR_L1IP_SHIFT) #define CTR_L1IP_PIPT (3 << CTR_L1IP_SHIFT) #define CTR_ILINE_SHIFT 0 +#define CTR_ILINE_WIDTH 4 #define CTR_ILINE_MASK (0xf << CTR_ILINE_SHIFT) #define CTR_ILINE_VAL(reg) ((reg) & CTR_ILINE_MASK) #define CTR_ILINE_SIZE(reg) (4 << (CTR_ILINE_VAL(reg) >> CTR_ILINE_SHIFT))