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