Tejas Patel | 9d09ff9 | 2019-01-08 01:46:35 -0800 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2019, Xilinx, Inc. All rights reserved. |
| 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Versal system level PM-API functions and communication with PMC via |
| 9 | * IPI interrupts |
| 10 | */ |
| 11 | |
| 12 | #include <pm_common.h> |
| 13 | #include <pm_ipi.h> |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 14 | #include <plat/common/platform.h> |
Tejas Patel | 9d09ff9 | 2019-01-08 01:46:35 -0800 | [diff] [blame] | 15 | #include "pm_api_sys.h" |
| 16 | #include "pm_client.h" |
| 17 | |
| 18 | /********************************************************************* |
| 19 | * Target module IDs macros |
| 20 | ********************************************************************/ |
| 21 | #define LIBPM_MODULE_ID 0x2 |
| 22 | #define LOADER_MODULE_ID 0x7 |
| 23 | |
| 24 | /** |
| 25 | * Assigning of argument values into array elements. |
| 26 | */ |
| 27 | #define PM_PACK_PAYLOAD1(pl, mid, arg0) { \ |
| 28 | pl[0] = (uint32_t)((uint32_t)((arg0) & 0xFF) | (mid << 8)); \ |
| 29 | } |
| 30 | |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 31 | #define PM_PACK_PAYLOAD2(pl, mid, arg0, arg1) { \ |
| 32 | pl[1] = (uint32_t)(arg1); \ |
| 33 | PM_PACK_PAYLOAD1(pl, mid, arg0); \ |
| 34 | } |
| 35 | |
| 36 | #define PM_PACK_PAYLOAD3(pl, mid, arg0, arg1, arg2) { \ |
| 37 | pl[2] = (uint32_t)(arg2); \ |
| 38 | PM_PACK_PAYLOAD2(pl, mid, arg0, arg1); \ |
| 39 | } |
| 40 | |
| 41 | #define PM_PACK_PAYLOAD4(pl, mid, arg0, arg1, arg2, arg3) { \ |
| 42 | pl[3] = (uint32_t)(arg3); \ |
| 43 | PM_PACK_PAYLOAD3(pl, mid, arg0, arg1, arg2); \ |
| 44 | } |
| 45 | |
| 46 | #define PM_PACK_PAYLOAD5(pl, mid, arg0, arg1, arg2, arg3, arg4) { \ |
| 47 | pl[4] = (uint32_t)(arg4); \ |
| 48 | PM_PACK_PAYLOAD4(pl, mid, arg0, arg1, arg2, arg3); \ |
| 49 | } |
| 50 | |
| 51 | #define PM_PACK_PAYLOAD6(pl, mid, arg0, arg1, arg2, arg3, arg4, arg5) { \ |
| 52 | pl[5] = (uint32_t)(arg5); \ |
| 53 | PM_PACK_PAYLOAD5(pl, mid, arg0, arg1, arg2, arg3, arg4); \ |
| 54 | } |
| 55 | |
Tejas Patel | 9d09ff9 | 2019-01-08 01:46:35 -0800 | [diff] [blame] | 56 | /* PM API functions */ |
| 57 | |
| 58 | /** |
| 59 | * pm_get_api_version() - Get version number of PMC PM firmware |
| 60 | * @version Returns 32-bit version number of PMC Power Management Firmware |
| 61 | * |
| 62 | * @return Returns status, either success or error+reason |
| 63 | */ |
| 64 | enum pm_ret_status pm_get_api_version(unsigned int *version) |
| 65 | { |
| 66 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 67 | |
| 68 | /* Send request to the PMC */ |
| 69 | PM_PACK_PAYLOAD1(payload, LIBPM_MODULE_ID, PM_GET_API_VERSION); |
| 70 | return pm_ipi_send_sync(primary_proc, payload, version, 1); |
| 71 | } |
Tejas Patel | fe0e10a | 2019-12-08 23:29:44 -0800 | [diff] [blame] | 72 | |
| 73 | /** |
| 74 | * pm_self_suspend() - PM call for processor to suspend itself |
| 75 | * @nid Node id of the processor or subsystem |
| 76 | * @latency Requested maximum wakeup latency (not supported) |
| 77 | * @state Requested state |
| 78 | * @address Resume address |
| 79 | * |
| 80 | * This is a blocking call, it will return only once PMU has responded. |
| 81 | * On a wakeup, resume address will be automatically set by PMU. |
| 82 | * |
| 83 | * @return Returns status, either success or error+reason |
| 84 | */ |
| 85 | enum pm_ret_status pm_self_suspend(uint32_t nid, |
| 86 | unsigned int latency, |
| 87 | unsigned int state, |
| 88 | uintptr_t address) |
| 89 | { |
| 90 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 91 | unsigned int cpuid = plat_my_core_pos(); |
| 92 | const struct pm_proc *proc = pm_get_proc(cpuid); |
| 93 | |
| 94 | if (!proc) { |
| 95 | WARN("Failed to get proc %d\n", cpuid); |
| 96 | return PM_RET_ERROR_INTERNAL; |
| 97 | } |
| 98 | |
| 99 | /* |
| 100 | * Do client specific suspend operations |
| 101 | * (e.g. set powerdown request bit) |
| 102 | */ |
| 103 | pm_client_suspend(proc, state); |
| 104 | |
| 105 | /* Send request to the PLM */ |
| 106 | PM_PACK_PAYLOAD6(payload, LIBPM_MODULE_ID, PM_SELF_SUSPEND, |
| 107 | proc->node_id, latency, state, address, |
| 108 | (address >> 32)); |
| 109 | return pm_ipi_send_sync(proc, payload, NULL, 0); |
| 110 | } |
| 111 | |
| 112 | /** |
| 113 | * pm_abort_suspend() - PM call to announce that a prior suspend request |
| 114 | * is to be aborted. |
| 115 | * @reason Reason for the abort |
| 116 | * |
| 117 | * Calling PU expects the PMU to abort the initiated suspend procedure. |
| 118 | * This is a non-blocking call without any acknowledge. |
| 119 | * |
| 120 | * @return Returns status, either success or error+reason |
| 121 | */ |
| 122 | enum pm_ret_status pm_abort_suspend(enum pm_abort_reason reason) |
| 123 | { |
| 124 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 125 | |
| 126 | /* |
| 127 | * Do client specific abort suspend operations |
| 128 | * (e.g. enable interrupts and clear powerdown request bit) |
| 129 | */ |
| 130 | pm_client_abort_suspend(); |
| 131 | |
| 132 | /* Send request to the PLM */ |
| 133 | PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, PM_ABORT_SUSPEND, reason, |
| 134 | primary_proc->node_id); |
| 135 | return pm_ipi_send(primary_proc, payload); |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * pm_req_suspend() - PM call to request for another PU or subsystem to |
| 140 | * be suspended gracefully. |
| 141 | * @target Node id of the targeted PU or subsystem |
| 142 | * @ack Flag to specify whether acknowledge is requested |
| 143 | * @latency Requested wakeup latency (not supported) |
| 144 | * @state Requested state (not supported) |
| 145 | * |
| 146 | * @return Returns status, either success or error+reason |
| 147 | */ |
| 148 | enum pm_ret_status pm_req_suspend(uint32_t target, uint8_t ack, |
| 149 | unsigned int latency, unsigned int state) |
| 150 | { |
| 151 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 152 | |
| 153 | /* Send request to the PMU */ |
| 154 | PM_PACK_PAYLOAD4(payload, LIBPM_MODULE_ID, PM_REQ_SUSPEND, target, |
| 155 | latency, state); |
| 156 | if (ack == IPI_BLOCKING) |
| 157 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 158 | else |
| 159 | return pm_ipi_send(primary_proc, payload); |
| 160 | } |
Tejas Patel | 41f3e0b | 2019-01-08 01:46:37 -0800 | [diff] [blame] | 161 | |
| 162 | /** |
| 163 | * pm_request_device() - Request a device |
| 164 | * @device_id Device ID |
| 165 | * @capabilities Requested capabilities for the device |
| 166 | * @qos Required Quality of Service |
| 167 | * @ack Flag to specify whether acknowledge requested |
| 168 | * |
| 169 | * @return Returns status, either success or error+reason |
| 170 | */ |
| 171 | enum pm_ret_status pm_request_device(uint32_t device_id, uint32_t capabilities, |
| 172 | uint32_t qos, uint32_t ack) |
| 173 | { |
| 174 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 175 | |
| 176 | /* Send request to the PMC */ |
| 177 | PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, PM_REQUEST_DEVICE, |
| 178 | device_id, capabilities, qos, ack); |
| 179 | |
| 180 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 181 | } |
| 182 | |
| 183 | /** |
| 184 | * pm_release_device() - Release a device |
| 185 | * @device_id Device ID |
| 186 | * |
| 187 | * @return Returns status, either success or error+reason |
| 188 | */ |
| 189 | enum pm_ret_status pm_release_device(uint32_t device_id) |
| 190 | { |
| 191 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 192 | |
| 193 | /* Send request to the PMC */ |
| 194 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, PM_RELEASE_DEVICE, |
| 195 | device_id); |
| 196 | |
| 197 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 198 | } |
| 199 | |
| 200 | /** |
| 201 | * pm_set_requirement() - Set requirement for the device |
| 202 | * @device_id Device ID |
| 203 | * @capabilities Requested capabilities for the device |
| 204 | * @latency Requested maximum latency |
| 205 | * @qos Required Quality of Service |
| 206 | * |
| 207 | * @return Returns status, either success or error+reason |
| 208 | */ |
| 209 | enum pm_ret_status pm_set_requirement(uint32_t device_id, uint32_t capabilities, |
| 210 | uint32_t latency, uint32_t qos) |
| 211 | { |
| 212 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 213 | |
| 214 | /* Send request to the PMC */ |
| 215 | PM_PACK_PAYLOAD5(payload, LIBPM_MODULE_ID, PM_SET_REQUIREMENT, |
| 216 | device_id, capabilities, latency, qos); |
| 217 | |
| 218 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 219 | } |
| 220 | |
| 221 | /** |
| 222 | * pm_get_device_status() - Get device's status |
| 223 | * @device_id Device ID |
| 224 | * @response Buffer to store device status response |
| 225 | * |
| 226 | * @return Returns status, either success or error+reason |
| 227 | */ |
| 228 | enum pm_ret_status pm_get_device_status(uint32_t device_id, uint32_t *response) |
| 229 | { |
| 230 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 231 | |
| 232 | /* Send request to the PMC */ |
| 233 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, PM_GET_DEVICE_STATUS, |
| 234 | device_id); |
| 235 | |
| 236 | return pm_ipi_send_sync(primary_proc, payload, response, 3); |
| 237 | } |
Tejas Patel | 87c4f3a | 2019-01-08 01:46:38 -0800 | [diff] [blame^] | 238 | |
| 239 | /** |
| 240 | * pm_reset_assert() - Assert/De-assert reset |
| 241 | * @reset Reset ID |
| 242 | * @assert Assert (1) or de-assert (0) |
| 243 | * |
| 244 | * @return Returns status, either success or error+reason |
| 245 | */ |
| 246 | enum pm_ret_status pm_reset_assert(uint32_t reset, bool assert) |
| 247 | { |
| 248 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 249 | |
| 250 | /* Send request to the PMC */ |
| 251 | PM_PACK_PAYLOAD3(payload, LIBPM_MODULE_ID, PM_RESET_ASSERT, reset, |
| 252 | assert); |
| 253 | |
| 254 | return pm_ipi_send_sync(primary_proc, payload, NULL, 0); |
| 255 | } |
| 256 | |
| 257 | /** |
| 258 | * pm_reset_get_status() - Get current status of a reset line |
| 259 | * @reset Reset ID |
| 260 | * @status Returns current status of selected reset ID |
| 261 | * |
| 262 | * @return Returns status, either success or error+reason |
| 263 | */ |
| 264 | enum pm_ret_status pm_reset_get_status(uint32_t reset, uint32_t *status) |
| 265 | { |
| 266 | uint32_t payload[PAYLOAD_ARG_CNT]; |
| 267 | |
| 268 | /* Send request to the PMC */ |
| 269 | PM_PACK_PAYLOAD2(payload, LIBPM_MODULE_ID, PM_RESET_ASSERT, reset); |
| 270 | |
| 271 | return pm_ipi_send_sync(primary_proc, payload, status, 1); |
| 272 | } |