Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright (C) 2008 Jordan Crouse <jordan@cosmicpenguin.net> |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 5 | * Copyright (C) 2013 The Chromium OS Authors. All rights reserved. |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 6 | * |
| 7 | * This file is dual-licensed. You can choose between: |
| 8 | * - The GNU GPL, version 2, as published by the Free Software Foundation |
| 9 | * - The revised BSD license (without advertising clause) |
| 10 | * |
| 11 | * --------------------------------------------------------------------------- |
| 12 | * This program is free software; you can redistribute it and/or modify |
| 13 | * it under the terms of the GNU General Public License as published by |
| 14 | * the Free Software Foundation; version 2 of the License. |
| 15 | * |
| 16 | * This program is distributed in the hope that it will be useful, |
| 17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 19 | * GNU General Public License for more details. |
| 20 | * |
| 21 | * You should have received a copy of the GNU General Public License |
| 22 | * along with this program; if not, write to the Free Software |
| 23 | * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA, 02110-1301 USA |
| 24 | * --------------------------------------------------------------------------- |
| 25 | * Redistribution and use in source and binary forms, with or without |
| 26 | * modification, are permitted provided that the following conditions |
| 27 | * are met: |
| 28 | * 1. Redistributions of source code must retain the above copyright |
| 29 | * notice, this list of conditions and the following disclaimer. |
| 30 | * 2. Redistributions in binary form must reproduce the above copyright |
| 31 | * notice, this list of conditions and the following disclaimer in the |
| 32 | * documentation and/or other materials provided with the distribution. |
| 33 | * 3. The name of the author may not be used to endorse or promote products |
| 34 | * derived from this software without specific prior written permission. |
| 35 | * |
| 36 | * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND |
| 37 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 38 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 39 | * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE |
| 40 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL |
| 41 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS |
| 42 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) |
| 43 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT |
| 44 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY |
| 45 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF |
| 46 | * SUCH DAMAGE. |
| 47 | * --------------------------------------------------------------------------- |
| 48 | */ |
| 49 | |
| 50 | #ifndef _CBFS_H_ |
| 51 | #define _CBFS_H_ |
| 52 | |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 53 | #include <cbfs_core.h> |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 54 | |
Aaron Durbin | 12d45b2 | 2015-03-24 15:50:45 -0500 | [diff] [blame^] | 55 | int init_backing_media(struct cbfs_media **media, struct cbfs_media *backing); |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 56 | void *cbfs_load_optionrom(struct cbfs_media *media, uint16_t vendor, |
| 57 | uint16_t device, void * dest); |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 58 | void *cbfs_load_stage(struct cbfs_media *media, const char *name); |
Daisuke Nojiri | 3589017 | 2014-09-19 09:56:15 -0700 | [diff] [blame] | 59 | void *cbfs_load_stage_by_offset(struct cbfs_media *media, ssize_t offset); |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 60 | |
| 61 | /* Simple buffer for streaming media. */ |
| 62 | struct cbfs_simple_buffer { |
| 63 | char *buffer; |
| 64 | size_t allocated; |
| 65 | size_t size; |
| 66 | size_t last_allocate; |
| 67 | }; |
| 68 | |
| 69 | void *cbfs_simple_buffer_map(struct cbfs_simple_buffer *buffer, |
| 70 | struct cbfs_media *media, |
| 71 | size_t offset, size_t count); |
| 72 | |
| 73 | void *cbfs_simple_buffer_unmap(struct cbfs_simple_buffer *buffer, |
| 74 | const void *address); |
| 75 | |
| 76 | // Utility functions |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 77 | int run_address(void *f); |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 78 | |
Hung-Te Lin | 6fe0cab | 2013-01-22 18:57:56 +0800 | [diff] [blame] | 79 | /* Defined in individual arch / board implementation. */ |
| 80 | int init_default_cbfs_media(struct cbfs_media *media); |
| 81 | |
Aaron Durbin | 0f33307 | 2014-01-30 17:19:46 -0600 | [diff] [blame] | 82 | #if defined(__PRE_RAM__) |
| 83 | struct romstage_handoff; |
| 84 | struct cbmem_entry; |
| 85 | |
Aaron Durbin | de1f890 | 2013-02-15 23:26:52 -0600 | [diff] [blame] | 86 | #if CONFIG_RELOCATABLE_RAMSTAGE && defined(__PRE_RAM__) |
| 87 | /* The cache_loaded_ramstage() and load_cached_ramstage() functions are defined |
| 88 | * to be weak so that board and chipset code may override them. Their job is to |
| 89 | * cache and load the ramstage for quick S3 resume. By default a copy of the |
Aaron Durbin | dd4a6d2 | 2013-02-27 22:50:12 -0600 | [diff] [blame] | 90 | * relocated ramstage is saved using the cbmem infrastructure. These |
Aaron Durbin | de1f890 | 2013-02-15 23:26:52 -0600 | [diff] [blame] | 91 | * functions are only valid during romstage. */ |
| 92 | |
Aaron Durbin | dd4a6d2 | 2013-02-27 22:50:12 -0600 | [diff] [blame] | 93 | /* The implementer of cache_loaded_ramstage() may use the romstage_handoff |
| 94 | * structure to store information, but note that the handoff variable can be |
| 95 | * NULL. The ramstage cbmem_entry represents the region occupied by the loaded |
| 96 | * ramstage. */ |
Kyösti Mälkki | c7c0267 | 2014-12-26 13:28:35 +0200 | [diff] [blame] | 97 | void cache_loaded_ramstage(struct romstage_handoff *handoff, |
Aaron Durbin | dd4a6d2 | 2013-02-27 22:50:12 -0600 | [diff] [blame] | 98 | const struct cbmem_entry *ramstage, void *entry_point); |
| 99 | /* Return NULL on error or entry point on success. The ramstage cbmem_entry is |
| 100 | * the region where to load the cached contents to. */ |
Kyösti Mälkki | c7c0267 | 2014-12-26 13:28:35 +0200 | [diff] [blame] | 101 | void * load_cached_ramstage(struct romstage_handoff *handoff, |
Aaron Durbin | dd4a6d2 | 2013-02-27 22:50:12 -0600 | [diff] [blame] | 102 | const struct cbmem_entry *ramstage); |
Aaron Durbin | 0f33307 | 2014-01-30 17:19:46 -0600 | [diff] [blame] | 103 | #else /* CONFIG_RELOCATABLE_RAMSTAGE */ |
| 104 | |
| 105 | static inline void cache_loaded_ramstage(struct romstage_handoff *handoff, |
| 106 | const struct cbmem_entry *ramstage, void *entry_point) |
| 107 | { |
| 108 | } |
| 109 | |
| 110 | static inline void * |
| 111 | load_cached_ramstage(struct romstage_handoff *handoff, |
| 112 | const struct cbmem_entry *ramstage) |
| 113 | { |
| 114 | return NULL; |
| 115 | } |
| 116 | |
Aaron Durbin | de1f890 | 2013-02-15 23:26:52 -0600 | [diff] [blame] | 117 | #endif /* CONFIG_RELOCATABLE_RAMSTAGE */ |
Aaron Durbin | 0f33307 | 2014-01-30 17:19:46 -0600 | [diff] [blame] | 118 | #endif /* defined(__PRE_RAM__) */ |
Aaron Durbin | de1f890 | 2013-02-15 23:26:52 -0600 | [diff] [blame] | 119 | |
Peter Stuge | 483b7bb | 2009-04-14 07:40:01 +0000 | [diff] [blame] | 120 | #endif |
| 121 | |