2016-12-06 16:15:22 +00:00
|
|
|
/*
|
2019-07-31 13:24:22 +01:00
|
|
|
* Copyright (c) 2017-2019, ARM Limited and Contributors. All rights reserved.
|
2020-07-05 21:12:28 +01:00
|
|
|
* Copyright (c) 2020, NVIDIA Corporation. All rights reserved.
|
2016-12-06 16:15:22 +00:00
|
|
|
*
|
|
|
|
* SPDX-License-Identifier: BSD-3-Clause
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
2020-03-25 15:50:38 +00:00
|
|
|
* Driver for GIC-500 and GIC-600 specific features. This driver only
|
|
|
|
* overrides APIs that are different to those generic ones in GICv3
|
|
|
|
* driver.
|
2016-12-06 16:15:22 +00:00
|
|
|
*
|
2019-07-31 13:24:22 +01:00
|
|
|
* GIC-600 supports independently power-gating redistributor interface.
|
2016-12-06 16:15:22 +00:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include <assert.h>
|
2018-12-14 00:18:21 +00:00
|
|
|
|
|
|
|
#include <arch_helpers.h>
|
|
|
|
#include <drivers/arm/gicv3.h>
|
2016-12-06 16:15:22 +00:00
|
|
|
|
|
|
|
#include "gicv3_private.h"
|
|
|
|
|
2019-07-31 13:24:22 +01:00
|
|
|
/* GIC-600 specific register offsets */
|
2020-07-05 21:12:28 +01:00
|
|
|
#define GICR_PWRR 0x24
|
|
|
|
#define IIDR_MODEL_ARM_GIC_600 (0x0200043b)
|
|
|
|
#define IIDR_MODEL_ARM_GIC_600AE (0x0300043b)
|
2016-12-06 16:15:22 +00:00
|
|
|
|
|
|
|
/* GICR_PWRR fields */
|
2020-07-05 21:12:28 +01:00
|
|
|
#define PWRR_RDPD_SHIFT 0
|
|
|
|
#define PWRR_RDAG_SHIFT 1
|
|
|
|
#define PWRR_RDGPD_SHIFT 2
|
|
|
|
#define PWRR_RDGPO_SHIFT 3
|
2016-12-06 16:15:22 +00:00
|
|
|
|
2020-07-05 21:12:28 +01:00
|
|
|
#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)
|
2016-12-06 16:15:22 +00:00
|
|
|
|
2019-07-31 13:24:22 +01:00
|
|
|
/*
|
|
|
|
* Values to write to GICR_PWRR register to power redistributor
|
|
|
|
* for operating through the core (GICR_PWRR.RDAG = 0)
|
|
|
|
*/
|
2020-07-05 21:12:28 +01:00
|
|
|
#define PWRR_ON (0 << PWRR_RDPD_SHIFT)
|
|
|
|
#define PWRR_OFF (1 << PWRR_RDPD_SHIFT)
|
2016-12-06 16:15:22 +00:00
|
|
|
|
2020-03-25 15:50:38 +00:00
|
|
|
#if GICV3_SUPPORT_GIC600
|
|
|
|
|
2019-07-31 13:24:22 +01:00
|
|
|
/* GIC-600 specific accessor functions */
|
2016-12-06 16:15:22 +00:00
|
|
|
static void gicr_write_pwrr(uintptr_t base, unsigned int val)
|
|
|
|
{
|
2017-08-03 15:59:49 +01:00
|
|
|
mmio_write_32(base + GICR_PWRR, val);
|
2016-12-06 16:15:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static uint32_t gicr_read_pwrr(uintptr_t base)
|
|
|
|
{
|
2017-08-03 15:59:49 +01:00
|
|
|
return mmio_read_32(base + GICR_PWRR);
|
2016-12-06 16:15:22 +00:00
|
|
|
}
|
|
|
|
|
2019-07-31 13:24:22 +01:00
|
|
|
static void gicr_wait_group_not_in_transit(uintptr_t base)
|
2016-12-06 16:15:22 +00:00
|
|
|
{
|
2019-07-31 13:24:22 +01:00
|
|
|
/* 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))
|
|
|
|
;
|
2016-12-06 16:15:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gic600_pwr_on(uintptr_t base)
|
|
|
|
{
|
2019-07-31 13:24:22 +01:00
|
|
|
do { /* Wait until group not transitioning */
|
|
|
|
gicr_wait_group_not_in_transit(base);
|
2016-12-06 16:15:22 +00:00
|
|
|
|
2019-07-31 13:24:22 +01:00
|
|
|
/* 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);
|
2016-12-06 16:15:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
static void gic600_pwr_off(uintptr_t base)
|
|
|
|
{
|
2019-07-31 13:24:22 +01:00
|
|
|
/* Wait until group not transitioning */
|
|
|
|
gicr_wait_group_not_in_transit(base);
|
|
|
|
|
2016-12-06 16:15:22 +00:00
|
|
|
/* Power off redistributor */
|
|
|
|
gicr_write_pwrr(base, PWRR_OFF);
|
|
|
|
|
|
|
|
/*
|
|
|
|
* If this is the last man, turning this redistributor frame off will
|
2019-07-31 13:24:22 +01:00
|
|
|
* 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.
|
2016-12-06 16:15:22 +00:00
|
|
|
*/
|
2019-07-31 13:24:22 +01:00
|
|
|
if ((gicr_read_pwrr(base) & PWRR_RDGPD) != 0) {
|
|
|
|
/* Wait until group not transitioning */
|
|
|
|
gicr_wait_group_not_in_transit(base);
|
2016-12-06 16:15:22 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-03-25 15:50:38 +00:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
static bool gicv3_is_gic600(uintptr_t gicr_base)
|
|
|
|
{
|
|
|
|
uint32_t reg = mmio_read_32(gicr_base + GICR_IIDR);
|
|
|
|
|
2020-07-05 21:12:28 +01:00
|
|
|
return (((reg & IIDR_MODEL_MASK) == IIDR_MODEL_ARM_GIC_600) ||
|
|
|
|
((reg & IIDR_MODEL_MASK) == IIDR_MODEL_ARM_GIC_600AE));
|
2020-03-25 15:50:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
2017-07-13 15:19:51 +01:00
|
|
|
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);
|
|
|
|
}
|
|
|
|
|
2020-03-25 15:50:38 +00:00
|
|
|
|
2016-12-06 16:15:22 +00:00
|
|
|
/*
|
2020-03-25 15:50:38 +00:00
|
|
|
* Power off GIC-600 redistributor (if configured and detected)
|
2016-12-06 16:15:22 +00:00
|
|
|
*/
|
|
|
|
void gicv3_rdistif_off(unsigned int proc_num)
|
|
|
|
{
|
2020-03-25 15:50:38 +00:00
|
|
|
#if GICV3_SUPPORT_GIC600
|
|
|
|
uintptr_t gicr_base = get_gicr_base(proc_num);
|
2016-12-06 16:15:22 +00:00
|
|
|
|
|
|
|
/* Attempt to power redistributor off */
|
2020-03-25 15:50:38 +00:00
|
|
|
if (gicv3_is_gic600(gicr_base)) {
|
|
|
|
gic600_pwr_off(gicr_base);
|
|
|
|
}
|
|
|
|
#endif
|
2016-12-06 16:15:22 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
2020-03-25 15:50:38 +00:00
|
|
|
* Power on GIC-600 redistributor (if configured and detected)
|
2016-12-06 16:15:22 +00:00
|
|
|
*/
|
|
|
|
void gicv3_rdistif_on(unsigned int proc_num)
|
|
|
|
{
|
2020-03-25 15:50:38 +00:00
|
|
|
#if GICV3_SUPPORT_GIC600
|
|
|
|
uintptr_t gicr_base = get_gicr_base(proc_num);
|
2016-12-06 16:15:22 +00:00
|
|
|
|
|
|
|
/* Power redistributor on */
|
2020-03-25 15:50:38 +00:00
|
|
|
if (gicv3_is_gic600(gicr_base)) {
|
|
|
|
gic600_pwr_on(gicr_base);
|
|
|
|
}
|
|
|
|
#endif
|
2016-12-06 16:15:22 +00:00
|
|
|
}
|