Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

ARM: mvebu: implement Armada 375 coherency workaround

The early revisions of Armada 375 SOCs (Z1 stepping) have a bug in the
I/O coherency unit that prevents using the normal method for the I/O
coherency barrier. The recommended workaround is to use a XOR memset
transfer to act as the I/O coherency barrier.

This involves "borrowing" a XOR engine, which gets disabled in the
Device Tree so the normal XOR driver doesn't use it.

Signed-off-by: Thomas Petazzoni <thomas.petazzoni@free-electrons.com>
Link: https://lkml.kernel.org/r/1397483228-25625-8-git-send-email-thomas.petazzoni@free-electrons.com
Signed-off-by: Jason Cooper <jason@lakedaemon.net>

authored by

Thomas Petazzoni and committed by
Jason Cooper
5ab5afd8 77fa4b9a

+165 -3
+165 -3
arch/arm/mach-mvebu/coherency.c
··· 17 17 * supplies basic routines for configuring and controlling hardware coherency 18 18 */ 19 19 20 + #define pr_fmt(fmt) "mvebu-coherency: " fmt 21 + 20 22 #include <linux/kernel.h> 21 23 #include <linux/init.h> 22 24 #include <linux/of_address.h> ··· 26 24 #include <linux/smp.h> 27 25 #include <linux/dma-mapping.h> 28 26 #include <linux/platform_device.h> 27 + #include <linux/slab.h> 28 + #include <linux/mbus.h> 29 + #include <linux/clk.h> 29 30 #include <asm/smp_plat.h> 30 31 #include <asm/cacheflush.h> 31 32 #include "armada-370-xp.h" ··· 71 66 return ll_set_cpu_coherent(coherency_base, hw_cpu_id); 72 67 } 73 68 69 + /* 70 + * The below code implements the I/O coherency workaround on Armada 71 + * 375. This workaround consists in using the two channels of the 72 + * first XOR engine to trigger a XOR transaction that serves as the 73 + * I/O coherency barrier. 74 + */ 75 + 76 + static void __iomem *xor_base, *xor_high_base; 77 + static dma_addr_t coherency_wa_buf_phys[CONFIG_NR_CPUS]; 78 + static void *coherency_wa_buf[CONFIG_NR_CPUS]; 79 + static bool coherency_wa_enabled; 80 + 81 + #define XOR_CONFIG(chan) (0x10 + (chan * 4)) 82 + #define XOR_ACTIVATION(chan) (0x20 + (chan * 4)) 83 + #define WINDOW_BAR_ENABLE(chan) (0x240 + ((chan) << 2)) 84 + #define WINDOW_BASE(w) (0x250 + ((w) << 2)) 85 + #define WINDOW_SIZE(w) (0x270 + ((w) << 2)) 86 + #define WINDOW_REMAP_HIGH(w) (0x290 + ((w) << 2)) 87 + #define WINDOW_OVERRIDE_CTRL(chan) (0x2A0 + ((chan) << 2)) 88 + #define XOR_DEST_POINTER(chan) (0x2B0 + (chan * 4)) 89 + #define XOR_BLOCK_SIZE(chan) (0x2C0 + (chan * 4)) 90 + #define XOR_INIT_VALUE_LOW 0x2E0 91 + #define XOR_INIT_VALUE_HIGH 0x2E4 92 + 93 + static inline void mvebu_hwcc_armada375_sync_io_barrier_wa(void) 94 + { 95 + int idx = smp_processor_id(); 96 + 97 + /* Write '1' to the first word of the buffer */ 98 + writel(0x1, coherency_wa_buf[idx]); 99 + 100 + /* Wait until the engine is idle */ 101 + while ((readl(xor_base + XOR_ACTIVATION(idx)) >> 4) & 0x3) 102 + ; 103 + 104 + dmb(); 105 + 106 + /* Trigger channel */ 107 + writel(0x1, xor_base + XOR_ACTIVATION(idx)); 108 + 109 + /* Poll the data until it is cleared by the XOR transaction */ 110 + while (readl(coherency_wa_buf[idx])) 111 + ; 112 + } 113 + 114 + static void __init armada_375_coherency_init_wa(void) 115 + { 116 + const struct mbus_dram_target_info *dram; 117 + struct device_node *xor_node; 118 + struct property *xor_status; 119 + struct clk *xor_clk; 120 + u32 win_enable = 0; 121 + int i; 122 + 123 + pr_warn("enabling coherency workaround for Armada 375 Z1, one XOR engine disabled\n"); 124 + 125 + /* 126 + * Since the workaround uses one XOR engine, we grab a 127 + * reference to its Device Tree node first. 128 + */ 129 + xor_node = of_find_compatible_node(NULL, NULL, "marvell,orion-xor"); 130 + BUG_ON(!xor_node); 131 + 132 + /* 133 + * Then we mark it as disabled so that the real XOR driver 134 + * will not use it. 135 + */ 136 + xor_status = kzalloc(sizeof(struct property), GFP_KERNEL); 137 + BUG_ON(!xor_status); 138 + 139 + xor_status->value = kstrdup("disabled", GFP_KERNEL); 140 + BUG_ON(!xor_status->value); 141 + 142 + xor_status->length = 8; 143 + xor_status->name = kstrdup("status", GFP_KERNEL); 144 + BUG_ON(!xor_status->name); 145 + 146 + of_update_property(xor_node, xor_status); 147 + 148 + /* 149 + * And we remap the registers, get the clock, and do the 150 + * initial configuration of the XOR engine. 151 + */ 152 + xor_base = of_iomap(xor_node, 0); 153 + xor_high_base = of_iomap(xor_node, 1); 154 + 155 + xor_clk = of_clk_get_by_name(xor_node, NULL); 156 + BUG_ON(!xor_clk); 157 + 158 + clk_prepare_enable(xor_clk); 159 + 160 + dram = mv_mbus_dram_info(); 161 + 162 + for (i = 0; i < 8; i++) { 163 + writel(0, xor_base + WINDOW_BASE(i)); 164 + writel(0, xor_base + WINDOW_SIZE(i)); 165 + if (i < 4) 166 + writel(0, xor_base + WINDOW_REMAP_HIGH(i)); 167 + } 168 + 169 + for (i = 0; i < dram->num_cs; i++) { 170 + const struct mbus_dram_window *cs = dram->cs + i; 171 + writel((cs->base & 0xffff0000) | 172 + (cs->mbus_attr << 8) | 173 + dram->mbus_dram_target_id, xor_base + WINDOW_BASE(i)); 174 + writel((cs->size - 1) & 0xffff0000, xor_base + WINDOW_SIZE(i)); 175 + 176 + win_enable |= (1 << i); 177 + win_enable |= 3 << (16 + (2 * i)); 178 + } 179 + 180 + writel(win_enable, xor_base + WINDOW_BAR_ENABLE(0)); 181 + writel(win_enable, xor_base + WINDOW_BAR_ENABLE(1)); 182 + writel(0, xor_base + WINDOW_OVERRIDE_CTRL(0)); 183 + writel(0, xor_base + WINDOW_OVERRIDE_CTRL(1)); 184 + 185 + for (i = 0; i < CONFIG_NR_CPUS; i++) { 186 + coherency_wa_buf[i] = kzalloc(PAGE_SIZE, GFP_KERNEL); 187 + BUG_ON(!coherency_wa_buf[i]); 188 + 189 + /* 190 + * We can't use the DMA mapping API, since we don't 191 + * have a valid 'struct device' pointer 192 + */ 193 + coherency_wa_buf_phys[i] = 194 + virt_to_phys(coherency_wa_buf[i]); 195 + BUG_ON(!coherency_wa_buf_phys[i]); 196 + 197 + /* 198 + * Configure the XOR engine for memset operation, with 199 + * a 128 bytes block size 200 + */ 201 + writel(0x444, xor_base + XOR_CONFIG(i)); 202 + writel(128, xor_base + XOR_BLOCK_SIZE(i)); 203 + writel(coherency_wa_buf_phys[i], 204 + xor_base + XOR_DEST_POINTER(i)); 205 + } 206 + 207 + writel(0x0, xor_base + XOR_INIT_VALUE_LOW); 208 + writel(0x0, xor_base + XOR_INIT_VALUE_HIGH); 209 + 210 + coherency_wa_enabled = true; 211 + } 212 + 74 213 static inline void mvebu_hwcc_sync_io_barrier(void) 75 214 { 215 + if (coherency_wa_enabled) { 216 + mvebu_hwcc_armada375_sync_io_barrier_wa(); 217 + return; 218 + } 219 + 76 220 writel(0x1, coherency_cpu_base + IO_SYNC_BARRIER_CTL_OFFSET); 77 221 while (readl(coherency_cpu_base + IO_SYNC_BARRIER_CTL_OFFSET) & 0x1); 78 222 } ··· 352 198 353 199 static int __init coherency_late_init(void) 354 200 { 355 - if (coherency_available()) 356 - bus_register_notifier(&platform_bus_type, 357 - &mvebu_hwcc_platform_nb); 201 + int type = coherency_type(); 202 + 203 + if (type == COHERENCY_FABRIC_TYPE_NONE) 204 + return 0; 205 + 206 + if (type == COHERENCY_FABRIC_TYPE_ARMADA_375) 207 + armada_375_coherency_init_wa(); 208 + 209 + bus_register_notifier(&platform_bus_type, 210 + &mvebu_hwcc_platform_nb); 211 + 358 212 return 0; 359 213 } 360 214