Debian Codegraph @

src/drivers/wifi/generic/acpi.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-only */
2
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>
13
14 #include "chip.h"
15 #include "wifi.h"
16 #include "wifi_private.h"
17
18 /* Domain type */
19 enum sar_domain {
20 DOMAIN_TYPE_WIFI = 0x7,
21 DOMAIN_TYPE_BLUETOOTH = 0x12
22 };
23
24 /* Maximum number DSM UUID bifurcations in _DSM */
25 #define MAX_DSM_FUNCS 2
26
27 /*
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.
32 */
33 #define WIFI_ACPI_NAME_MAX_LEN 5
34
35 /* Unique ID for the WIFI _DSM */
36 #define ACPI_DSM_OEM_WIFI_UUID "F21202BF-8F78-4DC6-A5B3-1F738E285ADE"
37
38 /* Unique ID for CnviDdrRfim entry in WIFI _DSM */
39 #define ACPI_DSM_RFIM_WIFI_UUID "7266172C-220B-4B29-814F-75E4DD26B5FD"
40
41 __weak int get_wifi_sar_limits(union wifi_sar_limits *sar_limits)
42 {
43 return -1;
44 }
45
46 /*
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
52 */
53 static void wifi_dsm_srd_active_channels(void *args)
54 {
55 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
56
57 acpigen_write_return_integer(dsm_config->disable_active_sdr_channels);
58 }
59
60 /*
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
65 */
66 static void wifi_dsm_indonasia_5Ghz_band_enable(void *args)
67 {
68 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
69
70 acpigen_write_return_integer(dsm_config->support_indonesia_5g_band);
71 }
72
73 /*
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
78 *
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)
82 */
83 static void wifi_dsm_supported_ultra_high_band(void *args)
84 {
85 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
86
87 acpigen_write_return_integer(dsm_config->support_ultra_high_band);
88 }
89
90 /*
91 * Function 4: Regulatory Special Configurations Enablements
92 */
93 static void wifi_dsm_regulatory_configurations(void *args)
94 {
95 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
96
97 acpigen_write_return_integer(dsm_config->regulatory_configurations);
98 }
99
100 /*
101 * Function 5: M.2 UART Interface Configuration
102 */
103 static void wifi_dsm_uart_configurations(void *args)
104 {
105 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
106
107 acpigen_write_return_integer(dsm_config->uart_configurations);
108 }
109
110 /*
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.
115 *
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
119 *
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.
123 *
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
127 *
128 * Bit 31:04 - Reserved
129 *
130 * Note: Assumed Russia Work with Wi-Fi FW/OTP definitions
131 */
132 static void wifi_dsm_ukrane_russia_11ax_enable(void *args)
133 {
134 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
135
136 acpigen_write_return_integer(dsm_config->enablement_11ax);
137 }
138
139 /*
140 * Function 7: Control Enablement UNII-4 over certificate modules
141 */
142 static void wifi_dsm_unii4_control_enable(void *args)
143 {
144 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
145
146 acpigen_write_return_integer(dsm_config->unii_4);
147 }
148
149 /*
150 * Function 10: Energy Detection Threshold (EDT)
151 * Bits 0-3: EDT revision - Default 0
152 *
153 * Bits 4-5: Reserved - Should be 0
154 *
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
158 *
159 * Bits 7-8: Reserved - Should be 0
160 *
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
164 *
165 * Bit 10-12: Reserved - Default 0
166 *
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
170 *
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
174 *
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
178 *
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
182 *
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
186 *
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
190 *
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
194 *
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
198 *
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
202 *
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
206 *
207 * Bits 23-31: Reserved - Should be 0
208 */
209 static void wifi_dsm_energy_detection_threshold(void *args)
210 {
211 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
212
213 acpigen_write_return_integer(dsm_config->energy_detection_threshold);
214 }
215
216 /*
217 * Function 11: RFI mitigation
218 * Bit 0:
219 * 0 - DLVR RFIm enabled (default)
220 * 1 - DLVR RFIm disabled
221 *
222 * Bit 1:
223 * 0 - DDR RFIm enabled (default)
224 * 1 - DDR RFIm disabled
225 *
226 * Bits 2-31: Reserved - Should be 0
227 */
228
229 static void wifi_dsm_rfi_mitigation(void *args)
230 {
231 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
232
233 acpigen_write_return_integer(dsm_config->rfi_mitigation);
234 }
235
236 /*
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
241 *
242 * Bit 1
243 * 0 - 11BE disabled for South Korea
244 * 1 - 11BE enabled for South Korea
245 *
246 * Bit 2:27 - Reserved (shall be set to zeroes)
247 *
248 * Bit 28:31 - 11BE enablement revision
249 *
250 */
251 static void wifi_dsm_11be_country_enablement(void *args)
252 {
253 struct dsm_profile *dsm_config = (struct dsm_profile *)args;
254
255 acpigen_write_return_integer(dsm_config->enablement_11be);
256 }
257
258 static void wifi_dsm_ddrrfim_func3_cb(void *ptr)
259 {
260 const bool is_cnvi_ddr_rfim_enabled = *(bool *)ptr;
261 acpigen_write_return_integer(is_cnvi_ddr_rfim_enabled ? 0 : 1);
262 }
263
264 /*
265 * Function 2: Power Resource for Reset (PRR) for Wi-Fi
266 *
267 * Args3 is a buffer comparable to the following C structure:
268 * struct pldr_mode {
269 * uint16_t cmd_type;
270 * uint16_t cmd_payload;
271 * };
272 *
273 * cmd_type can take one of the following values:
274 * 1 - Get PRR mode;
275 * 2 - Set PRR mode to cmd_payload;
276 * 3 - Get PRR status;
277 */
278 static void wifi_dsm_power_resource_for_reset(__always_unused void *args)
279 {
280 acpigen_write_create_word_field(ARG3_OP, 0, "CMDT");
281 acpigen_write_create_word_field(ARG3_OP, 2, "CMDP");
282
283 /* Get PRR mode */
284 acpigen_write_if_lequal_namestr_int("CMDT", 1);
285 {
286 acpigen_write_if_cond_ref_of("RSTT");
287 {
288 acpigen_write_return_namestr("RSTT");
289
290 }
291 acpigen_pop_len();
292 acpigen_write_return_integer(0);
293 }
294 acpigen_pop_len();
295
296 /* Set PRR mode */
297 acpigen_write_if_lequal_namestr_int("CMDT", 2);
298 {
299 acpigen_write_if_cond_ref_of("RSTT");
300 {
301 acpigen_write_store();
302 acpigen_emit_namestring("CMDP");
303 acpigen_emit_namestring("RSTT");
304
305 }
306 acpigen_pop_len();
307 acpigen_write_return_integer(0);
308 }
309 acpigen_pop_len();
310
311 /* Get last PRR status */
312 acpigen_write_if_lequal_namestr_int("CMDT", 3);
313 {
314 acpigen_write_if_cond_ref_of("PRRS");
315 {
316 acpigen_write_return_namestr("PRRS");
317 }
318 acpigen_pop_len();
319 acpigen_write_return_integer(0);
320 }
321 acpigen_pop_len();
322
323 acpigen_write_return_integer(0);
324 }
325
326 /*
327 * Function 5: Set Power Resource for Reset (PRR) reset delay for Wi-Fi
328 */
329 static void wifi_dsm_set_prr_reset_delay(__always_unused void *args)
330 {
331 acpigen_write_if_cond_ref_of("WFDL");
332 {
333 acpigen_write_store();
334 acpigen_emit_byte(ARG3_OP);
335 acpigen_emit_namestring("WFDL");
336 }
337 acpigen_pop_len();
338 }
339
340 static void (*wifi_dsm_callbacks[])(void *) = {
341 NULL, /* Function 0 */
342 wifi_dsm_srd_active_channels, /* Function 1 */
343 wifi_dsm_indonasia_5Ghz_band_enable, /* Function 2 */
344 wifi_dsm_supported_ultra_high_band, /* Function 3 */
345 wifi_dsm_regulatory_configurations, /* Function 4 */
346 wifi_dsm_uart_configurations, /* Function 5 */
347 wifi_dsm_ukrane_russia_11ax_enable, /* Function 6 */
348 wifi_dsm_unii4_control_enable, /* Function 7 */
349 NULL, /* Function 8 */
350 NULL, /* Function 9 */
351 wifi_dsm_energy_detection_threshold, /* Function 10 */
352 wifi_dsm_rfi_mitigation, /* Function 11 */
353 wifi_dsm_11be_country_enablement, /* Function 12 */
354 };
355
356 static void (*wifi_dsm2_callbacks[])(void *) = {
357 NULL, /* Function 0 */
358 NULL, /* Function 1 */
359 wifi_dsm_power_resource_for_reset, /* Function 2 */
360 wifi_dsm_ddrrfim_func3_cb, /* Function 3 */
361 NULL, /* Function 4 */
362 wifi_dsm_set_prr_reset_delay, /* Function 5 */
363 };
364
365 /*
366 * Function 5: Set Power Resource for Reset (PRR) mode for Bluetooth
367 *
368 * Args3 is a buffer comparable to the following C structure:
369 * struct pldr_mode {
370 * uint16_t cmd_type;
371 * uint16_t cmd_payload;
372 * };
373 *
374 * cmd_type can take one of the following values:
375 * 1 - Set PRR mode to cmd_payload;
376 */
377 static void bluetooth_dsm_set_power_resource_for_reset(__always_unused void *args)
378 {
379 acpigen_write_create_word_field(ARG3_OP, 0, "BCMT");
380 acpigen_write_create_word_field(ARG3_OP, 2, "BCMP");
381
382 /* Set PRR mode */
383 acpigen_write_if_lequal_namestr_int("BCMT", 1);
384 {
385 acpigen_write_if_cond_ref_of("RSTT");
386 {
387 acpigen_write_store();
388 acpigen_emit_namestring("BCMP");
389 acpigen_emit_namestring("RSTT");
390
391 }
392 acpigen_pop_len();
393 }
394 acpigen_pop_len();
395
396 acpigen_write_return_integer(0);
397 }
398
399 /*
400 * Function 6: Get Power Resource for Reset (PRR) mode and status for Bluetooth
401 */
402 static void bluetooth_dsm_get_power_resource_for_reset(__always_unused void *args)
403 {
404 /* Get PRR mode and status */
405 acpigen_write_if_cond_ref_of("RSTT");
406 {
407 acpigen_write_if_cond_ref_of("PRRS");
408 {
409 acpigen_emit_byte(RETURN_OP);
410 acpigen_write_package(2);
411 acpigen_emit_namestring("RSTT");
412 acpigen_emit_namestring("PRRS");
413 acpigen_pop_len();
414 }
415 acpigen_pop_len();
416 }
417 acpigen_pop_len();
418
419 acpigen_write_return_integer(0);
420 }
421
422 /*
423 * Function 7: Set Power Resource for Reset (PRR) reset delay for Bluetooth
424 */
425 static void bluetooth_dsm_set_prr_reset_delay(__always_unused void *args)
426 {
427 acpigen_write_if_cond_ref_of("BTDL");
428 {
429 acpigen_write_store();
430 acpigen_emit_byte(ARG3_OP);
431 acpigen_emit_namestring("BTDL");
432 }
433 acpigen_pop_len();
434 }
435
436
437 static void (*bluetooth_dsm_callbacks[])(void *) = {
438 NULL, /* Function 0 */
439 NULL, /* Function 1 */
440 NULL, /* Function 2 */
441 NULL, /* Function 3 */
442 NULL, /* Function 4 */
443 bluetooth_dsm_set_power_resource_for_reset, /* Function 5 */
444 bluetooth_dsm_get_power_resource_for_reset, /* Function 6 */
445 bluetooth_dsm_set_prr_reset_delay, /* Function 7 */
446 };
447
448 static const uint8_t *sar_fetch_set(const struct sar_profile *sar, size_t set_num)
449 {
450 const uint8_t *sar_table = &sar->sar_table[0];
451
452 return sar_table + (sar->chains_count * sar->subbands_count * set_num);
453 }
454
455 static const uint8_t *wgds_fetch_set(struct geo_profile *wgds, size_t set_num)
456 {
457 const uint8_t *wgds_table = &wgds->wgds_table[0];
458
459 return wgds_table + (wgds->bands_count * set_num);
460 }
461
462 static const uint8_t *ppag_fetch_set(struct gain_profile *ppag, size_t set_num)
463 {
464 const uint8_t *ppag_table = &ppag->ppag_table[0];
465
466 return ppag_table + (ppag->bands_count * set_num);
467 }
468
469 static void sar_emit_wrds(const struct sar_profile *sar)
470 {
471 int i;
472 size_t package_size, table_size;
473 const uint8_t *set;
474
475 if (sar == NULL)
476 return;
477
478 /*
479 * Name ("WRDS", Package () {
480 * Revision,
481 * Package () {
482 * Domain Type, // 0x7:WiFi
483 * WiFi SAR BIOS, // BIOS SAR Enable/disable
484 * SAR Table Set // Set#1 of SAR Table
485 * }
486 * })
487 */
488 if (sar->revision > MAX_SAR_REVISION) {
489 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
490 return;
491 }
492
493 acpigen_write_name("WRDS");
494 acpigen_write_package(2);
495 acpigen_write_dword(sar->revision);
496
497 table_size = sar->chains_count * sar->subbands_count;
498 /* Emit 'Domain Type' + 'WiFi SAR Enable' + Set#1 */
499 package_size = 1 + 1 + table_size;
500 acpigen_write_package(package_size);
501 acpigen_write_dword(DOMAIN_TYPE_WIFI);
502 acpigen_write_dword(1);
503
504 set = sar_fetch_set(sar, 0);
505 for (i = 0; i < table_size; i++)
506 acpigen_write_byte(set[i]);
507
508 acpigen_write_package_end();
509 acpigen_write_package_end();
510 }
511
512 static void sar_emit_ewrd(const struct sar_profile *sar)
513 {
514 int i;
515 size_t package_size, set_num, table_size;
516 const uint8_t *set;
517
518 if (sar == NULL)
519 return;
520
521 /*
522 * Name ("EWRD", Package () {
523 * Revision,
524 * Package () {
525 * Domain Type, // 0x7:WiFi
526 * Dynamic SAR Enable, // Dynamic SAR Enable/disable
527 * Extended SAR sets, // Number of optional SAR table sets
528 * SAR Table Set, // Set#2 of SAR Table
529 * SAR Table Set, // Set#3 of SAR Table
530 * SAR Table Set // Set#4 of SAR Table
531 * }
532 * })
533 */
534 if (sar->revision > MAX_SAR_REVISION) {
535 printk(BIOS_ERR, "Invalid SAR table revision: %d\n", sar->revision);
536 return;
537 }
538
539 if (sar->dsar_set_count == 0) {
540 printk(BIOS_WARNING, "DSAR set count is 0\n");
541 return;
542 }
543
544 acpigen_write_name("EWRD");
545 acpigen_write_package(2);
546 acpigen_write_dword(sar->revision);
547
548 table_size = sar->chains_count * sar->subbands_count;
549 /*
550 * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Extended SAR sets count'
551 * + number of bytes for Set#2 & 3 & 4
552 */
553 package_size = 1 + 1 + 1 + table_size * MAX_DSAR_SET_COUNT;
554 acpigen_write_package(package_size);
555 acpigen_write_dword(DOMAIN_TYPE_WIFI);
556 acpigen_write_dword(1);
557 acpigen_write_dword(sar->dsar_set_count);
558
559 for (set_num = 1; set_num <= sar->dsar_set_count; set_num++) {
560 set = sar_fetch_set(sar, set_num);
561 for (i = 0; i < table_size; i++)
562 acpigen_write_byte(set[i]);
563 }
564
565 /* wifi driver always expects 3 DSAR sets */
566 for (i = 0; i < (table_size * (MAX_DSAR_SET_COUNT - sar->dsar_set_count)); i++)
567 acpigen_write_byte(0);
568
569 acpigen_write_package_end();
570 acpigen_write_package_end();
571 }
572
573 static void sar_emit_wgds(struct geo_profile *wgds)
574 {
575 int i;
576 size_t package_size, set_num;
577 const uint8_t *set;
578
579 if (wgds == NULL)
580 return;
581
582 /*
583 * Name ("WGDS", Package() {
584 * Revision,
585 * Package() {
586 * DomainType, // 0x7:WiFi
587 * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max
588 * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset
589 * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset
590 * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max
591 * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset
592 * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset
593 * WgdsWiFiSarDeltaGroup1PowerMax3, // Group 1 FCC 6000-7000 Max
594 * WgdsWiFiSarDeltaGroup1PowerChainA3, // Group 1 FCC 6000-7000 A Offset
595 * WgdsWiFiSarDeltaGroup1PowerChainB3, // Group 1 FCC 6000-7000 B Offset
596 * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max
597 * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset
598 * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset
599 * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max
600 * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset
601 * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset
602 * WgdsWiFiSarDeltaGroup2PowerMax3, // Group 2 EC Jap 6000-7000 Max
603 * WgdsWiFiSarDeltaGroup2PowerChainA3, // Group 2 EC Jap 6000-7000 A Offset
604 * WgdsWiFiSarDeltaGroup2PowerChainB3, // Group 2 EC Jap 6000-7000 B Offset
605 * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max
606 * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset
607 * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset
608 * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max
609 * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset
610 * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset
611 * WgdsWiFiSarDeltaGroup3PowerMax3, // Group 3 ROW 6000-7000 Max
612 * WgdsWiFiSarDeltaGroup3PowerChainA3, // Group 3 ROW 6000-7000 A Offset
613 * WgdsWiFiSarDeltaGroup3PowerChainB3, // Group 3 ROW 6000-7000 B Offset
614 * }
615 * })
616 */
617 if (wgds->revision > MAX_GEO_OFFSET_REVISION) {
618 printk(BIOS_ERR, "Invalid WGDS revision: %d\n", wgds->revision);
619 return;
620 }
621
622 package_size = 1 + wgds->chains_count * wgds->bands_count;
623
624 acpigen_write_name("WGDS");
625 acpigen_write_package(2);
626 acpigen_write_dword(wgds->revision);
627 /* Emit 'Domain Type' +
628 * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS)
629 */
630 acpigen_write_package(package_size);
631 acpigen_write_dword(DOMAIN_TYPE_WIFI);
632
633 for (set_num = 0; set_num < wgds->chains_count; set_num++) {
634 set = wgds_fetch_set(wgds, set_num);
635 for (i = 0; i < wgds->bands_count; i++)
636 acpigen_write_byte(set[i]);
637 }
638
639 acpigen_write_package_end();
640 acpigen_write_package_end();
641 }
642
643 static void sar_emit_ppag(struct gain_profile *ppag)
644 {
645 int i;
646 size_t package_size, set_num;
647 const uint8_t *set;
648
649 if (ppag == NULL)
650 return;
651
652 /*
653 * Name ("PPAG", Package () {
654 * Revision,
655 * Package () {
656 * Domain Type, // 0x7:WiFi
657 * PPAG Mode, // Defines the mode of ANT_gain control to be used
658 * ANT_gain Table Chain A // Defines the ANT_gain in dBi for chain A
659 * ANT_gain Table Chain B // Defines the ANT_gain in dBi for chain B
660 * }
661 * })
662 */
663 if (ppag->revision > MAX_ANT_GAINS_REVISION) {
664 printk(BIOS_ERR, "Invalid PPAG revision: %d\n", ppag->revision);
665 return;
666 }
667
668 package_size = 1 + 1 + ppag->chains_count * ppag->bands_count;
669
670 acpigen_write_name("PPAG");
671 acpigen_write_package(2);
672 acpigen_write_dword(ppag->revision);
673 acpigen_write_package(package_size);
674 acpigen_write_dword(DOMAIN_TYPE_WIFI);
675 acpigen_write_dword(ppag->mode);
676
677 for (set_num = 0; set_num < ppag->chains_count; set_num++) {
678 set = ppag_fetch_set(ppag, set_num);
679 for (i = 0; i < ppag->bands_count; i++)
680 acpigen_write_byte(set[i]);
681 }
682
683 acpigen_write_package_end();
684 acpigen_write_package_end();
685 }
686
687 static void sar_emit_wtas(struct avg_profile *wtas)
688 {
689 int i;
690 size_t package_size;
691
692 if (wtas == NULL)
693 return;
694
695 /*
696 * Name (WTAS, Package() {
697 * {
698 * Revision,
699 * Package()
700 * {
701 * DomainType, // 0x7:WiFi
702 * WifiTASSelection, // Enable/Disable the TAS feature
703 * WifiTASListEntries, // No. of blocked countries not approved by OEM to
704 * BlockedListEntry1, support this feature
705 * BlockedListEntry2,
706 * BlockedListEntry3,
707 * BlockedListEntry4,
708 * BlockedListEntry5,
709 * BlockedListEntry6,
710 * BlockedListEntry7,
711 * BlockedListEntry8,
712 * BlockedListEntry9,
713 * BlockedListEntry10,
714 * BlockedListEntry11,
715 * BlockedListEntry12,
716 * BlockedListEntry13,
717 * BlockedListEntry14,
718 * BlockedListEntry15,
719 * BlockedListEntry16,
720 * }
721 * })
722 */
723 package_size = 1 + 1 + 1 + MAX_DENYLIST_ENTRY;
724
725 acpigen_write_name("WTAS");
726 acpigen_write_package(2);
727 acpigen_write_dword(wtas->revision);
728 acpigen_write_package(package_size);
729 acpigen_write_dword(DOMAIN_TYPE_WIFI);
730 acpigen_write_byte(wtas->tas_selection);
731 acpigen_write_byte(wtas->tas_list_size);
732 for (i = 0; i < MAX_DENYLIST_ENTRY; i++)
733 acpigen_write_word(wtas->deny_list_entry[i]);
734
735 acpigen_write_package_end();
736 acpigen_write_package_end();
737 }
738
739 static void sar_emit_brds(const struct bsar_profile *bsar)
740 {
741 size_t package_size, table_size;
742 const uint8_t *set;
743
744 if (bsar == NULL)
745 return;
746
747 /*
748 * Name ("BRDS", Package () {
749 * Revision,
750 * Package () {
751 * Domain Type, // 0x12:Bluetooth
752 * Bluetooth SAR BIOS, // BIOS SAR Enable/disable
753 * Bluetooth Increase Power Mode // SAR Limitation Enable/disable
754 * Bluetooth SAR Power Restriction, // 00000000 - 0dBm
755 * // 11111111 - 31.875dBm
756 * // (Step 0.125dBm)
757 * Bluetooth SAR Table // SAR Tx power limit table
758 * }
759 * })
760 */
761 if (bsar->revision == 0 || bsar->revision > MAX_BSAR_REVISION) {
762 printk(BIOS_ERR, "Unsupported BSAR table revision: %d\n",
763 bsar->revision);
764 return;
765 }
766
767 acpigen_write_name("BRDS");
768 acpigen_write_package(2);
769 acpigen_write_dword(bsar->revision);
770
771 if (bsar->revision == 1)
772 table_size = sizeof(bsar->revs.rev1);
773 else
774 table_size = sizeof(bsar->revs.rev2);
775
776 /*
777 * Emit 'Domain Type' + 'Dynamic SAR Enable' + 'Increase Power Mode'
778 * + ('SAR Power Restriction' + SAR table) | (Chain A and B SAR tables).
779 */
780 package_size = 1 + 1 + 1 + table_size;
781 acpigen_write_package(package_size);
782 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
783 acpigen_write_dword(1);
784 acpigen_write_dword(bsar->increased_power_mode_limitation);
785
786 set = (const uint8_t *)&bsar->revs;
787 for (int i = 0; i < table_size; i++)
788 acpigen_write_byte(set[i]);
789
790 acpigen_write_package_end();
791 acpigen_write_package_end();
792 }
793
794 static void sar_emit_wbem(const struct wbem_profile *wbem)
795 {
796 if (wbem == NULL)
797 return;
798
799 /*
800 * Name ("WBEM", Package() {
801 * {
802 * Revision,
803 * Package()
804 * {
805 * DomainType, // 0x7:WiFi
806 * bandwidth_320mhz_country_enablement // 0 Disabled
807 * // 1 Japan Enabled
808 * // 2 South Korea Enabled
809 * // 3 Japan + South Korea Enabled
810 * }
811 } })
812 */
813 if (wbem->revision != WBEM_REVISION) {
814 printk(BIOS_ERR, "Unsupported WBEM table revision: %d\n",
815 wbem->revision);
816 return;
817 }
818
819 acpigen_write_name("WBEM");
820 acpigen_write_package(2);
821 acpigen_write_dword(wbem->revision);
822
823 acpigen_write_package(2);
824 acpigen_write_dword(DOMAIN_TYPE_WIFI);
825 acpigen_write_dword(wbem->bandwidth_320mhz_country_enablement);
826
827 acpigen_write_package_end();
828 acpigen_write_package_end();
829 }
830
831 static void sar_emit_bpag(const struct bpag_profile *bpag)
832 {
833 if (bpag == NULL)
834 return;
835
836 /*
837 * Name ("BPAG", Package () {
838 * Revision,
839 * Package () {
840 * Domain Type, // 0x12:Bluetooth
841 * Bluetooth Per-Platform Antenna Gain Mode
842 * }
843 * })
844 */
845 if (bpag->revision == 0 || bpag->revision > BPAG_REVISION) {
846 printk(BIOS_ERR, "Unsupported BPAG table revision: %d\n",
847 bpag->revision);
848 return;
849 }
850
851 acpigen_write_name("BPAG");
852 acpigen_write_package(2);
853 acpigen_write_dword(bpag->revision);
854
855 /*
856 * Emit 'Domain Type' + 'Antenna Gain Mode'
857 */
858 acpigen_write_package(2);
859 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
860 acpigen_write_dword(bpag->antenna_gain_country_enablement);
861
862 acpigen_write_package_end();
863 acpigen_write_package_end();
864 }
865
866 static void sar_emit_bbfb(const struct bbfb_profile *bbfb)
867 {
868 if (bbfb == NULL)
869 return;
870
871 /*
872 * Name ("BBFB", Package () {
873 * Revision,
874 * Package () {
875 * Domain Type, // 0x12:Bluetooth
876 * By Pass Enabled // Enable ByPass
877 * }
878 * })
879 */
880 if (bbfb->revision != BBFB_REVISION) {
881 printk(BIOS_ERR, "Unsupported BBFB table revision: %d\n",
882 bbfb->revision);
883 return;
884 }
885
886 acpigen_write_name("BBFB");
887 acpigen_write_package(2);
888 acpigen_write_dword(bbfb->revision);
889
890 /*
891 * Emit 'Domain Type' + 'Enable ByPass'
892 */
893 acpigen_write_package(2);
894 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
895 acpigen_write_dword(bbfb->enable_quad_filter_bypass);
896
897 acpigen_write_package_end();
898 acpigen_write_package_end();
899 }
900
901 static void sar_emit_bdcm(const struct bdcm_profile *bdcm)
902 {
903 if (bdcm == NULL)
904 return;
905
906 /*
907 * Name ("BDCM", Package () {
908 * Revision,
909 * Package () {
910 * Domain Type, // 0x12:Bluetooth
911 * Dual Chain Mode
912 * }
913 * })
914 */
915 if (bdcm->revision != BDCM_REVISION) {
916 printk(BIOS_ERR, "Unsupported BDCM table revision: %d\n",
917 bdcm->revision);
918 return;
919 }
920
921 acpigen_write_name("BDCM");
922 acpigen_write_package(2);
923 acpigen_write_dword(bdcm->revision);
924
925 /*
926 * Emit 'Domain Type' + 'Dual Chain Mode'
927 */
928 acpigen_write_package(2);
929 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
930 acpigen_write_dword(bdcm->dual_chain_mode);
931
932 acpigen_write_package_end();
933 acpigen_write_package_end();
934 }
935
936 static void sar_emit_bbsm(const struct bbsm_profile *bbsm)
937 {
938 if (bbsm == NULL)
939 return;
940
941 /*
942 * Name ("BBSM", Package () {
943 * Revision,
944 * Package () {
945 * Domain Type, // 0x12:Bluetooth
946 * Bluetooth Bands Selection
947 * }
948 * })
949 */
950 if (bbsm->revision != BBSM_REVISION) {
951 printk(BIOS_ERR, "Unsupported BBSM table revision: %d\n",
952 bbsm->revision);
953 return;
954 }
955
956 acpigen_write_name("BBSM");
957 acpigen_write_package(2);
958 acpigen_write_dword(bbsm->revision);
959
960 /*
961 * Emit 'Domain Type' + 'Bluetooth Bands Selection'
962 */
963 acpigen_write_package(2);
964 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
965 acpigen_write_dword(bbsm->bands_selection);
966
967 acpigen_write_package_end();
968 acpigen_write_package_end();
969 }
970
971 static void sar_emit_bucs(const struct bucs_profile *bucs)
972 {
973 if (bucs == NULL)
974 return;
975
976 /*
977 * Name ("BUCS", Package () {
978 * Revision,
979 * Package () {
980 * Domain Type, // 0x12:Bluetooth
981 * UHB country selection bits
982 * }
983 * })
984 */
985 if (bucs->revision != BUCS_REVISION) {
986 printk(BIOS_ERR, "Unsupported BUCS table revision: %d\n",
987 bucs->revision);
988 return;
989 }
990
991 acpigen_write_name("BUCS");
992 acpigen_write_package(2);
993 acpigen_write_dword(bucs->revision);
994
995 /*
996 * Emit 'Domain Type' + 'UHB country selection bits'
997 */
998 acpigen_write_package(2);
999 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
1000 acpigen_write_dword(bucs->uhb_country_selection);
1001
1002 acpigen_write_package_end();
1003 acpigen_write_package_end();
1004 }
1005
1006 static void sar_emit_bdmm(const struct bdmm_profile *bdmm)
1007 {
1008 if (bdmm == NULL)
1009 return;
1010
1011 /*
1012 * Name ("BDMM", Package () {
1013 * Revision,
1014 * Package () {
1015 * Domain Type, // 0x12:Bluetooth
1016 * Dual Mac Enable
1017 * }
1018 * })
1019 */
1020 if (bdmm->revision != BDMM_REVISION) {
1021 printk(BIOS_ERR, "Unsupported BDMM table revision: %d\n",
1022 bdmm->revision);
1023 return;
1024 }
1025
1026 acpigen_write_name("BDMM");
1027 acpigen_write_package(2);
1028 acpigen_write_dword(bdmm->revision);
1029
1030 /*
1031 * Emit 'Domain Type' + 'Dual Mac Enable'
1032 */
1033 acpigen_write_package(2);
1034 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
1035 acpigen_write_dword(bdmm->dual_mac_enable);
1036
1037 acpigen_write_package_end();
1038 acpigen_write_package_end();
1039 }
1040
1041 static void sar_emit_ebrd(const struct ebrd_profile *ebrd)
1042 {
1043 if (ebrd == NULL)
1044 return;
1045
1046 size_t package_size, table_size;
1047 const uint8_t *set;
1048
1049 /*
1050 * Name ("EBRD", Package () {
1051 * Revision,
1052 * Package () {
1053 * Domain Type, // 0x12:Bluetooth
1054 * Dynamic SAR Enable,
1055 * Number of Optional SAR,
1056 * Three SAR Sets
1057 * }
1058 * })
1059 */
1060 if (ebrd->revision != EBRD_REVISION) {
1061 printk(BIOS_ERR, "Unsupported EBRD table revision: %d\n",
1062 ebrd->revision);
1063 return;
1064 }
1065
1066 acpigen_write_name("EBRD");
1067 acpigen_write_package(2);
1068 acpigen_write_dword(ebrd->revision);
1069
1070 /*
1071 * Emit 'Domain Type' + 'Dynamic Sar Enabled' + 'Number of Optional SAR' +
1072 * 'Three SAR Sets'
1073 */
1074 table_size = sizeof(*ebrd) - offsetof(struct ebrd_profile, sar_table_sets);
1075 package_size = 1 + 1 + 1 + table_size;
1076 acpigen_write_package(package_size);
1077 acpigen_write_dword(DOMAIN_TYPE_BLUETOOTH);
1078 acpigen_write_dword(ebrd->dynamic_sar_enable);
1079 acpigen_write_dword(ebrd->number_of_optional_sar);
1080
1081 set = (const uint8_t *)&ebrd->sar_table_sets;
1082 for (size_t i = 0; i < table_size; i++)
1083 acpigen_write_byte(set[i]);
1084
1085 acpigen_write_package_end();
1086 acpigen_write_package_end();
1087 }
1088
1089 static void sar_emit_wpfc(const struct wpfc_profile *wpfc)
1090 {
1091 if (wpfc == NULL)
1092 return;
1093
1094 /*
1095 * Name ("WPFC", Package() {
1096 * {
1097 * Revision,
1098 * Package()
1099 * {
1100 * DomainType, // 0x7:WiFi
1101 * Chain A Filter Platform Configuration
1102 * Chain B Filter Platform Configuration
1103 * Chain C Filter Platform Configuration
1104 * Chain D Filter Platform Configuration
1105 * }
1106 } })
1107 */
1108 if (wpfc->revision != WPFC_REVISION) {
1109 printk(BIOS_ERR, "Unsupported WPFC table revision: %d\n",
1110 wpfc->revision);
1111 return;
1112 }
1113
1114 acpigen_write_name("WPFC");
1115 acpigen_write_package(2);
1116 acpigen_write_dword(wpfc->revision);
1117
1118 acpigen_write_package(5);
1119 acpigen_write_dword(DOMAIN_TYPE_WIFI);
1120 acpigen_write_byte(wpfc->filter_cfg_chain_a);
1121 acpigen_write_byte(wpfc->filter_cfg_chain_b);
1122 acpigen_write_byte(wpfc->filter_cfg_chain_c);
1123 acpigen_write_byte(wpfc->filter_cfg_chain_d);
1124
1125 acpigen_write_package_end();
1126 acpigen_write_package_end();
1127 }
1128
1129 static void sar_emit_dsbr(const struct dsbr_profile *dsbr, enum sar_domain domain)
1130 {
1131 if (dsbr == NULL)
1132 return;
1133
1134 /*
1135 * Name ("DSBR", Package() {
1136 * {
1137 * Revision,
1138 * Package()
1139 * {
1140 * DomainType, // 0x7:WiFi
1141 * BRI Resistor Value // in Ohm
1142 * }
1143 } })
1144 */
1145 if (dsbr->revision > DSBR_REVISION) {
1146 printk(BIOS_ERR, "Unsupported DSBR table revision: %d\n",
1147 dsbr->revision);
1148 return;
1149 }
1150
1151 acpigen_write_name("DSBR");
1152 acpigen_write_package(2);
1153 acpigen_write_dword(dsbr->revision);
1154
1155 acpigen_write_package(2);
1156 acpigen_write_dword(domain);
1157 acpigen_write_dword(dsbr->bri_resistor_value);
1158
1159 acpigen_write_package_end();
1160 acpigen_write_package_end();
1161 }
1162
1163 static void emit_wifi_sar_acpi_structures(const struct device *dev,
1164 union wifi_sar_limits *sar_limits)
1165 {
1166 /*
1167 * If device type is PCI, ensure that the device has Intel vendor ID. CBFS SAR and SAR
1168 * ACPI tables are currently used only by Intel WiFi devices.
1169 */
1170 if (dev->path.type == DEVICE_PATH_PCI && dev->vendor != PCI_VID_INTEL)
1171 return;
1172
1173 sar_emit_wrds(sar_limits->sar);
1174 sar_emit_ewrd(sar_limits->sar);
1175 sar_emit_wgds(sar_limits->wgds);
1176 sar_emit_ppag(sar_limits->ppag);
1177 sar_emit_wtas(sar_limits->wtas);
1178 sar_emit_wbem(sar_limits->wbem);
1179 sar_emit_wpfc(sar_limits->wpfc);
1180 sar_emit_dsbr(sar_limits->dsbr, DOMAIN_TYPE_WIFI);
1181 }
1182
1183 static void wifi_ssdt_write_device(const struct device *dev, const char *path)
1184 {
1185 /* Device */
1186 acpigen_write_device(path);
1187 acpi_device_write_uid(dev);
1188
1189 if (dev->chip_ops)
1190 acpigen_write_name_string("_DDN", dev->chip_ops->name);
1191
1192 /* Address */
1193 acpigen_write_ADR_pci_device(dev);
1194
1195 acpigen_pop_len(); /* Device */
1196 }
1197
1198 static void wifi_ssdt_write_properties(const struct device *dev, const char *scope)
1199 {
1200 const struct drivers_wifi_generic_config *config = dev->chip_info;
1201
1202 bool is_cnvi_ddr_rfim_enabled = config && config->enable_cnvi_ddr_rfim;
1203
1204 /* Scope */
1205 acpigen_write_scope(scope);
1206
1207 if (config) {
1208 /* Wake capabilities */
1209 acpigen_write_PRW(config->wake, ACPI_S3);
1210
1211 if ((config->add_acpi_dma_property) || (config->cnvi_enable_gpio.pin_count)) {
1212 struct acpi_dp *dsd = acpi_dp_new_table("_DSD");
1213
1214 /* Add _DSD for DmaProperty property. */
1215 if (config->add_acpi_dma_property)
1216 acpi_device_add_dma_property(dsd);
1217
1218 if (config->cnvi_enable_gpio.pin_count)
1219 acpi_device_add_hotplug_support_in_d3(dsd);
1220
1221 acpi_dp_write(dsd);
1222 }
1223 }
1224
1225 /* Fill regulatory domain structure */
1226 if (CONFIG(HAVE_REGULATORY_DOMAIN)) {
1227 /*
1228 * Name ("WRDD", Package () {
1229 * WRDD_REVISION, // Revision
1230 * Package () {
1231 * DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
1232 * wifi_regulatory_domain() // Country Identifier
1233 * }
1234 * })
1235 */
1236 acpigen_write_name("WRDD");
1237 acpigen_write_package(2);
1238 acpigen_write_integer(WRDD_REVISION);
1239 acpigen_write_package(2);
1240 acpigen_write_dword(DOMAIN_TYPE_WIFI);
1241 acpigen_write_dword(wifi_regulatory_domain());
1242 acpigen_pop_len();
1243 acpigen_pop_len();
1244 }
1245
1246 struct dsm_uuid dsm_ids[MAX_DSM_FUNCS];
1247
1248 /* Retrieve the SAR limits data */
1249 union wifi_sar_limits sar_limits = {};
1250 bool sar_loaded = false;
1251 if (CONFIG(USE_SAR)) {
1252 if (get_wifi_sar_limits(&sar_limits) < 0)
1253 printk(BIOS_ERR, "failed getting SAR limits!\n");
1254 else
1255 sar_loaded = true;
1256 }
1257
1258 /* Fill Wifi SAR related ACPI structures */
1259 uint8_t dsm_count = 0;
1260 if (sar_loaded) {
1261 emit_wifi_sar_acpi_structures(dev, &sar_limits);
1262
1263 struct dsm_profile *dsm = sar_limits.dsm;
1264 if (dsm && dsm->supported_functions != 0) {
1265 for (int i = 1; i < ARRAY_SIZE(wifi_dsm_callbacks); i++)
1266 if (!(dsm->supported_functions & (1 << i)))
1267 wifi_dsm_callbacks[i] = NULL;
1268
1269 dsm_ids[dsm_count].uuid = ACPI_DSM_OEM_WIFI_UUID;
1270 dsm_ids[dsm_count].callbacks = &wifi_dsm_callbacks[0];
1271 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm_callbacks);
1272 dsm_ids[dsm_count].arg = dsm;
1273 dsm_count++;
1274 }
1275 }
1276
1277 dsm_ids[dsm_count].uuid = ACPI_DSM_RFIM_WIFI_UUID;
1278 dsm_ids[dsm_count].callbacks = &wifi_dsm2_callbacks[0];
1279 dsm_ids[dsm_count].count = ARRAY_SIZE(wifi_dsm2_callbacks);
1280 dsm_ids[dsm_count].arg = &is_cnvi_ddr_rfim_enabled;
1281 dsm_count++;
1282
1283 acpigen_write_dsm_uuid_arr(dsm_ids, dsm_count);
1284
1285 /*
1286 * Fill MediaTek MTCL related ACPI structure iff the device type is PCI,
1287 * the device has the MediaTek vendor ID, and the MTCL feature is
1288 * configured.
1289 */
1290 if (CONFIG(USE_MTCL)) {
1291 if (dev->path.type == DEVICE_PATH_PCI &&
1292 dev->vendor == PCI_VID_MEDIATEK)
1293 write_mtcl_function();
1294 }
1295
1296 acpigen_write_scope_end(); /* Scope */
1297
1298 /* Fill Bluetooth companion SAR related ACPI structures and DSM functions. */
1299 if (sar_loaded && is_dev_enabled(config->bluetooth_companion)) {
1300 const char *path = acpi_device_path(config->bluetooth_companion);
1301 if (path) { /* Bluetooth device under USB Hub scope or PCIe root port */
1302 acpigen_write_scope(path);
1303 sar_emit_brds(sar_limits.bsar);
1304 sar_emit_bpag(sar_limits.bpag);
1305 sar_emit_bbfb(sar_limits.bbfb);
1306 sar_emit_bdcm(sar_limits.bdcm);
1307 sar_emit_bbsm(sar_limits.bbsm);
1308 sar_emit_bucs(sar_limits.bucs);
1309 sar_emit_bdmm(sar_limits.bdmm);
1310 sar_emit_ebrd(sar_limits.ebrd);
1311 sar_emit_dsbr(sar_limits.dsbr, DOMAIN_TYPE_BLUETOOTH);
1312
1313 if (config->bluetooth_companion->path.type == DEVICE_PATH_PCI &&
1314 config->bluetooth_companion->vendor == PCI_VID_INTEL) {
1315 struct dsm_uuid bt_dsm_ids = {
1316 .uuid = ACPI_DSM_RFIM_WIFI_UUID,
1317 .callbacks = bluetooth_dsm_callbacks,
1318 .count = ARRAY_SIZE(bluetooth_dsm_callbacks)
1319 };
1320 acpigen_write_dsm_uuid_arr(&bt_dsm_ids, 1);
1321 }
1322
1323 acpigen_write_scope_end();
1324 } else {
1325 printk(BIOS_ERR, "Failed to get %s Bluetooth companion ACPI path\n",
1326 dev_path(dev));
1327 }
1328 }
1329
1330 if (sar_loaded)
1331 free(sar_limits.sar);
1332
1333 printk(BIOS_INFO, "%s: %s %s\n", scope, dev->chip_ops ? dev->chip_ops->name : "",
1334 dev_path(dev));
1335 }
1336
1337 void wifi_pcie_fill_ssdt(const struct device *dev)
1338 {
1339 const char *path;
1340
1341 path = acpi_device_path(dev);
1342 if (!path)
1343 return;
1344
1345 wifi_ssdt_write_device(dev, path);
1346 wifi_ssdt_write_properties(dev, path);
1347 }
1348
1349 const char *wifi_pcie_acpi_name(const struct device *dev)
1350 {
1351 static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN];
1352
1353 /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */
1354 snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X",
1355 (dev_path_encode(dev) & 0xff));
1356 return wifi_acpi_name;
1357 }
1358
1359 #if CONFIG(SOC_INTEL_COMMON_BLOCK_CNVI)
1360 static void write_cnvi_control(const struct acpi_gpio *gpio)
1361 {
1362
1363 acpigen_write_scope("\\_SB.PCI0");
1364
1365 /*
1366 * CNVi Status
1367 *
1368 * Method (CNVS, 0)
1369 * {
1370 * Local0 = \_SB.PCI0.GTXS (gpio)
1371 * Return (Local0)
1372 * }
1373 */
1374 acpigen_write_method("CNVS", 0);
1375 {
1376 acpigen_get_tx_gpio(gpio);
1377 acpigen_write_return_op(LOCAL0_OP);
1378 }
1379 acpigen_pop_len();
1380 /*
1381 * CNVi Control
1382 *
1383 * Method (CNVC, 1, NotSerialized)
1384 * {
1385 * If ((Arg0 == One))
1386 * {
1387 * \_SB.PCI0.STXS (gpio)
1388 * }
1389 * Else
1390 * {
1391 * \_SB.PCI0.CTXS (gpio)
1392 * }
1393 * }
1394 */
1395 acpigen_write_method("CNVC", 1);
1396 {
1397 acpigen_write_if_lequal_op_int(ARG0_OP, 1);
1398 {
1399 acpigen_enable_tx_gpio(gpio);
1400 }
1401 acpigen_write_else();
1402 {
1403 acpigen_disable_tx_gpio(gpio);
1404 }
1405 acpigen_pop_len();
1406 }
1407 acpigen_pop_len();
1408
1409 acpigen_write_scope_end();
1410 }
1411 #endif
1412
1413 void wifi_cnvi_fill_ssdt(const struct device *dev)
1414 {
1415 const char *path;
1416 if (!dev)
1417 return;
1418
1419 path = acpi_device_path(dev->upstream->dev);
1420 if (!path)
1421 return;
1422
1423 wifi_ssdt_write_properties(dev, path);
1424
1425 #if CONFIG(SOC_INTEL_COMMON_BLOCK_CNVI)
1426 const struct drivers_wifi_generic_config *config = dev->chip_info;
1427 if (config->cnvi_enable_gpio.pin_count)
1428 write_cnvi_control(&config->cnvi_enable_gpio);
1429 #endif
1430 }