Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 1 | /* |
Stefan Reinauer | 7e61e45 | 2008-01-18 10:35:56 +0000 | [diff] [blame] | 2 | * This file is part of the coreboot project. |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2004 Tyan Computer |
| 5 | * Written by Yinghai Lu <yhlu@tyan.com> for Tyan Computer. |
| 6 | * Copyright (C) 2006,2007 AMD |
| 7 | * Written by Yinghai Lu <yinghai.lu@amd.com> for AMD. |
| 8 | * |
| 9 | * This program is free software; you can redistribute it and/or modify |
| 10 | * it under the terms of the GNU General Public License as published by |
| 11 | * the Free Software Foundation; either version 2 of the License, or |
| 12 | * (at your option) any later version. |
| 13 | * |
| 14 | * This program is distributed in the hope that it will be useful, |
| 15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 17 | * GNU General Public License for more details. |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #include <console/console.h> |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 21 | #include <arch/io.h> |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 22 | #include <device/device.h> |
| 23 | #include <device/pci.h> |
| 24 | #include <device/pci_ids.h> |
| 25 | #include <device/pci_ops.h> |
| 26 | #include "mcp55.h" |
| 27 | |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 28 | static u32 final_reg; |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 29 | |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 30 | static device_t find_lpc_dev(device_t dev, unsigned devfn) |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 31 | { |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 32 | device_t lpc_dev; |
| 33 | |
| 34 | lpc_dev = dev_find_slot(dev->bus->secondary, devfn); |
| 35 | |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 36 | if (!lpc_dev) |
| 37 | return lpc_dev; |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 38 | |
| 39 | if ((lpc_dev->vendor != PCI_VENDOR_ID_NVIDIA) || ( |
| 40 | (lpc_dev->device < PCI_DEVICE_ID_NVIDIA_MCP55_LPC) || |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 41 | (lpc_dev->device > PCI_DEVICE_ID_NVIDIA_MCP55_PRO))) |
| 42 | { |
| 43 | u32 id; |
| 44 | id = pci_read_config32(lpc_dev, PCI_VENDOR_ID); |
| 45 | if ((id < (PCI_VENDOR_ID_NVIDIA |
| 46 | | (PCI_DEVICE_ID_NVIDIA_MCP55_LPC << 16))) || |
| 47 | (id > (PCI_VENDOR_ID_NVIDIA |
| 48 | | (PCI_DEVICE_ID_NVIDIA_MCP55_PRO << 16)))) |
| 49 | { |
| 50 | lpc_dev = 0; |
| 51 | } |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 52 | } |
| 53 | |
| 54 | return lpc_dev; |
| 55 | } |
| 56 | |
| 57 | void mcp55_enable(device_t dev) |
| 58 | { |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 59 | device_t lpc_dev = 0, sm_dev = 0; |
| 60 | unsigned index = 0, index2 = 0; |
| 61 | u32 reg_old, reg; |
| 62 | u8 byte; |
| 63 | unsigned deviceid, vendorid, devfn; |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 64 | struct southbridge_nvidia_mcp55_config *conf; |
| 65 | conf = dev->chip_info; |
| 66 | int i; |
| 67 | |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 68 | if (dev->device == 0x0000) { |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 69 | vendorid = pci_read_config32(dev, PCI_VENDOR_ID); |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 70 | deviceid = (vendorid >> 16) & 0xffff; |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 71 | // vendorid &= 0xffff; |
| 72 | } else { |
| 73 | // vendorid = dev->vendor; |
| 74 | deviceid = dev->device; |
| 75 | } |
| 76 | |
Stefan Reinauer | 2b34db8 | 2009-02-28 20:10:20 +0000 | [diff] [blame] | 77 | devfn = (dev->path.pci.devfn) & ~7; |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 78 | switch (deviceid) { |
| 79 | case PCI_DEVICE_ID_NVIDIA_MCP55_HT: |
| 80 | return; |
| 81 | case PCI_DEVICE_ID_NVIDIA_MCP55_SM2: //? |
| 82 | index = 16; |
| 83 | break; |
| 84 | case PCI_DEVICE_ID_NVIDIA_MCP55_USB: |
| 85 | devfn -= (1 << 3); |
| 86 | index = 8; |
| 87 | break; |
| 88 | case PCI_DEVICE_ID_NVIDIA_MCP55_USB2: |
| 89 | devfn -= (1 << 3); |
| 90 | index = 20; |
| 91 | break; |
| 92 | case PCI_DEVICE_ID_NVIDIA_MCP55_NIC: // two |
| 93 | case PCI_DEVICE_ID_NVIDIA_MCP55_NIC_BRIDGE: // two |
| 94 | devfn -= (7 << 3); |
| 95 | index = 10; |
| 96 | for (i = 0; i < 2; i++) { |
| 97 | lpc_dev = find_lpc_dev(dev, devfn - (i << 3)); |
| 98 | if (!lpc_dev) |
| 99 | continue; |
| 100 | index -= i; |
| 101 | devfn -= (i << 3); |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 102 | break; |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 103 | } |
| 104 | break; |
| 105 | case PCI_DEVICE_ID_NVIDIA_MCP55_AZA: |
| 106 | devfn -= (5 << 3); |
| 107 | index = 11; |
| 108 | break; |
| 109 | case PCI_DEVICE_ID_NVIDIA_MCP55_IDE: |
| 110 | devfn -= (3 << 3); |
| 111 | index = 14; |
| 112 | break; |
| 113 | case PCI_DEVICE_ID_NVIDIA_MCP55_SATA0: // three |
| 114 | case PCI_DEVICE_ID_NVIDIA_MCP55_SATA1: // three |
| 115 | devfn -= (4 << 3); |
| 116 | index = 22; |
| 117 | i = (dev->path.pci.devfn) & 7; |
| 118 | if (i > 0) |
| 119 | index -= (i + 3); |
| 120 | break; |
| 121 | case PCI_DEVICE_ID_NVIDIA_MCP55_PCI: |
| 122 | devfn -= (5 << 3); |
| 123 | index = 15; |
| 124 | break; |
| 125 | case PCI_DEVICE_ID_NVIDIA_MCP55_PCIE_A: |
| 126 | devfn -= (0x9 << 3); // to LPC |
| 127 | index2 = 9; |
| 128 | break; |
| 129 | case PCI_DEVICE_ID_NVIDIA_MCP55_PCIE_B_C: // two |
| 130 | devfn -= (0xa << 3); // to LPC |
| 131 | index2 = 8; |
| 132 | for (i = 0; i < 2; i++) { |
| 133 | lpc_dev = find_lpc_dev(dev, devfn - (i << 3)); |
| 134 | if (!lpc_dev) |
| 135 | continue; |
| 136 | index2 -= i; |
| 137 | devfn -= (i << 3); |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 138 | break; |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 139 | } |
| 140 | break; |
| 141 | case PCI_DEVICE_ID_NVIDIA_MCP55_PCIE_D: |
| 142 | devfn -= (0xc << 3); // to LPC |
| 143 | index2 = 6; |
| 144 | break; |
| 145 | case PCI_DEVICE_ID_NVIDIA_MCP55_PCIE_E: |
| 146 | devfn -= (0xd << 3); // to LPC |
| 147 | index2 = 5; |
| 148 | break; |
| 149 | case PCI_DEVICE_ID_NVIDIA_MCP55_PCIE_F: |
| 150 | devfn -= (0xe << 3); // to LPC |
| 151 | index2 = 4; |
| 152 | break; |
| 153 | default: |
| 154 | index = 0; |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 155 | } |
| 156 | |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 157 | if (!lpc_dev) |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 158 | lpc_dev = find_lpc_dev(dev, devfn); |
| 159 | |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 160 | if (!lpc_dev) |
| 161 | return; |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 162 | |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 163 | if (index2 != 0) { |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 164 | sm_dev = dev_find_slot(dev->bus->secondary, devfn + 1); |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 165 | if (!sm_dev) |
| 166 | return; |
| 167 | if (sm_dev) { |
| 168 | reg_old = reg = pci_read_config32(sm_dev, 0xe4); |
| 169 | if (!dev->enabled) |
| 170 | reg |= (1<<index2); /* Disable it. */ |
| 171 | if (reg != reg_old) |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 172 | pci_write_config32(sm_dev, 0xe4, reg); |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 173 | } |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 174 | index2 = 0; |
| 175 | return; |
| 176 | } |
| 177 | |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 178 | if (index == 0) { // for LPC |
| 179 | /* Expose IOAPIC base. */ |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 180 | byte = pci_read_config8(lpc_dev, 0x74); |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 181 | byte |= (1 << 1); /* Expose the BAR. */ |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 182 | pci_write_config8(dev, 0x74, byte); |
| 183 | |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 184 | /* Expose trap base. */ |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 185 | byte = pci_read_config8(lpc_dev, 0xdd); |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 186 | byte |= (1 << 0) | (1 << 3); /* Expose BAR and enable write. */ |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 187 | pci_write_config8(dev, 0xdd, byte); |
| 188 | |
| 189 | return; |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 190 | } |
| 191 | |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 192 | if (index == 16) { |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 193 | sm_dev = dev_find_slot(dev->bus->secondary, devfn + 1); |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 194 | if (!sm_dev) |
| 195 | return; |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 196 | |
| 197 | final_reg = pci_read_config32(sm_dev, 0xe8); |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 198 | final_reg &= ~((1 << 16) | (1 << 8) | (1 << 20) | (1 << 14) |
| 199 | | (1 << 22) | (1 << 18) | (1 << 17) | (1 << 15) |
| 200 | | (1 << 11) | (1 << 10) | (1 << 9)); |
| 201 | pci_write_config32(sm_dev, 0xe8, final_reg); /* Enable all at first. */ |
| 202 | |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 203 | #if 0 |
| 204 | reg_old = reg = pci_read_config32(sm_dev, 0xe4); |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 205 | // reg |= (1 << 0); |
| 206 | reg &= ~(0x3f << 4); |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 207 | if (reg != reg_old) { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 208 | printk(BIOS_DEBUG, "mcp55.c pcie enabled\n"); |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 209 | pci_write_config32(sm_dev, 0xe4, reg); |
| 210 | } |
| 211 | #endif |
| 212 | } |
| 213 | |
| 214 | if (!dev->enabled) { |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 215 | final_reg |= (1 << index); /* Disable it. */ |
| 216 | /* |
Martin Roth | e9c1b21 | 2014-12-09 13:49:34 -0700 | [diff] [blame] | 217 | * The reason for using final_reg is that if func 1 is disabled, |
| 218 | * then func 2 will become func 1. |
| 219 | * Because of this, we need loop through disabling them all at |
| 220 | * the same time. |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 221 | */ |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 222 | } |
| 223 | |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 224 | /* NIC1 is the final, we need update final reg to 0xe8. */ |
| 225 | if (index == 9) { |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 226 | sm_dev = dev_find_slot(dev->bus->secondary, devfn + 1); |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 227 | if (!sm_dev) |
| 228 | return; |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 229 | reg_old = pci_read_config32(sm_dev, 0xe8); |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 230 | if (final_reg != reg_old) |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 231 | pci_write_config32(sm_dev, 0xe8, final_reg); |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 232 | } |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 233 | } |
| 234 | |
Jonathan Kollasch | dca8b1b | 2010-10-29 20:40:06 +0000 | [diff] [blame] | 235 | static void mcp55_set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 236 | { |
| 237 | pci_write_config32(dev, 0x40, |
| 238 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 239 | } |
| 240 | |
| 241 | struct pci_operations mcp55_pci_ops = { |
| 242 | .set_subsystem = mcp55_set_subsystem, |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 243 | }; |
Jonathan Kollasch | dca8b1b | 2010-10-29 20:40:06 +0000 | [diff] [blame] | 244 | |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 245 | struct chip_operations southbridge_nvidia_mcp55_ops = { |
Uwe Hermann | 8a20213 | 2007-02-19 19:11:20 +0000 | [diff] [blame] | 246 | CHIP_NAME("NVIDIA MCP55 Southbridge") |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 247 | .enable_dev = mcp55_enable, |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 248 | }; |