Stefan Reinauer (stefan.reinauer@coreboot.org) just uploaded a new patch set to gerrit, which you can find at http://review.coreboot.org/2795
-gerrit
commit b6ce7ac7af4a4058b36d5afdacf88f4552257aab Author: Aaron Durbin adurbin@chromium.org Date: Mon Feb 11 21:07:18 2013 -0600
romstage_handoff: provide common logic for setup
The romstage_handoff structure can be utilized from different components of the romstage -- some in the chipset code, some in coreboot's core libarary. To ensure that all users handle initialization of a newly added romstage_handoff structure properly, provide a common function to handle structure initialization.
Change-Id: I3998c6bb228255f4fd93d27812cf749560b06e61 Signed-off-by: Aaron Durbin adurbin@chromium.org --- src/include/romstage_handoff.h | 27 +++++++++++++++++++++++++++ src/lib/cbfs.c | 2 +- 2 files changed, 28 insertions(+), 1 deletion(-)
diff --git a/src/include/romstage_handoff.h b/src/include/romstage_handoff.h index 0cadfb5..13dc979 100644 --- a/src/include/romstage_handoff.h +++ b/src/include/romstage_handoff.h @@ -20,6 +20,8 @@ #define ROMSTAGE_HANDOFF_H
#include <stdint.h> +#include <string.h> +#include <cbmem.h>
/* It is the chipset's responsbility for maintaining the integrity of this * structure in CBMEM. For instance, if chipset code adds this structure @@ -31,5 +33,30 @@ struct romstage_handoff { uint32_t reserve_size; };
+#if defined(__PRE_RAM__) +/* The romstage_handoff_find_or_add() function provides the necessary logic + * for initializng the romstage_handoff structure in cbmem. Different components + * of the romstage may be responsible for setting up different fields. Therefore + * that same logic flow should be used for allocating and initializing the + * structure. A newly allocated structure will be memset to 0. */ +static inline struct romstage_handoff *romstage_handoff_find_or_add(void) +{ + struct romstage_handoff *handoff; + + /* cbmem_add() first does a find and uses the old location before the + * real add. However, it is important to know when the structure is not + * found so it can be initialized to 0. */ + handoff = cbmem_find(CBMEM_ID_ROMSTAGE_INFO); + + if (handoff == NULL) { + handoff = cbmem_add(CBMEM_ID_ROMSTAGE_INFO, sizeof(*handoff)); + if (handoff != NULL) + memset(handoff, 0, sizeof(*handoff)); + } + + return handoff; +} +#endif + #endif /* ROMSTAGE_HANDOFF_H */
diff --git a/src/lib/cbfs.c b/src/lib/cbfs.c index 7d81038..c8bfb0c 100644 --- a/src/lib/cbfs.c +++ b/src/lib/cbfs.c @@ -161,7 +161,7 @@ void * cbfs_load_stage(struct cbfs_media *media, const char *name) if (rmodule_load_no_clear_bss(ramstage_loc, &ramstage)) return (void *) -1;
- handoff = cbmem_add(CBMEM_ID_ROMSTAGE_INFO, sizeof(*handoff)); + handoff = romstage_handoff_find_or_add(); if (handoff) { handoff->reserve_base = (uint32_t)ramstage_base; handoff->reserve_size = (uint32_t)cbmem_base -