source: mainline/kernel/generic/src/mm/frame.c@ aaceebc4

lfn serial ticket/834-toolchain-update topic/msim-upgrade topic/simplify-dev-export
Last change on this file since aaceebc4 was aaceebc4, checked in by Jan Vesely <jano.vesely@…>, 12 years ago

Create DMA zone.

use dma zone for dma_map_anonymous calls.
create non-available zone if all pages in that zone are used.
make occupying pages in non-available zones a no-op

This enables ISA DMA on configurations with more than 16 MB of ram

  • Property mode set to 100644
File size: 38.2 KB
Line 
1/*
2 * Copyright (c) 2001-2005 Jakub Jermar
3 * Copyright (c) 2005 Sergey Bondari
4 * Copyright (c) 2009 Martin Decky
5 * All rights reserved.
6 *
7 * Redistribution and use in source and binary forms, with or without
8 * modification, are permitted provided that the following conditions
9 * are met:
10 *
11 * - Redistributions of source code must retain the above copyright
12 * notice, this list of conditions and the following disclaimer.
13 * - Redistributions in binary form must reproduce the above copyright
14 * notice, this list of conditions and the following disclaimer in the
15 * documentation and/or other materials provided with the distribution.
16 * - The name of the author may not be used to endorse or promote products
17 * derived from this software without specific prior written permission.
18 *
19 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
20 * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
21 * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
22 * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
23 * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
24 * NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
28 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */
30
31/** @addtogroup genericmm
32 * @{
33 */
34
35/**
36 * @file
37 * @brief Physical frame allocator.
38 *
39 * This file contains the physical frame allocator and memory zone management.
40 * The frame allocator is built on top of the buddy allocator.
41 *
42 * @see buddy.c
43 */
44
45#include <typedefs.h>
46#include <mm/frame.h>
47#include <mm/reserve.h>
48#include <mm/as.h>
49#include <panic.h>
50#include <debug.h>
51#include <adt/list.h>
52#include <synch/mutex.h>
53#include <synch/condvar.h>
54#include <arch/asm.h>
55#include <arch.h>
56#include <print.h>
57#include <align.h>
58#include <mm/slab.h>
59#include <bitops.h>
60#include <macros.h>
61#include <config.h>
62#include <str.h>
63
64zones_t zones;
65
66/*
67 * Synchronization primitives used to sleep when there is no memory
68 * available.
69 */
70static mutex_t mem_avail_mtx;
71static condvar_t mem_avail_cv;
72static size_t mem_avail_req = 0; /**< Number of frames requested. */
73static size_t mem_avail_gen = 0; /**< Generation counter. */
74
75/********************/
76/* Helper functions */
77/********************/
78
79NO_TRACE static inline size_t frame_index(zone_t *zone, frame_t *frame)
80{
81 return (size_t) (frame - zone->frames);
82}
83
84NO_TRACE static inline size_t frame_index_abs(zone_t *zone, frame_t *frame)
85{
86 return (size_t) (frame - zone->frames) + zone->base;
87}
88
89NO_TRACE static inline bool frame_index_valid(zone_t *zone, size_t index)
90{
91 return (index < zone->count);
92}
93
94NO_TRACE static inline size_t make_frame_index(zone_t *zone, frame_t *frame)
95{
96 return (frame - zone->frames);
97}
98
99/** Initialize frame structure.
100 *
101 * @param frame Frame structure to be initialized.
102 *
103 */
104NO_TRACE static void frame_initialize(frame_t *frame)
105{
106 frame->refcount = 1;
107 frame->buddy_order = 0;
108}
109
110/*******************/
111/* Zones functions */
112/*******************/
113
114/** Insert-sort zone into zones list.
115 *
116 * Assume interrupts are disabled and zones lock is
117 * locked.
118 *
119 * @param base Base frame of the newly inserted zone.
120 * @param count Number of frames of the newly inserted zone.
121 *
122 * @return Zone number on success, -1 on error.
123 *
124 */
125NO_TRACE static size_t zones_insert_zone(pfn_t base, size_t count,
126 zone_flags_t flags)
127{
128 if (zones.count + 1 == ZONES_MAX) {
129 printf("Maximum zone count %u exceeded!\n", ZONES_MAX);
130 return (size_t) -1;
131 }
132
133 size_t i;
134 for (i = 0; i < zones.count; i++) {
135 /* Check for overlap */
136 if (overlaps(zones.info[i].base, zones.info[i].count,
137 base, count)) {
138
139 /*
140 * If the overlaping zones are of the same type
141 * and the new zone is completely within the previous
142 * one, then quietly ignore the new zone.
143 *
144 */
145
146 if ((zones.info[i].flags != flags) ||
147 (!iswithin(zones.info[i].base, zones.info[i].count,
148 base, count))) {
149 printf("Zone (%p, %p) overlaps "
150 "with previous zone (%p %p)!\n",
151 (void *) PFN2ADDR(base), (void *) PFN2ADDR(count),
152 (void *) PFN2ADDR(zones.info[i].base),
153 (void *) PFN2ADDR(zones.info[i].count));
154 }
155
156 return (size_t) -1;
157 }
158 if (base < zones.info[i].base)
159 break;
160 }
161
162 /* Move other zones up */
163 size_t j;
164 for (j = zones.count; j > i; j--) {
165 zones.info[j] = zones.info[j - 1];
166 if (zones.info[j].buddy_system != NULL)
167 zones.info[j].buddy_system->data =
168 (void *) &zones.info[j];
169 }
170
171 zones.count++;
172
173 return i;
174}
175
176/** Get total available frames.
177 *
178 * Assume interrupts are disabled and zones lock is
179 * locked.
180 *
181 * @return Total number of available frames.
182 *
183 */
184NO_TRACE static size_t frame_total_free_get_internal(void)
185{
186 size_t total = 0;
187 size_t i;
188
189 for (i = 0; i < zones.count; i++)
190 total += zones.info[i].free_count;
191
192 return total;
193}
194
195NO_TRACE size_t frame_total_free_get(void)
196{
197 size_t total;
198
199 irq_spinlock_lock(&zones.lock, true);
200 total = frame_total_free_get_internal();
201 irq_spinlock_unlock(&zones.lock, true);
202
203 return total;
204}
205
206
207/** Find a zone with a given frames.
208 *
209 * Assume interrupts are disabled and zones lock is
210 * locked.
211 *
212 * @param frame Frame number contained in zone.
213 * @param count Number of frames to look for.
214 * @param hint Used as zone hint.
215 *
216 * @return Zone index or -1 if not found.
217 *
218 */
219NO_TRACE size_t find_zone(pfn_t frame, size_t count, size_t hint)
220{
221 if (hint >= zones.count)
222 hint = 0;
223
224 size_t i = hint;
225 do {
226 if ((zones.info[i].base <= frame)
227 && (zones.info[i].base + zones.info[i].count >= frame + count))
228 return i;
229
230 i++;
231 if (i >= zones.count)
232 i = 0;
233
234 } while (i != hint);
235
236 return (size_t) -1;
237}
238
239/** @return True if zone can allocate specified order */
240NO_TRACE static bool zone_can_alloc(zone_t *zone, uint8_t order)
241{
242 return ((zone->flags & ZONE_AVAILABLE) &&
243 buddy_system_can_alloc(zone->buddy_system, order));
244}
245
246/** Find a zone that can allocate order frames.
247 *
248 * Assume interrupts are disabled and zones lock is
249 * locked.
250 *
251 * @param order Size (2^order) of free space we are trying to find.
252 * @param flags Required flags of the target zone.
253 * @param hind Preferred zone.
254 *
255 */
256NO_TRACE static size_t find_free_zone(uint8_t order, zone_flags_t flags,
257 size_t hint)
258{
259 if (hint >= zones.count)
260 hint = 0;
261
262 size_t i = hint;
263 do {
264 /*
265 * Check whether the zone meets the search criteria.
266 */
267 if (ZONE_FLAGS_MATCH(zones.info[i].flags, flags)) {
268 /*
269 * Check if the zone has 2^order frames area available.
270 */
271 if (zone_can_alloc(&zones.info[i], order))
272 return i;
273 }
274
275 i++;
276 if (i >= zones.count)
277 i = 0;
278
279 } while (i != hint);
280
281 return (size_t) -1;
282}
283
284/**************************/
285/* Buddy system functions */
286/**************************/
287
288/** Buddy system find_block implementation.
289 *
290 * Find block that is parent of current list.
291 * That means go to lower addresses, until such block is found
292 *
293 * @param order Order of parent must be different then this
294 * parameter!!
295 *
296 */
297NO_TRACE static link_t *zone_buddy_find_block(buddy_system_t *buddy,
298 link_t *child, uint8_t order)
299{
300 frame_t *frame = list_get_instance(child, frame_t, buddy_link);
301 zone_t *zone = (zone_t *) buddy->data;
302
303 size_t index = frame_index(zone, frame);
304 do {
305 if (zone->frames[index].buddy_order != order)
306 return &zone->frames[index].buddy_link;
307 } while (index-- > 0);
308
309 return NULL;
310}
311
312/** Buddy system find_buddy implementation.
313 *
314 * @param buddy Buddy system.
315 * @param block Block for which buddy should be found.
316 *
317 * @return Buddy for given block if found.
318 *
319 */
320NO_TRACE static link_t *zone_buddy_find_buddy(buddy_system_t *buddy,
321 link_t *block)
322{
323 frame_t *frame = list_get_instance(block, frame_t, buddy_link);
324 zone_t *zone = (zone_t *) buddy->data;
325 ASSERT(IS_BUDDY_ORDER_OK(frame_index_abs(zone, frame),
326 frame->buddy_order));
327
328 bool is_left = IS_BUDDY_LEFT_BLOCK_ABS(zone, frame);
329
330 size_t index;
331 if (is_left) {
332 index = (frame_index(zone, frame)) +
333 (1 << frame->buddy_order);
334 } else { /* is_right */
335 index = (frame_index(zone, frame)) -
336 (1 << frame->buddy_order);
337 }
338
339 if (frame_index_valid(zone, index)) {
340 if ((zone->frames[index].buddy_order == frame->buddy_order) &&
341 (zone->frames[index].refcount == 0)) {
342 return &zone->frames[index].buddy_link;
343 }
344 }
345
346 return NULL;
347}
348
349/** Buddy system bisect implementation.
350 *
351 * @param buddy Buddy system.
352 * @param block Block to bisect.
353 *
354 * @return Right block.
355 *
356 */
357NO_TRACE static link_t *zone_buddy_bisect(buddy_system_t *buddy, link_t *block)
358{
359 frame_t *frame_l = list_get_instance(block, frame_t, buddy_link);
360 frame_t *frame_r = (frame_l + (1 << (frame_l->buddy_order - 1)));
361
362 return &frame_r->buddy_link;
363}
364
365/** Buddy system coalesce implementation.
366 *
367 * @param buddy Buddy system.
368 * @param block_1 First block.
369 * @param block_2 First block's buddy.
370 *
371 * @return Coalesced block (actually block that represents lower
372 * address).
373 *
374 */
375NO_TRACE static link_t *zone_buddy_coalesce(buddy_system_t *buddy,
376 link_t *block_1, link_t *block_2)
377{
378 frame_t *frame1 = list_get_instance(block_1, frame_t, buddy_link);
379 frame_t *frame2 = list_get_instance(block_2, frame_t, buddy_link);
380
381 return ((frame1 < frame2) ? block_1 : block_2);
382}
383
384/** Buddy system set_order implementation.
385 *
386 * @param buddy Buddy system.
387 * @param block Buddy system block.
388 * @param order Order to set.
389 *
390 */
391NO_TRACE static void zone_buddy_set_order(buddy_system_t *buddy, link_t *block,
392 uint8_t order)
393{
394 list_get_instance(block, frame_t, buddy_link)->buddy_order = order;
395}
396
397/** Buddy system get_order implementation.
398 *
399 * @param buddy Buddy system.
400 * @param block Buddy system block.
401 *
402 * @return Order of block.
403 *
404 */
405NO_TRACE static uint8_t zone_buddy_get_order(buddy_system_t *buddy,
406 link_t *block)
407{
408 return list_get_instance(block, frame_t, buddy_link)->buddy_order;
409}
410
411/** Buddy system mark_busy implementation.
412 *
413 * @param buddy Buddy system.
414 * @param block Buddy system block.
415 *
416 */
417NO_TRACE static void zone_buddy_mark_busy(buddy_system_t *buddy, link_t *block)
418{
419 list_get_instance(block, frame_t, buddy_link)->refcount = 1;
420}
421
422/** Buddy system mark_available implementation.
423 *
424 * @param buddy Buddy system.
425 * @param block Buddy system block.
426 *
427 */
428NO_TRACE static void zone_buddy_mark_available(buddy_system_t *buddy,
429 link_t *block)
430{
431 list_get_instance(block, frame_t, buddy_link)->refcount = 0;
432}
433
434static buddy_system_operations_t zone_buddy_system_operations = {
435 .find_buddy = zone_buddy_find_buddy,
436 .bisect = zone_buddy_bisect,
437 .coalesce = zone_buddy_coalesce,
438 .set_order = zone_buddy_set_order,
439 .get_order = zone_buddy_get_order,
440 .mark_busy = zone_buddy_mark_busy,
441 .mark_available = zone_buddy_mark_available,
442 .find_block = zone_buddy_find_block
443};
444
445/******************/
446/* Zone functions */
447/******************/
448
449/** Allocate frame in particular zone.
450 *
451 * Assume zone is locked and is available for allocation.
452 * Panics if allocation is impossible.
453 *
454 * @param zone Zone to allocate from.
455 * @param order Allocate exactly 2^order frames.
456 *
457 * @return Frame index in zone.
458 *
459 */
460NO_TRACE static pfn_t zone_frame_alloc(zone_t *zone, uint8_t order)
461{
462 ASSERT(zone->flags & ZONE_AVAILABLE);
463
464 /* Allocate frames from zone buddy system */
465 link_t *link = buddy_system_alloc(zone->buddy_system, order);
466
467 ASSERT(link);
468
469 /* Update zone information. */
470 zone->free_count -= (1 << order);
471 zone->busy_count += (1 << order);
472
473 /* Frame will be actually a first frame of the block. */
474 frame_t *frame = list_get_instance(link, frame_t, buddy_link);
475
476 /* Get frame address */
477 return make_frame_index(zone, frame);
478}
479
480/** Free frame from zone.
481 *
482 * Assume zone is locked and is available for deallocation.
483 *
484 * @param zone Pointer to zone from which the frame is to be freed.
485 * @param frame_idx Frame index relative to zone.
486 *
487 * @return Number of freed frames.
488 *
489 */
490NO_TRACE static size_t zone_frame_free(zone_t *zone, size_t frame_idx)
491{
492 ASSERT(zone->flags & ZONE_AVAILABLE);
493
494 frame_t *frame = &zone->frames[frame_idx];
495 size_t size = 0;
496
497 ASSERT(frame->refcount);
498
499 if (!--frame->refcount) {
500 size = 1 << frame->buddy_order;
501 buddy_system_free(zone->buddy_system, &frame->buddy_link);
502 /* Update zone information. */
503 zone->free_count += size;
504 zone->busy_count -= size;
505 }
506
507 return size;
508}
509
510/** Return frame from zone. */
511NO_TRACE static frame_t *zone_get_frame(zone_t *zone, size_t frame_idx)
512{
513 ASSERT(frame_idx < zone->count);
514 return &zone->frames[frame_idx];
515}
516
517/** Mark frame in zone unavailable to allocation. */
518NO_TRACE static void zone_mark_unavailable(zone_t *zone, size_t frame_idx)
519{
520 if (!(zone->flags & ZONE_AVAILABLE))
521 return;
522// ASSERT(zone->flags & ZONE_AVAILABLE);
523
524 frame_t *frame = zone_get_frame(zone, frame_idx);
525 if (frame->refcount)
526 return;
527
528 link_t *link __attribute__ ((unused));
529
530 link = buddy_system_alloc_block(zone->buddy_system,
531 &frame->buddy_link);
532
533 ASSERT(link);
534 zone->free_count--;
535 reserve_force_alloc(1);
536}
537
538/** Merge two zones.
539 *
540 * Expect buddy to point to space at least zone_conf_size large.
541 * Assume z1 & z2 are locked and compatible and zones lock is
542 * locked.
543 *
544 * @param z1 First zone to merge.
545 * @param z2 Second zone to merge.
546 * @param old_z1 Original date of the first zone.
547 * @param buddy Merged zone buddy.
548 *
549 */
550NO_TRACE static void zone_merge_internal(size_t z1, size_t z2, zone_t *old_z1,
551 buddy_system_t *buddy)
552{
553 ASSERT(zones.info[z1].flags & ZONE_AVAILABLE);
554 ASSERT(zones.info[z2].flags & ZONE_AVAILABLE);
555 ASSERT(zones.info[z1].flags == zones.info[z2].flags);
556 ASSERT(zones.info[z1].base < zones.info[z2].base);
557 ASSERT(!overlaps(zones.info[z1].base, zones.info[z1].count,
558 zones.info[z2].base, zones.info[z2].count));
559
560 /* Difference between zone bases */
561 pfn_t base_diff = zones.info[z2].base - zones.info[z1].base;
562
563 zones.info[z1].count = base_diff + zones.info[z2].count;
564 zones.info[z1].free_count += zones.info[z2].free_count;
565 zones.info[z1].busy_count += zones.info[z2].busy_count;
566 zones.info[z1].buddy_system = buddy;
567
568 uint8_t order = fnzb(zones.info[z1].count);
569 buddy_system_create(zones.info[z1].buddy_system, order,
570 &zone_buddy_system_operations, (void *) &zones.info[z1]);
571
572 zones.info[z1].frames =
573 (frame_t *) ((uint8_t *) zones.info[z1].buddy_system
574 + buddy_conf_size(order));
575
576 /* This marks all frames busy */
577 size_t i;
578 for (i = 0; i < zones.info[z1].count; i++)
579 frame_initialize(&zones.info[z1].frames[i]);
580
581 /* Copy frames from both zones to preserve full frame orders,
582 * parents etc. Set all free frames with refcount = 0 to 1, because
583 * we add all free frames to buddy allocator later again, clearing
584 * order to 0. Don't set busy frames with refcount = 0, as they
585 * will not be reallocated during merge and it would make later
586 * problems with allocation/free.
587 */
588 for (i = 0; i < old_z1->count; i++)
589 zones.info[z1].frames[i] = old_z1->frames[i];
590
591 for (i = 0; i < zones.info[z2].count; i++)
592 zones.info[z1].frames[base_diff + i]
593 = zones.info[z2].frames[i];
594
595 i = 0;
596 while (i < zones.info[z1].count) {
597 if (zones.info[z1].frames[i].refcount) {
598 /* Skip busy frames */
599 i += 1 << zones.info[z1].frames[i].buddy_order;
600 } else {
601 /* Free frames, set refcount = 1
602 * (all free frames have refcount == 0, we need not
603 * to check the order)
604 */
605 zones.info[z1].frames[i].refcount = 1;
606 zones.info[z1].frames[i].buddy_order = 0;
607 i++;
608 }
609 }
610
611 /* Add free blocks from the original zone z1 */
612 while (zone_can_alloc(old_z1, 0)) {
613 /* Allocate from the original zone */
614 pfn_t frame_idx = zone_frame_alloc(old_z1, 0);
615
616 /* Free the frame from the merged zone */
617 frame_t *frame = &zones.info[z1].frames[frame_idx];
618 frame->refcount = 0;
619 buddy_system_free(zones.info[z1].buddy_system, &frame->buddy_link);
620 }
621
622 /* Add free blocks from the original zone z2 */
623 while (zone_can_alloc(&zones.info[z2], 0)) {
624 /* Allocate from the original zone */
625 pfn_t frame_idx = zone_frame_alloc(&zones.info[z2], 0);
626
627 /* Free the frame from the merged zone */
628 frame_t *frame = &zones.info[z1].frames[base_diff + frame_idx];
629 frame->refcount = 0;
630 buddy_system_free(zones.info[z1].buddy_system, &frame->buddy_link);
631 }
632}
633
634/** Return old configuration frames into the zone.
635 *
636 * We have two cases:
637 * - The configuration data is outside the zone
638 * -> do nothing (perhaps call frame_free?)
639 * - The configuration data was created by zone_create
640 * or updated by reduce_region -> free every frame
641 *
642 * @param znum The actual zone where freeing should occur.
643 * @param pfn Old zone configuration frame.
644 * @param count Old zone frame count.
645 *
646 */
647NO_TRACE static void return_config_frames(size_t znum, pfn_t pfn, size_t count)
648{
649 ASSERT(zones.info[znum].flags & ZONE_AVAILABLE);
650
651 size_t cframes = SIZE2FRAMES(zone_conf_size(count));
652
653 if ((pfn < zones.info[znum].base)
654 || (pfn >= zones.info[znum].base + zones.info[znum].count))
655 return;
656
657 frame_t *frame __attribute__ ((unused));
658
659 frame = &zones.info[znum].frames[pfn - zones.info[znum].base];
660 ASSERT(!frame->buddy_order);
661
662 size_t i;
663 for (i = 0; i < cframes; i++) {
664 zones.info[znum].busy_count++;
665 (void) zone_frame_free(&zones.info[znum],
666 pfn - zones.info[znum].base + i);
667 }
668}
669
670/** Reduce allocated block to count of order 0 frames.
671 *
672 * The allocated block needs 2^order frames. Reduce all frames
673 * in the block to order 0 and free the unneeded frames. This means that
674 * when freeing the previously allocated block starting with frame_idx,
675 * you have to free every frame.
676 *
677 * @param znum Zone.
678 * @param frame_idx Index the first frame of the block.
679 * @param count Allocated frames in block.
680 *
681 */
682NO_TRACE static void zone_reduce_region(size_t znum, pfn_t frame_idx,
683 size_t count)
684{
685 ASSERT(zones.info[znum].flags & ZONE_AVAILABLE);
686 ASSERT(frame_idx + count < zones.info[znum].count);
687
688 uint8_t order = zones.info[znum].frames[frame_idx].buddy_order;
689 ASSERT((size_t) (1 << order) >= count);
690
691 /* Reduce all blocks to order 0 */
692 size_t i;
693 for (i = 0; i < (size_t) (1 << order); i++) {
694 frame_t *frame = &zones.info[znum].frames[i + frame_idx];
695 frame->buddy_order = 0;
696 if (!frame->refcount)
697 frame->refcount = 1;
698 ASSERT(frame->refcount == 1);
699 }
700
701 /* Free unneeded frames */
702 for (i = count; i < (size_t) (1 << order); i++)
703 (void) zone_frame_free(&zones.info[znum], i + frame_idx);
704}
705
706/** Merge zones z1 and z2.
707 *
708 * The merged zones must be 2 zones with no zone existing in between
709 * (which means that z2 = z1 + 1). Both zones must be available zones
710 * with the same flags.
711 *
712 * When you create a new zone, the frame allocator configuration does
713 * not to be 2^order size. Once the allocator is running it is no longer
714 * possible, merged configuration data occupies more space :-/
715 *
716 */
717bool zone_merge(size_t z1, size_t z2)
718{
719 irq_spinlock_lock(&zones.lock, true);
720
721 bool ret = true;
722
723 /* We can join only 2 zones with none existing inbetween,
724 * the zones have to be available and with the same
725 * set of flags
726 */
727 if ((z1 >= zones.count) || (z2 >= zones.count) || (z2 - z1 != 1) ||
728 (zones.info[z1].flags != zones.info[z2].flags)) {
729 ret = false;
730 goto errout;
731 }
732
733 pfn_t cframes = SIZE2FRAMES(zone_conf_size(
734 zones.info[z2].base - zones.info[z1].base
735 + zones.info[z2].count));
736
737 uint8_t order;
738 if (cframes == 1)
739 order = 0;
740 else
741 order = fnzb(cframes - 1) + 1;
742
743 /* Allocate merged zone data inside one of the zones */
744 pfn_t pfn;
745 if (zone_can_alloc(&zones.info[z1], order)) {
746 pfn = zones.info[z1].base + zone_frame_alloc(&zones.info[z1], order);
747 } else if (zone_can_alloc(&zones.info[z2], order)) {
748 pfn = zones.info[z2].base + zone_frame_alloc(&zones.info[z2], order);
749 } else {
750 ret = false;
751 goto errout;
752 }
753
754 /* Preserve original data from z1 */
755 zone_t old_z1 = zones.info[z1];
756 old_z1.buddy_system->data = (void *) &old_z1;
757
758 /* Do zone merging */
759 buddy_system_t *buddy = (buddy_system_t *) PA2KA(PFN2ADDR(pfn));
760 zone_merge_internal(z1, z2, &old_z1, buddy);
761
762 /* Free unneeded config frames */
763 zone_reduce_region(z1, pfn - zones.info[z1].base, cframes);
764
765 /* Subtract zone information from busy frames */
766 zones.info[z1].busy_count -= cframes;
767
768 /* Free old zone information */
769 return_config_frames(z1,
770 ADDR2PFN(KA2PA((uintptr_t) old_z1.frames)), old_z1.count);
771 return_config_frames(z1,
772 ADDR2PFN(KA2PA((uintptr_t) zones.info[z2].frames)),
773 zones.info[z2].count);
774
775 /* Move zones down */
776 size_t i;
777 for (i = z2 + 1; i < zones.count; i++) {
778 zones.info[i - 1] = zones.info[i];
779 if (zones.info[i - 1].buddy_system != NULL)
780 zones.info[i - 1].buddy_system->data =
781 (void *) &zones.info[i - 1];
782 }
783
784 zones.count--;
785
786errout:
787 irq_spinlock_unlock(&zones.lock, true);
788
789 return ret;
790}
791
792/** Merge all mergeable zones into one big zone.
793 *
794 * It is reasonable to do this on systems where
795 * BIOS reports parts in chunks, so that we could
796 * have 1 zone (it's faster).
797 *
798 */
799void zone_merge_all(void)
800{
801 size_t i = 0;
802 while (i < zones.count) {
803 if (!zone_merge(i, i + 1))
804 i++;
805 }
806}
807
808/** Create new frame zone.
809 *
810 * @param zone Zone to construct.
811 * @param buddy Address of buddy system configuration information.
812 * @param start Physical address of the first frame within the zone.
813 * @param count Count of frames in zone.
814 * @param flags Zone flags.
815 *
816 * @return Initialized zone.
817 *
818 */
819NO_TRACE static void zone_construct(zone_t *zone, buddy_system_t *buddy,
820 pfn_t start, size_t count, zone_flags_t flags)
821{
822 zone->base = start;
823 zone->count = count;
824 zone->flags = flags;
825 zone->free_count = count;
826 zone->busy_count = 0;
827 zone->buddy_system = buddy;
828
829 if (flags & ZONE_AVAILABLE) {
830 /*
831 * Compute order for buddy system and initialize
832 */
833 uint8_t order = fnzb(count);
834 buddy_system_create(zone->buddy_system, order,
835 &zone_buddy_system_operations, (void *) zone);
836
837 /* Allocate frames _after_ the confframe */
838
839 /* Check sizes */
840 zone->frames = (frame_t *) ((uint8_t *) zone->buddy_system +
841 buddy_conf_size(order));
842
843 size_t i;
844 for (i = 0; i < count; i++)
845 frame_initialize(&zone->frames[i]);
846
847 /* Stuffing frames */
848 for (i = 0; i < count; i++) {
849 zone->frames[i].refcount = 0;
850 buddy_system_free(zone->buddy_system, &zone->frames[i].buddy_link);
851 }
852 } else
853 zone->frames = NULL;
854}
855
856/** Compute configuration data size for zone.
857 *
858 * @param count Size of zone in frames.
859 *
860 * @return Size of zone configuration info (in bytes).
861 *
862 */
863size_t zone_conf_size(size_t count)
864{
865 return (count * sizeof(frame_t) + buddy_conf_size(fnzb(count)));
866}
867
868/** Allocate external configuration frames from low memory. */
869pfn_t zone_external_conf_alloc(size_t count)
870{
871 size_t size = zone_conf_size(count);
872 size_t order = ispwr2(size) ? fnzb(size) : (fnzb(size) + 1);
873
874 return ADDR2PFN((uintptr_t) frame_alloc(order - FRAME_WIDTH,
875 FRAME_LOWMEM | FRAME_ATOMIC));
876}
877
878/** Create and add zone to system.
879 *
880 * @param start First frame number (absolute).
881 * @param count Size of zone in frames.
882 * @param confframe Where configuration frames are supposed to be.
883 * Automatically checks, that we will not disturb the
884 * kernel and possibly init. If confframe is given
885 * _outside_ this zone, it is expected, that the area is
886 * already marked BUSY and big enough to contain
887 * zone_conf_size() amount of data. If the confframe is
888 * inside the area, the zone free frame information is
889 * modified not to include it.
890 *
891 * @return Zone number or -1 on error.
892 *
893 */
894size_t zone_create(pfn_t start, size_t count, pfn_t confframe,
895 zone_flags_t flags)
896{
897 irq_spinlock_lock(&zones.lock, true);
898
899 if (flags & ZONE_AVAILABLE) { /* Create available zone */
900 /* Theoretically we could have NULL here, practically make sure
901 * nobody tries to do that. If some platform requires, remove
902 * the assert
903 */
904 ASSERT(confframe != ADDR2PFN((uintptr_t ) NULL));
905
906 /* Update the known end of physical memory. */
907 config.physmem_end = max(config.physmem_end, PFN2ADDR(start + count));
908
909 /* If confframe is supposed to be inside our zone, then make sure
910 * it does not span kernel & init
911 */
912 size_t confcount = SIZE2FRAMES(zone_conf_size(count));
913 if ((confframe >= start) && (confframe < start + count)) {
914 for (; confframe < start + count; confframe++) {
915 uintptr_t addr = PFN2ADDR(confframe);
916 if (overlaps(addr, PFN2ADDR(confcount),
917 KA2PA(config.base), config.kernel_size))
918 continue;
919
920 if (overlaps(addr, PFN2ADDR(confcount),
921 KA2PA(config.stack_base), config.stack_size))
922 continue;
923
924 bool overlap = false;
925 size_t i;
926 for (i = 0; i < init.cnt; i++)
927 if (overlaps(addr, PFN2ADDR(confcount),
928 init.tasks[i].paddr,
929 init.tasks[i].size)) {
930 overlap = true;
931 break;
932 }
933 if (overlap)
934 continue;
935
936 break;
937 }
938
939 if (confframe >= start + count) {
940 flags &= ~ZONE_AVAILABLE;
941 goto nonavail;
942// panic("Cannot find configuration data for zone.");
943 }
944 }
945
946 size_t znum = zones_insert_zone(start, count, flags);
947 if (znum == (size_t) -1) {
948 irq_spinlock_unlock(&zones.lock, true);
949 return (size_t) -1;
950 }
951
952 buddy_system_t *buddy = (buddy_system_t *) PA2KA(PFN2ADDR(confframe));
953 zone_construct(&zones.info[znum], buddy, start, count, flags);
954
955 /* If confdata in zone, mark as unavailable */
956 if ((confframe >= start) && (confframe < start + count)) {
957 size_t i;
958 for (i = confframe; i < confframe + confcount; i++)
959 zone_mark_unavailable(&zones.info[znum],
960 i - zones.info[znum].base);
961 }
962
963 irq_spinlock_unlock(&zones.lock, true);
964
965 return znum;
966 }
967nonavail:
968 (void)0; // label trick
969 /* Non-available zone */
970 size_t znum = zones_insert_zone(start, count, flags);
971 if (znum == (size_t) -1) {
972 irq_spinlock_unlock(&zones.lock, true);
973 return (size_t) -1;
974 }
975 zone_construct(&zones.info[znum], NULL, start, count, flags);
976
977 irq_spinlock_unlock(&zones.lock, true);
978
979 return znum;
980}
981
982/*******************/
983/* Frame functions */
984/*******************/
985
986/** Set parent of frame. */
987void frame_set_parent(pfn_t pfn, void *data, size_t hint)
988{
989 irq_spinlock_lock(&zones.lock, true);
990
991 size_t znum = find_zone(pfn, 1, hint);
992
993 ASSERT(znum != (size_t) -1);
994
995 zone_get_frame(&zones.info[znum],
996 pfn - zones.info[znum].base)->parent = data;
997
998 irq_spinlock_unlock(&zones.lock, true);
999}
1000
1001void *frame_get_parent(pfn_t pfn, size_t hint)
1002{
1003 irq_spinlock_lock(&zones.lock, true);
1004
1005 size_t znum = find_zone(pfn, 1, hint);
1006
1007 ASSERT(znum != (size_t) -1);
1008
1009 void *res = zone_get_frame(&zones.info[znum],
1010 pfn - zones.info[znum].base)->parent;
1011
1012 irq_spinlock_unlock(&zones.lock, true);
1013
1014 return res;
1015}
1016
1017/** Allocate power-of-two frames of physical memory.
1018 *
1019 * @param order Allocate exactly 2^order frames.
1020 * @param flags Flags for host zone selection and address processing.
1021 * @param pzone Preferred zone.
1022 *
1023 * @return Physical address of the allocated frame.
1024 *
1025 */
1026void *frame_alloc_generic(uint8_t order, frame_flags_t flags, size_t *pzone)
1027{
1028 size_t size = ((size_t) 1) << order;
1029 size_t hint = pzone ? (*pzone) : 0;
1030
1031 /*
1032 * If not told otherwise, we must first reserve the memory.
1033 */
1034 if (!(flags & FRAME_NO_RESERVE))
1035 reserve_force_alloc(size);
1036
1037loop:
1038 irq_spinlock_lock(&zones.lock, true);
1039
1040 /*
1041 * First, find suitable frame zone.
1042 */
1043 size_t znum = find_free_zone(order,
1044 FRAME_TO_ZONE_FLAGS(flags), hint);
1045
1046 /* If no memory, reclaim some slab memory,
1047 if it does not help, reclaim all */
1048 if ((znum == (size_t) -1) && (!(flags & FRAME_NO_RECLAIM))) {
1049 irq_spinlock_unlock(&zones.lock, true);
1050 size_t freed = slab_reclaim(0);
1051 irq_spinlock_lock(&zones.lock, true);
1052
1053 if (freed > 0)
1054 znum = find_free_zone(order,
1055 FRAME_TO_ZONE_FLAGS(flags), hint);
1056
1057 if (znum == (size_t) -1) {
1058 irq_spinlock_unlock(&zones.lock, true);
1059 freed = slab_reclaim(SLAB_RECLAIM_ALL);
1060 irq_spinlock_lock(&zones.lock, true);
1061
1062 if (freed > 0)
1063 znum = find_free_zone(order,
1064 FRAME_TO_ZONE_FLAGS(flags), hint);
1065 }
1066 }
1067
1068 if (znum == (size_t) -1) {
1069 if (flags & FRAME_ATOMIC) {
1070 irq_spinlock_unlock(&zones.lock, true);
1071 if (!(flags & FRAME_NO_RESERVE))
1072 reserve_free(size);
1073 return NULL;
1074 }
1075
1076#ifdef CONFIG_DEBUG
1077 size_t avail = frame_total_free_get_internal();
1078#endif
1079
1080 irq_spinlock_unlock(&zones.lock, true);
1081
1082 if (!THREAD)
1083 panic("Cannot wait for memory to become available.");
1084
1085 /*
1086 * Sleep until some frames are available again.
1087 */
1088
1089#ifdef CONFIG_DEBUG
1090 printf("Thread %" PRIu64 " waiting for %zu frames, "
1091 "%zu available.\n", THREAD->tid, size, avail);
1092#endif
1093
1094 /*
1095 * Since the mem_avail_mtx is an active mutex, we need to disable interrupts
1096 * to prevent deadlock with TLB shootdown.
1097 */
1098 ipl_t ipl = interrupts_disable();
1099 mutex_lock(&mem_avail_mtx);
1100
1101 if (mem_avail_req > 0)
1102 mem_avail_req = min(mem_avail_req, size);
1103 else
1104 mem_avail_req = size;
1105 size_t gen = mem_avail_gen;
1106
1107 while (gen == mem_avail_gen)
1108 condvar_wait(&mem_avail_cv, &mem_avail_mtx);
1109
1110 mutex_unlock(&mem_avail_mtx);
1111 interrupts_restore(ipl);
1112
1113#ifdef CONFIG_DEBUG
1114 printf("Thread %" PRIu64 " woken up.\n", THREAD->tid);
1115#endif
1116
1117 goto loop;
1118 }
1119
1120 pfn_t pfn = zone_frame_alloc(&zones.info[znum], order)
1121 + zones.info[znum].base;
1122
1123 irq_spinlock_unlock(&zones.lock, true);
1124
1125 if (pzone)
1126 *pzone = znum;
1127
1128 if (flags & FRAME_KA)
1129 return (void *) PA2KA(PFN2ADDR(pfn));
1130
1131 return (void *) PFN2ADDR(pfn);
1132}
1133
1134void *frame_alloc(uint8_t order, frame_flags_t flags)
1135{
1136 return frame_alloc_generic(order, flags, NULL);
1137}
1138
1139void *frame_alloc_noreserve(uint8_t order, frame_flags_t flags)
1140{
1141 return frame_alloc_generic(order, flags | FRAME_NO_RESERVE, NULL);
1142}
1143
1144/** Free a frame.
1145 *
1146 * Find respective frame structure for supplied physical frame address.
1147 * Decrement frame reference count. If it drops to zero, move the frame
1148 * structure to free list.
1149 *
1150 * @param frame Physical Address of of the frame to be freed.
1151 * @param flags Flags to control memory reservation.
1152 *
1153 */
1154void frame_free_generic(uintptr_t frame, frame_flags_t flags)
1155{
1156 size_t size;
1157
1158 irq_spinlock_lock(&zones.lock, true);
1159
1160 /*
1161 * First, find host frame zone for addr.
1162 */
1163 pfn_t pfn = ADDR2PFN(frame);
1164 size_t znum = find_zone(pfn, 1, 0);
1165
1166 ASSERT(znum != (size_t) -1);
1167
1168 size = zone_frame_free(&zones.info[znum], pfn - zones.info[znum].base);
1169
1170 irq_spinlock_unlock(&zones.lock, true);
1171
1172 /*
1173 * Signal that some memory has been freed.
1174 */
1175
1176
1177 /*
1178 * Since the mem_avail_mtx is an active mutex, we need to disable interrupts
1179 * to prevent deadlock with TLB shootdown.
1180 */
1181 ipl_t ipl = interrupts_disable();
1182 mutex_lock(&mem_avail_mtx);
1183 if (mem_avail_req > 0)
1184 mem_avail_req -= min(mem_avail_req, size);
1185
1186 if (mem_avail_req == 0) {
1187 mem_avail_gen++;
1188 condvar_broadcast(&mem_avail_cv);
1189 }
1190 mutex_unlock(&mem_avail_mtx);
1191 interrupts_restore(ipl);
1192
1193 if (!(flags & FRAME_NO_RESERVE))
1194 reserve_free(size);
1195}
1196
1197void frame_free(uintptr_t frame)
1198{
1199 frame_free_generic(frame, 0);
1200}
1201
1202void frame_free_noreserve(uintptr_t frame)
1203{
1204 frame_free_generic(frame, FRAME_NO_RESERVE);
1205}
1206
1207/** Add reference to frame.
1208 *
1209 * Find respective frame structure for supplied PFN and
1210 * increment frame reference count.
1211 *
1212 * @param pfn Frame number of the frame to be freed.
1213 *
1214 */
1215NO_TRACE void frame_reference_add(pfn_t pfn)
1216{
1217 irq_spinlock_lock(&zones.lock, true);
1218
1219 /*
1220 * First, find host frame zone for addr.
1221 */
1222 size_t znum = find_zone(pfn, 1, 0);
1223
1224 ASSERT(znum != (size_t) -1);
1225
1226 zones.info[znum].frames[pfn - zones.info[znum].base].refcount++;
1227
1228 irq_spinlock_unlock(&zones.lock, true);
1229}
1230
1231/** Mark given range unavailable in frame zones.
1232 *
1233 */
1234NO_TRACE void frame_mark_unavailable(pfn_t start, size_t count)
1235{
1236 irq_spinlock_lock(&zones.lock, true);
1237
1238 size_t i;
1239 for (i = 0; i < count; i++) {
1240 size_t znum = find_zone(start + i, 1, 0);
1241 if (znum == (size_t) -1) /* PFN not found */
1242 continue;
1243
1244 zone_mark_unavailable(&zones.info[znum],
1245 start + i - zones.info[znum].base);
1246 }
1247
1248 irq_spinlock_unlock(&zones.lock, true);
1249}
1250
1251/** Initialize physical memory management.
1252 *
1253 */
1254void frame_init(void)
1255{
1256 if (config.cpu_active == 1) {
1257 zones.count = 0;
1258 irq_spinlock_initialize(&zones.lock, "frame.zones.lock");
1259 mutex_initialize(&mem_avail_mtx, MUTEX_ACTIVE);
1260 condvar_initialize(&mem_avail_cv);
1261 }
1262
1263 /* Tell the architecture to create some memory */
1264 frame_low_arch_init();
1265 if (config.cpu_active == 1) {
1266 frame_mark_unavailable(ADDR2PFN(KA2PA(config.base)),
1267 SIZE2FRAMES(config.kernel_size));
1268 frame_mark_unavailable(ADDR2PFN(KA2PA(config.stack_base)),
1269 SIZE2FRAMES(config.stack_size));
1270
1271 size_t i;
1272 for (i = 0; i < init.cnt; i++) {
1273 pfn_t pfn = ADDR2PFN(init.tasks[i].paddr);
1274 frame_mark_unavailable(pfn,
1275 SIZE2FRAMES(init.tasks[i].size));
1276 }
1277
1278 if (ballocs.size)
1279 frame_mark_unavailable(ADDR2PFN(KA2PA(ballocs.base)),
1280 SIZE2FRAMES(ballocs.size));
1281
1282 /* Black list first frame, as allocating NULL would
1283 * fail in some places
1284 */
1285 frame_mark_unavailable(0, 1);
1286 }
1287 frame_high_arch_init();
1288}
1289
1290/** Adjust bounds of physical memory region according to low/high memory split.
1291 *
1292 * @param low[in] If true, the adjustment is performed to make the region
1293 * fit in the low memory. Otherwise the adjustment is
1294 * performed to make the region fit in the high memory.
1295 * @param basep[inout] Pointer to a variable which contains the region's base
1296 * address and which may receive the adjusted base address.
1297 * @param sizep[inout] Pointer to a variable which contains the region's size
1298 * and which may receive the adjusted size.
1299 * @retun True if the region still exists even after the
1300 * adjustment, false otherwise.
1301 */
1302bool frame_adjust_zone_bounds(bool low, uintptr_t *basep, size_t *sizep)
1303{
1304 uintptr_t limit = KA2PA(config.identity_base) + config.identity_size;
1305
1306 if (low) {
1307 if (*basep > limit)
1308 return false;
1309 if (*basep + *sizep > limit)
1310 *sizep = limit - *basep;
1311 } else {
1312 if (*basep + *sizep <= limit)
1313 return false;
1314 if (*basep <= limit) {
1315 *sizep -= limit - *basep;
1316 *basep = limit;
1317 }
1318 }
1319 return true;
1320}
1321
1322/** Return total size of all zones.
1323 *
1324 */
1325uint64_t zones_total_size(void)
1326{
1327 irq_spinlock_lock(&zones.lock, true);
1328
1329 uint64_t total = 0;
1330 size_t i;
1331 for (i = 0; i < zones.count; i++)
1332 total += (uint64_t) FRAMES2SIZE(zones.info[i].count);
1333
1334 irq_spinlock_unlock(&zones.lock, true);
1335
1336 return total;
1337}
1338
1339void zones_stats(uint64_t *total, uint64_t *unavail, uint64_t *busy,
1340 uint64_t *free)
1341{
1342 ASSERT(total != NULL);
1343 ASSERT(unavail != NULL);
1344 ASSERT(busy != NULL);
1345 ASSERT(free != NULL);
1346
1347 irq_spinlock_lock(&zones.lock, true);
1348
1349 *total = 0;
1350 *unavail = 0;
1351 *busy = 0;
1352 *free = 0;
1353
1354 size_t i;
1355 for (i = 0; i < zones.count; i++) {
1356 *total += (uint64_t) FRAMES2SIZE(zones.info[i].count);
1357
1358 if (zones.info[i].flags & ZONE_AVAILABLE) {
1359 *busy += (uint64_t) FRAMES2SIZE(zones.info[i].busy_count);
1360 *free += (uint64_t) FRAMES2SIZE(zones.info[i].free_count);
1361 } else
1362 *unavail += (uint64_t) FRAMES2SIZE(zones.info[i].count);
1363 }
1364
1365 irq_spinlock_unlock(&zones.lock, true);
1366}
1367
1368/** Prints list of zones.
1369 *
1370 */
1371void zones_print_list(void)
1372{
1373#ifdef __32_BITS__
1374 printf("[nr] [base addr] [frames ] [flags ] [free frames ] [busy frames ]\n");
1375#endif
1376
1377#ifdef __64_BITS__
1378 printf("[nr] [base address ] [frames ] [flags ] [free frames ] [busy frames ]\n");
1379#endif
1380
1381 /*
1382 * Because printing may require allocation of memory, we may not hold
1383 * the frame allocator locks when printing zone statistics. Therefore,
1384 * we simply gather the statistics under the protection of the locks and
1385 * print the statistics when the locks have been released.
1386 *
1387 * When someone adds/removes zones while we are printing the statistics,
1388 * we may end up with inaccurate output (e.g. a zone being skipped from
1389 * the listing).
1390 */
1391
1392 size_t i;
1393 for (i = 0;; i++) {
1394 irq_spinlock_lock(&zones.lock, true);
1395
1396 if (i >= zones.count) {
1397 irq_spinlock_unlock(&zones.lock, true);
1398 break;
1399 }
1400
1401 uintptr_t base = PFN2ADDR(zones.info[i].base);
1402 size_t count = zones.info[i].count;
1403 zone_flags_t flags = zones.info[i].flags;
1404 size_t free_count = zones.info[i].free_count;
1405 size_t busy_count = zones.info[i].busy_count;
1406
1407 irq_spinlock_unlock(&zones.lock, true);
1408
1409 bool available = ((flags & ZONE_AVAILABLE) != 0);
1410
1411 printf("%-4zu", i);
1412
1413#ifdef __32_BITS__
1414 printf(" %p", (void *) base);
1415#endif
1416
1417#ifdef __64_BITS__
1418 printf(" %p", (void *) base);
1419#endif
1420
1421 printf(" %12zu %c%c%c%c%c ", count,
1422 available ? 'A' : '-',
1423 (flags & ZONE_RESERVED) ? 'R' : '-',
1424 (flags & ZONE_FIRMWARE) ? 'F' : '-',
1425 (flags & ZONE_LOWMEM) ? 'L' : '-',
1426 (flags & ZONE_HIGHMEM) ? 'H' : '-');
1427
1428 if (available)
1429 printf("%14zu %14zu",
1430 free_count, busy_count);
1431
1432 printf("\n");
1433 }
1434}
1435
1436/** Prints zone details.
1437 *
1438 * @param num Zone base address or zone number.
1439 *
1440 */
1441void zone_print_one(size_t num)
1442{
1443 irq_spinlock_lock(&zones.lock, true);
1444 size_t znum = (size_t) -1;
1445
1446 size_t i;
1447 for (i = 0; i < zones.count; i++) {
1448 if ((i == num) || (PFN2ADDR(zones.info[i].base) == num)) {
1449 znum = i;
1450 break;
1451 }
1452 }
1453
1454 if (znum == (size_t) -1) {
1455 irq_spinlock_unlock(&zones.lock, true);
1456 printf("Zone not found.\n");
1457 return;
1458 }
1459
1460 uintptr_t base = PFN2ADDR(zones.info[i].base);
1461 zone_flags_t flags = zones.info[i].flags;
1462 size_t count = zones.info[i].count;
1463 size_t free_count = zones.info[i].free_count;
1464 size_t busy_count = zones.info[i].busy_count;
1465
1466 irq_spinlock_unlock(&zones.lock, true);
1467
1468 bool available = ((flags & ZONE_AVAILABLE) != 0);
1469
1470 uint64_t size;
1471 const char *size_suffix;
1472 bin_order_suffix(FRAMES2SIZE(count), &size, &size_suffix, false);
1473
1474 printf("Zone number: %zu\n", znum);
1475 printf("Zone base address: %p\n", (void *) base);
1476 printf("Zone size: %zu frames (%" PRIu64 " %s)\n", count,
1477 size, size_suffix);
1478 printf("Zone flags: %c%c%c%c%c\n",
1479 available ? 'A' : '-',
1480 (flags & ZONE_RESERVED) ? 'R' : '-',
1481 (flags & ZONE_FIRMWARE) ? 'F' : '-',
1482 (flags & ZONE_LOWMEM) ? 'L' : '-',
1483 (flags & ZONE_HIGHMEM) ? 'H' : '-');
1484
1485 if (available) {
1486 bin_order_suffix(FRAMES2SIZE(busy_count), &size, &size_suffix,
1487 false);
1488 printf("Allocated space: %zu frames (%" PRIu64 " %s)\n",
1489 busy_count, size, size_suffix);
1490 bin_order_suffix(FRAMES2SIZE(free_count), &size, &size_suffix,
1491 false);
1492 printf("Available space: %zu frames (%" PRIu64 " %s)\n",
1493 free_count, size, size_suffix);
1494 }
1495}
1496
1497/** @}
1498 */
Note: See TracBrowser for help on using the repository browser.