All of lore.kernel.org
 help / color / mirror / Atom feed
From: Stefano Stabellini <sstabellini@kernel.org>
To: Rahul Singh <rahul.singh@arm.com>
Cc: xen-devel@lists.xenproject.org, bertrand.marquis@arm.com,
	 Andre.Przywara@arm.com,
	Stefano Stabellini <sstabellini@kernel.org>,
	 Julien Grall <julien@xen.org>,
	 Volodymyr Babchuk <Volodymyr_Babchuk@epam.com>
Subject: Re: [PATCH v3 13/17] xen/arm: Implement pci access functions
Date: Wed, 29 Sep 2021 09:42:46 -0700 (PDT)	[thread overview]
Message-ID: <alpine.DEB.2.21.2109281642360.5022@sstabellini-ThinkPad-T480s> (raw)
In-Reply-To: <33cc6b7a133787700ea8ba4e54a03141d3aca1ea.1632847120.git.rahul.singh@arm.com>

On Tue, 28 Sep 2021, Rahul Singh wrote:
> Implement generic pci access functions to read/write the configuration
> space.
> 
> Signed-off-by: Rahul Singh <rahul.singh@arm.com>

Reviewed-by: Stefano Stabellini <sstabellini@kernel.org>


> ---
> Change in v3:
> - Remove PRI_pci as not used.
> - Replace uint32_t sbdf to pci_sbdf_t sbdf to avoid typecast
> Change in v2: Fixed comments
> ---
>  xen/arch/arm/pci/pci-access.c      | 57 ++++++++++++++++++++++++++++++
>  xen/arch/arm/pci/pci-host-common.c | 19 ++++++++++
>  xen/include/asm-arm/pci.h          |  1 +
>  3 files changed, 77 insertions(+)
> 
> diff --git a/xen/arch/arm/pci/pci-access.c b/xen/arch/arm/pci/pci-access.c
> index 3cd14a4b87..9f9aac43d7 100644
> --- a/xen/arch/arm/pci/pci-access.c
> +++ b/xen/arch/arm/pci/pci-access.c
> @@ -16,6 +16,7 @@
>  #include <asm/io.h>
>  
>  #define INVALID_VALUE (~0U)
> +#define PCI_ERR_VALUE(len) GENMASK(0, len * 8)
>  
>  int pci_generic_config_read(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,
>                              uint32_t reg, uint32_t len, uint32_t *value)
> @@ -72,6 +73,62 @@ int pci_generic_config_write(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,
>      return 0;
>  }
>  
> +static uint32_t pci_config_read(pci_sbdf_t sbdf, unsigned int reg,
> +                                unsigned int len)
> +{
> +    uint32_t val = PCI_ERR_VALUE(len);
> +    struct pci_host_bridge *bridge = pci_find_host_bridge(sbdf.seg, sbdf.bus);
> +
> +    if ( unlikely(!bridge) )
> +        return val;
> +
> +    if ( unlikely(!bridge->ops->read) )
> +        return val;
> +
> +    bridge->ops->read(bridge, sbdf, reg, len, &val);
> +
> +    return val;
> +}
> +
> +static void pci_config_write(pci_sbdf_t sbdf, unsigned int reg,
> +                             unsigned int len, uint32_t val)
> +{
> +    struct pci_host_bridge *bridge = pci_find_host_bridge(sbdf.seg, sbdf.bus);
> +
> +    if ( unlikely(!bridge) )
> +        return;
> +
> +    if ( unlikely(!bridge->ops->write) )
> +        return;
> +
> +    bridge->ops->write(bridge, sbdf, reg, len, val);
> +}
> +
> +/*
> + * Wrappers for all PCI configuration access functions.
> + */
> +
> +#define PCI_OP_WRITE(size, type)                            \
> +    void pci_conf_write##size(pci_sbdf_t sbdf,              \
> +                              unsigned int reg, type val)   \
> +{                                                           \
> +    pci_config_write(sbdf, reg, size / 8, val);             \
> +}
> +
> +#define PCI_OP_READ(size, type)                             \
> +    type pci_conf_read##size(pci_sbdf_t sbdf,               \
> +                              unsigned int reg)             \
> +{                                                           \
> +    return pci_config_read(sbdf, reg, size / 8);            \
> +}
> +
> +PCI_OP_READ(8, uint8_t)
> +PCI_OP_READ(16, uint16_t)
> +PCI_OP_READ(32, uint32_t)
> +PCI_OP_WRITE(8, uint8_t)
> +PCI_OP_WRITE(16, uint16_t)
> +PCI_OP_WRITE(32, uint32_t)
> +
>  /*
>   * Local variables:
>   * mode: C
> diff --git a/xen/arch/arm/pci/pci-host-common.c b/xen/arch/arm/pci/pci-host-common.c
> index a08e06cea1..c5941b10e9 100644
> --- a/xen/arch/arm/pci/pci-host-common.c
> +++ b/xen/arch/arm/pci/pci-host-common.c
> @@ -236,6 +236,25 @@ err_exit:
>      return err;
>  }
>  
> +/*
> + * This function will lookup an hostbridge based on the segment and bus
> + * number.
> + */
> +struct pci_host_bridge *pci_find_host_bridge(uint16_t segment, uint8_t bus)
> +{
> +    struct pci_host_bridge *bridge;
> +
> +    list_for_each_entry( bridge, &pci_host_bridges, node )
> +    {
> +        if ( bridge->segment != segment )
> +            continue;
> +        if ( (bus < bridge->cfg->busn_start) || (bus > bridge->cfg->busn_end) )
> +            continue;
> +        return bridge;
> +    }
> +
> +    return NULL;
> +}
>  /*
>   * Local variables:
>   * mode: C
> diff --git a/xen/include/asm-arm/pci.h b/xen/include/asm-arm/pci.h
> index bb7eda6705..49c9622902 100644
> --- a/xen/include/asm-arm/pci.h
> +++ b/xen/include/asm-arm/pci.h
> @@ -81,6 +81,7 @@ int pci_generic_config_write(struct pci_host_bridge *bridge, pci_sbdf_t sbdf,
>                               uint32_t reg, uint32_t len, uint32_t value);
>  void __iomem *pci_ecam_map_bus(struct pci_host_bridge *bridge,
>                                 pci_sbdf_t sbdf, uint32_t where);
> +struct pci_host_bridge *pci_find_host_bridge(uint16_t segment, uint8_t bus);
>  
>  static always_inline bool is_pci_passthrough_enabled(void)
>  {
> -- 
> 2.17.1
> 


  parent reply	other threads:[~2021-09-29 16:42 UTC|newest]

Thread overview: 64+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-28 18:18 [PATCH v3 00/17] PCI devices passthrough on Arm Rahul Singh
2021-09-28 18:18 ` [PATCH v3 01/17] xen/pci: Refactor MSI code that implements MSI functionality within XEN Rahul Singh
2021-09-29  7:28   ` Bertrand Marquis
2021-09-29 16:56   ` Stefano Stabellini
2021-09-30 14:22     ` Jan Beulich
2021-09-28 18:18 ` [PATCH v3 02/17] xen/arm: pci: Add stubs to allow selecting HAS_PCI Rahul Singh
2021-09-29  7:28   ` Bertrand Marquis
2021-09-28 18:18 ` [PATCH v3 03/17] xen/arm: solve compilation error on ARM with ACPI && HAS_PCI Rahul Singh
2021-09-29  7:29   ` Bertrand Marquis
2021-09-29  8:24   ` Jan Beulich
2021-09-29  9:29     ` Rahul Singh
2021-09-28 18:18 ` [PATCH v3 04/17] xen/arm: xc_domain_ioport_permission(..) not supported on ARM Rahul Singh
2021-09-29  7:30   ` Bertrand Marquis
2021-09-28 18:18 ` [PATCH v3 05/17] xen/arm: Add PHYSDEVOP_pci_device_* support for ARM Rahul Singh
2021-09-29  6:05   ` Stefano Stabellini
2021-09-29  7:34   ` Bertrand Marquis
2021-09-30 14:51   ` Jan Beulich
2021-10-01 16:19     ` Rahul Singh
2021-09-28 18:18 ` [PATCH v3 06/17] xen/device-tree: Add dt_property_read_variable_u32_array helper Rahul Singh
2021-09-29  6:06   ` Stefano Stabellini
2021-09-29  7:34   ` Bertrand Marquis
2021-09-28 18:18 ` [PATCH v3 07/17] xen/device-tree: Add dt_property_read_u32_array helper Rahul Singh
2021-09-29  6:07   ` Stefano Stabellini
2021-09-29  7:35   ` Bertrand Marquis
2021-09-28 18:18 ` [PATCH v3 08/17] xen/device-tree: Add dt_get_pci_domain_nr helper Rahul Singh
2021-09-29  6:09   ` Stefano Stabellini
2021-09-29  7:35   ` Bertrand Marquis
2021-09-28 18:18 ` [PATCH v3 09/17] xen/arm: Add support for PCI init to initialize the PCI driver Rahul Singh
2021-09-29  6:10   ` Stefano Stabellini
2021-09-29  7:35   ` Bertrand Marquis
2021-09-28 18:18 ` [PATCH v3 10/17] xen/arm: Add cmdline boot option "pci-passthrough = <boolean>" Rahul Singh
2021-09-29  6:11   ` Stefano Stabellini
2021-09-29  7:36   ` Bertrand Marquis
2021-09-30 15:00   ` Jan Beulich
2021-10-01 10:55     ` Rahul Singh
2021-09-28 18:18 ` [PATCH v3 11/17] xen/arm: PCI host bridge discovery within XEN on ARM Rahul Singh
2021-09-29  8:31   ` Jan Beulich
2021-09-29  8:59     ` Rahul Singh
2021-09-29 16:40   ` Stefano Stabellini
2021-09-30  7:47     ` Jan Beulich
2021-09-28 18:18 ` [PATCH v3 12/17] xen/arm: Add support for Xilinx ZynqMP PCI host controller Rahul Singh
2021-09-29 13:38   ` Bertrand Marquis
2021-09-29 14:17     ` Oleksandr Andrushchenko
2021-09-29 16:41   ` Stefano Stabellini
2021-09-30  7:48     ` Jan Beulich
2021-09-30 10:42       ` Rahul Singh
2021-09-28 18:18 ` [PATCH v3 13/17] xen/arm: Implement pci access functions Rahul Singh
2021-09-29 13:35   ` Bertrand Marquis
2021-09-29 16:42   ` Stefano Stabellini [this message]
2021-09-28 18:18 ` [PATCH v3 14/17] xen/arm: Enable the existing x86 virtual PCI support for ARM Rahul Singh
2021-09-29 16:45   ` Stefano Stabellini
2021-09-30 15:19   ` Jan Beulich
2021-10-01 11:44     ` Rahul Singh
2021-10-01 12:40       ` Jan Beulich
2021-09-28 18:18 ` [PATCH v3 15/17] xen/arm: Transitional change to build HAS_VPCI on ARM Rahul Singh
2021-09-29 13:39   ` Bertrand Marquis
2021-09-29 16:46   ` Stefano Stabellini
2021-09-28 18:18 ` [PATCH v3 16/17] arm/libxl: Emulated PCI device tree node in libxl Rahul Singh
2021-09-29 13:42   ` Bertrand Marquis
2021-09-29 16:47   ` Stefano Stabellini
2021-09-28 18:18 ` [PATCH v3 17/17] xen/arm: Add linux,pci-domain property for hwdom if not available Rahul Singh
2021-09-29 13:42   ` Bertrand Marquis
2021-09-29 16:48   ` Stefano Stabellini
2021-10-01  1:31 ` [PATCH v3 00/17] PCI devices passthrough on Arm Stefano Stabellini

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=alpine.DEB.2.21.2109281642360.5022@sstabellini-ThinkPad-T480s \
    --to=sstabellini@kernel.org \
    --cc=Andre.Przywara@arm.com \
    --cc=Volodymyr_Babchuk@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=julien@xen.org \
    --cc=rahul.singh@arm.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 an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.