Ignore:
File:
1 edited

Legend:

Unmodified
Added
Removed
  • kernel/genarch/src/mm/page_pt.c

    ra2789d2 r235e6c7  
    3939#include <mm/page.h>
    4040#include <mm/frame.h>
    41 #include <mm/km.h>
    4241#include <mm/as.h>
    4342#include <arch/mm/page.h>
     
    4645#include <arch/asm.h>
    4746#include <memstr.h>
    48 #include <align.h>
    49 #include <macros.h>
    5047
    5148static void pt_mapping_insert(as_t *, uintptr_t, uintptr_t, unsigned int);
    5249static void pt_mapping_remove(as_t *, uintptr_t);
    5350static pte_t *pt_mapping_find(as_t *, uintptr_t, bool);
    54 static void pt_mapping_make_global(uintptr_t, size_t);
    5551
    5652page_mapping_operations_t pt_mapping_operations = {
    5753        .mapping_insert = pt_mapping_insert,
    5854        .mapping_remove = pt_mapping_remove,
    59         .mapping_find = pt_mapping_find,
    60         .mapping_make_global = pt_mapping_make_global
     55        .mapping_find = pt_mapping_find
    6156};
    6257
     
    8075       
    8176        if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) {
    82                 pte_t *newpt = (pte_t *) frame_alloc(PTL1_SIZE,
    83                     FRAME_LOWMEM | FRAME_KA);
     77                pte_t *newpt = (pte_t *) frame_alloc(PTL1_SIZE, FRAME_KA);
    8478                memsetb(newpt, FRAME_SIZE << PTL1_SIZE, 0);
    8579                SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page), KA2PA(newpt));
    86                 SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page),
    87                     PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
    88                     PAGE_WRITE);
     80                SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
    8981        }
    9082       
     
    9284       
    9385        if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT) {
    94                 pte_t *newpt = (pte_t *) frame_alloc(PTL2_SIZE,
    95                     FRAME_LOWMEM | FRAME_KA);
     86                pte_t *newpt = (pte_t *) frame_alloc(PTL2_SIZE, FRAME_KA);
    9687                memsetb(newpt, FRAME_SIZE << PTL2_SIZE, 0);
    9788                SET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page), KA2PA(newpt));
    98                 SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page),
    99                     PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
    100                     PAGE_WRITE);
     89                SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
    10190        }
    10291       
     
    10493       
    10594        if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT) {
    106                 pte_t *newpt = (pte_t *) frame_alloc(PTL3_SIZE,
    107                     FRAME_LOWMEM | FRAME_KA);
     95                pte_t *newpt = (pte_t *) frame_alloc(PTL3_SIZE, FRAME_KA);
    10896                memsetb(newpt, FRAME_SIZE << PTL3_SIZE, 0);
    10997                SET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page), KA2PA(newpt));
    110                 SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page),
    111                     PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
    112                     PAGE_WRITE);
     98                SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
    11399        }
    114100       
     
    137123        /*
    138124         * First, remove the mapping, if it exists.
     125         *
    139126         */
    140127       
     
    153140        pte_t *ptl3 = (pte_t *) PA2KA(GET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page)));
    154141       
     142        /* Destroy the mapping. Setting to PAGE_NOT_PRESENT is not sufficient. */
     143        memsetb(&ptl3[PTL3_INDEX(page)], sizeof(pte_t), 0);
     144       
    155145        /*
    156          * Destroy the mapping.
    157          * Setting to PAGE_NOT_PRESENT is not sufficient.
    158          */
    159         memsetb(&ptl3[PTL3_INDEX(page)], sizeof(pte_t), 0);
    160        
    161         /*
    162          * Second, free all empty tables along the way from PTL3 down to PTL0
    163          * except those needed for sharing the kernel non-identity mappings.
     146         * Second, free all empty tables along the way from PTL3 down to PTL0.
     147         *
    164148         */
    165149       
     
    178162                /*
    179163                 * PTL3 is empty.
    180                  * Release the frame and remove PTL3 pointer from the parent
    181                  * table.
    182                  */
     164                 * Release the frame and remove PTL3 pointer from preceding table.
     165                 *
     166                 */
     167                frame_free(KA2PA((uintptr_t) ptl3));
    183168#if (PTL2_ENTRIES != 0)
    184169                memsetb(&ptl2[PTL2_INDEX(page)], sizeof(pte_t), 0);
     
    186171                memsetb(&ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
    187172#else
    188                 if (km_is_non_identity(page))
    189                         return;
    190 
    191173                memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
    192174#endif
    193                 frame_free(KA2PA((uintptr_t) ptl3));
    194175        } else {
    195176                /*
     
    214195                /*
    215196                 * PTL2 is empty.
    216                  * Release the frame and remove PTL2 pointer from the parent
    217                  * table.
    218                  */
     197                 * Release the frame and remove PTL2 pointer from preceding table.
     198                 *
     199                 */
     200                frame_free(KA2PA((uintptr_t) ptl2));
    219201#if (PTL1_ENTRIES != 0)
    220202                memsetb(&ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
    221203#else
    222                 if (km_is_non_identity(page))
    223                         return;
    224 
    225204                memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
    226205#endif
    227                 frame_free(KA2PA((uintptr_t) ptl2));
    228206        } else {
    229207                /*
     
    249227                /*
    250228                 * PTL1 is empty.
    251                  * Release the frame and remove PTL1 pointer from the parent
    252                  * table.
    253                  */
    254                 if (km_is_non_identity(page))
    255                         return;
    256 
     229                 * Release the frame and remove PTL1 pointer from preceding table.
     230                 *
     231                 */
     232                frame_free(KA2PA((uintptr_t) ptl1));
    257233                memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
    258                 frame_free(KA2PA((uintptr_t) ptl1));
    259234        }
    260235#endif /* PTL1_ENTRIES != 0 */
     
    292267}
    293268
    294 /** Make the mappings in the given range global accross all address spaces.
    295  *
    296  * All PTL0 entries in the given range will be mapped to a next level page
    297  * table. The next level page table will be allocated and cleared.
    298  *
    299  * pt_mapping_remove() will never deallocate these page tables even when there
    300  * are no PTEs in them.
    301  *
    302  * @param as   Address space.
    303  * @param base Base address corresponding to the first PTL0 entry that will be
    304  *             altered by this function.
    305  * @param size Size in bytes defining the range of PTL0 entries that will be
    306  *             altered by this function.
    307  */
    308 void pt_mapping_make_global(uintptr_t base, size_t size)
    309 {
    310         uintptr_t ptl0 = PA2KA((uintptr_t) AS_KERNEL->genarch.page_table);
    311         uintptr_t ptl0step = (((uintptr_t) -1) / PTL0_ENTRIES) + 1;
    312         size_t order;
    313         uintptr_t addr;
    314 
    315 #if (PTL1_ENTRIES != 0)
    316         order = PTL1_SIZE;
    317 #elif (PTL2_ENTRIES != 0)
    318         order = PTL2_SIZE;
    319 #else
    320         order = PTL3_SIZE;
    321 #endif
    322 
    323         ASSERT(ispwr2(ptl0step));
    324         ASSERT(size > 0);
    325 
    326         for (addr = ALIGN_DOWN(base, ptl0step); addr - 1 < base + size - 1;
    327             addr += ptl0step) {
    328                 uintptr_t l1;
    329 
    330                 l1 = (uintptr_t) frame_alloc(order, FRAME_KA | FRAME_LOWMEM);
    331                 memsetb((void *) l1, FRAME_SIZE << order, 0);
    332                 SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(addr), KA2PA(l1));
    333                 SET_PTL1_FLAGS(ptl0, PTL0_INDEX(addr),
    334                     PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
    335                     PAGE_WRITE);
    336         }
    337 }
    338 
    339269/** @}
    340270 */
Note: See TracChangeset for help on using the changeset viewer.