blob: e7968f4fa9ad8d8e924420402527e39deb343cad [file] [log] [blame]
Gabe Black396b0722013-09-26 16:22:09 -07001/*
2 * This file is part of the coreboot project.
3 *
Aaron Durbinc6588c52015-05-15 13:15:34 -05004 * Copyright 2015 Google Inc.
Gabe Black396b0722013-09-26 16:22:09 -07005 *
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.
Gabe Black396b0722013-09-26 16:22:09 -070014 */
15
Aaron Durbinc6588c52015-05-15 13:15:34 -050016#include <boot_device.h>
Gabe Black396b0722013-09-26 16:22:09 -070017
Aaron Durbinc6588c52015-05-15 13:15:34 -050018void __attribute__((weak)) boot_device_init(void)
Gabe Black396b0722013-09-26 16:22:09 -070019{
Aaron Durbinc6588c52015-05-15 13:15:34 -050020 /* Provide weak do-nothing init. */
21}
22
Aaron Durbindcbccd62016-08-10 11:42:42 -050023static int boot_device_subregion(const struct region *sub,
24 struct region_device *subrd,
25 const struct region_device *parent)
26{
27 if (parent == NULL)
28 return -1;
29
30 return rdev_chain(subrd, parent, region_offset(sub), region_sz(sub));
31}
32
Aaron Durbinc6588c52015-05-15 13:15:34 -050033int boot_device_ro_subregion(const struct region *sub,
34 struct region_device *subrd)
35{
Aaron Durbinaeb2e152015-10-13 14:26:55 -050036 /* Ensure boot device has been initialized at least once. */
37 boot_device_init();
38
Aaron Durbindcbccd62016-08-10 11:42:42 -050039 return boot_device_subregion(sub, subrd, boot_device_ro());
40}
Aaron Durbinc6588c52015-05-15 13:15:34 -050041
Aaron Durbindcbccd62016-08-10 11:42:42 -050042int boot_device_rw_subregion(const struct region *sub,
43 struct region_device *subrd)
44{
45 /* Ensure boot device has been initialized at least once. */
46 boot_device_init();
Aaron Durbinc6588c52015-05-15 13:15:34 -050047
Aaron Durbindcbccd62016-08-10 11:42:42 -050048 return boot_device_subregion(sub, subrd, boot_device_rw());
Gabe Black396b0722013-09-26 16:22:09 -070049}