Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2014 Google Inc. |
| 5 | * |
| 6 | * This program is free software; you can redistribute it and/or modify |
| 7 | * it under the terms of the GNU General Public License as published by |
| 8 | * the Free Software Foundation; version 2 of the License. |
| 9 | * |
| 10 | * This program is distributed in the hope that it will be useful, |
| 11 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | * GNU General Public License for more details. |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #include <arch/io.h> |
| 17 | #include <bootstate.h> |
| 18 | #include <console/console.h> |
| 19 | #include <console/post_codes.h> |
| 20 | #include <cpu/x86/smm.h> |
| 21 | #include <reg_script.h> |
| 22 | #include <spi-generic.h> |
| 23 | #include <stdlib.h> |
Julius Werner | 4ee4bd5 | 2014-10-20 13:46:39 -0700 | [diff] [blame] | 24 | #include <soc/pci_devs.h> |
| 25 | #include <soc/lpc.h> |
| 26 | #include <soc/me.h> |
| 27 | #include <soc/rcba.h> |
| 28 | #include <soc/spi.h> |
| 29 | #include <soc/systemagent.h> |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 30 | |
| 31 | const struct reg_script system_agent_finalize_script[] = { |
| 32 | REG_PCI_OR16(0x50, 1 << 0), /* GGC */ |
| 33 | REG_PCI_OR32(0x5c, 1 << 0), /* DPR */ |
| 34 | REG_PCI_OR32(0x78, 1 << 10), /* ME */ |
| 35 | REG_PCI_OR32(0x90, 1 << 0), /* REMAPBASE */ |
| 36 | REG_PCI_OR32(0x98, 1 << 0), /* REMAPLIMIT */ |
| 37 | REG_PCI_OR32(0xa0, 1 << 0), /* TOM */ |
| 38 | REG_PCI_OR32(0xa8, 1 << 0), /* TOUUD */ |
| 39 | REG_PCI_OR32(0xb0, 1 << 0), /* BDSM */ |
| 40 | REG_PCI_OR32(0xb4, 1 << 0), /* BGSM */ |
| 41 | REG_PCI_OR32(0xb8, 1 << 0), /* TSEGMB */ |
| 42 | REG_PCI_OR32(0xbc, 1 << 0), /* TOLUD */ |
| 43 | REG_MMIO_OR32(MCH_BASE_ADDRESS + 0x5500, 1 << 0), /* PAVP */ |
| 44 | REG_MMIO_OR32(MCH_BASE_ADDRESS + 0x5f00, 1 << 31), /* SA PM */ |
| 45 | REG_MMIO_OR32(MCH_BASE_ADDRESS + 0x6020, 1 << 0), /* UMA GFX */ |
| 46 | REG_MMIO_OR32(MCH_BASE_ADDRESS + 0x63fc, 1 << 0), /* VTDTRK */ |
| 47 | REG_MMIO_OR32(MCH_BASE_ADDRESS + 0x6800, 1 << 31), |
| 48 | REG_MMIO_OR32(MCH_BASE_ADDRESS + 0x7000, 1 << 31), |
| 49 | REG_MMIO_OR32(MCH_BASE_ADDRESS + 0x77fc, 1 << 0), |
Duncan Laurie | 88bbf16 | 2015-01-09 13:23:05 -0800 | [diff] [blame] | 50 | REG_MMIO_OR32(MCH_BASE_ADDRESS + 0x50fc, 0x8f), |
| 51 | REG_MMIO_OR32(MCH_BASE_ADDRESS + 0x7ffc, 1 << 0), |
| 52 | REG_MMIO_OR32(MCH_BASE_ADDRESS + 0x5880, 1 << 5), |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 53 | REG_MMIO_WRITE8(MCH_BASE_ADDRESS + 0x50fc, 0x8f), /* MC */ |
| 54 | |
| 55 | REG_SCRIPT_END |
| 56 | }; |
| 57 | |
| 58 | const struct reg_script pch_finalize_script[] = { |
Duncan Laurie | 9d08c4a | 2015-12-22 17:08:21 -0800 | [diff] [blame] | 59 | #if !IS_ENABLED(CONFIG_SPI_CONSOLE) |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 60 | /* Set SPI opcode menu */ |
| 61 | REG_MMIO_WRITE16(RCBA_BASE_ADDRESS + SPIBAR_OFFSET + SPIBAR_PREOP, |
| 62 | SPI_OPPREFIX), |
| 63 | REG_MMIO_WRITE16(RCBA_BASE_ADDRESS + SPIBAR_OFFSET + SPIBAR_OPTYPE, |
| 64 | SPI_OPTYPE), |
| 65 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + SPIBAR_OFFSET + |
| 66 | SPIBAR_OPMENU_LOWER, SPI_OPMENU_LOWER), |
| 67 | REG_MMIO_WRITE32(RCBA_BASE_ADDRESS + SPIBAR_OFFSET + |
| 68 | SPIBAR_OPMENU_UPPER, SPI_OPMENU_UPPER), |
| 69 | |
| 70 | /* Lock SPIBAR */ |
| 71 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + SPIBAR_OFFSET + SPIBAR_HSFS, |
| 72 | SPIBAR_HSFS_FLOCKDN), |
Duncan Laurie | 9d08c4a | 2015-12-22 17:08:21 -0800 | [diff] [blame] | 73 | #endif |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 74 | |
| 75 | /* TC Lockdown */ |
| 76 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + 0x0050, (1 << 31)), |
| 77 | |
| 78 | /* BIOS Interface Lockdown */ |
| 79 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + GCS, (1 << 0)), |
| 80 | |
| 81 | /* Function Disable SUS Well Lockdown */ |
| 82 | REG_MMIO_OR8(RCBA_BASE_ADDRESS + FDSW, (1 << 7)), |
| 83 | |
| 84 | /* Global SMI Lock */ |
| 85 | REG_PCI_OR16(GEN_PMCON_1, SMI_LOCK), |
| 86 | |
| 87 | /* GEN_PMCON Lock */ |
| 88 | REG_PCI_OR8(GEN_PMCON_LOCK, SLP_STR_POL_LOCK | ACPI_BASE_LOCK), |
| 89 | |
| 90 | /* PMSYNC */ |
| 91 | REG_MMIO_OR32(RCBA_BASE_ADDRESS + PMSYNC_CONFIG, (1 << 31)), |
| 92 | |
| 93 | |
| 94 | REG_SCRIPT_END |
| 95 | }; |
| 96 | |
| 97 | static void broadwell_finalize(void *unused) |
| 98 | { |
| 99 | printk(BIOS_DEBUG, "Finalizing chipset.\n"); |
| 100 | |
| 101 | reg_script_run_on_dev(SA_DEV_ROOT, system_agent_finalize_script); |
| 102 | reg_script_run_on_dev(PCH_DEV_LPC, pch_finalize_script); |
| 103 | |
Kane Chen | 472d0cb | 2014-08-21 10:36:17 -0700 | [diff] [blame] | 104 | /* Lock */ |
| 105 | RCBA32_OR(0x3a6c, 0x00000001); |
| 106 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 107 | /* Read+Write the following registers */ |
| 108 | MCHBAR32(0x6030) = MCHBAR32(0x6030); |
| 109 | MCHBAR32(0x6034) = MCHBAR32(0x6034); |
| 110 | MCHBAR32(0x6008) = MCHBAR32(0x6008); |
| 111 | RCBA32(0x21a4) = RCBA32(0x21a4); |
| 112 | |
| 113 | /* Re-init SPI after lockdown */ |
| 114 | spi_init(); |
| 115 | |
Duncan Laurie | c88c54c | 2014-04-30 16:36:13 -0700 | [diff] [blame] | 116 | printk(BIOS_DEBUG, "Finalizing SMM.\n"); |
| 117 | outb(APM_CNT_FINALIZE, APM_CNT); |
| 118 | |
| 119 | /* Indicate finalize step with post code */ |
| 120 | post_code(POST_OS_BOOT); |
| 121 | } |
| 122 | |
Aaron Durbin | 9ef9d85 | 2015-03-16 17:30:09 -0500 | [diff] [blame] | 123 | BOOT_STATE_INIT_ENTRY(BS_OS_RESUME, BS_ON_ENTRY, broadwell_finalize, NULL); |
| 124 | BOOT_STATE_INIT_ENTRY(BS_PAYLOAD_LOAD, BS_ON_EXIT, broadwell_finalize, NULL); |