blob: 5a4cd4dbab782d76e350d7a7bc4ae6892e8b6063 [file] [log] [blame]
Felix Helddba32292020-03-31 23:54:44 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
3
4#include <console/console.h>
5#include <device/pci_ops.h>
6#include <device/pci_def.h>
7#include <cpu/x86/msr.h>
8#include <soc/pci_devs.h>
9#include <soc/northbridge.h>
10#include <soc/southbridge.h>
11#include <amdblocks/psp.h>
12
13void soc_enable_psp_early(void)
14{
Elyes HAOUASb30d0542020-04-28 09:42:47 +020015 u32 base, limit;
16 u16 cmd;
Felix Helddba32292020-03-31 23:54:44 +020017
18 /* Open a posted hole from 0x80000000 : 0xfed00000-1 */
19 base = (0x80000000 >> 8) | MMIO_WE | MMIO_RE;
20 limit = (ALIGN_DOWN(HPET_BASE_ADDRESS - 1, 64 * KiB) >> 8);
21 pci_write_config32(SOC_ADDR_DEV, D18F1_MMIO_LIMIT0_LO, limit);
22 pci_write_config32(SOC_ADDR_DEV, D18F1_MMIO_BASE0_LO, base);
23
24 /* Preload a value into BAR and enable it */
25 pci_write_config32(SOC_PSP_DEV, PSP_MAILBOX_BAR, PSP_MAILBOX_BAR3_BASE);
26 pci_write_config32(SOC_PSP_DEV, PSP_BAR_ENABLES, PSP_MAILBOX_BAR_EN);
27
28 /* Enable memory access and master */
Elyes HAOUASb30d0542020-04-28 09:42:47 +020029 cmd = pci_read_config16(SOC_PSP_DEV, PCI_COMMAND);
Felix Helddba32292020-03-31 23:54:44 +020030 cmd |= PCI_COMMAND_MEMORY | PCI_COMMAND_MASTER;
Elyes HAOUASb30d0542020-04-28 09:42:47 +020031 pci_write_config16(SOC_PSP_DEV, PCI_COMMAND, cmd);
Felix Helddba32292020-03-31 23:54:44 +020032};
33
Marshall Dawsond6b72362020-03-05 11:44:24 -070034void *soc_get_mbox_address(void)
Felix Helddba32292020-03-31 23:54:44 +020035{
36 uintptr_t psp_mmio;
37
38 /* Check for presence of the PSP */
39 if (pci_read_config32(SOC_PSP_DEV, PCI_VENDOR_ID) == 0xffffffff) {
40 printk(BIOS_WARNING, "PSP: No SOC_PSP_DEV found at D%xF%x\n",
41 PSP_DEV, PSP_FUNC);
42 return 0;
43 }
44
45 /* Determine if Bar3Hide has been set, and if hidden get the base from
46 * the MSR instead. */
47 if (pci_read_config32(SOC_PSP_DEV, PSP_BAR_ENABLES) & BAR3HIDE) {
48 psp_mmio = rdmsr(MSR_CU_CBBCFG).lo;
49 if (psp_mmio == 0xffffffff) {
50 printk(BIOS_WARNING, "PSP: BAR hidden, MSR val uninitialized\n");
51 return 0;
52 }
53 } else {
54 psp_mmio = pci_read_config32(SOC_PSP_DEV, PCI_BASE_ADDRESS_4) &
55 ~PCI_BASE_ADDRESS_MEM_ATTR_MASK;
56 }
57
Marshall Dawsond6b72362020-03-05 11:44:24 -070058 return (void *)(psp_mmio + PSP_MAILBOX_OFFSET);
Felix Helddba32292020-03-31 23:54:44 +020059}