Rev 1224 | Rev 1248 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed
| Rev 1224 | Rev 1236 | ||
|---|---|---|---|
| Line 56... | Line 56... | ||
| 56 | typedef struct { |
56 | typedef struct { |
| 57 | count_t refcount; /**< tracking of shared frames */ |
57 | count_t refcount; /**< tracking of shared frames */ |
| 58 | __u8 buddy_order; /**< buddy system block order */ |
58 | __u8 buddy_order; /**< buddy system block order */ |
| 59 | link_t buddy_link; /**< link to the next free block inside one order */ |
59 | link_t buddy_link; /**< link to the next free block inside one order */ |
| 60 | void *parent; /**< If allocated by slab, this points there */ |
60 | void *parent; /**< If allocated by slab, this points there */ |
| 61 | }frame_t; |
61 | } frame_t; |
| 62 | 62 | ||
| 63 | typedef struct { |
63 | typedef struct { |
| 64 | SPINLOCK_DECLARE(lock); /**< this lock protects everything below */ |
64 | SPINLOCK_DECLARE(lock); /**< this lock protects everything below */ |
| 65 | pfn_t base; /**< frame_no of the first frame in the frames array */ |
65 | pfn_t base; /**< frame_no of the first frame in the frames array */ |
| 66 | count_t count; /**< Size of zone */ |
66 | count_t count; /**< Size of zone */ |
| 67 | 67 | ||
| 68 | frame_t *frames; /**< array of frame_t structures in this zone */ |
68 | frame_t *frames; /**< array of frame_t structures in this zone */ |
| 69 | count_t free_count; /**< number of free frame_t structures */ |
69 | count_t free_count; /**< number of free frame_t structures */ |
| 70 | count_t busy_count; /**< number of busy frame_t structures */ |
70 | count_t busy_count; /**< number of busy frame_t structures */ |
| 71 | 71 | ||
| 72 | buddy_system_t * buddy_system; /**< buddy system for the zone */ |
72 | buddy_system_t * buddy_system; /**< buddy system for the zone */ |
| 73 | int flags; |
73 | int flags; |
| 74 | }zone_t; |
74 | } zone_t; |
| 75 | 75 | ||
| 76 | /* |
76 | /* |
| 77 | * The zoneinfo.lock must be locked when accessing zoneinfo structure. |
77 | * The zoneinfo.lock must be locked when accessing zoneinfo structure. |
| 78 | * Some of the attributes in zone_t structures are 'read-only' |
78 | * Some of the attributes in zone_t structures are 'read-only' |
| 79 | */ |
79 | */ |
| 80 | 80 | ||
| 81 | struct { |
81 | struct { |
| 82 | SPINLOCK_DECLARE(lock); |
82 | SPINLOCK_DECLARE(lock); |
| 83 | int count; |
83 | int count; |
| 84 | zone_t *info[ZONES_MAX]; |
84 | zone_t *info[ZONES_MAX]; |
| 85 | }zones; |
85 | } zones; |
| 86 | 86 | ||
| 87 | 87 | ||
| 88 | /*********************************/ |
88 | /*********************************/ |
| 89 | /* Helper functions */ |
89 | /* Helper functions */ |
| 90 | static inline index_t frame_index(zone_t *zone, frame_t *frame) |
90 | static inline index_t frame_index(zone_t *zone, frame_t *frame) |
| Line 942... | Line 942... | ||
| 942 | return v; |
942 | return v; |
| 943 | } |
943 | } |
| 944 | 944 | ||
| 945 | /** Free a frame. |
945 | /** Free a frame. |
| 946 | * |
946 | * |
| 947 | * Find respective frame structure for supplied addr. |
947 | * Find respective frame structure for supplied PFN. |
| 948 | * Decrement frame reference count. |
948 | * Decrement frame reference count. |
| 949 | * If it drops to zero, move the frame structure to free list. |
949 | * If it drops to zero, move the frame structure to free list. |
| 950 | * |
950 | * |
| 951 | * @param frame Frame no to be freed. |
951 | * @param frame Frame number to be freed. |
| 952 | */ |
952 | */ |
| 953 | void frame_free(pfn_t pfn) |
953 | void frame_free(pfn_t pfn) |
| 954 | { |
954 | { |
| 955 | ipl_t ipl; |
955 | ipl_t ipl; |
| 956 | zone_t *zone; |
956 | zone_t *zone; |
| Line 967... | Line 967... | ||
| 967 | 967 | ||
| 968 | spinlock_unlock(&zone->lock); |
968 | spinlock_unlock(&zone->lock); |
| 969 | interrupts_restore(ipl); |
969 | interrupts_restore(ipl); |
| 970 | } |
970 | } |
| 971 | 971 | ||
| - | 972 | /** Add reference to frame. |
|
| - | 973 | * |
|
| - | 974 | * Find respective frame structure for supplied PFN and |
|
| - | 975 | * increment frame reference count. |
|
| - | 976 | * |
|
| - | 977 | * @param frame Frame no to be freed. |
|
| - | 978 | */ |
|
| - | 979 | void frame_reference_add(pfn_t pfn) |
|
| - | 980 | { |
|
| - | 981 | ipl_t ipl; |
|
| - | 982 | zone_t *zone; |
|
| - | 983 | frame_t *frame; |
|
| 972 | 984 | ||
| - | 985 | ipl = interrupts_disable(); |
|
| - | 986 | ||
| - | 987 | /* |
|
| - | 988 | * First, find host frame zone for addr. |
|
| - | 989 | */ |
|
| - | 990 | zone = find_zone_and_lock(pfn,NULL); |
|
| - | 991 | ASSERT(zone); |
|
| - | 992 | ||
| - | 993 | frame = &zone->frames[pfn-zone->base]; |
|
| - | 994 | frame->refcount++; |
|
| - | 995 | ||
| - | 996 | spinlock_unlock(&zone->lock); |
|
| - | 997 | interrupts_restore(ipl); |
|
| - | 998 | } |
|
| 973 | 999 | ||
| 974 | /** Mark given range unavailable in frame zones */ |
1000 | /** Mark given range unavailable in frame zones */ |
| 975 | void frame_mark_unavailable(pfn_t start, count_t count) |
1001 | void frame_mark_unavailable(pfn_t start, count_t count) |
| 976 | { |
1002 | { |
| 977 | int i; |
1003 | int i; |