blob: 09439f25ef6e1dc38c5f40af8188d3e87822d2ad [file] [log] [blame]
Arthur Heymans3b0eb602019-01-31 22:47:09 +01001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2010 coresystems GmbH
5 * Copyright (C) 2011 The ChromiumOS Authors. All rights reserved.
6 * Copyright (C) 2014 Vladimir Serbinenko
7 *
8 * This program is free software; you can redistribute it and/or modify
9 * it under the terms of the GNU General Public License as published by
10 * the Free Software Foundation; version 2 of the License.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17
18#include <cbmem.h>
19#include <romstage_handoff.h>
20#include <console/console.h>
21#include <arch/io.h>
Kyösti Mälkkif1b58b72019-03-01 13:43:02 +020022#include <device/pci_ops.h>
Arthur Heymans3b0eb602019-01-31 22:47:09 +010023#include <arch/acpi.h>
24#include <cpu/x86/lapic.h>
25#include <cpu/x86/bist.h>
26#include <cpu/intel/romstage.h>
27#include <northbridge/intel/gm45/gm45.h>
28#include <southbridge/intel/i82801ix/i82801ix.h>
29#include <southbridge/intel/common/gpio.h>
Elyes HAOUASa1e22b82019-03-18 22:49:36 +010030#include <string.h>
Arthur Heymans3b0eb602019-01-31 22:47:09 +010031
32#define LPC_DEV PCI_DEV(0, 0x1f, 0)
33#define MCH_DEV PCI_DEV(0, 0, 0)
34
35void __weak mb_setup_superio(void)
36{
37}
38
39void __weak mb_pre_raminit_setup(sysinfo_t *sysinfo)
40{
41}
42
43void __weak mb_post_raminit_setup(void)
44{
45}
46
47/* Platform has no romstage entry point under mainboard directory,
48 * so this one is named with prefix mainboard.
49 */
50void mainboard_romstage_entry(unsigned long bist)
51{
52 sysinfo_t sysinfo;
53 int s3resume = 0;
54 int cbmem_initted;
55 u16 reg16;
56
57 /* basic northbridge setup, including MMCONF BAR */
58 gm45_early_init();
59
60 if (bist == 0)
61 enable_lapic();
62
63 /* First, run everything needed for console output. */
64 i82801ix_early_init();
65 setup_pch_gpios(&mainboard_gpio_map);
66
67 mb_setup_lpc();
68
69 mb_setup_superio();
70
71 console_init();
72 report_bist_failure(bist);
73
74 reg16 = pci_read_config16(LPC_DEV, D31F0_GEN_PMCON_3);
75 pci_write_config16(LPC_DEV, D31F0_GEN_PMCON_3, reg16);
76 if ((MCHBAR16(SSKPD_MCHBAR) == 0xCAFE) && !(reg16 & (1 << 9))) {
77 printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n");
78 gm45_early_reset();
79 }
80
81 /* ASPM related setting, set early by original BIOS. */
82 DMIBAR16(0x204) &= ~(3 << 10);
83
84 /* Check for S3 resume. */
85 const u32 pm1_cnt = inl(DEFAULT_PMBASE + 0x04);
86 if (((pm1_cnt >> 10) & 7) == 5) {
87 if (acpi_s3_resume_allowed()) {
88 printk(BIOS_DEBUG, "Resume from S3 detected.\n");
89 s3resume = 1;
90 /* Clear SLP_TYPE. This will break stage2 but
91 * we care for that when we get there.
92 */
93 outl(pm1_cnt & ~(7 << 10), DEFAULT_PMBASE + 0x04);
94 } else {
95 printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n");
96 }
97 }
98
99 /* RAM initialization */
100 enter_raminit_or_reset();
101 memset(&sysinfo, 0, sizeof(sysinfo));
102 get_mb_spd_addrmap(sysinfo.spd_map);
103 const struct device *dev;
104 dev = pcidev_on_root(2, 0);
105 if (dev)
106 sysinfo.enable_igd = dev->enabled;
107 dev = pcidev_on_root(1, 0);
108 if (dev)
109 sysinfo.enable_peg = dev->enabled;
110 get_gmch_info(&sysinfo);
111
112 mb_pre_raminit_setup(&sysinfo);
113
114 raminit(&sysinfo, s3resume);
115
116 mb_post_raminit_setup();
117
118 const u32 deven = pci_read_config32(MCH_DEV, D0F0_DEVEN);
119 /* Disable D4F0 (unknown signal controller). */
120 pci_write_config32(MCH_DEV, D0F0_DEVEN, deven & ~0x4000);
121
122 init_pm(&sysinfo, 0);
123
124 i82801ix_dmi_setup();
125 gm45_late_init(sysinfo.stepping);
126 i82801ix_dmi_poll_vc1();
127
128 MCHBAR16(SSKPD_MCHBAR) = 0xCAFE;
129
130 init_iommu();
131
132 cbmem_initted = !cbmem_recovery(s3resume);
133
134 romstage_handoff_init(cbmem_initted && s3resume);
135
136 printk(BIOS_SPEW, "exit main()\n");
137}