From patchwork Thu Dec 21 14:29:21 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: "Michael S. Tsirkin" X-Patchwork-Id: 851983 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=nongnu.org (client-ip=2001:4830:134:3::11; helo=lists.gnu.org; envelope-from=qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org; receiver=) Received: from lists.gnu.org (lists.gnu.org [IPv6:2001:4830:134:3::11]) (using TLSv1 with cipher AES256-SHA (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 3z2ZMP6gKsz9s83 for ; Fri, 22 Dec 2017 01:50:57 +1100 (AEDT) Received: from localhost ([::1]:53262 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eS2BT-0008P4-QU for incoming@patchwork.ozlabs.org; Thu, 21 Dec 2017 09:50:55 -0500 Received: from eggs.gnu.org ([2001:4830:134:3::10]:45950) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1eS1qm-00083o-MM for qemu-devel@nongnu.org; Thu, 21 Dec 2017 09:29:33 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1eS1ql-0005q4-LW for qemu-devel@nongnu.org; Thu, 21 Dec 2017 09:29:32 -0500 Received: from mx1.redhat.com ([209.132.183.28]:52394) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1eS1qg-0005lS-K0; Thu, 21 Dec 2017 09:29:26 -0500 Received: from smtp.corp.redhat.com (int-mx03.intmail.prod.int.phx2.redhat.com [10.5.11.13]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id B86D2C00DBB1; Thu, 21 Dec 2017 14:29:25 +0000 (UTC) Received: from redhat.com (ovpn-124-215.rdu2.redhat.com [10.10.124.215]) by smtp.corp.redhat.com (Postfix) with ESMTP id AEBE317DC6; Thu, 21 Dec 2017 14:29:22 +0000 (UTC) Date: Thu, 21 Dec 2017 16:29:21 +0200 From: "Michael S. Tsirkin" To: qemu-devel@nongnu.org Message-ID: <1513866427-27125-16-git-send-email-mst@redhat.com> References: <1513866427-27125-1-git-send-email-mst@redhat.com> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <1513866427-27125-1-git-send-email-mst@redhat.com> X-Mutt-Fcc: =sent X-Scanned-By: MIMEDefang 2.79 on 10.5.11.13 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Thu, 21 Dec 2017 14:29:25 +0000 (UTC) X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.2.x-3.x [generic] [fuzzy] X-Received-From: 209.132.183.28 Subject: [Qemu-devel] [PULL 15/25] hw/block/nvme: QOM'ify PCI NVME 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: Kevin Wolf , Peter Maydell , qemu-block@nongnu.org, Philippe =?utf-8?q?Mathieu-Daud=C3=A9?= , Max Reitz , Keith Busch Errors-To: qemu-devel-bounces+incoming=patchwork.ozlabs.org@nongnu.org Sender: "Qemu-devel" From: Philippe Mathieu-Daudé Signed-off-by: Philippe Mathieu-Daudé Reviewed-by: Michael S. Tsirkin Signed-off-by: Michael S. Tsirkin --- hw/block/nvme.c | 32 +++++++++++++++++--------------- 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/hw/block/nvme.c b/hw/block/nvme.c index 441e21e..9c5f898 100644 --- a/hw/block/nvme.c +++ b/hw/block/nvme.c @@ -920,9 +920,9 @@ static const MemoryRegionOps nvme_cmb_ops = { }, }; -static int nvme_init(PCIDevice *pci_dev) +static void nvme_realize(PCIDevice *pci, Error **errp) { - NvmeCtrl *n = NVME(pci_dev); + NvmeCtrl *n = NVME(pci); NvmeIdCtrl *id = &n->id_ctrl; int i; @@ -931,30 +931,33 @@ static int nvme_init(PCIDevice *pci_dev) Error *local_err = NULL; if (!n->conf.blk) { - return -1; + error_setg(errp, "Block device missing"); + return; } bs_size = blk_getlength(n->conf.blk); if (bs_size < 0) { - return -1; + error_setg_errno(errp, -bs_size, "Could not get length of device"); + return; } blkconf_serial(&n->conf, &n->serial); if (!n->serial) { - return -1; + error_setg(errp, "Could not get device serial number"); + return; } blkconf_blocksizes(&n->conf); blkconf_apply_backend_options(&n->conf, blk_is_read_only(n->conf.blk), false, &local_err); if (local_err) { - error_report_err(local_err); - return -1; + error_propagate(errp, local_err); + return; } - pci_conf = pci_dev->config; + pci_conf = pci->config; pci_conf[PCI_INTERRUPT_PIN] = 1; - pci_config_set_prog_interface(pci_dev->config, 0x2); - pci_config_set_class(pci_dev->config, PCI_CLASS_STORAGE_EXPRESS); + pci_config_set_prog_interface(pci->config, 0x2); + pci_config_set_class(pci->config, PCI_CLASS_STORAGE_EXPRESS); pcie_endpoint_cap_init(&n->parent_obj, 0x80); n->num_namespaces = 1; @@ -1046,12 +1049,11 @@ static int nvme_init(PCIDevice *pci_dev) cpu_to_le64(n->ns_size >> id_ns->lbaf[NVME_ID_NS_FLBAS_INDEX(ns->id_ns.flbas)].ds); } - return 0; } -static void nvme_exit(PCIDevice *pci_dev) +static void nvme_exit(PCIDevice *pci) { - NvmeCtrl *n = NVME(pci_dev); + NvmeCtrl *n = NVME(pci); nvme_clear_ctrl(n); g_free(n->namespaces); @@ -1061,7 +1063,7 @@ static void nvme_exit(PCIDevice *pci_dev) memory_region_unref(&n->ctrl_mem); } - msix_uninit_exclusive_bar(pci_dev); + msix_uninit_exclusive_bar(pci); } static Property nvme_props[] = { @@ -1081,7 +1083,7 @@ static void nvme_class_init(ObjectClass *oc, void *data) DeviceClass *dc = DEVICE_CLASS(oc); PCIDeviceClass *pc = PCI_DEVICE_CLASS(oc); - pc->init = nvme_init; + pc->realize = nvme_realize; pc->exit = nvme_exit; pc->class_id = PCI_CLASS_STORAGE_EXPRESS; pc->vendor_id = PCI_VENDOR_ID_INTEL;