From patchwork Wed Aug 18 22:19:16 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12445519 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7A5EAC43216 for ; Wed, 18 Aug 2021 22:19:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 5B05A6112E for ; Wed, 18 Aug 2021 22:19:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234488AbhHRWUS (ORCPT ); Wed, 18 Aug 2021 18:20:18 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46818 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234535AbhHRWUR (ORCPT ); Wed, 18 Aug 2021 18:20:17 -0400 Received: from mail-lj1-x230.google.com (mail-lj1-x230.google.com [IPv6:2a00:1450:4864:20::230]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 56E9DC0613CF; Wed, 18 Aug 2021 15:19:42 -0700 (PDT) Received: by mail-lj1-x230.google.com with SMTP id l18so312309lji.12; Wed, 18 Aug 2021 15:19:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=1uZZlco6eQq/HqnOfmLu683xT1D8kyQqDaHKpo2lnkI=; b=L5j6fWLECUk64iGSu82/m8pclA8wZ5I1TMpN43cAv7b0CGDs09iwoTh1z8f9MVyNBq fz8Xft9KpJAv0BTfl5Zd+9KxPxlOqj5qTMErLv7h6fZj7Ky+PK1ILBE42qevDBA7my6N wTFhIOsQYA1nUHOlWd6HaWvdYmPXAm42ml5uKLnbIW+DP5UjhON5ilFnnCfRuQcdaI2c jrljvxLxGmxLc0zXjtSIsZcjVQT4ZpjBIYYLBsyInJlhmALaWUzbtj19ZXZ+Yt454nPT QwLnjUcIUS0WM4i2t1k45CFyMSpaI2WP5Jf8suXoCzgjUqrF9rTFJ8RF0myzPBSlAuyX 1IKA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=1uZZlco6eQq/HqnOfmLu683xT1D8kyQqDaHKpo2lnkI=; b=TIZhK8cjNFJjrH+Q1JNkszaPeetDaCI3bWA+nqwzlLOFhh9U1d7L7VKkE1L9pnXAwh z2Dq7QMymptSD1uvWmKia7gEwOiU2ylfXcHh4eQDRm6p8fV+77M1DFh8wGHlCRfHSQqA jKzkDxS+fb8rgXKE7uD3jPWrkONVBvF7fr8uh/FUluseua22uU3le0mIWyVYeNSy+RvB sneTX9l4zYGcbuvU4XBahrl5ZffglPp6ylH4Cqb8CLvFuGuDYDeuLjpcrOa7xkWwJxQ+ a5I/VLicWD3IeVUtXUcuJdmsji95WNmCh9pRZw0H2PGGLAcZxWuJgM9gM589EPHr5joU sRSg== X-Gm-Message-State: AOAM531E0Ss68mV23Zf2FBvaVITxo9q9a+YXSqnrA63pTvku93hvJqOn w1xT2wbdLVX4G67Yq6yOQDA= X-Google-Smtp-Source: ABdhPJxbgdXy1i81skijA/xJRm2fiSBlefs/wkh/MKv1EkaiQ08WVRcChJB/HKNRo+EyXLFeqGlMvg== X-Received: by 2002:a2e:8147:: with SMTP id t7mr9480074ljg.126.1629325180744; Wed, 18 Aug 2021 15:19:40 -0700 (PDT) Received: from localhost.localdomain (46-138-85-91.dynamic.spd-mgts.ru. [46.138.85.91]) by smtp.gmail.com with ESMTPSA id v23sm93300lfr.208.2021.08.18.15.19.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 15:19:40 -0700 (PDT) From: Dmitry Osipenko To: Jens Axboe , Thierry Reding , Jonathan Hunter , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , David Heidelberg , Peter Geis , Ulf Hansson , Adrian Hunter , Christoph Hellwig , Davidlohr Bueso , Rob Herring , Ion Agorria , Svyatoslav Ryhel Cc: linux-tegra@vger.kernel.org, linux-block@vger.kernel.org, linux-efi Subject: [PATCH v6 1/5] block: Add alternative_gpt_sector() operation Date: Thu, 19 Aug 2021 01:19:16 +0300 Message-Id: <20210818221920.3893-2-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210818221920.3893-1-digetx@gmail.com> References: <20210818221920.3893-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Add alternative_gpt_sector() block device operation which specifies alternative location of a GPT entry. This allows us to support Android devices that have GPT entry at a non-standard location and can't be repartitioned easily. Suggested-by: Christoph Hellwig Signed-off-by: Dmitry Osipenko Reviewed-by: Christoph Hellwig --- include/linux/blkdev.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 111a3911c4d2..d65c8f60ad8e 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1850,6 +1850,13 @@ struct block_device_operations { char *(*devnode)(struct gendisk *disk, umode_t *mode); struct module *owner; const struct pr_ops *pr_ops; + + /* + * Special callback for probing GPT entry at a given sector. + * Needed by Android devices, used by GPT scanner and MMC blk + * driver. + */ + int (*alternative_gpt_sector)(struct gendisk *disk, sector_t *sector); }; #ifdef CONFIG_COMPAT From patchwork Wed Aug 18 22:19:17 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12445521 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 56FA6C19F37 for ; Wed, 18 Aug 2021 22:19:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 404B06108D for ; Wed, 18 Aug 2021 22:19:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234581AbhHRWUT (ORCPT ); Wed, 18 Aug 2021 18:20:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46824 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234550AbhHRWUS (ORCPT ); Wed, 18 Aug 2021 18:20:18 -0400 Received: from mail-lf1-x12a.google.com (mail-lf1-x12a.google.com [IPv6:2a00:1450:4864:20::12a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3AF6EC061764; Wed, 18 Aug 2021 15:19:43 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id w20so7951820lfu.7; Wed, 18 Aug 2021 15:19:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=I8m3A5ojjjGr4tuZYoRH+9ybdfTR7NPts/xjHNXW+cg=; b=gCDGdNdaWu8hdnPG/tggLoVZlPxn7OWnfGa9sPTodCjCVf3q8a7+t9uzPYNJfNgvCS iW5l2Z5JYtzWy/3wnZ8ZT373nNP9qioBBw2HO1j9mO1zO6m+TWvMy6oaEW5BYWkZ9iV1 sAyNsQmpznLGwWYDSf1jOmSO6I8E5RtPiJ7va8DDcFeAnaDjJnVZCPZfNRi9Q6O+W7oJ y88+yCZu67CL8A3ANxogqBWmfNOcC0oGsiq+8IZ7/4mF1lydpk5ztuk3ReZv3HjnX6D8 7khYZn6djJBl7bffqNPIb+Wm7U10IDKn5avHJ5BMh6AuxBHzK13qdA6hRNIXa65Lup9F wdPw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=I8m3A5ojjjGr4tuZYoRH+9ybdfTR7NPts/xjHNXW+cg=; b=Bx8QKodg0+rdelS4N7amuxk8sHQkyAyaviVsDlwYpbzq6D1hbrHvenb45VxJNoRGQi U3CmWMc3mPjoAXKBSIW7QfuMvyZf5EUi2PN7bLztt/fttMRrCyieqtFjg2/mXl0iSrov CoLAW985flD6Vj2pJ8t45mu75e4qH2C8CarW/CDJ5RpKkJgxXrfHz6PfWIVIPy69XfFV GIiT08UH3mBrCvZKCXvg/4Izc4mLpNjJT3sobkekgdV2ajTgVEBi55cKzoX5zb/Q6htw 7X+EQNIWEpu3x/gck6hWqu7oZppBhYHt2z0yIzkaoAM/3ysDlIteg+o1D0h2NaRFOXjz +azg== X-Gm-Message-State: AOAM531lWkKLznK3fxKq3/hQ6JJ5ubRi7Pvzl+/aj1ViUAN0LWnTfsJ0 wLvUpFps1emv2KsQkFwWNDU= X-Google-Smtp-Source: ABdhPJxoavpH2kVL2BHylmnUL2aT6+FMjqUA6wXolJmwoncdXvHbyt6lQ7+oxUEaMeiXoXTxeNgIQA== X-Received: by 2002:a05:6512:401a:: with SMTP id br26mr3654435lfb.539.1629325181601; Wed, 18 Aug 2021 15:19:41 -0700 (PDT) Received: from localhost.localdomain (46-138-85-91.dynamic.spd-mgts.ru. [46.138.85.91]) by smtp.gmail.com with ESMTPSA id v23sm93300lfr.208.2021.08.18.15.19.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 15:19:41 -0700 (PDT) From: Dmitry Osipenko To: Jens Axboe , Thierry Reding , Jonathan Hunter , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , David Heidelberg , Peter Geis , Ulf Hansson , Adrian Hunter , Christoph Hellwig , Davidlohr Bueso , Rob Herring , Ion Agorria , Svyatoslav Ryhel Cc: linux-tegra@vger.kernel.org, linux-block@vger.kernel.org, linux-efi Subject: [PATCH v6 2/5] partitions/efi: Support non-standard GPT location Date: Thu, 19 Aug 2021 01:19:17 +0300 Message-Id: <20210818221920.3893-3-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210818221920.3893-1-digetx@gmail.com> References: <20210818221920.3893-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Support looking up GPT at a non-standard location specified by a block device driver. Signed-off-by: Dmitry Osipenko Reviewed-by: Christoph Hellwig Acked-by: Davidlohr Bueso --- block/partitions/efi.c | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/block/partitions/efi.c b/block/partitions/efi.c index aaa3dc487cb5..7ca5c4c374d4 100644 --- a/block/partitions/efi.c +++ b/block/partitions/efi.c @@ -585,6 +585,8 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt, gpt_header *pgpt = NULL, *agpt = NULL; gpt_entry *pptes = NULL, *aptes = NULL; legacy_mbr *legacymbr; + struct gendisk *disk = state->disk; + const struct block_device_operations *fops = disk->fops; sector_t total_sectors = get_capacity(state->disk); u64 lastlba; @@ -619,6 +621,16 @@ static int find_valid_gpt(struct parsed_partitions *state, gpt_header **gpt, if (!good_agpt && force_gpt) good_agpt = is_gpt_valid(state, lastlba, &agpt, &aptes); + if (!good_agpt && force_gpt && fops->alternative_gpt_sector) { + sector_t agpt_sector; + int err; + + err = fops->alternative_gpt_sector(disk, &agpt_sector); + if (!err) + good_agpt = is_gpt_valid(state, agpt_sector, + &agpt, &aptes); + } + /* The obviously unsuccessful case */ if (!good_pgpt && !good_agpt) goto fail; From patchwork Wed Aug 18 22:19:18 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12445523 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CCCE4C19F3A for ; Wed, 18 Aug 2021 22:19:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id B024B6103A for ; Wed, 18 Aug 2021 22:19:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234550AbhHRWUT (ORCPT ); Wed, 18 Aug 2021 18:20:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46830 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234570AbhHRWUT (ORCPT ); Wed, 18 Aug 2021 18:20:19 -0400 Received: from mail-lf1-x132.google.com (mail-lf1-x132.google.com [IPv6:2a00:1450:4864:20::132]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09BDEC061764; Wed, 18 Aug 2021 15:19:44 -0700 (PDT) Received: by mail-lf1-x132.google.com with SMTP id o10so7914016lfr.11; Wed, 18 Aug 2021 15:19:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=K6QaUUEp/rXx/wbK2KzXouwYq97hW25f84jkRB+ohcc=; b=nEC/ae0PSXn3p2MGe5DnoL7vkt3QJaPxeWhD8TJwrQqMQ5xL8BWZqZAWoPtdmRf1od zUK17L5rIxTEgAbLXoRQ821/ICWmMe9F2iGE5nqMxi9svauZad84Tman6b0RqQWunAny jw0Emh2UMseZUHOARo6fXEgSAMQWFXY3J3X6gpYCS5qAZJCsWX5UkC94PCjPVfpqXXbP 5OkZmzpH66NmZJDgyjiJVEwgHya2h/15viJqX/eK/lrmqibl663EKx+2JLqqoGnDJkOJ QJQ5e/Dhy7jYJQ0+EibjYuIZMbw+QyVQoZHjzIO14XfFZOAjO4+OD2umb2svdIxC41nm rvaw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=K6QaUUEp/rXx/wbK2KzXouwYq97hW25f84jkRB+ohcc=; b=aQsp/yG+cn17FMhDWeAsR6rEQI3O9Xyk95+I2G/0Qaj3BYlU2TjOo26ZLvkXY1Uity +WnZ9SAVjZt9cavN2YkHAsFJdOkXZGQlSL8WqiL36YMnoTACPhcAQ+qHoeMQgHaq068d 2k+iXSttfYkoc/YSQg1lxsAFVg5olnygeYk73hql55pY3/ZCBxMPX7bSL9tqQKqsLezf qbYU/PYVwCJurk0QBcM9MvQp/F73VmX9FQahhuocdoM3sPkN4i2W12lJFozDjvLtkTt6 WfjD5T2mbg8XvCrfXq/qqI9gV/zTuJvR0X85zS4loxfNr3qL2rKQQ6YzENIrXjJd//TN sK2A== X-Gm-Message-State: AOAM533uCGNGLAKQqRz3PEKphgrdetWnPDk+dPgL2qoRNb098qlAdVmr 0Hz9tgoRcq9D27byDNzX/mU= X-Google-Smtp-Source: ABdhPJw61jbm0S7IN9ZczlF8RfksF6FWUZWrqS1E0uwTp8wNHQig9KXHWNgjz1gPoy7l7CZImFTzwQ== X-Received: by 2002:ac2:4182:: with SMTP id z2mr8396353lfh.503.1629325182412; Wed, 18 Aug 2021 15:19:42 -0700 (PDT) Received: from localhost.localdomain (46-138-85-91.dynamic.spd-mgts.ru. [46.138.85.91]) by smtp.gmail.com with ESMTPSA id v23sm93300lfr.208.2021.08.18.15.19.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 15:19:42 -0700 (PDT) From: Dmitry Osipenko To: Jens Axboe , Thierry Reding , Jonathan Hunter , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , David Heidelberg , Peter Geis , Ulf Hansson , Adrian Hunter , Christoph Hellwig , Davidlohr Bueso , Rob Herring , Ion Agorria , Svyatoslav Ryhel Cc: linux-tegra@vger.kernel.org, linux-block@vger.kernel.org, linux-efi Subject: [PATCH v6 3/5] mmc: core: Add raw_boot_mult field to mmc_ext_csd Date: Thu, 19 Aug 2021 01:19:18 +0300 Message-Id: <20210818221920.3893-4-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210818221920.3893-1-digetx@gmail.com> References: <20210818221920.3893-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Bootloader of NVIDIA Tegra devices linearizes the boot0/boot1/main partitions into a single virtual space, and thus, all partition addresses are shifted by the size of boot0 + boot1 partitions. The offset needs to be known in order to find the GPT entry on eMMC storage of Tegra devices. Add raw_boot_mult field to mmc_ext_csd which allows to get size of the boot partitions. Signed-off-by: Dmitry Osipenko --- drivers/mmc/core/mmc.c | 2 ++ include/linux/mmc/card.h | 1 + 2 files changed, 3 insertions(+) diff --git a/drivers/mmc/core/mmc.c b/drivers/mmc/core/mmc.c index 838726b68ff3..29e58ffae379 100644 --- a/drivers/mmc/core/mmc.c +++ b/drivers/mmc/core/mmc.c @@ -418,6 +418,8 @@ static int mmc_decode_ext_csd(struct mmc_card *card, u8 *ext_csd) ext_csd[EXT_CSD_ERASE_TIMEOUT_MULT]; card->ext_csd.raw_hc_erase_grp_size = ext_csd[EXT_CSD_HC_ERASE_GRP_SIZE]; + card->ext_csd.raw_boot_mult = + ext_csd[EXT_CSD_BOOT_MULT]; if (card->ext_csd.rev >= 3) { u8 sa_shift = ext_csd[EXT_CSD_S_A_TIMEOUT]; card->ext_csd.part_config = ext_csd[EXT_CSD_PART_CONFIG]; diff --git a/include/linux/mmc/card.h b/include/linux/mmc/card.h index 74e6c0624d27..37f975875102 100644 --- a/include/linux/mmc/card.h +++ b/include/linux/mmc/card.h @@ -109,6 +109,7 @@ struct mmc_ext_csd { u8 raw_hc_erase_gap_size; /* 221 */ u8 raw_erase_timeout_mult; /* 223 */ u8 raw_hc_erase_grp_size; /* 224 */ + u8 raw_boot_mult; /* 226 */ u8 raw_sec_trim_mult; /* 229 */ u8 raw_sec_erase_mult; /* 230 */ u8 raw_sec_feature_support;/* 231 */ From patchwork Wed Aug 18 22:19:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12445525 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9B509C19F3B for ; Wed, 18 Aug 2021 22:19:46 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7D89A6108D for ; Wed, 18 Aug 2021 22:19:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234600AbhHRWUU (ORCPT ); Wed, 18 Aug 2021 18:20:20 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46836 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234537AbhHRWUU (ORCPT ); Wed, 18 Aug 2021 18:20:20 -0400 Received: from mail-lj1-x22a.google.com (mail-lj1-x22a.google.com [IPv6:2a00:1450:4864:20::22a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA883C0613CF; Wed, 18 Aug 2021 15:19:44 -0700 (PDT) Received: by mail-lj1-x22a.google.com with SMTP id s3so7816307ljp.11; Wed, 18 Aug 2021 15:19:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LTMAdBrsvzeZ0XhMt9UfvK9bMaYh6LsNsjbXOlJB+Ig=; b=NntM3vLdzCxMrLF7C+hI26B8faT8xvNVL11KAi4biul8CG5JMNniayaW336AcEqaoY 4tnU6YvdnxrAHXWI+5F9rigc5dKY7U8pbxwk0lf0FRh3Koj8bQY0wJK6/4pXJCXDoJw/ 8utjv9KF3jUwtjeXsY8UQzT6q5A92i5UTn+Ipy4Jah3rbWidPQNGNAscJlJpY+2IAmcx bW+WKVTlancG6gq7a9/P2u3SlHhCywKl8CmHOEDgGCjk+oaPwHiMixpuk5F0XO2B+lhc fXMieor1hHq5GRwwsdrZIIjbL5THHwB11yosn/NoBfv9dDGDvSa4hGHxP/IZEuw0+uRP P+bA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LTMAdBrsvzeZ0XhMt9UfvK9bMaYh6LsNsjbXOlJB+Ig=; b=mGv3WX0qzy08awItdC/o8C+LdGtePiy5dIHgr/Y8jopOjUlYQqlZB3JXliu+JGLU+m QTsoN7YJNQQAZZEtb6jvakPDdu8v9MqzwFQEpUw3mQpVTFb8mgTMfUUNiQVLoY6DdeUc ON3+s7jXGgfukYh9FdN1pjycWqOsm1PmqdKH6wGtWUeGNSnRtZ67VoTOiHRWa6NH71qz qc5BvDamWazucn3xzGcgZOj1REuwDxjiikcXULz0yQuGwdpaUXhwy9VXcpm/fEKPp/EY AiTkV6PytsXqg+X8oPdNpUKvgOgQfDSecVvQScBp5yoGVKiw0ptqf7FY0f/qAfri4Hnx jw/Q== X-Gm-Message-State: AOAM5326Ho6XN77rZW3HI76fnEtuajGKf0JR1csxlkbR8VCF9WHLkWeo tnvdoM5q1/Ou+DZ2lJSwo1A= X-Google-Smtp-Source: ABdhPJymNdEVPfjksCygr2UStMVzSzB3PbF21BxGtLXEWM25oXisKQIrDSOhP4y9EBNoP92BBQ4PrA== X-Received: by 2002:a2e:a785:: with SMTP id c5mr9499854ljf.434.1629325183279; Wed, 18 Aug 2021 15:19:43 -0700 (PDT) Received: from localhost.localdomain (46-138-85-91.dynamic.spd-mgts.ru. [46.138.85.91]) by smtp.gmail.com with ESMTPSA id v23sm93300lfr.208.2021.08.18.15.19.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 15:19:42 -0700 (PDT) From: Dmitry Osipenko To: Jens Axboe , Thierry Reding , Jonathan Hunter , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , David Heidelberg , Peter Geis , Ulf Hansson , Adrian Hunter , Christoph Hellwig , Davidlohr Bueso , Rob Herring , Ion Agorria , Svyatoslav Ryhel Cc: linux-tegra@vger.kernel.org, linux-block@vger.kernel.org, linux-efi Subject: [PATCH v6 4/5] mmc: block: Support alternative_gpt_sector() operation Date: Thu, 19 Aug 2021 01:19:19 +0300 Message-Id: <20210818221920.3893-5-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210818221920.3893-1-digetx@gmail.com> References: <20210818221920.3893-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Support generic alternative_gpt_sector() block device operation which calculates custom GPT location. Add new MMC_CAP2_ALTERNATIVE_GPT_SECTOR flag that enables scanning of the alternative sector. Signed-off-by: Dmitry Osipenko --- drivers/mmc/core/block.c | 21 +++++++++++++++++++++ drivers/mmc/core/core.c | 35 +++++++++++++++++++++++++++++++++++ drivers/mmc/core/core.h | 2 ++ include/linux/mmc/host.h | 1 + 4 files changed, 59 insertions(+) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 672cc505ce37..edd26164be06 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -801,6 +801,26 @@ static int mmc_blk_compat_ioctl(struct block_device *bdev, fmode_t mode, } #endif +static int mmc_blk_alternative_gpt_sector(struct gendisk *disk, + sector_t *sector) +{ + struct mmc_blk_data *md; + int ret; + + md = mmc_blk_get(disk); + if (!md) + return -EINVAL; + + if (md->queue.card) + ret = mmc_card_alternative_gpt_sector(md->queue.card, sector); + else + ret = -ENODEV; + + mmc_blk_put(md); + + return ret; +} + static const struct block_device_operations mmc_bdops = { .open = mmc_blk_open, .release = mmc_blk_release, @@ -810,6 +830,7 @@ static const struct block_device_operations mmc_bdops = { #ifdef CONFIG_COMPAT .compat_ioctl = mmc_blk_compat_ioctl, #endif + .alternative_gpt_sector = mmc_blk_alternative_gpt_sector, }; static int mmc_blk_part_switch_pre(struct mmc_card *card, diff --git a/drivers/mmc/core/core.c b/drivers/mmc/core/core.c index 6249c83d616f..c5cdd56051cb 100644 --- a/drivers/mmc/core/core.c +++ b/drivers/mmc/core/core.c @@ -2150,6 +2150,41 @@ int mmc_detect_card_removed(struct mmc_host *host) } EXPORT_SYMBOL(mmc_detect_card_removed); +int mmc_card_alternative_gpt_sector(struct mmc_card *card, sector_t *gpt_sector) +{ + unsigned int boot_sectors_num; + + if ((!(card->host->caps2 & MMC_CAP2_ALT_GPT_SECTOR))) + return -EOPNOTSUPP; + + /* filter out unrelated cards */ + if (card->ext_csd.rev < 3 || + !mmc_card_mmc(card) || + !mmc_card_is_blockaddr(card) || + mmc_card_is_removable(card->host)) + return -ENOENT; + + /* + * eMMC storage has two special boot partitions in addition to the + * main one. NVIDIA's bootloader linearizes eMMC boot0->boot1->main + * accesses, this means that the partition table addresses are shifted + * by the size of boot partitions. In accordance with the eMMC + * specification, the boot partition size is calculated as follows: + * + * boot partition size = 128K byte x BOOT_SIZE_MULT + * + * Calculate number of sectors occupied by the both boot partitions. + */ + boot_sectors_num = card->ext_csd.raw_boot_mult * SZ_128K / + SZ_512 * MMC_NUM_BOOT_PARTITION; + + /* Defined by NVIDIA and used by Android devices. */ + *gpt_sector = card->ext_csd.sectors - boot_sectors_num - 1; + + return 0; +} +EXPORT_SYMBOL(mmc_card_alternative_gpt_sector); + void mmc_rescan(struct work_struct *work) { struct mmc_host *host = diff --git a/drivers/mmc/core/core.h b/drivers/mmc/core/core.h index 0c4de2030b3f..7931a4f0137d 100644 --- a/drivers/mmc/core/core.h +++ b/drivers/mmc/core/core.h @@ -119,6 +119,8 @@ void mmc_release_host(struct mmc_host *host); void mmc_get_card(struct mmc_card *card, struct mmc_ctx *ctx); void mmc_put_card(struct mmc_card *card, struct mmc_ctx *ctx); +int mmc_card_alternative_gpt_sector(struct mmc_card *card, sector_t *sector); + /** * mmc_claim_host - exclusively claim a host * @host: mmc host to claim diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 0abd47e9ef9b..73a4cc063bb0 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -398,6 +398,7 @@ struct mmc_host { #else #define MMC_CAP2_CRYPTO 0 #endif +#define MMC_CAP2_ALT_GPT_SECTOR (1 << 28) /* Host with eMMC card that has GPT entry at a non-standard location */ int fixed_drv_type; /* fixed driver type for non-removable media */ From patchwork Wed Aug 18 22:19:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12445527 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 439BDC19F3E for ; Wed, 18 Aug 2021 22:19:47 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2B6CB6108B for ; Wed, 18 Aug 2021 22:19:47 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S234603AbhHRWUV (ORCPT ); Wed, 18 Aug 2021 18:20:21 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46846 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234537AbhHRWUV (ORCPT ); Wed, 18 Aug 2021 18:20:21 -0400 Received: from mail-lf1-x12e.google.com (mail-lf1-x12e.google.com [IPv6:2a00:1450:4864:20::12e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id BC5D2C0613D9; Wed, 18 Aug 2021 15:19:45 -0700 (PDT) Received: by mail-lf1-x12e.google.com with SMTP id o10so7914138lfr.11; Wed, 18 Aug 2021 15:19:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=xtGQgjxMEZMlhC/xeDEiMn9ep1RQCyByheCct7MRol4=; b=fqBqV/qWwyuboVt+vWtn58b/iJu8+z3vqWQuC9BB8si+QCQ3xNbWfZQrGBmGzwfNlk /zil+y5Svz6VxOIOCS8ZCr+tUNCYDLrRi/efgwwsN97hLg/mD9nAZ/L33DWmtEzEw4MT XHVRvEKRgAm1qsuVPbH182NyjXpvJQA9Tl9fw8kwc9gRpX931zIZHhoRMx+utU7Mxu51 zMiqsdfGmYpBFOdx/3y8Jq4/zcIoSInKWKYYlSKZ9Z9MgMOFEzqv/f8xnzHkigt5uzBe 15KNwSu8ePKYy6AdfLxkBQ5TZn2solVhnQopukQLaA+io7L0nvGY69CMd3u1iNqFR3+F Uf7Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=xtGQgjxMEZMlhC/xeDEiMn9ep1RQCyByheCct7MRol4=; b=T9Lo/UUwy8//nuislkHzYvYDRjcaycuXA8zQpTPK4vhy0k5Y1r0yB8yefiDZgpb8BK 8JxSO9T9SSpbKUPLAzCOW1ljAxaYe5ccW1RBWI6vOISeddqYq5aGYzQiim9HIUh06w+3 77Lt3D5u9C63ICo82pAT2nMxGXClxOM82ObfBlYZl9l4nZWjVLPYB7XaQbwTO10MSMmX pRuh+qI75WbtvVo9o0v/UEJ450G7TmUp+WP3IocOovciPUlwnGGlufrSQtkprV9CgoG6 i6kiZm54MefyVIzC1UtwpvRHN/VrN5rpypRwU9ShJY3XwbvMChytWDTXxOVZej5kMT61 BG2A== X-Gm-Message-State: AOAM533zhjq0b/gmfSNVp5fEIlbp46DqnKhVaj5jZ8L+DYhv0bbnUNqd qZr0bLzAku2YSfezZ2hbX7On29sQ74g= X-Google-Smtp-Source: ABdhPJzk8Bz3BIudvvqL9aNZo0PYlxdeHsaXV3MzYKZ+EdYIdH7reEaf1RQNTstLluu7sWur6PjKpA== X-Received: by 2002:a05:6512:1518:: with SMTP id bq24mr7681150lfb.271.1629325184128; Wed, 18 Aug 2021 15:19:44 -0700 (PDT) Received: from localhost.localdomain (46-138-85-91.dynamic.spd-mgts.ru. [46.138.85.91]) by smtp.gmail.com with ESMTPSA id v23sm93300lfr.208.2021.08.18.15.19.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 18 Aug 2021 15:19:43 -0700 (PDT) From: Dmitry Osipenko To: Jens Axboe , Thierry Reding , Jonathan Hunter , =?utf-8?b?TWljaGHFgiBNaXJvc8WCYXc=?= , David Heidelberg , Peter Geis , Ulf Hansson , Adrian Hunter , Christoph Hellwig , Davidlohr Bueso , Rob Herring , Ion Agorria , Svyatoslav Ryhel Cc: linux-tegra@vger.kernel.org, linux-block@vger.kernel.org, linux-efi Subject: [PATCH v6 5/5] mmc: sdhci-tegra: Enable MMC_CAP2_ALT_GPT_SECTOR Date: Thu, 19 Aug 2021 01:19:20 +0300 Message-Id: <20210818221920.3893-6-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210818221920.3893-1-digetx@gmail.com> References: <20210818221920.3893-1-digetx@gmail.com> MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: linux-block@vger.kernel.org Tegra20/30/114/124 Android devices place GPT at a non-standard location. Enable GPT entry scanning at that location. Signed-off-by: Dmitry Osipenko --- drivers/mmc/host/sdhci-tegra.c | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c index 387ce9cdbd7c..39cfbb28ccc3 100644 --- a/drivers/mmc/host/sdhci-tegra.c +++ b/drivers/mmc/host/sdhci-tegra.c @@ -116,6 +116,8 @@ */ #define NVQUIRK_HAS_TMCLK BIT(10) +#define NVQUIRK_HAS_ANDROID_GPT_SECTOR BIT(11) + /* SDMMC CQE Base Address for Tegra Host Ver 4.1 and Higher */ #define SDHCI_TEGRA_CQE_BASE_ADDR 0xF000 @@ -1361,6 +1363,7 @@ static const struct sdhci_tegra_soc_data soc_data_tegra20 = { .pdata = &sdhci_tegra20_pdata, .dma_mask = DMA_BIT_MASK(32), .nvquirks = NVQUIRK_FORCE_SDHCI_SPEC_200 | + NVQUIRK_HAS_ANDROID_GPT_SECTOR | NVQUIRK_ENABLE_BLOCK_GAP_DET, }; @@ -1390,6 +1393,7 @@ static const struct sdhci_tegra_soc_data soc_data_tegra30 = { .nvquirks = NVQUIRK_ENABLE_SDHCI_SPEC_300 | NVQUIRK_ENABLE_SDR50 | NVQUIRK_ENABLE_SDR104 | + NVQUIRK_HAS_ANDROID_GPT_SECTOR | NVQUIRK_HAS_PADCALIB, }; @@ -1422,6 +1426,7 @@ static const struct sdhci_pltfm_data sdhci_tegra114_pdata = { static const struct sdhci_tegra_soc_data soc_data_tegra114 = { .pdata = &sdhci_tegra114_pdata, .dma_mask = DMA_BIT_MASK(32), + .nvquirks = NVQUIRK_HAS_ANDROID_GPT_SECTOR, }; static const struct sdhci_pltfm_data sdhci_tegra124_pdata = { @@ -1438,6 +1443,7 @@ static const struct sdhci_pltfm_data sdhci_tegra124_pdata = { static const struct sdhci_tegra_soc_data soc_data_tegra124 = { .pdata = &sdhci_tegra124_pdata, .dma_mask = DMA_BIT_MASK(34), + .nvquirks = NVQUIRK_HAS_ANDROID_GPT_SECTOR, }; static const struct sdhci_ops tegra210_sdhci_ops = { @@ -1616,6 +1622,9 @@ static int sdhci_tegra_probe(struct platform_device *pdev) tegra_host->pad_control_available = false; tegra_host->soc_data = soc_data; + if (soc_data->nvquirks & NVQUIRK_HAS_ANDROID_GPT_SECTOR) + host->mmc->caps2 |= MMC_CAP2_ALT_GPT_SECTOR; + if (soc_data->nvquirks & NVQUIRK_NEEDS_PAD_CONTROL) { rc = tegra_sdhci_init_pinctrl_info(&pdev->dev, tegra_host); if (rc == 0)