wwan: fix hotplug event handling
[openwrt/openwrt.git] / target / linux / bcm27xx / patches-5.4 / 950-0213-vchiq-Add-36-bit-address-support.patch
1 From 2cba27bce0470a06237b3bd7883d43ade0d5c39c Mon Sep 17 00:00:00 2001
2 From: Phil Elwell <phil@raspberrypi.org>
3 Date: Thu, 1 Nov 2018 17:31:37 +0000
4 Subject: [PATCH] vchiq: Add 36-bit address support
5
6 Conditional on a new compatible string, change the pagelist encoding
7 such that the top 24 bits are the pfn, leaving 8 bits for run length
8 (-1).
9
10 Signed-off-by: Phil Elwell <phil@raspberrypi.org>
11 ---
12 .../interface/vchiq_arm/vchiq_2835_arm.c | 90 ++++++++++++++-----
13 .../interface/vchiq_arm/vchiq_arm.c | 6 ++
14 .../interface/vchiq_arm/vchiq_arm.h | 1 +
15 3 files changed, 75 insertions(+), 22 deletions(-)
16
17 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
18 +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_2835_arm.c
19 @@ -16,6 +16,8 @@
20 #include <soc/bcm2835/raspberrypi-firmware.h>
21
22 #define TOTAL_SLOTS (VCHIQ_SLOT_ZERO_SLOTS + 2 * 32)
23 +#define VC_SAFE(x) (g_use_36bit_addrs ? ((u32)(x) | 0xc0000000) : (u32)(x))
24 +#define IS_VC_SAFE(x) (g_use_36bit_addrs ? !((x) & ~0x3fffffffull) : 1)
25
26 #include "vchiq_arm.h"
27 #include "vchiq_connected.h"
28 @@ -63,6 +65,7 @@ static void __iomem *g_regs;
29 */
30 static unsigned int g_cache_line_size = 32;
31 static struct dma_pool *g_dma_pool;
32 +static unsigned int g_use_36bit_addrs = 0;
33 static unsigned int g_fragments_size;
34 static char *g_fragments_base;
35 static char *g_free_fragments;
36 @@ -106,6 +109,8 @@ int vchiq_platform_init(struct platform_
37 g_cache_line_size = drvdata->cache_line_size;
38 g_fragments_size = 2 * g_cache_line_size;
39
40 + g_use_36bit_addrs = (dev->dma_pfn_offset == 0);
41 +
42 /* Allocate space for the channels in coherent memory */
43 slot_mem_size = PAGE_ALIGN(TOTAL_SLOTS * VCHIQ_SLOT_SIZE);
44 frag_mem_size = PAGE_ALIGN(g_fragments_size * MAX_FRAGMENTS);
45 @@ -117,14 +122,21 @@ int vchiq_platform_init(struct platform_
46 return -ENOMEM;
47 }
48
49 + if (!IS_VC_SAFE(slot_phys)) {
50 + dev_err(dev, "allocated DMA memory %pad is not VC-safe\n",
51 + &slot_phys);
52 + return -ENOMEM;
53 + }
54 +
55 WARN_ON(((unsigned long)slot_mem & (PAGE_SIZE - 1)) != 0);
56 + channelbase = VC_SAFE(slot_phys);
57
58 vchiq_slot_zero = vchiq_init_slots(slot_mem, slot_mem_size);
59 if (!vchiq_slot_zero)
60 return -EINVAL;
61
62 vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_OFFSET_IDX] =
63 - (int)slot_phys + slot_mem_size;
64 + channelbase + slot_mem_size;
65 vchiq_slot_zero->platform_data[VCHIQ_PLATFORM_FRAGMENTS_COUNT_IDX] =
66 MAX_FRAGMENTS;
67
68 @@ -158,7 +170,6 @@ int vchiq_platform_init(struct platform_
69 }
70
71 /* Send the base address of the slots to VideoCore */
72 - channelbase = slot_phys;
73 err = rpi_firmware_property(fw, RPI_FIRMWARE_VCHIQ_INIT,
74 &channelbase, sizeof(channelbase));
75 if (err || channelbase) {
76 @@ -244,7 +255,7 @@ vchiq_prepare_bulk_data(struct vchiq_bul
77 if (!pagelistinfo)
78 return VCHIQ_ERROR;
79
80 - bulk->data = (void *)(unsigned long)pagelistinfo->dma_addr;
81 + bulk->data = (void *)VC_SAFE(pagelistinfo->dma_addr);
82
83 /*
84 * Store the pagelistinfo address in remote_data,
85 @@ -522,25 +533,60 @@ create_pagelist(char __user *buf, size_t
86
87 /* Combine adjacent blocks for performance */
88 k = 0;
89 - for_each_sg(scatterlist, sg, dma_buffers, i) {
90 - u32 len = sg_dma_len(sg);
91 - u32 addr = sg_dma_address(sg);
92 -
93 - /* Note: addrs is the address + page_count - 1
94 - * The firmware expects blocks after the first to be page-
95 - * aligned and a multiple of the page size
96 - */
97 - WARN_ON(len == 0);
98 - WARN_ON(i && (i != (dma_buffers - 1)) && (len & ~PAGE_MASK));
99 - WARN_ON(i && (addr & ~PAGE_MASK));
100 - if (k > 0 &&
101 - ((addrs[k - 1] & PAGE_MASK) +
102 - (((addrs[k - 1] & ~PAGE_MASK) + 1) << PAGE_SHIFT))
103 - == (addr & PAGE_MASK))
104 - addrs[k - 1] += ((len + PAGE_SIZE - 1) >> PAGE_SHIFT);
105 - else
106 - addrs[k++] = (addr & PAGE_MASK) |
107 - (((len + PAGE_SIZE - 1) >> PAGE_SHIFT) - 1);
108 + if (g_use_36bit_addrs) {
109 + for_each_sg(scatterlist, sg, dma_buffers, i) {
110 + u32 len = sg_dma_len(sg);
111 + u64 addr = sg_dma_address(sg);
112 + u32 page_id = (u32)((addr >> 4) & ~0xff);
113 + u32 sg_pages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
114 +
115 + /* Note: addrs is the address + page_count - 1
116 + * The firmware expects blocks after the first to be page-
117 + * aligned and a multiple of the page size
118 + */
119 + WARN_ON(len == 0);
120 + WARN_ON(i &&
121 + (i != (dma_buffers - 1)) && (len & ~PAGE_MASK));
122 + WARN_ON(i && (addr & ~PAGE_MASK));
123 + WARN_ON(upper_32_bits(addr) > 0xf);
124 + if (k > 0 &&
125 + ((addrs[k - 1] & ~0xff) +
126 + (((addrs[k - 1] & 0xff) + 1) << 8)
127 + == page_id)) {
128 + u32 inc_pages = min(sg_pages,
129 + 0xff - (addrs[k - 1] & 0xff));
130 + addrs[k - 1] += inc_pages;
131 + page_id += inc_pages << 8;
132 + sg_pages -= inc_pages;
133 + }
134 + while (sg_pages) {
135 + u32 inc_pages = min(sg_pages, 0x100u);
136 + addrs[k++] = page_id | (inc_pages - 1);
137 + page_id += inc_pages << 8;
138 + sg_pages -= inc_pages;
139 + }
140 + }
141 + } else {
142 + for_each_sg(scatterlist, sg, dma_buffers, i) {
143 + u32 len = sg_dma_len(sg);
144 + u32 addr = VC_SAFE(sg_dma_address(sg));
145 + u32 new_pages = (len + PAGE_SIZE - 1) >> PAGE_SHIFT;
146 +
147 + /* Note: addrs is the address + page_count - 1
148 + * The firmware expects blocks after the first to be page-
149 + * aligned and a multiple of the page size
150 + */
151 + WARN_ON(len == 0);
152 + WARN_ON(i && (i != (dma_buffers - 1)) && (len & ~PAGE_MASK));
153 + WARN_ON(i && (addr & ~PAGE_MASK));
154 + if (k > 0 &&
155 + ((addrs[k - 1] & PAGE_MASK) +
156 + (((addrs[k - 1] & ~PAGE_MASK) + 1) << PAGE_SHIFT))
157 + == (addr & PAGE_MASK))
158 + addrs[k - 1] += new_pages;
159 + else
160 + addrs[k++] = (addr & PAGE_MASK) | (new_pages - 1);
161 + }
162 }
163
164 /* Partial cache lines (fragments) require special measures */
165 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
166 +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.c
167 @@ -149,6 +149,11 @@ static struct vchiq_drvdata bcm2836_drvd
168 .cache_line_size = 64,
169 };
170
171 +static struct vchiq_drvdata bcm2838_drvdata = {
172 + .cache_line_size = 64,
173 + .use_36bit_addrs = true,
174 +};
175 +
176 static const char *const ioctl_names[] = {
177 "CONNECT",
178 "SHUTDOWN",
179 @@ -3164,6 +3169,7 @@ void vchiq_platform_conn_state_changed(s
180 static const struct of_device_id vchiq_of_match[] = {
181 { .compatible = "brcm,bcm2835-vchiq", .data = &bcm2835_drvdata },
182 { .compatible = "brcm,bcm2836-vchiq", .data = &bcm2836_drvdata },
183 + { .compatible = "brcm,bcm2838-vchiq", .data = &bcm2838_drvdata },
184 {},
185 };
186 MODULE_DEVICE_TABLE(of, vchiq_of_match);
187 --- a/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h
188 +++ b/drivers/staging/vc04_services/interface/vchiq_arm/vchiq_arm.h
189 @@ -97,6 +97,7 @@ struct vchiq_arm_state {
190
191 struct vchiq_drvdata {
192 const unsigned int cache_line_size;
193 + const bool use_36bit_addrs;
194 struct rpi_firmware *fw;
195 };
196