Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/generic/src/mm/page.c

    r8757be86 r2107e79  
    6565#include <arch/mm/asid.h>
    6666#include <mm/as.h>
     67#include <mm/km.h>
    6768#include <mm/frame.h>
    6869#include <arch/barrier.h>
     
    7576#include <errno.h>
    7677#include <align.h>
     78#include <macros.h>
     79#include <bitops.h>
    7780
    7881/** Virtual operations for page subsystem. */
     
    8285{
    8386        page_arch_init();
     87}
     88
     89/** Map memory structure
     90 *
     91 * Identity-map memory structure
     92 * considering possible crossings
     93 * of page boundaries.
     94 *
     95 * @param addr Address of the structure.
     96 * @param size Size of the structure.
     97 *
     98 */
     99void map_structure(uintptr_t addr, size_t size)
     100{
     101        size_t length = size + (addr - (addr & ~(PAGE_SIZE - 1)));
     102        size_t cnt = length / PAGE_SIZE + (length % PAGE_SIZE > 0);
     103       
     104        size_t i;
     105        for (i = 0; i < cnt; i++)
     106                page_mapping_insert(AS_KERNEL, addr + i * PAGE_SIZE,
     107                    addr + i * PAGE_SIZE, PAGE_NOT_CACHEABLE | PAGE_WRITE);
     108       
     109        /* Repel prefetched accesses to the old mapping. */
     110        memory_barrier();
    84111}
    85112
     
    166193}
    167194
     195uintptr_t hw_map(uintptr_t physaddr, size_t size)
     196{
     197        uintptr_t virtaddr;
     198        size_t asize;
     199        size_t align;
     200        pfn_t i;
     201
     202        asize = ALIGN_UP(size, PAGE_SIZE);
     203        align = ispwr2(size) ? size : (1U << (fnzb(size) + 1));
     204        virtaddr = km_page_alloc(asize, max(PAGE_SIZE, align));
     205
     206        page_table_lock(AS_KERNEL, true);
     207        for (i = 0; i < ADDR2PFN(asize); i++) {
     208                uintptr_t addr = PFN2ADDR(i);
     209                page_mapping_insert(AS_KERNEL, virtaddr + addr, physaddr + addr,
     210                    PAGE_NOT_CACHEABLE | PAGE_WRITE);
     211        }
     212        page_table_unlock(AS_KERNEL, true);
     213       
     214        return virtaddr;
     215}
     216
    168217int page_find_mapping(uintptr_t virt, void **phys)
    169218{
Note: See TracChangeset for help on using the changeset viewer.