blob: 8da2e64e226a70a033d3ed1416fe36e27080d345 [file] [log] [blame]
Simon Glassfcfd26e2019-12-08 17:40:14 -07001// SPDX-License-Identifier: GPL-2.0
2/*
3 * Copyright 2019 Google LLC
4 */
5
6#include <common.h>
7#include <cpu.h>
8#include <dm.h>
Simon Glass1eba1212020-09-22 12:45:21 -06009#include <log.h>
10#include <acpi/acpigen.h>
11#include <acpi/acpi_table.h>
Simon Glassfcfd26e2019-12-08 17:40:14 -070012#include <asm/cpu_common.h>
13#include <asm/cpu_x86.h>
Simon Glass1eba1212020-09-22 12:45:21 -060014#include <asm/intel_acpi.h>
15#include <asm/msr.h>
16#include <dm/acpi.h>
17
18#define CSTATE_RES(address_space, width, offset, address) \
19 { \
20 .space_id = address_space, \
21 .bit_width = width, \
22 .bit_offset = offset, \
23 .addrl = address, \
24 }
25
26static struct acpi_cstate cstate_map[] = {
27 {
28 /* C1 */
29 .ctype = 1, /* ACPI C1 */
30 .latency = 1,
31 .power = 1000,
32 .resource = {
33 .space_id = ACPI_ADDRESS_SPACE_FIXED,
34 },
35 }, {
36 .ctype = 2, /* ACPI C2 */
37 .latency = 50,
38 .power = 10,
39 .resource = {
40 .space_id = ACPI_ADDRESS_SPACE_IO,
41 .bit_width = 8,
42 .addrl = 0x415,
43 },
44 }, {
45 .ctype = 3, /* ACPI C3 */
46 .latency = 150,
47 .power = 10,
48 .resource = {
49 .space_id = ACPI_ADDRESS_SPACE_IO,
50 .bit_width = 8,
51 .addrl = 0x419,
52 },
53 },
54};
Simon Glassfcfd26e2019-12-08 17:40:14 -070055
Simon Glass791fa452020-01-26 22:06:27 -070056static int apl_get_info(const struct udevice *dev, struct cpu_info *info)
Simon Glassfcfd26e2019-12-08 17:40:14 -070057{
58 return cpu_intel_get_info(info, INTEL_BCLK_MHZ);
59}
60
Simon Glass1eba1212020-09-22 12:45:21 -060061static int acpi_cpu_fill_ssdt(const struct udevice *dev, struct acpi_ctx *ctx)
62{
63 uint core_id = dev->req_seq;
64 int cores_per_package;
65 int ret;
66
67 cores_per_package = cpu_get_cores_per_package();
68 ret = acpi_generate_cpu_header(ctx, core_id, cstate_map,
69 ARRAY_SIZE(cstate_map));
70
71 /* Generate P-state tables */
72 generate_p_state_entries(ctx, core_id, cores_per_package);
73
74 /* Generate T-state tables */
75 generate_t_state_entries(ctx, core_id, cores_per_package, NULL, 0);
76
77 acpigen_pop_len(ctx);
78
79 if (device_is_last_sibling(dev)) {
80 ret = acpi_generate_cpu_package_final(ctx, cores_per_package);
81
82 if (ret)
83 return ret;
84 }
85
86 return 0;
87}
88
89struct acpi_ops apl_cpu_acpi_ops = {
90 .fill_ssdt = acpi_cpu_fill_ssdt,
91};
92
Simon Glassfcfd26e2019-12-08 17:40:14 -070093static const struct cpu_ops cpu_x86_apl_ops = {
94 .get_desc = cpu_x86_get_desc,
95 .get_info = apl_get_info,
Wolfgang Wallner4e3dfd52020-02-25 13:19:48 +010096 .get_count = cpu_x86_get_count,
Simon Glassfcfd26e2019-12-08 17:40:14 -070097 .get_vendor = cpu_x86_get_vendor,
98};
99
100static const struct udevice_id cpu_x86_apl_ids[] = {
101 { .compatible = "intel,apl-cpu" },
102 { }
103};
104
105U_BOOT_DRIVER(cpu_x86_apl_drv) = {
106 .name = "cpu_x86_apl",
107 .id = UCLASS_CPU,
108 .of_match = cpu_x86_apl_ids,
109 .bind = cpu_x86_bind,
110 .ops = &cpu_x86_apl_ops,
Simon Glass1eba1212020-09-22 12:45:21 -0600111 ACPI_OPS_PTR(&apl_cpu_acpi_ops)
Simon Glassfcfd26e2019-12-08 17:40:14 -0700112 .flags = DM_FLAG_PRE_RELOC,
113};