blob: 1d02898688bf2f1e1819214666543d58f6f2843b [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 Ponsb82b4312020-07-23 23:32:46 +020026 pci_and_config16(dev, PCI_BRIDGE_CONTROL, ~PCI_BRIDGE_CTL_PARITY);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020027
28 /* Enable IO xAPIC on this PCIe port */
Angel Pons2048cb42020-06-08 02:09:33 +020029 pci_or_config32(dev, 0xd8, 1 << 7);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020030
31 /* Enable Backbone Clock Gating */
Angel Pons2048cb42020-06-08 02:09:33 +020032 pci_or_config32(dev, 0xe1, (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0));
Arthur Heymans7b9c1392017-04-09 20:40:39 +020033
34 /* Set VC0 transaction class */
Angel Pons2048cb42020-06-08 02:09:33 +020035 pci_update_config32(dev, 0x114, ~0x000000ff, 1);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020036
37 /* Mask completion timeouts */
Angel Pons2048cb42020-06-08 02:09:33 +020038 pci_or_config32(dev, 0x148, 1 << 14);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020039
40 /* Lock R/WO Correctable Error Mask. */
Angel Pons2048cb42020-06-08 02:09:33 +020041 pci_update_config32(dev, 0x154, ~0, 0);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020042
43 /* Clear errors in status registers */
Angel Pons2048cb42020-06-08 02:09:33 +020044 pci_update_config16(dev, 0x06, ~0, 0);
45 pci_update_config16(dev, 0x1e, ~0, 0);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020046
47 /* Get configured ASPM state */
48 const enum aspm_type apmc = pci_read_config32(dev, 0x50) & 3;
49
50 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
Angel Pons2048cb42020-06-08 02:09:33 +020051 if (apmc == PCIE_ASPM_BOTH)
52 pci_or_config32(dev, 0xe8, 1 << 1);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020053
54 /* Enable expresscard hotplug events. */
55 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
Angel Pons2048cb42020-06-08 02:09:33 +020056
57 pci_or_config32(dev, 0xd8, 1 << 30);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020058 pci_write_config16(dev, 0x42, 0x142);
59 }
60}
61
Elyes HAOUAS1a8c1df2018-05-13 13:36:44 +020062static void pch_pciexp_scan_bridge(struct device *dev)
Arthur Heymans7b9c1392017-04-09 20:40:39 +020063{
Arthur Heymans349e0852017-04-09 20:48:37 +020064 struct southbridge_intel_i82801jx_config *config = dev->chip_info;
Arthur Heymans7b9c1392017-04-09 20:40:39 +020065
Arthur Heymansa560c712021-02-24 22:27:44 +010066 if (CONFIG(PCIEXP_HOTPLUG) && config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
67 pciexp_hotplug_scan_bridge(dev);
68 } else {
69 /* Normal PCIe Scan */
70 pciexp_scan_bridge(dev);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020071 }
72}
73
Arthur Heymans7b9c1392017-04-09 20:40:39 +020074static struct device_operations device_ops = {
75 .read_resources = pci_bus_read_resources,
76 .set_resources = pci_dev_set_resources,
77 .enable_resources = pci_bus_enable_resources,
78 .init = pci_init,
79 .scan_bus = pch_pciexp_scan_bridge,
Angel Pons1fc0edd2020-05-31 00:03:28 +020080 .ops_pci = &pci_dev_ops_pci,
Arthur Heymans7b9c1392017-04-09 20:40:39 +020081};
82
Arthur Heymans349e0852017-04-09 20:48:37 +020083/* 82801lJx, ICH10 */
Arthur Heymans7b9c1392017-04-09 20:40:39 +020084static const unsigned short pci_device_ids[] = {
Arthur Heymans349e0852017-04-09 20:48:37 +020085 0x3a40, /* Port 1 */
86 0x3a42, /* Port 2 */
87 0x3a44, /* Port 3 */
88 0x3a46, /* Port 4 */
89 0x3a48, /* Port 5 */
90 0x3a4a, /* Port 6 */
91
92 0x3a70, /* Port 1 */
93 0x3a72, /* Port 2 */
94 0x3a74, /* Port 3 */
95 0x3a76, /* Port 4 */
96 0x3a78, /* Port 5 */
97 0x3a7a, /* Port 6 */
Arthur Heymans7b9c1392017-04-09 20:40:39 +020098 0
99};
Arthur Heymans349e0852017-04-09 20:48:37 +0200100
101static const struct pci_driver ich10_pcie __pci_driver = {
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200102 .ops = &device_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100103 .vendor = PCI_VID_INTEL,
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200104 .devices = pci_device_ids,
105};