pussuw commented on code in PR #6069: URL: https://github.com/apache/incubator-nuttx/pull/6069#discussion_r850434813
########## arch/risc-v/src/mpfs/mpfs_mm_init.c: ########## @@ -0,0 +1,188 @@ +/**************************************************************************** + * arch/risc-v/src/mpfs/mpfs_mm_init.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 <stdint.h> +#include <assert.h> +#include <debug.h> + +#include <arch/board/board_memorymap.h> + +#include "mpfs_memorymap.h" + +#include "riscv_internal.h" +#include "riscv_mmu.h" + +/**************************************************************************** + * Pre-processor Definitions + ****************************************************************************/ + +/* PMP settings */ + +#define PMP_IO_FLAGS (PMPCFG_A_NAPOT | PMPCFG_R | PMPCFG_W) +#define PMP_RAM_FLAGS (PMPCFG_A_NAPOT | PMPCFG_X | PMPCFG_R | PMPCFG_W) + +/* Open up (basically) the whole memory */ + +#define PMP_IO_BASE (MPFS_CLINT_BASE) +#define PMP_IO_SIZE (MPFS_DDR_BASE - MPFS_CLINT_BASE) +#define PMP_RAM_BASE (MPFS_DDR_BASE) +#define PMP_RAM_SIZE (MPFS_DDR_SIZE) + +/* Map the whole I/O memory with vaddr = paddr mappings */ + +#define MMU_IO_BASE (0x00000000) +#define MMU_IO_SIZE (0x80000000) + +/* Physical and virtual addresses to page tables (vaddr = paddr mapping) */ + +#define PGT_L1_PBASE (uintptr_t)&m_l1_pgtable +#define PGT_L2_PBASE (uintptr_t)&m_l2_pgtable +#define PGT_L3_PBASE (uintptr_t)&m_l3_pgtable +#define PGT_L1_VBASE PGT_L1_PBASE +#define PGT_L2_VBASE PGT_L2_PBASE +#define PGT_L3_VBASE PGT_L3_PBASE + +#define PGT_L1_SIZE (512) /* Enough to map 512 GiB */ +#define PGT_L2_SIZE (512) /* Enough to map 1 GiB */ +#define PGT_L3_SIZE (1024) /* Enough to map 4 MiB */ + +/**************************************************************************** + * Private Data + ****************************************************************************/ + +/* Kernel mappings simply here, mapping is vaddr=paddr */ + +static uint64_t m_l1_pgtable[PGT_L1_SIZE] locate_data(".pgtables"); +static uint64_t m_l2_pgtable[PGT_L2_SIZE] locate_data(".pgtables"); +static uint64_t m_l3_pgtable[PGT_L3_SIZE] locate_data(".pgtables"); Review Comment: Not really generic code. I don't want to force the way kernel mappings are done. How I did this is a very lazy approach. Static allocation limits how much memory can be allocated, dynamic allocation would be better but requires an order of magnitude more code to work. I can change the type, although mpfs is always RV64. -- 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]
