diff --git a/docs/api-reference.md b/docs/api-reference.md index 6cb8209..4a830e2 100644 --- a/docs/api-reference.md +++ b/docs/api-reference.md @@ -18,6 +18,11 @@ usable either directly or transparently through `dmdevfs`/`/dev`. ## IOCTL commands (`dmfmc_ioctl_cmd_t`) +Commands are numbered from `DMDRVI_IOCTL_CUSTOM_BASE` so they do not +collide with the standard `DMDRVI_IOCTL_*` commands. Any command outside this +range (e.g. the `DMDRVI_IOCTL_BLOCK_GET_INFO` / `DMDRVI_IOCTL_MONITOR_GET_POLICY` +probes sent by dmdevfs) is answered with `-ENOTTY`. + | Command | `arg` type | Meaning | |---------|-----------|---------| | `dmfmc_ioctl_cmd_get_memory_start` | `void **` | Direct pointer to the mapped memory. | diff --git a/include/dmfmc_types.h b/include/dmfmc_types.h index 78180d2..f5e6da4 100644 --- a/include/dmfmc_types.h +++ b/include/dmfmc_types.h @@ -2,6 +2,7 @@ #define DMFMC_TYPES_H #include +#include "dmdrvi_ioctl.h" #include #include @@ -185,7 +186,10 @@ typedef enum */ typedef enum { - dmfmc_ioctl_cmd_get_memory_start = 1, /**< arg = void** - direct pointer to the mapped memory */ + /* Private commands start at DMDRVI_IOCTL_CUSTOM_BASE (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. */ + dmfmc_ioctl_cmd_get_memory_start = DMDRVI_IOCTL_CUSTOM_BASE, /**< arg = void** - direct pointer to the mapped memory */ dmfmc_ioctl_cmd_get_memory_size, /**< arg = uint32_t* - size in bytes of the mapped memory */ dmfmc_ioctl_cmd_get_configured_frequency, /**< arg = uint32_t* - SDCLK frequency actually configured (Hz) */ dmfmc_ioctl_cmd_get_heap_context, /**< arg = dmheap_context_t** - heap context, or NULL if not used as heap */ diff --git a/src/dmfmc.c b/src/dmfmc.c index c5fdb25..3d656a2 100644 --- a/src/dmfmc.c +++ b/src/dmfmc.c @@ -503,10 +503,12 @@ dmod_dmdrvi_dif_api_declaration(2.0, dmfmc, int, _ioctl, ( dmdrvi_context_t cont return -EINVAL; } - if (command >= dmfmc_ioctl_cmd_max) + /* Not an error: generic clients (e.g. dmdevfs probing every node for the + * block/monitor classes) send standard DMDRVI_IOCTL_* commands the FMC + * does not implement - answer -ENOTTY quietly, as dmdrvi expects. */ + if (command < dmfmc_ioctl_cmd_get_memory_start || command >= dmfmc_ioctl_cmd_max) { - DMOD_LOG_ERROR("Invalid ioctl command %d\n", command); - return -EINVAL; + return -ENOTTY; } switch (command) @@ -555,7 +557,7 @@ dmod_dmdrvi_dif_api_declaration(2.0, dmfmc, int, _ioctl, ( dmdrvi_context_t cont return configure(context); default: - return -EINVAL; + return -ENOTTY; } } diff --git a/src/port/CMakeLists.txt b/src/port/CMakeLists.txt index 671c696..f9dcdff 100644 --- a/src/port/CMakeLists.txt +++ b/src/port/CMakeLists.txt @@ -38,8 +38,10 @@ dmod_add_library(${DMOD_MODULE_NAME} ${DMOD_MODULE_VERSION} ${COMMON_SOURCES} ) +# dmdrvi: dmfmc_types.h pulls in dmdrvi_ioctl.h (DMDRVI_IOCTL_CUSTOM_BASE) dmod_link_modules(${DMOD_MODULE_NAME} dmclk_port + dmdrvi ) target_include_directories(${DMOD_MODULE_NAME} BEFORE PRIVATE