blob: 8488040d3075e31a3b216f0aff5ad30b9102a47d [file] [log] [blame]
Mathew Kingc135b822019-10-14 10:19:15 -06001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2019 Google LLC
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <arch/acpigen.h>
17#include <console/console.h>
18#include <device/device.h>
19#include <device/pci.h>
20#include <device/pci_ids.h>
21#include <stdint.h>
Mathew Kingc135b822019-10-14 10:19:15 -060022
23#include "chip.h"
24
25#define ACPI_DSM_PRIVACY_SCREEN_UUID "C7033113-8720-4CEB-9090-9D52B3E52D73"
26
27static void privacy_screen_detect_cb(void *arg)
28{
Furquan Shaikha0b0d422020-02-21 09:57:54 -080029 struct drivers_gfx_generic_privacy_screen_config *config = arg;
Mathew Kingc135b822019-10-14 10:19:15 -060030
31 acpigen_write_store();
32 acpigen_emit_namestring(config->detect_function);
33 acpigen_emit_byte(LOCAL2_OP);
34 acpigen_write_if_lequal_op_int(LOCAL2_OP, 1);
35 acpigen_write_return_singleton_buffer(0xF);
36 acpigen_pop_len();
37}
38static void privacy_screen_get_status_cb(void *arg)
39{
Furquan Shaikha0b0d422020-02-21 09:57:54 -080040 struct drivers_gfx_generic_privacy_screen_config *config = arg;
Mathew Kingc135b822019-10-14 10:19:15 -060041
42 acpigen_emit_byte(RETURN_OP);
43 acpigen_emit_namestring(config->status_function);
44}
45static void privacy_screen_enable_cb(void *arg)
46{
Furquan Shaikha0b0d422020-02-21 09:57:54 -080047 struct drivers_gfx_generic_privacy_screen_config *config = arg;
Mathew Kingc135b822019-10-14 10:19:15 -060048
49 acpigen_emit_namestring(config->enable_function);
50}
51static void privacy_screen_disable_cb(void *arg)
52{
Furquan Shaikha0b0d422020-02-21 09:57:54 -080053 struct drivers_gfx_generic_privacy_screen_config *config = arg;
Mathew Kingc135b822019-10-14 10:19:15 -060054
55 acpigen_emit_namestring(config->disable_function);
56}
57
58static void (*privacy_screen_callbacks[])(void *) = {
59 privacy_screen_detect_cb,
60 privacy_screen_get_status_cb,
61 privacy_screen_enable_cb,
62 privacy_screen_disable_cb,
63};
64
65static void gfx_fill_ssdt_generator(struct device *dev)
66{
67 size_t i;
Furquan Shaikha0b0d422020-02-21 09:57:54 -080068 struct drivers_gfx_generic_config *config = dev->chip_info;
Mathew Kingc135b822019-10-14 10:19:15 -060069
70 const char *scope = acpi_device_scope(dev);
71
Jacob Garber45192772020-02-01 13:04:11 -070072 if (!scope)
73 return;
74
Mathew Kingc135b822019-10-14 10:19:15 -060075 acpigen_write_scope(scope);
76
77 /* Method (_DOD, 0) */
78 acpigen_write_method("_DOD", 0);
79 acpigen_emit_byte(RETURN_OP);
80 acpigen_write_package(config->device_count);
81 for (i = 0; i < config->device_count; i++)
82 acpigen_write_dword(config->device[i].addr);
83 acpigen_pop_len(); /* End Package. */
84 acpigen_pop_len(); /* End Method. */
85
86 for (i = 0; i < config->device_count; i++) {
87 acpigen_write_device(config->device[i].name);
88
89 acpigen_write_name_integer("_ADR", config->device[i].addr);
90 acpigen_write_name_integer("_STA", 0xF);
91
92 if (config->device[i].privacy.enabled) {
93 acpigen_write_dsm(ACPI_DSM_PRIVACY_SCREEN_UUID,
94 privacy_screen_callbacks,
95 ARRAY_SIZE(privacy_screen_callbacks),
96 &config->device[i].privacy);
97 }
98
99 acpigen_pop_len(); /* Device */
100 }
101 acpigen_pop_len(); /* Scope */
102}
103
104static const char *gfx_acpi_name(const struct device *dev)
105{
Furquan Shaikha0b0d422020-02-21 09:57:54 -0800106 struct drivers_gfx_generic_config *config = dev->chip_info;
Mathew Kingc135b822019-10-14 10:19:15 -0600107
108 return config->name ? : "GFX0";
109}
110
111static struct device_operations gfx_ops = {
112 .acpi_name = gfx_acpi_name,
113 .acpi_fill_ssdt_generator = gfx_fill_ssdt_generator,
114};
115
116static void gfx_enable(struct device *dev)
117{
Furquan Shaikha0b0d422020-02-21 09:57:54 -0800118 struct drivers_gfx_generic_config *config = dev->chip_info;
Mathew Kingc135b822019-10-14 10:19:15 -0600119
120 if (!config)
121 return;
122
123 dev->ops = &gfx_ops;
124}
125
Furquan Shaikha0b0d422020-02-21 09:57:54 -0800126struct chip_operations drivers_gfx_generic_ops = {
127 CHIP_NAME("Generic Graphics Device")
Mathew Kingc135b822019-10-14 10:19:15 -0600128 .enable_dev = gfx_enable
129};