util/intelp2m: Print the current project version
[coreboot2.git] / src / drivers / wifi / generic / acpi.c
blob44705535efe953821192869462228e9d21801c8d
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 enum sar_domain {
20 DOMAIN_TYPE_WIFI = 0x7,
21 DOMAIN_TYPE_BLUETOOTH = 0x12
24 /* Maximum number DSM UUID bifurcations in _DSM */
25 #define MAX_DSM_FUNCS 2
28 * WIFI ACPI NAME = "WF" + hex value of last 8 bits of dev_path_encode + '\0'
29 * The above representation returns unique and consistent name every time
30 * generate_wifi_acpi_name is invoked. The last 8 bits of dev_path_encode is
31 * chosen since it contains the bus address of the device.
33 #define WIFI_ACPI_NAME_MAX_LEN 5
35 /* Unique ID for the WIFI _DSM */
36 #define ACPI_DSM_OEM_WIFI_UUID "F21202BF-8F78-4DC6-A5B3-1F738E285ADE"
38 /* Unique ID for CnviDdrRfim entry in WIFI _DSM */
39 #define ACPI_DSM_RFIM_WIFI_UUID "7266172C-220B-4B29-814F-75E4DD26B5FD"
41 __weak int get_wifi_sar_limits(union wifi_sar_limits *sar_limits)
43 return -1;
47 * Function 1: Allow PC OEMs to set ETSI 5.8GHz SRD in Passive/Disabled ESTI SRD
48 * Channels: 149, 153, 157, 161, 165
49 * 0 - ETSI 5.8GHz SRD active scan
50 * 1 - ETSI 5.8GHz SRD passive scan
51 * 2 - ETSI 5.8GHz SRD disabled
53 static void wifi_dsm_srd_active_channels(void *args)
55 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
57 acpigen_write_return_integer(dsm_config->disable_active_sdr_channels);
61 * Function 2 : Supported Indonesia 5.15-5.35 GHz Band
62 * 0 - Set 5.115-5.35GHz to Disable in Indonesia
63 * 1 - Set 5.115-5.35GHz to Enable (Passive) in Indonesia
64 * 2 - Reserved
66 static void wifi_dsm_indonasia_5Ghz_band_enable(void *args)
68 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
70 acpigen_write_return_integer(dsm_config->support_indonesia_5g_band);
74 * Function 3: Support Wi-Fi 6 11ax Rev 2 new channels on 6-7 GHz.
75 * Bit 0:
76 * 0 - No override; use device settings 0
77 * 1 - Force disable all countries that are not defined in the following bits
79 * Bit 1:
80 * 0 No override; USA 6GHz disable 0
81 * 1 6GHz allowed in the USA (enabled only if the device is certified to the USA)
83 static void wifi_dsm_supported_ultra_high_band(void *args)
85 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
87 acpigen_write_return_integer(dsm_config->support_ultra_high_band);
91 * Function 4: Regulatory Special Configurations Enablements
93 static void wifi_dsm_regulatory_configurations(void *args)
95 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
97 acpigen_write_return_integer(dsm_config->regulatory_configurations);
101 * Function 5: M.2 UART Interface Configuration
103 static void wifi_dsm_uart_configurations(void *args)
105 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
107 acpigen_write_return_integer(dsm_config->uart_configurations);
111 * Function 6: Control Enablement 11ax on certificated modules
112 * Bit 0 - Apply changes to country Ukraine. 11Ax Setting within module certification
113 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
114 * 1 - Apply changes.
116 * Bit 1 - 11Ax Mode. Effective only if Bit 0 set to 1
117 * 0 - Disable 11Ax on country Ukraine [Default]
118 * 1 - Enable 11Ax on country Ukraine
120 * Bit 2 - Apply changes to country Russia. 11Ax Setting within module certification
121 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
122 * 1 - Apply changes.
124 * Bit 3 - 11Ax Mode. Effective only if Bit 2 set to 1
125 * 0 - Disable 11Ax on country Russia [Default]
126 * 1 - Enable 11Ax on country Russia
128 * Bit 31:04 - Reserved
130 * Note: Assumed Russia Work with Wi-Fi FW/OTP definitions
132 static void wifi_dsm_ukrane_russia_11ax_enable(void *args)
134 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
136 acpigen_write_return_integer(dsm_config->enablement_11ax);
140 * Function 7: Control Enablement UNII-4 over certificate modules
142 static void wifi_dsm_unii4_control_enable(void *args)
144 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
146 acpigen_write_return_integer(dsm_config->unii_4);
150 * Function 10: Energy Detection Threshold (EDT)
151 * Bits 0-3: EDT revision - Default 0
153 * Bits 4-5: Reserved - Should be 0
155 * Bit 6: HB EDT Level. 5 GHz ETSI - EDT Level change - Default 0
156 * 0 - Disable EDT optimization for ETSI HB
157 * 1 - Enable EDT optimization for ETSI HB
159 * Bits 7-8: Reserved - Should be 0
161 * Bit 9: UHB EDT Level. 6 GHz FCC - EDT Level change - Default 0
162 * 0 - Disable EDT optimization for FCC UHB
163 * 1 - Enable EDT optimization for FCC UHB
165 * Bit 10-12: Reserved - Default 0
167 * Bit 13: EDT_En_HB_5G2/3 - Default 0
168 * 0 - Disable EDT optimization for HB_5G2/3
169 * 1 - Enable EDT optimization for HB_5G2/3
171 * Bit 14: EDT_En_HB_5G4 - Default 0
172 * 0 - Disable EDT optimization for HB_5G4
173 * 1 - Enable EDT optimization for HB_5G4
175 * Bit 15: EDT_En_HB_5G6 - Default 0
176 * 0 - Disable EDT optimization for HB_5G6
177 * 1 - Enable EDT optimization for HB_5G6
179 * Bit 16: EDT_En_HB_5G8/9 - Default 0
180 * 0 - Disable EDT optimization for HB_5G8/9
181 * 1 - Enable EDT optimization for HB_5G8/9
183 * Bit 17: EDT_En_UHB_6G1 - Default 0
184 * 0 - Disable EDT optimization for UHB_6G1
185 * 1 - Enable EDT optimization for UHB_6G1
187 * Bit 18: EDT_En_UHB_6G3 - Default 0
188 * 0 - Disable EDT optimization for UHB_6G3
189 * 1 - Enable EDT optimization for UHB_6G3
191 * Bit 19: EDT_En_UHB_6G5 - Default 0
192 * 0 - Disable EDT optimization for UHB_6G5
193 * 1 - Enable EDT optimization for UHB_6G5
195 * Bit 20: EDT_En_UHB_6G6 - Default 0
196 * 0 - Disable EDT optimization for UHB_6G6
197 * 1 - Enable EDT optimization for UHB_6G6
199 * Bit 21: EDT_En_UHB_6G8 - Default 0
200 * 0 - Disable EDT optimization for UHB_6G8
201 * 1 - Enable EDT optimization for UHB_6G8
203 * Bit 22: EDT_En_UHB_7G0 - Default 0
204 * 0 - Disable EDT optimization for UHB_7G0
205 * 1 - Enable EDT optimization for UHB_7G0
207 * Bits 23-31: Reserved - Should be 0
209 static void wifi_dsm_energy_detection_threshold(void *args)
211 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
213 acpigen_write_return_integer(dsm_config->energy_detection_threshold);
217 * Function 11: RFI mitigation
218 * Bit 0:
219 * 0 - DLVR RFIm enabled (default)
220 * 1 - DLVR RFIm disabled
222 * Bit 1:
223 * 0 - DDR RFIm enabled (default)
224 * 1 - DDR RFIm disabled
226 * Bits 2-31: Reserved - Should be 0
229 static void wifi_dsm_rfi_mitigation(void *args)
231 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
233 acpigen_write_return_integer(dsm_config->rfi_mitigation);
237 * Function 12: Control Enablement 802.11be on certificated modules
238 * Bit 0
239 * 0 - 11BE disabled for China Mainland
240 * 1 - 11BE enabled for China Mainland
242 * Bit 1
243 * 0 - 11BE disabled for South Korea
244 * 1 - 11BE enabled for South Korea
246 * Bit 2:27 - Reserved (shall be set to zeroes)
248 * Bit 28:31 - 11BE enablement revision
251 static void wifi_dsm_11be_country_enablement(void *args)
253 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
255 acpigen_write_return_integer(dsm_config->enablement_11be);
258 static void wifi_dsm_ddrrfim_func3_cb(void *ptr)
260 const bool is_cnvi_ddr_rfim_enabled = *(bool *)ptr;
261 acpigen_write_return_integer(is_cnvi_ddr_rfim_enabled ? 0 : 1);
264 static void (*wifi_dsm_callbacks[])(void *) = {
265 NULL, /* Function 0 */
266 wifi_dsm_srd_active_channels, /* Function 1 */
267 wifi_dsm_indonasia_5Ghz_band_enable, /* Function 2 */
268 wifi_dsm_supported_ultra_high_band, /* Function 3 */
269 wifi_dsm_regulatory_configurations, /* Function 4 */
270 wifi_dsm_uart_configurations, /* Function 5 */
271 wifi_dsm_ukrane_russia_11ax_enable, /* Function 6 */
272 wifi_dsm_unii4_control_enable, /* Function 7 */
273 NULL, /* Function 8 */
274 NULL, /* Function 9 */
275 wifi_dsm_energy_detection_threshold, /* Function 10 */
276 wifi_dsm_rfi_mitigation, /* Function 11 */
277 wifi_dsm_11be_country_enablement, /* Function 12 */
281 * The current DSM2 table is only exporting one function (function 3), some more
282 * functions are reserved so marking them NULL.
284 static void (*wifi_dsm2_callbacks[])(void *) = {
285 NULL, /* Function 0 */
286 NULL, /* Function 1 */
287 NULL, /* Function 2 */
288 wifi_dsm_ddrrfim_func3_cb, /* Function 3 */
291 static const uint8_t *sar_fetch_set(const struct sar_profile *sar, size_t set_num)
293 const uint8_t *sar_table = &sar->sar_table[0];
295 return sar_table + (sar->chains_count * sar->subbands_count * set_num);
298 static const uint8_t *wgds_fetch_set(struct geo_profile *wgds, size_t set_num)
300 const uint8_t *wgds_table = &wgds->wgds_table[0];
302 return wgds_table + (wgds->bands_count * set_num);
305 static const uint8_t *ppag_fetch_set(struct gain_profile *ppag, size_t set_num)
307 const uint8_t *ppag_table = &ppag->ppag_table[0];
309 return ppag_table + (ppag->bands_count * set_num);
312 static void sar_emit_wrds(const struct sar_profile *sar)
314 int i;
315 size_t package_size, table_size;
316 const uint8_t *set;
318 if (sar == NULL)
319 return;
322 * Name ("WRDS", Package () {
323 * Revision,
324 * Package () {
325 * Domain Type, // 0x7:WiFi
326 * WiFi SAR BIOS, // BIOS SAR Enable/disable
327 * SAR Table Set // Set#1 of SAR Table
329 * })
331 if (sar->revision > MAX_SAR_REVISION) {
332 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
333 return;
336 acpigen_write_name("WRDS");
337 acpigen_write_package(2);
338 acpigen_write_dword(sar->revision);
340 table_size = sar->chains_count * sar->subbands_count;
341 /* Emit 'Domain Type' + 'WiFi SAR Enable' + Set#1 */
342 package_size = 1 + 1 + table_size;
343 acpigen_write_package(package_size);
344 acpigen_write_dword(DOMAIN_TYPE_WIFI);
345 acpigen_write_dword(1);
347 set = sar_fetch_set(sar, 0);
348 for (i = 0; i < table_size; i++)
349 acpigen_write_byte(set[i]);
351 acpigen_write_package_end();
352 acpigen_write_package_end();
355 static void sar_emit_ewrd(const struct sar_profile *sar)
357 int i;
358 size_t package_size, set_num, table_size;
359 const uint8_t *set;
361 if (sar == NULL)
362 return;
365 * Name ("EWRD", Package () {
366 * Revision,
367 * Package () {
368 * Domain Type, // 0x7:WiFi
369 * Dynamic SAR Enable, // Dynamic SAR Enable/disable
370 * Extended SAR sets, // Number of optional SAR table sets
371 * SAR Table Set, // Set#2 of SAR Table
372 * SAR Table Set, // Set#3 of SAR Table
373 * SAR Table Set // Set#4 of SAR Table
375 * })
377 if (sar->revision > MAX_SAR_REVISION) {
378 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
379 return;
382 if (sar->dsar_set_count == 0) {
383 printk(BIOS_WARNING, "DSAR set count is 0\n");
384 return;
387 acpigen_write_name("EWRD");
388 acpigen_write_package(2);
389 acpigen_write_dword(sar->revision);
391 table_size = sar->chains_count * sar->subbands_count;
393 * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Extended SAR sets count'
394 * + number of bytes for Set#2 & 3 & 4
396 package_size = 1 + 1 + 1 + table_size * MAX_DSAR_SET_COUNT;
397 acpigen_write_package(package_size);
398 acpigen_write_dword(DOMAIN_TYPE_WIFI);
399 acpigen_write_dword(1);
400 acpigen_write_dword(sar->dsar_set_count);
402 for (set_num = 1; set_num <= sar->dsar_set_count; set_num++) {
403 set = sar_fetch_set(sar, set_num);
404 for (i = 0; i < table_size; i++)
405 acpigen_write_byte(set[i]);
408 /* wifi driver always expects 3 DSAR sets */
409 for (i = 0; i < (table_size * (MAX_DSAR_SET_COUNT - sar->dsar_set_count)); i++)
410 acpigen_write_byte(0);
412 acpigen_write_package_end();
413 acpigen_write_package_end();
416 static void sar_emit_wgds(struct geo_profile *wgds)
418 int i;
419 size_t package_size, set_num;
420 const uint8_t *set;
422 if (wgds == NULL)
423 return;
426 * Name ("WGDS", Package() {
427 * Revision,
428 * Package() {
429 * DomainType, // 0x7:WiFi
430 * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max
431 * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset
432 * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset
433 * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max
434 * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset
435 * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset
436 * WgdsWiFiSarDeltaGroup1PowerMax3, // Group 1 FCC 6000-7000 Max
437 * WgdsWiFiSarDeltaGroup1PowerChainA3, // Group 1 FCC 6000-7000 A Offset
438 * WgdsWiFiSarDeltaGroup1PowerChainB3, // Group 1 FCC 6000-7000 B Offset
439 * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max
440 * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset
441 * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset
442 * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max
443 * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset
444 * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset
445 * WgdsWiFiSarDeltaGroup2PowerMax3, // Group 2 EC Jap 6000-7000 Max
446 * WgdsWiFiSarDeltaGroup2PowerChainA3, // Group 2 EC Jap 6000-7000 A Offset
447 * WgdsWiFiSarDeltaGroup2PowerChainB3, // Group 2 EC Jap 6000-7000 B Offset
448 * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max
449 * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset
450 * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset
451 * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max
452 * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset
453 * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset
454 * WgdsWiFiSarDeltaGroup3PowerMax3, // Group 3 ROW 6000-7000 Max
455 * WgdsWiFiSarDeltaGroup3PowerChainA3, // Group 3 ROW 6000-7000 A Offset
456 * WgdsWiFiSarDeltaGroup3PowerChainB3, // Group 3 ROW 6000-7000 B Offset
458 * })
460 if (wgds->revision > MAX_GEO_OFFSET_REVISION) {
461 printk(BIOS_ERR, "Invalid WGDS revision: %d\n", wgds->revision);
462 return;
465 package_size = 1 + wgds->chains_count * wgds->bands_count;
467 acpigen_write_name("WGDS");
468 acpigen_write_package(2);
469 acpigen_write_dword(wgds->revision);
470 /* Emit 'Domain Type' +
471 * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS)
473 acpigen_write_package(package_size);
474 acpigen_write_dword(DOMAIN_TYPE_WIFI);
476 for (set_num = 0; set_num < wgds->chains_count; set_num++) {
477 set = wgds_fetch_set(wgds, set_num);
478 for (i = 0; i < wgds->bands_count; i++)
479 acpigen_write_byte(set[i]);
482 acpigen_write_package_end();
483 acpigen_write_package_end();
486 static void sar_emit_ppag(struct gain_profile *ppag)
488 int i;
489 size_t package_size, set_num;
490 const uint8_t *set;
492 if (ppag == NULL)
493 return;
496 * Name ("PPAG", Package () {
497 * Revision,
498 * Package () {
499 * Domain Type, // 0x7:WiFi
500 * PPAG Mode, // Defines the mode of ANT_gain control to be used
501 * ANT_gain Table Chain A // Defines the ANT_gain in dBi for chain A
502 * ANT_gain Table Chain B // Defines the ANT_gain in dBi for chain B
504 * })
506 if (ppag->revision > MAX_ANT_GAINS_REVISION) {
507 printk(BIOS_ERR, "Invalid PPAG revision: %d\n", ppag->revision);
508 return;
511 package_size = 1 + 1 + ppag->chains_count * ppag->bands_count;
513 acpigen_write_name("PPAG");
514 acpigen_write_package(2);
515 acpigen_write_dword(ppag->revision);
516 acpigen_write_package(package_size);
517 acpigen_write_dword(DOMAIN_TYPE_WIFI);
518 acpigen_write_dword(ppag->mode);
520 for (set_num = 0; set_num < ppag->chains_count; set_num++) {
521 set = ppag_fetch_set(ppag, set_num);
522 for (i = 0; i < ppag->bands_count; i++)
523 acpigen_write_byte(set[i]);
526 acpigen_write_package_end();
527 acpigen_write_package_end();
530 static void sar_emit_wtas(struct avg_profile *wtas)
532 int i;
533 size_t package_size;
535 if (wtas == NULL)
536 return;
539 * Name (WTAS, Package() {
541 * Revision,
542 * Package()
544 * DomainType, // 0x7:WiFi
545 * WifiTASSelection, // Enable/Disable the TAS feature
546 * WifiTASListEntries, // No. of blocked countries not approved by OEM to
547 * BlockedListEntry1, support this feature
548 * BlockedListEntry2,
549 * BlockedListEntry3,
550 * BlockedListEntry4,
551 * BlockedListEntry5,
552 * BlockedListEntry6,
553 * BlockedListEntry7,
554 * BlockedListEntry8,
555 * BlockedListEntry9,
556 * BlockedListEntry10,
557 * BlockedListEntry11,
558 * BlockedListEntry12,
559 * BlockedListEntry13,
560 * BlockedListEntry14,
561 * BlockedListEntry15,
562 * BlockedListEntry16,
564 * })
566 package_size = 1 + 1 + 1 + MAX_DENYLIST_ENTRY;
568 acpigen_write_name("WTAS");
569 acpigen_write_package(2);
570 acpigen_write_dword(wtas->revision);
571 acpigen_write_package(package_size);
572 acpigen_write_dword(DOMAIN_TYPE_WIFI);
573 acpigen_write_byte(wtas->tas_selection);
574 acpigen_write_byte(wtas->tas_list_size);
575 for (i = 0; i < MAX_DENYLIST_ENTRY; i++)
576 acpigen_write_word(wtas->deny_list_entry[i]);
578 acpigen_write_package_end();
579 acpigen_write_package_end();
582 static void sar_emit_brds(const struct bsar_profile *bsar)
584 size_t package_size, table_size;
585 const uint8_t *set;
587 if (bsar == NULL)
588 return;
591 * Name ("BRDS", Package () {
592 * Revision,
593 * Package () {
594 * Domain Type, // 0x12:Bluetooth
595 * Bluetooth SAR BIOS, // BIOS SAR Enable/disable
596 * Bluetooth Increase Power Mode // SAR Limitation Enable/disable
597 * Bluetooth SAR Power Restriction, // 00000000 - 0dBm
598 * // 11111111 - 31.875dBm
599 * // (Step 0.125dBm)
600 * Bluetooth SAR Table // SAR Tx power limit table
602 * })
604 if (bsar->revision == 0 || bsar->revision > MAX_BSAR_REVISION) {
605 printk(BIOS_ERR, "Unsupported BSAR table revision: %d\n",
606 bsar->revision);
607 return;
610 acpigen_write_name("BRDS");
611 acpigen_write_package(2);
612 acpigen_write_dword(bsar->revision);
614 if (bsar->revision == 1)
615 table_size = sizeof(bsar->revs.rev1);
616 else
617 table_size = sizeof(bsar->revs.rev2);
620 * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Increase Power Mode'
621 * + ('SAR Power Restriction' + SAR table) | (Chain A and B SAR tables).
623 package_size = 1 + 1 + 1 + table_size;
624 acpigen_write_package(package_size);
625 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
626 acpigen_write_dword(1);
627 acpigen_write_dword(bsar->increased_power_mode_limitation);
629 set = (const uint8_t *)&bsar->revs;
630 for (int i = 0; i < table_size; i++)
631 acpigen_write_byte(set[i]);
633 acpigen_write_package_end();
634 acpigen_write_package_end();
637 static void sar_emit_wbem(const struct wbem_profile *wbem)
639 if (wbem == NULL)
640 return;
643 * Name ("WBEM", Package() {
645 * Revision,
646 * Package()
648 * DomainType, // 0x7:WiFi
649 * bandwidth_320mhz_country_enablement // 0 Disabled
650 * // 1 Japan Enabled
651 * // 2 South Korea Enabled
652 * // 3 Japan + South Korea Enabled
654 } })
656 if (wbem->revision != WBEM_REVISION) {
657 printk(BIOS_ERR, "Unsupported WBEM table revision: %d\n",
658 wbem->revision);
659 return;
662 acpigen_write_name("WBEM");
663 acpigen_write_package(2);
664 acpigen_write_dword(wbem->revision);
666 acpigen_write_package(2);
667 acpigen_write_dword(DOMAIN_TYPE_WIFI);
668 acpigen_write_dword(wbem->bandwidth_320mhz_country_enablement);
670 acpigen_write_package_end();
671 acpigen_write_package_end();
674 static void sar_emit_bpag(const struct bpag_profile *bpag)
676 if (bpag == NULL)
677 return;
680 * Name ("BPAG", Package () {
681 * Revision,
682 * Package () {
683 * Domain Type, // 0x12:Bluetooth
684 * Bluetooth Per-Platform Antenna Gain Mode
686 * })
688 if (bpag->revision == 0 || bpag->revision > BPAG_REVISION) {
689 printk(BIOS_ERR, "Unsupported BPAG table revision: %d\n",
690 bpag->revision);
691 return;
694 acpigen_write_name("BPAG");
695 acpigen_write_package(2);
696 acpigen_write_dword(bpag->revision);
699 * Emit 'Domain Type' + 'Antenna Gain Mode'
701 acpigen_write_package(2);
702 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
703 acpigen_write_dword(bpag->antenna_gain_country_enablement);
705 acpigen_write_package_end();
706 acpigen_write_package_end();
709 static void sar_emit_bbfb(const struct bbfb_profile *bbfb)
711 if (bbfb == NULL)
712 return;
715 * Name ("BBFB", Package () {
716 * Revision,
717 * Package () {
718 * Domain Type, // 0x12:Bluetooth
719 * By Pass Enabled // Enable ByPass
721 * })
723 if (bbfb->revision != BBFB_REVISION) {
724 printk(BIOS_ERR, "Unsupported BBFB table revision: %d\n",
725 bbfb->revision);
726 return;
729 acpigen_write_name("BBFB");
730 acpigen_write_package(2);
731 acpigen_write_dword(bbfb->revision);
734 * Emit 'Domain Type' + 'Enable ByPass'
736 acpigen_write_package(2);
737 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
738 acpigen_write_dword(bbfb->enable_quad_filter_bypass);
740 acpigen_write_package_end();
741 acpigen_write_package_end();
744 static void sar_emit_bdcm(const struct bdcm_profile *bdcm)
746 if (bdcm == NULL)
747 return;
750 * Name ("BDCM", Package () {
751 * Revision,
752 * Package () {
753 * Domain Type, // 0x12:Bluetooth
754 * Dual Chain Mode
756 * })
758 if (bdcm->revision != BDCM_REVISION) {
759 printk(BIOS_ERR, "Unsupported BDCM table revision: %d\n",
760 bdcm->revision);
761 return;
764 acpigen_write_name("BDCM");
765 acpigen_write_package(2);
766 acpigen_write_dword(bdcm->revision);
769 * Emit 'Domain Type' + 'Dual Chain Mode'
771 acpigen_write_package(2);
772 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
773 acpigen_write_dword(bdcm->dual_chain_mode);
775 acpigen_write_package_end();
776 acpigen_write_package_end();
779 static void sar_emit_bbsm(const struct bbsm_profile *bbsm)
781 if (bbsm == NULL)
782 return;
785 * Name ("BBSM", Package () {
786 * Revision,
787 * Package () {
788 * Domain Type, // 0x12:Bluetooth
789 * Bluetooth Bands Selection
791 * })
793 if (bbsm->revision != BBSM_REVISION) {
794 printk(BIOS_ERR, "Unsupported BBSM table revision: %d\n",
795 bbsm->revision);
796 return;
799 acpigen_write_name("BBSM");
800 acpigen_write_package(2);
801 acpigen_write_dword(bbsm->revision);
804 * Emit 'Domain Type' + 'Bluetooth Bands Selection'
806 acpigen_write_package(2);
807 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
808 acpigen_write_dword(bbsm->bands_selection);
810 acpigen_write_package_end();
811 acpigen_write_package_end();
814 static void sar_emit_bucs(const struct bucs_profile *bucs)
816 if (bucs == NULL)
817 return;
820 * Name ("BUCS", Package () {
821 * Revision,
822 * Package () {
823 * Domain Type, // 0x12:Bluetooth
824 * UHB country selection bits
826 * })
828 if (bucs->revision != BUCS_REVISION) {
829 printk(BIOS_ERR, "Unsupported BUCS table revision: %d\n",
830 bucs->revision);
831 return;
834 acpigen_write_name("BUCS");
835 acpigen_write_package(2);
836 acpigen_write_dword(bucs->revision);
839 * Emit 'Domain Type' + 'UHB country selection bits'
841 acpigen_write_package(2);
842 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
843 acpigen_write_dword(bucs->uhb_country_selection);
845 acpigen_write_package_end();
846 acpigen_write_package_end();
849 static void sar_emit_bdmm(const struct bdmm_profile *bdmm)
851 if (bdmm == NULL)
852 return;
855 * Name ("BDMM", Package () {
856 * Revision,
857 * Package () {
858 * Domain Type, // 0x12:Bluetooth
859 * Dual Mac Enable
861 * })
863 if (bdmm->revision != BDMM_REVISION) {
864 printk(BIOS_ERR, "Unsupported BDMM table revision: %d\n",
865 bdmm->revision);
866 return;
869 acpigen_write_name("BDMM");
870 acpigen_write_package(2);
871 acpigen_write_dword(bdmm->revision);
874 * Emit 'Domain Type' + 'Dual Mac Enable'
876 acpigen_write_package(2);
877 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
878 acpigen_write_dword(bdmm->dual_mac_enable);
880 acpigen_write_package_end();
881 acpigen_write_package_end();
884 static void sar_emit_ebrd(const struct ebrd_profile *ebrd)
886 if (ebrd == NULL)
887 return;
889 size_t package_size, table_size;
890 const uint8_t *set;
893 * Name ("EBRD", Package () {
894 * Revision,
895 * Package () {
896 * Domain Type, // 0x12:Bluetooth
897 * Dynamic SAR Enable,
898 * Number of Optional SAR,
899 * Three SAR Sets
901 * })
903 if (ebrd->revision != EBRD_REVISION) {
904 printk(BIOS_ERR, "Unsupported EBRD table revision: %d\n",
905 ebrd->revision);
906 return;
909 acpigen_write_name("EBRD");
910 acpigen_write_package(2);
911 acpigen_write_dword(ebrd->revision);
914 * Emit 'Domain Type' + 'Dynamic Sar Enabled' + 'Number of Optional SAR' +
915 * 'Three SAR Sets'
917 table_size = sizeof(*ebrd) - offsetof(struct ebrd_profile, sar_table_sets);
918 package_size = 1 + 1 + 1 + table_size;
919 acpigen_write_package(package_size);
920 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
921 acpigen_write_dword(ebrd->dynamic_sar_enable);
922 acpigen_write_dword(ebrd->number_of_optional_sar);
924 set = (const uint8_t *)&ebrd->sar_table_sets;
925 for (size_t i = 0; i < table_size; i++)
926 acpigen_write_byte(set[i]);
928 acpigen_write_package_end();
929 acpigen_write_package_end();
932 static void sar_emit_wpfc(const struct wpfc_profile *wpfc)
934 if (wpfc == NULL)
935 return;
938 * Name ("WPFC", Package() {
940 * Revision,
941 * Package()
943 * DomainType, // 0x7:WiFi
944 * Chain A Filter Platform Configuration
945 * Chain B Filter Platform Configuration
946 * Chain C Filter Platform Configuration
947 * Chain D Filter Platform Configuration
949 } })
951 if (wpfc->revision != WPFC_REVISION) {
952 printk(BIOS_ERR, "Unsupported WPFC table revision: %d\n",
953 wpfc->revision);
954 return;
957 acpigen_write_name("WPFC");
958 acpigen_write_package(2);
959 acpigen_write_dword(wpfc->revision);
961 acpigen_write_package(5);
962 acpigen_write_dword(DOMAIN_TYPE_WIFI);
963 acpigen_write_byte(wpfc->filter_cfg_chain_a);
964 acpigen_write_byte(wpfc->filter_cfg_chain_b);
965 acpigen_write_byte(wpfc->filter_cfg_chain_c);
966 acpigen_write_byte(wpfc->filter_cfg_chain_d);
968 acpigen_write_package_end();
969 acpigen_write_package_end();
972 static void sar_emit_dsbr(const struct dsbr_profile *dsbr, enum sar_domain domain)
974 if (dsbr == NULL)
975 return;
978 * Name ("DSBR", Package() {
980 * Revision,
981 * Package()
983 * DomainType, // 0x7:WiFi
984 * BRI Resistor Value // in Ohm
986 } })
988 if (dsbr->revision != DSBR_REVISION) {
989 printk(BIOS_ERR, "Unsupported DSBR table revision: %d\n",
990 dsbr->revision);
991 return;
994 acpigen_write_name("DSBR");
995 acpigen_write_package(2);
996 acpigen_write_dword(dsbr->revision);
998 acpigen_write_package(2);
999 acpigen_write_dword(domain);
1000 acpigen_write_dword(dsbr->bri_resistor_value);
1002 acpigen_write_package_end();
1003 acpigen_write_package_end();
1006 static void emit_wifi_sar_acpi_structures(const struct device *dev,
1007 union wifi_sar_limits *sar_limits)
1010 * If device type is PCI, ensure that the device has Intel vendor ID. CBFS SAR and SAR
1011 * ACPI tables are currently used only by Intel WiFi devices.
1013 if (dev->path.type == DEVICE_PATH_PCI && dev->vendor != PCI_VID_INTEL)
1014 return;
1016 sar_emit_wrds(sar_limits->sar);
1017 sar_emit_ewrd(sar_limits->sar);
1018 sar_emit_wgds(sar_limits->wgds);
1019 sar_emit_ppag(sar_limits->ppag);
1020 sar_emit_wtas(sar_limits->wtas);
1021 sar_emit_wbem(sar_limits->wbem);
1022 sar_emit_wpfc(sar_limits->wpfc);
1023 sar_emit_dsbr(sar_limits->dsbr, DOMAIN_TYPE_WIFI);
1026 static void wifi_ssdt_write_device(const struct device *dev, const char *path)
1028 /* Device */
1029 acpigen_write_device(path);
1030 acpi_device_write_uid(dev);
1032 if (dev->chip_ops)
1033 acpigen_write_name_string("_DDN", dev->chip_ops->name);
1035 /* Address */
1036 acpigen_write_ADR_pci_device(dev);
1038 acpigen_pop_len(); /* Device */
1041 static void wifi_ssdt_write_properties(const struct device *dev, const char *scope)
1043 const struct drivers_wifi_generic_config *config = dev->chip_info;
1045 bool is_cnvi_ddr_rfim_enabled = config && config->enable_cnvi_ddr_rfim;
1047 /* Scope */
1048 acpigen_write_scope(scope);
1050 if (config) {
1051 /* Wake capabilities */
1052 acpigen_write_PRW(config->wake, ACPI_S3);
1054 /* Add _DSD for DmaProperty property. */
1055 if (config->add_acpi_dma_property)
1056 acpi_device_add_dma_property(NULL);
1059 /* Fill regulatory domain structure */
1060 if (CONFIG(HAVE_REGULATORY_DOMAIN)) {
1062 * Name ("WRDD", Package () {
1063 * WRDD_REVISION, // Revision
1064 * Package () {
1065 * DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
1066 * wifi_regulatory_domain() // Country Identifier
1068 * })
1070 acpigen_write_name("WRDD");
1071 acpigen_write_package(2);
1072 acpigen_write_integer(WRDD_REVISION);
1073 acpigen_write_package(2);
1074 acpigen_write_dword(DOMAIN_TYPE_WIFI);
1075 acpigen_write_dword(wifi_regulatory_domain());
1076 acpigen_pop_len();
1077 acpigen_pop_len();
1080 struct dsm_uuid dsm_ids[MAX_DSM_FUNCS];
1082 /* Retrieve the SAR limits data */
1083 union wifi_sar_limits sar_limits = {0};
1084 bool sar_loaded = false;
1085 if (CONFIG(USE_SAR)) {
1086 if (get_wifi_sar_limits(&sar_limits) < 0)
1087 printk(BIOS_ERR, "failed getting SAR limits!\n");
1088 else
1089 sar_loaded = true;
1092 /* Fill Wifi SAR related ACPI structures */
1093 uint8_t dsm_count = 0;
1094 if (sar_loaded) {
1095 emit_wifi_sar_acpi_structures(dev, &sar_limits);
1097 struct dsm_profile *dsm = sar_limits.dsm;
1098 if (dsm && dsm->supported_functions != 0) {
1099 for (int i = 1; i < ARRAY_SIZE(wifi_dsm_callbacks); i++)
1100 if (!(dsm->supported_functions & (1 << i)))
1101 wifi_dsm_callbacks[i] = NULL;
1103 dsm_ids[dsm_count].uuid = ACPI_DSM_OEM_WIFI_UUID;
1104 dsm_ids[dsm_count].callbacks = &wifi_dsm_callbacks[0];
1105 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm_callbacks);
1106 dsm_ids[dsm_count].arg = dsm;
1107 dsm_count++;
1111 if (is_cnvi_ddr_rfim_enabled) {
1112 dsm_ids[dsm_count].uuid = ACPI_DSM_RFIM_WIFI_UUID;
1113 dsm_ids[dsm_count].callbacks = &wifi_dsm2_callbacks[0];
1114 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm2_callbacks);
1115 dsm_ids[dsm_count].arg = &is_cnvi_ddr_rfim_enabled;
1116 dsm_count++;
1119 acpigen_write_dsm_uuid_arr(dsm_ids, dsm_count);
1122 * Fill MediaTek MTCL related ACPI structure iff the device type is PCI,
1123 * the device has the MediaTek vendor ID, and the MTCL feature is
1124 * configured.
1126 if (CONFIG(USE_MTCL)) {
1127 if (dev->path.type == DEVICE_PATH_PCI &&
1128 dev->vendor == PCI_VID_MEDIATEK)
1129 write_mtcl_function();
1132 acpigen_write_scope_end(); /* Scope */
1134 /* Fill Bluetooth companion SAR related ACPI structures */
1135 if (sar_loaded && is_dev_enabled(config->bluetooth_companion)) {
1136 const char *path = acpi_device_path(config->bluetooth_companion);
1137 if (path) { /* Bluetooth device under USB Hub scope or PCIe root port */
1138 acpigen_write_scope(path);
1139 sar_emit_brds(sar_limits.bsar);
1140 sar_emit_bpag(sar_limits.bpag);
1141 sar_emit_bbfb(sar_limits.bbfb);
1142 sar_emit_bdcm(sar_limits.bdcm);
1143 sar_emit_bbsm(sar_limits.bbsm);
1144 sar_emit_bucs(sar_limits.bucs);
1145 sar_emit_bdmm(sar_limits.bdmm);
1146 sar_emit_ebrd(sar_limits.ebrd);
1147 sar_emit_dsbr(sar_limits.dsbr, DOMAIN_TYPE_BLUETOOTH);
1148 acpigen_write_scope_end();
1149 } else {
1150 printk(BIOS_ERR, "Failed to get %s Bluetooth companion ACPI path\n",
1151 dev_path(dev));
1155 if (sar_loaded)
1156 free(sar_limits.sar);
1158 printk(BIOS_INFO, "%s: %s %s\n", scope, dev->chip_ops ? dev->chip_ops->name : "",
1159 dev_path(dev));
1162 void wifi_pcie_fill_ssdt(const struct device *dev)
1164 const char *path;
1166 path = acpi_device_path(dev);
1167 if (!path)
1168 return;
1170 wifi_ssdt_write_device(dev, path);
1171 wifi_ssdt_write_properties(dev, path);
1174 const char *wifi_pcie_acpi_name(const struct device *dev)
1176 static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN];
1178 /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */
1179 snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X",
1180 (dev_path_encode(dev) & 0xff));
1181 return wifi_acpi_name;
1184 void wifi_cnvi_fill_ssdt(const struct device *dev)
1186 const char *path;
1187 if (!dev)
1188 return;
1190 path = acpi_device_path(dev->upstream->dev);
1191 if (!path)
1192 return;
1194 wifi_ssdt_write_properties(dev, path);