From patchwork Tue Nov 30 22:01:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Mike Leach X-Patchwork-Id: 12694228 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 3186BC433F5 for ; Tue, 30 Nov 2021 22:04:36 +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=9JlDyHwXWj7ElJ5uinuNrR+u1km2Gf6pWQhkzS5YrVU=; b=MW9qPqE0SfyUqE eXVngJ3xEHxlapgeF8r1D1BkNrVbCLqlbSH7bH1pHbLNXhgpXjEwvfdCWCHSE4vkWlkM9fls+qsP/ TxfGnH+VE8zO3q4gG5fFsZ6SQasxbTWBlJ/hTZRrqMSibRAT5ofYEiiddXzLBp5nRw0qxu3JtLP+C KOv0DKnCEdSU2Bqi918xLEnRRO4l6WaFQ6B+57qn5fgyPJlGB3cQY2Hv8nVIO3voUJUj9pH050Myf odejxJq3/AV00jwhebd7LagKuPAF45WokyxButXETrdBzpfi/WfVRbLHDKtVeqs9P3+76cfc55uYd LQJb9/mjNzz4z2xSqu0A==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1msBDD-006sYh-NT; Tue, 30 Nov 2021 22:02:56 +0000 Received: from mail-wr1-x436.google.com ([2a00:1450:4864:20::436]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1msBBX-006ryO-VR for linux-arm-kernel@lists.infradead.org; Tue, 30 Nov 2021 22:01:15 +0000 Received: by mail-wr1-x436.google.com with SMTP id d24so47647002wra.0 for ; Tue, 30 Nov 2021 14:01:11 -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=qLR7XsaQsCwnfEm1WLtzUI8vZjVqNoJXPGzhwKhjbOo=; b=YgvkW8aZqAYGclcIHg/X97tK5ZecClJsThA5O8tLbU4xa0Ghx8AKifgJpSi9fpGfcm xH1h5lxpkuu22qtomMTTtvn5+UTJIEkQmG4V0/+0fgUxVtZChP54xXTQHBSA+/bEZlZI mIs/LHzQdi7bpTwt94umbnhXwWk4bRStj0jZ7jQh1uEVqCleX9+IsLvLMgoOxP1vJZ4C vnJaR8An69RUO2kEFgZsJUBiu6jC2xc3spPrunBr7vuCZ8REryj3Y/wnZsSwhd5KQWg/ cRqCiVJqmr1KYAyDEHX5d/5rmJVvMIF8NChhCAv9iNN68H9G/+67NCVwRiiNtcbd1JrF /YgQ== 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=qLR7XsaQsCwnfEm1WLtzUI8vZjVqNoJXPGzhwKhjbOo=; b=uCx0ES5X2TcbGpGBmJsbYXTkqN3sQ+BQnLgxndsHlIHriZ4eIQlBMG2t+MftgoLfHm eUg+IY02twCmU/Q1Qmiom4Tr51gvVimOn4keBCo8A2I9crs65SGK01cQHjmPX0+nx5CQ B4zw0gmGR0IUoaMeDADxWuEicmaS4wq0+uuos9/mvCCHlumnlcOg6r0S/Fw/I/5V/QCB 98KzrBARd2iEI/CeiQcSfVKyt9PcIT0z/jbmyhofJEc3AIBHl+6rIFSNgdLf/riirLaX W0HO40IMU1umOKzxkuZbNASSE9024EYTbGJ346wwW2APxvrrqpJle4Knhb60uQXoSka0 13fg== X-Gm-Message-State: AOAM533B6R2kvZzK4768RUN86M91c12Zrh/bpeBtVTCS/OU4K5zeTS8x lDNQAhPLoI2+9G1GdSiQBiZJRhM65Noz4w== X-Google-Smtp-Source: ABdhPJw0nkfR+fGsDgBkr3SObJEt/qH4o8Redb1b0ifohIRBnKfx/IcSmSDNkiGbVYkRXUpjb7Rx7w== X-Received: by 2002:a5d:452c:: with SMTP id j12mr1819757wra.430.1638309670420; Tue, 30 Nov 2021 14:01:10 -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:10 -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 6/6] Documentation: coresight: docs for config load via configfs Date: Tue, 30 Nov 2021 22:01:00 +0000 Message-Id: <20211130220100.25888-7-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_140112_088402_F0E539B0 X-CRM114-Status: GOOD ( 27.26 ) 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 documentation covering the configfs updates that allow binary configuration files to be loaded and unloaded via configfs, along with the demonstration programs in samples. Signed-off-by: Mike Leach --- .../trace/coresight/coresight-config.rst | 151 +++++++++++++++++- 1 file changed, 145 insertions(+), 6 deletions(-) diff --git a/Documentation/trace/coresight/coresight-config.rst b/Documentation/trace/coresight/coresight-config.rst index 6d5ffa6f7347..f11def230fab 100644 --- a/Documentation/trace/coresight/coresight-config.rst +++ b/Documentation/trace/coresight/coresight-config.rst @@ -152,7 +152,7 @@ follows:: $ cd configurations/ $ ls - autofdo + autofdo last_load_status load unload $ cd autofdo/ $ ls description feature_refs preset1 preset3 preset5 preset7 preset9 @@ -278,9 +278,19 @@ Creating and Loading Custom Configurations ========================================== Custom configurations and / or features can be dynamically loaded into the -system by using a loadable module. +system by using a loadable module, or by loading a binary configuration +file in configfs. + +Loaded configurations can use previously loaded features. The system will +ensure that it is not possible to unload a feature that is currently in +use, by enforcing the unload order as the strict reverse of the load order. + +An example of a custom configuration module, and generators for binary +configuration files are found in './samples/coresight'. -An example of a custom configuration is found in ./samples/coresight. + +Using a Loadable Module +----------------------- This creates a new configuration that uses the existing built in strobing feature, but provides a different set of presets. @@ -289,6 +299,135 @@ When the module is loaded, then the configuration appears in the configfs file system and is selectable in the same way as the built in configuration described above. -Configurations can use previously loaded features. The system will ensure -that it is not possible to unload a feature that is currently in use, by -enforcing the unload order as the strict reverse of the load order. +The file 'coresight-cfg-sample.c' contains the configuration and module +initialisation code needed to create the loadable module. + +This will be built alongside the kernel modules if select in KConfig. + + +Using a Binary Configuration File +--------------------------------- + +Building the samples creates the 'coresight-cfg-filegen' program that will +generate a configuration binary 'example1.cscfg' that can be loaded into the +system using configfs. The configuration declared in the source file +'coresight-cfg-filegen.c' is named 'autofdo3' - the name that will be used +once loaded. + +The source files 'coresight-cfg-bufw.h' and 'coresight-cfg-bufw.c' provide a +standard function to convert a configuration declared in 'C' into the correct +binary buffer format. These files can be re-used to create new custom +configurations. + +The program 'coresight-cfg-file-read' can read back and print a configuration +binary. This is built using the reader from the driver code. + +There are additional attributes in the configurations directory - load, unload +and last_load_status that can be used to load and unload configuration +binary files. To load, 'cat' the binary config into the load attribute:: + + $ ls /config/cs-syscfg/configurations/ + autofdo last_load_status load unload + $ cat example1.cscfg > /config/cs-syscfg/configurations/load + $ ls /config/cs-syscfg/configurations/ + autofdo autofdo3 last_load_status load unload + $ cat /config/cs-syscfg/configurations/last_load_status + OK: configuration file loaded (autofdo3). + +To unload, use the same file in the unload attribute:: + + $ cat example1.cscfg > /config/cs-syscfg/configurations/unload + $ cat /config/cs-syscfg/configurations/last_load_status + OK: configuration file unloaded (autofdo3). + ls /config/cs-syscfg/configurations/ + autofdo last_load_status load unload + +The generator and reader programs can also be built directly, separately from +the kernel build by using the 'Makefile.host' file. This allows native binaries +to be created on the host machine rather than cross compiled version for the +target. + + +Binary Configuration File Format +-------------------------------- + +The file format is defined in the source file **coresight-config-file.h** + +The source reader and generator examples produce a binary of this format. + +This arrangement is reproduced below:- + +Overall File structure +~~~~~~~~~~~~~~~~~~~~~~ + +:: + + [cscfg_file_header] // Mandatory + [CONFIG_ELEM] // Optional - one per file, if present, first element in file. + [FEATURE_ELEM]* // Optional - multiple, defined by cscfg_file_header.nr_features + +File is invalid if both [CONFIG_ELEM] and [FEATURE_ELEM] are omitted. + +A file that contains only [FEATURE_ELEM] may be loaded, and the features used +by subsequently loaded files with [CONFIG_ELEM] elements. + +Where [CONFIG_ELEM] is present, then **cscfg_file_header.nr_features** and +**CONFIG_ELEM.nr_feat_refs** must have the same value. + +CONFIG_ELEM element +~~~~~~~~~~~~~~~~~~~ + +:: + + [cscfg_file_elem_header] // header length value to end of feature strings. + [cscfg_file_elem_str] // name of the configuration. + [cscfg_file_elem_str] // description of configuration. + [u16 value](nr_presets) // number of defined presets. + [u32 value](nr_total_params) // total parameters defined by all used features. + [u16 value](nr_feat_refs) // number of features referenced by the configuration + [u64 values] * (nr_presets * nr_total_params) // the preset values. + [cscfg_file_elem_str] * (nr_feat_refs) // the features used in the configurations. + +FEATURE_ELEM element +~~~~~~~~~~~~~~~~~~~~ + +:: + + [cscfg_file_elem_header] // header length is total bytes to end of param structures. + [cscfg_file_elem_str] // feature name. + [cscfg_file_elem_str] // feature description. + [u32 value](match_flags) // flags to associate the feature with a device. + [u16 value](nr_regs) // number of registers. + [u16 value](nr_params) // number of parameters. + [cscfg_regval_desc struct] * (nr_regs) // register definitions + [PARAM_ELEM] * (nr_params) // parameters definitions + +PARAM_ELEM element +~~~~~~~~~~~~~~~~~~ + +:: + + [cscfg_file_elem_str] // parameter name. + [u64 value](param_value] // initial value. + +Additional definitions. +~~~~~~~~~~~~~~~~~~~~~~~ + +The following structures are defined in **coresight-config-file.h** + + * **struct cscfg_file_header** : This structure contains an initial magic number, the total + length of the file, and the number of features in the file. + * **struct cscfg_file_elem_header**: This defines the total length and type of a CONFIG_ELEM + or a FEATURE_ELEM. + * **struct cscfg_file_elem_str**: This defines a string and its length. + +The magic number in cscfg_file_header is defined as two bitfields:: + + [31:8] Fixed magic number to identify file type. + [7:0] Current file format version. + +The following defines determine the maximum overall file size and maximum individual +string size:: + + CSCFG_FILE_MAXSIZE // maximum overall file size. + CSCFG_FILE_STR_MAXSIZE // maximum individual string size.