From patchwork Tue Apr 19 01:05:14 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 563301 Delivered-To: patch@linaro.org Received: by 2002:a05:7000:6886:0:0:0:0 with SMTP id m6csp2860785map; Mon, 18 Apr 2022 18:07:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwHq4sp0MvXNk0lCrzAAey+ciCPOa5SfZa414tlV4HWwRBOYw/9CoMO0HI4NYx2Gk44geqK X-Received: by 2002:a17:906:3ec6:b0:6e8:8534:6765 with SMTP id d6-20020a1709063ec600b006e885346765mr11226476ejj.110.1650330429398; Mon, 18 Apr 2022 18:07:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1650330429; cv=none; d=google.com; s=arc-20160816; b=V85rbcztFlcouWoOM/4lIEffHcUlPc/VUxKC3omYxXilYOvnNReE7jIxGx4Ug6ztA9 wexircXxnfkSLG9GVYTX1fiKbpnA3eoyjxfvkf3fhUNTkl/MPFWaszyvahCL+oUCQ2cY ODBlSjkGG8Zsa1WDzx9PfIhBr0uRvllhGRhOVM0Hy9mtwYIgclqVctXKvg06aDcemyB5 3iQhqFkvXFikj3tgXxTXX00LiYjLTB84sUacp4ZElV8/Oy1NpNJ2LoueasJ+OXO37JNg 8gTJ5nMapwYDN1lZ8jPtD6KGdCMcsVvKZdyvOhXiH4SPvlGOFPmLOpzZZFEy3HfqJ9og Bc7A== 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=R4/d+lKC2g30MsZHNXqvyLSXFngH6asqdeHzZF0J6H3L9ew9d35B5QedmS1cEENKju 5Ox4CbVBo/STHjzPCmPKe3SQSJeHc286ClRf3kRpB5g9yag1H3V4Q66CxzGrqmYNMuPX myEsuAV2+lICkEyq6a9wo+wr4SFE1WoQDXQ+eO1dUGkilogTFCnPBnPD4GnV6rbIJ8ht nMQgWohQZuRe/mLDrXfxXNiHB8h+gHrKt011MrsDTyI4YvIvhOfQ+gU0hnuY3xPoAYii sKlOOsO+kV3/uyrjGi7Kk123u4e0PYTfrFMM/mIa71XMpxFqk9rWoGvWO0Qp+va0Yvwb 1PXQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=fZtG1bbE; 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 d3-20020a170906c20300b006e88cd8b684si8044489ejz.727.2022.04.18.18.07.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 18:07:09 -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=fZtG1bbE; 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 9E7B683B11; Tue, 19 Apr 2022 03:06:44 +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="fZtG1bbE"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 4CAD783D07; Tue, 19 Apr 2022 03:06:11 +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-pg1-x52d.google.com (mail-pg1-x52d.google.com [IPv6:2607:f8b0:4864:20::52d]) (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 5A46C83D61 for ; Tue, 19 Apr 2022 03:06:01 +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-x52d.google.com with SMTP id q12so21956849pgj.13 for ; Mon, 18 Apr 2022 18:06:01 -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=fZtG1bbESJmXp63uxh/ba0/tGfW6IxEeZKtR3krYgGFOMfnUPQv+nCiVqgw4KaftW9 wFi4Ex21O81nboMlH3/18qbxVzVKC5tKNghmywQLIFaZUu9R07Qy30tlr5IiLov0H20k isu7DfQzhYa/s5bts7teg6ny6FXA/bPRrEfJSsY6x5k6teIXRMesYITVqeD6+uPbxcKs NPGuMM6EcPrFy7HH64UZp5mFdS+TqCtg3x9s42eyhMmPdUB9jBn0uzU5fjQOV0cDoJC6 buy6wL6DrESzUHu1Yf9LwH8MBEc900TFs7IfANyjZA+FUjOoaPSuRsIu1ptg7ZtBRPGV kimg== 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=MQ/O9wcUCpeSCaAocSpaS6WFcxtMu5NUGsyIXc0BXvUvMw+acToS9hyxhTij0Ozvm6 4Pnd4kJV9unCUn9dykJPK9Ug58iU0PDn77VUNfGgLMspAGYI755JlTZH/XQySqnF2NRs PBH1ZnsGxiXA/L2OR82wGSDumqxi6lnJOapeGRL+0urTOVWI7satGpUfM1GFVuFkYsEP GOiLnT37vAbufPGg6N0ax5ar72GUGydEMEqEXBMW28RUbKO6Ig6tANJuhj3pKNvIY3YA J259GthJKS6wfe7NjgWSg/cU509nlKWvp0FoHvIU7GFpjWMGADnHceK87ZwN1BhzyFxI c78Q== X-Gm-Message-State: AOAM531HfcURW/fdrZFVRvcidoyAdvyh4o77XV2gKxKBcY+4MR3pk5Uq +E13pKQqpltiMdwdLBe/Gr4Ayg== X-Received: by 2002:a65:4503:0:b0:382:aad5:ad7d with SMTP id n3-20020a654503000000b00382aad5ad7dmr12438436pgq.488.1650330359686; Mon, 18 Apr 2022 18:05:59 -0700 (PDT) Received: from localhost.localdomain ([2400:4050:c3e1:100:5858:d3a6:5cad:ceeb]) by smtp.gmail.com with ESMTPSA id k137-20020a633d8f000000b0039800918b00sm14043756pga.77.2022.04.18.18.05.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 18:05:59 -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 v5 09/12] efi_loader: disk: a helper function to delete efi_disk objects Date: Tue, 19 Apr 2022 10:05:14 +0900 Message-Id: <20220419010517.47175-10-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220419010517.47175-1-takahiro.akashi@linaro.org> References: <20220419010517.47175-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; }