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 "system_global.h"
17 
18 #ifdef ISP2401
19 
20 #include "assert_support.h"
21 #include "platform_support.h"
22 #include "ia_css_isys.h"
23 #include "bitop_support.h"
24 #include "isys_dma_rmgr.h"
25 
26 static isys_dma_rsrc_t isys_dma_rsrc[N_ISYS2401_DMA_ID];
27 
ia_css_isys_dma_channel_rmgr_init(void)28 void ia_css_isys_dma_channel_rmgr_init(void)
29 {
30 	memset(&isys_dma_rsrc, 0, sizeof(isys_dma_rsrc_t));
31 }
32 
ia_css_isys_dma_channel_rmgr_uninit(void)33 void ia_css_isys_dma_channel_rmgr_uninit(void)
34 {
35 	memset(&isys_dma_rsrc, 0, sizeof(isys_dma_rsrc_t));
36 }
37 
ia_css_isys_dma_channel_rmgr_acquire(isys2401_dma_ID_t dma_id,isys2401_dma_channel * channel)38 bool ia_css_isys_dma_channel_rmgr_acquire(
39     isys2401_dma_ID_t	dma_id,
40     isys2401_dma_channel	*channel)
41 {
42 	bool retval = false;
43 	isys2401_dma_channel	i;
44 	isys2401_dma_channel	max_dma_channel;
45 	isys_dma_rsrc_t		*cur_rsrc = NULL;
46 
47 	assert(dma_id < N_ISYS2401_DMA_ID);
48 	assert(channel);
49 
50 	max_dma_channel = N_ISYS2401_DMA_CHANNEL_PROCS[dma_id];
51 	cur_rsrc = &isys_dma_rsrc[dma_id];
52 
53 	if (cur_rsrc->num_active < max_dma_channel) {
54 		for (i = ISYS2401_DMA_CHANNEL_0; i < N_ISYS2401_DMA_CHANNEL; i++) {
55 			if (bitop_getbit(cur_rsrc->active_table, i) == 0) {
56 				bitop_setbit(cur_rsrc->active_table, i);
57 				*channel = i;
58 				cur_rsrc->num_active++;
59 				retval = true;
60 				break;
61 			}
62 		}
63 	}
64 
65 	return retval;
66 }
67 
ia_css_isys_dma_channel_rmgr_release(isys2401_dma_ID_t dma_id,isys2401_dma_channel * channel)68 void ia_css_isys_dma_channel_rmgr_release(
69     isys2401_dma_ID_t	dma_id,
70     isys2401_dma_channel	*channel)
71 {
72 	isys2401_dma_channel	max_dma_channel;
73 	isys_dma_rsrc_t		*cur_rsrc = NULL;
74 
75 	assert(dma_id < N_ISYS2401_DMA_ID);
76 	assert(channel);
77 
78 	max_dma_channel = N_ISYS2401_DMA_CHANNEL_PROCS[dma_id];
79 	cur_rsrc = &isys_dma_rsrc[dma_id];
80 
81 	if ((*channel < max_dma_channel) && (cur_rsrc->num_active > 0)) {
82 		if (bitop_getbit(cur_rsrc->active_table, *channel) == 1) {
83 			bitop_clearbit(cur_rsrc->active_table, *channel);
84 			cur_rsrc->num_active--;
85 		}
86 	}
87 }
88 #endif
89