1 /* SPDX-License-Identifier: GPL-2.0 */ 1 /* SPDX-License-Identifier: GPL-2.0 */ 2 /* 2 /* 3 * Copyright (C) 2015-2019 Intel Corp. All rig 3 * Copyright (C) 2015-2019 Intel Corp. All rights reserved 4 * Copyright (C) 2021-2022 Linaro Ltd 4 * Copyright (C) 2021-2022 Linaro Ltd 5 */ 5 */ 6 #ifndef __RPMB_H__ 6 #ifndef __RPMB_H__ 7 #define __RPMB_H__ 7 #define __RPMB_H__ 8 8 9 #include <linux/device.h> 9 #include <linux/device.h> 10 #include <linux/types.h> 10 #include <linux/types.h> 11 11 12 /** 12 /** 13 * enum rpmb_type - type of underlying storage 13 * enum rpmb_type - type of underlying storage technology 14 * 14 * 15 * @RPMB_TYPE_EMMC : emmc (JESD84-B50.1) 15 * @RPMB_TYPE_EMMC : emmc (JESD84-B50.1) 16 * @RPMB_TYPE_UFS : UFS (JESD220) 16 * @RPMB_TYPE_UFS : UFS (JESD220) 17 * @RPMB_TYPE_NVME : NVM Express 17 * @RPMB_TYPE_NVME : NVM Express 18 */ 18 */ 19 enum rpmb_type { 19 enum rpmb_type { 20 RPMB_TYPE_EMMC, 20 RPMB_TYPE_EMMC, 21 RPMB_TYPE_UFS, 21 RPMB_TYPE_UFS, 22 RPMB_TYPE_NVME, 22 RPMB_TYPE_NVME, 23 }; 23 }; 24 24 25 /** 25 /** 26 * struct rpmb_descr - RPMB description provid 26 * struct rpmb_descr - RPMB description provided by the underlying block device 27 * 27 * 28 * @type : block device type 28 * @type : block device type 29 * @route_frames : routes frames to and fr 29 * @route_frames : routes frames to and from the RPMB device 30 * @dev_id : unique device identifie 30 * @dev_id : unique device identifier read from the hardware 31 * @dev_id_len : length of unique device 31 * @dev_id_len : length of unique device identifier 32 * @reliable_wr_count: number of sectors that 32 * @reliable_wr_count: number of sectors that can be written in one access 33 * @capacity : capacity of the device 33 * @capacity : capacity of the device in units of 128K 34 * 34 * 35 * @dev_id is intended to be used as input whe 35 * @dev_id is intended to be used as input when deriving the authenticaion key. 36 */ 36 */ 37 struct rpmb_descr { 37 struct rpmb_descr { 38 enum rpmb_type type; 38 enum rpmb_type type; 39 int (*route_frames)(struct device *dev 39 int (*route_frames)(struct device *dev, u8 *req, unsigned int req_len, 40 u8 *resp, unsigned 40 u8 *resp, unsigned int resp_len); 41 u8 *dev_id; 41 u8 *dev_id; 42 size_t dev_id_len; 42 size_t dev_id_len; 43 u16 reliable_wr_count; 43 u16 reliable_wr_count; 44 u16 capacity; 44 u16 capacity; 45 }; 45 }; 46 46 47 /** 47 /** 48 * struct rpmb_dev - device which can support 48 * struct rpmb_dev - device which can support RPMB partition 49 * 49 * 50 * @dev : device 50 * @dev : device 51 * @id : device_id 51 * @id : device_id 52 * @list_node : linked list node 52 * @list_node : linked list node 53 * @descr : RPMB description 53 * @descr : RPMB description 54 */ 54 */ 55 struct rpmb_dev { 55 struct rpmb_dev { 56 struct device dev; 56 struct device dev; 57 int id; 57 int id; 58 struct list_head list_node; 58 struct list_head list_node; 59 struct rpmb_descr descr; 59 struct rpmb_descr descr; 60 }; 60 }; 61 61 62 #define to_rpmb_dev(x) container_of(( 62 #define to_rpmb_dev(x) container_of((x), struct rpmb_dev, dev) 63 63 64 #if IS_ENABLED(CONFIG_RPMB) 64 #if IS_ENABLED(CONFIG_RPMB) 65 struct rpmb_dev *rpmb_dev_get(struct rpmb_dev 65 struct rpmb_dev *rpmb_dev_get(struct rpmb_dev *rdev); 66 void rpmb_dev_put(struct rpmb_dev *rdev); 66 void rpmb_dev_put(struct rpmb_dev *rdev); 67 struct rpmb_dev *rpmb_dev_find_device(const vo 67 struct rpmb_dev *rpmb_dev_find_device(const void *data, 68 const st 68 const struct rpmb_dev *start, 69 int (*ma 69 int (*match)(struct device *dev, 70 70 const void *data)); 71 int rpmb_interface_register(struct class_inter 71 int rpmb_interface_register(struct class_interface *intf); 72 void rpmb_interface_unregister(struct class_in 72 void rpmb_interface_unregister(struct class_interface *intf); 73 struct rpmb_dev *rpmb_dev_register(struct devi 73 struct rpmb_dev *rpmb_dev_register(struct device *dev, 74 struct rpmb 74 struct rpmb_descr *descr); 75 int rpmb_dev_unregister(struct rpmb_dev *rdev) 75 int rpmb_dev_unregister(struct rpmb_dev *rdev); 76 76 77 int rpmb_route_frames(struct rpmb_dev *rdev, u 77 int rpmb_route_frames(struct rpmb_dev *rdev, u8 *req, 78 unsigned int req_len, u8 78 unsigned int req_len, u8 *resp, unsigned int resp_len); 79 79 80 #else 80 #else 81 static inline struct rpmb_dev *rpmb_dev_get(st 81 static inline struct rpmb_dev *rpmb_dev_get(struct rpmb_dev *rdev) 82 { 82 { 83 return NULL; 83 return NULL; 84 } 84 } 85 85 86 static inline void rpmb_dev_put(struct rpmb_de 86 static inline void rpmb_dev_put(struct rpmb_dev *rdev) { } 87 87 88 static inline struct rpmb_dev * 88 static inline struct rpmb_dev * 89 rpmb_dev_find_device(const void *data, const s 89 rpmb_dev_find_device(const void *data, const struct rpmb_dev *start, 90 int (*match)(struct devic 90 int (*match)(struct device *dev, const void *data)) 91 { 91 { 92 return NULL; 92 return NULL; 93 } 93 } 94 94 95 static inline int rpmb_interface_register(stru 95 static inline int rpmb_interface_register(struct class_interface *intf) 96 { 96 { 97 return -EOPNOTSUPP; 97 return -EOPNOTSUPP; 98 } 98 } 99 99 100 static inline void rpmb_interface_unregister(s 100 static inline void rpmb_interface_unregister(struct class_interface *intf) 101 { 101 { 102 } 102 } 103 103 104 static inline struct rpmb_dev * 104 static inline struct rpmb_dev * 105 rpmb_dev_register(struct device *dev, struct r 105 rpmb_dev_register(struct device *dev, struct rpmb_descr *descr) 106 { 106 { 107 return NULL; 107 return NULL; 108 } 108 } 109 109 110 static inline int rpmb_dev_unregister(struct r 110 static inline int rpmb_dev_unregister(struct rpmb_dev *dev) 111 { 111 { 112 return 0; 112 return 0; 113 } 113 } 114 114 115 static inline int rpmb_route_frames(struct rpm 115 static inline int rpmb_route_frames(struct rpmb_dev *rdev, u8 *req, 116 unsigned i 116 unsigned int req_len, u8 *resp, 117 unsigned i 117 unsigned int resp_len) 118 { 118 { 119 return -EOPNOTSUPP; 119 return -EOPNOTSUPP; 120 } 120 } 121 #endif /* CONFIG_RPMB */ 121 #endif /* CONFIG_RPMB */ 122 122 123 #endif /* __RPMB_H__ */ 123 #endif /* __RPMB_H__ */ 124 124
Linux® is a registered trademark of Linus Torvalds in the United States and other countries.
TOMOYO® is a registered trademark of NTT DATA CORPORATION.