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 | |
Aaron Durbin | c43d417 | 2015-08-05 14:51:48 -0500 | [diff] [blame^] | 50 | /* |
| 51 | * Subregions within SMM |
| 52 | * +-------------------------+ BUNIT_SMRRH |
| 53 | * | External Stage Cache | SMM_RESERVED_SIZE |
| 54 | * +-------------------------+ |
| 55 | * | code and data | |
| 56 | * | (TSEG) | |
| 57 | * +-------------------------+ BUNIT_SMRRL |
| 58 | */ |
| 59 | int smm_subregion(int sub, void **start, size_t *size) |
| 60 | { |
| 61 | uintptr_t sub_base; |
| 62 | void *sub_ptr; |
| 63 | size_t sub_size; |
| 64 | const size_t cache_size = CONFIG_SMM_RESERVED_SIZE; |
| 65 | |
| 66 | smm_region(&sub_ptr, &sub_size); |
| 67 | sub_base = (uintptr_t)sub_ptr; |
| 68 | |
| 69 | switch (sub) { |
| 70 | case SMM_SUBREGION_HANDLER: |
| 71 | /* Handler starts at the base of TSEG. */ |
| 72 | sub_size -= cache_size; |
| 73 | break; |
| 74 | case SMM_SUBREGION_CACHE: |
| 75 | /* External cache is in the middle of TSEG. */ |
| 76 | sub_base += sub_size - cache_size; |
| 77 | sub_size = cache_size; |
| 78 | break; |
| 79 | default: |
| 80 | return -1; |
| 81 | } |
| 82 | |
| 83 | *start = (void *)sub_base; |
| 84 | *size = sub_size; |
| 85 | |
| 86 | return 0; |
| 87 | } |
| 88 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 89 | void *cbmem_top(void) |
| 90 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 91 | char *smm_base; |
| 92 | size_t smm_size; |
| 93 | |
| 94 | /* |
| 95 | * +-------------------------+ Top of RAM (aligned) |
| 96 | * | System Management Mode | |
| 97 | * | code and data | Length: CONFIG_TSEG_SIZE |
| 98 | * | (TSEG) | |
| 99 | * +-------------------------+ SMM base (aligned) |
| 100 | * | | |
| 101 | * | Chipset Reserved Memory | Length: Multiple of CONFIG_TSEG_SIZE |
| 102 | * | | |
| 103 | * +-------------------------+ top_of_ram (aligned) |
| 104 | * | | |
| 105 | * | CBMEM Root | |
| 106 | * | | |
| 107 | * +-------------------------+ |
| 108 | * | | |
| 109 | * | FSP Reserved Memory | |
| 110 | * | | |
| 111 | * +-------------------------+ |
| 112 | * | | |
| 113 | * | Various CBMEM Entries | |
| 114 | * | | |
| 115 | * +-------------------------+ top_of_stack (8 byte aligned) |
| 116 | * | | |
| 117 | * | stack (CBMEM Entry) | |
| 118 | * | | |
| 119 | * +-------------------------+ |
| 120 | */ |
| 121 | |
| 122 | smm_region((void **)&smm_base, &smm_size); |
Aaron Durbin | bbbfbf2 | 2015-07-13 16:55:28 -0500 | [diff] [blame] | 123 | return (void *)smm_base; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 124 | } |