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 MMC_BLOCK_H
10 #define MMC_BLOCK_H
11 
12 #include "mmc_corex.h"
13 
14 #ifdef __cplusplus
15 #if __cplusplus
16 extern "C" {
17 #endif
18 #endif /* __cplusplus */
19 
20 /**
21  * @Defines the default mmc sector size
22  *
23  */
24 #define MMC_SEC_SIZE  512
25 
26 /**
27  * @Defines the default mmc sector size shift
28  *
29  */
30 #define MMC_SEC_SHIFT 9
31 
32 /**
33  * @Defines the help macro for getting sector number
34  *
35  */
36 #define MMC_MAX_SEC_NR (MMC_MAX_BYTES >> MMC_SEC_SHIFT)
37 
38 #define MMC_SEC_PARAM_INVALID(s, n) \
39     ((s) >= MMC_MAX_SEC_NR || \
40     (n) >= MMC_MAX_SEC_NR || \
41     (MMC_MAX_SEC_NR - (n)) <= (s))
42 
43 /**
44  * @Defines the max length of mmc block device name
45  *
46  */
47 #define MMC_BLOCK_NAME_LEN 32
48 
49 /**
50  * @Defines the structure used to identify a general block device.
51  *
52  */
53 struct MmcBlock {
54     char name[MMC_BLOCK_NAME_LEN]; /* name of the block device */
55     int32_t index;
56     bool removable;
57     size_t capacity;               /* sized by sector */
58     size_t secSize;                /* sized by bytes */
59     uint32_t errCnt;               /* err count on io transfer */
60     void *bops;                    /* block operations of specific os */
61     void *osData;                  /* os specific data */
62     struct MmcDevice *mmc;
63 };
64 
65 /**
66  * @brief Block device init for the mmc  device.
67  *
68  * This function behaves differently in different OS
69  *
70  * @param mmcDevice Indicates the pointer to the mmc device.
71  *
72  * @return Returns 0 if init successfully; returns a negative value otherwise.
73  */
74 int32_t MmcBlockInit(struct MmcDevice *mmcDevice);
75 
76 /**
77  * @brief Block device uninit for the mmc device.
78  *
79  * This function behaves differently in different OS
80  *
81  * @param mmcDevice Indicates the pointer to the mmc device.
82  *
83  */
84 void MmcBlockUninit(struct MmcDevice *mmcDevice);
85 
86 /**
87  * @brief Block device init for the mmc device in specific os.
88  *
89  * These function gona be implemented by specific os
90  *
91  * @param mmcDevice Indicates the pointer to the mmc device.
92  *
93  * @return Returns 0 if init successfully; returns a negative value otherwise.
94  */
95 int32_t MmcBlockOsInit(struct MmcDevice *mmcDevice);
96 
97 /**
98  * @brief Block device uninit for the mmc device in specific os.
99  *
100  * These function gona be implemented by specific os
101  *
102  * @param mmcDevice Indicates the pointer to the mmc device.
103  *
104  */
105 void MmcBlockOsUninit(struct MmcDevice *mmcDevice);
106 
107 #ifdef __cplusplus
108 #if __cplusplus
109 }
110 #endif
111 #endif /* __cplusplus */
112 
113 #endif /* MMC_BLOCK_H */
114