blob: a374068522162ca03a28238f255cf8aa3f2bce0a [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älkkif1b58b72019-03-01 13:43:02 +02006#include <device/pci_ops.h>
Patrick Georgie72a8a32012-11-06 11:05:09 +01007#include <device/pciexp.h>
8#include <device/pci_ids.h>
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +01009#include <southbridge/intel/common/pciehp.h>
10#include "chip.h"
Patrick Georgie72a8a32012-11-06 11:05:09 +010011
12static void pci_init(struct device *dev)
13{
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010014 struct southbridge_intel_i82801ix_config *config = dev->chip_info;
Patrick Georgie72a8a32012-11-06 11:05:09 +010015
16 printk(BIOS_DEBUG, "Initializing ICH9 PCIe root port.\n");
17
18 /* Enable Bus Master */
Elyes HAOUASb9d2e222020-04-28 10:25:12 +020019 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
Patrick Georgie72a8a32012-11-06 11:05:09 +010020
21 /* Set Cache Line Size to 0x10 */
22 // This has no effect but the OS might expect it
23 pci_write_config8(dev, 0x0c, 0x10);
24
Angel Ponsb82b4312020-07-23 23:32:46 +020025 pci_and_config16(dev, PCI_BRIDGE_CONTROL, ~PCI_BRIDGE_CTL_PARITY);
Patrick Georgie72a8a32012-11-06 11:05:09 +010026
27 /* Enable IO xAPIC on this PCIe port */
Angel Pons67406472020-06-08 11:13:42 +020028 pci_or_config32(dev, 0xd8, 1 << 7);
Patrick Georgie72a8a32012-11-06 11:05:09 +010029
30 /* Enable Backbone Clock Gating */
Angel Pons67406472020-06-08 11:13:42 +020031 pci_or_config32(dev, 0xe1, (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0));
Patrick Georgie72a8a32012-11-06 11:05:09 +010032
Patrick Georgie72a8a32012-11-06 11:05:09 +010033 /* Set VC0 transaction class */
Angel Pons67406472020-06-08 11:13:42 +020034 pci_update_config32(dev, 0x114, ~0x000000ff, 1);
Patrick Georgie72a8a32012-11-06 11:05:09 +010035
36 /* Mask completion timeouts */
Angel Pons67406472020-06-08 11:13:42 +020037 pci_or_config32(dev, 0x148, 1 << 14);
Patrick Georgie72a8a32012-11-06 11:05:09 +010038
39 /* Lock R/WO Correctable Error Mask. */
Angel Pons67406472020-06-08 11:13:42 +020040 pci_update_config32(dev, 0x154, ~0, 0);
Patrick Georgie72a8a32012-11-06 11:05:09 +010041
42 /* Clear errors in status registers */
Angel Pons67406472020-06-08 11:13:42 +020043 pci_update_config16(dev, 0x06, ~0, 0);
44 pci_update_config16(dev, 0x1e, ~0, 0);
Patrick Georgie72a8a32012-11-06 11:05:09 +010045
46 /* Get configured ASPM state */
47 const enum aspm_type apmc = pci_read_config32(dev, 0x50) & 3;
48
49 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
Angel Pons67406472020-06-08 11:13:42 +020050 if (apmc == PCIE_ASPM_BOTH)
51 pci_or_config32(dev, 0xe8, 1 << 1);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010052
53 /* Enable expresscard hotplug events. */
54 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
Angel Pons67406472020-06-08 11:13:42 +020055
56 pci_or_config32(dev, 0xd8, 1 << 30);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010057 pci_write_config16(dev, 0x42, 0x142);
58 }
Patrick Georgie72a8a32012-11-06 11:05:09 +010059}
60
Elyes HAOUAS8aa50732018-05-13 13:34:58 +020061static void pch_pciexp_scan_bridge(struct device *dev)
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010062{
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010063 struct southbridge_intel_i82801ix_config *config = dev->chip_info;
64
Arthur Heymansa560c712021-02-24 22:27:44 +010065 if (CONFIG(PCIEXP_HOTPLUG) && config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
66 pciexp_hotplug_scan_bridge(dev);
67 } else {
68 /* Normal PCIe Scan */
69 pciexp_scan_bridge(dev);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010070 }
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010071}
72
Patrick Georgie72a8a32012-11-06 11:05:09 +010073static struct device_operations device_ops = {
74 .read_resources = pci_bus_read_resources,
75 .set_resources = pci_dev_set_resources,
76 .enable_resources = pci_bus_enable_resources,
77 .init = pci_init,
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010078 .scan_bus = pch_pciexp_scan_bridge,
Angel Pons1fc0edd2020-05-31 00:03:28 +020079 .ops_pci = &pci_dev_ops_pci,
Patrick Georgie72a8a32012-11-06 11:05:09 +010080};
81
82/* 82801Ix (ICH9DH/ICH9DO/ICH9R/ICH9/ICH9M-E/ICH9M) */
83static const unsigned short pci_device_ids[] = {
Felix Singer43b7f412022-03-07 04:34:52 +010084 PCI_DID_INTEL_82801IB_PCIE1, /* Port 1 */
85 PCI_DID_INTEL_82801IB_PCIE2, /* Port 2 */
86 PCI_DID_INTEL_82801IB_PCIE3, /* Port 3 */
87 PCI_DID_INTEL_82801IB_PCIE4, /* Port 4 */
88 PCI_DID_INTEL_82801IB_PCIE5, /* Port 5 */
89 PCI_DID_INTEL_82801IB_PCIE6, /* Port 6 */
Patrick Georgie72a8a32012-11-06 11:05:09 +010090 0
91};
92static const struct pci_driver ich9_pcie __pci_driver = {
93 .ops = &device_ops,
Felix Singer43b7f412022-03-07 04:34:52 +010094 .vendor = PCI_VID_INTEL,
Patrick Georgie72a8a32012-11-06 11:05:09 +010095 .devices = pci_device_ids,
96};