aboutsummaryrefslogtreecommitdiffstats
path: root/drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/eventq/src/eventq.c
blob: 913a4bf7a34fc24522f762b2e52530b569e3a917 (plain) (blame)
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
/*
 * Support for Intel Camera Imaging ISP subsystem.
 * Copyright (c) 2015, Intel Corporation.
 *
 * This program is free software; you can redistribute it and/or modify it
 * under the terms and conditions of the GNU General Public License,
 * version 2, as published by the Free Software Foundation.
 *
 * This program is distributed in the hope it will be useful, but WITHOUT
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
 * more details.
 */

#include "ia_css_types.h"
#include "assert_support.h"
#include "ia_css_queue.h" /* sp2host_dequeue_irq_event() */
#include "ia_css_eventq.h"
#include "ia_css_event.h"	/* ia_css_event_encode()
				ia_css_event_decode()
				*/
#include "platform_support.h" /* hrt_sleep() */

int ia_css_eventq_recv(
		ia_css_queue_t *eventq_handle,
		uint8_t *payload)
{
	uint32_t sp_event;
	int error;

	/* dequeue the IRQ event */
	error = ia_css_queue_dequeue(eventq_handle, &sp_event);

	/* check whether the IRQ event is available or not */
	if (!error)
		ia_css_event_decode(sp_event, payload);
	return error;
}

/*
 * @brief The Host sends the event to the SP.
 * Refer to "sh_css_sp.h" for details.
 */
int ia_css_eventq_send(
			ia_css_queue_t *eventq_handle,
			uint8_t evt_id,
			uint8_t evt_payload_0,
			uint8_t evt_payload_1,
			uint8_t evt_payload_2)
{
	uint8_t tmp[4];
	uint32_t sw_event;
	int error = ENOSYS;

	/*
	 * Encode the queue type, the thread ID and
	 * the queue ID into the event.
	 */
	tmp[0] = evt_id;
	tmp[1] = evt_payload_0;
	tmp[2] = evt_payload_1;
	tmp[3] = evt_payload_2;
	ia_css_event_encode(tmp, 4, &sw_event);

	/* queue the software event (busy-waiting) */
	for ( ; ; ) {
		error = ia_css_queue_enqueue(eventq_handle, sw_event);
		if (ENOBUFS != error) {
			/* We were able to successfully send the event
			   or had a real failure. return the status*/
			break;
		}
		/* Wait for the queue to be not full and try again*/
		hrt_sleep();
	}
	return error;
}