| 1 |
|
| 2 |
|
| 3 |
#include <device/pci.h> |
| 4 |
#include <device/pciexp.h> |
| 5 |
#include <device/pci_ids.h> |
| 6 |
#include <soc/acpi.h> |
| 7 |
#include <soc/pci_devs.h> |
| 8 |
#include <soc/ramstage.h> |
| 9 |
|
| 10 |
static const char *pcie_device_get_acpi_name(const struct device *dev) |
| 11 |
{ |
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
assert(dev->name); |
| 17 |
return dev->name; |
| 18 |
} |
| 19 |
|
| 20 |
static void soc_pciexp_scan_bridge(struct device *dev) |
| 21 |
{ |
| 22 |
if (CONFIG(PCIEXP_HOTPLUG) && pciexp_dev_is_slot_hot_plug_cap(dev)) |
| 23 |
pciexp_hotplug_scan_bridge(dev); |
| 24 |
else |
| 25 |
pciexp_scan_bridge(dev); |
| 26 |
} |
| 27 |
|
| 28 |
static void pcie_device_set_acpi_name(struct device *dev, const char *prefix) |
| 29 |
{ |
| 30 |
assert(prefix != NULL && strlen(prefix) == 2); |
| 31 |
if (!prefix || strlen(prefix) != 2) |
| 32 |
return; |
| 33 |
|
| 34 |
char *name = xmalloc(ACPI_NAME_BUFFER_SIZE); |
| 35 |
uint8_t slot = PCI_SLOT(dev->path.pci.devfn); |
| 36 |
uint8_t func = PCI_FUNC(dev->path.pci.devfn); |
| 37 |
snprintf(name, ACPI_NAME_BUFFER_SIZE, "%s%02X", prefix, PCI_DEVFN(slot, func)); |
| 38 |
dev->name = name; |
| 39 |
} |
| 40 |
|
| 41 |
static void pcie_root_port_init(struct device *rp) |
| 42 |
{ |
| 43 |
if (!is_pci_bridge(rp)) |
| 44 |
return; |
| 45 |
|
| 46 |
pcie_device_set_acpi_name(rp, "RP"); |
| 47 |
|
| 48 |
struct device *dev = NULL; |
| 49 |
while ((dev = dev_bus_each_child(rp->downstream, dev))) { |
| 50 |
if (!is_pci(dev)) |
| 51 |
continue; |
| 52 |
pcie_device_set_acpi_name(dev, "DC"); |
| 53 |
} |
| 54 |
|
| 55 |
pci_dev_init(rp); |
| 56 |
} |
| 57 |
|
| 58 |
static const unsigned short pcie_root_port_ids[] = { |
| 59 |
|
| 60 |
|
| 61 |
|
| 62 |
0x352a, |
| 63 |
0x352b, |
| 64 |
0x352c, |
| 65 |
0x352d, |
| 66 |
0x347a, |
| 67 |
0x0db0, |
| 68 |
0x0db1, |
| 69 |
0x0db2, |
| 70 |
0x0db3, |
| 71 |
0x0db6, |
| 72 |
0x0db7, |
| 73 |
0x0db8, |
| 74 |
0x0db9, |
| 75 |
0 |
| 76 |
}; |
| 77 |
|
| 78 |
static struct device_operations pcie_root_port_ops = { |
| 79 |
.read_resources = pci_bus_read_resources, |
| 80 |
.set_resources = pci_dev_set_resources, |
| 81 |
.enable_resources = pci_bus_enable_resources, |
| 82 |
.scan_bus = soc_pciexp_scan_bridge, |
| 83 |
.reset_bus = pci_bus_reset, |
| 84 |
.init = pcie_root_port_init, |
| 85 |
.ops_pci = &soc_pci_ops, |
| 86 |
.acpi_fill_ssdt = &acpigen_write_pci_root_port, |
| 87 |
.acpi_name = &pcie_device_get_acpi_name, |
| 88 |
}; |
| 89 |
|
| 90 |
static const struct pci_driver pcie_root_port_driver __pci_driver = { |
| 91 |
.ops = &pcie_root_port_ops, |
| 92 |
.vendor = PCI_VID_INTEL, |
| 93 |
.devices = pcie_root_port_ids, |
| 94 |
}; |