Subversion Repositories HelenOS-historic

Compare Revisions

Ignore whitespace Rev 755 → Rev 756

/kernel/trunk/genarch/src/mm/as_ht.c
0,0 → 1,60
/*
* Copyright (C) 2006 Jakub Jermar
* 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.
*/
 
#include <genarch/mm/as_ht.h>
#include <genarch/mm/page_ht.h>
#include <mm/as.h>
#include <mm/frame.h>
#include <arch/types.h>
#include <typedefs.h>
#include <memstr.h>
 
static pte_t *ht_create(int flags);
 
as_operations_t as_ht_operations = {
.page_table_create = ht_create
};
 
 
/** Page hash table create.
*
* The page hash table will be created only once
* and will be shared by all address spaces.
*
* @param flags Ignored.
*
* @return Address of global page hash table.
*/
pte_t *ht_create(int flags)
{
if (!page_ht) {
page_ht = (pte_t *) frame_alloc(FRAME_KA | FRAME_PANIC, HT_WIDTH - FRAME_WIDTH, NULL);
memsetb((__address) page_ht, HT_SIZE, 0);
}
return page_ht;
}
/kernel/trunk/genarch/src/mm/page_pt.c
29,6 → 29,7
#include <genarch/mm/page_pt.h>
#include <mm/page.h>
#include <mm/frame.h>
#include <mm/as.h>
#include <arch/mm/page.h>
#include <arch/mm/as.h>
#include <arch/types.h>
36,8 → 37,8
#include <arch/asm.h>
#include <memstr.h>
 
static void pt_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root);
static pte_t *pt_mapping_find(as_t *as, __address page, __address root);
static void pt_mapping_insert(as_t *as, __address page, __address frame, int flags);
static pte_t *pt_mapping_find(as_t *as, __address page);
 
