libpayload: refactor fetching cbmem pointers
There's a recurring pattern of reading cbtable entries that point into cbmem entries. Move that pattern into its own function. Coccinelle patch used for this: @@ identifier T, T2; expression TARGET; @@ -struct cb_cbmem_tab *const T2 = (struct cb_cbmem_tab *)T; -TARGET = phys_to_virt(T2->cbmem_tab); +TARGET = get_cbmem_ptr(T); Change-Id: I7bd4a7ad8baeeaebf0fa7d4b4de6dbc719bc781f Signed-off-by: Patrick Georgi <pgeorgi@google.com> Reviewed-on: https://review.coreboot.org/c/coreboot/+/35756 Tested-by: build bot (Jenkins) <no-reply@coreboot.org> Reviewed-by: Paul Menzel <paulepanter@users.sourceforge.net> Reviewed-by: Furquan Shaikh <furquan@google.com> Reviewed-by: Stefan Reinauer <stefan.reinauer@coreboot.org>
This commit is contained in:
parent
c49869b424
commit
006eb9d8c8
|
@ -50,8 +50,7 @@ static void cb_parse_x86_rom_var_mtrr(void *ptr, struct sysinfo_t *info)
|
||||||
|
|
||||||
static void cb_parse_mrc_cache(void *ptr, struct sysinfo_t *info)
|
static void cb_parse_mrc_cache(void *ptr, struct sysinfo_t *info)
|
||||||
{
|
{
|
||||||
struct cb_cbmem_tab *const cbmem = (struct cb_cbmem_tab *)ptr;
|
info->mrc_cache = get_cbmem_ptr(ptr);
|
||||||
info->mrc_cache = phys_to_virt(cbmem->cbmem_tab);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
int cb_parse_arch_specific(struct cb_record *rec, struct sysinfo_t *info)
|
int cb_parse_arch_specific(struct cb_record *rec, struct sysinfo_t *info)
|
||||||
|
|
|
@ -395,4 +395,6 @@ static inline const char *cb_mb_part_string(const struct cb_mainboard *cbm)
|
||||||
(void *)(((u8 *) (_rec)) + sizeof(*(_rec)) \
|
(void *)(((u8 *) (_rec)) + sizeof(*(_rec)) \
|
||||||
+ (sizeof((_rec)->map[0]) * (_idx)))
|
+ (sizeof((_rec)->map[0]) * (_idx)))
|
||||||
|
|
||||||
|
/* Helper functions */
|
||||||
|
void *get_cbmem_ptr(unsigned char *ptr);
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -42,6 +42,12 @@
|
||||||
/* === Parsing code === */
|
/* === Parsing code === */
|
||||||
/* This is the generic parsing code. */
|
/* This is the generic parsing code. */
|
||||||
|
|
||||||
|
void *get_cbmem_ptr(unsigned char *ptr)
|
||||||
|
{
|
||||||
|
struct cb_cbmem_tab *const cbmem = (struct cb_cbmem_tab *)ptr;
|
||||||
|
return phys_to_virt(cbmem->cbmem_tab);
|
||||||
|
}
|
||||||
|
|
||||||
static void cb_parse_memory(void *ptr, struct sysinfo_t *info)
|
static void cb_parse_memory(void *ptr, struct sysinfo_t *info)
|
||||||
{
|
{
|
||||||
struct cb_memory *mem = ptr;
|
struct cb_memory *mem = ptr;
|
||||||
|
@ -128,20 +134,17 @@ static void cb_parse_mac_addresses(unsigned char *ptr,
|
||||||
|
|
||||||
static void cb_parse_tstamp(unsigned char *ptr, struct sysinfo_t *info)
|
static void cb_parse_tstamp(unsigned char *ptr, struct sysinfo_t *info)
|
||||||
{
|
{
|
||||||
struct cb_cbmem_tab *const cbmem = (struct cb_cbmem_tab *)ptr;
|
info->tstamp_table = get_cbmem_ptr(ptr);
|
||||||
info->tstamp_table = phys_to_virt(cbmem->cbmem_tab);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cb_parse_cbmem_cons(unsigned char *ptr, struct sysinfo_t *info)
|
static void cb_parse_cbmem_cons(unsigned char *ptr, struct sysinfo_t *info)
|
||||||
{
|
{
|
||||||
struct cb_cbmem_tab *const cbmem = (struct cb_cbmem_tab *)ptr;
|
info->cbmem_cons = get_cbmem_ptr(ptr);
|
||||||
info->cbmem_cons = phys_to_virt(cbmem->cbmem_tab);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cb_parse_acpi_gnvs(unsigned char *ptr, struct sysinfo_t *info)
|
static void cb_parse_acpi_gnvs(unsigned char *ptr, struct sysinfo_t *info)
|
||||||
{
|
{
|
||||||
struct cb_cbmem_tab *const cbmem = (struct cb_cbmem_tab *)ptr;
|
info->acpi_gnvs = get_cbmem_ptr(ptr);
|
||||||
info->acpi_gnvs = phys_to_virt(cbmem->cbmem_tab);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cb_parse_board_id(unsigned char *ptr, struct sysinfo_t *info)
|
static void cb_parse_board_id(unsigned char *ptr, struct sysinfo_t *info)
|
||||||
|
@ -193,8 +196,7 @@ static void cb_parse_string(unsigned char *ptr, char **info)
|
||||||
|
|
||||||
static void cb_parse_wifi_calibration(void *ptr, struct sysinfo_t *info)
|
static void cb_parse_wifi_calibration(void *ptr, struct sysinfo_t *info)
|
||||||
{
|
{
|
||||||
struct cb_cbmem_tab *const cbmem = (struct cb_cbmem_tab *)ptr;
|
info->wifi_calibration = get_cbmem_ptr(ptr);
|
||||||
info->wifi_calibration = phys_to_virt(cbmem->cbmem_tab);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cb_parse_ramoops(void *ptr, struct sysinfo_t *info)
|
static void cb_parse_ramoops(void *ptr, struct sysinfo_t *info)
|
||||||
|
@ -235,14 +237,12 @@ static void cb_parse_boot_media_params(unsigned char *ptr,
|
||||||
|
|
||||||
static void cb_parse_vpd(void *ptr, struct sysinfo_t *info)
|
static void cb_parse_vpd(void *ptr, struct sysinfo_t *info)
|
||||||
{
|
{
|
||||||
struct cb_cbmem_tab *const cbmem = (struct cb_cbmem_tab *)ptr;
|
info->chromeos_vpd = get_cbmem_ptr(ptr);
|
||||||
info->chromeos_vpd = phys_to_virt(cbmem->cbmem_tab);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void cb_parse_fmap_cache(void *ptr, struct sysinfo_t *info)
|
static void cb_parse_fmap_cache(void *ptr, struct sysinfo_t *info)
|
||||||
{
|
{
|
||||||
struct cb_cbmem_tab *const cbmem = (struct cb_cbmem_tab *)ptr;
|
info->fmap_cache = get_cbmem_ptr(ptr);
|
||||||
info->fmap_cache = phys_to_virt(cbmem->cbmem_tab);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#if CONFIG(LP_TIMER_RDTSC)
|
#if CONFIG(LP_TIMER_RDTSC)
|
||||||
|
|
Loading…
Reference in New Issue