From patchwork Mon Aug 26 05:36:58 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andrew Jeffery X-Patchwork-Id: 1152940 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 46H14X0R9Mz9sMr for ; Mon, 26 Aug 2019 15:38:04 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=none (p=none dis=none) header.from=aj.id.au Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="afzzoNrc"; dkim=fail reason="signature verification failed" (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="TdK6S8eO"; 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 46H14W3SySzDqNy for ; Mon, 26 Aug 2019 15:38:03 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Authentication-Results: lists.ozlabs.org; spf=pass (mailfrom) smtp.mailfrom=aj.id.au (client-ip=66.111.4.28; helo=out4-smtp.messagingengine.com; envelope-from=andrew@aj.id.au; receiver=) Authentication-Results: lists.ozlabs.org; dmarc=none (p=none dis=none) header.from=aj.id.au Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; unprotected) header.d=aj.id.au header.i=@aj.id.au header.b="afzzoNrc"; dkim=pass (2048-bit key; unprotected) header.d=messagingengine.com header.i=@messagingengine.com header.b="TdK6S8eO"; dkim-atps=neutral Received: from out4-smtp.messagingengine.com (out4-smtp.messagingengine.com [66.111.4.28]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 46H13Q5g8rzDqbx for ; Mon, 26 Aug 2019 15:37:06 +1000 (AEST) Received: from compute4.internal (compute4.nyi.internal [10.202.2.44]) by mailout.nyi.internal (Postfix) with ESMTP id B6BA621FAE; Mon, 26 Aug 2019 01:37:01 -0400 (EDT) Received: from mailfrontend1 ([10.202.2.162]) by compute4.internal (MEProxy); Mon, 26 Aug 2019 01:37:01 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=aj.id.au; h=from :to:cc:subject:date:message-id:mime-version :content-transfer-encoding; s=fm3; bh=RVdnXCYmpC9DFhxz1lfkBi95N9 1ZN4SJShohXnLWL4E=; b=afzzoNrcX1EupEXAFFWO8MXpuknwati3xQ0vVyqcxd kdj2WDIurGA10jraJXJ+XFmmC+2/HWQrqA6W7dn0KhOqx+5JJAwF8T36TgaYlpTP W/h/fizZMVJIenXjD36hLWBzviZD5/nDcfS6kQMfv/QcUmjd2aCC/VEWDrYXyevW hpjII55+2oNy6s535vEnF5jqUspGGB5tAmRvzVYKe6L3bs+b1xRpDXb2bMqgqB+A RbEkjNarA/it4awZwi+T05/6tnhBgRKCtMuGRvSr+TQCTB8O3doN7BolUjROXMNx DxnlsV4Dqn6fPTbfxNXPBOjinrDuIQkuCUDpd2SHajLQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=cc:content-transfer-encoding:date:from :message-id:mime-version:subject:to:x-me-proxy:x-me-proxy :x-me-sender:x-me-sender:x-sasl-enc; s=fm3; bh=RVdnXCYmpC9DFhxz1 lfkBi95N91ZN4SJShohXnLWL4E=; b=TdK6S8eOsM18LkVoN83IsEUH1KwVkpvVT 3u2a+z2eaYmUXGzY/yQz9rS0Qi32LvAfrWP0fa3f+VhfIcv+7NLSEOXGWd0e3vrL Kj+RNetyCqTMIOZzkvZHQbNVtbtUdpGSJAVHjiEyRonwBII5ntO452rxVu+2ZnLt 2FjWdlZ5g50+OcuospT7+Tia35VKiz3kw0w0eAwri/ONC3xSUmTuQ29oMrmgKXVT EFJMO+7ly7o1DsWeleeiKh+Xmp//vgT7B2vrx2QqCjyALRtmDgQCl3s23xGPpD6q emZ+NYFYNHGsXKhz+mTWArL39uqia0AXDuz3GX3l6BJqh3ULKyp0g== X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduvddrudehfedgleelucetufdoteggodetrfdotf fvucfrrhhofhhilhgvmecuhfgrshhtofgrihhlpdfqfgfvpdfurfetoffkrfgpnffqhgen uceurghilhhouhhtmecufedttdenucenucfjughrpefhvffufffkofgggfestdekredtre dttdenucfhrhhomheptehnughrvgifucflvghffhgvrhihuceorghnughrvgifsegrjhdr ihgurdgruheqnecuffhomhgrihhnpegrphgrtghhvgdrohhrghenucfkphepvddtfedrhe ejrddvudehrddujeeknecurfgrrhgrmhepmhgrihhlfhhrohhmpegrnhgurhgvfiesrghj rdhiugdrrghunecuvehluhhsthgvrhfuihiivgeptd X-ME-Proxy: Received: from localhost.localdomain (203-57-215-178.dyn.iinet.net.au [203.57.215.178]) by mail.messagingengine.com (Postfix) with ESMTPA id 1CD6080059; Mon, 26 Aug 2019 01:36:59 -0400 (EDT) From: Andrew Jeffery To: pdbg@lists.ozlabs.org Date: Mon, 26 Aug 2019 15:06:58 +0930 Message-Id: <20190826053658.23879-1-andrew@aj.id.au> X-Mailer: git-send-email 2.20.1 MIME-Version: 1.0 Subject: [Pdbg] [RFC PATCH] libpdbg: Handle cooked/raw CFAM addressing modes X-BeenThere: pdbg@lists.ozlabs.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: "mailing list for https://github.com/open-power/pdbg development" List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" Currently pdbg implements a "cooked" CFAM addressing mode where we have to unscramble the address provided on the commandline before accessing the CFAM itself. Introduce an environment variable, PDBG_CFAM_ADDRESS_MODE, that allows switching between "cooked" addressing and "raw" addressing, where "raw" is the intuitive byte-offset address of registers inside the CFAM address space. If the environment variable is undefined libpdbg will output a warning then continue on the assumption that the address is passed in cooked form. The assumption of cooked mode may change in future releases once adoption of the environment variable is high. Signed-off-by: Andrew Jeffery --- Makefile.am | 2 ++ libpdbg/addressing.c | 73 ++++++++++++++++++++++++++++++++++++++++++++ libpdbg/addressing.h | 23 ++++++++++++++ libpdbg/bmcfsi.c | 5 ++- libpdbg/kernel.c | 5 +-- 5 files changed, 105 insertions(+), 3 deletions(-) create mode 100644 libpdbg/addressing.c create mode 100644 libpdbg/addressing.h diff --git a/Makefile.am b/Makefile.am index 011e686f1bd8..23e51bb67ef3 100644 --- a/Makefile.am +++ b/Makefile.am @@ -144,6 +144,8 @@ libcronus_la_SOURCES = \ libpdbg_la_SOURCES = \ $(DT_sources) \ + libpdbg/addressing.c \ + libpdbg/addressing.h \ libpdbg/adu.c \ libpdbg/backend.h \ libpdbg/bitutils.h \ diff --git a/libpdbg/addressing.c b/libpdbg/addressing.c new file mode 100644 index 000000000000..14aec2347be2 --- /dev/null +++ b/libpdbg/addressing.c @@ -0,0 +1,73 @@ +/* Copyright 2019 IBM Corp. + * + * 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. + */ +#include +#include + +#include "addressing.h" +#include "debug.h" + +#define PDBG_CFAM_ADDRESS_MODE "PDBG_CFAM_ADDRESS_MODE" + +static void cfam_addr_help(void) +{ + pdbg_log(PDBG_ERROR, +"The following CFAM addressing modes are supported:\n" +"\n" +"'"PDBG_CFAM_ADDRESS_MODE"=help': Print this help and exit\n" +"'"PDBG_CFAM_ADDRESS_MODE"=raw': Byte-based engine addressing\n" +"'"PDBG_CFAM_ADDRESS_MODE"=cooked': Register-indexed engine addressing\n" +"\n" +"Each engine is allocated 1kiB of address space in the CFAM. 'cooked'\n" +"addressing mode requires the base address of the engine in the CFAM's\n" +"address space be OR'ed with the 4-byte index of the register of interest\n"); +} + +static int cfam_addr_warned; + +uint32_t cfam_addr(uint32_t addr) +{ + char *mode; + + /* PDBG_CFAM_ADDRESS_MODE=raw|cooked|help */ + mode = getenv("PDBG_CFAM_ADDRESS_MODE"); + + if (!mode) { + if (!cfam_addr_warned) { + pdbg_log(PDBG_ERROR, +"Please specify an explicit CFAM addressing mode using the\n" +PDBG_CFAM_ADDRESS_MODE " environment variable. Defaulting to 'cooked'.\n" +"The default may change to 'raw' in future releases\n"); + pdbg_log(PDBG_ERROR, "\n"); + cfam_addr_help(); + cfam_addr_warned = 1; + } + mode = "cooked"; + } + + if (!strcasecmp("raw", mode)) { + return addr; + } else if (!strcasecmp("cooked", mode)) { + return ((addr & 0x7ffc00) | ((addr & 0x3ff) << 2)); + } else if (!strcasecmp("help", mode)) { + cfam_addr_help(); + /* A little rude in library code... */ + exit(EXIT_SUCCESS); + } else { + cfam_addr_help(); + /* A little rude in library code... */ + exit(EXIT_FAILURE); + } +} diff --git a/libpdbg/addressing.h b/libpdbg/addressing.h new file mode 100644 index 000000000000..56a5fcc93a06 --- /dev/null +++ b/libpdbg/addressing.h @@ -0,0 +1,23 @@ +/* Copyright 2019 IBM Corp. + * + * 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. + */ +#ifndef __ADDRESSING_H +#define __ADDRESSING_H + +#include + +uint32_t cfam_addr(uint32_t addr); + +#endif diff --git a/libpdbg/bmcfsi.c b/libpdbg/bmcfsi.c index 1d2e304ea2ef..011da9a62222 100644 --- a/libpdbg/bmcfsi.c +++ b/libpdbg/bmcfsi.c @@ -25,6 +25,7 @@ #include #include +#include "addressing.h" #include "bitutils.h" #include "operations.h" #include "hwunit.h" @@ -206,10 +207,12 @@ static uint64_t fsi_abs_ar(uint32_t addr, int read) { uint32_t slave_id = (addr >> 21) & 0x3; + addr = cfam_addr(addr & 0x1fffff); + /* Reformat the address. I'm not sure I fully understand this * yet but we basically shift the bottom byte and add 0b01 * (for the write word?) */ - addr = ((addr & 0x1ffc00) | ((addr & 0x3ff) << 2)) << 1; + addr <<= 1; addr |= 0x3; addr |= slave_id << 26; addr |= (0x8ULL | !!(read)) << 22; diff --git a/libpdbg/kernel.c b/libpdbg/kernel.c index 4cc0334d7eb3..c71486ed0a85 100644 --- a/libpdbg/kernel.c +++ b/libpdbg/kernel.c @@ -25,6 +25,7 @@ #include #include +#include "addressing.h" #include "bitutils.h" #include "operations.h" #include "hwunit.h" @@ -37,7 +38,7 @@ int fsi_fd; static int kernel_fsi_getcfam(struct fsi *fsi, uint32_t addr64, uint32_t *value) { int rc; - uint32_t tmp, addr = (addr64 & 0x7ffc00) | ((addr64 & 0x3ff) << 2); + uint32_t tmp, addr = cfam_addr(addr64); rc = lseek(fsi_fd, addr, SEEK_SET); if (rc < 0) { @@ -64,7 +65,7 @@ static int kernel_fsi_getcfam(struct fsi *fsi, uint32_t addr64, uint32_t *value) static int kernel_fsi_putcfam(struct fsi *fsi, uint32_t addr64, uint32_t data) { int rc; - uint32_t tmp, addr = (addr64 & 0x7ffc00) | ((addr64 & 0x3ff) << 2); + uint32_t tmp, addr = cfam_addr(addr64); rc = lseek(fsi_fd, addr, SEEK_SET); if (rc < 0) {