Added freeing/unmapping of boot memory

This commit is contained in:
Bahadir Balban
2009-08-11 15:01:27 +03:00
parent f4d9520fef
commit f82db61519
4 changed files with 48 additions and 31 deletions

View File

@@ -98,6 +98,7 @@ struct ktcb *alloc_ktcb(void);
struct capability *alloc_capability(void); struct capability *alloc_capability(void);
struct container *alloc_container(void); struct container *alloc_container(void);
struct mutex_queue *alloc_user_mutex(void); struct mutex_queue *alloc_user_mutex(void);
int free_boot_memory(struct kernel_container *kcont);
int init_system_resources(struct kernel_container *kcont); int init_system_resources(struct kernel_container *kcont);

View File

@@ -249,9 +249,6 @@ int thread_setup_new_ids(struct task_ids *ids, unsigned int flags,
new->tgid = new->tid; new->tgid = new->tid;
} }
/* Set all ids */
//set_task_ids(new, ids);
return 0; return 0;
} }
@@ -354,7 +351,11 @@ out_err:
*/ */
int sys_thread_control(unsigned int flags, struct task_ids *ids) int sys_thread_control(unsigned int flags, struct task_ids *ids)
{ {
int ret = 0; int err, ret = 0;
if ((err = check_access((unsigned long)ids, sizeof(*ids),
MAP_USR_RW_FLAGS, 1)) < 0)
return err;
switch (flags & THREAD_ACTION_MASK) { switch (flags & THREAD_ACTION_MASK) {
case THREAD_CREATE: case THREAD_CREATE:

View File

@@ -161,6 +161,7 @@ int memcap_unmap_range(struct capability *cap,
return 0; return 0;
} }
/* /*
* Unmaps given memory range from the list of capabilities * Unmaps given memory range from the list of capabilities
* by either shrinking, splitting or destroying the * by either shrinking, splitting or destroying the
@@ -190,34 +191,56 @@ int memcap_unmap(struct cap_list *cap_list,
} }
/* /*
* Migrate any boot allocations to their relevant caches. * TODO: Evaluate if access bits are needed and add new cap ranges
* only if their access bits match.
*
* Maps a memory range as a capability to a list of capabilities either by
* merging the given range to an existing capability or creating a new one.
*/ */
void migrate_boot_resources(struct boot_resources *bootres, int memcap_map(struct cap_list *cap_list,
struct kernel_container *kcont) const unsigned long map_start,
const unsigned long map_end)
{ {
/* Migrate boot page tables to new caches */ struct capability *cap, *n;
// migrate_page_tables(kcont);
/* Migrate all boot-allocated capabilities */ list_foreach_removable_struct(cap, n, &cap_list->caps, list) {
// migrate_boot_caps(kcont); if (cap->start == map_end) {
cap->start = map_start;
return 0;
} else if(cap->end == map_start) {
cap->end = map_end;
return 0;
}
}
/* No capability could be extended, we create a new one */
cap = alloc_capability();
cap->start = map_start;
cap->end = map_end;
link_init(&cap->list);
cap_list_insert(cap, cap_list);
return 0;
} }
/* Delete all boot memory and add it to physical memory pool. */ /* Delete all boot memory and add it to physical memory pool. */
int free_boot_memory(struct boot_resources *bootres, int free_boot_memory(struct kernel_container *kcont)
struct kernel_container *kcont)
{ {
unsigned long pfn_start =
__pfn(virt_to_phys(_start_init));
unsigned long pfn_end =
__pfn(page_align_up(virt_to_phys(_end_init)));
/* Trim kernel used memory cap */ /* Trim kernel used memory cap */
memcap_unmap(&kcont->physmem_used, (unsigned long)_start_init, memcap_unmap(&kcont->physmem_used, pfn_start, pfn_end);
(unsigned long)_end_init);
/* Add it to unused physical memory */ /* Add it to unused physical memory */
// memcap_map(&kcont->physmem_free, (unsigned long)_start_init, memcap_map(&kcont->physmem_free, pfn_start, pfn_end);
// (unsigned long)_end_init);
/* Remove the init memory from the page tables */
for (unsigned long i = pfn_start; i < pfn_end; i++)
remove_mapping(phys_to_virt(__pfn_to_addr(i)));
/*
* Freed physical area will be unmapped from virtual
* by not mapping it in the task page tables.
*/
return 0; return 0;
} }
@@ -536,7 +559,7 @@ void init_resource_allocators(struct boot_resources *bootres,
kcont->pmd_cache = init_resource_cache(bootres->npmds, kcont->pmd_cache = init_resource_cache(bootres->npmds,
PMD_SIZE, kcont, 1); PMD_SIZE, kcont, 1);
} }
/* /*
* Do all system accounting for a given capability info * Do all system accounting for a given capability info

View File

@@ -369,11 +369,6 @@ void setup_dummy_current()
TASK_PGD(current) = &init_pgd; TASK_PGD(current) = &init_pgd;
} }
void free_bootmem(void)
{
/* TODO: Fill. */
}
void init_finalize(struct kernel_container *kcont) void init_finalize(struct kernel_container *kcont)
{ {
volatile register unsigned int stack asm("sp"); volatile register unsigned int stack asm("sp");
@@ -402,7 +397,7 @@ void init_finalize(struct kernel_container *kcont)
* Unmap boot memory, and add it as * Unmap boot memory, and add it as
* an unused kernel memcap * an unused kernel memcap
*/ */
free_bootmem(); free_boot_memory(&kernel_container);
/* /*
* Set up KIP UTCB ref * Set up KIP UTCB ref
@@ -444,9 +439,6 @@ void start_kernel(void)
remap_as_pages((void *)page_align(_start_kernel), remap_as_pages((void *)page_align(_start_kernel),
(void *)page_align_up(_end_kernel)); (void *)page_align_up(_end_kernel));
/* Move the initial pgd into a more convenient place, mapped as pages. */
// relocate_page_tables();
/* Initialise kip and map for userspace access */ /* Initialise kip and map for userspace access */
kip_init(); kip_init();