blob: f7b511dcba30570d1b299048cfcac7a073ca92c8 [file] [log] [blame]
Alex Deucherefd4e412012-07-31 17:18:17 -04001/*
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 */
23
Alberto Miloned7a29522010-07-06 11:40:24 -040024#include <linux/pci.h>
25#include <linux/acpi.h>
26#include <linux/slab.h>
27#include <acpi/acpi_drivers.h>
28#include <acpi/acpi_bus.h>
29
30#include "drmP.h"
31#include "drm.h"
32#include "drm_sarea.h"
33#include "drm_crtc_helper.h"
34#include "radeon.h"
Alex Deucher9e05b2f2012-07-18 13:28:52 -040035#include "radeon_acpi.h"
Alberto Miloned7a29522010-07-06 11:40:24 -040036
37#include <linux/vga_switcheroo.h>
38
39/* Call the ATIF method
Alberto Miloned7a29522010-07-06 11:40:24 -040040 */
Luca Tettamanti86504672012-07-29 17:04:43 +020041static union acpi_object *radeon_atif_call(acpi_handle handle, int function,
42 struct acpi_buffer *params)
Alberto Miloned7a29522010-07-06 11:40:24 -040043{
44 acpi_status status;
45 union acpi_object atif_arg_elements[2];
46 struct acpi_object_list atif_arg;
Luca Tettamanti86504672012-07-29 17:04:43 +020047 struct acpi_buffer buffer = { ACPI_ALLOCATE_BUFFER, NULL };
Alberto Miloned7a29522010-07-06 11:40:24 -040048
49 atif_arg.count = 2;
50 atif_arg.pointer = &atif_arg_elements[0];
51
52 atif_arg_elements[0].type = ACPI_TYPE_INTEGER;
Luca Tettamanti86504672012-07-29 17:04:43 +020053 atif_arg_elements[0].integer.value = function;
54
55 if (params) {
56 atif_arg_elements[1].type = ACPI_TYPE_BUFFER;
57 atif_arg_elements[1].buffer.length = params->length;
58 atif_arg_elements[1].buffer.pointer = params->pointer;
59 } else {
60 /* We need a second fake parameter */
61 atif_arg_elements[1].type = ACPI_TYPE_INTEGER;
62 atif_arg_elements[1].integer.value = 0;
63 }
Alberto Miloned7a29522010-07-06 11:40:24 -040064
65 status = acpi_evaluate_object(handle, "ATIF", &atif_arg, &buffer);
66
67 /* Fail only if calling the method fails and ATIF is supported */
68 if (ACPI_FAILURE(status) && status != AE_NOT_FOUND) {
Jean Delvarebc96f942011-11-30 17:26:36 +010069 DRM_DEBUG_DRIVER("failed to evaluate ATIF got %s\n",
70 acpi_format_exception(status));
Alberto Miloned7a29522010-07-06 11:40:24 -040071 kfree(buffer.pointer);
Luca Tettamanti86504672012-07-29 17:04:43 +020072 return NULL;
Alberto Miloned7a29522010-07-06 11:40:24 -040073 }
74
Luca Tettamanti86504672012-07-29 17:04:43 +020075 return buffer.pointer;
Alberto Miloned7a29522010-07-06 11:40:24 -040076}
77
78/* Call all ACPI methods here */
79int radeon_acpi_init(struct radeon_device *rdev)
80{
81 acpi_handle handle;
Luca Tettamanti86504672012-07-29 17:04:43 +020082 union acpi_object *info;
83 int ret = 0;
Alberto Miloned7a29522010-07-06 11:40:24 -040084
Alberto Miloned7a29522010-07-06 11:40:24 -040085 /* Get the device handle */
86 handle = DEVICE_ACPI_HANDLE(&rdev->pdev->dev);
87
Jean Delvare48cc9b22011-11-30 17:36:39 +010088 /* No need to proceed if we're sure that ATIF is not supported */
89 if (!ASIC_IS_AVIVO(rdev) || !rdev->bios || !handle)
90 return 0;
91
Alberto Miloned7a29522010-07-06 11:40:24 -040092 /* Call the ATIF method */
Luca Tettamanti86504672012-07-29 17:04:43 +020093 info = radeon_atif_call(handle, ATIF_FUNCTION_VERIFY_INTERFACE, NULL);
94 if (!info)
95 ret = -EIO;
Alberto Miloned7a29522010-07-06 11:40:24 -040096
Luca Tettamanti86504672012-07-29 17:04:43 +020097 kfree(info);
98 return ret;
Alberto Miloned7a29522010-07-06 11:40:24 -040099}
100