Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2013 Google, Inc. |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 5 | * Copyright (C) 2015 Intel Corp. |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 6 | * |
| 7 | * This program is free software; you can redistribute it and/or modify |
| 8 | * it under the terms of the GNU General Public License as published by |
| 9 | * the Free Software Foundation; version 2 of the License. |
| 10 | * |
| 11 | * This program is distributed in the hope that it will be useful, |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 12 | * but WITHOUT ANY WARRANTY; without even the implied wacbmem_entryanty of |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 13 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 14 | * GNU General Public License for more details. |
| 15 | * |
| 16 | * You should have received a copy of the GNU General Public License |
| 17 | * along with this program; if not, write to the Free Software |
Patrick Georgi | 25509ee | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 18 | * Foundation, Inc. |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 19 | */ |
| 20 | |
| 21 | #include <arch/io.h> |
| 22 | #include <cbmem.h> |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 23 | #include <console/console.h> |
| 24 | #include <soc/intel/common/memmap.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 25 | #include <soc/iosf.h> |
| 26 | #include <soc/smm.h> |
| 27 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 28 | static size_t smm_region_size(void) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 29 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 30 | u32 smm_size; |
| 31 | smm_size = iosf_bunit_read(BUNIT_SMRRH) & 0xFFFF; |
| 32 | smm_size -= iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF; |
| 33 | smm_size = (smm_size + 1) << 20; |
| 34 | return smm_size; |
| 35 | } |
| 36 | |
| 37 | void smm_region(void **start, size_t *size) |
| 38 | { |
| 39 | *start = (void *)((iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF) << 20); |
| 40 | *size = smm_region_size(); |
| 41 | } |
| 42 | |
| 43 | size_t mmap_region_granluarity(void) |
| 44 | { |
| 45 | /* Align to TSEG size when SMM is in use, and 8MiB by default */ |
| 46 | return IS_ENABLED(CONFIG_HAVE_SMI_HANDLER) ? smm_region_size() |
| 47 | : 8 << 20; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 48 | } |
| 49 | |
| 50 | void *cbmem_top(void) |
| 51 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 52 | char *smm_base; |
| 53 | size_t smm_size; |
| 54 | |
| 55 | /* |
| 56 | * +-------------------------+ Top of RAM (aligned) |
| 57 | * | System Management Mode | |
| 58 | * | code and data | Length: CONFIG_TSEG_SIZE |
| 59 | * | (TSEG) | |
| 60 | * +-------------------------+ SMM base (aligned) |
| 61 | * | | |
| 62 | * | Chipset Reserved Memory | Length: Multiple of CONFIG_TSEG_SIZE |
| 63 | * | | |
| 64 | * +-------------------------+ top_of_ram (aligned) |
| 65 | * | | |
| 66 | * | CBMEM Root | |
| 67 | * | | |
| 68 | * +-------------------------+ |
| 69 | * | | |
| 70 | * | FSP Reserved Memory | |
| 71 | * | | |
| 72 | * +-------------------------+ |
| 73 | * | | |
| 74 | * | Various CBMEM Entries | |
| 75 | * | | |
| 76 | * +-------------------------+ top_of_stack (8 byte aligned) |
| 77 | * | | |
| 78 | * | stack (CBMEM Entry) | |
| 79 | * | | |
| 80 | * +-------------------------+ |
| 81 | */ |
| 82 | |
| 83 | smm_region((void **)&smm_base, &smm_size); |
Aaron Durbin | bbbfbf2 | 2015-07-13 16:55:28 -0500 | [diff] [blame^] | 84 | return (void *)smm_base; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 85 | } |