From patchwork Fri Dec 10 06:49:43 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 522739 Delivered-To: patch@linaro.org Received: by 2002:a05:6e04:2287:0:0:0:0 with SMTP id bl7csp2170681imb; Thu, 9 Dec 2021 22:53:13 -0800 (PST) X-Google-Smtp-Source: ABdhPJwrzS0LIZLDZrzLEBgHnZDsmyc1tUgrike5ZYPjRVQl9Myee/Mwbpoe+GwvUbHHV2PFfIIQ X-Received: by 2002:aa7:d8da:: with SMTP id k26mr36243229eds.406.1639119192865; Thu, 09 Dec 2021 22:53:12 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1639119192; cv=none; d=google.com; s=arc-20160816; b=kmohlfqDzmcYJd6/IfDKDJ56+SFEBngCGYvVQBp1ZRZix4TF1j64ZFuOqEdojZiDHT ruo93c17SMSskM9Tj2OfAw8HolgF3ARm55oRZRjAYXswP47oktocysguFKV4Y+TjImeI 2mCdhhGy3JNu8+DwnQ3RFG1c5DOCo+ANRqSz+habwtEqP4xZudj5+W01B/HnQa8UPiC+ l0J0cpaasYP3vL+FsHe1tbguhN4Tn4ZaHALfP+10hx6GT3ts8jS0JU9+aOLn0TJ6o85B w49NY8l94gvdAH869sNIfca2y8YORrF4hH4tj9cHU82dzZZ9qCyl3tnHPrx+cwdBkNhE xjMQ== 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=LfzrvlE3CoM2ItEwxiKKRieK7zh6ChhYbS0KY4+JpOnkXQkMn3dVZrEgRf8doR5gc3 x9kwGfqT72VNAPWvRrSsglvD8DZiqKmNWl7kuI8L8iMv9dC1d6psOpC1p+VnE7MLCES4 lgBvTuMg7Tku1kJy9FR+IWw9kaUHzb3Araa0E2Txcwu5XSOmh2U4t7Hxx41w31y9thiP ZExVhREdua7Jfr6bH7hx1m0/WGGQb/PeE0H7MBnQMhxxUxjJueKWN4Z0TaL97M0lnsfg lAi7+vV7Dy/T8p0QbqxyUUK01cam7XsBUBDfiHymEg7H1YPpb6sdKkhovuQ5Blnqb6Hp Xgiw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="xhDn9K/Z"; 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 w18si3365067edq.29.2021.12.09.22.53.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Dec 2021 22:53:12 -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="xhDn9K/Z"; 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 78A29835FC; Fri, 10 Dec 2021 07:51:40 +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="xhDn9K/Z"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 0B395830BA; Fri, 10 Dec 2021 07:51:19 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x1036.google.com (mail-pj1-x1036.google.com [IPv6:2607:f8b0:4864:20::1036]) (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 7A773834B5 for ; Fri, 10 Dec 2021 07:51:10 +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-pj1-x1036.google.com with SMTP id j6-20020a17090a588600b001a78a5ce46aso8789139pji.0 for ; Thu, 09 Dec 2021 22:51:10 -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=xhDn9K/Zd16oYKiAkSgDVvZ8DHVc3ZHYhINhbNqDyxfC2dORoZrphOnuIN4uVquW5U C9MBQmgIZ/fm3ACGTaHjh9o2hGh2LajRsOFBGQL3zWicHCEXjrqtnis9FOzOgq4fjY18 5zqvOqOzFXHuHOzTIUTkZdnhg0dcpx4I0/cdNmIxCwGMKuELPZEHo42O7TDKl+9RKCE0 oXGaPiHW98OXusRdl8QyvsLcdalDdGbLnlIXoZNGIY63sQk9hJ/l0jdeHLi/ebmyjh0k mLob/4V7KBpsqoCemPyZ0KkWk2cyQNK0fCffZkFvZgbux2Tu2A/65yQMKPcp9EfoUlOJ BKJg== 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=lAhSyIZxcCEm8VpmG0BZgwU00HMmhFjYXpuYVoVtFNfcBEHwk0HeZVhwau1ULYE71Y IcC4nUtYjdEBfc7hi9qVkwTTmHY/oeRKs2bZum0zIPcqPFg+a4o2GS64OCgbZfJ1NBQ0 IgOYm5R/90Hj41OE4H0hNWx6rqJqc7kyG+wdWSFYmBzAqet79kHK6uFKfNG3qzWufHt1 UbfY/Xs9Hxio9HlzX8TdVsRV8hMb7nr2qfeu6oVOLVyMjJlHC00gvfZFbCBwbLwKy3j0 qoR2TIL4Y7jT3Y+bVeEWKkvQVVaQu2VIhB43+vNoso+cWG/VW9g1ATwUCuqCLV6PWpTc o63A== X-Gm-Message-State: AOAM532z2gLtIaDdej/ckqEz0yMHkYS1OZhCzlnPYSPKHUyJps6ui1CR CwCtzHzM7g94fkdDPOJjzA/hFQ== X-Received: by 2002:a17:902:e302:b0:141:ba08:2e44 with SMTP id q2-20020a170902e30200b00141ba082e44mr73023927plc.81.1639119068855; Thu, 09 Dec 2021 22:51:08 -0800 (PST) Received: from localhost.localdomain ([2400:4050:c3e1:100:75dd:4e0e:4542:936e]) by smtp.gmail.com with ESMTPSA id nn4sm1639035pjb.38.2021.12.09.22.51.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 09 Dec 2021 22:51:08 -0800 (PST) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de, sjg@chromium.org, ilias.apalodimas@linaro.org Cc: masami.hiramatsu@linaro.org, u-boot@lists.denx.de, AKASHI Takahiro Subject: [RFC v2 16/20] efi_loader: disk: a helper function to delete efi_disk objects Date: Fri, 10 Dec 2021 15:49:43 +0900 Message-Id: <20211210064947.73361-17-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 In-Reply-To: <20211210064947.73361-1-takahiro.akashi@linaro.org> References: <20211210064947.73361-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.38 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. 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; }