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> |
Felix Held | 0ffebac | 2021-02-05 22:26:00 +0100 | [diff] [blame] | 8 | #include <device/device.h> |
| 9 | #include <device/pci.h> |
| 10 | #include <device/pci_ids.h> |
Felix Held | 0810538 | 2021-02-16 18:46:01 +0100 | [diff] [blame] | 11 | #include <device/pciexp.h> |
Raul E Rangel | f2df29e | 2021-03-16 13:23:38 -0600 | [diff] [blame] | 12 | #include <soc/pci_devs.h> |
Raul E Rangel | 14734fc | 2021-05-03 16:56:34 -0600 | [diff] [blame] | 13 | #include <stdio.h> |
| 14 | #include <stdlib.h> |
Raul E Rangel | f2df29e | 2021-03-16 13:23:38 -0600 | [diff] [blame] | 15 | |
| 16 | static const char *pcie_gpp_acpi_name(const struct device *dev) |
| 17 | { |
Raul E Rangel | 14734fc | 2021-05-03 16:56:34 -0600 | [diff] [blame] | 18 | char *name; |
| 19 | |
Raul E Rangel | f2df29e | 2021-03-16 13:23:38 -0600 | [diff] [blame] | 20 | if (dev->path.type != DEVICE_PATH_PCI) |
| 21 | return NULL; |
| 22 | |
Raul E Rangel | 14734fc | 2021-05-03 16:56:34 -0600 | [diff] [blame] | 23 | name = malloc(ACPI_NAME_BUFFER_SIZE); |
Raul E Rangel | 556412b | 2021-05-10 15:04:57 -0600 | [diff] [blame] | 24 | snprintf(name, ACPI_NAME_BUFFER_SIZE, "GP%02X", dev->path.pci.devfn); |
Raul E Rangel | 14734fc | 2021-05-03 16:56:34 -0600 | [diff] [blame] | 25 | name[4] = '\0'; |
| 26 | |
| 27 | return name; |
Raul E Rangel | f2df29e | 2021-03-16 13:23:38 -0600 | [diff] [blame] | 28 | } |
Felix Held | 0ffebac | 2021-02-05 22:26:00 +0100 | [diff] [blame] | 29 | |
Raul E Rangel | f486fcc | 2021-03-16 20:29:06 -0600 | [diff] [blame] | 30 | static 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 Rangel | 506ee24 | 2021-05-07 12:30:49 -0600 | [diff] [blame] | 45 | acpigen_write_pci_GNB_PRT(dev); |
Raul E Rangel | f486fcc | 2021-03-16 20:29:06 -0600 | [diff] [blame] | 46 | |
| 47 | acpigen_pop_len(); /* Device */ |
| 48 | acpigen_pop_len(); /* Scope */ |
| 49 | } |
| 50 | |
Felix Held | 0ffebac | 2021-02-05 22:26:00 +0100 | [diff] [blame] | 51 | static 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 Rangel | f2df29e | 2021-03-16 13:23:38 -0600 | [diff] [blame] | 57 | .acpi_name = pcie_gpp_acpi_name, |
Raul E Rangel | f486fcc | 2021-03-16 20:29:06 -0600 | [diff] [blame] | 58 | .acpi_fill_ssdt = acpi_device_write_gpp_pci_dev, |
Felix Held | 0ffebac | 2021-02-05 22:26:00 +0100 | [diff] [blame] | 59 | }; |
| 60 | |
Raul E Rangel | 4831411 | 2021-05-10 14:55:11 -0600 | [diff] [blame] | 61 | static const unsigned short internal_pci_gpp_ids[] = { |
| 62 | PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_PCIE_GPP_BUSA, |
| 63 | PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_PCIE_GPP_BUSB, |
| 64 | PCI_DEVICE_ID_AMD_FAM17H_MODEL60H_PCIE_GPP_BUSABC, |
Felix Held | caa83ab | 2021-11-09 00:55:38 +0100 | [diff] [blame^] | 65 | PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_PCIE_GPP_BUSABC, |
Raul E Rangel | 4831411 | 2021-05-10 14:55:11 -0600 | [diff] [blame] | 66 | 0 |
| 67 | }; |
| 68 | |
Felix Held | 0ffebac | 2021-02-05 22:26:00 +0100 | [diff] [blame] | 69 | static const struct pci_driver internal_pcie_gpp_driver __pci_driver = { |
| 70 | .ops = &internal_pcie_gpp_ops, |
| 71 | .vendor = PCI_VENDOR_ID_AMD, |
Raul E Rangel | 4831411 | 2021-05-10 14:55:11 -0600 | [diff] [blame] | 72 | .devices = internal_pci_gpp_ids, |
Felix Held | 0ffebac | 2021-02-05 22:26:00 +0100 | [diff] [blame] | 73 | }; |
Felix Held | 0810538 | 2021-02-16 18:46:01 +0100 | [diff] [blame] | 74 | |
| 75 | static 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 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 | 0810538 | 2021-02-16 18:46:01 +0100 | [diff] [blame] | 83 | }; |
| 84 | |
| 85 | static const unsigned short external_pci_gpp_ids[] = { |
Raul E Rangel | 4831411 | 2021-05-10 14:55:11 -0600 | [diff] [blame] | 86 | PCI_DEVICE_ID_AMD_FAM17H_MODEL18H_PCIE_GPP, |
Felix Held | 0810538 | 2021-02-16 18:46:01 +0100 | [diff] [blame] | 87 | PCI_DEVICE_ID_AMD_FAM17H_MODEL60H_PCIE_GPP_D1, |
| 88 | PCI_DEVICE_ID_AMD_FAM17H_MODEL60H_PCIE_GPP_D2, |
Felix Held | caa83ab | 2021-11-09 00:55:38 +0100 | [diff] [blame^] | 89 | PCI_DEVICE_ID_AMD_FAM17H_MODELA0H_PCIE_GPP, |
Felix Held | 0810538 | 2021-02-16 18:46:01 +0100 | [diff] [blame] | 90 | 0 |
| 91 | }; |
| 92 | |
| 93 | static const struct pci_driver external_pcie_gpp_driver __pci_driver = { |
| 94 | .ops = &external_pcie_gpp_ops, |
| 95 | .vendor = PCI_VENDOR_ID_AMD, |
| 96 | .devices = external_pci_gpp_ids, |
| 97 | }; |