Marc Jones | 81ef9c2 | 2021-01-21 10:53:47 -0700 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | |
| 3 | #include <device/mmio.h> |
Marc Jones | 4681b27 | 2021-04-06 14:29:37 -0600 | [diff] [blame] | 4 | #include <device/pci.h> |
Marc Jones | 81ef9c2 | 2021-01-21 10:53:47 -0700 | [diff] [blame] | 5 | #include <intelblocks/cfg.h> |
Jonathan Zhang | fb2ebbc | 2022-10-26 16:19:40 -0700 | [diff] [blame^] | 6 | #include <intelblocks/lpc_lib.h> |
Marc Jones | 81ef9c2 | 2021-01-21 10:53:47 -0700 | [diff] [blame] | 7 | #include <intelblocks/pmclib.h> |
| 8 | #include <intelpch/lockdown.h> |
Marc Jones | 4681b27 | 2021-04-06 14:29:37 -0600 | [diff] [blame] | 9 | #include <soc/pci_devs.h> |
Marc Jones | 81ef9c2 | 2021-01-21 10:53:47 -0700 | [diff] [blame] | 10 | #include <soc/pm.h> |
| 11 | |
Jonathan Zhang | fb2ebbc | 2022-10-26 16:19:40 -0700 | [diff] [blame^] | 12 | static void lpc_lockdown_config(void) |
| 13 | { |
| 14 | /* Set BIOS Interface Lock, BIOS Lock */ |
| 15 | lpc_set_bios_interface_lock_down(); |
| 16 | |
| 17 | /* Only allow writes in SMM */ |
| 18 | if (CONFIG(BOOTMEDIA_SMM_BWP)) { |
| 19 | lpc_set_eiss(); |
| 20 | lpc_enable_wp(); |
| 21 | } |
| 22 | lpc_set_lock_enable(); |
| 23 | } |
| 24 | |
Marc Jones | 6545145 | 2021-03-02 15:16:25 -0700 | [diff] [blame] | 25 | static void pmc_lockdown_config(int chipset_lockdown) |
Marc Jones | 81ef9c2 | 2021-01-21 10:53:47 -0700 | [diff] [blame] | 26 | { |
| 27 | uint8_t *pmcbase; |
| 28 | u32 pmsyncreg; |
| 29 | |
| 30 | /* PMSYNC */ |
| 31 | pmcbase = pmc_mmio_regs(); |
| 32 | pmsyncreg = read32(pmcbase + PMSYNC_TPR_CFG); |
| 33 | pmsyncreg |= PMSYNC_LOCK; |
| 34 | write32(pmcbase + PMSYNC_TPR_CFG, pmsyncreg); |
| 35 | |
| 36 | /* Make sure payload/OS can't trigger global reset */ |
| 37 | pmc_global_reset_disable_and_lock(); |
Marc Jones | 4681b27 | 2021-04-06 14:29:37 -0600 | [diff] [blame] | 38 | |
| 39 | /* Lock PMC stretch policy */ |
| 40 | pci_or_config32(PCH_DEV_PMC, GEN_PMCON_B, SLP_STR_POL_LOCK); |
| 41 | } |
| 42 | |
| 43 | static void sata_lockdown_config(int chipset_lockdown) |
| 44 | { |
| 45 | if (chipset_lockdown == CHIPSET_LOCKDOWN_COREBOOT) { |
| 46 | pci_or_config32(PCH_DEV_SATA, SATAGC, SATAGC_REGLOCK); |
| 47 | pci_or_config32(PCH_DEV_SSATA, SATAGC, SATAGC_REGLOCK); |
| 48 | } |
Marc Jones | 81ef9c2 | 2021-01-21 10:53:47 -0700 | [diff] [blame] | 49 | } |
| 50 | |
| 51 | void soc_lockdown_config(int chipset_lockdown) |
| 52 | { |
Jonathan Zhang | fb2ebbc | 2022-10-26 16:19:40 -0700 | [diff] [blame^] | 53 | lpc_lockdown_config(); |
Marc Jones | 6545145 | 2021-03-02 15:16:25 -0700 | [diff] [blame] | 54 | pmc_lockdown_config(chipset_lockdown); |
Marc Jones | 4681b27 | 2021-04-06 14:29:37 -0600 | [diff] [blame] | 55 | sata_lockdown_config(chipset_lockdown); |
Marc Jones | 81ef9c2 | 2021-01-21 10:53:47 -0700 | [diff] [blame] | 56 | } |