From patchwork Thu Jul 12 12:21:52 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 141824 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp1445841ljj; Thu, 12 Jul 2018 05:22:07 -0700 (PDT) X-Google-Smtp-Source: AAOMgpdwd7wQfU9MUiiAgqtEY2MyQie8kHnOOUeE6w2e4an5C8/MfOSyu+F7epKqQHxD6mCLY9QF X-Received: by 2002:a62:d94a:: with SMTP id s71-v6mr2176218pfg.164.1531398126996; Thu, 12 Jul 2018 05:22:06 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1531398126; cv=none; d=google.com; s=arc-20160816; b=qo24hjIdIDJfwUoaJ5b1da1Bakvs20h+GpXQWKz88UMHRq+JX0PZXugDl7+TETvijl 7SK1Zew4/ZQqaXcw5gSmDGlqLtXcUNE2UcQSxMT+KsehMkr9kOAl9m0D3MxFnbqAntKh fpIJfqeMj7hK1Wfu/y83tZ5y3548a7a+efCkBtAHUivDIqN9NAQTMjp3/jrL2VeyNGn0 mjYdKVxWwbTc9KimIQ9Y1Or5pErYFV8Hu7fhnQ1SK9KewUWSSgebt3ZKdsONvDZH5FF3 5LUawx51dqrEEIeIph6wLX7jRDNivoD/atUqHbe/TcidEdrse3AiA6v7j0seI6HvuEZB aWAg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from:dkim-signature:arc-authentication-results; bh=k66eypQ+gfJy5GrB9k7glPT9ORuRPAOBLRyQCO9oMvg=; b=bISIFYNQcXop1Dtzu3RhR5fVDEw+o5LryVeCaFG5pMX5426PDTJpicOf75dUcPf5tc JSww9Y+ZLgy9MZP0iJWRLosheDOTlGcksvGBIU5CKnxN+wE7b+5/si0YzSXjwU/hhhKP cDFM53d9R+LWOJHT2X/xjvfQRPMdwBQwoRV7CnqOZ+aQpveAZxm1czPVqnBnZ8+9ioNv mpbHjexQOePAvPn3Q7GHHeU/6wzPn8kfLDmnPQprDzwRJyCL12dIofzubI7rPwyfpCWp ApQUpY0gvJCge334+iuDlSxZuEbbP+u3ozsi7LflF6HHppVwuqzg6zvOLogv7AxAu1Xf 7aGg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=GIuG+7xG; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id v8-v6si7016131pff.248.2018.07.12.05.22.06; Thu, 12 Jul 2018 05:22:06 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=GIuG+7xG; spf=pass (google.com: best guess record for domain of linux-efi-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-efi-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727077AbeGLMbZ (ORCPT + 3 others); Thu, 12 Jul 2018 08:31:25 -0400 Received: from mail-wr1-f67.google.com ([209.85.221.67]:43138 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726650AbeGLMbZ (ORCPT ); Thu, 12 Jul 2018 08:31:25 -0400 Received: by mail-wr1-f67.google.com with SMTP id b15-v6so21527528wrv.10 for ; Thu, 12 Jul 2018 05:22:04 -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; bh=fLEKaKaGvUJrSkn8yTm6nFj1/boi+MXs0KsskJ0gQQ0=; b=GIuG+7xGDC0YUo1dge3NJTY74+QNzzq9F/grskaNFj3s+5jvb0yHQiOwHDFU/WhgjU XAuF5COPDFF7M32vLfJ0GmJ5+YF/a+mgHjjhECWnr9MzPQ9K+ntVameYPTftv/G7uEAW 6WEsjri7wNcTge9j7UUuM8Y4oLgumlOWlRkhY= 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; bh=fLEKaKaGvUJrSkn8yTm6nFj1/boi+MXs0KsskJ0gQQ0=; b=D4TiNNZ5rlDIiaSQwWtgPZYGWjxHPalD7U3asYadoQVrmCk37fxi3kiiaZVXbP+fMX jO2r/T5bD+rIfDH/xYqyLuCKUnkQQivPPMv4zkKL4tQQGqpVFZHfKKKSI/pQJyJAG6O6 vQUUmgTHlbimiKAbciR5zA2Nr6SgIBVgpESs0++hL6NvE/hVOf4VLgfhsxgF4VDg8Ysp mSoJUCJY6AdrmRU/3vLoqahKCG15lWhLnl8Xvv06zkCnEWUHO848tbSsYtBynWspvsUy CyAmPlcIeSYWqMxmZ2ld5WdU+HQoEELOaGYQ2FYN7+u8r9FxU7LU0WRR0Fw9gLC3Jlpm 0kyw== X-Gm-Message-State: AOUpUlEb7mRKzBVqxs8N2W+r6+ARuTXBxui8fkcEFW4jRd9E0h1cIHW8 OxAf/jwdiKKoGml6FiQSD9lxYHabTxI= X-Received: by 2002:adf:8466:: with SMTP id 93-v6mr1228353wrf.274.1531398123930; Thu, 12 Jul 2018 05:22:03 -0700 (PDT) Received: from localhost.localdomain (33.153.69.91.rev.sfr.net. [91.69.153.33]) by smtp.gmail.com with ESMTPSA id y3-v6sm3551246wmd.24.2018.07.12.05.22.02 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 12 Jul 2018 05:22:03 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org Cc: sai.praneeth.prakhya@intel.com, mingo@kernel.org, hdegoede@redhat.com, lukas@wunner.de, Ard Biesheuvel Subject: [PATCH 4/6] efi/x86: merge 32-bit and 64-bit UGA draw protocol setup routines Date: Thu, 12 Jul 2018 14:21:52 +0200 Message-Id: <20180712122154.13819-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180712122154.13819-1-ard.biesheuvel@linaro.org> References: <20180712122154.13819-1-ard.biesheuvel@linaro.org> Sender: linux-efi-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-efi@vger.kernel.org The two versions of setup_uga##() are mostly identical, with the exception of the size of EFI_HANDLE. So let's merge the two, and pull the implementation into the calling function setup_uga(). Note that the 64-bit version was only mixed-mode safe by accident: it only calls the get_mode() method of the UGA draw protocol, which happens to be the first member, and so truncating that value at offset 0 to 32 bits happens to produce the correct value. But let's not rely on that, and use the proper API instead. Signed-off-by: Ard Biesheuvel --- arch/x86/boot/compressed/eboot.c | 111 +++++--------------- 1 file changed, 26 insertions(+), 85 deletions(-) -- 2.17.1 -- To unsubscribe from this list: send the line "unsubscribe linux-efi" in the body of a message to majordomo@vger.kernel.org More majordomo info at http://vger.kernel.org/majordomo-info.html diff --git a/arch/x86/boot/compressed/eboot.c b/arch/x86/boot/compressed/eboot.c index 011d5c289449..ac8e442db71f 100644 --- a/arch/x86/boot/compressed/eboot.c +++ b/arch/x86/boot/compressed/eboot.c @@ -318,81 +318,54 @@ static void setup_quirks(struct boot_params *boot_params) } } +/* + * See if we have Universal Graphics Adapter (UGA) protocol + */ static efi_status_t -setup_uga32(void **uga_handle, unsigned long size, u32 *width, u32 *height) +setup_uga(struct screen_info *si, efi_guid_t *uga_proto, unsigned long size) { + efi_status_t status; + u32 width, height; + void **uga_handle = NULL; efi_uga_draw_protocol_t *uga = NULL, *first_uga; - efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; unsigned long nr_ugas; - u32 *handles = (u32 *)uga_handle; - efi_status_t status = EFI_INVALID_PARAMETER; int i; - first_uga = NULL; - nr_ugas = size / sizeof(u32); - for (i = 0; i < nr_ugas; i++) { - efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; - u32 w, h, depth, refresh; - void *pciio; - u32 handle = handles[i]; - - status = efi_call_early(handle_protocol, handle, - &uga_proto, (void **)&uga); - if (status != EFI_SUCCESS) - continue; - - efi_call_early(handle_protocol, handle, &pciio_proto, &pciio); - - status = efi_early->call((unsigned long)uga->get_mode, uga, - &w, &h, &depth, &refresh); - if (status == EFI_SUCCESS && (!first_uga || pciio)) { - *width = w; - *height = h; - - /* - * Once we've found a UGA supporting PCIIO, - * don't bother looking any further. - */ - if (pciio) - break; - - first_uga = uga; - } - } + status = efi_call_early(allocate_pool, EFI_LOADER_DATA, + size, (void **)&uga_handle); + if (status != EFI_SUCCESS) + return status; - return status; -} + status = efi_call_early(locate_handle, + EFI_LOCATE_BY_PROTOCOL, + uga_proto, NULL, &size, uga_handle); + if (status != EFI_SUCCESS) + goto free_handle; -static efi_status_t -setup_uga64(void **uga_handle, unsigned long size, u32 *width, u32 *height) -{ - efi_uga_draw_protocol_t *uga = NULL, *first_uga; - efi_guid_t uga_proto = EFI_UGA_PROTOCOL_GUID; - unsigned long nr_ugas; - u64 *handles = (u64 *)uga_handle; - efi_status_t status = EFI_INVALID_PARAMETER; - int i; + height = 0; + width = 0; first_uga = NULL; - nr_ugas = size / sizeof(u64); + nr_ugas = size / (efi_is_64bit() ? sizeof(u64) : sizeof(u32)); for (i = 0; i < nr_ugas; i++) { efi_guid_t pciio_proto = EFI_PCI_IO_PROTOCOL_GUID; u32 w, h, depth, refresh; void *pciio; - u64 handle = handles[i]; + unsigned long handle = efi_is_64bit() ? ((u64 *)uga_handle)[i] + : ((u32 *)uga_handle)[i]; status = efi_call_early(handle_protocol, handle, - &uga_proto, (void **)&uga); + uga_proto, (void **)&uga); if (status != EFI_SUCCESS) continue; efi_call_early(handle_protocol, handle, &pciio_proto, &pciio); - status = efi_early->call((unsigned long)uga->get_mode, uga, - &w, &h, &depth, &refresh); + status = efi_call_proto(efi_uga_draw_protocol, get_mode, uga, + &w, &h, &depth, &refresh); if (status == EFI_SUCCESS && (!first_uga || pciio)) { - *width = w; - *height = h; + width = w; + height = h; /* * Once we've found a UGA supporting PCIIO, @@ -405,38 +378,6 @@ setup_uga64(void **uga_handle, unsigned long size, u32 *width, u32 *height) } } - return status; -} - -/* - * See if we have Universal Graphics Adapter (UGA) protocol - */ -static efi_status_t -setup_uga(struct screen_info *si, efi_guid_t *uga_proto, unsigned long size) -{ - efi_status_t status; - u32 width, height; - void **uga_handle = NULL; - - status = efi_call_early(allocate_pool, EFI_LOADER_DATA, - size, (void **)&uga_handle); - if (status != EFI_SUCCESS) - return status; - - status = efi_call_early(locate_handle, - EFI_LOCATE_BY_PROTOCOL, - uga_proto, NULL, &size, uga_handle); - if (status != EFI_SUCCESS) - goto free_handle; - - height = 0; - width = 0; - - if (efi_early->is64) - status = setup_uga64(uga_handle, size, &width, &height); - else - status = setup_uga32(uga_handle, size, &width, &height); - if (!width && !height) goto free_handle;