Linux kernel mirror (for testing) git.kernel.org/pub/scm/linux/kernel/git/torvalds/linux.git
kernel os linux

mmc: block: attach partitions fwnode if found in mmc-card

Attach partitions fwnode if found in mmc-card and register disk with it.

This permits block partition to reference the node and register a
partition table defined in DT for the special case for embedded device
that doesn't have a partition table flashed but have an hardcoded
partition table passed from the system.

JEDEC BOOT partition boot0/boot1 are supported but in DT we refer with
the JEDEC name of boot1 and boot2 to better adhere to documentation.

Also JEDEC GP partition gp0/1/2/3 are supported but in DT we refer with
the JEDEC name of gp1/2/3/4 to better adhere to documentration.

Signed-off-by: Christian Marangi <ansuelsmth@gmail.com>
Reviewed-by: Linus Walleij <linus.walleij@linaro.org>
Link: https://lore.kernel.org/r/20241002221306.4403-5-ansuelsmth@gmail.com
Signed-off-by: Jens Axboe <axboe@kernel.dk>

authored by

Christian Marangi and committed by
Jens Axboe
3ec7cb11 9dfd9ea9

+54 -1
+54 -1
drivers/mmc/core/block.c
··· 2501 2501 !(card->csd.cmdclass & CCC_BLOCK_WRITE); 2502 2502 } 2503 2503 2504 + /* 2505 + * Search for a declared partitions node for the disk in mmc-card related node. 2506 + * 2507 + * This is to permit support for partition table defined in DT in special case 2508 + * where a partition table is not written in the disk and is expected to be 2509 + * passed from the running system. 2510 + * 2511 + * For the user disk, "partitions" node is searched. 2512 + * For the special HW disk, "partitions-" node with the appended name is used 2513 + * following this conversion table (to adhere to JEDEC naming) 2514 + * - boot0 -> partitions-boot1 2515 + * - boot1 -> partitions-boot2 2516 + * - gp0 -> partitions-gp1 2517 + * - gp1 -> partitions-gp2 2518 + * - gp2 -> partitions-gp3 2519 + * - gp3 -> partitions-gp4 2520 + */ 2521 + static struct fwnode_handle *mmc_blk_get_partitions_node(struct device *mmc_dev, 2522 + const char *subname) 2523 + { 2524 + const char *node_name = "partitions"; 2525 + 2526 + if (subname) { 2527 + mmc_dev = mmc_dev->parent; 2528 + 2529 + /* 2530 + * Check if we are allocating a BOOT disk boot0/1 disk. 2531 + * In DT we use the JEDEC naming boot1/2. 2532 + */ 2533 + if (!strcmp(subname, "boot0")) 2534 + node_name = "partitions-boot1"; 2535 + if (!strcmp(subname, "boot1")) 2536 + node_name = "partitions-boot2"; 2537 + /* 2538 + * Check if we are allocating a GP disk gp0/1/2/3 disk. 2539 + * In DT we use the JEDEC naming gp1/2/3/4. 2540 + */ 2541 + if (!strcmp(subname, "gp0")) 2542 + node_name = "partitions-gp1"; 2543 + if (!strcmp(subname, "gp1")) 2544 + node_name = "partitions-gp2"; 2545 + if (!strcmp(subname, "gp2")) 2546 + node_name = "partitions-gp3"; 2547 + if (!strcmp(subname, "gp3")) 2548 + node_name = "partitions-gp4"; 2549 + } 2550 + 2551 + return device_get_named_child_node(mmc_dev, node_name); 2552 + } 2553 + 2504 2554 static struct mmc_blk_data *mmc_blk_alloc_req(struct mmc_card *card, 2505 2555 struct device *parent, 2506 2556 sector_t size, ··· 2559 2509 int area_type, 2560 2510 unsigned int part_type) 2561 2511 { 2512 + struct fwnode_handle *disk_fwnode; 2562 2513 struct mmc_blk_data *md; 2563 2514 int devidx, ret; 2564 2515 char cap_str[10]; ··· 2661 2610 /* used in ->open, must be set before add_disk: */ 2662 2611 if (area_type == MMC_BLK_DATA_AREA_MAIN) 2663 2612 dev_set_drvdata(&card->dev, md); 2664 - ret = device_add_disk(md->parent, md->disk, mmc_disk_attr_groups); 2613 + disk_fwnode = mmc_blk_get_partitions_node(parent, subname); 2614 + ret = add_disk_fwnode(md->parent, md->disk, mmc_disk_attr_groups, 2615 + disk_fwnode); 2665 2616 if (ret) 2666 2617 goto err_put_disk; 2667 2618 return md;