X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/d7e50217d7adf6e52786a38bcaa4cd698cb9a79e..d1ecb069dfe24481e4a83f44cb5217a2b06746d7:/osfmk/i386/phys.c?ds=sidebyside diff --git a/osfmk/i386/phys.c b/osfmk/i386/phys.c index 62ccfe5da..c8a2f5206 100644 --- a/osfmk/i386/phys.c +++ b/osfmk/i386/phys.c @@ -1,16 +1,19 @@ /* - * Copyright (c) 2000 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. * - * @APPLE_LICENSE_HEADER_START@ - * - * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved. + * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * * This file contains Original Code and/or Modifications of Original Code * as defined in and that are subject to the Apple Public Source License * Version 2.0 (the 'License'). You may not use this file except in - * compliance with the License. Please obtain a copy of the License at - * http://www.opensource.apple.com/apsl/ and read it before using this - * file. + * compliance with the License. The rights granted to you under the License + * may not be used to create, or enable the creation or redistribution of, + * unlawful or unlicensed copies of an Apple operating system, or to + * circumvent, violate, or enable the circumvention or violation of, any + * terms of an Apple operating system software license agreement. + * + * Please obtain a copy of the License at + * http://www.opensource.apple.com/apsl/ and read it before using this file. * * The Original Code and all software distributed under the License are * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER @@ -20,7 +23,7 @@ * Please see the License for the specific language governing rights and * limitations under the License. * - * @APPLE_LICENSE_HEADER_END@ + * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* * @OSF_COPYRIGHT@ @@ -50,23 +53,51 @@ * any improvements or extensions that they make and grant Carnegie Mellon * the rights to redistribute these changes. */ -#include +#include +#include +#include + +#include + +#include +#include #include -#include -#include -#include + +#include +#include +#include +#include +#include #include +#include +#include +#include +#include +#include +#include + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include /* * pmap_zero_page zeros the specified (machine independent) page. */ void pmap_zero_page( - vm_offset_t p) + ppnum_t pn) { - assert(p != vm_page_fictitious_addr); - bzero((char *)phystokv(p), PAGE_SIZE); + assert(pn != vm_page_fictitious_addr); + assert(pn != vm_page_guard_addr); + bzero_phys((addr64_t)i386_ptob(pn), PAGE_SIZE); } /* @@ -75,28 +106,14 @@ pmap_zero_page( */ void pmap_zero_part_page( - vm_offset_t p, + ppnum_t pn, vm_offset_t offset, vm_size_t len) { - assert(p != vm_page_fictitious_addr); + assert(pn != vm_page_fictitious_addr); + assert(pn != vm_page_guard_addr); assert(offset + len <= PAGE_SIZE); - - bzero((char *)phystokv(p) + offset, len); -} - -/* - * pmap_copy_page copies the specified (machine independent) pages. - */ -void -pmap_copy_page( - vm_offset_t src, - vm_offset_t dst) -{ - assert(src != vm_page_fictitious_addr); - assert(dst != vm_page_fictitious_addr); - - memcpy((void *)phystokv(dst), (void *)phystokv(src), PAGE_SIZE); + bzero_phys((addr64_t)(i386_ptob(pn) + offset), (uint32_t)len); } /* @@ -104,19 +121,28 @@ pmap_copy_page( */ void pmap_copy_part_page( - vm_offset_t src, + ppnum_t psrc, vm_offset_t src_offset, - vm_offset_t dst, + ppnum_t pdst, vm_offset_t dst_offset, vm_size_t len) { - assert(src != vm_page_fictitious_addr); - assert(dst != vm_page_fictitious_addr); - assert(((dst & PAGE_MASK) + dst_offset + len) <= PAGE_SIZE); - assert(((src & PAGE_MASK) + src_offset + len) <= PAGE_SIZE); + pmap_paddr_t src, dst; + + assert(psrc != vm_page_fictitious_addr); + assert(pdst != vm_page_fictitious_addr); + assert(psrc != vm_page_guard_addr); + assert(pdst != vm_page_guard_addr); + + src = i386_ptob(psrc); + dst = i386_ptob(pdst); + + assert((((uintptr_t)dst & PAGE_MASK) + dst_offset + len) <= PAGE_SIZE); + assert((((uintptr_t)src & PAGE_MASK) + src_offset + len) <= PAGE_SIZE); - memcpy((void *)(phystokv(dst) + dst_offset), - (void *)(phystokv(src) + src_offset), len); + bcopy_phys((addr64_t)src + (src_offset & INTEL_OFFMASK), + (addr64_t)dst + (dst_offset & INTEL_OFFMASK), + len); } /* @@ -125,16 +151,31 @@ pmap_copy_part_page( */ void pmap_copy_part_lpage( - vm_offset_t src, - vm_offset_t dst, - vm_offset_t dst_offset, - vm_size_t len) + __unused vm_offset_t src, + __unused ppnum_t pdst, + __unused vm_offset_t dst_offset, + __unused vm_size_t len) { - assert(src != vm_page_fictitious_addr); - assert(dst != vm_page_fictitious_addr); - assert(((dst & PAGE_MASK) + dst_offset + len) <= PAGE_SIZE); +#ifdef __i386__ + mapwindow_t *map; +#endif + + assert(pdst != vm_page_fictitious_addr); + assert(pdst != vm_page_guard_addr); + assert((dst_offset + len) <= PAGE_SIZE); + +#ifdef __i386__ + mp_disable_preemption(); + + map = pmap_get_mapwindow(INTEL_PTE_VALID | INTEL_PTE_RW | (i386_ptob(pdst) & PG_FRAME) | + INTEL_PTE_REF | INTEL_PTE_MOD); - memcpy((void *)(phystokv(dst) + dst_offset), (void *)src, len); + memcpy((void *) (map->prv_CADDR + (dst_offset & INTEL_OFFMASK)), (void *) src, len); + + pmap_put_mapwindow(map); + + mp_enable_preemption(); +#endif } /* @@ -143,16 +184,31 @@ pmap_copy_part_lpage( */ void pmap_copy_part_rpage( - vm_offset_t src, - vm_offset_t src_offset, - vm_offset_t dst, - vm_size_t len) + __unused ppnum_t psrc, + __unused vm_offset_t src_offset, + __unused vm_offset_t dst, + __unused vm_size_t len) { - assert(src != vm_page_fictitious_addr); - assert(dst != vm_page_fictitious_addr); - assert(((src & PAGE_MASK) + src_offset + len) <= PAGE_SIZE); +#ifdef __i386__ + mapwindow_t *map; +#endif + + assert(psrc != vm_page_fictitious_addr); + assert(psrc != vm_page_guard_addr); + assert((src_offset + len) <= PAGE_SIZE); - memcpy((void *)dst, (void *)(phystokv(src) + src_offset), len); +#ifdef __i386__ + mp_disable_preemption(); + + map = pmap_get_mapwindow(INTEL_PTE_VALID | INTEL_PTE_RW | (i386_ptob(psrc) & PG_FRAME) | + INTEL_PTE_REF); + + memcpy((void *) dst, (void *) (map->prv_CADDR + (src_offset & INTEL_OFFMASK)), len); + + pmap_put_mapwindow(map); + + mp_enable_preemption(); +#endif } /* @@ -160,13 +216,60 @@ pmap_copy_part_rpage( * * Convert a kernel virtual address to a physical address */ -vm_offset_t +addr64_t kvtophys( vm_offset_t addr) { - pt_entry_t *pte; + pmap_paddr_t pa; + + pa = ((pmap_paddr_t)pmap_find_phys(kernel_pmap, addr)) << INTEL_PGSHIFT; + if (pa) + pa |= (addr & INTEL_OFFMASK); + + return ((addr64_t)pa); +} + +__private_extern__ void ml_copy_phys(addr64_t src64, addr64_t dst64, vm_size_t bytes) { + void *src, *dst; + + mp_disable_preemption(); +#if NCOPY_WINDOWS > 0 + mapwindow_t *src_map, *dst_map; + /* We rely on MTRRs here */ + src_map = pmap_get_mapwindow((pt_entry_t)(INTEL_PTE_VALID | ((pmap_paddr_t)src64 & PG_FRAME) | INTEL_PTE_REF)); + dst_map = pmap_get_mapwindow((pt_entry_t)(INTEL_PTE_VALID | INTEL_PTE_RW | ((pmap_paddr_t)dst64 & PG_FRAME) | INTEL_PTE_REF | INTEL_PTE_MOD)); + src = (void *) ((uintptr_t)src_map->prv_CADDR | ((uint32_t)src64 & INTEL_OFFMASK)); + dst = (void *) ((uintptr_t)dst_map->prv_CADDR | ((uint32_t)dst64 & INTEL_OFFMASK)); +#elif defined(__x86_64__) + src = PHYSMAP_PTOV(src64); + dst = PHYSMAP_PTOV(dst64); +#endif + /* ensure we stay within a page */ + if (((((uint32_t)src64 & (I386_PGBYTES-1)) + bytes) > I386_PGBYTES) || ((((uint32_t)dst64 & (I386_PGBYTES-1)) + bytes) > I386_PGBYTES) ) { + panic("ml_copy_phys spans pages, src: 0x%llx, dst: 0x%llx", src64, dst64); + } - if ((pte = pmap_pte(kernel_pmap, addr)) == PT_ENTRY_NULL) - return 0; - return i386_trunc_page(*pte) | (addr & INTEL_OFFMASK); + switch (bytes) { + case 1: + *((uint8_t *) dst) = *((uint8_t *) src); + break; + case 2: + *((uint16_t *) dst) = *((uint16_t *) src); + break; + case 4: + *((uint32_t *) dst) = *((uint32_t *) src); + break; + /* Should perform two 32-bit reads */ + case 8: + *((uint64_t *) dst) = *((uint64_t *) src); + break; + default: + bcopy(src, dst, bytes); + break; + } +#if NCOPY_WINDOWS > 0 + pmap_put_mapwindow(src_map); + pmap_put_mapwindow(dst_map); +#endif + mp_enable_preemption(); }