Commit | Line | Data |
---|---|---|
f9fbac64 AD |
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 | ||
3bace359 JZ |
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 | int acpi_pcie_perf_request(void *device, uint8_t perf_req, bool advertise) | |
48 | { | |
49 | struct atcs_pref_req_input atcs_input; | |
50 | struct atcs_pref_req_output atcs_output; | |
51 | u32 retry = 3; | |
52 | int result; | |
53 | struct cgs_system_info info = {0}; | |
54 | ||
55 | if (!acpi_atcs_functions_supported(device, ATCS_FUNCTION_PCIE_PERFORMANCE_REQUEST)) | |
56 | return -EINVAL; | |
57 | ||
58 | info.size = sizeof(struct cgs_system_info); | |
59 | info.info_id = CGS_SYSTEM_INFO_ADAPTER_BDF_ID; | |
60 | result = cgs_query_system_info(device, &info); | |
61 | if (result != 0) | |
62 | return -EINVAL; | |
63 | atcs_input.client_id = (uint16_t)info.value; | |
64 | atcs_input.size = sizeof(struct atcs_pref_req_input); | |
65 | atcs_input.valid_flags_mask = ATCS_VALID_FLAGS_MASK; | |
66 | atcs_input.flags = ATCS_WAIT_FOR_COMPLETION; | |
67 | if (advertise) | |
68 | atcs_input.flags |= ATCS_ADVERTISE_CAPS; | |
69 | atcs_input.req_type = ATCS_PCIE_LINK_SPEED; | |
70 | atcs_input.perf_req = perf_req; | |
71 | ||
72 | atcs_output.size = sizeof(struct atcs_pref_req_input); | |
73 | ||
74 | while (retry--) { | |
75 | result = cgs_call_acpi_method(device, | |
76 | CGS_ACPI_METHOD_ATCS, | |
77 | ATCS_FUNCTION_PCIE_PERFORMANCE_REQUEST, | |
78 | &atcs_input, | |
79 | &atcs_output, | |
80 | 0, | |
81 | sizeof(atcs_input), | |
82 | sizeof(atcs_output)); | |
83 | if (result != 0) | |
84 | return -EIO; | |
85 | ||
86 | switch (atcs_output.ret_val) { | |
87 | case ATCS_REQUEST_REFUSED: | |
88 | default: | |
89 | return -EINVAL; | |
90 | case ATCS_REQUEST_COMPLETE: | |
91 | return 0; | |
92 | case ATCS_REQUEST_IN_PROGRESS: | |
93 | udelay(10); | |
94 | break; | |
95 | } | |
96 | } | |
97 | ||
98 | return 0; | |
99 | } |