drm/radeon: Sync to Linux 3.11
[dragonfly.git] / sys / dev / drm / radeon / radeon_acpi.c
CommitLineData
926deccb
FT
1/*
2 * Copyright 2012 Advanced Micro Devices, Inc.
3 *
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:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
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.
21 *
22 * $FreeBSD: head/sys/dev/drm2/radeon/radeon_acpi.c 254885 2013-08-25 19:37:15Z dumbbell $
23 */
24
25#include <drm/drmP.h>
26#include <drm/drm_crtc_helper.h>
27#include "radeon.h"
28#include "radeon_acpi.h"
29#include "atom.h"
30
31#define ACPI_AC_CLASS "ac_adapter"
32
33struct atif_verify_interface {
34 u16 size; /* structure size in bytes (includes size field) */
35 u16 version; /* version */
36 u32 notification_mask; /* supported notifications mask */
37 u32 function_bits; /* supported functions bit vector */
38} __packed;
39
40struct atif_system_params {
41 u16 size; /* structure size in bytes (includes size field) */
42 u32 valid_mask; /* valid flags mask */
43 u32 flags; /* flags */
44 u8 command_code; /* notify command code */
45} __packed;
46
47struct atif_sbios_requests {
48 u16 size; /* structure size in bytes (includes size field) */
49 u32 pending; /* pending sbios requests */
50 u8 panel_exp_mode; /* panel expansion mode */
51 u8 thermal_gfx; /* thermal state: target gfx controller */
52 u8 thermal_state; /* thermal state: state id (0: exit state, non-0: state) */
53 u8 forced_power_gfx; /* forced power state: target gfx controller */
54 u8 forced_power_state; /* forced power state: state id */
55 u8 system_power_src; /* system power source */
56 u8 backlight_level; /* panel backlight level (0-255) */
57} __packed;
58
59#define ATIF_NOTIFY_MASK 0x3
60#define ATIF_NOTIFY_NONE 0
61#define ATIF_NOTIFY_81 1
62#define ATIF_NOTIFY_N 2
63
64struct atcs_verify_interface {
65 u16 size; /* structure size in bytes (includes size field) */
66 u16 version; /* version */
67 u32 function_bits; /* supported functions bit vector */
68} __packed;
69
57e252bf
MN
70#define ATCS_VALID_FLAGS_MASK 0x3
71
72struct atcs_pref_req_input {
73 u16 size; /* structure size in bytes (includes size field) */
74 u16 client_id; /* client id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */
75 u16 valid_flags_mask; /* valid flags mask */
76 u16 flags; /* flags */
77 u8 req_type; /* request type */
78 u8 perf_req; /* performance request */
79} __packed;
80
81struct atcs_pref_req_output {
82 u16 size; /* structure size in bytes (includes size field) */
83 u8 ret_val; /* return value */
84} __packed;
85
926deccb
FT
86/* Call the ATIF method
87 */
88/**
89 * radeon_atif_call - call an ATIF method
90 *
91 * @handle: acpi handle
92 * @function: the ATIF function to execute
93 * @params: ATIF function params
94 *
95 * Executes the requested ATIF function (all asics).
96 * Returns a pointer to the acpi output buffer.
97 */
98static ACPI_OBJECT *radeon_atif_call(ACPI_HANDLE handle, int function,
99 ACPI_BUFFER *params)
100{
101 ACPI_STATUS status;
102 ACPI_OBJECT atif_arg_elements[2];
103 ACPI_OBJECT_LIST atif_arg;
104 ACPI_BUFFER buffer = { ACPI_ALLOCATE_BUFFER, NULL };
105
106 atif_arg.Count = 2;
107 atif_arg.Pointer = &atif_arg_elements[0];
108
109 atif_arg_elements[0].Type = ACPI_TYPE_INTEGER;
110 atif_arg_elements[0].Integer.Value = function;
111
112 if (params) {
113 atif_arg_elements[1].Type = ACPI_TYPE_BUFFER;
114 atif_arg_elements[1].Buffer.Length = params->Length;
115 atif_arg_elements[1].Buffer.Pointer = params->Pointer;
116 } else {
117 /* We need a second fake parameter */
118 atif_arg_elements[1].Type = ACPI_TYPE_INTEGER;
119 atif_arg_elements[1].Integer.Value = 0;
120 }
121
122 status = AcpiEvaluateObject(handle, "ATIF", &atif_arg, &buffer);
123
124 /* Fail only if calling the method fails and ATIF is supported */
125 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
126 DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",
127 AcpiFormatException(status));
128 AcpiOsFree(buffer.Pointer);
129 return NULL;
130 }
131
132 return buffer.Pointer;
133}
134
135/**
136 * radeon_atif_parse_notification - parse supported notifications
137 *
138 * @n: supported notifications struct
139 * @mask: supported notifications mask from ATIF
140 *
141 * Use the supported notifications mask from ATIF function
142 * ATIF_FUNCTION_VERIFY_INTERFACE to determine what notifications
143 * are supported (all asics).
144 */
145static void radeon_atif_parse_notification(struct radeon_atif_notifications *n, u32 mask)
146{
147 n->display_switch = mask & ATIF_DISPLAY_SWITCH_REQUEST_SUPPORTED;
148 n->expansion_mode_change = mask & ATIF_EXPANSION_MODE_CHANGE_REQUEST_SUPPORTED;
149 n->thermal_state = mask & ATIF_THERMAL_STATE_CHANGE_REQUEST_SUPPORTED;
150 n->forced_power_state = mask & ATIF_FORCED_POWER_STATE_CHANGE_REQUEST_SUPPORTED;
151 n->system_power_state = mask & ATIF_SYSTEM_POWER_SOURCE_CHANGE_REQUEST_SUPPORTED;
152 n->display_conf_change = mask & ATIF_DISPLAY_CONF_CHANGE_REQUEST_SUPPORTED;
153 n->px_gfx_switch = mask & ATIF_PX_GFX_SWITCH_REQUEST_SUPPORTED;
154 n->brightness_change = mask & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST_SUPPORTED;
155 n->dgpu_display_event = mask & ATIF_DGPU_DISPLAY_EVENT_SUPPORTED;
156}
157
158/**
159 * radeon_atif_parse_functions - parse supported functions
160 *
161 * @f: supported functions struct
162 * @mask: supported functions mask from ATIF
163 *
164 * Use the supported functions mask from ATIF function
165 * ATIF_FUNCTION_VERIFY_INTERFACE to determine what functions
166 * are supported (all asics).
167 */
168static void radeon_atif_parse_functions(struct radeon_atif_functions *f, u32 mask)
169{
170 f->system_params = mask & ATIF_GET_SYSTEM_PARAMETERS_SUPPORTED;
171 f->sbios_requests = mask & ATIF_GET_SYSTEM_BIOS_REQUESTS_SUPPORTED;
172 f->select_active_disp = mask & ATIF_SELECT_ACTIVE_DISPLAYS_SUPPORTED;
173 f->lid_state = mask & ATIF_GET_LID_STATE_SUPPORTED;
174 f->get_tv_standard = mask & ATIF_GET_TV_STANDARD_FROM_CMOS_SUPPORTED;
175 f->set_tv_standard = mask & ATIF_SET_TV_STANDARD_IN_CMOS_SUPPORTED;
176 f->get_panel_expansion_mode = mask & ATIF_GET_PANEL_EXPANSION_MODE_FROM_CMOS_SUPPORTED;
177 f->set_panel_expansion_mode = mask & ATIF_SET_PANEL_EXPANSION_MODE_IN_CMOS_SUPPORTED;
178 f->temperature_change = mask & ATIF_TEMPERATURE_CHANGE_NOTIFICATION_SUPPORTED;
179 f->graphics_device_types = mask & ATIF_GET_GRAPHICS_DEVICE_TYPES_SUPPORTED;
180}
181
182/**
183 * radeon_atif_verify_interface - verify ATIF
184 *
185 * @handle: acpi handle
186 * @atif: radeon atif struct
187 *
188 * Execute the ATIF_FUNCTION_VERIFY_INTERFACE ATIF function
189 * to initialize ATIF and determine what features are supported
190 * (all asics).
191 * returns 0 on success, error on failure.
192 */
193static int radeon_atif_verify_interface(ACPI_HANDLE handle,
194 struct radeon_atif *atif)
195{
196 ACPI_OBJECT *info;
197 struct atif_verify_interface output;
198 size_t size;
199 int err = 0;
200
201 info = radeon_atif_call(handle, ATIF_FUNCTION_VERIFY_INTERFACE, NULL);
202 if (!info)
203 return -EIO;
204
205 memset(&output, 0, sizeof(output));
206
207 size = *(u16 *) info->Buffer.Pointer;
208 if (size < 12) {
209 DRM_INFO("ATIF buffer is too small: %zu\n", size);
210 err = -EINVAL;
211 goto out;
212 }
213 size = min(sizeof(output), size);
214
215 memcpy(&output, info->Buffer.Pointer, size);
216
217 /* TODO: check version? */
218 DRM_DEBUG_DRIVER("ATIF version %u\n", output.version);
219
220 radeon_atif_parse_notification(&atif->notifications, output.notification_mask);
221 radeon_atif_parse_functions(&atif->functions, output.function_bits);
222
223out:
224 AcpiOsFree(info);
225 return err;
226}
227
228/**
229 * radeon_atif_get_notification_params - determine notify configuration
230 *
231 * @handle: acpi handle
232 * @n: atif notification configuration struct
233 *
234 * Execute the ATIF_FUNCTION_GET_SYSTEM_PARAMETERS ATIF function
235 * to determine if a notifier is used and if so which one
236 * (all asics). This is either Notify(VGA, 0x81) or Notify(VGA, n)
237 * where n is specified in the result if a notifier is used.
238 * Returns 0 on success, error on failure.
239 */
240static int radeon_atif_get_notification_params(ACPI_HANDLE handle,
241 struct radeon_atif_notification_cfg *n)
242{
243 ACPI_OBJECT *info;
244 struct atif_system_params params;
245 size_t size;
246 int err = 0;
247
248 info = radeon_atif_call(handle, ATIF_FUNCTION_GET_SYSTEM_PARAMETERS, NULL);
249 if (!info) {
250 err = -EIO;
251 goto out;
252 }
253
254 size = *(u16 *) info->Buffer.Pointer;
255 if (size < 10) {
256 err = -EINVAL;
257 goto out;
258 }
259
260 memset(&params, 0, sizeof(params));
261 size = min(sizeof(params), size);
262 memcpy(&params, info->Buffer.Pointer, size);
263
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;
267
268 if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_NONE) {
269 n->enabled = false;
270 n->command_code = 0;
271 } else if ((params.flags & ATIF_NOTIFY_MASK) == ATIF_NOTIFY_81) {
272 n->enabled = true;
273 n->command_code = 0x81;
274 } else {
275 if (size < 11) {
276 err = -EINVAL;
277 goto out;
278 }
279 n->enabled = true;
280 n->command_code = params.command_code;
281 }
282
283out:
284 DRM_DEBUG_DRIVER("Notification %s, command code = %#x\n",
285 (n->enabled ? "enabled" : "disabled"),
286 n->command_code);
287 AcpiOsFree(info);
288 return err;
289}
290
291/**
292 * radeon_atif_get_sbios_requests - get requested sbios event
293 *
294 * @handle: acpi handle
295 * @req: atif sbios request struct
296 *
297 * Execute the ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS ATIF function
298 * to determine what requests the sbios is making to the driver
299 * (all asics).
300 * Returns 0 on success, error on failure.
301 */
302static int radeon_atif_get_sbios_requests(ACPI_HANDLE handle,
303 struct atif_sbios_requests *req)
304{
305 ACPI_OBJECT *info;
306 size_t size;
307 int count = 0;
308
309 info = radeon_atif_call(handle, ATIF_FUNCTION_GET_SYSTEM_BIOS_REQUESTS, NULL);
310 if (!info)
311 return -EIO;
312
313 size = *(u16 *)info->Buffer.Pointer;
314 if (size < 0xd) {
315 count = -EINVAL;
316 goto out;
317 }
318 memset(req, 0, sizeof(*req));
319
320 size = min(sizeof(*req), size);
321 memcpy(req, info->Buffer.Pointer, size);
322 DRM_DEBUG_DRIVER("SBIOS pending requests: %#x\n", req->pending);
323
324 count = hweight32(req->pending);
325
326out:
327 AcpiOsFree(info);
328 return count;
329}
330
331/**
332 * radeon_atif_handler - handle ATIF notify requests
333 *
334 * @rdev: radeon_device pointer
335 * @event: atif sbios request struct
336 *
337 * Checks the acpi event and if it matches an atif event,
338 * handles it.
339 * Returns NOTIFY code
340 */
341void radeon_atif_handler(struct radeon_device *rdev,
342 UINT32 type)
343{
344 struct radeon_atif *atif = &rdev->atif;
345 struct atif_sbios_requests req;
346 ACPI_HANDLE handle;
347 int count;
348
349 DRM_DEBUG_DRIVER("event, type = %#x\n",
350 type);
351
352 if (!atif->notification_cfg.enabled ||
353 type != atif->notification_cfg.command_code)
354 /* Not our event */
355 return;
356
357 /* Check pending SBIOS requests */
358 handle = rdev->acpi.handle;
359 count = radeon_atif_get_sbios_requests(handle, &req);
360
361 if (count <= 0)
362 return;
363
364 DRM_DEBUG_DRIVER("ATIF: %d pending SBIOS requests\n", count);
365
366 if (req.pending & ATIF_PANEL_BRIGHTNESS_CHANGE_REQUEST) {
367 struct radeon_encoder *enc = atif->encoder_for_bl;
368
369 if (enc) {
370 DRM_DEBUG_DRIVER("Changing brightness to %d\n",
371 req.backlight_level);
372
373 radeon_set_backlight_level(rdev, enc, req.backlight_level);
374
375#ifdef DUMBBELL_WIP
376 if (rdev->is_atom_bios) {
377 struct radeon_encoder_atom_dig *dig = enc->enc_priv;
378 backlight_force_update(dig->bl_dev,
379 BACKLIGHT_UPDATE_HOTKEY);
380 } else {
381 struct radeon_encoder_lvds *dig = enc->enc_priv;
382 backlight_force_update(dig->bl_dev,
383 BACKLIGHT_UPDATE_HOTKEY);
384 }
385#endif /* DUMBBELL_WIP */
386 }
387 }
388 /* TODO: check other events */
389
390 /* We've handled the event, stop the notifier chain. The ACPI interface
391 * overloads ACPI_VIDEO_NOTIFY_PROBE, we don't want to send that to
392 * userspace if the event was generated only to signal a SBIOS
393 * request.
394 */
395}
396
397/* Call the ATCS method
398 */
399/**
400 * radeon_atcs_call - call an ATCS method
401 *
402 * @handle: acpi handle
403 * @function: the ATCS function to execute
404 * @params: ATCS function params
405 *
406 * Executes the requested ATCS function (all asics).
407 * Returns a pointer to the acpi output buffer.
408 */
409static union acpi_object *radeon_atcs_call(ACPI_HANDLE handle, int function,
410 ACPI_BUFFER *params)
411{
412 ACPI_STATUS status;
413 ACPI_OBJECT atcs_arg_elements[2];
414 ACPI_OBJECT_LIST atcs_arg;
415 ACPI_BUFFER buffer = { ACPI_ALLOCATE_BUFFER, NULL };
416
417 atcs_arg.Count = 2;
418 atcs_arg.Pointer = &atcs_arg_elements[0];
419
420 atcs_arg_elements[0].Type = ACPI_TYPE_INTEGER;
421 atcs_arg_elements[0].Integer.Value = function;
422
423 if (params) {
424 atcs_arg_elements[1].Type = ACPI_TYPE_BUFFER;
425 atcs_arg_elements[1].Buffer.Length = params->Length;
426 atcs_arg_elements[1].Buffer.Pointer = params->Pointer;
427 } else {
428 /* We need a second fake parameter */
429 atcs_arg_elements[1].Type = ACPI_TYPE_INTEGER;
430 atcs_arg_elements[1].Integer.Value = 0;
431 }
432
433 status = AcpiEvaluateObject(handle, "ATCS", &atcs_arg, &buffer);
434
435 /* Fail only if calling the method fails and ATIF is supported */
436 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
437 DRM_DEBUG_DRIVER("failed to evaluate ATCS got %s\n",
438 AcpiFormatException(status));
439 AcpiOsFree(buffer.Pointer);
440 return NULL;
441 }
442
443 return buffer.Pointer;
444}
445
446/**
447 * radeon_atcs_parse_functions - parse supported functions
448 *
449 * @f: supported functions struct
450 * @mask: supported functions mask from ATCS
451 *
452 * Use the supported functions mask from ATCS function
453 * ATCS_FUNCTION_VERIFY_INTERFACE to determine what functions
454 * are supported (all asics).
455 */
456static void radeon_atcs_parse_functions(struct radeon_atcs_functions *f, u32 mask)
457{
458 f->get_ext_state = mask & ATCS_GET_EXTERNAL_STATE_SUPPORTED;
459 f->pcie_perf_req = mask & ATCS_PCIE_PERFORMANCE_REQUEST_SUPPORTED;
460 f->pcie_dev_rdy = mask & ATCS_PCIE_DEVICE_READY_NOTIFICATION_SUPPORTED;
461 f->pcie_bus_width = mask & ATCS_SET_PCIE_BUS_WIDTH_SUPPORTED;
462}
463
464/**
465 * radeon_atcs_verify_interface - verify ATCS
466 *
467 * @handle: acpi handle
468 * @atcs: radeon atcs struct
469 *
470 * Execute the ATCS_FUNCTION_VERIFY_INTERFACE ATCS function
471 * to initialize ATCS and determine what features are supported
472 * (all asics).
473 * returns 0 on success, error on failure.
474 */
475static int radeon_atcs_verify_interface(ACPI_HANDLE handle,
476 struct radeon_atcs *atcs)
477{
478 ACPI_OBJECT *info;
479 struct atcs_verify_interface output;
480 size_t size;
481 int err = 0;
482
483 info = radeon_atcs_call(handle, ATCS_FUNCTION_VERIFY_INTERFACE, NULL);
484 if (!info)
485 return -EIO;
486
487 memset(&output, 0, sizeof(output));
488
489 size = *(u16 *) info->Buffer.Pointer;
490 if (size < 8) {
491 DRM_INFO("ATCS buffer is too small: %zu\n", size);
492 err = -EINVAL;
493 goto out;
494 }
495 size = min(sizeof(output), size);
496
497 memcpy(&output, info->Buffer.Pointer, size);
498
499 /* TODO: check version? */
500 DRM_DEBUG_DRIVER("ATCS version %u\n", output.version);
501
502 radeon_atcs_parse_functions(&atcs->functions, output.function_bits);
503
504out:
505 AcpiOsFree(info);
506 return err;
507}
508
57e252bf
MN
509/**
510 * radeon_acpi_is_pcie_performance_request_supported
511 *
512 * @rdev: radeon_device pointer
513 *
514 * Check if the ATCS pcie_perf_req and pcie_dev_rdy methods
515 * are supported (all asics).
516 * returns true if supported, false if not.
517 */
518bool radeon_acpi_is_pcie_performance_request_supported(struct radeon_device *rdev)
519{
520 struct radeon_atcs *atcs = &rdev->atcs;
521
522 if (atcs->functions.pcie_perf_req && atcs->functions.pcie_dev_rdy)
523 return true;
524
525 return false;
526}
527
528/**
529 * radeon_acpi_pcie_notify_device_ready
530 *
531 * @rdev: radeon_device pointer
532 *
533 * Executes the PCIE_DEVICE_READY_NOTIFICATION method
534 * (all asics).
535 * returns 0 on success, error on failure.
536 */
537int radeon_acpi_pcie_notify_device_ready(struct radeon_device *rdev)
538{
539#ifdef MN_TODO
540 acpi_handle handle;
541 union acpi_object *info;
542 struct radeon_atcs *atcs = &rdev->atcs;
543
544 /* Get the device handle */
545 handle = DEVICE_ACPI_HANDLE(&rdev->pdev->dev);
546 if (!handle)
547 return -EINVAL;
548
549 if (!atcs->functions.pcie_dev_rdy)
550 return -EINVAL;
551
552 info = radeon_atcs_call(handle, ATCS_FUNCTION_PCIE_DEVICE_READY_NOTIFICATION, NULL);
553 if (!info)
554 return -EIO;
555
556 kfree(info);
557 return 0;
558#else
559 return -EINVAL;
560#endif
561}
562
563/**
564 * radeon_acpi_pcie_performance_request
565 *
566 * @rdev: radeon_device pointer
567 * @perf_req: requested perf level (pcie gen speed)
568 * @advertise: set advertise caps flag if set
569 *
570 * Executes the PCIE_PERFORMANCE_REQUEST method to
571 * change the pcie gen speed (all asics).
572 * returns 0 on success, error on failure.
573 */
574int radeon_acpi_pcie_performance_request(struct radeon_device *rdev,
575 u8 perf_req, bool advertise)
576{
577#ifdef MN_TODO
578 acpi_handle handle;
579 union acpi_object *info;
580 struct radeon_atcs *atcs = &rdev->atcs;
581 struct atcs_pref_req_input atcs_input;
582 struct atcs_pref_req_output atcs_output;
583 struct acpi_buffer params;
584 size_t size;
585 u32 retry = 3;
586
587 /* Get the device handle */
588 handle = DEVICE_ACPI_HANDLE(&rdev->pdev->dev);
589 if (!handle)
590 return -EINVAL;
591
592 if (!atcs->functions.pcie_perf_req)
593 return -EINVAL;
594
595 atcs_input.size = sizeof(struct atcs_pref_req_input);
596 /* client id (bit 2-0: func num, 7-3: dev num, 15-8: bus num) */
597 atcs_input.client_id = rdev->pdev->devfn | (rdev->pdev->bus->number << 8);
598 atcs_input.valid_flags_mask = ATCS_VALID_FLAGS_MASK;
599 atcs_input.flags = ATCS_WAIT_FOR_COMPLETION;
600 if (advertise)
601 atcs_input.flags |= ATCS_ADVERTISE_CAPS;
602 atcs_input.req_type = ATCS_PCIE_LINK_SPEED;
603 atcs_input.perf_req = perf_req;
604
605 params.length = sizeof(struct atcs_pref_req_input);
606 params.pointer = &atcs_input;
607
608 while (retry--) {
609 info = radeon_atcs_call(handle, ATCS_FUNCTION_PCIE_PERFORMANCE_REQUEST, &params);
610 if (!info)
611 return -EIO;
612
613 memset(&atcs_output, 0, sizeof(atcs_output));
614
615 size = *(u16 *) info->buffer.pointer;
616 if (size < 3) {
617 DRM_INFO("ATCS buffer is too small: %zu\n", size);
618 kfree(info);
619 return -EINVAL;
620 }
621 size = min(sizeof(atcs_output), size);
622
623 memcpy(&atcs_output, info->buffer.pointer, size);
624
625 kfree(info);
626
627 switch (atcs_output.ret_val) {
628 case ATCS_REQUEST_REFUSED:
629 default:
630 return -EINVAL;
631 case ATCS_REQUEST_COMPLETE:
632 return 0;
633 case ATCS_REQUEST_IN_PROGRESS:
634 DRM_UDELAY(10);
635 break;
636 }
637 }
638
639 return 0;
640#else
641 return -EINVAL;
642#endif
643}
644
926deccb
FT
645/**
646 * radeon_acpi_event - handle notify events
647 *
648 * @nb: notifier block
649 * @val: val
650 * @data: acpi event
651 *
652 * Calls relevant radeon functions in response to various
653 * acpi events.
654 * Returns NOTIFY code
655 */
656static void radeon_acpi_event(ACPI_HANDLE handle, UINT32 type,
657 void *context)
658{
659 struct radeon_device *rdev = (struct radeon_device *)context;
660
661#ifdef DUMBBELL_WIP
662 if (strcmp(entry->device_class, ACPI_AC_CLASS) == 0) {
663 if (power_supply_is_system_supplied() > 0)
664 DRM_DEBUG_DRIVER("pm: AC\n");
665 else
666 DRM_DEBUG_DRIVER("pm: DC\n");
667
668 radeon_pm_acpi_event_handler(rdev);
669 }
670#endif /* DUMBBELL_WIP */
671
672 /* Check for pending SBIOS requests */
673 radeon_atif_handler(rdev, type);
674}
675
676/* Call all ACPI methods here */
677/**
678 * radeon_acpi_init - init driver acpi support
679 *
680 * @rdev: radeon_device pointer
681 *
682 * Verifies the AMD ACPI interfaces and registers with the acpi
683 * notifier chain (all asics).
684 * Returns 0 on success, error on failure.
685 */
686int radeon_acpi_init(struct radeon_device *rdev)
687{
688 ACPI_HANDLE handle;
689 struct radeon_atif *atif = &rdev->atif;
690 struct radeon_atcs *atcs = &rdev->atcs;
691 int ret;
692
693 /* Get the device handle */
694 handle = acpi_get_handle(rdev->dev);
695
696 /* No need to proceed if we're sure that ATIF is not supported */
697 if (!ASIC_IS_AVIVO(rdev) || !rdev->bios || !handle)
698 return 0;
699
700 /* Call the ATCS method */
701 ret = radeon_atcs_verify_interface(handle, atcs);
702 if (ret) {
703 DRM_DEBUG_DRIVER("Call to ATCS verify_interface failed: %d\n", ret);
704 }
705
706 /* Call the ATIF method */
707 ret = radeon_atif_verify_interface(handle, atif);
708 if (ret) {
709 DRM_DEBUG_DRIVER("Call to ATIF verify_interface failed: %d\n", ret);
710 goto out;
711 }
712
713 if (atif->notifications.brightness_change) {
714 struct drm_encoder *tmp;
715 struct radeon_encoder *target = NULL;
716
717 /* Find the encoder controlling the brightness */
718 list_for_each_entry(tmp, &rdev->ddev->mode_config.encoder_list,
719 head) {
720 struct radeon_encoder *enc = to_radeon_encoder(tmp);
721
722 if ((enc->devices & (ATOM_DEVICE_LCD_SUPPORT)) &&
723 enc->enc_priv) {
724 if (rdev->is_atom_bios) {
725 struct radeon_encoder_atom_dig *dig = enc->enc_priv;
726 if (dig->bl_dev) {
727 target = enc;
728 break;
729 }
730 } else {
731 struct radeon_encoder_lvds *dig = enc->enc_priv;
732 if (dig->bl_dev) {
733 target = enc;
734 break;
735 }
736 }
737 }
738 }
739
740 atif->encoder_for_bl = target;
741 if (!target) {
742 /* Brightness change notification is enabled, but we
743 * didn't find a backlight controller, this should
744 * never happen.
745 */
746 DRM_ERROR("Cannot find a backlight controller\n");
747 }
748 }
749
750 if (atif->functions.sbios_requests && !atif->functions.system_params) {
751 /* XXX check this workraround, if sbios request function is
752 * present we have to see how it's configured in the system
753 * params
754 */
755 atif->functions.system_params = true;
756 }
757
758 if (atif->functions.system_params) {
759 ret = radeon_atif_get_notification_params(handle,
760 &atif->notification_cfg);
761 if (ret) {
762 DRM_DEBUG_DRIVER("Call to GET_SYSTEM_PARAMS failed: %d\n",
763 ret);
764 /* Disable notification */
765 atif->notification_cfg.enabled = false;
766 }
767 }
768
769out:
770 rdev->acpi.handle = handle;
771 rdev->acpi.notifier_call = radeon_acpi_event;
772 AcpiInstallNotifyHandler(handle, ACPI_DEVICE_NOTIFY,
773 rdev->acpi.notifier_call, rdev);
774
775 return ret;
776}
777
778/**
779 * radeon_acpi_fini - tear down driver acpi support
780 *
781 * @rdev: radeon_device pointer
782 *
783 * Unregisters with the acpi notifier chain (all asics).
784 */
785void radeon_acpi_fini(struct radeon_device *rdev)
786{
787 AcpiRemoveNotifyHandler(rdev->acpi.handle, ACPI_DEVICE_NOTIFY,
788 rdev->acpi.notifier_call);
789}