Skip to content

Commit

Permalink
drivers: mm: Add RAT support using system_mm API
Browse files Browse the repository at this point in the history
Integrates get local address functionality required by the RAT driver
using sys_mm_drv_page_phys_get.

Signed-off-by: L Lakshmanan <l-lakshmanan@ti.com>
  • Loading branch information
KarthikL1729 committed Jul 6, 2023
1 parent 8fd98a7 commit b5b0fc9
Show file tree
Hide file tree
Showing 9 changed files with 39 additions and 75 deletions.
2 changes: 1 addition & 1 deletion drivers/mm/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -16,4 +16,4 @@ zephyr_sources_ifdef(
mm_drv_intel_adsp_mtl_tlb.c
)

add_subdirectory_ifdef(CONFIG_TI_RAT rat)
zephyr_sources_ifdef(CONFIG_TI_RAT mm_drv_ti_rat.c)
12 changes: 8 additions & 4 deletions drivers/mm/Kconfig
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,7 @@ config MM_DRV_INTEL_ADSP_TLB
Driver for the translation lookup buffer on
Intel Audio DSP hardware.

endif # MM_DRV

menuconfig EXTERNAL_ADDRESS_TRANSLATION
config EXTERNAL_ADDRESS_TRANSLATION
bool "Support for external address translation modules if necessary"
help
This config is intended to support an external address
Expand All @@ -55,7 +53,13 @@ menuconfig EXTERNAL_ADDRESS_TRANSLATION

if EXTERNAL_ADDRESS_TRANSLATION

source "drivers/mm/rat/Kconfig"
config TI_RAT
bool "Texas Instruments RAT module"
depends on EXTERNAL_ADDRESS_TRANSLATION
help
Enables Region based address translation
support functions specific to TI SoCs.

endif # EXTERNAL_ADDRESS_TRANSLATION

endif # MM_DRV
36 changes: 23 additions & 13 deletions drivers/mm/rat/ti_rat.c → drivers/mm/mm_drv_ti_rat.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
*/

#include <zephyr/drivers/mm/rat.h>
#include <zephyr/drivers/mm/system_mm.h>
#include <zephyr/sys/__assert.h>

address_trans_params translate_config;
Expand Down Expand Up @@ -53,7 +54,7 @@ void address_trans_init(address_trans_params *params)
}
}

