Rev 703 | Rev 735 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 703 | Rev 724 | ||
---|---|---|---|
Line 131... | Line 131... | ||
131 | 131 | ||
132 | panic("Sleep not implemented.\n"); |
132 | panic("Sleep not implemented.\n"); |
133 | goto loop; |
133 | goto loop; |
134 | } |
134 | } |
135 | 135 | ||
136 | - | ||
137 | /* Allocate frames from zone buddy system */ |
136 | /* Allocate frames from zone buddy system */ |
138 | tmp = buddy_system_alloc(zone->buddy_system, order); |
137 | tmp = buddy_system_alloc(zone->buddy_system, order); |
139 | 138 | ||
140 | ASSERT(tmp); |
139 | ASSERT(tmp); |
141 | 140 | ||
Line 158... | Line 157... | ||
158 | 157 | ||
159 | if (flags & FRAME_NON_BLOCKING) { |
158 | if (flags & FRAME_NON_BLOCKING) { |
160 | ASSERT(status != NULL); |
159 | ASSERT(status != NULL); |
161 | *status = FRAME_OK; |
160 | *status = FRAME_OK; |
162 | } |
161 | } |
163 | - | ||
164 | return v; |
162 | return v; |
165 | } |
163 | } |
166 | 164 | ||
167 | /** Free a frame. |
165 | /** Free a frame. |
168 | * |
166 | * |
Line 177... | Line 175... | ||
177 | ipl_t ipl; |
175 | ipl_t ipl; |
178 | link_t *cur; |
176 | link_t *cur; |
179 | zone_t *z; |
177 | zone_t *z; |
180 | zone_t *zone = NULL; |
178 | zone_t *zone = NULL; |
181 | frame_t *frame; |
179 | frame_t *frame; |
- | 180 | int order; |
|
- | 181 | ||
182 | ASSERT(addr % FRAME_SIZE == 0); |
182 | ASSERT(addr % FRAME_SIZE == 0); |
183 | 183 | ||
184 | ipl = interrupts_disable(); |
184 | ipl = interrupts_disable(); |
185 | spinlock_lock(&zone_head_lock); |
185 | spinlock_lock(&zone_head_lock); |
186 | 186 | ||
Line 207... | Line 207... | ||
207 | } |
207 | } |
208 | 208 | ||
209 | ASSERT(zone != NULL); |
209 | ASSERT(zone != NULL); |
210 | 210 | ||
211 | frame = ADDR2FRAME(zone, addr); |
211 | frame = ADDR2FRAME(zone, addr); |
- | 212 | ||
- | 213 | /* remember frame order */ |
|
- | 214 | order = frame->buddy_order; |
|
212 | 215 | ||
213 | ASSERT(frame->refcount); |
216 | ASSERT(frame->refcount); |
214 | 217 | ||
215 | if (!--frame->refcount) { |
218 | if (!--frame->refcount) { |
216 | buddy_system_free(zone->buddy_system, &frame->buddy_link); |
219 | buddy_system_free(zone->buddy_system, &frame->buddy_link); |
217 | } |
220 | } |
218 | 221 | ||
219 | /* Update zone information. */ |
222 | /* Update zone information. */ |
220 | zone->free_count += (1 << frame->buddy_order); |
223 | zone->free_count += (1 << order); |
221 | zone->busy_count -= (1 << frame->buddy_order); |
224 | zone->busy_count -= (1 << order); |
222 | 225 | ||
223 | spinlock_unlock(&zone->lock); |
226 | spinlock_unlock(&zone->lock); |
224 | spinlock_unlock(&zone_head_lock); |
227 | spinlock_unlock(&zone_head_lock); |
225 | interrupts_restore(ipl); |
228 | interrupts_restore(ipl); |
226 | } |
229 | } |
Line 319... | Line 322... | ||
319 | if (z) { |
322 | if (z) { |
320 | link_initialize(&z->link); |
323 | link_initialize(&z->link); |
321 | spinlock_initialize(&z->lock, "zone_lock"); |
324 | spinlock_initialize(&z->lock, "zone_lock"); |
322 | 325 | ||
323 | z->base = start; |
326 | z->base = start; |
- | 327 | z->base_index = start / FRAME_SIZE; |
|
- | 328 | ||
324 | z->flags = flags; |
329 | z->flags = flags; |
325 | 330 | ||
326 | z->free_count = cnt; |
331 | z->free_count = cnt; |
327 | z->busy_count = 0; |
332 | z->busy_count = 0; |
328 | 333 | ||
Line 346... | Line 351... | ||
346 | /* Stuffing frames */ |
351 | /* Stuffing frames */ |
347 | for (i = 0; i<cnt; i++) { |
352 | for (i = 0; i<cnt; i++) { |
348 | z->frames[i].refcount = 0; |
353 | z->frames[i].refcount = 0; |
349 | buddy_system_free(z->buddy_system, &z->frames[i].buddy_link); |
354 | buddy_system_free(z->buddy_system, &z->frames[i].buddy_link); |
350 | } |
355 | } |
- | 356 | ||
351 | } |
357 | } |
352 | return z; |
358 | return z; |
353 | } |
359 | } |
354 | 360 | ||
355 | /** Attach frame zone |
361 | /** Attach frame zone |
Line 398... | Line 404... | ||
398 | index_t index; |
404 | index_t index; |
399 | bool is_left, is_right; |
405 | bool is_left, is_right; |
400 | 406 | ||
401 | frame = list_get_instance(block, frame_t, buddy_link); |
407 | frame = list_get_instance(block, frame_t, buddy_link); |
402 | zone = (zone_t *) b->data; |
408 | zone = (zone_t *) b->data; |
- | 409 | ASSERT(IS_BUDDY_ORDER_OK(FRAME_INDEX_ABS(zone, frame), frame->buddy_order)); |
|
403 | 410 | ||
404 | ASSERT(IS_BUDDY_ORDER_OK(FRAME_INDEX(zone, frame), frame->buddy_order)); |
- | |
405 | 411 | ||
406 | is_left = IS_BUDDY_LEFT_BLOCK(zone, frame); |
412 | is_left = IS_BUDDY_LEFT_BLOCK_ABS(zone, frame); |
407 | is_right = IS_BUDDY_RIGHT_BLOCK(zone, frame); |
413 | is_right = IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame); |
408 | 414 | ||
409 | ASSERT(is_left ^ is_right); |
415 | ASSERT(is_left ^ is_right); |
410 | 416 | ||
411 | if (is_left) { |
417 | if (is_left) { |
412 | index = (FRAME_INDEX(zone, frame)) + (1 << frame->buddy_order); |
418 | index = (FRAME_INDEX(zone, frame)) + (1 << frame->buddy_order); |