From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MuNij-0006b4-C5 for qemu-devel@nongnu.org; Sun, 04 Oct 2009 05:49:37 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MuNie-0006ZA-SL for qemu-devel@nongnu.org; Sun, 04 Oct 2009 05:49:37 -0400 Received: from [199.232.76.173] (port=33047 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MuNid-0006Z0-Jj for qemu-devel@nongnu.org; Sun, 04 Oct 2009 05:49:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:31702) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MuNic-0007n4-V7 for qemu-devel@nongnu.org; Sun, 04 Oct 2009 05:49:31 -0400 Date: Sun, 4 Oct 2009 11:47:29 +0200 From: "Michael S. Tsirkin" Message-ID: <20091004094729.GB16887@redhat.com> References: <1254514577-11896-1-git-send-email-yamahata@valinux.co.jp> <1254514577-11896-9-git-send-email-yamahata@valinux.co.jp> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <1254514577-11896-9-git-send-email-yamahata@valinux.co.jp> Subject: [Qemu-devel] Re: [PATCH 08/25] pci: use helper functions to access pci config space. List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , To: Isaku Yamahata Cc: qemu-devel@nongnu.org On Sat, Oct 03, 2009 at 05:16:00AM +0900, Isaku Yamahata wrote: > use pci_[gs]et_{byte, word, long}() to access pci configuration > space. > > Signed-off-by: Isaku Yamahata Acked-by: Michael S. Tsirkin > --- > hw/pci.c | 38 ++++++++++++++++++-------------------- > 1 files changed, 18 insertions(+), 20 deletions(-) > > diff --git a/hw/pci.c b/hw/pci.c > index 39791d0..21e23b0 100644 > --- a/hw/pci.c > +++ b/hw/pci.c > @@ -426,9 +426,9 @@ void pci_register_bar(PCIDevice *pci_dev, int region_num, > } else { > addr = 0x10 + region_num * 4; > } > - *(uint32_t *)(pci_dev->config + addr) = cpu_to_le32(type); > - *(uint32_t *)(pci_dev->wmask + addr) = cpu_to_le32(wmask); > - *(uint32_t *)(pci_dev->cmask + addr) = 0xffffffff; > + pci_set_long(pci_dev->config + addr, type); > + pci_set_long(pci_dev->wmask + addr, wmask); > + pci_set_long(pci_dev->cmask + addr, 0xffffffff); > } > > static void pci_update_mappings(PCIDevice *d) > @@ -437,7 +437,7 @@ static void pci_update_mappings(PCIDevice *d) > int cmd, i; > uint32_t last_addr, new_addr, config_ofs; > > - cmd = le16_to_cpu(*(uint16_t *)(d->config + PCI_COMMAND)); > + cmd = pci_get_word(d->config + PCI_COMMAND); > for(i = 0; i < PCI_NUM_REGIONS; i++) { > r = &d->io_regions[i]; > if (i == PCI_ROM_SLOT) { > @@ -448,8 +448,7 @@ static void pci_update_mappings(PCIDevice *d) > if (r->size != 0) { > if (r->type & PCI_ADDRESS_SPACE_IO) { > if (cmd & PCI_COMMAND_IO) { > - new_addr = le32_to_cpu(*(uint32_t *)(d->config + > - config_ofs)); > + new_addr = pci_get_long(d->config + config_ofs); > new_addr = new_addr & ~(r->size - 1); > last_addr = new_addr + r->size - 1; > /* NOTE: we have only 64K ioports on PC */ > @@ -462,8 +461,7 @@ static void pci_update_mappings(PCIDevice *d) > } > } else { > if (cmd & PCI_COMMAND_MEMORY) { > - new_addr = le32_to_cpu(*(uint32_t *)(d->config + > - config_ofs)); > + new_addr = pci_get_long(d->config + config_ofs); > /* the ROM slot has a specific enable bit */ > if (i == PCI_ROM_SLOT && !(new_addr & 1)) > goto no_mem_map; > @@ -489,7 +487,7 @@ static void pci_update_mappings(PCIDevice *d) > int class; > /* NOTE: specific hack for IDE in PC case: > only one byte must be mapped. */ > - class = d->config[0x0a] | (d->config[0x0b] << 8); > + class = pci_get_word(d->config + PCI_CLASS_DEVICE); > if (class == 0x0101 && r->size == 4) { > isa_unassign_ioport(r->addr + 2, 1); > } else { > @@ -520,18 +518,18 @@ uint32_t pci_default_read_config(PCIDevice *d, > default: > case 4: > if (address <= 0xfc) { > - val = le32_to_cpu(*(uint32_t *)(d->config + address)); > + val = pci_get_long(d->config + address); > break; > } > /* fall through */ > case 2: > if (address <= 0xfe) { > - val = le16_to_cpu(*(uint16_t *)(d->config + address)); > + val = pci_get_word(d->config + address); > break; > } > /* fall through */ > case 1: > - val = d->config[address]; > + val = pci_get_byte(d->config + address); > break; > } > return val; > @@ -704,7 +702,7 @@ static void pci_info_device(PCIDevice *d) > > monitor_printf(mon, " Bus %2d, device %3d, function %d:\n", > d->bus->bus_num, PCI_SLOT(d->devfn), PCI_FUNC(d->devfn)); > - class = le16_to_cpu(*((uint16_t *)(d->config + PCI_CLASS_DEVICE))); > + class = pci_get_word(d->config + PCI_CLASS_DEVICE); > monitor_printf(mon, " "); > desc = pci_class_descriptions; > while (desc->desc && class != desc->class) > @@ -715,8 +713,8 @@ static void pci_info_device(PCIDevice *d) > monitor_printf(mon, "Class %04x", class); > } > monitor_printf(mon, ": PCI device %04x:%04x\n", > - le16_to_cpu(*((uint16_t *)(d->config + PCI_VENDOR_ID))), > - le16_to_cpu(*((uint16_t *)(d->config + PCI_DEVICE_ID)))); > + pci_get_word(d->config + PCI_VENDOR_ID), > + pci_get_word(d->config + PCI_DEVICE_ID)); > > if (d->config[PCI_INTERRUPT_PIN] != 0) { > monitor_printf(mon, " IRQ %d.\n", > @@ -1026,7 +1024,7 @@ static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent) > PCIIORegion *r; > int i, class; > > - class = le16_to_cpu(*((uint16_t *)(d->config + PCI_CLASS_DEVICE))); > + class = pci_get_word(d->config + PCI_CLASS_DEVICE); > desc = pci_class_descriptions; > while (desc->desc && class != desc->class) > desc++; > @@ -1040,10 +1038,10 @@ static void pcibus_dev_print(Monitor *mon, DeviceState *dev, int indent) > "pci id %04x:%04x (sub %04x:%04x)\n", > indent, "", ctxt, > d->bus->bus_num, PCI_SLOT(d->devfn), PCI_FUNC(d->devfn), > - le16_to_cpu(*((uint16_t *)(d->config + PCI_VENDOR_ID))), > - le16_to_cpu(*((uint16_t *)(d->config + PCI_DEVICE_ID))), > - le16_to_cpu(*((uint16_t *)(d->config + PCI_SUBSYSTEM_VENDOR_ID))), > - le16_to_cpu(*((uint16_t *)(d->config + PCI_SUBSYSTEM_ID)))); > + pci_get_word(d->config + PCI_VENDOR_ID), > + pci_get_word(d->config + PCI_DEVICE_ID), > + pci_get_word(d->config + PCI_SUBSYSTEM_VENDOR_ID), > + pci_get_word(d->config + PCI_SUBSYSTEM_ID)); > for (i = 0; i < PCI_NUM_REGIONS; i++) { > r = &d->io_regions[i]; > if (!r->size) > -- > 1.6.0.2 > >