2008-08-13 23:13:40 +04:00
|
|
|
|
2009-04-23 16:26:47 +04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
link_t link;
|
|
|
|
addr_t base;
|
|
|
|
size_t size;
|
|
|
|
addr_t pte[0];
|
|
|
|
|
|
|
|
}mmap_t;
|
|
|
|
|
|
|
|
|
2008-08-13 23:13:40 +04:00
|
|
|
typedef struct
|
|
|
|
{
|
|
|
|
link_t buddy_link; /**< link to the next free block inside one order */
|
2009-04-23 16:26:47 +04:00
|
|
|
u16_t refcount; /**< tracking of shared frames */
|
|
|
|
u16_t buddy_order; /**< buddy system block order */
|
2008-08-13 23:13:40 +04:00
|
|
|
void *parent; /**< If allocated by slab, this points there */
|
|
|
|
} frame_t;
|
|
|
|
|
2009-04-23 16:26:47 +04:00
|
|
|
typedef struct
|
|
|
|
{
|
2008-08-13 23:13:40 +04:00
|
|
|
SPINLOCK_DECLARE(lock); /**< this lock protects everything below */
|
|
|
|
pfn_t base; /**< frame_no of the first frame in the frames array */
|
|
|
|
count_t count; /**< Size of zone */
|
|
|
|
|
|
|
|
frame_t *frames; /**< array of frame_t structures in this zone */
|
|
|
|
count_t free_count; /**< number of free frame_t structures */
|
|
|
|
count_t busy_count; /**< number of busy frame_t structures */
|
|
|
|
|
|
|
|
u32_t max_order;
|
|
|
|
link_t order[21];
|
|
|
|
|
|
|
|
int flags;
|
|
|
|
} zone_t;
|
|
|
|
|
2008-10-30 09:30:13 +03:00
|
|
|
|
2008-09-10 17:04:24 +04:00
|
|
|
typedef struct
|
|
|
|
{
|
2008-10-30 09:30:13 +03:00
|
|
|
link_t link;
|
|
|
|
link_t adj;
|
|
|
|
addr_t base;
|
|
|
|
size_t size;
|
|
|
|
void *parent;
|
|
|
|
u32_t state;
|
|
|
|
}md_t;
|
2008-08-13 23:13:40 +04:00
|
|
|
|
2008-09-10 17:04:24 +04:00
|
|
|
|
2008-09-15 19:25:03 +04:00
|
|
|
#define PG_MAP 1
|
2008-10-30 09:30:13 +03:00
|
|
|
#define PG_WRITE 2
|
|
|
|
#define PG_USER 4
|
|
|
|
|
|
|
|
#define PG_SW 3
|
|
|
|
#define PG_UW 7
|
|
|
|
|
2008-09-15 19:25:03 +04:00
|
|
|
|
2008-08-13 23:13:40 +04:00
|
|
|
|
|
|
|
#define PAGE_SIZE 4096
|
2009-04-23 16:26:47 +04:00
|
|
|
#define PAGE_WIDTH 12
|
2008-08-13 23:13:40 +04:00
|
|
|
|
2008-09-15 19:25:03 +04:00
|
|
|
|
|
|
|
# define PA2KA(x) (((addr_t) (x)) + OS_BASE)
|
|
|
|
# define KA2PA(x) (((addr_t) (x)) - OS_BASE)
|
|
|
|
|
2008-08-13 23:13:40 +04:00
|
|
|
static inline count_t SIZE2FRAMES(size_t size)
|
|
|
|
{
|
|
|
|
if (!size)
|
|
|
|
return 0;
|
2009-04-23 16:26:47 +04:00
|
|
|
return (count_t) ((size - 1) >> PAGE_WIDTH) + 1;
|
2008-08-13 23:13:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline addr_t PFN2ADDR(pfn_t frame)
|
|
|
|
{
|
2009-04-23 16:26:47 +04:00
|
|
|
return (addr_t) (frame << PAGE_WIDTH);
|
2008-08-13 23:13:40 +04:00
|
|
|
}
|
|
|
|
|
|
|
|
static inline pfn_t ADDR2PFN(addr_t addr)
|
|
|
|
{
|
2009-04-23 16:26:47 +04:00
|
|
|
return (pfn_t) (addr >> PAGE_WIDTH);
|
2008-08-13 23:13:40 +04:00
|
|
|
};
|
|
|
|
|
|
|
|
void init_mm();
|
2009-04-23 16:26:47 +04:00
|
|
|
void init_pg_slab();
|
2008-08-13 23:13:40 +04:00
|
|
|
|
2008-10-30 09:30:13 +03:00
|
|
|
void* __fastcall frame_get_parent(pfn_t pfn);
|
|
|
|
void __fastcall frame_set_parent(pfn_t pfn, void *data);
|
|
|
|
|
|
|
|
|
2008-09-10 17:04:24 +04:00
|
|
|
addr_t __fastcall core_alloc(u32_t order);
|
2008-10-30 09:30:13 +03:00
|
|
|
void __fastcall core_free(addr_t frame);
|
2008-08-13 23:13:40 +04:00
|
|
|
|
|
|
|
|
2009-04-23 16:26:47 +04:00
|
|
|
addr_t alloc_page(void);
|
2008-10-30 22:23:42 +03:00
|
|
|
|
|
|
|
|
|
|
|
md_t* __fastcall md_alloc(size_t size, u32_t flags) ;
|
2008-11-01 04:25:51 +03:00
|
|
|
void __fastcall md_free(md_t *md);
|
2008-10-30 22:23:42 +03:00
|
|
|
|
2009-04-23 16:26:47 +04:00
|
|
|
addr_t __fastcall __export mem_alloc(size_t size, u32_t flags) asm ("MemAlloc");
|
|
|
|
void __fastcall __export mem_free(addr_t mem) asm ("MemFree");
|
|
|
|
|
|
|
|
addr_t __fastcall frame_alloc(size_t size);
|
|
|
|
size_t __fastcall frame_free(addr_t addr);
|
2008-09-15 19:25:03 +04:00
|
|
|
|