[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH v9 11/16] vpci/header: reset the command register when adding devices


  • To: "xen-devel@xxxxxxxxxxxxxxxxxxxx" <xen-devel@xxxxxxxxxxxxxxxxxxxx>
  • From: Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Date: Tue, 29 Aug 2023 23:19:45 +0000
  • Accept-language: en-US
  • Arc-authentication-results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=epam.com; dmarc=pass action=none header.from=epam.com; dkim=pass header.d=epam.com; arc=none
  • Arc-message-signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-AntiSpam-MessageData-ChunkCount:X-MS-Exchange-AntiSpam-MessageData-0:X-MS-Exchange-AntiSpam-MessageData-1; bh=9RSd6gDogowC6YhVNDeraATH9brdfi3Ahv2ppWZqTGA=; b=atcBiMjCfxvymrQ4SJ0twGA54cS7eYzAlura4+BMruMC4SzahHXr/fdCX7aSgfU6NNo9H8R0J8khXoTTqgMbgBig7HojyEjLAM78Yna6hIhv6IEmQT5uXNWSTZqr3n22rxNYPle+Cltp5YIaWiJJG8Y0R0DCkqEzA5K9d/41jY2DlGnfNuo59tT2EmBFFAqHkW45ncO9GNrklrPHrBYZIO5o8D5DoI3FvYmrywwYe2pNZaJmU7/HOkGHC/YBNl+6KRIugZUBN08Y1OrbHUySa7Dwc/9fu53GXQfmRWZ9TCPBbqktSBuUHj8DtaPc/rabrPx1BsQxjkFR1vcUno4JTw==
  • Arc-seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=NFNvxgSYc7546OdTijmQX44mWvoH4tcLfFaU9etjqk16saqG/2vvNZuHwPYOFNxVYYZiavhrGkXxfHcHy9C8+xMgyoFoUIs0GmrFJFs4akMsUyjoL/F6BSDYO2R/C0v2ieE2SZA6sNkq0Kue3i1s3ZwcaUxswZPbcwkv/ht7z0ebblhGsA9JEgTIQibsviN7uptXXVcelUqHuKNFW1xhI4yEjRwy/E2GQuGgpiybbMKPAUw+vz245GjFk4uL2a97oHoXf+/Nh1hLGhMyZTjmea0iLtTbi9u5TETjCFgqwt0SvBZWzHOUJJrlvJPhiD0vaNP6iDIEr5pBCzunYR4VvQ==
  • Cc: Stewart Hildebrand <stewart.hildebrand@xxxxxxx>, Oleksandr Andrushchenko <Oleksandr_Andrushchenko@xxxxxxxx>, Roger Pau Monné <roger.pau@xxxxxxxxxx>, Volodymyr Babchuk <Volodymyr_Babchuk@xxxxxxxx>
  • Delivery-date: Tue, 29 Aug 2023 23:20:05 +0000
  • List-id: Xen developer discussion <xen-devel.lists.xenproject.org>
  • Thread-index: AQHZ2s9MXPBeWfv85UCGprRCw+JOTA==
  • Thread-topic: [PATCH v9 11/16] vpci/header: reset the command register when adding devices

From: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>

Reset the command register when assigning a PCI device to a guest:
according to the PCI spec the PCI_COMMAND register is typically all 0's
after reset, but this might not be true for the guest as it needs
to respect host's settings.
For that reason, do not write 0 to the PCI_COMMAND register directly,
but go through the corresponding emulation layer (cmd_write), which
will take care about the actual bits written. Also, honor value of
PCI_COMMAND_VGA_PALETTE value, which is set by firmware.

Signed-off-by: Oleksandr Andrushchenko <oleksandr_andrushchenko@xxxxxxxx>
Signed-off-by: Volodymyr Babchuk <volodymyr_babchuk@xxxxxxxx>
---
Since v9:
- Honor PCI_COMMAND_VGA_PALETTE bit
Since v6:
- use cmd_write directly without introducing emulate_cmd_reg
- update commit message with more description on all 0's in PCI_COMMAND
Since v5:
- updated commit message
Since v1:
 - do not write 0 to the command register, but respect host settings.
---
 xen/drivers/vpci/header.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/xen/drivers/vpci/header.c b/xen/drivers/vpci/header.c
index e351db4620..1d243eeaf9 100644
--- a/xen/drivers/vpci/header.c
+++ b/xen/drivers/vpci/header.c
@@ -762,6 +762,12 @@ static int cf_check init_bars(struct pci_dev *pdev)
         return -EOPNOTSUPP;
     }
 
+    /* Reset the command register for guests. We want to preserve only
+     * PCI_COMMAND_VGA_PALETTE as it is configured by firmware */
+    cmd = pci_conf_read16(pdev->sbdf, PCI_COMMAND);
+    if ( !is_hwdom )
+        cmd_write(pdev, PCI_COMMAND, cmd & PCI_COMMAND_VGA_PALETTE, header);
+
     /* Setup a handler for the command register. */
     if ( is_hwdom )
         rc = vpci_add_register(pdev->vpci, vpci_hw_read16, cmd_write, 
PCI_COMMAND,
@@ -776,7 +782,6 @@ static int cf_check init_bars(struct pci_dev *pdev)
         return 0;
 
     /* Disable memory decoding before sizing. */
-    cmd = pci_conf_read16(pdev->sbdf, PCI_COMMAND);
     if ( cmd & PCI_COMMAND_MEMORY )
         pci_conf_write16(pdev->sbdf, PCI_COMMAND, cmd & ~PCI_COMMAND_MEMORY);
 
-- 
2.41.0



 


Rackspace

Lists.xenproject.org is hosted with RackSpace, monitoring our
servers 24x7x365 and backed by RackSpace's Fanatical Support®.