Skip to content

Commit d182632

Browse files
committed
Implement PMP hardware initialization function
Clear all PMP regions and initialize shadow configuration state. Sets up hardware and software state for subsequent region configuration.
1 parent b1528e5 commit d182632

File tree

1 file changed

+26
-0
lines changed

1 file changed

+26
-0
lines changed

arch/riscv/pmp.c

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,32 @@ pmp_config_t *pmp_get_config(void)
195195
return &pmp_global_config;
196196
}
197197

198+
int32_t pmp_init(pmp_config_t *config)
199+
{
200+
if (!config)
201+
return ERR_PMP_INVALID_REGION;
202+
203+
/* Clear all PMP regions in hardware and shadow configuration */
204+
for (uint8_t i = 0; i < PMP_MAX_REGIONS; i++) {
205+
write_pmpaddr(i, 0);
206+
if (i % 4 == 0)
207+
write_pmpcfg(i / 4, 0);
208+
209+
config->regions[i].addr_start = 0;
210+
config->regions[i].addr_end = 0;
211+
config->regions[i].permissions = 0;
212+
config->regions[i].priority = PMP_PRIORITY_TEMPORARY;
213+
config->regions[i].region_id = i;
214+
config->regions[i].locked = 0;
215+
}
216+
217+
config->region_count = 0;
218+
config->next_region_idx = 0;
219+
config->initialized = 1;
220+
221+
return ERR_OK;
222+
}
223+
198224
int32_t pmp_init_pools(pmp_config_t *config,
199225
const mempool_t *pools,
200226
size_t count)

0 commit comments

Comments
 (0)