1 // SPDX-License-Identifier: GPL-2.0
2 /*
3 * Support for Intel Camera Imaging ISP subsystem.
4 * Copyright (c) 2015, Intel Corporation.
5 *
6 * This program is free software; you can redistribute it and/or modify it
7 * under the terms and conditions of the GNU General Public License,
8 * version 2, as published by the Free Software Foundation.
9 *
10 * This program is distributed in the hope it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 */
15
16 #include "ia_css_types.h"
17 #include "assert_support.h"
18 #include "ia_css_queue.h" /* sp2host_dequeue_irq_event() */
19 #include "ia_css_eventq.h"
20 #include "ia_css_event.h" /* ia_css_event_encode()
21 ia_css_event_decode()
22 */
ia_css_eventq_recv(ia_css_queue_t * eventq_handle,uint8_t * payload)23 int ia_css_eventq_recv(
24 ia_css_queue_t *eventq_handle,
25 uint8_t *payload)
26 {
27 u32 sp_event;
28 int error;
29
30 /* dequeue the IRQ event */
31 error = ia_css_queue_dequeue(eventq_handle, &sp_event);
32
33 /* check whether the IRQ event is available or not */
34 if (!error)
35 ia_css_event_decode(sp_event, payload);
36 return error;
37 }
38
39 /*
40 * @brief The Host sends the event to the SP.
41 * Refer to "sh_css_sp.h" for details.
42 */
ia_css_eventq_send(ia_css_queue_t * eventq_handle,u8 evt_id,u8 evt_payload_0,u8 evt_payload_1,uint8_t evt_payload_2)43 int ia_css_eventq_send(
44 ia_css_queue_t *eventq_handle,
45 u8 evt_id,
46 u8 evt_payload_0,
47 u8 evt_payload_1,
48 uint8_t evt_payload_2)
49 {
50 u8 tmp[4];
51 u32 sw_event;
52 int error = -ENOSYS;
53
54 /*
55 * Encode the queue type, the thread ID and
56 * the queue ID into the event.
57 */
58 tmp[0] = evt_id;
59 tmp[1] = evt_payload_0;
60 tmp[2] = evt_payload_1;
61 tmp[3] = evt_payload_2;
62 ia_css_event_encode(tmp, 4, &sw_event);
63
64 /* queue the software event (busy-waiting) */
65 for ( ; ; ) {
66 error = ia_css_queue_enqueue(eventq_handle, sw_event);
67 if (error != -ENOBUFS) {
68 /* We were able to successfully send the event
69 or had a real failure. return the status*/
70 break;
71 }
72 /* Wait for the queue to be not full and try again*/
73 udelay(1);
74 }
75 return error;
76 }
77