Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 1 | /* |
| 2 | * This file is part of the coreboot project. |
| 3 | * |
| 4 | * Copyright 2015 Google Inc. |
| 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. |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 14 | */ |
| 15 | |
| 16 | #ifndef _BOOT_DEVICE_H_ |
| 17 | #define _BOOT_DEVICE_H_ |
| 18 | |
Aaron Durbin | dc9f5cd | 2015-09-08 13:34:43 -0500 | [diff] [blame] | 19 | #include <commonlib/region.h> |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 20 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 21 | /* |
Rizwan Qureshi | 6d4c1f5 | 2018-10-26 16:54:42 +0530 | [diff] [blame] | 22 | * Boot device region can be protected by 2 sources, media and controller. |
| 23 | * The following modes are identified. It depends on the flash chip and the |
| 24 | * controller if mode is actually supported. |
| 25 | * |
| 26 | * MEDIA_WP : Flash/Boot device enforces write protect |
| 27 | * CTRLR_WP : Controller device enforces write protect |
| 28 | * CTRLR_RP : Controller device enforces read protect |
| 29 | * CTRLR_RWP : Controller device enforces read-write protect |
| 30 | */ |
| 31 | enum bootdev_prot_type { |
| 32 | CTRLR_WP = 1, |
| 33 | CTRLR_RP = 2, |
| 34 | CTRLR_RWP = 3, |
| 35 | MEDIA_WP = 4, |
| 36 | }; |
| 37 | /* |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 38 | * Please note that the read-only boot device may not be coherent with |
| 39 | * the read-write boot device. Thus, mixing mmap() and writeat() is |
| 40 | * most likely not to work so don't rely on such semantics. |
| 41 | */ |
| 42 | |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 43 | /* Return the region_device for the read-only boot device. */ |
| 44 | const struct region_device *boot_device_ro(void); |
| 45 | |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 46 | /* Return the region_device for the read-write boot device. */ |
| 47 | const struct region_device *boot_device_rw(void); |
| 48 | |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 49 | /* |
| 50 | * Create a sub-region of the read-only boot device. |
| 51 | * Returns 0 on success, < 0 on error. |
| 52 | */ |
| 53 | int boot_device_ro_subregion(const struct region *sub, |
| 54 | struct region_device *subrd); |
| 55 | |
| 56 | /* |
Aaron Durbin | dcbccd6 | 2016-08-10 11:42:42 -0500 | [diff] [blame] | 57 | * Create a sub-region of the read-write boot device. |
| 58 | * Returns 0 on success, < 0 on error. |
| 59 | */ |
| 60 | int boot_device_rw_subregion(const struct region *sub, |
| 61 | struct region_device *subrd); |
| 62 | |
| 63 | /* |
Rizwan Qureshi | 6d4c1f5 | 2018-10-26 16:54:42 +0530 | [diff] [blame] | 64 | * Write protect a sub-region of the boot device represented |
| 65 | * by the region device. |
| 66 | * Returns 0 on success, < 0 on error. |
| 67 | */ |
| 68 | int boot_device_wp_region(struct region_device *rd, |
| 69 | const enum bootdev_prot_type type); |
| 70 | |
| 71 | /* |
Aaron Durbin | c6588c5 | 2015-05-15 13:15:34 -0500 | [diff] [blame] | 72 | * Initialize the boot device. This may be called multiple times within |
| 73 | * a stage so boot device implementations should account for this behavior. |
| 74 | **/ |
| 75 | void boot_device_init(void); |
| 76 | |
| 77 | #endif /* _BOOT_DEVICE_H_ */ |