From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from eggs.gnu.org ([2001:4830:134:3::10]:52750) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAjXA-0001Pu-Ir for qemu-devel@nongnu.org; Thu, 02 Jul 2015 14:48:31 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ZAjX1-00061v-Sf for qemu-devel@nongnu.org; Thu, 02 Jul 2015 14:48:28 -0400 Received: from mail-wi0-x22b.google.com ([2a00:1450:400c:c05::22b]:34003) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1ZAjX1-0005zi-KL for qemu-devel@nongnu.org; Thu, 02 Jul 2015 14:48:19 -0400 Received: by wiar9 with SMTP id r9so110017059wia.1 for ; Thu, 02 Jul 2015 11:48:17 -0700 (PDT) Sender: Paolo Bonzini References: <1435842022-13980-1-git-send-email-mst@redhat.com> From: Paolo Bonzini Message-ID: <5595876E.2040803@redhat.com> Date: Thu, 2 Jul 2015 20:48:14 +0200 MIME-Version: 1.0 In-Reply-To: <1435842022-13980-1-git-send-email-mst@redhat.com> Content-Type: text/plain; charset=windows-1252 Content-Transfer-Encoding: 7bit Subject: Re: [Qemu-devel] [PATCH] virtio-pci: implement cfg capability List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: "Michael S. Tsirkin" , qemu-devel@nongnu.org On 02/07/2015 15:00, Michael S. Tsirkin wrote: > + cfg = (void *)(proxy->pci_dev.config + proxy->config_cap); > + off = le32_to_cpu(cfg->cap.offset); > + len = le32_to_cpu(cfg->cap.length); > + > + if ((len == 1 || len == 2 || len == 4)) { > + address_space_write(&proxy->modern_as, off, > + MEMTXATTRS_UNSPECIFIED, > + cfg->pci_cfg_data, len); > + } This parses pci_cfg_data in target endianness I think. You just want to move the little-endian value from the config cap to the little-endian value in the modern_as, so you need to use ldl_le_p and address_space_stl_le. > + } > +} > + > +static uint32_t virtio_read_config(PCIDevice *pci_dev, > + uint32_t address, int len) > +{ > + VirtIOPCIProxy *proxy = DO_UPCAST(VirtIOPCIProxy, pci_dev, pci_dev); > + struct virtio_pci_cfg_cap *cfg; > + > + if (proxy->config_cap && > + ranges_overlap(address, len, proxy->config_cap + offsetof(struct virtio_pci_cfg_cap, > + pci_cfg_data), > + sizeof cfg->pci_cfg_data)) { > + uint32_t off; > + uint32_t len; > + > + cfg = (void *)(proxy->pci_dev.config + proxy->config_cap); > + off = le32_to_cpu(cfg->cap.offset); > + len = le32_to_cpu(cfg->cap.length); > + > + if ((len == 1 || len == 2 || len == 4)) { > + address_space_read(&proxy->modern_as, off, > + MEMTXATTRS_UNSPECIFIED, > + cfg->pci_cfg_data, len); Same here, use address_space_ldl_le to read into an int, and stl_le_p to write into cfg->pci_cfg_data. The best way to check it, of course, is to write a unit test! :) But you could also use a Linux BE guest on LE host. Everything else looks good. Paolo