450-09-block-partitions-populate-fwnode.patch 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. From 614f4f6fdda09e30ecf7ef6c8091579db15018cb Mon Sep 17 00:00:00 2001
  2. From: Daniel Golle <[email protected]>
  3. Date: Fri, 21 Jul 2023 17:51:03 +0100
  4. Subject: [PATCH 09/15] block: partitions: populate fwnode
  5. Let block partitions to be represented by a firmware node and hence
  6. allow them to being referenced e.g. for use with blk-nvmem.
  7. Signed-off-by: Daniel Golle <[email protected]>
  8. ---
  9. block/partitions/core.c | 41 +++++++++++++++++++++++++++++++++++++++++
  10. 1 file changed, 41 insertions(+)
  11. --- a/block/partitions/core.c
  12. +++ b/block/partitions/core.c
  13. @@ -10,6 +10,8 @@
  14. #include <linux/ctype.h>
  15. #include <linux/vmalloc.h>
  16. #include <linux/raid/detect.h>
  17. +#include <linux/property.h>
  18. +
  19. #include "check.h"
  20. static int (*const check_part[])(struct parsed_partitions *) = {
  21. @@ -292,6 +294,43 @@ static ssize_t whole_disk_show(struct de
  22. }
  23. static const DEVICE_ATTR(whole_disk, 0444, whole_disk_show, NULL);
  24. +static struct fwnode_handle *find_partition_fwnode(struct block_device *bdev)
  25. +{
  26. + struct fwnode_handle *fw_parts, *fw_part;
  27. + struct device *ddev = disk_to_dev(bdev->bd_disk);
  28. + const char *partname, *uuid;
  29. + u32 partno;
  30. +
  31. + fw_parts = device_get_named_child_node(ddev, "partitions");
  32. + if (!fw_parts)
  33. + fw_parts = device_get_named_child_node(ddev->parent, "partitions");
  34. +
  35. + if (!fw_parts)
  36. + return NULL;
  37. +
  38. + fwnode_for_each_child_node(fw_parts, fw_part) {
  39. + if (!fwnode_property_read_string(fw_part, "uuid", &uuid) &&
  40. + (!bdev->bd_meta_info || strncmp(uuid,
  41. + bdev->bd_meta_info->uuid,
  42. + PARTITION_META_INFO_UUIDLTH)))
  43. + continue;
  44. +
  45. + if (!fwnode_property_read_string(fw_part, "partname", &partname) &&
  46. + (!bdev->bd_meta_info || strncmp(partname,
  47. + bdev->bd_meta_info->volname,
  48. + PARTITION_META_INFO_VOLNAMELTH)))
  49. + continue;
  50. +
  51. + if (!fwnode_property_read_u32(fw_part, "partno", &partno) &&
  52. + bdev->bd_partno != partno)
  53. + continue;
  54. +
  55. + return fw_part;
  56. + }
  57. +
  58. + return NULL;
  59. +}
  60. +
  61. /*
  62. * Must be called either with open_mutex held, before a disk can be opened or
  63. * after all disk users are gone.
  64. @@ -374,6 +413,8 @@ static struct block_device *add_partitio
  65. goto out_put;
  66. }
  67. + device_set_node(pdev, find_partition_fwnode(bdev));
  68. +
  69. /* delay uevent until 'holders' subdir is created */
  70. dev_set_uevent_suppress(pdev, 1);
  71. err = device_add(pdev);