Skip to content

adsp: delegate creation of virtual memory regions to the application #93334

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions drivers/mm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,13 @@ config MM_DRV_INTEL_ADSP_TLB
Driver for the translation lookup buffer on
Intel Audio DSP hardware.

config MM_DRV_INTEL_VIRTUAL_REGION_COUNT
int "Maximum number of regions defined in virtual memory"
depends on MM_DRV_INTEL_ADSP_MTL_TLB
default 1
help
This options defines a table size keeping all virtual memory region

config EXTERNAL_ADDRESS_TRANSLATION
bool "Support for external address translation modules"
depends on !MMU
Expand Down
9 changes: 0 additions & 9 deletions drivers/mm/mm_drv_intel_adsp.h
Original file line number Diff line number Diff line change
Expand Up @@ -79,13 +79,4 @@ 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_ */
9 changes: 5 additions & 4 deletions drivers/mm/mm_drv_intel_adsp_mtl_tlb.c
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,11 @@
L2_SRAM_PAGES_NUM,
(uint8_t *) L2_SRAM_BASE);

uintptr_t adsp_mm_get_unused_l2_start_aligned()

Check failure on line 65 in drivers/mm/mm_drv_intel_adsp_mtl_tlb.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

FUNCTION_WITHOUT_ARGS

drivers/mm/mm_drv_intel_adsp_mtl_tlb.c:65 Bad function definition - uintptr_t adsp_mm_get_unused_l2_start_aligned() should probably be uintptr_t adsp_mm_get_unused_l2_start_aligned(void)
{
return UNUSED_L2_START_ALIGNED;
}

