]> git.saurik.com Git - apple/xnu.git/blobdiff - bsd/dev/i386/sysctl.c
xnu-2050.24.15.tar.gz
[apple/xnu.git] / bsd / dev / i386 / sysctl.c
index cb15eb632e49521e4ecf3b1f326afcfed347ea3e..ddc9503e3e9420a6499954209586ba15e2f32fe3 100644 (file)
@@ -1,5 +1,5 @@
 /*
 /*
- * Copyright (c) 2003 Apple Computer, Inc. All rights reserved.
+ * Copyright (c) 2003-2011 Apple Inc. All rights reserved.
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
  *
  * @APPLE_OSREFERENCE_LICENSE_HEADER_START@
  * 
@@ -36,6 +36,7 @@
 #include <i386/ucode.h>
 #include <kern/clock.h>
 #include <libkern/libkern.h>
 #include <i386/ucode.h>
 #include <kern/clock.h>
 #include <libkern/libkern.h>
+#include <i386/lapic.h>
 
 static int
 _i386_cpu_info SYSCTL_HANDLER_ARGS
 
 static int
 _i386_cpu_info SYSCTL_HANDLER_ARGS
@@ -119,6 +120,7 @@ cpu_xsave SYSCTL_HANDLER_ARGS
     return _i386_cpu_info(oidp, ptr, arg2, req);
 }
 
     return _i386_cpu_info(oidp, ptr, arg2, req);
 }
 
+
 static int
 cpu_features SYSCTL_HANDLER_ARGS
 {
 static int
 cpu_features SYSCTL_HANDLER_ARGS
 {
@@ -147,6 +149,24 @@ cpu_extfeatures SYSCTL_HANDLER_ARGS
     return SYSCTL_OUT(req, buf, strlen(buf) + 1);
 }
 
     return SYSCTL_OUT(req, buf, strlen(buf) + 1);
 }
 
+static int
+cpu_leaf7_features SYSCTL_HANDLER_ARGS
+{
+    __unused struct sysctl_oid *unused_oidp = oidp;
+    __unused void *unused_arg1 = arg1;
+    __unused int unused_arg2 = arg2; 
+    char buf[512];
+
+    uint32_t   leaf7_features = cpuid_info()->cpuid_leaf7_features;
+    if (leaf7_features == 0)
+        return ENOENT;
+
+    buf[0] = '\0';
+    cpuid_get_leaf7_feature_names(leaf7_features, buf, sizeof(buf));
+
+    return SYSCTL_OUT(req, buf, strlen(buf) + 1);
+}
+
 static int
 cpu_logical_per_package SYSCTL_HANDLER_ARGS
 {
 static int
 cpu_logical_per_package SYSCTL_HANDLER_ARGS
 {
@@ -262,6 +282,26 @@ misc_interrupt_latency_max(__unused struct sysctl_oid *oidp, __unused void *arg1
        return error;
 }
 
        return error;
 }
 
+/*
+ * Triggers a machine-check exception - for a suitably configured kernel only.
+ */
+extern void mca_exception_panic(void);
+static int
+misc_machine_check_panic(__unused struct sysctl_oid *oidp, __unused void *arg1, __unused int arg2, struct sysctl_req *req)
+{
+       int changed = 0, error;
+       char buf[128];
+       buf[0] = '\0';
+
+       error = sysctl_io_string(req, buf, sizeof(buf), 0, &changed);
+
+       if (error == 0 && changed) {
+               mca_exception_panic();
+       }
+       return error;
+}
+
+
 SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
        "CPU info");
 
 SYSCTL_NODE(_machdep, OID_AUTO, cpu, CTLFLAG_RW|CTLFLAG_LOCKED, 0,
        "CPU info");
 
@@ -305,6 +345,12 @@ SYSCTL_PROC(_machdep_cpu, OID_AUTO, feature_bits, CTLTYPE_QUAD | CTLFLAG_RD | CT
            (void *)offsetof(i386_cpu_info_t, cpuid_features), sizeof(uint64_t),
            i386_cpu_info, "IU", "CPU features");
 
            (void *)offsetof(i386_cpu_info_t, cpuid_features), sizeof(uint64_t),
            i386_cpu_info, "IU", "CPU features");
 
+SYSCTL_PROC(_machdep_cpu, OID_AUTO, leaf7_feature_bits,
+           CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, 
+           (void *)offsetof(i386_cpu_info_t, cpuid_leaf7_features),
+           sizeof(uint32_t),
+           i386_cpu_info_nonzero, "IU", "CPU Leaf7 features");
+
 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeature_bits, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_LOCKED, 
            (void *)offsetof(i386_cpu_info_t, cpuid_extfeatures), sizeof(uint64_t),
            i386_cpu_info, "IU", "CPU extended features");
 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeature_bits, CTLTYPE_QUAD | CTLFLAG_RD | CTLFLAG_LOCKED, 
            (void *)offsetof(i386_cpu_info_t, cpuid_extfeatures), sizeof(uint64_t),
            i386_cpu_info, "IU", "CPU extended features");
