GNU Linux-libre 4.14.262-gnu1
[releases.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / runtime / isys / src / isys_dma_rmgr.c
1 #ifndef ISP2401
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 #else
16 /**
17 Support for Intel Camera Imaging ISP subsystem.
18 Copyright (c) 2010 - 2015, Intel Corporation.
19
20 This program is free software; you can redistribute it and/or modify it
21 under the terms and conditions of the GNU General Public License,
22 version 2, as published by the Free Software Foundation.
23
24 This program is distributed in the hope it will be useful, but WITHOUT
25 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
26 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License for
27 more details.
28 */
29 #endif
30
31 #include "system_global.h"
32
33 #ifdef USE_INPUT_SYSTEM_VERSION_2401
34
35 #include "assert_support.h"
36 #include "platform_support.h"
37 #include "ia_css_isys.h"
38 #include "bitop_support.h"
39 #include "isys_dma_rmgr.h"
40
41 static isys_dma_rsrc_t isys_dma_rsrc[N_ISYS2401_DMA_ID];
42
43 void ia_css_isys_dma_channel_rmgr_init(void)
44 {
45         memset(&isys_dma_rsrc, 0, sizeof(isys_dma_rsrc_t));
46 }
47
48 void ia_css_isys_dma_channel_rmgr_uninit(void)
49 {
50         memset(&isys_dma_rsrc, 0, sizeof(isys_dma_rsrc_t));
51 }
52
53 bool ia_css_isys_dma_channel_rmgr_acquire(
54         isys2401_dma_ID_t       dma_id,
55         isys2401_dma_channel    *channel)
56 {
57         bool retval = false;
58         isys2401_dma_channel    i;
59         isys2401_dma_channel    max_dma_channel;
60         isys_dma_rsrc_t         *cur_rsrc = NULL;
61
62         assert(dma_id < N_ISYS2401_DMA_ID);
63         assert(channel != NULL);
64
65         max_dma_channel = N_ISYS2401_DMA_CHANNEL_PROCS[dma_id];
66         cur_rsrc = &isys_dma_rsrc[dma_id];
67
68         if (cur_rsrc->num_active < max_dma_channel) {
69                 for (i = ISYS2401_DMA_CHANNEL_0; i < N_ISYS2401_DMA_CHANNEL; i++) {
70                         if (bitop_getbit(cur_rsrc->active_table, i) == 0) {
71                                 bitop_setbit(cur_rsrc->active_table, i);
72                                 *channel = i;
73                                 cur_rsrc->num_active++;
74                                 retval = true;
75                                 break;
76                         }
77                 }
78         }
79
80         return retval;
81 }
82
83 void ia_css_isys_dma_channel_rmgr_release(
84         isys2401_dma_ID_t       dma_id,
85         isys2401_dma_channel    *channel)
86 {
87         isys2401_dma_channel    max_dma_channel;
88         isys_dma_rsrc_t         *cur_rsrc = NULL;
89
90         assert(dma_id < N_ISYS2401_DMA_ID);
91         assert(channel != NULL);
92
93         max_dma_channel = N_ISYS2401_DMA_CHANNEL_PROCS[dma_id];
94         cur_rsrc = &isys_dma_rsrc[dma_id];
95
96         if ((*channel < max_dma_channel) && (cur_rsrc->num_active > 0)) {
97                 if (bitop_getbit(cur_rsrc->active_table, *channel) == 1) {
98                         bitop_clearbit(cur_rsrc->active_table, *channel);
99                         cur_rsrc->num_active--;
100                 }
101         }
102 }
103 #endif