Received: by 2002:a89:2c3:0:b0:1ed:23cc:44d1 with SMTP id d3csp659920lqs; Tue, 5 Mar 2024 12:24:59 -0800 (PST) X-Forwarded-Encrypted: i=3; AJvYcCULv2NLu4SMtIuBfouK/VLqxmALSNeBFQXMYH1hv2PqL7xhK7bQDZjAajMdCsx2CxZViy8+h2f1Z40GqOTAGx2x2fHm72f9RQeMt2uoQw== X-Google-Smtp-Source: AGHT+IEth5G7v2k7HFmUBewpguPjJF4UBfmTyinrjW93MNJCidRXWpda1ZDg7i4s44vni5ElKH94 X-Received: by 2002:a17:903:1cf:b0:1db:fd4e:329f with SMTP id e15-20020a17090301cf00b001dbfd4e329fmr3270592plh.15.1709670299058; Tue, 05 Mar 2024 12:24:59 -0800 (PST) ARC-Seal: i=2; a=rsa-sha256; t=1709670299; cv=pass; d=google.com; s=arc-20160816; b=tm0/0qizbNTj9S0475SeWav2SvJdlEiHL/yzmqZXYJqLpbahCDvjz1aMzdw/C+wac/ nVqAFR4C+xI+NzUPcA1yYSsiAaC0JHsg1O/5L3DNZRzAPkvMjXSX4vEVJPjXJfdxFSNS ngobpD/MKk/oPMJ/BXNFt/zsGOzodEjeWahdG6KTVuPVqmiU7MZeOlmpQHRe/5QN7Ab3 a/tLiTuqNCTo3J6h7dzWFvK3EjNDkn0WfU3jh6x94nLmYHpQWgdvMhIHTLXw9bnBud5I dBZM2U5sd763XcdaH+hJab0iJd6O/jLiA+3oanvQBvYYXWrHlw8KLUDhUUS/ToF2K8OH kSBA== ARC-Message-Signature: i=2; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=in-reply-to:content-disposition:mime-version:list-unsubscribe :list-subscribe:list-id:precedence:references:message-id:subject:cc :to:from:date; bh=IhJCck9CorGXQ06XqLcXA4xj2mqS8t/hDHdL0P5+OlM=; fh=j7lw218M085b9rPtj+QACqlnmqhhsdWy5wQ1oNVKNQg=; b=g/hbO5DCpj8sBGi83fa5QVyZq0Jwm4OgU39gTYnOLjdf/LorNiYasiJzUaB8w6oLlz r7sTkclUH6ULZ0SUGWRZg0hvMkb752088Ao35qLQgzuideoVTSvr2nyden8rYgPMfbPf CDnrsrYozfuRMlwRMIEAN9eBTynAeiCjLrIpgcYW6tj8MUD5D92UXsMCm0rF0P1G4kIf aEl6T/7S5nrOjuCXf5/bDrQSnjgcOQ6Lv7AgMaZyjXMy8Mx3OpLrSFFhbMtfRu3viyQN C/f3ixnktT+u3TKX/X20sqS5FNzAVko4kqmLD17BEvTdxRKsvWVWkFOL4kCQ1jmKNl2o FOig==; dara=google.com ARC-Authentication-Results: i=2; mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-92956-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92956-linux.lists.archive=gmail.com@vger.kernel.org" Return-Path: Received: from sv.mirrors.kernel.org (sv.mirrors.kernel.org. [139.178.88.99]) by mx.google.com with ESMTPS id w17-20020a631611000000b005e456ae53cfsi10480222pgl.178.2024.03.05.12.24.58 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 05 Mar 2024 12:24:59 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel+bounces-92956-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) client-ip=139.178.88.99; Authentication-Results: mx.google.com; arc=pass (i=1 spf=pass spfdomain=makrotopia.org); spf=pass (google.com: domain of linux-kernel+bounces-92956-linux.lists.archive=gmail.com@vger.kernel.org designates 139.178.88.99 as permitted sender) smtp.mailfrom="linux-kernel+bounces-92956-linux.lists.archive=gmail.com@vger.kernel.org" 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 sv.mirrors.kernel.org (Postfix) with ESMTPS id B04E4294BF0 for ; Tue, 5 Mar 2024 20:24:58 +0000 (UTC) Received: from localhost.localdomain (localhost.localdomain [127.0.0.1]) by smtp.subspace.kernel.org (Postfix) with ESMTP id C2D7C12D1E5; Tue, 5 Mar 2024 20:24:10 +0000 (UTC) Received: from pidgin.makrotopia.org (pidgin.makrotopia.org [185.142.180.65]) (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 ABD421272CC; Tue, 5 Mar 2024 20:24:08 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=185.142.180.65 ARC-Seal:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709670250; cv=none; b=TS4Yx3jb7wlZeNweop2d/sO4acxbTRXLP+y7t0d2AV0AKES6HxSeNxWst5h2MlCe7x+dLx9KEITwhpeucntOz3kUzvP232bF1iWDLVvnOyiP5RhASNRheY+sVz9AKSEMPqPJYfFQs7XqimHYQZhbPmw6IEF3ROIMw+D7w9ARH5Q= ARC-Message-Signature:i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1709670250; c=relaxed/simple; bh=B7sCKtL9SO97ATHX5/GObMMyjqJrNuWBY8nTqV2huAQ=; h=Date:From:To:Cc:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=azUH4cMxAjeHF2gFcM0IxjBCwR7U2ARb1F2TX34Hc3AlKa14UbQynm5z7t525Nol51DfJUWbsCv8d+dB1E4NdpbQO4MMMkFpju9UL4iiXz7M6Im3HrU2NLYBACD7LTiPZSHo/J2cMt7wegz0ItASjuG37d1UOGLoOibn9jCvDwY= ARC-Authentication-Results:i=1; smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org; spf=pass smtp.mailfrom=makrotopia.org; arc=none smtp.client-ip=185.142.180.65 Authentication-Results: smtp.subspace.kernel.org; dmarc=none (p=none dis=none) header.from=makrotopia.org Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=makrotopia.org Received: from local by pidgin.makrotopia.org with esmtpsa (TLS1.3:TLS_AES_256_GCM_SHA384:256) (Exim 4.96.2) (envelope-from ) id 1rhbK5-0001MZ-0F; Tue, 05 Mar 2024 20:23:37 +0000 Date: Tue, 5 Mar 2024 20:23:32 +0000 From: Daniel Golle To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Ulf Hansson , Jens Axboe , Daniel Golle , Dave Chinner , Jan Kara , Thomas =?iso-8859-1?Q?Wei=DFschuh?= , Christian Brauner , Li Lingfeng , Damien Le Moal , Min Li , Adrian Hunter , Hannes Reinecke , Christian Loehle , Avri Altman , Bean Huo , Yeqi Fu , Victor Shih , Christophe JAILLET , "Ricardo B. Marliere" , Greg Kroah-Hartman , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-block@vger.kernel.org Cc: Diping Zhang , Jianhui Zhao , Jieying Zeng , Chad Monroe , Adam Fox , John Crispin Subject: [RFC PATCH v2 2/8] block: partitions: populate fwnode Message-ID: References: Precedence: bulk X-Mailing-List: linux-kernel@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: Let block partitions to be represented by a firmware node and hence allow them to being referenced e.g. for use with blk-nvmem. Signed-off-by: Daniel Golle --- block/partitions/core.c | 41 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/block/partitions/core.c b/block/partitions/core.c index 5f5ed5c75f04d..48d7f01d76c6a 100644 --- a/block/partitions/core.c +++ b/block/partitions/core.c @@ -10,6 +10,8 @@ #include #include #include +#include + #include "check.h" static int (*const check_part[])(struct parsed_partitions *) = { @@ -281,6 +283,43 @@ static ssize_t whole_disk_show(struct device *dev, } static const DEVICE_ATTR(whole_disk, 0444, whole_disk_show, NULL); +static struct fwnode_handle *find_partition_fwnode(struct block_device *bdev) +{ + struct fwnode_handle *fw_parts, *fw_part; + struct device *ddev = disk_to_dev(bdev->bd_disk); + const char *partname, *uuid; + u32 partno; + + fw_parts = device_get_named_child_node(ddev, "partitions"); + if (!fw_parts) + fw_parts = device_get_named_child_node(ddev->parent, "partitions"); + + if (!fw_parts) + return NULL; + + fwnode_for_each_child_node(fw_parts, fw_part) { + if (!fwnode_property_read_string(fw_part, "uuid", &uuid) && + (!bdev->bd_meta_info || strncmp(uuid, + bdev->bd_meta_info->uuid, + PARTITION_META_INFO_UUIDLTH))) + continue; + + if (!fwnode_property_read_string(fw_part, "partname", &partname) && + (!bdev->bd_meta_info || strncmp(partname, + bdev->bd_meta_info->volname, + PARTITION_META_INFO_VOLNAMELTH))) + continue; + + if (!fwnode_property_read_u32(fw_part, "partno", &partno) && + bdev->bd_partno != partno) + continue; + + return fw_part; + } + + return NULL; +} + /* * Must be called either with open_mutex held, before a disk can be opened or * after all disk users are gone. @@ -355,6 +394,8 @@ static struct block_device *add_partition(struct gendisk *disk, int partno, goto out_put; } + device_set_node(pdev, find_partition_fwnode(bdev)); + /* delay uevent until 'holders' subdir is created */ dev_set_uevent_suppress(pdev, 1); err = device_add(pdev); -- 2.44.0