blob: b1d0ecc214e8052a016cc8f379e18738f05aa81f [file] [log] [blame]
Patrick Georgie72a8a32012-11-06 11:05:09 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2008-2009 coresystems GmbH
5 * 2012 secunet Security Networks AG
6 *
7 * This program is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU General Public License as
9 * published by the Free Software Foundation; version 2 of
10 * the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Patrick Georgie72a8a32012-11-06 11:05:09 +010016 */
17
18#include <console/console.h>
19#include <device/device.h>
20#include <device/pci.h>
Kyösti Mälkkidf128a52019-09-21 18:35:37 +030021#include <device/pci_def.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020022#include <device/pci_ops.h>
Patrick Georgie72a8a32012-11-06 11:05:09 +010023#include <device/pciexp.h>
24#include <device/pci_ids.h>
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010025#include <southbridge/intel/common/pciehp.h>
26#include "chip.h"
Patrick Georgie72a8a32012-11-06 11:05:09 +010027
28static void pci_init(struct device *dev)
29{
30 u16 reg16;
31 u32 reg32;
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010032 struct southbridge_intel_i82801ix_config *config = dev->chip_info;
Patrick Georgie72a8a32012-11-06 11:05:09 +010033
34 printk(BIOS_DEBUG, "Initializing ICH9 PCIe root port.\n");
35
36 /* Enable Bus Master */
37 reg32 = pci_read_config32(dev, PCI_COMMAND);
38 reg32 |= PCI_COMMAND_MASTER;
39 pci_write_config32(dev, PCI_COMMAND, reg32);
40
41 /* Set Cache Line Size to 0x10 */
42 // This has no effect but the OS might expect it
43 pci_write_config8(dev, 0x0c, 0x10);
44
Kyösti Mälkkidf128a52019-09-21 18:35:37 +030045 reg16 = pci_read_config16(dev, PCI_BRIDGE_CONTROL);
46 reg16 &= ~PCI_BRIDGE_CTL_PARITY;
47 reg16 |= PCI_BRIDGE_CTL_NO_ISA;
48 pci_write_config16(dev, PCI_BRIDGE_CONTROL, reg16);
Patrick Georgie72a8a32012-11-06 11:05:09 +010049
50 /* Enable IO xAPIC on this PCIe port */
51 reg32 = pci_read_config32(dev, 0xd8);
52 reg32 |= (1 << 7);
53 pci_write_config32(dev, 0xd8, reg32);
54
55 /* Enable Backbone Clock Gating */
56 reg32 = pci_read_config32(dev, 0xe1);
57 reg32 |= (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0);
58 pci_write_config32(dev, 0xe1, reg32);
59
Patrick Georgie72a8a32012-11-06 11:05:09 +010060 /* Set VC0 transaction class */
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030061 reg32 = pci_read_config32(dev, 0x114);
Patrick Georgie72a8a32012-11-06 11:05:09 +010062 reg32 &= 0xffffff00;
63 reg32 |= 1;
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030064 pci_write_config32(dev, 0x114, reg32);
Patrick Georgie72a8a32012-11-06 11:05:09 +010065
66 /* Mask completion timeouts */
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030067 reg32 = pci_read_config32(dev, 0x148);
Patrick Georgie72a8a32012-11-06 11:05:09 +010068 reg32 |= (1 << 14);
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030069 pci_write_config32(dev, 0x148, reg32);
Patrick Georgie72a8a32012-11-06 11:05:09 +010070
71 /* Lock R/WO Correctable Error Mask. */
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030072 pci_write_config32(dev, 0x154, pci_read_config32(dev, 0x154));
Patrick Georgie72a8a32012-11-06 11:05:09 +010073
74 /* Clear errors in status registers */
75 reg16 = pci_read_config16(dev, 0x06);
76 pci_write_config16(dev, 0x06, reg16);
77 reg16 = pci_read_config16(dev, 0x1e);
78 pci_write_config16(dev, 0x1e, reg16);
79
80 /* Get configured ASPM state */
81 const enum aspm_type apmc = pci_read_config32(dev, 0x50) & 3;
82
83 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
84 if (apmc == PCIE_ASPM_BOTH) {
85 reg32 = pci_read_config32(dev, 0xe8);
86 reg32 |= (1 << 1);
87 pci_write_config32(dev, 0xe8, reg32);
88 }
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010089
90 /* Enable expresscard hotplug events. */
91 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
92 pci_write_config32(dev, 0xd8,
93 pci_read_config32(dev, 0xd8)
94 | (1 << 30));
95 pci_write_config16(dev, 0x42, 0x142);
96 }
Patrick Georgie72a8a32012-11-06 11:05:09 +010097}
98
Elyes HAOUAS8aa50732018-05-13 13:34:58 +020099static void pch_pciexp_scan_bridge(struct device *dev)
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100100{
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100101 struct southbridge_intel_i82801ix_config *config = dev->chip_info;
102
103 /* Normal PCIe Scan */
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200104 pciexp_scan_bridge(dev);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100105
106 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
107 intel_acpi_pcie_hotplug_scan_slot(dev->link_list);
108 }
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100109}
110
Patrick Georgie72a8a32012-11-06 11:05:09 +0100111static struct pci_operations pci_ops = {
Subrata Banik15ccbf02019-03-20 15:09:44 +0530112 .set_subsystem = pci_dev_set_subsystem,
Patrick Georgie72a8a32012-11-06 11:05:09 +0100113};
114
115static struct device_operations device_ops = {
116 .read_resources = pci_bus_read_resources,
117 .set_resources = pci_dev_set_resources,
118 .enable_resources = pci_bus_enable_resources,
119 .init = pci_init,
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100120 .scan_bus = pch_pciexp_scan_bridge,
Patrick Georgie72a8a32012-11-06 11:05:09 +0100121 .ops_pci = &pci_ops,
122};
123
124/* 82801Ix (ICH9DH/ICH9DO/ICH9R/ICH9/ICH9M-E/ICH9M) */
125static const unsigned short pci_device_ids[] = {
126 0x2940, /* Port 1 */
127 0x2942, /* Port 2 */
128 0x2944, /* Port 3 */
129 0x2946, /* Port 4 */
130 0x2948, /* Port 5 */
131 0x294a, /* Port 6 */
132 0
133};
134static const struct pci_driver ich9_pcie __pci_driver = {
135 .ops = &device_ops,
136 .vendor = PCI_VENDOR_ID_INTEL,
137 .devices = pci_device_ids,
138};