Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 1 | /* |
Michal Simek | 2a47faa | 2023-04-14 08:43:51 +0200 | [diff] [blame] | 2 | * Copyright (c) 2017-2019, Arm Limited and Contributors. All rights reserved. |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame^] | 3 | * Copyright (c) 2022-2023, Advanced Micro Devices, Inc. All rights reserved. |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 4 | * |
| 5 | * SPDX-License-Identifier: BSD-3-Clause |
| 6 | */ |
| 7 | |
| 8 | /* |
| 9 | * Top-level SMC handler for ZynqMP IPI Mailbox doorbell functions. |
| 10 | */ |
| 11 | |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 12 | #include <errno.h> |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 13 | #include <string.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 14 | |
| 15 | #include <common/debug.h> |
| 16 | #include <common/runtime_svc.h> |
| 17 | #include <lib/bakery_lock.h> |
| 18 | #include <lib/mmio.h> |
Jolly Shah | c2583ab | 2019-01-08 11:31:49 -0800 | [diff] [blame] | 19 | |
| 20 | #include <ipi.h> |
Jolly Shah | 4c17237 | 2019-01-08 11:21:29 -0800 | [diff] [blame] | 21 | #include <plat_ipi.h> |
Jolly Shah | 0bfd700 | 2019-01-08 11:10:47 -0800 | [diff] [blame] | 22 | #include <plat_private.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 23 | |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 24 | #include "ipi_mailbox_svc.h" |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 25 | |
| 26 | /********************************************************************* |
| 27 | * Macros definitions |
| 28 | ********************************************************************/ |
| 29 | |
| 30 | /* IPI SMC calls macros: */ |
| 31 | #define IPI_SMC_OPEN_IRQ_MASK 0x00000001U /* IRQ enable bit in IPI |
| 32 | * open SMC call |
| 33 | */ |
| 34 | #define IPI_SMC_NOTIFY_BLOCK_MASK 0x00000001U /* Flag to indicate if |
| 35 | * IPI notification needs |
| 36 | * to be blocking. |
| 37 | */ |
| 38 | #define IPI_SMC_ENQUIRY_DIRQ_MASK 0x00000001U /* Flag to indicate if |
| 39 | * notification interrupt |
| 40 | * to be disabled. |
| 41 | */ |
| 42 | #define IPI_SMC_ACK_EIRQ_MASK 0x00000001U /* Flag to indicate if |
| 43 | * notification interrupt |
| 44 | * to be enable. |
| 45 | */ |
| 46 | |
| 47 | #define UNSIGNED32_MASK 0xFFFFFFFFU /* 32bit mask */ |
| 48 | |
| 49 | /** |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame^] | 50 | * ipi_smc_handler() - SMC handler for IPI SMC calls. |
| 51 | * @smc_fid: Function identifier. |
| 52 | * @x1: Arguments. |
| 53 | * @x2: Arguments. |
| 54 | * @x3: Arguments. |
| 55 | * @x4: Arguments. |
| 56 | * @cookie: Unused. |
| 57 | * @handle: Pointer to caller's context structure. |
| 58 | * @flags: SECURE_FLAG or NON_SECURE_FLAG. |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 59 | * |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame^] | 60 | * Return: Unused. |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 61 | * |
| 62 | * Determines that smc_fid is valid and supported PM SMC Function ID from the |
| 63 | * list of pm_api_ids, otherwise completes the request with |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame^] | 64 | * the unknown SMC Function ID. |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 65 | * |
| 66 | * The SMC calls for PM service are forwarded from SIP Service SMC handler |
Prasad Kummari | 7d0623a | 2023-06-09 14:32:00 +0530 | [diff] [blame^] | 67 | * function with rt_svc_handle signature. |
| 68 | * |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 69 | */ |
| 70 | uint64_t ipi_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, |
Venkatesh Yadav Abbarapu | d3c0eb4 | 2022-05-24 14:02:52 +0530 | [diff] [blame] | 71 | uint64_t x3, uint64_t x4, const void *cookie, |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 72 | void *handle, uint64_t flags) |
| 73 | { |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 74 | int32_t ret; |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 75 | uint32_t ipi_local_id; |
| 76 | uint32_t ipi_remote_id; |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 77 | uint32_t is_secure; |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 78 | |
| 79 | ipi_local_id = x1 & UNSIGNED32_MASK; |
| 80 | ipi_remote_id = x2 & UNSIGNED32_MASK; |
| 81 | |
Akshay Belsare | ac45dbf | 2022-12-15 15:56:23 +0530 | [diff] [blame] | 82 | /* OEN Number 48 to 63 is for Trusted App and OS |
| 83 | * GET_SMC_OEN limits the return value of OEN number to 63 by bitwise |
| 84 | * AND operation with 0x3F. |
| 85 | * Upper limit check for OEN value is not required. |
| 86 | */ |
| 87 | if (GET_SMC_OEN(smc_fid) >= OEN_TAP_START) { |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 88 | is_secure = 1; |
Akshay Belsare | 6435ca0 | 2022-12-12 12:13:14 +0530 | [diff] [blame] | 89 | } else { |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 90 | is_secure = 0; |
Akshay Belsare | 6435ca0 | 2022-12-12 12:13:14 +0530 | [diff] [blame] | 91 | } |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 92 | |
| 93 | /* Validate IPI mailbox access */ |
| 94 | ret = ipi_mb_validate(ipi_local_id, ipi_remote_id, is_secure); |
| 95 | if (ret) |
| 96 | SMC_RET1(handle, ret); |
| 97 | |
Akshay Belsare | 6435ca0 | 2022-12-12 12:13:14 +0530 | [diff] [blame] | 98 | switch (GET_SMC_NUM(smc_fid)) { |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 99 | case IPI_MAILBOX_OPEN: |
| 100 | ipi_mb_open(ipi_local_id, ipi_remote_id); |
| 101 | SMC_RET1(handle, 0); |
| 102 | case IPI_MAILBOX_RELEASE: |
| 103 | ipi_mb_release(ipi_local_id, ipi_remote_id); |
| 104 | SMC_RET1(handle, 0); |
| 105 | case IPI_MAILBOX_STATUS_ENQUIRY: |
| 106 | { |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 107 | int32_t disable_irq; |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 108 | |
| 109 | disable_irq = (x3 & IPI_SMC_ENQUIRY_DIRQ_MASK) ? 1 : 0; |
| 110 | ret = ipi_mb_enquire_status(ipi_local_id, ipi_remote_id); |
| 111 | if ((ret & IPI_MB_STATUS_RECV_PENDING) && disable_irq) |
| 112 | ipi_mb_disable_irq(ipi_local_id, ipi_remote_id); |
| 113 | SMC_RET1(handle, ret); |
| 114 | } |
| 115 | case IPI_MAILBOX_NOTIFY: |
| 116 | { |
| 117 | uint32_t is_blocking; |
| 118 | |
| 119 | is_blocking = (x3 & IPI_SMC_NOTIFY_BLOCK_MASK) ? 1 : 0; |
Venkatesh Yadav Abbarapu | efa1d32 | 2021-08-04 21:33:15 -0600 | [diff] [blame] | 120 | ipi_mb_notify(ipi_local_id, ipi_remote_id, is_blocking); |
| 121 | SMC_RET1(handle, 0); |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 122 | } |
| 123 | case IPI_MAILBOX_ACK: |
| 124 | { |
Venkatesh Yadav Abbarapu | e7c4538 | 2022-05-19 14:49:49 +0530 | [diff] [blame] | 125 | int32_t enable_irq; |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 126 | |
| 127 | enable_irq = (x3 & IPI_SMC_ACK_EIRQ_MASK) ? 1 : 0; |
| 128 | ipi_mb_ack(ipi_local_id, ipi_remote_id); |
| 129 | if (enable_irq) |
| 130 | ipi_mb_enable_irq(ipi_local_id, ipi_remote_id); |
| 131 | SMC_RET1(handle, 0); |
| 132 | } |
| 133 | case IPI_MAILBOX_ENABLE_IRQ: |
| 134 | ipi_mb_enable_irq(ipi_local_id, ipi_remote_id); |
| 135 | SMC_RET1(handle, 0); |
| 136 | case IPI_MAILBOX_DISABLE_IRQ: |
| 137 | ipi_mb_disable_irq(ipi_local_id, ipi_remote_id); |
| 138 | SMC_RET1(handle, 0); |
| 139 | default: |
| 140 | WARN("Unimplemented IPI service call: 0x%x\n", smc_fid); |
| 141 | SMC_RET1(handle, SMC_UNK); |
| 142 | } |
| 143 | } |