Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 4 | * Copyright (C) 2008-2009 coresystems GmbH |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 5 | * |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 6 | * This program is free software; you can redistribute it and/or |
| 7 | * modify it under the terms of the GNU General Public License as |
| 8 | * published by the Free Software Foundation; version 2 of |
| 9 | * the License. |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
| 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
| 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
| 19 | */ |
| 20 | |
| 21 | #include <console/console.h> |
| 22 | #include <device/device.h> |
| 23 | #include <device/pci.h> |
| 24 | #include <device/pci_ids.h> |
| 25 | |
| 26 | static void pci_init(struct device *dev) |
| 27 | { |
| 28 | u16 reg16; |
| 29 | u32 reg32; |
| 30 | |
| 31 | printk_debug("Initializing ICH7 PCIe bridge.\n"); |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame^] | 32 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 33 | /* Enable Bus Master */ |
| 34 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 35 | reg32 |= PCI_COMMAND_MASTER; |
| 36 | pci_write_config32(dev, PCI_COMMAND, reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 37 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 38 | /* Set Cache Line Size to 0x10 */ |
| 39 | // This has no effect but the OS might expect it |
| 40 | pci_write_config8(dev, 0x0c, 0x10); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 41 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 42 | reg16 = pci_read_config16(dev, 0x3e); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 43 | reg16 &= ~(1 << 0); /* disable parity error response */ |
| 44 | // reg16 &= ~(1 << 1); /* disable SERR */ |
| 45 | reg16 |= (1 << 2); /* ISA enable */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 46 | pci_write_config16(dev, 0x3e, reg16); |
| 47 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 48 | /* Enable IO xAPIC on this PCIe port */ |
| 49 | reg32 = pci_read_config32(dev, 0xd8); |
| 50 | reg32 |= (1 << 7); |
| 51 | pci_write_config32(dev, 0xd8, reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 52 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 53 | /* Enable Backbone Clock Gating */ |
| 54 | reg32 = pci_read_config32(dev, 0xe1); |
| 55 | reg32 |= (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0); |
| 56 | pci_write_config32(dev, 0xe1, reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 57 | |
Stefan Reinauer | 0867062 | 2009-06-30 15:17:49 +0000 | [diff] [blame] | 58 | #if CONFIG_MMCONF_SUPPORT |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 59 | /* Set VC0 transaction class */ |
| 60 | reg32 = pci_mmio_read_config32(dev, 0x114); |
| 61 | reg32 &= 0xffffff00; |
| 62 | reg32 |= 1; |
| 63 | pci_mmio_write_config32(dev, 0x114, reg32); |
| 64 | |
| 65 | /* Mask completion timeouts */ |
| 66 | reg32 = pci_mmio_read_config32(dev, 0x148); |
| 67 | reg32 |= (1 << 14); |
| 68 | pci_mmio_write_config32(dev, 0x148, reg32); |
| 69 | #else |
| 70 | #error "MMIO needed for ICH7 PCIe" |
| 71 | #endif |
| 72 | /* Enable common clock configuration */ |
| 73 | // Are there cases when we don't want that? |
| 74 | reg16 = pci_read_config16(dev, 0x50); |
| 75 | reg16 |= (1 << 6); |
| 76 | pci_write_config16(dev, 0x50, reg16); |
| 77 | |
| 78 | #if EVEN_MORE_DEBUG |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 79 | reg32 = pci_read_config32(dev, 0x20); |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 80 | printk_spew(" MBL = 0x%08x\n", reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 81 | reg32 = pci_read_config32(dev, 0x24); |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 82 | printk_spew(" PMBL = 0x%08x\n", reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 83 | reg32 = pci_read_config32(dev, 0x28); |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 84 | printk_spew(" PMBU32 = 0x%08x\n", reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 85 | reg32 = pci_read_config32(dev, 0x2c); |
Stefan Reinauer | 54309d6 | 2009-01-20 22:53:10 +0000 | [diff] [blame] | 86 | printk_spew(" PMLU32 = 0x%08x\n", reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 87 | #endif |
| 88 | |
| 89 | /* Clear errors in status registers */ |
| 90 | reg16 = pci_read_config16(dev, 0x06); |
| 91 | //reg16 |= 0xf900; |
| 92 | pci_write_config16(dev, 0x06, reg16); |
| 93 | |
| 94 | reg16 = pci_read_config16(dev, 0x1e); |
| 95 | //reg16 |= 0xf900; |
| 96 | pci_write_config16(dev, 0x1e, reg16); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 97 | } |
| 98 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 99 | static void pcie_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 100 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 101 | /* NOTE: This is not the default position! */ |
| 102 | if (!vendor || !device) { |
| 103 | pci_write_config32(dev, 0x94, |
| 104 | pci_read_config32(dev, 0)); |
| 105 | } else { |
| 106 | pci_write_config32(dev, 0x94, |
| 107 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 108 | } |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | static struct pci_operations pci_ops = { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 112 | .set_subsystem = pcie_set_subsystem, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [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, |
| 120 | .scan_bus = pci_scan_bridge, |
| 121 | .ops_pci = &pci_ops, |
| 122 | }; |
| 123 | |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 124 | /* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 125 | static const struct pci_driver i82801gx_pcie_port1 __pci_driver = { |
| 126 | .ops = &device_ops, |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 127 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 128 | .device = 0x27d0, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 129 | }; |
| 130 | |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 131 | /* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 132 | static const struct pci_driver i82801gx_pcie_port2 __pci_driver = { |
| 133 | .ops = &device_ops, |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 134 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 135 | .device = 0x27d2, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 136 | }; |
| 137 | |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 138 | /* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 139 | static const struct pci_driver i82801gx_pcie_port3 __pci_driver = { |
| 140 | .ops = &device_ops, |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 141 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 142 | .device = 0x27d4, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 143 | }; |
| 144 | |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 145 | /* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 146 | static const struct pci_driver i82801gx_pcie_port4 __pci_driver = { |
| 147 | .ops = &device_ops, |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 148 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 149 | .device = 0x27d6, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 150 | }; |
| 151 | |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 152 | /* 82801GR/GDH/GHM (ICH7R/ICH7DH/ICH7-M DH) */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 153 | static const struct pci_driver i82801gx_pcie_port5 __pci_driver = { |
| 154 | .ops = &device_ops, |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 155 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 156 | .device = 0x27e0, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 157 | }; |
| 158 | |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 159 | /* 82801GR/GDH/GHM (ICH7R/ICH7DH/ICH7-M DH) */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 160 | static const struct pci_driver i82801gx_pcie_port6 __pci_driver = { |
| 161 | .ops = &device_ops, |
Uwe Hermann | bddc693 | 2008-10-29 13:51:31 +0000 | [diff] [blame] | 162 | .vendor = PCI_VENDOR_ID_INTEL, |
Uwe Hermann | 5d7a1c8 | 2008-10-31 18:41:09 +0000 | [diff] [blame] | 163 | .device = 0x27e2, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 164 | }; |