blob: 84b2b6a3fab51e2bf5c477803bb8fb4d7a2ebc1c [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älkkif1b58b72019-03-01 13:43:02 +020021#include <device/pci_ops.h>
Arthur Heymans7b9c1392017-04-09 20:40:39 +020022#include <device/pciexp.h>
23#include <device/pci_ids.h>
24#include <southbridge/intel/common/pciehp.h>
25#include "chip.h"
26
27static void pci_init(struct device *dev)
28{
29 u16 reg16;
30 u32 reg32;
Arthur Heymans349e0852017-04-09 20:48:37 +020031 struct southbridge_intel_i82801jx_config *config = dev->chip_info;
Arthur Heymans7b9c1392017-04-09 20:40:39 +020032
Arthur Heymans349e0852017-04-09 20:48:37 +020033 printk(BIOS_DEBUG, "Initializing ICH10 PCIe root port.\n");
Arthur Heymans7b9c1392017-04-09 20:40:39 +020034
35 /* Enable Bus Master */
36 reg32 = pci_read_config32(dev, PCI_COMMAND);
37 reg32 |= PCI_COMMAND_MASTER;
38 pci_write_config32(dev, PCI_COMMAND, reg32);
39
40 /* Set Cache Line Size to 0x10 */
41 // This has no effect but the OS might expect it
42 pci_write_config8(dev, 0x0c, 0x10);
43
44 reg16 = pci_read_config16(dev, 0x3e);
45 reg16 &= ~(1 << 0); /* disable parity error response */
46 reg16 |= (1 << 2); /* ISA enable */
47 pci_write_config16(dev, 0x3e, reg16);
48
49 /* Enable IO xAPIC on this PCIe port */
50 reg32 = pci_read_config32(dev, 0xd8);
51 reg32 |= (1 << 7);
52 pci_write_config32(dev, 0xd8, reg32);
53
54 /* Enable Backbone Clock Gating */
55 reg32 = pci_read_config32(dev, 0xe1);
56 reg32 |= (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0);
57 pci_write_config32(dev, 0xe1, reg32);
58
59 /* Set VC0 transaction class */
60 reg32 = pci_read_config32(dev, 0x114);
61 reg32 &= 0xffffff00;
62 reg32 |= 1;
63 pci_write_config32(dev, 0x114, reg32);
64
65 /* Mask completion timeouts */
66 reg32 = pci_read_config32(dev, 0x148);
67 reg32 |= (1 << 14);
68 pci_write_config32(dev, 0x148, reg32);
69
70 /* Lock R/WO Correctable Error Mask. */
71 pci_write_config32(dev, 0x154, pci_read_config32(dev, 0x154));
72
73 /* Clear errors in status registers */
74 reg16 = pci_read_config16(dev, 0x06);
75 pci_write_config16(dev, 0x06, reg16);
76 reg16 = pci_read_config16(dev, 0x1e);
77 pci_write_config16(dev, 0x1e, reg16);
78
79 /* Get configured ASPM state */
80 const enum aspm_type apmc = pci_read_config32(dev, 0x50) & 3;
81
82 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
83 if (apmc == PCIE_ASPM_BOTH) {
84 reg32 = pci_read_config32(dev, 0xe8);
85 reg32 |= (1 << 1);
86 pci_write_config32(dev, 0xe8, reg32);
87 }
88
89 /* Enable expresscard hotplug events. */
90 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
91 pci_write_config32(dev, 0xd8,
92 pci_read_config32(dev, 0xd8)
93 | (1 << 30));
94 pci_write_config16(dev, 0x42, 0x142);
95 }
96}
97
Elyes HAOUAS1a8c1df2018-05-13 13:36:44 +020098static void pch_pciexp_scan_bridge(struct device *dev)
Arthur Heymans7b9c1392017-04-09 20:40:39 +020099{
Arthur Heymans349e0852017-04-09 20:48:37 +0200100 struct southbridge_intel_i82801jx_config *config = dev->chip_info;
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200101
102 /* Normal PCIe Scan */
103 pciexp_scan_bridge(dev);
104
105 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
106 intel_acpi_pcie_hotplug_scan_slot(dev->link_list);
107 }
108}
109
110static struct pci_operations pci_ops = {
Subrata Banik15ccbf02019-03-20 15:09:44 +0530111 .set_subsystem = pci_dev_set_subsystem,
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200112};
113
114static struct device_operations device_ops = {
115 .read_resources = pci_bus_read_resources,
116 .set_resources = pci_dev_set_resources,
117 .enable_resources = pci_bus_enable_resources,
118 .init = pci_init,
119 .scan_bus = pch_pciexp_scan_bridge,
120 .ops_pci = &pci_ops,
121};
122
Arthur Heymans349e0852017-04-09 20:48:37 +0200123/* 82801lJx, ICH10 */
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200124static const unsigned short pci_device_ids[] = {
Arthur Heymans349e0852017-04-09 20:48:37 +0200125 0x3a40, /* Port 1 */
126 0x3a42, /* Port 2 */
127 0x3a44, /* Port 3 */
128 0x3a46, /* Port 4 */
129 0x3a48, /* Port 5 */
130 0x3a4a, /* Port 6 */
131
132 0x3a70, /* Port 1 */
133 0x3a72, /* Port 2 */
134 0x3a74, /* Port 3 */
135 0x3a76, /* Port 4 */
136 0x3a78, /* Port 5 */
137 0x3a7a, /* Port 6 */
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200138 0
139};
Arthur Heymans349e0852017-04-09 20:48:37 +0200140
141static const struct pci_driver ich10_pcie __pci_driver = {
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200142 .ops = &device_ops,
143 .vendor = PCI_VENDOR_ID_INTEL,
144 .devices = pci_device_ids,
145};