lin
2025-04-14 e0c033f30287744d392a8d700693b1c0b78afc7c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
/*
 * Allwinner SoCs grallocator.
 *
 * Copyright (C) 2017 Allwinner.
 *
 * This file is licensed under the terms of the GNU General Public
 * License version 2.  This program is licensed "as is" without any
 * warranty of any kind, whether express or implied.
 */
 
#include <common.h>
#include <malloc.h>
#include <grallocator.h>
 
 
int graphic_buffer_alloc(unsigned int w, unsigned h, unsigned int bpp,
   int usage, void **handle, unsigned int *stride)
{
   unsigned int size;
   void *addr = NULL;
 
   if (!w || !h)
       w = h = 1;
 
   *stride = DO_ALIGN(w * bpp >> 3, GR_ALIGN_BYTE);
   size = *stride * h;
 
   if (GRALLOC_USAGE_HW_FB & usage) {
       /* only for FB_ID_0 */
#if !defined(HW_FB_ADDR)
       DECLARE_GLOBAL_DATA_PTR;
       printf("size=0x%x, ram_size=0x%lx, FRAME_BUFFER_SIZE=0x%x\n",
           size, gd->ram_size, SUNXI_DISPLAY_FRAME_BUFFER_SIZE);
       if ((size < gd->ram_size)
           && (size <= SUNXI_DISPLAY_FRAME_BUFFER_SIZE))
           addr = (void *)(CONFIG_SYS_SDRAM_BASE + gd->ram_size
               - SUNXI_DISPLAY_FRAME_BUFFER_SIZE);
#else
       printf("HW_FB_ADDR=0x%x\n", HW_FB_ADDR);
       addr = (void *)HW_FB_ADDR;
#endif
 
   } else {
       addr = (void *)memalign(CONFIG_SYS_CACHELINE_SIZE, size);
   }
 
 
   if (NULL != addr) {
       *handle = addr;
       return 0;
   } else {
       printf("%s: failed\n", __func__);
       return -1;
   }
}
 
int graphic_buffer_free(void *handle, int usage)
{
   if (!(GRALLOC_USAGE_HW_FB & usage)) {
       free(handle);
   }
   return 0;
}