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
|
/*
All files except if stated otherwise in the begining of the file
are under the ISC license:
----------------------------------------------------------------------
Copyright (c) 2010-2012 Design Art Networks Ltd.
Permission to use, copy, modify, and/or distribute this software for any
purpose with or without fee is hereby granted, provided that the above
copyright notice and this permission notice appear in all copies.
THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
*/
/* -----------------------------------------------------------
* Include section
* -----------------------------------------------------------
*/
#include <linux/io.h>
#include "ipc_reg.h"
#include "ipc_api.h"
#include "danipc_lowlevel.h"
/* -----------------------------------------------------------
* MACRO (define) section
* -----------------------------------------------------------
*/
#define TCSR_IPC_IF_FIFO_RD_ACCESS_2_OFFSET 0x18
#define TCSR_IPC_IF_FIFO_RD_ACCESS_0_OFFSET 0x8
#define TCSR_IPC_FIFO_RD_IN_LOW_ADDR(cpuid) \
(ipc_regs[cpuid] + TCSR_IPC_IF_FIFO_RD_ACCESS_2_OFFSET)
#define TCSR_IPC_FIFO_RD_IN_HIGH_ADDR(cpuid) \
(ipc_regs[cpuid] + TCSR_IPC_IF_FIFO_RD_ACCESS_0_OFFSET)
#define IPC_FIFO_ACCESS(cpuid, odd, even) ({ \
const typeof(cpuid) __cpuid = cpuid; \
ipc_regs[__cpuid] + ((__cpuid & 1) ? (odd) : (even)); })
#define IPC_FIFO_RD_OUT_HIGH_ADDR(cpuid) \
IPC_FIFO_ACCESS(cpuid, DAN_IPC_IF_FIFO_RD_5, DAN_IPC_IF_FIFO_RD_1)
#define IPC_FIFO_RD_OUT_LOW_ADDR(cpuid) \
IPC_FIFO_ACCESS(cpuid, DAN_IPC_IF_FIFO_RD_7, DAN_IPC_IF_FIFO_RD_3)
#define IPC_FIFO_WR_IN_HIGH_ADDR(cpuid) \
IPC_FIFO_ACCESS(cpuid, DAN_IPC_IF_FIFO_WR_4, DAN_IPC_IF_FIFO_WR_0)
#define IPC_FIFO_WR_OUT_HIGH_ADDR(cpuid) \
IPC_FIFO_ACCESS(cpuid, DAN_IPC_IF_FIFO_WR_5, DAN_IPC_IF_FIFO_WR_1)
#define IPC_FIFO_WR_IN_LOW_ADDR(cpuid) \
IPC_FIFO_ACCESS(cpuid, DAN_IPC_IF_FIFO_WR_6, DAN_IPC_IF_FIFO_WR_2)
#define IPC_FIFO_WR_OUT_LOW_ADDR(cpuid) \
IPC_FIFO_ACCESS(cpuid, DAN_IPC_IF_FIFO_WR_7, DAN_IPC_IF_FIFO_WR_3)
uint32_t ipc_regs_phys[PLATFORM_MAX_NUM_OF_NODES];
unsigned ipc_regs_len[PLATFORM_MAX_NUM_OF_NODES];
uint32_t ipc_shared_mem_sizes[PLATFORM_MAX_NUM_OF_NODES];
/* Remapped addresses from ipc_regs_phys */
uintptr_t ipc_regs[PLATFORM_MAX_NUM_OF_NODES];
/* -----------------------------------------------------------
* Global prototypes section
* -----------------------------------------------------------
*/
/* ipc_trns_fifo_buf_alloc
*
* Transport layer buffer allocation API
* use to allocate buffer when message is to be sent
* from an agent on the phy to another agent on the
* phy (i.e. using fifo based transport)
*
*/
char *ipc_trns_fifo_buf_alloc(uint8_t cpuid, enum ipc_trns_prio prio)
{
uint32_t buff_addr;
uint32_t fifo_addr;
if (prio == ipc_trns_prio_0)
fifo_addr = IPC_FIFO_RD_OUT_LOW_ADDR(cpuid);
else
fifo_addr = IPC_FIFO_RD_OUT_HIGH_ADDR(cpuid);
buff_addr = __raw_readl_no_log((void *)fifo_addr);
return (char *) ((buff_addr) ?
ipc_to_virt(cpuid, prio, buff_addr) : 0);
}
/* ipc_trns_fifo_buf_free
*
* Transport layer buffer free API
* use to free buffer when message is receievd
* from an agent on the phy to another agent on the
* phy (i.e. using fifo based transport)
*
*/
void ipc_trns_fifo_buf_free(char *ptr, uint8_t cpuid, enum ipc_trns_prio prio)
{
uint32_t fifo_addr;
if (likely(ptr)) {
if (prio == ipc_trns_prio_0)
fifo_addr = IPC_FIFO_WR_OUT_LOW_ADDR(cpuid);
else
fifo_addr = IPC_FIFO_WR_OUT_HIGH_ADDR(cpuid);
__raw_writel_no_log(virt_to_ipc(cpuid, prio, (void *)ptr),
(void *)fifo_addr);
}
}
/* ipc_trns_fifo_buf_send
*
* Transport layer message sent API
* use to send message when message is to be sent
* from an agent on the phy to another agent on the
* phy (i.e. using fifo based transport)
*
*/
int32_t ipc_trns_fifo_buf_send(char *ptr, uint8_t cpuid,
enum ipc_trns_prio prio)
{
uint32_t fifo_addr;
if (prio == ipc_trns_prio_0)
fifo_addr = IPC_FIFO_WR_IN_LOW_ADDR(cpuid);
else
fifo_addr = IPC_FIFO_WR_IN_HIGH_ADDR(cpuid);
__raw_writel_no_log(virt_to_ipc(cpuid, prio, (void *)ptr),
(void *)fifo_addr);
return 0;
}
/* ipc_trns_fifo2eth_buf_alloc:
*
* Transport layer buffer allocation API
* use to allocate buffer when message is to be sent
* from an agent on the phy to another agent on the
* phy (i.e. using fifo based transport)
*
*/
char *ipc_trns_fifo2eth_buf_alloc(
uint8_t cpuid,
enum ipc_trns_prio prio
)
{
uint32_t buff_addr;
uint32_t fifo_addr;
(void)cpuid;
if (prio == ipc_trns_prio_0)
fifo_addr = IPC_FIFO_RD_OUT_LOW_ADDR(0);
else
fifo_addr = IPC_FIFO_RD_OUT_HIGH_ADDR(0);
buff_addr = __raw_readl_no_log((void *)fifo_addr);
return (char *)buff_addr;
}
/* ipc_trns_fifo2eth_buf_free:
*
* Transport layer buffer free API
* use to free buffer when message is receievd
* from an agent on the phy to another agent on the
* phy (i.e. using fifo based transport)
*
*/
void ipc_trns_fifo2eth_buf_free(char *ptr, uint8_t cpuid,
enum ipc_trns_prio prio)
{
uint32_t fifo_addr;
(void)cpuid;
if (likely(ptr)) {
if (prio == ipc_trns_prio_0)
fifo_addr = IPC_FIFO_WR_OUT_LOW_ADDR(0);
else
fifo_addr = IPC_FIFO_WR_OUT_HIGH_ADDR(0);
__raw_writel_no_log((uint32_t)ptr, (void *)fifo_addr);
}
}
/* ipc_trns_fifo2eth_buf_send
*
* Transport layer message sent API
* use to send message when message is to be sent
* from an agent on the phy to an agent on the mac
* (i.e. using fifo based transport to a predefined proxy)
*
*/
int32_t ipc_trns_fifo2eth_buf_send(char *ptr, uint8_t cpuid,
enum ipc_trns_prio prio)
{
uint32_t fifo_addr;
(void)cpuid;
if (prio == ipc_trns_prio_0)
fifo_addr = IPC_FIFO_WR_IN_LOW_ADDR(0);
else
fifo_addr = IPC_FIFO_WR_IN_HIGH_ADDR(0);
__raw_writel_no_log((uint32_t)ptr, (void *)fifo_addr);
return 0;
}
/* -----------------------------------------------------------
* Function: ipc_trns_fifo_buf_init
* Description: Initialize IPC buffer for current node
* Input: cpuid: node ID ()
* Output: None
* -----------------------------------------------------------
*/
void ipc_trns_fifo_buf_init(uint8_t cpuid)
{
uint32_t fifo_addr;
unsigned ix;
uint32_t buf_addr = virt_to_ipc(cpuid, ipc_trns_prio_1,
ipc_buffers);
fifo_addr = IPC_FIFO_WR_OUT_HIGH_ADDR(cpuid);
for (ix = 0; ix < IPC_FIFO_BUF_NUM_HIGH;
ix++, buf_addr += IPC_BUF_SIZE_MAX)
__raw_writel_no_log(buf_addr, (void *)fifo_addr);
fifo_addr = IPC_FIFO_WR_OUT_LOW_ADDR(cpuid);
for (ix = 0; ix < IPC_FIFO_BUF_NUM_LOW;
ix++, buf_addr += IPC_BUF_SIZE_MAX)
__raw_writel_no_log(buf_addr, (void *)fifo_addr);
}
/* -----------------------------------------------------------
* Function: ipc_trns_fifo_buf_read
* Description: Get message from node associated FIFO
* Input: agentId: NOT USED, current node ID already detected
* Output: None
* -----------------------------------------------------------
*/
char *ipc_trns_fifo_buf_read(enum ipc_trns_prio prio)
{
uint32_t fifo_addr;
uint32_t buff_addr = 0;
const uint8_t cpuid = ipc_own_node;
if (prio == ipc_trns_prio_0)
fifo_addr = TCSR_IPC_FIFO_RD_IN_LOW_ADDR(cpuid);
else
fifo_addr = TCSR_IPC_FIFO_RD_IN_HIGH_ADDR(cpuid);
buff_addr = __raw_readl_no_log((void *)fifo_addr);
return (char *)((buff_addr) ? ipc_to_virt(cpuid, prio, buff_addr) : 0);
}
|