git: e0388a906ca7 - main - arm64: enable superpage mappings by pmap_mapdev{,_attr}()

From: Alan Cox <alc_at_FreeBSD.org>
Date: Sat, 30 Mar 2024 20:54:50 UTC
The branch main has been updated by alc:

URL: https://cgit.FreeBSD.org/src/commit/?id=e0388a906ca77d07c99e8762d47dccaaaefd8bab

commit e0388a906ca77d07c99e8762d47dccaaaefd8bab
Author:     Alan Cox <alc@FreeBSD.org>
AuthorDate: 2024-03-30 20:35:32 +0000
Commit:     Alan Cox <alc@FreeBSD.org>
CommitDate: 2024-03-30 20:41:30 +0000

    arm64: enable superpage mappings by pmap_mapdev{,_attr}()
    
    In order for pmap_kenter{,_device}() to create superpage mappings,
    either 64 KB or 2 MB, pmap_mapdev{,_attr}() must request appropriately
    aligned virtual addresses.
    
    Reviewed by:    markj
    Tested by:      gallatin
    Differential Revision:  https://reviews.freebsd.org/D42737
---
 sys/kern/subr_devmap.c | 14 ++++++++++++++
 1 file changed, 14 insertions(+)

diff --git a/sys/kern/subr_devmap.c b/sys/kern/subr_devmap.c
index 5976f16c7577..441ffeb1270a 100644
--- a/sys/kern/subr_devmap.c
+++ b/sys/kern/subr_devmap.c
@@ -273,6 +273,13 @@ pmap_mapdev(vm_paddr_t pa, vm_size_t size)
 		KASSERT(va >= VM_MAX_KERNEL_ADDRESS - PMAP_MAPDEV_EARLY_SIZE,
 		    ("Too many early devmap mappings"));
 	} else
+#endif
+#ifdef __aarch64__
+	if (size >= L2_SIZE && (pa & L2_OFFSET) == 0)
+		va = kva_alloc_aligned(size, L2_SIZE);
+	else if (size >= L3C_SIZE && (pa & L3C_OFFSET) == 0)
+		va = kva_alloc_aligned(size, L3C_SIZE);
+	else
 #endif
 		va = kva_alloc(size);
 	if (!va)
@@ -304,6 +311,13 @@ pmap_mapdev_attr(vm_paddr_t pa, vm_size_t size, vm_memattr_t ma)
 		KASSERT(va >= (VM_MAX_KERNEL_ADDRESS - (PMAP_MAPDEV_EARLY_SIZE)),
 		    ("Too many early devmap mappings 2"));
 	} else
+#ifdef __aarch64__
+	if (size >= L2_SIZE && (pa & L2_OFFSET) == 0)
+		va = kva_alloc_aligned(size, L2_SIZE);
+	else if (size >= L3C_SIZE && (pa & L3C_OFFSET) == 0)
+		va = kva_alloc_aligned(size, L3C_SIZE);
+	else
+#endif
 		va = kva_alloc(size);
 	if (!va)
 		panic("pmap_mapdev: Couldn't alloc kernel virtual memory");