Andrey Petrov | 491c016 | 2016-03-02 15:09:27 -0800 | [diff] [blame] | 1 | /* |
| 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 Roth | ebabfad | 2016-04-10 11:09:16 -0600 | [diff] [blame] | 11 | * |
| 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 Petrov | 491c016 | 2016-03-02 15:09:27 -0800 | [diff] [blame] | 16 | */ |
| 17 | |
Alexandru Gagniuc | bbac5ac | 2016-05-23 14:04:58 -0700 | [diff] [blame] | 18 | /* |
| 19 | * The device_t returned by dev_find_slot() is different than the device_t |
| 20 | * passed to pci_write_config32(). If one needs to get access to the config.h |
| 21 | * of a device and perform i/o things are incorrect. One is a pointer while |
| 22 | * the other is a 32-bit integer. |
| 23 | */ |
| 24 | #define __SIMPLE_DEVICE__ |
| 25 | |
Andrey Petrov | 491c016 | 2016-03-02 15:09:27 -0800 | [diff] [blame] | 26 | #include <arch/io.h> |
| 27 | #include <cbmem.h> |
| 28 | #include <device/pci.h> |
| 29 | #include <soc/northbridge.h> |
| 30 | #include <soc/pci_devs.h> |
Hannah Williams | d9c84ca | 2016-05-13 00:47:14 -0700 | [diff] [blame] | 31 | #include <soc/smm.h> |
Andrey Petrov | 491c016 | 2016-03-02 15:09:27 -0800 | [diff] [blame] | 32 | |
| 33 | static uintptr_t smm_region_start(void) |
| 34 | { |
| 35 | return ALIGN_DOWN(pci_read_config32(NB_DEV_ROOT, TSEG), 1*MiB); |
| 36 | } |
| 37 | |
Hannah Williams | d9c84ca | 2016-05-13 00:47:14 -0700 | [diff] [blame] | 38 | static size_t smm_region_size(void) |
| 39 | { |
| 40 | uintptr_t smm_end = |
| 41 | ALIGN_DOWN(pci_read_config32(NB_DEV_ROOT, BGSM), 1*MiB); |
| 42 | return smm_end - smm_region_start(); |
| 43 | } |
| 44 | |
Andrey Petrov | 491c016 | 2016-03-02 15:09:27 -0800 | [diff] [blame] | 45 | void *cbmem_top(void) |
| 46 | { |
| 47 | return (void *)smm_region_start(); |
| 48 | } |
Hannah Williams | d9c84ca | 2016-05-13 00:47:14 -0700 | [diff] [blame] | 49 | |
| 50 | void smm_region(void **start, size_t *size) |
| 51 | { |
| 52 | *start = (void *)smm_region_start(); |
| 53 | *size = smm_region_size(); |
| 54 | } |