Gabe Black | 396b072 | 2013-09-26 16:22:09 -0700 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 4 | * Copyright 2015 Google Inc. |
Gabe Black | 396b072 | 2013-09-26 16:22:09 -0700 | [diff] [blame] | 5 | * |
| 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 Black | 396b072 | 2013-09-26 16:22:09 -0700 | [diff] [blame] | 14 | */ |
| 15 | |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 16 | #include <boot_device.h> |
Gabe Black | 396b072 | 2013-09-26 16:22:09 -0700 | [diff] [blame] | 17 | |
Aaron Durbin | 6403167 | 2018-04-21 14:45:32 -0600 | [diff] [blame] | 18 | void __weak boot_device_init(void) |
Gabe Black | 396b072 | 2013-09-26 16:22:09 -0700 | [diff] [blame] | 19 | { |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 20 | /* Provide weak do-nothing init. */ |
| 21 | } |
| 22 | |
Rizwan Qureshi | 6d4c1f5 | 2018-10-26 16:54:42 +0530 | [diff] [blame] | 23 | int __weak boot_device_wp_region(struct region_device *rd, |
| 24 | const enum bootdev_prot_type type) |
| 25 | { |
| 26 | /* return a failure, make aware WP is not implemented */ |
| 27 | return -1; |
| 28 | } |
| 29 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 30 | static int boot_device_subregion(const struct region *sub, |
| 31 | struct region_device *subrd, |
| 32 | const struct region_device *parent) |
| 33 | { |
| 34 | if (parent == NULL) |
| 35 | return -1; |
| 36 | |
| 37 | return rdev_chain(subrd, parent, region_offset(sub), region_sz(sub)); |
| 38 | } |
| 39 | |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 40 | int boot_device_ro_subregion(const struct region *sub, |
| 41 | struct region_device *subrd) |
| 42 | { |
Aaron Durbin | aeb2e15 | 2015-10-13 14:26:55 -0500 | [diff] [blame] | 43 | /* Ensure boot device has been initialized at least once. */ |
| 44 | boot_device_init(); |
| 45 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 46 | return boot_device_subregion(sub, subrd, boot_device_ro()); |
| 47 | } |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 48 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 49 | int boot_device_rw_subregion(const struct region *sub, |
| 50 | struct region_device *subrd) |
| 51 | { |
| 52 | /* Ensure boot device has been initialized at least once. */ |
| 53 | boot_device_init(); |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 54 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 55 | return boot_device_subregion(sub, subrd, boot_device_rw()); |
Gabe Black | 396b072 | 2013-09-26 16:22:09 -0700 | [diff] [blame] | 56 | } |