blob: 6abad83f8577c23e96187e64b7bcf4642c86035f [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>
8#include <sar.h>
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +05309#include <stdlib.h>
Furquan Shaikh2736c822020-10-27 19:46:11 -070010#include <wrdd.h>
11
12#include "chip.h"
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +053013#include "wifi.h"
Furquan Shaikh2736c822020-10-27 19:46:11 -070014#include "wifi_private.h"
15
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +053016/* WIFI Domain type */
17#define DOMAIN_TYPE_WIFI 0x7
Furquan Shaikh2736c822020-10-27 19:46:11 -070018
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +053019/* Maximum number DSM UUID bifurcations in _DSM */
20#define MAX_DSM_FUNCS 2
21
Furquan Shaikh2736c822020-10-27 19:46:11 -070022/*
23 * WIFI ACPI NAME = "WF" + hex value of last 8 bits of dev_path_encode + '\0'
24 * The above representation returns unique and consistent name every time
25 * generate_wifi_acpi_name is invoked. The last 8 bits of dev_path_encode is
26 * chosen since it contains the bus address of the device.
27 */
28#define WIFI_ACPI_NAME_MAX_LEN 5
29
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +053030/* Unique ID for the WIFI _DSM */
31#define ACPI_DSM_OEM_WIFI_UUID "F21202BF-8F78-4DC6-A5B3-1F738E285ADE"
32
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +053033/* Unique ID for CnviDdrRfim entry in WIFI _DSM */
34#define ACPI_DSM_RFIM_WIFI_UUID "7266172C-220B-4B29-814F-75E4DD26B5FD"
35
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +053036__weak int get_wifi_sar_limits(union wifi_sar_limits *sar_limits)
Furquan Shaikh2736c822020-10-27 19:46:11 -070037{
38 return -1;
39}
40
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +053041/*
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +053042 * Function 1: Allow PC OEMs to set ETSI 5.8GHz SRD in Passive/Disabled ESTI SRD
43 * Channels: 149, 153, 157, 161, 165
44 * 0 - ETSI 5.8GHz SRD active scan
45 * 1 - ETSI 5.8GHz SRD passive scan
46 * 2 - ETSI 5.8GHz SRD disabled
47 */
48static void wifi_dsm_srd_active_channels(void *args)
49{
50 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
51
52 acpigen_write_return_integer(dsm_config->disable_active_sdr_channels);
53}
54
55/*
56 * Function 2 : Supported Indonesia 5.15-5.35 GHz Band
57 * 0 - Set 5.115-5.35GHz to Disable in Indonesia
58 * 1 - Set 5.115-5.35GHz to Enable (Passive) in Indonesia
59 * 2 - Reserved
60 */
61static void wifi_dsm_indonasia_5Ghz_band_enable(void *args)
62{
63 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
64
65 acpigen_write_return_integer(dsm_config->support_indonesia_5g_band);
66}
67
68/*
69 * Function 3: Support Wi-Fi 6 11ax Rev 2 new channels on 6-7 GHz.
70 * Bit 0:
71 * 0 - No override; use device settings 0
72 * 1 - Force disable all countries that are not defined in the following bits
73 *
74 * Bit 1:
75 * 0 No override; USA 6GHz disable 0
76 * 1 6GHz allowed in the USA (enabled only if the device is certified to the USA)
77 */
78static void wifi_dsm_supported_ultra_high_band(void *args)
79{
80 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
81
82 acpigen_write_return_integer(dsm_config->support_ultra_high_band);
83}
84
85/*
86 * Function 4: Regulatory Special Configurations Enablements
87 */
88static void wifi_dsm_regulatory_configurations(void *args)
89{
90 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
91
92 acpigen_write_return_integer(dsm_config->regulatory_configurations);
93}
94
95/*
96 * Function 5: M.2 UART Interface Configuration
97 */
98static void wifi_dsm_uart_configurations(void *args)
99{
100 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
101
102 acpigen_write_return_integer(dsm_config->uart_configurations);
103}
104
105/*
106 * Function 6: Control Enablement 11ax on certificated modules
107 * Bit 0 - Apply changes to country Ukraine. 11Ax Setting within module certification
108 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
109 * 1 - Apply changes.
110 *
111 * Bit 1 - 11Ax Mode. Effective only if Bit 0 set to 1
112 * 0 - Disable 11Ax on country Ukraine [Default]
113 * 1 - Enable 11Ax on country Ukraine
114 *
115 * Bit 2 - Apply changes to country Russia. 11Ax Setting within module certification
116 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
117 * 1 - Apply changes.
118 *
119 * Bit 3 - 11Ax Mode. Effective only if Bit 2 set to 1
120 * 0 - Disable 11Ax on country Russia [Default]
121 * 1 - Enable 11Ax on country Russia
122 *
123 * Bit 31:04 - Reserved
124 *
125 * Note: Assumed Russia Work with Wi-Fi FW/OTP definitions
126 */
127static void wifi_dsm_ukrane_russia_11ax_enable(void *args)
128{
129 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
130
131 acpigen_write_return_integer(dsm_config->enablement_11ax);
132}
133
134/*
135 * Function 7: Control Enablement UNII-4 over certificate modules
136 */
137static void wifi_dsm_unii4_control_enable(void *args)
138{
139 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
140
141 acpigen_write_return_integer(dsm_config->unii_4);
142}
143
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530144static void wifi_dsm_ddrrfim_func3_cb(void *ptr)
145{
146 const bool is_cnvi_ddr_rfim_enabled = *(bool *)ptr;
Simon Yang59b383e2023-12-28 14:42:21 +0800147 acpigen_write_return_integer(is_cnvi_ddr_rfim_enabled ? 0 : 1);
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530148}
149
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +0530150static void (*wifi_dsm_callbacks[])(void *) = {
151 NULL, /* Function 0 */
152 wifi_dsm_srd_active_channels, /* Function 1 */
153 wifi_dsm_indonasia_5Ghz_band_enable, /* Function 2 */
154 wifi_dsm_supported_ultra_high_band, /* Function 3 */
155 wifi_dsm_regulatory_configurations, /* Function 4 */
156 wifi_dsm_uart_configurations, /* Function 5 */
157 wifi_dsm_ukrane_russia_11ax_enable, /* Function 6 */
158 wifi_dsm_unii4_control_enable, /* Function 7 */
159};
160
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530161/*
162 * The current DSM2 table is only exporting one function (function 3), some more
163 * functions are reserved so marking them NULL.
164*/
165static void (*wifi_dsm2_callbacks[])(void *) = {
166 NULL, /* Function 0 */
167 NULL, /* Function 1 */
168 NULL, /* Function 2 */
169 wifi_dsm_ddrrfim_func3_cb, /* Function 3 */
170};
171
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530172static const uint8_t *sar_fetch_set(const struct sar_profile *sar, size_t set_num)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700173{
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530174 const uint8_t *sar_table = &sar->sar_table[0];
Furquan Shaikh2736c822020-10-27 19:46:11 -0700175
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530176 return sar_table + (sar->chains_count * sar->subbands_count * set_num);
177}
Furquan Shaikh2736c822020-10-27 19:46:11 -0700178
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530179static const uint8_t *wgds_fetch_set(struct geo_profile *wgds, size_t set_num)
180{
181 const uint8_t *wgds_table = &wgds->wgds_table[0];
182
183 return wgds_table + (wgds->bands_count * set_num);
184}
185
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530186static const uint8_t *ppag_fetch_set(struct gain_profile *ppag, size_t set_num)
187{
188 const uint8_t *ppag_table = &ppag->ppag_table[0];
189
190 return ppag_table + (ppag->bands_count * set_num);
191}
192
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530193static void sar_emit_wrds(const struct sar_profile *sar)
194{
195 int i;
196 size_t package_size, table_size;
197 const uint8_t *set;
198
199 if (sar == NULL)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700200 return;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700201
202 /*
203 * Name ("WRDS", Package () {
204 * Revision,
205 * Package () {
206 * Domain Type, // 0x7:WiFi
207 * WiFi SAR BIOS, // BIOS SAR Enable/disable
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530208 * SAR Table Set // Set#1 of SAR Table
Furquan Shaikh2736c822020-10-27 19:46:11 -0700209 * }
210 * })
211 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530212 if (sar->revision > MAX_SAR_REVISION) {
Julius Wernere9665952022-01-21 17:06:20 -0800213 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530214 return;
215 }
216
Furquan Shaikh2736c822020-10-27 19:46:11 -0700217 acpigen_write_name("WRDS");
218 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530219 acpigen_write_dword(sar->revision);
220
221 table_size = sar->chains_count * sar->subbands_count;
222 /* Emit 'Domain Type' + 'WiFi SAR Enable' + Set#1 */
223 package_size = 1 + 1 + table_size;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700224 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530225 acpigen_write_dword(DOMAIN_TYPE_WIFI);
226 acpigen_write_dword(1);
227
228 set = sar_fetch_set(sar, 0);
229 for (i = 0; i < table_size; i++)
230 acpigen_write_byte(set[i]);
231
232 acpigen_write_package_end();
233 acpigen_write_package_end();
234}
235
236static void sar_emit_ewrd(const struct sar_profile *sar)
237{
238 int i;
239 size_t package_size, set_num, table_size;
240 const uint8_t *set;
241
242 if (sar == NULL)
243 return;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700244
245 /*
246 * Name ("EWRD", Package () {
247 * Revision,
248 * Package () {
249 * Domain Type, // 0x7:WiFi
250 * Dynamic SAR Enable, // Dynamic SAR Enable/disable
251 * Extended SAR sets, // Number of optional SAR table sets
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530252 * SAR Table Set, // Set#2 of SAR Table
253 * SAR Table Set, // Set#3 of SAR Table
254 * SAR Table Set // Set#4 of SAR Table
Furquan Shaikh2736c822020-10-27 19:46:11 -0700255 * }
256 * })
257 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530258 if (sar->revision > MAX_SAR_REVISION) {
Julius Wernere9665952022-01-21 17:06:20 -0800259 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530260 return;
261 }
262
263 if (sar->dsar_set_count == 0) {
Julius Wernere9665952022-01-21 17:06:20 -0800264 printk(BIOS_WARNING, "DSAR set count is 0\n");
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530265 return;
266 }
267
Furquan Shaikh2736c822020-10-27 19:46:11 -0700268 acpigen_write_name("EWRD");
269 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530270 acpigen_write_dword(sar->revision);
271
272 table_size = sar->chains_count * sar->subbands_count;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700273 /*
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530274 * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Extended SAR sets count'
Furquan Shaikh2736c822020-10-27 19:46:11 -0700275 * + number of bytes for Set#2 & 3 & 4
276 */
Matt Chen07e6b5f2021-11-04 18:13:25 +0800277 package_size = 1 + 1 + 1 + table_size * MAX_DSAR_SET_COUNT;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700278 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530279 acpigen_write_dword(DOMAIN_TYPE_WIFI);
280 acpigen_write_dword(1);
281 acpigen_write_dword(sar->dsar_set_count);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700282
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530283 for (set_num = 1; set_num <= sar->dsar_set_count; set_num++) {
284 set = sar_fetch_set(sar, set_num);
285 for (i = 0; i < table_size; i++)
286 acpigen_write_byte(set[i]);
287 }
288
289 /* wifi driver always expects 3 DSAR sets */
290 for (i = 0; i < (table_size * (MAX_DSAR_SET_COUNT - sar->dsar_set_count)); i++)
291 acpigen_write_byte(0);
292
293 acpigen_write_package_end();
294 acpigen_write_package_end();
295}
296
297static void sar_emit_wgds(struct geo_profile *wgds)
298{
299 int i;
300 size_t package_size, set_num;
301 const uint8_t *set;
302
303 if (wgds == NULL)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700304 return;
305
306 /*
307 * Name ("WGDS", Package() {
308 * Revision,
309 * Package() {
310 * DomainType, // 0x7:WiFi
311 * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max
312 * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset
313 * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset
314 * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max
315 * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset
316 * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530317 * WgdsWiFiSarDeltaGroup1PowerMax3, // Group 1 FCC 6000-7000 Max
318 * WgdsWiFiSarDeltaGroup1PowerChainA3, // Group 1 FCC 6000-7000 A Offset
319 * WgdsWiFiSarDeltaGroup1PowerChainB3, // Group 1 FCC 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700320 * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max
321 * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset
322 * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset
323 * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max
324 * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset
325 * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530326 * WgdsWiFiSarDeltaGroup2PowerMax3, // Group 2 EC Jap 6000-7000 Max
327 * WgdsWiFiSarDeltaGroup2PowerChainA3, // Group 2 EC Jap 6000-7000 A Offset
328 * WgdsWiFiSarDeltaGroup2PowerChainB3, // Group 2 EC Jap 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700329 * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max
330 * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset
331 * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset
332 * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max
333 * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset
334 * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530335 * WgdsWiFiSarDeltaGroup3PowerMax3, // Group 3 ROW 6000-7000 Max
336 * WgdsWiFiSarDeltaGroup3PowerChainA3, // Group 3 ROW 6000-7000 A Offset
337 * WgdsWiFiSarDeltaGroup3PowerChainB3, // Group 3 ROW 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700338 * }
339 * })
340 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530341 if (wgds->revision > MAX_GEO_OFFSET_REVISION) {
Julius Wernere9665952022-01-21 17:06:20 -0800342 printk(BIOS_ERR, "Invalid WGDS revision: %d\n", wgds->revision);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530343 return;
344 }
Furquan Shaikh2736c822020-10-27 19:46:11 -0700345
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530346 package_size = 1 + wgds->chains_count * wgds->bands_count;
347
Furquan Shaikh2736c822020-10-27 19:46:11 -0700348 acpigen_write_name("WGDS");
349 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530350 acpigen_write_dword(wgds->revision);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700351 /* Emit 'Domain Type' +
352 * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS)
353 */
Furquan Shaikh2736c822020-10-27 19:46:11 -0700354 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530355 acpigen_write_dword(DOMAIN_TYPE_WIFI);
356
357 for (set_num = 0; set_num < wgds->chains_count; set_num++) {
358 set = wgds_fetch_set(wgds, set_num);
359 for (i = 0; i < wgds->bands_count; i++)
360 acpigen_write_byte(set[i]);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700361 }
362
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530363 acpigen_write_package_end();
364 acpigen_write_package_end();
365}
366
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530367static void sar_emit_ppag(struct gain_profile *ppag)
368{
369 int i;
370 size_t package_size, set_num;
371 const uint8_t *set;
372
373 if (ppag == NULL)
374 return;
375
376 /*
377 * Name ("PPAG", Package () {
378 * Revision,
379 * Package () {
380 * Domain Type, // 0x7:WiFi
381 * PPAG Mode, // Defines the mode of ANT_gain control to be used
382 * ANT_gain Table Chain A // Defines the ANT_gain in dBi for chain A
383 * ANT_gain Table Chain B // Defines the ANT_gain in dBi for chain B
384 * }
385 * })
386 */
387 if (ppag->revision > MAX_ANT_GAINS_REVISION) {
388 printk(BIOS_ERR, "Invalid PPAG revision: %d\n", ppag->revision);
389 return;
390 }
391
392 package_size = 1 + 1 + ppag->chains_count * ppag->bands_count;
393
394 acpigen_write_name("PPAG");
395 acpigen_write_package(2);
396 acpigen_write_dword(ppag->revision);
397 acpigen_write_package(package_size);
398 acpigen_write_dword(DOMAIN_TYPE_WIFI);
399 acpigen_write_dword(ppag->mode);
400
401 for (set_num = 0; set_num < ppag->chains_count; set_num++) {
402 set = ppag_fetch_set(ppag, set_num);
403 for (i = 0; i < ppag->bands_count; i++)
404 acpigen_write_byte(set[i]);
405 }
406
407 acpigen_write_package_end();
408 acpigen_write_package_end();
409}
410
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530411static void sar_emit_wtas(struct avg_profile *wtas)
412{
413 int i;
414 size_t package_size;
415
416 if (wtas == NULL)
417 return;
418
419 /*
420 * Name (WTAS, Package() {
421 * {
422 * Revision,
423 * Package()
424 * {
425 * DomainType, // 0x7:WiFi
426 * WifiTASSelection, // Enable/Disable the TAS feature
427 * WifiTASListEntries, // No. of blocked countries not approved by OEM to
428 * BlockedListEntry1, support this feature
429 * BlockedListEntry2,
430 * BlockedListEntry3,
431 * BlockedListEntry4,
432 * BlockedListEntry5,
433 * BlockedListEntry6,
434 * BlockedListEntry7,
435 * BlockedListEntry8,
436 * BlockedListEntry9,
437 * BlockedListEntry10,
438 * BlockedListEntry11,
439 * BlockedListEntry12,
440 * BlockedListEntry13,
441 * BlockedListEntry14,
442 * BlockedListEntry15,
443 * BlockedListEntry16,
444 * }
445 * })
446 */
447 package_size = 1 + 1 + 1 + MAX_DENYLIST_ENTRY;
448
449 acpigen_write_name("WTAS");
450 acpigen_write_package(2);
451 acpigen_write_dword(wtas->revision);
452 acpigen_write_package(package_size);
453 acpigen_write_dword(DOMAIN_TYPE_WIFI);
Sugnan Prabhu S627c8442021-09-06 15:05:56 +0530454 acpigen_write_byte(wtas->tas_selection);
455 acpigen_write_byte(wtas->tas_list_size);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530456 for (i = 0; i < MAX_DENYLIST_ENTRY; i++)
Sugnan Prabhu S627c8442021-09-06 15:05:56 +0530457 acpigen_write_word(wtas->deny_list_entry[i]);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530458
459 acpigen_write_package_end();
460 acpigen_write_package_end();
461}
462
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530463static void emit_sar_acpi_structures(const struct device *dev, struct dsm_profile *dsm)
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530464{
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530465 union wifi_sar_limits sar_limits = {{NULL, NULL, NULL, NULL, NULL} };
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530466
467 /*
468 * If device type is PCI, ensure that the device has Intel vendor ID. CBFS SAR and SAR
469 * ACPI tables are currently used only by Intel WiFi devices.
470 */
Felix Singer43b7f412022-03-07 04:34:52 +0100471 if (dev->path.type == DEVICE_PATH_PCI && dev->vendor != PCI_VID_INTEL)
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530472 return;
473
Martin Roth3e25f852023-09-04 15:37:07 -0600474 /* Retrieve the SAR limits data */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530475 if (get_wifi_sar_limits(&sar_limits) < 0) {
Julius Wernere9665952022-01-21 17:06:20 -0800476 printk(BIOS_ERR, "failed getting SAR limits!\n");
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530477 return;
478 }
479
480 sar_emit_wrds(sar_limits.sar);
481 sar_emit_ewrd(sar_limits.sar);
482 sar_emit_wgds(sar_limits.wgds);
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530483 sar_emit_ppag(sar_limits.ppag);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530484 sar_emit_wtas(sar_limits.wtas);
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530485
486 /* copy the dsm data to be later used for creating _DSM function */
487 if (sar_limits.dsm != NULL)
Meera Ravindranathf3375372022-11-10 11:27:00 +0530488 memcpy(dsm, sar_limits.dsm, sizeof(struct dsm_profile));
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530489
490 free(sar_limits.sar);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700491}
492
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700493static void wifi_ssdt_write_device(const struct device *dev, const char *path)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700494{
Furquan Shaikh2736c822020-10-27 19:46:11 -0700495 /* Device */
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700496 acpigen_write_device(path);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700497 acpi_device_write_uid(dev);
498
499 if (dev->chip_ops)
500 acpigen_write_name_string("_DDN", dev->chip_ops->name);
501
502 /* Address */
503 acpigen_write_ADR_pci_device(dev);
504
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700505 acpigen_pop_len(); /* Device */
506}
507
508static void wifi_ssdt_write_properties(const struct device *dev, const char *scope)
509{
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530510 const struct drivers_wifi_generic_config *config = dev->chip_info;
Angel Pons1e124b92022-04-03 21:10:26 +0200511
512 bool is_cnvi_ddr_rfim_enabled = config && config->enable_cnvi_ddr_rfim;
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530513
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700514 /* Scope */
515 acpigen_write_scope(scope);
516
Reka Norman93928192022-07-22 08:01:19 +1000517 if (config) {
518 /* Wake capabilities */
519 acpigen_write_PRW(config->wake, ACPI_S3);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700520
Reka Norman93928192022-07-22 08:01:19 +1000521 /* Add _DSD for DmaProperty property. */
Kapil Porwal0b20a172022-11-26 20:10:47 +0530522 if (config->add_acpi_dma_property)
523 acpi_device_add_dma_property(NULL);
Tim Wawrzynczak3babc8e2022-01-25 14:05:20 -0700524 }
525
Furquan Shaikh2736c822020-10-27 19:46:11 -0700526 /* Fill regulatory domain structure */
527 if (CONFIG(HAVE_REGULATORY_DOMAIN)) {
528 /*
529 * Name ("WRDD", Package () {
530 * WRDD_REVISION, // Revision
531 * Package () {
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530532 * DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
Furquan Shaikh2736c822020-10-27 19:46:11 -0700533 * wifi_regulatory_domain() // Country Identifier
534 * }
535 * })
536 */
537 acpigen_write_name("WRDD");
538 acpigen_write_package(2);
539 acpigen_write_integer(WRDD_REVISION);
540 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530541 acpigen_write_dword(DOMAIN_TYPE_WIFI);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700542 acpigen_write_dword(wifi_regulatory_domain());
543 acpigen_pop_len();
544 acpigen_pop_len();
545 }
546
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530547 struct dsm_uuid dsm_ids[MAX_DSM_FUNCS];
548 /* We will need a copy dsm data to be used later for creating _DSM function */
549 struct dsm_profile dsm = {0};
550 uint8_t dsm_count = 0;
551
Martin Roth3e25f852023-09-04 15:37:07 -0600552 /* Fill Wifi SAR related ACPI structures */
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530553 if (CONFIG(USE_SAR)) {
554 emit_sar_acpi_structures(dev, &dsm);
555
556 if (dsm.supported_functions != 0) {
557 for (int i = 1; i < ARRAY_SIZE(wifi_dsm_callbacks); i++)
558 if (!(dsm.supported_functions & (1 << i)))
559 wifi_dsm_callbacks[i] = NULL;
560
561 dsm_ids[dsm_count].uuid = ACPI_DSM_OEM_WIFI_UUID;
562 dsm_ids[dsm_count].callbacks = &wifi_dsm_callbacks[0];
563 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm_callbacks);
Meera Ravindranathf3375372022-11-10 11:27:00 +0530564 dsm_ids[dsm_count].arg = &dsm;
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530565 dsm_count++;
566 }
567 }
568
569 if (is_cnvi_ddr_rfim_enabled) {
570 dsm_ids[dsm_count].uuid = ACPI_DSM_RFIM_WIFI_UUID;
571 dsm_ids[dsm_count].callbacks = &wifi_dsm2_callbacks[0];
572 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm2_callbacks);
573 dsm_ids[dsm_count].arg = &is_cnvi_ddr_rfim_enabled;
574 dsm_count++;
575 }
576
577 acpigen_write_dsm_uuid_arr(dsm_ids, dsm_count);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700578
Furquan Shaikh2736c822020-10-27 19:46:11 -0700579 acpigen_pop_len(); /* Scope */
580
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700581 printk(BIOS_INFO, "%s: %s %s\n", scope, dev->chip_ops ? dev->chip_ops->name : "",
582 dev_path(dev));
583}
584
Furquan Shaikhd4367502020-10-27 18:00:46 -0700585void wifi_pcie_fill_ssdt(const struct device *dev)
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700586{
587 const char *path;
588
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700589 path = acpi_device_path(dev);
590 if (!path)
591 return;
592
593 wifi_ssdt_write_device(dev, path);
Reka Norman93928192022-07-22 08:01:19 +1000594 wifi_ssdt_write_properties(dev, path);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700595}
596
Furquan Shaikhd4367502020-10-27 18:00:46 -0700597const char *wifi_pcie_acpi_name(const struct device *dev)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700598{
599 static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN];
600
601 /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */
602 snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X",
603 (dev_path_encode(dev) & 0xff));
604 return wifi_acpi_name;
605}
Furquan Shaikhd4367502020-10-27 18:00:46 -0700606
607void wifi_cnvi_fill_ssdt(const struct device *dev)
608{
609 const char *path;
Angel Pons1e124b92022-04-03 21:10:26 +0200610 if (!dev)
611 return;
Furquan Shaikhd4367502020-10-27 18:00:46 -0700612
Arthur Heymans7fcd4d52023-08-24 15:12:19 +0200613 path = acpi_device_path(dev->upstream->dev);
Furquan Shaikhd4367502020-10-27 18:00:46 -0700614 if (!path)
615 return;
616
617 wifi_ssdt_write_properties(dev, path);
618}