1 // SPDX-License-Identifier: GPL-2.0
3 * Copyright (C) 2005 Intel Corporation
4 * Copyright (C) 2009 Hewlett-Packard Development Company, L.P.
6 * Venkatesh Pallipadi <venkatesh.pallipadi@intel.com>
7 * - Added _PDC for platforms with Intel CPUs
10 #define pr_fmt(fmt) "ACPI: " fmt
12 #include <linux/dmi.h>
13 #include <linux/slab.h>
14 #include <linux/acpi.h>
15 #include <acpi/processor.h>
19 static bool __init processor_physically_present(acpi_handle handle)
24 acpi_object_type acpi_type;
25 unsigned long long tmp;
26 union acpi_object object = { 0 };
27 struct acpi_buffer buffer = { sizeof(union acpi_object), &object };
29 status = acpi_get_type(handle, &acpi_type);
30 if (ACPI_FAILURE(status))
34 case ACPI_TYPE_PROCESSOR:
35 status = acpi_evaluate_object(handle, NULL, NULL, &buffer);
36 if (ACPI_FAILURE(status))
38 acpi_id = object.processor.proc_id;
40 case ACPI_TYPE_DEVICE:
41 status = acpi_evaluate_integer(handle, "_UID", NULL, &tmp);
42 if (ACPI_FAILURE(status))
50 type = (acpi_type == ACPI_TYPE_DEVICE) ? 1 : 0;
51 cpuid = acpi_get_cpuid(handle, type, acpi_id);
53 return !invalid_logical_cpuid(cpuid);
56 static void acpi_set_pdc_bits(u32 *buf)
58 buf[0] = ACPI_PDC_REVISION_ID;
61 /* Enable coordination with firmware's _TSD info */
62 buf[2] = ACPI_PDC_SMP_T_SWCOORD;
64 /* Twiddle arch-specific bits needed for _PDC */
65 arch_acpi_set_pdc_bits(buf);
68 static struct acpi_object_list *acpi_processor_alloc_pdc(void)
70 struct acpi_object_list *obj_list;
71 union acpi_object *obj;
74 /* allocate and initialize pdc. It will be used later. */
75 obj_list = kmalloc(sizeof(struct acpi_object_list), GFP_KERNEL);
79 obj = kmalloc(sizeof(union acpi_object), GFP_KERNEL);
85 buf = kmalloc(12, GFP_KERNEL);
92 acpi_set_pdc_bits(buf);
94 obj->type = ACPI_TYPE_BUFFER;
95 obj->buffer.length = 12;
96 obj->buffer.pointer = (u8 *) buf;
98 obj_list->pointer = obj;
102 pr_err("Memory allocation error\n");
107 * _PDC is required for a BIOS-OS handshake for most of the newer
108 * ACPI processor features.
111 acpi_processor_eval_pdc(acpi_handle handle, struct acpi_object_list *pdc_in)
113 acpi_status status = AE_OK;
115 if (boot_option_idle_override == IDLE_NOMWAIT) {
117 * If mwait is disabled for CPU C-states, the C2C3_FFH access
118 * mode will be disabled in the parameter of _PDC object.
119 * Of course C1_FFH access mode will also be disabled.
121 union acpi_object *obj;
124 obj = pdc_in->pointer;
125 buffer = (u32 *)(obj->buffer.pointer);
126 buffer[2] &= ~(ACPI_PDC_C_C2C3_FFH | ACPI_PDC_C_C1_FFH);
129 status = acpi_evaluate_object(handle, "_PDC", pdc_in, NULL);
131 if (ACPI_FAILURE(status))
132 acpi_handle_debug(handle,
133 "Could not evaluate _PDC, using legacy perf control\n");
138 void acpi_processor_set_pdc(acpi_handle handle)
140 struct acpi_object_list *obj_list;
142 if (arch_has_acpi_pdc() == false)
145 obj_list = acpi_processor_alloc_pdc();
149 acpi_processor_eval_pdc(handle, obj_list);
151 kfree(obj_list->pointer->buffer.pointer);
152 kfree(obj_list->pointer);
156 static acpi_status __init
157 early_init_pdc(acpi_handle handle, u32 lvl, void *context, void **rv)
159 if (processor_physically_present(handle) == false)
162 acpi_processor_set_pdc(handle);
166 static int __init set_no_mwait(const struct dmi_system_id *id)
168 pr_notice("%s detected - disabling mwait for CPU C-states\n",
170 boot_option_idle_override = IDLE_NOMWAIT;
174 static const struct dmi_system_id processor_idle_dmi_table[] __initconst = {
176 set_no_mwait, "Extensa 5220", {
177 DMI_MATCH(DMI_BIOS_VENDOR, "Phoenix Technologies LTD"),
178 DMI_MATCH(DMI_SYS_VENDOR, "Acer"),
179 DMI_MATCH(DMI_PRODUCT_VERSION, "0100"),
180 DMI_MATCH(DMI_BOARD_NAME, "Columbia") }, NULL},
184 static void __init processor_dmi_check(void)
187 * Check whether the system is DMI table. If yes, OSPM
188 * should not use mwait for CPU-states.
190 dmi_check_system(processor_idle_dmi_table);
193 void __init acpi_early_processor_set_pdc(void)
195 processor_dmi_check();
197 acpi_walk_namespace(ACPI_TYPE_PROCESSOR, ACPI_ROOT_OBJECT,
199 early_init_pdc, NULL, NULL, NULL);
200 acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID, early_init_pdc, NULL, NULL);