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