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 | e0918bb | 2016-01-29 14:28:43 -0800 | [diff] [blame] | 5 | * Copyright (C) 2015-2016 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 | e0918bb | 2016-01-29 14:28:43 -0800 | [diff] [blame] | 12 | * but WITHOUT ANY WARRANTY; without even the implied warranty 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. |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 15 | */ |
| 16 | |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 17 | #include <cbmem.h> |
Kyösti Mälkki | b2a5f0b | 2019-08-04 19:54:32 +0300 | [diff] [blame] | 18 | #include <cpu/x86/smm.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 19 | #include <soc/iosf.h> |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 20 | |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 21 | static size_t smm_region_size(void) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 22 | { |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 23 | u32 smm_size; |
| 24 | smm_size = iosf_bunit_read(BUNIT_SMRRH) & 0xFFFF; |
| 25 | smm_size -= iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF; |
| 26 | smm_size = (smm_size + 1) << 20; |
| 27 | return smm_size; |
| 28 | } |
| 29 | |
Kyösti Mälkki | 14222d8 | 2019-08-05 15:10:18 +0300 | [diff] [blame] | 30 | void smm_region(uintptr_t *start, size_t *size) |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 31 | { |
Kyösti Mälkki | 14222d8 | 2019-08-05 15:10:18 +0300 | [diff] [blame] | 32 | *start = (iosf_bunit_read(BUNIT_SMRRL) & 0xFFFF) << 20; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 33 | *size = smm_region_size(); |
| 34 | } |
| 35 | |
Arthur Heymans | 340e4b8 | 2019-10-23 17:25:58 +0200 | [diff] [blame^] | 36 | void *cbmem_top_chipset(void) |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 37 | { |
Kyösti Mälkki | 14222d8 | 2019-08-05 15:10:18 +0300 | [diff] [blame] | 38 | uintptr_t smm_base; |
Lee Leahy | 3247172 | 2015-04-20 15:20:28 -0700 | [diff] [blame] | 39 | size_t smm_size; |
| 40 | |
| 41 | /* |
| 42 | * +-------------------------+ Top of RAM (aligned) |
| 43 | * | System Management Mode | |
| 44 | * | code and data | Length: CONFIG_TSEG_SIZE |
| 45 | * | (TSEG) | |
| 46 | * +-------------------------+ SMM base (aligned) |
| 47 | * | | |
| 48 | * | Chipset Reserved Memory | Length: Multiple of CONFIG_TSEG_SIZE |
| 49 | * | | |
| 50 | * +-------------------------+ top_of_ram (aligned) |
| 51 | * | | |
| 52 | * | CBMEM Root | |
| 53 | * | | |
| 54 | * +-------------------------+ |
| 55 | * | | |
| 56 | * | FSP Reserved Memory | |
| 57 | * | | |
| 58 | * +-------------------------+ |
| 59 | * | | |
| 60 | * | Various CBMEM Entries | |
| 61 | * | | |
| 62 | * +-------------------------+ top_of_stack (8 byte aligned) |
| 63 | * | | |
| 64 | * | stack (CBMEM Entry) | |
| 65 | * | | |
| 66 | * +-------------------------+ |
| 67 | */ |
| 68 | |
Kyösti Mälkki | 14222d8 | 2019-08-05 15:10:18 +0300 | [diff] [blame] | 69 | smm_region(&smm_base, &smm_size); |
Aaron Durbin | bbbfbf2 | 2015-07-13 16:55:28 -0500 | [diff] [blame] | 70 | return (void *)smm_base; |
Lee Leahy | 77ff0b1 | 2015-05-05 15:07:29 -0700 | [diff] [blame] | 71 | } |