bcm27xx: add support for linux v5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.15 / 950-0474-staging-vchiq_arm-Usa-a-DMA-pool-for-small-bulks.patch
1 From 3092242447d1132bf1e0d13efbc133c50224b1a7 Mon Sep 17 00:00:00 2001
2 From: detule <ogjoneski@gmail.com>
3 Date: Tue, 2 Oct 2018 04:10:08 -0400
4 Subject: [PATCH] staging: vchiq_arm: Usa a DMA pool for small bulks
5
6 During a bulk transfer we request a DMA allocation to hold the
7 scatter-gather list. Most of the time, this allocation is small
8 (<< PAGE_SIZE), however it can be requested at a high enough frequency
9 to cause fragmentation and/or stress the CMA allocator (think time
10 spent in compaction here, or during allocations elsewhere).
11
12 Implement a pool to serve up small DMA allocations, falling back
13 to a coherent allocation if the request is greater than
14 VCHIQ_DMA_POOL_SIZE.
15
16 Signed-off-by: Oliver Gjoneski <ogjoneski@gmail.com>
17 ---
18 .../interface/vchiq_arm/vchiq_arm.c | 36 ++++++++++++++++---
19 1 file changed, 32 insertions(+), 4 deletions(-)
20
21 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
22 +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
23 @@ -22,6 +22,7 @@
24 #include <linux/platform_device.h>
25 #include <linux/compat.h>
26 #include <linux/dma-mapping.h>
27 +#include <linux/dmapool.h>
28 #include <linux/rcupdate.h>
29 #include <linux/delay.h>
30 #include <linux/slab.h>
31 @@ -51,6 +52,8 @@
32
33 #define ARM_DS_ACTIVE BIT(2)
34
35 +#define VCHIQ_DMA_POOL_SIZE PAGE_SIZE
36 +
37 /* Override the default prefix, which would be vchiq_arm (from the filename) */
38 #undef MODULE_PARAM_PREFIX
39 #define MODULE_PARAM_PREFIX DEVICE_NAME "."
40 @@ -93,6 +96,7 @@ struct vchiq_pagelist_info {
41 struct pagelist *pagelist;
42 size_t pagelist_buffer_size;
43 dma_addr_t dma_addr;
44 + bool is_from_pool;
45 enum dma_data_direction dma_dir;
46 unsigned int num_pages;
47 unsigned int pages_need_release;
48 @@ -113,6 +117,7 @@ static void __iomem *g_regs;
49 * of 32.
50 */
51 static unsigned int g_cache_line_size = 32;
52 +static struct dma_pool *g_dma_pool;
53 static unsigned int g_use_36bit_addrs = 0;
54 static unsigned int g_fragments_size;
55 static char *g_fragments_base;
56 @@ -156,8 +161,14 @@ cleanup_pagelistinfo(struct vchiq_pageli
57 if (pagelistinfo->pages_need_release)
58 unpin_user_pages(pagelistinfo->pages, pagelistinfo->num_pages);
59
60 - dma_free_coherent(g_dev, pagelistinfo->pagelist_buffer_size,
61 - pagelistinfo->pagelist, pagelistinfo->dma_addr);
62 + if (pagelistinfo->is_from_pool) {
63 + dma_pool_free(g_dma_pool, pagelistinfo->pagelist,
64 + pagelistinfo->dma_addr);
65 + } else {
66 + dma_free_coherent(g_dev, pagelistinfo->pagelist_buffer_size,
67 + pagelistinfo->pagelist,
68 + pagelistinfo->dma_addr);
69 + }
70 }
71
72 /* There is a potential problem with partial cache lines (pages?)
73 @@ -178,6 +189,7 @@ create_pagelist(char *buf, char __user *
74 u32 *addrs;
75 unsigned int num_pages, offset, i, k;
76 int actual_pages;
77 + bool is_from_pool;
78 size_t pagelist_size;
79 struct scatterlist *scatterlist, *sg;
80 int dma_buffers;
81 @@ -207,8 +219,16 @@ create_pagelist(char *buf, char __user *
82 /* Allocate enough storage to hold the page pointers and the page
83 * list
84 */
85 - pagelist = dma_alloc_coherent(g_dev, pagelist_size, &dma_addr,
86 - GFP_KERNEL);
87 + if (pagelist_size > VCHIQ_DMA_POOL_SIZE) {
88 + pagelist = dma_alloc_coherent(g_dev,
89 + pagelist_size,
90 + &dma_addr,
91 + GFP_KERNEL);
92 + is_from_pool = false;
93 + } else {
94 + pagelist = dma_pool_alloc(g_dma_pool, GFP_KERNEL, &dma_addr);
95 + is_from_pool = true;
96 + }
97
98 vchiq_log_trace(vchiq_arm_log_level, "%s - %pK", __func__, pagelist);
99
100 @@ -229,6 +249,7 @@ create_pagelist(char *buf, char __user *
101 pagelistinfo->pagelist = pagelist;
102 pagelistinfo->pagelist_buffer_size = pagelist_size;
103 pagelistinfo->dma_addr = dma_addr;
104 + pagelistinfo->is_from_pool = is_from_pool;
105 pagelistinfo->dma_dir = (type == PAGELIST_WRITE) ?
106 DMA_TO_DEVICE : DMA_FROM_DEVICE;
107 pagelistinfo->num_pages = num_pages;
108 @@ -569,6 +590,13 @@ int vchiq_platform_init(struct platform_
109
110 g_dev = dev;
111 g_dma_dev = dma_dev ?: dev;
112 + g_dma_pool = dmam_pool_create("vchiq_scatter_pool", dev,
113 + VCHIQ_DMA_POOL_SIZE, g_cache_line_size,
114 + 0);
115 + if (!g_dma_pool) {
116 + dev_err(dev, "failed to create dma pool");
117 + return -ENOMEM;
118 + }
119
120 vchiq_log_info(vchiq_arm_log_level,
121 "vchiq_init - done (slots %pK, phys %pad)",