From patchwork Fri Nov 29 06:18:25 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicholas Piggin X-Patchwork-Id: 1202372 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 47PPjc1g6jz9sR7 for ; Fri, 29 Nov 2019 17:29: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="G8hPct0Q"; 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 47PPjc0TNzzDr85 for ; Fri, 29 Nov 2019 17:29: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::529; helo=mail-pg1-x529.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="G8hPct0Q"; dkim-atps=neutral Received: from mail-pg1-x529.google.com (mail-pg1-x529.google.com [IPv6:2607:f8b0:4864:20::529]) (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 47PPX92kYgzDr7q for ; Fri, 29 Nov 2019 17:20:57 +1100 (AEDT) Received: by mail-pg1-x529.google.com with SMTP id b1so13897707pgq.10 for ; Thu, 28 Nov 2019 22:20:57 -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=XUQzQIPegdqLNs1qt7W6cXTEwenJSbY8ZcTvYN/6Pr4=; b=G8hPct0Q/2BnHs1fQjTZ0j8JIeP2DCPmhk9hoKTx7gHqlAR3gUmMldOexGdGZfG7AE Zhq32Pvlz96hwS8fP4oxscZ45R2RpoWJmZ8Usgo7+y7YotNawazmW7oCdqn9ouF7ahvX JM5Pqu2xgkyfbOwO43P9wSBy1RzWSdtp6wxr+P4mk+fxBQRZ111idhVK43lgezznbmGb w1cSdKJhgcHQ3qW8dNRSdJ2PdOSVSJxNZrATUXnn0iQDxfmvPGeqnuvrEYnHxfEwGT5u YWuEjgWufI6OBQ01d43tXj2ITA+gXSDqOANv2fyq6Cty+HfgUu3QfwtTbYATIlrQ6rf9 SgeA== 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=XUQzQIPegdqLNs1qt7W6cXTEwenJSbY8ZcTvYN/6Pr4=; b=nY5Z1XZi89sggtlCMvmd+C6Bw6vW77VaaYmDWqBAV7/03P01SGIJ9Hf5ScW5wKpEUd zo7n+ipOArwjhym2jzuHCdbhRIj3wwBoOJ3dpc5G2SkWp3dtWQWwcVjZTn9bN+T9RMAk l4+urS9ehk65KbvCnaXU8EUODcZCtxQjEg3+I37wHLQo8BEB6jNT06eS83Sgyn9AkGO4 Qc6ye2KhWQIed6AzD9VEgbaV5FTEDX1P76uu3C5bQCJ1gg8TVfEVLy1P0eLgEl1wp8G/ jDhAinXyA0DeJ/QT+QH6yK1KVhVKejgai0MkfHe0xzP+9MJud34kima0d5Yu/mQjednW HGpw== X-Gm-Message-State: APjAAAVGgAV6DFG3aWl4t/bgWtsvGiwVMlrruKVdep+s606XE7MYLmXw 3XveR945d+Ug57FHrKxJDMXvzlCqwOs= X-Google-Smtp-Source: APXvYqylUzz41JCh38c4RTPgsXMrJU9QwuV223mukC9onUVHXFf+13p1jmcY3wIUd9uoothS7ZYDhA== X-Received: by 2002:a63:642:: with SMTP id 63mr10253444pgg.73.1575008455203; Thu, 28 Nov 2019 22:20:55 -0800 (PST) Received: from bobo.local0.net (123-243-13-215.tpgi.com.au. [123.243.13.215]) by smtp.gmail.com with ESMTPSA id o188sm22879253pfb.124.2019.11.28.22.20.53 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 28 Nov 2019 22:20:54 -0800 (PST) From: Nicholas Piggin To: skiboot@lists.ozlabs.org Date: Fri, 29 Nov 2019 16:18:25 +1000 Message-Id: <20191129061831.26261-25-npiggin@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191129061831.26261-1-npiggin@gmail.com> References: <20191129061831.26261-1-npiggin@gmail.com> MIME-Version: 1.0 Subject: [Skiboot] [PATCH v9 24/30] 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" Signed-off-by: Nicholas Piggin Reviewed-by: Vasant Hegde --- 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 b577952ea..b4a7474f4 100644 --- a/include/opal-api.h +++ b/include/opal-api.h @@ -1229,9 +1229,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 */ @@ -1240,10 +1240,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[]; };