Received: by 2002:a05:7412:98c1:b0:fa:551:50a7 with SMTP id kc1csp1515277rdb; Mon, 8 Jan 2024 01:22:22 -0800 (PST) X-Google-Smtp-Source: AGHT+IGLTiqI9fKcr1h6MPCUEcXBLFrFUvUlfN32dtNaMXuCjWj3cNUgxNubIJLbSnHJ0gP/kdYt X-Received: by 2002:a50:baa2:0:b0:556:f13c:d6ec with SMTP id x31-20020a50baa2000000b00556f13cd6ecmr2348733ede.76.1704705742818; Mon, 08 Jan 2024 01:22:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1704705742; cv=none; d=google.com; s=arc-20160816; b=Z5FV/IkF3jaq0k9zVh2BRqfMkfw+KzEQuGXcFIiaK10nAVxbERXuDAw0TmrFkLqO2B lohwwbbIGGyD2CrAY5u4wZZ/dz5clUfkZw7aM3Oc+hRPkvtFEWW9KVhiFk9zOQPXlP7M bi0WjEWJ4LMfDJ5cGxqlp28uINXBCq6lZYaEzF3yswn3C0wdMLLdhzAaX3kkXkhO3HO9 RQr9dgYpjDsKy2jV8w0roqAvEsMj+cgWPv/MNqAuEVAqnzNA/g1LPeMA4PBK7a5aefQI 9rq/mmFpw5Mgi7UIB4tvUUpD/sRsIAd0GWY+h14BUNMJaICaFoNa9Luo+eXfD+95NysR KbFQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=content-transfer-encoding:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:in-reply-to:message-id :date:subject:cc:to:from:dkim-signature; bh=arbdXlZxmXJOFEKJF2R1zNrEF3q6fd9QYRmRT41BVKs=; fh=L/75A92C4r6s7p0wl3tLaypnglq6P35gl2qn6oQwgpg=; b=nZJXZLtH47cQUnT9e5/pNe88D3n+PCeuoGlEeunnGgTDTo9AOvaGLOxS9diylD5n1o pEbIFCGVnbBqyRoSkycPVMK/c1n1KyOuAF41I/tAb2cwXy0FUm3NN9hhQ6FldYdWyBve TaWRyvDVjH5Ylmi4urylgAfSGvjeagKWmNXjtRq0oE+2wRTKuw3SN25iet33W4rTwOEN iFYhugqTynTiZ/u2p/3wyBHHyR1yP65i9QcTbEmjTkASON8dE2cu1h+MvHY/ZhU0lTHN iy+v4ds7cP7syHEbwDaRGtzVhABHoUGybO67tPm/BYi4q+0kgRF/rMdQRnyZ5VS8o923 Oh1g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TQJb9I9j; spf=pass (google.com: domain of linux-kernel+bounces-19271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19271-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from am.mirrors.kernel.org (am.mirrors.kernel.org. [2604:1380:4601:e00::3]) by mx.google.com with ESMTPS id q17-20020a50c351000000b00553bfa1dee0si2893300edb.64.2024.01.08.01.22.22 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 08 Jan 2024 01:22:22 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-19271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) client-ip=2604:1380:4601:e00::3; Authentication-Results: mx.google.com; dkim=pass header.i=@redhat.com header.s=mimecast20190719 header.b=TQJb9I9j; spf=pass (google.com: domain of linux-kernel+bounces-19271-linux.lists.archive=gmail.com@vger.kernel.org designates 2604:1380:4601:e00::3 as permitted sender) smtp.mailfrom="linux-kernel+bounces-19271-linux.lists.archive=gmail.com@vger.kernel.org"; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: from smtp.subspace.kernel.org (wormhole.subspace.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by am.mirrors.kernel.org (Postfix) with ESMTPS id 8A9D01F21181 for ; Mon, 8 Jan 2024 09:22:22 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id 7300F14016; Mon, 8 Jan 2024 09:21:05 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; dkim=pass (1024-bit key) header.d=redhat.com header.i=@redhat.com header.b="TQJb9I9j" X-Original-To: linux-kernel@vger.kernel.org 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 433EC13FED for ; Mon, 8 Jan 2024 09:21:02 +0000 (UTC) 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 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-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=arbdXlZxmXJOFEKJF2R1zNrEF3q6fd9QYRmRT41BVKs=; b=TQJb9I9j6/7hbwQeb/wFmek7SeqDCADNKmhpbpxgdYsECjU4rh6MA2/n6a5WqASn9IdgAp BZGj5gErIt2AVELcLkDafrKu/lRvKZjuxAJAzyegXZkDfHuUW/23lsXCOhVI5QdzOD5psX Uv2umGx9a0cLB+yEsQAxOZkN19WIgWg= Received: from mail-qt1-f198.google.com (mail-qt1-f198.google.com [209.85.160.198]) by relay.mimecast.com with ESMTP with STARTTLS (version=TLSv1.3, cipher=TLS_AES_256_GCM_SHA384) id us-mta-350-6LY5NC2iP8mqumGGCBsoxA-1; Mon, 08 Jan 2024 04:20:55 -0500 X-MC-Unique: 6LY5NC2iP8mqumGGCBsoxA-1 Received: by mail-qt1-f198.google.com with SMTP id d75a77b69052e-42989eb8897so2846731cf.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=JpYF09Qia3T10pHXTfMzCk8NMDJqexfwJzyO6PXBNyRwEXMwhcIBdb94i8GxQcYt1s 2zTw6Na3cYVgl3hb2vFw997gCKLrrH/iEzjVMK8Adzg0I6NjLS4oANXbc4DR9VS67GMr NSgymJuoJ+gMH679G5ajAAMA8yFGAE3TVB11cFXz4yFDAwy/epeyE7rvSQEMCavIxt+V zFhlTaOIJ+WTPOxlQVRDkRYhJaH1yr8ibmATzai1+z9TlpIAi5jB6ebSPJQgrRqelGlc +BQ1Lx5Q74KXyaiBiZ1+7QpwiTv/JWuMuuNL+YG1ui8YMP1UGVg4fgw2FAkIV36PiEXE kGCA== X-Gm-Message-State: AOJu0Yy6sQXrZ759Ly8bU9at68fYru8NuJdHEI9TrXTNqsc+JaME8L5M 9YeL0ukuN+BGm2PwW9lqdMXEX+4uiHP6mgydoybnpohUsU8ug7WBEKXaQuxls+hvtp7AT68tCy9 xZfS1C1Kc7Qxob+GDghASX4Pzco6NVWqV X-Received: by 2002:a05:6214:19c5:b0:67f:4c05:4d34 with SMTP id j5-20020a05621419c500b0067f4c054d34mr6990908qvc.5.1704705655233; Mon, 08 Jan 2024 01:20:55 -0800 (PST) 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=20Kleine-K=C3=B6nig?= Cc: linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org, linux-arm-kernel@lists.infradead.org, Philipp Stanner 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> Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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, -- 2.43.0