From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 164FDC433F5 for ; Tue, 5 Oct 2021 02:14:24 +0000 (UTC) Received: from phobos.denx.de (phobos.denx.de [85.214.62.61]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 1589661373 for ; Tue, 5 Oct 2021 02:14:22 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org 1589661373 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=pass smtp.mailfrom=lists.denx.de Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 45489805F9; Tue, 5 Oct 2021 04:14:20 +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="uVuMypbn"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id EB76280641; Tue, 5 Oct 2021 04:14:18 +0200 (CEST) Received: from mail-pj1-x1034.google.com (mail-pj1-x1034.google.com [IPv6:2607:f8b0:4864:20::1034]) (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 9E7598033A for ; Tue, 5 Oct 2021 04:14:14 +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-x1034.google.com with SMTP id na16-20020a17090b4c1000b0019f5bb661f9so1240730pjb.0 for ; Mon, 04 Oct 2021 19:14:14 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=date:from:to:cc:subject:message-id:mail-followup-to:references :mime-version:content-disposition:in-reply-to; bh=oymoJLzvSgE+Y6Uyfby4aR3tavnruqY1ymLWXxaPtSU=; b=uVuMypbnczgYEaiN2iSEC+n9TylbONdbv8CXg/m7y5c30Zj0z9tSc8gTvS50DvIBMI TLeAf5Elz1PNxtrSKeEbV36v9Mkz/HxcmzbYnvRka2AW2pcqWLDEFgDCUm3QSHU7wQ8z TtSlj81wvttBq2SMnDccqTf3SYutDByCvSZbPIabRXsUET+uBbNGN/mp9nJnNwZlQtrq U83AW/3npxGFc9sQpWwbMulbA0WiE7qyGRe05lFVCcIW7EJds12TMLekXyVAGIoKSLbJ RUxJ4/5CwOEZY4NAq1wKLPA1OR1oQk7GUHpz9j3Wlzce54JHqhyz+4qPgUYEX6Vp+BxK Umww== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:date:from:to:cc:subject:message-id :mail-followup-to:references:mime-version:content-disposition :in-reply-to; bh=oymoJLzvSgE+Y6Uyfby4aR3tavnruqY1ymLWXxaPtSU=; b=GmJ7VDya5JOrw3tEP3sOnwOyc5Vo5x8CWtMFIx4G+08GImHA9qJEcRELvAHl8wJ0qf 1MBpJtdccnDTlBXdVBy5GsN8tFor/mlDf5ZBeAqm5TGVIZ6nyLTRlIbpdpFKwZ5DfaEb 66Ig1zMgWWMPRs9Yizf6JQ0QGOd8w6qTq2gwbPRa+OKrMdecL2BT2chDwo7ZenEDmnmt 7frMNxr/r3AMw4FVsXjS0elhSfT06luiSQVnuTcSfHcovCiXk5aYqyZjNBBFYvQjkkqz O/fXUOLc1hVl/i1EJSoJO481oZg3wsaHBmcUa22Z+tOjCn/jiDEFIPVUy8HR0BEtgBXs nRRA== X-Gm-Message-State: AOAM5328+UbD+tOCymS5nKP5hR7MGNcHqzxy/lX4iK91hThTuJzeheYK 2yEDET1QKV6a7o1RmNwpj6WTgw== X-Google-Smtp-Source: ABdhPJwi1SPHKXz9+3Z9Pw9O53wNkP/4XRNt+KxHegN9jAixw//WMkTrlsTunLvS/8brGwgE2b7I6Q== X-Received: by 2002:a17:90a:9317:: with SMTP id p23mr603137pjo.151.1633400052096; Mon, 04 Oct 2021 19:14:12 -0700 (PDT) Received: from laputa (122-100-26-39m5.mineo.jp. [122.100.26.39]) by smtp.gmail.com with ESMTPSA id a10sm15715730pgd.91.2021.10.04.19.14.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 04 Oct 2021 19:14:11 -0700 (PDT) Date: Tue, 5 Oct 2021 11:14:06 +0900 From: AKASHI Takahiro To: Heinrich Schuchardt Cc: u-boot@lists.denx.de, agraf@csgraf.de, sjg@chromium.org, ilias.apalodimas@linaro.org Subject: Re: [resent RFC 00/22] efi_loader: more tightly integrate UEFI disks to device model Message-ID: <20211005021406.GD39521@laputa> Mail-Followup-To: AKASHI Takahiro , Heinrich Schuchardt , u-boot@lists.denx.de, agraf@csgraf.de, sjg@chromium.org, ilias.apalodimas@linaro.org References: <20211004034430.41355-1-takahiro.akashi@linaro.org> <88cc8ea2-648e-c86b-37e3-bcdb73c3f482@gmx.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <88cc8ea2-648e-c86b-37e3-bcdb73c3f482@gmx.de> X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.34 Precedence: list List-Id: U-Boot discussion List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: u-boot-bounces@lists.denx.de Sender: "U-Boot" X-Virus-Scanned: clamav-milter 0.103.2 at phobos.denx.de X-Virus-Status: Clean On Mon, Oct 04, 2021 at 04:47:53PM +0200, Heinrich Schuchardt wrote: > > > On 10/4/21 05:44, AKASHI Takahiro wrote: > > # Resending the RFC as some of patches were deplicately submitted. > > # See also > > https://git.linaro.org/people/takahiro.akashi/u-boot.git efi/dm_disk > > > > The purpose of this RPC is to reignite the discussion about how UEFI > > subystem would best be integrated into U-Boot device model. > > In the past, I poposed a couple of patch series, the latest one[1], > > while Heinrich revealed his idea[2], and the approach taken here is > > something between them, with a focus on block device handlings. > > > > # The code is a PoC and not well tested yet. > > > > Disks in UEFI world: > > ==================== > > In general in UEFI world, accessing to any device is performed through > > a 'protocol' interface which are installed to (or associated with) the device's > > UEFI handle (or an opaque pointer to UEFI object data). Protocols are > > implemented by either the UEFI system itself or UEFI drivers. > > > > For block IO's, it is a device which has EFI_BLOCK_IO_PROTOCOL (efi_disk > > hereafter). Currently, every efi_disk may have one of two origins: > > a.U-Boot's block devices or related partitions > > (lib/efi_loader/efi_disk.c) > > b.UEFI objects which are implemented as a block device by UEFI drivers. > > (lib/efi_driver/efi_block_device.c) > > > > All the efi_diskss as (a) will be enumelated and created only once at UEFI > > subsystem initialization (efi_disk_register()), which is triggered by > > first executing one of UEFI-related U-Boot commands, like "bootefi", > > "setenv -e" or "efidebug". > > EFI_BLOCK_IO_PROTOCOL is implemented by UEFI system using blk_desc(->ops) > > in the corresponding udevice(UCLASS_BLK). > > > > On the other hand, efi_disk as (b) will be created each time UEFI boot > > services' connect_controller() is executed in UEFI app which, as a (device) > > controller, gives the method to access the device's data, > > ie. EFI_BLOCK_IO_PROTOCOL. > > > > > > > more details >>> > > Internally, connect_controller() search for UEFI driver that can support > > this controller/protocol, 'efi_block' driver(UCLASS_EFI) in this case, > > then calls the driver's 'bind' interface, which eventually installs > > the controller's EFI_BLOCK_IO_PROTOCOL to efi_disk object. > > 'efi_block' driver also create a corresponding udevice(UCLASS_BLK) for > > * creating additional partitions efi_disk's, and > > * supporting a file system (EFI_SIMPLE_FILE_SYSTEM_PROTOCOL) on it. > > <<< <<< > > > > Issues: > > ======= > > 1. While an efi_disk represents a device equally for either a whole disk > > or a partition in UEFI world, the device model treats only a whole > > disk as a real block device or udevice(UCLASS_BLK). > > > > 2. efi_disk holds and makes use of "blk_desc" data even though blk_desc > > in plat_data is supposed to be private and not to be accessed outside > > the device model. > > # This issue, though, exists for all the implmenetation of U-Boot > > # file systems as well. > > > > For efi_disk(a), > > 3. A block device can be enumelated dynamically by 'scanning' a device bus > > in U-Boot, but UEFI subsystem is not able to update efi_disks accordingly. > > For examples, > > => scsi rescan; efidebug devices > > => usb start; efidebug devices ... (A) > > (A) doesn't show any usb devices detected. > > > > => scsi rescan; efidebug boot add -b 0 TEST scsi 0:1 ... > > => scsi rescan ... (B) > > => bootefi bootmgr ... (C) > > (C) may de-reference a bogus blk_desc pointer which has been freed by (B). > > (Please note that "scsi rescan" removes all udevices/blk_desc and then > > re-create them even if nothing is changed on a bus.) > > > > For efi_disk(b), > > 4. A controller (handle), combined with efi_block driver, has no > > corresponding udevice as a parent of efi_disks in DM tree, unlike, say, > > a scsi controller, even though it provides methods for block io perations. > > 5. There is no way supported to remove efi_disk's even after > > disconnect_controller() is called. > > > > > > My approach in this RFC: > > ======================== > > Due to functional differences in semantics, it would be difficult > > to identify "udevice" structure as a handle in UEFI world. Instead, we will > > have to somehow maintain a relationship between a udevice and a handle. > > > > 1-1. add a dedicated uclass, UCLASS_PARTITION, for partitions > > Currently, the uclass for paritions is not a UCLASS_BLK. > > It can be possible to define partitions as UCLASS_BLK > > (with IF_TYPE_PARTION?), but > > I'm afraid that it may introduce some chaos since udevice(UCLASS_BLK) > > is tightly coupled with 'struct blk_desc' data which is still used > > as a "structure to a whole disk" in a lot of interfaces. > > (I hope that you understand what it means.) > > > > In DM tree, a UCLASS_PARTITON instance has a UCLASS_BLK parent: > > For instance, > > UCLASS_SCSI --- UCLASS_BLK --- UCLASS_PARTITION > > (IF_TYPE_SCSI) | > > +- struct blk_desc +- struct disk_part > > +- scsi_blk_ops +- blk_part_ops > > > > 1-2. create partition udevices in the context of device_probe() > > part_init() is already called in blk_post_probe(). See the commit > > d0851c893706 ("blk: Call part_init() in the post_probe() method"). > > Why not enumelate partitions as well in there. > > > > 2. add new block access interfaces, which takes "udevice" as a target device, > > in U-Boot and use those functions to implement efi_disk operations > > (i.e. EFI_BLOCK_IO_PROTOCOL). > > > > 3-1. maintain a bi-directional link by adding > > - a UEFI handle pointer in "struct udevice" > > - a udevice pointer in UEFI handle (in fact, in "struct efi_disk_obj") > > An EFI application can create handles with any combination of protocols, > e.g. a handle with both the block IO protocol and the simple network > protocol. This means that a udevice cannot be assigned to a handle > created by an EFI application. Can you please elaborate more to clarify your point/suggestion here? > When the EFI application calls ConnectController() for the handle, > U-Boot can create child controllers. If U-Boot creates a udevice for > such a child controller, it has to store the udevice pointer. > lib/efi_driver/efi_block_device.c uses a private data section but you it > could be preferable to use a field in struct efi_obj. Before submitting this RFC, I also thought of a possibility of re-implementing lib/efi_loader/efi_disk.c by defining a "controller" for each U-Boot's block device (udevice) which is essentially a source of providing BLOCK_IO_PROTOCOL as "efi_disk" devices and then implementing "bind" interface of DRIVER_BINDING_PROTOCOL to create a mapping between udevice(UCLASS_BLK) and efi_disk. (Then I hoped we could reuse efi_driver framework for the case (1) below.) Is this similar to what you think of here? As I mentioned, there are two paths in creating efi_disks: 1) U-Boot's block device => efi_disk (efi_disk_add_dev() in lib/efi_loader/efi_disk.c is responsible for this.) 2) EFI app/driver -> efi_disk => U-Boot's block device (efi_bl_bind() in lib/efi_driver/efi_block_device.c) Those two methods try to establish the relationship in opposite directions. This is somewhat a cause of confusion/misunderstanding. > > > > 3-2. use device model's post_probe/pre_remove hook to synchronize the lifetime > > of efi_disk objects in UEFI world with the device model. > > > > 4. I have no answer to issue(4) and (5) yet. > > 4) A udevice shall only exist for the child controller handle created by > U-Boot and not for the controller handle created by an EFI application. I don't know what is a "child" controller, and will think of it. > 5) The stop() method of the driver binding protocol has to take care of > destroying the child controllers and the associated udevices. That is a missing piece of code. -Takahiro Akashi > Best regards > > Heinrich