Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 1 | /* |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 2 | * Copyright (c) 2013-2020, ARM Limited and Contributors. All rights reserved. |
Rajan Vaja | 566b2f9 | 2022-08-31 12:54:38 +0200 | [diff] [blame] | 3 | * Copyright (c) 2019-2022, Xilinx, Inc. All rights reserved. |
| 4 | * Copyright (c) 2022, Advanced Micro Devices, Inc. All rights reserved. |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 5 | * |
dp-arm | fa3cf0b | 2017-05-03 09:38:09 +0100 | [diff] [blame] | 6 | * SPDX-License-Identifier: BSD-3-Clause |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 7 | */ |
| 8 | |
Jolly Shah | 259afe5 | 2019-01-09 12:37:57 -0800 | [diff] [blame] | 9 | |
Isla Mitchell | e363146 | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 10 | #include <arch_helpers.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 11 | #include <lib/bakery_lock.h> |
| 12 | #include <lib/mmio.h> |
Jolly Shah | c2583ab | 2019-01-08 11:31:49 -0800 | [diff] [blame] | 13 | #include <ipi.h> |
Jolly Shah | 4c17237 | 2019-01-08 11:21:29 -0800 | [diff] [blame] | 14 | #include <plat_ipi.h> |
Jolly Shah | 0bfd700 | 2019-01-08 11:10:47 -0800 | [diff] [blame] | 15 | #include <plat_private.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 16 | #include <plat/common/platform.h> |
| 17 | |
Rajan Vaja | 566b2f9 | 2022-08-31 12:54:38 +0200 | [diff] [blame] | 18 | #include "pm_defs.h" |
Isla Mitchell | e363146 | 2017-07-14 10:46:32 +0100 | [diff] [blame] | 19 | #include "pm_ipi.h" |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 20 | |
HariBabu Gattem | 9f9db61 | 2022-09-15 22:35:11 -0700 | [diff] [blame] | 21 | #define ERROR_CODE_MASK (0xFFFFU) |
HariBabu Gattem | aa81171 | 2022-10-07 00:07:49 -0700 | [diff] [blame] | 22 | #define PM_OFFSET (0U) |
Ravi Patel | 6512371 | 2020-11-23 04:19:08 -0800 | [diff] [blame] | 23 | |
Stefan Krsmanovic | c5e9f66 | 2016-05-20 15:51:08 +0200 | [diff] [blame] | 24 | DEFINE_BAKERY_LOCK(pm_secure_lock); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 25 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 26 | /** |
Jolly Shah | 9bb628d | 2019-01-07 12:53:32 -0800 | [diff] [blame] | 27 | * pm_ipi_init() - Initialize IPI peripheral for communication with |
| 28 | * remote processor |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 29 | * |
Wendy Liang | 328105c | 2017-10-03 23:21:11 -0700 | [diff] [blame] | 30 | * @proc Pointer to the processor who is initiating request |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 31 | * @return On success, the initialization function must return 0. |
| 32 | * Any other return value will cause the framework to ignore |
| 33 | * the service |
| 34 | * |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 35 | * Called from pm_setup initialization function |
| 36 | */ |
HariBabu Gattem | aa81171 | 2022-10-07 00:07:49 -0700 | [diff] [blame] | 37 | void pm_ipi_init(const struct pm_proc *proc) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 38 | { |
| 39 | bakery_lock_init(&pm_secure_lock); |
Jolly Shah | 36c930b | 2019-01-07 12:51:40 -0800 | [diff] [blame] | 40 | ipi_mb_open(proc->ipi->local_ipi_id, proc->ipi->remote_ipi_id); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 41 | } |
| 42 | |
| 43 | /** |
Jolly Shah | 9bb628d | 2019-01-07 12:53:32 -0800 | [diff] [blame] | 44 | * pm_ipi_send_common() - Sends IPI request to the remote processor |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 45 | * @proc Pointer to the processor who is initiating request |
| 46 | * @payload API id and call arguments to be written in IPI buffer |
| 47 | * |
| 48 | * Send an IPI request to the power controller. Caller needs to hold |
| 49 | * the 'pm_secure_lock' lock. |
| 50 | * |
| 51 | * @return Returns status, either success or error+reason |
| 52 | */ |
| 53 | static enum pm_ret_status pm_ipi_send_common(const struct pm_proc *proc, |
Tejas Patel | af4b10e | 2018-02-09 02:42:59 -0800 | [diff] [blame] | 54 | uint32_t payload[PAYLOAD_ARG_CNT], |
| 55 | uint32_t is_blocking) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 56 | { |
HariBabu Gattem | aa81171 | 2022-10-07 00:07:49 -0700 | [diff] [blame] | 57 | uint32_t offset = PM_OFFSET; |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 58 | uintptr_t buffer_base = proc->ipi->buffer_base + |
Jolly Shah | 9bb628d | 2019-01-07 12:53:32 -0800 | [diff] [blame] | 59 | IPI_BUFFER_TARGET_REMOTE_OFFSET + |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 60 | IPI_BUFFER_REQ_OFFSET; |
Venkatesh Yadav Abbarapu | bfa2a2a | 2021-02-19 01:40:14 -0700 | [diff] [blame] | 61 | #if IPI_CRC_CHECK |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 62 | payload[PAYLOAD_CRC_POS] = calculate_crc(payload, IPI_W0_TO_W6_SIZE); |
| 63 | #endif |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 64 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 65 | /* Write payload into IPI buffer */ |
| 66 | for (size_t i = 0; i < PAYLOAD_ARG_CNT; i++) { |
| 67 | mmio_write_32(buffer_base + offset, payload[i]); |
| 68 | offset += PAYLOAD_ARG_SIZE; |
| 69 | } |
Tejas Patel | af4b10e | 2018-02-09 02:42:59 -0800 | [diff] [blame] | 70 | |
Jolly Shah | 9bb628d | 2019-01-07 12:53:32 -0800 | [diff] [blame] | 71 | /* Generate IPI to remote processor */ |
Venkatesh Yadav Abbarapu | efa1d32 | 2021-08-04 21:33:15 -0600 | [diff] [blame] | 72 | ipi_mb_notify(proc->ipi->local_ipi_id, proc->ipi->remote_ipi_id, |
Tejas Patel | af4b10e | 2018-02-09 02:42:59 -0800 | [diff] [blame] | 73 | is_blocking); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 74 | |
Venkatesh Yadav Abbarapu | efa1d32 | 2021-08-04 21:33:15 -0600 | [diff] [blame] | 75 | return PM_RET_SUCCESS; |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 76 | } |
| 77 | |
| 78 | /** |
Jolly Shah | 9bb628d | 2019-01-07 12:53:32 -0800 | [diff] [blame] | 79 | * pm_ipi_send_non_blocking() - Sends IPI request to the remote processor |
| 80 | * without blocking notification |
Tejas Patel | af4b10e | 2018-02-09 02:42:59 -0800 | [diff] [blame] | 81 | * @proc Pointer to the processor who is initiating request |
| 82 | * @payload API id and call arguments to be written in IPI buffer |
| 83 | * |
| 84 | * Send an IPI request to the power controller. |
| 85 | * |
| 86 | * @return Returns status, either success or error+reason |
| 87 | */ |
| 88 | enum pm_ret_status pm_ipi_send_non_blocking(const struct pm_proc *proc, |
| 89 | uint32_t payload[PAYLOAD_ARG_CNT]) |
| 90 | { |
| 91 | enum pm_ret_status ret; |
| 92 | |
| 93 | bakery_lock_get(&pm_secure_lock); |
| 94 | |
| 95 | ret = pm_ipi_send_common(proc, payload, IPI_NON_BLOCKING); |
| 96 | |
| 97 | bakery_lock_release(&pm_secure_lock); |
| 98 | |
| 99 | return ret; |
| 100 | } |
| 101 | |
| 102 | /** |
Jolly Shah | 9bb628d | 2019-01-07 12:53:32 -0800 | [diff] [blame] | 103 | * pm_ipi_send() - Sends IPI request to the remote processor |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 104 | * @proc Pointer to the processor who is initiating request |
| 105 | * @payload API id and call arguments to be written in IPI buffer |
| 106 | * |
| 107 | * Send an IPI request to the power controller. |
| 108 | * |
| 109 | * @return Returns status, either success or error+reason |
| 110 | */ |
| 111 | enum pm_ret_status pm_ipi_send(const struct pm_proc *proc, |
| 112 | uint32_t payload[PAYLOAD_ARG_CNT]) |
| 113 | { |
| 114 | enum pm_ret_status ret; |
| 115 | |
| 116 | bakery_lock_get(&pm_secure_lock); |
| 117 | |
Tejas Patel | af4b10e | 2018-02-09 02:42:59 -0800 | [diff] [blame] | 118 | ret = pm_ipi_send_common(proc, payload, IPI_BLOCKING); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 119 | |
| 120 | bakery_lock_release(&pm_secure_lock); |
| 121 | |
| 122 | return ret; |
| 123 | } |
| 124 | |
| 125 | |
| 126 | /** |
Jolly Shah | 9bb628d | 2019-01-07 12:53:32 -0800 | [diff] [blame] | 127 | * pm_ipi_buff_read() - Reads IPI response after remote processor has handled |
| 128 | * interrupt |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 129 | * @proc Pointer to the processor who is waiting and reading response |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 130 | * @value Used to return value from IPI buffer element (optional) |
| 131 | * @count Number of values to return in @value |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 132 | * |
| 133 | * @return Returns status, either success or error+reason |
| 134 | */ |
| 135 | static enum pm_ret_status pm_ipi_buff_read(const struct pm_proc *proc, |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 136 | uint32_t *value, size_t count) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 137 | { |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 138 | size_t i; |
Naman Trivedi Manojbhai | c0dfba8 | 2023-03-07 12:41:11 +0530 | [diff] [blame] | 139 | enum pm_ret_status ret; |
Venkatesh Yadav Abbarapu | bfa2a2a | 2021-02-19 01:40:14 -0700 | [diff] [blame] | 140 | #if IPI_CRC_CHECK |
Naman Trivedi Manojbhai | c0dfba8 | 2023-03-07 12:41:11 +0530 | [diff] [blame] | 141 | uint32_t *payload_ptr = value; |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 142 | size_t j; |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 143 | uint32_t response_payload[PAYLOAD_ARG_CNT]; |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 144 | #endif |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 145 | uintptr_t buffer_base = proc->ipi->buffer_base + |
Jolly Shah | 9bb628d | 2019-01-07 12:53:32 -0800 | [diff] [blame] | 146 | IPI_BUFFER_TARGET_REMOTE_OFFSET + |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 147 | IPI_BUFFER_RESP_OFFSET; |
| 148 | |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 149 | /* |
| 150 | * Read response from IPI buffer |
| 151 | * buf-0: success or error+reason |
| 152 | * buf-1: value |
| 153 | * buf-2: unused |
| 154 | * buf-3: unused |
| 155 | */ |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 156 | for (i = 1; i <= count; i++) { |
| 157 | *value = mmio_read_32(buffer_base + (i * PAYLOAD_ARG_SIZE)); |
| 158 | value++; |
| 159 | } |
Naman Trivedi Manojbhai | c0dfba8 | 2023-03-07 12:41:11 +0530 | [diff] [blame] | 160 | |
| 161 | ret = mmio_read_32(buffer_base); |
Venkatesh Yadav Abbarapu | bfa2a2a | 2021-02-19 01:40:14 -0700 | [diff] [blame] | 162 | #if IPI_CRC_CHECK |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 163 | for (j = 0; j < PAYLOAD_ARG_CNT; j++) { |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 164 | response_payload[j] = mmio_read_32(buffer_base + |
| 165 | (j * PAYLOAD_ARG_SIZE)); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 166 | } |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 167 | |
| 168 | if (response_payload[PAYLOAD_CRC_POS] != |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 169 | calculate_crc(response_payload, IPI_W0_TO_W6_SIZE)) { |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 170 | NOTICE("ERROR in CRC response payload value:0x%x\n", |
| 171 | response_payload[PAYLOAD_CRC_POS]); |
Naman Trivedi Manojbhai | c0dfba8 | 2023-03-07 12:41:11 +0530 | [diff] [blame] | 172 | ret = PM_RET_ERROR_INVALID_CRC; |
| 173 | /* Payload data is invalid as CRC validation failed |
| 174 | * Clear the payload to avoid leakage of data to upper layers |
| 175 | */ |
| 176 | memset(payload_ptr, 0, count); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 177 | } |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 178 | #endif |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 179 | |
Naman Trivedi Manojbhai | c0dfba8 | 2023-03-07 12:41:11 +0530 | [diff] [blame] | 180 | return ret; |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 181 | } |
| 182 | |
| 183 | /** |
Naman Patel | e975642 | 2023-02-15 01:01:21 -0800 | [diff] [blame] | 184 | * pm_ipi_buff_read_callb() - Callback function that reads value from |
| 185 | * ipi response buffer |
| 186 | * @value Used to return value from IPI buffer element |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 187 | * @count Number of values to return in @value |
| 188 | * |
Naman Patel | e975642 | 2023-02-15 01:01:21 -0800 | [diff] [blame] | 189 | * This callback function fills requested data in @value from ipi response |
| 190 | * buffer. |
Naman Trivedi Manojbhai | beec83f | 2023-03-07 12:41:12 +0530 | [diff] [blame] | 191 | * @return Returns status, either success or error |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 192 | */ |
Naman Trivedi Manojbhai | beec83f | 2023-03-07 12:41:12 +0530 | [diff] [blame] | 193 | enum pm_ret_status pm_ipi_buff_read_callb(uint32_t *value, size_t count) |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 194 | { |
| 195 | size_t i; |
Venkatesh Yadav Abbarapu | bfa2a2a | 2021-02-19 01:40:14 -0700 | [diff] [blame] | 196 | #if IPI_CRC_CHECK |
Naman Trivedi Manojbhai | beec83f | 2023-03-07 12:41:12 +0530 | [diff] [blame] | 197 | uint32_t *payload_ptr = value; |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 198 | size_t j; |
HariBabu Gattem | aa81171 | 2022-10-07 00:07:49 -0700 | [diff] [blame] | 199 | unsigned int response_payload[PAYLOAD_ARG_CNT] = {0}; |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 200 | #endif |
Jolly Shah | 9bb628d | 2019-01-07 12:53:32 -0800 | [diff] [blame] | 201 | uintptr_t buffer_base = IPI_BUFFER_REMOTE_BASE + |
| 202 | IPI_BUFFER_TARGET_LOCAL_OFFSET + |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 203 | IPI_BUFFER_REQ_OFFSET; |
Naman Trivedi Manojbhai | beec83f | 2023-03-07 12:41:12 +0530 | [diff] [blame] | 204 | enum pm_ret_status ret = PM_RET_SUCCESS; |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 205 | |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 206 | if (count > IPI_BUFFER_MAX_WORDS) { |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 207 | count = IPI_BUFFER_MAX_WORDS; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 208 | } |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 209 | |
| 210 | for (i = 0; i <= count; i++) { |
| 211 | *value = mmio_read_32(buffer_base + (i * PAYLOAD_ARG_SIZE)); |
| 212 | value++; |
| 213 | } |
Venkatesh Yadav Abbarapu | bfa2a2a | 2021-02-19 01:40:14 -0700 | [diff] [blame] | 214 | #if IPI_CRC_CHECK |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 215 | for (j = 0; j < PAYLOAD_ARG_CNT; j++) { |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 216 | response_payload[j] = mmio_read_32(buffer_base + |
| 217 | (j * PAYLOAD_ARG_SIZE)); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 218 | } |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 219 | |
| 220 | if (response_payload[PAYLOAD_CRC_POS] != |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 221 | calculate_crc(response_payload, IPI_W0_TO_W6_SIZE)) { |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 222 | NOTICE("ERROR in CRC response payload value:0x%x\n", |
| 223 | response_payload[PAYLOAD_CRC_POS]); |
Naman Trivedi Manojbhai | beec83f | 2023-03-07 12:41:12 +0530 | [diff] [blame] | 224 | ret = PM_RET_ERROR_INVALID_CRC; |
| 225 | /* Payload data is invalid as CRC validation failed |
| 226 | * Clear the payload to avoid leakage of data to upper layers |
| 227 | */ |
| 228 | memset(payload_ptr, 0, count); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 229 | } |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 230 | #endif |
Naman Trivedi Manojbhai | beec83f | 2023-03-07 12:41:12 +0530 | [diff] [blame] | 231 | return ret; |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 232 | } |
| 233 | |
| 234 | /** |
Jolly Shah | 9bb628d | 2019-01-07 12:53:32 -0800 | [diff] [blame] | 235 | * pm_ipi_send_sync() - Sends IPI request to the remote processor |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 236 | * @proc Pointer to the processor who is initiating request |
| 237 | * @payload API id and call arguments to be written in IPI buffer |
Soren Brinkmann | d6c9e03 | 2016-09-22 11:35:47 -0700 | [diff] [blame] | 238 | * @value Used to return value from IPI buffer element (optional) |
| 239 | * @count Number of values to return in @value |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 240 | * |
| 241 | * Send an IPI request to the power controller and wait for it to be handled. |
| 242 | * |
| 243 | * @return Returns status, either success or error+reason and, optionally, |
| 244 | * @value |
| 245 | */ |
| 246 | enum pm_ret_status pm_ipi_send_sync(const struct pm_proc *proc, |
| 247 | uint32_t payload[PAYLOAD_ARG_CNT], |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 248 | uint32_t *value, size_t count) |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 249 | { |
| 250 | enum pm_ret_status ret; |
| 251 | |
| 252 | bakery_lock_get(&pm_secure_lock); |
| 253 | |
Tejas Patel | af4b10e | 2018-02-09 02:42:59 -0800 | [diff] [blame] | 254 | ret = pm_ipi_send_common(proc, payload, IPI_BLOCKING); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 255 | if (ret != PM_RET_SUCCESS) { |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 256 | goto unlock; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 257 | } |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 258 | |
Ravi Patel | 6512371 | 2020-11-23 04:19:08 -0800 | [diff] [blame] | 259 | ret = ERROR_CODE_MASK & (pm_ipi_buff_read(proc, value, count)); |
Soren Brinkmann | 76fcae3 | 2016-03-06 20:16:27 -0800 | [diff] [blame] | 260 | |
| 261 | unlock: |
| 262 | bakery_lock_release(&pm_secure_lock); |
| 263 | |
| 264 | return ret; |
| 265 | } |
Soren Brinkmann | a1b0a90 | 2016-09-30 11:30:21 -0700 | [diff] [blame] | 266 | |
Wendy Liang | 328105c | 2017-10-03 23:21:11 -0700 | [diff] [blame] | 267 | void pm_ipi_irq_enable(const struct pm_proc *proc) |
Soren Brinkmann | a1b0a90 | 2016-09-30 11:30:21 -0700 | [diff] [blame] | 268 | { |
Jolly Shah | 36c930b | 2019-01-07 12:51:40 -0800 | [diff] [blame] | 269 | ipi_mb_enable_irq(proc->ipi->local_ipi_id, proc->ipi->remote_ipi_id); |
Soren Brinkmann | a1b0a90 | 2016-09-30 11:30:21 -0700 | [diff] [blame] | 270 | } |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 271 | |
Wendy Liang | 328105c | 2017-10-03 23:21:11 -0700 | [diff] [blame] | 272 | void pm_ipi_irq_clear(const struct pm_proc *proc) |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 273 | { |
Jolly Shah | 36c930b | 2019-01-07 12:51:40 -0800 | [diff] [blame] | 274 | ipi_mb_ack(proc->ipi->local_ipi_id, proc->ipi->remote_ipi_id); |
Soren Brinkmann | 84f0af4 | 2016-09-30 14:24:25 -0700 | [diff] [blame] | 275 | } |
Jolly Shah | 259afe5 | 2019-01-09 12:37:57 -0800 | [diff] [blame] | 276 | |
| 277 | uint32_t pm_ipi_irq_status(const struct pm_proc *proc) |
| 278 | { |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 279 | int32_t ret; |
Jolly Shah | 259afe5 | 2019-01-09 12:37:57 -0800 | [diff] [blame] | 280 | |
| 281 | ret = ipi_mb_enquire_status(proc->ipi->local_ipi_id, |
| 282 | proc->ipi->remote_ipi_id); |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 283 | if (ret & IPI_MB_STATUS_RECV_PENDING) { |
Jolly Shah | 259afe5 | 2019-01-09 12:37:57 -0800 | [diff] [blame] | 284 | return 1; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 285 | } else { |
Jolly Shah | 259afe5 | 2019-01-09 12:37:57 -0800 | [diff] [blame] | 286 | return 0; |
Venkatesh Yadav Abbarapu | 987fad3 | 2022-04-29 13:52:00 +0530 | [diff] [blame] | 287 | } |
Jolly Shah | 259afe5 | 2019-01-09 12:37:57 -0800 | [diff] [blame] | 288 | } |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 289 | |
Venkatesh Yadav Abbarapu | bfa2a2a | 2021-02-19 01:40:14 -0700 | [diff] [blame] | 290 | #if IPI_CRC_CHECK |
Venkatesh Yadav Abbarapu | 28b7759 | 2022-04-11 09:25:44 +0530 | [diff] [blame] | 291 | uint32_t calculate_crc(uint32_t payload[PAYLOAD_ARG_CNT], uint32_t bufsize) |
Venkatesh Yadav Abbarapu | 35a8be9 | 2019-04-04 14:23:32 +0530 | [diff] [blame] | 292 | { |
| 293 | uint32_t crcinit = CRC_INIT_VALUE; |
| 294 | uint32_t order = CRC_ORDER; |
| 295 | uint32_t polynom = CRC_POLYNOM; |
| 296 | uint32_t i, j, c, bit, datain, crcmask, crchighbit; |
| 297 | uint32_t crc = crcinit; |
| 298 | |
| 299 | crcmask = ((uint32_t)((1U << (order - 1U)) - 1U) << 1U) | 1U; |
| 300 | crchighbit = (uint32_t)(1U << (order - 1U)); |
| 301 | |
| 302 | for (i = 0U; i < bufsize; i++) { |
| 303 | datain = mmio_read_8((unsigned long)payload + i); |
| 304 | c = datain; |
| 305 | j = 0x80U; |
| 306 | while (j != 0U) { |
| 307 | bit = crc & crchighbit; |
| 308 | crc <<= 1U; |
| 309 | if (0U != (c & j)) |
| 310 | bit ^= crchighbit; |
| 311 | if (bit != 0U) |
| 312 | crc ^= polynom; |
| 313 | j >>= 1U; |
| 314 | } |
| 315 | crc &= crcmask; |
| 316 | } |
| 317 | return crc; |
| 318 | } |
| 319 | #endif |