Arthur Heymans | 3b0eb60 | 2019-01-31 22:47:09 +0100 | [diff] [blame] | 1 | /* |
| 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> |
| 22 | #include <arch/acpi.h> |
| 23 | #include <cpu/x86/lapic.h> |
| 24 | #include <cpu/x86/bist.h> |
| 25 | #include <cpu/intel/romstage.h> |
| 26 | #include <northbridge/intel/gm45/gm45.h> |
| 27 | #include <southbridge/intel/i82801ix/i82801ix.h> |
| 28 | #include <southbridge/intel/common/gpio.h> |
| 29 | |
| 30 | #define LPC_DEV PCI_DEV(0, 0x1f, 0) |
| 31 | #define MCH_DEV PCI_DEV(0, 0, 0) |
| 32 | |
| 33 | void __weak mb_setup_superio(void) |
| 34 | { |
| 35 | } |
| 36 | |
| 37 | void __weak mb_pre_raminit_setup(sysinfo_t *sysinfo) |
| 38 | { |
| 39 | } |
| 40 | |
| 41 | void __weak mb_post_raminit_setup(void) |
| 42 | { |
| 43 | } |
| 44 | |
| 45 | /* Platform has no romstage entry point under mainboard directory, |
| 46 | * so this one is named with prefix mainboard. |
| 47 | */ |
| 48 | void mainboard_romstage_entry(unsigned long bist) |
| 49 | { |
| 50 | sysinfo_t sysinfo; |
| 51 | int s3resume = 0; |
| 52 | int cbmem_initted; |
| 53 | u16 reg16; |
| 54 | |
| 55 | /* basic northbridge setup, including MMCONF BAR */ |
| 56 | gm45_early_init(); |
| 57 | |
| 58 | if (bist == 0) |
| 59 | enable_lapic(); |
| 60 | |
| 61 | /* First, run everything needed for console output. */ |
| 62 | i82801ix_early_init(); |
| 63 | setup_pch_gpios(&mainboard_gpio_map); |
| 64 | |
| 65 | mb_setup_lpc(); |
| 66 | |
| 67 | mb_setup_superio(); |
| 68 | |
| 69 | console_init(); |
| 70 | report_bist_failure(bist); |
| 71 | |
| 72 | reg16 = pci_read_config16(LPC_DEV, D31F0_GEN_PMCON_3); |
| 73 | pci_write_config16(LPC_DEV, D31F0_GEN_PMCON_3, reg16); |
| 74 | if ((MCHBAR16(SSKPD_MCHBAR) == 0xCAFE) && !(reg16 & (1 << 9))) { |
| 75 | printk(BIOS_DEBUG, "soft reset detected, rebooting properly\n"); |
| 76 | gm45_early_reset(); |
| 77 | } |
| 78 | |
| 79 | /* ASPM related setting, set early by original BIOS. */ |
| 80 | DMIBAR16(0x204) &= ~(3 << 10); |
| 81 | |
| 82 | /* Check for S3 resume. */ |
| 83 | const u32 pm1_cnt = inl(DEFAULT_PMBASE + 0x04); |
| 84 | if (((pm1_cnt >> 10) & 7) == 5) { |
| 85 | if (acpi_s3_resume_allowed()) { |
| 86 | printk(BIOS_DEBUG, "Resume from S3 detected.\n"); |
| 87 | s3resume = 1; |
| 88 | /* Clear SLP_TYPE. This will break stage2 but |
| 89 | * we care for that when we get there. |
| 90 | */ |
| 91 | outl(pm1_cnt & ~(7 << 10), DEFAULT_PMBASE + 0x04); |
| 92 | } else { |
| 93 | printk(BIOS_DEBUG, "Resume from S3 detected, but disabled.\n"); |
| 94 | } |
| 95 | } |
| 96 | |
| 97 | /* RAM initialization */ |
| 98 | enter_raminit_or_reset(); |
| 99 | memset(&sysinfo, 0, sizeof(sysinfo)); |
| 100 | get_mb_spd_addrmap(sysinfo.spd_map); |
| 101 | const struct device *dev; |
| 102 | dev = pcidev_on_root(2, 0); |
| 103 | if (dev) |
| 104 | sysinfo.enable_igd = dev->enabled; |
| 105 | dev = pcidev_on_root(1, 0); |
| 106 | if (dev) |
| 107 | sysinfo.enable_peg = dev->enabled; |
| 108 | get_gmch_info(&sysinfo); |
| 109 | |
| 110 | mb_pre_raminit_setup(&sysinfo); |
| 111 | |
| 112 | raminit(&sysinfo, s3resume); |
| 113 | |
| 114 | mb_post_raminit_setup(); |
| 115 | |
| 116 | const u32 deven = pci_read_config32(MCH_DEV, D0F0_DEVEN); |
| 117 | /* Disable D4F0 (unknown signal controller). */ |
| 118 | pci_write_config32(MCH_DEV, D0F0_DEVEN, deven & ~0x4000); |
| 119 | |
| 120 | init_pm(&sysinfo, 0); |
| 121 | |
| 122 | i82801ix_dmi_setup(); |
| 123 | gm45_late_init(sysinfo.stepping); |
| 124 | i82801ix_dmi_poll_vc1(); |
| 125 | |
| 126 | MCHBAR16(SSKPD_MCHBAR) = 0xCAFE; |
| 127 | |
| 128 | init_iommu(); |
| 129 | |
| 130 | cbmem_initted = !cbmem_recovery(s3resume); |
| 131 | |
| 132 | romstage_handoff_init(cbmem_initted && s3resume); |
| 133 | |
| 134 | printk(BIOS_SPEW, "exit main()\n"); |
| 135 | } |