From nobody Fri Nov 05 14:09:42 2021 X-Original-To: dev-commits-src-branches@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 5C68E184FD37; Fri, 5 Nov 2021 14:09:42 +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 "R3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 4Hm2Sk2Bv4z3lt2; Fri, 5 Nov 2021 14:09:42 +0000 (UTC) (envelope-from git@FreeBSD.org) 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 2095B187F7; Fri, 5 Nov 2021 14:09:42 +0000 (UTC) (envelope-from git@FreeBSD.org) Received: from gitrepo.freebsd.org ([127.0.1.44]) by gitrepo.freebsd.org (8.16.1/8.16.1) with ESMTP id 1A5E9gR0066319; Fri, 5 Nov 2021 14:09:42 GMT (envelope-from git@gitrepo.freebsd.org) Received: (from git@localhost) by gitrepo.freebsd.org (8.16.1/8.16.1/Submit) id 1A5E9gv7066318; Fri, 5 Nov 2021 14:09:42 GMT (envelope-from git) Date: Fri, 5 Nov 2021 14:09:42 GMT Message-Id: <202111051409.1A5E9gv7066318@gitrepo.freebsd.org> To: src-committers@FreeBSD.org, dev-commits-src-all@FreeBSD.org, dev-commits-src-branches@FreeBSD.org From: Leandro Lupori Subject: git: 84800daacf33 - stable/13 - powerpc64: fix OFWFB with Radix MMU List-Id: Commits to the stable branches of the FreeBSD src repository List-Archive: https://lists.freebsd.org/archives/dev-commits-src-branches List-Help: List-Post: List-Subscribe: List-Unsubscribe: Sender: owner-dev-commits-src-branches@freebsd.org X-BeenThere: dev-commits-src-branches@freebsd.org MIME-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 8bit X-Git-Committer: luporl X-Git-Repository: src X-Git-Refname: refs/heads/stable/13 X-Git-Reftype: branch X-Git-Commit: 84800daacf331192138b226db7d839a46fb2d642 Auto-Submitted: auto-generated X-ThisMailContainsUnwantedMimeParts: N The branch stable/13 has been updated by luporl: URL: https://cgit.FreeBSD.org/src/commit/?id=84800daacf331192138b226db7d839a46fb2d642 commit 84800daacf331192138b226db7d839a46fb2d642 Author: Leandro Lupori AuthorDate: 2021-10-14 13:39:52 +0000 Commit: Leandro Lupori CommitDate: 2021-11-05 14:08:27 +0000 powerpc64: fix OFWFB with Radix MMU Current implementation of Radix MMU doesn't support mapping arbitrary virtual addresses, such as the ones generated by "direct mapping" I/O addresses. This caused the system to hang, when early I/O addresses, such as those used by OpenFirmware Frame Buffer, were remapped after the MMU was up. To avoid having to modify mmu_radix_kenter_attr just to support this use case, this change makes early I/O map use virtual addresses from KVA area instead (similar to what mmu_radix_mapdev_attr does), as these can be safely remapped later. Reviewed by: alfredo (earlier version), jhibbits (in irc) Sponsored by: Instituto de Pesquisas Eldorado (eldorado.org.br) Differential Revision: https://reviews.freebsd.org/D31232 (cherry picked from commit 76384bd10fdbb97be2803d969905f15a84255d6a) --- sys/powerpc/aim/aim_machdep.c | 42 +++++++++++++++++++++++++++++++++--------- sys/powerpc/aim/mmu_radix.c | 8 +------- sys/powerpc/include/pmap.h | 3 +++ sys/powerpc/powerpc/machdep.c | 9 +++++++++ 4 files changed, 46 insertions(+), 16 deletions(-) diff --git a/sys/powerpc/aim/aim_machdep.c b/sys/powerpc/aim/aim_machdep.c index 784207e9a70d..bfbea09781a6 100644 --- a/sys/powerpc/aim/aim_machdep.c +++ b/sys/powerpc/aim/aim_machdep.c @@ -477,14 +477,9 @@ aim_cpu_init(vm_offset_t toc) * in case the platform module had a better idea of what we * should do. */ - if (cpu_features2 & PPC_FEATURE2_ARCH_3_00) { - radix_mmu = 0; - TUNABLE_INT_FETCH("radix_mmu", &radix_mmu); - if (radix_mmu) - pmap_mmu_install(MMU_TYPE_RADIX, BUS_PROBE_GENERIC); - else - pmap_mmu_install(MMU_TYPE_G5, BUS_PROBE_GENERIC); - } else if (cpu_features & PPC_FEATURE_64) + if (radix_mmu) + pmap_mmu_install(MMU_TYPE_RADIX, BUS_PROBE_GENERIC); + else if (cpu_features & PPC_FEATURE_64) pmap_mmu_install(MMU_TYPE_G5, BUS_PROBE_GENERIC); else pmap_mmu_install(MMU_TYPE_OEA, BUS_PROBE_GENERIC); @@ -587,6 +582,25 @@ va_to_vsid(pmap_t pm, vm_offset_t va) #endif +void +pmap_early_io_map_init(void) +{ + if ((cpu_features2 & PPC_FEATURE2_ARCH_3_00) == 0) + radix_mmu = 0; + else + TUNABLE_INT_FETCH("radix_mmu", &radix_mmu); + + /* + * When using Radix, set the start and end of kva early, to be able to + * use KVAs on pmap_early_io_map and avoid issues when remapping them + * later. + */ + if (radix_mmu) { + virtual_avail = VM_MIN_KERNEL_ADDRESS; + virtual_end = VM_MAX_SAFE_KERNEL_ADDRESS; + } +} + /* * These functions need to provide addresses that both (a) work in real mode * (or whatever mode/circumstances the kernel is in in early boot (now)) and @@ -602,10 +616,20 @@ pmap_early_io_map(vm_paddr_t pa, vm_size_t size) * If we have the MMU up in early boot, assume it is 1:1. Otherwise, * try to get the address in a memory region compatible with the * direct map for efficiency later. + * Except for Radix MMU, for which current implementation doesn't + * support mapping arbitrary virtual addresses, such as the ones + * generated by "direct mapping" I/O addresses. In this case, use + * addresses from KVA area. */ if (mfmsr() & PSL_DR) return (pa); - else + else if (radix_mmu) { + vm_offset_t va; + + va = virtual_avail; + virtual_avail += round_page(size + pa - trunc_page(pa)); + return (va); + } else return (DMAP_BASE_ADDRESS + pa); } diff --git a/sys/powerpc/aim/mmu_radix.c b/sys/powerpc/aim/mmu_radix.c index f1903c69dddb..333fa234fb4b 100644 --- a/sys/powerpc/aim/mmu_radix.c +++ b/sys/powerpc/aim/mmu_radix.c @@ -899,7 +899,7 @@ kvtopte(vm_offset_t va) pt_entry_t *l3e; l3e = pmap_pml3e(kernel_pmap, va); - if ((be64toh(*l3e) & RPTE_VALID) == 0) + if (l3e == NULL || (be64toh(*l3e) & RPTE_VALID) == 0) return (NULL); return (pmap_l3e_to_pte(l3e, va)); } @@ -2058,12 +2058,6 @@ mmu_radix_late_bootstrap(vm_offset_t start, vm_offset_t end) for (i = 0; phys_avail[i + 2] != 0; i += 2) Maxmem = MAX(Maxmem, powerpc_btop(phys_avail[i + 1])); - /* - * Set the start and end of kva. - */ - virtual_avail = VM_MIN_KERNEL_ADDRESS; - virtual_end = VM_MAX_SAFE_KERNEL_ADDRESS; - /* * Remap any early IO mappings (console framebuffer, etc.) */ diff --git a/sys/powerpc/include/pmap.h b/sys/powerpc/include/pmap.h index 2f1886a27093..d14398750080 100644 --- a/sys/powerpc/include/pmap.h +++ b/sys/powerpc/include/pmap.h @@ -340,6 +340,9 @@ extern int pmap_bootstrapped; extern int radix_mmu; extern int superpages_enabled; +#ifdef AIM +void pmap_early_io_map_init(void); +#endif vm_offset_t pmap_early_io_map(vm_paddr_t pa, vm_size_t size); void pmap_early_io_unmap(vm_offset_t va, vm_size_t size); void pmap_track_page(pmap_t pmap, vm_offset_t va); diff --git a/sys/powerpc/powerpc/machdep.c b/sys/powerpc/powerpc/machdep.c index 716f7e43db48..797f25747479 100644 --- a/sys/powerpc/powerpc/machdep.c +++ b/sys/powerpc/powerpc/machdep.c @@ -415,6 +415,15 @@ powerpc_init(vm_offset_t fdt, vm_offset_t toc, vm_offset_t ofentry, void *mdp, if (ofw_bootargs) ofw_parse_bootargs(); +#ifdef AIM + /* + * Early I/O map needs to be initialized before console, in order to + * map frame buffers properly, and after boot args have been parsed, + * to handle tunables properly. + */ + pmap_early_io_map_init(); +#endif + /* * Initialize the console before printing anything. */