blob: fce61b484a10ed4675edc5425fb9d3d4fd2cc61b [file] [log] [blame]
Corey Osgoodbd3f93e2008-02-21 00:56:14 +00001/*
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
Paul Menzela46a7122013-02-23 18:37:27 +010018 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000019 */
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>
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000027#include "northbridge.h"
28#include "cn700.h"
29
30/* This is the main AGP device, and only one used when configured for AGP 2.0 */
31static void agp_init(device_t dev)
32{
33 u32 reg32;
Uwe Hermannea7b5182008-10-09 17:08:32 +000034
35 /* Some of this may not be necessary (should be handled by the OS). */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000036 printk(BIOS_DEBUG, "Enabling AGP.\n");
Uwe Hermannea7b5182008-10-09 17:08:32 +000037
38 /* Allow R/W access to AGP registers. */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000039 pci_write_config8(dev, 0x4d, 0x15);
Uwe Hermannea7b5182008-10-09 17:08:32 +000040
41 /* Setup PCI latency timer. */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000042 pci_write_config8(dev, 0xd, 0x8);
Uwe Hermannea7b5182008-10-09 17:08:32 +000043
44 /*
45 * Set to AGP 3.0 Mode, which should theoretically render the rest of
46 * the registers set here pointless.
47 */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000048 pci_write_config8(dev, 0x84, 0xb);
Uwe Hermannea7b5182008-10-09 17:08:32 +000049
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000050 /* AGP Request Queue Size */
51 pci_write_config8(dev, 0x4a, 0x1f);
Uwe Hermannea7b5182008-10-09 17:08:32 +000052
53 /*
54 * AGP Hardware Support (default 0xc4)
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000055 * 7: AGP SBA Enable (1 to Enable)
56 * 6: AGP Enable
57 * 5: Reserved
58 * 4: Fast Write Enable
59 * 3: AGP8X Mode Enable
60 * 2: AGP4X Mode Enable
61 * 1: AGP2X Mode Enable
Uwe Hermannea7b5182008-10-09 17:08:32 +000062 * 0: AGP1X Mode Enable
63 */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000064 pci_write_config8(dev, 0x4b, 0xc4);
Uwe Hermannea7b5182008-10-09 17:08:32 +000065
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000066 /* Enable AGP Backdoor */
67 pci_write_config8(dev, 0xb5, 0x03);
Uwe Hermannea7b5182008-10-09 17:08:32 +000068
69 /* Set aperture to 32 MB. */
70 /* TODO: Use config option, explain how it works. */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000071 pci_write_config32(dev, 0x94, 0x00010f38);
Uwe Hermannea7b5182008-10-09 17:08:32 +000072 /* Set GART Table Base Address (31:12). */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000073 pci_write_config32(dev, 0x98, (0x1558 << 12));
Uwe Hermannea7b5182008-10-09 17:08:32 +000074 /* Set AGP Aperture Base. */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000075 pci_write_config32(dev, 0x10, 0xf8000008);
76
Uwe Hermannea7b5182008-10-09 17:08:32 +000077 /* Enable CPU/PMSTR GART Access. */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000078 reg32 = pci_read_config8(dev, 0xbf);
79 reg32 |= 0x80;
80 pci_write_config8(dev, 0xbf, reg32);
Uwe Hermannea7b5182008-10-09 17:08:32 +000081
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000082 /* Enable AGP Aperture. */
83 reg32 = pci_read_config32(dev, 0x94);
84 reg32 |= (3 << 7);
85 pci_write_config32(dev, 0x90, reg32);
86
87 /* AGP Control */
88 pci_write_config8(dev, 0xbc, 0x21);
89 pci_write_config8(dev, 0xbd, 0xd2);
Uwe Hermannea7b5182008-10-09 17:08:32 +000090
91 /*
92 * AGP Pad, driving strength, and delay control. All this should be
93 * constant, seeing as the VGA controller is onboard.
94 */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000095 pci_write_config8(dev, 0x40, 0xc7);
96 pci_write_config8(dev, 0x41, 0xdb);
97 pci_write_config8(dev, 0x42, 0x10);
98 pci_write_config8(dev, 0x43, 0xdb);
99 pci_write_config8(dev, 0x44, 0x24);
Uwe Hermannea7b5182008-10-09 17:08:32 +0000100
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000101 /* AGPC CKG Control */
102 pci_write_config8(dev, 0xc0, 0x02);
103 pci_write_config8(dev, 0xc1, 0x02);
104}
105
106static const struct device_operations agp_operations = {
Edward O'Callaghand2040732014-10-31 08:26:21 +1100107 .read_resources = DEVICE_NOOP,
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000108 .set_resources = pci_dev_set_resources,
109 .enable_resources = pci_dev_enable_resources,
110 .init = agp_init,
111 .ops_pci = 0,
112};
113
114static const struct pci_driver agp_driver __pci_driver = {
Uwe Hermannea7b5182008-10-09 17:08:32 +0000115 .ops = &agp_operations,
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000116 .vendor = PCI_VENDOR_ID_VIA,
117 .device = PCI_DEVICE_ID_VIA_CN700_AGP,
118};
119
Uwe Hermannea7b5182008-10-09 17:08:32 +0000120/*
121 * This is the AGP 3.0 "bridge" @Bus 0 Device 1 Func 0. When using AGP 3.0, the
122 * config in this device takes presidence. We configure both just to be safe.
123 */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000124static void agp_bridge_init(device_t dev)
125{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000126 printk(BIOS_DEBUG, "Setting up AGP bridge device\n");
Uwe Hermannea7b5182008-10-09 17:08:32 +0000127
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000128 pci_write_config16(dev, 0x4, 0x0007);
129
130 /* Secondary Bus Number */
131 pci_write_config8(dev, 0x19, 0x01);
132 /* Subordinate Bus Number */
133 pci_write_config8(dev, 0x1a, 0x01);
Uwe Hermannea7b5182008-10-09 17:08:32 +0000134 /* I/O Base */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000135 pci_write_config8(dev, 0x1c, 0xd0);
Uwe Hermannea7b5182008-10-09 17:08:32 +0000136 /* I/O Limit */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000137 pci_write_config8(dev, 0x1d, 0xd0);
Uwe Hermannea7b5182008-10-09 17:08:32 +0000138
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000139 /* Memory Base */
140 pci_write_config16(dev, 0x20, 0xfb00);
141 /* Memory Limit */
142 pci_write_config16(dev, 0x22, 0xfcf0);
143 /* Prefetchable Memory Base */
144 pci_write_config16(dev, 0x24, 0xf400);
145 /* Prefetchable Memory Limit */
146 pci_write_config16(dev, 0x26, 0xf7f0);
147 /* Enable VGA Compatible Memory/IO Range */
148 pci_write_config8(dev, 0x3e, 0x08);
149
150 /* Second PCI Bus Control (see datasheet) */
151 pci_write_config8(dev, 0x40, 0x83);
152 pci_write_config8(dev, 0x41, 0x43);
153 pci_write_config8(dev, 0x42, 0xe2);
154 pci_write_config8(dev, 0x43, 0x44);
155 pci_write_config8(dev, 0x44, 0x34);
156 pci_write_config8(dev, 0x45, 0x72);
157}
158
159static const struct device_operations agp_bridge_operations = {
Edward O'Callaghand2040732014-10-31 08:26:21 +1100160 .read_resources = DEVICE_NOOP,
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000161 .set_resources = pci_dev_set_resources,
162 .enable_resources = pci_bus_enable_resources,
163 .init = agp_bridge_init,
164 .scan_bus = pci_scan_bridge,
165 .ops_pci = 0,
166};
167
168static const struct pci_driver agp_bridge_driver __pci_driver = {
Uwe Hermannea7b5182008-10-09 17:08:32 +0000169 .ops = &agp_bridge_operations,
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000170 .vendor = PCI_VENDOR_ID_VIA,
171 .device = PCI_DEVICE_ID_VIA_CN700_BRIDGE,
172};