blob: b2e4ce55611104ff3ee0bc321c49169f6c11e8d7 [file] [log] [blame]
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00001/*
2 * This file is part of the coreboot project.
3 *
Stefan Reinauer54309d62009-01-20 22:53:10 +00004 * Copyright (C) 2008-2009 coresystems GmbH
Stefan Reinauerdebb11f2008-10-29 04:46:52 +00005 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; either version 2 of the License, or
9 * (at your option) any later version.
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
26static void pci_init(struct device *dev)
27{
28 u16 reg16;
29
30#if 0
31 /* Commented out for now because it will break on some machines. */
32 /* Set latency timer to 32. */
33 pci_write_config16(dev, 0x1b, 0x20);
34#endif
35
36 /* disable parity error response */
37 reg16 = pci_read_config16(dev, 0x3e);
38 reg16 &= ~(1 << 0);
39 pci_write_config16(dev, 0x3e, reg16);
40
41 /* Clear errors in status registers */
42 reg16 = pci_read_config16(dev, 0x06);
43 reg16 |= 0xf900;
44 pci_write_config16(dev, 0x06, reg16);
45
46 reg16 = pci_read_config16(dev, 0x1e);
47 reg16 |= 0xf900;
48 pci_write_config16(dev, 0x1e, reg16);
Stefan Reinauer54309d62009-01-20 22:53:10 +000049
50 /* Will this improve throughput of bus masters? */
51 pci_write_config8(dev, PCI_MIN_GNT, 0x06);
Stefan Reinauerdebb11f2008-10-29 04:46:52 +000052}
53
54static void ich_pci_dev_enable_resources(struct device *dev)
55{
56 const struct pci_operations *ops;
57 uint16_t command;
58
59 /* Set the subsystem vendor and device id for mainboard devices */
60 ops = ops_pci(dev);
61 if (dev->on_mainboard && ops && ops->set_subsystem) {
62 printk_debug("%s subsystem <- %02x/%02x\n",
63 dev_path(dev),
64 MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID,
65 MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID);
66 ops->set_subsystem(dev,
67 MAINBOARD_PCI_SUBSYSTEM_VENDOR_ID,
68 MAINBOARD_PCI_SUBSYSTEM_DEVICE_ID);
69 }
70
71#if 0
72 /* If we write to PCI_COMMAND, on some systems
73 * this will cause the ROM and APICs not being visible
74 * anymore.
75 */
76 command = pci_read_config16(dev, PCI_COMMAND);
77 command |= dev->command;
78 printk_debug("%s cmd <- %02x\n", dev_path(dev), command);
79 pci_write_config16(dev, PCI_COMMAND, command);
80#endif
81}
82
83static void ich_pci_bus_enable_resources(struct device *dev)
84{
85 uint16_t ctrl;
86 /* enable IO in command register if there is VGA card
87 * connected with (even it does not claim IO resource)
88 */
89 if (dev->link[0].bridge_ctrl & PCI_BRIDGE_CTL_VGA)
90 dev->command |= PCI_COMMAND_IO;
91 ctrl = pci_read_config16(dev, PCI_BRIDGE_CONTROL);
92 ctrl |= dev->link[0].bridge_ctrl;
93 ctrl |= (PCI_BRIDGE_CTL_PARITY + PCI_BRIDGE_CTL_SERR); /* error check */
94 printk_debug("%s bridge ctrl <- %04x\n", dev_path(dev), ctrl);
95 pci_write_config16(dev, PCI_BRIDGE_CONTROL, ctrl);
96
97 /* This is the reason we need our own pci_bus_enable_resources */
98 ich_pci_dev_enable_resources(dev);
99
100 enable_childrens_resources(dev);
101}
102
103static void set_subsystem(device_t dev, unsigned vendor, unsigned device)
104{
105#if 0
106 /* Currently disabled because it causes a "BAR 9" memory resource
107 * conflict:
108 */
109 u32 pci_id;
110
111 printk_debug("Setting PCI bridge subsystem ID\n");
112 pci_id = pci_read_config32(dev, 0);
113 pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID, pci_id );
114#endif
115}
116
117static struct pci_operations pci_ops = {
118 .set_subsystem = set_subsystem,
119};
120
121static struct device_operations device_ops = {
122 .read_resources = pci_bus_read_resources,
123 .set_resources = pci_dev_set_resources,
124 .enable_resources = ich_pci_bus_enable_resources,
125 .init = pci_init,
126 .scan_bus = pci_scan_bridge,
127 .ops_pci = &pci_ops,
128};
129
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000130/* Desktop */
Uwe Hermannbddc6932008-10-29 13:51:31 +0000131/* 82801BA/CA/DB/EB/ER/FB/FR/FW/FRW/GB/GR/GDH/HB/IB/6300ESB/i3100 */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000132static const struct pci_driver i82801g_pci __pci_driver = {
133 .ops = &device_ops,
Uwe Hermannbddc6932008-10-29 13:51:31 +0000134 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000135 .device = 0x244e,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000136};
137
138/* Mobile / Ultra Mobile */
Uwe Hermannbddc6932008-10-29 13:51:31 +0000139/* 82801BAM/CAM/DBL/DBM/FBM/GBM/GHM/GU/HBM/HEM */
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000140static const struct pci_driver i82801gmu_pci __pci_driver = {
141 .ops = &device_ops,
Uwe Hermannbddc6932008-10-29 13:51:31 +0000142 .vendor = PCI_VENDOR_ID_INTEL,
Uwe Hermann5d7a1c82008-10-31 18:41:09 +0000143 .device = 0x2448,
Stefan Reinauerdebb11f2008-10-29 04:46:52 +0000144};