bcm27xx: switch to 5.15
[openwrt/staging/chunkeey.git] / target / linux / bcm27xx / patches-5.10 / 950-0308-vchiq_2835_arm-Implement-a-DMA-pool-for-small-bulk-t.patch
1 From afbc6c9f890bd3d877451138b2ffd5bd19bfdf61 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] vchiq_2835_arm: Implement a DMA pool for small bulk
5 transfers (#2699)
6
7 During a bulk transfer we request a DMA allocation to hold the
8 scatter-gather list. Most of the time, this allocation is small
9 (<< PAGE_SIZE), however it can be requested at a high enough frequency
10 to cause fragmentation and/or stress the CMA allocator (think time
11 spent in compaction here, or during allocations elsewhere).
12
13 Implement a pool to serve up small DMA allocations, falling back
14 to a coherent allocation if the request is greater than
15 VCHIQ_DMA_POOL_SIZE.
16
17 Signed-off-by: Oliver Gjoneski <ogjoneski@gmail.com>
18 ---
19 .../interface/vchiq_arm/vchiq_2835_arm.c | 36 ++++++++++++++++---
20 1 file changed, 32 insertions(+), 4 deletions(-)
21
22 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
23 +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
24 @@ -7,6 +7,7 @@
25 #include <linux/interrupt.h>
26 #include <linux/pagemap.h>
27 #include <linux/dma-mapping.h>
28 +#include <linux/dmapool.h>
29 #include <linux/io.h>
30 #include <linux/platform_device.h>
31 #include <linux/uaccess.h>
32 @@ -29,6 +30,8 @@
33 #define BELL0 0x00
34 #define BELL2 0x08
35
36 +#define VCHIQ_DMA_POOL_SIZE PAGE_SIZE
37 +
38 struct vchiq_2835_state {
39 int inited;
40 struct vchiq_arm_state arm_state;
41 @@ -38,6 +41,7 @@ struct vchiq_pagelist_info {
42 struct pagelist *pagelist;
43 size_t pagelist_buffer_size;
44 dma_addr_t dma_addr;
45 + bool is_from_pool;
46 enum dma_data_direction dma_dir;
47 unsigned int num_pages;
48 unsigned int pages_need_release;
49 @@ -58,6 +62,7 @@ static void __iomem *g_regs;
50 * of 32.
51 */
52 static unsigned int g_cache_line_size = 32;
53 +static struct dma_pool *g_dma_pool;
54 static unsigned int g_use_36bit_addrs = 0;
55 static unsigned int g_fragments_size;
56 static char *g_fragments_base;
57 @@ -182,6 +187,13 @@ int vchiq_platform_init(struct platform_
58
59 g_dev = dev;
60 g_dma_dev = dma_dev ?: dev;
61 + g_dma_pool = dmam_pool_create("vchiq_scatter_pool", dev,
62 + VCHIQ_DMA_POOL_SIZE, g_cache_line_size,
63 + 0);
64 + if (!g_dma_pool) {
65 + dev_err(dev, "failed to create dma pool");
66 + return -ENOMEM;
67 + }
68
69 vchiq_log_info(vchiq_arm_log_level,
70 "vchiq_init - done (slots %pK, phys %pad)",
71 @@ -314,8 +326,14 @@ cleanup_pagelistinfo(struct vchiq_pageli
72 if (pagelistinfo->pages_need_release)
73 unpin_user_pages(pagelistinfo->pages, pagelistinfo->num_pages);
74
75 - dma_free_coherent(g_dev, pagelistinfo->pagelist_buffer_size,
76 - pagelistinfo->pagelist, pagelistinfo->dma_addr);
77 + if (pagelistinfo->is_from_pool) {
78 + dma_pool_free(g_dma_pool, pagelistinfo->pagelist,
79 + pagelistinfo->dma_addr);
80 + } else {
81 + dma_free_coherent(g_dev, pagelistinfo->pagelist_buffer_size,
82 + pagelistinfo->pagelist,
83 + pagelistinfo->dma_addr);
84 + }
85 }
86
87 /* There is a potential problem with partial cache lines (pages?)
88 @@ -336,6 +354,7 @@ create_pagelist(char *buf, char __user *
89 u32 *addrs;
90 unsigned int num_pages, offset, i, k;
91 int actual_pages;
92 + bool is_from_pool;
93 size_t pagelist_size;
94 struct scatterlist *scatterlist, *sg;
95 int dma_buffers;
96 @@ -365,8 +384,16 @@ create_pagelist(char *buf, char __user *
97 /* Allocate enough storage to hold the page pointers and the page
98 * list
99 */
100 - pagelist = dma_alloc_coherent(g_dev, pagelist_size, &dma_addr,
101 - GFP_KERNEL);
102 + if (pagelist_size > VCHIQ_DMA_POOL_SIZE) {
103 + pagelist = dma_alloc_coherent(g_dev,
104 + pagelist_size,
105 + &dma_addr,
106 + GFP_KERNEL);
107 + is_from_pool = false;
108 + } else {
109 + pagelist = dma_pool_alloc(g_dma_pool, GFP_KERNEL, &dma_addr);
110 + is_from_pool = true;
111 + }
112
113 vchiq_log_trace(vchiq_arm_log_level, "%s - %pK", __func__, pagelist);
114
115 @@ -387,6 +414,7 @@ create_pagelist(char *buf, char __user *
116 pagelistinfo->pagelist = pagelist;
117 pagelistinfo->pagelist_buffer_size = pagelist_size;
118 pagelistinfo->dma_addr = dma_addr;
119 + pagelistinfo->is_from_pool = is_from_pool;
120 pagelistinfo->dma_dir = (type == PAGELIST_WRITE) ?
121 DMA_TO_DEVICE : DMA_FROM_DEVICE;
122 pagelistinfo->num_pages = num_pages;