soc/intel/ptl: Update ME specification version to 21
[coreboot.git] / src / drivers / wifi / generic / acpi.c
blob9ed17e0b5c7919f9747eb08f74e6fa3356ae0e69
1 /* SPDX-License-Identifier: GPL-2.0-only */
3 #include <acpi/acpi_device.h>
4 #include <acpi/acpigen.h>
5 #include <acpi/acpigen_pci.h>
6 #include <console/console.h>
7 #include <device/pci_ids.h>
8 #include <mtcl.h>
9 #include <sar.h>
10 #include <stdio.h>
11 #include <stdlib.h>
12 #include <wrdd.h>
14 #include "chip.h"
15 #include "wifi.h"
16 #include "wifi_private.h"
18 /* Domain type */
19 #define DOMAIN_TYPE_WIFI 0x7
20 #define DOMAIN_TYPE_BLUETOOTH 0x12
22 /* Maximum number DSM UUID bifurcations in _DSM */
23 #define MAX_DSM_FUNCS 2
26 * WIFI ACPI NAME = "WF" + hex value of last 8 bits of dev_path_encode + '\0'
27 * The above representation returns unique and consistent name every time
28 * generate_wifi_acpi_name is invoked. The last 8 bits of dev_path_encode is
29 * chosen since it contains the bus address of the device.
31 #define WIFI_ACPI_NAME_MAX_LEN 5
33 /* Unique ID for the WIFI _DSM */
34 #define ACPI_DSM_OEM_WIFI_UUID "F21202BF-8F78-4DC6-A5B3-1F738E285ADE"
36 /* Unique ID for CnviDdrRfim entry in WIFI _DSM */
37 #define ACPI_DSM_RFIM_WIFI_UUID "7266172C-220B-4B29-814F-75E4DD26B5FD"
39 __weak int get_wifi_sar_limits(union wifi_sar_limits *sar_limits)
41 return -1;
45 * 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
51 static void wifi_dsm_srd_active_channels(void *args)
53 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
55 acpigen_write_return_integer(dsm_config->disable_active_sdr_channels);
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
64 static void wifi_dsm_indonasia_5Ghz_band_enable(void *args)
66 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
68 acpigen_write_return_integer(dsm_config->support_indonesia_5g_band);
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
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)
81 static void wifi_dsm_supported_ultra_high_band(void *args)
83 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
85 acpigen_write_return_integer(dsm_config->support_ultra_high_band);
89 * Function 4: Regulatory Special Configurations Enablements
91 static void wifi_dsm_regulatory_configurations(void *args)
93 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
95 acpigen_write_return_integer(dsm_config->regulatory_configurations);
99 * Function 5: M.2 UART Interface Configuration
101 static void wifi_dsm_uart_configurations(void *args)
103 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
105 acpigen_write_return_integer(dsm_config->uart_configurations);
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.
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
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.
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
126 * Bit 31:04 - Reserved
128 * Note: Assumed Russia Work with Wi-Fi FW/OTP definitions
130 static void wifi_dsm_ukrane_russia_11ax_enable(void *args)
132 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
134 acpigen_write_return_integer(dsm_config->enablement_11ax);
138 * Function 7: Control Enablement UNII-4 over certificate modules
140 static void wifi_dsm_unii4_control_enable(void *args)
142 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
144 acpigen_write_return_integer(dsm_config->unii_4);
148 * Function 10: Energy Detection Threshold (EDT)
149 * Bits 0-3: EDT revision - Default 0
151 * Bits 4-5: Reserved - Should be 0
153 * Bit 6: HB EDT Level. 5 GHz ETSI - EDT Level change - Default 0
154 * 0 - Disable EDT optimization for ETSI HB
155 * 1 - Enable EDT optimization for ETSI HB
157 * Bits 7-8: Reserved - Should be 0
159 * Bit 9: UHB EDT Level. 6 GHz FCC - EDT Level change - Default 0
160 * 0 - Disable EDT optimization for FCC UHB
161 * 1 - Enable EDT optimization for FCC UHB
163 * Bit 10-12: Reserved - Default 0
165 * Bit 13: EDT_En_HB_5G2/3 - Default 0
166 * 0 - Disable EDT optimization for HB_5G2/3
167 * 1 - Enable EDT optimization for HB_5G2/3
169 * Bit 14: EDT_En_HB_5G4 - Default 0
170 * 0 - Disable EDT optimization for HB_5G4
171 * 1 - Enable EDT optimization for HB_5G4
173 * Bit 15: EDT_En_HB_5G6 - Default 0
174 * 0 - Disable EDT optimization for HB_5G6
175 * 1 - Enable EDT optimization for HB_5G6
177 * Bit 16: EDT_En_HB_5G8/9 - Default 0
178 * 0 - Disable EDT optimization for HB_5G8/9
179 * 1 - Enable EDT optimization for HB_5G8/9
181 * Bit 17: EDT_En_UHB_6G1 - Default 0
182 * 0 - Disable EDT optimization for UHB_6G1
183 * 1 - Enable EDT optimization for UHB_6G1
185 * Bit 18: EDT_En_UHB_6G3 - Default 0
186 * 0 - Disable EDT optimization for UHB_6G3
187 * 1 - Enable EDT optimization for UHB_6G3
189 * Bit 19: EDT_En_UHB_6G5 - Default 0
190 * 0 - Disable EDT optimization for UHB_6G5
191 * 1 - Enable EDT optimization for UHB_6G5
193 * Bit 20: EDT_En_UHB_6G6 - Default 0
194 * 0 - Disable EDT optimization for UHB_6G6
195 * 1 - Enable EDT optimization for UHB_6G6
197 * Bit 21: EDT_En_UHB_6G8 - Default 0
198 * 0 - Disable EDT optimization for UHB_6G8
199 * 1 - Enable EDT optimization for UHB_6G8
201 * Bit 22: EDT_En_UHB_7G0 - Default 0
202 * 0 - Disable EDT optimization for UHB_7G0
203 * 1 - Enable EDT optimization for UHB_7G0
205 * Bits 23-31: Reserved - Should be 0
207 static void wifi_dsm_energy_detection_threshold(void *args)
209 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
211 acpigen_write_return_integer(dsm_config->energy_detection_threshold);
215 * Function 11: RFI mitigation
216 * Bit 0:
217 * 0 - DLVR RFIm enabled (default)
218 * 1 - DLVR RFIm disabled
220 * Bit 1:
221 * 0 - DDR RFIm enabled (default)
222 * 1 - DDR RFIm disabled
224 * Bits 2-31: Reserved - Should be 0
227 static void wifi_dsm_rfi_mitigation(void *args)
229 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
231 acpigen_write_return_integer(dsm_config->rfi_mitigation);
235 * Function 12: Control Enablement 802.11be on certificated modules
236 * Bit 0
237 * 0 - 11BE disabled for China Mainland
238 * 1 - 11BE enabled for China Mainland
240 * Bit 1
241 * 0 - 11BE disabled for South Korea
242 * 1 - 11BE enabled for South Korea
244 * Bit 2:27 - Reserved (shall be set to zeroes)
246 * Bit 28:31 - 11BE enablement revision
249 static void wifi_dsm_11be_country_enablement(void *args)
251 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
253 acpigen_write_return_integer(dsm_config->enablement_11be);
256 static void wifi_dsm_ddrrfim_func3_cb(void *ptr)
258 const bool is_cnvi_ddr_rfim_enabled = *(bool *)ptr;
259 acpigen_write_return_integer(is_cnvi_ddr_rfim_enabled ? 0 : 1);
262 static void (*wifi_dsm_callbacks[])(void *) = {
263 NULL, /* Function 0 */
264 wifi_dsm_srd_active_channels, /* Function 1 */
265 wifi_dsm_indonasia_5Ghz_band_enable, /* Function 2 */
266 wifi_dsm_supported_ultra_high_band, /* Function 3 */
267 wifi_dsm_regulatory_configurations, /* Function 4 */
268 wifi_dsm_uart_configurations, /* Function 5 */
269 wifi_dsm_ukrane_russia_11ax_enable, /* Function 6 */
270 wifi_dsm_unii4_control_enable, /* Function 7 */
271 NULL, /* Function 8 */
272 NULL, /* Function 9 */
273 wifi_dsm_energy_detection_threshold, /* Function 10 */
274 wifi_dsm_rfi_mitigation, /* Function 11 */
275 wifi_dsm_11be_country_enablement, /* Function 12 */
279 * The current DSM2 table is only exporting one function (function 3), some more
280 * functions are reserved so marking them NULL.
282 static void (*wifi_dsm2_callbacks[])(void *) = {
283 NULL, /* Function 0 */
284 NULL, /* Function 1 */
285 NULL, /* Function 2 */
286 wifi_dsm_ddrrfim_func3_cb, /* Function 3 */
289 static const uint8_t *sar_fetch_set(const struct sar_profile *sar, size_t set_num)
291 const uint8_t *sar_table = &sar->sar_table[0];
293 return sar_table + (sar->chains_count * sar->subbands_count * set_num);
296 static const uint8_t *wgds_fetch_set(struct geo_profile *wgds, size_t set_num)
298 const uint8_t *wgds_table = &wgds->wgds_table[0];
300 return wgds_table + (wgds->bands_count * set_num);
303 static const uint8_t *ppag_fetch_set(struct gain_profile *ppag, size_t set_num)
305 const uint8_t *ppag_table = &ppag->ppag_table[0];
307 return ppag_table + (ppag->bands_count * set_num);
310 static void sar_emit_wrds(const struct sar_profile *sar)
312 int i;
313 size_t package_size, table_size;
314 const uint8_t *set;
316 if (sar == NULL)
317 return;
320 * Name ("WRDS", Package () {
321 * Revision,
322 * Package () {
323 * Domain Type, // 0x7:WiFi
324 * WiFi SAR BIOS, // BIOS SAR Enable/disable
325 * SAR Table Set // Set#1 of SAR Table
327 * })
329 if (sar->revision > MAX_SAR_REVISION) {
330 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
331 return;
334 acpigen_write_name("WRDS");
335 acpigen_write_package(2);
336 acpigen_write_dword(sar->revision);
338 table_size = sar->chains_count * sar->subbands_count;
339 /* Emit 'Domain Type' + 'WiFi SAR Enable' + Set#1 */
340 package_size = 1 + 1 + table_size;
341 acpigen_write_package(package_size);
342 acpigen_write_dword(DOMAIN_TYPE_WIFI);
343 acpigen_write_dword(1);
345 set = sar_fetch_set(sar, 0);
346 for (i = 0; i < table_size; i++)
347 acpigen_write_byte(set[i]);
349 acpigen_write_package_end();
350 acpigen_write_package_end();
353 static void sar_emit_ewrd(const struct sar_profile *sar)
355 int i;
356 size_t package_size, set_num, table_size;
357 const uint8_t *set;
359 if (sar == NULL)
360 return;
363 * Name ("EWRD", Package () {
364 * Revision,
365 * Package () {
366 * Domain Type, // 0x7:WiFi
367 * Dynamic SAR Enable, // Dynamic SAR Enable/disable
368 * Extended SAR sets, // Number of optional SAR table sets
369 * SAR Table Set, // Set#2 of SAR Table
370 * SAR Table Set, // Set#3 of SAR Table
371 * SAR Table Set // Set#4 of SAR Table
373 * })
375 if (sar->revision > MAX_SAR_REVISION) {
376 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
377 return;
380 if (sar->dsar_set_count == 0) {
381 printk(BIOS_WARNING, "DSAR set count is 0\n");
382 return;
385 acpigen_write_name("EWRD");
386 acpigen_write_package(2);
387 acpigen_write_dword(sar->revision);
389 table_size = sar->chains_count * sar->subbands_count;
391 * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Extended SAR sets count'
392 * + number of bytes for Set#2 & 3 & 4
394 package_size = 1 + 1 + 1 + table_size * MAX_DSAR_SET_COUNT;
395 acpigen_write_package(package_size);
396 acpigen_write_dword(DOMAIN_TYPE_WIFI);
397 acpigen_write_dword(1);
398 acpigen_write_dword(sar->dsar_set_count);
400 for (set_num = 1; set_num <= sar->dsar_set_count; set_num++) {
401 set = sar_fetch_set(sar, set_num);
402 for (i = 0; i < table_size; i++)
403 acpigen_write_byte(set[i]);
406 /* wifi driver always expects 3 DSAR sets */
407 for (i = 0; i < (table_size * (MAX_DSAR_SET_COUNT - sar->dsar_set_count)); i++)
408 acpigen_write_byte(0);
410 acpigen_write_package_end();
411 acpigen_write_package_end();
414 static void sar_emit_wgds(struct geo_profile *wgds)
416 int i;
417 size_t package_size, set_num;
418 const uint8_t *set;
420 if (wgds == NULL)
421 return;
424 * Name ("WGDS", Package() {
425 * Revision,
426 * Package() {
427 * DomainType, // 0x7:WiFi
428 * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max
429 * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset
430 * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset
431 * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max
432 * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset
433 * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset
434 * WgdsWiFiSarDeltaGroup1PowerMax3, // Group 1 FCC 6000-7000 Max
435 * WgdsWiFiSarDeltaGroup1PowerChainA3, // Group 1 FCC 6000-7000 A Offset
436 * WgdsWiFiSarDeltaGroup1PowerChainB3, // Group 1 FCC 6000-7000 B Offset
437 * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max
438 * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset
439 * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset
440 * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max
441 * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset
442 * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset
443 * WgdsWiFiSarDeltaGroup2PowerMax3, // Group 2 EC Jap 6000-7000 Max
444 * WgdsWiFiSarDeltaGroup2PowerChainA3, // Group 2 EC Jap 6000-7000 A Offset
445 * WgdsWiFiSarDeltaGroup2PowerChainB3, // Group 2 EC Jap 6000-7000 B Offset
446 * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max
447 * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset
448 * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset
449 * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max
450 * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset
451 * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset
452 * WgdsWiFiSarDeltaGroup3PowerMax3, // Group 3 ROW 6000-7000 Max
453 * WgdsWiFiSarDeltaGroup3PowerChainA3, // Group 3 ROW 6000-7000 A Offset
454 * WgdsWiFiSarDeltaGroup3PowerChainB3, // Group 3 ROW 6000-7000 B Offset
456 * })
458 if (wgds->revision > MAX_GEO_OFFSET_REVISION) {
459 printk(BIOS_ERR, "Invalid WGDS revision: %d\n", wgds->revision);
460 return;
463 package_size = 1 + wgds->chains_count * wgds->bands_count;
465 acpigen_write_name("WGDS");
466 acpigen_write_package(2);
467 acpigen_write_dword(wgds->revision);
468 /* Emit 'Domain Type' +
469 * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS)
471 acpigen_write_package(package_size);
472 acpigen_write_dword(DOMAIN_TYPE_WIFI);
474 for (set_num = 0; set_num < wgds->chains_count; set_num++) {
475 set = wgds_fetch_set(wgds, set_num);
476 for (i = 0; i < wgds->bands_count; i++)
477 acpigen_write_byte(set[i]);
480 acpigen_write_package_end();
481 acpigen_write_package_end();
484 static void sar_emit_ppag(struct gain_profile *ppag)
486 int i;
487 size_t package_size, set_num;
488 const uint8_t *set;
490 if (ppag == NULL)
491 return;
494 * Name ("PPAG", Package () {
495 * Revision,
496 * Package () {
497 * Domain Type, // 0x7:WiFi
498 * PPAG Mode, // Defines the mode of ANT_gain control to be used
499 * ANT_gain Table Chain A // Defines the ANT_gain in dBi for chain A
500 * ANT_gain Table Chain B // Defines the ANT_gain in dBi for chain B
502 * })
504 if (ppag->revision > MAX_ANT_GAINS_REVISION) {
505 printk(BIOS_ERR, "Invalid PPAG revision: %d\n", ppag->revision);
506 return;
509 package_size = 1 + 1 + ppag->chains_count * ppag->bands_count;
511 acpigen_write_name("PPAG");
512 acpigen_write_package(2);
513 acpigen_write_dword(ppag->revision);
514 acpigen_write_package(package_size);
515 acpigen_write_dword(DOMAIN_TYPE_WIFI);
516 acpigen_write_dword(ppag->mode);
518 for (set_num = 0; set_num < ppag->chains_count; set_num++) {
519 set = ppag_fetch_set(ppag, set_num);
520 for (i = 0; i < ppag->bands_count; i++)
521 acpigen_write_byte(set[i]);
524 acpigen_write_package_end();
525 acpigen_write_package_end();
528 static void sar_emit_wtas(struct avg_profile *wtas)
530 int i;
531 size_t package_size;
533 if (wtas == NULL)
534 return;
537 * Name (WTAS, Package() {
539 * Revision,
540 * Package()
542 * DomainType, // 0x7:WiFi
543 * WifiTASSelection, // Enable/Disable the TAS feature
544 * WifiTASListEntries, // No. of blocked countries not approved by OEM to
545 * BlockedListEntry1, support this feature
546 * BlockedListEntry2,
547 * BlockedListEntry3,
548 * BlockedListEntry4,
549 * BlockedListEntry5,
550 * BlockedListEntry6,
551 * BlockedListEntry7,
552 * BlockedListEntry8,
553 * BlockedListEntry9,
554 * BlockedListEntry10,
555 * BlockedListEntry11,
556 * BlockedListEntry12,
557 * BlockedListEntry13,
558 * BlockedListEntry14,
559 * BlockedListEntry15,
560 * BlockedListEntry16,
562 * })
564 package_size = 1 + 1 + 1 + MAX_DENYLIST_ENTRY;
566 acpigen_write_name("WTAS");
567 acpigen_write_package(2);
568 acpigen_write_dword(wtas->revision);
569 acpigen_write_package(package_size);
570 acpigen_write_dword(DOMAIN_TYPE_WIFI);
571 acpigen_write_byte(wtas->tas_selection);
572 acpigen_write_byte(wtas->tas_list_size);
573 for (i = 0; i < MAX_DENYLIST_ENTRY; i++)
574 acpigen_write_word(wtas->deny_list_entry[i]);
576 acpigen_write_package_end();
577 acpigen_write_package_end();
580 static void sar_emit_brds(const struct bsar_profile *bsar)
582 size_t package_size, table_size;
583 const uint8_t *set;
585 if (bsar == NULL)
586 return;
589 * Name ("BRDS", Package () {
590 * Revision,
591 * Package () {
592 * Domain Type, // 0x12:Bluetooth
593 * Bluetooth SAR BIOS, // BIOS SAR Enable/disable
594 * Bluetooth Increase Power Mode // SAR Limitation Enable/disable
595 * Bluetooth SAR Power Restriction, // 00000000 - 0dBm
596 * // 11111111 - 31.875dBm
597 * // (Step 0.125dBm)
598 * Bluetooth SAR Table // SAR Tx power limit table
600 * })
602 if (bsar->revision != BSAR_REVISION) {
603 printk(BIOS_ERR, "Unsupported BSAR table revision: %d\n",
604 bsar->revision);
605 return;
608 acpigen_write_name("BRDS");
609 acpigen_write_package(2);
610 acpigen_write_dword(bsar->revision);
612 table_size = sizeof(*bsar) -
613 offsetof(struct bsar_profile, sar_lb_power_restriction);
615 * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Increase Power Mode'
616 * + ('SAR Power Restriction' + SAR table).
618 package_size = 1 + 1 + 1 + table_size;
619 acpigen_write_package(package_size);
620 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
621 acpigen_write_dword(1);
622 acpigen_write_dword(bsar->increased_power_mode_limitation);
624 set = (const uint8_t *)&bsar->sar_lb_power_restriction;
625 for (int i = 0; i < table_size; i++)
626 acpigen_write_byte(set[i]);
628 acpigen_write_package_end();
629 acpigen_write_package_end();
632 static void sar_emit_wbem(const struct wbem_profile *wbem)
634 if (wbem == NULL)
635 return;
638 * Name ("WBEM", Package() {
640 * Revision,
641 * Package()
643 * DomainType, // 0x7:WiFi
644 * bandwidth_320mhz_country_enablement // 0 Disabled
645 * // 1 Japan Enabled
646 * // 2 South Korea Enabled
647 * // 3 Japan + South Korea Enabled
649 } })
651 if (wbem->revision != WBEM_REVISION) {
652 printk(BIOS_ERR, "Unsupported WBEM table revision: %d\n",
653 wbem->revision);
654 return;
657 acpigen_write_name("WBEM");
658 acpigen_write_package(2);
659 acpigen_write_dword(wbem->revision);
661 acpigen_write_package(2);
662 acpigen_write_dword(DOMAIN_TYPE_WIFI);
663 acpigen_write_dword(wbem->bandwidth_320mhz_country_enablement);
665 acpigen_write_package_end();
666 acpigen_write_package_end();
669 static void emit_wifi_sar_acpi_structures(const struct device *dev,
670 union wifi_sar_limits *sar_limits)
673 * If device type is PCI, ensure that the device has Intel vendor ID. CBFS SAR and SAR
674 * ACPI tables are currently used only by Intel WiFi devices.
676 if (dev->path.type == DEVICE_PATH_PCI && dev->vendor != PCI_VID_INTEL)
677 return;
679 sar_emit_wrds(sar_limits->sar);
680 sar_emit_ewrd(sar_limits->sar);
681 sar_emit_wgds(sar_limits->wgds);
682 sar_emit_ppag(sar_limits->ppag);
683 sar_emit_wtas(sar_limits->wtas);
684 sar_emit_wbem(sar_limits->wbem);
687 static void wifi_ssdt_write_device(const struct device *dev, const char *path)
689 /* Device */
690 acpigen_write_device(path);
691 acpi_device_write_uid(dev);
693 if (dev->chip_ops)
694 acpigen_write_name_string("_DDN", dev->chip_ops->name);
696 /* Address */
697 acpigen_write_ADR_pci_device(dev);
699 acpigen_pop_len(); /* Device */
702 static void wifi_ssdt_write_properties(const struct device *dev, const char *scope)
704 const struct drivers_wifi_generic_config *config = dev->chip_info;
706 bool is_cnvi_ddr_rfim_enabled = config && config->enable_cnvi_ddr_rfim;
708 /* Scope */
709 acpigen_write_scope(scope);
711 if (config) {
712 /* Wake capabilities */
713 acpigen_write_PRW(config->wake, ACPI_S3);
715 /* Add _DSD for DmaProperty property. */
716 if (config->add_acpi_dma_property)
717 acpi_device_add_dma_property(NULL);
720 /* Fill regulatory domain structure */
721 if (CONFIG(HAVE_REGULATORY_DOMAIN)) {
723 * Name ("WRDD", Package () {
724 * WRDD_REVISION, // Revision
725 * Package () {
726 * DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
727 * wifi_regulatory_domain() // Country Identifier
729 * })
731 acpigen_write_name("WRDD");
732 acpigen_write_package(2);
733 acpigen_write_integer(WRDD_REVISION);
734 acpigen_write_package(2);
735 acpigen_write_dword(DOMAIN_TYPE_WIFI);
736 acpigen_write_dword(wifi_regulatory_domain());
737 acpigen_pop_len();
738 acpigen_pop_len();
741 struct dsm_uuid dsm_ids[MAX_DSM_FUNCS];
743 /* Retrieve the SAR limits data */
744 union wifi_sar_limits sar_limits = {0};
745 bool sar_loaded = false;
746 if (CONFIG(USE_SAR)) {
747 if (get_wifi_sar_limits(&sar_limits) < 0)
748 printk(BIOS_ERR, "failed getting SAR limits!\n");
749 else
750 sar_loaded = true;
753 /* Fill Wifi SAR related ACPI structures */
754 uint8_t dsm_count = 0;
755 if (sar_loaded) {
756 emit_wifi_sar_acpi_structures(dev, &sar_limits);
758 struct dsm_profile *dsm = sar_limits.dsm;
759 if (dsm && dsm->supported_functions != 0) {
760 for (int i = 1; i < ARRAY_SIZE(wifi_dsm_callbacks); i++)
761 if (!(dsm->supported_functions & (1 << i)))
762 wifi_dsm_callbacks[i] = NULL;
764 dsm_ids[dsm_count].uuid = ACPI_DSM_OEM_WIFI_UUID;
765 dsm_ids[dsm_count].callbacks = &wifi_dsm_callbacks[0];
766 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm_callbacks);
767 dsm_ids[dsm_count].arg = dsm;
768 dsm_count++;
772 if (is_cnvi_ddr_rfim_enabled) {
773 dsm_ids[dsm_count].uuid = ACPI_DSM_RFIM_WIFI_UUID;
774 dsm_ids[dsm_count].callbacks = &wifi_dsm2_callbacks[0];
775 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm2_callbacks);
776 dsm_ids[dsm_count].arg = &is_cnvi_ddr_rfim_enabled;
777 dsm_count++;
780 acpigen_write_dsm_uuid_arr(dsm_ids, dsm_count);
783 * Fill MediaTek MTCL related ACPI structure iff the device type is PCI,
784 * the device has the MediaTek vendor ID, and the MTCL feature is
785 * configured.
787 if (CONFIG(USE_MTCL)) {
788 if (dev->path.type == DEVICE_PATH_PCI &&
789 dev->vendor == PCI_VID_MEDIATEK)
790 write_mtcl_function();
793 acpigen_write_scope_end(); /* Scope */
795 /* Fill Bluetooth companion SAR related ACPI structures */
796 if (sar_loaded && is_dev_enabled(config->bluetooth_companion)) {
797 const char *path = acpi_device_path(config->bluetooth_companion);
798 if (path) { /* Bluetooth device under USB Hub scope or PCIe root port */
799 acpigen_write_scope(path);
800 sar_emit_brds(sar_limits.bsar);
801 acpigen_write_scope_end();
802 } else {
803 printk(BIOS_ERR, "Failed to get %s Bluetooth companion ACPI path\n",
804 dev_path(dev));
808 if (sar_loaded)
809 free(sar_limits.sar);
811 printk(BIOS_INFO, "%s: %s %s\n", scope, dev->chip_ops ? dev->chip_ops->name : "",
812 dev_path(dev));
815 void wifi_pcie_fill_ssdt(const struct device *dev)
817 const char *path;
819 path = acpi_device_path(dev);
820 if (!path)
821 return;
823 wifi_ssdt_write_device(dev, path);
824 wifi_ssdt_write_properties(dev, path);
827 const char *wifi_pcie_acpi_name(const struct device *dev)
829 static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN];
831 /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */
832 snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X",
833 (dev_path_encode(dev) & 0xff));
834 return wifi_acpi_name;
837 void wifi_cnvi_fill_ssdt(const struct device *dev)
839 const char *path;
840 if (!dev)
841 return;
843 path = acpi_device_path(dev->upstream->dev);
844 if (!path)
845 return;
847 wifi_ssdt_write_properties(dev, path);