1 /*
2  * Copyright (C) 2016 The Android Open Source Project
3  *
4  * Permission is hereby granted, free of charge, to any person
5  * obtaining a copy of this software and associated documentation
6  * files (the "Software"), to deal in the Software without
7  * restriction, including without limitation the rights to use, copy,
8  * modify, merge, publish, distribute, sublicense, and/or sell copies
9  * of the Software, and to permit persons to whom the Software is
10  * furnished to do so, subject to the following conditions:
11  *
12  * The above copyright notice and this permission notice shall be
13  * included in all copies or substantial portions of the Software.
14  *
15  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
16  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
17  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
18  * NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS
19  * BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN
20  * ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
21  * CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22  * SOFTWARE.
23  */
24 
25 #ifndef TRUSTY_RPMB_H_
26 #define TRUSTY_RPMB_H_
27 
28 #include <trusty/sysdeps.h>
29 #include <trusty/trusty_ipc.h>
30 
31 #define MMC_BLOCK_SIZE 512
32 
33 /*
34  * Initialize RPMB storage proxy. Returns one of trusty_err.
35  *
36  * @dev:      initialized with trusty_ipc_dev_create
37  * @rpmb_dev: Context of RPMB device, initialized with rpmb_storage_get_ctx
38  */
39 int rpmb_storage_proxy_init(struct trusty_ipc_dev* dev, void* rpmb_dev);
40 /*
41  * Shutdown RPMB storage proxy
42  *
43  * @dev: initialized with trusty_ipc_dev_create
44  */
45 void rpmb_storage_proxy_shutdown(struct trusty_ipc_dev* dev);
46 /*
47  * Execute RPMB command. Implementation is platform specific.
48  * Returns one of trusty_err.
49  *
50  * @rpmb_dev:            Context of RPMB device, initialized with
51  *                       rpmb_storage_get_ctx
52  * @reliable_write_data: Buffer containing RPMB structs for reliable write
53  * @reliable_write_size: Size of reliable_write_data
54  * @write_data:          Buffer containing RPMB structs for write
55  * @write_size:          Size of write_data
56  * @read_data:           Buffer to be filled with RPMB structs read from RPMB
57  *                       partition
58  * @read_size:           Size of read_data
59  */
60 int rpmb_storage_send(void* rpmb_dev,
61                       const void* reliable_write_data,
62                       size_t reliable_write_size,
63                       const void* write_data,
64                       size_t write_size,
65                       void* read_buf,
66                       size_t read_size);
67 /*
68  * Return context for RPMB device. This is called when the RPMB storage proxy is
69  * initialized, and subsequently used when issuing RPMB storage requests.
70  * Implementation is platform specific.
71  */
72 void* rpmb_storage_get_ctx(void);
73 
74 /*
75  * Release a previously obtained RPMB context.
76  * Implementation is platform specific.
77  */
78 void rpmb_storage_put_ctx(void* dev);
79 
80 #endif /* TRUSTY_RPMB_H_ */
81