/kernel/trunk/generic/include/mm/asid.h |
---|
26,9 → 26,35 |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/* |
* This is generic interface for managing |
* Address Space IDentifiers (ASIDs). |
*/ |
#ifndef __ASID_H__ |
#define __ASID_H__ |
#include <arch/mm/asid.h> |
#include <typedefs.h> |
#define ASID_KERNEL 0 |
#define ASID_INVALID 1 |
#define ASID_START 2 |
#define ASID_MAX ASID_MAX_ARCH |
#define ASIDS_ALLOCABLE ((ASID_MAX+1)-ASID_START) |
extern spinlock_t asidlock; |
extern link_t as_with_asid_head; |
extern asid_t asid_get(void); |
extern void asid_put(asid_t asid); |
#ifndef asid_install |
extern void asid_install(as_t *as); |
#endif /* !def asid_install */ |
#define asid_find_free() ASID_START |
#define asid_put_arch(x) |
#endif |
/kernel/trunk/generic/include/mm/tlb.h |
---|
31,25 → 31,14 |
#include <arch/mm/asid.h> |
#include <arch/types.h> |
#include <typedefs.h> |
extern void tlb_init(void); |
#ifdef CONFIG_SMP |
extern void tlb_shootdown_start(void); |
extern void tlb_shootdown_finalize(void); |
extern void tlb_shootdown_ipi_recv(void); |
#else |
# define tlb_shootdown_start() ; |
# define tlb_shootdown_finalize() ; |
# define tlb_shootdown_ipi_recv() ; |
#endif /* CONFIG_SMP */ |
/** Type of TLB shootdown message. */ |
enum tlb_invalidate_type { |
TLB_INVL_INVALID = 0, /**< Invalid type. */ |
TLB_INVL_ALL, /**< Invalidate all entries in TLB. */ |
TLB_INVL_ASID, /**< Invalidate all entries belonging to one address space. */ |
TLB_INVL_PAGE /**< Invalidate one entry for specified page. */ |
TLB_INVL_PAGES /**< Invalidate specified page range belonging to one address space. */ |
}; |
typedef enum tlb_invalidate_type tlb_invalidate_type_t; |
63,14 → 52,25 |
typedef struct tlb_shootdown_msg tlb_shootdown_msg_t; |
extern void tlb_init(void); |
#ifdef CONFIG_SMP |
extern void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid, __address page, count_t cnt); |
extern void tlb_shootdown_finalize(void); |
extern void tlb_shootdown_ipi_recv(void); |
#else |
# define tlb_shootdown_start(w, x, y, z) |
# define tlb_shootdown_finalize() |
# define tlb_shootdown_ipi_recv() |
#endif /* CONFIG_SMP */ |
/* Export TLB interface that each architecture must implement. */ |
extern void tlb_arch_init(void); |
extern void tlb_print(void); |
extern void tlb_invalidate(asid_t asid); |
extern void tlb_shootdown_ipi_send(void); |
extern void tlb_invalidate_all(void); |
extern void tlb_invalidate_asid(asid_t asid); |
extern void tlb_invalidate_page(asid_t asid, __address page); |
extern void tlb_invalidate_pages(asid_t asid, __address page, count_t cnt); |
#endif |
/kernel/trunk/generic/include/mm/as.h |
---|
48,6 → 48,8 |
#define USTACK_ADDRESS USTACK_ADDRESS_ARCH |
#define UDATA_ADDRESS UDATA_ADDRESS_ARCH |
#define AS_KERNEL (1<<0) /**< Kernel address space. */ |
enum as_area_type { |
AS_AREA_TEXT = 1, AS_AREA_DATA, AS_AREA_STACK |
}; |
61,7 → 63,7 |
SPINLOCK_DECLARE(lock); |
link_t link; |
as_area_type_t type; |
size_t size; /**< Size of this area. */ |
size_t size; /**< Size of this area in multiples of PAGE_SIZE. */ |
__address base; /**< Base address of this area. */ |
index_t *mapping; /**< Map of physical frame numbers mapped to virtual page numbers in this area. */ |
}; |
74,6 → 76,9 |
* set up during system initialization. |
*/ |
struct as { |
/** Protected by asidlock. Must be acquired before as-> lock. */ |
link_t as_with_asid_link; |
SPINLOCK_DECLARE(lock); |
link_t as_area_head; |
pte_t *ptl0; |
80,20 → 85,13 |
asid_t asid; /**< Address space identifier. */ |
}; |
extern as_t * as_create(pte_t *ptl0); |
extern as_t * as_create(pte_t *ptl0, int flags); |
extern as_area_t *as_area_create(as_t *as, as_area_type_t type, size_t size, __address base); |
extern void as_area_set_mapping(as_area_t *a, index_t vpn, index_t pfn); |
extern int as_page_fault(__address page); |
extern void as_install(as_t *m); |
/* |
* Each architecture should implement this function. |
* Its main purpose is to do TLB purges according |
* to architecture's requirements. Note that |
* some architectures invalidate their TLB automatically |
* on hardware address space switch (e.g. ia32 and |
* amd64). |
*/ |
/* Interface to be implemented by architectures. */ |
#ifndef as_install_arch |
extern void as_install_arch(as_t *as); |
#endif /* !def as_install_arch */ |
/kernel/trunk/generic/src/main/kinit.c |
---|
146,7 → 146,7 |
if (KA2PA(config.init_addr) % FRAME_SIZE) |
panic("config.init_addr is not frame aligned"); |
as = as_create(NULL); |
as = as_create(NULL, 0); |
if (!as) |
panic("as_create\n"); |
u = task_create(as); |
/kernel/trunk/generic/src/main/main.c |
---|
185,7 → 185,7 |
/* |
* Create kernel address space. |
*/ |
as = as_create(GET_PTL0_ADDRESS()); |
as = as_create(GET_PTL0_ADDRESS(), AS_KERNEL); |
if (!as) |
panic("can't create kernel address space\n"); |
/kernel/trunk/generic/src/mm/tlb.c |
---|
46,14 → 46,32 |
#ifdef CONFIG_SMP |
/* must be called with interrupts disabled */ |
void tlb_shootdown_start(void) |
void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid, __address page, count_t cnt) |
{ |
int i; |
CPU->tlb_active = 0; |
spinlock_lock(&tlblock); |
/* |
* TODO: assemble shootdown message. |
*/ |
tlb_shootdown_ipi_send(); |
tlb_invalidate(0); /* TODO: use valid ASID */ |
switch (type) { |
case TLB_INVL_ALL: |
tlb_invalidate_all(); |
break; |
case TLB_INVL_ASID: |
tlb_invalidate_asid(asid); |
break; |
case TLB_INVL_PAGES: |
tlb_invalidate_pages(asid, page, cnt); |
break; |
default: |
panic("unknown tlb_invalidate_type_t value: %d\n", type); |
break; |
} |
busy_wait: |
for (i = 0; i<config.cpu_count; i++) |
77,7 → 95,7 |
CPU->tlb_active = 0; |
spinlock_lock(&tlblock); |
spinlock_unlock(&tlblock); |
tlb_invalidate(0); /* TODO: use valid ASID */ |
tlb_invalidate_all(); /* TODO: use valid ASID */ |
CPU->tlb_active = 1; |
} |
#endif /* CONFIG_SMP */ |
/kernel/trunk/generic/src/mm/as.c |
---|
33,6 → 33,7 |
*/ |
#include <mm/as.h> |
#include <mm/asid.h> |
#include <mm/page.h> |
#include <mm/frame.h> |
#include <mm/tlb.h> |
39,6 → 40,7 |
#include <mm/heap.h> |
#include <arch/mm/page.h> |
#include <genarch/mm/page_pt.h> |
#include <mm/asid.h> |
#include <arch/mm/asid.h> |
#include <arch/mm/as.h> |
#include <arch/types.h> |
70,16 → 72,20 |
* FIXME: this interface must be meaningful for all possible VAT |
* (Virtual Address Translation) mechanisms. |
*/ |
as_t *as_create(pte_t *ptl0) |
as_t *as_create(pte_t *ptl0, int flags) |
{ |
as_t *as; |
as = (as_t *) malloc(sizeof(as_t)); |
if (as) { |
list_initialize(&as->as_with_asid_link); |
spinlock_initialize(&as->lock, "as_lock"); |
list_initialize(&as->as_area_head); |
as->asid = asid_get(); |
if (flags & AS_KERNEL) |
as->asid = ASID_KERNEL; |
else |
as->asid = ASID_INVALID; |
as->ptl0 = ptl0; |
if (!as->ptl0) { |
289,6 → 295,8 |
{ |
ipl_t ipl; |
asid_install(as); |
ipl = interrupts_disable(); |
spinlock_lock(&as->lock); |
ASSERT(as->ptl0); |
298,7 → 306,7 |
/* |
* Perform architecture-specific steps. |
* (e.g. invalidate TLB, install ASID etc.) |
* (e.g. write ASID to hardware register etc.) |
*/ |
as_install_arch(as); |