printk_foo -> printk(BIOS_FOO, ...)
[coreboot.git] / src / northbridge / via / cn400 / agp.c
1 /*
2  * This file is part of the coreboot project.
3  *
4  * Copyright (C) 2007 Corey Osgood <corey.osgood@gmail.com>
5  *
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 <arch/io.h>
23 #include <stdint.h>
24 #include <device/device.h>
25 #include <device/pci.h>
26 #include <device/pci_ids.h>
27 #include "chip.h"
28 #include "northbridge.h"
29 #include "cn400.h"
30
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)
33 {
34         u32 reg32;
35         u8 reg8;
36         int i, j;
37
38         /* Some of this may not be necessary (should be handled by the OS). */
39         printk(BIOS_DEBUG, "Enabling AGP.\n");
40
41         /* Allow R/W access to AGP registers. */
42         pci_write_config8(dev, 0x4d, 0x05);
43
44         /* Setup PCI latency timer. */
45         pci_write_config8(dev, 0xd, 0x8);
46
47         /* Write Secondary Vendor Ids */
48         pci_write_config32(dev, 0x2C, 0xAA071106);
49
50         /*
51          * Set to AGP 3.0 Mode, which should theoretically render the rest of
52          * the registers set here pointless.
53          */
54         pci_write_config8(dev, 0x84, 0x1b);
55
56         /* AGP Request Queue Size */
57         pci_write_config8(dev, 0x4a, 0x1f);
58
59         /*
60          * AGP Hardware Support (default 0xc4)
61          * 7: AGP SBA Enable (1 to Enable)
62          * 6: AGP Enable
63          * 5: Reserved
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
69          */
70         pci_write_config8(dev, 0x4b, 0xc4);
71
72         /* Enable AGP Backdoor */
73         pci_write_config8(dev, 0xb5, 0x03);
74
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);
82
83         /* NMI/AGPBUSY# Function Select */
84         pci_write_config8(dev, 0xbe, 0x80);
85
86         /* AGP Misc Control 1 */
87         pci_write_config8(dev, 0xc2, 0x40);
88
89         /* Enable CPU/PMSTR GART Access and DBI function. */
90         reg32 = pci_read_config8(dev, 0xbf);
91         reg32 |= 0x8c;
92         pci_write_config8(dev, 0xbf, reg32);
93
94         /* Enable AGP Aperture. */
95         pci_write_config32(dev, 0x90, 0x0180);
96
97         /* AGP Control */
98         pci_write_config8(dev, 0xbc, 0x25);
99         pci_write_config8(dev, 0xbd, 0xd2);
100
101         /*
102          * AGP Pad, driving strength, and delay control. All this should be
103          * constant, seeing as the VGA controller is onboard.
104          */
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);
110
111         /* AGPC CKG Control */
112         pci_write_config8(dev, 0xc0, 0x04);
113         pci_write_config8(dev, 0xc1, 0x02);
114
115 #ifdef DEBUG_CN400
116         printk(BIOS_SPEW, "%s PCI Header Regs::\n", dev_path(dev));
117
118         for (i = 0 ; i < 16; i++)
119         {
120                 printk(BIOS_SPEW, "%02X: ", i*16);
121                 for (j = 0; j < 16; j++)
122                 {
123                         reg8 = pci_read_config8(dev, j+(i*16));
124                         printk(BIOS_SPEW, "%02X ", reg8);
125                 }
126                 printk(BIOS_SPEW, "\n");
127         }
128 #endif
129 }
130
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,
135         .init             = agp_init,
136         .ops_pci          = 0,
137 };
138
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,
143 };
144
145 static void agp_bridge_read_resources (device_t dev)
146 {
147         struct resource *res;
148
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;
155
156         res = new_resource(dev, 2);
157         res->base = 0xB000UL;
158         res->size = 4096;
159         res->limit = 0xffffUL;
160         res->flags = IORESOURCE_IO | IORESOURCE_FIXED |
161                                 IORESOURCE_STORED | IORESOURCE_ASSIGNED;
162
163 }
164 /*
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.
167  */
168 static void agp_bridge_init(device_t dev)
169 {
170         u8 reg8;
171         int i, j;
172
173         printk(BIOS_DEBUG, "Entering %s\n", __func__);
174
175         pci_write_config16(dev, 0x4, 0x0107);
176
177         /* Secondary Bus Number */
178         pci_write_config8(dev, 0x19, 0x01);
179         /* Subordinate Bus Number */
180         pci_write_config8(dev, 0x1a, 0x01);
181
182         /* I/O Base */
183         pci_write_config8(dev, 0x1c, 0xf0);
184
185         /* I/O Limit */
186         pci_write_config8(dev, 0x1d, 0x00);
187
188         /* Memory Base */
189         pci_write_config16(dev, 0x20, 0xf400);
190
191         /* Memory Limit */
192         pci_write_config16(dev, 0x22, 0xf5f0);
193
194         /* Prefetchable Memory Base */
195         pci_write_config16(dev, 0x24, 0xf000);
196
197         /* Prefetchable Memory Limit */
198         pci_write_config16(dev, 0x26, 0xf3f0);
199
200         /* Enable VGA Compatible Memory/IO Range */
201         pci_write_config8(dev, 0x3e, 0x0e);
202
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);
210
211         printk(BIOS_SPEW, "%s PCI Header Regs::\n", dev_path(dev));
212
213         for (i = 0 ; i < 16; i++)
214         {
215                 printk(BIOS_SPEW, "%02X: ", i*16);
216                 for (j = 0; j < 16; j++)
217                 {
218                         reg8 = pci_read_config8(dev, j+(i*16));
219                         printk(BIOS_SPEW, "%02X ", reg8);
220                 }
221                 printk(BIOS_SPEW, "\n");
222         }
223
224 }
225
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,
232         .ops_pci          = 0,
233 };
234
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,
239 };