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; } }