2 * This file is part of the coreboot project.
4 * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
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; version 2 of the License.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <device/device.h>
21 #include <device/pci.h>
22 #include <device/pci_ids.h>
23 #include <console/console.h>
26 extern unsigned long log2(unsigned long x);
28 static void mmconfig_set_resources(device_t dev)
30 struct resource *resource;
33 resource = find_resource(dev, K8T890_MMCONFIG_MBAR);
35 report_resource_stored(dev, resource, "<mmconfig>");
37 /* Remember this resource has been stored. */
38 resource->flags |= IORESOURCE_STORED;
39 pci_write_config8(dev, K8T890_MMCONFIG_MBAR,
40 (resource->base >> 28));
41 reg = pci_read_config8(dev, 0x60);
43 /* Enable MMCONFIG decoding. */
44 pci_write_config8(dev, 0x60, reg);
46 pci_dev_set_resources(dev);
49 static void apic_mmconfig_read_resources(device_t dev)
52 pci_dev_read_resources(dev);
54 res = new_resource(dev, 0x40);
55 /* NB APIC fixed to this address. */
56 res->base = K8T890_APIC_BASE;
58 res->limit = res->base + res->size - 1;
61 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED |
62 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
64 /* Add an MMCONFIG resource. */
65 res = new_resource(dev, K8T890_MMCONFIG_MBAR);
66 res->size = 256 * 1024 * 1024;
67 res->align = log2(res->size);
68 res->gran = log2(res->size);
69 res->limit = 0xffffffff; /* 4G */
70 res->flags = IORESOURCE_MEM;
73 static void traf_ctrl_enable_generic(struct device *dev)
78 /* no device2 redirect, enable just one device behind
79 * bridge device 2 and device 3).
81 pci_write_config8(dev, 0x60, 0x08);
83 /* Will enable MMCONFIG later. */
84 pci_write_config8(dev, 0x64, 0x23);
85 /* No extended RCRB Base Address. */
86 pci_write_config8(dev, 0x62, 0x00);
88 /* Offset80 ->95 bit 4 in 1 in Award. */
90 /* Enable APIC, to K8T890_APIC_BASE. */
91 pci_write_config8(dev, 0x41, 0x00);
92 pci_write_config8(dev, 0x40, 0x8c);
93 /* BT_INTR enable, APIC Nonshare Mode Enable. */
94 pci_write_config8(dev, 0x42, 0x5);
96 apic = (u32 *)K8T890_APIC_BASE;
98 /* Set APIC to FSB transported messages. */
101 apic[4] = (data & 0xFFFFFE) | 1;
106 apic[4] = (data & 0xF0FFFF) | (K8T890_APIC_ID << 24);
109 static void traf_ctrl_enable_k8m890(struct device *dev)
111 traf_ctrl_enable_generic(dev);
114 static void traf_ctrl_enable_k8t890(struct device *dev)
118 traf_ctrl_enable_generic(dev);
120 /* Enable D3F1-D3F3 */
121 reg = pci_read_config8(dev, 0x60);
122 pci_write_config8(dev, 0x60, 0x80 | reg);
125 static const struct device_operations traf_ctrl_ops_m = {
126 .read_resources = apic_mmconfig_read_resources,
127 .set_resources = mmconfig_set_resources,
128 .enable_resources = pci_dev_enable_resources,
129 .enable = traf_ctrl_enable_k8m890,
133 static const struct device_operations traf_ctrl_ops_t = {
134 .read_resources = apic_mmconfig_read_resources,
135 .set_resources = mmconfig_set_resources,
136 .enable_resources = pci_dev_enable_resources,
137 .enable = traf_ctrl_enable_k8t890,
141 static const struct pci_driver northbridge_driver_t __pci_driver = {
142 .ops = &traf_ctrl_ops_t,
143 .vendor = PCI_VENDOR_ID_VIA,
144 .device = PCI_DEVICE_ID_VIA_K8T890CE_5,
147 static const struct pci_driver northbridge_driver_m __pci_driver = {
148 .ops = &traf_ctrl_ops_m,
149 .vendor = PCI_VENDOR_ID_VIA,
150 .device = PCI_DEVICE_ID_VIA_K8M890CE_5,