summaryrefslogtreecommitdiff
path: root/hifi/xaf/hifi-dpf/include/sys/xt-shmem/xf-shmem.h
blob: 813bfb48d36c5b736a31270faa01fbfdd7a477f2 (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
/*******************************************************************************
* Copyright (C) 2018 Cadence Design Systems, Inc.
* 
* Permission is hereby granted, free of charge, to any person obtaining
* a copy of this software and associated documentation files (the
* "Software"), to use this Software with Cadence processor cores only and 
* not with any other processors and platforms, subject to
* the following conditions:
* 
* The above copyright notice and this permission notice shall be included
* in all copies or substantial portions of the Software.
* 
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

******************************************************************************/

/*******************************************************************************
 * xf-shmem.h
 *
 * Definitions for Xtensa SHMEM configuration
 *
 *******************************************************************************/

#ifndef __XF_H
#error "xf-shmem.h mustn't be included directly"
#endif

/*******************************************************************************
 * Memory structures
 ******************************************************************************/

/* ...data managed by host CPU (remote) - in case of shunt it is a IPC layer */
struct xf_proxy_host_data
{
    /* ...command queue */
    xf_proxy_message_t      command[XF_PROXY_MESSAGE_QUEUE_LENGTH];
    
    /* ...writing index into command queue */
    u32                     cmd_write_idx;
    
    /* ...reading index for response queue */
    u32                     rsp_read_idx;
#ifdef XAF_ENABLE_NON_HIKEY
}   __attribute__((__packed__, __aligned__(XF_PROXY_ALIGNMENT)));
#else
}/*   __attribute__((__packed__, __aligned__(XF_PROXY_ALIGNMENT)))*/;
#endif

/* ...data managed by DSP (local) */
struct xf_proxy_dsp_data
{
    /* ...response queue */
    xf_proxy_message_t      response[XF_PROXY_MESSAGE_QUEUE_LENGTH];
    
    /* ...writing index into response queue */
    u32                     rsp_write_idx;
    
    /* ...reading index for command queue */
    u32                     cmd_read_idx;
#ifdef XAF_ENABLE_NON_HIKEY
}   __attribute__((__packed__, __aligned__(XF_PROXY_ALIGNMENT)));
#else
}/*   __attribute__((__packed__, __aligned__(XF_PROXY_ALIGNMENT)))*/;
#endif
/* ...shared memory data */
typedef struct xf_shmem_data 
{
    /* ...outgoing data (maintained by host CPU (remote side)) */
#ifdef XAF_ENABLE_NON_HIKEY
    struct xf_proxy_host_data   remote      __xf_shmem__;
    
    /* ...ingoing data (maintained by DSP (local side)) */
    struct xf_proxy_dsp_data    local       __xf_shmem__;

    /* ...shared memory pool (page-aligned; why? we map memory to user-space) */
    u8                          buffer[XF_CFG_REMOTE_IPC_POOL_SIZE]   __attribute__((__aligned__(4096)));
#else
    /* ...outgoing data (maintained by host CPU (remote side)) */
    struct xf_proxy_host_data   remote/*      __xf_shmem__*/;
    
    /* ...ingoing data (maintained by DSP (local side)) */
    struct xf_proxy_dsp_data    local/*       __xf_shmem__*/;

    /* ...shared memory pool (page-aligned; why? we map memory to user-space) */
    uint8_t*                          buffer;
#endif

}   xf_shmem_data_t;

/*******************************************************************************
 * Shared memory accessors
 ******************************************************************************/

/* ...shared memory pointer for a core */
#define XF_SHMEM_DATA(core)                         \
    ((xf_shmem_data_t *)XF_CORE_DATA(core)->shmem)

/* ...atomic reading */
#define XF_PROXY_READ_ATOMIC(var)                   \
    ({ XF_PROXY_INVALIDATE(&(var), sizeof(var)); (var); })

/* ...atomic writing */
#define XF_PROXY_WRITE_ATOMIC(var, value)           \
    ({(var) = (value); XF_PROXY_FLUSH(&(var), sizeof(var)); (value); })

/* ...accessors */
#define XF_PROXY_READ(core, field)                  \
    __XF_PROXY_READ_##field(XF_SHMEM_DATA(core))

#define XF_PROXY_WRITE(core, field, v)              \
    __XF_PROXY_WRITE_##field(XF_SHMEM_DATA(core), (v))

/* ...individual fields accessors */
#define __XF_PROXY_READ_cmd_write_idx(proxy)        \
    XF_PROXY_READ_ATOMIC(proxy->remote.cmd_write_idx)

#define __XF_PROXY_READ_cmd_read_idx(proxy)         \
    proxy->local.cmd_read_idx

#define __XF_PROXY_READ_rsp_write_idx(proxy)        \
    proxy->local.rsp_write_idx

#define __XF_PROXY_READ_rsp_read_idx(proxy)         \
    XF_PROXY_READ_ATOMIC(proxy->remote.rsp_read_idx)

/* ...individual fields accessors */
#define __XF_PROXY_WRITE_cmd_write_idx(proxy, v)    \
    XF_PROXY_WRITE_ATOMIC(proxy->remote.cmd_write_idx, v)

#define __XF_PROXY_WRITE_cmd_read_idx(proxy, v)     \
    XF_PROXY_WRITE_ATOMIC(proxy->local.cmd_read_idx, v)

#define __XF_PROXY_WRITE_rsp_read_idx(proxy, v)     \
    XF_PROXY_WRITE_ATOMIC(proxy->remote.rsp_read_idx, v)

#define __XF_PROXY_WRITE_rsp_write_idx(proxy, v)    \
    XF_PROXY_WRITE_ATOMIC(proxy->local.rsp_write_idx, v)

/* ...command buffer accessor */
#define XF_PROXY_COMMAND(core, idx)                 \
    (&XF_SHMEM_DATA((core))->remote.command[(idx)])

/* ...response buffer accessor */
#define XF_PROXY_RESPONSE(core, idx)                \
    (&XF_SHMEM_DATA((core))->local.response[(idx)])

/*******************************************************************************
 * Platform-specific SHMEM enable status
 ******************************************************************************/

static inline int xf_shmem_enabled(u32 core)
{
    return (core == 0);
}

/*******************************************************************************
 * API functions
 ******************************************************************************/

/* ...process shared memory interface on given DSP core */
extern void xf_shmem_process_queues(u32 core);

/* ...completion callback for message originating from remote proxy */
extern void xf_msg_proxy_complete(xf_message_t *m);

/* ...initialize shared memory interface (DSP side) */
extern int xf_shmem_init(u32 core);