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