Subversion Repositories HelenOS

Rev

Rev 3208 | Rev 3973 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 3208 Rev 3972
Line 36... Line 36...
36
#ifndef KERN_FRAME_H_
36
#ifndef KERN_FRAME_H_
37
#define KERN_FRAME_H_
37
#define KERN_FRAME_H_
38
 
38
 
39
#include <arch/types.h>
39
#include <arch/types.h>
40
#include <adt/list.h>
40
#include <adt/list.h>
41
#include <synch/spinlock.h>
-
 
42
#include <mm/buddy.h>
41
#include <mm/buddy.h>
43
#include <arch/mm/page.h>
42
#include <arch/mm/page.h>
44
#include <arch/mm/frame.h>
43
#include <arch/mm/frame.h>
45
 
44
 
46
#define ONE_FRAME   0
45
#define ONE_FRAME    0
47
#define TWO_FRAMES  1
46
#define TWO_FRAMES   1
48
#define FOUR_FRAMES 2
47
#define FOUR_FRAMES  2
49
 
48
 
50
 
49
 
51
#ifdef ARCH_STACK_FRAMES
50
#ifdef ARCH_STACK_FRAMES
52
#define STACK_FRAMES ARCH_STACK_FRAMES
51
    #define STACK_FRAMES  ARCH_STACK_FRAMES
53
#else
52
#else
54
#define STACK_FRAMES ONE_FRAME
53
    #define STACK_FRAMES  ONE_FRAME
55
#endif
54
#endif
56
 
55
 
57
/** Maximum number of zones in system. */
56
/** Maximum number of zones in the system. */
58
#define ZONES_MAX           16
57
#define ZONES_MAX  32
59
 
58
 
-
 
59
typedef uint8_t frame_flags_t;
-
 
60
 
60
/** Convert the frame address to kernel va. */
61
/** Convert the frame address to kernel VA. */
61
#define FRAME_KA        0x1
62
#define FRAME_KA          0x01
62
/** Do not panic and do not sleep on failure. */
63
/** Do not panic and do not sleep on failure. */
63
#define FRAME_ATOMIC        0x2
64
#define FRAME_ATOMIC      0x02
64
/** Do not start reclaiming when no free memory. */
65
/** Do not start reclaiming when no free memory. */
65
#define FRAME_NO_RECLAIM    0x4
66
#define FRAME_NO_RECLAIM  0x04
-
 
67
 
-
 
68
typedef uint8_t zone_flags_t;
-
 
69
 
66
/** Do not allocate above 4 GiB. */
70
/** Zone is reserved (not available for allocation) */
67
#define FRAME_LOW_4_GiB     0x8
71
#define ZONE_RESERVED  0x08
-
 
72
/** Zone is used by firmware (not available for allocation) */
-
 
73
#define ZONE_FIRMWARE  0x10
-
 
74
 
-
 
75
/** Currently there is no equivalent zone flags
-
 
76
    for frame flags */
-
 
77
#define FRAME_TO_ZONE_FLAGS(frame_flags)  0
68
 
78
 
69
static inline uintptr_t PFN2ADDR(pfn_t frame)
79
static inline uintptr_t PFN2ADDR(pfn_t frame)
70
{
80
{
71
    return (uintptr_t) (frame << FRAME_WIDTH);
81
    return (uintptr_t) (frame << FRAME_WIDTH);
72
}
82
}
Line 86... Line 96...
86
static inline size_t FRAMES2SIZE(count_t frames)
96
static inline size_t FRAMES2SIZE(count_t frames)
87
{
97
{
88
    return (size_t) (frames << FRAME_WIDTH);
98
    return (size_t) (frames << FRAME_WIDTH);
89
}
99
}
90
 
100
 
91
#define IS_BUDDY_ORDER_OK(index, order)     \
101
#define IS_BUDDY_ORDER_OK(index, order) \
92
    ((~(((unative_t) -1) << (order)) & (index)) == 0)
102
    ((~(((unative_t) -1) << (order)) & (index)) == 0)
93
#define IS_BUDDY_LEFT_BLOCK(zone, frame)    \
103
#define IS_BUDDY_LEFT_BLOCK(zone, frame) \
94
    (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
104
    (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x01) == 0)
95
#define IS_BUDDY_RIGHT_BLOCK(zone, frame)   \
105
#define IS_BUDDY_RIGHT_BLOCK(zone, frame) \
96
    (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
106
    (((frame_index((zone), (frame)) >> (frame)->buddy_order) & 0x01) == 1)
97
#define IS_BUDDY_LEFT_BLOCK_ABS(zone, frame)    \
107
#define IS_BUDDY_LEFT_BLOCK_ABS(zone, frame) \
98
    (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 0)
108
    (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x01) == 0)
99
#define IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame)   \
109
#define IS_BUDDY_RIGHT_BLOCK_ABS(zone, frame) \
100
    (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x1) == 1)
110
    (((frame_index_abs((zone), (frame)) >> (frame)->buddy_order) & 0x01) == 1)
101
 
111
 
102
#define frame_alloc(order, flags)       \
112
#define frame_alloc(order, flags) \
103
    frame_alloc_generic(order, flags, NULL)
113
    frame_alloc_generic(order, flags, NULL)
104
 
114
 
105
extern void frame_init(void);
115
extern void frame_init(void);
106
extern void *frame_alloc_generic(uint8_t, int, unsigned int *);
116
extern void *frame_alloc_generic(uint8_t, frame_flags_t, count_t *);
107
extern void frame_free(uintptr_t);
117
extern void frame_free(uintptr_t);
108
extern void frame_reference_add(pfn_t);
118
extern void frame_reference_add(pfn_t);
109
 
119
 
110
extern int zone_create(pfn_t, count_t, pfn_t, int);
120
extern count_t zone_create(pfn_t, count_t, pfn_t, zone_flags_t);
111
extern void *frame_get_parent(pfn_t, unsigned int);
121
extern void *frame_get_parent(pfn_t, count_t);
112
extern void frame_set_parent(pfn_t, void *, unsigned int);
122
extern void frame_set_parent(pfn_t, void *, count_t);
113
extern void frame_mark_unavailable(pfn_t, count_t);
123
extern void frame_mark_unavailable(pfn_t, count_t);
114
extern uintptr_t zone_conf_size(count_t);
124
extern uintptr_t zone_conf_size(count_t);
115
extern void zone_merge(unsigned int, unsigned int);
125
extern bool zone_merge(count_t, count_t);
116
extern void zone_merge_all(void);
126
extern void zone_merge_all(void);
117
extern uint64_t zone_total_size(void);
127
extern uint64_t zone_total_size(void);
118
 
128
 
119
/*
129
/*
120
 * Console functions
130
 * Console functions
121
 */
131
 */
122
extern void zone_print_list(void);
132
extern void zone_print_list(void);
123
extern void zone_print_one(unsigned int);
133
extern void zone_print_one(count_t);
124
 
134
 
125
#endif
135
#endif
126
 
136
 
127
/** @}
137
/** @}
128
 */
138
 */