Skip to content

Commit fdefe42

Browse files
committed
hal/arm: per-process MPU configuration
This commit introduces loader support for full MPU regions reconfiguration on context switch, allowing for more flexibile configuration of memory maps on MPU targets. Changes include * MPU configuration during app command, based on hal_syspage_prog_t structure with program configuration of MPU regions in form of ready-to-copy register values * reimplementation of mpu command, showing generated mpu configuration on per-app basis * passing all maps at once to hal/mpu module, allowing future map merging to reduce count of used MPU regions JIRA: RTOS-1149
1 parent 18ba2d0 commit fdefe42

File tree

29 files changed

+607
-284
lines changed

29 files changed

+607
-284
lines changed

cmds/app.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -161,6 +161,10 @@ static int cmd_appLoad(handler_t handler, size_t size, const char *name, char *i
161161
prog->start = entry->start;
162162
prog->end = entry->end;
163163

164+
if ((res = hal_getProgData(prog, imaps, imapSz, dmaps, dmapSz)) < 0) {
165+
return res;
166+
}
167+
164168
return EOK;
165169
}
166170

cmds/mpu.c

Lines changed: 34 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -82,54 +82,58 @@ static void mpu_regionPrint(const char *name, u32 rbar, u32 rasr)
8282

8383
static void cmd_mpuInfo(void)
8484
{
85-
lib_printf("prints the use of MPU regions, usage: mpu [all]");
85+
lib_printf("prints the use of MPU regions, usage: mpu [prog name]");
8686
}
8787

8888

