X-Git-Url: https://git.saurik.com/apple/xnu.git/blobdiff_plain/b226f5e54a60dc81db17b1260381d7dbfea3cdf1..0a7de7458d150b5d4dffc935ba399be265ef0a1a:/osfmk/i386/Diagnostics.c diff --git a/osfmk/i386/Diagnostics.c b/osfmk/i386/Diagnostics.c index 90eeb4192..4f1360216 100644 --- a/osfmk/i386/Diagnostics.c +++ b/osfmk/i386/Diagnostics.c @@ -2,7 +2,7 @@ * Copyright (c) 2005-2008 Apple 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 @@ -11,10 +11,10 @@ * 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 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES, @@ -22,7 +22,7 @@ * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT. * Please see the License for the specific language governing rights and * limitations under the License. - * + * * @APPLE_OSREFERENCE_LICENSE_HEADER_END@ */ /* @@ -83,7 +83,7 @@ diagWork dgWork; uint64_t lastRuptClear = 0ULL; -boolean_t diag_pmc_enabled = FALSE; +boolean_t diag_pmc_enabled = FALSE; void cpu_powerstats(void *); typedef struct { @@ -98,7 +98,7 @@ typedef struct { uint64_t cpu_insns; uint64_t cpu_ucc; uint64_t cpu_urc; -#if DIAG_ALL_PMCS +#if DIAG_ALL_PMCS uint64_t gpmcs[4]; #endif /* DIAG_ALL_PMCS */ } core_energy_stat_t; @@ -125,15 +125,15 @@ typedef struct { } pkg_energy_statistics_t; -int +int diagCall64(x86_saved_state_t * state) { - uint64_t curpos, i, j; - uint64_t selector, data; - uint64_t currNap, durNap; - x86_saved_state64_t *regs; - boolean_t diagflag; - uint32_t rval = 0; + uint64_t curpos, i, j; + uint64_t selector, data; + uint64_t currNap, durNap; + x86_saved_state64_t *regs; + boolean_t diagflag; + uint32_t rval = 0; assert(is_saved_state64(state)); regs = saved_state64(state); @@ -141,46 +141,47 @@ diagCall64(x86_saved_state_t * state) diagflag = ((dgWork.dgFlags & enaDiagSCs) != 0); selector = regs->rdi; - switch (selector) { /* Select the routine */ - case dgRuptStat: /* Suck Interruption statistics */ + switch (selector) { /* Select the routine */ + case dgRuptStat: /* Suck Interruption statistics */ (void) ml_set_interrupts_enabled(TRUE); data = regs->rsi; /* Get the number of processors */ if (data == 0) { /* If no location is specified for data, clear all - * counts - */ - for (i = 0; i < real_ncpus; i++) { /* Cycle through - * processors */ - for (j = 0; j < 256; j++) + * counts + */ + for (i = 0; i < real_ncpus; i++) { /* Cycle through + * processors */ + for (j = 0; j < 256; j++) { cpu_data_ptr[i]->cpu_hwIntCnt[j] = 0; + } } - lastRuptClear = mach_absolute_time(); /* Get the time of clear */ - rval = 1; /* Normal return */ + lastRuptClear = mach_absolute_time(); /* Get the time of clear */ + rval = 1; /* Normal return */ (void) ml_set_interrupts_enabled(FALSE); break; } - (void) copyout((char *) &real_ncpus, data, sizeof(real_ncpus)); /* Copy out number of - * processors */ - currNap = mach_absolute_time(); /* Get the time now */ - durNap = currNap - lastRuptClear; /* Get the last interval - * duration */ - if (durNap == 0) - durNap = 1; /* This is a very short time, make it - * bigger */ - - curpos = data + sizeof(real_ncpus); /* Point to the next - * available spot */ - - for (i = 0; i < real_ncpus; i++) { /* Move 'em all out */ - (void) copyout((char *) &durNap, curpos, 8); /* Copy out the time - * since last clear */ - (void) copyout((char *) &cpu_data_ptr[i]->cpu_hwIntCnt, curpos + 8, 256 * sizeof(uint32_t)); /* Copy out interrupt - * data for this - * processor */ - curpos = curpos + (256 * sizeof(uint32_t) + 8); /* Point to next out put - * slot */ + (void) copyout((char *) &real_ncpus, data, sizeof(real_ncpus)); /* Copy out number of + * processors */ + currNap = mach_absolute_time(); /* Get the time now */ + durNap = currNap - lastRuptClear; /* Get the last interval + * duration */ + if (durNap == 0) { + durNap = 1; /* This is a very short time, make it + * bigger */ + } + curpos = data + sizeof(real_ncpus); /* Point to the next + * available spot */ + + for (i = 0; i < real_ncpus; i++) { /* Move 'em all out */ + (void) copyout((char *) &durNap, curpos, 8); /* Copy out the time + * since last clear */ + (void) copyout((char *) &cpu_data_ptr[i]->cpu_hwIntCnt, curpos + 8, 256 * sizeof(uint32_t)); /* Copy out interrupt + * data for this + * processor */ + curpos = curpos + (256 * sizeof(uint32_t) + 8); /* Point to next out put + * slot */ } rval = 1; (void) ml_set_interrupts_enabled(FALSE); @@ -266,7 +267,7 @@ diagCall64(x86_saved_state_t * state) curpos = regs->rsi + sizeof(pkes); mp_cpus_call(CPUMASK_ALL, ASYNC, cpu_powerstats, NULL); - + for (i = 0; i < real_ncpus; i++) { (void) ml_set_interrupts_enabled(FALSE); @@ -298,10 +299,10 @@ diagCall64(x86_saved_state_t * state) rval = 1; (void) ml_set_interrupts_enabled(FALSE); } - break; - case dgEnaPMC: - { - boolean_t enable = TRUE; + break; + case dgEnaPMC: + { + boolean_t enable = TRUE; uint32_t cpuinfo[4]; /* Require architectural PMC v2 or higher, corresponding to * Merom+, or equivalent virtualised facility. @@ -311,10 +312,10 @@ diagCall64(x86_saved_state_t * state) mp_cpus_call(CPUMASK_ALL, ASYNC, cpu_pmc_control, &enable); diag_pmc_enabled = TRUE; } - rval = 1; - } - break; -#if DEVELOPMENT || DEBUG + rval = 1; + } + break; +#if DEVELOPMENT || DEBUG case dgGzallocTest: { (void) ml_set_interrupts_enabled(TRUE); @@ -329,17 +330,18 @@ diagCall64(x86_saved_state_t * state) #endif #if DEVELOPMENT || DEBUG - case dgPermCheck: + case dgPermCheck: { (void) ml_set_interrupts_enabled(TRUE); - if (diagflag) + if (diagflag) { rval = pmap_permissions_verify(kernel_pmap, kernel_map, 0, ~0ULL); + } (void) ml_set_interrupts_enabled(FALSE); } - break; + break; #endif /* DEVELOPMENT || DEBUG */ - default: /* Handle invalid ones */ - rval = 0; /* Return an exception */ + default: /* Handle invalid ones */ + rval = 0; /* Return an exception */ } regs->rax = rval; @@ -348,7 +350,9 @@ diagCall64(x86_saved_state_t * state) return rval; } -void cpu_powerstats(__unused void *arg) { +void +cpu_powerstats(__unused void *arg) +{ cpu_data_t *cdp = current_cpu_datap(); __unused int cnum = cdp->cpu_number; uint32_t cl = 0, ch = 0, mpl = 0, mph = 0, apl = 0, aph = 0; @@ -395,16 +399,17 @@ void cpu_powerstats(__unused void *arg) { } } -void cpu_pmc_control(void *enablep) { +void +cpu_pmc_control(void *enablep) +{ #if !MONOTONIC boolean_t enable = *(boolean_t *)enablep; - cpu_data_t *cdp = current_cpu_datap(); + cpu_data_t *cdp = current_cpu_datap(); if (enable) { wrmsr64(0x38F, 0x70000000FULL); wrmsr64(0x38D, 0x333); set_cr4(get_cr4() | CR4_PCE); - } else { wrmsr64(0x38F, 0); wrmsr64(0x38D, 0);