summaryrefslogtreecommitdiff
path: root/src/drivers
diff options
context:
space:
mode:
authorFurquan Shaikh <furquan@google.com>2020-10-27 19:46:11 -0700
committerPatrick Georgi <pgeorgi@google.com>2020-11-02 06:13:10 +0000
commit2736c82956d4c4969fd896688b8be0d16f3ab272 (patch)
tree5b53f29ff5bca59db8180e09177ef368d65e7aaf /src/drivers
parent507a98b689975561b54e5e156d624f7dcad6d393 (diff)
downloadcoreboot-2736c82956d4c4969fd896688b8be0d16f3ab272.tar.xz
drivers/wifi/generic: Move ACPI functions to a separate file
This change reorganizes the WiFi generic driver to move the ACPI functions to a separate file. This change is done to reduce the noise in generic.c file and improve readability of the file. Change-Id: If5fafb5452fb5bad327be730fcfc43d8a5d3b8ec Signed-off-by: Furquan Shaikh <furquan@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/46860 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Duncan Laurie <dlaurie@chromium.org>
Diffstat (limited to 'src/drivers')
-rw-r--r--src/drivers/wifi/generic/Makefile.inc1
-rw-r--r--src/drivers/wifi/generic/acpi.c231
-rw-r--r--src/drivers/wifi/generic/generic.c227
-rw-r--r--src/drivers/wifi/generic/wifi_private.h3
4 files changed, 235 insertions, 227 deletions
diff --git a/src/drivers/wifi/generic/Makefile.inc b/src/drivers/wifi/generic/Makefile.inc
index 3683c3eaad..c17844993d 100644
--- a/src/drivers/wifi/generic/Makefile.inc
+++ b/src/drivers/wifi/generic/Makefile.inc
@@ -3,6 +3,7 @@ ifeq ($(CONFIG_DRIVERS_WIFI_GENERIC),y)
ramstage-y += generic.c
ramstage-$(CONFIG_GENERATE_SMBIOS_TABLES) += smbios.c
+ramstage-$(CONFIG_HAVE_ACPI_TABLES) += acpi.c
cbfs-files-$(CONFIG_WIFI_SAR_CBFS) += wifi_sar_defaults.hex
wifi_sar_defaults.hex-file := $(call strip_quotes,$(CONFIG_WIFI_SAR_CBFS_FILEPATH))
diff --git a/src/drivers/wifi/generic/acpi.c b/src/drivers/wifi/generic/acpi.c
new file mode 100644
index 0000000000..f83d04ccc1
--- /dev/null
+++ b/src/drivers/wifi/generic/acpi.c
@@ -0,0 +1,231 @@
+/* SPDX-License-Identifier: GPL-2.0-only */
+
+#include <acpi/acpi_device.h>
+#include <acpi/acpigen.h>
+#include <console/console.h>
+#include <device/pci_ids.h>
+#include <sar.h>
+#include <wrdd.h>
+
+#include "chip.h"
+#include "wifi_private.h"
+
+/* WRDS Spec Revision */
+#define WRDS_REVISION 0x0
+
+/* EWRD Spec Revision */
+#define EWRD_REVISION 0x0
+
+/* WRDS Domain type */
+#define WRDS_DOMAIN_TYPE_WIFI 0x7
+
+/* EWRD Domain type */
+#define EWRD_DOMAIN_TYPE_WIFI 0x7
+
+/* WGDS Domain type */
+#define WGDS_DOMAIN_TYPE_WIFI 0x7
+
+/*
+ * WIFI ACPI NAME = "WF" + hex value of last 8 bits of dev_path_encode + '\0'
+ * The above representation returns unique and consistent name every time
+ * generate_wifi_acpi_name is invoked. The last 8 bits of dev_path_encode is
+ * chosen since it contains the bus address of the device.
+ */
+#define WIFI_ACPI_NAME_MAX_LEN 5
+
+__weak int get_wifi_sar_limits(struct wifi_sar_limits *sar_limits)
+{
+ return -1;
+}
+
+static void emit_sar_acpi_structures(const struct device *dev)
+{
+ int i, j, package_size;
+ struct wifi_sar_limits sar_limits;
+ struct wifi_sar_delta_table *wgds;
+
+ /* CBFS SAR and SAR ACPI tables are currently used only by Intel WiFi devices. */
+ if (dev->vendor != PCI_VENDOR_ID_INTEL)
+ return;
+
+ /* Retrieve the sar limits data */
+ if (get_wifi_sar_limits(&sar_limits) < 0) {
+ printk(BIOS_ERR, "Error: failed from getting SAR limits!\n");
+ return;
+ }
+
+ /*
+ * Name ("WRDS", Package () {
+ * Revision,
+ * Package () {
+ * Domain Type, // 0x7:WiFi
+ * WiFi SAR BIOS, // BIOS SAR Enable/disable
+ * SAR Table Set // Set#1 of SAR Table (10 bytes)
+ * }
+ * })
+ */
+ acpigen_write_name("WRDS");
+ acpigen_write_package(2);
+ acpigen_write_dword(WRDS_REVISION);
+ /* Emit 'Domain Type' + 'WiFi SAR BIOS' + 10 bytes for Set#1 */
+ package_size = 1 + 1 + BYTES_PER_SAR_LIMIT;
+ acpigen_write_package(package_size);
+ acpigen_write_dword(WRDS_DOMAIN_TYPE_WIFI);
+ acpigen_write_dword(CONFIG(SAR_ENABLE));
+ for (i = 0; i < BYTES_PER_SAR_LIMIT; i++)
+ acpigen_write_byte(sar_limits.sar_limit[0][i]);
+ acpigen_pop_len();
+ acpigen_pop_len();
+
+ /*
+ * Name ("EWRD", Package () {
+ * Revision,
+ * Package () {
+ * Domain Type, // 0x7:WiFi
+ * Dynamic SAR Enable, // Dynamic SAR Enable/disable
+ * Extended SAR sets, // Number of optional SAR table sets
+ * SAR Table Set, // Set#2 of SAR Table (10 bytes)
+ * SAR Table Set, // Set#3 of SAR Table (10 bytes)
+ * SAR Table Set // Set#4 of SAR Table (10 bytes)
+ * }
+ * })
+ */
+ acpigen_write_name("EWRD");
+ acpigen_write_package(2);
+ acpigen_write_dword(EWRD_REVISION);
+ /*
+ * Emit 'Domain Type' + "Dynamic SAR Enable' + 'Extended SAR sets'
+ * + number of bytes for Set#2 & 3 & 4
+ */
+ package_size = 1 + 1 + 1 + (NUM_SAR_LIMITS - 1) * BYTES_PER_SAR_LIMIT;
+ acpigen_write_package(package_size);
+ acpigen_write_dword(EWRD_DOMAIN_TYPE_WIFI);
+ acpigen_write_dword(CONFIG(DSAR_ENABLE));
+ acpigen_write_dword(CONFIG_DSAR_SET_NUM);
+ for (i = 1; i < NUM_SAR_LIMITS; i++)
+ for (j = 0; j < BYTES_PER_SAR_LIMIT; j++)
+ acpigen_write_byte(sar_limits.sar_limit[i][j]);
+ acpigen_pop_len();
+ acpigen_pop_len();
+
+ if (!CONFIG(GEO_SAR_ENABLE))
+ return;
+
+ /*
+ * Name ("WGDS", Package() {
+ * Revision,
+ * Package() {
+ * DomainType, // 0x7:WiFi
+ * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max
+ * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset
+ * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset
+ * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max
+ * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset
+ * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset
+ * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max
+ * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset
+ * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset
+ * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max
+ * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset
+ * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset
+ * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max
+ * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset
+ * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset
+ * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max
+ * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset
+ * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset
+ * }
+ * })
+ */
+
+ wgds = &sar_limits.wgds;
+ acpigen_write_name("WGDS");
+ acpigen_write_package(2);
+ acpigen_write_dword(wgds->version);
+ /* Emit 'Domain Type' +
+ * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS)
+ */
+ package_size = sizeof(sar_limits.wgds.group) + 1;
+ acpigen_write_package(package_size);
+ acpigen_write_dword(WGDS_DOMAIN_TYPE_WIFI);
+ for (i = 0; i < SAR_NUM_WGDS_GROUPS; i++) {
+ acpigen_write_byte(wgds->group[i].power_max_2400mhz);
+ acpigen_write_byte(wgds->group[i].power_chain_a_2400mhz);
+ acpigen_write_byte(wgds->group[i].power_chain_b_2400mhz);
+ acpigen_write_byte(wgds->group[i].power_max_5200mhz);
+ acpigen_write_byte(wgds->group[i].power_chain_a_5200mhz);
+ acpigen_write_byte(wgds->group[i].power_chain_b_5200mhz);
+ }
+
+ acpigen_pop_len();
+ acpigen_pop_len();
+}
+
+void wifi_generic_fill_ssdt(const struct device *dev)
+{
+ const char *path;
+ const struct drivers_wifi_generic_config *config = dev->chip_info;
+
+ if (!dev->enabled)
+ return;
+
+ path = acpi_device_path(dev->bus->dev);
+ if (!path)
+ return;
+
+ /* Device */
+ acpigen_write_scope(path);
+ acpigen_write_device(acpi_device_name(dev));
+ acpi_device_write_uid(dev);
+
+ if (dev->chip_ops)
+ acpigen_write_name_string("_DDN", dev->chip_ops->name);
+
+ /* Address */
+ acpigen_write_ADR_pci_device(dev);
+
+ /* Wake capabilities */
+ if (config)
+ acpigen_write_PRW(config->wake, ACPI_S3);
+
+ /* Fill regulatory domain structure */
+ if (CONFIG(HAVE_REGULATORY_DOMAIN)) {
+ /*
+ * Name ("WRDD", Package () {
+ * WRDD_REVISION, // Revision
+ * Package () {
+ * WRDD_DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
+ * wifi_regulatory_domain() // Country Identifier
+ * }
+ * })
+ */
+ acpigen_write_name("WRDD");
+ acpigen_write_package(2);
+ acpigen_write_integer(WRDD_REVISION);
+ acpigen_write_package(2);
+ acpigen_write_dword(WRDD_DOMAIN_TYPE_WIFI);
+ acpigen_write_dword(wifi_regulatory_domain());
+ acpigen_pop_len();
+ acpigen_pop_len();
+ }
+
+ /* Fill Wifi sar related ACPI structures */
+ if (CONFIG(USE_SAR))
+ emit_sar_acpi_structures(dev);
+
+ acpigen_pop_len(); /* Device */
+ acpigen_pop_len(); /* Scope */
+
+ printk(BIOS_INFO, "%s.%s: %s %s\n", path, acpi_device_name(dev),
+ dev->chip_ops ? dev->chip_ops->name : "", dev_path(dev));
+}
+
+const char *wifi_generic_acpi_name(const struct device *dev)
+{
+ static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN];
+
+ /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */
+ snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X",
+ (dev_path_encode(dev) & 0xff));
+ return wifi_acpi_name;
+}
diff --git a/src/drivers/wifi/generic/generic.c b/src/drivers/wifi/generic/generic.c
index 56944e61da..fcb7294ac8 100644
--- a/src/drivers/wifi/generic/generic.c
+++ b/src/drivers/wifi/generic/generic.c
@@ -1,241 +1,14 @@
/* SPDX-License-Identifier: GPL-2.0-only */
-#include <acpi/acpi_device.h>
-#include <acpi/acpigen.h>
#include <console/console.h>
#include <device/device.h>
#include <device/pci.h>
#include <device/pci_def.h>
#include <device/pci_ids.h>
#include <elog.h>
-#include <sar.h>
-#include <wrdd.h>
#include "chip.h"
#include "wifi_private.h"
-/* WRDS Spec Revision */
-#define WRDS_REVISION 0x0
-
-/* EWRD Spec Revision */
-#define EWRD_REVISION 0x0
-
-/* WRDS Domain type */
-#define WRDS_DOMAIN_TYPE_WIFI 0x7
-
-/* EWRD Domain type */
-#define EWRD_DOMAIN_TYPE_WIFI 0x7
-
-/* WGDS Domain type */
-#define WGDS_DOMAIN_TYPE_WIFI 0x7
-
-/*
- * WIFI ACPI NAME = "WF" + hex value of last 8 bits of dev_path_encode + '\0'
- * The above representation returns unique and consistent name every time
- * generate_wifi_acpi_name is invoked. The last 8 bits of dev_path_encode is
- * chosen since it contains the bus address of the device.
- */
-#define WIFI_ACPI_NAME_MAX_LEN 5
-
-#if CONFIG(HAVE_ACPI_TABLES)
-__weak
-int get_wifi_sar_limits(struct wifi_sar_limits *sar_limits)
-{
- return -1;
-}
-
-static void emit_sar_acpi_structures(const struct device *dev)
-{
- int i, j, package_size;
- struct wifi_sar_limits sar_limits;
- struct wifi_sar_delta_table *wgds;
-
- /* CBFS SAR and SAR ACPI tables are currently used only by Intel WiFi devices. */
- if (dev->vendor != PCI_VENDOR_ID_INTEL)
- return;
-
- /* Retrieve the sar limits data */
- if (get_wifi_sar_limits(&sar_limits) < 0) {
- printk(BIOS_ERR, "Error: failed from getting SAR limits!\n");
- return;
- }
-
- /*
- * Name ("WRDS", Package () {
- * Revision,
- * Package () {
- * Domain Type, // 0x7:WiFi
- * WiFi SAR BIOS, // BIOS SAR Enable/disable
- * SAR Table Set // Set#1 of SAR Table (10 bytes)
- * }
- * })
- */
- acpigen_write_name("WRDS");
- acpigen_write_package(2);
- acpigen_write_dword(WRDS_REVISION);
- /* Emit 'Domain Type' + 'WiFi SAR BIOS' + 10 bytes for Set#1 */
- package_size = 1 + 1 + BYTES_PER_SAR_LIMIT;
- acpigen_write_package(package_size);
- acpigen_write_dword(WRDS_DOMAIN_TYPE_WIFI);
- acpigen_write_dword(CONFIG(SAR_ENABLE));
- for (i = 0; i < BYTES_PER_SAR_LIMIT; i++)
- acpigen_write_byte(sar_limits.sar_limit[0][i]);
- acpigen_pop_len();
- acpigen_pop_len();
-
- /*
- * Name ("EWRD", Package () {
- * Revision,
- * Package () {
- * Domain Type, // 0x7:WiFi
- * Dynamic SAR Enable, // Dynamic SAR Enable/disable
- * Extended SAR sets, // Number of optional SAR table sets
- * SAR Table Set, // Set#2 of SAR Table (10 bytes)
- * SAR Table Set, // Set#3 of SAR Table (10 bytes)
- * SAR Table Set // Set#4 of SAR Table (10 bytes)
- * }
- * })
- */
- acpigen_write_name("EWRD");
- acpigen_write_package(2);
- acpigen_write_dword(EWRD_REVISION);
- /*
- * Emit 'Domain Type' + "Dynamic SAR Enable' + 'Extended SAR sets'
- * + number of bytes for Set#2 & 3 & 4
- */
- package_size = 1 + 1 + 1 + (NUM_SAR_LIMITS - 1) * BYTES_PER_SAR_LIMIT;
- acpigen_write_package(package_size);
- acpigen_write_dword(EWRD_DOMAIN_TYPE_WIFI);
- acpigen_write_dword(CONFIG(DSAR_ENABLE));
- acpigen_write_dword(CONFIG_DSAR_SET_NUM);
- for (i = 1; i < NUM_SAR_LIMITS; i++)
- for (j = 0; j < BYTES_PER_SAR_LIMIT; j++)
- acpigen_write_byte(sar_limits.sar_limit[i][j]);
- acpigen_pop_len();
- acpigen_pop_len();
-
- if (!CONFIG(GEO_SAR_ENABLE))
- return;
-
- /*
- * Name ("WGDS", Package() {
- * Revision,
- * Package() {
- * DomainType, // 0x7:WiFi
- * WgdsWiFiSarDeltaGroup1PowerMax1, // Group 1 FCC 2400 Max
- * WgdsWiFiSarDeltaGroup1PowerChainA1, // Group 1 FCC 2400 A Offset
- * WgdsWiFiSarDeltaGroup1PowerChainB1, // Group 1 FCC 2400 B Offset
- * WgdsWiFiSarDeltaGroup1PowerMax2, // Group 1 FCC 5200 Max
- * WgdsWiFiSarDeltaGroup1PowerChainA2, // Group 1 FCC 5200 A Offset
- * WgdsWiFiSarDeltaGroup1PowerChainB2, // Group 1 FCC 5200 B Offset
- * WgdsWiFiSarDeltaGroup2PowerMax1, // Group 2 EC Jap 2400 Max
- * WgdsWiFiSarDeltaGroup2PowerChainA1, // Group 2 EC Jap 2400 A Offset
- * WgdsWiFiSarDeltaGroup2PowerChainB1, // Group 2 EC Jap 2400 B Offset
- * WgdsWiFiSarDeltaGroup2PowerMax2, // Group 2 EC Jap 5200 Max
- * WgdsWiFiSarDeltaGroup2PowerChainA2, // Group 2 EC Jap 5200 A Offset
- * WgdsWiFiSarDeltaGroup2PowerChainB2, // Group 2 EC Jap 5200 B Offset
- * WgdsWiFiSarDeltaGroup3PowerMax1, // Group 3 ROW 2400 Max
- * WgdsWiFiSarDeltaGroup3PowerChainA1, // Group 3 ROW 2400 A Offset
- * WgdsWiFiSarDeltaGroup3PowerChainB1, // Group 3 ROW 2400 B Offset
- * WgdsWiFiSarDeltaGroup3PowerMax2, // Group 3 ROW 5200 Max
- * WgdsWiFiSarDeltaGroup3PowerChainA2, // Group 3 ROW 5200 A Offset
- * WgdsWiFiSarDeltaGroup3PowerChainB2, // Group 3 ROW 5200 B Offset
- * }
- * })
- */
-
- wgds = &sar_limits.wgds;
- acpigen_write_name("WGDS");
- acpigen_write_package(2);
- acpigen_write_dword(wgds->version);
- /* Emit 'Domain Type' +
- * Group specific delta of power (6 bytes * NUM_WGDS_SAR_GROUPS)
- */
- package_size = sizeof(sar_limits.wgds.group) + 1;
- acpigen_write_package(package_size);
- acpigen_write_dword(WGDS_DOMAIN_TYPE_WIFI);
- for (i = 0; i < SAR_NUM_WGDS_GROUPS; i++) {
- acpigen_write_byte(wgds->group[i].power_max_2400mhz);
- acpigen_write_byte(wgds->group[i].power_chain_a_2400mhz);
- acpigen_write_byte(wgds->group[i].power_chain_b_2400mhz);
- acpigen_write_byte(wgds->group[i].power_max_5200mhz);
- acpigen_write_byte(wgds->group[i].power_chain_a_5200mhz);
- acpigen_write_byte(wgds->group[i].power_chain_b_5200mhz);
- }
-
- acpigen_pop_len();
- acpigen_pop_len();
-}
-
-static void wifi_generic_fill_ssdt(const struct device *dev)
-{
- const char *path;
- const struct drivers_wifi_generic_config *config = dev->chip_info;
-
- if (!dev->enabled)
- return;
-
- path = acpi_device_path(dev->bus->dev);
- if (!path)
- return;
-
- /* Device */
- acpigen_write_scope(path);
- acpigen_write_device(acpi_device_name(dev));
- acpi_device_write_uid(dev);
-
- if (dev->chip_ops)
- acpigen_write_name_string("_DDN", dev->chip_ops->name);
-
- /* Address */
- acpigen_write_ADR_pci_device(dev);
-
- /* Wake capabilities */
- if (config)
- acpigen_write_PRW(config->wake, ACPI_S3);
-
- /* Fill regulatory domain structure */
- if (CONFIG(HAVE_REGULATORY_DOMAIN)) {
- /*
- * Name ("WRDD", Package () {
- * WRDD_REVISION, // Revision
- * Package () {
- * WRDD_DOMAIN_TYPE_WIFI, // Domain Type, 7:WiFi
- * wifi_regulatory_domain() // Country Identifier
- * }
- * })
- */
- acpigen_write_name("WRDD");
- acpigen_write_package(2);
- acpigen_write_integer(WRDD_REVISION);
- acpigen_write_package(2);
- acpigen_write_dword(WRDD_DOMAIN_TYPE_WIFI);
- acpigen_write_dword(wifi_regulatory_domain());
- acpigen_pop_len();
- acpigen_pop_len();
- }
-
- /* Fill Wifi sar related ACPI structures */
- if (CONFIG(USE_SAR))
- emit_sar_acpi_structures(dev);
-
- acpigen_pop_len(); /* Device */
- acpigen_pop_len(); /* Scope */
-
- printk(BIOS_INFO, "%s.%s: %s %s\n", path, acpi_device_name(dev),
- dev->chip_ops ? dev->chip_ops->name : "", dev_path(dev));
-}
-
-static const char *wifi_generic_acpi_name(const struct device *dev)
-{
- static char wifi_acpi_name[WIFI_ACPI_NAME_MAX_LEN];
-
- /* ACPI 6.3, ASL 20.2.2: (Name Objects Encoding). */
- snprintf(wifi_acpi_name, sizeof(wifi_acpi_name), "WF%02X",
- (dev_path_encode(dev) & 0xff));
- return wifi_acpi_name;
-}
-#endif
-
static void wifi_pci_dev_init(struct device *dev)
{
if (pci_dev_is_wake_source(dev))
diff --git a/src/drivers/wifi/generic/wifi_private.h b/src/drivers/wifi/generic/wifi_private.h
index 11b9198320..39cdfedf7c 100644
--- a/src/drivers/wifi/generic/wifi_private.h
+++ b/src/drivers/wifi/generic/wifi_private.h
@@ -5,4 +5,7 @@
int smbios_write_wifi(struct device *dev, int *handle, unsigned long *current);
+const char *wifi_generic_acpi_name(const struct device *dev);
+void wifi_generic_fill_ssdt(const struct device *dev);
+
#endif