Files
system76-coreboot/src/include/program_loading.h
Patrick Rudolph 71327fbad8 lib/prog_loaders: Store CBFS type in struct prog
Store the type of the loaded program after locating the file and add a
method to retrieve the type.
Will be used to distinguish between SELF and FIT payloads.

Change-Id: Ic226e7e028d722ab9e3c6f7f1c22bde2a1cd8a85
Signed-off-by: Patrick Rudolph <patrick.rudolph@9elements.com>
Reviewed-on: https://review.coreboot.org/26028
Reviewed-by: Ronald G. Minnich <rminnich@gmail.com>
Reviewed-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-by: Julius Werner <jwerner@chromium.org>
Tested-by: build bot (Jenkins) <no-reply@coreboot.org>
2018-05-16 20:02:52 +00:00

216 lines
6.3 KiB
C

/*
* This file is part of the coreboot project.
*
* Copyright 2015 Google Inc.
* Copyright (C) 2014 Imagination Technologies
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*/
#ifndef PROGRAM_LOADING_H
#define PROGRAM_LOADING_H
#include <commonlib/region.h>
#include <stdint.h>
#include <stddef.h>
enum {
/* Last segment of program. Can be used to take different actions for
* cache maintenance of a program load. */
SEG_FINAL = 1 << 0,
};
// The prog_type is a bit mask, so that in searches one can find, e.g.,
// a file with a given name that is either a payload or a ramstage.
// The PROG_UNKNOWN should not have any bits set that match a valid
// type, and for the sake of sanity, let's keep the high order bit out of it.
// The current value allows for 16 file types. This is a change from before,
// where we could have 2^32-1 different types. On a guess, it seems 16 should
// be enough. We started with 3 and are up to 6 twelve years later.
enum prog_type {
PROG_UNKNOWN = 0x7bba0000,
PROG_VERSTAGE = 1 << 0,
PROG_ROMSTAGE = 1 << 1,
PROG_RAMSTAGE = 1 << 2,
PROG_REFCODE = 1 << 3,
PROG_PAYLOAD = 1 << 4,
PROG_BL31 = 1 << 5,
PROG_BL32 = 1 << 6,
};
/*
* prog_segment_loaded() is called for each segment of a program loaded. The
* SEG_FINAL flag will be set on the last segment loaded. The following two
* functions, platform_segment_loaded() and arch_segment_loaded(), are called
* in that order within prog_segment_loaded(). In short, rely on
* prog_segment_loaded() to perform the proper dispatch sequence.
*/
void prog_segment_loaded(uintptr_t start, size_t size, int flags);
void platform_segment_loaded(uintptr_t start, size_t size, int flags);
void arch_segment_loaded(uintptr_t start, size_t size, int flags);
/* Return true if arch supports bounce buffer. */
int arch_supports_bounce_buffer(void);
/* Representation of a program. */
struct prog {
/* The region_device is the source of program content to load. After
* loading program it represents the memory region of the stages and
* payload. For architectures that use a bounce buffer
* then it would represent the bounce buffer. */
enum prog_type type;
uint32_t cbfs_type;
const char *name;
struct region_device rdev;
/* Entry to program with optional argument. It's up to the architecture
* to decide if argument is passed. */
void (*entry)(void *);
void *arg;
};
#define PROG_INIT(type_, name_) \
{ \
.type = (type_), \
.name = (name_), \
}
static inline const char *prog_name(const struct prog *prog)
{
return prog->name;
}
static inline enum prog_type prog_type(const struct prog *prog)
{
return prog->type;
}
static inline uint32_t prog_cbfs_type(const struct prog *prog)
{
return prog->cbfs_type;
}
static inline struct region_device *prog_rdev(struct prog *prog)
{
return &prog->rdev;
}
/* Only valid for loaded programs. */
static inline size_t prog_size(const struct prog *prog)
{
return region_device_sz(&prog->rdev);
}
/* Only valid for loaded programs. */
static inline void *prog_start(const struct prog *prog)
{
return rdev_mmap_full(&prog->rdev);
}
static inline void *prog_entry(const struct prog *prog)
{
return prog->entry;
}
static inline void *prog_entry_arg(const struct prog *prog)
{
return prog->arg;
}
/* region_device representing the 32-bit flat address space. */
extern const struct mem_region_device addrspace_32bit;
static inline void prog_memory_init(struct prog *prog, uintptr_t ptr,
size_t size)
{
rdev_chain(&prog->rdev, &addrspace_32bit.rdev, ptr, size);
}
static inline void prog_set_area(struct prog *prog, void *start, size_t size)
{
prog_memory_init(prog, (uintptr_t)start, size);
}
static inline void prog_set_entry(struct prog *prog, void *e, void *arg)
{
prog->entry = e;
prog->arg = arg;
}
/* Locate the identified program to run. Return 0 on success. < 0 on error. */
int prog_locate(struct prog *prog);
/* Run the program described by prog. */
void prog_run(struct prog *prog);
/* Per architecture implementation running a program. */
void arch_prog_run(struct prog *prog);
/* Platform (SoC/chipset) specific overrides for running a program. This is
* called prior to calling the arch_prog_run. Thus, if there is anything
* special that needs to be done by the platform similar to the architecture
* code it needs to that as well. */
void platform_prog_run(struct prog *prog);
struct prog_loader_ops {
const char *name;
/* Determine if the loader is the active one. If so returns 1 else 0
* or < 0 on error. */
int (*is_loader_active)(struct prog *prog);
/* Returns < 0 on error or 0 on success. This function locates
* the rdev representing the file data associated with the passed in
* prog. */
int (*locate)(struct prog *prog);
};
/************************
* ROMSTAGE LOADING *
************************/
/* Run romstage from bootblock. */
void run_romstage(void);
/************************
* RAMSTAGE LOADING *
************************/
/* Run ramstage from romstage. */
void run_ramstage(void);
/* Determine where stack for ramstage loader is located. */
enum { ROMSTAGE_STACK_CBMEM, ROMSTAGE_STACK_LOW_MEM };
uintptr_t romstage_ram_stack_base(size_t size, int src);
uintptr_t romstage_ram_stack_top(void);
uintptr_t romstage_ram_stack_bottom(void);
/* Backup OS memory to CBMEM_ID_RESUME on ACPI S3 resume path,
* if ramstage overwrites low memory. */
void backup_ramstage_section(uintptr_t base, size_t size);
/***********************
* PAYLOAD LOADING *
***********************/
/* Load payload into memory in preparation to run. */
void payload_load(void);
/* Run the loaded payload. */
void payload_run(void);
/* Mirror the payload to be loaded. */
void mirror_payload(struct prog *payload);
/*
* Set check_regions to true to check that the payload targets usable memory.
* With this flag set, if it does not, the load will fail and this function
* will return NULL.
*
* Defined in src/lib/selfboot.c
*/
void *selfload(struct prog *payload, bool check_regions);
#endif /* PROGRAM_LOADING_H */