blob: 2e37935da4e26b89c41a4bffdfd01eca2f1ab980 [file] [log] [blame]
Felix Held0ffebac2021-02-05 22:26:00 +01001/* SPDX-License-Identifier: GPL-2.0-or-later */
2
Raul E Rangelf2df29e2021-03-16 13:23:38 -06003#include <acpi/acpi_device.h>
Raul E Rangelf486fcc2021-03-16 20:29:06 -06004#include <acpi/acpigen.h>
5#include <acpi/acpigen_pci.h>
6#include <amdblocks/amd_pci_util.h>
7#include <assert.h>
Felix Held0ffebac2021-02-05 22:26:00 +01008#include <device/device.h>
9#include <device/pci.h>
10#include <device/pci_ids.h>
Felix Held08105382021-02-16 18:46:01 +010011#include <device/pciexp.h>
Raul E Rangelf2df29e2021-03-16 13:23:38 -060012#include <soc/pci_devs.h>
Raul E Rangel14734fc2021-05-03 16:56:34 -060013#include <stdio.h>
14#include <stdlib.h>
Raul E Rangelf2df29e2021-03-16 13:23:38 -060015
16static const char *pcie_gpp_acpi_name(const struct device *dev)
17{
Raul E Rangel14734fc2021-05-03 16:56:34 -060018 char *name;
19
Raul E Rangelf2df29e2021-03-16 13:23:38 -060020 if (dev->path.type != DEVICE_PATH_PCI)
21 return NULL;
22
Raul E Rangel14734fc2021-05-03 16:56:34 -060023 name = malloc(ACPI_NAME_BUFFER_SIZE);
Raul E Rangel556412b2021-05-10 15:04:57 -060024 snprintf(name, ACPI_NAME_BUFFER_SIZE, "GP%02X", dev->path.pci.devfn);
Raul E Rangel14734fc2021-05-03 16:56:34 -060025 name[4] = '\0';
26
27 return name;
Raul E Rangelf2df29e2021-03-16 13:23:38 -060028}
Felix Held0ffebac2021-02-05 22:26:00 +010029
Raul E Rangelf486fcc2021-03-16 20:29:06 -060030static void acpi_device_write_gpp_pci_dev(const struct device *dev)
31{
32 const char *scope = acpi_device_scope(dev);
33 const char *name = acpi_device_name(dev);
34
35 assert(dev->path.type == DEVICE_PATH_PCI);
36 assert(name);
37 assert(scope);
38
39 acpigen_write_scope(scope);
40 acpigen_write_device(name);
41
42 acpigen_write_ADR_pci_device(dev);
43 acpigen_write_STA(acpi_device_status(dev));
44
Raul E Rangel506ee242021-05-07 12:30:49 -060045 acpigen_write_pci_GNB_PRT(dev);
Raul E Rangelf486fcc2021-03-16 20:29:06 -060046
47 acpigen_pop_len(); /* Device */
48 acpigen_pop_len(); /* Scope */
49}
50
Felix Held0ffebac2021-02-05 22:26:00 +010051static struct device_operations internal_pcie_gpp_ops = {
52 .read_resources = pci_bus_read_resources,
53 .set_resources = pci_dev_set_resources,
54 .enable_resources = pci_bus_enable_resources,
55 .scan_bus = pci_scan_bridge,
56 .reset_bus = pci_bus_reset,
Raul E Rangelf2df29e2021-03-16 13:23:38 -060057 .acpi_name = pcie_gpp_acpi_name,
Raul E Rangelf486fcc2021-03-16 20:29:06 -060058 .acpi_fill_ssdt = acpi_device_write_gpp_pci_dev,
Felix Held0ffebac2021-02-05 22:26:00 +010059};
60
Raul E Rangel48314112021-05-10 14:55:11 -060061static const unsigned short internal_pci_gpp_ids[] = {
Felix Singer43b7f412022-03-07 04:34:52 +010062 PCI_DID_AMD_FAM17H_MODEL18H_PCIE_GPP_BUSA,
63 PCI_DID_AMD_FAM17H_MODEL18H_PCIE_GPP_BUSB,
64 PCI_DID_AMD_FAM17H_MODEL60H_PCIE_GPP_BUSABC,
65 PCI_DID_AMD_FAM17H_MODELA0H_PCIE_GPP_BUSABC,
Raul E Rangel48314112021-05-10 14:55:11 -060066 0
67};
68
Felix Held0ffebac2021-02-05 22:26:00 +010069static const struct pci_driver internal_pcie_gpp_driver __pci_driver = {
70 .ops = &internal_pcie_gpp_ops,
Felix Singer43b7f412022-03-07 04:34:52 +010071 .vendor = PCI_VID_AMD,
Raul E Rangel48314112021-05-10 14:55:11 -060072 .devices = internal_pci_gpp_ids,
Felix Held0ffebac2021-02-05 22:26:00 +010073};
Felix Held08105382021-02-16 18:46:01 +010074
75static struct device_operations external_pcie_gpp_ops = {
76 .read_resources = pci_bus_read_resources,
77 .set_resources = pci_dev_set_resources,
78 .enable_resources = pci_bus_enable_resources,
79 .scan_bus = pciexp_scan_bridge,
80 .reset_bus = pci_bus_reset,
Raul E Rangelf2df29e2021-03-16 13:23:38 -060081 .acpi_name = pcie_gpp_acpi_name,
Raul E Rangelf486fcc2021-03-16 20:29:06 -060082 .acpi_fill_ssdt = acpi_device_write_gpp_pci_dev,
Felix Held08105382021-02-16 18:46:01 +010083};
84
85static const unsigned short external_pci_gpp_ids[] = {
Felix Singer43b7f412022-03-07 04:34:52 +010086 PCI_DID_AMD_FAM17H_MODEL18H_PCIE_GPP,
87 PCI_DID_AMD_FAM17H_MODEL60H_PCIE_GPP_D1,
88 PCI_DID_AMD_FAM17H_MODEL60H_PCIE_GPP_D2,
89 PCI_DID_AMD_FAM17H_MODELA0H_PCIE_GPP,
Felix Held08105382021-02-16 18:46:01 +010090 0
91};
92
93static const struct pci_driver external_pcie_gpp_driver __pci_driver = {
94 .ops = &external_pcie_gpp_ops,
Felix Singer43b7f412022-03-07 04:34:52 +010095 .vendor = PCI_VID_AMD,
Felix Held08105382021-02-16 18:46:01 +010096 .devices = external_pci_gpp_ids,
97};