From patchwork Tue Apr 19 01:05:06 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1618588 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=fUMHTN6h; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kj5GB407Cz9sFx for ; Tue, 19 Apr 2022 11:05:54 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 07D3D83B29; Tue, 19 Apr 2022 03:05:51 +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="fUMHTN6h"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B9EFC83C13; Tue, 19 Apr 2022 03:05:47 +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-x52b.google.com (mail-pg1-x52b.google.com [IPv6:2607:f8b0:4864:20::52b]) (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 8022983B25 for ; Tue, 19 Apr 2022 03:05:42 +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-x52b.google.com with SMTP id 203so2952326pgb.3 for ; Mon, 18 Apr 2022 18:05:42 -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=yPlc4gJGW0AhXRY0zwO1CjBS+z1fQTk36P+/M080M4Q=; b=fUMHTN6hhSih6vtRKX2jDaA6+NCH6OVh1vHCGCmf7/Ddr2AN7aAdBNIbGW27/LKkZE fM/AlxDFXTHcHrzg9e8CBeAgjPIUZcn4GDGVt0KJev/mBqopPHegBwtny6CQTTDyMxBN NZHpaDEYMvTiFEGXo8zJ9J8lSa4thoD+M96iie8rJsE0fF5mTy2GW++Su9ZyBmRKKwwC 3WjElQOV1y+dHExkytxSoeP7g20XkezpwzEzh8qAozB5Q9RyUL5B3TVLUflNNAlp3mdW iwM5yvsxJktRK4NwK6C1AOkhj/QyjuFyyt6Db6oysT9rgM9gxYj9MAl3Xe+4A4DbsvIW neKA== 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=yPlc4gJGW0AhXRY0zwO1CjBS+z1fQTk36P+/M080M4Q=; b=M/3MaE1Piv5Xccf4MlWtNrI5xnODpD6EoZS/7QH6ErlM4BryyxB7bpQKc0x/Cni5Wc MCHXc0fksWF4txWBBqmiqjd7VA7BgiD2bKa6AnqNF2baPC2w1YY/MYC33OVGjoLNNjjE b6ocI8Y49HZa/wKaOyrg8EmW8lBPUtoH+0G4efBI1kNMViq+qlfJJQpmmPdYYrg+HeUo HYH+vQSSePYid78D3k3RwdW7QmYRkOVl6ZICq9GZFqsvx2Acof9KRVasESsGFJ4CZizN doclbt9Zoe4EhZn0Pt3EhQOIS9KqO9+R4vzCgaFWBES0Cp5k/4BrI+XicCF5j8uFRdAw /z8A== X-Gm-Message-State: AOAM532Gp52AnReizDr1ncFQ/5CZqtt4mwL1FcORUJZx9t2Sw2meX4uZ 52K3pEQwD6UPfm477pL91KNEumE2J3vhkw== X-Google-Smtp-Source: ABdhPJwOHULT+6Jt8x4JI9zFODtZhvfd/eV6ICv0DbGrtIg7f9LHiJfGLMrgQdpldQSZM6TLzppA+g== X-Received: by 2002:a63:368a:0:b0:398:2829:2698 with SMTP id d132-20020a63368a000000b0039828292698mr12513288pga.172.1650330340927; Mon, 18 Apr 2022 18:05:40 -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.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 18:05:40 -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 01/12] dm: tag: change ENOSPC to ENOMEM Date: Tue, 19 Apr 2022 10:05:06 +0900 Message-Id: <20220419010517.47175-2-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 ENOMEM is a more common error code for memory starvation. Signed-off-by: AKASHI Takahiro --- drivers/core/tag.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/drivers/core/tag.c b/drivers/core/tag.c index 6829bcd8806c..22999193a5a3 100644 --- a/drivers/core/tag.c +++ b/drivers/core/tag.c @@ -29,7 +29,7 @@ int dev_tag_set_ptr(struct udevice *dev, enum dm_tag_t tag, void *ptr) node = calloc(sizeof(*node), 1); if (!node) - return -ENOSPC; + return -ENOMEM; node->dev = dev; node->tag = tag; @@ -53,7 +53,7 @@ int dev_tag_set_val(struct udevice *dev, enum dm_tag_t tag, ulong val) node = calloc(sizeof(*node), 1); if (!node) - return -ENOSPC; + return -ENOMEM; node->dev = dev; node->tag = tag; From patchwork Tue Apr 19 01:05:07 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1618589 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=U0ZJLz8Y; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kj5GQ2hvXz9sFx for ; Tue, 19 Apr 2022 11:06:06 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3D14383B3D; Tue, 19 Apr 2022 03:05:56 +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="U0ZJLz8Y"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id DEF5C83C5A; Tue, 19 Apr 2022 03:05:48 +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-x535.google.com (mail-pg1-x535.google.com [IPv6:2607:f8b0:4864:20::535]) (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 E5D9283B38 for ; Tue, 19 Apr 2022 03:05: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=takahiro.akashi@linaro.org Received: by mail-pg1-x535.google.com with SMTP id k29so21958831pgm.12 for ; Mon, 18 Apr 2022 18:05:44 -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=cX/nLKjs6xoyV+5h4EfvdKOKYkfovrTdR9z7OgzIyt0=; b=U0ZJLz8YRru/MC16ZoU8meNq+tzIjbfs5WiJgIYeeiK9I3p4LP11s7rD64suRGKj2O oons0+bkKDzkYNbJ6hAp2F20IzT4sXfcPnkgusKZESS5sbnheYah0LSkBrZZ+pfdkZKa u0+lr7ZYV2bMkWdOION2YznekrLv5sgcPdmVWVSY/0s4OBgEuaVqEUxcCTZuCzS16EwE HR015POXudRRbiQvOaUAWcOjrY7GwSrsRVp/7JdDGV3j5BE/mRFShp3sU1r3HY9hwvRw C//fjc9z4bvxFGkIC6wc01PUhaBHP6YnFQMde/otUEiucYptt/RxJTFtlboWS51dPi4l 7b8A== 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=cX/nLKjs6xoyV+5h4EfvdKOKYkfovrTdR9z7OgzIyt0=; b=zXRpWERO60dLYaa/XRMn3llBlPIWjH5tl1v7sYbpggEJa0RBkHuc5ziwjFZJ0wBtIx VuSXbq31CydyrQUIzAaDoQeGBZ3Fa8BBNft3sqg7PsKc3lMqhftgRWxuwoGxeMrkp8iB 4XZJVB06Leu7p9UwOO1Plax1k5Ab1cPx5Sz0T3JkWWiP+PBcjzkp7ykuBpouzb3sXKTE oc83LGdChAhzvr3pCqKvvgNsogyS+TIhUcNZF1XpcX51uEYRZ8Y/Z6WmBN2to2zJA3S+ ADAlMtUo1sF8nXn3lAe+ELoaseSRirPa9WhXhGhmOzIDW7obsVJmXu5TmAGQBm+8zuj9 eKDA== X-Gm-Message-State: AOAM5319FhwvtmqjvxrBRQSU6gV8Aw9s5VokiJK+tPyn3ydxD4jUlKNC y/HegQ4bx0KGGf1xXscX88SiUg== X-Google-Smtp-Source: ABdhPJzpzfIoeInS0xbwmdhd9A0wVqhfe8+acYynFD3bXP6vegmjPzCNu68WAGUhx4/S8JVOzpoNUQ== X-Received: by 2002:a65:5b0b:0:b0:3a8:2190:9a07 with SMTP id y11-20020a655b0b000000b003a821909a07mr10001664pgq.462.1650330343302; Mon, 18 Apr 2022 18:05:43 -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.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 18:05:42 -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 02/12] dm: tag: add some document Date: Tue, 19 Apr 2022 10:05:07 +0900 Message-Id: <20220419010517.47175-3-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 Some basic stuff about tag support is explained under doc/devlop/driver-model. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass --- doc/develop/driver-model/design.rst | 20 ++++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/doc/develop/driver-model/design.rst b/doc/develop/driver-model/design.rst index b0e6337030a1..3e88dc40e6fd 100644 --- a/doc/develop/driver-model/design.rst +++ b/doc/develop/driver-model/design.rst @@ -1042,6 +1042,26 @@ data structure might be worthwhile in some rare cases, once we understand what the bottlenecks are. +Tag Support +----------- + +It is sometimes useful for a subsystem to associate its own private +data (or object) to a DM device, i.e. struct udevice, to support +additional features. + +Tag support in driver model will give us the ability to do so dynamically +instead of modifying "udevice" data structure. In the initial release, we +will support two type of attributes: +- a pointer with dm_tag_set_ptr(), and +- an unsigned long with dm_tag_set_val() + +For example, UEFI subsystem utilizes the feature to maintain efi_disk +objects depending on linked udevice's lifecycle. + +While the current implementation is quite simple, it will get evolved +as the feature is more extensively used in U-Boot subsystems. + + Changes since v1 ---------------- From patchwork Tue Apr 19 01:05:08 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1618590 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=W6N7oHwR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kj5Gd0Pr9z9sFx for ; Tue, 19 Apr 2022 11:06:16 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 4123583D8E; Tue, 19 Apr 2022 03:06:07 +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="W6N7oHwR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id A86D383C11; Tue, 19 Apr 2022 03:05:54 +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 5330A83C06 for ; Tue, 19 Apr 2022 03:05:47 +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 mm4-20020a17090b358400b001cb93d8b137so818743pjb.2 for ; Mon, 18 Apr 2022 18:05:47 -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=3zhbFhwoFiwMQkaYNb5BSiBvrj1lKF9eqN1bn4CV1xU=; b=W6N7oHwRJxB/mvAwHQY663/VXmgTCjTngepzDgiS+mYU4HjY2kGUvQCxmpHHqtgfO3 rNv0PsFVZluCzWiKM3El8iR7xZSSXtOSvTwPbpUgAho6w0zuwuwkF302tBDaASNR4XKe UhAx4NbGi4VLGdf/AEHcYsD97lEpvgaM511uzIixEwv/uayfhTY2BM5IdbH8Ann3YeTm B/fs/lH6AyteHO4Y/UmFe0YpBeWe4Ui/5kBxx1GF9siqaHDcyDqs8BFnJqQBWwwL5eNy iM9WRtV9bNqohnUJLKaSwu6RBxh/9XGSrtG3SucsipHzoOCtkMdcP9JlF8g9o2n87HBo DGoQ== 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=3zhbFhwoFiwMQkaYNb5BSiBvrj1lKF9eqN1bn4CV1xU=; b=gC/UiFnTlIZTQ4bMEe4RYw0ZL+O5XBshBEanq8/PyprW0wM5IV8AmErhz32OsBiYbj AEjLWdL2mKr2fmLhOJECNIguvWwCl5PXUtNhPH+DgrTZqV/fZzOnD5KbL5qLlE1iCcMy rz85IjzptYXI6qYB5XiW73ql62JUWDubTZoNHyn8OOo4PYGQZFvlW4QDNEmhgqQRPIno avgkE2B+kQyh7Z2NW80LpDYhVjA+hRzed1I41TDLN3J2wB02qDNJJuFaWf/yJHjt/xMl StPKWHEh2JFRCAzUQTN0Etft8UdHkUuXUxUI4fcTSbkG5DktXBgl2DDsFPagz8RMA0L+ RYsw== X-Gm-Message-State: AOAM533mc6zLsShJwY9CwoJsvtMcuNuimTfye6ZmerAdoMSGEM5OaKFf VPHUBaYRdBVOhO0M+kdR4MfFIA== X-Google-Smtp-Source: ABdhPJzMyv23s7zNvbN2pGDCt4nXpXEcIiM2HfYKFRAo7IboaikIAmoKX6cv8S28rd89myE1uP1B9g== X-Received: by 2002:a17:90a:b014:b0:1cb:ba36:8fe1 with SMTP id x20-20020a17090ab01400b001cbba368fe1mr21476839pjq.67.1650330345699; Mon, 18 Apr 2022 18:05:45 -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.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 18:05:45 -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 03/12] test: dm: add tests for tag support Date: Tue, 19 Apr 2022 10:05:08 +0900 Message-Id: <20220419010517.47175-4-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 The new test covers all tag-related interfaces. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass --- test/dm/Makefile | 1 + test/dm/tag.c | 84 ++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 85 insertions(+) create mode 100644 test/dm/tag.c diff --git a/test/dm/Makefile b/test/dm/Makefile index d46552fbf320..dc3177dbb7f4 100644 --- a/test/dm/Makefile +++ b/test/dm/Makefile @@ -102,6 +102,7 @@ obj-y += syscon.o obj-$(CONFIG_RESET_SYSCON) += syscon-reset.o obj-$(CONFIG_SYSINFO) += sysinfo.o obj-$(CONFIG_SYSINFO_GPIO) += sysinfo-gpio.o +obj-$(CONFIG_UT_DM) += tag.o obj-$(CONFIG_TEE) += tee.o obj-$(CONFIG_TIMER) += timer.o obj-$(CONFIG_DM_USB) += usb.o diff --git a/test/dm/tag.c b/test/dm/tag.c new file mode 100644 index 000000000000..8289954e7c26 --- /dev/null +++ b/test/dm/tag.c @@ -0,0 +1,84 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * DM tag test + * + * Copyright (c) 2021 Linaro Limited + * Author: AKASHI Takahiro + */ + +#include +#include +#include /* DM_TEST() */ +#include /* struct unit_test_state */ +#include /* assertions */ + +/* + * Test dm_tag_ptr() API + */ +static int dm_test_tag_ptr(struct unit_test_state *uts) +{ + ulong val; + void *ptr = NULL; + + ut_assertok(dev_tag_set_ptr(uts->root, DM_TAG_EFI, &val)); + + ut_assertok(dev_tag_get_ptr(uts->root, DM_TAG_EFI, &ptr)); + + ut_asserteq_ptr(&val, ptr); + + ut_assertok(dev_tag_del(uts->root, DM_TAG_EFI)); + + return 0; +} + +DM_TEST(dm_test_tag_ptr, 0); + +/* + * Test dm_tag_val() API + */ +static int dm_test_tag_val(struct unit_test_state *uts) +{ + ulong val1 = 0x12345678, val2 = 0; + + ut_assertok(dev_tag_set_val(uts->root, DM_TAG_EFI, val1)); + + ut_assertok(dev_tag_get_val(uts->root, DM_TAG_EFI, &val2)); + + ut_asserteq_64(val1, val2); + + ut_assertok(dev_tag_del(uts->root, DM_TAG_EFI)); + + return 0; +} + +DM_TEST(dm_test_tag_val, 0); + +/* + * Test against an invalid tag + */ +static int dm_test_tag_inval(struct unit_test_state *uts) +{ + ulong val; + + ut_asserteq(-EINVAL, dev_tag_set_ptr(uts->root, DM_TAG_COUNT, &val)); + + return 0; +} + +DM_TEST(dm_test_tag_inval, 0); + +/* + * Test dm_tag_del_all() AP: + */ +static int dm_test_tag_del_all(struct unit_test_state *uts) +{ + ulong val; + + ut_assertok(dev_tag_set_ptr(uts->root, DM_TAG_EFI, &val)); + + ut_assertok(dev_tag_del_all(uts->root)); + + return 0; +} + +DM_TEST(dm_test_tag_del_all, 0); From patchwork Tue Apr 19 01:05:09 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1618591 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=UiMZZ3Ly; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kj5Gq5ddGz9sFx for ; Tue, 19 Apr 2022 11:06:27 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id A05BC83C06; Tue, 19 Apr 2022 03:06:10 +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="UiMZZ3Ly"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D97AF83C1E; Tue, 19 Apr 2022 03:05:55 +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-x1033.google.com (mail-pj1-x1033.google.com [IPv6:2607:f8b0:4864:20::1033]) (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 BCEEC83B38 for ; Tue, 19 Apr 2022 03:05:49 +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-x1033.google.com with SMTP id j8-20020a17090a060800b001cd4fb60dccso840803pjj.2 for ; Mon, 18 Apr 2022 18:05:49 -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=ih7uQuXQd9OKOnMZdhgbhBngmt18xa7GFh0dW3fVUn0=; b=UiMZZ3LyF4Okrv+aMwNMntrzkt9F+bHFQQQnw1cGktiJ5ois3cG09iCpGtGUcjz/21 okI8P0b/1fSVcvNNhI5lYQ0L/c60t+fnGExghZo0U1yNkUX/d2EjBBruG89FiE00fehh OpRCi9SlQZJZQx5Dvm1Y06Ngj4BED7Uq0OVnEbjBqjwPiZPTYFSRjCLxggskNr73JnDD 955YDmbkapSj/xOOlOsAn1hpqJbs6cvmvjJpQxtWiWRQI3G+eGOzhxZtvGaK4zqFyMfN WA6TqOJIrCmE6wsq1a2lBm5Dx2OB5ohH7yGB6sLSAN4aKdjEf8ZBGWK+U9yx6s523H5o ZHZA== 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=ih7uQuXQd9OKOnMZdhgbhBngmt18xa7GFh0dW3fVUn0=; b=q+YpjDviazKWrXVMmxjS7n8zxtOaO1p/H7lGYvh7p0gevqpS2tqDeoP6Qrj8egIBj5 aJHP566Hb/R7JsNRUImsxWCwkXEWssA2ZHoz14MyqeyLJ4PZSmI7lVraqD0qgaWci2vW TNnGa3Kg26zOu0FNArDebqMMI5aX/WCCha7ypDtLK3PKRkUVbSjPLCLcYYoDJyPXLxGh MMFTIYjyT/Ra+zGSfMt3xmEFV2U7BFumw55C5w8d5tR+DStfR0dh513OMqKmr3X0DylE Um1nyrdiPWx5Kv7Q6n0GnYqZjBiGNbUbCA9klahhDGGG3VFKhxNVt5EmvG4HGQD5B47T hGmA== X-Gm-Message-State: AOAM531fxkizFMpaNbfXvAW6THOCp+DUr4dRqiG2XVcazK3DNsL6YF1K EXF3iavrJ6lewzBmHG4ycoD50WhIHzKGLw== X-Google-Smtp-Source: ABdhPJzWzcUEQRR9irsVxfl5nadnM6DdHuMyMtrATTx75oOYnx77RQLfDC6wf0yAqQ24ZAu8Dni0Pw== X-Received: by 2002:a17:90a:d082:b0:1ca:be58:c692 with SMTP id k2-20020a17090ad08200b001cabe58c692mr21129582pju.238.1650330348076; Mon, 18 Apr 2022 18:05:48 -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.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 18:05:47 -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 04/12] dm: disk: add UCLASS_PARTITION Date: Tue, 19 Apr 2022 10:05:09 +0900 Message-Id: <20220419010517.47175-5-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 NOTE: probably we have to update config dependencies, in particular, SPL/TPL_PRINTF? With this new function, UCLASS_PARTITION devices will be created as child nodes of UCLASS_BLK device. Signed-off-by: AKASHI Takahiro --- disk/Makefile | 3 + disk/disk-uclass.c | 153 +++++++++++++++++++++++++++++++++++++++++ include/dm/uclass-id.h | 1 + include/part.h | 10 +++ 4 files changed, 167 insertions(+) create mode 100644 disk/disk-uclass.c diff --git a/disk/Makefile b/disk/Makefile index 5ca10c55762b..ec148832b330 100644 --- a/disk/Makefile +++ b/disk/Makefile @@ -6,6 +6,9 @@ #ccflags-y += -DET_DEBUG -DDEBUG obj-$(CONFIG_$(SPL_TPL_)PARTITIONS) += part.o +ifdef CONFIG_$(SPL_TPL_)BLK +obj-$(CONFIG_$(SPL_TPL_)PARTITIONS) += disk-uclass.o +endif obj-$(CONFIG_$(SPL_TPL_)MAC_PARTITION) += part_mac.o obj-$(CONFIG_$(SPL_TPL_)DOS_PARTITION) += part_dos.o obj-$(CONFIG_$(SPL_TPL_)ISO_PARTITION) += part_iso.o diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c new file mode 100644 index 000000000000..4918a2f72d1e --- /dev/null +++ b/disk/disk-uclass.c @@ -0,0 +1,153 @@ +// SPDX-License-Identifier: GPL-2.0+ +/* + * Software partition device (UCLASS_PARTITION) + * + * Copyright (c) 2021 Linaro Limited + * Author: AKASHI Takahiro + */ + +#define LOG_CATEGORY UCLASS_PARTITION + +#include +#include +#include +#include +#include +#include +#include + +int part_create_block_devices(struct udevice *blk_dev) +{ + int part, count; + struct blk_desc *desc = dev_get_uclass_plat(blk_dev); + struct disk_partition info; + struct disk_part *part_data; + char devname[32]; + struct udevice *dev; + int ret; + + if (!CONFIG_IS_ENABLED(PARTITIONS) || + !CONFIG_IS_ENABLED(HAVE_BLOCK_DEVICE)) + return 0; + + if (device_get_uclass_id(blk_dev) != UCLASS_BLK) + return 0; + + /* Add devices for each partition */ + for (count = 0, part = 1; part <= MAX_SEARCH_PARTITIONS; part++) { + if (part_get_info(desc, part, &info)) + continue; + snprintf(devname, sizeof(devname), "%s:%d", blk_dev->name, + part); + + ret = device_bind_driver(blk_dev, "blk_partition", + strdup(devname), &dev); + if (ret) + return ret; + + part_data = dev_get_uclass_plat(dev); + part_data->partnum = part; + part_data->gpt_part_info = info; + count++; + + ret = device_probe(dev); + if (ret) { + debug("Can't probe\n"); + count--; + device_unbind(dev); + + continue; + } + } + debug("%s: %d partitions found in %s\n", __func__, count, + blk_dev->name); + + return 0; +} + +static ulong blk_part_read(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, void *buffer) +{ + struct udevice *parent; + struct disk_part *part; + const struct blk_ops *ops; + + parent = dev_get_parent(dev); + ops = blk_get_ops(parent); + if (!ops->read) + return -ENOSYS; + + part = dev_get_uclass_plat(dev); + if (start >= part->gpt_part_info.size) + return 0; + + if ((start + blkcnt) > part->gpt_part_info.size) + blkcnt = part->gpt_part_info.size - start; + start += part->gpt_part_info.start; + + return ops->read(parent, start, blkcnt, buffer); +} + +static ulong blk_part_write(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, const void *buffer) +{ + struct udevice *parent; + struct disk_part *part; + const struct blk_ops *ops; + + parent = dev_get_parent(dev); + ops = blk_get_ops(parent); + if (!ops->write) + return -ENOSYS; + + part = dev_get_uclass_plat(dev); + if (start >= part->gpt_part_info.size) + return 0; + + if ((start + blkcnt) > part->gpt_part_info.size) + blkcnt = part->gpt_part_info.size - start; + start += part->gpt_part_info.start; + + return ops->write(parent, start, blkcnt, buffer); +} + +static ulong blk_part_erase(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt) +{ + struct udevice *parent; + struct disk_part *part; + const struct blk_ops *ops; + + parent = dev_get_parent(dev); + ops = blk_get_ops(parent); + if (!ops->erase) + return -ENOSYS; + + part = dev_get_uclass_plat(dev); + if (start >= part->gpt_part_info.size) + return 0; + + if ((start + blkcnt) > part->gpt_part_info.size) + blkcnt = part->gpt_part_info.size - start; + start += part->gpt_part_info.start; + + return ops->erase(parent, start, blkcnt); +} + +static const struct blk_ops blk_part_ops = { + .read = blk_part_read, + .write = blk_part_write, + .erase = blk_part_erase, +}; + +U_BOOT_DRIVER(blk_partition) = { + .name = "blk_partition", + .id = UCLASS_PARTITION, + .ops = &blk_part_ops, +}; + +UCLASS_DRIVER(partition) = { + .id = UCLASS_PARTITION, + .per_device_plat_auto = sizeof(struct disk_part), + .name = "partition", +}; diff --git a/include/dm/uclass-id.h b/include/dm/uclass-id.h index 0e26e1d13824..230b1ea528cf 100644 --- a/include/dm/uclass-id.h +++ b/include/dm/uclass-id.h @@ -83,6 +83,7 @@ enum uclass_id { UCLASS_P2SB, /* (x86) Primary-to-Sideband Bus */ UCLASS_PANEL, /* Display panel, such as an LCD */ UCLASS_PANEL_BACKLIGHT, /* Backlight controller for panel */ + UCLASS_PARTITION, /* Logical disk partition device */ UCLASS_PCH, /* x86 platform controller hub */ UCLASS_PCI, /* PCI bus */ UCLASS_PCI_EP, /* PCI endpoint device */ diff --git a/include/part.h b/include/part.h index e5806edb3452..c4e0bef7749d 100644 --- a/include/part.h +++ b/include/part.h @@ -296,6 +296,16 @@ part_get_info_by_dev_and_name_or_num(const char *dev_iface, } #endif +struct udevice; +/** + * part_create_block_devices - Create block devices for disk partitions + * + * Create UCLASS_PARTITION udevices for each of disk partitions in @parent + * + * @blk_dev: Whole disk device + */ +int part_create_block_devices(struct udevice *blk_dev); + /* * We don't support printing partition information in SPL and only support * getting partition information in a few cases. From patchwork Tue Apr 19 01:05:10 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1618592 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=ih8bbXir; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kj5H23dxFz9sFx for ; Tue, 19 Apr 2022 11:06:38 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 779B983D07; Tue, 19 Apr 2022 03:06:13 +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="ih8bbXir"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id BF7AF83BE5; Tue, 19 Apr 2022 03:05:56 +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-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) (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 1C69083BE5 for ; Tue, 19 Apr 2022 03:05:52 +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-x534.google.com with SMTP id k14so22013164pga.0 for ; Mon, 18 Apr 2022 18:05:52 -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=2+O99jPAsVE8MNTnpcalytHrEjhAeCo2wBfrWozxCMc=; b=ih8bbXirohMeDXqqn12ALzJiJEg9K/juWb5ZeExm7XuwxkDxC5lJyl5A0YLsJLmhyA SwNyU6asfndJLih+oIy10XQljczwIx8sHoOxJvlguFlnX9+lkxBiCfTlEQxM1qKPjd02 1xfkeFjz7KCMqe3kkb8XAObay1l2wubogwBXMsTwPQ73lsB44OTaTxj/QTNQKg/OV4Rn nTBo3WPhkN5WmVGKGYdkN54Ld+lxXc4y6eXrhm2NlFSTQWOej5ZYk/FlLhe9Pvf+43Rm 9oS+/M6M1yPdbtL3iUO0jdpm4Go9q4rgyvNbh5xkoFx61k75jbmpKVz1ukxsKBF5vwqO bzmA== 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=2+O99jPAsVE8MNTnpcalytHrEjhAeCo2wBfrWozxCMc=; b=HUrrWu7Iphi/K/VmBEhEfWITqAAOIbE71mVo1edmCgQAkDuOr+l/NfOxelCVdDwFk1 L2nDozIjFFHKdioYIp48fhzXaJBD/svMz1MXexBtInTSfWtvScNXPYmPA1YN4S+vO8Y4 W94ask2P9r7sAZ5Q9OMYGwO5ZtdFctwrHCJEpBt4VEB5YHHqy50bkAayW+f7sCOshfLG gw1LReSt5xM0Tk0D+8+vvWPykMrz0vjTmpxQ9ZtJLmmXCCEdX4iKvdNXgZaxWOdmtCbL xBRr0GyNgV81LscfH64XLuuecPPU4y87VYMTWq/RKdh+snUVXlgLG/thH/GV/VrIyHpQ M7TQ== X-Gm-Message-State: AOAM533btNPOVDUBr8nsqzONWRCSVRApZ3MBNPgbJgPKEVUL/R4ei/Ww rudP0hFboqmy/aD1KLnl47UyJIJgBJy7fw== X-Google-Smtp-Source: ABdhPJxZBFCyG+6W0FgSwHdGsOwaR3rqJd3XNULvCEISwBf1iHkS5J0Grau9Dtab2GGUyiP4PheH8Q== X-Received: by 2002:a63:5007:0:b0:3aa:1670:e327 with SMTP id e7-20020a635007000000b003aa1670e327mr3947331pgb.124.1650330350537; Mon, 18 Apr 2022 18:05:50 -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.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 18:05:50 -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 05/12] dm: blk: add a device-probe hook for scanning disk partitions Date: Tue, 19 Apr 2022 10:05:10 +0900 Message-Id: <20220419010517.47175-6-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 Now that all the block device drivers have enable a probe hook, we will call part_create_block_devices() to enumerate all the partitions and create associated udevices when a block device is detected. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass --- drivers/block/blk-uclass.c | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/block/blk-uclass.c b/drivers/block/blk-uclass.c index f1e4a8564679..791e26c06ebe 100644 --- a/drivers/block/blk-uclass.c +++ b/drivers/block/blk-uclass.c @@ -741,6 +741,10 @@ static int blk_post_probe(struct udevice *dev) struct blk_desc *desc = dev_get_uclass_plat(dev); part_init(desc); + + if (desc->part_type != PART_TYPE_UNKNOWN && + part_create_block_devices(dev)) + debug("*** creating partitions failed\n"); } return 0; From patchwork Tue Apr 19 01:05:11 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1618593 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Ovv5H9BB; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kj5HG2Q6Cz9sFx for ; Tue, 19 Apr 2022 11:06:50 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id D9DDC83D92; Tue, 19 Apr 2022 03:06:16 +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="Ovv5H9BB"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id D103583D07; Tue, 19 Apr 2022 03:05:58 +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-x530.google.com (mail-pg1-x530.google.com [IPv6:2607:f8b0:4864:20::530]) (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 610D783B4E for ; Tue, 19 Apr 2022 03:05:54 +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-x530.google.com with SMTP id q12so21956433pgj.13 for ; Mon, 18 Apr 2022 18:05:54 -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=UQgQUXH6/e3P5T+GBMNREsegS1VF3JwCWSwgCegxL1I=; b=Ovv5H9BBmdwMPMMt5Gqn6iyTqp/2LIA3TBeivaPVUWGSbmC5Q5JjuFy1T/bL3lbo8d 79rVXp0puO4gzmEUTRWmK7ZSekvuCyNP7rDO/y1wRX3hu0JuDaz3YQnjt1nRGPtr20DN bZsvWaDmtJ4nHKQBKIJ7b40dcUpqKCcH7gmuThcNeZdbwb6Ichg0eN0W1mc78qNHDsI2 qhYjS05cJHERXxICBZmYqsfKU41diDlPE2kxemkhGN3e192olr6sCXP2oycqkVKgjDeZ HdxZEd5CPkzIM0Yu1vSOhqU6cURd3DzJfddFszZ5MgTmR0V0Wr+p6JdkvvBn2BLYg9bI NwSQ== 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=UQgQUXH6/e3P5T+GBMNREsegS1VF3JwCWSwgCegxL1I=; b=1h0YdEasGPjuHcezmkiUjR1VGxs6NpTNXVp/S+kxDGIemSxoavbkObY8VL09nB5Edy rgVUbTslS3STm0vHfLfvbvQVMg4It5XXK3V0g/W/BoyrTi8UMLfr85DWWDt8jIA7fR4D GEhOqyDkutwHADh//4Wp9vcvYVZTGGR1Udd2/dKTgCUFWn05VW9NqLPIXmeSeM2Bbv77 T5noiBut0WpQN58LpGgYT2L1HTFr26pfyY/rIwXM5HVgSoL7RGqi48STHiqcYup7k5p5 DURopktagn48cL1cH+ytThIe07VNnKVRgew6NZtTMstQ3UXRQuc4iQfwsC0zooqWeVWA VfEg== X-Gm-Message-State: AOAM532G4aWAamanKh3nzsWAGB7lF8Ghu6Ui+yqbSMu6OY3S8AJMaQqc vjy7NZOzFozx707pWfLSZi1odQ== X-Google-Smtp-Source: ABdhPJycOJOX5o2J/2iGlbWGpWuhlqmbZ1XUqV7odie2KhiEIExoU5/ZMc4QjvM/7CMA8XcB8fsWNg== X-Received: by 2002:a63:4862:0:b0:385:fb1d:fc54 with SMTP id x34-20020a634862000000b00385fb1dfc54mr12467966pgk.57.1650330352795; Mon, 18 Apr 2022 18:05:52 -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.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 18:05:52 -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 06/12] efi_loader: split efi_init_obj_list() into two stages Date: Tue, 19 Apr 2022 10:05:11 +0900 Message-Id: <20220419010517.47175-7-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 In the next commit, CONFIG_EFI_SETUP_EARLY will become mandated in order to support dynamic enumeration of efi_disk objects. This can, however, be problematic particularly in case of file-based variable storage (efi_variable.c, default). Non-volatile variables are to be restored from EFI system partition by efi_init_variables() in efi_init_obj_list(). When efi_init_obj_list() is called in board_init_r(), we don't know yet what disk devices we have since none of device probing commands (say, scsi rescan) has not been executed at that stage. So in this commit, a preparatory change is made; efi_init_obj_list() is broken into the two functions; * efi_init_early(), and * new efi_init_obj_list() Only efi_init_early() will be called in board_init_r(), which allows us to execute any of device probing commands, either though "preboot" variable or normal command line, before calling efi_init_obj_list() which is to be invoked at the first execution of an efi-related command (or at efi_launch_capsules()) as used to be. Signed-off-by: AKASHI Takahiro --- common/board_r.c | 2 +- common/main.c | 7 +++-- include/efi_loader.h | 2 ++ lib/efi_loader/efi_setup.c | 58 ++++++++++++++++++++++++++++++++------ 4 files changed, 57 insertions(+), 12 deletions(-) diff --git a/common/board_r.c b/common/board_r.c index 8dc87ed2be4c..7d0281f5447e 100644 --- a/common/board_r.c +++ b/common/board_r.c @@ -795,7 +795,7 @@ static init_fnc_t init_sequence_r[] = { initr_mem, #endif #ifdef CONFIG_EFI_SETUP_EARLY - (init_fnc_t)efi_init_obj_list, + efi_init_early, #endif run_main_loop, }; diff --git a/common/main.c b/common/main.c index 3f5214fd44b8..682f3359ea38 100644 --- a/common/main.c +++ b/common/main.c @@ -54,8 +54,11 @@ void main_loop(void) if (IS_ENABLED(CONFIG_UPDATE_TFTP)) update_tftp(0UL, NULL, NULL); - if (IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK_EARLY)) - efi_launch_capsules(); + if (IS_ENABLED(CONFIG_EFI_CAPSULE_ON_DISK_EARLY)) { + /* efi_init_early() already called */ + if (efi_init_obj_list() == EFI_SUCCESS) + efi_launch_capsules(); + } s = bootdelay_process(); if (cli_process_fdt(&s)) diff --git a/include/efi_loader.h b/include/efi_loader.h index c52ea59ec7ae..5bb8fb2acd04 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -493,6 +493,8 @@ struct efi_register_notify_event { /* List of all events registered by RegisterProtocolNotify() */ extern struct list_head efi_register_notify_events; +/* called at pre-initialization */ +int efi_init_early(void); /* Initialize efi execution environment */ efi_status_t efi_init_obj_list(void); /* Install device tree */ diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index eee54e48784f..de2f34bab537 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -174,20 +174,18 @@ static efi_status_t efi_init_os_indications(void) &os_indications_supported, false); } - /** - * efi_init_obj_list() - Initialize and populate EFI object list + * __efi_init_early() - handle initialization at early stage + * + * This function is called in efi_init_obj_list() only if + * !CONFIG_EFI_SETUP_EARLY. * * Return: status code */ -efi_status_t efi_init_obj_list(void) +static efi_status_t __efi_init_early(void) { efi_status_t ret = EFI_SUCCESS; - /* Initialize once only */ - if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) - return efi_obj_list_initialized; - /* Allow unaligned memory access */ allow_unaligned(); @@ -202,9 +200,51 @@ efi_status_t efi_init_obj_list(void) #ifdef CONFIG_PARTITIONS ret = efi_disk_register(); - if (ret != EFI_SUCCESS) - goto out; #endif +out: + return ret; +} + +/** + * efi_init_early() - handle initialization at early stage + * + * external version of __efi_init_early(); expected to be called in + * board_init_r(). + * + * Return: status code + */ +int efi_init_early(void) +{ + efi_status_t ret; + + ret = __efi_init_early(); + if (ret != EFI_SUCCESS) { + /* never re-init UEFI subsystem */ + efi_obj_list_initialized = ret; + return -1; + } + return 0; +} + +/** + * efi_init_obj_list() - Initialize and populate EFI object list + * + * Return: status code + */ +efi_status_t efi_init_obj_list(void) +{ + efi_status_t ret = EFI_SUCCESS; + + /* Initialize once only */ + if (efi_obj_list_initialized != OBJ_LIST_NOT_INITIALIZED) + return efi_obj_list_initialized; + + if (!IS_ENABLED(CONFIG_EFI_SETUP_EARLY)) { + ret = __efi_init_early(); + if (ret != EFI_SUCCESS) + goto out; + } + if (IS_ENABLED(CONFIG_EFI_RNG_PROTOCOL)) { ret = efi_rng_register(); if (ret != EFI_SUCCESS) From patchwork Tue Apr 19 01:05:12 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1618597 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=oZj6W2os; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kj5Hv4Dl7z9sFx for ; Tue, 19 Apr 2022 11:07:23 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3ACDF83DC8; Tue, 19 Apr 2022 03:06:52 +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="oZj6W2os"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 674D683D07; Tue, 19 Apr 2022 03:06:07 +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-x1035.google.com (mail-pj1-x1035.google.com [IPv6:2607:f8b0:4864:20::1035]) (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 AF75283CF7 for ; Tue, 19 Apr 2022 03:05:56 +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-x1035.google.com with SMTP id mm4-20020a17090b358400b001cb93d8b137so819014pjb.2 for ; Mon, 18 Apr 2022 18:05:56 -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=2efJQefKSbtDOhaTgGEEp5k6x3B/OY/cH9I91c8yY/8=; b=oZj6W2osd0j21PEBLKR9wh4MWt2aKPqT+J2rrr1ZYbXSJNL5DhoBD6FQ9EkXw7fEnP GG/C9fsnV1imexM00zWRUaZ1l2y/eAHYo27TtoNQOQeuF3p+EwEGhKA1Ti/Omtks4+uM mWl1pc/RLRnwedGvy28fJctgqVfCrIXwL05Gf6LQuSNa5Q+bWXhiT5QNNuRG1Lc6AfGM LY7d352aPbyz73MrytxZtwt0891nzhQe+c1tfBdld4tOmiCc9+wGNk892GQB1M8xI0Q1 ax+ItOkM4+V26ixs358xSj1TrByW1EjrZj5vVq1pfbS9AQi4Qhc46a/PdFvnEyX5eSC0 vFeA== 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=2efJQefKSbtDOhaTgGEEp5k6x3B/OY/cH9I91c8yY/8=; b=iWQ2OjLO6trsGj81uV3JPvIkIa2sPh13t6gjJpV+wVvshZxlC8VMJ2+IYJBridNUq3 WtbLZK0L5iUYHIm4a/OD7874kzs32vivfQiehlidDGcUxypW1OtMHiie6sldFD4KrKYA TV+veQvzikXnItnuRzHBmBnVxD+0TDbVPly+b/wewzzSoOfpnAPM4bXPvTuDZSwQMgLp cAGdjGXjiSrWyfC5hCgU/YpR9ER+7eE6kyVw1A9NAeuUQAIsBhAu+KvTwTiFiM9Ih6dJ vawLUUI0q0LpAaCobHC6xa/ITUkiGel4HdFf5yly4Lm+DHEyH919IEXHM5jqY9Sm6oGv uYpw== X-Gm-Message-State: AOAM531ktewbv14fxtpJcqxHB/Foo1Bh29t2EzCEVBYhgLUy7Uhfyw88 CAzZ6AOCdodV/5XH7LjGzNT2gg== X-Google-Smtp-Source: ABdhPJzUZImtiZOu/2AtTJ/fzbDL6EGRqiPAprSF/1WyBwhsCbO60hHPE2FjS33gY3KlHm0Aw6yvtg== X-Received: by 2002:a17:902:d4cb:b0:15a:872:a71 with SMTP id o11-20020a170902d4cb00b0015a08720a71mr2042599plg.151.1650330355022; Mon, 18 Apr 2022 18:05:55 -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.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 18:05:54 -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 07/12] efi_loader: disk: a helper function to create efi_disk objects from udevice Date: Tue, 19 Apr 2022 10:05:12 +0900 Message-Id: <20220419010517.47175-8-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 Add efi_disk_probe() function. This function creates an efi_disk object for a raw disk device (UCLASS_BLK) and additional objects for related partitions (UCLASS_PARTITION). So this function is expected to be called through driver model's "probe" interface every time one raw disk device is detected and activated. We assume that partition devices (UCLASS_PARTITION) have been created when this function is invoked. Signed-off-by: AKASHI Takahiro --- include/efi_loader.h | 4 +- lib/efi_driver/efi_block_device.c | 34 ++--- lib/efi_loader/Kconfig | 3 + lib/efi_loader/efi_disk.c | 201 +++++++++++++++++++----------- lib/efi_loader/efi_setup.c | 4 +- 5 files changed, 143 insertions(+), 103 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 5bb8fb2acd04..ba79a9afb404 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -525,8 +525,8 @@ void efi_carve_out_dt_rsv(void *fdt); void efi_try_purge_kaslr_seed(void *fdt); /* Called by bootefi to make console interface available */ efi_status_t efi_console_register(void); -/* Called by bootefi to make all disk storage accessible as EFI objects */ -efi_status_t efi_disk_register(void); +/* Called by efi_init_obj_list() to initialize efi_disks */ +efi_status_t efi_disk_init(void); /* Called by efi_init_obj_list() to install EFI_RNG_PROTOCOL */ efi_status_t efi_rng_register(void); /* Called by efi_init_obj_list() to install EFI_TCG2_PROTOCOL */ diff --git a/lib/efi_driver/efi_block_device.c b/lib/efi_driver/efi_block_device.c index 04cb3ef0d4e5..5baa6f87a375 100644 --- a/lib/efi_driver/efi_block_device.c +++ b/lib/efi_driver/efi_block_device.c @@ -35,6 +35,7 @@ #include #include #include +#include /* * EFI attributes of the udevice handled by this driver. @@ -106,25 +107,6 @@ static ulong efi_bl_write(struct udevice *dev, lbaint_t blknr, lbaint_t blkcnt, return blkcnt; } -/** - * Create partions for the block device. - * - * @handle: EFI handle of the block device - * @dev: udevice of the block device - * Return: number of partitions created - */ -static int efi_bl_bind_partitions(efi_handle_t handle, struct udevice *dev) -{ - struct blk_desc *desc; - const char *if_typename; - - desc = dev_get_uclass_plat(dev); - if_typename = blk_get_if_type_name(desc->if_type); - - return efi_disk_create_partitions(handle, desc, if_typename, - desc->devnum, dev->name); -} - /** * Create a block device for a handle * @@ -139,7 +121,6 @@ static int efi_bl_bind(efi_handle_t handle, void *interface) char *name; struct efi_object *obj = efi_search_obj(handle); struct efi_block_io *io = interface; - int disks; struct efi_blk_plat *plat; EFI_PRINT("%s: handle %p, interface %p\n", __func__, handle, io); @@ -173,15 +154,20 @@ static int efi_bl_bind(efi_handle_t handle, void *interface) plat->handle = handle; plat->io = interface; + /* + * FIXME: necessary because we won't do almost nothing in + * efi_disk_create() when called from device_probe(). + */ + ret = dev_tag_set_ptr(bdev, DM_TAG_EFI, handle); + if (ret) + /* FIXME: cleanup for bdev */ + return ret; + ret = device_probe(bdev); if (ret) return ret; EFI_PRINT("%s: block device '%s' created\n", __func__, bdev->name); - /* Create handles for the partions of the block device */ - disks = efi_bl_bind_partitions(handle, bdev); - EFI_PRINT("Found %d partitions\n", disks); - return 0; } diff --git a/lib/efi_loader/Kconfig b/lib/efi_loader/Kconfig index bc518d7a413b..6b245f50a726 100644 --- a/lib/efi_loader/Kconfig +++ b/lib/efi_loader/Kconfig @@ -14,6 +14,8 @@ config EFI_LOADER depends on DM_ETH || !NET depends on !EFI_APP default y if !ARM || SYS_CPU = armv7 || SYS_CPU = armv8 + select DM_EVENT + select EVENT_DYNAMIC select LIB_UUID imply PARTITION_UUIDS select HAVE_BLOCK_DEVICE @@ -40,6 +42,7 @@ config CMD_BOOTEFI_BOOTMGR config EFI_SETUP_EARLY bool + default y choice prompt "Store for non-volatile UEFI variables" diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index c905c12abc2f..d4a0edb458b8 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -10,6 +10,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -487,103 +490,153 @@ error: return ret; } -/** - * efi_disk_create_partitions() - create handles and protocols for partitions +/* + * Create a handle for a whole raw disk + * + * @dev uclass device (UCLASS_BLK) * - * Create handles and protocols for the partitions of a block device. + * Create an efi_disk object which is associated with @dev. + * The type of @dev must be UCLASS_BLK. * - * @parent: handle of the parent disk - * @desc: block device - * @if_typename: interface type - * @diskid: device number - * @pdevname: device name - * Return: number of partitions created + * @return 0 on success, -1 otherwise */ -int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc, - const char *if_typename, int diskid, - const char *pdevname) +static int efi_disk_create_raw(struct udevice *dev) { - int disks = 0; - char devname[32] = { 0 }; /* dp->str is u16[32] long */ - int part; - struct efi_device_path *dp = NULL; + struct efi_disk_obj *disk; + struct blk_desc *desc; + const char *if_typename; + int diskid; efi_status_t ret; - struct efi_handler *handler; - /* Get the device path of the parent */ - ret = efi_search_protocol(parent, &efi_guid_device_path, &handler); - if (ret == EFI_SUCCESS) - dp = handler->protocol_interface; - - /* Add devices for each partition */ - for (part = 1; part <= MAX_SEARCH_PARTITIONS; part++) { - struct disk_partition info; - - if (part_get_info(desc, part, &info)) - continue; - snprintf(devname, sizeof(devname), "%s:%x", pdevname, - part); - ret = efi_disk_add_dev(parent, dp, if_typename, desc, diskid, - &info, part, NULL); - if (ret != EFI_SUCCESS) { - log_err("Adding partition %s failed\n", pdevname); - continue; - } - disks++; + desc = dev_get_uclass_plat(dev); + if_typename = blk_get_if_type_name(desc->if_type); + diskid = desc->devnum; + + ret = efi_disk_add_dev(NULL, NULL, if_typename, desc, + diskid, NULL, 0, &disk); + if (ret != EFI_SUCCESS) { + if (ret == EFI_NOT_READY) + log_notice("Disk %s not ready\n", dev->name); + else + log_err("Adding disk for %s failed\n", dev->name); + + return -1; + } + if (dev_tag_set_ptr(dev, DM_TAG_EFI, &disk->header)) { + efi_free_pool(disk->dp); + efi_delete_handle(&disk->header); + + return -1; } - return disks; + return 0; } -/** - * efi_disk_register() - register block devices - * - * U-Boot doesn't have a list of all online disk devices. So when running our - * EFI payload, we scan through all of the potentially available ones and - * store them in our object pool. +/* + * Create a handle for a disk partition * - * This function is called in efi_init_obj_list(). + * @dev uclass device (UCLASS_PARTITION) * - * TODO(sjg@chromium.org): Actually with CONFIG_BLK, U-Boot does have this. - * Consider converting the code to look up devices as needed. The EFI device - * could be a child of the UCLASS_BLK block device, perhaps. + * Create an efi_disk object which is associated with @dev. + * The type of @dev must be UCLASS_PARTITION. * - * Return: status code + * @return 0 on success, -1 otherwise */ -efi_status_t efi_disk_register(void) +static int efi_disk_create_part(struct udevice *dev) { + efi_handle_t parent; + struct blk_desc *desc; + const char *if_typename; + struct disk_part *part_data; + struct disk_partition *info; + unsigned int part; + int diskid; + struct efi_handler *handler; + struct efi_device_path *dp_parent; struct efi_disk_obj *disk; - int disks = 0; efi_status_t ret; + + if (dev_tag_get_ptr(dev_get_parent(dev), DM_TAG_EFI, (void **)&parent)) + return -1; + + desc = dev_get_uclass_plat(dev_get_parent(dev)); + if_typename = blk_get_if_type_name(desc->if_type); + diskid = desc->devnum; + + part_data = dev_get_uclass_plat(dev); + part = part_data->partnum; + info = &part_data->gpt_part_info; + + ret = efi_search_protocol(parent, &efi_guid_device_path, &handler); + if (ret != EFI_SUCCESS) + return -1; + dp_parent = (struct efi_device_path *)handler->protocol_interface; + + ret = efi_disk_add_dev(parent, dp_parent, if_typename, desc, diskid, + info, part, &disk); + if (ret != EFI_SUCCESS) { + log_err("Adding partition for %s failed\n", dev->name); + return -1; + } + if (dev_tag_set_ptr(dev, DM_TAG_EFI, &disk->header)) { + efi_free_pool(disk->dp); + efi_delete_handle(&disk->header); + + return -1; + } + + return 0; +} + +/* + * Create efi_disk objects for a block device + * + * @dev uclass device (UCLASS_BLK) + * + * Create efi_disk objects for partitions as well as a raw disk + * which is associated with @dev. + * The type of @dev must be UCLASS_BLK. + * This function is expected to be called at EV_PM_POST_PROBE. + * + * @return 0 on success, -1 otherwise + */ +static int efi_disk_probe(void *ctx, struct event *event) +{ struct udevice *dev; + enum uclass_id id; + struct udevice *child; + int ret; - for (uclass_first_device_check(UCLASS_BLK, &dev); dev; - uclass_next_device_check(&dev)) { - struct blk_desc *desc = dev_get_uclass_plat(dev); - const char *if_typename = blk_get_if_type_name(desc->if_type); + dev = event->data.dm.dev; + id = device_get_uclass_id(dev); - /* Add block device for the full device */ - log_info("Scanning disk %s...\n", dev->name); - ret = efi_disk_add_dev(NULL, NULL, if_typename, - desc, desc->devnum, NULL, 0, &disk); - if (ret == EFI_NOT_READY) { - log_notice("Disk %s not ready\n", dev->name); - continue; - } - if (ret) { - log_err("ERROR: failure to add disk device %s, r = %lu\n", - dev->name, ret & ~EFI_ERROR_MASK); - continue; - } - disks++; + /* TODO: We won't support partitions in a partition */ + if (id != UCLASS_BLK) + return 0; + + ret = efi_disk_create_raw(dev); + if (ret) + return -1; - /* Partitions show up as block devices in EFI */ - disks += efi_disk_create_partitions( - &disk->header, desc, if_typename, - desc->devnum, dev->name); + device_foreach_child(child, dev) { + ret = efi_disk_create_part(child); + if (ret) + return -1; } - log_info("Found %d disks\n", disks); + return 0; +} + +efi_status_t efi_disk_init(void) +{ + int ret; + + ret = event_register("efi_disk add", EVT_DM_POST_PROBE, + efi_disk_probe, NULL); + if (ret) { + log_err("Event registration for efi_disk add failed\n"); + return EFI_OUT_OF_RESOURCES; + } return EFI_SUCCESS; } diff --git a/lib/efi_loader/efi_setup.c b/lib/efi_loader/efi_setup.c index de2f34bab537..250eeb2fcd6b 100644 --- a/lib/efi_loader/efi_setup.c +++ b/lib/efi_loader/efi_setup.c @@ -198,9 +198,7 @@ static efi_status_t __efi_init_early(void) if (ret != EFI_SUCCESS) goto out; -#ifdef CONFIG_PARTITIONS - ret = efi_disk_register(); -#endif + ret = efi_disk_init(); out: return ret; } From patchwork Tue Apr 19 01:05:13 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1618594 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=znSPGsk3; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kj5HS4KRvz9sFx for ; Tue, 19 Apr 2022 11:07:00 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 67EDB83B3D; Tue, 19 Apr 2022 03:06:40 +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="znSPGsk3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 11A5183C7B; Tue, 19 Apr 2022 03:06:10 +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-pl1-x62e.google.com (mail-pl1-x62e.google.com [IPv6:2607:f8b0:4864:20::62e]) (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 EF3DA83B4E for ; Tue, 19 Apr 2022 03:05:58 +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-pl1-x62e.google.com with SMTP id v12so13738143plv.4 for ; Mon, 18 Apr 2022 18:05:58 -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=j/16UycWtqTLoNpUdQHYPcu4PfFK9e8OHWjqkEtJQ2g=; b=znSPGsk3hLRPEkvKTl9juCveLElJTDYj1gimMfREzD7fIsJJiGXJHvy6/jA2GcXQrR qW/JUCe3jEG+D7nLwOV8qXeKsaWqAaBbL1UO2nAFI1Q3KIKwy7WMb4vKpa6s0BGuoeko 8Wau1Q0buFFfuslZD/vPQDaO3c4mYvzI5RO9MWYa3omeQ6i+NCaeJNnTwWHhZikSUA3r QMQxKxiv8PBB9mCHDs3bwW/snOJT1AiPA3C4c3ynZFQP/mnuItJvPyvJw/OhABmkDrke mCjjIySkPgGYtfzHZipVyzC79P9+Zq4R9SaEb+5w9h8jlLNz4zwZe0E4FHNu+Ev9PGuz ZvMA== 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=j/16UycWtqTLoNpUdQHYPcu4PfFK9e8OHWjqkEtJQ2g=; b=Y3FR3bmILkh05PX5KklK3FcEauchIJFrbjENG9P68/PuW4k+jZMjyTNAmpsNVHXIRy nCuhtyXCmPjGmlG7ssH+mJc41MmjYF2iwPG9871LpCdbCnJI56wvYBiGPOFEXS5iVY8s N3n9epxYrGO0MOdYs7uuykssMk5R9yBnGvFTAQtRjbXZ8+RRybT8loi/5dgw54HrACKK yPMSy/dP3lzWBTNdGZhpvUd6bApH7K05is8iaJorSoJAfoW3Hlzo4XbS7Lmek6Nous1y jeleHj0pjQgkuq0X7zkBD+BquoSd48Camjuarcp6cxGSVE/v6vpSBQBIZtWolRHOGzAi QZ+Q== X-Gm-Message-State: AOAM533TJkl+HDq+AahT9D1sV19PMF5vCx5i6wiphNeEj+7V4p7TJNsu t6puArMldg9wgGeVttn1oUWw+VukqYAVQA== X-Google-Smtp-Source: ABdhPJzfiWMX1KhbIqk6B3r10rm6/xh1Ax2LapSHKxPyRZrX5alr+JQCg8cncwAGvTMafArRoHzm0A== X-Received: by 2002:a17:902:e8c6:b0:158:f809:311f with SMTP id v6-20020a170902e8c600b00158f809311fmr8934625plg.4.1650330357340; Mon, 18 Apr 2022 18:05:57 -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.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 18:05:57 -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 08/12] efi_loader: disk: not create BLK device for BLK(IF_TYPE_EFI_LOADER) devices Date: Tue, 19 Apr 2022 10:05:13 +0900 Message-Id: <20220419010517.47175-9-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 When we create an efi_disk device with an UEFI application using driver binding protocol, the 'efi_driver' framework tries to create a corresponding block device(UCLASS_BLK/IF_TYPE_EFI). This will lead to calling a PROBE callback, efi_disk_probe(). In this case, however, we don't need to create another "efi_disk" device as we already have this device instance. So we should avoid recursively invoke further processing in the callback function. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass --- lib/efi_loader/efi_disk.c | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index d4a0edb458b8..037f8594a727 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -604,6 +604,7 @@ static int efi_disk_probe(void *ctx, struct event *event) { struct udevice *dev; enum uclass_id id; + struct blk_desc *desc; struct udevice *child; int ret; @@ -614,9 +615,16 @@ static int efi_disk_probe(void *ctx, struct event *event) if (id != UCLASS_BLK) return 0; - ret = efi_disk_create_raw(dev); - if (ret) - return -1; + /* + * avoid creating duplicated objects now that efi_driver + * has already created an efi_disk at this moment. + */ + desc = dev_get_uclass_plat(dev); + if (desc->if_type != IF_TYPE_EFI_LOADER) { + ret = efi_disk_create_raw(dev); + if (ret) + return -1; + } device_foreach_child(child, dev) { ret = efi_disk_create_part(child); 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: 1618595 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=fZtG1bbE; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kj5Hg3lW7z9sFx for ; Tue, 19 Apr 2022 11:07:11 +1000 (AEST) 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-Google-Smtp-Source: ABdhPJyuhFGy4eWAMwKKYOTdu3/M0OHoptpmY7238GNppHe5k797ho7x9RfAqsggq9IosVNSv50YNw== 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; } From patchwork Tue Apr 19 01:05:15 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1618598 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=lj1/6pyR; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [IPv6:2a01:238:438b:c500:173d:9f52:ddab:ee01]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kj5J772Wbz9sFx for ; Tue, 19 Apr 2022 11:07:35 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7FB4083DB6; Tue, 19 Apr 2022 03:06:56 +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="lj1/6pyR"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id CA68983D62; 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-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (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 E0A7983C8C for ; Tue, 19 Apr 2022 03:06:03 +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-x1030.google.com with SMTP id o5so14448998pjr.0 for ; Mon, 18 Apr 2022 18:06:03 -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=iM8IiiuHSbTPbKVfkhnxnKS9CR4E6GlTaqdcIdJsPes=; b=lj1/6pyRPvdn6kD0zhnxanqG/DhGgBmGTEeZPT6WHc4tHobe8FeroR3cJuOGHRzGsx IdmhgYfUKm10RsRonuKuBN/0tWAWIp91WYieo6OwEl/+DqBaJKwfrxGT6lOq26CAeIiT lTFqnAzwd4i37rG0akFHln2wPJzx8tDKMT+4DWg3lpmIPIR/A/fiCd/LLJTwEONOy83N 02r96uTWMKbMPsT9SFv5cltaw/gMRj9j6+FyIWfIBQd2LtEpm9JSpkrznbiOV+T9l0iK xWRcgBpRPhDqDEILGIx+4yG/jnNvOxbqLCRamGPtm/pEtuPzoY8mW4HiTVHlES8vaDRs /pTg== 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=iM8IiiuHSbTPbKVfkhnxnKS9CR4E6GlTaqdcIdJsPes=; b=5N5JAdKwjXYSCeOq/GManUEOYEV7+Ey/+57IWsiHnI/4JtANl7Qou6vs9Q3jrQ6LAj U7sSOiLY6jk6hmhSK14JdaZOsxBK4/KvkxezYLZ6umrjcg2VTbpTdbaPFgCTDLN2Ed+z 1T4dGnbRgpo7PnTnLi/VicY56wiD0hQdFJmliwZ4hozlTb4yDcj8eFtYbwL+8F82Gq5P nbHQjv4znpd+LXQyKi8PvE7czpJTNqcsblXpZXFJ4F0ZEOwxDIxeds7PmlI7GlH4Sgce 6zh11Zl6Wra8ysep0ccxcuBhAYgdQyusGzxU2TKMo5x5cCdl/NgWXYps8gggMoo+zsg2 I8YQ== X-Gm-Message-State: AOAM5325tKERvJWY03wxSQKPCnsuEa81FJAfcojQztvdM0WhwadiflAO 7X+/C64eHAVXNah8KtGn1mNKDA== X-Google-Smtp-Source: ABdhPJxRtgs0asd7dpIRowacvoZZilQ31U+8WSjQSiyHazEabJ3fAXK23578LtjMvMOvXrlDU/Ks9A== X-Received: by 2002:a17:902:7296:b0:151:62b1:e2b0 with SMTP id d22-20020a170902729600b0015162b1e2b0mr12915881pll.165.1650330361904; Mon, 18 Apr 2022 18:06:01 -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.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 18:06:01 -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 10/12] efi_loader: disk: not delete BLK device for BLK(IF_TYPE_EFI_LOADER) devices Date: Tue, 19 Apr 2022 10:05:15 +0900 Message-Id: <20220419010517.47175-11-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 When we create an efi_disk device with an UEFI application using driver binding protocol, the 'efi_driver' framework tries to create a corresponding block device(UCLASS_BLK/IF_TYPE_EFI). This will lead to calling a PROBE callback, efi_disk_probe(). In this case, however, we don't need to create another "efi_disk" device as we already have this device instance. So we should avoid recursively invoke further processing in the callback function. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass --- lib/efi_loader/efi_disk.c | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 940390ac8bcc..34bb662e9cc0 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -648,13 +648,17 @@ static int efi_disk_probe(void *ctx, struct event *event) static int efi_disk_delete_raw(struct udevice *dev) { efi_handle_t handle; + struct blk_desc *desc; 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); + desc = dev_get_uclass_plat(dev); + if (desc->if_type != IF_TYPE_EFI_LOADER) { + 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); From patchwork Tue Apr 19 01:05:16 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1618602 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=Mmjy1TL3; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kj5JS1cbtz9sFx for ; Tue, 19 Apr 2022 11:07:52 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id F17EB83DEB; Tue, 19 Apr 2022 03:07:17 +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="Mmjy1TL3"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id B201883D7A; Tue, 19 Apr 2022 03:06:12 +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-x52a.google.com (mail-pg1-x52a.google.com [IPv6:2607:f8b0:4864:20::52a]) (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 866E583D87 for ; Tue, 19 Apr 2022 03:06:06 +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-x52a.google.com with SMTP id bg9so21961151pgb.9 for ; Mon, 18 Apr 2022 18:06:06 -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=4wYb7tEoKo57lYnVDu9KLBr+sDHPj+ghJWaUwTkHj10=; b=Mmjy1TL3yqLVYyTSpA/jRmyqDUYuVOphz8XFYb8kEzbrciR8APwr/femo6Vc8RS2UO ElfDdq4Pae4X73eMQwsiwF0Xrl0e1/a9mY3WDw85qEXjnCXQg6gqyKho5fkKx6S/9Iz1 0Cl06QD4jHyA7eETVaBJBugutP3SWy6VB3eYb/ZKJdH7ZmF/gblQDcVN6CAenQCStB/B KtC/+AAD91WyhLWOgjoqA+wLjF598XbaBrb88sutR9ubpXRtpN6boiO3tLrhFv2Utol8 s8ni4+PReS/WFyyaAbu2FRA/Lx5HvhudZQCiUUcEjqr8xVo0JRHiwcl6v1Hp6IHnmUmg Uaiw== 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=4wYb7tEoKo57lYnVDu9KLBr+sDHPj+ghJWaUwTkHj10=; b=P7jGrmIWqhQ473IJK85y980P5d2Ad5HtOcOc4hyNVibfL28rDjVJstxlm22l1lWP0/ B/+vT4p9X4VCaRFo5DV0R/ggfzTG2e6Ya/n7rOR+sRSeIsO7wa2gtYZ7Cjo7up42HSvc syKem0azUu4W303PntqNn600BqXlxFY/6/vQSUOxn9Vkh7/HQ3aGQ6DWpl6E76X0nhEF 5Y1Q5INkyGYbXel1D1E3fDFYJJTnFnN/xOxr/Fg3wFPzzD7UK6lBSDDYlQ3ixXkUHrcf sO2Ah4e9Kt8eY7U5/Z9oSzZDLNK4Qaf0Y0NHpsRs2ygk9dEg8195r279ZjPH4SsXUQDw 2aSA== X-Gm-Message-State: AOAM532T/u2eQVUIn6X9QdaSz/1hxi+LzviHLy1+u8gcfuK1FR1u3kIW BnJbl9WT6oOVJvS76fsPTfXNVA== X-Google-Smtp-Source: ABdhPJwoaYrGhuhSzn6bg4Rl6WWaZTvl8UEVG9ouKgXlL0zaFOYNlhDgr4bVWM8QYOJMX3V4KI1k1Q== X-Received: by 2002:a65:4381:0:b0:3a2:ca0a:7ed8 with SMTP id m1-20020a654381000000b003a2ca0a7ed8mr12188238pgp.15.1650330364361; Mon, 18 Apr 2022 18:06:04 -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.06.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 18:06:04 -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 11/12] dm: disk: add read/write interfaces with udevice Date: Tue, 19 Apr 2022 10:05:16 +0900 Message-Id: <20220419010517.47175-12-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 In include/blk.h, Simon suggested: ===> /* * These functions should take struct udevice instead of struct blk_desc, * but this is convenient for migration to driver model. Add a 'd' prefix * to the function operations, so that blk_read(), etc. can be reserved for * functions with the correct arguments. */ unsigned long blk_dread(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, void *buffer); unsigned long blk_dwrite(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt, const void *buffer); unsigned long blk_derase(struct blk_desc *block_dev, lbaint_t start, lbaint_t blkcnt); <=== So new interfaces are provided with this patch. They are expected to be used everywhere in U-Boot at the end. The exceptions are block device drivers, partition drivers and efi_disk which should know details of blk_desc structure. Signed-off-by: AKASHI Takahiro --- disk/disk-uclass.c | 94 ++++++++++++++++++++++++++++++++++++++++++++++ include/part.h | 7 ++++ 2 files changed, 101 insertions(+) diff --git a/disk/disk-uclass.c b/disk/disk-uclass.c index 4918a2f72d1e..72ff62ebf581 100644 --- a/disk/disk-uclass.c +++ b/disk/disk-uclass.c @@ -146,6 +146,100 @@ U_BOOT_DRIVER(blk_partition) = { .ops = &blk_part_ops, }; +/* + * BLOCK IO APIs + */ +static struct blk_desc *dev_get_blk(struct udevice *dev) +{ + struct blk_desc *block_dev; + + switch (device_get_uclass_id(dev)) { + /* + * We won't support UCLASS_BLK with dev_* interfaces. + */ + case UCLASS_PARTITION: + block_dev = dev_get_uclass_plat(dev_get_parent(dev)); + break; + default: + block_dev = NULL; + break; + } + + return block_dev; +} + +unsigned long dev_read(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, void *buffer) +{ + struct blk_desc *block_dev; + const struct blk_ops *ops; + struct disk_part *part; + lbaint_t start_in_disk; + ulong blks_read; + + block_dev = dev_get_blk(dev); + if (!block_dev) + return -ENOSYS; + + ops = blk_get_ops(dev); + if (!ops->read) + return -ENOSYS; + + start_in_disk = start; + if (device_get_uclass_id(dev) == UCLASS_PARTITION) { + part = dev_get_uclass_plat(dev); + start_in_disk += part->gpt_part_info.start; + } + + if (blkcache_read(block_dev->if_type, block_dev->devnum, + start_in_disk, blkcnt, block_dev->blksz, buffer)) + return blkcnt; + blks_read = ops->read(dev, start, blkcnt, buffer); + if (blks_read == blkcnt) + blkcache_fill(block_dev->if_type, block_dev->devnum, + start_in_disk, blkcnt, block_dev->blksz, buffer); + + return blks_read; +} + +unsigned long dev_write(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, const void *buffer) +{ + struct blk_desc *block_dev; + const struct blk_ops *ops; + + block_dev = dev_get_blk(dev); + if (!block_dev) + return -ENOSYS; + + ops = blk_get_ops(dev); + if (!ops->write) + return -ENOSYS; + + blkcache_invalidate(block_dev->if_type, block_dev->devnum); + + return ops->write(dev, start, blkcnt, buffer); +} + +unsigned long dev_erase(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt) +{ + struct blk_desc *block_dev; + const struct blk_ops *ops; + + block_dev = dev_get_blk(dev); + if (!block_dev) + return -ENOSYS; + + ops = blk_get_ops(dev); + if (!ops->erase) + return -ENOSYS; + + blkcache_invalidate(block_dev->if_type, block_dev->devnum); + + return ops->erase(dev, start, blkcnt); +} + UCLASS_DRIVER(partition) = { .id = UCLASS_PARTITION, .per_device_plat_auto = sizeof(struct disk_part), diff --git a/include/part.h b/include/part.h index c4e0bef7749d..4956cec314ed 100644 --- a/include/part.h +++ b/include/part.h @@ -306,6 +306,13 @@ struct udevice; */ int part_create_block_devices(struct udevice *blk_dev); +unsigned long dev_read(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, void *buffer); +unsigned long dev_write(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt, const void *buffer); +unsigned long dev_erase(struct udevice *dev, lbaint_t start, + lbaint_t blkcnt); + /* * We don't support printing partition information in SPL and only support * getting partition information in a few cases. From patchwork Tue Apr 19 01:05:17 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 1618603 X-Patchwork-Delegate: xypron.glpk@gmx.de Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Authentication-Results: bilbo.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=linaro.org header.i=@linaro.org header.a=rsa-sha256 header.s=google header.b=xGyUKgFF; dkim-atps=neutral Authentication-Results: ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=lists.denx.de (client-ip=85.214.62.61; helo=phobos.denx.de; envelope-from=u-boot-bounces@lists.denx.de; receiver=) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by bilbo.ozlabs.org (Postfix) with ESMTPS id 4Kj5Jg3mPFz9sFx for ; Tue, 19 Apr 2022 11:08:03 +1000 (AEST) Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 7DDFC83DF3; Tue, 19 Apr 2022 03:07:26 +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="xGyUKgFF"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 6A94783DA7; Tue, 19 Apr 2022 03:06:18 +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 7953E83DA3 for ; Tue, 19 Apr 2022 03:06:08 +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 t13so21988326pgn.8 for ; Mon, 18 Apr 2022 18:06:08 -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=ttzRaXmF+uRsWc3HJfIzPa3gWWQ85JO83DmWjnDfnrM=; b=xGyUKgFFKY2ooMkM38FcPTuaCvEV0i0k/Pqdfp/D/vKc3t9k1VY7JBt0uBSftBMo8n 6/oKmH51TZHyLLBCZWA/+lOMRhn99bo0K+fnED2btORTLxCM4Dcvf/aYtrWp8BcjHJXW DObENk71g/soBA3sLQOP+HowtJZziM+YYu17S3a8mMnlX/ZVHe/zpcG9o0cNVMcCUMem cK5SU8+6lgQJd/6AMYRLVTqKwZ63fGZGFA1r+7wK+OiJGL5H2p/YQIUKS/lcjlKs0mfy MdSNyJ9wGQQOQnxKIpfyBJMji2hLCie/LHS6lYcUpzdYNeUenh5M8rRivr74e5mkFvdK w/yg== 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=ttzRaXmF+uRsWc3HJfIzPa3gWWQ85JO83DmWjnDfnrM=; b=A6HsppUoBt7UvhIBzVfUdOseEfco7wH9Axkd3TfKOcXIwSfs9Rp79U5Y9gZVgW5pzO r1AOZKqcjXdJns47gRkWLsBTRUwwkfEIf9wUHtyJM9BYx4VdymWNPPHkFf1jaGHtLwbH F4+tHGNmaZADwLOen9VzAzutYDjgTaEJWnpNdCJ25ALZRQZQ4BKHnv0HFHtd3liiAIUg QFGHZqZIJ5q6kl9hN9cK5vab+s+MDNe2C35MhDq9gOUbgnAIVBMO5VGgwljhPcOY/gid 7VgV9PQr5mAymnHToCyzVDch33p1dU5lO/uasAzlvvoJ3G1HWDuShMB4bvuAy2BybeDk unVA== X-Gm-Message-State: AOAM532iE0gGrQXzy3QOW4xX0TB6mAT5rVT9G3fBR3YlR4/7Lu3jY6YP 3QhbvaWOlp7E5XbDmqK5VpDDOw== X-Google-Smtp-Source: ABdhPJzhvyeVqmlon/1ytuGAUwVryu1IPjF26vk1UAQRmdUX6oPWsiQkyCRjauTDo7dSIlZtwdEQIg== X-Received: by 2002:a63:af06:0:b0:378:3582:a49f with SMTP id w6-20020a63af06000000b003783582a49fmr12324720pge.125.1650330366826; Mon, 18 Apr 2022 18:06:06 -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.06.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 18 Apr 2022 18:06:06 -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 12/12] efi_loader: disk: use udevice instead of blk_desc Date: Tue, 19 Apr 2022 10:05:17 +0900 Message-Id: <20220419010517.47175-13-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 In most of all cases, we can avoid using blk_desc which is expected to be private to udevice(UCLASS_BLK), that is, the data should not be manipulated outside the device driver unless really needed. Now efi_disk's internally use dev_read/write() interfaces if CONFIG_PARTITIONS is enabled. Signed-off-by: AKASHI Takahiro Reviewed-by: Simon Glass --- lib/efi_loader/efi_disk.c | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 34bb662e9cc0..8fb5b2363c45 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -36,7 +36,7 @@ const efi_guid_t efi_system_partition_guid = PARTITION_SYSTEM_GUID; * @part: partition * @volume: simple file system protocol of the partition * @offset: offset into disk for simple partition - * @desc: internal block device descriptor + * @dev: associated DM device */ struct efi_disk_obj { struct efi_object header; @@ -48,7 +48,7 @@ struct efi_disk_obj { unsigned int part; struct efi_simple_file_system_protocol *volume; lbaint_t offset; - struct blk_desc *desc; + struct udevice *dev; /* TODO: move it to efi_object */ }; /** @@ -83,14 +83,12 @@ static efi_status_t efi_disk_rw_blocks(struct efi_block_io *this, void *buffer, enum efi_disk_direction direction) { struct efi_disk_obj *diskobj; - struct blk_desc *desc; int blksz; int blocks; unsigned long n; diskobj = container_of(this, struct efi_disk_obj, ops); - desc = (struct blk_desc *) diskobj->desc; - blksz = desc->blksz; + blksz = diskobj->media.block_size; blocks = buffer_size / blksz; lba += diskobj->offset; @@ -101,10 +99,21 @@ static efi_status_t efi_disk_rw_blocks(struct efi_block_io *this, if (buffer_size & (blksz - 1)) return EFI_BAD_BUFFER_SIZE; +#if CONFIG_IS_ENABLED(PARTITIONS) + if (direction == EFI_DISK_READ) + n = dev_read(diskobj->dev, lba, blocks, buffer); + else + n = dev_write(diskobj->dev, lba, blocks, buffer); +#else + /* dev is always a block device (UCLASS_BLK) */ + struct blk_desc *desc; + + desc = dev_get_uclass_plat(diskobj->dev); if (direction == EFI_DISK_READ) n = blk_dread(desc, lba, blocks, buffer); else n = blk_dwrite(desc, lba, blocks, buffer); +#endif /* We don't do interrupts, so check for timers cooperatively */ efi_timer_check(); @@ -446,7 +455,6 @@ static efi_status_t efi_disk_add_dev( diskobj->ops = block_io_disk_template; diskobj->ifname = if_typename; diskobj->dev_index = dev_index; - diskobj->desc = desc; /* Fill in EFI IO Media info (for read/write callbacks) */ diskobj->media.removable_media = desc->removable; @@ -522,6 +530,7 @@ static int efi_disk_create_raw(struct udevice *dev) return -1; } + disk->dev = dev; if (dev_tag_set_ptr(dev, DM_TAG_EFI, &disk->header)) { efi_free_pool(disk->dp); efi_delete_handle(&disk->header); @@ -578,6 +587,7 @@ static int efi_disk_create_part(struct udevice *dev) log_err("Adding partition for %s failed\n", dev->name); return -1; } + disk->dev = dev; if (dev_tag_set_ptr(dev, DM_TAG_EFI, &disk->header)) { efi_free_pool(disk->dp); efi_delete_handle(&disk->header);