blob: a199dd12a8bf6ae0c160fa544cd79c386b0071b7 [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 Ponsb82b4312020-07-23 23:32:46 +020026 pci_and_config16(dev, PCI_BRIDGE_CONTROL, ~PCI_BRIDGE_CTL_PARITY);
Patrick Georgie72a8a32012-11-06 11:05:09 +010027
28 /* Enable IO xAPIC on this PCIe port */
Angel Pons67406472020-06-08 11:13:42 +020029 pci_or_config32(dev, 0xd8, 1 << 7);
Patrick Georgie72a8a32012-11-06 11:05:09 +010030
31 /* Enable Backbone Clock Gating */
Angel Pons67406472020-06-08 11:13:42 +020032 pci_or_config32(dev, 0xe1, (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0));
Patrick Georgie72a8a32012-11-06 11:05:09 +010033
Patrick Georgie72a8a32012-11-06 11:05:09 +010034 /* Set VC0 transaction class */
Angel Pons67406472020-06-08 11:13:42 +020035 pci_update_config32(dev, 0x114, ~0x000000ff, 1);
Patrick Georgie72a8a32012-11-06 11:05:09 +010036
37 /* Mask completion timeouts */
Angel Pons67406472020-06-08 11:13:42 +020038 pci_or_config32(dev, 0x148, 1 << 14);
Patrick Georgie72a8a32012-11-06 11:05:09 +010039
40 /* Lock R/WO Correctable Error Mask. */
Angel Pons67406472020-06-08 11:13:42 +020041 pci_update_config32(dev, 0x154, ~0, 0);
Patrick Georgie72a8a32012-11-06 11:05:09 +010042
43 /* Clear errors in status registers */
Angel Pons67406472020-06-08 11:13:42 +020044 pci_update_config16(dev, 0x06, ~0, 0);
45 pci_update_config16(dev, 0x1e, ~0, 0);
Patrick Georgie72a8a32012-11-06 11:05:09 +010046
47 /* Get configured ASPM state */
48 const enum aspm_type apmc = pci_read_config32(dev, 0x50) & 3;
49
50 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
Angel Pons67406472020-06-08 11:13:42 +020051 if (apmc == PCIE_ASPM_BOTH)
52 pci_or_config32(dev, 0xe8, 1 << 1);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010053
54 /* Enable expresscard hotplug events. */
55 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
Angel Pons67406472020-06-08 11:13:42 +020056
57 pci_or_config32(dev, 0xd8, 1 << 30);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010058 pci_write_config16(dev, 0x42, 0x142);
59 }
Patrick Georgie72a8a32012-11-06 11:05:09 +010060}
61
Elyes HAOUAS8aa50732018-05-13 13:34:58 +020062static void pch_pciexp_scan_bridge(struct device *dev)
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010063{
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010064 struct southbridge_intel_i82801ix_config *config = dev->chip_info;
65
Arthur Heymansa560c712021-02-24 22:27:44 +010066 if (CONFIG(PCIEXP_HOTPLUG) && config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
67 pciexp_hotplug_scan_bridge(dev);
68 } else {
69 /* Normal PCIe Scan */
70 pciexp_scan_bridge(dev);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010071 }
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010072}
73
Patrick Georgie72a8a32012-11-06 11:05:09 +010074static struct device_operations device_ops = {
75 .read_resources = pci_bus_read_resources,
76 .set_resources = pci_dev_set_resources,
77 .enable_resources = pci_bus_enable_resources,
78 .init = pci_init,
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010079 .scan_bus = pch_pciexp_scan_bridge,
Angel Pons1fc0edd2020-05-31 00:03:28 +020080 .ops_pci = &pci_dev_ops_pci,
Patrick Georgie72a8a32012-11-06 11:05:09 +010081};
82
83/* 82801Ix (ICH9DH/ICH9DO/ICH9R/ICH9/ICH9M-E/ICH9M) */
84static const unsigned short pci_device_ids[] = {
Felix Singer43b7f412022-03-07 04:34:52 +010085 PCI_DID_INTEL_82801IB_PCIE1, /* Port 1 */
86 PCI_DID_INTEL_82801IB_PCIE2, /* Port 2 */
87 PCI_DID_INTEL_82801IB_PCIE3, /* Port 3 */
88 PCI_DID_INTEL_82801IB_PCIE4, /* Port 4 */
89 PCI_DID_INTEL_82801IB_PCIE5, /* Port 5 */
90 PCI_DID_INTEL_82801IB_PCIE6, /* Port 6 */
Patrick Georgie72a8a32012-11-06 11:05:09 +010091 0
92};
93static const struct pci_driver ich9_pcie __pci_driver = {
94 .ops = &device_ops,
Felix Singer43b7f412022-03-07 04:34:52 +010095 .vendor = PCI_VID_INTEL,
Patrick Georgie72a8a32012-11-06 11:05:09 +010096 .devices = pci_device_ids,
97};