This is an automated email from the ASF dual-hosted git repository.

acassis pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/nuttx.git


The following commit(s) were added to refs/heads/master by this push:
     new 42fc52a1e97 arch/arm64: Implement up_addrenv_pa_to_va().
42fc52a1e97 is described below

commit 42fc52a1e97716bf922a285d909dfe0e5464c3f5
Author: Marco Casaroli <[email protected]>
AuthorDate: Wed Oct 7 23:43:33 2026 +0200

    arch/arm64: Implement up_addrenv_pa_to_va().
    
    OpenAMP libmetal calls up_addrenv_pa_to_va() and up_addrenv_va_to_pa(),
    and every virtio driver uses libmetal.  With CONFIG_DEV_SIMPLE_ADDRENV,
    drivers/misc/addrenv.c provides both.  Without it, arm64 provides only
    up_addrenv_va_to_pa(), in arm64_physpgaddr.c.  So an arm64 build with
    an MMU and any virtio driver does not link, flat or kernel:
    
      undefined reference to `up_addrenv_pa_to_va'
    
    The flat qemu-armv8a virtio configurations set CONFIG_DEV_SIMPLE_ADDRENV.
    That does not fit a kernel build: its table gives the same address back
    for a user address of the process.
    
    Add up_addrenv_pa_to_va() next to up_addrenv_va_to_pa().  It translates
    the page pool and the kernel RAM with arm64_pgvaddr(), and any other
    address to itself.  up_addrenv_va_to_pa() must then give back the same
    physical address, otherwise the function returns NULL, as
    include/nuttx/arch.h specifies.
    
    Assisted-by: Claude Code:claude-opus-5-5
    Signed-off-by: Marco Casaroli <[email protected]>
---
 arch/arm64/src/common/arm64_physpgaddr.c | 42 ++++++++++++++++++++++++++++++++
 1 file changed, 42 insertions(+)

diff --git a/arch/arm64/src/common/arm64_physpgaddr.c 
b/arch/arm64/src/common/arm64_physpgaddr.c
index 9180387fdcc..15d017e3f73 100644
--- a/arch/arm64/src/common/arm64_physpgaddr.c
+++ b/arch/arm64/src/common/arm64_physpgaddr.c
@@ -34,6 +34,11 @@
 #include "arm64_arch.h"
 #include "arm64_internal.h"
 
+#ifdef CONFIG_ARCH_PGPOOL_MAPPING
+#  include <nuttx/pgalloc.h>
+#  include "pgalloc.h"
+#endif
+
 #ifndef CONFIG_DEV_SIMPLE_ADDRENV
 
 /****************************************************************************
@@ -98,4 +103,41 @@ uintptr_t up_addrenv_va_to_pa(void *va)
                      ((uintptr_t)va & VA_PAGE_OFFSET_MASK));
 }
 
+/****************************************************************************
+ * Name: up_addrenv_pa_to_va
+ *
+ * Description:
+ *   Map a physical address to a kernel virtual address: through the page
+ *   pool or kernel RAM mapping, otherwise the same address.  The MMU must
+ *   confirm the result.
+ *
+ * Input Parameters:
+ *   pa - The physical address to be mapped.
+ *
+ * Returned Value:
+ *   Virtual address on success; NULL if no kernel mapping was found.
+ *
+ ****************************************************************************/
+
+void *up_addrenv_pa_to_va(uintptr_t pa)
+{
+  uintptr_t va = 0;
+
+#ifdef CONFIG_ARCH_PGPOOL_MAPPING
+  va = arm64_pgvaddr(pa);
+#endif
+
+  if (va == 0)
+    {
+      va = pa;
+    }
+
+  if (up_addrenv_va_to_pa((void *)va) != pa)
+    {
+      return NULL;
+    }
+
+  return (void *)va;
+}
+
 #endif /* CONFIG_DEV_SIMPLE_ADDRENV */

Reply via email to