HelenOS sources
This source file includes following definitions.
- tlb_init
- tlb_shootdown_start
- tlb_shootdown_finalize
- tlb_shootdown_ipi_send
- tlb_shootdown_ipi_recv
#include <mm/tlb.h>
#include <mm/asid.h>
#include <arch/mm/tlb.h>
#include <assert.h>
#include <smp/ipi.h>
#include <synch/spinlock.h>
#include <atomic.h>
#include <arch/interrupt.h>
#include <config.h>
#include <arch.h>
#include <panic.h>
#include <cpu.h>
void tlb_init(void)
{
tlb_arch_init();
}
#ifdef CONFIG_SMP
IRQ_SPINLOCK_STATIC_INITIALIZE(tlblock);
ipl_t tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid,
uintptr_t page, size_t count)
{
ipl_t ipl = interrupts_disable();
CPU->tlb_active = false;
irq_spinlock_lock(&tlblock, false);
size_t i;
for (i = 0; i < config.cpu_count; i++) {
if (i == CPU->id)
continue;
cpu_t *cpu = &cpus[i];
irq_spinlock_lock(&cpu->tlb_lock, false);
if (cpu->tlb_messages_count == TLB_MESSAGE_QUEUE_LEN) {
cpu->tlb_messages_count = 1;
cpu->tlb_messages[0].type = TLB_INVL_ALL;
cpu->tlb_messages[0].asid = ASID_INVALID;
cpu->tlb_messages[0].page = 0;
cpu->tlb_messages[0].count = 0;
} else {
size_t idx = cpu->tlb_messages_count++;
cpu->tlb_messages[idx].type = type;
cpu->tlb_messages[idx].asid = asid;
cpu->tlb_messages[idx].page = page;
cpu->tlb_messages[idx].count = count;
}
irq_spinlock_unlock(&cpu->tlb_lock, false);
}
tlb_shootdown_ipi_send();
busy_wait:
for (i = 0; i < config.cpu_count; i++) {
if (cpus[i].tlb_active)
goto busy_wait;
}
return ipl;
}
void tlb_shootdown_finalize(ipl_t ipl)
{
irq_spinlock_unlock(&tlblock, false);
CPU->tlb_active = true;
interrupts_restore(ipl);
}
void tlb_shootdown_ipi_send(void)
{
ipi_broadcast(VECTOR_TLB_SHOOTDOWN_IPI);
}
void tlb_shootdown_ipi_recv(void)
{
assert(CPU);
CPU->tlb_active = false;
irq_spinlock_lock(&tlblock, false);
irq_spinlock_unlock(&tlblock, false);
irq_spinlock_lock(&CPU->tlb_lock, false);
assert(CPU->tlb_messages_count <= TLB_MESSAGE_QUEUE_LEN);
size_t i;
for (i = 0; i < CPU->tlb_messages_count; i++) {
tlb_invalidate_type_t type = CPU->tlb_messages[i].type;
asid_t asid = CPU->tlb_messages[i].asid;
uintptr_t page = CPU->tlb_messages[i].page;
size_t count = CPU->tlb_messages[i].count;
switch (type) {
case TLB_INVL_ALL:
tlb_invalidate_all();
break;
case TLB_INVL_ASID:
tlb_invalidate_asid(asid);
break;
case TLB_INVL_PAGES:
assert(count);
tlb_invalidate_pages(asid, page, count);
break;
default:
panic("Unknown type (%d).", type);
break;
}
if (type == TLB_INVL_ALL)
break;
}
CPU->tlb_messages_count = 0;
irq_spinlock_unlock(&CPU->tlb_lock, false);
CPU->tlb_active = true;
}
#endif
HelenOS homepage, sources at GitHub