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 | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame^] | 33 | /* Object representing cbfs files. */ |
| 34 | struct cbfsf; |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 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. */ |
Aaron Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame^] | 46 | int cbfs_boot_locate(struct cbfsf *fh, const char *name, uint32_t *type); |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 47 | /* Map file into memory leaking the mapping. Only should be used when |
| 48 | * leaking mappings are a no-op. Returns NULL on error, else returns |
| 49 | * the mapping and sets the size of the file. */ |
| 50 | void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size); |
| 51 | |
| 52 | /* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */ |
| 53 | int cbfs_prog_stage_load(struct prog *prog); |
| 54 | |
| 55 | /* Locate file by name and optional type. Returns 0 on succcess else < 0 on |
| 56 | * error.*/ |
Aaron Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame^] | 57 | int cbfs_locate(struct cbfsf *fh, const struct region_device *cbfs, |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 58 | const char *name, uint32_t *type); |
| 59 | |
| 60 | /***************************************************************** |
| 61 | * Support structures and functions. Direct field access should * |
| 62 | * only be done by implementers of cbfs regions -- Not the above * |
| 63 | * API. * |
| 64 | *****************************************************************/ |
| 65 | |
Aaron Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame^] | 66 | struct cbfsf { |
| 67 | struct region_device metadata; |
| 68 | struct region_device data; |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 69 | }; |
| 70 | |
Aaron Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame^] | 71 | static inline void cbfs_file_data(struct region_device *data, |
| 72 | const struct cbfsf *file) |
| 73 | { |
| 74 | rdev_chain(data, &file->data, 0, region_device_sz(&file->data)); |
| 75 | } |
| 76 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 77 | /* The cbfs_props struct describes the properties associated with a CBFS. */ |
| 78 | struct cbfs_props { |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 79 | /* CBFS starts at the following offset within the boot region. */ |
| 80 | size_t offset; |
| 81 | /* CBFS size. */ |
| 82 | size_t size; |
| 83 | }; |
| 84 | |
| 85 | /* Return < 0 on error otherwise props are filled out accordingly. */ |
| 86 | int cbfs_boot_region_properties(struct cbfs_props *props); |
| 87 | |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 88 | #endif |