From: Peter Xu <peterx@redhat.com>
To: kvm@vger.kernel.org
Cc: drjones@redhat.com, agordeev@redhat.com, jan.kiszka@web.de,
rkrcmar@redhat.com, pbonzini@redhat.com, peterx@redhat.com
Subject: [PATCH kvm-unit-tests v5 10/14] pci: provide pci_enable_defaults()
Date: Tue, 15 Nov 2016 17:25:05 -0500 [thread overview]
Message-ID: <1479248709-10281-11-git-send-email-peterx@redhat.com> (raw)
In-Reply-To: <1479248709-10281-1-git-send-email-peterx@redhat.com>
One helper function to set/clear specific bit in PCI_COMMAND register is
introduced. Then, provide a function to do most of the common PCI init
work.
Suggested-by: Andrew Jones <drjones@redhat.com>
Reviewed-by: Andrew Jones <drjones@redhat.com>
Signed-off-by: Peter Xu <peterx@redhat.com>
---
lib/pci.c | 19 +++++++++++++++++++
lib/pci.h | 2 ++
2 files changed, 21 insertions(+)
diff --git a/lib/pci.c b/lib/pci.c
index 462c370..1c59e13 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 &&
@@ -242,3 +254,10 @@ void pci_scan_bars(struct pci_dev *dev)
}
}
}
+
+void pci_enable_defaults(struct pci_dev *dev)
+{
+ pci_scan_bars(dev);
+ /* Enable device DMA operations */
+ pci_cmd_set_clr(dev, PCI_COMMAND_MASTER, 0);
+}
diff --git a/lib/pci.h b/lib/pci.h
index 302b47c..a9ce652 100644
--- a/lib/pci.h
+++ b/lib/pci.h
@@ -25,6 +25,8 @@ struct pci_dev {
extern void pci_dev_init(struct pci_dev *dev, pcidevaddr_t bdf);
extern void pci_scan_bars(struct pci_dev *dev);
+extern void pci_cmd_set_clr(struct pci_dev *dev, uint16_t set, uint16_t clr);
+extern void pci_enable_defaults(struct pci_dev *dev);
extern bool pci_probe(void);
extern void pci_print(void);
--
2.7.4
next prev parent reply other threads:[~2016-11-15 22:25 UTC|newest]
Thread overview: 28+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-11-15 22:24 [PATCH kvm-unit-tests v5 00/14] VT-d unit test Peter Xu
2016-11-15 22:24 ` [PATCH kvm-unit-tests v5 01/14] pci: fix missing extern for pci_testdev() Peter Xu
2016-11-16 9:26 ` Andrew Jones
2016-11-15 22:24 ` [PATCH kvm-unit-tests v5 02/14] x86/asm: add cpu_relax() Peter Xu
2016-11-15 22:24 ` [PATCH kvm-unit-tests v5 03/14] libcflat: introduce is_power_of_2() Peter Xu
2016-11-15 22:24 ` [PATCH kvm-unit-tests v5 04/14] x86: intel-iommu: add vt-d init test Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 05/14] libcflat: add IS_ALIGNED() macro, and page sizes Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 06/14] libcflat: moving MIN/MAX here Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 07/14] vm/page: provide PGDIR_OFFSET() macro Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 08/14] pci: introduce struct pci_dev Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 09/14] pci: provide pci_scan_bars() Peter Xu
2016-11-16 9:50 ` Alexander Gordeev
2016-11-21 7:27 ` Peter Xu
2016-11-21 19:24 ` Alexander Gordeev
2016-11-22 2:16 ` Peter Xu
2016-11-15 22:25 ` Peter Xu [this message]
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 11/14] pci: edu: introduce pci-edu helpers Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 12/14] x86: intel-iommu: add dmar test Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 13/14] pci: add msi support for 32/64bit address Peter Xu
2016-11-21 19:27 ` Alexander Gordeev
2016-11-22 4:59 ` Peter Xu
2016-11-22 7:03 ` Alexander Gordeev
2016-11-22 7:21 ` Peter Xu
2016-11-22 12:30 ` Andrew Jones
2016-11-23 2:40 ` Peter Xu
2016-11-23 10:36 ` Andrew Jones
2016-11-23 10:39 ` Peter Xu
2016-11-15 22:25 ` [PATCH kvm-unit-tests v5 14/14] x86: intel-iommu: add IR MSI test Peter Xu
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=1479248709-10281-11-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=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).