All of lore.kernel.org
 help / color / mirror / Atom feed
From: Oleksandr Andrushchenko <andr2000@gmail.com>
To: xen-devel@lists.xenproject.org
Cc: julien@xen.org, sstabellini@kernel.org,
	oleksandr_tyshchenko@epam.com, volodymyr_babchuk@epam.com,
	Artem_Mygaiev@epam.com, roger.pau@citrix.com, jbeulich@suse.com,
	bertrand.marquis@arm.com, rahul.singh@arm.com,
	Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
Subject: [PATCH v2 05/11] vpci/header: Implement guest BAR register handlers
Date: Thu, 23 Sep 2021 15:54:55 +0300	[thread overview]
Message-ID: <20210923125501.234252-6-andr2000@gmail.com> (raw)
In-Reply-To: <20210923125501.234252-1-andr2000@gmail.com>

From: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>

Emulate guest BAR register values: this allows creating a guest view
of the registers and emulates size and properties probe as it is done
during PCI device enumeration by the guest.

ROM BAR is only handled for the hardware domain and for guest domains
there is a stub: at the moment PCI expansion ROM is x86 only, so it
might not be used by other architectures without emulating x86. Other
use-cases may include using that expansion ROM before Xen boots, hence
no emulation is needed in Xen itself. Or when a guest wants to use the
ROM code which seems to be rare.

Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>

---
Since v1:
 - re-work guest read/write to be much simpler and do more work on write
   than read which is expected to be called more frequently
 - removed one too obvious comment

Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@epam.com>
---
 xen/drivers/vpci/header.c | 30 +++++++++++++++++++++++++++++-
 xen/include/xen/vpci.h    |  3 +++
 2 files changed, 32 insertions(+), 1 deletion(-)

diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c
index 1ce98795fcca..ec4d215f36ff 100644
--- a/xen/drivers/vpci/header.c
+++ b/xen/drivers/vpci/header.c
@@ -400,12 +400,38 @@ static void bar_write(const struct pci_dev *pdev, unsigned int reg,
 static void guest_bar_write(const struct pci_dev *pdev, unsigned int reg,
                             uint32_t val, void *data)
 {
+    struct vpci_bar *bar = data;
+    bool hi = false;
+
+    if ( bar->type == VPCI_BAR_MEM64_HI )
+    {
+        ASSERT(reg > PCI_BASE_ADDRESS_0);
+        bar--;
+        hi = true;
+    }
+    else
+    {
+        val &= PCI_BASE_ADDRESS_MEM_MASK;
+        val |= bar->type == VPCI_BAR_MEM32 ? PCI_BASE_ADDRESS_MEM_TYPE_32
+                                           : PCI_BASE_ADDRESS_MEM_TYPE_64;
+        val |= bar->prefetchable ? PCI_BASE_ADDRESS_MEM_PREFETCH : 0;
+    }
+
+    bar->guest_addr &= ~(0xffffffffull << (hi ? 32 : 0));
+    bar->guest_addr |= (uint64_t)val << (hi ? 32 : 0);
+
+    bar->guest_addr &= ~(bar->size - 1) | ~PCI_BASE_ADDRESS_MEM_MASK;
 }
 
 static uint32_t guest_bar_read(const struct pci_dev *pdev, unsigned int reg,
                                void *data)
 {
-    return 0xffffffff;
+    const struct vpci_bar *bar = data;
+
+    if ( bar->type == VPCI_BAR_MEM64_HI )
+        return bar->guest_addr >> 32;
+
+    return bar->guest_addr;
 }
 
 static void rom_write(const struct pci_dev *pdev, unsigned int reg,
@@ -522,6 +548,8 @@ static int add_bar_handlers(const struct pci_dev *pdev, bool is_hwdom)
             if ( rc )
                 return rc;
         }
+
+        bars[i].guest_addr = 0;
     }
     return 0;
 }
