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