Changeset 8cbf1c3 in mainline


Ignore:
Timestamp:
2013-09-09T23:13:10Z (11 years ago)
Author:
Martin Decky <martin@…>
Branches:
lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
Children:
e2a0d76
Parents:
c67dbd6
Message:

prepare the public API of the frame allocator for the new backend
remove FRAME_KA (can be easily implemented explicitly)

Location:
kernel
Files:
20 edited

Legend:

Unmodified
Added
Removed
  • kernel/arch/arm32/src/mm/page.c

    rc67dbd6 r8cbf1c3  
    6969#ifdef HIGH_EXCEPTION_VECTORS
    7070        /* Create mapping for exception table at high offset */
    71         uintptr_t ev_frame = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_NONE);
     71        uintptr_t ev_frame = frame_alloc(ONE_FRAME, FRAME_NONE, 0);
    7272        page_mapping_insert(AS_KERNEL, EXC_BASE_ADDRESS, ev_frame, flags);
    7373#else
  • kernel/arch/arm32/src/ras.c

    rc67dbd6 r8cbf1c3  
    5353        uintptr_t frame;
    5454
    55         frame = (uintptr_t) frame_alloc(ONE_FRAME,
    56             FRAME_ATOMIC | FRAME_HIGHMEM);
     55        frame = frame_alloc(ONE_FRAME,
     56            FRAME_ATOMIC | FRAME_HIGHMEM, 0);
    5757        if (!frame)
    58                 frame = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_LOWMEM);
     58                frame = frame_alloc(ONE_FRAME, FRAME_LOWMEM, 0);
    5959        ras_page = (uintptr_t *) km_map(frame,
    6060            PAGE_SIZE, PAGE_READ | PAGE_WRITE | PAGE_USER | PAGE_CACHEABLE);
  • kernel/arch/ia64/src/mm/vhpt.c

    rc67dbd6 r8cbf1c3  
    4242uintptr_t vhpt_set_up(void)
    4343{
    44         vhpt_base = frame_alloc(VHPT_WIDTH - FRAME_WIDTH,
    45             FRAME_KA | FRAME_ATOMIC);
     44        vhpt_base = (vhpt_entry_t *) PA2KA(frame_alloc(VHPT_WIDTH - FRAME_WIDTH,
     45            FRAME_ATOMIC, 0));
    4646        if (!vhpt_base)
    4747                panic("Kernel configured with VHPT but no memory for table.");
  • kernel/arch/sparc64/src/mm/sun4u/as.c

    rc67dbd6 r8cbf1c3  
    7171            sizeof(tsb_entry_t)) >> FRAME_WIDTH);
    7272       
    73         uintptr_t tsb = (uintptr_t) frame_alloc(order, flags | FRAME_KA);
     73        uintptr_t tsb = PA2KA(frame_alloc(order, flags, 0));
    7474       
    7575        if (!tsb)
  • kernel/arch/sparc64/src/mm/sun4v/as.c

    rc67dbd6 r8cbf1c3  
    6969                (TSB_ENTRY_COUNT * sizeof(tsb_entry_t)) >> FRAME_WIDTH);
    7070       
    71         uintptr_t tsb = (uintptr_t) frame_alloc(order, flags);
     71        uintptr_t tsb = frame_alloc(order, flags, 0);
    7272       
    7373        if (!tsb)
  • kernel/genarch/src/mm/as_pt.c

    rc67dbd6 r8cbf1c3  
    7373pte_t *ptl0_create(unsigned int flags)
    7474{
    75         pte_t *dst_ptl0 = (pte_t *) frame_alloc(PTL0_SIZE,
    76             FRAME_LOWMEM | FRAME_KA);
     75        pte_t *dst_ptl0 = (pte_t *) PA2KA(frame_alloc(PTL0_SIZE,
     76            FRAME_LOWMEM, 0));
    7777        size_t table_size = FRAME_SIZE << PTL0_SIZE;
    7878       
  • kernel/genarch/src/mm/page_pt.c

    rc67dbd6 r8cbf1c3  
    8282       
    8383        if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) {
    84                 pte_t *newpt = (pte_t *) frame_alloc(PTL1_SIZE,
    85                     FRAME_LOWMEM | FRAME_KA);
     84                pte_t *newpt = (pte_t *) PA2KA(frame_alloc(PTL1_SIZE,
     85                    FRAME_LOWMEM, 0));
    8686                memsetb(newpt, FRAME_SIZE << PTL1_SIZE, 0);
    8787                SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(page), KA2PA(newpt));
     
    101101       
    102102        if (GET_PTL2_FLAGS(ptl1, PTL1_INDEX(page)) & PAGE_NOT_PRESENT) {
    103                 pte_t *newpt = (pte_t *) frame_alloc(PTL2_SIZE,
    104                     FRAME_LOWMEM | FRAME_KA);
     103                pte_t *newpt = (pte_t *) PA2KA(frame_alloc(PTL2_SIZE,
     104                    FRAME_LOWMEM, 0));
    105105                memsetb(newpt, FRAME_SIZE << PTL2_SIZE, 0);
    106106                SET_PTL2_ADDRESS(ptl1, PTL1_INDEX(page), KA2PA(newpt));
     
    118118       
    119119        if (GET_PTL3_FLAGS(ptl2, PTL2_INDEX(page)) & PAGE_NOT_PRESENT) {
    120                 pte_t *newpt = (pte_t *) frame_alloc(PTL3_SIZE,
    121                     FRAME_LOWMEM | FRAME_KA);
     120                pte_t *newpt = (pte_t *) PA2KA(frame_alloc(PTL3_SIZE,
     121                    FRAME_LOWMEM, 0));
    122122                memsetb(newpt, FRAME_SIZE << PTL3_SIZE, 0);
    123123                SET_PTL3_ADDRESS(ptl2, PTL2_INDEX(page), KA2PA(newpt));
     
    385385                uintptr_t l1;
    386386
    387                 l1 = (uintptr_t) frame_alloc(order, FRAME_KA | FRAME_LOWMEM);
     387                l1 = PA2KA(frame_alloc(order, FRAME_LOWMEM, 0));
    388388                memsetb((void *) l1, FRAME_SIZE << order, 0);
    389389                SET_PTL1_ADDRESS(ptl0, PTL0_INDEX(addr), KA2PA(l1));
  • kernel/generic/include/mm/frame.h

    rc67dbd6 r8cbf1c3  
    5050typedef uint8_t frame_flags_t;
    5151
    52 #define FRAME_NONE        0x0
    53 /** Convert the frame address to kernel VA. */
    54 #define FRAME_KA          0x1
     52#define FRAME_NONE        0x00
    5553/** Do not panic and do not sleep on failure. */
    56 #define FRAME_ATOMIC      0x2
     54#define FRAME_ATOMIC      0x01
    5755/** Do not start reclaiming when no free memory. */
    58 #define FRAME_NO_RECLAIM  0x4
     56#define FRAME_NO_RECLAIM  0x02
    5957/** Do not reserve / unreserve memory. */
    60 #define FRAME_NO_RESERVE  0x8
     58#define FRAME_NO_RESERVE  0x04
    6159/** Allocate a frame which can be identity-mapped. */
    62 #define FRAME_LOWMEM      0x10
     60#define FRAME_LOWMEM      0x08
    6361/** Allocate a frame which cannot be identity-mapped. */
    64 #define FRAME_HIGHMEM     0x20
     62#define FRAME_HIGHMEM     0x10
    6563
    6664typedef uint8_t zone_flags_t;
    6765
    68 #define ZONE_NONE       0x0
     66#define ZONE_NONE       0x00
    6967/** Available zone (free for allocation) */
    70 #define ZONE_AVAILABLE  0x1
     68#define ZONE_AVAILABLE  0x01
    7169/** Zone is reserved (not available for allocation) */
    72 #define ZONE_RESERVED   0x2
     70#define ZONE_RESERVED   0x02
    7371/** Zone is used by firmware (not available for allocation) */
    74 #define ZONE_FIRMWARE   0x4
     72#define ZONE_FIRMWARE   0x04
    7573/** Zone contains memory that can be identity-mapped */
    76 #define ZONE_LOWMEM     0x8
     74#define ZONE_LOWMEM     0x08
    7775/** Zone contains memory that cannot be identity-mapped */
    78 #define ZONE_HIGHMEM    0x10
     76#define ZONE_HIGHMEM    0x10
    7977
    8078/** Mask of zone bits that must be matched exactly. */
    81 #define ZONE_EF_MASK    0x7
     79#define ZONE_EF_MASK  0x07
    8280
    8381#define FRAME_TO_ZONE_FLAGS(ff) \
     
    138136NO_TRACE static inline size_t SIZE2FRAMES(size_t size)
    139137{
    140         if (!size)
     138        if (size == 0)
    141139                return 0;
     140       
    142141        return (size_t) ((size - 1) >> FRAME_WIDTH) + 1;
    143142}
     
    161160extern void frame_init(void);
    162161extern bool frame_adjust_zone_bounds(bool, uintptr_t *, size_t *);
    163 extern void *frame_alloc_generic(uint8_t, frame_flags_t, size_t *);
    164 extern void *frame_alloc(uint8_t, frame_flags_t);
    165 extern void *frame_alloc_noreserve(uint8_t, frame_flags_t);
     162extern uintptr_t frame_alloc_generic(uint8_t, frame_flags_t, uintptr_t, size_t *);
     163extern uintptr_t frame_alloc(uint8_t, frame_flags_t, uintptr_t);
     164extern uintptr_t frame_alloc_noreserve(uint8_t, frame_flags_t, uintptr_t);
    166165extern void frame_free_generic(uintptr_t, frame_flags_t);
    167166extern void frame_free(uintptr_t);
  • kernel/generic/include/mm/page.h

    rc67dbd6 r8cbf1c3  
    6565extern void page_table_destroy(pte_t *);
    6666
    67 extern int page_find_mapping(uintptr_t, void **);
    68 extern sysarg_t sys_page_find_mapping(uintptr_t, void *);
     67extern int page_find_mapping(uintptr_t, uintptr_t *);
     68extern sysarg_t sys_page_find_mapping(uintptr_t, uintptr_t *);
    6969
    7070#endif
  • kernel/generic/src/cpu/cpu.c

    rc67dbd6 r8cbf1c3  
    7373                size_t i;
    7474                for (i = 0; i < config.cpu_count; i++) {
    75                         cpus[i].stack = (uint8_t *) frame_alloc(STACK_FRAMES,
    76                             FRAME_LOWMEM | FRAME_KA | FRAME_ATOMIC);
     75                        cpus[i].stack = (uint8_t *) PA2KA(frame_alloc(STACK_FRAMES,
     76                            FRAME_LOWMEM | FRAME_ATOMIC, 0));
    7777                        cpus[i].id = i;
    7878                       
  • kernel/generic/src/ddi/ddi.c

    rc67dbd6 r8cbf1c3  
    314314
    315315NO_TRACE static int dmamem_map(uintptr_t virt, size_t size, unsigned int map_flags,
    316     unsigned int flags, void **phys)
     316    unsigned int flags, uintptr_t *phys)
    317317{
    318318        ASSERT(TASK);
     
    323323
    324324NO_TRACE static int dmamem_map_anonymous(size_t size, unsigned int map_flags,
    325     unsigned int flags, void **phys, uintptr_t *virt, uintptr_t bound)
     325    unsigned int flags, uintptr_t *phys, uintptr_t *virt, uintptr_t bound)
    326326{
    327327        ASSERT(TASK);
     
    336336                order = fnzb(pages - 1) + 1;
    337337       
    338         *phys = frame_alloc_noreserve(order, 0);
    339         if (*phys == NULL)
     338        *phys = frame_alloc_noreserve(order, 0, 0);
     339        if (*phys == 0)
    340340                return ENOMEM;
    341341       
    342342        mem_backend_data_t backend_data;
    343         backend_data.base = (uintptr_t) *phys;
     343        backend_data.base = *phys;
    344344        backend_data.frames = pages;
    345345       
    346346        if (!as_area_create(TASK->as, map_flags, size,
    347347            AS_AREA_ATTR_NONE, &phys_backend, &backend_data, virt, bound)) {
    348                 frame_free_noreserve((uintptr_t) *phys);
     348                frame_free_noreserve(*phys);
    349349                return ENOMEM;
    350350        }
     
    387387                 */
    388388               
    389                 void *phys;
     389                uintptr_t phys;
    390390                int rc = dmamem_map((uintptr_t) virt_ptr, size, map_flags,
    391391                    flags, &phys);
     
    404404                 */
    405405               
    406                 void *phys;
     406                uintptr_t phys;
    407407                uintptr_t virt = (uintptr_t) -1;
    408408                int rc = dmamem_map_anonymous(size, map_flags, flags,
  • kernel/generic/src/mm/frame.c

    rc67dbd6 r8cbf1c3  
    873873
    874874        return ADDR2PFN((uintptr_t) frame_alloc(order - FRAME_WIDTH,
    875             FRAME_LOWMEM | FRAME_ATOMIC));
     875            FRAME_LOWMEM | FRAME_ATOMIC, 0));
    876876}
    877877
     
    10241024 *
    10251025 */
    1026 void *frame_alloc_generic(uint8_t order, frame_flags_t flags, size_t *pzone)
     1026uintptr_t frame_alloc_generic(uint8_t order, frame_flags_t flags,
     1027    uintptr_t constraint, size_t *pzone)
    10271028{
    10281029        size_t size = ((size_t) 1) << order;
     
    10711072                        if (!(flags & FRAME_NO_RESERVE))
    10721073                                reserve_free(size);
    1073                         return NULL;
     1074                        return 0;
    10741075                }
    10751076               
     
    11261127                *pzone = znum;
    11271128       
    1128         if (flags & FRAME_KA)
    1129                 return (void *) PA2KA(PFN2ADDR(pfn));
    1130        
    1131         return (void *) PFN2ADDR(pfn);
    1132 }
    1133 
    1134 void *frame_alloc(uint8_t order, frame_flags_t flags)
    1135 {
    1136         return frame_alloc_generic(order, flags, NULL);
    1137 }
    1138 
    1139 void *frame_alloc_noreserve(uint8_t order, frame_flags_t flags)
    1140 {
    1141         return frame_alloc_generic(order, flags | FRAME_NO_RESERVE, NULL);
     1129        return PFN2ADDR(pfn);
     1130}
     1131
     1132uintptr_t frame_alloc(uint8_t order, frame_flags_t flags, uintptr_t constraint)
     1133{
     1134        return frame_alloc_generic(order, flags, constraint, NULL);
     1135}
     1136
     1137uintptr_t frame_alloc_noreserve(uint8_t order, frame_flags_t flags,
     1138    uintptr_t constraint)
     1139{
     1140        return frame_alloc_generic(order, flags | FRAME_NO_RESERVE, constraint,
     1141            NULL);
    11421142}
    11431143
  • kernel/generic/src/mm/km.c

    rc67dbd6 r8cbf1c3  
    249249         * Allocate a frame, preferably from high memory.
    250250         */
    251         frame = (uintptr_t) frame_alloc(ONE_FRAME,
    252             FRAME_HIGHMEM | FRAME_ATOMIC | flags);
     251        frame = frame_alloc(ONE_FRAME,
     252            FRAME_HIGHMEM | FRAME_ATOMIC | flags, 0);
    253253        if (frame) {
    254254                page = km_map(frame, PAGE_SIZE,
     
    256256                ASSERT(page);   // FIXME
    257257        } else {
    258                 frame = (uintptr_t) frame_alloc(ONE_FRAME,
    259                     FRAME_LOWMEM | flags);
     258                frame = frame_alloc(ONE_FRAME, FRAME_LOWMEM | flags, 0);
    260259                if (!frame)
    261260                        return (uintptr_t) NULL;
  • kernel/generic/src/mm/page.c

    rc67dbd6 r8cbf1c3  
    169169}
    170170
    171 int page_find_mapping(uintptr_t virt, void **phys)
     171int page_find_mapping(uintptr_t virt, uintptr_t *phys)
    172172{
    173173        page_table_lock(AS, true);
     
    179179        }
    180180       
    181         *phys = (void *) PTE_GET_FRAME(pte) +
     181        *phys = PTE_GET_FRAME(pte) +
    182182            (virt - ALIGN_DOWN(virt, PAGE_SIZE));
    183183       
     
    193193 *
    194194 */
    195 sysarg_t sys_page_find_mapping(uintptr_t virt, void *phys_ptr)
    196 {
    197         void *phys;
     195sysarg_t sys_page_find_mapping(uintptr_t virt, uintptr_t *phys_ptr)
     196{
     197        uintptr_t phys;
    198198        int rc = page_find_mapping(virt, &phys);
    199199        if (rc != EOK)
  • kernel/generic/src/mm/slab.c

    rc67dbd6 r8cbf1c3  
    182182        size_t zone = 0;
    183183       
    184         void *data = frame_alloc_generic(cache->order, FRAME_KA | flags, &zone);
     184        void *data = (void *)
     185            PA2KA(frame_alloc_generic(cache->order, flags, 0, &zone));
    185186        if (!data) {
    186187                return NULL;
  • kernel/generic/src/proc/thread.c

    rc67dbd6 r8cbf1c3  
    192192        kmflags &= ~FRAME_HIGHMEM;
    193193       
    194         thread->kstack = (uint8_t *) frame_alloc(STACK_FRAMES, FRAME_KA | kmflags);
     194        thread->kstack = (uint8_t *)
     195            PA2KA(frame_alloc(STACK_FRAMES, kmflags, 0));
    195196        if (!thread->kstack) {
    196197#ifdef CONFIG_FPU
  • kernel/generic/src/time/clock.c

    rc67dbd6 r8cbf1c3  
    8181void clock_counter_init(void)
    8282{
    83         void *faddr = frame_alloc(ONE_FRAME, FRAME_ATOMIC);
    84         if (!faddr)
     83        uintptr_t faddr = frame_alloc(ONE_FRAME, FRAME_ATOMIC, 0);
     84        if (faddr == 0)
    8585                panic("Cannot allocate page for clock.");
    8686       
     
    9191        uptime->useconds = 0;
    9292       
    93         clock_parea.pbase = (uintptr_t) faddr;
     93        clock_parea.pbase = faddr;
    9494        clock_parea.frames = 1;
    9595        clock_parea.unpriv = true;
  • kernel/test/mm/falloc1.c

    rc67dbd6 r8cbf1c3  
    5858                        unsigned int allocated = 0;
    5959                        for (unsigned int i = 0; i < (MAX_FRAMES >> order); i++) {
    60                                 frames[allocated] = (uintptr_t)
    61                                     frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
     60                                frames[allocated] =
     61                                    PA2KA(frame_alloc(order, FRAME_ATOMIC, 0));
    6262                               
    6363                                if (ALIGN_UP(frames[allocated], FRAME_SIZE << order) !=
  • kernel/test/mm/falloc2.c

    rc67dbd6 r8cbf1c3  
    5353        uint8_t val = THREAD->tid % THREADS;
    5454       
    55         void **frames = (void **)
    56             malloc(MAX_FRAMES * sizeof(void *), FRAME_ATOMIC);
     55        uintptr_t *frames = (uintptr_t *)
     56            malloc(MAX_FRAMES * sizeof(uintptr_t), FRAME_ATOMIC);
    5757        if (frames == NULL) {
    5858                TPRINTF("Thread #%" PRIu64 " (cpu%u): "
     
    7474                        for (unsigned int i = 0; i < (MAX_FRAMES >> order); i++) {
    7575                                frames[allocated] =
    76                                     frame_alloc(order, FRAME_ATOMIC | FRAME_KA);
     76                                    PA2KA(frame_alloc(order, FRAME_ATOMIC, 0));
    7777                                if (frames[allocated]) {
    78                                         memsetb(frames[allocated], FRAME_SIZE << order, val);
     78                                        memsetb((void *) frames[allocated], FRAME_SIZE << order, val);
    7979                                        allocated++;
    8080                                } else
     
    9393                                        if (((uint8_t *) frames[i])[k] != val) {
    9494                                                TPRINTF("Thread #%" PRIu64 " (cpu%u): "
    95                                                     "Unexpected data (%c) in block %p offset %zu\n",
     95                                                    "Unexpected data (%c) in block %zu offset %zu\n",
    9696                                                    THREAD->tid, CPU->id, ((char *) frames[i])[k],
    9797                                                    frames[i], k);
  • kernel/test/mm/mapping1.c

    rc67dbd6 r8cbf1c3  
    4242{
    4343        uintptr_t page0, page1;
    44         uintptr_t frame;
    4544        uint32_t v;
    4645        int i;
    4746       
    48         frame = (uintptr_t) frame_alloc(ONE_FRAME, FRAME_NONE);
    49 
     47        uintptr_t frame = frame_alloc(ONE_FRAME, FRAME_NONE, 0);
     48       
    5049        page0 = km_map(frame, FRAME_SIZE,
    5150            PAGE_READ | PAGE_WRITE | PAGE_CACHEABLE);
Note: See TracChangeset for help on using the changeset viewer.