/trunk/kernel/generic/include/mm/frame.h |
---|
53,22 → 53,27 |
#define STACK_FRAMES ONE_FRAME |
#endif |
#define ZONES_MAX 16 /**< Maximum number of zones in system */ |
/** Maximum number of zones in system. */ |
#define ZONES_MAX 16 |
#define ZONE_JOIN 0x1 /**< If possible, merge with neighbouring zones */ |
/** If possible, merge with neighbouring zones. */ |
#define ZONE_JOIN 0x1 |
#define FRAME_KA 0x1 /* convert the frame address to kernel va */ |
#define FRAME_ATOMIC 0x2 /* do not panic and do not sleep on failure */ |
#define FRAME_NO_RECLAIM 0x4 /* do not start reclaiming when no free memory */ |
/** Convert the frame address to kernel va. */ |
#define FRAME_KA 0x1 |
/** Do not panic and do not sleep on failure. */ |
#define FRAME_ATOMIC 0x2 |
/** Do not start reclaiming when no free memory. */ |
#define FRAME_NO_RECLAIM 0x4 |
static inline uintptr_t PFN2ADDR(pfn_t frame) |
{ |
return (uintptr_t)(frame << FRAME_WIDTH); |
return (uintptr_t) (frame << FRAME_WIDTH); |
} |
static inline pfn_t ADDR2PFN(uintptr_t addr) |
{ |
return (pfn_t)(addr >> FRAME_WIDTH); |
return (pfn_t) (addr >> FRAME_WIDTH); |
} |
static inline count_t SIZE2FRAMES(size_t size) |
75,24 → 80,30 |
{ |
if (!size) |
return 0; |
return (count_t)((size-1) >> FRAME_WIDTH)+1; |
return (count_t) ((size - 1) >> FRAME_WIDTH) + 1; |
} |
#define IS_BUDDY_ORDER_OK(index, order) ((~(((unative_t) -1) << (order)) & (index)) == 0) |
#define IS_BUDDY_LEFT_BLOCK(zone, frame) (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0) |
#define IS_BUDDY_RIGHT_BLOCK(zone, frame) (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1) |
#define IS_BUDDY_LEFT_BLOCK_ABS(zone, frame) (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0) |
#define IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame) (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1) |
#define IS_BUDDY_ORDER_OK(index, order) \ |
((~(((unative_t) -1) << (order)) & (index)) == 0) |
#define IS_BUDDY_LEFT_BLOCK(zone, frame) \ |
(((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0) |
#define IS_BUDDY_RIGHT_BLOCK(zone, frame) \ |
(((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1) |
#define IS_BUDDY_LEFT_BLOCK_ABS(zone, frame) \ |
(((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0) |
#define IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame) \ |
(((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1) |
#define frame_alloc(order, flags) frame_alloc_generic(order, flags, NULL) |
#define frame_alloc(order, flags) \ |
frame_alloc_generic(order, flags, NULL) |
extern void frame_init(void); |
extern void * frame_alloc_generic(uint8_t order, int flags, int *pzone); |
extern void *frame_alloc_generic(uint8_t order, int flags, int *pzone); |
extern void frame_free(uintptr_t frame); |
extern void frame_reference_add(pfn_t pfn); |
extern int zone_create(pfn_t start, count_t count, pfn_t confframe, int flags); |
void * frame_get_parent(pfn_t frame, int hint); |
void *frame_get_parent(pfn_t frame, int hint); |
void frame_set_parent(pfn_t frame, void *data, int hint); |
void frame_mark_unavailable(pfn_t start, count_t count); |
uintptr_t zone_conf_size(count_t count); |
/trunk/kernel/generic/include/mm/buddy.h |
---|
42,13 → 42,22 |
/** Buddy system operations to be implemented by each implementation. */ |
struct buddy_system_operations { |
link_t *(* find_buddy)(buddy_system_t *, link_t *); /**< Return pointer to left-side or right-side buddy for block passed as argument. */ |
link_t *(* bisect)(buddy_system_t *, link_t *); /**< Bisect the block passed as argument and return pointer to the new right-side buddy. */ |
link_t *(* coalesce)(buddy_system_t *, link_t *, link_t *); /**< Coalesce two buddies into a bigger block. */ |
void (*set_order)(buddy_system_t *, link_t *, uint8_t); /**< Set order of block passed as argument. */ |
uint8_t (*get_order)(buddy_system_t *, link_t *); /**< Return order of block passed as argument. */ |
void (*mark_busy)(buddy_system_t *, link_t *); /**< Mark block as busy. */ |
void (*mark_available)(buddy_system_t *, link_t *); /**< Mark block as available. */ |
/** Return pointer to left-side or right-side buddy for block passed as |
* argument. */ |
link_t *(* find_buddy)(buddy_system_t *, link_t *); |
/** Bisect the block passed as argument and return pointer to the new |
* right-side buddy. */ |
link_t *(* bisect)(buddy_system_t *, link_t *); |
/** Coalesce two buddies into a bigger block. */ |
link_t *(* coalesce)(buddy_system_t *, link_t *, link_t *); |
/** Set order of block passed as argument. */ |
void (*set_order)(buddy_system_t *, link_t *, uint8_t); |
/** Return order of block passed as argument. */ |
uint8_t (*get_order)(buddy_system_t *, link_t *); |
/** Mark block as busy. */ |
void (*mark_busy)(buddy_system_t *, link_t *); |
/** Mark block as available. */ |
void (*mark_available)(buddy_system_t *, link_t *); |
/** Find parent of block that has given order */ |
link_t *(* find_block)(buddy_system_t *, link_t *, uint8_t); |
void (* print_id)(buddy_system_t *, link_t *); |
55,15 → 64,16 |
}; |
struct buddy_system { |
uint8_t max_order; /**< Maximal order of block which can be stored by buddy system. */ |
/** Maximal order of block which can be stored by buddy system. */ |
uint8_t max_order; |
link_t *order; |
buddy_system_operations_t *op; |
void *data; /**< Pointer to be used by the implementation. */ |
/** Pointer to be used by the implementation. */ |
void *data; |
}; |
extern void buddy_system_create(buddy_system_t *b, |
uint8_t max_order, |
buddy_system_operations_t *op, void *data); |
extern void buddy_system_create(buddy_system_t *b, uint8_t max_order, |
buddy_system_operations_t *op, void *data); |
extern link_t *buddy_system_alloc(buddy_system_t *b, uint8_t i); |
extern bool buddy_system_can_alloc(buddy_system_t *b, uint8_t order); |
extern void buddy_system_free(buddy_system_t *b, link_t *block); |
/trunk/kernel/generic/src/mm/frame.c |
---|
83,7 → 83,7 |
count_t free_count; /**< number of free frame_t structures */ |
count_t busy_count; /**< number of busy frame_t structures */ |
buddy_system_t * buddy_system; /**< buddy system for the zone */ |
buddy_system_t *buddy_system; /**< buddy system for the zone */ |
int flags; |
} zone_t; |
176,13 → 176,13 |
/** |
* Try to find a zone where can we find the frame |
* |
* Assume interrupts are disabled. |
* @param frame Frame number contained in zone |
* @param pzone If not null, it is used as zone hint. Zone index |
* is filled into the variable on success. |
* @return Pointer to LOCKED zone containing frame |
* |
* Assume interrupts disable |
* @return Pointer to locked zone containing frame |
*/ |
static zone_t * find_zone_and_lock(pfn_t frame, int *pzone) |
{ |
222,10 → 222,9 |
return buddy_system_can_alloc(z->buddy_system, order); |
} |
/** |
* Find AND LOCK zone that can allocate order frames |
/** Find and lock zone that can allocate order frames. |
* |
* Assume interrupts are disabled!! |
* Assume interrupts are disabled. |
* |
* @param order Size (2^order) of free space we are trying to find |
* @param pzone Pointer to preferred zone or NULL, on return contains zone number |
260,8 → 259,9 |
return NULL; |
} |
/********************************************/ |
/**************************/ |
/* Buddy system functions */ |
/**************************/ |
/** Buddy system find_block implementation |
* |
436,8 → 436,9 |
.print_id = zone_buddy_print_id |
}; |
/*************************************/ |
/******************/ |
/* Zone functions */ |
/******************/ |
/** Allocate frame in particular zone |
* |
534,7 → 535,6 |
* @param z1 Zone to merge |
* @param z2 Zone to merge |
*/ |
static void _zone_merge(zone_t *z, zone_t *z1, zone_t *z2) |
{ |
uint8_t max_order; |