blob: 08b0e98f52bab72d56c8897cfc83b85acc82af88 [file] [log] [blame]
Arthur Heymans7b9c1392017-04-09 20:40:39 +02001/*
2 * This file is part of the coreboot project.
3 *
Arthur Heymans7b9c1392017-04-09 20:40:39 +02004 *
5 * This program is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU General Public License as
7 * published by the Free Software Foundation; version 2 of
8 * the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 */
15
16#include <console/console.h>
17#include <device/device.h>
18#include <device/pci.h>
Kyösti Mälkkidf128a52019-09-21 18:35:37 +030019#include <device/pci_def.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020020#include <device/pci_ops.h>
Arthur Heymans7b9c1392017-04-09 20:40:39 +020021#include <device/pciexp.h>
22#include <device/pci_ids.h>
23#include <southbridge/intel/common/pciehp.h>
24#include "chip.h"
25
26static void pci_init(struct device *dev)
27{
28 u16 reg16;
29 u32 reg32;
Arthur Heymans349e0852017-04-09 20:48:37 +020030 struct southbridge_intel_i82801jx_config *config = dev->chip_info;
Arthur Heymans7b9c1392017-04-09 20:40:39 +020031
Arthur Heymans349e0852017-04-09 20:48:37 +020032 printk(BIOS_DEBUG, "Initializing ICH10 PCIe root port.\n");
Arthur Heymans7b9c1392017-04-09 20:40:39 +020033
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
Kyösti Mälkkidf128a52019-09-21 18:35:37 +030043 reg16 = pci_read_config16(dev, PCI_BRIDGE_CONTROL);
44 reg16 &= ~PCI_BRIDGE_CTL_PARITY;
45 reg16 |= PCI_BRIDGE_CTL_NO_ISA;
46 pci_write_config16(dev, PCI_BRIDGE_CONTROL, reg16);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020047
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
58 /* Set VC0 transaction class */
59 reg32 = pci_read_config32(dev, 0x114);
60 reg32 &= 0xffffff00;
61 reg32 |= 1;
62 pci_write_config32(dev, 0x114, reg32);
63
64 /* Mask completion timeouts */
65 reg32 = pci_read_config32(dev, 0x148);
66 reg32 |= (1 << 14);
67 pci_write_config32(dev, 0x148, reg32);
68
69 /* Lock R/WO Correctable Error Mask. */
70 pci_write_config32(dev, 0x154, pci_read_config32(dev, 0x154));
71
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 }
87
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 }
95}
96
Elyes HAOUAS1a8c1df2018-05-13 13:36:44 +020097static void pch_pciexp_scan_bridge(struct device *dev)
Arthur Heymans7b9c1392017-04-09 20:40:39 +020098{
Arthur Heymans349e0852017-04-09 20:48:37 +020099 struct southbridge_intel_i82801jx_config *config = dev->chip_info;
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200100
101 /* Normal PCIe Scan */
102 pciexp_scan_bridge(dev);
103
104 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
105 intel_acpi_pcie_hotplug_scan_slot(dev->link_list);
106 }
107}
108
109static struct pci_operations pci_ops = {
Subrata Banik15ccbf02019-03-20 15:09:44 +0530110 .set_subsystem = pci_dev_set_subsystem,
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200111};
112
113static struct device_operations device_ops = {
114 .read_resources = pci_bus_read_resources,
115 .set_resources = pci_dev_set_resources,
116 .enable_resources = pci_bus_enable_resources,
117 .init = pci_init,
118 .scan_bus = pch_pciexp_scan_bridge,
119 .ops_pci = &pci_ops,
120};
121
Arthur Heymans349e0852017-04-09 20:48:37 +0200122/* 82801lJx, ICH10 */
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200123static const unsigned short pci_device_ids[] = {
Arthur Heymans349e0852017-04-09 20:48:37 +0200124 0x3a40, /* Port 1 */
125 0x3a42, /* Port 2 */
126 0x3a44, /* Port 3 */
127 0x3a46, /* Port 4 */
128 0x3a48, /* Port 5 */
129 0x3a4a, /* Port 6 */
130
131 0x3a70, /* Port 1 */
132 0x3a72, /* Port 2 */
133 0x3a74, /* Port 3 */
134 0x3a76, /* Port 4 */
135 0x3a78, /* Port 5 */
136 0x3a7a, /* Port 6 */
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200137 0
138};
Arthur Heymans349e0852017-04-09 20:48:37 +0200139
140static const struct pci_driver ich10_pcie __pci_driver = {
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200141 .ops = &device_ops,
142 .vendor = PCI_VENDOR_ID_INTEL,
143 .devices = pci_device_ids,
144};