blob: c9e9cb98f573a04556e8b5a54813be4782092741 [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.
Varun Wadekar75594062020-07-05 13:12:28 -07003 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +00004 *
5 * SPDX-License-Identifier: BSD-3-Clause
6 */
7
8/*
Andre Przywarae1cc1302020-03-25 15:50:38 +00009 * Driver for GIC-500 and GIC-600 specific features. This driver only
10 * overrides APIs that are different to those generic ones in GICv3
11 * driver.
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000012 *
Alexei Fedorov88fba672019-07-31 13:24:22 +010013 * GIC-600 supports independently power-gating redistributor interface.
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000014 */
15
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000016#include <assert.h>
Antonio Nino Diaze0f90632018-12-14 00:18:21 +000017
18#include <arch_helpers.h>
19#include <drivers/arm/gicv3.h>
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000020
21#include "gicv3_private.h"
22
Alexei Fedorov88fba672019-07-31 13:24:22 +010023/* GIC-600 specific register offsets */
Varun Wadekar75594062020-07-05 13:12:28 -070024#define GICR_PWRR 0x24
25#define IIDR_MODEL_ARM_GIC_600 (0x0200043b)
26#define IIDR_MODEL_ARM_GIC_600AE (0x0300043b)
Andre Przywara19b2d4e2020-06-26 10:30:33 +010027#define IIDR_MODEL_ARM_GIC_CLAYTON (0x0400043b)
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000028
29/* GICR_PWRR fields */
Varun Wadekar75594062020-07-05 13:12:28 -070030#define PWRR_RDPD_SHIFT 0
31#define PWRR_RDAG_SHIFT 1
32#define PWRR_RDGPD_SHIFT 2
33#define PWRR_RDGPO_SHIFT 3
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000034
Varun Wadekar75594062020-07-05 13:12:28 -070035#define PWRR_RDPD (1 << PWRR_RDPD_SHIFT)
36#define PWRR_RDAG (1 << PWRR_RDAG_SHIFT)
37#define PWRR_RDGPD (1 << PWRR_RDGPD_SHIFT)
38#define PWRR_RDGPO (1 << PWRR_RDGPO_SHIFT)
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000039
Alexei Fedorov88fba672019-07-31 13:24:22 +010040/*
41 * Values to write to GICR_PWRR register to power redistributor
42 * for operating through the core (GICR_PWRR.RDAG = 0)
43 */
Varun Wadekar75594062020-07-05 13:12:28 -070044#define PWRR_ON (0 << PWRR_RDPD_SHIFT)
45#define PWRR_OFF (1 << PWRR_RDPD_SHIFT)
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000046
Andre Przywarae1cc1302020-03-25 15:50:38 +000047#if GICV3_SUPPORT_GIC600
48
Andre Przywara19b2d4e2020-06-26 10:30:33 +010049/* GIC-600/Clayton specific accessor functions */
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000050static void gicr_write_pwrr(uintptr_t base, unsigned int val)
51{
Douglas Raillard1bd2d742017-08-03 15:59:49 +010052 mmio_write_32(base + GICR_PWRR, val);
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000053}
54
55static uint32_t gicr_read_pwrr(uintptr_t base)
56{
Douglas Raillard1bd2d742017-08-03 15:59:49 +010057 return mmio_read_32(base + GICR_PWRR);
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000058}
59
Alexei Fedorov88fba672019-07-31 13:24:22 +010060static void gicr_wait_group_not_in_transit(uintptr_t base)
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000061{
Alexei Fedorov88fba672019-07-31 13:24:22 +010062 /* Check group not transitioning: RDGPD == RDGPO */
63 while (((gicr_read_pwrr(base) & PWRR_RDGPD) >> PWRR_RDGPD_SHIFT) !=
64 ((gicr_read_pwrr(base) & PWRR_RDGPO) >> PWRR_RDGPO_SHIFT))
65 ;
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000066}
67
68static void gic600_pwr_on(uintptr_t base)
69{
Alexei Fedorov88fba672019-07-31 13:24:22 +010070 do { /* Wait until group not transitioning */
71 gicr_wait_group_not_in_transit(base);
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000072
Alexei Fedorov88fba672019-07-31 13:24:22 +010073 /* Power on redistributor */
74 gicr_write_pwrr(base, PWRR_ON);
75
76 /*
77 * Wait until the power on state is reflected.
78 * If RDPD == 0 then powered on.
79 */
80 } while ((gicr_read_pwrr(base) & PWRR_RDPD) != PWRR_ON);
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000081}
82
83static void gic600_pwr_off(uintptr_t base)
84{
Alexei Fedorov88fba672019-07-31 13:24:22 +010085 /* Wait until group not transitioning */
86 gicr_wait_group_not_in_transit(base);
87
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000088 /* Power off redistributor */
89 gicr_write_pwrr(base, PWRR_OFF);
90
91 /*
92 * If this is the last man, turning this redistributor frame off will
Alexei Fedorov88fba672019-07-31 13:24:22 +010093 * result in the group itself being powered off and RDGPD = 1.
94 * In that case, wait as long as it's in transition, or has aborted
95 * the transition altogether for any reason.
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +000096 */
Alexei Fedorov88fba672019-07-31 13:24:22 +010097 if ((gicr_read_pwrr(base) & PWRR_RDGPD) != 0) {
98 /* Wait until group not transitioning */
99 gicr_wait_group_not_in_transit(base);
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +0000100 }
101}
102
Andre Przywarae1cc1302020-03-25 15:50:38 +0000103static uintptr_t get_gicr_base(unsigned int proc_num)
104{
105 uintptr_t gicr_base;
106
107 assert(gicv3_driver_data);
108 assert(proc_num < gicv3_driver_data->rdistif_num);
109 assert(gicv3_driver_data->rdistif_base_addrs);
110
111 gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num];
112 assert(gicr_base);
113
114 return gicr_base;
115}
116
Andre Przywara19b2d4e2020-06-26 10:30:33 +0100117static bool gicv3_redists_need_power_mgmt(uintptr_t gicr_base)
Andre Przywarae1cc1302020-03-25 15:50:38 +0000118{
119 uint32_t reg = mmio_read_32(gicr_base + GICR_IIDR);
120
Andre Przywara19b2d4e2020-06-26 10:30:33 +0100121 /*
122 * The Arm GIC-600 and GIC-Clayton models have their redistributors
123 * powered down at reset.
124 */
Varun Wadekar75594062020-07-05 13:12:28 -0700125 return (((reg & IIDR_MODEL_MASK) == IIDR_MODEL_ARM_GIC_600) ||
Andre Przywara19b2d4e2020-06-26 10:30:33 +0100126 ((reg & IIDR_MODEL_MASK) == IIDR_MODEL_ARM_GIC_600AE) ||
127 ((reg & IIDR_MODEL_MASK) == IIDR_MODEL_ARM_GIC_CLAYTON));
Andre Przywarae1cc1302020-03-25 15:50:38 +0000128}
129
130#endif
131
Soby Mathew327548c2017-07-13 15:19:51 +0100132void gicv3_distif_pre_save(unsigned int proc_num)
133{
134 arm_gicv3_distif_pre_save(proc_num);
135}
136
137void gicv3_distif_post_restore(unsigned int proc_num)
138{
139 arm_gicv3_distif_post_restore(proc_num);
140}
141
Andre Przywarae1cc1302020-03-25 15:50:38 +0000142
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +0000143/*
Andre Przywarae1cc1302020-03-25 15:50:38 +0000144 * Power off GIC-600 redistributor (if configured and detected)
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +0000145 */
146void gicv3_rdistif_off(unsigned int proc_num)
147{
Andre Przywarae1cc1302020-03-25 15:50:38 +0000148#if GICV3_SUPPORT_GIC600
149 uintptr_t gicr_base = get_gicr_base(proc_num);
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +0000150
151 /* Attempt to power redistributor off */
Andre Przywara19b2d4e2020-06-26 10:30:33 +0100152 if (gicv3_redists_need_power_mgmt(gicr_base)) {
Andre Przywarae1cc1302020-03-25 15:50:38 +0000153 gic600_pwr_off(gicr_base);
154 }
155#endif
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +0000156}
157
158/*
Andre Przywarae1cc1302020-03-25 15:50:38 +0000159 * Power on GIC-600 redistributor (if configured and detected)
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +0000160 */
161void gicv3_rdistif_on(unsigned int proc_num)
162{
Andre Przywarae1cc1302020-03-25 15:50:38 +0000163#if GICV3_SUPPORT_GIC600
164 uintptr_t gicr_base = get_gicr_base(proc_num);
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +0000165
166 /* Power redistributor on */
Andre Przywara19b2d4e2020-06-26 10:30:33 +0100167 if (gicv3_redists_need_power_mgmt(gicr_base)) {
Andre Przywarae1cc1302020-03-25 15:50:38 +0000168 gic600_pwr_on(gicr_base);
169 }
170#endif
Jeenu Viswambharand7a901e2016-12-06 16:15:22 +0000171}