[coreboot-gerrit] Patch set updated for coreboot: northbridge/intel/x4x: Initial Intel 4-series northbridge support

Damien Zammit (damien@zamaudio.com) gerrit at coreboot.org
Mon Dec 14 12:58:43 CET 2015


Damien Zammit (damien at zamaudio.com) just uploaded a new patch set to gerrit, which you can find at https://review.coreboot.org/11305

-gerrit

commit 9d8d28725a48752b6645898ff68e74a1059be524
Author: Damien Zammit <damien at zamaudio.com>
Date:   Wed Aug 19 15:16:59 2015 +1000

    northbridge/intel/x4x: Initial Intel 4-series northbridge support
    
    Boots to console on Gigabyte GA-G41M-ES2L
    Planned to support all Eaglelake chipsets
    
    Ram initialization not included in this patch
    
    Change-Id: I5262f73fd03d5e5c12e9f11d027bdfbbf0ddde82
    Signed-off-by: Damien Zammit <damien at zamaudio.com>
---
 src/Kconfig                                   |   1 +
 src/northbridge/intel/x4x/Kconfig             |  41 ++
 src/northbridge/intel/x4x/Makefile.inc        |  32 ++
 src/northbridge/intel/x4x/acpi.c              | 110 ++++++
 src/northbridge/intel/x4x/acpi/gm45.asl       |  52 +++
 src/northbridge/intel/x4x/acpi/hostbridge.asl | 238 ++++++++++++
 src/northbridge/intel/x4x/acpi/igd.asl        |  77 ++++
 src/northbridge/intel/x4x/acpi/peg.asl        |  49 +++
 src/northbridge/intel/x4x/bootblock.c         |  32 ++
 src/northbridge/intel/x4x/chip.h              |  26 ++
 src/northbridge/intel/x4x/debug.h             |  28 ++
 src/northbridge/intel/x4x/delay.c             |  96 +++++
 src/northbridge/intel/x4x/delay.h             |  24 ++
 src/northbridge/intel/x4x/early_init.c        |  59 +++
 src/northbridge/intel/x4x/gma.c               | 535 ++++++++++++++++++++++++++
 src/northbridge/intel/x4x/northbridge.c       | 270 +++++++++++++
 src/northbridge/intel/x4x/ram_calc.c          |  66 ++++
 src/northbridge/intel/x4x/x4x.h               | 442 +++++++++++++++++++++
 18 files changed, 2178 insertions(+)

diff --git a/src/Kconfig b/src/Kconfig
index 8439a00..a491049 100644
--- a/src/Kconfig
+++ b/src/Kconfig
@@ -358,6 +358,7 @@ source "src/mainboard/Kconfig"
 config CBFS_SIZE
 	hex "Size of CBFS filesystem in ROM"
 	default 0x100000 if HAVE_INTEL_FIRMWARE || \
+	  NORTHBRIDGE_INTEL_X4X || \
 	  NORTHBRIDGE_INTEL_GM45 || NORTHBRIDGE_INTEL_SANDYBRIDGE_MRC || \
 	  NORTHBRIDGE_INTEL_IVYBRIDGE_MRC || NORTHBRIDGE_INTEL_IVYBRIDGE || \
 	  NORTHBRIDGE_INTEL_SANDYBRIDGE || \
