]>
git.proxmox.com Git - mirror_ubuntu-hirsute-kernel.git/blob - drivers/staging/media/atomisp/pci/atomisp2/css2400/runtime/isys/src/ibuf_ctrl_rmgr.c
3 * Support for Intel Camera Imaging ISP subsystem.
4 * Copyright (c) 2015, Intel Corporation.
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.
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
17 * Support for Intel Camera Imaging ISP subsystem.
18 * Copyright (c) 2010 - 2015, Intel Corporation.
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.
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
31 #include "system_global.h"
33 #ifdef USE_INPUT_SYSTEM_VERSION_2401
35 #include "assert_support.h"
36 #include "platform_support.h"
37 #include "ia_css_isys.h"
38 #include "ibuf_ctrl_rmgr.h"
40 static ibuf_rsrc_t ibuf_rsrc
;
42 static ibuf_handle_t
*getHandle(uint16_t index
)
44 ibuf_handle_t
*handle
= NULL
;
46 if (index
< MAX_IBUF_HANDLES
)
47 handle
= &ibuf_rsrc
.handles
[index
];
51 void ia_css_isys_ibuf_rmgr_init(void)
53 memset(&ibuf_rsrc
, 0, sizeof(ibuf_rsrc
));
54 ibuf_rsrc
.free_size
= MAX_INPUT_BUFFER_SIZE
;
57 void ia_css_isys_ibuf_rmgr_uninit(void)
59 memset(&ibuf_rsrc
, 0, sizeof(ibuf_rsrc
));
60 ibuf_rsrc
.free_size
= MAX_INPUT_BUFFER_SIZE
;
63 bool ia_css_isys_ibuf_rmgr_acquire(
68 bool input_buffer_found
= false;
69 uint32_t aligned_size
;
70 ibuf_handle_t
*handle
= NULL
;
73 assert(start_addr
!= NULL
);
76 aligned_size
= (size
+ (IBUF_ALIGN
- 1)) & ~(IBUF_ALIGN
- 1);
78 /* Check if there is an available un-used handle with the size
79 * that will fulfill the request.
81 if (ibuf_rsrc
.num_active
< ibuf_rsrc
.num_allocated
) {
82 for (i
= 0; i
< ibuf_rsrc
.num_allocated
; i
++) {
83 handle
= getHandle(i
);
84 if (!handle
->active
) {
85 if (handle
->size
>= aligned_size
) {
86 handle
->active
= true;
87 input_buffer_found
= true;
88 ibuf_rsrc
.num_active
++;
95 if (!input_buffer_found
) {
96 /* There were no available handles that fulfilled the
97 * request. Allocate a new handle with the requested size.
99 if ((ibuf_rsrc
.num_allocated
< MAX_IBUF_HANDLES
) &&
100 (ibuf_rsrc
.free_size
>= aligned_size
)) {
101 handle
= getHandle(ibuf_rsrc
.num_allocated
);
102 handle
->start_addr
= ibuf_rsrc
.free_start_addr
;
103 handle
->size
= aligned_size
;
104 handle
->active
= true;
106 ibuf_rsrc
.free_start_addr
+= aligned_size
;
107 ibuf_rsrc
.free_size
-= aligned_size
;
108 ibuf_rsrc
.num_active
++;
109 ibuf_rsrc
.num_allocated
++;
111 input_buffer_found
= true;
115 if (input_buffer_found
&& handle
) {
116 *start_addr
= handle
->start_addr
;
123 void ia_css_isys_ibuf_rmgr_release(
124 uint32_t *start_addr
)
127 ibuf_handle_t
*handle
= NULL
;
129 assert(start_addr
!= NULL
);
131 for (i
= 0; i
< ibuf_rsrc
.num_allocated
; i
++) {
132 handle
= getHandle(i
);
133 if (handle
->active
&& handle
->start_addr
== *start_addr
) {
134 handle
->active
= false;
135 ibuf_rsrc
.num_active
--;