blob: 63faae01767a1582bba9eb555ea2e842ba8ae284 [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"
13#include "wifi_private.h"
14
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +053015/* WIFI Domain type */
16#define DOMAIN_TYPE_WIFI 0x7
Furquan Shaikh2736c822020-10-27 19:46:11 -070017
18/*
19 * WIFI ACPI NAME = "WF" + hex value of last 8 bits of dev_path_encode + '\0'
20 * The above representation returns unique and consistent name every time
21 * generate_wifi_acpi_name is invoked. The last 8 bits of dev_path_encode is
22 * chosen since it contains the bus address of the device.
23 */
24#define WIFI_ACPI_NAME_MAX_LEN 5
25
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +053026/* Unique ID for the WIFI _DSM */
27#define ACPI_DSM_OEM_WIFI_UUID "F21202BF-8F78-4DC6-A5B3-1F738E285ADE"
28
Tim Wawrzynczak3babc8e2022-01-25 14:05:20 -070029/* Unique ID for the Wifi _DSD */
30#define ACPI_DSD_UNTRUSTED_UUID "88566a92-1a61-466d-949a-6d12809d480c"
31
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +053032__weak int get_wifi_sar_limits(union wifi_sar_limits *sar_limits)
Furquan Shaikh2736c822020-10-27 19:46:11 -070033{
34 return -1;
35}
36
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +053037/*
38 * Generate ACPI AML code for _DSM method.
39 * This function takes as input uuid for the device, set of callbacks and
40 * argument to pass into the callbacks. Callbacks should ensure that Local0 and
41 * Local1 are left untouched. Use of Local2-Local7 is permitted in callbacks.
42 */
43void wifi_emit_dsm(struct dsm_profile *dsm);
44
45/*
46 * Function 1: Allow PC OEMs to set ETSI 5.8GHz SRD in Passive/Disabled ESTI SRD
47 * Channels: 149, 153, 157, 161, 165
48 * 0 - ETSI 5.8GHz SRD active scan
49 * 1 - ETSI 5.8GHz SRD passive scan
50 * 2 - ETSI 5.8GHz SRD disabled
51 */
52static void wifi_dsm_srd_active_channels(void *args)
53{
54 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
55
56 acpigen_write_return_integer(dsm_config->disable_active_sdr_channels);
57}
58
59/*
60 * Function 2 : Supported Indonesia 5.15-5.35 GHz Band
61 * 0 - Set 5.115-5.35GHz to Disable in Indonesia
62 * 1 - Set 5.115-5.35GHz to Enable (Passive) in Indonesia
63 * 2 - Reserved
64 */
65static void wifi_dsm_indonasia_5Ghz_band_enable(void *args)
66{
67 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
68
69 acpigen_write_return_integer(dsm_config->support_indonesia_5g_band);
70}
71
72/*
73 * Function 3: Support Wi-Fi 6 11ax Rev 2 new channels on 6-7 GHz.
74 * Bit 0:
75 * 0 - No override; use device settings 0
76 * 1 - Force disable all countries that are not defined in the following bits
77 *
78 * Bit 1:
79 * 0 No override; USA 6GHz disable 0
80 * 1 6GHz allowed in the USA (enabled only if the device is certified to the USA)
81 */
82static void wifi_dsm_supported_ultra_high_band(void *args)
83{
84 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
85
86 acpigen_write_return_integer(dsm_config->support_ultra_high_band);
87}
88
89/*
90 * Function 4: Regulatory Special Configurations Enablements
91 */
92static void wifi_dsm_regulatory_configurations(void *args)
93{
94 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
95
96 acpigen_write_return_integer(dsm_config->regulatory_configurations);
97}
98
99/*
100 * Function 5: M.2 UART Interface Configuration
101 */
102static void wifi_dsm_uart_configurations(void *args)
103{
104 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
105
106 acpigen_write_return_integer(dsm_config->uart_configurations);
107}
108
109/*
110 * Function 6: Control Enablement 11ax on certificated modules
111 * Bit 0 - Apply changes to country Ukraine. 11Ax Setting within module certification
112 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
113 * 1 - Apply changes.
114 *
115 * Bit 1 - 11Ax Mode. Effective only if Bit 0 set to 1
116 * 0 - Disable 11Ax on country Ukraine [Default]
117 * 1 - Enable 11Ax on country Ukraine
118 *
119 * Bit 2 - Apply changes to country Russia. 11Ax Setting within module certification
120 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
121 * 1 - Apply changes.
122 *
123 * Bit 3 - 11Ax Mode. Effective only if Bit 2 set to 1
124 * 0 - Disable 11Ax on country Russia [Default]
125 * 1 - Enable 11Ax on country Russia
126 *
127 * Bit 31:04 - Reserved
128 *
129 * Note: Assumed Russia Work with Wi-Fi FW/OTP definitions
130 */
131static void wifi_dsm_ukrane_russia_11ax_enable(void *args)
132{
133 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
134
135 acpigen_write_return_integer(dsm_config->enablement_11ax);
136}
137
138/*
139 * Function 7: Control Enablement UNII-4 over certificate modules
140 */
141static void wifi_dsm_unii4_control_enable(void *args)
142{
143 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
144
145 acpigen_write_return_integer(dsm_config->unii_4);
146}
147
148static void (*wifi_dsm_callbacks[])(void *) = {
149 NULL, /* Function 0 */
150 wifi_dsm_srd_active_channels, /* Function 1 */
151 wifi_dsm_indonasia_5Ghz_band_enable, /* Function 2 */
152 wifi_dsm_supported_ultra_high_band, /* Function 3 */
153 wifi_dsm_regulatory_configurations, /* Function 4 */
154 wifi_dsm_uart_configurations, /* Function 5 */
155 wifi_dsm_ukrane_russia_11ax_enable, /* Function 6 */
156 wifi_dsm_unii4_control_enable, /* Function 7 */
157};
158
159void wifi_emit_dsm(struct dsm_profile *dsm)
160{
161 int i;
162 size_t count = ARRAY_SIZE(wifi_dsm_callbacks);
163
164 if (dsm == NULL)
165 return;
166
167 for (i = 1; i < count; i++)
168 if (!(dsm->supported_functions & (1 << i)))
169 wifi_dsm_callbacks[i] = NULL;
170
171 acpigen_write_dsm(ACPI_DSM_OEM_WIFI_UUID, wifi_dsm_callbacks, count, dsm);
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
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530465static void emit_sar_acpi_structures(const struct device *dev)
466{
467 union wifi_sar_limits sar_limits;
468
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
476 /* Retrieve the sar limits data */
477 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);
Sugnan Prabhu Sd70f4812021-08-25 17:36:44 +0530487 wifi_emit_dsm(sar_limits.dsm);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530488
489 free(sar_limits.sar);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700490}
491
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700492static void wifi_ssdt_write_device(const struct device *dev, const char *path)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700493{
Furquan Shaikh2736c822020-10-27 19:46:11 -0700494 /* Device */
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700495 acpigen_write_device(path);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700496 acpi_device_write_uid(dev);
497
498 if (dev->chip_ops)
499 acpigen_write_name_string("_DDN", dev->chip_ops->name);
500
501 /* Address */
502 acpigen_write_ADR_pci_device(dev);
503
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700504 acpigen_pop_len(); /* Device */
505}
506
507static void wifi_ssdt_write_properties(const struct device *dev, const char *scope)
508{
509 const struct drivers_wifi_generic_config *config = dev->chip_info;
510
511 /* Scope */
512 acpigen_write_scope(scope);
513
Tim Wawrzynczak3babc8e2022-01-25 14:05:20 -0700514 if (config) {
515 /* Wake capabilities */
Furquan Shaikh2736c822020-10-27 19:46:11 -0700516 acpigen_write_PRW(config->wake, ACPI_S3);
517
Tim Wawrzynczakafaee232022-02-23 10:17:21 -0700518 /* Add _DSD for DmaProperty property. */
Tim Wawrzynczak3babc8e2022-01-25 14:05:20 -0700519 if (config->is_untrusted) {
520 struct acpi_dp *dsd, *pkg;
521
522 dsd = acpi_dp_new_table("_DSD");
523 pkg = acpi_dp_new_table(ACPI_DSD_UNTRUSTED_UUID);
Tim Wawrzynczakafaee232022-02-23 10:17:21 -0700524 acpi_dp_add_integer(pkg, "DmaProperty", 1);
Tim Wawrzynczak3babc8e2022-01-25 14:05:20 -0700525 acpi_dp_add_package(dsd, pkg);
526 acpi_dp_write(dsd);
527 }
528 }
529
Furquan Shaikh2736c822020-10-27 19:46:11 -0700530 /* Fill regulatory domain structure */
531 if (CONFIG(HAVE_REGULATORY_DOMAIN)) {
532 /*
533 * Name ("WRDD", Package () {
534 * WRDD_REVISION, // Revision
535 * Package () {
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530536 * DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
Furquan Shaikh2736c822020-10-27 19:46:11 -0700537 * wifi_regulatory_domain() // Country Identifier
538 * }
539 * })
540 */
541 acpigen_write_name("WRDD");
542 acpigen_write_package(2);
543 acpigen_write_integer(WRDD_REVISION);
544 acpigen_write_package(2);
Sugnan Prabhu Sfcb4f2d2021-07-30 20:12:22 +0530545 acpigen_write_dword(DOMAIN_TYPE_WIFI);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700546 acpigen_write_dword(wifi_regulatory_domain());
547 acpigen_pop_len();
548 acpigen_pop_len();
549 }
550
551 /* Fill Wifi sar related ACPI structures */
552 if (CONFIG(USE_SAR))
553 emit_sar_acpi_structures(dev);
554
Furquan Shaikh2736c822020-10-27 19:46:11 -0700555 acpigen_pop_len(); /* Scope */
556
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700557 printk(BIOS_INFO, "%s: %s %s\n", scope, dev->chip_ops ? dev->chip_ops->name : "",
558 dev_path(dev));
559}
560
Furquan Shaikhd4367502020-10-27 18:00:46 -0700561void wifi_pcie_fill_ssdt(const struct device *dev)
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700562{
563 const char *path;
564
Furquan Shaikh6017abb2020-10-27 17:41:09 -0700565 path = acpi_device_path(dev);
566 if (!path)
567 return;
568
569 wifi_ssdt_write_device(dev, path);
570 wifi_ssdt_write_properties(dev, path);
Furquan Shaikh2736c822020-10-27 19:46:11 -0700571}
572
Furquan Shaikhd4367502020-10-27 18:00:46 -0700573const char *wifi_pcie_acpi_name(const struct device *dev)
Furquan Shaikh2736c822020-10-27 19:46:11 -0700574{
575 static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN];
576
577 /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */
578 snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X",
579 (dev_path_encode(dev) & 0xff));
580 return wifi_acpi_name;
581}
Furquan Shaikhd4367502020-10-27 18:00:46 -0700582
583void wifi_cnvi_fill_ssdt(const struct device *dev)
584{
585 const char *path;
586
Furquan Shaikhd4367502020-10-27 18:00:46 -0700587 path = acpi_device_path(dev->bus->dev);
588 if (!path)
589 return;
590
591 wifi_ssdt_write_properties(dev, path);
592}