Felix Held | 0ffebac | 2021-02-05 22:26:00 +0100 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-or-later */ |
| 2 | |
Raul E Rangel | f2df29e | 2021-03-16 13:23:38 -0600 | [diff] [blame] | 3 | #include <acpi/acpi_device.h> |
Raul E Rangel | f486fcc | 2021-03-16 20:29:06 -0600 | [diff] [blame] | 4 | #include <acpi/acpigen.h> |
| 5 | #include <acpi/acpigen_pci.h> |
| 6 | #include <amdblocks/amd_pci_util.h> |
| 7 | #include <assert.h> |
Raul E Rangel | f2df29e | 2021-03-16 13:23:38 -0600 | [diff] [blame] | 8 | #include <console/console.h> |
Felix Held | 0ffebac | 2021-02-05 22:26:00 +0100 | [diff] [blame] | 9 | #include <device/device.h> |
| 10 | #include <device/pci.h> |
| 11 | #include <device/pci_ids.h> |
Felix Held | 0810538 | 2021-02-16 18:46:01 +0100 | [diff] [blame] | 12 | #include <device/pciexp.h> |
Raul E Rangel | f2df29e | 2021-03-16 13:23:38 -0600 | [diff] [blame] | 13 | #include <soc/pci_devs.h> |
| 14 | |
| 15 | static const char *pcie_gpp_acpi_name(const struct device *dev) |
| 16 | { |
| 17 | if (dev->path.type != DEVICE_PATH_PCI) |
| 18 | return NULL; |
| 19 | |
| 20 | switch (dev->path.pci.devfn) { |
| 21 | case PCIE_GPP_1_0_DEVFN: |
| 22 | return "GP10"; |
| 23 | case PCIE_GPP_1_1_DEVFN: |
| 24 | return "GP11"; |
| 25 | case PCIE_GPP_1_2_DEVFN: |
| 26 | return "GP12"; |
| 27 | case PCIE_GPP_2_0_DEVFN: |
| 28 | return "GP20"; |
| 29 | case PCIE_GPP_2_1_DEVFN: |
| 30 | return "GP21"; |
| 31 | case PCIE_GPP_2_2_DEVFN: |
| 32 | return "GP22"; |
| 33 | case PCIE_GPP_2_3_DEVFN: |
| 34 | return "GP23"; |
| 35 | case PCIE_GPP_2_4_DEVFN: |
| 36 | return "GP24"; |
| 37 | case PCIE_GPP_2_5_DEVFN: |
| 38 | return "GP25"; |
| 39 | case PCIE_GPP_2_6_DEVFN: |
| 40 | return "GP26"; |
| 41 | case PCIE_ABC_A_DEVFN: |
| 42 | return "GPPA"; |
| 43 | case PCIE_GPP_B_DEVFN: |
| 44 | return "GPPB"; |
| 45 | case PCIE_GPP_C_DEVFN: |
| 46 | return "GPPC"; |
| 47 | default: |
| 48 | printk(BIOS_ERR, "%s: Unhanded devfn 0x%x\n", __func__, dev->path.pci.devfn); |
| 49 | return NULL; |
| 50 | } |
| 51 | } |
Felix Held | 0ffebac | 2021-02-05 22:26:00 +0100 | [diff] [blame] | 52 | |
Raul E Rangel | f486fcc | 2021-03-16 20:29:06 -0600 | [diff] [blame] | 53 | static void acpi_device_write_gpp_pci_dev(const struct device *dev) |
| 54 | { |
| 55 | const char *scope = acpi_device_scope(dev); |
| 56 | const char *name = acpi_device_name(dev); |
| 57 | |
| 58 | assert(dev->path.type == DEVICE_PATH_PCI); |
| 59 | assert(name); |
| 60 | assert(scope); |
| 61 | |
| 62 | acpigen_write_scope(scope); |
| 63 | acpigen_write_device(name); |
| 64 | |
| 65 | acpigen_write_ADR_pci_device(dev); |
| 66 | acpigen_write_STA(acpi_device_status(dev)); |
| 67 | |
| 68 | /* b/187083211 - Enable GNB IO-APIC */ |
| 69 | acpigen_write_pci_FCH_PRT(dev); |
| 70 | |
| 71 | acpigen_pop_len(); /* Device */ |
| 72 | acpigen_pop_len(); /* Scope */ |
| 73 | } |
| 74 | |
Felix Held | 0ffebac | 2021-02-05 22:26:00 +0100 | [diff] [blame] | 75 | static struct device_operations internal_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 = pci_scan_bridge, |
| 80 | .reset_bus = pci_bus_reset, |
Raul E Rangel | f2df29e | 2021-03-16 13:23:38 -0600 | [diff] [blame] | 81 | .acpi_name = pcie_gpp_acpi_name, |
Raul E Rangel | f486fcc | 2021-03-16 20:29:06 -0600 | [diff] [blame] | 82 | .acpi_fill_ssdt = acpi_device_write_gpp_pci_dev, |
Felix Held | 0ffebac | 2021-02-05 22:26:00 +0100 | [diff] [blame] | 83 | }; |
| 84 | |
Felix Held | 0ffebac | 2021-02-05 22:26:00 +0100 | [diff] [blame] | 85 | static const struct pci_driver internal_pcie_gpp_driver __pci_driver = { |
| 86 | .ops = &internal_pcie_gpp_ops, |
| 87 | .vendor = PCI_VENDOR_ID_AMD, |
Felix Held | abeecec | 2021-02-16 18:42:15 +0100 | [diff] [blame] | 88 | .device = PCI_DEVICE_ID_AMD_FAM17H_MODEL60H_PCIE_GPP_BUSABC, |
Felix Held | 0ffebac | 2021-02-05 22:26:00 +0100 | [diff] [blame] | 89 | }; |
Felix Held | 0810538 | 2021-02-16 18:46:01 +0100 | [diff] [blame] | 90 | |
| 91 | static struct device_operations external_pcie_gpp_ops = { |
| 92 | .read_resources = pci_bus_read_resources, |
| 93 | .set_resources = pci_dev_set_resources, |
| 94 | .enable_resources = pci_bus_enable_resources, |
| 95 | .scan_bus = pciexp_scan_bridge, |
| 96 | .reset_bus = pci_bus_reset, |
Raul E Rangel | f2df29e | 2021-03-16 13:23:38 -0600 | [diff] [blame] | 97 | .acpi_name = pcie_gpp_acpi_name, |
Raul E Rangel | f486fcc | 2021-03-16 20:29:06 -0600 | [diff] [blame] | 98 | .acpi_fill_ssdt = acpi_device_write_gpp_pci_dev, |
Felix Held | 0810538 | 2021-02-16 18:46:01 +0100 | [diff] [blame] | 99 | }; |
| 100 | |
| 101 | static const unsigned short external_pci_gpp_ids[] = { |
| 102 | PCI_DEVICE_ID_AMD_FAM17H_MODEL60H_PCIE_GPP_D1, |
| 103 | PCI_DEVICE_ID_AMD_FAM17H_MODEL60H_PCIE_GPP_D2, |
| 104 | 0 |
| 105 | }; |
| 106 | |
| 107 | static const struct pci_driver external_pcie_gpp_driver __pci_driver = { |
| 108 | .ops = &external_pcie_gpp_ops, |
| 109 | .vendor = PCI_VENDOR_ID_AMD, |
| 110 | .devices = external_pci_gpp_ids, |
| 111 | }; |