From: lorenzo.pieralisi@arm.com (Lorenzo Pieralisi)
To: linux-arm-kernel@lists.infradead.org
Subject: [RFC PATCH 3/4] ACPI: IORT: Skip SMMUv3 device ID map for two steps mappings
Date: Wed, 9 Aug 2017 18:12:45 +0100 [thread overview]
Message-ID: <20170809171245.GA13377@red-moon> (raw)
In-Reply-To: <CAGHbJ3Bif=Lg7AOErohFG_wkdXAJi+E+zbud4hJGHCzh=VTegQ@mail.gmail.com>
On Wed, Aug 09, 2017 at 10:48:00PM +0800, Hanjun Guo wrote:
> Hi Robin,
>
> On 9 August 2017 at 19:50, Robin Murphy <robin.murphy@arm.com> wrote:
> > Hi Hanjun,
> >
> > It's a nice surprise to see this already; one less thing for us to do :)
>
> Glad to hear this patch set helps :)
>
> >
> > On 09/08/17 11:53, Hanjun Guo wrote:
> >> From: Hanjun Guo <hanjun.guo@linaro.org>
> >>
> >> IORT revision C introduced SMMUv3 MSI support which adding a
> >> device ID mapping index in SMMUv3 sub table, to get the SMMUv3
> >> device ID mapping for the output ID (dev ID for ITS) and the
> >> link to which ITS.
> >>
> >> So if a platform supports SMMUv3 MSI for control interrupt,
> >> there will be a additional single map entry under SMMU, this
> >> will not introduce any difference for devices just use one
> >> step map to get its output ID and parent (ITS or SMMU), such
> >> as PCI/NC/PMCG ---> ITS or PCI/NC ---> SMMU, but we need to
> >> do the spcial handling for two steps map case such as
> >> PCI/NC--->SMMUv3--->ITS.
> >>
> >> Take a PCI hostbridge for example,
> >>
> >> |----------------------|
> >> | Root Complex Node |
> >> |----------------------|
> >> | map entry[x] |
> >> |----------------------|
> >> | id value |
> >> | output_reference |
> >> |---|------------------|
> >> |
> >> | |----------------------|
> >> |-->| SMMUv3 |
> >> |----------------------|
> >> | SMMU dev ID |
> >> | mapping index 0 |
> >> |----------------------|
> >> | map entry[0] |
> >> |----------------------|
> >> | id value |
> >> | output_reference-----------> ITS 1 (SMMU MSI domain)
> >> |----------------------|
> >> | map entry[1] |
> >> |----------------------|
> >> | id value |
> >> | output_reference-----------> ITS 2 (PCI MSI domain)
> >> |----------------------|
> >>
> >> When the SMMU dev ID mapping index is 0, there is entry[0]
> >> to map to a ITS, we need to skip that map entry for PCI
> >> or NC (named component), or we may get the wrong ITS parent.
> >>
> >> For now we have two APIs for ID mapping, iort_node_map_id()
> >> and iort_node_map_platform_id(), and iort_node_map_id() is
> >> used for optional two steps mapping, so we just need to
> >> skip the map entry in iort_node_map_id() for non-SMMUv3
> >> devices.
> >>
> >> Signed-off-by: Hanjun Guo <hanjun.guo@linaro.org>
> >> ---
> >> drivers/acpi/arm64/iort.c | 37 ++++++++++++++++++++++++++++++++++++-
> >> 1 file changed, 36 insertions(+), 1 deletion(-)
> >>
> >> diff --git a/drivers/acpi/arm64/iort.c b/drivers/acpi/arm64/iort.c
> >> index 32bd4a4..9439f02 100644
> >> --- a/drivers/acpi/arm64/iort.c
> >> +++ b/drivers/acpi/arm64/iort.c
> >> @@ -366,6 +366,28 @@ struct acpi_iort_node *iort_node_get_id(struct acpi_iort_node *node,
> >> return NULL;
> >> }
> >>
> >> +static int iort_get_smmu_v3_id_mapping_index(struct acpi_iort_node *node,
> >> + u32 *index)
> >> +{
> >> + struct acpi_iort_smmu_v3 *smmu;
> >> +
> >> + /*
> >> + * SMMUv3 dev ID mapping index was introdueced in revision 1
> >> + * table, not avaible in revision 0
> >> + */
> >> + if (node->revision < 1)
> >> + return -EINVAL;
> >> +
> >> + smmu = (struct acpi_iort_smmu_v3 *)node->node_data;
> >> + /* if any of the gsi for control interrupts is not 0, ignore the MSI */
> >
> > IORT says "If all the SMMU control interrupts are GSIV based, this
> > field is ignored" - not "any". There doesn't seem to be any reason to
> > disallow a mixture of MSIs and GSIs.
>
> Hmm, since GSIV for control interrupts are SPI, those GSIVs should not
> be zero, does it mean we need the code below?
>
> if (smmu->event_gsiv && smmu->pri_gsiv && smmu->gerr_gsiv && smmu->sync_gsiv)
> return -EINVAL;
>
> This seems not consistent with the code for now (parsing
> the SMMU GSIV for SMMU platform device).
>
> >
> >> + if (smmu->event_gsiv || smmu->pri_gsiv || smmu->gerr_gsiv
> >> + || smmu->sync_gsiv)
> >> + return -EINVAL;
> >> +
> >> + *index = smmu->id_mapping_index;
> >> + return 0;
> >> +}
> >> +
> >> static struct acpi_iort_node *iort_node_map_id(struct acpi_iort_node *node,
> >> u32 id_in, u32 *id_out,
> >> u8 type_mask)
> >> @@ -375,7 +397,9 @@ static struct acpi_iort_node *iort_node_map_id(struct acpi_iort_node *node,
> >> /* Parse the ID mapping tree to find specified node type */
> >> while (node) {
> >> struct acpi_iort_id_mapping *map;
> >> - int i;
> >> + int i, ret = -EINVAL;
> >> + /* big enough for an invalid id index in practical */
> >> + u32 index = U32_MAX;
> >>
> >> if (IORT_TYPE_MASK(node->type) & type_mask) {
> >> if (id_out)
> >> @@ -396,8 +420,19 @@ static struct acpi_iort_node *iort_node_map_id(struct acpi_iort_node *node,
> >> goto fail_map;
> >> }
> >>
> >> + /*
> >> + * we need to get SMMUv3 dev ID mapping index and skip its
> >> + * associated ID map for single mapping cases.
> >> + */
> >> + if (node->type == ACPI_IORT_NODE_SMMU_V3)
> >> + ret = iort_get_smmu_v3_id_mapping_index(node, &index);
> >> +
> >> /* Do the ID translation */
> >> for (i = 0; i < node->mapping_count; i++, map++) {
> >> + /* if it's a SMMUv3 device id mapping index, skip it */
> >> + if (!ret && i == index)
> >
> > Given that i is an int anyway, there doesn't seem to be much need for
> > the ret dance - iort_get_smmu_v3_id_mapping_index() could just return
> > the index/error value as an int directly. You can rely on (i == index)
> > being false if index is negative, because for node->mapping_count to
> > overflow INT_MAX the IORT would have to be over 40GB in size, which is
> > definitely impossible.
>
> Good point, it will simplify the code, I will update this patch :)
How about:
(1) Ignoring SMMU_V3 single mappings in iort_id_map() (as we do today -
minus the warning) - we will never need them, just ignore them all
regarless of id_mapping_index
(2) Write some simple code that instead of relying on the
iort_pmsi_get_dev_id() API just get the SMMU V3 IORT node mapping
entry (at id_mapping_index), grab a reference to the ITS and
look-up the MSI domain
?
I do not see the point in making any of this generic for IORT kernel
code, it is a one-off kludge for SMMU_V3 and can easily be
self-contained IORT code.
Thoughts ?
Lorenzo
next prev parent reply other threads:[~2017-08-09 17:12 UTC|newest]
Thread overview: 17+ messages / expand[flat|nested] mbox.gz Atom feed top
2017-08-09 10:53 [RFC PATCH 0/4] SMMUv3 MSI support Hanjun Guo
2017-08-09 10:53 ` [RFC PATCH 1/4] ACPICA: Add SMMUv3 device ID mapping index support Hanjun Guo
2017-08-09 10:53 ` [RFC PATCH 2/4] ACPI: IORT: lookup iort node via fwnode Hanjun Guo
2017-08-09 10:53 ` [RFC PATCH 3/4] ACPI: IORT: Skip SMMUv3 device ID map for two steps mappings Hanjun Guo
2017-08-09 11:50 ` Robin Murphy
2017-08-09 14:48 ` Hanjun Guo
2017-08-09 17:12 ` Lorenzo Pieralisi [this message]
2017-08-10 9:41 ` Hanjun Guo
2017-08-15 17:13 ` Lorenzo Pieralisi
2017-08-09 10:53 ` [RFC PATCH 4/4] ACPI: IORT: Add SMMUv3 MSI support Hanjun Guo
2017-08-11 9:33 ` Lorenzo Pieralisi
2017-08-11 13:56 ` Hanjun Guo
2017-08-15 17:15 ` Lorenzo Pieralisi
2017-08-17 7:49 ` Hanjun Guo
2017-08-17 13:01 ` Lorenzo Pieralisi
2017-09-12 3:27 ` Hanjun Guo
2017-09-12 15:51 ` Lorenzo Pieralisi
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=20170809171245.GA13377@red-moon \
--to=lorenzo.pieralisi@arm.com \
--cc=linux-arm-kernel@lists.infradead.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).