From patchwork Fri Oct 2 20:16:00 2009 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Isaku Yamahata X-Patchwork-Id: 34893 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.gnu.org (lists.gnu.org [199.232.76.165]) (using TLSv1 with cipher DHE-RSA-AES256-SHA (256/256 bits)) (Client did not present a certificate) by ozlabs.org (Postfix) with ESMTPS id 8B985B7BE3 for ; Sat, 3 Oct 2009 06:38:02 +1000 (EST) Received: from localhost ([127.0.0.1]:56857 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1Mtot5-0005OT-ON for incoming@patchwork.ozlabs.org; Fri, 02 Oct 2009 16:37:59 -0400 Received: from mailman by lists.gnu.org with tmda-scanned (Exim 4.43) id 1MtoZv-0004SB-Vw for qemu-devel@nongnu.org; Fri, 02 Oct 2009 16:18:12 -0400 Received: from exim by lists.gnu.org with spam-scanned (Exim 4.43) id 1MtoZm-0004M2-LX for qemu-devel@nongnu.org; Fri, 02 Oct 2009 16:18:07 -0400 Received: from [199.232.76.173] (port=46075 helo=monty-python.gnu.org) by lists.gnu.org with esmtp (Exim 4.43) id 1MtoZl-0004LI-C3 for qemu-devel@nongnu.org; Fri, 02 Oct 2009 16:18:01 -0400 Received: from mail.valinux.co.jp ([210.128.90.3]:43781) by monty-python.gnu.org with esmtp (Exim 4.60) (envelope-from ) id 1MtoZk-0000hu-AS for qemu-devel@nongnu.org; Fri, 02 Oct 2009 16:18:01 -0400 Received: from nm.local.valinux.co.jp (vagw.valinux.co.jp [210.128.90.14]) by mail.valinux.co.jp (Postfix) with ESMTP id 9C4C549D13; Sat, 3 Oct 2009 05:17:56 +0900 (JST) Received: from yamahata by nm.local.valinux.co.jp with local (Exim 4.69) (envelope-from ) id 1MtoY6-00038c-GU; Sat, 03 Oct 2009 05:16:18 +0900 From: Isaku Yamahata To: qemu-devel@nongnu.org, anthony@codemonkey.ws Date: Sat, 3 Oct 2009 05:16:00 +0900 Message-Id: <1254514577-11896-9-git-send-email-yamahata@valinux.co.jp> X-Mailer: git-send-email 1.6.0.2 In-Reply-To: <1254514577-11896-1-git-send-email-yamahata@valinux.co.jp> References: <1254514577-11896-1-git-send-email-yamahata@valinux.co.jp> X-Virus-Scanned: clamav-milter 0.95.2 at va-mail.local.valinux.co.jp X-Virus-Status: Clean X-detected-operating-system: by monty-python.gnu.org: GNU/Linux 2.6 (newer, 3) Cc: yamahata@valinux.co.jp Subject: [Qemu-devel] [PATCH 08/25] pci: use helper functions to access pci config space. X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: qemu-devel.nongnu.org List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org 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)