diff --git a/src/northbridge/intel/x4x/Kconfig b/src/northbridge/intel/x4x/Kconfig
new file mode 100644
index 0000000..f2d196c
--- /dev/null
+++ b/src/northbridge/intel/x4x/Kconfig
@@ -0,0 +1,41 @@
+##
+## This file is part of the coreboot project.
+##
+## Copyright (C) 2007-2009 coresystems GmbH
+## Copyright (C) 2015 Damien Zammit <damien at zamaudio.com>
+##
+## 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; version 2 of the License.
+##
+## 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.
+##
+
+config NORTHBRIDGE_INTEL_X4X
+	bool
+
+if NORTHBRIDGE_INTEL_X4X
+
+config NORTHBRIDGE_SPECIFIC_OPTIONS # dummy
+	def_bool y
+	select HAVE_DEBUG_RAM_SETUP
+	select MMCONF_SUPPORT
+	select MMCONF_SUPPORT_DEFAULT
+	select VGA
+
+config BOOTBLOCK_NORTHBRIDGE_INIT
+	string
+	default "northbridge/intel/x4x/bootblock.c"
+
+config VGA_BIOS_ID
+	string
+	default "8086,2a42"
+
+endif
diff --git a/src/northbridge/intel/x4x/Makefile.inc b/src/northbridge/intel/x4x/Makefile.inc
new file mode 100644
index 0000000..9ef6086
--- /dev/null
+++ b/src/northbridge/intel/x4x/Makefile.inc
@@ -0,0 +1,32 @@
+#
+# This file is part of the coreboot project.
+#
+# Copyright (C) 2012 secunet Security Networks AG
+# Copyright (C) 2015 Damien Zammit <damien at zamaudio.com>
+#
+# 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; version 2 of the License.
+#
+# 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.
+#
+
+ifeq ($(CONFIG_NORTHBRIDGE_INTEL_X4X),y)
+
+romstage-y += early_init.c
+romstage-y += delay.c
+romstage-y += raminit.c
+romstage-y += raminit_ddr2.c
+romstage-y += ram_calc.c
+
+ramstage-y += acpi.c
+ramstage-y += ram_calc.c
+ramstage-y += northbridge.c
+ramstage-y += gma.c
+
+smm-$(CONFIG_HAVE_SMI_HANDLER) += delay.c
+
+endif
diff --git a/src/northbridge/intel/x4x/acpi.c b/src/northbridge/intel/x4x/acpi.c
new file mode 100644
index 0000000..bf920f7
--- /dev/null
+++ b/src/northbridge/intel/x4x/acpi.c
@@ -0,0 +1,110 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2007-2009 coresystems GmbH
+ *
+ * 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; version 2 of
+ * the License.
+ *
+ * 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.
+ *
+ */
+
+#include <types.h>
+#include <string.h>
+#include <console/console.h>
+#include <arch/acpi.h>
+#include <arch/acpigen.h>
+#include <device/device.h>
+#include <device/pci.h>
+#include <device/pci_ids.h>
+#include <cbmem.h>
+#include <arch/acpigen.h>
+#include <cpu/cpu.h>
+#include "x4x.h"
+
+unsigned long acpi_fill_mcfg(unsigned long current)
+{
+	device_t dev;
+	u32 pciexbar = 0;
+	u32 pciexbar_reg;
+	int max_buses;
+
+	dev = dev_find_device(0x8086, 0x2a40, 0);
+	if (!dev)
+		return current;
+
+	pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO);
+
+	// MMCFG not supported or not enabled.
+	if (!(pciexbar_reg & (1 << 0)))
+		return current;
+
+	switch ((pciexbar_reg >> 1) & 3) {
+	case 0: // 256MB
+		pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28));
+		max_buses = 256;
+		break;
+	case 1: // 128M
+		pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27));
+		max_buses = 128;
+		break;
+	case 2: // 64M
+		pciexbar = pciexbar_reg & ((1 << 31)|(1 << 30)|(1 << 29)|(1 << 28)|(1 << 27)|(1 << 26));
+		max_buses = 64;
+		break;
+	default: // RSVD
+		return current;
+	}
+
+	if (!pciexbar)
+		return current;
+
+	current += acpi_create_mcfg_mmconfig((acpi_mcfg_mmconfig_t *) current,
+			pciexbar, 0x0, 0x0, max_buses - 1);
+
+	return current;
+}
+
+/*
+static unsigned long acpi_fill_dmar(unsigned long current)
+{
+	//int me_active = (dev_find_slot(0, PCI_DEVFN(3, 0)) != NULL);
+	//int stepping = pci_read_config8(dev_find_slot(0, PCI_DEVFN(0, 0)), PCI_CLASS_REVISION);
+
+	//unsigned long tmp = current;
+	return current;
+}
+*/
+#define ALIGN_CURRENT current = (ALIGN(current, 16))
+unsigned long northbridge_write_acpi_tables(device_t device,
+					    unsigned long start,
+					    struct acpi_rsdp *rsdp)
+{
+	unsigned long current;
+#if CONFIG_IOMMU
+	acpi_dmar_t *dmar;
+#endif
+
+	current = start;
+
+#if CONFIG_IOMMU
+	printk(BIOS_DEBUG, "ACPI:     * DMAR\n");
+	dmar = (acpi_dmar_t *) current;
+	acpi_create_dmar(dmar, acpi_fill_dmar);
+	current += dmar->header.length;
+	ALIGN_CURRENT;
+	acpi_add_table(rsdp, dmar);
+#endif
+
+	ALIGN_CURRENT;
+
+	printk(BIOS_DEBUG, "current = %lx\n", current);
+
+	return current;
+}
diff --git a/src/northbridge/intel/x4x/acpi/gm45.asl b/src/northbridge/intel/x4x/acpi/gm45.asl
new file mode 100644
index 0000000..187064b
--- /dev/null
+++ b/src/northbridge/intel/x4x/acpi/gm45.asl
@@ -0,0 +1,52 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2007-2009 coresystems GmbH
+ *
+ * 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; version 2 of
+ * the License.
+ *
+ * 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.
+ */
+
+#include "hostbridge.asl"
+#include "../x4x.h"
+
+/* PCI Device Resource Consumption */
+Device (PDRC)
+{
+	Name (_HID, EISAID("PNP0C02"))
+	Name (_UID, 1)
+
+	Name (PDRS, ResourceTemplate() {
+		Memory32Fixed(ReadWrite, 0xfed1c000, 0x00004000) // RCBA
+		Memory32Fixed(ReadWrite, DEFAULT_MCHBAR,   0x00004000)
+		Memory32Fixed(ReadWrite, DEFAULT_DMIBAR,   0x00001000)
+		Memory32Fixed(ReadWrite, DEFAULT_EPBAR,    0x00001000)
+		Memory32Fixed(ReadWrite, DEFAULT_PCIEXBAR, 0x04000000)
+		Memory32Fixed(ReadWrite, 0xfed20000, 0x00020000) // Misc ICH
+		Memory32Fixed(ReadWrite, 0xfed40000, 0x00005000) // Misc ICH
+		Memory32Fixed(ReadWrite, 0xfed45000, 0x0004b000) // Misc ICH
+	})
+
+	// Current Resource Settings
+	Method (_CRS, 0, Serialized)
+	{
+		Return(PDRS)
+	}
+}
+
+// PCIe graphics port 0:1.0
+#include "peg.asl"
+
+// Integrated graphics 0:2.0
+//#include "igd.asl"
diff --git a/src/northbridge/intel/x4x/acpi/hostbridge.asl b/src/northbridge/intel/x4x/acpi/hostbridge.asl
new file mode 100644
index 0000000..cdcaa7f
--- /dev/null
+++ b/src/northbridge/intel/x4x/acpi/hostbridge.asl
@@ -0,0 +1,238 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2007-2009 coresystems GmbH
+ *
+ * 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; version 2 of
+ * the License.
+ *
+ * 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.
+ */
+
+#include <arch/ioapic.h>
+
+Name(_HID,EISAID("PNP0A08"))	// PCIe
+Name(_CID,EISAID("PNP0A03"))	// PCI
+
+Name(_ADR, 0)
+Name(_BBN, 0)
+
+Device (MCHC)
+{
+	Name(_ADR, 0x00000000)	// 0:0.0
+
+	OperationRegion(MCHP, PCI_Config, 0x00, 0x100)
+	Field (MCHP, DWordAcc, NoLock, Preserve)
+	{
+		Offset (0x40),	// EPBAR
+		EPEN,	 1,	// Enable
+		,	11,	//
+		EPBR,	24,	// EPBAR
+
+		Offset (0x48),	// MCHBAR
+		MHEN,	 1,	// Enable
+		,	13,	//
+		MHBR,	22,	// MCHBAR
+
+		Offset (0x60),	// PCIe BAR
+		PXEN,	 1,	// Enable
+		PXSZ,	 2,	// BAR size
+		,	23,	//
+		PXBR,	10,	// PCIe BAR
+
+		Offset (0x68),	// DMIBAR
+		DMEN,	 1,	// Enable
+		,	11,	//
+		DMBR,	24,	// DMIBAR
+
+		// ...
+
+		Offset (0x90),	// PAM0
+		,	 4,
+		PM0H,	 2,
+		,	 2,
+		Offset (0x91),	// PAM1
+		PM1L,	 2,
+		,	 2,
+		PM1H,	 2,
+		,	 2,
+		Offset (0x92),	// PAM2
+		PM2L,	 2,
+		,	 2,
+		PM2H,	 2,
+		,	 2,
+		Offset (0x93),	// PAM3
+		PM3L,	 2,
+		,	 2,
+		PM3H,	 2,
+		,	 2,
+		Offset (0x94),	// PAM4
+		PM4L,	 2,
+		,	 2,
+		PM4H,	 2,
+		,	 2,
+		Offset (0x95),	// PAM5
+		PM5L,	 2,
+		,	 2,
+		PM5H,	 2,
+		,	 2,
+		Offset (0x96),	// PAM6
+		PM6L,	 2,
+		,	 2,
+		PM6H,	 2,
+		,	 2,
+
+		Offset (0xa0),	// Top of Used Memory
+		TOM,	 8,
+
+		Offset (0xb0),	// Top of Low Used Memory
+		,	 4,
+		TLUD,	12,
+	}
+
+}
+
+
+// Current Resource Settings
+
+Method (_CRS, 0, Serialized)
+{
+	Name (MCRS, ResourceTemplate()
+	{
+		// Bus Numbers
+		WordBusNumber (ResourceProducer, MinFixed, MaxFixed, PosDecode,
+				0x0000, 0x0000, 0x00ff, 0x0000, 0x0100,,, PB00)
+
+		// IO Region 0
+		DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
+				0x0000, 0x0000, 0x0cf7, 0x0000, 0x0cf8,,, PI00)
+
+		// PCI Config Space
+		Io (Decode16, 0x0cf8, 0x0cf8, 0x0001, 0x0008)
+
+		// IO Region 1
+		DWordIO (ResourceProducer, MinFixed, MaxFixed, PosDecode, EntireRange,
+				0x0000, 0x0d00, 0xffff, 0x0000, 0xf300,,, PI01)
+
+		// VGA memory (0xa0000-0xbffff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0x000a0000, 0x000bffff, 0x00000000,
+				0x00020000,,, ASEG)
+
+		// OPROM reserved (0xc0000-0xc3fff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0x000c0000, 0x000c3fff, 0x00000000,
+				0x00004000,,, OPR0)
+
+		// OPROM reserved (0xc4000-0xc7fff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0x000c4000, 0x000c7fff, 0x00000000,
+				0x00004000,,, OPR1)
+
+		// OPROM reserved (0xc8000-0xcbfff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0x000c8000, 0x000cbfff, 0x00000000,
+				0x00004000,,, OPR2)
+
+		// OPROM reserved (0xcc000-0xcffff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0x000cc000, 0x000cffff, 0x00000000,
+				0x00004000,,, OPR3)
+
+		// OPROM reserved (0xd0000-0xd3fff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0x000d0000, 0x000d3fff, 0x00000000,
+				0x00004000,,, OPR4)
+
+		// OPROM reserved (0xd4000-0xd7fff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0x000d4000, 0x000d7fff, 0x00000000,
+				0x00004000,,, OPR5)
+
+		// OPROM reserved (0xd8000-0xdbfff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0x000d8000, 0x000dbfff, 0x00000000,
+				0x00004000,,, OPR6)
+
+		// OPROM reserved (0xdc000-0xdffff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0x000dc000, 0x000dffff, 0x00000000,
+				0x00004000,,, OPR7)
+
+		// BIOS Extension (0xe0000-0xe3fff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0x000e0000, 0x000e3fff, 0x00000000,
+				0x00004000,,, ESG0)
+
+		// BIOS Extension (0xe4000-0xe7fff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0x000e4000, 0x000e7fff, 0x00000000,
+				0x00004000,,, ESG1)
+
+		// BIOS Extension (0xe8000-0xebfff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0x000e8000, 0x000ebfff, 0x00000000,
+				0x00004000,,, ESG2)
+
+		// BIOS Extension (0xec000-0xeffff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0x000ec000, 0x000effff, 0x00000000,
+				0x00004000,,, ESG3)
+
+		// System BIOS (0xf0000-0xfffff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0x000f0000, 0x000fffff, 0x00000000,
+				0x00010000,,, FSEG)
+
+		// PCI Memory Region (Top of memory-0xfebfffff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0x00000000, 0xfebfffff, 0x00000000,
+				IO_APIC_ADDR,,, PM01)
+
+		// TPM Area (0xfed40000-0xfed44fff)
+		DWordMemory (ResourceProducer, PosDecode, MinFixed, MaxFixed,
+				Cacheable, ReadWrite,
+				0x00000000, 0xfed40000, 0xfed44fff, 0x00000000,
+				0x00005000,,, TPMR)
+	})
+
+	// Find PCI resource area in MCRS
+	CreateDwordField(MCRS, PM01._MIN, PMIN)
+	CreateDwordField(MCRS, PM01._MAX, PMAX)
+	CreateDwordField(MCRS, PM01._LEN, PLEN)
+
+	// Fix up PCI memory region:
+	// Enter actual TOLUD. The TOLUD register contains bits 20-31 of
+	// the top of memory address.
+	ShiftLeft (^MCHC.TLUD, 20, PMIN)
+	Add(Subtract(PMAX, PMIN), 1, PLEN)
+
+	Return (MCRS)
+}
+
+/* IRQ assignment is mainboard specific. Get it from mainboard ACPI code */
+#include "acpi/gm45_pci_irqs.asl"
diff --git a/src/northbridge/intel/x4x/acpi/igd.asl b/src/northbridge/intel/x4x/acpi/igd.asl
new file mode 100644
index 0000000..dfb567b
--- /dev/null
+++ b/src/northbridge/intel/x4x/acpi/igd.asl
@@ -0,0 +1,77 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2007-2009 coresystems GmbH
+ *
+ * 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; version 2 of
+ * the License.
+ *
+ * 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.
+ */
+
+Device (GFX0)
+{
+	Name (_ADR, 0x00020000)
+
+	OperationRegion (GFXC, PCI_Config, 0x00, 0x0100)
+	Field (GFXC, DWordAcc, NoLock, Preserve)
+	{
+		Offset (0x10),
+		BAR0, 64
+	}
+
+	OperationRegion (GFRG, SystemMemory, And(BAR0, 0xfffffffffffffff0), 0x400000)
+	Field (GFRG, DWordAcc, NoLock, Preserve)
+	{
+		Offset (0x61250),
+			CR1, 32,
+			BCLV, 16,
+			BCLM, 16,
+	}
+
+	Name (BRIG, Package (0x12)
+	{
+		0x61,
+		0x61,
+		0x2,
+		0x4,
+		0x5,
+		0x7,
+		0x9,
+		0xb,
+		0xd,
+		0x11,
+		0x14,
+		0x17,
+		0x1c,
+		0x20,
+		0x27,
+		0x31,
+		0x41,
+		0x61,
+	})
+
+	Method (XBCM, 1, NotSerialized)
+	{
+		Store (ShiftLeft (Arg0, 4), BCLV)
+		Store (0x80000000, CR1)
+		Store (0x0610, BCLM)
+	}
+
+	Method (XBQC, 0, NotSerialized)
+	{
+		Store (BCLV, Local0)
+		ShiftRight (Local0, 4, Local0)
+		Return (Local0)
+	}
+#include <drivers/intel/gma/acpi/common.asl>
+}
diff --git a/src/northbridge/intel/x4x/acpi/peg.asl b/src/northbridge/intel/x4x/acpi/peg.asl
new file mode 100644
index 0000000..d8b965e
--- /dev/null
+++ b/src/northbridge/intel/x4x/acpi/peg.asl
@@ -0,0 +1,49 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2007-2009 coresystems GmbH
+ *
+ * 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; version 2 of
+ * the License.
+ *
+ * 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.
+ */
+
+Device (PEGP)
+{
+	Name (_ADR, 0x00010000)
+
+	// PCI Interrupt Routing.
+	Method (_PRT)
+	{
+		If (PICM) {
+			Return (Package() {
+				Package() { 0x0000ffff, 0, 0, 16 },
+				Package() { 0x0000ffff, 1, 0, 17 },
+				Package() { 0x0000ffff, 2, 0, 18 },
+				Package() { 0x0000ffff, 3, 0, 19 },
+				Package() { 0x0000ffff, 0, 0, 16 },
+				Package() { 0x0000ffff, 1, 0, 17 },
+			})
+		} Else {
+			Return (Package() {
+				Package() { 0x0000ffff, 0, \_SB.PCI0.LPCB.LNKA, 0 },
+				Package() { 0x0000ffff, 1, \_SB.PCI0.LPCB.LNKB, 0 },
+				Package() { 0x0000ffff, 2, \_SB.PCI0.LPCB.LNKC, 0 },
+				Package() { 0x0000ffff, 3, \_SB.PCI0.LPCB.LNKD, 0 },
+				Package() { 0x0000ffff, 0, \_SB.PCI0.LPCB.LNKA, 0 },
+				Package() { 0x0000ffff, 1, \_SB.PCI0.LPCB.LNKB, 0 },
+			})
+		}
+
+	}
+}
diff --git a/src/northbridge/intel/x4x/bootblock.c b/src/northbridge/intel/x4x/bootblock.c
new file mode 100644
index 0000000..cf6af9e
--- /dev/null
+++ b/src/northbridge/intel/x4x/bootblock.c
@@ -0,0 +1,32 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2015  Damien Zammit <damien at zamaudio.com>
+ *
+ * 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.
+ */
+
+#include <arch/io.h>
+
+#define D0F0_PCIEXBAR_LO 0x60
+#define TPMBASE 0xfed40000
+#define TPM32(x) *((volatile u32 *)(TPMBASE + x))
+
+static void bootblock_northbridge_init(void)
+{
+	uint32_t reg32;
+
+	/* Magic */
+	reg32 = TPM32(0);
+
+	reg32 = CONFIG_MMCONF_BASE_ADDRESS | (2 << 1) | 1;
+	pci_io_write_config32(PCI_DEV(0,0,0), D0F0_PCIEXBAR_LO, reg32);
+}
diff --git a/src/northbridge/intel/x4x/chip.h b/src/northbridge/intel/x4x/chip.h
new file mode 100644
index 0000000..1fb54cc
--- /dev/null
+++ b/src/northbridge/intel/x4x/chip.h
@@ -0,0 +1,26 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2015  Damien Zammit <damien at zamaudio.com>
+ *
+ * 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.
+ */
+
+#ifndef NORTHBRIDGE_INTEL_X4X_CHIP_H
+#define NORTHBRIDGE_INTEL_X4X_CHIP_H
+
+#include <drivers/intel/gma/i915.h>
+
+struct northbridge_intel_x4x_config {
+	struct i915_gpu_controller_info gfx;
+};
+
+#endif
diff --git a/src/northbridge/intel/x4x/debug.h b/src/northbridge/intel/x4x/debug.h
new file mode 100644
index 0000000..c5d3cf4
--- /dev/null
+++ b/src/northbridge/intel/x4x/debug.h
@@ -0,0 +1,28 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2015  Damien Zammit <damien at zamaudio.com>
+ *
+ * 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.
+ */
+
+/* Debugging macros. */
+#if 1
+#define PRINTK_DEBUG(x...)	printk(BIOS_DEBUG, x)
+#else
+#define PRINTK_DEBUG(x...)
+#endif
+
+#if 0
+#define PRINTK_VERBOSE(x...)	printk(BIOS_DEBUG, x)
+#else
+#define PRINTK_VERBOSE(x...)
+#endif
diff --git a/src/northbridge/intel/x4x/delay.c b/src/northbridge/intel/x4x/delay.c
new file mode 100644
index 0000000..ad2e543
--- /dev/null
+++ b/src/northbridge/intel/x4x/delay.c
@@ -0,0 +1,96 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2007-2008 coresystems GmbH
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ */
+
+#include <stdint.h>
+#include <cpu/x86/tsc.h>
+#include <cpu/x86/msr.h>
+#include <cpu/intel/speedstep.h>
+#include "delay.h"
+
+/**
+ * Intel Core(tm) CPUs always run the TSC at the maximum possible CPU clock
+ */
+static void _udelay(const u32 us, const u32 numerator, const int total)
+{
+	u32 dword;
+	tsc_t tsc, tsc1, tscd;
+	msr_t msr;
+	u32 fsb = 0, divisor;
+	u32 d;			/* ticks per us */
+
+	msr = rdmsr(MSR_FSB_FREQ);
+	switch (msr.lo & 0x07) {
+	case 5:
+		fsb = 400;
+		break;
+	case 1:
+		fsb = 533;
+		break;
+	case 3:
+		fsb = 667;
+		break;
+	case 2:
+		fsb = 800;
+		break;
+	case 0:
+		fsb = 1067;
+		break;
+	case 4:
+		fsb = 1333;
+		break;
+	case 6:
+		fsb = 1600;
+		break;
+	}
+
+	msr = rdmsr(0x198);
+	divisor = (msr.hi >> 8) & 0x1f;
+
+	d = ((fsb * divisor) / numerator) / 4;	/* CPU clock is always a quarter. */
+
+	multiply_to_tsc(&tscd, us, d);
+
+	if (!total) {
+		tsc1 = rdtsc();
+		dword = tsc1.lo + tscd.lo;
+		if ((dword < tsc1.lo) || (dword < tscd.lo)) {
+			tsc1.hi++;
+		}
+		tsc1.lo = dword;
+		tsc1.hi += tscd.hi;
+	} else {
+		tsc1 = tscd;
+	}
+
+	do {
+		tsc = rdtsc();
+	} while ((tsc.hi < tsc1.hi)
+		 || ((tsc.hi == tsc1.hi) && (tsc.lo < tsc1.lo)));
+}
+
+void udelay(const u32 us)
+{
+	_udelay(us, 1, 0);
+}
+
+void ns100delay(const u32 ns100)
+{
+	_udelay(ns100, 10, 0);
+}
+
+void udelay_from_reset(const u32 us)
+{
+	_udelay(us, 1, 1);
+}
diff --git a/src/northbridge/intel/x4x/delay.h b/src/northbridge/intel/x4x/delay.h
new file mode 100644
index 0000000..d84c5fb
--- /dev/null
+++ b/src/northbridge/intel/x4x/delay.h
@@ -0,0 +1,24 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2012 secunet Security Networks AG
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ */
+
+#ifndef __NORTHBRIDGE_INTEL_GM45_DELAY_H__
+#define __NORTHBRIDGE_INTEL_GM45_DELAY_H__
+
+#include <delay.h>
+
+void ns100delay(u32);
+void udelay_from_reset(u32);
+
+#endif /* __NORTHBRIDGE_INTEL_GM45_DELAY_H__ */
diff --git a/src/northbridge/intel/x4x/early_init.c b/src/northbridge/intel/x4x/early_init.c
new file mode 100644
index 0000000..be8ebab
--- /dev/null
+++ b/src/northbridge/intel/x4x/early_init.c
@@ -0,0 +1,59 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2012 secunet Security Networks AG
+ * Copyright (C) 2015 Damien Zammit <damien at zamaudio.com>
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ */
+
+#include <stdint.h>
+#include <arch/io.h>
+#include "x4x.h"
+
+void x4x_early_init(void)
+{
+	u16 reg16;
+
+	const device_t d0f0 = PCI_DEV(0, 0, 0);
+
+	/* Setup MCHBAR. */
+	pci_write_config32(d0f0, D0F0_MCHBAR_LO, (uintptr_t)DEFAULT_MCHBAR | 1);
+
+	/* Setup DMIBAR. */
+	pci_write_config32(d0f0, D0F0_DMIBAR_LO, (uintptr_t)DEFAULT_DMIBAR | 1);
+
+	/* Setup EPBAR. */
+	pci_write_config32(d0f0, D0F0_EPBAR_LO, DEFAULT_EPBAR | 1);
+
+	/* Setup PMBASE */
+	pci_write_config32(d0f0, D0F0_PMBASE, DEFAULT_PMBASE | 1);
+
+	/* Setup HECIBAR */
+	pci_write_config32(PCI_DEV(0,3,0), 0x10, DEFAULT_HECIBAR);
+	reg16 = pci_read_config16(PCI_DEV(0,3,0), 0x4);
+	pci_write_config16(PCI_DEV(0,3,0), 0x4, reg16 | 0x6);
+
+	/* Set C0000-FFFFF to access RAM on both reads and writes */
+	pci_write_config8(d0f0, D0F0_PAM(0), 0x30);
+	pci_write_config8(d0f0, D0F0_PAM(1), 0x33);
+	pci_write_config8(d0f0, D0F0_PAM(2), 0x33);
+	pci_write_config8(d0f0, D0F0_PAM(3), 0x33);
+	pci_write_config8(d0f0, D0F0_PAM(4), 0x33);
+	pci_write_config8(d0f0, D0F0_PAM(5), 0x33);
+	pci_write_config8(d0f0, D0F0_PAM(6), 0x33);
+
+	/* Disable internal GFX */
+	pci_write_config16(d0f0, 0x52, 0x0002);
+	// 0x180 GTT = 1MiB, UMA = 128MiB
+
+	reg16 = pci_read_config16(d0f0, 0x54);
+	pci_write_config16(d0f0, 0x54, reg16 | 0x8);
+}
diff --git a/src/northbridge/intel/x4x/gma.c b/src/northbridge/intel/x4x/gma.c
new file mode 100644
index 0000000..7309207
--- /dev/null
+++ b/src/northbridge/intel/x4x/gma.c
@@ -0,0 +1,535 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2011 Chromium OS Authors
+ * Copyright (C) 2013 Vladimir Serbinenko
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ */
+
+#include <arch/io.h>
+#include <console/console.h>
+#include <delay.h>
+#include <device/device.h>
+#include <device/pci.h>
+#include <device/pci_ids.h>
+#include <string.h>
+#include <device/pci_ops.h>
+#include <cpu/x86/msr.h>
+#include <cpu/x86/mtrr.h>
+#include <kconfig.h>
+
+#include "drivers/intel/gma/i915_reg.h"
+#include "chip.h"
+#include "x4x.h"
+#include <drivers/intel/gma/intel_bios.h>
+#include <drivers/intel/gma/edid.h>
+#include <drivers/intel/gma/i915.h>
+#include <pc80/vga.h>
+#include <pc80/vga_io.h>
+
+static struct resource *gtt_res = NULL;
+
+void gtt_write(u32 reg, u32 data)
+{
+	write32(res2mmio(gtt_res, reg, 0), data);
+}
+
+#if IS_ENABLED(CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT)
+
+static void power_port(u8 *mmio)
+{
+	read32(mmio + 0x00061100); // = 0x00000000
+	write32(mmio + 0x00061100, 0x00000000);
+	write32(mmio + 0x00061100, 0x00010000);
+	read32(mmio + 0x00061100); // = 0x00010000
+	read32(mmio + 0x00061100); // = 0x00010000
+	read32(mmio + 0x00061100); // = 0x00000000
+	write32(mmio + 0x00061100, 0x00000000);
+	read32(mmio + 0x00061100); // = 0x00000000
+	read32(mmio + 0x00064200); // = 0x0000001c
+	write32(mmio + 0x00064210, 0x8004003e);
+	write32(mmio + 0x00064214, 0x80060002);
+	write32(mmio + 0x00064218, 0x01000000);
+	read32(mmio + 0x00064210); // = 0x5144003e
+	write32(mmio + 0x00064210, 0x5344003e);
+	read32(mmio + 0x00064210); // = 0x0144003e
+	write32(mmio + 0x00064210, 0x8074003e);
+	read32(mmio + 0x00064210); // = 0x5144003e
+	read32(mmio + 0x00064210); // = 0x5144003e
+	write32(mmio + 0x00064210, 0x5344003e);
+	read32(mmio + 0x00064210); // = 0x0144003e
+	write32(mmio + 0x00064210, 0x8074003e);
+	read32(mmio + 0x00064210); // = 0x5144003e
+	read32(mmio + 0x00064210); // = 0x5144003e
+	write32(mmio + 0x00064210, 0x5344003e);
+	read32(mmio + 0x00064210); // = 0x0144003e
+	write32(mmio + 0x00064210, 0x8074003e);
+	read32(mmio + 0x00064210); // = 0x5144003e
+	read32(mmio + 0x00064210); // = 0x5144003e
+	write32(mmio + 0x00064210, 0x5344003e);
+	write32(mmio + 0x00064f00, 0x0100030c);
+	write32(mmio + 0x00064f04, 0x00b8230c);
+	write32(mmio + 0x00064f08, 0x06f8930c);
+	write32(mmio + 0x00064f0c, 0x09f8e38e);
+	write32(mmio + 0x00064f10, 0x00b8030c);
+	write32(mmio + 0x00064f14, 0x0b78830c);
+	write32(mmio + 0x00064f18, 0x0ff8d3cf);
+	write32(mmio + 0x00064f1c, 0x01e8030c);
+	write32(mmio + 0x00064f20, 0x0ff863cf);
+	write32(mmio + 0x00064f24, 0x0ff803cf);
+	write32(mmio + 0x000c4030, 0x00001000);
+	read32(mmio + 0x00044000); // = 0x00000000
+	write32(mmio + 0x00044030, 0x00001000);
+	read32(mmio + 0x00061150); // = 0x0000001c
+	write32(mmio + 0x00061150, 0x0000089c);
+	write32(mmio + 0x000fcc00, 0x01986f00);
+	write32(mmio + 0x000fcc0c, 0x01986f00);
+	write32(mmio + 0x000fcc18, 0x01986f00);
+	write32(mmio + 0x000fcc24, 0x01986f00);
+	read32(mmio + 0x00044000); // = 0x00000000
+	read32(mmio + LVDS); // = 0x40000002
+}
+
+static void intel_gma_init(const struct northbridge_intel_x4x_config *info,
+			   u8 *mmio, u32 physbase, u16 piobase, u32 lfb)
+{
+
+	int i;
+	u8 edid_data[128];
+	struct edid edid;
+	u32 hactive, vactive, right_border, bottom_border;
+	int hpolarity, vpolarity;
+	u32 vsync, hsync, vblank, hblank, hfront_porch, vfront_porch;
+	u32 candp1, candn;
+	u32 best_delta = 0xffffffff;
+	u32 target_frequency;
+	u32 pixel_p1 = 1;
+	u32 pixel_n = 1;
+	u32 pixel_m1 = 1;
+	u32 pixel_m2 = 1;
+	u32 link_frequency = info->gfx.link_frequency_270_mhz ? 270000 : 162000;
+	u32 data_m1;
+	u32 data_n1 = 0x00800000;
+	u32 link_m1;
+	u32 link_n1 = 0x00080000;
+
+	vga_gr_write(0x18, 0);
+
+	/* Setup GTT.  */
+	for (i = 0; i < 0x2000; i++)
+	{
+		outl((i << 2) | 1, piobase);
+		outl(physbase + (i << 12) + 1, piobase + 4);
+	}
+
+	write32(mmio + ADPA, 0x40008c18);
+	write32(mmio + 0x7041c, 0x0);
+	write32(mmio + _DPLL_B_MD, 0x3);
+
+	vga_misc_write(0x67);
+
+	const u8 cr[] = { 0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f,
+		    0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00,
+		    0x9c, 0x8e, 0x8f, 0x28, 0x1f, 0x96, 0xb9, 0xa3,
+		    0xff
+	};
+	vga_cr_write(0x11, 0);
+
+	for (i = 0; i <= 0x18; i++)
+		vga_cr_write(i, cr[i]);
+
+	power_port(mmio);
+
+	intel_gmbus_read_edid(mmio + GMBUS0, 3, 0x50, edid_data, 128);
+	decode_edid(edid_data,
+		    sizeof(edid_data), &edid);
+
+	/* Disable screen memory to prevent garbage from appearing.  */
+	vga_sr_write(1, vga_sr_read(1) | 0x20);
+
+	hactive = edid.x_resolution;
+	vactive = edid.y_resolution;
+	right_border = edid.hborder;
+	bottom_border = edid.vborder;
+	hpolarity = (edid.phsync == '-');
+	vpolarity = (edid.pvsync == '-');
+	vsync = edid.vspw;
+	hsync = edid.hspw;
+	vblank = edid.vbl;
+	hblank = edid.hbl;
+	hfront_porch = edid.hso;
+	vfront_porch = edid.vso;
+
+	target_frequency = info->gfx.lvds_dual_channel ? edid.pixel_clock
+		: (2 * edid.pixel_clock);
+#if IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
+	vga_sr_write(1, 1);
+	vga_sr_write(0x2, 0xf);
+	vga_sr_write(0x3, 0x0);
+	vga_sr_write(0x4, 0xe);
+	vga_gr_write(0, 0x0);
+	vga_gr_write(1, 0x0);
+	vga_gr_write(2, 0x0);
+	vga_gr_write(3, 0x0);
+	vga_gr_write(4, 0x0);
+	vga_gr_write(5, 0x0);
+	vga_gr_write(6, 0x5);
+	vga_gr_write(7, 0xf);
+	vga_gr_write(0x10, 0x1);
+	vga_gr_write(0x11, 0);
+
+	edid.bytes_per_line = (edid.bytes_per_line + 63) & ~63;
+
+	write32(mmio + DSPCNTR(0), DISPPLANE_BGRX888);
+	write32(mmio + DSPADDR(0), 0);
+	write32(mmio + DSPSTRIDE(0), edid.bytes_per_line);
+	write32(mmio + DSPSURF(0), 0);
+	for (i = 0; i < 0x100; i++)
+		write32(mmio + LGC_PALETTE(0) + 4 * i, i * 0x010101);
+#else
+	vga_textmode_init();
+#endif
+
+	/* Find suitable divisors.  */
+	for (candp1 = 1; candp1 <= 8; candp1++) {
+		for (candn = 5; candn <= 10; candn++) {
+			u32 cur_frequency;
+			u32 m; /* 77 - 131.  */
+			u32 denom; /* 35 - 560.  */
+			u32 current_delta;
+
+			denom = candn * candp1 * 7;
+			/* Doesnt overflow for up to
+			   5000000 kHz = 5 GHz.  */
+			m = (target_frequency * denom + 60000) / 120000;
+
+			if (m < 77 || m > 131)
+				continue;
+
+			cur_frequency = (120000 * m) / denom;
+			if (target_frequency > cur_frequency)
+				current_delta = target_frequency - cur_frequency;
+			else
+				current_delta = cur_frequency - target_frequency;
+
+
+			if (best_delta > current_delta) {
+				best_delta = current_delta;
+				pixel_n = candn;
+				pixel_p1 = candp1;
+				pixel_m2 = ((m + 3) % 5) + 7;
+				pixel_m1 = (m - pixel_m2) / 5;
+			}
+		}
+	}
+
+	if (best_delta == 0xffffffff) {
+		printk (BIOS_ERR, "Couldn't find GFX clock divisors\n");
+		return;
+	}
+
+	link_m1 = ((uint64_t)link_n1 * edid.pixel_clock) / link_frequency;
+	data_m1 = ((uint64_t)data_n1 * 18 * edid.pixel_clock)
+		/ (link_frequency * 8 * (info->gfx.lvds_num_lanes ? : 4));
+
+	printk(BIOS_INFO, "bringing up panel at resolution %d x %d\n",
+	       hactive, vactive);
+	printk(BIOS_DEBUG, "Borders %d x %d\n",
+	       right_border, bottom_border);
+	printk(BIOS_DEBUG, "Blank %d x %d\n",
+	       hblank, vblank);
+	printk(BIOS_DEBUG, "Sync %d x %d\n",
+	       hsync, vsync);
+	printk(BIOS_DEBUG, "Front porch %d x %d\n",
+	       hfront_porch, vfront_porch);
+	printk(BIOS_DEBUG, (info->gfx.use_spread_spectrum_clock
+			    ? "Spread spectrum clock\n" : "DREF clock\n"));
+	printk(BIOS_DEBUG,
+	       info->gfx.lvds_dual_channel ? "Dual channel\n" : "Single channel\n");
+	printk(BIOS_DEBUG, "Polarities %d, %d\n",
+	       hpolarity, vpolarity);
+	printk(BIOS_DEBUG, "Data M1=%d, N1=%d\n",
+	       data_m1, data_n1);
+	printk(BIOS_DEBUG, "Link frequency %d kHz\n",
+	       link_frequency);
+	printk(BIOS_DEBUG, "Link M1=%d, N1=%d\n",
+	       link_m1, link_n1);
+	printk(BIOS_DEBUG, "Pixel N=%d, M1=%d, M2=%d, P1=%d\n",
+	       pixel_n, pixel_m1, pixel_m2, pixel_p1);
+	printk(BIOS_DEBUG, "Pixel clock %d kHz\n",
+	       120000 * (5 * pixel_m1 + pixel_m2) / pixel_n
+	       / (pixel_p1 * 7));
+
+	write32(mmio + LVDS,
+		(hpolarity << 20) | (vpolarity << 21)
+		| (info->gfx.lvds_dual_channel ? LVDS_CLOCK_B_POWERUP_ALL
+		   | LVDS_CLOCK_BOTH_POWERUP_ALL : 0)
+		| LVDS_BORDER_ENABLE | LVDS_CLOCK_A_POWERUP_ALL);
+	mdelay(1);
+	write32(mmio + PP_CONTROL, PANEL_UNLOCK_REGS
+		| (read32(mmio + PP_CONTROL) & ~PANEL_UNLOCK_MASK));
+	write32(mmio + FP0(0),
+		((pixel_n - 2) << 16)
+		| ((pixel_m1 - 2) << 8) | pixel_m2);
+	write32(mmio + DPLL(0),
+		DPLL_VCO_ENABLE | DPLLB_MODE_LVDS
+		| (info->gfx.lvds_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7
+		   : DPLLB_LVDS_P2_CLOCK_DIV_14)
+		| (0x10000 << (pixel_p1 - 1))
+		| ((info->gfx.use_spread_spectrum_clock ? 3 : 0) << 13)
+		| (0x1 << (pixel_p1 - 1)));
+	mdelay(1);
+	write32(mmio + DPLL(0),
+		DPLL_VCO_ENABLE | DPLLB_MODE_LVDS
+		| (info->gfx.lvds_dual_channel ? DPLLB_LVDS_P2_CLOCK_DIV_7
+		   : DPLLB_LVDS_P2_CLOCK_DIV_14)
+		| (0x10000 << (pixel_p1 - 1))
+		| ((info->gfx.use_spread_spectrum_clock ? 3 : 0) << 13)
+		| (0x1 << (pixel_p1 - 1)));
+	/* Re-lock the registers.  */
+	write32(mmio + PP_CONTROL,
+		(read32(mmio + PP_CONTROL) & ~PANEL_UNLOCK_MASK));
+
+	write32(mmio + LVDS,
+		(hpolarity << 20) | (vpolarity << 21)
+		| (info->gfx.lvds_dual_channel ? LVDS_CLOCK_B_POWERUP_ALL
+		   | LVDS_CLOCK_BOTH_POWERUP_ALL : 0)
+		| LVDS_BORDER_ENABLE | LVDS_CLOCK_A_POWERUP_ALL);
+
+	write32(mmio + HTOTAL(0),
+		((hactive + right_border + hblank - 1) << 16)
+		| (hactive - 1));
+	write32(mmio + HBLANK(0),
+		((hactive + right_border + hblank - 1) << 16)
+		| (hactive + right_border - 1));
+	write32(mmio + HSYNC(0),
+		((hactive + right_border + hfront_porch + hsync - 1) << 16)
+		| (hactive + right_border + hfront_porch - 1));
+
+	write32(mmio + VTOTAL(0), ((vactive + bottom_border + vblank - 1) << 16)
+		| (vactive - 1));
+	write32(mmio + VBLANK(0), ((vactive + bottom_border + vblank - 1) << 16)
+		| (vactive + bottom_border - 1));
+	write32(mmio + VSYNC(0),
+		(vactive + bottom_border + vfront_porch + vsync - 1)
+		| (vactive + bottom_border + vfront_porch - 1));
+
+	write32(mmio + PIPECONF(0), PIPECONF_DISABLE);
+
+	write32(mmio + PF_WIN_POS(0), 0);
+#if IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
+	write32(mmio + PIPESRC(0), ((hactive - 1) << 16) | (vactive - 1));
+	write32(mmio + PF_CTL(0),0);
+	write32(mmio + PF_WIN_SZ(0), 0);
+	write32(mmio + PFIT_CONTROL, 0x20000000);
+#else
+	write32(mmio + PIPESRC(0), (639 << 16) | 399);
+	write32(mmio + PF_CTL(0),PF_ENABLE | PF_FILTER_MED_3x3);
+	write32(mmio + PF_WIN_SZ(0), vactive | (hactive << 16));
+	write32(mmio + PFIT_CONTROL, 0xa0000000);
+#endif
+
+	mdelay(1);
+
+	write32(mmio + PIPE_DATA_M1(0), 0x7e000000 | data_m1);
+	write32(mmio + PIPE_DATA_N1(0), data_n1);
+	write32(mmio + PIPE_LINK_M1(0), link_m1);
+	write32(mmio + PIPE_LINK_N1(0), link_n1);
+
+	write32(mmio + 0x000f000c, 0x00002040);
+	mdelay(1);
+	write32(mmio + 0x000f000c, 0x00002050);
+	write32(mmio + 0x00060100, 0x00044000);
+	mdelay(1);
+	write32(mmio + PIPECONF(0), PIPECONF_BPP_6);
+	write32(mmio + 0x000f0008, 0x00000040);
+	write32(mmio + 0x000f000c, 0x00022050);
+	write32(mmio + PIPECONF(0), PIPECONF_BPP_6 | PIPECONF_DITHER_EN);
+	write32(mmio + PIPECONF(0), PIPECONF_ENABLE | PIPECONF_BPP_6 | PIPECONF_DITHER_EN);
+
+#if IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
+	write32(mmio + VGACNTRL, 0x22c4008e | VGA_DISP_DISABLE);
+	write32(mmio + DSPCNTR(0), DISPLAY_PLANE_ENABLE | DISPPLANE_BGRX888);
+	mdelay(1);
+#else
+	write32(mmio + VGACNTRL, 0x22c4008e);
+#endif
+
+	write32(mmio + TRANS_HTOTAL(0),
+		((hactive + right_border + hblank - 1) << 16)
+		| (hactive - 1));
+	write32(mmio + TRANS_HBLANK(0),
+		((hactive + right_border + hblank - 1) << 16)
+		| (hactive + right_border - 1));
+	write32(mmio + TRANS_HSYNC(0),
+		((hactive + right_border + hfront_porch + hsync - 1) << 16)
+		| (hactive + right_border + hfront_porch - 1));
+
+	write32(mmio + TRANS_VTOTAL(0),
+		((vactive + bottom_border + vblank - 1) << 16)
+		| (vactive - 1));
+	write32(mmio + TRANS_VBLANK(0),
+		((vactive + bottom_border + vblank - 1) << 16)
+		| (vactive + bottom_border - 1));
+	write32(mmio + TRANS_VSYNC(0),
+		(vactive + bottom_border + vfront_porch + vsync - 1)
+		| (vactive + bottom_border + vfront_porch - 1));
+
+	write32(mmio + 0x00060100, 0xb01c4000);
+	write32(mmio + 0x000f000c, 0xb01a2050);
+	mdelay(1);
+	write32(mmio + TRANSCONF(0), TRANS_ENABLE | TRANS_6BPC
+		);
+	write32(mmio + LVDS,
+		LVDS_PORT_ENABLE
+		| (hpolarity << 20) | (vpolarity << 21)
+		| (info->gfx.lvds_dual_channel ? LVDS_CLOCK_B_POWERUP_ALL
+		   | LVDS_CLOCK_BOTH_POWERUP_ALL : 0)
+		| LVDS_BORDER_ENABLE | LVDS_CLOCK_A_POWERUP_ALL);
+
+	write32(mmio + PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_OFF);
+	write32(mmio + PP_CONTROL, PANEL_UNLOCK_REGS | PANEL_POWER_RESET);
+	mdelay(1);
+	write32(mmio + PP_CONTROL, PANEL_UNLOCK_REGS
+		| PANEL_POWER_ON | PANEL_POWER_RESET);
+
+	printk (BIOS_DEBUG, "waiting for panel powerup\n");
+	while (1) {
+		u32 reg32;
+		reg32 = read32(mmio + PP_STATUS);
+		if (((reg32 >> 28) & 3) == 0)
+			break;
+	}
+	printk (BIOS_DEBUG, "panel powered up\n");
+
+	write32(mmio + PP_CONTROL, PANEL_POWER_ON | PANEL_POWER_RESET);
+
+	/* Enable screen memory.  */
+	vga_sr_write(1, vga_sr_read(1) & ~0x20);
+
+	/* Clear interrupts. */
+	write32(mmio + DEIIR, 0xffffffff);
+	write32(mmio + SDEIIR, 0xffffffff);
+
+#if IS_ENABLED(CONFIG_FRAMEBUFFER_KEEP_VESA_MODE)
+	memset ((void *) lfb, 0, edid.x_resolution * edid.y_resolution * 4);
+	set_vbe_mode_info_valid(&edid, lfb);
+#endif
+}
+
+#endif
+
+static void gma_func0_init(struct device *dev)
+{
+	u32 reg32;
+
+	/* IGD needs to be Bus Master */
+	reg32 = pci_read_config32(dev, PCI_COMMAND);
+	reg32 |= PCI_COMMAND_MASTER | PCI_COMMAND_MEMORY | PCI_COMMAND_IO;
+	pci_write_config32(dev, PCI_COMMAND, reg32);
+
+	/* Init graphics power management */
+	gtt_res = find_resource(dev, PCI_BASE_ADDRESS_0);
+
+	struct northbridge_intel_x4x_config *conf = dev->chip_info;
+
+#if !CONFIG_MAINBOARD_DO_NATIVE_VGA_INIT
+	/* PCI Init, will run VBIOS */
+	pci_dev_init(dev);
+#else
+	u32 physbase;
+	struct resource *lfb_res;
+	struct resource *pio_res;
+
+	lfb_res = find_resource(dev, PCI_BASE_ADDRESS_2);
+	pio_res = find_resource(dev, PCI_BASE_ADDRESS_4);
+
+	physbase = pci_read_config32(dev, 0x5c) & ~0xf;
+
+	if (gtt_res && gtt_res->base && physbase && pio_res && pio_res->base
+	    && lfb_res && lfb_res->base) {
+		printk(BIOS_SPEW, "Initializing VGA without OPROM. MMIO 0x%llx\n",
+		       gtt_res->base);
+		intel_gma_init(conf, res2mmio(gtt_res, 0, 0), physbase,
+			       pio_res->base, lfb_res->base);
+	}
+
+	/* Linux relies on VBT for panel info.  */
+	generate_fake_intel_oprom(&conf->gfx, dev, "$VBT IRONLAKE-MOBILE");
+#endif
+
+	/* Post VBIOS init */
+	/* Enable Backlight  */
+	gtt_write(BLC_PWM_CTL2, (1 << 31));
+	if (conf->gfx.backlight == 0)
+		gtt_write(BLC_PWM_CTL, 0x06100610);
+	else
+		gtt_write(BLC_PWM_CTL, conf->gfx.backlight);
+}
+
+static void gma_set_subsystem(device_t dev, unsigned vendor, unsigned device)
+{
+	if (!vendor || !device) {
+		pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
+				   pci_read_config32(dev, PCI_VENDOR_ID));
+	} else {
+		pci_write_config32(dev, PCI_SUBSYSTEM_VENDOR_ID,
+				   ((device & 0xffff) << 16) | (vendor &
+								0xffff));
+	}
+}
+
+const struct i915_gpu_controller_info *
+intel_gma_get_controller_info(void)
+{
+	device_t dev = dev_find_slot(0, PCI_DEVFN(0x2,0));
+	if (!dev) {
+		return NULL;
+	}
+	struct northbridge_intel_x4x_config *chip = dev->chip_info;
+	return &chip->gfx;
+}
+
+static void gma_ssdt(device_t device)
+{
+	const struct i915_gpu_controller_info *gfx = intel_gma_get_controller_info();
+	if (!gfx) {
+		return;
+	}
+
+	//XXX drivers_intel_gma_displays_ssdt_generate(gfx);
+}
+
+static struct pci_operations gma_pci_ops = {
+	.set_subsystem = gma_set_subsystem,
+};
+
+static struct device_operations gma_func0_ops = {
+	.read_resources = pci_dev_read_resources,
+	.set_resources = pci_dev_set_resources,
+	.enable_resources = pci_dev_enable_resources,
+	.acpi_fill_ssdt_generator = gma_ssdt,
+	.init = gma_func0_init,
+	.scan_bus = 0,
+	.enable = 0,
+	.ops_pci = &gma_pci_ops,
+};
+
+static const unsigned short pci_device_ids[] =
+{
+	0x2a42, 0
+};
+
+static const struct pci_driver gma __pci_driver = {
+	.ops = &gma_func0_ops,
+	.vendor = PCI_VENDOR_ID_INTEL,
+	.devices = pci_device_ids,
+};
diff --git a/src/northbridge/intel/x4x/northbridge.c b/src/northbridge/intel/x4x/northbridge.c
new file mode 100644
index 0000000..1de0168
--- /dev/null
+++ b/src/northbridge/intel/x4x/northbridge.c
@@ -0,0 +1,270 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2007-2009 coresystems GmbH
+ * Copyright (C) 2015 Damien Zammit <damien at zamaudio.com>
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ */
+
+#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 <device/hypertransport.h>
+#include <stdlib.h>
+#include <string.h>
+#include <cpu/cpu.h>
+#include <boot/tables.h>
+#include <arch/acpi.h>
+#include <cbmem.h>
+#include "chip.h"
+#include "x4x.h"
+#include "arch/acpi.h"
+
+/* Reserve segments A and B:
+ *
+ * 0xa0000 - 0xbffff: legacy VGA
+ */
+static const int legacy_hole_base_k = 0xa0000 / 1024;
+static const int legacy_hole_size_k = 128;
+
+static int decode_pcie_bar(u32 *const base, u32 *const len)
+{
+	*base = 0;
+	*len = 0;
+
+	const device_t dev = dev_find_slot(0, PCI_DEVFN(0, 0));
+	if (!dev)
+		return 0;
+
+	const u32 pciexbar_reg = pci_read_config32(dev, D0F0_PCIEXBAR_LO);
+
+	if (!(pciexbar_reg & (1 << 0)))
+		return 0;
+
+	switch ((pciexbar_reg >> 1) & 3) {
+	case 0: /* 256MB */
+		*base = pciexbar_reg & (0x0f << 28);
+		*len = 256 * 1024 * 1024;
+		return 1;
+	case 1: /* 128M */
+		*base = pciexbar_reg & (0x1f << 27);
+		*len = 128 * 1024 * 1024;
+		return 1;
+	case 2: /* 64M */
+		*base = pciexbar_reg & (0x3f << 26);
+		*len = 64 * 1024 * 1024;
+		return 1;
+	}
+
+	return 0;
+}
+
+static void mch_domain_read_resources(device_t dev)
+{
+	u64 tom, touud;
+	u32 tomk, tolud, uma_sizek = 0, usable_tomk;
+	u32 pcie_config_base, pcie_config_size;
+
+	pci_domain_read_resources(dev);
+
+	/* Top of Upper Usable DRAM, including remap */
+	touud = pci_read_config16(dev, D0F0_TOUUD);
+	touud <<= 20;
+
+	/* Top of Lower Usable DRAM */
+	tolud = pci_read_config16(dev, D0F0_TOLUD) & 0xfff0;
+	tolud <<= 16;
+
+	/* Top of Memory - does not account for any UMA */
+	tom = pci_read_config16(dev, D0F0_TOM) & 0x01ff;
+	tom <<= 26;
+
+	printk(BIOS_DEBUG, "TOUUD 0x%llx TOLUD 0x%08x TOM 0x%llx\n",
+	       touud, tolud, tom);
+
+	tomk = tolud >> 10;
+
+	/* Graphics memory comes next */
+	const u16 ggc = pci_read_config16(dev, D0F0_GGC);
+	printk(BIOS_DEBUG, "IGD decoded, subtracting ");
+
+	/* Graphics memory */
+	const u32 gms_sizek = decode_igd_memory_size((ggc >> 4) & 0xf);
+	printk(BIOS_DEBUG, "%uM UMA", gms_sizek >> 10);
+	tomk -= gms_sizek;
+
+	/* GTT Graphics Stolen Memory Size (GGMS) */
+	const u32 gsm_sizek = decode_igd_gtt_size((ggc >> 8) & 0xf);
+	printk(BIOS_DEBUG, " and %uM GTT\n", gsm_sizek >> 10);
+	tomk -= gsm_sizek;
+
+	uma_sizek = gms_sizek + gsm_sizek;
+
+	usable_tomk = ALIGN_DOWN(tomk, 64 << 10);
+	if (tomk - usable_tomk > (16 << 10))
+		usable_tomk = tomk;
+
+	printk(BIOS_INFO, "Available memory below 4GB: %uM\n", usable_tomk >> 10);
+
+	/* Report the memory regions */
+	ram_resource(dev, 3, 0, legacy_hole_base_k);
+	ram_resource(dev, 4, legacy_hole_base_k + legacy_hole_size_k,
+		     (usable_tomk - (legacy_hole_base_k + legacy_hole_size_k)));
+
+	/*
+	 * If >= 4GB installed then memory from TOLUD to 4GB
+	 * is remapped above TOM, TOUUD will account for both
+	 */
+	touud >>= 10; /* Convert to KB */
+	if (touud > 4096 * 1024) {
+		ram_resource(dev, 5, 4096 * 1024, touud - (4096 * 1024));
+		printk(BIOS_INFO, "Available memory above 4GB: %lluM\n",
+		       (touud >> 10) - 4096);
+	}
+
+	printk(BIOS_DEBUG, "Adding UMA memory area base=0x%llx "
+	       "size=0x%llx\n", ((u64)tomk) << 10, ((u64)uma_sizek) << 10);
+	/* Don't use uma_resource() as our UMA touches the PCI hole. */
+	fixed_mem_resource(dev, 6, tomk, uma_sizek, IORESOURCE_RESERVE);
+
+	/* Some strange hole, reserve it */
+	fixed_mem_resource(dev, 7, 0xa0000000 >> 10, 0x20000000 >> 10, IORESOURCE_RESERVE);
+
+	if (decode_pcie_bar(&pcie_config_base, &pcie_config_size)) {
+		printk(BIOS_DEBUG, "Adding PCIe config bar base=0x%08x "
+		       "size=0x%x\n", pcie_config_base, pcie_config_size);
+		fixed_mem_resource(dev, 8, pcie_config_base >> 10,
+			pcie_config_size >> 10, IORESOURCE_RESERVE);
+	}
+}
+
+static void mch_domain_set_resources(device_t dev)
+{
+	struct resource *resource;
+	int i;
+
+	for (i = 3; i < 8; ++i) {
+		/* Report read resources. */
+		resource = probe_resource(dev, i);
+		if (resource)
+			report_resource_stored(dev, resource, "");
+	}
+
+	assign_resources(dev->link_list);
+}
+
+static void mch_domain_init(device_t dev)
+{
+	u32 reg32;
+
+	/* Enable SERR */
+	reg32 = pci_read_config32(dev, PCI_COMMAND);
+	reg32 |= PCI_COMMAND_SERR;
+	pci_write_config32(dev, PCI_COMMAND, reg32);
+}
+
+static struct device_operations pci_domain_ops = {
+	.read_resources   = mch_domain_read_resources,
+	.set_resources    = mch_domain_set_resources,
+	.enable_resources = NULL,
+	.init             = mch_domain_init,
+	.scan_bus         = pci_domain_scan_bus,
+	.ops_pci_bus	  = pci_bus_default_ops,
+	.write_acpi_tables = northbridge_write_acpi_tables,
+	.acpi_fill_ssdt_generator = generate_cpu_entries,
+};
+
+
+static void cpu_bus_init(device_t dev)
+{
+	initialize_cpus(dev->link_list);
+}
+
+static struct device_operations cpu_bus_ops = {
+	.read_resources   = DEVICE_NOOP,
+	.set_resources    = DEVICE_NOOP,
+	.enable_resources = DEVICE_NOOP,
+	.init             = cpu_bus_init,
+	.scan_bus         = 0,
+};
+
+
+static void enable_dev(device_t dev)
+{
+	/* Set the operations if it is a special bus type */
+	if (dev->path.type == DEVICE_PATH_DOMAIN) {
+		dev->ops = &pci_domain_ops;
+#if CONFIG_HAVE_ACPI_RESUME
+		switch (pci_read_config32(dev_find_slot(0, PCI_DEVFN(0, 0)), /*D0F0_SKPD*/0xdc)) {
+		case SKPAD_NORMAL_BOOT_MAGIC:
+			printk(BIOS_DEBUG, "Normal boot.\n");
+			acpi_slp_type=0;
+			break;
+		case SKPAD_ACPI_S3_MAGIC:
+			printk(BIOS_DEBUG, "S3 Resume.\n");
+			acpi_slp_type=3;
+			break;
+		default:
+			printk(BIOS_DEBUG, "Unknown boot method, assuming normal.\n");
+			acpi_slp_type=0;
+			break;
+		}
+#endif
+	} else if (dev->path.type == DEVICE_PATH_CPU_CLUSTER) {
+		dev->ops = &cpu_bus_ops;
+	}
+}
+
+static void x4x_init(void *const chip_info)
+{
+	int dev, fn, bit_base;
+
+	struct device *const d0f0 = dev_find_slot(0, 0);
+
+	/* Hide internal functions based on devicetree info. */
+	for (dev = 3; dev > 0; --dev) {
+		switch (dev) {
+		case 3: /* ME */
+			fn = 3;
+			bit_base = 6;
+			break;
+		case 2: /* IGD */
+			fn = 1;
+			bit_base = 3;
+			break;
+		case 1: /* PEG */
+			fn = 0;
+			bit_base = 1;
+			break;
+		}
+		for (; fn >= 0; --fn) {
+			const struct device *const d =
+				dev_find_slot(0, PCI_DEVFN(dev, fn));
+			if (!d || d->enabled) continue;
+			const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN);
+			pci_write_config32(d0f0, D0F0_DEVEN,
+					   deven & ~(1 << (bit_base + fn)));
+		}
+	}
+
+	const u32 deven = pci_read_config32(d0f0, D0F0_DEVEN);
+	if (!(deven & (0xf << 6)))
+		pci_write_config32(d0f0, D0F0_DEVEN, deven & ~(1 << 14));
+}
+
+struct chip_operations northbridge_intel_x4x_ops = {
+	CHIP_NAME("Intel 4-Series Northbridge")
+	.enable_dev = enable_dev,
+	.init = x4x_init,
+};
diff --git a/src/northbridge/intel/x4x/ram_calc.c b/src/northbridge/intel/x4x/ram_calc.c
new file mode 100644
index 0000000..752b311
--- /dev/null
+++ b/src/northbridge/intel/x4x/ram_calc.c
@@ -0,0 +1,66 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2012 secunet Security Networks AG
+ * Copyright (C) 2015 Damien Zammit <damien at zamaudio.com>
+ *
+ * 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; version 2 of
+ * the License.
+ *
+ * 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.
+ */
+
+// Use simple device model for this file even in ramstage
+#define __SIMPLE_DEVICE__
+
+#include <stdint.h>
+#include <arch/io.h>
+#include <device/pci_def.h>
+#include <console/console.h>
+#include <cbmem.h>
+#include "x4x.h"
+
+/** Decodes used Graphics Mode Select (GMS) to kilobytes. */
+u32 decode_igd_memory_size(const u32 gms)
+{
+	const u16 ggc2uma[] = { 0, 0, 0, 0, 0,
+			32, 48, 64, 128, 256, 96, 160, 224, 352 };
+
+	if (gms > 14)
+		die("Bad Graphics Mode Select (GMS) setting.\n");
+
+	return ggc2uma[gms] << 10;
+}
+
+/** Decodes used GTT Graphics Memory Size (GGMS) to kilobytes. */
+u32 decode_igd_gtt_size(const u32 gsm)
+{
+	const u8 ggc2gtt[] = { 0, 1, 0, 2, 0, 0, 0, 0, 0, 2, 3, 4};
+
+	if (gsm > 12)
+		die("Bad GTT Graphics Memory Size (GGMS) setting.\n");
+
+	return ggc2gtt[gsm] << 10;
+}
+
+static u32 smm_region_start(void)
+{
+	const pci_devfn_t dev = PCI_DEV(0, 0, 0);
+	u32 tseg;
+
+	tseg = pci_read_config32(dev, 0xac);
+	if (tseg >= 0xa0000000)
+		tseg = 0x9ff00000;
+
+	return tseg;
+}
+
+void *cbmem_top(void)
+{
+	return (void *)smm_region_start();
+}
diff --git a/src/northbridge/intel/x4x/x4x.h b/src/northbridge/intel/x4x/x4x.h
new file mode 100644
index 0000000..5f9c418
--- /dev/null
+++ b/src/northbridge/intel/x4x/x4x.h
@@ -0,0 +1,442 @@
+/*
+ * This file is part of the coreboot project.
+ *
+ * Copyright (C) 2007-2008 coresystems GmbH
+ *               2012 secunet Security Networks AG
+ * Copyright (C) 2015 Damien Zammit <damien at zamaudio.com>
+ *
+ * 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; version 2 of the License.
+ *
+ * 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.
+ */
+
+#ifndef __NORTHBRIDGE_INTEL_X4X_X4X_H__
+#define __NORTHBRIDGE_INTEL_X4X_X4X_H__
+
+#include "southbridge/intel/i82801gx/i82801gx.h"
+
+#ifndef __ACPI__
+
+#include <rules.h>
+#include <stdint.h>
+
+typedef enum {
+	FSB_CLOCK_1067MHz	= 0,
+	FSB_CLOCK_800MHz	= 1,
+	FSB_CLOCK_667MHz	= 2,
+} fsb_clock_t;
+
+typedef enum { /* Steppings below B1 were pre-production,
+		  conversion stepping A1 is... ?
+		  We'll support B1, B2, B3, and conversion stepping A1. */
+	STEPPING_A0 = 0,
+	STEPPING_A1 = 1,
+	STEPPING_A2 = 2,
+	STEPPING_A3 = 3,
+	STEPPING_B0 = 4,
+	STEPPING_B1 = 5,
+	STEPPING_B2 = 6,
+	STEPPING_B3 = 7,
+	STEPPING_CONVERSION_A1 = 9,
+} stepping_t;
+
+typedef enum {
+	GMCH_GM45 = 0,
+	GMCH_GM47,
+	GMCH_GM49,
+	GMCH_GE45,
+	GMCH_GL40,
+	GMCH_GL43,
+	GMCH_GS40,
+	GMCH_GS45,
+	GMCH_PM45,
+	GMCH_UNKNOWN
+} gmch_gfx_t;
+
+typedef enum {
+	MEM_CLOCK_533MHz  = 0,
+	MEM_CLOCK_400MHz  = 1,
+	MEM_CLOCK_333MHz  = 2,
+	MEM_CLOCK_1067MT  = 0,
+	MEM_CLOCK_800MT   = 1,
+	MEM_CLOCK_667MT   = 2,
+} mem_clock_t;
+
+typedef enum {
+	DDR1 = 1,
+	DDR2 = 2,
+	DDR3 = 3,
+} ddr_t;
+
+typedef enum {
+	CHANNEL_MODE_SINGLE,
+	CHANNEL_MODE_DUAL_ASYNC,
+	CHANNEL_MODE_DUAL_INTERLEAVED,
+} channel_mode_t;
+
+typedef enum { /* as in DDR3 spd */
+	CHIP_WIDTH_x4	= 0,
+	CHIP_WIDTH_x8	= 1,
+	CHIP_WIDTH_x16	= 2,
+	CHIP_WIDTH_x32	= 3,
+} chip_width_t;
+
+typedef enum { /* as in DDR3 spd */
+	CHIP_CAP_256M	= 0,
+	CHIP_CAP_512M	= 1,
+	CHIP_CAP_1G	= 2,
+	CHIP_CAP_2G	= 3,
+	CHIP_CAP_4G	= 4,
+	CHIP_CAP_8G	= 5,
+	CHIP_CAP_16G	= 6,
+} chip_capacity_t;
+
+typedef struct {
+	unsigned int	CAS;
+	fsb_clock_t	fsb_clock;
+	mem_clock_t	mem_clock;
+	channel_mode_t	channel_mode;
+	unsigned int	tRAS;
+	unsigned int	tRP;
+	unsigned int	tRCD;
+	unsigned int	tRFC;
+	unsigned int	tWR;
+	unsigned int	tRD;
+	unsigned int	tRRD;
+	unsigned int	tFAW;
+	unsigned int	tWL;
+} timings_t;
+
+typedef struct {
+	unsigned int	card_type; /* 0x0: unpopulated,
+				      0xa - 0xf: raw card type A - F */
+	chip_width_t	chip_width;
+	chip_capacity_t	chip_capacity;
+	unsigned int	page_size; /* of whole DIMM in Bytes (4096 or 8192) */
+	unsigned int	banks;
+	unsigned int	ranks;
+	unsigned int	rank_capacity_mb; /* per rank in Mega Bytes */
+} dimminfo_t;
+
+/* The setup is one DIMM per channel, so there's no need to find a
+   common timing setup between multiple chips (but chip and controller
+   still need to be coordinated */
+typedef struct {
+	stepping_t	stepping;
+	int		txt_enabled;
+	int		cores;
+	gmch_gfx_t	gfx_type;
+	int		gs45_low_power_mode; /* low power mode of GMCH_GS45 */
+	int		max_ddr2_mhz;
+	int		max_ddr3_mt;
+	fsb_clock_t	max_fsb;
+	int		max_fsb_mhz;
+	int		max_render_mhz;
+	int		enable_igd;
+	int		enable_peg;
+	u16		ggc;
+
+	int		spd_type;
+	timings_t	selected_timings;
+	dimminfo_t	dimms[2];
+	u8		spd_map[4];
+} sysinfo_t;
+#define TOTAL_CHANNELS 2
+#define CHANNEL_IS_POPULATED(dimms, idx) (dimms[idx].card_type != 0)
+#define CHANNEL_IS_CARDF(dimms, idx) (dimms[idx].card_type == 0xf)
+#define IF_CHANNEL_POPULATED(dimms, idx) if (dimms[idx].card_type != 0)
+#define FOR_EACH_CHANNEL(idx) \
+	for (idx = 0; idx < TOTAL_CHANNELS; ++idx)
+#define FOR_EACH_POPULATED_CHANNEL(dimms, idx) \
+	FOR_EACH_CHANNEL(idx) IF_CHANNEL_POPULATED(dimms, idx)
+
+#define RANKS_PER_CHANNEL 4 /* Only two may be populated */
+#define IF_RANK_POPULATED(dimms, ch, r) \
+	if (dimms[ch].card_type && ((r) < dimms[ch].ranks))
+#define FOR_EACH_RANK_IN_CHANNEL(r) \
+	for (r = 0; r < RANKS_PER_CHANNEL; ++r)
+#define FOR_EACH_POPULATED_RANK_IN_CHANNEL(dimms, ch, r) \
+	FOR_EACH_RANK_IN_CHANNEL(r) IF_RANK_POPULATED(dimms, ch, r)
+#define FOR_EACH_RANK(ch, r) \
+	FOR_EACH_CHANNEL(ch) FOR_EACH_RANK_IN_CHANNEL(r)
+#define FOR_EACH_POPULATED_RANK(dimms, ch, r) \
+	FOR_EACH_RANK(ch, r) IF_RANK_POPULATED(dimms, ch, r)
+
+#define DDR3_MAX_CAS 18
+
+enum {
+	VCO_2666 = 4,
+	VCO_3200 = 0,
+	VCO_4000 = 1,
+	VCO_5333 = 2,
+};
+
+#endif
+
+/* Offsets of read/write training results in CMOS.
+   They will be restored upon S3 resumes. */
+#define CMOS_READ_TRAINING	0x80 /* 16 bytes */
+#define CMOS_WRITE_TRAINING	0x90 /* 16 bytes
+					(could be reduced to 10 bytes) */
+
+
+#ifndef __ACPI__
+#define DEFAULT_MCHBAR		((u8 *)0xfed14000)
+#define DEFAULT_DMIBAR		((u8 *)0xfed18000)
+#else
+#define DEFAULT_MCHBAR		0xfed14000
+#define DEFAULT_DMIBAR		0xfed18000
+#endif
+#define DEFAULT_EPBAR		0xfed19000
+#define DEFAULT_HECIBAR		((u8 *)0xfed10000)
+
+				/* 4 KB per PCIe device */
+#define DEFAULT_PCIEXBAR	CONFIG_MMCONF_BASE_ADDRESS
+
+/*
+ * D0:F0
+ */
+#define D0F0_EPBAR_LO 0x40
+#define D0F0_EPBAR_HI 0x44
+#define D0F0_MCHBAR_LO 0x48
+#define D0F0_MCHBAR_HI 0x4c
+#define D0F0_GGC 0x52
+#define D0F0_DEVEN 0x54
+#define D0F0_PCIEXBAR_LO 0x60
+#define D0F0_PCIEXBAR_HI 0x64
+#define D0F0_DMIBAR_LO 0x68
+#define D0F0_DMIBAR_HI 0x6c
+#define D0F0_PMBASE 0x78
+#define D0F0_PAM(x) (0x90+(x)) /* 0-6*/
+#define D0F0_REMAPBASE 0x98
+#define D0F0_REMAPLIMIT 0x9a
+#define D0F0_SMRAM 0x9d
+#define D0F0_ESMRAMC 0x9e
+#define D0F0_TOM 0xa0
+#define D0F0_TOUUD 0xa2
+#define D0F0_TOLUD 0xb0
+#define D0F0_GBSM 0xa4
+#define D0F0_BGSM 0xa8
+#define D0F0_SKPD 0xdc /* Scratchpad Data */
+#define D0F0_CAPID0 0xe0
+
+/*
+ * D1:F0 PEG
+ */
+#define PEG_CAP 0xa2
+#define SLOTCAP 0xb4
+#define PEGLC 0xec
+#define D1F0_VCCAP 0x104
+#define D1F0_VC0RCTL 0x114
+
+/*
+ * Graphics frequencies
+ */
+#define GCFGC_PCIDEV		PCI_DEV(0, 2, 0)
+#define GCFGC_OFFSET		0xf0
+#define GCFGC_CR_SHIFT		0
+#define GCFGC_CR_MASK		(0xf << GCFGC_CR_SHIFT)
+#define GCFGC_CS_SHIFT		8
+#define GCFGC_CS_MASK		(0xf << GCFGC_CS_SHIFT)
+#define GCFGC_CD_SHIFT		12
+#define GCFGC_CD_MASK		(0x1 << GCFGC_CD_SHIFT)
+#define GCFGC_UPDATE_SHIFT	5
+#define GCFGC_UPDATE		(0x1 << GCFGC_UPDATE_SHIFT)
+
+/*
+ * MCHBAR
+ */
+
+#define MCHBAR8(x) *((volatile u8 *)(DEFAULT_MCHBAR + x))
+#define MCHBAR16(x) *((volatile u16 *)(DEFAULT_MCHBAR + x))
+#define MCHBAR32(x) *((volatile u32 *)(DEFAULT_MCHBAR + x))
+
+#define PMSTS_MCHBAR		0x0f14	/* Self refresh channel status */
+#define PMSTS_WARM_RESET	(1 << 1)
+#define PMSTS_BOTH_SELFREFRESH	(1 << 0)
+
+#define CLKCFG_MCHBAR		0x0c00
+#define CLKCFG_FSBCLK_SHIFT	0
+#define CLKCFG_FSBCLK_MASK	(7 << CLKCFG_FSBCLK_SHIFT)
+#define CLKCFG_MEMCLK_SHIFT	4
+#define CLKCFG_MEMCLK_MASK	(7 << CLKCFG_MEMCLK_SHIFT)
+#define CLKCFG_UPDATE		(1 << 12)
+
+#define SSKPD_MCHBAR		0x0c1c
+#define SSKPD_CLK_SHIFT		0
+#define SSKPD_CLK_MASK		(7 << SSKPD_CLK_SHIFT)
+
+#define DCC_MCHBAR		0x200
+#define DCC_NO_CHANXOR		(1 << 10)
+#define DCC_INTERLEAVED		(1 <<  1)
+#define DCC_CMD_SHIFT		16
+#define DCC_CMD_MASK		(7 << DCC_CMD_SHIFT)
+#define DCC_CMD_NOP		(1 << DCC_CMD_SHIFT)
+				/* For mode register mr0: */
+#define DCC_SET_MREG		(3 << DCC_CMD_SHIFT)
+				/* For extended mode registers mr1 to mr3: */
+#define DCC_SET_EREG		(4 << DCC_CMD_SHIFT)
+#define DCC_SET_EREG_SHIFT	21
+#define DCC_SET_EREG_MASK	(DCC_CMD_MASK | (3 << DCC_SET_EREG_SHIFT))
+#define DCC_SET_EREGx(x)	((DCC_SET_EREG |			   \
+					((x - 1) << DCC_SET_EREG_SHIFT)) & \
+				 DCC_SET_EREG_MASK)
+
+/* Per channel DRAM Row Attribute registers (32-bit) */
+#define CxDRA_MCHBAR(x)		(0x1208 + (x * 0x0100))
+#define CxDRA_PAGESIZE_SHIFT(r)	(r * 4)		/* Per rank r */
+#define CxDRA_PAGESIZE_MASKr(r)	(0x7 << CxDRA_PAGESIZE_SHIFT(r))
+#define CxDRA_PAGESIZE_MASK	0x0000ffff
+#define CxDRA_PAGESIZE(r, p)	/* for log2(dimm page size in bytes) p */ \
+	(((p - 10) << CxDRA_PAGESIZE_SHIFT(r)) & CxDRA_PAGESIZE_MASKr(r))
+#define CxDRA_BANKS_SHIFT(r)	((r * 3) + 16)
+#define CxDRA_BANKS_MASKr(r)	(0x3 << CxDRA_BANKS_SHIFT(r))
+#define CxDRA_BANKS_MASK	0x07ff0000
+#define CxDRA_BANKS(r, b)	/* for number of banks b */ \
+	((b << (CxDRA_BANKS_SHIFT(r) - 3)) & CxDRA_BANKS_MASKr(r))
+
+/*
+ * Per channel DRAM Row Boundary registers (32-bit)
+ * Every two ranks share one register and must be programmed at the same time.
+ * All registers (4 ranks per channel) have to be set.
+ */
+#define CxDRBy_MCHBAR(x, r)	(0x1200 + (x * 0x0100) + ((r/2) * 4))
+#define CxDRBy_BOUND_SHIFT(r)	((r % 2) * 16)
+#define CxDRBy_BOUND_MASK(r)	(0x1fc << CxDRBy_BOUND_SHIFT(r))
+#define CxDRBy_BOUND_MB(r, b)	/* for boundary in MB b */ \
+	(((b >> 5) << CxDRBy_BOUND_SHIFT(r)) & CxDRBy_BOUND_MASK(r))
+
+#define CxDRC0_MCHBAR(x)	(0x1230 + (x * 0x0100))
+#define CxDRC0_RANKEN0		(1 << 24)	/* Rank Enable */
+#define CxDRC0_RANKEN1		(1 << 25)
+#define CxDRC0_RANKEN2		(1 << 26)
+#define CxDRC0_RANKEN3		(1 << 27)
+#define CxDRC0_RANKEN(r)	(1 << (24 + r))
+#define CxDRC0_RANKEN_MASK	(0xf << 24)
+#define CxDRC0_RMS_SHIFT	8		/* Refresh Mode Select */
+#define CxDRC0_RMS_MASK		(7 << CxDRC0_RMS_SHIFT)
+#define CxDRC0_RMS_78US		(2 << CxDRC0_RMS_SHIFT)
+#define CxDRC0_RMS_39US		(3 << CxDRC0_RMS_SHIFT)
+
+#define CxDRC1_MCHBAR(x)	(0x1234 + (x * 0x0100))
+#define CxDRC1_SSDS_SHIFT	24
+#define CxDRC1_SSDS_MASK	(0xff << CxDRC1_SSDS_SHIFT)
+#define CxDRC1_DS		(0x91 << CxDRC1_SSDS_SHIFT)
+#define CxDRC1_SS		(0xb1 << CxDRC1_SSDS_SHIFT)
+#define CxDRC1_NOTPOP(r)	(1 << (16 + r)) /* Write 1 for Not Populated */
+#define CxDRC1_NOTPOP_MASK	(0xf << 16)
+#define CxDRC1_MUSTWR		(3 << 11)
+
+#define CxDRC2_MCHBAR(x)	(0x1238 + (x * 0x0100))
+#define CxDRC2_NOTPOP(r)	(1 << (24 + r)) /* Write 1 for Not Populated */
+#define CxDRC2_NOTPOP_MASK	(0xf << 24)
+#define CxDRC2_MUSTWR		(1 << 12)
+#define CxDRC2_CLK1067MT	(1 << 0)
+
+/* DRAM Timing registers (32-bit each) */
+#define CxDRT0_MCHBAR(x)	(0x1210 + (x * 0x0100))
+#define CxDRT0_BtB_WtP_SHIFT	26
+#define CxDRT0_BtB_WtP_MASK	(0x1f << CxDRT0_BtB_WtP_SHIFT)
+#define CxDRT0_BtB_WtR_SHIFT	20
+#define CxDRT0_BtB_WtR_MASK	(0x1f << CxDRT0_BtB_WtR_SHIFT)
+#define CxDRT1_MCHBAR(x)	(0x1214 + (x * 0x0100))
+#define CxDRT2_MCHBAR(x)	(0x1218 + (x * 0x0100))
+#define CxDRT3_MCHBAR(x)	(0x121c + (x * 0x0100))
+#define CxDRT4_MCHBAR(x)	(0x1220 + (x * 0x0100))
+#define CxDRT5_MCHBAR(x)	(0x1224 + (x * 0x0100))
+#define CxDRT6_MCHBAR(x)	(0x1228 + (x * 0x0100))
+
+/* Clock disable registers (32-bit each) */
+#define CxDCLKDIS_MCHBAR(x)	(0x120c + (x * 0x0100))
+#define CxDCLKDIS_MASK		3
+#define CxDCLKDIS_ENABLE	3 /* Always enable both clock pairs. */
+
+/* On-Die-Termination registers (2x 32-bit per channel) */
+#define CxODT_HIGH(x)		(0x124c + (x * 0x0100))
+#define CxODT_LOW(x)		(0x1248 + (x * 0x0100))
+
+/* Write Training registers. */
+#define CxWRTy_MCHBAR(ch, s)	(0x1470 + (ch * 0x0100) + ((3 - s) * 4))
+
+#define CxGTEW(x)		(0x1270+(x*0x100))
+#define CxGTC(x)		(0x1274+(x*0x100))
+#define CxDTPEW(x)		(0x1278+(x*0x100))
+#define CxDTAEW(x)		(0x1280+(x*0x100))
+#define CxDTC(x)		(0x1288+(x*0x100))
+
+
+/*
+ * DMIBAR
+ */
+
+#define DMIBAR8(x) *((volatile u8 *)(DEFAULT_DMIBAR + x))
+#define DMIBAR16(x) *((volatile u16 *)(DEFAULT_DMIBAR + x))
+#define DMIBAR32(x) *((volatile u32 *)(DEFAULT_DMIBAR + x))
+
+#define DMIVC0RCTL 0x14
+#define DMIVC1RCTL 0x20
+#define DMIVC1RSTS 0x26
+#define DMIESD  0x44
+#define DMILE1D 0x50
+#define DMILE1A 0x58
+#define DMILE2D 0x60
+#define DMILE2A 0x68
+
+
+/*
+ * EPBAR
+ */
+
+#define EPBAR8(x) *((volatile u8 *)(DEFAULT_EPBAR + x))
+#define EPBAR16(x) *((volatile u16 *)(DEFAULT_EPBAR + x))
+#define EPBAR32(x) *((volatile u32 *)(DEFAULT_EPBAR + x))
+
+#define EPESD 0x44
+#define EPLE1D 0x50
+#define EPLE1A 0x58
+#define EPLE2D 0x60
+
+
+#ifndef __ACPI__
+void x4x_early_init(void);
+/*
+void gm45_early_reset(void);
+
+void enter_raminit_or_reset(void);
+void get_gmch_info(sysinfo_t *);
+void raminit(sysinfo_t *, int s3resume);
+void raminit_thermal(const sysinfo_t *);
+void init_pm(const sysinfo_t *, int do_freq_scaling_cfg);
+u32 raminit_get_rank_addr(unsigned int channel, unsigned int rank);
+
+void raminit_rcomp_calibration(stepping_t stepping);
+void raminit_reset_readwrite_pointers(void);
+void raminit_receive_enable_calibration(const timings_t *, const dimminfo_t *);
+void raminit_write_training(const mem_clock_t, const dimminfo_t *, int s3resume);
+void raminit_read_training(const dimminfo_t *, int s3resume);
+
+void gm45_late_init(stepping_t);
+void init_iommu(void);
+*/
+u32 decode_igd_memory_size(u32 gms);
+u32 decode_igd_gtt_size(u32 gsm);
+void init_igd(const sysinfo_t *const);
+void igd_compute_ggc(sysinfo_t *const sysinfo);
+int raminit_read_vco_index(void);
+
+
+#if ENV_RAMSTAGE
+#include <device/device.h>
+
+struct acpi_rsdp;
+unsigned long northbridge_write_acpi_tables(device_t device, unsigned long start, struct acpi_rsdp *rsdp);
+#endif
+
+
+#endif /* !__ACPI__ */
+#endif



More information about the coreboot-gerrit mailing list