@@ -321,6 +367,11 @@ SYSCTL_PROC(_machdep_cpu, OID_AUTO, features, CTLTYPE_STRING | CTLFLAG_RD | CTLF
            0, 0,
            cpu_features, "A", "CPU feature names");
 
            0, 0,
            cpu_features, "A", "CPU feature names");
 
+SYSCTL_PROC(_machdep_cpu, OID_AUTO, leaf7_features,
+           CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED, 
+           0, 0,
+           cpu_leaf7_features, "A", "CPU Leaf7 feature names");
+
 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeatures, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED, 
            0, 0,
            cpu_extfeatures, "A", "CPU extended feature names");
 SYSCTL_PROC(_machdep_cpu, OID_AUTO, extfeatures, CTLTYPE_STRING | CTLFLAG_RD | CTLFLAG_LOCKED, 
            0, 0,
            cpu_extfeatures, "A", "CPU extended feature names");
@@ -426,7 +477,7 @@ SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, package_thermal_intr,
            CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, 
            (void *)offsetof(cpuid_thermal_leaf_t, package_thermal_intr),
            sizeof(boolean_t),
            CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, 
            (void *)offsetof(cpuid_thermal_leaf_t, package_thermal_intr),
            sizeof(boolean_t),
-           cpu_thermal, "I", "Packge Thermal interrupt and Status");
+           cpu_thermal, "I", "Package Thermal interrupt and Status");
 
 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, hardware_feedback,
            CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, 
 
 SYSCTL_PROC(_machdep_cpu_thermal, OID_AUTO, hardware_feedback,
            CTLTYPE_INT | CTLFLAG_RD | CTLFLAG_LOCKED, 
@@ -631,6 +682,15 @@ SYSCTL_PROC(_machdep_cpu, OID_AUTO, ucupdate,
                        CTLTYPE_INT | CTLFLAG_WR | CTLFLAG_LOCKED, 0, 0,
             cpu_ucode_update, "S", "Microcode update interface");
 
                        CTLTYPE_INT | CTLFLAG_WR | CTLFLAG_LOCKED, 0, 0,
             cpu_ucode_update, "S", "Microcode update interface");
 
+static const uint32_t apic_timer_vector = (LAPIC_DEFAULT_INTERRUPT_BASE + LAPIC_TIMER_INTERRUPT);
+static const uint32_t apic_IPI_vector = (LAPIC_DEFAULT_INTERRUPT_BASE + LAPIC_INTERPROCESSOR_INTERRUPT);
+
+SYSCTL_NODE(_machdep, OID_AUTO, vectors, CTLFLAG_RD | CTLFLAG_LOCKED, 0,
+       "Interrupt vector assignments");
+
+SYSCTL_UINT     (_machdep_vectors, OID_AUTO, timer, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (uint32_t *)&apic_timer_vector, 0, "");
+SYSCTL_UINT     (_machdep_vectors, OID_AUTO, IPI, CTLFLAG_RD | CTLFLAG_KERN | CTLFLAG_LOCKED, (uint32_t *)&apic_IPI_vector, 0, "");
+
 uint64_t pmap_pv_hashlist_walks;
 uint64_t pmap_pv_hashlist_cnts;
 uint32_t pmap_pv_hashlist_max;
 uint64_t pmap_pv_hashlist_walks;
 uint64_t pmap_pv_hashlist_cnts;
 uint32_t pmap_pv_hashlist_max;
@@ -680,6 +740,13 @@ SYSCTL_PROC(_machdep_misc, OID_AUTO, panic_restart_timeout,
            0, 0,
            panic_set_restart_timeout, "I", "Panic restart timeout in seconds");
 
            0, 0,
            panic_set_restart_timeout, "I", "Panic restart timeout in seconds");
 
-SYSCTL_PROC(_machdep_misc, OID_AUTO, interrupt_latency_max, CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED, 
+SYSCTL_PROC(_machdep_misc, OID_AUTO, interrupt_latency_max,
+           CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED, 
            0, 0,
            misc_interrupt_latency_max, "A", "Maximum Interrupt latency");
            0, 0,
            misc_interrupt_latency_max, "A", "Maximum Interrupt latency");
+
+SYSCTL_PROC(_machdep_misc, OID_AUTO, machine_check_panic,
+           CTLTYPE_STRING | CTLFLAG_RW | CTLFLAG_LOCKED, 
+           0, 0,
+           misc_machine_check_panic, "A", "Machine-check exception test");
+