diff options
author | Aaron Durbin <adurbin@chromium.org> | 2015-05-20 12:08:55 -0500 |
---|---|---|
committer | Patrick Georgi <pgeorgi@google.com> | 2015-06-02 14:10:08 +0200 |
commit | ac12c66cf91343153ea90a6f33977a13e10b21d0 (patch) | |
tree | 2864de25bb12ed2d5c7ec8d691ec753f146c5e57 /src/include | |
parent | 6a452eff90411176f9f2cad0ca0c665a31c032ee (diff) | |
download | coreboot-ac12c66cf91343153ea90a6f33977a13e10b21d0.tar.xz |
assets: abstract away the firmware assets used for booting
As there can be more than one source of firmware assets this
patch generalizes the notion of locating a particular asset.
struct asset is added along with some helper functions for
working on assets as a first class citizen.
Change-Id: I2ce575d1e5259aed4c34c3dcfd438abe9db1d7b9
Signed-off-by: Aaron Durbin <adurbin@chromium.org>
Reviewed-on: http://review.coreboot.org/10264
Reviewed-by: Patrick Georgi <pgeorgi@google.com>
Tested-by: build bot (Jenkins)
Diffstat (limited to 'src/include')
-rw-r--r-- | src/include/assets.h | 91 | ||||
-rw-r--r-- | src/include/program_loading.h | 55 |
2 files changed, 125 insertions, 21 deletions
diff --git a/src/include/assets.h b/src/include/assets.h new file mode 100644 index 0000000000..9c757edc5e --- /dev/null +++ b/src/include/assets.h @@ -0,0 +1,91 @@ +/* + * This file is part of the coreboot project. + * + * Copyright 2015 Google Inc. + * + * 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. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc. + */ +#ifndef ASSETS_H +#define ASSETS_H + +#include <region.h> + +/* An asset represents data used to boot the system. It can be found within + * CBFS or some other mechanism. While CBFS can be a source of an asset, note + * that using the asset API implies querying of other sources. */ + +enum asset_type { + ASSET_UNKNOWN, + ASSET_VERSTAGE, + ASSET_ROMSTAGE, + ASSET_RAMSTAGE, + ASSET_REFCODE, + ASSET_PAYLOAD, + ASSET_BL31, +}; + +struct asset { + enum asset_type type; + const char *name; + struct region_device rdev; +}; + +static inline const char *asset_name(const struct asset *asset) +{ + return asset->name; +} + +static inline enum asset_type asset_type(const struct asset *asset) +{ + return asset->type; +} + +static struct region_device *asset_rdev(struct asset *asset) +{ + return &asset->rdev; +} + +static inline size_t asset_size(const struct asset *asset) +{ + return region_device_sz(&asset->rdev); +} + +/* Returns NULL on error. */ +static inline void *asset_mmap(const struct asset *asset) +{ + return rdev_mmap_full(&asset->rdev); +} + +#define ASSET_INIT(type_, name_) \ + { \ + .type = (type_), \ + .name = (name_), \ + } + +/* Locate the asset as described by the parameter. It will query all known + * asset providers. Returns 0 on success. < 0 on error. */ +int asset_locate(struct asset *asset); + +struct asset_provider { + const char *name; + /* Determines if the provider is the active one. If so returns 1 else 0 + * or < 0 on error. */ + int (*is_active)(struct asset *asset); + /* 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 asset *asset); +}; + +#endif /* ASSETS_H */ diff --git a/src/include/program_loading.h b/src/include/program_loading.h index 7506c50f0f..d6da688831 100644 --- a/src/include/program_loading.h +++ b/src/include/program_loading.h @@ -22,7 +22,7 @@ #include <stdint.h> #include <stddef.h> -#include <region.h> +#include <assets.h> enum { /* Last segment of program. Can be used to take different actions for @@ -34,40 +34,49 @@ enum { * set on the last segment loaded. */ void arch_segment_loaded(uintptr_t start, size_t size, int flags); -enum prog_type { - PROG_VERSTAGE, - PROG_ROMSTAGE, - PROG_RAMSTAGE, - PROG_REFCODE, - PROG_PAYLOAD, - PROG_BL31, -}; - /* Representation of a program. */ struct prog { - enum prog_type type; - const char *name; - /* 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. */ - struct region_device rdev; + /* The region_device within the asset 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. */ + struct asset asset; /* 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_) \ + { \ + .asset = ASSET_INIT(type_, name_), \ + } + +static inline const char *prog_name(const struct prog *prog) +{ + return asset_name(&prog->asset); +} + +static inline enum asset_type prog_type(const struct prog *prog) +{ + return asset_type(&prog->asset); +} + +static inline struct region_device *prog_rdev(struct prog *prog) +{ + return asset_rdev(&prog->asset); +} + /* Only valid for loaded programs. */ static inline size_t prog_size(const struct prog *prog) { - return region_device_sz(&prog->rdev); + return asset_size(&prog->asset); } /* Only valid for loaded programs. */ static inline void *prog_start(const struct prog *prog) { - return rdev_mmap_full(&prog->rdev); + return asset_mmap(&prog->asset); } static inline void *prog_entry(const struct prog *prog) @@ -86,7 +95,7 @@ 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); + rdev_chain(&prog->asset.rdev, &addrspace_32bit.rdev, ptr, size); } static inline void prog_set_area(struct prog *prog, void *start, size_t size) @@ -101,7 +110,11 @@ static inline void prog_set_entry(struct prog *prog, void *e, void *arg) } /* Locate the identified program to run. Return 0 on success. < 0 on error. */ -int prog_locate(struct prog *prog); +static inline int prog_locate(struct prog *prog) +{ + return asset_locate(&prog->asset); +} + /* Run the program described by prog. */ void prog_run(struct prog *prog); /* Per architecture implementation running a program. */ |