From nobody Wed Dec 11 17:47:51 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 4Y7jjz6MPbz5gFrp; Wed, 11 Dec 2024 17:47:51 +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 4Y7jjz5kgQz4L2B; Wed, 11 Dec 2024 17:47:51 +0000 (UTC) (envelope-from git@FreeBSD.org) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733939271; 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=MRFbsrre7pm6S5l6omvnpe6Eg7q3l5zrZeXL4J29sCk=; b=SxOehDwo3Fup0SpgDoUaVza164SYihx2zUYgnetr/f4vTSF7cuujzMytB3Ad0jeL2fxiLW mJOSTmLGA6gSgZHYs6/4XMiXHYWFBrCW4bpyVJ2qnc8QqrZDGTu47/4IyPh2l2AaIBpAEf xtVg6SYgx/LfVU2ER9v2+o0dCwp7lR82KfILfRR/78ods5+TAZMeN/wUcqfbRlZZDnKTlh Tv+6Cd1vTVKExKcUTOi4A57EDaPTSs2nNGy2czqvEJLQSpl0ilcIUu8JbXdZwc6dwG7SWC gDXM4G3Zm+vFE+qyrrGhQ/LsZSolM+QCjZ4yiE505VKKExRW+xMN6EZ8elE/KA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=freebsd.org; s=dkim; t=1733939271; 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=MRFbsrre7pm6S5l6omvnpe6Eg7q3l5zrZeXL4J29sCk=; b=XxDPViTwVIOsDJkuGpGLpduG9rWme7dXXO5nBs/C/peGT1W0RujXdfU0dTlPrAKAHC6tT9 mmdukETdW4fxCwvLAafO/mbTjGXFTZCFKCgEUhkRoVHUZJ91A4WENV/qNzbLAdlULGOLsJ cD1oHRVvyal2+GmG9VOY09soJNwln29bD61l1b04NqE/28hInYGytCwxUtGth/1ZIL9JiV gsmtbOSYqUnvzAKfIX4YEXJhisFFQ7YfeK9PE4nYQRSsQugO6W1nhxNfjLu7lmbP8/PItF TE5S7NQzdkil15/R9cRmz2zpw86KOET44grk0aiHtlcRk4fd7S8w7Yjf5UDtDg== ARC-Authentication-Results: i=1; mx1.freebsd.org; none ARC-Seal: i=1; s=dkim; d=freebsd.org; t=1733939271; a=rsa-sha256; cv=none; b=x6XaC01rF8SmkWaJfJIvaRQK2W/DFZEciRvunicxGnWvuXBC8FFeLSZ3ZbVmtgWo+vGo2C cu4yGhdNNV7+pgT2Ae075xU6qMaQeVNlqdmgbVPuxe5ILlFH120IPezht+R5/+njJxGR/+ BDYvauOWlzsoEq3Svbxv+mV0IuTsQCeTou4qejWir0JXeV/soEYWLxCZ7BrX4G50uRmG5X EyR7rYxmjYdt7gjChdSukYYm2FNfWDJNj4o3uK3fXsq5LhlCZEH5nEr0krWscpSFNV0V9K 7BajAFjeN6VXrmIuPjf8Y2R1RUAYwrHR+9DNG0aW1v9YjsvxwSjYK9BF3sglig== 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 4Y7jjz5KTxzJ2T; Wed, 11 Dec 2024 17:47:51 +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 4BBHlpMG049249; Wed, 11 Dec 2024 17:47:51 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.18.1/8.18.1/Submit) id 4BBHlpjI049245; Wed, 11 Dec 2024 17:47:51 GMT (envelope-from git) Date: Wed, 11 Dec 2024 17:47:51 GMT Message-Id: <202412111747.4BBHlpjI049245@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: 4056e774b1b3 - main - arm64: Move setting TCR_HD to C code 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: 4056e774b1b3b07db83fcf3dea2e62d0bf02cd9b Auto-Submitted: auto-generated The branch main has been updated by andrew: URL: https://cgit.FreeBSD.org/src/commit/?id=4056e774b1b3b07db83fcf3dea2e62d0bf02cd9b commit 4056e774b1b3b07db83fcf3dea2e62d0bf02cd9b Author: Andrew Turner AuthorDate: 2024-12-11 15:48:56 +0000 Commit: Andrew Turner CommitDate: 2024-12-11 17:02:24 +0000 arm64: Move setting TCR_HD to C code To allow for it to be more selective when we enable it, e.g. if the CPU has an erratum that prevents us from doing so, move the check for setting TCR_HD to C. Reviewed by: alc Sponsored by: Arm Ltd Differential Revision: https://reviews.freebsd.org/D47808 --- sys/arm64/arm64/locore.S | 17 +++++++---------- sys/arm64/arm64/mp_machdep.c | 1 + sys/arm64/arm64/pmap.c | 21 +++++++++++++++++++++ sys/arm64/include/pmap.h | 1 + 4 files changed, 30 insertions(+), 10 deletions(-) diff --git a/sys/arm64/arm64/locore.S b/sys/arm64/arm64/locore.S index f9a179931d7d..e721092455e8 100644 --- a/sys/arm64/arm64/locore.S +++ b/sys/arm64/arm64/locore.S @@ -940,20 +940,17 @@ LENTRY(start_mmu) bfi x2, x3, #(TCR_ASID_SHIFT), #(TCR_ASID_WIDTH) /* - * Check if the HW supports access flag and dirty state updates, - * and set TCR_EL1.HA and TCR_EL1.HD accordingly. + * Check if the HW supports access flag updates, and set + * TCR_EL1.HA accordingly. The TCR_EL1.HD flag to enable + * HW management of dirty state is set in C code as it may + * need to be disabled because of CPU errata. */ mrs x3, id_aa64mmfr1_el1 and x3, x3, #(ID_AA64MMFR1_HAFDBS_MASK) - cmp x3, #1 - b.ne 1f - orr x2, x2, #(TCR_HA) - b 2f + cbz x3, 1f + orr x2, x2, #(TCR_HA) 1: - cmp x3, #2 - b.ne 2f - orr x2, x2, #(TCR_HA | TCR_HD) -2: + msr tcr_el1, x2 /* diff --git a/sys/arm64/arm64/mp_machdep.c b/sys/arm64/arm64/mp_machdep.c index e9b015443477..636f26fba939 100644 --- a/sys/arm64/arm64/mp_machdep.c +++ b/sys/arm64/arm64/mp_machdep.c @@ -219,6 +219,7 @@ init_secondary(uint64_t cpu) pcpup = cpuid_to_pcpu[cpu]; pcpup->pc_midr = get_midr(); identify_cpu(cpu); + pmap_cpu_init(); /* Ensure the stores in identify_cpu have completed */ atomic_thread_fence_acq_rel(); diff --git a/sys/arm64/arm64/pmap.c b/sys/arm64/arm64/pmap.c index 17e34888282a..b8f519388977 100644 --- a/sys/arm64/arm64/pmap.c +++ b/sys/arm64/arm64/pmap.c @@ -1309,6 +1309,8 @@ pmap_bootstrap(vm_size_t kernlen) vm_paddr_t start_pa, pa; uint64_t tcr; + pmap_cpu_init(); + tcr = READ_SPECIALREG(tcr_el1); /* Verify that the ASID is set through TTBR0. */ @@ -1623,6 +1625,25 @@ pmap_init_pv_table(void) } } +void +pmap_cpu_init(void) +{ + uint64_t id_aa64mmfr1, tcr; + + /* Enable HAFDBS if supported */ + id_aa64mmfr1 = READ_SPECIALREG(id_aa64mmfr1_el1); + if (ID_AA64MMFR1_HAFDBS_VAL(id_aa64mmfr1) >=ID_AA64MMFR1_HAFDBS_AF_DBS){ + tcr = READ_SPECIALREG(tcr_el1) | TCR_HD; + WRITE_SPECIALREG(tcr_el1, tcr); + isb(); + /* Flush the local TLB for the TCR_HD flag change */ + dsb(nshst); + __asm __volatile("tlbi vmalle1"); + dsb(nsh); + isb(); + } +} + /* * Initialize the pmap module. * diff --git a/sys/arm64/include/pmap.h b/sys/arm64/include/pmap.h index 8bdb4cf025e3..d92069ee42fd 100644 --- a/sys/arm64/include/pmap.h +++ b/sys/arm64/include/pmap.h @@ -140,6 +140,7 @@ extern pt_entry_t pmap_sh_attr; void pmap_activate_vm(pmap_t); void pmap_bootstrap(vm_size_t); +void pmap_cpu_init(void); int pmap_change_attr(vm_offset_t va, vm_size_t size, int mode); int pmap_change_prot(vm_offset_t va, vm_size_t size, vm_prot_t prot); void pmap_kenter(vm_offset_t sva, vm_size_t size, vm_paddr_t pa, int mode);