blob: e46b15e24cb73cd79a9ba9e195e6841a1d58e399 [file] [log] [blame]
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +00001/*
2 * Copyright (c) 2015-2020, Arm Limited and Contributors. All rights reserved.
3 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7#include <arch.h>
8#include <arch_helpers.h>
9#include <common/debug.h>
10#include <common/interrupt_props.h>
11#include <drivers/arm/gicv3.h>
12#include "gicv3_private.h"
13
14/*******************************************************************************
15 * GIC Redistributor functions
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010016 * Note: The raw register values correspond to multiple interrupt `id`s and
17 * the number of interrupt `id`s involved depends on the register accessed.
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000018 ******************************************************************************/
19
20/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010021 * Accessor to set the byte corresponding to interrupt `id`
22 * in GIC Redistributor IPRIORITYR and IPRIORITYRE.
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000023 */
24void gicr_set_ipriorityr(uintptr_t base, unsigned int id, unsigned int pri)
25{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010026 GICR_WRITE_8(IPRIORITY, base, id, (uint8_t)(pri & GIC_PRI_MASK));
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000027}
28
29/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010030 * Accessors to get/set/clear the bit corresponding to interrupt `id`
31 * from GIC Redistributor IGROUPR0 and IGROUPRE
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000032 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010033unsigned int gicr_get_igroupr(uintptr_t base, unsigned int id)
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000034{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010035 return GICR_GET_BIT(IGROUP, base, id);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000036}
37
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010038void gicr_set_igroupr(uintptr_t base, unsigned int id)
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000039{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010040 GICR_SET_BIT(IGROUP, base, id);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000041}
42
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010043void gicr_clr_igroupr(uintptr_t base, unsigned int id)
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000044{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010045 GICR_CLR_BIT(IGROUP, base, id);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000046}
47
48/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010049 * Accessors to get/set/clear the bit corresponding to interrupt `id`
50 * from GIC Redistributor IGRPMODR0 and IGRPMODRE
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000051 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010052unsigned int gicr_get_igrpmodr(uintptr_t base, unsigned int id)
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000053{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010054 return GICR_GET_BIT(IGRPMOD, base, id);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000055}
56
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010057void gicr_set_igrpmodr(uintptr_t base, unsigned int id)
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000058{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010059 GICR_SET_BIT(IGRPMOD, base, id);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000060}
61
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010062void gicr_clr_igrpmodr(uintptr_t base, unsigned int id)
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000063{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010064 GICR_CLR_BIT(IGRPMOD, base, id);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000065}
66
67/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010068 * Accessor to write the bit corresponding to interrupt `id`
69 * in GIC Redistributor ISENABLER0 and ISENABLERE
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000070 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010071void gicr_set_isenabler(uintptr_t base, unsigned int id)
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000072{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010073 GICR_WRITE_BIT(ISENABLE, base, id);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000074}
75
76/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010077 * Accessor to write the bit corresponding to interrupt `id`
78 * in GIC Redistributor ICENABLER0 and ICENABLERE
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000079 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010080void gicr_set_icenabler(uintptr_t base, unsigned int id)
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000081{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010082 GICR_WRITE_BIT(ICENABLE, base, id);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000083}
84
85/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010086 * Accessor to get the bit corresponding to interrupt `id`
87 * in GIC Redistributor ISACTIVER0 and ISACTIVERE
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000088 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010089unsigned int gicr_get_isactiver(uintptr_t base, unsigned int id)
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000090{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010091 return GICR_GET_BIT(ISACTIVE, base, id);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000092}
93
94/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010095 * Accessor to clear the bit corresponding to interrupt `id`
96 * in GIC Redistributor ICPENDR0 and ICPENDRE
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000097 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +010098void gicr_set_icpendr(uintptr_t base, unsigned int id)
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +000099{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100100 GICR_WRITE_BIT(ICPEND, base, id);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000101}
102
103/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100104 * Accessor to write the bit corresponding to interrupt `id`
105 * in GIC Redistributor ISPENDR0 and ISPENDRE
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000106 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100107void gicr_set_ispendr(uintptr_t base, unsigned int id)
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000108{
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100109 GICR_WRITE_BIT(ISPEND, base, id);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000110}
111
112/*
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100113 * Accessor to set the bit fields corresponding to interrupt `id`
114 * in GIC Redistributor ICFGR0, ICFGR1 and ICFGRE
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000115 */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100116void gicr_set_icfgr(uintptr_t base, unsigned int id, unsigned int cfg)
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000117{
118 /* Interrupt configuration is a 2-bit field */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100119 unsigned int bit_shift = BIT_NUM(ICFG, id) << 1U;
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000120
121 /* Clear the field, and insert required configuration */
Alexei Fedorova6e6ae02020-04-06 16:27:54 +0100122 mmio_clrsetbits_32(base + GICR_OFFSET(ICFG, id),
123 (uint32_t)GIC_CFG_MASK << bit_shift,
124 (cfg & GIC_CFG_MASK) << bit_shift);
Alexei Fedorov2f13d6c2020-02-21 10:17:26 +0000125}