Tom Rini | 10e4779 | 2018-05-06 17:58:06 -0400 | [diff] [blame] | 1 | /* SPDX-License-Identifier: GPL-2.0+ */ |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 2 | /* |
| 3 | * GIC Initialization Routines. |
| 4 | * |
| 5 | * (C) Copyright 2013 |
| 6 | * David Feng <fenghua@phytium.com.cn> |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 7 | */ |
| 8 | |
| 9 | #include <asm-offsets.h> |
| 10 | #include <config.h> |
| 11 | #include <linux/linkage.h> |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 12 | #include <asm/gic.h> |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 13 | #include <asm/macro.h> |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 14 | |
| 15 | |
| 16 | /************************************************************************* |
| 17 | * |
| 18 | * void gic_init_secure(DistributorBase); |
| 19 | * |
| 20 | * Initialize secure copy of GIC at EL3. |
| 21 | * |
| 22 | *************************************************************************/ |
| 23 | ENTRY(gic_init_secure) |
| 24 | /* |
| 25 | * Initialize Distributor |
| 26 | * x0: Distributor Base |
| 27 | */ |
| 28 | #if defined(CONFIG_GICV3) |
| 29 | mov w9, #0x37 /* EnableGrp0 | EnableGrp1NS */ |
| 30 | /* EnableGrp1S | ARE_S | ARE_NS */ |
| 31 | str w9, [x0, GICD_CTLR] /* Secure GICD_CTLR */ |
| 32 | ldr w9, [x0, GICD_TYPER] |
| 33 | and w10, w9, #0x1f /* ITLinesNumber */ |
| 34 | cbz w10, 1f /* No SPIs */ |
| 35 | add x11, x0, (GICD_IGROUPRn + 4) |
| 36 | add x12, x0, (GICD_IGROUPMODRn + 4) |
| 37 | mov w9, #~0 |
| 38 | 0: str w9, [x11], #0x4 |
| 39 | str wzr, [x12], #0x4 /* Config SPIs as Group1NS */ |
| 40 | sub w10, w10, #0x1 |
| 41 | cbnz w10, 0b |
| 42 | #elif defined(CONFIG_GICV2) |
Sai Pavan Boddu | bd3fd0c | 2022-05-11 10:39:07 +0200 | [diff] [blame] | 43 | switch_el x1, 2f, 1f, 1f |
| 44 | 2: |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 45 | mov w9, #0x3 /* EnableGrp0 | EnableGrp1 */ |
| 46 | str w9, [x0, GICD_CTLR] /* Secure GICD_CTLR */ |
| 47 | ldr w9, [x0, GICD_TYPER] |
| 48 | and w10, w9, #0x1f /* ITLinesNumber */ |
| 49 | cbz w10, 1f /* No SPIs */ |
Thierry Reding | da1a904 | 2015-08-20 11:52:15 +0200 | [diff] [blame] | 50 | add x11, x0, GICD_IGROUPRn |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 51 | mov w9, #~0 /* Config SPIs as Grp1 */ |
Thierry Reding | da1a904 | 2015-08-20 11:52:15 +0200 | [diff] [blame] | 52 | str w9, [x11], #0x4 |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 53 | 0: str w9, [x11], #0x4 |
| 54 | sub w10, w10, #0x1 |
| 55 | cbnz w10, 0b |
Thierry Reding | da1a904 | 2015-08-20 11:52:15 +0200 | [diff] [blame] | 56 | |
| 57 | ldr x1, =GICC_BASE /* GICC_CTLR */ |
| 58 | mov w0, #3 /* EnableGrp0 | EnableGrp1 */ |
| 59 | str w0, [x1] |
| 60 | |
| 61 | mov w0, #1 << 7 /* allow NS access to GICC_PMR */ |
| 62 | str w0, [x1, #4] /* GICC_PMR */ |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 63 | #endif |
| 64 | 1: |
| 65 | ret |
| 66 | ENDPROC(gic_init_secure) |
| 67 | |
| 68 | |
| 69 | /************************************************************************* |
| 70 | * For Gicv2: |
| 71 | * void gic_init_secure_percpu(DistributorBase, CpuInterfaceBase); |
| 72 | * For Gicv3: |
| 73 | * void gic_init_secure_percpu(ReDistributorBase); |
| 74 | * |
| 75 | * Initialize secure copy of GIC at EL3. |
| 76 | * |
| 77 | *************************************************************************/ |
| 78 | ENTRY(gic_init_secure_percpu) |
| 79 | #if defined(CONFIG_GICV3) |
| 80 | /* |
| 81 | * Initialize ReDistributor |
| 82 | * x0: ReDistributor Base |
| 83 | */ |
| 84 | mrs x10, mpidr_el1 |
| 85 | lsr x9, x10, #32 |
| 86 | bfi x10, x9, #24, #8 /* w10 is aff3:aff2:aff1:aff0 */ |
| 87 | mov x9, x0 |
| 88 | 1: ldr x11, [x9, GICR_TYPER] |
| 89 | lsr x11, x11, #32 /* w11 is aff3:aff2:aff1:aff0 */ |
| 90 | cmp w10, w11 |
| 91 | b.eq 2f |
| 92 | add x9, x9, #(2 << 16) |
| 93 | b 1b |
| 94 | |
| 95 | /* x9: ReDistributor Base Address of Current CPU */ |
| 96 | 2: mov w10, #~0x2 |
| 97 | ldr w11, [x9, GICR_WAKER] |
| 98 | and w11, w11, w10 /* Clear ProcessorSleep */ |
| 99 | str w11, [x9, GICR_WAKER] |
| 100 | dsb st |
| 101 | isb |
| 102 | 3: ldr w10, [x9, GICR_WAKER] |
| 103 | tbnz w10, #2, 3b /* Wait Children be Alive */ |
| 104 | |
| 105 | add x10, x9, #(1 << 16) /* SGI_Base */ |
| 106 | mov w11, #~0 |
| 107 | str w11, [x10, GICR_IGROUPRn] |
| 108 | str wzr, [x10, GICR_IGROUPMODRn] /* SGIs|PPIs Group1NS */ |
| 109 | mov w11, #0x1 /* Enable SGI 0 */ |
| 110 | str w11, [x10, GICR_ISENABLERn] |
| 111 | |
Michal Simek | 1d10cc6 | 2017-09-07 09:20:32 +0200 | [diff] [blame] | 112 | switch_el x10, 3f, 2f, 1f |
| 113 | 3: |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 114 | /* Initialize Cpu Interface */ |
| 115 | mrs x10, ICC_SRE_EL3 |
| 116 | orr x10, x10, #0xf /* SRE & Disable IRQ/FIQ Bypass & */ |
| 117 | /* Allow EL2 access to ICC_SRE_EL2 */ |
| 118 | msr ICC_SRE_EL3, x10 |
| 119 | isb |
| 120 | |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 121 | mov x10, #0x3 /* EnableGrp1NS | EnableGrp1S */ |
| 122 | msr ICC_IGRPEN1_EL3, x10 |
| 123 | isb |
| 124 | |
| 125 | msr ICC_CTLR_EL3, xzr |
| 126 | isb |
Michal Simek | 1d10cc6 | 2017-09-07 09:20:32 +0200 | [diff] [blame] | 127 | 2: |
| 128 | mrs x10, ICC_SRE_EL2 |
| 129 | orr x10, x10, #0xf /* SRE & Disable IRQ/FIQ Bypass & */ |
| 130 | /* Allow EL1 access to ICC_SRE_EL1 */ |
| 131 | msr ICC_SRE_EL2, x10 |
| 132 | isb |
| 133 | 1: |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 134 | msr ICC_CTLR_EL1, xzr /* NonSecure ICC_CTLR_EL1 */ |
| 135 | isb |
| 136 | |
| 137 | mov x10, #0x1 << 7 /* Non-Secure access to ICC_PMR_EL1 */ |
| 138 | msr ICC_PMR_EL1, x10 |
| 139 | isb |
| 140 | #elif defined(CONFIG_GICV2) |
| 141 | /* |
| 142 | * Initialize SGIs and PPIs |
| 143 | * x0: Distributor Base |
| 144 | * x1: Cpu Interface Base |
| 145 | */ |
Sai Pavan Boddu | bd3fd0c | 2022-05-11 10:39:07 +0200 | [diff] [blame] | 146 | switch_el x2, 4f, 5f, 5f |
| 147 | 4: |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 148 | mov w9, #~0 /* Config SGIs and PPIs as Grp1 */ |
| 149 | str w9, [x0, GICD_IGROUPRn] /* GICD_IGROUPR0 */ |
| 150 | mov w9, #0x1 /* Enable SGI 0 */ |
| 151 | str w9, [x0, GICD_ISENABLERn] |
| 152 | |
| 153 | /* Initialize Cpu Interface */ |
| 154 | mov w9, #0x1e7 /* Disable IRQ/FIQ Bypass & */ |
| 155 | /* Enable Ack Group1 Interrupt & */ |
| 156 | /* EnableGrp0 & EnableGrp1 */ |
| 157 | str w9, [x1, GICC_CTLR] /* Secure GICC_CTLR */ |
| 158 | |
| 159 | mov w9, #0x1 << 7 /* Non-Secure access to GICC_PMR */ |
| 160 | str w9, [x1, GICC_PMR] |
| 161 | #endif |
Sai Pavan Boddu | bd3fd0c | 2022-05-11 10:39:07 +0200 | [diff] [blame] | 162 | 5: |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 163 | ret |
| 164 | ENDPROC(gic_init_secure_percpu) |
| 165 | |
| 166 | |
| 167 | /************************************************************************* |
| 168 | * For Gicv2: |
| 169 | * void gic_kick_secondary_cpus(DistributorBase); |
| 170 | * For Gicv3: |
| 171 | * void gic_kick_secondary_cpus(void); |
| 172 | * |
| 173 | *************************************************************************/ |
| 174 | ENTRY(gic_kick_secondary_cpus) |
| 175 | #if defined(CONFIG_GICV3) |
| 176 | mov x9, #(1 << 40) |
| 177 | msr ICC_ASGI1R_EL1, x9 |
| 178 | isb |
| 179 | #elif defined(CONFIG_GICV2) |
| 180 | mov w9, #0x8000 |
| 181 | movk w9, #0x100, lsl #16 |
| 182 | str w9, [x0, GICD_SGIR] |
| 183 | #endif |
| 184 | ret |
| 185 | ENDPROC(gic_kick_secondary_cpus) |
| 186 | |
| 187 | |
| 188 | /************************************************************************* |
| 189 | * For Gicv2: |
| 190 | * void gic_wait_for_interrupt(CpuInterfaceBase); |
| 191 | * For Gicv3: |
| 192 | * void gic_wait_for_interrupt(void); |
| 193 | * |
| 194 | * Wait for SGI 0 from master. |
| 195 | * |
| 196 | *************************************************************************/ |
| 197 | ENTRY(gic_wait_for_interrupt) |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 198 | #if defined(CONFIG_GICV3) |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 199 | gic_wait_for_interrupt_m x9 |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 200 | #elif defined(CONFIG_GICV2) |
York Sun | 56cc3db | 2014-09-08 12:20:00 -0700 | [diff] [blame] | 201 | gic_wait_for_interrupt_m x0, w9 |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 202 | #endif |
David Feng | 79bbde0 | 2014-03-14 14:26:27 +0800 | [diff] [blame] | 203 | ret |
| 204 | ENDPROC(gic_wait_for_interrupt) |