From patchwork Wed Oct 9 23:49: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: 1174212 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 46pWNY2Wzwz9sN1 for ; Thu, 10 Oct 2019 10:57: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="l4Apf3ZR"; dkim-atps=neutral Received: from bilbo.ozlabs.org (lists.ozlabs.org [IPv6:2401:3900:2:1::3]) by lists.ozlabs.org (Postfix) with ESMTP id 46pWNY0tV3zDq9B for ; Thu, 10 Oct 2019 10:57:17 +1100 (AEDT) X-Original-To: skiboot@lists.ozlabs.org Delivered-To: skiboot@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) 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="l4Apf3ZR"; 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 46pWJ34hjFzDqYj for ; Thu, 10 Oct 2019 10:53:23 +1100 (AEDT) Received: by mail-pl1-x641.google.com with SMTP id u12so1820284pls.12 for ; Wed, 09 Oct 2019 16:53:23 -0700 (PDT) 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=AOG503UdfDeTx0lu437omNlIRCX956zjmUF8b0KsQa0=; b=l4Apf3ZRsz3FAslsSgG3N0IozwwgC76XY/toGBWGY0aKdUNpgAbDhKtnlTAezbRQjW 8m3bE/S30McvmVOYEmmOtdFUNVMSNbYsgf1BFDx52y1ULYtL9Q7RThMnlY2aimu55T4z +1lSaMdkaapvG4ZUDU8ATsyVQqL+ys6G+zISTNQtciY2S8w01Qw4+i/iATiynLs42Z1m W92Rd45v2R7Afn9skpP+KkFGpOGyDIxW7hX2DB1UGA39gUNdb2YxS6StuZlosTHnY97P MYEGYQTBafHYSds8rwvBE8WXVpQjyV3Hr6vA0+1FfLKZsZynzahcjzJVCZEhRD7B7zK0 TCUg== 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=AOG503UdfDeTx0lu437omNlIRCX956zjmUF8b0KsQa0=; b=b2sXYCzXGx+gV0is7YnKKkAnxFxzyhYcvVu3WLCDFpJWlGXNG2uElmRxSJ3EblEo85 YRvJFtfH6m2ze0s08tflB5zYBg0xw5KRymoiWv3aYWcLQwWdDj50EN5q8jXzY5QffXMt OzXjU0FdohWUyaFo99k7XaVcdgs6ockxV4e1od2KafZThCbnqmarUxflQa4ZubNpzVsI +o0SMEQk8KFebS0EMViJG25O1dyxgFM+s+BaluSqu5AouGjOVqbeTDt5KO7iX0w3fkYu I64SlcetLoR/nwqpjnwxnAV6vTQBMCu1Xq3wW2iA1Uov//zfPqQrdenAy9qleE9ZnMf9 fAew== X-Gm-Message-State: APjAAAWQFUYDkpG8njvB/sdTa4jfA5ZWQoZIREKjDgkmw701pxSDFXjR AkKHSQ/rQELLJFss9yokDNPJSEiy X-Google-Smtp-Source: APXvYqwWTCpG80NxrY+7gJ0MjcCkC7fKK+nA49kxXgLtvOy3bmWiQY4qlRuU82EBVOOn+jZsOGtF/g== X-Received: by 2002:a17:902:9344:: with SMTP id g4mr5916745plp.158.1570665201186; Wed, 09 Oct 2019 16:53:21 -0700 (PDT) Received: from bobo.ozlabs.ibm.com ([122.99.82.10]) by smtp.gmail.com with ESMTPSA id y144sm4015675pfb.188.2019.10.09.16.53.19 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 09 Oct 2019 16:53:20 -0700 (PDT) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Thu, 10 Oct 2019 09:49:49 +1000 Message-Id: <20191009234951.2850-14-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191009234951.2850-1-npiggin@gmail.com> References: <20191009234951.2850-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v4 13/15] 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 a0339ec25..edb60eb4a 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; /* We only have space in the TCE table for the trace diff --git a/platforms/ibm-fsp/hostservices.c b/platforms/ibm-fsp/hostservices.c index 3bdad4a5e..81008ac2b 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)