]> git.proxmox.com Git - mirror_ubuntu-jammy-kernel.git/blob - drivers/staging/media/atomisp/pci/atomisp2/css2400/memory_realloc.c
staging/atomisp: Add support for the Intel IPU v2
[mirror_ubuntu-jammy-kernel.git] / drivers / staging / media / atomisp / pci / atomisp2 / css2400 / memory_realloc.c
1 /**
2 Support for Intel Camera Imaging ISP subsystem.
3 Copyright (c) 2010 - 2015, Intel Corporation.
4
5 This program is free software; you can redistribute it and/or modify it
6 under the terms and conditions of the GNU General Public License,
7 version 2, as published by the Free Software Foundation.
8
9 This program is distributed in the hope it will be useful, but WITHOUT
10 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
11 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
12 more details.
13 */
14 #include "memory_realloc.h"
15 #include "ia_css_debug.h"
16 #include "ia_css_refcount.h"
17 #include "memory_access.h"
18
19 static bool realloc_isp_css_mm_buf(
20 hrt_vaddress *curr_buf,
21 size_t *curr_size,
22 size_t needed_size,
23 bool force,
24 enum ia_css_err *err,
25 uint16_t mmgr_attribute);
26
27
28 bool reallocate_buffer(
29 hrt_vaddress *curr_buf,
30 size_t *curr_size,
31 size_t needed_size,
32 bool force,
33 enum ia_css_err *err)
34 {
35 bool ret;
36 uint16_t mmgr_attribute = MMGR_ATTRIBUTE_DEFAULT;
37
38 IA_CSS_ENTER_PRIVATE("void");
39
40 ret = realloc_isp_css_mm_buf(curr_buf,
41 curr_size, needed_size, force, err, mmgr_attribute);
42
43 IA_CSS_LEAVE_PRIVATE("ret=%d", ret);
44 return ret;
45 }
46
47 static bool realloc_isp_css_mm_buf(
48 hrt_vaddress *curr_buf,
49 size_t *curr_size,
50 size_t needed_size,
51 bool force,
52 enum ia_css_err *err,
53 uint16_t mmgr_attribute)
54 {
55 int32_t id;
56
57 *err = IA_CSS_SUCCESS;
58 /* Possible optimization: add a function sh_css_isp_css_mm_realloc()
59 * and implement on top of hmm. */
60
61 IA_CSS_ENTER_PRIVATE("void");
62
63 if (ia_css_refcount_is_single(*curr_buf) && !force && *curr_size >= needed_size) {
64 IA_CSS_LEAVE_PRIVATE("false");
65 return false;
66 }
67
68 id = IA_CSS_REFCOUNT_PARAM_BUFFER;
69 ia_css_refcount_decrement(id, *curr_buf);
70 *curr_buf = ia_css_refcount_increment(id, mmgr_alloc_attr(needed_size,
71 mmgr_attribute));
72
73 if (!*curr_buf) {
74 *err = IA_CSS_ERR_CANNOT_ALLOCATE_MEMORY;
75 *curr_size = 0;
76 } else {
77 *curr_size = needed_size;
78 }
79 IA_CSS_LEAVE_PRIVATE("true");
80 return true;
81 }