From patchwork Mon Oct 4 03:44:26 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 515146 Delivered-To: patch@linaro.org Received: by 2002:ac0:890a:0:0:0:0:0 with SMTP id 10csp1062732imy; Sun, 3 Oct 2021 20:48:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxhTJtdEf0QqyGyrXLe4QNAV3q3kjcRe1peb6FbOiyCGWVWIHWODPmssuHmQxgewGwQJ6sW X-Received: by 2002:aa7:cb03:: with SMTP id s3mr13264025edt.334.1633319305537; Sun, 03 Oct 2021 20:48:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633319305; cv=none; d=google.com; s=arc-20160816; b=nGZJHRX60ADgZR89B2lC5SA2Csbsa85SESTgtx9wqpMLEqQhNtCAuQRqaIW5HYQq8n tOtB+ruGVExl0IpaXVgQL86Wz4rYoJmVOjn1a8UYxlgkohIwbSQH2YomZEDjKVAy+rBD iUhL/bwLv3HTrLl0Qq0Hu42dojFbRbs/cNZmFdbLnUICM2QsTh4crVQ9dyU6rWNcvhyW 2NSrHrLkf/iwq2OxhvPYbip3HtsHj4I5M7bBmau+HDZeF2j0Dp/w/sBBgADB5p2XC9Nu bBqoVNMgd1c+FONtWYCCOYZMTc90A7kLbmxMFO/gmhYfV0SW1PFRPotTX9203Nc5pMJS yEqA== 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=r4WMHXVR9bdfZhzpFrTZ3+fQvyDk44Wck5P7ISb1GB0HEP/l+TnQvZz2BVpvo2e9eV lTGLgRy4zWK3k2zj3OqqS+e7LNUGk8KGe+43p8WPJXf6Owg11BObJty1GnDCpgjph6sS qgorCCx7Gk95c5O81o9PVtV6of3QnIcrJE6+l/end7cmhqr91YJEBVwS+eW5/wGmTtBW YLAggoe8Y1rlDuCmkjzL3jDzi0MDnQjKLBogTJu2z0wERM/9L00CKRKODteZKj0KDVEb WBNTHKDKRjhHyLa77PAqWZO2FjjlgmotGzfER61mh4lTXxkHDeIDjbsC4KB2wn9lx8Zc dRPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gIcin2uz; 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 l9si8532703ejz.88.2021.10.03.20.48.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 20:48:25 -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=gIcin2uz; 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 74814835B8; Mon, 4 Oct 2021 05:46:59 +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="gIcin2uz"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7A61E83562; Mon, 4 Oct 2021 05:46:37 +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-x536.google.com (mail-pg1-x536.google.com [IPv6:2607:f8b0:4864:20::536]) (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 8333883571 for ; Mon, 4 Oct 2021 05:46:28 +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-x536.google.com with SMTP id 66so14840239pgc.9 for ; Sun, 03 Oct 2021 20:46:28 -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=gIcin2uzSoVjZBQDp8cNh9GnIht43SN3L+7Vdh9AYRB5K635xijk1H2fosP3UbpoDU aRWvpRZZHO0ZslHXsOHJOIFj3SK1uu96fajCwI5GclIEa76QGXxk2HqWlwG2+qNqPeHi W+MNYsFXYm6WqqmuxdtOJlcmZJ6n/3gd9ol9P0uxmdlsBuoKeAtY8aGIzKn95AYcFp3r 9r6O7Je+By9N35HcJoB2W4KAgmfFf+a7pQRzy1HwPnfobr740UIYEbzSxH1Ela5wwK7i g1BKQ5a2YJLnWoJXYCo5UEgF99d6Q7auzw1X5+bJJTFVo8VxJcoscx/yIRsV1qIpqSYg oySQ== 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=V6TtW0aeLMZAT2w79bxWUlKI1G86jsnLhsDgGSw887r/51Hy1bOsAz21QlDm1cXV26 HPRROKNCZzcPcQlhDGTrN68/SHo68mpvMiDLBiAWq2WaYLe0AlBo5EVbhf1oE7JQirlS mtpZPZNh63UPzPkr35CkEVvBYquxPmRB7k3eWBwHaUaR3sFFJQd2oQHDMzSci1sJAFUJ qJEmKbfDIv4Nen0WYcIUiewjEMx9Ubm1h27QatjahBGX6h1oS+X0bORPpYBSDn/IkGvI PUXGJ+vw+gAr8wNnugXHutJqJAbJxBPGwhkFsP6ZPjv6ihlfYwGc5m51U3DlrJcEauIN gxcA== X-Gm-Message-State: AOAM531VD97sfdVA/0jnJkNynyV/qybnDKpV67kDR710BWB33VlXnXar Rpd7pk12PSSkstpbEDF9DJdPLw== X-Received: by 2002:a05:6a00:9c:b0:448:603f:720b with SMTP id c28-20020a056a00009c00b00448603f720bmr23014636pfj.66.1633319186696; Sun, 03 Oct 2021 20:46:26 -0700 (PDT) Received: from localhost.localdomain (61-205-96-147m5.grp4.mineo.jp. [61.205.96.147]) by smtp.gmail.com with ESMTPSA id a11sm11863515pgj.75.2021.10.03.20.46.21 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 03 Oct 2021 20:46:26 -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: [resent RFC 18/22] efi_loader: efi_disk: a helper function to delete efi_disk objects Date: Mon, 4 Oct 2021 12:44:26 +0900 Message-Id: <20211004034430.41355-19-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211004034430.41355-1-takahiro.akashi@linaro.org> References: <20211004034430.41355-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 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 *