Gregory CLEMENT | 009f131 | 2012-08-02 11:16:29 +0300 | [diff] [blame] | 1 | /* |
| 2 | * Coherency fabric: low level functions |
| 3 | * |
| 4 | * Copyright (C) 2012 Marvell |
| 5 | * |
| 6 | * Gregory CLEMENT <gregory.clement@free-electrons.com> |
| 7 | * |
| 8 | * This file is licensed under the terms of the GNU General Public |
| 9 | * License version 2. This program is licensed "as is" without any |
| 10 | * warranty of any kind, whether express or implied. |
| 11 | * |
| 12 | * This file implements the assembly function to add a CPU to the |
| 13 | * coherency fabric. This function is called by each of the secondary |
| 14 | * CPUs during their early boot in an SMP kernel, this why this |
| 15 | * function have to callable from assembly. It can also be called by a |
| 16 | * primary CPU from C code during its boot. |
| 17 | */ |
| 18 | |
| 19 | #include <linux/linkage.h> |
| 20 | #define ARMADA_XP_CFB_CTL_REG_OFFSET 0x0 |
| 21 | #define ARMADA_XP_CFB_CFG_REG_OFFSET 0x4 |
| 22 | |
Ben Dooks | bca028e | 2013-02-01 10:36:22 +0000 | [diff] [blame] | 23 | #include <asm/assembler.h> |
Gregory CLEMENT | ccd6a13 | 2014-04-14 17:10:05 +0200 | [diff] [blame] | 24 | #include <asm/cp15.h> |
Ben Dooks | bca028e | 2013-02-01 10:36:22 +0000 | [diff] [blame] | 25 | |
Gregory CLEMENT | 009f131 | 2012-08-02 11:16:29 +0300 | [diff] [blame] | 26 | .text |
Thomas Petazzoni | 30cdef9 | 2014-11-13 10:38:56 +0100 | [diff] [blame] | 27 | /* |
| 28 | * Returns the coherency base address in r1 (r0 is untouched), or 0 if |
| 29 | * the coherency fabric is not enabled. |
| 30 | */ |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 31 | ENTRY(ll_get_coherency_base) |
Gregory CLEMENT | ccd6a13 | 2014-04-14 17:10:05 +0200 | [diff] [blame] | 32 | mrc p15, 0, r1, c1, c0, 0 |
| 33 | tst r1, #CR_M @ Check MMU bit enabled |
| 34 | bne 1f |
| 35 | |
Thomas Petazzoni | 4dd1b7f | 2014-05-22 14:48:01 +0200 | [diff] [blame] | 36 | /* |
| 37 | * MMU is disabled, use the physical address of the coherency |
Ard Biesheuvel | 0b58725 | 2020-09-16 13:56:54 +0300 | [diff] [blame] | 38 | * base address, (or 0x0 if the coherency fabric is not mapped) |
Thomas Petazzoni | 4dd1b7f | 2014-05-22 14:48:01 +0200 | [diff] [blame] | 39 | */ |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 40 | adr r1, 3f |
| 41 | ldr r3, [r1] |
| 42 | ldr r1, [r1, r3] |
Gregory CLEMENT | ccd6a13 | 2014-04-14 17:10:05 +0200 | [diff] [blame] | 43 | b 2f |
| 44 | 1: |
Thomas Petazzoni | 4dd1b7f | 2014-05-22 14:48:01 +0200 | [diff] [blame] | 45 | /* |
| 46 | * MMU is enabled, use the virtual address of the coherency |
| 47 | * base address. |
| 48 | */ |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 49 | ldr r1, =coherency_base |
| 50 | ldr r1, [r1] |
Gregory CLEMENT | ccd6a13 | 2014-04-14 17:10:05 +0200 | [diff] [blame] | 51 | 2: |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 52 | ret lr |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 53 | ENDPROC(ll_get_coherency_base) |
| 54 | |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 55 | /* |
| 56 | * Returns the coherency CPU mask in r3 (r0 is untouched). This |
| 57 | * coherency CPU mask can be used with the coherency fabric |
| 58 | * configuration and control registers. Note that the mask is already |
| 59 | * endian-swapped as appropriate so that the calling functions do not |
| 60 | * have to care about endianness issues while accessing the coherency |
| 61 | * fabric registers |
| 62 | */ |
| 63 | ENTRY(ll_get_coherency_cpumask) |
Stefan Agner | 969ad77 | 2019-04-11 09:54:03 +0200 | [diff] [blame] | 64 | mrc p15, 0, r3, cr0, cr0, 5 |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 65 | and r3, r3, #15 |
Gregory CLEMENT | b41375f | 2014-04-14 17:10:06 +0200 | [diff] [blame] | 66 | mov r2, #(1 << 24) |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 67 | lsl r3, r2, r3 |
Thomas Petazzoni | 4fbe639 | 2014-05-22 14:47:59 +0200 | [diff] [blame] | 68 | ARM_BE8(rev r3, r3) |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 69 | ret lr |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 70 | ENDPROC(ll_get_coherency_cpumask) |
Gregory CLEMENT | 009f131 | 2012-08-02 11:16:29 +0300 | [diff] [blame] | 71 | |
Thomas Petazzoni | 4dd1b7f | 2014-05-22 14:48:01 +0200 | [diff] [blame] | 72 | /* |
| 73 | * ll_add_cpu_to_smp_group(), ll_enable_coherency() and |
| 74 | * ll_disable_coherency() use the strex/ldrex instructions while the |
| 75 | * MMU can be disabled. The Armada XP SoC has an exclusive monitor |
| 76 | * that tracks transactions to Device and/or SO memory and thanks to |
| 77 | * that, exclusive transactions are functional even when the MMU is |
| 78 | * disabled. |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 79 | */ |
| 80 | |
| 81 | ENTRY(ll_add_cpu_to_smp_group) |
| 82 | /* |
Thomas Petazzoni | 4dd1b7f | 2014-05-22 14:48:01 +0200 | [diff] [blame] | 83 | * As r0 is not modified by ll_get_coherency_base() and |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 84 | * ll_get_coherency_cpumask(), we use it to temporarly save lr |
| 85 | * and avoid it being modified by the branch and link |
| 86 | * calls. This function is used very early in the secondary |
| 87 | * CPU boot, and no stack is available at this point. |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 88 | */ |
Thomas Petazzoni | 90ba76f | 2014-05-22 14:48:00 +0200 | [diff] [blame] | 89 | mov r0, lr |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 90 | bl ll_get_coherency_base |
Thomas Petazzoni | 30cdef9 | 2014-11-13 10:38:56 +0100 | [diff] [blame] | 91 | /* Bail out if the coherency is not enabled */ |
| 92 | cmp r1, #0 |
| 93 | reteq r0 |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 94 | bl ll_get_coherency_cpumask |
Thomas Petazzoni | 90ba76f | 2014-05-22 14:48:00 +0200 | [diff] [blame] | 95 | mov lr, r0 |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 96 | add r0, r1, #ARMADA_XP_CFB_CFG_REG_OFFSET |
Nadav Haklai | b60b61d | 2013-05-23 10:54:02 +0200 | [diff] [blame] | 97 | 1: |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 98 | ldrex r2, [r0] |
| 99 | orr r2, r2, r3 |
| 100 | strex r1, r2, [r0] |
| 101 | cmp r1, #0 |
| 102 | bne 1b |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 103 | ret lr |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 104 | ENDPROC(ll_add_cpu_to_smp_group) |
Gregory CLEMENT | 009f131 | 2012-08-02 11:16:29 +0300 | [diff] [blame] | 105 | |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 106 | ENTRY(ll_enable_coherency) |
| 107 | /* |
Thomas Petazzoni | 4dd1b7f | 2014-05-22 14:48:01 +0200 | [diff] [blame] | 108 | * As r0 is not modified by ll_get_coherency_base() and |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 109 | * ll_get_coherency_cpumask(), we use it to temporarly save lr |
| 110 | * and avoid it being modified by the branch and link |
| 111 | * calls. This function is used very early in the secondary |
| 112 | * CPU boot, and no stack is available at this point. |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 113 | */ |
| 114 | mov r0, lr |
| 115 | bl ll_get_coherency_base |
Thomas Petazzoni | 30cdef9 | 2014-11-13 10:38:56 +0100 | [diff] [blame] | 116 | /* Bail out if the coherency is not enabled */ |
| 117 | cmp r1, #0 |
| 118 | reteq r0 |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 119 | bl ll_get_coherency_cpumask |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 120 | mov lr, r0 |
| 121 | add r0, r1, #ARMADA_XP_CFB_CTL_REG_OFFSET |
Nadav Haklai | b60b61d | 2013-05-23 10:54:02 +0200 | [diff] [blame] | 122 | 1: |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 123 | ldrex r2, [r0] |
| 124 | orr r2, r2, r3 |
| 125 | strex r1, r2, [r0] |
| 126 | cmp r1, #0 |
| 127 | bne 1b |
Gregory CLEMENT | 009f131 | 2012-08-02 11:16:29 +0300 | [diff] [blame] | 128 | dsb |
Gregory CLEMENT | 009f131 | 2012-08-02 11:16:29 +0300 | [diff] [blame] | 129 | mov r0, #0 |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 130 | ret lr |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 131 | ENDPROC(ll_enable_coherency) |
| 132 | |
Gregory CLEMENT | 1a6bfbc | 2014-04-14 17:10:09 +0200 | [diff] [blame] | 133 | ENTRY(ll_disable_coherency) |
| 134 | /* |
Thomas Petazzoni | 4dd1b7f | 2014-05-22 14:48:01 +0200 | [diff] [blame] | 135 | * As r0 is not modified by ll_get_coherency_base() and |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 136 | * ll_get_coherency_cpumask(), we use it to temporarly save lr |
| 137 | * and avoid it being modified by the branch and link |
| 138 | * calls. This function is used very early in the secondary |
| 139 | * CPU boot, and no stack is available at this point. |
Gregory CLEMENT | 1a6bfbc | 2014-04-14 17:10:09 +0200 | [diff] [blame] | 140 | */ |
Thomas Petazzoni | 90ba76f | 2014-05-22 14:48:00 +0200 | [diff] [blame] | 141 | mov r0, lr |
Gregory CLEMENT | 1a6bfbc | 2014-04-14 17:10:09 +0200 | [diff] [blame] | 142 | bl ll_get_coherency_base |
Thomas Petazzoni | 30cdef9 | 2014-11-13 10:38:56 +0100 | [diff] [blame] | 143 | /* Bail out if the coherency is not enabled */ |
| 144 | cmp r1, #0 |
| 145 | reteq r0 |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 146 | bl ll_get_coherency_cpumask |
Thomas Petazzoni | 90ba76f | 2014-05-22 14:48:00 +0200 | [diff] [blame] | 147 | mov lr, r0 |
Gregory CLEMENT | 1a6bfbc | 2014-04-14 17:10:09 +0200 | [diff] [blame] | 148 | add r0, r1, #ARMADA_XP_CFB_CTL_REG_OFFSET |
| 149 | 1: |
| 150 | ldrex r2, [r0] |
| 151 | bic r2, r2, r3 |
| 152 | strex r1, r2, [r0] |
| 153 | cmp r1, #0 |
| 154 | bne 1b |
| 155 | dsb |
Russell King | 6ebbf2c | 2014-06-30 16:29:12 +0100 | [diff] [blame] | 156 | ret lr |
Gregory CLEMENT | 1a6bfbc | 2014-04-14 17:10:09 +0200 | [diff] [blame] | 157 | ENDPROC(ll_disable_coherency) |
Gregory CLEMENT | ccd6a13 | 2014-04-14 17:10:05 +0200 | [diff] [blame] | 158 | |
| 159 | .align 2 |
| 160 | 3: |
| 161 | .long coherency_phys_base - . |