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/slab.h>
13 #include <linux/acpi.h>
14 #include <acpi/processor.h>
18 static void acpi_set_pdc_bits(u32
*buf
)
20 buf
[0] = ACPI_PDC_REVISION_ID
;
24 /* Twiddle arch-specific bits needed for _PDC */
25 arch_acpi_set_proc_cap_bits(&buf
[2]);
28 static struct acpi_object_list
*acpi_processor_alloc_pdc(void)
30 struct acpi_object_list
*obj_list
;
31 union acpi_object
*obj
;
34 /* allocate and initialize pdc. It will be used later. */
35 obj_list
= kmalloc(sizeof(struct acpi_object_list
), GFP_KERNEL
);
39 obj
= kmalloc(sizeof(union acpi_object
), GFP_KERNEL
);
45 buf
= kmalloc(12, GFP_KERNEL
);
52 acpi_set_pdc_bits(buf
);
54 obj
->type
= ACPI_TYPE_BUFFER
;
55 obj
->buffer
.length
= 12;
56 obj
->buffer
.pointer
= (u8
*) buf
;
58 obj_list
->pointer
= obj
;
62 pr_err("Memory allocation error\n");
67 * _PDC is required for a BIOS-OS handshake for most of the newer
68 * ACPI processor features.
71 acpi_processor_eval_pdc(acpi_handle handle
, struct acpi_object_list
*pdc_in
)
73 acpi_status status
= AE_OK
;
75 status
= acpi_evaluate_object(handle
, "_PDC", pdc_in
, NULL
);
77 if (ACPI_FAILURE(status
))
78 acpi_handle_debug(handle
,
79 "Could not evaluate _PDC, using legacy perf control\n");
84 void acpi_processor_set_pdc(acpi_handle handle
)
86 struct acpi_object_list
*obj_list
;
88 if (arch_has_acpi_pdc() == false)
91 obj_list
= acpi_processor_alloc_pdc();
95 acpi_processor_eval_pdc(handle
, obj_list
);
97 kfree(obj_list
->pointer
->buffer
.pointer
);
98 kfree(obj_list
->pointer
);
102 static acpi_status __init
103 early_init_pdc(acpi_handle handle
, u32 lvl
, void *context
, void **rv
)
105 if (processor_physically_present(handle
) == false)
108 acpi_processor_set_pdc(handle
);
112 void __init
acpi_early_processor_set_pdc(void)
114 acpi_proc_quirk_mwait_check();
116 acpi_walk_namespace(ACPI_TYPE_PROCESSOR
, ACPI_ROOT_OBJECT
,
118 early_init_pdc
, NULL
, NULL
, NULL
);
119 acpi_get_devices(ACPI_PROCESSOR_DEVICE_HID
, early_init_pdc
, NULL
, NULL
);