Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 1 | /* |
| 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 King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 22 | |
| 23 | #include "chip.h" |
| 24 | |
| 25 | #define ACPI_DSM_PRIVACY_SCREEN_UUID "C7033113-8720-4CEB-9090-9D52B3E52D73" |
| 26 | |
| 27 | static void privacy_screen_detect_cb(void *arg) |
| 28 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 29 | struct drivers_gfx_generic_privacy_screen_config *config = arg; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 30 | |
| 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 | } |
| 38 | static void privacy_screen_get_status_cb(void *arg) |
| 39 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 40 | struct drivers_gfx_generic_privacy_screen_config *config = arg; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 41 | |
| 42 | acpigen_emit_byte(RETURN_OP); |
| 43 | acpigen_emit_namestring(config->status_function); |
| 44 | } |
| 45 | static void privacy_screen_enable_cb(void *arg) |
| 46 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 47 | struct drivers_gfx_generic_privacy_screen_config *config = arg; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 48 | |
| 49 | acpigen_emit_namestring(config->enable_function); |
| 50 | } |
| 51 | static void privacy_screen_disable_cb(void *arg) |
| 52 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 53 | struct drivers_gfx_generic_privacy_screen_config *config = arg; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 54 | |
| 55 | acpigen_emit_namestring(config->disable_function); |
| 56 | } |
| 57 | |
| 58 | static 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 | |
| 65 | static void gfx_fill_ssdt_generator(struct device *dev) |
| 66 | { |
| 67 | size_t i; |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 68 | struct drivers_gfx_generic_config *config = dev->chip_info; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 69 | |
| 70 | const char *scope = acpi_device_scope(dev); |
| 71 | |
Jacob Garber | 4519277 | 2020-02-01 13:04:11 -0700 | [diff] [blame] | 72 | if (!scope) |
| 73 | return; |
| 74 | |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 75 | 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 | |
| 104 | static const char *gfx_acpi_name(const struct device *dev) |
| 105 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 106 | struct drivers_gfx_generic_config *config = dev->chip_info; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 107 | |
| 108 | return config->name ? : "GFX0"; |
| 109 | } |
| 110 | |
| 111 | static struct device_operations gfx_ops = { |
| 112 | .acpi_name = gfx_acpi_name, |
| 113 | .acpi_fill_ssdt_generator = gfx_fill_ssdt_generator, |
| 114 | }; |
| 115 | |
| 116 | static void gfx_enable(struct device *dev) |
| 117 | { |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 118 | struct drivers_gfx_generic_config *config = dev->chip_info; |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 119 | |
| 120 | if (!config) |
| 121 | return; |
| 122 | |
| 123 | dev->ops = &gfx_ops; |
| 124 | } |
| 125 | |
Furquan Shaikh | a0b0d42 | 2020-02-21 09:57:54 -0800 | [diff] [blame] | 126 | struct chip_operations drivers_gfx_generic_ops = { |
| 127 | CHIP_NAME("Generic Graphics Device") |
Mathew King | c135b82 | 2019-10-14 10:19:15 -0600 | [diff] [blame] | 128 | .enable_dev = gfx_enable |
| 129 | }; |