#include <cbmem.h>
#include <console/console.h>
-#if 1
-#define debug(x...) printk(BIOS_DEBUG, x)
-#else
-#define debug(x...)
-#endif
-
// The CBMEM TOC reserves 512 bytes to keep
// the other entries somewhat aligned.
// Increase if MAX_CBMEM_ENTRIES exceeds 21
u64 size;
} __attribute__((packed));
-#ifndef __PRE_RAM__
-struct cbmem_entry *bss_cbmem_toc;
+
+#ifdef __PRE_RAM__
+
+/* note this should be done as weak function but we do #include
+ of C files in the romstage breaking this (in same compile
+ unit is weak and non weak function
+struct cbmem_entry *__attribute__((weak)) get_cbmem_toc(void)
+*/
+#ifndef get_cbmem_toc
+ #define get_cbmem_toc() (struct cbmem_entry *)(get_top_of_ram() - HIGH_MEMORY_SIZE)
+#endif
+
+#else
+
+static struct cbmem_entry *bss_cbmem_toc;
+
+struct cbmem_entry *__attribute__((weak)) get_cbmem_toc(void)
+{
+ return bss_cbmem_toc;
+}
+
+void __attribute__((weak)) set_cbmem_toc(struct cbmem_entry * x)
+{
+ /* do nothing, this should be called by chipset to save TOC in NVRAM */
+}
+
#endif
/**
#ifndef __PRE_RAM__
bss_cbmem_toc = cbmem_toc;
#endif
-
- debug("Initializing CBMEM area to 0x%llx (%lld bytes)\n", baseaddr, size);
+
+ printk(BIOS_DEBUG, "Initializing CBMEM area to 0x%llx (%lld bytes)\n",
+ baseaddr, size);
if (size < (64 * 1024)) {
- debug("Increase CBMEM size!!\n");
+ printk(BIOS_DEBUG, "Increase CBMEM size!\n");
for (;;) ;
}
+ /* we don't need to call this in romstage, usefull only from ramstage */
+#ifndef __PRE_RAM__
+ set_cbmem_toc((struct cbmem_entry *)(unsigned long)baseaddr);
+#endif
memset(cbmem_toc, 0, CBMEM_TOC_RESERVED);
cbmem_toc[0] = (struct cbmem_entry) {
struct cbmem_entry *cbmem_toc;
cbmem_toc = (struct cbmem_entry *)(unsigned long)baseaddr;
- debug("Re-Initializing CBMEM area to 0x%lx\n", (unsigned long)baseaddr);
+ printk(BIOS_DEBUG, "Re-Initializing CBMEM area to 0x%lx\n",
+ (unsigned long)baseaddr);
+
#ifndef __PRE_RAM__
bss_cbmem_toc = cbmem_toc;
#endif
{
struct cbmem_entry *cbmem_toc;
int i;
-#ifdef __PRE_RAM__
- cbmem_toc = (struct cbmem_entry *)(get_top_of_ram() - HIGH_MEMORY_SIZE);
-#else
- cbmem_toc = bss_cbmem_toc;
-#endif
-
+ cbmem_toc = get_cbmem_toc();
+
if (cbmem_toc == NULL) {
return NULL;
}
/* Align size to 512 byte blocks */
- size = ALIGN(size, 512) < cbmem_toc[0].size ?
+ size = ALIGN(size, 512) < cbmem_toc[0].size ?
ALIGN(size, 512) : cbmem_toc[0].size;
/* Now look for the first free/usable TOC entry */
return NULL;
}
- debug("Adding CBMEM entry as no. %d\n", i);
+ printk(BIOS_DEBUG, "Adding CBMEM entry as no. %d\n", i);
cbmem_toc[i] = (struct cbmem_entry) {
.magic = CBMEM_MAGIC,
{
struct cbmem_entry *cbmem_toc;
int i;
-#ifdef __PRE_RAM__
- cbmem_toc = (struct cbmem_entry *)(get_top_of_ram() - HIGH_MEMORY_SIZE);
-#else
- cbmem_toc = bss_cbmem_toc;
-#endif
-
+ cbmem_toc = get_cbmem_toc();
+
if (cbmem_toc == NULL)
return NULL;
#if CONFIG_HAVE_ACPI_RESUME
extern u8 acpi_slp_type;
#endif
-extern uint64_t high_tables_base, high_tables_size;
void cbmem_initialize(void)
{
{
struct cbmem_entry *cbmem_toc;
int i;
-#ifdef __PRE_RAM__
- cbmem_toc = (struct cbmem_entry *)(get_top_of_ram() - HIGH_MEMORY_SIZE);
-#else
- cbmem_toc = bss_cbmem_toc;
-#endif
-
+ cbmem_toc = get_cbmem_toc();
+
if (cbmem_toc == NULL)
return;