Changeset b43eaba0 in mainline
- Timestamp:
- 2006-12-25T11:38:48Z (18 years ago)
- Branches:
- lfn, master, serial, ticket/834-toolchain-update, topic/msim-upgrade, topic/simplify-dev-export
- Children:
- 66eb2c8
- Parents:
- b2e5e25
- Location:
- kernel/generic
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
kernel/generic/include/mm/buddy.h
rb2e5e25 rb43eaba0 43 43 /** Buddy system operations to be implemented by each implementation. */ 44 44 struct buddy_system_operations { 45 link_t *(* find_buddy)(buddy_system_t *, link_t *); /**< Return pointer to left-side or right-side buddy for block passed as argument. */ 46 link_t *(* bisect)(buddy_system_t *, link_t *); /**< Bisect the block passed as argument and return pointer to the new right-side buddy. */ 47 link_t *(* coalesce)(buddy_system_t *, link_t *, link_t *); /**< Coalesce two buddies into a bigger block. */ 48 void (*set_order)(buddy_system_t *, link_t *, uint8_t); /**< Set order of block passed as argument. */ 49 uint8_t (*get_order)(buddy_system_t *, link_t *); /**< Return order of block passed as argument. */ 50 void (*mark_busy)(buddy_system_t *, link_t *); /**< Mark block as busy. */ 51 void (*mark_available)(buddy_system_t *, link_t *); /**< Mark block as available. */ 45 /** Return pointer to left-side or right-side buddy for block passed as 46 * argument. */ 47 link_t *(* find_buddy)(buddy_system_t *, link_t *); 48 /** Bisect the block passed as argument and return pointer to the new 49 * right-side buddy. */ 50 link_t *(* bisect)(buddy_system_t *, link_t *); 51 /** Coalesce two buddies into a bigger block. */ 52 link_t *(* coalesce)(buddy_system_t *, link_t *, link_t *); 53 /** Set order of block passed as argument. */ 54 void (*set_order)(buddy_system_t *, link_t *, uint8_t); 55 /** Return order of block passed as argument. */ 56 uint8_t (*get_order)(buddy_system_t *, link_t *); 57 /** Mark block as busy. */ 58 void (*mark_busy)(buddy_system_t *, link_t *); 59 /** Mark block as available. */ 60 void (*mark_available)(buddy_system_t *, link_t *); 52 61 /** Find parent of block that has given order */ 53 62 link_t *(* find_block)(buddy_system_t *, link_t *, uint8_t); … … 56 65 57 66 struct buddy_system { 58 uint8_t max_order; /**< Maximal order of block which can be stored by buddy system. */ 67 /** Maximal order of block which can be stored by buddy system. */ 68 uint8_t max_order; 59 69 link_t *order; 60 70 buddy_system_operations_t *op; 61 void *data; /**< Pointer to be used by the implementation. */ 71 /** Pointer to be used by the implementation. */ 72 void *data; 62 73 }; 63 74 64 extern void buddy_system_create(buddy_system_t *b, 65 uint8_t max_order, 66 buddy_system_operations_t *op, void *data); 75 extern void buddy_system_create(buddy_system_t *b, uint8_t max_order, 76 buddy_system_operations_t *op, void *data); 67 77 extern link_t *buddy_system_alloc(buddy_system_t *b, uint8_t i); 68 78 extern bool buddy_system_can_alloc(buddy_system_t *b, uint8_t order); -
kernel/generic/include/mm/frame.h
rb2e5e25 rb43eaba0 54 54 #endif 55 55 56 #define ZONES_MAX 16 /**< Maximum number of zones in system */ 56 /** Maximum number of zones in system. */ 57 #define ZONES_MAX 16 57 58 58 #define ZONE_JOIN 0x1 /**< If possible, merge with neighbouring zones */ 59 /** If possible, merge with neighbouring zones. */ 60 #define ZONE_JOIN 0x1 59 61 60 #define FRAME_KA 0x1 /* convert the frame address to kernel va */ 61 #define FRAME_ATOMIC 0x2 /* do not panic and do not sleep on failure */ 62 #define FRAME_NO_RECLAIM 0x4 /* do not start reclaiming when no free memory */ 62 /** Convert the frame address to kernel va. */ 63 #define FRAME_KA 0x1 64 /** Do not panic and do not sleep on failure. */ 65 #define FRAME_ATOMIC 0x2 66 /** Do not start reclaiming when no free memory. */ 67 #define FRAME_NO_RECLAIM 0x4 63 68 64 69 static inline uintptr_t PFN2ADDR(pfn_t frame) 65 70 { 66 return (uintptr_t) (frame << FRAME_WIDTH);71 return (uintptr_t) (frame << FRAME_WIDTH); 67 72 } 68 73 69 74 static inline pfn_t ADDR2PFN(uintptr_t addr) 70 75 { 71 return (pfn_t) (addr >> FRAME_WIDTH);76 return (pfn_t) (addr >> FRAME_WIDTH); 72 77 } 73 78 … … 76 81 if (!size) 77 82 return 0; 78 return (count_t) ((size-1) >> FRAME_WIDTH)+1;83 return (count_t) ((size - 1) >> FRAME_WIDTH) + 1; 79 84 } 80 85 81 #define IS_BUDDY_ORDER_OK(index, order) ((~(((unative_t) -1) << (order)) & (index)) == 0) 82 #define IS_BUDDY_LEFT_BLOCK(zone, frame) (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0) 83 #define IS_BUDDY_RIGHT_BLOCK(zone, frame) (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1) 84 #define IS_BUDDY_LEFT_BLOCK_ABS(zone, frame) (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0) 85 #define IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame) (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1) 86 #define IS_BUDDY_ORDER_OK(index, order) \ 87 ((~(((unative_t) -1) << (order)) & (index)) == 0) 88 #define IS_BUDDY_LEFT_BLOCK(zone, frame) \ 89 (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0) 90 #define IS_BUDDY_RIGHT_BLOCK(zone, frame) \ 91 (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1) 92 #define IS_BUDDY_LEFT_BLOCK_ABS(zone, frame) \ 93 (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0) 94 #define IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame) \ 95 (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1) 86 96 87 #define frame_alloc(order, flags) frame_alloc_generic(order, flags, NULL) 97 #define frame_alloc(order, flags) \ 98 frame_alloc_generic(order, flags, NULL) 88 99 89 100 extern void frame_init(void); 90 extern void * 101 extern void *frame_alloc_generic(uint8_t order, int flags, int *pzone); 91 102 extern void frame_free(uintptr_t frame); 92 103 extern void frame_reference_add(pfn_t pfn); 93 104 94 105 extern int zone_create(pfn_t start, count_t count, pfn_t confframe, int flags); 95 void * 106 void *frame_get_parent(pfn_t frame, int hint); 96 107 void frame_set_parent(pfn_t frame, void *data, int hint); 97 108 void frame_mark_unavailable(pfn_t start, count_t count); -
kernel/generic/src/mm/frame.c
rb2e5e25 rb43eaba0 84 84 count_t busy_count; /**< number of busy frame_t structures */ 85 85 86 buddy_system_t * 86 buddy_system_t *buddy_system; /**< buddy system for the zone */ 87 87 int flags; 88 88 } zone_t; … … 177 177 /** 178 178 * Try to find a zone where can we find the frame 179 * 179 180 * Assume interrupts are disabled. 181 180 182 * @param frame Frame number contained in zone 181 183 * @param pzone If not null, it is used as zone hint. Zone index 182 184 * is filled into the variable on success. 183 * @return Pointer to LOCKED zone containing frame 184 * 185 * Assume interrupts disable 185 * @return Pointer to locked zone containing frame 186 186 */ 187 187 static zone_t * find_zone_and_lock(pfn_t frame, int *pzone) … … 223 223 } 224 224 225 /** 226 * Find AND LOCK zone that can allocate order frames 227 * 228 * Assume interrupts are disabled!! 225 /** Find and lock zone that can allocate order frames. 226 * 227 * Assume interrupts are disabled. 229 228 * 230 229 * @param order Size (2^order) of free space we are trying to find … … 261 260 } 262 261 263 /************************** ******************/262 /**************************/ 264 263 /* Buddy system functions */ 264 /**************************/ 265 265 266 266 /** Buddy system find_block implementation … … 437 437 }; 438 438 439 /****************** *******************/439 /******************/ 440 440 /* Zone functions */ 441 /******************/ 441 442 442 443 /** Allocate frame in particular zone … … 535 536 * @param z2 Zone to merge 536 537 */ 537 538 538 static void _zone_merge(zone_t *z, zone_t *z1, zone_t *z2) 539 539 {
Note:
See TracChangeset
for help on using the changeset viewer.