From nobody Mon Nov 25 21:08:47 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 4XxyxC6khDz5fCbN; Mon, 25 Nov 2024 21:08:47 +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 "R10" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4XxyxC4GrSz4tlt; Mon, 25 Nov 2024 21:08:47 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732568927; 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=psiTXbzLXzE4IVXX2ACvwKlmWTK3kp4KuJkOiBataSo=; b=cbF7LMXB5bOb9zjVkHSmB0nIasAVEX10Pb0TYck41adCwlJaiAp+NS50JZOvx31lUHFYQz lHiH4OFqbM9mCtbXiK/svEJK+qW91H/fTbZ1ON5DfHSe6rPshKU5SGVJTHylxT3AYJfnhU MsWOe/BFoove/rojHJHTm7p/vn3QZa4hWdBefZVvKbW1j+nf7VFdZ6m2sAQdQyZmLF4IoK XhOaxMGzDGAVZ4JuOg7zRdE5xFTQUmSb6iHVdj+08ldxjQIGruRZ3qgZAgoATzd3PQWiLN 000ZA0LiTQgCTowDOLVUUe61qp7EPqvqq8jCLNJwr9uRl8fzczf1qzz/Ast4qg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1732568927; 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=psiTXbzLXzE4IVXX2ACvwKlmWTK3kp4KuJkOiBataSo=; b=mljypU+Je3jUfkHkfdorVTXk0r47sPpW6ospjQ45Gr3uKoiQqBfL8BLpv0Iykc6gsvZbD8 bsHTxZo4KZC2q1wRtyRDSCf+65OBJ7FzGB+rGOc/KgQmTbDTadIjRVfbYorALIPKwNJbxL Os4m6hFAjF4CD7bviA6/rI2Lc69rXq6MZGnCPEBf4ebs0T00nh5Cy4c4K+n0nfB1y5K5q0 nG2Guc2ro21kUYhCVjvivWBU6kBZuvL5PGm2fqzEhnNOPxo4HPn4P07ULHzpnlL6KE6RWy 2ENv7w3VTYshkEl+EyzDFfPjXGIHHbgd3dWSI5KL+5/BycP0Ea9R5qp0SAMvVw== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1732568927; a=rsa-sha256; cv=none; b=AJHmkOuTuDK0Pp4AoQqcUkC4xc2UGXs+xN58ksg22zDG4o7cOuDjVK5Lap5cqtl7ZTifC1 RK33nbz/oMbQ6FHVCISSsZcR0mIJOgD2lcwCd6uCOsYrk/8b1DCF5E0Y3wT6yBYDVwfEij 8Zuz9IXoeTaDuEpS6NBBrjrRS61xLpTNsjt/jPoYn7848oJQjesjc6bP8IkRjr/9ZEWlmu mdP9Kbg23TSVTY8saiOEpLTXq1iOU7Y+w35+ThjPOBO0G5MYU1WtSG6fUcBHGBXzQCGpYb XR+jdUShO02nXL1IVyd2cU7G/+9+BKFdgJBCKUkcMtzHOnfoiJzhD0rcX7jWww== 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 4XxyxC3sMMzwTk; Mon, 25 Nov 2024 21:08:47 +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 4APL8lk9011447; Mon, 25 Nov 2024 21:08:47 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4APL8lsh011444; Mon, 25 Nov 2024 21:08:47 GMT (envelope-from git) Date: Mon, 25 Nov 2024 21:08:47 GMT Message-Id: <202411252108.4APL8lsh011444@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-main@FreeBSD.org From: Mitchell Horne Subject: git: ccbe9a9f732e - main - riscv: T-HEAD PBMT support 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: mhorne X-Git-Repository: src X-Git-Refname: refs/heads/main X-Git-Reftype: branch X-Git-Commit: ccbe9a9f732ee2f10f252a5586309a82e6ffd1e7 Auto-Submitted: auto-generated The branch main has been updated by mhorne: URL: https://cgit.FreeBSD.org/src/commit/?id=ccbe9a9f732ee2f10f252a5586309a82e6ffd1e7 commit ccbe9a9f732ee2f10f252a5586309a82e6ffd1e7 Author: Mitchell Horne AuthorDate: 2024-11-21 18:12:12 +0000 Commit: Mitchell Horne CommitDate: 2024-11-25 21:08:04 +0000 riscv: T-HEAD PBMT support T-HEAD CPUs provide a spec-violating implementation of page-based memory types, using PTE bits [63:59]. Add basic support for this "errata", referred to in some places as an "extension". Note that this change is not enough on its own, but a workaround is needed for the bootstrap (locore) page tables as well. Reviewed by: jhb Sponsored by: The FreeBSD Foundation Differential Revision: https://reviews.freebsd.org/D45472 --- sys/riscv/include/pte.h | 26 ++++++++++++++++++++++++++ sys/riscv/include/thead.h | 2 ++ sys/riscv/riscv/identcpu.c | 1 + sys/riscv/riscv/pmap.c | 6 ++++++ sys/riscv/thead/thead.c | 2 ++ 5 files changed, 37 insertions(+) diff --git a/sys/riscv/include/pte.h b/sys/riscv/include/pte.h index 34cd2a674627..77a7817fd27e 100644 --- a/sys/riscv/include/pte.h +++ b/sys/riscv/include/pte.h @@ -102,6 +102,32 @@ typedef uint64_t pn_t; /* page number */ #define PTE_MA_NC (1ul << PTE_MA_SHIFT) #define PTE_MA_IO (2ul << PTE_MA_SHIFT) +/* + * T-HEAD Custom Memory Attribute (MA) bits [63:59]. + * + * bit 59: Trustable (relating to TEE) + * bit 60: Shareable (among CPUs, not configurable) + * bit 61: Bufferable (writes to device memory) + * bit 62: Cacheable + * bit 63: Memory Ordering (1 = strongly ordered (device), 0 = default) + * + * +------+-------+------------------------------------------------------------+ + * | Mode | Value | Requested Memory Attributes | + * +------+-------+------------------------------------------------------------+ + * | NC | 00110 | Weakly-ordered, non-cacheable, bufferable, shareable, | + * | | | non-trustable | + * | PMA | 01110 | Weakly-ordered, cacheable, bufferable, shareable, | + * | | | non-trustable | + * | IO | 10010 | Strongly-ordered, non-cacheable, non-bufferable, | + * | | | shareable, non-trustable | + * +------+-------+------------------------------------------------------------+ + */ +#define PTE_THEAD_MA_SHIFT 59 +#define PTE_THEAD_MA_MASK (0x1ful << PTE_THEAD_MA_SHIFT) +#define PTE_THEAD_MA_NC (0x6ul << PTE_THEAD_MA_SHIFT) +#define PTE_THEAD_MA_NONE (0xeul << PTE_THEAD_MA_SHIFT) +#define PTE_THEAD_MA_IO (0x12ul << PTE_THEAD_MA_SHIFT) + /* Bits 63 - 54 are reserved for future use. */ #define PTE_HI_MASK 0xFFC0000000000000ULL diff --git a/sys/riscv/include/thead.h b/sys/riscv/include/thead.h index e11d5c37374c..7d845f6660e8 100644 --- a/sys/riscv/include/thead.h +++ b/sys/riscv/include/thead.h @@ -30,6 +30,8 @@ #ifndef _RISCV_THEAD_H_ #define _RISCV_THEAD_H_ +extern bool has_errata_thead_pbmt; + void thead_setup_cache(void); #endif /* _RISCV_THEAD_H_ */ diff --git a/sys/riscv/riscv/identcpu.c b/sys/riscv/riscv/identcpu.c index f85aed88d3b9..e02907092b56 100644 --- a/sys/riscv/riscv/identcpu.c +++ b/sys/riscv/riscv/identcpu.c @@ -470,6 +470,7 @@ handle_thead_quirks(u_int cpu, struct cpu_desc *desc) if (cpu != 0) return; + has_errata_thead_pbmt = true; thead_setup_cache(); } diff --git a/sys/riscv/riscv/pmap.c b/sys/riscv/riscv/pmap.c index e11adba0d832..c8a69f9674e9 100644 --- a/sys/riscv/riscv/pmap.c +++ b/sys/riscv/riscv/pmap.c @@ -156,6 +156,7 @@ #include #include #include +#include /* * Boundary values for the page table page index space: @@ -867,6 +868,11 @@ pmap_bootstrap(vm_paddr_t kernstart, vm_size_t kernlen) memattr_bits[VM_MEMATTR_UNCACHEABLE] = PTE_MA_NC; memattr_bits[VM_MEMATTR_DEVICE] = PTE_MA_IO; memattr_mask = PTE_MA_MASK; + } else if (has_errata_thead_pbmt) { + memattr_bits[VM_MEMATTR_PMA] = PTE_THEAD_MA_NONE; + memattr_bits[VM_MEMATTR_UNCACHEABLE] = PTE_THEAD_MA_NC; + memattr_bits[VM_MEMATTR_DEVICE] = PTE_THEAD_MA_IO; + memattr_mask = PTE_THEAD_MA_MASK; } /* Create a new set of pagetables to run the kernel in. */ diff --git a/sys/riscv/thead/thead.c b/sys/riscv/thead/thead.c index f959d32cfed8..c72f4f1312e0 100644 --- a/sys/riscv/thead/thead.c +++ b/sys/riscv/thead/thead.c @@ -32,6 +32,8 @@ #include +bool has_errata_thead_pbmt = false; + /* ----------------- dcache ops --------------------- */