1 /*
2  * Copyright (c) 2020-2021 Huawei Device Co., Ltd.
3  *
4  * HDF is dual licensed: you can use it either under the terms of
5  * the GPL, or the BSD license, at your option.
6  * See the LICENSE file in the root of this repository for complete details.
7  */
8 
9 #ifndef HDF_SEC_H
10 #define HDF_SEC_H
11 
12 #if defined(__KERNEL__)
13 #include <linux/ioctl.h>
14 #include <linux/types.h>
15 #else
16 #include <sys/ioctl.h>
17 #include <stddef.h>
18 #include <stdint.h>
19 #endif
20 
21 #ifdef __cplusplus
22 #if __cplusplus
23 extern "C" {
24 #endif
25 #endif /* __cplusplus */
26 
27 #define DEVICE_HDF_SECURE_NAME "hdf_secure"
28 #define HDF_SECURE_MAGIC 'S'
29 
30 /* event commands */
31 #define HDF_SECURE_SET_INFO _IO(HDF_SECURE_MAGIC, 0x1)
32 #define HDF_SECURE_SET_CURRENT_ID _IO(HDF_SECURE_MAGIC, 0x2)
33 #define HDF_SECURE_DELETE_INFO _IO(HDF_SECURE_MAGIC, 0x3)
34 
35 #define HDF_DECLARE_BITMAP(name, bits) \
36     uint64_t name[HDF_BITS_TO_LONGS(bits)]
37 #define HDF_BITS_TO_LONGS(nr) HDF_DIV_ROUND_UP(nr, HDF_BITS_PER_BYTE * sizeof(uint64_t))
38 #define HDF_DIV_ROUND_UP(n, d) (((n) + (d) - 1) / (d))
39 #define HDF_BITS_PER_BYTE 8
40 
41 #define SECMAP_MAX_SIZE 64
42 #define ID_MAX_SIZE 65
43 
44 struct SecInfo {
45     char secId[ID_MAX_SIZE];
46     HDF_DECLARE_BITMAP(secMap, SECMAP_MAX_SIZE);
47 };
48 uint32_t HdfPermissionCheck(uint8_t type);
49 
50 #ifdef __cplusplus
51 #if __cplusplus
52 }
53 #endif
54 #endif /* __cplusplus */
55 
56 #endif /* HDF_SEC_H */
57