blob: f23a82a1730049ca2836ac3bb6109db092b7d276 [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.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program; if not, write to the Free Software
Patrick Georgib890a122015-03-26 15:17:45 +010017 * Foundation, Inc.
Peter Stuge483b7bb2009-04-14 07:40:01 +000018 */
19
20#ifndef _CBFS_H_
21#define _CBFS_H_
22
Aaron Durbindc9f5cd2015-09-08 13:34:43 -050023#include <commonlib/cbfs_serialized.h>
24#include <commonlib/region.h>
Aaron Durbin899d13d2015-05-15 23:39:23 -050025#include <program_loading.h>
Daisuke Nojirie1298df2014-12-01 15:30:01 -080026
27/*
Aaron Durbin899d13d2015-05-15 23:39:23 -050028 * CBFS operations consist of the following concepts:
29 * - region_device for the boot media
30 * - cbfsd which is a descriptor for representing a cbfs instance
Daisuke Nojirie1298df2014-12-01 15:30:01 -080031 */
Hung-Te Lin6fe0cab2013-01-22 18:57:56 +080032
Aaron Durbin899d13d2015-05-15 23:39:23 -050033/* Descriptor for cbfs lookup operations. */
34struct cbfsd;
35
36/***********************************************
37 * Perform CBFS operations on the boot device. *
38 ***********************************************/
39
40/* Return mapping of option rom found in boot device. NULL on error. */
41void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device);
42/* Load stage by name into memory. Returns entry address on success. NULL on
43 * failure. */
44void *cbfs_boot_load_stage_by_name(const char *name);
45/* Locate file by name and optional type. Return 0 on success. < 0 on error. */
46int cbfs_boot_locate(struct region_device *fh, const char *name,
47 uint32_t *type);
48/* Map file into memory leaking the mapping. Only should be used when
49 * leaking mappings are a no-op. Returns NULL on error, else returns
50 * the mapping and sets the size of the file. */
51void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size);
52
53/* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */
54int cbfs_prog_stage_load(struct prog *prog);
55
56/* Locate file by name and optional type. Returns 0 on succcess else < 0 on
57 * error.*/
58int cbfs_locate(struct region_device *fh, const struct cbfsd *cbfs,
59 const char *name, uint32_t *type);
60
61/*****************************************************************
62 * Support structures and functions. Direct field access should *
63 * only be done by implementers of cbfs regions -- Not the above *
64 * API. *
65 *****************************************************************/
66
67struct cbfsd {
68 const struct region_device *rdev;
Aaron Durbin899d13d2015-05-15 23:39:23 -050069};
70
71/* The cbfs_props struct describes the properties associated with a CBFS. */
72struct cbfs_props {
Aaron Durbin899d13d2015-05-15 23:39:23 -050073 /* CBFS starts at the following offset within the boot region. */
74 size_t offset;
75 /* CBFS size. */
76 size_t size;
77};
78
79/* Return < 0 on error otherwise props are filled out accordingly. */
80int cbfs_boot_region_properties(struct cbfs_props *props);
81
Peter Stuge483b7bb2009-04-14 07:40:01 +000082#endif