Angel Pons | 182dbde | 2020-04-02 23:49:05 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 2 | |
| 3 | #include <console/console.h> |
| 4 | #include <device/device.h> |
| 5 | #include <device/pci.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 6 | #include <device/pci_ops.h> |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 7 | #include <device/pciexp.h> |
| 8 | #include <device/pci_ids.h> |
| 9 | #include <southbridge/intel/common/pciehp.h> |
| 10 | #include "chip.h" |
| 11 | |
| 12 | static void pci_init(struct device *dev) |
| 13 | { |
Arthur Heymans | 349e085 | 2017-04-09 20:48:37 +0200 | [diff] [blame] | 14 | struct southbridge_intel_i82801jx_config *config = dev->chip_info; |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 15 | |
Arthur Heymans | 349e085 | 2017-04-09 20:48:37 +0200 | [diff] [blame] | 16 | printk(BIOS_DEBUG, "Initializing ICH10 PCIe root port.\n"); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 17 | |
| 18 | /* Enable Bus Master */ |
Elyes HAOUAS | ca4ff25 | 2020-04-28 10:29:11 +0200 | [diff] [blame] | 19 | pci_or_config16(dev, PCI_COMMAND, PCI_COMMAND_MASTER); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 20 | |
| 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 Pons | b82b431 | 2020-07-23 23:32:46 +0200 | [diff] [blame] | 25 | pci_and_config16(dev, PCI_BRIDGE_CONTROL, ~PCI_BRIDGE_CTL_PARITY); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 26 | |
| 27 | /* Enable IO xAPIC on this PCIe port */ |
Angel Pons | 2048cb4 | 2020-06-08 02:09:33 +0200 | [diff] [blame] | 28 | pci_or_config32(dev, 0xd8, 1 << 7); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 29 | |
| 30 | /* Enable Backbone Clock Gating */ |
Angel Pons | 2048cb4 | 2020-06-08 02:09:33 +0200 | [diff] [blame] | 31 | pci_or_config32(dev, 0xe1, (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0)); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 32 | |
| 33 | /* Set VC0 transaction class */ |
Angel Pons | 2048cb4 | 2020-06-08 02:09:33 +0200 | [diff] [blame] | 34 | pci_update_config32(dev, 0x114, ~0x000000ff, 1); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 35 | |
| 36 | /* Mask completion timeouts */ |
Angel Pons | 2048cb4 | 2020-06-08 02:09:33 +0200 | [diff] [blame] | 37 | pci_or_config32(dev, 0x148, 1 << 14); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 38 | |
| 39 | /* Lock R/WO Correctable Error Mask. */ |
Angel Pons | 2048cb4 | 2020-06-08 02:09:33 +0200 | [diff] [blame] | 40 | pci_update_config32(dev, 0x154, ~0, 0); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 41 | |
| 42 | /* Clear errors in status registers */ |
Angel Pons | 2048cb4 | 2020-06-08 02:09:33 +0200 | [diff] [blame] | 43 | pci_update_config16(dev, 0x06, ~0, 0); |
| 44 | pci_update_config16(dev, 0x1e, ~0, 0); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 45 | |
| 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 Pons | 2048cb4 | 2020-06-08 02:09:33 +0200 | [diff] [blame] | 50 | if (apmc == PCIE_ASPM_BOTH) |
| 51 | pci_or_config32(dev, 0xe8, 1 << 1); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 52 | |
| 53 | /* Enable expresscard hotplug events. */ |
| 54 | if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) { |
Angel Pons | 2048cb4 | 2020-06-08 02:09:33 +0200 | [diff] [blame] | 55 | |
| 56 | pci_or_config32(dev, 0xd8, 1 << 30); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 57 | pci_write_config16(dev, 0x42, 0x142); |
| 58 | } |
| 59 | } |
| 60 | |
Elyes HAOUAS | 1a8c1df | 2018-05-13 13:36:44 +0200 | [diff] [blame] | 61 | static void pch_pciexp_scan_bridge(struct device *dev) |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 62 | { |
Arthur Heymans | 349e085 | 2017-04-09 20:48:37 +0200 | [diff] [blame] | 63 | struct southbridge_intel_i82801jx_config *config = dev->chip_info; |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 64 | |
Arthur Heymans | a560c71 | 2021-02-24 22:27:44 +0100 | [diff] [blame] | 65 | if (CONFIG(PCIEXP_HOTPLUG) && config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) { |
| 66 | pciexp_hotplug_scan_bridge(dev); |
| 67 | } else { |
| 68 | /* Normal PCIe Scan */ |
| 69 | pciexp_scan_bridge(dev); |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 70 | } |
| 71 | } |
| 72 | |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 73 | static struct device_operations device_ops = { |
| 74 | .read_resources = pci_bus_read_resources, |
| 75 | .set_resources = pci_dev_set_resources, |
| 76 | .enable_resources = pci_bus_enable_resources, |
| 77 | .init = pci_init, |
| 78 | .scan_bus = pch_pciexp_scan_bridge, |
Angel Pons | 1fc0edd | 2020-05-31 00:03:28 +0200 | [diff] [blame] | 79 | .ops_pci = &pci_dev_ops_pci, |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 80 | }; |
| 81 | |
Arthur Heymans | 349e085 | 2017-04-09 20:48:37 +0200 | [diff] [blame] | 82 | /* 82801lJx, ICH10 */ |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 83 | static const unsigned short pci_device_ids[] = { |
Arthur Heymans | 349e085 | 2017-04-09 20:48:37 +0200 | [diff] [blame] | 84 | 0x3a40, /* Port 1 */ |
| 85 | 0x3a42, /* Port 2 */ |
| 86 | 0x3a44, /* Port 3 */ |
| 87 | 0x3a46, /* Port 4 */ |
| 88 | 0x3a48, /* Port 5 */ |
| 89 | 0x3a4a, /* Port 6 */ |
| 90 | |
| 91 | 0x3a70, /* Port 1 */ |
| 92 | 0x3a72, /* Port 2 */ |
| 93 | 0x3a74, /* Port 3 */ |
| 94 | 0x3a76, /* Port 4 */ |
| 95 | 0x3a78, /* Port 5 */ |
| 96 | 0x3a7a, /* Port 6 */ |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 97 | 0 |
| 98 | }; |
Arthur Heymans | 349e085 | 2017-04-09 20:48:37 +0200 | [diff] [blame] | 99 | |
| 100 | static const struct pci_driver ich10_pcie __pci_driver = { |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 101 | .ops = &device_ops, |
Felix Singer | 43b7f41 | 2022-03-07 04:34:52 +0100 | [diff] [blame] | 102 | .vendor = PCI_VID_INTEL, |
Arthur Heymans | 7b9c139 | 2017-04-09 20:40:39 +0200 | [diff] [blame] | 103 | .devices = pci_device_ids, |
| 104 | }; |