/**
* Calculate the index to the TLB table.
*
Expand Down Expand Up @@ -738,10 +743,6 @@

L2_PHYS_SRAM_REGION.info.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
Expand Down
60 changes: 30 additions & 30 deletions drivers/mm/mm_drv_intel_adsp_regions.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,48 +12,48 @@

#include "mm_drv_intel_adsp.h"


/* virtual memory regions table, last item is an end marker */
struct sys_mm_drv_region
virtual_memory_regions[CONFIG_MP_MAX_NUM_CPUS + VIRTUAL_REGION_COUNT] = { {0} };
virtual_memory_regions[CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT+1] = { {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 *total_size)
int adsp_add_virtual_memory_region(uintptr_t region_address, uint32_t region_size, uint32_t attr)
{
virtual_memory_regions[position].addr = address;
virtual_memory_regions[position].size = mem_size;
virtual_memory_regions[position].attr = attributes;
total_size += mem_size;
}
struct sys_mm_drv_region *region;
uint32_t pos = 0;
uintptr_t new_region_end = region_address + region_size;

int calculate_memory_regions(uintptr_t static_alloc_end_ptr)
{
int i, total_size = 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, &total_size);
/* check if the region fits to virtual memory */
if (region_address < L2_VIRTUAL_SRAM_BASE ||
new_region_end > L2_VIRTUAL_SRAM_BASE + L2_VIRTUAL_SRAM_SIZE) {
return -EINVAL;
}

append_region((void *)((uintptr_t)virtual_memory_regions[i - 1].addr +
virtual_memory_regions[i - 1].size),
CORE_HEAP_SIZE, MEM_REG_ATTR_SHARED_HEAP, i, &total_size);
i++;
append_region((void *)((uintptr_t)virtual_memory_regions[i - 1].addr +
virtual_memory_regions[i - 1].size),
OPPORTUNISTIC_REGION_SIZE, MEM_REG_ATTR_OPPORTUNISTIC_MEMORY, i, &total_size);
i++;
/* Apending last region as 0 so iterators know where table is over
* check is for size = 0;
*/
append_region(NULL, 0, 0, i, &total_size);

if (total_size > L2_VIRTUAL_SRAM_SIZE) {
return -EINVAL;
/* find an empty slot, verify if the region is not overlapping */
SYS_MM_DRV_MEMORY_REGION_FOREACH(virtual_memory_regions, region) {
uintptr_t region_start = (uintptr_t)region->addr;
uintptr_t region_end = region_start + region->size;

/* check region overlapping */
if (region_address < region_end && new_region_end > region_start)

Check warning on line 43 in drivers/mm/mm_drv_intel_adsp_regions.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

BRACES

drivers/mm/mm_drv_intel_adsp_regions.c:43 braces {} are required around if/while/for/else
return -EINVAL;
pos++;
}

/* SYS_MM_DRV_MEMORY_REGION_FOREACH exits when an empty slot is found */
if (pos == CONFIG_MM_DRV_INTEL_VIRTUAL_REGION_COUNT)

Check warning on line 49 in drivers/mm/mm_drv_intel_adsp_regions.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

BRACES

drivers/mm/mm_drv_intel_adsp_regions.c:49 braces {} are required around if/while/for/else
/* no more free slots */
return -ENOMEM;

/* add new region */
virtual_memory_regions[pos].addr = (void*)region_address;

Check failure on line 54 in drivers/mm/mm_drv_intel_adsp_regions.c

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

POINTER_LOCATION

drivers/mm/mm_drv_intel_adsp_regions.c:54 "(foo*)" should be "(foo *)"
virtual_memory_regions[pos].size = region_size;
virtual_memory_regions[pos].attr = attr;

return 0;
}
5 changes: 5 additions & 0 deletions include/zephyr/drivers/mm/mm_drv_intel_adsp_mtl_tlb.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,11 @@
*/
void adsp_mm_restore_context(void *storage_buffer);

/*
* This procedure return a pointer to a first unused address in L2 virtual memory
*/
uintptr_t adsp_mm_get_unused_l2_start_aligned();

Check failure on line 50 in include/zephyr/drivers/mm/mm_drv_intel_adsp_mtl_tlb.h

View workflow job for this annotation

GitHub Actions / Run compliance checks on patch series (PR)

FUNCTION_WITHOUT_ARGS

include/zephyr/drivers/mm/mm_drv_intel_adsp_mtl_tlb.h:50 Bad function definition - uintptr_t adsp_mm_get_unused_l2_start_aligned() should probably be uintptr_t adsp_mm_get_unused_l2_start_aligned(void)

struct intel_adsp_tlb_api {
mm_save_context save_context;
mm_get_storage_size get_storage_size;
Expand Down
23 changes: 11 additions & 12 deletions soc/intel/intel_adsp/ace/include/adsp_memory_regions.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,21 @@
#ifndef ZEPHYR_SOC_INTEL_ADSP_MEMORY_REGIONS_H_
#define ZEPHYR_SOC_INTEL_ADSP_MEMORY_REGIONS_H_

/* Define amount of regions other than core heaps that virtual memory will be split to
* currently includes shared heap and oma region and one regions set to 0 as for table
* iterator end value.
/**
* Add a virtual memory region to the table
*
* @param virtual_address an address of a new region
* @param region_size a size of a new region
* @param attr an attribute of a new region, may not be unique
*
* @return 0 success
* @return -ENOMEM if there are no empty slots for virtual memory regions
* @return -EINVAL if virtual memory region overlaps with existing ones or exceeds memory size
*/
#define VIRTUAL_REGION_COUNT 3

#define CORE_HEAP_SIZE 0x100000
#define SHARED_HEAP_SIZE 0x100000
#define OPPORTUNISTIC_REGION_SIZE 0x100000
int adsp_add_virtual_memory_region(uintptr_t region_address, uint32_t region_size, uint32_t attr);

/* size of TLB table */
#define TLB_SIZE DT_REG_SIZE_BY_IDX(DT_INST(0, intel_adsp_mtl_tlb), 0)

/* Attribiutes for memory regions */
#define MEM_REG_ATTR_CORE_HEAP 1U
#define MEM_REG_ATTR_SHARED_HEAP 2U
#define MEM_REG_ATTR_OPPORTUNISTIC_MEMORY 4U

#endif /* ZEPHYR_SOC_INTEL_ADSP_MEMORY_REGIONS_H_ */
Loading