blob: a8e7b11179c3d0dc97bc16c30cce8093b05faf6b [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Patrick Georgie72a8a32012-11-06 11:05:09 +01002
3#include <console/console.h>
4#include <device/device.h>
5#include <device/pci.h>
Kyösti Mälkkidf128a52019-09-21 18:35:37 +03006#include <device/pci_def.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02007#include <device/pci_ops.h>
Patrick Georgie72a8a32012-11-06 11:05:09 +01008#include <device/pciexp.h>
9#include <device/pci_ids.h>
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010010#include <southbridge/intel/common/pciehp.h>
11#include "chip.h"
Patrick Georgie72a8a32012-11-06 11:05:09 +010012
13static void pci_init(struct device *dev)
14{
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010015 struct southbridge_intel_i82801ix_config *config = dev->chip_info;
Patrick Georgie72a8a32012-11-06 11:05:09 +010016
17 printk(BIOS_DEBUG, "Initializing ICH9 PCIe root port.\n");
18
19 /* Enable Bus Master */
Elyes HAOUASb9d2e222020-04-28 10:25:12 +020020 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
Patrick Georgie72a8a32012-11-06 11:05:09 +010021
22 /* Set Cache Line Size to 0x10 */
23 // This has no effect but the OS might expect it
24 pci_write_config8(dev, 0x0c, 0x10);
25
Angel Pons67406472020-06-08 11:13:42 +020026 pci_update_config16(dev, PCI_BRIDGE_CONTROL, ~PCI_BRIDGE_CTL_PARITY,
27 PCI_BRIDGE_CTL_NO_ISA);
Patrick Georgie72a8a32012-11-06 11:05:09 +010028
29 /* Enable IO xAPIC on this PCIe port */
Angel Pons67406472020-06-08 11:13:42 +020030 pci_or_config32(dev, 0xd8, 1 << 7);
Patrick Georgie72a8a32012-11-06 11:05:09 +010031
32 /* Enable Backbone Clock Gating */
Angel Pons67406472020-06-08 11:13:42 +020033 pci_or_config32(dev, 0xe1, (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0));
Patrick Georgie72a8a32012-11-06 11:05:09 +010034
Patrick Georgie72a8a32012-11-06 11:05:09 +010035 /* Set VC0 transaction class */
Angel Pons67406472020-06-08 11:13:42 +020036 pci_update_config32(dev, 0x114, ~0x000000ff, 1);
Patrick Georgie72a8a32012-11-06 11:05:09 +010037
38 /* Mask completion timeouts */
Angel Pons67406472020-06-08 11:13:42 +020039 pci_or_config32(dev, 0x148, 1 << 14);
Patrick Georgie72a8a32012-11-06 11:05:09 +010040
41 /* Lock R/WO Correctable Error Mask. */
Angel Pons67406472020-06-08 11:13:42 +020042 pci_update_config32(dev, 0x154, ~0, 0);
Patrick Georgie72a8a32012-11-06 11:05:09 +010043
44 /* Clear errors in status registers */
Angel Pons67406472020-06-08 11:13:42 +020045 pci_update_config16(dev, 0x06, ~0, 0);
46 pci_update_config16(dev, 0x1e, ~0, 0);
Patrick Georgie72a8a32012-11-06 11:05:09 +010047
48 /* Get configured ASPM state */
49 const enum aspm_type apmc = pci_read_config32(dev, 0x50) & 3;
50
51 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
Angel Pons67406472020-06-08 11:13:42 +020052 if (apmc == PCIE_ASPM_BOTH)
53 pci_or_config32(dev, 0xe8, 1 << 1);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010054
55 /* Enable expresscard hotplug events. */
56 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
Angel Pons67406472020-06-08 11:13:42 +020057
58 pci_or_config32(dev, 0xd8, 1 << 30);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010059 pci_write_config16(dev, 0x42, 0x142);
60 }
Patrick Georgie72a8a32012-11-06 11:05:09 +010061}
62
Elyes HAOUAS8aa50732018-05-13 13:34:58 +020063static void pch_pciexp_scan_bridge(struct device *dev)
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010064{
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010065 struct southbridge_intel_i82801ix_config *config = dev->chip_info;
66
67 /* Normal PCIe Scan */
Kyösti Mälkki580e7222015-03-19 21:04:23 +020068 pciexp_scan_bridge(dev);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010069
70 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
71 intel_acpi_pcie_hotplug_scan_slot(dev->link_list);
72 }
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010073}
74
Patrick Georgie72a8a32012-11-06 11:05:09 +010075static struct device_operations device_ops = {
76 .read_resources = pci_bus_read_resources,
77 .set_resources = pci_dev_set_resources,
78 .enable_resources = pci_bus_enable_resources,
79 .init = pci_init,
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010080 .scan_bus = pch_pciexp_scan_bridge,
Angel Pons1fc0edd2020-05-31 00:03:28 +020081 .ops_pci = &pci_dev_ops_pci,
Patrick Georgie72a8a32012-11-06 11:05:09 +010082};
83
84/* 82801Ix (ICH9DH/ICH9DO/ICH9R/ICH9/ICH9M-E/ICH9M) */
85static const unsigned short pci_device_ids[] = {
Felix Singer7f8b0cd2019-11-10 11:04:08 +010086 PCI_DEVICE_ID_INTEL_82801IB_PCIE1, /* Port 1 */
87 PCI_DEVICE_ID_INTEL_82801IB_PCIE2, /* Port 2 */
88 PCI_DEVICE_ID_INTEL_82801IB_PCIE3, /* Port 3 */
89 PCI_DEVICE_ID_INTEL_82801IB_PCIE4, /* Port 4 */
90 PCI_DEVICE_ID_INTEL_82801IB_PCIE5, /* Port 5 */
91 PCI_DEVICE_ID_INTEL_82801IB_PCIE6, /* Port 6 */
Patrick Georgie72a8a32012-11-06 11:05:09 +010092 0
93};
94static const struct pci_driver ich9_pcie __pci_driver = {
95 .ops = &device_ops,
96 .vendor = PCI_VENDOR_ID_INTEL,
97 .devices = pci_device_ids,
98};