blob: 5195522217b2e6d2d8ca853963b376b563200f7b [file] [log] [blame]
Angel Pons182dbde2020-04-02 23:49:05 +02001/* SPDX-License-Identifier: GPL-2.0-only */
Arthur Heymans7b9c1392017-04-09 20:40:39 +02002
3#include <console/console.h>
4#include <device/device.h>
5#include <device/pci.h>
Kyösti Mälkkidf128a52019-09-21 18:35:37 +03006#include <device/pci_def.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +02007#include <device/pci_ops.h>
Arthur Heymans7b9c1392017-04-09 20:40:39 +02008#include <device/pciexp.h>
9#include <device/pci_ids.h>
10#include <southbridge/intel/common/pciehp.h>
11#include "chip.h"
12
13static void pci_init(struct device *dev)
14{
Arthur Heymans349e0852017-04-09 20:48:37 +020015 struct southbridge_intel_i82801jx_config *config = dev->chip_info;
Arthur Heymans7b9c1392017-04-09 20:40:39 +020016
Arthur Heymans349e0852017-04-09 20:48:37 +020017 printk(BIOS_DEBUG, "Initializing ICH10 PCIe root port.\n");
Arthur Heymans7b9c1392017-04-09 20:40:39 +020018
19 /* Enable Bus Master */
Elyes HAOUASca4ff252020-04-28 10:29:11 +020020 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020021
22 /* Set Cache Line Size to 0x10 */
23 // This has no effect but the OS might expect it
24 pci_write_config8(dev, 0x0c, 0x10);
25
Angel Pons2048cb42020-06-08 02:09:33 +020026 pci_update_config16(dev, PCI_BRIDGE_CONTROL, ~PCI_BRIDGE_CTL_PARITY,
27 PCI_BRIDGE_CTL_NO_ISA);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020028
29 /* Enable IO xAPIC on this PCIe port */
Angel Pons2048cb42020-06-08 02:09:33 +020030 pci_or_config32(dev, 0xd8, 1 << 7);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020031
32 /* Enable Backbone Clock Gating */
Angel Pons2048cb42020-06-08 02:09:33 +020033 pci_or_config32(dev, 0xe1, (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0));
Arthur Heymans7b9c1392017-04-09 20:40:39 +020034
35 /* Set VC0 transaction class */
Angel Pons2048cb42020-06-08 02:09:33 +020036 pci_update_config32(dev, 0x114, ~0x000000ff, 1);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020037
38 /* Mask completion timeouts */
Angel Pons2048cb42020-06-08 02:09:33 +020039 pci_or_config32(dev, 0x148, 1 << 14);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020040
41 /* Lock R/WO Correctable Error Mask. */
Angel Pons2048cb42020-06-08 02:09:33 +020042 pci_update_config32(dev, 0x154, ~0, 0);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020043
44 /* Clear errors in status registers */
Angel Pons2048cb42020-06-08 02:09:33 +020045 pci_update_config16(dev, 0x06, ~0, 0);
46 pci_update_config16(dev, 0x1e, ~0, 0);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020047
48 /* Get configured ASPM state */
49 const enum aspm_type apmc = pci_read_config32(dev, 0x50) & 3;
50
51 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
Angel Pons2048cb42020-06-08 02:09:33 +020052 if (apmc == PCIE_ASPM_BOTH)
53 pci_or_config32(dev, 0xe8, 1 << 1);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020054
55 /* Enable expresscard hotplug events. */
56 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
Angel Pons2048cb42020-06-08 02:09:33 +020057
58 pci_or_config32(dev, 0xd8, 1 << 30);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020059 pci_write_config16(dev, 0x42, 0x142);
60 }
61}
62
Elyes HAOUAS1a8c1df2018-05-13 13:36:44 +020063static void pch_pciexp_scan_bridge(struct device *dev)
Arthur Heymans7b9c1392017-04-09 20:40:39 +020064{
Arthur Heymans349e0852017-04-09 20:48:37 +020065 struct southbridge_intel_i82801jx_config *config = dev->chip_info;
Arthur Heymans7b9c1392017-04-09 20:40:39 +020066
67 /* Normal PCIe Scan */
68 pciexp_scan_bridge(dev);
69
70 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
71 intel_acpi_pcie_hotplug_scan_slot(dev->link_list);
72 }
73}
74
Arthur Heymans7b9c1392017-04-09 20:40:39 +020075static struct device_operations device_ops = {
76 .read_resources = pci_bus_read_resources,
77 .set_resources = pci_dev_set_resources,
78 .enable_resources = pci_bus_enable_resources,
79 .init = pci_init,
80 .scan_bus = pch_pciexp_scan_bridge,
Angel Pons1fc0edd2020-05-31 00:03:28 +020081 .ops_pci = &pci_dev_ops_pci,
Arthur Heymans7b9c1392017-04-09 20:40:39 +020082};
83
Arthur Heymans349e0852017-04-09 20:48:37 +020084/* 82801lJx, ICH10 */
Arthur Heymans7b9c1392017-04-09 20:40:39 +020085static const unsigned short pci_device_ids[] = {
Arthur Heymans349e0852017-04-09 20:48:37 +020086 0x3a40, /* Port 1 */
87 0x3a42, /* Port 2 */
88 0x3a44, /* Port 3 */
89 0x3a46, /* Port 4 */
90 0x3a48, /* Port 5 */
91 0x3a4a, /* Port 6 */
92
93 0x3a70, /* Port 1 */
94 0x3a72, /* Port 2 */
95 0x3a74, /* Port 3 */
96 0x3a76, /* Port 4 */
97 0x3a78, /* Port 5 */
98 0x3a7a, /* Port 6 */
Arthur Heymans7b9c1392017-04-09 20:40:39 +020099 0
100};
Arthur Heymans349e0852017-04-09 20:48:37 +0200101
102static const struct pci_driver ich10_pcie __pci_driver = {
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200103 .ops = &device_ops,
104 .vendor = PCI_VENDOR_ID_INTEL,
105 .devices = pci_device_ids,
106};