Rev 532 | Rev 534 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 532 | Rev 533 | ||
---|---|---|---|
Line 40... | Line 40... | ||
40 | #define FRAME_PANIC 2 /* panic on failure */ |
40 | #define FRAME_PANIC 2 /* panic on failure */ |
41 | 41 | ||
42 | #define FRAME2ADDR(zone, frame) ((zone)->base + ((frame) - (zone)->frames) * FRAME_SIZE) |
42 | #define FRAME2ADDR(zone, frame) ((zone)->base + ((frame) - (zone)->frames) * FRAME_SIZE) |
43 | #define ADDR2FRAME(zone, addr) (&((zone)->frames[((addr) - (zone)->base) / FRAME_SIZE])) |
43 | #define ADDR2FRAME(zone, addr) (&((zone)->frames[((addr) - (zone)->base) / FRAME_SIZE])) |
44 | #define FRAME_INDEX(zone, frame) ((count_t)((frame) - (zone)->frames)) |
44 | #define FRAME_INDEX(zone, frame) ((count_t)((frame) - (zone)->frames)) |
- | 45 | #define FRAME_INDEX_VALID(zone, index) (((index) >= 0) && ((index) < ((zone)->free_count + (zone)->busy_count))) |
|
45 | #define IS_BUDDY_LEFT_BLOCK(zone, frame) ((FRAME_INDEX((zone), (frame)) % (1 >> ((frame)->buddy_order + 1))) == 0) |
46 | #define IS_BUDDY_LEFT_BLOCK(zone, frame) ((FRAME_INDEX((zone), (frame)) % (1 << ((frame)->buddy_order + 1))) == 0) |
46 | #define IS_BUDDY_RIGHT_BLOCK(zone, frame) ((FRAME_INDEX((zone), (frame)) % (1 >> ((frame)->buddy_order + 1))) == (1 >> (frame)->buddy_order)) |
47 | #define IS_BUDDY_RIGHT_BLOCK(zone, frame) ((FRAME_INDEX((zone), (frame)) % (1 << ((frame)->buddy_order + 1))) == (1 << (frame)->buddy_order)) |
47 | - | ||
48 | 48 | ||
- | 49 | #define ZONE_BLACKLIST_SIZE 3 |
|
49 | 50 | ||
50 | struct zone { |
51 | struct zone { |
51 | link_t link; /**< link to previous and next zone */ |
52 | link_t link; /**< link to previous and next zone */ |
52 | 53 | ||
53 | spinlock_t lock; /**< this lock protects everything below */ |
54 | spinlock_t lock; /**< this lock protects everything below */ |
Line 66... | Line 67... | ||
66 | link_t link; /**< link to zone free list when refcount == 0 */ |
67 | link_t link; /**< link to zone free list when refcount == 0 */ |
67 | __u8 buddy_order; /**< buddy system block order */ |
68 | __u8 buddy_order; /**< buddy system block order */ |
68 | link_t buddy_link; /**< link to the next free block inside one order*/ |
69 | link_t buddy_link; /**< link to the next free block inside one order*/ |
69 | }; |
70 | }; |
70 | 71 | ||
- | 72 | struct region { |
|
- | 73 | __address base; |
|
- | 74 | size_t size; |
|
- | 75 | }; |
|
- | 76 | ||
- | 77 | extern region_t zone_blacklist[]; |
|
- | 78 | extern count_t zone_blacklist_count; |
|
- | 79 | extern void frame_region_not_free(__address base, size_t size); |
|
- | 80 | extern void zone_create_in_region(__address base, size_t size); |
|
- | 81 | ||
71 | extern spinlock_t zone_head_lock; /**< this lock protects zone_head list */ |
82 | extern spinlock_t zone_head_lock; /**< this lock protects zone_head list */ |
72 | extern link_t zone_head; /**< list of all zones in the system */ |
83 | extern link_t zone_head; /**< list of all zones in the system */ |
73 | 84 | ||
74 | extern void zone_init(void); |
85 | extern void zone_init(void); |
75 | extern zone_t *zone_create(__address start, size_t size, int flags); |
86 | extern zone_t *zone_create(__address start, size_t size, int flags); |
76 | extern void zone_attach(zone_t *zone); |
87 | extern void zone_attach(zone_t *zone); |
77 | 88 | ||
78 | extern void frame_init(void); |
89 | extern void frame_init(void); |
79 | extern void frame_initialize(frame_t *frame, zone_t *zone); |
90 | extern void frame_initialize(frame_t *frame, zone_t *zone); |
80 | __address frame_alloc(int flags); |
91 | __address frame_alloc(int flags, __u8 order); |
81 | extern void frame_free(__address addr); |
92 | extern void frame_free(__address addr); |
82 | extern void frame_not_free(__address addr); |
- | |
83 | extern void frame_region_not_free(__address start, __address stop); |
- | |
84 | zone_t * get_zone_by_frame(frame_t * frame); |
93 | zone_t * get_zone_by_frame(frame_t * frame); |
85 | 94 | ||
86 | /* |
95 | /* |
87 | * Buddy system operations |
96 | * Buddy system operations |
88 | */ |
97 | */ |
89 | link_t * zone_buddy_find_buddy(buddy_system_t *b, link_t * buddy); |
98 | link_t * zone_buddy_find_buddy(buddy_system_t *b, link_t * buddy); |
90 | link_t * zone_buddy_bisect(buddy_system_t *b, link_t * block); |
99 | link_t * zone_buddy_bisect(buddy_system_t *b, link_t * block); |
91 | link_t * zone_buddy_coalesce(buddy_system_t *b, link_t * buddy_l, link_t * buddy_r); |
100 | link_t * zone_buddy_coalesce(buddy_system_t *b, link_t * buddy_l, link_t * buddy_r); |
92 | void zone_buddy_set_order(buddy_system_t *b, link_t * block, __u8 order); |
101 | void zone_buddy_set_order(buddy_system_t *b, link_t * block, __u8 order); |
93 | __u8 zone_buddy_get_order(buddy_system_t *b, link_t * block); |
102 | __u8 zone_buddy_get_order(buddy_system_t *b, link_t * block); |
94 | - | ||
95 | __address zone_buddy_frame_alloc(int flags, __u8 order); |
- | |
96 | void zone_buddy_frame_free(__address addr); |
103 | void zone_buddy_mark_busy(buddy_system_t *b, link_t * block); |
97 | 104 | ||
98 | /* |
105 | /* |
99 | * TODO: Implement the following functions. |
106 | * TODO: Implement the following functions. |
100 | */ |
107 | */ |
101 | extern frame_t *frame_reference(frame_t *frame); |
108 | extern frame_t *frame_reference(frame_t *frame); |