This patch adds support for K8T890CE northbridge.
[coreboot.git] / src / southbridge / via / k8t890 / k8t890_dram.c
1 /*
2  * This file is part of the LinuxBIOS project.
3  *
4  * Copyright (C) 2007 Rudolf Marek <r.marek@assembler.cz>
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 v2 as published by
8  * the Free Software Foundation.
9  *
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.
14  *
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
18  */
19
20 #include <device/device.h>
21 #include <device/pci.h>
22 #include <device/pci_ops.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
28 static void dram_enable(struct device *dev)
29 {
30         msr_t msr;
31         u16 reg;
32
33         /*
34          * Enable Lowest Interrupt arbitration for APIC, enable NB APIC
35          * decoding, MSI support, no SMRAM, compatible SMM.
36          */
37         pci_write_config8(dev, 0x86, 0x39);
38
39         /*
40          * We want to use the 0xC0000-0xEFFFF as RAM mark area as RW, even if
41          * memory is doing K8 the DMA from SB will fail if we have it wrong,
42          * AND even we have it here, we must later copy it to SB to make it work :/
43          */
44
45         /* For CC000-CFFFF, bits 7:6 (10 = REn, 01 = WEn) bits 1:0 for
46          * C0000-C3FFF etc.
47          */
48         pci_write_config8(dev, 0x80, 0xff);
49         /* For page D0000-DFFFF */
50         pci_write_config8(dev, 0x81, 0xff);
51         /* For page E0000-EFFFF */
52         pci_write_config8(dev, 0x82, 0xff);
53         pci_write_config8(dev, 0x83, 0x30);
54
55         msr = rdmsr(TOP_MEM);
56         reg = pci_read_config16(dev, 0x84);
57         reg &= 0xf;
58         pci_write_config16(dev, 0x84, (msr.lo >> 16) | reg);
59
60         reg = pci_read_config16(dev, 0x88);
61         reg &= 0xf800;
62
63         pci_write_config16(dev, 0x88, (msr.lo >> 24) | reg);
64 }
65
66 static struct device_operations dram_ops = {
67         .read_resources = pci_dev_read_resources,
68         .set_resources = pci_dev_set_resources,
69         .enable_resources = pci_dev_enable_resources,
70         .enable = dram_enable,
71         .ops_pci = 0,
72 };
73
74 static struct pci_driver northbridge_driver __pci_driver = {
75         .ops = &dram_ops,
76         .vendor = PCI_VENDOR_ID_VIA,
77         .device = PCI_DEVICE_ID_VIA_K8T890CE_3,
78 };