1 /*
2 * rpmb_driver.c
3 *
4 * rpmb driver function, such as ioctl
5 *
6 * Copyright (C) 2022 Huawei Technologies Co., Ltd.
7 *
8 * This software is licensed under the terms of the GNU General Public
9 * License version 2, as published by the Free Software Foundation, and
10 * may be copied, distributed, and modified under those terms.
11 *
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
16 */
17 #include "rpmb_driver.h"
18 #include <linux/kallsyms.h>
19 #include "tc_ns_log.h"
20
21 typedef int *(rpmb_ioctl_func)(enum func_id id, enum rpmb_op_type operation,
22 struct storage_blk_ioc_rpmb_data *storage_data);
23
rpmb_ioctl_cmd(enum func_id id,enum rpmb_op_type operation,struct storage_blk_ioc_rpmb_data * storage_data)24 int rpmb_ioctl_cmd(enum func_id id, enum rpmb_op_type operation,
25 struct storage_blk_ioc_rpmb_data *storage_data)
26 {
27 static rpmb_ioctl_func *rpmb_ioctl = NULL;
28
29 if (storage_data == NULL)
30 return NULL;
31
32 if (rpmb_ioctl == NULL) {
33 #if (LINUX_VERSION_CODE >= KERNEL_VERSION(5, 10, 0))
34 rpmb_ioctl =
35 (rpmb_ioctl_func *)(uintptr_t)__symbol_get("vendor_rpmb_ioctl_cmd");
36 #else
37 rpmb_ioctl =
38 (rpmb_ioctl_func *)(uintptr_t)kallsyms_lookup_name("vendor_rpmb_ioctl_cmd");
39 #endif
40 if (rpmb_ioctl == NULL) {
41 tloge("fail to find symbol vendor_rpmb_ioctl_cmd\n");
42 return NULL;
43 }
44 }
45 return rpmb_ioctl(id, operation, storage_data);
46 }
47