Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0
0002 /*
0003  * Copyright (C) 2005 Intel Corporation
0004  * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
0005  *
0006  *      Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
0007  *      - Added _PDC for platforms with Intel CPUs
0008  */
0009 
0010 #define pr_fmt(fmt) "ACPI: " fmt
0011 
0012 #include <linux/dmi.h>
0013 #include <linux/slab.h>
0014 #include <linux/acpi.h>
0015 #include <acpi/processor.h>
0016 
0017 #include "internal.h"
0018 
0019 static bool __init processor_physically_present(acpi_handle handle)
0020 {
0021     int cpuid, type;
0022     u32 acpi_id;
0023     acpi_status status;
0024     acpi_object_type acpi_type;
0025     unsigned long long tmp;
0026     union acpi_object object = { 0 };
0027     struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
0028 
0029     status = acpi_get_type(handle, &acpi_type);
0030     if (ACPI_FAILURE(status))
0031         return false;
0032 
0033     switch (acpi_type) {
0034     case ACPI_TYPE_PROCESSOR:
0035         status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
0036         if (ACPI_FAILURE(status))
0037             return false;
0038         acpi_id = object.processor.proc_id;
0039         break;
0040     case ACPI_TYPE_DEVICE:
0041         status = acpi_evaluate_integer(handle, "_UID", NULL, &tmp);
0042         if (ACPI_FAILURE(status))
0043             return false;
0044         acpi_id = tmp;
0045         break;
0046     default:
0047         return false;
0048     }
0049 
0050     type = (acpi_type == ACPI_TYPE_DEVICE) ? 1 : 0;
0051     cpuid = acpi_get_cpuid(handle, type, acpi_id);
0052 
0053     return !invalid_logical_cpuid(cpuid);
0054 }
0055 
0056 static void acpi_set_pdc_bits(u32 *buf)
0057 {
0058     buf[0] = ACPI_PDC_REVISION_ID;
0059     buf[1] = 1;
0060 
0061     /* Enable coordination with firmware's _TSD info */
0062     buf[2] = ACPI_PDC_SMP_T_SWCOORD;
0063 
0064     /* Twiddle arch-specific bits needed for _PDC */
0065     arch_acpi_set_pdc_bits(buf);
0066 }
0067 
0068 static struct acpi_object_list *acpi_processor_alloc_pdc(void)
0069 {
0070     struct acpi_object_list *obj_list;
0071     union acpi_object *obj;
0072     u32 *buf;
0073 
0074     /* allocate and initialize pdc. It will be used later. */
0075     obj_list = kmalloc(sizeof(struct acpi_object_list), GFP_KERNEL);
0076     if (!obj_list)
0077         goto out;
0078 
0079     obj = kmalloc(sizeof(union acpi_object), GFP_KERNEL);
0080     if (!obj) {
0081         kfree(obj_list);
0082         goto out;
0083     }
0084 
0085     buf = kmalloc(12, GFP_KERNEL);
0086     if (!buf) {
0087         kfree(obj);
0088         kfree(obj_list);
0089         goto out;
0090     }
0091 
0092     acpi_set_pdc_bits(buf);
0093 
0094     obj->type = ACPI_TYPE_BUFFER;
0095     obj->buffer.length = 12;
0096     obj->buffer.pointer = (u8 *) buf;
0097     obj_list->count = 1;
0098     obj_list->pointer = obj;
0099 
0100     return obj_list;
0101 out:
0102     pr_err("Memory allocation error\n");
0103     return NULL;
0104 }
0105 
0106 /*
0107  * _PDC is required for a BIOS-OS handshake for most of the newer
0108  * ACPI processor features.
0109  */
0110 static acpi_status
0111 acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in)
0112 {
0113     acpi_status status = AE_OK;
0114 
0115     if (boot_option_idle_override == IDLE_NOMWAIT) {
0116         /*
0117          * If mwait is disabled for CPU C-states, the C2C3_FFH access
0118          * mode will be disabled in the parameter of _PDC object.
0119          * Of course C1_FFH access mode will also be disabled.
0120          */
0121         union acpi_object *obj;
0122         u32 *buffer = NULL;
0123 
0124         obj = pdc_in->pointer;
0125         buffer = (u32 *)(obj->buffer.pointer);
0126         buffer[2] &= ~(ACPI_PDC_C_C2C3_FFH | ACPI_PDC_C_C1_FFH);
0127 
0128     }
0129     status = acpi_evaluate_object(handle, "_PDC", pdc_in, NULL);
0130 
0131     if (ACPI_FAILURE(status))
0132         acpi_handle_debug(handle,
0133             "Could not evaluate _PDC, using legacy perf control\n");
0134 
0135     return status;
0136 }
0137 
0138 void acpi_processor_set_pdc(acpi_handle handle)
0139 {
0140     struct acpi_object_list *obj_list;
0141 
0142     if (arch_has_acpi_pdc() == false)
0143         return;
0144 
0145     obj_list = acpi_processor_alloc_pdc();
0146     if (!obj_list)
0147         return;
0148 
0149     acpi_processor_eval_pdc(handle, obj_list);
0150 
0151     kfree(obj_list->pointer->buffer.pointer);
0152     kfree(obj_list->pointer);
0153     kfree(obj_list);
0154 }
0155 
0156 static acpi_status __init
0157 early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)
0158 {
0159     if (processor_physically_present(handle) == false)
0160         return AE_OK;
0161 
0162     acpi_processor_set_pdc(handle);
0163     return AE_OK;
0164 }
0165 
0166 static int __init set_no_mwait(const struct dmi_system_id *id)
0167 {
0168     pr_notice("%s detected - disabling mwait for CPU C-states\n",
0169           id->ident);
0170     boot_option_idle_override = IDLE_NOMWAIT;
0171     return 0;
0172 }
0173 
0174 static const struct dmi_system_id processor_idle_dmi_table[] __initconst = {
0175     {
0176     set_no_mwait, "Extensa 5220", {
0177     DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
0178     DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
0179     DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
0180     DMI_MATCH(DMI_BOARD_NAME, "Columbia") }, NULL},
0181     {},
0182 };
0183 
0184 static void __init processor_dmi_check(void)
0185 {
0186     /*
0187      * Check whether the system is DMI table. If yes, OSPM
0188      * should not use mwait for CPU-states.
0189      */
0190     dmi_check_system(processor_idle_dmi_table);
0191 }
0192 
0193 void __init acpi_early_processor_set_pdc(void)
0194 {
0195     processor_dmi_check();
0196 
0197     acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
0198                 ACPI_UINT32_MAX,
0199                 early_init_pdc, NULL, NULL, NULL);
0200     acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, early_init_pdc, NULL, NULL);
0201 }