Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * 2012 secunet Security Networks AG |
| 6 | * |
| 7 | * This program is free software; you can redistribute it and/or |
| 8 | * modify it under the terms of the GNU General Public License as |
| 9 | * published by the Free Software Foundation; version 2 of |
| 10 | * the License. |
| 11 | * |
| 12 | * This program is distributed in the hope that it will be useful, |
| 13 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 14 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 15 | * GNU General Public License for more details. |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 16 | */ |
| 17 | |
| 18 | #include <console/console.h> |
| 19 | #include <device/device.h> |
| 20 | #include <device/pci.h> |
Kyösti Mälkki | df128a5 | 2019-09-21 18:35:37 +0300 | [diff] [blame] | 21 | #include <device/pci_def.h> |
Kyösti Mälkki | f1b58b7 | 2019-03-01 13:43:02 +0200 | [diff] [blame] | 22 | #include <device/pci_ops.h> |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 23 | #include <device/pciexp.h> |
| 24 | #include <device/pci_ids.h> |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 25 | #include <southbridge/intel/common/pciehp.h> |
| 26 | #include "chip.h" |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 27 | |
| 28 | static void pci_init(struct device *dev) |
| 29 | { |
| 30 | u16 reg16; |
| 31 | u32 reg32; |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 32 | struct southbridge_intel_i82801ix_config *config = dev->chip_info; |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 33 | |
| 34 | printk(BIOS_DEBUG, "Initializing ICH9 PCIe root port.\n"); |
| 35 | |
| 36 | /* Enable Bus Master */ |
| 37 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 38 | reg32 |= PCI_COMMAND_MASTER; |
| 39 | pci_write_config32(dev, PCI_COMMAND, reg32); |
| 40 | |
| 41 | /* Set Cache Line Size to 0x10 */ |
| 42 | // This has no effect but the OS might expect it |
| 43 | pci_write_config8(dev, 0x0c, 0x10); |
| 44 | |
Kyösti Mälkki | df128a5 | 2019-09-21 18:35:37 +0300 | [diff] [blame] | 45 | reg16 = pci_read_config16(dev, PCI_BRIDGE_CONTROL); |
| 46 | reg16 &= ~PCI_BRIDGE_CTL_PARITY; |
| 47 | reg16 |= PCI_BRIDGE_CTL_NO_ISA; |
| 48 | pci_write_config16(dev, PCI_BRIDGE_CONTROL, reg16); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 49 | |
| 50 | /* Enable IO xAPIC on this PCIe port */ |
| 51 | reg32 = pci_read_config32(dev, 0xd8); |
| 52 | reg32 |= (1 << 7); |
| 53 | pci_write_config32(dev, 0xd8, reg32); |
| 54 | |
| 55 | /* Enable Backbone Clock Gating */ |
| 56 | reg32 = pci_read_config32(dev, 0xe1); |
| 57 | reg32 |= (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0); |
| 58 | pci_write_config32(dev, 0xe1, reg32); |
| 59 | |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 60 | /* Set VC0 transaction class */ |
Kyösti Mälkki | 9b143e1 | 2013-07-26 08:35:09 +0300 | [diff] [blame] | 61 | reg32 = pci_read_config32(dev, 0x114); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 62 | reg32 &= 0xffffff00; |
| 63 | reg32 |= 1; |
Kyösti Mälkki | 9b143e1 | 2013-07-26 08:35:09 +0300 | [diff] [blame] | 64 | pci_write_config32(dev, 0x114, reg32); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 65 | |
| 66 | /* Mask completion timeouts */ |
Kyösti Mälkki | 9b143e1 | 2013-07-26 08:35:09 +0300 | [diff] [blame] | 67 | reg32 = pci_read_config32(dev, 0x148); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 68 | reg32 |= (1 << 14); |
Kyösti Mälkki | 9b143e1 | 2013-07-26 08:35:09 +0300 | [diff] [blame] | 69 | pci_write_config32(dev, 0x148, reg32); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 70 | |
| 71 | /* Lock R/WO Correctable Error Mask. */ |
Kyösti Mälkki | 9b143e1 | 2013-07-26 08:35:09 +0300 | [diff] [blame] | 72 | pci_write_config32(dev, 0x154, pci_read_config32(dev, 0x154)); |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 73 | |
| 74 | /* Clear errors in status registers */ |
| 75 | reg16 = pci_read_config16(dev, 0x06); |
| 76 | pci_write_config16(dev, 0x06, reg16); |
| 77 | reg16 = pci_read_config16(dev, 0x1e); |
| 78 | pci_write_config16(dev, 0x1e, reg16); |
| 79 | |
| 80 | /* Get configured ASPM state */ |
| 81 | const enum aspm_type apmc = pci_read_config32(dev, 0x50) & 3; |
| 82 | |
| 83 | /* If both L0s and L1 enabled then set root port 0xE8[1]=1 */ |
| 84 | if (apmc == PCIE_ASPM_BOTH) { |
| 85 | reg32 = pci_read_config32(dev, 0xe8); |
| 86 | reg32 |= (1 << 1); |
| 87 | pci_write_config32(dev, 0xe8, reg32); |
| 88 | } |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 89 | |
| 90 | /* Enable expresscard hotplug events. */ |
| 91 | if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) { |
| 92 | pci_write_config32(dev, 0xd8, |
| 93 | pci_read_config32(dev, 0xd8) |
| 94 | | (1 << 30)); |
| 95 | pci_write_config16(dev, 0x42, 0x142); |
| 96 | } |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 97 | } |
| 98 | |
Elyes HAOUAS | 8aa5073 | 2018-05-13 13:34:58 +0200 | [diff] [blame] | 99 | static void pch_pciexp_scan_bridge(struct device *dev) |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 100 | { |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 101 | struct southbridge_intel_i82801ix_config *config = dev->chip_info; |
| 102 | |
| 103 | /* Normal PCIe Scan */ |
Kyösti Mälkki | 580e722 | 2015-03-19 21:04:23 +0200 | [diff] [blame] | 104 | pciexp_scan_bridge(dev); |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 105 | |
| 106 | if (config->pcie_hotplug_map[PCI_FUNC(dev->path.pci.devfn)]) { |
| 107 | intel_acpi_pcie_hotplug_scan_slot(dev->link_list); |
| 108 | } |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 109 | } |
| 110 | |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 111 | static struct pci_operations pci_ops = { |
Subrata Banik | 15ccbf0 | 2019-03-20 15:09:44 +0530 | [diff] [blame] | 112 | .set_subsystem = pci_dev_set_subsystem, |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 113 | }; |
| 114 | |
| 115 | static struct device_operations device_ops = { |
| 116 | .read_resources = pci_bus_read_resources, |
| 117 | .set_resources = pci_dev_set_resources, |
| 118 | .enable_resources = pci_bus_enable_resources, |
| 119 | .init = pci_init, |
Vladimir Serbinenko | 36fa5b8 | 2014-10-28 23:43:20 +0100 | [diff] [blame] | 120 | .scan_bus = pch_pciexp_scan_bridge, |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 121 | .ops_pci = &pci_ops, |
| 122 | }; |
| 123 | |
| 124 | /* 82801Ix (ICH9DH/ICH9DO/ICH9R/ICH9/ICH9M-E/ICH9M) */ |
| 125 | static const unsigned short pci_device_ids[] = { |
Felix Singer | 7f8b0cd8 | 2019-11-10 11:04:08 +0100 | [diff] [blame^] | 126 | PCI_DEVICE_ID_INTEL_82801IB_PCIE1, /* Port 1 */ |
| 127 | PCI_DEVICE_ID_INTEL_82801IB_PCIE2, /* Port 2 */ |
| 128 | PCI_DEVICE_ID_INTEL_82801IB_PCIE3, /* Port 3 */ |
| 129 | PCI_DEVICE_ID_INTEL_82801IB_PCIE4, /* Port 4 */ |
| 130 | PCI_DEVICE_ID_INTEL_82801IB_PCIE5, /* Port 5 */ |
| 131 | PCI_DEVICE_ID_INTEL_82801IB_PCIE6, /* Port 6 */ |
Patrick Georgi | e72a8a3 | 2012-11-06 11:05:09 +0100 | [diff] [blame] | 132 | 0 |
| 133 | }; |
| 134 | static const struct pci_driver ich9_pcie __pci_driver = { |
| 135 | .ops = &device_ops, |
| 136 | .vendor = PCI_VENDOR_ID_INTEL, |
| 137 | .devices = pci_device_ids, |
| 138 | }; |