]> git.saurik.com Git - apple/xnu.git/blobdiff - osfmk/x86_64/loose_ends.c
xnu-3789.1.32.tar.gz
[apple/xnu.git] / osfmk / x86_64 / loose_ends.c
index 10a086542bcc289180d046c080b899689bf14380..161b397c306c5e440e3b3728d9c561ab8be912c9 100644 (file)
@@ -1,5 +1,5 @@
 /*
- * Copyright (c) 2000-2006 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2000-2013 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
 #include <libkern/OSAtomic.h>
 #include <sys/kdebug.h>
 
+#if !MACH_KDP
+#include <kdp/kdp_callout.h>
+#endif /* !MACH_KDP */
+
+#include <libkern/OSDebug.h>
+#if CONFIG_DTRACE
+#include <mach/sdt.h>
+#endif
+
 #if 0
 
 #undef KERNEL_DEBUG
@@ -98,7 +107,7 @@ extern void          mapping_set_ref(ppnum_t pn);
 extern void            ovbcopy(const char      *from,
                                char            *to,
                                vm_size_t       nbytes);
-void machine_callstack(natural_t *buf, vm_size_t callstack_max);
+void machine_callstack(uintptr_t *buf, vm_size_t callstack_max);
 
 
 #define value_64bit(value)  ((value) & 0xFFFFFFFF00000000ULL)
@@ -242,18 +251,27 @@ ovbcopy(
  *  Read data from a physical address. Memory should not be cache inhibited.
  */
 
+uint64_t reportphyreaddelayabs;
+uint32_t reportphyreadosbt;
 
 static inline unsigned int
 ml_phys_read_data(pmap_paddr_t paddr, int size)
 {
-       unsigned int result;
+       unsigned int result = 0;
+       unsigned char s1;
+       unsigned short s2;
+       boolean_t istate;
+       uint64_t sabs, eabs;
 
-       if (!physmap_enclosed(paddr))
+       if (__improbable(!physmap_enclosed(paddr)))
                panic("%s: 0x%llx out of bounds\n", __FUNCTION__, paddr);
 
+       if (__improbable(reportphyreaddelayabs != 0)) {
+               istate = ml_set_interrupts_enabled(FALSE);
+               sabs = mach_absolute_time();
+       }
+
         switch (size) {
-               unsigned char s1;
-               unsigned short s2;
         case 1:
                s1 = *(volatile unsigned char *)PHYSMAP_PTOV(paddr);
                result = s1;
@@ -269,6 +287,22 @@ ml_phys_read_data(pmap_paddr_t paddr, int size)
                panic("Invalid size %d for ml_phys_read_data\n", size);
                break;
         }
+
+       if (__improbable(reportphyreaddelayabs != 0)) {
+               eabs = mach_absolute_time();
+               (void)ml_set_interrupts_enabled(istate);
+
+               if ((eabs - sabs) > reportphyreaddelayabs) {
+                       if (reportphyreadosbt) {
+                               OSReportWithBacktrace("ml_phys_read_data took %lluus\n", (eabs - sabs) / 1000);
+                       }
+#if CONFIG_DTRACE
+                       DTRACE_PHYSLAT3(physread, uint64_t, (eabs - sabs),
+                           pmap_paddr_t, paddr, uint32_t, size);
+#endif
+               }
+       }
+
         return result;
 }
 
@@ -487,6 +521,13 @@ memcmp(const void *s1, const void *s2, size_t n)
        return (0);
 }
 
