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. |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #ifndef _CBFS_H_ |
| 17 | #define _CBFS_H_ |
| 18 | |
Aaron Durbin | dc9f5cd | 2015-09-08 13:34:43 -0500 | [diff] [blame] | 19 | #include <commonlib/cbfs_serialized.h> |
| 20 | #include <commonlib/region.h> |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 21 | #include <program_loading.h> |
Daisuke Nojiri | e1298df | 2014-12-01 15:30:01 -0800 | [diff] [blame] | 22 | |
| 23 | /* |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 24 | * 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 Nojiri | e1298df | 2014-12-01 15:30:01 -0800 | [diff] [blame] | 27 | */ |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 28 | |
Aaron Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame] | 29 | /* Object representing cbfs files. */ |
| 30 | struct cbfsf; |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 31 | |
| 32 | /*********************************************** |
| 33 | * Perform CBFS operations on the boot device. * |
| 34 | ***********************************************/ |
| 35 | |
| 36 | /* Return mapping of option rom found in boot device. NULL on error. */ |
| 37 | void *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. */ |
| 40 | void *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 Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame] | 42 | 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] | 43 | /* 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. */ |
| 46 | void *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. */ |
| 49 | int 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 Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame] | 53 | int cbfs_locate(struct cbfsf *fh, const struct region_device *cbfs, |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 54 | 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 Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame] | 62 | struct cbfsf { |
| 63 | struct region_device metadata; |
| 64 | struct region_device data; |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 65 | }; |
| 66 | |
Aaron Durbin | 37a5d15 | 2015-09-17 16:09:30 -0500 | [diff] [blame] | 67 | static 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 Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 73 | /* The cbfs_props struct describes the properties associated with a CBFS. */ |
| 74 | struct cbfs_props { |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 75 | /* 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. */ |
| 82 | int cbfs_boot_region_properties(struct cbfs_props *props); |
| 83 | |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 84 | /* Allow external logic to take action prior to locating a program |
| 85 | * (stage or payload). */ |
| 86 | void 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(). */ |
| 91 | struct 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 Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 98 | #endif |