X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/21362eb3e66fd2c787aee132bce100a44d71a99c..d26ffc64f583ab2d29df48f13518685602bc8832:/osfmk/i386/phys.c diff --git a/osfmk/i386/phys.c b/osfmk/i386/phys.c index 13ebbd267..49147fc2a 100644 --- a/osfmk/i386/phys.c +++ b/osfmk/i386/phys.c @@ -1,5 +1,5 @@ /* - * Copyright (c) 2000-2004 Apple Computer, Inc. All rights reserved. + * Copyright (c) 2000-2012 Apple Inc. All rights reserved. * * @APPLE_OSREFERENCE_LICENSE_HEADER_START@ * @@ -54,7 +54,6 @@ * the rights to redistribute these changes. */ -#include #include #include @@ -86,7 +85,6 @@ #include #include #include -#include #include /* @@ -94,9 +92,10 @@ */ void pmap_zero_page( - ppnum_t pn) + ppnum_t pn) { assert(pn != vm_page_fictitious_addr); + assert(pn != vm_page_guard_addr); bzero_phys((addr64_t)i386_ptob(pn), PAGE_SIZE); } @@ -106,13 +105,14 @@ pmap_zero_page( */ void pmap_zero_part_page( - ppnum_t pn, + ppnum_t pn, vm_offset_t offset, vm_size_t len) { assert(pn != vm_page_fictitious_addr); + assert(pn != vm_page_guard_addr); assert(offset + len <= PAGE_SIZE); - bzero_phys((addr64_t)(i386_ptob(pn) + offset), len); + bzero_phys((addr64_t)(i386_ptob(pn) + offset), (uint32_t)len); } /* @@ -126,13 +126,19 @@ pmap_copy_part_page( vm_offset_t dst_offset, vm_size_t len) { - vm_offset_t src, dst; + pmap_paddr_t src, dst; + assert(psrc != vm_page_fictitious_addr); assert(pdst != vm_page_fictitious_addr); - src = (vm_offset_t)i386_ptob(psrc); - dst = (vm_offset_t)i386_ptob(pdst); - assert(((dst & PAGE_MASK) + dst_offset + len) <= PAGE_SIZE); - assert(((src & PAGE_MASK) + src_offset + len) <= PAGE_SIZE); + 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); + bcopy_phys((addr64_t)src + (src_offset & INTEL_OFFMASK), (addr64_t)dst + (dst_offset & INTEL_OFFMASK), len); @@ -144,26 +150,16 @@ pmap_copy_part_page( */ void pmap_copy_part_lpage( - vm_offset_t src, - ppnum_t pdst, - 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) { - pt_entry_t *ptep; - thread_t thr_act = current_thread(); assert(pdst != vm_page_fictitious_addr); - ptep = pmap_pte(thr_act->map->pmap, i386_ptob(pdst)); - if (0 == ptep) - panic("pmap_copy_part_lpage ptep"); - assert(((pdst & PAGE_MASK) + dst_offset + len) <= PAGE_SIZE); - if (*(pt_entry_t *) CM2) - panic("pmap_copy_part_lpage"); - *(int *) CM2 = INTEL_PTE_VALID | INTEL_PTE_RW | (*ptep & PG_FRAME) | - INTEL_PTE_REF | INTEL_PTE_MOD; - invlpg((unsigned int) CA2); - memcpy((void *) (CA2 + (dst_offset & INTEL_OFFMASK)), (void *) src, len); - *(pt_entry_t *) CM2 = 0; + assert(pdst != vm_page_guard_addr); + assert((dst_offset + len) <= PAGE_SIZE); + } /* @@ -172,26 +168,16 @@ pmap_copy_part_lpage( */ void pmap_copy_part_rpage( - ppnum_t psrc, - 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) { - pt_entry_t *ptep; - thread_t thr_act = current_thread(); assert(psrc != vm_page_fictitious_addr); - ptep = pmap_pte(thr_act->map->pmap, i386_ptob(psrc)); - if (0 == ptep) - panic("pmap_copy_part_rpage ptep"); - assert(((psrc & PAGE_MASK) + src_offset + len) <= PAGE_SIZE); - if (*(pt_entry_t *) CM2) - panic("pmap_copy_part_rpage"); - *(pt_entry_t *) CM2 = INTEL_PTE_VALID | INTEL_PTE_RW | (*ptep & PG_FRAME) | - INTEL_PTE_REF; - invlpg((unsigned int) CA2); - memcpy((void *) dst, (void *) (CA2 + (src_offset & INTEL_OFFMASK)), len); - *(pt_entry_t *) CM2 = 0; + assert(psrc != vm_page_guard_addr); + assert((src_offset + len) <= PAGE_SIZE); + } /* @@ -199,19 +185,106 @@ 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 *ptep; pmap_paddr_t pa; - if ((ptep = pmap_pte(kernel_pmap, addr)) == PT_ENTRY_NULL) { - pa = 0; + pa = ((pmap_paddr_t)pmap_find_phys(kernel_pmap, addr)) << INTEL_PGSHIFT; + if (pa) + pa |= (addr & INTEL_OFFMASK); + + return ((addr64_t)pa); +} + +extern pt_entry_t *debugger_ptep; +extern vm_map_offset_t debugger_window_kva; +extern int _bcopy(const void *, void *, vm_size_t); +extern int _bcopy2(const void *, void *); +extern int _bcopy4(const void *, void *); +extern int _bcopy8(const void *, void *); + +__private_extern__ int ml_copy_phys(addr64_t src64, addr64_t dst64, vm_size_t bytes) { + void *src, *dst; + int err = 0; + + 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__) + addr64_t debug_pa = 0; + + /* If either destination or source are outside the + * physical map, establish a physical window onto the target frame. + */ + assert(physmap_enclosed(src64) || physmap_enclosed(dst64)); + + if (physmap_enclosed(src64) == FALSE) { + src = (void *)(debugger_window_kva | (src64 & INTEL_OFFMASK)); + dst = PHYSMAP_PTOV(dst64); + debug_pa = src64 & PG_FRAME; + } else if (physmap_enclosed(dst64) == FALSE) { + src = PHYSMAP_PTOV(src64); + dst = (void *)(debugger_window_kva | (dst64 & INTEL_OFFMASK)); + debug_pa = dst64 & PG_FRAME; } else { - pa = pte_to_pa(*ptep) | (addr & INTEL_OFFMASK); + src = PHYSMAP_PTOV(src64); + dst = PHYSMAP_PTOV(dst64); + } + /* DRK: debugger only routine, we don't bother checking for an + * identical mapping. + */ + if (debug_pa) { + if (debugger_window_kva == 0) + panic("%s: invoked in non-debug mode", __FUNCTION__); + /* Establish a cache-inhibited physical window; some platforms + * may not cover arbitrary ranges with MTRRs + */ + pmap_store_pte(debugger_ptep, debug_pa | INTEL_PTE_NCACHE | INTEL_PTE_RW | INTEL_PTE_REF| INTEL_PTE_MOD | INTEL_PTE_VALID); + flush_tlb_raw(); +#if DEBUG + kprintf("Remapping debugger physical window at %p to 0x%llx\n", (void *)debugger_window_kva, debug_pa); +#endif } - if (0 == pa) - kprintf("kvtophys ret 0!\n"); - return (pa); +#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); + } + + /* + * For device register access from the debugger, + * 2-byte/16-bit, 4-byte/32-bit and 8-byte/64-bit copies are handled + * by assembly routines ensuring the required access widths. + * 1-byte and other copies are handled by the regular _bcopy. + */ + switch (bytes) { + case 2: + err = _bcopy2(src, dst); + break; + case 4: + err = _bcopy4(src, dst); + break; + case 8: + err = _bcopy8(src, dst); + break; + case 1: + default: + err = _bcopy(src, dst, bytes); + break; + } + +#if NCOPY_WINDOWS > 0 + pmap_put_mapwindow(src_map); + pmap_put_mapwindow(dst_map); +#endif + mp_enable_preemption(); + + return err; }