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 | 295d58b | 2015-12-15 13:33:51 -0600 | [diff] [blame] | 19 | #include <commonlib/cbfs.h> |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 20 | #include <program_loading.h> |
Daisuke Nojiri | e1298df | 2014-12-01 15:30:01 -0800 | [diff] [blame] | 21 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 22 | /*********************************************** |
| 23 | * Perform CBFS operations on the boot device. * |
| 24 | ***********************************************/ |
| 25 | |
Elyes HAOUAS | 918535a | 2016-07-28 21:25:21 +0200 | [diff] [blame] | 26 | /* Return mapping of option ROM found in boot device. NULL on error. */ |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 27 | void *cbfs_boot_map_optionrom(uint16_t vendor, uint16_t device); |
| 28 | /* Load stage by name into memory. Returns entry address on success. NULL on |
| 29 | * failure. */ |
| 30 | void *cbfs_boot_load_stage_by_name(const char *name); |
| 31 | /* 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] | 32 | 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] | 33 | /* Map file into memory leaking the mapping. Only should be used when |
| 34 | * leaking mappings are a no-op. Returns NULL on error, else returns |
| 35 | * the mapping and sets the size of the file. */ |
| 36 | void *cbfs_boot_map_with_leak(const char *name, uint32_t type, size_t *size); |
Pratik Prajapati | 2a7708a | 2016-11-30 17:29:10 -0800 | [diff] [blame] | 37 | /* Locate file in a specific region of fmap. Return 0 on success. < 0 on error*/ |
| 38 | int cbfs_locate_file_in_region(struct cbfsf *fh, const char *region_name, |
| 39 | const char *name, uint32_t *type); |
Julius Werner | f975e55 | 2016-08-19 15:43:06 -0700 | [diff] [blame] | 40 | /* Load a struct file from CBFS into a buffer. Returns amount of loaded |
| 41 | * bytes on success or 0 on error. File will get decompressed as necessary. |
| 42 | * Same decompression requirements as cbfs_load_and_decompress(). */ |
| 43 | size_t cbfs_boot_load_struct(const char *name, void *buf, size_t buf_size); |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 44 | |
Julius Werner | 09f2921 | 2015-09-29 13:51:35 -0700 | [diff] [blame] | 45 | /* Load |in_size| bytes from |rdev| at |offset| to the |buffer_size| bytes |
| 46 | * large |buffer|, decompressing it according to |compression| in the process. |
| 47 | * Returns the decompressed file size, or 0 on error. |
| 48 | * LZMA files will be mapped for decompression. LZ4 files will be decompressed |
| 49 | * in-place with the buffer size requirements outlined in compression.h. */ |
| 50 | size_t cbfs_load_and_decompress(const struct region_device *rdev, size_t offset, |
| 51 | size_t in_size, void *buffer, size_t buffer_size, uint32_t compression); |
| 52 | |
Kyösti Mälkki | 9d6f365 | 2016-06-28 07:38:46 +0300 | [diff] [blame] | 53 | /* Return the size and fill base of the memory pstage will occupy after loaded. */ |
| 54 | size_t cbfs_prog_stage_section(struct prog *pstage, uintptr_t *base); |
| 55 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 56 | /* Load stage into memory filling in prog. Return 0 on success. < 0 on error. */ |
| 57 | int cbfs_prog_stage_load(struct prog *prog); |
| 58 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 59 | /***************************************************************** |
| 60 | * Support structures and functions. Direct field access should * |
| 61 | * only be done by implementers of cbfs regions -- Not the above * |
| 62 | * API. * |
| 63 | *****************************************************************/ |
| 64 | |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 65 | /* The cbfs_props struct describes the properties associated with a CBFS. */ |
| 66 | struct cbfs_props { |
Aaron Durbin | 899d13d | 2015-05-15 23:39:23 -0500 | [diff] [blame] | 67 | /* CBFS starts at the following offset within the boot region. */ |
| 68 | size_t offset; |
| 69 | /* CBFS size. */ |
| 70 | size_t size; |
| 71 | }; |
| 72 | |
| 73 | /* Return < 0 on error otherwise props are filled out accordingly. */ |
| 74 | int cbfs_boot_region_properties(struct cbfs_props *props); |
| 75 | |
Aaron Durbin | 6d720f3 | 2015-12-08 17:00:23 -0600 | [diff] [blame] | 76 | /* Allow external logic to take action prior to locating a program |
| 77 | * (stage or payload). */ |
| 78 | void cbfs_prepare_program_locate(void); |
| 79 | |
| 80 | /* Object used to identify location of current cbfs to use for cbfs_boot_* |
| 81 | * operations. It's used by cbfs_boot_region_properties() and |
| 82 | * cbfs_prepare_program_locate(). */ |
| 83 | struct cbfs_locator { |
| 84 | const char *name; |
| 85 | void (*prepare)(void); |
| 86 | /* Returns 0 on successful fill of cbfs properties. */ |
| 87 | int (*locate)(struct cbfs_props *props); |
| 88 | }; |
| 89 | |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 90 | #endif |