MCPcopy Create free account
hub / github.com/RT-Thread/rt-thread / rt_hw_mmu_map

Function rt_hw_mmu_map

libcpu/risc-v/common64/mmu.c:182–217  ·  view source on GitHub ↗

* @brief Maps a virtual address space to a physical address space. * * This function maps a specified range of virtual addresses to a range of physical addresses * and sets the attributes of the page table entries (PTEs). If an error occurs during the * mapping process, the function will automatically roll back any partially completed mappings. * * @param aspace Pointer to the address space

Source from the content-addressed store, hash-verified

180 *
181 */
182void *rt_hw_mmu_map(struct rt_aspace *aspace, void *v_addr, void *p_addr,
183 size_t size, size_t attr)
184{
185 int ret = -1;
186 void *unmap_va = v_addr;
187 size_t npages = size >> ARCH_PAGE_SHIFT;
188
189 /* TODO trying with HUGEPAGE here */
190 while (npages--)
191 {
192 MM_PGTBL_LOCK(aspace);
193 ret = _map_one_page(aspace, v_addr, p_addr, attr);
194 MM_PGTBL_UNLOCK(aspace);
195 if (ret != 0)
196 {
197 /* error, undo map */
198 while (unmap_va != v_addr)
199 {
200 MM_PGTBL_LOCK(aspace);
201 _unmap_area(aspace, unmap_va);
202 MM_PGTBL_UNLOCK(aspace);
203 unmap_va += ARCH_PAGE_SIZE;
204 }
205 break;
206 }
207 v_addr += ARCH_PAGE_SIZE;
208 p_addr += ARCH_PAGE_SIZE;
209 }
210
211 if (ret == 0)
212 {
213 return unmap_va;
214 }
215
216 return NULL;
217}
218
219/* unmap page table entry */
220static void _unmap_pte(rt_ubase_t *pentry, rt_ubase_t *lvl_entry[], int level)

Callers

nothing calls this directly

Calls 2

_map_one_pageFunction · 0.85
_unmap_areaFunction · 0.85

Tested by

no test coverage detected