From patchwork Thu May 30 02:13:09 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 13679699 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 9AE9917984; Thu, 30 May 2024 02:13:45 +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=1717035230; cv=none; b=jwc+8T4IcSBb7yOlpD6N565bO3S9Mwcdtka4SEXAkCIYAebXOq6QkDpPnLpQ4pwZVZpNC/SPFD6syTsLVv+2KOg+dbTi3ufMyxwpK19DGUjWF1zB2pfiJnWWhTH1gIK19jZFqEbudicjxkxTcC0cGwNn8p5MFZ0vH+lRIEGIb/s= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717035230; c=relaxed/simple; bh=jwJEg7siBPxa7QbQVCX/r1nA9rstIO45gfu1eOfH+Qg=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=CQqAVmEewDT2tBlKKa0B8B2eA4fb9BoPy/b7zXCu/PCyqCI+I6WERp6v10L+Py7mHPUswokwBTBCLDO8EHthd2Ft5VDdTowmjNy312Ukg3gWYsmPqjoMiOpSVYGKS93RSCW9gFdNE3qW5FWqfPpiyFFmszTyFHMa4//Ego+m/LQ= 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.97.1) (envelope-from ) id 1sCVI1-000000004d1-02Df; Thu, 30 May 2024 02:13:13 +0000 Date: Thu, 30 May 2024 03:13:09 +0100 From: Daniel Golle To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Ulf Hansson , Jens Axboe , Srinivas Kandagatla , Daniel Golle , Dave Chinner , Jan Kara , Christian Brauner , Thomas =?iso-8859-1?q?Wei=DFschuh?= , Al Viro , Li Lingfeng , Christian Heusel , Min Li , Avri Altman , Adrian Hunter , Hannes Reinecke , Mikko Rapeli , Yeqi Fu , Victor Shih , Christophe JAILLET , Li Zhijian , "Ricardo B. Marliere" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH v2 1/9] dt-bindings: block: add basic bindings for block devices Message-ID: References: Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Add bindings for block devices which are used to allow referencing nvmem bits on them. Signed-off-by: Daniel Golle --- .../bindings/block/block-device.yaml | 22 ++++++++ .../devicetree/bindings/block/partition.yaml | 51 +++++++++++++++++++ .../devicetree/bindings/block/partitions.yaml | 20 ++++++++ 3 files changed, 93 insertions(+) create mode 100644 Documentation/devicetree/bindings/block/block-device.yaml create mode 100644 Documentation/devicetree/bindings/block/partition.yaml create mode 100644 Documentation/devicetree/bindings/block/partitions.yaml diff --git a/Documentation/devicetree/bindings/block/block-device.yaml b/Documentation/devicetree/bindings/block/block-device.yaml new file mode 100644 index 000000000000..c83ea525650b --- /dev/null +++ b/Documentation/devicetree/bindings/block/block-device.yaml @@ -0,0 +1,22 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/block/block-device.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: block storage device + +description: | + This binding is generic and describes a block-oriented storage device. + +maintainers: + - Daniel Golle + +properties: + partitions: + $ref: /schemas/block/partitions.yaml + + nvmem-layout: + $ref: /schemas/nvmem/layouts/nvmem-layout.yaml# + +unevaluatedProperties: false diff --git a/Documentation/devicetree/bindings/block/partition.yaml b/Documentation/devicetree/bindings/block/partition.yaml new file mode 100644 index 000000000000..86b61e30f9a4 --- /dev/null +++ b/Documentation/devicetree/bindings/block/partition.yaml @@ -0,0 +1,51 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/block/partition.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Partition on a block device + +description: | + This binding describes a partition on a block device. + Partitions may be matched by a combination of partition number, name, + and UUID. + +maintainers: + - Daniel Golle + +properties: + $nodename: + pattern: '^block-partition-.+$' + + partnum: + $ref: /schemas/types.yaml#/definitions/uint32 + description: + Matches partition by number if present. + + partname: + $ref: /schemas/types.yaml#/definitions/string + description: + Matches partition by PARTNAME if present. + + partuuid: + $ref: /schemas/types.yaml#/definitions/string + description: + Matches partition by PARTUUID if present. + + nvmem-layout: + $ref: /schemas/nvmem/layouts/nvmem-layout.yaml# + description: + This container may reference an NVMEM layout parser. + +anyOf: + - required: + - partnum + + - required: + - partname + + - required: + - partuuid + +unevaluatedProperties: false diff --git a/Documentation/devicetree/bindings/block/partitions.yaml b/Documentation/devicetree/bindings/block/partitions.yaml new file mode 100644 index 000000000000..fd84c3ba8493 --- /dev/null +++ b/Documentation/devicetree/bindings/block/partitions.yaml @@ -0,0 +1,20 @@ +# SPDX-License-Identifier: GPL-2.0-only OR BSD-2-Clause +%YAML 1.2 +--- +$id: http://devicetree.org/schemas/block/partitions.yaml# +$schema: http://devicetree.org/meta-schemas/core.yaml# + +title: Partitions on block devices + +description: | + This binding is generic and describes the content of the partitions container + node. + +maintainers: + - Daniel Golle + +patternProperties: + "^block-partition-.+$": + $ref: partition.yaml + +unevaluatedProperties: false From patchwork Thu May 30 02:13:19 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 13679698 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 9AEFC18054; Thu, 30 May 2024 02:13:45 +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=1717035227; cv=none; b=I9fIjuG0XhmOOYsbdjEK//pylYeqH0sOicppP4xOJZWX5wVsWOjmyHQc4Dd+mYLUhzX38Jay+AZ1m4+gHViOk6V1oI9hIoAqyunSOd+PY+0QjGxaFsW9zOr8w8SeOIAYc8DduMGpEJQPXMvRB5hrKJ5DcHN0eJSxTV0pkqnZ5Y4= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717035227; c=relaxed/simple; bh=8KiukBQuZe8dk/35HCsKrEZ3OpWGl77bj/JKjKV4ggo=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=mkRP2/7rD7pV5FSVh4vtCe5WmiDIsnT01psM6X+ad0wEZmxkBVvDxvvbirAA9TGITpMKymD35k2NB86BTiAdpzDDK4FOcXKV1eDtsQhIfv6MPLABzsfXRRY9YuM9NU7BIJkkf1s1fTQ76lAeJVBq90wWPg2VVqxgJ+u33PzIrTc= 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.97.1) (envelope-from ) id 1sCVIB-000000004dG-0THb; Thu, 30 May 2024 02:13:23 +0000 Date: Thu, 30 May 2024 03:13:19 +0100 From: Daniel Golle To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Ulf Hansson , Jens Axboe , Srinivas Kandagatla , Daniel Golle , Dave Chinner , Jan Kara , Christian Brauner , Thomas =?iso-8859-1?q?Wei=DFschuh?= , Al Viro , Li Lingfeng , Christian Heusel , Min Li , Avri Altman , Adrian Hunter , Hannes Reinecke , Mikko Rapeli , Yeqi Fu , Victor Shih , Christophe JAILLET , Li Zhijian , "Ricardo B. Marliere" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH v2 2/9] block: partitions: populate fwnode Message-ID: <3329bf2fa25695934b392944ff977ae95dc8c02d.1717031992.git.daniel@makrotopia.org> References: Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 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 ab76e64f0f6c..93d109409905 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_partno(bdev) != 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); From patchwork Thu May 30 02:14:34 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 13679700 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 4239D1BC44; Thu, 30 May 2024 02:14:50 +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=1717035292; cv=none; b=JyLqc8h8KgFIBT8uYA06EabnTTBZdEi+M0TWy1l6LrAnP5QlpQRshgn1LAnQH2jLI+3R+On95W3ZKL+JqpieZlRX4VKihlMystQd9Tj6qmMe+QANQpVGBhk8pGOlOPyINglyrHy7+fhW+YGJ7wjwkZ847B2s31IaL7i2GyyDEYM= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717035292; c=relaxed/simple; bh=eZcSx2sOVs3qbSCl2YnVDXzrJD2rtCpa0KGRs94iBwg=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=UgRjLfVFzHWX4qBpse70wFbUT1SzG3LMsA6Zl34VeaumithfQLzEne7QSC1kRzDsBn7cJPPamptqLSk3Kdge81INYJZX/nwxfnXnLg8snc4D0QMi1xybfWT5ygKn5i4IbEXP9ZZro1qtQtLt6E4AyLmgoT06HhuWTUg8eerG3jE= 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.97.1) (envelope-from ) id 1sCVJO-000000004fi-3Y7Q; Thu, 30 May 2024 02:14:38 +0000 Date: Thu, 30 May 2024 03:14:34 +0100 From: Daniel Golle To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Ulf Hansson , Jens Axboe , Srinivas Kandagatla , Daniel Golle , Dave Chinner , Jan Kara , Christian Brauner , Thomas =?iso-8859-1?q?Wei=DFschuh?= , Al Viro , Li Lingfeng , Christian Heusel , Min Li , Avri Altman , Adrian Hunter , Hannes Reinecke , Mikko Rapeli , Yeqi Fu , Victor Shih , Christophe JAILLET , Li Zhijian , "Ricardo B. Marliere" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH v2 3/9] block: add support for notifications Message-ID: <99a9b6347f0b442be40290a26c8cce2621878d6d.1717031992.git.daniel@makrotopia.org> References: Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Add notifier block to notify other subsystems about the addition or removal of block devices. Signed-off-by: Daniel Golle --- block/Kconfig | 6 +++ block/Makefile | 1 + block/blk-notify.c | 88 ++++++++++++++++++++++++++++++++++++++++++ include/linux/blkdev.h | 8 ++++ 4 files changed, 103 insertions(+) create mode 100644 block/blk-notify.c diff --git a/block/Kconfig b/block/Kconfig index dc12af58dbae..b9a28ecd408f 100644 --- a/block/Kconfig +++ b/block/Kconfig @@ -213,6 +213,12 @@ config BLK_INLINE_ENCRYPTION_FALLBACK by falling back to the kernel crypto API when inline encryption hardware is not present. +config BLOCK_NOTIFIERS + bool "Enable support for notifications in block layer" + help + Enable this option to provide notifiers for other subsystems + upon addition or removal of block devices. + source "block/partitions/Kconfig" config BLK_MQ_PCI diff --git a/block/Makefile b/block/Makefile index 168150b9c510..54ff8aded85e 100644 --- a/block/Makefile +++ b/block/Makefile @@ -39,3 +39,4 @@ obj-$(CONFIG_BLK_INLINE_ENCRYPTION) += blk-crypto.o blk-crypto-profile.o \ blk-crypto-sysfs.o obj-$(CONFIG_BLK_INLINE_ENCRYPTION_FALLBACK) += blk-crypto-fallback.o obj-$(CONFIG_BLOCK_HOLDER_DEPRECATED) += holder.o +obj-$(CONFIG_BLOCK_NOTIFIERS) += blk-notify.o diff --git a/block/blk-notify.c b/block/blk-notify.c new file mode 100644 index 000000000000..ae161baf1634 --- /dev/null +++ b/block/blk-notify.c @@ -0,0 +1,88 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Notifiers for addition and removal of block devices + * + * Copyright (c) 2024 Daniel Golle + */ + +#include +#include +#include + +#include "blk.h" + +struct blk_device_list { + struct device *dev; + struct list_head list; +}; + +static RAW_NOTIFIER_HEAD(blk_notifier_list); +static DEFINE_MUTEX(blk_notifier_lock); +static LIST_HEAD(blk_devices); + +void blk_register_notify(struct notifier_block *nb) +{ + struct blk_device_list *existing_blkdev; + + mutex_lock(&blk_notifier_lock); + raw_notifier_chain_register(&blk_notifier_list, nb); + + list_for_each_entry(existing_blkdev, &blk_devices, list) + nb->notifier_call(nb, BLK_DEVICE_ADD, existing_blkdev->dev); + + mutex_unlock(&blk_notifier_lock); +} +EXPORT_SYMBOL_GPL(blk_register_notify); + +void blk_unregister_notify(struct notifier_block *nb) +{ + mutex_lock(&blk_notifier_lock); + raw_notifier_chain_unregister(&blk_notifier_list, nb); + mutex_unlock(&blk_notifier_lock); +} +EXPORT_SYMBOL_GPL(blk_unregister_notify); + +static int blk_call_notifier_add(struct device *dev) +{ + struct blk_device_list *new_blkdev; + + new_blkdev = kmalloc(sizeof(*new_blkdev), GFP_KERNEL); + if (!new_blkdev) + return -ENOMEM; + + new_blkdev->dev = dev; + mutex_lock(&blk_notifier_lock); + list_add_tail(&new_blkdev->list, &blk_devices); + raw_notifier_call_chain(&blk_notifier_list, BLK_DEVICE_ADD, dev); + mutex_unlock(&blk_notifier_lock); + + return 0; +} + +static void blk_call_notifier_remove(struct device *dev) +{ + struct blk_device_list *old_blkdev, *tmp; + + mutex_lock(&blk_notifier_lock); + list_for_each_entry_safe(old_blkdev, tmp, &blk_devices, list) { + if (old_blkdev->dev != dev) + continue; + + list_del(&old_blkdev->list); + kfree(old_blkdev); + } + raw_notifier_call_chain(&blk_notifier_list, BLK_DEVICE_REMOVE, dev); + mutex_unlock(&blk_notifier_lock); +} + +static struct class_interface blk_notifications_bus_interface __refdata = { + .class = &block_class, + .add_dev = &blk_call_notifier_add, + .remove_dev = &blk_call_notifier_remove, +}; + +static int __init blk_notifications_init(void) +{ + return class_interface_register(&blk_notifications_bus_interface); +} +device_initcall(blk_notifications_init); diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index aefdda9f4ec7..0a8c3478a462 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1604,4 +1604,12 @@ struct io_comp_batch { #define DEFINE_IO_COMP_BATCH(name) struct io_comp_batch name = { } + +#ifdef CONFIG_BLOCK_NOTIFIERS +#define BLK_DEVICE_ADD 1 +#define BLK_DEVICE_REMOVE 2 +void blk_register_notify(struct notifier_block *nb); +void blk_unregister_notify(struct notifier_block *nb); +#endif + #endif /* _LINUX_BLKDEV_H */ From patchwork Thu May 30 02:14:49 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 13679701 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 AF298208A9; Thu, 30 May 2024 02:15:02 +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=1717035304; cv=none; b=MeSXI0NV0E5q37jCEe/SoY+qWJzXnn47eOcXNxW3Ef6yFHvM33uk0VYTSAAchnlpRdpF090uNSWg/B2gUsANFY9+m8Xf8jGFbVxXCeGYlzYTeMzqNVRLYZBAwRpaLj5MhF45JmaLPIr4Deps+tddPIozGiZUZzQCiwAEms8TEkQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717035304; c=relaxed/simple; bh=3/qKbynN3yd31VH9tB9RkMiH7LQj1z+unggA4X0foD0=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QdU6DsmWlVHt6mJd4uCBilVY4dvkqo8L0oCik/mmYK/XNUQ4pZTnl/EmF7bCuGWrS9x6pWiMGRdG20aMLH718hy06seGvmminJNUfjxjlGgIPX5ES1fUush/+Ld0INk6xqacTmE+wu6UGiUKtLy8uo0YjXcD6DOCVqJmOSmk0Hs= 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.97.1) (envelope-from ) id 1sCVJd-000000004gC-060q; Thu, 30 May 2024 02:14:53 +0000 Date: Thu, 30 May 2024 03:14:49 +0100 From: Daniel Golle To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Ulf Hansson , Jens Axboe , Srinivas Kandagatla , Daniel Golle , Dave Chinner , Jan Kara , Christian Brauner , Thomas =?iso-8859-1?q?Wei=DFschuh?= , Al Viro , Li Lingfeng , Christian Heusel , Min Li , Avri Altman , Adrian Hunter , Hannes Reinecke , Mikko Rapeli , Yeqi Fu , Victor Shih , Christophe JAILLET , Li Zhijian , "Ricardo B. Marliere" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH v2 4/9] block: add new genhd flag GENHD_FL_NVMEM Message-ID: <991e1dc3d7a08355a0e746129ecad18df5aa2405.1717031992.git.daniel@makrotopia.org> References: Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Add new flag to destinguish block devices which may act as an NVMEM provider. Signed-off-by: Daniel Golle --- include/linux/blkdev.h | 2 ++ 1 file changed, 2 insertions(+) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 0a8c3478a462..c3365856e67b 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -81,11 +81,13 @@ struct partition_meta_info { * ``GENHD_FL_NO_PART``: partition support is disabled. The kernel will not * scan for partitions from add_disk, and users can't add partitions manually. * + * ``GENHD_FL_NVMEM``: the block device should be considered as NVMEM provider. */ enum { GENHD_FL_REMOVABLE = 1 << 0, GENHD_FL_HIDDEN = 1 << 1, GENHD_FL_NO_PART = 1 << 2, + GENHD_FL_NVMEM = 1 << 3, }; enum { From patchwork Thu May 30 02:15:02 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 13679702 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 5A1181C6BE; Thu, 30 May 2024 02:15:16 +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=1717035318; cv=none; b=rqdn8nuSth9t5l+ICrF2r7FS+rKkm++hu+TRYSpvDXu2m1Atwir5MtbmkFkxB+CTqt7ZGCQj9vJHVmeTD7qt1pnY+pNN0qrA/ov6bipRRQdp5nLwpaaK3UcRiO3lkPt2W81CRsYIGtrOmAgir7vxsY7Fsz+BK79zaSvDFeBVjBw= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717035318; c=relaxed/simple; bh=H02eYHE1BedVpEUBdE0xG8/wNXYB9wQeEmhHAiAsL2U=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=FHJGDTxllmB82XoqE590Fjsd5h2YohyUcr+4M02NrUkMt2vqrO6+ar0RpyXtmznbdbiX5t5lodFxUfcs0oymk+NtrAvjcj9/h2URUi1LMotZMNZoaf40NJPiC0cf6Hd3Wauy2MoqOY0NNMpp85qGPqJIgYtcXdi7+eaRhmJU4fc= 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.97.1) (envelope-from ) id 1sCVJq-000000004gi-0v8J; Thu, 30 May 2024 02:15:06 +0000 Date: Thu, 30 May 2024 03:15:02 +0100 From: Daniel Golle To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Ulf Hansson , Jens Axboe , Srinivas Kandagatla , Daniel Golle , Dave Chinner , Jan Kara , Christian Brauner , Thomas =?iso-8859-1?q?Wei=DFschuh?= , Al Viro , Li Lingfeng , Christian Heusel , Min Li , Avri Altman , Adrian Hunter , Hannes Reinecke , Mikko Rapeli , Yeqi Fu , Victor Shih , Christophe JAILLET , Li Zhijian , "Ricardo B. Marliere" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH v2 5/9] nvmem: implement block NVMEM provider Message-ID: <96554d6b4d9fa72f936c2c476eb0b023cdd60a64.1717031992.git.daniel@makrotopia.org> References: Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: On embedded devices using an eMMC it is common that one or more partitions on the eMMC are used to store MAC addresses and Wi-Fi calibration EEPROM data. Allow referencing any block device or partition in Device Tree to allow e.g. Ethernet and Wi-Fi drivers accessing them via the NVMEM layer. Signed-off-by: Daniel Golle --- drivers/nvmem/Kconfig | 11 +++ drivers/nvmem/Makefile | 2 + drivers/nvmem/block.c | 198 +++++++++++++++++++++++++++++++++++++++++ 3 files changed, 211 insertions(+) create mode 100644 drivers/nvmem/block.c diff --git a/drivers/nvmem/Kconfig b/drivers/nvmem/Kconfig index 283134498fbc..1d6df20301a4 100644 --- a/drivers/nvmem/Kconfig +++ b/drivers/nvmem/Kconfig @@ -40,6 +40,17 @@ config NVMEM_APPLE_EFUSES This driver can also be built as a module. If so, the module will be called nvmem-apple-efuses. +config NVMEM_BLOCK + tristate "Block device NVMEM provider" + depends on BLOCK + depends on OF + depends on NVMEM + select BLOCK_NOTIFIERS + help + Allow block devices (or partitions) to act as NVMEM prodivers, + typically used with eMMC to store MAC addresses or Wi-Fi + calibration data on embedded devices. + config NVMEM_BCM_OCOTP tristate "Broadcom On-Chip OTP Controller support" depends on ARCH_BCM_IPROC || COMPILE_TEST diff --git a/drivers/nvmem/Makefile b/drivers/nvmem/Makefile index cdd01fbf1313..68fcf845f417 100644 --- a/drivers/nvmem/Makefile +++ b/drivers/nvmem/Makefile @@ -14,6 +14,8 @@ obj-$(CONFIG_NVMEM_APPLE_EFUSES) += nvmem-apple-efuses.o nvmem-apple-efuses-y := apple-efuses.o obj-$(CONFIG_NVMEM_BCM_OCOTP) += nvmem-bcm-ocotp.o nvmem-bcm-ocotp-y := bcm-ocotp.o +obj-$(CONFIG_NVMEM_BLOCK) += nvmem-block.o +nvmem-block-y := block.o obj-$(CONFIG_NVMEM_BRCM_NVRAM) += nvmem_brcm_nvram.o nvmem_brcm_nvram-y := brcm_nvram.o obj-$(CONFIG_NVMEM_IMX_IIM) += nvmem-imx-iim.o diff --git a/drivers/nvmem/block.c b/drivers/nvmem/block.c new file mode 100644 index 000000000000..dc9e43f98616 --- /dev/null +++ b/drivers/nvmem/block.c @@ -0,0 +1,197 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * block device NVMEM provider + * + * Copyright (c) 2024 Daniel Golle + * + * Useful on devices using a partition on an eMMC for MAC addresses or + * Wi-Fi calibration EEPROM data. + */ + +#include +#include +#include +#include +#include + +/* List of all NVMEM devices */ +static LIST_HEAD(nvmem_devices); +static DEFINE_MUTEX(devices_mutex); + +struct blk_nvmem { + struct nvmem_device *nvmem; + struct device *dev; + struct list_head list; +}; + +static int blk_nvmem_reg_read(void *priv, unsigned int from, + void *val, size_t bytes) +{ + blk_mode_t mode = BLK_OPEN_READ | BLK_OPEN_RESTRICT_WRITES; + unsigned long offs = from & ~PAGE_MASK, to_read; + pgoff_t f_index = from >> PAGE_SHIFT; + struct blk_nvmem *bnv = priv; + size_t bytes_left = bytes; + struct file *bdev_file; + struct folio *folio; + void *p; + int ret = 0; + + bdev_file = bdev_file_open_by_dev(bnv->dev->devt, mode, priv, NULL); + if (!bdev_file) + return -ENODEV; + + if (IS_ERR(bdev_file)) + return PTR_ERR(bdev_file); + + while (bytes_left) { + folio = read_mapping_folio(bdev_file->f_mapping, f_index++, NULL); + if (IS_ERR(folio)) { + ret = PTR_ERR(folio); + goto err_release_bdev; + } + to_read = min_t(unsigned long, bytes_left, PAGE_SIZE - offs); + p = folio_address(folio) + offset_in_folio(folio, offs); + memcpy(val, p, to_read); + offs = 0; + bytes_left -= to_read; + val += to_read; + folio_put(folio); + } + +err_release_bdev: + fput(bdev_file); + + return ret; +} + +static int blk_nvmem_register(struct device *dev) +{ + struct block_device *bdev = dev_to_bdev(dev); + struct device_node *np = dev_of_node(dev); + struct nvmem_config config = {}; + struct blk_nvmem *bnv; + + /* skip devices which do not have a device tree node */ + if (!np) + return 0; + + /* skip devices without an nvmem layout defined */ + if (!of_get_child_by_name(np, "nvmem-layout")) + return 0; + + /* + * skip devices which don't have GENHD_FL_NVMEM set + * + * This flag is used for mtdblock and ubiblock devices because + * both, MTD and UBI already implement their own NVMEM provider. + * To avoid registering multiple NVMEM providers for the same + * device node, don't register the block NVMEM provider for them. + */ + if (!(bdev->bd_disk->flags & GENHD_FL_NVMEM)) + return 0; + + /* + * skip block device too large to be represented as NVMEM devices + * which are using an 'int' as address + */ + if (bdev_nr_bytes(bdev) > INT_MAX) + return -EFBIG; + + bnv = kzalloc(sizeof(struct blk_nvmem), GFP_KERNEL); + if (!bnv) + return -ENOMEM; + + config.id = NVMEM_DEVID_NONE; + config.dev = &bdev->bd_device; + config.name = dev_name(&bdev->bd_device); + config.owner = THIS_MODULE; + config.priv = bnv; + config.reg_read = blk_nvmem_reg_read; + config.size = bdev_nr_bytes(bdev); + config.word_size = 1; + config.stride = 1; + config.read_only = true; + config.root_only = true; + config.ignore_wp = true; + config.of_node = to_of_node(dev->fwnode); + + bnv->dev = &bdev->bd_device; + bnv->nvmem = nvmem_register(&config); + if (IS_ERR(bnv->nvmem)) { + dev_err_probe(&bdev->bd_device, PTR_ERR(bnv->nvmem), + "Failed to register NVMEM device\n"); + + kfree(bnv); + return PTR_ERR(bnv->nvmem); + } + + mutex_lock(&devices_mutex); + list_add_tail(&bnv->list, &nvmem_devices); + mutex_unlock(&devices_mutex); + + return 0; +} + +static void blk_nvmem_unregister(struct device *dev) +{ + struct blk_nvmem *bnv_c, *bnv = NULL; + + mutex_lock(&devices_mutex); + list_for_each_entry(bnv_c, &nvmem_devices, list) { + if (bnv_c->dev == dev) { + bnv = bnv_c; + break; + } + } + + if (!bnv) { + mutex_unlock(&devices_mutex); + return; + } + + list_del(&bnv->list); + mutex_unlock(&devices_mutex); + nvmem_unregister(bnv->nvmem); + kfree(bnv); +} + +static int blk_nvmem_handler(struct notifier_block *this, unsigned long code, void *obj) +{ + struct device *dev = (struct device *)obj; + + switch (code) { + case BLK_DEVICE_ADD: + return blk_nvmem_register(dev); + case BLK_DEVICE_REMOVE: + blk_nvmem_unregister(dev); + break; + default: + return -EINVAL; + } + + return 0; +} + +static struct notifier_block blk_nvmem_notifier = { + .notifier_call = blk_nvmem_handler, +}; + +static int __init blk_nvmem_init(void) +{ + blk_register_notify(&blk_nvmem_notifier); + + return 0; +} + +static void __exit blk_nvmem_exit(void) +{ + blk_unregister_notify(&blk_nvmem_notifier); +} + +module_init(blk_nvmem_init); +module_exit(blk_nvmem_exit); + +MODULE_LICENSE("GPL"); +MODULE_AUTHOR("Daniel Golle "); +MODULE_DESCRIPTION("block device NVMEM provider"); From patchwork Thu May 30 02:15:11 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 13679703 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 B81F328DD0; Thu, 30 May 2024 02:15:25 +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=1717035327; cv=none; b=CXb4IGnfRyG3aR6mwhXcB8IFEQHapG3j2F5gUA7l7wvEboUS2IwcwYL8+E9dOFMaAtTFvK2bO7QIKmyA6q8gaOtMMb52wOvTlGuKlVrlc946c1X58VyYDQGgOLQr0+zHvJux9QVGu91X6lUVuot2A464ykIuJzets2Bcoaxm4JA= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717035327; c=relaxed/simple; bh=ZND/IraLGpqQA+zSSLk7Bz2Qe5V3dwxk3TRcMUKSLPk=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=QpZEqwVtNavCpDQ2TaYkDaT48W8/Oh29JSLuxkBaOGMmBAYW8rosjGJ0dfXCycT7PT6hNildFTmho4YcW4AK+lzhhhG3GSFtdV4vDaySWi4Qb1noP9i5qQPKnm6LCol/fz4LlR/28GYUPqpZLxQYddxAiUKubHxo6nEPJH+6ayA= 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.97.1) (envelope-from ) id 1sCVJz-000000004hP-0r0o; Thu, 30 May 2024 02:15:15 +0000 Date: Thu, 30 May 2024 03:15:11 +0100 From: Daniel Golle To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Ulf Hansson , Jens Axboe , Srinivas Kandagatla , Daniel Golle , Dave Chinner , Jan Kara , Christian Brauner , Thomas =?iso-8859-1?q?Wei=DFschuh?= , Al Viro , Li Lingfeng , Christian Heusel , Min Li , Avri Altman , Adrian Hunter , Hannes Reinecke , Mikko Rapeli , Yeqi Fu , Victor Shih , Christophe JAILLET , Li Zhijian , "Ricardo B. Marliere" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH v2 6/9] dt-bindings: mmc: mmc-card: add block device nodes Message-ID: References: Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Add nodes representing the block devices exposed by an MMC device including an example involving nvmem-cells. Signed-off-by: Daniel Golle --- .../devicetree/bindings/mmc/mmc-card.yaml | 45 +++++++++++++++++++ 1 file changed, 45 insertions(+) diff --git a/Documentation/devicetree/bindings/mmc/mmc-card.yaml b/Documentation/devicetree/bindings/mmc/mmc-card.yaml index fd347126449a..95ccbda871d2 100644 --- a/Documentation/devicetree/bindings/mmc/mmc-card.yaml +++ b/Documentation/devicetree/bindings/mmc/mmc-card.yaml @@ -26,6 +26,18 @@ properties: Use this to indicate that the mmc-card has a broken hpi implementation, and that hpi should not be used. + block: + $ref: /schemas/block/block-device.yaml# + description: + Represents the block storage provided by an SD card or the + main hardware partition of an eMMC. + +patternProperties: + '^boot[0-9]+': + $ref: /schemas/block/block-device.yaml# + description: + Represents a boot hardware partition on an eMMC. + required: - compatible - reg @@ -42,6 +54,39 @@ examples: compatible = "mmc-card"; reg = <0>; broken-hpi; + + block { + partitions { + cal_data: block-partition-rf { + partnum = <3>; + partname = "rf"; + + nvmem-layout { + compatible = "fixed-layout"; + #address-cells = <1>; + #size-cells = <1>; + + eeprom@0 { + reg = <0x0 0x1000>; + }; + }; + }; + }; + }; + + boot1 { + nvmem-layout { + compatible = "fixed-layout"; + #address-cells = <1>; + #size-cells = <1>; + + macaddr: macaddr@a { + compatible = "mac-base"; + reg = <0xa 0x6>; + #nvmem-cell-cells = <1>; + }; + }; + }; }; }; From patchwork Thu May 30 02:15:25 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 13679704 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 3F2991C693; Thu, 30 May 2024 02:15:38 +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=1717035339; cv=none; b=oCs0V611KpiEnYtXFi8Swmt5t3pyPJQYycS/o+HcwWuJzaO097IckOtvTsgYnH67dwjg0e6CMmUaIYzH2bSlYQ2wBBlo4EuRYk6CL6FfKrwIYjtGRFoUHuQcwuyJdsApJDULWijbEkN2DW39WuxYfpfUG7lch/cuTulFE9dqCVo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717035339; c=relaxed/simple; bh=6wAe6PDwPoPRbuAdisd3AgoRY7qZA25aGbQfD/XuvsY=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=iF/poW5jiWccKJQebTxrbR5KxgAqfMtimToSpxOIPyZc6svXa7OZico+sCzC2zZ5xY4XaE2blo9XIgC3eSiOgTDVnGK6UnaAk8drCIQCyu3xOVHth6UyT90MZ4AnTpC/yaSDp05bwYvKKGw3aVeKGo3bKmZ6Hw8z0SvxuqPl15g= 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.97.1) (envelope-from ) id 1sCVKD-000000004iN-1qwQ; Thu, 30 May 2024 02:15:29 +0000 Date: Thu, 30 May 2024 03:15:25 +0100 From: Daniel Golle To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Ulf Hansson , Jens Axboe , Srinivas Kandagatla , Daniel Golle , Dave Chinner , Jan Kara , Christian Brauner , Thomas =?iso-8859-1?q?Wei=DFschuh?= , Al Viro , Li Lingfeng , Christian Heusel , Min Li , Avri Altman , Adrian Hunter , Hannes Reinecke , Mikko Rapeli , Yeqi Fu , Victor Shih , Christophe JAILLET , Li Zhijian , "Ricardo B. Marliere" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH v2 7/9] mmc: core: set card fwnode_handle Message-ID: References: Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Set fwnode in case it isn't set yet and of_node is present. Signed-off-by: Daniel Golle --- drivers/mmc/core/bus.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/drivers/mmc/core/bus.c b/drivers/mmc/core/bus.c index 0ddaee0eae54..e1c5fc1b3ce4 100644 --- a/drivers/mmc/core/bus.c +++ b/drivers/mmc/core/bus.c @@ -364,6 +364,8 @@ int mmc_add_card(struct mmc_card *card) mmc_add_card_debugfs(card); card->dev.of_node = mmc_of_find_child_device(card->host, 0); + if (card->dev.of_node && !card->dev.fwnode) + card->dev.fwnode = &card->dev.of_node->fwnode; device_enable_async_suspend(&card->dev); From patchwork Thu May 30 02:15:36 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 13679705 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 522BA3D57A; Thu, 30 May 2024 02:15:49 +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=1717035350; cv=none; b=T5EU8eGdqALO0cHJWc7VJTSu3gIC/odDEzZ53MNGVzCuiH5Wuag2DBjuql3tLKt5F+/prTaNcQzZWrty4sWy1CVYgHs9WOKOrNuNxKeu3fh9PrF/gBo9ZKXlC5FLykVjIpCeyDTOOvWSdTJQf34o6B/2pVJ7TX8i1c2Bl3dvvrk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717035350; c=relaxed/simple; bh=jUdRJVyoIcjUb4yayy/yqSHIWyvEbd3XvWtltACDs4w=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=cV+ThJ1aRtEY+hFtAm16c13e1KrDc89GimVNu2mhRUX/OJKTyYuFKKi/TnSjFY+gRBYFUltPWknPQ8M+FP/tWEZAkDW29UuWyUTSG10ZJ4bydvSEPZyIjFmIMJgEg4GXKb2fum6ttJ6WmhNwVOVyTCjGXj1qgQUr12ykLxInRD8= 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.97.1) (envelope-from ) id 1sCVKO-000000004is-1sla; Thu, 30 May 2024 02:15:40 +0000 Date: Thu, 30 May 2024 03:15:36 +0100 From: Daniel Golle To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Ulf Hansson , Jens Axboe , Srinivas Kandagatla , Daniel Golle , Dave Chinner , Jan Kara , Christian Brauner , Thomas =?iso-8859-1?q?Wei=DFschuh?= , Al Viro , Li Lingfeng , Christian Heusel , Min Li , Avri Altman , Adrian Hunter , Hannes Reinecke , Mikko Rapeli , Yeqi Fu , Victor Shih , Christophe JAILLET , Li Zhijian , "Ricardo B. Marliere" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH v2 8/9] mmc: block: set fwnode of disk devices Message-ID: References: Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Set fwnode of disk devices to 'block', 'boot0' and 'boot1' subnodes of the mmc-card. This is done in preparation for having the eMMC act as NVMEM provider. Signed-off-by: Daniel Golle --- drivers/mmc/core/block.c | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 367509b5b646..cd3ee6d69aaa 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -2463,6 +2463,7 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, int area_type, unsigned int part_type) { + struct fwnode_handle *fwnode; struct mmc_blk_data *md; int devidx, ret; char cap_str[10]; @@ -2559,6 +2560,12 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, blk_queue_write_cache(md->queue.queue, cache_enabled, fua_enabled); + fwnode = device_get_named_child_node(subname ? md->parent->parent : + md->parent, + subname ? subname : "block"); + if (fwnode) + device_set_node(disk_to_dev(md->disk), fwnode); + string_get_size((u64)size, 512, STRING_UNITS_2, cap_str, sizeof(cap_str)); pr_info("%s: %s %s %s%s\n", From patchwork Thu May 30 02:15:46 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Daniel Golle X-Patchwork-Id: 13679706 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 33A441C2AD; Thu, 30 May 2024 02:16:00 +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=1717035361; cv=none; b=Yf7mfOeNOoXzN273K73Zp25laV3vLdfph1pRuA64yfC4gtszapAjMd6aEtM1CXMQ1oMvc+2wtI2gwt+GcmDKmOeO2HmbUlHo1+kgjHi434tdfUN+435gIVSiZG/OaeTjlooDe9H+PNy9VVMRgjgvUdr8Zbp4HgMireydlMDG7EQ= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1717035361; c=relaxed/simple; bh=m34IzQbYV7M9yK88DF0P7kP3OWiFqCk8AKxKQuzB5bs=; h=Date:From:To:Subject:Message-ID:References:MIME-Version: Content-Type:Content-Disposition:In-Reply-To; b=Rl2Nh51vy1R15rqwTStqZzWacxmPYkn+wEBaOzQtIDj6Z1zKCmx1Xjg3NBpiworcWcDbyykcCJl4Se2jm0G5IDcHuLzLQSnIfzh4feSQHRI/JzrGNNkcfjYqQHwW/4/nxtJDCE2/S+0TS9OvSyCOYWNHE8HDA0LGa624kboXGp0= 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.97.1) (envelope-from ) id 1sCVKY-000000004jd-18lv; Thu, 30 May 2024 02:15:50 +0000 Date: Thu, 30 May 2024 03:15:46 +0100 From: Daniel Golle To: Rob Herring , Krzysztof Kozlowski , Conor Dooley , Ulf Hansson , Jens Axboe , Srinivas Kandagatla , Daniel Golle , Dave Chinner , Jan Kara , Christian Brauner , Thomas =?iso-8859-1?q?Wei=DFschuh?= , Al Viro , Li Lingfeng , Christian Heusel , Min Li , Avri Altman , Adrian Hunter , Hannes Reinecke , Mikko Rapeli , Yeqi Fu , Victor Shih , Christophe JAILLET , Li Zhijian , "Ricardo B. Marliere" , devicetree@vger.kernel.org, linux-kernel@vger.kernel.org, linux-mmc@vger.kernel.org, linux-block@vger.kernel.org Subject: [PATCH v2 9/9] mmc: block: set GENHD_FL_NVMEM Message-ID: <927d02524c467351c546c4245a2eaf19030e8316.1717031992.git.daniel@makrotopia.org> References: Precedence: bulk X-Mailing-List: linux-block@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Set flag to consider MMC block devices as NVMEM providers. Signed-off-by: Daniel Golle --- drivers/mmc/core/block.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index cd3ee6d69aaa..577e7ae5df14 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -2516,6 +2516,7 @@ static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, md->disk->major = MMC_BLOCK_MAJOR; md->disk->minors = perdev_minors; md->disk->first_minor = devidx * perdev_minors; + md->disk->flags = GENHD_FL_NVMEM; md->disk->fops = &mmc_bdops; md->disk->private_data = md; md->parent = parent;