summaryrefslogtreecommitdiff
path: root/zephyr/include/drivers
diff options
context:
space:
mode:
authorTim Lin <tim2.lin@ite.corp-partner.google.com>2021-06-29 17:00:32 +0800
committerCommit Bot <commit-bot@chromium.org>2021-07-01 15:01:02 +0000
commit7e023660225971dc0b9edb4889a7ed6dc70b59e8 (patch)
tree641c10020b477181c3413d662aaaf26b7f0dc043 /zephyr/include/drivers
parent300daebbb748a7b5f51bf411adfb985b83c085a4 (diff)
downloadchrome-ec-7e023660225971dc0b9edb4889a7ed6dc70b59e8.tar.gz
zephyr/drivers: npcx: reorganizes the flash driver(3)
Move NPCX specific code crec_flash_physical_get_protect(), crec_flash_physical_get_protect_flags(), crec_flash_physical_protect_at_boot(), and crec_flash_physical_protect_now() from shim/flash.c to cros_flash/cros_flash_npcx.c. BUG=b:187192628 BRANCH=none TEST=zmake -lDEBUG configure -b -B zephyr/build_volteer \ zephyr/projects/volteer/volteer/ Cq-Depend: chromium:2994430 Signed-off-by: Tim Lin <tim2.lin@ite.corp-partner.google.com> Change-Id: Id6ed382ad4578969838339c9eb874b323390c485 Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/platform/ec/+/2891674 Reviewed-by: Keith Short <keithshort@chromium.org> Commit-Queue: Keith Short <keithshort@chromium.org> Tested-by: Keith Short <keithshort@chromium.org>
Diffstat (limited to 'zephyr/include/drivers')
-rw-r--r--zephyr/include/drivers/cros_flash.h116
1 files changed, 116 insertions, 0 deletions
diff --git a/zephyr/include/drivers/cros_flash.h b/zephyr/include/drivers/cros_flash.h
index 19c93210e1..7f48cf7285 100644
--- a/zephyr/include/drivers/cros_flash.h
+++ b/zephyr/include/drivers/cros_flash.h
@@ -46,11 +46,27 @@ typedef int (*cros_flash_api_physical_write)(const struct device *dev,
typedef int (*cros_flash_api_physical_erase)(const struct device *dev,
int offset, int size);
+typedef int (*cros_flash_api_physical_get_protect)(const struct device *dev,
+ int bank);
+
+typedef uint32_t
+(*cros_flash_api_physical_get_protect_flags)(const struct device *dev);
+
+typedef int (*cros_flash_api_physical_protect_at_boot)(const struct device *dev,
+ uint32_t new_flags);
+
+typedef int (*cros_flash_api_physical_protect_now)(const struct device *dev,
+ int all);
+
__subsystem struct cros_flash_driver_api {
cros_flash_api_init init;
cros_flash_api_physical_read physical_read;
cros_flash_api_physical_write physical_write;
cros_flash_api_physical_erase physical_erase;
+ cros_flash_api_physical_get_protect physical_get_protect;
+ cros_flash_api_physical_get_protect_flags physical_get_protect_flags;
+ cros_flash_api_physical_protect_at_boot physical_protect_at_boot;
+ cros_flash_api_physical_protect_now physical_protect_now;
};
/**
@@ -166,6 +182,106 @@ static inline int z_impl_cros_flash_physical_erase(const struct device *dev,
}
/**
+ * @brief Read physical write protect setting for a flash bank.
+ *
+ * @param dev Pointer to the device structure for the flash driver instance.
+ * @param bank Bank index to check.
+ *
+ * @return non-zero if bank is protected until reboot.
+ * @retval -ENOTSUP Not supported api function.
+ */
+__syscall int cros_flash_physical_get_protect(const struct device *dev,
+ int bank);
+
+static inline int
+z_impl_cros_flash_physical_get_protect(const struct device *dev, int bank)
+{
+ const struct cros_flash_driver_api *api =
+ (const struct cros_flash_driver_api *)dev->api;
+
+ if (!api->physical_get_protect) {
+ return -ENOTSUP;
+ }
+
+ return api->physical_get_protect(dev, bank);
+}
+
+/**
+ * @brief Return flash protect state flags from the physical layer.
+ *
+ * @param dev Pointer to the device structure for the flash driver instance.
+ *
+ * @retval -ENOTSUP Not supported api function.
+ */
+__syscall
+uint32_t cros_flash_physical_get_protect_flags(const struct device *dev);
+
+static inline uint32_t
+z_impl_cros_flash_physical_get_protect_flags(const struct device *dev)
+{
+ const struct cros_flash_driver_api *api =
+ (const struct cros_flash_driver_api *)dev->api;
+
+ if (!api->physical_get_protect_flags) {
+ return -ENOTSUP;
+ }
+
+ return api->physical_get_protect_flags(dev);
+}
+
+/**
+ * @brief Enable/disable protecting firmware/pstate at boot.
+ *
+ * @param dev Pointer to the device structure for the flash driver instance.
+ * @param new_flags to protect (only EC_FLASH_PROTECT_*_AT_BOOT are
+ * taken care of)
+ *
+ * @return 0 If successful.
+ * @retval -ENOTSUP Not supported api function.
+ */
+__syscall int cros_flash_physical_protect_at_boot(const struct device *dev,
+ uint32_t new_flags);
+
+static inline int
+z_impl_cros_flash_physical_protect_at_boot(const struct device *dev,
+ uint32_t new_flags)
+{
+ const struct cros_flash_driver_api *api =
+ (const struct cros_flash_driver_api *)dev->api;
+
+ if (!api->physical_protect_at_boot) {
+ return -ENOTSUP;
+ }
+
+ return api->physical_protect_at_boot(dev, new_flags);
+}
+
+/**
+ * @brief Protect now physical flash.
+ *
+ * @param dev Pointer to the device structure for the flash driver instance.
+ * @param all Protect all (=1) or just read-only and pstate (=0).
+ *
+ * @return 0 If successful.
+ * @retval -ENOTSUP Not supported api function.
+ */
+__syscall int cros_flash_physical_protect_now(const struct device *dev,
+ int all);
+
+static inline int
+z_impl_cros_flash_physical_protect_now(const struct device *dev, int all)
+{
+ const struct cros_flash_driver_api *api =
+ (const struct cros_flash_driver_api *)dev->api;
+
+ if (!api->physical_protect_now) {
+ return -ENOTSUP;
+ }
+
+ return api->physical_protect_now(dev, all);
+}
+
+/**
* @}
*/
#include <syscalls/cros_flash.h>