Debian Codegraph @

src/soc/intel/common/block/usb4/pcie.c

raw symbols SCIP
1 /* SPDX-License-Identifier: GPL-2.0-or-later */
2
3 #include <acpi/acpi_device.h>
4 #include <acpi/acpigen.h>
5 #include <console/console.h>
6 #include <device/device.h>
7 #include <string.h>
8
9 #include "chip.h"
10
11 #if CONFIG(HAVE_ACPI_TABLES)
12 static void usb4_pcie_acpi_fill_ssdt(const struct device *dev)
13 {
14 const struct soc_intel_common_block_usb4_config *config;
15 const struct device *parent;
16 struct acpi_dp *dsd;
17 const char *usb4_path;
18 int port_id;
19
20 /* Get parent PCI device */
21 parent = dev->upstream->dev;
22 if (!parent) {
23 printk(BIOS_ERR, "%s: Unable to find parent device\n", __func__);
24 return;
25 }
26
27 if (!parent->enabled)
28 return;
29
30 config = config_of(dev);
31 if (!config->usb4_port) {
32 printk(BIOS_ERR, "%s: Unable to find reference to usb4_port\n", __func__);
33 return;
34 }
35
36 /* Get ACPI path to USB4 device. */
37 usb4_path = acpi_device_path(config->usb4_port);
38 if (!usb4_path) {
39 printk(BIOS_ERR, "%s: Unable to find ACPI path for usb4_port %s\n",
40 __func__, dev_path(config->usb4_port));
41 return;
42 }
43
44 usb4_path = strdup(usb4_path);
45 port_id = dev->path.generic.id;
46
47 acpigen_write_scope(acpi_device_path(parent));
48
49 /* Add pointer to USB4 port controller. */
50 dsd = acpi_dp_new_table("_DSD");
51 acpi_dp_add_reference(dsd, "usb4-host-interface", usb4_path);
52 acpi_dp_add_integer(dsd, "usb4-port-number", port_id);
53
54 /* Indicate that device supports hotplug in D3. */
55 acpi_device_add_hotplug_support_in_d3(dsd);
56
57 /* Indicate that port is external. */
58 acpi_device_add_external_facing_port(dsd);
59
60 acpi_dp_write(dsd);
61
62 acpigen_pop_len(); /* Scope */
63
64 printk(BIOS_INFO, "%s: %s at %s\n", acpi_device_path(parent),
65 config->desc ? : dev->chip_ops->name, dev_path(parent));
66 }
67 #endif
68
69 static struct device_operations usb4_pcie_acpi_dev_ops = {
70 .read_resources = noop_read_resources,
71 .set_resources = noop_set_resources,
72 #if CONFIG(HAVE_ACPI_TABLES)
73 .acpi_fill_ssdt = usb4_pcie_acpi_fill_ssdt,
74 #endif
75 };
76
77 static void usb4_pcie_acpi_enable(struct device *dev)
78 {
79 dev->ops = &usb4_pcie_acpi_dev_ops;
80 }
81
82 struct chip_operations soc_intel_common_block_usb4_ops = {
83 .name = "Intel USB4 PCIe Root Port",
84 .enable_dev = usb4_pcie_acpi_enable
85 };