Subversion Repositories HelenOS

Compare Revisions

Ignore whitespace Rev 2105 → Rev 2106

/trunk/kernel/generic/include/mm/mm.h
46,20 → 46,20
#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_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_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_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_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)
#define PAGE_GLOBAL (1 << PAGE_GLOBAL_SHIFT)
 
#endif
 
/trunk/kernel/generic/include/mm/page.h
58,7 → 58,7
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);
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/slab.h
56,13 → 56,19
#define SLAB_MAX_BADNESS(cache) ((PAGE_SIZE << (cache)->order) >> 2)
 
/* slab_reclaim constants */
#define SLAB_RECLAIM_ALL 0x1 /**< Reclaim all possible memory, because we are in memory stress */
 
/** Reclaim all possible memory, because we are in memory stress */
#define SLAB_RECLAIM_ALL 0x1
 
/* cache_create flags */
#define SLAB_CACHE_NOMAGAZINE 0x1 /**< Do not use per-cpu cache */
#define SLAB_CACHE_SLINSIDE 0x2 /**< Have control structure inside SLAB */
#define SLAB_CACHE_MAGDEFERRED (0x4 | SLAB_CACHE_NOMAGAZINE) /**< We add magazine cache later, if we have this flag */
 
/** Do not use per-cpu cache */
#define SLAB_CACHE_NOMAGAZINE 0x1
/** Have control structure inside SLAB */
#define SLAB_CACHE_SLINSIDE 0x2
/** We add magazine cache later, if we have this flag */
#define SLAB_CACHE_MAGDEFERRED (0x4 | SLAB_CACHE_NOMAGAZINE)
 
typedef struct {
link_t link;
count_t busy; /**< Count of full slots in magazine */
81,12 → 87,17
char *name;
 
link_t link;
 
/* Configuration */
size_t size; /**< Size of slab position - align_up(sizeof(obj)) */
/** Size of slab position - align_up(sizeof(obj)) */
size_t size;
 
int (*constructor)(void *obj, int kmflag);
int (*destructor)(void *obj);
int flags; /**< Flags changing behaviour of cache */
 
/** Flags changing behaviour of cache */
int flags;
 
/* Computed values */
uint8_t order; /**< Order of frames to be allocated */
int objects; /**< Number of objects that fit in */
95,7 → 106,8
atomic_t allocated_slabs;
atomic_t allocated_objs;
atomic_t cached_objs;
atomic_t magazine_counter; /**< How many magazines in magazines list */
/** How many magazines in magazines list */
atomic_t magazine_counter;
 
/* Slabs */
link_t full_slabs; /**< List of full slabs */
109,12 → 121,9
slab_mag_cache_t *mag_cache;
} slab_cache_t;
 
extern slab_cache_t * slab_cache_create(char *name,
size_t size,
size_t align,
int (*constructor)(void *obj, int kmflag),
int (*destructor)(void *obj),
int flags);
extern slab_cache_t * slab_cache_create(char *name, size_t size, size_t align,
int (*constructor)(void *obj, int kmflag), int (*destructor)(void *obj),
int flags);
extern void slab_cache_destroy(slab_cache_t *cache);
 
extern void * slab_alloc(slab_cache_t *cache, int flags);
121,7 → 130,7
extern void slab_free(slab_cache_t *cache, void *obj);
extern count_t slab_reclaim(int flags);
 
/** Initialize slab subsytem */
/* slab subsytem initialization */
extern void slab_cache_init(void);
extern void slab_enable_cpucache(void);
 
/trunk/kernel/generic/include/mm/tlb.h
39,17 → 39,21
#include <arch/types.h>
 
/**
* Number of TLB shootdown messages that can be queued in processor
* tlb_messages queue.
* Number of TLB shootdown messages that can be queued in processor tlb_messages
* queue.
*/
#define TLB_MESSAGE_QUEUE_LEN 10
 
/** Type of TLB shootdown message. */
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. */
/** Invalid type. */
TLB_INVL_INVALID = 0,
/** Invalidate all entries in TLB. */
TLB_INVL_ALL,
/** Invalidate all entries belonging to one address space. */
TLB_INVL_ASID,
/** Invalidate specified page range belonging to one address space. */
TLB_INVL_PAGES
} tlb_invalidate_type_t;
 
/** TLB shootdown message. */
63,13 → 67,14
extern void tlb_init(void);
 
#ifdef CONFIG_SMP
extern void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid, uintptr_t page, count_t count);
extern void tlb_shootdown_start(tlb_invalidate_type_t type, asid_t asid,
uintptr_t page, count_t count);
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()
#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. */
/trunk/kernel/generic/include/mm/as.h
53,7 → 53,10
#include <adt/btree.h>
#include <lib/elf.h>
 
/** Defined to be true if user address space and kernel address space shadow each other. */
/**
* Defined to be true if user address space and kernel address space shadow each
* other.
*/
#define KERNEL_ADDRESS_SPACE_SHADOWED KERNEL_ADDRESS_SPACE_SHADOWED_ARCH
 
#define KERNEL_ADDRESS_SPACE_START KERNEL_ADDRESS_SPACE_START_ARCH
61,18 → 64,57
#define USER_ADDRESS_SPACE_START USER_ADDRESS_SPACE_START_ARCH
#define USER_ADDRESS_SPACE_END USER_ADDRESS_SPACE_END_ARCH
 
