pussuw commented on code in PR #12922:
URL: https://github.com/apache/nuttx/pull/12922#discussion_r1724973577


##########
arch/arm64/src/common/arm64_addrenv_utils.c:
##########
@@ -0,0 +1,239 @@
+/****************************************************************************
+ * arch/arm64/src/common/arm64_addrenv_utils.c
+ *
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.  The
+ * ASF licenses this file to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance with the
+ * License.  You may obtain a copy of the License at
+ *
+ *   http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.  See the
+ * License for the specific language governing permissions and limitations
+ * under the License.
+ *
+ ****************************************************************************/
+
+/****************************************************************************
+ * Included Files
+ ****************************************************************************/
+
+#include <nuttx/config.h>
+
+#include <nuttx/arch.h>
+#include <nuttx/addrenv.h>
+#include <nuttx/irq.h>
+#include <nuttx/pgalloc.h>
+#include <nuttx/sched.h>
+
+#include "barriers.h"
+#include "pgalloc.h"
+#include "arm64_mmu.h"
+
+#ifdef CONFIG_BUILD_KERNEL
+
+/****************************************************************************
+ * Public Functions
+ ****************************************************************************/
+
+/****************************************************************************
+ * Name: arm64_get_pgtable
+ *
+ * Description:
+ *   Get the physical address of the final level page table corresponding to
+ *   'vaddr'. If one does not exist, it will be allocated.
+ *
+ * Input Parameters:
+ *   addrenv - Pointer to a structure describing the address environment
+ *   vaddr - Virtual address to query for
+ *
+ * Returned Value:
+ *   The physical address of the corresponding final level page table, or
+ *   NULL if one does not exist, and there is no free memory to allocate one
+ *
+ ****************************************************************************/
+
+uintptr_t arm64_get_pgtable(arch_addrenv_t *addrenv, uintptr_t vaddr)
+{
+  uintptr_t paddr;
+  uintptr_t ptprev;
+  uint32_t  ptlevel;
+  uint32_t  flags;
+
+  /* Get the current level MAX_LEVELS-1 entry corresponding to this vaddr */
+
+  ptlevel = ARCH_SPGTS;
+  ptprev  = arm64_pgvaddr(addrenv->spgtables[ARCH_SPGTS - 1]);
+  if (!ptprev)
+    {
+      /* Something is very wrong */
+
+      return 0;
+    }
+
+  /* Find the physical address of the final level page table */
+
+  paddr = mmu_pte_to_paddr(mmu_ln_getentry(ptlevel, ptprev, vaddr));
+  if (!paddr)
+    {
+      /* No page table has been allocated... allocate one now */
+
+      paddr = mm_pgalloc(1);
+      if (paddr)
+        {
+          /* Determine page table flags */
+
+          if (arm64_uservaddr(vaddr))
+            {
+              flags = MMU_UPGT_FLAGS;
+            }
+          else
+            {
+              flags = MMU_KPGT_FLAGS;
+            }
+
+          /* Wipe the page and assign it */
+
+          arm64_pgwipe(paddr);
+          mmu_ln_setentry(ptlevel, ptprev, paddr, vaddr, flags);
+        }
+    }
+
+  /* Flush the data cache, so the changes are committed to memory */
+
+  up_flush_dcache(ptprev, sizeof(uintptr_t));

Review Comment:
   Also wrong, what must be flushed is the entry in ptprev, not the first index



-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to