2 * This file is part of the coreboot project.
4 * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License v2 as published by
8 * the Free Software Foundation.
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
20 #include <device/device.h>
21 #include <device/pci.h>
22 #include <device/pci_ids.h>
23 #include <console/console.h>
24 #include <cpu/x86/msr.h>
25 #include <cpu/amd/mtrr.h>
29 static void dram_enable(struct device *dev)
35 * Enable Lowest Interrupt arbitration for APIC, enable NB APIC
36 * decoding, MSI support, no SMRAM, compatible SMM.
38 pci_write_config8(dev, 0x86, 0x39);
41 * We want to use the 0xC0000-0xEFFFF as RAM mark area as RW, even if
42 * memory is doing K8 the DMA from SB will fail if we have it wrong,
43 * AND even we have it here, we must later copy it to SB to make it work :/
46 /* For CC000-CFFFF, bits 7:6 (10 = REn, 01 = WEn) bits 1:0 for
49 pci_write_config8(dev, 0x80, 0xff);
50 /* For page D0000-DFFFF */
51 pci_write_config8(dev, 0x81, 0xff);
52 /* For page E0000-EFFFF */
53 pci_write_config8(dev, 0x82, 0xff);
54 pci_write_config8(dev, 0x83, 0x30);
57 reg = pci_read_config16(dev, 0x84);
59 pci_write_config16(dev, 0x84, (msr.lo >> 16) | reg);
61 reg = pci_read_config16(dev, 0x88);
64 /* The Address Next to the Last Valid DRAM Address */
65 pci_write_config16(dev, 0x88, (msr.lo >> 24) | reg);
69 static void dram_enable_k8m890(struct device *dev)
73 /* enable VGA, so the bridges gets VGA_EN and resources are set */
74 pci_write_config8(dev, 0xa1, 0x80);
77 static struct resource *resmax;
79 static void get_memres(void *gp, struct device *dev, struct resource *res)
81 unsigned int *fbsize = (unsigned int *) gp;
82 uint64_t proposed_base = res->base + res->size - *fbsize;
84 printk_debug("get_memres: res->base=%llx res->size=%llx %d %d %d\n",
85 res->base, res->size, (res->size > *fbsize),
86 (!(proposed_base & (*fbsize - 1))),
87 (proposed_base < ((uint64_t) 0xffffffff)));
89 /* if we fit and also align OK, and must be below 4GB */
90 if ((res->size > *fbsize) && (!(proposed_base & (*fbsize - 1))) &&
91 (proposed_base < ((uint64_t) 0xffffffff) )) {
94 #if HAVE_HIGH_TABLES==1
95 /* in arch/i386/boot/tables.c */
96 extern uint64_t high_tables_base, high_tables_size;
98 if ((high_tables_base) && ((high_tables_base > proposed_base) &&
99 (high_tables_base < (res->base + res->size)))) {
100 high_tables_base = proposed_base - high_tables_size;
101 printk_debug("Moving the high_tables_base pointer to "
102 "new base %llx\n", high_tables_base);
108 static void dram_init_fb(struct device *dev)
111 * Enable the internal GFX bit 7 of reg 0xa1 plus in same reg:
112 * bits 6:4 X fbuffer size will be 2^(X+2) or 100 = 64MB, 101 = 128MB
113 * bits 3:0 BASE [31:28]
114 * reg 0xa0 bits 7:1 BASE [27:21] bit0 enable CPU access
117 uint64_t proposed_base;
118 unsigned int fbsize = (K8M890_FBSIZEMB * 1024 * 1024);
121 search_global_resources(
122 IORESOURCE_MEM | IORESOURCE_CACHEABLE, IORESOURCE_MEM | IORESOURCE_CACHEABLE,
123 get_memres, (void *) &fbsize);
125 /* no space for FB */
127 printk_err("VIA FB: no space for framebuffer in RAM\n");
131 proposed_base = resmax->base + resmax->size - fbsize;
132 resmax->size -= fbsize;
134 printk_debug("VIA FB proposed base: %llx\n", proposed_base);
136 /* Step 1: enable UMA but no FB */
137 pci_write_config8(dev, 0xa1, 0x80);
139 /* Step 2: enough is just the FB size, the CPU accessible address is not needed */
140 tmp = ((log2(K8M890_FBSIZEMB) - 2) << 4) | 0x80;
141 pci_write_config8(dev, 0xa1, tmp);
143 /* TODO K8 needs some UMA fine tuning too maybe call some generic routine here? */
146 static const struct device_operations dram_ops_t = {
147 .read_resources = pci_dev_read_resources,
148 .set_resources = pci_dev_set_resources,
149 .enable_resources = pci_dev_enable_resources,
150 .enable = dram_enable,
154 static const struct device_operations dram_ops_m = {
155 .read_resources = pci_dev_read_resources,
156 .set_resources = pci_dev_set_resources,
157 .enable_resources = pci_dev_enable_resources,
158 .enable = dram_enable_k8m890,
159 .init = dram_init_fb,
163 static const struct pci_driver northbridge_driver_t __pci_driver = {
165 .vendor = PCI_VENDOR_ID_VIA,
166 .device = PCI_DEVICE_ID_VIA_K8T890CE_3,
169 static const struct pci_driver northbridge_driver_m __pci_driver = {
171 .vendor = PCI_VENDOR_ID_VIA,
172 .device = PCI_DEVICE_ID_VIA_K8M890CE_3,