blob: e371298241fca33cb632b1550753285529c2a521 [file] [log] [blame]
Furquan Shaikh4208e0c2014-04-28 16:43:07 -07001/*
2 * This file is part of the coreboot project.
3 *
4 * Copyright 2014 Google Inc.
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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#include <cbmem.h>
Aaron Durbineeacf742014-07-10 15:05:13 -050021#include <soc/addressmap.h>
22
Furquan Shaikh4208e0c2014-04-28 16:43:07 -070023void *cbmem_top(void)
24{
Aaron Durbinf13c5672014-07-11 15:56:31 -050025 static uintptr_t addr;
Aaron Durbineeacf742014-07-10 15:05:13 -050026
Aaron Durbinacbf32a2014-10-07 16:16:48 -050027 if (addr == 0) {
28 uintptr_t begin_mib;
29 uintptr_t end_mib;
Aaron Durbin5f66b522014-07-14 15:00:41 -050030
Aaron Durbinacbf32a2014-10-07 16:16:48 -050031 memory_in_range_below_4gb(&begin_mib, &end_mib);
32 /* Make sure we consume everything up to 4GiB. */
33 if (end_mib == 4096)
34 addr = ~(uint32_t)0;
35 else
36 addr = end_mib << 20;
37 }
Aaron Durbinf13c5672014-07-11 15:56:31 -050038
Aaron Durbinacbf32a2014-10-07 16:16:48 -050039 return (void *)addr;
Furquan Shaikh4208e0c2014-04-28 16:43:07 -070040}