Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 1 | /* |
Jolly Shah | 0bfd700 | 2019-01-08 11:10:47 -0800 | [diff] [blame] | 2 | * Copyright (c) 2017-2018, ARM Limited and Contributors. All rights reserved. |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 3 | * |
| 4 | * SPDX-License-Identifier: BSD-3-Clause |
| 5 | */ |
| 6 | |
| 7 | /* |
| 8 | * Top-level SMC handler for ZynqMP IPI Mailbox doorbell functions. |
| 9 | */ |
| 10 | |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 11 | #include <errno.h> |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 12 | #include <string.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 13 | |
| 14 | #include <common/debug.h> |
| 15 | #include <common/runtime_svc.h> |
| 16 | #include <lib/bakery_lock.h> |
| 17 | #include <lib/mmio.h> |
Jolly Shah | 0bfd700 | 2019-01-08 11:10:47 -0800 | [diff] [blame] | 18 | #include <plat_private.h> |
Antonio Nino Diaz | e0f9063 | 2018-12-14 00:18:21 +0000 | [diff] [blame] | 19 | |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 20 | #include "ipi_mailbox_svc.h" |
| 21 | #include "../zynqmp_ipi.h" |
Wendy Liang | f8fec36 | 2017-09-06 09:39:55 -0700 | [diff] [blame] | 22 | #include "../../../services/spd/trusty/smcall.h" |
| 23 | |
| 24 | /********************************************************************* |
| 25 | * Macros definitions |
| 26 | ********************************************************************/ |
| 27 | |
| 28 | /* IPI SMC calls macros: */ |
| 29 | #define IPI_SMC_OPEN_IRQ_MASK 0x00000001U /* IRQ enable bit in IPI |
| 30 | * open SMC call |
| 31 | */ |
| 32 | #define IPI_SMC_NOTIFY_BLOCK_MASK 0x00000001U /* Flag to indicate if |
| 33 | * IPI notification needs |
| 34 | * to be blocking. |
| 35 | */ |
| 36 | #define IPI_SMC_ENQUIRY_DIRQ_MASK 0x00000001U /* Flag to indicate if |
| 37 | * notification interrupt |
| 38 | * to be disabled. |
| 39 | */ |
| 40 | #define IPI_SMC_ACK_EIRQ_MASK 0x00000001U /* Flag to indicate if |
| 41 | * notification interrupt |
| 42 | * to be enable. |
| 43 | */ |
| 44 | |
| 45 | #define UNSIGNED32_MASK 0xFFFFFFFFU /* 32bit mask */ |
| 46 | |
| 47 | /** |
| 48 | * ipi_smc_handler() - SMC handler for IPI SMC calls |
| 49 | * |
| 50 | * @smc_fid - Function identifier |
| 51 | * @x1 - x4 - Arguments |
| 52 | * @cookie - Unused |
| 53 | * @handler - Pointer to caller's context structure |
| 54 | * |
| 55 | * @return - Unused |
| 56 | * |
| 57 | * Determines that smc_fid is valid and supported PM SMC Function ID from the |
| 58 | * list of pm_api_ids, otherwise completes the request with |
| 59 | * the unknown SMC Function ID |
| 60 | * |
| 61 | * The SMC calls for PM service are forwarded from SIP Service SMC handler |
| 62 | * function with rt_svc_handle signature |
| 63 | */ |
| 64 | uint64_t ipi_smc_handler(uint32_t smc_fid, uint64_t x1, uint64_t x2, |
| 65 | uint64_t x3, uint64_t x4, void *cookie, |
| 66 | void *handle, uint64_t flags) |
| 67 | { |
| 68 | int ret; |
| 69 | uint32_t ipi_local_id; |
| 70 | uint32_t ipi_remote_id; |
| 71 | unsigned int is_secure; |
| 72 | |
| 73 | ipi_local_id = x1 & UNSIGNED32_MASK; |
| 74 | ipi_remote_id = x2 & UNSIGNED32_MASK; |
| 75 | |
| 76 | if (SMC_ENTITY(smc_fid) >= SMC_ENTITY_TRUSTED_APP) |
| 77 | is_secure = 1; |
| 78 | else |
| 79 | is_secure = 0; |
| 80 | |
| 81 | /* Validate IPI mailbox access */ |
| 82 | ret = ipi_mb_validate(ipi_local_id, ipi_remote_id, is_secure); |
| 83 | if (ret) |
| 84 | SMC_RET1(handle, ret); |
| 85 | |
| 86 | switch (SMC_FUNCTION(smc_fid)) { |
| 87 | case IPI_MAILBOX_OPEN: |
| 88 | ipi_mb_open(ipi_local_id, ipi_remote_id); |
| 89 | SMC_RET1(handle, 0); |
| 90 | case IPI_MAILBOX_RELEASE: |
| 91 | ipi_mb_release(ipi_local_id, ipi_remote_id); |
| 92 | SMC_RET1(handle, 0); |
| 93 | case IPI_MAILBOX_STATUS_ENQUIRY: |
| 94 | { |
| 95 | int disable_irq; |
| 96 | |
| 97 | disable_irq = (x3 & IPI_SMC_ENQUIRY_DIRQ_MASK) ? 1 : 0; |
| 98 | ret = ipi_mb_enquire_status(ipi_local_id, ipi_remote_id); |
| 99 | if ((ret & IPI_MB_STATUS_RECV_PENDING) && disable_irq) |
| 100 | ipi_mb_disable_irq(ipi_local_id, ipi_remote_id); |
| 101 | SMC_RET1(handle, ret); |
| 102 | } |
| 103 | case IPI_MAILBOX_NOTIFY: |
| 104 | { |
| 105 | uint32_t is_blocking; |
| 106 | |
| 107 | is_blocking = (x3 & IPI_SMC_NOTIFY_BLOCK_MASK) ? 1 : 0; |
| 108 | ipi_mb_notify(ipi_local_id, ipi_remote_id, is_blocking); |
| 109 | SMC_RET1(handle, 0); |
| 110 | } |
| 111 | case IPI_MAILBOX_ACK: |
| 112 | { |
| 113 | int enable_irq; |
| 114 | |
| 115 | enable_irq = (x3 & IPI_SMC_ACK_EIRQ_MASK) ? 1 : 0; |
| 116 | ipi_mb_ack(ipi_local_id, ipi_remote_id); |
| 117 | if (enable_irq) |
| 118 | ipi_mb_enable_irq(ipi_local_id, ipi_remote_id); |
| 119 | SMC_RET1(handle, 0); |
| 120 | } |
| 121 | case IPI_MAILBOX_ENABLE_IRQ: |
| 122 | ipi_mb_enable_irq(ipi_local_id, ipi_remote_id); |
| 123 | SMC_RET1(handle, 0); |
| 124 | case IPI_MAILBOX_DISABLE_IRQ: |
| 125 | ipi_mb_disable_irq(ipi_local_id, ipi_remote_id); |
| 126 | SMC_RET1(handle, 0); |
| 127 | default: |
| 128 | WARN("Unimplemented IPI service call: 0x%x\n", smc_fid); |
| 129 | SMC_RET1(handle, SMC_UNK); |
| 130 | } |
| 131 | } |