blob: 7848d6d6fddf0f2a56b2b507b267669ca09440f1 [file] [log] [blame]
Peter Stuge483b7bb2009-04-14 07:40:01 +00001/*
2 * This file is part of the coreboot project.
3 *
Aaron Durbin899d13d2015-05-15 23:39:23 -05004 * Copyright 2015 Google Inc.
Peter Stuge483b7bb2009-04-14 07:40:01 +00005 *
Peter Stuge483b7bb2009-04-14 07:40:01 +00006 * This program is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 2 of the License.
9 *
10 * This program is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
Peter Stuge483b7bb2009-04-14 07:40:01 +000014 */
15
16#ifndef _CBFS_H_
17#define _CBFS_H_
18
Aaron Durbindc9f5cd2015-09-08 13:34:43 -050019#include <commonlib/cbfs_serialized.h>
20#include <commonlib/region.h>
Aaron Durbin899d13d2015-05-15 23:39:23 -050021#include <program_loading.h>
Daisuke Nojirie1298df2014-12-01 15:30:01 -080022
23/*
Aaron Durbin899d13d2015-05-15 23:39:23 -050024 * CBFS operations consist of the following concepts:
25 * - region_device for the boot media
26 * - cbfsd which is a descriptor for representing a cbfs instance
Daisuke Nojirie1298df2014-12-01 15:30:01 -080027 */
Hung-Te Lin6fe0cab2013-01-22 18:57:56 +080028
Aaron Durbin37a5d152015-09-17 16:09:30 -050029/* Object representing cbfs files. */
30struct cbfsf;
Aaron Durbin899d13d2015-05-15 23:39:23 -050031
32/***********************************************
33 * Perform CBFS operations on the boot device. *
34 ***********************************************/
35
36/* Return mapping of option rom found in boot device. NULL on error. */
37void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device);
38/* Load stage by name into memory. Returns entry address on success. NULL on
39 * failure. */
40void *cbfs_boot_load_stage_by_name(const char *name);
41/* Locate file by name and optional type. Return 0 on success. < 0 on error. */
Aaron Durbin37a5d152015-09-17 16:09:30 -050042int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type);
Aaron Durbin899d13d2015-05-15 23:39:23 -050043/* Map file into memory leaking the mapping. Only should be used when
44 * leaking mappings are a no-op. Returns NULL on error, else returns
45 * the mapping and sets the size of the file. */
46void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size);
47
48/* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */
49int cbfs_prog_stage_load(struct prog *prog);
50
51/* Locate file by name and optional type. Returns 0 on succcess else < 0 on
52 * error.*/
Aaron Durbin37a5d152015-09-17 16:09:30 -050053int cbfs_locate(struct cbfsf *fh, const struct region_device *cbfs,
Aaron Durbin899d13d2015-05-15 23:39:23 -050054 const char *name, uint32_t *type);
55
56/*****************************************************************
57 * Support structures and functions. Direct field access should *
58 * only be done by implementers of cbfs regions -- Not the above *
59 * API. *
60 *****************************************************************/
61
Aaron Durbin37a5d152015-09-17 16:09:30 -050062struct cbfsf {
63 struct region_device metadata;
64 struct region_device data;
Aaron Durbin899d13d2015-05-15 23:39:23 -050065};
66
Aaron Durbin37a5d152015-09-17 16:09:30 -050067static inline void cbfs_file_data(struct region_device *data,
68 const struct cbfsf *file)
69{
70 rdev_chain(data, &file->data, 0, region_device_sz(&file->data));
71}
72
Aaron Durbin899d13d2015-05-15 23:39:23 -050073/* The cbfs_props struct describes the properties associated with a CBFS. */
74struct cbfs_props {
Aaron Durbin899d13d2015-05-15 23:39:23 -050075 /* CBFS starts at the following offset within the boot region. */
76 size_t offset;
77 /* CBFS size. */
78 size_t size;
79};
80
81/* Return < 0 on error otherwise props are filled out accordingly. */
82int cbfs_boot_region_properties(struct cbfs_props *props);
83
Aaron Durbin6d720f32015-12-08 17:00:23 -060084/* Allow external logic to take action prior to locating a program
85 * (stage or payload). */
86void cbfs_prepare_program_locate(void);
87
88/* Object used to identify location of current cbfs to use for cbfs_boot_*
89 * operations. It's used by cbfs_boot_region_properties() and
90 * cbfs_prepare_program_locate(). */
91struct cbfs_locator {
92 const char *name;
93 void (*prepare)(void);
94 /* Returns 0 on successful fill of cbfs properties. */
95 int (*locate)(struct cbfs_props *props);
96};
97
Peter Stuge483b7bb2009-04-14 07:40:01 +000098#endif