From patchwork Tue Dec 6 03:42:51 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Matt Evans X-Patchwork-Id: 129521 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by ozlabs.org (Postfix) with ESMTP id EE0C61007D5 for ; Tue, 6 Dec 2011 14:42:06 +1100 (EST) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S932878Ab1LFDmF (ORCPT ); Mon, 5 Dec 2011 22:42:05 -0500 Received: from ozlabs.org ([203.10.76.45]:35304 "EHLO ozlabs.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S932871Ab1LFDmE (ORCPT ); Mon, 5 Dec 2011 22:42:04 -0500 Received: from [10.61.2.183] (ibmaus65.lnk.telstra.net [165.228.126.9]) (using TLSv1 with cipher ECDHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPSA id 318EA1007D5; Tue, 6 Dec 2011 14:42:01 +1100 (EST) Message-ID: <4EDD8F3B.5030101@ozlabs.org> Date: Tue, 06 Dec 2011 14:42:51 +1100 From: Matt Evans User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.2.23) Gecko/20110921 Thunderbird/3.1.15 MIME-Version: 1.0 To: kvm@vger.kernel.org, kvm-ppc@vger.kernel.org Subject: [PATCH 26/28] kvm tools: Add pci__config_{rd, wr}(), pci__find_dev() and fix PCI config register addressing References: In-Reply-To: Sender: kvm-ppc-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm-ppc@vger.kernel.org This allows config space access in a more natural manner than clunky x86 IO ports, and is useful for other architectures. Furthermore, the actual registers were only accessed in 32bit chunks; other systems (e.g. PPC) allow smaller accesses so that, for example, the 16-bit config field can be read directly. This patch allows this sort of addressing. Signed-off-by: Matt Evans --- tools/kvm/include/kvm/pci.h | 5 +++ tools/kvm/pci.c | 63 +++++++++++++++++++++++++++--------------- 2 files changed, 45 insertions(+), 23 deletions(-) -- To unsubscribe from this list: send the line "unsubscribe kvm-ppc" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/tools/kvm/include/kvm/pci.h b/tools/kvm/include/kvm/pci.h index 88e92dc..be2b0bc 100644 --- a/tools/kvm/include/kvm/pci.h +++ b/tools/kvm/include/kvm/pci.h @@ -7,6 +7,8 @@ #include #include +#include "kvm/kvm.h" + #define PCI_MAX_DEVICES 256 /* * PCI Configuration Mechanism #1 I/O ports. See Section 3.7.4.1. @@ -82,6 +84,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..8282e23 100644 --- a/tools/kvm/pci.c +++ b/tools/kvm/pci.c @@ -77,7 +77,6 @@ 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 @@ -85,12 +84,41 @@ static bool pci_config_data_out(struct ioport *ioport, struct kvm *kvm, u16 port */ start = port - PCI_CONFIG_DATA; - dev_num = pci_config_address.device_number; + 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) +{ + unsigned long start; + + /* + * 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_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 +144,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 +164,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);