From patchwork Wed Apr 29 18:11:36 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 11518079 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CE27F14DD for ; Wed, 29 Apr 2020 18:12:19 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 5600B21D90 for ; Wed, 29 Apr 2020 18:12:19 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="gAGUzTal"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="X98dJh2m" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 5600B21D90 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=G4liEbRfhmNvM/I9FfEENdN9sBc/Glo2RInjpekrPAs=; b=gAGUzTalKoiZCs YHqVOWnmp0tBprwvCULAl5D+vIMrkRyg6X/knOJ7tWuRBgvS1rWsuw2kIs1d+3KDsDsScu41cHvYh DEh/fUDxK526WZhzdKHcdggYsJec1DP50C4ab12Da8q6aLuXg1XRIq4Sy0e6FbX4A3E0onTn6+NeN NTAw/XIGKg3tKoqrCBJaE0CIo4/rgADuF52nmMCIgKPznyAo/zCcaCGxuiE/Gc7h+NW7Lwydgqu0C +lLMAtj75xMhJPmRCiESj25TwF5EKxHTVFw1nQSjE2b03/GwIzl0Zrdhy+AF9ATerauWRT4BvyJsg I7zYPwHbg/firYE4yICQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jTrBu-0004P3-0t; Wed, 29 Apr 2020 18:12:14 +0000 Received: from mail-qt1-x843.google.com ([2607:f8b0:4864:20::843]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jTrBg-0004Di-BZ for linux-arm-kernel@lists.infradead.org; Wed, 29 Apr 2020 18:12:02 +0000 Received: by mail-qt1-x843.google.com with SMTP id w29so2701961qtv.3 for ; Wed, 29 Apr 2020 11:12:00 -0700 (PDT) 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=ozWAZTiRiQAsK8Aefmx7KqwvCcl9XDLzbB/7ZK1Lnsc=; b=X98dJh2mUqPg9rHjeKO5tNwemXuPt/5B4cuoYCOj/ENiDh8dqX5JfZfHbLnz9RK7Bk LEXUoo3YA0cfboza3R2b/+yYHdNIKetX61wBVB8K2oYEDhA4F+25D4Pn9gUBe/sGJS+9 qr7LFqSz89b177nk9ztecnXr3yQouAOu/tQyzNsWaxXdsDi8pfIHZgkvJGINd7UV5TNz oFS3XN5kFlv3lZPiS6OJrAmCkeR1VfBStHrD+7+FvTslu7vlnqlAeH7gr2Hyhogy1kNv X5391wX02q2k+g8VDQQ87UsAL0Gp54czE6mQS8n61cTmsdpnplQYm3uQddBL6vjWoB9G 4+ew== 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=ozWAZTiRiQAsK8Aefmx7KqwvCcl9XDLzbB/7ZK1Lnsc=; b=TAEcKZSB9wOaV/O3ITIQGR30GnCBF/BnA/a1EGxc8wZjY5/ghAtrTKPGBJrTIX6q9g YtjkKCSN8EmfdlcytL9DVuV6jorEblxALkZvs3fIBeUfNWo9XDQuB2SFg661608/8H8D VV3jopi9XFDvaUVOQcaKZhBesdcwlqK5M4o8TFRv9vQ8pAwOO/vPsdkuo9NdrQ32BgqE Y7B4xvajj2bPZbnR/ip8nohfrr/+Yhp8nRmKB7nrT0yAjtrGJ0yF1+oPu+xtTpvUrUjn thcCbA0NrobG2VpAJoaFA4/qzr+u0K4JR5Jjb+i+6NV2KFiUIuHYB53iJHuQxSxF86zd wYHQ== X-Gm-Message-State: AGi0PuYUkNziOfKQaCWj1/ZUJWiegIqP7HHRtdT2BGRQyn85hGGnIsHn JUMwpGcc0cpfDWuaxSABf6E= X-Google-Smtp-Source: APiQypIWl6+H5EHpNscQV77b86EnqxfLSGzZvkfErQF6MEiAnf4tiPyI8Vqlk2Lg1QDznTxR0sOJ9A== X-Received: by 2002:ac8:7c81:: with SMTP id y1mr33853251qtv.97.1588183919027; Wed, 29 Apr 2020 11:11:59 -0700 (PDT) Received: from localhost.localdomain (072-189-064-225.res.spectrum.com. [72.189.64.225]) by smtp.gmail.com with ESMTPSA id o43sm16315082qtf.46.2020.04.29.11.11.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 11:11:58 -0700 (PDT) From: William Breathitt Gray To: jic23@kernel.org Subject: [PATCH 2/4] docs: counter: Update to reflect sysfs internalization Date: Wed, 29 Apr 2020 14:11:36 -0400 Message-Id: <0e37267e49de3a45c850b051d76a8a55ffdde196.1588176662.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200429_111200_416332_F64704E0 X-CRM114-Status: GOOD ( 22.15 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:843 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [vilhelm.gray[at]gmail.com] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kamel.bouhara@bootlin.com, gwendal@chromium.org, david@lechnology.com, felipe.balbi@linux.intel.com, linux-iio@vger.kernel.org, syednwaris@gmail.com, alexandre.belloni@bootlin.com, linux-kernel@vger.kernel.org, mcoquelin.stm32@gmail.com, patrick.havelange@essensium.com, William Breathitt Gray , fabrice.gasnier@st.com, fabien.lahoudere@collabora.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, alexandre.torgue@st.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org The Counter subsystem architecture and driver implementations have changed in order to handle Counter sysfs interactions in a more consistent way. This patch updates the Generic Counter interface documentation to reflect the changes. Signed-off-by: William Breathitt Gray --- Documentation/driver-api/generic-counter.rst | 220 +++++++++++++------ 1 file changed, 157 insertions(+), 63 deletions(-) diff --git a/Documentation/driver-api/generic-counter.rst b/Documentation/driver-api/generic-counter.rst index e622f8f6e56a..3ab8125b9c05 100644 --- a/Documentation/driver-api/generic-counter.rst +++ b/Documentation/driver-api/generic-counter.rst @@ -250,8 +250,8 @@ for defining a counter device. .. kernel-doc:: drivers/counter/counter.c :export: -Implementation -============== +Driver Implementation +===================== To support a counter device, a driver must first allocate the available Counter Signals via counter_signal structures. These Signals should @@ -267,11 +267,10 @@ respective counter_count structure. These counter_count structures are set to the counts array member of an allocated counter_device structure before the Counter is registered to the system. -Driver callbacks should be provided to the counter_device structure via -a constant counter_ops structure in order to communicate with the -device: to read and write various Signals and Counts, and to set and get -the "action mode" and "function mode" for various Synapses and Counts -respectively. +Driver callbacks must be provided to the counter_device structure in +order to communicate with the device: to read and write various Signals +and Counts, and to set and get the "action mode" and "function mode" for +various Synapses and Counts respectively. A defined counter_device structure may be registered to the system by passing it to the counter_register function, and unregistered by passing @@ -279,13 +278,58 @@ it to the counter_unregister function. Similarly, the devm_counter_register and devm_counter_unregister functions may be used if device memory-managed registration is desired. -Extension sysfs attributes can be created for auxiliary functionality -and data by passing in defined counter_device_ext, counter_count_ext, -and counter_signal_ext structures. In these cases, the -counter_device_ext structure is used for global/miscellaneous exposure -and configuration of the respective Counter device, while the -counter_count_ext and counter_signal_ext structures allow for auxiliary -exposure and configuration of a specific Count or Signal respectively. +The struct counter_data structure is used to define counter extensions +for Signals, Synapses, and Counts:: + + struct counter_data { + enum counter_data_type type; + const char *name; + void *read; + void *write; + void *priv; + }; + +The "type" member specifies the type of data (e.g. unsigned long, +boolean, etc.) handled by this extension. The "read" and "write" members +can then be set by the counter device driver with callbacks to handle +that data. + +Convenience macros such as COUNTER_DATA_UNSIGNED_LONG are provided for +use by driver authors. In particular, driver authors are expected to use +the provided macros for standard Counter subsystem attributes in order +to maintain a consistent interface for userspace. For example, a counter +device driver may define several standard attributes like so:: + + struct counter_data count_ext[] = { + COUNTER_DATA_DIRECTION(count_direction_read), + COUNTER_DATA_ENABLE(count_enable_read, count_enable_write), + COUNTER_DATA_CEILING(count_ceiling_read, count_ceiling_write), + }; + +This makes it intuitive to see, add, and modify the attributes that are +supported by this driver ("direction", "enable", and "ceiling") and to +maintain this code without getting lost in a web of struct braces. + +Callbacks must match the function type expected for the respective +component or extension. These types are defined in the +`drivers/counter/counter-function-types.h` file. + +The corresponding prototypes for the callbacks mentioned in the previous +example would be:: + + int count_direction_read(struct counter_device *counter, + struct counter_count *count, + enum counter_count_direction *direction); + int count_enable_read(struct counter_device *counter, + struct counter_count *count, bool *enable); + int count_enable_write(struct counter_device *counter, + struct counter_count *count, bool enable); + int count_ceiling_read(struct counter_device *counter, + struct counter_count *count, + unsigned long *ceiling); + int count_ceiling_write(struct counter_device *counter, + struct counter_count *count, + unsigned long ceiling); Determining the type of extension to create is a matter of scope. @@ -313,52 +357,102 @@ Determining the type of extension to create is a matter of scope. chip overheated via a device extension called "error_overtemp": /sys/bus/counter/devices/counterX/error_overtemp -Architecture -============ - -When the Generic Counter interface counter module is loaded, the -counter_init function is called which registers a bus_type named -"counter" to the system. Subsequently, when the module is unloaded, the -counter_exit function is called which unregisters the bus_type named -"counter" from the system. - -Counter devices are registered to the system via the counter_register -function, and later removed via the counter_unregister function. The -counter_register function establishes a unique ID for the Counter -device and creates a respective sysfs directory, where X is the -mentioned unique ID: - - /sys/bus/counter/devices/counterX - -Sysfs attributes are created within the counterX directory to expose -functionality, configurations, and data relating to the Counts, Signals, -and Synapses of the Counter device, as well as options and information -for the Counter device itself. - -Each Signal has a directory created to house its relevant sysfs -attributes, where Y is the unique ID of the respective Signal: - - /sys/bus/counter/devices/counterX/signalY - -Similarly, each Count has a directory created to house its relevant -sysfs attributes, where Y is the unique ID of the respective Count: - - /sys/bus/counter/devices/counterX/countY - -For a more detailed breakdown of the available Generic Counter interface -sysfs attributes, please refer to the -Documentation/ABI/testing/sysfs-bus-counter file. - -The Signals and Counts associated with the Counter device are registered -to the system as well by the counter_register function. The -signal_read/signal_write driver callbacks are associated with their -respective Signal attributes, while the count_read/count_write and -function_get/function_set driver callbacks are associated with their -respective Count attributes; similarly, the same is true for the -action_get/action_set driver callbacks and their respective Synapse -attributes. If a driver callback is left undefined, then the respective -read/write permission is left disabled for the relevant attributes. - -Similarly, extension sysfs attributes are created for the defined -counter_device_ext, counter_count_ext, and counter_signal_ext -structures that are passed in. +Subsystem Architecture +====================== + +Counter drivers pass and take data natively (i.e. unsigned long, bool, +size_t, etc.) and the shared counter module handles the translation +between the driver callbacks and userspace interfaces. This gurantees a +standard userspace interface for all counter drivers, and helps +generalize the Generic Counter driver ABI in order to support various +userspace interfaces without changes to the existing counter drivers. + +A high-level view of how a count value is passed down from a counter +driver can be exemplified by the following:: + + Count data request: + ~~~~~~~~~~~~~~~~~~~ + ---------------------- + / Counter device \ + +----------------------+ + | Count register: 0x28 | + +----------------------+ + | + ----------------- + / raw count data / + ----------------- + | + V + +----------------------------+ + | Counter device driver |----------+ + +----------------------------+ | + | Processes data from device | ------------------- + |----------------------------| / driver callbacks / + | Type: unsigned long | ------------------- + | Value: 42 | | + +----------------------------+ | + | | + ---------------- | + / unsigned long / | + ---------------- | + | | + | V + | +----------------------+ + | | Counter core | + | +----------------------+ + | | Routes device driver | + | | callbacks to the | + | | userspace interfaces | + | +----------------------+ + | | + | ------------------- + | / driver callbacks / + | ------------------- + | | + +-------+ | + | | + | +---------------+ + | | + V | + +--------------------+ | + | Counter sysfs |<-+ + +--------------------+ + | Translates to the | + | standard Counter | + | sysfs output | + |--------------------| + | Type: const char * | + | Value: "42" | + +--------------------+ + | + --------------- + / const char * / + --------------- + | + V + +--------------------------------------------------+ + | `/sys/bus/counter/devices/counterX/countY/count` | + +--------------------------------------------------+ + \ Count: "42" / + -------------------------------------------------- + +There are three primary components involved: + +Counter device driver +--------------------- +Communicates with the hardware device to read/write data; e.g. counter +drivers for quadrature encoders, timers, etc. + +Counter core +------------ +Registers the counter device driver to the system so that the respective +callbacks are called during userspace interaction. + +Counter sysfs +------------- +Translates counter data to the standard Counter sysfs interface format +and vice versa. + +Please refer to the `Documentation/ABI/testing/sysfs-bus-counter` file +for a detailed breakdown of the available Generic Counter interface +sysfs attributes. From patchwork Wed Apr 29 18:11:37 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 11518083 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7680E112C for ; Wed, 29 Apr 2020 18:13:00 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id 3960121973 for ; Wed, 29 Apr 2020 18:13:00 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="uBRJiL5K"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="NiASIR5e" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 3960121973 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=/BuZ5Cc/hvpbLPgnRx3yw8UKgDuku1PAsJPH20T1iX8=; b=uBRJiL5KO1TceA ar0jEiqh+fb7lmX72BISDw9dg9w2SrlRY8datbSylGlrI3CzQp6qXmbrJPI9jiBoHhV+Epzazekj8 4ixtevH4G3wWQxYu0OazJP8CbuORofR3bIy54mnZq3acy26YSzuCVeAq9bS7BUZ3W3QJ+ruRV0qWA TivxIZnvvH3K0+rDhgzLyxh7PLstJQ9cQLrB+l4vNtuW9m3Ak2JOmzNDjqMAqudAvR8Z6XyqB99Ya 4YzwQ4LSJVQRJ8SJU/zEQtQ7XTywpUr6NwiTdlFQUYEOESatwWKNWGpB3bMke/GHz9iVCbmu8tMsD R3TcQfQ/IHIIA69Duh6Q==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jTrCY-0004xF-CI; Wed, 29 Apr 2020 18:12:54 +0000 Received: from mail-qk1-x742.google.com ([2607:f8b0:4864:20::742]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jTrBi-0004Eg-L1 for linux-arm-kernel@lists.infradead.org; Wed, 29 Apr 2020 18:12:08 +0000 Received: by mail-qk1-x742.google.com with SMTP id q7so3011927qkf.3 for ; Wed, 29 Apr 2020 11:12:02 -0700 (PDT) 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=hMWCXFqPNvhEPK2mqnfUXlPJrRHb10i4WAvB8Ay5seM=; b=NiASIR5epbSYQoqxQVGjUsoqG8G0jHkYlF4feBMKDVP4OpQ11Yhl+1kcNG+CXJxfeT 5UmIU8IU50X8/ZyRtInxqtkzKzjNkdiHNHLkogEg+MpdpTBevW35ke7NoF7og5aRkX9a NPv9M85GFMpFyAqccR5TG8kyjkMsTPOqIo0qDP83UwFq1ox+dhoDnOPXWK1M/jf/R2OG 4VeuHXAHGMIC3bQnHeOaQnZLvIfJpdFVnCcl/2ao5+zrOL92CZ0f/cstLZRKcA895lXj in5g8/0f0nvk9z9gFKqE8qo7yHDc+Bjsm0id+n0SE6pGwkGF7fgPdvPERPkDzTukRZWc hoQw== 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=hMWCXFqPNvhEPK2mqnfUXlPJrRHb10i4WAvB8Ay5seM=; b=eOj0/oIvChg/hAqEnpvSglSxKQigyWiWIY7QwRnEV7Q5Pn8QfWS03e9ag2QNTCpSSm gQTL0HVo7dAMYypzYm759V5kKCj8FodwghobAXaPwDcaxME//G8Ho0wAkrdKMlRSOB13 cwDuIccOmKMFSLrolpGFoiH7wXQMCYsVWVPXHBy5YlPqVX3dQzSAjgltHGJLu4lzaxfk oIPmD3ow7rspr5DYZ5+iZDm6snLoq4WjPPvb5RVSqmcfbr4N5ELrZrcNLocjm4cEDUOU qjPYiYxbfZ26BufDUB3KopcGUzdF9xvNsd8yYvbr5IrhbRFDbB2FiQfyg4DDEtMg36jm 0TQw== X-Gm-Message-State: AGi0PuZPHEhz8/lL1bkhKUscT4HAVmbd5sfyfpiLLmgr2Qk4NFD/Bdrq Tv2n54mT7u7DHIGibTVJCbQ= X-Google-Smtp-Source: APiQypLUl+TCQbvawr5tyR/PVvF6bhqqY2tXYk0WasrdUDL3ChfUik6elCIEyq9X0z+rim1O0bGoaA== X-Received: by 2002:a05:620a:81b:: with SMTP id s27mr34579533qks.351.1588183920994; Wed, 29 Apr 2020 11:12:00 -0700 (PDT) Received: from localhost.localdomain (072-189-064-225.res.spectrum.com. [72.189.64.225]) by smtp.gmail.com with ESMTPSA id o43sm16315082qtf.46.2020.04.29.11.11.59 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 11:12:00 -0700 (PDT) From: William Breathitt Gray To: jic23@kernel.org Subject: [PATCH 3/4] counter: Add character device interface Date: Wed, 29 Apr 2020 14:11:37 -0400 Message-Id: <531bf7d00146c6f0cca3ce9a1492cb76ec3bc8f5.1588176662.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200429_111202_916586_DEB52C19 X-CRM114-Status: GOOD ( 16.78 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:742 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [vilhelm.gray[at]gmail.com] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kamel.bouhara@bootlin.com, gwendal@chromium.org, david@lechnology.com, felipe.balbi@linux.intel.com, linux-iio@vger.kernel.org, syednwaris@gmail.com, alexandre.belloni@bootlin.com, linux-kernel@vger.kernel.org, mcoquelin.stm32@gmail.com, patrick.havelange@essensium.com, William Breathitt Gray , fabrice.gasnier@st.com, fabien.lahoudere@collabora.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, alexandre.torgue@st.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This patch introduces a character device interface for the Counter subsystem. Device information and control is exposed through a standard set of ioctl commands. A high-level view of how a count value is passed down from a counter driver can be exemplified by the following: ---------------------- / Counter device \ +----------------------+ | Count register: 0x28 | +----------------------+ | ----------------- / raw count data / ----------------- | V +----------------------------+ | Counter device driver |----------+ +----------------------------+ | | Processes data from device | ------------------- |----------------------------| / driver callbacks / | Type: unsigned long | ------------------- | Value: 42 | | +----------------------------+ | | | ---------------- | / unsigned long / | ---------------- | | | | V | +----------------------+ | | Counter core | | +----------------------+ | | Routes device driver | | | callbacks to the | | | userspace interfaces | | +----------------------+ | | | ------------------- | / driver callbacks / | ------------------- | | +-------+---------------+ | | | | | +-------|-------+ | | | V | V +--------------------+ | +---------------------+ | Counter sysfs |<-+->| Counter chrdev | +--------------------+ +---------------------+ | Translates to the | | Translates to the | | standard Counter | | standard Counter | | sysfs output | | character device | |--------------------| |---------------------+ | Type: const char * | | Type: unsigned long | | Value: "42" | | Value: 42 | +--------------------+ +---------------------+ | | --------------- ---------------- / const char * / / unsigned long / --------------- ---------------- | | | V | +-----------+ | | ioctl | | +-----------+ | \ Count: 42 / | ----------- | V +--------------------------------------------------+ | `/sys/bus/counter/devices/counterX/countY/count` | +--------------------------------------------------+ \ Count: "42" / -------------------------------------------------- Signed-off-by: William Breathitt Gray --- MAINTAINERS | 1 + drivers/counter/Makefile | 3 +- drivers/counter/counter-chrdev.c | 1134 ++++++++++++++++++++++++++++++ drivers/counter/counter-chrdev.h | 16 + drivers/counter/counter-core.c | 34 +- include/linux/counter.h | 2 + include/uapi/linux/counter.h | 313 +++++++++ 7 files changed, 1500 insertions(+), 3 deletions(-) create mode 100644 drivers/counter/counter-chrdev.c create mode 100644 drivers/counter/counter-chrdev.h create mode 100644 include/uapi/linux/counter.h diff --git a/MAINTAINERS b/MAINTAINERS index 89def3fe1c76..b8c7677e6564 100644 --- a/MAINTAINERS +++ b/MAINTAINERS @@ -4367,6 +4367,7 @@ F: Documentation/ABI/testing/sysfs-bus-counter* F: Documentation/driver-api/generic-counter.rst F: drivers/counter/ F: include/linux/counter.h +F: include/uapi/linux/counter.h F: include/uapi/linux/counter-types.h CPMAC ETHERNET DRIVER diff --git a/drivers/counter/Makefile b/drivers/counter/Makefile index 2d2644bd7777..86a93100e3f6 100644 --- a/drivers/counter/Makefile +++ b/drivers/counter/Makefile @@ -4,7 +4,8 @@ # obj-$(CONFIG_COUNTER) += counter.o -counter-y := counter-core.o counter-sysfs.o counter-sysfs-callbacks.o +counter-y := counter-core.o counter-sysfs.o counter-sysfs-callbacks.o \ + counter-chrdev.o obj-$(CONFIG_104_QUAD_8) += 104-quad-8.o obj-$(CONFIG_STM32_TIMER_CNT) += stm32-timer-cnt.o diff --git a/drivers/counter/counter-chrdev.c b/drivers/counter/counter-chrdev.c new file mode 100644 index 000000000000..00b1d9f62527 --- /dev/null +++ b/drivers/counter/counter-chrdev.c @@ -0,0 +1,1134 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Generic Counter character device interface + * Copyright (C) 2020 William Breathitt Gray + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include "counter-function-types.h" + +static long counter_device_info_ioctl(const unsigned long arg, + const struct counter_device *const counter) +{ + struct counter_device_info info; + void __user *const uinfo = (void __user *)arg; + + snprintf(info.name, sizeof(info.name), "%s", counter->name); + info.num_signals = counter->num_signals; + info.num_counts = counter->num_counts; + info.num_ext = counter->num_ext; + + if (copy_to_user(uinfo, &info, sizeof(info))) + return -EFAULT; + + return 0; +} + +static long counter_signal_info_ioctl(const unsigned long arg, + const struct counter_device *const counter) +{ + struct counter_signal_info info; + void __user *const uinfo = (void __user *)arg; + const struct counter_signal *signal; + + if (copy_from_user(&info, uinfo, sizeof(info))) + return -EFAULT; + + if (info.index >= counter->num_signals) + return -EINVAL; + + signal = counter->signals + info.index; + + info.id = signal->id; + snprintf(info.name, sizeof(info.name), "%s", signal->name); + info.num_ext = signal->num_ext; + + if (copy_to_user(uinfo, &info, sizeof(info))) + return -EFAULT; + + return 0; +} + +static long counter_synapse_info_ioctl(const unsigned long arg, + const struct counter_device *const counter) +{ + struct counter_synapse_info info; + void __user *const uinfo = (void __user *)arg; + const struct counter_synapse *synapse; + + if (copy_from_user(&info, uinfo, sizeof(info))) + return -EFAULT; + + if (info.count_index >= counter->num_counts) + return -EINVAL; + + if (info.index >= counter->counts[info.count_index].num_synapses) + return -EINVAL; + + synapse = counter->counts[info.count_index].synapses + info.index; + + info.num_actions = synapse->num_actions; + info.signal_index = synapse->signal - counter->signals; + + if (copy_to_user(uinfo, &info, sizeof(info))) + return -EFAULT; + + return 0; +} + +static long counter_count_info_ioctl(const unsigned long arg, + const struct counter_device *const counter) +{ + struct counter_count_info info; + void __user *const uinfo = (void __user *)arg; + const struct counter_count *count; + + if (copy_from_user(&info, uinfo, sizeof(info))) + return -EFAULT; + + if (info.index >= counter->num_counts) + return -EINVAL; + + count = counter->counts + info.index; + + info.id = count->id; + snprintf(info.name, sizeof(info.name), "%s", count->name); + info.num_functions = count->num_functions; + info.num_synapses = count->num_synapses; + info.num_ext = count->num_ext; + + if (copy_to_user(uinfo, &info, sizeof(info))) + return -EFAULT; + + return 0; +} + +static const struct counter_data *counter_get_ext( + const enum counter_owner_type type, const size_t owner_index, + const size_t index, const struct counter_device *const counter) +{ + const struct counter_data *ext; + + switch (type) { + case COUNTER_OWNER_TYPE_DEVICE: + if (index >= counter->num_ext) + return ERR_PTR(-EINVAL); + + ext = counter->ext + index; + break; + case COUNTER_OWNER_TYPE_SIGNAL: + if (owner_index >= counter->num_signals) + return ERR_PTR(-EINVAL); + + if (index >= counter->signals[owner_index].num_ext) + return ERR_PTR(-EINVAL); + + ext = counter->signals[owner_index].ext + index; + break; + case COUNTER_OWNER_TYPE_COUNT: + if (owner_index >= counter->num_counts) + return ERR_PTR(-EINVAL); + + if (index >= counter->counts[owner_index].num_ext) + return ERR_PTR(-EINVAL); + + ext = counter->counts[owner_index].ext + index; + break; + default: + return ERR_PTR(-EINVAL); + } + + return ext; +} + +static long counter_ext_info_ioctl(const unsigned long arg, + const struct counter_device *const counter) +{ + struct counter_ext_info info; + void __user *const uinfo = (void __user *)arg; + const struct counter_data *ext; + + if (copy_from_user(&info, uinfo, sizeof(info))) + return -EFAULT; + + ext = counter_get_ext(info.owner_type, info.owner_index, info.index, + counter); + if (IS_ERR(ext)) + return PTR_ERR(ext); + + info.type = ext->type; + snprintf(info.name, sizeof(info.name), "%s", ext->name); + + if (copy_to_user(uinfo, &info, sizeof(info))) + return -EFAULT; + + return 0; +} + +static long counter_signal_get_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + const counter_signal_signal_read signal_read = counter->signal_read; + struct counter_signal_request req; + void __user *const ureq = (void __user *)arg; + int err; + + if (!signal_read) + return -EINVAL; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + if (req.index >= counter->num_signals) + return -EINVAL; + + err = signal_read(counter, counter->signals + req.index, &req.value); + if (err) + return err; + + if (copy_to_user(ureq, &req, sizeof(req))) + return -EFAULT; + + return 0; +} + +static long counter_count_get_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + const counter_count_lu_read count_read = counter->count_read; + struct counter_count_request req; + void __user *const ureq = (void __user *)arg; + int err; + + if (!count_read) + return -EINVAL; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + if (req.index >= counter->num_counts) + return -EINVAL; + + err = count_read(counter, counter->counts + req.index, &req.value); + if (err) + return err; + + if (copy_to_user(ureq, &req, sizeof(req))) + return -EFAULT; + + return 0; +} + +static long counter_count_set_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + const counter_count_lu_write count_write = counter->count_write; + struct counter_count_request req; + void __user *const ureq = (void __user *)arg; + int err; + + if (!count_write) + return -EINVAL; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + if (req.index >= counter->num_counts) + return -EINVAL; + + err = count_write(counter, counter->counts + req.index, req.value); + if (err) + return err; + + return 0; +} + +static long counter_count_function_get_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + const counter_count_function_read func_read = counter->function_read; + struct counter_count_function_request req; + void __user *const ureq = (void __user *)arg; + int err; + + if (!func_read) + return -EINVAL; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + if (req.index >= counter->num_counts) + return -EINVAL; + + err = func_read(counter, counter->counts + req.index, &req.function); + if (err) + return err; + + if (copy_to_user(ureq, &req, sizeof(req))) + return -EFAULT; + + return 0; +} + +static long counter_count_function_set_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + const counter_count_function_write func_write = counter->function_write; + struct counter_count_function_request req; + void __user *const ureq = (void __user *)arg; + struct counter_count *count; + size_t i; + int err; + + if (!func_write) + return -EINVAL; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + if (req.index >= counter->num_counts) + return -EINVAL; + + count = counter->counts + req.index; + + /* Find requested function mode */ + for (i = 0; i < count->num_functions; i++) + if (req.function == count->functions_list[i]) + break; + + /* If requested function mode is not found */ + if (i >= count->num_functions) + return -EINVAL; + + err = func_write(counter, count, req.function); + if (err) + return err; + + return 0; +} + +static long counter_synapse_action_get_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + const counter_synapse_action_read action_read = counter->action_read; + struct counter_synapse_action_request req; + void __user *const ureq = (void __user *)arg; + struct counter_count *count; + struct counter_synapse *synapse; + int err; + + if (!action_read) + return -EINVAL; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + if (req.count_index >= counter->num_counts) + return -EINVAL; + + count = counter->counts + req.count_index; + + if (req.index >= count->num_synapses) + return -EINVAL; + + synapse = count->synapses + req.index; + + err = action_read(counter, count, synapse, &req.action); + if (err) + return err; + + if (copy_to_user(ureq, &req, sizeof(req))) + return -EFAULT; + + return 0; +} + +static long counter_synapse_action_set_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + const counter_synapse_action_write action_write = counter->action_write; + struct counter_synapse_action_request req; + void __user *const ureq = (void __user *)arg; + struct counter_count *count; + struct counter_synapse *synapse; + size_t i; + int err; + + if (!action_write) + return -EINVAL; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + if (req.count_index >= counter->num_counts) + return -EINVAL; + + count = counter->counts + req.count_index; + + if (req.index >= count->num_synapses) + return -EINVAL; + + synapse = count->synapses + req.index; + + /* Find requested action mode */ + for (i = 0; i < synapse->num_actions; i++) + if (req.action == synapse->actions_list[i]) + break; + + /* If requested action mode is not found */ + if (i >= synapse->num_actions) + return -EINVAL; + + err = action_write(counter, count, synapse, req.action); + if (err) + return err; + + return 0; +} + +static long counter_count_function_info_ioctl(const unsigned long arg, + const struct counter_device *const counter) +{ + struct counter_count_function_info info; + void __user *const uinfo = (void __user *)arg; + const struct counter_count *count; + + if (copy_from_user(&info, uinfo, sizeof(info))) + return -EFAULT; + + if (info.count_index >= counter->num_counts) + return -EINVAL; + + count = counter->counts + info.count_index; + + if (info.index >= count->num_functions) + return -EINVAL; + + info.function = count->functions_list[info.index]; + + if (copy_to_user(uinfo, &info, sizeof(info))) + return -EFAULT; + + return 0; +} + +static long counter_synapse_action_info_ioctl(const unsigned long arg, + const struct counter_device *const counter) +{ + struct counter_synapse_action_info info; + void __user *const uinfo = (void __user *)arg; + const struct counter_count *count; + const struct counter_synapse *synapse; + + if (copy_from_user(&info, uinfo, sizeof(info))) + return -EFAULT; + + if (info.count_index >= counter->num_counts) + return -EINVAL; + + count = counter->counts + info.count_index; + + if (info.synapse_index >= count->num_synapses) + return -EINVAL; + + synapse = count->synapses + info.synapse_index; + + if (info.index >= synapse->num_actions) + return -EINVAL; + + info.action = synapse->actions_list[info.index]; + + if (copy_to_user(uinfo, &info, sizeof(info))) + return -EFAULT; + + return 0; +} + +static long counter_ext_bool_get_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + counter_device_bool_read device_bool_read; + counter_signal_bool_read signal_bool_read; + counter_count_bool_read count_bool_read; + struct counter_ext_bool_request req; + void __user *const ureq = (void __user *)arg; + const struct counter_data *ext; + int err = 0; + struct counter_count *count; + struct counter_signal *signal; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + ext = counter_get_ext(req.owner_type, req.owner_index, req.index, + counter); + if (IS_ERR(ext)) + return PTR_ERR(ext); + + if (!ext->read) + return -EINVAL; + + switch (req.owner_type) { + case COUNTER_OWNER_TYPE_DEVICE: + device_bool_read = ext->read; + err = device_bool_read(counter, &req.data); + break; + case COUNTER_OWNER_TYPE_SIGNAL: + signal_bool_read = ext->read; + signal = counter->signals + req.owner_index; + err = signal_bool_read(counter, signal, &req.data); + break; + case COUNTER_OWNER_TYPE_COUNT: + count_bool_read = ext->read; + count = counter->counts + req.owner_index; + err = count_bool_read(counter, count, &req.data); + break; + } + if (err) + return err; + + if (copy_to_user(ureq, &req, sizeof(req))) + return -EFAULT; + + return 0; +} + +static long counter_ext_bool_set_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + counter_device_bool_write device_bool_write; + counter_signal_bool_write signal_bool_write; + counter_count_bool_write count_bool_write; + struct counter_ext_bool_request req; + void __user *const ureq = (void __user *)arg; + const struct counter_data *ext; + int retval = 0; + struct counter_count *count; + struct counter_signal *signal; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + ext = counter_get_ext(req.owner_type, req.owner_index, req.index, + counter); + if (IS_ERR(ext)) + return PTR_ERR(ext); + + if (!ext->write) + return -EINVAL; + + switch (req.owner_type) { + case COUNTER_OWNER_TYPE_DEVICE: + device_bool_write = ext->write; + retval = device_bool_write(counter, req.data); + break; + case COUNTER_OWNER_TYPE_SIGNAL: + signal_bool_write = ext->write; + signal = counter->signals + req.owner_index; + retval = signal_bool_write(counter, signal, req.data); + break; + case COUNTER_OWNER_TYPE_COUNT: + count_bool_write = ext->write; + count = counter->counts + req.owner_index; + retval = count_bool_write(counter, count, req.data); + break; + } + + return retval; +} + +static long counter_ext_lu_get_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + counter_device_lu_read device_lu_read; + counter_signal_lu_read signal_lu_read; + counter_count_lu_read count_lu_read; + struct counter_ext_lu_request req; + void __user *const ureq = (void __user *)arg; + const struct counter_data *ext; + int err = 0; + struct counter_count *count; + struct counter_signal *signal; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + ext = counter_get_ext(req.owner_type, req.owner_index, req.index, + counter); + if (IS_ERR(ext)) + return PTR_ERR(ext); + + if (!ext->read) + return -EINVAL; + + switch (req.owner_type) { + case COUNTER_OWNER_TYPE_DEVICE: + device_lu_read = ext->read; + err = device_lu_read(counter, &req.data); + break; + case COUNTER_OWNER_TYPE_SIGNAL: + signal_lu_read = ext->read; + signal = counter->signals + req.owner_index; + err = signal_lu_read(counter, signal, &req.data); + break; + case COUNTER_OWNER_TYPE_COUNT: + count_lu_read = ext->read; + count = counter->counts + req.owner_index; + err = count_lu_read(counter, count, &req.data); + break; + } + if (err) + return err; + + if (copy_to_user(ureq, &req, sizeof(req))) + return -EFAULT; + + return 0; +} + +static long counter_ext_lu_set_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + counter_device_lu_write device_lu_write; + counter_signal_lu_write signal_lu_write; + counter_count_lu_write count_lu_write; + struct counter_ext_lu_request req; + void __user *const ureq = (void __user *)arg; + const struct counter_data *ext; + int retval = 0; + struct counter_count *count; + struct counter_signal *signal; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + ext = counter_get_ext(req.owner_type, req.owner_index, req.index, + counter); + if (IS_ERR(ext)) + return PTR_ERR(ext); + + if (!ext->write) + return -EINVAL; + + switch (req.owner_type) { + case COUNTER_OWNER_TYPE_DEVICE: + device_lu_write = ext->write; + retval = device_lu_write(counter, req.data); + break; + case COUNTER_OWNER_TYPE_SIGNAL: + signal_lu_write = ext->write; + signal = counter->signals + req.owner_index; + retval = signal_lu_write(counter, signal, req.data); + break; + case COUNTER_OWNER_TYPE_COUNT: + count_lu_write = ext->write; + count = counter->counts + req.owner_index; + retval = count_lu_write(counter, count, req.data); + break; + } + + return retval; +} + +static long counter_ext_string_get_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + counter_device_s_read device_s_read; + counter_signal_s_read signal_s_read; + counter_count_s_read count_s_read; + struct counter_ext_string_request req; + void __user *const ureq = (void __user *)arg; + const struct counter_data *ext; + ssize_t len = 0; + struct counter_count *count; + struct counter_signal *signal; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + ext = counter_get_ext(req.owner_type, req.owner_index, req.index, + counter); + if (IS_ERR(ext)) + return PTR_ERR(ext); + + if (!ext->read) + return -EINVAL; + + switch (req.owner_type) { + case COUNTER_OWNER_TYPE_DEVICE: + device_s_read = ext->read; + len = device_s_read(counter, req.data, sizeof(req.data)); + break; + case COUNTER_OWNER_TYPE_SIGNAL: + signal_s_read = ext->read; + signal = counter->signals + req.owner_index; + len = signal_s_read(counter, signal, req.data, + sizeof(req.data)); + break; + case COUNTER_OWNER_TYPE_COUNT: + count_s_read = ext->read; + count = counter->counts + req.owner_index; + len = count_s_read(counter, count, req.data, sizeof(req.data)); + break; + } + if (len < 0) + return len; + + if (copy_to_user(ureq, &req, sizeof(req))) + return -EFAULT; + + return 0; +} + +static long counter_ext_string_set_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + counter_device_s_write device_s_write; + counter_signal_s_write signal_s_write; + counter_count_s_write count_s_write; + struct counter_ext_string_request req; + void __user *const ureq = (void __user *)arg; + const struct counter_data *ext; + ssize_t len = 0; + struct counter_count *count; + struct counter_signal *signal; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + ext = counter_get_ext(req.owner_type, req.owner_index, req.index, + counter); + if (IS_ERR(ext)) + return PTR_ERR(ext); + + if (!ext->write) + return -EINVAL; + + switch (req.owner_type) { + case COUNTER_OWNER_TYPE_DEVICE: + device_s_write = ext->write; + len = device_s_write(counter, req.data, sizeof(req.data)); + break; + case COUNTER_OWNER_TYPE_SIGNAL: + signal_s_write = ext->write; + signal = counter->signals + req.owner_index; + len = signal_s_write(counter, signal, req.data, + sizeof(req.data)); + break; + case COUNTER_OWNER_TYPE_COUNT: + count_s_write = ext->write; + count = counter->counts + req.owner_index; + len = count_s_write(counter, count, req.data, sizeof(req.data)); + break; + } + if (len < 0) + return len; + + return 0; +} + +static long counter_ext_enum_get_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + counter_device_zu_read device_enum_read; + counter_signal_zu_read signal_enum_read; + counter_count_zu_read count_enum_read; + struct counter_ext_enum_request req; + void __user *const ureq = (void __user *)arg; + const struct counter_data *ext; + int err = 0; + size_t enum_index; + struct counter_count *count; + struct counter_signal *signal; + const struct counter_enum *cntr_enum; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + ext = counter_get_ext(req.owner_type, req.owner_index, req.index, + counter); + if (IS_ERR(ext)) + return PTR_ERR(ext); + + if (!ext->read) + return -EINVAL; + + switch (req.owner_type) { + case COUNTER_OWNER_TYPE_DEVICE: + device_enum_read = ext->read; + err = device_enum_read(counter, &enum_index); + break; + case COUNTER_OWNER_TYPE_SIGNAL: + signal_enum_read = ext->read; + signal = counter->signals + req.owner_index; + err = signal_enum_read(counter, signal, &enum_index); + break; + case COUNTER_OWNER_TYPE_COUNT: + count_enum_read = ext->read; + count = counter->counts + req.owner_index; + err = count_enum_read(counter, count, &enum_index); + break; + } + if (err) + return err; + + cntr_enum = ext->priv; + + if (enum_index >= cntr_enum->num_items) + return -EINVAL; + + req.enum_index = enum_index; + + if (copy_to_user(ureq, &req, sizeof(req))) + return -EFAULT; + + return 0; +} + +static long counter_ext_enum_set_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + counter_device_zu_write device_enum_write; + counter_signal_zu_write signal_enum_write; + counter_count_zu_write count_enum_write; + struct counter_ext_enum_request req; + void __user *const ureq = (void __user *)arg; + const struct counter_data *ext; + int retval = 0; + struct counter_count *count; + struct counter_signal *signal; + const struct counter_enum *cntr_enum; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + ext = counter_get_ext(req.owner_type, req.owner_index, req.index, + counter); + if (IS_ERR(ext)) + return PTR_ERR(ext); + + if (!ext->write) + return -EINVAL; + + cntr_enum = ext->priv; + if (req.enum_index >= cntr_enum->num_items) + return -EINVAL; + + switch (req.owner_type) { + case COUNTER_OWNER_TYPE_DEVICE: + device_enum_write = ext->write; + retval = device_enum_write(counter, req.enum_index); + break; + case COUNTER_OWNER_TYPE_SIGNAL: + signal_enum_write = ext->write; + signal = counter->signals + req.owner_index; + retval = signal_enum_write(counter, signal, req.enum_index); + break; + case COUNTER_OWNER_TYPE_COUNT: + count_enum_write = ext->write; + count = counter->counts + req.owner_index; + retval = count_enum_write(counter, count, req.enum_index); + break; + } + + return retval; +} + +static long counter_ext_enum_info_ioctl(const unsigned long arg, + const struct counter_device *const counter) +{ + struct counter_ext_enum_info info; + void __user *const uinfo = (void __user *)arg; + const struct counter_data *ext; + const struct counter_enum *cntr_enum; + + if (copy_from_user(&info, uinfo, sizeof(info))) + return -EFAULT; + + ext = counter_get_ext(info.owner_type, info.owner_index, info.ext_index, + counter); + if (IS_ERR(ext)) + return PTR_ERR(ext); + + cntr_enum = ext->priv; + + if (info.index >= cntr_enum->num_items) + return -EINVAL; + + snprintf(info.value, sizeof(info.value), "%s", + cntr_enum->items[info.index]); + + if (copy_to_user(uinfo, &info, sizeof(info))) + return -EFAULT; + + return 0; +} + +static long counter_count_direction_get_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + counter_count_direction_read count_direction_read; + struct counter_count_direction_request req; + void __user *const ureq = (void __user *)arg; + const struct counter_data *ext; + struct counter_count *count; + int err; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + ext = counter_get_ext(COUNTER_OWNER_TYPE_COUNT, req.count_index, + req.index, counter); + if (IS_ERR(ext)) + return PTR_ERR(ext); + + if (!ext->read) + return -EINVAL; + + count_direction_read = ext->read; + count = counter->counts + req.count_index; + err = count_direction_read(counter, count, &req.direction); + if (err) + return err; + + if (copy_to_user(ureq, &req, sizeof(req))) + return -EFAULT; + + return 0; +} + +static long counter_count_mode_get_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + counter_count_mode_read count_mode_read; + struct counter_count_mode_request req; + void __user *const ureq = (void __user *)arg; + const struct counter_data *ext; + struct counter_count *count; + int err; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + ext = counter_get_ext(COUNTER_OWNER_TYPE_COUNT, req.count_index, + req.index, counter); + if (IS_ERR(ext)) + return PTR_ERR(ext); + + if (!ext->read) + return -EINVAL; + + count_mode_read = ext->read; + count = counter->counts + req.count_index; + err = count_mode_read(counter, count, &req.count_mode); + if (err) + return err; + + if (copy_to_user(ureq, &req, sizeof(req))) + return -EFAULT; + + return 0; +} + +static long counter_count_mode_set_ioctl(const unsigned long arg, + struct counter_device *const counter) +{ + counter_count_mode_write count_mode_write; + struct counter_count_mode_request req; + void __user *const ureq = (void __user *)arg; + const struct counter_data *ext; + const struct counter_available *available; + const enum counter_count_mode *count_modes; + size_t i; + struct counter_count *count; + int err; + + if (copy_from_user(&req, ureq, sizeof(req))) + return -EFAULT; + + ext = counter_get_ext(COUNTER_OWNER_TYPE_COUNT, req.count_index, + req.index, counter); + if (IS_ERR(ext)) + return PTR_ERR(ext); + + if (!ext->write) + return -EINVAL; + + available = ext->priv; + count_modes = available->items; + + /* Find requested count mode */ + for (i = 0; i < available->num_items; i++) { + if (req.count_mode == count_modes[i]) + break; + } + /* If requested count mode not found */ + if (i >= available->num_items) + return -EINVAL; + + count_mode_write = ext->write; + count = counter->counts + req.count_index; + err = count_mode_write(counter, count, req.count_mode); + if (err) + return err; + + return 0; +} + +static long counter_count_mode_info_ioctl(const unsigned long arg, + const struct counter_device *const counter) +{ + struct counter_count_mode_info info; + void __user *const uinfo = (void __user *)arg; + const struct counter_data *ext; + const struct counter_available *available; + const enum counter_count_mode *count_modes; + + if (copy_from_user(&info, uinfo, sizeof(info))) + return -EFAULT; + + ext = counter_get_ext(COUNTER_OWNER_TYPE_COUNT, info.count_index, + info.ext_index, counter); + if (IS_ERR(ext)) + return PTR_ERR(ext); + + available = ext->priv; + + if (info.index >= available->num_items) + return -EINVAL; + + count_modes = available->items; + info.count_mode = count_modes[info.index]; + + if (copy_to_user(uinfo, &info, sizeof(info))) + return -EFAULT; + + return 0; +} + +static long counter_chrdev_ioctl(struct file *filp, unsigned int cmd, + unsigned long arg) +{ + struct counter_device *const counter = filp->private_data; + + switch (cmd) { + case COUNTER_DEVICE_INFO_IOCTL: + return counter_device_info_ioctl(arg, counter); + case COUNTER_SIGNAL_INFO_IOCTL: + return counter_signal_info_ioctl(arg, counter); + case COUNTER_SYNAPSE_INFO_IOCTL: + return counter_synapse_info_ioctl(arg, counter); + case COUNTER_COUNT_INFO_IOCTL: + return counter_count_info_ioctl(arg, counter); + case COUNTER_EXT_INFO_IOCTL: + return counter_ext_info_ioctl(arg, counter); + case COUNTER_SIGNAL_GET_IOCTL: + return counter_signal_get_ioctl(arg, counter); + case COUNTER_COUNT_GET_IOCTL: + return counter_count_get_ioctl(arg, counter); + case COUNTER_COUNT_SET_IOCTL: + return counter_count_set_ioctl(arg, counter); + case COUNTER_COUNT_FUNCTION_GET_IOCTL: + return counter_count_function_get_ioctl(arg, counter); + case COUNTER_COUNT_FUNCTION_SET_IOCTL: + return counter_count_function_set_ioctl(arg, counter); + case COUNTER_SYNAPSE_ACTION_GET_IOCTL: + return counter_synapse_action_get_ioctl(arg, counter); + case COUNTER_SYNAPSE_ACTION_SET_IOCTL: + return counter_synapse_action_set_ioctl(arg, counter); + case COUNTER_COUNT_FUNCTION_INFO_IOCTL: + return counter_count_function_info_ioctl(arg, counter); + case COUNTER_SYNAPSE_ACTION_INFO_IOCTL: + return counter_synapse_action_info_ioctl(arg, counter); + case COUNTER_EXT_BOOL_GET_IOCTL: + return counter_ext_bool_get_ioctl(arg, counter); + case COUNTER_EXT_BOOL_SET_IOCTL: + return counter_ext_bool_set_ioctl(arg, counter); + case COUNTER_EXT_LU_GET_IOCTL: + return counter_ext_lu_get_ioctl(arg, counter); + case COUNTER_EXT_LU_SET_IOCTL: + return counter_ext_lu_set_ioctl(arg, counter); + case COUNTER_EXT_STRING_GET_IOCTL: + return counter_ext_string_get_ioctl(arg, counter); + case COUNTER_EXT_STRING_SET_IOCTL: + return counter_ext_string_set_ioctl(arg, counter); + case COUNTER_EXT_ENUM_GET_IOCTL: + return counter_ext_enum_get_ioctl(arg, counter); + case COUNTER_EXT_ENUM_SET_IOCTL: + return counter_ext_enum_set_ioctl(arg, counter); + case COUNTER_EXT_ENUM_INFO_IOCTL: + return counter_ext_enum_info_ioctl(arg, counter); + case COUNTER_COUNT_DIRECTION_GET_IOCTL: + return counter_count_direction_get_ioctl(arg, counter); + case COUNTER_COUNT_MODE_GET_IOCTL: + return counter_count_mode_get_ioctl(arg, counter); + case COUNTER_COUNT_MODE_SET_IOCTL: + return counter_count_mode_set_ioctl(arg, counter); + case COUNTER_COUNT_MODE_INFO_IOCTL: + return counter_count_mode_info_ioctl(arg, counter); + default: + break; + } + + return -ENOIOCTLCMD; +} + +static int counter_chrdev_open(struct inode *inode, struct file *filp) +{ + struct counter_device *const counter = container_of(inode->i_cdev, + struct counter_device, + chrdev); + + get_device(&counter->dev); + filp->private_data = counter; + + return nonseekable_open(inode, filp); +} + +static int counter_chrdev_release(struct inode *inode, struct file *filp) +{ + struct counter_device *const counter = container_of(inode->i_cdev, + struct counter_device, + chrdev); + + put_device(&counter->dev); + + return 0; +} + +static const struct file_operations counter_fops = { + .llseek = no_llseek, + .unlocked_ioctl = counter_chrdev_ioctl, + .open = counter_chrdev_open, + .release = counter_chrdev_release, +}; + +int counter_chrdev_add(struct counter_device *const counter, + const dev_t counter_devt) +{ + struct device *const dev = &counter->dev; + struct cdev *const chrdev = &counter->chrdev; + + cdev_init(chrdev, &counter_fops); + dev->devt = MKDEV(MAJOR(counter_devt), counter->id); + cdev_set_parent(chrdev, &dev->kobj); + + return cdev_add(chrdev, dev->devt, 1); +} + +void counter_chrdev_free(struct counter_device *const counter) +{ + cdev_del(&counter->chrdev); +} diff --git a/drivers/counter/counter-chrdev.h b/drivers/counter/counter-chrdev.h new file mode 100644 index 000000000000..7ab0797d3857 --- /dev/null +++ b/drivers/counter/counter-chrdev.h @@ -0,0 +1,16 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Counter character device interface + * Copyright (C) 2020 William Breathitt Gray + */ +#ifndef _COUNTER_CHRDEV_H_ +#define _COUNTER_CHRDEV_H_ + +#include +#include + +int counter_chrdev_add(struct counter_device *const counter, + const dev_t counter_devt); +void counter_chrdev_free(struct counter_device *const counter); + +#endif /* _COUNTER_CHRDEV_H_ */ diff --git a/drivers/counter/counter-core.c b/drivers/counter/counter-core.c index 008d51284a2c..a345d3273ccd 100644 --- a/drivers/counter/counter-core.c +++ b/drivers/counter/counter-core.c @@ -7,12 +7,15 @@ #include #include #include +#include #include #include #include #include #include +#include +#include "counter-chrdev.h" #include "counter-sysfs.h" /* Provides a unique ID for each counter device */ @@ -36,6 +39,8 @@ static struct bus_type counter_bus_type = { .name = "counter" }; +static dev_t counter_devt; + /** * counter_register - register Counter to the system * @counter: pointer to Counter to register @@ -65,10 +70,15 @@ int counter_register(struct counter_device *const counter) device_initialize(dev); dev_set_drvdata(dev, counter); + /* Add Counter character device */ + err = counter_chrdev_add(counter, counter_devt); + if (err) + goto err_free_id; + /* Add Counter sysfs attributes */ err = counter_sysfs_add(counter); if (err) - goto err_free_id; + goto err_free_chrdev; /* Add device to system */ err = device_add(dev); @@ -79,6 +89,8 @@ int counter_register(struct counter_device *const counter) err_free_sysfs: counter_sysfs_free(counter); +err_free_chrdev: + counter_chrdev_free(counter); err_free_id: ida_simple_remove(&counter_ida, counter->id); return err; @@ -96,6 +108,7 @@ void counter_unregister(struct counter_device *const counter) if (counter) { device_del(&counter->dev); counter_sysfs_free(counter); + counter_chrdev_free(counter); } } EXPORT_SYMBOL_GPL(counter_unregister); @@ -172,13 +185,30 @@ void devm_counter_unregister(struct device *dev, } EXPORT_SYMBOL_GPL(devm_counter_unregister); +#define COUNTER_DEV_MAX 256 + static int __init counter_init(void) { - return bus_register(&counter_bus_type); + int err; + + err = bus_register(&counter_bus_type); + if (err < 0) + return err; + + err = alloc_chrdev_region(&counter_devt, 0, COUNTER_DEV_MAX, "counter"); + if (err < 0) + goto err_unregister_bus; + + return 0; + +err_unregister_bus: + bus_unregister(&counter_bus_type); + return err; } static void __exit counter_exit(void) { + unregister_chrdev_region(counter_devt, COUNTER_DEV_MAX); bus_unregister(&counter_bus_type); } diff --git a/include/linux/counter.h b/include/linux/counter.h index d628c7eaf754..2ae361b4734c 100644 --- a/include/linux/counter.h +++ b/include/linux/counter.h @@ -6,6 +6,7 @@ #ifndef _COUNTER_H_ #define _COUNTER_H_ +#include #include #include #include @@ -162,6 +163,7 @@ struct counter_device { int id; struct device dev; + struct cdev chrdev; struct list_head synapse_names_list; struct counter_attribute_group *groups_list; size_t num_groups; diff --git a/include/uapi/linux/counter.h b/include/uapi/linux/counter.h new file mode 100644 index 000000000000..7e4b1f158d57 --- /dev/null +++ b/include/uapi/linux/counter.h @@ -0,0 +1,313 @@ +/* SPDX-License-Identifier: GPL-2.0 WITH Linux-syscall-note */ +/* + * Userspace ABI for Counter character devices + * Copyright (C) 2020 William Breathitt Gray + */ +#ifndef _UAPI_COUNTER_H_ +#define _UAPI_COUNTER_H_ + +#include +#include +#include + +/** + * struct counter_device_info - Counter device information + * @name: name of the device + * @num_signals: number of Signals + * @num_counts: number of Counts + * @num_ext: number of Counter device extensions + */ +struct counter_device_info { + char name[32]; + size_t num_signals; + size_t num_counts; + size_t num_ext; +}; + +/** + * struct counter_signal_info - Signal information + * @index: index of the Signal + * @id: unique ID used to identify the Signal + * @name: device-specific Signal name + * @num_ext: number of Signal extensions + */ +struct counter_signal_info { + size_t index; + + int id; + char name[32]; + size_t num_ext; +}; + +/** + * struct counter_synapse_info - Synapse information + * @count_index: index of the Count + * @index: index of the Synapse + * @num_actions: number of action modes + * @signal_index: index of the associated Signal + */ +struct counter_synapse_info { + size_t count_index; + size_t index; + + size_t num_actions; + size_t signal_index; +}; + +/** + * struct counter_count_info - Count information + * @index: index of the Count + * @id: unique ID used to identify Count + * @name: device-specific Count name + * @num_functions: number of function modes + * @num_synapses: number of synapses + * @num_ext: number of Count extensions + */ +struct counter_count_info { + size_t index; + + int id; + char name[32]; + size_t num_functions; + size_t num_synapses; + size_t num_ext; +}; + +/** + * struct counter_ext_info - Counter extension information + * @owner_type: component type of the owner + * @owner_index: index of the owning Count or Signal + * @index: index of the extension + * @type: data type of the extension + * @name: name of the extension + */ +struct counter_ext_info { + enum counter_owner_type owner_type; + size_t owner_index; + size_t index; + + enum counter_data_type type; + char name[32]; +}; + +/** + * struct counter_signal_request - Signal request + * @index: index of the Signal + * @value: Signal value + */ +struct counter_signal_request { + size_t index; + + enum counter_signal_value value; +}; + +/** + * struct counter_count_request - Count request + * @index: index of the Count + * @value: Count value + */ +struct counter_count_request { + size_t index; + + unsigned long value; +}; + +/** + * struct counter_count_function_request - Count function mode request + * @index: index of the Count + * @function: Count function mode + */ +struct counter_count_function_request { + size_t index; + + enum counter_count_function function; +}; + +/** + * struct counter_synapse_action_request - Synapse action mode request + * @count_index: index of the Count + * @index: index of the Synapse + * @action: Synapse action mode + */ +struct counter_synapse_action_request { + size_t count_index; + size_t index; + + enum counter_synapse_action action; +}; + +/** + * struct counter_count_function_info - Count function mode information + * @count_index: index of the Count + * @index: index of the Count function mode + * @function: Count function mode + */ +struct counter_count_function_info { + size_t count_index; + size_t index; + + enum counter_count_function function; +}; + +/** + * struct counter_synapse_action_info - Synapse action mode information + * @count_index: index of the Count + * @synapse_index: index of the Synapse + * @index: index of the Synapse action mode + * @action: Synapse action mode + */ +struct counter_synapse_action_info { + size_t count_index; + size_t synapse_index; + size_t index; + + enum counter_synapse_action action; +}; + +/** + * struct counter_ext_bool_request - Counter extension bool data request + * @owner_type: component type of the owner + * @owner_index: index of the owning Count or Signal + * @index: index of the extension + * @data: extension data + */ +struct counter_ext_bool_request { + enum counter_owner_type owner_type; + size_t owner_index; + size_t index; + + bool data; +}; + +/** + * struct counter_ext_lu_request - Counter extension unsigned long data request + * @owner_type: component type of the owner + * @owner_index: index of the owning Count or Signal + * @index: index of the extension + * @data: extension data + */ +struct counter_ext_lu_request { + enum counter_owner_type owner_type; + size_t owner_index; + size_t index; + + unsigned long data; +}; + +/** + * struct counter_ext_string_request - Counter extension string data request + * @owner_type: component type of the owner + * @owner_index: index of the owning Count or Signal + * @index: index of the extension + * @data: extension data + */ +struct counter_ext_string_request { + enum counter_owner_type owner_type; + size_t owner_index; + size_t index; + + char data[32]; +}; + +/** + * struct counter_ext_enum_request - Counter extension enum request + * @owner_type: component type of the owner + * @owner_index: index of the owning Count or Signal + * @index: index of the extension + * @enum_index: index of the extension enum + */ +struct counter_ext_enum_request { + enum counter_owner_type owner_type; + size_t owner_index; + size_t index; + + size_t enum_index; +}; + +/** + * struct counter_ext_enum_info - Counter extension enum information + * @owner_type: component type of the owner + * @owner_index: index of the owning Count or Signal + * @ext_index: index of the extension + * @index: index of the extension enum + * @data: extension enum value + */ +struct counter_ext_enum_info { + enum counter_owner_type owner_type; + size_t owner_index; + size_t ext_index; + size_t index; + + char value[32]; +}; + +/** + * struct counter_count_direction_request - Counter count direction request + * @count_index: index of the Count + * @index: index of the extension + * @direction: Count direction + */ +struct counter_count_direction_request { + size_t count_index; + size_t index; + + enum counter_count_direction direction; +}; + +/** + * struct counter_count_mode_request - Counter count mode request + * @count_index: index of the Count + * @index: index of the extension + * @count_mode: count mode + */ +struct counter_count_mode_request { + size_t count_index; + size_t index; + + enum counter_count_mode count_mode; +}; + +/** + * struct counter_count_mode_info - Counter count mode information + * @count_index: index of the Count + * @ext_index: index of the extension + * @index: index of the count mode + * @count_mode: count mode + */ +struct counter_count_mode_info { + size_t count_index; + size_t ext_index; + size_t index; + + enum counter_count_mode count_mode; +}; + +#define COUNTER_DEVICE_INFO_IOCTL _IOR(0x3E, 0x00, struct counter_device_info) +#define COUNTER_SIGNAL_INFO_IOCTL _IOWR(0x3E, 0x01, struct counter_signal_info) +#define COUNTER_SYNAPSE_INFO_IOCTL _IOWR(0x3E, 0x02, struct counter_synapse_info) +#define COUNTER_COUNT_INFO_IOCTL _IOWR(0x3E, 0x03, struct counter_count_info) +#define COUNTER_EXT_INFO_IOCTL _IOWR(0x3E, 0x04, struct counter_ext_info) +#define COUNTER_SIGNAL_GET_IOCTL _IOWR(0x3E, 0x05, struct counter_signal_request) +#define COUNTER_COUNT_GET_IOCTL _IOWR(0x3E, 0x06, struct counter_count_request) +#define COUNTER_COUNT_SET_IOCTL _IOW(0x3E, 0x07, struct counter_count_request) +#define COUNTER_COUNT_FUNCTION_GET_IOCTL _IOWR(0x3E, 0x08, struct counter_count_function_request) +#define COUNTER_COUNT_FUNCTION_SET_IOCTL _IOW(0x3E, 0x09, struct counter_count_function_request) +#define COUNTER_SYNAPSE_ACTION_GET_IOCTL _IOWR(0x3E, 0x0A, struct counter_synapse_action_request) +#define COUNTER_SYNAPSE_ACTION_SET_IOCTL _IOW(0x3E, 0x0B, struct counter_synapse_action_request) +#define COUNTER_COUNT_FUNCTION_INFO_IOCTL _IOWR(0x3E, 0x0C, struct counter_count_function_info) +#define COUNTER_SYNAPSE_ACTION_INFO_IOCTL _IOWR(0x3E, 0x0D, struct counter_synapse_action_info) +#define COUNTER_EXT_BOOL_GET_IOCTL _IOWR(0x3E, 0x0E, struct counter_ext_bool_request) +#define COUNTER_EXT_BOOL_SET_IOCTL _IOW(0x3E, 0x0F, struct counter_ext_bool_request) +#define COUNTER_EXT_LU_GET_IOCTL _IOWR(0x3E, 0x10, struct counter_ext_lu_request) +#define COUNTER_EXT_LU_SET_IOCTL _IOW(0x3E, 0x11, struct counter_ext_lu_request) +#define COUNTER_EXT_STRING_GET_IOCTL _IOWR(0x3E, 0x12, struct counter_ext_string_request) +#define COUNTER_EXT_STRING_SET_IOCTL _IOW(0x3E, 0x13, struct counter_ext_string_request) +#define COUNTER_EXT_ENUM_GET_IOCTL _IOWR(0x3E, 0x14, struct counter_ext_enum_request) +#define COUNTER_EXT_ENUM_SET_IOCTL _IOW(0x3E, 0x15, struct counter_ext_enum_request) +#define COUNTER_EXT_ENUM_INFO_IOCTL _IOWR(0x3E, 0x16, struct counter_ext_enum_info) +#define COUNTER_COUNT_DIRECTION_GET_IOCTL _IOWR(0x3E, 0x17, struct counter_count_direction_request) +#define COUNTER_COUNT_MODE_GET_IOCTL _IOWR(0x3E, 0x18, struct counter_count_mode_request) +#define COUNTER_COUNT_MODE_SET_IOCTL _IOW(0x3E, 0x19, struct counter_count_mode_request) +#define COUNTER_COUNT_MODE_INFO_IOCTL _IOWR(0x3E, 0x1A, struct counter_count_mode_info) + +#endif /* _UAPI_COUNTER_H_ */ From patchwork Wed Apr 29 18:11:38 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: William Breathitt Gray X-Patchwork-Id: 11518081 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id C7A8C14DD for ; Wed, 29 Apr 2020 18:12:41 +0000 (UTC) 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 mail.kernel.org (Postfix) with ESMTPS id A631221973 for ; Wed, 29 Apr 2020 18:12:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="DiEFjeKj"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="p4WsQDKV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org A631221973 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=gmail.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=Ytyxyhjr9YVyj4VY5bCC4bbnmiB2tbqs2f9OcPQYvIg=; b=DiEFjeKjigxy5N 0ocickK7fD0WO2VK7ccKS0TA5TiNpNoRw2rkf0M2JUsZ+hBiLLT9yl6cnXKxSrJPreYszUCnRmzer 3YASDrBBo0I5DHeCMjgcgcLCd1g+X1qs1+FI1PZ+Rw70FDenfZpS7JNRtt2TCRRQ8FIoRdJZEveLY /J3LvPl/1uhYxTqRCSWYLkFCCh7Nhq2epf4ZapdU87rJhFYWv4O/UenFi+ZbeWsPwQWtDE5HNNoUp k5D57Llq5TOjXPuHT5HFlZvspM7E4eDtB338mDNKBw54lZ5zkEwSxxeSQdj6lb0+9iY0W2rXnQyab lvgVr/I7361rICsB6YwQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1jTrCH-0004i6-Vt; Wed, 29 Apr 2020 18:12:38 +0000 Received: from mail-qt1-x844.google.com ([2607:f8b0:4864:20::844]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1jTrBk-0004Ft-1Z for linux-arm-kernel@lists.infradead.org; Wed, 29 Apr 2020 18:12:06 +0000 Received: by mail-qt1-x844.google.com with SMTP id v26so2718438qto.0 for ; Wed, 29 Apr 2020 11:12:03 -0700 (PDT) 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=2tsSqdNWnb3CiuOvg96gs7sg5rhYKvwHlBRsWbohoX4=; b=p4WsQDKVxAz07MQA8hvDDKFPZMOxcFuvPUKCfaz8nY2dZ7WnmYgSOoDOobts8uWuvo ZIcaaUm1ApaCNIvFdCdSbVP3+b4Qc6Xn23PTrLU9ul80cxZdoD02Ok2mE1EIMRIHJJXI yjExhQiHAHJg8SjYdCjE3cSHxPBoeMhEWCxsqJy64KziBdBvPyFIL2u7/RNmhnKXp+bv WTASNdkj+S4YmcGpI3V//KYIg/zkKVb+FuBQwALXWhCKmRTbslaW+HTZa98NStwz4dOi RkXlsx9MfonxSRxhbh0nh5F/kD1T0obPNRx34CvhmcVOTjjZZtbr+b/lHgijj5fe9fq0 NN1g== 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=2tsSqdNWnb3CiuOvg96gs7sg5rhYKvwHlBRsWbohoX4=; b=r9enJj+dZvAc3CJecexSKO9/Ynwi5FLKe//kTZjI09ju5zHCfJX3Jb1td0YJJrE1Q4 GFbzZOheX2QauQ/oGbnWX9f0ZwPUddZPp8U2vwz0VzCJYdpt5DuhfDzHFdzS3VYl186t swuBJjTb/XjIm+1k9FFra4FrefefyYuBzSVWbFMvY7AS+CTkPn2eP7PGmcpYK5A58TO9 bgdrYQWG+CaVpwtsHAb/O+FBPn2e9VNDq/xIlZHvdF8RIlwZKk/BW6D44hQXPD0KhSuq 1Lr7L9neGKUPDI2wqb3Y8fEsiMDw5fH/T9VLwOU92WP0l9LjbdTuM1yClsuxkqQjwlri C40Q== X-Gm-Message-State: AGi0PuZGLTtkfTw/7jSM9raTFljcDAAAq0LsB8pNMvAk+ONzJLOJIbj7 ahiRKCvlEqoSRXVzThwzhW4= X-Google-Smtp-Source: APiQypKY8OpPGQ+A02xX2a1aWXbNyQ9A0dh8ssyUBdOY9769gG4lAy9hnA/fuVUNNmetqVHdZBDzeg== X-Received: by 2002:aed:2766:: with SMTP id n93mr35352318qtd.130.1588183922632; Wed, 29 Apr 2020 11:12:02 -0700 (PDT) Received: from localhost.localdomain (072-189-064-225.res.spectrum.com. [72.189.64.225]) by smtp.gmail.com with ESMTPSA id o43sm16315082qtf.46.2020.04.29.11.12.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 29 Apr 2020 11:12:01 -0700 (PDT) From: William Breathitt Gray To: jic23@kernel.org Subject: [PATCH 4/4] docs: counter: Document character device interface Date: Wed, 29 Apr 2020 14:11:38 -0400 Message-Id: <639b231a155fee0b1786aafb441f61e8094dcf75.1588176662.git.vilhelm.gray@gmail.com> X-Mailer: git-send-email 2.26.2 In-Reply-To: References: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20200429_111204_107097_358E974B X-CRM114-Status: GOOD ( 12.06 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.4 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [2607:f8b0:4864:20:0:0:0:844 listed in] [list.dnswl.org] -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record 0.0 FREEMAIL_FROM Sender email is commonly abused enduser mail provider [vilhelm.gray[at]gmail.com] 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: kamel.bouhara@bootlin.com, gwendal@chromium.org, david@lechnology.com, felipe.balbi@linux.intel.com, linux-iio@vger.kernel.org, syednwaris@gmail.com, alexandre.belloni@bootlin.com, linux-kernel@vger.kernel.org, mcoquelin.stm32@gmail.com, patrick.havelange@essensium.com, William Breathitt Gray , fabrice.gasnier@st.com, fabien.lahoudere@collabora.com, linux-stm32@st-md-mailman.stormreply.com, linux-arm-kernel@lists.infradead.org, alexandre.torgue@st.com Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This patch adds high-level documentation about the Counter subsystem character device interface. The 0x3E major number and respective minor number range is reserved for Counter character device interface ioctl calls. Signed-off-by: William Breathitt Gray --- Documentation/driver-api/generic-counter.rst | 87 ++++++++++++------- .../userspace-api/ioctl/ioctl-number.rst | 1 + 2 files changed, 56 insertions(+), 32 deletions(-) diff --git a/Documentation/driver-api/generic-counter.rst b/Documentation/driver-api/generic-counter.rst index 3ab8125b9c05..959c4074078c 100644 --- a/Documentation/driver-api/generic-counter.rst +++ b/Documentation/driver-api/generic-counter.rst @@ -223,19 +223,6 @@ whether an input line is differential or single-ended) and instead focus on the core idea of what the data and process represent (e.g. position as interpreted from quadrature encoding data). -Userspace Interface -=================== - -Several sysfs attributes are generated by the Generic Counter interface, -and reside under the /sys/bus/counter/devices/counterX directory, where -counterX refers to the respective counter device. Please see -Documentation/ABI/testing/sysfs-bus-counter for detailed -information on each Generic Counter interface sysfs attribute. - -Through these sysfs attributes, programs and scripts may interact with -the Generic Counter paradigm Counts, Signals, and Synapses of respective -counter devices. - Driver API ========== @@ -409,25 +396,32 @@ driver can be exemplified by the following:: | / driver callbacks / | ------------------- | | - +-------+ | + +-------+---------------+ | + | | | + | +-------|-------+ + | | | + V | V + +--------------------+ | +---------------------+ + | Counter sysfs |<-+->| Counter chrdev | + +--------------------+ +---------------------+ + | Translates to the | | Translates to the | + | standard Counter | | standard Counter | + | sysfs output | | character device | + |--------------------| |---------------------+ + | Type: const char * | | Type: unsigned long | + | Value: "42" | | Value: 42 | + +--------------------+ +---------------------+ | | - | +---------------+ - | | - V | - +--------------------+ | - | Counter sysfs |<-+ - +--------------------+ - | Translates to the | - | standard Counter | - | sysfs output | - |--------------------| - | Type: const char * | - | Value: "42" | - +--------------------+ - | - --------------- - / const char * / - --------------- + --------------- ---------------- + / const char * / / unsigned long / + --------------- ---------------- + | | + | V + | +-----------+ + | | ioctl | + | +-----------+ + | \ Count: 42 / + | ----------- | V +--------------------------------------------------+ @@ -436,7 +430,7 @@ driver can be exemplified by the following:: \ Count: "42" / -------------------------------------------------- -There are three primary components involved: +There are four primary components involved: Counter device driver --------------------- @@ -456,3 +450,32 @@ and vice versa. Please refer to the `Documentation/ABI/testing/sysfs-bus-counter` file for a detailed breakdown of the available Generic Counter interface sysfs attributes. + +Counter chrdev +-------------- +Translates counter data to the standard Counter character device; data +is transferred via ioctl calls. + +Sysfs Interface +=============== + +Several sysfs attributes are generated by the Generic Counter interface, +and reside under the `/sys/bus/counter/devices/counterX` directory, +where `X` is to the respective counter device id. Please see +Documentation/ABI/testing/sysfs-bus-counter for detailed information on +each Generic Counter interface sysfs attribute. + +Through these sysfs attributes, programs and scripts may interact with +the Generic Counter paradigm Counts, Signals, and Synapses of respective +counter devices. + +Counter Character Device +======================== + +Counter character device nodes are created under the `/dev` directory as +`counterX`, where `X` is the respective counter device id. Device +information and control is exposed via a set of standard Counter +subsystem ioctl commands. + +.. kernel-doc:: include/uapi/linux/counter.h + :internal: diff --git a/Documentation/userspace-api/ioctl/ioctl-number.rst b/Documentation/userspace-api/ioctl/ioctl-number.rst index f759edafd938..8136a26fb81c 100644 --- a/Documentation/userspace-api/ioctl/ioctl-number.rst +++ b/Documentation/userspace-api/ioctl/ioctl-number.rst @@ -88,6 +88,7 @@ Code Seq# Include File Comments 0x20 all drivers/cdrom/cm206.h 0x22 all scsi/sg.h +0x3E 00-1F linux/counter.h '!' 00-1F uapi/linux/seccomp.h '#' 00-3F IEEE 1394 Subsystem Block for the entire subsystem