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 */ 23 #include "platform_support.h" /* hrt_sleep() */ 24 25 int ia_css_eventq_recv( 26 ia_css_queue_t *eventq_handle, 27 uint8_t *payload) 28 { 29 u32 sp_event; 30 int error; 31 32 /* dequeue the IRQ event */ 33 error = ia_css_queue_dequeue(eventq_handle, &sp_event); 34 35 /* check whether the IRQ event is available or not */ 36 if (!error) 37 ia_css_event_decode(sp_event, payload); 38 return error; 39 } 40 41 /* 42 * @brief The Host sends the event to the SP. 43 * Refer to "sh_css_sp.h" for details. 44 */ 45 int ia_css_eventq_send( 46 ia_css_queue_t *eventq_handle, 47 u8 evt_id, 48 u8 evt_payload_0, 49 u8 evt_payload_1, 50 uint8_t evt_payload_2) 51 { 52 u8 tmp[4]; 53 u32 sw_event; 54 int error = -ENOSYS; 55 56 /* 57 * Encode the queue type, the thread ID and 58 * the queue ID into the event. 59 */ 60 tmp[0] = evt_id; 61 tmp[1] = evt_payload_0; 62 tmp[2] = evt_payload_1; 63 tmp[3] = evt_payload_2; 64 ia_css_event_encode(tmp, 4, &sw_event); 65 66 /* queue the software event (busy-waiting) */ 67 for ( ; ; ) { 68 error = ia_css_queue_enqueue(eventq_handle, sw_event); 69 if (error != -ENOBUFS) { 70 /* We were able to successfully send the event 71 or had a real failure. return the status*/ 72 break; 73 } 74 /* Wait for the queue to be not full and try again*/ 75 hrt_sleep(); 76 } 77 return error; 78 } 79