blob: 4349d19ea7d668beb4a3632eb9694beb0e7afc16 [file] [log] [blame]
Kyösti Mälkkicb08e162013-10-15 17:19:41 +03001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright (C) 2007-2009 coresystems GmbH
5 *
6 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030014 */
15
16// Use simple device model for this file even in ramstage
17#define __SIMPLE_DEVICE__
18
19#include <arch/io.h>
20#include <cbmem.h>
21#include "i945.h"
Arthur Heymans874a8f92016-05-19 16:06:09 +020022#include <console/console.h>
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030023
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020024static uintptr_t smm_region_start(void)
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030025{
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020026 uintptr_t tom;
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030027
Kyösti Mälkki3c3e34d2014-05-31 11:32:54 +030028 if (pci_read_config8(PCI_DEV(0, 0x0, 0), DEVEN) & (DEVEN_D2F0 | DEVEN_D2F1)) {
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030029 /* IGD enabled, get top of Memory from BSM register */
Paul Menzel355ce382014-05-30 13:58:59 +020030 tom = pci_read_config32(PCI_DEV(0,2,0), BSM);
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030031 } else {
32 tom = (pci_read_config8(PCI_DEV(0,0,0), TOLUD) & 0xf7) << 24;
33 }
34
35 /* if TSEG enabled subtract size */
Kyösti Mälkkifd2501b2014-05-31 16:36:29 +030036 switch(pci_read_config8(PCI_DEV(0, 0, 0), ESMRAM) & 0x07) {
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030037 case 0x01:
38 /* 1MB TSEG */
Kyösti Mälkkifd2501b2014-05-31 16:36:29 +030039 tom -= 0x100000;
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030040 break;
41 case 0x03:
42 /* 2MB TSEG */
Kyösti Mälkkifd2501b2014-05-31 16:36:29 +030043 tom -= 0x200000;
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030044 break;
45 case 0x05:
46 /* 8MB TSEG */
Kyösti Mälkkifd2501b2014-05-31 16:36:29 +030047 tom -= 0x800000;
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030048 break;
49 default:
50 /* TSEG either disabled or invalid */
51 break;
52 }
Kyösti Mälkkif1e3c762014-12-22 12:28:07 +020053 return tom;
54}
55
56void *cbmem_top(void)
57{
58 return (void *) smm_region_start();
Kyösti Mälkkicb08e162013-10-15 17:19:41 +030059}
Arthur Heymans874a8f92016-05-19 16:06:09 +020060
61/** Decodes used Graphics Mode Select (GMS) to kilobytes. */
62u32 decode_igd_memory_size(const u32 gms)
63{
64 static const u16 ggc2uma[] = { 0, 1, 4, 8, 16, 32,
65 48, 64 };
66
67 if (gms > ARRAY_SIZE(ggc2uma))
68 die("Bad Graphics Mode Select (GMS) setting.\n");
69
70 return ggc2uma[gms] << 10;
71}