Fork us on GitHub Follow us on Facebook Follow us on Twitter

Changeset 3d4750f in mainline


Ignore:
Timestamp:
2012-01-31T22:52:06Z (8 years ago)
Author:
Jakub Jermar <jakub@…>
Branches:
master
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.

Location:
kernel
Files:
5 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/acpi/acpi.c

    rbf31e3f r3d4750f  
    102102
    103103        /* Start with mapping the header only. */
    104         vhdr = (struct acpi_sdt_header *) km_map_structure((uintptr_t) psdt,
     104        vhdr = (struct acpi_sdt_header *) km_map((uintptr_t) psdt,
    105105            sizeof(struct acpi_sdt_header), PAGE_READ | PAGE_NOT_CACHEABLE);
    106106
    107107        /* Now we can map the entire structure. */
    108         vsdt = (struct acpi_sdt_header *) km_map_structure((uintptr_t) psdt,
     108        vsdt = (struct acpi_sdt_header *) km_map((uintptr_t) psdt,
    109109            vhdr->length, PAGE_WRITE | PAGE_NOT_CACHEABLE);
    110110       
  • kernel/generic/include/mm/km.h

    rbf31e3f r3d4750f  
    5050
    5151extern uintptr_t km_map(uintptr_t, size_t, unsigned int);
    52 extern uintptr_t km_map_structure(uintptr_t, size_t, unsigned int);
     52extern void km_unmap(uintptr_t, size_t);
    5353
    5454extern uintptr_t km_temporary_page_get(uintptr_t *, frame_flags_t);
  • 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.
  • kernel/test/mm/mapping1.c

    rbf31e3f r3d4750f  
    6666                v = *((uint32_t *) page1);
    6767       
    68                 if (v != TEST_MAGIC)
     68                if (v != TEST_MAGIC) {
     69                        km_unmap(page0, PAGE_SIZE);
     70                        km_unmap(page1, PAGE_SIZE);
     71                        frame_free(frame);
    6972                        return "Criss-cross read does not match the value written.";
     73                }
    7074
    7175                TPRINTF("Writing zero using the second virtual address.\n");
     
    7781                v = *((uint32_t *) page0);
    7882       
    79                 if (v != 0)
     83                if (v != 0) {
     84                        km_unmap(page0, PAGE_SIZE);
     85                        km_unmap(page1, PAGE_SIZE);
     86                        frame_free(frame);
    8087                        return "Criss-cross read does not match the value written.";
     88                }
    8189        }
    8290
    83         // FIXME: do not leak frame, page0 and page1
     91        km_unmap(page0, PAGE_SIZE);
     92        km_unmap(page1, PAGE_SIZE);
     93        frame_free(frame);
    8494       
    8595        return NULL;
  • kernel/test/mm/mapping1.def

    rbf31e3f r3d4750f  
    33        "Mapping test",
    44        &test_mapping1,
    5         false
     5        true   
    66},
Note: See TracChangeset for help on using the changeset viewer.