mb/google/brya: Create rull variant
[coreboot2.git] / src / drivers / wifi / generic / acpi.c
blob81620f75050e44aa7be84f49cbb8f2f406df25c4
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;
586 * Name ("BRDS", Package () {
587 * Revision,
588 * Package () {
589 * Domain Type, // 0x12:Bluetooth
590 * Bluetooth SAR BIOS, // BIOS SAR Enable/disable
591 * Bluetooth Increase Power Mode // SAR Limitation Enable/disable
592 * Bluetooth SAR Power Restriction, // 00000000 - 0dBm
593 * // 11111111 - 31.875dBm
594 * // (Step 0.125dBm)
595 * Bluetooth SAR Table // SAR Tx power limit table
597 * })
599 if (bsar->revision != BSAR_REVISION) {
600 printk(BIOS_ERR, "Unsupported BSAR table revision: %d\n",
601 bsar->revision);
602 return;
605 acpigen_write_name("BRDS");
606 acpigen_write_package(2);
607 acpigen_write_dword(bsar->revision);
609 table_size = sizeof(*bsar) -
610 offsetof(struct bsar_profile, sar_lb_power_restriction);
612 * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Increase Power Mode'
613 * + ('SAR Power Restriction' + SAR table).
615 package_size = 1 + 1 + 1 + table_size;
616 acpigen_write_package(package_size);
617 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
618 acpigen_write_dword(1);
619 acpigen_write_dword(bsar->increased_power_mode_limitation);
621 set = (const uint8_t *)&bsar->sar_lb_power_restriction;
622 for (int i = 0; i < table_size; i++)
623 acpigen_write_byte(set[i]);
625 acpigen_write_package_end();
626 acpigen_write_package_end();
629 static void sar_emit_wbem(const struct wbem_profile *wbem)
631 if (wbem == NULL)
632 return;
635 * Name ("WBEM", Package() {
637 * Revision,
638 * Package()
640 * DomainType, // 0x7:WiFi
641 * bandwidth_320mhz_country_enablement // 0 Disabled
642 * // 1 Japan Enabled
643 * // 2 South Korea Enabled
644 * // 3 Japan + South Korea Enabled
646 } })
648 if (wbem->revision != WBEM_REVISION) {
649 printk(BIOS_ERR, "Unsupported WBEM table revision: %d\n",
650 wbem->revision);
651 return;
654 acpigen_write_name("WBEM");
655 acpigen_write_package(2);
656 acpigen_write_dword(wbem->revision);
658 acpigen_write_package(2);
659 acpigen_write_dword(DOMAIN_TYPE_WIFI);
660 acpigen_write_dword(wbem->bandwidth_320mhz_country_enablement);
662 acpigen_write_package_end();
663 acpigen_write_package_end();
666 static void emit_sar_acpi_structures(const struct device *dev, struct dsm_profile *dsm,
667 struct bsar_profile *bsar, bool *bsar_loaded)
669 union wifi_sar_limits sar_limits = {0};
672 * If device type is PCI, ensure that the device has Intel vendor ID. CBFS SAR and SAR
673 * ACPI tables are currently used only by Intel WiFi devices.
675 if (dev->path.type == DEVICE_PATH_PCI && dev->vendor != PCI_VID_INTEL)
676 return;
678 /* Retrieve the SAR limits data */
679 if (get_wifi_sar_limits(&sar_limits) < 0) {
680 printk(BIOS_ERR, "failed getting SAR limits!\n");
681 return;
684 sar_emit_wrds(sar_limits.sar);
685 sar_emit_ewrd(sar_limits.sar);
686 sar_emit_wgds(sar_limits.wgds);
687 sar_emit_ppag(sar_limits.ppag);
688 sar_emit_wtas(sar_limits.wtas);
689 sar_emit_wbem(sar_limits.wbem);
691 /* copy the dsm data to be later used for creating _DSM function */
692 if (sar_limits.dsm != NULL)
693 memcpy(dsm, sar_limits.dsm, sizeof(struct dsm_profile));
695 /* copy the bsar data to be later used for creating Bluetooth BRDS method */
696 if (sar_limits.bsar != NULL) {
697 memcpy(bsar, sar_limits.bsar, sizeof(struct bsar_profile));
698 *bsar_loaded = true;
701 free(sar_limits.sar);
704 static void wifi_ssdt_write_device(const struct device *dev, const char *path)
706 /* Device */
707 acpigen_write_device(path);
708 acpi_device_write_uid(dev);
710 if (dev->chip_ops)
711 acpigen_write_name_string("_DDN", dev->chip_ops->name);
713 /* Address */
714 acpigen_write_ADR_pci_device(dev);
716 acpigen_pop_len(); /* Device */
719 static void wifi_ssdt_write_properties(const struct device *dev, const char *scope)
721 const struct drivers_wifi_generic_config *config = dev->chip_info;
723 bool is_cnvi_ddr_rfim_enabled = config && config->enable_cnvi_ddr_rfim;
725 /* Scope */
726 acpigen_write_scope(scope);
728 if (config) {
729 /* Wake capabilities */
730 acpigen_write_PRW(config->wake, ACPI_S3);
732 /* Add _DSD for DmaProperty property. */
733 if (config->add_acpi_dma_property)
734 acpi_device_add_dma_property(NULL);
737 /* Fill regulatory domain structure */
738 if (CONFIG(HAVE_REGULATORY_DOMAIN)) {
740 * Name ("WRDD", Package () {
741 * WRDD_REVISION, // Revision
742 * Package () {
743 * DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
744 * wifi_regulatory_domain() // Country Identifier
746 * })
748 acpigen_write_name("WRDD");
749 acpigen_write_package(2);
750 acpigen_write_integer(WRDD_REVISION);
751 acpigen_write_package(2);
752 acpigen_write_dword(DOMAIN_TYPE_WIFI);
753 acpigen_write_dword(wifi_regulatory_domain());
754 acpigen_pop_len();
755 acpigen_pop_len();
758 struct dsm_uuid dsm_ids[MAX_DSM_FUNCS];
759 /* We will need a copy dsm data to be used later for creating _DSM function */
760 struct dsm_profile dsm = {0};
761 /* We will need a copy of bsar data to be used later for creating BRDS function */
762 struct bsar_profile bsar = {0};
763 bool bsar_loaded = false;
764 uint8_t dsm_count = 0;
766 /* Fill Wifi SAR related ACPI structures */
767 if (CONFIG(USE_SAR)) {
768 emit_sar_acpi_structures(dev, &dsm, &bsar, &bsar_loaded);
770 if (dsm.supported_functions != 0) {
771 for (int i = 1; i < ARRAY_SIZE(wifi_dsm_callbacks); i++)
772 if (!(dsm.supported_functions & (1 << i)))
773 wifi_dsm_callbacks[i] = NULL;
775 dsm_ids[dsm_count].uuid = ACPI_DSM_OEM_WIFI_UUID;
776 dsm_ids[dsm_count].callbacks = &wifi_dsm_callbacks[0];
777 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm_callbacks);
778 dsm_ids[dsm_count].arg = &dsm;
779 dsm_count++;
783 if (is_cnvi_ddr_rfim_enabled) {
784 dsm_ids[dsm_count].uuid = ACPI_DSM_RFIM_WIFI_UUID;
785 dsm_ids[dsm_count].callbacks = &wifi_dsm2_callbacks[0];
786 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm2_callbacks);
787 dsm_ids[dsm_count].arg = &is_cnvi_ddr_rfim_enabled;
788 dsm_count++;
791 acpigen_write_dsm_uuid_arr(dsm_ids, dsm_count);
794 * Fill MediaTek MTCL related ACPI structure iff the device type is PCI,
795 * the device has the MediaTek vendor ID, and the MTCL feature is
796 * configured.
798 if (CONFIG(USE_MTCL)) {
799 if (dev->path.type == DEVICE_PATH_PCI &&
800 dev->vendor == PCI_VID_MEDIATEK)
801 write_mtcl_function();
804 acpigen_write_scope_end(); /* Scope */
806 /* Fill Bluetooth companion SAR related ACPI structures */
807 if (bsar_loaded && is_dev_enabled(config->bluetooth_companion)) {
808 const char *path = acpi_device_path(config->bluetooth_companion);
809 if (path) { /* Bluetooth device under USB Hub scope or PCIe root port */
810 acpigen_write_scope(path);
811 sar_emit_brds(&bsar);
812 acpigen_write_scope_end();
813 } else {
814 printk(BIOS_ERR, "Failed to get %s Bluetooth companion ACPI path\n",
815 dev_path(dev));
819 printk(BIOS_INFO, "%s: %s %s\n", scope, dev->chip_ops ? dev->chip_ops->name : "",
820 dev_path(dev));
823 void wifi_pcie_fill_ssdt(const struct device *dev)
825 const char *path;
827 path = acpi_device_path(dev);
828 if (!path)
829 return;
831 wifi_ssdt_write_device(dev, path);
832 wifi_ssdt_write_properties(dev, path);
835 const char *wifi_pcie_acpi_name(const struct device *dev)
837 static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN];
839 /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */
840 snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X",
841 (dev_path_encode(dev) & 0xff));
842 return wifi_acpi_name;
845 void wifi_cnvi_fill_ssdt(const struct device *dev)
847 const char *path;
848 if (!dev)
849 return;
851 path = acpi_device_path(dev->upstream->dev);
852 if (!path)
853 return;
855 wifi_ssdt_write_properties(dev, path);