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>
14 #include "wifi_private.h"
16 /* WIFI Domain type */
17 #define DOMAIN_TYPE_WIFI 0x7
19 /* Maximum number DSM UUID bifurcations in _DSM */
20 #define MAX_DSM_FUNCS 2
23 * WIFI ACPI NAME = "WF" + hex value of last 8 bits of dev_path_encode + '\0'
24 * The above representation returns unique and consistent name every time
25 * generate_wifi_acpi_name is invoked. The last 8 bits of dev_path_encode is
26 * chosen since it contains the bus address of the device.
28 #define WIFI_ACPI_NAME_MAX_LEN 5
30 /* Unique ID for the WIFI _DSM */
31 #define ACPI_DSM_OEM_WIFI_UUID "F21202BF-8F78-4DC6-A5B3-1F738E285ADE"
33 /* Unique ID for CnviDdrRfim entry in WIFI _DSM */
34 #define ACPI_DSM_RFIM_WIFI_UUID "7266172C-220B-4B29-814F-75E4DD26B5FD"
36 __weak
int get_wifi_sar_limits(union wifi_sar_limits
*sar_limits
)
42 * Function 1: Allow PC OEMs to set ETSI 5.8GHz SRD in Passive/Disabled ESTI SRD
43 * Channels: 149, 153, 157, 161, 165
44 * 0 - ETSI 5.8GHz SRD active scan
45 * 1 - ETSI 5.8GHz SRD passive scan
46 * 2 - ETSI 5.8GHz SRD disabled
48 static void wifi_dsm_srd_active_channels(void *args
)
50 struct dsm_profile
*dsm_config
= (struct dsm_profile
*)args
;
52 acpigen_write_return_integer(dsm_config
->disable_active_sdr_channels
);
56 * Function 2 : Supported Indonesia 5.15-5.35 GHz Band
57 * 0 - Set 5.115-5.35GHz to Disable in Indonesia
58 * 1 - Set 5.115-5.35GHz to Enable (Passive) in Indonesia
61 static void wifi_dsm_indonasia_5Ghz_band_enable(void *args
)
63 struct dsm_profile
*dsm_config
= (struct dsm_profile
*)args
;
65 acpigen_write_return_integer(dsm_config
->support_indonesia_5g_band
);
69 * Function 3: Support Wi-Fi 6 11ax Rev 2 new channels on 6-7 GHz.
71 * 0 - No override; use device settings 0
72 * 1 - Force disable all countries that are not defined in the following bits
75 * 0 No override; USA 6GHz disable 0
76 * 1 6GHz allowed in the USA (enabled only if the device is certified to the USA)
78 static void wifi_dsm_supported_ultra_high_band(void *args
)
80 struct dsm_profile
*dsm_config
= (struct dsm_profile
*)args
;
82 acpigen_write_return_integer(dsm_config
->support_ultra_high_band
);
86 * Function 4: Regulatory Special Configurations Enablements
88 static void wifi_dsm_regulatory_configurations(void *args
)
90 struct dsm_profile
*dsm_config
= (struct dsm_profile
*)args
;
92 acpigen_write_return_integer(dsm_config
->regulatory_configurations
);
96 * Function 5: M.2 UART Interface Configuration
98 static void wifi_dsm_uart_configurations(void *args
)
100 struct dsm_profile
*dsm_config
= (struct dsm_profile
*)args
;
102 acpigen_write_return_integer(dsm_config
->uart_configurations
);
106 * Function 6: Control Enablement 11ax on certificated modules
107 * Bit 0 - Apply changes to country Ukraine. 11Ax Setting within module certification
108 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
111 * Bit 1 - 11Ax Mode. Effective only if Bit 0 set to 1
112 * 0 - Disable 11Ax on country Ukraine [Default]
113 * 1 - Enable 11Ax on country Ukraine
115 * Bit 2 - Apply changes to country Russia. 11Ax Setting within module certification
116 * 0 - None. Work with Wi-Fi FW/OTP definitions [Default]
119 * Bit 3 - 11Ax Mode. Effective only if Bit 2 set to 1
120 * 0 - Disable 11Ax on country Russia [Default]
121 * 1 - Enable 11Ax on country Russia
123 * Bit 31:04 - Reserved
125 * Note: Assumed Russia Work with Wi-Fi FW/OTP definitions
127 static void wifi_dsm_ukrane_russia_11ax_enable(void *args
)
129 struct dsm_profile
*dsm_config
= (struct dsm_profile
*)args
;
131 acpigen_write_return_integer(dsm_config
->enablement_11ax
);
135 * Function 7: Control Enablement UNII-4 over certificate modules
137 static void wifi_dsm_unii4_control_enable(void *args
)
139 struct dsm_profile
*dsm_config
= (struct dsm_profile
*)args
;
141 acpigen_write_return_integer(dsm_config
->unii_4
);
144 static void wifi_dsm_ddrrfim_func3_cb(void *ptr
)
146 const bool is_cnvi_ddr_rfim_enabled
= *(bool *)ptr
;
147 acpigen_write_return_integer(is_cnvi_ddr_rfim_enabled
? 1 : 0);
150 static void (*wifi_dsm_callbacks
[])(void *) = {
151 NULL
, /* Function 0 */
152 wifi_dsm_srd_active_channels
, /* Function 1 */
153 wifi_dsm_indonasia_5Ghz_band_enable
, /* Function 2 */
154 wifi_dsm_supported_ultra_high_band
, /* Function 3 */
155 wifi_dsm_regulatory_configurations
, /* Function 4 */
156 wifi_dsm_uart_configurations
, /* Function 5 */
157 wifi_dsm_ukrane_russia_11ax_enable
, /* Function 6 */
158 wifi_dsm_unii4_control_enable
, /* Function 7 */
162 * The current DSM2 table is only exporting one function (function 3), some more
163 * functions are reserved so marking them NULL.
165 static void (*wifi_dsm2_callbacks
[])(void *) = {
166 NULL
, /* Function 0 */
167 NULL
, /* Function 1 */
168 NULL
, /* Function 2 */
169 wifi_dsm_ddrrfim_func3_cb
, /* Function 3 */
172 static const uint8_t *sar_fetch_set(const struct sar_profile
*sar
, size_t set_num
)
174 const uint8_t *sar_table
= &sar
->sar_table
[0];
176 return sar_table
+ (sar
->chains_count
* sar
->subbands_count
* set_num
);
179 static const uint8_t *wgds_fetch_set(struct geo_profile
*wgds
, size_t set_num
)
181 const uint8_t *wgds_table
= &wgds
->wgds_table
[0];
183 return wgds_table
+ (wgds
->bands_count
* set_num
);
186 static const uint8_t *ppag_fetch_set(struct gain_profile
*ppag
, size_t set_num
)
188 const uint8_t *ppag_table
= &ppag
->ppag_table
[0];
190 return ppag_table
+ (ppag
->bands_count
* set_num
);
193 static void sar_emit_wrds(const struct sar_profile
*sar
)
196 size_t package_size
, table_size
;
203 * Name ("WRDS", Package () {
206 * Domain Type, // 0x7:WiFi
207 * WiFi SAR BIOS, // BIOS SAR Enable/disable
208 * SAR Table Set // Set#1 of SAR Table
212 if (sar
->revision
> MAX_SAR_REVISION
) {
213 printk(BIOS_ERR
, "Invalid SAR table revision: %d\n", sar
->revision
);
217 acpigen_write_name("WRDS");
218 acpigen_write_package(2);
219 acpigen_write_dword(sar
->revision
);
221 table_size
= sar
->chains_count
* sar
->subbands_count
;
222 /* Emit 'Domain Type' + 'WiFi SAR Enable' + Set#1 */
223 package_size
= 1 + 1 + table_size
;
224 acpigen_write_package(package_size
);
225 acpigen_write_dword(DOMAIN_TYPE_WIFI
);
226 acpigen_write_dword(1);
228 set
= sar_fetch_set(sar
, 0);
229 for (i
= 0; i
< table_size
; i
++)
230 acpigen_write_byte(set
[i
]);
232 acpigen_write_package_end();
233 acpigen_write_package_end();
236 static void sar_emit_ewrd(const struct sar_profile
*sar
)
239 size_t package_size
, set_num
, table_size
;
246 * Name ("EWRD", Package () {
249 * Domain Type, // 0x7:WiFi
250 * Dynamic SAR Enable, // Dynamic SAR Enable/disable
251 * Extended SAR sets, // Number of optional SAR table sets
252 * SAR Table Set, // Set#2 of SAR Table
253 * SAR Table Set, // Set#3 of SAR Table
254 * SAR Table Set // Set#4 of SAR Table
258 if (sar
->revision
> MAX_SAR_REVISION
) {
259 printk(BIOS_ERR
, "Invalid SAR table revision: %d\n", sar
->revision
);
263 if (sar
->dsar_set_count
== 0) {
264 printk(BIOS_WARNING
, "DSAR set count is 0\n");
268 acpigen_write_name("EWRD");
269 acpigen_write_package(2);
270 acpigen_write_dword(sar
->revision
);
272 table_size
= sar
->chains_count
* sar
->subbands_count
;
274 * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Extended SAR sets count'
275 * + number of bytes for Set#2 & 3 & 4
277 package_size
= 1 + 1 + 1 + table_size
* MAX_DSAR_SET_COUNT
;
278 acpigen_write_package(package_size
);
279 acpigen_write_dword(DOMAIN_TYPE_WIFI
);
280 acpigen_write_dword(1);
281 acpigen_write_dword(sar
->dsar_set_count
);
283 for (set_num
= 1; set_num
<= sar
->dsar_set_count
; set_num
++) {
284 set
= sar_fetch_set(sar
, set_num
);
285 for (i
= 0; i
< table_size
; i
++)
286 acpigen_write_byte(set
[i
]);
289 /* wifi driver always expects 3 DSAR sets */
290 for (i
= 0; i
< (table_size
* (MAX_DSAR_SET_COUNT
- sar
->dsar_set_count
)); i
++)
291 acpigen_write_byte(0);
293 acpigen_write_package_end();
294 acpigen_write_package_end();
297 static void sar_emit_wgds(struct geo_profile
*wgds
)
300 size_t package_size
, set_num
;
307 * Name ("WGDS", Package() {
310 * DomainType, // 0x7:WiFi
311 * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max
312 * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset
313 * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset
314 * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max
315 * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset
316 * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset
317 * WgdsWiFiSarDeltaGroup1PowerMax3, // Group 1 FCC 6000-7000 Max
318 * WgdsWiFiSarDeltaGroup1PowerChainA3, // Group 1 FCC 6000-7000 A Offset
319 * WgdsWiFiSarDeltaGroup1PowerChainB3, // Group 1 FCC 6000-7000 B Offset
320 * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max
321 * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset
322 * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset
323 * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max
324 * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset
325 * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset
326 * WgdsWiFiSarDeltaGroup2PowerMax3, // Group 2 EC Jap 6000-7000 Max
327 * WgdsWiFiSarDeltaGroup2PowerChainA3, // Group 2 EC Jap 6000-7000 A Offset
328 * WgdsWiFiSarDeltaGroup2PowerChainB3, // Group 2 EC Jap 6000-7000 B Offset
329 * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max
330 * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset
331 * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset
332 * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max
333 * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset
334 * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset
335 * WgdsWiFiSarDeltaGroup3PowerMax3, // Group 3 ROW 6000-7000 Max
336 * WgdsWiFiSarDeltaGroup3PowerChainA3, // Group 3 ROW 6000-7000 A Offset
337 * WgdsWiFiSarDeltaGroup3PowerChainB3, // Group 3 ROW 6000-7000 B Offset
341 if (wgds
->revision
> MAX_GEO_OFFSET_REVISION
) {
342 printk(BIOS_ERR
, "Invalid WGDS revision: %d\n", wgds
->revision
);
346 package_size
= 1 + wgds
->chains_count
* wgds
->bands_count
;
348 acpigen_write_name("WGDS");
349 acpigen_write_package(2);
350 acpigen_write_dword(wgds
->revision
);
351 /* Emit 'Domain Type' +
352 * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS)
354 acpigen_write_package(package_size
);
355 acpigen_write_dword(DOMAIN_TYPE_WIFI
);
357 for (set_num
= 0; set_num
< wgds
->chains_count
; set_num
++) {
358 set
= wgds_fetch_set(wgds
, set_num
);
359 for (i
= 0; i
< wgds
->bands_count
; i
++)
360 acpigen_write_byte(set
[i
]);
363 acpigen_write_package_end();
364 acpigen_write_package_end();
367 static void sar_emit_ppag(struct gain_profile
*ppag
)
370 size_t package_size
, set_num
;
377 * Name ("PPAG", Package () {
380 * Domain Type, // 0x7:WiFi
381 * PPAG Mode, // Defines the mode of ANT_gain control to be used
382 * ANT_gain Table Chain A // Defines the ANT_gain in dBi for chain A
383 * ANT_gain Table Chain B // Defines the ANT_gain in dBi for chain B
387 if (ppag
->revision
> MAX_ANT_GAINS_REVISION
) {
388 printk(BIOS_ERR
, "Invalid PPAG revision: %d\n", ppag
->revision
);
392 package_size
= 1 + 1 + ppag
->chains_count
* ppag
->bands_count
;
394 acpigen_write_name("PPAG");
395 acpigen_write_package(2);
396 acpigen_write_dword(ppag
->revision
);
397 acpigen_write_package(package_size
);
398 acpigen_write_dword(DOMAIN_TYPE_WIFI
);
399 acpigen_write_dword(ppag
->mode
);
401 for (set_num
= 0; set_num
< ppag
->chains_count
; set_num
++) {
402 set
= ppag_fetch_set(ppag
, set_num
);
403 for (i
= 0; i
< ppag
->bands_count
; i
++)
404 acpigen_write_byte(set
[i
]);
407 acpigen_write_package_end();
408 acpigen_write_package_end();
411 static void sar_emit_wtas(struct avg_profile
*wtas
)
420 * Name (WTAS, Package() {
425 * DomainType, // 0x7:WiFi
426 * WifiTASSelection, // Enable/Disable the TAS feature
427 * WifiTASListEntries, // No. of blocked countries not approved by OEM to
428 * BlockedListEntry1, support this feature
437 * BlockedListEntry10,
438 * BlockedListEntry11,
439 * BlockedListEntry12,
440 * BlockedListEntry13,
441 * BlockedListEntry14,
442 * BlockedListEntry15,
443 * BlockedListEntry16,
447 package_size
= 1 + 1 + 1 + MAX_DENYLIST_ENTRY
;
449 acpigen_write_name("WTAS");
450 acpigen_write_package(2);
451 acpigen_write_dword(wtas
->revision
);
452 acpigen_write_package(package_size
);
453 acpigen_write_dword(DOMAIN_TYPE_WIFI
);
454 acpigen_write_byte(wtas
->tas_selection
);
455 acpigen_write_byte(wtas
->tas_list_size
);
456 for (i
= 0; i
< MAX_DENYLIST_ENTRY
; i
++)
457 acpigen_write_word(wtas
->deny_list_entry
[i
]);
459 acpigen_write_package_end();
460 acpigen_write_package_end();
463 static void emit_sar_acpi_structures(const struct device
*dev
, struct dsm_profile
*dsm
)
465 union wifi_sar_limits sar_limits
= {{NULL
, NULL
, NULL
, NULL
, NULL
} };
468 * If device type is PCI, ensure that the device has Intel vendor ID. CBFS SAR and SAR
469 * ACPI tables are currently used only by Intel WiFi devices.
471 if (dev
->path
.type
== DEVICE_PATH_PCI
&& dev
->vendor
!= PCI_VID_INTEL
)
474 /* Retrieve the sar limits data */
475 if (get_wifi_sar_limits(&sar_limits
) < 0) {
476 printk(BIOS_ERR
, "failed getting SAR limits!\n");
480 sar_emit_wrds(sar_limits
.sar
);
481 sar_emit_ewrd(sar_limits
.sar
);
482 sar_emit_wgds(sar_limits
.wgds
);
483 sar_emit_ppag(sar_limits
.ppag
);
484 sar_emit_wtas(sar_limits
.wtas
);
486 /* copy the dsm data to be later used for creating _DSM function */
487 if (sar_limits
.dsm
!= NULL
)
488 memcpy(dsm
, sar_limits
.dsm
, sizeof(struct dsm_profile
));
490 free(sar_limits
.sar
);
493 static void wifi_ssdt_write_device(const struct device
*dev
, const char *path
)
496 acpigen_write_device(path
);
497 acpi_device_write_uid(dev
);
500 acpigen_write_name_string("_DDN", dev
->chip_ops
->name
);
503 acpigen_write_ADR_pci_device(dev
);
505 acpigen_pop_len(); /* Device */
508 static void wifi_ssdt_write_properties(const struct device
*dev
, const char *scope
)
510 const struct drivers_wifi_generic_config
*config
= dev
->chip_info
;
512 bool is_cnvi_ddr_rfim_enabled
= config
&& config
->enable_cnvi_ddr_rfim
;
515 acpigen_write_scope(scope
);
518 /* Wake capabilities */
519 acpigen_write_PRW(config
->wake
, ACPI_S3
);
521 /* Add _DSD for DmaProperty property. */
522 if (config
->add_acpi_dma_property
)
523 acpi_device_add_dma_property(NULL
);
526 /* Fill regulatory domain structure */
527 if (CONFIG(HAVE_REGULATORY_DOMAIN
)) {
529 * Name ("WRDD", Package () {
530 * WRDD_REVISION, // Revision
532 * DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
533 * wifi_regulatory_domain() // Country Identifier
537 acpigen_write_name("WRDD");
538 acpigen_write_package(2);
539 acpigen_write_integer(WRDD_REVISION
);
540 acpigen_write_package(2);
541 acpigen_write_dword(DOMAIN_TYPE_WIFI
);
542 acpigen_write_dword(wifi_regulatory_domain());
547 struct dsm_uuid dsm_ids
[MAX_DSM_FUNCS
];
548 /* We will need a copy dsm data to be used later for creating _DSM function */
549 struct dsm_profile dsm
= {0};
550 uint8_t dsm_count
= 0;
552 /* Fill Wifi sar related ACPI structures */
553 if (CONFIG(USE_SAR
)) {
554 emit_sar_acpi_structures(dev
, &dsm
);
556 if (dsm
.supported_functions
!= 0) {
557 for (int i
= 1; i
< ARRAY_SIZE(wifi_dsm_callbacks
); i
++)
558 if (!(dsm
.supported_functions
& (1 << i
)))
559 wifi_dsm_callbacks
[i
] = NULL
;
561 dsm_ids
[dsm_count
].uuid
= ACPI_DSM_OEM_WIFI_UUID
;
562 dsm_ids
[dsm_count
].callbacks
= &wifi_dsm_callbacks
[0];
563 dsm_ids
[dsm_count
].count
= ARRAY_SIZE(wifi_dsm_callbacks
);
564 dsm_ids
[dsm_count
].arg
= &dsm
;
569 if (is_cnvi_ddr_rfim_enabled
) {
570 dsm_ids
[dsm_count
].uuid
= ACPI_DSM_RFIM_WIFI_UUID
;
571 dsm_ids
[dsm_count
].callbacks
= &wifi_dsm2_callbacks
[0];
572 dsm_ids
[dsm_count
].count
= ARRAY_SIZE(wifi_dsm2_callbacks
);
573 dsm_ids
[dsm_count
].arg
= &is_cnvi_ddr_rfim_enabled
;
577 acpigen_write_dsm_uuid_arr(dsm_ids
, dsm_count
);
579 acpigen_pop_len(); /* Scope */
581 printk(BIOS_INFO
, "%s: %s %s\n", scope
, dev
->chip_ops
? dev
->chip_ops
->name
: "",
585 void wifi_pcie_fill_ssdt(const struct device
*dev
)
589 path
= acpi_device_path(dev
);
593 wifi_ssdt_write_device(dev
, path
);
594 wifi_ssdt_write_properties(dev
, path
);
597 const char *wifi_pcie_acpi_name(const struct device
*dev
)
599 static char wifi_acpi_name
[WIFI_ACPI_NAME_MAX_LEN
];
601 /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */
602 snprintf(wifi_acpi_name
, sizeof(wifi_acpi_name
), "WF%02X",
603 (dev_path_encode(dev
) & 0xff));
604 return wifi_acpi_name
;
607 void wifi_cnvi_fill_ssdt(const struct device
*dev
)
613 path
= acpi_device_path(dev
->bus
->dev
);
617 wifi_ssdt_write_properties(dev
, path
);