Subversion Repositories HelenOS-historic

Rev

Rev 1702 | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 1702 Rev 1780
Line 50... Line 50...
50
#include <debug.h>
50
#include <debug.h>
51
#include <memstr.h>
51
#include <memstr.h>
52
#include <adt/hash_table.h>
52
#include <adt/hash_table.h>
53
#include <align.h>
53
#include <align.h>
54
 
54
 
55
static index_t hash(__native key[]);
55
static index_t hash(unative_t key[]);
56
static bool compare(__native key[], count_t keys, link_t *item);
56
static bool compare(unative_t key[], count_t keys, link_t *item);
57
static void remove_callback(link_t *item);
57
static void remove_callback(link_t *item);
58
 
58
 
59
static void ht_mapping_insert(as_t *as, __address page, __address frame, int flags);
59
static void ht_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int flags);
60
static void ht_mapping_remove(as_t *as, __address page);
60
static void ht_mapping_remove(as_t *as, uintptr_t page);
61
static pte_t *ht_mapping_find(as_t *as, __address page);
61
static pte_t *ht_mapping_find(as_t *as, uintptr_t page);
62
 
62
 
63
/**
63
/**
64
 * This lock protects the page hash table. It must be acquired
64
 * This lock protects the page hash table. It must be acquired
65
 * after address space lock and after any address space area
65
 * after address space lock and after any address space area
66
 * locks.
66
 * locks.
Line 91... Line 91...
91
 *
91
 *
92
 * @param key Array of two keys (i.e. page and address space).
92
 * @param key Array of two keys (i.e. page and address space).
93
 *
93
 *
94
 * @return Index into page hash table.
94
 * @return Index into page hash table.
95
 */
95
 */
96
index_t hash(__native key[])
96
index_t hash(unative_t key[])
97
{
97
{
98
    as_t *as = (as_t *) key[KEY_AS];
98
    as_t *as = (as_t *) key[KEY_AS];
99
    __address page = (__address) key[KEY_PAGE];
99
    uintptr_t page = (uintptr_t) key[KEY_PAGE];
100
    index_t index;
100
    index_t index;
101
   
101
   
102
    /*
102
    /*
103
     * Virtual page addresses have roughly the same probability
103
     * Virtual page addresses have roughly the same probability
104
     * of occurring. Least significant bits of VPN compose the
104
     * of occurring. Least significant bits of VPN compose the
Line 109... Line 109...
109
    /*
109
    /*
110
     * Address space structures are likely to be allocated from
110
     * Address space structures are likely to be allocated from
111
     * similar addresses. Least significant bits compose the
111
     * similar addresses. Least significant bits compose the
112
     * hash index.
112
     * hash index.
113
     */
113
     */
114
    index |= ((__native) as) & (PAGE_HT_ENTRIES-1);
114
    index |= ((unative_t) as) & (PAGE_HT_ENTRIES-1);
115
   
115
   
116
    return index;
116
    return index;
117
}
117
}
118
 
118
 
119
/** Compare page hash table item with page and/or address space.
119
/** Compare page hash table item with page and/or address space.
Line 122... Line 122...
122
 * @param keys Number of keys passed.
122
 * @param keys Number of keys passed.
123
 * @param item Item to compare the keys with.
123
 * @param item Item to compare the keys with.
124
 *
124
 *
125
 * @return true on match, false otherwise.
125
 * @return true on match, false otherwise.
126
 */
126
 */
127
bool compare(__native key[], count_t keys, link_t *item)
127
bool compare(unative_t key[], count_t keys, link_t *item)
128
{
128
{
129
    pte_t *t;
129
    pte_t *t;
130
 
130
 
131
    ASSERT(item);
131
    ASSERT(item);
132
    ASSERT((keys > 0) && (keys <= PAGE_HT_KEYS));
132
    ASSERT((keys > 0) && (keys <= PAGE_HT_KEYS));
Line 135... Line 135...
135
     * Convert item to PTE.
135
     * Convert item to PTE.
136
     */
136
     */
137
    t = hash_table_get_instance(item, pte_t, link);
137
    t = hash_table_get_instance(item, pte_t, link);
138
 
138
 
139
    if (keys == PAGE_HT_KEYS) {
139
    if (keys == PAGE_HT_KEYS) {
140
        return (key[KEY_AS] == (__address) t->as) && (key[KEY_PAGE] == t->page);
140
        return (key[KEY_AS] == (uintptr_t) t->as) && (key[KEY_PAGE] == t->page);
141
    } else {
141
    } else {
142
        return (key[KEY_AS] == (__address) t->as);
142
        return (key[KEY_AS] == (uintptr_t) t->as);
143
    }
143
    }
144
}
144
}
145
 
