3 * Copyright (C) 2013 Google, Inc.
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions
8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright
11 * notice, this list of conditions and the following disclaimer in the
12 * documentation and/or other materials provided with the distribution.
13 * 3. The name of the author may not be used to endorse or promote products
14 * derived from this software without specific prior written permission.
16 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
17 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
18 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
19 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
20 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
21 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
22 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
23 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
24 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
25 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
35 # define init_default_cbfs_media libpayload_init_default_cbfs_media
36 extern int libpayload_init_default_cbfs_media(struct cbfs_media
*media
);
38 # include <console/console.h>
41 // Implementation of memory-mapped ROM media source on X86.
43 static int x86_rom_open(struct cbfs_media
*media
) {
47 static void *x86_rom_map(struct cbfs_media
*media
, size_t offset
, size_t count
) {
49 // Some address (ex, pointer to master header) may be given in memory
50 // mapped location. To workaround that, we handle >0xf0000000 as real
53 if ((uint32_t)offset
> (uint32_t)0xf0000000)
56 ptr
= (void*)(0 - (uint32_t)media
->context
+ offset
);
60 static void *x86_rom_unmap(struct cbfs_media
*media
, const void *address
) {
64 static size_t x86_rom_read(struct cbfs_media
*media
, void *dest
, size_t offset
,
66 void *ptr
= x86_rom_map(media
, offset
, count
);
67 memcpy(dest
, ptr
, count
);
68 x86_rom_unmap(media
, ptr
);
72 static int x86_rom_close(struct cbfs_media
*media
) {
76 int init_x86rom_cbfs_media(struct cbfs_media
*media
);
77 int init_x86rom_cbfs_media(struct cbfs_media
*media
) {
78 // On X86, we always keep a reference of pointer to CBFS header in
79 // 0xfffffffc, and the pointer is still a memory-mapped address.
80 // Since the CBFS core always use ROM offset, we need to figure out
81 // header->romsize even before media is initialized.
82 struct cbfs_header
*header
= (struct cbfs_header
*)
83 *(uint32_t*)(0xfffffffc);
84 if (CBFS_HEADER_MAGIC
!= ntohl(header
->magic
)) {
85 #if CONFIG(LP_ROM_SIZE)
86 printk(BIOS_ERR
, "Invalid CBFS master header at %p\n", header
);
87 media
->context
= (void*)CONFIG_LP_ROM_SIZE
;
92 uint32_t romsize
= ntohl(header
->romsize
);
93 media
->context
= (void*)romsize
;
94 #if CONFIG(LP_ROM_SIZE)
95 if (CONFIG_LP_ROM_SIZE
!= romsize
)
96 printk(BIOS_WARNING
, "rom size unmatch (%d/%d)\n",
97 CONFIG_LP_ROM_SIZE
, romsize
);
100 media
->open
= x86_rom_open
;
101 media
->close
= x86_rom_close
;
102 media
->map
= x86_rom_map
;
103 media
->unmap
= x86_rom_unmap
;
104 media
->read
= x86_rom_read
;
108 int init_default_cbfs_media(struct cbfs_media
*media
) {
109 return init_x86rom_cbfs_media(media
);