hc
2024-08-16 a24a44ff9ca902811b99aa9663d697cf452e08ef
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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
// SPDX-License-Identifier: GPL-2.0
/*
 * Early setup for Rockchip DMA CMA
 *
 * Copyright (C) 2022 Rockchip Electronics Co. Ltd.
 * Author: Simon Xue <xxm@rock-chips.com>
 */
 
#include <linux/cma.h>
#include <linux/dma-map-ops.h>
 
#include "rk-dma-heap.h"
 
#define RK_DMA_HEAP_CMA_DEFAULT_SIZE SZ_32M
 
static unsigned long rk_dma_heap_size __initdata;
static unsigned long rk_dma_heap_base __initdata;
 
static struct cma *rk_dma_heap_cma;
 
static int __init early_dma_heap_cma(char *p)
{
   if (!p) {
       pr_err("Config string not provided\n");
       return -EINVAL;
   }
 
   rk_dma_heap_size = memparse(p, &p);
   if (*p != '@')
       return 0;
 
   rk_dma_heap_base = memparse(p + 1, &p);
 
   return 0;
}
early_param("rk_dma_heap_cma", early_dma_heap_cma);
 
#ifndef CONFIG_DMA_CMA
void __weak
dma_contiguous_early_fixup(phys_addr_t base, unsigned long size)
{
}
#endif
 
int __init rk_dma_heap_cma_setup(void)
{
   unsigned long size;
   int ret;
   bool fix = false;
 
   if (rk_dma_heap_size)
       size = rk_dma_heap_size;
   else
       size = RK_DMA_HEAP_CMA_DEFAULT_SIZE;
 
   if (rk_dma_heap_base)
       fix = true;
 
   ret = cma_declare_contiguous(rk_dma_heap_base, PAGE_ALIGN(size), 0x0,
                    PAGE_SIZE, 0, fix, "rk-dma-heap-cma",
                    &rk_dma_heap_cma);
   if (ret)
       return ret;
 
#if !IS_ENABLED(CONFIG_CMA_INACTIVE)
   /* Architecture specific contiguous memory fixup. */
   dma_contiguous_early_fixup(cma_get_base(rk_dma_heap_cma),
   cma_get_size(rk_dma_heap_cma));
#endif
 
   return 0;
}
 
struct cma *rk_dma_heap_get_cma(void)
{
   return rk_dma_heap_cma;
}