2015-05-13 03:19:47 +02:00
|
|
|
/*
|
|
|
|
* This file is part of the coreboot project.
|
|
|
|
*
|
|
|
|
* Copyright (C) 2014 Google Inc.
|
2015-05-13 03:23:27 +02:00
|
|
|
* Copyright (C) 2015 Intel Corporation.
|
2015-05-13 03:19:47 +02:00
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2015-05-13 03:23:27 +02:00
|
|
|
* Foundation, Inc.
|
2015-05-13 03:19:47 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <arch/io.h>
|
|
|
|
#include <cbmem.h>
|
|
|
|
#include <device/pci.h>
|
|
|
|
#include <soc/pci_devs.h>
|
2015-05-13 03:23:27 +02:00
|
|
|
#include <soc/romstage.h>
|
|
|
|
#include <soc/smm.h>
|
2015-05-13 03:19:47 +02:00
|
|
|
#include <soc/systemagent.h>
|
2015-08-05 21:33:37 +02:00
|
|
|
#include <stdlib.h>
|
2015-05-13 03:19:47 +02:00
|
|
|
|
2015-05-13 03:23:27 +02:00
|
|
|
size_t mmap_region_granluarity(void)
|
|
|
|
{
|
|
|
|
if (IS_ENABLED(CONFIG_HAVE_SMI_HANDLER))
|
|
|
|
/* Align to TSEG size when SMM is in use */
|
|
|
|
if (CONFIG_SMM_TSEG_SIZE != 0)
|
|
|
|
return CONFIG_SMM_TSEG_SIZE;
|
|
|
|
|
|
|
|
/* Make it 8MiB by default. */
|
2015-08-05 21:33:37 +02:00
|
|
|
return 8*MiB;
|
2015-05-13 03:23:27 +02:00
|
|
|
}
|
|
|
|
|
2015-08-05 21:33:37 +02:00
|
|
|
/* Returns base of requested region encoded in the system agent. */
|
|
|
|
static inline uintptr_t system_agent_region_base(size_t reg)
|
2015-05-13 03:19:47 +02:00
|
|
|
{
|
2015-08-05 21:33:37 +02:00
|
|
|
/* All regions concerned for have 1 MiB alignment. */
|
|
|
|
return ALIGN_DOWN(pci_read_config32(SA_DEV_ROOT, reg), 1*MiB);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline uintptr_t smm_region_start(void)
|
|
|
|
{
|
|
|
|
return system_agent_region_base(TSEG);
|
|
|
|
}
|
|
|
|
|
|
|
|
static inline size_t smm_region_size(void)
|
|
|
|
{
|
|
|
|
return system_agent_region_base(BGSM) - smm_region_start();
|
2015-05-13 03:23:27 +02:00
|
|
|
}
|
2015-05-13 03:19:47 +02:00
|
|
|
|
2015-05-13 03:23:27 +02:00
|
|
|
void smm_region(void **start, size_t *size)
|
|
|
|
{
|
2015-08-05 21:33:37 +02:00
|
|
|
*start = (void *)smm_region_start();
|
|
|
|
*size = smm_region_size();
|
2015-05-13 03:19:47 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
void *cbmem_top(void)
|
|
|
|
{
|
2015-05-13 03:23:27 +02:00
|
|
|
/*
|
|
|
|
* +-------------------------+ Top of RAM (aligned)
|
|
|
|
* | System Management Mode |
|
|
|
|
* | code and data | Length: CONFIG_TSEG_SIZE
|
|
|
|
* | (TSEG) |
|
|
|
|
* +-------------------------+ SMM base (aligned)
|
|
|
|
* | |
|
|
|
|
* | Chipset Reserved Memory | Length: Multiple of CONFIG_TSEG_SIZE
|
|
|
|
* | |
|
|
|
|
* +-------------------------+ top_of_ram (aligned)
|
|
|
|
* | |
|
|
|
|
* | CBMEM Root |
|
|
|
|
* | |
|
|
|
|
* +-------------------------+
|
|
|
|
* | |
|
|
|
|
* | FSP Reserved Memory |
|
|
|
|
* | |
|
|
|
|
* +-------------------------+
|
|
|
|
* | |
|
|
|
|
* | Various CBMEM Entries |
|
|
|
|
* | |
|
|
|
|
* +-------------------------+ top_of_stack (8 byte aligned)
|
|
|
|
* | |
|
|
|
|
* | stack (CBMEM Entry) |
|
|
|
|
* | |
|
|
|
|
* +-------------------------+
|
|
|
|
*/
|
|
|
|
|
2015-08-05 21:33:37 +02:00
|
|
|
uintptr_t top_of_ram = smm_region_start();
|
2015-05-13 03:23:27 +02:00
|
|
|
|
|
|
|
/*
|
|
|
|
* Subtract DMA Protected Range size if enabled and align to a multiple
|
|
|
|
* of TSEG size.
|
|
|
|
*/
|
|
|
|
u32 dpr = pci_read_config32(SA_DEV_ROOT, DPR);
|
|
|
|
if (dpr & DPR_EPM) {
|
|
|
|
top_of_ram -= (dpr & DPR_SIZE_MASK) << 16;
|
|
|
|
top_of_ram = ALIGN_DOWN(top_of_ram, mmap_region_granluarity());
|
|
|
|
}
|
|
|
|
|
2015-07-13 23:55:28 +02:00
|
|
|
return (void *)top_of_ram;
|
2015-05-13 03:19:47 +02:00
|
|
|
}
|
2015-05-13 03:23:27 +02:00
|
|
|
|