From patchwork Wed Jun 10 05:24:20 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Amitay Isaacs X-Patchwork-Id: 1306455 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 49hb5p2DZQz9sRR for ; Wed, 10 Jun 2020 15:24:46 +1000 (AEST) Authentication-Results: ozlabs.org; dmarc=fail (p=none dis=none) header.from=ozlabs.org Authentication-Results: ozlabs.org; dkim=fail reason="signature verification failed" (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=kUMX6cNi; 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 49hb5n4QmtzDqP5 for ; Wed, 10 Jun 2020 15:24:45 +1000 (AEST) X-Original-To: pdbg@lists.ozlabs.org Delivered-To: pdbg@lists.ozlabs.org Received: from ozlabs.org (bilbo.ozlabs.org [203.11.71.1]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits)) (No client certificate requested) by lists.ozlabs.org (Postfix) with ESMTPS id 49hb5d0q68zDqMC for ; Wed, 10 Jun 2020 15:24:37 +1000 (AEST) Authentication-Results: lists.ozlabs.org; dmarc=pass (p=none dis=none) header.from=ozlabs.org Authentication-Results: lists.ozlabs.org; dkim=pass (2048-bit key; secure) header.d=ozlabs.org header.i=@ozlabs.org header.a=rsa-sha256 header.s=201707 header.b=kUMX6cNi; dkim-atps=neutral Received: from authenticated.ozlabs.org (localhost [127.0.0.1]) (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 mail.ozlabs.org (Postfix) with ESMTPSA id 49hb5c5xKnz9sSF; Wed, 10 Jun 2020 15:24:36 +1000 (AEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=ozlabs.org; s=201707; t=1591766676; bh=YK5Mj9dgN5C3FUkUPL0mdDel+1NapKBzhM3R4CZUIAo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=kUMX6cNi3qyGCZ42lEKqJHePI1v8P5G5T1GWSfUwFSTqhJZii87sMqNluqLHjP+XR i2vMbhWKFwoVrDJC8CZTB53G6eBBLL4mE1HEDdP3XxAZIbrjR9jygvg3oKwArTGZ9N v2+9k5nb4nR8sxw/UTK2o7VRjWogCK5eRS/N3vWZjVQDDeadwItniL3+jT/Tk2HFrT wCY20QcnkoKIv4k9VXHnI+Fy1FKLtWs5gvmQECy+siz4qzq5VXt03ia7yhHgu/fyfN dp61b9bCIlmmzjBPK1IgX7TZrbQ6QTy1Kf1KneOmeNKK53RAGrr7JUI96aJJ8vMmdX h7slUCUUHBlMA== From: Amitay Isaacs To: pdbg@lists.ozlabs.org Date: Wed, 10 Jun 2020 15:24:20 +1000 Message-Id: <20200610052426.150225-2-amitay@ozlabs.org> X-Mailer: git-send-email 2.26.2 In-Reply-To: <20200610052426.150225-1-amitay@ozlabs.org> References: <20200610052426.150225-1-amitay@ozlabs.org> MIME-Version: 1.0 Subject: [Pdbg] [PATCH v2 1/7] libpdbg: Store fsi_fd state information in fsi structure 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: , Cc: Amitay Isaacs Errors-To: pdbg-bounces+incoming=patchwork.ozlabs.org@lists.ozlabs.org Sender: "Pdbg" This allows to have different fd for different fsi targets. Also, we can close the fd cleanly in release procedure. Signed-off-by: Amitay Isaacs Reviewed-by: Alistair Popple --- libpdbg/hwunit.h | 1 + libpdbg/kernel.c | 87 +++++++++++++++++++++++------------------------- 2 files changed, 43 insertions(+), 45 deletions(-) diff --git a/libpdbg/hwunit.h b/libpdbg/hwunit.h index 61aea0f..e3a8426 100644 --- a/libpdbg/hwunit.h +++ b/libpdbg/hwunit.h @@ -112,6 +112,7 @@ struct fsi { int (*read)(struct fsi *, uint32_t, uint32_t *); int (*write)(struct fsi *, uint32_t, uint32_t); enum chip_type chip_type; + int fd; }; #define target_to_fsi(x) container_of(x, struct fsi, target) diff --git a/libpdbg/kernel.c b/libpdbg/kernel.c index c4637a7..7914e50 100644 --- a/libpdbg/kernel.c +++ b/libpdbg/kernel.c @@ -33,7 +33,6 @@ #define OPENFSI_LEGACY_PATH "/sys/bus/platform/devices/gpio-fsi/" #define OPENFSI_PATH "/sys/class/fsi-master/" -int fsi_fd; const char *fsi_base; const char *kernel_get_fsi_path(void) @@ -66,14 +65,14 @@ 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); - rc = lseek(fsi_fd, addr, SEEK_SET); + rc = lseek(fsi->fd, addr, SEEK_SET); if (rc < 0) { rc = errno; PR_WARNING("seek failed: %s\n", strerror(errno)); return rc; } - rc = read(fsi_fd, &tmp, 4); + rc = read(fsi->fd, &tmp, 4); if (rc < 0) { rc = errno; if ((addr64 & 0xfff) != 0xc09) @@ -93,7 +92,7 @@ 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); - rc = lseek(fsi_fd, addr, SEEK_SET); + rc = lseek(fsi->fd, addr, SEEK_SET); if (rc < 0) { rc = errno; PR_WARNING("seek failed: %s\n", strerror(errno)); @@ -101,7 +100,7 @@ static int kernel_fsi_putcfam(struct fsi *fsi, uint32_t addr64, uint32_t data) } tmp = htobe32(data); - rc = write(fsi_fd, &tmp, 4); + rc = write(fsi->fd, &tmp, 4); if (rc < 0) { rc = errno; PR_ERROR("Failed to write to 0x%08" PRIx32 " (%016" PRIx32 ")\n", addr, addr64); @@ -111,16 +110,6 @@ static int kernel_fsi_putcfam(struct fsi *fsi, uint32_t addr64, uint32_t data) return 0; } -#if 0 -/* TODO: At present we don't have a generic destroy method as there aren't many - * use cases for it. So for the moment we can just let the OS close the file - * descriptor on exit. */ -static void kernel_fsi_destroy(struct pdbg_target *target) -{ - close(fsi_fd); -} -#endif - static void kernel_fsi_scan_devices(void) { const char one = '1'; @@ -154,51 +143,59 @@ static void kernel_fsi_scan_devices(void) int kernel_fsi_probe(struct pdbg_target *target) { - if (!fsi_fd) { - int tries = 5; - int rc; - const char *kernel_path = kernel_get_fsi_path(); - char *path; - - if (!kernel_path) - return -1; - - rc = asprintf(&path, "%s/fsi0/slave@00:00/raw", kernel_get_fsi_path()); - if (rc < 0) { - PR_ERROR("Unable create fsi path\n"); - return rc; - } + struct fsi *fsi = target_to_fsi(target); + int tries = 5; + int rc; + const char *kernel_path = kernel_get_fsi_path(); + char *path; - while (tries) { - /* Open first raw device */ - fsi_fd = open(path, O_RDWR | O_SYNC); - if (fsi_fd >= 0) { - free(path); - return 0; - } - tries--; - - /* Scan */ - kernel_fsi_scan_devices(); - sleep(1); - } - if (fsi_fd < 0) { - PR_ERROR("Unable to open %s\n", path); + if (!kernel_path) + return -1; + + rc = asprintf(&path, "%s/fsi0/slave@00:00/raw", kernel_get_fsi_path()); + if (rc < 0) { + PR_ERROR("Unable create fsi path\n"); + return rc; + } + + while (tries) { + /* Open first raw device */ + fsi->fd = open(path, O_RDWR | O_SYNC); + if (fsi->fd >= 0) { free(path); - return -1; + return 0; } + tries--; + /* Scan */ + kernel_fsi_scan_devices(); + sleep(1); + } + if (fsi->fd < 0) { + PR_ERROR("Unable to open %s\n", path); + free(path); } return -1; } +static void kernel_fsi_release(struct pdbg_target *target) +{ + struct fsi *fsi = target_to_fsi(target); + + if (fsi->fd != -1) { + close(fsi->fd); + fsi->fd = -1; + } +} + static struct fsi kernel_fsi = { .target = { .name = "Kernel based FSI master", .compatible = "ibm,kernel-fsi", .class = "fsi", .probe = kernel_fsi_probe, + .release = kernel_fsi_release, }, .read = kernel_fsi_getcfam, .write = kernel_fsi_putcfam,