145
 
146
/** Callback on page hash table item removal.
146
/** Callback on page hash table item removal.
147
 *
147
 *
Line 171... Line 171...
171
 * @param as Address space to which page belongs.
171
 * @param as Address space to which page belongs.
172
 * @param page Virtual address of the page to be mapped.
172
 * @param page Virtual address of the page to be mapped.
173
 * @param frame Physical address of memory frame to which the mapping is done.
173
 * @param frame Physical address of memory frame to which the mapping is done.
174
 * @param flags Flags to be used for mapping.
174
 * @param flags Flags to be used for mapping.
175
 */
175
 */
176
void ht_mapping_insert(as_t *as, __address page, __address frame, int flags)
176
void ht_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int flags)
177
{
177
{
178
    pte_t *t;
178
    pte_t *t;
179
    __native key[2] = { (__address) as, page = ALIGN_DOWN(page, PAGE_SIZE) };
179
    unative_t key[2] = { (uintptr_t) as, page = ALIGN_DOWN(page, PAGE_SIZE) };
180
   
180
   
181
    if (!hash_table_find(&page_ht, key)) {
181
    if (!hash_table_find(&page_ht, key)) {
182
        t = (pte_t *) malloc(sizeof(pte_t), FRAME_ATOMIC);
182
        t = (pte_t *) malloc(sizeof(pte_t), FRAME_ATOMIC);
183
        ASSERT(t != NULL);
183
        ASSERT(t != NULL);
184
 
184
 
Line 206... Line 206...
206
 * The page table must be locked and interrupts must be disabled.
206
 * The page table must be locked and interrupts must be disabled.
207
 *
207
 *
208
 * @param as Address space to wich page belongs.
208
 * @param as Address space to wich page belongs.
209
 * @param page Virtual address of the page to be demapped.
209
 * @param page Virtual address of the page to be demapped.
210
 */
210
 */
211
void ht_mapping_remove(as_t *as, __address page)
211
void ht_mapping_remove(as_t *as, uintptr_t page)
212
{
212
{
213
    __native key[2] = { (__address) as, page = ALIGN_DOWN(page, PAGE_SIZE) };
213
    unative_t key[2] = { (uintptr_t) as, page = ALIGN_DOWN(page, PAGE_SIZE) };
214
   
214
   
215
    /*
215
    /*
216
     * Note that removed PTE's will be freed
216
     * Note that removed PTE's will be freed
217
     * by remove_callback().
217
     * by remove_callback().
218
     */
218
     */
Line 229... Line 229...
229
 * @param as Address space to wich page belongs.
229
 * @param as Address space to wich page belongs.
230
 * @param page Virtual page.
230
 * @param page Virtual page.
231
 *
231
 *
232
 * @return NULL if there is no such mapping; requested mapping otherwise.
232
 * @return NULL if there is no such mapping; requested mapping otherwise.
233
 */
233
 */
234
pte_t *ht_mapping_find(as_t *as, __address page)
234
pte_t *ht_mapping_find(as_t *as, uintptr_t page)
235
{
235
{
236
    link_t *hlp;
236
    link_t *hlp;
237
    pte_t *t = NULL;
237
    pte_t *t = NULL;
238
    __native key[2] = { (__address) as, page = ALIGN_DOWN(page, PAGE_SIZE) };
238
    unative_t key[2] = { (uintptr_t) as, page = ALIGN_DOWN(page, PAGE_SIZE) };
239
   
239
   
240
    hlp = hash_table_find(&page_ht, key);
240
    hlp = hash_table_find(&page_ht, key);
241
    if (hlp)
241
    if (hlp)
242
        t = hash_table_get_instance(hlp, pte_t, link);
242
        t = hash_table_get_instance(hlp, pte_t, link);
243
 
243