2 * This file is part of the coreboot project.
4 * Copyright (C) 2008 VIA Technologies, Inc.
5 * (Written by Aaron Lwe <aaron.lwe@gmail.com> for VIA)
6 * Copyright (C) 2007 Corey Osgood <corey.osgood@gmail.com>
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; either version 2 of the License, or
11 * (at your option) any later version.
13 * This program is distributed in the hope that it will be useful,
14 * but WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16 * GNU General Public License for more details.
18 * You should have received a copy of the GNU General Public License
19 * along with this program; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
23 #include <console/console.h>
26 #include <device/device.h>
27 #include <device/pci.h>
28 #include <device/pci_ids.h>
34 #include "northbridge.h"
37 static void memctrl_init(device_t dev)
41 u8 ranks, pagec, paged, pagee, pagef, shadowreg;
43 /* Set up the VGA framebuffer size. */
44 reg16 = (log2(CONFIG_VIDEO_MB) << 12) | (1 << 15);
45 pci_write_config16(dev, 0xa0, reg16);
47 /* Set up VGA timers. */
48 pci_write_config8(dev, 0xa2, 0x44);
50 for (ranks = 0x4b; ranks >= 0x48; ranks--) {
51 if (pci_read_config8(dev, ranks)) {
60 /* GMINT Misc. FrameBuffer rank */
61 pci_write_config16(dev, 0xb0, reg16);
63 pci_write_config8(dev, 0xb8, 0x08);
66 pagec = 0xff, paged = 0xff, pagee = 0xff, pagef = 0x30;
67 /* PAGE C, D, E are all read write enable */
68 pci_write_config8(dev, 0x80, pagec);
69 pci_write_config8(dev, 0x81, paged);
70 pci_write_config8(dev, 0x82, pagee);
71 /* PAGE F are read/writable */
72 shadowreg = pci_read_config8(dev, 0x83);
74 pci_write_config8(dev, 0x83, shadowreg);
76 vlink_dev = dev_find_device(PCI_VENDOR_ID_VIA,
77 PCI_DEVICE_ID_VIA_CN700_VLINK, 0);
79 pci_write_config8(vlink_dev, 0x61, pagec);
80 pci_write_config8(vlink_dev, 0x62, paged);
81 pci_write_config8(vlink_dev, 0x64, pagee);
83 shadowreg = pci_read_config8(vlink_dev, 0x63);
85 pci_write_config8(vlink_dev, 0x63, shadowreg);
89 static const struct device_operations memctrl_operations = {
90 .read_resources = cn700_noop,
94 static const struct pci_driver memctrl_driver __pci_driver = {
95 .ops = &memctrl_operations,
96 .vendor = PCI_VENDOR_ID_VIA,
97 .device = PCI_DEVICE_ID_VIA_CN700_MEMCTRL,
100 #if CONFIG_WRITE_HIGH_TABLES==1
101 /* maximum size of high tables in KB */
102 #define HIGH_TABLES_SIZE 64
103 extern uint64_t high_tables_base, high_tables_size;
106 static void pci_domain_set_resources(device_t dev)
108 /* The order is important to find the correct RAM size. */
109 static const u8 ramregs[] = { 0x43, 0x42, 0x41, 0x40 };
113 printk(BIOS_SPEW, "Entering cn700 pci_domain_set_resources.\n");
115 pci_tolm = find_pci_tolm(dev->link_list);
116 mc_dev = dev_find_device(PCI_VENDOR_ID_VIA,
117 PCI_DEVICE_ID_VIA_CN700_MEMCTRL, 0);
120 unsigned long tomk, tolmk;
121 unsigned char rambits;
125 * Once the register value is not zero, the RAM size is
126 * this register's value multiply 64 * 1024 * 1024.
128 for (rambits = 0, i = 0; i < ARRAY_SIZE(ramregs); i++) {
129 rambits = pci_read_config8(mc_dev, ramregs[i]);
134 tomk = rambits * 64 * 1024;
135 printk(BIOS_DEBUG, "tomk is 0x%lx\n", tomk);
136 /* Compute the Top Of Low Memory (TOLM), in Kb. */
137 tolmk = pci_tolm >> 10;
139 /* The PCI hole does does not overlap the memory. */
143 #if CONFIG_WRITE_HIGH_TABLES == 1
144 high_tables_base = (tolmk - CONFIG_VIDEO_MB * 1024 - HIGH_TABLES_SIZE) * 1024;
145 high_tables_size = HIGH_TABLES_SIZE * 1024;
146 printk(BIOS_DEBUG, "tom: %lx, high_tables_base: %llx, high_tables_size: %llx\n", tomk*1024, high_tables_base, high_tables_size);
149 /* Report the memory regions. */
151 /* TODO: Hole needed? */
152 ram_resource(dev, idx++, 0, 640); /* First 640k */
153 /* Leave a hole for VGA, 0xa0000 - 0xc0000 */
154 ram_resource(dev, idx++, 768,
155 (tolmk - 768 - CONFIG_VIDEO_MB * 1024));
157 assign_resources(dev->link_list);
160 static struct device_operations pci_domain_ops = {
161 .read_resources = pci_domain_read_resources,
162 .set_resources = pci_domain_set_resources,
163 .enable_resources = NULL,
165 .scan_bus = pci_domain_scan_bus,
168 static void cpu_bus_init(device_t dev)
170 initialize_cpus(dev->link_list);
173 static void cpu_bus_noop(device_t dev)
177 static struct device_operations cpu_bus_ops = {
178 .read_resources = cpu_bus_noop,
179 .set_resources = cpu_bus_noop,
180 .enable_resources = cpu_bus_noop,
181 .init = cpu_bus_init,
185 static void enable_dev(struct device *dev)
187 printk(BIOS_SPEW, "In cn700 enable_dev for device %s.\n", dev_path(dev));
189 /* Set the operations if it is a special bus type. */
190 if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
191 dev->ops = &pci_domain_ops;
193 } else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
194 dev->ops = &cpu_bus_ops;
198 struct chip_operations northbridge_via_cn700_ops = {
199 CHIP_NAME("VIA CN700 Northbridge")
200 .enable_dev = enable_dev,