From patchwork Wed Sep 3 11:32:20 2014 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Laszlo Ersek X-Patchwork-Id: 36593 Return-Path: X-Original-To: linaro@patches.linaro.org Delivered-To: linaro@patches.linaro.org Received: from mail-pa0-f72.google.com (mail-pa0-f72.google.com [209.85.220.72]) by ip-10-151-82-157.ec2.internal (Postfix) with ESMTPS id CB6EA202E4 for ; Wed, 3 Sep 2014 11:35:42 +0000 (UTC) Received: by mail-pa0-f72.google.com with SMTP id eu11sf82808257pac.11 for ; Wed, 03 Sep 2014 04:35:40 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:mime-version:delivered-to:from:to:subject:date :message-id:in-reply-to:references:sender:precedence:list-id :x-original-sender:x-original-authentication-results:mailing-list :list-post:list-help:list-archive:list-unsubscribe; bh=2dwLGWQr5B1kF3yjDernxz1N+bP8v/G8yCL3m2ogBsY=; b=gCtPmf+DlfB6mKp+NhpkuB810rl8uX+laYCQ2PYjYM5Plo2+GxwDMfqMJVFZx94xfq LYx2sFi0KZ2367ddceHa5G/07rc4IB2ekwMtFfDGLxUxUyw6Z47RPaGANunfum41uCw2 s2A/m2IZxx/pV/Ghk9nGx8GvpJW51n9IbXGxVUnVDYxJkuoKcbWHI5iAgyVVl1idWQRM 9oTL+6pOU93wzxoLOcvUMPIGHHggcyxRY4WouUQm1/3B6oT6RVLChETxJ1ZLl/ZSprw6 4Bkj+YvrL1W2aqqD9XvjcERoUgcv2xHLm5HG2k6BHN+9T3b9C1JHDoF/S8UGHelUbzTD wecA== X-Gm-Message-State: ALoCoQnC8BEU8YdNGcr5aO3Sltn8T9By2y5Ayw0Ae1gJVsBNwXMl4ds+FjGsR6/TauB0R65GYUcf X-Received: by 10.66.171.231 with SMTP id ax7mr22589501pac.29.1409744138732; Wed, 03 Sep 2014 04:35:38 -0700 (PDT) MIME-Version: 1.0 X-BeenThere: patchwork-forward@linaro.org Received: by 10.140.36.105 with SMTP id o96ls2712332qgo.35.gmail; Wed, 03 Sep 2014 04:35:38 -0700 (PDT) X-Received: by 10.220.194.130 with SMTP id dy2mr83630vcb.47.1409744138508; Wed, 03 Sep 2014 04:35:38 -0700 (PDT) Received: from mail-vc0-f180.google.com (mail-vc0-f180.google.com [209.85.220.180]) by mx.google.com with ESMTPS id s18si3496566vcu.2.2014.09.03.04.35.38 for (version=TLSv1 cipher=ECDHE-RSA-RC4-SHA bits=128/128); Wed, 03 Sep 2014 04:35:38 -0700 (PDT) Received-SPF: pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) client-ip=209.85.220.180; Received: by mail-vc0-f180.google.com with SMTP id lf12so8362412vcb.25 for ; Wed, 03 Sep 2014 04:35:38 -0700 (PDT) X-Received: by 10.220.110.77 with SMTP id m13mr1160938vcp.35.1409744138402; Wed, 03 Sep 2014 04:35:38 -0700 (PDT) X-Forwarded-To: patchwork-forward@linaro.org X-Forwarded-For: patch@linaro.org patchwork-forward@linaro.org Delivered-To: patch@linaro.org Received: by 10.221.45.67 with SMTP id uj3csp666031vcb; Wed, 3 Sep 2014 04:35:37 -0700 (PDT) X-Received: by 10.66.163.65 with SMTP id yg1mr57636332pab.33.1409744137472; Wed, 03 Sep 2014 04:35:37 -0700 (PDT) Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id gg10si10516756pac.188.2014.09.03.04.35.30 for ; Wed, 03 Sep 2014 04:35:30 -0700 (PDT) Received-SPF: none (google.com: linux-kernel-owner@vger.kernel.org does not designate permitted sender hosts) client-ip=209.132.180.67; Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1756273AbaICLc5 (ORCPT + 25 others); Wed, 3 Sep 2014 07:32:57 -0400 Received: from mx1.redhat.com ([209.132.183.28]:22374 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1756201AbaICLcy (ORCPT ); Wed, 3 Sep 2014 07:32:54 -0400 Received: from int-mx14.intmail.prod.int.phx2.redhat.com (int-mx14.intmail.prod.int.phx2.redhat.com [10.5.11.27]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id s83BWX3j003795 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=FAIL); Wed, 3 Sep 2014 07:32:33 -0400 Received: from lacos-laptop-7.usersys.redhat.com (ovpn-116-89.ams2.redhat.com [10.36.116.89]) by int-mx14.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id s83BWP7T002681; Wed, 3 Sep 2014 07:32:30 -0400 From: Laszlo Ersek To: mingo@kernel.org, linux-efi@vger.kernel.org, linux-kernel@vger.kernel.org, linux-arm-kernel@lists.infradead.org, x86@kernel.org, linux-ia64@vger.kernel.org, matt.fleming@intel.com, msalter@redhat.com, lersek@redhat.com Subject: [PATCH v2 2/5] efi: introduce efi_md_typeattr_format() Date: Wed, 3 Sep 2014 13:32:20 +0200 Message-Id: <1409743943-16934-3-git-send-email-lersek@redhat.com> In-Reply-To: <1409743943-16934-1-git-send-email-lersek@redhat.com> References: <1409743943-16934-1-git-send-email-lersek@redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.27 Sender: linux-kernel-owner@vger.kernel.org Precedence: list List-ID: X-Mailing-List: linux-kernel@vger.kernel.org X-Removed-Original-Auth: Dkim didn't pass. X-Original-Sender: lersek@redhat.com X-Original-Authentication-Results: mx.google.com; spf=pass (google.com: domain of patch+caf_=patchwork-forward=linaro.org@linaro.org designates 209.85.220.180 as permitted sender) smtp.mail=patch+caf_=patchwork-forward=linaro.org@linaro.org Mailing-list: list patchwork-forward@linaro.org; contact patchwork-forward+owners@linaro.org X-Google-Group-Id: 836684582541 List-Post: , List-Help: , List-Archive: List-Unsubscribe: , At the moment, there are three architectures debug-printing the EFI memory map at initialization: x86, ia64, and arm64. They all use different format strings, plus the EFI memory type and the EFI memory attributes are similarly hard to decode for a human reader. Introduce a helper __init function that formats the memory type and the memory attributes in a unified way, to a user-provided character buffer. The array "memory_type_name" is copied from the arm64 code, temporarily duplicating it. The (otherwise optional) braces around each string literal in the initializer list are dropped in order to match the kernel coding style more closely. The element size is tightened from 32 to 20 bytes (maximum actual string length + 1) so that we can derive the field width from the element size. Signed-off-by: Laszlo Ersek --- include/linux/efi.h | 7 ++++++ drivers/firmware/efi/efi.c | 57 ++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 64 insertions(+) diff --git a/include/linux/efi.h b/include/linux/efi.h index b4b1d8d..d04d618 100644 --- a/include/linux/efi.h +++ b/include/linux/efi.h @@ -887,6 +887,13 @@ extern bool efi_poweroff_required(void); (md) <= (efi_memory_desc_t *)((m)->map_end - (m)->desc_size); \ (md) = (void *)(md) + (m)->desc_size) +/* + * Format an EFI memory descriptor's type and attributes to a user-provided + * character buffer, as per snprintf(), and return the buffer. + */ +char * __init efi_md_typeattr_format(char *buf, size_t size, + const efi_memory_desc_t *md); + /** * efi_range_is_wc - check the WC bit on an address range * @start: starting kvirt address diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c index 64ecbb5..43d9d25 100644 --- a/drivers/firmware/efi/efi.c +++ b/drivers/firmware/efi/efi.c @@ -423,3 +423,60 @@ int __init efi_get_fdt_params(struct efi_fdt_params *params, int verbose) return ret; } #endif /* CONFIG_EFI_PARAMS_FROM_FDT */ + +static __initdata char memory_type_name[][20] = { + "Reserved", + "Loader Code", + "Loader Data", + "Boot Code", + "Boot Data", + "Runtime Code", + "Runtime Data", + "Conventional Memory", + "Unusable Memory", + "ACPI Reclaim Memory", + "ACPI Memory NVS", + "Memory Mapped I/O", + "MMIO Port Space", + "PAL Code" +}; + +char * __init efi_md_typeattr_format(char *buf, size_t size, + const efi_memory_desc_t *md) +{ + char *pos; + int type_len; + register u64 attr; + + pos = buf; + if (md->type >= ARRAY_SIZE(memory_type_name)) + type_len = snprintf(pos, size, "[type=%u", md->type); + else + type_len = snprintf(pos, size, "[%-*s", + (int)(sizeof(memory_type_name[0]) - 1), + memory_type_name[md->type]); + if (type_len >= size) + return buf; + + pos += type_len; + size -= type_len; + + attr = md->attribute; + if (attr & ~(EFI_MEMORY_UC | EFI_MEMORY_WC | EFI_MEMORY_WT | + EFI_MEMORY_WB | EFI_MEMORY_UCE | EFI_MEMORY_WP | + EFI_MEMORY_RP | EFI_MEMORY_XP | EFI_MEMORY_RUNTIME)) + snprintf(pos, size, "|attr=0x%016llx]", + (unsigned long long)attr); + else + snprintf(pos, size, "|%3s|%2s|%2s|%2s|%3s|%2s|%2s|%2s|%2s]", + attr & EFI_MEMORY_RUNTIME ? "RUN" : "", + attr & EFI_MEMORY_XP ? "XP" : "", + attr & EFI_MEMORY_RP ? "RP" : "", + attr & EFI_MEMORY_WP ? "WP" : "", + attr & EFI_MEMORY_UCE ? "UCE" : "", + attr & EFI_MEMORY_WB ? "WB" : "", + attr & EFI_MEMORY_WT ? "WT" : "", + attr & EFI_MEMORY_WC ? "WC" : "", + attr & EFI_MEMORY_UC ? "UC" : ""); + return buf; +}