Rev 536 | Rev 538 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 536 | Rev 537 | ||
---|---|---|---|
Line 61... | Line 61... | ||
61 | */ |
61 | */ |
62 | void frame_init(void) |
62 | void frame_init(void) |
63 | { |
63 | { |
64 | if (config.cpu_active == 1) { |
64 | if (config.cpu_active == 1) { |
65 | zone_init(); |
65 | zone_init(); |
66 | frame_region_not_free(config.base, config.kernel_size); |
66 | frame_region_not_free(KA2PA(config.base), config.kernel_size); |
67 | } |
67 | } |
68 | 68 | ||
69 | frame_arch_init(); |
69 | frame_arch_init(); |
70 | } |
70 | } |
71 | 71 | ||
72 | /** Allocate a frame |
- | |
73 | * |
- | |
74 | * Allocate a frame of physical memory. |
72 | /** Allocate power-of-two frames of physical memory. |
75 | * |
73 | * |
76 | * @param flags Flags for host zone selection and address processing. |
74 | * @param flags Flags for host zone selection and address processing. |
- | 75 | * @param order Allocate exactly 2^order frames. |
|
77 | * |
76 | * |
78 | * @return Allocated frame. |
77 | * @return Allocated frame. |
79 | */ |
78 | */ |
80 | __address frame_alloc(int flags, __u8 order) |
79 | __address frame_alloc(int flags, __u8 order) |
81 | { |
80 | { |
Line 200... | Line 199... | ||
200 | 199 | ||
201 | /** Mark frame region not free. |
200 | /** Mark frame region not free. |
202 | * |
201 | * |
203 | * Mark frame region not free. |
202 | * Mark frame region not free. |
204 | * |
203 | * |
205 | * @param start First address. |
204 | * @param base Base address of non-available region. |
206 | * @param stop Last address. |
205 | * @param size Size of non-available region. |
207 | */ |
206 | */ |
208 | void frame_region_not_free(__address base, size_t size) |
207 | void frame_region_not_free(__address base, size_t size) |
209 | { |
208 | { |
210 | count_t index; |
209 | index_t index; |
211 | index = zone_blacklist_count++; |
210 | index = zone_blacklist_count++; |
212 | ASSERT(base % FRAME_SIZE == 0); |
- | |
213 | 211 | ||
- | 212 | /* Force base to the nearest lower address frame boundary. */ |
|
214 | if (size % FRAME_SIZE != 0) { |
213 | base &= ~(FRAME_SIZE - 1); |
- | 214 | /* Align size to frame boundary. */ |
|
215 | size = ALIGN(size, FRAME_SIZE); |
215 | size = ALIGN(size, FRAME_SIZE); |
216 | } |
216 | |
217 | ASSERT(size % FRAME_SIZE == 0); |
- | |
218 | ASSERT(zone_blacklist_count <= ZONE_BLACKLIST_SIZE); |
217 | ASSERT(zone_blacklist_count <= ZONE_BLACKLIST_SIZE); |
219 | zone_blacklist[index].base = base; |
218 | zone_blacklist[index].base = base; |
220 | zone_blacklist[index].size = size; |
219 | zone_blacklist[index].size = size; |
221 | } |
220 | } |
222 | 221 | ||
Line 233... | Line 232... | ||
233 | 232 | ||
234 | 233 | ||
235 | void zone_create_in_region(__address base, size_t size) { |
234 | void zone_create_in_region(__address base, size_t size) { |
236 | int i; |
235 | int i; |
237 | zone_t * z; |
236 | zone_t * z; |
238 | __address s; size_t sz; |
237 | __address s; |
- | 238 | size_t sz; |
|
239 | 239 | ||
240 | ASSERT(base % FRAME_SIZE == 0); |
240 | ASSERT(base % FRAME_SIZE == 0); |
241 | ASSERT(size % FRAME_SIZE == 0); |
241 | ASSERT(size % FRAME_SIZE == 0); |
242 | 242 | ||
243 | if (!size) return; |
243 | if (!size) |
- | 244 | return; |
|
244 | 245 | ||
245 | for (i = 0; i < zone_blacklist_count; i++) { |
246 | for (i = 0; i < zone_blacklist_count; i++) { |
246 | if (zone_blacklist[i].base >= base && zone_blacklist[i].base < base + size) { |
247 | if (zone_blacklist[i].base >= base && zone_blacklist[i].base < base + size) { |
247 | s = base; sz = zone_blacklist[i].base - base; |
248 | s = base; sz = zone_blacklist[i].base - base; |
248 | ASSERT(base != s || sz != size); |
249 | ASSERT(base != s || sz != size); |
249 | zone_create_in_region(s, sz); |
250 | zone_create_in_region(s, sz); |
Line 301... | Line 302... | ||
301 | 302 | ||
302 | z->base = start; |
303 | z->base = start; |
303 | z->flags = flags; |
304 | z->flags = flags; |
304 | 305 | ||
305 | z->free_count = cnt; |
306 | z->free_count = cnt; |
306 | list_initialize(&z->free_head); |
- | |
307 | - | ||
308 | z->busy_count = 0; |
307 | z->busy_count = 0; |
309 | 308 | ||
310 | z->frames = (frame_t *) early_malloc(cnt * sizeof(frame_t)); |
309 | z->frames = (frame_t *) early_malloc(cnt * sizeof(frame_t)); |
311 | if (!z->frames) { |
310 | if (!z->frames) { |
312 | early_free(z); |
311 | early_free(z); |
313 | return NULL; |
312 | return NULL; |
314 | } |
313 | } |
315 | 314 | ||
316 | for (i = 0; i<cnt; i++) { |
315 | for (i = 0; i<cnt; i++) { |
317 | frame_initialize(&z->frames[i], z); |
316 | frame_initialize(&z->frames[i], z); |
318 | list_append(&z->frames[i].link, &z->free_head); |
- | |
319 | } |
317 | } |
320 | 318 | ||
321 | /* |
319 | /* |
322 | * Create buddy system for the zone |
320 | * Create buddy system for the zone |
323 | */ |
321 | */ |
324 | for (max_order = 0; cnt >> max_order; max_order++); |
322 | for (max_order = 0; cnt >> max_order; max_order++) |
- | 323 | ; |
|
325 | z->buddy_system = buddy_system_create(max_order, &zone_buddy_system_operations, (void *) z); |
324 | z->buddy_system = buddy_system_create(max_order, &zone_buddy_system_operations, (void *) z); |
326 | 325 | ||
327 | /* Stuffing frames */ |
326 | /* Stuffing frames */ |
328 | for (i = 0; i<cnt; i++) { |
327 | for (i = 0; i<cnt; i++) { |
329 | z->frames[i].refcount = 0; |
328 | z->frames[i].refcount = 0; |
Line 361... | Line 360... | ||
361 | */ |
360 | */ |
362 | void frame_initialize(frame_t *frame, zone_t *zone) |
361 | void frame_initialize(frame_t *frame, zone_t *zone) |
363 | { |
362 | { |
364 | frame->refcount = 1; |
363 | frame->refcount = 1; |
365 | frame->buddy_order = 0; |
364 | frame->buddy_order = 0; |
366 | link_initialize(&frame->link); |
- | |
367 | } |
365 | } |
368 | 366 | ||
369 | 367 | ||
370 | /** Buddy system find_buddy implementation |
368 | /** Buddy system find_buddy implementation |
371 | * |
369 | * |