diff --git a/xen/include/xen/vpci.h b/xen/include/xen/vpci.h
index 912cbc6aa7ad..9eaf99f356fe 100644
--- a/xen/include/xen/vpci.h
+++ b/xen/include/xen/vpci.h
@@ -81,7 +81,10 @@ struct vpci {
     struct vpci_header {
         /* Information about the PCI BARs of this device. */
         struct vpci_bar {
+            /* Physical view of the BAR. */
             uint64_t addr;
+            /* Guest view of the BAR. */
+            uint64_t guest_addr;
             uint64_t size;
             enum {
                 VPCI_BAR_EMPTY,
-- 
2.25.1



  parent reply	other threads:[~2021-09-23 12:58 UTC|newest]

Thread overview: 44+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-23 12:54 [PATCH v2 00/11] PCI devices passthrough on Arm, part 3 Oleksandr Andrushchenko
2021-09-23 12:54 ` [PATCH v2 01/11] vpci: Make vpci registers removal a dedicated function Oleksandr Andrushchenko
2021-09-28 11:15   ` Michal Orzel
2021-09-23 12:54 ` [PATCH v2 02/11] vpci: Add hooks for PCI device assign/de-assign Oleksandr Andrushchenko
2021-09-29  9:35   ` Michal Orzel
2021-09-23 12:54 ` [PATCH v2 03/11] vpci/header: Move register assignments from init_bars Oleksandr Andrushchenko
2021-09-23 12:54 ` [PATCH v2 04/11] vpci/header: Add and remove register handlers dynamically Oleksandr Andrushchenko
2021-09-23 12:54 ` Oleksandr Andrushchenko [this message]
2021-09-29  9:27   ` [PATCH v2 05/11] vpci/header: Implement guest BAR register handlers Michal Orzel
2021-09-23 12:54 ` [PATCH v2 06/11] vpci/header: Handle p2m range sets per BAR Oleksandr Andrushchenko
2021-09-23 12:54 ` [PATCH v2 07/11] vpci/header: program p2m with guest BAR view Oleksandr Andrushchenko
2021-09-29  8:13   ` Michal Orzel
2021-09-29  8:16     ` Jan Beulich
2021-09-29  8:24       ` Oleksandr Andrushchenko
2021-09-29  8:36         ` Jan Beulich
2021-09-29  8:58           ` Oleksandr Andrushchenko
2021-09-29  8:16     ` Oleksandr Andrushchenko
2021-09-23 12:54 ` [PATCH v2 08/11] vpci/header: Emulate PCI_COMMAND register for guests Oleksandr Andrushchenko
2021-09-28  7:34   ` Michal Orzel
2021-09-23 12:54 ` [PATCH v2 09/11] vpci/header: Reset the command register when adding devices Oleksandr Andrushchenko
2021-09-28  7:38   ` Michal Orzel
2021-09-23 12:55 ` [PATCH v2 10/11] vpci: Add initial support for virtual PCI bus topology Oleksandr Andrushchenko
2021-09-28  7:48   ` Michal Orzel
2021-09-28  7:59     ` Jan Beulich
2021-09-28  8:17       ` Michal Orzel
2021-09-28 12:58         ` Oleksandr Andrushchenko
2021-09-29  9:03           ` Oleksandr Andrushchenko
2021-09-29  9:09             ` Jan Beulich
2021-09-29 11:56               ` Oleksandr Andrushchenko
2021-09-29 12:54                 ` Jan Beulich
2021-09-29 13:16                   ` Oleksandr Andrushchenko
2021-09-29 13:23                     ` Jan Beulich
2021-09-29 13:49                       ` Oleksandr Andrushchenko
2021-09-29 14:07                         ` Jan Beulich
2021-09-29 14:16                           ` Oleksandr Andrushchenko
2021-09-23 12:55 ` [PATCH v2 11/11] xen/arm: Translate virtual PCI bus topology for guests Oleksandr Andrushchenko
2021-09-27 11:31   ` Jan Beulich
2021-09-27 12:08     ` Oleksandr Andrushchenko
2021-09-27 13:34       ` Jan Beulich
2021-09-27 13:43         ` Oleksandr Andrushchenko
2021-09-27 13:51           ` Jan Beulich
2021-09-27 14:04             ` Oleksandr Andrushchenko
2021-09-27 14:16               ` Jan Beulich
2021-09-27 14:20                 ` Oleksandr Andrushchenko

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=20210923125501.234252-6-andr2000@gmail.com \
    --to=andr2000@gmail.com \
    --cc=Artem_Mygaiev@epam.com \
    --cc=bertrand.marquis@arm.com \
    --cc=jbeulich@suse.com \
    --cc=julien@xen.org \
    --cc=oleksandr_andrushchenko@epam.com \
    --cc=oleksandr_tyshchenko@epam.com \
    --cc=rahul.singh@arm.com \
    --cc=roger.pau@citrix.com \
    --cc=sstabellini@kernel.org \
    --cc=volodymyr_babchuk@epam.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.