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 <linux/suspend.h>
30 #include <acpi/video.h>
31 #include <acpi/actbl.h>
33 #include <drm/drm_crtc_helper.h>
35 #include "amdgpu_pm.h"
36 #include "amdgpu_display.h"
40 struct amdgpu_atif_notification_cfg {
45 struct amdgpu_atif_notifications {
47 bool forced_power_state;
48 bool system_power_state;
49 bool brightness_change;
50 bool dgpu_display_event;
51 bool gpu_package_power_limit;
54 struct amdgpu_atif_functions {
57 bool temperature_change;
58 bool query_backlight_transfer_characteristics;
60 bool external_gpu_information;
66 struct amdgpu_atif_notifications notifications;
67 struct amdgpu_atif_functions functions;
68 struct amdgpu_atif_notification_cfg notification_cfg;
69 struct backlight_device *bd;
70 struct amdgpu_dm_backlight_caps backlight_caps;
73 struct amdgpu_atcs_functions {
78 bool power_shift_control;
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) {
438 DRM_DEBUG_DRIVER("Changing brightness to %d\n",
439 req.backlight_level);
441 * XXX backlight_device_set_brightness() is
442 * hardwired to post BACKLIGHT_UPDATE_SYSFS.
443 * It probably should accept 'reason' parameter.
445 backlight_device_set_brightness(atif->bd, req.backlight_level);
449 if (req.pending & ATIF_DGPU_DISPLAY_EVENT) {
450 if (adev->flags & AMD_IS_PX) {
451 pm_runtime_get_sync(adev_to_drm(adev)->dev);
452 /* Just fire off a uevent and let userspace tell us what to do */
453 drm_helper_hpd_irq_event(adev_to_drm(adev));
454 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
455 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
458 /* TODO: check other events */
461 /* We've handled the event, stop the notifier chain. The ACPI interface
462 * overloads ACPI_VIDEO_NOTIFY_PROBE, we don't want to send that to
463 * userspace if the event was generated only to signal a SBIOS
469 /* Call the ATCS method
472 * amdgpu_atcs_call - call an ATCS method
474 * @atcs: atcs structure
475 * @function: the ATCS function to execute
476 * @params: ATCS function params
478 * Executes the requested ATCS function (all asics).
479 * Returns a pointer to the acpi output buffer.
481 static union acpi_object *amdgpu_atcs_call(struct amdgpu_atcs *atcs,
483 struct acpi_buffer *params)
486 union acpi_object atcs_arg_elements[2];
487 struct acpi_object_list atcs_arg;
488 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
491 atcs_arg.pointer = &atcs_arg_elements[0];
493 atcs_arg_elements[0].type = ACPI_TYPE_INTEGER;
494 atcs_arg_elements[0].integer.value = function;
497 atcs_arg_elements[1].type = ACPI_TYPE_BUFFER;
498 atcs_arg_elements[1].buffer.length = params->length;
499 atcs_arg_elements[1].buffer.pointer = params->pointer;
501 /* We need a second fake parameter */
502 atcs_arg_elements[1].type = ACPI_TYPE_INTEGER;
503 atcs_arg_elements[1].integer.value = 0;
506 status = acpi_evaluate_object(atcs->handle, NULL, &atcs_arg, &buffer);
508 /* Fail only if calling the method fails and ATIF is supported */
509 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
510 DRM_DEBUG_DRIVER("failed to evaluate ATCS got %s\n",
511 acpi_format_exception(status));
512 kfree(buffer.pointer);
516 return buffer.pointer;
520 * amdgpu_atcs_parse_functions - parse supported functions
522 * @f: supported functions struct
523 * @mask: supported functions mask from ATCS
525 * Use the supported functions mask from ATCS function
526 * ATCS_FUNCTION_VERIFY_INTERFACE to determine what functions
527 * are supported (all asics).
529 static void amdgpu_atcs_parse_functions(struct amdgpu_atcs_functions *f, u32 mask)
531 f->get_ext_state = mask & ATCS_GET_EXTERNAL_STATE_SUPPORTED;
532 f->pcie_perf_req = mask & ATCS_PCIE_PERFORMANCE_REQUEST_SUPPORTED;
533 f->pcie_dev_rdy = mask & ATCS_PCIE_DEVICE_READY_NOTIFICATION_SUPPORTED;
534 f->pcie_bus_width = mask & ATCS_SET_PCIE_BUS_WIDTH_SUPPORTED;
535 f->power_shift_control = mask & ATCS_SET_POWER_SHIFT_CONTROL_SUPPORTED;
539 * amdgpu_atcs_verify_interface - verify ATCS
541 * @atcs: amdgpu atcs struct
543 * Execute the ATCS_FUNCTION_VERIFY_INTERFACE ATCS function
544 * to initialize ATCS and determine what features are supported
546 * returns 0 on success, error on failure.
548 static int amdgpu_atcs_verify_interface(struct amdgpu_atcs *atcs)
550 union acpi_object *info;
551 struct atcs_verify_interface output;
555 info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_VERIFY_INTERFACE, NULL);
559 memset(&output, 0, sizeof(output));
561 size = *(u16 *) info->buffer.pointer;
563 DRM_INFO("ATCS buffer is too small: %zu\n", size);
567 size = min(sizeof(output), size);
569 memcpy(&output, info->buffer.pointer, size);
571 /* TODO: check version? */
572 DRM_DEBUG_DRIVER("ATCS version %u\n", output.version);
574 amdgpu_atcs_parse_functions(&atcs->functions, output.function_bits);
582 * amdgpu_acpi_is_pcie_performance_request_supported
584 * @adev: amdgpu_device pointer
586 * Check if the ATCS pcie_perf_req and pcie_dev_rdy methods
587 * are supported (all asics).
588 * returns true if supported, false if not.
590 bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev)
592 struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
594 if (atcs->functions.pcie_perf_req && atcs->functions.pcie_dev_rdy)
601 * amdgpu_acpi_is_power_shift_control_supported
603 * Check if the ATCS power shift control method
605 * returns true if supported, false if not.
607 bool amdgpu_acpi_is_power_shift_control_supported(void)
609 return amdgpu_acpi_priv.atcs.functions.power_shift_control;
613 * amdgpu_acpi_pcie_notify_device_ready
615 * @adev: amdgpu_device pointer
617 * Executes the PCIE_DEVICE_READY_NOTIFICATION method
619 * returns 0 on success, error on failure.
621 int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev)
623 union acpi_object *info;
624 struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
626 if (!atcs->functions.pcie_dev_rdy)
629 info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_PCIE_DEVICE_READY_NOTIFICATION, NULL);
639 * amdgpu_acpi_pcie_performance_request
641 * @adev: amdgpu_device pointer
642 * @perf_req: requested perf level (pcie gen speed)
643 * @advertise: set advertise caps flag if set
645 * Executes the PCIE_PERFORMANCE_REQUEST method to
646 * change the pcie gen speed (all asics).
647 * returns 0 on success, error on failure.
649 int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
650 u8 perf_req, bool advertise)
652 union acpi_object *info;
653 struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
654 struct atcs_pref_req_input atcs_input;
655 struct atcs_pref_req_output atcs_output;
656 struct acpi_buffer params;
660 if (amdgpu_acpi_pcie_notify_device_ready(adev))
663 if (!atcs->functions.pcie_perf_req)
666 atcs_input.size = sizeof(struct atcs_pref_req_input);
667 /* client id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */
668 atcs_input.client_id = adev->pdev->devfn | (adev->pdev->bus->number << 8);
669 atcs_input.valid_flags_mask = ATCS_VALID_FLAGS_MASK;
670 atcs_input.flags = ATCS_WAIT_FOR_COMPLETION;
672 atcs_input.flags |= ATCS_ADVERTISE_CAPS;
673 atcs_input.req_type = ATCS_PCIE_LINK_SPEED;
674 atcs_input.perf_req = perf_req;
676 params.length = sizeof(struct atcs_pref_req_input);
677 params.pointer = &atcs_input;
680 info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_PCIE_PERFORMANCE_REQUEST, ¶ms);
684 memset(&atcs_output, 0, sizeof(atcs_output));
686 size = *(u16 *) info->buffer.pointer;
688 DRM_INFO("ATCS buffer is too small: %zu\n", size);
692 size = min(sizeof(atcs_output), size);
694 memcpy(&atcs_output, info->buffer.pointer, size);
698 switch (atcs_output.ret_val) {
699 case ATCS_REQUEST_REFUSED:
702 case ATCS_REQUEST_COMPLETE:
704 case ATCS_REQUEST_IN_PROGRESS:
714 * amdgpu_acpi_power_shift_control
716 * @adev: amdgpu_device pointer
717 * @dev_state: device acpi state
718 * @drv_state: driver state
720 * Executes the POWER_SHIFT_CONTROL method to
721 * communicate current dGPU device state and
722 * driver state to APU/SBIOS.
723 * returns 0 on success, error on failure.
725 int amdgpu_acpi_power_shift_control(struct amdgpu_device *adev,
726 u8 dev_state, bool drv_state)
728 union acpi_object *info;
729 struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
730 struct atcs_pwr_shift_input atcs_input;
731 struct acpi_buffer params;
733 if (!amdgpu_acpi_is_power_shift_control_supported())
736 atcs_input.size = sizeof(struct atcs_pwr_shift_input);
737 /* dGPU id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */
738 atcs_input.dgpu_id = adev->pdev->devfn | (adev->pdev->bus->number << 8);
739 atcs_input.dev_acpi_state = dev_state;
740 atcs_input.drv_state = drv_state;
742 params.length = sizeof(struct atcs_pwr_shift_input);
743 params.pointer = &atcs_input;
745 info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_POWER_SHIFT_CONTROL, ¶ms);
747 DRM_ERROR("ATCS PSC update failed\n");
755 * amdgpu_acpi_smart_shift_update - update dGPU device state to SBIOS
757 * @dev: drm_device pointer
758 * @ss_state: current smart shift event
760 * returns 0 on success,
761 * otherwise return error number.
763 int amdgpu_acpi_smart_shift_update(struct drm_device *dev, enum amdgpu_ss ss_state)
765 struct amdgpu_device *adev = drm_to_adev(dev);
768 if (!amdgpu_device_supports_smart_shift(dev))
772 /* SBIOS trigger “stop”, “enable” and “start” at D0, Driver Operational.
773 * SBIOS trigger “stop” at D3, Driver Not Operational.
774 * SBIOS trigger “stop” and “disable” at D0, Driver NOT operational.
776 case AMDGPU_SS_DRV_LOAD:
777 r = amdgpu_acpi_power_shift_control(adev,
778 AMDGPU_ATCS_PSC_DEV_STATE_D0,
779 AMDGPU_ATCS_PSC_DRV_STATE_OPR);
781 case AMDGPU_SS_DEV_D0:
782 r = amdgpu_acpi_power_shift_control(adev,
783 AMDGPU_ATCS_PSC_DEV_STATE_D0,
784 AMDGPU_ATCS_PSC_DRV_STATE_OPR);
786 case AMDGPU_SS_DEV_D3:
787 r = amdgpu_acpi_power_shift_control(adev,
788 AMDGPU_ATCS_PSC_DEV_STATE_D3_HOT,
789 AMDGPU_ATCS_PSC_DRV_STATE_NOT_OPR);
791 case AMDGPU_SS_DRV_UNLOAD:
792 r = amdgpu_acpi_power_shift_control(adev,
793 AMDGPU_ATCS_PSC_DEV_STATE_D0,
794 AMDGPU_ATCS_PSC_DRV_STATE_NOT_OPR);
804 * amdgpu_acpi_event - handle notify events
806 * @nb: notifier block
810 * Calls relevant amdgpu functions in response to various
812 * Returns NOTIFY code
814 static int amdgpu_acpi_event(struct notifier_block *nb,
818 struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, acpi_nb);
819 struct acpi_bus_event *entry = (struct acpi_bus_event *)data;
821 if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) {
822 if (power_supply_is_system_supplied() > 0)
823 DRM_DEBUG_DRIVER("pm: AC\n");
825 DRM_DEBUG_DRIVER("pm: DC\n");
827 amdgpu_pm_acpi_event_handler(adev);
830 /* Check for pending SBIOS requests */
831 return amdgpu_atif_handler(adev, entry);
834 /* Call all ACPI methods here */
836 * amdgpu_acpi_init - init driver acpi support
838 * @adev: amdgpu_device pointer
840 * Verifies the AMD ACPI interfaces and registers with the acpi
841 * notifier chain (all asics).
842 * Returns 0 on success, error on failure.
844 int amdgpu_acpi_init(struct amdgpu_device *adev)
846 struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;
848 if (atif->notifications.brightness_change) {
849 if (amdgpu_device_has_dc_support(adev)) {
850 #if defined(CONFIG_DRM_AMD_DC)
851 struct amdgpu_display_manager *dm = &adev->dm;
852 if (dm->backlight_dev[0])
853 atif->bd = dm->backlight_dev[0];
856 struct drm_encoder *tmp;
858 /* Find the encoder controlling the brightness */
859 list_for_each_entry(tmp, &adev_to_drm(adev)->mode_config.encoder_list,
861 struct amdgpu_encoder *enc = to_amdgpu_encoder(tmp);
863 if ((enc->devices & (ATOM_DEVICE_LCD_SUPPORT)) &&
865 struct amdgpu_encoder_atom_dig *dig = enc->enc_priv;
867 atif->bd = dig->bl_dev;
874 adev->acpi_nb.notifier_call = amdgpu_acpi_event;
875 register_acpi_notifier(&adev->acpi_nb);
880 void amdgpu_acpi_get_backlight_caps(struct amdgpu_dm_backlight_caps *caps)
882 struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;
884 caps->caps_valid = atif->backlight_caps.caps_valid;
885 caps->min_input_signal = atif->backlight_caps.min_input_signal;
886 caps->max_input_signal = atif->backlight_caps.max_input_signal;
890 * amdgpu_acpi_fini - tear down driver acpi support
892 * @adev: amdgpu_device pointer
894 * Unregisters with the acpi notifier chain (all asics).
896 void amdgpu_acpi_fini(struct amdgpu_device *adev)
898 unregister_acpi_notifier(&adev->acpi_nb);
902 * amdgpu_atif_pci_probe_handle - look up the ATIF handle
906 * Look up the ATIF handles (all asics).
907 * Returns true if the handle is found, false if not.
909 static bool amdgpu_atif_pci_probe_handle(struct pci_dev *pdev)
911 char acpi_method_name[255] = { 0 };
912 struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
913 acpi_handle dhandle, atif_handle;
917 dhandle = ACPI_HANDLE(&pdev->dev);
921 status = acpi_get_handle(dhandle, "ATIF", &atif_handle);
922 if (ACPI_FAILURE(status)) {
925 amdgpu_acpi_priv.atif.handle = atif_handle;
926 acpi_get_name(amdgpu_acpi_priv.atif.handle, ACPI_FULL_PATHNAME, &buffer);
927 DRM_DEBUG_DRIVER("Found ATIF handle %s\n", acpi_method_name);
928 ret = amdgpu_atif_verify_interface(&amdgpu_acpi_priv.atif);
930 amdgpu_acpi_priv.atif.handle = 0;
937 * amdgpu_atcs_pci_probe_handle - look up the ATCS handle
941 * Look up the ATCS handles (all asics).
942 * Returns true if the handle is found, false if not.
944 static bool amdgpu_atcs_pci_probe_handle(struct pci_dev *pdev)
946 char acpi_method_name[255] = { 0 };
947 struct acpi_buffer buffer = { sizeof(acpi_method_name), acpi_method_name };
948 acpi_handle dhandle, atcs_handle;
952 dhandle = ACPI_HANDLE(&pdev->dev);
956 status = acpi_get_handle(dhandle, "ATCS", &atcs_handle);
957 if (ACPI_FAILURE(status)) {
960 amdgpu_acpi_priv.atcs.handle = atcs_handle;
961 acpi_get_name(amdgpu_acpi_priv.atcs.handle, ACPI_FULL_PATHNAME, &buffer);
962 DRM_DEBUG_DRIVER("Found ATCS handle %s\n", acpi_method_name);
963 ret = amdgpu_atcs_verify_interface(&amdgpu_acpi_priv.atcs);
965 amdgpu_acpi_priv.atcs.handle = 0;
972 * amdgpu_acpi_detect - detect ACPI ATIF/ATCS methods
974 * Check if we have the ATIF/ATCS methods and populate
975 * the structures in the driver.
977 void amdgpu_acpi_detect(void)
979 struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;
980 struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
981 struct pci_dev *pdev = NULL;
984 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
986 amdgpu_atif_pci_probe_handle(pdev);
988 amdgpu_atcs_pci_probe_handle(pdev);
991 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_OTHER << 8, pdev)) != NULL) {
993 amdgpu_atif_pci_probe_handle(pdev);
995 amdgpu_atcs_pci_probe_handle(pdev);
998 if (atif->functions.sbios_requests && !atif->functions.system_params) {
999 /* XXX check this workraround, if sbios request function is
1000 * present we have to see how it's configured in the system
1003 atif->functions.system_params = true;
1006 if (atif->functions.system_params) {
1007 ret = amdgpu_atif_get_notification_params(atif);
1009 DRM_DEBUG_DRIVER("Call to GET_SYSTEM_PARAMS failed: %d\n",
1011 /* Disable notification */
1012 atif->notification_cfg.enabled = false;
1016 if (atif->functions.query_backlight_transfer_characteristics) {
1017 ret = amdgpu_atif_query_backlight_caps(atif);
1019 DRM_DEBUG_DRIVER("Call to QUERY_BACKLIGHT_TRANSFER_CHARACTERISTICS failed: %d\n",
1021 atif->backlight_caps.caps_valid = false;
1024 atif->backlight_caps.caps_valid = false;
1028 #if IS_ENABLED(CONFIG_SUSPEND)
1030 * amdgpu_acpi_is_s3_active
1032 * @adev: amdgpu_device_pointer
1034 * returns true if supported, false if not.
1036 bool amdgpu_acpi_is_s3_active(struct amdgpu_device *adev)
1038 return !(adev->flags & AMD_IS_APU) ||
1039 (pm_suspend_target_state == PM_SUSPEND_MEM);
1043 * amdgpu_acpi_should_gpu_reset
1045 * @adev: amdgpu_device_pointer
1047 * returns true if should reset GPU, false if not
1049 bool amdgpu_acpi_should_gpu_reset(struct amdgpu_device *adev)
1051 if (adev->flags & AMD_IS_APU)
1053 return pm_suspend_target_state != PM_SUSPEND_TO_IDLE;
1057 * amdgpu_acpi_is_s0ix_active
1059 * @adev: amdgpu_device_pointer
1061 * returns true if supported, false if not.
1063 bool amdgpu_acpi_is_s0ix_active(struct amdgpu_device *adev)
1065 if (!(adev->flags & AMD_IS_APU) ||
1066 (pm_suspend_target_state != PM_SUSPEND_TO_IDLE))
1069 if (!(acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0)) {
1070 dev_warn_once(adev->dev,
1071 "Power consumption will be higher as BIOS has not been configured for suspend-to-idle.\n"
1072 "To use suspend-to-idle change the sleep mode in BIOS setup.\n");
1076 #if !IS_ENABLED(CONFIG_AMD_PMC)
1077 dev_warn_once(adev->dev,
1078 "Power consumption will be higher as the kernel has not been compiled with CONFIG_AMD_PMC.\n");
1082 #endif /* CONFIG_AMD_PMC */
1085 #endif /* CONFIG_SUSPEND */