1d38ceaf9SAlex Deucher /* 2d38ceaf9SAlex Deucher * Copyright 2012 Advanced Micro Devices, Inc. 3d38ceaf9SAlex Deucher * 4d38ceaf9SAlex Deucher * Permission is hereby granted, free of charge, to any person obtaining a 5d38ceaf9SAlex Deucher * copy of this software and associated documentation files (the "Software"), 6d38ceaf9SAlex Deucher * to deal in the Software without restriction, including without limitation 7d38ceaf9SAlex Deucher * the rights to use, copy, modify, merge, publish, distribute, sublicense, 8d38ceaf9SAlex Deucher * and/or sell copies of the Software, and to permit persons to whom the 9d38ceaf9SAlex Deucher * Software is furnished to do so, subject to the following conditions: 10d38ceaf9SAlex Deucher * 11d38ceaf9SAlex Deucher * The above copyright notice and this permission notice shall be included in 12d38ceaf9SAlex Deucher * all copies or substantial portions of the Software. 13d38ceaf9SAlex Deucher * 14d38ceaf9SAlex Deucher * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 15d38ceaf9SAlex Deucher * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 16d38ceaf9SAlex Deucher * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 17d38ceaf9SAlex Deucher * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR 18d38ceaf9SAlex Deucher * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, 19d38ceaf9SAlex Deucher * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR 20d38ceaf9SAlex Deucher * OTHER DEALINGS IN THE SOFTWARE. 21d38ceaf9SAlex Deucher * 22d38ceaf9SAlex Deucher */ 23d38ceaf9SAlex Deucher 24d38ceaf9SAlex Deucher #include <linux/pci.h> 25d38ceaf9SAlex Deucher #include <linux/acpi.h> 26d38ceaf9SAlex Deucher #include <linux/slab.h> 27d38ceaf9SAlex Deucher #include <linux/power_supply.h> 281b0f568dSAlex Deucher #include <linux/pm_runtime.h> 29d38ceaf9SAlex Deucher #include <acpi/video.h> 30d38ceaf9SAlex Deucher #include <drm/drmP.h> 31d38ceaf9SAlex Deucher #include <drm/drm_crtc_helper.h> 32d38ceaf9SAlex Deucher #include "amdgpu.h" 3398c65108SJean Delvare #include "amdgpu_pm.h" 3466dc0dddSRex Zhu #include "amd_acpi.h" 35d38ceaf9SAlex Deucher #include "atom.h" 36d38ceaf9SAlex Deucher 37d38ceaf9SAlex Deucher /* Call the ATIF method 38d38ceaf9SAlex Deucher */ 39d38ceaf9SAlex Deucher /** 40d38ceaf9SAlex Deucher * amdgpu_atif_call - call an ATIF method 41d38ceaf9SAlex Deucher * 42d38ceaf9SAlex Deucher * @handle: acpi handle 43d38ceaf9SAlex Deucher * @function: the ATIF function to execute 44d38ceaf9SAlex Deucher * @params: ATIF function params 45d38ceaf9SAlex Deucher * 46d38ceaf9SAlex Deucher * Executes the requested ATIF function (all asics). 47d38ceaf9SAlex Deucher * Returns a pointer to the acpi output buffer. 48d38ceaf9SAlex Deucher */ 49d38ceaf9SAlex Deucher static union acpi_object *amdgpu_atif_call(acpi_handle handle, int function, 50d38ceaf9SAlex Deucher struct acpi_buffer *params) 51d38ceaf9SAlex Deucher { 52d38ceaf9SAlex Deucher acpi_status status; 53d38ceaf9SAlex Deucher union acpi_object atif_arg_elements[2]; 54d38ceaf9SAlex Deucher struct acpi_object_list atif_arg; 55d38ceaf9SAlex Deucher struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 56d38ceaf9SAlex Deucher 57d38ceaf9SAlex Deucher atif_arg.count = 2; 58d38ceaf9SAlex Deucher atif_arg.pointer = &atif_arg_elements[0]; 59d38ceaf9SAlex Deucher 60d38ceaf9SAlex Deucher atif_arg_elements[0].type = ACPI_TYPE_INTEGER; 61d38ceaf9SAlex Deucher atif_arg_elements[0].integer.value = function; 62d38ceaf9SAlex Deucher 63d38ceaf9SAlex Deucher if (params) { 64d38ceaf9SAlex Deucher atif_arg_elements[1].type = ACPI_TYPE_BUFFER; 65d38ceaf9SAlex Deucher atif_arg_elements[1].buffer.length = params->length; 66d38ceaf9SAlex Deucher atif_arg_elements[1].buffer.pointer = params->pointer; 67d38ceaf9SAlex Deucher } else { 68d38ceaf9SAlex Deucher /* We need a second fake parameter */ 69d38ceaf9SAlex Deucher atif_arg_elements[1].type = ACPI_TYPE_INTEGER; 70d38ceaf9SAlex Deucher atif_arg_elements[1].integer.value = 0; 71d38ceaf9SAlex Deucher } 72d38ceaf9SAlex Deucher 73d38ceaf9SAlex Deucher status = acpi_evaluate_object(handle, "ATIF", &atif_arg, &buffer); 74d38ceaf9SAlex Deucher 75d38ceaf9SAlex Deucher /* Fail only if calling the method fails and ATIF is supported */ 76d38ceaf9SAlex Deucher if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { 77d38ceaf9SAlex Deucher DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n", 78d38ceaf9SAlex Deucher acpi_format_exception(status)); 79d38ceaf9SAlex Deucher kfree(buffer.pointer); 80d38ceaf9SAlex Deucher return NULL; 81d38ceaf9SAlex Deucher } 82d38ceaf9SAlex Deucher 83d38ceaf9SAlex Deucher return buffer.pointer; 84d38ceaf9SAlex Deucher } 85d38ceaf9SAlex Deucher 86d38ceaf9SAlex Deucher /** 87d38ceaf9SAlex Deucher * amdgpu_atif_parse_notification - parse supported notifications 88d38ceaf9SAlex Deucher * 89d38ceaf9SAlex Deucher * @n: supported notifications struct 90d38ceaf9SAlex Deucher * @mask: supported notifications mask from ATIF 91d38ceaf9SAlex Deucher * 92d38ceaf9SAlex Deucher * Use the supported notifications mask from ATIF function 93d38ceaf9SAlex Deucher * ATIF_FUNCTION_VERIFY_INTERFACE to determine what notifications 94d38ceaf9SAlex Deucher * are supported (all asics). 95d38ceaf9SAlex Deucher */ 96d38ceaf9SAlex Deucher static void amdgpu_atif_parse_notification(struct amdgpu_atif_notifications *n, u32 mask) 97d38ceaf9SAlex Deucher { 98d38ceaf9SAlex Deucher n->display_switch = mask & ATIF_DISPLAY_SWITCH_REQUEST_SUPPORTED; 99d38ceaf9SAlex Deucher n->expansion_mode_change = mask & ATIF_EXPANSION_MODE_CHANGE_REQUEST_SUPPORTED; 100d38ceaf9SAlex Deucher n->thermal_state = mask & ATIF_THERMAL_STATE_CHANGE_REQUEST_SUPPORTED; 101d38ceaf9SAlex Deucher n->forced_power_state = mask & ATIF_FORCED_POWER_STATE_CHANGE_REQUEST_SUPPORTED; 102d38ceaf9SAlex Deucher n->system_power_state = mask & ATIF_SYSTEM_POWER_SOURCE_CHANGE_REQUEST_SUPPORTED; 103d38ceaf9SAlex Deucher n->display_conf_change = mask & ATIF_DISPLAY_CONF_CHANGE_REQUEST_SUPPORTED; 104d38ceaf9SAlex Deucher n->px_gfx_switch = mask & ATIF_PX_GFX_SWITCH_REQUEST_SUPPORTED; 105d38ceaf9SAlex Deucher n->brightness_change = mask & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST_SUPPORTED; 106d38ceaf9SAlex Deucher n->dgpu_display_event = mask & ATIF_DGPU_DISPLAY_EVENT_SUPPORTED; 107d38ceaf9SAlex Deucher } 108d38ceaf9SAlex Deucher 109d38ceaf9SAlex Deucher /** 110d38ceaf9SAlex Deucher * amdgpu_atif_parse_functions - parse supported functions 111d38ceaf9SAlex Deucher * 112d38ceaf9SAlex Deucher * @f: supported functions struct 113d38ceaf9SAlex Deucher * @mask: supported functions mask from ATIF 114d38ceaf9SAlex Deucher * 115d38ceaf9SAlex Deucher * Use the supported functions mask from ATIF function 116d38ceaf9SAlex Deucher * ATIF_FUNCTION_VERIFY_INTERFACE to determine what functions 117d38ceaf9SAlex Deucher * are supported (all asics). 118d38ceaf9SAlex Deucher */ 119d38ceaf9SAlex Deucher static void amdgpu_atif_parse_functions(struct amdgpu_atif_functions *f, u32 mask) 120d38ceaf9SAlex Deucher { 121d38ceaf9SAlex Deucher f->system_params = mask & ATIF_GET_SYSTEM_PARAMETERS_SUPPORTED; 122d38ceaf9SAlex Deucher f->sbios_requests = mask & ATIF_GET_SYSTEM_BIOS_REQUESTS_SUPPORTED; 123d38ceaf9SAlex Deucher f->select_active_disp = mask & ATIF_SELECT_ACTIVE_DISPLAYS_SUPPORTED; 124d38ceaf9SAlex Deucher f->lid_state = mask & ATIF_GET_LID_STATE_SUPPORTED; 125d38ceaf9SAlex Deucher f->get_tv_standard = mask & ATIF_GET_TV_STANDARD_FROM_CMOS_SUPPORTED; 126d38ceaf9SAlex Deucher f->set_tv_standard = mask & ATIF_SET_TV_STANDARD_IN_CMOS_SUPPORTED; 127d38ceaf9SAlex Deucher f->get_panel_expansion_mode = mask & ATIF_GET_PANEL_EXPANSION_MODE_FROM_CMOS_SUPPORTED; 128d38ceaf9SAlex Deucher f->set_panel_expansion_mode = mask & ATIF_SET_PANEL_EXPANSION_MODE_IN_CMOS_SUPPORTED; 129d38ceaf9SAlex Deucher f->temperature_change = mask & ATIF_TEMPERATURE_CHANGE_NOTIFICATION_SUPPORTED; 130d38ceaf9SAlex Deucher f->graphics_device_types = mask & ATIF_GET_GRAPHICS_DEVICE_TYPES_SUPPORTED; 131d38ceaf9SAlex Deucher } 132d38ceaf9SAlex Deucher 133d38ceaf9SAlex Deucher /** 134d38ceaf9SAlex Deucher * amdgpu_atif_verify_interface - verify ATIF 135d38ceaf9SAlex Deucher * 136d38ceaf9SAlex Deucher * @handle: acpi handle 137d38ceaf9SAlex Deucher * @atif: amdgpu atif struct 138d38ceaf9SAlex Deucher * 139d38ceaf9SAlex Deucher * Execute the ATIF_FUNCTION_VERIFY_INTERFACE ATIF function 140d38ceaf9SAlex Deucher * to initialize ATIF and determine what features are supported 141d38ceaf9SAlex Deucher * (all asics). 142d38ceaf9SAlex Deucher * returns 0 on success, error on failure. 143d38ceaf9SAlex Deucher */ 144d38ceaf9SAlex Deucher static int amdgpu_atif_verify_interface(acpi_handle handle, 145d38ceaf9SAlex Deucher struct amdgpu_atif *atif) 146d38ceaf9SAlex Deucher { 147d38ceaf9SAlex Deucher union acpi_object *info; 148d38ceaf9SAlex Deucher struct atif_verify_interface output; 149d38ceaf9SAlex Deucher size_t size; 150d38ceaf9SAlex Deucher int err = 0; 151d38ceaf9SAlex Deucher 152d38ceaf9SAlex Deucher info = amdgpu_atif_call(handle, ATIF_FUNCTION_VERIFY_INTERFACE, NULL); 153d38ceaf9SAlex Deucher if (!info) 154d38ceaf9SAlex Deucher return -EIO; 155d38ceaf9SAlex Deucher 156d38ceaf9SAlex Deucher memset(&output, 0, sizeof(output)); 157d38ceaf9SAlex Deucher 158d38ceaf9SAlex Deucher size = *(u16 *) info->buffer.pointer; 159d38ceaf9SAlex Deucher if (size < 12) { 160d38ceaf9SAlex Deucher DRM_INFO("ATIF buffer is too small: %zu\n", size); 161d38ceaf9SAlex Deucher err = -EINVAL; 162d38ceaf9SAlex Deucher goto out; 163d38ceaf9SAlex Deucher } 164d38ceaf9SAlex Deucher size = min(sizeof(output), size); 165d38ceaf9SAlex Deucher 166d38ceaf9SAlex Deucher memcpy(&output, info->buffer.pointer, size); 167d38ceaf9SAlex Deucher 168d38ceaf9SAlex Deucher /* TODO: check version? */ 169d38ceaf9SAlex Deucher DRM_DEBUG_DRIVER("ATIF version %u\n", output.version); 170d38ceaf9SAlex Deucher 171d38ceaf9SAlex Deucher amdgpu_atif_parse_notification(&atif->notifications, output.notification_mask); 172d38ceaf9SAlex Deucher amdgpu_atif_parse_functions(&atif->functions, output.function_bits); 173d38ceaf9SAlex Deucher 174d38ceaf9SAlex Deucher out: 175d38ceaf9SAlex Deucher kfree(info); 176d38ceaf9SAlex Deucher return err; 177d38ceaf9SAlex Deucher } 178d38ceaf9SAlex Deucher 179d38ceaf9SAlex Deucher /** 180d38ceaf9SAlex Deucher * amdgpu_atif_get_notification_params - determine notify configuration 181d38ceaf9SAlex Deucher * 182d38ceaf9SAlex Deucher * @handle: acpi handle 183d38ceaf9SAlex Deucher * @n: atif notification configuration struct 184d38ceaf9SAlex Deucher * 185d38ceaf9SAlex Deucher * Execute the ATIF_FUNCTION_GET_SYSTEM_PARAMETERS ATIF function 186d38ceaf9SAlex Deucher * to determine if a notifier is used and if so which one 187d38ceaf9SAlex Deucher * (all asics). This is either Notify(VGA, 0x81) or Notify(VGA, n) 188d38ceaf9SAlex Deucher * where n is specified in the result if a notifier is used. 189d38ceaf9SAlex Deucher * Returns 0 on success, error on failure. 190d38ceaf9SAlex Deucher */ 191d38ceaf9SAlex Deucher static int amdgpu_atif_get_notification_params(acpi_handle handle, 192d38ceaf9SAlex Deucher struct amdgpu_atif_notification_cfg *n) 193d38ceaf9SAlex Deucher { 194d38ceaf9SAlex Deucher union acpi_object *info; 195d38ceaf9SAlex Deucher struct atif_system_params params; 196d38ceaf9SAlex Deucher size_t size; 197d38ceaf9SAlex Deucher int err = 0; 198d38ceaf9SAlex Deucher 199d38ceaf9SAlex Deucher info = amdgpu_atif_call(handle, ATIF_FUNCTION_GET_SYSTEM_PARAMETERS, NULL); 200d38ceaf9SAlex Deucher if (!info) { 201d38ceaf9SAlex Deucher err = -EIO; 202d38ceaf9SAlex Deucher goto out; 203d38ceaf9SAlex Deucher } 204d38ceaf9SAlex Deucher 205d38ceaf9SAlex Deucher size = *(u16 *) info->buffer.pointer; 206d38ceaf9SAlex Deucher if (size < 10) { 207d38ceaf9SAlex Deucher err = -EINVAL; 208d38ceaf9SAlex Deucher goto out; 209d38ceaf9SAlex Deucher } 210d38ceaf9SAlex Deucher 211d38ceaf9SAlex Deucher memset(¶ms, 0, sizeof(params)); 212d38ceaf9SAlex Deucher size = min(sizeof(params), size); 213d38ceaf9SAlex Deucher memcpy(¶ms, info->buffer.pointer, size); 214d38ceaf9SAlex Deucher 215d38ceaf9SAlex Deucher DRM_DEBUG_DRIVER("SYSTEM_PARAMS: mask = %#x, flags = %#x\n", 216d38ceaf9SAlex Deucher params.flags, params.valid_mask); 217d38ceaf9SAlex Deucher params.flags = params.flags & params.valid_mask; 218d38ceaf9SAlex Deucher 219d38ceaf9SAlex Deucher if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_NONE) { 220d38ceaf9SAlex Deucher n->enabled = false; 221d38ceaf9SAlex Deucher n->command_code = 0; 222d38ceaf9SAlex Deucher } else if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_81) { 223d38ceaf9SAlex Deucher n->enabled = true; 224d38ceaf9SAlex Deucher n->command_code = 0x81; 225d38ceaf9SAlex Deucher } else { 226d38ceaf9SAlex Deucher if (size < 11) { 227d38ceaf9SAlex Deucher err = -EINVAL; 228d38ceaf9SAlex Deucher goto out; 229d38ceaf9SAlex Deucher } 230d38ceaf9SAlex Deucher n->enabled = true; 231d38ceaf9SAlex Deucher n->command_code = params.command_code; 232d38ceaf9SAlex Deucher } 233d38ceaf9SAlex Deucher 234d38ceaf9SAlex Deucher out: 235d38ceaf9SAlex Deucher DRM_DEBUG_DRIVER("Notification %s, command code = %#x\n", 236d38ceaf9SAlex Deucher (n->enabled ? "enabled" : "disabled"), 237d38ceaf9SAlex Deucher n->command_code); 238d38ceaf9SAlex Deucher kfree(info); 239d38ceaf9SAlex Deucher return err; 240d38ceaf9SAlex Deucher } 241d38ceaf9SAlex Deucher 242d38ceaf9SAlex Deucher /** 243d38ceaf9SAlex Deucher * amdgpu_atif_get_sbios_requests - get requested sbios event 244d38ceaf9SAlex Deucher * 245d38ceaf9SAlex Deucher * @handle: acpi handle 246d38ceaf9SAlex Deucher * @req: atif sbios request struct 247d38ceaf9SAlex Deucher * 248d38ceaf9SAlex Deucher * Execute the ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS ATIF function 249d38ceaf9SAlex Deucher * to determine what requests the sbios is making to the driver 250d38ceaf9SAlex Deucher * (all asics). 251d38ceaf9SAlex Deucher * Returns 0 on success, error on failure. 252d38ceaf9SAlex Deucher */ 253d38ceaf9SAlex Deucher static int amdgpu_atif_get_sbios_requests(acpi_handle handle, 254d38ceaf9SAlex Deucher struct atif_sbios_requests *req) 255d38ceaf9SAlex Deucher { 256d38ceaf9SAlex Deucher union acpi_object *info; 257d38ceaf9SAlex Deucher size_t size; 258d38ceaf9SAlex Deucher int count = 0; 259d38ceaf9SAlex Deucher 260d38ceaf9SAlex Deucher info = amdgpu_atif_call(handle, ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS, NULL); 261d38ceaf9SAlex Deucher if (!info) 262d38ceaf9SAlex Deucher return -EIO; 263d38ceaf9SAlex Deucher 264d38ceaf9SAlex Deucher size = *(u16 *)info->buffer.pointer; 265d38ceaf9SAlex Deucher if (size < 0xd) { 266d38ceaf9SAlex Deucher count = -EINVAL; 267d38ceaf9SAlex Deucher goto out; 268d38ceaf9SAlex Deucher } 269d38ceaf9SAlex Deucher memset(req, 0, sizeof(*req)); 270d38ceaf9SAlex Deucher 271d38ceaf9SAlex Deucher size = min(sizeof(*req), size); 272d38ceaf9SAlex Deucher memcpy(req, info->buffer.pointer, size); 273d38ceaf9SAlex Deucher DRM_DEBUG_DRIVER("SBIOS pending requests: %#x\n", req->pending); 274d38ceaf9SAlex Deucher 275d38ceaf9SAlex Deucher count = hweight32(req->pending); 276d38ceaf9SAlex Deucher 277d38ceaf9SAlex Deucher out: 278d38ceaf9SAlex Deucher kfree(info); 279d38ceaf9SAlex Deucher return count; 280d38ceaf9SAlex Deucher } 281d38ceaf9SAlex Deucher 282d38ceaf9SAlex Deucher /** 283d38ceaf9SAlex Deucher * amdgpu_atif_handler - handle ATIF notify requests 284d38ceaf9SAlex Deucher * 285d38ceaf9SAlex Deucher * @adev: amdgpu_device pointer 286d38ceaf9SAlex Deucher * @event: atif sbios request struct 287d38ceaf9SAlex Deucher * 288d38ceaf9SAlex Deucher * Checks the acpi event and if it matches an atif event, 289d38ceaf9SAlex Deucher * handles it. 290d38ceaf9SAlex Deucher * Returns NOTIFY code 291d38ceaf9SAlex Deucher */ 292b7cecbe8SJean Delvare static int amdgpu_atif_handler(struct amdgpu_device *adev, 293d38ceaf9SAlex Deucher struct acpi_bus_event *event) 294d38ceaf9SAlex Deucher { 295d38ceaf9SAlex Deucher struct amdgpu_atif *atif = &adev->atif; 296d38ceaf9SAlex Deucher struct atif_sbios_requests req; 297d38ceaf9SAlex Deucher acpi_handle handle; 298d38ceaf9SAlex Deucher int count; 299d38ceaf9SAlex Deucher 300d38ceaf9SAlex Deucher DRM_DEBUG_DRIVER("event, device_class = %s, type = %#x\n", 301d38ceaf9SAlex Deucher event->device_class, event->type); 302d38ceaf9SAlex Deucher 303d38ceaf9SAlex Deucher if (strcmp(event->device_class, ACPI_VIDEO_CLASS) != 0) 304d38ceaf9SAlex Deucher return NOTIFY_DONE; 305d38ceaf9SAlex Deucher 306d38ceaf9SAlex Deucher if (!atif->notification_cfg.enabled || 307d38ceaf9SAlex Deucher event->type != atif->notification_cfg.command_code) 308d38ceaf9SAlex Deucher /* Not our event */ 309d38ceaf9SAlex Deucher return NOTIFY_DONE; 310d38ceaf9SAlex Deucher 311d38ceaf9SAlex Deucher /* Check pending SBIOS requests */ 312d38ceaf9SAlex Deucher handle = ACPI_HANDLE(&adev->pdev->dev); 313d38ceaf9SAlex Deucher count = amdgpu_atif_get_sbios_requests(handle, &req); 314d38ceaf9SAlex Deucher 315d38ceaf9SAlex Deucher if (count <= 0) 316d38ceaf9SAlex Deucher return NOTIFY_DONE; 317d38ceaf9SAlex Deucher 318d38ceaf9SAlex Deucher DRM_DEBUG_DRIVER("ATIF: %d pending SBIOS requests\n", count); 319d38ceaf9SAlex Deucher 320d38ceaf9SAlex Deucher if (req.pending & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST) { 321d38ceaf9SAlex Deucher struct amdgpu_encoder *enc = atif->encoder_for_bl; 322d38ceaf9SAlex Deucher 323d38ceaf9SAlex Deucher if (enc) { 324d38ceaf9SAlex Deucher struct amdgpu_encoder_atom_dig *dig = enc->enc_priv; 325d38ceaf9SAlex Deucher 326d38ceaf9SAlex Deucher DRM_DEBUG_DRIVER("Changing brightness to %d\n", 327d38ceaf9SAlex Deucher req.backlight_level); 328d38ceaf9SAlex Deucher 329d38ceaf9SAlex Deucher amdgpu_display_backlight_set_level(adev, enc, req.backlight_level); 330d38ceaf9SAlex Deucher 331d38ceaf9SAlex Deucher #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE) 332d38ceaf9SAlex Deucher backlight_force_update(dig->bl_dev, 333d38ceaf9SAlex Deucher BACKLIGHT_UPDATE_HOTKEY); 334d38ceaf9SAlex Deucher #endif 335d38ceaf9SAlex Deucher } 336d38ceaf9SAlex Deucher } 3371b0f568dSAlex Deucher if (req.pending & ATIF_DGPU_DISPLAY_EVENT) { 3381b0f568dSAlex Deucher if ((adev->flags & AMD_IS_PX) && 3391b0f568dSAlex Deucher amdgpu_atpx_dgpu_req_power_for_displays()) { 3401b0f568dSAlex Deucher pm_runtime_get_sync(adev->ddev->dev); 3411b0f568dSAlex Deucher /* Just fire off a uevent and let userspace tell us what to do */ 3421b0f568dSAlex Deucher drm_helper_hpd_irq_event(adev->ddev); 3431b0f568dSAlex Deucher pm_runtime_mark_last_busy(adev->ddev->dev); 3441b0f568dSAlex Deucher pm_runtime_put_autosuspend(adev->ddev->dev); 3451b0f568dSAlex Deucher } 3461b0f568dSAlex Deucher } 347d38ceaf9SAlex Deucher /* TODO: check other events */ 348d38ceaf9SAlex Deucher 349d38ceaf9SAlex Deucher /* We've handled the event, stop the notifier chain. The ACPI interface 350d38ceaf9SAlex Deucher * overloads ACPI_VIDEO_NOTIFY_PROBE, we don't want to send that to 351d38ceaf9SAlex Deucher * userspace if the event was generated only to signal a SBIOS 352d38ceaf9SAlex Deucher * request. 353d38ceaf9SAlex Deucher */ 354d38ceaf9SAlex Deucher return NOTIFY_BAD; 355d38ceaf9SAlex Deucher } 356d38ceaf9SAlex Deucher 357d38ceaf9SAlex Deucher /* Call the ATCS method 358d38ceaf9SAlex Deucher */ 359d38ceaf9SAlex Deucher /** 360d38ceaf9SAlex Deucher * amdgpu_atcs_call - call an ATCS method 361d38ceaf9SAlex Deucher * 362d38ceaf9SAlex Deucher * @handle: acpi handle 363d38ceaf9SAlex Deucher * @function: the ATCS function to execute 364d38ceaf9SAlex Deucher * @params: ATCS function params 365d38ceaf9SAlex Deucher * 366d38ceaf9SAlex Deucher * Executes the requested ATCS function (all asics). 367d38ceaf9SAlex Deucher * Returns a pointer to the acpi output buffer. 368d38ceaf9SAlex Deucher */ 369d38ceaf9SAlex Deucher static union acpi_object *amdgpu_atcs_call(acpi_handle handle, int function, 370d38ceaf9SAlex Deucher struct acpi_buffer *params) 371d38ceaf9SAlex Deucher { 372d38ceaf9SAlex Deucher acpi_status status; 373d38ceaf9SAlex Deucher union acpi_object atcs_arg_elements[2]; 374d38ceaf9SAlex Deucher struct acpi_object_list atcs_arg; 375d38ceaf9SAlex Deucher struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL }; 376d38ceaf9SAlex Deucher 377d38ceaf9SAlex Deucher atcs_arg.count = 2; 378d38ceaf9SAlex Deucher atcs_arg.pointer = &atcs_arg_elements[0]; 379d38ceaf9SAlex Deucher 380d38ceaf9SAlex Deucher atcs_arg_elements[0].type = ACPI_TYPE_INTEGER; 381d38ceaf9SAlex Deucher atcs_arg_elements[0].integer.value = function; 382d38ceaf9SAlex Deucher 383d38ceaf9SAlex Deucher if (params) { 384d38ceaf9SAlex Deucher atcs_arg_elements[1].type = ACPI_TYPE_BUFFER; 385d38ceaf9SAlex Deucher atcs_arg_elements[1].buffer.length = params->length; 386d38ceaf9SAlex Deucher atcs_arg_elements[1].buffer.pointer = params->pointer; 387d38ceaf9SAlex Deucher } else { 388d38ceaf9SAlex Deucher /* We need a second fake parameter */ 389d38ceaf9SAlex Deucher atcs_arg_elements[1].type = ACPI_TYPE_INTEGER; 390d38ceaf9SAlex Deucher atcs_arg_elements[1].integer.value = 0; 391d38ceaf9SAlex Deucher } 392d38ceaf9SAlex Deucher 393d38ceaf9SAlex Deucher status = acpi_evaluate_object(handle, "ATCS", &atcs_arg, &buffer); 394d38ceaf9SAlex Deucher 395d38ceaf9SAlex Deucher /* Fail only if calling the method fails and ATIF is supported */ 396d38ceaf9SAlex Deucher if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) { 397d38ceaf9SAlex Deucher DRM_DEBUG_DRIVER("failed to evaluate ATCS got %s\n", 398d38ceaf9SAlex Deucher acpi_format_exception(status)); 399d38ceaf9SAlex Deucher kfree(buffer.pointer); 400d38ceaf9SAlex Deucher return NULL; 401d38ceaf9SAlex Deucher } 402d38ceaf9SAlex Deucher 403d38ceaf9SAlex Deucher return buffer.pointer; 404d38ceaf9SAlex Deucher } 405d38ceaf9SAlex Deucher 406d38ceaf9SAlex Deucher /** 407d38ceaf9SAlex Deucher * amdgpu_atcs_parse_functions - parse supported functions 408d38ceaf9SAlex Deucher * 409d38ceaf9SAlex Deucher * @f: supported functions struct 410d38ceaf9SAlex Deucher * @mask: supported functions mask from ATCS 411d38ceaf9SAlex Deucher * 412d38ceaf9SAlex Deucher * Use the supported functions mask from ATCS function 413d38ceaf9SAlex Deucher * ATCS_FUNCTION_VERIFY_INTERFACE to determine what functions 414d38ceaf9SAlex Deucher * are supported (all asics). 415d38ceaf9SAlex Deucher */ 416d38ceaf9SAlex Deucher static void amdgpu_atcs_parse_functions(struct amdgpu_atcs_functions *f, u32 mask) 417d38ceaf9SAlex Deucher { 418d38ceaf9SAlex Deucher f->get_ext_state = mask & ATCS_GET_EXTERNAL_STATE_SUPPORTED; 419d38ceaf9SAlex Deucher f->pcie_perf_req = mask & ATCS_PCIE_PERFORMANCE_REQUEST_SUPPORTED; 420d38ceaf9SAlex Deucher f->pcie_dev_rdy = mask & ATCS_PCIE_DEVICE_READY_NOTIFICATION_SUPPORTED; 421d38ceaf9SAlex Deucher f->pcie_bus_width = mask & ATCS_SET_PCIE_BUS_WIDTH_SUPPORTED; 422d38ceaf9SAlex Deucher } 423d38ceaf9SAlex Deucher 424d38ceaf9SAlex Deucher /** 425d38ceaf9SAlex Deucher * amdgpu_atcs_verify_interface - verify ATCS 426d38ceaf9SAlex Deucher * 427d38ceaf9SAlex Deucher * @handle: acpi handle 428d38ceaf9SAlex Deucher * @atcs: amdgpu atcs struct 429d38ceaf9SAlex Deucher * 430d38ceaf9SAlex Deucher * Execute the ATCS_FUNCTION_VERIFY_INTERFACE ATCS function 431d38ceaf9SAlex Deucher * to initialize ATCS and determine what features are supported 432d38ceaf9SAlex Deucher * (all asics). 433d38ceaf9SAlex Deucher * returns 0 on success, error on failure. 434d38ceaf9SAlex Deucher */ 435d38ceaf9SAlex Deucher static int amdgpu_atcs_verify_interface(acpi_handle handle, 436d38ceaf9SAlex Deucher struct amdgpu_atcs *atcs) 437d38ceaf9SAlex Deucher { 438d38ceaf9SAlex Deucher union acpi_object *info; 439d38ceaf9SAlex Deucher struct atcs_verify_interface output; 440d38ceaf9SAlex Deucher size_t size; 441d38ceaf9SAlex Deucher int err = 0; 442d38ceaf9SAlex Deucher 443d38ceaf9SAlex Deucher info = amdgpu_atcs_call(handle, ATCS_FUNCTION_VERIFY_INTERFACE, NULL); 444d38ceaf9SAlex Deucher if (!info) 445d38ceaf9SAlex Deucher return -EIO; 446d38ceaf9SAlex Deucher 447d38ceaf9SAlex Deucher memset(&output, 0, sizeof(output)); 448d38ceaf9SAlex Deucher 449d38ceaf9SAlex Deucher size = *(u16 *) info->buffer.pointer; 450d38ceaf9SAlex Deucher if (size < 8) { 451d38ceaf9SAlex Deucher DRM_INFO("ATCS buffer is too small: %zu\n", size); 452d38ceaf9SAlex Deucher err = -EINVAL; 453d38ceaf9SAlex Deucher goto out; 454d38ceaf9SAlex Deucher } 455d38ceaf9SAlex Deucher size = min(sizeof(output), size); 456d38ceaf9SAlex Deucher 457d38ceaf9SAlex Deucher memcpy(&output, info->buffer.pointer, size); 458d38ceaf9SAlex Deucher 459d38ceaf9SAlex Deucher /* TODO: check version? */ 460d38ceaf9SAlex Deucher DRM_DEBUG_DRIVER("ATCS version %u\n", output.version); 461d38ceaf9SAlex Deucher 462d38ceaf9SAlex Deucher amdgpu_atcs_parse_functions(&atcs->functions, output.function_bits); 463d38ceaf9SAlex Deucher 464d38ceaf9SAlex Deucher out: 465d38ceaf9SAlex Deucher kfree(info); 466d38ceaf9SAlex Deucher return err; 467d38ceaf9SAlex Deucher } 468d38ceaf9SAlex Deucher 469d38ceaf9SAlex Deucher /** 470d38ceaf9SAlex Deucher * amdgpu_acpi_is_pcie_performance_request_supported 471d38ceaf9SAlex Deucher * 472d38ceaf9SAlex Deucher * @adev: amdgpu_device pointer 473d38ceaf9SAlex Deucher * 474d38ceaf9SAlex Deucher * Check if the ATCS pcie_perf_req and pcie_dev_rdy methods 475d38ceaf9SAlex Deucher * are supported (all asics). 476d38ceaf9SAlex Deucher * returns true if supported, false if not. 477d38ceaf9SAlex Deucher */ 478d38ceaf9SAlex Deucher bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev) 479d38ceaf9SAlex Deucher { 480d38ceaf9SAlex Deucher struct amdgpu_atcs *atcs = &adev->atcs; 481d38ceaf9SAlex Deucher 482d38ceaf9SAlex Deucher if (atcs->functions.pcie_perf_req && atcs->functions.pcie_dev_rdy) 483d38ceaf9SAlex Deucher return true; 484d38ceaf9SAlex Deucher 485d38ceaf9SAlex Deucher return false; 486d38ceaf9SAlex Deucher } 487d38ceaf9SAlex Deucher 488d38ceaf9SAlex Deucher /** 489d38ceaf9SAlex Deucher * amdgpu_acpi_pcie_notify_device_ready 490d38ceaf9SAlex Deucher * 491d38ceaf9SAlex Deucher * @adev: amdgpu_device pointer 492d38ceaf9SAlex Deucher * 493d38ceaf9SAlex Deucher * Executes the PCIE_DEVICE_READY_NOTIFICATION method 494d38ceaf9SAlex Deucher * (all asics). 495d38ceaf9SAlex Deucher * returns 0 on success, error on failure. 496d38ceaf9SAlex Deucher */ 497d38ceaf9SAlex Deucher int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev) 498d38ceaf9SAlex Deucher { 499d38ceaf9SAlex Deucher acpi_handle handle; 500d38ceaf9SAlex Deucher union acpi_object *info; 501d38ceaf9SAlex Deucher struct amdgpu_atcs *atcs = &adev->atcs; 502d38ceaf9SAlex Deucher 503d38ceaf9SAlex Deucher /* Get the device handle */ 504d38ceaf9SAlex Deucher handle = ACPI_HANDLE(&adev->pdev->dev); 505d38ceaf9SAlex Deucher if (!handle) 506d38ceaf9SAlex Deucher return -EINVAL; 507d38ceaf9SAlex Deucher 508d38ceaf9SAlex Deucher if (!atcs->functions.pcie_dev_rdy) 509d38ceaf9SAlex Deucher return -EINVAL; 510d38ceaf9SAlex Deucher 511d38ceaf9SAlex Deucher info = amdgpu_atcs_call(handle, ATCS_FUNCTION_PCIE_DEVICE_READY_NOTIFICATION, NULL); 512d38ceaf9SAlex Deucher if (!info) 513d38ceaf9SAlex Deucher return -EIO; 514d38ceaf9SAlex Deucher 515d38ceaf9SAlex Deucher kfree(info); 516d38ceaf9SAlex Deucher 517d38ceaf9SAlex Deucher return 0; 518d38ceaf9SAlex Deucher } 519d38ceaf9SAlex Deucher 520d38ceaf9SAlex Deucher /** 521d38ceaf9SAlex Deucher * amdgpu_acpi_pcie_performance_request 522d38ceaf9SAlex Deucher * 523d38ceaf9SAlex Deucher * @adev: amdgpu_device pointer 524d38ceaf9SAlex Deucher * @perf_req: requested perf level (pcie gen speed) 525d38ceaf9SAlex Deucher * @advertise: set advertise caps flag if set 526d38ceaf9SAlex Deucher * 527d38ceaf9SAlex Deucher * Executes the PCIE_PERFORMANCE_REQUEST method to 528d38ceaf9SAlex Deucher * change the pcie gen speed (all asics). 529d38ceaf9SAlex Deucher * returns 0 on success, error on failure. 530d38ceaf9SAlex Deucher */ 531d38ceaf9SAlex Deucher int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev, 532d38ceaf9SAlex Deucher u8 perf_req, bool advertise) 533d38ceaf9SAlex Deucher { 534d38ceaf9SAlex Deucher acpi_handle handle; 535d38ceaf9SAlex Deucher union acpi_object *info; 536d38ceaf9SAlex Deucher struct amdgpu_atcs *atcs = &adev->atcs; 537d38ceaf9SAlex Deucher struct atcs_pref_req_input atcs_input; 538d38ceaf9SAlex Deucher struct atcs_pref_req_output atcs_output; 539d38ceaf9SAlex Deucher struct acpi_buffer params; 540d38ceaf9SAlex Deucher size_t size; 541d38ceaf9SAlex Deucher u32 retry = 3; 542d38ceaf9SAlex Deucher 543*1bced75fSRex Zhu if (amdgpu_acpi_pcie_notify_device_ready(adev)) 544*1bced75fSRex Zhu return -EINVAL; 545*1bced75fSRex Zhu 546d38ceaf9SAlex Deucher /* Get the device handle */ 547d38ceaf9SAlex Deucher handle = ACPI_HANDLE(&adev->pdev->dev); 548d38ceaf9SAlex Deucher if (!handle) 549d38ceaf9SAlex Deucher return -EINVAL; 550d38ceaf9SAlex Deucher 551d38ceaf9SAlex Deucher if (!atcs->functions.pcie_perf_req) 552d38ceaf9SAlex Deucher return -EINVAL; 553d38ceaf9SAlex Deucher 554d38ceaf9SAlex Deucher atcs_input.size = sizeof(struct atcs_pref_req_input); 555d38ceaf9SAlex Deucher /* client id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */ 556d38ceaf9SAlex Deucher atcs_input.client_id = adev->pdev->devfn | (adev->pdev->bus->number << 8); 557d38ceaf9SAlex Deucher atcs_input.valid_flags_mask = ATCS_VALID_FLAGS_MASK; 558d38ceaf9SAlex Deucher atcs_input.flags = ATCS_WAIT_FOR_COMPLETION; 559d38ceaf9SAlex Deucher if (advertise) 560d38ceaf9SAlex Deucher atcs_input.flags |= ATCS_ADVERTISE_CAPS; 561d38ceaf9SAlex Deucher atcs_input.req_type = ATCS_PCIE_LINK_SPEED; 562d38ceaf9SAlex Deucher atcs_input.perf_req = perf_req; 563d38ceaf9SAlex Deucher 564d38ceaf9SAlex Deucher params.length = sizeof(struct atcs_pref_req_input); 565d38ceaf9SAlex Deucher params.pointer = &atcs_input; 566d38ceaf9SAlex Deucher 567d38ceaf9SAlex Deucher while (retry--) { 568d38ceaf9SAlex Deucher info = amdgpu_atcs_call(handle, ATCS_FUNCTION_PCIE_PERFORMANCE_REQUEST, ¶ms); 569d38ceaf9SAlex Deucher if (!info) 570d38ceaf9SAlex Deucher return -EIO; 571d38ceaf9SAlex Deucher 572d38ceaf9SAlex Deucher memset(&atcs_output, 0, sizeof(atcs_output)); 573d38ceaf9SAlex Deucher 574d38ceaf9SAlex Deucher size = *(u16 *) info->buffer.pointer; 575d38ceaf9SAlex Deucher if (size < 3) { 576d38ceaf9SAlex Deucher DRM_INFO("ATCS buffer is too small: %zu\n", size); 577d38ceaf9SAlex Deucher kfree(info); 578d38ceaf9SAlex Deucher return -EINVAL; 579d38ceaf9SAlex Deucher } 580d38ceaf9SAlex Deucher size = min(sizeof(atcs_output), size); 581d38ceaf9SAlex Deucher 582d38ceaf9SAlex Deucher memcpy(&atcs_output, info->buffer.pointer, size); 583d38ceaf9SAlex Deucher 584d38ceaf9SAlex Deucher kfree(info); 585d38ceaf9SAlex Deucher 586d38ceaf9SAlex Deucher switch (atcs_output.ret_val) { 587d38ceaf9SAlex Deucher case ATCS_REQUEST_REFUSED: 588d38ceaf9SAlex Deucher default: 589d38ceaf9SAlex Deucher return -EINVAL; 590d38ceaf9SAlex Deucher case ATCS_REQUEST_COMPLETE: 591d38ceaf9SAlex Deucher return 0; 592d38ceaf9SAlex Deucher case ATCS_REQUEST_IN_PROGRESS: 593d38ceaf9SAlex Deucher udelay(10); 594d38ceaf9SAlex Deucher break; 595d38ceaf9SAlex Deucher } 596d38ceaf9SAlex Deucher } 597d38ceaf9SAlex Deucher 598d38ceaf9SAlex Deucher return 0; 599d38ceaf9SAlex Deucher } 600d38ceaf9SAlex Deucher 601d38ceaf9SAlex Deucher /** 602d38ceaf9SAlex Deucher * amdgpu_acpi_event - handle notify events 603d38ceaf9SAlex Deucher * 604d38ceaf9SAlex Deucher * @nb: notifier block 605d38ceaf9SAlex Deucher * @val: val 606d38ceaf9SAlex Deucher * @data: acpi event 607d38ceaf9SAlex Deucher * 608d38ceaf9SAlex Deucher * Calls relevant amdgpu functions in response to various 609d38ceaf9SAlex Deucher * acpi events. 610d38ceaf9SAlex Deucher * Returns NOTIFY code 611d38ceaf9SAlex Deucher */ 612d38ceaf9SAlex Deucher static int amdgpu_acpi_event(struct notifier_block *nb, 613d38ceaf9SAlex Deucher unsigned long val, 614d38ceaf9SAlex Deucher void *data) 615d38ceaf9SAlex Deucher { 616d38ceaf9SAlex Deucher struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, acpi_nb); 617d38ceaf9SAlex Deucher struct acpi_bus_event *entry = (struct acpi_bus_event *)data; 618d38ceaf9SAlex Deucher 619d38ceaf9SAlex Deucher if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) { 620d38ceaf9SAlex Deucher if (power_supply_is_system_supplied() > 0) 621d38ceaf9SAlex Deucher DRM_DEBUG_DRIVER("pm: AC\n"); 622d38ceaf9SAlex Deucher else 623d38ceaf9SAlex Deucher DRM_DEBUG_DRIVER("pm: DC\n"); 624d38ceaf9SAlex Deucher 625d38ceaf9SAlex Deucher amdgpu_pm_acpi_event_handler(adev); 626d38ceaf9SAlex Deucher } 627d38ceaf9SAlex Deucher 628d38ceaf9SAlex Deucher /* Check for pending SBIOS requests */ 629d38ceaf9SAlex Deucher return amdgpu_atif_handler(adev, entry); 630d38ceaf9SAlex Deucher } 631d38ceaf9SAlex Deucher 632d38ceaf9SAlex Deucher /* Call all ACPI methods here */ 633d38ceaf9SAlex Deucher /** 634d38ceaf9SAlex Deucher * amdgpu_acpi_init - init driver acpi support 635d38ceaf9SAlex Deucher * 636d38ceaf9SAlex Deucher * @adev: amdgpu_device pointer 637d38ceaf9SAlex Deucher * 638d38ceaf9SAlex Deucher * Verifies the AMD ACPI interfaces and registers with the acpi 639d38ceaf9SAlex Deucher * notifier chain (all asics). 640d38ceaf9SAlex Deucher * Returns 0 on success, error on failure. 641d38ceaf9SAlex Deucher */ 642d38ceaf9SAlex Deucher int amdgpu_acpi_init(struct amdgpu_device *adev) 643d38ceaf9SAlex Deucher { 644d38ceaf9SAlex Deucher acpi_handle handle; 645d38ceaf9SAlex Deucher struct amdgpu_atif *atif = &adev->atif; 646d38ceaf9SAlex Deucher struct amdgpu_atcs *atcs = &adev->atcs; 647d38ceaf9SAlex Deucher int ret; 648d38ceaf9SAlex Deucher 649d38ceaf9SAlex Deucher /* Get the device handle */ 650d38ceaf9SAlex Deucher handle = ACPI_HANDLE(&adev->pdev->dev); 651d38ceaf9SAlex Deucher 652d38ceaf9SAlex Deucher if (!adev->bios || !handle) 653d38ceaf9SAlex Deucher return 0; 654d38ceaf9SAlex Deucher 655d38ceaf9SAlex Deucher /* Call the ATCS method */ 656d38ceaf9SAlex Deucher ret = amdgpu_atcs_verify_interface(handle, atcs); 657d38ceaf9SAlex Deucher if (ret) { 658d38ceaf9SAlex Deucher DRM_DEBUG_DRIVER("Call to ATCS verify_interface failed: %d\n", ret); 659d38ceaf9SAlex Deucher } 660d38ceaf9SAlex Deucher 661d38ceaf9SAlex Deucher /* Call the ATIF method */ 662d38ceaf9SAlex Deucher ret = amdgpu_atif_verify_interface(handle, atif); 663d38ceaf9SAlex Deucher if (ret) { 664d38ceaf9SAlex Deucher DRM_DEBUG_DRIVER("Call to ATIF verify_interface failed: %d\n", ret); 665d38ceaf9SAlex Deucher goto out; 666d38ceaf9SAlex Deucher } 667d38ceaf9SAlex Deucher 668d38ceaf9SAlex Deucher if (atif->notifications.brightness_change) { 669d38ceaf9SAlex Deucher struct drm_encoder *tmp; 670d38ceaf9SAlex Deucher 671d38ceaf9SAlex Deucher /* Find the encoder controlling the brightness */ 672d38ceaf9SAlex Deucher list_for_each_entry(tmp, &adev->ddev->mode_config.encoder_list, 673d38ceaf9SAlex Deucher head) { 674d38ceaf9SAlex Deucher struct amdgpu_encoder *enc = to_amdgpu_encoder(tmp); 675d38ceaf9SAlex Deucher 676d38ceaf9SAlex Deucher if ((enc->devices & (ATOM_DEVICE_LCD_SUPPORT)) && 677d38ceaf9SAlex Deucher enc->enc_priv) { 678d38ceaf9SAlex Deucher struct amdgpu_encoder_atom_dig *dig = enc->enc_priv; 679d38ceaf9SAlex Deucher if (dig->bl_dev) { 680d38ceaf9SAlex Deucher atif->encoder_for_bl = enc; 681d38ceaf9SAlex Deucher break; 682d38ceaf9SAlex Deucher } 683d38ceaf9SAlex Deucher } 684d38ceaf9SAlex Deucher } 685d38ceaf9SAlex Deucher } 686d38ceaf9SAlex Deucher 687d38ceaf9SAlex Deucher if (atif->functions.sbios_requests && !atif->functions.system_params) { 688d38ceaf9SAlex Deucher /* XXX check this workraround, if sbios request function is 689d38ceaf9SAlex Deucher * present we have to see how it's configured in the system 690d38ceaf9SAlex Deucher * params 691d38ceaf9SAlex Deucher */ 692d38ceaf9SAlex Deucher atif->functions.system_params = true; 693d38ceaf9SAlex Deucher } 694d38ceaf9SAlex Deucher 695d38ceaf9SAlex Deucher if (atif->functions.system_params) { 696d38ceaf9SAlex Deucher ret = amdgpu_atif_get_notification_params(handle, 697d38ceaf9SAlex Deucher &atif->notification_cfg); 698d38ceaf9SAlex Deucher if (ret) { 699d38ceaf9SAlex Deucher DRM_DEBUG_DRIVER("Call to GET_SYSTEM_PARAMS failed: %d\n", 700d38ceaf9SAlex Deucher ret); 701d38ceaf9SAlex Deucher /* Disable notification */ 702d38ceaf9SAlex Deucher atif->notification_cfg.enabled = false; 703d38ceaf9SAlex Deucher } 704d38ceaf9SAlex Deucher } 705d38ceaf9SAlex Deucher 706d38ceaf9SAlex Deucher out: 707d38ceaf9SAlex Deucher adev->acpi_nb.notifier_call = amdgpu_acpi_event; 708d38ceaf9SAlex Deucher register_acpi_notifier(&adev->acpi_nb); 709d38ceaf9SAlex Deucher 710d38ceaf9SAlex Deucher return ret; 711d38ceaf9SAlex Deucher } 712d38ceaf9SAlex Deucher 713d38ceaf9SAlex Deucher /** 714d38ceaf9SAlex Deucher * amdgpu_acpi_fini - tear down driver acpi support 715d38ceaf9SAlex Deucher * 716d38ceaf9SAlex Deucher * @adev: amdgpu_device pointer 717d38ceaf9SAlex Deucher * 718d38ceaf9SAlex Deucher * Unregisters with the acpi notifier chain (all asics). 719d38ceaf9SAlex Deucher */ 720d38ceaf9SAlex Deucher void amdgpu_acpi_fini(struct amdgpu_device *adev) 721d38ceaf9SAlex Deucher { 722d38ceaf9SAlex Deucher unregister_acpi_notifier(&adev->acpi_nb); 723d38ceaf9SAlex Deucher } 724