1 // SPDX-License-Identifier: GPL-2.0
2 /*
3  * Support for Intel Camera Imaging ISP subsystem.
4  * Copyright (c) 2010 - 2015, Intel Corporation.
5  */
6 
7 #include "sh_css_sp.h"
8 
9 #include "dma.h"	/* N_DMA_CHANNEL_ID */
10 
11 #include <type_support.h>
12 #include "ia_css_binary.h"
13 #include "sh_css_hrt.h"
14 #include "sh_css_defs.h"
15 #include "sh_css_internal.h"
16 #include "ia_css_debug.h"
17 #include "ia_css_debug_internal.h"
18 #include "sh_css_legacy.h"
19 
20 #include "gdc_device.h"				/* HRT_GDC_N */
21 
22 /*#include "sp.h"*/	/* host2sp_enqueue_frame_data() */
23 
24 #include "assert_support.h"
25 
26 #include "ia_css_queue.h"	/* host_sp_enqueue_XXX */
27 #include "ia_css_event.h"	/* ia_css_event_encode */
28 /*
29  * @brief Encode the information into the software-event.
30  * Refer to "sw_event_public.h" for details.
31  */
ia_css_event_encode(u8 * in,u8 nr,uint32_t * out)32 bool ia_css_event_encode(
33     u8	*in,
34     u8	nr,
35     uint32_t	*out)
36 {
37 	bool ret;
38 	u32 nr_of_bits;
39 	u32 i;
40 
41 	assert(in);
42 	assert(out);
43 	OP___assert(nr > 0 && nr <= MAX_NR_OF_PAYLOADS_PER_SW_EVENT);
44 
45 	/* initialize the output */
46 	*out = 0;
47 
48 	/* get the number of bits per information */
49 	nr_of_bits = sizeof(uint32_t) * 8 / nr;
50 
51 	/* compress the all inputs into a signle output */
52 	for (i = 0; i < nr; i++) {
53 		*out <<= nr_of_bits;
54 		*out |= in[i];
55 	}
56 
57 	/* get the return value */
58 	ret = (nr > 0 && nr <= MAX_NR_OF_PAYLOADS_PER_SW_EVENT);
59 
60 	return ret;
61 }
62 
ia_css_event_decode(u32 event,uint8_t * payload)63 void ia_css_event_decode(
64     u32 event,
65     uint8_t *payload)
66 {
67 	assert(payload[1] == 0);
68 	assert(payload[2] == 0);
69 	assert(payload[3] == 0);
70 
71 	ia_css_debug_dtrace(IA_CSS_DEBUG_TRACE_PRIVATE,
72 			    "ia_css_event_decode() enter:\n");
73 
74 	/* First decode according to the common case
75 	 * In case of a PORT_EOF event we overwrite with
76 	 * the specific values
77 	 * This is somewhat ugly but probably somewhat efficient
78 	 * (and it avoids some code duplication)
79 	 */
80 	payload[0] = event & 0xff;  /*event_code */
81 	payload[1] = (event >> 8) & 0xff;
82 	payload[2] = (event >> 16) & 0xff;
83 	payload[3] = 0;
84 
85 	switch (payload[0]) {
86 	case SH_CSS_SP_EVENT_PORT_EOF:
87 		payload[2] = 0;
88 		payload[3] = (event >> 24) & 0xff;
89 		break;
90 
91 	case SH_CSS_SP_EVENT_ACC_STAGE_COMPLETE:
92 	case SH_CSS_SP_EVENT_TIMER:
93 	case SH_CSS_SP_EVENT_FRAME_TAGGED:
94 	case SH_CSS_SP_EVENT_FW_WARNING:
95 	case SH_CSS_SP_EVENT_FW_ASSERT:
96 		payload[3] = (event >> 24) & 0xff;
97 		break;
98 	default:
99 		break;
100 	}
101 }
102