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. |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 15 | */ |
| 16 | |
| 17 | #include <console/console.h> |
| 18 | #include <device/device.h> |
| 19 | #include <device/pci.h> |
| 20 | #include <device/pci_ids.h> |
| 21 | |
| 22 | static void pci_init(struct device *dev) |
| 23 | { |
| 24 | u16 reg16; |
| 25 | u32 reg32; |
| 26 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 27 | printk(BIOS_DEBUG, "Initializing ICH7 PCIe bridge.\n"); |
Stefan Reinauer | 109ab31 | 2009-08-12 16:08:05 +0000 | [diff] [blame] | 28 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 29 | /* Enable Bus Master */ |
| 30 | reg32 = pci_read_config32(dev, PCI_COMMAND); |
| 31 | reg32 |= PCI_COMMAND_MASTER; |
| 32 | pci_write_config32(dev, PCI_COMMAND, reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 33 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 34 | /* Set Cache Line Size to 0x10 */ |
| 35 | // This has no effect but the OS might expect it |
| 36 | pci_write_config8(dev, 0x0c, 0x10); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 37 | |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 38 | reg16 = pci_read_config16(dev, 0x3e); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 39 | reg16 &= ~(1 << 0); /* disable parity error response */ |
| 40 | // reg16 &= ~(1 << 1); /* disable SERR */ |
| 41 | reg16 |= (1 << 2); /* ISA enable */ |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 42 | pci_write_config16(dev, 0x3e, reg16); |
| 43 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 44 | /* Enable IO xAPIC on this PCIe port */ |
| 45 | reg32 = pci_read_config32(dev, 0xd8); |
| 46 | reg32 |= (1 << 7); |
| 47 | pci_write_config32(dev, 0xd8, reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 48 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 49 | /* Enable Backbone Clock Gating */ |
| 50 | reg32 = pci_read_config32(dev, 0xe1); |
| 51 | reg32 |= (1 << 3) | (1 << 2) | (1 << 1) | (1 << 0); |
| 52 | pci_write_config32(dev, 0xe1, reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 53 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 54 | /* Set VC0 transaction class */ |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 55 | reg32 = pci_read_config32(dev, 0x114); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 56 | reg32 &= 0xffffff00; |
| 57 | reg32 |= 1; |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 58 | pci_write_config32(dev, 0x114, reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 59 | |
| 60 | /* Mask completion timeouts */ |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 61 | reg32 = pci_read_config32(dev, 0x148); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 62 | reg32 |= (1 << 14); |
Kyösti Mälkki | 8aa7e83 | 2013-07-26 08:52:10 +0300 | [diff] [blame] | 63 | pci_write_config32(dev, 0x148, reg32); |
| 64 | |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 65 | /* Enable common clock configuration */ |
| 66 | // Are there cases when we don't want that? |
| 67 | reg16 = pci_read_config16(dev, 0x50); |
| 68 | reg16 |= (1 << 6); |
| 69 | pci_write_config16(dev, 0x50, reg16); |
| 70 | |
Stefan Reinauer | de3206a | 2010-02-22 06:09:43 +0000 | [diff] [blame] | 71 | #ifdef EVEN_MORE_DEBUG |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 72 | reg32 = pci_read_config32(dev, 0x20); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 73 | printk(BIOS_SPEW, " MBL = 0x%08x\n", reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 74 | reg32 = pci_read_config32(dev, 0x24); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 75 | printk(BIOS_SPEW, " PMBL = 0x%08x\n", reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 76 | reg32 = pci_read_config32(dev, 0x28); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 77 | printk(BIOS_SPEW, " PMBU32 = 0x%08x\n", reg32); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 78 | reg32 = pci_read_config32(dev, 0x2c); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 79 | printk(BIOS_SPEW, " PMLU32 = 0x%08x\n", reg32); |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 80 | #endif |
| 81 | |
| 82 | /* Clear errors in status registers */ |
| 83 | reg16 = pci_read_config16(dev, 0x06); |
| 84 | //reg16 |= 0xf900; |
| 85 | pci_write_config16(dev, 0x06, reg16); |
| 86 | |
| 87 | reg16 = pci_read_config16(dev, 0x1e); |
| 88 | //reg16 |= 0xf900; |
| 89 | pci_write_config16(dev, 0x1e, reg16); |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 90 | } |
| 91 | |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame^] | 92 | static void pcie_set_subsystem(device_t dev, unsigned int vendor, |
| 93 | unsigned int device) |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 94 | { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 95 | /* NOTE: This is not the default position! */ |
| 96 | if (!vendor || !device) { |
| 97 | pci_write_config32(dev, 0x94, |
| 98 | pci_read_config32(dev, 0)); |
| 99 | } else { |
| 100 | pci_write_config32(dev, 0x94, |
| 101 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 102 | } |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 103 | } |
| 104 | |
| 105 | static struct pci_operations pci_ops = { |
Stefan Reinauer | a8e1168 | 2009-03-11 14:54:18 +0000 | [diff] [blame] | 106 | .set_subsystem = pcie_set_subsystem, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 107 | }; |
| 108 | |
| 109 | static struct device_operations device_ops = { |
| 110 | .read_resources = pci_bus_read_resources, |
| 111 | .set_resources = pci_dev_set_resources, |
| 112 | .enable_resources = pci_bus_enable_resources, |
| 113 | .init = pci_init, |
| 114 | .scan_bus = pci_scan_bridge, |
| 115 | .ops_pci = &pci_ops, |
| 116 | }; |
| 117 | |
Patrick Georgi | efff733 | 2012-07-26 19:48:23 +0200 | [diff] [blame] | 118 | static const unsigned short i82801gx_pcie_ids[] = { |
| 119 | 0x27d0, /* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */ |
| 120 | 0x27d2, /* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */ |
| 121 | 0x27d4, /* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */ |
| 122 | 0x27d6, /* 82801GB/GR/GDH/GBM/GHM (ICH7/ICH7R/ICH7DH/ICH7-M/ICH7-M DH) */ |
| 123 | 0x27e0, /* 82801GR/GDH/GHM (ICH7R/ICH7DH/ICH7-M DH) */ |
| 124 | 0x27e2, /* 82801GR/GDH/GHM (ICH7R/ICH7DH/ICH7-M DH) */ |
| 125 | 0 |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 126 | }; |
| 127 | |
Patrick Georgi | efff733 | 2012-07-26 19:48:23 +0200 | [diff] [blame] | 128 | static const struct pci_driver i82801gx_pcie __pci_driver = { |
Arthur Heymans | 3f111b0 | 2017-03-09 12:02:52 +0100 | [diff] [blame^] | 129 | .ops = &device_ops, |
| 130 | .vendor = PCI_VENDOR_ID_INTEL, |
| 131 | .devices = i82801gx_pcie_ids, |
Stefan Reinauer | debb11f | 2008-10-29 04:46:52 +0000 | [diff] [blame] | 132 | }; |