1 /*
2  * Arm SCP/MCP Software
3  * Copyright (c) 2022, Arm Limited and Contributors. All rights reserved.
4  *
5  * SPDX-License-Identifier: BSD-3-Clause
6  */
7 
8 #ifndef MOD_SCMI_SYSTEM_POWER_REQ_H
9 #define MOD_SCMI_SYSTEM_POWER_REQ_H
10 
11 #include <fwk_id.h>
12 #include <fwk_macros.h>
13 #include <fwk_module_idx.h>
14 
15 #include <stddef.h>
16 #include <stdint.h>
17 
18 /*!
19  * \brief Set state configurations
20  */
21 struct scmi_sys_power_req_state_set_a2p {
22     /*! System Power command flags*/
23     uint32_t flags;
24 
25     /*! The state being transitioned to.*/
26     uint32_t system_state;
27 };
28 
29 /*!
30  * \brief System Power Requester module restricted interface.
31  *
32  * \details The interface the system power requester module exposes to a
33  *          restricted set of modules. The set of modules that are allowed
34  *          to access this interface is defined by the module configuration
35  *          data.
36  */
37 struct mod_system_power_requester_api {
38     /*!
39      * \brief Request an asynchronous power state transition.
40      *
41      * \warning Successful completion of this function does not indicate
42      *      completion of a transition, but instead that a request has been
43      *      submitted.
44      *
45      * \param resp_requested True if the caller wants to be notified with an
46      *      event response at the end of the request processing.
47      *
48      * \param state State the system power requester has to put and request
49      *      from the rest of the system.
50      *
51      * \param flags The SCMI System Power command flags to denote if graceful
52      *      shutdown or not.
53      *
54      * \retval ::FWK_PENDING The power state transition request was submitted.
55      * \retval ::FWK_E_ACCESS Invalid access, the framework has rejected the
56      *      call to the API.
57      * \retval ::FWK_E_PARAM One or more parameters were invalid.
58      *
59      * \return Status code representing the result of the operation.
60      */
61     int (*set_req_state)(
62         bool response_requested,
63         uint32_t state,
64         uint32_t flags);
65 
66     /*!
67      * \brief Get the state of all the elements of the System Power
68      *        Requester.
69      *
70      * \param[out] state The System Power Requester.
71      *
72      * \retval ::FWK_SUCCESS The system power requester state was returned.
73      * \retval ::FWK_E_PARAM An invalid parameter was encountered:
74      *      - The `state` parameter was a null pointer value.
75      *
76      * \return Status code representing the result of the operation.
77      *
78      */
79     int (*get_req_state)(uint32_t *state);
80 };
81 
82 /*!
83  * \brief API indices
84  */
85 enum mod_sys_power_req_api_idx {
86     /*! API used for sending SCMI commands and receive responses */
87     MOD_SYS_POW_REQ_API_IDX_SCMI_REQ,
88     /*! API used to set and get the state from another module */
89     MOD_SYS_POW_REQ_API_IDX_REQ,
90     MOD_SYS_POW_REQ_API_IDX_COUNT,
91 };
92 
93 /*!
94  * \brief SCMI system power platform configuration
95  */
96 struct mod_scmi_system_power_req_dev_config {
97     /*!
98      * \brief SCMI Service ID
99      *
100      * \details The service ID which corresponds to the required
101      *      channel in the transport layer.
102      */
103     fwk_id_t service_id;
104 };
105 
106 /*! Identifier of the system power req API */
107 static const fwk_id_t mod_sys_power_req_api_id = FWK_ID_API_INIT(
108     FWK_MODULE_IDX_SCMI_SYSTEM_POWER_REQ,
109     MOD_SYS_POW_REQ_API_IDX_REQ);
110 
111 /*! Identifier of the system power req SCMI API */
112 static const fwk_id_t mod_sys_power_req_scmi_api_id = FWK_ID_API_INIT(
113     FWK_MODULE_IDX_SCMI_SYSTEM_POWER_REQ,
114     MOD_SYS_POW_REQ_API_IDX_SCMI_REQ);
115 
116 /*!
117  * System Power Requestor set state request event index
118  */
119 #define MOD_SCMI_SPR_EVENT_IDX_SET_STATE 0
120 
121 /*!
122  * \brief Read request event identifier.
123  *
124  * \details Clients which expect to receive a response event from this module
125  *      should use this identifier to properly identify the response.
126  */
127 static const fwk_id_t system_power_requester_set_state_request =
128     FWK_ID_EVENT_INIT(
129         FWK_MODULE_IDX_SCMI_SYSTEM_POWER_REQ,
130         MOD_SCMI_SPR_EVENT_IDX_SET_STATE);
131 
132 #endif /* MOD_SCMI_SYSTEM_POWER_REQ_H */
133