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 | 4dd1b7f | 2014-05-22 14:48:01 +0200 | [diff] [blame] | 27 | /* Returns the coherency base address in r1 (r0 is untouched) */ |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 28 | ENTRY(ll_get_coherency_base) |
Gregory CLEMENT | ccd6a13 | 2014-04-14 17:10:05 +0200 | [diff] [blame] | 29 | mrc p15, 0, r1, c1, c0, 0 |
| 30 | tst r1, #CR_M @ Check MMU bit enabled |
| 31 | bne 1f |
| 32 | |
Thomas Petazzoni | 4dd1b7f | 2014-05-22 14:48:01 +0200 | [diff] [blame] | 33 | /* |
| 34 | * MMU is disabled, use the physical address of the coherency |
| 35 | * base address. |
| 36 | */ |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 37 | adr r1, 3f |
| 38 | ldr r3, [r1] |
| 39 | ldr r1, [r1, r3] |
Gregory CLEMENT | ccd6a13 | 2014-04-14 17:10:05 +0200 | [diff] [blame] | 40 | b 2f |
| 41 | 1: |
Thomas Petazzoni | 4dd1b7f | 2014-05-22 14:48:01 +0200 | [diff] [blame] | 42 | /* |
| 43 | * MMU is enabled, use the virtual address of the coherency |
| 44 | * base address. |
| 45 | */ |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 46 | ldr r1, =coherency_base |
| 47 | ldr r1, [r1] |
Gregory CLEMENT | ccd6a13 | 2014-04-14 17:10:05 +0200 | [diff] [blame] | 48 | 2: |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 49 | mov pc, lr |
| 50 | ENDPROC(ll_get_coherency_base) |
| 51 | |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 52 | /* |
| 53 | * Returns the coherency CPU mask in r3 (r0 is untouched). This |
| 54 | * coherency CPU mask can be used with the coherency fabric |
| 55 | * configuration and control registers. Note that the mask is already |
| 56 | * endian-swapped as appropriate so that the calling functions do not |
| 57 | * have to care about endianness issues while accessing the coherency |
| 58 | * fabric registers |
| 59 | */ |
| 60 | ENTRY(ll_get_coherency_cpumask) |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 61 | mrc 15, 0, r3, cr0, cr0, 5 |
| 62 | and r3, r3, #15 |
Gregory CLEMENT | b41375f | 2014-04-14 17:10:06 +0200 | [diff] [blame] | 63 | mov r2, #(1 << 24) |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 64 | lsl r3, r2, r3 |
Thomas Petazzoni | 4fbe639 | 2014-05-22 14:47:59 +0200 | [diff] [blame] | 65 | ARM_BE8(rev r3, r3) |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 66 | mov pc, lr |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 67 | ENDPROC(ll_get_coherency_cpumask) |
Gregory CLEMENT | 009f131 | 2012-08-02 11:16:29 +0300 | [diff] [blame] | 68 | |
Thomas Petazzoni | 4dd1b7f | 2014-05-22 14:48:01 +0200 | [diff] [blame] | 69 | /* |
| 70 | * ll_add_cpu_to_smp_group(), ll_enable_coherency() and |
| 71 | * ll_disable_coherency() use the strex/ldrex instructions while the |
| 72 | * MMU can be disabled. The Armada XP SoC has an exclusive monitor |
| 73 | * that tracks transactions to Device and/or SO memory and thanks to |
| 74 | * that, exclusive transactions are functional even when the MMU is |
| 75 | * disabled. |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 76 | */ |
| 77 | |
| 78 | ENTRY(ll_add_cpu_to_smp_group) |
| 79 | /* |
Thomas Petazzoni | 4dd1b7f | 2014-05-22 14:48:01 +0200 | [diff] [blame] | 80 | * As r0 is not modified by ll_get_coherency_base() and |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 81 | * ll_get_coherency_cpumask(), we use it to temporarly save lr |
| 82 | * and avoid it being modified by the branch and link |
| 83 | * calls. This function is used very early in the secondary |
| 84 | * CPU boot, and no stack is available at this point. |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 85 | */ |
Thomas Petazzoni | 90ba76f | 2014-05-22 14:48:00 +0200 | [diff] [blame] | 86 | mov r0, lr |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 87 | bl ll_get_coherency_base |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 88 | bl ll_get_coherency_cpumask |
Thomas Petazzoni | 90ba76f | 2014-05-22 14:48:00 +0200 | [diff] [blame] | 89 | mov lr, r0 |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 90 | add r0, r1, #ARMADA_XP_CFB_CFG_REG_OFFSET |
Nadav Haklai | b60b61d | 2013-05-23 10:54:02 +0200 | [diff] [blame] | 91 | 1: |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 92 | ldrex r2, [r0] |
| 93 | orr r2, r2, r3 |
| 94 | strex r1, r2, [r0] |
| 95 | cmp r1, #0 |
| 96 | bne 1b |
| 97 | mov pc, lr |
| 98 | ENDPROC(ll_add_cpu_to_smp_group) |
Gregory CLEMENT | 009f131 | 2012-08-02 11:16:29 +0300 | [diff] [blame] | 99 | |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 100 | ENTRY(ll_enable_coherency) |
| 101 | /* |
Thomas Petazzoni | 4dd1b7f | 2014-05-22 14:48:01 +0200 | [diff] [blame] | 102 | * As r0 is not modified by ll_get_coherency_base() and |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 103 | * ll_get_coherency_cpumask(), we use it to temporarly save lr |
| 104 | * and avoid it being modified by the branch and link |
| 105 | * calls. This function is used very early in the secondary |
| 106 | * CPU boot, and no stack is available at this point. |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 107 | */ |
| 108 | mov r0, lr |
| 109 | bl ll_get_coherency_base |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 110 | bl ll_get_coherency_cpumask |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 111 | mov lr, r0 |
| 112 | add r0, r1, #ARMADA_XP_CFB_CTL_REG_OFFSET |
Nadav Haklai | b60b61d | 2013-05-23 10:54:02 +0200 | [diff] [blame] | 113 | 1: |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 114 | ldrex r2, [r0] |
| 115 | orr r2, r2, r3 |
| 116 | strex r1, r2, [r0] |
| 117 | cmp r1, #0 |
| 118 | bne 1b |
Gregory CLEMENT | 009f131 | 2012-08-02 11:16:29 +0300 | [diff] [blame] | 119 | dsb |
Gregory CLEMENT | 009f131 | 2012-08-02 11:16:29 +0300 | [diff] [blame] | 120 | mov r0, #0 |
| 121 | mov pc, lr |
Gregory CLEMENT | 2e8a594 | 2014-04-14 17:10:08 +0200 | [diff] [blame] | 122 | ENDPROC(ll_enable_coherency) |
| 123 | |
Gregory CLEMENT | 1a6bfbc | 2014-04-14 17:10:09 +0200 | [diff] [blame] | 124 | ENTRY(ll_disable_coherency) |
| 125 | /* |
Thomas Petazzoni | 4dd1b7f | 2014-05-22 14:48:01 +0200 | [diff] [blame] | 126 | * As r0 is not modified by ll_get_coherency_base() and |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 127 | * ll_get_coherency_cpumask(), we use it to temporarly save lr |
| 128 | * and avoid it being modified by the branch and link |
| 129 | * calls. This function is used very early in the secondary |
| 130 | * CPU boot, and no stack is available at this point. |
Gregory CLEMENT | 1a6bfbc | 2014-04-14 17:10:09 +0200 | [diff] [blame] | 131 | */ |
Thomas Petazzoni | 90ba76f | 2014-05-22 14:48:00 +0200 | [diff] [blame] | 132 | mov r0, lr |
Gregory CLEMENT | 1a6bfbc | 2014-04-14 17:10:09 +0200 | [diff] [blame] | 133 | bl ll_get_coherency_base |
Thomas Petazzoni | 07ae144 | 2014-05-22 14:48:02 +0200 | [diff] [blame] | 134 | bl ll_get_coherency_cpumask |
Thomas Petazzoni | 90ba76f | 2014-05-22 14:48:00 +0200 | [diff] [blame] | 135 | mov lr, r0 |
Gregory CLEMENT | 1a6bfbc | 2014-04-14 17:10:09 +0200 | [diff] [blame] | 136 | add r0, r1, #ARMADA_XP_CFB_CTL_REG_OFFSET |
| 137 | 1: |
| 138 | ldrex r2, [r0] |
| 139 | bic r2, r2, r3 |
| 140 | strex r1, r2, [r0] |
| 141 | cmp r1, #0 |
| 142 | bne 1b |
| 143 | dsb |
| 144 | mov pc, lr |
| 145 | ENDPROC(ll_disable_coherency) |
Gregory CLEMENT | ccd6a13 | 2014-04-14 17:10:05 +0200 | [diff] [blame] | 146 | |
| 147 | .align 2 |
| 148 | 3: |
| 149 | .long coherency_phys_base - . |