From patchwork Fri Jul 20 01:47:21 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ard Biesheuvel X-Patchwork-Id: 142400 Delivered-To: patch@linaro.org Received: by 2002:a2e:9754:0:0:0:0:0 with SMTP id f20-v6csp2392051ljj; Thu, 19 Jul 2018 18:47:59 -0700 (PDT) X-Google-Smtp-Source: AAOMgpeBmUC0ETHljMYWNSvq0a4BUz8zhYgp/B5IPndDlD+BsD0V4ZCmFFakeojZIGepImLFhDdt X-Received: by 2002:a62:ad1:: with SMTP id 78-v6mr100457pfk.57.1532051279228; Thu, 19 Jul 2018 18:47:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1532051279; cv=none; d=google.com; s=arc-20160816; b=Yj3qg2mJ0rRZmyORlOAZ4bRstZgigjwTGe/81DRur3zRCoXxrCSc5SNl8aGLsR+ZGw j5ZeK6QhJuWlEDN0nvDTUPBWAkDDPd/7T6R84e5mArmT+B5PmolTxOxj5yNDOSAvf0Np 5Wgg/ezdiZ2YfVE/V2TMi5eBGf81hL4+LYI0F99AtmyLKIbduQB9TYe51AqFm+lCY1QW skBTyL16vq/Ucf1zuWSKESiKZThj/vR31Z8FzVX1DT1iFSeUxPh7dtPKPwXzMXvCKvKv QnzLCb51E9keL7KjIA1mnt4W0Qt6qdthGfowt/CAZE3wbwx0rO1yeRTtWmRhVNkWyizi cGQw== 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=LNHkWUQA6S84qp4/yqCqd/F6Q+DP5IN/kJ9RCTZqEto=; b=eWtIktwpKALnz9+apaa/+oBoqFDFSvV5z2B7CN27hIRcsFdLTrYB2olnCEIaWe36l2 WqZ65A8OBLJI1S8A1cldE2xqvgzPQXjNe6MX+Jyt7XRnz2rn00erwMiZ2AudHugpeuEr 1qlxJqiIqtE54gZUpN7YwnwD678ZdPmelbbBqDOvA6kGhs4HghSU5bDTC6YHldcFQL7I nzGqzW2hlS621sG7ESMDL+kAmlDsleyxiael+EaBUw2ViiuUt2gkV15n93CNQ8WNh5de ltzvtFcBvjkd4l0ecp1FtY59hlET+Tni+kbJ5NiWDjK667pURdQrAJWD10DJwn8h70Q5 aBEg== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=PG+R2Cyx; 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 e16-v6si550523pgv.561.2018.07.19.18.47.59; Thu, 19 Jul 2018 18:47:59 -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=PG+R2Cyx; 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 S1731232AbeGTCds (ORCPT + 3 others); Thu, 19 Jul 2018 22:33:48 -0400 Received: from mail-pg1-f193.google.com ([209.85.215.193]:40258 "EHLO mail-pg1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731221AbeGTCdr (ORCPT ); Thu, 19 Jul 2018 22:33:47 -0400 Received: by mail-pg1-f193.google.com with SMTP id x5-v6so5358020pgp.7 for ; Thu, 19 Jul 2018 18:47:57 -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=yumR4lvkykhvrfnsDUe6tO0L5ayyApzQLDr9GgxXvqY=; b=PG+R2CyxyKHJpZJKGfFin7HqTVC7Dbr3WvpbJ4UBquLOJ+mI1eEowR4b9zEap0M8so i5Nz7eKshwZmXjXWuv/iRxdawD9llNTFUbZHQQx1V7tdo+pGWmZhOFv4C1Ym6KMYDuM3 OPU3vXWnoJioX3uSFAWgZ+us99ZcnOAb1DnJc= 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=yumR4lvkykhvrfnsDUe6tO0L5ayyApzQLDr9GgxXvqY=; b=HwGf6AkwuZPtAUaU6RZalez1+L7KzAIpmOcCP63rrfGWmxGaP/DYpcWo3HDM7L1r0N RVxo7ICyWdW6yE5xjIeiL20KOgaYR4CCxrLHexoZwXViuZxOUa7dkDrX3tuxYLN240rh wgm0P0XOwE1eyeCxBu7tChKj5uKkF2N67xSrnD3wINLhsegLjabfl2ARrzJZggAHMPVO oblyVoCb8M+rW18nMB4bueY4XF/qbmCWL0QpkycprDrIz8xonbSCDvY7rZCRq+T49YA2 EeZql+dYFM5fILHkOM2K8cK1isSHvYWCWDkMclaRO6pqfbFtS9/fhKvbHIuT6+1+Qh8u P1lw== X-Gm-Message-State: AOUpUlGQBYRsxjQAwOIw4uHa5AuTCCK62yQGMEHvbMVtCUikvs9ksOQS nscjoLsW7QJ5omueQEznN3G/ZYgvDlw= X-Received: by 2002:a63:1403:: with SMTP id u3-v6mr95955pgl.13.1532051277236; Thu, 19 Jul 2018 18:47:57 -0700 (PDT) Received: from localhost.localdomain (fs76eedbeb.tkyc508.ap.nuro.jp. [118.238.219.235]) by smtp.gmail.com with ESMTPSA id 203-v6sm475868pgb.14.2018.07.19.18.47.54 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Thu, 19 Jul 2018 18:47:56 -0700 (PDT) From: Ard Biesheuvel To: linux-efi@vger.kernel.org, Ingo Molnar , Thomas Gleixner Cc: Ard Biesheuvel , linux-kernel@vger.kernel.org, Andy Shevchenko , Hans de Goede , Lukas Wunner Subject: [PATCH 4/9] efi/x86: merge 32-bit and 64-bit UGA draw protocol setup routines Date: Fri, 20 Jul 2018 10:47:21 +0900 Message-Id: <20180720014726.24031-5-ard.biesheuvel@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20180720014726.24031-1-ard.biesheuvel@linaro.org> References: <20180720014726.24031-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 32-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 the 64-bit void* 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. Tested-by: Hans de Goede 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;