memory manager: add region calculation for virtual memory
Add region calculations and implementation of sys_mm_drv_query_memory_regions to pass calculated regions down the line. Signed-off-by: Jakub Dabek <jakub.dabek@intel.com>
This commit is contained in:
parent
9531f96627
commit
72f626046d
5 changed files with 105 additions and 3 deletions
|
@ -12,5 +12,6 @@ zephyr_library_sources_ifdef(
|
|||
|
||||
zephyr_sources_ifdef(
|
||||
CONFIG_MM_DRV_INTEL_ADSP_MTL_TLB
|
||||
mm_drv_intel_adsp_regions.c
|
||||
mm_drv_intel_adsp_mtl_tlb.c
|
||||
)
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
|
||||
#include <soc.h>
|
||||
#include <adsp_memory.h>
|
||||
#include <adsp_memory_regions.h>
|
||||
|
||||
#include "mm_drv_common.h"
|
||||
|
||||
|
@ -59,9 +60,6 @@ DEVICE_MMIO_TOPLEVEL_STATIC(tlb_regs, DT_DRV_INST(0));
|
|||
#define L2_SRAM_BANK_NUM (L2_SRAM_SIZE / SRAM_BANK_SIZE)
|
||||
#define IS_BIT_SET(value, idx) ((value) & (1 << (idx)))
|
||||
|
||||
/* size of TLB table */
|
||||
#define TLB_SIZE DT_REG_SIZE_BY_IDX(DT_INST(0, intel_adsp_mtl_tlb), 0)
|
||||
|
||||
/**
|
||||
* Calculate TLB entry based on physical address.
|
||||
*
|
||||
|
@ -85,4 +83,13 @@ static inline uintptr_t tlb_entry_to_pa(uint16_t tlb_entry)
|
|||
CONFIG_MM_DRV_PAGE_SIZE) + TLB_PHYS_BASE);
|
||||
}
|
||||
|
||||
/**
|
||||
* Calculate virtual memory regions allocation based on
|
||||
* info from linker script.
|
||||
*
|
||||
* @param End address of staticaly allocated memory.
|
||||
* @return Error Code.
|
||||
*/
|
||||
int calculate_memory_regions(uintptr_t static_alloc_end_ptr);
|
||||
|
||||
#endif /* ZEPHYR_DRIVERS_SYSTEM_MM_DRV_INTEL_MTL_ */
|
||||
|
|
|
@ -589,6 +589,10 @@ static int sys_mm_drv_mm_init(const struct device *dev)
|
|||
|
||||
L2_PHYS_SRAM_REGION.num_blocks = avalible_memory_size / CONFIG_MM_DRV_PAGE_SIZE;
|
||||
|
||||
ret = calculate_memory_regions(UNUSED_L2_START_ALIGNED);
|
||||
CHECKIF(ret != 0) {
|
||||
return ret;
|
||||
}
|
||||
/*
|
||||
* Initialize memblocks that will store physical
|
||||
* page usage. Initially all physical pages are
|
||||
|
@ -619,6 +623,7 @@ static int sys_mm_drv_mm_init(const struct device *dev)
|
|||
*/
|
||||
if (L2_SRAM_BASE + L2_SRAM_SIZE < UNUSED_L2_START_ALIGNED ||
|
||||
L2_SRAM_BASE > UNUSED_L2_START_ALIGNED) {
|
||||
|
||||
__ASSERT(false,
|
||||
"unused l2 pointer is outside of l2 sram range %p\n",
|
||||
UNUSED_L2_START_ALIGNED);
|
||||
|
|
62
drivers/mm/mm_drv_intel_adsp_regions.c
Normal file
62
drivers/mm/mm_drv_intel_adsp_regions.c
Normal file
|
@ -0,0 +1,62 @@
|
|||
/*
|
||||
* Copyright (c) 2022 Intel Corporation
|
||||
*
|
||||
* SPDX-License-Identifier: Apache-2.0
|
||||
*/
|
||||
|
||||
/**
|
||||
* @file
|
||||
* @brief Driver handling memory regions related
|
||||
* functions
|
||||
*/
|
||||
|
||||
#include "mm_drv_intel_adsp.h"
|
||||
|
||||
struct sys_mm_drv_region
|
||||
virtual_memory_regions[CONFIG_MP_MAX_NUM_CPUS + VIRTUAL_REGION_COUNT] = { {0} };
|
||||
|
||||
const struct sys_mm_drv_region *sys_mm_drv_query_memory_regions(void)
|
||||
{
|
||||
return (const struct sys_mm_drv_region *) virtual_memory_regions;
|
||||
}
|
||||
|
||||
static inline void append_region(void *address, uint32_t mem_size,
|
||||
uint32_t attributes, uint32_t position, uint32_t *checksum)
|
||||
{
|
||||
virtual_memory_regions[position].addr = address;
|
||||
virtual_memory_regions[position].size = mem_size;
|
||||
virtual_memory_regions[position].attr = attributes;
|
||||
checksum += mem_size;
|
||||
}
|
||||
|
||||
int calculate_memory_regions(uintptr_t static_alloc_end_ptr)
|
||||
{
|
||||
struct sys_mm_drv_region *temporary_table =
|
||||
(struct sys_mm_drv_region *)&virtual_memory_regions[0];
|
||||
|
||||
int i, checksum = 0;
|
||||
|
||||
for (i = 0; i < CONFIG_MP_MAX_NUM_CPUS; i++) {
|
||||
append_region((void *)(static_alloc_end_ptr + i * CORE_HEAP_SIZE),
|
||||
CORE_HEAP_SIZE, MEM_REG_ATTR_CORE_HEAP, i, &checksum);
|
||||
}
|
||||
|
||||
append_region((void *)((uintptr_t)
|
||||
virtual_memory_regions[i - 1].addr + temporary_table[i - 1].size),
|
||||
CORE_HEAP_SIZE, MEM_REG_ATTR_SHARED_HEAP, i, &checksum);
|
||||
i++;
|
||||
append_region((void *)((uintptr_t)
|
||||
virtual_memory_regions[i - 1].addr + temporary_table[i - 1].size),
|
||||
OPPORTUNISTIC_REGION_SIZE, MEM_REG_ATTR_OPPORTUNISTIC_MEMORY, i, &checksum);
|
||||
i++;
|
||||
/* Apending last region as 0 so iterators know where table is over
|
||||
* check is for size = 0;
|
||||
*/
|
||||
append_region((void *)0, 0, 0, i, &checksum);
|
||||
|
||||
if (checksum > L2_VIRTUAL_SRAM_SIZE) {
|
||||
return -EINVAL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue