Subversion Repositories HelenOS-historic

Rev

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

Rev 375 Rev 413
Line 66... Line 66...
66
 *
66
 *
67
 * @return Allocated frame.
67
 * @return Allocated frame.
68
 */
68
 */
69
__address frame_alloc(int flags)
69
__address frame_alloc(int flags)
70
{
70
{
71
    pri_t pri;
71
    ipl_t ipl;
72
    link_t *cur, *tmp;
72
    link_t *cur, *tmp;
73
    zone_t *z;
73
    zone_t *z;
74
    zone_t *zone = NULL;
74
    zone_t *zone = NULL;
75
    frame_t *frame = NULL;
75
    frame_t *frame = NULL;
76
    __address v;
76
    __address v;
77
   
77
   
78
loop:
78
loop:
79
    pri = cpu_priority_high();
79
    ipl = interrupts_disable();
80
    spinlock_lock(&zone_head_lock);
80
    spinlock_lock(&zone_head_lock);
81
   
81
   
82
    /*
82
    /*
83
     * First, find suitable frame zone.
83
     * First, find suitable frame zone.
84
     */
84
     */
Line 102... Line 102...
102
       
102
       
103
        /*
103
        /*
104
         * TODO: Sleep until frames are available again.
104
         * TODO: Sleep until frames are available again.
105
         */
105
         */
106
        spinlock_unlock(&zone_head_lock);
106
        spinlock_unlock(&zone_head_lock);
107
        cpu_priority_restore(pri);
107
        interrupts_restore(ipl);
108
 
108
 
109
        panic("Sleep not implemented.\n");
109
        panic("Sleep not implemented.\n");
110
        goto loop;
110
        goto loop;
111
    }
111
    }
112
       
112
       
Line 124... Line 124...
124
        v = PA2KA(v);
124
        v = PA2KA(v);
125
   
125
   
126
    spinlock_unlock(&zone->lock);
126
    spinlock_unlock(&zone->lock);
127
   
127
   
128
    spinlock_unlock(&zone_head_lock);
128
    spinlock_unlock(&zone_head_lock);
129
    cpu_priority_restore(pri);
129
    interrupts_restore(ipl);
130
   
130
   
131
    return v;
131
    return v;
132
}
132
}
133
 
133
 
134
/** Free a frame.
134
/** Free a frame.
Line 139... Line 139...
139
 *
139
 *
140
 * @param addr Address of the frame to be freed. It must be a multiple of FRAME_SIZE.
140
 * @param addr Address of the frame to be freed. It must be a multiple of FRAME_SIZE.
141
 */
141
 */
142
void frame_free(__address addr)
142
void frame_free(__address addr)
143
{
143
{
144
    pri_t pri;
144
    ipl_t ipl;
145
    link_t *cur;
145
    link_t *cur;
146
    zone_t *z;
146
    zone_t *z;
147
    zone_t *zone = NULL;
147
    zone_t *zone = NULL;
148
    frame_t *frame;
148
    frame_t *frame;
149
   
149
   
150
    ASSERT(addr % FRAME_SIZE == 0);
150
    ASSERT(addr % FRAME_SIZE == 0);
151
   
151
   
152
    pri = cpu_priority_high();
152
    ipl = interrupts_disable();
153
    spinlock_lock(&zone_head_lock);
153
    spinlock_lock(&zone_head_lock);
154
   
154
   
155
    /*
155
    /*
156
     * First, find host frame zone for addr.
156
     * First, find host frame zone for addr.
157
     */
157
     */
Line 185... Line 185...
185
    }
185
    }
186
   
186
   
187
    spinlock_unlock(&zone->lock);  
187
    spinlock_unlock(&zone->lock);  
188
   
188
   
189
    spinlock_unlock(&zone_head_lock);
189
    spinlock_unlock(&zone_head_lock);
190
    cpu_priority_restore(pri);
190
    interrupts_restore(ipl);
191
}
191
}
192
 
192
 
193
/** Mark frame not free.
193
/** Mark frame not free.
194
 *
194
 *
195
 * Find respective frame structrue for supplied addr.
195
 * Find respective frame structrue for supplied addr.
Line 197... Line 197...
197
 *
197
 *
198
 * @param addr Address of the frame to be marked. It must be a multiple of FRAME_SIZE.
198
 * @param addr Address of the frame to be marked. It must be a multiple of FRAME_SIZE.
199
 */
199
 */
200
void frame_not_free(__address addr)
200
void frame_not_free(__address addr)
201
{
201
{
202
    pri_t pri;
202
    ipl_t ipl;
203
    link_t *cur;
203
    link_t *cur;
204
    zone_t *z;
204
    zone_t *z;
205
    zone_t *zone = NULL;
205
    zone_t *zone = NULL;
206
    frame_t *frame;
206
    frame_t *frame;
207
   
207
   
208
    ASSERT(addr % FRAME_SIZE == 0);
208
    ASSERT(addr % FRAME_SIZE == 0);
209
   
209
   
210
    pri = cpu_priority_high();
210
    ipl = interrupts_disable();
211
    spinlock_lock(&zone_head_lock);
211
    spinlock_lock(&zone_head_lock);
212
   
212
   
213
    /*
213
    /*
214
     * First, find host frame zone for addr.
214
     * First, find host frame zone for addr.
215
     */
215
     */
Line 244... Line 244...
244
    }
244
    }
245
   
245
   
246
    spinlock_unlock(&zone->lock);  
246
    spinlock_unlock(&zone->lock);  
247
   
247
   
248
    spinlock_unlock(&zone_head_lock);
248
    spinlock_unlock(&zone_head_lock);
249
    cpu_priority_restore(pri);
249
    interrupts_restore(ipl);
250
}
250
}
251
 
251
 
252
/** Mark frame region not free.
252
/** Mark frame region not free.
253
 *
253
 *
254
 * Mark frame region not free.
254
 * Mark frame region not free.
Line 333... Line 333...
333
 *
333
 *
334
 * @param zone Zone to be attached.
334
 * @param zone Zone to be attached.
335
 */
335
 */
336
void zone_attach(zone_t *zone)
336
void zone_attach(zone_t *zone)
337
{
337
{
338
    pri_t pri;
338
    ipl_t ipl;
339
   
339
   
340
    pri = cpu_priority_high();
340
    ipl = interrupts_disable();
341
    spinlock_lock(&zone_head_lock);
341
    spinlock_lock(&zone_head_lock);
342
   
342
   
343
    list_append(&zone->link, &zone_head);
343
    list_append(&zone->link, &zone_head);
344
   
344
   
345
    spinlock_unlock(&zone_head_lock);
345
    spinlock_unlock(&zone_head_lock);
346
    cpu_priority_restore(pri);
346
    interrupts_restore(ipl);
347
}
347
}
348
 
348
 
349
/** Initialize frame structure
349
/** Initialize frame structure
350
 *
350
 *
351
 * Initialize frame structure.
351
 * Initialize frame structure.