acpi/pstate: Fix the long standing P-State detection problem on Intel CPUs
[dragonfly.git] / sys / dev / acpica5 / acpi_cpu_cstate.c
index 934380f..028d77b 100644 (file)
@@ -25,7 +25,6 @@
  * SUCH DAMAGE.
  *
  * $FreeBSD: src/sys/dev/acpica/acpi_cpu.c,v 1.72 2008/04/12 12:06:00 rpaulo Exp $
- * $DragonFly: src/sys/dev/acpica5/acpi_cpu.c,v 1.21 2008/09/05 10:28:35 hasso Exp $
  */
 
 #include "opt_acpi.h"
@@ -80,7 +79,6 @@ struct acpi_cpu_softc {
     struct acpi_cx      cpu_cx_states[MAX_CX_STATES];
     int                         cpu_cx_count;  /* Number of valid Cx states. */
     int                         cpu_prev_sleep;/* Last idle sleep duration. */
-    int                         cpu_features;  /* Child driver supported features. */
     /* Runtime state. */
     int                         cpu_non_c3;    /* Index of lowest non-C3 state. */
     u_int               cpu_cx_stats[MAX_CX_STATES];/* Cx usage history. */
@@ -199,7 +197,7 @@ static driver_t acpi_cpu_cst_driver = {
 };
 
 static devclass_t acpi_cpu_cst_devclass;
-DRIVER_MODULE(cpu_cst, cpu, acpi_cpu_cst_driver, acpi_cpu_cst_devclass, 0, 0);
+DRIVER_MODULE(cpu_cst, cpu, acpi_cpu_cst_driver, acpi_cpu_cst_devclass, NULL, NULL);
 MODULE_DEPEND(cpu_cst, acpi, 1, 1, 1);
 
 static int
@@ -236,20 +234,11 @@ static int
 acpi_cpu_cst_attach(device_t dev)
 {
     ACPI_BUFFER                   buf;
-    ACPI_OBJECT                   arg[4], *obj;
-    ACPI_OBJECT_LIST      arglist;
+    ACPI_OBJECT                   *obj;
     struct mdglobaldata          *md;
     struct acpi_cpu_softc *sc;
     ACPI_STATUS                   status;
-    u_int                 features;
-    int                           cpu_id, drv_count, i;
-    driver_t             **drivers;
-    uint32_t              cap_set[3];
-
-    /* UUID needed by _OSC evaluation */
-    static uint8_t cpu_oscuuid[16] = { 0x16, 0xA6, 0x77, 0x40, 0x0C, 0x29,
-                                      0xBE, 0x47, 0x9E, 0xBD, 0xD8, 0x70,
-                                      0x58, 0x71, 0x39, 0x53 };
+    int                           cpu_id;
 
     ACPI_FUNCTION_TRACE((char *)(uintptr_t)__func__);
 
@@ -292,60 +281,6 @@ acpi_cpu_cst_attach(device_t dev)
        AcpiOsExecute(OSL_NOTIFY_HANDLER, acpi_cpu_startup, NULL);
     }
 
-    /*
-     * Before calling any CPU methods, collect child driver feature hints
-     * and notify ACPI of them.  We support unified SMP power control
-     * so advertise this ourselves.  Note this is not the same as independent
-     * SMP control where each CPU can have different settings.
-     */
-    sc->cpu_features = ACPI_CAP_SMP_SAME | ACPI_CAP_SMP_SAME_C3;
-    if (devclass_get_drivers(acpi_cpu_cst_devclass,
-                            &drivers, &drv_count) == 0) {
-       for (i = 0; i < drv_count; i++) {
-           if (ACPI_GET_FEATURES(drivers[i], &features) == 0)
-               sc->cpu_features |= features;
-       }
-       kfree(drivers, M_TEMP);
-    }
-
-    /*
-     * CPU capabilities are specified as a buffer of 32-bit integers:
-     * revision, count, and one or more capabilities.  The revision of
-     * "1" is not specified anywhere but seems to match Linux.
-     */
-    if (sc->cpu_features) {
-       arglist.Pointer = arg;
-       arglist.Count = 1;
-       arg[0].Type = ACPI_TYPE_BUFFER;
-       arg[0].Buffer.Length = sizeof(cap_set);
-       arg[0].Buffer.Pointer = (uint8_t *)cap_set;
-       cap_set[0] = 1; /* revision */
-       cap_set[1] = 1; /* number of capabilities integers */
-       cap_set[2] = sc->cpu_features;
-       AcpiEvaluateObject(sc->cpu_handle, "_PDC", &arglist, NULL);
-
-       /*
-        * On some systems we need to evaluate _OSC so that the ASL
-        * loads the _PSS and/or _PDC methods at runtime.
-        *
-        * TODO: evaluate failure of _OSC.
-        */
-       arglist.Pointer = arg;
-       arglist.Count = 4;
-       arg[0].Type = ACPI_TYPE_BUFFER;
-       arg[0].Buffer.Length = sizeof(cpu_oscuuid);
-       arg[0].Buffer.Pointer = cpu_oscuuid;    /* UUID */
-       arg[1].Type = ACPI_TYPE_INTEGER;
-       arg[1].Integer.Value = 1;               /* revision */
-       arg[2].Type = ACPI_TYPE_INTEGER;
-       arg[2].Integer.Value = 1;               /* count */
-       arg[3].Type = ACPI_TYPE_BUFFER;
-       arg[3].Buffer.Length = sizeof(cap_set); /* Capabilities buffer */
-       arg[3].Buffer.Pointer = (uint8_t *)cap_set;
-       cap_set[0] = 0;
-       AcpiEvaluateObject(sc->cpu_handle, "_OSC", &arglist, NULL);
-    }
-
     /* Probe for Cx state support. */
     acpi_cpu_cx_probe(sc);
 
@@ -611,18 +546,11 @@ acpi_cpu_cx_cst(struct acpi_cpu_softc *sc)
            sc->cpu_cx_count++;
            continue;
        case ACPI_STATE_C2:
-           if (cx_ptr->trans_lat > 100) {
-               ACPI_DEBUG_PRINT((ACPI_DB_INFO,
-                                "acpi_cpu%d: C2[%d] not available.\n",
-                                device_get_unit(sc->cpu_dev), i));
-               continue;
-           }
            sc->cpu_non_c3 = i;
            break;
        case ACPI_STATE_C3:
        default:
-           if (cx_ptr->trans_lat > 1000 ||
-               (cpu_quirks & CPU_QUIRK_NO_C3) != 0) {
+           if ((cpu_quirks & CPU_QUIRK_NO_C3) != 0) {
 
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                                 "acpi_cpu%d: C3[%d] not available.\n",
@@ -807,7 +735,7 @@ acpi_cpu_idle(void)
 {
     struct     acpi_cpu_softc *sc;
     struct     acpi_cx *cx_next;
-    uint32_t   start_time, end_time;
+    uint64_t   start_time, end_time;
     int                bm_active, cx_next_idx, i;
 
     /* If disabled, return immediately. */
@@ -1017,7 +945,7 @@ acpi_cpu_quirks(void)
            if (val) {
                ACPI_DEBUG_PRINT((ACPI_DB_INFO,
                    "acpi_cpu: PIIX4: reset BRLD_EN_BM\n"));
-               AcpiReadBitRegister(ACPI_BITREG_BUS_MASTER_RLD, 0);
+               AcpiWriteBitRegister(ACPI_BITREG_BUS_MASTER_RLD, 0);
            }
            break;
        default:
@@ -1094,7 +1022,7 @@ acpi_cpu_set_cx_lowest(struct acpi_cpu_softc *sc, int val)
            if (!error) {
                cputimer_intr_restart();
            } else {
-               kprintf("no suitable intr cuptimer found\n");
+               kprintf("no suitable intr cputimer found\n");
 
                /* Restore */
                sc->cpu_cx_lowest = old_lowest;
@@ -1192,12 +1120,12 @@ acpi_cpu_c1(void)
 #else
     splz();
 #ifdef SMP
-    if (!lwkt_runnable())
+    if ((mycpu->gd_reqflags & RQF_IDLECHECK_WK_MASK) == 0)
         __asm __volatile("sti; hlt");
     else
         __asm __volatile("sti; pause");
 #else
-    if (!lwkt_runnable())
+    if ((mycpu->gd_reqflags & RQF_IDLECHECK_WK_MASK) == 0)
         __asm __volatile("sti; hlt");
     else
         __asm __volatile("sti");