From patchwork Mon Jan 8 09:20:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13513198 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id E4565C3DA6E for ; Mon, 8 Jan 2024 09:21:01 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 3AB4B8825B; Mon, 8 Jan 2024 09:21:01 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.129.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id C94A910E20F for ; Mon, 8 Jan 2024 09:20:59 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704705659; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=arbdXlZxmXJOFEKJF2R1zNrEF3q6fd9QYRmRT41BVKs=; b=ZaAh1UBpZYOIGe4CHgoR2Dr+xv24IpLV+01uQL52V6YjQgLJV985r1x3U/eJ7D4LnpDJFe 8pX0XeIA/3R7YdKGGaQqPI0P1VpAW6OtX7hefqNQWNnkos9hVOUX3l+cArJZmVq76kqW9h HXMY57PJ43kz+2IMwJr4vYSIHr+vVjo= Received: from mail-qk1-f199.google.com (mail-qk1-f199.google.com [209.85.222.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-457-Edbyen5zMXWOHpjmix8F7A-1; Mon, 08 Jan 2024 04:20:55 -0500 X-MC-Unique: Edbyen5zMXWOHpjmix8F7A-1 Received: by mail-qk1-f199.google.com with SMTP id af79cd13be357-7831a20711dso23478785a.0 for ; Mon, 08 Jan 2024 01:20:55 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704705655; x=1705310455; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=arbdXlZxmXJOFEKJF2R1zNrEF3q6fd9QYRmRT41BVKs=; b=QXaD4azsSc0a+0N126TIVij/PPjRGrcWcZNCI9QB0oL3wmDQL5gpO4LeLc36i4xWY7 V657GQWCubdvFff9quPchI4vB/isSrwF8iqCAJci7uLGidG+0TpSyhU/m+8SJBcZRbd+ jN48ol4PAO4IL+F3Kqio8WKN9Cd6mSNFh0+IAsq/J4Ui7CL1v4+AAdIJJfD4SNj5CMhR E+/Ufy5fDUWTkgnvVJq1WGQb7L0B7VcanizzC/bCpngqzcxdUogyBxNEhkmi9iCZe+UH OUbcAJyqTVSdsT2c4sla3G5bTrtX+GN8q1VUN1T/gKijxuFN/Ej1hQCIRCC9jgXNtjnx HTBw== X-Gm-Message-State: AOJu0Yz3se31dw9Rjlsyb/5+nfNGY4zrbAbALTRwxBq9pQpEBPDHogBI y5cdIbP875VLl5qmJAdQdSBy5hzDtgytxSdONBP2jBLOok7rBGerXnTU3ULkiVL4b3D8mVOI6BH xdlBb739c0d7o1BNxoAzHV9ZBnH9KpoVJRhCO X-Received: by 2002:a05:6214:19c5:b0:67f:4c05:4d34 with SMTP id j5-20020a05621419c500b0067f4c054d34mr6990911qvc.5.1704705655234; Mon, 08 Jan 2024 01:20:55 -0800 (PST) X-Google-Smtp-Source: AGHT+IFnK+XpKlzV2pJwpxp9WnHxnhGBrqDUDY4SuSe10hNQMzlz0sxl/7oEnH6B+hqyoG0C8qKDAg== X-Received: by 2002:a05:6214:19c5:b0:67f:4c05:4d34 with SMTP id j5-20020a05621419c500b0067f4c054d34mr6990895qvc.5.1704705654917; Mon, 08 Jan 2024 01:20:54 -0800 (PST) Received: from pstanner-thinkpadt14sgen1.muc.redhat.com (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id dm4-20020ad44e24000000b00680613267d5sm2732554qvb.115.2024.01.08.01.20.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 01:20:54 -0800 (PST) From: Philipp Stanner To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Laurentiu Palcu , Lucas Stach , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Mark Brown , Takashi Iwai , David Gow , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Subject: [PATCH v2 1/2] platform_device: add devres function region-reqs Date: Mon, 8 Jan 2024 10:20:42 +0100 Message-ID: <20240108092042.16949-3-pstanner@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240108092042.16949-2-pstanner@redhat.com> References: <20240108092042.16949-2-pstanner@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Philipp Stanner Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Some drivers want to use (request) a region exclusively but nevertheless create several mappings within that region. Currently, there is no managed devres function to request a region without mapping it. Add the function devm_platform_get_resource(). Signed-off-by: Philipp Stanner --- drivers/base/platform.c | 38 +++++++++++++++++++++++++++++++++ include/linux/platform_device.h | 3 +++ 2 files changed, 41 insertions(+) diff --git a/drivers/base/platform.c b/drivers/base/platform.c index 10c577963418..7b29e6da31ae 100644 --- a/drivers/base/platform.c +++ b/drivers/base/platform.c @@ -82,6 +82,44 @@ struct resource *platform_get_mem_or_io(struct platform_device *dev, } EXPORT_SYMBOL_GPL(platform_get_mem_or_io); +/** + * devm_platform_get_and_request_resource - get and request a resource + * + * @pdev: the platform device to get the resource from + * @type: resource type (either IORESOURCE_MEM or IORESOURCE_IO) + * @num: resource index + * @name: name to be associated with the request + * + * Return: a pointer to the resource on success, an ERR_PTR on failure. + * + * Gets a resource and requests it. Use this instead of + * devm_platform_ioremap_resource() only if you have to create several single + * mappings with devm_ioremap(). + */ +struct resource *devm_platform_get_and_request_resource( + struct platform_device *pdev, unsigned int type, + unsigned int num, const char *name) +{ + struct resource *res; + + res = platform_get_resource(pdev, type, num); + if (!res) + return ERR_PTR(-EINVAL); + + if (type & IORESOURCE_MEM) + res = devm_request_mem_region(&pdev->dev, res->start, res->end, name); + else if (type & IORESOURCE_IO) + res = devm_request_region(&pdev->dev, res->start, res->end, name); + else + return ERR_PTR(-EINVAL); + + if (!res) + return ERR_PTR(-EBUSY); + + return res; +} +EXPORT_SYMBOL_GPL(devm_platform_get_and_request_resource); + #ifdef CONFIG_HAS_IOMEM /** * devm_platform_get_and_ioremap_resource - call devm_ioremap_resource() for a diff --git a/include/linux/platform_device.h b/include/linux/platform_device.h index 7a41c72c1959..44e4ba930d5f 100644 --- a/include/linux/platform_device.h +++ b/include/linux/platform_device.h @@ -59,6 +59,9 @@ extern struct resource *platform_get_resource(struct platform_device *, unsigned int, unsigned int); extern struct resource *platform_get_mem_or_io(struct platform_device *, unsigned int); +extern struct resource *devm_platform_get_and_request_resource( + struct platform_device *pdev, unsigned int type, + unsigned int num, const char *name); extern struct device * platform_find_device_by_driver(struct device *start, From patchwork Mon Jan 8 09:20:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Philipp Stanner X-Patchwork-Id: 13513199 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 97464C3DA6E for ; Mon, 8 Jan 2024 09:21:05 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id F40E310E1A4; Mon, 8 Jan 2024 09:21:04 +0000 (UTC) Received: from us-smtp-delivery-124.mimecast.com (us-smtp-delivery-124.mimecast.com [170.10.133.124]) by gabe.freedesktop.org (Postfix) with ESMTPS id F0DCD89BAC for ; Mon, 8 Jan 2024 09:21:02 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=redhat.com; s=mimecast20190719; t=1704705662; h=from:from:reply-to:subject:subject:date:date:message-id:message-id: to:to:cc:cc:mime-version:mime-version:content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=OT2gYV6QW0aw9hDO4YgXL/qxcf2YqqLjTuz//C31W+E=; b=Re22zcsbpiQz7MvXbmqFR9/CroxGenc7BtP8+zaGo9h0f1cDk9BzCLiG1qLkCLuqMaxLp8 xFaK3F+iJ9lk1WlSgmI6Y3D3uKitlcfogN0O4YsxMzrab7mjoQCv52HgWPEfZ7CfZmUaLD Epeot8GTVejHh8orJ05J/M3Cko7c4fU= Received: from mail-oi1-f199.google.com (mail-oi1-f199.google.com [209.85.167.199]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-590-wpJ_0hrMPhq_jcO1sMFgyw-1; Mon, 08 Jan 2024 04:20:59 -0500 X-MC-Unique: wpJ_0hrMPhq_jcO1sMFgyw-1 Received: by mail-oi1-f199.google.com with SMTP id 5614622812f47-3bbbfe871afso426518b6e.1 for ; Mon, 08 Jan 2024 01:20:58 -0800 (PST) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1704705658; x=1705310458; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=OT2gYV6QW0aw9hDO4YgXL/qxcf2YqqLjTuz//C31W+E=; b=JQ3cjqxOx6YBmD1NMNiSlRhSP8czuquV+SDTz5SOomWC7ajG4Q0nK8azwCeqsNGjXK XTAXaWemiUgdPWo1G9zsChcbmzrCe1OdaNqUUgsITRI6VMfpjltx3/+Bjq03EWUvGupn VAi+2ioWzjI3Zf7TKUkMSdyUQW68u5m19EBe3jd7qYcSTOsE6OLnKi30aPdMD7sfoBIm zb4haxijeZeY63abv39/+/DT9pG3ZVCj+4kalir538LQb+2VcktVQX4eVjJwwcRFLGC1 6TKChPqE8Obj3HNgVMgjFaGdCH1txw48kZoheeUv6/8oUEPjdILbXT/bDWUHTdJXHJ2K /ggg== X-Gm-Message-State: AOJu0YzWRZS0DB5vIkgDB9swk02RjvGnHytlp4dGNcN+RmHufzkTc9fs iKnY4B3E0YNqvPDgOVoTVsk7WWs1JHMZvM216ot4syrsLOcIk+Bb7W65UjFqosivFymSY4Ikmnt doe50GHJr8hDTQSt+h48HnDzozhu5N0CkCmys X-Received: by 2002:a05:6808:b29:b0:3bd:1fe4:731d with SMTP id t9-20020a0568080b2900b003bd1fe4731dmr5145674oij.2.1704705658322; Mon, 08 Jan 2024 01:20:58 -0800 (PST) X-Google-Smtp-Source: AGHT+IEB1C15Fw6VGoZGz9oWNUFxUzMEbudyu27+vWQsCI2s0Rd1Z7xeT1ZpKC2PTY/Nx1IYLi86pQ== X-Received: by 2002:a05:6808:b29:b0:3bd:1fe4:731d with SMTP id t9-20020a0568080b2900b003bd1fe4731dmr5145658oij.2.1704705658009; Mon, 08 Jan 2024 01:20:58 -0800 (PST) Received: from pstanner-thinkpadt14sgen1.muc.redhat.com (nat-pool-muc-t.redhat.com. [149.14.88.26]) by smtp.gmail.com with ESMTPSA id dm4-20020ad44e24000000b00680613267d5sm2732554qvb.115.2024.01.08.01.20.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 01:20:57 -0800 (PST) From: Philipp Stanner To: Greg Kroah-Hartman , "Rafael J. Wysocki" , Laurentiu Palcu , Lucas Stach , Maarten Lankhorst , Maxime Ripard , Thomas Zimmermann , David Airlie , Daniel Vetter , Shawn Guo , Sascha Hauer , Pengutronix Kernel Team , Fabio Estevam , NXP Linux Team , Mark Brown , Takashi Iwai , David Gow , =?utf-8?q?Uwe_Kleine-K=C3=B6nig?= Subject: [PATCH v2 2/2] drm/dcss: request memory region Date: Mon, 8 Jan 2024 10:20:43 +0100 Message-ID: <20240108092042.16949-4-pstanner@redhat.com> X-Mailer: git-send-email 2.43.0 In-Reply-To: <20240108092042.16949-2-pstanner@redhat.com> References: <20240108092042.16949-2-pstanner@redhat.com> MIME-Version: 1.0 X-Mimecast-Spam-Score: 0 X-Mimecast-Originator: redhat.com X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, Philipp Stanner Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" The driver's memory regions are currently just ioremap()ed, but not reserved through a request. That's not a bug, but having the request is a little more robust. Implement the region-request through the corresponding managed devres-function. Signed-off-by: Philipp Stanner --- drivers/gpu/drm/imx/dcss/dcss-dev.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/drivers/gpu/drm/imx/dcss/dcss-dev.c b/drivers/gpu/drm/imx/dcss/dcss-dev.c index 4f3af0dfb344..63dbb8d9c1b0 100644 --- a/drivers/gpu/drm/imx/dcss/dcss-dev.c +++ b/drivers/gpu/drm/imx/dcss/dcss-dev.c @@ -177,10 +177,11 @@ struct dcss_dev *dcss_dev_create(struct device *dev, bool hdmi_output) return ERR_PTR(-ENODEV); } - res = platform_get_resource(pdev, IORESOURCE_MEM, 0); - if (!res) { - dev_err(dev, "cannot get memory resource\n"); - return ERR_PTR(-EINVAL); + res = devm_platform_get_and_request_resource(pdev, IORESOURCE_MEM, + 0, "dcss"); + if (IS_ERR(res)) { + dev_err(dev, "cannot get / request memory resource\n"); + return res; } dcss = kzalloc(sizeof(*dcss), GFP_KERNEL);