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> |
| 21 | #include <device/device.h> |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 22 | #include <device/resource.h> |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 23 | #include <device/pci.h> |
| 24 | #include <device/pci_ids.h> |
| 25 | #include <device/pci_ops.h> |
| 26 | #include "mcp55.h" |
| 27 | |
| 28 | static void pci_init(struct device *dev) |
| 29 | { |
Uwe Hermann | c7f0c8f | 2011-01-04 19:51:33 +0000 | [diff] [blame] | 30 | u32 dword; |
| 31 | u16 word; |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 32 | device_t pci_domain_dev; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 33 | struct resource *mem, *pref; |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 34 | |
| 35 | /* System error enable */ |
| 36 | dword = pci_read_config32(dev, 0x04); |
| 37 | dword |= (1<<8); /* System error enable */ |
| 38 | dword |= (1<<30); /* Clear possible errors */ |
| 39 | pci_write_config32(dev, 0x04, dword); |
| 40 | |
| 41 | #if 1 |
| 42 | //only need (a01,xx] |
| 43 | word = pci_read_config16(dev, 0x48); |
| 44 | word |= (1<<0); /* MRL2MRM */ |
| 45 | word |= (1<<2); /* MR2MRM */ |
| 46 | pci_write_config16(dev, 0x48, word); |
| 47 | #endif |
| 48 | |
| 49 | #if 1 |
| 50 | dword = pci_read_config32(dev, 0x4c); |
| 51 | dword |= 0x00440000; /*TABORT_SER_ENABLE Park Last Enable.*/ |
| 52 | pci_write_config32(dev, 0x4c, dword); |
| 53 | #endif |
| 54 | |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 55 | pci_domain_dev = dev->bus->dev; |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 56 | while (pci_domain_dev) { |
Stefan Reinauer | 4aff445 | 2013-02-12 14:17:15 -0800 | [diff] [blame] | 57 | if (pci_domain_dev->path.type == DEVICE_PATH_DOMAIN) |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 58 | break; |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 59 | pci_domain_dev = pci_domain_dev->bus->dev; |
| 60 | } |
| 61 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 62 | if (!pci_domain_dev) |
| 63 | return; /* Impossible */ |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 64 | |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 65 | pref = probe_resource(pci_domain_dev, IOINDEX_SUBTRACTIVE(2,0)); |
| 66 | mem = probe_resource(pci_domain_dev, IOINDEX_SUBTRACTIVE(1,0)); |
| 67 | |
| 68 | if (!mem) |
| 69 | return; /* Impossible */ |
| 70 | |
| 71 | if (!pref || pref->base > mem->base) { |
| 72 | dword = mem->base & (0xffff0000UL); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 73 | printk(BIOS_DEBUG, "PCI DOMAIN mem base = 0x%010Lx\n", mem->base); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 74 | } else { |
| 75 | dword = pref->base & (0xffff0000UL); |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 76 | printk(BIOS_DEBUG, "PCI DOMAIN pref base = 0x%010Lx\n", pref->base); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 77 | } |
| 78 | |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 79 | printk(BIOS_DEBUG, "[0x50] <-- 0x%08x\n", dword); |
Myles Watson | 29cc9ed | 2009-07-02 18:56:24 +0000 | [diff] [blame] | 80 | pci_write_config32(dev, 0x50, dword); /* TOM */ |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 81 | } |
| 82 | |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 83 | static struct device_operations pci_ops = { |
| 84 | .read_resources = pci_bus_read_resources, |
| 85 | .set_resources = pci_dev_set_resources, |
| 86 | .enable_resources = pci_bus_enable_resources, |
| 87 | .init = pci_init, |
| 88 | .scan_bus = pci_scan_bridge, |
| 89 | // .enable = mcp55_enable, |
| 90 | .reset_bus = pci_bus_reset, |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 91 | }; |
| 92 | |
Stefan Reinauer | f1cf1f7 | 2007-10-24 09:08:58 +0000 | [diff] [blame] | 93 | static const struct pci_driver pci_driver __pci_driver = { |
Yinghai Lu | c65bd56 | 2007-02-01 00:10:05 +0000 | [diff] [blame] | 94 | .ops = &pci_ops, |
| 95 | .vendor = PCI_VENDOR_ID_NVIDIA, |
| 96 | .device = PCI_DEVICE_ID_NVIDIA_MCP55_PCI, |
| 97 | }; |