blob: d3da51b11623f088599c2b588974ffe5d1e9a6c9 [file] [log] [blame]
Furquan Shaikh2736c822020-10-27 19:46:11 -07001/* SPDX-License-Identifier: GPL-2.0-only */
2
3#include <acpi/acpi_device.h>
4#include <acpi/acpigen.h>
Tim Wawrzynczakd40a4c22021-02-25 13:14:49 -07005#include <acpi/acpigen_pci.h>
Furquan Shaikh2736c822020-10-27 19:46:11 -07006#include <console/console.h>
7#include <device/pci_ids.h>
David Ruthea8330e2023-12-06 21:39:54 +00008#include <mtcl.h>
Furquan Shaikh2736c822020-10-27 19:46:11 -07009#include <sar.h>
Elyes Haouasbdd03c22024-05-27 11:20:07 +020010#include <stdio.h>
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +053011#include <stdlib.h>
Furquan Shaikh2736c822020-10-27 19:46:11 -070012#include <wrdd.h>
13
14#include "chip.h"
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +053015#include "wifi.h"
Furquan Shaikh2736c822020-10-27 19:46:11 -070016#include "wifi_private.h"
17
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +053018/* WIFI Domain type */
19#define DOMAIN_TYPE_WIFI 0x7
Furquan Shaikh2736c822020-10-27 19:46:11 -070020
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +053021/* Maximum number DSM UUID bifurcations in _DSM */
22#define MAX_DSM_FUNCS 2
23
Furquan Shaikh2736c822020-10-27 19:46:11 -070024/*
25 * WIFI ACPI NAME = "WF" + hex value of last 8 bits of dev_path_encode + '\0'
26 * The above representation returns unique and consistent name every time
27 * generate_wifi_acpi_name is invoked. The last 8 bits of dev_path_encode is
28 * chosen since it contains the bus address of the device.
29 */
30#define WIFI_ACPI_NAME_MAX_LEN 5
31
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +053032/* Unique ID for the WIFI _DSM */
33#define ACPI_DSM_OEM_WIFI_UUID "F21202BF-8F78-4DC6-A5B3-1F738E285ADE"
34
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +053035/* Unique ID for CnviDdrRfim entry in WIFI _DSM */
36#define ACPI_DSM_RFIM_WIFI_UUID "7266172C-220B-4B29-814F-75E4DD26B5FD"
37
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +053038__weak int get_wifi_sar_limits(union wifi_sar_limits *sar_limits)
Furquan Shaikh2736c822020-10-27 19:46:11 -070039{
40 return -1;
41}
42
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +053043/*
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +053044 * Function 1: Allow PC OEMs to set ETSI 5.8GHz SRD in Passive/Disabled ESTI SRD
45 * Channels: 149, 153, 157, 161, 165
46 * 0 - ETSI 5.8GHz SRD active scan
47 * 1 - ETSI 5.8GHz SRD passive scan
48 * 2 - ETSI 5.8GHz SRD disabled
49 */
50static void wifi_dsm_srd_active_channels(void *args)
51{
52 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
53
54 acpigen_write_return_integer(dsm_config->disable_active_sdr_channels);
55}
56
57/*
58 * Function 2 : Supported Indonesia 5.15-5.35 GHz Band
59 * 0 - Set 5.115-5.35GHz to Disable in Indonesia
60 * 1 - Set 5.115-5.35GHz to Enable (Passive) in Indonesia
61 * 2 - Reserved
62 */
63static void wifi_dsm_indonasia_5Ghz_band_enable(void *args)
64{
65 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
66
67 acpigen_write_return_integer(dsm_config->support_indonesia_5g_band);
68}
69
70/*
71 * Function 3: Support Wi-Fi 6 11ax Rev 2 new channels on 6-7 GHz.
72 * Bit 0:
73 * 0 - No override; use device settings 0
74 * 1 - Force disable all countries that are not defined in the following bits
75 *
76 * Bit 1:
77 * 0 No override; USA 6GHz disable 0
78 * 1 6GHz allowed in the USA (enabled only if the device is certified to the USA)
79 */
80static void wifi_dsm_supported_ultra_high_band(void *args)
81{
82 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
83
84 acpigen_write_return_integer(dsm_config->support_ultra_high_band);
85}
86
87/*
88 * Function 4: Regulatory Special Configurations Enablements
89 */
90static void wifi_dsm_regulatory_configurations(void *args)
91{
92 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
93
94 acpigen_write_return_integer(dsm_config->regulatory_configurations);
95}
96
97/*
98 * Function 5: M.2 UART Interface Configuration
99 */
100static void wifi_dsm_uart_configurations(void *args)
101{
102 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
103
104 acpigen_write_return_integer(dsm_config->uart_configurations);
105}
106
107/*
108 * Function 6: Control Enablement 11ax on certificated modules
109 * Bit 0 - Apply changes to country Ukraine. 11Ax Setting within module certification
110 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
111 * 1 - Apply changes.
112 *
113 * Bit 1 - 11Ax Mode. Effective only if Bit 0 set to 1
114 * 0 - Disable 11Ax on country Ukraine [Default]
115 * 1 - Enable 11Ax on country Ukraine
116 *
117 * Bit 2 - Apply changes to country Russia. 11Ax Setting within module certification
118 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
119 * 1 - Apply changes.
120 *
121 * Bit 3 - 11Ax Mode. Effective only if Bit 2 set to 1
122 * 0 - Disable 11Ax on country Russia [Default]
123 * 1 - Enable 11Ax on country Russia
124 *
125 * Bit 31:04 - Reserved
126 *
127 * Note: Assumed Russia Work with Wi-Fi FW/OTP definitions
128 */
129static void wifi_dsm_ukrane_russia_11ax_enable(void *args)
130{
131 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
132
133 acpigen_write_return_integer(dsm_config->enablement_11ax);
134}
135
136/*
137 * Function 7: Control Enablement UNII-4 over certificate modules
138 */
139static void wifi_dsm_unii4_control_enable(void *args)
140{
141 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
142
143 acpigen_write_return_integer(dsm_config->unii_4);
144}
145
Ravi Sarawadi511222c2024-05-06 09:58:52 -0700146/*
147 * Function 12: Control Enablement 802.11be on certificated modules
148 * Bit 0
149 * 0 - 11BE disabled for China Mainland
150 * 1 - 11BE enabled for China Mainland
151 *
152 * Bit 1
153 * 0 - 11BE disabled for South Korea
154 * 1 - 11BE enabled for South Korea
155 *
156 * Bit 2:27 - Reserved (shall be set to zeroes)
157 *
158 * Bit 28:31 - 11BE enablement revision
159 *
160 */
161static void wifi_dsm_11be_country_enablement(void *args)
162{
163 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
164
165 acpigen_write_return_integer(dsm_config->enablement_11be);
166}
167
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530168static void wifi_dsm_ddrrfim_func3_cb(void *ptr)
169{
170 const bool is_cnvi_ddr_rfim_enabled = *(bool *)ptr;
Simon Yang59b383e2023-12-28 14:42:21 +0800171 acpigen_write_return_integer(is_cnvi_ddr_rfim_enabled ? 0 : 1);
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530172}
173
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +0530174static void (*wifi_dsm_callbacks[])(void *) = {
175 NULL, /* Function 0 */
176 wifi_dsm_srd_active_channels, /* Function 1 */
177 wifi_dsm_indonasia_5Ghz_band_enable, /* Function 2 */
178 wifi_dsm_supported_ultra_high_band, /* Function 3 */
179 wifi_dsm_regulatory_configurations, /* Function 4 */
180 wifi_dsm_uart_configurations, /* Function 5 */
181 wifi_dsm_ukrane_russia_11ax_enable, /* Function 6 */
182 wifi_dsm_unii4_control_enable, /* Function 7 */
Ravi Sarawadi511222c2024-05-06 09:58:52 -0700183 NULL, /* Function 8 */
184 NULL, /* Function 9 */
185 NULL, /* Function 10 */
186 NULL, /* Function 11 */
187 wifi_dsm_11be_country_enablement, /* Function 12 */
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +0530188};
189
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530190/*
191 * The current DSM2 table is only exporting one function (function 3), some more
192 * functions are reserved so marking them NULL.
193*/
194static void (*wifi_dsm2_callbacks[])(void *) = {
195 NULL, /* Function 0 */
196 NULL, /* Function 1 */
197 NULL, /* Function 2 */
198 wifi_dsm_ddrrfim_func3_cb, /* Function 3 */
199};
200
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530201static const uint8_t *sar_fetch_set(const struct sar_profile *sar, size_t set_num)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700202{
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530203 const uint8_t *sar_table = &sar->sar_table[0];
Furquan Shaikh2736c822020-10-27 19:46:11 -0700204
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530205 return sar_table + (sar->chains_count * sar->subbands_count * set_num);
206}
Furquan Shaikh2736c822020-10-27 19:46:11 -0700207
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530208static const uint8_t *wgds_fetch_set(struct geo_profile *wgds, size_t set_num)
209{
210 const uint8_t *wgds_table = &wgds->wgds_table[0];
211
212 return wgds_table + (wgds->bands_count * set_num);
213}
214
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530215static const uint8_t *ppag_fetch_set(struct gain_profile *ppag, size_t set_num)
216{
217 const uint8_t *ppag_table = &ppag->ppag_table[0];
218
219 return ppag_table + (ppag->bands_count * set_num);
220}
221
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530222static void sar_emit_wrds(const struct sar_profile *sar)
223{
224 int i;
225 size_t package_size, table_size;
226 const uint8_t *set;
227
228 if (sar == NULL)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700229 return;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700230
231 /*
232 * Name ("WRDS", Package () {
233 * Revision,
234 * Package () {
235 * Domain Type, // 0x7:WiFi
236 * WiFi SAR BIOS, // BIOS SAR Enable/disable
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530237 * SAR Table Set // Set#1 of SAR Table
Furquan Shaikh2736c822020-10-27 19:46:11 -0700238 * }
239 * })
240 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530241 if (sar->revision > MAX_SAR_REVISION) {
Julius Wernere9665952022-01-21 17:06:20 -0800242 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530243 return;
244 }
245
Furquan Shaikh2736c822020-10-27 19:46:11 -0700246 acpigen_write_name("WRDS");
247 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530248 acpigen_write_dword(sar->revision);
249
250 table_size = sar->chains_count * sar->subbands_count;
251 /* Emit 'Domain Type' + 'WiFi SAR Enable' + Set#1 */
252 package_size = 1 + 1 + table_size;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700253 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530254 acpigen_write_dword(DOMAIN_TYPE_WIFI);
255 acpigen_write_dword(1);
256
257 set = sar_fetch_set(sar, 0);
258 for (i = 0; i < table_size; i++)
259 acpigen_write_byte(set[i]);
260
261 acpigen_write_package_end();
262 acpigen_write_package_end();
263}
264
265static void sar_emit_ewrd(const struct sar_profile *sar)
266{
267 int i;
268 size_t package_size, set_num, table_size;
269 const uint8_t *set;
270
271 if (sar == NULL)
272 return;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700273
274 /*
275 * Name ("EWRD", Package () {
276 * Revision,
277 * Package () {
278 * Domain Type, // 0x7:WiFi
279 * Dynamic SAR Enable, // Dynamic SAR Enable/disable
280 * Extended SAR sets, // Number of optional SAR table sets
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530281 * SAR Table Set, // Set#2 of SAR Table
282 * SAR Table Set, // Set#3 of SAR Table
283 * SAR Table Set // Set#4 of SAR Table
Furquan Shaikh2736c822020-10-27 19:46:11 -0700284 * }
285 * })
286 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530287 if (sar->revision > MAX_SAR_REVISION) {
Julius Wernere9665952022-01-21 17:06:20 -0800288 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530289 return;
290 }
291
292 if (sar->dsar_set_count == 0) {
Julius Wernere9665952022-01-21 17:06:20 -0800293 printk(BIOS_WARNING, "DSAR set count is 0\n");
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530294 return;
295 }
296
Furquan Shaikh2736c822020-10-27 19:46:11 -0700297 acpigen_write_name("EWRD");
298 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530299 acpigen_write_dword(sar->revision);
300
301 table_size = sar->chains_count * sar->subbands_count;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700302 /*
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530303 * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Extended SAR sets count'
Furquan Shaikh2736c822020-10-27 19:46:11 -0700304 * + number of bytes for Set#2 & 3 & 4
305 */
Matt Chen07e6b5f2021-11-04 18:13:25 +0800306 package_size = 1 + 1 + 1 + table_size * MAX_DSAR_SET_COUNT;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700307 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530308 acpigen_write_dword(DOMAIN_TYPE_WIFI);
309 acpigen_write_dword(1);
310 acpigen_write_dword(sar->dsar_set_count);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700311
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530312 for (set_num = 1; set_num <= sar->dsar_set_count; set_num++) {
313 set = sar_fetch_set(sar, set_num);
314 for (i = 0; i < table_size; i++)
315 acpigen_write_byte(set[i]);
316 }
317
318 /* wifi driver always expects 3 DSAR sets */
319 for (i = 0; i < (table_size * (MAX_DSAR_SET_COUNT - sar->dsar_set_count)); i++)
320 acpigen_write_byte(0);
321
322 acpigen_write_package_end();
323 acpigen_write_package_end();
324}
325
326static void sar_emit_wgds(struct geo_profile *wgds)
327{
328 int i;
329 size_t package_size, set_num;
330 const uint8_t *set;
331
332 if (wgds == NULL)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700333 return;
334
335 /*
336 * Name ("WGDS", Package() {
337 * Revision,
338 * Package() {
339 * DomainType, // 0x7:WiFi
340 * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max
341 * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset
342 * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset
343 * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max
344 * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset
345 * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530346 * WgdsWiFiSarDeltaGroup1PowerMax3, // Group 1 FCC 6000-7000 Max
347 * WgdsWiFiSarDeltaGroup1PowerChainA3, // Group 1 FCC 6000-7000 A Offset
348 * WgdsWiFiSarDeltaGroup1PowerChainB3, // Group 1 FCC 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700349 * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max
350 * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset
351 * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset
352 * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max
353 * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset
354 * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530355 * WgdsWiFiSarDeltaGroup2PowerMax3, // Group 2 EC Jap 6000-7000 Max
356 * WgdsWiFiSarDeltaGroup2PowerChainA3, // Group 2 EC Jap 6000-7000 A Offset
357 * WgdsWiFiSarDeltaGroup2PowerChainB3, // Group 2 EC Jap 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700358 * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max
359 * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset
360 * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset
361 * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max
362 * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset
363 * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530364 * WgdsWiFiSarDeltaGroup3PowerMax3, // Group 3 ROW 6000-7000 Max
365 * WgdsWiFiSarDeltaGroup3PowerChainA3, // Group 3 ROW 6000-7000 A Offset
366 * WgdsWiFiSarDeltaGroup3PowerChainB3, // Group 3 ROW 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700367 * }
368 * })
369 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530370 if (wgds->revision > MAX_GEO_OFFSET_REVISION) {
Julius Wernere9665952022-01-21 17:06:20 -0800371 printk(BIOS_ERR, "Invalid WGDS revision: %d\n", wgds->revision);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530372 return;
373 }
Furquan Shaikh2736c822020-10-27 19:46:11 -0700374
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530375 package_size = 1 + wgds->chains_count * wgds->bands_count;
376
Furquan Shaikh2736c822020-10-27 19:46:11 -0700377 acpigen_write_name("WGDS");
378 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530379 acpigen_write_dword(wgds->revision);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700380 /* Emit 'Domain Type' +
381 * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS)
382 */
Furquan Shaikh2736c822020-10-27 19:46:11 -0700383 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530384 acpigen_write_dword(DOMAIN_TYPE_WIFI);
385
386 for (set_num = 0; set_num < wgds->chains_count; set_num++) {
387 set = wgds_fetch_set(wgds, set_num);
388 for (i = 0; i < wgds->bands_count; i++)
389 acpigen_write_byte(set[i]);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700390 }
391
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530392 acpigen_write_package_end();
393 acpigen_write_package_end();
394}
395
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530396static void sar_emit_ppag(struct gain_profile *ppag)
397{
398 int i;
399 size_t package_size, set_num;
400 const uint8_t *set;
401
402 if (ppag == NULL)
403 return;
404
405 /*
406 * Name ("PPAG", Package () {
407 * Revision,
408 * Package () {
409 * Domain Type, // 0x7:WiFi
410 * PPAG Mode, // Defines the mode of ANT_gain control to be used
411 * ANT_gain Table Chain A // Defines the ANT_gain in dBi for chain A
412 * ANT_gain Table Chain B // Defines the ANT_gain in dBi for chain B
413 * }
414 * })
415 */
416 if (ppag->revision > MAX_ANT_GAINS_REVISION) {
417 printk(BIOS_ERR, "Invalid PPAG revision: %d\n", ppag->revision);
418 return;
419 }
420
421 package_size = 1 + 1 + ppag->chains_count * ppag->bands_count;
422
423 acpigen_write_name("PPAG");
424 acpigen_write_package(2);
425 acpigen_write_dword(ppag->revision);
426 acpigen_write_package(package_size);
427 acpigen_write_dword(DOMAIN_TYPE_WIFI);
428 acpigen_write_dword(ppag->mode);
429
430 for (set_num = 0; set_num < ppag->chains_count; set_num++) {
431 set = ppag_fetch_set(ppag, set_num);
432 for (i = 0; i < ppag->bands_count; i++)
433 acpigen_write_byte(set[i]);
434 }
435
436 acpigen_write_package_end();
437 acpigen_write_package_end();
438}
439
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530440static void sar_emit_wtas(struct avg_profile *wtas)
441{
442 int i;
443 size_t package_size;
444
445 if (wtas == NULL)
446 return;
447
448 /*
449 * Name (WTAS, Package() {
450 * {
451 * Revision,
452 * Package()
453 * {
454 * DomainType, // 0x7:WiFi
455 * WifiTASSelection, // Enable/Disable the TAS feature
456 * WifiTASListEntries, // No. of blocked countries not approved by OEM to
457 * BlockedListEntry1, support this feature
458 * BlockedListEntry2,
459 * BlockedListEntry3,
460 * BlockedListEntry4,
461 * BlockedListEntry5,
462 * BlockedListEntry6,
463 * BlockedListEntry7,
464 * BlockedListEntry8,
465 * BlockedListEntry9,
466 * BlockedListEntry10,
467 * BlockedListEntry11,
468 * BlockedListEntry12,
469 * BlockedListEntry13,
470 * BlockedListEntry14,
471 * BlockedListEntry15,
472 * BlockedListEntry16,
473 * }
474 * })
475 */
476 package_size = 1 + 1 + 1 + MAX_DENYLIST_ENTRY;
477
478 acpigen_write_name("WTAS");
479 acpigen_write_package(2);
480 acpigen_write_dword(wtas->revision);
481 acpigen_write_package(package_size);
482 acpigen_write_dword(DOMAIN_TYPE_WIFI);
Sugnan Prabhu S627c8442021-09-06 15:05:56 +0530483 acpigen_write_byte(wtas->tas_selection);
484 acpigen_write_byte(wtas->tas_list_size);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530485 for (i = 0; i < MAX_DENYLIST_ENTRY; i++)
Sugnan Prabhu S627c8442021-09-06 15:05:56 +0530486 acpigen_write_word(wtas->deny_list_entry[i]);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530487
488 acpigen_write_package_end();
489 acpigen_write_package_end();
490}
491
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530492static void emit_sar_acpi_structures(const struct device *dev, struct dsm_profile *dsm)
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530493{
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530494 union wifi_sar_limits sar_limits = {{NULL, NULL, NULL, NULL, NULL} };
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530495
496 /*
497 * If device type is PCI, ensure that the device has Intel vendor ID. CBFS SAR and SAR
498 * ACPI tables are currently used only by Intel WiFi devices.
499 */
Felix Singer43b7f412022-03-07 04:34:52 +0100500 if (dev->path.type == DEVICE_PATH_PCI && dev->vendor != PCI_VID_INTEL)
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530501 return;
502
Martin Roth3e25f852023-09-04 15:37:07 -0600503 /* Retrieve the SAR limits data */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530504 if (get_wifi_sar_limits(&sar_limits) < 0) {
Julius Wernere9665952022-01-21 17:06:20 -0800505 printk(BIOS_ERR, "failed getting SAR limits!\n");
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530506 return;
507 }
508
509 sar_emit_wrds(sar_limits.sar);
510 sar_emit_ewrd(sar_limits.sar);
511 sar_emit_wgds(sar_limits.wgds);
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530512 sar_emit_ppag(sar_limits.ppag);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530513 sar_emit_wtas(sar_limits.wtas);
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530514
515 /* copy the dsm data to be later used for creating _DSM function */
516 if (sar_limits.dsm != NULL)
Meera Ravindranathf3375372022-11-10 11:27:00 +0530517 memcpy(dsm, sar_limits.dsm, sizeof(struct dsm_profile));
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530518
519 free(sar_limits.sar);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700520}
521
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700522static void wifi_ssdt_write_device(const struct device *dev, const char *path)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700523{
Furquan Shaikh2736c822020-10-27 19:46:11 -0700524 /* Device */
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700525 acpigen_write_device(path);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700526 acpi_device_write_uid(dev);
527
528 if (dev->chip_ops)
529 acpigen_write_name_string("_DDN", dev->chip_ops->name);
530
531 /* Address */
532 acpigen_write_ADR_pci_device(dev);
533
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700534 acpigen_pop_len(); /* Device */
535}
536
537static void wifi_ssdt_write_properties(const struct device *dev, const char *scope)
538{
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530539 const struct drivers_wifi_generic_config *config = dev->chip_info;
Angel Pons1e124b92022-04-03 21:10:26 +0200540
541 bool is_cnvi_ddr_rfim_enabled = config && config->enable_cnvi_ddr_rfim;
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530542
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700543 /* Scope */
544 acpigen_write_scope(scope);
545
Reka Norman93928192022-07-22 08:01:19 +1000546 if (config) {
547 /* Wake capabilities */
548 acpigen_write_PRW(config->wake, ACPI_S3);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700549
Reka Norman93928192022-07-22 08:01:19 +1000550 /* Add _DSD for DmaProperty property. */
Kapil Porwal0b20a172022-11-26 20:10:47 +0530551 if (config->add_acpi_dma_property)
552 acpi_device_add_dma_property(NULL);
Tim Wawrzynczak3babc8e2022-01-25 14:05:20 -0700553 }
554
Furquan Shaikh2736c822020-10-27 19:46:11 -0700555 /* Fill regulatory domain structure */
556 if (CONFIG(HAVE_REGULATORY_DOMAIN)) {
557 /*
558 * Name ("WRDD", Package () {
559 * WRDD_REVISION, // Revision
560 * Package () {
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530561 * DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
Furquan Shaikh2736c822020-10-27 19:46:11 -0700562 * wifi_regulatory_domain() // Country Identifier
563 * }
564 * })
565 */
566 acpigen_write_name("WRDD");
567 acpigen_write_package(2);
568 acpigen_write_integer(WRDD_REVISION);
569 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530570 acpigen_write_dword(DOMAIN_TYPE_WIFI);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700571 acpigen_write_dword(wifi_regulatory_domain());
572 acpigen_pop_len();
573 acpigen_pop_len();
574 }
575
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530576 struct dsm_uuid dsm_ids[MAX_DSM_FUNCS];
577 /* We will need a copy dsm data to be used later for creating _DSM function */
578 struct dsm_profile dsm = {0};
579 uint8_t dsm_count = 0;
580
Martin Roth3e25f852023-09-04 15:37:07 -0600581 /* Fill Wifi SAR related ACPI structures */
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530582 if (CONFIG(USE_SAR)) {
583 emit_sar_acpi_structures(dev, &dsm);
584
585 if (dsm.supported_functions != 0) {
586 for (int i = 1; i < ARRAY_SIZE(wifi_dsm_callbacks); i++)
587 if (!(dsm.supported_functions & (1 << i)))
588 wifi_dsm_callbacks[i] = NULL;
589
590 dsm_ids[dsm_count].uuid = ACPI_DSM_OEM_WIFI_UUID;
591 dsm_ids[dsm_count].callbacks = &wifi_dsm_callbacks[0];
592 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm_callbacks);
Meera Ravindranathf3375372022-11-10 11:27:00 +0530593 dsm_ids[dsm_count].arg = &dsm;
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530594 dsm_count++;
595 }
596 }
597
598 if (is_cnvi_ddr_rfim_enabled) {
599 dsm_ids[dsm_count].uuid = ACPI_DSM_RFIM_WIFI_UUID;
600 dsm_ids[dsm_count].callbacks = &wifi_dsm2_callbacks[0];
601 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm2_callbacks);
602 dsm_ids[dsm_count].arg = &is_cnvi_ddr_rfim_enabled;
603 dsm_count++;
604 }
605
606 acpigen_write_dsm_uuid_arr(dsm_ids, dsm_count);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700607
David Ruthea8330e2023-12-06 21:39:54 +0000608 /*
609 * Fill MediaTek MTCL related ACPI structure iff the device type is PCI,
610 * the device has the MediaTek vendor ID, and the MTCL feature is
611 * configured.
612 */
613 if (CONFIG(USE_MTCL)) {
614 if (dev->path.type == DEVICE_PATH_PCI &&
615 dev->vendor == PCI_VID_MEDIATEK)
616 write_mtcl_function();
617 }
618
619 acpigen_write_scope_end(); /* Scope */
Furquan Shaikh2736c822020-10-27 19:46:11 -0700620
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700621 printk(BIOS_INFO, "%s: %s %s\n", scope, dev->chip_ops ? dev->chip_ops->name : "",
622 dev_path(dev));
623}
624
Furquan Shaikhd4367502020-10-27 18:00:46 -0700625void wifi_pcie_fill_ssdt(const struct device *dev)
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700626{
627 const char *path;
628
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700629 path = acpi_device_path(dev);
630 if (!path)
631 return;
632
633 wifi_ssdt_write_device(dev, path);
Reka Norman93928192022-07-22 08:01:19 +1000634 wifi_ssdt_write_properties(dev, path);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700635}
636
Furquan Shaikhd4367502020-10-27 18:00:46 -0700637const char *wifi_pcie_acpi_name(const struct device *dev)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700638{
639 static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN];
640
641 /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */
642 snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X",
643 (dev_path_encode(dev) & 0xff));
644 return wifi_acpi_name;
645}
Furquan Shaikhd4367502020-10-27 18:00:46 -0700646
647void wifi_cnvi_fill_ssdt(const struct device *dev)
648{
649 const char *path;
Angel Pons1e124b92022-04-03 21:10:26 +0200650 if (!dev)
651 return;
Furquan Shaikhd4367502020-10-27 18:00:46 -0700652
Arthur Heymans7fcd4d52023-08-24 15:12:19 +0200653 path = acpi_device_path(dev->upstream->dev);
Furquan Shaikhd4367502020-10-27 18:00:46 -0700654 if (!path)
655 return;
656
657 wifi_ssdt_write_properties(dev, path);
658}