diff options
-rw-r--r-- | module/mock_psu/include/mod_mock_psu.h | 45 | ||||
-rw-r--r-- | module/mock_psu/src/mod_mock_psu.c | 180 | ||||
-rw-r--r-- | product/rdn1e1/scp_ramfw/config_mock_psu.c | 4 | ||||
-rw-r--r-- | product/rdn1e1/scp_ramfw/config_psu.c | 4 | ||||
-rw-r--r-- | product/sgi575/scp_ramfw/config_mock_psu.c | 4 | ||||
-rw-r--r-- | product/sgi575/scp_ramfw/config_psu.c | 4 | ||||
-rw-r--r-- | product/sgm775/scp_ramfw/config_mock_psu.c | 8 | ||||
-rw-r--r-- | product/sgm775/scp_ramfw/config_psu.c | 8 |
8 files changed, 160 insertions, 97 deletions
diff --git a/module/mock_psu/include/mod_mock_psu.h b/module/mock_psu/include/mod_mock_psu.h index 6afd5237..e2c1128f 100644 --- a/module/mock_psu/include/mod_mock_psu.h +++ b/module/mock_psu/include/mod_mock_psu.h @@ -8,24 +8,33 @@ #ifndef MOD_MOCK_PSU_H #define MOD_MOCK_PSU_H +#include <fwk_module_idx.h> #include <stdbool.h> #include <stdint.h> -#include <fwk_module_idx.h> /*! * \ingroup GroupModules * \defgroup GroupMockPsu Mock Power Supply Driver + * + * \details The `mock_psu` module provides a mock power supply driver for use + * alongside the `psu` interface on systems that do not provide a real + * power supply. + * * \{ */ /*! * \brief Element configuration. */ -struct mod_mock_psu_device_config { - /*! Default state of the mock device's supply (enabled or disabled) */ +struct mod_mock_psu_element_cfg { + /*! + * \brief Default state of the mock device's supply (enabled or disabled). + */ bool default_enabled; - /*! Default voltage, in millivolts (mV), of the device's supply */ + /*! + * \brief Default voltage, in millivolts (mV), of the device's supply. + */ uint64_t default_voltage; }; @@ -33,16 +42,30 @@ struct mod_mock_psu_device_config { * \brief API indices. */ enum mod_mock_psu_api_idx { - /*! API index for PSU driver API */ - MOD_MOCK_PSU_API_IDX_PSU_DRIVER, + /*! + * \brief Driver API index. + * + * \note This API implements the ::mod_psu_driver_api interface. + * + * \warning Binding to this API must occur through an element of this + * module. + */ + MOD_MOCK_PSU_API_IDX_DRIVER, - /*! Number of defined APIs */ - MOD_MOCK_PSU_API_COUNT + /*! + * \brief Number of defined APIs. + */ + MOD_MOCK_PSU_API_IDX_COUNT }; -/*! Driver API identifier */ -static const fwk_id_t mod_mock_psu_api_id_psu_driver = - FWK_ID_API_INIT(FWK_MODULE_IDX_MOCK_PSU, MOD_MOCK_PSU_API_IDX_PSU_DRIVER); +/*! + * \brief Driver API identifier. + * + * \note This identifier corresponds to the ::MOD_MOCK_PSU_API_IDX_DRIVER API + * index. + */ +static const fwk_id_t mod_mock_psu_api_id_driver = + FWK_ID_API_INIT(FWK_MODULE_IDX_MOCK_PSU, MOD_MOCK_PSU_API_IDX_DRIVER); /*! * \} diff --git a/module/mock_psu/src/mod_mock_psu.c b/module/mock_psu/src/mod_mock_psu.c index d4fa6582..277738ea 100644 --- a/module/mock_psu/src/mod_mock_psu.c +++ b/module/mock_psu/src/mod_mock_psu.c @@ -5,131 +5,169 @@ * SPDX-License-Identifier: BSD-3-Clause */ -#include <stdbool.h> -#include <stddef.h> -#include <stdint.h> +#include <mod_mock_psu.h> +#include <mod_psu.h> #include <fwk_assert.h> #include <fwk_id.h> #include <fwk_macros.h> #include <fwk_mm.h> #include <fwk_module.h> #include <fwk_module_idx.h> -#include <mod_psu.h> -#include <mod_mock_psu.h> - -struct mod_mock_psu_device_ctx { - bool enabled; /* Current enabled state */ - uint64_t voltage; /* Current voltage (in mV) */ -}; +#include <stdbool.h> +#include <stddef.h> +#include <stdint.h> -static struct mod_mock_psu_device_ctx (*device_ctx)[]; +static struct mod_mock_psu_ctx { + struct mod_mock_psu_element_ctx { + bool enabled; + uint64_t voltage; + } *elements; +} mod_mock_psu_ctx; -static struct mod_mock_psu_device_ctx *get_device_ctx( - fwk_id_t device_id) +static struct mod_mock_psu_element_ctx *mod_mock_psu_get_ctx_unchecked( + fwk_id_t element_id) { - return &(*device_ctx)[fwk_id_get_element_idx(device_id)]; + unsigned int element_idx = fwk_id_get_element_idx(element_id); + + return &mod_mock_psu_ctx.elements[element_idx]; } -static struct mod_mock_psu_device_ctx *mod_mock_psu_get_valid_device_ctx( - fwk_id_t device_id) +static struct mod_mock_psu_element_ctx *mod_mock_psu_get_element_ctx( + fwk_id_t element_id) { - if (fwk_module_check_call(device_id) != FWK_SUCCESS) + if (fwk_id_get_module_idx(element_id) != FWK_MODULE_IDX_MOCK_PSU) return NULL; + else if (!fwk_module_is_valid_element_id(element_id)) + return NULL; + else + return mod_mock_psu_get_ctx_unchecked(element_id); +} + +static int mod_mock_psu_get_cfg_ctx( + fwk_id_t element_id, + const struct mod_mock_psu_element_cfg **cfg, + struct mod_mock_psu_element_ctx **ctx) +{ + int status; - return get_device_ctx(device_id); + status = fwk_module_check_call(element_id); + if (status != FWK_SUCCESS) { + status = FWK_E_STATE; + + goto exit; + } + + if (ctx != NULL) { + *ctx = mod_mock_psu_get_element_ctx(element_id); + if (ctx == NULL) { + status = FWK_E_PARAM; + + goto exit; + } + } + + if (cfg != NULL) { + *cfg = fwk_module_get_data(element_id); + fwk_assert(cfg != NULL); + } + +exit: + return status; } -static int api_set_enabled(fwk_id_t device_id, bool enable) +static int mod_mock_psu_get_enabled(fwk_id_t device_id, bool *enabled) { - struct mod_mock_psu_device_ctx *ctx; + int status; - ctx = mod_mock_psu_get_valid_device_ctx(device_id); - if (ctx == NULL) - return FWK_E_PARAM; + struct mod_mock_psu_element_ctx *ctx; - ctx->enabled = enable; + status = mod_mock_psu_get_cfg_ctx(device_id, NULL, &ctx); + if (status == FWK_SUCCESS) + *enabled = ctx->enabled; - return FWK_SUCCESS; + return status; } -static int api_get_enabled(fwk_id_t device_id, bool *enabled) +static int mod_mock_psu_set_enabled(fwk_id_t device_id, bool enabled) { - struct mod_mock_psu_device_ctx *ctx; + int status; - ctx = mod_mock_psu_get_valid_device_ctx(device_id); - if (ctx == NULL) - return FWK_E_PARAM; + struct mod_mock_psu_element_ctx *ctx; - *enabled = ctx->enabled; + status = mod_mock_psu_get_cfg_ctx(device_id, NULL, &ctx); + if (status == FWK_SUCCESS) + ctx->enabled = enabled; - return FWK_SUCCESS; + return status; } -static int api_set_voltage(fwk_id_t device_id, uint64_t voltage) +static int mod_mock_psu_get_voltage(fwk_id_t device_id, uint64_t *voltage) { - struct mod_mock_psu_device_ctx *ctx; + int status; - ctx = mod_mock_psu_get_valid_device_ctx(device_id); - if (ctx == NULL) - return FWK_E_PARAM; + struct mod_mock_psu_element_ctx *ctx; - ctx->voltage = voltage; + status = mod_mock_psu_get_cfg_ctx(device_id, NULL, &ctx); + if (status == FWK_SUCCESS) + *voltage = ctx->voltage; - return FWK_SUCCESS; + return status; } -static int api_get_voltage(fwk_id_t device_id, uint64_t *voltage) +static int mod_mock_psu_set_voltage(fwk_id_t device_id, uint64_t voltage) { - struct mod_mock_psu_device_ctx *ctx; + int status; - ctx = mod_mock_psu_get_valid_device_ctx(device_id); - if (ctx == NULL) - return FWK_E_PARAM; + struct mod_mock_psu_element_ctx *ctx; - *voltage = ctx->voltage; + status = mod_mock_psu_get_cfg_ctx(device_id, NULL, &ctx); + if (status == FWK_SUCCESS) + ctx->voltage = voltage; - return FWK_SUCCESS; + return status; } -static const struct mod_psu_driver_api mod_mock_psu_psu_driver_api = { - .set_enabled = api_set_enabled, - .get_enabled = api_get_enabled, - .set_voltage = api_set_voltage, - .get_voltage = api_get_voltage, +static const struct mod_psu_driver_api mod_mock_psu_driver_api = { + .get_enabled = mod_mock_psu_get_enabled, + .set_enabled = mod_mock_psu_set_enabled, + .get_voltage = mod_mock_psu_get_voltage, + .set_voltage = mod_mock_psu_set_voltage, }; -static int mock_psu_init( +static int mod_mock_psu_init( fwk_id_t module_id, unsigned int element_count, const void *data) { - device_ctx = fwk_mm_calloc( - element_count, - sizeof((*device_ctx)[0])); - if (device_ctx == NULL) + fwk_expect(data == NULL); + + mod_mock_psu_ctx.elements = + fwk_mm_calloc(element_count, sizeof(mod_mock_psu_ctx.elements[0])); + if (mod_mock_psu_ctx.elements == NULL) return FWK_E_NOMEM; return FWK_SUCCESS; } -static int mock_psu_element_init( +static int mod_mock_psu_element_init( fwk_id_t device_id, unsigned int sub_element_count, const void *data) { - struct mod_mock_psu_device_ctx *ctx; - const struct mod_mock_psu_device_config *config = data; + struct mod_mock_psu_element_ctx *ctx; + const struct mod_mock_psu_element_cfg *cfg = data; + + fwk_expect(sub_element_count == 0); - assert(sub_element_count == 0); + ctx = mod_mock_psu_get_ctx_unchecked(device_id); - ctx = get_device_ctx(device_id); - ctx->enabled = config->default_enabled; - ctx->voltage = config->default_voltage; + ctx->enabled = cfg->default_enabled; + ctx->voltage = cfg->default_voltage; return FWK_SUCCESS; } -static int mock_psu_process_bind_request( +static int mod_mock_psu_process_bind_request( fwk_id_t source_id, fwk_id_t target_id, fwk_id_t api_id, @@ -139,17 +177,19 @@ static int mock_psu_process_bind_request( if (!fwk_id_is_type(target_id, FWK_ID_TYPE_ELEMENT)) return FWK_E_PARAM; - *api = &mod_mock_psu_psu_driver_api; + *api = &mod_mock_psu_driver_api; return FWK_SUCCESS; } /* Module description */ const struct fwk_module module_mock_psu = { - .name = "MOCK_PSU", + .name = "mock_psu", .type = FWK_MODULE_TYPE_DRIVER, - .api_count = MOD_MOCK_PSU_API_COUNT, - .init = mock_psu_init, - .element_init = mock_psu_element_init, - .process_bind_request = mock_psu_process_bind_request, + + .init = mod_mock_psu_init, + .element_init = mod_mock_psu_element_init, + + .api_count = MOD_MOCK_PSU_API_IDX_COUNT, + .process_bind_request = mod_mock_psu_process_bind_request, }; diff --git a/product/rdn1e1/scp_ramfw/config_mock_psu.c b/product/rdn1e1/scp_ramfw/config_mock_psu.c index 3c72b9ad..fa66ac18 100644 --- a/product/rdn1e1/scp_ramfw/config_mock_psu.c +++ b/product/rdn1e1/scp_ramfw/config_mock_psu.c @@ -13,7 +13,7 @@ static const struct fwk_element element_table[] = { { .name = "DVFS_GROUP0", .data = - &(const struct mod_mock_psu_device_config){ + &(const struct mod_mock_psu_element_cfg){ .default_enabled = true, .default_voltage = 100, }, @@ -21,7 +21,7 @@ static const struct fwk_element element_table[] = { { .name = "DVFS_GROUP1", .data = - &(const struct mod_mock_psu_device_config){ + &(const struct mod_mock_psu_element_cfg){ .default_enabled = true, .default_voltage = 100, }, diff --git a/product/rdn1e1/scp_ramfw/config_psu.c b/product/rdn1e1/scp_ramfw/config_psu.c index 40d317c6..835f6a59 100644 --- a/product/rdn1e1/scp_ramfw/config_psu.c +++ b/product/rdn1e1/scp_ramfw/config_psu.c @@ -17,7 +17,7 @@ static const struct fwk_element element_table[] = { .data = &(const struct mod_psu_element_cfg) { .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_MOCK_PSU, 0), .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_MOCK_PSU, - MOD_MOCK_PSU_API_IDX_PSU_DRIVER) + MOD_MOCK_PSU_API_IDX_DRIVER) }, }, { @@ -25,7 +25,7 @@ static const struct fwk_element element_table[] = { .data = &(const struct mod_psu_element_cfg){ .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_MOCK_PSU, 1), .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_MOCK_PSU, - MOD_MOCK_PSU_API_IDX_PSU_DRIVER) + MOD_MOCK_PSU_API_IDX_DRIVER) }, }, { 0 } diff --git a/product/sgi575/scp_ramfw/config_mock_psu.c b/product/sgi575/scp_ramfw/config_mock_psu.c index 614c6b66..9859bc13 100644 --- a/product/sgi575/scp_ramfw/config_mock_psu.c +++ b/product/sgi575/scp_ramfw/config_mock_psu.c @@ -13,7 +13,7 @@ static const struct fwk_element element_table[] = { { .name = "DVFS_GROUP0", .data = - &(const struct mod_mock_psu_device_config){ + &(const struct mod_mock_psu_element_cfg){ .default_enabled = true, .default_voltage = 100, }, @@ -21,7 +21,7 @@ static const struct fwk_element element_table[] = { { .name = "DVFS_GROUP1", .data = - &(const struct mod_mock_psu_device_config){ + &(const struct mod_mock_psu_element_cfg){ .default_enabled = true, .default_voltage = 100, }, diff --git a/product/sgi575/scp_ramfw/config_psu.c b/product/sgi575/scp_ramfw/config_psu.c index d1ce5884..b31b8cd5 100644 --- a/product/sgi575/scp_ramfw/config_psu.c +++ b/product/sgi575/scp_ramfw/config_psu.c @@ -17,7 +17,7 @@ static const struct fwk_element element_table[] = { .data = &(const struct mod_psu_element_cfg) { .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_MOCK_PSU, 0), .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_MOCK_PSU, - MOD_MOCK_PSU_API_IDX_PSU_DRIVER) + MOD_MOCK_PSU_API_IDX_DRIVER) }, }, { @@ -25,7 +25,7 @@ static const struct fwk_element element_table[] = { .data = &(const struct mod_psu_element_cfg){ .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_MOCK_PSU, 1), .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_MOCK_PSU, - MOD_MOCK_PSU_API_IDX_PSU_DRIVER) + MOD_MOCK_PSU_API_IDX_DRIVER) }, }, { 0 } diff --git a/product/sgm775/scp_ramfw/config_mock_psu.c b/product/sgm775/scp_ramfw/config_mock_psu.c index 60a0e632..a91cc43c 100644 --- a/product/sgm775/scp_ramfw/config_mock_psu.c +++ b/product/sgm775/scp_ramfw/config_mock_psu.c @@ -12,28 +12,28 @@ static const struct fwk_element element_table[] = { { .name = "CPU_GROUP_LITTLE", - .data = &(const struct mod_mock_psu_device_config) { + .data = &(const struct mod_mock_psu_element_cfg) { .default_enabled = true, .default_voltage = 100, }, }, { .name = "CPU_GROUP_BIG", - .data = &(const struct mod_mock_psu_device_config) { + .data = &(const struct mod_mock_psu_element_cfg) { .default_enabled = true, .default_voltage = 100, }, }, { .name = "GPU", - .data = &(const struct mod_mock_psu_device_config) { + .data = &(const struct mod_mock_psu_element_cfg) { .default_enabled = true, .default_voltage = 100, }, }, { .name = "VPU", - .data = &(const struct mod_mock_psu_device_config) { + .data = &(const struct mod_mock_psu_element_cfg) { .default_enabled = true, .default_voltage = 100, }, diff --git a/product/sgm775/scp_ramfw/config_psu.c b/product/sgm775/scp_ramfw/config_psu.c index a37968bb..32122393 100644 --- a/product/sgm775/scp_ramfw/config_psu.c +++ b/product/sgm775/scp_ramfw/config_psu.c @@ -17,7 +17,7 @@ static const struct fwk_element element_table[] = { .data = &(const struct mod_psu_element_cfg) { .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_MOCK_PSU, 0), .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_MOCK_PSU, - MOD_MOCK_PSU_API_IDX_PSU_DRIVER) + MOD_MOCK_PSU_API_IDX_DRIVER) }, }, { @@ -25,7 +25,7 @@ static const struct fwk_element element_table[] = { .data = &(const struct mod_psu_element_cfg) { .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_MOCK_PSU, 1), .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_MOCK_PSU, - MOD_MOCK_PSU_API_IDX_PSU_DRIVER) + MOD_MOCK_PSU_API_IDX_DRIVER) }, }, { @@ -33,7 +33,7 @@ static const struct fwk_element element_table[] = { .data = &(const struct mod_psu_element_cfg) { .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_MOCK_PSU, 2), .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_MOCK_PSU, - MOD_MOCK_PSU_API_IDX_PSU_DRIVER) + MOD_MOCK_PSU_API_IDX_DRIVER) }, }, { @@ -41,7 +41,7 @@ static const struct fwk_element element_table[] = { .data = &(const struct mod_psu_element_cfg) { .driver_id = FWK_ID_ELEMENT_INIT(FWK_MODULE_IDX_MOCK_PSU, 3), .driver_api_id = FWK_ID_API_INIT(FWK_MODULE_IDX_MOCK_PSU, - MOD_MOCK_PSU_API_IDX_PSU_DRIVER) + MOD_MOCK_PSU_API_IDX_DRIVER) }, }, { 0 } |