Varun Wadekar | b316e24 | 2015-05-19 16:48:04 +0530 | [diff] [blame] | 1 | /* |
| 2 | * Copyright (c) 2015, ARM Limited and Contributors. All rights reserved. |
| 3 | * |
| 4 | * Redistribution and use in source and binary forms, with or without |
| 5 | * modification, are permitted provided that the following conditions are met: |
| 6 | * |
| 7 | * Redistributions of source code must retain the above copyright notice, this |
| 8 | * list of conditions and the following disclaimer. |
| 9 | * |
| 10 | * Redistributions in binary form must reproduce the above copyright notice, |
| 11 | * this list of conditions and the following disclaimer in the documentation |
| 12 | * and/or other materials provided with the distribution. |
| 13 | * |
| 14 | * Neither the name of ARM nor the names of its contributors may be used |
| 15 | * to endorse or promote products derived from this software without specific |
| 16 | * prior written permission. |
| 17 | * |
| 18 | * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
| 19 | * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
| 20 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
| 21 | * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
| 22 | * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
| 23 | * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
| 24 | * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
| 25 | * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN |
| 26 | * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) |
| 27 | * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE |
| 28 | * POSSIBILITY OF SUCH DAMAGE. |
| 29 | */ |
| 30 | |
| 31 | #include <arch_helpers.h> |
| 32 | #include <assert.h> |
| 33 | #include <bl_common.h> |
| 34 | #include <debug.h> |
| 35 | #include <gic_v2.h> |
| 36 | #include <interrupt_mgmt.h> |
| 37 | #include <platform.h> |
| 38 | #include <stdint.h> |
| 39 | #include <tegra_private.h> |
| 40 | #include <tegra_def.h> |
| 41 | |
| 42 | /******************************************************************************* |
| 43 | * Place the cpu interface in a state where it can never make a cpu exit wfi as |
| 44 | * as result of an asserted interrupt. This is critical for powering down a cpu |
| 45 | ******************************************************************************/ |
| 46 | void tegra_gic_cpuif_deactivate(void) |
| 47 | { |
| 48 | unsigned int val; |
| 49 | |
| 50 | /* Disable secure, non-secure interrupts and disable their bypass */ |
| 51 | val = gicc_read_ctlr(TEGRA_GICC_BASE); |
| 52 | val &= ~(ENABLE_GRP0 | ENABLE_GRP1); |
| 53 | val |= FIQ_BYP_DIS_GRP1 | FIQ_BYP_DIS_GRP0; |
| 54 | val |= IRQ_BYP_DIS_GRP0 | IRQ_BYP_DIS_GRP1; |
| 55 | gicc_write_ctlr(TEGRA_GICC_BASE, val); |
| 56 | } |
| 57 | |
| 58 | /******************************************************************************* |
| 59 | * Enable secure interrupts and set the priority mask register to allow all |
| 60 | * interrupts to trickle in. |
| 61 | ******************************************************************************/ |
| 62 | static void tegra_gic_cpuif_setup(unsigned int gicc_base) |
| 63 | { |
| 64 | gicc_write_ctlr(gicc_base, ENABLE_GRP0 | ENABLE_GRP1); |
| 65 | gicc_write_pmr(gicc_base, GIC_PRI_MASK); |
| 66 | } |
| 67 | |
| 68 | /******************************************************************************* |
| 69 | * Global gic distributor setup which will be done by the primary cpu after a |
| 70 | * cold boot. It marks out the non secure SPIs, PPIs & SGIs and enables them. |
| 71 | * It then enables the secure GIC distributor interface. |
| 72 | ******************************************************************************/ |
| 73 | static void tegra_gic_distif_setup(unsigned int gicd_base) |
| 74 | { |
| 75 | unsigned int ctr, num_ints; |
| 76 | |
| 77 | /* |
| 78 | * Mark out non-secure interrupts. Calculate number of |
| 79 | * IGROUPR registers to consider. Will be equal to the |
| 80 | * number of IT_LINES |
| 81 | */ |
| 82 | num_ints = gicd_read_typer(gicd_base) & IT_LINES_NO_MASK; |
| 83 | num_ints++; |
| 84 | for (ctr = 0; ctr < num_ints; ctr++) |
| 85 | gicd_write_igroupr(gicd_base, ctr << IGROUPR_SHIFT, ~0); |
| 86 | |
| 87 | /* enable distributor */ |
| 88 | gicd_write_ctlr(gicd_base, ENABLE_GRP0 | ENABLE_GRP1); |
| 89 | } |
| 90 | |
| 91 | void tegra_gic_setup(void) |
| 92 | { |
| 93 | tegra_gic_cpuif_setup(TEGRA_GICC_BASE); |
| 94 | tegra_gic_distif_setup(TEGRA_GICD_BASE); |
| 95 | } |