diff --git a/include/ipc/ipc_service.h b/include/ipc/ipc_service.h index 6755f3ccc83..0cf631aa188 100644 --- a/include/ipc/ipc_service.h +++ b/include/ipc/ipc_service.h @@ -116,6 +116,21 @@ struct ipc_ept_cfg { void *priv; }; +/** @brief Open an instance + * + * Function to be used to open an instance before being able to register a new + * endpoint on it. + * + * @retval -EINVAL when instance configuration is invalid. + * @retval -EIO when no backend is registered. + * @retval -EALREADY when the instance is already opened (or being opened). + * + * @retval 0 on success or when not implemented on the backend (not needed). + * @retval other errno codes depending on the implementation of the backend. + */ +int ipc_service_open_instance(const struct device *instance); + + /** @brief Register IPC endpoint onto an instance. * * Registers IPC endpoint onto an instance to enable communication with a diff --git a/include/ipc/ipc_service_backend.h b/include/ipc/ipc_service_backend.h index 486d3cc98b4..53e546d49cf 100644 --- a/include/ipc/ipc_service_backend.h +++ b/include/ipc/ipc_service_backend.h @@ -25,6 +25,18 @@ extern "C" { * This structure is used for configuration backend during registration. */ struct ipc_service_backend { + /** @brief Pointer to the function that will be used to open an instance + * + * @param instance Instance pointer. + * + * @retval -EALREADY when the instance is already opened. + * + * @retval 0 on success + * @retval other errno codes depending on the implementation of the + * backend. + */ + int (*open_instance)(const struct device *instance); + /** @brief Pointer to the function that will be used to send data to the endpoint. * * @param instance Instance pointer. diff --git a/subsys/ipc/ipc_service/ipc_service.c b/subsys/ipc/ipc_service/ipc_service.c index 040223bc4e3..ca3efb34ac5 100644 --- a/subsys/ipc/ipc_service/ipc_service.c +++ b/subsys/ipc/ipc_service/ipc_service.c @@ -14,6 +14,30 @@ LOG_MODULE_REGISTER(ipc_service, CONFIG_IPC_SERVICE_LOG_LEVEL); +int ipc_service_open_instance(const struct device *instance) +{ + const struct ipc_service_backend *backend; + + if (!instance) { + LOG_ERR("Invalid instance"); + return -EINVAL; + } + + backend = (const struct ipc_service_backend *) instance->api; + + if (!backend) { + LOG_ERR("Invalid backend configuration"); + return -EIO; + } + + if (!backend->open_instance) { + /* maybe not needed on backend */ + return 0; + } + + return backend->open_instance(instance); +} + int ipc_service_register_endpoint(const struct device *instance, struct ipc_ept *ept, const struct ipc_ept_cfg *cfg)