blob: ea6f447d43f324d65608f01be9c008870700b678 [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
Alexandru Gagniucbbac5ac2016-05-23 14:04:58 -070018/*
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 Petrov491c0162016-03-02 15:09:27 -080026#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 Williamsd9c84ca2016-05-13 00:47:14 -070031#include <soc/smm.h>
Andrey Petrov491c0162016-03-02 15:09:27 -080032
33static uintptr_t smm_region_start(void)
34{
35 return ALIGN_DOWN(pci_read_config32(NB_DEV_ROOT, TSEG), 1*MiB);
36}
37
Hannah Williamsd9c84ca2016-05-13 00:47:14 -070038static 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 Petrov491c0162016-03-02 15:09:27 -080045void *cbmem_top(void)
46{
47 return (void *)smm_region_start();
48}
Hannah Williamsd9c84ca2016-05-13 00:47:14 -070049
50void smm_region(void **start, size_t *size)
51{
52 *start = (void *)smm_region_start();
53 *size = smm_region_size();
54}