Subversion Repositories HelenOS

Rev

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

Rev 2071 Rev 2170
Line 60... Line 60...
60
#include <mm/as.h>
60
#include <mm/as.h>
61
#include <mm/tlb.h>
61
#include <mm/tlb.h>
62
#include <arch/mm/asid.h>
62
#include <arch/mm/asid.h>
63
#include <synch/spinlock.h>
63
#include <synch/spinlock.h>
64
#include <synch/mutex.h>
64
#include <synch/mutex.h>
65
#include <arch.h>
-
 
66
#include <adt/list.h>
65
#include <adt/list.h>
67
#include <debug.h>
66
#include <debug.h>
68
 
67
 
69
/**
-
 
70
 * asidlock protects the asids_allocated counter.
-
 
71
 */
-
 
72
SPINLOCK_INITIALIZE(asidlock);
-
 
73
 
-
 
74
static count_t asids_allocated = 0;
68
static count_t asids_allocated = 0;
75
 
69
 
76
/** Allocate free address space identifier.
70
/** Allocate free address space identifier.
77
 *
71
 *
78
 * Interrupts must be disabled and inactive_as_with_asid_lock must be held
72
 * Interrupts must be disabled and inactive_as_with_asid_lock must be held
Line 88... Line 82...
88
 
82
 
89
    /*
83
    /*
90
     * Check if there is an unallocated ASID.
84
     * Check if there is an unallocated ASID.
91
     */
85
     */
92
   
86
   
93
    spinlock_lock(&asidlock);
-
 
94
    if (asids_allocated == ASIDS_ALLOCABLE) {
87
    if (asids_allocated == ASIDS_ALLOCABLE) {
95
 
88
 
96
        /*
89
        /*
97
         * All ASIDs are already allocated.
90
         * All ASIDs are already allocated.
98
         * Resort to stealing.
91
         * Resort to stealing.
Line 106... Line 99...
106
        ASSERT(!list_empty(&inactive_as_with_asid_head));
99
        ASSERT(!list_empty(&inactive_as_with_asid_head));
107
        tmp = inactive_as_with_asid_head.next;
100
        tmp = inactive_as_with_asid_head.next;
108
        list_remove(tmp);
101
        list_remove(tmp);
109
       
102
       
110
        as = list_get_instance(tmp, as_t, inactive_as_with_asid_link);
103
        as = list_get_instance(tmp, as_t, inactive_as_with_asid_link);
111
        mutex_lock_active(&as->lock);
-
 
112
 
104
 
113
        /*
105
        /*
114
         * Steal the ASID.
106
         * Steal the ASID.
115
         * Note that the stolen ASID is not active.
107
         * Note that the stolen ASID is not active.
116
         */
108
         */
Line 128... Line 120...
128
         * of TLB entries (e.g. TSB on sparc64), the
120
         * of TLB entries (e.g. TSB on sparc64), the
129
         * cache must be invalidated as well.
121
         * cache must be invalidated as well.
130
         */
122
         */
131
        as_invalidate_translation_cache(as, 0, (count_t) -1);
123
        as_invalidate_translation_cache(as, 0, (count_t) -1);
132
       
124
       
133
        mutex_unlock(&as->lock);
-
 
134
 
-
 
135
        /*
125
        /*
136
         * Get the system rid of the stolen ASID.
126
         * Get the system rid of the stolen ASID.
137
         */
127
         */
138
        tlb_shootdown_start(TLB_INVL_ASID, asid, 0, 0);
128
        tlb_shootdown_start(TLB_INVL_ASID, asid, 0, 0);
139
        tlb_invalidate_asid(asid);
129
        tlb_invalidate_asid(asid);
Line 154... Line 144...
154
        tlb_shootdown_start(TLB_INVL_ASID, asid, 0, 0);
144
        tlb_shootdown_start(TLB_INVL_ASID, asid, 0, 0);
155
        tlb_invalidate_asid(asid);
145
        tlb_invalidate_asid(asid);
156
        tlb_shootdown_finalize();
146
        tlb_shootdown_finalize();
157
    }
147
    }
158
   
148
   
159
    spinlock_unlock(&asidlock);
-
 
160
   
-
 
161
    return asid;
149
    return asid;
162
}
150
}
163
 
151
 
164
/** Release address space identifier.
152
/** Release address space identifier.
165
 *
153
 *
Line 168... Line 156...
168
 *
156
 *
169
 * @param asid ASID to be released.
157
 * @param asid ASID to be released.
170
 */
158
 */
171
void asid_put(asid_t asid)
159
void asid_put(asid_t asid)
172
{
160
{
173
    ipl_t ipl;
-
 
174
 
-
 
175
    ipl = interrupts_disable();
-
 
176
    spinlock_lock(&asidlock);
-
 
177
 
-
 
178
    asids_allocated--;
161
    asids_allocated--;
179
    asid_put_arch(asid);
162
    asid_put_arch(asid);
180
   
-
 
181
    spinlock_unlock(&asidlock);
-
 
182
    interrupts_restore(ipl);
-
 
183
}
163
}
184
 
164
 
185
/** @}
165
/** @}
186
 */
166
 */