qemu-devel.nongnu.org archive mirror
 help / color / mirror / Atom feed
From: Peter Xu <peterx@redhat.com>
To: qemu-devel@nongnu.org, kvm@vger.kernel.org
Cc: "Jan Kiszka" <jan.kiszka@web.de>,
	"Paolo Bonzini" <pbonzini@redhat.com>,
	agordeev@redhat.com, "Radim Krčmář" <rkrcmar@redhat.com>,
	"Andrew Jones" <drjones@redhat.com>,
	peterx@redhat.com
Subject: [Qemu-devel] [kvm-unit-tests PATCH 2/8] pci: introduce pci_msi_set_enable()
Date: Fri, 30 Dec 2016 16:55:54 +0800	[thread overview]
Message-ID: <1483088160-6714-3-git-send-email-peterx@redhat.com> (raw)
In-Reply-To: <1483088160-6714-1-git-send-email-peterx@redhat.com>

Generalize this function out of pci_setup_msi(), then it can be further
used to enable INTx (or, disable MSI).

Signed-off-by: Peter Xu <peterx@redhat.com>
---
 lib/pci.c | 19 +++++++++++++++++--
 lib/pci.h |  1 +
 2 files changed, 18 insertions(+), 2 deletions(-)

diff --git a/lib/pci.c b/lib/pci.c
index a7cfacb..5062036 100644
--- a/lib/pci.c
+++ b/lib/pci.c
@@ -39,6 +39,22 @@ void pci_cap_walk(struct pci_dev *dev)
 	}
 }
 
+void pci_msi_set_enable(struct pci_dev *dev, bool enabled)
+{
+	uint16_t msi_control;
+	uint16_t offset;
+
+	offset = dev->msi_offset;
+	msi_control = pci_config_readw(dev->bdf, offset + PCI_MSI_FLAGS);
+
+	if (enabled)
+		msi_control |= PCI_MSI_FLAGS_ENABLE;
+	else
+		msi_control &= ~PCI_MSI_FLAGS_ENABLE;
+
+	pci_config_writew(dev->bdf, offset + PCI_MSI_FLAGS, msi_control);
+}
+
 bool pci_setup_msi(struct pci_dev *dev, uint64_t msi_addr, uint32_t msi_data)
 {
 	uint16_t msi_control;
@@ -69,8 +85,7 @@ bool pci_setup_msi(struct pci_dev *dev, uint64_t msi_addr, uint32_t msi_data)
 	}
 	printf("addr=0x%lx, data=0x%x\n", msi_addr, msi_data);
 
-	msi_control |= PCI_MSI_FLAGS_ENABLE;
-	pci_config_writew(addr, offset + PCI_MSI_FLAGS, msi_control);
+	pci_msi_set_enable(dev, true);
 
 	return true;
 }
diff --git a/lib/pci.h b/lib/pci.h
index df86951..0815754 100644
--- a/lib/pci.h
+++ b/lib/pci.h
@@ -65,6 +65,7 @@ extern bool pci_bar_is_valid(struct pci_dev *dev, int bar_num);
 extern void pci_bar_print(struct pci_dev *dev, int bar_num);
 extern void pci_dev_print_id(pcidevaddr_t dev);
 extern uint8_t pci_intx_line(struct pci_dev *dev);
+void pci_msi_set_enable(struct pci_dev *dev, bool enabled);
 
 extern int pci_testdev(void);
 
-- 
2.7.4

  parent reply	other threads:[~2016-12-30  8:56 UTC|newest]

Thread overview: 10+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2016-12-30  8:55 [Qemu-devel] [kvm-unit-tests PATCH 0/8] VT-d ioapic irq test Peter Xu
2016-12-30  8:55 ` [Qemu-devel] [kvm-unit-tests PATCH 1/8] pci: introduce pci_intx_line() Peter Xu
2016-12-30  8:55 ` Peter Xu [this message]
2016-12-30  8:55 ` [Qemu-devel] [kvm-unit-tests PATCH 3/8] lib/asm-generic: add atomic.h Peter Xu
2016-12-30  8:55 ` [Qemu-devel] [kvm-unit-tests PATCH 4/8] x86: ioapic: generalize trigger mode Peter Xu
2016-12-30  8:55 ` [Qemu-devel] [kvm-unit-tests PATCH 5/8] intel-iommu: add report prefixes Peter Xu
2016-12-30  8:55 ` [Qemu-devel] [kvm-unit-tests PATCH 6/8] intel-iommu: use atomic ops for irte index alloc Peter Xu
2016-12-30  8:55 ` [Qemu-devel] [kvm-unit-tests PATCH 7/8] intel-iommu: allow setup trigger mode for irte Peter Xu
2016-12-30  8:56 ` [Qemu-devel] [kvm-unit-tests PATCH 8/8] intel-iommu: add ioapic irq test Peter Xu
2017-01-12 12:14 ` [Qemu-devel] [kvm-unit-tests PATCH 0/8] VT-d " Paolo Bonzini

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=1483088160-6714-3-git-send-email-peterx@redhat.com \
    --to=peterx@redhat.com \
    --cc=agordeev@redhat.com \
    --cc=drjones@redhat.com \
    --cc=jan.kiszka@web.de \
    --cc=kvm@vger.kernel.org \
    --cc=pbonzini@redhat.com \
    --cc=qemu-devel@nongnu.org \
    --cc=rkrcmar@redhat.com \
    /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).