blob: 59652da634da8a72e63365883fc7a6380bfc7607 [file] [log] [blame]
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +00001/*
Alexei Fedorov88fba672019-07-31 13:24:22 +01002 * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +00003 *
4 * SPDX-License-Identifier: BSD-3-Clause
5 */
6
7/*
Alexei Fedorov88fba672019-07-31 13:24:22 +01008 * Driver for GIC-600 specific features. This driver only overrides
9 * APIs that are different to those generic ones in GICv3 driver.
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000010 *
Alexei Fedorov88fba672019-07-31 13:24:22 +010011 * GIC-600 supports independently power-gating redistributor interface.
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000012 */
13
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000014#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000015
16#include <arch_helpers.h>
17#include <drivers/arm/gicv3.h>
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000018
19#include "gicv3_private.h"
20
Alexei Fedorov88fba672019-07-31 13:24:22 +010021/* GIC-600 specific register offsets */
Douglas Raillard1bd2d742017-08-03 15:59:49 +010022#define GICR_PWRR 0x24
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000023
24/* GICR_PWRR fields */
25#define PWRR_RDPD_SHIFT 0
Alexei Fedorov88fba672019-07-31 13:24:22 +010026#define PWRR_RDAG_SHIFT 1
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000027#define PWRR_RDGPD_SHIFT 2
28#define PWRR_RDGPO_SHIFT 3
29
Alexei Fedorov88fba672019-07-31 13:24:22 +010030#define PWRR_RDPD (1 << PWRR_RDPD_SHIFT)
31#define PWRR_RDAG (1 << PWRR_RDAG_SHIFT)
Douglas Raillard1bd2d742017-08-03 15:59:49 +010032#define PWRR_RDGPD (1 << PWRR_RDGPD_SHIFT)
33#define PWRR_RDGPO (1 << PWRR_RDGPO_SHIFT)
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000034
Alexei Fedorov88fba672019-07-31 13:24:22 +010035/*
36 * Values to write to GICR_PWRR register to power redistributor
37 * for operating through the core (GICR_PWRR.RDAG = 0)
38 */
Douglas Raillard1bd2d742017-08-03 15:59:49 +010039#define PWRR_ON (0 << PWRR_RDPD_SHIFT)
40#define PWRR_OFF (1 << PWRR_RDPD_SHIFT)
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000041
Alexei Fedorov88fba672019-07-31 13:24:22 +010042/* GIC-600 specific accessor functions */
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000043static void gicr_write_pwrr(uintptr_t base, unsigned int val)
44{
Douglas Raillard1bd2d742017-08-03 15:59:49 +010045 mmio_write_32(base + GICR_PWRR, val);
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000046}
47
48static uint32_t gicr_read_pwrr(uintptr_t base)
49{
Douglas Raillard1bd2d742017-08-03 15:59:49 +010050 return mmio_read_32(base + GICR_PWRR);
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000051}
52
Alexei Fedorov88fba672019-07-31 13:24:22 +010053static void gicr_wait_group_not_in_transit(uintptr_t base)
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000054{
Alexei Fedorov88fba672019-07-31 13:24:22 +010055 /* Check group not transitioning: RDGPD == RDGPO */
56 while (((gicr_read_pwrr(base) & PWRR_RDGPD) >> PWRR_RDGPD_SHIFT) !=
57 ((gicr_read_pwrr(base) & PWRR_RDGPO) >> PWRR_RDGPO_SHIFT))
58 ;
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000059}
60
61static void gic600_pwr_on(uintptr_t base)
62{
Alexei Fedorov88fba672019-07-31 13:24:22 +010063 do { /* Wait until group not transitioning */
64 gicr_wait_group_not_in_transit(base);
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000065
Alexei Fedorov88fba672019-07-31 13:24:22 +010066 /* Power on redistributor */
67 gicr_write_pwrr(base, PWRR_ON);
68
69 /*
70 * Wait until the power on state is reflected.
71 * If RDPD == 0 then powered on.
72 */
73 } while ((gicr_read_pwrr(base) & PWRR_RDPD) != PWRR_ON);
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000074}
75
76static void gic600_pwr_off(uintptr_t base)
77{
Alexei Fedorov88fba672019-07-31 13:24:22 +010078 /* Wait until group not transitioning */
79 gicr_wait_group_not_in_transit(base);
80
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000081 /* Power off redistributor */
82 gicr_write_pwrr(base, PWRR_OFF);
83
84 /*
85 * If this is the last man, turning this redistributor frame off will
Alexei Fedorov88fba672019-07-31 13:24:22 +010086 * result in the group itself being powered off and RDGPD = 1.
87 * In that case, wait as long as it's in transition, or has aborted
88 * the transition altogether for any reason.
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000089 */
Alexei Fedorov88fba672019-07-31 13:24:22 +010090 if ((gicr_read_pwrr(base) & PWRR_RDGPD) != 0) {
91 /* Wait until group not transitioning */
92 gicr_wait_group_not_in_transit(base);
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000093 }
94}
95
Soby Mathew327548c2017-07-13 15:19:51 +010096void gicv3_distif_pre_save(unsigned int proc_num)
97{
98 arm_gicv3_distif_pre_save(proc_num);
99}
100
101void gicv3_distif_post_restore(unsigned int proc_num)
102{
103 arm_gicv3_distif_post_restore(proc_num);
104}
105
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +0000106/*
Alexei Fedorov88fba672019-07-31 13:24:22 +0100107 * Power off GIC-600 redistributor
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +0000108 */
109void gicv3_rdistif_off(unsigned int proc_num)
110{
111 uintptr_t gicr_base;
112
113 assert(gicv3_driver_data);
114 assert(proc_num < gicv3_driver_data->rdistif_num);
115 assert(gicv3_driver_data->rdistif_base_addrs);
116
117 gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num];
118 assert(gicr_base);
119
120 /* Attempt to power redistributor off */
121 gic600_pwr_off(gicr_base);
122}
123
124/*
Alexei Fedorov88fba672019-07-31 13:24:22 +0100125 * Power on GIC-600 redistributor
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +0000126 */
127void gicv3_rdistif_on(unsigned int proc_num)
128{
129 uintptr_t gicr_base;
130
131 assert(gicv3_driver_data);
132 assert(proc_num < gicv3_driver_data->rdistif_num);
133 assert(gicv3_driver_data->rdistif_base_addrs);
134
135 gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num];
136 assert(gicr_base);
137
138 /* Power redistributor on */
139 gic600_pwr_on(gicr_base);
140}