From: Matt Evans <matt@ozlabs.org>
To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org
Cc: penberg@kernel.org, asias.hejun@gmail.com,
levinsasha928@gmail.com, gorcunov@gmail.com
Subject: [PATCH V2 21/23] kvm tools: Add pci__config_{rd,wr}(), pci__find_dev()
Date: Fri, 09 Dec 2011 06:55:45 +0000 [thread overview]
Message-ID: <4EE1B0F1.4030808@ozlabs.org> (raw)
In-Reply-To: <cover.1323413420.git.matt@ozlabs.org>
This allows config space access in a more natural manner than clunky x86 IO ports,
and is useful for other architectures. Internally, the x86 IO port access uses
these new config space interfaces.
Signed-off-by: Matt Evans <matt@ozlabs.org>
---
tools/kvm/include/kvm/pci.h | 9 +++++-
tools/kvm/pci.c | 63 ++++++++++++++++++++++++++-----------------
2 files changed, 45 insertions(+), 27 deletions(-)
diff --git a/tools/kvm/include/kvm/pci.h b/tools/kvm/include/kvm/pci.h
index 21f93d0..07b5403 100644
--- a/tools/kvm/include/kvm/pci.h
+++ b/tools/kvm/include/kvm/pci.h
@@ -7,6 +7,8 @@
#include <linux/msi.h>
#include <endian.h>
+#include "kvm/kvm.h"
+
#define PCI_MAX_DEVICES 256
/*
* PCI Configuration Mechanism #1 I/O ports. See Section 3.7.4.1.
@@ -21,7 +23,7 @@
union pci_config_address {
struct {
#if __BYTE_ORDER = __LITTLE_ENDIAN
- unsigned zeros : 2; /* 1 .. 0 */
+ unsigned reg_offset : 2; /* 1 .. 0 */
unsigned register_number : 6; /* 7 .. 2 */
unsigned function_number : 3; /* 10 .. 8 */
unsigned device_number : 5; /* 15 .. 11 */
@@ -35,7 +37,7 @@ union pci_config_address {
unsigned device_number : 5; /* 15 .. 11 */
unsigned function_number : 3; /* 10 .. 8 */
unsigned register_number : 6; /* 7 .. 2 */
- unsigned zeros : 2; /* 1 .. 0 */
+ unsigned reg_offset : 2; /* 1 .. 0 */
#endif
};
u32 w;
@@ -84,6 +86,9 @@ struct pci_device_header {
void pci__init(void);
void pci__register(struct pci_device_header *dev, u8 dev_num);
+struct pci_device_header *pci__find_dev(u8 dev_num);
u32 pci_get_io_space_block(u32 size);
+void pci__config_wr(struct kvm *kvm, union pci_config_address addr, void *data, int size);
+void pci__config_rd(struct kvm *kvm, union pci_config_address addr, void *data, int size);
#endif /* KVM__PCI_H */
diff --git a/tools/kvm/pci.c b/tools/kvm/pci.c
index 5bbcbc7..95df169 100644
--- a/tools/kvm/pci.c
+++ b/tools/kvm/pci.c
@@ -76,21 +76,45 @@ static bool pci_device_exists(u8 bus_number, u8 device_number, u8 function_numbe
static bool pci_config_data_out(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size)
{
- unsigned long start;
- u8 dev_num;
+ /*
+ * If someone accesses PCI configuration space offsets that are not
+ * aligned to 4 bytes, it uses ioports to signify that.
+ */
+ pci_config_address.reg_offset = port - PCI_CONFIG_DATA;
+
+ pci__config_wr(kvm, pci_config_address, data, size);
+ return true;
+}
+
+static bool pci_config_data_in(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size)
+{
/*
* If someone accesses PCI configuration space offsets that are not
* aligned to 4 bytes, it uses ioports to signify that.
*/
- start = port - PCI_CONFIG_DATA;
+ pci_config_address.reg_offset = port - PCI_CONFIG_DATA;
- dev_num = pci_config_address.device_number;
+ pci__config_rd(kvm, pci_config_address, data, size);
+
+ return true;
+}
+
+static struct ioport_operations pci_config_data_ops = {
+ .io_in = pci_config_data_in,
+ .io_out = pci_config_data_out,
+};
+
+void pci__config_wr(struct kvm *kvm, union pci_config_address addr, void *data, int size)
+{
+ u8 dev_num;
+
+ dev_num = addr.device_number;
if (pci_device_exists(0, dev_num, 0)) {
unsigned long offset;
- offset = start + (pci_config_address.register_number << 2);
+ offset = addr.w & 0xff;
if (offset < sizeof(struct pci_device_header)) {
void *p = pci_devices[dev_num];
u8 bar = (offset - PCI_BAR_OFFSET(0)) / (sizeof(u32));
@@ -116,27 +140,18 @@ static bool pci_config_data_out(struct ioport *ioport, struct kvm *kvm, u16 port
}
}
}
-
- return true;
}
-static bool pci_config_data_in(struct ioport *ioport, struct kvm *kvm, u16 port, void *data, int size)
+void pci__config_rd(struct kvm *kvm, union pci_config_address addr, void *data, int size)
{
- unsigned long start;
u8 dev_num;
- /*
- * If someone accesses PCI configuration space offsets that are not
- * aligned to 4 bytes, it uses ioports to signify that.
- */
- start = port - PCI_CONFIG_DATA;
-
- dev_num = pci_config_address.device_number;
+ dev_num = addr.device_number;
if (pci_device_exists(0, dev_num, 0)) {
unsigned long offset;
- offset = start + (pci_config_address.register_number << 2);
+ offset = addr.w & 0xff;
if (offset < sizeof(struct pci_device_header)) {
void *p = pci_devices[dev_num];
@@ -145,22 +160,20 @@ static bool pci_config_data_in(struct ioport *ioport, struct kvm *kvm, u16 port,
memset(data, 0x00, size);
} else
memset(data, 0xff, size);
-
- return true;
}
-static struct ioport_operations pci_config_data_ops = {
- .io_in = pci_config_data_in,
- .io_out = pci_config_data_out,
-};
-
void pci__register(struct pci_device_header *dev, u8 dev_num)
{
assert(dev_num < PCI_MAX_DEVICES);
-
pci_devices[dev_num] = dev;
}
+struct pci_device_header *pci__find_dev(u8 dev_num)
+{
+ assert(dev_num < PCI_MAX_DEVICES);
+ return pci_devices[dev_num];
+}
+
void pci__init(void)
{
ioport__register(PCI_CONFIG_DATA + 0, &pci_config_data_ops, 4, NULL);
next prev parent reply other threads:[~2011-12-09 6:55 UTC|newest]
Thread overview: 37+ messages / expand[flat|nested] mbox.gz Atom feed top
[not found] <cover.1323413420.git.matt@ozlabs.org>
2011-12-09 6:52 ` [PATCH V2 01/23] kvm tools: Only build/init i8042 on x86 Matt Evans
2011-12-09 6:52 ` [PATCH V2 03/23] kvm tools: Re-arrange Makefile to heed CFLAGS before Matt Evans
2011-12-09 6:53 ` [PATCH V2 02/23] kvm tools: Add Makefile parameter for kernel include Matt Evans
2011-12-09 6:53 ` [PATCH V2 04/23] kvm tools: Get correct 64-bit types on PPC64 and Matt Evans
2011-12-09 8:24 ` [PATCH V2 04/23] kvm tools: Get correct 64-bit types on PPC64 Sasha Levin
2011-12-09 8:29 ` [PATCH V2 04/23] kvm tools: Get correct 64-bit types on PPC64 and Pekka Enberg
2011-12-12 1:03 ` [PATCH V2 04/23] kvm tools: Get correct 64-bit types on PPC64 Matt Evans
2011-12-12 5:57 ` Pekka Enberg
2011-12-13 6:44 ` Matt Evans
2011-12-09 6:53 ` [PATCH V2 05/23] kvm tools: Add arch-specific KVM_RUN exit handling Matt Evans
2011-12-09 6:54 ` [PATCH V2 06/23] kvm tools: Don't die if KVM_CAP_NR_VCPUS isn't available Matt Evans
2011-12-09 6:54 ` [PATCH V2 07/23] kvm tools: Fix KVM_RUN exit code check Matt Evans
2011-12-09 6:54 ` [PATCH V2 08/23] kvm tools: Add kvm__arch_periodic_poll() Matt Evans
2011-12-09 6:54 ` [PATCH V2 09/23] kvm tools: Move arch-specific cmdline init into Matt Evans
2011-12-09 6:54 ` [PATCH V2 10/23] kvm tools: Add CONSOLE_HV term type and allow it Matt Evans
2011-12-09 6:54 ` [PATCH V2 11/23] kvm tools: Fix term_getc(), term_getc_iov() endian Matt Evans
2011-12-09 6:54 ` [PATCH V2 12/23] kvm tools: Allow initrd_check() to match a cpio Matt Evans
2011-12-09 6:54 ` [PATCH V2 13/23] kvm tools: Allow load_flat_binary() to load an initrd Matt Evans
2011-12-09 6:55 ` [PATCH V2 14/23] kvm tools: Initialise PCI before devices start getting Matt Evans
2011-12-09 6:55 ` [PATCH V2 15/23] kvm tools: Perform CPU and firmware setup after Matt Evans
2011-12-09 6:55 ` [PATCH V2 16/23] kvm tools: Init IRQs after determining nrcpus Matt Evans
2011-12-09 6:55 ` [PATCH V2 17/23] kvm tools: Add ability to map guest RAM from hugetlbfs Matt Evans
2011-12-09 7:39 ` [PATCH V2 17/23] kvm tools: Add ability to map guest RAM from Sasha Levin
2011-12-12 5:05 ` Matt Evans
2011-12-09 8:38 ` [PATCH V2 17/23] kvm tools: Add ability to map guest RAM from hugetlbfs Pekka Enberg
2011-12-12 6:19 ` [PATCH V2 17/23] kvm tools: Add ability to map guest RAM from Matt Evans
2011-12-09 8:42 ` [PATCH V2 17/23] kvm tools: Add ability to map guest RAM from hugetlbfs Pekka Enberg
2011-12-12 5:17 ` [PATCH V2 17/23] kvm tools: Add ability to map guest RAM from Matt Evans
2011-12-12 6:06 ` [PATCH V2 17/23] kvm tools: Add ability to map guest RAM from hugetlbfs Pekka Enberg
2011-12-09 6:55 ` [PATCH V2 18/23] kvm tools: Move PCI_MAX_DEVICES to pci.h Matt Evans
2011-12-09 6:55 ` [PATCH V2 19/23] kvm tools: Endian-sanitise pci.h and PCI device Matt Evans
2011-12-09 6:55 ` [PATCH V2 20/23] kvm tools: Correctly set virtio-pci bar_size and Matt Evans
2011-12-09 6:55 ` Matt Evans [this message]
2011-12-09 6:55 ` [PATCH V2 22/23] kvm tools: Arch-specific define for PCI MMIO allocation Matt Evans
2011-12-09 6:56 ` [PATCH V2 23/23] kvm tools: Create arch-specific kvm_cpu__emulate_{mm}io() Matt Evans
2011-12-09 7:53 ` [PATCH V2 23/23] kvm tools: Create arch-specific Sasha Levin
2011-12-12 1:08 ` [PATCH V2 23/23] kvm tools: Create arch-specific kvm_cpu__emulate_{mm}io() Matt Evans
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=4EE1B0F1.4030808@ozlabs.org \
--to=matt@ozlabs.org \
--cc=asias.hejun@gmail.com \
--cc=gorcunov@gmail.com \
--cc=kvm-ppc@vger.kernel.org \
--cc=kvm@vger.kernel.org \
--cc=levinsasha928@gmail.com \
--cc=penberg@kernel.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 a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox