1 /*
2 * g2d_rcq/g2d_rcq.c
3 *
4 * Copyright (c) 2007-2019 Allwinnertech Co., Ltd.
5 * Author: zhengxiaobin <zhengxiaobin@allwinnertech.com>
6 *
7 * This software is licensed under the terms of the GNU General Public
8 * License version 2, as published by the Free Software Foundation, and
9 * may be copied, distributed, and modified under those terms.
10 *
11 * This program is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 */
17
18 #include "g2d_rcq.h"
19 #include "g2d_driver_i.h"
20
g2d_top_mem_pool_alloc(struct g2d_rcq_mem_info * p_rcq_info)21 __s32 g2d_top_mem_pool_alloc(struct g2d_rcq_mem_info *p_rcq_info)
22 {
23 int ret = 0;
24
25 p_rcq_info->rcq_byte_used =
26 p_rcq_info->alloc_num * sizeof(*(p_rcq_info->vir_addr));
27 p_rcq_info->vir_addr = g2d_malloc(p_rcq_info->rcq_reg_mem_size,
28 (__u32 *)&p_rcq_info->phy_addr);
29 if (!p_rcq_info->vir_addr)
30 ret = -1;
31
32 return ret;
33 }
34
g2d_top_reg_memory_alloc(__u32 size,void * phy_addr,struct g2d_rcq_mem_info * p_rcq_info)35 void *g2d_top_reg_memory_alloc(__u32 size, void *phy_addr,
36 struct g2d_rcq_mem_info *p_rcq_info)
37 {
38 void *viraddr = NULL;
39 if (p_rcq_info->vir_addr) {
40
41 *(dma_addr_t *)phy_addr = (dma_addr_t)p_rcq_info->phy_addr +
42 p_rcq_info->rcq_byte_used;
43
44 viraddr =
45 (void *)p_rcq_info->vir_addr + p_rcq_info->rcq_byte_used;
46
47 p_rcq_info->rcq_byte_used += G2D_RCQ_BYTE_ALIGN(size);
48
49 if (p_rcq_info->rcq_byte_used > p_rcq_info->rcq_reg_mem_size) {
50 G2D_ERR_MSG("Malloc %d byte fail, out of total "
51 "memory %d bytes, current used byte:%d\n",
52 G2D_RCQ_BYTE_ALIGN(size),
53 p_rcq_info->rcq_reg_mem_size,
54 p_rcq_info->rcq_byte_used);
55 viraddr = NULL;
56 *(dma_addr_t *)phy_addr = (dma_addr_t)NULL;
57 }
58 return viraddr;
59 } else {
60 G2D_ERR_MSG("Null pointer!\n");
61 *(dma_addr_t *)phy_addr = (dma_addr_t)NULL;
62 return NULL;
63 }
64 }
65
g2d_top_mem_pool_free(struct g2d_rcq_mem_info * p_rcq_info)66 void g2d_top_mem_pool_free(struct g2d_rcq_mem_info *p_rcq_info)
67 {
68 if (p_rcq_info->vir_addr) {
69 g2d_free((void *)p_rcq_info->vir_addr,
70 (void *)p_rcq_info->phy_addr,
71 p_rcq_info->rcq_reg_mem_size);
72 }
73 }
74