Subversion Repositories HelenOS-historic

Rev

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

Rev 922 Rev 1044
Line 50... Line 50...
50
static void ht_mapping_insert(as_t *as, __address page, __address frame, int flags);
50
static void ht_mapping_insert(as_t *as, __address page, __address frame, int flags);
51
static void ht_mapping_remove(as_t *as, __address page);
51
static void ht_mapping_remove(as_t *as, __address page);
52
static pte_t *ht_mapping_find(as_t *as, __address page);
52
static pte_t *ht_mapping_find(as_t *as, __address page);
53
 
53
 
54
/**
54
/**
55
 * This lock protects the page hash table.
55
 * This lock protects the page hash table. It must be acquired
-
 
56
 * after address space lock and after any address space area
-
 
57
 * locks.
56
 */
58
 */
57
SPINLOCK_INITIALIZE(page_ht_lock);
59
SPINLOCK_INITIALIZE(page_ht_lock);
58
 
60
 
59
/**
61
/**
60
 * Page hash table.
62
 * Page hash table.
Line 153... Line 155...
153
/** Map page to frame using page hash table.
155
/** Map page to frame using page hash table.
154
 *
156
 *
155
 * Map virtual address 'page' to physical address 'frame'
157
 * Map virtual address 'page' to physical address 'frame'
156
 * using 'flags'.
158
 * using 'flags'.
157
 *
159
 *
158
 * The address space must be locked and interruptsmust be disabled.
160
 * The page table must be locked and interrupts must be disabled.
159
 *
161
 *
160
 * @param as Address space to which page belongs.
162
 * @param as Address space to which page belongs.
161
 * @param page Virtual address of the page to be mapped.
163
 * @param page Virtual address of the page to be mapped.
162
 * @param frame Physical address of memory frame to which the mapping is done.
164
 * @param frame Physical address of memory frame to which the mapping is done.
163
 * @param flags Flags to be used for mapping.
165
 * @param flags Flags to be used for mapping.
Line 165... Line 167...
165
void ht_mapping_insert(as_t *as, __address page, __address frame, int flags)
167
void ht_mapping_insert(as_t *as, __address page, __address frame, int flags)
166
{
168
{
167
    pte_t *t;
169
    pte_t *t;
168
    __native key[2] = { (__address) as, page = ALIGN_DOWN(page, PAGE_SIZE) };
170
    __native key[2] = { (__address) as, page = ALIGN_DOWN(page, PAGE_SIZE) };
169
   
171
   
170
    spinlock_lock(&page_ht_lock);
-
 
171
 
-
 
172
    if (!hash_table_find(&page_ht, key)) {
172
    if (!hash_table_find(&page_ht, key)) {
173
        t = (pte_t *) malloc(sizeof(pte_t), FRAME_ATOMIC);
173
        t = (pte_t *) malloc(sizeof(pte_t), FRAME_ATOMIC);
174
        ASSERT(t != NULL);
174
        ASSERT(t != NULL);
175
 
175
 
176
        t->g = (flags & PAGE_GLOBAL) != 0;
176
        t->g = (flags & PAGE_GLOBAL) != 0;
Line 184... Line 184...
184
        t->page = page;
184
        t->page = page;
185
        t->frame = frame;
185
        t->frame = frame;
186
 
186
 
187
        hash_table_insert(&page_ht, key, &t->link);
187
        hash_table_insert(&page_ht, key, &t->link);
188
    }
188
    }
189
   
-
 
190
    spinlock_unlock(&page_ht_lock);
-
 
191
}
189
}
192
 
190
 
193
/** Remove mapping of page from page hash table.
191
/** Remove mapping of page from page hash table.
194
 *
192
 *
195
 * Remove any mapping of 'page' within address space 'as'.
193
 * Remove any mapping of 'page' within address space 'as'.
196
 * TLB shootdown should follow in order to make effects of
194
 * TLB shootdown should follow in order to make effects of
197
 * this call visible.
195
 * this call visible.
198
 *
196
 *
199
 * The address space must be locked and interrupts must be disabled.
197
 * The page table must be locked and interrupts must be disabled.
200
 *
198
 *
201
 * @param as Address space to wich page belongs.
199
 * @param as Address space to wich page belongs.
202
 * @param page Virtual address of the page to be demapped.
200
 * @param page Virtual address of the page to be demapped.
203
 */
201
 */
204
void ht_mapping_remove(as_t *as, __address page)
202
void ht_mapping_remove(as_t *as, __address page)
205
{
203
{
206
    __native key[2] = { (__address) as, page = ALIGN_DOWN(page, PAGE_SIZE) };
204
    __native key[2] = { (__address) as, page = ALIGN_DOWN(page, PAGE_SIZE) };
207
   
205
   
208
    spinlock_lock(&page_ht_lock);
-
 
209
 
-
 
210
    /*
206
    /*
211
     * Note that removed PTE's will be freed
207
     * Note that removed PTE's will be freed
212
     * by remove_callback().
208
     * by remove_callback().
213
     */
209
     */
214
    hash_table_remove(&page_ht, key, 2);
210
    hash_table_remove(&page_ht, key, 2);
215
 
-
 
216
    spinlock_unlock(&page_ht_lock);
-
 
217
}
211
}
218
 
212
 
219
 
213
 
220
/** Find mapping for virtual page in page hash table.
214
/** Find mapping for virtual page in page hash table.
221
 *
215
 *
222
 * Find mapping for virtual page.
216
 * Find mapping for virtual page.
223
 *
217
 *
224
 * The address space must be locked and interrupts must be disabled.
218
 * The page table must be locked and interrupts must be disabled.
225
 *
219
 *
226
 * @param as Address space to wich page belongs.
220
 * @param as Address space to wich page belongs.
227
 * @param page Virtual page.
221
 * @param page Virtual page.
228
 *
222
 *
229
 * @return NULL if there is no such mapping; requested mapping otherwise.
223
 * @return NULL if there is no such mapping; requested mapping otherwise.
Line 232... Line 226...
232
{
226
{
233
    link_t *hlp;
227
    link_t *hlp;
234
    pte_t *t = NULL;
228
    pte_t *t = NULL;
235
    __native key[2] = { (__address) as, page = ALIGN_DOWN(page, PAGE_SIZE) };
229
    __native key[2] = { (__address) as, page = ALIGN_DOWN(page, PAGE_SIZE) };
236
   
230
   
237
    spinlock_lock(&page_ht_lock);
-
 
238
 
-
 
239
    hlp = hash_table_find(&page_ht, key);
231
    hlp = hash_table_find(&page_ht, key);
240
    if (hlp)
232
    if (hlp)
241
        t = hash_table_get_instance(hlp, pte_t, link);
233
        t = hash_table_get_instance(hlp, pte_t, link);
242
 
234
 
243
    spinlock_unlock(&page_ht_lock);
-
 
244
    return t;
235
    return t;
245
}
236
}