8989
static int cmd_mpu(int argc, char *argv[])
9090
{
9191
const char *name;
92-
unsigned int i, regCnt;
93-
const mpu_region_t *region;
94-
const mpu_common_t *const mpu_common = mpu_getCommon();
92+
unsigned int i;
93+
const syspage_prog_t *prog = syspage_progsGet();
94+
const syspage_prog_t *firstProg = prog;
95+
const unsigned int regMax = mpu_getMaxRegionsCount();
9596

96-
if (argc == 1) {
97-
regCnt = mpu_common->regCnt;
98-
}
99-
else if (argc == 2) {
100-
if (hal_strcmp(argv[1], "all") != 0) {
101-
log_error("\n%s: Wrong arguments", argv[0]);
102-
return CMD_EXIT_FAILURE;
103-
}
104-
105-
regCnt = mpu_common->regMax;
106-
}
107-
else {
108-
log_error("\n%s: Wrong argument count", argv[0]);
97+
if (prog == NULL) {
98+
log_error("\nNo programs in syspage!");
10999
return CMD_EXIT_FAILURE;
110100
}
111101

112-
if (mpu_common->regMax != sizeof(((hal_syspage_t *)0)->mpu.table) / sizeof(((hal_syspage_t *)0)->mpu.table[0])) {
113-
log_error("\n%s: MPU hal is not initialized or unsupported type was detected", argv[0]);
102+
if (argc > 2) {
103+
log_error("\n%s: Wrong argument count", argv[0]);
114104
return CMD_EXIT_FAILURE;
115105
}
116106

117-
lib_printf(CONSOLE_BOLD "\n%-9s %-7s %-4s %-11s %-11s %-3s %-3s %-9s %-4s %-2s %-2s %-2s\n" CONSOLE_NORMAL,
118-
"MAP NAME", "REGION", "SUB", "START", "END", "EN", "XN", "PERM P/U", "TEX", "S", "C", "B");
107+
do {
108+
name = (prog->argv[0] == 'X') ? prog->argv + 1 : prog->argv;
109+
if ((argc == 2) && (hal_strcmp(name, argv[1]) != 0)) {
110+
prog = prog->next;
111+
continue;
112+
}
113+
lib_printf("\n%-16s 0x%08x%4s 0x%08x", name, prog->start, "", prog->end);
114+
lib_printf(CONSOLE_BOLD "\n%-9s %-7s %-4s %-11s %-11s %-3s %-3s %-9s %-4s %-2s %-2s %-2s\n" CONSOLE_NORMAL,
115+
"MAP NAME", "REGION", "SUB", "START", "END", "EN", "XN", "PERM P/U", "TEX", "S", "C", "B");
116+
for (i = 0; i < prog->hal.mpu.allocCnt; i++) {
117+
name = syspage_mapName(prog->hal.mpu.map[i]);
118+
if (name == NULL) {
119+
name = "<none>";
120+
}
121+
mpu_regionPrint(name, prog->hal.mpu.table[i].rbar, prog->hal.mpu.table[i].rasr);
122+
}
119123

120-
for (i = 0; i < regCnt; i++) {
121-
region = &mpu_common->region[i];
122-
name = syspage_mapName(mpu_common->mapId[i]);
124+
lib_printf("Configured %d of %d MPU regions.\n", prog->hal.mpu.allocCnt, regMax);
123125

124-
if (name == NULL) {
125-
name = "<none>";
126+
if (argc == 2) {
127+
return CMD_EXIT_SUCCESS;
126128
}
127129

128-
mpu_regionPrint(name, region->rbar, region->rasr);
129-
}
130+
prog = prog->next;
131+
} while (prog != firstProg);
130132

131-
lib_printf("\nConfigured %d of %d MPU regions based on %d map definitions.\n",
132-
mpu_common->regCnt, mpu_common->regMax, mpu_common->mapCnt);
133+
if (argc == 2) {
134+
log_error("\nProgram %s not found in syspage!", argv[1]);
135+
return CMD_EXIT_FAILURE;
136+
}
133137

134138
return CMD_EXIT_SUCCESS;
135139
}

hal/aarch64/zynqmp/hal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ void hal_kernelEntryPoint(addr_t addr)
154154
}
155155

156156

157-
int hal_memoryAddMap(addr_t start, addr_t end, u32 attr, u32 mapId)
157+
int hal_getProgData(syspage_prog_t *prog, const char *imaps, size_t imapSz, const char *dmaps, size_t dmapSz)
158158
{
159159
return 0;
160160
}

hal/armv7a/imx6ull/hal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -171,7 +171,7 @@ void hal_kernelEntryPoint(addr_t addr)
171171
}
172172

173173

174-
int hal_memoryAddMap(addr_t start, addr_t end, u32 attr, u32 mapId)
174+
int hal_getProgData(syspage_prog_t *prog, const char *imaps, size_t imapSz, const char *dmaps, size_t dmapSz)
175175
{
176176
return 0;
177177
}

hal/armv7a/zynq7000/hal.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -151,7 +151,7 @@ void hal_kernelEntryPoint(addr_t addr)
151151
}
152152

153153

154-
int hal_memoryAddMap(addr_t start, addr_t end, u32 attr, u32 mapId)
154+
int hal_getProgData(syspage_prog_t *prog, const char *imaps, size_t imapSz, const char *dmaps, size_t dmapSz)
155155
{
156156
return 0;
157157
}

hal/armv7m/imxrt/hal.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,12 +124,13 @@ void hal_kernelGetEntryPointOffset(addr_t *off, int *indirect)
124124
void hal_kernelEntryPoint(addr_t addr)
125125
{
126126
hal_common.entry = addr;
127+
mpu_kernelEntryPoint(addr);
127128
}
128129

129130

130-
int hal_memoryAddMap(addr_t start, addr_t end, u32 attr, u32 mapId)
131+
int hal_getProgData(syspage_prog_t *prog, const char *imaps, size_t imapSz, const char *dmaps, size_t dmapSz)
131132
{
132-
return mpu_regionAlloc(start, end, attr, mapId, 1);
133+
return mpu_getHalProgData(prog, imaps, imapSz, dmaps, dmapSz);
133134
}
134135

135136

0 commit comments

Comments
 (0)