summaryrefslogtreecommitdiff
path: root/packages/ti/sdo/ipc/family/am65xx/NotifySciClient.c
blob: 62374e255e67a6036e6a91d27b31e65c666c511e (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
/*
 * Copyright (C) 2018 Texas Instruments Incorporated - http://www.ti.com/
 *
 * Redistribution and use in source and binary forms, with or without
 * modification, are permitted provided that the following conditions
 * are met:
 *
 * Redistributions of source code must retain the above copyright
 * notice, this list of conditions and the following disclaimer.
 *
 * Redistributions in binary form must reproduce the above copyright
 * notice, this list of conditions and the following disclaimer in the
 * documentation and/or other materials provided with the
 * distribution.
 *
 * Neither the name of Texas Instruments Incorporated nor the names of
 * its contributors may be used to endorse or promote products derived
 * from this software without specific prior written permission.
 *
 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
 *
 */

/* The following are required to avoid issues with types used in CSL */
#undef xdc__strict
/* Define SOC_AM65XX for header files below */
#define SOC_AM65XX

#include <ti/csl/csl_types.h>
#include <ti/drv/sciclient/sciclient.h>

#include "package/internal/NotifySciClient.xdc.h"

#define NOTIFY_SCICLIENT_RESP_TIMEOUT 1000000

/*********************************************************************
 * @fn      NotifySciClient_Init
 *
 * @brief   Initialises NotifySciclient
 *          Currently only checking communication with system core.
 *
 *
 * @return  0 : Success; -1 for failures
 */
Int32 NotifySciClient_Init(void)
{
    int32_t status = 0;
    Sciclient_ConfigPrms_t        config;

    struct tisci_msg_version_req request;
    /* Setup Request for Version check */
    const Sciclient_ReqPrm_t      reqPrm =
    {
        .messageType = TISCI_MSG_VERSION,
        .flags = TISCI_MSG_FLAG_AOP,
        .pReqPayload = (uint8_t *) &request,
        .reqPayloadSize = sizeof(request),
        .timeout = NOTIFY_SCICLIENT_RESP_TIMEOUT
    };

    struct tisci_msg_version_resp response;
    /* Setup Response parameters */
    Sciclient_RespPrm_t           respPrm =
    {
        .flags = 0,
        .pRespPayload = (uint8_t *) &response,
        .respPayloadSize = sizeof (response)
    };

    /* Now reinitialize it as default parameter */
    Sciclient_configPrmsInit(&config);
#if defined(xdc_target__isaCompatible_v8A)
    config.opModeFlag  = SCICLIENT_SERVICE_OPERATION_MODE_POLLED;
#endif

    status = Sciclient_init(&config);
    if (status < 0) {
        return -1;
    }

    /* Check version check to TISCI connection */
    status = Sciclient_service(&reqPrm, &respPrm);
    if (CSL_PASS == status)
    {
        if (respPrm.flags != TISCI_MSG_FLAG_ACK)
        {
            return -1;
        }
    } else {
        return -1;
    }
    return status;
}

/*********************************************************************
 * @fn      NotifySciClient_IrqSet
 *
 * @brief   Configures interrupt routes by requesting the system core
 *
 * @param1  coreIndex: core index
 * @param2  mailboxClusterIndex: Mailbox Cluster index
 * @param3  mailboxUserIndex: Mailbox User index
 * @param4  intNumber: Local cpu interrupt number
 *
 * @return  0 : Success; -1 for failures
 */
Int32 NotifySciClient_IrqSet(NotifySciClient_CoreIndex coreIndex,
               NotifySciClient_SourceIdIndex mailboxClusterIndex,
               NotifySciClient_MailboxIndex mailboxUserIndex,
               UInt32 intNumber)
{
    int32_t status = 0;
    struct tisci_msg_rm_irq_set_resp resp;

    /* Indexed list of dst ids */
    const int32_t map_dst_id[] =
    {
        /* NOTE: This list should match the Core index */
        TISCI_DEV_GIC0,
        TISCI_DEV_MCU_ARMSS0_CPU0,
        TISCI_DEV_MCU_ARMSS0_CPU1
    };
    /* Indexed list of src ids */
    const uint16_t map_src_id[] =
    {
        TISCI_DEV_NAVSS0_MAILBOX0_CLUSTER0,
        TISCI_DEV_NAVSS0_MAILBOX0_CLUSTER1,
        TISCI_DEV_NAVSS0_MAILBOX0_CLUSTER2
    };

    /* Indexed list of host ids */
    const uint16_t map_host_id[] =
    {
        TISCI_HOST_ID_A53_0,
        TISCI_HOST_ID_R5_0,  /* This corresponds to R5F core 0 non-secure */
        TISCI_HOST_ID_R5_2   /* This corresponds to R5F core 1 non-secure */
    };

    /* Initialize unused parameters */
    struct tisci_msg_rm_irq_set_req irq_set_req =
    {
        .ia_id          = 0,
        .vint           = 0,
        .global_event   = 0,
        .vint_status_bit_index = 0,
    };

    /* Request irq set for specified interrupt source */
    irq_set_req.valid_params = 0x80000003 ; /* Sets bits for secondary host, dst_id, dst_host_irq */
    irq_set_req.src_id = map_src_id[mailboxClusterIndex];
    irq_set_req.src_index = mailboxUserIndex;
    irq_set_req.dst_id = map_dst_id[coreIndex];
    irq_set_req.dst_host_irq = intNumber;
    irq_set_req.secondary_host = map_host_id[coreIndex];

    /* Call irq Set */
    if (CSL_PASS != Sciclient_rmIrqSet(&irq_set_req, &resp, NOTIFY_SCICLIENT_RESP_TIMEOUT ))
    {
        return -1;
    }

    return status;
}

/*********************************************************************
 * @fn      NotifySciClient_IrqRelease
 *
 * @brief   Releases interrupt routes by requesting the system core
 *
 * @param1  coreIndex: core index
 * @param2  mailboxClusterIndex: Mailbox Cluster index
 * @param3  mailboxUserIndex: Mailbox User index
 * @param4  intNumber: Local cpu interrupt number
 *
 * @return  0 : Success; -1 for failures
 */
Int32 NotifySciClient_IrqRelease(NotifySciClient_CoreIndex coreIndex,
               NotifySciClient_SourceIdIndex mailboxClusterIndex,
               NotifySciClient_MailboxIndex mailboxUserIndex,
               UInt32 intNumber)
{
    int32_t status = 0;

    /* Indexed list of dst ids */
    const int32_t map_dst_id[] =
    {
        /* NOTE: This list should match the Core index */
        TISCI_DEV_GIC0,
        TISCI_DEV_MCU_ARMSS0_CPU0,
        TISCI_DEV_MCU_ARMSS0_CPU1
    };
    /* Indexed list of src ids */
    const uint16_t map_src_id[] =
    {
        TISCI_DEV_NAVSS0_MAILBOX0_CLUSTER0,
        TISCI_DEV_NAVSS0_MAILBOX0_CLUSTER1,
        TISCI_DEV_NAVSS0_MAILBOX0_CLUSTER2
    };

    /* Indexed list of host ids */
    const uint16_t map_host_id[] =
    {
        TISCI_HOST_ID_A53_0,
        TISCI_HOST_ID_R5_0,  /* This corresponds to R5F core 0 non-secure */
        TISCI_HOST_ID_R5_2   /* This corresponds to R5F core 1 non-secure */
    };

    /* Initialize unused parameters */
    struct tisci_msg_rm_irq_release_req irq_release_req =
    {
        .ia_id          = 0,
        .vint           = 0,
        .global_event   = 0,
        .vint_status_bit_index = 0,
    };

    /* Request irq release for specified interrupt source */
    irq_release_req.valid_params = 0x80000003 ; /* Sets bits for secondary host, dst_id, dst_host_irq */
    irq_release_req.src_id = map_src_id[mailboxClusterIndex];
    irq_release_req.src_index = mailboxUserIndex;
    irq_release_req.dst_id = map_dst_id[coreIndex];
    irq_release_req.dst_host_irq = intNumber;
    irq_release_req.secondary_host = map_host_id[coreIndex];

    /* Call irq Release */
    if (CSL_PASS != Sciclient_rmIrqRelease(&irq_release_req, NOTIFY_SCICLIENT_RESP_TIMEOUT ))
    {
        return -1;
    }

    return status;
}

/*********************************************************************
 * @fn      NotifySciClient_getIntNumRange
 *
 * @brief   Get range of interrupt Numbers available
 *
 * @param1  coreIndex: core index
 * @param2  coreIndex: secondary_host
 * @param1  rangeStartP: Pointer to range start
 * @param2  rangeNumP: Pointer to number of interrupts
 *
 * @return  0 : Success; -1 for failures
 */
Int32 NotifySciClient_getIntNumRange(NotifySciClient_CoreIndex coreIndex,
                                     NotifySciClient_SecondaryHost secondaryHost,
                                     UInt16 *rangeStartP,
                                     UInt16 *rangeNumP)
{
    int32_t status = 0;
    struct tisci_msg_rm_get_resource_range_resp resp;
    struct tisci_msg_rm_get_resource_range_req get_resource_range_req;
   /* Indexed list of req type */
    const uint16_t req_type[] =
    {
        /* NOTE: This list should match the Core index */
        TISCI_RESASG_TYPE_GIC_IRQ,
        TISCI_RESASG_TYPE_PULSAR_C0_IRQ,
        TISCI_RESASG_TYPE_PULSAR_C1_IRQ
    };
   /* Indexed list of req subtype */
    const uint16_t req_subtype[] =
    {
        /* NOTE: This list should match the Core index */
        TISCI_RESASG_SUBTYPE_GIC_IRQ_MAIN_NAV_SET1,
        TISCI_RESASG_SUBTYPE_PULSAR_C0_IRQ_MAIN2MCU_LVL,
        TISCI_RESASG_SUBTYPE_PULSAR_C1_IRQ_MAIN2MCU_LVL
    };

    /* Indexed list of host ids */
    const uint16_t map_host_id[] =
    {
        TISCI_HOST_ID_A53_0,
        TISCI_HOST_ID_R5_0,  /* This corresponds to R5F core 0 non-secure */
        TISCI_HOST_ID_R5_2   /* This corresponds to R5F core 1 non-secure */
    };

    get_resource_range_req.type = req_type[coreIndex];
    get_resource_range_req.subtype = req_subtype[coreIndex];
    if (secondaryHost == NotifySciClient_SECONDARYHOST_UNUSED) {
        get_resource_range_req.secondary_host = TISCI_MSG_VALUE_RM_UNUSED_SECONDARY_HOST;
    } else if (secondaryHost == NotifySciClient_SECONDARYHOST_SPECIFIC_HOST) {
        get_resource_range_req.secondary_host = map_host_id[coreIndex];
    } else {
        get_resource_range_req.secondary_host = TISCI_HOST_ID_ALL;
    }
    /* Get interrupt number range */
    status =  Sciclient_rmGetResourceRange(
                &get_resource_range_req,
                &resp,
                NOTIFY_SCICLIENT_RESP_TIMEOUT);
    if (CSL_PASS == status)
    {
        *rangeStartP = resp.range_start;
        *rangeNumP = resp.range_num;
    } else {
        return -1;
    }
    return status;
}