blob: 12ca36ba509f73b2e5e61e4233cbc0b3146f7528 [file] [log] [blame]
Angel Pons118a9c72020-04-02 23:48:34 +02001/* SPDX-License-Identifier: GPL-2.0-only */
2/* This file is part of the coreboot project. */
Gabe Black396b0722013-09-26 16:22:09 -07003
Aaron Durbinc6588c52015-05-15 13:15:34 -05004#include <boot_device.h>
Gabe Black396b0722013-09-26 16:22:09 -07005
Aaron Durbin64031672018-04-21 14:45:32 -06006void __weak boot_device_init(void)
Gabe Black396b0722013-09-26 16:22:09 -07007{
Aaron Durbinc6588c52015-05-15 13:15:34 -05008 /* Provide weak do-nothing init. */
9}
10
Patrick Rudolph2be0b502019-05-09 13:43:49 +020011int __weak boot_device_wp_region(const struct region_device *rd,
Rizwan Qureshi6d4c1f52018-10-26 16:54:42 +053012 const enum bootdev_prot_type type)
13{
14 /* return a failure, make aware WP is not implemented */
15 return -1;
16}
17
Aaron Durbindcbccd62016-08-10 11:42:42 -050018static int boot_device_subregion(const struct region *sub,
19 struct region_device *subrd,
20 const struct region_device *parent)
21{
22 if (parent == NULL)
23 return -1;
24
25 return rdev_chain(subrd, parent, region_offset(sub), region_sz(sub));
26}
27
Aaron Durbinc6588c52015-05-15 13:15:34 -050028int boot_device_ro_subregion(const struct region *sub,
29 struct region_device *subrd)
30{
Aaron Durbinaeb2e152015-10-13 14:26:55 -050031 /* Ensure boot device has been initialized at least once. */
32 boot_device_init();
33
Aaron Durbindcbccd62016-08-10 11:42:42 -050034 return boot_device_subregion(sub, subrd, boot_device_ro());
35}
Aaron Durbinc6588c52015-05-15 13:15:34 -050036
Aaron Durbindcbccd62016-08-10 11:42:42 -050037int boot_device_rw_subregion(const struct region *sub,
38 struct region_device *subrd)
39{
40 /* Ensure boot device has been initialized at least once. */
41 boot_device_init();
Aaron Durbinc6588c52015-05-15 13:15:34 -050042
Aaron Durbindcbccd62016-08-10 11:42:42 -050043 return boot_device_subregion(sub, subrd, boot_device_rw());
Gabe Black396b0722013-09-26 16:22:09 -070044}