blob: 0068fb116f13d60e84eca8d3e5b6e96d5a1e6989 [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älkkif1b58b72019-03-01 13:43:02 +02006#include <device/pci_ops.h>
Arthur Heymans7b9c1392017-04-09 20:40:39 +02007#include <device/pciexp.h>
8#include <device/pci_ids.h>
9#include <southbridge/intel/common/pciehp.h>
10#include "chip.h"
11
12static void pci_init(struct device *dev)
13{
Arthur Heymans349e0852017-04-09 20:48:37 +020014 struct southbridge_intel_i82801jx_config *config = dev->chip_info;
Arthur Heymans7b9c1392017-04-09 20:40:39 +020015
Arthur Heymans349e0852017-04-09 20:48:37 +020016 printk(BIOS_DEBUG, "Initializing ICH10 PCIe root port.\n");
Arthur Heymans7b9c1392017-04-09 20:40:39 +020017
18 /* Enable Bus Master */
Elyes HAOUASca4ff252020-04-28 10:29:11 +020019 pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020020
21 /* Set Cache Line Size to 0x10 */
22 // This has no effect but the OS might expect it
23 pci_write_config8(dev, 0x0c, 0x10);
24
Angel Ponsb82b4312020-07-23 23:32:46 +020025 pci_and_config16(dev, PCI_BRIDGE_CONTROL, ~PCI_BRIDGE_CTL_PARITY);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020026
27 /* Enable IO xAPIC on this PCIe port */
Angel Pons2048cb42020-06-08 02:09:33 +020028 pci_or_config32(dev, 0xd8, 1 << 7);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020029
30 /* Enable Backbone Clock Gating */
Angel Pons2048cb42020-06-08 02:09:33 +020031 pci_or_config32(dev, 0xe1, (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0));
Arthur Heymans7b9c1392017-04-09 20:40:39 +020032
33 /* Set VC0 transaction class */
Angel Pons2048cb42020-06-08 02:09:33 +020034 pci_update_config32(dev, 0x114, ~0x000000ff, 1);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020035
36 /* Mask completion timeouts */
Angel Pons2048cb42020-06-08 02:09:33 +020037 pci_or_config32(dev, 0x148, 1 << 14);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020038
39 /* Lock R/WO Correctable Error Mask. */
Angel Pons2048cb42020-06-08 02:09:33 +020040 pci_update_config32(dev, 0x154, ~0, 0);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020041
42 /* Clear errors in status registers */
Angel Pons2048cb42020-06-08 02:09:33 +020043 pci_update_config16(dev, 0x06, ~0, 0);
44 pci_update_config16(dev, 0x1e, ~0, 0);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020045
46 /* Get configured ASPM state */
47 const enum aspm_type apmc = pci_read_config32(dev, 0x50) & 3;
48
49 /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */
Angel Pons2048cb42020-06-08 02:09:33 +020050 if (apmc == PCIE_ASPM_BOTH)
51 pci_or_config32(dev, 0xe8, 1 << 1);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020052
53 /* Enable expresscard hotplug events. */
54 if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
Angel Pons2048cb42020-06-08 02:09:33 +020055 pci_or_config32(dev, 0xd8, 1 << 30);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020056 pci_write_config16(dev, 0x42, 0x142);
57 }
58}
59
Elyes HAOUAS1a8c1df2018-05-13 13:36:44 +020060static void pch_pciexp_scan_bridge(struct device *dev)
Arthur Heymans7b9c1392017-04-09 20:40:39 +020061{
Arthur Heymans349e0852017-04-09 20:48:37 +020062 struct southbridge_intel_i82801jx_config *config = dev->chip_info;
Arthur Heymans7b9c1392017-04-09 20:40:39 +020063
Arthur Heymansa560c712021-02-24 22:27:44 +010064 if (CONFIG(PCIEXP_HOTPLUG) && config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) {
65 pciexp_hotplug_scan_bridge(dev);
66 } else {
67 /* Normal PCIe Scan */
68 pciexp_scan_bridge(dev);
Arthur Heymans7b9c1392017-04-09 20:40:39 +020069 }
70}
71
Arthur Heymans7b9c1392017-04-09 20:40:39 +020072static struct device_operations device_ops = {
73 .read_resources = pci_bus_read_resources,
74 .set_resources = pci_dev_set_resources,
75 .enable_resources = pci_bus_enable_resources,
76 .init = pci_init,
77 .scan_bus = pch_pciexp_scan_bridge,
Angel Pons1fc0edd2020-05-31 00:03:28 +020078 .ops_pci = &pci_dev_ops_pci,
Arthur Heymans7b9c1392017-04-09 20:40:39 +020079};
80
Arthur Heymans349e0852017-04-09 20:48:37 +020081/* 82801lJx, ICH10 */
Arthur Heymans7b9c1392017-04-09 20:40:39 +020082static const unsigned short pci_device_ids[] = {
Arthur Heymans349e0852017-04-09 20:48:37 +020083 0x3a40, /* Port 1 */
84 0x3a42, /* Port 2 */
85 0x3a44, /* Port 3 */
86 0x3a46, /* Port 4 */
87 0x3a48, /* Port 5 */
88 0x3a4a, /* Port 6 */
89
90 0x3a70, /* Port 1 */
91 0x3a72, /* Port 2 */
92 0x3a74, /* Port 3 */
93 0x3a76, /* Port 4 */
94 0x3a78, /* Port 5 */
95 0x3a7a, /* Port 6 */
Arthur Heymans7b9c1392017-04-09 20:40:39 +020096 0
97};
Arthur Heymans349e0852017-04-09 20:48:37 +020098
99static const struct pci_driver ich10_pcie __pci_driver = {
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200100 .ops = &device_ops,
Felix Singer43b7f412022-03-07 04:34:52 +0100101 .vendor = PCI_VID_INTEL,
Arthur Heymans7b9c1392017-04-09 20:40:39 +0200102 .devices = pci_device_ids,
103};