void RAT_init(void *region_config, uint64_t rat_base_addr, uint8_t translate_regions)
void mm_drv_ti_rat_init(void *region_config, uint64_t rat_base_addr, uint8_t translate_regions)
{
translate_config.num_regions = translate_regions;
translate_config.rat_base_addr = rat_base_addr;
Expand All @@ -66,46 +67,55 @@ void RAT_deinit(void)
{
}

void *z_get_local_addr(uint64_t system_addr)
int sys_mm_drv_page_phys_get(void *virt, uintptr_t *phys)
{
return rat_get_local_addr(system_addr);
}
if (virt == NULL) {
return -EINVAL;
}
uint64_t pa = ((uint64_t) (virt));
uintptr_t *va = phys;

void *rat_get_local_addr(uint64_t system_addr)
{
uint32_t found, regionId;
void *local_addr;

__ASSERT(translate_config.num_regions < address_trans_MAX_REGIONS,
"Exceeding maximum number of regions");

found = 0;
uint32_t x = translate_config.num_regions;

for (regionId = 0; regionId < translate_config.num_regions; regionId++) {
uint64_t start_addr, end_addr;
uint32_t size_mask;

/* we assume translate_config.region_config[] address and size is aligned */
size_mask =
((uint32_t)(((uint64_t)1 << translate_config.region_config[regionId].size) -
1));

start_addr = translate_config.region_config[regionId].system_addr;

/* calculate end address */
end_addr = start_addr + size_mask;

if (system_addr >= start_addr && system_addr <= end_addr) {
/* see if input address falls in this region */
if (pa >= start_addr && pa <= end_addr) {
/* yes, input address falls in this region, break from loop */
found = 1;
break;
}
}
if (found) {
/* translate input address to output address */
uint32_t offset =
system_addr - translate_config.region_config[regionId].system_addr;
pa - translate_config.region_config[regionId].system_addr;

local_addr = (void *)(translate_config.region_config[regionId].local_addr + offset);
*va = (void *)(translate_config.region_config[regionId].local_addr + offset);
} else {
local_addr = (void *)system_addr;
/* no mapping found, set output = input with 32b truncation */
*va = (void *)pa;
}

if (va == NULL) {
return -EFAULT;
}
return local_addr;
return 0;
}
8 changes: 0 additions & 8 deletions drivers/mm/rat/CMakeLists.txt

This file was deleted.

13 changes: 0 additions & 13 deletions drivers/mm/rat/Kconfig

This file was deleted.

7 changes: 2 additions & 5 deletions include/zephyr/drivers/mm/rat.h
Original file line number Diff line number Diff line change
Expand Up @@ -85,11 +85,8 @@ typedef struct address_trans_params_s {
} address_trans_params;

void address_trans_init(address_trans_params *params);
void RAT_init(void *region_config, uint64_t rat_base_addr, uint8_t translate_regions);
void RAT_deinit(void);
void *rat_get_local_addr(uint64_t system_addr);
/* Generic abstraction function to override weakly defined function */
void *z_get_local_addr(uint64_t system_addr);
void mm_drv_ti_rat_init(void *region_config, uint64_t rat_base_addr, uint8_t translate_regions);
void mm_drv_ti_rat_deinit(void);

/** @} */

Expand Down
6 changes: 5 additions & 1 deletion include/zephyr/sys/device_mmio.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,10 @@
#define DEVICE_MMIO_IS_IN_RAM
#endif

#if defined(CONFIG_MM_DRV)
#include <zephyr/drivers/mm/system_mm.h>
#endif

#ifndef _ASMLANGUAGE
#include <stdint.h>
#include <stddef.h>
Expand Down Expand Up @@ -102,7 +106,7 @@ static inline void device_map(mm_reg_t *virt_addr, uintptr_t phys_addr,
ARG_UNUSED(size);
ARG_UNUSED(flags);
#ifdef CONFIG_EXTERNAL_ADDRESS_TRANSLATION
*virt_addr = (mm_reg_t *) z_get_local_addr((uint64_t) phys_addr);
sys_mm_drv_page_phys_get((void *) phys_addr, virt_addr);
#else
*virt_addr = phys_addr;
#endif /* CONFIG_EXTERNAL_ADDRESS_TRANSLATION */
Expand Down
20 changes: 0 additions & 20 deletions include/zephyr/sys/mem_manage.h
Original file line number Diff line number Diff line change
Expand Up @@ -261,26 +261,6 @@ void z_phys_map(uint8_t **virt_ptr, uintptr_t phys, size_t size,
*/
void z_phys_unmap(uint8_t *virt, size_t size);

#ifdef CONFIG_EXTERNAL_ADDRESS_TRANSLATION
/**
* Get a local address using a custom memory mapping function.
*
* This API is only available if CONFIG_EXTERNAL_ADDRESS_TRANSLATION
* is enabled.
*
* This function is meant to be overridden by custom address mapppings
* defined in drivers.
*
* This API is part of infrastructure still under development and may
* change.
*
* @param phys_addr Physical address that is to be translated by the
* external module.
*/

__weak void *z_get_local_addr(uint64_t phys_addr);
#endif /* CONFIG_EXTERNAL_ADDRESS_TRANSLATION */

/*
* k_mem_map() control flags
*/
Expand Down
10 changes: 0 additions & 10 deletions kernel/mmu.c
Original file line number Diff line number Diff line change
Expand Up @@ -952,16 +952,6 @@ void z_mem_manage_boot_finish(void)
#endif
}

#ifdef CONFIG_EXTERNAL_ADDRESS_TRANSLATION

__weak void *z_get_local_addr(uint64_t phys_addr)
{
/* To be overridden by external address translation in drivers */
return (void *) phys_addr;
}

#endif /* CONFIG_EXTERNAL_ADDRESS_TRANSLATION */

#ifdef CONFIG_DEMAND_PAGING

#ifdef CONFIG_DEMAND_PAGING_STATS
Expand Down

0 comments on commit b5b0fc9

Please sign in to comment.