| 1 |
|
| 2 |
|
| 3 |
#include <acpi/acpi_device.h> |
| 4 |
#include <acpi/acpigen.h> |
| 5 |
#include <acpi/acpigen_pci.h> |
| 6 |
#include <amdblocks/amd_pci_util.h> |
| 7 |
#include <assert.h> |
| 8 |
#include <device/device.h> |
| 9 |
#include <device/pci.h> |
| 10 |
#include <device/pciexp.h> |
| 11 |
#include <soc/pci_devs.h> |
| 12 |
#include <stdio.h> |
| 13 |
#include <stdlib.h> |
| 14 |
|
| 15 |
static const char *pcie_gpp_acpi_name(const struct device *dev) |
| 16 |
{ |
| 17 |
char *name; |
| 18 |
|
| 19 |
if (dev->path.type != DEVICE_PATH_PCI) |
| 20 |
return NULL; |
| 21 |
|
| 22 |
name = malloc(ACPI_NAME_BUFFER_SIZE); |
| 23 |
snprintf(name, ACPI_NAME_BUFFER_SIZE, "GP%02X", dev->path.pci.devfn); |
| 24 |
name[4] = '\0'; |
| 25 |
|
| 26 |
return name; |
| 27 |
} |
| 28 |
|
| 29 |
static void acpi_device_write_gpp_pci_dev(const struct device *dev) |
| 30 |
{ |
| 31 |
const char *scope = acpi_device_scope(dev); |
| 32 |
const char *name = acpi_device_name(dev); |
| 33 |
|
| 34 |
assert(dev->path.type == DEVICE_PATH_PCI); |
| 35 |
assert(name); |
| 36 |
assert(scope); |
| 37 |
|
| 38 |
acpigen_write_scope(scope); |
| 39 |
acpigen_write_device(name); |
| 40 |
|
| 41 |
acpigen_write_ADR_pci_device(dev); |
| 42 |
acpigen_write_STA(acpi_device_status(dev)); |
| 43 |
|
| 44 |
acpigen_write_pci_GNB_PRT(dev); |
| 45 |
|
| 46 |
acpigen_pop_len(); |
| 47 |
acpigen_pop_len(); |
| 48 |
} |
| 49 |
|
| 50 |
|
| 51 |
#define PCIE_LTR_MAX_LATENCY_1049US 0x1001 |
| 52 |
|
| 53 |
static void pcie_get_ltr_max_latencies(u16 *max_snoop, u16 *max_nosnoop) |
| 54 |
{ |
| 55 |
*max_snoop = PCIE_LTR_MAX_LATENCY_1049US; |
| 56 |
*max_nosnoop = PCIE_LTR_MAX_LATENCY_1049US; |
| 57 |
} |
| 58 |
|
| 59 |
static struct pci_operations pcie_ops = { |
| 60 |
.get_ltr_max_latencies = pcie_get_ltr_max_latencies, |
| 61 |
.set_subsystem = pci_dev_set_subsystem, |
| 62 |
}; |
| 63 |
|
| 64 |
struct device_operations amd_internal_pcie_gpp_ops = { |
| 65 |
.read_resources = pci_bus_read_resources, |
| 66 |
.set_resources = pci_dev_set_resources, |
| 67 |
.enable_resources = pci_bus_enable_resources, |
| 68 |
.scan_bus = pci_scan_bridge, |
| 69 |
.reset_bus = pci_bus_reset, |
| 70 |
.acpi_name = pcie_gpp_acpi_name, |
| 71 |
.acpi_fill_ssdt = acpi_device_write_gpp_pci_dev, |
| 72 |
}; |
| 73 |
|
| 74 |
struct device_operations amd_external_pcie_gpp_ops = { |
| 75 |
.read_resources = pci_bus_read_resources, |
| 76 |
.set_resources = pci_dev_set_resources, |
| 77 |
.enable_resources = pci_bus_enable_resources, |
| 78 |
.scan_bus = pciexp_scan_bridge, |
| 79 |
.reset_bus = pci_bus_reset, |
| 80 |
.acpi_name = pcie_gpp_acpi_name, |
| 81 |
.acpi_fill_ssdt = acpi_device_write_gpp_pci_dev, |
| 82 |
.ops_pci = &pcie_ops, |
| 83 |
}; |