2019-12-16 17:09:43 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0+
|
|
|
|
/*
|
|
|
|
* Copyright 2019 Broadcom.
|
|
|
|
*/
|
|
|
|
#include <common.h>
|
2020-07-26 17:07:32 +00:00
|
|
|
#include <dm.h>
|
2020-07-26 17:07:33 +00:00
|
|
|
#include <regmap.h>
|
|
|
|
#include <syscon.h>
|
2019-12-16 17:09:43 +00:00
|
|
|
#include <asm/gic.h>
|
|
|
|
#include <asm/gic-v3.h>
|
|
|
|
#include <asm/io.h>
|
2020-05-10 17:40:13 +00:00
|
|
|
#include <linux/bitops.h>
|
2020-02-14 05:30:52 +00:00
|
|
|
#include <linux/sizes.h>
|
2019-12-16 17:09:43 +00:00
|
|
|
|
|
|
|
static u32 lpi_id_bits;
|
|
|
|
|
|
|
|
#define LPI_NRBITS lpi_id_bits
|
|
|
|
#define LPI_PROPBASE_SZ ALIGN(BIT(LPI_NRBITS), SZ_64K)
|
|
|
|
#define LPI_PENDBASE_SZ ALIGN(BIT(LPI_NRBITS) / 8, SZ_64K)
|
|
|
|
|
2020-07-26 17:07:33 +00:00
|
|
|
/* Number of GIC re-distributors */
|
|
|
|
#define MAX_GIC_REDISTRIBUTORS 8
|
|
|
|
|
2020-07-26 17:07:32 +00:00
|
|
|
/*
|
|
|
|
* gic_v3_its_priv - gic details
|
|
|
|
*
|
|
|
|
* @gicd_base: gicd base address
|
|
|
|
* @gicr_base: gicr base address
|
2020-07-26 17:07:33 +00:00
|
|
|
* @lpi_base: gic lpi base address
|
|
|
|
* @num_redist: number of gic re-distributors
|
2020-07-26 17:07:32 +00:00
|
|
|
*/
|
|
|
|
struct gic_v3_its_priv {
|
|
|
|
ulong gicd_base;
|
|
|
|
ulong gicr_base;
|
2020-07-26 17:07:33 +00:00
|
|
|
ulong lpi_base;
|
|
|
|
u32 num_redist;
|
2020-07-26 17:07:32 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
static int gic_v3_its_get_gic_addr(struct gic_v3_its_priv *priv)
|
|
|
|
{
|
|
|
|
struct udevice *dev;
|
|
|
|
fdt_addr_t addr;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_driver(UCLASS_IRQ,
|
|
|
|
DM_GET_DRIVER(arm_gic_v3_its), &dev);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("%s: failed to get %s irq device\n", __func__,
|
|
|
|
DM_GET_DRIVER(arm_gic_v3_its)->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
addr = dev_read_addr_index(dev, 0);
|
|
|
|
if (addr == FDT_ADDR_T_NONE) {
|
|
|
|
pr_err("%s: failed to get GICD address\n", __func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
priv->gicd_base = addr;
|
|
|
|
|
|
|
|
addr = dev_read_addr_index(dev, 1);
|
|
|
|
if (addr == FDT_ADDR_T_NONE) {
|
|
|
|
pr_err("%s: failed to get GICR address\n", __func__);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
priv->gicr_base = addr;
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-26 17:07:33 +00:00
|
|
|
static int gic_v3_its_get_gic_lpi_addr(struct gic_v3_its_priv *priv)
|
|
|
|
{
|
|
|
|
struct regmap *regmap;
|
|
|
|
struct udevice *dev;
|
|
|
|
int ret;
|
|
|
|
|
|
|
|
ret = uclass_get_device_by_driver(UCLASS_SYSCON,
|
|
|
|
DM_GET_DRIVER(gic_lpi_syscon), &dev);
|
|
|
|
if (ret) {
|
|
|
|
pr_err("%s: failed to get %s syscon device\n", __func__,
|
|
|
|
DM_GET_DRIVER(gic_lpi_syscon)->name);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
regmap = syscon_get_regmap(dev);
|
|
|
|
if (!regmap) {
|
|
|
|
pr_err("%s: failed to regmap for %s syscon device\n", __func__,
|
|
|
|
DM_GET_DRIVER(gic_lpi_syscon)->name);
|
|
|
|
return -ENODEV;
|
|
|
|
}
|
|
|
|
priv->lpi_base = regmap->ranges[0].start;
|
|
|
|
|
|
|
|
priv->num_redist = dev_read_u32_default(dev, "max-gic-redistributors",
|
|
|
|
MAX_GIC_REDISTRIBUTORS);
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2019-12-16 17:09:43 +00:00
|
|
|
/*
|
|
|
|
* Program the GIC LPI configuration tables for all
|
|
|
|
* the re-distributors and enable the LPI table
|
|
|
|
*/
|
2020-07-26 17:07:33 +00:00
|
|
|
int gic_lpi_tables_init(void)
|
2019-12-16 17:09:43 +00:00
|
|
|
{
|
2020-07-26 17:07:32 +00:00
|
|
|
struct gic_v3_its_priv priv;
|
2019-12-16 17:09:43 +00:00
|
|
|
u32 gicd_typer;
|
|
|
|
u64 val;
|
|
|
|
u64 tmp;
|
|
|
|
int i;
|
|
|
|
u64 redist_lpi_base;
|
2020-07-26 17:07:32 +00:00
|
|
|
u64 pend_base;
|
2019-12-16 17:09:43 +00:00
|
|
|
|
2020-07-26 17:07:32 +00:00
|
|
|
if (gic_v3_its_get_gic_addr(&priv))
|
|
|
|
return -EINVAL;
|
2019-12-16 17:09:43 +00:00
|
|
|
|
2020-07-26 17:07:33 +00:00
|
|
|
if (gic_v3_its_get_gic_lpi_addr(&priv))
|
|
|
|
return -EINVAL;
|
|
|
|
|
2020-07-26 17:07:32 +00:00
|
|
|
gicd_typer = readl((uintptr_t)(priv.gicd_base + GICD_TYPER));
|
2019-12-16 17:09:43 +00:00
|
|
|
/* GIC support for Locality specific peripheral interrupts (LPI's) */
|
|
|
|
if (!(gicd_typer & GICD_TYPER_LPIS)) {
|
|
|
|
pr_err("GIC implementation does not support LPI's\n");
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Check for LPI is disabled for all the redistributors.
|
|
|
|
* Once the LPI table is enabled, can not program the
|
|
|
|
* LPI configuration tables again, unless the GIC is reset.
|
|
|
|
*/
|
2020-07-26 17:07:33 +00:00
|
|
|
for (i = 0; i < priv.num_redist; i++) {
|
2019-12-16 17:09:43 +00:00
|
|
|
u32 offset = i * GIC_REDISTRIBUTOR_OFFSET;
|
|
|
|
|
2020-07-26 17:07:32 +00:00
|
|
|
if ((readl((uintptr_t)(priv.gicr_base + offset))) &
|
2019-12-16 17:09:43 +00:00
|
|
|
GICR_CTLR_ENABLE_LPIS) {
|
|
|
|
pr_err("Re-Distributor %d LPI is already enabled\n",
|
|
|
|
i);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/* lpi_id_bits to get LPI_PENDBASE_SZ and LPi_PROPBASE_SZ */
|
|
|
|
lpi_id_bits = min_t(u32, GICD_TYPER_ID_BITS(gicd_typer),
|
|
|
|
ITS_MAX_LPI_NRBITS);
|
|
|
|
|
|
|
|
/* Set PropBase */
|
2020-07-26 17:07:33 +00:00
|
|
|
val = (priv.lpi_base |
|
2019-12-16 17:09:43 +00:00
|
|
|
GICR_PROPBASER_INNERSHAREABLE |
|
|
|
|
GICR_PROPBASER_RAWAWB |
|
|
|
|
((LPI_NRBITS - 1) & GICR_PROPBASER_IDBITS_MASK));
|
|
|
|
|
2020-07-26 17:07:32 +00:00
|
|
|
writeq(val, (uintptr_t)(priv.gicr_base + GICR_PROPBASER));
|
|
|
|
tmp = readl((uintptr_t)(priv.gicr_base + GICR_PROPBASER));
|
2019-12-16 17:09:43 +00:00
|
|
|
if ((tmp ^ val) & GICR_PROPBASER_SHAREABILITY_MASK) {
|
|
|
|
if (!(tmp & GICR_PROPBASER_SHAREABILITY_MASK)) {
|
|
|
|
val &= ~(GICR_PROPBASER_SHAREABILITY_MASK |
|
|
|
|
GICR_PROPBASER_CACHEABILITY_MASK);
|
|
|
|
val |= GICR_PROPBASER_NC;
|
2020-07-26 17:07:32 +00:00
|
|
|
writeq(val,
|
|
|
|
(uintptr_t)(priv.gicr_base + GICR_PROPBASER));
|
2019-12-16 17:09:43 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2020-07-26 17:07:33 +00:00
|
|
|
redist_lpi_base = priv.lpi_base + LPI_PROPBASE_SZ;
|
2019-12-16 17:09:43 +00:00
|
|
|
|
2020-07-26 17:07:32 +00:00
|
|
|
pend_base = priv.gicr_base + GICR_PENDBASER;
|
2020-07-26 17:07:33 +00:00
|
|
|
for (i = 0; i < priv.num_redist; i++) {
|
2019-12-16 17:09:43 +00:00
|
|
|
u32 offset = i * GIC_REDISTRIBUTOR_OFFSET;
|
|
|
|
|
|
|
|
val = ((redist_lpi_base + (i * LPI_PENDBASE_SZ)) |
|
|
|
|
GICR_PENDBASER_INNERSHAREABLE |
|
|
|
|
GICR_PENDBASER_RAWAWB);
|
|
|
|
|
|
|
|
writeq(val, (uintptr_t)(pend_base + offset));
|
|
|
|
tmp = readq((uintptr_t)(pend_base + offset));
|
|
|
|
if (!(tmp & GICR_PENDBASER_SHAREABILITY_MASK)) {
|
|
|
|
val &= ~(GICR_PENDBASER_SHAREABILITY_MASK |
|
|
|
|
GICR_PENDBASER_CACHEABILITY_MASK);
|
|
|
|
val |= GICR_PENDBASER_NC;
|
|
|
|
writeq(val, (uintptr_t)(pend_base + offset));
|
|
|
|
}
|
|
|
|
|
|
|
|
/* Enable LPI for the redistributor */
|
2020-07-26 17:07:32 +00:00
|
|
|
writel(GICR_CTLR_ENABLE_LPIS,
|
|
|
|
(uintptr_t)(priv.gicr_base + offset));
|
2019-12-16 17:09:43 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2020-07-26 17:07:32 +00:00
|
|
|
static const struct udevice_id gic_v3_its_ids[] = {
|
|
|
|
{ .compatible = "arm,gic-v3" },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(arm_gic_v3_its) = {
|
|
|
|
.name = "gic-v3",
|
|
|
|
.id = UCLASS_IRQ,
|
|
|
|
.of_match = gic_v3_its_ids,
|
|
|
|
};
|
2020-07-26 17:07:33 +00:00
|
|
|
|
|
|
|
static const struct udevice_id gic_lpi_syscon_ids[] = {
|
|
|
|
{ .compatible = "gic-lpi-base" },
|
|
|
|
{}
|
|
|
|
};
|
|
|
|
|
|
|
|
U_BOOT_DRIVER(gic_lpi_syscon) = {
|
|
|
|
.name = "gic-lpi-base",
|
|
|
|
.id = UCLASS_SYSCON,
|
|
|
|
.of_match = gic_lpi_syscon_ids,
|
|
|
|
};
|