iosm_ipc_task_queue.h 3.0 KB

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