1 /*
2  * Copyright (c) 2016 Intel Corporation.
3  *
4  * SPDX-License-Identifier: Apache-2.0
5  */
6 
7 /**
8  * @file
9  * @brief Disk Access layer API
10  *
11  * This file contains APIs for disk access.
12  */
13 
14 #ifndef ZEPHYR_INCLUDE_STORAGE_DISK_ACCESS_H_
15 #define ZEPHYR_INCLUDE_STORAGE_DISK_ACCESS_H_
16 
17 /**
18  * @brief Storage APIs
19  * @defgroup storage_apis Storage APIs
20  * @ingroup os_services
21  * @{
22  * @}
23  */
24 
25 /**
26  * @brief Disk Access APIs
27  * @defgroup disk_access_interface Disk Access Interface
28  * @ingroup storage_apis
29  * @{
30  */
31 
32 #include <zephyr/drivers/disk.h>
33 
34 #ifdef __cplusplus
35 extern "C" {
36 #endif
37 
38 /**
39  * @brief perform any initialization
40  *
41  * This call is made by the consumer before doing any IO calls so that the
42  * disk or the backing device can do any initialization.
43  *
44  * @param[in] pdrv          Disk name
45  *
46  * @return 0 on success, negative errno code on fail
47  */
48 int disk_access_init(const char *pdrv);
49 
50 /**
51  * @brief Get the status of disk
52  *
53  * This call is used to get the status of the disk
54  *
55  * @param[in] pdrv          Disk name
56  *
57  * @return DISK_STATUS_OK or other DISK_STATUS_*s
58  */
59 int disk_access_status(const char *pdrv);
60 
61 /**
62  * @brief read data from disk
63  *
64  * Function to read data from disk to a memory buffer.
65  *
66  * Note: if he disk is of NVMe type, user will need to ensure data_buf
67  *       pointer is 4-bytes aligned.
68  *
69  * @param[in] pdrv          Disk name
70  * @param[in] data_buf      Pointer to the memory buffer to put data.
71  * @param[in] start_sector  Start disk sector to read from
72  * @param[in] num_sector    Number of disk sectors to read
73  *
74  * @return 0 on success, negative errno code on fail
75  */
76 int disk_access_read(const char *pdrv, uint8_t *data_buf,
77 		     uint32_t start_sector, uint32_t num_sector);
78 
79 /**
80  * @brief write data to disk
81  *
82  * Function write data from memory buffer to disk.
83  *
84  * Note: if he disk is of NVMe type, user will need to ensure data_buf
85  *       pointer is 4-bytes aligned.
86  *
87  * @param[in] pdrv          Disk name
88  * @param[in] data_buf      Pointer to the memory buffer
89  * @param[in] start_sector  Start disk sector to write to
90  * @param[in] num_sector    Number of disk sectors to write
91  *
92  * @return 0 on success, negative errno code on fail
93  */
94 int disk_access_write(const char *pdrv, const uint8_t *data_buf,
95 		      uint32_t start_sector, uint32_t num_sector);
96 
97 /**
98  * @brief Get/Configure disk parameters
99  *
100  * Function to get disk parameters and make any special device requests.
101  *
102  * @param[in] pdrv          Disk name
103  * @param[in] cmd           DISK_IOCTL_* code describing the request
104  * @param[in] buff          Command data buffer
105  *
106  * @return 0 on success, negative errno code on fail
107  */
108 int disk_access_ioctl(const char *pdrv, uint8_t cmd, void *buff);
109 
110 #ifdef __cplusplus
111 }
112 #endif
113 
114 /**
115  * @}
116  */
117 
118 #endif /* ZEPHYR_INCLUDE_STORAGE_DISK_ACCESS_H_ */
119