developer | fd40db2 | 2021-04-29 10:08:25 +0800 | [diff] [blame] | 1 | --- a/arch/mips/Kconfig |
| 2 | +++ b/arch/mips/Kconfig |
| 3 | @@ -2466,6 +2466,17 @@ config SB1_PASS_2_1_WORKAROUNDS |
| 4 | depends on CPU_SB1 && CPU_SB1_PASS_2 |
| 5 | default y |
| 6 | |
| 7 | +config MIPS_ER35_WORKAROUNDS |
| 8 | + bool |
| 9 | + depends on SYS_SUPPORTS_MIPS_CPS |
| 10 | + select ZONE_DMA |
| 11 | + default y |
| 12 | + |
| 13 | +config MIPS_ER35_RESERVED_SPACE |
| 14 | + hex |
| 15 | + default 0x1000000 |
| 16 | + depends on MIPS_ER35_WORKAROUNDS |
| 17 | + |
| 18 | choice |
| 19 | prompt "SmartMIPS or microMIPS ASE support" |
| 20 | |
| 21 | --- a/arch/mips/include/asm/dma.h |
| 22 | +++ b/arch/mips/include/asm/dma.h |
| 23 | @@ -87,6 +87,8 @@ |
| 24 | #if defined(CONFIG_SGI_IP22) || defined(CONFIG_SGI_IP28) |
| 25 | /* don't care; ISA bus master won't work, ISA slave DMA supports 32bit addr */ |
| 26 | #define MAX_DMA_ADDRESS PAGE_OFFSET |
| 27 | +#elif defined(CONFIG_MIPS_ER35_WORKAROUNDS) |
| 28 | +#define MAX_DMA_ADDRESS (PAGE_OFFSET + CONFIG_MIPS_ER35_RESERVED_SPACE) |
| 29 | #else |
| 30 | #define MAX_DMA_ADDRESS (PAGE_OFFSET + 0x01000000) |
| 31 | #endif |
| 32 | --- a/arch/mips/kernel/head.S |
| 33 | +++ b/arch/mips/kernel/head.S |
| 34 | @@ -22,6 +22,7 @@ |
| 35 | #include <asm/irqflags.h> |
| 36 | #include <asm/regdef.h> |
| 37 | #include <asm/mipsregs.h> |
| 38 | +#include <asm/cacheops.h> |
| 39 | #include <asm/stackframe.h> |
| 40 | |
| 41 | #include <kernel-entry-init.h> |
| 42 | @@ -93,6 +94,67 @@ NESTED(kernel_entry, 16, sp) # kernel entry point |
| 43 | |
| 44 | setup_c0_status_pri |
| 45 | |
| 46 | +#ifdef CONFIG_MIPS_ER35_WORKAROUNDS |
| 47 | + /* Jump to KSEG1 so that we can perform cache related operations */ |
| 48 | + PTR_LA t0, 0f |
| 49 | + li t1, 5 |
| 50 | + ins t0, t1, 29, 3 |
| 51 | + jr t0 |
| 52 | + nop |
| 53 | +0: |
| 54 | + |
| 55 | + /* Calculate L2 Cache size */ |
| 56 | + MFC0 t0, CP0_CONFIG, 2 |
| 57 | + ext t1, t0, 4, 4 |
| 58 | + li t2, 2 |
| 59 | + sllv t1, t2, t1 /* Cache line size */ |
| 60 | + |
| 61 | + ext t2, t0, 8, 4 |
| 62 | + li t3, 64 |
| 63 | + sllv t2, t3, t2 /* Sets per way */ |
| 64 | + |
| 65 | + ext t3, t0, 0, 4 |
| 66 | + addiu t3, 1 /* Number of ways */ |
| 67 | + |
| 68 | + mul t2, t2, t3 /* Number of sets */ |
| 69 | + |
| 70 | + |
| 71 | + /* Flush L2 Cache before setting CCA overrides */ |
| 72 | + move t3, zero |
| 73 | +1: |
| 74 | + cache Index_Writeback_Inv_SD, 0(t3) |
| 75 | + sub t2, 1 |
| 76 | + add t3, t3, t1 |
| 77 | + bne t2, zero, 1b |
| 78 | + nop |
| 79 | + |
| 80 | + sync |
| 81 | + |
| 82 | + /* |
| 83 | + * Override bottom CONFIG_MIPS_ER35_RESERVED_SPACE of DDR to |
| 84 | + * Uncached (which will be reserved as DMA zone) |
| 85 | + */ |
| 86 | + MFC0 t0, CP0_CMGCRBASE |
| 87 | + PTR_SLL t0, t0, 4 |
| 88 | + li t1, 5 |
| 89 | + ins t0, t1, 29, 3 |
| 90 | + |
| 91 | + /* GCR_REG2_MASK */ |
| 92 | + lui t1, (~((CONFIG_MIPS_ER35_RESERVED_SPACE - 1) >> 16)) & 0xffff |
| 93 | + ori t1, t1, 0x0051 |
| 94 | + sw t1, 0xb8(t0) |
| 95 | + |
| 96 | + /* GCR_REG2_BASE */ |
| 97 | + sw zero, 0xb0(t0) |
| 98 | + |
| 99 | + /* Set default override to Write-through */ |
| 100 | + lw t1, 0x08(t0) |
| 101 | + li t2, 0xffff8000 |
| 102 | + and t1, t1, t2 |
| 103 | + ori t1, 0x10 |
| 104 | + sw t1, 0x08(t0) |
| 105 | +#endif |
| 106 | + |
| 107 | /* We might not get launched at the address the kernel is linked to, |
| 108 | so we jump there. */ |
| 109 | PTR_LA t0, 0f |
| 110 | --- a/arch/mips/ralink/Kconfig |
| 111 | +++ b/arch/mips/ralink/Kconfig |
| 112 | @@ -59,6 +59,8 @@ choice |
| 113 | select HAVE_PCI if PCI_MT7621 |
| 114 | select WEAK_REORDERING_BEYOND_LLSC |
| 115 | select GENERIC_CLOCKEVENTS_BROADCAST |
| 116 | + select MIPS_ER35_WORKAROUNDS |
| 117 | + |
| 118 | endchoice |
| 119 | |
| 120 | choice |
| 121 | --- a/arch/mips/ralink/Platform |
| 122 | +++ b/arch/mips/ralink/Platform |
| 123 | @@ -30,5 +30,5 @@ cflags-$(CONFIG_SOC_MT7620) += -I$(srctree)/arch/mips/include/asm/mach-ralink/mt |
| 124 | |
| 125 | # Ralink MT7621 |
| 126 | # |
| 127 | -load-$(CONFIG_SOC_MT7621) += 0xffffffff80001000 |
| 128 | +load-$(CONFIG_SOC_MT7621) += 0xffffffff80001000+$(CONFIG_MIPS_ER35_RESERVED_SPACE) |
| 129 | cflags-$(CONFIG_SOC_MT7621) += -I$(srctree)/arch/mips/include/asm/mach-ralink/mt7621 |
| 130 | --- a/kernel/dma/direct.c |
| 131 | +++ b/kernel/dma/direct.c |
| 132 | @@ -91,6 +91,10 @@ struct page *__dma_direct_alloc_pages(struct device *dev, size_t size, |
| 133 | struct page *page = NULL; |
| 134 | u64 phys_mask; |
| 135 | |
| 136 | +#ifdef CONFIG_MIPS_ER35_WORKAROUNDS |
| 137 | + gfp |= __GFP_DMA; |
| 138 | +#endif |
| 139 | + |
| 140 | if (attrs & DMA_ATTR_NO_WARN) |
| 141 | gfp |= __GFP_NOWARN; |
| 142 | |