mm: hugetlb: fix hugepage memory leak caused by wrong reserve count
[linux/fpc-iii.git] / drivers / gpu / drm / amd / amdgpu / amdgpu_acpi.c
bloba142d5ae148d91eaa89b8a92c95836ba0d0b45f3
1 /*
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 <acpi/video.h>
29 #include <drm/drmP.h>
30 #include <drm/drm_crtc_helper.h>
31 #include "amdgpu.h"
32 #include "amdgpu_acpi.h"
33 #include "atom.h"
35 #define ACPI_AC_CLASS "ac_adapter"
37 extern void amdgpu_pm_acpi_event_handler(struct amdgpu_device *adev);
39 struct atif_verify_interface {
40 u16 size; /* structure size in bytes (includes size field) */
41 u16 version; /* version */
42 u32 notification_mask; /* supported notifications mask */
43 u32 function_bits; /* supported functions bit vector */
44 } __packed;
46 struct atif_system_params {
47 u16 size; /* structure size in bytes (includes size field) */
48 u32 valid_mask; /* valid flags mask */
49 u32 flags; /* flags */
50 u8 command_code; /* notify command code */
51 } __packed;
53 struct atif_sbios_requests {
54 u16 size; /* structure size in bytes (includes size field) */
55 u32 pending; /* pending sbios requests */
56 u8 panel_exp_mode; /* panel expansion mode */
57 u8 thermal_gfx; /* thermal state: target gfx controller */
58 u8 thermal_state; /* thermal state: state id (0: exit state, non-0: state) */
59 u8 forced_power_gfx; /* forced power state: target gfx controller */
60 u8 forced_power_state; /* forced power state: state id */
61 u8 system_power_src; /* system power source */
62 u8 backlight_level; /* panel backlight level (0-255) */
63 } __packed;
65 #define ATIF_NOTIFY_MASK 0x3
66 #define ATIF_NOTIFY_NONE 0
67 #define ATIF_NOTIFY_81 1
68 #define ATIF_NOTIFY_N 2
70 struct atcs_verify_interface {
71 u16 size; /* structure size in bytes (includes size field) */
72 u16 version; /* version */
73 u32 function_bits; /* supported functions bit vector */
74 } __packed;
76 #define ATCS_VALID_FLAGS_MASK 0x3
78 struct atcs_pref_req_input {
79 u16 size; /* structure size in bytes (includes size field) */
80 u16 client_id; /* client id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */
81 u16 valid_flags_mask; /* valid flags mask */
82 u16 flags; /* flags */
83 u8 req_type; /* request type */
84 u8 perf_req; /* performance request */
85 } __packed;
87 struct atcs_pref_req_output {
88 u16 size; /* structure size in bytes (includes size field) */
89 u8 ret_val; /* return value */
90 } __packed;
92 /* Call the ATIF method
94 /**
95 * amdgpu_atif_call - call an ATIF method
97 * @handle: acpi handle
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(acpi_handle handle, int function,
105 struct acpi_buffer *params)
107 acpi_status status;
108 union acpi_object atif_arg_elements[2];
109 struct acpi_object_list atif_arg;
110 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
112 atif_arg.count = 2;
113 atif_arg.pointer = &atif_arg_elements[0];
115 atif_arg_elements[0].type = ACPI_TYPE_INTEGER;
116 atif_arg_elements[0].integer.value = function;
118 if (params) {
119 atif_arg_elements[1].type = ACPI_TYPE_BUFFER;
120 atif_arg_elements[1].buffer.length = params->length;
121 atif_arg_elements[1].buffer.pointer = params->pointer;
122 } else {
123 /* We need a second fake parameter */
124 atif_arg_elements[1].type = ACPI_TYPE_INTEGER;
125 atif_arg_elements[1].integer.value = 0;
128 status = acpi_evaluate_object(handle, "ATIF", &atif_arg, &buffer);
130 /* Fail only if calling the method fails and ATIF is supported */
131 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
132 DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",
133 acpi_format_exception(status));
134 kfree(buffer.pointer);
135 return NULL;
138 return buffer.pointer;
142 * amdgpu_atif_parse_notification - parse supported notifications
144 * @n: supported notifications struct
145 * @mask: supported notifications mask from ATIF
147 * Use the supported notifications mask from ATIF function
148 * ATIF_FUNCTION_VERIFY_INTERFACE to determine what notifications
149 * are supported (all asics).
151 static void amdgpu_atif_parse_notification(struct amdgpu_atif_notifications *n, u32 mask)
153 n->display_switch = mask & ATIF_DISPLAY_SWITCH_REQUEST_SUPPORTED;
154 n->expansion_mode_change = mask & ATIF_EXPANSION_MODE_CHANGE_REQUEST_SUPPORTED;
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->display_conf_change = mask & ATIF_DISPLAY_CONF_CHANGE_REQUEST_SUPPORTED;
159 n->px_gfx_switch = mask & ATIF_PX_GFX_SWITCH_REQUEST_SUPPORTED;
160 n->brightness_change = mask & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST_SUPPORTED;
161 n->dgpu_display_event = mask & ATIF_DGPU_DISPLAY_EVENT_SUPPORTED;
165 * amdgpu_atif_parse_functions - parse supported functions
167 * @f: supported functions struct
168 * @mask: supported functions mask from ATIF
170 * Use the supported functions mask from ATIF function
171 * ATIF_FUNCTION_VERIFY_INTERFACE to determine what functions
172 * are supported (all asics).
174 static void amdgpu_atif_parse_functions(struct amdgpu_atif_functions *f, u32 mask)
176 f->system_params = mask & ATIF_GET_SYSTEM_PARAMETERS_SUPPORTED;
177 f->sbios_requests = mask & ATIF_GET_SYSTEM_BIOS_REQUESTS_SUPPORTED;
178 f->select_active_disp = mask & ATIF_SELECT_ACTIVE_DISPLAYS_SUPPORTED;
179 f->lid_state = mask & ATIF_GET_LID_STATE_SUPPORTED;
180 f->get_tv_standard = mask & ATIF_GET_TV_STANDARD_FROM_CMOS_SUPPORTED;
181 f->set_tv_standard = mask & ATIF_SET_TV_STANDARD_IN_CMOS_SUPPORTED;
182 f->get_panel_expansion_mode = mask & ATIF_GET_PANEL_EXPANSION_MODE_FROM_CMOS_SUPPORTED;
183 f->set_panel_expansion_mode = mask & ATIF_SET_PANEL_EXPANSION_MODE_IN_CMOS_SUPPORTED;
184 f->temperature_change = mask & ATIF_TEMPERATURE_CHANGE_NOTIFICATION_SUPPORTED;
185 f->graphics_device_types = mask & ATIF_GET_GRAPHICS_DEVICE_TYPES_SUPPORTED;
189 * amdgpu_atif_verify_interface - verify ATIF
191 * @handle: acpi handle
192 * @atif: amdgpu atif struct
194 * Execute the ATIF_FUNCTION_VERIFY_INTERFACE ATIF function
195 * to initialize ATIF and determine what features are supported
196 * (all asics).
197 * returns 0 on success, error on failure.
199 static int amdgpu_atif_verify_interface(acpi_handle handle,
200 struct amdgpu_atif *atif)
202 union acpi_object *info;
203 struct atif_verify_interface output;
204 size_t size;
205 int err = 0;
207 info = amdgpu_atif_call(handle, ATIF_FUNCTION_VERIFY_INTERFACE, NULL);
208 if (!info)
209 return -EIO;
211 memset(&output, 0, sizeof(output));
213 size = *(u16 *) info->buffer.pointer;
214 if (size < 12) {
215 DRM_INFO("ATIF buffer is too small: %zu\n", size);
216 err = -EINVAL;
217 goto out;
219 size = min(sizeof(output), size);
221 memcpy(&output, info->buffer.pointer, size);
223 /* TODO: check version? */
224 DRM_DEBUG_DRIVER("ATIF version %u\n", output.version);
226 amdgpu_atif_parse_notification(&atif->notifications, output.notification_mask);
227 amdgpu_atif_parse_functions(&atif->functions, output.function_bits);
229 out:
230 kfree(info);
231 return err;
235 * amdgpu_atif_get_notification_params - determine notify configuration
237 * @handle: acpi handle
238 * @n: atif notification configuration struct
240 * Execute the ATIF_FUNCTION_GET_SYSTEM_PARAMETERS ATIF function
241 * to determine if a notifier is used and if so which one
242 * (all asics). This is either Notify(VGA, 0x81) or Notify(VGA, n)
243 * where n is specified in the result if a notifier is used.
244 * Returns 0 on success, error on failure.
246 static int amdgpu_atif_get_notification_params(acpi_handle handle,
247 struct amdgpu_atif_notification_cfg *n)
249 union acpi_object *info;
250 struct atif_system_params params;
251 size_t size;
252 int err = 0;
254 info = amdgpu_atif_call(handle, ATIF_FUNCTION_GET_SYSTEM_PARAMETERS, NULL);
255 if (!info) {
256 err = -EIO;
257 goto out;
260 size = *(u16 *) info->buffer.pointer;
261 if (size < 10) {
262 err = -EINVAL;
263 goto out;
266 memset(&params, 0, sizeof(params));
267 size = min(sizeof(params), size);
268 memcpy(&params, info->buffer.pointer, size);
270 DRM_DEBUG_DRIVER("SYSTEM_PARAMS: mask = %#x, flags = %#x\n",
271 params.flags, params.valid_mask);
272 params.flags = params.flags & params.valid_mask;
274 if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_NONE) {
275 n->enabled = false;
276 n->command_code = 0;
277 } else if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_81) {
278 n->enabled = true;
279 n->command_code = 0x81;
280 } else {
281 if (size < 11) {
282 err = -EINVAL;
283 goto out;
285 n->enabled = true;
286 n->command_code = params.command_code;
289 out:
290 DRM_DEBUG_DRIVER("Notification %s, command code = %#x\n",
291 (n->enabled ? "enabled" : "disabled"),
292 n->command_code);
293 kfree(info);
294 return err;
298 * amdgpu_atif_get_sbios_requests - get requested sbios event
300 * @handle: acpi handle
301 * @req: atif sbios request struct
303 * Execute the ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS ATIF function
304 * to determine what requests the sbios is making to the driver
305 * (all asics).
306 * Returns 0 on success, error on failure.
308 static int amdgpu_atif_get_sbios_requests(acpi_handle handle,
309 struct atif_sbios_requests *req)
311 union acpi_object *info;
312 size_t size;
313 int count = 0;
315 info = amdgpu_atif_call(handle, ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS, NULL);
316 if (!info)
317 return -EIO;
319 size = *(u16 *)info->buffer.pointer;
320 if (size < 0xd) {
321 count = -EINVAL;
322 goto out;
324 memset(req, 0, sizeof(*req));
326 size = min(sizeof(*req), size);
327 memcpy(req, info->buffer.pointer, size);
328 DRM_DEBUG_DRIVER("SBIOS pending requests: %#x\n", req->pending);
330 count = hweight32(req->pending);
332 out:
333 kfree(info);
334 return count;
338 * amdgpu_atif_handler - handle ATIF notify requests
340 * @adev: amdgpu_device pointer
341 * @event: atif sbios request struct
343 * Checks the acpi event and if it matches an atif event,
344 * handles it.
345 * Returns NOTIFY code
347 int amdgpu_atif_handler(struct amdgpu_device *adev,
348 struct acpi_bus_event *event)
350 struct amdgpu_atif *atif = &adev->atif;
351 struct atif_sbios_requests req;
352 acpi_handle handle;
353 int count;
355 DRM_DEBUG_DRIVER("event, device_class = %s, type = %#x\n",
356 event->device_class, event->type);
358 if (strcmp(event->device_class, ACPI_VIDEO_CLASS) != 0)
359 return NOTIFY_DONE;
361 if (!atif->notification_cfg.enabled ||
362 event->type != atif->notification_cfg.command_code)
363 /* Not our event */
364 return NOTIFY_DONE;
366 /* Check pending SBIOS requests */
367 handle = ACPI_HANDLE(&adev->pdev->dev);
368 count = amdgpu_atif_get_sbios_requests(handle, &req);
370 if (count <= 0)
371 return NOTIFY_DONE;
373 DRM_DEBUG_DRIVER("ATIF: %d pending SBIOS requests\n", count);
375 if (req.pending & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST) {
376 struct amdgpu_encoder *enc = atif->encoder_for_bl;
378 if (enc) {
379 struct amdgpu_encoder_atom_dig *dig = enc->enc_priv;
381 DRM_DEBUG_DRIVER("Changing brightness to %d\n",
382 req.backlight_level);
384 amdgpu_display_backlight_set_level(adev, enc, req.backlight_level);
386 #if defined(CONFIG_BACKLIGHT_CLASS_DEVICE) || defined(CONFIG_BACKLIGHT_CLASS_DEVICE_MODULE)
387 backlight_force_update(dig->bl_dev,
388 BACKLIGHT_UPDATE_HOTKEY);
389 #endif
392 /* TODO: check other events */
394 /* We've handled the event, stop the notifier chain. The ACPI interface
395 * overloads ACPI_VIDEO_NOTIFY_PROBE, we don't want to send that to
396 * userspace if the event was generated only to signal a SBIOS
397 * request.
399 return NOTIFY_BAD;
402 /* Call the ATCS method
405 * amdgpu_atcs_call - call an ATCS method
407 * @handle: acpi handle
408 * @function: the ATCS function to execute
409 * @params: ATCS function params
411 * Executes the requested ATCS function (all asics).
412 * Returns a pointer to the acpi output buffer.
414 static union acpi_object *amdgpu_atcs_call(acpi_handle handle, int function,
415 struct acpi_buffer *params)
417 acpi_status status;
418 union acpi_object atcs_arg_elements[2];
419 struct acpi_object_list atcs_arg;
420 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
422 atcs_arg.count = 2;
423 atcs_arg.pointer = &atcs_arg_elements[0];
425 atcs_arg_elements[0].type = ACPI_TYPE_INTEGER;
426 atcs_arg_elements[0].integer.value = function;
428 if (params) {
429 atcs_arg_elements[1].type = ACPI_TYPE_BUFFER;
430 atcs_arg_elements[1].buffer.length = params->length;
431 atcs_arg_elements[1].buffer.pointer = params->pointer;
432 } else {
433 /* We need a second fake parameter */
434 atcs_arg_elements[1].type = ACPI_TYPE_INTEGER;
435 atcs_arg_elements[1].integer.value = 0;
438 status = acpi_evaluate_object(handle, "ATCS", &atcs_arg, &buffer);
440 /* Fail only if calling the method fails and ATIF is supported */
441 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
442 DRM_DEBUG_DRIVER("failed to evaluate ATCS got %s\n",
443 acpi_format_exception(status));
444 kfree(buffer.pointer);
445 return NULL;
448 return buffer.pointer;
452 * amdgpu_atcs_parse_functions - parse supported functions
454 * @f: supported functions struct
455 * @mask: supported functions mask from ATCS
457 * Use the supported functions mask from ATCS function
458 * ATCS_FUNCTION_VERIFY_INTERFACE to determine what functions
459 * are supported (all asics).
461 static void amdgpu_atcs_parse_functions(struct amdgpu_atcs_functions *f, u32 mask)
463 f->get_ext_state = mask & ATCS_GET_EXTERNAL_STATE_SUPPORTED;
464 f->pcie_perf_req = mask & ATCS_PCIE_PERFORMANCE_REQUEST_SUPPORTED;
465 f->pcie_dev_rdy = mask & ATCS_PCIE_DEVICE_READY_NOTIFICATION_SUPPORTED;
466 f->pcie_bus_width = mask & ATCS_SET_PCIE_BUS_WIDTH_SUPPORTED;
470 * amdgpu_atcs_verify_interface - verify ATCS
472 * @handle: acpi handle
473 * @atcs: amdgpu atcs struct
475 * Execute the ATCS_FUNCTION_VERIFY_INTERFACE ATCS function
476 * to initialize ATCS and determine what features are supported
477 * (all asics).
478 * returns 0 on success, error on failure.
480 static int amdgpu_atcs_verify_interface(acpi_handle handle,
481 struct amdgpu_atcs *atcs)
483 union acpi_object *info;
484 struct atcs_verify_interface output;
485 size_t size;
486 int err = 0;
488 info = amdgpu_atcs_call(handle, ATCS_FUNCTION_VERIFY_INTERFACE, NULL);
489 if (!info)
490 return -EIO;
492 memset(&output, 0, sizeof(output));
494 size = *(u16 *) info->buffer.pointer;
495 if (size < 8) {
496 DRM_INFO("ATCS buffer is too small: %zu\n", size);
497 err = -EINVAL;
498 goto out;
500 size = min(sizeof(output), size);
502 memcpy(&output, info->buffer.pointer, size);
504 /* TODO: check version? */
505 DRM_DEBUG_DRIVER("ATCS version %u\n", output.version);
507 amdgpu_atcs_parse_functions(&atcs->functions, output.function_bits);
509 out:
510 kfree(info);
511 return err;
515 * amdgpu_acpi_is_pcie_performance_request_supported
517 * @adev: amdgpu_device pointer
519 * Check if the ATCS pcie_perf_req and pcie_dev_rdy methods
520 * are supported (all asics).
521 * returns true if supported, false if not.
523 bool amdgpu_acpi_is_pcie_performance_request_supported(struct amdgpu_device *adev)
525 struct amdgpu_atcs *atcs = &adev->atcs;
527 if (atcs->functions.pcie_perf_req && atcs->functions.pcie_dev_rdy)
528 return true;
530 return false;
534 * amdgpu_acpi_pcie_notify_device_ready
536 * @adev: amdgpu_device pointer
538 * Executes the PCIE_DEVICE_READY_NOTIFICATION method
539 * (all asics).
540 * returns 0 on success, error on failure.
542 int amdgpu_acpi_pcie_notify_device_ready(struct amdgpu_device *adev)
544 acpi_handle handle;
545 union acpi_object *info;
546 struct amdgpu_atcs *atcs = &adev->atcs;
548 /* Get the device handle */
549 handle = ACPI_HANDLE(&adev->pdev->dev);
550 if (!handle)
551 return -EINVAL;
553 if (!atcs->functions.pcie_dev_rdy)
554 return -EINVAL;
556 info = amdgpu_atcs_call(handle, ATCS_FUNCTION_PCIE_DEVICE_READY_NOTIFICATION, NULL);
557 if (!info)
558 return -EIO;
560 kfree(info);
562 return 0;
566 * amdgpu_acpi_pcie_performance_request
568 * @adev: amdgpu_device pointer
569 * @perf_req: requested perf level (pcie gen speed)
570 * @advertise: set advertise caps flag if set
572 * Executes the PCIE_PERFORMANCE_REQUEST method to
573 * change the pcie gen speed (all asics).
574 * returns 0 on success, error on failure.
576 int amdgpu_acpi_pcie_performance_request(struct amdgpu_device *adev,
577 u8 perf_req, bool advertise)
579 acpi_handle handle;
580 union acpi_object *info;
581 struct amdgpu_atcs *atcs = &adev->atcs;
582 struct atcs_pref_req_input atcs_input;
583 struct atcs_pref_req_output atcs_output;
584 struct acpi_buffer params;
585 size_t size;
586 u32 retry = 3;
588 /* Get the device handle */
589 handle = ACPI_HANDLE(&adev->pdev->dev);
590 if (!handle)
591 return -EINVAL;
593 if (!atcs->functions.pcie_perf_req)
594 return -EINVAL;
596 atcs_input.size = sizeof(struct atcs_pref_req_input);
597 /* client id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */
598 atcs_input.client_id = adev->pdev->devfn | (adev->pdev->bus->number << 8);
599 atcs_input.valid_flags_mask = ATCS_VALID_FLAGS_MASK;
600 atcs_input.flags = ATCS_WAIT_FOR_COMPLETION;
601 if (advertise)
602 atcs_input.flags |= ATCS_ADVERTISE_CAPS;
603 atcs_input.req_type = ATCS_PCIE_LINK_SPEED;
604 atcs_input.perf_req = perf_req;
606 params.length = sizeof(struct atcs_pref_req_input);
607 params.pointer = &atcs_input;
609 while (retry--) {
610 info = amdgpu_atcs_call(handle, ATCS_FUNCTION_PCIE_PERFORMANCE_REQUEST, &params);
611 if (!info)
612 return -EIO;
614 memset(&atcs_output, 0, sizeof(atcs_output));
616 size = *(u16 *) info->buffer.pointer;
617 if (size < 3) {
618 DRM_INFO("ATCS buffer is too small: %zu\n", size);
619 kfree(info);
620 return -EINVAL;
622 size = min(sizeof(atcs_output), size);
624 memcpy(&atcs_output, info->buffer.pointer, size);
626 kfree(info);
628 switch (atcs_output.ret_val) {
629 case ATCS_REQUEST_REFUSED:
630 default:
631 return -EINVAL;
632 case ATCS_REQUEST_COMPLETE:
633 return 0;
634 case ATCS_REQUEST_IN_PROGRESS:
635 udelay(10);
636 break;
640 return 0;
644 * amdgpu_acpi_event - handle notify events
646 * @nb: notifier block
647 * @val: val
648 * @data: acpi event
650 * Calls relevant amdgpu functions in response to various
651 * acpi events.
652 * Returns NOTIFY code
654 static int amdgpu_acpi_event(struct notifier_block *nb,
655 unsigned long val,
656 void *data)
658 struct amdgpu_device *adev = container_of(nb, struct amdgpu_device, acpi_nb);
659 struct acpi_bus_event *entry = (struct acpi_bus_event *)data;
661 if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) {
662 if (power_supply_is_system_supplied() > 0)
663 DRM_DEBUG_DRIVER("pm: AC\n");
664 else
665 DRM_DEBUG_DRIVER("pm: DC\n");
667 amdgpu_pm_acpi_event_handler(adev);
670 /* Check for pending SBIOS requests */
671 return amdgpu_atif_handler(adev, entry);
674 /* Call all ACPI methods here */
676 * amdgpu_acpi_init - init driver acpi support
678 * @adev: amdgpu_device pointer
680 * Verifies the AMD ACPI interfaces and registers with the acpi
681 * notifier chain (all asics).
682 * Returns 0 on success, error on failure.
684 int amdgpu_acpi_init(struct amdgpu_device *adev)
686 acpi_handle handle;
687 struct amdgpu_atif *atif = &adev->atif;
688 struct amdgpu_atcs *atcs = &adev->atcs;
689 int ret;
691 /* Get the device handle */
692 handle = ACPI_HANDLE(&adev->pdev->dev);
694 if (!adev->bios || !handle)
695 return 0;
697 /* Call the ATCS method */
698 ret = amdgpu_atcs_verify_interface(handle, atcs);
699 if (ret) {
700 DRM_DEBUG_DRIVER("Call to ATCS verify_interface failed: %d\n", ret);
703 /* Call the ATIF method */
704 ret = amdgpu_atif_verify_interface(handle, atif);
705 if (ret) {
706 DRM_DEBUG_DRIVER("Call to ATIF verify_interface failed: %d\n", ret);
707 goto out;
710 if (atif->notifications.brightness_change) {
711 struct drm_encoder *tmp;
713 /* Find the encoder controlling the brightness */
714 list_for_each_entry(tmp, &adev->ddev->mode_config.encoder_list,
715 head) {
716 struct amdgpu_encoder *enc = to_amdgpu_encoder(tmp);
718 if ((enc->devices & (ATOM_DEVICE_LCD_SUPPORT)) &&
719 enc->enc_priv) {
720 if (adev->is_atom_bios) {
721 struct amdgpu_encoder_atom_dig *dig = enc->enc_priv;
722 if (dig->bl_dev) {
723 atif->encoder_for_bl = enc;
724 break;
731 if (atif->functions.sbios_requests && !atif->functions.system_params) {
732 /* XXX check this workraround, if sbios request function is
733 * present we have to see how it's configured in the system
734 * params
736 atif->functions.system_params = true;
739 if (atif->functions.system_params) {
740 ret = amdgpu_atif_get_notification_params(handle,
741 &atif->notification_cfg);
742 if (ret) {
743 DRM_DEBUG_DRIVER("Call to GET_SYSTEM_PARAMS failed: %d\n",
744 ret);
745 /* Disable notification */
746 atif->notification_cfg.enabled = false;
750 out:
751 adev->acpi_nb.notifier_call = amdgpu_acpi_event;
752 register_acpi_notifier(&adev->acpi_nb);
754 return ret;
758 * amdgpu_acpi_fini - tear down driver acpi support
760 * @adev: amdgpu_device pointer
762 * Unregisters with the acpi notifier chain (all asics).
764 void amdgpu_acpi_fini(struct amdgpu_device *adev)
766 unregister_acpi_notifier(&adev->acpi_nb);