Subversion Repositories HelenOS

Rev

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

Rev 2089 Rev 2141
Line 53... Line 53...
53
 
53
 
54
static index_t hash(unative_t key[]);
54
static index_t hash(unative_t key[]);
55
static bool compare(unative_t key[], count_t keys, link_t *item);
55
static bool compare(unative_t key[], count_t keys, link_t *item);
56
static void remove_callback(link_t *item);
56
static void remove_callback(link_t *item);
57
 
57
 
58
static void ht_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int flags);
58
static void ht_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame,
-
 
59
    int flags);
59
static void ht_mapping_remove(as_t *as, uintptr_t page);
60
static void ht_mapping_remove(as_t *as, uintptr_t page);
60
static pte_t *ht_mapping_find(as_t *as, uintptr_t page);
61
static pte_t *ht_mapping_find(as_t *as, uintptr_t page);
61
 
62
 
62
/**
63
/**
63
 * This lock protects the page hash table. It must be acquired
64
 * This lock protects the page hash table. It must be acquired
Line 101... Line 102...
101
    /*
102
    /*
102
     * Virtual page addresses have roughly the same probability
103
     * Virtual page addresses have roughly the same probability
103
     * of occurring. Least significant bits of VPN compose the
104
     * of occurring. Least significant bits of VPN compose the
104
     * hash index.
105
     * hash index.
105
     */
106
     */
106
    index = ((page >> PAGE_WIDTH) & (PAGE_HT_ENTRIES-1));
107
    index = ((page >> PAGE_WIDTH) & (PAGE_HT_ENTRIES - 1));
107
   
108
   
108
    /*
109
    /*
109
     * Address space structures are likely to be allocated from
110
     * Address space structures are likely to be allocated from
110
     * similar addresses. Least significant bits compose the
111
     * similar addresses. Least significant bits compose the
111
     * hash index.
112
     * hash index.
112
     */
113
     */
113
    index |= ((unative_t) as) & (PAGE_HT_ENTRIES-1);
114
    index |= ((unative_t) as) & (PAGE_HT_ENTRIES - 1);
114
   
115
   
115
    return index;
116
    return index;
116
}
117
}
117
 
118
 
118
/** Compare page hash table item with page and/or address space.
119
/** Compare page hash table item with page and/or address space.
Line 134... Line 135...
134
     * Convert item to PTE.
135
     * Convert item to PTE.
135
     */
136
     */
136
    t = hash_table_get_instance(item, pte_t, link);
137
    t = hash_table_get_instance(item, pte_t, link);
137
 
138
 
138
    if (keys == PAGE_HT_KEYS) {
139
    if (keys == PAGE_HT_KEYS) {
139
        return (key[KEY_AS] == (uintptr_t) t->as) && (key[KEY_PAGE] == t->page);
140
        return (key[KEY_AS] == (uintptr_t) t->as) &&
-
 
141
            (key[KEY_PAGE] == t->page);
140
    } else {
142
    } else {
141
        return (key[KEY_AS] == (uintptr_t) t->as);
143
        return (key[KEY_AS] == (uintptr_t) t->as);
142
    }
144
    }
143
}
145
}
144
 
146
 
Line 173... Line 175...
173
 * @param flags Flags to be used for mapping.
175
 * @param flags Flags to be used for mapping.
174
 */
176
 */
175
void ht_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int flags)
177
void ht_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int flags)
176
{
178
{
177
    pte_t *t;
179
    pte_t *t;
-
 
180
    unative_t key[2] = {
-
 
181
        (uintptr_t) as,
178
    unative_t key[2] = { (uintptr_t) as, page = ALIGN_DOWN(page, PAGE_SIZE) };
182
        page = ALIGN_DOWN(page, PAGE_SIZE)
-
 
183
    };
179
   
184
   
180
    if (!hash_table_find(&page_ht, key)) {
185
    if (!hash_table_find(&page_ht, key)) {
181
        t = (pte_t *) malloc(sizeof(pte_t), FRAME_ATOMIC);
186
        t = (pte_t *) malloc(sizeof(pte_t), FRAME_ATOMIC);
182
        ASSERT(t != NULL);
187
        ASSERT(t != NULL);
183
 
188
 
Line 207... Line 212...
207
 * @param as Address space to wich page belongs.
212
 * @param as Address space to wich page belongs.
208
 * @param page Virtual address of the page to be demapped.
213
 * @param page Virtual address of the page to be demapped.
209
 */
214
 */
210
void ht_mapping_remove(as_t *as, uintptr_t page)
215
void ht_mapping_remove(as_t *as, uintptr_t page)
211
{
216
{
-
 
217
    unative_t key[2] = {
-
 
218
        (uintptr_t) as,
212
    unative_t key[2] = { (uintptr_t) as, page = ALIGN_DOWN(page, PAGE_SIZE) };
219
        page = ALIGN_DOWN(page, PAGE_SIZE)
-
 
220
    };
213
   
221
   
214
    /*
222
    /*
215
     * Note that removed PTE's will be freed
223
     * Note that removed PTE's will be freed
216
     * by remove_callback().
224
     * by remove_callback().
217
     */
225
     */
Line 232... Line 240...
232
 */
240
 */
233
pte_t *ht_mapping_find(as_t *as, uintptr_t page)
241
pte_t *ht_mapping_find(as_t *as, uintptr_t page)
234
{
242
{
235
    link_t *hlp;
243
    link_t *hlp;
236
    pte_t *t = NULL;
244
    pte_t *t = NULL;
-
 
245
    unative_t key[2] = {
-
 
246
        (uintptr_t) as,
237
    unative_t key[2] = { (uintptr_t) as, page = ALIGN_DOWN(page, PAGE_SIZE) };
247
        page = ALIGN_DOWN(page, PAGE_SIZE)
-
 
248
    };
238
   
249
   
239
    hlp = hash_table_find(&page_ht, key);
250
    hlp = hash_table_find(&page_ht, key);
240
    if (hlp)
251
    if (hlp)
241
        t = hash_table_get_instance(hlp, pte_t, link);
252
        t = hash_table_get_instance(hlp, pte_t, link);
242
 
253