2 * Copyright 2012 Advanced Micro Devices, Inc.
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
24 #include <linux/pci.h>
25 #include <linux/acpi.h>
26 #include <linux/slab.h>
27 #include <linux/power_supply.h>
28 #include <linux/pm_runtime.h>
29 #include <acpi/video.h>
30 #include <acpi/actbl.h>
32 #include <drm/drm_crtc_helper.h>
34 #include "amdgpu_pm.h"
35 #include "amdgpu_display.h"
39 struct amdgpu_atif_notification_cfg {
44 struct amdgpu_atif_notifications {
46 bool forced_power_state;
47 bool system_power_state;
48 bool brightness_change;
49 bool dgpu_display_event;
50 bool gpu_package_power_limit;
53 struct amdgpu_atif_functions {
56 bool temperature_change;
57 bool query_backlight_transfer_characteristics;
59 bool external_gpu_information;
65 struct amdgpu_atif_notifications notifications;
66 struct amdgpu_atif_functions functions;
67 struct amdgpu_atif_notification_cfg notification_cfg;
68 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
69 struct backlight_device *bd;
71 struct amdgpu_dm_backlight_caps backlight_caps;
74 struct amdgpu_atcs_functions {
84 struct amdgpu_atcs_functions functions;
87 static struct amdgpu_acpi_priv {
88 struct amdgpu_atif atif;
89 struct amdgpu_atcs atcs;
92 /* Call the ATIF method
95 * amdgpu_atif_call - call an ATIF method
97 * @atif: atif structure
98 * @function: the ATIF function to execute
99 * @params: ATIF function params
101 * Executes the requested ATIF function (all asics).
102 * Returns a pointer to the acpi output buffer.
104 static union acpi_object *amdgpu_atif_call(struct amdgpu_atif *atif,
106 struct acpi_buffer *params)
109 union acpi_object atif_arg_elements[2];
110 struct acpi_object_list atif_arg;
111 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
114 atif_arg.pointer = &atif_arg_elements[0];
116 atif_arg_elements[0].type = ACPI_TYPE_INTEGER;
117 atif_arg_elements[0].integer.value = function;
120 atif_arg_elements[1].type = ACPI_TYPE_BUFFER;
121 atif_arg_elements[1].buffer.length = params->length;
122 atif_arg_elements[1].buffer.pointer = params->pointer;
124 /* We need a second fake parameter */
125 atif_arg_elements[1].type = ACPI_TYPE_INTEGER;
126 atif_arg_elements[1].integer.value = 0;
129 status = acpi_evaluate_object(atif->handle, NULL, &atif_arg,
132 /* Fail only if calling the method fails and ATIF is supported */
133 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
134 DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",
135 acpi_format_exception(status));
136 kfree(buffer.pointer);
140 return buffer.pointer;
144 * amdgpu_atif_parse_notification - parse supported notifications
146 * @n: supported notifications struct
147 * @mask: supported notifications mask from ATIF
149 * Use the supported notifications mask from ATIF function
150 * ATIF_FUNCTION_VERIFY_INTERFACE to determine what notifications
151 * are supported (all asics).
153 static void amdgpu_atif_parse_notification(struct amdgpu_atif_notifications *n, u32 mask)
155 n->thermal_state = mask & ATIF_THERMAL_STATE_CHANGE_REQUEST_SUPPORTED;
156 n->forced_power_state = mask & ATIF_FORCED_POWER_STATE_CHANGE_REQUEST_SUPPORTED;
157 n->system_power_state = mask & ATIF_SYSTEM_POWER_SOURCE_CHANGE_REQUEST_SUPPORTED;
158 n->brightness_change = mask & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST_SUPPORTED;
159 n->dgpu_display_event = mask & ATIF_DGPU_DISPLAY_EVENT_SUPPORTED;
160 n->gpu_package_power_limit = mask & ATIF_GPU_PACKAGE_POWER_LIMIT_REQUEST_SUPPORTED;
164 * amdgpu_atif_parse_functions - parse supported functions
166 * @f: supported functions struct
167 * @mask: supported functions mask from ATIF
169 * Use the supported functions mask from ATIF function
170 * ATIF_FUNCTION_VERIFY_INTERFACE to determine what functions
171 * are supported (all asics).
173 static void amdgpu_atif_parse_functions(struct amdgpu_atif_functions *f, u32 mask)
175 f->system_params = mask & ATIF_GET_SYSTEM_PARAMETERS_SUPPORTED;
176 f->sbios_requests = mask & ATIF_GET_SYSTEM_BIOS_REQUESTS_SUPPORTED;
177 f->temperature_change = mask & ATIF_TEMPERATURE_CHANGE_NOTIFICATION_SUPPORTED;
178 f->query_backlight_transfer_characteristics =
179 mask & ATIF_QUERY_BACKLIGHT_TRANSFER_CHARACTERISTICS_SUPPORTED;
180 f->ready_to_undock = mask & ATIF_READY_TO_UNDOCK_NOTIFICATION_SUPPORTED;
181 f->external_gpu_information = mask & ATIF_GET_EXTERNAL_GPU_INFORMATION_SUPPORTED;
185 * amdgpu_atif_verify_interface - verify ATIF
187 * @atif: amdgpu atif struct
189 * Execute the ATIF_FUNCTION_VERIFY_INTERFACE ATIF function
190 * to initialize ATIF and determine what features are supported
192 * returns 0 on success, error on failure.
194 static int amdgpu_atif_verify_interface(struct amdgpu_atif *atif)
196 union acpi_object *info;
197 struct atif_verify_interface output;
201 info = amdgpu_atif_call(atif, ATIF_FUNCTION_VERIFY_INTERFACE, NULL);
205 memset(&output, 0, sizeof(output));
207 size = *(u16 *) info->buffer.pointer;
209 DRM_INFO("ATIF buffer is too small: %zu\n", size);
213 size = min(sizeof(output), size);
215 memcpy(&output, info->buffer.pointer, size);
217 /* TODO: check version? */
218 DRM_DEBUG_DRIVER("ATIF version %u\n", output.version);
220 amdgpu_atif_parse_notification(&atif->notifications, output.notification_mask);
221 amdgpu_atif_parse_functions(&atif->functions, output.function_bits);
229 * amdgpu_atif_get_notification_params - determine notify configuration
233 * Execute the ATIF_FUNCTION_GET_SYSTEM_PARAMETERS ATIF function
234 * to determine if a notifier is used and if so which one
235 * (all asics). This is either Notify(VGA, 0x81) or Notify(VGA, n)
236 * where n is specified in the result if a notifier is used.
237 * Returns 0 on success, error on failure.
239 static int amdgpu_atif_get_notification_params(struct amdgpu_atif *atif)
241 union acpi_object *info;
242 struct amdgpu_atif_notification_cfg *n = &atif->notification_cfg;
243 struct atif_system_params params;
247 info = amdgpu_atif_call(atif, ATIF_FUNCTION_GET_SYSTEM_PARAMETERS,
254 size = *(u16 *) info->buffer.pointer;
260 memset(¶ms, 0, sizeof(params));
261 size = min(sizeof(params), size);
262 memcpy(¶ms, info->buffer.pointer, size);
264 DRM_DEBUG_DRIVER("SYSTEM_PARAMS: mask = %#x, flags = %#x\n",
265 params.flags, params.valid_mask);
266 params.flags = params.flags & params.valid_mask;
268 if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_NONE) {
271 } else if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_81) {
273 n->command_code = 0x81;
280 n->command_code = params.command_code;
284 DRM_DEBUG_DRIVER("Notification %s, command code = %#x\n",
285 (n->enabled ? "enabled" : "disabled"),
292 * amdgpu_atif_query_backlight_caps - get min and max backlight input signal
296 * Execute the QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS ATIF function
297 * to determine the acceptable range of backlight values
299 * Backlight_caps.caps_valid will be set to true if the query is successful
301 * The input signals are in range 0-255
303 * This function assumes the display with backlight is the first LCD
305 * Returns 0 on success, error on failure.
307 static int amdgpu_atif_query_backlight_caps(struct amdgpu_atif *atif)
309 union acpi_object *info;
310 struct atif_qbtc_output characteristics;
311 struct atif_qbtc_arguments arguments;
312 struct acpi_buffer params;
316 arguments.size = sizeof(arguments);
317 arguments.requested_display = ATIF_QBTC_REQUEST_LCD1;
319 params.length = sizeof(arguments);
320 params.pointer = (void *)&arguments;
322 info = amdgpu_atif_call(atif,
323 ATIF_FUNCTION_QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS,
330 size = *(u16 *) info->buffer.pointer;
336 memset(&characteristics, 0, sizeof(characteristics));
337 size = min(sizeof(characteristics), size);
338 memcpy(&characteristics, info->buffer.pointer, size);
340 atif->backlight_caps.caps_valid = true;
341 atif->backlight_caps.min_input_signal =
342 characteristics.min_input_signal;
343 atif->backlight_caps.max_input_signal =
344 characteristics.max_input_signal;
351 * amdgpu_atif_get_sbios_requests - get requested sbios event
354 * @req: atif sbios request struct
356 * Execute the ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS ATIF function
357 * to determine what requests the sbios is making to the driver
359 * Returns 0 on success, error on failure.
361 static int amdgpu_atif_get_sbios_requests(struct amdgpu_atif *atif,
362 struct atif_sbios_requests *req)
364 union acpi_object *info;
368 info = amdgpu_atif_call(atif, ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS,
373 size = *(u16 *)info->buffer.pointer;
378 memset(req, 0, sizeof(*req));
380 size = min(sizeof(*req), size);
381 memcpy(req, info->buffer.pointer, size);
382 DRM_DEBUG_DRIVER("SBIOS pending requests: %#x\n", req->pending);
384 count = hweight32(req->pending);
392 * amdgpu_atif_handler - handle ATIF notify requests
394 * @adev: amdgpu_device pointer
395 * @event: atif sbios request struct
397 * Checks the acpi event and if it matches an atif event,
401 * NOTIFY_BAD or NOTIFY_DONE, depending on the event.
403 static int amdgpu_atif_handler(struct amdgpu_device *adev,
404 struct acpi_bus_event *event)
406 struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;
409 DRM_DEBUG_DRIVER("event, device_class = %s, type = %#x\n",
410 event->device_class, event->type);
412 if (strcmp(event->device_class, ACPI_VIDEO_CLASS) != 0)
415 /* Is this actually our event? */
416 if (!atif->notification_cfg.enabled ||
417 event->type != atif->notification_cfg.command_code) {
418 /* These events will generate keypresses otherwise */
419 if (event->type == ACPI_VIDEO_NOTIFY_PROBE)
425 if (atif->functions.sbios_requests) {
426 struct atif_sbios_requests req;
428 /* Check pending SBIOS requests */
429 count = amdgpu_atif_get_sbios_requests(atif, &req);
434 DRM_DEBUG_DRIVER("ATIF: %d pending SBIOS requests\n", count);
436 if (req.pending & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST) {
437 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
439 DRM_DEBUG_DRIVER("Changing brightness to %d\n",
440 req.backlight_level);
442 * XXX backlight_device_set_brightness() is
443 * hardwired to post BACKLIGHT_UPDATE_SYSFS.
444 * It probably should accept 'reason' parameter.
446 backlight_device_set_brightness(atif->bd, req.backlight_level);
451 if (req.pending & ATIF_DGPU_DISPLAY_EVENT) {
452 if (adev->flags & AMD_IS_PX) {
453 pm_runtime_get_sync(adev_to_drm(adev)->dev);
454 /* Just fire off a uevent and let userspace tell us what to do */
455 drm_helper_hpd_irq_event(adev_to_drm(adev));
456 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
457 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
460 /* TODO: check other events */
463 /* We've handled the event, stop the notifier chain. The ACPI interface
464 * overloads ACPI_VIDEO_NOTIFY_PROBE, we don't want to send that to
465 * userspace if the event was generated only to signal a SBIOS
471 /* Call the ATCS method
474 * amdgpu_atcs_call - call an ATCS method
476 * @atcs: atcs structure
477 * @function: the ATCS function to execute
478 * @params: ATCS function params
480 * Executes the requested ATCS function (all asics).
481 * Returns a pointer to the acpi output buffer.
483 static union acpi_object *amdgpu_atcs_call(struct amdgpu_atcs *atcs,
485 struct acpi_buffer *params)
488 union acpi_object atcs_arg_elements[2];
489 struct acpi_object_list atcs_arg;
490 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
493 atcs_arg.pointer = &atcs_arg_elements[0];
495 atcs_arg_elements[0].type = ACPI_TYPE_INTEGER;
496 atcs_arg_elements[0].integer.value = function;
499 atcs_arg_elements[1].type = ACPI_TYPE_BUFFER;
500 atcs_arg_elements[1].buffer.length = params->length;
501 atcs_arg_elements[1].buffer.pointer = params->pointer;
503 /* We need a second fake parameter */
504 atcs_arg_elements[1].type = ACPI_TYPE_INTEGER;
505 atcs_arg_elements[1].integer.value = 0;
508 status = acpi_evaluate_object(atcs->handle, NULL, &atcs_arg, &buffer);
510 /* Fail only if calling the method fails and ATIF is supported */
511 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
512 DRM_DEBUG_DRIVER("failed to evaluate ATCS got %s\n",
513 acpi_format_exception(status));
514 kfree(buffer.pointer);
518 return buffer.pointer;
522 * amdgpu_atcs_parse_functions - parse supported functions
524 * @f: supported functions struct
525 * @mask: supported functions mask from ATCS
527 * Use the supported functions mask from ATCS function
528 * ATCS_FUNCTION_VERIFY_INTERFACE to determine what functions
529 * are supported (all asics).
531 static void amdgpu_atcs_parse_functions(struct amdgpu_atcs_functions *f, u32 mask)
533 f->get_ext_state = mask & ATCS_GET_EXTERNAL_STATE_SUPPORTED;
534 f->pcie_perf_req = mask & ATCS_PCIE_PERFORMANCE_REQUEST_SUPPORTED;
535 f->pcie_dev_rdy = mask & ATCS_PCIE_DEVICE_READY_NOTIFICATION_SUPPORTED;
536 f->pcie_bus_width = mask & ATCS_SET_PCIE_BUS_WIDTH_SUPPORTED;
540 * amdgpu_atcs_verify_interface - verify ATCS
542 * @atcs: amdgpu atcs struct
544 * Execute the ATCS_FUNCTION_VERIFY_INTERFACE ATCS function
545 * to initialize ATCS and determine what features are supported
547 * returns 0 on success, error on failure.
549 static int amdgpu_atcs_verify_interface(struct amdgpu_atcs *atcs)
551 union acpi_object *info;
552 struct atcs_verify_interface output;
556 info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_VERIFY_INTERFACE, NULL);
560 memset(&output, 0, sizeof(output));
562 size = *(u16 *) info->buffer.pointer;
564 DRM_INFO("ATCS buffer is too small: %zu\n", size);
568 size = min(sizeof(output), size);
570 memcpy(&output, info->buffer.pointer, size);
572 /* TODO: check version? */
573 DRM_DEBUG_DRIVER("ATCS version %u\n", output.version);
575 amdgpu_atcs_parse_functions(&atcs->functions, output.function_bits);
583 * amdgpu_acpi_is_pcie_performance_request_supported
585 * @adev: amdgpu_device pointer
587 * Check if the ATCS pcie_perf_req and pcie_dev_rdy methods
588 * are supported (all asics).
589 * returns true if supported, false if not.
591 bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev)
593 struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
595 if (atcs->functions.pcie_perf_req && atcs->functions.pcie_dev_rdy)
602 * amdgpu_acpi_pcie_notify_device_ready
604 * @adev: amdgpu_device pointer
606 * Executes the PCIE_DEVICE_READY_NOTIFICATION method
608 * returns 0 on success, error on failure.
610 int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev)
612 union acpi_object *info;
613 struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
615 if (!atcs->functions.pcie_dev_rdy)
618 info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_PCIE_DEVICE_READY_NOTIFICATION, NULL);
628 * amdgpu_acpi_pcie_performance_request
630 * @adev: amdgpu_device pointer
631 * @perf_req: requested perf level (pcie gen speed)
632 * @advertise: set advertise caps flag if set
634 * Executes the PCIE_PERFORMANCE_REQUEST method to
635 * change the pcie gen speed (all asics).
636 * returns 0 on success, error on failure.
638 int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
639 u8 perf_req, bool advertise)
641 union acpi_object *info;
642 struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
643 struct atcs_pref_req_input atcs_input;
644 struct atcs_pref_req_output atcs_output;
645 struct acpi_buffer params;
649 if (amdgpu_acpi_pcie_notify_device_ready(adev))
652 if (!atcs->functions.pcie_perf_req)
655 atcs_input.size = sizeof(struct atcs_pref_req_input);
656 /* client id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */
657 atcs_input.client_id = adev->pdev->devfn | (adev->pdev->bus->number << 8);
658 atcs_input.valid_flags_mask = ATCS_VALID_FLAGS_MASK;
659 atcs_input.flags = ATCS_WAIT_FOR_COMPLETION;
661 atcs_input.flags |= ATCS_ADVERTISE_CAPS;
662 atcs_input.req_type = ATCS_PCIE_LINK_SPEED;
663 atcs_input.perf_req = perf_req;
665 params.length = sizeof(struct atcs_pref_req_input);
666 params.pointer = &atcs_input;
669 info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_PCIE_PERFORMANCE_REQUEST, ¶ms);
673 memset(&atcs_output, 0, sizeof(atcs_output));
675 size = *(u16 *) info->buffer.pointer;
677 DRM_INFO("ATCS buffer is too small: %zu\n", size);
681 size = min(sizeof(atcs_output), size);
683 memcpy(&atcs_output, info->buffer.pointer, size);
687 switch (atcs_output.ret_val) {
688 case ATCS_REQUEST_REFUSED:
691 case ATCS_REQUEST_COMPLETE:
693 case ATCS_REQUEST_IN_PROGRESS:
703 * amdgpu_acpi_event - handle notify events
705 * @nb: notifier block
709 * Calls relevant amdgpu functions in response to various
711 * Returns NOTIFY code
713 static int amdgpu_acpi_event(struct notifier_block *nb,
717 struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, acpi_nb);
718 struct acpi_bus_event *entry = (struct acpi_bus_event *)data;
720 if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) {
721 if (power_supply_is_system_supplied() > 0)
722 DRM_DEBUG_DRIVER("pm: AC\n");
724 DRM_DEBUG_DRIVER("pm: DC\n");
726 amdgpu_pm_acpi_event_handler(adev);
729 /* Check for pending SBIOS requests */
730 return amdgpu_atif_handler(adev, entry);
733 /* Call all ACPI methods here */
735 * amdgpu_acpi_init - init driver acpi support
737 * @adev: amdgpu_device pointer
739 * Verifies the AMD ACPI interfaces and registers with the acpi
740 * notifier chain (all asics).
741 * Returns 0 on success, error on failure.
743 int amdgpu_acpi_init(struct amdgpu_device *adev)
745 struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;
747 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
748 if (atif->notifications.brightness_change) {
749 if (amdgpu_device_has_dc_support(adev)) {
750 #if defined(CONFIG_DRM_AMD_DC)
751 struct amdgpu_display_manager *dm = &adev->dm;
752 if (dm->backlight_dev)
753 atif->bd = dm->backlight_dev;
756 struct drm_encoder *tmp;
758 /* Find the encoder controlling the brightness */
759 list_for_each_entry(tmp, &adev_to_drm(adev)->mode_config.encoder_list,
761 struct amdgpu_encoder *enc = to_amdgpu_encoder(tmp);
763 if ((enc->devices & (ATOM_DEVICE_LCD_SUPPORT)) &&
765 struct amdgpu_encoder_atom_dig *dig = enc->enc_priv;
767 atif->bd = dig->bl_dev;
775 adev->acpi_nb.notifier_call = amdgpu_acpi_event;
776 register_acpi_notifier(&adev->acpi_nb);
781 void amdgpu_acpi_get_backlight_caps(struct amdgpu_dm_backlight_caps *caps)
783 struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;
785 caps->caps_valid = atif->backlight_caps.caps_valid;
786 caps->min_input_signal = atif->backlight_caps.min_input_signal;
787 caps->max_input_signal = atif->backlight_caps.max_input_signal;
791 * amdgpu_acpi_fini - tear down driver acpi support
793 * @adev: amdgpu_device pointer
795 * Unregisters with the acpi notifier chain (all asics).
797 void amdgpu_acpi_fini(struct amdgpu_device *adev)
799 unregister_acpi_notifier(&adev->acpi_nb);
803 * amdgpu_atif_pci_probe_handle - look up the ATIF handle
807 * Look up the ATIF handles (all asics).
808 * Returns true if the handle is found, false if not.
810 static bool amdgpu_atif_pci_probe_handle(struct pci_dev *pdev)
812 char acpi_method_name[255] = { 0 };
813 struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
814 acpi_handle dhandle, atif_handle;
818 dhandle = ACPI_HANDLE(&pdev->dev);
822 status = acpi_get_handle(dhandle, "ATIF", &atif_handle);
823 if (ACPI_FAILURE(status)) {
826 amdgpu_acpi_priv.atif.handle = atif_handle;
827 acpi_get_name(amdgpu_acpi_priv.atif.handle, ACPI_FULL_PATHNAME, &buffer);
828 DRM_DEBUG_DRIVER("Found ATIF handle %s\n", acpi_method_name);
829 ret = amdgpu_atif_verify_interface(&amdgpu_acpi_priv.atif);
831 amdgpu_acpi_priv.atif.handle = 0;
838 * amdgpu_atcs_pci_probe_handle - look up the ATCS handle
842 * Look up the ATCS handles (all asics).
843 * Returns true if the handle is found, false if not.
845 static bool amdgpu_atcs_pci_probe_handle(struct pci_dev *pdev)
847 char acpi_method_name[255] = { 0 };
848 struct acpi_buffer buffer = { sizeof(acpi_method_name), acpi_method_name };
849 acpi_handle dhandle, atcs_handle;
853 dhandle = ACPI_HANDLE(&pdev->dev);
857 status = acpi_get_handle(dhandle, "ATCS", &atcs_handle);
858 if (ACPI_FAILURE(status)) {
861 amdgpu_acpi_priv.atcs.handle = atcs_handle;
862 acpi_get_name(amdgpu_acpi_priv.atcs.handle, ACPI_FULL_PATHNAME, &buffer);
863 DRM_DEBUG_DRIVER("Found ATCS handle %s\n", acpi_method_name);
864 ret = amdgpu_atcs_verify_interface(&amdgpu_acpi_priv.atcs);
866 amdgpu_acpi_priv.atcs.handle = 0;
873 * amdgpu_acpi_detect - detect ACPI ATIF/ATCS methods
875 * Check if we have the ATIF/ATCS methods and populate
876 * the structures in the driver.
878 void amdgpu_acpi_detect(void)
880 struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;
881 struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
882 struct pci_dev *pdev = NULL;
885 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
887 amdgpu_atif_pci_probe_handle(pdev);
889 amdgpu_atcs_pci_probe_handle(pdev);
892 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_OTHER << 8, pdev)) != NULL) {
894 amdgpu_atif_pci_probe_handle(pdev);
896 amdgpu_atcs_pci_probe_handle(pdev);
899 if (atif->functions.sbios_requests && !atif->functions.system_params) {
900 /* XXX check this workraround, if sbios request function is
901 * present we have to see how it's configured in the system
904 atif->functions.system_params = true;
907 if (atif->functions.system_params) {
908 ret = amdgpu_atif_get_notification_params(atif);
910 DRM_DEBUG_DRIVER("Call to GET_SYSTEM_PARAMS failed: %d\n",
912 /* Disable notification */
913 atif->notification_cfg.enabled = false;
917 if (atif->functions.query_backlight_transfer_characteristics) {
918 ret = amdgpu_atif_query_backlight_caps(atif);
920 DRM_DEBUG_DRIVER("Call to QUERY_BACKLIGHT_TRANSFER_CHARACTERISTICS failed: %d\n",
922 atif->backlight_caps.caps_valid = false;
925 atif->backlight_caps.caps_valid = false;
930 * amdgpu_acpi_is_s0ix_supported
932 * @adev: amdgpu_device_pointer
934 * returns true if supported, false if not.
936 bool amdgpu_acpi_is_s0ix_supported(struct amdgpu_device *adev)
938 #if defined(CONFIG_AMD_PMC) || defined(CONFIG_AMD_PMC_MODULE)
939 if (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0) {
940 if (adev->flags & AMD_IS_APU)