summaryrefslogtreecommitdiff
path: root/src/northbridge
diff options
context:
space:
mode:
authorJoseph Smith <joe@smittys.pointclark.net>2008-03-09 13:24:46 +0000
committerUwe Hermann <uwe@hermann-uwe.de>2008-03-09 13:24:46 +0000
commit6a1dc86005bb14c14d1b0f8c69f554912a2d3199 (patch)
treeadac3f9775da67fb5cb6f508272e691823a7b397 /src/northbridge
parentc4f536568833fb7b0052a2eda63dd39f05885978 (diff)
Initial support for the Intel 82830 northbridge and RCA RM4100 board.
Signed-off-by: Joseph Smith <joe@smittys.pointclark.net> Acked-by: Uwe Hermann <uwe@hermann-uwe.de> git-svn-id: svn://svn.coreboot.org/coreboot/trunk@3129 2b7e53f0-3cfb-0310-b3e9-8179ed1497e1
Diffstat (limited to 'src/northbridge')
-rw-r--r--src/northbridge/intel/i82830/Config.lb22
-rw-r--r--src/northbridge/intel/i82830/chip.h24
-rw-r--r--src/northbridge/intel/i82830/debug.c66
-rw-r--r--src/northbridge/intel/i82830/i82830.h52
-rw-r--r--src/northbridge/intel/i82830/northbridge.c197
-rw-r--r--src/northbridge/intel/i82830/raminit.c508
-rw-r--r--src/northbridge/intel/i82830/raminit.h32
7 files changed, 901 insertions, 0 deletions
diff --git a/src/northbridge/intel/i82830/Config.lb b/src/northbridge/intel/i82830/Config.lb
new file mode 100644
index 0000000000..460bd87ed0
--- /dev/null
+++ b/src/northbridge/intel/i82830/Config.lb
@@ -0,0 +1,22 @@
+##
+## This file is part of the coreboot project.
+##
+## Copyright (C) 2008 Joseph Smith <joe@smittys.pointclark.net>
+##
+## This program is free software; you can redistribute it and/or modify
+## it under the terms of the GNU General Public License as published by
+## the Free Software Foundation; either version 2 of the License, or
+## (at your option) any later version.
+##
+## This program is distributed in the hope that it will be useful,
+## but WITHOUT ANY WARRANTY; without even the implied warranty of
+## MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+## GNU General Public License for more details.
+##
+## You should have received a copy of the GNU General Public License
+## along with this program; if not, write to the Free Software
+## Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+##
+
+config chip.h
+object northbridge.o
diff --git a/src/northbridge/intel/i82830/chip.h b/src/northbridge/intel/i82830/chip.h
new file mode 100644
index 0000000000..af398f5e23
--- /dev/null
+++ b/src/northbridge/intel/i82830/chip.h
@@ -0,0 +1,24 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2008 Joseph Smith <joe@smittys.pointclark.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+struct northbridge_intel_i82830_config {
+};
+
+extern struct chip_operations northbridge_intel_i82830_ops;
diff --git a/src/northbridge/intel/i82830/debug.c b/src/northbridge/intel/i82830/debug.c
new file mode 100644
index 0000000000..7eeabdef47
--- /dev/null
+++ b/src/northbridge/intel/i82830/debug.c
@@ -0,0 +1,66 @@
+
+static void print_debug_pci_dev(unsigned dev)
+{
+ print_debug("PCI: ");
+ print_debug_hex8((dev >> 16) & 0xff);
+ print_debug_char(':');
+ print_debug_hex8((dev >> 11) & 0x1f);
+ print_debug_char('.');
+ print_debug_hex8((dev >> 8) & 7);
+}
+
+static void print_pci_devices(void)
+{
+ device_t dev;
+ for(dev = PCI_DEV(0, 0, 0);
+ dev <= PCI_DEV(0, 0x1f, 0x7);
+ dev += PCI_DEV(0,0,1)) {
+ uint32_t id;
+ id = pci_read_config32(dev, PCI_VENDOR_ID);
+ if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
+ (((id >> 16) & 0xffff) == 0xffff) ||
+ (((id >> 16) & 0xffff) == 0x0000)) {
+ continue;
+ }
+ print_debug_pci_dev(dev);
+ print_debug("\r\n");
+ }
+}
+
+static void dump_pci_device(unsigned dev)
+{
+ int i;
+ print_debug_pci_dev(dev);
+ print_debug("\r\n");
+
+ for(i = 0; i <= 255; i++) {
+ unsigned char val;
+ if ((i & 0x0f) == 0) {
+ print_debug_hex8(i);
+ print_debug_char(':');
+ }
+ val = pci_read_config8(dev, i);
+ print_debug_char(' ');
+ print_debug_hex8(val);
+ if ((i & 0x0f) == 0x0f) {
+ print_debug("\r\n");
+ }
+ }
+}
+
+static void dump_pci_devices(void)
+{
+ device_t dev;
+ for(dev = PCI_DEV(0, 0, 0);
+ dev <= PCI_DEV(0, 0x1f, 0x7);
+ dev += PCI_DEV(0,0,1)) {
+ uint32_t id;
+ id = pci_read_config32(dev, PCI_VENDOR_ID);
+ if (((id & 0xffff) == 0x0000) || ((id & 0xffff) == 0xffff) ||
+ (((id >> 16) & 0xffff) == 0xffff) ||
+ (((id >> 16) & 0xffff) == 0x0000)) {
+ continue;
+ }
+ dump_pci_device(dev);
+ }
+}
diff --git a/src/northbridge/intel/i82830/i82830.h b/src/northbridge/intel/i82830/i82830.h
new file mode 100644
index 0000000000..c4e0b140fb
--- /dev/null
+++ b/src/northbridge/intel/i82830/i82830.h
@@ -0,0 +1,52 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2008 Joseph Smith <joe@smittys.pointclark.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#define RRBAR 0x48 /* Register Range Base Address (0x00000000) */
+#define GCC0 0x50 /* GMCH Control #0 (0xa072) */
+#define GCC1 0x52 /* GMCH Control #1 (0x0000) */
+#define FDHC 0x58 /* Fixed DRAM Hole Control (0x00) */
+#define PAM0 0x59 /* Programable Attribute Map #0 (0x00) */
+#define PAM1 0x5a /* Programable Attribute Map #1 (0x00) */
+#define PAM2 0x5b /* Programable Attribute Map #2 (0x00) */
+#define PAM3 0x5c /* Programable Attribute Map #3 (0x00) */
+#define PAM4 0x5d /* Programable Attribute Map #4 (0x00) */
+#define PAM5 0x5e /* Programable Attribute Map #5 (0x00) */
+#define PAM6 0x5f /* Programable Attribute Map #6 (0x00) */
+#define DRB 0x60 /* DRAM Row Boundary #0 (0x00) */
+#define DRB1 0x61 /* DRAM Row Boundary #1 (0x00) */
+#define DRB2 0x62 /* DRAM Row Boundary #2 (0x00) */
+#define DRB3 0x63 /* DRAM Row Boundary #3 (0x00) */
+#define DRA 0x70 /* DRAM Row Attribute #0 (0xff) */
+#define DRA1 0x71 /* DRAM Row Attribute #1 (0xff) */
+#define DRT 0x78 /* DRAM Timing (0x00000010) */
+#define DRC 0x7c /* DRAM Controller Mode #0 (0x00000000) */
+#define DRC1 0x7d /* DRAM Controller Mode #1 (0x00000000) */
+#define DRC2 0x7e /* DRAM Controller Mode #2 (0x00000000) */
+#define DRC3 0x7f /* DRAM Controller Mode #3 (0x00000000) */
+#define DTC 0x8c /* DRAM Throttling Control (0x00000000) */
+#define SMRAM 0x90 /* System Management RAM Control (0x02) */
+#define ESMRAMC 0x91 /* Extended System Management RAM Control Reg. (0x38) */
+#define ERRSTS 0x92 /* Error Status (0x0000) */
+#define ERRCMD 0x94 /* Error Command (0x0000) */
+#define BUFF_SC 0xec /* System Memory Buffer Strength Control (0x00000000) */
+#define APBASE 0x10 /* Aperture Base Configuration (0x00000008) */
+#define APSIZE 0xb4 /* Apterture Size (0x00) */
+#define ATTBASE 0xb8 /* Aperture Translation Table Base (0x00000000) */
+
diff --git a/src/northbridge/intel/i82830/northbridge.c b/src/northbridge/intel/i82830/northbridge.c
new file mode 100644
index 0000000000..bd2690a359
--- /dev/null
+++ b/src/northbridge/intel/i82830/northbridge.c
@@ -0,0 +1,197 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2008 Joseph Smith <joe@smittys.pointclark.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#include <console/console.h>
+#include <arch/io.h>
+#include <stdint.h>
+#include <device/device.h>
+#include <device/pci.h>
+#include <device/pci_ids.h>
+#include <stdlib.h>
+#include <string.h>
+#include <bitops.h>
+#include "chip.h"
+#include "i82830.h"
+
+static void northbridge_init(device_t dev)
+{
+ printk_spew("Northbridge init\n");
+}
+
+static struct device_operations northbridge_operations = {
+ .read_resources = pci_dev_read_resources,
+ .set_resources = pci_dev_set_resources,
+ .enable_resources = pci_dev_enable_resources,
+ .init = northbridge_init,
+ .enable = 0,
+ .ops_pci = 0,
+};
+
+static struct pci_driver northbridge_driver __pci_driver = {
+ .ops = &northbridge_operations,
+ .vendor = PCI_VENDOR_ID_INTEL,
+ .device = 0x3575,
+};
+
+#define BRIDGE_IO_MASK (IORESOURCE_IO | IORESOURCE_MEM)
+
+static void pci_domain_read_resources(device_t dev)
+{
+ struct resource *resource;
+
+ /* Initialize the system wide I/O space constraints. */
+ resource = new_resource(dev, IOINDEX_SUBTRACTIVE(0, 0));
+ resource->limit = 0xffffUL;
+ resource->flags =
+ IORESOURCE_IO | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
+
+ /* Initialize the system wide memory resources constraints. */
+ resource = new_resource(dev, IOINDEX_SUBTRACTIVE(1, 0));
+ resource->limit = 0xffffffffULL;
+ resource->flags =
+ IORESOURCE_MEM | IORESOURCE_SUBTRACTIVE | IORESOURCE_ASSIGNED;
+}
+
+static void ram_resource(device_t dev, unsigned long index,
+ unsigned long basek, unsigned long sizek)
+{
+ struct resource *resource;
+
+ if (!sizek)
+ return;
+ resource = new_resource(dev, index);
+ resource->base = ((resource_t) basek) << 10;
+ resource->size = ((resource_t) sizek) << 10;
+ resource->flags = IORESOURCE_MEM | IORESOURCE_CACHEABLE |
+ IORESOURCE_FIXED | IORESOURCE_STORED | IORESOURCE_ASSIGNED;
+}
+
+static void tolm_test(void *gp, struct device *dev, struct resource *new)
+{
+ struct resource **best_p = gp;
+ struct resource *best;
+ best = *best_p;
+ if (!best || (best->base > new->base))
+ best = new;
+ *best_p = best;
+}
+
+static uint32_t find_pci_tolm(struct bus *bus)
+{
+ struct resource *min;
+ uint32_t tolm;
+ min = 0;
+ search_bus_resources(bus, IORESOURCE_MEM, IORESOURCE_MEM, tolm_test,
+ &min);
+ tolm = 0xffffffffUL;
+ if (min && tolm > min->base)
+ tolm = min->base;
+ return tolm;
+}
+
+static void pci_domain_set_resources(device_t dev)
+{
+ device_t mc_dev;
+ uint32_t pci_tolm;
+ int igd_memory = 0;
+
+ pci_tolm = find_pci_tolm(&dev->link[0]);
+ mc_dev = dev->link[0].children;
+ if (mc_dev) {
+ unsigned long tomk, tolmk;
+ int idx;
+
+ if (CONFIG_VIDEO_MB == 512) {
+ igd_memory = (CONFIG_VIDEO_MB);
+ } else {
+ igd_memory = (CONFIG_VIDEO_MB * 1024);
+ }
+
+ /* Get the value of the highest DRB. This tells the end of
+ * the physical memory. The units are ticks of 32MB
+ * i.e. 1 means 32MB.
+ */
+ tomk = ((unsigned long)pci_read_config8(mc_dev, DRB + 3)) << 15;
+ tomk -= igd_memory;
+ printk_debug("Setting RAM size to %d\n", tomk);
+
+ /* Compute the top of low memory. */
+ tolmk = pci_tolm >> 10;
+ if (tolmk >= tomk) {
+ /* The PCI hole does does not overlap the memory. */
+ tolmk = tomk;
+ }
+
+ /* Report the memory regions. */
+ idx = 10;
+ ram_resource(dev, idx++, 0, 640);
+ ram_resource(dev, idx++, 1024, tolmk - 1024);
+ }
+ assign_resources(&dev->link[0]);
+}
+
+static unsigned int pci_domain_scan_bus(device_t dev, unsigned int max)
+{
+ max = pci_scan_bus(&dev->link[0], PCI_DEVFN(0, 0), 0xff, max);
+ return max;
+}
+
+static struct device_operations pci_domain_ops = {
+ .read_resources = pci_domain_read_resources,
+ .set_resources = pci_domain_set_resources,
+ .enable_resources = enable_childrens_resources,
+ .init = 0,
+ .scan_bus = pci_domain_scan_bus,
+};
+
+static void cpu_bus_init(device_t dev)
+{
+ initialize_cpus(&dev->link[0]);
+}
+
+static void cpu_bus_noop(device_t dev)
+{
+}
+
+static struct device_operations cpu_bus_ops = {
+ .read_resources = cpu_bus_noop,
+ .set_resources = cpu_bus_noop,
+ .enable_resources = cpu_bus_noop,
+ .init = cpu_bus_init,
+ .scan_bus = 0,
+};
+
+static void enable_dev(struct device *dev)
+{
+ struct device_path;
+
+ /* Set the operations if it is a special bus type. */
+ if (dev->path.type == DEVICE_PATH_PCI_DOMAIN) {
+ dev->ops = &pci_domain_ops;
+ pci_set_method(dev);
+ } else if (dev->path.type == DEVICE_PATH_APIC_CLUSTER) {
+ dev->ops = &cpu_bus_ops;
+ }
+}
+
+struct chip_operations northbridge_intel_i82830_ops = {
+ CHIP_NAME("Intel 82830 Northbridge")
+ .enable_dev = enable_dev,
+};
diff --git a/src/northbridge/intel/i82830/raminit.c b/src/northbridge/intel/i82830/raminit.c
new file mode 100644
index 0000000000..1deb2572c8
--- /dev/null
+++ b/src/northbridge/intel/i82830/raminit.c
@@ -0,0 +1,508 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2008 Joseph Smith <joe@smittys.pointclark.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ */
+
+#include <spd.h>
+#include <sdram_mode.h>
+#include <delay.h>
+#include "debug.c"
+#include "i82830.h"
+
+/*-----------------------------------------------------------------------------
+Macros and definitions.
+-----------------------------------------------------------------------------*/
+
+/* Uncomment this to enable debugging output. */
+/* #define DEBUG_RAM_SETUP 1 */
+
+/* Debugging macros. */
+#if defined(DEBUG_RAM_SETUP)
+#define PRINT_DEBUG(x) print_debug(x)
+#define PRINT_DEBUG_HEX8(x) print_debug_hex8(x)
+#define PRINT_DEBUG_HEX16(x) print_debug_hex16(x)
+#define PRINT_DEBUG_HEX32(x) print_debug_hex32(x)
+#define DUMPNORTH() dump_pci_device(PCI_DEV(0, 0, 0))
+#else
+#define PRINT_DEBUG(x)
+#define PRINT_DEBUG_HEX8(x)
+#define PRINT_DEBUG_HEX16(x)
+#define PRINT_DEBUG_HEX32(x)
+#define DUMPNORTH()
+#endif
+
+/* DRC[10:8] - Refresh Mode Select (RMS).
+ * 0x0 for Refresh Disabled (Self Refresh)
+ * 0x1 for Refresh interval 15.6 us for 133MHz
+ * 0x2 for Refresh interval 7.8 us for 133MHz
+ * 0x7 /* Refresh interval 128 Clocks. (Fast Refresh Mode)
+ */
+#define RAM_COMMAND_REFRESH 0x2
+
+/* DRC[6:4] - SDRAM Mode Select (SMS). */
+#define RAM_COMMAND_SELF_REFRESH 0x0
+#define RAM_COMMAND_NOP 0x1
+#define RAM_COMMAND_PRECHARGE 0x2
+#define RAM_COMMAND_MRS 0x3
+#define RAM_COMMAND_CBR 0x6
+#define RAM_COMMAND_NORMAL 0x7
+
+/* DRC[29] - Initialization Complete (IC). */
+#define RAM_COMMAND_IC 0x1
+
+/*-----------------------------------------------------------------------------
+SDRAM configuration functions.
+-----------------------------------------------------------------------------*/
+
+/* Send the specified RAM command to all DIMMs. */
+
+static void do_ram_command(const struct mem_controller *ctrl, uint32_t command,
+ uint32_t addr_offset)
+{
+ int i;
+ uint8_t reg8, reg8_2 = 0;
+ uint32_t reg32;
+
+ /* Configure the RAM command. */
+ reg32 = pci_read_config32(ctrl->d0, DRC);
+ /* Clear bits 29, 10-8, 6-4. */
+ reg32 &= 0xdffff88f;
+ reg32 |= command << 4;
+ /* If RAM_COMMAND_NORMAL set the refresh mode and IC bit. */
+ if (command == RAM_COMMAND_NORMAL)
+ reg32 |= ((RAM_COMMAND_REFRESH << 8) | (RAM_COMMAND_IC << 29));
+ pci_write_config32(ctrl->d0, DRC, reg32);
+
+ /* RAM_COMMAND_NORMAL affects only the memory controller and
+ doesn't need to be "sent" to the DIMMs. */
+ /* if (command == RAM_COMMAND_NORMAL) return; */
+
+ PRINT_DEBUG(" Sending RAM command 0x");
+ PRINT_DEBUG_HEX32(reg32);
+ PRINT_DEBUG(" to 0x");
+ PRINT_DEBUG_HEX32(0 + addr_offset);
+ PRINT_DEBUG("\r\n");
+
+ /* NOTE: Dual-sided ready. */
+ read32(0 + addr_offset);
+ for (i = 0; i < 4; i++) {
+ reg8 = pci_read_config8(ctrl->d0, DRB + i);
+ if (reg8 != reg8_2)
+ read32(reg8 * 32 * 1024 * 1024);
+ reg8_2 = reg8;
+ }
+}
+
+/*-----------------------------------------------------------------------------
+DIMM-independant configuration functions.
+-----------------------------------------------------------------------------*/
+
+struct dimm_size {
+ unsigned long side1;
+ unsigned long side2;
+};
+
+static struct dimm_size spd_get_dimm_size(unsigned device)
+{
+ struct dimm_size sz;
+ int i, module_density, dimm_banks;
+ sz.side1 = 0;
+ module_density = spd_read_byte(device, 31);
+ dimm_banks = spd_read_byte(device, 5);
+
+ /* Find the size of side1. */
+ /* Find the larger value. The larger value is always side1. */
+ for (i = 512; i >= 0; i >>= 1) {
+ if ((module_density & i) == i) {
+ sz.side1 = i;
+ break;
+ }
+ }
+
+ /* Set to 0 in case it's single sided. */
+ sz.side2 = 0;
+
+ /* Test if it's a dual-sided DIMM. */
+ if (dimm_banks > 1) {
+ /* Test to see if there's a second value, if so it's asymmetrical. */
+ if (module_density != i) {
+ /* Find the second value, picking up where we left off. */
+ /* i >>= 1 done initially to make sure we don't get the same value again. */
+ for (i >>= 1; i >= 0; i >>= 1) {
+ if (module_density == (sz.side1 | i)) {
+ sz.side2 = i;
+ break;
+ }
+ }
+ /* If not, it's symmetrical */
+ } else {
+ sz.side2 = sz.side1;
+ }
+ }
+
+ /* SPD byte 31 is the memory size divided by 4 so we
+ * need to muliply by 4 to get the total size.
+ */
+ sz.side1 *= 4;
+ sz.side2 *= 4;
+ return sz;
+}
+
+static void spd_set_dram_size(const struct mem_controller *ctrl)
+{
+ int i, value, drb1, drb2;
+
+ for (i = 0; i < DIMM_SOCKETS; i++) {
+ struct dimm_size sz;
+ unsigned device;
+ device = ctrl->channel0[i];
+ drb1 = 0;
+ drb2 = 0;
+
+ /* First check if a DIMM is actually present. */
+ if (spd_read_byte(device, 2) == 0x4) {
+ print_debug("Found DIMM in slot ");
+ print_debug_hex8(i);
+ print_debug("\r\n");
+
+ sz = spd_get_dimm_size(device);
+
+ /* WISHLIST: would be nice to display it as decimal? */
+ print_debug("DIMM is 0x");
+ print_debug_hex16(sz.side1);
+ print_debug(" on side 1\r\n");
+ print_debug("DIMM is 0x");
+ print_debug_hex16(sz.side2);
+ print_debug(" on side 2\r\n");
+
+ /* Test for PC133 (i82830 only supports PC133) */
+ /* PC133 SPD9 - cycle time is always 75 */
+ if (spd_read_byte(device, 9) != 0x75) {
+ print_err("SPD9 DIMM Is Not PC133 Compatable\r\n");
+ die("HALT\r\n");
+ }
+ /* PC133 SPD10 - access time is always 54 */
+ if (spd_read_byte(device, 10) != 0x54) {
+ print_err("SPD10 DIMM Is Not PC133 Compatable\r\n");
+ die("HALT\r\n");
+ }
+
+ /* The i82830 only supports a symmetrical dual-sided dimms
+ * and can't handle DIMMs smaller than 32MB per
+ * side or larger than 256MB per side.
+ */
+ if ((sz.side2 != 0) && (sz.side1 != sz.side2)) {
+ print_err("This northbridge only supports\r\n");
+ print_err("symmetrical dual-sided DIMMs\r\n");
+ print_err("booting as a single-sided DIMM\r\n");
+ sz.side2 = 0;
+ }
+ if ((sz.side1 < 32)) {
+ print_err("DIMMs smaller than 32MB per side\r\n");
+ print_err("are not supported on this northbridge\r\n");
+ die("HALT\r\n");
+ }
+
+ if ((sz.side1 > 256)) {
+ print_err
+ ("DIMMs larger than 256MB per side\r\n");
+ print_err
+ ("are not supported on this northbridge\r\n");
+ die("HALT\r\n");
+ }
+
+ /* We need to divide size by 32 to set up the
+ * DRB registers.
+ */
+ if (sz.side1)
+ drb1 = sz.side1 / 32;
+ if (sz.side2)
+ drb2 = sz.side2 / 32;
+ } else {
+ PRINT_DEBUG("No DIMM found in slot ");
+ PRINT_DEBUG_HEX8(i);
+ PRINT_DEBUG("\r\n");
+
+ /* If there's no DIMM in the slot, set value to 0. */
+ drb1 = 0;
+ drb2 = 0;
+ }
+ /* Set the value for DRAM Row Boundary Registers */
+ if (i == 0) {
+ pci_write_config8(ctrl->d0, DRB, drb1);
+ pci_write_config8(ctrl->d0, DRB + 1, drb1 + drb2);
+ PRINT_DEBUG("DRB 0x");
+ PRINT_DEBUG_HEX8(DRB);
+ PRINT_DEBUG(" has been set to 0x");
+ PRINT_DEBUG_HEX8(drb1);
+ PRINT_DEBUG("\r\n");
+ PRINT_DEBUG("DRB1 0x");
+ PRINT_DEBUG_HEX8(DRB + 1);
+ PRINT_DEBUG(" has been set to 0x");
+ PRINT_DEBUG_HEX8(drb1 + drb2);
+ PRINT_DEBUG("\r\n");
+ } else if (i == 1) {
+ value = pci_read_config8(ctrl->d0, DRB + 1);
+ pci_write_config8(ctrl->d0, DRB + 2, value + drb1);
+ pci_write_config8(ctrl->d0, DRB + 3,
+ value + drb1 + drb2);
+ PRINT_DEBUG("DRB2 0x");
+ PRINT_DEBUG_HEX8(DRB + 2);
+ PRINT_DEBUG(" has been set to 0x");
+ PRINT_DEBUG_HEX8(value + drb1);
+ PRINT_DEBUG("\r\n");
+ PRINT_DEBUG("DRB3 0x");
+ PRINT_DEBUG_HEX8(DRB + 3);
+ PRINT_DEBUG(" has been set to 0x");
+ PRINT_DEBUG_HEX8(value + drb1 + drb2);
+ PRINT_DEBUG("\r\n");
+
+ /* We need to set the highest DRB value to 0x64 and 0x65.
+ * These are supposed to be "Reserved" but memory will
+ * not initialize properly if we don't.
+ */
+ value = pci_read_config8(ctrl->d0, DRB + 3);
+ pci_write_config8(ctrl->d0, DRB + 4, value);
+ pci_write_config8(ctrl->d0, DRB + 5, value);
+ }
+ }
+}
+
+static void set_dram_row_attributes(const struct mem_controller *ctrl)
+{
+ int i, dra, col, width, value;
+
+ for (i = 0; i < DIMM_SOCKETS; i++) {
+ unsigned device;
+ device = ctrl->channel0[i];
+
+ /* First check if a DIMM is actually present. */
+ if (spd_read_byte(device, 2) == 0x4) {
+ print_debug("Found DIMM in slot ");
+ print_debug_hex8(i);
+ print_debug(", setting DRA...\r\n");
+
+ dra = 0x00;
+
+ /* columns */
+ col = spd_read_byte(device, 4);
+
+ /* data width */
+ width = spd_read_byte(device, 6);
+
+ /* calculate page size in bits */
+ value = ((1 << col) * width);
+
+ /* convert to Kilobytes */
+ dra = ((value / 8) >> 10);
+
+ /* # of banks of DIMM (single or double sided) */
+ value = spd_read_byte(device, 5);
+
+ if (value == 1) {
+ switch (dra) {
+ case 2: /* 2KB */
+ dra = 0xF0;
+ break;
+ case 4: /* 4KB */
+ dra = 0xF1;
+ break;
+ case 8: /* 8KB */
+ dra = 0xF2;
+ break;
+ case 16: /* 16KB */
+ dra = 0xF3;
+ break;
+ default:
+ print_err("Page size not supported\r\n");
+ die("HALT\r\n");
+ }
+ } else if (value == 2) {
+ switch (dra) {
+ case 2: /* 2KB */
+ dra = 0x00;
+ break;
+ case 4: /* 4KB */
+ dra = 0x11;
+ break;
+ case 8: /* 8KB */
+ dra = 0x22;
+ break;
+ case 16: /* 16KB */
+ dra = 0x33;
+ break;
+ default:
+ print_err("Page size not supported\r\n");
+ die("HALT\r\n");
+ }
+ } else {
+ print_err("# of banks of DIMM not supported\r\n");
+ die("HALT\r\n");
+ }
+
+ } else {
+ PRINT_DEBUG("No DIMM found in slot ");
+ PRINT_DEBUG_HEX8(i);
+ PRINT_DEBUG(", setting DRA to 0xFF\r\n");
+
+ /* If there's no DIMM in the slot, set dra value to 0xFF. */
+ dra = 0xFF;
+ }
+
+ /* Set the value for DRAM Row Attribute Registers */
+ pci_write_config8(ctrl->d0, DRA + i, dra);
+ PRINT_DEBUG("DRA 0x");
+ PRINT_DEBUG_HEX8(DRA + i);
+ PRINT_DEBUG(" has been set to 0x");
+ PRINT_DEBUG_HEX8(dra);
+ PRINT_DEBUG("\r\n");
+ }
+}
+
+static void set_dram_timing(const struct mem_controller *ctrl)
+{
+ /* Set the value for DRAM Timing Register */
+ /* TODO: Configure the value according to SPD values. */
+ pci_write_config32(ctrl->d0, DRT, 0x00000010);
+}
+
+static void set_dram_buffer_strength(const struct mem_controller *ctrl)
+{
+ /* TODO: This needs to be set according to the DRAM tech
+ * (x8, x16, or x32). Argh, Intel provides no docs on this!
+ * Currently, it needs to be pulled from the output of
+ * lspci -xxx Rx92
+ */
+
+ /* Set the value for System Memory Buffer Strength Control Registers */
+ pci_write_config32(ctrl->d0, BUFF_SC, 0xFC9B491B);
+}
+
+/*-----------------------------------------------------------------------------
+Public interface.
+-----------------------------------------------------------------------------*/
+
+static void sdram_set_registers(const struct mem_controller *ctrl)
+{
+ uint16_t value;
+ int igd_memory = 0;
+
+ PRINT_DEBUG("Setting initial registers....\r\n");
+
+ /* Set the value for GMCH Control Register #0 */
+ pci_write_config16(ctrl->d0, GCC0, 0xA072);
+
+ /* Set the value for GMCH Control Register #1 */
+ switch (CONFIG_VIDEO_MB) {
+ case 512: /* 512K of memory */
+ igd_memory = 0x2;
+ break;
+ case 1: /* 1M of memory */
+ igd_memory = 0x3;
+ break;
+ case 8: /* 8M of memory */
+ igd_memory = 0x4;
+ break;
+ default: /* No memory */
+ pci_write_config16(ctrl->d0, GCC1, 0x0002);
+ igd_memory = 0x0;
+ }
+
+ value = pci_read_config16(ctrl->d0, GCC1);
+ value |= igd_memory << 4;
+ pci_write_config16(ctrl->d0, GCC1, value);
+
+ /* Set the value for Aperture Base Configuration Register */
+ pci_write_config32(ctrl->d0, APBASE, 0x00000008);
+
+ /* Set the value for Register Range Base Address Register */
+ pci_write_config32(ctrl->d0, RRBAR, 0x00000000);
+
+ /* Set the value for Fixed DRAM Hole Control Register */
+ pci_write_config8(ctrl->d0, FDHC, 0x00);
+
+ /* Set the value for Programable Attribute Map Registers
+ * Ideally, this should be R/W for as many ranges as possible.
+ */
+ pci_write_config8(ctrl->d0, PAM0, 0x30);
+ pci_write_config8(ctrl->d0, PAM1, 0x33);
+ pci_write_config8(ctrl->d0, PAM2, 0x33);
+ pci_write_config8(ctrl->d0, PAM3, 0x33);
+ pci_write_config8(ctrl->d0, PAM4, 0x33);
+ pci_write_config8(ctrl->d0, PAM5, 0x33);
+ pci_write_config8(ctrl->d0, PAM6, 0x33);
+
+ /* Set the value for DRAM Throttling Control Register */
+ pci_write_config32(ctrl->d0, DTC, 0x00000000);
+
+ /* Set the value for System Management RAM Control Register */
+ pci_write_config8(ctrl->d0, SMRAM, 0x02);
+
+ /* Set the value for Extended System Management RAM Control Register */
+ pci_write_config8(ctrl->d0, ESMRAMC, 0x38);
+
+ PRINT_DEBUG("Initial registers have been set.\r\n");
+}
+
+static void sdram_set_spd_registers(const struct mem_controller *ctrl)
+{
+ spd_set_dram_size(ctrl);
+ set_dram_row_attributes(ctrl);
+ set_dram_timing(ctrl);
+ set_dram_buffer_strength(ctrl);
+}
+
+static void sdram_enable(int controllers, const struct mem_controller *ctrl)
+{
+ int i;
+
+ /* 0. Wait until power/voltages and clocks are stable (200us). */
+ udelay(200);
+
+ /* 1. Apply NOP. */
+ PRINT_DEBUG("RAM Enable 1: Apply NOP\r\n");
+ do_ram_command(ctrl, RAM_COMMAND_NOP, 0);
+ udelay(200);
+
+ /* 2. Precharge all. Wait tRP. */
+ PRINT_DEBUG("RAM Enable 2: Precharge all\r\n");
+ do_ram_command(ctrl, RAM_COMMAND_PRECHARGE, 0);
+ udelay(1);
+
+ /* 3. Perform 8 refresh cycles. Wait tRC each time. */
+ PRINT_DEBUG("RAM Enable 3: CBR\r\n");
+ for (i = 0; i < 8; i++) {
+ do_ram_command(ctrl, RAM_COMMAND_CBR, 0);
+ udelay(1);
+ }
+
+ /* 4. Mode register set. Wait two memory cycles. */
+ /* TODO: Set offset according to DRT values */
+ PRINT_DEBUG("RAM Enable 4: Mode register set\r\n");
+ do_ram_command(ctrl, RAM_COMMAND_MRS, 0x1d0);
+ udelay(2);
+
+ /* 5. Normal operation (enables refresh) */
+ PRINT_DEBUG("RAM Enable 5: Normal operation\r\n");
+ do_ram_command(ctrl, RAM_COMMAND_NORMAL, 0);
+ udelay(1);
+
+ PRINT_DEBUG("Northbridge following SDRAM init:\r\n");
+ DUMPNORTH();
+}
diff --git a/src/northbridge/intel/i82830/raminit.h b/src/northbridge/intel/i82830/raminit.h
new file mode 100644
index 0000000000..707d38b611
--- /dev/null
+++ b/src/northbridge/intel/i82830/raminit.h
@@ -0,0 +1,32 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2008 Joseph Smith <joe@smittys.pointclark.net>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+#ifndef NORTHBRIDGE_INTEL_I82830_RAMINIT_H
+#define NORTHBRIDGE_INTEL_I82830_RAMINIT_H
+
+/* The 82830 supports max. 2 dual-sided SO-DIMMs. */
+#define DIMM_SOCKETS 2
+
+struct mem_controller {
+ device_t d0;
+ uint16_t channel0[DIMM_SOCKETS];
+};
+
+#endif /* NORTHBRIDGE_INTEL_I82830_RAMINIT_H */