]> git.kernelconcepts.de Git - karo-tx-linux.git/blob - drivers/gpu/drm/amd/powerplay/hwmgr/pp_acpi.c
Merge branch 'for-4.8/core' of git://git.kernel.dk/linux-block
[karo-tx-linux.git] / drivers / gpu / drm / amd / powerplay / hwmgr / pp_acpi.c
1 /*
2  * Copyright 2016 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
24 #include <linux/errno.h>
25 #include "linux/delay.h"
26 #include "hwmgr.h"
27 #include "amd_acpi.h"
28
29 bool acpi_atcs_functions_supported(void *device, uint32_t index)
30 {
31         int32_t result;
32         struct atcs_verify_interface output_buf = {0};
33
34         int32_t temp_buffer = 1;
35
36         result = cgs_call_acpi_method(device, CGS_ACPI_METHOD_ATCS,
37                                                 ATCS_FUNCTION_VERIFY_INTERFACE,
38                                                 &temp_buffer,
39                                                 &output_buf,
40                                                 1,
41                                                 sizeof(temp_buffer),
42                                                 sizeof(output_buf));
43
44         return result == 0 ? (output_buf.function_bits & (1 << (index - 1))) != 0 : false;
45 }
46
47 bool acpi_atcs_notify_pcie_device_ready(void *device)
48 {
49         int32_t temp_buffer = 1;
50
51         return cgs_call_acpi_method(device, CGS_ACPI_METHOD_ATCS,
52                                 ATCS_FUNCTION_PCIE_DEVICE_READY_NOTIFICATION,
53                                                 &temp_buffer,
54                                                 NULL,
55                                                 0,
56                                                 sizeof(temp_buffer),
57                                                 0);
58 }
59
60
61 int acpi_pcie_perf_request(void *device, uint8_t perf_req, bool advertise)
62 {
63         struct atcs_pref_req_input atcs_input;
64         struct atcs_pref_req_output atcs_output;
65         u32 retry = 3;
66         int result;
67         struct cgs_system_info info = {0};
68
69         if( 0 != acpi_atcs_notify_pcie_device_ready(device))
70                 return -EINVAL;
71
72         info.size = sizeof(struct cgs_system_info);
73         info.info_id = CGS_SYSTEM_INFO_ADAPTER_BDF_ID;
74         result = cgs_query_system_info(device, &info);
75         if (result != 0)
76                 return -EINVAL;
77         atcs_input.client_id = (uint16_t)info.value;
78         atcs_input.size = sizeof(struct atcs_pref_req_input);
79         atcs_input.valid_flags_mask = ATCS_VALID_FLAGS_MASK;
80         atcs_input.flags = ATCS_WAIT_FOR_COMPLETION;
81         if (advertise)
82                 atcs_input.flags |= ATCS_ADVERTISE_CAPS;
83         atcs_input.req_type = ATCS_PCIE_LINK_SPEED;
84         atcs_input.perf_req = perf_req;
85
86         atcs_output.size = sizeof(struct atcs_pref_req_input);
87
88         while (retry--) {
89                 result = cgs_call_acpi_method(device,
90                                                 CGS_ACPI_METHOD_ATCS,
91                                                 ATCS_FUNCTION_PCIE_PERFORMANCE_REQUEST,
92                                                 &atcs_input,
93                                                 &atcs_output,
94                                                 1,
95                                                 sizeof(atcs_input),
96                                                 sizeof(atcs_output));
97                 if (result != 0)
98                         return -EIO;
99
100                 switch (atcs_output.ret_val) {
101                 case ATCS_REQUEST_REFUSED:
102                 default:
103                         return -EINVAL;
104                 case ATCS_REQUEST_COMPLETE:
105                         return 0;
106                 case ATCS_REQUEST_IN_PROGRESS:
107                         udelay(10);
108                         break;
109                 }
110         }
111
112         return 0;
113 }