Rev 2071 | Rev 2089 | Go to most recent revision | Show entire file | Regard whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 2071 | Rev 2083 | ||
---|---|---|---|
Line 38... | Line 38... | ||
38 | #include <arch/types.h> |
38 | #include <arch/types.h> |
39 | #include <typedefs.h> |
39 | #include <typedefs.h> |
40 | 40 | ||
41 | #define BUDDY_SYSTEM_INNER_BLOCK 0xff |
41 | #define BUDDY_SYSTEM_INNER_BLOCK 0xff |
42 | 42 | ||
- | 43 | struct buddy_system; |
|
- | 44 | ||
43 | /** Buddy system operations to be implemented by each implementation. */ |
45 | /** Buddy system operations to be implemented by each implementation. */ |
44 | struct buddy_system_operations { |
46 | typedef struct { |
45 | /** Return pointer to left-side or right-side buddy for block passed as |
47 | /** Return pointer to left-side or right-side buddy for block passed as |
46 | * argument. */ |
48 | * argument. */ |
47 | link_t *(* find_buddy)(buddy_system_t *, link_t *); |
49 | link_t *(* find_buddy)(struct buddy_system *, link_t *); |
48 | /** Bisect the block passed as argument and return pointer to the new |
50 | /** Bisect the block passed as argument and return pointer to the new |
49 | * right-side buddy. */ |
51 | * right-side buddy. */ |
50 | link_t *(* bisect)(buddy_system_t *, link_t *); |
52 | link_t *(* bisect)(struct buddy_system *, link_t *); |
51 | /** Coalesce two buddies into a bigger block. */ |
53 | /** Coalesce two buddies into a bigger block. */ |
52 | link_t *(* coalesce)(buddy_system_t *, link_t *, link_t *); |
54 | link_t *(* coalesce)(struct buddy_system *, link_t *, link_t *); |
53 | /** Set order of block passed as argument. */ |
55 | /** Set order of block passed as argument. */ |
54 | void (*set_order)(buddy_system_t *, link_t *, uint8_t); |
56 | void (*set_order)(struct buddy_system *, link_t *, uint8_t); |
55 | /** Return order of block passed as argument. */ |
57 | /** Return order of block passed as argument. */ |
56 | uint8_t (*get_order)(buddy_system_t *, link_t *); |
58 | uint8_t (*get_order)(struct buddy_system *, link_t *); |
57 | /** Mark block as busy. */ |
59 | /** Mark block as busy. */ |
58 | void (*mark_busy)(buddy_system_t *, link_t *); |
60 | void (*mark_busy)(struct buddy_system *, link_t *); |
59 | /** Mark block as available. */ |
61 | /** Mark block as available. */ |
60 | void (*mark_available)(buddy_system_t *, link_t *); |
62 | void (*mark_available)(struct buddy_system *, link_t *); |
61 | /** Find parent of block that has given order */ |
63 | /** Find parent of block that has given order */ |
62 | link_t *(* find_block)(buddy_system_t *, link_t *, uint8_t); |
64 | link_t *(* find_block)(struct buddy_system *, link_t *, uint8_t); |
63 | void (* print_id)(buddy_system_t *, link_t *); |
65 | void (* print_id)(struct buddy_system *, link_t *); |
64 | }; |
66 | } buddy_system_operations_t; |
65 | 67 | ||
66 | struct buddy_system { |
68 | typedef struct buddy_system { |
67 | /** Maximal order of block which can be stored by buddy system. */ |
69 | /** Maximal order of block which can be stored by buddy system. */ |
68 | uint8_t max_order; |
70 | uint8_t max_order; |
69 | link_t *order; |
71 | link_t *order; |
70 | buddy_system_operations_t *op; |
72 | buddy_system_operations_t *op; |
71 | /** Pointer to be used by the implementation. */ |
73 | /** Pointer to be used by the implementation. */ |
72 | void *data; |
74 | void *data; |
73 | }; |
75 | } buddy_system_t; |
74 | 76 | ||
75 | extern void buddy_system_create(buddy_system_t *b, uint8_t max_order, |
77 | extern void buddy_system_create(buddy_system_t *b, uint8_t max_order, |
76 | buddy_system_operations_t *op, void *data); |
78 | buddy_system_operations_t *op, void *data); |
77 | extern link_t *buddy_system_alloc(buddy_system_t *b, uint8_t i); |
79 | extern link_t *buddy_system_alloc(buddy_system_t *b, uint8_t i); |
78 | extern bool buddy_system_can_alloc(buddy_system_t *b, uint8_t order); |
80 | extern bool buddy_system_can_alloc(buddy_system_t *b, uint8_t order); |