Changeset 3d4750f in mainline for kernel/generic/src/mm/km.c


Ignore:
Timestamp:
2012-01-31T22:52:06Z (12 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
512a7df, 70922c2, b7068da, bb6f135
Parents:
bf31e3f (diff), 7b5789e (diff)
Note: this is a merge changeset, the changes displayed below correspond to the merge itself.
Use the (diff) links above to see all the changes relative to each parent.
Message:

Merge from lp:~jakub/helenos/mm.

File:
1 edited

Legend:

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

    rbf31e3f r3d4750f  
    124124}
    125125
    126 uintptr_t km_map(uintptr_t paddr, size_t size, unsigned int flags)
     126static uintptr_t
     127km_map_aligned(uintptr_t paddr, size_t size, unsigned int flags)
    127128{
    128129        uintptr_t vaddr;
    129         size_t asize;
    130130        size_t align;
    131131        uintptr_t offs;
    132132
    133         asize = ALIGN_UP(size, PAGE_SIZE);
     133        ASSERT(ALIGN_DOWN(paddr, FRAME_SIZE) == paddr);
     134        ASSERT(ALIGN_UP(size, FRAME_SIZE) == size);
     135
    134136        align = ispwr2(size) ? size : (1U << (fnzb(size) + 1));
    135         vaddr = km_page_alloc(asize, max(PAGE_SIZE, align));
     137        vaddr = km_page_alloc(size, max(PAGE_SIZE, align));
    136138
    137139        page_table_lock(AS_KERNEL, true);
    138         for (offs = 0; offs < asize; offs += PAGE_SIZE) {
     140        for (offs = 0; offs < size; offs += PAGE_SIZE) {
    139141                page_mapping_insert(AS_KERNEL, vaddr + offs, paddr + offs,
    140142                    flags);
     
    145147}
    146148
    147 uintptr_t km_map_structure(uintptr_t paddr, size_t size, unsigned int flags)
    148 {
    149         size_t offs = paddr - ALIGN_DOWN(paddr, FRAME_SIZE);
     149static void km_unmap_aligned(uintptr_t vaddr, size_t size)
     150{
     151        uintptr_t offs;
     152        ipl_t ipl;
     153
     154        ASSERT(ALIGN_DOWN(vaddr, PAGE_SIZE) == vaddr);
     155        ASSERT(ALIGN_UP(size, PAGE_SIZE) == size);
     156
     157        page_table_lock(AS_KERNEL, true);
     158
     159        ipl = tlb_shootdown_start(TLB_INVL_ASID, ASID_KERNEL, 0, 0);
     160
     161        for (offs = 0; offs < size; offs += PAGE_SIZE)
     162                page_mapping_remove(AS_KERNEL, vaddr + offs);
     163
     164        tlb_invalidate_asid(ASID_KERNEL);
     165
     166        as_invalidate_translation_cache(AS_KERNEL, 0, -1);
     167        tlb_shootdown_finalize(ipl);
     168        page_table_unlock(AS_KERNEL, true);
     169
     170        km_page_free(vaddr, size);
     171}
     172
     173/** Map a piece of physical address space into the virtual address space.
     174 *
     175 * @param paddr         Physical address to be mapped. May be unaligned.
     176 * @param size          Size of area starting at paddr to be mapped.
     177 * @param flags         Protection flags to be used for the mapping.
     178 *
     179 * @return New virtual address mapped to paddr.
     180 */
     181uintptr_t km_map(uintptr_t paddr, size_t size, unsigned int flags)
     182{
    150183        uintptr_t page;
    151 
    152         page = km_map(ALIGN_DOWN(paddr, FRAME_SIZE), size + offs, flags);
     184        size_t offs;
     185
     186        offs = paddr - ALIGN_DOWN(paddr, FRAME_SIZE);
     187        page = km_map_aligned(ALIGN_DOWN(paddr, FRAME_SIZE),
     188            ALIGN_UP(size + offs, FRAME_SIZE), flags);
     189
    153190        return page + offs;
    154191}
    155192
    156 /** Unmap kernen non-identity page.
     193/** Unmap a piece of virtual address space.
     194 *
     195 * @param vaddr         Virtual address to be unmapped. May be unaligned, but
     196 *                      it must a value previously returned by km_map().
     197 * @param size          Size of area starting at vaddr to be unmapped.
     198 */
     199void km_unmap(uintptr_t vaddr, size_t size)
     200{
     201        size_t offs;
     202
     203        offs = vaddr - ALIGN_DOWN(vaddr, PAGE_SIZE);
     204        km_unmap_aligned(ALIGN_DOWN(vaddr, PAGE_SIZE),
     205            ALIGN_UP(size + offs, PAGE_SIZE));
     206}
     207
     208/** Unmap kernel non-identity page.
    157209 *
    158210 * @param[in] page      Non-identity page to be unmapped.
Note: See TracChangeset for help on using the changeset viewer.