1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
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>
32
33#include <drm/drm_crtc_helper.h>
34#include "amdgpu.h"
35#include "amdgpu_pm.h"
36#include "amdgpu_display.h"
37#include "amd_acpi.h"
38#include "atom.h"
39
40struct amdgpu_atif_notification_cfg {
41 bool enabled;
42 int command_code;
43};
44
45struct amdgpu_atif_notifications {
46 bool thermal_state;
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;
52};
53
54struct amdgpu_atif_functions {
55 bool system_params;
56 bool sbios_requests;
57 bool temperature_change;
58 bool query_backlight_transfer_characteristics;
59 bool ready_to_undock;
60 bool external_gpu_information;
61};
62
63struct amdgpu_atif {
64 acpi_handle handle;
65
66 struct amdgpu_atif_notifications notifications;
67 struct amdgpu_atif_functions functions;
68 struct amdgpu_atif_notification_cfg notification_cfg;
69#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
70 struct backlight_device *bd;
71#endif
72 struct amdgpu_dm_backlight_caps backlight_caps;
73};
74
75struct amdgpu_atcs_functions {
76 bool get_ext_state;
77 bool pcie_perf_req;
78 bool pcie_dev_rdy;
79 bool pcie_bus_width;
80 bool power_shift_control;
81};
82
83struct amdgpu_atcs {
84 acpi_handle handle;
85
86 struct amdgpu_atcs_functions functions;
87};
88
89static struct amdgpu_acpi_priv {
90 struct amdgpu_atif atif;
91 struct amdgpu_atcs atcs;
92} amdgpu_acpi_priv;
93
94
95
96
97
98
99
100
101
102
103
104
105
106static union acpi_object *amdgpu_atif_call(struct amdgpu_atif *atif,
107 int function,
108 struct acpi_buffer *params)
109{
110 acpi_status status;
111 union acpi_object atif_arg_elements[2];
112 struct acpi_object_list atif_arg;
113 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
114
115 atif_arg.count = 2;
116 atif_arg.pointer = &atif_arg_elements[0];
117
118 atif_arg_elements[0].type = ACPI_TYPE_INTEGER;
119 atif_arg_elements[0].integer.value = function;
120
121 if (params) {
122 atif_arg_elements[1].type = ACPI_TYPE_BUFFER;
123 atif_arg_elements[1].buffer.length = params->length;
124 atif_arg_elements[1].buffer.pointer = params->pointer;
125 } else {
126
127 atif_arg_elements[1].type = ACPI_TYPE_INTEGER;
128 atif_arg_elements[1].integer.value = 0;
129 }
130
131 status = acpi_evaluate_object(atif->handle, NULL, &atif_arg,
132 &buffer);
133
134
135 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
136 DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",
137 acpi_format_exception(status));
138 kfree(buffer.pointer);
139 return NULL;
140 }
141
142 return buffer.pointer;
143}
144
145
146
147
148
149
150
151
152
153
154
155static void amdgpu_atif_parse_notification(struct amdgpu_atif_notifications *n, u32 mask)
156{
157 n->thermal_state = mask & ATIF_THERMAL_STATE_CHANGE_REQUEST_SUPPORTED;
158 n->forced_power_state = mask & ATIF_FORCED_POWER_STATE_CHANGE_REQUEST_SUPPORTED;
159 n->system_power_state = mask & ATIF_SYSTEM_POWER_SOURCE_CHANGE_REQUEST_SUPPORTED;
160 n->brightness_change = mask & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST_SUPPORTED;
161 n->dgpu_display_event = mask & ATIF_DGPU_DISPLAY_EVENT_SUPPORTED;
162 n->gpu_package_power_limit = mask & ATIF_GPU_PACKAGE_POWER_LIMIT_REQUEST_SUPPORTED;
163}
164
165
166
167
168
169
170
171
172
173
174
175static void amdgpu_atif_parse_functions(struct amdgpu_atif_functions *f, u32 mask)
176{
177 f->system_params = mask & ATIF_GET_SYSTEM_PARAMETERS_SUPPORTED;
178 f->sbios_requests = mask & ATIF_GET_SYSTEM_BIOS_REQUESTS_SUPPORTED;
179 f->temperature_change = mask & ATIF_TEMPERATURE_CHANGE_NOTIFICATION_SUPPORTED;
180 f->query_backlight_transfer_characteristics =
181 mask & ATIF_QUERY_BACKLIGHT_TRANSFER_CHARACTERISTICS_SUPPORTED;
182 f->ready_to_undock = mask & ATIF_READY_TO_UNDOCK_NOTIFICATION_SUPPORTED;
183 f->external_gpu_information = mask & ATIF_GET_EXTERNAL_GPU_INFORMATION_SUPPORTED;
184}
185
186
187
188
189
190
191
192
193
194
195
196static int amdgpu_atif_verify_interface(struct amdgpu_atif *atif)
197{
198 union acpi_object *info;
199 struct atif_verify_interface output;
200 size_t size;
201 int err = 0;
202
203 info = amdgpu_atif_call(atif, ATIF_FUNCTION_VERIFY_INTERFACE, NULL);
204 if (!info)
205 return -EIO;
206
207 memset(&output, 0, sizeof(output));
208
209 size = *(u16 *) info->buffer.pointer;
210 if (size < 12) {
211 DRM_INFO("ATIF buffer is too small: %zu\n", size);
212 err = -EINVAL;
213 goto out;
214 }
215 size = min(sizeof(output), size);
216
217 memcpy(&output, info->buffer.pointer, size);
218
219
220 DRM_DEBUG_DRIVER("ATIF version %u\n", output.version);
221
222 amdgpu_atif_parse_notification(&atif->notifications, output.notification_mask);
223 amdgpu_atif_parse_functions(&atif->functions, output.function_bits);
224
225out:
226 kfree(info);
227 return err;
228}
229
230
231
232
233
234
235
236
237
238
239
240
241static int amdgpu_atif_get_notification_params(struct amdgpu_atif *atif)
242{
243 union acpi_object *info;
244 struct amdgpu_atif_notification_cfg *n = &atif->notification_cfg;
245 struct atif_system_params params;
246 size_t size;
247 int err = 0;
248
249 info = amdgpu_atif_call(atif, ATIF_FUNCTION_GET_SYSTEM_PARAMETERS,
250 NULL);
251 if (!info) {
252 err = -EIO;
253 goto out;
254 }
255
256 size = *(u16 *) info->buffer.pointer;
257 if (size < 10) {
258 err = -EINVAL;
259 goto out;
260 }
261
262 memset(¶ms, 0, sizeof(params));
263 size = min(sizeof(params), size);
264 memcpy(¶ms, info->buffer.pointer, size);
265
266 DRM_DEBUG_DRIVER("SYSTEM_PARAMS: mask = %#x, flags = %#x\n",
267 params.flags, params.valid_mask);
268 params.flags = params.flags & params.valid_mask;
269
270 if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_NONE) {
271 n->enabled = false;
272 n->command_code = 0;
273 } else if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_81) {
274 n->enabled = true;
275 n->command_code = 0x81;
276 } else {
277 if (size < 11) {
278 err = -EINVAL;
279 goto out;
280 }
281 n->enabled = true;
282 n->command_code = params.command_code;
283 }
284
285out:
286 DRM_DEBUG_DRIVER("Notification %s, command code = %#x\n",
287 (n->enabled ? "enabled" : "disabled"),
288 n->command_code);
289 kfree(info);
290 return err;
291}
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309static int amdgpu_atif_query_backlight_caps(struct amdgpu_atif *atif)
310{
311 union acpi_object *info;
312 struct atif_qbtc_output characteristics;
313 struct atif_qbtc_arguments arguments;
314 struct acpi_buffer params;
315 size_t size;
316 int err = 0;
317
318 arguments.size = sizeof(arguments);
319 arguments.requested_display = ATIF_QBTC_REQUEST_LCD1;
320
321 params.length = sizeof(arguments);
322 params.pointer = (void *)&arguments;
323
324 info = amdgpu_atif_call(atif,
325 ATIF_FUNCTION_QUERY_BRIGHTNESS_TRANSFER_CHARACTERISTICS,
326 ¶ms);
327 if (!info) {
328 err = -EIO;
329 goto out;
330 }
331
332 size = *(u16 *) info->buffer.pointer;
333 if (size < 10) {
334 err = -EINVAL;
335 goto out;
336 }
337
338 memset(&characteristics, 0, sizeof(characteristics));
339 size = min(sizeof(characteristics), size);
340 memcpy(&characteristics, info->buffer.pointer, size);
341
342 atif->backlight_caps.caps_valid = true;
343 atif->backlight_caps.min_input_signal =
344 characteristics.min_input_signal;
345 atif->backlight_caps.max_input_signal =
346 characteristics.max_input_signal;
347out:
348 kfree(info);
349 return err;
350}
351
352
353
354
355
356
357
358
359
360
361
362
363static int amdgpu_atif_get_sbios_requests(struct amdgpu_atif *atif,
364 struct atif_sbios_requests *req)
365{
366 union acpi_object *info;
367 size_t size;
368 int count = 0;
369
370 info = amdgpu_atif_call(atif, ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS,
371 NULL);
372 if (!info)
373 return -EIO;
374
375 size = *(u16 *)info->buffer.pointer;
376 if (size < 0xd) {
377 count = -EINVAL;
378 goto out;
379 }
380 memset(req, 0, sizeof(*req));
381
382 size = min(sizeof(*req), size);
383 memcpy(req, info->buffer.pointer, size);
384 DRM_DEBUG_DRIVER("SBIOS pending requests: %#x\n", req->pending);
385
386 count = hweight32(req->pending);
387
388out:
389 kfree(info);
390 return count;
391}
392
393
394
395
396
397
398
399
400
401
402
403
404
405static int amdgpu_atif_handler(struct amdgpu_device *adev,
406 struct acpi_bus_event *event)
407{
408 struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;
409 int count;
410
411 DRM_DEBUG_DRIVER("event, device_class = %s, type = %#x\n",
412 event->device_class, event->type);
413
414 if (strcmp(event->device_class, ACPI_VIDEO_CLASS) != 0)
415 return NOTIFY_DONE;
416
417
418 if (!atif->notification_cfg.enabled ||
419 event->type != atif->notification_cfg.command_code) {
420
421 if (event->type == ACPI_VIDEO_NOTIFY_PROBE)
422 return NOTIFY_BAD;
423 else
424 return NOTIFY_DONE;
425 }
426
427 if (atif->functions.sbios_requests) {
428 struct atif_sbios_requests req;
429
430
431 count = amdgpu_atif_get_sbios_requests(atif, &req);
432
433 if (count <= 0)
434 return NOTIFY_BAD;
435
436 DRM_DEBUG_DRIVER("ATIF: %d pending SBIOS requests\n", count);
437
438 if (req.pending & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST) {
439#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
440 if (atif->bd) {
441 DRM_DEBUG_DRIVER("Changing brightness to %d\n",
442 req.backlight_level);
443
444
445
446
447
448 backlight_device_set_brightness(atif->bd, req.backlight_level);
449 }
450#endif
451 }
452
453 if (req.pending & ATIF_DGPU_DISPLAY_EVENT) {
454 if (adev->flags & AMD_IS_PX) {
455 pm_runtime_get_sync(adev_to_drm(adev)->dev);
456
457 drm_helper_hpd_irq_event(adev_to_drm(adev));
458 pm_runtime_mark_last_busy(adev_to_drm(adev)->dev);
459 pm_runtime_put_autosuspend(adev_to_drm(adev)->dev);
460 }
461 }
462
463 }
464
465
466
467
468
469
470 return NOTIFY_BAD;
471}
472
473
474
475
476
477
478
479
480
481
482
483
484
485static union acpi_object *amdgpu_atcs_call(struct amdgpu_atcs *atcs,
486 int function,
487 struct acpi_buffer *params)
488{
489 acpi_status status;
490 union acpi_object atcs_arg_elements[2];
491 struct acpi_object_list atcs_arg;
492 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
493
494 atcs_arg.count = 2;
495 atcs_arg.pointer = &atcs_arg_elements[0];
496
497 atcs_arg_elements[0].type = ACPI_TYPE_INTEGER;
498 atcs_arg_elements[0].integer.value = function;
499
500 if (params) {
501 atcs_arg_elements[1].type = ACPI_TYPE_BUFFER;
502 atcs_arg_elements[1].buffer.length = params->length;
503 atcs_arg_elements[1].buffer.pointer = params->pointer;
504 } else {
505
506 atcs_arg_elements[1].type = ACPI_TYPE_INTEGER;
507 atcs_arg_elements[1].integer.value = 0;
508 }
509
510 status = acpi_evaluate_object(atcs->handle, NULL, &atcs_arg, &buffer);
511
512
513 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
514 DRM_DEBUG_DRIVER("failed to evaluate ATCS got %s\n",
515 acpi_format_exception(status));
516 kfree(buffer.pointer);
517 return NULL;
518 }
519
520 return buffer.pointer;
521}
522
523
524
525
526
527
528
529
530
531
532
533static void amdgpu_atcs_parse_functions(struct amdgpu_atcs_functions *f, u32 mask)
534{
535 f->get_ext_state = mask & ATCS_GET_EXTERNAL_STATE_SUPPORTED;
536 f->pcie_perf_req = mask & ATCS_PCIE_PERFORMANCE_REQUEST_SUPPORTED;
537 f->pcie_dev_rdy = mask & ATCS_PCIE_DEVICE_READY_NOTIFICATION_SUPPORTED;
538 f->pcie_bus_width = mask & ATCS_SET_PCIE_BUS_WIDTH_SUPPORTED;
539 f->power_shift_control = mask & ATCS_SET_POWER_SHIFT_CONTROL_SUPPORTED;
540}
541
542
543
544
545
546
547
548
549
550
551
552static int amdgpu_atcs_verify_interface(struct amdgpu_atcs *atcs)
553{
554 union acpi_object *info;
555 struct atcs_verify_interface output;
556 size_t size;
557 int err = 0;
558
559 info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_VERIFY_INTERFACE, NULL);
560 if (!info)
561 return -EIO;
562
563 memset(&output, 0, sizeof(output));
564
565 size = *(u16 *) info->buffer.pointer;
566 if (size < 8) {
567 DRM_INFO("ATCS buffer is too small: %zu\n", size);
568 err = -EINVAL;
569 goto out;
570 }
571 size = min(sizeof(output), size);
572
573 memcpy(&output, info->buffer.pointer, size);
574
575
576 DRM_DEBUG_DRIVER("ATCS version %u\n", output.version);
577
578 amdgpu_atcs_parse_functions(&atcs->functions, output.function_bits);
579
580out:
581 kfree(info);
582 return err;
583}
584
585
586
587
588
589
590
591
592
593
594bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev)
595{
596 struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
597
598 if (atcs->functions.pcie_perf_req && atcs->functions.pcie_dev_rdy)
599 return true;
600
601 return false;
602}
603
604
605
606
607
608
609
610
611bool amdgpu_acpi_is_power_shift_control_supported(void)
612{
613 return amdgpu_acpi_priv.atcs.functions.power_shift_control;
614}
615
616
617
618
619
620
621
622
623
624
625int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev)
626{
627 union acpi_object *info;
628 struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
629
630 if (!atcs->functions.pcie_dev_rdy)
631 return -EINVAL;
632
633 info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_PCIE_DEVICE_READY_NOTIFICATION, NULL);
634 if (!info)
635 return -EIO;
636
637 kfree(info);
638
639 return 0;
640}
641
642
643
644
645
646
647
648
649
650
651
652
653int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
654 u8 perf_req, bool advertise)
655{
656 union acpi_object *info;
657 struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
658 struct atcs_pref_req_input atcs_input;
659 struct atcs_pref_req_output atcs_output;
660 struct acpi_buffer params;
661 size_t size;
662 u32 retry = 3;
663
664 if (amdgpu_acpi_pcie_notify_device_ready(adev))
665 return -EINVAL;
666
667 if (!atcs->functions.pcie_perf_req)
668 return -EINVAL;
669
670 atcs_input.size = sizeof(struct atcs_pref_req_input);
671
672 atcs_input.client_id = adev->pdev->devfn | (adev->pdev->bus->number << 8);
673 atcs_input.valid_flags_mask = ATCS_VALID_FLAGS_MASK;
674 atcs_input.flags = ATCS_WAIT_FOR_COMPLETION;
675 if (advertise)
676 atcs_input.flags |= ATCS_ADVERTISE_CAPS;
677 atcs_input.req_type = ATCS_PCIE_LINK_SPEED;
678 atcs_input.perf_req = perf_req;
679
680 params.length = sizeof(struct atcs_pref_req_input);
681 params.pointer = &atcs_input;
682
683 while (retry--) {
684 info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_PCIE_PERFORMANCE_REQUEST, ¶ms);
685 if (!info)
686 return -EIO;
687
688 memset(&atcs_output, 0, sizeof(atcs_output));
689
690 size = *(u16 *) info->buffer.pointer;
691 if (size < 3) {
692 DRM_INFO("ATCS buffer is too small: %zu\n", size);
693 kfree(info);
694 return -EINVAL;
695 }
696 size = min(sizeof(atcs_output), size);
697
698 memcpy(&atcs_output, info->buffer.pointer, size);
699
700 kfree(info);
701
702 switch (atcs_output.ret_val) {
703 case ATCS_REQUEST_REFUSED:
704 default:
705 return -EINVAL;
706 case ATCS_REQUEST_COMPLETE:
707 return 0;
708 case ATCS_REQUEST_IN_PROGRESS:
709 udelay(10);
710 break;
711 }
712 }
713
714 return 0;
715}
716
717
718
719
720
721
722
723
724
725
726
727
728
729int amdgpu_acpi_power_shift_control(struct amdgpu_device *adev,
730 u8 dev_state, bool drv_state)
731{
732 union acpi_object *info;
733 struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
734 struct atcs_pwr_shift_input atcs_input;
735 struct acpi_buffer params;
736
737 if (!amdgpu_acpi_is_power_shift_control_supported())
738 return -EINVAL;
739
740 atcs_input.size = sizeof(struct atcs_pwr_shift_input);
741
742 atcs_input.dgpu_id = adev->pdev->devfn | (adev->pdev->bus->number << 8);
743 atcs_input.dev_acpi_state = dev_state;
744 atcs_input.drv_state = drv_state;
745
746 params.length = sizeof(struct atcs_pwr_shift_input);
747 params.pointer = &atcs_input;
748
749 info = amdgpu_atcs_call(atcs, ATCS_FUNCTION_POWER_SHIFT_CONTROL, ¶ms);
750 if (!info) {
751 DRM_ERROR("ATCS PSC update failed\n");
752 return -EIO;
753 }
754
755 return 0;
756}
757
758
759
760
761
762
763
764
765
766
767int amdgpu_acpi_smart_shift_update(struct drm_device *dev, enum amdgpu_ss ss_state)
768{
769 struct amdgpu_device *adev = drm_to_adev(dev);
770 int r;
771
772 if (!amdgpu_device_supports_smart_shift(dev))
773 return 0;
774
775 switch (ss_state) {
776
777
778
779
780 case AMDGPU_SS_DRV_LOAD:
781 r = amdgpu_acpi_power_shift_control(adev,
782 AMDGPU_ATCS_PSC_DEV_STATE_D0,
783 AMDGPU_ATCS_PSC_DRV_STATE_OPR);
784 break;
785 case AMDGPU_SS_DEV_D0:
786 r = amdgpu_acpi_power_shift_control(adev,
787 AMDGPU_ATCS_PSC_DEV_STATE_D0,
788 AMDGPU_ATCS_PSC_DRV_STATE_OPR);
789 break;
790 case AMDGPU_SS_DEV_D3:
791 r = amdgpu_acpi_power_shift_control(adev,
792 AMDGPU_ATCS_PSC_DEV_STATE_D3_HOT,
793 AMDGPU_ATCS_PSC_DRV_STATE_NOT_OPR);
794 break;
795 case AMDGPU_SS_DRV_UNLOAD:
796 r = amdgpu_acpi_power_shift_control(adev,
797 AMDGPU_ATCS_PSC_DEV_STATE_D0,
798 AMDGPU_ATCS_PSC_DRV_STATE_NOT_OPR);
799 break;
800 default:
801 return -EINVAL;
802 }
803
804 return r;
805}
806
807
808
809
810
811
812
813
814
815
816
817
818static int amdgpu_acpi_event(struct notifier_block *nb,
819 unsigned long val,
820 void *data)
821{
822 struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, acpi_nb);
823 struct acpi_bus_event *entry = (struct acpi_bus_event *)data;
824
825 if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) {
826 if (power_supply_is_system_supplied() > 0)
827 DRM_DEBUG_DRIVER("pm: AC\n");
828 else
829 DRM_DEBUG_DRIVER("pm: DC\n");
830
831 amdgpu_pm_acpi_event_handler(adev);
832 }
833
834
835 return amdgpu_atif_handler(adev, entry);
836}
837
838
839
840
841
842
843
844
845
846
847
848int amdgpu_acpi_init(struct amdgpu_device *adev)
849{
850 struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;
851
852#if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
853 if (atif->notifications.brightness_change) {
854 if (amdgpu_device_has_dc_support(adev)) {
855#if defined(CONFIG_DRM_AMD_DC)
856 struct amdgpu_display_manager *dm = &adev->dm;
857 if (dm->backlight_dev)
858 atif->bd = dm->backlight_dev;
859#endif
860 } else {
861 struct drm_encoder *tmp;
862
863
864 list_for_each_entry(tmp, &adev_to_drm(adev)->mode_config.encoder_list,
865 head) {
866 struct amdgpu_encoder *enc = to_amdgpu_encoder(tmp);
867
868 if ((enc->devices & (ATOM_DEVICE_LCD_SUPPORT)) &&
869 enc->enc_priv) {
870 struct amdgpu_encoder_atom_dig *dig = enc->enc_priv;
871 if (dig->bl_dev) {
872 atif->bd = dig->bl_dev;
873 break;
874 }
875 }
876 }
877 }
878 }
879#endif
880 adev->acpi_nb.notifier_call = amdgpu_acpi_event;
881 register_acpi_notifier(&adev->acpi_nb);
882
883 return 0;
884}
885
886void amdgpu_acpi_get_backlight_caps(struct amdgpu_dm_backlight_caps *caps)
887{
888 struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;
889
890 caps->caps_valid = atif->backlight_caps.caps_valid;
891 caps->min_input_signal = atif->backlight_caps.min_input_signal;
892 caps->max_input_signal = atif->backlight_caps.max_input_signal;
893}
894
895
896
897
898
899
900
901
902void amdgpu_acpi_fini(struct amdgpu_device *adev)
903{
904 unregister_acpi_notifier(&adev->acpi_nb);
905}
906
907
908
909
910
911
912
913
914
915static bool amdgpu_atif_pci_probe_handle(struct pci_dev *pdev)
916{
917 char acpi_method_name[255] = { 0 };
918 struct acpi_buffer buffer = {sizeof(acpi_method_name), acpi_method_name};
919 acpi_handle dhandle, atif_handle;
920 acpi_status status;
921 int ret;
922
923 dhandle = ACPI_HANDLE(&pdev->dev);
924 if (!dhandle)
925 return false;
926
927 status = acpi_get_handle(dhandle, "ATIF", &atif_handle);
928 if (ACPI_FAILURE(status)) {
929 return false;
930 }
931 amdgpu_acpi_priv.atif.handle = atif_handle;
932 acpi_get_name(amdgpu_acpi_priv.atif.handle, ACPI_FULL_PATHNAME, &buffer);
933 DRM_DEBUG_DRIVER("Found ATIF handle %s\n", acpi_method_name);
934 ret = amdgpu_atif_verify_interface(&amdgpu_acpi_priv.atif);
935 if (ret) {
936 amdgpu_acpi_priv.atif.handle = 0;
937 return false;
938 }
939 return true;
940}
941
942
943
944
945
946
947
948
949
950static bool amdgpu_atcs_pci_probe_handle(struct pci_dev *pdev)
951{
952 char acpi_method_name[255] = { 0 };
953 struct acpi_buffer buffer = { sizeof(acpi_method_name), acpi_method_name };
954 acpi_handle dhandle, atcs_handle;
955 acpi_status status;
956 int ret;
957
958 dhandle = ACPI_HANDLE(&pdev->dev);
959 if (!dhandle)
960 return false;
961
962 status = acpi_get_handle(dhandle, "ATCS", &atcs_handle);
963 if (ACPI_FAILURE(status)) {
964 return false;
965 }
966 amdgpu_acpi_priv.atcs.handle = atcs_handle;
967 acpi_get_name(amdgpu_acpi_priv.atcs.handle, ACPI_FULL_PATHNAME, &buffer);
968 DRM_DEBUG_DRIVER("Found ATCS handle %s\n", acpi_method_name);
969 ret = amdgpu_atcs_verify_interface(&amdgpu_acpi_priv.atcs);
970 if (ret) {
971 amdgpu_acpi_priv.atcs.handle = 0;
972 return false;
973 }
974 return true;
975}
976
977
978
979
980
981
982
983void amdgpu_acpi_detect(void)
984{
985 struct amdgpu_atif *atif = &amdgpu_acpi_priv.atif;
986 struct amdgpu_atcs *atcs = &amdgpu_acpi_priv.atcs;
987 struct pci_dev *pdev = NULL;
988 int ret;
989
990 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_VGA << 8, pdev)) != NULL) {
991 if (!atif->handle)
992 amdgpu_atif_pci_probe_handle(pdev);
993 if (!atcs->handle)
994 amdgpu_atcs_pci_probe_handle(pdev);
995 }
996
997 while ((pdev = pci_get_class(PCI_CLASS_DISPLAY_OTHER << 8, pdev)) != NULL) {
998 if (!atif->handle)
999 amdgpu_atif_pci_probe_handle(pdev);
1000 if (!atcs->handle)
1001 amdgpu_atcs_pci_probe_handle(pdev);
1002 }
1003
1004 if (atif->functions.sbios_requests && !atif->functions.system_params) {
1005
1006
1007
1008
1009 atif->functions.system_params = true;
1010 }
1011
1012 if (atif->functions.system_params) {
1013 ret = amdgpu_atif_get_notification_params(atif);
1014 if (ret) {
1015 DRM_DEBUG_DRIVER("Call to GET_SYSTEM_PARAMS failed: %d\n",
1016 ret);
1017
1018 atif->notification_cfg.enabled = false;
1019 }
1020 }
1021
1022 if (atif->functions.query_backlight_transfer_characteristics) {
1023 ret = amdgpu_atif_query_backlight_caps(atif);
1024 if (ret) {
1025 DRM_DEBUG_DRIVER("Call to QUERY_BACKLIGHT_TRANSFER_CHARACTERISTICS failed: %d\n",
1026 ret);
1027 atif->backlight_caps.caps_valid = false;
1028 }
1029 } else {
1030 atif->backlight_caps.caps_valid = false;
1031 }
1032}
1033
1034
1035
1036
1037
1038
1039
1040
1041bool amdgpu_acpi_is_s0ix_supported(struct amdgpu_device *adev)
1042{
1043#if IS_ENABLED(CONFIG_AMD_PMC) && IS_ENABLED(CONFIG_SUSPEND)
1044 if (acpi_gbl_FADT.flags & ACPI_FADT_LOW_POWER_S0) {
1045 if (adev->flags & AMD_IS_APU)
1046 return pm_suspend_target_state == PM_SUSPEND_TO_IDLE;
1047 }
1048#endif
1049 return false;
1050}
1051