Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 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 |
Paul Menzel | a46a712 | 2013-02-23 18:37:27 +0100 | [diff] [blame] | 18 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 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> |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 27 | #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 */ |
| 31 | static void agp_init(device_t dev) |
| 32 | { |
| 33 | u32 reg32; |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 34 | |
| 35 | /* Some of this may not be necessary (should be handled by the OS). */ |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 36 | printk(BIOS_DEBUG, "Enabling AGP.\n"); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 37 | |
| 38 | /* Allow R/W access to AGP registers. */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 39 | pci_write_config8(dev, 0x4d, 0x15); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 40 | |
| 41 | /* Setup PCI latency timer. */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 42 | pci_write_config8(dev, 0xd, 0x8); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 43 | |
| 44 | /* |
| 45 | * Set to AGP 3.0 Mode, which should theoretically render the rest of |
| 46 | * the registers set here pointless. |
| 47 | */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 48 | pci_write_config8(dev, 0x84, 0xb); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 49 | |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 50 | /* AGP Request Queue Size */ |
| 51 | pci_write_config8(dev, 0x4a, 0x1f); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 52 | |
| 53 | /* |
| 54 | * AGP Hardware Support (default 0xc4) |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 55 | * 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 Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 62 | * 0: AGP1X Mode Enable |
| 63 | */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 64 | pci_write_config8(dev, 0x4b, 0xc4); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 65 | |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 66 | /* Enable AGP Backdoor */ |
| 67 | pci_write_config8(dev, 0xb5, 0x03); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 68 | |
| 69 | /* Set aperture to 32 MB. */ |
| 70 | /* TODO: Use config option, explain how it works. */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 71 | pci_write_config32(dev, 0x94, 0x00010f38); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 72 | /* Set GART Table Base Address (31:12). */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 73 | pci_write_config32(dev, 0x98, (0x1558 << 12)); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 74 | /* Set AGP Aperture Base. */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 75 | pci_write_config32(dev, 0x10, 0xf8000008); |
| 76 | |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 77 | /* Enable CPU/PMSTR GART Access. */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 78 | reg32 = pci_read_config8(dev, 0xbf); |
| 79 | reg32 |= 0x80; |
| 80 | pci_write_config8(dev, 0xbf, reg32); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 81 | |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 82 | /* 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 Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 90 | |
| 91 | /* |
| 92 | * AGP Pad, driving strength, and delay control. All this should be |
| 93 | * constant, seeing as the VGA controller is onboard. |
| 94 | */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 95 | 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 Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 100 | |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 101 | /* AGPC CKG Control */ |
| 102 | pci_write_config8(dev, 0xc0, 0x02); |
| 103 | pci_write_config8(dev, 0xc1, 0x02); |
| 104 | } |
| 105 | |
| 106 | static const struct device_operations agp_operations = { |
Edward O'Callaghan | d204073 | 2014-10-31 08:26:21 +1100 | [diff] [blame] | 107 | .read_resources = DEVICE_NOOP, |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 108 | .set_resources = pci_dev_set_resources, |
| 109 | .enable_resources = pci_dev_enable_resources, |
| 110 | .init = agp_init, |
| 111 | .ops_pci = 0, |
| 112 | }; |
| 113 | |
| 114 | static const struct pci_driver agp_driver __pci_driver = { |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 115 | .ops = &agp_operations, |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 116 | .vendor = PCI_VENDOR_ID_VIA, |
| 117 | .device = PCI_DEVICE_ID_VIA_CN700_AGP, |
| 118 | }; |
| 119 | |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 120 | /* |
| 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 Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 124 | static void agp_bridge_init(device_t dev) |
| 125 | { |
Stefan Reinauer | c02b4fc | 2010-03-22 11:42:32 +0000 | [diff] [blame] | 126 | printk(BIOS_DEBUG, "Setting up AGP bridge device\n"); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 127 | |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 128 | 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 Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 134 | /* I/O Base */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 135 | pci_write_config8(dev, 0x1c, 0xd0); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 136 | /* I/O Limit */ |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 137 | pci_write_config8(dev, 0x1d, 0xd0); |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 138 | |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 139 | /* 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 | |
| 159 | static const struct device_operations agp_bridge_operations = { |
Edward O'Callaghan | d204073 | 2014-10-31 08:26:21 +1100 | [diff] [blame] | 160 | .read_resources = DEVICE_NOOP, |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 161 | .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 | |
| 168 | static const struct pci_driver agp_bridge_driver __pci_driver = { |
Uwe Hermann | ea7b518 | 2008-10-09 17:08:32 +0000 | [diff] [blame] | 169 | .ops = &agp_bridge_operations, |
Corey Osgood | bd3f93e | 2008-02-21 00:56:14 +0000 | [diff] [blame] | 170 | .vendor = PCI_VENDOR_ID_VIA, |
| 171 | .device = PCI_DEVICE_ID_VIA_CN700_BRIDGE, |
| 172 | }; |