From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 95854C433EF for ; Fri, 1 Oct 2021 05:09:20 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1042961A55 for ; Fri, 1 Oct 2021 05:09:20 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1042961A55 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 1F6F483490; Fri, 1 Oct 2021 07:05:32 +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="bF49bRai"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 2CF49832AF; Fri, 1 Oct 2021 07:04:56 +0200 (CEST) Received: from mail-pl1-x629.google.com (mail-pl1-x629.google.com [IPv6:2607:f8b0:4864:20::629]) (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 D14AC83473 for ; Fri, 1 Oct 2021 07:04:47 +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-pl1-x629.google.com with SMTP id t11so5527162plq.11 for ; Thu, 30 Sep 2021 22:04:47 -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=bF49bRaieTvGC80xcjigmd8JFAEdyenGa+SD02isLTfa07x237hq1epMR4FQcui7yh EiTkpnkOKoYkZA87WA3piL63b53fxfKp9e119NxRaO0uI/gLcjhCfK+2qVgx+eQYSE7F cx7GFh0CtTXSRLaR+hBer8A8NCc0Fs0XcY32qoMOSXAdTWXKeN0zf9ls5K6qdYEilsjQ PWtayyPJ7Yw17iFbPjQtlf/d3+bLz91lLI5swiEMHMCF4HLeP6if24XP+59RzSVgq8jq JNf9KOvFwyQm0tmxp3yQ4EuogGci24fkRMmUgjqcTfv7j/mauNph29tF5dqE89SqVY9m H7EA== 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=TCysak3wh206deoVIkDnN+thfUIA25aAwADgkOzmxNlR8hxlfzSrbsyV3r8NP97TxY YvNO+QrxUAG5N+NGV5f+XW9dIbk+A8KpdQ9BeVxjXfCPXzaUE3+23DvmcNYNKA44FxAi 6LaGULtmKgeqIGtb+H1ed9I8rz4GOmT1rPEURyy1HvQWBBk8aMz57W2mNfnBdrnueGvU EAZJR/NeOJYYdadSgyE9t4IFzpV3FVBD3DXsYcudaWZiuvzptAy1iXNlenP0Pv9vo5PR qCxgV8mvBGgHdnN3DpO+ZO1f+Bozg+L/yoeAzudyAmRD1gH8xUypquXTX3WkIBNfdKlc yz7Q== X-Gm-Message-State: AOAM533dcLBo37NravOf+dFPcUN2ztDidgDBYIkOOQrPOB5ISoQUox7Y X8T+8enJT3SUUgIm0IiEo4Q0Bw== X-Google-Smtp-Source: ABdhPJzBLrxwMTMVeeCWAEYOp/6zlt7Hl9EnI4cz4KZyhpavkA1LsiIGqxuxNXywJuJv6MfJ9ZJY1w== X-Received: by 2002:a17:902:6f17:b0:139:eec4:867e with SMTP id w23-20020a1709026f1700b00139eec4867emr9055503plk.77.1633064685997; Thu, 30 Sep 2021 22:04:45 -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.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 22:04:45 -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 17/22] efi_loader: efi_disk: a helper function to delete efi_disk objects Date: Fri, 1 Oct 2021 14:02:18 +0900 Message-Id: <20211001050228.55183-35-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 Content-Transfer-Encoding: 8bit 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(+) 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 * -- 2.33.0