From nobody Fri Nov 29 16:32:09 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 1CCD51662F4 for ; Tue, 17 Sep 2024 09:39:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726565951; cv=none; b=CZDCtkXETCMMN5VsObOijgd0iLkMHeWRmDXKG2tAJJBBx7yuu/+HZpBqRSXkiAqpIFi2c/xeE5WYMr08TNQOfIyKSQZEYIEc++elQNK9bf/BPMMh9s3VCGtso8u6EjdnrDWZa2WqmnUj6cy1kKYzZhFQKpzkL95PtkCgPZvQuSc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726565951; c=relaxed/simple; bh=Pby3DcZyp14RhAJleSoL2znXIzFMNtZrCFUDqVhutQM=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=o7lfDzfSeiug78+xMeMKVNeAw4ZCpOH41S+auEuxJSva986VRFV8+cjmgmudMW/OELHDd9Cyy51K3eoD/AUMUmg2IYc1ka3QKYikPma40/DU38EunlFOkM7s+b5on6Nj6nTOSvxSSJqwyQDisAmjSA1My23IhZAbHfTZIh5SH4s= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Eew8mu/B; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Eew8mu/B" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726565948; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=BHimdIgejLVZPp9ejvAk3wHq7yXS/6u29ozuQ5c+vvI=; b=Eew8mu/BGMJ1hQs/nJK5rQHNiTKpWzIlr3LsolEc7CKLV6l9Gc9Ii8oxillSBpr1aL24bD iVhhIFLbkMm0OVtgAhoC5UlyLEeYj63jIshprKKJ8+riaDPC0dvW7S3ImSUWGxSYYsvCqf xiuQAGppB2P2jKqWDVrohVALCnikB/8= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-582-zglMNBjjNEK0ORYMx6jSjw-1; Tue, 17 Sep 2024 05:39:05 -0400 X-MC-Unique: zglMNBjjNEK0ORYMx6jSjw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 5C12C1955D4A; Tue, 17 Sep 2024 09:39:03 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.23]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id E5B7530001A1; Tue, 17 Sep 2024 09:38:58 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, treding@nvidia.com, vbhadram@nvidia.com, jonathanh@nvidia.com, mperttunen@nvidia.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, alex.williamson@redhat.com, clg@redhat.com, alexandre.torgue@foss.st.com, joabreu@synopsys.com Cc: msalter@redhat.com Subject: [RFC PATCH v2 1/6] vfio_platform: Introduce vfio_platform_get_region helper Date: Tue, 17 Sep 2024 11:38:09 +0200 Message-ID: <20240917093851.990344-2-eric.auger@redhat.com> In-Reply-To: <20240917093851.990344-1-eric.auger@redhat.com> References: <20240917093851.990344-1-eric.auger@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Reset modules need to access some specific regions. It may easier and safer to refer to those regions using their name instead of relying on their index. So let's introduce a helper that looks for the struct vfio_platform_region with a given name. Signed-off-by: Eric Auger --- I don't know if reg names described in binding yaml are guaranteed to appear in the listed order. I guess no, hence the reg-names. In my case, for the host tegra234 dt node, regs I even observe regs that are not documented in the yaml: mac, xpcs, macsec-base, hypervisor whereas yaml only describes hypervisor, mac, xpcs --- drivers/vfio/platform/vfio_platform_common.c | 14 ++++++++++++++ drivers/vfio/platform/vfio_platform_private.h | 5 +++++ 2 files changed, 19 insertions(+) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/pl= atform/vfio_platform_common.c index e53757d1d095..6861f977fd5b 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -153,6 +153,7 @@ static int vfio_platform_regions_init(struct vfio_platf= orm_device *vdev) vdev->regions[i].addr =3D res->start; vdev->regions[i].size =3D resource_size(res); vdev->regions[i].flags =3D 0; + vdev->regions[i].name =3D res->name; =20 switch (resource_type(res)) { case IORESOURCE_MEM: @@ -188,6 +189,19 @@ static int vfio_platform_regions_init(struct vfio_plat= form_device *vdev) return -EINVAL; } =20 +struct vfio_platform_region* +vfio_platform_get_region(struct vfio_platform_device *vdev, const char *na= me) +{ + int i; + + for (i =3D 0; i < vdev->num_regions; i++) { + if (!strcmp(vdev->regions[i].name, name)) + return &vdev->regions[i]; + } + return NULL; +} +EXPORT_SYMBOL_GPL(vfio_platform_get_region); + static void vfio_platform_regions_cleanup(struct vfio_platform_device *vde= v) { int i; diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/p= latform/vfio_platform_private.h index 8d8fab516849..20d67634bc41 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -37,6 +37,7 @@ struct vfio_platform_region { resource_size_t size; u32 flags; u32 type; + const char *name; #define VFIO_PLATFORM_REGION_TYPE_MMIO 1 #define VFIO_PLATFORM_REGION_TYPE_PIO 2 void __iomem *ioaddr; @@ -104,6 +105,10 @@ int vfio_platform_set_irqs_ioctl(struct vfio_platform_= device *vdev, void __vfio_platform_register_reset(struct vfio_platform_reset_node *n); void vfio_platform_unregister_reset(const char *compat, vfio_platform_reset_fn_t fn); + +struct vfio_platform_region * +vfio_platform_get_region(struct vfio_platform_device *vdev, const char *na= me); + #define vfio_platform_register_reset(__compat, __reset) \ static struct vfio_platform_reset_node __reset ## _node =3D { \ .owner =3D THIS_MODULE, \ --=20 2.41.0 From nobody Fri Nov 29 16:32:09 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id D10A31684A8 for ; Tue, 17 Sep 2024 09:39:13 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726565955; cv=none; b=Mx201udCeS9lU3a9gty3gSkxBT/Gl/aym7nRo/et8+PC+pzM3YUweFZEcaoCL8oqJZ03hImmc9PdhJlXab4VYxjNdYQpZFAS5uioo5U1mh6pMzV12ts85yYblk5u5GGw/dZR1s0NPYfncu66D7mY+WDuHLFMmJWKgFjVie6RKIQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726565955; c=relaxed/simple; bh=rf4F8czHFbs9uDTC6tsePIcakRJIZP/Ldz26DPqiW+c=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=NF2EooRV/Z/cIBlS/4Z+81t5tyTdFFDvzFjsMUBJMbVHGTRNenwx8xZWufiX/Jvesojy+j3DR8kKt5w4JCnR5ImFdOHeUsEc6BRNoYmdyTrS/r3FsOuAn6Rl/0TsszyJgdPHSkI2F3Z2f1z1ByagW7jxYBv1chPTpwf10yw1kGw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=R9fpWt0M; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="R9fpWt0M" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726565952; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=IToaz1nja85sQIj1yHHKM5f1NusWJO/Amiu2qLuJhU4=; b=R9fpWt0MoPYH2QnOWDyNGwy+93XKbqMeqQSm9LWlTE2h/ADA8X++FOAViIwJmPNxBl4ajZ tNgExGsdVoG5dWE66MUqoI65lxZj7Y+70X/P5qIAIetpSZp3CPYKzWtw4+ax7uUQ94yaNa DOpTyTn9sMrV9mQz9x6GyTnWjDJ8X1I= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-644-UwutjC3GMbOvnZY2jeC16w-1; Tue, 17 Sep 2024 05:39:09 -0400 X-MC-Unique: UwutjC3GMbOvnZY2jeC16w-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id C7CFF1953945; Tue, 17 Sep 2024 09:39:07 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.23]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 9404230001A1; Tue, 17 Sep 2024 09:39:03 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, treding@nvidia.com, vbhadram@nvidia.com, jonathanh@nvidia.com, mperttunen@nvidia.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, alex.williamson@redhat.com, clg@redhat.com, alexandre.torgue@foss.st.com, joabreu@synopsys.com Cc: msalter@redhat.com Subject: [RFC PATCH v2 2/6] vfio_platform: reset: Prepare for additional reset ops Date: Tue, 17 Sep 2024 11:38:10 +0200 Message-ID: <20240917093851.990344-3-eric.auger@redhat.com> In-Reply-To: <20240917093851.990344-1-eric.auger@redhat.com> References: <20240917093851.990344-1-eric.auger@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Reset modules currently offer a single reset function that gets called on open, close and VFIO_DEVICE_RESET ioctl. For more complex devices this infrastructure looks too simplistic. Indeed some resources may be needed from the init() until the release(), like clocks, resets. A single function does not allow that setup. So let's encapsulate the current reset function into an ops struct that will be soon extended with new open and close callbacks. Existing reset modules are adapted. Signed-off-by: Eric Auger --- .../platform/reset/vfio_platform_amdxgbe.c | 7 +++- .../reset/vfio_platform_calxedaxgmac.c | 7 +++- drivers/vfio/platform/vfio_platform_common.c | 36 ++++++++++--------- drivers/vfio/platform/vfio_platform_private.h | 30 ++++++++++------ 4 files changed, 50 insertions(+), 30 deletions(-) diff --git a/drivers/vfio/platform/reset/vfio_platform_amdxgbe.c b/drivers/= vfio/platform/reset/vfio_platform_amdxgbe.c index abdca900802d..037d6e5ffd92 100644 --- a/drivers/vfio/platform/reset/vfio_platform_amdxgbe.c +++ b/drivers/vfio/platform/reset/vfio_platform_amdxgbe.c @@ -109,7 +109,12 @@ static int vfio_platform_amdxgbe_reset(struct vfio_pla= tform_device *vdev) return 0; } =20 -module_vfio_reset_handler("amd,xgbe-seattle-v1a", vfio_platform_amdxgbe_re= set); +static const struct vfio_platform_of_reset_ops +vfio_platform_amdxgbe_of_reset_ops =3D { + .reset =3D vfio_platform_amdxgbe_reset, +}; + +module_vfio_reset_handler("amd,xgbe-seattle-v1a", vfio_platform_amdxgbe_of= _reset_ops); =20 MODULE_VERSION("0.1"); MODULE_LICENSE("GPL v2"); diff --git a/drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c b/dri= vers/vfio/platform/reset/vfio_platform_calxedaxgmac.c index 63cc7f0b2e4a..f1d62821aa73 100644 --- a/drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c +++ b/drivers/vfio/platform/reset/vfio_platform_calxedaxgmac.c @@ -66,7 +66,12 @@ static int vfio_platform_calxedaxgmac_reset(struct vfio_= platform_device *vdev) return 0; } =20 -module_vfio_reset_handler("calxeda,hb-xgmac", vfio_platform_calxedaxgmac_r= eset); +static const struct vfio_platform_of_reset_ops +vfio_platform_calxedaxgmac_of_reset_ops =3D { + .reset =3D vfio_platform_calxedaxgmac_reset, +}; + +module_vfio_reset_handler("calxeda,hb-xgmac", vfio_platform_calxedaxgmac_o= f_reset_ops); =20 MODULE_VERSION(DRIVER_VERSION); MODULE_LICENSE("GPL v2"); diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/pl= atform/vfio_platform_common.c index 6861f977fd5b..976864d2e2f0 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -28,23 +28,23 @@ static LIST_HEAD(reset_list); static DEFINE_MUTEX(driver_lock); =20 -static vfio_platform_reset_fn_t vfio_platform_lookup_reset(const char *com= pat, - struct module **module) +static const struct vfio_platform_of_reset_ops * +vfio_platform_lookup_reset(const char *compat, struct module **module) { + const struct vfio_platform_of_reset_ops *ops =3D NULL; struct vfio_platform_reset_node *iter; - vfio_platform_reset_fn_t reset_fn =3D NULL; =20 mutex_lock(&driver_lock); list_for_each_entry(iter, &reset_list, link) { if (!strcmp(iter->compat, compat) && try_module_get(iter->owner)) { *module =3D iter->owner; - reset_fn =3D iter->of_reset; + ops =3D &iter->ops; break; } } mutex_unlock(&driver_lock); - return reset_fn; + return ops; } =20 static int vfio_platform_acpi_probe(struct vfio_platform_device *vdev, @@ -106,7 +106,7 @@ static bool vfio_platform_has_reset(struct vfio_platfor= m_device *vdev) if (VFIO_PLATFORM_IS_ACPI(vdev)) return vfio_platform_acpi_has_reset(vdev); =20 - return vdev->of_reset ? true : false; + return vdev->of_reset_ops ? true : false; } =20 static int vfio_platform_get_reset(struct vfio_platform_device *vdev) @@ -114,15 +114,15 @@ static int vfio_platform_get_reset(struct vfio_platfo= rm_device *vdev) if (VFIO_PLATFORM_IS_ACPI(vdev)) return vfio_platform_acpi_has_reset(vdev) ? 0 : -ENOENT; =20 - vdev->of_reset =3D vfio_platform_lookup_reset(vdev->compat, - &vdev->reset_module); - if (!vdev->of_reset) { + vdev->of_reset_ops =3D vfio_platform_lookup_reset(vdev->compat, + &vdev->reset_module); + if (!vdev->of_reset_ops) { request_module("vfio-reset:%s", vdev->compat); - vdev->of_reset =3D vfio_platform_lookup_reset(vdev->compat, - &vdev->reset_module); + vdev->of_reset_ops =3D vfio_platform_lookup_reset(vdev->compat, + &vdev->reset_module); } =20 - return vdev->of_reset ? 0 : -ENOENT; + return vdev->of_reset_ops ? 0 : -ENOENT; } =20 static void vfio_platform_put_reset(struct vfio_platform_device *vdev) @@ -130,7 +130,7 @@ static void vfio_platform_put_reset(struct vfio_platfor= m_device *vdev) if (VFIO_PLATFORM_IS_ACPI(vdev)) return; =20 - if (vdev->of_reset) + if (vdev->of_reset_ops) module_put(vdev->reset_module); } =20 @@ -219,9 +219,9 @@ static int vfio_platform_call_reset(struct vfio_platfor= m_device *vdev, if (VFIO_PLATFORM_IS_ACPI(vdev)) { dev_info(vdev->device, "reset\n"); return vfio_platform_acpi_call_reset(vdev, extra_dbg); - } else if (vdev->of_reset) { + } else if (vdev->of_reset_ops && vdev->of_reset_ops->reset) { dev_info(vdev->device, "reset\n"); - return vdev->of_reset(vdev); + return vdev->of_reset_ops->reset(vdev); } =20 dev_warn(vdev->device, "no reset function found!\n"); @@ -686,13 +686,15 @@ void __vfio_platform_register_reset(struct vfio_platf= orm_reset_node *node) EXPORT_SYMBOL_GPL(__vfio_platform_register_reset); =20 void vfio_platform_unregister_reset(const char *compat, - vfio_platform_reset_fn_t fn) + struct vfio_platform_of_reset_ops ops) { struct vfio_platform_reset_node *iter, *temp; =20 mutex_lock(&driver_lock); list_for_each_entry_safe(iter, temp, &reset_list, link) { - if (!strcmp(iter->compat, compat) && (iter->of_reset =3D=3D fn)) { + if (!strcmp(iter->compat, compat) && + !memcmp(&iter->ops, &ops, + sizeof(struct vfio_platform_of_reset_ops))) { list_del(&iter->link); break; } diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/p= latform/vfio_platform_private.h index 20d67634bc41..333aefe2a1fc 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -65,18 +65,26 @@ struct vfio_platform_device { struct resource* (*get_resource)(struct vfio_platform_device *vdev, int i); int (*get_irq)(struct vfio_platform_device *vdev, int i); - int (*of_reset)(struct vfio_platform_device *vdev); =20 + const struct vfio_platform_of_reset_ops *of_reset_ops; bool reset_required; }; =20 -typedef int (*vfio_platform_reset_fn_t)(struct vfio_platform_device *vdev); +/** + * struct vfio_platform_of_reset_ops - reset ops + * + * @reset: reset function (required) + */ +struct vfio_platform_of_reset_ops { + int (*reset)(struct vfio_platform_device *vdev); +}; + =20 struct vfio_platform_reset_node { struct list_head link; char *compat; struct module *owner; - vfio_platform_reset_fn_t of_reset; + struct vfio_platform_of_reset_ops ops; }; =20 int vfio_platform_init_common(struct vfio_platform_device *vdev); @@ -104,29 +112,29 @@ int vfio_platform_set_irqs_ioctl(struct vfio_platform= _device *vdev, =20 void __vfio_platform_register_reset(struct vfio_platform_reset_node *n); void vfio_platform_unregister_reset(const char *compat, - vfio_platform_reset_fn_t fn); + struct vfio_platform_of_reset_ops ops); =20 struct vfio_platform_region * vfio_platform_get_region(struct vfio_platform_device *vdev, const char *na= me); =20 -#define vfio_platform_register_reset(__compat, __reset) \ -static struct vfio_platform_reset_node __reset ## _node =3D { \ +#define vfio_platform_register_reset(__compat, __ops) \ +static struct vfio_platform_reset_node __ops ## _node =3D { \ .owner =3D THIS_MODULE, \ .compat =3D __compat, \ - .of_reset =3D __reset, \ + .ops =3D __ops, \ }; \ -__vfio_platform_register_reset(&__reset ## _node) +__vfio_platform_register_reset(&__ops ## _node) =20 -#define module_vfio_reset_handler(compat, reset) \ +#define module_vfio_reset_handler(compat, ops) \ MODULE_ALIAS("vfio-reset:" compat); \ static int __init reset ## _module_init(void) \ { \ - vfio_platform_register_reset(compat, reset); \ + vfio_platform_register_reset(compat, ops); \ return 0; \ }; \ static void __exit reset ## _module_exit(void) \ { \ - vfio_platform_unregister_reset(compat, reset); \ + vfio_platform_unregister_reset(compat, ops); \ }; \ module_init(reset ## _module_init); \ module_exit(reset ## _module_exit) --=20 2.41.0 From nobody Fri Nov 29 16:32:09 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id E2B2816C84B for ; Tue, 17 Sep 2024 09:39:17 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726565959; cv=none; b=SkqEd1BlG7h4w+FN6rYDlpNVf4cg1eY8Cd+2L+m8QdqpL9QZ+RLIdbBYYEGbErQDWgHl8u8YFQ9CY+qiwS2J98EnhZdUUt/P8Bxaj++108Jp4K3Nb6yYID9V0fovr7gFJOkxXdsyL7iNZYZiPi3eyxL1er33k5NBbgpn+aFKWX0= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726565959; c=relaxed/simple; bh=nXSFRm5EggAjXzaZJlUbYnL6NsfIlysuS1hkMsyj8hA=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=txoeNHxYDRUyL4yqKQtN+NjJjpkZZVCkIVyELsTJK6BKMiqYDH4nS1cRYDx/eaQvx0CTMvoBpxgmtKKH8E31k2NE+fmHke2XDZOsgJGs0OrDVYWkIV1g8Iy1EuQDVDnLwbWV5C2wGzJr/sYGwKy4CxtemWFAQIjtWyrF7XprycQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=B8RNNNoz; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="B8RNNNoz" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726565957; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=FFwP7NucSuTkSHwGEdDxPI8XV0NW9fB3DoBDL5pk6ro=; b=B8RNNNozXthh6HtGLTbyVbazWs32hTIfr7/OhUlt4nwyu9p7N2OOZYtdjfpg9lx3cSM3yn cYn4uojFs5+xlBRLMW5rt6ihd7QIwEAnS3wy7jqndbrSkJ3UV0DXbcurDixBmUkuMxkxrt sXvf/rg+vb9pYkmoBP17t5Fszmpxeek= Received: from mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-81--UrbarYZOg6i5bf_PQ73tA-1; Tue, 17 Sep 2024 05:39:13 -0400 X-MC-Unique: -UrbarYZOg6i5bf_PQ73tA-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 47A08195608B; Tue, 17 Sep 2024 09:39:12 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.23]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 4F72130001A1; Tue, 17 Sep 2024 09:39:08 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, treding@nvidia.com, vbhadram@nvidia.com, jonathanh@nvidia.com, mperttunen@nvidia.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, alex.williamson@redhat.com, clg@redhat.com, alexandre.torgue@foss.st.com, joabreu@synopsys.com Cc: msalter@redhat.com Subject: [RFC PATCH v2 3/6] vfio-platform: Move region initialization to vfio_platform_init_common Date: Tue, 17 Sep 2024 11:38:11 +0200 Message-ID: <20240917093851.990344-4-eric.auger@redhat.com> In-Reply-To: <20240917093851.990344-1-eric.auger@redhat.com> References: <20240917093851.990344-1-eric.auger@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" We plan to introduce a new reset module init() callback. This latter would need to have vdev->regions populated. At the moment this latter is allocated and populated later on device open. Call vfio_platform_regions_init() in vfio_platform_init_common() instead. Signed-off-by: Eric Auger --- drivers/vfio/platform/vfio_platform_common.c | 15 +++++++-------- 1 file changed, 7 insertions(+), 8 deletions(-) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/pl= atform/vfio_platform_common.c index 976864d2e2f0..cd0f2ebff586 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -243,7 +243,6 @@ void vfio_platform_close_device(struct vfio_device *cor= e_vdev) ret, extra_dbg ? extra_dbg : ""); } pm_runtime_put(vdev->device); - vfio_platform_regions_cleanup(vdev); vfio_platform_irq_cleanup(vdev); } EXPORT_SYMBOL_GPL(vfio_platform_close_device); @@ -255,13 +254,9 @@ int vfio_platform_open_device(struct vfio_device *core= _vdev) const char *extra_dbg =3D NULL; int ret; =20 - ret =3D vfio_platform_regions_init(vdev); - if (ret) - return ret; - ret =3D vfio_platform_irq_init(vdev); if (ret) - goto err_irq; + return ret; =20 ret =3D pm_runtime_get_sync(vdev->device); if (ret < 0) @@ -280,8 +275,6 @@ int vfio_platform_open_device(struct vfio_device *core_= vdev) err_rst: pm_runtime_put(vdev->device); vfio_platform_irq_cleanup(vdev); -err_irq: - vfio_platform_regions_cleanup(vdev); return ret; } EXPORT_SYMBOL_GPL(vfio_platform_open_device); @@ -658,12 +651,17 @@ int vfio_platform_init_common(struct vfio_platform_de= vice *vdev) return ret; =20 vdev->device =3D dev; + ret =3D vfio_platform_regions_init(vdev); + if (ret) + return ret; + mutex_init(&vdev->igate); =20 ret =3D vfio_platform_get_reset(vdev); if (ret && vdev->reset_required) { dev_err(dev, "No reset function found for device %s\n", vdev->name); + vfio_platform_regions_cleanup(vdev); return ret; } =20 @@ -674,6 +672,7 @@ EXPORT_SYMBOL_GPL(vfio_platform_init_common); void vfio_platform_release_common(struct vfio_platform_device *vdev) { vfio_platform_put_reset(vdev); + vfio_platform_regions_cleanup(vdev); } EXPORT_SYMBOL_GPL(vfio_platform_release_common); =20 --=20 2.41.0 From nobody Fri Nov 29 16:32:09 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C5F6715DBD5 for ; Tue, 17 Sep 2024 09:39:23 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726565965; cv=none; b=gMt0U39mNSQEx9PIgUvCEKAgpCGZj0DxB+to2WBz5hKnX9PD2DFYXqj4sdM0b5e4V0RKlfTWMLrnzjB3nvbq5na1Dzyhsk/yykNjaVNHlVXP3v+VqB/QZBvW68IkxRBtDrTgqaOzkaSmW33Cq7CD9oSY62xtepGyZwK6AGeI2hc= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726565965; c=relaxed/simple; bh=0RDnGkcH5gBUXPSkOdE1ySzJO4gf/kusKNj3cc3gv2g=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mdHIBIsufckpnYW4yKR+wiw5M3Nii6D2utm+6PPth/pFwyNAmj+qujnU0ziqFfYYCZvToFnl+GJv1XHKR47lBR8Wn/zdC8C4H0lZFLk9FDRAdjGGx6RmRumCvZ0+FgkIkSoaPOUU9Nb/WIjfbF64GHG5poiIiBS2CDy2rIavL9I= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=FsiOrZ+9; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="FsiOrZ+9" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726565962; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=kp4U5UOayVdGnJFTxBOBON9W0uurDj22AVgPaFZSSVo=; b=FsiOrZ+98iVvNmTGt2cH45ScjffpTTv1eZi+Ami9cuqD2yIuE7yNLBP4bn2gjuMu2Hng/1 GYIZsa6LvPuznsmKFpkRzYCBeZE2Bzv3gchEG6gu5PfsRFl+rbuI+kuvdPe5SpezyaeuUr G7ia8BJKgefcu7BNm5BYuFyU2kzpIdo= Received: from mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-136-xuKen4ggP-yPwqEtwt7wAQ-1; Tue, 17 Sep 2024 05:39:19 -0400 X-MC-Unique: xuKen4ggP-yPwqEtwt7wAQ-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-05.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id E74D61956048; Tue, 17 Sep 2024 09:39:17 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.23]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id C0D4D30001A1; Tue, 17 Sep 2024 09:39:12 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, treding@nvidia.com, vbhadram@nvidia.com, jonathanh@nvidia.com, mperttunen@nvidia.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, alex.williamson@redhat.com, clg@redhat.com, alexandre.torgue@foss.st.com, joabreu@synopsys.com Cc: msalter@redhat.com Subject: [RFC PATCH v2 4/6] vfio_platform: reset: Introduce new init and release callbacks Date: Tue, 17 Sep 2024 11:38:12 +0200 Message-ID: <20240917093851.990344-5-eric.auger@redhat.com> In-Reply-To: <20240917093851.990344-1-eric.auger@redhat.com> References: <20240917093851.990344-1-eric.auger@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Some devices may require resources such as clocks and resets which cannot be handled in the vfio_platform agnostic code. Let's add 2 new callbacks to handle those resources. Those new callbacks are optional, as opposed to the reset callback. In case they are implemented, both need to be. They are not implemented by the existing reset modules. Signed-off-by: Eric Auger --- drivers/vfio/platform/vfio_platform_common.c | 23 ++++++++++++++++++- drivers/vfio/platform/vfio_platform_private.h | 6 +++++ 2 files changed, 28 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/platform/vfio_platform_common.c b/drivers/vfio/pl= atform/vfio_platform_common.c index cd0f2ebff586..8d40ca452bbb 100644 --- a/drivers/vfio/platform/vfio_platform_common.c +++ b/drivers/vfio/platform/vfio_platform_common.c @@ -228,6 +228,23 @@ static int vfio_platform_call_reset(struct vfio_platfo= rm_device *vdev, return -EINVAL; } =20 +static void vfio_platform_reset_module_release(struct vfio_platform_device= *vpdev) +{ + if (VFIO_PLATFORM_IS_ACPI(vpdev)) + return; + if (vpdev->of_reset_ops && vpdev->of_reset_ops->release) + vpdev->of_reset_ops->release(vpdev); +} + +static int vfio_platform_reset_module_init(struct vfio_platform_device *vp= dev) +{ + if (VFIO_PLATFORM_IS_ACPI(vpdev)) + return 0; + if (vpdev->of_reset_ops && vpdev->of_reset_ops->init) + return vpdev->of_reset_ops->init(vpdev); + return 0; +} + void vfio_platform_close_device(struct vfio_device *core_vdev) { struct vfio_platform_device *vdev =3D @@ -665,12 +682,16 @@ int vfio_platform_init_common(struct vfio_platform_de= vice *vdev) return ret; } =20 - return 0; + ret =3D vfio_platform_reset_module_init(vdev); + if (ret) + vfio_platform_put_reset(vdev); + return ret; } EXPORT_SYMBOL_GPL(vfio_platform_init_common); =20 void vfio_platform_release_common(struct vfio_platform_device *vdev) { + vfio_platform_reset_module_release(vdev); vfio_platform_put_reset(vdev); vfio_platform_regions_cleanup(vdev); } diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/p= latform/vfio_platform_private.h index 333aefe2a1fc..33183addd235 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -74,9 +74,13 @@ struct vfio_platform_device { * struct vfio_platform_of_reset_ops - reset ops * * @reset: reset function (required) + * @init: Called on device attach (optional) + * @release: Called on device detach (optional) */ struct vfio_platform_of_reset_ops { int (*reset)(struct vfio_platform_device *vdev); + int (*init)(struct vfio_platform_device *vdev); + void (*release)(struct vfio_platform_device *vdev); }; =20 =20 @@ -129,6 +133,8 @@ __vfio_platform_register_reset(&__ops ## _node) MODULE_ALIAS("vfio-reset:" compat); \ static int __init reset ## _module_init(void) \ { \ + if (!!ops.init ^ !!ops.release) \ + return -EINVAL; \ vfio_platform_register_reset(compat, ops); \ return 0; \ }; \ --=20 2.41.0 From nobody Fri Nov 29 16:32:09 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id EED09172BB9 for ; Tue, 17 Sep 2024 09:39:27 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.133.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726565969; cv=none; b=YC5UvVBzOMW36LTCiAdbtuQYD4DQ+O5q7mlh/ZRRv2zdoRvcnTFV09jkp2dL8lqef3tbju4kaIIBufYjH/a/GiL66P4Gmdm0KamGg6tL4jsH/756JoNMMkJbyjfc4Gtf7iYblCKYfQmmDYztEakxP0iu/jl2hiIBjjQukezd8bg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726565969; c=relaxed/simple; bh=tOlw+0SpkXvqDfEuVO4XzD3JyEACideS3j8tZUxF4Zw=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=mJCBu2GKEIoU3p8RMUcL4OAH00g+rRDf78Vs4fKI9OwlRPvExlgyeZ3mJvNumQIVyL54PKwHASb91YvQZmLbKNpEdBAdZczA2LdhFlsqGzspW4tneGsIcOrABRWWocP3HFm2OljhplaS7+ntS25ly948l2owyI4i+P+r4CdjDik= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=Q62YrJW+; arc=none smtp.client-ip=170.10.133.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="Q62YrJW+" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726565966; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=vAawFAb52fCqX52IPWL8KVnHoQv/EF5r6l5LZxJMwgM=; b=Q62YrJW+YRqc/QZThQUdqTUeuSYaScsoBvFriMeLCVtR4hiokVPPOd3o4M1ySsZbORaNS+ laGbI84sypdU0Om8ZtgT+X3Y+UjKvSYiAUbB5Dw4N/s0zV0JpBd0I3gLQ3jqkIoOIfgEMo z1Y0Cq4pwQX01XNKwbHxEwYECUbSRg4= Received: from mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-378--XUP5QaxNu-cauuQcGDg7g-1; Tue, 17 Sep 2024 05:39:23 -0400 X-MC-Unique: -XUP5QaxNu-cauuQcGDg7g-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-02.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id 4B0F61956096; Tue, 17 Sep 2024 09:39:22 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.23]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id 327CE30001A1; Tue, 17 Sep 2024 09:39:17 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, treding@nvidia.com, vbhadram@nvidia.com, jonathanh@nvidia.com, mperttunen@nvidia.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, alex.williamson@redhat.com, clg@redhat.com, alexandre.torgue@foss.st.com, joabreu@synopsys.com Cc: msalter@redhat.com Subject: [RFC PATCH v2 5/6] vfio-platform: Add a new handle to store reset data Date: Tue, 17 Sep 2024 11:38:13 +0200 Message-ID: <20240917093851.990344-6-eric.auger@redhat.com> In-Reply-To: <20240917093851.990344-1-eric.auger@redhat.com> References: <20240917093851.990344-1-eric.auger@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" Add a new field to store data used by the reset modules. Signed-off-by: Eric Auger --- drivers/vfio/platform/vfio_platform_private.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/vfio/platform/vfio_platform_private.h b/drivers/vfio/p= latform/vfio_platform_private.h index 33183addd235..3e50d48005a2 100644 --- a/drivers/vfio/platform/vfio_platform_private.h +++ b/drivers/vfio/platform/vfio_platform_private.h @@ -68,6 +68,8 @@ struct vfio_platform_device { =20 const struct vfio_platform_of_reset_ops *of_reset_ops; bool reset_required; + /* This field can be used by reset driver to store some data */ + void *reset_opaque; }; =20 /** --=20 2.41.0 From nobody Fri Nov 29 16:32:09 2024 Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 94E28175D35 for ; Tue, 17 Sep 2024 09:39:32 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=170.10.129.124 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726565974; cv=none; b=ghmvvEDQ2VveZOeeD4quj3MUANP71ZYZ6BWeowAE971VRPk98iBCmfxl0tcupmdpJ7fLRVUv0Lhpl64+hgC3AtFbwJDgygSMy2ZC8lgVTEnpQ9T7fmGSja+5fsEB85nFYeleYplxB/608jXR2T687EsNFCjZ8QeRTIK5g5T5Scs= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1726565974; c=relaxed/simple; bh=DD7LKAAtg82s+28f/r6UEMp2lwsOQZEDcHe9oYbBG+Q=; h=From:To:Cc:Subject:Date:Message-ID:In-Reply-To:References: MIME-Version; b=fvdQsriVps5PhfsXiz+yO/iRVBKXO60XlXxfVb/YDQnIRdO9iF744bp9YpcxSSGvHUuvSAJVmU6OVePf5X2T8i1aqW7WVJco5Wc1gGP3t/6ofjUPblsUL9JmLJZ/aA2V6Al6G4g18EV//Zq5vB6/VNFyKhy/343YoT3oob5Qcj0= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com; spf=pass smtp.mailfrom=redhat.com; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b=PYO+6Vlt; arc=none smtp.client-ip=170.10.129.124 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=redhat.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=redhat.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="PYO+6Vlt" DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1726565971; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=yJBF0n0Br65n2hjLZ9wmJHiD+OfAK3na6qQbL7dPnQQ=; b=PYO+6VltLLdY26Wsb05/tbyAomQvD/A/zHxNruB98yclDDjl2CbIS4Sz/f7hi6YHKbfUTi CiFXjZgNU8W2vNvxiqau5sp5Ev8+5fGDpCzvGINQCLfDjdTTONrkPCAm5ziyS+SE9uzJwe XJf5uohSRg6frrcPkXoBEZueymifIho= Received: from mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (ec2-54-186-198-63.us-west-2.compute.amazonaws.com [54.186.198.63]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-645-Bm8CA_JRN8av95K9V719Rw-1; Tue, 17 Sep 2024 05:39:28 -0400 X-MC-Unique: Bm8CA_JRN8av95K9V719Rw-1 Received: from mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com [10.30.177.4]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by mx-prod-mc-04.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTPS id BFED419560A3; Tue, 17 Sep 2024 09:39:26 +0000 (UTC) Received: from laptop.redhat.com (unknown [10.39.193.23]) by mx-prod-int-01.mail-002.prod.us-west-2.aws.redhat.com (Postfix) with ESMTP id AB43E30001A1; Tue, 17 Sep 2024 09:39:22 +0000 (UTC) From: Eric Auger To: eric.auger.pro@gmail.com, eric.auger@redhat.com, treding@nvidia.com, vbhadram@nvidia.com, jonathanh@nvidia.com, mperttunen@nvidia.com, linux-kernel@vger.kernel.org, kvm@vger.kernel.org, alex.williamson@redhat.com, clg@redhat.com, alexandre.torgue@foss.st.com, joabreu@synopsys.com Cc: msalter@redhat.com Subject: [RFC PATCH v2 6/6] vfio/platform: Add tegra234-mgbe vfio platform reset module Date: Tue, 17 Sep 2024 11:38:14 +0200 Message-ID: <20240917093851.990344-7-eric.auger@redhat.com> In-Reply-To: <20240917093851.990344-1-eric.auger@redhat.com> References: <20240917093851.990344-1-eric.auger@redhat.com> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-Scanned-By: MIMEDefang 3.4.1 on 10.30.177.4 Content-Type: text/plain; charset="utf-8" init and release callbacks take care of resources requested by the reset code, ie. clocks and reset. The actual reset function toggles the mac reset, disable mac ihterrupts, stop DMA requests and do a SW reset. Signed-off-by: Eric Auger --- drivers/vfio/platform/reset/Kconfig | 7 + drivers/vfio/platform/reset/Makefile | 2 + .../reset/vfio_platform_tegra234_mgbe.c | 234 ++++++++++++++++++ 3 files changed, 243 insertions(+) create mode 100644 drivers/vfio/platform/reset/vfio_platform_tegra234_mgbe= .c diff --git a/drivers/vfio/platform/reset/Kconfig b/drivers/vfio/platform/re= set/Kconfig index dcc08dc145a5..3113fae21ebf 100644 --- a/drivers/vfio/platform/reset/Kconfig +++ b/drivers/vfio/platform/reset/Kconfig @@ -14,6 +14,13 @@ config VFIO_PLATFORM_AMDXGBE_RESET =20 If you don't know what to do here, say N. =20 +config VFIO_PLATFORM_TEGRA234_MGBE_RESET + tristate "VFIO support for NVidia tegra234 MGBE reset" + help + Enables the VFIO platform driver to handle reset for NVidia tegra234 mg= be + + If you don't know what to do here, say N. + config VFIO_PLATFORM_BCMFLEXRM_RESET tristate "VFIO support for Broadcom FlexRM reset" depends on ARCH_BCM_IPROC || COMPILE_TEST diff --git a/drivers/vfio/platform/reset/Makefile b/drivers/vfio/platform/r= eset/Makefile index 7294c5ea122e..5ebef71f61a0 100644 --- a/drivers/vfio/platform/reset/Makefile +++ b/drivers/vfio/platform/reset/Makefile @@ -1,7 +1,9 @@ # SPDX-License-Identifier: GPL-2.0 vfio-platform-calxedaxgmac-y :=3D vfio_platform_calxedaxgmac.o vfio-platform-amdxgbe-y :=3D vfio_platform_amdxgbe.o +vfio-platform-tegra234-mgbe-y :=3D vfio_platform_tegra234_mgbe.o =20 obj-$(CONFIG_VFIO_PLATFORM_CALXEDAXGMAC_RESET) +=3D vfio-platform-calxedax= gmac.o obj-$(CONFIG_VFIO_PLATFORM_AMDXGBE_RESET) +=3D vfio-platform-amdxgbe.o +obj-$(CONFIG_VFIO_PLATFORM_TEGRA234_MGBE_RESET) +=3D vfio-platform-tegra23= 4-mgbe.o obj-$(CONFIG_VFIO_PLATFORM_BCMFLEXRM_RESET) +=3D vfio_platform_bcmflexrm.o diff --git a/drivers/vfio/platform/reset/vfio_platform_tegra234_mgbe.c b/dr= ivers/vfio/platform/reset/vfio_platform_tegra234_mgbe.c new file mode 100644 index 000000000000..8e889e5d04f3 --- /dev/null +++ b/drivers/vfio/platform/reset/vfio_platform_tegra234_mgbe.c @@ -0,0 +1,234 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * VFIO platform driver specialized for NVidia tegra234-mgbe reset + * Code is inspired from dwxgmac2_dma.c and dwmac-tegra.c code + * + * Copyright (c) 2024 Red Hat, Inc. All rights reserved. + * Author: Eric Auger + */ + +#include +#include +#include +#include +#include + +#include "../vfio_platform_private.h" + +static const char *const mgbe_clks[] =3D { + "rx-pcs", "tx", "tx-pcs", "mac-divider", "mac", "mgbe", "ptp-ref", "mac" +}; + +struct tegra_mgbe { + struct clk_bulk_data *clks; + struct reset_control *mac_rst; + void __iomem *mac; +}; + +#define XGMAC_TX_CONFIG 0x00000000 +#define XGMAC_CONFIG_TE BIT(0) +#define XGMAC_RX_CONFIG 0x00000004 +#define XGMAC_CONFIG_RE BIT(0) +#define XGMAC_DMA_MODE 0x00003000 +#define XGMAC_SWR BIT(0) + +#define XGMAC_DMA_CH_INT_EN(x) (0x00003138 + (0x80 * (x))) +#define XGMAC_TIE BIT(0) +#define XGMAC_RIE BIT(6) +#define XGMAC_RBUE BIT(7) +#define XGMAC_DMA_INT_DEFAULT_RX (XGMAC_RBUE | XGMAC_RIE) +#define XGMAC_DMA_INT_DEFAULT_TX (XGMAC_TIE) + +#define XGMAC_DMA_CH_STATUS(x) (0x00003160 + (0x80 * (x))) +#define XGMAC_DMA_CH_RX_CONTROL(x) (0x00003108 + (0x80 * (x))) +#define XGMAC_RXST BIT(0) +#define XGMAC_DMA_CH_TX_CONTROL(x) (0x00003104 + (0x80 * (x))) +#define XGMAC_TXST BIT(0) + +#define XGMAC_INT_STATUS 0x000000b0 +#define XGMAC_INT_EN 0x000000b4 + +#define MGBE_WRAP_COMMON_INTR_ENABLE 0x8704 + +static int +toggle_reset(struct device *dev, const char *rst_str, struct reset_control= *rst) +{ + int ret; + + ret =3D reset_control_assert(rst); + if (ret < 0) + dev_err(dev, "Failed to assert %s reset %d\n", + rst_str, ret); + usleep_range(2000, 4000); + + ret =3D reset_control_deassert(rst); + if (ret < 0) + dev_err(dev, "Failed to deassert %s reset %d\n", rst_str, ret); + usleep_range(2000, 4000); + return ret; +} + +static void stop_dma(void __iomem *mac, uint channel) +{ + u32 value; + + /* DMA Stop RX */ + value =3D readl(mac + XGMAC_DMA_CH_RX_CONTROL(channel)); + value &=3D ~XGMAC_RXST; + writel(value, mac + XGMAC_DMA_CH_RX_CONTROL(channel)); + + value =3D readl(mac + XGMAC_RX_CONFIG); + value &=3D ~XGMAC_CONFIG_RE; + writel(value, mac + XGMAC_RX_CONFIG); + + usleep_range(10, 15); + + /* DMA Stop TX */ + value =3D readl(mac + XGMAC_DMA_CH_TX_CONTROL(channel)); + value &=3D ~XGMAC_RXST; + writel(value, mac + XGMAC_DMA_CH_TX_CONTROL(channel)); + + value =3D readl(mac + XGMAC_TX_CONFIG); + value &=3D ~XGMAC_CONFIG_TE; + writel(value, mac + XGMAC_TX_CONFIG); + + usleep_range(10, 15); +} + +static int dma_sw_reset(void __iomem *mac) +{ + u32 value; + + value =3D readl(mac + XGMAC_DMA_MODE); + writel(value | XGMAC_SWR, mac + XGMAC_DMA_MODE); + return readl_poll_timeout(mac + XGMAC_DMA_MODE, value, + !(value & XGMAC_SWR), 0, 100000); +} + +static void disable_dma_irq(void __iomem *mac, u32 channel) +{ + u32 intr_en, intr_status; + + intr_en =3D readl(mac + XGMAC_DMA_CH_INT_EN(channel)); + + intr_en &=3D ~XGMAC_DMA_INT_DEFAULT_RX; + intr_en &=3D ~XGMAC_DMA_INT_DEFAULT_TX; + writel(intr_en, mac + XGMAC_DMA_CH_INT_EN(channel)); + usleep_range(10, 15); + + intr_status =3D readl(mac + XGMAC_DMA_CH_STATUS(channel)); + writel(0, mac + XGMAC_DMA_CH_STATUS(channel)); +} + +static int prepare_enable_clocks(struct device *dev, struct clk_bulk_data = **clocks) +{ + struct clk_bulk_data *clks; + int ret; + + clks =3D kcalloc(ARRAY_SIZE(mgbe_clks), sizeof(*clks), GFP_KERNEL); + if (!clks) + return -ENOMEM; + + for (int i =3D 0; i < ARRAY_SIZE(mgbe_clks); i++) + clks[i].id =3D mgbe_clks[i]; + + ret =3D devm_clk_bulk_get(dev, ARRAY_SIZE(mgbe_clks), clks); + if (ret < 0) { + dev_err(dev, "Failed to get clocks %d\n", ret); + return ret; + } + + ret =3D clk_bulk_prepare_enable(ARRAY_SIZE(mgbe_clks), clks); + if (ret < 0) { + dev_err(dev, "Failed to prepare_enable clocks %d\n", ret); + return ret; + } + *clocks =3D clks; + return ret; +} + +static int vfio_platform_tegra234_mgbe_init(struct vfio_platform_device *v= pdev) +{ + struct tegra_mgbe *mgbe; + struct vfio_platform_region *mac_regs; + struct vfio_device *vdev =3D &vpdev->vdev; + struct device *dev =3D vdev->dev; + int ret =3D 0; + + mac_regs =3D vfio_platform_get_region(vpdev, "mac"); + if (!mac_regs) + return -EINVAL; + + mgbe =3D devm_kmalloc(dev, sizeof(struct tegra_mgbe), GFP_KERNEL); + if (!mgbe) + return -ENOMEM; + + ret =3D prepare_enable_clocks(dev, &mgbe->clks); + if (ret) + return ret; + + mgbe->mac_rst =3D devm_reset_control_get(dev, "mac"); + if (IS_ERR(mgbe->mac_rst)) { + dev_err(dev, "Failed to get mac reset %ld\n", PTR_ERR(mgbe->mac_rst)); + ret =3D PTR_ERR(mgbe->mac_rst); + return ret; + } + + mac_regs->ioaddr =3D ioremap(mac_regs->addr, mac_regs->size); + if (!mac_regs->ioaddr) + return -ENOMEM; + + mgbe->mac =3D mac_regs->ioaddr; + vpdev->reset_opaque =3D mgbe; + return ret; +} + +static void vfio_platform_tegra234_mgbe_release(struct vfio_platform_devic= e *vpdev) +{ + struct tegra_mgbe *mgbe =3D vpdev->reset_opaque; + + /* iounmap is done in vfio_platform_common */ + clk_bulk_disable_unprepare(ARRAY_SIZE(mgbe_clks), mgbe->clks); + vpdev->reset_opaque =3D NULL; +} + +static int vfio_platform_tegra234_mgbe_reset(struct vfio_platform_device *= vpdev) +{ + struct tegra_mgbe *mgbe =3D vpdev->reset_opaque; + struct vfio_device *vdev =3D &vpdev->vdev; + struct device *dev =3D vdev->dev; + int ret; + + if (!mgbe) + return -ENODEV; + + toggle_reset(dev, "mac", mgbe->mac_rst); + + for (int i =3D 0; i < 10; i++) + disable_dma_irq(mgbe->mac, i); + + writel(0, mgbe->mac + MGBE_WRAP_COMMON_INTR_ENABLE); + + for (int i =3D 0; i < 10; i++) + stop_dma(mgbe->mac, i); + + ret =3D dma_sw_reset(mgbe->mac); + if (ret) + dev_err(dev, "Failed to reset the DMA %d\n", ret); + + return ret; +} + +static const struct vfio_platform_of_reset_ops +vfio_platform_tegra234_mgbe_of_reset_ops =3D { + .reset =3D vfio_platform_tegra234_mgbe_reset, + .init =3D vfio_platform_tegra234_mgbe_init, + .release =3D vfio_platform_tegra234_mgbe_release, +}; + +module_vfio_reset_handler("nvidia,tegra234-mgbe", vfio_platform_tegra234_m= gbe_of_reset_ops); + +MODULE_VERSION("0.1"); +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Eric Auger "); +MODULE_DESCRIPTION("Reset support for NVidia tegra234 mgbe vfio platform d= evice"); --=20 2.41.0