/trunk/kernel/generic/include/mm/mm.h |
---|
0,0 → 1,67 |
/* |
* Copyright (c) 2007 Martin Decky |
* All rights reserved. |
* |
* Redistribution and use in source and binary forms, with or without |
* modification, are permitted provided that the following conditions |
* are met: |
* |
* - Redistributions of source code must retain the above copyright |
* notice, this list of conditions and the following disclaimer. |
* - Redistributions in binary form must reproduce the above copyright |
* notice, this list of conditions and the following disclaimer in the |
* documentation and/or other materials provided with the distribution. |
* - The name of the author may not be used to endorse or promote products |
* derived from this software without specific prior written permission. |
* |
* THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR |
* IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES |
* OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. |
* IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, |
* INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT |
* NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
* DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
* THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
* THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
*/ |
/** @addtogroup genericmm |
* @{ |
*/ |
/** @file |
*/ |
#ifndef KERN_MM_H_ |
#define KERN_MM_H_ |
#define PAGE_CACHEABLE_SHIFT 0 |
#define PAGE_NOT_CACHEABLE_SHIFT PAGE_CACHEABLE_SHIFT |
#define PAGE_PRESENT_SHIFT 1 |
#define PAGE_NOT_PRESENT_SHIFT PAGE_PRESENT_SHIFT |
#define PAGE_USER_SHIFT 2 |
#define PAGE_KERNEL_SHIFT PAGE_USER_SHIFT |
#define PAGE_READ_SHIFT 3 |
#define PAGE_WRITE_SHIFT 4 |
#define PAGE_EXEC_SHIFT 5 |
#define PAGE_GLOBAL_SHIFT 6 |
#define PAGE_NOT_CACHEABLE (0 << PAGE_CACHEABLE_SHIFT) |
#define PAGE_CACHEABLE (1 << PAGE_CACHEABLE_SHIFT) |
#define PAGE_PRESENT (0 << PAGE_PRESENT_SHIFT) |
#define PAGE_NOT_PRESENT (1 << PAGE_PRESENT_SHIFT) |
#define PAGE_USER (1 << PAGE_USER_SHIFT) |
#define PAGE_KERNEL (0 << PAGE_USER_SHIFT) |
#define PAGE_READ (1 << PAGE_READ_SHIFT) |
#define PAGE_WRITE (1 << PAGE_WRITE_SHIFT) |
#define PAGE_EXEC (1 << PAGE_EXEC_SHIFT) |
#define PAGE_GLOBAL (1 << PAGE_GLOBAL_SHIFT) |
#endif |
/** @} |
*/ |
/trunk/kernel/generic/include/mm/frame.h |
---|
37,7 → 37,6 |
#define KERN_FRAME_H_ |
#include <arch/types.h> |
#include <typedefs.h> |
#include <adt/list.h> |
#include <synch/spinlock.h> |
#include <mm/buddy.h> |
/trunk/kernel/generic/include/mm/page.h |
---|
35,59 → 35,22 |
#ifndef KERN_PAGE_H_ |
#define KERN_PAGE_H_ |
#include <arch/mm/asid.h> |
#include <arch/types.h> |
#include <typedefs.h> |
#include <mm/as.h> |
#include <memstr.h> |
#define PAGE_CACHEABLE_SHIFT 0 |
#define PAGE_NOT_CACHEABLE_SHIFT PAGE_CACHEABLE_SHIFT |
#define PAGE_PRESENT_SHIFT 1 |
#define PAGE_NOT_PRESENT_SHIFT PAGE_PRESENT_SHIFT |
#define PAGE_USER_SHIFT 2 |
#define PAGE_KERNEL_SHIFT PAGE_USER_SHIFT |
#define PAGE_READ_SHIFT 3 |
#define PAGE_WRITE_SHIFT 4 |
#define PAGE_EXEC_SHIFT 5 |
#define PAGE_GLOBAL_SHIFT 6 |
#define PAGE_NOT_CACHEABLE (0<<PAGE_CACHEABLE_SHIFT) |
#define PAGE_CACHEABLE (1<<PAGE_CACHEABLE_SHIFT) |
#define PAGE_PRESENT (0<<PAGE_PRESENT_SHIFT) |
#define PAGE_NOT_PRESENT (1<<PAGE_PRESENT_SHIFT) |
#define PAGE_USER (1<<PAGE_USER_SHIFT) |
#define PAGE_KERNEL (0<<PAGE_USER_SHIFT) |
#define PAGE_READ (1<<PAGE_READ_SHIFT) |
#define PAGE_WRITE (1<<PAGE_WRITE_SHIFT) |
#define PAGE_EXEC (1<<PAGE_EXEC_SHIFT) |
#define PAGE_GLOBAL (1<<PAGE_GLOBAL_SHIFT) |
/** |
* Macro for computing page color. |
*/ |
#define PAGE_COLOR(va) (((va) >> PAGE_WIDTH) & ((1 << PAGE_COLOR_BITS) - 1)) |
/** Page fault access type. */ |
enum pf_access { |
PF_ACCESS_READ, |
PF_ACCESS_WRITE, |
PF_ACCESS_EXEC |
}; |
typedef enum pf_access pf_access_t; |
/** Operations to manipulate page mappings. */ |
struct page_mapping_operations { |
void (* mapping_insert)(as_t *as, uintptr_t page, uintptr_t frame, int |
flags); |
typedef struct { |
void (* mapping_insert)(as_t *as, uintptr_t page, uintptr_t frame, |
int flags); |
void (* mapping_remove)(as_t *as, uintptr_t page); |
pte_t *(* mapping_find)(as_t *as, uintptr_t page); |
}; |
typedef struct page_mapping_operations page_mapping_operations_t; |
} page_mapping_operations_t; |
extern page_mapping_operations_t *page_mapping_operations; |
94,8 → 57,8 |
extern void page_init(void); |
extern void page_table_lock(as_t *as, bool lock); |
extern void page_table_unlock(as_t *as, bool unlock); |
extern void page_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, int |
flags); |
extern void page_mapping_insert(as_t *as, uintptr_t page, uintptr_t frame, |
int flags); |
extern void page_mapping_remove(as_t *as, uintptr_t page); |
extern pte_t *page_mapping_find(as_t *as, uintptr_t page); |
extern pte_t *page_table_create(int flags); |
/trunk/kernel/generic/include/mm/asid.h |
---|
44,7 → 44,8 |
#include <arch/mm/asid.h> |
#include <synch/spinlock.h> |
#include <typedefs.h> |
#include <adt/list.h> |
#include <mm/as.h> |
#endif |
/trunk/kernel/generic/include/mm/tlb.h |
---|
37,7 → 37,6 |
#include <arch/mm/asid.h> |
#include <arch/types.h> |
#include <typedefs.h> |
/** |
* Number of TLB shootdown messages that can be queued in processor |
46,22 → 45,20 |
#define TLB_MESSAGE_QUEUE_LEN 10 |
/** Type of TLB shootdown message. */ |
enum tlb_invalidate_type { |
typedef enum { |
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_PAGES /**< Invalidate specified page range belonging to one address space. */ |
}; |
typedef enum tlb_invalidate_type tlb_invalidate_type_t; |
} tlb_invalidate_type_t; |
/** TLB shootdown message. */ |
struct tlb_shootdown_msg { |
typedef struct { |
tlb_invalidate_type_t type; /**< Message type. */ |
asid_t asid; /**< Address space identifier. */ |
uintptr_t page; /**< Page address. */ |
count_t count; /**< Number of pages to invalidate. */ |
}; |
typedef struct tlb_shootdown_msg tlb_shootdown_msg_t; |
} tlb_shootdown_msg_t; |
extern void tlb_init(void); |
/trunk/kernel/generic/include/mm/as.h |
---|
47,7 → 47,6 |
#include <arch/mm/as.h> |
#include <arch/mm/asid.h> |
#include <arch/types.h> |
#include <typedefs.h> |
#include <synch/spinlock.h> |
#include <synch/mutex.h> |
#include <adt/list.h> |
66,55 → 65,21 |
#define FLAG_AS_KERNEL (1 << 0) /**< Kernel address space. */ |
/** Address space structure. |
* |
* as_t contains the list of as_areas of userspace accessible |
* pages for one or more tasks. Ranges of kernel memory pages are not |
* supposed to figure in the list as they are shared by all tasks and |
* set up during system initialization. |
*/ |
struct as { |
/** Protected by asidlock. */ |
link_t inactive_as_with_asid_link; |
/** Address space area attributes. */ |
#define AS_AREA_ATTR_NONE 0 |
#define AS_AREA_ATTR_PARTIAL 1 /**< Not fully initialized area. */ |
mutex_t lock; |
#define AS_PF_FAULT 0 /**< The page fault was not resolved by as_page_fault(). */ |
#define AS_PF_OK 1 /**< The page fault was resolved by as_page_fault(). */ |
#define AS_PF_DEFER 2 /**< The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */ |
/** Number of references (i.e tasks that reference this as). */ |
count_t refcount; |
/** Number of processors on wich is this address space active. */ |
count_t cpu_refcount; |
/** B+tree of address space areas. */ |
btree_t as_area_btree; |
/** Page table pointer. Constant on architectures that use global page hash table. */ |
pte_t *page_table; |
/** Address space identifier. Constant on architectures that do not support ASIDs.*/ |
asid_t asid; |
/** Architecture specific content. */ |
as_arch_t arch; |
}; |
struct as_operations { |
typedef struct { |
pte_t *(* page_table_create)(int flags); |
void (* page_table_destroy)(pte_t *page_table); |
void (* page_table_lock)(as_t *as, bool lock); |
void (* page_table_unlock)(as_t *as, bool unlock); |
}; |
typedef struct as_operations as_operations_t; |
} as_operations_t; |
/** Address space area attributes. */ |
#define AS_AREA_ATTR_NONE 0 |
#define AS_AREA_ATTR_PARTIAL 1 /**< Not fully initialized area. */ |
#define AS_PF_FAULT 0 /**< The page fault was not resolved by as_page_fault(). */ |
#define AS_PF_OK 1 /**< The page fault was resolved by as_page_fault(). */ |
#define AS_PF_DEFER 2 /**< The page fault was caused by memcpy_from_uspace() |
or memcpy_to_uspace(). */ |
/** This structure contains information associated with the shared address space area. */ |
typedef struct { |
mutex_t lock; /**< This lock must be acquired only when the as_area lock is held. */ |
122,15 → 87,17 |
btree_t pagemap; /**< B+tree containing complete map of anonymous pages of the shared area. */ |
} share_info_t; |
/** Address space area backend structure. */ |
typedef struct { |
int (* page_fault)(as_area_t *area, uintptr_t addr, pf_access_t access); |
void (* frame_free)(as_area_t *area, uintptr_t page, uintptr_t frame); |
void (* share)(as_area_t *area); |
} mem_backend_t; |
/** Page fault access type. */ |
typedef enum { |
PF_ACCESS_READ, |
PF_ACCESS_WRITE, |
PF_ACCESS_EXEC |
} pf_access_t; |
struct mem_backend; |
/** Backend data stored in address space area. */ |
typedef union { |
typedef union mem_backend_data { |
struct { /**< elf_backend members */ |
elf_header_t *elf; |
elf_segment_header_t *segment; |
146,7 → 113,7 |
* Each as_area_t structure describes one contiguous area of virtual memory. |
* In the future, it should not be difficult to support shared areas. |
*/ |
struct as_area { |
typedef struct { |
mutex_t lock; |
as_t *as; /**< Containing address space. */ |
int flags; /**< Flags related to the memory represented by the address space area. */ |
156,12 → 123,19 |
btree_t used_space; /**< Map of used space. */ |
share_info_t *sh_info; /**< If the address space area has been shared, this pointer will |
reference the share info structure. */ |
mem_backend_t *backend; /**< Memory backend backing this address space area. */ |
struct mem_backend *backend; /**< Memory backend backing this address space area. */ |
/** Data to be used by the backend. */ |
mem_backend_data_t backend_data; |
}; |
} as_area_t; |
/** Address space area backend structure. */ |
typedef struct mem_backend { |
int (* page_fault)(as_area_t *area, uintptr_t addr, pf_access_t access); |
void (* frame_free)(as_area_t *area, uintptr_t page, uintptr_t frame); |
void (* share)(as_area_t *area); |
} mem_backend_t; |
extern as_t *AS_KERNEL; |
extern as_operations_t *as_operations; |
206,11 → 180,13 |
extern void as_deinstall_arch(as_t *as); |
#endif /* !def as_deinstall_arch */ |
/* Backend declarations. */ |
/* Backend declarations and functions. */ |
extern mem_backend_t anon_backend; |
extern mem_backend_t elf_backend; |
extern mem_backend_t phys_backend; |
extern int elf_load(elf_header_t *header, as_t *as); |
/* Address space area related syscalls. */ |
extern unative_t sys_as_area_create(uintptr_t address, size_t size, int flags); |
extern unative_t sys_as_area_resize(uintptr_t address, size_t size, int flags); |
/trunk/kernel/generic/include/mm/buddy.h |
---|
36,7 → 36,7 |
#define KERN_BUDDY_H_ |
#include <arch/types.h> |
#include <typedefs.h> |
#include <adt/list.h> |
#define BUDDY_SYSTEM_INNER_BLOCK 0xff |