blob: 65940d6e9f374475702eb06a2d1bb765f0f53239 [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
Tim Wawrzynczak5e6fd362022-03-10 16:25:27 -070033/* ID for the Wifi DmaProperty _DSD */
34#define ACPI_DSD_DMA_PROPERTY_UUID "70D24161-6DD5-4C9E-8070-705531292865"
Tim Wawrzynczak3babc8e2022-01-25 14:05:20 -070035
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +053036/* Unique ID for CnviDdrRfim entry in WIFI _DSM */
37#define ACPI_DSM_RFIM_WIFI_UUID "7266172C-220B-4B29-814F-75E4DD26B5FD"
38
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +053039__weak int get_wifi_sar_limits(union wifi_sar_limits *sar_limits)
Furquan Shaikh2736c822020-10-27 19:46:11 -070040{
41 return -1;
42}
43
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +053044/*
45 * Generate ACPI AML code for _DSM method.
46 * This function takes as input uuid for the device, set of callbacks and
47 * argument to pass into the callbacks. Callbacks should ensure that Local0 and
48 * Local1 are left untouched. Use of Local2-Local7 is permitted in callbacks.
49 */
50void wifi_emit_dsm(struct dsm_profile *dsm);
51
52/*
53 * Function 1: Allow PC OEMs to set ETSI 5.8GHz SRD in Passive/Disabled ESTI SRD
54 * Channels: 149, 153, 157, 161, 165
55 * 0 - ETSI 5.8GHz SRD active scan
56 * 1 - ETSI 5.8GHz SRD passive scan
57 * 2 - ETSI 5.8GHz SRD disabled
58 */
59static void wifi_dsm_srd_active_channels(void *args)
60{
61 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
62
63 acpigen_write_return_integer(dsm_config->disable_active_sdr_channels);
64}
65
66/*
67 * Function 2 : Supported Indonesia 5.15-5.35 GHz Band
68 * 0 - Set 5.115-5.35GHz to Disable in Indonesia
69 * 1 - Set 5.115-5.35GHz to Enable (Passive) in Indonesia
70 * 2 - Reserved
71 */
72static void wifi_dsm_indonasia_5Ghz_band_enable(void *args)
73{
74 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
75
76 acpigen_write_return_integer(dsm_config->support_indonesia_5g_band);
77}
78
79/*
80 * Function 3: Support Wi-Fi 6 11ax Rev 2 new channels on 6-7 GHz.
81 * Bit 0:
82 * 0 - No override; use device settings 0
83 * 1 - Force disable all countries that are not defined in the following bits
84 *
85 * Bit 1:
86 * 0 No override; USA 6GHz disable 0
87 * 1 6GHz allowed in the USA (enabled only if the device is certified to the USA)
88 */
89static void wifi_dsm_supported_ultra_high_band(void *args)
90{
91 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
92
93 acpigen_write_return_integer(dsm_config->support_ultra_high_band);
94}
95
96/*
97 * Function 4: Regulatory Special Configurations Enablements
98 */
99static void wifi_dsm_regulatory_configurations(void *args)
100{
101 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
102
103 acpigen_write_return_integer(dsm_config->regulatory_configurations);
104}
105
106/*
107 * Function 5: M.2 UART Interface Configuration
108 */
109static void wifi_dsm_uart_configurations(void *args)
110{
111 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
112
113 acpigen_write_return_integer(dsm_config->uart_configurations);
114}
115
116/*
117 * Function 6: Control Enablement 11ax on certificated modules
118 * Bit 0 - Apply changes to country Ukraine. 11Ax Setting within module certification
119 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
120 * 1 - Apply changes.
121 *
122 * Bit 1 - 11Ax Mode. Effective only if Bit 0 set to 1
123 * 0 - Disable 11Ax on country Ukraine [Default]
124 * 1 - Enable 11Ax on country Ukraine
125 *
126 * Bit 2 - Apply changes to country Russia. 11Ax Setting within module certification
127 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
128 * 1 - Apply changes.
129 *
130 * Bit 3 - 11Ax Mode. Effective only if Bit 2 set to 1
131 * 0 - Disable 11Ax on country Russia [Default]
132 * 1 - Enable 11Ax on country Russia
133 *
134 * Bit 31:04 - Reserved
135 *
136 * Note: Assumed Russia Work with Wi-Fi FW/OTP definitions
137 */
138static void wifi_dsm_ukrane_russia_11ax_enable(void *args)
139{
140 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
141
142 acpigen_write_return_integer(dsm_config->enablement_11ax);
143}
144
145/*
146 * Function 7: Control Enablement UNII-4 over certificate modules
147 */
148static void wifi_dsm_unii4_control_enable(void *args)
149{
150 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
151
152 acpigen_write_return_integer(dsm_config->unii_4);
153}
154
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530155static void wifi_dsm_ddrrfim_func3_cb(void *ptr)
156{
157 const bool is_cnvi_ddr_rfim_enabled = *(bool *)ptr;
158 acpigen_write_return_integer(is_cnvi_ddr_rfim_enabled ? 1 : 0);
159}
160
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +0530161static void (*wifi_dsm_callbacks[])(void *) = {
162 NULL, /* Function 0 */
163 wifi_dsm_srd_active_channels, /* Function 1 */
164 wifi_dsm_indonasia_5Ghz_band_enable, /* Function 2 */
165 wifi_dsm_supported_ultra_high_band, /* Function 3 */
166 wifi_dsm_regulatory_configurations, /* Function 4 */
167 wifi_dsm_uart_configurations, /* Function 5 */
168 wifi_dsm_ukrane_russia_11ax_enable, /* Function 6 */
169 wifi_dsm_unii4_control_enable, /* Function 7 */
170};
171
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530172/*
173 * The current DSM2 table is only exporting one function (function 3), some more
174 * functions are reserved so marking them NULL.
175*/
176static void (*wifi_dsm2_callbacks[])(void *) = {
177 NULL, /* Function 0 */
178 NULL, /* Function 1 */
179 NULL, /* Function 2 */
180 wifi_dsm_ddrrfim_func3_cb, /* Function 3 */
181};
182
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +0530183void wifi_emit_dsm(struct dsm_profile *dsm)
184{
185 int i;
186 size_t count = ARRAY_SIZE(wifi_dsm_callbacks);
187
188 if (dsm == NULL)
189 return;
190
191 for (i = 1; i < count; i++)
192 if (!(dsm->supported_functions & (1 << i)))
193 wifi_dsm_callbacks[i] = NULL;
194
195 acpigen_write_dsm(ACPI_DSM_OEM_WIFI_UUID, wifi_dsm_callbacks, count, dsm);
196}
197
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530198static const uint8_t *sar_fetch_set(const struct sar_profile *sar, size_t set_num)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700199{
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530200 const uint8_t *sar_table = &sar->sar_table[0];
Furquan Shaikh2736c822020-10-27 19:46:11 -0700201
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530202 return sar_table + (sar->chains_count * sar->subbands_count * set_num);
203}
Furquan Shaikh2736c822020-10-27 19:46:11 -0700204
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530205static const uint8_t *wgds_fetch_set(struct geo_profile *wgds, size_t set_num)
206{
207 const uint8_t *wgds_table = &wgds->wgds_table[0];
208
209 return wgds_table + (wgds->bands_count * set_num);
210}
211
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530212static const uint8_t *ppag_fetch_set(struct gain_profile *ppag, size_t set_num)
213{
214 const uint8_t *ppag_table = &ppag->ppag_table[0];
215
216 return ppag_table + (ppag->bands_count * set_num);
217}
218
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530219static void sar_emit_wrds(const struct sar_profile *sar)
220{
221 int i;
222 size_t package_size, table_size;
223 const uint8_t *set;
224
225 if (sar == NULL)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700226 return;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700227
228 /*
229 * Name ("WRDS", Package () {
230 * Revision,
231 * Package () {
232 * Domain Type, // 0x7:WiFi
233 * WiFi SAR BIOS, // BIOS SAR Enable/disable
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530234 * SAR Table Set // Set#1 of SAR Table
Furquan Shaikh2736c822020-10-27 19:46:11 -0700235 * }
236 * })
237 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530238 if (sar->revision > MAX_SAR_REVISION) {
Julius Wernere9665952022-01-21 17:06:20 -0800239 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530240 return;
241 }
242
Furquan Shaikh2736c822020-10-27 19:46:11 -0700243 acpigen_write_name("WRDS");
244 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530245 acpigen_write_dword(sar->revision);
246
247 table_size = sar->chains_count * sar->subbands_count;
248 /* Emit 'Domain Type' + 'WiFi SAR Enable' + Set#1 */
249 package_size = 1 + 1 + table_size;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700250 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530251 acpigen_write_dword(DOMAIN_TYPE_WIFI);
252 acpigen_write_dword(1);
253
254 set = sar_fetch_set(sar, 0);
255 for (i = 0; i < table_size; i++)
256 acpigen_write_byte(set[i]);
257
258 acpigen_write_package_end();
259 acpigen_write_package_end();
260}
261
262static void sar_emit_ewrd(const struct sar_profile *sar)
263{
264 int i;
265 size_t package_size, set_num, table_size;
266 const uint8_t *set;
267
268 if (sar == NULL)
269 return;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700270
271 /*
272 * Name ("EWRD", Package () {
273 * Revision,
274 * Package () {
275 * Domain Type, // 0x7:WiFi
276 * Dynamic SAR Enable, // Dynamic SAR Enable/disable
277 * Extended SAR sets, // Number of optional SAR table sets
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530278 * SAR Table Set, // Set#2 of SAR Table
279 * SAR Table Set, // Set#3 of SAR Table
280 * SAR Table Set // Set#4 of SAR Table
Furquan Shaikh2736c822020-10-27 19:46:11 -0700281 * }
282 * })
283 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530284 if (sar->revision > MAX_SAR_REVISION) {
Julius Wernere9665952022-01-21 17:06:20 -0800285 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530286 return;
287 }
288
289 if (sar->dsar_set_count == 0) {
Julius Wernere9665952022-01-21 17:06:20 -0800290 printk(BIOS_WARNING, "DSAR set count is 0\n");
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530291 return;
292 }
293
Furquan Shaikh2736c822020-10-27 19:46:11 -0700294 acpigen_write_name("EWRD");
295 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530296 acpigen_write_dword(sar->revision);
297
298 table_size = sar->chains_count * sar->subbands_count;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700299 /*
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530300 * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Extended SAR sets count'
Furquan Shaikh2736c822020-10-27 19:46:11 -0700301 * + number of bytes for Set#2 & 3 & 4
302 */
Matt Chen07e6b5f2021-11-04 18:13:25 +0800303 package_size = 1 + 1 + 1 + table_size * MAX_DSAR_SET_COUNT;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700304 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530305 acpigen_write_dword(DOMAIN_TYPE_WIFI);
306 acpigen_write_dword(1);
307 acpigen_write_dword(sar->dsar_set_count);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700308
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530309 for (set_num = 1; set_num <= sar->dsar_set_count; set_num++) {
310 set = sar_fetch_set(sar, set_num);
311 for (i = 0; i < table_size; i++)
312 acpigen_write_byte(set[i]);
313 }
314
315 /* wifi driver always expects 3 DSAR sets */
316 for (i = 0; i < (table_size * (MAX_DSAR_SET_COUNT - sar->dsar_set_count)); i++)
317 acpigen_write_byte(0);
318
319 acpigen_write_package_end();
320 acpigen_write_package_end();
321}
322
323static void sar_emit_wgds(struct geo_profile *wgds)
324{
325 int i;
326 size_t package_size, set_num;
327 const uint8_t *set;
328
329 if (wgds == NULL)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700330 return;
331
332 /*
333 * Name ("WGDS", Package() {
334 * Revision,
335 * Package() {
336 * DomainType, // 0x7:WiFi
337 * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max
338 * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset
339 * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset
340 * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max
341 * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset
342 * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530343 * WgdsWiFiSarDeltaGroup1PowerMax3, // Group 1 FCC 6000-7000 Max
344 * WgdsWiFiSarDeltaGroup1PowerChainA3, // Group 1 FCC 6000-7000 A Offset
345 * WgdsWiFiSarDeltaGroup1PowerChainB3, // Group 1 FCC 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700346 * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max
347 * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset
348 * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset
349 * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max
350 * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset
351 * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530352 * WgdsWiFiSarDeltaGroup2PowerMax3, // Group 2 EC Jap 6000-7000 Max
353 * WgdsWiFiSarDeltaGroup2PowerChainA3, // Group 2 EC Jap 6000-7000 A Offset
354 * WgdsWiFiSarDeltaGroup2PowerChainB3, // Group 2 EC Jap 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700355 * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max
356 * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset
357 * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset
358 * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max
359 * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset
360 * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530361 * WgdsWiFiSarDeltaGroup3PowerMax3, // Group 3 ROW 6000-7000 Max
362 * WgdsWiFiSarDeltaGroup3PowerChainA3, // Group 3 ROW 6000-7000 A Offset
363 * WgdsWiFiSarDeltaGroup3PowerChainB3, // Group 3 ROW 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700364 * }
365 * })
366 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530367 if (wgds->revision > MAX_GEO_OFFSET_REVISION) {
Julius Wernere9665952022-01-21 17:06:20 -0800368 printk(BIOS_ERR, "Invalid WGDS revision: %d\n", wgds->revision);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530369 return;
370 }
Furquan Shaikh2736c822020-10-27 19:46:11 -0700371
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530372 package_size = 1 + wgds->chains_count * wgds->bands_count;
373
Furquan Shaikh2736c822020-10-27 19:46:11 -0700374 acpigen_write_name("WGDS");
375 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530376 acpigen_write_dword(wgds->revision);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700377 /* Emit 'Domain Type' +
378 * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS)
379 */
Furquan Shaikh2736c822020-10-27 19:46:11 -0700380 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530381 acpigen_write_dword(DOMAIN_TYPE_WIFI);
382
383 for (set_num = 0; set_num < wgds->chains_count; set_num++) {
384 set = wgds_fetch_set(wgds, set_num);
385 for (i = 0; i < wgds->bands_count; i++)
386 acpigen_write_byte(set[i]);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700387 }
388
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530389 acpigen_write_package_end();
390 acpigen_write_package_end();
391}
392
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530393static void sar_emit_ppag(struct gain_profile *ppag)
394{
395 int i;
396 size_t package_size, set_num;
397 const uint8_t *set;
398
399 if (ppag == NULL)
400 return;
401
402 /*
403 * Name ("PPAG", Package () {
404 * Revision,
405 * Package () {
406 * Domain Type, // 0x7:WiFi
407 * PPAG Mode, // Defines the mode of ANT_gain control to be used
408 * ANT_gain Table Chain A // Defines the ANT_gain in dBi for chain A
409 * ANT_gain Table Chain B // Defines the ANT_gain in dBi for chain B
410 * }
411 * })
412 */
413 if (ppag->revision > MAX_ANT_GAINS_REVISION) {
414 printk(BIOS_ERR, "Invalid PPAG revision: %d\n", ppag->revision);
415 return;
416 }
417
418 package_size = 1 + 1 + ppag->chains_count * ppag->bands_count;
419
420 acpigen_write_name("PPAG");
421 acpigen_write_package(2);
422 acpigen_write_dword(ppag->revision);
423 acpigen_write_package(package_size);
424 acpigen_write_dword(DOMAIN_TYPE_WIFI);
425 acpigen_write_dword(ppag->mode);
426
427 for (set_num = 0; set_num < ppag->chains_count; set_num++) {
428 set = ppag_fetch_set(ppag, set_num);
429 for (i = 0; i < ppag->bands_count; i++)
430 acpigen_write_byte(set[i]);
431 }
432
433 acpigen_write_package_end();
434 acpigen_write_package_end();
435}
436
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530437static void sar_emit_wtas(struct avg_profile *wtas)
438{
439 int i;
440 size_t package_size;
441
442 if (wtas == NULL)
443 return;
444
445 /*
446 * Name (WTAS, Package() {
447 * {
448 * Revision,
449 * Package()
450 * {
451 * DomainType, // 0x7:WiFi
452 * WifiTASSelection, // Enable/Disable the TAS feature
453 * WifiTASListEntries, // No. of blocked countries not approved by OEM to
454 * BlockedListEntry1, support this feature
455 * BlockedListEntry2,
456 * BlockedListEntry3,
457 * BlockedListEntry4,
458 * BlockedListEntry5,
459 * BlockedListEntry6,
460 * BlockedListEntry7,
461 * BlockedListEntry8,
462 * BlockedListEntry9,
463 * BlockedListEntry10,
464 * BlockedListEntry11,
465 * BlockedListEntry12,
466 * BlockedListEntry13,
467 * BlockedListEntry14,
468 * BlockedListEntry15,
469 * BlockedListEntry16,
470 * }
471 * })
472 */
473 package_size = 1 + 1 + 1 + MAX_DENYLIST_ENTRY;
474
475 acpigen_write_name("WTAS");
476 acpigen_write_package(2);
477 acpigen_write_dword(wtas->revision);
478 acpigen_write_package(package_size);
479 acpigen_write_dword(DOMAIN_TYPE_WIFI);
Sugnan Prabhu S627c8442021-09-06 15:05:56 +0530480 acpigen_write_byte(wtas->tas_selection);
481 acpigen_write_byte(wtas->tas_list_size);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530482 for (i = 0; i < MAX_DENYLIST_ENTRY; i++)
Sugnan Prabhu S627c8442021-09-06 15:05:56 +0530483 acpigen_write_word(wtas->deny_list_entry[i]);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530484
485 acpigen_write_package_end();
486 acpigen_write_package_end();
487}
488
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530489static void emit_sar_acpi_structures(const struct device *dev, struct dsm_profile *dsm)
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530490{
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530491 union wifi_sar_limits sar_limits = {{NULL, NULL, NULL, NULL, NULL} };
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530492
493 /*
494 * If device type is PCI, ensure that the device has Intel vendor ID. CBFS SAR and SAR
495 * ACPI tables are currently used only by Intel WiFi devices.
496 */
Felix Singer43b7f412022-03-07 04:34:52 +0100497 if (dev->path.type == DEVICE_PATH_PCI && dev->vendor != PCI_VID_INTEL)
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530498 return;
499
500 /* Retrieve the sar limits data */
501 if (get_wifi_sar_limits(&sar_limits) < 0) {
Julius Wernere9665952022-01-21 17:06:20 -0800502 printk(BIOS_ERR, "failed getting SAR limits!\n");
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530503 return;
504 }
505
506 sar_emit_wrds(sar_limits.sar);
507 sar_emit_ewrd(sar_limits.sar);
508 sar_emit_wgds(sar_limits.wgds);
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530509 sar_emit_ppag(sar_limits.ppag);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530510 sar_emit_wtas(sar_limits.wtas);
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530511
512 /* copy the dsm data to be later used for creating _DSM function */
513 if (sar_limits.dsm != NULL)
514 memcpy(dsm, &sar_limits.dsm, sizeof(struct dsm_profile));
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530515
516 free(sar_limits.sar);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700517}
518
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700519static void wifi_ssdt_write_device(const struct device *dev, const char *path)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700520{
Furquan Shaikh2736c822020-10-27 19:46:11 -0700521 /* Device */
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700522 acpigen_write_device(path);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700523 acpi_device_write_uid(dev);
524
525 if (dev->chip_ops)
526 acpigen_write_name_string("_DDN", dev->chip_ops->name);
527
528 /* Address */
529 acpigen_write_ADR_pci_device(dev);
530
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700531 acpigen_pop_len(); /* Device */
532}
533
534static void wifi_ssdt_write_properties(const struct device *dev, const char *scope)
535{
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530536 bool is_cnvi_ddr_rfim_enabled = false;
537
538 const struct drivers_wifi_generic_config *config = dev->chip_info;
539 if (dev && config)
540 is_cnvi_ddr_rfim_enabled = config->enable_cnvi_ddr_rfim;
541
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700542 /* Scope */
543 acpigen_write_scope(scope);
544
Tim Wawrzynczak5e6fd362022-03-10 16:25:27 -0700545 if (dev->path.type == DEVICE_PATH_GENERIC) {
Tim Wawrzynczak5e6fd362022-03-10 16:25:27 -0700546 if (config) {
547 /* Wake capabilities */
548 acpigen_write_PRW(config->wake, ACPI_S3);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700549
Tim Wawrzynczak5e6fd362022-03-10 16:25:27 -0700550 /* Add _DSD for DmaProperty property. */
551 if (config->is_untrusted) {
552 struct acpi_dp *dsd, *pkg;
Tim Wawrzynczak3babc8e2022-01-25 14:05:20 -0700553
Tim Wawrzynczak5e6fd362022-03-10 16:25:27 -0700554 dsd = acpi_dp_new_table("_DSD");
555 pkg = acpi_dp_new_table(ACPI_DSD_DMA_PROPERTY_UUID);
556 acpi_dp_add_integer(pkg, "DmaProperty", 1);
557 acpi_dp_add_package(dsd, pkg);
558 acpi_dp_write(dsd);
559 }
Tim Wawrzynczak3babc8e2022-01-25 14:05:20 -0700560 }
561 }
562
Furquan Shaikh2736c822020-10-27 19:46:11 -0700563 /* Fill regulatory domain structure */
564 if (CONFIG(HAVE_REGULATORY_DOMAIN)) {
565 /*
566 * Name ("WRDD", Package () {
567 * WRDD_REVISION, // Revision
568 * Package () {
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530569 * DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
Furquan Shaikh2736c822020-10-27 19:46:11 -0700570 * wifi_regulatory_domain() // Country Identifier
571 * }
572 * })
573 */
574 acpigen_write_name("WRDD");
575 acpigen_write_package(2);
576 acpigen_write_integer(WRDD_REVISION);
577 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530578 acpigen_write_dword(DOMAIN_TYPE_WIFI);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700579 acpigen_write_dword(wifi_regulatory_domain());
580 acpigen_pop_len();
581 acpigen_pop_len();
582 }
583
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530584 struct dsm_uuid dsm_ids[MAX_DSM_FUNCS];
585 /* We will need a copy dsm data to be used later for creating _DSM function */
586 struct dsm_profile dsm = {0};
587 uint8_t dsm_count = 0;
588
Furquan Shaikh2736c822020-10-27 19:46:11 -0700589 /* Fill Wifi sar related ACPI structures */
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530590 if (CONFIG(USE_SAR)) {
591 emit_sar_acpi_structures(dev, &dsm);
592
593 if (dsm.supported_functions != 0) {
594 for (int i = 1; i < ARRAY_SIZE(wifi_dsm_callbacks); i++)
595 if (!(dsm.supported_functions & (1 << i)))
596 wifi_dsm_callbacks[i] = NULL;
597
598 dsm_ids[dsm_count].uuid = ACPI_DSM_OEM_WIFI_UUID;
599 dsm_ids[dsm_count].callbacks = &wifi_dsm_callbacks[0];
600 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm_callbacks);
601 dsm_ids[dsm_count].arg = NULL;
602 dsm_count++;
603 }
604 }
605
606 if (is_cnvi_ddr_rfim_enabled) {
607 dsm_ids[dsm_count].uuid = ACPI_DSM_RFIM_WIFI_UUID;
608 dsm_ids[dsm_count].callbacks = &wifi_dsm2_callbacks[0];
609 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm2_callbacks);
610 dsm_ids[dsm_count].arg = &is_cnvi_ddr_rfim_enabled;
611 dsm_count++;
612 }
613
614 acpigen_write_dsm_uuid_arr(dsm_ids, dsm_count);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700615
Furquan Shaikh2736c822020-10-27 19:46:11 -0700616 acpigen_pop_len(); /* Scope */
617
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700618 printk(BIOS_INFO, "%s: %s %s\n", scope, dev->chip_ops ? dev->chip_ops->name : "",
619 dev_path(dev));
620}
621
Furquan Shaikhd4367502020-10-27 18:00:46 -0700622void wifi_pcie_fill_ssdt(const struct device *dev)
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700623{
624 const char *path;
625
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700626 path = acpi_device_path(dev);
627 if (!path)
628 return;
629
630 wifi_ssdt_write_device(dev, path);
Tim Wawrzynczak5e6fd362022-03-10 16:25:27 -0700631 const struct device *child = dev->link_list->children;
632 if (child && child->path.type == DEVICE_PATH_GENERIC)
633 wifi_ssdt_write_properties(child, path);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700634}
635
Furquan Shaikhd4367502020-10-27 18:00:46 -0700636const char *wifi_pcie_acpi_name(const struct device *dev)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700637{
638 static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN];
639
640 /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */
641 snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X",
642 (dev_path_encode(dev) & 0xff));
643 return wifi_acpi_name;
644}
Furquan Shaikhd4367502020-10-27 18:00:46 -0700645
646void wifi_cnvi_fill_ssdt(const struct device *dev)
647{
648 const char *path;
649
Furquan Shaikhd4367502020-10-27 18:00:46 -0700650 path = acpi_device_path(dev->bus->dev);
651 if (!path)
652 return;
653
654 wifi_ssdt_write_properties(dev, path);
655}