blob: fd1da069341988cb0b2e17040d4f5a9964b6759a [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
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530146static void wifi_dsm_ddrrfim_func3_cb(void *ptr)
147{
148 const bool is_cnvi_ddr_rfim_enabled = *(bool *)ptr;
Simon Yang59b383e2023-12-28 14:42:21 +0800149 acpigen_write_return_integer(is_cnvi_ddr_rfim_enabled ? 0 : 1);
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530150}
151
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +0530152static void (*wifi_dsm_callbacks[])(void *) = {
153 NULL, /* Function 0 */
154 wifi_dsm_srd_active_channels, /* Function 1 */
155 wifi_dsm_indonasia_5Ghz_band_enable, /* Function 2 */
156 wifi_dsm_supported_ultra_high_band, /* Function 3 */
157 wifi_dsm_regulatory_configurations, /* Function 4 */
158 wifi_dsm_uart_configurations, /* Function 5 */
159 wifi_dsm_ukrane_russia_11ax_enable, /* Function 6 */
160 wifi_dsm_unii4_control_enable, /* Function 7 */
161};
162
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530163/*
164 * The current DSM2 table is only exporting one function (function 3), some more
165 * functions are reserved so marking them NULL.
166*/
167static void (*wifi_dsm2_callbacks[])(void *) = {
168 NULL, /* Function 0 */
169 NULL, /* Function 1 */
170 NULL, /* Function 2 */
171 wifi_dsm_ddrrfim_func3_cb, /* Function 3 */
172};
173
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530174static const uint8_t *sar_fetch_set(const struct sar_profile *sar, size_t set_num)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700175{
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530176 const uint8_t *sar_table = &sar->sar_table[0];
Furquan Shaikh2736c822020-10-27 19:46:11 -0700177
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530178 return sar_table + (sar->chains_count * sar->subbands_count * set_num);
179}
Furquan Shaikh2736c822020-10-27 19:46:11 -0700180
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530181static const uint8_t *wgds_fetch_set(struct geo_profile *wgds, size_t set_num)
182{
183 const uint8_t *wgds_table = &wgds->wgds_table[0];
184
185 return wgds_table + (wgds->bands_count * set_num);
186}
187
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530188static const uint8_t *ppag_fetch_set(struct gain_profile *ppag, size_t set_num)
189{
190 const uint8_t *ppag_table = &ppag->ppag_table[0];
191
192 return ppag_table + (ppag->bands_count * set_num);
193}
194
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530195static void sar_emit_wrds(const struct sar_profile *sar)
196{
197 int i;
198 size_t package_size, table_size;
199 const uint8_t *set;
200
201 if (sar == NULL)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700202 return;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700203
204 /*
205 * Name ("WRDS", Package () {
206 * Revision,
207 * Package () {
208 * Domain Type, // 0x7:WiFi
209 * WiFi SAR BIOS, // BIOS SAR Enable/disable
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530210 * SAR Table Set // Set#1 of SAR Table
Furquan Shaikh2736c822020-10-27 19:46:11 -0700211 * }
212 * })
213 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530214 if (sar->revision > MAX_SAR_REVISION) {
Julius Wernere9665952022-01-21 17:06:20 -0800215 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530216 return;
217 }
218
Furquan Shaikh2736c822020-10-27 19:46:11 -0700219 acpigen_write_name("WRDS");
220 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530221 acpigen_write_dword(sar->revision);
222
223 table_size = sar->chains_count * sar->subbands_count;
224 /* Emit 'Domain Type' + 'WiFi SAR Enable' + Set#1 */
225 package_size = 1 + 1 + table_size;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700226 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530227 acpigen_write_dword(DOMAIN_TYPE_WIFI);
228 acpigen_write_dword(1);
229
230 set = sar_fetch_set(sar, 0);
231 for (i = 0; i < table_size; i++)
232 acpigen_write_byte(set[i]);
233
234 acpigen_write_package_end();
235 acpigen_write_package_end();
236}
237
238static void sar_emit_ewrd(const struct sar_profile *sar)
239{
240 int i;
241 size_t package_size, set_num, table_size;
242 const uint8_t *set;
243
244 if (sar == NULL)
245 return;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700246
247 /*
248 * Name ("EWRD", Package () {
249 * Revision,
250 * Package () {
251 * Domain Type, // 0x7:WiFi
252 * Dynamic SAR Enable, // Dynamic SAR Enable/disable
253 * Extended SAR sets, // Number of optional SAR table sets
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530254 * SAR Table Set, // Set#2 of SAR Table
255 * SAR Table Set, // Set#3 of SAR Table
256 * SAR Table Set // Set#4 of SAR Table
Furquan Shaikh2736c822020-10-27 19:46:11 -0700257 * }
258 * })
259 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530260 if (sar->revision > MAX_SAR_REVISION) {
Julius Wernere9665952022-01-21 17:06:20 -0800261 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530262 return;
263 }
264
265 if (sar->dsar_set_count == 0) {
Julius Wernere9665952022-01-21 17:06:20 -0800266 printk(BIOS_WARNING, "DSAR set count is 0\n");
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530267 return;
268 }
269
Furquan Shaikh2736c822020-10-27 19:46:11 -0700270 acpigen_write_name("EWRD");
271 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530272 acpigen_write_dword(sar->revision);
273
274 table_size = sar->chains_count * sar->subbands_count;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700275 /*
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530276 * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Extended SAR sets count'
Furquan Shaikh2736c822020-10-27 19:46:11 -0700277 * + number of bytes for Set#2 & 3 & 4
278 */
Matt Chen07e6b5f2021-11-04 18:13:25 +0800279 package_size = 1 + 1 + 1 + table_size * MAX_DSAR_SET_COUNT;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700280 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530281 acpigen_write_dword(DOMAIN_TYPE_WIFI);
282 acpigen_write_dword(1);
283 acpigen_write_dword(sar->dsar_set_count);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700284
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530285 for (set_num = 1; set_num <= sar->dsar_set_count; set_num++) {
286 set = sar_fetch_set(sar, set_num);
287 for (i = 0; i < table_size; i++)
288 acpigen_write_byte(set[i]);
289 }
290
291 /* wifi driver always expects 3 DSAR sets */
292 for (i = 0; i < (table_size * (MAX_DSAR_SET_COUNT - sar->dsar_set_count)); i++)
293 acpigen_write_byte(0);
294
295 acpigen_write_package_end();
296 acpigen_write_package_end();
297}
298
299static void sar_emit_wgds(struct geo_profile *wgds)
300{
301 int i;
302 size_t package_size, set_num;
303 const uint8_t *set;
304
305 if (wgds == NULL)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700306 return;
307
308 /*
309 * Name ("WGDS", Package() {
310 * Revision,
311 * Package() {
312 * DomainType, // 0x7:WiFi
313 * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max
314 * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset
315 * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset
316 * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max
317 * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset
318 * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530319 * WgdsWiFiSarDeltaGroup1PowerMax3, // Group 1 FCC 6000-7000 Max
320 * WgdsWiFiSarDeltaGroup1PowerChainA3, // Group 1 FCC 6000-7000 A Offset
321 * WgdsWiFiSarDeltaGroup1PowerChainB3, // Group 1 FCC 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700322 * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max
323 * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset
324 * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset
325 * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max
326 * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset
327 * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530328 * WgdsWiFiSarDeltaGroup2PowerMax3, // Group 2 EC Jap 6000-7000 Max
329 * WgdsWiFiSarDeltaGroup2PowerChainA3, // Group 2 EC Jap 6000-7000 A Offset
330 * WgdsWiFiSarDeltaGroup2PowerChainB3, // Group 2 EC Jap 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700331 * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max
332 * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset
333 * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset
334 * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max
335 * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset
336 * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530337 * WgdsWiFiSarDeltaGroup3PowerMax3, // Group 3 ROW 6000-7000 Max
338 * WgdsWiFiSarDeltaGroup3PowerChainA3, // Group 3 ROW 6000-7000 A Offset
339 * WgdsWiFiSarDeltaGroup3PowerChainB3, // Group 3 ROW 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700340 * }
341 * })
342 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530343 if (wgds->revision > MAX_GEO_OFFSET_REVISION) {
Julius Wernere9665952022-01-21 17:06:20 -0800344 printk(BIOS_ERR, "Invalid WGDS revision: %d\n", wgds->revision);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530345 return;
346 }
Furquan Shaikh2736c822020-10-27 19:46:11 -0700347
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530348 package_size = 1 + wgds->chains_count * wgds->bands_count;
349
Furquan Shaikh2736c822020-10-27 19:46:11 -0700350 acpigen_write_name("WGDS");
351 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530352 acpigen_write_dword(wgds->revision);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700353 /* Emit 'Domain Type' +
354 * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS)
355 */
Furquan Shaikh2736c822020-10-27 19:46:11 -0700356 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530357 acpigen_write_dword(DOMAIN_TYPE_WIFI);
358
359 for (set_num = 0; set_num < wgds->chains_count; set_num++) {
360 set = wgds_fetch_set(wgds, set_num);
361 for (i = 0; i < wgds->bands_count; i++)
362 acpigen_write_byte(set[i]);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700363 }
364
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530365 acpigen_write_package_end();
366 acpigen_write_package_end();
367}
368
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530369static void sar_emit_ppag(struct gain_profile *ppag)
370{
371 int i;
372 size_t package_size, set_num;
373 const uint8_t *set;
374
375 if (ppag == NULL)
376 return;
377
378 /*
379 * Name ("PPAG", Package () {
380 * Revision,
381 * Package () {
382 * Domain Type, // 0x7:WiFi
383 * PPAG Mode, // Defines the mode of ANT_gain control to be used
384 * ANT_gain Table Chain A // Defines the ANT_gain in dBi for chain A
385 * ANT_gain Table Chain B // Defines the ANT_gain in dBi for chain B
386 * }
387 * })
388 */
389 if (ppag->revision > MAX_ANT_GAINS_REVISION) {
390 printk(BIOS_ERR, "Invalid PPAG revision: %d\n", ppag->revision);
391 return;
392 }
393
394 package_size = 1 + 1 + ppag->chains_count * ppag->bands_count;
395
396 acpigen_write_name("PPAG");
397 acpigen_write_package(2);
398 acpigen_write_dword(ppag->revision);
399 acpigen_write_package(package_size);
400 acpigen_write_dword(DOMAIN_TYPE_WIFI);
401 acpigen_write_dword(ppag->mode);
402
403 for (set_num = 0; set_num < ppag->chains_count; set_num++) {
404 set = ppag_fetch_set(ppag, set_num);
405 for (i = 0; i < ppag->bands_count; i++)
406 acpigen_write_byte(set[i]);
407 }
408
409 acpigen_write_package_end();
410 acpigen_write_package_end();
411}
412
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530413static void sar_emit_wtas(struct avg_profile *wtas)
414{
415 int i;
416 size_t package_size;
417
418 if (wtas == NULL)
419 return;
420
421 /*
422 * Name (WTAS, Package() {
423 * {
424 * Revision,
425 * Package()
426 * {
427 * DomainType, // 0x7:WiFi
428 * WifiTASSelection, // Enable/Disable the TAS feature
429 * WifiTASListEntries, // No. of blocked countries not approved by OEM to
430 * BlockedListEntry1, support this feature
431 * BlockedListEntry2,
432 * BlockedListEntry3,
433 * BlockedListEntry4,
434 * BlockedListEntry5,
435 * BlockedListEntry6,
436 * BlockedListEntry7,
437 * BlockedListEntry8,
438 * BlockedListEntry9,
439 * BlockedListEntry10,
440 * BlockedListEntry11,
441 * BlockedListEntry12,
442 * BlockedListEntry13,
443 * BlockedListEntry14,
444 * BlockedListEntry15,
445 * BlockedListEntry16,
446 * }
447 * })
448 */
449 package_size = 1 + 1 + 1 + MAX_DENYLIST_ENTRY;
450
451 acpigen_write_name("WTAS");
452 acpigen_write_package(2);
453 acpigen_write_dword(wtas->revision);
454 acpigen_write_package(package_size);
455 acpigen_write_dword(DOMAIN_TYPE_WIFI);
Sugnan Prabhu S627c8442021-09-06 15:05:56 +0530456 acpigen_write_byte(wtas->tas_selection);
457 acpigen_write_byte(wtas->tas_list_size);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530458 for (i = 0; i < MAX_DENYLIST_ENTRY; i++)
Sugnan Prabhu S627c8442021-09-06 15:05:56 +0530459 acpigen_write_word(wtas->deny_list_entry[i]);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530460
461 acpigen_write_package_end();
462 acpigen_write_package_end();
463}
464
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530465static void emit_sar_acpi_structures(const struct device *dev, struct dsm_profile *dsm)
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530466{
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530467 union wifi_sar_limits sar_limits = {{NULL, NULL, NULL, NULL, NULL} };
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530468
469 /*
470 * If device type is PCI, ensure that the device has Intel vendor ID. CBFS SAR and SAR
471 * ACPI tables are currently used only by Intel WiFi devices.
472 */
Felix Singer43b7f412022-03-07 04:34:52 +0100473 if (dev->path.type == DEVICE_PATH_PCI && dev->vendor != PCI_VID_INTEL)
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530474 return;
475
Martin Roth3e25f852023-09-04 15:37:07 -0600476 /* Retrieve the SAR limits data */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530477 if (get_wifi_sar_limits(&sar_limits) < 0) {
Julius Wernere9665952022-01-21 17:06:20 -0800478 printk(BIOS_ERR, "failed getting SAR limits!\n");
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530479 return;
480 }
481
482 sar_emit_wrds(sar_limits.sar);
483 sar_emit_ewrd(sar_limits.sar);
484 sar_emit_wgds(sar_limits.wgds);
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530485 sar_emit_ppag(sar_limits.ppag);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530486 sar_emit_wtas(sar_limits.wtas);
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530487
488 /* copy the dsm data to be later used for creating _DSM function */
489 if (sar_limits.dsm != NULL)
Meera Ravindranathf3375372022-11-10 11:27:00 +0530490 memcpy(dsm, sar_limits.dsm, sizeof(struct dsm_profile));
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530491
492 free(sar_limits.sar);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700493}
494
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700495static void wifi_ssdt_write_device(const struct device *dev, const char *path)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700496{
Furquan Shaikh2736c822020-10-27 19:46:11 -0700497 /* Device */
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700498 acpigen_write_device(path);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700499 acpi_device_write_uid(dev);
500
501 if (dev->chip_ops)
502 acpigen_write_name_string("_DDN", dev->chip_ops->name);
503
504 /* Address */
505 acpigen_write_ADR_pci_device(dev);
506
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700507 acpigen_pop_len(); /* Device */
508}
509
510static void wifi_ssdt_write_properties(const struct device *dev, const char *scope)
511{
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530512 const struct drivers_wifi_generic_config *config = dev->chip_info;
Angel Pons1e124b92022-04-03 21:10:26 +0200513
514 bool is_cnvi_ddr_rfim_enabled = config && config->enable_cnvi_ddr_rfim;
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530515
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700516 /* Scope */
517 acpigen_write_scope(scope);
518
Reka Norman93928192022-07-22 08:01:19 +1000519 if (config) {
520 /* Wake capabilities */
521 acpigen_write_PRW(config->wake, ACPI_S3);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700522
Reka Norman93928192022-07-22 08:01:19 +1000523 /* Add _DSD for DmaProperty property. */
Kapil Porwal0b20a172022-11-26 20:10:47 +0530524 if (config->add_acpi_dma_property)
525 acpi_device_add_dma_property(NULL);
Tim Wawrzynczak3babc8e2022-01-25 14:05:20 -0700526 }
527
Furquan Shaikh2736c822020-10-27 19:46:11 -0700528 /* Fill regulatory domain structure */
529 if (CONFIG(HAVE_REGULATORY_DOMAIN)) {
530 /*
531 * Name ("WRDD", Package () {
532 * WRDD_REVISION, // Revision
533 * Package () {
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530534 * DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
Furquan Shaikh2736c822020-10-27 19:46:11 -0700535 * wifi_regulatory_domain() // Country Identifier
536 * }
537 * })
538 */
539 acpigen_write_name("WRDD");
540 acpigen_write_package(2);
541 acpigen_write_integer(WRDD_REVISION);
542 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530543 acpigen_write_dword(DOMAIN_TYPE_WIFI);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700544 acpigen_write_dword(wifi_regulatory_domain());
545 acpigen_pop_len();
546 acpigen_pop_len();
547 }
548
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530549 struct dsm_uuid dsm_ids[MAX_DSM_FUNCS];
550 /* We will need a copy dsm data to be used later for creating _DSM function */
551 struct dsm_profile dsm = {0};
552 uint8_t dsm_count = 0;
553
Martin Roth3e25f852023-09-04 15:37:07 -0600554 /* Fill Wifi SAR related ACPI structures */
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530555 if (CONFIG(USE_SAR)) {
556 emit_sar_acpi_structures(dev, &dsm);
557
558 if (dsm.supported_functions != 0) {
559 for (int i = 1; i < ARRAY_SIZE(wifi_dsm_callbacks); i++)
560 if (!(dsm.supported_functions & (1 << i)))
561 wifi_dsm_callbacks[i] = NULL;
562
563 dsm_ids[dsm_count].uuid = ACPI_DSM_OEM_WIFI_UUID;
564 dsm_ids[dsm_count].callbacks = &wifi_dsm_callbacks[0];
565 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm_callbacks);
Meera Ravindranathf3375372022-11-10 11:27:00 +0530566 dsm_ids[dsm_count].arg = &dsm;
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530567 dsm_count++;
568 }
569 }
570
571 if (is_cnvi_ddr_rfim_enabled) {
572 dsm_ids[dsm_count].uuid = ACPI_DSM_RFIM_WIFI_UUID;
573 dsm_ids[dsm_count].callbacks = &wifi_dsm2_callbacks[0];
574 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm2_callbacks);
575 dsm_ids[dsm_count].arg = &is_cnvi_ddr_rfim_enabled;
576 dsm_count++;
577 }
578
579 acpigen_write_dsm_uuid_arr(dsm_ids, dsm_count);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700580
David Ruthea8330e2023-12-06 21:39:54 +0000581 /*
582 * Fill MediaTek MTCL related ACPI structure iff the device type is PCI,
583 * the device has the MediaTek vendor ID, and the MTCL feature is
584 * configured.
585 */
586 if (CONFIG(USE_MTCL)) {
587 if (dev->path.type == DEVICE_PATH_PCI &&
588 dev->vendor == PCI_VID_MEDIATEK)
589 write_mtcl_function();
590 }
591
592 acpigen_write_scope_end(); /* Scope */
Furquan Shaikh2736c822020-10-27 19:46:11 -0700593
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700594 printk(BIOS_INFO, "%s: %s %s\n", scope, dev->chip_ops ? dev->chip_ops->name : "",
595 dev_path(dev));
596}
597
Furquan Shaikhd4367502020-10-27 18:00:46 -0700598void wifi_pcie_fill_ssdt(const struct device *dev)
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700599{
600 const char *path;
601
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700602 path = acpi_device_path(dev);
603 if (!path)
604 return;
605
606 wifi_ssdt_write_device(dev, path);
Reka Norman93928192022-07-22 08:01:19 +1000607 wifi_ssdt_write_properties(dev, path);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700608}
609
Furquan Shaikhd4367502020-10-27 18:00:46 -0700610const char *wifi_pcie_acpi_name(const struct device *dev)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700611{
612 static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN];
613
614 /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */
615 snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X",
616 (dev_path_encode(dev) & 0xff));
617 return wifi_acpi_name;
618}
Furquan Shaikhd4367502020-10-27 18:00:46 -0700619
620void wifi_cnvi_fill_ssdt(const struct device *dev)
621{
622 const char *path;
Angel Pons1e124b92022-04-03 21:10:26 +0200623 if (!dev)
624 return;
Furquan Shaikhd4367502020-10-27 18:00:46 -0700625
Arthur Heymans7fcd4d52023-08-24 15:12:19 +0200626 path = acpi_device_path(dev->upstream->dev);
Furquan Shaikhd4367502020-10-27 18:00:46 -0700627 if (!path)
628 return;
629
630 wifi_ssdt_write_properties(dev, path);
631}