2 * This file is part of the coreboot project.
4 * Copyright (C) 2007 Corey Osgood <corey.osgood@gmail.com>
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.
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.
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
21 #include <console/console.h>
24 #include <device/device.h>
25 #include <device/pci.h>
26 #include <device/pci_ids.h>
28 #include "northbridge.h"
31 /* This is the main AGP device, and only one used when configured for AGP 2.0 */
32 static void agp_init(device_t dev)
38 /* Some of this may not be necessary (should be handled by the OS). */
39 printk(BIOS_DEBUG, "Enabling AGP.\n");
41 /* Allow R/W access to AGP registers. */
42 pci_write_config8(dev, 0x4d, 0x05);
44 /* Setup PCI latency timer. */
45 pci_write_config8(dev, 0xd, 0x8);
47 /* Write Secondary Vendor Ids */
48 pci_write_config32(dev, 0x2C, 0xAA071106);
51 * Set to AGP 3.0 Mode, which should theoretically render the rest of
52 * the registers set here pointless.
54 pci_write_config8(dev, 0x84, 0x1b);
56 /* AGP Request Queue Size */
57 pci_write_config8(dev, 0x4a, 0x1f);
60 * AGP Hardware Support (default 0xc4)
61 * 7: AGP SBA Enable (1 to Enable)
64 * 4: Fast Write Enable
65 * 3: AGP8X Mode Enable
66 * 2: AGP4X Mode Enable
67 * 1: AGP2X Mode Enable
68 * 0: AGP1X Mode Enable
70 pci_write_config8(dev, 0x4b, 0xc4);
72 /* Enable AGP Backdoor */
73 pci_write_config8(dev, 0xb5, 0x03);
75 /* Set aperture to 128 MB. */
76 /* TODO: Use config option, explain how it works. */
77 pci_write_config32(dev, 0x94, 0x00010f20);
78 /* Set GART Table Base Address (31:12). */
79 pci_write_config32(dev, 0x98, (0x37b20 << 12));
80 /* Set AGP Aperture Base. */
81 pci_write_config32(dev, 0x10, 0xe8000008);
83 /* NMI/AGPBUSY# Function Select */
84 pci_write_config8(dev, 0xbe, 0x80);
86 /* AGP Misc Control 1 */
87 pci_write_config8(dev, 0xc2, 0x40);
89 /* Enable CPU/PMSTR GART Access and DBI function. */
90 reg32 = pci_read_config8(dev, 0xbf);
92 pci_write_config8(dev, 0xbf, reg32);
94 /* Enable AGP Aperture. */
95 pci_write_config32(dev, 0x90, 0x0180);
98 pci_write_config8(dev, 0xbc, 0x25);
99 pci_write_config8(dev, 0xbd, 0xd2);
102 * AGP Pad, driving strength, and delay control. All this should be
103 * constant, seeing as the VGA controller is onboard.
105 pci_write_config8(dev, 0x40, 0xda);
106 pci_write_config8(dev, 0x41, 0xca);
107 pci_write_config8(dev, 0x42, 0x01);
108 pci_write_config8(dev, 0x43, 0xca);
109 pci_write_config8(dev, 0x44, 0x04);
111 /* AGPC CKG Control */
112 pci_write_config8(dev, 0xc0, 0x04);
113 pci_write_config8(dev, 0xc1, 0x02);
116 printk(BIOS_SPEW, "%s PCI Header Regs::\n", dev_path(dev));
118 for (i = 0 ; i < 16; i++)
120 printk(BIOS_SPEW, "%02X: ", i*16);
121 for (j = 0; j < 16; j++)
123 reg8 = pci_read_config8(dev, j+(i*16));
124 printk(BIOS_SPEW, "%02X ", reg8);
126 printk(BIOS_SPEW, "\n");
131 static const struct device_operations agp_operations = {
132 .read_resources = cn400_noop,
133 .set_resources = pci_dev_set_resources,
134 .enable_resources = pci_dev_enable_resources,
139 static const struct pci_driver agp_driver __pci_driver = {
140 .ops = &agp_operations,
141 .vendor = PCI_VENDOR_ID_VIA,
142 .device = PCI_DEVICE_ID_VIA_CN400_AGP,
145 static void agp_bridge_read_resources (device_t dev)
147 struct resource *res;
149 res = new_resource(dev, 1);
150 res->base = 0xF0000000ULL;
151 res->size = 0x06000000ULL;
152 res->limit = 0xffffffffULL;
153 res->flags = IORESOURCE_MEM | IORESOURCE_FIXED |
154 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
156 res = new_resource(dev, 2);
157 res->base = 0xB000UL;
159 res->limit = 0xffffUL;
160 res->flags = IORESOURCE_IO | IORESOURCE_FIXED |
161 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
165 * This is the AGP 3.0 "bridge" @Bus 0 Device 1 Func 0. When using AGP 3.0, the
166 * config in this device takes presidence. We configure both just to be safe.
168 static void agp_bridge_init(device_t dev)
173 printk(BIOS_DEBUG, "Entering %s\n", __func__);
175 pci_write_config16(dev, 0x4, 0x0107);
177 /* Secondary Bus Number */
178 pci_write_config8(dev, 0x19, 0x01);
179 /* Subordinate Bus Number */
180 pci_write_config8(dev, 0x1a, 0x01);
183 pci_write_config8(dev, 0x1c, 0xf0);
186 pci_write_config8(dev, 0x1d, 0x00);
189 pci_write_config16(dev, 0x20, 0xf400);
192 pci_write_config16(dev, 0x22, 0xf5f0);
194 /* Prefetchable Memory Base */
195 pci_write_config16(dev, 0x24, 0xf000);
197 /* Prefetchable Memory Limit */
198 pci_write_config16(dev, 0x26, 0xf3f0);
200 /* Enable VGA Compatible Memory/IO Range */
201 pci_write_config8(dev, 0x3e, 0x0e);
203 /* AGP Bus Control */
204 pci_write_config8(dev, 0x40, 0x83);
205 pci_write_config8(dev, 0x41, 0xC7);
206 pci_write_config8(dev, 0x42, 0x02);
207 pci_write_config8(dev, 0x43, 0x44);
208 pci_write_config8(dev, 0x44, 0x34);
209 pci_write_config8(dev, 0x45, 0x72);
211 printk(BIOS_SPEW, "%s PCI Header Regs::\n", dev_path(dev));
213 for (i = 0 ; i < 16; i++)
215 printk(BIOS_SPEW, "%02X: ", i*16);
216 for (j = 0; j < 16; j++)
218 reg8 = pci_read_config8(dev, j+(i*16));
219 printk(BIOS_SPEW, "%02X ", reg8);
221 printk(BIOS_SPEW, "\n");
226 static const struct device_operations agp_bridge_operations = {
227 .read_resources = agp_bridge_read_resources,
228 .set_resources = pci_dev_set_resources,
229 .enable_resources = pci_bus_enable_resources,
230 .init = agp_bridge_init,
231 .scan_bus = pci_scan_bridge,
235 static const struct pci_driver agp_bridge_driver __pci_driver = {
236 .ops = &agp_bridge_operations,
237 .vendor = PCI_VENDOR_ID_VIA,
238 .device = PCI_DEVICE_ID_VIA_CN400_BRIDGE,