Received: by 2002:a25:6193:0:0:0:0:0 with SMTP id v141csp3934982ybb; Mon, 23 Mar 2020 10:21:21 -0700 (PDT) X-Google-Smtp-Source: ADFU+vtJ+y4op94tqT9PRFe+cAxF97llxzGPsDELbuaRzXNKK4yQ9saJmId66GzqtcpLkZgyFEP7 X-Received: by 2002:a9d:404b:: with SMTP id o11mr2505691oti.120.1584984080987; Mon, 23 Mar 2020 10:21:20 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584984080; cv=none; d=google.com; s=arc-20160816; b=qHsjQlCTdL52gs6p0oTRNDpNNiRPbK+IyBPwM0IZgiytbQMMs60z3GnOj2J8CxA2qP XlNglohCsPos2l1wRhI5iVaIgql1NI+fAKR91YBUn6yc+sX0unFgVY6gUOuYKom8Hg/G 42ymZkKLPraH6sWo/LAySnm2CWfsXWh1SDHUVK0xxBaq9ZPWszyeOz9mih8DVNo6vMQO eM//UZzZYFMj5Rx8fZ+wcStfSJ1fvUHChvhtgqpgeSHA5i3TGrQneG3DzRcM8BT5WB6S hMY/09CxH3GKQ8+/pjYQ30VrRvfP6OyvAlXqcVmEvoIiFh9TRcEFElL6v9uRPknUNjgJ KcGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=uaIVxOrZSVp9GsPcVSu5ePTOiasdNll1KqdT9WeJFN0=; b=C/zpyqmvYddA/XMVBU0lt8vFHDrfBKDlKffGYACfEWR83ZvhwEJXH9JM4k/+WK8KR1 5VuYLoThNMoyo7MHiTvRDKapoVJf9IjwtFysBIiZrYtMvPiYiJ274Yw7OVnRKmBptJ9I 09zvQapwcUPMz6Ic3l2QXZCA0ImnTL6QAiOUJcBrvafKosAw42FCCCZGP0Y5a4j97aJg zqdwkOLn6qwBIFzLVD6DrkIpl6k2g8WeomFn5XW2egDisMw4Ysfg/plCVG0TjqFVUmx7 wt1O9gI8H5hmSQu8Rwg9z/LsVIAsLlnlHtBEb2ZTmAB9+/6v8Xl8tCE2DIdOzUTqVrBd cQ0w== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g22si8092965otn.291.2020.03.23.10.21.07; Mon, 23 Mar 2020 10:21:20 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=nxp.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728005AbgCWRUI (ORCPT + 99 others); Mon, 23 Mar 2020 13:20:08 -0400 Received: from inva020.nxp.com ([92.121.34.13]:50508 "EHLO inva020.nxp.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727318AbgCWRTa (ORCPT ); Mon, 23 Mar 2020 13:19:30 -0400 Received: from inva020.nxp.com (localhost [127.0.0.1]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id E38D91A14D4; Mon, 23 Mar 2020 18:19:27 +0100 (CET) Received: from inva024.eu-rdc02.nxp.com (inva024.eu-rdc02.nxp.com [134.27.226.22]) by inva020.eu-rdc02.nxp.com (Postfix) with ESMTP id D73871A14A9; Mon, 23 Mar 2020 18:19:27 +0100 (CET) Received: from fsr-ub1864-111.ea.freescale.net (fsr-ub1864-111.ea.freescale.net [10.171.82.141]) by inva024.eu-rdc02.nxp.com (Postfix) with ESMTP id 599792035C; Mon, 23 Mar 2020 18:19:27 +0100 (CET) From: Diana Craciun To: kvm@vger.kernel.org, alex.williamson@redhat.com, laurentiu.tudor@nxp.com, linux-arm-kernel@lists.infradead.org, bharatb.yadav@gmail.com Cc: linux-kernel@vger.kernel.org, Diana Craciun , Bharat Bhushan Subject: [PATCH 2/9] vfio/fsl-mc: Scan DPRC objects on vfio-fsl-mc driver bind Date: Mon, 23 Mar 2020 19:19:04 +0200 Message-Id: <20200323171911.27178-3-diana.craciun@oss.nxp.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20200323171911.27178-1-diana.craciun@oss.nxp.com> References: <20200323171911.27178-1-diana.craciun@oss.nxp.com> X-Virus-Scanned: ClamAV using ClamSMTP Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The DPRC (Data Path Resource Container) device is a bus device and has child devices attached to it. When the vfio-fsl-mc driver is probed the DPRC is scanned and the child devices discovered and initialized. Signed-off-by: Bharat Bhushan Signed-off-by: Diana Craciun --- drivers/vfio/fsl-mc/vfio_fsl_mc.c | 66 +++++++++++++++++++++++++++++++ 1 file changed, 66 insertions(+) diff --git a/drivers/vfio/fsl-mc/vfio_fsl_mc.c b/drivers/vfio/fsl-mc/vfio_fsl_mc.c index 320fb09b5691..5cc533808bc1 100644 --- a/drivers/vfio/fsl-mc/vfio_fsl_mc.c +++ b/drivers/vfio/fsl-mc/vfio_fsl_mc.c @@ -74,6 +74,34 @@ static int vfio_fsl_mc_mmap(void *device_data, struct vm_area_struct *vma) return -EINVAL; } +static int vfio_fsl_mc_init_device(struct vfio_fsl_mc_device *vdev) +{ + struct fsl_mc_device *mc_dev = vdev->mc_dev; + int ret = 0; + + /* Non-dprc devices share mc_io from parent */ + if (!is_fsl_mc_bus_dprc(mc_dev)) { + struct fsl_mc_device *mc_cont = to_fsl_mc_device(mc_dev->dev.parent); + + mc_dev->mc_io = mc_cont->mc_io; + return 0; + } + + /* open DPRC, allocate a MC portal */ + ret = dprc_setup(mc_dev); + if (ret < 0) { + dev_err(&mc_dev->dev, "Failed to setup DPRC (error = %d)\n", ret); + return ret; + } + + ret = dprc_scan_container(mc_dev, mc_dev->driver_override, false); + if (ret < 0) { + dev_err(&mc_dev->dev, "Container scanning failed: %d\n", ret); + dprc_cleanup(mc_dev); + } + + return 0; +} static const struct vfio_device_ops vfio_fsl_mc_ops = { .name = "vfio-fsl-mc", .open = vfio_fsl_mc_open, @@ -112,9 +140,42 @@ static int vfio_fsl_mc_probe(struct fsl_mc_device *mc_dev) return ret; } + ret = vfio_fsl_mc_init_device(vdev); + if (ret) { + vfio_iommu_group_put(group, dev); + return ret; + } + return ret; } +static int vfio_fsl_mc_device_remove(struct device *dev, void *data) +{ + struct fsl_mc_device *mc_dev; + + WARN_ON(!dev); + mc_dev = to_fsl_mc_device(dev); + if (WARN_ON(!mc_dev)) + return -ENODEV; + + kfree(mc_dev->driver_override); + mc_dev->driver_override = NULL; + + /* + * The device-specific remove callback will get invoked by device_del() + */ + device_del(&mc_dev->dev); + put_device(&mc_dev->dev); + + return 0; +} + +static void vfio_fsl_mc_cleanup_dprc(struct fsl_mc_device *mc_dev) +{ + device_for_each_child(&mc_dev->dev, NULL, vfio_fsl_mc_device_remove); + dprc_cleanup(mc_dev); +} + static int vfio_fsl_mc_remove(struct fsl_mc_device *mc_dev) { struct vfio_fsl_mc_device *vdev; @@ -124,6 +185,11 @@ static int vfio_fsl_mc_remove(struct fsl_mc_device *mc_dev) if (!vdev) return -EINVAL; + if (is_fsl_mc_bus_dprc(mc_dev)) + vfio_fsl_mc_cleanup_dprc(vdev->mc_dev); + + mc_dev->mc_io = NULL; + vfio_iommu_group_put(mc_dev->dev.iommu_group, dev); devm_kfree(dev, vdev); -- 2.17.1