Stefan Reinauer | 8e07382 | 2012-04-04 00:07:22 +0200 | [diff] [blame^] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008-2009 coresystems GmbH |
| 5 | * |
| 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. |
| 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 | #include "pch.h" |
| 26 | |
| 27 | static void pci_init(struct device *dev) |
| 28 | { |
| 29 | u16 reg16; |
| 30 | u8 reg8; |
| 31 | |
| 32 | printk(BIOS_DEBUG, "PCI init.\n"); |
| 33 | /* Enable Bus Master */ |
| 34 | reg16 = pci_read_config16(dev, PCI_COMMAND); |
| 35 | reg16 |= PCI_COMMAND_MASTER; |
| 36 | pci_write_config16(dev, PCI_COMMAND, reg16); |
| 37 | |
| 38 | /* This device has no interrupt */ |
| 39 | pci_write_config8(dev, INTR, 0xff); |
| 40 | |
| 41 | /* disable parity error response and SERR */ |
| 42 | reg16 = pci_read_config16(dev, BCTRL); |
| 43 | reg16 &= ~(1 << 0); |
| 44 | reg16 &= ~(1 << 1); |
| 45 | pci_write_config16(dev, BCTRL, reg16); |
| 46 | |
| 47 | /* Master Latency Count must be set to 0x04! */ |
| 48 | reg8 = pci_read_config8(dev, SMLT); |
| 49 | reg8 &= 0x07; |
| 50 | reg8 |= (0x04 << 3); |
| 51 | pci_write_config8(dev, SMLT, reg8); |
| 52 | |
| 53 | /* Will this improve throughput of bus masters? */ |
| 54 | pci_write_config8(dev, PCI_MIN_GNT, 0x06); |
| 55 | |
| 56 | /* Clear errors in status registers */ |
| 57 | reg16 = pci_read_config16(dev, PSTS); |
| 58 | //reg16 |= 0xf900; |
| 59 | pci_write_config16(dev, PSTS, reg16); |
| 60 | |
| 61 | reg16 = pci_read_config16(dev, SECSTS); |
| 62 | // reg16 |= 0xf900; |
| 63 | pci_write_config16(dev, SECSTS, reg16); |
| 64 | } |
| 65 | |
| 66 | #undef PCI_BRIDGE_UPDATE_COMMAND |
| 67 | static void ich_pci_dev_enable_resources(struct device *dev) |
| 68 | { |
| 69 | const struct pci_operations *ops; |
| 70 | uint16_t command; |
| 71 | |
| 72 | /* Set the subsystem vendor and device id for mainboard devices */ |
| 73 | ops = ops_pci(dev); |
| 74 | if (dev->on_mainboard && ops && ops->set_subsystem) { |
| 75 | printk(BIOS_DEBUG, "%s subsystem <- %02x/%02x\n", |
| 76 | dev_path(dev), |
| 77 | CONFIG_MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID, |
| 78 | CONFIG_MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID); |
| 79 | ops->set_subsystem(dev, |
| 80 | CONFIG_MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID, |
| 81 | CONFIG_MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID); |
| 82 | } |
| 83 | |
| 84 | command = pci_read_config16(dev, PCI_COMMAND); |
| 85 | command |= dev->command; |
| 86 | #ifdef PCI_BRIDGE_UPDATE_COMMAND |
| 87 | /* If we write to PCI_COMMAND, on some systems |
| 88 | * this will cause the ROM and APICs not being visible |
| 89 | * anymore. |
| 90 | */ |
| 91 | printk(BIOS_DEBUG, "%s cmd <- %02x\n", dev_path(dev), command); |
| 92 | pci_write_config16(dev, PCI_COMMAND, command); |
| 93 | #else |
| 94 | printk(BIOS_DEBUG, "%s cmd <- %02x (NOT WRITTEN!)\n", dev_path(dev), command); |
| 95 | #endif |
| 96 | } |
| 97 | |
| 98 | static void ich_pci_bus_enable_resources(struct device *dev) |
| 99 | { |
| 100 | uint16_t ctrl; |
| 101 | /* enable IO in command register if there is VGA card |
| 102 | * connected with (even it does not claim IO resource) |
| 103 | */ |
| 104 | if (dev->link_list->bridge_ctrl & PCI_BRIDGE_CTL_VGA) |
| 105 | dev->command |= PCI_COMMAND_IO; |
| 106 | ctrl = pci_read_config16(dev, PCI_BRIDGE_CONTROL); |
| 107 | ctrl |= dev->link_list->bridge_ctrl; |
| 108 | ctrl |= (PCI_BRIDGE_CTL_PARITY + PCI_BRIDGE_CTL_SERR); /* error check */ |
| 109 | printk(BIOS_DEBUG, "%s bridge ctrl <- %04x\n", dev_path(dev), ctrl); |
| 110 | pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl); |
| 111 | |
| 112 | /* This is the reason we need our own pci_bus_enable_resources */ |
| 113 | ich_pci_dev_enable_resources(dev); |
| 114 | } |
| 115 | |
| 116 | static void set_subsystem(device_t dev, unsigned vendor, unsigned device) |
| 117 | { |
| 118 | /* NOTE: This is not the default position! */ |
| 119 | if (!vendor || !device) { |
| 120 | pci_write_config32(dev, 0x54, |
| 121 | pci_read_config32(dev, PCI_VENDOR_ID)); |
| 122 | } else { |
| 123 | pci_write_config32(dev, 0x54, |
| 124 | ((device & 0xffff) << 16) | (vendor & 0xffff)); |
| 125 | } |
| 126 | } |
| 127 | |
| 128 | static struct pci_operations pci_ops = { |
| 129 | .set_subsystem = set_subsystem, |
| 130 | }; |
| 131 | |
| 132 | static struct device_operations device_ops = { |
| 133 | .read_resources = pci_bus_read_resources, |
| 134 | .set_resources = pci_dev_set_resources, |
| 135 | .enable_resources = ich_pci_bus_enable_resources, |
| 136 | .init = pci_init, |
| 137 | .scan_bus = pci_scan_bridge, |
| 138 | .ops_pci = &pci_ops, |
| 139 | }; |
| 140 | |
| 141 | static const struct pci_driver pch_pci __pci_driver = { |
| 142 | .ops = &device_ops, |
| 143 | .vendor = PCI_VENDOR_ID_INTEL, |
| 144 | .device = 0x2448, |
| 145 | }; |