Skip to content

Commit 9e814c0

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 49ddd7d commit 9e814c0

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
@@ -118,6 +118,32 @@ pmp_config_t *pmp_get_config(void)
118118
return &pmp_global_config;
119119
}
120120

121+
int32_t pmp_init(pmp_config_t *config)
122+
{
123+
if (!config)
124+
return ERR_PMP_INVALID_REGION;
125+
126+
/* Clear all PMP regions in hardware and shadow configuration */
127+
for (uint8_t i = 0; i < PMP_MAX_REGIONS; i++) {
128+
write_pmpaddr(i, 0);
129+
if (i % 4 == 0)
130+
write_pmpcfg(i / 4, 0);
131+
132+
config->regions[i].addr_start = 0;
133+
config->regions[i].addr_end = 0;
134+
config->regions[i].permissions = 0;
135+
config->regions[i].priority = PMP_PRIORITY_TEMPORARY;
136+
config->regions[i].region_id = i;
137+
config->regions[i].locked = 0;
138+
}
139+
140+
config->region_count = 0;
141+
config->next_region_idx = 0;
142+
config->initialized = 1;
143+
144+
return ERR_OK;
145+
}
146+
121147
int32_t pmp_init_pools(pmp_config_t *config, const mempool_t *pools,
122148
size_t count)
123149
{

0 commit comments

Comments
 (0)