blob: ee122ea2d8ceffe9c6803c87007da72355ce5c9e [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/*
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +053045 * Function 1: Allow PC OEMs to set ETSI 5.8GHz SRD in Passive/Disabled ESTI SRD
46 * Channels: 149, 153, 157, 161, 165
47 * 0 - ETSI 5.8GHz SRD active scan
48 * 1 - ETSI 5.8GHz SRD passive scan
49 * 2 - ETSI 5.8GHz SRD disabled
50 */
51static void wifi_dsm_srd_active_channels(void *args)
52{
53 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
54
55 acpigen_write_return_integer(dsm_config->disable_active_sdr_channels);
56}
57
58/*
59 * Function 2 : Supported Indonesia 5.15-5.35 GHz Band
60 * 0 - Set 5.115-5.35GHz to Disable in Indonesia
61 * 1 - Set 5.115-5.35GHz to Enable (Passive) in Indonesia
62 * 2 - Reserved
63 */
64static void wifi_dsm_indonasia_5Ghz_band_enable(void *args)
65{
66 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
67
68 acpigen_write_return_integer(dsm_config->support_indonesia_5g_band);
69}
70
71/*
72 * Function 3: Support Wi-Fi 6 11ax Rev 2 new channels on 6-7 GHz.
73 * Bit 0:
74 * 0 - No override; use device settings 0
75 * 1 - Force disable all countries that are not defined in the following bits
76 *
77 * Bit 1:
78 * 0 No override; USA 6GHz disable 0
79 * 1 6GHz allowed in the USA (enabled only if the device is certified to the USA)
80 */
81static void wifi_dsm_supported_ultra_high_band(void *args)
82{
83 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
84
85 acpigen_write_return_integer(dsm_config->support_ultra_high_band);
86}
87
88/*
89 * Function 4: Regulatory Special Configurations Enablements
90 */
91static void wifi_dsm_regulatory_configurations(void *args)
92{
93 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
94
95 acpigen_write_return_integer(dsm_config->regulatory_configurations);
96}
97
98/*
99 * Function 5: M.2 UART Interface Configuration
100 */
101static void wifi_dsm_uart_configurations(void *args)
102{
103 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
104
105 acpigen_write_return_integer(dsm_config->uart_configurations);
106}
107
108/*
109 * Function 6: Control Enablement 11ax on certificated modules
110 * Bit 0 - Apply changes to country Ukraine. 11Ax Setting within module certification
111 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
112 * 1 - Apply changes.
113 *
114 * Bit 1 - 11Ax Mode. Effective only if Bit 0 set to 1
115 * 0 - Disable 11Ax on country Ukraine [Default]
116 * 1 - Enable 11Ax on country Ukraine
117 *
118 * Bit 2 - Apply changes to country Russia. 11Ax Setting within module certification
119 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
120 * 1 - Apply changes.
121 *
122 * Bit 3 - 11Ax Mode. Effective only if Bit 2 set to 1
123 * 0 - Disable 11Ax on country Russia [Default]
124 * 1 - Enable 11Ax on country Russia
125 *
126 * Bit 31:04 - Reserved
127 *
128 * Note: Assumed Russia Work with Wi-Fi FW/OTP definitions
129 */
130static void wifi_dsm_ukrane_russia_11ax_enable(void *args)
131{
132 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
133
134 acpigen_write_return_integer(dsm_config->enablement_11ax);
135}
136
137/*
138 * Function 7: Control Enablement UNII-4 over certificate modules
139 */
140static void wifi_dsm_unii4_control_enable(void *args)
141{
142 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
143
144 acpigen_write_return_integer(dsm_config->unii_4);
145}
146
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530147static void wifi_dsm_ddrrfim_func3_cb(void *ptr)
148{
149 const bool is_cnvi_ddr_rfim_enabled = *(bool *)ptr;
150 acpigen_write_return_integer(is_cnvi_ddr_rfim_enabled ? 1 : 0);
151}
152
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +0530153static void (*wifi_dsm_callbacks[])(void *) = {
154 NULL, /* Function 0 */
155 wifi_dsm_srd_active_channels, /* Function 1 */
156 wifi_dsm_indonasia_5Ghz_band_enable, /* Function 2 */
157 wifi_dsm_supported_ultra_high_band, /* Function 3 */
158 wifi_dsm_regulatory_configurations, /* Function 4 */
159 wifi_dsm_uart_configurations, /* Function 5 */
160 wifi_dsm_ukrane_russia_11ax_enable, /* Function 6 */
161 wifi_dsm_unii4_control_enable, /* Function 7 */
162};
163
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530164/*
165 * The current DSM2 table is only exporting one function (function 3), some more
166 * functions are reserved so marking them NULL.
167*/
168static void (*wifi_dsm2_callbacks[])(void *) = {
169 NULL, /* Function 0 */
170 NULL, /* Function 1 */
171 NULL, /* Function 2 */
172 wifi_dsm_ddrrfim_func3_cb, /* Function 3 */
173};
174
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530175static const uint8_t *sar_fetch_set(const struct sar_profile *sar, size_t set_num)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700176{
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530177 const uint8_t *sar_table = &sar->sar_table[0];
Furquan Shaikh2736c822020-10-27 19:46:11 -0700178
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530179 return sar_table + (sar->chains_count * sar->subbands_count * set_num);
180}
Furquan Shaikh2736c822020-10-27 19:46:11 -0700181
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530182static const uint8_t *wgds_fetch_set(struct geo_profile *wgds, size_t set_num)
183{
184 const uint8_t *wgds_table = &wgds->wgds_table[0];
185
186 return wgds_table + (wgds->bands_count * set_num);
187}
188
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530189static const uint8_t *ppag_fetch_set(struct gain_profile *ppag, size_t set_num)
190{
191 const uint8_t *ppag_table = &ppag->ppag_table[0];
192
193 return ppag_table + (ppag->bands_count * set_num);
194}
195
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530196static void sar_emit_wrds(const struct sar_profile *sar)
197{
198 int i;
199 size_t package_size, table_size;
200 const uint8_t *set;
201
202 if (sar == NULL)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700203 return;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700204
205 /*
206 * Name ("WRDS", Package () {
207 * Revision,
208 * Package () {
209 * Domain Type, // 0x7:WiFi
210 * WiFi SAR BIOS, // BIOS SAR Enable/disable
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530211 * SAR Table Set // Set#1 of SAR Table
Furquan Shaikh2736c822020-10-27 19:46:11 -0700212 * }
213 * })
214 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530215 if (sar->revision > MAX_SAR_REVISION) {
Julius Wernere9665952022-01-21 17:06:20 -0800216 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530217 return;
218 }
219
Furquan Shaikh2736c822020-10-27 19:46:11 -0700220 acpigen_write_name("WRDS");
221 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530222 acpigen_write_dword(sar->revision);
223
224 table_size = sar->chains_count * sar->subbands_count;
225 /* Emit 'Domain Type' + 'WiFi SAR Enable' + Set#1 */
226 package_size = 1 + 1 + table_size;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700227 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530228 acpigen_write_dword(DOMAIN_TYPE_WIFI);
229 acpigen_write_dword(1);
230
231 set = sar_fetch_set(sar, 0);
232 for (i = 0; i < table_size; i++)
233 acpigen_write_byte(set[i]);
234
235 acpigen_write_package_end();
236 acpigen_write_package_end();
237}
238
239static void sar_emit_ewrd(const struct sar_profile *sar)
240{
241 int i;
242 size_t package_size, set_num, table_size;
243 const uint8_t *set;
244
245 if (sar == NULL)
246 return;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700247
248 /*
249 * Name ("EWRD", Package () {
250 * Revision,
251 * Package () {
252 * Domain Type, // 0x7:WiFi
253 * Dynamic SAR Enable, // Dynamic SAR Enable/disable
254 * Extended SAR sets, // Number of optional SAR table sets
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530255 * SAR Table Set, // Set#2 of SAR Table
256 * SAR Table Set, // Set#3 of SAR Table
257 * SAR Table Set // Set#4 of SAR Table
Furquan Shaikh2736c822020-10-27 19:46:11 -0700258 * }
259 * })
260 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530261 if (sar->revision > MAX_SAR_REVISION) {
Julius Wernere9665952022-01-21 17:06:20 -0800262 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530263 return;
264 }
265
266 if (sar->dsar_set_count == 0) {
Julius Wernere9665952022-01-21 17:06:20 -0800267 printk(BIOS_WARNING, "DSAR set count is 0\n");
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530268 return;
269 }
270
Furquan Shaikh2736c822020-10-27 19:46:11 -0700271 acpigen_write_name("EWRD");
272 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530273 acpigen_write_dword(sar->revision);
274
275 table_size = sar->chains_count * sar->subbands_count;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700276 /*
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530277 * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Extended SAR sets count'
Furquan Shaikh2736c822020-10-27 19:46:11 -0700278 * + number of bytes for Set#2 & 3 & 4
279 */
Matt Chen07e6b5f2021-11-04 18:13:25 +0800280 package_size = 1 + 1 + 1 + table_size * MAX_DSAR_SET_COUNT;
Furquan Shaikh2736c822020-10-27 19:46:11 -0700281 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530282 acpigen_write_dword(DOMAIN_TYPE_WIFI);
283 acpigen_write_dword(1);
284 acpigen_write_dword(sar->dsar_set_count);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700285
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530286 for (set_num = 1; set_num <= sar->dsar_set_count; set_num++) {
287 set = sar_fetch_set(sar, set_num);
288 for (i = 0; i < table_size; i++)
289 acpigen_write_byte(set[i]);
290 }
291
292 /* wifi driver always expects 3 DSAR sets */
293 for (i = 0; i < (table_size * (MAX_DSAR_SET_COUNT - sar->dsar_set_count)); i++)
294 acpigen_write_byte(0);
295
296 acpigen_write_package_end();
297 acpigen_write_package_end();
298}
299
300static void sar_emit_wgds(struct geo_profile *wgds)
301{
302 int i;
303 size_t package_size, set_num;
304 const uint8_t *set;
305
306 if (wgds == NULL)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700307 return;
308
309 /*
310 * Name ("WGDS", Package() {
311 * Revision,
312 * Package() {
313 * DomainType, // 0x7:WiFi
314 * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max
315 * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset
316 * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset
317 * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max
318 * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset
319 * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530320 * WgdsWiFiSarDeltaGroup1PowerMax3, // Group 1 FCC 6000-7000 Max
321 * WgdsWiFiSarDeltaGroup1PowerChainA3, // Group 1 FCC 6000-7000 A Offset
322 * WgdsWiFiSarDeltaGroup1PowerChainB3, // Group 1 FCC 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700323 * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max
324 * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset
325 * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset
326 * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max
327 * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset
328 * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530329 * WgdsWiFiSarDeltaGroup2PowerMax3, // Group 2 EC Jap 6000-7000 Max
330 * WgdsWiFiSarDeltaGroup2PowerChainA3, // Group 2 EC Jap 6000-7000 A Offset
331 * WgdsWiFiSarDeltaGroup2PowerChainB3, // Group 2 EC Jap 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700332 * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max
333 * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset
334 * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset
335 * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max
336 * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset
337 * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530338 * WgdsWiFiSarDeltaGroup3PowerMax3, // Group 3 ROW 6000-7000 Max
339 * WgdsWiFiSarDeltaGroup3PowerChainA3, // Group 3 ROW 6000-7000 A Offset
340 * WgdsWiFiSarDeltaGroup3PowerChainB3, // Group 3 ROW 6000-7000 B Offset
Furquan Shaikh2736c822020-10-27 19:46:11 -0700341 * }
342 * })
343 */
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530344 if (wgds->revision > MAX_GEO_OFFSET_REVISION) {
Julius Wernere9665952022-01-21 17:06:20 -0800345 printk(BIOS_ERR, "Invalid WGDS revision: %d\n", wgds->revision);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530346 return;
347 }
Furquan Shaikh2736c822020-10-27 19:46:11 -0700348
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530349 package_size = 1 + wgds->chains_count * wgds->bands_count;
350
Furquan Shaikh2736c822020-10-27 19:46:11 -0700351 acpigen_write_name("WGDS");
352 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530353 acpigen_write_dword(wgds->revision);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700354 /* Emit 'Domain Type' +
355 * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS)
356 */
Furquan Shaikh2736c822020-10-27 19:46:11 -0700357 acpigen_write_package(package_size);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530358 acpigen_write_dword(DOMAIN_TYPE_WIFI);
359
360 for (set_num = 0; set_num < wgds->chains_count; set_num++) {
361 set = wgds_fetch_set(wgds, set_num);
362 for (i = 0; i < wgds->bands_count; i++)
363 acpigen_write_byte(set[i]);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700364 }
365
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530366 acpigen_write_package_end();
367 acpigen_write_package_end();
368}
369
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530370static void sar_emit_ppag(struct gain_profile *ppag)
371{
372 int i;
373 size_t package_size, set_num;
374 const uint8_t *set;
375
376 if (ppag == NULL)
377 return;
378
379 /*
380 * Name ("PPAG", Package () {
381 * Revision,
382 * Package () {
383 * Domain Type, // 0x7:WiFi
384 * PPAG Mode, // Defines the mode of ANT_gain control to be used
385 * ANT_gain Table Chain A // Defines the ANT_gain in dBi for chain A
386 * ANT_gain Table Chain B // Defines the ANT_gain in dBi for chain B
387 * }
388 * })
389 */
390 if (ppag->revision > MAX_ANT_GAINS_REVISION) {
391 printk(BIOS_ERR, "Invalid PPAG revision: %d\n", ppag->revision);
392 return;
393 }
394
395 package_size = 1 + 1 + ppag->chains_count * ppag->bands_count;
396
397 acpigen_write_name("PPAG");
398 acpigen_write_package(2);
399 acpigen_write_dword(ppag->revision);
400 acpigen_write_package(package_size);
401 acpigen_write_dword(DOMAIN_TYPE_WIFI);
402 acpigen_write_dword(ppag->mode);
403
404 for (set_num = 0; set_num < ppag->chains_count; set_num++) {
405 set = ppag_fetch_set(ppag, set_num);
406 for (i = 0; i < ppag->bands_count; i++)
407 acpigen_write_byte(set[i]);
408 }
409
410 acpigen_write_package_end();
411 acpigen_write_package_end();
412}
413
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530414static void sar_emit_wtas(struct avg_profile *wtas)
415{
416 int i;
417 size_t package_size;
418
419 if (wtas == NULL)
420 return;
421
422 /*
423 * Name (WTAS, Package() {
424 * {
425 * Revision,
426 * Package()
427 * {
428 * DomainType, // 0x7:WiFi
429 * WifiTASSelection, // Enable/Disable the TAS feature
430 * WifiTASListEntries, // No. of blocked countries not approved by OEM to
431 * BlockedListEntry1, support this feature
432 * BlockedListEntry2,
433 * BlockedListEntry3,
434 * BlockedListEntry4,
435 * BlockedListEntry5,
436 * BlockedListEntry6,
437 * BlockedListEntry7,
438 * BlockedListEntry8,
439 * BlockedListEntry9,
440 * BlockedListEntry10,
441 * BlockedListEntry11,
442 * BlockedListEntry12,
443 * BlockedListEntry13,
444 * BlockedListEntry14,
445 * BlockedListEntry15,
446 * BlockedListEntry16,
447 * }
448 * })
449 */
450 package_size = 1 + 1 + 1 + MAX_DENYLIST_ENTRY;
451
452 acpigen_write_name("WTAS");
453 acpigen_write_package(2);
454 acpigen_write_dword(wtas->revision);
455 acpigen_write_package(package_size);
456 acpigen_write_dword(DOMAIN_TYPE_WIFI);
Sugnan Prabhu S627c8442021-09-06 15:05:56 +0530457 acpigen_write_byte(wtas->tas_selection);
458 acpigen_write_byte(wtas->tas_list_size);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530459 for (i = 0; i < MAX_DENYLIST_ENTRY; i++)
Sugnan Prabhu S627c8442021-09-06 15:05:56 +0530460 acpigen_write_word(wtas->deny_list_entry[i]);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530461
462 acpigen_write_package_end();
463 acpigen_write_package_end();
464}
465
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530466static void emit_sar_acpi_structures(const struct device *dev, struct dsm_profile *dsm)
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530467{
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530468 union wifi_sar_limits sar_limits = {{NULL, NULL, NULL, NULL, NULL} };
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530469
470 /*
471 * If device type is PCI, ensure that the device has Intel vendor ID. CBFS SAR and SAR
472 * ACPI tables are currently used only by Intel WiFi devices.
473 */
Felix Singer43b7f412022-03-07 04:34:52 +0100474 if (dev->path.type == DEVICE_PATH_PCI && dev->vendor != PCI_VID_INTEL)
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530475 return;
476
477 /* Retrieve the sar limits data */
478 if (get_wifi_sar_limits(&sar_limits) < 0) {
Julius Wernere9665952022-01-21 17:06:20 -0800479 printk(BIOS_ERR, "failed getting SAR limits!\n");
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530480 return;
481 }
482
483 sar_emit_wrds(sar_limits.sar);
484 sar_emit_ewrd(sar_limits.sar);
485 sar_emit_wgds(sar_limits.wgds);
Sugnan Prabhu Sd1fc8322021-08-31 07:11:35 +0530486 sar_emit_ppag(sar_limits.ppag);
Sugnan Prabhu Scc507702021-08-31 07:19:30 +0530487 sar_emit_wtas(sar_limits.wtas);
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530488
489 /* copy the dsm data to be later used for creating _DSM function */
490 if (sar_limits.dsm != NULL)
491 memcpy(dsm, &sar_limits.dsm, sizeof(struct dsm_profile));
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530492
493 free(sar_limits.sar);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700494}
495
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700496static void wifi_ssdt_write_device(const struct device *dev, const char *path)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700497{
Furquan Shaikh2736c822020-10-27 19:46:11 -0700498 /* Device */
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700499 acpigen_write_device(path);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700500 acpi_device_write_uid(dev);
501
502 if (dev->chip_ops)
503 acpigen_write_name_string("_DDN", dev->chip_ops->name);
504
505 /* Address */
506 acpigen_write_ADR_pci_device(dev);
507
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700508 acpigen_pop_len(); /* Device */
509}
510
511static void wifi_ssdt_write_properties(const struct device *dev, const char *scope)
512{
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530513 const struct drivers_wifi_generic_config *config = dev->chip_info;
Angel Pons1e124b92022-04-03 21:10:26 +0200514
515 bool is_cnvi_ddr_rfim_enabled = config && config->enable_cnvi_ddr_rfim;
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530516
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700517 /* Scope */
518 acpigen_write_scope(scope);
519
Reka Norman93928192022-07-22 08:01:19 +1000520 if (config) {
521 /* Wake capabilities */
522 acpigen_write_PRW(config->wake, ACPI_S3);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700523
Reka Norman93928192022-07-22 08:01:19 +1000524 /* Add _DSD for DmaProperty property. */
525 if (config->is_untrusted) {
526 struct acpi_dp *dsd, *pkg;
Tim Wawrzynczak3babc8e2022-01-25 14:05:20 -0700527
Reka Norman93928192022-07-22 08:01:19 +1000528 dsd = acpi_dp_new_table("_DSD");
529 pkg = acpi_dp_new_table(ACPI_DSD_DMA_PROPERTY_UUID);
530 acpi_dp_add_integer(pkg, "DmaProperty", 1);
531 acpi_dp_add_package(dsd, pkg);
532 acpi_dp_write(dsd);
Tim Wawrzynczak3babc8e2022-01-25 14:05:20 -0700533 }
534 }
535
Furquan Shaikh2736c822020-10-27 19:46:11 -0700536 /* Fill regulatory domain structure */
537 if (CONFIG(HAVE_REGULATORY_DOMAIN)) {
538 /*
539 * Name ("WRDD", Package () {
540 * WRDD_REVISION, // Revision
541 * Package () {
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530542 * DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
Furquan Shaikh2736c822020-10-27 19:46:11 -0700543 * wifi_regulatory_domain() // Country Identifier
544 * }
545 * })
546 */
547 acpigen_write_name("WRDD");
548 acpigen_write_package(2);
549 acpigen_write_integer(WRDD_REVISION);
550 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530551 acpigen_write_dword(DOMAIN_TYPE_WIFI);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700552 acpigen_write_dword(wifi_regulatory_domain());
553 acpigen_pop_len();
554 acpigen_pop_len();
555 }
556
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530557 struct dsm_uuid dsm_ids[MAX_DSM_FUNCS];
558 /* We will need a copy dsm data to be used later for creating _DSM function */
559 struct dsm_profile dsm = {0};
560 uint8_t dsm_count = 0;
561
Furquan Shaikh2736c822020-10-27 19:46:11 -0700562 /* Fill Wifi sar related ACPI structures */
Varshit B Pandyab6ebcdf2022-02-03 18:35:18 +0530563 if (CONFIG(USE_SAR)) {
564 emit_sar_acpi_structures(dev, &dsm);
565
566 if (dsm.supported_functions != 0) {
567 for (int i = 1; i < ARRAY_SIZE(wifi_dsm_callbacks); i++)
568 if (!(dsm.supported_functions & (1 << i)))
569 wifi_dsm_callbacks[i] = NULL;
570
571 dsm_ids[dsm_count].uuid = ACPI_DSM_OEM_WIFI_UUID;
572 dsm_ids[dsm_count].callbacks = &wifi_dsm_callbacks[0];
573 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm_callbacks);
574 dsm_ids[dsm_count].arg = NULL;
575 dsm_count++;
576 }
577 }
578
579 if (is_cnvi_ddr_rfim_enabled) {
580 dsm_ids[dsm_count].uuid = ACPI_DSM_RFIM_WIFI_UUID;
581 dsm_ids[dsm_count].callbacks = &wifi_dsm2_callbacks[0];
582 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm2_callbacks);
583 dsm_ids[dsm_count].arg = &is_cnvi_ddr_rfim_enabled;
584 dsm_count++;
585 }
586
587 acpigen_write_dsm_uuid_arr(dsm_ids, dsm_count);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700588
Furquan Shaikh2736c822020-10-27 19:46:11 -0700589 acpigen_pop_len(); /* Scope */
590
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700591 printk(BIOS_INFO, "%s: %s %s\n", scope, dev->chip_ops ? dev->chip_ops->name : "",
592 dev_path(dev));
593}
594
Furquan Shaikhd4367502020-10-27 18:00:46 -0700595void wifi_pcie_fill_ssdt(const struct device *dev)
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700596{
597 const char *path;
598
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700599 path = acpi_device_path(dev);
600 if (!path)
601 return;
602
603 wifi_ssdt_write_device(dev, path);
Reka Norman93928192022-07-22 08:01:19 +1000604 wifi_ssdt_write_properties(dev, path);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700605}
606
Furquan Shaikhd4367502020-10-27 18:00:46 -0700607const char *wifi_pcie_acpi_name(const struct device *dev)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700608{
609 static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN];
610
611 /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */
612 snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X",
613 (dev_path_encode(dev) & 0xff));
614 return wifi_acpi_name;
615}
Furquan Shaikhd4367502020-10-27 18:00:46 -0700616
617void wifi_cnvi_fill_ssdt(const struct device *dev)
618{
619 const char *path;
Angel Pons1e124b92022-04-03 21:10:26 +0200620 if (!dev)
621 return;
Furquan Shaikhd4367502020-10-27 18:00:46 -0700622
Furquan Shaikhd4367502020-10-27 18:00:46 -0700623 path = acpi_device_path(dev->bus->dev);
624 if (!path)
625 return;
626
627 wifi_ssdt_write_properties(dev, path);
628}