Ignore:
File:
1 edited

Legend:

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

    r235e6c7 rc72dc15  
    3939#include <mm/page.h>
    4040#include <mm/frame.h>
     41#include <mm/km.h>
    4142#include <mm/as.h>
    4243#include <arch/mm/page.h>
     
    7576       
    7677        if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) {
    77                 pte_t *newpt = (pte_t *) frame_alloc(PTL1_SIZE, FRAME_KA);
     78                pte_t *newpt = (pte_t *) frame_alloc(PTL1_SIZE,
     79                    FRAME_LOWMEM | FRAME_KA);
    7880                memsetb(newpt, FRAME_SIZE << PTL1_SIZE, 0);
    7981                SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page), KA2PA(newpt));
    80                 SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
     82                SET_PTL1_FLAGS(ptl0, PTL0_INDEX(page),
     83                    PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
     84                    PAGE_WRITE);
    8185        }
    8286       
     
    8488       
    8589        if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT) {
    86                 pte_t *newpt = (pte_t *) frame_alloc(PTL2_SIZE, FRAME_KA);
     90                pte_t *newpt = (pte_t *) frame_alloc(PTL2_SIZE,
     91                    FRAME_LOWMEM | FRAME_KA);
    8792                memsetb(newpt, FRAME_SIZE << PTL2_SIZE, 0);
    8893                SET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page), KA2PA(newpt));
    89                 SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
     94                SET_PTL2_FLAGS(ptl1, PTL1_INDEX(page),
     95                    PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
     96                    PAGE_WRITE);
    9097        }
    9198       
     
    93100       
    94101        if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT) {
    95                 pte_t *newpt = (pte_t *) frame_alloc(PTL3_SIZE, FRAME_KA);
     102                pte_t *newpt = (pte_t *) frame_alloc(PTL3_SIZE,
     103                    FRAME_LOWMEM | FRAME_KA);
    96104                memsetb(newpt, FRAME_SIZE << PTL3_SIZE, 0);
    97105                SET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page), KA2PA(newpt));
    98                 SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page), PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE | PAGE_WRITE);
     106                SET_PTL3_FLAGS(ptl2, PTL2_INDEX(page),
     107                    PAGE_PRESENT | PAGE_USER | PAGE_EXEC | PAGE_CACHEABLE |
     108                    PAGE_WRITE);
    99109        }
    100110       
     
    144154       
    145155        /*
    146          * Second, free all empty tables along the way from PTL3 down to PTL0.
    147          *
     156         * Second, free all empty tables along the way from PTL3 down to PTL0
     157         * except those needed for sharing the kernel non-identity mappings.
    148158         */
    149159       
     
    162172                /*
    163173                 * PTL3 is empty.
    164                  * Release the frame and remove PTL3 pointer from preceding table.
    165                  *
    166                  */
    167                 frame_free(KA2PA((uintptr_t) ptl3));
     174                 * Release the frame and remove PTL3 pointer from the parent
     175                 * table.
     176                 */
    168177#if (PTL2_ENTRIES != 0)
    169178                memsetb(&ptl2[PTL2_INDEX(page)], sizeof(pte_t), 0);
     
    171180                memsetb(&ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
    172181#else
     182                if (km_is_non_identity(page))
     183                        return;
     184
    173185                memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
    174186#endif
     187                frame_free(KA2PA((uintptr_t) ptl3));
    175188        } else {
    176189                /*
     
    195208                /*
    196209                 * PTL2 is empty.
    197                  * Release the frame and remove PTL2 pointer from preceding table.
    198                  *
    199                  */
    200                 frame_free(KA2PA((uintptr_t) ptl2));
     210                 * Release the frame and remove PTL2 pointer from the parent
     211                 * table.
     212                 */
    201213#if (PTL1_ENTRIES != 0)
    202214                memsetb(&ptl1[PTL1_INDEX(page)], sizeof(pte_t), 0);
    203215#else
     216                if (km_is_non_identity(page))
     217                        return;
     218
    204219                memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
    205220#endif
     221                frame_free(KA2PA((uintptr_t) ptl2));
    206222        } else {
    207223                /*
     
    227243                /*
    228244                 * PTL1 is empty.
    229                  * Release the frame and remove PTL1 pointer from preceding table.
    230                  *
    231                  */
     245                 * Release the frame and remove PTL1 pointer from the parent
     246                 * table.
     247                 */
     248                if (km_is_non_identity(page))
     249                        return;
     250
     251                memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
    232252                frame_free(KA2PA((uintptr_t) ptl1));
    233                 memsetb(&ptl0[PTL0_INDEX(page)], sizeof(pte_t), 0);
    234253        }
    235254#endif /* PTL1_ENTRIES != 0 */
Note: See TracChangeset for help on using the changeset viewer.