summaryrefslogtreecommitdiff
path: root/drivers/dsp/syslink/multicore_ipc/listmp.c
blob: 742c67f58f4c64bf4022ab37b6c31fd9e47c4148 (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
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
/*
 *  listmp_sharedmemory.c
 *
 *  The listmp_sharedmemory is a linked-list based module designed to be
 *  used in a multi-processor environment.  It is designed to
 *  provide a means of communication between different processors.
 *
 *  Copyright (C) 2008-2009 Texas Instruments, Inc.
 *
 *  This package is free software; you can redistribute it and/or modify
 *  it under the terms of the GNU General Public License version 2 as
 *  published by the Free Software Foundation.
 *
 *  THIS PACKAGE IS PROVIDED ``AS IS'' AND WITHOUT ANY EXPRESS OR
 *  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
 *  WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR
 *  PURPOSE.
 */

/*!
 *
 *  This module implements the ListMP.
 *  This module is instance based. Each instance requires a small
 *  piece of shared memory. This is specified via the #shared_addr
 *  parameter to the create. The proper #shared_addr_size parameter
 *  can be determined via the #sharedMemReq call. Note: the
 *  parameters to this function must be the same that will used to
 *  create or open the instance.
 *  The ListMP module uses a #ti.sdo.utils.NameServer instance
 *  to store instance information when an instance is created and
 *  the name parameter is non-NULL. If a name is supplied, it must
 *  be unique for all ListMP instances.
 *  The #create also initializes the shared memory as needed. The
 *  shared memory must be initialized to 0 or all ones
 *  (e.g. 0xFFFFFFFFF) before the ListMP instance is created.
 *  Once an instance is created, an open can be performed. The #open
 *  is used to gain access to the same ListMP instance.
 *  Generally an instance is created on one processor and opened
 *  on the other processor.
 *  The open returns a ListMP instance handle like the create,
 *  however the open does not modify the shared memory. Generally an
 *  instance is created on one processor and opened on the other
 *  processor.
 *  There are two options when opening the instance:
 *  @li Supply the same name as specified in the create. The
 *  ListMP module queries the NameServer to get the needed
 *  information.
 *  @li Supply the same #shared_addr value as specified in the
 *  create. If the open is called before the instance is created,
 *  open returns NULL.
 *  There is currently a list of restrictions for the module:
 *  @li Both processors must have the same endianness. Endianness
 *  conversion may supported in a future version of ListMP.
 *  @li The module will be made a gated module
 */


/* Standard headers */
#include <linux/types.h>
#include <linux/module.h>

/* Utilities headers */
#include <linux/string.h>
#include <linux/list.h>

/* Module level headers */
#include <nameserver.h>
#include <listmp.h>
#include <listmp_sharedmemory.h>


/*
 * ======== listmp_params_init ========
 *  Purpose:
 *  Function initializes listmp parameters
 */
void listmp_params_init(void *listmp_handle, struct listmp_params *params)
{
	BUG_ON(params == NULL);
	listmp_sharedmemory_params_init(listmp_handle, params);
}

/*
 * ======== listmp_shared_memreq ========
 *  Purpose:
 *  Function to get shared memory requirement for the module
 */
int listmp_shared_memreq(struct listmp_params *params)
{
	int shared_memreq = 0;

	if (WARN_ON(params == NULL))
		goto exit;

	shared_memreq = listmp_sharedmemory_shared_memreq(params);
exit:
	return shared_memreq;
}

/*
 * ======== listmp_create ========
 *  Purpose:
 *  Creates a new instance of listmp_sharedmemory module.
 */
void *listmp_create(struct listmp_params *params)
{
	struct listmp_object *handle = NULL;

	if (WARN_ON(params == NULL))
		goto exit;

	if (params->list_type == listmp_type_SHARED)
		handle = (struct listmp_object *)
				listmp_sharedmemory_create(params);
	return (void *)handle;

exit:
	printk(KERN_ERR "listmp_create: listmp_params passed are NULL!\n");
	return NULL;
}

/*
 * ======== listmp_delete ========
 *  Purpose:
 *  Deletes an instance of listmp_sharedmemory module.
 */
int listmp_delete(void **listmp_handle_ptr)
{
	int status = 0;

	if (WARN_ON(*listmp_handle_ptr == NULL)) {
		status = -EINVAL;
		goto exit;
	}

	if (((struct listmp_object *)(*listmp_handle_ptr))->list_type == \
		listmp_type_SHARED)
		status = listmp_sharedmemory_delete(listmp_handle_ptr);

exit:
	if (status < 0) {
		printk(KERN_ERR "listmp_delete failed! status = 0x%x\n",
			status);
	}
	return status;
}

/*
 * ======== listmp_open ========
 *  Purpose:
 *  Opens an instance ofa previously created listmp_sharedmemory module.
 */
int listmp_open(void **listmp_handle_ptr, struct listmp_params *params)
{
	int  status = 0;

	if (WARN_ON(listmp_handle_ptr == NULL)) {
		status = -EINVAL;
		goto exit;
	}
	if (WARN_ON(params == NULL)) {
		status = -EINVAL;
		goto exit;
	}

	if (params->list_type == listmp_type_SHARED)
		status = listmp_sharedmemory_open(listmp_handle_ptr, params);

exit:
	if (status < 0)
		printk(KERN_ERR "listmp_open failed! status = 0x%x\n", status);
	return status;
}

/*
 * ======== listmp_close ========
 *  Purpose:
 *  Closes an instance of a previously opened listmp_sharedmemory module.
 */
int listmp_close(void *listmp_handle)
{
	int status = 0;

	if (WARN_ON(listmp_handle == NULL)) {
		status = -EINVAL;
		goto exit;
	}

	if (((struct listmp_object *)listmp_handle)->list_type == \
		listmp_type_SHARED)
		status = listmp_sharedmemory_close(listmp_handle);

exit:
	if (status < 0)
		printk(KERN_ERR "listmp_close failed! status = 0x%x\n", status);
	return status;
}

/*
 * ======== listmp_empty ========
 *  Purpose:
 *  Function to check if list is empty
 */
bool listmp_empty(void *listmp_handle)
{
	bool isEmpty = false;
	struct listmp_object *handle = NULL;

	if (WARN_ON(listmp_handle == NULL))
		goto exit;

	handle = (struct listmp_object *)listmp_handle;

	BUG_ON(handle->empty == NULL);
	isEmpty = handle->empty(listmp_handle);

exit:
	return isEmpty;
}

/*
 * ======== listmp_get_head ========
 *  Purpose:
 *  Function to get head element from a listmp_sharedmemory list
 */
void *listmp_get_head(void *listmp_handle)
{
	struct listmp_object *handle = NULL;
	struct listmp_elem *elem = NULL;

	if (WARN_ON(listmp_handle == NULL))
		goto exit;

	handle = (struct listmp_object *)listmp_handle;

	BUG_ON(handle->get_head == NULL);
	elem = handle->get_head(listmp_handle);

exit:
	return elem;
}

/*
 * ======== listmp_get_tail =====
 *  Purpose:
 *  Function to get tailement from a listmp_sharedmemory list
 */
void *listmp_get_tail(void *listmp_handle)
{
	struct listmp_object *handle = NULL;
	struct listmp_elem *elem = NULL;

	if (WARN_ON(listmp_handle == NULL))
		goto exit;

	handle = (struct listmp_object *)listmp_handle;

	BUG_ON(handle->get_tail == NULL);
	elem = handle->get_tail(listmp_handle);

exit:
	return elem;
}

/*
 * ======== listmp_put_head ========
 *  Purpose:
 *  Function to put head element into a listmp_sharedmemory list
 */
int listmp_put_head(void *listmp_handle, struct listmp_elem *elem)
{
	int status = 0;
	struct listmp_object *handle = NULL;

	if (WARN_ON(listmp_handle == NULL)) {
		status = -EINVAL;
		goto exit;
	}
	if (WARN_ON(elem == NULL)) {
		status = -EINVAL;
		goto exit;
	}

	handle = (struct listmp_object *) listmp_handle;

	BUG_ON(handle->put_head == NULL);
	status = handle->put_head(listmp_handle, elem);

exit:
	if (status < 0) {
		printk(KERN_ERR "listmp_put_head failed! status = 0x%x\n",
			status);
	}
	return status;
}

/*
 * ======== listmp_put_tail ========
 *  Purpose:
 *  Function to put tail element into a listmp_sharedmemory list
 */
int listmp_put_tail(void *listmp_handle, struct listmp_elem *elem)
{
	int status = 0;
	struct listmp_object *handle = NULL;

	if (WARN_ON(listmp_handle == NULL)) {
		status = -EINVAL;
		goto exit;
	}
	if (WARN_ON(elem == NULL)) {
		status = -EINVAL;
		goto exit;
	}

	handle = (struct listmp_object *)listmp_handle;

	BUG_ON(handle->put_tail == NULL);
	status = handle->put_tail(listmp_handle, elem);

exit:
	if (status < 0) {
		printk(KERN_ERR "listmp_put_tail failed! status = 0x%x\n",
			status);
	}
	return status;
}

/*
 * ======== listmp_insert ========
 *  Purpose:
 *  Function to insert element into a listmp_sharedmemory list
 */
int listmp_insert(void *listmp_handle, struct listmp_elem *elem,
			struct listmp_elem *curElem)
{
	int status = 0;
	struct listmp_object *handle = NULL;

	if (WARN_ON(listmp_handle == NULL)) {
		status = -EINVAL;
		goto exit;
	}
	if (WARN_ON(elem == NULL)) {
		status = -EINVAL;
		goto exit;
	}
	if (WARN_ON(curElem == NULL)) {
		status = -EINVAL;
		goto exit;
	}

	handle = (struct listmp_object *)listmp_handle;

	BUG_ON(handle->insert == NULL);
	status = handle->insert(listmp_handle, elem, curElem);

exit:
	if (status < 0) {
		printk(KERN_ERR "listmp_insert failed! status = 0x%x\n",
			status);
	}
	return status;
}

/*
 * ======== listmp_remove ========
 *  Purpose:
 *  Function to remove an element from a listmp_sharedmemory list
 */
int listmp_remove(void *listmp_handle, struct listmp_elem *elem)
{
	int status = LISTMP_SUCCESS;
	struct listmp_object *handle = NULL;

	if (WARN_ON(listmp_handle == NULL)) {
		status = -EINVAL;
		goto exit;
	}
	if (WARN_ON(elem == NULL)) {
		status = -EINVAL;
		goto exit;
	}

	handle = (struct listmp_object *)listmp_handle;

	BUG_ON(handle->remove == NULL);
	status = handle->remove(listmp_handle, elem);

exit:
	if (status < 0) {
		printk(KERN_ERR "listmp_remove failed! status = 0x%x\n",
			status);
	}
	return status ;
}

/*
 * ======== listmp_next ========
 *  Purpose:
 *  Function to return the next element from a listmp_sharedmemory list
 */
void *listmp_next(void *listmp_handle, struct listmp_elem *elem)
{
	struct listmp_object *handle = NULL;
	struct listmp_elem *nextElem = NULL;

	if (WARN_ON(listmp_handle == NULL))
		goto exit;

	handle = (struct listmp_object *)listmp_handle;

	BUG_ON(handle->next == NULL);
	nextElem = handle->next(listmp_handle, elem);

exit:
	return nextElem;
}

/*
 * ======== listmp_next ========
 *  Purpose:
 *  Function to return the prev element from a listmp_sharedmemory list
 */
void *listmp_prev(void *listmp_handle, struct listmp_elem *elem)
{
	struct listmp_object *handle = NULL;
	struct listmp_elem *prevElem = NULL;

	if (WARN_ON(listmp_handle == NULL))
		goto exit;

	handle = (struct listmp_object *)listmp_handle;

	BUG_ON(handle->prev == NULL);
	prevElem = handle->prev(listmp_handle, elem);

exit:
	return prevElem;
}