aboutsummaryrefslogtreecommitdiff
path: root/module/psu/src
diff options
context:
space:
mode:
authorChris Kay <chris.kay@arm.com>2019-02-21 13:49:14 +0000
committersouvikkc <52570545+souvikkc@users.noreply.github.com>2019-10-15 10:48:39 +0100
commitf081e1e299ba2a14348794a71e8608f872b6d4b0 (patch)
tree7b77e6aead57fad250b47c20b2768bf2290b0c39 /module/psu/src
parent691b6cff8ab9c4398802c4f1e3791f8b6b1621c8 (diff)
psu: Consolidate components into one file
This commit consolidates all the individual PSU C files into a single C file. This follows the conventions followed by most of the rest of the standard modules. Change-Id: I73ab4abc5228a99ac4afdf067d7e367b425d60ac Signed-off-by: Chris Kay <chris.kay@arm.com>
Diffstat (limited to 'module/psu/src')
-rw-r--r--module/psu/src/Makefile5
-rw-r--r--module/psu/src/mod_psu.c450
-rw-r--r--module/psu/src/mod_psu_device_api.c223
-rw-r--r--module/psu/src/mod_psu_device_api_private.h16
-rw-r--r--module/psu/src/mod_psu_event.c98
-rw-r--r--module/psu/src/mod_psu_event_private.h29
-rw-r--r--module/psu/src/mod_psu_module.c128
-rw-r--r--module/psu/src/mod_psu_module_private.h28
-rw-r--r--module/psu/src/mod_psu_private.h16
9 files changed, 451 insertions, 542 deletions
diff --git a/module/psu/src/Makefile b/module/psu/src/Makefile
index 5d02fdc6..056fb445 100644
--- a/module/psu/src/Makefile
+++ b/module/psu/src/Makefile
@@ -6,9 +6,6 @@
#
BS_LIB_NAME := psu
-BS_LIB_SOURCES := \
- mod_psu_device_api.c \
- mod_psu_event.c \
- mod_psu_module.c
+BS_LIB_SOURCES := mod_psu.c
include $(BS_DIR)/lib.mk
diff --git a/module/psu/src/mod_psu.c b/module/psu/src/mod_psu.c
new file mode 100644
index 00000000..d73c111f
--- /dev/null
+++ b/module/psu/src/mod_psu.c
@@ -0,0 +1,450 @@
+/*
+ * Arm SCP/MCP Software
+ * Copyright (c) 2017-2019, Arm Limited and Contributors. All rights reserved.
+ *
+ * SPDX-License-Identifier: BSD-3-Clause
+ */
+
+#include <fwk_assert.h>
+#include <fwk_event.h>
+#include <fwk_id.h>
+#include <fwk_macros.h>
+#include <fwk_module.h>
+#include <fwk_module_idx.h>
+#include <fwk_mm.h>
+#include <fwk_thread.h>
+#include <mod_psu.h>
+
+/* "Set enabled" event */
+struct mod_psu_event_params_set_enabled {
+ bool enable;
+};
+
+/* "Set voltage" event */
+struct mod_psu_event_params_set_voltage {
+ uintmax_t voltage;
+};
+
+/* Device context */
+struct mod_psu_device_ctx {
+ /* Device configuration */
+ const struct mod_psu_device_config *config;
+
+ struct {
+ /* Driver API */
+ const struct mod_psu_driver_api *driver;
+ } apis;
+};
+
+/* Device context table */
+static struct mod_psu_device_ctx (*device_ctx)[];
+
+static struct mod_psu_device_ctx *mod_psu_get_device_ctx(fwk_id_t device_id)
+{
+ unsigned int element_idx = fwk_id_get_element_idx(device_id);
+
+ return &(*device_ctx)[element_idx];
+}
+
+static struct mod_psu_device_ctx *mod_psu_get_valid_device_ctx(
+ fwk_id_t device_id)
+{
+ if (fwk_module_check_call(device_id) != FWK_SUCCESS)
+ return NULL;
+
+ return mod_psu_get_device_ctx(device_id);
+}
+
+int mod_psu_event_set_enabled(
+ const struct fwk_event *event,
+ struct fwk_event *response)
+{
+ const struct mod_psu_device_ctx *ctx;
+ const struct mod_psu_event_params_set_enabled *params;
+ struct mod_psu_event_params_set_enabled_response *response_params;
+
+ /* These conditions were checked when we submitted the event */
+ assert(fwk_id_get_module_idx(event->target_id) == FWK_MODULE_IDX_PSU);
+ assert(fwk_module_is_valid_element_id(event->target_id));
+
+ /* Explicitly cast to our parameter types */
+ params = (void *)&event->params;
+ response_params = (void *)&response->params;
+
+ ctx = mod_psu_get_device_ctx(event->target_id);
+
+ /* Set the enabled state through the driver */
+ response_params->status = ctx->apis.driver->set_enabled(
+ ctx->config->driver_id,
+ params->enable);
+
+ return FWK_SUCCESS;
+}
+
+int mod_psu_event_set_voltage(
+ const struct fwk_event *event,
+ struct fwk_event *response)
+{
+ const struct mod_psu_device_ctx *ctx;
+ const struct mod_psu_event_params_set_voltage *params;
+ struct mod_psu_event_params_set_voltage_response *response_params;
+
+ /* These conditions were checked when we submitted the event */
+ assert(fwk_id_get_module_idx(event->target_id) == FWK_MODULE_IDX_PSU);
+ assert(fwk_module_is_valid_element_id(event->target_id));
+
+ /* Explicitly cast to our parameter types */
+ params = (void *)&event->params;
+ response_params = (void *)&response->params;
+
+ ctx = mod_psu_get_device_ctx(event->target_id);
+
+ /* Set the voltage through the driver */
+ response_params->status = ctx->apis.driver->set_voltage(
+ ctx->config->driver_id,
+ params->voltage);
+
+ return FWK_SUCCESS;
+}
+
+static int mod_psu_process_event(
+ const struct fwk_event *event,
+ struct fwk_event *response)
+{
+ typedef int (*handler_t)(
+ const struct fwk_event *event,
+ struct fwk_event *response);
+
+ static const handler_t handlers[] = {
+ [MOD_PSU_EVENT_IDX_SET_ENABLED] = mod_psu_event_set_enabled,
+ [MOD_PSU_EVENT_IDX_SET_VOLTAGE] = mod_psu_event_set_voltage,
+ };
+
+ unsigned int event_idx;
+ handler_t handler;
+
+ /* We only handle the events defined by us */
+ if (fwk_id_get_module_idx(event->id) != FWK_MODULE_IDX_PSU)
+ return FWK_E_PARAM;
+
+ /* Ensure the event index is within bounds we can handle */
+ event_idx = fwk_id_get_event_idx(event->id);
+ if (event_idx >= FWK_ARRAY_SIZE(handlers))
+ return FWK_E_PARAM;
+
+ /* Ensure we have an implemented handler for this event */
+ handler = handlers[event_idx];
+ if (handler == NULL)
+ return FWK_E_PARAM;
+
+ /* Delegate event handling to the relevant handler */
+ return handler(event, response);
+}
+
+static int api_get_enabled(fwk_id_t device_id, bool *enabled)
+{
+ int status;
+ const struct mod_psu_device_ctx *ctx;
+
+ /* This API call cannot target another module */
+ if (fwk_id_get_module_idx(device_id) != FWK_MODULE_IDX_PSU)
+ return FWK_E_PARAM;
+
+ /* Ensure the identifier refers to a valid element */
+ if (!fwk_module_is_valid_element_id(device_id))
+ return FWK_E_PARAM;
+
+ /* Validate the API call */
+ status = fwk_module_check_call(device_id);
+ if (status != FWK_SUCCESS)
+ return FWK_E_STATE;
+
+ ctx = mod_psu_get_valid_device_ctx(device_id);
+ if (ctx == NULL)
+ return FWK_E_PARAM;
+
+ /* Get the enabled state from the driver */
+ status = ctx->apis.driver->get_enabled(ctx->config->driver_id, enabled);
+ if (status != FWK_SUCCESS)
+ return FWK_E_HANDLER;
+
+ return FWK_SUCCESS;
+}
+
+static int api_set_enabled(fwk_id_t device_id, bool enable)
+{
+ int status;
+ const struct mod_psu_device_ctx *ctx;
+
+ /* This API call cannot target another module */
+ if (fwk_id_get_module_idx(device_id) != FWK_MODULE_IDX_PSU)
+ return FWK_E_PARAM;
+
+ /* Ensure the identifier refers to a valid element */
+ if (!fwk_module_is_valid_element_id(device_id))
+ return FWK_E_PARAM;
+
+ /* Validate the API call */
+ status = fwk_module_check_call(device_id);
+ if (status != FWK_SUCCESS)
+ return FWK_E_STATE;
+
+ ctx = mod_psu_get_valid_device_ctx(device_id);
+ if (ctx == NULL)
+ return FWK_E_PARAM;
+
+ /* Set the enabled state through the driver */
+ status = ctx->apis.driver->set_enabled(ctx->config->driver_id, enable);
+ if (status != FWK_SUCCESS)
+ return FWK_E_HANDLER;
+
+ return FWK_SUCCESS;
+}
+
+static int api_set_enabled_async(fwk_id_t device_id, bool enable)
+{
+ int status;
+ struct fwk_event event;
+ struct mod_psu_event_params_set_enabled *params;
+
+ /* This API call cannot target another module */
+ if (fwk_id_get_module_idx(device_id) != FWK_MODULE_IDX_PSU)
+ return FWK_E_PARAM;
+
+ /* Ensure the identifier refers to an existing element */
+ if (fwk_module_is_valid_element_id(device_id))
+ return FWK_E_PARAM;
+
+ /* Validate the API call */
+ status = fwk_module_check_call(device_id);
+ if (status != FWK_SUCCESS)
+ return FWK_E_STATE;
+
+ /* Build and submit the event */
+ event = (struct fwk_event) {
+ .id = mod_psu_event_id_set_enabled,
+ .target_id = device_id,
+ .response_requested = true,
+ };
+
+ params = (void *)&event.params;
+ *params = (struct mod_psu_event_params_set_enabled) {
+ .enable = enable,
+ };
+
+ /* Submit the event for processing */
+ status = fwk_thread_put_event(&event);
+ if (status == FWK_E_NOMEM)
+ return FWK_E_NOMEM;
+ else if (status != FWK_SUCCESS)
+ return FWK_E_PANIC;
+
+ return FWK_SUCCESS;
+}
+
+static int api_get_voltage(fwk_id_t device_id, uintmax_t *voltage)
+{
+ int status;
+ const struct mod_psu_device_ctx *ctx;
+
+ /* This API call cannot target another module */
+ if (fwk_id_get_module_idx(device_id) != FWK_MODULE_IDX_PSU)
+ return FWK_E_PARAM;
+
+ /* Ensure the identifier refers to a valid element */
+ if (!fwk_module_is_valid_element_id(device_id))
+ return FWK_E_PARAM;
+
+ /* Validate the API call */
+ status = fwk_module_check_call(device_id);
+ if (status != FWK_SUCCESS)
+ return FWK_E_STATE;
+
+ ctx = mod_psu_get_valid_device_ctx(device_id);
+ if (ctx == NULL)
+ return FWK_E_PARAM;
+
+ /* Get the voltage from the driver */
+ status = ctx->apis.driver->get_voltage(ctx->config->driver_id, voltage);
+ if (status != FWK_SUCCESS)
+ return FWK_E_HANDLER;
+
+ return FWK_SUCCESS;
+}
+
+static int api_set_voltage(fwk_id_t device_id, uintmax_t voltage)
+{
+ int status;
+ const struct mod_psu_device_ctx *ctx;
+
+ /* This API call cannot target another module */
+ if (fwk_id_get_module_idx(device_id) != FWK_MODULE_IDX_PSU)
+ return FWK_E_PARAM;
+
+ /* Ensure the identifier refers to a valid element */
+ if (!fwk_module_is_valid_element_id(device_id))
+ return FWK_E_PARAM;
+
+ /* Validate the API call */
+ status = fwk_module_check_call(device_id);
+ if (status != FWK_SUCCESS)
+ return FWK_E_STATE;
+
+ ctx = mod_psu_get_valid_device_ctx(device_id);
+ if (ctx == NULL)
+ return FWK_E_PARAM;
+
+ /* Set the voltage state through the driver */
+ status = ctx->apis.driver->set_voltage(ctx->config->driver_id, voltage);
+ if (status != FWK_SUCCESS)
+ return FWK_E_HANDLER;
+
+ return FWK_SUCCESS;
+}
+
+static int api_set_voltage_async(fwk_id_t device_id, uintmax_t voltage)
+{
+ int status;
+ struct fwk_event event;
+ struct mod_psu_event_params_set_voltage *params;
+
+ /* This API call cannot target another module */
+ if (fwk_id_get_module_idx(device_id) != FWK_MODULE_IDX_PSU)
+ return FWK_E_PARAM;
+
+ /* Ensure the identifier refers to an existing element */
+ if (fwk_module_is_valid_element_id(device_id))
+ return FWK_E_PARAM;
+
+ /* Validate the API call */
+ status = fwk_module_check_call(device_id);
+ if (status != FWK_SUCCESS)
+ return FWK_E_STATE;
+
+ /* Build and submit the event */
+ event = (struct fwk_event) {
+ .id = mod_psu_event_id_set_enabled,
+ .target_id = device_id,
+ .response_requested = true,
+ };
+
+ params = (void *)&event.params;
+ *params = (struct mod_psu_event_params_set_voltage) {
+ .voltage = voltage,
+ };
+
+ status = fwk_thread_put_event(&event);
+ if (status == FWK_E_NOMEM)
+ return FWK_E_NOMEM;
+ else if (status != FWK_SUCCESS)
+ return FWK_E_PANIC;
+
+ return FWK_SUCCESS;
+}
+
+/* Module API implementation */
+static const struct mod_psu_device_api mod_psu_device_api = {
+ .get_enabled = api_get_enabled,
+ .set_enabled = api_set_enabled,
+ .set_enabled_async = api_set_enabled_async,
+ .get_voltage = api_get_voltage,
+ .set_voltage = api_set_voltage,
+ .set_voltage_async = api_set_voltage_async,
+};
+
+static int 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)
+ return FWK_E_NOMEM;
+
+ return FWK_SUCCESS;
+}
+
+static int psu_element_init(
+ fwk_id_t device_id,
+ unsigned int sub_element_count,
+ const void *data)
+{
+ assert(sub_element_count == 0);
+
+ mod_psu_get_device_ctx(device_id)->config = data;
+
+ return FWK_SUCCESS;
+}
+
+static int psu_bind_element(fwk_id_t device_id, unsigned int round)
+{
+ int status;
+ const struct mod_psu_device_ctx *ctx;
+
+ /* Only handle the first round */
+ if (round > 0)
+ return FWK_SUCCESS;
+
+ ctx = mod_psu_get_device_ctx(device_id);
+
+ /* Bind to the driver */
+ status = fwk_module_bind(
+ ctx->config->driver_id,
+ ctx->config->driver_api_id,
+ &ctx->apis.driver);
+ if (status != FWK_SUCCESS) {
+ assert(false);
+
+ return FWK_E_PANIC;
+ }
+
+ assert(ctx->apis.driver->set_enabled != NULL);
+ assert(ctx->apis.driver->get_enabled != NULL);
+ assert(ctx->apis.driver->set_voltage != NULL);
+ assert(ctx->apis.driver->get_voltage != NULL);
+
+ return FWK_SUCCESS;
+}
+
+static int psu_bind(fwk_id_t id, unsigned int round)
+{
+ /* We only need to handle element binding */
+ if (fwk_id_is_type(id, FWK_ID_TYPE_ELEMENT))
+ return psu_bind_element(id, round);
+
+ return FWK_SUCCESS;
+}
+
+static int psu_process_bind_request(
+ fwk_id_t source_id,
+ fwk_id_t target_id,
+ fwk_id_t api_id,
+ const void **api)
+{
+ /* Only accept binds to the elements */
+ if (!fwk_id_is_type(target_id, FWK_ID_TYPE_ELEMENT))
+ return FWK_E_PARAM;
+
+ /* Only expose the device API */
+ if (!fwk_id_is_equal(api_id, mod_psu_api_id_psu_device))
+ return FWK_E_PARAM;
+
+ *api = &mod_psu_device_api;
+
+ return FWK_SUCCESS;
+}
+
+/* Module description */
+const struct fwk_module module_psu = {
+ .name = "PSU",
+ .type = FWK_MODULE_TYPE_HAL,
+ .init = psu_init,
+ .element_init = psu_element_init,
+ .bind = psu_bind,
+ .process_bind_request = psu_process_bind_request,
+ .process_event = mod_psu_process_event,
+ .api_count = MOD_PSU_API_IDX_COUNT,
+ .event_count = MOD_PSU_EVENT_IDX_COUNT,
+};
diff --git a/module/psu/src/mod_psu_device_api.c b/module/psu/src/mod_psu_device_api.c
deleted file mode 100644
index 8b1a09ed..00000000
--- a/module/psu/src/mod_psu_device_api.c
+++ /dev/null
@@ -1,223 +0,0 @@
-/*
- * Arm SCP/MCP Software
- * Copyright (c) 2017-2019, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <fwk_mm.h>
-#include <fwk_module.h>
-#include <fwk_module_idx.h>
-#include <fwk_thread.h>
-#include <mod_psu_private.h>
-
-static int api_get_enabled(fwk_id_t device_id, bool *enabled)
-{
- int status;
- const struct mod_psu_device_ctx *ctx;
-
- /* This API call cannot target another module */
- if (fwk_id_get_module_idx(device_id) != FWK_MODULE_IDX_PSU)
- return FWK_E_PARAM;
-
- /* Ensure the identifier refers to a valid element */
- if (!fwk_module_is_valid_element_id(device_id))
- return FWK_E_PARAM;
-
- /* Validate the API call */
- status = fwk_module_check_call(device_id);
- if (status != FWK_SUCCESS)
- return FWK_E_STATE;
-
- ctx = __mod_psu_get_valid_device_ctx(device_id);
- if (ctx == NULL)
- return FWK_E_PARAM;
-
- /* Get the enabled state from the driver */
- status = ctx->apis.driver->get_enabled(ctx->config->driver_id, enabled);
- if (status != FWK_SUCCESS)
- return FWK_E_HANDLER;
-
- return FWK_SUCCESS;
-}
-
-static int api_set_enabled(fwk_id_t device_id, bool enable)
-{
- int status;
- const struct mod_psu_device_ctx *ctx;
-
- /* This API call cannot target another module */
- if (fwk_id_get_module_idx(device_id) != FWK_MODULE_IDX_PSU)
- return FWK_E_PARAM;
-
- /* Ensure the identifier refers to a valid element */
- if (!fwk_module_is_valid_element_id(device_id))
- return FWK_E_PARAM;
-
- /* Validate the API call */
- status = fwk_module_check_call(device_id);
- if (status != FWK_SUCCESS)
- return FWK_E_STATE;
-
- ctx = __mod_psu_get_valid_device_ctx(device_id);
- if (ctx == NULL)
- return FWK_E_PARAM;
-
- /* Set the enabled state through the driver */
- status = ctx->apis.driver->set_enabled(ctx->config->driver_id, enable);
- if (status != FWK_SUCCESS)
- return FWK_E_HANDLER;
-
- return FWK_SUCCESS;
-}
-
-static int api_set_enabled_async(fwk_id_t device_id, bool enable)
-{
- int status;
- struct fwk_event event;
- struct mod_psu_event_params_set_enabled *params;
-
- /* This API call cannot target another module */
- if (fwk_id_get_module_idx(device_id) != FWK_MODULE_IDX_PSU)
- return FWK_E_PARAM;
-
- /* Ensure the identifier refers to an existing element */
- if (fwk_module_is_valid_element_id(device_id))
- return FWK_E_PARAM;
-
- /* Validate the API call */
- status = fwk_module_check_call(device_id);
- if (status != FWK_SUCCESS)
- return FWK_E_STATE;
-
- /* Build and submit the event */
- event = (struct fwk_event) {
- .id = mod_psu_event_id_set_enabled,
- .target_id = device_id,
- .response_requested = true,
- };
-
- params = (void *)&event.params;
- *params = (struct mod_psu_event_params_set_enabled) {
- .enable = enable,
- };
-
- /* Submit the event for processing */
- status = fwk_thread_put_event(&event);
- if (status == FWK_E_NOMEM)
- return FWK_E_NOMEM;
- else if (status != FWK_SUCCESS)
- return FWK_E_PANIC;
-
- return FWK_SUCCESS;
-}
-
-static int api_get_voltage(fwk_id_t device_id, uintmax_t *voltage)
-{
- int status;
- const struct mod_psu_device_ctx *ctx;
-
- /* This API call cannot target another module */
- if (fwk_id_get_module_idx(device_id) != FWK_MODULE_IDX_PSU)
- return FWK_E_PARAM;
-
- /* Ensure the identifier refers to a valid element */
- if (!fwk_module_is_valid_element_id(device_id))
- return FWK_E_PARAM;
-
- /* Validate the API call */
- status = fwk_module_check_call(device_id);
- if (status != FWK_SUCCESS)
- return FWK_E_STATE;
-
- ctx = __mod_psu_get_valid_device_ctx(device_id);
- if (ctx == NULL)
- return FWK_E_PARAM;
-
- /* Get the voltage from the driver */
- status = ctx->apis.driver->get_voltage(ctx->config->driver_id, voltage);
- if (status != FWK_SUCCESS)
- return FWK_E_HANDLER;
-
- return FWK_SUCCESS;
-}
-
-static int api_set_voltage(fwk_id_t device_id, uintmax_t voltage)
-{
- int status;
- const struct mod_psu_device_ctx *ctx;
-
- /* This API call cannot target another module */
- if (fwk_id_get_module_idx(device_id) != FWK_MODULE_IDX_PSU)
- return FWK_E_PARAM;
-
- /* Ensure the identifier refers to a valid element */
- if (!fwk_module_is_valid_element_id(device_id))
- return FWK_E_PARAM;
-
- /* Validate the API call */
- status = fwk_module_check_call(device_id);
- if (status != FWK_SUCCESS)
- return FWK_E_STATE;
-
- ctx = __mod_psu_get_valid_device_ctx(device_id);
- if (ctx == NULL)
- return FWK_E_PARAM;
-
- /* Set the voltage state through the driver */
- status = ctx->apis.driver->set_voltage(ctx->config->driver_id, voltage);
- if (status != FWK_SUCCESS)
- return FWK_E_HANDLER;
-
- return FWK_SUCCESS;
-}
-
-static int api_set_voltage_async(fwk_id_t device_id, uintmax_t voltage)
-{
- int status;
- struct fwk_event event;
- struct mod_psu_event_params_set_voltage *params;
-
- /* This API call cannot target another module */
- if (fwk_id_get_module_idx(device_id) != FWK_MODULE_IDX_PSU)
- return FWK_E_PARAM;
-
- /* Ensure the identifier refers to an existing element */
- if (fwk_module_is_valid_element_id(device_id))
- return FWK_E_PARAM;
-
- /* Validate the API call */
- status = fwk_module_check_call(device_id);
- if (status != FWK_SUCCESS)
- return FWK_E_STATE;
-
- /* Build and submit the event */
- event = (struct fwk_event) {
- .id = mod_psu_event_id_set_enabled,
- .target_id = device_id,
- .response_requested = true,
- };
-
- params = (void *)&event.params;
- *params = (struct mod_psu_event_params_set_voltage) {
- .voltage = voltage,
- };
-
- status = fwk_thread_put_event(&event);
- if (status == FWK_E_NOMEM)
- return FWK_E_NOMEM;
- else if (status != FWK_SUCCESS)
- return FWK_E_PANIC;
-
- return FWK_SUCCESS;
-}
-
-/* Module API implementation */
-const struct mod_psu_device_api __mod_psu_device_api = {
- .get_enabled = api_get_enabled,
- .set_enabled = api_set_enabled,
- .set_enabled_async = api_set_enabled_async,
- .get_voltage = api_get_voltage,
- .set_voltage = api_set_voltage,
- .set_voltage_async = api_set_voltage_async,
-};
diff --git a/module/psu/src/mod_psu_device_api_private.h b/module/psu/src/mod_psu_device_api_private.h
deleted file mode 100644
index 3151781e..00000000
--- a/module/psu/src/mod_psu_device_api_private.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Arm SCP/MCP Software
- * Copyright (c) 2017-2019, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef MOD_PSU_DEVICE_API_PRIVATE_H
-#define MOD_PSU_DEVICE_API_PRIVATE_H
-
-#include <mod_psu.h>
-
-/* Module API implementation */
-extern const struct mod_psu_device_api __mod_psu_device_api;
-
-#endif /* MOD_PSU_DEVICE_API_PRIVATE_H */
diff --git a/module/psu/src/mod_psu_event.c b/module/psu/src/mod_psu_event.c
deleted file mode 100644
index b989b16b..00000000
--- a/module/psu/src/mod_psu_event.c
+++ /dev/null
@@ -1,98 +0,0 @@
-/*
- * Arm SCP/MCP Software
- * Copyright (c) 2017-2019, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <fwk_assert.h>
-#include <fwk_macros.h>
-#include <fwk_module.h>
-#include <fwk_module_idx.h>
-#include <mod_psu_private.h>
-
-int mod_psu_event_set_enabled(
- const struct fwk_event *event,
- struct fwk_event *response)
-{
- const struct mod_psu_device_ctx *ctx;
- const struct mod_psu_event_params_set_enabled *params;
- struct mod_psu_event_params_set_enabled_response *response_params;
-
- /* These conditions were checked when we submitted the event */
- assert(fwk_id_get_module_idx(event->target_id) == FWK_MODULE_IDX_PSU);
- assert(fwk_module_is_valid_element_id(event->target_id));
-
- /* Explicitly cast to our parameter types */
- params = (void *)&event->params;
- response_params = (void *)&response->params;
-
- ctx = __mod_psu_get_device_ctx(event->target_id);
-
- /* Set the enabled state through the driver */
- response_params->status = ctx->apis.driver->set_enabled(
- ctx->config->driver_id,
- params->enable);
-
- return FWK_SUCCESS;
-}
-
-int mod_psu_event_set_voltage(
- const struct fwk_event *event,
- struct fwk_event *response)
-{
- const struct mod_psu_device_ctx *ctx;
- const struct mod_psu_event_params_set_voltage *params;
- struct mod_psu_event_params_set_voltage_response *response_params;
-
- /* These conditions were checked when we submitted the event */
- assert(fwk_id_get_module_idx(event->target_id) == FWK_MODULE_IDX_PSU);
- assert(fwk_module_is_valid_element_id(event->target_id));
-
- /* Explicitly cast to our parameter types */
- params = (void *)&event->params;
- response_params = (void *)&response->params;
-
- ctx = __mod_psu_get_device_ctx(event->target_id);
-
- /* Set the voltage through the driver */
- response_params->status = ctx->apis.driver->set_voltage(
- ctx->config->driver_id,
- params->voltage);
-
- return FWK_SUCCESS;
-}
-
-int __mod_psu_process_event(
- const struct fwk_event *event,
- struct fwk_event *response)
-{
- typedef int (*handler_t)(
- const struct fwk_event *event,
- struct fwk_event *response);
-
- static const handler_t handlers[] = {
- [MOD_PSU_EVENT_IDX_SET_ENABLED] = mod_psu_event_set_enabled,
- [MOD_PSU_EVENT_IDX_SET_VOLTAGE] = mod_psu_event_set_voltage,
- };
-
- unsigned int event_idx;
- handler_t handler;
-
- /* We only handle the events defined by us */
- if (fwk_id_get_module_idx(event->id) != FWK_MODULE_IDX_PSU)
- return FWK_E_PARAM;
-
- /* Ensure the event index is within bounds we can handle */
- event_idx = fwk_id_get_event_idx(event->id);
- if (event_idx >= FWK_ARRAY_SIZE(handlers))
- return FWK_E_PARAM;
-
- /* Ensure we have an implemented handler for this event */
- handler = handlers[event_idx];
- if (handler == NULL)
- return FWK_E_PARAM;
-
- /* Delegate event handling to the relevant handler */
- return handler(event, response);
-}
diff --git a/module/psu/src/mod_psu_event_private.h b/module/psu/src/mod_psu_event_private.h
deleted file mode 100644
index 8640002c..00000000
--- a/module/psu/src/mod_psu_event_private.h
+++ /dev/null
@@ -1,29 +0,0 @@
-/*
- * Arm SCP/MCP Software
- * Copyright (c) 2017-2019, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef MOD_PSU_EVENT_PRIVATE_H
-#define MOD_PSU_EVENT_PRIVATE_H
-
-#include <fwk_event.h>
-#include <fwk_id.h>
-
-/* "Set enabled" event */
-struct mod_psu_event_params_set_enabled {
- bool enable;
-};
-
-/* "Set voltage" event */
-struct mod_psu_event_params_set_voltage {
- uintmax_t voltage;
-};
-
-/* Event handler */
-int __mod_psu_process_event(
- const struct fwk_event *event,
- struct fwk_event *response);
-
-#endif /* MOD_PSU_EVENT_PRIVATE_H */
diff --git a/module/psu/src/mod_psu_module.c b/module/psu/src/mod_psu_module.c
deleted file mode 100644
index ace8059f..00000000
--- a/module/psu/src/mod_psu_module.c
+++ /dev/null
@@ -1,128 +0,0 @@
-/*
- * Arm SCP/MCP Software
- * Copyright (c) 2017-2019, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#include <fwk_assert.h>
-#include <fwk_macros.h>
-#include <fwk_mm.h>
-#include <fwk_module.h>
-#include <fwk_module_idx.h>
-#include <mod_psu_private.h>
-
-/* Device context table */
-static struct mod_psu_device_ctx (*device_ctx)[];
-
-static int 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)
- return FWK_E_NOMEM;
-
- return FWK_SUCCESS;
-}
-
-static int psu_element_init(
- fwk_id_t device_id,
- unsigned int sub_element_count,
- const void *data)
-{
- assert(sub_element_count == 0);
-
- __mod_psu_get_device_ctx(device_id)->config = data;
-
- return FWK_SUCCESS;
-}
-
-static int psu_bind_element(fwk_id_t device_id, unsigned int round)
-{
- int status;
- const struct mod_psu_device_ctx *ctx;
-
- /* Only handle the first round */
- if (round > 0)
- return FWK_SUCCESS;
-
- ctx = __mod_psu_get_device_ctx(device_id);
-
- /* Bind to the driver */
- status = fwk_module_bind(
- ctx->config->driver_id,
- ctx->config->driver_api_id,
- &ctx->apis.driver);
- if (status != FWK_SUCCESS) {
- assert(false);
-
- return FWK_E_PANIC;
- }
-
- assert(ctx->apis.driver->set_enabled != NULL);
- assert(ctx->apis.driver->get_enabled != NULL);
- assert(ctx->apis.driver->set_voltage != NULL);
- assert(ctx->apis.driver->get_voltage != NULL);
-
- return FWK_SUCCESS;
-}
-
-static int psu_bind(fwk_id_t id, unsigned int round)
-{
- /* We only need to handle element binding */
- if (fwk_id_is_type(id, FWK_ID_TYPE_ELEMENT))
- return psu_bind_element(id, round);
-
- return FWK_SUCCESS;
-}
-
-static int psu_process_bind_request(
- fwk_id_t source_id,
- fwk_id_t target_id,
- fwk_id_t api_id,
- const void **api)
-{
- /* Only accept binds to the elements */
- if (!fwk_id_is_type(target_id, FWK_ID_TYPE_ELEMENT))
- return FWK_E_PARAM;
-
- /* Only expose the device API */
- if (!fwk_id_is_equal(api_id, mod_psu_api_id_psu_device))
- return FWK_E_PARAM;
-
- *api = &__mod_psu_device_api;
-
- return FWK_SUCCESS;
-}
-
-struct mod_psu_device_ctx *__mod_psu_get_device_ctx(fwk_id_t device_id)
-{
- unsigned int element_idx = fwk_id_get_element_idx(device_id);
-
- return &(*device_ctx)[element_idx];
-}
-
-struct mod_psu_device_ctx *__mod_psu_get_valid_device_ctx(fwk_id_t device_id)
-{
- if (fwk_module_check_call(device_id) != FWK_SUCCESS)
- return NULL;
-
- return __mod_psu_get_device_ctx(device_id);
-}
-
-/* Module description */
-const struct fwk_module module_psu = {
- .name = "PSU",
- .type = FWK_MODULE_TYPE_HAL,
- .init = psu_init,
- .element_init = psu_element_init,
- .bind = psu_bind,
- .process_bind_request = psu_process_bind_request,
- .process_event = __mod_psu_process_event,
- .api_count = MOD_PSU_API_IDX_COUNT,
- .event_count = MOD_PSU_EVENT_IDX_COUNT,
-};
diff --git a/module/psu/src/mod_psu_module_private.h b/module/psu/src/mod_psu_module_private.h
deleted file mode 100644
index cf8cf65c..00000000
--- a/module/psu/src/mod_psu_module_private.h
+++ /dev/null
@@ -1,28 +0,0 @@
-/*
- * Arm SCP/MCP Software
- * Copyright (c) 2017-2019, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef MOD_PSU_DEVICE_CTX_PRIVATE_H
-#define MOD_PSU_DEVICE_CTX_PRIVATE_H
-
-#include <fwk_id.h>
-#include <mod_psu.h>
-
-/* Device context */
-struct mod_psu_device_ctx {
- /* Device configuration */
- const struct mod_psu_device_config *config;
-
- struct {
- /* Driver API */
- const struct mod_psu_driver_api *driver;
- } apis;
-};
-
-struct mod_psu_device_ctx *__mod_psu_get_device_ctx(fwk_id_t device_id);
-struct mod_psu_device_ctx *__mod_psu_get_valid_device_ctx(fwk_id_t device_id);
-
-#endif /* MOD_PSU_DEVICE_CTX_PRIVATE_H */
diff --git a/module/psu/src/mod_psu_private.h b/module/psu/src/mod_psu_private.h
deleted file mode 100644
index 5a46246e..00000000
--- a/module/psu/src/mod_psu_private.h
+++ /dev/null
@@ -1,16 +0,0 @@
-/*
- * Arm SCP/MCP Software
- * Copyright (c) 2017-2019, Arm Limited and Contributors. All rights reserved.
- *
- * SPDX-License-Identifier: BSD-3-Clause
- */
-
-#ifndef MOD_PSU_PRIVATE_H
-#define MOD_PSU_PRIVATE_H
-
-#include <fwk_id.h>
-#include <mod_psu_device_api_private.h>
-#include <mod_psu_event_private.h>
-#include <mod_psu_module_private.h>
-
-#endif /* MOD_PSU_PRIVATE_H */