blob: c5c332c85d69f52dd05701bb46493dfb8b040370 [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{
15 u16 reg16;
16 u32 reg32;
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010017 struct southbridge_intel_i82801ix_config *config = dev->chip_info;
Patrick Georgie72a8a32012-11-06 11:05:09 +010018
19 printk(BIOS_DEBUG, "Initializing ICH9 PCIe root port.\n");
20
21 /* Enable Bus Master */
Elyes HAOUASb9d2e222020-04-28 10:25:12 +020022 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
Patrick Georgie72a8a32012-11-06 11:05:09 +010023
24 /* Set Cache Line Size to 0x10 */
25 // This has no effect but the OS might expect it
26 pci_write_config8(dev, 0x0c, 0x10);
27
Kyösti Mälkkidf128a52019-09-21 18:35:37 +030028 reg16 = pci_read_config16(dev, PCI_BRIDGE_CONTROL);
29 reg16 &= ~PCI_BRIDGE_CTL_PARITY;
30 reg16 |= PCI_BRIDGE_CTL_NO_ISA;
31 pci_write_config16(dev, PCI_BRIDGE_CONTROL, reg16);
Patrick Georgie72a8a32012-11-06 11:05:09 +010032
33 /* Enable IO xAPIC on this PCIe port */
34 reg32 = pci_read_config32(dev, 0xd8);
35 reg32 |= (1 << 7);
36 pci_write_config32(dev, 0xd8, reg32);
37
38 /* Enable Backbone Clock Gating */
39 reg32 = pci_read_config32(dev, 0xe1);
40 reg32 |= (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0);
41 pci_write_config32(dev, 0xe1, reg32);
42
Patrick Georgie72a8a32012-11-06 11:05:09 +010043 /* Set VC0 transaction class */
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030044 reg32 = pci_read_config32(dev, 0x114);
Patrick Georgie72a8a32012-11-06 11:05:09 +010045 reg32 &= 0xffffff00;
46 reg32 |= 1;
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030047 pci_write_config32(dev, 0x114, reg32);
Patrick Georgie72a8a32012-11-06 11:05:09 +010048
49 /* Mask completion timeouts */
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030050 reg32 = pci_read_config32(dev, 0x148);
Patrick Georgie72a8a32012-11-06 11:05:09 +010051 reg32 |= (1 << 14);
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030052 pci_write_config32(dev, 0x148, reg32);
Patrick Georgie72a8a32012-11-06 11:05:09 +010053
54 /* Lock R/WO Correctable Error Mask. */
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030055 pci_write_config32(dev, 0x154, pci_read_config32(dev, 0x154));
Patrick Georgie72a8a32012-11-06 11:05:09 +010056
57 /* Clear errors in status registers */
58 reg16 = pci_read_config16(dev, 0x06);
59 pci_write_config16(dev, 0x06, reg16);
60 reg16 = pci_read_config16(dev, 0x1e);
61 pci_write_config16(dev, 0x1e, reg16);
62
63 /* Get configured ASPM state */
64 const enum aspm_type apmc = pci_read_config32(dev, 0x50) & 3;
65
66 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
67 if (apmc == PCIE_ASPM_BOTH) {
68 reg32 = pci_read_config32(dev, 0xe8);
69 reg32 |= (1 << 1);
70 pci_write_config32(dev, 0xe8, reg32);
71 }
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010072
73 /* Enable expresscard hotplug events. */
74 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
75 pci_write_config32(dev, 0xd8,
76 pci_read_config32(dev, 0xd8)
77 | (1 << 30));
78 pci_write_config16(dev, 0x42, 0x142);
79 }
Patrick Georgie72a8a32012-11-06 11:05:09 +010080}
81
Elyes HAOUAS8aa50732018-05-13 13:34:58 +020082static void pch_pciexp_scan_bridge(struct device *dev)
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010083{
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010084 struct southbridge_intel_i82801ix_config *config = dev->chip_info;
85
86 /* Normal PCIe Scan */
Kyösti Mälkki580e7222015-03-19 21:04:23 +020087 pciexp_scan_bridge(dev);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010088
89 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
90 intel_acpi_pcie_hotplug_scan_slot(dev->link_list);
91 }
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010092}
93
Patrick Georgie72a8a32012-11-06 11:05:09 +010094static struct device_operations device_ops = {
95 .read_resources = pci_bus_read_resources,
96 .set_resources = pci_dev_set_resources,
97 .enable_resources = pci_bus_enable_resources,
98 .init = pci_init,
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010099 .scan_bus = pch_pciexp_scan_bridge,
Angel Pons1fc0edd2020-05-31 00:03:28 +0200100 .ops_pci = &pci_dev_ops_pci,
Patrick Georgie72a8a32012-11-06 11:05:09 +0100101};
102
103/* 82801Ix (ICH9DH/ICH9DO/ICH9R/ICH9/ICH9M-E/ICH9M) */
104static const unsigned short pci_device_ids[] = {
Felix Singer7f8b0cd82019-11-10 11:04:08 +0100105 PCI_DEVICE_ID_INTEL_82801IB_PCIE1, /* Port 1 */
106 PCI_DEVICE_ID_INTEL_82801IB_PCIE2, /* Port 2 */
107 PCI_DEVICE_ID_INTEL_82801IB_PCIE3, /* Port 3 */
108 PCI_DEVICE_ID_INTEL_82801IB_PCIE4, /* Port 4 */
109 PCI_DEVICE_ID_INTEL_82801IB_PCIE5, /* Port 5 */
110 PCI_DEVICE_ID_INTEL_82801IB_PCIE6, /* Port 6 */
Patrick Georgie72a8a32012-11-06 11:05:09 +0100111 0
112};
113static const struct pci_driver ich9_pcie __pci_driver = {
114 .ops = &device_ops,
115 .vendor = PCI_VENDOR_ID_INTEL,
116 .devices = pci_device_ids,
117};