From patchwork Fri Apr 15 07:15:43 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 561945 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp115749map; Fri, 15 Apr 2022 00:18:00 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxy4BreEX06gbIF2CAPU0UP+wm+2TxYcbyNCAVXt826+QAunWGH5wr2V89O+HiJTYzNVhtS X-Received: by 2002:a17:906:d54b:b0:6df:7cff:42b7 with SMTP id cr11-20020a170906d54b00b006df7cff42b7mr5234662ejc.731.1650007080064; Fri, 15 Apr 2022 00:18:00 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650007080; cv=none; d=google.com; s=arc-20160816; b=bP3SDvyZvFg88qxnWqiIKOpsLkBqZLN0n6UsJn3h6N6WicpuNPUPxh6tI9eUhpm27w JItG9nmcapYPdPiglFwDG+TR9gavc948EIyTqvW2RG5X412kX+7RCvlkycITd+2MLuco Bsc3I7GkJzbMt+mbBzgH8jCSBftveFLqy6U9xybLYKD9kiQ/QfN5iG8CUmg2w9RL769K VW+WpQ8ra1g0uba/Ex+84s74e+3JOD7xiVWFxHrPdUkLMudlLnPRGQJ0g4HHpJ9pUcGY l0cSBXVopxSfB9tZplz5dwHbiNPiDUm/Z7pDNarMHcj0oh7V4ihUHX/qV4JqjSJcGTu7 PqDg== 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=us55YGuTJDqDpqGBbF/SZgDLRcXZhwzXbRwbiam3AVQ=; b=GWoDVIZTmstMsJR3XFg3+gBYfV4C6KqB4qpMrC4s8Lwvy755VWQGC+jdvA4JV8OXIA HN3KGgWFeK+KqeoFncnzu1p9R1keLLLlv40iFVurcEteKfHfWch0k7jqDHoXp0jiu7CR N+2SIV8UlOT52lsGWVkDMg55tt5YP4gIFe9E6GnW4ehXmd7KuwFxf6rWGaikiRLOVLEF MB+1mJnsc+u0MHsjWicVBQE+U9euU0p6ej3QOr7BQpBBQTP7EjJz+Dj4bqZdxYkC8ysE /g05bP/CnKSZ+3/HPp3XFaQ8vI8mK8UBPOmu/E17O8OmYhd9jV0GadJSz4fo4EWtJtwG gngA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=jR5pSG9s; 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 oz16-20020a170906cd1000b006e8c12d426csi478079ejb.1002.2022.04.15.00.17.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 00:18:00 -0700 (PDT) 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=jR5pSG9s; 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 8F60B83DEF; Fri, 15 Apr 2022 09:16:50 +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="jR5pSG9s"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 5A83583D9B; Fri, 15 Apr 2022 09:16:40 +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, 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 80D9683BF6 for ; Fri, 15 Apr 2022 09:16:37 +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-pj1-x102d.google.com with SMTP id bx5so7024647pjb.3 for ; Fri, 15 Apr 2022 00:16:37 -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=us55YGuTJDqDpqGBbF/SZgDLRcXZhwzXbRwbiam3AVQ=; b=jR5pSG9sV1qT0Wyxp1a9gwgl0i5jymBAhI9DJAhrAHDyzvxidauJw1ugQxWI56cg6k U1nRyQuoKzcb8LApVD5xtHI6RMq5A5g9Omz/ktwblKLH9FXBfFOdbExxhSYonLu4NkfS igY9JGHpq+bo/dGegf+KuncBqRF0xA51OmJXg3zFYlAOdEisgwpFNTOyNucmOq1//PBY d3xXVcaJoj2trLoGqw5aVMyaeFGe9Pd1KAssseWiKwppetMW2HV2WFRm4Y1I+O4JJVoL NxJOgSEDnjexZKxvFsmdQRf1CeXN0hJ7/Y5Ny6mVMxV7Ux5KeE2KgJLDegK8h10WWR1b bGYQ== 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=us55YGuTJDqDpqGBbF/SZgDLRcXZhwzXbRwbiam3AVQ=; b=7kSgp9IYX7DdsG3fiirJjlWPtkjJHJK8uwfEXeD5c+NpJTUJloP+5hNtxnGy6tOMA1 BO1D7seZJwENwO5EBhFBNjbiiOTwu44EBHUlYIr5oT0DP8D06+YBZ8Uv0E+YhdB0hHPO o9IHs71F3G0RnWsiipzR3yI5IbTFc8UJ0o/tTpl7e8Mu1pljXW5y5ROWtGETAT85qbeC pnWJJ7X5epywqspJ9EWY/XeGinTfQGxLZKOz80JQAs37OqNfoZHm0z8vB36/yil7MpIq /S/0EdpMeFhI8d7wCZBV2wT0WIy2cEbqYsOTrGvMz1ADU2yYOr/AgJrf38+pW5FjHBWk ogLg== X-Gm-Message-State: AOAM5314k5nNCezoMCDko1+koVOGSWxUIabgYDr8t1zqgopMYCz+YkoM FDhczAIvs3RNbAQXzrKPcQ0uTg== X-Received: by 2002:a17:902:f612:b0:14c:e978:f99e with SMTP id n18-20020a170902f61200b0014ce978f99emr51196232plg.23.1650006995898; Fri, 15 Apr 2022 00:16:35 -0700 (PDT) Received: from localhost.localdomain ([2400:4050:c3e1:100:18f3:1e4:6c4:6ea3]) by smtp.gmail.com with ESMTPSA id p1-20020a17090a0e4100b001ce188720e5sm3566921pja.53.2022.04.15.00.16.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 15 Apr 2022 00:16:35 -0700 (PDT) From: AKASHI Takahiro To: 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 v4 09/12] efi_loader: disk: a helper function to delete efi_disk objects Date: Fri, 15 Apr 2022 16:15:43 +0900 Message-Id: <20220415071546.122475-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220415071546.122475-1-takahiro.akashi@linaro.org> References: <20220415071546.122475-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 037f8594a727..940390ac8bcc 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -635,6 +635,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; @@ -646,5 +727,12 @@ 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; }