From patchwork Wed Feb 2 01:08:49 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 539315 Delivered-To: patch@linaro.org Received: by 2002:ac0:f7d2:0:0:0:0:0 with SMTP id i18csp1192794imr; Tue, 1 Feb 2022 17:13:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJw41eAZVRRvLJddgqXTqFie44odXxTLEmiy6RLuk6Bu41+BqDK9meIcY3E9fu/vJ6xQImhQ X-Received: by 2002:a05:6402:26ce:: with SMTP id x14mr23667245edd.211.1643764408125; Tue, 01 Feb 2022 17:13:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1643764408; cv=none; d=google.com; s=arc-20160816; b=lRaPMQ/0M2ouURGSgvvsi9vy/zUv5cgbNGij22ikOj21+OZpOsJlegthvWAitL5x4g gs9REUipbhiePM2j+DEqGBNmQpJPXvofX4FcZIqwFZnZDZSOliZRe10Cl1xxVaFfgPsO jtRR0UQqlacBR9clieCvfejOeTczTXGRzYU60mv3XIWCbYpxKpC2TxpZrsLXUkjRl0EW 3MOptXEgkyPb/w7EKSmvBYa4Gvgl3/EXtyP1phjCyQffMZmRwAgzj7Wj+E9jeb3Rezsf snZxLghQiH2VEN62goMX0sBwLr/KpA9LQiqa50oBPta8B08aV54EMiH1tsKfYYp/1JAI z9ug== 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=scQDk7CU4Htpi+80mL//SWDOEq0M+vsnaakCV4qH5zc=; b=N0RX7+NJYrb7qf+eIMUw0fnI6ol4ZN0W6Vn1MWY4BVL/QanM/0rbRWKGLoW5qwh93L cy/e1S6vz92MtvlLd62AsfrMu/xBHfxRV1QQkwBNEjVDIIiqUXtYHbu3fgCacyj8+VhW 1J4ae0n1Kmk7FDeTqpX3a6grEpeeImSGGuHPvRawiGRhuQoBRqzb9UgiB6RxJwCN51JN Xfwbazmmv0nbHfpHidXJMNyWf1jzkhfJDDoXARY206prNbxaiKf5LB3bkmjIZCrdEPHK +zoDb+5a+lD6D41KbWf15YHtmAYrACtFODuTxKef6pDyEimDrDl9b+fApkFrp2UrEpwl IbZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ux1Kvod2; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id hq3si11511452ejc.417.2022.02.01.17.13.27 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 17:13:28 -0800 (PST) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=ux1Kvod2; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 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 11C9083910; Wed, 2 Feb 2022 02:10:36 +0100 (CET) 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="ux1Kvod2"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D9621838AD; Wed, 2 Feb 2022 02:10:32 +0100 (CET) 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, T_SCC_BODY_TEXT_LINE autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x102d.google.com (mail-pj1-x102d.google.com [IPv6:2607:f8b0:4864:20::102d]) (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 781E2838FE for ; Wed, 2 Feb 2022 02:10:22 +0100 (CET) Authentication-Results: phobos.denx.de; dmarc=pass (p=none dis=none) header.from=linaro.org Authentication-Results: phobos.denx.de; spf=fail smtp.mailfrom=takahiro.akashi@linaro.org Received: by mail-pj1-x102d.google.com with SMTP id z10-20020a17090acb0a00b001b520826011so5187851pjt.5 for ; Tue, 01 Feb 2022 17:10:22 -0800 (PST) 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=scQDk7CU4Htpi+80mL//SWDOEq0M+vsnaakCV4qH5zc=; b=ux1Kvod2N77ImLHStv5f8CSCDKY05nUpQFF9FAV2mYLnZiOA+PRFBo6r49OCQ+3jxj b4jL2PWhOn/Z+ezH3VcmM/ORdyezyV2iyVmquB5+XqgyZoaVsF9gKdrtJT4uRAoneEtF ZWkT9vVUwEdHDHRP5FeF0sZMI91wk7yJ2qxe5wFNj+P84mH79xGIKC9S+6gxDJKIW5G8 Bpzq5fxo69Q+fXgEmV2+Tvw86CTquglt9+J5nwH5aeRZltywGgVtmLWeeaWP4r1SLfZA 2dP5MzTpd83g33Kgbztsb0zss/4Ai/cavgYmHHIfMpEuzo4ykEv7c6uLNtV6FVLyeyZH YarQ== 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=scQDk7CU4Htpi+80mL//SWDOEq0M+vsnaakCV4qH5zc=; b=f1cLLTsfpKSkJ0TCwYiz+KBS2aX8cKpNPVmJ1F2s14d5vaSFPNE2k+AkZA6pZCLsfG vDL6tzMXqFm//LnxEibpfsb3aC1FFXRFe3+xgnTNi0HUmzRdpcmXwXQf1dK2lTPA+N7P s2rXp3vAo5uYeUZ/pMiTzs1OpsIE71Ud9xqf43vEp4DEAQwdZcxtPw57dEQbOuijSSeh UY7igfXE+dBE0lueLoUXaDvMTLd+3+drwsF6Sr+ny6YpwGIJEHhg9pgLYuzdj9Sw/8Zw A3wGugovAY7OPCYCwBZN7ttlAm/T1KHu+zsMseSiMvacZc7FmS2Q52lIH0X+h/J+sjja ygWw== X-Gm-Message-State: AOAM531odBaDG59ppReHCQFD/F9BvY8ViBesu1YRbntjWDQKXaC+KzEv 9wKw/xhMI4PPxPaRGyh95oXhrQ== X-Received: by 2002:a17:90a:34cc:: with SMTP id m12mr5509866pjf.24.1643764220875; Tue, 01 Feb 2022 17:10:20 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c3e1:100:314e:b83b:fa90:7f2e]) by smtp.gmail.com with ESMTPSA id f5sm10761429pfc.0.2022.02.01.17.10.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 01 Feb 2022 17:10:20 -0800 (PST) From: AKASHI Takahiro To: lukma@denx.de, peng.fan@nxp.com, jh80.chung@samsung.com, bmeng.cn@gmail.com, peng.ma@nxp.com, sr@denx.de, xypron.glpk@gmx.de, sjg@chromium.org, ilias.apalodimas@linaro.org Cc: masami.hiramatsu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [PATCH 15/19] efi_loader: disk: a helper function to delete efi_disk objects Date: Wed, 2 Feb 2022 10:08:49 +0900 Message-Id: <20220202010853.40405-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220202010853.40405-1-takahiro.akashi@linaro.org> References: <20220202010853.40405-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.39 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.5 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. Add efi_disk_remove() function. This function removes an efi_disk object for a raw disk device (UCLASS_BLK) and related objects for its partitions (UCLASS_PARTITION). So this function is expected to be called through driver model's "remove" interface every time a raw disk device is to be disconnected. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass --- lib/efi_loader/efi_disk.c | 88 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 88 insertions(+) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 2941b0c3db47..8dc7534278da 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -632,6 +632,87 @@ static int efi_disk_probe(void *ctx, struct event *event) return 0; } +/* + * Delete an efi_disk object for a whole raw disk + * + * @dev uclass device (UCLASS_BLK) + * + * Delete an efi_disk object which is associated with @dev. + * The type of @dev must be UCLASS_BLK. + * + * @return 0 on success, -1 otherwise + */ +static int efi_disk_delete_raw(struct udevice *dev) +{ + efi_handle_t handle; + struct efi_disk_obj *diskobj; + + if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)&handle)) + return -1; + + diskobj = container_of(handle, struct efi_disk_obj, header); + efi_free_pool(diskobj->dp); + + efi_delete_handle(handle); + dev_tag_del(dev, DM_TAG_EFI); + + return 0; +} + +/* + * Delete an efi_disk object for a disk partition + * + * @dev uclass device (UCLASS_PARTITION) + * + * Delete an efi_disk object which is associated with @dev. + * The type of @dev must be UCLASS_PARTITION. + * + * @return 0 on success, -1 otherwise + */ +static int efi_disk_delete_part(struct udevice *dev) +{ + efi_handle_t handle; + struct efi_disk_obj *diskobj; + + if (dev_tag_get_ptr(dev, DM_TAG_EFI, (void **)&handle)) + return -1; + + diskobj = container_of(handle, struct efi_disk_obj, header); + + efi_free_pool(diskobj->dp); + efi_delete_handle(handle); + dev_tag_del(dev, DM_TAG_EFI); + + return 0; +} + +/* + * Delete an efi_disk object for a block device + * + * @dev uclass device (UCLASS_BLK or UCLASS_PARTITION) + * + * Delete an efi_disk object which is associated with @dev. + * The type of @dev must be either UCLASS_BLK or UCLASS_PARTITION. + * This function is expected to be called at EV_PM_PRE_REMOVE. + * + * @return 0 on success, -1 otherwise + */ +static int efi_disk_remove(void *ctx, struct event *event) +{ + enum uclass_id id; + struct udevice *dev; + + dev = event->data.dm.dev; + 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 0; +} + efi_status_t efi_disk_init(void) { int ret; @@ -643,6 +724,13 @@ efi_status_t efi_disk_init(void) return EFI_OUT_OF_RESOURCES; } + ret = event_register("efi_disk del", EVT_DM_PRE_REMOVE, + efi_disk_remove, NULL); + if (ret) { + log_err("Event registration for efi_disk del failed\n"); + return EFI_OUT_OF_RESOURCES; + } + return EFI_SUCCESS; }