Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <device/device.h> |
| 5 | #include <device/pci.h> |
Kyösti Mälkki | df128a5 | 2019-09-21 18:35:37 +0300 | [diff] [blame] | 6 | #include <device/pci_def.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 7 | #include <device/pci_ops.h> |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 8 | #include <device/pciexp.h> |
| 9 | #include <device/pci_ids.h> |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 10 | #include <southbridge/intel/common/pciehp.h> |
| 11 | #include "chip.h" |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 12 | |
| 13 | static void pci_init(struct device *dev) |
| 14 | { |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 15 | struct southbridge_intel_i82801ix_config *config = dev->chip_info; |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 16 | |
| 17 | printk(BIOS_DEBUG, "Initializing ICH9 PCIe root port.\n"); |
| 18 | |
| 19 | /* Enable Bus Master */ |
Elyes HAOUAS | b9d2e22 | 2020-04-28 10:25:12 +0200 | [diff] [blame] | 20 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 21 | |
| 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 Pons | b82b431 | 2020-07-23 23:32:46 +0200 | [diff] [blame] | 26 | pci_and_config16(dev, PCI_BRIDGE_CONTROL, ~PCI_BRIDGE_CTL_PARITY); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 27 | |
| 28 | /* Enable IO xAPIC on this PCIe port */ |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 29 | pci_or_config32(dev, 0xd8, 1 << 7); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 30 | |
| 31 | /* Enable Backbone Clock Gating */ |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 32 | pci_or_config32(dev, 0xe1, (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0)); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 33 | |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 34 | /* Set VC0 transaction class */ |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 35 | pci_update_config32(dev, 0x114, ~0x000000ff, 1); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 36 | |
| 37 | /* Mask completion timeouts */ |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 38 | pci_or_config32(dev, 0x148, 1 << 14); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 39 | |
| 40 | /* Lock R/WO Correctable Error Mask. */ |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 41 | pci_update_config32(dev, 0x154, ~0, 0); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 42 | |
| 43 | /* Clear errors in status registers */ |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 44 | pci_update_config16(dev, 0x06, ~0, 0); |
| 45 | pci_update_config16(dev, 0x1e, ~0, 0); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 46 | |
| 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 Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 51 | if (apmc == PCIE_ASPM_BOTH) |
| 52 | pci_or_config32(dev, 0xe8, 1 << 1); |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 53 | |
| 54 | /* Enable expresscard hotplug events. */ |
| 55 | if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) { |
Angel Pons | 6740647 | 2020-06-08 11:13:42 +0200 | [diff] [blame] | 56 | |
| 57 | pci_or_config32(dev, 0xd8, 1 << 30); |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 58 | pci_write_config16(dev, 0x42, 0x142); |
| 59 | } |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 60 | } |
| 61 | |
Elyes HAOUAS | 8aa5073 | 2018-05-13 13:34:58 +0200 | [diff] [blame] | 62 | static void pch_pciexp_scan_bridge(struct device *dev) |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 63 | { |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 64 | struct southbridge_intel_i82801ix_config *config = dev->chip_info; |
| 65 | |
Arthur Heymans | a560c71 | 2021-02-24 22:27:44 +0100 | [diff] [blame] | 66 | 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); |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 71 | } |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 72 | } |
| 73 | |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 74 | static 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, |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 79 | .scan_bus = pch_pciexp_scan_bridge, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 80 | .ops_pci = &pci_dev_ops_pci, |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 81 | }; |
| 82 | |
| 83 | /* 82801Ix (ICH9DH/ICH9DO/ICH9R/ICH9/ICH9M-E/ICH9M) */ |
| 84 | static const unsigned short pci_device_ids[] = { |
Felix Singer | 7f8b0cd | 2019-11-10 11:04:08 +0100 | [diff] [blame] | 85 | PCI_DEVICE_ID_INTEL_82801IB_PCIE1, /* Port 1 */ |
| 86 | PCI_DEVICE_ID_INTEL_82801IB_PCIE2, /* Port 2 */ |
| 87 | PCI_DEVICE_ID_INTEL_82801IB_PCIE3, /* Port 3 */ |
| 88 | PCI_DEVICE_ID_INTEL_82801IB_PCIE4, /* Port 4 */ |
| 89 | PCI_DEVICE_ID_INTEL_82801IB_PCIE5, /* Port 5 */ |
| 90 | PCI_DEVICE_ID_INTEL_82801IB_PCIE6, /* Port 6 */ |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 91 | 0 |
| 92 | }; |
| 93 | static const struct pci_driver ich9_pcie __pci_driver = { |
| 94 | .ops = &device_ops, |
| 95 | .vendor = PCI_VENDOR_ID_INTEL, |
| 96 | .devices = pci_device_ids, |
| 97 | }; |