Rev 814 | Rev 822 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
Rev 814 | Rev 820 | ||
---|---|---|---|
Line 59... | Line 59... | ||
59 | }frame_t; |
59 | }frame_t; |
60 | 60 | ||
61 | typedef struct { |
61 | typedef struct { |
62 | SPINLOCK_DECLARE(lock); /**< this lock protects everything below */ |
62 | SPINLOCK_DECLARE(lock); /**< this lock protects everything below */ |
63 | pfn_t base; /**< frame_no of the first frame in the frames array */ |
63 | pfn_t base; /**< frame_no of the first frame in the frames array */ |
64 | pfn_t count; /**< Size of zone */ |
64 | count_t count; /**< Size of zone */ |
65 | 65 | ||
66 | frame_t *frames; /**< array of frame_t structures in this zone */ |
66 | frame_t *frames; /**< array of frame_t structures in this zone */ |
67 | count_t free_count; /**< number of free frame_t structures */ |
67 | count_t free_count; /**< number of free frame_t structures */ |
68 | count_t busy_count; /**< number of busy frame_t structures */ |
68 | count_t busy_count; /**< number of busy frame_t structures */ |
69 | 69 | ||
Line 97... | Line 97... | ||
97 | { |
97 | { |
98 | return index >= 0 && index < zone->count; |
98 | return index >= 0 && index < zone->count; |
99 | } |
99 | } |
100 | 100 | ||
101 | /** Compute pfn_t from frame_t pointer & zone pointer */ |
101 | /** Compute pfn_t from frame_t pointer & zone pointer */ |
102 | static pfn_t make_frame_index(zone_t *zone, frame_t *frame) |
102 | static index_t make_frame_index(zone_t *zone, frame_t *frame) |
103 | { |
103 | { |
104 | return frame - zone->frames; |
104 | return frame - zone->frames; |
105 | } |
105 | } |
106 | 106 | ||
107 | /** Initialize frame structure |
107 | /** Initialize frame structure |
Line 421... | Line 421... | ||
421 | 421 | ||
422 | /** Free frame from zone |
422 | /** Free frame from zone |
423 | * |
423 | * |
424 | * Assume zone is locked |
424 | * Assume zone is locked |
425 | */ |
425 | */ |
426 | static void zone_frame_free(zone_t *zone, pfn_t frame_idx) |
426 | static void zone_frame_free(zone_t *zone, index_t frame_idx) |
427 | { |
427 | { |
428 | frame_t *frame; |
428 | frame_t *frame; |
429 | __u8 order; |
429 | __u8 order; |
430 | 430 | ||
431 | frame = &zone->frames[frame_idx]; |
431 | frame = &zone->frames[frame_idx]; |
Line 443... | Line 443... | ||
443 | zone->free_count += (1 << order); |
443 | zone->free_count += (1 << order); |
444 | zone->busy_count -= (1 << order); |
444 | zone->busy_count -= (1 << order); |
445 | } |
445 | } |
446 | 446 | ||
447 | /** Return frame from zone */ |
447 | /** Return frame from zone */ |
448 | static frame_t * zone_get_frame(zone_t *zone, pfn_t frame_idx) |
448 | static frame_t * zone_get_frame(zone_t *zone, index_t frame_idx) |
449 | { |
449 | { |
450 | ASSERT(frame_idx < zone->count); |
450 | ASSERT(frame_idx < zone->count); |
451 | return &zone->frames[frame_idx]; |
451 | return &zone->frames[frame_idx]; |
452 | } |
452 | } |
453 | 453 | ||
454 | /** Mark frame in zone unavailable to allocation */ |
454 | /** Mark frame in zone unavailable to allocation */ |
455 | static void zone_mark_unavailable(zone_t *zone, pfn_t frame_idx) |
455 | static void zone_mark_unavailable(zone_t *zone, index_t frame_idx) |
456 | { |
456 | { |
457 | frame_t *frame; |
457 | frame_t *frame; |
458 | link_t *link; |
458 | link_t *link; |
459 | 459 | ||
460 | frame = zone_get_frame(zone, frame_idx); |
460 | frame = zone_get_frame(zone, frame_idx); |
Line 473... | Line 473... | ||
473 | * @param conffram Address of configuration frame |
473 | * @param conffram Address of configuration frame |
474 | * @param flags Zone flags. |
474 | * @param flags Zone flags. |
475 | * |
475 | * |
476 | * @return Initialized zone. |
476 | * @return Initialized zone. |
477 | */ |
477 | */ |
478 | static zone_t * zone_construct(pfn_t start, pfn_t count, |
478 | static zone_t * zone_construct(pfn_t start, count_t count, |
479 | zone_t *z, int flags) |
479 | zone_t *z, int flags) |
480 | { |
480 | { |
481 | int i; |
481 | int i; |
482 | __u8 max_order; |
482 | __u8 max_order; |
483 | 483 | ||
Line 514... | Line 514... | ||
514 | return z; |
514 | return z; |
515 | } |
515 | } |
516 | 516 | ||
517 | 517 | ||
518 | /** Compute configuration data size for zone */ |
518 | /** Compute configuration data size for zone */ |
519 | __address zone_conf_size(pfn_t start, pfn_t count) |
519 | __address zone_conf_size(pfn_t start, count_t count) |
520 | { |
520 | { |
521 | int size = sizeof(zone_t) + count*sizeof(frame_t); |
521 | int size = sizeof(zone_t) + count*sizeof(frame_t); |
522 | int max_order; |
522 | int max_order; |
523 | 523 | ||
524 | for (max_order = 0; count >> max_order; max_order++) |
524 | for (max_order = 0; count >> max_order; max_order++) |
Line 528... | Line 528... | ||
528 | } |
528 | } |
529 | 529 | ||
530 | /** Create and add zone to system |
530 | /** Create and add zone to system |
531 | * |
531 | * |
532 | * @param confframe Where configuration frame is supposed to be. |
532 | * @param confframe Where configuration frame is supposed to be. |
533 | * Always check, that we will not disturb kernel pages |
533 | * Always check, that we will not disturb the kernel and possibly init. |
534 | * the kernel and possibly init. |
- | |
535 | * If confframe is given _outside_ this zone, it is expected, |
534 | * If confframe is given _outside_ this zone, it is expected, |
536 | * that the area is already marked BUSY and big enough |
535 | * that the area is already marked BUSY and big enough |
537 | * to contain zone_conf_size() amount of data |
536 | * to contain zone_conf_size() amount of data |
538 | */ |
537 | */ |
539 | void zone_create(pfn_t start, pfn_t count, pfn_t confframe, int flags) |
538 | void zone_create(pfn_t start, count_t count, pfn_t confframe, int flags) |
540 | { |
539 | { |
541 | zone_t *z; |
540 | zone_t *z; |
542 | __address addr,endaddr; |
541 | __address addr,endaddr; |
543 | pfn_t confcount; |
542 | count_t confcount; |
544 | int i; |
543 | int i; |
545 | 544 | ||
546 | /* Theoretically we could have here 0, practically make sure |
545 | /* Theoretically we could have here 0, practically make sure |
547 | * nobody tries to do that. If some platform requires, remove |
546 | * nobody tries to do that. If some platform requires, remove |
548 | * the assert |
547 | * the assert |
549 | */ |
548 | */ |
550 | ASSERT(confframe); |
549 | ASSERT(confframe); |
551 | /* If conframe is supposed to be inside our zone, then make sure |
550 | /* If conframe is supposed to be inside our zone, then make sure |
552 | * it does not span kernel & init |
551 | * it does not span kernel & init |
553 | */ |
552 | */ |
554 | confcount = SIZE2PFN(zone_conf_size(start,count)); |
553 | confcount = SIZE2FRAMES(zone_conf_size(start,count)); |
555 | if (confframe >= start && confframe < start+count) { |
554 | if (confframe >= start && confframe < start+count) { |
556 | for (;confframe < start+count;confframe++) { |
555 | for (;confframe < start+count;confframe++) { |
557 | addr = PFN2ADDR(confframe); |
556 | addr = PFN2ADDR(confframe); |
558 | endaddr = PFN2ADDR (confframe + confcount); |
557 | endaddr = PFN2ADDR (confframe + confcount); |
559 | if (overlaps(addr, endaddr, KA2PA(config.base), |
558 | if (overlaps(addr, endaddr, KA2PA(config.base), |
Line 697... | Line 696... | ||
697 | } |
696 | } |
698 | 697 | ||
699 | 698 | ||
700 | 699 | ||
701 | /** Mark given range unavailable in frame zones */ |
700 | /** Mark given range unavailable in frame zones */ |
702 | void frame_mark_unavailable(pfn_t start, pfn_t count) |
701 | void frame_mark_unavailable(pfn_t start, count_t count) |
703 | { |
702 | { |
704 | int i; |
703 | int i; |
705 | zone_t *zone; |
704 | zone_t *zone; |
706 | int prefzone = 0; |
705 | int prefzone = 0; |
707 | 706 | ||
Line 727... | Line 726... | ||
727 | } |
726 | } |
728 | /* Tell the architecture to create some memory */ |
727 | /* Tell the architecture to create some memory */ |
729 | frame_arch_init(); |
728 | frame_arch_init(); |
730 | if (config.cpu_active == 1) { |
729 | if (config.cpu_active == 1) { |
731 | frame_mark_unavailable(ADDR2PFN(KA2PA(config.base)), |
730 | frame_mark_unavailable(ADDR2PFN(KA2PA(config.base)), |
732 | SIZE2PFN(config.kernel_size)); |
731 | SIZE2FRAMES(config.kernel_size)); |
733 | if (config.init_size > 0) |
732 | if (config.init_size > 0) |
734 | frame_mark_unavailable(ADDR2PFN(KA2PA(config.init_addr)), |
733 | frame_mark_unavailable(ADDR2PFN(KA2PA(config.init_addr)), |
735 | SIZE2PFN(config.init_size)); |
734 | SIZE2FRAMES(config.init_size)); |
736 | } |
735 | } |
737 | } |
736 | } |
738 | 737 | ||
739 | 738 | ||
740 | 739 |