From patchwork Tue Jun 2 15:02:26 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 27481 Received: from vger.kernel.org (vger.kernel.org [209.132.176.167]) by demeter.kernel.org (8.14.2/8.14.2) with ESMTP id n52F6xah011479 for ; Tue, 2 Jun 2009 15:07:00 GMT Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756439AbZFBPF6 (ORCPT ); Tue, 2 Jun 2009 11:05:58 -0400 Received: (majordomo@vger.kernel.org) by vger.kernel.org id S1755536AbZFBPF6 (ORCPT ); Tue, 2 Jun 2009 11:05:58 -0400 Received: from mx2.redhat.com ([66.187.237.31]:47703 "EHLO mx2.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756263AbZFBPF4 (ORCPT ); Tue, 2 Jun 2009 11:05:56 -0400 Received: from int-mx2.corp.redhat.com (int-mx2.corp.redhat.com [172.16.27.26]) by mx2.redhat.com (8.13.8/8.13.8) with ESMTP id n52F3Mkl013112; Tue, 2 Jun 2009 11:03:22 -0400 Received: from ns3.rdu.redhat.com (ns3.rdu.redhat.com [10.11.255.199]) by int-mx2.corp.redhat.com (8.13.1/8.13.1) with ESMTP id n52F3L0H011617; Tue, 2 Jun 2009 11:03:21 -0400 Received: from redhat.com (dhcp-0-223.tlv.redhat.com [10.35.0.223]) by ns3.rdu.redhat.com (8.13.8/8.13.8) with ESMTP id n52F3I4c019269; Tue, 2 Jun 2009 11:03:18 -0400 Date: Tue, 2 Jun 2009 18:02:26 +0300 From: "Michael S. Tsirkin" To: Paul Brook , Avi Kivity , qemu-devel@nongnu.org, Carsten Otte , kvm@vger.kernel.org, Rusty Russell , virtualization@lists.linux-foundation.org, Christian Borntraeger , Blue Swirl , Anthony Liguori Subject: [PATCHv2 04/13] qemu: helper routines for pci access. Message-ID: <20090602150226.GE6554@redhat.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: User-Agent: Mutt/1.5.18 (2008-05-17) X-Scanned-By: MIMEDefang 2.58 on 172.16.27.26 Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org Add inline routines for convenient access to pci devices with correct (little) endianness. Will be used by MSI-X support. Signed-off-by: Michael S. Tsirkin --- hw/pci.h | 30 +++++++++++++++++++++++++++--- 1 files changed, 27 insertions(+), 3 deletions(-) diff --git a/hw/pci.h b/hw/pci.h index 40137c6..4e112a3 100644 --- a/hw/pci.h +++ b/hw/pci.h @@ -240,21 +240,45 @@ PCIBus *pci_bridge_init(PCIBus *bus, int devfn, uint16_t vid, uint16_t did, pci_map_irq_fn map_irq, const char *name); static inline void +pci_set_word(uint8_t *config, uint16_t val) +{ + cpu_to_le16wu((uint16_t *)config, val); +} + +static inline uint16_t +pci_get_word(uint8_t *config) +{ + return le16_to_cpupu((uint16_t *)config); +} + +static inline void +pci_set_long(uint8_t *config, uint32_t val) +{ + cpu_to_le32wu((uint32_t *)config, val); +} + +static inline uint32_t +pci_get_long(uint8_t *config) +{ + return le32_to_cpupu((uint32_t *)config); +} + +static inline void pci_config_set_vendor_id(uint8_t *pci_config, uint16_t val) { - cpu_to_le16wu((uint16_t *)&pci_config[PCI_VENDOR_ID], val); + pci_set_word(&pci_config[PCI_VENDOR_ID], val); } static inline void pci_config_set_device_id(uint8_t *pci_config, uint16_t val) { - cpu_to_le16wu((uint16_t *)&pci_config[PCI_DEVICE_ID], val); + pci_set_word(&pci_config[PCI_DEVICE_ID], val); } static inline void pci_config_set_class(uint8_t *pci_config, uint16_t val) { - cpu_to_le16wu((uint16_t *)&pci_config[PCI_CLASS_DEVICE], val); + pci_set_word(&pci_config[PCI_CLASS_DEVICE], val); } typedef void (*pci_qdev_initfn)(PCIDevice *dev);