From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Xu Subject: [PATCH kvm-unit-tests v2 10/17] pci: provide pci_cmd_set_clr() Date: Wed, 9 Nov 2016 10:10:17 -0500 Message-ID: <1478704224-20472-11-git-send-email-peterx@redhat.com> References: <1478704224-20472-1-git-send-email-peterx@redhat.com> Cc: drjones@redhat.com, rkrcmar@redhat.com, peterx@redhat.com, agordeev@redhat.com, jan.kiszka@web.de, pbonzini@redhat.com To: kvm@vger.kernel.org Return-path: Received: from mx1.redhat.com ([209.132.183.28]:43894 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S933958AbcKIPKp (ORCPT ); Wed, 9 Nov 2016 10:10:45 -0500 In-Reply-To: <1478704224-20472-1-git-send-email-peterx@redhat.com> Sender: kvm-owner@vger.kernel.org List-ID: Helper function to set/clear specific bit in PCI_COMMAND register. Signed-off-by: Peter Xu --- lib/pci.c | 12 ++++++++++++ lib/pci.h | 1 + 2 files changed, 13 insertions(+) diff --git a/lib/pci.c b/lib/pci.c index c063d53..fd17ea5 100644 --- a/lib/pci.c +++ b/lib/pci.c @@ -7,6 +7,18 @@ #include "pci.h" #include "asm/pci.h" +void pci_cmd_set_clr(struct pci_dev *dev, uint16_t set, uint16_t clr) +{ + uint16_t val = pci_config_readw(dev->bdf, PCI_COMMAND); + + /* No overlap is allowed */ + assert((set & clr) == 0); + val |= set; + val &= ~clr; + + pci_config_writew(dev->bdf, PCI_COMMAND, val); +} + bool pci_dev_exists(pcidevaddr_t dev) { return (pci_config_readw(dev, PCI_VENDOR_ID) != 0xffff && diff --git a/lib/pci.h b/lib/pci.h index e452819..de15086 100644 --- a/lib/pci.h +++ b/lib/pci.h @@ -25,6 +25,7 @@ struct pci_dev { void pci_dev_init(struct pci_dev *dev, pcidevaddr_t bdf); void pci_scan_bars(struct pci_dev *dev); +void pci_cmd_set_clr(struct pci_dev *dev, uint16_t set, uint16_t clr); extern bool pci_probe(void); extern void pci_print(void); -- 2.7.4