+void *
+memmove(void *dst, const void *src, size_t ulen)
+{
+       bcopy(src, dst, ulen);
+       return dst;
+}
+
 /*
  * Abstract:
  * strlen returns the number of characters in "string" preceeding
@@ -495,23 +536,15 @@ memcmp(const void *s1, const void *s2, size_t n)
 
 size_t
 strlen(
-       register const char *string)
+       const char *string)
 {
-       register const char *ret = string;
+       const char *ret = string;
 
        while (*string++ != '\0')
                continue;
        return string - 1 - ret;
 }
 
-uint32_t
-hw_compare_and_store(uint32_t oldval, uint32_t newval, volatile uint32_t *dest)
-{
-       return OSCompareAndSwap((UInt32)oldval,
-                               (UInt32)newval,
-                               (volatile UInt32 *)dest);
-}
-
 #if    MACH_ASSERT
 
 /*
@@ -519,7 +552,7 @@ hw_compare_and_store(uint32_t oldval, uint32_t newval, volatile uint32_t *dest)
  * levels of return pc information.
  */
 void machine_callstack(
-       __unused natural_t      *buf,
+       __unused uintptr_t      *buf,
        __unused vm_size_t      callstack_max)
 {
 }
@@ -538,18 +571,6 @@ void fillPage(ppnum_t pa, unsigned int fill)
                *addr++ = fill;
 }
 
-static inline void __sfence(void)
-{
-    __asm__ volatile("sfence");
-}
-static inline void __mfence(void)
-{
-    __asm__ volatile("mfence");
-}
-static inline void __wbinvd(void)
-{
-    __asm__ volatile("wbinvd");
-}
 static inline void __clflush(void *ptr)
 {
        __asm__ volatile("clflush (%0)" : : "r" (ptr));
@@ -560,14 +581,14 @@ void dcache_incoherent_io_store64(addr64_t pa, unsigned int count)
        addr64_t  linesize = cpuid_info()->cache_linesize;
        addr64_t  bound = (pa + count + linesize - 1) & ~(linesize - 1);
 
-       __mfence();
+       mfence();
 
        while (pa < bound) {
                __clflush(PHYSMAP_PTOV(pa));
                pa += linesize;
        }
 
-       __mfence();
+       mfence();
 }
 
 void dcache_incoherent_io_flush64(addr64_t pa, unsigned int count)
@@ -582,14 +603,14 @@ flush_dcache64(addr64_t addr, unsigned count, int phys)
                dcache_incoherent_io_flush64(addr, count);
        }
        else {
-               uint32_t  linesize = cpuid_info()->cache_linesize;
+               uint64_t  linesize = cpuid_info()->cache_linesize;
                addr64_t  bound = (addr + count + linesize -1) & ~(linesize - 1);
-               __mfence();
+               mfence();
                while (addr < bound) {
                        __clflush((void *) (uintptr_t) addr);
                        addr += linesize;
                }
-               __mfence();
+               mfence();
        }
 }
 
@@ -615,15 +636,22 @@ mapping_set_ref(ppnum_t pn)
   pmap_set_reference(pn);
 }
 
+extern i386_cpu_info_t cpuid_cpu_info;
 void
 cache_flush_page_phys(ppnum_t pa)
 {
        boolean_t       istate;
        unsigned char   *cacheline_addr;
-       int             cacheline_size = cpuid_info()->cache_linesize;
-       int             cachelines_to_flush = PAGE_SIZE/cacheline_size;
+       i386_cpu_info_t *cpuid_infop = cpuid_info();
+       int             cacheline_size;
+       int             cachelines_to_flush;
+
+       cacheline_size = cpuid_infop->cache_linesize;
+       if (cacheline_size == 0)
+               panic("cacheline_size=0 cpuid_infop=%p\n", cpuid_infop);
+       cachelines_to_flush = PAGE_SIZE/cacheline_size;
 
-       __mfence();
+       mfence();
 
        istate = ml_set_interrupts_enabled(FALSE);
 
@@ -635,14 +663,15 @@ cache_flush_page_phys(ppnum_t pa)
 
        (void) ml_set_interrupts_enabled(istate);
 
-       __mfence();
+       mfence();
 }
 
 
 #if !MACH_KDP
 void
-kdp_register_callout(void)
+kdp_register_callout(kdp_callout_fn_t fn, void *arg)
 {
+#pragma unused(fn,arg)
 }
 #endif