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)