Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 726 → Rev 727

/kernel/trunk/arch/mips32/src/mm/asid.c
28,93 → 28,5
*/
 
#include <arch/mm/asid.h>
#include <synch/spinlock.h>
#include <arch.h>
#include <debug.h>
#include <typedefs.h>
 
SPINLOCK_INITIALIZE(asid_usage_lock);
static count_t asid_usage[ASIDS]; /**< Usage tracking array for ASIDs */
 
/** Get ASID
*
* Get the least used ASID.
*
* @return ASID
*/
asid_t asid_get(void)
{
ipl_t ipl;
int i, j;
count_t min;
min = (unsigned) -1;
ipl = interrupts_disable();
spinlock_lock(&asid_usage_lock);
for (i = ASID_START, j = ASID_START; i < ASIDS; i++) {
if (asid_usage[i] < min) {
j = i;
min = asid_usage[i];
if (!min)
break;
}
}
 
asid_usage[j]++;
 
spinlock_unlock(&asid_usage_lock);
interrupts_restore(ipl);
 
return i;
}
 
/** Release ASID
*
* Release ASID by decrementing its usage count.
*
* @param asid ASID.
*/
void asid_put(asid_t asid)
{
ipl_t ipl;
 
ipl = interrupts_disable();
spinlock_lock(&asid_usage_lock);
 
ASSERT(asid != ASID_INVALID);
ASSERT(asid_usage[asid] > 0);
asid_usage[asid]--;
 
spinlock_unlock(&asid_usage_lock);
interrupts_restore(ipl);
}
 
/** Find out whether ASID is used by more address spaces
*
* Find out whether ASID is used by more address spaces.
*
* @param asid ASID in question.
*
* @return True if 'asid' is used by more address spaces, false otherwise.
*/
bool asid_has_conflicts(asid_t asid)
{
bool has_conflicts = false;
ipl_t ipl;
 
ASSERT(asid != ASID_INVALID);
 
ipl = interrupts_disable();
spinlock_lock(&asid_usage_lock);
 
if (asid_usage[asid] > 1)
has_conflicts = true;
 
spinlock_unlock(&asid_usage_lock);
interrupts_restore(ipl);
 
return has_conflicts;
}
/kernel/trunk/arch/mips32/src/mm/tlb.c
27,7 → 27,7
*/
 
#include <arch/mm/tlb.h>
#include <arch/mm/asid.h>
#include <mm/asid.h>
#include <mm/tlb.h>
#include <mm/page.h>
#include <mm/as.h>
494,13 → 494,15
cp0_entry_hi_write(hi_save.value);
}
 
/** Invalidate TLB entry for specified page belonging to specified address space.
/** Invalidate TLB entries for specified page range belonging to specified address space.
*
* @param asid Address space identifier.
* @param page Page whose TLB entry is to be invalidated.
* @param page First page whose TLB entry is to be invalidated.
* @param cnt Number of entries to invalidate.
*/
void tlb_invalidate_page(asid_t asid, __address page)
void tlb_invalidate_pages(asid_t asid, __address page, count_t cnt)
{
int i;
ipl_t ipl;
entry_lo_t lo0, lo1;
entry_hi_t hi, hi_save;
511,27 → 513,29
hi_save.value = cp0_entry_hi_read();
ipl = interrupts_disable();
 
hi.value = 0;
prepare_entry_hi(&hi, asid, page);
cp0_entry_hi_write(hi.value);
for (i = 0; i < cnt; i++) {
hi.value = 0;
prepare_entry_hi(&hi, asid, page + i * PAGE_SIZE);
cp0_entry_hi_write(hi.value);
 
tlbp();
index.value = cp0_index_read();
tlbp();
index.value = cp0_index_read();
 
if (!index.p) {
/* Entry was found, index register contains valid index. */
tlbr();
if (!index.p) {
/* Entry was found, index register contains valid index. */
tlbr();
 
lo0.value = cp0_entry_lo0_read();
lo1.value = cp0_entry_lo1_read();
lo0.value = cp0_entry_lo0_read();
lo1.value = cp0_entry_lo1_read();
 
lo0.v = 0;
lo1.v = 0;
lo0.v = 0;
lo1.v = 0;
 
cp0_entry_lo0_write(lo0.value);
cp0_entry_lo1_write(lo1.value);
cp0_entry_lo0_write(lo0.value);
cp0_entry_lo1_write(lo1.value);
 
tlbwi();
tlbwi();
}
}
interrupts_restore(ipl);
/kernel/trunk/arch/mips32/src/mm/as.c
35,7 → 35,7
 
/** Install address space.
*
* Install ASID and if necessary, purge TLB.
* Install ASID.
*
* @param as Address space structure.
*/
45,11 → 45,6
ipl_t ipl;
 
/*
* If necessary, purge TLB.
*/
tlb_invalidate_asid(as->asid); /* TODO: do it only if necessary */
 
/*
* Install ASID.
*/
hi.value = cp0_entry_hi_read();