From patchwork Tue Nov 30 22:00:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12694225 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id A1244C433EF for ; Tue, 30 Nov 2021 22:03:27 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:MIME-Version:List-Subscribe:List-Help: List-Post:List-Archive:List-Unsubscribe:List-Id:References:In-Reply-To: Message-Id:Date:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=2shdUsipFoNt4osFAgTNk0RNkzSqPt9P3wsQmSk8fFo=; b=WQySujpSllDs1z XPW3Af258yfs/Kleen7LPdjlMh40jk0rWtLKB20TCBs6uyvUhC4jTYNGN2Uj9RcXAs0WyO4I/6G+L ANVAZzl9+kAwHXaHwOY0TDkcbx4k7094eF2y5TmUFBpewQ74/Y3drofoNk4B8U6RsgQzGScxm5H1K lUtyxYPOQMby+Eb0aSC9mHFuMV+KWA4gSiy22FTvgcMQ++vVeRpC2KBBVArVYMdtPiov9o0NaPH36 JL3IX7SsGOxSrPi/T83xs3Jzk8PXiqOZZZ0hWtjpUigaM19b8a7VEkVhNeYVwcJEDZTKuC693L5OP OrBDDxGtOIlVA6+gM/gQ==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1msBCH-006s9d-Hm; Tue, 30 Nov 2021 22:01:57 +0000 Received: from mail-wr1-x429.google.com ([2a00:1450:4864:20::429]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1msBBX-006ryD-6a for linux-arm-kernel@lists.infradead.org; Tue, 30 Nov 2021 22:01:14 +0000 Received: by mail-wr1-x429.google.com with SMTP id d9so26706311wrw.4 for ; Tue, 30 Nov 2021 14:01:10 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=Nj27ByMCOq05Ai/Gqjxxta7U7cPsZTGIc/1CiRF7cLg=; b=mlHcHAdofwpfAkJ+zd7JRE21fOngYj9anA100JVZDCsN8grkV6m/Z8xDptCDSvn/D6 UG/c3+vZEKXt7Ry/qwTEKTWl6LdFv2tgjf0ewe8TYVet0FyegBlZV+4tgh3G/TtOZqmg PqMlyW0NMezIeK8o+U4sH9WALKbtC7Smi9atWnaFfnNRuNgacAy2LEvaI0g/mNbkLC+x rHYMM5PQL7n7idJB8phh0qJnF9vsy9jVBOJxiJg4Kvy/R/4TS++1E6vlJX3Xx/Emog7L 9iYYD7f7mxP7GIEupsF4AIW6+pl6ESmM2mQAkv+k3nQ1J9aK6VwcUgVjF5mQuPUC4JTC ng2Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=Nj27ByMCOq05Ai/Gqjxxta7U7cPsZTGIc/1CiRF7cLg=; b=OZxfa6hDb6Xq5vNIOrTbfUbi/8glUsA6X2IYJGjQmD8wtjH4AYF5cG616SBeXTbKNL Y+nXGj5/9wfLABBRhBJZmR1Rpx7XmYgspaR+yc9prJRqPZMfD+Uv6fdUS2MS0YcNlVD5 UuC+cEYVTLQ2X0PAOioKYNqx2YSrFm12NYuA4u6IZn8rNozxrT+cTQY5VO0+H31l6qAK 02leyaScRyrjXZ3+PiQWtXQ7NWlu6bNa5ILaITbVfj6uXm0VZTlW3xE7k7K76DCpqXKI HZRB0zy8ibbyVybMDnlDAf/ecvEdzT48VeCmU5+rWCAyyiFK/OZKxbn9qLqA18o3BVTY l/nw== X-Gm-Message-State: AOAM533SZQxQYfcpLoC0CUOCFMSrnUU15S8DDCDqZTQku0rSdpbYpsbt 8oLbm9bIl7hpf8WgoWx5LN+zN9KMBkDkxA== X-Google-Smtp-Source: ABdhPJy/6TUAheGi+srDn/bbfEtD8oFBONS1zBbkqQNyuQqTE/6YyZEZ8rwV3COQdHiD03JqEXigsA== X-Received: by 2002:a5d:4e52:: with SMTP id r18mr1872616wrt.224.1638309669831; Tue, 30 Nov 2021 14:01:09 -0800 (PST) Received: from linaro.org ([2a00:23c5:6809:2201:546d:7d59:1703:bf96]) by smtp.gmail.com with ESMTPSA id y142sm3755280wmc.40.2021.11.30.14.01.09 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 30 Nov 2021 14:01:09 -0800 (PST) From: Mike Leach To: linux-arm-kernel@lists.infradead.org, coresight@lists.linaro.org Cc: mathieu.poirier@linaro.org, suzuki.poulose@arm.com, leo.yan@linaro.org, Mike Leach Subject: [PATCH v2 5/6] coresight: samples: Add coresight file reader sample program Date: Tue, 30 Nov 2021 22:00:59 +0000 Message-Id: <20211130220100.25888-6-mike.leach@linaro.org> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20211130220100.25888-1-mike.leach@linaro.org> References: <20211130220100.25888-1-mike.leach@linaro.org> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211130_140111_301325_3486FFB2 X-CRM114-Status: GOOD ( 28.04 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Add a userspace program to read and print a configuration generated for loading via the configfs attributes. Signed-off-by: Mike Leach --- samples/coresight/Makefile | 20 +- samples/coresight/Makefile.host | 47 +++++ samples/coresight/coresight-cfg-file-read.c | 191 ++++++++++++++++++++ 3 files changed, 256 insertions(+), 2 deletions(-) create mode 100644 samples/coresight/Makefile.host create mode 100644 samples/coresight/coresight-cfg-file-read.c diff --git a/samples/coresight/Makefile b/samples/coresight/Makefile index 07bfd99d7a68..ad8f29a77881 100644 --- a/samples/coresight/Makefile +++ b/samples/coresight/Makefile @@ -4,8 +4,24 @@ obj-$(CONFIG_SAMPLE_CORESIGHT_SYSCFG) += coresight-cfg-sample.o ccflags-y += -I$(srctree)/drivers/hwtracing/coresight -# coresight config - configfs loadable binary config generator -userprogs-always-y += coresight-cfg-filegen +# coresight config - configfs loadable binary config generator & reader +userprogs-always-y += coresight-cfg-filegen coresight-cfg-file-read coresight-cfg-filegen-objs := coresight-cfg-filegen.o coresight-cfg-bufw.o +coresight-cfg-file-read-objs := coresight-cfg-file-read.o coresight-config-file.o + +# pull in the coresight headers userccflags += -I$(srctree)/drivers/hwtracing/coresight + +# need to copy over the reader source from the driver tree - to build separately +CORESIGHT_SRC_PATH := $(abspath $(srctree)/$(src)) + +$(src)/coresight-config-file.c: copy_coresight_source + +.PHONY: copy_coresight_source + +copy_coresight_source: + @cp $(CORESIGHT_SRC_PATH)/../../drivers/hwtracing/coresight/coresight-config-file.c $(CORESIGHT_SRC_PATH)/. + +# clean up the copy after use. +clean-files += coresight-config-file.c diff --git a/samples/coresight/Makefile.host b/samples/coresight/Makefile.host new file mode 100644 index 000000000000..fc01f33bc1ff --- /dev/null +++ b/samples/coresight/Makefile.host @@ -0,0 +1,47 @@ +# SPDX-License-Identifier: GPL-2.0-only + +# Makefile to build just the example userspace programs on host m/c + +this-makefile := $(lastword $(MAKEFILE_LIST)) +sample-src := $(realpath $(dir $(this-makefile))) +srctree := $(realpath $(dir $(sample-src)/../../.)) + +# ensure we use all as the default - skip anything in included Makefile +.DEFAULT_GOAL = all +# MAKECMDGOALS isn't set if there's no explicit goal in the +# command line, so set the default. +MAKECMDGOALS ?= $(.DEFAULT_GOAL) + +# include the main Makefile to use some of the vars from it +include Makefile + +# compile flags +CFLAGS += $(CPPFLAGS) -c -Wall -DLINUX -Wno-switch -Wlogical-op -fPIC $(userccflags) + +# debug variant +ifdef DEBUG +CFLAGS += -g -O0 -DDEBUG +else +CFLAGS += -O2 -DNDEBUG +endif + +.PHONY: all +all: coresight-cfg-filegen coresight-cfg-file-read + +coresight-config-file.o: src_copy + $(CC) $(CFLAGS) coresight-config-file.c -o coresight-config-file.o + +.PHONY: src_copy +src_copy: + @cp $(srctree)/drivers/hwtracing/coresight/coresight-config-file.c $(sample-src)/. + +coresight-cfg-filegen: $(coresight-cfg-filegen-objs) + $(CC) $(LDFLAGS) $(coresight-cfg-filegen-objs) -o coresight-cfg-filegen + +coresight-cfg-file-read: $(coresight-cfg-file-read-objs) + $(CC) $(LDFLAGS) $(coresight-cfg-file-read-objs) -o coresight-cfg-file-read + +clean: + rm -f $(userprogs-always-y) + rm -f *.o + rm -f $(clean-files) diff --git a/samples/coresight/coresight-cfg-file-read.c b/samples/coresight/coresight-cfg-file-read.c new file mode 100644 index 000000000000..4e0fd840428f --- /dev/null +++ b/samples/coresight/coresight-cfg-file-read.c @@ -0,0 +1,191 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2020 Linaro Limited, All rights reserved. + * Author: Mike Leach + */ + +#include +#include +#include +#include +#include + +#include "coresight-config-file.h" + +/* + * tool to read and print a generated configuration + * re-uses the read code source from the driver. + */ + +static void print_configs(struct cscfg_fs_load_descs *load_descs) +{ + struct cscfg_config_desc *config_desc = load_descs->config_descs[0]; + int i, j, p; + + if (!config_desc) { + printf("File contains no configurations.\n\n"); + return; + } + + printf("Configuration name : %s\n", config_desc->name); + printf("Uses %d features:-\n", config_desc->nr_feat_refs); + for (i = 0; i < config_desc->nr_feat_refs; i++) + printf("Feature-%d: %s\n", i + 1, config_desc->feat_ref_names[i]); + + printf("\nProvides %d sets of preset values, %d presets per set\n", config_desc->nr_presets, + config_desc->nr_total_params); + if (config_desc->nr_presets) { + for (i = 0; i < config_desc->nr_presets; i++) { + printf("set[%d]: ", i); + for (j = 0; j < config_desc->nr_total_params; j++) { + p = (i * config_desc->nr_total_params) + j; + printf("0x%llx, ", config_desc->presets[p]); + } + printf("\n"); + } + } + printf("\n\n"); +} + +static void print_reg_type_info(u8 type) +{ + if (type & CS_CFG_REG_TYPE_STD) + printf("std_reg "); + if (type & CS_CFG_REG_TYPE_RESOURCE) + printf("resource "); + if (type & CS_CFG_REG_TYPE_VAL_PARAM) + printf("param_index "); + if (type & CS_CFG_REG_TYPE_VAL_64BIT) + printf("64_bit "); + else + printf("32_bit "); + if (type & CS_CFG_REG_TYPE_VAL_MASK) + printf("masked "); + if (type & CS_CFG_REG_TYPE_VAL_SAVE) + printf("save_on_disable "); + +} + +static void print_regs(int nr, struct cscfg_regval_desc *regs_desc_array) +{ + int i; + struct cscfg_regval_desc *reg_desc; + u8 type; + u16 offset; + u16 info; + + for (i = 0; i < nr; i++) { + reg_desc = ®s_desc_array[i]; + type = (u8)reg_desc->type; + offset = (u16)reg_desc->offset; + info = (u16)reg_desc->hw_info; + + printf("Reg(%d): Type 0x%x: ", i, type); + print_reg_type_info(type); + printf("\nOffset: 0x%03x; HW Info: 0x%03x\n", offset, info); + printf("Value: "); + if (type & CS_CFG_REG_TYPE_VAL_64BIT) + printf("0x%llx\n", reg_desc->val64); + else if (type & CS_CFG_REG_TYPE_VAL_PARAM) + printf("idx = %d\n", reg_desc->param_idx); + else { + printf("0x%x ", reg_desc->val32); + if (type & CS_CFG_REG_TYPE_VAL_MASK) + printf(" mask: 0x%x", reg_desc->mask32); + printf("\n"); + } + } +} + +static void print_params(int nr, struct cscfg_parameter_desc *params_desc) +{ + int i; + + for (i = 0; i < nr; i++) + printf("Param(%d) : %s; Init value 0x%llx\n", i, + params_desc[i].name, params_desc[i].value); +} + +static void print_features(struct cscfg_fs_load_descs *load_descs) +{ + struct cscfg_feature_desc *feat_desc = 0; + int idx = 0; + + feat_desc = load_descs->feat_descs[idx]; + if (!feat_desc) { + printf("File contains no features\n\n"); + return; + } + + while (feat_desc) { + printf("Feature %d name : %s\n", idx+1, feat_desc->name); + printf("Description: %s\n", feat_desc->description); + printf("Match flags: 0x%x\n", feat_desc->match_flags); + printf("Number of Paraneters: %d\n", feat_desc->nr_params); + if (feat_desc->nr_params) + print_params(feat_desc->nr_params, feat_desc->params_desc); + printf("Number of Registers: %d\n", feat_desc->nr_regs); + if (feat_desc->nr_regs) + print_regs(feat_desc->nr_regs, feat_desc->regs_desc); + printf("\n\n"); + + /* next feature */ + idx++; + feat_desc = load_descs->feat_descs[idx]; + } +} + +int main(int argc, char **argv) +{ + FILE *fp; + struct cscfg_fs_load_descs *load_descs; + int err, fsize; + u8 buffer[CSCFG_FILE_MAXSIZE]; + + printf("CoreSight Configuration file reader\n\n"); + + /* need a filename */ + if (argc <= 1) { + printf("Please provide filename on command line\n"); + return -EINVAL; + } + + /* open file and read into the buffer. */ + fp = fopen(argv[1], "rb"); + if (fp == NULL) { + printf("Error opening file %s\n", argv[1]); + return -EINVAL; + } + + fseek(fp, 0, SEEK_END); + fsize = ftell(fp); + rewind(fp); + if (fsize > CSCFG_FILE_MAXSIZE) { + printf("Error: Input file too large."); + fclose(fp); + return -EINVAL; + } + fread(buffer, sizeof(u8), fsize, fp); + fclose(fp); + + /* allocate the descriptor structures to be populated by read operation */ + load_descs = malloc(sizeof(struct cscfg_fs_load_descs)); + if (!load_descs) { + printf("Error allocating load descs structure.\n"); + return -ENOMEM; + } + + /* read the buffer and create the configuration and feature structures */ + err = cscfg_file_read_buffer(buffer, fsize, load_descs); + if (err) { + printf("Error reading configuration file\n"); + goto exit_free_mem; + } + /* print the contents of the structures */ + print_configs(load_descs); + print_features(load_descs); + +exit_free_mem: + free(load_descs); + return err; +}