From: Shanker Donthineni <shankerd@codeaurora.org>
To: Andre Przywara <andre.przywara@arm.com>,
Stefano Stabellini <sstabellini@kernel.org>,
Julien Grall <julien.grall@arm.com>
Cc: xen-devel@lists.xenproject.org, Vijay Kilari <vijay.kilari@gmail.com>
Subject: Re: [PATCH v2 05/27] ARM: GICv3 ITS: introduce ITS command handling
Date: Thu, 16 Mar 2017 10:05:16 -0500 [thread overview]
Message-ID: <5dacefe8-e0c4-bc7c-1620-4643a04bfa9a@codeaurora.org> (raw)
In-Reply-To: <20170316112030.20419-6-andre.przywara@arm.com>
Hi Andre,
On 03/16/2017 06:20 AM, Andre Przywara wrote:
> To be able to easily send commands to the ITS, create the respective
> wrapper functions, which take care of the ring buffer.
> The first two commands we implement provide methods to map a collection
> to a redistributor (aka host core) and to flush the command queue (SYNC).
> Start using these commands for mapping one collection to each host CPU.
>
> Signed-off-by: Andre Przywara <andre.przywara@arm.com>
> ---
> xen/arch/arm/gic-v3-its.c | 181 +++++++++++++++++++++++++++++++++++++-
> xen/arch/arm/gic-v3-lpi.c | 22 +++++
> xen/arch/arm/gic-v3.c | 19 +++-
> xen/include/asm-arm/gic_v3_defs.h | 2 +
> xen/include/asm-arm/gic_v3_its.h | 38 ++++++++
> 5 files changed, 260 insertions(+), 2 deletions(-)
>
> diff --git a/xen/arch/arm/gic-v3-its.c b/xen/arch/arm/gic-v3-its.c
> index e5601ed..5c11b0d 100644
> --- a/xen/arch/arm/gic-v3-its.c
> +++ b/xen/arch/arm/gic-v3-its.c
> @@ -19,11 +19,14 @@
> */
>
> #include <xen/lib.h>
> +#include <xen/delay.h>
> #include <xen/mm.h>
> #include <xen/sizes.h>
> +#include <asm/gic.h>
> #include <asm/gic_v3_defs.h>
> #include <asm/gic_v3_its.h>
> #include <asm/io.h>
> +#include <asm/page.h>
>
> #define ITS_CMD_QUEUE_SZ SZ_64K
>
> @@ -34,6 +37,145 @@ bool gicv3_its_host_has_its(void)
> return !list_empty(&host_its_list);
> }
>
> +#define BUFPTR_MASK GENMASK(19, 5)
> +static int its_send_command(struct host_its *hw_its, const void *its_cmd)
> +{
> + s_time_t deadline = NOW() + MILLISECS(1);
> + uint64_t readp, writep;
> + int ret = -EBUSY;
> +
> + /* No ITS commands from an interrupt handler (at the moment). */
> + ASSERT(!in_irq());
> +
> + spin_lock(&hw_its->cmd_lock);
> +
> + do {
> + readp = readq_relaxed(hw_its->its_base + GITS_CREADR) & BUFPTR_MASK;
> + writep = readq_relaxed(hw_its->its_base + GITS_CWRITER) & BUFPTR_MASK;
> +
> + if ( ((writep + ITS_CMD_SIZE) % ITS_CMD_QUEUE_SZ) != readp )
> + {
> + ret = 0;
> + break;
> + }
> +
> + /*
> + * If the command queue is full, wait for a bit in the hope it drains
> + * before giving up.
> + */
> + spin_unlock(&hw_its->cmd_lock);
> + cpu_relax();
> + udelay(1);
> + spin_lock(&hw_its->cmd_lock);
> + } while ( NOW() <= deadline );
> +
> + if ( ret )
> + {
> + spin_unlock(&hw_its->cmd_lock);
> + printk(XENLOG_WARNING "ITS: command queue full.\n");
> + return ret;
> + }
> +
> + memcpy(hw_its->cmd_buf + writep, its_cmd, ITS_CMD_SIZE);
> + if ( hw_its->flags & HOST_ITS_FLUSH_CMD_QUEUE )
> + clean_and_invalidate_dcache_va_range(hw_its->cmd_buf + writep,
> + ITS_CMD_SIZE);
> + else
> + dsb(ishst);
> +
> + writep = (writep + ITS_CMD_SIZE) % ITS_CMD_QUEUE_SZ;
> + writeq_relaxed(writep & BUFPTR_MASK, hw_its->its_base + GITS_CWRITER);
> +
> + spin_unlock(&hw_its->cmd_lock);
> +
> + return 0;
> +}
> +
> +/* Wait for an ITS to finish processing all commands. */
> +static int gicv3_its_wait_commands(struct host_its *hw_its)
> +{
> + s_time_t deadline = NOW() + MILLISECS(100);
> + uint64_t readp, writep;
> +
> + do {
> + spin_lock(&hw_its->cmd_lock);
> + readp = readq_relaxed(hw_its->its_base + GITS_CREADR) & BUFPTR_MASK;
> + writep = readq_relaxed(hw_its->its_base + GITS_CWRITER) & BUFPTR_MASK;
> + spin_unlock(&hw_its->cmd_lock);
> +
> + if ( readp == writep )
> + return 0;
> +
> + cpu_relax();
> + udelay(1);
> + } while ( NOW() <= deadline );
> +
> + return -ETIMEDOUT;
> +}
> +
> +static uint64_t encode_rdbase(struct host_its *hw_its, unsigned int cpu,
> + uint64_t reg)
> +{
> + reg &= ~GENMASK(51, 16);
> +
> + reg |= gicv3_get_redist_address(cpu, hw_its->flags & HOST_ITS_USES_PTA);
> +
> + return reg;
> +}
> +
> +static int its_send_cmd_sync(struct host_its *its, unsigned int cpu)
> +{
> + uint64_t cmd[4];
> +
> + cmd[0] = GITS_CMD_SYNC;
> + cmd[1] = 0x00;
> + cmd[2] = encode_rdbase(its, cpu, 0x0);
> + cmd[3] = 0x00;
> +
> + return its_send_command(its, cmd);
> +}
> +
> +static int its_send_cmd_mapc(struct host_its *its, uint32_t collection_id,
> + unsigned int cpu)
> +{
> + uint64_t cmd[4];
> +
> + cmd[0] = GITS_CMD_MAPC;
> + cmd[1] = 0x00;
> + cmd[2] = encode_rdbase(its, cpu, (collection_id & GENMASK(15, 0)));
> + cmd[2] |= GITS_VALID_BIT;
> + cmd[3] = 0x00;
> +
> + return its_send_command(its, cmd);
> +}
> +
> +/* Set up the (1:1) collection mapping for the given host CPU. */
> +int gicv3_its_setup_collection(unsigned int cpu)
> +{
> + struct host_its *its;
> + int ret;
> +
> + list_for_each_entry(its, &host_its_list, entry)
> + {
> + if ( !its->cmd_buf )
> + continue;
> +
> + ret = its_send_cmd_mapc(its, cpu, cpu);
> + if ( ret )
> + return ret;
> +
> + ret = its_send_cmd_sync(its, cpu);
> + if ( ret )
> + return ret;
> +
> + ret = gicv3_its_wait_commands(its);
> + if ( ret )
> + return ret;
> + }
> +
> + return 0;
> +}
> +
> #define BASER_ATTR_MASK \
> ((0x3UL << GITS_BASER_SHAREABILITY_SHIFT) | \
> (0x7UL << GITS_BASER_OUTER_CACHEABILITY_SHIFT) | \
> @@ -184,22 +326,59 @@ retry:
> return -EINVAL;
> }
>
> +/*
> + * Before an ITS gets initialized, it should be in a quiescent state, where
> + * all outstanding commands and transactions have finished.
> + * So if the ITS is already enabled, turn it off and wait for all outstanding
> + * operations to get processed by polling the QUIESCENT bit.
> + */
> +static int gicv3_disable_its(struct host_its *hw_its)
> +{
> + uint32_t reg;
> + s_time_t deadline = NOW() + MILLISECS(100);
> +
> + reg = readl_relaxed(hw_its->its_base + GITS_CTLR);
> + if ( (reg & GITS_CTLR_QUIESCENT) && !(reg & GITS_CTLR_ENABLE) )
nit: I prefer changing to 'if ( !(reg & GITS_CTLR_ENABLE) && (reg & GITS_CTLR_QUIESCENT) ) ' because bit GITS_CTLR_QUIESCENT is not valid if ITS hardware is in enabled state.
> #endif
--
Shanker Donthineni
Qualcomm Datacenter Technologies, Inc. as an affiliate of Qualcomm Technologies, Inc.
Qualcomm Technologies, Inc. is a member of the Code Aurora Forum, a Linux Foundation Collaborative Project.
_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel
next prev parent reply other threads:[~2017-03-16 15:05 UTC|newest]
Thread overview: 119+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-03-16 11:20 [PATCH v2 00/27] arm64: Dom0 ITS emulation Andre Przywara
2017-03-16 11:20 ` [PATCH v2 01/27] ARM: GICv3 ITS: parse and store ITS subnodes from hardware DT Andre Przywara
2017-03-21 20:17 ` Julien Grall
2017-03-23 10:57 ` Andre Przywara
2017-03-23 17:32 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 02/27] ARM: GICv3: allocate LPI pending and property table Andre Przywara
2017-03-21 21:23 ` Julien Grall
2017-03-23 14:40 ` Andre Przywara
2017-03-23 17:42 ` Julien Grall
2017-03-23 17:45 ` Stefano Stabellini
2017-03-23 17:49 ` Julien Grall
2017-03-23 18:01 ` Stefano Stabellini
2017-03-23 18:21 ` Andre Przywara
2017-03-24 11:45 ` Julien Grall
2017-03-24 17:22 ` Stefano Stabellini
2017-03-21 22:57 ` Stefano Stabellini
2017-03-21 23:08 ` André Przywara
2017-03-21 23:27 ` Stefano Stabellini
2017-03-23 10:50 ` Andre Przywara
2017-03-23 17:47 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 03/27] ARM: GICv3 ITS: allocate device and collection table Andre Przywara
2017-03-21 23:29 ` Stefano Stabellini
2017-03-22 13:52 ` Julien Grall
2017-03-22 16:08 ` André Przywara
2017-03-22 16:33 ` Julien Grall
2017-03-29 13:58 ` Andre Przywara
2017-03-16 11:20 ` [PATCH v2 04/27] ARM: GICv3 ITS: map ITS command buffer Andre Przywara
2017-03-21 23:48 ` Stefano Stabellini
2017-03-22 15:23 ` Julien Grall
2017-03-22 16:31 ` André Przywara
2017-03-22 16:41 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 05/27] ARM: GICv3 ITS: introduce ITS command handling Andre Przywara
2017-03-16 15:05 ` Shanker Donthineni [this message]
2017-03-16 15:18 ` Andre Przywara
2017-03-22 0:02 ` Stefano Stabellini
2017-03-22 15:59 ` Julien Grall
2017-04-03 10:58 ` Andre Przywara
2017-04-03 11:23 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 06/27] ARM: GICv3 ITS: introduce device mapping Andre Przywara
2017-03-22 17:29 ` Julien Grall
2017-04-03 20:08 ` Andre Przywara
2017-04-03 20:41 ` Julien Grall
2017-04-04 9:57 ` Andre Przywara
2017-03-22 22:45 ` Stefano Stabellini
2017-04-03 19:45 ` Andre Przywara
2017-03-30 11:17 ` Vijay Kilari
2017-03-16 11:20 ` [PATCH v2 07/27] ARM: arm64: activate atomic 64-bit accessors Andre Przywara
2017-03-22 17:30 ` Julien Grall
2017-03-22 22:49 ` Stefano Stabellini
2017-03-16 11:20 ` [PATCH v2 08/27] ARM: GICv3 ITS: introduce host LPI array Andre Przywara
2017-03-22 23:38 ` Stefano Stabellini
2017-03-23 8:48 ` Julien Grall
2017-03-23 10:21 ` Andre Przywara
2017-03-23 17:52 ` Stefano Stabellini
2017-03-24 11:54 ` Julien Grall
2017-03-23 19:08 ` Julien Grall
2017-04-03 19:30 ` Andre Przywara
2017-04-03 20:13 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 09/27] ARM: GICv3: introduce separate pending_irq structs for LPIs Andre Przywara
2017-03-22 23:44 ` Stefano Stabellini
2017-03-23 20:08 ` André Przywara
2017-03-24 10:59 ` Julien Grall
2017-03-24 11:40 ` Julien Grall
2017-03-24 15:50 ` Andre Przywara
2017-03-24 16:19 ` Julien Grall
2017-03-24 17:26 ` Stefano Stabellini
2017-03-27 9:02 ` Andre Przywara
2017-03-27 14:01 ` Julien Grall
2017-03-27 17:44 ` Stefano Stabellini
2017-03-27 17:49 ` Julien Grall
2017-03-27 18:39 ` Stefano Stabellini
2017-03-27 21:24 ` Julien Grall
2017-03-28 7:58 ` Jan Beulich
2017-03-28 13:12 ` Julien Grall
2017-03-28 13:34 ` Jan Beulich
2017-03-16 11:20 ` [PATCH v2 10/27] ARM: GICv3: forward pending LPIs to guests Andre Przywara
2017-03-24 12:03 ` Julien Grall
2017-04-03 14:18 ` Andre Przywara
2017-04-04 11:49 ` Julien Grall
2017-04-04 12:51 ` Andre Przywara
2017-04-04 12:50 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 11/27] ARM: GICv3: enable ITS and LPIs on the host Andre Przywara
2017-03-16 11:20 ` [PATCH v2 12/27] ARM: vGICv3: handle virtual LPI pending and property tables Andre Przywara
2017-03-24 12:09 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 13/27] ARM: vGICv3: Handle disabled LPIs Andre Przywara
2017-03-24 12:20 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 14/27] ARM: vGICv3: introduce basic ITS emulation bits Andre Przywara
2017-03-16 16:25 ` Shanker Donthineni
2017-03-20 12:17 ` Vijay Kilari
2017-03-24 12:41 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 15/27] ARM: vITS: introduce translation table walks Andre Przywara
2017-03-24 13:00 ` Julien Grall
2017-04-03 18:25 ` Andre Przywara
2017-04-04 15:59 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 16/27] ARM: vITS: handle CLEAR command Andre Przywara
2017-03-24 14:27 ` Julien Grall
2017-03-24 15:53 ` Andre Przywara
2017-03-24 17:17 ` Stefano Stabellini
2017-03-27 8:44 ` Andre Przywara
2017-03-27 14:12 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 17/27] ARM: vITS: handle INT command Andre Przywara
2017-03-24 14:38 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 18/27] ARM: vITS: handle MAPC command Andre Przywara
2017-03-16 11:20 ` [PATCH v2 19/27] ARM: vITS: handle MAPD command Andre Przywara
2017-03-24 14:41 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 20/27] ARM: vITS: handle MAPTI command Andre Przywara
2017-03-24 14:54 ` Julien Grall
2017-04-03 18:47 ` Andre Przywara
2017-03-16 11:20 ` [PATCH v2 21/27] ARM: vITS: handle MOVI command Andre Przywara
2017-03-24 15:00 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 22/27] ARM: vITS: handle DISCARD command Andre Przywara
2017-03-16 11:20 ` [PATCH v2 23/27] ARM: vITS: handle INV command Andre Przywara
2017-03-16 11:20 ` [PATCH v2 24/27] ARM: vITS: handle INVALL command Andre Przywara
2017-03-24 15:12 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 25/27] ARM: vITS: create and initialize virtual ITSes for Dom0 Andre Przywara
2017-03-24 15:18 ` Julien Grall
2017-03-16 11:20 ` [PATCH v2 26/27] ARM: vITS: create ITS subnodes for Dom0 DT Andre Przywara
2017-03-16 11:20 ` [PATCH v2 27/27] ARM: vGIC: advertise LPI support Andre Przywara
2017-03-24 15:25 ` Julien Grall
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=5dacefe8-e0c4-bc7c-1620-4643a04bfa9a@codeaurora.org \
--to=shankerd@codeaurora.org \
--cc=andre.przywara@arm.com \
--cc=julien.grall@arm.com \
--cc=sstabellini@kernel.org \
--cc=vijay.kilari@gmail.com \
--cc=xen-devel@lists.xenproject.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).