Please bear with me - another rename checkin. This qualifies as trivial, no
[coreboot.git] / src / southbridge / via / k8t890 / k8t890_dram.c
1 /*
2  * This file is part of the coreboot 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_ids.h>
23 #include <console/console.h>
24 #include <cpu/x86/msr.h>
25 #include <cpu/amd/mtrr.h>
26
27 static void dram_enable(struct device *dev)
28 {
29         msr_t msr;
30         u16 reg;
31
32         /*
33          * Enable Lowest Interrupt arbitration for APIC, enable NB APIC
34          * decoding, MSI support, no SMRAM, compatible SMM.
35          */
36         pci_write_config8(dev, 0x86, 0x39);
37
38         /*
39          * We want to use the 0xC0000-0xEFFFF as RAM mark area as RW, even if
40          * memory is doing K8 the DMA from SB will fail if we have it wrong,
41          * AND even we have it here, we must later copy it to SB to make it work :/
42          */
43
44         /* For CC000-CFFFF, bits 7:6 (10 = REn, 01 = WEn) bits 1:0 for
45          * C0000-C3FFF etc.
46          */
47         pci_write_config8(dev, 0x80, 0xff);
48         /* For page D0000-DFFFF */
49         pci_write_config8(dev, 0x81, 0xff);
50         /* For page E0000-EFFFF */
51         pci_write_config8(dev, 0x82, 0xff);
52         pci_write_config8(dev, 0x83, 0x30);
53
54         msr = rdmsr(TOP_MEM);
55         reg = pci_read_config16(dev, 0x84);
56         reg &= 0xf;
57         pci_write_config16(dev, 0x84, (msr.lo >> 16) | reg);
58
59         reg = pci_read_config16(dev, 0x88);
60         reg &= 0xf800;
61
62         pci_write_config16(dev, 0x88, (msr.lo >> 24) | reg);
63 }
64
65 static const struct device_operations dram_ops = {
66         .read_resources         = pci_dev_read_resources,
67         .set_resources          = pci_dev_set_resources,
68         .enable_resources       = pci_dev_enable_resources,
69         .enable                 = dram_enable,
70         .ops_pci                = 0,
71 };
72
73 static const struct pci_driver northbridge_driver __pci_driver = {
74         .ops    = &dram_ops,
75         .vendor = PCI_VENDOR_ID_VIA,
76         .device = PCI_DEVICE_ID_VIA_K8T890CE_3,
77 };