From patchwork Thu Nov 15 04:58:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: AKASHI Takahiro X-Patchwork-Id: 151160 Delivered-To: patch@linaro.org Received: by 2002:a2e:299d:0:0:0:0:0 with SMTP id p29-v6csp6554167ljp; Wed, 14 Nov 2018 20:57:38 -0800 (PST) X-Google-Smtp-Source: AJdET5fqMbeTxbPNX41of2F0SzeFK9DOPfs8T0vQRiZNZLa7+2olw0R5WfTYBIC8naFH2YnVlAAV X-Received: by 2002:a50:a307:: with SMTP id 7-v6mr4315787edn.231.1542257858248; Wed, 14 Nov 2018 20:57:38 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542257858; cv=none; d=google.com; s=arc-20160816; b=Q9q6GyBABEIw4ivdrQwc92lBx+J6bCVMJvIDBFHuPDk6NtOdqpQ9+Wp/LoFbO7Mi0k plUB2ouffkfYI0rhwZJERIw045FaJk+H4UpRSQqGJBEkp01zrVFAS0GR3q9LkdDPgws2 kWNqeaCJE+z5Znuv3Y6Rl6okkOsZsmWnj0CaiB2rCtU35LvWkIKvzZckqIOsjYg+BSon ZZIZSSP8HodXVGW3ydOyosVVfBvI0YAP83tlS2qxNXcyltZNb9CMgAyDG2PeVZj946rQ Fm+c+wiZIaQjNMqNA0V+AvLRd4ME6oOM0I+OBCe+w65rKxe4dVRPLdKx2QoKFqk2otTZ WFtA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:list-subscribe:list-help :list-post:list-archive:list-unsubscribe:list-id:precedence:subject :cc:mime-version:references:in-reply-to:message-id:date:to:from :dkim-signature; bh=R7Zs2tqxmLWUVkb5xQOEEbmeaM14/O/XhlRknNEYMdw=; b=r1G8gpvjSoP9h9VrTNNY3aVHxFPnUB7+eeOHvZGGQjlMg9GxeqF3Pc/s7xahbyvk+X 5MOF/mKI8K97zHCiaf+UudO2J0tp9sQQxq1rWNl6ViHxrmX7QMEuvNDSS9UMr38NX4Fh GOts+KGemO+gU38CaIt/nQ7/floi3Rj1gw/MdfpLuPNEzd8SZw+WI8GoYcG5mJsgU5Y9 sZzE79GoFbC3ZH7bgfUhdqgeclGEllWpqtWp7t0hiYwtA4eTDJpntmv3TzV4Kow5J2u4 TMFffUNAkKzwyagzhxQm+dv6yuQZQudnu6oo6jMnoEmBqz9dfClbdfcpy26eqS1e0wfr SNiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="Ypq8DN/V"; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from lists.denx.de (dione.denx.de. [81.169.180.215]) by mx.google.com with ESMTP id 35si3638671eds.137.2018.11.14.20.57.37; Wed, 14 Nov 2018 20:57:38 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) client-ip=81.169.180.215; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b="Ypq8DN/V"; spf=pass (google.com: best guess record for domain of u-boot-bounces@lists.denx.de designates 81.169.180.215 as permitted sender) smtp.mailfrom=u-boot-bounces@lists.denx.de; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: by lists.denx.de (Postfix, from userid 105) id DA26AC222EA; Thu, 15 Nov 2018 04:57:04 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on lists.denx.de X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=RCVD_IN_MSPIKE_H2, T_DKIM_INVALID autolearn=unavailable autolearn_force=no version=3.4.0 Received: from lists.denx.de (localhost [IPv6:::1]) by lists.denx.de (Postfix) with ESMTP id A960BC2249D; Thu, 15 Nov 2018 04:56:38 +0000 (UTC) Received: by lists.denx.de (Postfix, from userid 105) id 3CB4AC223FF; Thu, 15 Nov 2018 04:56:16 +0000 (UTC) Received: from mail-yb1-f195.google.com (mail-yb1-f195.google.com [209.85.219.195]) by lists.denx.de (Postfix) with ESMTPS id D30D9C224B8 for ; Thu, 15 Nov 2018 04:56:12 +0000 (UTC) Received: by mail-yb1-f195.google.com with SMTP id h187-v6so7865561ybg.10 for ; Wed, 14 Nov 2018 20:56:12 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=sEmW8TD1fQj+shkOF89uMJsMyVjrnSsOTY5KRyEy8ZM=; b=Ypq8DN/VxpWmXGB0yBFZ38yTMLAzELPiGmns6oWf4gGODhkOMJPbfkWKywJ6+6w+RM s1Nn8ou/9dVZvYnttRJ1tt6PiF8wWcVPmVpvK79EgOAmfND0dAmcpDy+0wG3nrD8ydq+ 1oUJzbvlc1syR+Vwswulb2EFxTd6dqfudqShU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=sEmW8TD1fQj+shkOF89uMJsMyVjrnSsOTY5KRyEy8ZM=; b=uoUTcOM5Ex/126vDVnJvUCJC3K7i/iVDn4aanbJMWB9h0vHl/P2chmp+bMjP8x9tSS DAYV/V11bfJNhlYsO4uNAPKtxcVG6F2NvbDEv6/LSlcKmX3w4eeQ2bXE7CXhF4KpPWYr /KsR7ooXcH0V0u46AJy8Hp7mn57AO/x45Qz3myUdK5LkEjn5K/397N4Vu7cXVcS0yrRW yI0L106RQQYK9AWXALayZdDZ3Xd2BWwN4bhSeyRsxhZdBXw9wUSAaEviDSZVOdlMX54j KCKsL/K1QJ6VvgHG7ba6UZhsMJbJ7RmOnpjvRGR6+g5qzSlBPjxGfq0+FKpRErSVmXtm EWmw== X-Gm-Message-State: AGRZ1gLDUicAgPtGcZVWOuDLmE08GrU12csGNRrOdN4FzWagAhFxXyp7 NdM2JQXHvx+VhWu0yKkoOeU4dw== X-Received: by 2002:a5b:84e:: with SMTP id v14-v6mr4305512ybq.87.1542257771677; Wed, 14 Nov 2018 20:56:11 -0800 (PST) Received: from linaro.org ([121.95.100.191]) by smtp.googlemail.com with ESMTPSA id h145sm5014203ywc.72.2018.11.14.20.56.10 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 14 Nov 2018 20:56:11 -0800 (PST) From: AKASHI Takahiro To: trini@konsulko.com, agraf@suse.de Date: Thu, 15 Nov 2018 13:58:10 +0900 Message-Id: <20181115045810.28736-4-takahiro.akashi@linaro.org> X-Mailer: git-send-email 2.19.0 In-Reply-To: <20181115045810.28736-1-takahiro.akashi@linaro.org> References: <20181115045810.28736-1-takahiro.akashi@linaro.org> MIME-Version: 1.0 Cc: xypron.glpk@gmx.de, u-boot@lists.denx.de Subject: [U-Boot] [PATCH v2 3/3] efi_loader: remove block device details from efi file X-BeenThere: u-boot@lists.denx.de X-Mailman-Version: 2.1.18 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" Logically, details on u-boot block device used to implement efi file protocol are mostly unnecessary, as well as being duplicated, in efi_file structure. Moreover, a newly introduced flag, _EFI_DISK_FLAG_INVALID, should be honored in any file operations via efi file protocol. These observation suggests that those internal details be set behind efi_disk object. So rework in this patch addresses all those issues above although there is little change in its functionality. Signed-off-by: AKASHI Takahiro --- include/efi_loader.h | 6 +++++- lib/efi_loader/efi_disk.c | 38 ++++++++++++++++++++++++++++++++++++-- lib/efi_loader/efi_file.c | 21 ++++++++------------- 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/include/efi_loader.h b/include/efi_loader.h index 3bae1844befb..108ef3fe52ee 100644 --- a/include/efi_loader.h +++ b/include/efi_loader.h @@ -264,6 +264,10 @@ efi_status_t efi_disk_register(void); bool efi_disk_is_valid(efi_handle_t handle); /* Called by bootefi to find and update disk storage information */ efi_status_t efi_disk_update(void); +/* Called by file protocol to set internal block io device */ +int efi_disk_set_blk_dev(efi_handle_t disk); +/* Called by file protocol to get disk/partition information */ +int efi_disk_get_info(efi_handle_t disk, disk_partition_t *part); /* Create handles and protocols for the partitions of a block device */ int efi_disk_create_partitions(efi_handle_t parent, struct blk_desc *desc, const char *if_typename, int diskid, @@ -355,7 +359,7 @@ void efi_signal_event(struct efi_event *event, bool check_tpl); /* open file system: */ struct efi_simple_file_system_protocol *efi_simple_file_system( - struct blk_desc *desc, int part, struct efi_device_path *dp); + efi_handle_t disk); /* open file from device-path: */ struct efi_file_handle *efi_file_from_path(struct efi_device_path *fp); diff --git a/lib/efi_loader/efi_disk.c b/lib/efi_loader/efi_disk.c index 0c4d79ee3fc9..180e8e10bb28 100644 --- a/lib/efi_loader/efi_disk.c +++ b/lib/efi_loader/efi_disk.c @@ -9,6 +9,7 @@ #include #include #include +#include #include #include @@ -254,6 +255,40 @@ efi_fs_from_path(struct efi_device_path *full_path) return handler->protocol_interface; } +/* + * Set block device for later block io's from file system protocol + * + * @disk handle to uefi disk device + * @return 0 for success, -1 for failure + */ +int efi_disk_set_blk_dev(efi_handle_t disk) +{ + struct efi_disk_obj *diskobj; + + diskobj = container_of(disk, struct efi_disk_obj, header); + + return fs_set_blk_dev_with_part(diskobj->desc, diskobj->part); +} + +/* + * Get disk/partition information + * + * @disk handle to uefi disk device + * @part pointer to disk/partition information to be returned + * @return 0 for success, -1 for failure + */ +int efi_disk_get_info(efi_handle_t disk, disk_partition_t *part) +{ + struct efi_disk_obj *diskobj; + + diskobj = container_of(disk, struct efi_disk_obj, header); + + if (diskobj->part >= 1) + return part_get_info(diskobj->desc, diskobj->part, part); + else + return part_get_info_whole_disk(diskobj->desc, part); +} + /* * Create a handle for a partition or disk * @@ -308,8 +343,7 @@ static efi_status_t efi_disk_add_dev( if (ret != EFI_SUCCESS) return ret; if (part >= 1) { - diskobj->volume = efi_simple_file_system(desc, part, - diskobj->dp); + diskobj->volume = efi_simple_file_system(&diskobj->header); ret = efi_add_protocol(&diskobj->header, &efi_simple_file_system_protocol_guid, diskobj->volume); diff --git a/lib/efi_loader/efi_file.c b/lib/efi_loader/efi_file.c index beb4fba917d8..944383224f30 100644 --- a/lib/efi_loader/efi_file.c +++ b/lib/efi_loader/efi_file.c @@ -17,9 +17,7 @@ const efi_guid_t efi_file_system_info_guid = EFI_FILE_SYSTEM_INFO_GUID; struct file_system { struct efi_simple_file_system_protocol base; - struct efi_device_path *dp; - struct blk_desc *desc; - int part; + efi_handle_t disk; }; #define to_fs(x) container_of(x, struct file_system, base) @@ -49,7 +47,10 @@ static char *basename(struct file_handle *fh) static int set_blk_dev(struct file_handle *fh) { - return fs_set_blk_dev_with_part(fh->fs->desc, fh->fs->part); + if (!efi_disk_is_valid(fh->fs->disk)) + return -1; + + return efi_disk_set_blk_dev(fh->fs->disk); } /** @@ -570,10 +571,7 @@ static efi_status_t EFIAPI efi_file_getinfo(struct efi_file_handle *file, efi_uintn_t required_size; int r; - if (fh->fs->part >= 1) - r = part_get_info(fh->fs->desc, fh->fs->part, &part); - else - r = part_get_info_whole_disk(fh->fs->desc, &part); + r = efi_disk_get_info(fh->fs->disk, &part); if (r < 0) { ret = EFI_DEVICE_ERROR; goto error; @@ -694,17 +692,14 @@ efi_open_volume(struct efi_simple_file_system_protocol *this, } struct efi_simple_file_system_protocol * -efi_simple_file_system(struct blk_desc *desc, int part, - struct efi_device_path *dp) +efi_simple_file_system(efi_handle_t disk) { struct file_system *fs; fs = calloc(1, sizeof(*fs)); fs->base.rev = EFI_SIMPLE_FILE_SYSTEM_PROTOCOL_REVISION; fs->base.open_volume = efi_open_volume; - fs->desc = desc; - fs->part = part; - fs->dp = dp; + fs->disk = disk; return &fs->base; }