Subversion Repositories HelenOS

Rev

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

Rev 746 Rev 755
Line 28... Line 28...
28
 
28
 
29
#include <genarch/mm/page_ht.h>
29
#include <genarch/mm/page_ht.h>
30
#include <mm/page.h>
30
#include <mm/page.h>
31
#include <mm/frame.h>
31
#include <mm/frame.h>
32
#include <mm/heap.h>
32
#include <mm/heap.h>
-
 
33
#include <mm/as.h>
33
#include <arch/mm/asid.h>
34
#include <arch/mm/asid.h>
34
#include <arch/types.h>
35
#include <arch/types.h>
35
#include <typedefs.h>
36
#include <typedefs.h>
36
#include <arch/asm.h>
37
#include <arch/asm.h>
37
#include <synch/spinlock.h>
38
#include <synch/spinlock.h>
Line 50... Line 51...
50
 * Page hash table pointer.
51
 * Page hash table pointer.
51
 * The page hash table may be accessed only when page_ht_lock is held.
52
 * The page hash table may be accessed only when page_ht_lock is held.
52
 */
53
 */
53
pte_t *page_ht = NULL;
54
pte_t *page_ht = NULL;
54
 
55
 
55
static void ht_mapping_insert(__address page, asid_t asid, __address frame, int flags, __address root);
56
static void ht_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root);
56
static pte_t *ht_mapping_find(__address page, asid_t asid, __address root);
57
static pte_t *ht_mapping_find(as_t *as, __address page, __address root);
57
 
58
 
58
page_operations_t page_ht_operations = {
59
page_operations_t page_ht_operations = {
59
    .mapping_insert = ht_mapping_insert,
60
    .mapping_insert = ht_mapping_insert,
60
    .mapping_find = ht_mapping_find
61
    .mapping_find = ht_mapping_find
61
};
62
};
Line 65... Line 66...
65
 * Map virtual address 'page' to physical address 'frame'
66
 * Map virtual address 'page' to physical address 'frame'
66
 * using 'flags'. In order not to disturb hardware searching,
67
 * using 'flags'. In order not to disturb hardware searching,
67
 * new mappings are appended to the end of the collision
68
 * new mappings are appended to the end of the collision
68
 * chain.
69
 * chain.
69
 *
70
 *
-
 
71
 * @param as Address space to which page belongs. Must be locked prior the call.
70
 * @param page Virtual address of the page to be mapped.
72
 * @param page Virtual address of the page to be mapped.
71
 * @param asid Address space to which page belongs.
-
 
72
 * @param frame Physical address of memory frame to which the mapping is done.
73
 * @param frame Physical address of memory frame to which the mapping is done.
73
 * @param flags Flags to be used for mapping.
74
 * @param flags Flags to be used for mapping.
74
 * @param root Ignored.
75
 * @param root Ignored.
75
 */
76
 */
76
void ht_mapping_insert(__address page, asid_t asid, __address frame, int flags, __address root)
77
void ht_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root)
77
{
78
{
78
    pte_t *t, *u;
79
    pte_t *t, *u;
79
    ipl_t ipl;
80
    ipl_t ipl;
80
   
81
   
81
    ipl = interrupts_disable();
82
    ipl = interrupts_disable();
82
    spinlock_lock(&page_ht_lock);
83
    spinlock_lock(&page_ht_lock);
83
   
84
 
84
    t = HT_HASH(page, asid);
85
    t = HT_HASH(page, as->asid);
85
    if (!HT_SLOT_EMPTY(t)) {
86
    if (!HT_SLOT_EMPTY(t)) {
86
   
87
   
87
        /*
88
        /*
88
         * The slot is occupied.
89
         * The slot is occupied.
89
         * Walk through the collision chain and append the mapping to its end.
90
         * Walk through the collision chain and append the mapping to its end.
90
         */
91
         */
91
         
92
         
92
        do {
93
        do {
93
            u = t;
94
            u = t;
94
            if (HT_COMPARE(page, asid, t)) {
95
            if (HT_COMPARE(page, as->asid, t)) {
95
                /*
96
                /*
96
                 * Nothing to do,
97
                 * Nothing to do,
97
                 * the record is already there.
98
                 * the record is already there.
98
                 */
99
                 */
99
                spinlock_unlock(&page_ht_lock);
100
                spinlock_unlock(&page_ht_lock);
Line 107... Line 108...
107
            panic("could not allocate memory\n");
108
            panic("could not allocate memory\n");
108
 
109
 
109
        HT_SET_NEXT(u, t);
110
        HT_SET_NEXT(u, t);
110
    }
111
    }
111
   
112
   
112
    HT_SET_RECORD(t, page, asid, frame, flags);
113
    HT_SET_RECORD(t, page, as->asid, frame, flags);
113
    HT_SET_NEXT(t, NULL);
114
    HT_SET_NEXT(t, NULL);
114
   
115
   
115
    spinlock_unlock(&page_ht_lock);
116
    spinlock_unlock(&page_ht_lock);
116
    interrupts_restore(ipl);
117
    interrupts_restore(ipl);
117
}
118
}
Line 120... Line 121...
120
 *
121
 *
121
 * Find mapping for virtual page.
122
 * Find mapping for virtual page.
122
 *
123
 *
123
 * Interrupts must be disabled.
124
 * Interrupts must be disabled.
124
 *
125
 *
-
 
126
 * @param as Address space to wich page belongs. Must be locked prior the call.
125
 * @param page Virtual page.
127
 * @param page Virtual page.
126
 * @param asid Address space to wich page belongs.
-
 
127
 * @param root Ignored.
128
 * @param root Ignored.
128
 *
129
 *
129
 * @return NULL if there is no such mapping; requested mapping otherwise.
130
 * @return NULL if there is no such mapping; requested mapping otherwise.
130
 */
131
 */
131
pte_t *ht_mapping_find(__address page, asid_t asid, __address root)
132
pte_t *ht_mapping_find(as_t *as, __address page, __address root)
132
{
133
{
133
    pte_t *t;
134
    pte_t *t;
134
   
135
   
135
    spinlock_lock(&page_ht_lock);
136
    spinlock_lock(&page_ht_lock);
136
    t = HT_HASH(page, asid);
137
    t = HT_HASH(page, as->asid);
137
    if (!HT_SLOT_EMPTY(t)) {
138
    if (!HT_SLOT_EMPTY(t)) {
138
        while (!HT_COMPARE(page, asid, t) && HT_GET_NEXT(t))
139
        while (!HT_COMPARE(page, as->asid, t) && HT_GET_NEXT(t))
139
            t = HT_GET_NEXT(t);
140
            t = HT_GET_NEXT(t);
140
        t = HT_COMPARE(page, asid, t) ? t : NULL;
141
        t = HT_COMPARE(page, as->asid, t) ? t : NULL;
141
    } else {
142
    } else {
142
        t = NULL;
143
        t = NULL;
143
    }
144
    }
144
    spinlock_unlock(&page_ht_lock);
145
    spinlock_unlock(&page_ht_lock);
145
    return t;
146
    return t;