Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 4 | * Copyright 2015 Google Inc. |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 5 | * |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 6 | * 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 Georgi | b890a12 | 2015-03-26 15:17:45 +0100 | [diff] [blame] | 17 | * Foundation, Inc. |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 18 | */ |
| 19 | |
| 20 | #ifndef _CBFS_H_ |
| 21 | #define _CBFS_H_ |
| 22 | |
Aaron Durbin | dc9f5cd | 2015-09-08 13:34:43 -0500 | [diff] [blame] | 23 | #include <commonlib/cbfs_serialized.h> |
| 24 | #include <commonlib/region.h> |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 25 | #include <program_loading.h> |
Daisuke Nojiri | e1298df | 2014-12-01 15:30:01 -0800 | [diff] [blame] | 26 | |
| 27 | /* |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 28 | * 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 Nojiri | e1298df | 2014-12-01 15:30:01 -0800 | [diff] [blame] | 31 | */ |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 32 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 33 | /* Descriptor for cbfs lookup operations. */ |
| 34 | struct 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. */ |
| 41 | void *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. */ |
| 44 | void *cbfs_boot_load_stage_by_name(const char *name); |
| 45 | /* Locate file by name and optional type. Return 0 on success. < 0 on error. */ |
| 46 | int 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. */ |
| 51 | void *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. */ |
| 54 | int 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.*/ |
| 58 | int 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 | |
| 67 | struct cbfsd { |
| 68 | const struct region_device *rdev; |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 69 | }; |
| 70 | |
| 71 | /* The cbfs_props struct describes the properties associated with a CBFS. */ |
| 72 | struct cbfs_props { |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 73 | /* 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. */ |
| 80 | int cbfs_boot_region_properties(struct cbfs_props *props); |
| 81 | |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 82 | #endif |