2 * This file is part of the coreboot project.
4 * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
5 * Copyright (C) 2011 Alexandru Gagniuc <mr.nuke.me@gmail.com>
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
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 <device/device.h>
22 #include <device/pci.h>
23 #include <device/pci_ids.h>
24 #include <console/console.h>
25 #include <cpu/x86/msr.h>
26 #include <cpu/amd/mtrr.h>
27 #include <pc80/mc146818rtc.h>
31 static void dram_enable(struct device *dev)
37 * Enable Lowest Interrupt arbitration for APIC, enable NB APIC
38 * decoding, MSI support, no SMRAM, compatible SMM.
40 pci_write_config8(dev, 0x86, 0x19);
43 * We want to use the 0xC0000-0xEFFFF as RAM mark area as RW, even if
44 * memory is doing K8 the DMA from SB will fail if we have it wrong,
45 * AND even we have it here, we must later copy it to SB to make it work :/
48 /* For CC000-CFFFF, bits 7:6 (10 = REn, 01 = WEn) bits 1:0 for
51 pci_write_config8(dev, 0x80, 0xff);
52 /* For page D0000-DFFFF */
53 pci_write_config8(dev, 0x81, 0xff);
54 /* For page E0000-EFFFF */
55 pci_write_config8(dev, 0x82, 0xff);
56 pci_write_config8(dev, 0x83, 0x30);
59 reg = pci_read_config16(dev, 0x84);
61 pci_write_config16(dev, 0x84, (msr.lo >> 16) | reg);
63 reg = pci_read_config16(dev, 0x88);
66 /* The Address Next to the Last Valid DRAM Address */
67 pci_write_config16(dev, 0x88, (msr.lo >> 24) | reg);
69 print_debug(" VIA_X_3 device dump:\n");
75 extern uint64_t uma_memory_base, uma_memory_size;
78 static void dram_enable_k8m890(struct device *dev)
86 if (CONFIG_VIDEO_MB == -1) {
87 ret = get_option(&fbbits, "videoram_size");
89 printk(BIOS_WARNING, "Failed to get videoram size (error %d), using default.\n", ret);
93 if ((fbbits < 1) || (fbbits > 7)) {
94 printk(BIOS_WARNING, "Invalid videoram size (%d), using default.\n",
98 uma_memory_size = 4 << (fbbits + 20);
100 uma_memory_size = (CONFIG_VIDEO_MB << 20);
103 msr = rdmsr(TOP_MEM);
104 uma_memory_base = msr.lo - uma_memory_size;
105 printk(BIOS_INFO, "K8M890: UMA base is %llx size is %u (MB)\n", uma_memory_base,
106 (u32) (uma_memory_size / 1024 / 1024));
107 /* enable VGA, so the bridges gets VGA_EN and resources are set */
108 pci_write_config8(dev, 0xa1, 0x80);
114 k8m890_host_fb_size_get(void)
116 struct device *dev = dev_find_device(PCI_VENDOR_ID_VIA,
117 PCI_DEVICE_ID_VIA_K8M800_DRAM, 0);
118 if(!dev) dev = dev_find_device(PCI_VENDOR_ID_VIA,
119 PCI_DEVICE_ID_VIA_K8M890CE_3, 0);
122 tmp = pci_read_config8(dev, 0xA1);
125 return 4 << (tmp & 7);
130 static void dram_init_fb(struct device *dev)
134 * Enable the internal GFX bit 7 of reg 0xa1 plus in same reg:
135 * bits 6:4 X fbuffer size will be 2^(X+2) or 100 = 64MB, 101 = 128MB
136 * bits 3:0 BASE [31:28]
137 * reg 0xa0 bits 7:1 BASE [27:21] bit0 enable CPU access
139 unsigned int fbbits = 0;
142 fbbits = ((log2(uma_memory_size >> 20) - 2) << 4);
143 printk(BIOS_INFO, "K8M890: Using a %dMB framebuffer.\n", (unsigned int) (uma_memory_size >> 20));
145 /* Step 1: enable UMA but no FB */
146 pci_write_config8(dev, 0xa1, 0x80);
148 /* Step 2: enough is just the FB size, the CPU accessible address is not needed */
150 pci_write_config8(dev, 0xa1, tmp);
152 /* TODO K8 needs some UMA fine tuning too maybe call some generic routine here? */
156 static const struct device_operations dram_ops_t = {
157 .read_resources = pci_dev_read_resources,
158 .set_resources = pci_dev_set_resources,
159 .enable_resources = pci_dev_enable_resources,
160 .enable = dram_enable,
164 static const struct device_operations dram_ops_m = {
165 .read_resources = pci_dev_read_resources,
166 .set_resources = pci_dev_set_resources,
167 .enable_resources = pci_dev_enable_resources,
168 .enable = dram_enable_k8m890,
169 .init = dram_init_fb,
173 static const struct pci_driver northbridge_driver_t800 __pci_driver = {
175 .vendor = PCI_VENDOR_ID_VIA,
176 .device = PCI_DEVICE_ID_VIA_K8T800_DRAM,
179 static const struct pci_driver northbridge_driver_m800 __pci_driver = {
181 .vendor = PCI_VENDOR_ID_VIA,
182 .device = PCI_DEVICE_ID_VIA_K8M800_DRAM,
185 static const struct pci_driver northbridge_driver_t890 __pci_driver = {
187 .vendor = PCI_VENDOR_ID_VIA,
188 .device = PCI_DEVICE_ID_VIA_K8T890CE_3,
191 static const struct pci_driver northbridge_driver_t890cf __pci_driver = {
193 .vendor = PCI_VENDOR_ID_VIA,
194 .device = PCI_DEVICE_ID_VIA_K8T890CF_3,
197 static const struct pci_driver northbridge_driver_m890 __pci_driver = {
199 .vendor = PCI_VENDOR_ID_VIA,
200 .device = PCI_DEVICE_ID_VIA_K8M890CE_3,