#define USTACK_ADDRESS USTACK_ADDRESS_ARCH
#define USTACK_ADDRESS USTACK_ADDRESS_ARCH
 
#define FLAG_AS_KERNEL (1 << 0) /**< Kernel address space. */
/** Kernel address space. */
#define FLAG_AS_KERNEL (1 << 0)
 
/** Address space area attributes. */
/* 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(). */
/** The page fault was not resolved by as_page_fault(). */
#define AS_PF_FAULT 0
/** The page fault was resolved by as_page_fault(). */
#define AS_PF_OK 1
/** The page fault was caused by memcpy_from_uspace() or memcpy_to_uspace(). */
#define AS_PF_DEFER 2
 
/** 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.
*/
typedef struct as {
/** Protected by asidlock. */
link_t inactive_as_with_asid_link;
 
mutex_t lock;
 
/** 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;
/**
* Address space identifier.
* Constant on architectures that do not support ASIDs.
*/
asid_t asid;
/** Non-generic content. */
as_genarch_t genarch;
 
/** Architecture specific content. */
as_arch_t arch;
} as_t;
 
typedef struct {
pte_t *(* page_table_create)(int flags);
void (* page_table_destroy)(pte_t *page_table);
80,11 → 122,19
void (* page_table_unlock)(as_t *as, bool unlock);
} as_operations_t;
 
/** This structure contains information associated with the shared address space area. */
/**
* 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. */
count_t refcount; /**< This structure can be deallocated if refcount drops to 0. */
btree_t pagemap; /**< B+tree containing complete map of anonymous pages of the shared area. */
/** This lock must be acquired only when the as_area lock is held. */
mutex_t lock;
/** This structure can be deallocated if refcount drops to 0. */
count_t refcount;
/**
* B+tree containing complete map of anonymous pages of the shared area.
*/
btree_t pagemap;
} share_info_t;
 
/** Page fault access type. */
115,16 → 165,28
*/
typedef struct {
mutex_t lock;
as_t *as; /**< Containing address space. */
int flags; /**< Flags related to the memory represented by the address space area. */
int attributes; /**< Attributes related to the address space area itself. */
count_t pages; /**< Size of this area in multiples of PAGE_SIZE. */
uintptr_t base; /**< Base address of this area. */
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. */
struct mem_backend *backend; /**< Memory backend backing this address space area. */
/** Containing address space. */
as_t *as;
/** Flags related to the memory represented by the address space area. */
int flags;
/** Attributes related to the address space area itself. */
int attributes;
/** Size of this area in multiples of PAGE_SIZE. */
count_t pages;
/** Base address of this area. */
uintptr_t base;
/** Map of used space. */
btree_t used_space;
 
/**
* If the address space area has been shared, this pointer will reference
* the share info structure.
*/
share_info_t *sh_info;
 
/** Memory backend backing this address space area. */
struct mem_backend *backend;
 
/** Data to be used by the backend. */
mem_backend_data_t backend_data;
} as_area_t;
146,15 → 208,16
 
extern as_t *as_create(int flags);
extern void as_destroy(as_t *as);
extern void as_switch(as_t *old, as_t *replace);
extern void as_switch(as_t *old_as, as_t *new_as);
extern int as_page_fault(uintptr_t page, pf_access_t access, istate_t *istate);
 
extern as_area_t *as_area_create(as_t *as, int flags, size_t size, uintptr_t base, int attrs,
mem_backend_t *backend, mem_backend_data_t *backend_data);
extern as_area_t *as_area_create(as_t *as, int flags, size_t size,
uintptr_t base, int attrs, mem_backend_t *backend,
mem_backend_data_t *backend_data);
extern int as_area_destroy(as_t *as, uintptr_t address);
extern int as_area_resize(as_t *as, uintptr_t address, size_t size, int flags);
int as_area_share(as_t *src_as, uintptr_t src_base, size_t acc_size,
as_t *dst_as, uintptr_t dst_base, int dst_flags_mask);
as_t *dst_as, uintptr_t dst_base, int dst_flags_mask);
 
extern int as_area_get_flags(as_area_t *area);
extern bool as_area_check_access(as_area_t *area, pf_access_t access);
/trunk/kernel/generic/include/mm/buddy.h
44,11 → 44,15
 
/** Buddy system operations to be implemented by each implementation. */
typedef struct {
/** Return pointer to left-side or right-side buddy for block passed as
* argument. */
/**
* Return pointer to left-side or right-side buddy for block passed as
* argument.
*/
link_t *(* find_buddy)(struct buddy_system *, link_t *);
/** Bisect the block passed as argument and return pointer to the new
* right-side buddy. */
/**
* Bisect the block passed as argument and return pointer to the new
* right-side buddy.
*/
link_t *(* bisect)(struct buddy_system *, link_t *);
/** Coalesce two buddies into a bigger block. */
link_t *(* coalesce)(struct buddy_system *, link_t *, link_t *);
75,7 → 79,7
} buddy_system_t;
 
extern void buddy_system_create(buddy_system_t *b, uint8_t max_order,
buddy_system_operations_t *op, void *data);
buddy_system_operations_t *op, void *data);
extern link_t *buddy_system_alloc(buddy_system_t *b, uint8_t i);
extern bool buddy_system_can_alloc(buddy_system_t *b, uint8_t order);
extern void buddy_system_free(buddy_system_t *b, link_t *block);