blob: 502e765773a3d39ee419122bf39e325b2099a7c5 [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>
21#include <device/pciexp.h>
22#include <device/pci_ids.h>
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010023#include <southbridge/intel/common/pciehp.h>
24#include "chip.h"
Patrick Georgie72a8a32012-11-06 11:05:09 +010025
26static void pci_init(struct device *dev)
27{
28 u16 reg16;
29 u32 reg32;
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010030 struct southbridge_intel_i82801ix_config *config = dev->chip_info;
Patrick Georgie72a8a32012-11-06 11:05:09 +010031
32 printk(BIOS_DEBUG, "Initializing ICH9 PCIe root port.\n");
33
34 /* Enable Bus Master */
35 reg32 = pci_read_config32(dev, PCI_COMMAND);
36 reg32 |= PCI_COMMAND_MASTER;
37 pci_write_config32(dev, PCI_COMMAND, reg32);
38
39 /* Set Cache Line Size to 0x10 */
40 // This has no effect but the OS might expect it
41 pci_write_config8(dev, 0x0c, 0x10);
42
43 reg16 = pci_read_config16(dev, 0x3e);
44 reg16 &= ~(1 << 0); /* disable parity error response */
45 reg16 |= (1 << 2); /* ISA enable */
46 pci_write_config16(dev, 0x3e, reg16);
47
48 /* Enable IO xAPIC on this PCIe port */
49 reg32 = pci_read_config32(dev, 0xd8);
50 reg32 |= (1 << 7);
51 pci_write_config32(dev, 0xd8, reg32);
52
53 /* Enable Backbone Clock Gating */
54 reg32 = pci_read_config32(dev, 0xe1);
55 reg32 |= (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0);
56 pci_write_config32(dev, 0xe1, reg32);
57
Patrick Georgie72a8a32012-11-06 11:05:09 +010058 /* Set VC0 transaction class */
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030059 reg32 = pci_read_config32(dev, 0x114);
Patrick Georgie72a8a32012-11-06 11:05:09 +010060 reg32 &= 0xffffff00;
61 reg32 |= 1;
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030062 pci_write_config32(dev, 0x114, reg32);
Patrick Georgie72a8a32012-11-06 11:05:09 +010063
64 /* Mask completion timeouts */
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030065 reg32 = pci_read_config32(dev, 0x148);
Patrick Georgie72a8a32012-11-06 11:05:09 +010066 reg32 |= (1 << 14);
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030067 pci_write_config32(dev, 0x148, reg32);
Patrick Georgie72a8a32012-11-06 11:05:09 +010068
69 /* Lock R/WO Correctable Error Mask. */
Kyösti Mälkki9b143e12013-07-26 08:35:09 +030070 pci_write_config32(dev, 0x154, pci_read_config32(dev, 0x154));
Patrick Georgie72a8a32012-11-06 11:05:09 +010071
72 /* Clear errors in status registers */
73 reg16 = pci_read_config16(dev, 0x06);
74 pci_write_config16(dev, 0x06, reg16);
75 reg16 = pci_read_config16(dev, 0x1e);
76 pci_write_config16(dev, 0x1e, reg16);
77
78 /* Get configured ASPM state */
79 const enum aspm_type apmc = pci_read_config32(dev, 0x50) & 3;
80
81 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
82 if (apmc == PCIE_ASPM_BOTH) {
83 reg32 = pci_read_config32(dev, 0xe8);
84 reg32 |= (1 << 1);
85 pci_write_config32(dev, 0xe8, reg32);
86 }
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +010087
88 /* Enable expresscard hotplug events. */
89 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
90 pci_write_config32(dev, 0xd8,
91 pci_read_config32(dev, 0xd8)
92 | (1 << 30));
93 pci_write_config16(dev, 0x42, 0x142);
94 }
Patrick Georgie72a8a32012-11-06 11:05:09 +010095}
96
97static void pcie_set_subsystem(device_t dev, unsigned vendor, unsigned device)
98{
99 /* NOTE: 0x94 is not the default position! */
100 if (!vendor || !device) {
101 pci_write_config32(dev, 0x94,
102 pci_read_config32(dev, 0));
103 } else {
104 pci_write_config32(dev, 0x94,
105 ((device & 0xffff) << 16) | (vendor & 0xffff));
106 }
107}
108
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200109static void pch_pciexp_scan_bridge(device_t dev)
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100110{
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100111 struct southbridge_intel_i82801ix_config *config = dev->chip_info;
112
113 /* Normal PCIe Scan */
Kyösti Mälkki580e7222015-03-19 21:04:23 +0200114 pciexp_scan_bridge(dev);
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100115
116 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
117 intel_acpi_pcie_hotplug_scan_slot(dev->link_list);
118 }
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100119}
120
Patrick Georgie72a8a32012-11-06 11:05:09 +0100121static struct pci_operations pci_ops = {
122 .set_subsystem = pcie_set_subsystem,
123};
124
125static struct device_operations device_ops = {
126 .read_resources = pci_bus_read_resources,
127 .set_resources = pci_dev_set_resources,
128 .enable_resources = pci_bus_enable_resources,
129 .init = pci_init,
Vladimir Serbinenko36fa5b82014-10-28 23:43:20 +0100130 .scan_bus = pch_pciexp_scan_bridge,
Patrick Georgie72a8a32012-11-06 11:05:09 +0100131 .ops_pci = &pci_ops,
132};
133
134/* 82801Ix (ICH9DH/ICH9DO/ICH9R/ICH9/ICH9M-E/ICH9M) */
135static const unsigned short pci_device_ids[] = {
136 0x2940, /* Port 1 */
137 0x2942, /* Port 2 */
138 0x2944, /* Port 3 */
139 0x2946, /* Port 4 */
140 0x2948, /* Port 5 */
141 0x294a, /* Port 6 */
142 0
143};
144static const struct pci_driver ich9_pcie __pci_driver = {
145 .ops = &device_ops,
146 .vendor = PCI_VENDOR_ID_INTEL,
147 .devices = pci_device_ids,
148};