From patchwork Tue Mar 8 11:36:53 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 549281 Delivered-To: patch@linaro.org Received: by 2002:adf:80eb:0:0:0:0:0 with SMTP id 98csp1662395wrl; Tue, 8 Mar 2022 03:41:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJxszP8uesbFqbP941MCdiXVKMYq1JiDKBROOorqAmcX9qS4F9nsHuUlqjF93GbkawdXwkDw X-Received: by 2002:a05:6402:216:b0:416:279d:b314 with SMTP id t22-20020a056402021600b00416279db314mr14150901edv.75.1646739688701; Tue, 08 Mar 2022 03:41:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1646739688; cv=none; d=google.com; s=arc-20160816; b=JHA2W0r8IxzoTmqpNQowSCN4SsVuxK2jFjJ5TqL8MCwnLugyNowYgHo/AXZwvHm9um +Yp2jTHGwjk6F4t1Cgt024QbEzmXKc1o6+GaapCPxrgz/icl71VxXOCKe4FbwBSq55Bk wqACc3+57rOs05HOObVPvOnMi39kQCHYKzReLnv1YPybK0iNy3uC+6DO7eGdJD7a/STw /KkDO49akyF9N0GKaxnUpxx+2t4/h8cDEH/dIjy/oxjxFIu7Q8EomKNWK0EetYKN6eag Ote/24En5aCPwDVdWP7pzzI40SfLIRMXtV38VJydJaWOf3srR4lIQaqmlsbW28Gz2Yop 9bTQ== 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=TIdKmybonljI9I5WNrTv5pf40sZY+2ZbFYmLTbUWX0Q=; b=B2ILbsWWxhCl3VYmyGqtu7k47mgUKqMpMFll186oSoRFoT9sO/boNjBdqWAPtxsB6V KXHxTXebMDWekP0WB0x42PsFc5sO2cnWFtfLent8sGvZKh+IphOvGT2ZTC27+/aPH7km uOeTNl/47dZjhGEZlKptzdMMw/MKzMVV4hf03DjGc2J3LzdOqXbNA1LG7N8OfISWGEgX y979YWYBdfN/iaN0QoQVlomee/A3hw9f2S//EqFkUz94DoRJKXaf0KXeGPO0iiql8OIL 0qpIDETHYsJ6tCUchKDtBUAcQxCWKeJ5DOu05GKMgD3iP7CoZh+i5oL95IoLbfRrSOSr gfKg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="Hc7N/C12"; 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 u5-20020a056402110500b004128684bd43si9773985edv.507.2022.03.08.03.41.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 03:41:28 -0800 (PST) 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="Hc7N/C12"; 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 4B9A5839A3; Tue, 8 Mar 2022 12:41:22 +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="Hc7N/C12"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CEE3283991; Tue, 8 Mar 2022 12:40:52 +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=unavailable autolearn_force=no version=3.4.2 Received: from mail-pf1-x42f.google.com (mail-pf1-x42f.google.com [IPv6:2607:f8b0:4864:20::42f]) (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 55B1C8399D for ; Tue, 8 Mar 2022 12:38:37 +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=takahiro.akashi@linaro.org Received: by mail-pf1-x42f.google.com with SMTP id z16so17101033pfh.3 for ; Tue, 08 Mar 2022 03:38:37 -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=TIdKmybonljI9I5WNrTv5pf40sZY+2ZbFYmLTbUWX0Q=; b=Hc7N/C12vAW8OWbX3+pkesfxaYiqrQgW4ukpKKElqR0PnhWBKU36jUvoNUvty/fFgA ajlA7qdMCYyrbz1TAs/d5fJcbBbTWkT2Q39Gmr563oouW099aw16j6Vp/COE9xkRZpkb 5CuDaESwtvDyFXKojD4hTjuTmiTLG8+TX6tNwTyXdxVsCMMHSlDQPfs1XZuRTeeeqf2M 7TpBrxB8lGz2UsbQQ4Djp1Ua588HDwCLZPaDz0CkYJWQy7weMYBXtDbZWBgXrGsmjno4 HRcVuG8HQKf6V8b3nnXzEqJ2ybvddbJXu0AlT0ic1zx/9tFiXjQ2SZaIZ96ccld7XEiI POfA== 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=TIdKmybonljI9I5WNrTv5pf40sZY+2ZbFYmLTbUWX0Q=; b=QEYB8y+fE+j/ZlHElNowxcVZycaid8Ij5CzRNo3AVHyuRMpLVBAZuBtUbiracegCeT aAkGpPGHe33aO6+r9pPM2gusDx4PH34r3KJg2fWie5+n6SAL6e3l5I9i79dHwJMjPHbn iIpZCRDs+mbxI9gse6MG4papys07Cu1s3IiBbbWp6qny/kpQhtdZm88N/TqvbZmzL7q5 pNk6jPS/g0TksgJZ9aOpIWRwPbnNDtIyiMow0ghoRj0kN5KtweQDxgCkF6zN5CPQ2OTO KilCD8P4PQ0xxJG6e0kK50ge8kpSBeGHysbwvvG4+DUaU1kYFhk4ynTaroT5o6m4X7Ge Fy0w== X-Gm-Message-State: AOAM531gGiJ1pd7Bl31tE7KGFdgSD7IzDQuOtw8hv6NHFHSIAPEQmOh7 55Ef1BEVMNkugSSA+Q/A8LPirA== X-Received: by 2002:a63:5024:0:b0:380:83f7:1603 with SMTP id e36-20020a635024000000b0038083f71603mr4013966pgb.289.1646739515207; Tue, 08 Mar 2022 03:38:35 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c3e1:100:b94a:f47a:3d51:185c]) by smtp.gmail.com with ESMTPSA id z2-20020a17090a170200b001bf2d530d64sm3434677pjd.2.2022.03.08.03.38.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 08 Mar 2022 03:38:34 -0800 (PST) From: AKASHI Takahiro To: lukma@denx.de, peng.fan@nxp.com, jh80.chung@samsung.com, bmeng.cn@gmail.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 v3 15/19] efi_loader: disk: a helper function to delete efi_disk objects Date: Tue, 8 Mar 2022 20:36:53 +0900 Message-Id: <20220308113657.221101-16-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20220308113657.221101-1-takahiro.akashi@linaro.org> References: <20220308113657.221101-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 bf9824b9b1a4..53bee6654421 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -627,6 +627,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; @@ -638,6 +719,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; }