blob: c4375ea4e0a036b7a2b327b92430406ea195e4da [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.
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000015 */
16
17#include <console/console.h>
18#include <arch/io.h>
19#include <stdint.h>
20#include <device/device.h>
21#include <device/pci.h>
22#include <device/pci_ids.h>
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000023#include "northbridge.h"
24#include "cn700.h"
25
26/* This is the main AGP device, and only one used when configured for AGP 2.0 */
27static void agp_init(device_t dev)
28{
29 u32 reg32;
Uwe Hermannea7b5182008-10-09 17:08:32 +000030
31 /* Some of this may not be necessary (should be handled by the OS). */
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +000032 printk(BIOS_DEBUG, "Enabling AGP.\n");
Uwe Hermannea7b5182008-10-09 17:08:32 +000033
34 /* Allow R/W access to AGP registers. */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000035 pci_write_config8(dev, 0x4d, 0x15);
Uwe Hermannea7b5182008-10-09 17:08:32 +000036
37 /* Setup PCI latency timer. */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000038 pci_write_config8(dev, 0xd, 0x8);
Uwe Hermannea7b5182008-10-09 17:08:32 +000039
40 /*
41 * Set to AGP 3.0 Mode, which should theoretically render the rest of
42 * the registers set here pointless.
43 */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000044 pci_write_config8(dev, 0x84, 0xb);
Uwe Hermannea7b5182008-10-09 17:08:32 +000045
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000046 /* AGP Request Queue Size */
47 pci_write_config8(dev, 0x4a, 0x1f);
Uwe Hermannea7b5182008-10-09 17:08:32 +000048
49 /*
50 * AGP Hardware Support (default 0xc4)
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000051 * 7: AGP SBA Enable (1 to Enable)
52 * 6: AGP Enable
53 * 5: Reserved
54 * 4: Fast Write Enable
55 * 3: AGP8X Mode Enable
56 * 2: AGP4X Mode Enable
57 * 1: AGP2X Mode Enable
Uwe Hermannea7b5182008-10-09 17:08:32 +000058 * 0: AGP1X Mode Enable
59 */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000060 pci_write_config8(dev, 0x4b, 0xc4);
Uwe Hermannea7b5182008-10-09 17:08:32 +000061
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000062 /* Enable AGP Backdoor */
63 pci_write_config8(dev, 0xb5, 0x03);
Uwe Hermannea7b5182008-10-09 17:08:32 +000064
65 /* Set aperture to 32 MB. */
66 /* TODO: Use config option, explain how it works. */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000067 pci_write_config32(dev, 0x94, 0x00010f38);
Uwe Hermannea7b5182008-10-09 17:08:32 +000068 /* Set GART Table Base Address (31:12). */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000069 pci_write_config32(dev, 0x98, (0x1558 << 12));
Uwe Hermannea7b5182008-10-09 17:08:32 +000070 /* Set AGP Aperture Base. */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000071 pci_write_config32(dev, 0x10, 0xf8000008);
72
Uwe Hermannea7b5182008-10-09 17:08:32 +000073 /* Enable CPU/PMSTR GART Access. */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000074 reg32 = pci_read_config8(dev, 0xbf);
75 reg32 |= 0x80;
76 pci_write_config8(dev, 0xbf, reg32);
Uwe Hermannea7b5182008-10-09 17:08:32 +000077
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000078 /* Enable AGP Aperture. */
79 reg32 = pci_read_config32(dev, 0x94);
80 reg32 |= (3 << 7);
81 pci_write_config32(dev, 0x90, reg32);
82
83 /* AGP Control */
84 pci_write_config8(dev, 0xbc, 0x21);
85 pci_write_config8(dev, 0xbd, 0xd2);
Uwe Hermannea7b5182008-10-09 17:08:32 +000086
87 /*
88 * AGP Pad, driving strength, and delay control. All this should be
89 * constant, seeing as the VGA controller is onboard.
90 */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000091 pci_write_config8(dev, 0x40, 0xc7);
92 pci_write_config8(dev, 0x41, 0xdb);
93 pci_write_config8(dev, 0x42, 0x10);
94 pci_write_config8(dev, 0x43, 0xdb);
95 pci_write_config8(dev, 0x44, 0x24);
Uwe Hermannea7b5182008-10-09 17:08:32 +000096
Corey Osgoodbd3f93e2008-02-21 00:56:14 +000097 /* AGPC CKG Control */
98 pci_write_config8(dev, 0xc0, 0x02);
99 pci_write_config8(dev, 0xc1, 0x02);
100}
101
102static const struct device_operations agp_operations = {
Edward O'Callaghand2040732014-10-31 08:26:21 +1100103 .read_resources = DEVICE_NOOP,
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000104 .set_resources = pci_dev_set_resources,
105 .enable_resources = pci_dev_enable_resources,
106 .init = agp_init,
107 .ops_pci = 0,
108};
109
110static const struct pci_driver agp_driver __pci_driver = {
Uwe Hermannea7b5182008-10-09 17:08:32 +0000111 .ops = &agp_operations,
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000112 .vendor = PCI_VENDOR_ID_VIA,
113 .device = PCI_DEVICE_ID_VIA_CN700_AGP,
114};
115
Uwe Hermannea7b5182008-10-09 17:08:32 +0000116/*
117 * This is the AGP 3.0 "bridge" @Bus 0 Device 1 Func 0. When using AGP 3.0, the
118 * config in this device takes presidence. We configure both just to be safe.
119 */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000120static void agp_bridge_init(device_t dev)
121{
Stefan Reinauerc02b4fc2010-03-22 11:42:32 +0000122 printk(BIOS_DEBUG, "Setting up AGP bridge device\n");
Uwe Hermannea7b5182008-10-09 17:08:32 +0000123
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000124 pci_write_config16(dev, 0x4, 0x0007);
125
126 /* Secondary Bus Number */
127 pci_write_config8(dev, 0x19, 0x01);
128 /* Subordinate Bus Number */
129 pci_write_config8(dev, 0x1a, 0x01);
Uwe Hermannea7b5182008-10-09 17:08:32 +0000130 /* I/O Base */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000131 pci_write_config8(dev, 0x1c, 0xd0);
Uwe Hermannea7b5182008-10-09 17:08:32 +0000132 /* I/O Limit */
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000133 pci_write_config8(dev, 0x1d, 0xd0);
Uwe Hermannea7b5182008-10-09 17:08:32 +0000134
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000135 /* Memory Base */
136 pci_write_config16(dev, 0x20, 0xfb00);
137 /* Memory Limit */
138 pci_write_config16(dev, 0x22, 0xfcf0);
139 /* Prefetchable Memory Base */
140 pci_write_config16(dev, 0x24, 0xf400);
141 /* Prefetchable Memory Limit */
142 pci_write_config16(dev, 0x26, 0xf7f0);
143 /* Enable VGA Compatible Memory/IO Range */
144 pci_write_config8(dev, 0x3e, 0x08);
145
146 /* Second PCI Bus Control (see datasheet) */
147 pci_write_config8(dev, 0x40, 0x83);
148 pci_write_config8(dev, 0x41, 0x43);
149 pci_write_config8(dev, 0x42, 0xe2);
150 pci_write_config8(dev, 0x43, 0x44);
151 pci_write_config8(dev, 0x44, 0x34);
152 pci_write_config8(dev, 0x45, 0x72);
153}
154
155static const struct device_operations agp_bridge_operations = {
Edward O'Callaghand2040732014-10-31 08:26:21 +1100156 .read_resources = DEVICE_NOOP,
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000157 .set_resources = pci_dev_set_resources,
158 .enable_resources = pci_bus_enable_resources,
159 .init = agp_bridge_init,
160 .scan_bus = pci_scan_bridge,
161 .ops_pci = 0,
162};
163
164static const struct pci_driver agp_bridge_driver __pci_driver = {
Uwe Hermannea7b5182008-10-09 17:08:32 +0000165 .ops = &agp_bridge_operations,
Corey Osgoodbd3f93e2008-02-21 00:56:14 +0000166 .vendor = PCI_VENDOR_ID_VIA,
167 .device = PCI_DEVICE_ID_VIA_CN700_BRIDGE,
168};