page_operations_t page_pt_operations = {
.mapping_insert = pt_mapping_insert,
49,18 → 50,19
* Map virtual address 'page' to physical address 'frame'
* using 'flags'.
*
* @param as Ignored.
* The address space must be locked and interrupts must be disabled.
*
* @param as Address space to wich page belongs.
* @param page Virtual address of the page to be mapped.
* @param frame Physical address of memory frame to which the mapping is done.
* @param flags Flags to be used for mapping.
* @param root Explicit PTL0 address.
*/
void pt_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root)
void pt_mapping_insert(as_t *as, __address page, __address frame, int flags)
{
pte_t *ptl0, *ptl1, *ptl2, *ptl3;
__address newpt;
 
ptl0 = (pte_t *) PA2KA(root ? root : (__address) GET_PTL0_ADDRESS());
ptl0 = (pte_t *) PA2KA((__address) as->page_table);
 
if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT) {
newpt = frame_alloc(FRAME_KA, ONE_FRAME, NULL);
97,17 → 99,18
*
* Find mapping for virtual page.
*
* @param as Ignored.
* The address space must be locked and interrupts must be disabled.
*
* @param as Address space to which page belongs.
* @param page Virtual page.
* @param root PTL0 address if non-zero.
*
* @return NULL if there is no such mapping; entry from PTL3 describing the mapping otherwise.
*/
pte_t *pt_mapping_find(as_t *as, __address page, __address root)
pte_t *pt_mapping_find(as_t *as, __address page)
{
pte_t *ptl0, *ptl1, *ptl2, *ptl3;
 
ptl0 = (pte_t *) PA2KA(root ? root : (__address) GET_PTL0_ADDRESS());
ptl0 = (pte_t *) PA2KA((__address) as->page_table);
 
if (GET_PTL1_FLAGS(ptl0, PTL0_INDEX(page)) & PAGE_NOT_PRESENT)
return NULL;
/kernel/trunk/genarch/src/mm/as_pt.c
0,0 → 1,78
/*
* Copyright (C) 2006 Jakub Jermar
* 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.
*/
 
#include <genarch/mm/page_pt.h>
#include <mm/page.h>
#include <mm/frame.h>
#include <mm/as.h>
#include <arch/mm/page.h>
#include <arch/mm/as.h>
#include <arch/types.h>
#include <typedefs.h>
#include <memstr.h>
#include <arch.h>
 
static pte_t *ptl0_create(int flags);
 
as_operations_t as_pt_operations = {
.page_table_create = ptl0_create
};
 
/** Create PTL0.
*
* PTL0 of 4-level page table will be created for each address space.
*
* @param flags Flags can specify whether ptl0 is for the kernel address space.
*
* @return New PTL0.
*/
pte_t *ptl0_create(int flags)
{
pte_t *src_ptl0, *dst_ptl0;
ipl_t ipl;
 
dst_ptl0 = (pte_t *) frame_alloc(FRAME_KA | FRAME_PANIC, ONE_FRAME, NULL);
 
if (flags & FLAG_AS_KERNEL) {
memsetb((__address) dst_ptl0, PAGE_SIZE, 0);
} else {
/*
* Copy the kernel address space portion to new PTL0.
* TODO: copy only kernel address space.
*/
ipl = interrupts_disable();
spinlock_lock(&AS_KERNEL->lock);
src_ptl0 = (pte_t *) PA2KA((__address) AS_KERNEL->page_table);
memcpy((void *) dst_ptl0,(void *) src_ptl0, PAGE_SIZE);
spinlock_unlock(&AS_KERNEL->lock);
interrupts_restore(ipl);
}
 
return (pte_t *) KA2PA((__address) dst_ptl0);
}
/kernel/trunk/genarch/src/mm/page_ht.c
38,12 → 38,10
#include <synch/spinlock.h>
#include <arch.h>
#include <debug.h>
#include <memstr.h>
 
/**
* This lock protects the page hash table. Note that software must
* be still careful about ordering of writes to ensure consistent
* view of the page hash table for hardware helpers such as VHPT
* walker on ia64.
* This lock protects the page hash table.
*/
SPINLOCK_INITIALIZE(page_ht_lock);
 
53,28 → 51,27
*/
pte_t *page_ht = NULL;
 
static void ht_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root);
static pte_t *ht_mapping_find(as_t *as, __address page, __address root);
static void ht_mapping_insert(as_t *as, __address page, __address frame, int flags);
static pte_t *ht_mapping_find(as_t *as, __address page);
 
page_operations_t page_ht_operations = {
.mapping_insert = ht_mapping_insert,
.mapping_find = ht_mapping_find
.mapping_find = ht_mapping_find,
};
 
/** Map page to frame using page hash table.
*
* Map virtual address 'page' to physical address 'frame'
* using 'flags'. In order not to disturb hardware searching,
* new mappings are appended to the end of the collision
* chain.
* using 'flags'.
*
* @param as Address space to which page belongs. Must be locked prior the call.
* The address space must be locked and interruptsmust be disabled.
*
* @param as Address space to which page belongs.
* @param page Virtual address of the page to be mapped.
* @param frame Physical address of memory frame to which the mapping is done.
* @param flags Flags to be used for mapping.
* @param root Ignored.
*/
void ht_mapping_insert(as_t *as, __address page, __address frame, int flags, __address root)
void ht_mapping_insert(as_t *as, __address page, __address frame, int flags)
{
pte_t *t, *u;
ipl_t ipl;
121,15 → 118,14
*
* Find mapping for virtual page.
*
* Interrupts must be disabled.
* The address space must be locked and interrupts must be disabled.
*
* @param as Address space to wich page belongs. Must be locked prior the call.
* @param as Address space to wich page belongs.
* @param page Virtual page.
* @param root Ignored.
*
* @return NULL if there is no such mapping; requested mapping otherwise.
*/
pte_t *ht_mapping_find(as_t *as, __address page, __address root)
pte_t *ht_mapping_find(as_t *as, __address page)
{
pte_t *t;