blob: a69a5cb11692e5e745ac7a2ae66e38d37414b05d [file] [log] [blame]
Andrey Petrov491c0162016-03-02 15:09:27 -08001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2015 Intel Corp.
5 * (Written by Andrey Petrov <andrey.petrov@intel.com> for Intel Corp.)
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; either version 2 of the License, or
10 * (at your option) any later version.
Martin Rothebabfad2016-04-10 11:09:16 -060011 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
Andrey Petrov491c0162016-03-02 15:09:27 -080016 */
17
Brandon Breitenstein135eae92016-09-30 13:57:12 -070018#include <assert.h>
Andrey Petrov491c0162016-03-02 15:09:27 -080019#include <cbmem.h>
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -070020#include "chip.h"
Andrey Petrov491c0162016-03-02 15:09:27 -080021#include <device/pci.h>
Brandon Breitensteina86d1b82017-06-08 17:32:02 -070022#include <fsp/memmap.h>
Subrata Banikce90c782017-08-30 16:53:20 +053023#include <intelblocks/smm.h>
Subrata Banik7952e282017-03-14 18:26:27 +053024#include <soc/systemagent.h>
Andrey Petrov491c0162016-03-02 15:09:27 -080025#include <soc/pci_devs.h>
26
Andrey Petrov491c0162016-03-02 15:09:27 -080027void *cbmem_top(void)
28{
Pratik Prajapati4bc6edf2017-08-29 14:11:16 -070029 const struct device *dev;
30 const config_t *config;
31 void *tolum = (void *)sa_get_tseg_base();
32
33 if (!IS_ENABLED(CONFIG_SOC_INTEL_GLK))
34 return tolum;
35
36 dev = dev_find_slot(0, PCH_DEVFN_LPC);
37 assert(dev != NULL);
38 config = dev->chip_info;
39
40 if (!config)
41 die("Failed to get chip_info\n");
42
43 /* FSP allocates 2x PRMRR Size Memory for alignment */
44 if (config->sgx_enable)
45 tolum -= config->PrmrrSize * 2;
46
47 return tolum;
Hannah Williamsd9c84ca2016-05-13 00:47:14 -070048}
Brandon Breitenstein135eae92016-09-30 13:57:12 -070049
50int smm_subregion(int sub, void **start, size_t *size)
51{
52 uintptr_t sub_base;
53 size_t sub_size;
Subrata Banikce90c782017-08-30 16:53:20 +053054 void *smm_base;
Brandon Breitenstein135eae92016-09-30 13:57:12 -070055 const size_t cache_size = CONFIG_SMM_RESERVED_SIZE;
56
Subrata Banikce90c782017-08-30 16:53:20 +053057 smm_region_info(&smm_base, &sub_size);
58 sub_base = (uintptr_t)smm_base;
Brandon Breitenstein135eae92016-09-30 13:57:12 -070059
60 assert(sub_size > CONFIG_SMM_RESERVED_SIZE);
61
62 switch (sub) {
63 case SMM_SUBREGION_HANDLER:
64 /* Handler starts at the base of TSEG. */
65 sub_size -= cache_size;
66 break;
67 case SMM_SUBREGION_CACHE:
68 /* External cache is in the middle of TSEG. */
69 sub_base += sub_size - cache_size;
70 sub_size = cache_size;
71 break;
72 default:
73 return -1;
74 }
75
76 *start = (void *)sub_base;
77 *size = sub_size;
78
79 return 0;
80}