From patchwork Fri Oct 1 05:01:44 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 514977 Delivered-To: patch@linaro.org Received: by 2002:a02:606e:0:0:0:0:0 with SMTP id d46csp450492jaf; Thu, 30 Sep 2021 22:02:50 -0700 (PDT) X-Google-Smtp-Source: ABdhPJwj/IMMOlbvvklEedgMHHqV7+/M78kqp/1TyYr3/SnHriWhrIiW5E7e3cLZBTfyha5NAzsD X-Received: by 2002:a17:906:fcaf:: with SMTP id qw15mr3931468ejb.506.1633064570437; Thu, 30 Sep 2021 22:02:50 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1633064570; cv=none; d=google.com; s=arc-20160816; b=AY9McpxL+atMaeb7HlHL6e/Detk+BQa4kzsafU41RZK1xscOTfO7ltVp5uzYx1TE5e OsiVByRS3D4MD7S59yRp8w4fNDiAXRTmZJwEQzkMi+7WHI+7ghHO2Wt+uC53VYjMvgZG /rHfKBS+6tR+pMcJ3Yx1p/V2XEZf4nCuZ2nSPPLj7ZmM1iTkJhbdSJWeSQJ3hptmbGjk l14DlcCebmk9WgzD3dimy60Qq4sJ8EFoaQEjVgO7NrZg8DBMRE/0ZUSv8fNkfWs1nZ2w EJh5N7dyGNQc0gdcY9lpPFMBbL9YwS78pb6V1riOnxCt1Np4GvzJ6RTQsUghSlh1d5rq S3AA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:list-subscribe:list-help:list-post:list-archive :list-unsubscribe:list-id:precedence:content-transfer-encoding :mime-version:message-id:date:subject:cc:to:from:dkim-signature; bh=wzOMNia9VW/nGM02Wu7spxBKzUG7S5J/LPepAgqyM7k=; b=npp2jhxS8FjUhmCVqALTcO/Vx/uYyxbTGrkHzl0sfa40RZ5KJ0OQ8iohTVLGqqg9f+ eYe4X0A1c+Tu9PboeNY0VH27YRpfI0LGbKozwLT9UQyLEiFsOvpifoZHv3GgnA+bJhaM AOW/bZZ6RJ2QF7XGJbB2VkS8niYLphX019vwRskexAzeDu5KXJ7rBDmyLvgZu2JiF/iW IvB7MPwfFBDBQSRRH1wfmkZJ1oOyIt7NSmE1hUaZ/E6m1WXNsnDt8szlSouOmdIw+94G tcoFjZhXylG0HSmhEca/z06wfIlhD2ntSOmkaQDp/NBzqW2WF4kfm1toS3eatPgUrr8k lyow== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UEC/+LnS"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from phobos.denx.de (phobos.denx.de. [2a01:238:438b:c500:173d:9f52:ddab:ee01]) by mx.google.com with ESMTPS id kq18si6918517ejb.533.2021.09.30.22.02.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 22:02:50 -0700 (PDT) Received-SPF: pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) client-ip=2a01:238:438b:c500:173d:9f52:ddab:ee01; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b="UEC/+LnS"; spf=pass (google.com: domain of u-boot-bounces@lists.denx.de designates 2a01:238:438b:c500:173d:9f52:ddab:ee01 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from h2850616.stratoserver.net (localhost [IPv6:::1]) by phobos.denx.de (Postfix) with ESMTP id 3DAD881545; Fri, 1 Oct 2021 07:02: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=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="UEC/+LnS"; dkim-atps=neutral Received: by phobos.denx.de (Postfix, from userid 109) id 7FCD380F1A; Fri, 1 Oct 2021 07:02:45 +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 autolearn=ham autolearn_force=no version=3.4.2 Received: from mail-pj1-x102a.google.com (mail-pj1-x102a.google.com [IPv6:2607:f8b0:4864:20::102a]) (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 220AF80F1A for ; Fri, 1 Oct 2021 07:02:41 +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-x102a.google.com with SMTP id me1so5697735pjb.4 for ; Thu, 30 Sep 2021 22:02:41 -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:mime-version :content-transfer-encoding; bh=wzOMNia9VW/nGM02Wu7spxBKzUG7S5J/LPepAgqyM7k=; b=UEC/+LnSEBK6QB69zpkkL6AgsKf/0VKNx8ua8NIJbBwSxI76EEgSWF6NXEUIcU8g8c 9rsiA2ZoK95XNDHkR6KMPbHYpxaFRQYSF6Mb6Og6QwZQU1L94olM9HcfFPDX/DhWyNrB sxLIVetJRgop4bWrLCSWGakpXSeD+aDDOUpYy+FJLI8/qRbJCW9JTzpqfpqzYkJfWw4H 2Qc+YRCGE+sw2s+N96HkA3f+1Zk6diJvOQ+jzLCsgfsUe8QY+3pYMFQEC3o4mhT2xkyv 4bSUH5sTauY1e+PdvqVKbfgtIDH3US60PpCqwMdKNqgDg2eVBFMbsB0ly35+ktLy7CA0 JdxQ== 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:mime-version :content-transfer-encoding; bh=wzOMNia9VW/nGM02Wu7spxBKzUG7S5J/LPepAgqyM7k=; b=mL/Txwi7UhMCTgGJhrJakJeyW0C48K1Sr/PDz8SsKZUkaLegEiDk4PdaCiJHnzsYrc IdpXKIUxuGy7GV2IAXxVomH8ZBJQ2UbYKY1gLY9JIkM8EYhJ6i3axa3VdsC7eo6K/iRj XG3jWFU17wEXTNCLNtLSbdrHlDRbccmpSXVgjlMMwdhTDbVmAOw56fd/khu5KCN2gQKj 6bnpHFCVv9AJpXvDQpJmh1/uF3eEKPfdsxSsyRcZnSo6VbWbHzYFwCMxLiBO4R31N6tf XHZ1OhSiRs5eqzok0JqPSL9NxBH/G8G6FE53iF6kVuXlpe8m/8744b+Wu15y3m/3u8u2 RMew== X-Gm-Message-State: AOAM533yhUt2p+gHatORa8jGfdQ/zwG54TvSN1iQpSJtIVwsaPclkoD6 up3jwzHMRvZj2WHYsxpTe4fy0w== X-Received: by 2002:a17:90a:5ac2:: with SMTP id n60mr10921568pji.184.1633064558884; Thu, 30 Sep 2021 22:02:38 -0700 (PDT) Received: from localhost.localdomain (122-100-26-52m5.mineo.jp. [122.100.26.52]) by smtp.gmail.com with ESMTPSA id z8sm4615113pgc.53.2021.09.30.22.02.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 30 Sep 2021 22:02:38 -0700 (PDT) From: AKASHI Takahiro To: xypron.glpk@gmx.de, agraf@csgraf.de, sjg@chromium.org, ilias.apalodimas@linaro.org Cc: u-boot@lists.denx.de, AKASHI Takahiro Subject: [RFC 00/22] efi_loader: more tightly integrate UEFI disks to device model Date: Fri, 1 Oct 2021 14:01:44 +0900 Message-Id: <20211001050228.55183-1-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.33.0 MIME-Version: 1.0 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 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") 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. Patchs: ======= For easy understandings, patches may be categorized into seperate groups of changes. Patch#1-#9: DM: create udevices for partitions Patch#11,#12: UEFI: use udevice interfaces Patch#13-#16: UEFI: sync up with the device model for adding Patch#17-#19: UEFI: sync up with the device model for removing For removal case, we may need more consideration since removing handles unconditionally may end up breaking integrity of handles (some may still be held and referenced to by a UEFI app). Patch#20-#22: UEFI: align efi_driver with changes by the integration [1] https://lists.denx.de/pipermail/u-boot/2019-February/357923.html [2] https://lists.denx.de/pipermail/u-boot/2021-June/452297.html AKASHI Takahiro (22): scsi: call device_probe() after scanning usb: storage: call device_probe() after scanning mmc: call device_probe() after scanning nvme: call device_probe() after scanning sata: call device_probe() after scanning block: ide: call device_probe() after scanning dm: blk: add UCLASS_PARTITION dm: blk: add a device-probe hook for scanning disk partitions dm: blk: add read/write interfaces with udevice efi_loader: disk: use udevice instead of blk_desc dm: add a hidden link to efi object efi_loader: remove !CONFIG_BLK code from efi_disk efi_loader: disk: a helper function to create efi_disk objects from udevice dm: blk: call efi's device-probe hook efi_loader: cleanup after efi_disk-dm integration efi_loader: add efi_remove_handle() efi_loader: efi_disk: a helper function to delete efi_disk objects dm: blk: call efi's device-removal hook efi_driver: align with efi_disk-dm integration efi_driver: cleanup after efi_disk-dm integration efi_selftest: block device: adjust dp for a test disk (TEST) let dm-tree unchanged after block_io testing is done common/usb_storage.c | 6 + drivers/ata/dwc_ahsata.c | 10 + drivers/ata/fsl_sata.c | 11 + drivers/ata/sata_mv.c | 9 + drivers/ata/sata_sil.c | 12 + drivers/block/blk-uclass.c | 249 ++++++++++++++++ drivers/block/ide.c | 6 + drivers/mmc/mmc-uclass.c | 7 + drivers/nvme/nvme.c | 6 + drivers/scsi/scsi.c | 10 + include/blk.h | 15 + include/dm/device.h | 4 + include/dm/uclass-id.h | 1 + include/efi_loader.h | 8 +- lib/efi_driver/efi_block_device.c | 30 +- lib/efi_loader/efi_boottime.c | 8 + lib/efi_loader/efi_device_path.c | 29 ++ lib/efi_loader/efi_disk.c | 286 ++++++++++--------- lib/efi_loader/efi_setup.c | 5 - lib/efi_selftest/efi_selftest_block_device.c | 28 +- 20 files changed, 566 insertions(+), 174 deletions(-) -- 2.33.0