1 /*
2 *
3 * SPDX-License-Identifier: GPL-2.0
4 *
5 * Copyright (C) 2011-2018 ARM or its affiliates
6 *
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2.
10 * This program is distributed in the hope that it will be useful, but
11 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
12 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
13 * for more details.
14 * You should have received a copy of the GNU General Public License along
15 * with this program; if not, write to the Free Software Foundation, Inc.,
16 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
17 *
18 */
19
20 #include "acamera_types.h"
21 #include "system_semaphore.h"
22 #include <linux/semaphore.h>
23 #include <linux/slab.h>
24
25
system_semaphore_init(semaphore_t * sem)26 int32_t system_semaphore_init( semaphore_t *sem )
27 {
28 struct semaphore *sys_sem = kmalloc( sizeof( struct semaphore ), GFP_KERNEL | __GFP_NOFAIL );
29 *sem = sys_sem;
30 sema_init( sys_sem, 1 );
31 return 0;
32 }
33
34
system_semaphore_raise(semaphore_t sem)35 int32_t system_semaphore_raise( semaphore_t sem )
36 {
37 struct semaphore *sys_sem = (struct semaphore *)sem;
38 up( sys_sem );
39 return 0;
40 }
41
system_semaphore_wait(semaphore_t sem,uint32_t timeout_ms)42 int32_t system_semaphore_wait( semaphore_t sem, uint32_t timeout_ms )
43 {
44 struct semaphore *sys_sem = (struct semaphore *)sem;
45
46 if ( timeout_ms ) {
47 return down_timeout( sys_sem, msecs_to_jiffies( timeout_ms ) );
48 } else {
49 return down_interruptible( sys_sem );
50 }
51 }
52
system_semaphore_destroy(semaphore_t sem)53 int32_t system_semaphore_destroy( semaphore_t sem )
54 {
55 struct semaphore *sys_sem = (struct semaphore *)sem;
56 kfree( sys_sem );
57 return 0;
58 }
59