Angel Pons | 118a9c7 | 2020-04-02 23:48:34 +0200 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0-only */ |
| 2 | /* This file is part of the coreboot project. */ |
Gabe Black | 396b072 | 2013-09-26 16:22:09 -0700 | [diff] [blame] | 3 | |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 4 | #include <boot_device.h> |
Gabe Black | 396b072 | 2013-09-26 16:22:09 -0700 | [diff] [blame] | 5 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 6 | void __weak boot_device_init(void) |
Gabe Black | 396b072 | 2013-09-26 16:22:09 -0700 | [diff] [blame] | 7 | { |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 8 | /* Provide weak do-nothing init. */ |
| 9 | } |
| 10 | |
Patrick Rudolph | 2be0b50 | 2019-05-09 13:43:49 +0200 | [diff] [blame] | 11 | int __weak boot_device_wp_region(const struct region_device *rd, |
Rizwan Qureshi | 6d4c1f5 | 2018-10-26 16:54:42 +0530 | [diff] [blame] | 12 | const enum bootdev_prot_type type) |
| 13 | { |
| 14 | /* return a failure, make aware WP is not implemented */ |
| 15 | return -1; |
| 16 | } |
| 17 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 18 | static 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 Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 28 | int boot_device_ro_subregion(const struct region *sub, |
| 29 | struct region_device *subrd) |
| 30 | { |
Aaron Durbin | aeb2e15 | 2015-10-13 14:26:55 -0500 | [diff] [blame] | 31 | /* Ensure boot device has been initialized at least once. */ |
| 32 | boot_device_init(); |
| 33 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 34 | return boot_device_subregion(sub, subrd, boot_device_ro()); |
| 35 | } |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 36 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 37 | int 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 Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 42 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 43 | return boot_device_subregion(sub, subrd, boot_device_rw()); |
Gabe Black | 396b072 | 2013-09-26 16:22:09 -0700 | [diff] [blame] | 44 | } |