coreboot
coreboot is an Open Source project aimed at replacing the proprietary BIOS found in most computers.
thermal_zone.c
Go to the documentation of this file.
1 /* SPDX-License-Identifier: GPL-2.0-only */
2 
3 #include <acpi/acpigen.h>
4 #include <assert.h>
6 #include <console/console.h>
7 #include <device/device.h>
8 #include <stdlib.h>
9 #include <string.h>
10 
11 #include "chip.h"
12 
13 #define TZ_DEVICE_PATH "\\_TZ"
14 /* These defaults should be good enough for most systems */
15 #define DEFAULT_TC1 2
16 #define DEFAULT_TC2 5
17 #define DEFAULT_TSP 10
18 
19 #define CELSIUS_TO_DECI_KELVIN(temp_c) ((temp_c) * 10 + 2731)
20 #define SECONDS_TO_DECI_SECONDS(s) ((s) * 10)
21 
22 static const char *thermal_zone_acpi_name(const struct device *dev)
23 {
24  char *name;
25 
26  if (dev->path.type != DEVICE_PATH_GENERIC)
27  return NULL;
28 
31 
32  return name;
33 }
34 
35 static void thermal_zone_fill_ssdt(const struct device *dev)
36 {
38  const char *scope;
39  const char *name;
40 
42 
43  if (config->use_acpi1_thermal_zone_scope)
44  scope = TZ_DEVICE_PATH;
45  else
46  scope = acpi_device_scope(dev);
47 
48  name = acpi_device_name(dev);
49 
50  assert(name);
51  assert(scope);
52 
53  if (!config->temperature_controller) {
54  printk(BIOS_ERR, "%s: missing temperature_controller\n", dev_path(dev));
55  return;
56  }
57 
58  printk(BIOS_INFO, "%s.%s: %s at %s\n", scope, name, dev->chip_ops->name, dev_path(dev));
59 
60  acpigen_write_scope(scope);
62 
63  if (config->description)
64  acpigen_write_name_string("_STR", config->description);
65 
66  if (config->polling_period)
68  "_TZP", SECONDS_TO_DECI_SECONDS(config->polling_period));
69 
70  if (config->critical_temperature)
72  "_CRT", CELSIUS_TO_DECI_KELVIN(config->critical_temperature));
73 
74  if (config->hibernate_temperature)
76  "_HOT", CELSIUS_TO_DECI_KELVIN(config->hibernate_temperature));
77 
78  if (config->passive_config.temperature) {
80  "_PSV", CELSIUS_TO_DECI_KELVIN(config->passive_config.temperature));
81 
82  /*
83  * The linux kernel currently has an artificial limit of 10 on the number of
84  * references that can be returned in a list. If we don't respect this limit,
85  * then the passive threshold won't work.
86  *
87  * See https://source.chromium.org/chromiumos/chromiumos/codesearch/+/main:src/third_party/kernel/v5.10/include/acpi/acpi_bus.h;l=19
88  */
90 
91  acpigen_write_name_integer("_TC1", config->passive_config.time_constant_1
92  ?: DEFAULT_TC1);
93  acpigen_write_name_integer("_TC2", config->passive_config.time_constant_2
94  ?: DEFAULT_TC2);
96  "_TSP",
97  SECONDS_TO_DECI_SECONDS(config->passive_config.time_sampling_period
98  ?: DEFAULT_TSP));
99  }
100 
101  /*
102  * Method (_TMP) {
103  * Return (<path>.TMP(<sensor_id>))
104  * }
105  */
108  acpigen_emit_namestring(acpi_device_path_join(config->temperature_controller, "TMP"));
109  acpigen_write_integer(config->sensor_id);
111 
114 }
115 
116 static struct device_operations thermal_zone_ops = {
118  .set_resources = noop_set_resources,
119  .acpi_name = thermal_zone_acpi_name,
120  .acpi_fill_ssdt = thermal_zone_fill_ssdt,
121 };
122 
123 static void thermal_zone_enable_dev(struct device *dev)
124 {
125  dev->ops = &thermal_zone_ops;
126 }
127 
129  CHIP_NAME("ACPI Thermal Zone")
130  .enable_dev = thermal_zone_enable_dev,
131 };
const char * acpi_device_path_join(const struct device *dev, const char *name)
Definition: device.c:172
const char * acpi_device_name(const struct device *dev)
Definition: device.c:49
const char * acpi_device_scope(const struct device *dev)
Definition: device.c:158
void acpigen_emit_namestring(const char *namepath)
Definition: acpigen.c:275
void acpigen_write_integer(uint64_t data)
Definition: acpigen.c:136
void acpigen_write_scope(const char *name)
Definition: acpigen.c:326
void acpigen_write_method_serialized(const char *name, int nargs)
Definition: acpigen.c:764
void acpigen_write_name_integer(const char *name, uint64_t val)
Definition: acpigen.c:170
void acpigen_write_processor_package(const char *const name, const unsigned int first_core, const unsigned int core_count)
Definition: acpigen.c:409
void acpigen_emit_byte(unsigned char b)
Definition: acpigen.c:61
void acpigen_write_thermal_zone(const char *name)
Definition: acpigen.c:776
void acpigen_write_name_string(const char *name, const char *string)
Definition: acpigen.c:176
const char * name
Definition: mmu.c:92
#define assert(statement)
Definition: assert.h:74
#define MIN(a, b)
Definition: helpers.h:37
#define printk(level,...)
Definition: stdlib.h:16
const char * dev_path(const struct device *dev)
Definition: device_util.c:149
int dev_count_cpu(void)
Definition: device_util.c:907
#define ACPI_NAME_BUFFER_SIZE
Definition: acpi.h:59
@ RETURN_OP
Definition: acpigen.h:146
void acpigen_write_method_end(void)
Definition: acpigen.h:349
void acpigen_write_scope_end(void)
Definition: acpigen.h:343
void acpigen_write_thermal_zone_end(void)
Definition: acpigen.h:359
#define CHIP_NAME(X)
Definition: device.h:32
static void noop_read_resources(struct device *dev)
Standard device operations function pointers shims.
Definition: device.h:73
static void noop_set_resources(struct device *dev)
Definition: device.h:74
static DEVTREE_CONST void * config_of(const struct device *dev)
Definition: device.h:382
void * malloc(size_t size)
Definition: malloc.c:53
#define BIOS_INFO
BIOS_INFO - Expected events.
Definition: loglevel.h:113
#define BIOS_ERR
BIOS_ERR - System in incomplete state.
Definition: loglevel.h:72
enum board_config config
Definition: memory.c:448
@ DEVICE_PATH_GENERIC
Definition: path.h:18
#define NULL
Definition: stddef.h:19
const char * name
Definition: device.h:29
void(* read_resources)(struct device *dev)
Definition: device.h:39
struct generic_path generic
Definition: path.h:125
enum device_path_type type
Definition: path.h:114
Definition: device.h:107
struct chip_operations * chip_ops
Definition: device.h:144
struct device_path path
Definition: device.h:115
struct device_operations * ops
Definition: device.h:143
unsigned int id
Definition: path.h:96
static void thermal_zone_enable_dev(struct device *dev)
Definition: thermal_zone.c:123
#define DEFAULT_TSP
Definition: thermal_zone.c:17
static struct device_operations thermal_zone_ops
Definition: thermal_zone.c:116
struct chip_operations drivers_acpi_thermal_zone_ops
Definition: thermal_zone.c:128
#define CELSIUS_TO_DECI_KELVIN(temp_c)
Definition: thermal_zone.c:19
#define DEFAULT_TC2
Definition: thermal_zone.c:16
static const char * thermal_zone_acpi_name(const struct device *dev)
Definition: thermal_zone.c:22
#define DEFAULT_TC1
Definition: thermal_zone.c:15
#define TZ_DEVICE_PATH
Definition: thermal_zone.c:13
static void thermal_zone_fill_ssdt(const struct device *dev)
Definition: thermal_zone.c:35
#define SECONDS_TO_DECI_SECONDS(s)
Definition: thermal_zone.c:20
int snprintf(char *buf, size_t size, const char *fmt,...)
Note: This file is only for POSIX compatibility, and is meant to be chain-included via string....
Definition: vsprintf.c:35