From patchwork Wed Aug 18 00:55:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12442439 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 65771C43216 for ; Wed, 18 Aug 2021 00:57:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 48F5E61056 for ; Wed, 18 Aug 2021 00:57:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237269AbhHRA5s (ORCPT ); Tue, 17 Aug 2021 20:57:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59168 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S234119AbhHRA5r (ORCPT ); Tue, 17 Aug 2021 20:57:47 -0400 Received: from mail-lf1-x133.google.com (mail-lf1-x133.google.com [IPv6:2a00:1450:4864:20::133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 474F2C061764; Tue, 17 Aug 2021 17:57:13 -0700 (PDT) Received: by mail-lf1-x133.google.com with SMTP id x27so906268lfu.5; Tue, 17 Aug 2021 17:57:13 -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=FHpah2Dpj/TPubzzjmkmJuckncZAa3WMYxXsj2gsyts=; b=YSYnszVgE5PGV58mwWn67rQ0Qo3HjRDXp+af5aIntm1uZ8ToaPuKIcgg7+semEvT6o dUSAlnevDzeGlPupiIn5iTD0o/LdvbMteTvM2aALs7CrsxdElukm7Xr3J8RyUTapgeo0 9eXOT38ZR/JjOQ0q+C96ps9+y5sYiDIpD2cg9rnWoeNn/xwGGZYuo7ZKpI+pLsvDvINj M0558BipCq8ETfsCHj4EJqr31sDeOKMhNmRyTWqYBDvbcTjiYIHFPZMmd0DR8+k0I80B 1Er9XwH9kr2FOw3Mo5dmiBcqSz1LZ36b8Tst4F9POz1FBLLnpgBaxAWE3yDr3XzMWLcj Alsw== 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=FHpah2Dpj/TPubzzjmkmJuckncZAa3WMYxXsj2gsyts=; b=ErLT+gWbeqUstHwdLPCnj8K7xcPUj/FXKRV/aSSqCLiJgnWCCpW50Uh1PWgIuL6jSh JMKw2tl8mtNnoJ9yvk20mgBpmaAnRLX0OyhYQHc+kUHKALjKk4VwGumVVv4h2P+3JdW+ GGk0eqPecR8fp+GJ6GKXZDDrC8uM7vwu0vikFvIs2p6dVWIpUrxS76BaZnNSrSboLqEm xjVKpoarVpEvhfzTUg37kBVj4+7KEOghqeldfJ6GdGM6Bq9DJBTr/vNl5K90WjSdyMqI yWVsFvWOf/VmK70z0d4zlFwdd+BAZcJK/L/NnKBQMmYbEKgLxsl8MWeBmizqArHEKZrz upkA== X-Gm-Message-State: AOAM533bSTj5kXtXndRGKp201lJdqFk15ni6jIalDRaZkXIKrSusuwiZ fNUcfDWJozhv8oXyhC5uWrQ= X-Google-Smtp-Source: ABdhPJzHR1wMJp3yBjzWxkyYvY33vsGCKBmKN2ow3m7gwngkxK9Xdtf/PN36aCM0S5wPqlQVVECrbQ== X-Received: by 2002:ac2:46ef:: with SMTP id q15mr4460085lfo.407.1629248231719; Tue, 17 Aug 2021 17:57:11 -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 h19sm335879lfu.138.2021.08.17.17.57.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 17:57:11 -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 v5 1/5] block: Add alternative_gpt_sector() operation Date: Wed, 18 Aug 2021 03:55:43 +0300 Message-Id: <20210818005547.14497-2-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210818005547.14497-1-digetx@gmail.com> References: <20210818005547.14497-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 which have GPT entry at a non-standard location and can't be repartitioned easily. Suggested-by: Christoph Hellwig Signed-off-by: Dmitry Osipenko --- include/linux/blkdev.h | 1 + 1 file changed, 1 insertion(+) diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h index 111a3911c4d2..a662a8f5065f 100644 --- a/include/linux/blkdev.h +++ b/include/linux/blkdev.h @@ -1848,6 +1848,7 @@ struct block_device_operations { int (*report_zones)(struct gendisk *, sector_t sector, unsigned int nr_zones, report_zones_cb cb, void *data); char *(*devnode)(struct gendisk *disk, umode_t *mode); + int (*alternative_gpt_sector)(struct block_device *, sector_t *); struct module *owner; const struct pr_ops *pr_ops; }; From patchwork Wed Aug 18 00:55:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12442441 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 DF1B9C19F37 for ; Wed, 18 Aug 2021 00:57:15 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id C3AA661059 for ; Wed, 18 Aug 2021 00:57:15 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237273AbhHRA5s (ORCPT ); Tue, 17 Aug 2021 20:57:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59174 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237271AbhHRA5s (ORCPT ); Tue, 17 Aug 2021 20:57:48 -0400 Received: from mail-lf1-x12d.google.com (mail-lf1-x12d.google.com [IPv6:2a00:1450:4864:20::12d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35772C061764; Tue, 17 Aug 2021 17:57:14 -0700 (PDT) Received: by mail-lf1-x12d.google.com with SMTP id u22so820649lfq.13; Tue, 17 Aug 2021 17:57:14 -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=s3Vv60zrqT++YyiYanL+6/G2oO/cuU/RaWrweHuPjcg=; b=fx+/BJFxPb5FnS0XPHkrkv8GVMf2mOUi2DX/ZOp9mE+mBJfi1il7r7xzdcrzQcJErD ROVIOZzuKcqX+nctTE9qrOESpTFo8b3pcwW/VvgE/pV9fMgULYa0fhp//bQaxAgRaRUm pW99AJCDDxASyFMVGuI/rX7hgqTv2O7PPmKfvZt0rzh930kwwXXe9jdIZlUPpYF/KIOh vLxVo0P7rZPKJgqq6MjlVK+cITNLWLRYUzKFeMSpFvb5iXKFWRf+SGQF6fBf9SQgBhrN xZoedh3A3vXvUSQ1r9cUxrhAzOogpENZxaPE9IemX+aeAYH/5Sqdmzi19RnUxilEyYrC W0Dg== 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=s3Vv60zrqT++YyiYanL+6/G2oO/cuU/RaWrweHuPjcg=; b=nMtUMJ/qPZCeOPQ7FtI4uwSsXi5GaXFacDgiByXGdj3dXJgnU/pGAEQ5HVp0yPwNSf QpWLQwMRaoXYmu48DnwL/3yJSC+1iuPV7tjYirtB6r2VcRAoYzSkI62gsdg5+ks18sEx k5dqPF4mXAHLRgdQ6xXpT6szTB4tM7rvQ20irdsel0gJOHwokITvAF1eqEYmbtWO7Bmm 8/rTwWzFloKVAbTOM8GAzVtvCKOqkkG5ypormsmEx6gx3HhIHbceQUS3TPhW43sg5ysN 009s8YGsWDwMKjrdhNkmVL85cG/8sf2dfELdkbg6sJTC//Oc5+V57e4m7DrRoUP3ZwGj APkg== X-Gm-Message-State: AOAM531Zu1rz62/B83Bxj2r1U1ZgfV6PLlPeP66IfBG5uX0DE03a7T2P PAemry+tzmOe/hAH0zl9Y7o= X-Google-Smtp-Source: ABdhPJzGr9MXh4M2KzMSknIcRtkfl6GPJENUJYuGpo5rcW+TJEEkwmuLAGPRbIWoz6PPUsXtY3+p3w== X-Received: by 2002:a05:6512:3b85:: with SMTP id g5mr4226680lfv.249.1629248232607; Tue, 17 Aug 2021 17:57:12 -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 h19sm335879lfu.138.2021.08.17.17.57.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 17:57:12 -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 v5 2/5] mmc: block: Support alternative_gpt_sector() operation Date: Wed, 18 Aug 2021 03:55:44 +0300 Message-Id: <20210818005547.14497-3-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210818005547.14497-1-digetx@gmail.com> References: <20210818005547.14497-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 by invoking a new platform-specific MMC host hook that is also named alternative_gpt_sector(). Signed-off-by: Dmitry Osipenko --- drivers/mmc/core/block.c | 30 ++++++++++++++++++++++++++++++ include/linux/mmc/host.h | 4 ++++ 2 files changed, 34 insertions(+) diff --git a/drivers/mmc/core/block.c b/drivers/mmc/core/block.c index 672cc505ce37..8ad1841f0dbd 100644 --- a/drivers/mmc/core/block.c +++ b/drivers/mmc/core/block.c @@ -178,6 +178,7 @@ static void mmc_blk_rw_rq_prep(struct mmc_queue_req *mqrq, int disable_multi, struct mmc_queue *mq); static void mmc_blk_hsq_req_done(struct mmc_request *mrq); +static struct mmc_card *mmc_bdev_to_card(struct block_device *bdev); static struct mmc_blk_data *mmc_blk_get(struct gendisk *disk) { @@ -801,6 +802,20 @@ static int mmc_blk_compat_ioctl(struct block_device *bdev, fmode_t mode, } #endif +static int mmc_blk_alternative_gpt_sector(struct block_device *bdev, + sector_t *sector) +{ + struct mmc_card *card = mmc_bdev_to_card(bdev); + + if (!card) + return -ENODEV; + + if (!card->host->ops->alternative_gpt_sector) + return -EOPNOTSUPP; + + return card->host->ops->alternative_gpt_sector(card, sector); +} + static const struct block_device_operations mmc_bdops = { .open = mmc_blk_open, .release = mmc_blk_release, @@ -810,8 +825,23 @@ 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 struct mmc_card *mmc_bdev_to_card(struct block_device *bdev) +{ + struct mmc_blk_data *md; + + if (bdev->bd_disk->fops != &mmc_bdops) + return NULL; + + md = mmc_blk_get(bdev->bd_disk); + if (!md) + return NULL; + + return md->queue.card; +} + static int mmc_blk_part_switch_pre(struct mmc_card *card, unsigned int part_type) { diff --git a/include/linux/mmc/host.h b/include/linux/mmc/host.h index 0abd47e9ef9b..18281c444bf6 100644 --- a/include/linux/mmc/host.h +++ b/include/linux/mmc/host.h @@ -190,6 +190,10 @@ struct mmc_host_ops { /* Initialize an SD express card, mandatory for MMC_CAP2_SD_EXP. */ int (*init_sd_express)(struct mmc_host *host, struct mmc_ios *ios); + + /* Get platform-specific GPT entry location */ + int (*alternative_gpt_sector)(struct mmc_card *card, + sector_t *sector); }; struct mmc_cqe_ops { From patchwork Wed Aug 18 00:55:45 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12442443 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 B0BEDC432BE for ; Wed, 18 Aug 2021 00:57:16 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 90DD861058 for ; Wed, 18 Aug 2021 00:57:16 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237306AbhHRA5t (ORCPT ); Tue, 17 Aug 2021 20:57:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237271AbhHRA5t (ORCPT ); Tue, 17 Aug 2021 20:57:49 -0400 Received: from mail-lj1-x229.google.com (mail-lj1-x229.google.com [IPv6:2a00:1450:4864:20::229]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 19A96C061764; Tue, 17 Aug 2021 17:57:15 -0700 (PDT) Received: by mail-lj1-x229.google.com with SMTP id y6so1938489lje.2; Tue, 17 Aug 2021 17:57:15 -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=e+PwoAn2TbsYyBgAUnjfJ0mPTEWF4OtaWk/OQ83AcWM=; b=OgIqTjQP/2I6zKJkTHxQkuLSFKrqUuLTgxY0ySO+ixz0jMUFqzcCT9xwsPxRVeLiKj AceLQOQ3vMGT+PU2pteuVzmYf93EIvZeoJRBh/2FjNaktiYpw7WNflnpR/BotzhYSGpB 98jWS9W/kar1qWaeucQN7xYBko4zfdd3Hk1KeqjTXp/DeIkaB5JSXBpn4+h8nlmSlhgr V8+kJaJSczAeEfRjNIy4b5N86aTJtXp+295UQteah/EHX5bNFpRZXehcY1yFbQ+T03iX Zov05ZLQPrRkwhZ8P84I5kQoqhVD5lLT8pS46CvwYKMyvRuVsAtiOumIpO4Ni1mF2Dp/ U4+g== 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=e+PwoAn2TbsYyBgAUnjfJ0mPTEWF4OtaWk/OQ83AcWM=; b=dl15Da78pdw/BAfVVj3hKsxjozdl7/ZCvt/42G0pdLStnb7i/2dA1Au1y6C7Q1QVvd ryklFwEQ31ZUzOc+W9ALvHKeFBsDCFbNihEP0TtEJJqsv4kux70/OQVnWFmVtAAeJE0v EwqwydOawrs8KBnE+60aY8y8oSVz5oDDe2bo/kG7gUJS52LohGIsb+sJhM1s+eD5NZO4 8dB8GJYpWppX13NgRSFPBHrVzcxhWz+ut881pTVBlBe9ugcNd3sP+SevBo9Xj6YuN9C7 9hEulNKTVWWNqvNQ/Zhpa1SpjRVH8a+6jz4Ur3kUzxahpjR4iCUg1uRG8pKce0Y3r/qQ D9yg== X-Gm-Message-State: AOAM532j43Xv31ZfTkfuXPTISsN5LT1hMd6DXXJ7vNVJdA1eKl270QvJ F+iy0PI+Lefow3AooD2voao= X-Google-Smtp-Source: ABdhPJyOKk5m9JTY/i1OECIuQzCEr/YJMBQXB5FhWA1QN/Cfa/eQrB2486zb/GmvIuRiJCqXOrKpjw== X-Received: by 2002:a2e:557:: with SMTP id 84mr5516909ljf.507.1629248233491; Tue, 17 Aug 2021 17:57:13 -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 h19sm335879lfu.138.2021.08.17.17.57.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 17:57:13 -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 v5 3/5] mmc: core: Add raw_boot_mult field to mmc_ext_csd Date: Wed, 18 Aug 2021 03:55:45 +0300 Message-Id: <20210818005547.14497-4-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210818005547.14497-1-digetx@gmail.com> References: <20210818005547.14497-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 EFI 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 00:55:46 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12442445 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 A0A0EC19F3B for ; Wed, 18 Aug 2021 00:57:17 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 8372C61053 for ; Wed, 18 Aug 2021 00:57:17 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237322AbhHRA5u (ORCPT ); Tue, 17 Aug 2021 20:57:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59184 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237271AbhHRA5t (ORCPT ); Tue, 17 Aug 2021 20:57:49 -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 D9491C061764; Tue, 17 Aug 2021 17:57:15 -0700 (PDT) Received: by mail-lf1-x12a.google.com with SMTP id z2so947988lft.1; Tue, 17 Aug 2021 17:57:15 -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=jb8ONuZrLSTX5nrNt5iZbaPVBcdEQEKZDB8VnBowyRQ=; b=fEby/6An7FHD0Mmy6Kb78PCT9cdYLrmqaT67k1qevHu6EwTOmtPmps7blJtVpFOBbM nqdFi1kyaCyOEuPt6Ah8W/D+5aQEfNZaOP/EvPePyyEx2F6cWPrfqQF9LmFtTKtxvi6h v49Q0zth4aW64B03QFb7kcO2lZzKRcqfBiYxU8dPp5pqpOFB+QJhTY78YxPvqLJ5M0Ay +jHKNFgQkf+tFFsUdZudos9vNwRC7t3aU+nugH53qrMqUVJx1hk5kA3hjT+OTIApzoQH vb2rLBIAQHIvHmOaUGNvldioovL+ctv/bp5CxBD4wKxSpOBTo0Qo8qfbBDhQi2s8zev9 ZGBw== 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=jb8ONuZrLSTX5nrNt5iZbaPVBcdEQEKZDB8VnBowyRQ=; b=bqJbKcwsf3Yji+fGvBS0lEE+SsyGdjpM66Ix2FTvuLcZlqd+eflfi1PAsBj90gBl4G cceK2YPFnqADc4tCYqdDRXwXTjwHBS91RmeIIvEODTWSHC8N033vrsv8E7GJAjqEZpV/ GXp9n/DeFxqO6HqloUJ9mXVkI6ATO+fMll4XhHhU4XFVkhT4ln9KzygU7FZpSRFDXIUL gxCjEBPLYc+7Lmn1gkZ1zDcZd1QdX82VuEUP9D7/iJ5JuXY3Eo8vVusAXpjzNEEsoLgu E/kDk9o2fhHG4sz8w+fVbqI6mZFoI7XmLQO4wNjt6HPu687phncHBS2tLIbnjRodZ9Go 6OpA== X-Gm-Message-State: AOAM531muNJQrZCS08h7ADO/iDuObsdwtPFP229M4w5xhPiGfszo3rEZ u2UcMO+AU8/ONj+WswJdLCA= X-Google-Smtp-Source: ABdhPJynee7m2Gi3rS6YccjCsxhmk9gdk3eIOqSz+KU7xgorcTAVU8K1ZJUUmgelnOh3cEgFMx1E6A== X-Received: by 2002:ac2:4c2a:: with SMTP id u10mr4435697lfq.631.1629248234298; Tue, 17 Aug 2021 17:57:14 -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 h19sm335879lfu.138.2021.08.17.17.57.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 17:57:14 -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 v5 4/5] mmc: sdhci-tegra: Implement alternative_gpt_sector() Date: Wed, 18 Aug 2021 03:55:46 +0300 Message-Id: <20210818005547.14497-5-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210818005547.14497-1-digetx@gmail.com> References: <20210818005547.14497-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. Implement alternative_gpt_sector() callback of the MMC host ops which specifies that GPT location for the partition scanner. Signed-off-by: Dmitry Osipenko --- drivers/mmc/host/sdhci-tegra.c | 42 ++++++++++++++++++++++++++++++++++ 1 file changed, 42 insertions(+) diff --git a/drivers/mmc/host/sdhci-tegra.c b/drivers/mmc/host/sdhci-tegra.c index 387ce9cdbd7c..24a713689d5b 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 = { @@ -1590,6 +1596,38 @@ static int sdhci_tegra_add_host(struct sdhci_host *host) return ret; } +static int sdhci_tegra_alternative_gpt_sector(struct mmc_card *card, + sector_t *gpt_sector) +{ + unsigned int boot_sectors_num; + + /* 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; +} + static int sdhci_tegra_probe(struct platform_device *pdev) { const struct of_device_id *match; @@ -1616,6 +1654,10 @@ 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_host_ops.alternative_gpt_sector = + sdhci_tegra_alternative_gpt_sector; + if (soc_data->nvquirks & NVQUIRK_NEEDS_PAD_CONTROL) { rc = tegra_sdhci_init_pinctrl_info(&pdev->dev, tegra_host); if (rc == 0) From patchwork Wed Aug 18 00:55:47 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Dmitry Osipenko X-Patchwork-Id: 12442447 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 421F8C432BE for ; Wed, 18 Aug 2021 00:57:22 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 23C8760F41 for ; Wed, 18 Aug 2021 00:57:22 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S237339AbhHRA5w (ORCPT ); Tue, 17 Aug 2021 20:57:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:59198 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S237271AbhHRA5v (ORCPT ); Tue, 17 Aug 2021 20:57:51 -0400 Received: from mail-lf1-x136.google.com (mail-lf1-x136.google.com [IPv6:2a00:1450:4864:20::136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6BC3AC061764; Tue, 17 Aug 2021 17:57:17 -0700 (PDT) Received: by mail-lf1-x136.google.com with SMTP id p38so1009676lfa.0; Tue, 17 Aug 2021 17:57:17 -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=I01H5a6uHWni87egbbK4J+JI32iz47EYQ+sGtHJn9C8=; b=N6JSsp07CpZCty+GpUO8Ix550NiKbjjfrr3MgQs6vBbp0jeZ2mo4YGpEwCfpOyU2fS XbLBOGzidYQAvvw8vr521Wfpl+G2A0uhBOv5Ao/+qI26ERIW6HSeqZLCqYDifZcjDq7V 9pYnMVA8yeHjOAcvrbyHnCEaB6qUMYtaIpihhyQIVj5zwzxDkX3Ku8fXTkHrxv4yO0gd 4gvZLn8FQk0/6d40xcXz0BDe5lbAZSWFO1PZ8yABdh2ImVq9iJ/txZD2BbBFpnRHtKx7 Di2clJlPnhcSvfIcXGgy8BEivwI85p1b2C8e22q8TlT7KjTgiK9pzkW2eaUG1gSu6aps cQgA== 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=I01H5a6uHWni87egbbK4J+JI32iz47EYQ+sGtHJn9C8=; b=ibwHReew4h90c7iobA+39RBGbbzJllBg5SHAflYA3TcYr+jl0OC/AVw4BxNwQtkT9k olC810k00mCjnf/HJMEz/xVY2WIVOeZX+XSlJVE/SkP+Y2JWV6g/GdsxQ9ij42HhfCvF BJWri+JrHZk7quRN69h0q7SQfT7SZV1VBCdRze6OKn/ab051GTtBWhE8U1IoVtlRBqWg H2v+7GURP6sm4HKYTod+dPiFiJJHp+3W5mUG2UMvg1WadJsHAvqWFmN8tMWW94ej5g2k BBMvLMT3pljQPTLfxixUcBfZrOUA+sXKTX0rbEHe7Zj7HA34BwzTWOoP8igkfYIrqhDw 0JDg== X-Gm-Message-State: AOAM533BZxYgAhdi2c9hyLxWYqt/vr2vMGVQtKAg1xMJliV/H28Qmu+Q JZGQKuKhEHs3nBJtqJl70kI= X-Google-Smtp-Source: ABdhPJyM2Pw5uNedmsQZXhYwx6gDYixKDMuB77RrrxaMT/g2PWwc2DQwvCordjK6ChUFqDanxd6hBA== X-Received: by 2002:ac2:428a:: with SMTP id m10mr4503044lfh.636.1629248235291; Tue, 17 Aug 2021 17:57:15 -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 h19sm335879lfu.138.2021.08.17.17.57.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 17 Aug 2021 17:57:14 -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 v5 5/5] partitions/efi: Support non-standard GPT location Date: Wed, 18 Aug 2021 03:55:47 +0300 Message-Id: <20210818005547.14497-6-digetx@gmail.com> X-Mailer: git-send-email 2.32.0 In-Reply-To: <20210818005547.14497-1-digetx@gmail.com> References: <20210818005547.14497-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 --- block/partitions/efi.c | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/block/partitions/efi.c b/block/partitions/efi.c index aaa3dc487cb5..b9509f445b3c 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,17 @@ 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) { + struct block_device *bdev = disk->part0; + sector_t agpt_sector; + int err; + + err = fops->alternative_gpt_sector(bdev, &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;