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