From patchwork Fri Oct 1 05:02:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 515013 Delivered-To: patch@linaro.org Received: by 2002:a02:606e:0:0:0:0:0 with SMTP id d46csp454504jaf; Thu, 30 Sep 2021 22:09:38 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxwETMOFlKSMYeTR5w0O2/uZ7IAOF1agXHVCQNO9bR8touNlAwPcbIMA+DgqJHUxtR2nWDv X-Received: by 2002:a17:907:7703:: with SMTP id kw3mr3837136ejc.34.1633064977858; Thu, 30 Sep 2021 22:09:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633064977; cv=none; d=google.com; s=arc-20160816; b=1JnSHnB7OUrPh+61e3XQRQmeS0BdGUDgas3Ve1aSFwkY7rcoHOYEPkr9kJ2t/mDTGN gT6vB2CU1z01+VhfBNtzy8VmQq+49da5Mx5qta6rRLJ7jlQMvFdlpqDJ2C2NPiECoR9B C9EHBDf+8f3ezjs7dQ1nUblM6rBUIq4mmrKS4KTaEp3KIXVctRamSwpXVCct/QrehLUx Trvh3FrxnqJ8j6oM3BZXf7rJtmmGoT0LIFSicqfpf4InEVwHhu2F6kFEnJIIgPdJ5Hpf +YXOJFeW7wY2c8a1IouKrzDhihBz7PqLp3A0m44ObE8gNpYUMWOmVqOnSnV6ICc5WHYg j6jw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=LenLxMm4jJHe2glN2La5lemFNR7mrKrC7NL+E7b7ypg=; b=D9sBseTzmWRN5DZGVTqz5ayuo9kiDkfGsKdg1775mSLhbmpWeR8ri+JzDx9OBvsUQ0 W5aMWjxmhSj7frkQZZPy8JkqKnDgt2oIJ0fgOR0QPi9+4nQtogJaAQxKJiWHLLK6orI7 MAtBwAuIQqb4qY/Tjtj7tgUHfo5OguTy+M8ayez+rms18qAB2EVBtZD7rzQCZM5EOn3g da0+Q7mgLHOXLXl+NEVaIIbmJ2hC/Aaw+YcqgpiouwGmLjLG7dNuxaj0E6f7ksaJQ+AP JNz3IxSVrMQEVcMIXKFIpyr3YtyzbU4+acaFLFTSBg59HzKitKluXp4vPEJ8FNYa7A4t uSvg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QtsTXHzq; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [85.214.62.61]) by mx.google.com with ESMTPS id i25si6742175ejd.625.2021.09.30.22.09.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 22:09:37 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) client-ip=85.214.62.61; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QtsTXHzq; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 85.214.62.61 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 5507B82EBD; Fri, 1 Oct 2021 07:05:40 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=u-boot-bounces@lists.denx.de Authentication-Results: phobos.denx.de; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.b="QtsTXHzq"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 9CEAC83165; Fri, 1 Oct 2021 07:05:04 +0200 (CEST) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on phobos.denx.de X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) (using TLSv1.3 with cipher TLS_AES_128_GCM_SHA256 (128/128 bits)) (No client certificate requested) by phobos.denx.de (Postfix) with ESMTPS id C0FFA83423 for ; Fri, 1 Oct 2021 07:04:54 +0200 (CEST) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=pass smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pg1-x532.google.com with SMTP id e7so8381440pgk.2 for ; Thu, 30 Sep 2021 22:04:54 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=LenLxMm4jJHe2glN2La5lemFNR7mrKrC7NL+E7b7ypg=; b=QtsTXHzqbNuD/xqtLyTiuS9IBDQUftcS/hO6qrzn1d2UCHbbCI3CrBa/YUxoHe98HJ 0K2wsyX94HGT5l/aem9GXPNGDjVmIiimPchMyWYM0xwPY52S/ToTa/BibnH8xiHG9qUC qI6OEx9CuUXZMxV5mn/6vw7wakCtczeK5Bf9/7jjmSea8WtO9OHPQLZvu+LijGStrHF1 qaPoenOGAWB1UQKq5gebPcXl9yhP81kLUO1YUxIlx0wfZVFAY50U6lssilE2NdAntQga QAjeNaAZq+gyahboZyCpaNwVpO/PChld2DbQZP3yMQPDdDtQi4/340JFcMSU8dQWhcNH ETKw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=LenLxMm4jJHe2glN2La5lemFNR7mrKrC7NL+E7b7ypg=; b=IPRO6gIJytiZIkox0HDzIPxu7nxAXCtJVc46sx21m00/jhyE4yBj1K9E86Xz1huD2T f+MSf2mu2frJlJ4WJTMPl27zQqq2PUk6QJtOV/IQcmYg/63IgrJnwisLU2lKaYK8dLSB WI944DJYAew1qPkX9i19Wj7HQOg65r/0X3GUYWZmchydpvABx7gXGmXWVbHqU4I+eCw3 Hsf7C459xsIXO5PsakQCePi4XsV/geg+IFp5RrBDeyDWatZD8sk7ZF/gB2Puca3l5/zk mhR6kTqV0+SOtXhqQC2AZa611GuVFLkXskSI3c7UeDqtMA/xkeZk6C+P2JJ4qYCIc6mE nA+w== X-Gm-Message-State: AOAM533EOAY/7oLG4zrmspMGnxzQbVjKEoFo0KHtR3QkBomwkF+0QDll WH9+M111Emllu40OT+StvJJt+9VxtdBHfQ== X-Received: by 2002:a62:8141:0:b0:447:96be:ac2 with SMTP id t62-20020a628141000000b0044796be0ac2mr9245657pfd.61.1633064693024; Thu, 30 Sep 2021 22:04:53 -0700 (PDT) Received: from localhost.localdomain (122-100-26-52m5.mineo.jp. [122.100.26.52]) by smtp.gmail.com with ESMTPSA id z8sm4615113pgc.53.2021.09.30.22.04.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 22:04:52 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de, sjg@chromium.org, ilias.apalodimas@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [RFC 18/22] efi_loader: efi_disk: a helper function to delete efi_disk objects Date: Fri, 1 Oct 2021 14:02:20 +0900 Message-Id: <20211001050228.55183-37-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211001050228.55183-1-takahiro.akashi@linaro.org> References: <20211001050228.55183-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean This function is expected to be called, in particular from dm's pre_remove hook, when associated block devices no longer exist. Signed-off-by: AKASHI Takahiro --- include/efi_loader.h | 2 ++ lib/efi_loader/efi_disk.c | 54 +++++++++++++++++++++++++++++++++++++++ 2 files changed, 56 insertions(+) -- 2.33.0 Reviewed-by: Simon Glass diff --git a/include/efi_loader.h b/include/efi_loader.h index 50f4119dcdfb..7079549bea70 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -519,6 +519,8 @@ void efi_carve_out_dt_rsv(void *fdt); efi_status_t efi_console_register(void); /* Called when a block devices has been probed */ int efi_disk_create(struct udevice *dev); +/* Called when a block devices is to be removed */ +int efi_disk_delete(struct udevice *dev); /* Called by efi_init_obj_list() to install EFI_RNG_PROTOCOL */ efi_status_t efi_rng_register(void); /* Called by efi_init_obj_list() to install EFI_TCG2_PROTOCOL */ diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 74ef923d1d67..dfd06dd31e4a 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -574,6 +574,60 @@ int efi_disk_create(struct udevice *dev) return -1; } +static int efi_disk_delete_raw(struct udevice *dev) +{ + efi_handle_t handle = dev->efi_obj; + struct blk_desc *desc; + struct efi_disk_obj *diskobj; + + desc = dev_get_uclass_plat(dev); + if (desc->if_type != IF_TYPE_EFI) { + diskobj = container_of(handle, struct efi_disk_obj, header); + efi_free_pool(diskobj->dp); + } + + /* + * TODO: Can we use efi_delete_handle() here? + */ + efi_remove_all_protocols(handle); + + efi_remove_handle(handle); + free(diskobj); + + return 0; +} + +static int efi_disk_delete_part(struct udevice *dev) +{ + efi_handle_t handle = dev->efi_obj; + struct efi_disk_obj *diskobj; + + diskobj = container_of(handle, struct efi_disk_obj, header); + + efi_free_pool(diskobj->dp); + + efi_remove_all_protocols(handle); + + efi_remove_handle(handle); + free(diskobj); + + return 0; +} + +int efi_disk_delete(struct udevice *dev) +{ + enum uclass_id id; + + id = device_get_uclass_id(dev); + + if (id == UCLASS_BLK) + return efi_disk_delete_raw(dev); + else if (id == UCLASS_PARTITION) + return efi_disk_delete_part(dev); + else + return -1; +} + /** * efi_disk_is_system_part() - check if handle refers to an EFI system partition *