From b43eaba0c2b7c92653509bc1e364dc2812bd1b17 Mon Sep 17 00:00:00 2001 From: Jakub Jermar Date: Mon, 25 Dec 2006 11:38:48 +0000 Subject: [PATCH] Improve indentation and formatting. --- kernel/generic/include/mm/buddy.h | 34 ++++++++++++++++++++----------- kernel/generic/include/mm/frame.h | 43 ++++++++++++++++++++++++--------------- kernel/generic/src/mm/frame.c | 22 ++++++++++---------- 3 files changed, 60 insertions(+), 39 deletions(-) diff --git a/kernel/generic/include/mm/buddy.h b/kernel/generic/include/mm/buddy.h index f20b180bd..712d77091 100644 --- a/kernel/generic/include/mm/buddy.h +++ b/kernel/generic/include/mm/buddy.h @@ -42,28 +42,38 @@ /** 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 *); }; 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); diff --git a/kernel/generic/include/mm/frame.h b/kernel/generic/include/mm/frame.h index fcafa7989..44e2127a4 100644 --- a/kernel/generic/include/mm/frame.h +++ b/kernel/generic/include/mm/frame.h @@ -53,46 +53,57 @@ #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) { 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); diff --git a/kernel/generic/src/mm/frame.c b/kernel/generic/src/mm/frame.c index 0d6b7efcc..9c4efb112 100644 --- a/kernel/generic/src/mm/frame.c +++ b/kernel/generic/src/mm/frame.c @@ -83,7 +83,7 @@ typedef struct { 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 @@ static int zones_add_zone(zone_t *newzone) /** * 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 @@ static int zone_can_alloc(zone_t *z, uint8_t order) 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 @@ static zone_t * find_free_zone_and_lock(uint8_t order, int *pzone) return NULL; } -/********************************************/ +/**************************/ /* Buddy system functions */ +/**************************/ /** Buddy system find_block implementation * @@ -436,8 +436,9 @@ static struct buddy_system_operations zone_buddy_system_operations = { .print_id = zone_buddy_print_id }; -/*************************************/ +/******************/ /* Zone functions */ +/******************/ /** Allocate frame in particular zone * @@ -534,7 +535,6 @@ static void zone_mark_unavailable(zone_t *zone, index_t frame_idx) * @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; -- 2.11.4.GIT