From patchwork Thu Jan 21 17:01:30 2016 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Stefano Stabellini X-Patchwork-Id: 8083631 Return-Path: X-Original-To: patchwork-xen-devel@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 63A329F440 for ; Thu, 21 Jan 2016 17:34:55 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id 69899202FF for ; Thu, 21 Jan 2016 17:34:54 +0000 (UTC) Received: from lists.xen.org (lists.xenproject.org [50.57.142.19]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 572082022A for ; Thu, 21 Jan 2016 17:34:53 +0000 (UTC) Received: from localhost ([127.0.0.1] helo=lists.xen.org) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aMJ5s-0002qA-Co; Thu, 21 Jan 2016 17:32:24 +0000 Received: from mail6.bemta3.messagelabs.com ([195.245.230.39]) by lists.xen.org with esmtp (Exim 4.72) (envelope-from ) id 1aMJ5r-0002po-Gp for xen-devel@lists.xensource.com; Thu, 21 Jan 2016 17:32:23 +0000 Received: from [85.158.137.68] by server-16.bemta-3.messagelabs.com id AC/CD-07451-62611A65; Thu, 21 Jan 2016 17:32:22 +0000 X-Env-Sender: prvs=821047e81=Stefano.Stabellini@citrix.com X-Msg-Ref: server-5.tower-31.messagelabs.com!1453397540!17363614!1 X-Originating-IP: [66.165.176.63] X-SpamReason: No, hits=0.0 required=7.0 tests=sa_preprocessor: VHJ1c3RlZCBJUDogNjYuMTY1LjE3Ni42MyA9PiAzMDYwNDg=\n, received_headers: No Received headers X-StarScan-Received: X-StarScan-Version: 7.35.1; banners=-,-,- X-VirusChecked: Checked Received: (qmail 50951 invoked from network); 21 Jan 2016 17:32:21 -0000 Received: from smtp02.citrix.com (HELO SMTP02.CITRIX.COM) (66.165.176.63) by server-5.tower-31.messagelabs.com with RC4-SHA encrypted SMTP; 21 Jan 2016 17:32:21 -0000 X-IronPort-AV: E=Sophos;i="5.22,326,1449532800"; d="scan'208";a="333131725" From: Stefano Stabellini To: Date: Thu, 21 Jan 2016 17:01:30 +0000 Message-ID: <1453395690-32660-11-git-send-email-stefano.stabellini@eu.citrix.com> X-Mailer: git-send-email 1.7.9.5 In-Reply-To: References: MIME-Version: 1.0 X-DLP: MIA2 Cc: Cao jin , xen-devel@lists.xensource.com, Eric Blake , qemu-devel@nongnu.org, Stefano Stabellini Subject: [Xen-devel] [PULL 11/11] Xen PCI passthru: convert to realize() X-BeenThere: xen-devel@lists.xen.org X-Mailman-Version: 2.1.13 Precedence: list List-Id: Xen developer discussion List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Sender: xen-devel-bounces@lists.xen.org Errors-To: xen-devel-bounces@lists.xen.org X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_MED, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Cao jin Signed-off-by: Cao jin Reviewed-by: Eric Blake Reviewed-by: Stefano Stabellini --- hw/xen/xen_pt.c | 53 ++++++++++++++++++++++++++++------------------------- 1 file changed, 28 insertions(+), 25 deletions(-) diff --git a/hw/xen/xen_pt.c b/hw/xen/xen_pt.c index 9eef3df..d33221b 100644 --- a/hw/xen/xen_pt.c +++ b/hw/xen/xen_pt.c @@ -760,10 +760,10 @@ static void xen_pt_destroy(PCIDevice *d) { } /* init */ -static int xen_pt_initfn(PCIDevice *d) +static void xen_pt_realize(PCIDevice *d, Error **errp) { XenPCIPassthroughState *s = XEN_PT_DEVICE(d); - int rc = 0; + int i, rc = 0; uint8_t machine_irq = 0, scratch; uint16_t cmd = 0; int pirq = XEN_PT_UNASSIGNED_PIRQ; @@ -781,8 +781,8 @@ static int xen_pt_initfn(PCIDevice *d) &err); if (err) { error_append_hint(&err, "Failed to \"open\" the real pci device"); - error_report_err(err); - return -1; + error_propagate(errp, err); + return; } s->is_virtfn = s->real_device.is_virtfn; @@ -802,19 +802,19 @@ static int xen_pt_initfn(PCIDevice *d) if ((s->real_device.domain == 0) && (s->real_device.bus == 0) && (s->real_device.dev == 2) && (s->real_device.func == 0)) { if (!is_igd_vga_passthrough(&s->real_device)) { - XEN_PT_ERR(d, "Need to enable igd-passthru if you're trying" - " to passthrough IGD GFX.\n"); + error_setg(errp, "Need to enable igd-passthru if you're trying" + " to passthrough IGD GFX"); xen_host_pci_device_put(&s->real_device); - return -1; + return; } xen_pt_setup_vga(s, &s->real_device, &err); if (err) { error_append_hint(&err, "Setup VGA BIOS of passthrough" " GFX failed"); - error_report_err(err); + error_propagate(errp, err); xen_host_pci_device_put(&s->real_device); - return -1; + return; } /* Register ISA bridge for passthrough GFX. */ @@ -836,20 +836,19 @@ static int xen_pt_initfn(PCIDevice *d) /* Bind interrupt */ rc = xen_host_pci_get_byte(&s->real_device, PCI_INTERRUPT_PIN, &scratch); if (rc) { - XEN_PT_ERR(d, "Failed to read PCI_INTERRUPT_PIN! (rc:%d)\n", rc); + error_setg_errno(errp, errno, "Failed to read PCI_INTERRUPT_PIN"); goto err_out; } if (!scratch) { - XEN_PT_LOG(d, "no pin interrupt\n"); + error_setg(errp, "no pin interrupt"); goto out; } machine_irq = s->real_device.irq; rc = xc_physdev_map_pirq(xen_xc, xen_domid, machine_irq, &pirq); - if (rc < 0) { - XEN_PT_ERR(d, "Mapping machine irq %u to pirq %i failed, (err: %d)\n", - machine_irq, pirq, errno); + error_setg_errno(errp, errno, "Mapping machine irq %u to" + " pirq %i failed", machine_irq, pirq); /* Disable PCI intx assertion (turn on bit10 of devctl) */ cmd |= PCI_COMMAND_INTX_DISABLE; @@ -870,8 +869,8 @@ static int xen_pt_initfn(PCIDevice *d) PCI_SLOT(d->devfn), e_intx); if (rc < 0) { - XEN_PT_ERR(d, "Binding of interrupt %i failed! (err: %d)\n", - e_intx, errno); + error_setg_errno(errp, errno, "Binding of interrupt %u failed", + e_intx); /* Disable PCI intx assertion (turn on bit10 of devctl) */ cmd |= PCI_COMMAND_INTX_DISABLE; @@ -879,8 +878,8 @@ static int xen_pt_initfn(PCIDevice *d) if (xen_pt_mapped_machine_irq[machine_irq] == 0) { if (xc_physdev_unmap_pirq(xen_xc, xen_domid, machine_irq)) { - XEN_PT_ERR(d, "Unmapping of machine interrupt %i failed!" - " (err: %d)\n", machine_irq, errno); + error_setg_errno(errp, errno, "Unmapping of machine" + " interrupt %u failed", machine_irq); } } s->machine_irq = 0; @@ -893,14 +892,14 @@ out: rc = xen_host_pci_get_word(&s->real_device, PCI_COMMAND, &val); if (rc) { - XEN_PT_ERR(d, "Failed to read PCI_COMMAND! (rc: %d)\n", rc); + error_setg_errno(errp, errno, "Failed to read PCI_COMMAND"); goto err_out; } else { val |= cmd; rc = xen_host_pci_set_word(&s->real_device, PCI_COMMAND, val); if (rc) { - XEN_PT_ERR(d, "Failed to write PCI_COMMAND val=0x%x!(rc: %d)\n", - val, rc); + error_setg_errno(errp, errno, "Failed to write PCI_COMMAND" + " val = 0x%x", val); goto err_out; } } @@ -910,15 +909,19 @@ out: memory_listener_register(&s->io_listener, &address_space_io); s->listener_set = true; XEN_PT_LOG(d, - "Real physical device %02x:%02x.%d registered successfully!\n", + "Real physical device %02x:%02x.%d registered successfully\n", s->hostaddr.bus, s->hostaddr.slot, s->hostaddr.function); - return 0; + return; err_out: + for (i = 0; i < PCI_ROM_SLOT; i++) { + object_unparent(OBJECT(&s->bar[i])); + } + object_unparent(OBJECT(&s->rom)); + xen_pt_destroy(d); assert(rc); - return rc; } static void xen_pt_unregister_device(PCIDevice *d) @@ -937,7 +940,7 @@ static void xen_pci_passthrough_class_init(ObjectClass *klass, void *data) DeviceClass *dc = DEVICE_CLASS(klass); PCIDeviceClass *k = PCI_DEVICE_CLASS(klass); - k->init = xen_pt_initfn; + k->realize = xen_pt_realize; k->exit = xen_pt_unregister_device; k->config_read = xen_pt_pci_read_config; k->config_write = xen_pt_pci_write_config;