Skip to content

Commit 46def99

Browse files
committed
Merge branch 'feature/esp_blockdev_updates' into 'master'
fix(storage): BDL interface comprehensive update See merge request espressif/esp-idf!42371
2 parents 75305c2 + 832b8f8 commit 46def99

File tree

1 file changed

+49
-36
lines changed

1 file changed

+49
-36
lines changed

components/esp_blockdev/include/esp_blockdev.h

Lines changed: 49 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#include <stdarg.h>
1212
#include <stdbool.h>
1313
#include "esp_err.h"
14-
#include "sdkconfig.h"
1514

1615
#ifdef __cplusplus
1716
extern "C" {
@@ -28,34 +27,23 @@ extern "C" {
2827

2928
/**
3029
* @brief Block device I/O control commands
30+
*
31+
* The commands are grouped into two categories: system and user.
32+
* The system commands are used for internal device management and are not expected to be used by the user (values 0-127).
33+
* The user commands are used for user-specific operations and are expected to be defined by the user (values 128-255).
3134
*/
32-
typedef enum {
33-
ESP_BLOCKDEV_CMD_ERASE, /*!< perform device specific ERASE operation */
34-
ESP_BLOCKDEV_CMD_TRIM, /*!< perform device specific TRIM operation */
35-
ESP_BLOCKDEV_CMD_DISCARD, /*!< perform device specific DISCARD operation */
36-
ESP_BLOCKDEV_CMD_SANITIZE, /*!< perform device specific SANITIZE operation */
37-
ESP_BLOCKDEV_CMD_SECTOR_SIZE, /*!< get device sector size (not necessarily equal to specific block size) */
38-
ESP_BLOCKDEV_CMD_DBG_INFO, /*!< get device debug information */
39-
ESP_BLOCKDEV_CMD_STATISTICS /*!< get device operation statistics */
40-
} esp_blockdev_ioctl_cmd_t;
35+
36+
#define ESP_BLOCKDEV_CMD_SYSTEM_BASE 0x00 /*!< System commands base value */
37+
#define ESP_BLOCKDEV_CMD_USER_BASE 0x80 /*!< User commands base value */
38+
39+
#define ESP_BLOCKDEV_CMD_MARK_DELETED ESP_BLOCKDEV_CMD_SYSTEM_BASE /*!< mark given range as invalid, data to be deleted/overwritten eventually */
40+
#define ESP_BLOCKDEV_CMD_ERASE_CONTENTS ESP_BLOCKDEV_CMD_SYSTEM_BASE + 1 /*!< erase required range and set the contents to the device's default bit values */
4141

4242
typedef struct esp_blockdev_cmd_arg_erase_t {
4343
uint64_t start_addr; /*!< IN - starting address of the disk space to erase/trim/discard/sanitize (in bytes), must be a multiple of erase block size */
4444
size_t erase_len; /*!< IN - size of the area to erase/trim/discard/sanitize (in bytes), must be a multiple of erase block size */
4545
} esp_blockdev_cmd_arg_erase_t;
4646

47-
typedef struct esp_blockdev_cmd_arg_dbginfo_t esp_blockdev_cmd_arg_dbginfo_t;
48-
typedef struct esp_blockdev_cmd_arg_dbginfo_t {
49-
uint32_t device_bdl_version; /*!< OUT - device BDL interface version */
50-
bool get_device_chain; /*!< IN - require debug info from the underlying device (true/false) */
51-
esp_blockdev_cmd_arg_dbginfo_t* bottom_device; /*!< OUT - optional parameter to retrieve the debug info of the underlying device.
52-
Used when 'get_device_chain' flag is True. To be freed by the topmost caller */
53-
} esp_blockdev_cmd_arg_dbginfo_t;
54-
55-
typedef struct esp_blockdev_cmd_arg_stat_t {
56-
uint64_t available_space; /*!< OUT - remaining disk space (in bytes) */
57-
} esp_blockdev_cmd_arg_stat_t;
58-
5947
/**
6048
* @brief Block device property flags
6149
*
@@ -119,6 +107,7 @@ typedef struct esp_blockdev_geometry_t {
119107

120108
/** Minimum block size (in bytes) for erase operations on given device.
121109
* Mandatory parameter for all R/W devices, 0 for R/O.
110+
* @note Typically used as a sector size in file system meaning.
122111
* */
123112
size_t erase_size;
124113

@@ -134,6 +123,7 @@ typedef struct esp_blockdev_geometry_t {
134123

135124
/** Default erase block size (in bytes) of given device. Recommended for optimal performance.
136125
* 0 means not used.
126+
* @note Typically used as target hardware erase block size.
137127
* */
138128
size_t recommended_erase_size;
139129

@@ -143,19 +133,14 @@ typedef struct esp_blockdev_geometry_t {
143133
* Allocated and initialized by the device's class factory, optionally closed by the device release handler.
144134
*/
145135
typedef struct esp_blockdev_t* esp_blockdev_handle_t;
136+
#define ESP_BLOCKDEV_HANDLE_INVALID NULL
146137

147138
/**
148-
* @brief IDF generic Block device interface structure
149-
* This structure defines an interface for a generic block-device capable of common disk operations and providing properties important
150-
* for the device's deployment into the target component stack.
139+
* @brief Block device operations
140+
*
141+
* Various block operations needed for proper R/W/E processing on given device.
151142
*/
152-
typedef struct esp_blockdev_t {
153-
154-
/* Device flags */
155-
esp_blockdev_flags_t device_flags;
156-
157-
/* Block device geometry parameters */
158-
esp_blockdev_geometry_t geometry;
143+
typedef struct esp_blockdev_ops_t {
159144

160145
/** READ operation:
161146
* Read required number of bytes from the device at given offset, store the data into the output buffer.
@@ -200,13 +185,41 @@ typedef struct esp_blockdev_t {
200185

201186
/** IOCTL operation:
202187
* I/O control commands. Each command has corresponding in/out parameters which are to be verified
203-
* within given ioctl handler.
188+
* within given ioctl handler. The commands can be extended by the device implementation within the following ranges:
189+
* - 0x00-0x7F: IDF device commands (system)
190+
* - 0x80-0xFF: user-defined commands
191+
* See ESP_BLOCKDEV_CMD* macros.
204192
*
205193
* @param dev_handle Target device handle
206-
* @param cmd Command ID as given by esp_block_dev_ioctl_cmd enumeration
207-
* @param args Command specific arguments, see esp_block_dev_ioctl_cmd details
194+
* @param cmd Command ID
195+
* @param args Command specific arguments
196+
* */
197+
esp_err_t (*ioctl)(esp_blockdev_handle_t dev_handle, const uint8_t cmd, void* args);
198+
199+
/** Instance destructor:
200+
* Cleanup code for the specific device handle
201+
* @param dev_handle Target device handle
208202
* */
209-
esp_err_t (*ioctl)(esp_blockdev_handle_t dev_handle, const esp_blockdev_ioctl_cmd_t cmd, void* args);
203+
esp_err_t (*release)(esp_blockdev_handle_t dev_handle);
204+
205+
} esp_blockdev_ops_t;
206+
207+
/**
208+
* @brief IDF generic Block device interface structure
209+
* This structure defines an interface for a generic block-device capable of common disk operations and providing properties important
210+
* for the device's deployment into the target component stack.
211+
*
212+
* @note The device context pointer is used to store the device-specific context. It is not used by the BDL layer and is intended to be used by the device implementation.
213+
* @note The ops pointer holds the address of the device operations structure which can be shared by multiple device instances of the same type (driver).
214+
*/
215+
typedef struct esp_blockdev_t {
216+
217+
/* Device context pointer */
218+
void* ctx;
219+
220+
const esp_blockdev_flags_t device_flags;
221+
const esp_blockdev_geometry_t geometry;
222+
const esp_blockdev_ops_t* ops;
210223

211224
} esp_blockdev_t;
212225

0 commit comments

Comments
 (0)