blob: 64da5a734bae9e52c99778820568f2c25590c27e [file] [log] [blame]
Arthur Heymans7b9c1392017-04-09 20:40:39 +02001/*
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.
16 */
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>
Arthur Heymans7b9c1392017-04-09 20:40:39 +020023#include <device/pciexp.h>
24#include <device/pci_ids.h>
25#include <southbridge/intel/common/pciehp.h>
26#include "chip.h"
27
28static void pci_init(struct device *dev)
29{
30 u16 reg16;
31 u32 reg32;
Arthur Heymans349e0852017-04-09 20:48:37 +020032 struct southbridge_intel_i82801jx_config *config = dev->chip_info;
Arthur Heymans7b9c1392017-04-09 20:40:39 +020033
Arthur Heymans349e0852017-04-09 20:48:37 +020034 printk(BIOS_DEBUG, "Initializing ICH10 PCIe root port.\n");
Arthur Heymans7b9c1392017-04-09 20:40:39 +020035
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);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020049
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
60 /* Set VC0 transaction class */
61 reg32 = pci_read_config32(dev, 0x114);
62 reg32 &= 0xffffff00;
63 reg32 |= 1;
64 pci_write_config32(dev, 0x114, reg32);
65
66 /* Mask completion timeouts */
67 reg32 = pci_read_config32(dev, 0x148);
68 reg32 |= (1 << 14);
69 pci_write_config32(dev, 0x148, reg32);
70
71 /* Lock R/WO Correctable Error Mask. */
72 pci_write_config32(dev, 0x154, pci_read_config32(dev, 0x154));
73
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 }
89
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 }
97}
98
Elyes HAOUAS1a8c1df2018-05-13 13:36:44 +020099static void pch_pciexp_scan_bridge(struct device *dev)
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200100{
Arthur Heymans349e0852017-04-09 20:48:37 +0200101 struct southbridge_intel_i82801jx_config *config = dev->chip_info;
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200102
103 /* Normal PCIe Scan */
104 pciexp_scan_bridge(dev);
105
106 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
107 intel_acpi_pcie_hotplug_scan_slot(dev->link_list);
108 }
109}
110
111static struct pci_operations pci_ops = {
Subrata Banik15ccbf02019-03-20 15:09:44 +0530112 .set_subsystem = pci_dev_set_subsystem,
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200113};
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,
120 .scan_bus = pch_pciexp_scan_bridge,
121 .ops_pci = &pci_ops,
122};
123
Arthur Heymans349e0852017-04-09 20:48:37 +0200124/* 82801lJx, ICH10 */
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200125static const unsigned short pci_device_ids[] = {
Arthur Heymans349e0852017-04-09 20:48:37 +0200126 0x3a40, /* Port 1 */
127 0x3a42, /* Port 2 */
128 0x3a44, /* Port 3 */
129 0x3a46, /* Port 4 */
130 0x3a48, /* Port 5 */
131 0x3a4a, /* Port 6 */
132
133 0x3a70, /* Port 1 */
134 0x3a72, /* Port 2 */
135 0x3a74, /* Port 3 */
136 0x3a76, /* Port 4 */
137 0x3a78, /* Port 5 */
138 0x3a7a, /* Port 6 */
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200139 0
140};
Arthur Heymans349e0852017-04-09 20:48:37 +0200141
142static const struct pci_driver ich10_pcie __pci_driver = {
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200143 .ops = &device_ops,
144 .vendor = PCI_VENDOR_ID_INTEL,
145 .devices = pci_device_ids,
146};