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