Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion include/dmdma_types.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,7 +196,10 @@ typedef enum
*/
typedef enum
{
dmdma_ioctl_cmd_start_transfer = 1, /**< arg = const dmdma_transfer_config_t* - configure and start */
/* Private commands start at DMDRVI_IOCTL_CUSTOM_BASE (0x1000, dmdrvi_ioctl.h)
* so they never collide with the standard DMDRVI_IOCTL_* commands (network,
* block, monitor) that dmdevfs and other generic clients send to any node. */
dmdma_ioctl_cmd_start_transfer = 0x1000, /**< arg = const dmdma_transfer_config_t* - configure and start */
dmdma_ioctl_cmd_stop_transfer, /**< Abort a transfer in progress; arg = NULL */
dmdma_ioctl_cmd_is_busy, /**< arg = bool* - whether a transfer is currently in flight */
dmdma_ioctl_cmd_get_remaining, /**< arg = size_t* - elements left in the current/last transfer */
Expand Down
15 changes: 11 additions & 4 deletions src/dmdma.c
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@
/* "DMDA" packed into a uint32_t - see dmdrvi context magic-field convention */
#define DMDMA_CONTEXT_MAGIC 0x444D4441UL

#ifdef DMDRVI_IOCTL_CUSTOM_BASE
_Static_assert(dmdma_ioctl_cmd_start_transfer == DMDRVI_IOCTL_CUSTOM_BASE,
"dmdma private ioctl commands must start at DMDRVI_IOCTL_CUSTOM_BASE");
#endif

/* Generous upper bound on physical DMA controllers a board can have - real
* hardware (STM32F4/F7) has at most 2. */
#define DMDMA_MAX_CONTROLLERS 4U
Expand Down Expand Up @@ -655,10 +660,12 @@ dmod_dmdrvi_dif_api_declaration(2.0, dmdma, int, _ioctl,
return -EINVAL;
}

if (command < 0 || command >= dmdma_ioctl_cmd_max)
/* Not an error: generic clients (e.g. dmdevfs probing every node for the
* block/monitor classes) send standard DMDRVI_IOCTL_* commands a DMA stream
* does not implement - answer -ENOTTY quietly, as dmdrvi expects. */
if (command < dmdma_ioctl_cmd_start_transfer || command >= dmdma_ioctl_cmd_max)
{
DMOD_LOG_ERROR("Invalid ioctl command %d\n", command);
return -EINVAL;
return -ENOTTY;
}

dmdma_controller_t controller = context->config.controller;
Expand Down Expand Up @@ -713,7 +720,7 @@ dmod_dmdrvi_dif_api_declaration(2.0, dmdma, int, _ioctl,
return 0;

default:
return -EINVAL;
return -ENOTTY;
}
}

Expand Down
Loading