Changes in kernel/generic/include/mm/frame.h [f72906c:aaceebc4] in mainline
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/mm/frame.h
rf72906c raaceebc4 39 39 #include <typedefs.h> 40 40 #include <trace.h> 41 #include <adt/bitmap.h>42 41 #include <adt/list.h> 42 #include <mm/buddy.h> 43 43 #include <synch/spinlock.h> 44 44 #include <arch/mm/page.h> … … 50 50 typedef uint8_t frame_flags_t; 51 51 52 #define FRAME_NONE 0x00 52 #define FRAME_NONE 0x0 53 /** Convert the frame address to kernel VA. */ 54 #define FRAME_KA 0x1 53 55 /** Do not panic and do not sleep on failure. */ 54 #define FRAME_ATOMIC 0x 0156 #define FRAME_ATOMIC 0x2 55 57 /** Do not start reclaiming when no free memory. */ 56 #define FRAME_NO_RECLAIM 0x 0258 #define FRAME_NO_RECLAIM 0x4 57 59 /** Do not reserve / unreserve memory. */ 58 #define FRAME_NO_RESERVE 0x 0460 #define FRAME_NO_RESERVE 0x8 59 61 /** Allocate a frame which can be identity-mapped. */ 60 #define FRAME_LOWMEM 0x0862 #define FRAME_LOWMEM 0x10 61 63 /** Allocate a frame which cannot be identity-mapped. */ 62 #define FRAME_HIGHMEM 0x10 64 #define FRAME_HIGHMEM 0x20 65 /** Allocate a frame which needs to be from DMA zone. */ 66 #define FRAME_DMA 0x40 63 67 64 68 typedef uint8_t zone_flags_t; 65 69 66 #define ZONE_NONE 0x0070 #define ZONE_NONE 0x0 67 71 /** Available zone (free for allocation) */ 68 #define ZONE_AVAILABLE 0x 0172 #define ZONE_AVAILABLE 0x1 69 73 /** Zone is reserved (not available for allocation) */ 70 #define ZONE_RESERVED 0x 0274 #define ZONE_RESERVED 0x2 71 75 /** Zone is used by firmware (not available for allocation) */ 72 #define ZONE_FIRMWARE 0x 0476 #define ZONE_FIRMWARE 0x4 73 77 /** Zone contains memory that can be identity-mapped */ 74 #define ZONE_LOWMEM 0x0878 #define ZONE_LOWMEM 0x8 75 79 /** Zone contains memory that cannot be identity-mapped */ 76 #define ZONE_HIGHMEM 0x10 80 #define ZONE_HIGHMEM 0x10 81 /** Zone contains memory suitable for old ISA DMA */ 82 #define ZONE_DMA 0x20 77 83 78 84 /** Mask of zone bits that must be matched exactly. */ 79 #define ZONE_EF_MASK 0x0785 #define ZONE_EF_MASK 0x7 80 86 81 #define FRAME_TO_ZONE_FLAGS(ff) \ 82 ((((ff) & FRAME_LOWMEM) ? ZONE_LOWMEM : \ 87 #define FRAME_TO_ZONE_FLAGS(ff) \ 88 ((((ff) & FRAME_DMA) ? ZONE_DMA : \ 89 (((ff) & FRAME_LOWMEM) ? ZONE_LOWMEM : \ 83 90 (((ff) & FRAME_HIGHMEM) ? ZONE_HIGHMEM : \ 84 ZONE_LOWMEM /* | ZONE_HIGHMEM */)) | \91 ZONE_LOWMEM /* | ZONE_HIGHMEM */))) | \ 85 92 ZONE_AVAILABLE) 86 93 … … 90 97 91 98 typedef struct { 92 size_t refcount; /**< Tracking of shared frames */ 93 void *parent; /**< If allocated by slab, this points there */ 99 size_t refcount; /**< Tracking of shared frames */ 100 link_t buddy_link; /**< Link to the next free block inside 101 one order */ 102 void *parent; /**< If allocated by slab, this points there */ 103 uint8_t buddy_order; /**< Buddy system block order */ 94 104 } frame_t; 95 105 96 106 typedef struct { 97 /** Frame_no of the first frame in the frames array */ 98 pfn_t base; 107 pfn_t base; /**< Frame_no of the first frame 108 in the frames array */ 109 size_t count; /**< Size of zone */ 110 size_t free_count; /**< Number of free frame_t 111 structures */ 112 size_t busy_count; /**< Number of busy frame_t 113 structures */ 114 zone_flags_t flags; /**< Type of the zone */ 99 115 100 /** Size of zone */ 101 size_t count; 102 103 /** Number of free frame_t structures */ 104 size_t free_count; 105 106 /** Number of busy frame_t structures */ 107 size_t busy_count; 108 109 /** Type of the zone */ 110 zone_flags_t flags; 111 112 /** Frame bitmap */ 113 bitmap_t bitmap; 114 115 /** Array of frame_t structures in this zone */ 116 frame_t *frames; 116 frame_t *frames; /**< Array of frame_t structures 117 in this zone */ 118 buddy_system_t *buddy_system; /**< Buddy system for the zone */ 117 119 } zone_t; 118 120 … … 129 131 extern zones_t zones; 130 132 133 NO_TRACE static inline uintptr_t PFN2ADDR(pfn_t frame) 134 { 135 return (uintptr_t) (frame << FRAME_WIDTH); 136 } 137 138 NO_TRACE static inline pfn_t ADDR2PFN(uintptr_t addr) 139 { 140 return (pfn_t) (addr >> FRAME_WIDTH); 141 } 142 143 NO_TRACE static inline size_t SIZE2FRAMES(size_t size) 144 { 145 if (!size) 146 return 0; 147 return (size_t) ((size - 1) >> FRAME_WIDTH) + 1; 148 } 149 150 NO_TRACE static inline size_t FRAMES2SIZE(size_t frames) 151 { 152 return (size_t) (frames << FRAME_WIDTH); 153 } 154 155 #define IS_BUDDY_ORDER_OK(index, order) \ 156 ((~(((sysarg_t) -1) << (order)) & (index)) == 0) 157 #define IS_BUDDY_LEFT_BLOCK(zone, frame) \ 158 (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0) 159 #define IS_BUDDY_RIGHT_BLOCK(zone, frame) \ 160 (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1) 161 #define IS_BUDDY_LEFT_BLOCK_ABS(zone, frame) \ 162 (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0) 163 #define IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame) \ 164 (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1) 165 131 166 extern void frame_init(void); 132 167 extern bool frame_adjust_zone_bounds(bool, uintptr_t *, size_t *); 133 extern uintptr_t frame_alloc_generic(size_t, frame_flags_t, uintptr_t,134 size_t *);135 extern uintptr_t frame_alloc(size_t, frame_flags_t, uintptr_t);136 extern void frame_free_generic(uintptr_t, size_t,frame_flags_t);137 extern void frame_free(uintptr_t , size_t);138 extern void frame_free_noreserve(uintptr_t , size_t);168 extern void *frame_alloc_generic(uint8_t, frame_flags_t, size_t *); 169 extern void *frame_alloc(uint8_t, frame_flags_t); 170 extern void *frame_alloc_noreserve(uint8_t, frame_flags_t); 171 extern void frame_free_generic(uintptr_t, frame_flags_t); 172 extern void frame_free(uintptr_t); 173 extern void frame_free_noreserve(uintptr_t); 139 174 extern void frame_reference_add(pfn_t); 140 175 extern size_t frame_total_free_get(void);
Note:
See TracChangeset
for help on using the changeset viewer.