From patchwork Fri Oct 12 03:40:29 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Li Qiang X-Patchwork-Id: 10637811 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id D513C933 for ; Fri, 12 Oct 2018 03:41:41 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B6D762C497 for ; Fri, 12 Oct 2018 03:41:41 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 9A3AE2C49A; Fri, 12 Oct 2018 03:41:41 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-7.7 required=2.0 tests=BAYES_00,DKIM_ADSP_CUSTOM_MED, DKIM_INVALID,DKIM_SIGNED,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from lists.gnu.org (lists.gnu.org [208.118.235.17]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 1518F2C497 for ; Fri, 12 Oct 2018 03:41:40 +0000 (UTC) Received: from localhost ([::1]:38102 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAoKZ-0000DM-Gf for patchwork-qemu-devel@patchwork.kernel.org; Thu, 11 Oct 2018 23:41:39 -0400 Received: from eggs.gnu.org ([2001:4830:134:3::10]:35325) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gAoJt-0008L6-1C for qemu-devel@nongnu.org; Thu, 11 Oct 2018 23:40:57 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gAoJp-0001ly-Rn for qemu-devel@nongnu.org; Thu, 11 Oct 2018 23:40:56 -0400 Received: from mail-pl1-x642.google.com ([2607:f8b0:4864:20::642]:37074) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gAoJp-0001kr-Ku for qemu-devel@nongnu.org; Thu, 11 Oct 2018 23:40:53 -0400 Received: by mail-pl1-x642.google.com with SMTP id u6-v6so2482038plz.4 for ; Thu, 11 Oct 2018 20:40:53 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id; bh=3wJavj35BQRgWamkru6hCn0SW8JX0eOApqDa1BQ/5pI=; b=h4CeTxQvgiB1AzXCtkYKDWZoWFb7GBmjeIifzVj4dd97tElLMymYMAGyUN0aIW+zzq BV6D/LQnz1d7ZcCZAiqXOLypzaLAQhjEt7BGSm3LQ8aOUIpZijIIEcaz5xk2X08fhTMe mHqRdYbOlkP4XmDBARifSUeUIUR4wdDhT0ZIyPQknHthsfNvfH4mGDtdVe4ZXolOAmwN 3ioFLodfyQ+GB8LCRZQsYtD/haMBYtYjwGALNaPa3ErdIbM+fB8q5pHmCLYDbzxO5gZJ Cya3ekQHnuUAcGNWYAEJXvOlMGn3n37B24gTqncV6u7tgwcP3t0zDcNI3xbFaDwHhqiR vQlA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id; bh=3wJavj35BQRgWamkru6hCn0SW8JX0eOApqDa1BQ/5pI=; b=GhTnCHtTW3R0JBzDVkfl2ZVjXz62T43hRCHKhRRTxKJeLearPZyOC0yLlwP0t+MSg4 M+woES/JF0r4kdquet+kTXkaQRsR2i15Fyb9gCFpEKIBs7ziXRRnIOdTS7fbinJZPZxO 5sOqARU7IkFAZrc+1Z6dW9BW5ioCiau0A9tjqH4D2igDQab4ZaomdfxT3irRMFj32bYH s7tu9dK2TgqcI80kgvAQcuGP3LSSXKQk4kHjhh8ViMoGIpLiFga4GZFm5bMycygy+M3/ +cpBE54X7IQcWAGKueF9u5NctmbhgYLcCwcpV3U1pwNsSc0VP2h0wpczbKwn/K/oNwIQ VeJQ== X-Gm-Message-State: ABuFfog9yWdaJaGAiEajxk3HhE2KKR61PQMWyUcFkfjQ0ZE4ITUm6hvL tpPsusBMXxUsuOMAM/e2qMY= X-Google-Smtp-Source: ACcGV63NTMIGbxT4Oqb/CGJk3bwuZsyJrOMADZP7TIdoyQwOqKWiTcdnS3Atr1iVbCi2qna9M55cYw== X-Received: by 2002:a17:902:15c5:: with SMTP id a5-v6mr4166600plh.137.1539315652750; Thu, 11 Oct 2018 20:40:52 -0700 (PDT) Received: from localhost.localdomain.localdomain ([103.65.40.65]) by smtp.gmail.com with ESMTPSA id q21-v6sm90051176pfq.51.2018.10.11.20.40.51 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 11 Oct 2018 20:40:52 -0700 (PDT) From: Li Qiang To: alex.williamson@redhat.com Date: Thu, 11 Oct 2018 20:40:29 -0700 Message-Id: <1539315629-5424-1-git-send-email-liq3ea@gmail.com> X-Mailer: git-send-email 1.8.3.1 X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:4864:20::642 Subject: [Qemu-devel] [PATCH] vfio-pci: make vfio-pci device more QOM conventional X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.21 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: pbonzini@redhat.com, Li Qiang , philmd@redhat.com, qemu-devel@nongnu.org Errors-To: qemu-devel-bounces+patchwork-qemu-devel=patchwork.kernel.org@nongnu.org Sender: "Qemu-devel" X-Virus-Scanned: ClamAV using ClamSMTP Define a TYPE_VFIO_PCI and drop DO_UPCAST. Signed-off-by: Li Qiang Reviewed-by: Philippe Mathieu-Daudé --- hw/vfio/pci.c | 29 +++++++++++++++-------------- 1 file changed, 15 insertions(+), 14 deletions(-) diff --git a/hw/vfio/pci.c b/hw/vfio/pci.c index 866f0deeb7..3f232aedff 100644 --- a/hw/vfio/pci.c +++ b/hw/vfio/pci.c @@ -37,6 +37,9 @@ #define MSIX_CAP_LENGTH 12 +#define TYPE_VFIO_PCI "vfio-pci" +#define PCI_VFIO(obj) OBJECT_CHECK(VFIOPCIDevice, obj, TYPE_VFIO_PCI) + static void vfio_disable_interrupts(VFIOPCIDevice *vdev); static void vfio_mmap_set_enabled(VFIOPCIDevice *vdev, bool enabled); @@ -222,7 +225,7 @@ static void vfio_intx_disable_kvm(VFIOPCIDevice *vdev) static void vfio_intx_update(PCIDevice *pdev) { - VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOPCIDevice *vdev = PCI_VFIO(pdev); PCIINTxRoute route; Error *err = NULL; @@ -477,7 +480,7 @@ static void vfio_update_kvm_msi_virq(VFIOMSIVector *vector, MSIMessage msg, static int vfio_msix_vector_do_use(PCIDevice *pdev, unsigned int nr, MSIMessage *msg, IOHandler *handler) { - VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOPCIDevice *vdev = PCI_VFIO(pdev); VFIOMSIVector *vector; int ret; @@ -574,7 +577,7 @@ static int vfio_msix_vector_use(PCIDevice *pdev, static void vfio_msix_vector_release(PCIDevice *pdev, unsigned int nr) { - VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOPCIDevice *vdev = PCI_VFIO(pdev); VFIOMSIVector *vector = &vdev->msi_vectors[nr]; trace_vfio_msix_vector_release(vdev->vbasedev.name, nr); @@ -1086,7 +1089,7 @@ static const MemoryRegionOps vfio_vga_ops = { */ static void vfio_sub_page_bar_update_mapping(PCIDevice *pdev, int bar) { - VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOPCIDevice *vdev = PCI_VFIO(pdev); VFIORegion *region = &vdev->bars[bar].region; MemoryRegion *mmap_mr, *region_mr, *base_mr; PCIIORegion *r; @@ -1132,7 +1135,7 @@ static void vfio_sub_page_bar_update_mapping(PCIDevice *pdev, int bar) */ uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len) { - VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOPCIDevice *vdev = PCI_VFIO(pdev); uint32_t emu_bits = 0, emu_val = 0, phys_val = 0, val; memcpy(&emu_bits, vdev->emulated_config_bits + addr, len); @@ -1165,7 +1168,7 @@ uint32_t vfio_pci_read_config(PCIDevice *pdev, uint32_t addr, int len) void vfio_pci_write_config(PCIDevice *pdev, uint32_t addr, uint32_t val, int len) { - VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOPCIDevice *vdev = PCI_VFIO(pdev); uint32_t val_le = cpu_to_le32(val); trace_vfio_pci_write_config(vdev->vbasedev.name, addr, val, len); @@ -2801,7 +2804,7 @@ static void vfio_unregister_req_notifier(VFIOPCIDevice *vdev) static void vfio_realize(PCIDevice *pdev, Error **errp) { - VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOPCIDevice *vdev = PCI_VFIO(pdev); VFIODevice *vbasedev_iter; VFIOGroup *group; char *tmp, *subsys, group_path[PATH_MAX], *group_name; @@ -3084,8 +3087,7 @@ error: static void vfio_instance_finalize(Object *obj) { - PCIDevice *pci_dev = PCI_DEVICE(obj); - VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pci_dev); + VFIOPCIDevice *vdev = PCI_VFIO(obj); VFIOGroup *group = vdev->vbasedev.group; vfio_display_finalize(vdev); @@ -3105,7 +3107,7 @@ static void vfio_instance_finalize(Object *obj) static void vfio_exitfn(PCIDevice *pdev) { - VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOPCIDevice *vdev = PCI_VFIO(pdev); vfio_unregister_req_notifier(vdev); vfio_unregister_err_notifier(vdev); @@ -3120,8 +3122,7 @@ static void vfio_exitfn(PCIDevice *pdev) static void vfio_pci_reset(DeviceState *dev) { - PCIDevice *pdev = DO_UPCAST(PCIDevice, qdev, dev); - VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, pdev); + VFIOPCIDevice *vdev = PCI_VFIO(dev); trace_vfio_pci_reset(vdev->vbasedev.name); @@ -3161,7 +3162,7 @@ post_reset: static void vfio_instance_init(Object *obj) { PCIDevice *pci_dev = PCI_DEVICE(obj); - VFIOPCIDevice *vdev = DO_UPCAST(VFIOPCIDevice, pdev, PCI_DEVICE(obj)); + VFIOPCIDevice *vdev = PCI_VFIO(obj); device_add_bootindex_property(obj, &vdev->bootindex, "bootindex", NULL, @@ -3245,7 +3246,7 @@ static void vfio_pci_dev_class_init(ObjectClass *klass, void *data) } static const TypeInfo vfio_pci_dev_info = { - .name = "vfio-pci", + .name = TYPE_VFIO_PCI, .parent = TYPE_PCI_DEVICE, .instance_size = sizeof(VFIOPCIDevice), .class_init = vfio_pci_dev_class_init,