1 /* SPDX-License-Identifier: GPL-2.0-only
3 * Copyright (C) 2020-21 Intel Corporation.
6 #ifndef IOSM_IPC_TASK_QUEUE_H
7 #define IOSM_IPC_TASK_QUEUE_H
9 /* Number of available element for the input message queue of the IPC
12 #define IPC_THREAD_QUEUE_SIZE 256
15 * struct ipc_task_queue_args - Struct for Task queue elements
16 * @ipc_imem: Pointer to struct iosm_imem
17 * @msg: Message argument for tasklet function. (optional, can be NULL)
18 * @completion: OS object used to wait for the tasklet function to finish for
20 * @func: Function to be called in tasklet (tl) context
21 * @arg: Generic integer argument for tasklet function (optional)
22 * @size: Message size argument for tasklet function (optional)
23 * @response: Return code of tasklet function for synchronous calls
24 * @is_copy: Is true if msg contains a pointer to a copy of the original msg
25 * for async. calls that needs to be freed once the tasklet returns
27 struct ipc_task_queue_args {
28 struct iosm_imem *ipc_imem;
30 struct completion *completion;
31 int (*func)(struct iosm_imem *ipc_imem, int arg, void *msg,
40 * struct ipc_task_queue - Struct for Task queue
41 * @q_lock: Protect the message queue of the ipc ipc_task
42 * @args: Message queue of the IPC ipc_task
43 * @q_rpos: First queue element to process.
44 * @q_wpos: First free element of the input queue.
46 struct ipc_task_queue {
47 spinlock_t q_lock; /* for atomic operation on queue */
48 struct ipc_task_queue_args args[IPC_THREAD_QUEUE_SIZE];
54 * struct ipc_task - Struct for Task
55 * @dev: Pointer to device structure
56 * @ipc_tasklet: Tasklet for serialized work offload
57 * from interrupts and OS callbacks
58 * @ipc_queue: Task for entry into ipc task queue
62 struct tasklet_struct *ipc_tasklet;
63 struct ipc_task_queue ipc_queue;
67 * ipc_task_init - Allocate a tasklet
68 * @ipc_task: Pointer to ipc_task structure
69 * Returns: 0 on success and failure value on error.
71 int ipc_task_init(struct ipc_task *ipc_task);
74 * ipc_task_deinit - Free a tasklet, invalidating its pointer.
75 * @ipc_task: Pointer to ipc_task structure
77 void ipc_task_deinit(struct ipc_task *ipc_task);
80 * ipc_task_queue_send_task - Synchronously/Asynchronously call a function in
82 * @imem: Pointer to iosm_imem struct
83 * @func: Function to be called in tasklet context
84 * @arg: Integer argument for func
85 * @msg: Message pointer argument for func
86 * @size: Size argument for func
87 * @wait: if true wait for result
89 * Returns: Result value returned by func or failure value if func could not
92 int ipc_task_queue_send_task(struct iosm_imem *imem,
93 int (*func)(struct iosm_imem *ipc_imem, int arg,
94 void *msg, size_t size),
95 int arg, void *msg, size_t size, bool wait);