gic-x00.c 4.19 KB
Newer Older
1
/*
2
 * Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
3
 * Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
4
5
6
7
8
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

/*
9
10
11
 * Driver for GIC-500 and GIC-600 specific features. This driver only
 * overrides APIs that are different to those generic ones in GICv3
 * driver.
12
 *
13
 * GIC-600 supports independently power-gating redistributor interface.
14
15
16
 */

#include <assert.h>
17
18
19

#include <arch_helpers.h>
#include <drivers/arm/gicv3.h>
20
21
22

#include "gicv3_private.h"

23
/* GIC-600 specific register offsets */
24
25
26
#define GICR_PWRR			0x24
#define IIDR_MODEL_ARM_GIC_600		(0x0200043b)
#define IIDR_MODEL_ARM_GIC_600AE	(0x0300043b)
27
#define IIDR_MODEL_ARM_GIC_CLAYTON	(0x0400043b)
28
29

/* GICR_PWRR fields */
30
31
32
33
#define PWRR_RDPD_SHIFT			0
#define PWRR_RDAG_SHIFT			1
#define PWRR_RDGPD_SHIFT		2
#define PWRR_RDGPO_SHIFT		3
34

35
36
37
38
#define PWRR_RDPD			(1 << PWRR_RDPD_SHIFT)
#define PWRR_RDAG			(1 << PWRR_RDAG_SHIFT)
#define PWRR_RDGPD			(1 << PWRR_RDGPD_SHIFT)
#define PWRR_RDGPO			(1 << PWRR_RDGPO_SHIFT)
39

40
41
42
43
/*
 * Values to write to GICR_PWRR register to power redistributor
 * for operating through the core (GICR_PWRR.RDAG = 0)
 */
44
45
#define PWRR_ON				(0 << PWRR_RDPD_SHIFT)
#define PWRR_OFF			(1 << PWRR_RDPD_SHIFT)
46

47
48
#if GICV3_SUPPORT_GIC600

49
/* GIC-600/Clayton specific accessor functions */
50
51
static void gicr_write_pwrr(uintptr_t base, unsigned int val)
{
52
	mmio_write_32(base + GICR_PWRR, val);
53
54
55
56
}

static uint32_t gicr_read_pwrr(uintptr_t base)
{
57
	return mmio_read_32(base + GICR_PWRR);
58
59
}

60
static void gicr_wait_group_not_in_transit(uintptr_t base)
61
{
62
63
64
65
	/* Check group not transitioning: RDGPD == RDGPO */
	while (((gicr_read_pwrr(base) & PWRR_RDGPD) >> PWRR_RDGPD_SHIFT) !=
		((gicr_read_pwrr(base) & PWRR_RDGPO) >> PWRR_RDGPO_SHIFT))
		;
66
67
68
69
}

static void gic600_pwr_on(uintptr_t base)
{
70
71
	do {	/* Wait until group not transitioning */
		gicr_wait_group_not_in_transit(base);
72

73
74
75
76
77
78
79
80
		/* Power on redistributor */
		gicr_write_pwrr(base, PWRR_ON);

		/*
		 * Wait until the power on state is reflected.
		 * If RDPD == 0 then powered on.
		 */
	} while ((gicr_read_pwrr(base) & PWRR_RDPD) != PWRR_ON);
81
82
83
84
}

static void gic600_pwr_off(uintptr_t base)
{
85
86
87
	/* Wait until group not transitioning */
	gicr_wait_group_not_in_transit(base);

88
89
90
91
92
	/* Power off redistributor */
	gicr_write_pwrr(base, PWRR_OFF);

	/*
	 * If this is the last man, turning this redistributor frame off will
93
94
95
	 * result in the group itself being powered off and RDGPD = 1.
	 * In that case, wait as long as it's in transition, or has aborted
	 * the transition altogether for any reason.
96
	 */
97
98
99
	if ((gicr_read_pwrr(base) & PWRR_RDGPD) != 0) {
		/* Wait until group not transitioning */
		gicr_wait_group_not_in_transit(base);
100
101
102
	}
}

103
104
105
106
107
108
109
110
111
112
113
114
115
116
static uintptr_t get_gicr_base(unsigned int proc_num)
{
	uintptr_t gicr_base;

	assert(gicv3_driver_data);
	assert(proc_num < gicv3_driver_data->rdistif_num);
	assert(gicv3_driver_data->rdistif_base_addrs);

	gicr_base = gicv3_driver_data->rdistif_base_addrs[proc_num];
	assert(gicr_base);

	return gicr_base;
}

117
static bool gicv3_redists_need_power_mgmt(uintptr_t gicr_base)
118
119
120
{
	uint32_t reg = mmio_read_32(gicr_base + GICR_IIDR);

121
122
123
124
	/*
	 * The Arm GIC-600 and GIC-Clayton models have their redistributors
	 * powered down at reset.
	 */
125
	return (((reg & IIDR_MODEL_MASK) == IIDR_MODEL_ARM_GIC_600) ||
126
127
		((reg & IIDR_MODEL_MASK) == IIDR_MODEL_ARM_GIC_600AE) ||
		((reg & IIDR_MODEL_MASK) == IIDR_MODEL_ARM_GIC_CLAYTON));
128
129
130
131
}

#endif

132
133
134
135
136
137
138
139
140
141
void gicv3_distif_pre_save(unsigned int proc_num)
{
	arm_gicv3_distif_pre_save(proc_num);
}

void gicv3_distif_post_restore(unsigned int proc_num)
{
	arm_gicv3_distif_post_restore(proc_num);
}

142

143
/*
144
 * Power off GIC-600 redistributor (if configured and detected)
145
146
147
 */
void gicv3_rdistif_off(unsigned int proc_num)
{
148
149
#if GICV3_SUPPORT_GIC600
	uintptr_t gicr_base = get_gicr_base(proc_num);
150
151

	/* Attempt to power redistributor off */
152
	if (gicv3_redists_need_power_mgmt(gicr_base)) {
153
154
155
		gic600_pwr_off(gicr_base);
	}
#endif
156
157
158
}

/*
159
 * Power on GIC-600 redistributor (if configured and detected)
160
161
162
 */
void gicv3_rdistif_on(unsigned int proc_num)
{
163
164
#if GICV3_SUPPORT_GIC600
	uintptr_t gicr_base = get_gicr_base(proc_num);
165
166

	/* Power redistributor on */
167
	if (gicv3_redists_need_power_mgmt(gicr_base)) {
168
169
170
		gic600_pwr_on(gicr_base);
	}
#endif
171
}