From patchwork Sun Dec 8 12:22:42 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205615 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W59N1Mygz9sPf for ; Sun, 8 Dec 2019 23:24:24 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aognJS/+"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W59L4RmJzDqF6 for ; Sun, 8 Dec 2019 23:24:22 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::644; helo=mail-pl1-x644.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="aognJS/+"; dkim-atps=neutral Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W58B2qC3zDqDb for ; Sun, 8 Dec 2019 23:23:21 +1100 (AEDT) Received: by mail-pl1-x644.google.com with SMTP id q16so4607458plr.10 for ; Sun, 08 Dec 2019 04:23:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ABHnyc9cGiUchiY4LlVwkTd97Le2d9Q8dXvPTCHUoFc=; b=aognJS/+EAsbrXg6OkkoWwQBbGULfAnlNKq7BItaUeatiEeYHqqpDagXJ/1g8GoXJP VjbP06FJcp72DCKB950OekTkIDFSCQdKp1qBUMegv5ErKYVYca2ygwDeNNAZ1UB9vYbZ Z7RzNt68qgyY4ud+6dDucwQmymQggoSLfxqE4ubjshz33g7hvdy2KRBhMGe/ll5F++gE PlkWx71K9tfadzl5BSljIijo6DuAOqsk5dY6jk1aCr3AnHk8XSHPwcNidUo1OW9CsZ1n VJyhYC6qwF9/NzZppTbtMXym5W3V4GkZKxitQy1GhEe6OiVRkxB0FqXkSvsGT9FffPwx 1Scw== 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=ABHnyc9cGiUchiY4LlVwkTd97Le2d9Q8dXvPTCHUoFc=; b=kc2u2p6jNCdvg7pzThUEbNxkIazljNDFUxLWtN1jSKNihdW30+LMNab3+9rxyzg3Vc B4FJFEfPdNtpobZ3iLp4JW/m5jQkk0SCDXOjy+O3ppt5VITOjtw4kGgiKEpMRVTrbLDV XSO3CKfOd9RFtHNLjfTVoGl3XPQeo1p36oFhY+GSO71yf8PiT0LKse6UKMZ+GN6pY2E1 gUI8zo0qpPr4vX3OAa68erHNm+6KlUfpHdyAu7skfiebkHbFJyIJbxHAauSVSw58AYNU BOXuAu2M6HWEiuE5B1YgwoXotT7dgKX/dNdo6kgSZ1GMW3yI8azLpM8N4fHzrBC63PmP w9pA== X-Gm-Message-State: APjAAAVjmW2r3745zQ312fYhQWjXUwRJrAwsa5tdPGEuEPdV3hwxe216 15/JpRQU7Mv/V357TRB8hWDayQun X-Google-Smtp-Source: APXvYqzzQoRuuYMzyzBCIgaSPnwvCrMMik68AB3lbcJN2z+SyGLVLQPSw1CQdZSsNdO14OwZ9qDVhA== X-Received: by 2002:a17:902:fe8b:: with SMTP id x11mr16074458plm.83.1575807798840; Sun, 08 Dec 2019 04:23:18 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.23.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:23:18 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:42 +1000 Message-Id: <20191208122312.12837-2-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 01/31] asm/cvc_entry.S: r2 save fix X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" The TOC save area for the current stack frame should be used to save r2, not the caller's frame. Acked-by: Stewart Smith Signed-off-by: Nicholas Piggin --- asm/cvc_entry.S | 9 +++++++-- include/stack.h | 2 ++ 2 files changed, 9 insertions(+), 2 deletions(-) diff --git a/asm/cvc_entry.S b/asm/cvc_entry.S index 1296e88fe..3e8b3fdad 100644 --- a/asm/cvc_entry.S +++ b/asm/cvc_entry.S @@ -24,6 +24,11 @@ #.include "kernel/ppcconsts.S" +# Updated hostboot location is src/securerom/rom_entry.S. +# This also has a fix for TOC save frame pointer. + +#include + .section .text .global __cvc_verify_v1 @@ -33,10 +38,10 @@ __cvc_verify_v1: __cvc_sha512_v1: call_rom_entry: - std %r2, 40(%r1) mflr %r0 std %r0, 16(%r1) stdu %r1, -128(%r1) + std %r2, STACK_TOC_OFFSET(%r1) li %r2, 0 mtctr %r3 mr %r3, %r4 @@ -45,8 +50,8 @@ call_rom_entry: mr %r6, %r7 mr %r7, %r8 bctrl + ld %r2, STACK_TOC_OFFSET(%r1) addi %r1, %r1, 128 - ld %r2, 40(%r1) ld %r0, 16(%r1) mtlr %r0 blr diff --git a/include/stack.h b/include/stack.h index 3ad52d64c..09d22adb6 100644 --- a/include/stack.h +++ b/include/stack.h @@ -11,6 +11,8 @@ #define STACK_ENTRY_RESET 0x0100 /* System reset */ #define STACK_ENTRY_SOFTPATCH 0x1500 /* Soft patch (denorm emulation) */ +#define STACK_TOC_OFFSET 40 + /* Safety/ABI gap at top of stack */ #define STACK_TOP_GAP 0x100 From patchwork Sun Dec 8 12:22:43 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205616 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5B53ZLlz9sP3 for ; Sun, 8 Dec 2019 23:25:01 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZzJeULzh"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5B505gMzDqDV for ; Sun, 8 Dec 2019 23:25:01 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::644; helo=mail-pl1-x644.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="ZzJeULzh"; dkim-atps=neutral Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W58D07CgzDqDV for ; Sun, 8 Dec 2019 23:23:23 +1100 (AEDT) Received: by mail-pl1-x644.google.com with SMTP id bd4so4609618plb.8 for ; Sun, 08 Dec 2019 04:23:23 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ZH3kc4PtPjVkIsHqCzSJ1NXZCF0M8ei3mKZnUcJmbok=; b=ZzJeULzhX1UAOtn+cO66q3ZK615f76j+6c0KzSjRIA6tluy20sq6FdebUj1/KBYq2T aHARk7bfJAVkPHrPr0NNlDi808HTpontwiAFlX286vj4Q3mfWD5qdNcPeF4PXGBZYsM0 vVHuTv5AY9uHFqNVD7K+zCiU0d70n0o6k1vtQ13Bm7N6dh9BU0btbg/VWEybMOolSpmf 7ue+SeEKwU7LEy0V3ITh1KR5aau31afzgtz4xym5FkIEM+LLiHNVXnB5ElLCuSz0e2KX 4nvpq1Cyhy41Jh4Yhpo18IrfJ4Q/NmOhdeNd32KDZ8IaAIX+HBxAzxZkVc5KYSR5tM/5 tlRA== 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=ZH3kc4PtPjVkIsHqCzSJ1NXZCF0M8ei3mKZnUcJmbok=; b=m1qaacvyfYBNiNtqZh0AL6d/PRUs0IalDHrlwfLmtcwNE7VDqY9xAd1q7p6ZPPgOU1 RftMgMd31xRYzZQLjJzZ4SOn47rGz4LWdDqayOioRVQ2/5PyUya++U0kr3SBLWpvuzD6 x/LARZEEzr2SSVERLZr4pTpPY9tQIYThfiTm4/Y/9BjZIzOeZv0sL6rCOzvK2aqggKeY i9n7UEN7vX2JPgRPFwWlkLtc0hVP1oJgm+KaLednz5rzsF/S8XNi7ZlF31SngzkVdhNI SnnYVKqhOgLEJgQLnFTkoWt0GHjvlrult/IqiZFuqcQ8JVa2MwI+07WW+6dCXJqYL4uu qcwQ== X-Gm-Message-State: APjAAAUrlFpk4c6lfa8zHHeCUP3D4fu1MirPb+bW9nfkw3ncH3vfOV5j fM6j7z7Y0HVkbyf356U5Xx0vrJF9 X-Google-Smtp-Source: APXvYqxBDsQST0MdIBeu1dEx6s624fE8SBWGIUhy1RP/gQ+oR1betoD65bZfYXhPC3+K+hZrsYuVOA== X-Received: by 2002:a17:902:7485:: with SMTP id h5mr24370393pll.265.1575807801719; Sun, 08 Dec 2019 04:23:21 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.23.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:23:21 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:43 +1000 Message-Id: <20191208122312.12837-3-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 02/31] capp: fix endian conversion X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Andrew Donnellan Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Acked-by: Stewart Smith Reviewed-by: Andrew Donnellan Signed-off-by: Nicholas Piggin --- hw/capp.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/capp.c b/hw/capp.c index 709e6db14..269deb637 100644 --- a/hw/capp.c +++ b/hw/capp.c @@ -168,7 +168,7 @@ int64_t capp_load_ucode(unsigned int chip_id, uint32_t opal_id, /* 'CAPPULID' in ASCII */ if ((be64_to_cpu(ucode->eyecatcher) != 0x43415050554C4944UL) || - (be64_to_cpu(ucode->version != 1))) { + (be64_to_cpu(ucode->version) != 1)) { PHBERR(opal_id, chip_id, index, "CAPP: ucode header invalid\n"); return OPAL_HARDWARE; From patchwork Sun Dec 8 12:22:44 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205617 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5Bw5Jb2z9sP3 for ; Sun, 8 Dec 2019 23:25:44 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FW6Vixeq"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5Bw3QR2zDqP9 for ; Sun, 8 Dec 2019 23:25:44 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::543; helo=mail-pg1-x543.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="FW6Vixeq"; dkim-atps=neutral Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W58J11FszDqDV for ; Sun, 8 Dec 2019 23:23:28 +1100 (AEDT) Received: by mail-pg1-x543.google.com with SMTP id r11so5682847pgf.1 for ; Sun, 08 Dec 2019 04:23:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=WCa1ACVp+vaUVGvsbwQFkJ61j2bUvsIeaZ10011zcEM=; b=FW6VixeqwMVSrjx6MycmwAtopkyxTdh59PZR9HKG3fQ5/Ymwz46yfwpV1/lE2WAx4h pi0NRKEnYiBiRzhcq46oM5tAMrcME0zuYN5PAnynxtpVF6+7spoODrgqY3mpyldkZotn BBTd6l9nO23EUBv3jXmuE5omgLwrKvtrh8hF1VGG4uPSuO4kGoq06NziuYYuCOYUtLzy sTjmYUEOPHZqLDzvfjwPZxZdu7XITVTcJ5Aj4qhFIuQuG2ruFRsEkqUy8vZf7gLrCDii RsQ9NQilABdW0IAfwRIqrPUboZhFCehlfR3Pe5pNzp6OqK82dMd4OGbWPbjPbWWMJBnD cOzQ== 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=WCa1ACVp+vaUVGvsbwQFkJ61j2bUvsIeaZ10011zcEM=; b=Uo3VjDKXtyuTkcy4jGTB53TQcZMrb5IYHa0DEM2z7YHXkGc9FSLmPux6F7uwSIJVDD 1V83E0xGTnDdfWscYvsmGsRceftzJGzHh0yRcLfI6H7BTxPOOGbkJdxT7YrLTSwE6NJl VkjfbaijGkm6vMM3ibLgaBstkL3qMmou3cezwMYl2Pd+udywRSPCENmJR8IBKRRyRENm pZeJRa9wtlJHgjyr9C/J4G12M+0JXjDI11w1Y7BiynSfC2OCVgUL8/EBOe/WGeBQLDlJ WzwequHrBOSqGuyGTDDasO+YW0tWq4SCZ60F2OyvsYabvih3RdSf3GZErof+NpoGM2gU SdJQ== X-Gm-Message-State: APjAAAXCJHoJwJLebHHaOcAY51MJFa3cAOrRIj0+7dJcw/VXxduwAafQ mLRj/BwvN5EpmAZIgdtg19+CTGTG X-Google-Smtp-Source: APXvYqx655Z/TFUyuKh9b8kXcXS0Cb7VoXVtyg2jtfXEasWg+g20wATL1t7L43cOKXXcMqVQEN24yA== X-Received: by 2002:aa7:96b7:: with SMTP id g23mr23706746pfk.108.1575807804868; Sun, 08 Dec 2019 04:23:24 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.23.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:23:24 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:44 +1000 Message-Id: <20191208122312.12837-4-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 03/31] cpu: use dt accessor device tree access X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" In several cases the make test reference .dts files were incorrectly byteswapped, these are fixed here too. Reviewed-by: Vasant Hegde Signed-off-by: Nicholas Piggin --- core/cpu.c | 2 +- core/device.c | 1 + core/fdt.c | 4 ++-- core/interrupts.c | 4 ++-- core/pci.c | 28 +++++++++++++--------------- hdata/fsp.c | 7 ++++--- hdata/iohub.c | 32 ++++++++++++++++---------------- hdata/test/op920.wsp.dts | 20 ++++++++++++++------ hdata/test/p8-840-spira.dts | 16 ++++++++-------- hdata/test/p81-811.spira.dts | 25 +++++++++++++------------ hw/fsp/fsp-sysparam.c | 4 ++-- hw/fsp/fsp.c | 2 +- hw/imc.c | 4 ++-- hw/lpc.c | 8 ++++---- hw/psi.c | 8 ++++---- hw/vas.c | 6 ++---- 16 files changed, 89 insertions(+), 82 deletions(-) diff --git a/core/cpu.c b/core/cpu.c index 99d016f0d..370bf4b03 100644 --- a/core/cpu.c +++ b/core/cpu.c @@ -1214,7 +1214,7 @@ void init_all_cpus(void) t = &cpu_stacks[pir + thread].cpu; init_cpu_thread(t, state, pir + thread); t->trace = boot_cpu->trace; - t->server_no = ((const u32 *)p->prop)[thread]; + t->server_no = dt_property_get_cell(p, thread); t->is_secondary = true; t->primary = pt; t->node = cpu; diff --git a/core/device.c b/core/device.c index ce0171b67..0118d485f 100644 --- a/core/device.c +++ b/core/device.c @@ -1110,6 +1110,7 @@ void dt_adjust_subtree_phandle(struct dt_node *dev, continue; phandle = dt_prop_get_u32(node, *name); phandle += import_phandle; + phandle = cpu_to_be32(phandle); memcpy((char *)&prop->prop, &phandle, prop->len); } } diff --git a/core/fdt.c b/core/fdt.c index d3c6d9fa1..e093e8b54 100644 --- a/core/fdt.c +++ b/core/fdt.c @@ -146,8 +146,8 @@ static void create_dtb_reservemap(void *fdt, const struct dt_node *root) ranges = (const void *)prop->prop; for (i = 0; i < prop->len / (sizeof(uint64_t) * 2); i++) { - base = *(ranges++); - size = *(ranges++); + base = be64_to_cpu(*(ranges++)); + size = be64_to_cpu(*(ranges++)); save_err(fdt_add_reservemap_entry(fdt, base, size)); } } diff --git a/core/interrupts.c b/core/interrupts.c index b0c1da198..10baa15f6 100644 --- a/core/interrupts.c +++ b/core/interrupts.c @@ -231,8 +231,8 @@ void add_opal_interrupts(void) names[tns++] = 0; i = count++; irqs = realloc(irqs, 8 * count); - irqs[i*2] = isn; - irqs[i*2+1] = iflags; + irqs[i*2] = cpu_to_be32(isn); + irqs[i*2+1] = cpu_to_be32(iflags); } } unlock(&irq_lock); diff --git a/core/pci.c b/core/pci.c index f74d7163f..e497fd50c 100644 --- a/core/pci.c +++ b/core/pci.c @@ -1312,7 +1312,7 @@ void pci_std_swizzle_irq_map(struct dt_node *np, { uint32_t *map, *p; int dev, irq, esize, edevcount; - size_t map_size, isize; + size_t map_size; /* Some emulated setups don't use standard interrupts * representation @@ -1320,9 +1320,6 @@ void pci_std_swizzle_irq_map(struct dt_node *np, if (lstate->int_size == 0) return; - /* Size in bytes of a target interrupt */ - isize = lstate->int_size * sizeof(uint32_t); - /* Calculate the size of a map entry: * * 3 cells : PCI Address @@ -1362,22 +1359,23 @@ void pci_std_swizzle_irq_map(struct dt_node *np, for (dev = 0; dev < edevcount; dev++) { for (irq = 0; irq < 4; irq++) { /* Calculate pin */ + size_t i; uint32_t new_irq = (irq + dev + swizzle) % 4; /* PCI address portion */ - *(p++) = dev << (8 + 3); + *(p++) = cpu_to_be32(dev << (8 + 3)); *(p++) = 0; *(p++) = 0; /* PCI interrupt portion */ - *(p++) = irq + 1; + *(p++) = cpu_to_be32(irq + 1); /* Parent phandle */ - *(p++) = lstate->int_parent[new_irq]; + *(p++) = cpu_to_be32(lstate->int_parent[new_irq]); /* Parent desc */ - memcpy(p, lstate->int_val[new_irq], isize); - p += lstate->int_size; + for (i = 0; i < lstate->int_size; i++) + *(p++) = cpu_to_be32(lstate->int_val[new_irq][i]); } } @@ -1526,16 +1524,16 @@ static void __noinline pci_add_one_device_node(struct phb *phb, char name[MAX_NAME]; char compat[MAX_NAME]; uint32_t rev_class; - uint32_t reg[5]; + __be32 reg[5]; uint8_t intpin; bool is_pcie; - const uint32_t ranges_direct[] = { + const __be32 ranges_direct[] = { /* 64-bit direct mapping. We know the bridges * don't cover the entire address space so * use 0xf00... as a good compromise. */ - 0x02000000, 0x0, 0x0, - 0x02000000, 0x0, 0x0, - 0xf0000000, 0x0}; + cpu_to_be32(0x02000000), 0x0, 0x0, + cpu_to_be32(0x02000000), 0x0, 0x0, + cpu_to_be32(0xf0000000), 0x0}; pci_cfg_read32(phb, pd->bdfn, PCI_CFG_REV_ID, &rev_class); pci_cfg_read8(phb, pd->bdfn, PCI_CFG_INT_PIN, &intpin); @@ -1611,7 +1609,7 @@ static void __noinline pci_add_one_device_node(struct phb *phb, * entry in the "reg" property. That's enough for Linux and we might * even want to make this legit in future ePAPR */ - reg[0] = pd->bdfn << 8; + reg[0] = cpu_to_be32(pd->bdfn << 8); reg[1] = reg[2] = reg[3] = reg[4] = 0; dt_add_property(np, "reg", reg, sizeof(reg)); diff --git a/hdata/fsp.c b/hdata/fsp.c index 5923f1feb..fe36eef18 100644 --- a/hdata/fsp.c +++ b/hdata/fsp.c @@ -206,7 +206,7 @@ static void fsp_create_links(const void *spss, int index, chip = fsp_create_link(iopath, i, index); lp = lcount++; links = realloc(links, 4 * lcount); - links[lp] = chip; + links[lp] = cpu_to_be32(chip); } if (links) dt_add_property(fsp_node, "ibm,psi-links", links, lcount * 4); @@ -268,7 +268,7 @@ static void add_uart(const struct spss_iopath *iopath, struct dt_node *lpc) be32_to_cpu(iopath->lpc.uart_baud)); } -static void add_chip_id_to_sensors(struct dt_node *sensor_node, __be32 slca_index) +static void add_chip_id_to_sensors(struct dt_node *sensor_node, uint32_t slca_index) { unsigned int i; const void *hdif; @@ -347,7 +347,8 @@ static void add_ipmi_sensors(struct dt_node *bmc_node) dt_add_property_cells(sensor_node, "ipmi-sensor-type", ipmi_sensors->data[i].type); - add_chip_id_to_sensors(sensor_node, ipmi_sensors->data[i].slca_index); + add_chip_id_to_sensors(sensor_node, + be32_to_cpu(ipmi_sensors->data[i].slca_index)); } } diff --git a/hdata/iohub.c b/hdata/iohub.c index 6921d95ce..6647e6aac 100644 --- a/hdata/iohub.c +++ b/hdata/iohub.c @@ -20,7 +20,7 @@ static bool io_get_lx_info(const void *kwvpd, unsigned int kwvpd_sz, { const void *lxr; char recname[5]; - uint32_t lxrbuf[2] = { 0, 0 }; + beint32_t lxrbuf[2] = { 0, 0 }; /* Find LXRn, where n is the index passed in*/ strcpy(recname, "LXR0"); @@ -38,17 +38,17 @@ static bool io_get_lx_info(const void *kwvpd, unsigned int kwvpd_sz, return false; } - memcpy(lxrbuf, lxr, sizeof(uint32_t)*2); + memcpy(lxrbuf, lxr, sizeof(beint32_t)*2); - prlog(PR_DEBUG, "CEC: LXRn=%d LXR=%08x%08x\n", lx_idx, lxrbuf[0], lxrbuf[1]); + prlog(PR_DEBUG, "CEC: LXRn=%d LXR=%08x%08x\n", lx_idx, be32_to_cpu(lxrbuf[0]), be32_to_cpu(lxrbuf[1])); prlog(PR_DEBUG, "CEC: LX Info added to %llx\n", (long long)hn); /* Add the LX info */ if (!dt_has_node_property(hn, "ibm,vpd-lx-info", NULL)) { dt_add_property_cells(hn, "ibm,vpd-lx-info", lx_idx, - lxrbuf[0], - lxrbuf[1]); + be32_to_cpu(lxrbuf[0]), + be32_to_cpu(lxrbuf[1])); } return true; @@ -109,12 +109,12 @@ static struct dt_node *io_add_phb3(const struct cechub_io_hub *hub, /* "reg" property contains in order the PE, PCI and SPCI XSCOM * addresses */ - reg[0] = pe_xscom; - reg[1] = 0x20; - reg[2] = pci_xscom; - reg[3] = 0x05; - reg[4] = spci_xscom; - reg[5] = 0x15; + reg[0] = cpu_to_be32(pe_xscom); + reg[1] = cpu_to_be32(0x20); + reg[2] = cpu_to_be32(pci_xscom); + reg[3] = cpu_to_be32(0x05); + reg[4] = cpu_to_be32(spci_xscom); + reg[5] = cpu_to_be32(0x15); dt_add_property(pbcq, "reg", reg, sizeof(reg)); /* A couple more things ... */ @@ -214,10 +214,10 @@ static struct dt_node *io_add_phb4(const struct cechub_io_hub *hub, return NULL; /* "reg" property contains (in order) the PE and PCI XSCOM addresses */ - reg[0] = pe_xscom; - reg[1] = 0x100; - reg[2] = pci_xscom; - reg[3] = 0x200; + reg[0] = cpu_to_be32(pe_xscom); + reg[1] = cpu_to_be32(0x100); + reg[2] = cpu_to_be32(pci_xscom); + reg[3] = cpu_to_be32(0x200); dt_add_property(pbcq, "reg", reg, sizeof(reg)); /* The hubs themselves go under the stacks */ @@ -322,7 +322,7 @@ static void io_add_p8_cec_vpd(const struct HDIF_common_hdr *sp_iohubs) } if (be32_to_cpu(iokids->count) > 1) { prlog(PR_WARNING, "CEC: WARNING ! More than 1 IO KID !!! (%d)\n", - iokids->count); + be32_to_cpu(iokids->count)); /* Ignoring the additional ones */ } diff --git a/hdata/test/op920.wsp.dts b/hdata/test/op920.wsp.dts index 057021f4d..e26fa1272 100644 --- a/hdata/test/op920.wsp.dts +++ b/hdata/test/op920.wsp.dts @@ -76,6 +76,7 @@ sensor@8 { phandle = <0x2b>; compatible = "ibm,ipmi-sensor"; + ibm,chip-id = <0x00>; reg = <0x8>; ipmi-sensor-type = <0x7>; }; @@ -83,6 +84,7 @@ sensor@9 { phandle = <0x3f>; compatible = "ibm,ipmi-sensor"; + ibm,chip-id = <0x08>; reg = <0x9>; ipmi-sensor-type = <0x7>; }; @@ -139,6 +141,7 @@ sensor@59 { phandle = <0x18>; compatible = "ibm,ipmi-sensor"; + ibm,chip-id = <0x00>; reg = <0x59>; ipmi-sensor-type = <0x1>; }; @@ -146,6 +149,7 @@ sensor@5a { phandle = <0x1a>; compatible = "ibm,ipmi-sensor"; + ibm,chip-id = <0x00>; reg = <0x5a>; ipmi-sensor-type = <0x7>; }; @@ -153,6 +157,7 @@ sensor@a3 { phandle = <0x2c>; compatible = "ibm,ipmi-sensor"; + ibm,chip-id = <0x08>; reg = <0xa3>; ipmi-sensor-type = <0x1>; }; @@ -160,6 +165,7 @@ sensor@a4 { phandle = <0x2e>; compatible = "ibm,ipmi-sensor"; + ibm,chip-id = <0x08>; reg = <0xa4>; ipmi-sensor-type = <0x7>; }; @@ -433,6 +439,7 @@ sensor@e0 { phandle = <0x19>; compatible = "ibm,ipmi-sensor"; + ibm,chip-id = <0x00>; reg = <0xe0>; ipmi-sensor-type = <0x1>; }; @@ -440,6 +447,7 @@ sensor@e1 { phandle = <0x2d>; compatible = "ibm,ipmi-sensor"; + ibm,chip-id = <0x08>; reg = <0xe1>; ipmi-sensor-type = <0x1>; }; @@ -4166,7 +4174,7 @@ pbcq@4010c00 { phandle = <0x140>; - reg = <0xc0104 0x10000 0x8010d 0x20000>; + reg = <0x4010c00 0x100 0xd010800 0x200>; compatible = "ibm,power9-pbcq"; ibm,pec-index = <0x0>; #address-cells = <0x1>; @@ -4186,7 +4194,7 @@ pbcq@4011000 { phandle = <0x142>; - reg = <0x100104 0x10000 0x8010e 0x20000>; + reg = <0x4011000 0x100 0xe010800 0x200>; compatible = "ibm,power9-pbcq"; ibm,pec-index = <0x1>; #address-cells = <0x1>; @@ -4215,7 +4223,7 @@ pbcq@4011400 { phandle = <0x145>; - reg = <0x140104 0x10000 0x8010f 0x20000>; + reg = <0x4011400 0x100 0xf010800 0x200>; compatible = "ibm,power9-pbcq"; ibm,pec-index = <0x2>; #address-cells = <0x1>; @@ -4796,7 +4804,7 @@ pbcq@4010c00 { phandle = <0x15c>; - reg = <0xc0104 0x10000 0x8010d 0x20000>; + reg = <0x4010c00 0x100 0xd010800 0x200>; compatible = "ibm,power9-pbcq"; ibm,pec-index = <0x0>; #address-cells = <0x1>; @@ -4816,7 +4824,7 @@ pbcq@4011000 { phandle = <0x15e>; - reg = <0x100104 0x10000 0x8010e 0x20000>; + reg = <0x4011000 0x100 0xe010800 0x200>; compatible = "ibm,power9-pbcq"; ibm,pec-index = <0x1>; #address-cells = <0x1>; @@ -4845,7 +4853,7 @@ pbcq@4011400 { phandle = <0x161>; - reg = <0x140104 0x10000 0x8010f 0x20000>; + reg = <0x4011400 0x100 0xf010800 0x200>; compatible = "ibm,power9-pbcq"; ibm,pec-index = <0x2>; #address-cells = <0x1>; diff --git a/hdata/test/p8-840-spira.dts b/hdata/test/p8-840-spira.dts index dfd262845..625935d30 100644 --- a/hdata/test/p8-840-spira.dts +++ b/hdata/test/p8-840-spira.dts @@ -1,8 +1,8 @@ /dts-v1/; -/memreserve/ 0x000070fd07000000 0x0000100000000000; -/memreserve/ 0x00006afd07000000 0x0000060000000000; -/memreserve/ 0x000051fd07000000 0x0000190000000000; +/memreserve/ 0x00000007fd510000 0x0000000000190000; +/memreserve/ 0x00000007fd6a0000 0x0000000000060000; +/memreserve/ 0x00000007fd700000 0x0000000000100000; / { phandle = <0x1>; #address-cells = <0x2>; @@ -12,7 +12,7 @@ nest-frequency = <0x0 0x77359400>; vendor = "IBM"; ibm,io-base-loc-code = "U78C9.001.WZS0CWX-P1"; - ibm,vpd-lx-info = <0x0 0x1040031 0x43003000>; + ibm,vpd-lx-info = <0x0 0x31000401 0x300043>; model = "8286-41A"; system-id = "TU00163"; system-brand = "S0"; @@ -991,7 +991,7 @@ pbcq@2012000 { phandle = <0x4c>; - reg = <0x200102 0x20000000 0x200109 0x5000000 0x3c0109 0x15000000>; + reg = <0x2012000 0x20 0x9012000 0x05 0x9013c00 0x15>; compatible = "ibm,power8-pbcq"; ibm,phb-index = <0x0>; ibm,hub-id = <0x0>; @@ -1002,7 +1002,7 @@ pbcq@2012400 { phandle = <0x4d>; - reg = <0x240102 0x20000000 0x240109 0x5000000 0x403c0109 0x15000000>; + reg = <0x2012400 0x20 0x9012400 0x05 0x9013c40 0x15>; compatible = "ibm,power8-pbcq"; ibm,phb-index = <0x1>; ibm,hub-id = <0x0>; @@ -1056,7 +1056,7 @@ pbcq@2012000 { phandle = <0x4e>; - reg = <0x200102 0x20000000 0x200109 0x5000000 0x3c0109 0x15000000>; + reg = <0x2012000 0x20 0x9012000 0x05 0x9013c00 0x15>; compatible = "ibm,power8-pbcq"; ibm,phb-index = <0x0>; ibm,hub-id = <0x1>; @@ -1067,7 +1067,7 @@ pbcq@2012400 { phandle = <0x4f>; - reg = <0x240102 0x20000000 0x240109 0x5000000 0x403c0109 0x15000000>; + reg = <0x2012400 0x20 0x9012400 0x05 0x9013c40 0x15>; compatible = "ibm,power8-pbcq"; ibm,phb-index = <0x1>; ibm,hub-id = <0x1>; diff --git a/hdata/test/p81-811.spira.dts b/hdata/test/p81-811.spira.dts index cea6a32c5..ed7bd5deb 100644 --- a/hdata/test/p81-811.spira.dts +++ b/hdata/test/p81-811.spira.dts @@ -1,8 +1,9 @@ /dts-v1/; -/memreserve/ 0x000070fd1f000000 0x0000100000000000; -/memreserve/ 0x00d06bfd1f000000 0x0030040000000000; -/memreserve/ 0x006058fd1f000000 0x0070130000000000; +/memreserve/ 0x0000001ffd586000 0x0000000000137000; +/memreserve/ 0x0000001ffd6bd000 0x0000000000043000; +/memreserve/ 0x0000001ffd700000 0x0000000000100000; + / { phandle = <0x1>; #address-cells = <0x2>; @@ -12,7 +13,7 @@ nest-frequency = <0x0 0x77359400>; vendor = "IBM"; ibm,io-base-loc-code = "U78CB.001.WZS00AL-P1"; - ibm,vpd-lx-info = <0x0 0x1040031 0x42003000>; + ibm,vpd-lx-info = <0x0 0x31000401 0x300042>; model = "8247-22L"; system-id = "1010C8A"; system-brand = "S0"; @@ -1401,7 +1402,7 @@ hw-version = <0x2>; sw-version = <0x1>; primary; - ibm,psi-links = <0x0 0x10000000>; + ibm,psi-links = <0x0 0x10>; }; }; @@ -2209,7 +2210,7 @@ pbcq@2012000 { phandle = <0x95>; - reg = <0x200102 0x20000000 0x200109 0x5000000 0x3c0109 0x15000000>; + reg = <0x2012000 0x20 0x9012000 0x05 0x9013c00 0x15>; compatible = "ibm,power8-pbcq"; ibm,phb-index = <0x0>; ibm,hub-id = <0x0>; @@ -2220,7 +2221,7 @@ pbcq@2012400 { phandle = <0x96>; - reg = <0x240102 0x20000000 0x240109 0x5000000 0x403c0109 0x15000000>; + reg = <0x2012400 0x20 0x9012400 0x05 0x9013c40 0x15>; compatible = "ibm,power8-pbcq"; ibm,phb-index = <0x1>; ibm,hub-id = <0x0>; @@ -2273,7 +2274,7 @@ pbcq@2012000 { phandle = <0x97>; - reg = <0x200102 0x20000000 0x200109 0x5000000 0x3c0109 0x15000000>; + reg = <0x2012000 0x20 0x9012000 0x05 0x9013c00 0x15>; compatible = "ibm,power8-pbcq"; ibm,phb-index = <0x0>; ibm,hub-id = <0x1>; @@ -2284,7 +2285,7 @@ pbcq@2012400 { phandle = <0x98>; - reg = <0x240102 0x20000000 0x240109 0x5000000 0x403c0109 0x15000000>; + reg = <0x2012400 0x20 0x9012400 0x05 0x9013c40 0x15>; compatible = "ibm,power8-pbcq"; ibm,phb-index = <0x1>; ibm,hub-id = <0x1>; @@ -2336,7 +2337,7 @@ pbcq@2012000 { phandle = <0x99>; - reg = <0x200102 0x20000000 0x200109 0x5000000 0x3c0109 0x15000000>; + reg = <0x2012000 0x20 0x9012000 0x05 0x9013c00 0x15>; compatible = "ibm,power8-pbcq"; ibm,phb-index = <0x0>; ibm,hub-id = <0x2>; @@ -2388,7 +2389,7 @@ pbcq@2012000 { phandle = <0x9a>; - reg = <0x200102 0x20000000 0x200109 0x5000000 0x3c0109 0x15000000>; + reg = <0x2012000 0x20 0x9012000 0x05 0x9013c00 0x15>; compatible = "ibm,power8-pbcq"; ibm,phb-index = <0x0>; ibm,hub-id = <0x3>; @@ -2399,7 +2400,7 @@ pbcq@2012400 { phandle = <0x9b>; - reg = <0x240102 0x20000000 0x240109 0x5000000 0x403c0109 0x15000000>; + reg = <0x2012400 0x20 0x9012400 0x05 0x9013c40 0x15>; compatible = "ibm,power8-pbcq"; ibm,phb-index = <0x1>; ibm,hub-id = <0x3>; diff --git a/hw/fsp/fsp-sysparam.c b/hw/fsp/fsp-sysparam.c index 09005ef87..0e1e8181f 100644 --- a/hw/fsp/fsp-sysparam.c +++ b/hw/fsp/fsp-sysparam.c @@ -469,8 +469,8 @@ static void add_opal_sysparam_node(void) strcpy(s, sysparam_attrs[i].name); s = s + strlen(sysparam_attrs[i].name) + 1; - ids[i] = sysparam_attrs[i].id; - lens[i] = sysparam_attrs[i].length; + ids[i] = cpu_to_be32(sysparam_attrs[i].id); + lens[i] = cpu_to_be32(sysparam_attrs[i].length); perms[i] = sysparam_attrs[i].perm; } diff --git a/hw/fsp/fsp.c b/hw/fsp/fsp.c index f368998fb..2b2c5379a 100644 --- a/hw/fsp/fsp.c +++ b/hw/fsp/fsp.c @@ -1912,7 +1912,7 @@ static void fsp_init_links(struct dt_node *fsp_node) u64 reg; u32 link; - link = ((const u32 *)linksprop->prop)[i]; + link = be32_to_cpu(((const __be32 *)linksprop->prop)[i]); fiop = &fsp->iopath[i]; fiop->psi = psi_find_link(link); if (fiop->psi == NULL) { diff --git a/hw/imc.c b/hw/imc.c index ca06f3c36..16b060d39 100644 --- a/hw/imc.c +++ b/hw/imc.c @@ -458,8 +458,8 @@ static void imc_dt_update_nest_node(struct dt_node *dev) base_addr = malloc(sizeof(uint64_t) * nr_chip); chipids = malloc(sizeof(uint32_t) * nr_chip); for_each_chip(chip) { - base_addr[i] = chip->homer_base; - chipids[i] = chip->id; + base_addr[i] = cpu_to_be64(chip->homer_base); + chipids[i] = cpu_to_be32(chip->id); i++; } diff --git a/hw/lpc.c b/hw/lpc.c index 354d2b4f0..ec5146fbf 100644 --- a/hw/lpc.c +++ b/hw/lpc.c @@ -873,7 +873,7 @@ unsigned int lpc_get_irq_policy(uint32_t chip_id, uint32_t psi_idx) static void lpc_create_int_map(struct lpcm *lpc, struct dt_node *psi_node) { - uint32_t map[LPC_NUM_SERIRQ * 5], *pmap; + __be32 map[LPC_NUM_SERIRQ * 5], *pmap; uint32_t i; if (!psi_node) @@ -884,9 +884,9 @@ static void lpc_create_int_map(struct lpcm *lpc, struct dt_node *psi_node) continue; *(pmap++) = 0; *(pmap++) = 0; - *(pmap++) = i; - *(pmap++) = psi_node->phandle; - *(pmap++) = lpc->sirq_routes[i] + P9_PSI_IRQ_LPC_SIRQ0; + *(pmap++) = cpu_to_be32(i); + *(pmap++) = cpu_to_be32(psi_node->phandle); + *(pmap++) = cpu_to_be32(lpc->sirq_routes[i] + P9_PSI_IRQ_LPC_SIRQ0); } if (pmap == map) return; diff --git a/hw/psi.c b/hw/psi.c index 73e49ceb7..30c2a6cbc 100644 --- a/hw/psi.c +++ b/hw/psi.c @@ -786,10 +786,10 @@ static void psi_create_p9_int_map(struct psi *psi, struct dt_node *np) int i; for (i = 0; i < P9_PSI_NUM_IRQS; i++) { - map[i][0] = i; - map[i][1] = get_ics_phandle(); - map[i][2] = psi->interrupt + i; - map[i][3] = 1; + map[i][0] = cpu_to_be32(i); + map[i][1] = cpu_to_be32(get_ics_phandle()); + map[i][2] = cpu_to_be32(psi->interrupt + i); + map[i][3] = cpu_to_be32(1); } dt_add_property(np, "interrupt-map", map, sizeof(map)); dt_add_property_cells(np, "#address-cells", 0); diff --git a/hw/vas.c b/hw/vas.c index b913519b9..b4af31d12 100644 --- a/hw/vas.c +++ b/hw/vas.c @@ -379,7 +379,6 @@ static struct vas *alloc_vas(uint32_t chip_id, uint32_t vas_id, uint64_t base) static void create_mm_dt_node(struct proc_chip *chip) { - int gcid; struct dt_node *dn; struct vas *vas; uint64_t hvwc_start, hvwc_len; @@ -388,7 +387,6 @@ static void create_mm_dt_node(struct proc_chip *chip) uint64_t pbf_start, pbf_nbits; vas = chip->vas; - gcid = chip->id; get_hvwc_mmio_bar(chip->id, &hvwc_start, &hvwc_len); get_uwc_mmio_bar(chip->id, &uwc_start, &uwc_len); get_paste_bar(chip->id, &pbar_start, &pbar_len); @@ -404,8 +402,8 @@ static void create_mm_dt_node(struct proc_chip *chip) pbar_start, pbar_len, pbf_start, pbf_nbits); - dt_add_property(dn, "ibm,vas-id", &vas->vas_id, sizeof(vas->vas_id)); - dt_add_property(dn, "ibm,chip-id", &gcid, sizeof(gcid)); + dt_add_property_cells(dn, "ibm,vas-id", vas->vas_id); + dt_add_property_cells(dn, "ibm,chip-id", chip->id); if (vas->vas_irq) { dt_add_property_cells(dn, "interrupts", vas->vas_irq, 0); dt_add_property_cells(dn, "interrupt-parent", From patchwork Sun Dec 8 12:22:45 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205618 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5D333ZQz9sP3 for ; Sun, 8 Dec 2019 23:26:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="sHi4BVJH"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5D30pjZzDqGS for ; Sun, 8 Dec 2019 23:26:43 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::432; helo=mail-pf1-x432.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="sHi4BVJH"; dkim-atps=neutral Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W58M73klzDqDV for ; Sun, 8 Dec 2019 23:23:31 +1100 (AEDT) Received: by mail-pf1-x432.google.com with SMTP id s18so5744610pfd.8 for ; Sun, 08 Dec 2019 04:23:31 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=21xJy6qGS4RUbS6wrAsGdINkbfr2KVe2D3EuCs4cJO0=; b=sHi4BVJH8eqi01ybG5nkHpZT8l5DrK1TNfW0ClyDU+NILLdV4g3CJT1td61sslR1aa lSqnz5y0DAgJrnwAD+ObJFyiRypcdYq2WwIcklsWRWFJWQSjDhWpkPXZ/HGsIaCxAkrx dufQdsQgYjCyKQ8z808CgG0Fprhk5z3jT+F09nWK4gq71peLkGq/AXwrWVBhSjr9CAOS gnbaNiw/ONecp/2Ak2oM+o7RJ+xPJl8tGwVq2xz+hUeapxgp5SN8SCK9bSeQg4c1gUWI p2EXzbfWTEQSwJOC+KmCBB8W8j8nwWmtnGnriwOtbfQI0rgIe02Qzc5Uyw4+219gDudl YorQ== 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=21xJy6qGS4RUbS6wrAsGdINkbfr2KVe2D3EuCs4cJO0=; b=J/bszkt79OqlRECvHP5Xu5C6SGcn0nXvE7ukdHfsnssnfC2GkPqZzcQicnekdNyK7x UCvN/WDur2bDsOwhP9k1VZkvosoYWzc0eV9ddatZg8NTa4ZPwfrN7dGkPTxy5x1yyfVt Da3BfYNcfuMp+XZShxkdRj3W3SLbNROBj4eYDGW+a5t74ITppv8bWBVA6pFpZsu8cdTx A6LHX8m0rCP8TDFrWRGyXeuo73U1NkK5S8+t6r0H2++U6yO13WnDigXo87RZUsFPZ4qr 95uM/HvdspFNBfFymKI6skgStCKqwQYUcZinD5SRhyKtdRiVAioArYv8AR5Wigj7uHgB WYQw== X-Gm-Message-State: APjAAAWTBAWKIzoE2IK3bZVRRQUWYZ5Jok7DSKwK8gsMRe+KvEDzb/J7 grF+vaVrTsiCPFcSutJnAhqQkjvG X-Google-Smtp-Source: APXvYqxSaKhy2eK4bab618Tp3B9hynx7dL1yl/NFBkECigzR+G1OGOyn913/D1D8jng5+FDrvrsruw== X-Received: by 2002:a62:8202:: with SMTP id w2mr24918125pfd.100.1575807808100; Sun, 08 Dec 2019 04:23:28 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.23.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:23:27 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:45 +1000 Message-Id: <20191208122312.12837-5-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 04/31] opal-api: add endian conversions to most opal calls X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This adds missing endian conversions to most calls, sufficient at least to handle calls from a kernel booting on mambo. Subsystems requiring more extensive changes (e.g., xive) will be done with individual changes. Signed-off-by: Nicholas Piggin Reviewed-by: Vasant Hegde --- core/console.c | 19 ++++--- core/interrupts.c | 8 ++- core/ipmi-opal.c | 6 +-- core/pci-opal.c | 100 +++++++++++++++++++++++++++--------- core/powercap.c | 14 +++-- core/psr.c | 14 +++-- core/sensor.c | 52 +++++++++++-------- hw/dts.c | 12 ++--- hw/fake-rtc.c | 11 ++-- hw/fsp/fsp-console.c | 26 ++++++---- hw/fsp/fsp-rtc.c | 25 +++++---- hw/fsp/fsp-sensor.c | 8 +-- hw/ipmi/ipmi-rtc.c | 11 ++-- hw/lpc-rtc.c | 11 ++-- hw/lpc-uart.c | 16 +++--- hw/lpc.c | 29 +++++++---- hw/npu2-opencapi.c | 12 +++-- hw/occ-sensor.c | 13 +++-- hw/phb4.c | 6 +-- hw/xscom.c | 19 ++++++- include/console.h | 6 +-- include/cpu.h | 2 +- include/dts.h | 2 +- include/fsp.h | 2 +- include/occ.h | 2 +- include/pci.h | 2 +- include/platform.h | 2 +- platforms/ibm-fsp/ibm-fsp.h | 2 +- platforms/mambo/mambo.c | 9 +++- 29 files changed, 290 insertions(+), 151 deletions(-) diff --git a/core/console.c b/core/console.c index 139ba4a97..ac88f0c71 100644 --- a/core/console.c +++ b/core/console.c @@ -351,22 +351,25 @@ void memcons_add_properties(void) * complicated since they can come from the in-memory console (BML) or from the * internal skiboot console driver. */ -static int64_t dummy_console_write(int64_t term_number, int64_t *length, +static int64_t dummy_console_write(int64_t term_number, __be64 *length, const uint8_t *buffer) { + uint64_t l; + if (term_number != 0) return OPAL_PARAMETER; if (!opal_addr_valid(length) || !opal_addr_valid(buffer)) return OPAL_PARAMETER; - write(0, buffer, *length); + l = be64_to_cpu(*length); + write(0, buffer, l); return OPAL_SUCCESS; } static int64_t dummy_console_write_buffer_space(int64_t term_number, - int64_t *length) + __be64 *length) { if (term_number != 0) return OPAL_PARAMETER; @@ -375,21 +378,25 @@ static int64_t dummy_console_write_buffer_space(int64_t term_number, return OPAL_PARAMETER; if (length) - *length = INMEM_CON_OUT_LEN; + *length = cpu_to_be64(INMEM_CON_OUT_LEN); return OPAL_SUCCESS; } -static int64_t dummy_console_read(int64_t term_number, int64_t *length, +static int64_t dummy_console_read(int64_t term_number, __be64 *length, uint8_t *buffer) { + uint64_t l; + if (term_number != 0) return OPAL_PARAMETER; if (!opal_addr_valid(length) || !opal_addr_valid(buffer)) return OPAL_PARAMETER; - *length = read(0, buffer, *length); + l = be64_to_cpu(*length); + l = read(0, buffer, l); + *length = cpu_to_be64(l); opal_update_pending_evt(OPAL_EVENT_CONSOLE_INPUT, 0); return OPAL_SUCCESS; diff --git a/core/interrupts.c b/core/interrupts.c index 10baa15f6..d4a2c3124 100644 --- a/core/interrupts.c +++ b/core/interrupts.c @@ -439,9 +439,11 @@ static int64_t opal_set_xive(uint32_t isn, uint16_t server, uint8_t priority) } opal_call(OPAL_SET_XIVE, opal_set_xive, 3); -static int64_t opal_get_xive(uint32_t isn, uint16_t *server, uint8_t *priority) +static int64_t opal_get_xive(uint32_t isn, __be16 *server, uint8_t *priority) { struct irq_source *is = irq_find_source(isn); + uint16_t s; + int64_t ret; if (!opal_addr_valid(server)) return OPAL_PARAMETER; @@ -449,7 +451,9 @@ static int64_t opal_get_xive(uint32_t isn, uint16_t *server, uint8_t *priority) if (!is || !is->ops->get_xive) return OPAL_PARAMETER; - return is->ops->get_xive(is, isn, server, priority); + ret = is->ops->get_xive(is, isn, &s, priority); + *server = cpu_to_be16(s); + return ret; } opal_call(OPAL_GET_XIVE, opal_get_xive, 3); diff --git a/core/ipmi-opal.c b/core/ipmi-opal.c index 796508ca0..d36962d36 100644 --- a/core/ipmi-opal.c +++ b/core/ipmi-opal.c @@ -57,7 +57,7 @@ static int64_t opal_ipmi_send(uint64_t interface, } static int64_t opal_ipmi_recv(uint64_t interface, - struct opal_ipmi_msg *opal_ipmi_msg, uint64_t *msg_len) + struct opal_ipmi_msg *opal_ipmi_msg, __be64 *msg_len) { struct ipmi_msg *msg; int64_t rc; @@ -82,7 +82,7 @@ static int64_t opal_ipmi_recv(uint64_t interface, goto out_del_msg; } - if (*msg_len - sizeof(struct opal_ipmi_msg) < msg->resp_size + 1) { + if (be64_to_cpu(*msg_len) - sizeof(struct opal_ipmi_msg) < msg->resp_size + 1) { rc = OPAL_RESOURCE; goto out_del_msg; } @@ -101,7 +101,7 @@ static int64_t opal_ipmi_recv(uint64_t interface, msg->cmd, msg->netfn >> 2, msg->resp_size); /* Add one as the completion code is returned in the message data */ - *msg_len = msg->resp_size + sizeof(struct opal_ipmi_msg) + 1; + *msg_len = cpu_to_be64(msg->resp_size + sizeof(struct opal_ipmi_msg) + 1); ipmi_free_msg(msg); return OPAL_SUCCESS; diff --git a/core/pci-opal.c b/core/pci-opal.c index ce8de6325..4dc5237cc 100644 --- a/core/pci-opal.c +++ b/core/pci-opal.c @@ -58,9 +58,38 @@ OPAL_PCICFG_ACCESS_WRITE(write_byte, write8, uint8_t) OPAL_PCICFG_ACCESS_WRITE(write_half_word, write16, uint16_t) OPAL_PCICFG_ACCESS_WRITE(write_word, write32, uint32_t) +static int64_t opal_pci_config_read_half_word_be(uint64_t phb_id, + uint64_t bus_dev_func, + uint64_t offset, + __be16 *__data) +{ + uint16_t data; + int64_t rc; + + rc = opal_pci_config_read_half_word(phb_id, bus_dev_func, offset, &data); + *__data = cpu_to_be16(data); + + return rc; +} + +static int64_t opal_pci_config_read_word_be(uint64_t phb_id, + uint64_t bus_dev_func, + uint64_t offset, + __be32 *__data) +{ + uint32_t data; + int64_t rc; + + rc = opal_pci_config_read_word(phb_id, bus_dev_func, offset, &data); + *__data = cpu_to_be32(data); + + return rc; +} + + opal_call(OPAL_PCI_CONFIG_READ_BYTE, opal_pci_config_read_byte, 4); -opal_call(OPAL_PCI_CONFIG_READ_HALF_WORD, opal_pci_config_read_half_word, 4); -opal_call(OPAL_PCI_CONFIG_READ_WORD, opal_pci_config_read_word, 4); +opal_call(OPAL_PCI_CONFIG_READ_HALF_WORD, opal_pci_config_read_half_word_be, 4); +opal_call(OPAL_PCI_CONFIG_READ_WORD, opal_pci_config_read_word_be, 4); opal_call(OPAL_PCI_CONFIG_WRITE_BYTE, opal_pci_config_write_byte, 4); opal_call(OPAL_PCI_CONFIG_WRITE_HALF_WORD, opal_pci_config_write_half_word, 4); opal_call(OPAL_PCI_CONFIG_WRITE_WORD, opal_pci_config_write_word, 4); @@ -87,14 +116,15 @@ void opal_pci_eeh_clear_evt(uint64_t phb_id) static int64_t opal_pci_eeh_freeze_status(uint64_t phb_id, uint64_t pe_number, uint8_t *freeze_state, - uint16_t *pci_error_type, - uint64_t *phb_status) + __be16 *__pci_error_type, + __be64 *__phb_status) { struct phb *phb = pci_get_phb(phb_id); + uint16_t pci_error_type; int64_t rc; - if (!opal_addr_valid(freeze_state) || !opal_addr_valid(pci_error_type) - || !opal_addr_valid(phb_status)) + if (!opal_addr_valid(freeze_state) || !opal_addr_valid(__pci_error_type) + || !opal_addr_valid(__phb_status)) return OPAL_PARAMETER; if (!phb) @@ -103,12 +133,13 @@ static int64_t opal_pci_eeh_freeze_status(uint64_t phb_id, uint64_t pe_number, return OPAL_UNSUPPORTED; phb_lock(phb); - if (phb_status) + if (__phb_status) prlog(PR_ERR, "PHB#%04llx: %s: deprecated PHB status\n", phb_id, __func__); rc = phb->ops->eeh_freeze_status(phb, pe_number, freeze_state, - pci_error_type, NULL); + &pci_error_type, NULL); + *__pci_error_type = cpu_to_be16(pci_error_type); phb_unlock(phb); return rc; @@ -371,12 +402,14 @@ opal_call(OPAL_PCI_SET_XIVE_PE, opal_pci_set_xive_pe, 3); static int64_t opal_get_msi_32(uint64_t phb_id, uint32_t mve_number, uint32_t xive_num, uint8_t msi_range, - uint32_t *msi_address, uint32_t *message_data) + __be32 *__msi_address, __be32 *__message_data) { struct phb *phb = pci_get_phb(phb_id); + uint32_t msi_address; + uint32_t message_data; int64_t rc; - if (!opal_addr_valid(msi_address) || !opal_addr_valid(message_data)) + if (!opal_addr_valid(__msi_address) || !opal_addr_valid(__message_data)) return OPAL_PARAMETER; if (!phb) @@ -385,21 +418,26 @@ static int64_t opal_get_msi_32(uint64_t phb_id, uint32_t mve_number, return OPAL_UNSUPPORTED; phb_lock(phb); rc = phb->ops->get_msi_32(phb, mve_number, xive_num, msi_range, - msi_address, message_data); + &msi_address, &message_data); phb_unlock(phb); + *__msi_address = cpu_to_be32(msi_address); + *__message_data = cpu_to_be32(message_data); + return rc; } opal_call(OPAL_GET_MSI_32, opal_get_msi_32, 6); static int64_t opal_get_msi_64(uint64_t phb_id, uint32_t mve_number, uint32_t xive_num, uint8_t msi_range, - uint64_t *msi_address, uint32_t *message_data) + __be64 *__msi_address, __be32 *__message_data) { struct phb *phb = pci_get_phb(phb_id); + uint64_t msi_address; + uint32_t message_data; int64_t rc; - if (!opal_addr_valid(msi_address) || !opal_addr_valid(message_data)) + if (!opal_addr_valid(__msi_address) || !opal_addr_valid(__message_data)) return OPAL_PARAMETER; if (!phb) @@ -408,9 +446,12 @@ static int64_t opal_get_msi_64(uint64_t phb_id, uint32_t mve_number, return OPAL_UNSUPPORTED; phb_lock(phb); rc = phb->ops->get_msi_64(phb, mve_number, xive_num, msi_range, - msi_address, message_data); + &msi_address, &message_data); phb_unlock(phb); + *__msi_address = cpu_to_be64(msi_address); + *__message_data = cpu_to_be32(message_data); + return rc; } opal_call(OPAL_GET_MSI_64, opal_get_msi_64, 6); @@ -482,7 +523,7 @@ static int64_t opal_phb_set_option(uint64_t phb_id, uint64_t opt, opal_call(OPAL_PHB_SET_OPTION, opal_phb_set_option, 3); static int64_t opal_phb_get_option(uint64_t phb_id, uint64_t opt, - uint64_t *setting) + __be64 *setting) { struct phb *phb = pci_get_phb(phb_id); int64_t rc; @@ -958,14 +999,17 @@ static int64_t opal_pci_get_phb_diag_data2(uint64_t phb_id, } opal_call(OPAL_PCI_GET_PHB_DIAG_DATA2, opal_pci_get_phb_diag_data2, 3); -static int64_t opal_pci_next_error(uint64_t phb_id, uint64_t *first_frozen_pe, - uint16_t *pci_error_type, uint16_t *severity) +static int64_t opal_pci_next_error(uint64_t phb_id, __be64 *__first_frozen_pe, + __be16 *__pci_error_type, __be16 *__severity) { struct phb *phb = pci_get_phb(phb_id); + uint64_t first_frozen_pe; + uint16_t pci_error_type; + uint16_t severity; int64_t rc; - if (!opal_addr_valid(first_frozen_pe) || - !opal_addr_valid(pci_error_type) || !opal_addr_valid(severity)) + if (!opal_addr_valid(__first_frozen_pe) || + !opal_addr_valid(__pci_error_type) || !opal_addr_valid(__severity)) return OPAL_PARAMETER; if (!phb) @@ -975,10 +1019,14 @@ static int64_t opal_pci_next_error(uint64_t phb_id, uint64_t *first_frozen_pe, phb_lock(phb); opal_pci_eeh_clear_evt(phb_id); - rc = phb->ops->next_error(phb, first_frozen_pe, pci_error_type, - severity); + rc = phb->ops->next_error(phb, &first_frozen_pe, &pci_error_type, + &severity); phb_unlock(phb); + *__first_frozen_pe = cpu_to_be64(first_frozen_pe); + *__pci_error_type = cpu_to_be16(pci_error_type); + *__severity = cpu_to_be16(severity); + return rc; } opal_call(OPAL_PCI_NEXT_ERROR, opal_pci_next_error, 4); @@ -1039,11 +1087,12 @@ static int64_t opal_pci_set_p2p(uint64_t phbid_init, uint64_t phbid_target, } opal_call(OPAL_PCI_SET_P2P, opal_pci_set_p2p, 4); -static int64_t opal_pci_get_pbcq_tunnel_bar(uint64_t phb_id, uint64_t *addr) +static int64_t opal_pci_get_pbcq_tunnel_bar(uint64_t phb_id, __be64 *__addr) { struct phb *phb = pci_get_phb(phb_id); + uint64_t addr; - if (!opal_addr_valid(addr)) + if (!opal_addr_valid(__addr)) return OPAL_PARAMETER; if (!phb) @@ -1052,8 +1101,11 @@ static int64_t opal_pci_get_pbcq_tunnel_bar(uint64_t phb_id, uint64_t *addr) return OPAL_UNSUPPORTED; phb_lock(phb); - phb->ops->get_tunnel_bar(phb, addr); + phb->ops->get_tunnel_bar(phb, &addr); phb_unlock(phb); + + *__addr = cpu_to_be64(addr); + return OPAL_SUCCESS; } opal_call(OPAL_PCI_GET_PBCQ_TUNNEL_BAR, opal_pci_get_pbcq_tunnel_bar, 2); diff --git a/core/powercap.c b/core/powercap.c index b9d172b54..de2a79095 100644 --- a/core/powercap.c +++ b/core/powercap.c @@ -7,13 +7,19 @@ #include -static int opal_get_powercap(u32 handle, int token __unused, u32 *pcap) +static int opal_get_powercap(u32 handle, int token __unused, __be32 *__pcap) { - if (!pcap || !opal_addr_valid(pcap)) + if (!__pcap || !opal_addr_valid(__pcap)) return OPAL_PARAMETER; - if (powercap_get_class(handle) == POWERCAP_CLASS_OCC) - return occ_get_powercap(handle, pcap); + if (powercap_get_class(handle) == POWERCAP_CLASS_OCC) { + u32 pcap; + int rc; + + rc = occ_get_powercap(handle, &pcap); + *__pcap = cpu_to_be32(pcap); + return rc; + } return OPAL_UNSUPPORTED; }; diff --git a/core/psr.c b/core/psr.c index 4cd3768ae..6698df8d2 100644 --- a/core/psr.c +++ b/core/psr.c @@ -10,13 +10,19 @@ #include static int opal_get_power_shift_ratio(u32 handle, int token __unused, - u32 *ratio) + __be32 *__ratio) { - if (!ratio || !opal_addr_valid(ratio)) + if (!__ratio || !opal_addr_valid(__ratio)) return OPAL_PARAMETER; - if (psr_get_class(handle) == PSR_CLASS_OCC) - return occ_get_psr(handle, ratio); + if (psr_get_class(handle) == PSR_CLASS_OCC) { + u32 ratio; + int rc; + + rc = occ_get_psr(handle, &ratio); + *__ratio = cpu_to_be32(ratio); + return rc; + } return OPAL_UNSUPPORTED; }; diff --git a/core/sensor.c b/core/sensor.c index a804f968a..d63d909e6 100644 --- a/core/sensor.c +++ b/core/sensor.c @@ -20,12 +20,12 @@ static LIST_HEAD(async_read_list); struct sensor_async_read { struct list_node link; - u64 *sensor_data64; - u32 *sensor_data32; + __be64 *val; + __be32 *opal_data; int token; }; -static int add_to_async_read_list(int token, u32 *data32, u64 *data64) +static int add_to_async_read_list(int token, __be32 *opal_data, __be64 *val) { struct sensor_async_read *req; @@ -34,8 +34,8 @@ static int add_to_async_read_list(int token, u32 *data32, u64 *data64) return OPAL_NO_MEM; req->token = token; - req->sensor_data64 = data64; - req->sensor_data32 = data32; + req->val = val; + req->opal_data = opal_data; lock(&async_read_list_lock); list_add_tail(&async_read_list, &req->link); @@ -59,50 +59,58 @@ void check_sensor_read(int token) if (!req) goto out; - *req->sensor_data32 = *req->sensor_data64; - free(req->sensor_data64); + *req->opal_data = cpu_to_be32(be64_to_cpu(*req->val)); + free(req->val); list_del(&req->link); free(req); out: unlock(&async_read_list_lock); } -static s64 opal_sensor_read_u64(u32 sensor_hndl, int token, u64 *sensor_data) +static s64 opal_sensor_read_64(u32 sensor_hndl, int token, __be64 *data) { + s64 rc; + switch (sensor_get_family(sensor_hndl)) { case SENSOR_DTS: - return dts_sensor_read(sensor_hndl, token, sensor_data); + rc = dts_sensor_read(sensor_hndl, token, data); + return rc; + case SENSOR_OCC: - return occ_sensor_read(sensor_hndl, sensor_data); + rc = occ_sensor_read(sensor_hndl, data); + return rc; + default: break; } - if (platform.sensor_read) - return platform.sensor_read(sensor_hndl, token, sensor_data); + if (platform.sensor_read) { + rc = platform.sensor_read(sensor_hndl, token, data); + return rc; + } return OPAL_UNSUPPORTED; } static int64_t opal_sensor_read(uint32_t sensor_hndl, int token, - uint32_t *sensor_data) + __be32 *data) { - u64 *val; - s64 ret; + __be64 *val; + s64 rc; val = zalloc(sizeof(*val)); if (!val) return OPAL_NO_MEM; - ret = opal_sensor_read_u64(sensor_hndl, token, val); - if (!ret) { - *sensor_data = *val; + rc = opal_sensor_read_64(sensor_hndl, token, val); + if (rc == OPAL_SUCCESS) { + *data = cpu_to_be32(be64_to_cpu(*val)); free(val); - } else if (ret == OPAL_ASYNC_COMPLETION) { - ret = add_to_async_read_list(token, sensor_data, val); + } else if (rc == OPAL_ASYNC_COMPLETION) { + rc = add_to_async_read_list(token, data, val); } - return ret; + return rc; } static int opal_sensor_group_clear(u32 group_hndl, int token) @@ -139,6 +147,6 @@ void sensor_init(void) /* Register OPAL interface */ opal_register(OPAL_SENSOR_READ, opal_sensor_read, 3); opal_register(OPAL_SENSOR_GROUP_CLEAR, opal_sensor_group_clear, 2); - opal_register(OPAL_SENSOR_READ_U64, opal_sensor_read_u64, 3); + opal_register(OPAL_SENSOR_READ_U64, opal_sensor_read_64, 3); opal_register(OPAL_SENSOR_GROUP_ENABLE, opal_sensor_group_enable, 3); } diff --git a/hw/dts.c b/hw/dts.c index 31b068b78..c21c5c779 100644 --- a/hw/dts.c +++ b/hw/dts.c @@ -174,9 +174,9 @@ static void dts_async_read_temp(struct timer *t __unused, void *data, rc = dts_read_core_temp_p9(cpu->pir, &dts); if (!rc) { if (cpu->sensor_attr == SENSOR_DTS_ATTR_TEMP_MAX) - *cpu->sensor_data = dts.temp; + *cpu->sensor_data = cpu_to_be64(dts.temp); else if (cpu->sensor_attr == SENSOR_DTS_ATTR_TEMP_TRIP) - *cpu->sensor_data = dts.trip; + *cpu->sensor_data = cpu_to_be64(dts.trip); } if (!swkup_rc) @@ -191,7 +191,7 @@ static void dts_async_read_temp(struct timer *t __unused, void *data, } static int dts_read_core_temp(u32 pir, struct dts *dts, u8 attr, - int token, u64 *sensor_data) + int token, __be64 *sensor_data) { struct cpu_thread *cpu; int rc; @@ -286,7 +286,7 @@ enum sensor_dts_class { */ #define centaur_get_id(rid) (0x80000000 | ((rid) & 0x3ff)) -int64_t dts_sensor_read(u32 sensor_hndl, int token, u64 *sensor_data) +int64_t dts_sensor_read(u32 sensor_hndl, int token, __be64 *sensor_data) { uint8_t attr = sensor_get_attr(sensor_hndl); uint32_t rid = sensor_get_rid(sensor_hndl); @@ -313,9 +313,9 @@ int64_t dts_sensor_read(u32 sensor_hndl, int token, u64 *sensor_data) return rc; if (attr == SENSOR_DTS_ATTR_TEMP_MAX) - *sensor_data = dts.temp; + *sensor_data = cpu_to_be64(dts.temp); else if (attr == SENSOR_DTS_ATTR_TEMP_TRIP) - *sensor_data = dts.trip; + *sensor_data = cpu_to_be64(dts.trip); return 0; } diff --git a/hw/fake-rtc.c b/hw/fake-rtc.c index 328be97d9..fd2882d68 100644 --- a/hw/fake-rtc.c +++ b/hw/fake-rtc.c @@ -34,13 +34,15 @@ static int64_t fake_rtc_write(uint32_t ymd, uint64_t hmsm) return OPAL_SUCCESS; } -static int64_t fake_rtc_read(uint32_t *ymd, uint64_t *hmsm) +static int64_t fake_rtc_read(__be32 *__ymd, __be64 *__hmsm) { time_t sec; struct tm tm_calculated; + uint32_t ymd; + uint64_t hmsm; - if (!ymd || !hmsm) + if (!__ymd || !__hmsm) return OPAL_PARAMETER; /* Compute the emulated clock value */ @@ -48,10 +50,13 @@ static int64_t fake_rtc_read(uint32_t *ymd, uint64_t *hmsm) sec = tb_to_secs(mftb() - tb_synctime) + mktime(&tm_offset); gmtime_r(&sec, &tm_calculated); - tm_to_datetime(&tm_calculated, ymd, hmsm); + tm_to_datetime(&tm_calculated, &ymd, &hmsm); unlock(&emulation_lock); + *__ymd = cpu_to_be32(ymd); + *__hmsm = cpu_to_be64(hmsm); + return OPAL_SUCCESS; } diff --git a/hw/fsp/fsp-console.c b/hw/fsp/fsp-console.c index 1a2ecaba0..624efb469 100644 --- a/hw/fsp/fsp-console.c +++ b/hw/fsp/fsp-console.c @@ -579,7 +579,7 @@ void fsp_console_preinit(void) } -static int64_t fsp_console_write(int64_t term_number, int64_t *length, +static int64_t fsp_console_write(int64_t term_number, __be64 *__length, const uint8_t *buffer) { struct fsp_serial *fs; @@ -596,7 +596,7 @@ static int64_t fsp_console_write(int64_t term_number, int64_t *length, return OPAL_CLOSED; } /* Clamp to a reasonable size */ - requested = *length; + requested = be64_to_cpu(*__length); if (requested > 0x1000) requested = 0x1000; written = fsp_write_vserial(fs, buffer, requested); @@ -618,7 +618,7 @@ static int64_t fsp_console_write(int64_t term_number, int64_t *length, buffer[6], buffer[6], buffer[7], buffer[7]); #endif /* OPAL_DEBUG_CONSOLE_IO */ - *length = written; + *__length = cpu_to_be64(written); unlock(&fsp_con_lock); if (written) @@ -628,11 +628,12 @@ static int64_t fsp_console_write(int64_t term_number, int64_t *length, } static int64_t fsp_console_write_buffer_space(int64_t term_number, - int64_t *length) + __be64 *__length) { static bool elog_generated = false; struct fsp_serial *fs; struct fsp_serbuf_hdr *sb; + int64_t length; if (term_number < 0 || term_number >= MAX_SERIAL) return OPAL_PARAMETER; @@ -645,15 +646,16 @@ static int64_t fsp_console_write_buffer_space(int64_t term_number, return OPAL_CLOSED; } sb = fs->out_buf; - *length = (sb->next_out + SER_BUF_DATA_SIZE - sb->next_in - 1) + length = (sb->next_out + SER_BUF_DATA_SIZE - sb->next_in - 1) % SER_BUF_DATA_SIZE; unlock(&fsp_con_lock); /* Console buffer has enough space to write incoming data */ - if (*length != fs->out_buf_prev_len) { - fs->out_buf_prev_len = *length; + if (length != fs->out_buf_prev_len) { + fs->out_buf_prev_len = length; fs->out_buf_timeout = 0; + *__length = cpu_to_be64(length); return OPAL_SUCCESS; } @@ -667,8 +669,10 @@ static int64_t fsp_console_write_buffer_space(int64_t term_number, secs_to_tb(SER_BUFFER_OUT_TIMEOUT); } - if (tb_compare(mftb(), fs->out_buf_timeout) != TB_AAFTERB) + if (tb_compare(mftb(), fs->out_buf_timeout) != TB_AAFTERB) { + *__length = cpu_to_be64(length); return OPAL_SUCCESS; + } /* * FSP is still active but not reading console data. Hence @@ -686,13 +690,13 @@ static int64_t fsp_console_write_buffer_space(int64_t term_number, return OPAL_RESOURCE; } -static int64_t fsp_console_read(int64_t term_number, int64_t *length, +static int64_t fsp_console_read(int64_t term_number, __be64 *__length, uint8_t *buffer) { struct fsp_serial *fs; struct fsp_serbuf_hdr *sb; bool pending = false; - uint32_t old_nin, n, i, chunk, req = *length; + uint32_t old_nin, n, i, chunk, req = be64_to_cpu(*__length); int rc = OPAL_SUCCESS; if (term_number < 0 || term_number >= MAX_SERIAL) @@ -716,7 +720,7 @@ static int64_t fsp_console_read(int64_t term_number, int64_t *length, pending = true; n = req; } - *length = n; + *__length = cpu_to_be64(n); chunk = SER_BUF_DATA_SIZE - sb->next_out; if (chunk > n) diff --git a/hw/fsp/fsp-rtc.c b/hw/fsp/fsp-rtc.c index 53838f87c..e68836e66 100644 --- a/hw/fsp/fsp-rtc.c +++ b/hw/fsp/fsp-rtc.c @@ -249,12 +249,13 @@ static int64_t fsp_rtc_send_read_request(void) return OPAL_BUSY_EVENT; } -static int64_t fsp_opal_rtc_read(uint32_t *year_month_day, - uint64_t *hour_minute_second_millisecond) +static int64_t fsp_opal_rtc_read(__be32 *__ymd, __be64 *__hmsm) { int64_t rc; + uint32_t ymd; + uint64_t hmsm; - if (!year_month_day || !hour_minute_second_millisecond) + if (!__ymd || !__hmsm) return OPAL_PARAMETER; lock(&rtc_lock); @@ -267,8 +268,7 @@ static int64_t fsp_opal_rtc_read(uint32_t *year_month_day, /* During R/R of FSP, read cached TOD */ if (fsp_in_rr()) { if (rtc_tod_state == RTC_TOD_VALID) { - rtc_cache_get_datetime(year_month_day, - hour_minute_second_millisecond); + rtc_cache_get_datetime(&ymd, &hmsm); rc = OPAL_SUCCESS; } else { rc = OPAL_INTERNAL_ERROR; @@ -290,11 +290,9 @@ static int64_t fsp_opal_rtc_read(uint32_t *year_month_day, opal_rtc_eval_events(true); if (rtc_tod_state == RTC_TOD_VALID) { - rtc_cache_get_datetime(year_month_day, - hour_minute_second_millisecond); + rtc_cache_get_datetime(&ymd, &hmsm); prlog(PR_TRACE,"FSP-RTC Cached datetime: %x %llx\n", - *year_month_day, - *hour_minute_second_millisecond); + ymd, hmsm); rc = OPAL_SUCCESS; } else { rc = OPAL_INTERNAL_ERROR; @@ -306,8 +304,7 @@ static int64_t fsp_opal_rtc_read(uint32_t *year_month_day, prlog(PR_TRACE, "RTC read timed out\n"); if (rtc_tod_state == RTC_TOD_VALID) { - rtc_cache_get_datetime(year_month_day, - hour_minute_second_millisecond); + rtc_cache_get_datetime(&ymd, &hmsm); rc = OPAL_SUCCESS; } else { rc = OPAL_INTERNAL_ERROR; @@ -319,6 +316,12 @@ static int64_t fsp_opal_rtc_read(uint32_t *year_month_day, } out: unlock(&rtc_lock); + + if (rc == OPAL_SUCCESS) { + *__ymd = cpu_to_be32(ymd); + *__hmsm = cpu_to_be64(hmsm); + } + return rc; } diff --git a/hw/fsp/fsp-sensor.c b/hw/fsp/fsp-sensor.c index 43c8ce40b..74deac7a7 100644 --- a/hw/fsp/fsp-sensor.c +++ b/hw/fsp/fsp-sensor.c @@ -70,7 +70,7 @@ enum spcn_attr { /* Parsed sensor attributes, passed through OPAL */ struct opal_sensor_data { uint64_t async_token; /* Asynchronous token */ - uint64_t *sensor_data; /* Kernel pointer to copy data */ + __be64 *sensor_data; /* Kernel pointer to copy data */ enum spcn_attr spcn_attr; /* Modifier attribute */ uint16_t rid; /* Sensor RID */ uint8_t frc; /* Sensor resource class */ @@ -243,7 +243,7 @@ static void fsp_sensor_process_data(struct opal_sensor_data *attr) sensor_buf_ptr += spcn_mod_data[attr->mod_index].entry_size; } - *(attr->sensor_data) = sensor_data; + *attr->sensor_data = cpu_to_be64(sensor_data); if (sensor_data == INVALID_DATA) queue_msg_for_delivery(OPAL_PARTIAL, attr); else @@ -345,7 +345,7 @@ static void fsp_sensor_read_complete(struct fsp_msg *msg) unlock(&sensor_lock); return; err: - *(attr->sensor_data) = INVALID_DATA; + *attr->sensor_data = cpu_to_be64(INVALID_DATA); queue_msg_for_delivery(rc, attr); unlock(&sensor_lock); log_simple_error(&e_info(OPAL_RC_SENSOR_ASYNC_COMPLETE), @@ -496,7 +496,7 @@ static int64_t parse_sensor_id(uint32_t handler, struct opal_sensor_data *attr) int64_t fsp_opal_read_sensor(uint32_t sensor_hndl, int token, - uint64_t *sensor_data) + __be64 *sensor_data) { struct opal_sensor_data *attr; int64_t rc; diff --git a/hw/ipmi/ipmi-rtc.c b/hw/ipmi/ipmi-rtc.c index deb4addcb..ad98f21c6 100644 --- a/hw/ipmi/ipmi-rtc.c +++ b/hw/ipmi/ipmi-rtc.c @@ -62,12 +62,13 @@ static int64_t ipmi_set_sel_time(uint32_t _tv) return ipmi_queue_msg(msg); } -static int64_t ipmi_opal_rtc_read(uint32_t *y_m_d, - uint64_t *h_m_s_m) +static int64_t ipmi_opal_rtc_read(__be32 *__ymd, __be64 *__hmsm) { int ret = 0; + uint32_t ymd; + uint64_t hmsm; - if (!y_m_d || !h_m_s_m) + if (!__ymd || !__hmsm) return OPAL_PARAMETER; switch(time_status) { @@ -83,7 +84,9 @@ static int64_t ipmi_opal_rtc_read(uint32_t *y_m_d, break; case updated: - rtc_cache_get_datetime(y_m_d, h_m_s_m); + rtc_cache_get_datetime(&ymd, &hmsm); + *__ymd = cpu_to_be32(ymd); + *__hmsm = cpu_to_be64(hmsm); time_status = idle; ret = OPAL_SUCCESS; break; diff --git a/hw/lpc-rtc.c b/hw/lpc-rtc.c index f560c8c9f..ba15941fb 100644 --- a/hw/lpc-rtc.c +++ b/hw/lpc-rtc.c @@ -139,14 +139,15 @@ static void lpc_init_hw(void) unlock(&rtc_lock); } -static int64_t lpc_opal_rtc_read(uint32_t *y_m_d, - uint64_t *h_m_s_m) +static int64_t lpc_opal_rtc_read(__be32 *__ymd, __be64 *__hmsm) { uint8_t val; int64_t rc = OPAL_SUCCESS; struct tm tm; + uint32_t ymd; + uint64_t hmsm; - if (!y_m_d || !h_m_s_m) + if (!__ymd || !__hmsm) return OPAL_PARAMETER; /* Return busy if updating. This is somewhat racy, but will @@ -172,7 +173,9 @@ static int64_t lpc_opal_rtc_read(uint32_t *y_m_d, rtc_cache_update(&tm); /* Convert to OPAL time */ - tm_to_datetime(&tm, y_m_d, h_m_s_m); + tm_to_datetime(&tm, &ymd, &hmsm); + *__ymd = cpu_to_be32(ymd); + *__hmsm = cpu_to_be64(hmsm); } return rc; diff --git a/hw/lpc-uart.c b/hw/lpc-uart.c index feca229b6..b37e04201 100644 --- a/hw/lpc-uart.c +++ b/hw/lpc-uart.c @@ -255,10 +255,10 @@ static uint32_t uart_tx_buf_space(void) (out_buf_prod + OUT_BUF_SIZE - out_buf_cons) % OUT_BUF_SIZE; } -static int64_t uart_opal_write(int64_t term_number, int64_t *length, +static int64_t uart_opal_write(int64_t term_number, __be64 *__length, const uint8_t *buffer) { - size_t written = 0, len = *length; + size_t written = 0, len = be64_to_cpu(*__length); if (term_number != 0) return OPAL_PARAMETER; @@ -277,19 +277,19 @@ static int64_t uart_opal_write(int64_t term_number, int64_t *length, unlock(&uart_lock); - *length = written; + *__length = cpu_to_be64(written); return OPAL_SUCCESS; } static int64_t uart_opal_write_buffer_space(int64_t term_number, - int64_t *length) + __be64 *__length) { if (term_number != 0) return OPAL_PARAMETER; lock(&uart_lock); - *length = uart_tx_buf_space(); + *__length = cpu_to_be64(uart_tx_buf_space()); unlock(&uart_lock); return OPAL_SUCCESS; @@ -326,10 +326,10 @@ static void uart_adjust_opal_event(void) } /* This is called with the console lock held */ -static int64_t uart_opal_read(int64_t term_number, int64_t *length, +static int64_t uart_opal_read(int64_t term_number, __be64 *__length, uint8_t *buffer) { - size_t req_count = *length, read_cnt = 0; + size_t req_count = be64_to_cpu(*__length), read_cnt = 0; uint8_t lsr = 0; if (term_number != 0) @@ -373,7 +373,7 @@ static int64_t uart_opal_read(int64_t term_number, int64_t *length, /* Adjust the OPAL event */ uart_adjust_opal_event(); - *length = read_cnt; + *__length = cpu_to_be64(read_cnt); return OPAL_SUCCESS; } diff --git a/hw/lpc.c b/hw/lpc.c index ec5146fbf..abf549746 100644 --- a/hw/lpc.c +++ b/hw/lpc.c @@ -673,27 +673,36 @@ int64_t lpc_probe_read(enum OpalLPCAddressType addr_type, uint32_t addr, * existing Linux expectations */ static int64_t opal_lpc_read(uint32_t chip_id, enum OpalLPCAddressType addr_type, - uint32_t addr, uint32_t *data, uint32_t sz) + uint32_t addr, __be32 *data, uint32_t sz) { struct proc_chip *chip; int64_t rc; + uint32_t tmp; chip = get_chip(chip_id); if (!chip || !chip->lpc) return OPAL_PARAMETER; - if (addr_type == OPAL_LPC_FW || sz == 1) - return __lpc_read(chip->lpc, addr_type, addr, data, sz, false); - *data = 0; - while(sz--) { - uint32_t byte; - - rc = __lpc_read(chip->lpc, addr_type, addr, &byte, 1, false); + if (addr_type == OPAL_LPC_FW) { + rc = __lpc_read(chip->lpc, addr_type, addr, &tmp, sz, false); if (rc) return rc; - *data = *data | (byte << (8 * sz)); - addr++; + + } else { + tmp = 0; + while (sz--) { + uint32_t byte; + + rc = __lpc_read(chip->lpc, addr_type, addr, &byte, 1, false); + if (rc) + return rc; + tmp = tmp | (byte << (8 * sz)); + addr++; + } } + + *data = cpu_to_be32(tmp); + return OPAL_SUCCESS; } diff --git a/hw/npu2-opencapi.c b/hw/npu2-opencapi.c index ed6650f4b..19589c92d 100644 --- a/hw/npu2-opencapi.c +++ b/hw/npu2-opencapi.c @@ -2250,10 +2250,12 @@ out: } static int64_t opal_npu_mem_alloc(uint64_t phb_id, uint32_t __unused bdfn, - uint64_t size, uint64_t *bar) + uint64_t size, __be64 *__bar) { struct phb *phb = pci_get_phb(phb_id); struct npu2_dev *dev; + uint64_t bar; + int64_t rc; if (!phb || phb->phb_type != phb_type_npu_v2_opencapi) @@ -2263,10 +2265,14 @@ static int64_t opal_npu_mem_alloc(uint64_t phb_id, uint32_t __unused bdfn, if (!dev) return OPAL_PARAMETER; - if (!opal_addr_valid(bar)) + if (!opal_addr_valid(__bar)) return OPAL_PARAMETER; - return alloc_mem_bar(dev, size, bar); + rc = alloc_mem_bar(dev, size, &bar); + if (rc == OPAL_SUCCESS) + *__bar = cpu_to_be64(bar); + + return rc; } opal_call(OPAL_NPU_MEM_ALLOC, opal_npu_mem_alloc, 4); diff --git a/hw/occ-sensor.c b/hw/occ-sensor.c index 8434c1930..da846bd92 100644 --- a/hw/occ-sensor.c +++ b/hw/occ-sensor.c @@ -241,13 +241,14 @@ static void *select_sensor_buffer(struct occ_sensor_data_header *hb, int id) return buffer; } -int occ_sensor_read(u32 handle, u64 *data) +int occ_sensor_read(u32 handle, __be64 *data) { struct occ_sensor_data_header *hb; struct occ_sensor_name *md; u16 id = sensor_get_rid(handle); u8 occ_num = sensor_get_frc(handle); u8 attr = sensor_get_attr(handle); + u64 d; void *buff; if (occ_num > MAX_OCCS) @@ -271,15 +272,17 @@ int occ_sensor_read(u32 handle, u64 *data) if (!buff) return OPAL_HARDWARE; - *data = read_sensor(buff, attr); - if (!*data) + d = read_sensor(buff, attr); + if (!d) return OPAL_SUCCESS; md = get_names_block(hb); if (md[id].type == OCC_SENSOR_TYPE_POWER && attr == SENSOR_ACCUMULATOR) - scale_energy(&md[id], data); + scale_energy(&md[id], &d); else - scale_sensor(&md[id], data); + scale_sensor(&md[id], &d); + + *data = cpu_to_be64(d); return OPAL_SUCCESS; } diff --git a/hw/phb4.c b/hw/phb4.c index e96466d87..85d6a0c06 100644 --- a/hw/phb4.c +++ b/hw/phb4.c @@ -1571,7 +1571,7 @@ static int64_t phb4_set_option(struct phb *phb, enum OpalPhbOption opt, } static int64_t phb4_get_option(struct phb *phb, enum OpalPhbOption opt, - uint64_t *setting) + __be64 *setting) { struct phb4 *p = phb_to_phb4(phb); uint64_t data64; @@ -1579,10 +1579,10 @@ static int64_t phb4_get_option(struct phb *phb, enum OpalPhbOption opt, data64 = phb4_read_reg(p, PHB_CTRLR); switch (opt) { case OPAL_PHB_OPTION_TVE1_4GB: - *setting = (data64 & PPC_BIT(24)) ? 1 : 0; + *setting = cpu_to_be64((data64 & PPC_BIT(24)) ? 1 : 0); break; case OPAL_PHB_OPTION_MMIO_EEH_DISABLE: - *setting = (data64 & PPC_BIT(14)) ? 1 : 0; + *setting = cpu_to_be64((data64 & PPC_BIT(14)) ? 1 : 0); break; default: return OPAL_UNSUPPORTED; diff --git a/hw/xscom.c b/hw/xscom.c index 381cf2c4a..a85169598 100644 --- a/hw/xscom.c +++ b/hw/xscom.c @@ -638,7 +638,17 @@ int _xscom_read(uint32_t partid, uint64_t pcb_addr, uint64_t *val, bool take_loc return rc; } -opal_call(OPAL_XSCOM_READ, xscom_read, 3); +static int64_t opal_xscom_read(uint32_t partid, uint64_t pcb_addr, __be64 *__val) +{ + uint64_t val; + int64_t rc; + + rc = xscom_read(partid, pcb_addr, &val); + *__val = cpu_to_be64(val); + + return rc; +} +opal_call(OPAL_XSCOM_READ, opal_xscom_read, 3); int _xscom_write(uint32_t partid, uint64_t pcb_addr, uint64_t val, bool take_lock) { @@ -682,7 +692,12 @@ int _xscom_write(uint32_t partid, uint64_t pcb_addr, uint64_t val, bool take_loc unlock(&xscom_lock); return rc; } -opal_call(OPAL_XSCOM_WRITE, xscom_write, 3); + +static int64_t opal_xscom_write(uint32_t partid, uint64_t pcb_addr, uint64_t val) +{ + return xscom_write(partid, pcb_addr, val); +} +opal_call(OPAL_XSCOM_WRITE, opal_xscom_write, 3); /* * Perform a xscom read-modify-write. diff --git a/include/console.h b/include/console.h index 26602b7ac..230b825b0 100644 --- a/include/console.h +++ b/include/console.h @@ -47,13 +47,13 @@ struct opal_con_ops { */ void (*init)(void); - int64_t (*write)(int64_t term, int64_t *len, const uint8_t *buf); - int64_t (*read)(int64_t term, int64_t *len, uint8_t *buf); + int64_t (*write)(int64_t term, __be64 *__len, const uint8_t *buf); + int64_t (*read)(int64_t term, __be64 *__len, uint8_t *buf); /* * returns the amount of space available in the console write buffer */ - int64_t (*space)(int64_t term_number, int64_t *length); + int64_t (*space)(int64_t term_number, __be64 *__length); /* * Forces the write buffer to be flushed by the driver diff --git a/include/cpu.h b/include/cpu.h index 5fdcc9862..7b1c1bcf3 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -103,7 +103,7 @@ struct cpu_thread { */ struct lock dts_lock; struct timer dts_timer; - u64 *sensor_data; + __be64 *sensor_data; u32 sensor_attr; u32 token; bool dts_read_in_progress; diff --git a/include/dts.h b/include/dts.h index 2b54054e4..66f81a294 100644 --- a/include/dts.h +++ b/include/dts.h @@ -6,7 +6,7 @@ #include -extern int64_t dts_sensor_read(u32 sensor_hndl, int token, u64 *sensor_data); +extern int64_t dts_sensor_read(u32 sensor_hndl, int token, __be64 *sensor_data); extern bool dts_sensor_create_nodes(struct dt_node *sensors); #endif /* __DTS_H */ diff --git a/include/fsp.h b/include/fsp.h index b4c17598e..b2827b327 100644 --- a/include/fsp.h +++ b/include/fsp.h @@ -819,7 +819,7 @@ extern void fsp_memory_err_init(void); /* Sensor */ extern void fsp_init_sensor(void); extern int64_t fsp_opal_read_sensor(uint32_t sensor_hndl, int token, - uint64_t *sensor_data); + __be64 *sensor_data); /* Diagnostic */ extern void fsp_init_diag(void); diff --git a/include/occ.h b/include/occ.h index 0030af5ae..ab45e9e46 100644 --- a/include/occ.h +++ b/include/occ.h @@ -32,7 +32,7 @@ bool occ_get_gpu_presence(struct proc_chip *chip, int gpu_num); /* OCC Inband Sensors */ extern bool occ_sensors_init(void); -extern int occ_sensor_read(u32 handle, u64 *data); +extern int occ_sensor_read(u32 handle, __be64 *data); extern int occ_sensor_group_clear(u32 group_hndl, int token); extern void occ_add_sensor_groups(struct dt_node *sg, u32 *phandles, u32 *ptype, int nr_phandles, int chipid); diff --git a/include/pci.h b/include/pci.h index a808b68da..0239e448a 100644 --- a/include/pci.h +++ b/include/pci.h @@ -294,7 +294,7 @@ struct phb_ops { int64_t (*set_option)(struct phb *phb, enum OpalPhbOption opt, uint64_t setting); int64_t (*get_option)(struct phb *phb, enum OpalPhbOption opt, - uint64_t *setting); + __be64 *setting); int64_t (*set_mve)(struct phb *phb, uint32_t mve_number, uint64_t pe_number); diff --git a/include/platform.h b/include/platform.h index 412f8fc80..6ecdbe474 100644 --- a/include/platform.h +++ b/include/platform.h @@ -258,7 +258,7 @@ struct platform { * Read a sensor value */ int64_t (*sensor_read)(uint32_t sensor_hndl, int token, - uint64_t *sensor_data); + __be64 *sensor_data); /* * Return the heartbeat time */ diff --git a/platforms/ibm-fsp/ibm-fsp.h b/platforms/ibm-fsp/ibm-fsp.h index b3418e692..16af68f8c 100644 --- a/platforms/ibm-fsp/ibm-fsp.h +++ b/platforms/ibm-fsp/ibm-fsp.h @@ -15,7 +15,7 @@ struct errorlog; extern int elog_fsp_commit(struct errorlog *buf); extern int64_t ibm_fsp_sensor_read(uint32_t sensor_hndl, int token, - uint64_t *sensor_data); + __be64 *sensor_data); /* Apollo PCI support */ extern void apollo_pci_setup_phb(struct phb *phb, diff --git a/platforms/mambo/mambo.c b/platforms/mambo/mambo.c index e523cd3eb..aa1bf8305 100644 --- a/platforms/mambo/mambo.c +++ b/platforms/mambo/mambo.c @@ -173,11 +173,13 @@ static void bogus_disk_flash_init(void) } } -static int64_t mambo_rtc_read(uint32_t *ymd, uint64_t *hmsm) +static int64_t mambo_rtc_read(__be32 *ymd, __be64 *hmsm) { int64_t mambo_time; struct tm t; time_t mt; + uint32_t __ymd; + uint64_t __hmsm; if (!ymd || !hmsm) return OPAL_PARAMETER; @@ -185,7 +187,10 @@ static int64_t mambo_rtc_read(uint32_t *ymd, uint64_t *hmsm) mambo_time = callthru0(SIM_GET_TIME_CODE); mt = mambo_time >> 32; gmtime_r(&mt, &t); - tm_to_datetime(&t, ymd, hmsm); + tm_to_datetime(&t, &__ymd, &__hmsm); + + *ymd = cpu_to_be32(__ymd); + *hmsm = cpu_to_be64(__hmsm); return OPAL_SUCCESS; } From patchwork Sun Dec 8 12:22:46 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205619 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5Dj4Z8hz9sP3 for ; Sun, 8 Dec 2019 23:27:17 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="iTNqLncU"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5Dj3TKwzDqPk for ; Sun, 8 Dec 2019 23:27:17 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::542; helo=mail-pg1-x542.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="iTNqLncU"; dkim-atps=neutral Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W58P6w26zDqDV for ; Sun, 8 Dec 2019 23:23:33 +1100 (AEDT) Received: by mail-pg1-x542.google.com with SMTP id b137so5669352pga.6 for ; Sun, 08 Dec 2019 04:23:33 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0Hy/eDJxQwT6dfoi0aVE6cgqTtZqOVr9MHsBZfpvSxg=; b=iTNqLncUJKNzZkWH/3S6wz5+AflPzpjKzfa0nAuRtlRARedX76rP09Sm6b02Dgh/Fh ktEyb1yz2XzOd8Tgmdz9BEWFviJDQbSqmZqPzCL+0PEn2CrPpY6Po+qJDwIBgFzyrAV5 6x/r7fnUWPLk1AN3JYuLf40Wzx0SZUBONaBh7dQDmWa3sodwPFeBEyHc7hnX8HWu7YnS itj+YqPTobQUJPg5JMJvKrumgqc6xBGiU6NGeJ7WwbK0PaQFINuRY/DGs1czL5XFw958 H2v1uBb3IaV5q2BwPmcYx2rcKEwa4BmUdQhHqN7Igr8YhKTbNETLb5B6M6Nir0kq6a1l WAow== 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=0Hy/eDJxQwT6dfoi0aVE6cgqTtZqOVr9MHsBZfpvSxg=; b=pM3Yayhap6eAuIZxyfMJOtU++GE5XRSMXUt8ut3Kt+waCoIERGeANd6tWLgNwZOXsK W3tW2P/TLP1mc9f/bqtL1+fSSdnbmIjgOSem58WcB9Hu9DkJHax+giUAIBr6o4Q6yBPJ fIVx7U3K7bt8zRC+14VBSkJld8RTjdQ1VBS4Kuq0EH4hNmc75759yo/KzZ2pagdQ3l+T 5OEHc0VmfGF93N4hEDVEMghb1BJB13U2I60stB9hMcyCAgime/HNH4O94zNiMq+6sraY w1L5LLOoDJodJsC2BEHkvnp7f/iI3hCR41HWONzY/Dy4Ble84P+/kwNL04JwwEwbqcha upXw== X-Gm-Message-State: APjAAAXxoZyBLkyaCPCWmgdew7iW68+IAUU1kvDXN+DnRYi0gAxsJidH Qrw17oOjKOR46gcFnlHFXH4itj2A X-Google-Smtp-Source: APXvYqyffkoHdLtu2BwGobhYkwaBsqaUY5VeCkrJc1fxVLrigZEMoKwoYedB/h0A9ol/nDe2ZHMO0g== X-Received: by 2002:a63:e30a:: with SMTP id f10mr13329536pgh.331.1575807810992; Sun, 08 Dec 2019 04:23:30 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.23.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:23:30 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:46 +1000 Message-Id: <20191208122312.12837-6-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 05/31] opal-msg: endian fixes for opal-msg.c and opal_queue_msg callers X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Reported-by: Vasant Hegde Reviewed-by: Vasant Hegde Signed-off-by: Nicholas Piggin --- core/flash.c | 5 ++++- core/i2c.c | 4 +++- core/opal-msg.c | 2 +- core/pci-opal.c | 25 ++++++++++++++++--------- hw/dts.c | 4 +++- hw/fsp/fsp-leds.c | 4 +++- hw/fsp/fsp-mem-err.c | 9 +++++---- hw/fsp/fsp-op-panel.c | 4 +++- hw/fsp/fsp-rtc.c | 3 ++- hw/fsp/fsp-sensor.c | 3 ++- hw/fsp/fsp-sysparam.c | 6 ++++-- hw/ipmi/ipmi-sel.c | 6 ++++-- hw/occ.c | 6 ++++-- include/opal-msg.h | 4 ++-- 14 files changed, 56 insertions(+), 29 deletions(-) diff --git a/core/flash.c b/core/flash.c index 7fbfca22b..4e10229d5 100644 --- a/core/flash.c +++ b/core/flash.c @@ -470,7 +470,10 @@ static int64_t opal_flash_op(enum flash_op op, uint64_t id, uint64_t offset, unlock(&flash_lock); - opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, token, rc); + opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, + cpu_to_be64(token), + cpu_to_be64(rc)); + return OPAL_ASYNC_COMPLETION; err: diff --git a/core/i2c.c b/core/i2c.c index 6bae83b42..f33028743 100644 --- a/core/i2c.c +++ b/core/i2c.c @@ -42,7 +42,9 @@ static void opal_i2c_request_complete(int rc, struct i2c_request *req) { uint64_t token = (uint64_t)(unsigned long)req->user_data; - opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, token, rc); + opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, + cpu_to_be64(token), + cpu_to_be64(rc)); free(req); } diff --git a/core/opal-msg.c b/core/opal-msg.c index c393be7ef..dbe75e14a 100644 --- a/core/opal-msg.c +++ b/core/opal-msg.c @@ -143,7 +143,7 @@ static int64_t opal_check_completion(uint64_t *buffer, uint64_t size, lock(&opal_msg_lock); list_for_each_safe(&msg_pending_list, entry, next_entry, link) { - if (entry->msg.msg_type == OPAL_MSG_ASYNC_COMP && + if (be32_to_cpu(entry->msg.msg_type) == OPAL_MSG_ASYNC_COMP && be64_to_cpu(entry->msg.params[0]) == token) { list_del(&entry->link); callback = entry->consumed; diff --git a/core/pci-opal.c b/core/pci-opal.c index 4dc5237cc..292f1006e 100644 --- a/core/pci-opal.c +++ b/core/pci-opal.c @@ -804,8 +804,10 @@ static void link_up_timer(struct timer *t, void *data, rescan_slot_devices(slot); out: opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, - slot->async_token, get_slot_phandle(slot), - slot->power_state, rc <= 0 ? rc : OPAL_BUSY); + cpu_to_be64(slot->async_token), + cpu_to_be64(get_slot_phandle(slot)), + cpu_to_be64(slot->power_state), + rc <= 0 ? cpu_to_be64(rc) : cpu_to_be64(OPAL_BUSY)); phb_unlock(phb); } @@ -834,9 +836,10 @@ static void wait_for_link_up_and_rescan(struct pci_slot *slot) rc = slot->ops.freset(slot); if (rc < 0) { opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, - slot->async_token, - get_slot_phandle(slot), - slot->power_state, rc); + cpu_to_be64(slot->async_token), + cpu_to_be64(get_slot_phandle(slot)), + cpu_to_be64(slot->power_state), + cpu_to_be64(rc)) return; } } else { @@ -863,8 +866,10 @@ static void set_power_timer(struct timer *t __unused, void *data, if (slot->retries-- == 0) { pci_slot_set_state(slot, PCI_SLOT_STATE_NORMAL); opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, - slot->async_token, get_slot_phandle(slot), - slot->power_state, OPAL_BUSY); + cpu_to_be64(slot->async_token), + cpu_to_be64(get_slot_phandle(slot)), + cpu_to_be64(slot->power_state), + cpu_to_be64(OPAL_BUSY)); } else { schedule_timer(&slot->timer, msecs_to_tb(10)); } @@ -875,8 +880,10 @@ static void set_power_timer(struct timer *t __unused, void *data, remove_slot_devices(slot); pci_slot_set_state(slot, PCI_SLOT_STATE_NORMAL); opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, - slot->async_token, get_slot_phandle(slot), - OPAL_PCI_SLOT_POWER_OFF, OPAL_SUCCESS); + cpu_to_be64(slot->async_token), + cpu_to_be64(get_slot_phandle(slot)), + cpu_to_be64(OPAL_PCI_SLOT_POWER_OFF), + cpu_to_be64(OPAL_SUCCESS)); break; } diff --git a/hw/dts.c b/hw/dts.c index c21c5c779..b72516ab2 100644 --- a/hw/dts.c +++ b/hw/dts.c @@ -183,7 +183,9 @@ static void dts_async_read_temp(struct timer *t __unused, void *data, dctl_clear_special_wakeup(cpu); check_sensor_read(cpu->token); - rc = opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, cpu->token, rc); + rc = opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, + cpu_to_be64(cpu->token), + cpu_to_be64(rc)); if (rc) prerror("Failed to queue async message\n"); diff --git a/hw/fsp/fsp-leds.c b/hw/fsp/fsp-leds.c index 7d234a81c..9e89f20d0 100644 --- a/hw/fsp/fsp-leds.c +++ b/hw/fsp/fsp-leds.c @@ -186,7 +186,9 @@ static bool is_enclosure_led(char *loc_code) static inline void opal_led_update_complete(u64 async_token, u64 result) { - opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, async_token, result); + opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, + cpu_to_be64(async_token), + cpu_to_be64(result)); } static inline bool is_sai_loc_code(const char *loc_code) diff --git a/hw/fsp/fsp-mem-err.c b/hw/fsp/fsp-mem-err.c index ffafb96b9..01b1e55ab 100644 --- a/hw/fsp/fsp-mem-err.c +++ b/hw/fsp/fsp-mem-err.c @@ -96,10 +96,11 @@ static void queue_event_for_delivery(void *data __unused, int staus __unused) merr_data = (uint64_t *)&entry->data; /* queue up for delivery */ - rc = opal_queue_msg(OPAL_MSG_MEM_ERR, NULL, - queue_event_for_delivery, - merr_data[0], merr_data[1], - merr_data[2], merr_data[3]); + rc = opal_queue_msg(OPAL_MSG_MEM_ERR, NULL, queue_event_for_delivery, + cpu_to_be64(merr_data[0]), + cpu_to_be64(merr_data[1]), + cpu_to_be64(merr_data[2]), + cpu_to_be64(merr_data[3])); lock(&mem_err_lock); if (rc) { /* diff --git a/hw/fsp/fsp-op-panel.c b/hw/fsp/fsp-op-panel.c index 320da241f..00d275131 100644 --- a/hw/fsp/fsp-op-panel.c +++ b/hw/fsp/fsp-op-panel.c @@ -155,7 +155,9 @@ static void op_panel_write_complete(struct fsp_msg *msg) __op_panel_write_complete(msg); - opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, 1, op_async_token); + opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, + cpu_to_be64(1), + cpu_to_be64(op_async_token)); } static int64_t __opal_write_oppanel(oppanel_line_t *lines, uint64_t num_lines, diff --git a/hw/fsp/fsp-rtc.c b/hw/fsp/fsp-rtc.c index e68836e66..ac12ddf22 100644 --- a/hw/fsp/fsp-rtc.c +++ b/hw/fsp/fsp-rtc.c @@ -139,7 +139,8 @@ static void fsp_tpo_req_complete(struct fsp_msg *read_resp) break; } opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, - attr->tpo_async_token, rc); + cpu_to_be64(attr->tpo_async_token), + cpu_to_be64(rc)); free(attr); fsp_freemsg(read_resp); } diff --git a/hw/fsp/fsp-sensor.c b/hw/fsp/fsp-sensor.c index 74deac7a7..46385b0a6 100644 --- a/hw/fsp/fsp-sensor.c +++ b/hw/fsp/fsp-sensor.c @@ -293,7 +293,8 @@ static void queue_msg_for_delivery(int rc, struct opal_sensor_data *attr) __func__, rc, *(attr->sensor_data)); check_sensor_read(attr->async_token); opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, - attr->async_token, rc); + cpu_to_be64(attr->async_token), + cpu_to_be64(rc)); spcn_mod_data[attr->mod_index].entry_count = 0; free(attr); prev_msg_consumed = true; diff --git a/hw/fsp/fsp-sysparam.c b/hw/fsp/fsp-sysparam.c index 0e1e8181f..c7ed36e43 100644 --- a/hw/fsp/fsp-sysparam.c +++ b/hw/fsp/fsp-sysparam.c @@ -194,7 +194,8 @@ static void fsp_opal_getparam_complete(uint32_t param_id __unused, int err_len, rc = OPAL_INTERNAL_ERROR; opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, - comp_data->async_token, rc); + cpu_to_be64(comp_data->async_token), + cpu_to_be64(rc)); free(comp_data); } @@ -242,7 +243,8 @@ static void fsp_opal_setparam_complete(struct fsp_msg *msg) out: opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, - comp_data->async_token, rc); + cpu_to_be64(comp_data->async_token), + cpu_to_be64(rc)); free(comp_data); fsp_freemsg(msg); } diff --git a/hw/ipmi/ipmi-sel.c b/hw/ipmi/ipmi-sel.c index 794aa3801..60df9d927 100644 --- a/hw/ipmi/ipmi-sel.c +++ b/hw/ipmi/ipmi-sel.c @@ -496,7 +496,8 @@ static void sel_power(uint8_t power, void *context __unused) prlog(PR_NOTICE, "Host not up, shutting down now\n"); platform.cec_power_down(IPMI_CHASSIS_PWR_DOWN); } else { - opal_queue_msg(OPAL_MSG_SHUTDOWN, NULL, NULL, SOFT_OFF); + opal_queue_msg(OPAL_MSG_SHUTDOWN, NULL, NULL, + cpu_to_be64(SOFT_OFF)); } break; @@ -506,7 +507,8 @@ static void sel_power(uint8_t power, void *context __unused) prlog(PR_NOTICE, "Host not up, rebooting now\n"); platform.cec_reboot(); } else { - opal_queue_msg(OPAL_MSG_SHUTDOWN, NULL, NULL, SOFT_REBOOT); + opal_queue_msg(OPAL_MSG_SHUTDOWN, NULL, NULL, + cpu_to_be64(SOFT_REBOOT)); } break; diff --git a/hw/occ.c b/hw/occ.c index 2c989a616..46210ba20 100644 --- a/hw/occ.c +++ b/hw/occ.c @@ -1126,7 +1126,9 @@ static inline void queue_occ_rsp_msg(int token, int rc) { int ret; - ret = opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, token, rc); + ret = opal_queue_msg(OPAL_MSG_ASYNC_COMP, NULL, NULL, + cpu_to_be64(token), + cpu_to_be64(rc)); if (ret) prerror("OCC: Failed to queue OCC response status message\n"); } @@ -1877,7 +1879,7 @@ int find_master_and_slave_occ(uint64_t **master, uint64_t **slave, int occ_msg_queue_occ_reset(void) { - struct opal_occ_msg occ_msg = { OCC_RESET, 0, 0 }; + struct opal_occ_msg occ_msg = { CPU_TO_BE64(OCC_RESET), 0, 0 }; struct proc_chip *chip; int rc; diff --git a/include/opal-msg.h b/include/opal-msg.h index 036183343..df605b3b6 100644 --- a/include/opal-msg.h +++ b/include/opal-msg.h @@ -27,8 +27,8 @@ int _opal_queue_msg(enum opal_msg_type msg_type, void *data, #define opal_queue_msg(msg_type, data, cb, ...) \ _opal_queue_msg(msg_type, data, cb, \ - sizeof((u64[]) {__VA_ARGS__}), \ - (u64[]) {__VA_ARGS__}); + sizeof((__be64[]) {__VA_ARGS__}), \ + (__be64[]) {__VA_ARGS__}); void opal_init_msg(void); From patchwork Sun Dec 8 12:22:47 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205620 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5FD0Kkgz9sP3 for ; Sun, 8 Dec 2019 23:27:44 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="C4M8Vo0U"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5FC6HQfzDqGt for ; Sun, 8 Dec 2019 23:27:43 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::442; helo=mail-pf1-x442.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="C4M8Vo0U"; dkim-atps=neutral Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W58S1PVdzDqDV for ; Sun, 8 Dec 2019 23:23:35 +1100 (AEDT) Received: by mail-pf1-x442.google.com with SMTP id b19so5761351pfo.2 for ; Sun, 08 Dec 2019 04:23:35 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bMIp+bsR8pdzP7QKrC4NJb06V3TaLbWuJLoU9a9UeGQ=; b=C4M8Vo0U3/GuCzX/NkZJzsxio5md7ybuO6T6wd1+FWpMXLUUe1SPZY//TZDHUBussh a6AwrPHlAXzMU3NTSLTgVcaxjHXGwl3GHRmo4W60xBLbWFHJ+OqAcMv5IN9Jx5G40vqA h4aA9lFk8tuYfS7THW1arB+pMUDsfljapu9qRqJ10S2po5EAp5VOrFjWnUMcTGTXKc5q Vm8iWqbzQ0KXOpVdH3FNjq14mZxfvECHEJ2ZZD5z2u63aX8UsEKSQtmCwi/525k+GvOs uDo5OLB189Sy1yeSkuh6428iUM4Xz2OZZRSQ/Lgt/yEnPcDjgir/Oc/1ChNmUFbz+XTj P6Xg== 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=bMIp+bsR8pdzP7QKrC4NJb06V3TaLbWuJLoU9a9UeGQ=; b=gt/U+xznhOAEjijQzkzQ/oFr3lTHEKbUpQUwKbN3mnH6Zo0JQkbUhkZgjsF8i7uCH2 FDCE048OAjwqCULdVAr0AGZrXryGmg4FadtXEp2iR9/CvU05/oqQyh+HbDKordCgfOuk xDSWLgLzShj9/9olvg2GdMuti0IacxJxKmiQGS/3NT9ZLAN/djLkWh79i8+QwBUqKL9/ gaIZ+M3zrH52DdVfb83ljza3lKXZ2DrP/Rmz0oIYcqUSDAv643QloktrH1rNRNjk/SXr u5NeaMMi6yLOysbfIFD2BELCAyqyJa1oSK49f5ZPmHWrZc7f9uYRigosTme2pEeLp0OS XbTA== X-Gm-Message-State: APjAAAWddLILRfniJa15Bjm80Xe4JLoUxhUjWtFoYPdGbouvf7y5dK82 poe2hA9MOa6zzgw5P3fHigJxZQqb X-Google-Smtp-Source: APXvYqwSVY9bYdn2Yz+PDDYVfUbbOfGMjmjtWKiO0Rhc6ZicOjEhS9J2SmudE4m41YelVwHT92rbOw== X-Received: by 2002:a05:6a00:3:: with SMTP id h3mr23623359pfk.78.1575807813632; Sun, 08 Dec 2019 04:23:33 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.23.31 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:23:33 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:47 +1000 Message-Id: <20191208122312.12837-7-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 06/31] elf: endian conversions X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Signed-off-by: Nicholas Piggin --- core/flash.c | 36 +++++--- core/init.c | 92 ++++++++++--------- include/elf.h | 235 +++++++++++++++++++++++++++++++++--------------- include/stack.h | 4 + include/types.h | 4 + 5 files changed, 248 insertions(+), 123 deletions(-) diff --git a/core/flash.c b/core/flash.c index 4e10229d5..de748641f 100644 --- a/core/flash.c +++ b/core/flash.c @@ -523,24 +523,38 @@ const char *flash_map_resource_name(enum resource_id id) static size_t sizeof_elf_from_hdr(void *buf) { - struct elf_hdr *elf = (struct elf_hdr*) buf; + struct elf_hdr *elf = (struct elf_hdr *)buf; size_t sz = 0; BUILD_ASSERT(SECURE_BOOT_HEADERS_SIZE > sizeof(struct elf_hdr)); - BUILD_ASSERT(SECURE_BOOT_HEADERS_SIZE > sizeof(struct elf64_hdr)); - BUILD_ASSERT(SECURE_BOOT_HEADERS_SIZE > sizeof(struct elf32_hdr)); + BUILD_ASSERT(SECURE_BOOT_HEADERS_SIZE > sizeof(struct elf64be_hdr)); + BUILD_ASSERT(SECURE_BOOT_HEADERS_SIZE > sizeof(struct elf32be_hdr)); if (elf->ei_ident == ELF_IDENT) { if (elf->ei_class == ELF_CLASS_64) { - struct elf64_hdr *elf64 = (struct elf64_hdr*) buf; - sz = le64_to_cpu(elf64->e_shoff) + - ((uint32_t)le16_to_cpu(elf64->e_shentsize) * - (uint32_t)le16_to_cpu(elf64->e_shnum)); + if (elf->ei_data == ELF_DATA_LSB) { + struct elf64le_hdr *kh = (struct elf64le_hdr *)buf; + sz = le64_to_cpu(kh->e_shoff) + + ((uint32_t)le16_to_cpu(kh->e_shentsize) * + (uint32_t)le16_to_cpu(kh->e_shnum)); + } else { + struct elf64be_hdr *kh = (struct elf64be_hdr *)buf; + sz = be64_to_cpu(kh->e_shoff) + + ((uint32_t)be16_to_cpu(kh->e_shentsize) * + (uint32_t)be16_to_cpu(kh->e_shnum)); + } } else if (elf->ei_class == ELF_CLASS_32) { - struct elf32_hdr *elf32 = (struct elf32_hdr*) buf; - sz = le32_to_cpu(elf32->e_shoff) + - (le16_to_cpu(elf32->e_shentsize) * - le16_to_cpu(elf32->e_shnum)); + if (elf->ei_data == ELF_DATA_LSB) { + struct elf32le_hdr *kh = (struct elf32le_hdr *)buf; + sz = le32_to_cpu(kh->e_shoff) + + (le16_to_cpu(kh->e_shentsize) * + le16_to_cpu(kh->e_shnum)); + } else { + struct elf32be_hdr *kh = (struct elf32be_hdr *)buf; + sz = be32_to_cpu(kh->e_shoff) + + (be16_to_cpu(kh->e_shentsize) * + be16_to_cpu(kh->e_shnum)); + } } } diff --git a/core/init.c b/core/init.c index a7083456e..d90695c16 100644 --- a/core/init.c +++ b/core/init.c @@ -89,9 +89,9 @@ static void checksum_romem(void); static bool try_load_elf64_le(struct elf_hdr *header) { - struct elf64_hdr *kh = (struct elf64_hdr *)header; + struct elf64le_hdr *kh = (struct elf64le_hdr *)header; uint64_t load_base = (uint64_t)kh; - struct elf64_phdr *ph; + struct elf64le_phdr *ph; unsigned int i; printf("INIT: 64-bit LE kernel discovered\n"); @@ -103,7 +103,7 @@ static bool try_load_elf64_le(struct elf_hdr *header) * to work for the Linux Kernel because it's a fairly dumb ELF * but it will not work for any ELF binary. */ - ph = (struct elf64_phdr *)(load_base + le64_to_cpu(kh->e_phoff)); + ph = (struct elf64le_phdr *)(load_base + le64_to_cpu(kh->e_phoff)); for (i = 0; i < le16_to_cpu(kh->e_phnum); i++, ph++) { if (le32_to_cpu(ph->p_type) != ELF_PTYPE_LOAD) continue; @@ -137,23 +137,24 @@ static bool try_load_elf64_le(struct elf_hdr *header) static bool try_load_elf64(struct elf_hdr *header) { - struct elf64_hdr *kh = (struct elf64_hdr *)header; + struct elf64be_hdr *kh = (struct elf64be_hdr *)header; + struct elf64le_hdr *khle = (struct elf64le_hdr *)header; uint64_t load_base = (uint64_t)kh; - struct elf64_phdr *ph; - struct elf64_shdr *sh; + struct elf64be_phdr *ph; + struct elf64be_shdr *sh; unsigned int i; /* Check it's a ppc64 LE ELF */ - if (kh->ei_ident == ELF_IDENT && - kh->ei_data == ELF_DATA_LSB && - kh->e_machine == le16_to_cpu(ELF_MACH_PPC64)) { + if (khle->ei_ident == ELF_IDENT && + khle->ei_data == ELF_DATA_LSB && + le16_to_cpu(khle->e_machine) == ELF_MACH_PPC64) { return try_load_elf64_le(header); } /* Check it's a ppc64 ELF */ if (kh->ei_ident != ELF_IDENT || kh->ei_data != ELF_DATA_MSB || - kh->e_machine != ELF_MACH_PPC64) { + be16_to_cpu(kh->e_machine) != ELF_MACH_PPC64) { prerror("INIT: Kernel doesn't look like an ppc64 ELF\n"); return false; } @@ -165,16 +166,18 @@ static bool try_load_elf64(struct elf_hdr *header) * to work for the Linux Kernel because it's a fairly dumb ELF * but it will not work for any ELF binary. */ - ph = (struct elf64_phdr *)(load_base + kh->e_phoff); - for (i = 0; i < kh->e_phnum; i++, ph++) { - if (ph->p_type != ELF_PTYPE_LOAD) + ph = (struct elf64be_phdr *)(load_base + be64_to_cpu(kh->e_phoff)); + for (i = 0; i < be16_to_cpu(kh->e_phnum); i++, ph++) { + if (be32_to_cpu(ph->p_type) != ELF_PTYPE_LOAD) continue; - if (ph->p_vaddr > kh->e_entry || - (ph->p_vaddr + ph->p_memsz) < kh->e_entry) + if (be64_to_cpu(ph->p_vaddr) > be64_to_cpu(kh->e_entry) || + (be64_to_cpu(ph->p_vaddr) + be64_to_cpu(ph->p_memsz)) < + be64_to_cpu(kh->e_entry)) continue; /* Get our entry */ - kernel_entry = kh->e_entry - ph->p_vaddr + ph->p_offset; + kernel_entry = be64_to_cpu(kh->e_entry) - + be64_to_cpu(ph->p_vaddr) + be64_to_cpu(ph->p_offset); break; } @@ -189,23 +192,27 @@ static bool try_load_elf64(struct elf_hdr *header) * into an executable section or not to figure this out. Default * to assuming it obeys the ABI. */ - sh = (struct elf64_shdr *)(load_base + kh->e_shoff); - for (i = 0; i < kh->e_shnum; i++, sh++) { - if (sh->sh_addr <= kh->e_entry && - (sh->sh_addr + sh->sh_size) > kh->e_entry) + sh = (struct elf64be_shdr *)(load_base + be64_to_cpu(kh->e_shoff)); + for (i = 0; i < be16_to_cpu(kh->e_shnum); i++, sh++) { + if (be64_to_cpu(sh->sh_addr) <= be64_to_cpu(kh->e_entry) && + (be64_to_cpu(sh->sh_addr) + be64_to_cpu(sh->sh_size)) > + be64_to_cpu(kh->e_entry)) break; } - if (i == kh->e_shnum || !(sh->sh_flags & ELF_SFLAGS_X)) { + if (i == be16_to_cpu(kh->e_shnum) || + !(be64_to_cpu(sh->sh_flags) & ELF_SFLAGS_X)) { kernel_entry = *(uint64_t *)(kernel_entry + load_base); - kernel_entry = kernel_entry - ph->p_vaddr + ph->p_offset; + kernel_entry = kernel_entry - + be64_to_cpu(ph->p_vaddr) + be64_to_cpu(ph->p_offset); } kernel_entry += load_base; kernel_32bit = false; - kernel_size = kh->e_shoff + - ((uint32_t)kh->e_shentsize * (uint32_t)kh->e_shnum); + kernel_size = be64_to_cpu(kh->e_shoff) + + ((uint32_t)be16_to_cpu(kh->e_shentsize) * + (uint32_t)be16_to_cpu(kh->e_shnum)); printf("INIT: 64-bit kernel entry at 0x%llx, size 0x%lx\n", kernel_entry, kernel_size); @@ -215,9 +222,9 @@ static bool try_load_elf64(struct elf_hdr *header) static bool try_load_elf32_le(struct elf_hdr *header) { - struct elf32_hdr *kh = (struct elf32_hdr *)header; + struct elf32le_hdr *kh = (struct elf32le_hdr *)header; uint64_t load_base = (uint64_t)kh; - struct elf32_phdr *ph; + struct elf32le_phdr *ph; unsigned int i; printf("INIT: 32-bit LE kernel discovered\n"); @@ -229,7 +236,7 @@ static bool try_load_elf32_le(struct elf_hdr *header) * to work for the Linux Kernel because it's a fairly dumb ELF * but it will not work for any ELF binary. */ - ph = (struct elf32_phdr *)(load_base + le32_to_cpu(kh->e_phoff)); + ph = (struct elf32le_phdr *)(load_base + le32_to_cpu(kh->e_phoff)); for (i = 0; i < le16_to_cpu(kh->e_phnum); i++, ph++) { if (le32_to_cpu(ph->p_type) != ELF_PTYPE_LOAD) continue; @@ -259,22 +266,23 @@ static bool try_load_elf32_le(struct elf_hdr *header) static bool try_load_elf32(struct elf_hdr *header) { - struct elf32_hdr *kh = (struct elf32_hdr *)header; + struct elf32be_hdr *kh = (struct elf32be_hdr *)header; + struct elf32le_hdr *khle = (struct elf32le_hdr *)header; uint64_t load_base = (uint64_t)kh; - struct elf32_phdr *ph; + struct elf32be_phdr *ph; unsigned int i; /* Check it's a ppc32 LE ELF */ - if (header->ei_ident == ELF_IDENT && - header->ei_data == ELF_DATA_LSB && - header->e_machine == le16_to_cpu(ELF_MACH_PPC32)) { + if (khle->ei_ident == ELF_IDENT && + khle->ei_data == ELF_DATA_LSB && + le16_to_cpu(khle->e_machine) == ELF_MACH_PPC32) { return try_load_elf32_le(header); } /* Check it's a ppc32 ELF */ - if (header->ei_ident != ELF_IDENT || - header->ei_data != ELF_DATA_MSB || - header->e_machine != ELF_MACH_PPC32) { + if (kh->ei_ident != ELF_IDENT || + kh->ei_data != ELF_DATA_MSB || + be16_to_cpu(kh->e_machine) != ELF_MACH_PPC32) { prerror("INIT: Kernel doesn't look like an ppc32 ELF\n"); return false; } @@ -286,16 +294,18 @@ static bool try_load_elf32(struct elf_hdr *header) * to work for the Linux Kernel because it's a fairly dumb ELF * but it will not work for any ELF binary. */ - ph = (struct elf32_phdr *)(load_base + kh->e_phoff); - for (i = 0; i < kh->e_phnum; i++, ph++) { - if (ph->p_type != ELF_PTYPE_LOAD) + ph = (struct elf32be_phdr *)(load_base + be32_to_cpu(kh->e_phoff)); + for (i = 0; i < be16_to_cpu(kh->e_phnum); i++, ph++) { + if (be32_to_cpu(ph->p_type) != ELF_PTYPE_LOAD) continue; - if (ph->p_vaddr > kh->e_entry || - (ph->p_vaddr + ph->p_memsz) < kh->e_entry) + if (be32_to_cpu(ph->p_vaddr) > be32_to_cpu(kh->e_entry) || + (be32_to_cpu(ph->p_vaddr) + be32_to_cpu(ph->p_memsz)) < + be32_to_cpu(kh->e_entry)) continue; /* Get our entry */ - kernel_entry = kh->e_entry - ph->p_vaddr + ph->p_offset; + kernel_entry = be32_to_cpu(kh->e_entry) - + be32_to_cpu(ph->p_vaddr) + be32_to_cpu(ph->p_offset); break; } diff --git a/include/elf.h b/include/elf.h index 93524bb99..f3e071de1 100644 --- a/include/elf.h +++ b/include/elf.h @@ -5,11 +5,16 @@ #define __ELF_H #include +#include /* Generic ELF header */ struct elf_hdr { uint32_t ei_ident; +#if HAVE_BIG_ENDIAN #define ELF_IDENT 0x7F454C46 +#else +#define ELF_IDENT 0x464C457F +#endif uint8_t ei_class; #define ELF_CLASS_32 1 #define ELF_CLASS_64 2 @@ -18,68 +23,190 @@ struct elf_hdr { #define ELF_DATA_MSB 2 uint8_t ei_version; uint8_t ei_pad[9]; - uint16_t e_type; - uint16_t e_machine; +}; + #define ELF_MACH_PPC32 0x14 #define ELF_MACH_PPC64 0x15 - uint32_t e_version; + +/* 64-bit ELF header */ +struct elf64be_hdr { + uint32_t ei_ident; + uint8_t ei_class; + uint8_t ei_data; + uint8_t ei_version; + uint8_t ei_pad[9]; + __be16 e_type; + __be16 e_machine; + __be32 e_version; + __be64 e_entry; + __be64 e_phoff; + __be64 e_shoff; + __be32 e_flags; + __be16 e_ehsize; + __be16 e_phentsize; + __be16 e_phnum; + __be16 e_shentsize; + __be16 e_shnum; + __be16 e_shstrndx; +}; + +/* 64-bit ELF program header */ +struct elf64be_phdr { + __be32 p_type; +#define ELF_PTYPE_LOAD 1 + __be32 p_flags; +#define ELF_PFLAGS_R 0x4 +#define ELF_PFLAGS_W 0x2 +#define ELF_PFLAGS_X 0x1 + __be64 p_offset; + __be64 p_vaddr; + __be64 p_paddr; + __be64 p_filesz; + __be64 p_memsz; + __be64 p_align; +}; + +/* 64-bit ELF section header */ +struct elf64be_shdr { + __be32 sh_name; + __be32 sh_type; + __be64 sh_flags; +#define ELF_SFLAGS_X 0x4 +#define ELF_SFLAGS_A 0x2 +#define ELF_SFLAGS_W 0x1 + __be64 sh_addr; + __be64 sh_offset; + __be64 sh_size; + __be32 sh_link; + __be32 sh_info; + __be64 sh_addralign; + __be64 sh_entsize; +}; + +/* 32-bit ELF header */ +struct elf32be_hdr { + uint32_t ei_ident; + uint8_t ei_class; + uint8_t ei_data; + uint8_t ei_version; + uint8_t ei_pad[9]; + __be16 e_type; + __be16 e_machine; + __be32 e_version; + __be32 e_entry; + __be32 e_phoff; + __be32 e_shoff; + __be32 e_flags; + __be16 e_ehsize; + __be16 e_phentsize; + __be16 e_phnum; + __be16 e_shentsize; + __be16 e_shnum; + __be16 e_shstrndx; +}; + +/* 32-bit ELF program header*/ +struct elf32be_phdr { + __be32 p_type; + __be32 p_offset; + __be32 p_vaddr; + __be32 p_paddr; + __be32 p_filesz; + __be32 p_memsz; + __be32 p_flags; + __be32 p_align; }; /* 64-bit ELF header */ -struct elf64_hdr { +struct elf64le_hdr { uint32_t ei_ident; uint8_t ei_class; uint8_t ei_data; uint8_t ei_version; uint8_t ei_pad[9]; - uint16_t e_type; - uint16_t e_machine; - uint32_t e_version; - uint64_t e_entry; - uint64_t e_phoff; - uint64_t e_shoff; - uint32_t e_flags; - uint16_t e_ehsize; - uint16_t e_phentsize; - uint16_t e_phnum; - uint16_t e_shentsize; - uint16_t e_shnum; - uint16_t e_shstrndx; + __le16 e_type; + __le16 e_machine; + __le32 e_version; + __le64 e_entry; + __le64 e_phoff; + __le64 e_shoff; + __le32 e_flags; + __le16 e_ehsize; + __le16 e_phentsize; + __le16 e_phnum; + __le16 e_shentsize; + __le16 e_shnum; + __le16 e_shstrndx; }; /* 64-bit ELF program header */ -struct elf64_phdr { - uint32_t p_type; +struct elf64le_phdr { + __le32 p_type; #define ELF_PTYPE_LOAD 1 - uint32_t p_flags; + __le32 p_flags; #define ELF_PFLAGS_R 0x4 #define ELF_PFLAGS_W 0x2 #define ELF_PFLAGS_X 0x1 - uint64_t p_offset; - uint64_t p_vaddr; - uint64_t p_paddr; - uint64_t p_filesz; - uint64_t p_memsz; - uint64_t p_align; + __le64 p_offset; + __le64 p_vaddr; + __le64 p_paddr; + __le64 p_filesz; + __le64 p_memsz; + __le64 p_align; }; /* 64-bit ELF section header */ -struct elf64_shdr { - uint32_t sh_name; - uint32_t sh_type; - uint64_t sh_flags; +struct elf64le_shdr { + __le32 sh_name; + __le32 sh_type; + __le64 sh_flags; #define ELF_SFLAGS_X 0x4 #define ELF_SFLAGS_A 0x2 #define ELF_SFLAGS_W 0x1 - uint64_t sh_addr; - uint64_t sh_offset; - uint64_t sh_size; - uint32_t sh_link; - uint32_t sh_info; - uint64_t sh_addralign; - int64_t sh_entsize; + __le64 sh_addr; + __le64 sh_offset; + __le64 sh_size; + __le32 sh_link; + __le32 sh_info; + __le64 sh_addralign; + __le64 sh_entsize; +}; + +/* 32-bit ELF header */ +struct elf32le_hdr { + uint32_t ei_ident; + uint8_t ei_class; + uint8_t ei_data; + uint8_t ei_version; + uint8_t ei_pad[9]; + __le16 e_type; + __le16 e_machine; + __le32 e_version; + __le32 e_entry; + __le32 e_phoff; + __le32 e_shoff; + __le32 e_flags; + __le16 e_ehsize; + __le16 e_phentsize; + __le16 e_phnum; + __le16 e_shentsize; + __le16 e_shnum; + __le16 e_shstrndx; +}; + +/* 32-bit ELF program header*/ +struct elf32le_phdr { + __le32 p_type; + __le32 p_offset; + __le32 p_vaddr; + __le32 p_paddr; + __le32 p_filesz; + __le32 p_memsz; + __le32 p_flags; + __le32 p_align; }; + /* Some relocation related stuff used in relocate.c */ struct elf64_dyn { int64_t d_tag; @@ -101,39 +228,5 @@ struct elf64_rela { /* relocs we support */ #define R_PPC64_RELATIVE 22 -/* 32-bit ELF header */ -struct elf32_hdr { - uint32_t ei_ident; - uint8_t ei_class; - uint8_t ei_data; - uint8_t ei_version; - uint8_t ei_pad[9]; - uint16_t e_type; - uint16_t e_machine; - uint32_t e_version; - uint32_t e_entry; - uint32_t e_phoff; - uint32_t e_shoff; - uint32_t e_flags; - uint16_t e_ehsize; - uint16_t e_phentsize; - uint16_t e_phnum; - uint16_t e_shentsize; - uint16_t e_shnum; - uint16_t e_shstrndx; -}; - -/* 32-bit ELF program header*/ -struct elf32_phdr { - uint32_t p_type; - uint32_t p_offset; - uint32_t p_vaddr; - uint32_t p_paddr; - uint32_t p_filesz; - uint32_t p_memsz; - uint32_t p_flags; - uint32_t p_align; -}; - #endif /* __ELF_H */ diff --git a/include/stack.h b/include/stack.h index 09d22adb6..b0d6df17d 100644 --- a/include/stack.h +++ b/include/stack.h @@ -11,7 +11,11 @@ #define STACK_ENTRY_RESET 0x0100 /* System reset */ #define STACK_ENTRY_SOFTPATCH 0x1500 /* Soft patch (denorm emulation) */ +#if HAVE_BIG_ENDIAN #define STACK_TOC_OFFSET 40 +#else +#define STACK_TOC_OFFSET 24 +#endif /* Safety/ABI gap at top of stack */ #define STACK_TOP_GAP 0x100 diff --git a/include/types.h b/include/types.h index a7a45f5cb..e7660f6b7 100644 --- a/include/types.h +++ b/include/types.h @@ -11,5 +11,9 @@ typedef beint16_t __be16; typedef beint32_t __be32; typedef beint64_t __be64; +typedef leint16_t __le16; +typedef leint32_t __le32; +typedef leint64_t __le64; + #endif /* __TYPES_H */ From patchwork Sun Dec 8 12:22:48 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205621 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5Fh4QkBz9sP3 for ; Sun, 8 Dec 2019 23:28:08 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YAVUUiI5"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5Fh38dDzDqJH for ; Sun, 8 Dec 2019 23:28:08 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::642; helo=mail-pl1-x642.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="YAVUUiI5"; dkim-atps=neutral Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W58V3YTQzDqDV for ; Sun, 8 Dec 2019 23:23:38 +1100 (AEDT) Received: by mail-pl1-x642.google.com with SMTP id x13so4608693plr.9 for ; Sun, 08 Dec 2019 04:23:38 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4hjunjg3NXZ2G2IfHTctnTs2v7nQufULBIOgtvrJVaM=; b=YAVUUiI5MojmK/XvEOy1HFNg9b8jWkftjl+st/ugYsE7jv5TLKLmx2JLrSdgnTT96O Kzov0tG4gmdETG0aDfOi2JBieYXbX8O+z4eWCMk9pAash08HGhxgffezpEpakCriYTFM ulTknqh6fVhMR/3yrk6UnkYYE6fY8fvDRxBAFI2d+SpNMkcI8ID+uPXptJ+/58oB9hB/ DMvbkj3GM62DimCZwYZmI6OCoewYtb1GoBOX55hTWi3vC5FRecy+N+4cpyn5stXbfO8L 8fthizmMTswQzRm/qSJsUu+kJLhCfdArEa5k6JXmXyVL+oBQ4zxiHZ8OL+D6n/X6ofsy pYoA== 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=4hjunjg3NXZ2G2IfHTctnTs2v7nQufULBIOgtvrJVaM=; b=l8cZXVvfFmyqpmrEyhuIZNT8osy44Vnuw+42Dx4zI+IpxfPHUuG8g5M+BXzINALCIB KpPVjCul1wTIhZ7ym9W06TBARvvpEDwSvMFPdn9rbYJ16EK3flKTtmW2cqFAd+PT5aW1 X8sjtXg4YgQvcTDsWK3RdXFswyHHwd6lrO1EWPrUnNhzS4Y8GhiDNTuOVHX9k9Tgocss AfEQaHLAWeW1PWZ+1b3p0zdx0y9djYiPMlLdeCBfeufV7has8o+Oh2WzqY2N4EKlZtXU 7Fto4CjthjVZM815HRxIM2E1/xmBBoGY3NBxOL7i4rCt0G5UkKd4uDHQCxl8gL3Kx8p5 80zA== X-Gm-Message-State: APjAAAWSkBQth0LCh/i+JbtC0lq9sTbc7Nh01XJ3TOnwKp6SDpTzLEGJ 6hED0qhCvuiLTHG79QCLnJCvT5bL X-Google-Smtp-Source: APXvYqzThGtJRnEFmt+qlOq3k5hCcrw26ZLDzrRihS7/NYjrPIbvq/N0Q0Oj0FyYpNAkBidq4GCGBQ== X-Received: by 2002:a17:90a:f0d6:: with SMTP id fa22mr26428169pjb.136.1575807815924; Sun, 08 Dec 2019 04:23:35 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.23.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:23:35 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:48 +1000 Message-Id: <20191208122312.12837-8-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 07/31] spira: fix endian conversions in spira data structures X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Labels can't be used for static initialisers that require endian conversion. Use constants for these. Signed-off-by: Nicholas Piggin Reviewed-by: Vasant Hegde --- hdata/spira.c | 59 +++++++++++++++++++++++++--------------- hdata/test/hdata_to_dt.c | 3 ++ 2 files changed, 40 insertions(+), 22 deletions(-) diff --git a/hdata/spira.c b/hdata/spira.c index 6e4da3c02..2d0e875e3 100644 --- a/hdata/spira.c +++ b/hdata/spira.c @@ -33,41 +33,61 @@ __section(".procin.data") struct proc_init_data proc_init_data = { .regs_ptr = HDIF_IDATA_PTR(offsetof(struct proc_init_data, regs), 0x10), .regs = { .nia = CPU_TO_BE64(0x180), - .msr = CPU_TO_BE64(0x9000000000000000ULL), /* SF | HV */ + .msr = CPU_TO_BE64(MSR_SF | MSR_HV), }, }; +extern struct cpu_ctl_init_data cpu_ctl_init_data; extern struct sp_addr_table cpu_ctl_spat_area; -__section(".cpuctrl.data") struct sp_addr_table cpu_ctl_spat_area; -__section(".cpuctrl.data") struct sp_attn_area cpu_ctl_sp_attn_area1; -__section(".cpuctrl.data") struct sp_attn_area cpu_ctl_sp_attn_area2; +extern struct sp_attn_area cpu_ctl_sp_attn_area1; +extern struct sp_attn_area cpu_ctl_sp_attn_area2; extern struct hsr_data_area cpu_ctl_hsr_area; + +/* + * cpuctrl.data begins at CPU_CTL_OFF - cpu_ctl_init_data is located there. + * + sizeof(struct cpu_ctl_init_data) - cpu_ctl_spat_area + * + sizeof(struct sp_addr_table) - cpu_ctl_sp_attn_area1 + * + sizeof(struct sp_attn_area) - cpu_ctl_sp_attn_area2 + * + sizeof(struct sp_attn_area) - cpu_ctl_hsr_area + * + * Can't use CPU_TO_BE64 directly on the labels as a constant initialiser. + * + * CPU_CTL_INIT_DATA_OFF is offset from 0, the others are addressed from the + * relocated address (+SKIBOOT_BASE) + */ +#define CPU_CTL_INIT_DATA_OFF (CPU_CTL_OFF) +#define CPU_CTL_SPAT_AREA_OFF (CPU_CTL_INIT_DATA_OFF + sizeof(struct cpu_ctl_init_data) + SKIBOOT_BASE) +#define CPU_CTL_SP_ATTN_AREA1_OFF (CPU_CTL_SPAT_AREA_OFF + sizeof(struct sp_addr_table)) +#define CPU_CTL_SP_ATTN_AREA2_OFF (CPU_CTL_SP_ATTN_AREA1_OFF + sizeof(struct sp_attn_area)) +#define CPU_CTL_HSR_AREA_OFF (CPU_CTL_SP_ATTN_AREA2_OFF + sizeof(struct sp_attn_area)) + __section(".cpuctrl.data") struct hsr_data_area cpu_ctl_hsr_area; +__section(".cpuctrl.data") struct sp_attn_area cpu_ctl_sp_attn_area2; +__section(".cpuctrl.data") struct sp_attn_area cpu_ctl_sp_attn_area1; +__section(".cpuctrl.data") struct sp_addr_table cpu_ctl_spat_area; -extern struct cpu_ctl_init_data cpu_ctl_init_data; __section(".cpuctrl.data") struct cpu_ctl_init_data cpu_ctl_init_data = { .hdr = HDIF_SIMPLE_HDR(CPU_CTL_HDIF_SIG, 2, struct cpu_ctl_init_data), - .cpu_ctl = HDIF_IDATA_PTR(offsetof(struct cpu_ctl_init_data, cpu_ctl_lt), sizeof(struct cpu_ctl_legacy_table)), -#if !defined(TEST) + .cpu_ctl = HDIF_IDATA_PTR(offsetof(struct cpu_ctl_init_data, cpu_ctl_lt), + sizeof(struct cpu_ctl_legacy_table)), .cpu_ctl_lt = { .spat = { - .addr = CPU_TO_BE64((unsigned long)&(cpu_ctl_spat_area) + SKIBOOT_BASE), + .addr = CPU_TO_BE64(CPU_CTL_SPAT_AREA_OFF), .size = CPU_TO_BE64(sizeof(struct sp_addr_table)), }, .sp_attn_area1 = { - .addr = CPU_TO_BE64((unsigned long)&(cpu_ctl_sp_attn_area1) + SKIBOOT_BASE), + .addr = CPU_TO_BE64(CPU_CTL_SP_ATTN_AREA1_OFF), .size = CPU_TO_BE64(sizeof(struct sp_attn_area)), }, .sp_attn_area2 = { - .addr = CPU_TO_BE64((unsigned long)&(cpu_ctl_sp_attn_area2) + SKIBOOT_BASE), + .addr = CPU_TO_BE64(CPU_CTL_SP_ATTN_AREA2_OFF), .size = CPU_TO_BE64(sizeof(struct sp_attn_area)), }, .hsr_area = { - .addr = CPU_TO_BE64((unsigned long)&(cpu_ctl_hsr_area) + SKIBOOT_BASE), + .addr = CPU_TO_BE64(CPU_CTL_HSR_AREA_OFF), .size = CPU_TO_BE64(sizeof(struct hsr_data_area)), }, }, -#endif }; /* Populate MDST table @@ -131,15 +151,12 @@ __section(".spira.data") struct spira spira = { .alloc_len = CPU_TO_BE32(sizeof(init_mdst_table)), }, -#if !defined(TEST) .cpu_ctrl = { - .addr = CPU_TO_BE64((unsigned long)&cpu_ctl_init_data), + .addr = CPU_TO_BE64(CPU_CTL_INIT_DATA_OFF), .alloc_cnt = CPU_TO_BE16(1), .act_cnt = CPU_TO_BE16(1), - .alloc_len = - CPU_TO_BE32(sizeof(cpu_ctl_init_data)), + .alloc_len = CPU_TO_BE32(sizeof(cpu_ctl_init_data)), }, -#endif }, }; @@ -170,15 +187,13 @@ __section(".spirah.data") struct spirah spirah = { .alloc_len = CPU_TO_BE32(sizeof(struct proc_init_data)), }, -#if !defined(TEST) .cpu_ctrl = { - .addr = CPU_TO_BE64((unsigned long)&cpu_ctl_init_data), + .addr = CPU_TO_BE64(CPU_CTL_INIT_DATA_OFF), .alloc_cnt = CPU_TO_BE16(1), .act_cnt = CPU_TO_BE16(1), .alloc_len = CPU_TO_BE32(sizeof(cpu_ctl_init_data)), }, -#endif .mdump_src = { .addr = CPU_TO_BE64(MDST_TABLE_OFF), .alloc_cnt = CPU_TO_BE16(MDST_TABLE_SIZE / sizeof(struct mdst_table)), @@ -1695,8 +1710,8 @@ static void update_spirah_addr(void) if (proc_gen < proc_gen_p9) return; - *spirah_offset = SPIRAH_OFF; - *spira_offset = SPIRA_OFF; + *spirah_offset = CPU_TO_BE64(SPIRAH_OFF); + *spira_offset = CPU_TO_BE64(SPIRA_OFF); spirah.ntuples.hs_data_area.addr = CPU_TO_BE64(SPIRA_HEAP_BASE - SKIBOOT_BASE); spirah.ntuples.mdump_res.addr = CPU_TO_BE64(MDRT_TABLE_BASE - SKIBOOT_BASE); #endif diff --git a/hdata/test/hdata_to_dt.c b/hdata/test/hdata_to_dt.c index 4605d507e..11b7a3aca 100644 --- a/hdata/test/hdata_to_dt.c +++ b/hdata/test/hdata_to_dt.c @@ -67,6 +67,9 @@ unsigned long tb_hz = 512000000; #define SPR_PVR 0x11f /* RO: Processor version register */ +#define MSR_SF 0x8000000000000000ULL +#define MSR_HV 0x1000000000000000ULL + #define __CPU_H struct cpu_thread { uint32_t pir; From patchwork Sun Dec 8 12:22:49 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205623 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5G51lqqz9sP3 for ; Sun, 8 Dec 2019 23:28:29 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="VmS37pMh"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5G44V5fzDqGS for ; Sun, 8 Dec 2019 23:28:28 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::441; helo=mail-pf1-x441.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="VmS37pMh"; dkim-atps=neutral Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W58Y3jC8zDqDV for ; Sun, 8 Dec 2019 23:23:41 +1100 (AEDT) Received: by mail-pf1-x441.google.com with SMTP id n13so5766708pff.1 for ; Sun, 08 Dec 2019 04:23:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=QbjC3e4vIgJcURgVKwN7PCvoE+PMcaSrTzeRwFq4iyA=; b=VmS37pMhEftthrsJumCtL4Sklsz59eCrkCxVW8qzcTJUZpS6UUnCa0K9k1734Ir7hh OikyBCD1moT3pHdaT/ryh9RRyRwdcxHk3cCDPcNEpeWBmfG6/IK+PIfHPS1NAKqvRMuV 0o2zPmZ6VcxPufXn91Tqdyp6pzmNXRgCEvP5lRvNUQWbQIYJ+ZyvyVhu3iQwsBQMB333 SGqVi7slAkp3QeUeU1YPHEgBODOytfaqsHg5KItHo/OvZ8K+gJMKOhSqDLUQLxdfPXcq qp2v64TySffgGIPtOCFQrITuHN/EJhm009VKmvaMg2wNmn2a7Zh2OM6hJMX5kM3yWx9B jr5w== 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=QbjC3e4vIgJcURgVKwN7PCvoE+PMcaSrTzeRwFq4iyA=; b=j4BhuITAzpKmp8xOxUsFZr0hnZec6y5i3jb0+zlbPAkGE1jphIgPlGAPQMBr8UpdFX P9u2tw/hnG7DJkWS4FYIYfD152xiA5WPXxU22FraHILZLHSlz48HRvYIlVU+AMW24LFP QVgTMiCy9FwSwvZBAFjur4qc/3URO0Gw6Kfg+TykODvlV8FI7fL1dtG/+m6ADN6Sw+vg OuyA1HUVT50UTlC3CPlWUyKlZGK4goKcdQUPRMVOBHiJeEUBL6aHnt07lytZ8Pm3TVVX 61F0EDcI66fpfrtdlzFJujvumZkiZpDfnsV6n6mC042ZeGZfAE6VelPUqIuMyCjF+M/g LLAw== X-Gm-Message-State: APjAAAVfMrUkgDYL/UIqNeaAG781jaVaiSxFXmFQQN27Bjrxf2zck22R W5k4D0UemGWlQBuKy4LsN7I4TMfC X-Google-Smtp-Source: APXvYqyyywrfuChxLy83SlOJp3YH33Pjdl72SIx15kr2fSA7YGtTN1xVFKyxyGx6fLXE8W/zIirQKQ== X-Received: by 2002:a65:4345:: with SMTP id k5mr13757745pgq.252.1575807818991; Sun, 08 Dec 2019 04:23:38 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.23.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:23:38 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:49 +1000 Message-Id: <20191208122312.12837-9-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 08/31] hdata: endian conversions X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Reviewed-by: Vasant Hegde Signed-off-by: Nicholas Piggin --- hdata/memory.c | 3 ++- hdata/spira.c | 6 +++--- 2 files changed, 5 insertions(+), 4 deletions(-) diff --git a/hdata/memory.c b/hdata/memory.c index 9af7ae71d..9e5e99b9c 100644 --- a/hdata/memory.c +++ b/hdata/memory.c @@ -135,7 +135,8 @@ static bool add_address_range(struct dt_node *root, "on Chip 0x%x mattr: 0x%x pattr: 0x%x status:0x%x\n", (long long)be64_to_cpu(arange->start), (long long)be64_to_cpu(arange->end), - chip_id, arange->mirror_attr, mem_type, mem_status); + chip_id, be32_to_cpu(arange->mirror_attr), + mem_type, mem_status); /* reg contains start and length */ reg[0] = cleanup_addr(be64_to_cpu(arange->start)); diff --git a/hdata/spira.c b/hdata/spira.c index 2d0e875e3..f62170710 100644 --- a/hdata/spira.c +++ b/hdata/spira.c @@ -953,7 +953,7 @@ static void dt_init_secureboot_node(const struct iplparams_sysparams *sysparams) static void opal_dump_add_mpipl_boot(const struct iplparams_iplparams *p) { - u32 mdrt_cnt = spira.ntuples.mdump_res.act_cnt; + u32 mdrt_cnt = be16_to_cpu(spira.ntuples.mdump_res.act_cnt); u32 mdrt_max_cnt = MDRT_TABLE_SIZE / sizeof(struct mdrt_table); struct dt_node *dump_node; @@ -976,7 +976,7 @@ static void opal_dump_add_mpipl_boot(const struct iplparams_iplparams *p) return; } - if (p->cec_ipl_attrib != IPLPARAMS_ATTRIB_MEM_PRESERVE) { + if (be16_to_cpu(p->cec_ipl_attrib) != IPLPARAMS_ATTRIB_MEM_PRESERVE) { prlog(PR_DEBUG, "DUMP: Memory not preserved\n"); return; } @@ -1660,7 +1660,7 @@ static void add_npus(void) static void fixup_spira(void) { #if !defined(TEST) - spiras = (struct spiras *)CPU_TO_BE64(SPIRA_HEAP_BASE); + spiras = (struct spiras *)SPIRA_HEAP_BASE; #endif /* Validate SPIRA-S signature */ From patchwork Sun Dec 8 12:22:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205625 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5Gc6YY4z9sPL for ; Sun, 8 Dec 2019 23:28:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Gx2N/BiA"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5Gc4t4pzDqFG for ; Sun, 8 Dec 2019 23:28:56 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::644; helo=mail-pl1-x644.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Gx2N/BiA"; dkim-atps=neutral Received: from mail-pl1-x644.google.com (mail-pl1-x644.google.com [IPv6:2607:f8b0:4864:20::644]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W58d0DPyzDqP1 for ; Sun, 8 Dec 2019 23:23:45 +1100 (AEDT) Received: by mail-pl1-x644.google.com with SMTP id bd4so4609792plb.8 for ; Sun, 08 Dec 2019 04:23:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=uTtjqdDqUVQYvpfq9YjDER1OXrAR1H0VJS0uzzjs0M4=; b=Gx2N/BiAosfwQUAw++l7L1cyDR1YQhTTYphchLmMPilGybczolgDuhz9HJlgGg8rgo B+yKvGiOvyWne33y/1dELmIarTm7cFLPMOmFDNLGNG5am8Zc89jJ+360IDgNA3eB6pJ5 wyQPDNF+xz1mlgrL5ik3X2lYdX3ksKlYtzF5ujYIiHfSKtGzemxbM3yiRyMETsV/Gozm c36ApybFkpHarXLwtU9xgxQo2ovm/GuonHpyzPGhN4GH54nOsy3OqOtkgP0Uf0YpQ1c1 E+cCWXeW936niC7PfV5q5d2985vsjY13vOvcyW0MiEguGpR8xNit5oOElTrSxRcMYplW O55Q== 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=uTtjqdDqUVQYvpfq9YjDER1OXrAR1H0VJS0uzzjs0M4=; b=DtZ8L9y2TlbB/3J6oqRM5dLH93UmSbEEahBb3R71FB+YOysCDVAIbWbsU4aGIVwPvW R8iwd/5LUB8oCqABc9PGSSpY9tszerGg5M4ylttLF96ZY7PYyW7dt+k86MvAgWzSi+Zr VlRHjzKgyfbkc+sAZaXAXpuxO9YQ9Qgf6d+dt+n3nyJgwyzZQG0JbViQsJm7l4aPPoez WpFo9dACVt1lb3t9VtK+55UG2ZKrcOpcX3M19s6rowkQBvf2kr7u7fHGLbNHPfm28SVW mZNZwbJuXzRnd2ZljZqZXxm2jf80LFv2qSi4qXBSqFgw8ly02Ba7qEOMfPw8icyccKrt HsVQ== X-Gm-Message-State: APjAAAWkwcajLN/arNvlBJv+O97CjIEdK+I/fBQGcLhBe47fEqEznFSF 3zTSxm/waTFx7nOJhQ8YtwhSW5tg X-Google-Smtp-Source: APXvYqxcG3cfBncgVa78SpLAhdZP2hw31I99H9pSR8Ov7yeW6TiyfRCLbtVW9z1QfNV2zFZhj9PVwA== X-Received: by 2002:a17:90a:b318:: with SMTP id d24mr25378067pjr.142.1575807822833; Sun, 08 Dec 2019 04:23:42 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.23.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:23:42 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:50 +1000 Message-Id: <20191208122312.12837-10-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 09/31] naca: move naca definition from asm to C X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This results in the same layout and location of the naca and hv data structures. Signed-off-by: Nicholas Piggin --- asm/asm-offsets.c | 2 -- asm/head.S | 50 ------------------------------------------ hdata/Makefile.inc | 2 +- hdata/hdata.h | 2 ++ hdata/naca.c | 26 ++++++++++++++++++++++ hdata/naca.h | 54 ++++++++++++++++++++++++++++++++++++++++++++++ hdata/spira.c | 11 ++++------ hdata/spira.h | 6 +++++- include/mem-map.h | 2 ++ skiboot.lds.S | 5 +++++ 10 files changed, 99 insertions(+), 61 deletions(-) create mode 100644 hdata/naca.c create mode 100644 hdata/naca.h diff --git a/asm/asm-offsets.c b/asm/asm-offsets.c index e4584059c..61a25cab3 100644 --- a/asm/asm-offsets.c +++ b/asm/asm-offsets.c @@ -25,8 +25,6 @@ int main(void); int main(void) { - OFFSET(SPIRA_ACTUAL_SIZE, spira, reserved); - OFFSET(CPUTHREAD_PIR, cpu_thread, pir); OFFSET(CPUTHREAD_SAVE_R1, cpu_thread, save_r1); OFFSET(CPUTHREAD_STATE, cpu_thread, state); diff --git a/asm/head.S b/asm/head.S index e59f63871..b38cc870b 100644 --- a/asm/head.S +++ b/asm/head.S @@ -810,56 +810,6 @@ enter_nap: bne 1b nap b . -/* - * - * NACA structure, accessed by the FPS to find the SPIRA - * - */ - . = 0x4000 -.global naca -naca: - .llong spirah /* 0x0000 : SPIRA-H */ - .llong 0 /* 0x0008 : Reserved */ - .llong 0 /* 0x0010 : Reserved */ - .llong hv_release_data /* 0x0018 : HV release data */ - .llong 0 /* 0x0020 : Reserved */ - .llong 0 /* 0x0028 : Reserved */ - .llong spira /* 0x0030 : SP Interface Root */ - .llong hv_lid_load_table /* 0x0038 : LID load table */ - .llong 0 /* 0x0040 : Reserved */ - .space 68 - .long 0 /* 0x008c : Reserved */ - .space 16 - .long SPIRA_ACTUAL_SIZE /* 0x00a0 : Actual size of SPIRA */ - .space 28 - .llong 0 /* 0x00c0 : resident module loadmap */ - .space 136 - .llong 0 /* 0x0150 : reserved */ - .space 40 - .llong 0 /* 0x0180 : reserved */ - .space 36 - .long 0 /* 0x01ac : control flags */ - .byte 0 /* 0x01b0 : reserved */ - .space 4 - .byte 0 /* 0x01b5 : default state for SW attn */ - .space 1 - .byte 0x01 /* 0x01b7 : PCIA format */ - .llong hdat_entry /* 0x01b8 : Primary thread entry */ - .llong hdat_entry /* 0x01c0 : Secondary thread entry */ - .space 0xe38 - - .balign 0x10 -hv_release_data: - .space 58 - .llong 0x666 /* VRM ? */ - - .balign 0x10 -hv_lid_load_table: - .long 0x10 - .long 0x10 - .long 0 - .long 0 - /* * diff --git a/hdata/Makefile.inc b/hdata/Makefile.inc index 2d52f7654..49690f3c5 100644 --- a/hdata/Makefile.inc +++ b/hdata/Makefile.inc @@ -1,7 +1,7 @@ # -*-Makefile-*- SUBDIRS += hdata -HDATA_OBJS = spira.o pcia.o hdif.o memory.o fsp.o iohub.o vpd.o slca.o +HDATA_OBJS = naca.o spira.o pcia.o hdif.o memory.o fsp.o iohub.o vpd.o slca.o HDATA_OBJS += cpu-common.o vpd-common.o hostservices.o i2c.o tpmrel.o DEVSRC_OBJ = hdata/built-in.a diff --git a/hdata/hdata.h b/hdata/hdata.h index 7504b1e8f..580e5c75b 100644 --- a/hdata/hdata.h +++ b/hdata/hdata.h @@ -5,6 +5,8 @@ #define __HDATA_H #include +#include "hdif.h" +#include "spira.h" struct dt_node; diff --git a/hdata/naca.c b/hdata/naca.c new file mode 100644 index 000000000..b215c39eb --- /dev/null +++ b/hdata/naca.c @@ -0,0 +1,26 @@ +#include +#include +#include + +#include "naca.h" +#include "spira.h" + +__section(".naca.data") struct naca naca = { + .spirah_addr = CPU_TO_BE64(SPIRAH_OFF), + .hv_release_data_addr = CPU_TO_BE64(NACA_OFF + offsetof(struct naca, hv_release_data)), + .spira_addr = CPU_TO_BE64(SPIRA_OFF), + .lid_table_addr = CPU_TO_BE64(NACA_OFF + offsetof(struct naca, hv_lid_load_table)), + .spira_size = CPU_TO_BE32(SPIRA_ACTUAL_SIZE), + .hv_load_map_addr = 0, + .attn_enabled = 0, + .pcia_supported = 1, + .__primary_thread_entry = CPU_TO_BE64(0x180), + .__secondary_thread_entry = CPU_TO_BE64(0x180), + .hv_release_data = { + .vrm = CPU_TO_BE64(0x666), /* ? */ + }, + .hv_lid_load_table = { + .w0 = CPU_TO_BE32(0x10), + .w1 = CPU_TO_BE32(0x10), + }, +}; diff --git a/hdata/naca.h b/hdata/naca.h new file mode 100644 index 000000000..1271b59a5 --- /dev/null +++ b/hdata/naca.h @@ -0,0 +1,54 @@ +// SPDX-License-Identifier: Apache-2.0 +/* Copyright 2019 IBM Corp. */ + +#ifndef __NACA_H +#define __NACA_H + +#include +#include +#include + +struct hv_release_data { + uint8_t reserved_0x0[58]; + __be64 vrm; +} __packed __attribute__((aligned(0x10))); + +struct hv_lid_load_table { + __be32 w0; + __be32 w1; + __be32 w2; + __be32 w3; +} __packed __attribute__((aligned(0x10))); + +/* + * NACA structure, accessed by the FSP to find the SPIRA + */ +struct naca { + __be64 spirah_addr; /* 0x0000 */ + uint8_t reserved_0x8[0x10]; + __be64 hv_release_data_addr; /* 0x0018 */ + uint8_t reserved_0x20[0x10]; + __be64 spira_addr; /* 0x0030 */ + __be64 lid_table_addr; /* 0x0038 */ + uint8_t reserved_0x40[0x60]; + __be32 spira_size; /* 0x00a0 */ + uint8_t reserved_0xa4[0x1c]; + __be64 hv_load_map_addr; /* 0x00c0 */ + uint8_t reserved_0xc8[0xe4]; + uint8_t flags[4]; /* 0x01ac */ + uint8_t reserved_0x1b0[0x5]; + uint8_t attn_enabled; /* 0x01b5 */ + uint8_t reserved_0x1b6[0x1]; + uint8_t pcia_supported; /* 0x01b7 */ + __be64 __primary_thread_entry; /* 0x01b8 */ + __be64 __secondary_thread_entry; /* 0x01c0 */ + uint8_t reserved_0x1d0[0xe38]; + + /* Not part of the naca but it's convenient to put them here */ + struct hv_release_data hv_release_data; + struct hv_lid_load_table hv_lid_load_table; +} __packed __attribute((aligned(0x10))); + +extern struct naca naca; + +#endif diff --git a/hdata/spira.c b/hdata/spira.c index f62170710..7e19d3d5c 100644 --- a/hdata/spira.c +++ b/hdata/spira.c @@ -3,7 +3,6 @@ #include #include -#include "spira.h" #include #include #include @@ -15,6 +14,8 @@ #include "hdata.h" #include "hostservices.h" +#include "naca.h" +#include "spira.h" /* Processor Initialization structure, contains * the initial NIA and MSR values for the entry @@ -1703,15 +1704,11 @@ static void fixup_spira(void) static void update_spirah_addr(void) { #if !defined(TEST) - extern uint32_t naca; - uint64_t *spirah_offset = (uint64_t *)&naca; - uint64_t *spira_offset = (uint64_t *)((u64)(&naca) + 0x30); - if (proc_gen < proc_gen_p9) return; - *spirah_offset = CPU_TO_BE64(SPIRAH_OFF); - *spira_offset = CPU_TO_BE64(SPIRA_OFF); + naca.spirah_addr = CPU_TO_BE64(SPIRAH_OFF); + naca.spira_addr = CPU_TO_BE64(SPIRA_OFF); spirah.ntuples.hs_data_area.addr = CPU_TO_BE64(SPIRA_HEAP_BASE - SKIBOOT_BASE); spirah.ntuples.mdump_res.addr = CPU_TO_BE64(MDRT_TABLE_BASE - SKIBOOT_BASE); #endif diff --git a/hdata/spira.h b/hdata/spira.h index 2c944be9f..2c2872260 100644 --- a/hdata/spira.h +++ b/hdata/spira.h @@ -66,6 +66,8 @@ struct spira_ntuples { struct spira_ntuple proc_dump_area; /* 0x400 */ }; +#define SPIRA_RESERVED_BYTES 0x60 + struct spira { struct HDIF_common_hdr hdr; struct HDIF_idata_ptr ntuples_ptr; @@ -77,9 +79,11 @@ struct spira { * * According to FSP engineers, this is an okay thing to do. */ - u8 reserved[0x60]; + u8 reserved[SPIRA_RESERVED_BYTES]; } __packed __align(0x100); +#define SPIRA_ACTUAL_SIZE (sizeof(struct spira) - SPIRA_RESERVED_BYTES) + extern struct spira spira; /* SPIRA-H signature */ diff --git a/include/mem-map.h b/include/mem-map.h index 61ecac3c8..8ac11e916 100644 --- a/include/mem-map.h +++ b/include/mem-map.h @@ -21,6 +21,8 @@ */ #define EXCEPTION_VECTORS_END 0x2000 +#define NACA_OFF 0x4000 + /* The NACA and other stuff in head.S need to be at the start: we * give it 64k before placing the SPIRA and related data. */ diff --git a/skiboot.lds.S b/skiboot.lds.S index 1dc0ca92e..1822334b2 100644 --- a/skiboot.lds.S +++ b/skiboot.lds.S @@ -59,6 +59,11 @@ SECTIONS KEEP(*(.head)) } + . = NACA_OFF; + .naca : { + KEEP(*(.naca.data)) + } + . = SPIRA_OFF; .spira : { KEEP(*(.spira.data)) From patchwork Sun Dec 8 12:22:51 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205631 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5H31Zfmz9sP3 for ; Sun, 8 Dec 2019 23:29:19 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Il9fbsUO"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5H26wnkzDqPf for ; Sun, 8 Dec 2019 23:29:18 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1030; helo=mail-pj1-x1030.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Il9fbsUO"; dkim-atps=neutral Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W58j51fWzDqFL for ; Sun, 8 Dec 2019 23:23:49 +1100 (AEDT) Received: by mail-pj1-x1030.google.com with SMTP id g4so4643087pjs.10 for ; Sun, 08 Dec 2019 04:23:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5LLfbAweH8IeROJ/vHuL11tEKhpy3FiIGdKn/fTeIz8=; b=Il9fbsUO7L/nv78G7xzbbWUAmuMd0IeGqfMtMnC7ewkRyO+hZ44dPXllAJsZ0MwuKt S8Pv3rzW4jVnejn5ZAC/3buNIWZwXgwNbTnvVttNC5e6QW6zOFVmuHuMZK8PBadF0ORY JghEjV83+j/67JAA3vMfuYn3at0sKNffo2ET/eNvhqDhY9tkT4347gV0d4p/pFNkuJMY 06sZbqhnOghhiWoy/S7+jWGOEw4F+eXExY+aRockRMt2UToSTyRwASafolO3g9QdJrXo rbXGPUG8VZ69S+s9dELU+hs6vNX0tOV3c1dJoZZoPevAQta7HsuEbgogUJthcsjCLqh2 Q9Tw== 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=5LLfbAweH8IeROJ/vHuL11tEKhpy3FiIGdKn/fTeIz8=; b=qXyd2pYpLkXXPZIIDUZ4sBq4+4HfHRAtUC4dbPrsuJ8SXAZ1QbwL0mzoa1sTqpJqOZ j0xO0GORoPocfuhj7mA8mO82Bsc8jR+OG9YTb0vOz/ApqvWeyTDxsbm9JIcV0s+jTEwk ILXHqDjelkbI1Crj8KD1N29cD3vA1jhee6jdO2yJLZ3YTxAwZBRQlcHwRi0VJ1KIyMXj folrUnsHure0w0XQivdh1/x1O4/QF89ahtFVkJKZPXw5wyqweNd/E8CUOOpnNTi0in4m ts6VKwcmcVv6TrjjXM2tYiqGxWbMhrlnWqUbuo7Oc9sxYdY1mIUXQl2P5SCKAr0+BOIR l0wQ== X-Gm-Message-State: APjAAAWMD6OeZybtA/ADZ+sJ28BLlI3DVb7pJTcuNMsCRRyUl+/y6kcX 72q3CuI7ht5UKu8j/VqYzduESJTx X-Google-Smtp-Source: APXvYqynQ3sk3qfcTlWoFCvUM8VJcxYzftlBelkgBTHfWLubENCXG1pUFpktfVto5YMGXge/Dkdz6w== X-Received: by 2002:a17:902:5999:: with SMTP id p25mr25261165pli.261.1575807825333; Sun, 08 Dec 2019 04:23:45 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.23.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:23:44 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:51 +1000 Message-Id: <20191208122312.12837-11-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 10/31] io: endian conversions for io accessors X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This requires a small change to flash drivers which assumed 4-byte LPC reads would not change endian. _raw accessors could be added if this becomes a signifcant pattern, but for now this hack works. Signed-off-by: Nicholas Piggin --- include/io.h | 79 ++++++++++++++++++++++++++++++------- libflash/ipmi-hiomap.c | 20 +++++++--- libflash/mbox-flash.c | 20 +++++++--- libflash/test/mbox-server.c | 31 ++++++++++++++- 4 files changed, 121 insertions(+), 29 deletions(-) diff --git a/include/io.h b/include/io.h index c6203a274..57dddd49f 100644 --- a/include/io.h +++ b/include/io.h @@ -9,6 +9,7 @@ #include #include #include +#include #include /* @@ -35,10 +36,10 @@ static inline uint8_t in_8(const volatile uint8_t *addr) static inline uint16_t __in_be16(const volatile uint16_t *addr) { - uint16_t val; + __be16 val; asm volatile("lhzcix %0,0,%1" : "=r"(val) : "r"(addr), "m"(*addr) : "memory"); - return val; + return be16_to_cpu(val); } static inline uint16_t in_be16(const volatile uint16_t *addr) @@ -47,17 +48,26 @@ static inline uint16_t in_be16(const volatile uint16_t *addr) return __in_be16(addr); } +static inline uint16_t __in_le16(const volatile uint16_t *addr) +{ + __le16 val; + asm volatile("lhzcix %0,0,%1" : + "=r"(val) : "r"(addr), "m"(*addr) : "memory"); + return le16_to_cpu(val); +} + static inline uint16_t in_le16(const volatile uint16_t *addr) { - return bswap_16(in_be16(addr)); + sync(); + return __in_le16(addr); } static inline uint32_t __in_be32(const volatile uint32_t *addr) { - uint32_t val; + __be32 val; asm volatile("lwzcix %0,0,%1" : "=r"(val) : "r"(addr), "m"(*addr) : "memory"); - return val; + return be32_to_cpu(val); } static inline uint32_t in_be32(const volatile uint32_t *addr) @@ -66,17 +76,26 @@ static inline uint32_t in_be32(const volatile uint32_t *addr) return __in_be32(addr); } +static inline uint32_t __in_le32(const volatile uint32_t *addr) +{ + __le32 val; + asm volatile("lwzcix %0,0,%1" : + "=r"(val) : "r"(addr), "m"(*addr) : "memory"); + return le32_to_cpu(val); +} + static inline uint32_t in_le32(const volatile uint32_t *addr) { - return bswap_32(in_be32(addr)); + sync(); + return __in_le32(addr); } static inline uint64_t __in_be64(const volatile uint64_t *addr) { - uint64_t val; + __be64 val; asm volatile("ldcix %0,0,%1" : "=r"(val) : "r"(addr), "m"(*addr) : "memory"); - return val; + return be64_to_cpu(val); } static inline uint64_t in_be64(const volatile uint64_t *addr) @@ -85,9 +104,18 @@ static inline uint64_t in_be64(const volatile uint64_t *addr) return __in_be64(addr); } +static inline uint64_t __in_le64(const volatile uint64_t *addr) +{ + __le64 val; + asm volatile("ldcix %0,0,%1" : + "=r"(val) : "r"(addr), "m"(*addr) : "memory"); + return le64_to_cpu(val); +} + static inline uint64_t in_le64(const volatile uint64_t *addr) { - return bswap_64(in_be64(addr)); + sync(); + return __in_le64(addr); } static inline void __out_8(volatile uint8_t *addr, uint8_t val) @@ -105,7 +133,7 @@ static inline void out_8(volatile uint8_t *addr, uint8_t val) static inline void __out_be16(volatile uint16_t *addr, uint16_t val) { asm volatile("sthcix %0,0,%1" - : : "r"(val), "r"(addr), "m"(*addr) : "memory"); + : : "r"(cpu_to_be16(val)), "r"(addr), "m"(*addr) : "memory"); } static inline void out_be16(volatile uint16_t *addr, uint16_t val) @@ -114,15 +142,22 @@ static inline void out_be16(volatile uint16_t *addr, uint16_t val) return __out_be16(addr, val); } +static inline void __out_le16(volatile uint16_t *addr, uint16_t val) +{ + asm volatile("sthcix %0,0,%1" + : : "r"(cpu_to_le16(val)), "r"(addr), "m"(*addr) : "memory"); +} + static inline void out_le16(volatile uint16_t *addr, uint16_t val) { - out_be16(addr, bswap_16(val)); + sync(); + return __out_le16(addr, val); } static inline void __out_be32(volatile uint32_t *addr, uint32_t val) { asm volatile("stwcix %0,0,%1" - : : "r"(val), "r"(addr), "m"(*addr) : "memory"); + : : "r"(cpu_to_be32(val)), "r"(addr), "m"(*addr) : "memory"); } static inline void out_be32(volatile uint32_t *addr, uint32_t val) @@ -131,15 +166,22 @@ static inline void out_be32(volatile uint32_t *addr, uint32_t val) return __out_be32(addr, val); } +static inline void __out_le32(volatile uint32_t *addr, uint32_t val) +{ + asm volatile("stwcix %0,0,%1" + : : "r"(cpu_to_le32(val)), "r"(addr), "m"(*addr) : "memory"); +} + static inline void out_le32(volatile uint32_t *addr, uint32_t val) { - out_be32(addr, bswap_32(val)); + sync(); + return __out_le32(addr, val); } static inline void __out_be64(volatile uint64_t *addr, uint64_t val) { asm volatile("stdcix %0,0,%1" - : : "r"(val), "r"(addr), "m"(*addr) : "memory"); + : : "r"(cpu_to_be64(val)), "r"(addr), "m"(*addr) : "memory"); } static inline void out_be64(volatile uint64_t *addr, uint64_t val) @@ -148,9 +190,16 @@ static inline void out_be64(volatile uint64_t *addr, uint64_t val) return __out_be64(addr, val); } +static inline void __out_le64(volatile uint64_t *addr, uint64_t val) +{ + asm volatile("stdcix %0,0,%1" + : : "r"(cpu_to_le64(val)), "r"(addr), "m"(*addr) : "memory"); +} + static inline void out_le64(volatile uint64_t *addr, uint64_t val) { - out_be64(addr, bswap_64(val)); + sync(); + return __out_le64(addr, val); } /* Assistant to macros used to access PCI config space */ diff --git a/libflash/ipmi-hiomap.c b/libflash/ipmi-hiomap.c index 0328101c6..821d28dd9 100644 --- a/libflash/ipmi-hiomap.c +++ b/libflash/ipmi-hiomap.c @@ -570,8 +570,13 @@ static int lpc_window_read(struct ipmi_hiomap *ctx, uint32_t pos, /* XXX: make this read until it's aligned */ if (len > 3 && !(off & 3)) { rc = lpc_read(OPAL_LPC_FW, off, &dat, 4); - if (!rc) - *(uint32_t *)buf = dat; + if (!rc) { + /* + * lpc_read swaps to CPU endian but it's not + * really a 32-bit value, so convert back. + */ + *(__be32 *)buf = cpu_to_be32(dat); + } chunk = 4; } else { rc = lpc_read(OPAL_LPC_FW, off, &dat, 1); @@ -615,12 +620,15 @@ static int lpc_window_write(struct ipmi_hiomap *ctx, uint32_t pos, uint32_t chunk; if (len > 3 && !(off & 3)) { - rc = lpc_write(OPAL_LPC_FW, off, - *(uint32_t *)buf, 4); + /* endian swap: see lpc_window_write */ + uint32_t dat = be32_to_cpu(*(__be32 *)buf); + + rc = lpc_write(OPAL_LPC_FW, off, dat, 4); chunk = 4; } else { - rc = lpc_write(OPAL_LPC_FW, off, - *(uint8_t *)buf, 1); + uint8_t dat = *(uint8_t *)buf; + + rc = lpc_write(OPAL_LPC_FW, off, dat, 1); chunk = 1; } if (rc) { diff --git a/libflash/mbox-flash.c b/libflash/mbox-flash.c index 9d47fe7ea..5df020f55 100644 --- a/libflash/mbox-flash.c +++ b/libflash/mbox-flash.c @@ -159,8 +159,13 @@ static int lpc_window_read(struct mbox_flash_data *mbox_flash, uint32_t pos, /* XXX: make this read until it's aligned */ if (len > 3 && !(off & 3)) { rc = lpc_read(OPAL_LPC_FW, off, &dat, 4); - if (!rc) - *(uint32_t *)buf = dat; + if (!rc) { + /* + * lpc_read swaps to CPU endian but it's not + * really a 32-bit value, so convert back. + */ + *(__be32 *)buf = cpu_to_be32(dat); + } chunk = 4; } else { rc = lpc_read(OPAL_LPC_FW, off, &dat, 1); @@ -194,12 +199,15 @@ static int lpc_window_write(struct mbox_flash_data *mbox_flash, uint32_t pos, uint32_t chunk; if (len > 3 && !(off & 3)) { - rc = lpc_write(OPAL_LPC_FW, off, - *(uint32_t *)buf, 4); + /* endian swap: see lpc_window_write */ + uint32_t dat = be32_to_cpu(*(__be32 *)buf); + + rc = lpc_write(OPAL_LPC_FW, off, dat, 4); chunk = 4; } else { - rc = lpc_write(OPAL_LPC_FW, off, - *(uint8_t *)buf, 1); + uint8_t dat = *(uint8_t *)buf; + + rc = lpc_write(OPAL_LPC_FW, off, dat, 1); chunk = 1; } if (rc) { diff --git a/libflash/test/mbox-server.c b/libflash/test/mbox-server.c index 3f879dfa4..59786ca14 100644 --- a/libflash/test/mbox-server.c +++ b/libflash/test/mbox-server.c @@ -100,7 +100,21 @@ int64_t lpc_read(enum OpalLPCAddressType __unused addr_type, uint32_t addr, /* Let it read from a write window... Spec says it ok! */ if (!check_window(addr, sz) || server_state.win_type == WIN_CLOSED) return 1; - memcpy(data, server_state.lpc_base + addr, sz); + + switch (sz) { + case 1: + *(uint8_t *)data = *(uint8_t *)(server_state.lpc_base + addr); + break; + case 2: + *(uint16_t *)data = be16_to_cpu(*(uint16_t *)(server_state.lpc_base + addr)); + break; + case 4: + *(uint32_t *)data = be32_to_cpu(*(uint32_t *)(server_state.lpc_base + addr)); + break; + default: + prerror("Invalid data size %d\n", sz); + return 1; + } return 0; } @@ -111,7 +125,20 @@ int64_t lpc_write(enum OpalLPCAddressType __unused addr_type, uint32_t addr, { if (!check_window(addr, sz) || server_state.win_type != WIN_WRITE) return 1; - memcpy(server_state.lpc_base + addr, &data, sz); + switch (sz) { + case 1: + *(uint8_t *)(server_state.lpc_base + addr) = data; + break; + case 2: + *(uint16_t *)(server_state.lpc_base + addr) = cpu_to_be16(data); + break; + case 4: + *(uint32_t *)(server_state.lpc_base + addr) = cpu_to_be32(data); + break; + default: + prerror("Invalid data size %d\n", sz); + return 1; + } return 0; } From patchwork Sun Dec 8 12:22:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205633 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5HX61Tlz9sP3 for ; Sun, 8 Dec 2019 23:29:44 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OOd2iKTS"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5HX45sxzDqPK for ; Sun, 8 Dec 2019 23:29:44 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1041; helo=mail-pj1-x1041.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="OOd2iKTS"; dkim-atps=neutral Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W58l3XRyzDqJW for ; Sun, 8 Dec 2019 23:23:51 +1100 (AEDT) Received: by mail-pj1-x1041.google.com with SMTP id g4so4643109pjs.10 for ; Sun, 08 Dec 2019 04:23:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=l2i6VgWiENS9CWUysFibYFV7sjFhs5PNWT8Cvdl9zvs=; b=OOd2iKTSkwa9GApZcaYZoXN1LT3fCd0H0aOOq1AjB/IsuKEHG5Al2d/Cc007uD2Mcf VZ6Hilx7H/3Vo5jYhDAjJChRO8smxNlrM3+jt32Ie42K7KCmh7fSW1bn89a3NKm4D/0a rfizJ5x84h8LbcIhoVsVnaNx1XJ54GwSSkr+6aph5is3LMFC3eu3ZHB08vaGmf02CNrl FnrjiazWKvW8XE92RjKuaFYu88rQBcC7l5b8WWMOSzL6Cwsf2f2SIGRbBQtEVDUzYtGx epCklOOacZPQSSgaPgdoHlwa/BhkR9mcBYksQYXnfE2KKa8PH1lcPbM5EAmioFuTW64t ffCQ== 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=l2i6VgWiENS9CWUysFibYFV7sjFhs5PNWT8Cvdl9zvs=; b=mOZ61z0K5sZhDuOWucIOyoTz+1D966QvRy5DH1Oq8Oo283BWGBs+XUsCh03687a2Gq TIVLaaOlcvoABFnKNgDDX4akWKYTeknvvI8NfnPnpuGqMAjyxZNtdlwteGQSXeMa15g6 wJLlZksV0lkRCkUoLmj8DoCALRyABqAEKWy4LyUsgZfFDHvMyaR2ODN4xdpFE0fD6jOQ KCEDraorgPdOBL4BX+hNlChp3efiodLlxxdx1ForIuer2wxn+BAd0p1sevdi78NATMko XIBEq7pTwZ1bQqMNM/ZjNV9EzpsOPXECO4CcDchZT2xOPUiZfCP5HYEz9AUauMv84veT Cqag== X-Gm-Message-State: APjAAAUvkGXSpwoEV8E0UzWXjieR2pz/GgH+st0ypzeji6AnChkxA+8i hthVhQ8MsxknZuRG8uE21dQmSZ94 X-Google-Smtp-Source: APXvYqzSUSDTp8rmjDT6Aadfvat8neG0KEHbnIsTE3OR9IZQ39d27v4dueLdlSjTbeTclzscXgizIQ== X-Received: by 2002:a17:902:904b:: with SMTP id w11mr20352949plz.204.1575807828032; Sun, 08 Dec 2019 04:23:48 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.23.45 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:23:47 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:52 +1000 Message-Id: <20191208122312.12837-12-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 11/31] hmi: endian conversions X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Signed-off-by: Nicholas Piggin --- core/hmi.c | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/core/hmi.c b/core/hmi.c index cb158c01c..3e38e04d5 100644 --- a/core/hmi.c +++ b/core/hmi.c @@ -399,7 +399,7 @@ static bool decode_core_fir(struct cpu_thread *cpu, if (core_fir & PPC_BIT(xstop_bits[i].bit)) { found = true; hmi_evt->u.xstop_error.xstop_reason - |= xstop_bits[i].reason; + |= cpu_to_be32(xstop_bits[i].reason); } } return found; @@ -430,7 +430,7 @@ static void find_core_checkstop_reason(struct OpalHMIEvent *hmi_evt, /* Initialize xstop_error fields. */ hmi_evt->u.xstop_error.xstop_reason = 0; - hmi_evt->u.xstop_error.u.pir = cpu->pir; + hmi_evt->u.xstop_error.u.pir = cpu_to_be32(cpu->pir); if (decode_core_fir(cpu, hmi_evt)) queue_hmi_event(hmi_evt, 0, out_flags); @@ -521,7 +521,7 @@ static void find_nx_checkstop_reason(int flat_chip_id, hmi_evt->severity = OpalHMI_SEV_FATAL; hmi_evt->type = OpalHMI_ERROR_MALFUNC_ALERT; hmi_evt->u.xstop_error.xstop_type = CHECKSTOP_TYPE_NX; - hmi_evt->u.xstop_error.u.chip_id = flat_chip_id; + hmi_evt->u.xstop_error.u.chip_id = cpu_to_be32(flat_chip_id); /* Get DMA & Engine FIR data register value. */ if (xscom_read(flat_chip_id, nx_dma_engine_fir, &nx_dma_fir) != 0) { @@ -539,12 +539,12 @@ static void find_nx_checkstop_reason(int flat_chip_id, for (i = 0; i < ARRAY_SIZE(nx_dma_xstop_bits); i++) if (nx_dma_fir & PPC_BIT(nx_dma_xstop_bits[i].bit)) hmi_evt->u.xstop_error.xstop_reason - |= nx_dma_xstop_bits[i].reason; + |= cpu_to_be32(nx_dma_xstop_bits[i].reason); for (i = 0; i < ARRAY_SIZE(nx_pbi_xstop_bits); i++) if (nx_pbi_fir_val & PPC_BIT(nx_pbi_xstop_bits[i].bit)) hmi_evt->u.xstop_error.xstop_reason - |= nx_pbi_xstop_bits[i].reason; + |= cpu_to_be32(nx_pbi_xstop_bits[i].reason); /* * Set NXDMAENGFIR[38] to signal PRD that service action is required. @@ -705,8 +705,8 @@ static void find_npu2_checkstop_reason(int flat_chip_id, hmi_evt->severity = OpalHMI_SEV_WARNING; hmi_evt->type = OpalHMI_ERROR_MALFUNC_ALERT; hmi_evt->u.xstop_error.xstop_type = CHECKSTOP_TYPE_NPU; - hmi_evt->u.xstop_error.xstop_reason = xstop_reason; - hmi_evt->u.xstop_error.u.chip_id = flat_chip_id; + hmi_evt->u.xstop_error.xstop_reason = cpu_to_be32(xstop_reason); + hmi_evt->u.xstop_error.u.chip_id = cpu_to_be32(flat_chip_id); /* Marking the event as recoverable so that we don't crash */ queue_hmi_event(hmi_evt, 1, out_flags); @@ -774,7 +774,7 @@ static void find_npu_checkstop_reason(int flat_chip_id, hmi_evt->severity = OpalHMI_SEV_WARNING; hmi_evt->type = OpalHMI_ERROR_MALFUNC_ALERT; hmi_evt->u.xstop_error.xstop_type = CHECKSTOP_TYPE_NPU; - hmi_evt->u.xstop_error.u.chip_id = flat_chip_id; + hmi_evt->u.xstop_error.u.chip_id = cpu_to_be32(flat_chip_id); /* The HMI is "recoverable" because it shouldn't crash the system */ queue_hmi_event(hmi_evt, 1, out_flags); @@ -1116,7 +1116,7 @@ static int handle_tfac_errors(struct OpalHMIEvent *hmi_evt, uint64_t *out_flags) uint64_t tfmr = mfspr(SPR_TFMR); /* Initialize the hmi event with old value of TFMR */ - hmi_evt->tfmr = tfmr; + hmi_evt->tfmr = cpu_to_be64(tfmr); /* A TFMR parity/corrupt error makes us ignore all the local stuff.*/ if (tfmr & SPR_TFMR_TFMR_CORRUPT) { @@ -1204,7 +1204,7 @@ static int handle_hmi_exception(uint64_t hmer, struct OpalHMIEvent *hmi_evt, prlog(PR_DEBUG, "Received HMI interrupt: HMER = 0x%016llx\n", hmer); /* Initialize the hmi event with old value of HMER */ if (hmi_evt) - hmi_evt->hmer = hmer; + hmi_evt->hmer = cpu_to_be64(hmer); /* Handle Timer/TOD errors separately */ if (hmer & (SPR_HMER_TFAC_ERROR | SPR_HMER_TFMR_PARITY_ERROR)) { From patchwork Sun Dec 8 12:22:53 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205634 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5JJ7496z9sQp for ; Sun, 8 Dec 2019 23:30:24 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="knk4RAiF"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5JJ4spMzDqGp for ; Sun, 8 Dec 2019 23:30:24 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::444; helo=mail-pf1-x444.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="knk4RAiF"; dkim-atps=neutral Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W58n37QpzDqDb for ; Sun, 8 Dec 2019 23:23:53 +1100 (AEDT) Received: by mail-pf1-x444.google.com with SMTP id x185so5752284pfc.5 for ; Sun, 08 Dec 2019 04:23:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=rLw4TBkcEEF0vwfKeRaANqeeoSI3/d1GlgLJBLDaJAw=; b=knk4RAiFXw362JP27V2QPl4tzNu+UUtxbR5YICHcQxGTGSXm++6SzKUmCXdYrBzd+g jg9H57jXh8dKgatQELfZzFGdfd9vWrNAE8586RMB+zOplqL/4uejd1ig/XM4uIvtKma8 sNB6m0Y7C3c3ntFHHvceSwWjbPvfzMrs8jvychc011ddmeKof3U4EOHaLfFgDCrDiwTR pzyZ9XM2RV9bEaicQnGTn1qdcOjQa8QrMdriNFz0+gQ+WA+Qmh7Ee4uJsgEBw4Mj15HE xEEMItz3dxBpaAaegLxkNVzEsfdwK0VZQAs5IWvkjL4tV9ZyHY4N/IgoBtJ4ZotnOTgr YomA== 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=rLw4TBkcEEF0vwfKeRaANqeeoSI3/d1GlgLJBLDaJAw=; b=rF5NmaWvPtvM4TSYtv7LjSzMllaOx172hFag40b2Cb/lT+za//+PN5FrP8dTlM+Yc0 aFKOQzUwia2oscMHuN5hNEm4pwzDHbpFCqW9VAaduqk5WVFnryLfqTax5L7OctbhOcmo Dq72CEAXy/X5UXwOvKcA4YoeSfCbMFn/SnJElPOw/Bngd6iL0cOmFJj5z/1Pm1z4ukqC MU9hWw9kKZGECU1gSOzkVssoIshxyaPNGBQ80u98QTR7jk5wN6vYQD822HrylCgLVyYx JT+wLr9NS8QZc8xdjnl1PxU6Mbw0SsyfLo6KOfMKotvDMt8QMw08PAyu3uRqHSsTSpsc X0gg== X-Gm-Message-State: APjAAAVoC2ToRzMGfoUBLHmuTaIny22GC/2NuoL56/tJhaqEBgYoknEL sWozVPBQdwnMR49gG8SN/nfuhdYc X-Google-Smtp-Source: APXvYqwflHL3ACVD9C1JsbgarOuAu272GVoorOkL+pMYNQtt6EOcQyoxLGOL5T8V+SNaB3FTbDGPFQ== X-Received: by 2002:a63:d94b:: with SMTP id e11mr13574218pgj.79.1575807830652; Sun, 08 Dec 2019 04:23:50 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.23.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:23:50 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:53 +1000 Message-Id: <20191208122312.12837-13-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 12/31] cvc: allow BE cvc code to be called from LE context X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Signed-off-by: Nicholas Piggin --- asm/cvc_entry.S | 42 ++++++++++++++++++------------------------ libstb/cvc.c | 16 +++++++++++----- libstb/cvc.h | 2 +- 3 files changed, 30 insertions(+), 30 deletions(-) diff --git a/asm/cvc_entry.S b/asm/cvc_entry.S index 3e8b3fdad..94cd1aec1 100644 --- a/asm/cvc_entry.S +++ b/asm/cvc_entry.S @@ -1,28 +1,9 @@ # SPDX-License-Identifier: Apache-2.0 -# IBM_PROLOG_BEGIN_TAG -# This is an automatically generated prolog. -# -# $Source: src/usr/secureboot/base/rom_entry.S $ -# -# OpenPOWER HostBoot Project -# -# COPYRIGHT International Business Machines Corp. 2013,2016 -# -# Licensed under the Apache License, Version 2.0 (the "License"); -# you may not use this file except in compliance with the License. -# You may obtain a copy of the License at -# -# http://www.apache.org/licenses/LICENSE-2.0 -# -# Unless required by applicable law or agreed to in writing, software -# distributed under the License is distributed on an "AS IS" BASIS, -# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or -# implied. See the License for the specific language governing -# permissions and limitations under the License. -# -# IBM_PROLOG_END_TAG - -#.include "kernel/ppcconsts.S" + +# Derived from automatically generated HostBoot rom_entry.S + +#include +#include # Updated hostboot location is src/securerom/rom_entry.S. # This also has a fix for TOC save frame pointer. @@ -49,7 +30,20 @@ call_rom_entry: mr %r5, %r6 mr %r6, %r7 mr %r7, %r8 +#if HAVE_BIG_ENDIAN bctrl +#else + bl $+4 +1: mflr %r9 + addi %r9,%r9,2f - 1b + mtspr SPR_HSRR0, %r9 + mfmsr %r9 + xori %r9,%r9,MSR_LE + mtspr SPR_HSRR1, %r9 + hrfid +2: .long 0x2104804e /* bctrl */ + FIXUP_ENDIAN +#endif ld %r2, STACK_TOC_OFFSET(%r1) addi %r1, %r1, 128 ld %r0, 16(%r1) diff --git a/libstb/cvc.c b/libstb/cvc.c index a14ed49f4..356d36bd9 100644 --- a/libstb/cvc.c +++ b/libstb/cvc.c @@ -324,16 +324,19 @@ int call_cvc_sha512(const uint8_t *data, size_t data_len, uint8_t *digest, if (!service) return OPAL_UNSUPPORTED; - if (service->version == 1) + if (service->version == 1) { + unsigned long msr = mfmsr(); __cvc_sha512_v1((void*) service->addr, data, data_len, digest); - else + assert(msr == mfmsr()); + } else { return OPAL_UNSUPPORTED; + } return OPAL_SUCCESS; } int call_cvc_verify(void *container, size_t len, const void *hw_key_hash, - size_t hw_key_hash_size, uint64_t *log) + size_t hw_key_hash_size, __be64 *log) { ROM_hw_params hw_params; ROM_response rc; @@ -354,12 +357,15 @@ int call_cvc_verify(void *container, size_t len, const void *hw_key_hash, memset(&hw_params, 0, sizeof(ROM_hw_params)); memcpy(&hw_params.hw_key_hash, hw_key_hash, hw_key_hash_size); - if (service->version == 1) + if (service->version == 1) { + unsigned long msr = mfmsr(); rc = __cvc_verify_v1((void*) service->addr, (ROM_container_raw*) container, &hw_params); - else + assert(msr == mfmsr()); + } else { return OPAL_UNSUPPORTED; + } if (log) *log = hw_params.log; diff --git a/libstb/cvc.h b/libstb/cvc.h index 6d8546fb2..ef105f76d 100644 --- a/libstb/cvc.h +++ b/libstb/cvc.h @@ -30,7 +30,7 @@ int cvc_init(void); * */ int call_cvc_verify(void *buf, size_t size, const void *hw_key_hash, - size_t hw_key_hash_size, uint64_t *log); + size_t hw_key_hash_size, __be64 *log); /* * call_cvc_sha512 - Call the CVC-sha512 service to calculate a sha512 hash. From patchwork Sun Dec 8 12:22:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205635 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5Jw6Vbzz9sPL for ; Sun, 8 Dec 2019 23:30:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jqEIIa4z"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5Jw57nQzDqGp for ; Sun, 8 Dec 2019 23:30:56 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::52c; helo=mail-pg1-x52c.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jqEIIa4z"; dkim-atps=neutral Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W58t4mGszDqH5 for ; Sun, 8 Dec 2019 23:23:58 +1100 (AEDT) Received: by mail-pg1-x52c.google.com with SMTP id k3so5019758pgc.3 for ; Sun, 08 Dec 2019 04:23:58 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=8W+G9puK03/GNQpRCeSkgxlVqQMcp6pFwN5Gu7ZSR6I=; b=jqEIIa4zJfPl88iEgVOEe1SWFhMR+mzQSBksmqgGuSHOCnl2U6VWFRRuWIi55+Kz9K wxqDoOn3nqX/dKKmfBI2lbVpFqfiU7FclmJXCcZJ19y8KpCuuJgtTZj74LkjIe8BYDFf YkfxJ/bec8IWB0IeOWoRWMpTot5lKE5k9OEWsGPvU9z/LA+/+YoMQH99gjqawe0yIE4g W25ZRQGed9nvHJbwsagJorBI4r33My957C2gA3kZozS6Nmibkrp+gkR37zao6m6GiMbk jfM6W8/rRcuikyPvN2uBshPbFc0QNUZofaDR+OchlQHK4HHGSVYmi7HrLjwlf7mRvEFH U4uA== 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=8W+G9puK03/GNQpRCeSkgxlVqQMcp6pFwN5Gu7ZSR6I=; b=toueyFwRaTS3p14TJXXgz37v5FbzESdbdJ1RwCaI7HW+QGF9QzJ+I2w5D8NkRHJmx6 xKsbUuTUO4m0IYvSThU7GCARnQyhNNc8np9qz0A1C2RnLUouwfgA0yxOXHhoxOZpPi6l 4pK0wR/Nbk6IJFf0M1OWKdNvNuCJtc8UWj2TfMSsZzsNs20c4KcZZ5yCzt3A9wpfIrXp RRgh+cEnvzgn4tIv1i6BwFz97pDxuOjOt5Q2R1Nyd9+pbx9OZzXQn4cnP3FtU39hHM5F yrenkU5L9U98qqztm1qD4DSD8FO3NtNCwCzMMi/b6UGtwOm3BbW3aljlbNawMyHzB+1w mXng== X-Gm-Message-State: APjAAAUt+gc3ezrMFnhQ/X1aSgnYzK/wKHckd5o/PvBZ8RxacwzXyqjw cHKDg3nykQOU17ljSwRNmmTV/iZe X-Google-Smtp-Source: APXvYqzh7lZbKNeJgzGBaEQ6Mp/XxcnLVBxF3MbT68lv7BjT0kYrYQqDraRKMBZrqU8kGxfNNqRTQQ== X-Received: by 2002:a63:4416:: with SMTP id r22mr13545033pga.254.1575807834472; Sun, 08 Dec 2019 04:23:54 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.23.51 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:23:54 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:54 +1000 Message-Id: <20191208122312.12837-14-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 13/31] xive: make endian-clean X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Convert xive opal calls, dt construction, and in-memory hardware tables to use explicit endian conversions. Reviewed-by: Cédric Le Goater Signed-off-by: Nicholas Piggin --- hw/xive.c | 389 +++++++++++++++++++++-------------------- include/xive-p9-regs.h | 51 +++--- include/xive-regs.h | 26 +++ include/xive.h | 2 +- 4 files changed, 257 insertions(+), 211 deletions(-) diff --git a/hw/xive.c b/hw/xive.c index 80ab25001..41575dae7 100644 --- a/hw/xive.c +++ b/hw/xive.c @@ -396,7 +396,7 @@ struct xive { /* Indirect END/EQ table. NULL entries are unallocated, count is * the numbre of pointers (ie, sub page placeholders). */ - uint64_t *eq_ind_base; + __be64 *eq_ind_base; uint32_t eq_ind_count; /* EQ allocation bitmap. Each bit represent 8 EQs */ @@ -405,7 +405,7 @@ struct xive { /* Indirect NVT/VP table. NULL entries are unallocated, count is * the numbre of pointers (ie, sub page placeholders). */ - uint64_t *vp_ind_base; + __be64 *vp_ind_base; uint32_t vp_ind_count; /* Pool of donated pages for provisioning indirect EQ and VP pages */ @@ -717,7 +717,7 @@ static struct xive_eq *xive_get_eq(struct xive *x, unsigned int idx) if (idx >= (x->eq_ind_count * EQ_PER_PAGE)) return NULL; - p = (struct xive_eq *)(x->eq_ind_base[idx / EQ_PER_PAGE] & + p = (struct xive_eq *)(be64_to_cpu(x->eq_ind_base[idx / EQ_PER_PAGE]) & VSD_ADDRESS_MASK); if (!p) return NULL; @@ -749,7 +749,7 @@ static struct xive_ive *xive_get_ive(struct xive *x, unsigned int isn) /* If using single-escalation, don't let anybody get to the individual * esclation interrupts */ - if (eq->w0 & EQ_W0_UNCOND_ESCALATE) + if (xive_get_field32(EQ_W0_UNCOND_ESCALATE, eq->w0)) return NULL; /* Grab the buried IVE */ @@ -777,7 +777,7 @@ static struct xive_vp *xive_get_vp(struct xive *x, unsigned int idx) struct xive_vp *p; assert(idx < (x->vp_ind_count * VP_PER_PAGE)); - p = (struct xive_vp *)(x->vp_ind_base[idx / VP_PER_PAGE] & + p = (struct xive_vp *)(be64_to_cpu(x->vp_ind_base[idx / VP_PER_PAGE]) & VSD_ADDRESS_MASK); if (!p) return NULL; @@ -791,8 +791,8 @@ static void xive_init_default_vp(struct xive_vp *vp, memset(vp, 0, sizeof(struct xive_vp)); /* Stash the EQ base in the pressure relief interrupt field */ - vp->w1 = (eq_blk << 28) | eq_idx; - vp->w0 = VP_W0_VALID; + vp->w1 = cpu_to_be32((eq_blk << 28) | eq_idx); + vp->w0 = xive_set_field32(VP_W0_VALID, 0, 1); } static void xive_init_emu_eq(uint32_t vp_blk, uint32_t vp_idx, @@ -801,19 +801,20 @@ static void xive_init_emu_eq(uint32_t vp_blk, uint32_t vp_idx, { memset(eq, 0, sizeof(struct xive_eq)); - eq->w1 = EQ_W1_GENERATION; - eq->w3 = ((uint64_t)backing_page) & EQ_W3_OP_DESC_LO; - eq->w2 = (((uint64_t)backing_page) >> 32) & EQ_W2_OP_DESC_HI; - - eq->w6 = SETFIELD(EQ_W6_NVT_BLOCK, 0ul, vp_blk) | - SETFIELD(EQ_W6_NVT_INDEX, 0ul, vp_idx); - eq->w7 = SETFIELD(EQ_W7_F0_PRIORITY, 0ul, prio); - eq->w0 = EQ_W0_VALID | EQ_W0_ENQUEUE | - SETFIELD(EQ_W0_QSIZE, 0ul, EQ_QSIZE_64K) | - EQ_W0_FIRMWARE; + eq->w1 = xive_set_field32(EQ_W1_GENERATION, 0, 1); + eq->w3 = cpu_to_be32(((uint64_t)backing_page) & EQ_W3_OP_DESC_LO); + eq->w2 = cpu_to_be32((((uint64_t)backing_page) >> 32) & EQ_W2_OP_DESC_HI); + eq->w6 = xive_set_field32(EQ_W6_NVT_BLOCK, 0, vp_blk) | + xive_set_field32(EQ_W6_NVT_INDEX, 0, vp_idx); + eq->w7 = xive_set_field32(EQ_W7_F0_PRIORITY, 0, prio); + eq->w0 = xive_set_field32(EQ_W0_VALID, 0, 1) | + xive_set_field32(EQ_W0_ENQUEUE, 0, 1) | + xive_set_field32(EQ_W0_FIRMWARE, 0, 1) | + xive_set_field32(EQ_W0_QSIZE, 0, EQ_QSIZE_64K) | #ifdef EQ_ALWAYS_NOTIFY - eq->w0 |= EQ_W0_UCOND_NOTIFY; + xive_set_field32(EQ_W0_UCOND_NOTIFY, 0, 1) | #endif + 0 ; } static uint32_t *xive_get_eq_buf(uint32_t eq_blk, uint32_t eq_idx) @@ -825,8 +826,8 @@ static uint32_t *xive_get_eq_buf(uint32_t eq_blk, uint32_t eq_idx) assert(x); eq = xive_get_eq(x, eq_idx); assert(eq); - assert(eq->w0 & EQ_W0_VALID); - addr = (((uint64_t)eq->w2) & 0x0fffffff) << 32 | eq->w3; + assert(xive_get_field32(EQ_W0_VALID, eq->w0)); + addr = ((((uint64_t)be32_to_cpu(eq->w2)) & 0x0fffffff) << 32) | be32_to_cpu(eq->w3); return (uint32_t *)addr; } @@ -895,8 +896,8 @@ static uint32_t xive_alloc_eq_set(struct xive *x, bool alloc_indirect) } } memset(page, 0, 0x10000); - x->eq_ind_base[ind_idx] = vsd_flags | - (((uint64_t)page) & VSD_ADDRESS_MASK); + x->eq_ind_base[ind_idx] = cpu_to_be64(vsd_flags | + (((uint64_t)page) & VSD_ADDRESS_MASK)); /* Any cache scrub needed ? */ } @@ -942,7 +943,7 @@ static bool xive_provision_vp_ind(struct xive *x, uint32_t vp_idx, uint32_t orde vsd = ((uint64_t)page) & VSD_ADDRESS_MASK; vsd |= SETFIELD(VSD_TSIZE, 0ull, 4); vsd |= SETFIELD(VSD_MODE, 0ull, VSD_MODE_EXCLUSIVE); - x->vp_ind_base[i] = vsd; + x->vp_ind_base[i] = cpu_to_be64(vsd); } return true; } @@ -1041,7 +1042,7 @@ enum xive_cache_type { static int64_t __xive_cache_watch(struct xive *x, enum xive_cache_type ctype, uint64_t block, uint64_t idx, uint32_t start_dword, uint32_t dword_count, - uint64_t *new_data, bool light_watch, + __be64 *new_data, bool light_watch, bool synchronous); static void xive_scrub_workaround_vp(struct xive *x, uint32_t block, uint32_t idx __unused) @@ -1196,7 +1197,7 @@ static int64_t xive_eqc_scrub(struct xive *x, uint64_t block, uint64_t idx) static int64_t __xive_cache_watch(struct xive *x, enum xive_cache_type ctype, uint64_t block, uint64_t idx, uint32_t start_dword, uint32_t dword_count, - uint64_t *new_data, bool light_watch, + __be64 *new_data, bool light_watch, bool synchronous) { uint64_t sreg, sregx, dreg0, dreg0x; @@ -1249,7 +1250,7 @@ static int64_t __xive_cache_watch(struct xive *x, enum xive_cache_type ctype, * one written. */ for (i = start_dword + dword_count - 1; i >= start_dword ;i--) { - uint64_t dw = new_data[i - start_dword]; + uint64_t dw = be64_to_cpu(new_data[i - start_dword]); __xive_regw(x, dreg0 + i * 8, dreg0x + i, dw, NULL); } @@ -1296,7 +1297,7 @@ static int64_t xive_eqc_cache_update(struct xive *x, uint64_t block, bool synchronous) { return __xive_cache_watch(x, xive_cache_eqc, block, idx, - 0, 4, (uint64_t *)eq, false, synchronous); + 0, 4, (__be64 *)eq, false, synchronous); } static int64_t xive_vpc_cache_update(struct xive *x, uint64_t block, @@ -1304,7 +1305,7 @@ static int64_t xive_vpc_cache_update(struct xive *x, uint64_t block, bool synchronous) { return __xive_cache_watch(x, xive_cache_vpc, block, idx, - 0, 8, (uint64_t *)vp, false, synchronous); + 0, 8, (__be64 *)vp, false, synchronous); } static bool xive_set_vsd(struct xive *x, uint32_t tbl, uint32_t idx, uint64_t v) @@ -1690,7 +1691,7 @@ static bool xive_prealloc_tables(struct xive *x) vsd |= SETFIELD(VSD_TSIZE, 0ull, 4); vsd |= SETFIELD(VSD_MODE, 0ull, VSD_MODE_EXCLUSIVE); vsd |= VSD_FIRMWARE; - x->vp_ind_base[i] = vsd; + x->vp_ind_base[i] = cpu_to_be64(vsd); } /* Allocate the queue overflow pages */ @@ -1704,7 +1705,7 @@ static bool xive_prealloc_tables(struct xive *x) static void xive_add_provisioning_properties(void) { - uint32_t chips[XIVE_MAX_CHIPS]; + __be32 chips[XIVE_MAX_CHIPS]; uint32_t i, count; dt_add_property_cells(xive_dt_node, @@ -1712,7 +1713,7 @@ static void xive_add_provisioning_properties(void) count = 1 << xive_chips_alloc_bits; for (i = 0; i < count; i++) - chips[i] = xive_block_to_chip[i]; + chips[i] = cpu_to_be32(xive_block_to_chip[i]); dt_add_property(xive_dt_node, "ibm,xive-provision-chips", chips, 4 * count); } @@ -1837,7 +1838,9 @@ uint32_t xive_alloc_hw_irqs(uint32_t chip_id, uint32_t count, uint32_t align) for (i = 0; i < count; i++) { struct xive_ive *ive = xive_get_ive(x, base + i); - ive->w = IVE_VALID | IVE_MASKED | SETFIELD(IVE_EQ_DATA, 0ul, base + i); + ive->w = xive_set_field64(IVE_VALID, 0ul, 1) | + xive_set_field64(IVE_MASKED, 0ul, 1) | + xive_set_field64(IVE_EQ_DATA, 0ul, base + i); } unlock(&x->lock); @@ -1883,8 +1886,9 @@ uint32_t xive_alloc_ipi_irqs(uint32_t chip_id, uint32_t count, uint32_t align) for (i = 0; i < count; i++) { struct xive_ive *ive = xive_get_ive(x, base + i); - ive->w = IVE_VALID | IVE_MASKED | - SETFIELD(IVE_EQ_DATA, 0ul, base + i); + ive->w = xive_set_field64(IVE_VALID, 0ul, 1) | + xive_set_field64(IVE_MASKED, 0ul, 1) | + xive_set_field64(IVE_EQ_DATA, 0ul, base + i); } unlock(&x->lock); @@ -2020,17 +2024,17 @@ static bool xive_get_irq_targetting(uint32_t isn, uint32_t *out_target, ive = xive_get_ive(x, isn); if (!ive) return false; - if (!(ive->w & IVE_VALID) && !is_escalation) { + if (!xive_get_field64(IVE_VALID, ive->w) && !is_escalation) { xive_err(x, "ISN %x lead to invalid IVE !\n", isn); return false; } if (out_lirq) - *out_lirq = GETFIELD(IVE_EQ_DATA, ive->w); + *out_lirq = xive_get_field64(IVE_EQ_DATA, ive->w); /* Find the EQ and its xive instance */ - eq_blk = GETFIELD(IVE_EQ_BLOCK, ive->w); - eq_idx = GETFIELD(IVE_EQ_INDEX, ive->w); + eq_blk = xive_get_field64(IVE_EQ_BLOCK, ive->w); + eq_idx = xive_get_field64(IVE_EQ_INDEX, ive->w); eq_x = xive_from_vc_blk(eq_blk); /* This can fail if the interrupt hasn't been initialized yet @@ -2045,15 +2049,15 @@ static bool xive_get_irq_targetting(uint32_t isn, uint32_t *out_target, /* XXX Check valid and format 0 */ /* No priority conversion, return the actual one ! */ - if (ive->w & IVE_MASKED) + if (xive_get_field64(IVE_MASKED, ive->w)) prio = 0xff; else - prio = GETFIELD(EQ_W7_F0_PRIORITY, eq->w7); + prio = xive_get_field32(EQ_W7_F0_PRIORITY, eq->w7); if (out_prio) *out_prio = prio; - vp_blk = GETFIELD(EQ_W6_NVT_BLOCK, eq->w6); - vp_idx = GETFIELD(EQ_W6_NVT_INDEX, eq->w6); + vp_blk = xive_get_field32(EQ_W6_NVT_BLOCK, eq->w6); + vp_idx = xive_get_field32(EQ_W6_NVT_INDEX, eq->w6); server = VP2PIR(vp_blk, vp_idx); if (out_target) @@ -2103,8 +2107,8 @@ static inline bool xive_eq_for_target(uint32_t target, uint8_t prio, /* Grab it, it's in the pressure relief interrupt field, * top 4 bits are the block (word 1). */ - eq_blk = vp->w1 >> 28; - eq_idx = vp->w1 & 0x0fffffff; + eq_blk = be32_to_cpu(vp->w1) >> 28; + eq_idx = be32_to_cpu(vp->w1) & 0x0fffffff; /* Currently the EQ block and VP block should be the same */ if (eq_blk != vp_blk) { @@ -2139,7 +2143,7 @@ static int64_t xive_set_irq_targetting(uint32_t isn, uint32_t target, ive = xive_get_ive(x, isn); if (!ive) return OPAL_PARAMETER; - if (!(ive->w & IVE_VALID) && !is_escalation) { + if (!xive_get_field64(IVE_VALID, ive->w) && !is_escalation) { xive_err(x, "ISN %x lead to invalid IVE !\n", isn); return OPAL_PARAMETER; } @@ -2155,14 +2159,14 @@ static int64_t xive_set_irq_targetting(uint32_t isn, uint32_t target, /* Are we masking ? */ if (prio == 0xff && !is_escalation) { - new_ive.w |= IVE_MASKED; + new_ive.w = xive_set_field64(IVE_MASKED, new_ive.w, 1); xive_vdbg(x, "ISN %x masked !\n", isn); /* Put prio 7 in the EQ */ prio = XIVE_MAX_PRIO; } else { /* Unmasking */ - new_ive.w &= ~IVE_MASKED; + new_ive.w = xive_set_field64(IVE_MASKED, new_ive.w, 0); xive_vdbg(x, "ISN %x unmasked !\n", isn); /* For normal interrupt sources, keep track of which ones @@ -2186,13 +2190,13 @@ static int64_t xive_set_irq_targetting(uint32_t isn, uint32_t target, /* Try to update it atomically to avoid an intermediary * stale state */ - new_ive.w = SETFIELD(IVE_EQ_BLOCK, new_ive.w, eq_blk); - new_ive.w = SETFIELD(IVE_EQ_INDEX, new_ive.w, eq_idx); + new_ive.w = xive_set_field64(IVE_EQ_BLOCK, new_ive.w, eq_blk); + new_ive.w = xive_set_field64(IVE_EQ_INDEX, new_ive.w, eq_idx); } - new_ive.w = SETFIELD(IVE_EQ_DATA, new_ive.w, lirq); + new_ive.w = xive_set_field64(IVE_EQ_DATA, new_ive.w, lirq); xive_vdbg(x,"ISN %x routed to eq %x/%x lirq=%08x IVE=%016llx !\n", - isn, eq_blk, eq_idx, lirq, new_ive.w); + isn, eq_blk, eq_idx, lirq, be64_to_cpu(new_ive.w)); /* Updating the cache differs between real IVEs and escalation * IVEs inside an EQ @@ -2394,7 +2398,7 @@ static void __xive_source_eoi(struct irq_source *is, uint32_t isn) */ /* If it's invalid or masked, don't do anything */ - if ((ive->w & IVE_MASKED) || !(ive->w & IVE_VALID)) + if (xive_get_field64(IVE_MASKED, ive->w) || !xive_get_field64(IVE_VALID, ive->w)) return; /* Grab MMIO control address for that ESB */ @@ -2761,13 +2765,17 @@ static bool xive_check_eq_update(struct xive *x, uint32_t idx, struct xive_eq *e if (memcmp(eq, &eq2, sizeof(struct xive_eq)) != 0) { xive_err(x, "EQ update mismatch idx %d\n", idx); xive_err(x, "want: %08x %08x %08x %08x\n", - eq->w0, eq->w1, eq->w2, eq->w3); + be32_to_cpu(eq->w0), be32_to_cpu(eq->w1), + be32_to_cpu(eq->w2), be32_to_cpu(eq->w3)); xive_err(x, " %08x %08x %08x %08x\n", - eq->w4, eq->w5, eq->w6, eq->w7); + be32_to_cpu(eq->w4), be32_to_cpu(eq->w5), + be32_to_cpu(eq->w6), be32_to_cpu(eq->w7)); xive_err(x, "got : %08x %08x %08x %08x\n", - eq2.w0, eq2.w1, eq2.w2, eq2.w3); + be32_to_cpu(eq2.w0), be32_to_cpu(eq2.w1), + be32_to_cpu(eq2.w2), be32_to_cpu(eq2.w3)); xive_err(x, " %08x %08x %08x %08x\n", - eq2.w4, eq2.w5, eq2.w6, eq2.w7); + be32_to_cpu(eq2.w4), be32_to_cpu(eq2.w5), + be32_to_cpu(eq2.w6), be32_to_cpu(eq2.w7)); return false; } return true; @@ -2783,13 +2791,17 @@ static bool xive_check_vpc_update(struct xive *x, uint32_t idx, struct xive_vp * if (memcmp(vp, &vp2, sizeof(struct xive_vp)) != 0) { xive_err(x, "VP update mismatch idx %d\n", idx); xive_err(x, "want: %08x %08x %08x %08x\n", - vp->w0, vp->w1, vp->w2, vp->w3); + be32_to_cpu(vp->w0), be32_to_cpu(vp->w1), + be32_to_cpu(vp->w2), be32_to_cpu(vp->w3)); xive_err(x, " %08x %08x %08x %08x\n", - vp->w4, vp->w5, vp->w6, vp->w7); + be32_to_cpu(vp->w4), be32_to_cpu(vp->w5), + be32_to_cpu(vp->w6), be32_to_cpu(vp->w7)); xive_err(x, "got : %08x %08x %08x %08x\n", - vp2.w0, vp2.w1, vp2.w2, vp2.w3); + be32_to_cpu(vp2.w0), be32_to_cpu(vp2.w1), + be32_to_cpu(vp2.w2), be32_to_cpu(vp2.w3)); xive_err(x, " %08x %08x %08x %08x\n", - vp2.w4, vp2.w5, vp2.w6, vp2.w7); + be32_to_cpu(vp2.w4), be32_to_cpu(vp2.w5), + be32_to_cpu(vp2.w6), be32_to_cpu(vp2.w7)); return false; } return true; @@ -2821,7 +2833,7 @@ static void xive_special_cache_check(struct xive *x, uint32_t blk, uint32_t idx) memset(vp_m, (~i) & 0xff, sizeof(*vp_m)); sync(); - vp.w1 = (i << 16) | i; + vp.w1 = cpu_to_be32((i << 16) | i); xive_vpc_cache_update(x, blk, idx, &vp, true); if (!xive_check_vpc_update(x, idx, &vp)) { xive_dbg(x, "Test failed at %d iterations\n", i); @@ -3065,7 +3077,7 @@ static void xive_init_cpu(struct cpu_thread *c) static void xive_init_cpu_properties(struct cpu_thread *cpu) { struct cpu_thread *t; - uint32_t iprop[8][2] = { }; + __be32 iprop[8][2] = { }; uint32_t i; assert(cpu_thread_count <= 8); @@ -3076,7 +3088,7 @@ static void xive_init_cpu_properties(struct cpu_thread *cpu) t = (i == 0) ? cpu : find_cpu_by_pir(cpu->pir + i); if (!t) continue; - iprop[i][0] = t->xstate->ipi_irq; + iprop[i][0] = cpu_to_be32(t->xstate->ipi_irq); iprop[i][1] = 0; /* Edge */ } dt_add_property(cpu->node, "interrupts", iprop, cpu_thread_count * 8); @@ -3147,7 +3159,7 @@ static uint32_t xive_read_eq(struct xive_cpu_state *xs, bool just_peek) unlock(&xs->xive->lock); eq = xive_get_eq(xs->xive, xs->eq_idx + XIVE_EMULATION_PRIO); prerror("EQ @%p W0=%08x W1=%08x qbuf @%p\n", - eq, eq->w0, eq->w1, xs->eqbuf); + eq, be32_to_cpu(eq->w0), be32_to_cpu(eq->w1), xs->eqbuf); } log_add(xs, LOG_TYPE_POPQ, 7, cur, xs->eqbuf[(xs->eqptr + 1) & xs->eqmsk], @@ -3364,20 +3376,20 @@ static bool check_misrouted_ipi(struct cpu_thread *me, uint32_t irq) xive_cpu_err(me, "no ive attached\n"); return true; } - xive_cpu_err(me, "ive=%016llx\n", ive->w); + xive_cpu_err(me, "ive=%016llx\n", be64_to_cpu(ive->w)); for_each_chip(chip) { x = chip->xive; if (!x) continue; ive = x->ivt_base; for (i = 0; i < MAX_INT_ENTRIES; i++) { - if ((ive[i].w & IVE_EQ_DATA) == irq) { - eq_blk = GETFIELD(IVE_EQ_BLOCK, ive[i].w); - eq_idx = GETFIELD(IVE_EQ_INDEX, ive[i].w); + if (xive_get_field64(IVE_EQ_DATA, ive[i].w) == irq) { + eq_blk = xive_get_field64(IVE_EQ_BLOCK, ive[i].w); + eq_idx = xive_get_field64(IVE_EQ_INDEX, ive[i].w); xive_cpu_err(me, "Found source: 0x%x ive=%016llx\n" " eq 0x%x/%x", BLKIDX_TO_GIRQ(x->block_id, i), - ive[i].w, eq_blk, eq_idx); + be64_to_cpu(ive[i].w), eq_blk, eq_idx); xive_dump_eq(eq_blk, eq_idx); } } @@ -3395,7 +3407,7 @@ static inline bool check_misrouted_ipi(struct cpu_thread *c __unused, } #endif -static int64_t opal_xive_get_xirr(uint32_t *out_xirr, bool just_poll) +static int64_t opal_xive_get_xirr(__be32 *out_xirr, bool just_poll) { struct cpu_thread *c = this_cpu(); struct xive_cpu_state *xs = c->xstate; @@ -3479,7 +3491,7 @@ static int64_t opal_xive_get_xirr(uint32_t *out_xirr, bool just_poll) false, false); unlock(&xs->xive->lock); eq = xive_get_eq(xs->xive, xs->eq_idx + XIVE_EMULATION_PRIO); - log_add(xs, LOG_TYPE_EQD, 2, eq->w0, eq->w1); + log_add(xs, LOG_TYPE_EQD, 2, be32_to_cpu(eq->w0), be32_to_cpu(eq->w1)); } #endif /* XIVE_PERCPU_LOG */ @@ -3502,7 +3514,7 @@ static int64_t opal_xive_get_xirr(uint32_t *out_xirr, bool just_poll) if (check_misrouted_ipi(c, val)) val = 2; - *out_xirr = (old_cppr << 24) | val; + *out_xirr = cpu_to_be32((old_cppr << 24) | val); /* If we are polling, that's it */ if (just_poll) @@ -3539,9 +3551,9 @@ static int64_t opal_xive_get_xirr(uint32_t *out_xirr, bool just_poll) skip: log_add(xs, LOG_TYPE_XIRR2, 5, xs->cppr, xs->pending, - *out_xirr, xs->eqptr, xs->eqgen); + be32_to_cpu(*out_xirr), xs->eqptr, xs->eqgen); xive_cpu_vdbg(c, " returning XIRR=%08x, pending=0x%x\n", - *out_xirr, xs->pending); + be32_to_cpu(*out_xirr), xs->pending); unlock(&xs->lock); @@ -3615,11 +3627,11 @@ static uint64_t xive_convert_irq_flags(uint64_t iflags) } static int64_t opal_xive_get_irq_info(uint32_t girq, - uint64_t *out_flags, - uint64_t *out_eoi_page, - uint64_t *out_trig_page, - uint32_t *out_esb_shift, - uint32_t *out_src_chip) + __be64 *out_flags, + __be64 *out_eoi_page, + __be64 *out_trig_page, + __be32 *out_esb_shift, + __be32 *out_src_chip) { struct irq_source *is = irq_find_source(girq); struct xive_src *s = container_of(is, struct xive_src, is); @@ -3634,12 +3646,12 @@ static int64_t opal_xive_get_irq_info(uint32_t girq, assert(is->ops == &xive_irq_source_ops); if (out_flags) - *out_flags = xive_convert_irq_flags(s->flags); + *out_flags = cpu_to_be64(xive_convert_irq_flags(s->flags)); idx = girq - s->esb_base; if (out_esb_shift) - *out_esb_shift = s->esb_shift; + *out_esb_shift = cpu_to_be32(s->esb_shift); mm_base = (uint64_t)s->esb_mmio + (1ull << s->esb_shift) * idx; @@ -3655,27 +3667,31 @@ static int64_t opal_xive_get_irq_info(uint32_t girq, trig_page = mm_base; if (out_eoi_page) - *out_eoi_page = eoi_page; + *out_eoi_page = cpu_to_be64(eoi_page); if (out_trig_page) - *out_trig_page = trig_page; + *out_trig_page = cpu_to_be64(trig_page); if (out_src_chip) - *out_src_chip = GIRQ_TO_CHIP(girq); + *out_src_chip = cpu_to_be32(GIRQ_TO_CHIP(girq)); return OPAL_SUCCESS; } static int64_t opal_xive_get_irq_config(uint32_t girq, - uint64_t *out_vp, + __be64 *out_vp, uint8_t *out_prio, - uint32_t *out_lirq) + __be32 *out_lirq) { uint32_t vp; + uint32_t lirq; + uint8_t prio; if (xive_mode != XIVE_MODE_EXPL) return OPAL_WRONG_STATE; - if (xive_get_irq_targetting(girq, &vp, out_prio, out_lirq)) { - *out_vp = vp; + if (xive_get_irq_targetting(girq, &vp, &prio, &lirq)) { + *out_vp = cpu_to_be64(vp); + *out_prio = prio; + *out_lirq = cpu_to_be32(lirq); return OPAL_SUCCESS; } else return OPAL_PARAMETER; @@ -3706,11 +3722,11 @@ static int64_t opal_xive_set_irq_config(uint32_t girq, } static int64_t opal_xive_get_queue_info(uint64_t vp, uint32_t prio, - uint64_t *out_qpage, - uint64_t *out_qsize, - uint64_t *out_qeoi_page, - uint32_t *out_escalate_irq, - uint64_t *out_qflags) + __be64 *out_qpage, + __be64 *out_qsize, + __be64 *out_qeoi_page, + __be32 *out_escalate_irq, + __be64 *out_qflags) { uint32_t blk, idx; struct xive *x; @@ -3736,16 +3752,17 @@ static int64_t opal_xive_get_queue_info(uint64_t vp, uint32_t prio, /* If escalations are routed to a single queue, fix up * the escalation interrupt number here. */ - if (eq->w0 & EQ_W0_UNCOND_ESCALATE) + if (xive_get_field32(EQ_W0_UNCOND_ESCALATE, eq->w0)) esc_idx |= XIVE_ESCALATION_PRIO; + *out_escalate_irq = - MAKE_ESCALATION_GIRQ(blk, esc_idx); + cpu_to_be32(MAKE_ESCALATION_GIRQ(blk, esc_idx)); } /* If this is a single-escalation gather queue, that's all * there is to return */ - if (eq->w0 & EQ_W0_SILENT_ESCALATE) { + if (xive_get_field32(EQ_W0_SILENT_ESCALATE, eq->w0)) { if (out_qflags) *out_qflags = 0; if (out_qpage) @@ -3758,30 +3775,29 @@ static int64_t opal_xive_get_queue_info(uint64_t vp, uint32_t prio, } if (out_qpage) { - if (eq->w0 & EQ_W0_ENQUEUE) - *out_qpage = - (((uint64_t)(eq->w2 & EQ_W2_OP_DESC_HI)) << 32) | eq->w3; + if (xive_get_field32(EQ_W0_ENQUEUE, eq->w0)) + *out_qpage = cpu_to_be64(((uint64_t)xive_get_field32(EQ_W2_OP_DESC_HI, eq->w2) << 32) | be32_to_cpu(eq->w3)); else *out_qpage = 0; } if (out_qsize) { - if (eq->w0 & EQ_W0_ENQUEUE) - *out_qsize = GETFIELD(EQ_W0_QSIZE, eq->w0) + 12; + if (xive_get_field32(EQ_W0_ENQUEUE, eq->w0)) + *out_qsize = cpu_to_be64(xive_get_field32(EQ_W0_QSIZE, eq->w0) + 12); else *out_qsize = 0; } if (out_qeoi_page) { *out_qeoi_page = - (uint64_t)x->eq_mmio + idx * 0x20000; + cpu_to_be64((uint64_t)x->eq_mmio + idx * 0x20000); } if (out_qflags) { *out_qflags = 0; - if (eq->w0 & EQ_W0_VALID) - *out_qflags |= OPAL_XIVE_EQ_ENABLED; - if (eq->w0 & EQ_W0_UCOND_NOTIFY) - *out_qflags |= OPAL_XIVE_EQ_ALWAYS_NOTIFY; - if (eq->w0 & EQ_W0_ESCALATE_CTL) - *out_qflags |= OPAL_XIVE_EQ_ESCALATE; + if (xive_get_field32(EQ_W0_VALID, eq->w0)) + *out_qflags |= cpu_to_be64(OPAL_XIVE_EQ_ENABLED); + if (xive_get_field32(EQ_W0_UCOND_NOTIFY, eq->w0)) + *out_qflags |= cpu_to_be64(OPAL_XIVE_EQ_ALWAYS_NOTIFY); + if (xive_get_field32(EQ_W0_ESCALATE_CTL, eq->w0)) + *out_qflags |= cpu_to_be64(OPAL_XIVE_EQ_ESCALATE); } return OPAL_SUCCESS; @@ -3789,8 +3805,8 @@ static int64_t opal_xive_get_queue_info(uint64_t vp, uint32_t prio, static void xive_cleanup_eq(struct xive_eq *eq) { - eq->w0 = eq->w0 & EQ_W0_FIRMWARE; - eq->w1 = EQ_W1_ESe_Q | EQ_W1_ESn_Q; + eq->w0 = xive_set_field32(EQ_W0_FIRMWARE, 0, xive_get_field32(EQ_W0_FIRMWARE, eq->w0)); + eq->w1 = cpu_to_be32(EQ_W1_ESe_Q | EQ_W1_ESn_Q); eq->w2 = eq->w3 = eq->w4 = eq->w5 = eq->w6 = eq->w7 = 0; } @@ -3823,7 +3839,7 @@ static int64_t opal_xive_set_queue_info(uint64_t vp, uint32_t prio, /* If this is a silent escalation queue, it cannot be * configured directly */ - if (old_eq->w0 & EQ_W0_SILENT_ESCALATE) + if (xive_get_field32(EQ_W0_SILENT_ESCALATE, old_eq->w0)) return OPAL_PARAMETER; /* This shouldn't fail or xive_eq_for_target would have @@ -3845,14 +3861,14 @@ static int64_t opal_xive_set_queue_info(uint64_t vp, uint32_t prio, case 16: case 21: case 24: - eq.w3 = ((uint64_t)qpage) & EQ_W3_OP_DESC_LO; - eq.w2 = (((uint64_t)qpage) >> 32) & EQ_W2_OP_DESC_HI; - eq.w0 |= EQ_W0_ENQUEUE; - eq.w0 = SETFIELD(EQ_W0_QSIZE, eq.w0, qsize - 12); + eq.w3 = cpu_to_be32(((uint64_t)qpage) & EQ_W3_OP_DESC_LO); + eq.w2 = cpu_to_be32((((uint64_t)qpage) >> 32) & EQ_W2_OP_DESC_HI); + eq.w0 = xive_set_field32(EQ_W0_ENQUEUE, eq.w0, 1); + eq.w0 = xive_set_field32(EQ_W0_QSIZE, eq.w0, qsize - 12); break; case 0: eq.w2 = eq.w3 = 0; - eq.w0 &= ~EQ_W0_ENQUEUE; + eq.w0 = xive_set_field32(EQ_W0_ENQUEUE, eq.w0, 0); break; default: return OPAL_PARAMETER; @@ -3861,34 +3877,34 @@ static int64_t opal_xive_set_queue_info(uint64_t vp, uint32_t prio, /* Ensure the priority and target are correctly set (they will * not be right after allocation */ - eq.w6 = SETFIELD(EQ_W6_NVT_BLOCK, 0ul, vp_blk) | - SETFIELD(EQ_W6_NVT_INDEX, 0ul, vp_idx); - eq.w7 = SETFIELD(EQ_W7_F0_PRIORITY, 0ul, prio); + eq.w6 = xive_set_field32(EQ_W6_NVT_BLOCK, 0, vp_blk) | + xive_set_field32(EQ_W6_NVT_INDEX, 0, vp_idx); + eq.w7 = xive_set_field32(EQ_W7_F0_PRIORITY, 0, prio); /* XXX Handle group i bit when needed */ /* Always notify flag */ if (qflags & OPAL_XIVE_EQ_ALWAYS_NOTIFY) - eq.w0 |= EQ_W0_UCOND_NOTIFY; + eq.w0 = xive_set_field32(EQ_W0_UCOND_NOTIFY, eq.w0, 1); else - eq.w0 &= ~EQ_W0_UCOND_NOTIFY; + eq.w0 = xive_set_field32(EQ_W0_UCOND_NOTIFY, eq.w0, 0); /* Escalation flag */ if (qflags & OPAL_XIVE_EQ_ESCALATE) - eq.w0 |= EQ_W0_ESCALATE_CTL; + eq.w0 = xive_set_field32(EQ_W0_ESCALATE_CTL, eq.w0, 1); else - eq.w0 &= ~EQ_W0_ESCALATE_CTL; + eq.w0 = xive_set_field32(EQ_W0_ESCALATE_CTL, eq.w0, 0); /* Unconditionally clear the current queue pointer, set * generation to 1 and disable escalation interrupts. */ - eq.w1 = EQ_W1_GENERATION | - (old_eq->w1 & (EQ_W1_ESe_P | EQ_W1_ESe_Q | - EQ_W1_ESn_P | EQ_W1_ESn_Q)); + eq.w1 = xive_set_field32(EQ_W1_GENERATION, 0, 1) | + xive_set_field32(EQ_W1_ES, 0, xive_get_field32(EQ_W1_ES, old_eq->w1)); /* Enable. We always enable backlog for an enabled queue * otherwise escalations won't work. */ - eq.w0 |= EQ_W0_VALID | EQ_W0_BACKLOG; + eq.w0 = xive_set_field32(EQ_W0_VALID, eq.w0, 1); + eq.w0 = xive_set_field32(EQ_W0_BACKLOG, eq.w0, 1); } else xive_cleanup_eq(&eq); @@ -3901,8 +3917,8 @@ static int64_t opal_xive_set_queue_info(uint64_t vp, uint32_t prio, } static int64_t opal_xive_get_queue_state(uint64_t vp, uint32_t prio, - uint32_t *out_qtoggle, - uint32_t *out_qindex) + __be32 *out_qtoggle, + __be32 *out_qindex) { uint32_t blk, idx; struct xive *x; @@ -3932,11 +3948,11 @@ static int64_t opal_xive_get_queue_state(uint64_t vp, uint32_t prio, return rc; /* We don't do disable queues */ - if (!(eq->w0 & EQ_W0_VALID)) + if (!xive_get_field32(EQ_W0_VALID, eq->w0)) return OPAL_WRONG_STATE; - *out_qtoggle = GETFIELD(EQ_W1_GENERATION, eq->w1); - *out_qindex = GETFIELD(EQ_W1_PAGE_OFF, eq->w1); + *out_qtoggle = cpu_to_be32(xive_get_field32(EQ_W1_GENERATION, eq->w1)); + *out_qindex = cpu_to_be32(xive_get_field32(EQ_W1_PAGE_OFF, eq->w1)); return OPAL_SUCCESS; } @@ -3964,13 +3980,13 @@ static int64_t opal_xive_set_queue_state(uint64_t vp, uint32_t prio, return OPAL_PARAMETER; /* We don't do disable queues */ - if (!(eq->w0 & EQ_W0_VALID)) + if (!xive_get_field32(EQ_W0_VALID, eq->w0)) return OPAL_WRONG_STATE; new_eq = *eq; - new_eq.w1 = SETFIELD(EQ_W1_GENERATION, new_eq.w1, qtoggle); - new_eq.w1 = SETFIELD(EQ_W1_PAGE_OFF, new_eq.w1, qindex); + new_eq.w1 = xive_set_field32(EQ_W1_GENERATION, new_eq.w1, qtoggle); + new_eq.w1 = xive_set_field32(EQ_W1_PAGE_OFF, new_eq.w1, qindex); lock(&x->lock); rc = xive_eqc_cache_update(x, blk, idx, &new_eq, false); @@ -4002,10 +4018,10 @@ static int64_t opal_xive_donate_page(uint32_t chip_id, uint64_t addr) } static int64_t opal_xive_get_vp_info(uint64_t vp_id, - uint64_t *out_flags, - uint64_t *out_cam_value, - uint64_t *out_report_cl_pair, - uint32_t *out_chip_id) + __be64 *out_flags, + __be64 *out_cam_value, + __be64 *out_report_cl_pair, + __be32 *out_chip_id) { struct xive *x; struct xive_vp *vp; @@ -4048,22 +4064,22 @@ static int64_t opal_xive_get_vp_info(uint64_t vp_id, eq = xive_get_eq(x, eq_idx); if (!eq) return OPAL_PARAMETER; - if (vp->w0 & VP_W0_VALID) - *out_flags |= OPAL_XIVE_VP_ENABLED; - if (eq->w0 & EQ_W0_SILENT_ESCALATE) - *out_flags |= OPAL_XIVE_VP_SINGLE_ESCALATION; + if (xive_get_field32(VP_W0_VALID, vp->w0)) + *out_flags |= cpu_to_be64(OPAL_XIVE_VP_ENABLED); + if (xive_get_field32(EQ_W0_SILENT_ESCALATE, eq->w0)) + *out_flags |= cpu_to_be64(OPAL_XIVE_VP_SINGLE_ESCALATION); } if (out_cam_value) - *out_cam_value = (blk << NVT_SHIFT) | idx; + *out_cam_value = cpu_to_be64((blk << NVT_SHIFT) | idx); if (out_report_cl_pair) { - *out_report_cl_pair = ((uint64_t)(vp->w6 & 0x0fffffff)) << 32; - *out_report_cl_pair |= vp->w7 & 0xffffff00; + *out_report_cl_pair = cpu_to_be64(((uint64_t)(be32_to_cpu(vp->w6) & 0x0fffffff)) << 32); + *out_report_cl_pair |= cpu_to_be64(be32_to_cpu(vp->w7) & 0xffffff00); } if (out_chip_id) - *out_chip_id = xive_block_to_chip[blk]; + *out_chip_id = cpu_to_be32(xive_block_to_chip[blk]); return OPAL_SUCCESS; } @@ -4091,8 +4107,8 @@ static int64_t xive_setup_silent_gather(uint64_t vp_id, bool enable) /* If trying to enable silent gather, make sure prio 7 is not * already enabled as a normal queue */ - if (enable && (eq_orig->w0 & EQ_W0_VALID) && - !(eq_orig->w0 & EQ_W0_SILENT_ESCALATE)) { + if (enable && xive_get_field32(EQ_W0_VALID, eq_orig->w0) && + !xive_get_field32(EQ_W0_SILENT_ESCALATE, eq_orig->w0)) { xive_dbg(x, "Attempt at enabling silent gather but" " prio 7 queue already in use\n"); return OPAL_PARAMETER; @@ -4102,15 +4118,17 @@ static int64_t xive_setup_silent_gather(uint64_t vp_id, bool enable) if (enable) { /* W0: Enabled and "s" set, no other bit */ - eq.w0 &= EQ_W0_FIRMWARE; - eq.w0 |= EQ_W0_VALID | EQ_W0_SILENT_ESCALATE | - EQ_W0_ESCALATE_CTL | EQ_W0_BACKLOG; + eq.w0 = xive_set_field32(EQ_W0_FIRMWARE, 0, xive_get_field32(EQ_W0_FIRMWARE, eq.w0)) | + xive_set_field32(EQ_W0_VALID, 0, 1) | + xive_set_field32(EQ_W0_SILENT_ESCALATE, 0, 1) | + xive_set_field32(EQ_W0_ESCALATE_CTL, 0, 1) | + xive_set_field32(EQ_W0_BACKLOG, 0, 1); /* W1: Mark ESn as 01, ESe as 00 */ - eq.w1 &= ~EQ_W1_ESn_P; - eq.w1 |= EQ_W1_ESn_Q; - eq.w1 &= ~(EQ_W1_ESe); - } else if (eq.w0 & EQ_W0_SILENT_ESCALATE) + eq.w1 = xive_set_field32(EQ_W1_ESn_P, eq.w1, 0); + eq.w1 = xive_set_field32(EQ_W1_ESn_Q, eq.w1, 1); + eq.w1 = xive_set_field32(EQ_W1_ESe, eq.w1, 0); + } else if (xive_get_field32(EQ_W0_SILENT_ESCALATE, eq.w0)) xive_cleanup_eq(&eq); if (!memcmp(eq_orig, &eq, sizeof(eq))) @@ -4132,19 +4150,17 @@ static int64_t xive_setup_silent_gather(uint64_t vp_id, bool enable) eq = *eq_orig; if (enable) { /* Set new "u" bit */ - eq.w0 |= EQ_W0_UNCOND_ESCALATE; + eq.w0 = xive_set_field32(EQ_W0_UNCOND_ESCALATE, eq.w0, 1); /* Re-route escalation interrupt (previous * route is lost !) to the gather queue */ - eq.w4 = SETFIELD(EQ_W4_ESC_EQ_BLOCK, - eq.w4, blk); - eq.w4 = SETFIELD(EQ_W4_ESC_EQ_INDEX, - eq.w4, idx + XIVE_ESCALATION_PRIO); - } else if (eq.w0 & EQ_W0_UNCOND_ESCALATE) { + eq.w4 = xive_set_field32(EQ_W4_ESC_EQ_BLOCK, eq.w4, blk); + eq.w4 = xive_set_field32(EQ_W4_ESC_EQ_INDEX, eq.w4, idx + XIVE_ESCALATION_PRIO); + } else if (xive_get_field32(EQ_W0_UNCOND_ESCALATE, eq.w0)) { /* Clear the "u" bit, disable escalations if it was set */ - eq.w0 &= ~EQ_W0_UNCOND_ESCALATE; - eq.w0 &= ~EQ_W0_ESCALATE_CTL; + eq.w0 = xive_set_field32(EQ_W0_UNCOND_ESCALATE, eq.w0, 0); + eq.w0 = xive_set_field32(EQ_W0_ESCALATE_CTL, eq.w0, 0); } if (!memcmp(eq_orig, &eq, sizeof(eq))) continue; @@ -4184,9 +4200,9 @@ static int64_t opal_xive_set_vp_info(uint64_t vp_id, vp_new = *vp; if (flags & OPAL_XIVE_VP_ENABLED) { - vp_new.w0 |= VP_W0_VALID; - vp_new.w6 = report_cl_pair >> 32; - vp_new.w7 = report_cl_pair & 0xffffffff; + vp_new.w0 = xive_set_field32(VP_W0_VALID, vp_new.w0, 1); + vp_new.w6 = cpu_to_be32(report_cl_pair >> 32); + vp_new.w7 = cpu_to_be32(report_cl_pair & 0xffffffff); if (flags & OPAL_XIVE_VP_SINGLE_ESCALATION) rc = xive_setup_silent_gather(vp_id, true); @@ -4218,7 +4234,7 @@ bail: return rc; } -static int64_t opal_xive_get_vp_state(uint64_t vp_id, uint64_t *out_state) +static int64_t opal_xive_get_vp_state(uint64_t vp_id, __be64 *out_state) { struct xive *x; struct xive_vp *vp; @@ -4244,14 +4260,14 @@ static int64_t opal_xive_get_vp_state(uint64_t vp_id, uint64_t *out_state) if (rc) return rc; - if (!(vp->w0 & VP_W0_VALID)) + if (!xive_get_field32(VP_W0_VALID, vp->w0)) return OPAL_WRONG_STATE; /* * Return word4 and word5 which contain the saved HW thread * context. The IPB register is all we care for now on P9. */ - *out_state = (((uint64_t)vp->w4) << 32) | vp->w5; + *out_state = cpu_to_be64((((uint64_t)be32_to_cpu(vp->w4)) << 32) | be32_to_cpu(vp->w5)); return OPAL_SUCCESS; } @@ -4340,7 +4356,7 @@ static void xive_cleanup_vp_ind(struct xive *x) xive_dbg(x, "Cleaning up %d VP ind entries...\n", x->vp_ind_count); for (i = 0; i < x->vp_ind_count; i++) { - if (x->vp_ind_base[i] & VSD_FIRMWARE) { + if (be64_to_cpu(x->vp_ind_base[i]) & VSD_FIRMWARE) { xive_dbg(x, " %04x ... skip (firmware)\n", i); continue; } @@ -4358,7 +4374,7 @@ static void xive_cleanup_eq_ind(struct xive *x) xive_dbg(x, "Cleaning up %d EQ ind entries...\n", x->eq_ind_count); for (i = 0; i < x->eq_ind_count; i++) { - if (x->eq_ind_base[i] & VSD_FIRMWARE) { + if (be64_to_cpu(x->eq_ind_base[i]) & VSD_FIRMWARE) { xive_dbg(x, " %04x ... skip (firmware)\n", i); continue; } @@ -4413,15 +4429,15 @@ static void xive_reset_one(struct xive *x) * we will incorrectly free the EQs that are reserved * for the physical CPUs */ - if (eq->w0 & EQ_W0_VALID) { - if (!(eq->w0 & EQ_W0_FIRMWARE)) + if (xive_get_field32(EQ_W0_VALID, eq->w0)) { + if (!xive_get_field32(EQ_W0_FIRMWARE, eq->w0)) xive_dbg(x, "EQ 0x%x:0x%x is valid at reset: %08x %08x\n", - x->block_id, idx, eq->w0, eq->w1); + x->block_id, idx, be32_to_cpu(eq->w0), be32_to_cpu(eq->w1)); eq0 = *eq; xive_cleanup_eq(&eq0); xive_eqc_cache_update(x, x->block_id, idx, &eq0, true); } - if (eq->w0 & EQ_W0_FIRMWARE) + if (xive_get_field32(EQ_W0_FIRMWARE, eq->w0)) eq_firmware = true; } if (!eq_firmware) @@ -4452,7 +4468,7 @@ static void xive_reset_one(struct xive *x) /* Is the VP valid ? */ vp = xive_get_vp(x, i); - if (!vp || !(vp->w0 & VP_W0_VALID)) + if (!vp || !xive_get_field32(VP_W0_VALID, vp->w0)) continue; /* Clear it */ @@ -4621,7 +4637,7 @@ static int64_t opal_xive_free_vp_block(uint64_t vp_base) } /* VP must be disabled */ - if (vp->w0 & VP_W0_VALID) { + if (xive_get_field32(VP_W0_VALID, vp->w0)) { prlog(PR_ERR, "XIVE: freeing active VP %d\n", vp_id); return OPAL_XIVE_FREE_ACTIVE; } @@ -4629,8 +4645,8 @@ static int64_t opal_xive_free_vp_block(uint64_t vp_base) /* Not populated */ if (vp->w1 == 0) continue; - eq_blk = vp->w1 >> 28; - eq_idx = vp->w1 & 0x0fffffff; + eq_blk = be32_to_cpu(vp->w1) >> 28; + eq_idx = be32_to_cpu(vp->w1) & 0x0fffffff; lock(&x->lock); @@ -4641,7 +4657,7 @@ static int64_t opal_xive_free_vp_block(uint64_t vp_base) struct xive *eq_x = xive_from_vc_blk(eq_blk); struct xive_eq eq, *orig_eq = xive_get_eq(eq_x, eq_idx + j); - if (!(orig_eq->w0 & EQ_W0_VALID)) + if (!xive_get_field32(EQ_W0_VALID, orig_eq->w0)) continue; prlog(PR_WARNING, "XIVE: freeing VP %d with queue %d active\n", @@ -4729,7 +4745,7 @@ static int64_t opal_xive_alloc_vp_block(uint32_t alloc_order) * it out of the cache. */ memset(vp, 0, sizeof(*vp)); - vp->w1 = (blk << 28) | eqs; + vp->w1 = cpu_to_be32((blk << 28) | eqs); } return vp_base; fail: @@ -4766,7 +4782,9 @@ static int64_t xive_try_allocate_irq(struct xive *x) unlock(&x->lock); return OPAL_PARAMETER; } - ive->w = IVE_VALID | IVE_MASKED | SETFIELD(IVE_EQ_DATA, 0ul, girq); + ive->w = xive_set_field64(IVE_VALID, 0ul, 1) | + xive_set_field64(IVE_MASKED, 0ul, 1) | + xive_set_field64(IVE_EQ_DATA, 0ul, girq); unlock(&x->lock); return girq; @@ -4835,7 +4853,8 @@ static int64_t opal_xive_free_irq(uint32_t girq) xive_update_irq_mask(s, girq - s->esb_base, true); /* Mark the IVE masked and invalid */ - ive->w = IVE_MASKED | IVE_VALID; + ive->w = xive_set_field64(IVE_VALID, 0ul, 1) | + xive_set_field64(IVE_MASKED, 0ul, 1); xive_ivc_scrub(x, x->block_id, idx); /* Free it */ @@ -4975,7 +4994,7 @@ static int64_t __opal_xive_dump_emu(struct xive_cpu_state *xs, uint32_t pir) false, false); eq = xive_get_eq(xs->xive, xs->eq_idx + XIVE_EMULATION_PRIO); prlog(PR_INFO, "CPU[%04x]: EQ @%p W0=%08x W1=%08x qbuf @%p\n", - pir, eq, eq->w0, eq->w1, xs->eqbuf); + pir, eq, be32_to_cpu(eq->w0), be32_to_cpu(eq->w1), xs->eqbuf); return OPAL_SUCCESS; } diff --git a/include/xive-p9-regs.h b/include/xive-p9-regs.h index f6b7c20b3..126ab525a 100644 --- a/include/xive-p9-regs.h +++ b/include/xive-p9-regs.h @@ -310,7 +310,7 @@ struct xive_ive { /* Use a single 64-bit definition to make it easier to * perform atomic updates */ - uint64_t w; + __be64 w; #define IVE_VALID PPC_BIT(0) #define IVE_EQ_BLOCK PPC_BITMASK(4,7) /* Destination EQ block# */ #define IVE_EQ_INDEX PPC_BITMASK(8,31) /* Destination EQ index */ @@ -320,7 +320,7 @@ struct xive_ive { /* EQ */ struct xive_eq { - uint32_t w0; + __be32 w0; #define EQ_W0_VALID PPC_BIT32(0) /* "v" bit */ #define EQ_W0_ENQUEUE PPC_BIT32(1) /* "q" bit */ #define EQ_W0_UCOND_NOTIFY PPC_BIT32(2) /* "n" bit */ @@ -335,30 +335,31 @@ struct xive_eq { #define EQ_QSIZE_4K 0 #define EQ_QSIZE_64K 4 #define EQ_W0_HWDEP PPC_BITMASK32(24,31) - uint32_t w1; + __be32 w1; #define EQ_W1_ESn PPC_BITMASK32(0,1) #define EQ_W1_ESn_P PPC_BIT32(0) #define EQ_W1_ESn_Q PPC_BIT32(1) #define EQ_W1_ESe PPC_BITMASK32(2,3) #define EQ_W1_ESe_P PPC_BIT32(2) #define EQ_W1_ESe_Q PPC_BIT32(3) +#define EQ_W1_ES PPC_BITMASK32(0,3) #define EQ_W1_GENERATION PPC_BIT32(9) #define EQ_W1_PAGE_OFF PPC_BITMASK32(10,31) - uint32_t w2; + __be32 w2; #define EQ_W2_MIGRATION_REG PPC_BITMASK32(0,3) #define EQ_W2_OP_DESC_HI PPC_BITMASK32(4,31) - uint32_t w3; + __be32 w3; #define EQ_W3_OP_DESC_LO PPC_BITMASK32(0,31) - uint32_t w4; + __be32 w4; #define EQ_W4_ESC_EQ_BLOCK PPC_BITMASK32(4,7) #define EQ_W4_ESC_EQ_INDEX PPC_BITMASK32(8,31) - uint32_t w5; + __be32 w5; #define EQ_W5_ESC_EQ_DATA PPC_BITMASK32(1,31) - uint32_t w6; + __be32 w6; #define EQ_W6_FORMAT_BIT PPC_BIT32(8) #define EQ_W6_NVT_BLOCK PPC_BITMASK32(9,12) #define EQ_W6_NVT_INDEX PPC_BITMASK32(13,31) - uint32_t w7; + __be32 w7; #define EQ_W7_F0_IGNORE PPC_BIT32(0) #define EQ_W7_F0_BLK_GROUPING PPC_BIT32(1) #define EQ_W7_F0_PRIORITY PPC_BITMASK32(8,15) @@ -368,24 +369,24 @@ struct xive_eq { /* VP */ struct xive_vp { - uint32_t w0; + __be32 w0; #define VP_W0_VALID PPC_BIT32(0) - uint32_t w1; - uint32_t w2; - uint32_t w3; - uint32_t w4; - uint32_t w5; - uint32_t w6; - uint32_t w7; - uint32_t w8; + __be32 w1; + __be32 w2; + __be32 w3; + __be32 w4; + __be32 w5; + __be32 w6; + __be32 w7; + __be32 w8; #define VP_W8_GRP_VALID PPC_BIT32(0) - uint32_t w9; - uint32_t wa; - uint32_t wb; - uint32_t wc; - uint32_t wd; - uint32_t we; - uint32_t wf; + __be32 w9; + __be32 wa; + __be32 wb; + __be32 wc; + __be32 wd; + __be32 we; + __be32 wf; }; #endif /* XIVE_P9_REGS_H */ diff --git a/include/xive-regs.h b/include/xive-regs.h index a6a6ce35a..7f0054ef5 100644 --- a/include/xive-regs.h +++ b/include/xive-regs.h @@ -8,6 +8,32 @@ #ifndef XIVE_REGS_H #define XIVE_REGS_H +static inline uint64_t xive_get_field64(uint64_t mask, beint64_t word) +{ + return (be64_to_cpu(word) & mask) >> MASK_TO_LSH(mask); +} + +static inline beint64_t xive_set_field64(uint64_t mask, beint64_t word, + uint64_t value) +{ + uint64_t tmp = (be64_to_cpu(word) & ~mask) | + ((value << MASK_TO_LSH(mask)) & mask); + return cpu_to_be64(tmp); +} + +static inline uint32_t xive_get_field32(uint32_t mask, beint32_t word) +{ + return (be32_to_cpu(word) & mask) >> MASK_TO_LSH(mask); +} + +static inline beint32_t xive_set_field32(uint32_t mask, beint32_t word, + uint32_t value) +{ + uint32_t tmp = (be32_to_cpu(word) & ~mask) | + ((value << MASK_TO_LSH(mask)) & mask); + return cpu_to_be32(tmp); +} + /* * TM registers are special, see below */ diff --git a/include/xive.h b/include/xive.h index 5706d275a..592a6dc09 100644 --- a/include/xive.h +++ b/include/xive.h @@ -27,7 +27,7 @@ uint32_t xive_alloc_ipi_irqs(uint32_t chip_id, uint32_t count, uint32_t align); #define XIVE_HW_SRC_PSI 8 uint64_t xive_get_notify_port(uint32_t chip_id, uint32_t ent); -uint32_t xive_get_notify_base(uint32_t girq); +__attrconst uint32_t xive_get_notify_base(uint32_t girq); /* XIVE feature flag to de/activate store EOI */ #define XIVE_STORE_EOI_ENABLED 0 From patchwork Sun Dec 8 12:22:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205636 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5KL5t3hz9sPK for ; Sun, 8 Dec 2019 23:31:18 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="C1aoVoeA"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5KL48sSzDqPg for ; Sun, 8 Dec 2019 23:31:18 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::62b; helo=mail-pl1-x62b.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="C1aoVoeA"; dkim-atps=neutral Received: from mail-pl1-x62b.google.com (mail-pl1-x62b.google.com [IPv6:2607:f8b0:4864:20::62b]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W58w6j3LzDqDb for ; Sun, 8 Dec 2019 23:24:00 +1100 (AEDT) Received: by mail-pl1-x62b.google.com with SMTP id bh2so3488565plb.11 for ; Sun, 08 Dec 2019 04:24:00 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=9SmlT6IE6OOiFhtHGCKIMINdK3yB4L9wWp2edi4vm/g=; b=C1aoVoeAh3kaXI4FgWTdAhf2bhBoeAAcvXpdDluUl5t0z8v+QI+llmvibtvQImvYGj TeivevrWWzJ32XFhpza05BkdQ//LpTX5y1RAhg1FqYQ6f8CexkVvVIfZUbfkUTwVoOE+ B7kjpdDDJXD801OnG2MggjZ/qvn8ubWPJUeU713TqlRP3kwsDtszRwXOf+GoZTH5nlvp TRB/GK2F2HkEul4YXUWmgTTqgCKc5Pe0TzRXSpgT8Ylnufgaulzn7huQnK2M5gnzSX1+ LWINM8znWWjpRxgETUB2K1evIOOVsdIVFsO33P3Vgt8OAP5EkpyB/qSW9f9UEadC9o+w l8Rw== 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=9SmlT6IE6OOiFhtHGCKIMINdK3yB4L9wWp2edi4vm/g=; b=FsE0kDh9gUmdo78YENTIRdNYq/N/ArfR5A2rp/nfSVCnprBSH3sEFAOaPykXKiMuwS /avVIC0QCBHVNhwFFY+eGSkFaHT3ID5DsKbwtsy1nGVA8qpmi0Hu23MFt9+z4BtifDzt etRjUUKKUq8KD6F0km3Ut7W4WUgr36CoTCpKf3lfDNQEeb4YfEf0FLE164Qtk9+YxjrU x3xi9UL7aVK/cXA4Zfo91DBzyq64rRtzDqAW9c+XdBVbEx+wHeIHeOqIET2RjC5V0asm nUwotFi+arCu6Nk8HigbLmd1kE5jrG4tnjgzVoz3ah8wVFAQj7IfeyKSJS2J8zD0n4Op CNSQ== X-Gm-Message-State: APjAAAUf258zU8YhOyICBuc/PofH/dz9aFMl0lYuQMbEBp2nvxpcK2k9 BwSC8CD+iWM6+vQUhLgfRoDPYJtb X-Google-Smtp-Source: APXvYqz+L4hU3MVpWs0Mao1xnv9tfXtV9d62htlVMDlIa5kQ8Xxu/SoUpUCNrxSft0qgBsukTXoRLg== X-Received: by 2002:a17:90a:1696:: with SMTP id o22mr26570922pja.78.1575807837953; Sun, 08 Dec 2019 04:23:57 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.23.55 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:23:57 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:55 +1000 Message-Id: <20191208122312.12837-15-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 14/31] phb4: make endian-clean X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Convert phb4 dt construction and in-memory hardware tables to use explicit endian conversions. Signed-off-by: Nicholas Piggin --- hw/phb4.c | 342 +++++++++++++++++++++++++------------------------ include/phb4.h | 2 +- 2 files changed, 177 insertions(+), 167 deletions(-) diff --git a/hw/phb4.c b/hw/phb4.c index 85d6a0c06..9f7bcd4ca 100644 --- a/hw/phb4.c +++ b/hw/phb4.c @@ -273,7 +273,7 @@ static int64_t phb4_pcicfg_check(struct phb4 *p, uint32_t bdfn, return OPAL_HARDWARE; /* Fetch the PE# from cache */ - *pe = p->tbl_rtt[bdfn]; + *pe = be16_to_cpu(p->tbl_rtt[bdfn]); return OPAL_SUCCESS; } @@ -913,7 +913,7 @@ static void phb4_init_ioda_cache(struct phb4 *p) * and this occurs before PEs have been assigned. */ for (i = 0; i < RTT_TABLE_ENTRIES; i++) - p->tbl_rtt[i] = PHB4_RESERVED_PE_NUM(p); + p->tbl_rtt[i] = cpu_to_be16(PHB4_RESERVED_PE_NUM(p)); memset(p->tbl_peltv, 0x0, p->tbl_peltv_size); memset(p->tve_cache, 0x0, sizeof(p->tve_cache)); @@ -1795,126 +1795,139 @@ static void phb4_err_clear(struct phb4 *p) static void phb4_read_phb_status(struct phb4 *p, struct OpalIoPhb4ErrorData *stat) { - uint16_t val = 0; uint32_t i; - uint64_t *pPEST; + __be64 *pPEST; + uint16_t __16; + uint32_t __32; + uint64_t __64; memset(stat, 0, sizeof(struct OpalIoPhb4ErrorData)); /* Error data common part */ - stat->common.version = OPAL_PHB_ERROR_DATA_VERSION_1; - stat->common.ioType = OPAL_PHB_ERROR_DATA_TYPE_PHB4; - stat->common.len = sizeof(struct OpalIoPhb4ErrorData); + stat->common.version = cpu_to_be32(OPAL_PHB_ERROR_DATA_VERSION_1); + stat->common.ioType = cpu_to_be32(OPAL_PHB_ERROR_DATA_TYPE_PHB4); + stat->common.len = cpu_to_be32(sizeof(struct OpalIoPhb4ErrorData)); /* Use ASB for config space if the PHB is fenced */ if (p->flags & PHB4_AIB_FENCED) p->flags |= PHB4_CFG_USE_ASB; /* Grab RC bridge control, make it 32-bit */ - phb4_pcicfg_read16(&p->phb, 0, PCI_CFG_BRCTL, &val); - stat->brdgCtl = val; + phb4_pcicfg_read16(&p->phb, 0, PCI_CFG_BRCTL, &__16); + stat->brdgCtl = cpu_to_be32(__16); /* * Grab various RC PCIe capability registers. All device, slot * and link status are 16-bit, so we grab the pair control+status * for each of them */ - phb4_pcicfg_read32(&p->phb, 0, p->ecap + PCICAP_EXP_DEVCTL, - &stat->deviceStatus); - phb4_pcicfg_read32(&p->phb, 0, p->ecap + PCICAP_EXP_SLOTCTL, - &stat->slotStatus); - phb4_pcicfg_read32(&p->phb, 0, p->ecap + PCICAP_EXP_LCTL, - &stat->linkStatus); + phb4_pcicfg_read32(&p->phb, 0, p->ecap + PCICAP_EXP_DEVCTL, &__32); + stat->deviceStatus = cpu_to_be32(__32); + phb4_pcicfg_read32(&p->phb, 0, p->ecap + PCICAP_EXP_SLOTCTL, &__32); + stat->slotStatus = cpu_to_be32(__32); + phb4_pcicfg_read32(&p->phb, 0, p->ecap + PCICAP_EXP_LCTL, &__32); + stat->linkStatus = cpu_to_be32(__32); /* * I assume those are the standard config space header, cmd & status * together makes 32-bit. Secondary status is 16-bit so I'll clear * the top on that one */ - phb4_pcicfg_read32(&p->phb, 0, PCI_CFG_CMD, &stat->devCmdStatus); - phb4_pcicfg_read16(&p->phb, 0, PCI_CFG_SECONDARY_STATUS, &val); - stat->devSecStatus = val; + phb4_pcicfg_read32(&p->phb, 0, PCI_CFG_CMD, &__32); + stat->devCmdStatus = cpu_to_be32(__32); + phb4_pcicfg_read16(&p->phb, 0, PCI_CFG_SECONDARY_STATUS, &__16); + stat->devSecStatus = cpu_to_be32(__32); /* Grab a bunch of AER regs */ - phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_RERR_STA, - &stat->rootErrorStatus); - phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_UE_STATUS, - &stat->uncorrErrorStatus); - phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_CE_STATUS, - &stat->corrErrorStatus); - phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_HDR_LOG0, - &stat->tlpHdr1); - phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_HDR_LOG1, - &stat->tlpHdr2); - phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_HDR_LOG2, - &stat->tlpHdr3); - phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_HDR_LOG3, - &stat->tlpHdr4); - phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_SRCID, - &stat->sourceId); + phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_RERR_STA, &__32); + stat->rootErrorStatus = cpu_to_be32(__32); + phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_UE_STATUS, &__32); + stat->uncorrErrorStatus = cpu_to_be32(__32); + + phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_CE_STATUS, &__32); + stat->corrErrorStatus = cpu_to_be32(__32); + + phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_HDR_LOG0, &__32); + stat->tlpHdr1 = cpu_to_be32(__32); + + phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_HDR_LOG1, &__32); + stat->tlpHdr2 = cpu_to_be32(__32); + + phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_HDR_LOG2, &__32); + stat->tlpHdr3 = cpu_to_be32(__32); + + phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_HDR_LOG3, &__32); + stat->tlpHdr4 = cpu_to_be32(__32); + + phb4_pcicfg_read32(&p->phb, 0, p->aercap + PCIECAP_AER_SRCID, &__32); + stat->sourceId = cpu_to_be32(__32); + /* PEC NFIR, same as P8/PHB3 */ - xscom_read(p->chip_id, p->pe_stk_xscom + 0x0, &stat->nFir); - xscom_read(p->chip_id, p->pe_stk_xscom + 0x3, &stat->nFirMask); - xscom_read(p->chip_id, p->pe_stk_xscom + 0x8, &stat->nFirWOF); + xscom_read(p->chip_id, p->pe_stk_xscom + 0x0, &__64); + stat->nFir = cpu_to_be64(__64); + xscom_read(p->chip_id, p->pe_stk_xscom + 0x3, &__64); + stat->nFirMask = cpu_to_be64(__64); + xscom_read(p->chip_id, p->pe_stk_xscom + 0x8, &__64); + stat->nFirWOF = cpu_to_be64(__64); /* PHB4 inbound and outbound error Regs */ - stat->phbPlssr = phb4_read_reg_asb(p, PHB_CPU_LOADSTORE_STATUS); - stat->phbCsr = phb4_read_reg_asb(p, PHB_DMA_CHAN_STATUS); - stat->lemFir = phb4_read_reg_asb(p, PHB_LEM_FIR_ACCUM); - stat->lemErrorMask = phb4_read_reg_asb(p, PHB_LEM_ERROR_MASK); - stat->lemWOF = phb4_read_reg_asb(p, PHB_LEM_WOF); - stat->phbErrorStatus = phb4_read_reg_asb(p, PHB_ERR_STATUS); - stat->phbFirstErrorStatus = phb4_read_reg_asb(p, PHB_ERR1_STATUS); - stat->phbErrorLog0 = phb4_read_reg_asb(p, PHB_ERR_LOG_0); - stat->phbErrorLog1 = phb4_read_reg_asb(p, PHB_ERR_LOG_1); - stat->phbTxeErrorStatus = phb4_read_reg_asb(p, PHB_TXE_ERR_STATUS); - stat->phbTxeFirstErrorStatus = phb4_read_reg_asb(p, PHB_TXE_ERR1_STATUS); - stat->phbTxeErrorLog0 = phb4_read_reg_asb(p, PHB_TXE_ERR_LOG_0); - stat->phbTxeErrorLog1 = phb4_read_reg_asb(p, PHB_TXE_ERR_LOG_1); - stat->phbRxeArbErrorStatus = phb4_read_reg_asb(p, PHB_RXE_ARB_ERR_STATUS); - stat->phbRxeArbFirstErrorStatus = phb4_read_reg_asb(p, PHB_RXE_ARB_ERR1_STATUS); - stat->phbRxeArbErrorLog0 = phb4_read_reg_asb(p, PHB_RXE_ARB_ERR_LOG_0); - stat->phbRxeArbErrorLog1 = phb4_read_reg_asb(p, PHB_RXE_ARB_ERR_LOG_1); - stat->phbRxeMrgErrorStatus = phb4_read_reg_asb(p, PHB_RXE_MRG_ERR_STATUS); - stat->phbRxeMrgFirstErrorStatus = phb4_read_reg_asb(p, PHB_RXE_MRG_ERR1_STATUS); - stat->phbRxeMrgErrorLog0 = phb4_read_reg_asb(p, PHB_RXE_MRG_ERR_LOG_0); - stat->phbRxeMrgErrorLog1 = phb4_read_reg_asb(p, PHB_RXE_MRG_ERR_LOG_1); - stat->phbRxeTceErrorStatus = phb4_read_reg_asb(p, PHB_RXE_TCE_ERR_STATUS); - stat->phbRxeTceFirstErrorStatus = phb4_read_reg_asb(p, PHB_RXE_TCE_ERR1_STATUS); - stat->phbRxeTceErrorLog0 = phb4_read_reg_asb(p, PHB_RXE_TCE_ERR_LOG_0); - stat->phbRxeTceErrorLog1 = phb4_read_reg_asb(p, PHB_RXE_TCE_ERR_LOG_1); + stat->phbPlssr = cpu_to_be64(phb4_read_reg_asb(p, PHB_CPU_LOADSTORE_STATUS)); + stat->phbCsr = cpu_to_be64(phb4_read_reg_asb(p, PHB_DMA_CHAN_STATUS)); + stat->lemFir = cpu_to_be64(phb4_read_reg_asb(p, PHB_LEM_FIR_ACCUM)); + stat->lemErrorMask = cpu_to_be64(phb4_read_reg_asb(p, PHB_LEM_ERROR_MASK)); + stat->lemWOF = cpu_to_be64(phb4_read_reg_asb(p, PHB_LEM_WOF)); + stat->phbErrorStatus = cpu_to_be64(phb4_read_reg_asb(p, PHB_ERR_STATUS)); + stat->phbFirstErrorStatus = cpu_to_be64(phb4_read_reg_asb(p, PHB_ERR1_STATUS)); + stat->phbErrorLog0 = cpu_to_be64(phb4_read_reg_asb(p, PHB_ERR_LOG_0)); + stat->phbErrorLog1 = cpu_to_be64(phb4_read_reg_asb(p, PHB_ERR_LOG_1)); + stat->phbTxeErrorStatus = cpu_to_be64(phb4_read_reg_asb(p, PHB_TXE_ERR_STATUS)); + stat->phbTxeFirstErrorStatus = cpu_to_be64(phb4_read_reg_asb(p, PHB_TXE_ERR1_STATUS)); + stat->phbTxeErrorLog0 = cpu_to_be64(phb4_read_reg_asb(p, PHB_TXE_ERR_LOG_0)); + stat->phbTxeErrorLog1 = cpu_to_be64(phb4_read_reg_asb(p, PHB_TXE_ERR_LOG_1)); + stat->phbRxeArbErrorStatus = cpu_to_be64(phb4_read_reg_asb(p, PHB_RXE_ARB_ERR_STATUS)); + stat->phbRxeArbFirstErrorStatus = cpu_to_be64(phb4_read_reg_asb(p, PHB_RXE_ARB_ERR1_STATUS)); + stat->phbRxeArbErrorLog0 = cpu_to_be64(phb4_read_reg_asb(p, PHB_RXE_ARB_ERR_LOG_0)); + stat->phbRxeArbErrorLog1 = cpu_to_be64(phb4_read_reg_asb(p, PHB_RXE_ARB_ERR_LOG_1)); + stat->phbRxeMrgErrorStatus = cpu_to_be64(phb4_read_reg_asb(p, PHB_RXE_MRG_ERR_STATUS)); + stat->phbRxeMrgFirstErrorStatus = cpu_to_be64(phb4_read_reg_asb(p, PHB_RXE_MRG_ERR1_STATUS)); + stat->phbRxeMrgErrorLog0 = cpu_to_be64(phb4_read_reg_asb(p, PHB_RXE_MRG_ERR_LOG_0)); + stat->phbRxeMrgErrorLog1 = cpu_to_be64(phb4_read_reg_asb(p, PHB_RXE_MRG_ERR_LOG_1)); + stat->phbRxeTceErrorStatus = cpu_to_be64(phb4_read_reg_asb(p, PHB_RXE_TCE_ERR_STATUS)); + stat->phbRxeTceFirstErrorStatus = cpu_to_be64(phb4_read_reg_asb(p, PHB_RXE_TCE_ERR1_STATUS)); + stat->phbRxeTceErrorLog0 = cpu_to_be64(phb4_read_reg_asb(p, PHB_RXE_TCE_ERR_LOG_0)); + stat->phbRxeTceErrorLog1 = cpu_to_be64(phb4_read_reg_asb(p, PHB_RXE_TCE_ERR_LOG_1)); /* PHB4 REGB error registers */ - stat->phbPblErrorStatus = phb4_read_reg_asb(p, PHB_PBL_ERR_STATUS); - stat->phbPblFirstErrorStatus = phb4_read_reg_asb(p, PHB_PBL_ERR1_STATUS); - stat->phbPblErrorLog0 = phb4_read_reg_asb(p, PHB_PBL_ERR_LOG_0); - stat->phbPblErrorLog1 = phb4_read_reg_asb(p, PHB_PBL_ERR_LOG_1); + stat->phbPblErrorStatus = cpu_to_be64(phb4_read_reg_asb(p, PHB_PBL_ERR_STATUS)); + stat->phbPblFirstErrorStatus = cpu_to_be64(phb4_read_reg_asb(p, PHB_PBL_ERR1_STATUS)); + stat->phbPblErrorLog0 = cpu_to_be64(phb4_read_reg_asb(p, PHB_PBL_ERR_LOG_0)); + stat->phbPblErrorLog1 = cpu_to_be64(phb4_read_reg_asb(p, PHB_PBL_ERR_LOG_1)); - stat->phbPcieDlpErrorStatus = phb4_read_reg_asb(p, PHB_PCIE_DLP_ERR_STATUS); - stat->phbPcieDlpErrorLog1 = phb4_read_reg_asb(p, PHB_PCIE_DLP_ERRLOG1); - stat->phbPcieDlpErrorLog2 = phb4_read_reg_asb(p, PHB_PCIE_DLP_ERRLOG2); + stat->phbPcieDlpErrorStatus = cpu_to_be64(phb4_read_reg_asb(p, PHB_PCIE_DLP_ERR_STATUS)); + stat->phbPcieDlpErrorLog1 = cpu_to_be64(phb4_read_reg_asb(p, PHB_PCIE_DLP_ERRLOG1)); + stat->phbPcieDlpErrorLog2 = cpu_to_be64(phb4_read_reg_asb(p, PHB_PCIE_DLP_ERRLOG2)); - stat->phbRegbErrorStatus = phb4_read_reg_asb(p, PHB_REGB_ERR_STATUS); - stat->phbRegbFirstErrorStatus = phb4_read_reg_asb(p, PHB_REGB_ERR1_STATUS); - stat->phbRegbErrorLog0 = phb4_read_reg_asb(p, PHB_REGB_ERR_LOG_0); - stat->phbRegbErrorLog1 = phb4_read_reg_asb(p, PHB_REGB_ERR_LOG_1); + stat->phbRegbErrorStatus = cpu_to_be64(phb4_read_reg_asb(p, PHB_REGB_ERR_STATUS)); + stat->phbRegbFirstErrorStatus = cpu_to_be64(phb4_read_reg_asb(p, PHB_REGB_ERR1_STATUS)); + stat->phbRegbErrorLog0 = cpu_to_be64(phb4_read_reg_asb(p, PHB_REGB_ERR_LOG_0)); + stat->phbRegbErrorLog1 = cpu_to_be64(phb4_read_reg_asb(p, PHB_REGB_ERR_LOG_1)); /* * Grab PESTA & B content. The error bit (bit#0) should * be fetched from IODA and the left content from memory * resident tables. */ - pPEST = (uint64_t *)p->tbl_pest; + pPEST = (__be64 *)p->tbl_pest; phb4_ioda_sel(p, IODA3_TBL_PESTA, 0, true); for (i = 0; i < p->max_num_pes; i++) { - stat->pestA[i] = phb4_read_reg_asb(p, PHB_IODA_DATA0); + stat->pestA[i] = cpu_to_be64(phb4_read_reg_asb(p, PHB_IODA_DATA0)); stat->pestA[i] |= pPEST[2 * i]; } phb4_ioda_sel(p, IODA3_TBL_PESTB, 0, true); for (i = 0; i < p->max_num_pes; i++) { - stat->pestB[i] = phb4_read_reg_asb(p, PHB_IODA_DATA0); + stat->pestB[i] = cpu_to_be64(phb4_read_reg_asb(p, PHB_IODA_DATA0)); stat->pestB[i] |= pPEST[2 * i + 1]; } } @@ -2064,17 +2077,17 @@ static void phb4_eeh_dump_regs(struct phb4 *p) } phb4_read_phb_status(p, s); - PHBERR(p, " brdgCtl = %08x\n", s->brdgCtl); + PHBERR(p, " brdgCtl = %08x\n", be32_to_cpu(s->brdgCtl)); /* PHB4 cfg regs */ - PHBERR(p, " deviceStatus = %08x\n", s->deviceStatus); - PHBERR(p, " slotStatus = %08x\n", s->slotStatus); - PHBERR(p, " linkStatus = %08x\n", s->linkStatus); - PHBERR(p, " devCmdStatus = %08x\n", s->devCmdStatus); - PHBERR(p, " devSecStatus = %08x\n", s->devSecStatus); - PHBERR(p, " rootErrorStatus = %08x\n", s->rootErrorStatus); - PHBERR(p, " corrErrorStatus = %08x\n", s->corrErrorStatus); - PHBERR(p, " uncorrErrorStatus = %08x\n", s->uncorrErrorStatus); + PHBERR(p, " deviceStatus = %08x\n", be32_to_cpu(s->deviceStatus)); + PHBERR(p, " slotStatus = %08x\n", be32_to_cpu(s->slotStatus)); + PHBERR(p, " linkStatus = %08x\n", be32_to_cpu(s->linkStatus)); + PHBERR(p, " devCmdStatus = %08x\n", be32_to_cpu(s->devCmdStatus)); + PHBERR(p, " devSecStatus = %08x\n", be32_to_cpu(s->devSecStatus)); + PHBERR(p, " rootErrorStatus = %08x\n", be32_to_cpu(s->rootErrorStatus)); + PHBERR(p, " corrErrorStatus = %08x\n", be32_to_cpu(s->corrErrorStatus)); + PHBERR(p, " uncorrErrorStatus = %08x\n", be32_to_cpu(s->uncorrErrorStatus)); /* Two non OPAL API registers that are useful */ phb4_pcicfg_read16(&p->phb, 0, p->ecap + PCICAP_EXP_DEVCTL, ®); @@ -2084,57 +2097,57 @@ static void phb4_eeh_dump_regs(struct phb4 *p) PHBERR(p, " devStat = %08x\n", reg); /* Byte swap TLP headers so they are the same as the PCIe spec */ - PHBERR(p, " tlpHdr1 = %08x\n", bswap_32(s->tlpHdr1)); - PHBERR(p, " tlpHdr2 = %08x\n", bswap_32(s->tlpHdr2)); - PHBERR(p, " tlpHdr3 = %08x\n", bswap_32(s->tlpHdr3)); - PHBERR(p, " tlpHdr4 = %08x\n", bswap_32(s->tlpHdr4)); - PHBERR(p, " sourceId = %08x\n", s->sourceId); - PHBERR(p, " nFir = %016llx\n", s->nFir); - PHBERR(p, " nFirMask = %016llx\n", s->nFirMask); - PHBERR(p, " nFirWOF = %016llx\n", s->nFirWOF); - PHBERR(p, " phbPlssr = %016llx\n", s->phbPlssr); - PHBERR(p, " phbCsr = %016llx\n", s->phbCsr); - PHBERR(p, " lemFir = %016llx\n", s->lemFir); - PHBERR(p, " lemErrorMask = %016llx\n", s->lemErrorMask); - PHBERR(p, " lemWOF = %016llx\n", s->lemWOF); - PHBERR(p, " phbErrorStatus = %016llx\n", s->phbErrorStatus); - PHBERR(p, " phbFirstErrorStatus = %016llx\n", s->phbFirstErrorStatus); - PHBERR(p, " phbErrorLog0 = %016llx\n", s->phbErrorLog0); - PHBERR(p, " phbErrorLog1 = %016llx\n", s->phbErrorLog1); - PHBERR(p, " phbTxeErrorStatus = %016llx\n", s->phbTxeErrorStatus); - PHBERR(p, " phbTxeFirstErrorStatus = %016llx\n", s->phbTxeFirstErrorStatus); - PHBERR(p, " phbTxeErrorLog0 = %016llx\n", s->phbTxeErrorLog0); - PHBERR(p, " phbTxeErrorLog1 = %016llx\n", s->phbTxeErrorLog1); - PHBERR(p, " phbRxeArbErrorStatus = %016llx\n", s->phbRxeArbErrorStatus); - PHBERR(p, "phbRxeArbFrstErrorStatus = %016llx\n", s->phbRxeArbFirstErrorStatus); - PHBERR(p, " phbRxeArbErrorLog0 = %016llx\n", s->phbRxeArbErrorLog0); - PHBERR(p, " phbRxeArbErrorLog1 = %016llx\n", s->phbRxeArbErrorLog1); - PHBERR(p, " phbRxeMrgErrorStatus = %016llx\n", s->phbRxeMrgErrorStatus); - PHBERR(p, "phbRxeMrgFrstErrorStatus = %016llx\n", s->phbRxeMrgFirstErrorStatus); - PHBERR(p, " phbRxeMrgErrorLog0 = %016llx\n", s->phbRxeMrgErrorLog0); - PHBERR(p, " phbRxeMrgErrorLog1 = %016llx\n", s->phbRxeMrgErrorLog1); - PHBERR(p, " phbRxeTceErrorStatus = %016llx\n", s->phbRxeTceErrorStatus); - PHBERR(p, "phbRxeTceFrstErrorStatus = %016llx\n", s->phbRxeTceFirstErrorStatus); - PHBERR(p, " phbRxeTceErrorLog0 = %016llx\n", s->phbRxeTceErrorLog0); - PHBERR(p, " phbRxeTceErrorLog1 = %016llx\n", s->phbRxeTceErrorLog1); - PHBERR(p, " phbPblErrorStatus = %016llx\n", s->phbPblErrorStatus); - PHBERR(p, " phbPblFirstErrorStatus = %016llx\n", s->phbPblFirstErrorStatus); - PHBERR(p, " phbPblErrorLog0 = %016llx\n", s->phbPblErrorLog0); - PHBERR(p, " phbPblErrorLog1 = %016llx\n", s->phbPblErrorLog1); - PHBERR(p, " phbPcieDlpErrorLog1 = %016llx\n", s->phbPcieDlpErrorLog1); - PHBERR(p, " phbPcieDlpErrorLog2 = %016llx\n", s->phbPcieDlpErrorLog2); - PHBERR(p, " phbPcieDlpErrorStatus = %016llx\n", s->phbPcieDlpErrorStatus); - - PHBERR(p, " phbRegbErrorStatus = %016llx\n", s->phbRegbErrorStatus); - PHBERR(p, " phbRegbFirstErrorStatus = %016llx\n", s->phbRegbFirstErrorStatus); - PHBERR(p, " phbRegbErrorLog0 = %016llx\n", s->phbRegbErrorLog0); - PHBERR(p, " phbRegbErrorLog1 = %016llx\n", s->phbRegbErrorLog1); + PHBERR(p, " tlpHdr1 = %08x\n", cpu_to_le32(be32_to_cpu(s->tlpHdr1))); + PHBERR(p, " tlpHdr2 = %08x\n", cpu_to_le32(be32_to_cpu(s->tlpHdr2))); + PHBERR(p, " tlpHdr3 = %08x\n", cpu_to_le32(be32_to_cpu(s->tlpHdr3))); + PHBERR(p, " tlpHdr4 = %08x\n", cpu_to_le32(be32_to_cpu(s->tlpHdr4))); + PHBERR(p, " sourceId = %08x\n", be32_to_cpu(s->sourceId)); + PHBERR(p, " nFir = %016llx\n", be64_to_cpu(s->nFir)); + PHBERR(p, " nFirMask = %016llx\n", be64_to_cpu(s->nFirMask)); + PHBERR(p, " nFirWOF = %016llx\n", be64_to_cpu(s->nFirWOF)); + PHBERR(p, " phbPlssr = %016llx\n", be64_to_cpu(s->phbPlssr)); + PHBERR(p, " phbCsr = %016llx\n", be64_to_cpu(s->phbCsr)); + PHBERR(p, " lemFir = %016llx\n", be64_to_cpu(s->lemFir)); + PHBERR(p, " lemErrorMask = %016llx\n", be64_to_cpu(s->lemErrorMask)); + PHBERR(p, " lemWOF = %016llx\n", be64_to_cpu(s->lemWOF)); + PHBERR(p, " phbErrorStatus = %016llx\n", be64_to_cpu(s->phbErrorStatus)); + PHBERR(p, " phbFirstErrorStatus = %016llx\n", be64_to_cpu(s->phbFirstErrorStatus)); + PHBERR(p, " phbErrorLog0 = %016llx\n", be64_to_cpu(s->phbErrorLog0)); + PHBERR(p, " phbErrorLog1 = %016llx\n", be64_to_cpu(s->phbErrorLog1)); + PHBERR(p, " phbTxeErrorStatus = %016llx\n", be64_to_cpu(s->phbTxeErrorStatus)); + PHBERR(p, " phbTxeFirstErrorStatus = %016llx\n", be64_to_cpu(s->phbTxeFirstErrorStatus)); + PHBERR(p, " phbTxeErrorLog0 = %016llx\n", be64_to_cpu(s->phbTxeErrorLog0)); + PHBERR(p, " phbTxeErrorLog1 = %016llx\n", be64_to_cpu(s->phbTxeErrorLog1)); + PHBERR(p, " phbRxeArbErrorStatus = %016llx\n", be64_to_cpu(s->phbRxeArbErrorStatus)); + PHBERR(p, "phbRxeArbFrstErrorStatus = %016llx\n", be64_to_cpu(s->phbRxeArbFirstErrorStatus)); + PHBERR(p, " phbRxeArbErrorLog0 = %016llx\n", be64_to_cpu(s->phbRxeArbErrorLog0)); + PHBERR(p, " phbRxeArbErrorLog1 = %016llx\n", be64_to_cpu(s->phbRxeArbErrorLog1)); + PHBERR(p, " phbRxeMrgErrorStatus = %016llx\n", be64_to_cpu(s->phbRxeMrgErrorStatus)); + PHBERR(p, "phbRxeMrgFrstErrorStatus = %016llx\n", be64_to_cpu(s->phbRxeMrgFirstErrorStatus)); + PHBERR(p, " phbRxeMrgErrorLog0 = %016llx\n", be64_to_cpu(s->phbRxeMrgErrorLog0)); + PHBERR(p, " phbRxeMrgErrorLog1 = %016llx\n", be64_to_cpu(s->phbRxeMrgErrorLog1)); + PHBERR(p, " phbRxeTceErrorStatus = %016llx\n", be64_to_cpu(s->phbRxeTceErrorStatus)); + PHBERR(p, "phbRxeTceFrstErrorStatus = %016llx\n", be64_to_cpu(s->phbRxeTceFirstErrorStatus)); + PHBERR(p, " phbRxeTceErrorLog0 = %016llx\n", be64_to_cpu(s->phbRxeTceErrorLog0)); + PHBERR(p, " phbRxeTceErrorLog1 = %016llx\n", be64_to_cpu(s->phbRxeTceErrorLog1)); + PHBERR(p, " phbPblErrorStatus = %016llx\n", be64_to_cpu(s->phbPblErrorStatus)); + PHBERR(p, " phbPblFirstErrorStatus = %016llx\n", be64_to_cpu(s->phbPblFirstErrorStatus)); + PHBERR(p, " phbPblErrorLog0 = %016llx\n", be64_to_cpu(s->phbPblErrorLog0)); + PHBERR(p, " phbPblErrorLog1 = %016llx\n", be64_to_cpu(s->phbPblErrorLog1)); + PHBERR(p, " phbPcieDlpErrorLog1 = %016llx\n", be64_to_cpu(s->phbPcieDlpErrorLog1)); + PHBERR(p, " phbPcieDlpErrorLog2 = %016llx\n", be64_to_cpu(s->phbPcieDlpErrorLog2)); + PHBERR(p, " phbPcieDlpErrorStatus = %016llx\n", be64_to_cpu(s->phbPcieDlpErrorStatus)); + + PHBERR(p, " phbRegbErrorStatus = %016llx\n", be64_to_cpu(s->phbRegbErrorStatus)); + PHBERR(p, " phbRegbFirstErrorStatus = %016llx\n", be64_to_cpu(s->phbRegbFirstErrorStatus)); + PHBERR(p, " phbRegbErrorLog0 = %016llx\n", be64_to_cpu(s->phbRegbErrorLog0)); + PHBERR(p, " phbRegbErrorLog1 = %016llx\n", be64_to_cpu(s->phbRegbErrorLog1)); for (i = 0; i < p->max_num_pes; i++) { if (!s->pestA[i] && !s->pestB[i]) continue; PHBERR(p, " PEST[%03x] = %016llx %016llx\n", - i, s->pestA[i], s->pestB[i]); + i, be64_to_cpu(s->pestA[i]), be64_to_cpu(s->pestB[i])); } free(s); } @@ -2178,7 +2191,7 @@ static int64_t phb4_set_pe(struct phb *phb, /* Map or unmap the RTT range */ for (idx = 0; idx < RTT_TABLE_ENTRIES; idx++) if ((idx & mask) == (bdfn & mask)) - p->tbl_rtt[idx] = pe_number; + p->tbl_rtt[idx] = cpu_to_be16(pe_number); /* Invalidate the RID Translation Cache (RTC) inside the PHB */ out_be64(p->regs + PHB_RTC_INVALIDATE, PHB_RTC_INVALIDATE_ALL); @@ -3490,14 +3503,15 @@ static struct pci_slot *phb4_slot_create(struct phb *phb) static uint64_t phb4_get_pesta(struct phb4 *p, uint64_t pe_number) { - uint64_t pesta, *pPEST; + uint64_t pesta; + __be64 *pPEST; - pPEST = (uint64_t *)p->tbl_pest; + pPEST = (__be64 *)p->tbl_pest; phb4_ioda_sel(p, IODA3_TBL_PESTA, pe_number, false); pesta = phb4_read_reg(p, PHB_IODA_DATA0); if (pesta & IODA3_PESTA_MMIO_FROZEN) - pesta |= pPEST[2*pe_number]; + pesta |= be64_to_cpu(pPEST[2*pe_number]); return pesta; } @@ -3855,13 +3869,13 @@ static int64_t phb4_err_inject_cfg(struct phb4 *phb, uint64_t pe_number, ctrl = PHB_PAPR_ERR_INJ_CTL_CFG; for (bdfn = 0; bdfn < RTT_TABLE_ENTRIES; bdfn++) { - if (phb->tbl_rtt[bdfn] != pe_number) + if (be16_to_cpu(phb->tbl_rtt[bdfn]) != pe_number) continue; /* The PE can be associated with PCI bus or device */ is_bus_pe = false; if ((bdfn + 8) < RTT_TABLE_ENTRIES && - phb->tbl_rtt[bdfn + 8] == pe_number) + be16_to_cpu(phb->tbl_rtt[bdfn + 8]) == pe_number) is_bus_pe = true; /* Figure out the PCI config address */ @@ -5392,7 +5406,7 @@ static void phb4_allocate_tables(struct phb4 *p) p->tbl_rtt = local_alloc(p->chip_id, RTT_TABLE_SIZE, RTT_TABLE_SIZE); assert(p->tbl_rtt); for (i = 0; i < RTT_TABLE_ENTRIES; i++) - p->tbl_rtt[i] = PHB4_RESERVED_PE_NUM(p); + p->tbl_rtt[i] = cpu_to_be16(PHB4_RESERVED_PE_NUM(p)); p->tbl_peltv = local_alloc(p->chip_id, p->tbl_peltv_size, p->tbl_peltv_size); assert(p->tbl_peltv); @@ -5530,11 +5544,11 @@ static bool phb4_calculate_windows(struct phb4 *p) "ibm,mmio-windows", -1); assert(prop->len >= (2 * sizeof(uint64_t))); - p->mm0_base = ((const uint64_t *)prop->prop)[0]; - p->mm0_size = ((const uint64_t *)prop->prop)[1]; + p->mm0_base = be64_to_cpu(((__be64 *)prop->prop)[0]); + p->mm0_size = be64_to_cpu(((__be64 *)prop->prop)[1]); if (prop->len > 16) { - p->mm1_base = ((const uint64_t *)prop->prop)[2]; - p->mm1_size = ((const uint64_t *)prop->prop)[3]; + p->mm1_base = be64_to_cpu(((__be64 *)prop->prop)[2]); + p->mm1_size = be64_to_cpu(((__be64 *)prop->prop)[3]); } /* Sort them so that 0 is big and 1 is small */ @@ -5606,16 +5620,12 @@ static const struct irq_source_ops phb4_lsi_ops = { .attributes = phb4_lsi_attributes, }; -#ifdef HAVE_BIG_ENDIAN -static u64 lane_eq_default[8] = { - 0x5454545454545454UL, 0x5454545454545454UL, - 0x5454545454545454UL, 0x5454545454545454UL, - 0x7777777777777777UL, 0x7777777777777777UL, - 0x7777777777777777UL, 0x7777777777777777UL +static __be64 lane_eq_default[8] = { + CPU_TO_BE64(0x5454545454545454UL), CPU_TO_BE64(0x5454545454545454UL), + CPU_TO_BE64(0x5454545454545454UL), CPU_TO_BE64(0x5454545454545454UL), + CPU_TO_BE64(0x7777777777777777UL), CPU_TO_BE64(0x7777777777777777UL), + CPU_TO_BE64(0x7777777777777777UL), CPU_TO_BE64(0x7777777777777777UL), }; -#else -#error lane_eq_default needs to be big endian (device tree property) -#endif static void phb4_create(struct dt_node *np) { @@ -5650,11 +5660,11 @@ static void phb4_create(struct dt_node *np) /* Get the various XSCOM register bases from the device-tree */ prop = dt_require_property(np, "ibm,xscom-bases", 5 * sizeof(uint32_t)); - p->pe_xscom = ((const uint32_t *)prop->prop)[0]; - p->pe_stk_xscom = ((const uint32_t *)prop->prop)[1]; - p->pci_xscom = ((const uint32_t *)prop->prop)[2]; - p->pci_stk_xscom = ((const uint32_t *)prop->prop)[3]; - p->etu_xscom = ((const uint32_t *)prop->prop)[4]; + p->pe_xscom = be32_to_cpu(((__be32 *)prop->prop)[0]); + p->pe_stk_xscom = be32_to_cpu(((__be32 *)prop->prop)[1]); + p->pci_xscom = be32_to_cpu(((__be32 *)prop->prop)[2]); + p->pci_stk_xscom = be32_to_cpu(((__be32 *)prop->prop)[3]); + p->etu_xscom = be32_to_cpu(((__be32 *)prop->prop)[4]); /* * We skip the initial PERST assertion requested by the generic code @@ -5817,7 +5827,7 @@ static void phb4_probe_stack(struct dt_node *stk_node, uint32_t pec_index, uint64_t mmio1_bar = 0, mmio1_bmask, mmio1_sz; uint64_t reg[4]; void *foo; - uint64_t mmio_win[4]; + __be64 mmio_win[4]; unsigned int mmio_win_sz; struct dt_node *np; char *path; @@ -5877,13 +5887,13 @@ static void phb4_probe_stack(struct dt_node *stk_node, uint32_t pec_index, /* Build MMIO windows list */ mmio_win_sz = 0; if (mmio0_bar) { - mmio_win[mmio_win_sz++] = mmio0_bar; - mmio_win[mmio_win_sz++] = mmio0_sz; + mmio_win[mmio_win_sz++] = cpu_to_be64(mmio0_bar); + mmio_win[mmio_win_sz++] = cpu_to_be64(mmio0_sz); bar_en |= XPEC_NEST_STK_BAR_EN_MMIO0; } if (mmio1_bar) { - mmio_win[mmio_win_sz++] = mmio1_bar; - mmio_win[mmio_win_sz++] = mmio1_sz; + mmio_win[mmio_win_sz++] = cpu_to_be64(mmio1_bar); + mmio_win[mmio_win_sz++] = cpu_to_be64(mmio1_sz); bar_en |= XPEC_NEST_STK_BAR_EN_MMIO1; } @@ -5913,12 +5923,12 @@ static void phb4_probe_stack(struct dt_node *stk_node, uint32_t pec_index, prlog_once(PR_DEBUG, "Version reg: 0x%016llx\n", in_be64(foo)); /* Create PHB node */ - reg[0] = phb_bar; - reg[1] = 0x1000; - reg[2] = irq_bar; - reg[3] = 0x10000000; + reg[0] = cpu_to_be64(phb_bar); + reg[1] = cpu_to_be64(0x1000); + reg[2] = cpu_to_be64(irq_bar); + reg[3] = cpu_to_be64(0x10000000); - np = dt_new_addr(dt_root, "pciex", reg[0]); + np = dt_new_addr(dt_root, "pciex", phb_bar); if (!np) return; diff --git a/include/phb4.h b/include/phb4.h index 1c68ec2e2..ca701a311 100644 --- a/include/phb4.h +++ b/include/phb4.h @@ -183,7 +183,7 @@ struct phb4 { uint64_t creset_start_time; /* SkiBoot owned in-memory tables */ - uint16_t *tbl_rtt; + __be16 *tbl_rtt; uint8_t *tbl_peltv; uint64_t tbl_peltv_size; uint64_t tbl_pest; From patchwork Sun Dec 8 12:22:56 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205637 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5Kh47qJz9sP3 for ; Sun, 8 Dec 2019 23:31:36 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Xc0jAmIo"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5Kh393GzDqNv for ; Sun, 8 Dec 2019 23:31:36 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1043; helo=mail-pj1-x1043.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Xc0jAmIo"; dkim-atps=neutral Received: from mail-pj1-x1043.google.com (mail-pj1-x1043.google.com [IPv6:2607:f8b0:4864:20::1043]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W58z5GcPzDqDb for ; Sun, 8 Dec 2019 23:24:03 +1100 (AEDT) Received: by mail-pj1-x1043.google.com with SMTP id j11so3534052pjs.1 for ; Sun, 08 Dec 2019 04:24:03 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=3tLnU9uVwkIUcw6FV+m8kYEaojUI9wKwba16XPrQaTg=; b=Xc0jAmIoiiWXUWcjvrP/KnmfiS7WwpYKo/KTUGxA9nxFXdApbe1lr/k1SSmvvDKZQF U5GtpxWDfxIN8lBwPxurry2ziY/bM6Dwr7F2nEpxZFN90BYTR05L3k5Y1edr62TLvwCX zuHl1Y1+y2Jq0K3+YRxormP0E4rRaqvKodqx+onZbmli8iKZPSH7Cy1leoTrPqiTaPTQ U69+ddUyQ+TyjZmR4fW4HKNdWcB7UPYOjAQvw3sqUOp/1V9EsAEj6qDvPnfCUeyXfn5S JDqfE3YK9gn5ppucLKJIfZUHGgoWctXsfzXk9sH4r/514OXnwOVRqkYum5CpRJad/7J2 10Rw== 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=3tLnU9uVwkIUcw6FV+m8kYEaojUI9wKwba16XPrQaTg=; b=giDylAnmgCkczh/v7E+MOEZ50YYymIb/PrZKtr2eiGUPl2fyxqU4/FBMSsF4RAe9oS 7c9NILqmqC+gUmSQk2NVFIxr2Cgtdq1WtAXZSuu3RIGgTqzTAZJyZ2BAtWAindLP1PXP St8CaQtLotk1iscGbZpnnJVkzk+5AGefG7DGssKlihiWdjgKddYHKsv2ORh3O31ONbXp egrjBkA0Hz/VEpjRy215urPkUro1nhOBgGvi9a0uRZyBH9WEKyQRfa6xAh3AGByL9eqd BrzWG7lrg1QbTr7qHG5Zb1m2FYtvlnzVf68eSeQprVb1/vz1lcOYoLLncfnEJVwDDpx+ /i8Q== X-Gm-Message-State: APjAAAWazbgi99soCnioHNkX8FBw0h8aqT6DbN+rVY9xBJgsnSWqvrKy KkOizaTGBy+L3e7iXdyT+UEzeklu X-Google-Smtp-Source: APXvYqwM52Ja9tI/djzgyD7T61ZYurqTJqwSdBFrBmAEPR+2qsyDPo8mi5iKyMIHKK3+dNaar388Zw== X-Received: by 2002:a17:90a:b906:: with SMTP id p6mr19176096pjr.81.1575807840621; Sun, 08 Dec 2019 04:24:00 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.23.58 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:00 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:56 +1000 Message-Id: <20191208122312.12837-16-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 15/31] occ sensors: make endian-clean X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Convert occ sensors dt construction and in-memory hardware tables to use explicit endian conversions. Signed-off-by: Nicholas Piggin --- hw/occ-sensor.c | 100 ++++++++++++++++++++++++++---------------------- hw/occ.c | 46 +++++++++++----------- include/occ.h | 50 ++++++++++++------------ 3 files changed, 103 insertions(+), 93 deletions(-) diff --git a/hw/occ-sensor.c b/hw/occ-sensor.c index da846bd92..e9ac5df4b 100644 --- a/hw/occ-sensor.c +++ b/hw/occ-sensor.c @@ -116,7 +116,7 @@ struct occ_sensor_data_header *get_sensor_header_block(int occ_num) static inline struct occ_sensor_name *get_names_block(struct occ_sensor_data_header *hb) { - return ((struct occ_sensor_name *)((u64)hb + hb->names_offset)); + return ((struct occ_sensor_name *)((u64)hb + be32_to_cpu(hb->names_offset))); } static inline u32 sensor_handler(int occ_num, int sensor_id, int attr) @@ -131,11 +131,11 @@ static inline u32 sensor_handler(int occ_num, int sensor_id, int attr) */ static void scale_sensor(struct occ_sensor_name *md, u64 *sensor) { - u32 factor = md->scale_factor; + u32 factor = be32_to_cpu(md->scale_factor); int i; s8 exp; - if (md->type == OCC_SENSOR_TYPE_CURRENT) + if (be16_to_cpu(md->type) == OCC_SENSOR_TYPE_CURRENT) *sensor *= 1000; //convert to mA *sensor *= factor >> 8; @@ -152,7 +152,7 @@ static void scale_sensor(struct occ_sensor_name *md, u64 *sensor) static void scale_energy(struct occ_sensor_name *md, u64 *sensor) { - u32 factor = md->freq; + u32 factor = be32_to_cpu(md->freq); int i; s8 exp; @@ -174,17 +174,17 @@ static u64 read_sensor(struct occ_sensor_record *sensor, int attr) { switch (attr) { case SENSOR_SAMPLE: - return sensor->sample; + return be16_to_cpu(sensor->sample); case SENSOR_SAMPLE_MIN: - return sensor->sample_min; + return be16_to_cpu(sensor->sample_min); case SENSOR_SAMPLE_MAX: - return sensor->sample_max; + return be16_to_cpu(sensor->sample_max); case SENSOR_CSM_MIN: - return sensor->csm_min; + return be16_to_cpu(sensor->csm_min); case SENSOR_CSM_MAX: - return sensor->csm_max; + return be16_to_cpu(sensor->csm_max); case SENSOR_ACCUMULATOR: - return sensor->accumulator; + return be64_to_cpu(sensor->accumulator); default: break; } @@ -197,14 +197,16 @@ static void *select_sensor_buffer(struct occ_sensor_data_header *hb, int id) struct occ_sensor_name *md; u8 *ping, *pong; void *buffer = NULL; + u32 reading_offset; if (!hb) return NULL; md = get_names_block(hb); - ping = (u8 *)((u64)hb + hb->reading_ping_offset); - pong = (u8 *)((u64)hb + hb->reading_pong_offset); + ping = (u8 *)((u64)hb + be32_to_cpu(hb->reading_ping_offset)); + pong = (u8 *)((u64)hb + be32_to_cpu(hb->reading_pong_offset)); + reading_offset = be32_to_cpu(md[id].reading_offset); /* Check which buffer is valid and read the data from that. * Ping Pong Action @@ -216,11 +218,11 @@ static void *select_sensor_buffer(struct occ_sensor_data_header *hb, int id) if (*ping && *pong) { u64 tping, tpong; - u64 ping_buf = (u64)ping + md[id].reading_offset; - u64 pong_buf = (u64)pong + md[id].reading_offset; + u64 ping_buf = (u64)ping + reading_offset; + u64 pong_buf = (u64)pong + reading_offset; - tping = ((struct occ_sensor_record *)ping_buf)->timestamp; - tpong = ((struct occ_sensor_record *)pong_buf)->timestamp; + tping = be64_to_cpu(((struct occ_sensor_record *)ping_buf)->timestamp); + tpong = be64_to_cpu(((struct occ_sensor_record *)pong_buf)->timestamp); if (tping > tpong) buffer = ping; @@ -236,7 +238,7 @@ static void *select_sensor_buffer(struct occ_sensor_data_header *hb, int id) } assert(buffer); - buffer = (void *)((u64)buffer + md[id].reading_offset); + buffer = (void *)((u64)buffer + reading_offset); return buffer; } @@ -265,7 +267,7 @@ int occ_sensor_read(u32 handle, __be64 *data) if (hb->valid != 1) return OPAL_HARDWARE; - if (id > hb->nr_sensors) + if (id > be16_to_cpu(hb->nr_sensors)) return OPAL_PARAMETER; buff = select_sensor_buffer(hb, id); @@ -277,7 +279,7 @@ int occ_sensor_read(u32 handle, __be64 *data) return OPAL_SUCCESS; md = get_names_block(hb); - if (md[id].type == OCC_SENSOR_TYPE_POWER && attr == SENSOR_ACCUMULATOR) + if (be16_to_cpu(md[id].type) == OCC_SENSOR_TYPE_POWER && attr == SENSOR_ACCUMULATOR) scale_energy(&md[id], &d); else scale_sensor(&md[id], &d); @@ -323,7 +325,8 @@ static bool occ_sensor_sanity(struct occ_sensor_data_header *hb, int chipid) return false; } - if (!hb->names_offset || !hb->reading_ping_offset || + if (!hb->names_offset || + !hb->reading_ping_offset || !hb->reading_pong_offset) { prerror("OCC: Chip %d Invalid sensor buffer pointers\n", chipid); @@ -360,9 +363,10 @@ static void add_sensor_label(struct dt_node *node, struct occ_sensor_name *md, { char sname[30] = ""; char prefix[30] = ""; + uint16_t location = be16_to_cpu(md->location); int i; - if (md->location != OCC_SENSOR_LOC_SYSTEM) + if (location != OCC_SENSOR_LOC_SYSTEM) snprintf(prefix, sizeof(prefix), "%s %d ", "Chip", chipid); for (i = 0; i < ARRAY_SIZE(str_maps); i++) @@ -371,7 +375,7 @@ static void add_sensor_label(struct dt_node *node, struct occ_sensor_name *md, char *end; int num = -1; - if (md->location != OCC_SENSOR_LOC_CORE) + if (location != OCC_SENSOR_LOC_CORE) num = parse_entity(md->name, &end); if (num != -1) { @@ -387,7 +391,7 @@ static void add_sensor_label(struct dt_node *node, struct occ_sensor_name *md, } /* Fallback to OCC literal if mapping is not found */ - if (md->location == OCC_SENSOR_LOC_SYSTEM) { + if (location == OCC_SENSOR_LOC_SYSTEM) { dt_add_property_string(node, "label", md->name); } else { snprintf(sname, sizeof(sname), "%s%s", prefix, md->name); @@ -447,15 +451,15 @@ static bool check_sensor_sample(struct occ_sensor_data_header *hb, u32 offset) { struct occ_sensor_record *ping, *pong; - ping = (struct occ_sensor_record *)((u64)hb + hb->reading_ping_offset - + offset); - pong = (struct occ_sensor_record *)((u64)hb + hb->reading_pong_offset - + offset); + ping = (struct occ_sensor_record *)((u64)hb + + be32_to_cpu(hb->reading_ping_offset) + offset); + pong = (struct occ_sensor_record *)((u64)hb + + be32_to_cpu(hb->reading_pong_offset) + offset); return ping->sample || pong->sample; } static void add_sensor_node(const char *loc, const char *type, int i, int attr, - struct occ_sensor_name *md, u32 *phandle, u32 *ptype, + struct occ_sensor_name *md, __be32 *phandle, u32 *ptype, u32 pir, u32 occ_num, u32 chipid) { char name[30]; @@ -471,10 +475,10 @@ static void add_sensor_node(const char *loc, const char *type, int i, int attr, dt_add_property_string(node, "occ_label", md->name); add_sensor_label(node, md, chipid); - if (md->location == OCC_SENSOR_LOC_CORE) + if (be16_to_cpu(md->location) == OCC_SENSOR_LOC_CORE) dt_add_property_cells(node, "ibm,pir", pir); - *ptype = md->type; + *ptype = be16_to_cpu(md->type); if (attr == SENSOR_SAMPLE) { handler = sensor_handler(occ_num, i, SENSOR_CSM_MAX); @@ -485,7 +489,7 @@ static void add_sensor_node(const char *loc, const char *type, int i, int attr, } dt_add_property_string(node, "compatible", "ibm,opal-sensor"); - *phandle = node->phandle; + *phandle = cpu_to_be32(node->phandle); } bool occ_sensors_init(void) @@ -523,7 +527,9 @@ bool occ_sensors_init(void) for_each_chip(chip) { struct occ_sensor_data_header *hb; struct occ_sensor_name *md; - u32 *phandles, *ptype, phcount = 0; + __be32 *phandles; + u32 *ptype, phcount = 0; + unsigned int nr_sensors; hb = get_sensor_header_block(occ_num); md = get_names_block(hb); @@ -532,30 +538,34 @@ bool occ_sensors_init(void) if (!occ_sensor_sanity(hb, chip->id)) continue; - phandles = malloc(hb->nr_sensors * sizeof(u32)); + nr_sensors = be16_to_cpu(hb->nr_sensors); + + phandles = malloc(nr_sensors * sizeof(__be32)); assert(phandles); - ptype = malloc(hb->nr_sensors * sizeof(u32)); + ptype = malloc(nr_sensors * sizeof(u32)); assert(ptype); - for (i = 0; i < hb->nr_sensors; i++) { - const char *type, *loc; + for (i = 0; i < nr_sensors; i++) { + const char *type_name, *loc; struct cpu_thread *c = NULL; uint32_t pir = 0; + uint16_t type = be16_to_cpu(md[i].type); + uint16_t location = be16_to_cpu(md[i].location); if (md[i].structure_type != OCC_SENSOR_READING_FULL) continue; - if (!(md[i].type & HWMON_SENSORS_MASK)) + if (!(type & HWMON_SENSORS_MASK)) continue; - if (md[i].location == OCC_SENSOR_LOC_GPU && !has_gpu) + if (location == OCC_SENSOR_LOC_GPU && !has_gpu) continue; - if (md[i].type == OCC_SENSOR_TYPE_POWER && - !check_sensor_sample(hb, md[i].reading_offset)) + if (type == OCC_SENSOR_TYPE_POWER && + !check_sensor_sample(hb, be32_to_cpu(md[i].reading_offset))) continue; - if (md[i].location == OCC_SENSOR_LOC_CORE) { + if (location == OCC_SENSOR_LOC_CORE) { int num = parse_entity(md[i].name, NULL); for_each_available_core_in_chip(c, chip->id) @@ -566,16 +576,16 @@ bool occ_sensors_init(void) pir = c->pir; } - type = get_sensor_type_string(md[i].type); - loc = get_sensor_loc_string(md[i].location); + type_name = get_sensor_type_string(type); + loc = get_sensor_loc_string(location); - add_sensor_node(loc, type, i, SENSOR_SAMPLE, &md[i], + add_sensor_node(loc, type_name, i, SENSOR_SAMPLE, &md[i], &phandles[phcount], &ptype[phcount], pir, occ_num, chip->id); phcount++; /* Add energy sensors */ - if (md[i].type == OCC_SENSOR_TYPE_POWER && + if (type == OCC_SENSOR_TYPE_POWER && md[i].structure_type == OCC_SENSOR_READING_FULL) { add_sensor_node(loc, "energy", i, SENSOR_ACCUMULATOR, &md[i], diff --git a/hw/occ.c b/hw/occ.c index 46210ba20..3542e44a3 100644 --- a/hw/occ.c +++ b/hw/occ.c @@ -97,7 +97,7 @@ struct occ_pstate_table { u8 flags; u8 vdd; u8 vcs; - u32 freq_khz; + __be32 freq_khz; } pstates[MAX_PSTATES]; s8 core_max[MAX_P8_CORES]; u8 pad[100]; @@ -115,7 +115,7 @@ struct occ_pstate_table { u8 id; u8 flags; u16 reserved; - u32 freq_khz; + __be32 freq_khz; } pstates[MAX_PSTATES]; u8 core_max[MAX_P9_CORES]; u8 pad[56]; @@ -375,7 +375,7 @@ static bool wait_for_all_occ_init(void) chip->occ_functional = true; prlog(PR_DEBUG, "OCC: Chip %02x Data (%016llx) = %016llx\n", - chip->id, (uint64_t)occ_data, *(uint64_t *)occ_data); + chip->id, (uint64_t)occ_data, be64_to_cpu(*(__be64 *)occ_data)); } end_time = mftb(); prlog(PR_NOTICE, "OCC: All Chip Rdy after %lu ms\n", @@ -398,8 +398,8 @@ static bool wait_for_all_occ_init(void) * the list and break from the loop as this is the last valid * element in the pstate table. */ -static void parse_pstates_v2(struct occ_pstate_table *data, u32 *dt_id, - u32 *dt_freq, int nr_pstates, int pmax, int pmin) +static void parse_pstates_v2(struct occ_pstate_table *data, __be32 *dt_id, + __be32 *dt_freq, int nr_pstates, int pmax, int pmin) { int i, j; @@ -407,8 +407,8 @@ static void parse_pstates_v2(struct occ_pstate_table *data, u32 *dt_id, if (cmp_pstates(data->v2.pstates[i].id, pmax) > 0) continue; - dt_id[j] = data->v2.pstates[i].id; - dt_freq[j] = data->v2.pstates[i].freq_khz / 1000; + dt_id[j] = cpu_to_be32(data->v2.pstates[i].id); + dt_freq[j] = cpu_to_be32(be32_to_cpu(data->v2.pstates[i].freq_khz) / 1000); j++; if (data->v2.pstates[i].id == pmin) @@ -420,8 +420,8 @@ static void parse_pstates_v2(struct occ_pstate_table *data, u32 *dt_id, nr_pstates, j); } -static void parse_pstates_v9(struct occ_pstate_table *data, u32 *dt_id, - u32 *dt_freq, int nr_pstates, int pmax, int pmin) +static void parse_pstates_v9(struct occ_pstate_table *data, __be32 *dt_id, + __be32 *dt_freq, int nr_pstates, int pmax, int pmin) { int i, j; @@ -429,8 +429,8 @@ static void parse_pstates_v9(struct occ_pstate_table *data, u32 *dt_id, if (cmp_pstates(data->v9.pstates[i].id, pmax) > 0) continue; - dt_id[j] = data->v9.pstates[i].id; - dt_freq[j] = data->v9.pstates[i].freq_khz / 1000; + dt_id[j] = cpu_to_be32(data->v9.pstates[i].id); + dt_freq[j] = cpu_to_be32(be32_to_cpu(data->v9.pstates[i].freq_khz) / 1000); j++; if (data->v9.pstates[i].id == pmin) @@ -482,7 +482,7 @@ static bool add_cpu_pstate_properties(struct dt_node *power_mgt, uint64_t occ_data_area; struct occ_pstate_table *occ_data; /* Arrays for device tree */ - u32 *dt_id, *dt_freq; + __be32 *dt_id, *dt_freq; int pmax, pmin, pnom; u8 nr_pstates; bool ultra_turbo_supported; @@ -500,8 +500,8 @@ static bool add_cpu_pstate_properties(struct dt_node *power_mgt, occ_data_area = (uint64_t)occ_data; prlog(PR_DEBUG, "OCC: Data (%16llx) = %16llx %16llx\n", occ_data_area, - *(uint64_t *)occ_data_area, - *(uint64_t *)(occ_data_area + 8)); + be64_to_cpu(*(__be64 *)occ_data_area), + be64_to_cpu(*(__be64 *)(occ_data_area + 8))); if (!occ_data->valid) { /** @@ -629,9 +629,9 @@ static bool add_cpu_pstate_properties(struct dt_node *power_mgt, return false; } - dt_id = malloc(nr_pstates * sizeof(u32)); + dt_id = malloc(nr_pstates * sizeof(__be32)); assert(dt_id); - dt_freq = malloc(nr_pstates * sizeof(u32)); + dt_freq = malloc(nr_pstates * sizeof(__be32)); assert(dt_freq); switch (major) { @@ -649,9 +649,9 @@ static bool add_cpu_pstate_properties(struct dt_node *power_mgt, /* Add the device-tree entries */ dt_add_property(power_mgt, "ibm,pstate-ids", dt_id, - nr_pstates * sizeof(u32)); + nr_pstates * sizeof(__be32)); dt_add_property(power_mgt, "ibm,pstate-frequencies-mhz", dt_freq, - nr_pstates * sizeof(u32)); + nr_pstates * sizeof(__be32)); dt_add_property_cells(power_mgt, "ibm,pstate-min", pmin); dt_add_property_cells(power_mgt, "ibm,pstate-nominal", pnom); dt_add_property_cells(power_mgt, "ibm,pstate-max", pmax); @@ -667,7 +667,7 @@ static bool add_cpu_pstate_properties(struct dt_node *power_mgt, if (ultra_turbo_supported) { int pturbo, pultra_turbo; u8 nr_cores = get_available_nr_cores_in_chip(chip->id); - u32 *dt_cmax; + __be32 *dt_cmax; dt_cmax = malloc(nr_cores * sizeof(u32)); assert(dt_cmax); @@ -676,13 +676,13 @@ static bool add_cpu_pstate_properties(struct dt_node *power_mgt, pturbo = occ_data->v2.pstate_turbo; pultra_turbo = occ_data->v2.pstate_ultra_turbo; for (i = 0; i < nr_cores; i++) - dt_cmax[i] = occ_data->v2.core_max[i]; + dt_cmax[i] = cpu_to_be32(occ_data->v2.core_max[i]); break; case 0x9: pturbo = occ_data->v9.pstate_turbo; pultra_turbo = occ_data->v9.pstate_ultra_turbo; for (i = 0; i < nr_cores; i++) - dt_cmax[i] = occ_data->v9.core_max[i]; + dt_cmax[i] = cpu_to_be32(occ_data->v9.core_max[i]); break; default: return false; @@ -1602,7 +1602,7 @@ int occ_sensor_group_enable(u32 group_hndl, int token, bool enable) return opal_occ_command(&chips[i], token, &sensor_mask_data); } -void occ_add_sensor_groups(struct dt_node *sg, u32 *phandles, u32 *ptype, +void occ_add_sensor_groups(struct dt_node *sg, __be32 *phandles, u32 *ptype, int nr_phandles, int chipid) { struct group_info { @@ -1689,7 +1689,7 @@ void occ_add_sensor_groups(struct dt_node *sg, u32 *phandles, u32 *ptype, dt_add_property_cells(node, "ibm,chip-id", chipid); dt_add_property_cells(node, "reg", handle); if (groups[j].ops == OPAL_SENSOR_GROUP_ENABLE) { - u32 *_phandles; + __be32 *_phandles; int k, pcount = 0; _phandles = malloc(sizeof(u32) * nr_phandles); diff --git a/include/occ.h b/include/occ.h index ab45e9e46..967c3fd18 100644 --- a/include/occ.h +++ b/include/occ.h @@ -34,7 +34,7 @@ bool occ_get_gpu_presence(struct proc_chip *chip, int gpu_num); extern bool occ_sensors_init(void); extern int occ_sensor_read(u32 handle, __be64 *data); extern int occ_sensor_group_clear(u32 group_hndl, int token); -extern void occ_add_sensor_groups(struct dt_node *sg, u32 *phandles, +extern void occ_add_sensor_groups(struct dt_node *sg, __be32 *phandles, u32 *ptype, int nr_phandles, int chipid); extern int occ_sensor_group_enable(u32 group_hndl, int token, bool enable); @@ -186,15 +186,15 @@ enum sensor_struct_type { struct occ_sensor_data_header { u8 valid; u8 version; - u16 nr_sensors; + __be16 nr_sensors; u8 reading_version; u8 pad[3]; - u32 names_offset; + __be32 names_offset; u8 names_version; u8 name_length; u16 reserved; - u32 reading_ping_offset; - u32 reading_pong_offset; + __be32 reading_ping_offset; + __be32 reading_pong_offset; } __attribute__((__packed__)); /** @@ -220,13 +220,13 @@ struct occ_sensor_data_header { struct occ_sensor_name { char name[MAX_CHARS_SENSOR_NAME]; char units[MAX_CHARS_SENSOR_UNIT]; - u16 gsid; - u32 freq; - u32 scale_factor; - u16 type; - u16 location; + __be16 gsid; + __be32 freq; + __be32 scale_factor; + __be16 type; + __be16 location; u8 structure_type; - u32 reading_offset; + __be32 reading_offset; u8 sensor_data; u8 pad[8]; } __attribute__((__packed__)); @@ -258,18 +258,18 @@ struct occ_sensor_name { */ struct occ_sensor_record { u16 gsid; - u64 timestamp; - u16 sample; - u16 sample_min; - u16 sample_max; - u16 csm_min; - u16 csm_max; - u16 profiler_min; - u16 profiler_max; - u16 job_scheduler_min; - u16 job_scheduler_max; - u64 accumulator; - u32 update_tag; + __be64 timestamp; + __be16 sample; + __be16 sample_min; + __be16 sample_max; + __be16 csm_min; + __be16 csm_max; + __be16 profiler_min; + __be16 profiler_max; + __be16 job_scheduler_min; + __be16 job_scheduler_max; + __be64 accumulator; + __be32 update_tag; u8 pad[8]; } __attribute__((__packed__)); @@ -284,8 +284,8 @@ struct occ_sensor_record { */ struct occ_sensor_counter { u16 gsid; - u64 timestamp; - u64 accumulator; + __be64 timestamp; + __be64 accumulator; u8 sample; u8 pad[5]; } __attribute__((__packed__)); From patchwork Sun Dec 8 12:22:57 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205638 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5L43ZHBz9sP3 for ; Sun, 8 Dec 2019 23:31:56 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BnAJH+UH"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5L41lcnzDqGl for ; Sun, 8 Dec 2019 23:31:56 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::543; helo=mail-pg1-x543.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="BnAJH+UH"; dkim-atps=neutral Received: from mail-pg1-x543.google.com (mail-pg1-x543.google.com [IPv6:2607:f8b0:4864:20::543]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W5920nKNzDqF6 for ; Sun, 8 Dec 2019 23:24:06 +1100 (AEDT) Received: by mail-pg1-x543.google.com with SMTP id b1so5650485pgq.10 for ; Sun, 08 Dec 2019 04:24:06 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=4qsvAWxQ08PPClwaCFxZ+xx8g/KwW8Dd6NSXErvNgT4=; b=BnAJH+UH/TWgVlALHSvwxNlFnVoc/TO+cl4pVsUQNx8akBt4JBC4cYS8a5L3r7DSKP +exs6Hk/AGXsW/BnWUeIWRxV/6uBxhDAVdfAuh4+1md1LWWe2yH3qkN3LQAKdrJTxT6g H5f7Fz77pv5/73azugsTTosIEnNG5DZ9SKYZu4osycIK+n7vPu+WGuzB0cc73oZlI2qi luTPpWdxPyFFIjtblO/9mbtQLSLdthiRjzR22Gg9hlj5d+vI6a8nuX29+ATy75tOnJKu eEWiwSvM8XswY15JWfoTs0NFyUbg4rSoz3Dy0tBZgFpMtOdEIucxegbamcq9AzMSdlnR pXSA== 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=4qsvAWxQ08PPClwaCFxZ+xx8g/KwW8Dd6NSXErvNgT4=; b=CWXWMaV/ril8s16BM/S9ojSaG5gNO80JC+hbTfc5xfCcrlJRxokM6C1SWR4HTf+nIs 2u5Kq0gpy5JkbwpRr04LDvOxYeXnyIr4Ci6Q5/XMjMy/xe4V34e3bHO4I7aiokDzkFIj 7qM+0VbNZuACF6jIazQ1Z39UO+7OeA8UZQ9Dnwy6VAbz9eLf7uwRnsgNT1O6dvml/6q5 Cq6++/oslHXmS99G5V3D8yUt7Kyt40B8bIIAfB41qZ1zYKmRI986fXzGiKeb9zsUO+Fi agUCrStnIAaO/FqT0ly9+B7XKNSp+Z4xyr3Ju09yGWOSf2SukVro+3x3iZzCyDc1KE4K uEhw== X-Gm-Message-State: APjAAAXdImXAghBv00fTBJcfRZolq/0Tsnurb7WpQXq5KNB+EfqcuHNE 1hZz4fQWo2x1O6PJqUhDtNtiH279 X-Google-Smtp-Source: APXvYqx+y5hG8M4igyj9vtkAN7rOAPQd3JYNqWdop4VBg/trBAJOwlkps4x2uMUnM6n6mnfeNBkNbg== X-Received: by 2002:a63:954f:: with SMTP id t15mr13454725pgn.137.1575807843492; Sun, 08 Dec 2019 04:24:03 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:03 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:57 +1000 Message-Id: <20191208122312.12837-17-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 16/31] memconsole: make endian-clean X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Convert memconsole dt construction and in-memory tables to use explicit endian conversions. Signed-off-by: Nicholas Piggin --- core/console.c | 22 +++++++++++----------- include/console.h | 16 ++++++++-------- platforms/ibm-fsp/common.c | 4 ++-- platforms/ibm-fsp/hostservices.c | 12 ++++++------ 4 files changed, 27 insertions(+), 27 deletions(-) diff --git a/core/console.c b/core/console.c index ac88f0c71..030c1d918 100644 --- a/core/console.c +++ b/core/console.c @@ -30,11 +30,11 @@ static struct lock con_lock = LOCK_UNLOCKED; /* This is mapped via TCEs so we keep it alone in a page */ struct memcons memcons __section(".data.memcons") = { - .magic = MEMCONS_MAGIC, - .obuf_phys = INMEM_CON_START, - .ibuf_phys = INMEM_CON_START + INMEM_CON_OUT_LEN, - .obuf_size = INMEM_CON_OUT_LEN, - .ibuf_size = INMEM_CON_IN_LEN, + .magic = CPU_TO_BE64(MEMCONS_MAGIC), + .obuf_phys = CPU_TO_BE64(INMEM_CON_START), + .ibuf_phys = CPU_TO_BE64(INMEM_CON_START + INMEM_CON_OUT_LEN), + .obuf_size = CPU_TO_BE32(INMEM_CON_OUT_LEN), + .ibuf_size = CPU_TO_BE32(INMEM_CON_IN_LEN), }; static bool dummy_console_enabled(void) @@ -197,7 +197,7 @@ static void inmem_write(char c) if (con_wrapped) opos |= MEMCONS_OUT_POS_WRAP; lwsync(); - memcons.out_pos = opos; + memcons.out_pos = cpu_to_be32(opos); /* If head reaches tail, push tail around & drop chars */ if (con_in == con_out) @@ -207,12 +207,12 @@ static void inmem_write(char c) static size_t inmem_read(char *buf, size_t req) { size_t read = 0; - char *ibuf = (char *)memcons.ibuf_phys; + char *ibuf = (char *)be64_to_cpu(memcons.ibuf_phys); - while (req && memcons.in_prod != memcons.in_cons) { - *(buf++) = ibuf[memcons.in_cons]; + while (req && be32_to_cpu(memcons.in_prod) != be32_to_cpu(memcons.in_cons)) { + *(buf++) = ibuf[be32_to_cpu(memcons.in_cons)]; lwsync(); - memcons.in_cons = (memcons.in_cons + 1) % INMEM_CON_IN_LEN; + memcons.in_cons = cpu_to_be32((be32_to_cpu(memcons.in_cons) + 1) % INMEM_CON_IN_LEN); req--; read++; } @@ -428,7 +428,7 @@ void dummy_console_add_nodes(void) { struct dt_property *p; - add_opal_console_node(0, "raw", memcons.obuf_size); + add_opal_console_node(0, "raw", be32_to_cpu(memcons.obuf_size)); /* Mambo might have left a crap one, clear it */ p = __dt_find_property(dt_chosen, "linux,stdout-path"); diff --git a/include/console.h b/include/console.h index 230b825b0..61448e28e 100644 --- a/include/console.h +++ b/include/console.h @@ -14,17 +14,17 @@ * (This is v3 of the format, the previous one sucked) */ struct memcons { - uint64_t magic; + __be64 magic; #define MEMCONS_MAGIC 0x6630696567726173LL - uint64_t obuf_phys; - uint64_t ibuf_phys; - uint32_t obuf_size; - uint32_t ibuf_size; - uint32_t out_pos; + __be64 obuf_phys; + __be64 ibuf_phys; + __be32 obuf_size; + __be32 ibuf_size; + __be32 out_pos; #define MEMCONS_OUT_POS_WRAP 0x80000000u #define MEMCONS_OUT_POS_MASK 0x00ffffffu - uint32_t in_prod; - uint32_t in_cons; + __be32 in_prod; + __be32 in_cons; }; extern struct memcons memcons; diff --git a/platforms/ibm-fsp/common.c b/platforms/ibm-fsp/common.c index 1ad221053..48b9fd884 100644 --- a/platforms/ibm-fsp/common.c +++ b/platforms/ibm-fsp/common.c @@ -25,9 +25,9 @@ static void map_debug_areas(void) fsp_tce_map(PSI_DMA_LOG_BUF, (void*)INMEM_CON_START, INMEM_CON_LEN); debug_descriptor.memcons_tce = PSI_DMA_MEMCONS; - t = memcons.obuf_phys - INMEM_CON_START + PSI_DMA_LOG_BUF; + t = be64_to_cpu(memcons.obuf_phys) - INMEM_CON_START + PSI_DMA_LOG_BUF; debug_descriptor.memcons_obuf_tce = t; - t = memcons.ibuf_phys - INMEM_CON_START + PSI_DMA_LOG_BUF; + t = be64_to_cpu(memcons.ibuf_phys) - INMEM_CON_START + PSI_DMA_LOG_BUF; debug_descriptor.memcons_ibuf_tce = t; t = PSI_DMA_TRACE_BASE; diff --git a/platforms/ibm-fsp/hostservices.c b/platforms/ibm-fsp/hostservices.c index 19a87e4cb..ab4c90016 100644 --- a/platforms/ibm-fsp/hostservices.c +++ b/platforms/ibm-fsp/hostservices.c @@ -178,11 +178,11 @@ static bool hbrt_con_wrapped; #define HBRT_CON_OUT_LEN (HBRT_CON_LEN - HBRT_CON_IN_LEN) static struct memcons hbrt_memcons __section(".data.memcons") = { - .magic = MEMCONS_MAGIC, - .obuf_phys = HBRT_CON_START, - .ibuf_phys = HBRT_CON_START + HBRT_CON_OUT_LEN, - .obuf_size = HBRT_CON_OUT_LEN, - .ibuf_size = HBRT_CON_IN_LEN, + .magic = CPU_TO_BE64(MEMCONS_MAGIC), + .obuf_phys = CPU_TO_BE64(HBRT_CON_START), + .ibuf_phys = CPU_TO_BE64(HBRT_CON_START + HBRT_CON_OUT_LEN), + .obuf_size = CPU_TO_BE32(HBRT_CON_OUT_LEN), + .ibuf_size = CPU_TO_BE32(HBRT_CON_IN_LEN), }; static void hservice_putc(char c) @@ -206,7 +206,7 @@ static void hservice_putc(char c) if (hbrt_con_wrapped) opos |= MEMCONS_OUT_POS_WRAP; lwsync(); - hbrt_memcons.out_pos = opos; + hbrt_memcons.out_pos = cpu_to_be32(opos); } static void hservice_puts(const char *str) From patchwork Sun Dec 8 12:22:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205639 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5LN0kFRz9sPK for ; Sun, 8 Dec 2019 23:32:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Vpk0fpK2"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5LM6FvqzDqH5 for ; Sun, 8 Dec 2019 23:32:11 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::442; helo=mail-pf1-x442.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Vpk0fpK2"; dkim-atps=neutral Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W5943nVczDqKZ for ; Sun, 8 Dec 2019 23:24:08 +1100 (AEDT) Received: by mail-pf1-x442.google.com with SMTP id y14so5733884pfm.13 for ; Sun, 08 Dec 2019 04:24:08 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=jLXzw/48+W+uprecFQbReM9HUd/uhyWydF7p1MP/DII=; b=Vpk0fpK2B4KmxPHXnRDcMwhRJe7AOMTOFeZItUDW/6JiG3z4cMb6/ZJ17mrKlBLEL/ Im88R5D+8uJA5ToDJEGh1GxVAHJWgxwhUxLLdJ46n+eOaKXUi8uH4dU0WCZMawL3og4M 5fPK+Q2Spo60D5iFD7mlGs8mbBKotX3RMPwNOcjixtE0bOtHJBWC+JMxEq5Jqghz3xN9 HDE1tVFhNdVBjglS8LqlChu2il8Vjuum7s+WXqn76Hiu7O9+GIg1n48VthLk0hucmObq ZUZycoCteA3ipLyzI4ku30mmm+day1NLsOPO2aOQGixfuNBthtNgMnPO9cNZaPNLSEGt UopQ== 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=jLXzw/48+W+uprecFQbReM9HUd/uhyWydF7p1MP/DII=; b=VQEyD6l8eLxqGOZjn38OLKx8JNoFYpyJaY/K7nRrBXoZ+ObUpI6ahX+y1ibeUKY+ku vRFDZPwRZlWOUZxSIX6yO27JkMnBUnIpGZ332+3BCXeWjnw/aSKSM7oGeeYxE9b661hG IziNOWubNBRF6zmNlIwg3Dut9YJt2hjcJGeTDrOhMEHE65Fuxsq7B+D+E3cNq0uJj5cv Ed70+pMSr00e3pIxjS+nqx1hSr3qGBeELwBHudhuzaua5ySQgfYxdMXBABbAsfzSc4rJ KM50kQW6GVIQK8F4R9BE4IgvBzk+zE02SuD38Ju9AkJLXXlrZqHszOefP1C1MInjbCjG 64rg== X-Gm-Message-State: APjAAAVt6sOz2BQ3C67FewCD2ddFmb6+jGsNzviPSd53QpanSTwMhYjG DUmoPWKqhffcJYPSmT8Vq40DNcC1 X-Google-Smtp-Source: APXvYqwNFTS9M7volHQaG1w9gJXvKTYGW4CKUH7AXE9Z/rXd695Vz5MNeLfr6YUQuWoqdX/Y4k2WHA== X-Received: by 2002:a62:1883:: with SMTP id 125mr6473063pfy.166.1575807846501; Sun, 08 Dec 2019 04:24:06 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:05 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:58 +1000 Message-Id: <20191208122312.12837-18-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 17/31] debug descriptor: make endian-clean X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Signed-off-by: Nicholas Piggin --- core/init.c | 9 +++++++-- core/trace.c | 22 +++++++++++----------- include/debug_descriptor.h | 26 +++++++++++++------------- platforms/ibm-fsp/common.c | 19 ++++++++++--------- 4 files changed, 41 insertions(+), 35 deletions(-) diff --git a/core/init.c b/core/init.c index d90695c16..b7bf2e50c 100644 --- a/core/init.c +++ b/core/init.c @@ -72,9 +72,9 @@ void skiboot_gcov_done(void); struct debug_descriptor debug_descriptor = { .eye_catcher = "OPALdbug", - .version = DEBUG_DESC_VERSION, + .version = CPU_TO_BE32(DEBUG_DESC_VERSION), .state_flags = 0, - .memcons_phys = (uint64_t)&memcons, + .memcons_phys = 0, /* cpu_to_be64(&memcons) can't init constant */ .trace_mask = 0, /* All traces disabled by default */ /* console log level: * high 4 bits in memory, low 4 bits driver (e.g. uart). */ @@ -1008,6 +1008,11 @@ void __noreturn __nomcount main_cpu_entry(const void *fdt) */ pre_init_boot_cpu(); + /* + * Point to our mem console + */ + debug_descriptor.memcons_phys = cpu_to_be64((uint64_t)&memcons); + /* * Before first printk, ensure console buffer is clear or * reading tools might think it has wrapped diff --git a/core/trace.c b/core/trace.c index 5388972f3..5c71370fd 100644 --- a/core/trace.c +++ b/core/trace.c @@ -121,7 +121,7 @@ void trace_add(union trace *trace, u8 type, u16 len) #endif /* Skip traces not enabled in the debug descriptor */ if (trace->hdr.type < (8 * sizeof(debug_descriptor.trace_mask)) && - !((1ul << trace->hdr.type) & debug_descriptor.trace_mask)) + !((1ul << trace->hdr.type) & be64_to_cpu(debug_descriptor.trace_mask))) return; trace->hdr.timestamp = cpu_to_be64(mftb()); @@ -171,12 +171,12 @@ static void trace_add_dt_props(void) if (!exports) return; - prop = malloc(sizeof(u64) * 2 * debug_descriptor.num_traces); + prop = malloc(sizeof(u64) * 2 * be32_to_cpu(debug_descriptor.num_traces)); - for (i = 0; i < debug_descriptor.num_traces; i++) { - uint64_t addr = debug_descriptor.trace_phys[i]; - uint64_t size = debug_descriptor.trace_size[i]; - uint32_t pir = debug_descriptor.trace_pir[i]; + for (i = 0; i < be32_to_cpu(debug_descriptor.num_traces); i++) { + uint64_t addr = be64_to_cpu(debug_descriptor.trace_phys[i]); + uint64_t size = be32_to_cpu(debug_descriptor.trace_size[i]); + uint32_t pir = be16_to_cpu(debug_descriptor.trace_pir[i]); prop[i * 2] = cpu_to_fdt64(addr); prop[i * 2 + 1] = cpu_to_fdt64(size); @@ -199,18 +199,18 @@ static void trace_add_dt_props(void) static void trace_add_desc(struct trace_info *t, uint64_t size, uint16_t pir) { - unsigned int i = debug_descriptor.num_traces; + unsigned int i = be32_to_cpu(debug_descriptor.num_traces); if (i >= DEBUG_DESC_MAX_TRACES) { prerror("TRACE: Debug descriptor trace list full !\n"); return; } - debug_descriptor.num_traces++; - debug_descriptor.trace_phys[i] = (uint64_t)t; + debug_descriptor.num_traces = cpu_to_be32(i + 1); + debug_descriptor.trace_phys[i] = cpu_to_be64((uint64_t)t); debug_descriptor.trace_tce[i] = 0; /* populated later */ - debug_descriptor.trace_size[i] = size; - debug_descriptor.trace_pir[i] = pir; + debug_descriptor.trace_size[i] = cpu_to_be32(size); + debug_descriptor.trace_pir[i] = cpu_to_be16(pir); } /* Allocate trace buffers once we know memory topology */ diff --git a/include/debug_descriptor.h b/include/debug_descriptor.h index 774c3607d..cbe9293e3 100644 --- a/include/debug_descriptor.h +++ b/include/debug_descriptor.h @@ -11,27 +11,27 @@ struct debug_descriptor { u8 eye_catcher[8]; /* "OPALdbug" */ #define DEBUG_DESC_VERSION 1 - u32 version; + __be32 version; u8 console_log_levels; /* high 4 bits in memory, * low 4 bits driver (e.g. uart). */ u8 state_flags; /* various state flags - OPAL_BOOT_COMPLETE etc */ - u16 reserved2; - u32 reserved[2]; + __be16 reserved2; + __be32 reserved[2]; /* Memory console */ - u64 memcons_phys; - u32 memcons_tce; - u32 memcons_obuf_tce; - u32 memcons_ibuf_tce; + __be64 memcons_phys; + __be32 memcons_tce; + __be32 memcons_obuf_tce; + __be32 memcons_ibuf_tce; /* Traces */ - u64 trace_mask; - u32 num_traces; + __be64 trace_mask; + __be32 num_traces; #define DEBUG_DESC_MAX_TRACES 256 - u64 trace_phys[DEBUG_DESC_MAX_TRACES]; - u32 trace_size[DEBUG_DESC_MAX_TRACES]; - u32 trace_tce[DEBUG_DESC_MAX_TRACES]; - u16 trace_pir[DEBUG_DESC_MAX_TRACES]; + __be64 trace_phys[DEBUG_DESC_MAX_TRACES]; + __be32 trace_size[DEBUG_DESC_MAX_TRACES]; + __be32 trace_tce[DEBUG_DESC_MAX_TRACES]; + __be16 trace_pir[DEBUG_DESC_MAX_TRACES]; }; extern struct debug_descriptor debug_descriptor; diff --git a/platforms/ibm-fsp/common.c b/platforms/ibm-fsp/common.c index 48b9fd884..c288bff36 100644 --- a/platforms/ibm-fsp/common.c +++ b/platforms/ibm-fsp/common.c @@ -24,14 +24,14 @@ static void map_debug_areas(void) fsp_tce_map(PSI_DMA_MEMCONS, &memcons, 0x1000); fsp_tce_map(PSI_DMA_LOG_BUF, (void*)INMEM_CON_START, INMEM_CON_LEN); - debug_descriptor.memcons_tce = PSI_DMA_MEMCONS; + debug_descriptor.memcons_tce = cpu_to_be32(PSI_DMA_MEMCONS); t = be64_to_cpu(memcons.obuf_phys) - INMEM_CON_START + PSI_DMA_LOG_BUF; - debug_descriptor.memcons_obuf_tce = t; + debug_descriptor.memcons_obuf_tce = cpu_to_be32(t); t = be64_to_cpu(memcons.ibuf_phys) - INMEM_CON_START + PSI_DMA_LOG_BUF; - debug_descriptor.memcons_ibuf_tce = t; + debug_descriptor.memcons_ibuf_tce = cpu_to_be32(t); t = PSI_DMA_TRACE_BASE; - for (i = 0; i < debug_descriptor.num_traces; i++) { + for (i = 0; i < be32_to_cpu(debug_descriptor.num_traces); i++) { /* * Trace buffers are misaligned by 0x10 due to the lock * in the trace structure, and their size is also not @@ -46,15 +46,16 @@ static void map_debug_areas(void) * Note: Maybe we should map them read-only... */ uint64_t tstart, tend, toff, tsize; + uint64_t trace_phys = be64_to_cpu(debug_descriptor.trace_phys[i]); + uint32_t trace_size = be32_to_cpu(debug_descriptor.trace_size[i]); - tstart = ALIGN_DOWN(debug_descriptor.trace_phys[i], 0x1000); - tend = ALIGN_UP(debug_descriptor.trace_phys[i] + - debug_descriptor.trace_size[i], 0x1000); - toff = debug_descriptor.trace_phys[i] - tstart; + tstart = ALIGN_DOWN(trace_phys, 0x1000); + tend = ALIGN_UP(trace_phys + trace_size, 0x1000); + toff = trace_phys - tstart; tsize = tend - tstart; fsp_tce_map(t, (void *)tstart, tsize); - debug_descriptor.trace_tce[i] = t + toff; + debug_descriptor.trace_tce[i] = cpu_to_be32(t + toff); t += tsize; } } From patchwork Sun Dec 8 12:22:59 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205640 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5Ll0yF1z9sP3 for ; Sun, 8 Dec 2019 23:32:31 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LUS2cMuU"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5Lj3cpfzDqGY for ; Sun, 8 Dec 2019 23:32:29 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::641; helo=mail-pl1-x641.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="LUS2cMuU"; dkim-atps=neutral Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W5975gQpzDqFv for ; Sun, 8 Dec 2019 23:24:11 +1100 (AEDT) Received: by mail-pl1-x641.google.com with SMTP id c13so3988247pls.0 for ; Sun, 08 Dec 2019 04:24:11 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=5ZcmmBrLEj3lgYPgVR1pGRijMPSxssE10TvZDL93mwA=; b=LUS2cMuUGEb9t0oYg5wq6/G8xYjrjtSKwXXkT5s2X6WMrhZSMOeuK1gx0UCt1SHRaK wBwHW9erMKjtyOgKVTjP1OYiezDoepv0aA0L8vXBQsJjST+zEZeZ0hquJOkQyl0OFyjb XJwFGV811LF9K7m82Lpfpusak8oTYCXt5DF1urb1fbY+AcxNC0KaxCqMXLFzJqVgt6D+ uZhnK3olrfMBn8LxjszfYkEPCyHoa+57CaPXzDlfrVHODXxZVGtBe9Aza94GuDPv6ryn WsDUtZav3rIJiyP67WFkzzmp1NJdrgVZasBlvuOsZMlkNzqQyTJLhgJMT+eAW+BwCUQW nyyQ== 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=5ZcmmBrLEj3lgYPgVR1pGRijMPSxssE10TvZDL93mwA=; b=ThdNbONs2ROPrvzQ5vrSjkuihu2GLemVXMrB+pqVDZJaQIc/VNW/WUVBZo3vVZJqEO jwSnzHTlrAIz2hqTesaFl6Cyy9O2qptx0q543WEgjLQRAyt/9Z7zl9YjFylJNLoxFscB 4C2Z8eS7ieAfJeB6AvE1MezXo5wv8JYNnd5gxr7Kvsvr4CrTnUDVjKAjw/+GoXdITynU 2/EZdE8iXYKpakvNYhnO8NJ094w+iuRTZ+ZLQ6z3WZRg6aED5viA0im7UG9VUHu3+dCq uLUcDbaQ22KiJAUbIE9Ff/B2588HHFVdTWixmwy5mGyFYqqSTwIgUsEMDABbiTjt9tJN YtjQ== X-Gm-Message-State: APjAAAUFeHu1z4f85JhheKtqUJiCCch8NM08ioFy/rYjBRpBM04Qyv+E EGDlmbWQup46j9sAUMSc5/3ZsPlD X-Google-Smtp-Source: APXvYqwZa+FuYxSXY9JzHI0d+0GxsMblowodPbr8jMNfaLaCqXgksiQZcqcd/PPaXQGDEUf+aIIQgQ== X-Received: by 2002:a17:90a:a004:: with SMTP id q4mr26421255pjp.106.1575807849087; Sun, 08 Dec 2019 04:24:09 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.07 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:08 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:22:59 +1000 Message-Id: <20191208122312.12837-19-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 18/31] ipmi: endian conversion X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Signed-off-by: Nicholas Piggin --- hw/ipmi/ipmi-sel.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/ipmi/ipmi-sel.c b/hw/ipmi/ipmi-sel.c index 60df9d927..537bb3b38 100644 --- a/hw/ipmi/ipmi-sel.c +++ b/hw/ipmi/ipmi-sel.c @@ -192,7 +192,7 @@ static void ipmi_init_esel_record(void) { memset(&sel_record, 0, sizeof(struct sel_record)); sel_record.record_type = SEL_REC_TYPE_AMI_ESEL; - sel_record.generator_id = SEL_GENERATOR_ID_AMI; + sel_record.generator_id = cpu_to_le16(SEL_GENERATOR_ID_AMI); sel_record.evm_ver = SEL_EVM_VER_2; sel_record.sensor_type = SENSOR_TYPE_SYS_EVENT; sel_record.sensor_number = From patchwork Sun Dec 8 12:23:00 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205641 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5M82fvvz9sP3 for ; Sun, 8 Dec 2019 23:32:52 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fUXejlha"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5M81bJRzDqGY for ; Sun, 8 Dec 2019 23:32:52 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::444; helo=mail-pf1-x444.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="fUXejlha"; dkim-atps=neutral Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W59B3gM9zDqJW for ; Sun, 8 Dec 2019 23:24:14 +1100 (AEDT) Received: by mail-pf1-x444.google.com with SMTP id y14so5733942pfm.13 for ; Sun, 08 Dec 2019 04:24:14 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=+uDHoa+iUfIc/4ifeukUPt9IIop+htGPot4N7QjYmSk=; b=fUXejlhaObTaKBQdstiqjsZwiD35nh3YqHF7L7TmOjVZx71Y4R9flUbJV7K1rK390q xib5tJStbLRMB/OeBR7Q5cDXSHyQ+XKXm+c6HQRbuK9RitnI5iAgPVzT96v6bSMha9gk 5ssUYuogry2TP+TJ4asZgh6BTdIlwk8lZ1tT4QOYyPBvmMUwCFSbQczCE0k0MWUGpTbE 2lH50fJDbbqPxy8mmuJWkBDK5eMvMJRuDI5icY0YjQ6dhQcHJlyhSEoYLtTfetmRXDmc XWDz793mWVp2keXyEiEXHqI9U+mJQWzasV1rfLZMLirayukHbPSGJVLH3D6JtsDQOWdh lQyA== 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=+uDHoa+iUfIc/4ifeukUPt9IIop+htGPot4N7QjYmSk=; b=NlVKRwQsp9urVLQTPCP6FOu87yxCNxlQOLOxG8vkLj7dIDLgsP7jFcxs/hZ0+tRs+8 Nx2yb8jpk0mCbP7Tgu0sLOoReaNLbpX5jMEl3cOnpN22wVf3gykOw792GSSanC7YP11O vQMM8JmkLJyMILg8aYzbro/6tuHKx2AqVtl/zIlS8tmGx813SqqDjA1Hx5QE2LgZw7GA EAgnXUpEf+YS5DL4iHOKXy+JSsBHeNXJSwGsW/lBw4TG4l8Wj9NnLLueD96o7GB7KsqJ 44w3Fim65w2scYLV76K3UwEWq54FB4KEirixHsFZvGYehI8FH3hfoAx6OOl47aY8LK2P 88iw== X-Gm-Message-State: APjAAAVMiGUHfz+TWywohWSe/Fgg/DoTxmmE754pDp0/wTL0gbn3gvp6 cp1jI5giHnt5NMglFHYppise/VKa X-Google-Smtp-Source: APXvYqx4gEq6VwmLmHyTtlQjseN1jFiRlERYC5Yt30SB+44TRelvbLnOh97iwYWFTBF8aOZUjPp4FA== X-Received: by 2002:a62:b615:: with SMTP id j21mr15486687pff.247.1575807852439; Sun, 08 Dec 2019 04:24:12 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.10 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:12 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:23:00 +1000 Message-Id: <20191208122312.12837-20-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 19/31] sbe-p9: endian conversion X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Reviewed-by: Vasant Hegde Signed-off-by: Nicholas Piggin --- hw/sbe-p9.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/hw/sbe-p9.c b/hw/sbe-p9.c index 1b5f29ec1..53f378e18 100644 --- a/hw/sbe-p9.c +++ b/hw/sbe-p9.c @@ -123,7 +123,7 @@ static u64 p9_sbe_rreg(u32 chip_id, u64 reg) return 0xffffffff; } - return be64_to_cpu(data); + return data; } static void p9_sbe_reg_dump(u32 chip_id) From patchwork Sun Dec 8 12:23:01 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205643 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5N11NYvz9sP3 for ; Sun, 8 Dec 2019 23:33:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="h0zw8Hhi"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5N1057ZzDqGY for ; Sun, 8 Dec 2019 23:33:37 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::532; helo=mail-pg1-x532.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="h0zw8Hhi"; dkim-atps=neutral Received: from mail-pg1-x532.google.com (mail-pg1-x532.google.com [IPv6:2607:f8b0:4864:20::532]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W59L4NPrzDqDb for ; Sun, 8 Dec 2019 23:24:22 +1100 (AEDT) Received: by mail-pg1-x532.google.com with SMTP id a33so5457292pgm.5 for ; Sun, 08 Dec 2019 04:24:22 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=hzL/y9KHJVEJW2q2Q6rfb3dLuus//LDFc57bE8xmYsI=; b=h0zw8Hhiruhjm8eZXMyZ64kwChfBHKdm2uCgRSqfXiad64PaWU6uIOhxgzhaZStsA2 QsNaTn9jaD19oR+kjfc9VCG5Wkud/fzvrwlViVMLWYYtjXrptNv3ezoTmDB4MKKf9n9K pmOuOIJYE26fDQL3BTq6xNcKsoGj6uFhAjVkFZm6hudbKnIKhVKhOcCB2sPVo3WBRxVk EawTjYgb0TYzh4/HpWYf19OrpMHApjJv4GviQWr4WPlzViXvinJQGaU/jwFQh2QUOaTY dl5hPN8lh5j3QqEeCVsBfhL5Y09ql1WSTjsoOcjfDpbKalvo2akkVsHRtda6bUWOOJ99 yA4A== 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=hzL/y9KHJVEJW2q2Q6rfb3dLuus//LDFc57bE8xmYsI=; b=pzEslBxjbdfCn6gOFGslSvDuv9UBO3qth6MYCsmkEr79PBkMpCAFsJ+ZZewEUXyh1l fzewLoyG+SCI+37iz/2/41wxRmcKlz399CDW4Mehh2RaVuM1jWozswVf4608yUPNBLKs CFb50GArSensiwxk4TVW/SEbHy74ZpIyP0dHQBu54tE1akagyVXDhnMTjoJDH745IyoX rpQHVCfz6744ZqNrMt0B8M+eLHnligQV9ne/WOuhGTYXackyGoa3uYvgt9ZQQyjjLYFN rghlV6BuY4pNhAI/YcKzw8veLImzfnopw+zMhn2906GwkTkZPSZMidk+maGRAMdY8doU P2qg== X-Gm-Message-State: APjAAAX1bXKFkki3qYXfZ2E2FS8cu7SfIo8TLuY6o2SDY2HJ+YZpQFwF RwvJU7yqLG2fXhd7DCMqiBy3+wUu X-Google-Smtp-Source: APXvYqx790AUTYQyp4ZaQGRAuXTl/PxhiQ5OsrLqc4HlFmkEsjLSv0kYSbnx8em7TzyF9AHkvfR9fg== X-Received: by 2002:aa7:86c5:: with SMTP id h5mr24023564pfo.259.1575807857589; Sun, 08 Dec 2019 04:24:17 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:16 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:23:01 +1000 Message-Id: <20191208122312.12837-21-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 20/31] fsp: endian conversions X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Reviewed-by: Vasant Hegde Signed-off-by: Nicholas Piggin --- hw/fsp/fsp-attn.c | 4 +- hw/fsp/fsp-codeupdate.c | 48 +++++++------- hw/fsp/fsp-codeupdate.h | 86 ++++++++++++------------- hw/fsp/fsp-console.c | 75 +++++++++++----------- hw/fsp/fsp-diag.c | 2 +- hw/fsp/fsp-dpo.c | 4 +- hw/fsp/fsp-dump.c | 33 +++++----- hw/fsp/fsp-elog-read.c | 20 +++--- hw/fsp/fsp-elog-write.c | 11 ++-- hw/fsp/fsp-epow.c | 12 ++-- hw/fsp/fsp-ipmi.c | 8 +-- hw/fsp/fsp-leds.c | 107 ++++++++++++++++--------------- hw/fsp/fsp-mem-err.c | 6 +- hw/fsp/fsp-nvram.c | 14 ++-- hw/fsp/fsp-occ.c | 8 +-- hw/fsp/fsp-op-panel.c | 22 +++---- hw/fsp/fsp-rtc.c | 17 +++-- hw/fsp/fsp-sensor.c | 37 ++++++----- hw/fsp/fsp-surveillance.c | 1 + hw/fsp/fsp-sysdump.c | 2 +- hw/fsp/fsp-sysparam.c | 26 ++++---- hw/fsp/fsp.c | 42 ++++++------ include/fsp-attn.h | 2 +- include/fsp-elog.h | 4 +- include/fsp-leds.h | 24 +++---- include/fsp.h | 12 +++- include/spcn.h | 18 +++--- platforms/ibm-fsp/common.c | 2 +- platforms/ibm-fsp/firenze-pci.c | 89 +++++++++++++------------ platforms/ibm-fsp/hostservices.c | 4 +- platforms/ibm-fsp/lxvpd.c | 6 +- platforms/ibm-fsp/lxvpd.h | 44 ++++++++++++- 32 files changed, 431 insertions(+), 359 deletions(-) diff --git a/hw/fsp/fsp-attn.c b/hw/fsp/fsp-attn.c index 2c0260cde..e121d8ada 100644 --- a/hw/fsp/fsp-attn.c +++ b/hw/fsp/fsp-attn.c @@ -106,8 +106,8 @@ static void update_sp_attn_area(const char *msg) backtrace_print(bt_buf, &metadata, ti_attn->msg.bt_buf, &len, false); snprintf(ti_attn->msg.file_info, FILE_INFO_LEN, "%s", msg); - ti_attn->msg_len = VERSION_LEN + BT_FRAME_LEN + - strlen(ti_attn->msg.file_info); + ti_attn->msg_len = cpu_to_be32(VERSION_LEN + BT_FRAME_LEN + + strlen(ti_attn->msg.file_info)); } void __attribute__((noreturn)) ibm_fsp_terminate(const char *msg) diff --git a/hw/fsp/fsp-codeupdate.c b/hw/fsp/fsp-codeupdate.c index 67732a739..13aa357e1 100644 --- a/hw/fsp/fsp-codeupdate.c +++ b/hw/fsp/fsp-codeupdate.c @@ -148,9 +148,11 @@ static void got_code_update_policy(uint32_t param_id __unused, int err_len, if (err_len != 4) { log_simple_error(&e_info(OPAL_RC_CU_INIT), "CUPD: Error " "retrieving code update policy: %d\n", err_len); - } else + } else { + update_policy = be32_to_cpu((__be32)update_policy); prlog(PR_NOTICE, "CUPD: Code update policy from FSP: %d\n", update_policy); + } dec_in_flight_param(); } @@ -175,9 +177,11 @@ static void got_platform_hmc_managed(uint32_t param_id __unused, int err_len, if (err_len != 4) { log_simple_error(&e_info(OPAL_RC_CU_INIT), "CUPD: Error " "retrieving hmc managed status: %d\n", err_len); - } else + } else { + hmc_managed = be32_to_cpu((__be32)hmc_managed); prlog(PR_NOTICE, "CUPD: HMC managed status from FSP: %d\n", hmc_managed); + } dec_in_flight_param(); } @@ -198,9 +202,9 @@ static void get_platform_hmc_managed(void) static bool fw_ipl_side_update_notify(struct fsp_msg *msg) { - u32 param_id = msg->data.words[0]; - int dlen = msg->data.words[1] & 0xffff; - uint32_t state = msg->data.words[2]; + u32 param_id = fsp_msg_get_data_word(msg, 0); + int dlen = fsp_msg_get_data_word(msg, 1) & 0xffff; + uint32_t state = fsp_msg_get_data_word(msg, 2); if (param_id != SYS_PARAM_FW_IPL_SIDE) return false; @@ -322,15 +326,15 @@ static void fetch_lid_data_complete(struct fsp_msg *msg) int rc; status = (msg->resp->word1 >> 8) & 0xff; - flags = (msg->data.words[0] >> 16) & 0xff; - id = msg->data.words[0] & 0xffff; - lid_id = msg->data.words[1]; - offset = msg->resp->data.words[1]; - length = msg->resp->data.words[2]; + flags = (fsp_msg_get_data_word(msg, 0) >> 16) & 0xff; + id = fsp_msg_get_data_word(msg, 0) & 0xffff; + lid_id = fsp_msg_get_data_word(msg, 1); + offset = fsp_msg_get_data_word(msg->resp, 1); + length = fsp_msg_get_data_word(msg->resp, 2); prlog(PR_NOTICE, "CUPD: Marker LID id : size : status = " "0x%x : 0x%x : 0x%x\n", - msg->data.words[1], msg->resp->data.words[2], status); + fsp_msg_get_data_word(msg, 1), fsp_msg_get_data_word(msg->resp, 2), status); fsp_freemsg(msg); @@ -783,7 +787,7 @@ static int validate_candidate_image(uint64_t buffer, memcpy(validate_buf, (void *)buffer, VALIDATE_BUF_SIZE); header = (struct update_image_header *)validate_buf; - if (validate_magic_num(be32_to_cpu(header->magic)) != 0) { + if (validate_magic_num(be16_to_cpu(header->magic)) != 0) { *result = VALIDATE_INVALID_IMG; rc = OPAL_SUCCESS; goto out; @@ -936,14 +940,15 @@ static int validate_ipl_side(void) } static int64_t fsp_opal_validate_flash(uint64_t buffer, - uint32_t *size, uint32_t *result) + __be32 *size, __be32 *result) { int64_t rc = 0; int offset; + uint32_t r; lock(&flash_lock); - rc = validate_candidate_image(buffer, *size, result); + rc = validate_candidate_image(buffer, be32_to_cpu(*size), &r); /* Fill output buffer * * Format: @@ -952,16 +957,15 @@ static int64_t fsp_opal_validate_flash(uint64_t buffer, * MLcurrent-T-imagecurrent-P-image<0x0A> * MLnew-T-imagenew-P-image<0x0A> */ - if (!rc && (*result != VALIDATE_FLASH_AUTH && - *result != VALIDATE_INVALID_IMG)) { + if (!rc && (r != VALIDATE_FLASH_AUTH && r != VALIDATE_INVALID_IMG)) { /* Clear output buffer */ memset((void *)buffer, 0, VALIDATE_BUF_SIZE); - offset = validate_out_buf_mi_data((void *)buffer, 0, *result); - offset += validate_out_buf_ml_data((void *)buffer, - offset, *result); - *size = offset; + offset = validate_out_buf_mi_data((void *)buffer, 0, r); + offset += validate_out_buf_ml_data((void *)buffer, offset, r); + *size = cpu_to_be32(offset); } + *result = cpu_to_be32(r); unlock(&flash_lock); return rc; @@ -1125,7 +1129,7 @@ static int64_t validate_sglist(struct opal_sg_list *list) return OPAL_PARAMETER; /* All non-terminal entries size must be aligned */ - if (prev_entry && (prev_entry->length & 0xfff)) + if (prev_entry && (be64_to_cpu(prev_entry->length) & 0xfff)) return OPAL_PARAMETER; prev_entry = entry; @@ -1200,7 +1204,7 @@ static bool code_update_notify(uint32_t cmd_sub_mod, struct fsp_msg *msg) case FSP_CMD_FLASH_CACHE: cmd = FSP_CMD_FLASH_CACHE_RSP; prlog(PR_NOTICE, "CUPD: Update LID cache event [data = 0x%x]\n", - msg->data.words[0]); + fsp_msg_get_data_word(msg, 0)); break; case FSP_CMD_FLASH_OUTC: case FSP_CMD_FLASH_OUTR: diff --git a/hw/fsp/fsp-codeupdate.h b/hw/fsp/fsp-codeupdate.h index 237043c8e..0262c69ce 100644 --- a/hw/fsp/fsp-codeupdate.h +++ b/hw/fsp/fsp-codeupdate.h @@ -76,17 +76,17 @@ struct fw_image_vpd { struct master_lid_header { char key[3]; /* "MLH" */ uint8_t version; /* 0x02 */ - uint16_t header_size; - uint16_t entry_size; + __be16 header_size; + __be16 entry_size; uint8_t reserved[56]; }; /* LID index entry */ struct lid_index_entry { - uint32_t id; - uint32_t size; - uint32_t offset; - uint32_t crc; + __be32 id; + __be32 size; + __be32 offset; + __be32 crc; }; /* SP flags */ @@ -99,7 +99,7 @@ struct lid_index_entry { * sp_flag addr = header->data + header->ext_fw_id_size */ struct update_image_ga_date { - uint32_t sp_flag; + __be32 sp_flag; char sp_ga_date[8]; /* YYYYMMDD */ }; @@ -108,39 +108,39 @@ struct update_image_ga_date { /* Image header structure */ struct update_image_header { - uint16_t magic; - uint16_t version; - uint32_t package_size; - uint32_t crc; - uint16_t lid_index_offset; - uint16_t number_lids; - uint16_t package_flags; - uint16_t mi_keyword_size; + __be16 magic; + __be16 version; + __be32 package_size; + __be32 crc; + __be16 lid_index_offset; + __be16 number_lids; + __be16 package_flags; + __be16 mi_keyword_size; char mi_keyword_data[40]; - uint16_t ext_fw_id_size; + __be16 ext_fw_id_size; /* Rest of the image data including ext fw id, sp flags */ char data[]; }; /* FipS header */ struct fips_header { - uint16_t magic; - uint16_t version; - uint32_t lid_id; - uint32_t lid_date; /* YYYYMMDD */ - uint16_t lid_time; /* HHMM */ - uint16_t lid_class; - uint32_t crc; - uint32_t lid_size; /* Number of bytes below header */ - uint32_t header_size; + __be16 magic; + __be16 version; + __be32 lid_id; + __be32 lid_date; /* YYYYMMDD */ + __be16 lid_time; /* HHMM */ + __be16 lid_class; + __be32 crc; + __be32 lid_size; /* Number of bytes below header */ + __be32 header_size; uint8_t mtd_number; uint8_t valid; /* 1 = valid, 0 = invalid */ uint8_t reserved; uint8_t lid_info_size; char lid_info[64]; /* code level */ - uint32_t update_date; /* YYYYMMDD */ - uint16_t update_time; /* HHMM */ - uint16_t phylum_len; + __be32 update_date; /* YYYYMMDD */ + __be16 update_time; /* HHMM */ + __be16 phylum_len; uint8_t lid_phylum[]; }; @@ -165,30 +165,30 @@ struct fips_header { * not all ADF sections in common marker LID. */ struct com_marker_header { - uint32_t version; - uint32_t MI_offset; /* Offset to MI section */ - uint32_t iseries_offset; + __be32 version; + __be32 MI_offset; /* Offset to MI section */ + __be32 iseries_offset; }; /* MI Keyword section */ struct com_marker_mi_section { - uint32_t MI_size; + __be32 MI_size; char mi_keyword[40]; /* MI Keyword */ char lst_disrupt_fix_lvl[3]; char skip[21]; /* Skip not interested fields */ - uint32_t adf_offset; /* Offset to ADF section */ + __be32 adf_offset; /* Offset to ADF section */ }; /* Additional Data Fields */ struct com_marker_adf_sec { - uint32_t adf_cnt; /* ADF count */ + __be32 adf_cnt; /* ADF count */ char adf_data[]; /* ADF data */ }; /* ADF common header */ struct com_marker_adf_header { - uint32_t size; /* Section size */ - uint32_t name; /* Section name */ + __be32 size; /* Section size */ + __be32 name; /* Section name */ }; /* @@ -200,9 +200,9 @@ struct com_marker_adf_header { struct com_marker_adf_sp { struct com_marker_adf_header header; - uint32_t sp_name_offset; /* Offset from start of ADF */ - uint32_t sp_name_size; - uint32_t skip[4]; /* Skip rest of fields */ + __be32 sp_name_offset; /* Offset from start of ADF */ + __be32 sp_name_size; + __be32 skip[4]; /* Skip rest of fields */ }; /* @@ -213,10 +213,10 @@ struct com_marker_adf_sp #define ADF_NAME_FW_IP 0x46495050 /* FIPP */ struct com_marker_fw_ip { struct com_marker_adf_header header; - uint32_t sp_flag_offset; /* Offset from start of ADF */ - uint32_t sp_flag_size; - uint32_t sp_ga_offset; /* Offset from start of ADF*/ - uint32_t sp_ga_size; + __be32 sp_flag_offset; /* Offset from start of ADF */ + __be32 sp_flag_size; + __be32 sp_ga_offset; /* Offset from start of ADF*/ + __be32 sp_ga_size; }; #endif /* __CODEUPDATE_H */ diff --git a/hw/fsp/fsp-console.c b/hw/fsp/fsp-console.c index 624efb469..05feb71fc 100644 --- a/hw/fsp/fsp-console.c +++ b/hw/fsp/fsp-console.c @@ -22,16 +22,16 @@ DEFINE_LOG_ENTRY(OPAL_RC_CONSOLE_HANG, OPAL_PLATFORM_ERR_EVT, OPAL_CONSOLE, OPAL_PREDICTIVE_ERR_GENERAL, OPAL_NA); struct fsp_serbuf_hdr { - u16 partition_id; + __be16 partition_id; u8 session_id; u8 hmc_id; - u16 data_offset; - u16 last_valid; - u16 ovf_count; - u16 next_in; + __be16 data_offset; + __be16 last_valid; + __be16 ovf_count; + __be16 next_in; u8 flags; u8 reserved; - u16 next_out; + __be16 next_out; u8 data[]; }; #define SER_BUF_DATA_SIZE (0x10000 - sizeof(struct fsp_serbuf_hdr)) @@ -158,13 +158,13 @@ static size_t fsp_write_vserial(struct fsp_serial *fs, const char *buf, size_t len) { struct fsp_serbuf_hdr *sb = fs->out_buf; - u16 old_nin = sb->next_in; + u16 old_nin = be16_to_cpu(sb->next_in); u16 space, chunk; if (!fs->open) return 0; - space = (sb->next_out + SER_BUF_DATA_SIZE - old_nin - 1) + space = (be16_to_cpu(sb->next_out) + SER_BUF_DATA_SIZE - old_nin - 1) % SER_BUF_DATA_SIZE; if (space < len) len = space; @@ -178,10 +178,10 @@ static size_t fsp_write_vserial(struct fsp_serial *fs, const char *buf, if (chunk < len) memcpy(&sb->data[0], buf + chunk, len - chunk); lwsync(); - sb->next_in = (old_nin + len) % SER_BUF_DATA_SIZE; + sb->next_in = cpu_to_be16((old_nin + len) % SER_BUF_DATA_SIZE); sync(); - if (sb->next_out == old_nin && fs->poke_msg) { + if (be16_to_cpu(sb->next_out) == old_nin && fs->poke_msg) { if (fs->poke_msg->state == fsp_msg_unused) { if (fsp_queue_msg(fs->poke_msg, fsp_pokemsg_reclaim)) prerror("FSPCON: poke msg queuing failed\n"); @@ -229,8 +229,8 @@ static void fsp_open_vserial(struct fsp_msg *msg) { struct fsp_msg *resp; - u16 part_id = msg->data.words[0] & 0xffff; - u16 sess_id = msg->data.words[1] & 0xffff; + u16 part_id = fsp_msg_get_data_word(msg, 0) & 0xffff; + u16 sess_id = fsp_msg_get_data_word(msg, 1) & 0xffff; u8 hmc_sess = msg->data.bytes[0]; u8 hmc_indx = msg->data.bytes[1]; u8 authority = msg->data.bytes[4]; @@ -285,8 +285,8 @@ static void fsp_open_vserial(struct fsp_msg *msg) } fs->poke_msg = fsp_mkmsg(FSP_CMD_VSERIAL_OUT, 2, - msg->data.words[0], - msg->data.words[1] & 0xffff); + fsp_msg_get_data_word(msg, 0), + fsp_msg_get_data_word(msg, 1) & 0xffff); if (fs->poke_msg == NULL) { prerror("FSPCON: Failed to allocate poke_msg\n"); unlock(&fsp_con_lock); @@ -296,13 +296,13 @@ static void fsp_open_vserial(struct fsp_msg *msg) fs->open = true; fs->poke_msg->user_data = fs; - fs->in_buf->partition_id = fs->out_buf->partition_id = part_id; + fs->in_buf->partition_id = fs->out_buf->partition_id = cpu_to_be16(part_id); fs->in_buf->session_id = fs->out_buf->session_id = sess_id; fs->in_buf->hmc_id = fs->out_buf->hmc_id = hmc_indx; fs->in_buf->data_offset = fs->out_buf->data_offset = - sizeof(struct fsp_serbuf_hdr); + cpu_to_be16(sizeof(struct fsp_serbuf_hdr)); fs->in_buf->last_valid = fs->out_buf->last_valid = - SER_BUF_DATA_SIZE - 1; + cpu_to_be16(SER_BUF_DATA_SIZE - 1); fs->in_buf->ovf_count = fs->out_buf->ovf_count = 0; fs->in_buf->next_in = fs->out_buf->next_in = 0; fs->in_buf->flags = fs->out_buf->flags = 0; @@ -313,8 +313,8 @@ static void fsp_open_vserial(struct fsp_msg *msg) unlock(&fsp_con_lock); already_open: - resp = fsp_mkmsg(FSP_RSP_OPEN_VSERIAL, 6, msg->data.words[0], - msg->data.words[1] & 0xffff, 0, tce_in, 0, tce_out); + resp = fsp_mkmsg(FSP_RSP_OPEN_VSERIAL, 6, fsp_msg_get_data_word(msg, 0), + fsp_msg_get_data_word(msg, 1) & 0xffff, 0, tce_in, 0, tce_out); if (!resp) { prerror("FSPCON: Failed to allocate open msg response\n"); return; @@ -347,8 +347,8 @@ static void fsp_open_vserial(struct fsp_msg *msg) static void fsp_close_vserial(struct fsp_msg *msg) { - u16 part_id = msg->data.words[0] & 0xffff; - u16 sess_id = msg->data.words[1] & 0xffff; + u16 part_id = fsp_msg_get_data_word(msg, 0) & 0xffff; + u16 sess_id = fsp_msg_get_data_word(msg, 1) & 0xffff; u8 hmc_sess = msg->data.bytes[0]; u8 hmc_indx = msg->data.bytes[1]; u8 authority = msg->data.bytes[4]; @@ -399,8 +399,8 @@ static void fsp_close_vserial(struct fsp_msg *msg) } unlock(&fsp_con_lock); skip_close: - resp = fsp_mkmsg(FSP_RSP_CLOSE_VSERIAL, 2, msg->data.words[0], - msg->data.words[1] & 0xffff); + resp = fsp_mkmsg(FSP_RSP_CLOSE_VSERIAL, 2, fsp_msg_get_data_word(msg, 0), + fsp_msg_get_data_word(msg, 1) & 0xffff); if (!resp) { prerror("FSPCON: Failed to allocate close msg response\n"); return; @@ -437,7 +437,7 @@ static bool fsp_con_msg_hmc(u32 cmd_sub_mod, struct fsp_msg *msg) prlog(PR_DEBUG, "FSPCON: Got HMC interface query\n"); got_intf_query = true; resp = fsp_mkmsg(FSP_RSP_HMC_INTF_QUERY, 1, - msg->data.words[0] & 0x00ffffff); + fsp_msg_get_data_word(msg, 0) & 0x00ffffff); if (!resp) { prerror("FSPCON: Failed to allocate hmc intf response\n"); return true; @@ -453,7 +453,7 @@ static bool fsp_con_msg_hmc(u32 cmd_sub_mod, struct fsp_msg *msg) static bool fsp_con_msg_vt(u32 cmd_sub_mod, struct fsp_msg *msg) { - u16 sess_id = msg->data.words[1] & 0xffff; + u16 sess_id = fsp_msg_get_data_word(msg, 1) & 0xffff; if (cmd_sub_mod == FSP_CMD_VSERIAL_IN && sess_id < MAX_SERIAL) { struct fsp_serial *fs = &fsp_serials[sess_id]; @@ -610,7 +610,8 @@ static int64_t fsp_console_write(int64_t term_number, __be64 *__length, #ifdef OPAL_DEBUG_CONSOLE_IO prlog(PR_TRACE, "OPAL: console write req=%ld written=%ld" " ni=%d no=%d\n", - requested, written, fs->out_buf->next_in, fs->out_buf->next_out); + requested, written, be16_to_cpu(fs->out_buf->next_in), + be16_to_cpu(fs->out_buf->next_out)); prlog(PR_TRACE, " %02x %02x %02x %02x " "%02x \'%c\' %02x \'%c\' %02x \'%c\'.%02x \'%c\'..\n", buffer[0], buffer[1], buffer[2], buffer[3], @@ -646,7 +647,8 @@ static int64_t fsp_console_write_buffer_space(int64_t term_number, return OPAL_CLOSED; } sb = fs->out_buf; - length = (sb->next_out + SER_BUF_DATA_SIZE - sb->next_in - 1) + length = (be16_to_cpu(sb->next_out) + SER_BUF_DATA_SIZE + - be16_to_cpu(sb->next_in) - 1) % SER_BUF_DATA_SIZE; unlock(&fsp_con_lock); @@ -712,9 +714,9 @@ static int64_t fsp_console_read(int64_t term_number, __be64 *__length, if (fs->waiting) fs->waiting = 0; sb = fs->in_buf; - old_nin = sb->next_in; + old_nin = be16_to_cpu(sb->next_in); lwsync(); - n = (old_nin + SER_BUF_DATA_SIZE - sb->next_out) + n = (old_nin + SER_BUF_DATA_SIZE - be16_to_cpu(sb->next_out)) % SER_BUF_DATA_SIZE; if (n > req) { pending = true; @@ -722,17 +724,17 @@ static int64_t fsp_console_read(int64_t term_number, __be64 *__length, } *__length = cpu_to_be64(n); - chunk = SER_BUF_DATA_SIZE - sb->next_out; + chunk = SER_BUF_DATA_SIZE - be16_to_cpu(sb->next_out); if (chunk > n) chunk = n; - memcpy(buffer, &sb->data[sb->next_out], chunk); + memcpy(buffer, &sb->data[be16_to_cpu(sb->next_out)], chunk); if (chunk < n) memcpy(buffer + chunk, &sb->data[0], n - chunk); - sb->next_out = (sb->next_out + n) % SER_BUF_DATA_SIZE; + sb->next_out = cpu_to_be16(((be16_to_cpu(sb->next_out)) + n) % SER_BUF_DATA_SIZE); #ifdef OPAL_DEBUG_CONSOLE_IO prlog(PR_TRACE, "OPAL: console read req=%d read=%d ni=%d no=%d\n", - req, n, sb->next_in, sb->next_out); + req, n, be16_to_cpu(sb->next_in), be16_to_cpu(sb->next_out)); prlog(PR_TRACE, " %02x %02x %02x %02x %02x %02x %02x %02x ...\n", buffer[0], buffer[1], buffer[2], buffer[3], buffer[4], buffer[5], buffer[6], buffer[7]); @@ -809,7 +811,8 @@ void fsp_console_poll(void *data __unused) if (debug < 5) { prlog(PR_DEBUG,"OPAL: %d still pending" " ni=%d no=%d\n", - i, sb->next_in, sb->next_out); + i, be16_to_cpu(sb->next_in), + be16_to_cpu(sb->next_out)); debug++; } #endif /* OPAL_DEBUG_CONSOLE_POLL */ @@ -918,8 +921,8 @@ static bool send_all_hvsi_close(void) /* Do we have room ? Wait a bit if not */ while(timeout--) { - space = (sb->next_out + SER_BUF_DATA_SIZE - - sb->next_in - 1) % SER_BUF_DATA_SIZE; + space = (be16_to_cpu(sb->next_out) + SER_BUF_DATA_SIZE - + be16_to_cpu(sb->next_in) - 1) % SER_BUF_DATA_SIZE; if (space >= 6) break; time_wait_ms(500); diff --git a/hw/fsp/fsp-diag.c b/hw/fsp/fsp-diag.c index 0ee8975a8..9d1a35017 100644 --- a/hw/fsp/fsp-diag.c +++ b/hw/fsp/fsp-diag.c @@ -29,7 +29,7 @@ static bool fsp_diag_msg(u32 cmd_sub_mod, struct fsp_msg *msg) } printf("BUG: High Level ACK timeout (FSP_MCLASS_DIAG) for 0x%x\n", - msg->data.words[0] & 0xffff0000); + fsp_msg_get_data_word(msg, 0) & 0xffff0000); return true; } diff --git a/hw/fsp/fsp-dpo.c b/hw/fsp/fsp-dpo.c index 0796d9ae9..8f0861ed4 100644 --- a/hw/fsp/fsp-dpo.c +++ b/hw/fsp/fsp-dpo.c @@ -28,14 +28,14 @@ static unsigned long fsp_dpo_init_tb; * of seconds remaining for a forced system shutdown. This will enable * the host to schedule for shutdown voluntarily before timeout occurs. */ -static int64_t fsp_opal_get_dpo_status(int64_t *dpo_timeout) +static int64_t fsp_opal_get_dpo_status(__be64 *dpo_timeout) { if (!fsp_dpo_pending) { *dpo_timeout = 0; return OPAL_WRONG_STATE; } - *dpo_timeout = DPO_TIMEOUT - tb_to_secs(mftb() - fsp_dpo_init_tb); + *dpo_timeout = cpu_to_be64(DPO_TIMEOUT - tb_to_secs(mftb() - fsp_dpo_init_tb)); return OPAL_SUCCESS; } diff --git a/hw/fsp/fsp-dump.c b/hw/fsp/fsp-dump.c index 37efa9d5b..bf72438ea 100644 --- a/hw/fsp/fsp-dump.c +++ b/hw/fsp/fsp-dump.c @@ -356,8 +356,8 @@ static int64_t fsp_opal_dump_init(uint8_t dump_type) /* * OPAL interface to send dump information to Linux. */ -static int64_t fsp_opal_dump_info2(uint32_t *dump_id, uint32_t *dump_size, - uint32_t *dump_type) +static int64_t fsp_opal_dump_info2(__be32 *dump_id, __be32 *dump_size, + __be32 *dump_type) { struct dump_record *record; int rc = OPAL_SUCCESS; @@ -373,18 +373,18 @@ static int64_t fsp_opal_dump_info2(uint32_t *dump_id, uint32_t *dump_size, rc = OPAL_INTERNAL_ERROR; goto out; } - *dump_id = record->id; - *dump_size = record->size; - *dump_type = record->type; + *dump_id = cpu_to_be32(record->id); + *dump_size = cpu_to_be32(record->size); + *dump_type = cpu_to_be32(record->type); out: unlock(&dump_lock); return rc; } -static int64_t fsp_opal_dump_info(uint32_t *dump_id, uint32_t *dump_size) +static int64_t fsp_opal_dump_info(__be32 *dump_id, __be32 *dump_size) { - uint32_t dump_type; + __be32 dump_type; return fsp_opal_dump_info2(dump_id, dump_size, &dump_type); } @@ -505,11 +505,11 @@ static void dump_read_complete(struct fsp_msg *msg) bool compl = false; status = (msg->resp->word1 >> 8) & 0xff; - flags = (msg->data.words[0] >> 16) & 0xff; - id = msg->data.words[0] & 0xffff; - dump_id = msg->data.words[1]; - offset = msg->resp->data.words[1]; - length = msg->resp->data.words[2]; + flags = (fsp_msg_get_data_word(msg, 0) >> 16) & 0xff; + id = fsp_msg_get_data_word(msg, 0) & 0xffff; + dump_id = fsp_msg_get_data_word(msg, 1); + offset = fsp_msg_get_data_word(msg->resp, 1); + length = fsp_msg_get_data_word(msg->resp, 2); fsp_freemsg(msg); @@ -654,9 +654,9 @@ static void dump_ack_complete(struct fsp_msg *msg) if (status) log_simple_error(&e_info(OPAL_RC_DUMP_ACK), "DUMP: ACK failed for ID: 0x%x\n", - msg->data.words[0]); + fsp_msg_get_data_word(msg, 0)); else - printf("DUMP: ACKed dump ID: 0x%x\n", msg->data.words[0]); + printf("DUMP: ACKed dump ID: 0x%x\n", fsp_msg_get_data_word(msg, 0)); fsp_freemsg(msg); } @@ -807,10 +807,11 @@ static bool fsp_sys_dump_notify(uint32_t cmd_sub_mod, struct fsp_msg *msg) return false; printf("DUMP: Platform dump available. ID = 0x%x [size: %d bytes]\n", - msg->data.words[0], msg->data.words[1]); + fsp_msg_get_data_word(msg, 0), fsp_msg_get_data_word(msg, 1)); add_dump_id_to_list(DUMP_TYPE_SYS, - msg->data.words[0], msg->data.words[1]); + fsp_msg_get_data_word(msg, 0), + fsp_msg_get_data_word(msg, 1)); return true; } diff --git a/hw/fsp/fsp-elog-read.c b/hw/fsp/fsp-elog-read.c index 5b373aa80..fb81320b8 100644 --- a/hw/fsp/fsp-elog-read.c +++ b/hw/fsp/fsp-elog-read.c @@ -265,13 +265,13 @@ static void fsp_elog_queue_fetch(void) } /* OPAL interface for PowerNV to read log size and log ID from Sapphire. */ -static int64_t fsp_opal_elog_info(uint64_t *opal_elog_id, - uint64_t *opal_elog_size, uint64_t *elog_type) +static int64_t fsp_opal_elog_info(__be64 *opal_elog_id, + __be64 *opal_elog_size, __be64 *elog_type) { struct fsp_log_entry *log_data; /* Copy type of the error log */ - *elog_type = ELOG_TYPE_PEL; + *elog_type = cpu_to_be64(ELOG_TYPE_PEL); /* Check if any OPAL log needs to be reported to the host */ if (opal_elog_info(opal_elog_id, opal_elog_size)) @@ -298,15 +298,15 @@ static int64_t fsp_opal_elog_info(uint64_t *opal_elog_id, return OPAL_WRONG_STATE; } - *opal_elog_id = log_data->log_id; - *opal_elog_size = log_data->log_size; + *opal_elog_id = cpu_to_be64(log_data->log_id); + *opal_elog_size = cpu_to_be64(log_data->log_size); fsp_elog_set_head_state(ELOG_STATE_HOST_INFO); unlock(&elog_read_lock); return OPAL_SUCCESS; } /* OPAL interface for PowerNV to read log from Sapphire. */ -static int64_t fsp_opal_elog_read(uint64_t *buffer, uint64_t opal_elog_size, +static int64_t fsp_opal_elog_read(void *buffer, uint64_t opal_elog_size, uint64_t opal_elog_id) { int size = opal_elog_size; @@ -350,8 +350,8 @@ static int64_t fsp_opal_elog_read(uint64_t *buffer, uint64_t opal_elog_size, if (opal_elog_size > log_data->log_size) size = log_data->log_size; - memset((void *)buffer, 0, opal_elog_size); - memcpy((void *)buffer, elog_read_buffer, size); + memset(buffer, 0, opal_elog_size); + memcpy(buffer, elog_read_buffer, size); /* * Once log is read from linux move record from pending @@ -483,8 +483,8 @@ static bool fsp_elog_msg(uint32_t cmd_sub_mod, struct fsp_msg *msg) if (cmd_sub_mod != FSP_CMD_ERRLOG_NOTIFICATION) return false; - log_id = msg->data.words[0]; - log_size = msg->data.words[1]; + log_id = fsp_msg_get_data_word(msg, 0); + log_size = fsp_msg_get_data_word(msg, 1); prlog(PR_TRACE, "ELOG: Notified of log 0x%08x (size: %d)\n", log_id, log_size); diff --git a/hw/fsp/fsp-elog-write.c b/hw/fsp/fsp-elog-write.c index 6aa0c5909..1776c965d 100644 --- a/hw/fsp/fsp-elog-write.c +++ b/hw/fsp/fsp-elog-write.c @@ -122,7 +122,7 @@ static inline void fsp_elog_write_set_head_state(enum elog_head_state state) elog_write_to_host_head_state = state; } -bool opal_elog_info(uint64_t *opal_elog_id, uint64_t *opal_elog_size) +bool opal_elog_info(__be64 *opal_elog_id, __be64 *opal_elog_size) { struct errorlog *head; bool rc = false; @@ -143,8 +143,8 @@ bool opal_elog_info(uint64_t *opal_elog_id, uint64_t *opal_elog_size) __func__); fsp_elog_write_set_head_state(ELOG_STATE_NONE); } else { - *opal_elog_id = head->plid; - *opal_elog_size = head->log_size; + *opal_elog_id = cpu_to_be64(head->plid); + *opal_elog_size = cpu_to_be64(head->log_size); fsp_elog_write_set_head_state(ELOG_STATE_HOST_INFO); rc = true; } @@ -172,7 +172,7 @@ static void opal_commit_elog_in_host(void) unlock(&elog_write_to_host_lock); } -bool opal_elog_read(uint64_t *buffer, uint64_t opal_elog_size, +bool opal_elog_read(void *buffer, uint64_t opal_elog_size, uint64_t opal_elog_id) { struct errorlog *log_data; @@ -194,8 +194,7 @@ bool opal_elog_read(uint64_t *buffer, uint64_t opal_elog_size, return rc; } - memcpy((void *)buffer, elog_write_to_host_buffer, - opal_elog_size); + memcpy(buffer, elog_write_to_host_buffer, opal_elog_size); list_del(&log_data->link); list_add(&elog_write_to_host_processed, &log_data->link); fsp_elog_write_set_head_state(ELOG_STATE_NONE); diff --git a/hw/fsp/fsp-epow.c b/hw/fsp/fsp-epow.c index bac1d3df7..300a44136 100644 --- a/hw/fsp/fsp-epow.c +++ b/hw/fsp/fsp-epow.c @@ -120,11 +120,11 @@ static void fsp_process_epow(struct fsp_msg *msg, int epow_type) * and then updates the length variable back to reflect the * number of EPOW sub classes it has updated the buffer with. */ -static int64_t fsp_opal_get_epow_status(int16_t *out_epow, - int16_t *length) +static int64_t fsp_opal_get_epow_status(__be16 *out_epow, __be16 *length) { int i; int n_epow_class; + int l = be16_to_cpu(*length); /* * There can be situations where the host and the Sapphire versions @@ -144,16 +144,16 @@ static int64_t fsp_opal_get_epow_status(int16_t *out_epow, * Sapphire sends out EPOW status for sub classes host knows about * and can interpret correctly. */ - if (*length >= OPAL_SYSEPOW_MAX) { + if (l >= OPAL_SYSEPOW_MAX) { n_epow_class = OPAL_SYSEPOW_MAX; - *length = OPAL_SYSEPOW_MAX; + *length = cpu_to_be16(OPAL_SYSEPOW_MAX); } else { - n_epow_class = *length; + n_epow_class = l; } /* Transfer EPOW Status */ for (i = 0; i < n_epow_class; i++) - out_epow[i] = epow_status[i]; + out_epow[i] = cpu_to_be16(epow_status[i]); return OPAL_SUCCESS; } diff --git a/hw/fsp/fsp-ipmi.c b/hw/fsp/fsp-ipmi.c index f57a3df9c..f62f18c14 100644 --- a/hw/fsp/fsp-ipmi.c +++ b/hw/fsp/fsp-ipmi.c @@ -85,7 +85,7 @@ static void fsp_ipmi_cmd_done(uint8_t cmd, uint8_t netfn, uint8_t cc) static void fsp_ipmi_req_complete(struct fsp_msg *msg) { uint8_t status = (msg->resp->word1 >> 8) & 0xff; - uint32_t length = msg->resp->data.words[0]; + uint32_t length = fsp_msg_get_data_word(msg->resp, 0); struct fsp_ipmi_msg *fsp_ipmi_msg = msg->user_data; struct ipmi_msg *ipmi_msg; @@ -308,8 +308,8 @@ static bool fsp_ipmi_send_response(uint32_t cmd) static bool fsp_ipmi_read_response(struct fsp_msg *msg) { uint8_t *resp_buf = fsp_ipmi.ipmi_resp_buf; - uint32_t status = msg->data.words[3]; - uint32_t length = msg->data.words[2]; + uint32_t status = fsp_msg_get_data_word(msg, 3); + uint32_t length = fsp_msg_get_data_word(msg, 2); struct ipmi_msg *ipmi_msg; uint8_t netfn, cmd, cc; @@ -317,7 +317,7 @@ static bool fsp_ipmi_read_response(struct fsp_msg *msg) ipmi_msg = &fsp_ipmi.cur_msg->ipmi_msg; /* Response TCE token */ - assert(msg->data.words[1] == PSI_DMA_PLAT_RESP_BUF); + assert(fsp_msg_get_data_word(msg, 1) == PSI_DMA_PLAT_RESP_BUF); if (status != FSP_STATUS_SUCCESS) { if(status == FSP_STATUS_DMA_ERROR) diff --git a/hw/fsp/fsp-leds.c b/hw/fsp/fsp-leds.c index 9e89f20d0..58dfab37a 100644 --- a/hw/fsp/fsp-leds.c +++ b/hw/fsp/fsp-leds.c @@ -308,7 +308,7 @@ static void fsp_get_sai_complete(struct fsp_msg *msg) prlog(PR_ERR, "Read real SAI cmd failed [rc = 0x%x].\n", rc); } else { /* Update SAI state */ lock(&sai_lock); - sai_data.state = msg->resp->data.words[0] & 0xff; + sai_data.state = fsp_msg_get_data_word(msg->resp, 0) & 0xff; unlock(&sai_lock); prlog(PR_TRACE, "SAI initial state = 0x%x\n", sai_data.state); @@ -346,25 +346,25 @@ static void fsp_get_sai(void) static bool sai_update_notification(struct fsp_msg *msg) { - uint32_t *state = &msg->data.words[2]; - uint32_t param_id = msg->data.words[0]; - int len = msg->data.words[1] & 0xffff; + uint32_t state = fsp_msg_get_data_word(msg, 2); + uint32_t param_id = fsp_msg_get_data_word(msg, 0); + int len = fsp_msg_get_data_word(msg, 1) & 0xffff; if (param_id != SYS_PARAM_REAL_SAI && param_id != SYS_PARAM_PLAT_SAI) return false; - if ( len != 4) + if (len != 4) return false; - if (*state != LED_STATE_ON && *state != LED_STATE_OFF) + if (state != LED_STATE_ON && state != LED_STATE_OFF) return false; /* Update SAI state */ lock(&sai_lock); - sai_data.state = *state; + sai_data.state = state; unlock(&sai_lock); - prlog(PR_TRACE, "SAI updated. New SAI state = 0x%x\n", *state); + prlog(PR_TRACE, "SAI updated. New SAI state = 0x%x\n", state); return true; } @@ -559,7 +559,7 @@ static int fsp_msg_set_led_state(struct led_set_cmd *spcn_cmd) */ spcn_cmd->ckpt_status = led->status; spcn_cmd->ckpt_excl_bit = led->excl_bit; - sled.state = led->status; + sled.state = cpu_to_be16(led->status); /* Update the exclussive LED bits */ if (is_enclosure_led(spcn_cmd->loc_code)) { @@ -581,24 +581,24 @@ static int fsp_msg_set_led_state(struct led_set_cmd *spcn_cmd) /* LED FAULT commad */ if (spcn_cmd->command == LED_COMMAND_FAULT) { if (spcn_cmd->state == LED_STATE_ON) - sled.state |= SPCN_LED_FAULT_MASK; + sled.state |= cpu_to_be16(SPCN_LED_FAULT_MASK); if (spcn_cmd->state == LED_STATE_OFF) - sled.state &= ~SPCN_LED_FAULT_MASK; + sled.state &= cpu_to_be16(~SPCN_LED_FAULT_MASK); } /* LED IDENTIFY command */ if (spcn_cmd->command == LED_COMMAND_IDENTIFY) { if (spcn_cmd->state == LED_STATE_ON) - sled.state |= SPCN_LED_IDENTIFY_MASK; + sled.state |= cpu_to_be16(SPCN_LED_IDENTIFY_MASK); if (spcn_cmd->state == LED_STATE_OFF) - sled.state &= ~SPCN_LED_IDENTIFY_MASK; + sled.state &= cpu_to_be16(~SPCN_LED_IDENTIFY_MASK); } /* Write into SPCN TCE buffer */ buf_write(buf, u8, sled.lc_len); /* Location code length */ memcpy(buf, sled.lc_code, sled.lc_len); /* Location code */ buf += sled.lc_len; - buf_write(buf, u16, sled.state); /* LED state */ + buf_write(buf, __be16, sled.state); /* LED state */ msg = fsp_mkmsg(FSP_CMD_SPCN_PASSTHRU, 4, SPCN_ADDR_MODE_CEC_NODE, cmd_hdr, 0, PSI_DMA_LED_BUF); @@ -612,7 +612,7 @@ static int fsp_msg_set_led_state(struct led_set_cmd *spcn_cmd) * Update the local lists based on the attempted SPCN command to * set/reset an individual led (CEC or ENCL). */ - update_led_list(spcn_cmd->loc_code, sled.state, led->excl_bit); + update_led_list(spcn_cmd->loc_code, be16_to_cpu(sled.state), led->excl_bit); msg->user_data = spcn_cmd; rc = fsp_queue_msg(msg, fsp_spcn_set_led_completion); @@ -775,20 +775,20 @@ static u32 fsp_push_data_to_tce(struct fsp_led_data *led, u8 *out_data, lcode.fld_sz = sizeof(lcode.loc_code); /* Rest of the structure */ - lcode.size = sizeof(lcode); + lcode.size = cpu_to_be16(sizeof(lcode)); lcode.status &= 0x0f; /* * Check for outbound buffer overflow. If there are still * more LEDs to be sent across to FSP, don't send, ignore. */ - if ((total_size + lcode.size) > PSI_DMA_LOC_COD_BUF_SZ) + if ((total_size + be16_to_cpu(lcode.size)) > PSI_DMA_LOC_COD_BUF_SZ) return 0; /* Copy over to the buffer */ memcpy(out_data, &lcode, sizeof(lcode)); - return lcode.size; + return be16_to_cpu(lcode.size); } /* @@ -904,7 +904,7 @@ static void fsp_ret_loc_code_list(u16 req_type, char *loc_code) static void fsp_get_led_list(struct fsp_msg *msg) { struct fsp_loc_code_req req; - u32 tce_token = msg->data.words[1]; + u32 tce_token = fsp_msg_get_data_word(msg, 1); void *buf; /* Parse inbound buffer */ @@ -929,9 +929,9 @@ static void fsp_get_led_list(struct fsp_msg *msg) memcpy(&req, buf, sizeof(req)); prlog(PR_TRACE, "Request for loc code list type 0x%04x LC=%s\n", - req.req_type, req.loc_code); + be16_to_cpu(req.req_type), req.loc_code); - fsp_ret_loc_code_list(req.req_type, req.loc_code); + fsp_ret_loc_code_list(be16_to_cpu(req.req_type), req.loc_code); } /* @@ -944,7 +944,7 @@ static void fsp_get_led_list(struct fsp_msg *msg) */ static void fsp_free_led_list_buf(struct fsp_msg *msg) { - u32 tce_token = msg->data.words[1]; + u32 tce_token = fsp_msg_get_data_word(msg, 1); u32 cmd = FSP_RSP_RET_LED_BUFFER; struct fsp_msg *resp; @@ -1039,7 +1039,7 @@ static void fsp_ret_led_state(char *loc_code) static void fsp_get_led_state(struct fsp_msg *msg) { struct fsp_get_ind_state_req req; - u32 tce_token = msg->data.words[1]; + u32 tce_token = fsp_msg_get_data_word(msg, 1); void *buf; /* Parse the inbound buffer */ @@ -1091,7 +1091,7 @@ static void fsp_set_led_state(struct fsp_msg *msg) { struct fsp_set_ind_state_req req; struct fsp_led_data *led, *next; - u32 tce_token = msg->data.words[1]; + u32 tce_token = fsp_msg_get_data_word(msg, 1); bool command, state; void *buf; int rc; @@ -1107,8 +1107,8 @@ static void fsp_set_led_state(struct fsp_msg *msg) prlog(PR_TRACE, "%s: tce=0x%08x buf=%p rq.sz=%d rq.typ=0x%04x" " rq.lc_len=%d rq.fld_sz=%d LC: %02x %02x %02x %02x....\n", - __func__, tce_token, buf, req.size, req.lc_len, req.fld_sz, - req.req_type, + __func__, tce_token, buf, be16_to_cpu(req.size), req.lc_len, req.fld_sz, + be16_to_cpu(req.req_type), req.loc_code[0], req.loc_code[1], req.loc_code[2], req.loc_code[3]); @@ -1129,7 +1129,7 @@ static void fsp_set_led_state(struct fsp_msg *msg) LED_STATE_ON : LED_STATE_OFF; /* Handle requests */ - switch (req.req_type) { + switch (be16_to_cpu(req.req_type)) { case SET_IND_ENCLOSURE: list_for_each_safe(&cec_ledq, led, next, link) { /* Only descendants of the same enclosure */ @@ -1261,12 +1261,11 @@ static struct fsp_client fsp_indicator_client = { }; -static int fsp_opal_get_sai(u64 *led_mask, u64 *led_value) +static int fsp_opal_get_sai(__be64 *led_mask, __be64 *led_value) { - *led_mask |= OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ATTN; + *led_mask |= cpu_to_be64(OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ATTN); if (sai_data.state & OPAL_SLOT_LED_STATE_ON) - *led_value |= - OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ATTN; + *led_value |= cpu_to_be64(OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ATTN); return OPAL_SUCCESS; } @@ -1309,8 +1308,8 @@ static int fsp_opal_set_sai(uint64_t async_token, char *loc_code, * number of LED type it understands and updates 'led_mask', 'led_value' * based on that maximum value of LED types. */ -static int64_t fsp_opal_leds_get_ind(char *loc_code, u64 *led_mask, - u64 *led_value, u64 *max_led_type) +static int64_t fsp_opal_leds_get_ind(char *loc_code, __be64 *led_mask, + __be64 *led_value, __be64 *max_led_type) { bool supported = true; int64_t max; @@ -1325,14 +1324,16 @@ static int64_t fsp_opal_leds_get_ind(char *loc_code, u64 *led_mask, if (led_support != LED_STATE_PRESENT) return OPAL_HARDWARE; + max = be64_to_cpu(*max_led_type); + /* Adjust max LED type */ - if (*max_led_type > OPAL_SLOT_LED_TYPE_MAX) { + if (max > OPAL_SLOT_LED_TYPE_MAX) { supported = false; - *max_led_type = OPAL_SLOT_LED_TYPE_MAX; + max = OPAL_SLOT_LED_TYPE_MAX; + *max_led_type = cpu_to_be64(max); } /* Invalid parameter */ - max = *max_led_type; if (max <= 0) return OPAL_PARAMETER; @@ -1352,20 +1353,18 @@ static int64_t fsp_opal_leds_get_ind(char *loc_code, u64 *led_mask, /* Identify LED */ --max; - *led_mask |= OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ID; + *led_mask |= cpu_to_be64(OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ID); if (led->status & SPCN_LED_IDENTIFY_MASK) - *led_value |= - OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ID; + *led_value |= cpu_to_be64(OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_ID); /* Fault LED */ if (!max) return OPAL_SUCCESS; --max; - *led_mask |= OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_FAULT; + *led_mask |= cpu_to_be64(OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_FAULT); if (led->status & SPCN_LED_FAULT_MASK) - *led_value |= - OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_FAULT; + *led_value |= cpu_to_be64(OPAL_SLOT_LED_STATE_ON << OPAL_SLOT_LED_TYPE_FAULT); /* OPAL doesn't support all the LED type requested by payload */ if (!supported) @@ -1401,7 +1400,7 @@ static int64_t fsp_opal_leds_get_ind(char *loc_code, u64 *led_mask, */ static int64_t fsp_opal_leds_set_ind(uint64_t async_token, char *loc_code, const u64 led_mask, - const u64 led_value, u64 *max_led_type) + const u64 led_value, __be64 *max_led_type) { bool supported = true; int command, state, rc = OPAL_SUCCESS; @@ -1416,13 +1415,15 @@ static int64_t fsp_opal_leds_set_ind(uint64_t async_token, if (led_support != LED_STATE_PRESENT) return OPAL_HARDWARE; + max = be64_to_cpu(*max_led_type); + /* Adjust max LED type */ - if (*max_led_type > OPAL_SLOT_LED_TYPE_MAX) { + if (max > OPAL_SLOT_LED_TYPE_MAX) { supported = false; - *max_led_type = OPAL_SLOT_LED_TYPE_MAX; + max = OPAL_SLOT_LED_TYPE_MAX; + *max_led_type = cpu_to_be64(max); } - max = *max_led_type; /* Invalid parameter */ if (max <= 0) return OPAL_PARAMETER; @@ -1623,13 +1624,15 @@ static void fsp_process_leds_data(u16 len) buf = led_buffer; while (len) { size_t lc_len; + __be16 tmp; /* Prepare */ led_data = zalloc(sizeof(struct fsp_led_data)); assert(led_data); /* Resource ID */ - buf_read(buf, u16, &led_data->rid); + buf_read(buf, __be16, &tmp); + led_data->rid = be16_to_cpu(tmp); len -= sizeof(led_data->rid); /* Location code length */ @@ -1653,11 +1656,13 @@ static void fsp_process_leds_data(u16 len) len -= led_data->lc_len; /* Parameters */ - buf_read(buf, u16, &led_data->parms); + buf_read(buf, __be16, &tmp); + led_data->parms = be16_to_cpu(tmp); len -= sizeof(led_data->parms); /* Status */ - buf_read(buf, u16, &led_data->status); + buf_read(buf, __be16, &tmp); + led_data->status = be16_to_cpu(tmp); len -= sizeof(led_data->status); /* @@ -1744,8 +1749,8 @@ static void fsp_read_leds_data_complete(struct fsp_msg *msg) int rc = 0; u32 msg_status = resp->word1 & 0xff00; - u32 led_status = (resp->data.words[1] >> 24) & 0xff; - u16 data_len = (u16)(resp->data.words[1] & 0xffff); + u32 led_status = (fsp_msg_get_data_word(resp, 1) >> 24) & 0xff; + u16 data_len = (u16)(fsp_msg_get_data_word(resp, 1) & 0xffff); if (msg_status != FSP_STATUS_SUCCESS) { log_simple_error(&e_info(OPAL_RC_LED_SUPPORT), diff --git a/hw/fsp/fsp-mem-err.c b/hw/fsp/fsp-mem-err.c index 01b1e55ab..d64558a49 100644 --- a/hw/fsp/fsp-mem-err.c +++ b/hw/fsp/fsp-mem-err.c @@ -345,13 +345,13 @@ static bool fsp_mem_err_msg(u32 cmd_sub_mod, struct fsp_msg *msg) * correctable/Uncorrectable/scrub UE errors with real * address of 4K memory page in which the error occurred. */ - paddr_start = be64_to_cpu(*((__be64 *)&msg->data.words[0])); + paddr_start = be64_to_cpu(*((__be64 *)&msg->data.bytes[0])); printf("Got memory resilience error message for " "paddr=0x%016llux\n", paddr_start); return handle_memory_resilience(cmd_sub_mod, paddr_start); case FSP_CMD_MEM_DYN_DEALLOC: - paddr_start = be64_to_cpu(*((__be64 *)&msg->data.words[0])); - paddr_end = be64_to_cpu(*((__be64 *)&msg->data.words[2])); + paddr_start = be64_to_cpu(*((__be64 *)&msg->data.bytes[0])); + paddr_end = be64_to_cpu(*((__be64 *)&msg->data.bytes[8])); printf("Got dynamic memory deallocation message: " "paddr_start=0x%016llux, paddr_end=0x%016llux\n", paddr_start, paddr_end); diff --git a/hw/fsp/fsp-nvram.c b/hw/fsp/fsp-nvram.c index 159a956f0..f5c6d665e 100644 --- a/hw/fsp/fsp-nvram.c +++ b/hw/fsp/fsp-nvram.c @@ -45,9 +45,9 @@ #define NVRAM_BLKSIZE 0x1000 struct nvram_triplet { - uint64_t dma_addr; - uint32_t blk_offset; - uint32_t blk_count; + __be64 dma_addr; + __be32 blk_offset; + __be32 blk_count; } __packed; #define NVRAM_FLAG_CLEAR_WPEND 0x80000000 @@ -147,9 +147,9 @@ static void fsp_nvram_send_write(void) if (start > end || fsp_nvram_state != NVRAM_STATE_OPEN) return; count = (end - start) / NVRAM_BLKSIZE + 1; - fsp_nvram_triplet.dma_addr = PSI_DMA_NVRAM_BODY + start; - fsp_nvram_triplet.blk_offset = start / NVRAM_BLKSIZE; - fsp_nvram_triplet.blk_count = count; + fsp_nvram_triplet.dma_addr = cpu_to_be64(PSI_DMA_NVRAM_BODY + start); + fsp_nvram_triplet.blk_offset = cpu_to_be32(start / NVRAM_BLKSIZE); + fsp_nvram_triplet.blk_count = cpu_to_be32(count); fsp_nvram_msg = fsp_mkmsg(FSP_CMD_WRITE_VNVRAM, 6, 0, PSI_DMA_NVRAM_TRIPL, 1, NVRAM_FLAG_CLEAR_WPEND, 0, 0); @@ -269,7 +269,7 @@ static bool fsp_nvram_get_size(uint32_t *out_size) assert(msg); rc = fsp_sync_msg(msg, false); - size = msg->resp ? msg->resp->data.words[0] : 0; + size = msg->resp ? fsp_msg_get_data_word(msg->resp, 0) : 0; fsp_freemsg(msg); if (rc || size == 0) { log_simple_error(&e_info(OPAL_RC_NVRAM_SIZE), diff --git a/hw/fsp/fsp-occ.c b/hw/fsp/fsp-occ.c index 8164129e9..03ddc2c96 100644 --- a/hw/fsp/fsp-occ.c +++ b/hw/fsp/fsp-occ.c @@ -381,8 +381,8 @@ static bool fsp_occ_msg(u32 cmd_sub_mod, struct fsp_msg *msg) * be nice and respond to OCC. */ scope = msg->data.bytes[3]; - dbob_id = msg->data.words[1]; - seq_id = msg->data.words[2]; + dbob_id = fsp_msg_get_data_word(msg, 1); + seq_id = fsp_msg_get_data_word(msg, 2); prlog(PR_INFO, "OCC: Got OCC Load message, scope=0x%x" " dbob=0x%x seq=0x%x\n", scope, dbob_id, seq_id); occ_do_load(scope, dbob_id, seq_id); @@ -394,8 +394,8 @@ static bool fsp_occ_msg(u32 cmd_sub_mod, struct fsp_msg *msg) * to reply something sensible or the FSP will get upset */ scope = msg->data.bytes[3]; - dbob_id = msg->data.words[1]; - seq_id = msg->data.words[2]; + dbob_id = fsp_msg_get_data_word(msg, 1); + seq_id = fsp_msg_get_data_word(msg, 2); prlog(PR_INFO, "OCC: Got OCC Reset message, scope=0x%x" " dbob=0x%x seq=0x%x\n", scope, dbob_id, seq_id); occ_do_reset(scope, dbob_id, seq_id); diff --git a/hw/fsp/fsp-op-panel.c b/hw/fsp/fsp-op-panel.c index 00d275131..9bd0247e8 100644 --- a/hw/fsp/fsp-op-panel.c +++ b/hw/fsp/fsp-op-panel.c @@ -119,16 +119,16 @@ struct op_src { uint8_t flags; uint8_t reserved; uint8_t hex_word_cnt; - uint16_t reserved2; - uint16_t total_size; - uint32_t word2; /* SRC format in low byte */ - uint32_t word3; - uint32_t word4; - uint32_t word5; - uint32_t word6; - uint32_t word7; - uint32_t word8; - uint32_t word9; + __be16 reserved2; + __be16 total_size; + __be32 word2; /* SRC format in low byte */ + __be32 word3; + __be32 word4; + __be32 word5; + __be32 word6; + __be32 word7; + __be32 word8; + __be32 word9; uint8_t ascii[OP_PANEL_NUM_LINES * OP_PANEL_LINE_LEN]; /* Word 11 */ } __packed __align(4); @@ -195,7 +195,7 @@ static int64_t __opal_write_oppanel(oppanel_line_t *lines, uint64_t num_lines, op_src.reserved = 0; op_src.hex_word_cnt = 1; /* header word only */ op_src.reserved2 = 0; - op_src.total_size = sizeof(op_src); + op_src.total_size = cpu_to_be16(sizeof(op_src)); op_src.word2 = 0; /* should be unneeded */ for (i = 0; i < num_lines; i++) { diff --git a/hw/fsp/fsp-rtc.c b/hw/fsp/fsp-rtc.c index ac12ddf22..4e5a80919 100644 --- a/hw/fsp/fsp-rtc.c +++ b/hw/fsp/fsp-rtc.c @@ -81,8 +81,8 @@ static bool rtc_tod_cache_dirty = false; struct opal_tpo_data { uint64_t tpo_async_token; - uint32_t *year_month_day; - uint32_t *hour_min; + __be32 *year_month_day; + __be32 *hour_min; }; /* Timebase value when we last initiated a RTC read request */ @@ -125,10 +125,9 @@ static void fsp_tpo_req_complete(struct fsp_msg *read_resp) case FSP_STATUS_SUCCESS: /* Save the read TPO value in our cache */ if (attr->year_month_day) - *(attr->year_month_day) = - read_resp->resp->data.words[0]; + *attr->year_month_day = cpu_to_be32(fsp_msg_get_data_word(read_resp->resp, 0)); if (attr->hour_min) - *(attr->hour_min) = read_resp->resp->data.words[1]; + *attr->hour_min = cpu_to_be32(fsp_msg_get_data_word(read_resp->resp, 1)); rc = OPAL_SUCCESS; break; @@ -170,8 +169,8 @@ static void fsp_rtc_process_read(struct fsp_msg *read_resp) case FSP_STATUS_SUCCESS: /* Save the read RTC value in our cache */ rtc_tod_state = RTC_TOD_VALID; - datetime_to_tm(read_resp->data.words[0], - (u64) read_resp->data.words[1] << 32, &tm); + datetime_to_tm(fsp_msg_get_data_word(read_resp, 0), + (u64)fsp_msg_get_data_word(read_resp, 1) << 32, &tm); rtc_cache_update(&tm); prlog(PR_TRACE, "FSP-RTC Got time: %d-%d-%d %d:%d:%d\n", tm.tm_year, tm.tm_mon, tm.tm_mday, @@ -442,8 +441,8 @@ static int64_t fsp_opal_tpo_write(uint64_t async_token, uint32_t y_m_d, } /* Read Timed power on (TPO) from FSP */ -static int64_t fsp_opal_tpo_read(uint64_t async_token, uint32_t *y_m_d, - uint32_t *hr_min) +static int64_t fsp_opal_tpo_read(uint64_t async_token, __be32 *y_m_d, + __be32 *hr_min) { static struct opal_tpo_data *attr; struct fsp_msg *msg; diff --git a/hw/fsp/fsp-sensor.c b/hw/fsp/fsp-sensor.c index 46385b0a6..5cff25867 100644 --- a/hw/fsp/fsp-sensor.c +++ b/hw/fsp/fsp-sensor.c @@ -191,7 +191,7 @@ static uint32_t sensor_power_process_data(uint16_t rid, prlog(PR_TRACE, "Power[%d]: %d mW\n", i, power->supplies[i].milliwatts); if (rid == normalize_power_rid(power->supplies[i].rid)) - return power->supplies[i].milliwatts / 1000; + return be32_to_cpu(power->supplies[i].milliwatts) / 1000; } return 0; @@ -206,7 +206,7 @@ static void fsp_sensor_process_data(struct opal_sensor_data *attr) { uint8_t *sensor_buf_ptr = (uint8_t *)sensor_buffer; uint32_t sensor_data = INVALID_DATA; - uint16_t sensor_mod_data[8]; + __be16 sensor_mod_data[8]; int count; for (count = 0; count < spcn_mod_data[attr->mod_index].entry_count; @@ -220,18 +220,18 @@ static void fsp_sensor_process_data(struct opal_sensor_data *attr) sensor_data = sensor_power_process_data(attr->rid, (struct sensor_power *) sensor_buf_ptr); break; - } else if (sensor_mod_data[0] == attr->frc && - sensor_mod_data[1] == attr->rid) { + } else if (be16_to_cpu(sensor_mod_data[0]) == attr->frc && + be16_to_cpu(sensor_mod_data[1]) == attr->rid) { switch (attr->spcn_attr) { case SENSOR_STATUS: sensor_data = - convert_status_to_fault(sensor_mod_data[3]); + convert_status_to_fault(be16_to_cpu(sensor_mod_data[3])); break; case SENSOR_THRS: - sensor_data = sensor_mod_data[6]; + sensor_data = be16_to_cpu(sensor_mod_data[6]); break; case SENSOR_DATA: - sensor_data = sensor_mod_data[2]; + sensor_data = be16_to_cpu(sensor_mod_data[2]); break; default: break; @@ -259,7 +259,7 @@ static int fsp_sensor_process_read(struct fsp_msg *resp_msg) switch (mbx_rsp_status) { case SP_RSP_STATUS_VALID_DATA: sensor_state = SENSOR_VALID_DATA; - size = resp_msg->data.words[1] & 0xffff; + size = fsp_msg_get_data_word(resp_msg, 1) & 0xffff; break; case SP_RSP_STATUS_INVALID_DATA: log_simple_error(&e_info(OPAL_RC_SENSOR_READ), @@ -308,7 +308,7 @@ static void fsp_sensor_read_complete(struct fsp_msg *msg) prlog(PR_INSANE, "%s()\n", __func__); - status = (msg->resp->data.words[1] >> 24) & 0xff; + status = (fsp_msg_get_data_word(msg->resp, 1) >> 24) & 0xff; size = fsp_sensor_process_read(msg->resp); fsp_freemsg(msg); @@ -576,8 +576,7 @@ static struct dt_node *sensor_get_node(struct dt_node *sensors, * Just use the resource class name and resource id. This * should be obvious enough for a node name. */ - snprintf(name, sizeof(name), "%s#%d-%s", frc_names[header->frc], - header->rid, attrname); + snprintf(name, sizeof(name), "%s#%d-%s", frc_names[be16_to_cpu(header->frc)], be16_to_cpu(header->rid), attrname); /* * The same resources are reported by the different PRS @@ -592,7 +591,7 @@ static struct dt_node *sensor_get_node(struct dt_node *sensors, node = dt_new(sensors, name); snprintf(name, sizeof(name), "ibm,opal-sensor-%s", - frc_names[header->frc]); + frc_names[be16_to_cpu(header->frc)]); dt_add_property_string(node, "compatible", name); } else { /** @@ -608,7 +607,7 @@ static struct dt_node *sensor_get_node(struct dt_node *sensors, } #define sensor_handler(header, attr_num) \ - sensor_make_handler(SENSOR_FSP, (header).frc, (header).rid, attr_num) + sensor_make_handler(SENSOR_FSP, be16_to_cpu((header).frc), be16_to_cpu((header).rid), attr_num) static int add_sensor_prs(struct dt_node *sensors, struct sensor_prs *prs) { @@ -655,7 +654,7 @@ static int add_sensor_data(struct dt_node *sensors, * Some resource, like fans, get their status attribute from * three different commands ... */ - if (data->header.frc == SENSOR_FRC_AMB_TEMP) { + if (be16_to_cpu(data->header.frc) == SENSOR_FRC_AMB_TEMP) { node = sensor_get_node(sensors, &data->header, "faulted"); if (!node) return -1; @@ -677,15 +676,15 @@ static int add_sensor_power(struct dt_node *sensors, struct sensor_power *power) for (i = 0; i < sensor_power_count(power); i++) { struct sensor_header header = { - SENSOR_FRC_POWER_SUPPLY, - normalize_power_rid(power->supplies[i].rid) + cpu_to_be16(SENSOR_FRC_POWER_SUPPLY), + cpu_to_be16(normalize_power_rid(power->supplies[i].rid)) }; node = sensor_get_node(sensors, &header, "data"); prlog(PR_TRACE, "SENSOR: Power[%d] : %d mW\n", power->supplies[i].rid, - power->supplies[i].milliwatts); + be32_to_cpu(power->supplies[i].milliwatts)); dt_add_property_cells(node, "sensor-id", sensor_handler(header, SENSOR_DATA)); @@ -715,7 +714,7 @@ static void add_sensor_ids(struct dt_node *sensors) struct sensor_header *header = (struct sensor_header *) sensor_buf_ptr; - if (!sensor_frc_is_valid(header->frc)) + if (!sensor_frc_is_valid(be16_to_cpu(header->frc))) goto out_sensor; switch (smod->mod) { @@ -821,7 +820,7 @@ void fsp_init_sensor(void) rc = fsp_sync_msg(&msg, false); if (rc >= 0) { - status = (resp.data.words[1] >> 24) & 0xff; + status = (fsp_msg_get_data_word(&resp, 1) >> 24) & 0xff; size = fsp_sensor_process_read(&resp); psi_dma_offset += size; spcn_mod_data[index].entry_count += (size / diff --git a/hw/fsp/fsp-surveillance.c b/hw/fsp/fsp-surveillance.c index d774bea1e..0b7cc21d0 100644 --- a/hw/fsp/fsp-surveillance.c +++ b/hw/fsp/fsp-surveillance.c @@ -145,6 +145,7 @@ static void fsp_surv_got_param(uint32_t param_id __unused, int err_len, return; } + surv_state_param = be32_to_cpu((__be32)surv_state_param); if (!(surv_state_param & 0x01)) { prlog(PR_NOTICE, "SURV: Status from FSP: disabled\n"); return; diff --git a/hw/fsp/fsp-sysdump.c b/hw/fsp/fsp-sysdump.c index fd915f402..f2777befe 100644 --- a/hw/fsp/fsp-sysdump.c +++ b/hw/fsp/fsp-sysdump.c @@ -231,7 +231,7 @@ static int __dump_region_add_entry(uint32_t id, uint64_t addr, uint32_t size) } /* Add entry to dump memory region table */ - dump_mem_region[cur_mdst_entry].data_region = (u8)cpu_to_be32(id); + dump_mem_region[cur_mdst_entry].data_region = (u8)id; dump_mem_region[cur_mdst_entry].addr = cpu_to_be64(addr); dump_mem_region[cur_mdst_entry].size = cpu_to_be32(size); diff --git a/hw/fsp/fsp-sysparam.c b/hw/fsp/fsp-sysparam.c index c7ed36e43..2b8446c41 100644 --- a/hw/fsp/fsp-sysparam.c +++ b/hw/fsp/fsp-sysparam.c @@ -69,18 +69,18 @@ static int fsp_sysparam_process(struct sysparam_req *r) if (r->msg.state != fsp_msg_done) { prerror("FSP: Request for sysparam 0x%x got FSP failure!\n", - r->msg.data.words[0]); + fsp_msg_get_data_word(&r->msg, 0)); stlen = -1; /* XXX Find saner error codes */ goto complete; } - param_id = r->resp.data.words[0]; - len = r->resp.data.words[1] & 0xffff; + param_id = fsp_msg_get_data_word(&r->resp, 0); + len = fsp_msg_get_data_word(&r->resp, 1) & 0xffff; /* Check params validity */ - if (param_id != r->msg.data.words[0]) { + if (param_id != fsp_msg_get_data_word(&r->msg, 0)) { prerror("FSP: Request for sysparam 0x%x got resp. for 0x%x!\n", - r->msg.data.words[0], param_id); + fsp_msg_get_data_word(&r->msg, 0), param_id); stlen = -2; /* XXX Sane error codes */ goto complete; } @@ -95,7 +95,7 @@ static int fsp_sysparam_process(struct sysparam_req *r) switch(fstat) { case 0x00: /* XXX Is that even possible ? */ case 0x11: /* Data in request */ - memcpy(r->ubuf, &r->resp.data.words[2], len); + memcpy(r->ubuf, &r->resp.data.bytes[8], len); /* fallthrough */ case 0x12: /* Data in TCE */ stlen = len; @@ -106,7 +106,7 @@ static int fsp_sysparam_process(struct sysparam_req *r) complete: /* Call completion if any */ if (comp) - comp(r->msg.data.words[0], stlen, cdata); + comp(fsp_msg_get_data_word(&r->msg, 0), stlen, cdata); free(r); @@ -208,15 +208,15 @@ static void fsp_opal_setparam_complete(struct fsp_msg *msg) if (msg->state != fsp_msg_done) { prerror("FSP: Request for set sysparam 0x%x got FSP failure!\n", - msg->data.words[0]); + fsp_msg_get_data_word(msg, 0)); rc = OPAL_INTERNAL_ERROR; goto out; } - param_id = msg->resp->data.words[0]; - if (param_id != msg->data.words[0]) { + param_id = fsp_msg_get_data_word(msg->resp, 0); + if (param_id != fsp_msg_get_data_word(msg, 0)) { prerror("FSP: Request for set sysparam 0x%x got resp. for 0x%x!" - "\n", msg->data.words[0], param_id); + "\n", fsp_msg_get_data_word(msg, 0), param_id); rc = OPAL_INTERNAL_ERROR; goto out; } @@ -399,7 +399,7 @@ static bool fsp_sysparam_msg(u32 cmd_sub_mod, struct fsp_msg *msg) case FSP_CMD_SP_SPARM_UPD_0: case FSP_CMD_SP_SPARM_UPD_1: printf("FSP: Got sysparam update, param ID 0x%x\n", - msg->data.words[0]); + fsp_msg_get_data_word(msg, 0)); sysparam_run_update_notifier(msg); @@ -424,7 +424,7 @@ static void add_opal_sysparam_node(void) { struct dt_node *sysparams; char *names, *s; - uint32_t *ids, *lens; + __be32 *ids, *lens; uint8_t *perms; unsigned int i, count, size = 0; diff --git a/hw/fsp/fsp.c b/hw/fsp/fsp.c index 2b2c5379a..1112fb74b 100644 --- a/hw/fsp/fsp.c +++ b/hw/fsp/fsp.c @@ -91,7 +91,7 @@ static enum ipl_state ipl_state = ipl_initial; static struct fsp *first_fsp; static struct fsp *active_fsp; static u16 fsp_curseq = 0x8000; -static u64 *fsp_tce_table; +static __be64 *fsp_tce_table; #define FSP_INBOUND_SIZE 0x00100000UL static void *fsp_inbound_buf = NULL; @@ -181,8 +181,8 @@ static void fsp_trace_msg(struct fsp_msg *msg, u8 dir __unused) size_t len = offsetof(struct trace_fsp_msg, data[msg->dlen]); fsp.fsp_msg.dlen = msg->dlen; - fsp.fsp_msg.word0 = msg->word0; - fsp.fsp_msg.word1 = msg->word1; + fsp.fsp_msg.word0 = cpu_to_be32(msg->word0); + fsp.fsp_msg.word1 = cpu_to_be32(msg->word1); fsp.fsp_msg.dir = dir; memcpy(fsp.fsp_msg.data, msg->data.bytes, msg->dlen); trace_add(&fsp, TRACE_FSP_MSG, len); @@ -634,12 +634,12 @@ static void fsp_trace_event(struct fsp *fsp, u32 evt, #ifdef FSP_TRACE_EVENT size_t len = sizeof(struct trace_fsp_event); - tfsp.fsp_evt.event = evt; - tfsp.fsp_evt.fsp_state = fsp->state; - tfsp.fsp_evt.data[0] = data0; - tfsp.fsp_evt.data[1] = data1; - tfsp.fsp_evt.data[2] = data2; - tfsp.fsp_evt.data[3] = data3; + tfsp.fsp_evt.event = cpu_to_be16(evt); + tfsp.fsp_evt.fsp_state = cpu_to_be16(fsp->state); + tfsp.fsp_evt.data[0] = cpu_to_be32(data0); + tfsp.fsp_evt.data[1] = cpu_to_be32(data1); + tfsp.fsp_evt.data[2] = cpu_to_be32(data2); + tfsp.fsp_evt.data[3] = cpu_to_be32(data3); trace_add(&tfsp, TRACE_FSP_EVENT, len); #endif /* FSP_TRACE_EVENT */ } @@ -931,7 +931,7 @@ static bool fsp_post_msg(struct fsp *fsp, struct fsp_msg *msg) fsp_wreg(fsp, reg, msg->word1); reg += 4; wlen = (msg->dlen + 3) >> 2; for (i = 0; i < wlen; i++) { - fsp_wreg(fsp, reg, msg->data.words[i]); + fsp_wreg(fsp, reg, fsp_msg_get_data_word(msg, i)); reg += 4; } @@ -994,7 +994,7 @@ static void __fsp_fillmsg(struct fsp_msg *msg, u32 cmd_sub_mod, msg->dlen = add_words << 2; for (i = 0; i < add_words; i++) - msg->data.words[i] = va_arg(list, unsigned int); + fsp_msg_set_data_word(msg, i, va_arg(list, unsigned int)); va_end(list); } @@ -1141,8 +1141,8 @@ static void fsp_complete_send(struct fsp *fsp) static void fsp_alloc_inbound(struct fsp_msg *msg) { - u16 func_id = msg->data.words[0] & 0xffff; - u32 len = msg->data.words[1]; + u16 func_id = fsp_msg_get_data_word(msg, 0) & 0xffff; + u32 len = fsp_msg_get_data_word(msg, 1); u32 tce_token = 0, act_len = 0; u8 rc = 0; void *buf; @@ -1294,12 +1294,12 @@ static bool fsp_local_command(u32 cmd_sub_mod, struct fsp_msg *msg) return true; case FSP_CMD_SP_RELOAD_COMP: if (msg->data.bytes[3] & PPC_BIT8(0)) { - fsp_fips_dump_notify(msg->data.words[1], - msg->data.words[2]); + fsp_fips_dump_notify(fsp_msg_get_data_word(msg, 1), + fsp_msg_get_data_word(msg, 2)); if (msg->data.bytes[3] & PPC_BIT8(1)) prlog(PR_DEBUG, " PLID is %x\n", - msg->data.words[3]); + fsp_msg_get_data_word(msg, 3)); } if (msg->data.bytes[3] & PPC_BIT8(2)) { prlog(PR_INFO, "FSP: SP Reset/Reload was NOT done\n"); @@ -1407,7 +1407,7 @@ static void __fsp_fill_incoming(struct fsp *fsp, struct fsp_msg *msg, wlen = (dlen + 3) >> 2; reg = FSP_MBX1_FDATA_AREA + 8; for (i = 0; i < wlen; i++) { - msg->data.words[i] = fsp_rreg(fsp, reg); + fsp_msg_set_data_word(msg, i, fsp_rreg(fsp, reg)); reg += 4; } @@ -1842,7 +1842,7 @@ static int fsp_init_mbox(struct fsp *fsp) /* We use a single fixed TCE table for all PSI interfaces */ static void fsp_init_tce_table(void) { - fsp_tce_table = (u64 *)PSI_TCE_TABLE_BASE; + fsp_tce_table = (__be64 *)PSI_TCE_TABLE_BASE; memset(fsp_tce_table, 0, PSI_TCE_TABLE_SIZE); } @@ -1859,7 +1859,7 @@ void fsp_tce_map(u32 offset, void *addr, u32 size) offset >>= TCE_SHIFT; while(size--) { - fsp_tce_table[offset++] = raddr | 0x3; + fsp_tce_table[offset++] = cpu_to_be64(raddr | 0x3); raddr += TCE_PSIZE; } } @@ -2397,8 +2397,8 @@ static void fsp_fetch_lid_complete(struct fsp_msg *msg) last = list_top(&fsp_fetch_lid_queue, struct fsp_fetch_lid_item, link); fsp_tce_unmap(PSI_DMA_FETCH, last->bsize); - woffset = msg->resp->data.words[1]; - wlen = msg->resp->data.words[2]; + woffset = fsp_msg_get_data_word(msg->resp, 1); + wlen = fsp_msg_get_data_word(msg->resp, 2); rc = (msg->resp->word1 >> 8) & 0xff; /* Fall back to a PHYP LID for kernel loads */ diff --git a/include/fsp-attn.h b/include/fsp-attn.h index 4399ead35..b2f007b55 100644 --- a/include/fsp-attn.h +++ b/include/fsp-attn.h @@ -84,7 +84,7 @@ struct ti_attn { __be32 src_word[SRC_WORD_COUNT]; /* ASCII data */ char src[SRC_LEN]; - uint32_t msg_len; + __be32 msg_len; /* User data: Debug details */ struct user_data msg; } __packed __align(ATTN_AREA_SZ); diff --git a/include/fsp-elog.h b/include/fsp-elog.h index f24251df6..2de1a04dd 100644 --- a/include/fsp-elog.h +++ b/include/fsp-elog.h @@ -29,9 +29,9 @@ enum elog_head_state { int elog_fsp_commit(struct errorlog *buf) __warn_unused_result; -bool opal_elog_info(uint64_t *opal_elog_id, uint64_t *opal_elog_size) __warn_unused_result; +bool opal_elog_info(__be64 *opal_elog_id, __be64 *opal_elog_size) __warn_unused_result; -bool opal_elog_read(uint64_t *buffer, uint64_t opal_elog_size, +bool opal_elog_read(void *buffer, uint64_t opal_elog_size, uint64_t opal_elog_id) __warn_unused_result; bool opal_elog_ack(uint64_t ack_id) __warn_unused_result; diff --git a/include/fsp-leds.h b/include/fsp-leds.h index 57b3d1f85..d62505fa2 100644 --- a/include/fsp-leds.h +++ b/include/fsp-leds.h @@ -34,9 +34,9 @@ enum spcn_cmd_src { /* SPCN set LED */ struct spcn_led_data { u8 lc_len; - u16 state; + __be16 state; char lc_code[LOC_CODE_SIZE]; -}; +} __packed; /* LED data */ struct fsp_led_data { @@ -51,17 +51,17 @@ struct fsp_led_data { /* FSP location code request */ struct fsp_loc_code_req { - u16 len; - u16 req_type; + __be16 len; + __be16 req_type; u8 raw_len; u8 lc_sz; char loc_code[LOC_CODE_SIZE]; -}; +} __packed; /* FSP location code data */ struct fsp_loc_code_data { - u16 size; - u32 ccin; + __be16 size; + __be32 ccin; u8 status; u8 ind_state; u8 raw_len; @@ -81,22 +81,22 @@ struct fsp_loc_code_data { /* Get indicator state request */ struct fsp_get_ind_state_req { - u16 size; + __be16 size; u8 lc_len; u8 fld_sz; char loc_code[LOC_CODE_SIZE]; -}; +} __packed; /* Set indicator state request */ struct fsp_set_ind_state_req { - u16 size; - u16 req_type; + __be16 size; + __be16 req_type; u8 reserved[3]; u8 ind_state; u8 lc_len; u8 fld_sz; char loc_code[LOC_CODE_SIZE]; -}; +} __packed; /* LED set SPCN command */ struct led_set_cmd { diff --git a/include/fsp.h b/include/fsp.h index b2827b327..92f5459a5 100644 --- a/include/fsp.h +++ b/include/fsp.h @@ -604,7 +604,7 @@ struct fsp_msg { u32 word0; /* seq << 16 | cmd */ u32 word1; /* mod << 8 | sub */ union { - u32 words[14]; + __be32 words[14]; u8 bytes[56]; } data; @@ -629,6 +629,16 @@ struct fsp_msg { struct list_node link; }; +static inline u32 fsp_msg_get_data_word(struct fsp_msg *msg, unsigned long i) +{ + return be32_to_cpu(msg->data.words[i]); +} + +static inline void fsp_msg_set_data_word(struct fsp_msg *msg, unsigned long i, u32 w) +{ + msg->data.words[i] = cpu_to_be32(w); +} + /* This checks if a message is still "in progress" in the FSP driver */ static inline bool fsp_msg_busy(struct fsp_msg *msg) { diff --git a/include/spcn.h b/include/spcn.h index bec71341e..3a99eac05 100644 --- a/include/spcn.h +++ b/include/spcn.h @@ -78,8 +78,8 @@ enum { * Common to all PRS modifiers (subcommands) */ struct sensor_header { - uint16_t frc; /* Frame resource class */ - uint16_t rid; /* Resource ID */ + __be16 frc; /* Frame resource class */ + __be16 rid; /* Resource ID */ } __packed; /* @@ -87,8 +87,8 @@ struct sensor_header { */ struct sensor_prs { struct sensor_header header; - uint16_t src; /* unused */ - uint16_t status; + __be16 src; /* unused */ + __be16 status; } __packed; #define PRS_STATUS_ON_SUPPORTED 0x0010 @@ -104,8 +104,8 @@ struct sensor_param { struct sensor_header header; char location[4]; char __reserved[4]; - uint16_t threshold; - uint16_t status; + __be16 threshold; + __be16 status; } __packed; /* @@ -113,8 +113,8 @@ struct sensor_param { */ struct sensor_data { struct sensor_header header; - uint16_t data; - uint16_t status; + __be16 data; + __be16 status; } __packed; #define SENSOR_STATUS_EM_ALERT 0x0004 @@ -156,7 +156,7 @@ struct sensor_data { struct sensor_power_supply { uint8_t rid; /* Power supply ID */ - uint32_t milliwatts; + __be32 milliwatts; } __packed; struct sensor_power { diff --git a/platforms/ibm-fsp/common.c b/platforms/ibm-fsp/common.c index c288bff36..b58b07337 100644 --- a/platforms/ibm-fsp/common.c +++ b/platforms/ibm-fsp/common.c @@ -238,7 +238,7 @@ int64_t ibm_fsp_cec_power_down(uint64_t request) } int64_t ibm_fsp_sensor_read(uint32_t sensor_hndl, int token, - uint64_t *sensor_data) + __be64 *sensor_data) { return fsp_opal_read_sensor(sensor_hndl, token, sensor_data); } diff --git a/platforms/ibm-fsp/firenze-pci.c b/platforms/ibm-fsp/firenze-pci.c index da496727a..6d5aab1e4 100644 --- a/platforms/ibm-fsp/firenze-pci.c +++ b/platforms/ibm-fsp/firenze-pci.c @@ -94,22 +94,22 @@ struct firenze_pci_slot_fixup_info { }; struct firenze_pci_inv { - uint32_t hw_proc_id; - uint16_t slot_idx; - uint16_t reserved; - uint16_t vendor_id; - uint16_t device_id; - uint16_t subsys_vendor_id; - uint16_t subsys_device_id; -}; + __be32 hw_proc_id; + __be16 slot_idx; + __be16 reserved; + __be16 vendor_id; + __be16 device_id; + __be16 subsys_vendor_id; + __be16 subsys_device_id; +} __packed; struct firenze_pci_inv_data { - uint32_t version; /* currently 1 */ - uint32_t num_entries; - uint32_t entry_size; - uint32_t entry_offset; + __be32 version; /* currently 1 */ + __be32 num_entries; + __be32 entry_size; + __be32 entry_offset; struct firenze_pci_inv entries[]; -}; +} __packed; /* * Note: According to Tuleta system workbook, I didn't figure @@ -159,6 +159,8 @@ static void firenze_pci_add_inventory(struct phb *phb, struct proc_chip *chip; size_t size; bool need_init = false; + u32 num_entries; + u16 tmp16; /* * Do we need to add that to the FSP inventory for power @@ -191,7 +193,7 @@ static void firenze_pci_add_inventory(struct phb *phb, /* Check if we need to do some (Re)allocation */ if (!firenze_inv_data || - firenze_inv_data->num_entries == firenze_inv_cnt) { + be32_to_cpu(firenze_inv_data->num_entries) == firenze_inv_cnt) { need_init = !firenze_inv_data; /* (Re)allocate the block to the new size */ @@ -203,16 +205,18 @@ static void firenze_pci_add_inventory(struct phb *phb, /* Initialize the header for a new inventory */ if (need_init) { - firenze_inv_data->version = 1; + firenze_inv_data->version = cpu_to_be32(1); firenze_inv_data->num_entries = 0; firenze_inv_data->entry_size = - sizeof(struct firenze_pci_inv); + cpu_to_be32(sizeof(struct firenze_pci_inv)); firenze_inv_data->entry_offset = - offsetof(struct firenze_pci_inv_data, entries); + cpu_to_be32(offsetof(struct firenze_pci_inv_data, entries)); } /* Append slot entry */ - entry = &firenze_inv_data->entries[firenze_inv_data->num_entries++]; + num_entries = be32_to_cpu(firenze_inv_data->num_entries); + firenze_inv_data->num_entries = cpu_to_be32(num_entries + 1); + entry = &firenze_inv_data->entries[num_entries]; chip = get_chip(dt_get_chip_id(phb->dt_node)); if (!chip) { /** @@ -227,36 +231,38 @@ static void firenze_pci_add_inventory(struct phb *phb, return; } - entry->hw_proc_id = chip->pcid; + entry->hw_proc_id = cpu_to_be32(chip->pcid); entry->reserved = 0; if (pd->parent && pd->parent->slot && pd->parent->slot->data) { lxvpd_slot = pd->parent->slot->data; - entry->slot_idx = lxvpd_slot->slot_index; + entry->slot_idx = cpu_to_be16(lxvpd_slot->slot_index); } - pci_cfg_read16(phb, pd->bdfn, PCI_CFG_VENDOR_ID, &entry->vendor_id); - pci_cfg_read16(phb, pd->bdfn, PCI_CFG_DEVICE_ID, &entry->device_id); + pci_cfg_read16(phb, pd->bdfn, PCI_CFG_VENDOR_ID, &tmp16); + entry->vendor_id = cpu_to_be16(tmp16); + pci_cfg_read16(phb, pd->bdfn, PCI_CFG_DEVICE_ID, &tmp16); + entry->device_id = cpu_to_be16(tmp16); if (pd->is_bridge) { int64_t ssvc = pci_find_cap(phb, pd->bdfn, PCI_CFG_CAP_ID_SUBSYS_VID); if (ssvc <= 0) { - entry->subsys_vendor_id = 0xffff; - entry->subsys_device_id = 0xffff; + entry->subsys_vendor_id = cpu_to_be16(0xffff); + entry->subsys_device_id = cpu_to_be16(0xffff); } else { pci_cfg_read16(phb, pd->bdfn, - ssvc + PCICAP_SUBSYS_VID_VENDOR, - &entry->subsys_vendor_id); + ssvc + PCICAP_SUBSYS_VID_VENDOR, &tmp16); + entry->subsys_vendor_id = cpu_to_be16(tmp16); pci_cfg_read16(phb, pd->bdfn, - ssvc + PCICAP_SUBSYS_VID_DEVICE, - &entry->subsys_device_id); + ssvc + PCICAP_SUBSYS_VID_DEVICE, &tmp16); + entry->subsys_device_id = cpu_to_be16(tmp16); } } else { - pci_cfg_read16(phb, pd->bdfn, PCI_CFG_SUBSYS_VENDOR_ID, - &entry->subsys_vendor_id); - pci_cfg_read16(phb, pd->bdfn, PCI_CFG_SUBSYS_ID, - &entry->subsys_device_id); + pci_cfg_read16(phb, pd->bdfn, PCI_CFG_SUBSYS_VENDOR_ID, &tmp16); + entry->subsys_vendor_id = cpu_to_be16(tmp16); + pci_cfg_read16(phb, pd->bdfn, PCI_CFG_SUBSYS_ID, &tmp16); + entry->subsys_device_id = cpu_to_be16(tmp16); } } @@ -272,13 +278,16 @@ static void firenze_dump_pci_inventory(void) prlog(PR_INFO, "Dumping Firenze PCI inventory\n"); prlog(PR_INFO, "HWP SLT VDID DVID SVID SDID\n"); prlog(PR_INFO, "---------------------------\n"); - for (i = 0; i < firenze_inv_data->num_entries; i++) { + for (i = 0; i < be32_to_cpu(firenze_inv_data->num_entries); i++) { e = &firenze_inv_data->entries[i]; prlog(PR_INFO, "%03d %03d %04x %04x %04x %04x\n", - e->hw_proc_id, e->slot_idx, - e->vendor_id, e->device_id, - e->subsys_vendor_id, e->subsys_device_id); + be32_to_cpu(e->hw_proc_id), + be16_to_cpu(e->slot_idx), + be16_to_cpu(e->vendor_id), + be16_to_cpu(e->device_id), + be16_to_cpu(e->subsys_vendor_id), + be16_to_cpu(e->subsys_device_id)); } #endif /* FIRENZE_PCI_INVENTORY_DUMP */ } @@ -293,14 +302,14 @@ void firenze_pci_send_inventory(void) /* Dump the inventory */ prlog(PR_INFO, "Sending %d inventory to FSP\n", - firenze_inv_data->num_entries); + be32_to_cpu(firenze_inv_data->num_entries)); firenze_dump_pci_inventory(); /* Memory location for inventory */ base = (uint64_t)firenze_inv_data; - end = base + - sizeof(struct firenze_pci_inv_data) + - firenze_inv_data->num_entries * firenze_inv_data->entry_size; + end = base + sizeof(struct firenze_pci_inv_data) + + be32_to_cpu(firenze_inv_data->num_entries) * + be32_to_cpu(firenze_inv_data->entry_size); abase = base & ~0xffful; aend = (end + 0xffful) & ~0xffful; offset = PSI_DMA_PCIE_INVENTORY + (base & 0xfff); diff --git a/platforms/ibm-fsp/hostservices.c b/platforms/ibm-fsp/hostservices.c index ab4c90016..d93c4f6e6 100644 --- a/platforms/ibm-fsp/hostservices.c +++ b/platforms/ibm-fsp/hostservices.c @@ -873,8 +873,8 @@ static bool hservice_hbrt_msg_notify(uint32_t cmd_sub_mod, struct fsp_msg *msg) prlog(PR_TRACE, "HBRT: FSP - HBRT message generated\n"); - tce_token = msg->data.words[1]; - len = msg->data.words[2]; + tce_token = fsp_msg_get_data_word(msg, 1); + len = fsp_msg_get_data_word(msg, 2); buf = fsp_inbound_buf_from_tce(tce_token); if (!buf) { prlog(PR_DEBUG, "HBRT: Invalid inbound data\n"); diff --git a/platforms/ibm-fsp/lxvpd.c b/platforms/ibm-fsp/lxvpd.c index bdebc44a7..81cb612ed 100644 --- a/platforms/ibm-fsp/lxvpd.c +++ b/platforms/ibm-fsp/lxvpd.c @@ -275,7 +275,7 @@ void lxvpd_process_slot_entries(struct phb *phb, const void *lxvpd; const uint8_t *pr_rec, *pr_end, *sm; size_t lxvpd_size, pr_size; - const uint16_t *mf = NULL; + const beint16_t *mf = NULL; char record[5] = "PR00"; uint8_t mf_sz, sm_sz; bool found = false; @@ -317,8 +317,8 @@ void lxvpd_process_slot_entries(struct phb *phb, return; } - prlog(PR_DEBUG, "Found 0x%04x map...\n", *mf); - switch (*mf) { + prlog(PR_DEBUG, "Found 0x%04x map...\n", be16_to_cpu(*mf)); + switch (be16_to_cpu(*mf)) { case 0x1004: lxvpd_parse_1004_map(phb, sm + 1, sm_sz - 1, slot_size); found = true; diff --git a/platforms/ibm-fsp/lxvpd.h b/platforms/ibm-fsp/lxvpd.h index bc9daf55c..46acf6748 100644 --- a/platforms/ibm-fsp/lxvpd.h +++ b/platforms/ibm-fsp/lxvpd.h @@ -14,32 +14,54 @@ struct slot_p0 { union { uint8_t byte; struct { +#if HAVE_BIG_ENDIAN uint8_t pluggable:1; uint8_t pluggable_location:3; uint8_t power_ctl:1; uint8_t rsvd_5:1; uint8_t upstream_port:1; uint8_t alt_load_source:1; +#else + uint8_t alt_load_source:1; + uint8_t upstream_port:1; + uint8_t rsvd_5:1; + uint8_t power_ctl:1; + uint8_t pluggable_location:3; + uint8_t pluggable:1; +#endif }; }; }; struct slot_p1 { +#if HAVE_BIG_ENDIAN uint8_t rsvd_0:1; uint8_t wired_lanes:3; uint8_t rsvd_4:4; +#else + uint8_t rsvd_4:4; + uint8_t wired_lanes:3; + uint8_t rsvd_0:1; +#endif }; struct slot_p2 { +#if HAVE_BIG_ENDIAN uint8_t rsvd_0:1; uint8_t bus_clock:3; uint8_t connector_type:4; +#else + uint8_t connector_type:4; + uint8_t bus_clock:3; + uint8_t rsvd_0:1; +#endif }; struct slot_p3 { union { uint8_t byte; struct { +#if HAVE_BIG_ENDIAN uint8_t height:1; uint8_t length:1; uint8_t left_mech:1; @@ -48,6 +70,16 @@ struct slot_p3 { uint8_t pow_led_fsp:1; uint8_t attn_led_kvm:1; uint8_t attn_led_fsp:1; +#else + uint8_t attn_led_fsp:1; + uint8_t attn_led_kvm:1; + uint8_t pow_led_fsp:1; + uint8_t pow_led_kvm:1; + uint8_t right_mech:1; + uint8_t left_mech:1; + uint8_t length:1; + uint8_t height:1; +#endif }; }; }; @@ -57,7 +89,7 @@ struct pci_slot_entry_1004 { uint8_t sba; uint8_t phb_or_slot_type; char label[3]; - uint16_t bis; + __be16 bis; struct slot_p0 p0; struct slot_p1 p1; struct slot_p2 p2; @@ -73,13 +105,23 @@ struct pci_slot_entry_1005 { union { uint8_t pba; struct { +#if HAVE_BIG_ENDIAN uint8_t switch_id:4; uint8_t vswitch_id:4; +#else + uint8_t vswitch_id:4; + uint8_t switch_id:4; +#endif }; }; uint8_t switch_device_id; +#if HAVE_BIG_ENDIAN uint8_t slot_type:4; uint8_t phb_id:4; +#else + uint8_t phb_id:4; + uint8_t slot_type:4; +#endif char label[8]; uint8_t rsvd_11[4]; struct slot_p0 p0; From patchwork Sun Dec 8 12:23:02 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205642 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5MW6nLKz9sPK for ; Sun, 8 Dec 2019 23:33:11 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DERID4v+"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5MW4hnKzDqGY for ; Sun, 8 Dec 2019 23:33:11 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::442; helo=mail-pf1-x442.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DERID4v+"; dkim-atps=neutral Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W59K6cWBzDqP1 for ; Sun, 8 Dec 2019 23:24:21 +1100 (AEDT) Received: by mail-pf1-x442.google.com with SMTP id x185so5752609pfc.5 for ; Sun, 08 Dec 2019 04:24:21 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=KrbMQtDFnDlRvIopRyMEXvQlNmLsdFtST1djkIWUBcE=; b=DERID4v+qOA+76tUuRVljpKWWfejIAa/dp0KqEFKPXtC2j4vxq2w7Tt+/qHHtn9XVk 5xpaE1v9EyytkH8wwjEv7Fp8EDScUIcvW9VH3FAj4Z1IPX67t81uJukkMQxJ48RmSnJU 4XEu9LRJKVTD6gLYA2dvolqAUUOHAuEEr5saolYQP8BUZ70i6dOiEUVEvjoZNX+LQWdx k46h29KWtG8zjLjwK1rWt32XoQ/W4qnjB+4zihQN136H/7u5hQkXPH3+Cc7to2Gl1mGD Lvvi9FeSo7IUeK8SDnoiOiumsHhnt+MN2AwVHFulb7tExj1xHWJxZzc3URi16EuM71Z0 p/BQ== 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=KrbMQtDFnDlRvIopRyMEXvQlNmLsdFtST1djkIWUBcE=; b=rvI5RiQ8hUaxsaa/HGu5D28u3WbvTFBLKysrpUSq+yDQTPa+UIIr98I3h4kJZ93gUd jrhicBERh1t4htU26RoMVLbBDo2P03awAG+ZawrfiytZ6B4KCxcozpHowOsqXtXJ6sVR 4u6q9wTFSWMAZzhd09gkTekQXuiSM8ZlaPQ9M7jFBK01Znw6OM8G6pP7IIqCPQ1nEYeS SDbXUeCV/L2TrZERJG2EefPvDzcvgf9RgcQTDdPl+S1BDXxsgO7STywqeupbOfQXQOdp K8/ii1TUAcFh6JWzbXHtoUZIuRo/okvgWkmR7aILLTtiRbXzHQ+NxwUYabn/5hVykQXk iTAg== X-Gm-Message-State: APjAAAXNXLOBe5DmYSEgFilRQKDkXV6i02S2WgJB6XpF71+ZM6TSRRIE ML+RRafGpoUDVD3sU//fbJz9/muI X-Google-Smtp-Source: APXvYqzMjPqXqWhwmEs7n/tUqsWiH9DYYaU0AQpOwqZDMIg2D2x5MHRwC8Qo7AgtrXTLwlogl2ekLA== X-Received: by 2002:a63:d802:: with SMTP id b2mr6131176pgh.414.1575807859970; Sun, 08 Dec 2019 04:24:19 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:19 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:23:02 +1000 Message-Id: <20191208122312.12837-22-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 21/31] errorlog: endian conversion X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Signed-off-by: Nicholas Piggin --- core/errorlog.c | 14 ++++++++------ core/pel.c | 15 ++++++++++----- include/errorlog.h | 12 ++++++------ 3 files changed, 24 insertions(+), 17 deletions(-) diff --git a/core/errorlog.c b/core/errorlog.c index 01e296999..fd316836f 100644 --- a/core/errorlog.c +++ b/core/errorlog.c @@ -93,10 +93,10 @@ void log_add_section(struct errorlog *buf, uint32_t tag) tmp = (struct elog_user_data_section *)(buf->user_data_dump + buf->user_section_size); /* Use DESC if no other tag provided */ - tmp->tag = tag ? tag : 0x44455343; - tmp->size = size; + tmp->tag = tag ? cpu_to_be32(tag) : cpu_to_be32(0x44455343); + tmp->size = cpu_to_be16(size); - buf->user_section_size += tmp->size; + buf->user_section_size += size; buf->user_section_count++; } @@ -133,6 +133,7 @@ void log_append_data(struct errorlog *buf, unsigned char *data, uint16_t size) struct elog_user_data_section *section; uint8_t n_sections; char *buffer; + uint16_t ssize; if (!buf) { prerror("ELOG: Cannot update user data. Buffer is invalid\n"); @@ -154,13 +155,14 @@ void log_append_data(struct errorlog *buf, unsigned char *data, uint16_t size) while (--n_sections) { section = (struct elog_user_data_section *)buffer; - buffer += section->size; + buffer += be16_to_cpu(section->size); } section = (struct elog_user_data_section *)buffer; - buffer += section->size; + ssize = be16_to_cpu(section->size); + buffer += ssize; memcpy(buffer, data, size); - section->size += size; + section->size = cpu_to_be16(ssize + size); buf->user_section_size += size; } diff --git a/core/pel.c b/core/pel.c index b07ba0efc..7f9abb8f3 100644 --- a/core/pel.c +++ b/core/pel.c @@ -211,16 +211,19 @@ static void create_user_defined_section(struct errorlog *elog_data, opal_usr_data = (struct elog_user_data_section *)opal_buf; usrhdr->v6header.id = ELOG_SID_USER_DEFINED; + usrhdr->v6header.length = cpu_to_be16( + sizeof(struct opal_v6_header) + + be16_to_cpu(opal_usr_data->size)); usrhdr->v6header.version = OPAL_ELOG_VERSION; usrhdr->v6header.length = sizeof(struct opal_v6_header) + opal_usr_data->size; usrhdr->v6header.subtype = OPAL_ELOG_SST; usrhdr->v6header.component_id = elog_data->component_id; - memcpy(usrhdr->dump, opal_buf, opal_usr_data->size); + memcpy(usrhdr->dump, opal_buf, be16_to_cpu(opal_usr_data->size)); *pel_offset += usrhdr->v6header.length; dump += usrhdr->v6header.length; - opal_buf += opal_usr_data->size; + opal_buf += be16_to_cpu(opal_usr_data->size); privhdr->section_count++; } } @@ -233,10 +236,12 @@ static size_t pel_user_section_size(struct errorlog *elog_data) struct elog_user_data_section *opal_usr_data; for (i = 0; i < elog_data->user_section_count; i++) { + u16 s; + opal_usr_data = (struct elog_user_data_section *)opal_buf; - total += sizeof(struct opal_v6_header) + - opal_usr_data->size; - opal_buf += opal_usr_data->size; + s = be16_to_cpu(opal_usr_data->size); + total += sizeof(struct opal_v6_header) + s; + opal_buf += s; } return total; diff --git a/include/errorlog.h b/include/errorlog.h index 3fd475c07..a01ab97be 100644 --- a/include/errorlog.h +++ b/include/errorlog.h @@ -94,19 +94,19 @@ #define ORG_POWERNV 2 /* Multiple user data sections */ -struct __attribute__((__packed__))elog_user_data_section { - uint32_t tag; - uint16_t size; - uint16_t component_id; +struct elog_user_data_section { + __be32 tag; + __be16 size; + __be16 component_id; char data_dump[1]; -}; +} __packed; /* * All the information regarding an error/event to be reported * needs to populate this structure using pre-defined interfaces * only */ -struct __attribute__((__packed__)) __attribute__ ((aligned (8))) errorlog { +struct errorlog { uint16_t component_id; uint8_t error_event_type; From patchwork Sun Dec 8 12:23:03 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205644 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5NQ2B4gz9sP3 for ; Sun, 8 Dec 2019 23:33:58 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="O1fRJsx4"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5NQ0CXpzDqDV for ; Sun, 8 Dec 2019 23:33:58 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::542; helo=mail-pg1-x542.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="O1fRJsx4"; dkim-atps=neutral Received: from mail-pg1-x542.google.com (mail-pg1-x542.google.com [IPv6:2607:f8b0:4864:20::542]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W59P2Zl0zDqDV for ; Sun, 8 Dec 2019 23:24:25 +1100 (AEDT) Received: by mail-pg1-x542.google.com with SMTP id 6so5679692pgk.0 for ; Sun, 08 Dec 2019 04:24:25 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=o2nqQxzCre8AopJTfAbnx+g0uSfI6zLEiLt0BjTjFM0=; b=O1fRJsx4jSVOIWfdqgMNJQdJZOVXQZUu7pqSfA+TwE3EJtfukKqp+CGC8Fo24xOdFO +ENJ7kzltOOX2FUNHNtgTi18X3IsGDD8SaOKHV7WzEPBtmhK7AAsdFeB7CsBqNK374aB qT2K7So+Q1cDo9UPZ9wpArGvsSkU0PywI+DAgxXd8VMY5uQcwit5fTigN5h2bYLYNqxf wsT7+eYJ4gIifAvEGUnX9uJA2WgFEH6A9WOPSv9cxtQPYkkApecFWIhPNWV0Sd+bUn3B CRLD8dB6K8PzNrJCO7FYGWTc4J8gTKl8y+6eeAjUNHH5/3nY4EhetZkPBfQK9xeo9vvE SOXg== 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=o2nqQxzCre8AopJTfAbnx+g0uSfI6zLEiLt0BjTjFM0=; b=o+XLkHipRtJaXgt3aseZbsyK/KNglRHGZgO6au1NLRBrxbRjaRajE1L2t7XYVTuP6P W+jy6Z465ZjkxqAcCXT2Y/Fpf3Y6MEKUKFHJ8P1+jVIA4iZgUtDwQ/puZjoqUb7aBSNM 8gEGE8L9haNpmDPw4HWC5JBAUTvsJy1PtnWDxRsc3pfc1b9raLiwBNiHza1qnyNwHA/n kYXxLrB+V6uXhioCyNazlL62uxM3L8vnNFB8FKMKy2RuSkqMVd3qqlIm/10jQw1SPsYI kpoYpky+C3STlrRxDjdUYdOx01dJY3TJwOpN+aHQ54Glu7l3rEZCmxsOqX//8InkXjk4 qnog== X-Gm-Message-State: APjAAAXlXtU7z73XolUoxPOyPsWckH7oX9umiDh+VGTh0Fh7Nf9+HeIr 6fVoZebNfLQTtK4qEXpGyMAbGYyH X-Google-Smtp-Source: APXvYqxmkcrJIuxn9apf/Lq4ZpFB+321e3Znnkiat2MAnceMn+41g4nS8cH7rvivE+ZFOkO5ixHiog== X-Received: by 2002:a63:5920:: with SMTP id n32mr3442992pgb.443.1575807862467; Sun, 08 Dec 2019 04:24:22 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.20 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:22 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:23:03 +1000 Message-Id: <20191208122312.12837-23-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 22/31] pel: endian conversion X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Signed-off-by: Nicholas Piggin --- core/pel.c | 72 ++++++++++++++++++++++++------------------------ include/pel.h | 76 +++++++++++++++++++++++++-------------------------- 2 files changed, 75 insertions(+), 73 deletions(-) diff --git a/core/pel.c b/core/pel.c index 7f9abb8f3..f37b2185f 100644 --- a/core/pel.c +++ b/core/pel.c @@ -21,11 +21,11 @@ static void create_mtms_section(struct errorlog *elog_data, struct opal_mtms_section *mtms = (struct opal_mtms_section *) (pel_buffer + *pel_offset); - mtms->v6header.id = ELOG_SID_MACHINE_TYPE; - mtms->v6header.length = MTMS_SECTION_SIZE; + mtms->v6header.id = cpu_to_be16(ELOG_SID_MACHINE_TYPE); + mtms->v6header.length = cpu_to_be16(MTMS_SECTION_SIZE); mtms->v6header.version = OPAL_EXT_HRD_VER; mtms->v6header.subtype = 0; - mtms->v6header.component_id = elog_data->component_id; + mtms->v6header.component_id = cpu_to_be16(elog_data->component_id); memset(mtms->model, 0x00, sizeof(mtms->model)); memcpy(mtms->model, dt_prop_get(dt_root, "model"), OPAL_SYS_MODEL_LEN); @@ -47,16 +47,17 @@ static void create_extended_header_section(struct errorlog *elog_data, const char *opalmodel = NULL; const struct dt_property *p; uint64_t extd_time; + uint32_t extd_date; struct opal_extended_header_section *extdhdr = (struct opal_extended_header_section *) (pel_buffer + *pel_offset); - extdhdr->v6header.id = ELOG_SID_EXTENDED_HEADER; - extdhdr->v6header.length = EXTENDED_HEADER_SECTION_SIZE; + extdhdr->v6header.id = cpu_to_be16(ELOG_SID_EXTENDED_HEADER); + extdhdr->v6header.length = cpu_to_be16(EXTENDED_HEADER_SECTION_SIZE); extdhdr->v6header.version = OPAL_EXT_HRD_VER; extdhdr->v6header.subtype = 0; - extdhdr->v6header.component_id = elog_data->component_id; + extdhdr->v6header.component_id = cpu_to_be16(elog_data->component_id); memset(extdhdr->model, 0x00, sizeof(extdhdr->model)); opalmodel = dt_prop_get(dt_root, "model"); @@ -74,8 +75,9 @@ static void create_extended_header_section(struct errorlog *elog_data, memset(extdhdr->opal_subsys_version, 0x00, sizeof(extdhdr->opal_subsys_version)); - rtc_cache_get_datetime(&extdhdr->extended_header_date, &extd_time); - extdhdr->extended_header_time = extd_time >> 32; + rtc_cache_get_datetime(&extd_date, &extd_time); + extdhdr->extended_header_date = cpu_to_be32(extd_date); + extdhdr->extended_header_time = cpu_to_be32(extd_time >> 32); extdhdr->opal_symid_len = 0; *pel_offset += EXTENDED_HEADER_SECTION_SIZE; @@ -112,25 +114,25 @@ static void create_src_section(struct errorlog *elog_data, struct opal_src_section *src = (struct opal_src_section *) (pel_buffer + *pel_offset); - src->v6header.id = ELOG_SID_PRIMARY_SRC; - src->v6header.length = SRC_SECTION_SIZE; + src->v6header.id = cpu_to_be16(ELOG_SID_PRIMARY_SRC); + src->v6header.length = cpu_to_be16(SRC_SECTION_SIZE); src->v6header.version = OPAL_ELOG_VERSION; src->v6header.subtype = OPAL_ELOG_SST; - src->v6header.component_id = elog_data->component_id; + src->v6header.component_id = cpu_to_be16(elog_data->component_id); src->version = OPAL_SRC_SEC_VER; src->flags = 0; src->wordcount = OPAL_SRC_MAX_WORD_COUNT; - src->srclength = SRC_LENGTH; + src->srclength = cpu_to_be16(SRC_LENGTH); settype(src, OPAL_SRC_TYPE_ERROR); setsubsys(src, OPAL_FAILING_SUBSYSTEM); setrefcode(src, elog_data->reason_code); memset(src->hexwords, 0 , (8 * 4)); - src->hexwords[0] = OPAL_SRC_FORMAT; - src->hexwords[4] = elog_data->additional_info[0]; - src->hexwords[5] = elog_data->additional_info[1]; - src->hexwords[6] = elog_data->additional_info[2]; - src->hexwords[7] = elog_data->additional_info[3]; + src->hexwords[0] = cpu_to_be32(OPAL_SRC_FORMAT); + src->hexwords[4] = cpu_to_be32(elog_data->additional_info[0]); + src->hexwords[5] = cpu_to_be32(elog_data->additional_info[1]); + src->hexwords[6] = cpu_to_be32(elog_data->additional_info[2]); + src->hexwords[7] = cpu_to_be32(elog_data->additional_info[3]); *pel_offset += SRC_SECTION_SIZE; } @@ -142,11 +144,11 @@ static void create_user_header_section(struct errorlog *elog_data, (struct opal_user_header_section *) (pel_buffer + *pel_offset); - usrhdr->v6header.id = ELOG_SID_USER_HEADER; - usrhdr->v6header.length = USER_HEADER_SECTION_SIZE; + usrhdr->v6header.id = cpu_to_be16(ELOG_SID_USER_HEADER); + usrhdr->v6header.length = cpu_to_be16(USER_HEADER_SECTION_SIZE); usrhdr->v6header.version = OPAL_ELOG_VERSION; usrhdr->v6header.subtype = OPAL_ELOG_SST; - usrhdr->v6header.component_id = elog_data->component_id; + usrhdr->v6header.component_id = cpu_to_be16(elog_data->component_id); usrhdr->subsystem_id = elog_data->subsystem_id; usrhdr->event_scope = 0; @@ -154,9 +156,9 @@ static void create_user_header_section(struct errorlog *elog_data, usrhdr->event_type = elog_data->event_subtype; if (elog_data->elog_origin == ORG_SAPPHIRE) - usrhdr->action_flags = ERRL_ACTION_REPORT; + usrhdr->action_flags = cpu_to_be16(ERRL_ACTION_REPORT); else - usrhdr->action_flags = ERRL_ACTION_NONE; + usrhdr->action_flags = cpu_to_be16(ERRL_ACTION_NONE); *pel_offset += USER_HEADER_SECTION_SIZE; } @@ -166,19 +168,21 @@ static void create_private_header_section(struct errorlog *elog_data, char *pel_buffer, int *pel_offset) { uint64_t ctime; + uint32_t cdate; struct opal_private_header_section *privhdr = (struct opal_private_header_section *) pel_buffer; - privhdr->v6header.id = ELOG_SID_PRIVATE_HEADER; - privhdr->v6header.length = PRIVATE_HEADER_SECTION_SIZE; + privhdr->v6header.id = cpu_to_be16(ELOG_SID_PRIVATE_HEADER); + privhdr->v6header.length = cpu_to_be16(PRIVATE_HEADER_SECTION_SIZE); privhdr->v6header.version = OPAL_ELOG_VERSION; privhdr->v6header.subtype = OPAL_ELOG_SST; - privhdr->v6header.component_id = elog_data->component_id; - privhdr->plid = elog_data->plid; + privhdr->v6header.component_id = cpu_to_be16(elog_data->component_id); + privhdr->plid = cpu_to_be32(elog_data->plid); - rtc_cache_get_datetime(&privhdr->create_date, &ctime); - privhdr->create_time = ctime >> 32; + rtc_cache_get_datetime(&cdate, &ctime); + privhdr->create_date = cpu_to_be32(cdate); + privhdr->create_time = cpu_to_be32(ctime >> 32); privhdr->section_count = 5; privhdr->creator_subid_hi = 0x00; @@ -189,7 +193,7 @@ static void create_private_header_section(struct errorlog *elog_data, else privhdr->creator_id = OPAL_CID_POWERNV; - privhdr->log_entry_id = elog_data->plid; /*entry id is updated by FSP*/ + privhdr->log_entry_id = cpu_to_be32(elog_data->plid); /*entry id is updated by FSP*/ *pel_offset += PRIVATE_HEADER_SECTION_SIZE; } @@ -210,19 +214,17 @@ static void create_user_defined_section(struct errorlog *elog_data, usrhdr = (struct opal_user_section *)dump; opal_usr_data = (struct elog_user_data_section *)opal_buf; - usrhdr->v6header.id = ELOG_SID_USER_DEFINED; + usrhdr->v6header.id = cpu_to_be16(ELOG_SID_USER_DEFINED); usrhdr->v6header.length = cpu_to_be16( sizeof(struct opal_v6_header) + be16_to_cpu(opal_usr_data->size)); usrhdr->v6header.version = OPAL_ELOG_VERSION; - usrhdr->v6header.length = sizeof(struct opal_v6_header) + - opal_usr_data->size; usrhdr->v6header.subtype = OPAL_ELOG_SST; - usrhdr->v6header.component_id = elog_data->component_id; + usrhdr->v6header.component_id = cpu_to_be16(elog_data->component_id); memcpy(usrhdr->dump, opal_buf, be16_to_cpu(opal_usr_data->size)); - *pel_offset += usrhdr->v6header.length; - dump += usrhdr->v6header.length; + *pel_offset += be16_to_cpu(usrhdr->v6header.length); + dump += be16_to_cpu(usrhdr->v6header.length); opal_buf += be16_to_cpu(opal_usr_data->size); privhdr->section_count++; } diff --git a/include/pel.h b/include/pel.h index 19361d35e..cd878a258 100644 --- a/include/pel.h +++ b/include/pel.h @@ -61,12 +61,12 @@ enum elogSectionId { struct opal_v6_header { - enum elogSectionId id:16; /* section id */ - uint16_t length; /* section length */ - uint8_t version; /* section version */ - uint8_t subtype; /* section sub-type id */ - uint16_t component_id; /* component id of section creator */ -}; + __be16 id; /* section id */ + __be16 length; /* section length */ + uint8_t version; /* section version */ + uint8_t subtype; /* section sub-type id */ + __be16 component_id; /* component id of section creator */ +} __packed; /* opal_srctype */ #define OPAL_SRC_TYPE_ERROR 0xBB @@ -85,20 +85,20 @@ struct opal_v6_header { struct opal_private_header_section { struct opal_v6_header v6header; - uint32_t create_date; - uint32_t create_time; - uint32_t commit_date; - uint32_t commit_time; - - uint32_t creator_id:8; /* subsystem component id */ - uint32_t reserved_0:16; - uint32_t section_count:8; /* number of sections in log */ - uint32_t reserved_1; - uint32_t creator_subid_hi; - uint32_t creator_subid_lo; - uint32_t plid; /* platform log id */ - uint32_t log_entry_id; /* Unique log entry id */ -}; + __be32 create_date; + __be32 create_time; + __be32 commit_date; + __be32 commit_time; + + uint8_t creator_id; /* subsystem component id */ + __be16 reserved_0; + uint8_t section_count; /* number of sections in log */ + __be32 reserved_1; + __be32 creator_subid_hi; + __be32 creator_subid_lo; + __be32 plid; /* platform log id */ + __be32 log_entry_id; /* Unique log entry id */ +} __packed; /* opal user header section */ struct opal_user_header_section { @@ -110,11 +110,11 @@ struct opal_user_header_section { uint8_t event_severity; uint8_t event_type; /* error/event severity */ - uint32_t reserved_0; - uint16_t reserved_1; - uint16_t action_flags; /* error action code */ - uint32_t reserved_2; -}; + __be32 reserved_0; + __be16 reserved_1; + __be16 action_flags; /* error action code */ + __be32 reserved_2; +} __packed; struct opal_src_section { struct opal_v6_header v6header; @@ -122,11 +122,11 @@ struct opal_src_section { uint8_t flags; uint8_t reserved_0; uint8_t wordcount; - uint16_t reserved_1; - uint16_t srclength; - uint32_t hexwords[OPAL_SRC_MAX_WORD_COUNT]; + __be16 reserved_1; + __be16 srclength; + __be32 hexwords[OPAL_SRC_MAX_WORD_COUNT]; char srcstring[OPAL_MAX_SRC_BYTES]; -}; +} __packed; struct opal_extended_header_section { struct opal_v6_header v6header; @@ -134,27 +134,27 @@ struct opal_extended_header_section { char serial_no[OPAL_SYS_SERIAL_LEN]; char opal_release_version[OPAL_VER_LEN]; char opal_subsys_version[OPAL_VER_LEN]; - uint16_t reserved_0; - uint32_t extended_header_date; - uint32_t extended_header_time; - uint16_t reserved_1; - uint8_t reserved_2; - uint8_t opal_symid_len; + __be16 reserved_0; + __be32 extended_header_date; + __be32 extended_header_time; + __be16 reserved_1; + uint8_t reserved_2; + uint8_t opal_symid_len; char opalsymid[OPAL_SYMPID_LEN]; -}; +} __packed; /* opal MTMS section */ struct opal_mtms_section { struct opal_v6_header v6header; char model[OPAL_SYS_MODEL_LEN]; char serial_no[OPAL_SYS_SERIAL_LEN]; -}; +} __packed; /* User defined section */ struct opal_user_section { struct opal_v6_header v6header; char dump[1]; -}; +} __packed; /* The minimum size of a PEL record */ #define PEL_MIN_SIZE (PRIVATE_HEADER_SECTION_SIZE + USER_HEADER_SECTION_SIZE \ From patchwork Sun Dec 8 12:23:04 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205645 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5Nm61P5z9sPK for ; Sun, 8 Dec 2019 23:34:16 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HNzGaYCW"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5Nm4F6yzDqD1 for ; Sun, 8 Dec 2019 23:34:16 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::441; helo=mail-pf1-x441.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="HNzGaYCW"; dkim-atps=neutral Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W59R1W7ZzDqFL for ; Sun, 8 Dec 2019 23:24:27 +1100 (AEDT) Received: by mail-pf1-x441.google.com with SMTP id x185so5752669pfc.5 for ; Sun, 08 Dec 2019 04:24:27 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=PTxw4ybDCrcvFqq9R1qIu91EA31/ELvggdq1ktW6Fqs=; b=HNzGaYCWstIsAa0oPXSDWyvS/KrKNMiPHHhmTo2B8WdGI2d3hqNEwraEPSwZtPNyF8 pYAi159mUtEW/cPlaKNinzLk69ZWiYf81zUsza2M8p8VAEsI9CpEpCntWkGaFzl6DqHk ho93k2fNWSdJR+rvVu+gpEpF4yhwH7EBp7AUrcTdvfjL/oFQrOGmvhL+VCYYqRCAuVIX sln0qnl5QSUTA5RcNteF/FC2g59FO8XvPThQx5IozfQM819QF7u3nQPWXxjg4Ut/Gjm1 HEpmNjSykKGf5jYYMjB6KA0qvprdabEHKs4oF9Q3YRPhL7InyYK4aNYvMlzBCQM9KFRQ Gusw== 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=PTxw4ybDCrcvFqq9R1qIu91EA31/ELvggdq1ktW6Fqs=; b=si+2Stugf51mijd+r3gJP1+TNzNDzNlPHstQIYV7348vAPg4b0xUpz7GB41rosU2cM jP8dZuokD3OOFQZTHhaR7IwYM1ow/xliAwFvh+APR720ArF97V98xzefSFIv1I3KYsDT LKi2aIkaWoJFUASDzG8y58/kcPwWOLsjH77t4jYadFTa8l0G9NkUOSahPFy0cIsu4OzB UaFUoIAjd9uLjtryAh2BlooJH3II/3H5oeMumXoeoMRzZErly47siTlByY9jY0cW9Sl9 x7RkYjAOfgX3viM+0I+X7LktGV0gD8zMv8+stpWoc7N+THfqpRrj9956xNT1oALqPUeO h5Ug== X-Gm-Message-State: APjAAAVLl6ehKzxiP077GrqjfHuNIhPYLMKpEzGaTfIYhLz3rpeTARoN jqjbv3OlRJgD6UjEuGIjoTn9XUvI X-Google-Smtp-Source: APXvYqyDR9dc+PfrBHbrHjHq4f33VsYGynzcMYj+XSuZ8cujkLxUfqpVDlbvzMQglGQhz4MefdkHBA== X-Received: by 2002:a63:151:: with SMTP id 78mr12232487pgb.302.1575807864920; Sun, 08 Dec 2019 04:24:24 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:24 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:23:04 +1000 Message-Id: <20191208122312.12837-24-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 23/31] libflash: ecc endian conversions X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Signed-off-by: Nicholas Piggin --- libflash/ecc.c | 36 ++++++++++++++++++++---------------- libflash/ecc.h | 8 ++++---- 2 files changed, 24 insertions(+), 20 deletions(-) diff --git a/libflash/ecc.c b/libflash/ecc.c index 0b85fb3ea..8e76e7cf3 100644 --- a/libflash/ecc.c +++ b/libflash/ecc.c @@ -142,30 +142,34 @@ static inline uint64_t eccflipbit(uint64_t data, uint8_t bit) return data ^ (1ul << (63 - bit)); } -static int eccbyte(uint64_t *dst, struct ecc64 *src) +static int eccbyte(beint64_t *dst, struct ecc64 *src) { uint8_t ecc, badbit; uint64_t data; - data = src->data; + data = be64_to_cpu(src->data); ecc = src->ecc; - badbit = eccverify(be64_to_cpu(data), ecc); + badbit = eccverify(data, ecc); if (badbit == UE) { - FL_ERR("ECC: uncorrectable error: %016lx %02x\n", - (long unsigned int)be64_to_cpu(data), ecc); + FL_ERR("ECC: uncorrectable error: %016llx %02x\n", (unsigned long long int)data, ecc); return badbit; } - *dst = data; if (badbit <= UE) FL_INF("ECC: correctable error: %i\n", badbit); if (badbit < 64) - *dst = (uint64_t)be64_to_cpu(eccflipbit(be64_to_cpu(data), - badbit)); + *dst = cpu_to_be64(eccflipbit(data, badbit)); + else + *dst = cpu_to_be64(data); return 0; } +static beint64_t *inc_beint64_by(const void *p, uint64_t i) +{ + return (beint64_t *)(((char *)p) + i); +} + static uint64_t *inc_uint64_by(const void *p, uint64_t i) { return (uint64_t *)(((char *)p) + i); @@ -200,7 +204,7 @@ static uint64_t whole_ecc_structs(uint64_t i) * @retval: 0 - success * @retfal: other - fail */ -int memcpy_from_ecc(uint64_t *dst, struct ecc64 *src, uint64_t len) +int memcpy_from_ecc(beint64_t *dst, struct ecc64 *src, uint64_t len) { uint32_t i; @@ -256,7 +260,7 @@ int memcpy_from_ecc(uint64_t *dst, struct ecc64 *src, uint64_t len) * @retval: 0 - success * @retfal: other - fail */ -int memcpy_from_ecc_unaligned(uint64_t *dst, struct ecc64 *src, +int memcpy_from_ecc_unaligned(beint64_t *dst, struct ecc64 *src, uint64_t len, uint8_t alignment) { char data[BYTES_PER_ECC]; @@ -273,14 +277,14 @@ int memcpy_from_ecc_unaligned(uint64_t *dst, struct ecc64 *src, * required - otherwise jump straight to memcpy_from_ecc() */ if (alignment) { - rc = eccbyte((uint64_t *)data, src); + rc = eccbyte((beint64_t *)data, src); if (rc) return rc; memcpy(dst, &data[alignment], bytes_wanted); src = inc_ecc64_by(src, sizeof(struct ecc64)); - dst = inc_uint64_by(dst, bytes_wanted); + dst = inc_beint64_by(dst, bytes_wanted); len -= bytes_wanted; } @@ -299,7 +303,7 @@ int memcpy_from_ecc_unaligned(uint64_t *dst, struct ecc64 *src, } if (len) { - rc = eccbyte((uint64_t *)data, src); + rc = eccbyte((beint64_t *)data, src); if (rc) return rc; @@ -323,7 +327,7 @@ int memcpy_from_ecc_unaligned(uint64_t *dst, struct ecc64 *src, * @retval: 0 - success * @retfal: other - fail */ -int memcpy_to_ecc(struct ecc64 *dst, const uint64_t *src, uint64_t len) +int memcpy_to_ecc(struct ecc64 *dst, const beint64_t *src, uint64_t len) { struct ecc64 ecc_word; uint64_t i; @@ -390,7 +394,7 @@ int memcpy_to_ecc(struct ecc64 *dst, const uint64_t *src, uint64_t len) * @retfal: other - fail */ -int memcpy_to_ecc_unaligned(struct ecc64 *dst, const uint64_t *src, +int memcpy_to_ecc_unaligned(struct ecc64 *dst, const beint64_t *src, uint64_t len, uint8_t alignment) { struct ecc64 ecc_word; @@ -412,7 +416,7 @@ int memcpy_to_ecc_unaligned(struct ecc64 *dst, const uint64_t *src, sizeof(struct ecc64) - alignment); dst = inc_ecc64_by(dst, sizeof(struct ecc64) - alignment); - src = inc_uint64_by(src, bytes_wanted); + src = inc_beint64_by(src, bytes_wanted); len -= bytes_wanted; } diff --git a/libflash/ecc.h b/libflash/ecc.h index 608d50008..75c3adf22 100644 --- a/libflash/ecc.h +++ b/libflash/ecc.h @@ -16,12 +16,12 @@ struct ecc64 { uint8_t ecc; } __attribute__((__packed__)); -extern int memcpy_from_ecc(uint64_t *dst, struct ecc64 *src, uint64_t len); -extern int memcpy_from_ecc_unaligned(uint64_t *dst, struct ecc64 *src, uint64_t len, +extern int memcpy_from_ecc(beint64_t *dst, struct ecc64 *src, uint64_t len); +extern int memcpy_from_ecc_unaligned(beint64_t *dst, struct ecc64 *src, uint64_t len, uint8_t alignment); -extern int memcpy_to_ecc(struct ecc64 *dst, const uint64_t *src, uint64_t len); -extern int memcpy_to_ecc_unaligned(struct ecc64 *dst, const uint64_t *src, uint64_t len, +extern int memcpy_to_ecc(struct ecc64 *dst, const beint64_t *src, uint64_t len); +extern int memcpy_to_ecc_unaligned(struct ecc64 *dst, const beint64_t *src, uint64_t len, uint8_t alignment); /* From patchwork Sun Dec 8 12:23:05 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205646 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5P91wjCz9sP3 for ; Sun, 8 Dec 2019 23:34:37 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="PpkQHau4"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5P862KYzDqPS for ; Sun, 8 Dec 2019 23:34:36 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::441; helo=mail-pf1-x441.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="PpkQHau4"; dkim-atps=neutral Received: from mail-pf1-x441.google.com (mail-pf1-x441.google.com [IPv6:2607:f8b0:4864:20::441]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W59V0Z46zDqFL for ; Sun, 8 Dec 2019 23:24:30 +1100 (AEDT) Received: by mail-pf1-x441.google.com with SMTP id n13so5767223pff.1 for ; Sun, 08 Dec 2019 04:24:29 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=UiR6wrjmh6Wpu3YVg89/kU5w9vJBnSc0kMIDJFqKb8I=; b=PpkQHau4LgodyrP8rUQv8vxHXAET6LiM0VE5N+qFn20mOyClgQ+nyGIQbVB+0nDtCI +uRfwCpGTs024bT6KKbd0u+YCJVBrk6qcQdReT1frPM/ycqo3ELJF6o0B2KvqbJ1c8XI Njt7+fBiClZtYE0jVrhlcAmkr3lyu0bm9zhz8JKoFuBcXIF8iW7URKqZBJA+72vA94Pr a778jvx61gRG6SBb7elGewC1Q4gtIyB/RUCVzuMqi0ilxOFoYnsoLTzgDRxT+8uUKaGI c1cW86E7+9WsJE7ui3sELpDf38EtRMHkZ9dwUAv6HpbElaAJYCJ+RpCwxUT40pWi5y9M TbFw== 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=UiR6wrjmh6Wpu3YVg89/kU5w9vJBnSc0kMIDJFqKb8I=; b=jkxC5w1wYL4XhY74vAjk9qdHO4IbvpoLNnJWKseWR3IGXJ0TbuVkPO+7FbhCR081ai wwbiSmStzLh/pMiUlQxeX+KTob69XDBba2B+NK7X02N16izQQU+ifm2etKXyjOq+S6hs 7DsFSyVDkok9GX/yC7hYrADfnqz3jnysl2fQmc8p3ltd4YR/7XLCR9uWsWBWYYlviQni 8wkqaqRZeC6K79TXmYAu+JprHzZzDpnRceuaHGlFUHThKm1Fcy6kZpvxWm7AjaawOx+6 mXpzamNUT/qsYSNGQq386K1ZgIQrGmtays0xYUmG0Lct4Cy/SCm9+lL32abtUcBI/B3W WRPA== X-Gm-Message-State: APjAAAWavQUdGSFeYuUdPYPpIqFMA2Nk9dgXvR38oOIAxqtJ52XK3FSe ZHmouIozp/1VD3SNIhrfdh7VNQmV X-Google-Smtp-Source: APXvYqzq7o0rUYXuiMUDrJTQEWTjRK3/xbtIji/RXXoQZjIwnftscP1V3KrvPuLHADCvAhrNQg81GQ== X-Received: by 2002:a62:1e42:: with SMTP id e63mr24911245pfe.25.1575807867964; Sun, 08 Dec 2019 04:24:27 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.25 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:27 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:23:05 +1000 Message-Id: <20191208122312.12837-25-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 24/31] prd: endian conversions X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Reviewed-by: Vasant Hegde Signed-off-by: Nicholas Piggin --- hw/prd.c | 64 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 32 insertions(+), 32 deletions(-) diff --git a/hw/prd.c b/hw/prd.c index 69cfbf9d5..2301dafd0 100644 --- a/hw/prd.c +++ b/hw/prd.c @@ -84,7 +84,7 @@ static void prd_msg_consumed(void *data, int status) lock(&events_lock); switch (msg->hdr.type) { case OPAL_PRD_MSG_TYPE_ATTN: - proc = msg->attn.proc; + proc = be64_to_cpu(msg->attn.proc); /* If other ipoll events have been received in the time * between prd_msg creation and consumption, we'll need to @@ -92,17 +92,17 @@ static void prd_msg_consumed(void *data, int status) * clear the event if we don't have any further ipoll_status * bits. */ - ipoll_status[proc] &= ~msg->attn.ipoll_status; + ipoll_status[proc] &= ~be64_to_cpu(msg->attn.ipoll_status); if (!ipoll_status[proc]) event = EVENT_ATTN; break; case OPAL_PRD_MSG_TYPE_OCC_ERROR: - proc = msg->occ_error.chip; + proc = be64_to_cpu(msg->occ_error.chip); event = EVENT_OCC_ERROR; break; case OPAL_PRD_MSG_TYPE_OCC_RESET: - proc = msg->occ_reset.chip; + proc = be64_to_cpu(msg->occ_reset.chip); event = EVENT_OCC_RESET; break; case OPAL_PRD_MSG_TYPE_FIRMWARE_RESPONSE: @@ -126,15 +126,15 @@ static void prd_msg_consumed(void *data, int status) platform.prd->msg_response(notify_status); break; case OPAL_PRD_MSG_TYPE_SBE_PASSTHROUGH: - proc = msg->sbe_passthrough.chip; + proc = be64_to_cpu(msg->sbe_passthrough.chip); event = EVENT_SBE_PASSTHROUGH; break; case OPAL_PRD_MSG_TYPE_FSP_OCC_RESET: - proc = msg->occ_reset.chip; + proc = be64_to_cpu(msg->occ_reset.chip); event = EVENT_FSP_OCC_RESET; break; case OPAL_PRD_MSG_TYPE_FSP_OCC_LOAD_START: - proc = msg->occ_reset.chip; + proc = be64_to_cpu(msg->occ_reset.chip); event = EVENT_FSP_OCC_LOAD_START; break; default: @@ -180,9 +180,9 @@ static int populate_ipoll_msg(struct opal_prd_msg *msg, uint32_t proc) return -1; } - msg->attn.proc = proc; - msg->attn.ipoll_status = ipoll_status[proc]; - msg->attn.ipoll_mask = ipoll_mask; + msg->attn.proc = cpu_to_be64(proc); + msg->attn.ipoll_status = cpu_to_be64(ipoll_status[proc]); + msg->attn.ipoll_mask = cpu_to_be64(ipoll_mask); return 0; } @@ -212,27 +212,27 @@ static void send_next_pending_event(void) return; prd_msg->token = 0; - prd_msg->hdr.size = sizeof(*prd_msg); + prd_msg->hdr.size = cpu_to_be16(sizeof(*prd_msg)); if (event & EVENT_ATTN) { prd_msg->hdr.type = OPAL_PRD_MSG_TYPE_ATTN; populate_ipoll_msg(prd_msg, proc); } else if (event & EVENT_OCC_ERROR) { prd_msg->hdr.type = OPAL_PRD_MSG_TYPE_OCC_ERROR; - prd_msg->occ_error.chip = proc; + prd_msg->occ_error.chip = cpu_to_be64(proc); } else if (event & EVENT_OCC_RESET) { prd_msg->hdr.type = OPAL_PRD_MSG_TYPE_OCC_RESET; - prd_msg->occ_reset.chip = proc; + prd_msg->occ_reset.chip = cpu_to_be64(proc); occ_msg_queue_occ_reset(); } else if (event & EVENT_SBE_PASSTHROUGH) { prd_msg->hdr.type = OPAL_PRD_MSG_TYPE_SBE_PASSTHROUGH; - prd_msg->sbe_passthrough.chip = proc; + prd_msg->sbe_passthrough.chip = cpu_to_be64(proc); } else if (event & EVENT_FSP_OCC_RESET) { prd_msg->hdr.type = OPAL_PRD_MSG_TYPE_FSP_OCC_RESET; - prd_msg->occ_reset.chip = proc; + prd_msg->occ_reset.chip = cpu_to_be64(proc); } else if (event & EVENT_FSP_OCC_LOAD_START) { prd_msg->hdr.type = OPAL_PRD_MSG_TYPE_FSP_OCC_LOAD_START; - prd_msg->occ_reset.chip = proc; + prd_msg->occ_reset.chip = cpu_to_be64(proc); } /* @@ -351,7 +351,7 @@ void prd_fw_resp_fsp_response(int status) fw_resp->type = cpu_to_be64(PRD_FW_MSG_TYPE_RESP_GENERIC); fw_resp->generic_resp.status = cpu_to_be64(status); - fw_resp_len_old = prd_msg_fsp_req->fw_resp.len; + fw_resp_len_old = be64_to_cpu(prd_msg_fsp_req->fw_resp.len); prd_msg_fsp_req->fw_resp.len = cpu_to_be64(PRD_FW_MSG_BASE_SIZE + sizeof(fw_resp->generic_resp)); @@ -430,8 +430,8 @@ static int prd_msg_handle_attn_ack(struct opal_prd_msg *msg) int rc; lock(&ipoll_lock); - rc = __ipoll_update_mask(msg->attn_ack.proc, false, - msg->attn_ack.ipoll_ack & prd_ipoll_mask); + rc = __ipoll_update_mask(be64_to_cpu(msg->attn_ack.proc), false, + be64_to_cpu(msg->attn_ack.ipoll_ack) & prd_ipoll_mask); unlock(&ipoll_lock); if (rc) @@ -447,7 +447,7 @@ static int prd_msg_handle_init(struct opal_prd_msg *msg) lock(&ipoll_lock); for_each_chip(chip) { __ipoll_update_mask(chip->id, false, - msg->init.ipoll & prd_ipoll_mask); + be64_to_cpu(msg->init.ipoll) & prd_ipoll_mask); } unlock(&ipoll_lock); @@ -497,7 +497,7 @@ static int prd_msg_handle_firmware_req(struct opal_prd_msg *msg) /* does the total (outer) PRD message len provide enough data for the * claimed (inner) FW message? */ - if (msg->hdr.size < fw_req_len + + if (be16_to_cpu(msg->hdr.size) < fw_req_len + offsetof(struct opal_prd_msg, fw_req.data)) return -EINVAL; @@ -524,8 +524,8 @@ static int prd_msg_handle_firmware_req(struct opal_prd_msg *msg) case PRD_FW_MSG_TYPE_ERROR_LOG: assert(platform.prd); assert(platform.prd->send_error_log); - rc = platform.prd->send_error_log(fw_req->errorlog.plid, - fw_req->errorlog.size, + rc = platform.prd->send_error_log(be32_to_cpu(fw_req->errorlog.plid), + be32_to_cpu(fw_req->errorlog.size), fw_req->errorlog.data); /* Return generic response to HBRT */ fw_resp->type = cpu_to_be64(PRD_FW_MSG_TYPE_RESP_GENERIC); @@ -581,7 +581,7 @@ static int prd_msg_handle_firmware_req(struct opal_prd_msg *msg) prd_msg_fsp_req->hdr.type = OPAL_PRD_MSG_TYPE_FIRMWARE_RESPONSE; prd_msg_fsp_req->hdr.size = cpu_to_be16(resp_msg_size); prd_msg_fsp_req->token = 0; - prd_msg_fsp_req->fw_resp.len = fw_req_len; + prd_msg_fsp_req->fw_resp.len = cpu_to_be64(fw_req_len); /* copy HBRT data to local memory */ fw_resp = (struct prd_fw_msg *)prd_msg_fsp_req->fw_resp.data; @@ -644,11 +644,11 @@ static int64_t opal_prd_msg(struct opal_prd_msg *msg) /* fini is a little special: the kernel (which may not have the entire * opal_prd_msg definition) can send a FINI message, so we don't check * the full size */ - if (msg->hdr.size >= sizeof(struct opal_prd_msg_header) && + if (be16_to_cpu(msg->hdr.size) >= sizeof(struct opal_prd_msg_header) && msg->hdr.type == OPAL_PRD_MSG_TYPE_FINI) return prd_msg_handle_fini(); - if (msg->hdr.size < sizeof(*msg)) + if (be16_to_cpu(msg->hdr.size) < sizeof(*msg)) return OPAL_PARAMETER; switch (msg->hdr.type) { @@ -668,21 +668,21 @@ static int64_t opal_prd_msg(struct opal_prd_msg *msg) assert(platform.prd); assert(platform.prd->fsp_occ_reset_status); rc = platform.prd->fsp_occ_reset_status( - msg->fsp_occ_reset_status.chip, - msg->fsp_occ_reset_status.status); + be64_to_cpu(msg->fsp_occ_reset_status.chip), + be64_to_cpu(msg->fsp_occ_reset_status.status)); break; case OPAL_PRD_MSG_TYPE_CORE_SPECIAL_WAKEUP: assert(platform.prd); assert(platform.prd->wakeup); - rc = platform.prd->wakeup(msg->spl_wakeup.core, - msg->spl_wakeup.mode); + rc = platform.prd->wakeup(be32_to_cpu(msg->spl_wakeup.core), + be32_to_cpu(msg->spl_wakeup.mode)); break; case OPAL_PRD_MSG_TYPE_FSP_OCC_LOAD_START_STATUS: assert(platform.prd); assert(platform.prd->fsp_occ_load_start_status); rc = platform.prd->fsp_occ_load_start_status( - msg->fsp_occ_reset_status.chip, - msg->fsp_occ_reset_status.status); + be64_to_cpu(msg->fsp_occ_reset_status.chip), + be64_to_cpu(msg->fsp_occ_reset_status.status)); break; default: prlog(PR_DEBUG, "PRD: Unsupported prd message type : 0x%x\n", From patchwork Sun Dec 8 12:23:06 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205647 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5PS0Xnvz9sPK for ; Sun, 8 Dec 2019 23:34:52 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="el7SjHlp"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5PR5x4qzDqDV for ; Sun, 8 Dec 2019 23:34:51 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::52c; helo=mail-pg1-x52c.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="el7SjHlp"; dkim-atps=neutral Received: from mail-pg1-x52c.google.com (mail-pg1-x52c.google.com [IPv6:2607:f8b0:4864:20::52c]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W59Z1h0hzDqL8 for ; Sun, 8 Dec 2019 23:24:34 +1100 (AEDT) Received: by mail-pg1-x52c.google.com with SMTP id x7so5653368pgl.11 for ; Sun, 08 Dec 2019 04:24:34 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=k1iYJAyT5G/uFX9KEUin5LS5jWHNb47r2xpz01DOa3Q=; b=el7SjHlpns+ojsSSsgOBplFFWi4cAc+JapPTz47AUE+tmMQpPv/JmEqK/1AubDIbBo R8zJGOkTH3myJWlWVlJdjfoRwV8cDlgN3EajBXOWGjt0Ytm6c9me6aj8bCrOQasBqFfG gO34pWh2jS4eu1RTVKL5ys58GFepWd6H0W9c7YEfTmMuLU6CBs5RY3OyHeEiryDkd2JV hCdQxEK/f7fK4/yJBtD73MHarenlGUumMssfZKGj/fbjFQb6q1hsavHq+TxwRkI0vkgc 8pptO+um8c4wvS5OX2Y0XJNGHemS+0r5zii5W/paXI6AfWQygzdu5TE8qzql4oPtejy0 CDOA== 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=k1iYJAyT5G/uFX9KEUin5LS5jWHNb47r2xpz01DOa3Q=; b=ZsDhySzSQxxJZuBcNhmWluiOADi6kUaksQ3l/pTVJm2i28QJbOYHtJqgtmfFacXMib mWwPCrtJ1nj5tRSxy65e4XOoFa/w1po3VNtt6u4caWOQMALzdl8JmgN6JWNAK67AP++h NDBrHkt3RMXWVYTBf1N5tSq8U4krAW+BjgSXC8sNa8cdbvuBxiJEw4v2EKxx6CuiTQud j7eGlg3TLl5C/PAw7Cf/OjXhQzYzsplY4Kz6Vx4+yGBTy8SZWCcQj7gF+C9dyY0S83aW gkgG5DLbd0aGvtYg8IUxxhJRzkfZ2QaPMpwFitcy8y7pz8PXwpq9waCQNjyh9EaNtovu J1jA== X-Gm-Message-State: APjAAAWv+WQh8bWlOUsYvGmBXOTgrV8v2O+F/4okKaannJSMYyPoBsVN wv5VLzTPjN2XRrJW2GsSvyeGuvuI X-Google-Smtp-Source: APXvYqzsknQWv9JjqIQUD2Uh7Ka840ZkxYfgrprgGaKkJOluIBcLUnvJDkq75HbXu7jQtnAmbvRvdw== X-Received: by 2002:aa7:9197:: with SMTP id x23mr25178182pfa.163.1575807872113; Sun, 08 Dec 2019 04:24:32 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.28 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:31 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:23:06 +1000 Message-Id: <20191208122312.12837-26-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 25/31] opal-dump: MPIPL endan conversions X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Reviewed-by: Vasant Hegde Signed-off-by: Nicholas Piggin --- core/opal-dump.c | 90 +++++++++++++++++++++++++--------------------- include/opal-api.h | 14 ++++---- 2 files changed, 56 insertions(+), 48 deletions(-) diff --git a/core/opal-dump.c b/core/opal-dump.c index 3bea1f105..256c9c949 100644 --- a/core/opal-dump.c +++ b/core/opal-dump.c @@ -68,18 +68,18 @@ static int opal_mpipl_max_tags = MAX_OPAL_MPIPL_TAGS; static int opal_mpipl_add_entry(u8 region, u64 src, u64 dest, u64 size) { - int i, max_cnt; + int i; + int mdst_cnt = be16_to_cpu(ntuple_mdst->act_cnt); + int mddt_cnt = be16_to_cpu(ntuple_mddt->act_cnt); struct mdst_table *mdst; struct mddt_table *mddt; - max_cnt = MDST_TABLE_SIZE / sizeof(struct mdst_table); - if (ntuple_mdst->act_cnt >= max_cnt) { + if (mdst_cnt >= MDST_TABLE_SIZE / sizeof(struct mdst_table)) { prlog(PR_DEBUG, "MDST table is full\n"); return OPAL_RESOURCE; } - max_cnt = MDDT_TABLE_SIZE / sizeof(struct mddt_table); - if (ntuple_mdst->act_cnt >= max_cnt) { + if (mddt_cnt >= MDDT_TABLE_SIZE / sizeof(struct mddt_table)) { prlog(PR_DEBUG, "MDDT table is full\n"); return OPAL_RESOURCE; } @@ -89,16 +89,16 @@ static int opal_mpipl_add_entry(u8 region, u64 src, u64 dest, u64 size) mddt = (void *)(MDDT_TABLE_BASE); /* Check for duplicate entry */ - for (i = 0; i < ntuple_mdst->act_cnt; i++) { - if (mdst->addr == (src | HRMOR_BIT)) { + for (i = 0; i < mdst_cnt; i++) { + if (be64_to_cpu(mdst->addr) == (src | HRMOR_BIT)) { prlog(PR_DEBUG, "Duplicate source address : 0x%llx", src); return OPAL_PARAMETER; } mdst++; } - for (i = 0; i < ntuple_mddt->act_cnt; i++) { - if (mddt->addr == (dest | HRMOR_BIT)) { + for (i = 0; i < mddt_cnt; i++) { + if (be64_to_cpu(mddt->addr) == (dest | HRMOR_BIT)) { prlog(PR_DEBUG, "Duplicate destination address : 0x%llx", dest); return OPAL_PARAMETER; @@ -107,16 +107,16 @@ static int opal_mpipl_add_entry(u8 region, u64 src, u64 dest, u64 size) } /* Add OPAL source address to MDST entry */ - mdst->addr = src | HRMOR_BIT; + mdst->addr = cpu_to_be64(src | HRMOR_BIT); mdst->data_region = region; - mdst->size = size; - ntuple_mdst->act_cnt++; + mdst->size = cpu_to_be32(size); + ntuple_mdst->act_cnt = cpu_to_be16(mdst_cnt + 1); /* Add OPAL destination address to MDDT entry */ - mddt->addr = dest | HRMOR_BIT; + mddt->addr = cpu_to_be64(dest | HRMOR_BIT); mddt->data_region = region; - mddt->size = size; - ntuple_mddt->act_cnt++; + mddt->size = cpu_to_be32(size); + ntuple_mddt->act_cnt = cpu_to_be16(mddt_cnt + 1); prlog(PR_TRACE, "Added new entry. src : 0x%llx, dest : 0x%llx," " size : 0x%llx\n", src, dest, size); @@ -128,17 +128,19 @@ static int opal_mpipl_remove_entry_mdst(bool remove_all, u8 region, u64 src) { bool found = false; int i, j; + int mdst_cnt = be16_to_cpu(ntuple_mdst->act_cnt); struct mdst_table *tmp_mdst; struct mdst_table *mdst = (void *)(MDST_TABLE_BASE); - for (i = 0; i < ntuple_mdst->act_cnt;) { + for (i = 0; i < mdst_cnt;) { if (mdst->data_region != region) { mdst++; i++; continue; } - if (remove_all != true && mdst->addr != (src | HRMOR_BIT)) { + if (remove_all != true && + be64_to_cpu(mdst->addr) != (src | HRMOR_BIT)) { mdst++; i++; continue; @@ -147,14 +149,14 @@ static int opal_mpipl_remove_entry_mdst(bool remove_all, u8 region, u64 src) tmp_mdst = mdst; memset(tmp_mdst, 0, sizeof(struct mdst_table)); - for (j = i; j < ntuple_mdst->act_cnt - 1; j++) { + for (j = i; j < mdst_cnt - 1; j++) { memcpy((void *)tmp_mdst, (void *)(tmp_mdst + 1), sizeof(struct mdst_table)); tmp_mdst++; memset(tmp_mdst, 0, sizeof(struct mdst_table)); } - ntuple_mdst->act_cnt--; + mdst_cnt--; if (remove_all == false) { found = true; @@ -162,6 +164,8 @@ static int opal_mpipl_remove_entry_mdst(bool remove_all, u8 region, u64 src) } } /* end - for loop */ + ntuple_mdst->act_cnt = cpu_to_be16((u16)mdst_cnt); + if (remove_all == false && found == false) { prlog(PR_DEBUG, "Source address [0x%llx] not found in MDST table\n", src); @@ -176,17 +180,19 @@ static int opal_mpipl_remove_entry_mddt(bool remove_all, u8 region, u64 dest) { bool found = false; int i, j; + int mddt_cnt = be16_to_cpu(ntuple_mddt->act_cnt); struct mddt_table *tmp_mddt; struct mddt_table *mddt = (void *)(MDDT_TABLE_BASE); - for (i = 0; i < ntuple_mddt->act_cnt;) { + for (i = 0; i < mddt_cnt;) { if (mddt->data_region != region) { mddt++; i++; continue; } - if (remove_all != true && mddt->addr != (dest | HRMOR_BIT)) { + if (remove_all != true && + be64_to_cpu(mddt->addr) != (dest | HRMOR_BIT)) { mddt++; i++; continue; @@ -195,14 +201,14 @@ static int opal_mpipl_remove_entry_mddt(bool remove_all, u8 region, u64 dest) tmp_mddt = mddt; memset(tmp_mddt, 0, sizeof(struct mddt_table)); - for (j = i; j < ntuple_mddt->act_cnt - 1; j++) { + for (j = i; j < mddt_cnt - 1; j++) { memcpy((void *)tmp_mddt, (void *)(tmp_mddt + 1), sizeof(struct mddt_table)); tmp_mddt++; memset(tmp_mddt, 0, sizeof(struct mddt_table)); } - ntuple_mddt->act_cnt--; + mddt_cnt--; if (remove_all == false) { found = true; @@ -210,6 +216,8 @@ static int opal_mpipl_remove_entry_mddt(bool remove_all, u8 region, u64 dest) } } /* end - for loop */ + ntuple_mddt->act_cnt = cpu_to_be16((u16)mddt_cnt); + if (remove_all == false && found == false) { prlog(PR_DEBUG, "Dest address [0x%llx] not found in MDDT table\n", dest); @@ -258,8 +266,8 @@ static void opal_mpipl_register(void) /* Reserve memory used to capture architected register state */ mem_reserve_fw("ibm,firmware-arch-registers", arch_regs_dest, arch_regs_size); - proc_dump->alloc_addr = arch_regs_dest | HRMOR_BIT; - proc_dump->alloc_size = arch_regs_size; + proc_dump->alloc_addr = cpu_to_be64(arch_regs_dest | HRMOR_BIT); + proc_dump->alloc_size = cpu_to_be32(arch_regs_size); prlog(PR_NOTICE, "Architected register dest addr : 0x%llx, " "size : 0x%llx\n", arch_regs_dest, arch_regs_size); } @@ -339,7 +347,7 @@ static int64_t opal_mpipl_update(enum opal_mpipl_ops ops, /* Clear MDRT table */ memset((void *)MDRT_TABLE_BASE, 0, MDRT_TABLE_SIZE); /* Set MDRT count to max allocated count */ - ntuple_mdrt->act_cnt = MDRT_TABLE_SIZE / sizeof(struct mdrt_table); + ntuple_mdrt->act_cnt = cpu_to_be16(MDRT_TABLE_SIZE / sizeof(struct mdrt_table)); rc = OPAL_SUCCESS; prlog(PR_NOTICE, "Payload Invalidated MPIPL\n"); break; @@ -380,8 +388,7 @@ static int64_t opal_mpipl_register_tag(enum opal_mpipl_tags tag, return rc; } -static uint64_t opal_mpipl_query_tag(enum opal_mpipl_tags tag, - uint64_t *tag_val) +static uint64_t opal_mpipl_query_tag(enum opal_mpipl_tags tag, __be64 *tag_val) { if (!opal_addr_valid(tag_val)) { prlog(PR_DEBUG, "Invalid tag address\n"); @@ -391,7 +398,7 @@ static uint64_t opal_mpipl_query_tag(enum opal_mpipl_tags tag, if (tag >= opal_mpipl_max_tags) return OPAL_PARAMETER; - *tag_val = opal_mpipl_tags[tag]; + *tag_val = cpu_to_be64(opal_mpipl_tags[tag]); return OPAL_SUCCESS; } @@ -426,13 +433,13 @@ static void post_mpipl_arch_regs_data(void) /* Fill CPU register details */ opal_mpipl_cpu_data->version = OPAL_MPIPL_VERSION; - opal_mpipl_cpu_data->cpu_data_version = proc_dump->version; + opal_mpipl_cpu_data->cpu_data_version = cpu_to_be32((u32)proc_dump->version); opal_mpipl_cpu_data->cpu_data_size = proc_dump->thread_size; opal_mpipl_cpu_data->region_cnt = cpu_to_be32(1); - opal_mpipl_cpu_data->region[0].src = proc_dump->dest_addr & ~(HRMOR_BIT); - opal_mpipl_cpu_data->region[0].dest = proc_dump->dest_addr & ~(HRMOR_BIT); - opal_mpipl_cpu_data->region[0].size = proc_dump->act_size; + opal_mpipl_cpu_data->region[0].src = proc_dump->dest_addr & ~(cpu_to_be64(HRMOR_BIT)); + opal_mpipl_cpu_data->region[0].dest = proc_dump->dest_addr & ~(cpu_to_be64(HRMOR_BIT)); + opal_mpipl_cpu_data->region[0].size = cpu_to_be64(be32_to_cpu(proc_dump->act_size)); /* Update tag */ opal_mpipl_tags[OPAL_MPIPL_TAG_CPU] = (u64)opal_mpipl_cpu_data; @@ -442,7 +449,7 @@ static void post_mpipl_get_opal_data(void) { struct mdrt_table *mdrt = (void *)(MDRT_TABLE_BASE); int i, j = 0, count = 0; - u32 mdrt_cnt = ntuple_mdrt->act_cnt; + int mdrt_cnt = be16_to_cpu(ntuple_mdrt->act_cnt); struct opal_mpipl_region *region; /* Count OPAL dump regions */ @@ -466,8 +473,8 @@ static void post_mpipl_get_opal_data(void) /* Fill OPAL dump details */ opal_mpipl_data->version = OPAL_MPIPL_VERSION; - opal_mpipl_data->crashing_pir = mpipl_metadata->crashing_pir; - opal_mpipl_data->region_cnt = count; + opal_mpipl_data->crashing_pir = cpu_to_be32(mpipl_metadata->crashing_pir); + opal_mpipl_data->region_cnt = cpu_to_be32(count); region = opal_mpipl_data->region; mdrt = (void *)(MDRT_TABLE_BASE); @@ -477,13 +484,14 @@ static void post_mpipl_get_opal_data(void) continue; } - region[j].src = mdrt->src_addr & ~(HRMOR_BIT); - region[j].dest = mdrt->dest_addr & ~(HRMOR_BIT); - region[j].size = mdrt->size; + region[j].src = mdrt->src_addr & ~(cpu_to_be64(HRMOR_BIT)); + region[j].dest = mdrt->dest_addr & ~(cpu_to_be64(HRMOR_BIT)); + region[j].size = cpu_to_be64(be32_to_cpu(mdrt->size)); prlog(PR_NOTICE, "OPAL reserved region %d - src : 0x%llx, " - "dest : 0x%llx, size : 0x%llx\n", j, region[j].src, - region[j].dest, region[j].size); + "dest : 0x%llx, size : 0x%llx\n", j, + be64_to_cpu(region[j].src), be64_to_cpu(region[j].dest), + be64_to_cpu(region[j].size)); mdrt++; j++; diff --git a/include/opal-api.h b/include/opal-api.h index d92ecf549..5b07dea13 100644 --- a/include/opal-api.h +++ b/include/opal-api.h @@ -1236,9 +1236,9 @@ enum opal_mpipl_tags { /* Preserved memory details */ struct opal_mpipl_region { - u64 src; - u64 dest; - u64 size; + __be64 src; + __be64 dest; + __be64 size; }; /* Structure version */ @@ -1247,10 +1247,10 @@ struct opal_mpipl_region { struct opal_mpipl_fadump { u8 version; u8 reserved[7]; - u32 crashing_pir; /* OPAL crashing CPU PIR */ - u32 cpu_data_version; - u32 cpu_data_size; - u32 region_cnt; + __be32 crashing_pir; /* OPAL crashing CPU PIR */ + __be32 cpu_data_version; + __be32 cpu_data_size; + __be32 region_cnt; struct opal_mpipl_region region[]; }; From patchwork Sun Dec 8 12:23:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205648 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5Pr4vltz9sPK for ; Sun, 8 Dec 2019 23:35:12 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="eXQ5WKip"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5Pr2TqtzDqHr for ; Sun, 8 Dec 2019 23:35:12 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::442; helo=mail-pf1-x442.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="eXQ5WKip"; dkim-atps=neutral Received: from mail-pf1-x442.google.com (mail-pf1-x442.google.com [IPv6:2607:f8b0:4864:20::442]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W59c48lPzDqLd for ; Sun, 8 Dec 2019 23:24:36 +1100 (AEDT) Received: by mail-pf1-x442.google.com with SMTP id h14so5741059pfe.10 for ; Sun, 08 Dec 2019 04:24:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=nbK3P51iV91Lhm+V6LgZgLT1Nyd+Sf5dGmmno7i0JiI=; b=eXQ5WKipaCKUsrJebQ0uVt68R+/EDPGt8t+qa6dle06Na3FJ3Htxw00TKI5gQr7llS YHIFWscXdXsenwfz7+PH1GJ/L49wQYK9XeeCi9QfvJvADL/M0ejJM5nPT/bvL/H+Th1n xeuOl95VUFT/4/JinDa5pPMeL+riGQIHeMNQL0fMt79ymQLIKFGszRYllfcqEiIcxhN8 3JLzUDol42Q9vUoqdVutFHG2e+6l4Gi/WZdPBCKgMAPHTjQftVD1o/6dxWuNOE868Moh homwfwz1vE8OcABM/kGryR/ulCHUiJan8bRfKUkGJbCQqCzlB1P74wzjmSLMTAvQexRp p6rA== 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=nbK3P51iV91Lhm+V6LgZgLT1Nyd+Sf5dGmmno7i0JiI=; b=n5jAFVfMniXUHIzdzgZuCu7MyJxwGv5bRx3ICvxyr9qY8buXDH9i27T8CLX57JLiqU 5CkW6NsCmEz1GVJ88N7CLzdfdZ9wyYu/O9bzLqRIFPD8CeGhdTqaYfLrXXpAUrk0jqgA JfvRoAftSSND+8pOXAnVWU0rtdjJrW+FqngxAiZl+6fhNR6hjmnsrCxpbbz9lyCZaecr 64HM/I9e3MMeCc1cUDJ6eW7PXlh8mhOuUa5xK2fkqqlIKqHOoOkcmFsauY3+mTLm1TlI ifDPvLcaZcQvUunK+t2f1TKpFMPnjaAVZ0WvFvURFIrImThzig6G2yqqfSdF1bUXucuB y+FA== X-Gm-Message-State: APjAAAWvQ/vJyGp7Cll8xUTVhz4YhG6cSBHtpV75L79MN9onum4YbQkT sBkdRERUZUCjJHRhMB9iTAD/L+Va X-Google-Smtp-Source: APXvYqxXykwAEH+Ph/9wuRwAWC4/uBvi7Yyngik8W6vLenkc1BYQafU9GdUaPxqcfIu7Oyzz4lXfMA== X-Received: by 2002:a63:e30a:: with SMTP id f10mr13332789pgh.331.1575807874564; Sun, 08 Dec 2019 04:24:34 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.32 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:34 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:23:07 +1000 Message-Id: <20191208122312.12837-27-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 26/31] sfc-ctrl: endian conversions X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Signed-off-by: Nicholas Piggin --- hw/sfc-ctrl.c | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/hw/sfc-ctrl.c b/hw/sfc-ctrl.c index f17b8de29..d66be09eb 100644 --- a/hw/sfc-ctrl.c +++ b/hw/sfc-ctrl.c @@ -110,33 +110,32 @@ struct sfc_ctrl { /* Command register support */ static inline int sfc_reg_read(uint8_t reg, uint32_t *val) { - uint32_t tmp; int rc; *val = 0xffffffff; - rc = lpc_fw_read32(&tmp, SFC_CMDREG_OFFSET + reg); + rc = lpc_fw_read32(val, SFC_CMDREG_OFFSET + reg); if (rc) return rc; - *val = be32_to_cpu(tmp); return 0; } static inline int sfc_reg_write(uint8_t reg, uint32_t val) { - return lpc_fw_write32(cpu_to_be32(val), SFC_CMDREG_OFFSET + reg); + return lpc_fw_write32(val, SFC_CMDREG_OFFSET + reg); } static int sfc_buf_write(uint32_t len, const void *data) { - uint32_t tmp, off = 0; + __be32 tmp; + uint32_t off = 0; int rc; if (len > SFC_CMDBUF_SIZE) return FLASH_ERR_PARM_ERROR; while (len >= 4) { - tmp = *(const uint32_t *)data; - rc = lpc_fw_write32(tmp, SFC_CMDBUF_OFFSET + off); + tmp = cpu_to_be32(*(const uint32_t *)data); + rc = lpc_fw_write32((u32)tmp, SFC_CMDBUF_OFFSET + off); if (rc) return rc; off += 4; @@ -150,9 +149,9 @@ static int sfc_buf_write(uint32_t len, const void *data) * in memory with memcpy. The swap in the register on LE doesn't * matter, the result in memory will be in the right order. */ - tmp = -1; - memcpy(&tmp, data, len); - return lpc_fw_write32(tmp, SFC_CMDBUF_OFFSET + off); + tmp = cpu_to_be32(-1); + memcpy(&tmp, data, len); /* XXX: is this right? */ + return lpc_fw_write32((u32)tmp, SFC_CMDBUF_OFFSET + off); } static int sfc_buf_read(uint32_t len, void *data) From patchwork Sun Dec 8 12:23:08 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205649 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5QG4kPZz9sPf for ; Sun, 8 Dec 2019 23:35:34 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jcypr+mf"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5QF6LqRzDqCp for ; Sun, 8 Dec 2019 23:35:33 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::443; helo=mail-pf1-x443.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="jcypr+mf"; dkim-atps=neutral Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W59g43shzDqDV for ; Sun, 8 Dec 2019 23:24:39 +1100 (AEDT) Received: by mail-pf1-x443.google.com with SMTP id n13so5767319pff.1 for ; Sun, 08 Dec 2019 04:24:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=SL7UNLdugsPghYw05DJG1KDl3UGUGPux1AGljYGSNsg=; b=jcypr+mf3BQezLkP5dGsWZaWlVS9U8nAggx+nccacCSX3WnGEARNgscu8Sa6eDFUBZ 2ysH34vyEbdx5Wcp1JZbJuIVbxCoa3RigRWLnBZFAbuD/byOa99f4dyafCWA6qNMLE8S +1xbTB7d5wVuV6RQ7rS9IP7FCw7TA5JlMqmGw571alyYCRvx4EL/e1fgu5+n6hKkelE2 2WKCnVyauu4DQO9x5hfGASv9hyhuImAGcKQ8aB7TXpQEOwIoIi/fPRMHyRE9El1kZMqM IDwoO7MKuDobkhZq/bdhkzYDI/W+nR+717Bds0nxpWCNc4WDfrXIr5i2vvYtZkC4lNt9 DDTw== 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=SL7UNLdugsPghYw05DJG1KDl3UGUGPux1AGljYGSNsg=; b=BSyu6f6DF6f8tu9Bl1xDxuprHFzQscdimPPM6Etx352X/sK/xsmC/Oosg7Pm9aAFtz imY8bKrgmWkXIztK4eY0uxJDVqW5ttH1Hv00AzYwvHyhHRqj0C5pzmzuwPKq6U50mmj9 umZ0e2pdUpfMyjLn/KDaCBLuLUgMaxfzbMLYw5PTVYaA5X800opBcOcBdV+uzUzXsB16 srT3v8x7igWB9t79X/fUzuRChqMT4TI5GwpEDGEu6elrm5ODc7D5jSJL2OA1rhCaY5Wh Jopdoq3MD7Sqhqy0WiLPUg7rb1qwL05yUTcqODVn23sSvs/XtDg7E0S8DgDPA+/4S9Z/ 38Mw== X-Gm-Message-State: APjAAAVk2qLCJSCTWyQrYZZvDEH6ubshBitqzJFLqLIdj5f9/Ck5QbwJ lBl94A9kqy32dGy+KSSzdQqRAM+D X-Google-Smtp-Source: APXvYqza/7mAZjK6kz7EmE7H0Z4Q93rAUfhhfYnrpF3NLJ07XU7Wo0ILq20b1JJiH1XKj9iXm9S4Uw== X-Received: by 2002:a63:3756:: with SMTP id g22mr13499013pgn.375.1575807877034; Sun, 08 Dec 2019 04:24:37 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.34 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:36 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:23:08 +1000 Message-Id: <20191208122312.12837-28-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 27/31] add little endian support X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This adds support for building LE skiboot with LITTLE_ENDIAN=1. This is not complete, notably PHB3, NPU* and *CAPI*, but it is sufficient to build and boot on mambo and OpenPOWER POWER9 systems. LE/ELFv2 is a nicer calling convention, and results in smaller image and less stack usage. It also follows the rest of the Linux/OpenPOWER stack moving to LE. The OPALv3 call interface still requires an ugly transition through BE for compatibility, but that is all handled on the OPAL side. Signed-off-by: Nicholas Piggin --- Makefile.main | 38 ++++++++++++-- asm/head.S | 66 +++++++++++++++++------- core/cpu.c | 24 +++++++-- core/init.c | 1 + doc/stb.rst | 2 +- include/asm-utils.h | 22 ++++++-- include/cpu.h | 3 ++ libpore/p9_cpu_reg_restore_instruction.H | 23 +++++---- 8 files changed, 135 insertions(+), 44 deletions(-) diff --git a/Makefile.main b/Makefile.main index 4d7ebcec9..e26a9ab17 100644 --- a/Makefile.main +++ b/Makefile.main @@ -67,21 +67,35 @@ CPPFLAGS += -I$(SRC)/libfdt -I$(SRC)/libflash -I$(SRC)/libxz -I$(SRC)/libc/inclu CPPFLAGS += -I$(SRC)/libpore CPPFLAGS += -D__SKIBOOT__ -nostdinc CPPFLAGS += -isystem $(shell $(CC) -print-file-name=include) -CPPFLAGS += -DBITS_PER_LONG=64 -DHAVE_BIG_ENDIAN +CPPFLAGS += -DBITS_PER_LONG=64 + # We might want to remove our copy of stdint.h # but that means uint64_t becomes an ulong instead of an ullong # causing all our printf's to warn CPPFLAGS += -ffreestanding +ifeq ($(LITTLE_ENDIAN),1) +CPPFLAGS += -DHAVE_LITTLE_ENDIAN +else +CPPFLAGS += -DHAVE_BIG_ENDIAN +endif + ifeq ($(DEBUG),1) CPPFLAGS += -DDEBUG -DCCAN_LIST_DEBUG endif -CFLAGS := -fno-strict-aliasing -pie -fpie -fno-pic -mbig-endian -m64 -fno-asynchronous-unwind-tables +CFLAGS := -fno-strict-aliasing -pie -fpie -fno-pic -m64 -fno-asynchronous-unwind-tables CFLAGS += -mcpu=power8 CFLAGS += -Wl,--oformat,elf64-powerpc -ggdb CFLAGS += $(call try-cflag,$(CC),-ffixed-r13) CFLAGS += $(call try-cflag,$(CC),-std=gnu11) + +ifeq ($(LITTLE_ENDIAN),1) +CFLAGS += -mlittle-endian +else +CFLAGS += -mbig-endian +endif + ifeq ($(ELF_ABI_v2),1) CFLAGS += $(call try-cflag,$(CC),-mabi=elfv2) else @@ -139,8 +153,8 @@ LDFLAGS := -m64 -static -nostdlib -pie LDFLAGS += -Wl,-pie LDFLAGS += -Wl,-Ttext-segment,$(LD_TEXT) -Wl,-N -Wl,--build-id=none LDFLAGS += -Wl,--no-multi-toc -LDFLAGS += -mcpu=power8 -mbig-endian -Wl,--oformat,elf64-powerpc -LDFLAGS_FINAL = -EB -m elf64ppc --no-multi-toc -N --build-id=none --whole-archive +LDFLAGS += -mcpu=power8 -Wl,--oformat,elf64-powerpc +LDFLAGS_FINAL = -m elf64lppc --no-multi-toc -N --build-id=none --whole-archive LDFLAGS_FINAL += -static -nostdlib -pie -Ttext-segment=$(LD_TEXT) --oformat=elf64-powerpc LDFLAGS_FINAL += --orphan-handling=warn @@ -148,11 +162,25 @@ LDRFLAGS=-melf64ppc # Debug stuff #LDFLAGS += -Wl,-v -Wl,-Map,foomap +ifeq ($(LITTLE_ENDIAN),1) +LDFLAGS += -mlittle-endian +LDFLAGS_FINAL += -EL +else +LDFLAGS += -mbig-endian +LDFLAGS_FINAL += -EB +endif + ifeq ($(DEAD_CODE_ELIMINATION),1) LDFLAGS += -Wl,--gc-sections endif -AFLAGS := -D__ASSEMBLY__ -mbig-endian -m64 +AFLAGS := -D__ASSEMBLY__ -m64 +ifeq ($(LITTLE_ENDIAN),1) +AFLAGS += -mlittle-endian +else +AFLAGS += -mbig-endian +endif + ifeq ($(ELF_ABI_v2),1) AFLAGS += $(call try-cflag,$(CC),-mabi=elfv2) else diff --git a/asm/head.S b/asm/head.S index b38cc870b..b565f6c9c 100644 --- a/asm/head.S +++ b/asm/head.S @@ -43,6 +43,7 @@ __head: . = 0x10 .global fdt_entry fdt_entry: + FIXUP_ENDIAN mr %r27,%r3 b boot_entry @@ -89,6 +90,7 @@ hir_trigger: . = 0x100 sreset_vector: /* BML entry, load up r3 with device tree location */ + FIXUP_ENDIAN li %r3, 0 oris %r3, %r3, 0xa b fdt_entry /* hack for lab boot */ @@ -96,6 +98,7 @@ sreset_vector: /* Entry point set by the FSP */ .= 0x180 hdat_entry: + FIXUP_ENDIAN li %r27,0 b boot_entry @@ -364,7 +367,11 @@ boot_entry: add %r2,%r2,%r29 /* Fixup our MSR (remove TA) */ +#if HAVE_BIG_ENDIAN LOAD_IMM64(%r3, (MSR_HV | MSR_SF)) +#else + LOAD_IMM64(%r3, (MSR_HV | MSR_SF | MSR_LE)) +#endif mtmsrd %r3,0 /* Check our PIR, avoid threads */ @@ -702,14 +709,18 @@ init_shared_sprs: mtspr SPR_TSCR, %r3 /* HID0: Clear bit 13 (enable core recovery) - * Clear bit 19 (HILE) + * Set/clear bit 19 (HILE) depending on skiboot endian */ mfspr %r3,SPR_HID0 li %r0,1 sldi %r4,%r0,(63-13) - sldi %r5,%r0,(63-19) - or %r0,%r4,%r5 - andc %r3,%r3,%r0 + andc %r3,%r3,%r4 + sldi %r4,%r0,(63-19) +#if HAVE_BIG_ENDIAN + andc %r3,%r3,%r4 +#else + or %r3,%r3,%r4 +#endif sync mtspr SPR_HID0,%r3 mfspr %r3,SPR_HID0 @@ -736,17 +747,21 @@ init_shared_sprs: LOAD_IMM32(%r3,0x80287880) mtspr SPR_TSCR, %r3 /* HID0: Clear bit 5 (enable core recovery) - * Clear bit 4 (HILE) + * Set/clear bit 4 (HILE) depending on skiboot endian * Set bit 8 (radix) */ mfspr %r3,SPR_HID0 li %r0,1 - sldi %r4,%r0,(63-8) + sldi %r4,%r0,(63-4) +#if HAVE_BIG_ENDIAN + andc %r3,%r3,%r4 +#else or %r3,%r3,%r4 +#endif sldi %r4,%r0,(63-5) - sldi %r5,%r0,(63-4) - or %r0,%r4,%r5 - andc %r3,%r3,%r0 + andc %r3,%r3,%r4 + sldi %r4,%r0,(63-8) + or %r3,%r3,%r4 sync mtspr SPR_HID0,%r3 isync @@ -826,6 +841,8 @@ enter_nap: .balign 0x10 .global opal_entry opal_entry: + OPAL_ENTRY_TO_SKIBOOT_ENDIAN + /* Get our per CPU pointer in r12 to check for quiesce */ mfspr %r12,SPR_PIR GET_STACK(%r12,%r12) @@ -971,20 +988,33 @@ opal_entry: lwz %r11,CPUTHREAD_IN_OPAL_CALL(%r12) subi %r11,%r11,1 stw %r11,CPUTHREAD_IN_OPAL_CALL(%r12) +#if HAVE_BIG_ENDIAN /* * blr with BH=01b means it's not a function return, OPAL was entered * via (h)rfid not bl, so we don't have a corresponding link stack * prediction to return to here. */ bclr 20,0,1 +#else + mflr %r12 + mtspr SPR_HSRR0,%r12 + mfmsr %r11 + li %r12,MSR_LE + andc %r11,%r11,%r12 + mtspr SPR_HSRR1,%r11 + hrfid +#endif .global start_kernel start_kernel: + LOAD_IMM64(%r10,MSR_HV|MSR_SF) +__start_kernel: sync icbi 0,%r3 sync isync - mtctr %r3 + mtspr SPR_HSRR0,%r3 + mtspr SPR_HSRR1,%r10 mr %r3,%r4 LOAD_IMM64(%r8,SKIBOOT_BASE); LOAD_IMM32(%r10, opal_entry - __head) @@ -993,21 +1023,19 @@ start_kernel: addi %r7,%r5,1 li %r4,0 li %r5,0 - bctr + hrfid .global start_kernel32 start_kernel32: - mfmsr %r10 - clrldi %r10,%r10,1 - mtmsrd %r10,0 - sync - isync - b start_kernel + LOAD_IMM64(%r10,MSR_HV) + b __start_kernel .global start_kernel_secondary start_kernel_secondary: sync isync - mtctr %r3 + LOAD_IMM64(%r10,MSR_HV|MSR_SF) + mtspr SPR_HSRR0,%r3 + mtspr SPR_HSRR1,%r10 mfspr %r3,SPR_PIR - bctr + hrfid diff --git a/core/cpu.c b/core/cpu.c index 370bf4b03..d5b7d623b 100644 --- a/core/cpu.c +++ b/core/cpu.c @@ -42,7 +42,7 @@ static unsigned long hid0_attn; static bool sreset_enabled; static bool ipi_enabled; static bool pm_enabled; -static bool current_hile_mode; +static bool current_hile_mode = HAVE_LITTLE_ENDIAN; static bool current_radix_mode = true; static bool tm_suspend_enabled; @@ -1415,6 +1415,24 @@ static int64_t cpu_change_all_hid0(struct hid0_change_req *req) return OPAL_SUCCESS; } +void cpu_set_hile_mode(bool hile) +{ + struct hid0_change_req req; + + if (hile == current_hile_mode) + return; + + if (hile) { + req.clr_bits = 0; + req.set_bits = hid0_hile; + } else { + req.clr_bits = hid0_hile; + req.set_bits = 0; + } + cpu_change_all_hid0(&req); + current_hile_mode = hile; +} + static void cpu_cleanup_one(void *param __unused) { mtspr(SPR_AMR, 0); @@ -1453,8 +1471,8 @@ static int64_t cpu_cleanup_all(void) void cpu_fast_reboot_complete(void) { - /* Fast reboot will have cleared HID0:HILE */ - current_hile_mode = false; + /* Fast reboot will have set HID0:HILE to skiboot endian */ + current_hile_mode = HAVE_LITTLE_ENDIAN; /* and set HID0:RADIX */ current_radix_mode = true; diff --git a/core/init.c b/core/init.c index b7bf2e50c..16f4a4f53 100644 --- a/core/init.c +++ b/core/init.c @@ -632,6 +632,7 @@ void __noreturn load_and_boot_kernel(bool is_reboot) cpu_disable_ME_RI_all(); patch_traps(false); + cpu_set_hile_mode(false); /* Clear HILE on all CPUs */ checksum_romem(); diff --git a/doc/stb.rst b/doc/stb.rst index 6fc8f73da..84855ca55 100644 --- a/doc/stb.rst +++ b/doc/stb.rst @@ -92,7 +92,7 @@ CVC-verify Service .. code-block:: c int call_cvc_verify(void *buf, size_t size, const void *hw_key_hash, - size_t hw_key_hash_size, uint64_t *log) + size_t hw_key_hash_size, __be64 *log) This function wrapper calls into the *CVC-verify*, which verifies if the firmware code provided in ``@buf`` is properly signed with the keys trusted by diff --git a/include/asm-utils.h b/include/asm-utils.h index 2d26545e7..c3d8c09ea 100644 --- a/include/asm-utils.h +++ b/include/asm-utils.h @@ -28,17 +28,29 @@ /* Load an address via the TOC */ #define LOAD_ADDR_FROM_TOC(r, e) ld r,e@got(%r2) -#define FIXUP_ENDIAN \ - tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \ - b 191f; /* Skip trampoline if endian is good */ \ +/* This must preserve LR, so can't use Linux kernel's FIXUP_ENDIAN */ +#define SWITCH_ENDIAN \ .long 0xa600607d; /* mfmsr r11 */ \ .long 0x01006b69; /* xori r11,r11,1 */ \ + .long 0xa64b7b7d; /* mthsrr1 r11 */ \ + .long 0xa602687d; /* mflr r11 */ \ .long 0x05009f42; /* bcl 20,31,$+4 */ \ .long 0xa602487d; /* mflr r10 */ \ .long 0x14004a39; /* addi r10,r10,20 */ \ .long 0xa64b5a7d; /* mthsrr0 r10 */ \ - .long 0xa64b7b7d; /* mthsrr1 r11 */ \ - .long 0x2402004c; /* hrfid */ \ + .long 0xa603687d; /* mtlr r11 */ \ + .long 0x2402004c /* hrfid */ + +#define FIXUP_ENDIAN \ + tdi 0,0,0x48; /* Reverse endian of b . + 8 */ \ + b 191f; /* Skip trampoline if endian is good */ \ + SWITCH_ENDIAN; /* Do the switch */ \ 191: +#if HAVE_BIG_ENDIAN +#define OPAL_ENTRY_TO_SKIBOOT_ENDIAN +#else +#define OPAL_ENTRY_TO_SKIBOOT_ENDIAN SWITCH_ENDIAN +#endif + #endif /* __ASM_UTILS_H */ diff --git a/include/cpu.h b/include/cpu.h index 7b1c1bcf3..686310d71 100644 --- a/include/cpu.h +++ b/include/cpu.h @@ -282,6 +282,9 @@ extern void cpu_process_local_jobs(void); /* Check if there's any job pending */ bool cpu_check_jobs(struct cpu_thread *cpu); +/* Set/clear HILE on all CPUs */ +void cpu_set_hile_mode(bool hile); + /* OPAL sreset vector in place at 0x100 */ void cpu_set_sreset_enable(bool sreset_enabled); diff --git a/libpore/p9_cpu_reg_restore_instruction.H b/libpore/p9_cpu_reg_restore_instruction.H index dd4358a82..cf00ff5e5 100644 --- a/libpore/p9_cpu_reg_restore_instruction.H +++ b/libpore/p9_cpu_reg_restore_instruction.H @@ -61,23 +61,24 @@ enum RLDICR_CONST = 1, MTSPR_CONST1 = 467, MTMSRD_CONST1 = 178, - MR_R0_TO_R10 = 0x7c0a0378, //mr r10, r0 - MR_R0_TO_R21 = 0x7c150378, //mr r21, r0 - MR_R0_TO_R9 = 0x7c090378, //mr r9, r0 - URMOR_CORRECTION = 0x7d397ba6, MFSPR_CONST = 339, - BLR_INST = 0x4e800020, - MTSPR_BASE_OPCODE = 0x7c0003a6, - ATTN_OPCODE = 0x00000200, OPCODE_18 = 18, SELF_SAVE_FUNC_ADD = 0x2300, SELF_SAVE_OFFSET = 0x180, - SKIP_SPR_REST_INST = 0x4800001c, //b . +0x01c - MFLR_R30 = 0x7fc802a6, - SKIP_SPR_SELF_SAVE = 0x3bff0020, //addi r31 r31, 0x20 - MTLR_INST = 0x7fc803a6 //mtlr r30 }; +#define MR_R0_TO_R10 0x7c0a0378UL //mr r10 r0 +#define MR_R0_TO_R21 0x7c150378UL //mr r21 r0 +#define MR_R0_TO_R9 0x7c090378UL //mr r9 r0 +#define URMOR_CORRECTION 0x7d397ba6UL +#define BLR_INST 0x4e800020UL +#define MTSPR_BASE_OPCODE 0x7c0003a6UL +#define ATTN_OPCODE 0x00000200UL +#define SKIP_SPR_REST_INST 0x4800001cUL //b . +0x01c +#define MFLR_R30 0x7fc802a6UL +#define SKIP_SPR_SELF_SAVE 0x3bff0020UL //addi r31 r31 0x20 +#define MTLR_INST 0x7fc803a6UL //mtlr r30 + #ifdef __cplusplus } // namespace stopImageSection ends From patchwork Sun Dec 8 12:23:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205650 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5Qm5bPWz9sPL for ; Sun, 8 Dec 2019 23:36:00 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DCd2TWLZ"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5Qm2mlDzDqFt for ; Sun, 8 Dec 2019 23:36:00 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::443; helo=mail-pf1-x443.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="DCd2TWLZ"; dkim-atps=neutral Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W59j4bcQzDqPQ for ; Sun, 8 Dec 2019 23:24:41 +1100 (AEDT) Received: by mail-pf1-x443.google.com with SMTP id y14so5734209pfm.13 for ; Sun, 08 Dec 2019 04:24:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=X3rhcmNYXSZv2QHqpy039KHr5Qk8ytMJ3/cfnz8AdMc=; b=DCd2TWLZtukrpvI35UvEigWd0tc7xLlLtHysAdFrX6nI5Rbvbo/9+HDLNo4s52C9Jk 94yGralY8Swk8RDOdGOZF3BR+w8JaFCphHmW+xbcj7sDivEDw0P6YH5JM4rqQP6+K8bX nQtUClrC1ocqf2a58tAs1gFhtCp4e9qJ8ogFDdy68hRBWxFjEHVIGpXsAiladzKRIEWa 9fy3xm1NJB1vbgyJ8RZaVCZTlLg+HpoO0j83PJs9GK5pmf4DHoF99azaHGdaQx+WqdyX UCeDmplhBUwvWm8nG6gqPl6865YJ/3Etsj9I8IVyKMiKkO9gxNvqDwQr0E/AgZWTPQL3 A7iQ== 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=X3rhcmNYXSZv2QHqpy039KHr5Qk8ytMJ3/cfnz8AdMc=; b=FhFq3kj2wqaOcCac73slkf5F7Wq81lvOIYUmPh03XsBK6b3lYtxYCqn0KlT1cIkfO2 0MeYxm+b29Lawc4eoij0pVIJwSA4h+u2cVhLC1xZVmwEdbmbunw4g+DlxBdzIPwR26wd SUgI0trsdcr1J76KbEajGTYG2vfvlkHudLvwionaIRFhtWSyDtNvZWjjUODA/3UX6VVZ t1eOpKjj3DNG3KaVVNdjCP/pmWo+JArYGLbr00/FoUAdlISaAZLy+gC28F1twrjuHgPu uZmhWTt6ncsXlXCzldXNZNAy5h6AX0QM3Hk3Se8Nzjm5vT65fif12G9dV/5xrX43dV3G P/YQ== X-Gm-Message-State: APjAAAWRk0tuwHh8A08BwQCNfeT/utyCeUntwAnaZSvbq/aNROATHWom 1gIlJ9y/FSPveQq9/D3MjzoRb5c4 X-Google-Smtp-Source: APXvYqxNBbWZCr1LNC5zBHC0HRLdIRVMu7UNAFuBN2lYsbQ9cx+vseEzXEY9sIPFMOdcjB5V1cTjdQ== X-Received: by 2002:aa7:85d3:: with SMTP id z19mr24574419pfn.62.1575807879666; Sun, 08 Dec 2019 04:24:39 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:39 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:23:09 +1000 Message-Id: <20191208122312.12837-29-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 28/31] dt: assorted cleanups X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This replaces several instances dt accesses with higher level primitives throughout the tree. Signed-off-by: Nicholas Piggin --- core/device.c | 9 ++++++++- core/pci.c | 20 ++++++++------------ hdata/iohub.c | 21 +++++++-------------- hdata/memory.c | 7 ++----- hw/fsp/fsp.c | 2 +- hw/phb4.c | 28 ++++++++++++---------------- include/device.h | 1 + 7 files changed, 39 insertions(+), 49 deletions(-) diff --git a/core/device.c b/core/device.c index 0118d485f..f48a80159 100644 --- a/core/device.c +++ b/core/device.c @@ -593,11 +593,18 @@ u32 dt_property_get_cell(const struct dt_property *prop, u32 index) return fdt32_to_cpu(((const u32 *)prop->prop)[index]); } +u64 dt_property_get_u64(const struct dt_property *prop, u32 index) +{ + assert(prop->len >= (index+1)*sizeof(u64)); + /* Always aligned, so this works. */ + return fdt64_to_cpu(((const fdt64_t *)prop->prop)[index]); +} + void dt_property_set_cell(struct dt_property *prop, u32 index, u32 val) { assert(prop->len >= (index+1)*sizeof(u32)); /* Always aligned, so this works. */ - ((u32 *)prop->prop)[index] = cpu_to_fdt32(val); + ((fdt32_t *)prop->prop)[index] = cpu_to_fdt32(val); } /* First child of this node. */ diff --git a/core/pci.c b/core/pci.c index e497fd50c..f23ba1873 100644 --- a/core/pci.c +++ b/core/pci.c @@ -1524,16 +1524,8 @@ static void __noinline pci_add_one_device_node(struct phb *phb, char name[MAX_NAME]; char compat[MAX_NAME]; uint32_t rev_class; - __be32 reg[5]; uint8_t intpin; bool is_pcie; - const __be32 ranges_direct[] = { - /* 64-bit direct mapping. We know the bridges - * don't cover the entire address space so - * use 0xf00... as a good compromise. */ - cpu_to_be32(0x02000000), 0x0, 0x0, - cpu_to_be32(0x02000000), 0x0, 0x0, - cpu_to_be32(0xf0000000), 0x0}; pci_cfg_read32(phb, pd->bdfn, PCI_CFG_REV_ID, &rev_class); pci_cfg_read8(phb, pd->bdfn, PCI_CFG_INT_PIN, &intpin); @@ -1609,9 +1601,7 @@ static void __noinline pci_add_one_device_node(struct phb *phb, * entry in the "reg" property. That's enough for Linux and we might * even want to make this legit in future ePAPR */ - reg[0] = cpu_to_be32(pd->bdfn << 8); - reg[1] = reg[2] = reg[3] = reg[4] = 0; - dt_add_property(np, "reg", reg, sizeof(reg)); + dt_add_property_cells(np, "reg", pd->bdfn << 8, 0, 0, 0, 0); /* Print summary info about the device */ pci_print_summary_line(phb, pd, np, rev_class, cname); @@ -1646,7 +1636,13 @@ static void __noinline pci_add_one_device_node(struct phb *phb, * (ie. an empty ranges property). * Instead add a ranges property that explicitly translates 1:1. */ - dt_add_property(np, "ranges", ranges_direct, sizeof(ranges_direct)); + dt_add_property_cells(np, "ranges", + /* 64-bit direct mapping. We know the bridges + * don't cover the entire address space so + * use 0xf00... as a good compromise. */ + 0x02000000, 0x0, 0x0, + 0x02000000, 0x0, 0x0, + 0xf0000000, 0x0); } void __noinline pci_add_device_nodes(struct phb *phb, diff --git a/hdata/iohub.c b/hdata/iohub.c index 6647e6aac..35f4a74c9 100644 --- a/hdata/iohub.c +++ b/hdata/iohub.c @@ -95,7 +95,6 @@ static struct dt_node *io_add_phb3(const struct cechub_io_hub *hub, unsigned int spci_xscom) { struct dt_node *pbcq; - uint32_t reg[6]; unsigned int hdif_vers; /* Get HDIF version */ @@ -109,13 +108,10 @@ static struct dt_node *io_add_phb3(const struct cechub_io_hub *hub, /* "reg" property contains in order the PE, PCI and SPCI XSCOM * addresses */ - reg[0] = cpu_to_be32(pe_xscom); - reg[1] = cpu_to_be32(0x20); - reg[2] = cpu_to_be32(pci_xscom); - reg[3] = cpu_to_be32(0x05); - reg[4] = cpu_to_be32(spci_xscom); - reg[5] = cpu_to_be32(0x15); - dt_add_property(pbcq, "reg", reg, sizeof(reg)); + dt_add_property_cells(pbcq, "reg", + pe_xscom, 0x20, + pci_xscom, 0x05, + spci_xscom, 0x15); /* A couple more things ... */ dt_add_property_strings(pbcq, "compatible", "ibm,power8-pbcq"); @@ -202,7 +198,6 @@ static struct dt_node *io_add_phb4(const struct cechub_io_hub *hub, int phb_base) { struct dt_node *pbcq; - uint32_t reg[4]; uint8_t active_phb_mask = hub->fab_br0_pdt; uint32_t pe_xscom = 0x4010c00 + (pec_index * 0x0000400); uint32_t pci_xscom = 0xd010800 + (pec_index * 0x1000000); @@ -214,11 +209,9 @@ static struct dt_node *io_add_phb4(const struct cechub_io_hub *hub, return NULL; /* "reg" property contains (in order) the PE and PCI XSCOM addresses */ - reg[0] = cpu_to_be32(pe_xscom); - reg[1] = cpu_to_be32(0x100); - reg[2] = cpu_to_be32(pci_xscom); - reg[3] = cpu_to_be32(0x200); - dt_add_property(pbcq, "reg", reg, sizeof(reg)); + dt_add_property_cells(pbcq, "reg", + pe_xscom, 0x100, + pci_xscom, 0x200); /* The hubs themselves go under the stacks */ dt_add_property_strings(pbcq, "compatible", "ibm,power9-pbcq"); diff --git a/hdata/memory.c b/hdata/memory.c index 9e5e99b9c..7839dea3f 100644 --- a/hdata/memory.c +++ b/hdata/memory.c @@ -77,24 +77,21 @@ static void append_chip_id(struct dt_node *mem, u32 id) { struct dt_property *prop; size_t len, i; - be32 *p; prop = __dt_find_property(mem, "ibm,chip-id"); if (!prop) return; len = prop->len >> 2; - p = (be32*)prop->prop; /* Check if it exists already */ for (i = 0; i < len; i++) { - if (be32_to_cpu(p[i]) == id) + if (dt_property_get_cell(prop, i) == id) return; } /* Add it to the list */ dt_resize_property(&prop, (len + 1) << 2); - p = (be32 *)prop->prop; - p[len] = cpu_to_be32(id); + dt_property_set_cell(prop, len, id); } static void update_status(struct dt_node *mem, uint32_t status) diff --git a/hw/fsp/fsp.c b/hw/fsp/fsp.c index 1112fb74b..7592ee07b 100644 --- a/hw/fsp/fsp.c +++ b/hw/fsp/fsp.c @@ -1912,7 +1912,7 @@ static void fsp_init_links(struct dt_node *fsp_node) u64 reg; u32 link; - link = be32_to_cpu(((const __be32 *)linksprop->prop)[i]); + link = dt_property_get_cell(linksprop, i); fiop = &fsp->iopath[i]; fiop->psi = psi_find_link(link); if (fiop->psi == NULL) { diff --git a/hw/phb4.c b/hw/phb4.c index 9f7bcd4ca..ed7f4e5c4 100644 --- a/hw/phb4.c +++ b/hw/phb4.c @@ -5544,11 +5544,11 @@ static bool phb4_calculate_windows(struct phb4 *p) "ibm,mmio-windows", -1); assert(prop->len >= (2 * sizeof(uint64_t))); - p->mm0_base = be64_to_cpu(((__be64 *)prop->prop)[0]); - p->mm0_size = be64_to_cpu(((__be64 *)prop->prop)[1]); + p->mm0_base = dt_property_get_u64(prop, 0); + p->mm0_size = dt_property_get_u64(prop, 1); if (prop->len > 16) { - p->mm1_base = be64_to_cpu(((__be64 *)prop->prop)[2]); - p->mm1_size = be64_to_cpu(((__be64 *)prop->prop)[3]); + p->mm1_base = dt_property_get_u64(prop, 2); + p->mm1_size = dt_property_get_u64(prop, 3); } /* Sort them so that 0 is big and 1 is small */ @@ -5660,11 +5660,11 @@ static void phb4_create(struct dt_node *np) /* Get the various XSCOM register bases from the device-tree */ prop = dt_require_property(np, "ibm,xscom-bases", 5 * sizeof(uint32_t)); - p->pe_xscom = be32_to_cpu(((__be32 *)prop->prop)[0]); - p->pe_stk_xscom = be32_to_cpu(((__be32 *)prop->prop)[1]); - p->pci_xscom = be32_to_cpu(((__be32 *)prop->prop)[2]); - p->pci_stk_xscom = be32_to_cpu(((__be32 *)prop->prop)[3]); - p->etu_xscom = be32_to_cpu(((__be32 *)prop->prop)[4]); + p->pe_xscom = dt_property_get_cell(prop, 0); + p->pe_stk_xscom = dt_property_get_cell(prop, 1); + p->pci_xscom = dt_property_get_cell(prop, 2); + p->pci_stk_xscom = dt_property_get_cell(prop, 3); + p->etu_xscom = dt_property_get_cell(prop, 4); /* * We skip the initial PERST assertion requested by the generic code @@ -5825,7 +5825,6 @@ static void phb4_probe_stack(struct dt_node *stk_node, uint32_t pec_index, uint64_t val, phb_bar = 0, irq_bar = 0, bar_en; uint64_t mmio0_bar = 0, mmio0_bmask, mmio0_sz; uint64_t mmio1_bar = 0, mmio1_bmask, mmio1_sz; - uint64_t reg[4]; void *foo; __be64 mmio_win[4]; unsigned int mmio_win_sz; @@ -5923,18 +5922,15 @@ static void phb4_probe_stack(struct dt_node *stk_node, uint32_t pec_index, prlog_once(PR_DEBUG, "Version reg: 0x%016llx\n", in_be64(foo)); /* Create PHB node */ - reg[0] = cpu_to_be64(phb_bar); - reg[1] = cpu_to_be64(0x1000); - reg[2] = cpu_to_be64(irq_bar); - reg[3] = cpu_to_be64(0x10000000); - np = dt_new_addr(dt_root, "pciex", phb_bar); if (!np) return; dt_add_property_strings(np, "compatible", "ibm,power9-pciex", "ibm,ioda3-phb"); dt_add_property_strings(np, "device_type", "pciex"); - dt_add_property(np, "reg", reg, sizeof(reg)); + dt_add_property_u64s(np, "reg", + phb_bar, 0x1000, + irq_bar, 0x10000000); /* Everything else is handled later by skiboot, we just * stick a few hints here diff --git a/include/device.h b/include/device.h index 25325ec07..4f7a0983f 100644 --- a/include/device.h +++ b/include/device.h @@ -130,6 +130,7 @@ void dt_resize_property(struct dt_property **prop, size_t len); void dt_property_set_cell(struct dt_property *prop, u32 index, u32 val); u32 dt_property_get_cell(const struct dt_property *prop, u32 index); +u64 dt_property_get_u64(const struct dt_property *prop, u32 index); /* First child of this node. */ struct dt_node *dt_first(const struct dt_node *root); From patchwork Sun Dec 8 12:23:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205651 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5R81zPxz9sP3 for ; Sun, 8 Dec 2019 23:36:20 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="t62S0N2F"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5R80qCDzDqHr for ; Sun, 8 Dec 2019 23:36:20 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::642; helo=mail-pl1-x642.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="t62S0N2F"; dkim-atps=neutral Received: from mail-pl1-x642.google.com (mail-pl1-x642.google.com [IPv6:2607:f8b0:4864:20::642]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W59m34BgzDqNw for ; Sun, 8 Dec 2019 23:24:44 +1100 (AEDT) Received: by mail-pl1-x642.google.com with SMTP id o9so4614197plk.6 for ; Sun, 08 Dec 2019 04:24:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Iwriz47YfU03NVN/ZrmdQUj57/rf85YRXS8pidEUkGI=; b=t62S0N2FZ2hDWTGGEVfhOPp/UZLIN+XMneRlyyAOl9OaLXCURxobPeo0NOAIRu0LHo tuzNuHqDAZmfStnIbPoJbo6pkgdUiiup6/BmJfEexKUd+5oLpsTb6ciPjMVzbEgSvOw0 vFACCpTXUOQF82G6N1UROXJHZVqogZvwyQHKQKgNoKrGxZ8YWgFWD1+Q6n3uYGPNaSSD jeCb2e9/jv9bTHqGvI/PxRC/72CRBtCZ4rn0s51LfG28wxaykrsIHxHslS2nIaQoN3l7 8La1pJl5G+i218EiMeJPk8XrxhTgx1Z47O5Sm7rRgvGzgsai0tb/otg5byLU4StKs3Pu zZxQ== 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=Iwriz47YfU03NVN/ZrmdQUj57/rf85YRXS8pidEUkGI=; b=IhmAGonKa7ZWJlKbNosdZ/fcfANRhNzhF1KUnoEZE6fZ6jolqGRJgLfrSg3zUHa/31 rTmoAz2ws1N44pISIgXeDVENuV9D9BPR+4F4DoExtfRW7jUruzLvYly4q6hp+zMex6ng piKAynQq/nn+fdnaLLDowNNGT3Y7X5jarrntnzLKCzXLNuAf5WsscNCyZHY0mcvONw6P kWo++rIHvyGFeDstiYa/eD4aJygH/z5b9ZBuLDP9Ccsvue7QedJoPqGB50doItbd28To ONGhQ2U8tuKL2zDGW8Sy6LCmTOl5pPbRQvda/Gcn2wSxa2KI/IM/Mn3FZCMX9J0w663X XQJg== X-Gm-Message-State: APjAAAW5fuiOt//phwNZGxq7CujAGICcQ1pjWSRpydh4N3Ms/I+GAkER 02piMx6SEljEnjQ+ZqhzIhKFTlwq X-Google-Smtp-Source: APXvYqyxzKav6PUZ6Jr6Pag4r6LETZ9PKwgv/x7GK3xFdBwbib+vqr8AnlgdCq5GJ0O3LIyjgf7oJw== X-Received: by 2002:a17:90a:3aaf:: with SMTP id b44mr27422638pjc.9.1575807882089; Sun, 08 Dec 2019 04:24:42 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:41 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:23:10 +1000 Message-Id: <20191208122312.12837-30-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 29/31] add more sparse endian annotations X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" This fixes quite a few sparse endian annotations across the tree. Signed-off-by: Nicholas Piggin --- core/device.c | 17 +++++++++-------- core/fdt.c | 2 +- core/interrupts.c | 3 ++- core/mem_region.c | 2 +- core/pci.c | 2 +- core/trace.c | 3 ++- hdata/fsp.c | 2 +- hdata/memory.c | 8 ++++---- hdata/spira.c | 2 +- hw/ast-bmc/ast-sf-ctrl.c | 5 +++-- hw/imc.c | 4 ++-- hw/psi.c | 2 +- hw/slw.c | 10 +++++----- include/ipmi.h | 2 +- include/opal-internal.h | 4 ++-- libflash/mbox-flash.c | 8 ++++---- libstb/secureboot.c | 2 +- platforms/astbmc/vesnin.c | 8 ++++---- 18 files changed, 45 insertions(+), 41 deletions(-) diff --git a/core/device.c b/core/device.c index f48a80159..6c7794677 100644 --- a/core/device.c +++ b/core/device.c @@ -514,12 +514,12 @@ struct dt_property *__dt_add_property_cells(struct dt_node *node, int count, ...) { struct dt_property *p; - u32 *val; + fdt32_t *val; unsigned int i; va_list args; p = new_property(node, name, count * sizeof(u32)); - val = (u32 *)p->prop; + val = (fdt32_t *)p->prop; va_start(args, count); for (i = 0; i < count; i++) val[i] = cpu_to_fdt32(va_arg(args, u32)); @@ -532,12 +532,12 @@ struct dt_property *__dt_add_property_u64s(struct dt_node *node, int count, ...) { struct dt_property *p; - u64 *val; + fdt64_t *val; unsigned int i; va_list args; p = new_property(node, name, count * sizeof(u64)); - val = (u64 *)p->prop; + val = (fdt64_t *)p->prop; va_start(args, count); for (i = 0; i < count; i++) val[i] = cpu_to_fdt64(va_arg(args, u64)); @@ -590,7 +590,7 @@ u32 dt_property_get_cell(const struct dt_property *prop, u32 index) { assert(prop->len >= (index+1)*sizeof(u32)); /* Always aligned, so this works. */ - return fdt32_to_cpu(((const u32 *)prop->prop)[index]); + return fdt32_to_cpu(((const fdt32_t *)prop->prop)[index]); } u64 dt_property_get_u64(const struct dt_property *prop, u32 index) @@ -918,7 +918,7 @@ void dt_expand(const void *fdt) u64 dt_get_number(const void *pdata, unsigned int cells) { - const u32 *p = pdata; + const __be32 *p = pdata; u64 ret = 0; while(cells--) @@ -1095,6 +1095,7 @@ void dt_adjust_subtree_phandle(struct dt_node *dev, struct dt_node *node; struct dt_property *prop; u32 phandle, max_phandle = 0, import_phandle = new_phandle(); + __be32 p; const char **name; dt_for_each_node(dev, node) { @@ -1117,8 +1118,8 @@ void dt_adjust_subtree_phandle(struct dt_node *dev, continue; phandle = dt_prop_get_u32(node, *name); phandle += import_phandle; - phandle = cpu_to_be32(phandle); - memcpy((char *)&prop->prop, &phandle, prop->len); + p = cpu_to_be32(phandle); + memcpy((char *)&prop->prop, &p, prop->len); } } diff --git a/core/fdt.c b/core/fdt.c index e093e8b54..92fdc5b03 100644 --- a/core/fdt.c +++ b/core/fdt.c @@ -136,7 +136,7 @@ static void flatten_dt_node(void *fdt, const struct dt_node *root, static void create_dtb_reservemap(void *fdt, const struct dt_node *root) { uint64_t base, size; - const uint64_t *ranges; + const __be64 *ranges; const struct dt_property *prop; int i; diff --git a/core/interrupts.c b/core/interrupts.c index d4a2c3124..681483209 100644 --- a/core/interrupts.c +++ b/core/interrupts.c @@ -194,7 +194,8 @@ void add_opal_interrupts(void) { struct irq_source *is; unsigned int i, ns, tns = 0, count = 0; - uint32_t *irqs = NULL, isn; + uint32_t isn; + __be32 *irqs = NULL; char *names = NULL; lock(&irq_lock); diff --git a/core/mem_region.c b/core/mem_region.c index 1bb87805c..eb48a1a11 100644 --- a/core/mem_region.c +++ b/core/mem_region.c @@ -1444,7 +1444,7 @@ void mem_region_add_dt_reserved(void) struct mem_region *region; void *names, *ranges; struct dt_node *node; - uint64_t *range; + fdt64_t *range; char *name; names_len = 0; diff --git a/core/pci.c b/core/pci.c index f23ba1873..4ac9346f1 100644 --- a/core/pci.c +++ b/core/pci.c @@ -1310,7 +1310,7 @@ void pci_std_swizzle_irq_map(struct dt_node *np, struct pci_lsi_state *lstate, uint8_t swizzle) { - uint32_t *map, *p; + __be32 *p, *map; int dev, irq, esize, edevcount; size_t map_size; diff --git a/core/trace.c b/core/trace.c index 5c71370fd..00d71cf58 100644 --- a/core/trace.c +++ b/core/trace.c @@ -160,7 +160,8 @@ static void trace_add_dt_props(void) uint64_t boot_buf_phys = (uint64_t) &boot_tracebuf.trace_info; struct dt_node *exports, *traces; unsigned int i; - u64 *prop, tmask; + fdt64_t *prop; + u64 tmask; char tname[256]; exports = dt_find_by_path(opal_node, "firmware/exports"); diff --git a/hdata/fsp.c b/hdata/fsp.c index fe36eef18..d351f5ac5 100644 --- a/hdata/fsp.c +++ b/hdata/fsp.c @@ -174,7 +174,7 @@ static uint32_t fsp_create_link(const struct spss_iopath *iopath, int index, static void fsp_create_links(const void *spss, int index, struct dt_node *fsp_node) { - uint32_t *links = NULL; + __be32 *links = NULL; unsigned int i, lp, lcount = 0; int count; diff --git a/hdata/memory.c b/hdata/memory.c index 7839dea3f..9c588ff61 100644 --- a/hdata/memory.c +++ b/hdata/memory.c @@ -329,8 +329,8 @@ static void vpd_add_ram_area(const struct HDIF_common_hdr *msarea) static void vpd_parse_spd(struct dt_node *dimm, const char *spd, u32 size) { - u16 *vendor; - u32 *sn; + __be16 *vendor; + __be32 *sn; /* SPD is too small */ if (size < 512) { @@ -355,14 +355,14 @@ static void vpd_parse_spd(struct dt_node *dimm, const char *spd, u32 size) dt_add_property_cells(dimm, "product-version", spd[0x15d]); /* Serial number */ - sn = (u32 *)&spd[0x145]; + sn = (__be32 *)&spd[0x145]; dt_add_property_cells(dimm, "serial-number", be32_to_cpu(*sn)); /* Part number */ dt_add_property_nstr(dimm, "part-number", &spd[0x149], 20); /* Module manufacturer ID */ - vendor = (u16 *)&spd[0x140]; + vendor = (__be16 *)&spd[0x140]; dt_add_property_cells(dimm, "manufacturer-id", be16_to_cpu(*vendor)); } diff --git a/hdata/spira.c b/hdata/spira.c index 7e19d3d5c..77c937b10 100644 --- a/hdata/spira.c +++ b/hdata/spira.c @@ -994,7 +994,7 @@ static void opal_dump_add_mpipl_boot(const struct iplparams_iplparams *p) static void add_opal_dump_node(void) { - u64 fw_load_area[4]; + __be64 fw_load_area[4]; struct dt_node *node; opal_node = dt_new_check(dt_root, "ibm,opal"); diff --git a/hw/ast-bmc/ast-sf-ctrl.c b/hw/ast-bmc/ast-sf-ctrl.c index ece847d6b..f1814c4df 100644 --- a/hw/ast-bmc/ast-sf-ctrl.c +++ b/hw/ast-bmc/ast-sf-ctrl.c @@ -169,12 +169,13 @@ static void ast_sf_end_cmd(struct ast_sf_ctrl *ct) static int ast_sf_send_addr(struct ast_sf_ctrl *ct, uint32_t addr) { const void *ap; + beint32_t tmp; /* Layout address MSB first in memory */ - addr = cpu_to_be32(addr); + tmp = cpu_to_be32(addr); /* Send the right amount of bytes */ - ap = (char *)&addr; + ap = (char *)&tmp; if (ct->mode_4b) return ast_copy_to_ahb(ct->flash, ap, 4); diff --git a/hw/imc.c b/hw/imc.c index 16b060d39..36c2cf3a5 100644 --- a/hw/imc.c +++ b/hw/imc.c @@ -448,8 +448,8 @@ void imc_catalog_preload(void) static void imc_dt_update_nest_node(struct dt_node *dev) { struct proc_chip *chip; - uint64_t *base_addr = NULL; - uint32_t *chipids = NULL; + __be64 *base_addr = NULL; + __be32 *chipids = NULL; int i=0, nr_chip = nr_chips(); struct dt_node *node; const struct dt_property *type; diff --git a/hw/psi.c b/hw/psi.c index 30c2a6cbc..eede4e5b4 100644 --- a/hw/psi.c +++ b/hw/psi.c @@ -782,7 +782,7 @@ static void psi_activate_phb(struct psi *psi) static void psi_create_p9_int_map(struct psi *psi, struct dt_node *np) { - uint32_t map[P9_PSI_NUM_IRQS][4]; + __be32 map[P9_PSI_NUM_IRQS][4]; int i; for (i = 0; i < P9_PSI_NUM_IRQS; i++) { diff --git a/hw/slw.c b/hw/slw.c index 566a1128b..2f7619793 100644 --- a/hw/slw.c +++ b/hw/slw.c @@ -725,8 +725,8 @@ void add_cpu_idle_state_properties(void) bool has_stop_inst = false; u8 i; - u64 *pm_ctrl_reg_val_buf; - u64 *pm_ctrl_reg_mask_buf; + fdt64_t *pm_ctrl_reg_val_buf; + fdt64_t *pm_ctrl_reg_mask_buf; u32 supported_states_mask; u32 opal_disabled_states_mask = ~0xEC000000; /* all but stop11 */ const char* nvram_disable_str; @@ -739,9 +739,9 @@ void add_cpu_idle_state_properties(void) /* Buffers to hold idle state properties */ char *name_buf, *alloced_name_buf; - u32 *latency_ns_buf; - u32 *residency_ns_buf; - u32 *flags_buf; + fdt32_t *latency_ns_buf; + fdt32_t *residency_ns_buf; + fdt32_t *flags_buf; prlog(PR_DEBUG, "CPU idle state device tree init\n"); diff --git a/include/ipmi.h b/include/ipmi.h index 4f5134745..50deec01a 100644 --- a/include/ipmi.h +++ b/include/ipmi.h @@ -164,7 +164,7 @@ struct ipmi_msg { }; struct ipmi_backend { - __be64 opal_event_ipmi_recv; + uint64_t opal_event_ipmi_recv; struct ipmi_msg *(*alloc_msg)(size_t, size_t); void (*free_msg)(struct ipmi_msg *); int (*queue_msg)(struct ipmi_msg *); diff --git a/include/opal-internal.h b/include/opal-internal.h index fd2187f09..83bf77084 100644 --- a/include/opal-internal.h +++ b/include/opal-internal.h @@ -49,8 +49,8 @@ extern struct dt_node *opal_node; extern void opal_table_init(void); extern void opal_update_pending_evt(uint64_t evt_mask, uint64_t evt_values); -__be64 opal_dynamic_event_alloc(void); -void opal_dynamic_event_free(__be64 event); +uint64_t opal_dynamic_event_alloc(void); +void opal_dynamic_event_free(uint64_t event); extern void add_opal_node(void); #define opal_register(token, func, nargs) \ diff --git a/libflash/mbox-flash.c b/libflash/mbox-flash.c index 5df020f55..3fd2c057a 100644 --- a/libflash/mbox-flash.c +++ b/libflash/mbox-flash.c @@ -239,23 +239,23 @@ static void msg_put_u8(struct bmc_mbox_msg *msg, int i, uint8_t val) static uint16_t msg_get_u16(struct bmc_mbox_msg *msg, int i) { - return le16_to_cpu(*(uint16_t *)(&msg->args[i])); + return le16_to_cpu(*(__le16 *)(&msg->args[i])); } static void msg_put_u16(struct bmc_mbox_msg *msg, int i, uint16_t val) { - uint16_t tmp = cpu_to_le16(val); + __le16 tmp = cpu_to_le16(val); memcpy(&msg->args[i], &tmp, sizeof(val)); } static uint32_t msg_get_u32(struct bmc_mbox_msg *msg, int i) { - return le32_to_cpu(*(uint32_t *)(&msg->args[i])); + return le32_to_cpu(*(__le32 *)(&msg->args[i])); } static void msg_put_u32(struct bmc_mbox_msg *msg, int i, uint32_t val) { - uint32_t tmp = cpu_to_le32(val); + __le32 tmp = cpu_to_le32(val); memcpy(&msg->args[i], &tmp, sizeof(val)); } diff --git a/libstb/secureboot.c b/libstb/secureboot.c index bfc98f2ae..022e2aa09 100644 --- a/libstb/secureboot.c +++ b/libstb/secureboot.c @@ -163,7 +163,7 @@ void secureboot_init(void) int secureboot_verify(enum resource_id id, void *buf, size_t len) { const char *name; - uint64_t log; + __be64 log; int rc = -1; name = flash_map_resource_name(id); diff --git a/platforms/astbmc/vesnin.c b/platforms/astbmc/vesnin.c index bd412aa8d..b1d909e29 100644 --- a/platforms/astbmc/vesnin.c +++ b/platforms/astbmc/vesnin.c @@ -38,13 +38,13 @@ * All fields have Big Endian byte order. */ struct pciinv_device { - uint16_t domain_num; + beint16_t domain_num; uint8_t bus_num; uint8_t device_num; uint8_t func_num; - uint16_t vendor_id; - uint16_t device_id; - uint32_t class_code; + beint16_t vendor_id; + beint16_t device_id; + beint32_t class_code; uint8_t revision; } __packed; From patchwork Sun Dec 8 12:23:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205652 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [203.11.71.2]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5Rb4Dc9z9sP3 for ; Sun, 8 Dec 2019 23:36:43 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nmdBm/YB"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5Rb2w6PzDqGW for ; Sun, 8 Dec 2019 23:36:43 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::1041; helo=mail-pj1-x1041.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="nmdBm/YB"; dkim-atps=neutral Received: from mail-pj1-x1041.google.com (mail-pj1-x1041.google.com [IPv6:2607:f8b0:4864:20::1041]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W59q21mwzDqFL for ; Sun, 8 Dec 2019 23:24:47 +1100 (AEDT) Received: by mail-pj1-x1041.google.com with SMTP id w23so4661622pjd.2 for ; Sun, 08 Dec 2019 04:24:47 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=tAKNvz0hOOD/DQQrynuRB7d3hNFQQnJHGd31QV0ufGE=; b=nmdBm/YBdgT27KW9SPwJwS7CpCjGW4bLiZC04SWGxpAlUJ6FAw9RctG+bQ+9dob11u 8gRLsJWh8JdXZoRh6Y6hVFosC7KtgynCLNgQov2SwnpYMK7pinBjYVHnOQ6sThHzAT1T dIBEicetYlJDKk3HB2WfQcQzJ6UCDrWB+PAxT4SzFCfu9Gn5FmeS5+LJIhPwiueOJzgh Cjzm6C6Eypt2gtryAnPLUQg1nnI9HmZCppP3sMfJtJ2q0ww2U/nfT1CbkDSjh3Cq65IB 4y23MS/px/2mpEXAZ4JlT9j8DFjI3goXHjPsp3YEcYOSoDyVeKUgbkMvPZkc0CVaoMu4 YJKQ== 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=tAKNvz0hOOD/DQQrynuRB7d3hNFQQnJHGd31QV0ufGE=; b=oFBHlQr7vU7S4HpEncSD52lQasTQH9fgFxxZSoJ6JJaN5ubUKlmGtanEeNvPAP2a7P DA2X23J6CBFBwMayu95O8VyS23X2C5z6FHX8cJsMx7Hu3+3cc5PckdGgzcXZZL+Yoq7t b421qnMV0wuUoosUeASB/P6ndwA9y4F5x0/pvCoJ38K82+Nvmd8LLVFOK+EtaGcMeey2 3BDBQnC8zYtQRQsKbmSEq5Ca2/XI080HInBiOIENPDBcfaE4vMtQYp8CWaHcXHsnVDeO FWXseytscxOYB/flxGgFcHHom5uklflJtnU5QtkraHCqxzdM/YK8o2lqJyZ7Kyx+SCA8 jXnQ== X-Gm-Message-State: APjAAAXPNqesGqmblZ7Olmjn45xDoTEb+9XhbQX0uCwrsOaedMvMq4DU o87hHvKs5aA7HtQBwruDKgjQK2Fd X-Google-Smtp-Source: APXvYqz7IEirfOAnUEKJe3TYRGmHnTEwEidLYAIiKUnpEFRpDEhaMhfoHk7GlHDVA9dPfPxt19QGVQ== X-Received: by 2002:a17:90a:348c:: with SMTP id p12mr26343707pjb.105.1575807884521; Sun, 08 Dec 2019 04:24:44 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.42 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:44 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:23:11 +1000 Message-Id: <20191208122312.12837-31-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 30/31] fix simple sparse warnings X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Should be no real code change, these mostly update type declarations that sparse complains about. Signed-off-by: Nicholas Piggin --- core/init.c | 4 ++-- core/pci.c | 2 +- core/platform.c | 2 +- hdata/tpmrel.c | 2 +- hw/fsp/fsp-dpo.c | 2 +- hw/imc.c | 4 ++-- hw/vas.c | 2 +- include/device.h | 3 ++- include/skiboot.h | 2 +- libc/stdlib/labs.c | 2 +- platforms/astbmc/common.c | 4 ++-- platforms/astbmc/p8dtu.c | 2 +- platforms/astbmc/p9dsu.c | 2 +- platforms/astbmc/witherspoon.c | 6 +++--- 14 files changed, 20 insertions(+), 19 deletions(-) diff --git a/core/init.c b/core/init.c index 16f4a4f53..339462e5d 100644 --- a/core/init.c +++ b/core/init.c @@ -531,7 +531,7 @@ static int64_t cpu_disable_ME_RI_all(void) return OPAL_SUCCESS; } -void *fdt; +static void *fdt; void __noreturn load_and_boot_kernel(bool is_reboot) { @@ -828,7 +828,7 @@ static void setup_branch_null_catcher(void) * ABI v1 (ie. big endian). This will be broken if we ever * move to ABI v2 (ie little endian) */ - memcpy_null(0, bn, 16); + memcpy_null((void *)0, bn, 16); } #endif diff --git a/core/pci.c b/core/pci.c index 4ac9346f1..8b52fc108 100644 --- a/core/pci.c +++ b/core/pci.c @@ -1349,7 +1349,7 @@ void pci_std_swizzle_irq_map(struct dt_node *np, dt_add_property_cells(np, "interrupt-map-mask", 0xf800, 0, 0, 7); } - map_size = esize * edevcount * 4 * sizeof(uint32_t); + map_size = esize * edevcount * 4 * sizeof(u32); map = p = zalloc(map_size); if (!map) { prerror("Failed to allocate interrupt-map-mask !\n"); diff --git a/core/platform.c b/core/platform.c index 9f1873c90..2544f0ccf 100644 --- a/core/platform.c +++ b/core/platform.c @@ -184,7 +184,7 @@ static int generic_start_preload_resource(enum resource_id id, uint32_t subid, } /* These values will work for a ZZ booted using BML */ -const struct platform_ocapi generic_ocapi = { +static const struct platform_ocapi generic_ocapi = { .i2c_engine = 1, .i2c_port = 4, .i2c_reset_addr = 0x20, diff --git a/hdata/tpmrel.c b/hdata/tpmrel.c index 8bfc0f8fc..93a8b485e 100644 --- a/hdata/tpmrel.c +++ b/hdata/tpmrel.c @@ -118,7 +118,7 @@ static struct dt_node *get_hb_reserved_memory(const char *label) return NULL; } -struct { +static struct { uint32_t type; const char *compat; } cvc_services[] = { diff --git a/hw/fsp/fsp-dpo.c b/hw/fsp/fsp-dpo.c index 8f0861ed4..da83a93d8 100644 --- a/hw/fsp/fsp-dpo.c +++ b/hw/fsp/fsp-dpo.c @@ -18,7 +18,7 @@ #define DPO_CMD_SGN_BYTE1 0x20 /* Byte[1] signature */ #define DPO_TIMEOUT 2700 /* 45 minutes in seconds */ -bool fsp_dpo_pending; +static bool fsp_dpo_pending; static unsigned long fsp_dpo_init_tb; /* diff --git a/hw/imc.c b/hw/imc.c index 36c2cf3a5..3a5382c0c 100644 --- a/hw/imc.c +++ b/hw/imc.c @@ -455,8 +455,8 @@ static void imc_dt_update_nest_node(struct dt_node *dev) const struct dt_property *type; /* Add the base_addr and chip-id properties for the nest node */ - base_addr = malloc(sizeof(uint64_t) * nr_chip); - chipids = malloc(sizeof(uint32_t) * nr_chip); + base_addr = malloc(sizeof(u64) * nr_chip); + chipids = malloc(sizeof(u32) * nr_chip); for_each_chip(chip) { base_addr[i] = cpu_to_be64(chip->homer_base); chipids[i] = cpu_to_be32(chip->id); diff --git a/hw/vas.c b/hw/vas.c index b4af31d12..aebfebde9 100644 --- a/hw/vas.c +++ b/hw/vas.c @@ -494,7 +494,7 @@ static int init_vas_inst(struct dt_node *np, bool enable) } -void vas_init() +void vas_init(void) { bool enabled; struct dt_node *np; diff --git a/include/device.h b/include/device.h index 4f7a0983f..f17b089d8 100644 --- a/include/device.h +++ b/include/device.h @@ -118,7 +118,8 @@ struct dt_property *__dt_add_property_u64s(struct dt_node *node, static inline struct dt_property *dt_add_property_u64(struct dt_node *node, const char *name, u64 val) { - return dt_add_property_cells(node, name, (u32)(val >> 32), (u32)val); + return dt_add_property_cells(node, name, (u32)(val >> 32), + (u32)(val & 0xffffffffUL)); } void dt_del_property(struct dt_node *node, struct dt_property *prop); diff --git a/include/skiboot.h b/include/skiboot.h index e9d57decd..6946b8056 100644 --- a/include/skiboot.h +++ b/include/skiboot.h @@ -318,7 +318,7 @@ extern void fake_rtc_init(void); struct stack_frame; extern void exception_entry(struct stack_frame *stack); extern void exception_entry_pm_sreset(void); -extern void exception_entry_pm_mce(void); +extern void __noreturn exception_entry_pm_mce(void); /* Assembly in head.S */ extern void disable_machine_check(void); diff --git a/libc/stdlib/labs.c b/libc/stdlib/labs.c index 9b68bb275..8bd15eab9 100644 --- a/libc/stdlib/labs.c +++ b/libc/stdlib/labs.c @@ -19,7 +19,7 @@ * Returns the absolute value of the long integer argument */ -long int labs(long int n) +long int __attribute__((const)) labs(long int n) { return (n > 0) ? n : -n; } diff --git a/platforms/astbmc/common.c b/platforms/astbmc/common.c index 15ac231fb..de837f326 100644 --- a/platforms/astbmc/common.c +++ b/platforms/astbmc/common.c @@ -503,13 +503,13 @@ void astbmc_exit(void) ipmi_wdt_final_reset(); } -const struct bmc_sw_config bmc_sw_ami = { +static const struct bmc_sw_config bmc_sw_ami = { .ipmi_oem_partial_add_esel = IPMI_CODE(0x3a, 0xf0), .ipmi_oem_pnor_access_status = IPMI_CODE(0x3a, 0x07), .ipmi_oem_hiomap_cmd = IPMI_CODE(0x3a, 0x5a), }; -const struct bmc_sw_config bmc_sw_openbmc = { +static const struct bmc_sw_config bmc_sw_openbmc = { .ipmi_oem_partial_add_esel = IPMI_CODE(0x3a, 0xf0), .ipmi_oem_hiomap_cmd = IPMI_CODE(0x3a, 0x5a), }; diff --git a/platforms/astbmc/p8dtu.c b/platforms/astbmc/p8dtu.c index c62223b24..a9d8dc068 100644 --- a/platforms/astbmc/p8dtu.c +++ b/platforms/astbmc/p8dtu.c @@ -223,7 +223,7 @@ static const struct bmc_sw_config bmc_sw_smc = { }; /* Provided by Eric Chen (SMC) */ -const struct bmc_hw_config p8dtu_bmc_hw = { +static const struct bmc_hw_config p8dtu_bmc_hw = { .scu_revision_id = 0x02010303, .mcr_configuration = 0x00000577, .mcr_scu_mpll = 0x000050c0, diff --git a/platforms/astbmc/p9dsu.c b/platforms/astbmc/p9dsu.c index d49f7fe07..5c9756ec6 100644 --- a/platforms/astbmc/p9dsu.c +++ b/platforms/astbmc/p9dsu.c @@ -695,7 +695,7 @@ static const struct bmc_sw_config bmc_sw_smc = { }; /* Provided by Eric Chen (SMC) */ -const struct bmc_hw_config p9dsu_bmc_hw = { +static const struct bmc_hw_config p9dsu_bmc_hw = { .scu_revision_id = 0x04030303, .mcr_configuration = 0x11000756, .mcr_scu_mpll = 0x000071c1, diff --git a/platforms/astbmc/witherspoon.c b/platforms/astbmc/witherspoon.c index c576a176c..081996684 100644 --- a/platforms/astbmc/witherspoon.c +++ b/platforms/astbmc/witherspoon.c @@ -325,7 +325,7 @@ i2c_failed: return; } -const struct platform_ocapi witherspoon_ocapi = { +static const struct platform_ocapi witherspoon_ocapi = { .i2c_engine = 1, .i2c_port = 4, .odl_phy_swap = false, @@ -370,8 +370,8 @@ static int gpu_slot_to_num(const char *slot) static void npu2_phb_nvlink_dt(struct phb *npuphb) { - struct dt_node *g[3] = { 0 }; /* Current maximum is 3 GPUs per 1 NPU */ - struct dt_node *n[6] = { 0 }; + struct dt_node *g[3] = { NULL }; /* Current maximum 3 GPUs per 1 NPU */ + struct dt_node *n[6] = { NULL }; int max_gpus, i, gpuid, first, last; struct npu2 *npu2_phb = phb_to_npu2_nvlink(npuphb); struct pci_device *npd; From patchwork Sun Dec 8 12:23:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1205653 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (4096 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id 47W5Rv6D1dz9sP3 for ; Sun, 8 Dec 2019 23:36:59 +1100 (AEDT) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Og1sBh1r"; dkim-atps=neutral Received: from lists.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 47W5Rv4xBMzDqPK for ; Sun, 8 Dec 2019 23:36:59 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (sender SPF authorized) smtp.mailfrom=gmail.com (client-ip=2607:f8b0:4864:20::444; helo=mail-pf1-x444.google.com; envelope-from=npiggin@gmail.com; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=gmail.com header.i=@gmail.com header.b="Og1sBh1r"; dkim-atps=neutral Received: from mail-pf1-x444.google.com (mail-pf1-x444.google.com [IPv6:2607:f8b0:4864:20::444]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 47W59s0BmszDqNw for ; Sun, 8 Dec 2019 23:24:49 +1100 (AEDT) Received: by mail-pf1-x444.google.com with SMTP id b19so5762119pfo.2 for ; Sun, 08 Dec 2019 04:24:48 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=bYYFWwdjFxPqPAxTWKSd7a8OHpfh7QVCgjkecWyu9bQ=; b=Og1sBh1rJhY+EpAqOkNz5/ACtUO882sYREb+WF0oBZnn9bZEf52d1BzgxmYqz/DGRO DNy3A01qNtMMimwz62oN7MIipvTghs1D5fHpi1u4RjFeAZ/xFNRag9pr8jKFjURw6e5z WQXY/geZjGD3qRO59dXB0gpsK68KeVtx53MGvPQYwP0MW8MiImrOHRIax6d4YBwE70Dk 3WWsIsVEYM5MhPLgb2u31KPTlHQOdh1O4AghsQ0OwW8/BOya5tzTKERYBL8SEaj8nzdQ XdGpDWX++zDnH2EpGDR5/Fmv8FwcZ2wpzrXi4P6OXAcgxIjt7JKZ+b76XmxyQoUsxG29 jrRQ== 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=bYYFWwdjFxPqPAxTWKSd7a8OHpfh7QVCgjkecWyu9bQ=; b=jPXMnpW/ulpew6EXbPbIbyX0aH6mACg9kNKwoDFY/xAmLq6C5W0HPB9UkF+B0NZUPy eOe3N94+YS3WXXlQPtlFHSX67qzS+QaQPgl0EZu4f2ip8/WmZxWwaxYHtF+LM0L+h9co TM70GidIHvcIz9v7xLJcDcTyBG/jljzaDFE6RJCrK6Y7c10dWWbbssHBRbEGLX9Oxdny wdOUq0y5t9Z0CxyEtj3tRcuOjtpeeZej/Ql9MaRs0NW4TO7Om95ObUTHOk75entKZwCZ g+1V4qoSFNcCXo1MdkQzmU27Fsa7OFi4cMdeqyvSVveIxo2BkjqldQG6koal5GCgOhkt TerA== X-Gm-Message-State: APjAAAVh1va+l9IkAOAlFWEhPPQdYbU3S5q7ycsFIYr6HSM8s6jiPlBk cVWCDzyLy5dBsyhgTp0s4EqdwiMS X-Google-Smtp-Source: APXvYqypAdEPHdDicRL4nPQoPBf5CpotaZ6/eLKBYk2W2iYu0Wc+fTtUTszIkEzAW/2XkegEZVnKlg== X-Received: by 2002:a63:4416:: with SMTP id r22mr13547515pga.254.1575807887015; Sun, 08 Dec 2019 04:24:47 -0800 (PST) Received: from bobo.local0.net ([202.21.15.182]) by smtp.gmail.com with ESMTPSA id i9sm23741866pfk.24.2019.12.08.04.24.44 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sun, 08 Dec 2019 04:24:46 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Sun, 8 Dec 2019 22:23:12 +1000 Message-Id: <20191208122312.12837-32-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191208122312.12837-1-npiggin@gmail.com> References: <20191208122312.12837-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v10 31/31] i2c: fix dereference beyond the end of buffer X-BeenThere: skiboot@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Mailing list for skiboot development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: skiboot-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Skiboot" Print the contents of the buffer as an array of bytes in hex, which avoids endian issues and reading beyond the end of the buffer. Signed-off-by: Nicholas Piggin --- core/i2c.c | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/core/i2c.c b/core/i2c.c index f33028743..9bc32aa23 100644 --- a/core/i2c.c +++ b/core/i2c.c @@ -138,6 +138,8 @@ int64_t i2c_request_sync(struct i2c_request *req) uint64_t timer_period = msecs_to_tb(5), timer_count; uint64_t time_to_wait = 0; int64_t rc, waited, retries; + size_t i, count; + char buf[17]; /* 8 bytes in hex + NUL */ for (retries = 0; retries <= MAX_NACK_RETRIES; retries++) { waited = 0; @@ -175,10 +177,16 @@ int64_t i2c_request_sync(struct i2c_request *req) req->req_state = i2c_req_new; } - prlog(PR_DEBUG, "I2C: %s req op=%x offset=%x buf=%016llx buflen=%d " + count = 0; + for (i = 0; i < req->rw_len && count < sizeof(buf); i++) { + count += snprintf(buf+count, sizeof(buf)-count, "%02x", + *(unsigned char *)(req->rw_buf+i)); + } + + prlog(PR_DEBUG, "I2C: %s req op=%x offset=%x buf=%s buflen=%d " "delay=%lu/%lld rc=%lld\n", (rc) ? "!!!!" : "----", req->op, req->offset, - *(uint64_t*) req->rw_buf, req->rw_len, tb_to_msecs(waited), req->timeout, rc); + buf, req->rw_len, tb_to_msecs(waited), req->timeout, rc); return rc; }