gic600.c 2.79 KB
Newer Older
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
/*
 * Copyright (c) 2017, ARM Limited and Contributors. All rights reserved.
 *
 * SPDX-License-Identifier: BSD-3-Clause
 */

/*
 * Driver for GIC600-specific features. This driver only overrides APIs that are
 * different to those generic ones in GICv3 driver.
 *
 * GIC600 supports independently power-gating redistributor interface.
 */

#include <arch_helpers.h>
#include <assert.h>
#include <gicv3.h>

#include "gicv3_private.h"

/* GIC600-specific register offsets */
21
#define GICR_PWRR	0x24
22
23
24
25
26
27

/* GICR_PWRR fields */
#define PWRR_RDPD_SHIFT		0
#define PWRR_RDGPD_SHIFT	2
#define PWRR_RDGPO_SHIFT	3

28
29
#define PWRR_RDGPD	(1 << PWRR_RDGPD_SHIFT)
#define PWRR_RDGPO	(1 << PWRR_RDGPO_SHIFT)
30
31

/* Values to write to GICR_PWRR register to power redistributor */
32
33
#define PWRR_ON		(0 << PWRR_RDPD_SHIFT)
#define PWRR_OFF	(1 << PWRR_RDPD_SHIFT)
34
35
36
37
38
39
40

/* Generic GICv3 resources */
extern const gicv3_driver_data_t *gicv3_driver_data;

/* GIC600-specific accessor functions */
static void gicr_write_pwrr(uintptr_t base, unsigned int val)
{
41
	mmio_write_32(base + GICR_PWRR, val);
42
43
44
45
}

static uint32_t gicr_read_pwrr(uintptr_t base)
{
46
	return mmio_read_32(base + GICR_PWRR);
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
}

static int gicr_group_powering_down(uint32_t pwrr)
{
	/*
	 * Whether the redistributor group power down operation is in transit:
	 * i.e. it's intending to, but not finished yet.
	 */
	return ((pwrr & PWRR_RDGPD) && !(pwrr & PWRR_RDGPO));
}

static void gic600_pwr_on(uintptr_t base)
{
	/* Power on redistributor */
	gicr_write_pwrr(base, PWRR_ON);

	/* Wait until the power on state is reflected */
	while (gicr_read_pwrr(base) & PWRR_RDGPO)
		;
}

static void gic600_pwr_off(uintptr_t base)
{
	/* Power off redistributor */
	gicr_write_pwrr(base, PWRR_OFF);

	/*
	 * If this is the last man, turning this redistributor frame off will
	 * result in the group itself being powered off. In that case, wait as
	 * long as it's in transition, or has aborted the transition altogether
	 * for any reason.
	 */
	if (gicr_read_pwrr(base) & PWRR_RDGPD) {
		while (gicr_group_powering_down(gicr_read_pwrr(base)))
			;
	}
}

/*
 * Power off GIC600 redistributor
 */
void gicv3_rdistif_off(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);

	/* Attempt to power redistributor off */
	gic600_pwr_off(gicr_base);
}

/*
 * Power on GIC600 redistributor
 */
void gicv3_rdistif_on(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);

	/* Power redistributor on */
	gic600_pwr_on(gicr_base);
}