From patchwork Tue Dec 10 15:37:29 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitor Soares X-Patchwork-Id: 11282833 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 31044112B for ; Tue, 10 Dec 2019 15:37:43 +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 0E5802077B for ; Tue, 10 Dec 2019 15:37:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="q/Pkpean"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="YDPKO9wz" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0E5802077B Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=synopsys.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=Gel5XmcjWVHo96iFqwspsUQ31XNcvW8UqHtnE51kV00=; b=q/PkpeanLi4MrQ2jMZWBfMP0tA j41qR7mZJx+8wm2mdIfHscD4KIqEXqImp6ggSlCXFP4qJugCENumXvvlxxlgD4evBepL02mBMv9M/ /VdW3U5B6PszG56INpUKgVd1FDrm636jt5RqQvdB1BLv1AUWjxg5twWy23hfbC65RovZlMli35JKD PVDkLzhq6MjGN6glPYco7h3K4PAURDacbO+KLKjMoVtFga9evm3/cDaDEYkgJ0Qx7zHcMVJzCRTqK RCRlBACp9H1TgxTmBjYlExmjsKh8fAN0ZyyJAle6UYqj07oweNl2gaQy1kasdT8wmQuUcmaggAsgM qRDjrR9Q==; 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 1ieha2-0003wW-Ju; Tue, 10 Dec 2019 15:37:42 +0000 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iehZz-0003qN-RR for linux-i3c@lists.infradead.org; Tue, 10 Dec 2019 15:37:41 +0000 Received: from mailhost.synopsys.com (mdc-mailhost2.synopsys.com [10.225.0.210]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 8A2B9C00BC; Tue, 10 Dec 2019 15:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1575992259; bh=wCGz21uv5jylmEZ0nnnjoDbbVduGA33/JL1HaoI4a4g=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=YDPKO9wzoyy39bw6iC7+R76kinU7HKu9ki7xlgNpkouzr6ES2FCtj56iRAgaPfe+Q ZIR9oIHNjzEildKY/ywHeHs4otRepS3e4WCOEoqPV8vXSYNRDhDqLJGEppwH5Yy6VB KVRXF+mk1PhEcJQURZ12MKLYx/Z7ZFQHLFAI7YCEI6ylywYo2x+5ZJaJrlANuH0DYO gEC24w6H1pFeGejXf+E77nQiAcdVTuPCXd3o3+ufxOKvtSHO6winoIcUFnljbJ4pDW uNDmuelsw1zoLpVCyB1kMDpGpv/ZhkUTZA65gGNilmn4Kg9m0KnemZh+5o3ZAAqny8 kzDPkFLhAHmqQ== Received: from de02.synopsys.com (de02.internal.synopsys.com [10.225.17.21]) by mailhost.synopsys.com (Postfix) with ESMTP id 96528A0062; Tue, 10 Dec 2019 15:37:36 +0000 (UTC) Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by de02.synopsys.com (Postfix) with ESMTP id 6D4D23E2D0; Tue, 10 Dec 2019 16:37:36 +0100 (CET) From: Vitor Soares To: linux-kernel@vger.kernel.org, linux-i3c@lists.infradead.org Subject: [RFC 1/5] i3c: master: export i3c_masterdev_type Date: Tue, 10 Dec 2019 16:37:29 +0100 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191210_073739_933635_9B3A2B27 X-CRM114-Status: GOOD ( 11.28 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux I3C List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joao.Pinto@synopsys.com, arnd@arndb.de, wsa@the-dreams.de, gregkh@linuxfoundation.org, bbrezillon@kernel.org, Vitor Soares , broonie@kernel.org MIME-Version: 1.0 Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org Export i3c_masterdev_type symbol so i3cdev module can verify if an i3c device is a master device. Signed-off-by: Vitor Soares --- drivers/i3c/internals.h | 1 + drivers/i3c/master.c | 3 ++- 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/drivers/i3c/internals.h b/drivers/i3c/internals.h index 86b7b44..bc062e8 100644 --- a/drivers/i3c/internals.h +++ b/drivers/i3c/internals.h @@ -11,6 +11,7 @@ #include extern struct bus_type i3c_bus_type; +extern const struct device_type i3c_masterdev_type; void i3c_bus_normaluse_lock(struct i3c_bus *bus); void i3c_bus_normaluse_unlock(struct i3c_bus *bus); diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index 0436916..a1fb5f7 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -523,9 +523,10 @@ static void i3c_masterdev_release(struct device *dev) of_node_put(dev->of_node); } -static const struct device_type i3c_masterdev_type = { +const struct device_type i3c_masterdev_type = { .groups = i3c_masterdev_groups, }; +EXPORT_SYMBOL_GPL(i3c_masterdev_type); int i3c_bus_set_mode(struct i3c_bus *i3cbus, enum i3c_bus_mode mode, unsigned long max_i2c_scl_rate) From patchwork Tue Dec 10 15:37:30 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitor Soares X-Patchwork-Id: 11282841 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 54D5914E3 for ; Tue, 10 Dec 2019 15:37:46 +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 32C3C206D5 for ; Tue, 10 Dec 2019 15:37:46 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="W96YodLz"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="cinuiUHh" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 32C3C206D5 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=synopsys.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=SPVfs3IgnTMq/ZoerOzM8qN5EgGchMt1dy7lneL/hkA=; b=W96YodLzg77TgE91NzXNXBRiA/ /6XvClfygLV45gBvbBkU5qxKQvCVLc3ADWzrNI/QeNO2rJt9zv42cvvMtuS958yNtv/J8JXy/a00r ysVUxYukKc0fVdoDezwg8wmmJgQnBZF5YQNbGVy64CIyL5F0+vrDxOFZj39xH5Ktgi3v+OobQDr5Q 8LB3J6nHIqJE8d4F+kpzg7W0KzlBzOa4Foau2R82GPTI97bNiKdPldLwVZxAw7zShqqDdPjAVNLIv CrWtQNJO9oIBD4D721OqdzOH1dw5e3OWfAkXZ8nYn9VUXbkxhXhVyZxVrvMx7owi9Ef7/fgfw1wnq Nv//XPCQ==; 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 1ieha5-00044H-TI; Tue, 10 Dec 2019 15:37:45 +0000 Received: from sv2-smtprelay2.synopsys.com ([149.117.73.133] helo=smtprelay-out1.synopsys.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ieha3-0003z7-88 for linux-i3c@lists.infradead.org; Tue, 10 Dec 2019 15:37:44 +0000 Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id F41AB405D4; Tue, 10 Dec 2019 15:37:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1575992263; bh=9uIArk7W/VoQqStsEzOZbVA9gvJuUpov0r2L92iFq/E=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=cinuiUHh9Si9BaJO/IpfKrVF3he0bzfZTFf9miLGhgaswE8kCAQDZhjH2ESDy+Jca ek57K74C43TL6d7dM/R4NEHeRiI58s5nRi4GuGOdKMMq+Q7vtuVf7l16DXZYtz6ZjE 1StsAF5/dPiA8Noky+se3axFdxcn1nBLMxaG053XJgqGtKDpVc6L6cuFpkQJsczVC7 4IXoPurEDTOJ9jrIrSfLd0N6XXN+7dCsJb1m2thsIU5m7lxXvmg8KtR/BhzrWpzDI3 orTONP0URW4+P0GIkiUmsXAp1hfBo0qwOg2VDS90obk+CSG8g1ZiTl+jy6xNLiwZSn 6Yo2hhYw93YoA== Received: from de02.synopsys.com (germany.internal.synopsys.com [10.225.17.21]) by mailhost.synopsys.com (Postfix) with ESMTP id 97B18A0086; Tue, 10 Dec 2019 15:37:36 +0000 (UTC) Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by de02.synopsys.com (Postfix) with ESMTP id 7C8FB3E2D3; Tue, 10 Dec 2019 16:37:36 +0100 (CET) From: Vitor Soares To: linux-kernel@vger.kernel.org, linux-i3c@lists.infradead.org Subject: [RFC 2/5] i3c: master: export i3c_bus_type symbol Date: Tue, 10 Dec 2019 16:37:30 +0100 Message-Id: <96507b6036bf834ca8ee086578b8616958a363be.1575977795.git.vitor.soares@synopsys.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191210_073743_314387_06ACBF3E X-CRM114-Status: UNSURE ( 8.81 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux I3C List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joao.Pinto@synopsys.com, arnd@arndb.de, wsa@the-dreams.de, gregkh@linuxfoundation.org, bbrezillon@kernel.org, Vitor Soares , broonie@kernel.org MIME-Version: 1.0 Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org Export i3c_bus_type symbol so i3cdev can register a notifier chain for the i3c bus. Signed-off-by: Vitor Soares --- drivers/i3c/master.c | 1 + 1 file changed, 1 insertion(+) diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index a1fb5f7..a9df276 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -321,6 +321,7 @@ struct bus_type i3c_bus_type = { .probe = i3c_device_probe, .remove = i3c_device_remove, }; +EXPORT_SYMBOL_GPL(i3c_bus_type); static enum i3c_addr_slot_status i3c_bus_get_addr_slot_status(struct i3c_bus *bus, u16 addr) From patchwork Tue Dec 10 15:37:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitor Soares X-Patchwork-Id: 11282845 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 8810F14E3 for ; Tue, 10 Dec 2019 15:37:47 +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 6712E20838 for ; Tue, 10 Dec 2019 15:37:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="EDt9aOGR"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="DF9bQBza" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 6712E20838 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=synopsys.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=zIyopAJp5xS2IkV7u6t+zWuIGn94KYcwjAJARo2iuWY=; b=EDt9aOGR7pEju9T7S/fqF9mAzx 8AYyefWQWRoWLcT/bLbiPPurXK4ojT2kzqffG9Ke2/LHHffm2dw4Gnrg81l0/TEHS1S6QwhdBlXE0 /8zAnxpVMiULqeVw4E2jcvV3vojePvWUJ2bBKBL3LNKFdd+I3siy6+CfE3oG41kWMz/qMiLF3+ZiO zjA6KkF3LLY90Ec7ANEjqf55YXWKRLCo6R0p4Rt009/TE+HrGXoWCp6Mv5d/5gaE+fEnG9ll7X/0t 96lnWh7beKb095Fy9iex3TVA7+JX9TfL+vsT8BT/EiP0HfvxvJ9FTq/G47p0+Slo5vBfEeUYGoS2N bvodLI5w==; 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 1ieha7-00044w-3r; Tue, 10 Dec 2019 15:37:47 +0000 Received: from sv2-smtprelay2.synopsys.com ([149.117.73.133] helo=smtprelay-out1.synopsys.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ieha3-0003zA-Ap for linux-i3c@lists.infradead.org; Tue, 10 Dec 2019 15:37:45 +0000 Received: from mailhost.synopsys.com (mdc-mailhost1.synopsys.com [10.225.0.209]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id DDBC5405D3; Tue, 10 Dec 2019 15:37:42 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1575992263; bh=VbA5BxszGxxpBvjX7QPw0ZeM5aDPv05lVfXsQi2i6zo=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=DF9bQBzakzmR59p2IBRadN2EejZw/ho/g0KcA9oykCFDBiZmKAv0X0ZaonD17NAj8 zgMxq4cAwrNLIUk/0N69+D9sadtdO4vPjmfkg95UZbvOQ9r6RUwbcBIihjSPnYSa35 k62rUCRXIvIlOgFqrbhhDYPMx+RF0lhHOzxk3mtnv3AUAAf41Tq3E0OJ/5QZssC5or G3PRKd0M7ijrHXLDXYENXP6NlGb2+r9rb/we67RPWnGoIXZ3Yea6ek7BQgfGx8RCV3 Z3JOkQCm667xqgPpwCeKYenjkHvAG+yuphC3yRl5GSVl+K+Nr8F9L55+xLdMtJlvMl p/DNNFA/6M/VA== Received: from de02.synopsys.com (de02.internal.synopsys.com [10.225.17.21]) by mailhost.synopsys.com (Postfix) with ESMTP id A2D27A0087; Tue, 10 Dec 2019 15:37:36 +0000 (UTC) Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by de02.synopsys.com (Postfix) with ESMTP id 8B6FB3E2D6; Tue, 10 Dec 2019 16:37:36 +0100 (CET) From: Vitor Soares To: linux-kernel@vger.kernel.org, linux-i3c@lists.infradead.org Subject: [RFC 3/5] i3c: device: expose transfer strutures to uapi Date: Tue, 10 Dec 2019 16:37:31 +0100 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191210_073743_400121_5BE22421 X-CRM114-Status: GOOD ( 14.17 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux I3C List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joao.Pinto@synopsys.com, arnd@arndb.de, wsa@the-dreams.de, gregkh@linuxfoundation.org, bbrezillon@kernel.org, Vitor Soares , broonie@kernel.org MIME-Version: 1.0 Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org Move i3c transfer related structures to uapi, so they can be access by userspace. Signed-off-by: Vitor Soares --- include/linux/i3c/device.h | 54 +-------------------------------- include/uapi/linux/i3c/device.h | 66 +++++++++++++++++++++++++++++++++++++++++ 2 files changed, 67 insertions(+), 53 deletions(-) create mode 100644 include/uapi/linux/i3c/device.h diff --git a/include/linux/i3c/device.h b/include/linux/i3c/device.h index de102e4..1df05c2 100644 --- a/include/linux/i3c/device.h +++ b/include/linux/i3c/device.h @@ -14,59 +14,7 @@ #include #include #include - -/** - * enum i3c_error_code - I3C error codes - * - * These are the standard error codes as defined by the I3C specification. - * When -EIO is returned by the i3c_device_do_priv_xfers() or - * i3c_device_send_hdr_cmds() one can check the error code in - * &struct_i3c_priv_xfer.err or &struct i3c_hdr_cmd.err to get a better idea of - * what went wrong. - * - * @I3C_ERROR_UNKNOWN: unknown error, usually means the error is not I3C - * related - * @I3C_ERROR_M0: M0 error - * @I3C_ERROR_M1: M1 error - * @I3C_ERROR_M2: M2 error - */ -enum i3c_error_code { - I3C_ERROR_UNKNOWN = 0, - I3C_ERROR_M0 = 1, - I3C_ERROR_M1, - I3C_ERROR_M2, -}; - -/** - * enum i3c_hdr_mode - HDR mode ids - * @I3C_HDR_DDR: DDR mode - * @I3C_HDR_TSP: TSP mode - * @I3C_HDR_TSL: TSL mode - */ -enum i3c_hdr_mode { - I3C_HDR_DDR, - I3C_HDR_TSP, - I3C_HDR_TSL, -}; - -/** - * struct i3c_priv_xfer - I3C SDR private transfer - * @rnw: encodes the transfer direction. true for a read, false for a write - * @len: transfer length in bytes of the transfer - * @data: input/output buffer - * @data.in: input buffer. Must point to a DMA-able buffer - * @data.out: output buffer. Must point to a DMA-able buffer - * @err: I3C error code - */ -struct i3c_priv_xfer { - u8 rnw; - u16 len; - union { - void *in; - const void *out; - } data; - enum i3c_error_code err; -}; +#include /** * enum i3c_dcr - I3C DCR values diff --git a/include/uapi/linux/i3c/device.h b/include/uapi/linux/i3c/device.h new file mode 100644 index 0000000..edbb14d --- /dev/null +++ b/include/uapi/linux/i3c/device.h @@ -0,0 +1,66 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2019 Synopsys, Inc. and/or its affiliates. + * + * Author: Vitor Soares + */ + +#ifndef _UAPI_LINUX_I3C_DEVICE_H +#define _UAPI_LINUX_I3C_DEVICE_H + +#include + +/** + * enum i3c_error_code - I3C error codes + * + * These are the standard error codes as defined by the I3C specification. + * When -EIO is returned by the i3c_device_do_priv_xfers() or + * i3c_device_send_hdr_cmds() one can check the error code in + * &struct_i3c_priv_xfer.err or &struct i3c_hdr_cmd.err to get a better idea of + * what went wrong. + * + * @I3C_ERROR_UNKNOWN: unknown error, usually means the error is not I3C + * related + * @I3C_ERROR_M0: M0 error + * @I3C_ERROR_M1: M1 error + * @I3C_ERROR_M2: M2 error + */ +enum i3c_error_code { + I3C_ERROR_UNKNOWN = 0, + I3C_ERROR_M0 = 1, + I3C_ERROR_M1, + I3C_ERROR_M2, +}; + +/** + * enum i3c_hdr_mode - HDR mode ids + * @I3C_HDR_DDR: DDR mode + * @I3C_HDR_TSP: TSP mode + * @I3C_HDR_TSL: TSL mode + */ +enum i3c_hdr_mode { + I3C_HDR_DDR, + I3C_HDR_TSP, + I3C_HDR_TSL, +}; + +/** + * struct i3c_priv_xfer - I3C SDR private transfer + * @rnw: encodes the transfer direction. true for a read, false for a write + * @len: transfer length in bytes of the transfer + * @data: input/output buffer + * @data.in: input buffer. Must point to a DMA-able buffer + * @data.out: output buffer. Must point to a DMA-able buffer + * @err: I3C error code + */ +struct i3c_priv_xfer { + u8 rnw; + u16 len; + union { + void *in; + const void *out; + } data; + enum i3c_error_code err; +}; + +#endif /* _UAPI_LINUX_I3C_DEVICE_H */ From patchwork Tue Dec 10 15:37:32 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitor Soares X-Patchwork-Id: 11282835 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 3FC8E14E3 for ; Tue, 10 Dec 2019 15:37:43 +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 1DD9E207FF for ; Tue, 10 Dec 2019 15:37:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="IMh9bYJe"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="lj6AdmHY" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 1DD9E207FF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=synopsys.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=j3eoof96I2wa1gFnElZhI2i2rHvcwcYLGiOGp6JPbv8=; b=IMh9bYJe5b8EW5JP2dBWLlfKsR p3NM0gYxz0EPiGGD5Rz+sMHQ2YPDyu7duhCywTcDGyWJMbMZp9PaOU4m+WgqTw1yVcaekrvCj+sfv FBO5ij8F2Wka2ScCZDza4u1JytvAi5gKaK+0iWHFNL5xXvQUO+rpbaUtzHhQePU5+aWGh356h+rAP mvH9RJ6Ok/MjeQ4MWdvBmhVlorVM5HioyLQiEeq7lNWHMX+sEp8za176VM60D55M2vYOnBMXr6hxr i01x+conQUQq1AODyKKubSPF4vgsd+a7RBhLuMFxqFhLn2xXiH1lnMFpeWXDGQx33OQXm+eNwD36w HpXCdTxw==; 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 1ieha2-0003wD-GA; Tue, 10 Dec 2019 15:37:42 +0000 Received: from smtprelay-out1.synopsys.com ([149.117.87.133]) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1iehZz-0003qO-RR for linux-i3c@lists.infradead.org; Tue, 10 Dec 2019 15:37:41 +0000 Received: from mailhost.synopsys.com (mdc-mailhost2.synopsys.com [10.225.0.210]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id B42EEC00A2; Tue, 10 Dec 2019 15:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1575992259; bh=69j7jHbx5yJ5MhVkwHC0PThYgKjCClJKrN77KC+ilaQ=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=lj6AdmHY5d6/zKnLaJDfKGQkeuwYZ8dPP0k+lRnshmtc+9iZds0nmrUjvP0AK+jWU +5zGv7senN67OngiOPgLBWIAWUX4nQ7xmvb6gtaZT3uJqXqQv6XRRbzYaWNBXNlLV8 QpcGGdQBlB3QrDxQu43UJpve+oME81fEwYEWBKbnQSNKpgqnJy4/pHrywG7Y8fM79X IFfxGWBTpxBc3Own+RjQ4DXKmJTOe/cQEqN/dCESfAm0XVDkNo9Vt6jLo2a1w04rPa RZAvqeW0JFsQGJURhMYwkLVahtlh3tpT4ulPkPmLF4zt4Tp2MN3bx8nW3S/3xSBrOU h4AyhzEDoXkMA== Received: from de02.synopsys.com (de02.internal.synopsys.com [10.225.17.21]) by mailhost.synopsys.com (Postfix) with ESMTP id B48B9A005E; Tue, 10 Dec 2019 15:37:36 +0000 (UTC) Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by de02.synopsys.com (Postfix) with ESMTP id A0FB73E2D9; Tue, 10 Dec 2019 16:37:36 +0100 (CET) From: Vitor Soares To: linux-kernel@vger.kernel.org, linux-i3c@lists.infradead.org Subject: [RFC 4/5] i3c: master: add i3c_for_each_dev helper Date: Tue, 10 Dec 2019 16:37:32 +0100 Message-Id: <5aa3bd64a6082ded430ce27f5ea3f6956d1436ac.1575977795.git.vitor.soares@synopsys.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191210_073739_932704_00738D98 X-CRM114-Status: UNSURE ( 9.58 ) X-CRM114-Notice: Please train this message. X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux I3C List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joao.Pinto@synopsys.com, arnd@arndb.de, wsa@the-dreams.de, gregkh@linuxfoundation.org, bbrezillon@kernel.org, Vitor Soares , broonie@kernel.org MIME-Version: 1.0 Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org Introduce i3c_for_each_dev(), an i3c device iterator for use by i3cdev. Signed-off-by: Vitor Soares --- drivers/i3c/internals.h | 1 + drivers/i3c/master.c | 12 ++++++++++++ 2 files changed, 13 insertions(+) diff --git a/drivers/i3c/internals.h b/drivers/i3c/internals.h index bc062e8..a6deedf 100644 --- a/drivers/i3c/internals.h +++ b/drivers/i3c/internals.h @@ -24,4 +24,5 @@ int i3c_dev_enable_ibi_locked(struct i3c_dev_desc *dev); int i3c_dev_request_ibi_locked(struct i3c_dev_desc *dev, const struct i3c_ibi_setup *req); void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev); +int i3c_for_each_dev(void *data, int (*fn)(struct device *, void *)); #endif /* I3C_INTERNAL_H */ diff --git a/drivers/i3c/master.c b/drivers/i3c/master.c index a9df276..cc41efe 100644 --- a/drivers/i3c/master.c +++ b/drivers/i3c/master.c @@ -2640,6 +2640,18 @@ void i3c_dev_free_ibi_locked(struct i3c_dev_desc *dev) dev->ibi = NULL; } +int i3c_for_each_dev(void *data, int (*fn)(struct device *, void *)) +{ + int res; + + mutex_lock(&i3c_core_lock); + res = bus_for_each_dev(&i3c_bus_type, NULL, data, fn); + mutex_unlock(&i3c_core_lock); + + return res; +} +EXPORT_SYMBOL_GPL(i3c_for_each_dev); + static int __init i3c_init(void) { return bus_register(&i3c_bus_type); From patchwork Tue Dec 10 15:37:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Vitor Soares X-Patchwork-Id: 11282843 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 78D51112B for ; Tue, 10 Dec 2019 15:37:47 +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 54B80207FF for ; Tue, 10 Dec 2019 15:37:47 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="DnDSwCnd"; dkim=fail reason="signature verification failed" (2048-bit key) header.d=synopsys.com header.i=@synopsys.com header.b="XEi6lCqG" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 54B80207FF Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=synopsys.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-i3c-bounces+linux-i3c=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:MIME-Version:Cc:List-Subscribe: List-Help:List-Post:List-Archive:List-Unsubscribe:List-Id: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=3/IlV3ocxkMuuNoMB0i3v2DTaUcpbwvX9swovRGD0Ys=; b=DnDSwCnd0QmamxP9ABA3rrKKj4 18XGMD88m9btRg2OXr275CjSZW01wko0T8WEoJQtHnT2BBc4AvRlELq3MizU9BOxkcJDEKrsvp69J EUIua+lkLb2uGmPHsxta3I1y9HqqIUgGkrhEVFKUFttkbetFSpunbFtCorI1l5HdCGmene9DSzRqk kDkBAfwVuMJAuBkbOUiGdVloDJX8F2ftfVzBxc6y1mubjAotimPI5iVzWQtve9++52vjkMrtrxRnU TyJf35OgshDKazV9SG0yYe7e3reH+63wC3s3dauGmKIyrDl5P/fY3iOimD/ecgqVust9cw0hgm3x6 Ho+sr/gg==; 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 1ieha7-00044o-0C; Tue, 10 Dec 2019 15:37:47 +0000 Received: from sv2-smtprelay2.synopsys.com ([149.117.73.133] helo=smtprelay-out1.synopsys.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ieha1-0003qP-6R for linux-i3c@lists.infradead.org; Tue, 10 Dec 2019 15:37:45 +0000 Received: from mailhost.synopsys.com (mdc-mailhost2.synopsys.com [10.225.0.210]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits)) (No client certificate requested) by smtprelay-out1.synopsys.com (Postfix) with ESMTPS id 83A5940235; Tue, 10 Dec 2019 15:37:38 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=synopsys.com; s=mail; t=1575992259; bh=vfAJzCoYEGjQU8QTAYJK/QlCdujJtaY7VskjZ9rPM5s=; h=From:To:Cc:Subject:Date:In-Reply-To:References:In-Reply-To: References:From; b=XEi6lCqGMdd3T2IGhddQBury+QiF5TkH6hNbJ4y7lNvIi13n/JQLLRw4ZqjLyldyR oyhxnpDqqsqrBH69kbMa5XkXUUq0site474JYtSKJ512jlgsWA3y7Fgi0F6THfh43R 5WxaotFHv3qXxVpqKLrK8bZC0g6rP/xyTBX/vkWyCDzy7HW67P+vGJ8CY0sYNvh+Wr ZdrgijYhYvSDTxLiGlOV6kirMdMnqLkXSwgCF2DTZfyOkX73AX+Rk/AWcdtx2xTgCr 56T43BWNdrhsa37Q6wqOu4wIQPLKCCLZn9fHj+kxJQUQ4I2jm6csDRwZgXrdZMX8+y Ae8AMK5HLmvUw== Received: from de02.synopsys.com (de02.internal.synopsys.com [10.225.17.21]) by mailhost.synopsys.com (Postfix) with ESMTP id E81CBA0082; Tue, 10 Dec 2019 15:37:36 +0000 (UTC) Received: from de02dwia024.internal.synopsys.com (de02dwia024.internal.synopsys.com [10.225.19.81]) by de02.synopsys.com (Postfix) with ESMTP id B24DC3E2DC; Tue, 10 Dec 2019 16:37:36 +0100 (CET) From: Vitor Soares To: linux-kernel@vger.kernel.org, linux-i3c@lists.infradead.org Subject: [RFC 5/5] i3c: add i3cdev module to expose i3c dev in /dev Date: Tue, 10 Dec 2019 16:37:33 +0100 Message-Id: X-Mailer: git-send-email 2.7.4 In-Reply-To: References: In-Reply-To: References: X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191210_073741_266801_839871EF X-CRM114-Status: GOOD ( 23.03 ) X-Spam-Score: -0.2 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (-0.2 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 SPF_PASS SPF: sender matches SPF record 0.0 SPF_HELO_NONE SPF: HELO does not publish an SPF Record -0.1 DKIM_VALID_AU Message has a valid DKIM or DK signature from author's domain 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature -0.1 DKIM_VALID_EF Message has a valid DKIM or DK signature from envelope-from domain X-BeenThere: linux-i3c@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Linux I3C List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Joao.Pinto@synopsys.com, arnd@arndb.de, wsa@the-dreams.de, gregkh@linuxfoundation.org, bbrezillon@kernel.org, Vitor Soares , broonie@kernel.org MIME-Version: 1.0 Sender: "linux-i3c" Errors-To: linux-i3c-bounces+linux-i3c=patchwork.kernel.org@lists.infradead.org This patch adds user-mode support to I3C SDR transfers. The module is based on i2c-dev.c with the following features: - expose on /dev the i3c devices dynamically based on if they have a device driver bound. - Dynamically allocate the char device Major number. Signed-off-by: Vitor Soares --- drivers/i3c/Kconfig | 15 ++ drivers/i3c/Makefile | 1 + drivers/i3c/i3cdev.c | 438 ++++++++++++++++++++++++++++++++++++++++ include/uapi/linux/i3c/i3cdev.h | 27 +++ 4 files changed, 481 insertions(+) create mode 100644 drivers/i3c/i3cdev.c create mode 100644 include/uapi/linux/i3c/i3cdev.h diff --git a/drivers/i3c/Kconfig b/drivers/i3c/Kconfig index 30a4415..0164276 100644 --- a/drivers/i3c/Kconfig +++ b/drivers/i3c/Kconfig @@ -20,5 +20,20 @@ menuconfig I3C will be called i3c. if I3C + +config I3CDEV + tristate "I3C device interface" + depends on I3C + help + Say Y here to use i3c-* device files, usually found in the /dev + directory on your system. They make it possible to have user-space + programs use the I3C devices. + + This support is also available as a module. If so, the module + will be called i3cdev. + + Note that this application programming interface is EXPERIMENTAL + and hence SUBJECT TO CHANGE WITHOUT NOTICE while it stabilizes. + source "drivers/i3c/master/Kconfig" endif # I3C diff --git a/drivers/i3c/Makefile b/drivers/i3c/Makefile index 11982ef..606d422 100644 --- a/drivers/i3c/Makefile +++ b/drivers/i3c/Makefile @@ -1,4 +1,5 @@ # SPDX-License-Identifier: GPL-2.0 i3c-y := device.o master.o obj-$(CONFIG_I3C) += i3c.o +obj-$(CONFIG_I3CDEV) += i3cdev.o obj-$(CONFIG_I3C) += master/ diff --git a/drivers/i3c/i3cdev.c b/drivers/i3c/i3cdev.c new file mode 100644 index 0000000..4d4b83c --- /dev/null +++ b/drivers/i3c/i3cdev.c @@ -0,0 +1,438 @@ +// SPDX-License-Identifier: GPL-2.0 +/* + * Copyright (c) 2019 Synopsys, Inc. and/or its affiliates. + * + * Author: Vitor Soares + */ + +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#include + +#include "internals.h" + +#define I3C_MINORS MINORMASK +#define N_I3C_MINORS 16 /* For now */ + +static DECLARE_BITMAP(minors, N_I3C_MINORS); + +struct i3cdev_data { + struct list_head list; + struct i3c_device *i3c; + struct cdev cdev; + struct device *dev; + dev_t devt; +}; + +static dev_t i3cdev_number; /* Alloted device number */ + +static LIST_HEAD(i3cdev_list); +static DEFINE_SPINLOCK(i3cdev_list_lock); + +static struct i3cdev_data *i3cdev_get_by_minor(unsigned int minor) +{ + struct i3cdev_data *i3cdev; + + spin_lock(&i3cdev_list_lock); + list_for_each_entry(i3cdev, &i3cdev_list, list) { + if (MINOR(i3cdev->devt) == minor) + goto found; + } + + i3cdev = NULL; + +found: + spin_unlock(&i3cdev_list_lock); + return i3cdev; +} + +static struct i3cdev_data *i3cdev_get_by_i3c(struct i3c_device *i3c) +{ + struct i3cdev_data *i3cdev; + + spin_lock(&i3cdev_list_lock); + list_for_each_entry(i3cdev, &i3cdev_list, list) { + if (i3cdev->i3c == i3c) + goto found; + } + + i3cdev = NULL; + +found: + spin_unlock(&i3cdev_list_lock); + return i3cdev; +} + +static struct i3cdev_data *get_free_i3cdev(struct i3c_device *i3c) +{ + struct i3cdev_data *i3cdev; + unsigned long minor; + + minor = find_first_zero_bit(minors, N_I3C_MINORS); + if (minor >= N_I3C_MINORS) { + pr_err("i3cdev: no minor number available!\n"); + return ERR_PTR(-ENODEV); + } + + i3cdev = kzalloc(sizeof(*i3cdev), GFP_KERNEL); + if (!i3cdev) + return ERR_PTR(-ENOMEM); + + i3cdev->i3c = i3c; + i3cdev->devt = MKDEV(MAJOR(i3cdev_number), minor); + set_bit(minor, minors); + + spin_lock(&i3cdev_list_lock); + list_add_tail(&i3cdev->list, &i3cdev_list); + spin_unlock(&i3cdev_list_lock); + + return i3cdev; +} + +static void put_i3cdev(struct i3cdev_data *i3cdev) +{ + spin_lock(&i3cdev_list_lock); + list_del(&i3cdev->list); + spin_unlock(&i3cdev_list_lock); + kfree(i3cdev); +} + +static ssize_t +i3cdev_read(struct file *file, char __user *buf, size_t count, loff_t *f_pos) +{ + struct i3c_device *i3c = file->private_data; + struct i3c_priv_xfer xfers = { + .rnw = true, + .len = count, + }; + char *tmp; + int ret; + + tmp = kzalloc(count, GFP_KERNEL); + if (!tmp) + return -ENOMEM; + + xfers.data.in = tmp; + + dev_dbg(&i3c->dev, "Reading %zu bytes.\n", count); + + ret = i3c_device_do_priv_xfers(i3c, &xfers, 1); + if (!ret) + ret = copy_to_user(buf, tmp, count) ? -EFAULT : ret; + + kfree(tmp); + return ret; +} + +static ssize_t +i3cdev_write(struct file *file, const char __user *buf, size_t count, + loff_t *f_pos) +{ + struct i3c_device *i3c = file->private_data; + struct i3c_priv_xfer xfers = { + .rnw = false, + .len = count, + }; + char *tmp; + int ret; + + tmp = memdup_user(buf, count); + if (IS_ERR(tmp)) + return PTR_ERR(tmp); + + xfers.data.out = tmp; + + dev_dbg(&i3c->dev, "Writing %zu bytes.\n", count); + + ret = i3c_device_do_priv_xfers(i3c, &xfers, 1); + kfree(tmp); + return (!ret) ? count : ret; +} + +static int +i3cdev_do_priv_xfer(struct i3c_device *dev, struct i3c_priv_xfer *xfers, + unsigned int nxfers) +{ + void __user **data_ptrs; + unsigned int i; + int ret = 0; + + data_ptrs = kmalloc_array(nxfers, sizeof(*data_ptrs), GFP_KERNEL); + if (!data_ptrs) + return -ENOMEM; + + for (i = 0; i < nxfers; i++) { + if (xfers[i].rnw) { + data_ptrs[i] = (void __user *)xfers[i].data.in; + xfers[i].data.in = memdup_user(data_ptrs[i], + xfers[i].len); + if (IS_ERR(xfers[i].data.in)) { + ret = PTR_ERR(xfers[i].data.in); + break; + } + } else { + data_ptrs[i] = (void __user *)xfers[i].data.out; + xfers[i].data.out = memdup_user(data_ptrs[i], + xfers[i].len); + if (IS_ERR(xfers[i].data.out)) { + ret = PTR_ERR(xfers[i].data.out); + break; + } + } + } + + if (ret < 0) { + unsigned int j; + + for (j = 0; j < i; ++j) { + if (xfers[i].rnw) + kfree(xfers[i].data.in); + else + kfree(xfers[i].data.out); + } + + kfree(data_ptrs); + return ret; + } + + ret = i3c_device_do_priv_xfers(dev, xfers, nxfers); + while (i-- > 0) { + if (ret >= 0 && xfers[i].rnw) { + if (copy_to_user(data_ptrs[i], xfers[i].data.in, + xfers[i].len)) + ret = -EFAULT; + } + + if (xfers[i].rnw) + kfree(xfers[i].data.in); + else + kfree(xfers[i].data.out); + } + + kfree(data_ptrs); + return ret; +} + +static int +i3cdev_ioc_priv_xfer(struct i3c_device *i3c, + struct i3c_ioc_priv_xfer __user *u_ioc_xfers) +{ + struct i3c_ioc_priv_xfer k_ioc_xfer; + struct i3c_priv_xfer *xfers; + int ret; + + if (copy_from_user(&k_ioc_xfer, u_ioc_xfers, sizeof(k_ioc_xfer))) + return -EFAULT; + + xfers = memdup_user(k_ioc_xfer.xfers, + k_ioc_xfer.nxfers * sizeof(struct i3c_priv_xfer)); + if (IS_ERR(xfers)) + return PTR_ERR(xfers); + + ret = i3cdev_do_priv_xfer(i3c, xfers, k_ioc_xfer.nxfers); + kfree(xfers); + + return ret; +} + +static long +i3cdev_ioctl(struct file *file, unsigned int cmd, unsigned long arg) +{ + struct i3c_device *i3c = file->private_data; + + dev_dbg(&i3c->dev, "ioctl, cmd=0x%02x, arg=0x%02lx\n", cmd, arg); + + if (_IOC_TYPE(cmd) != I3C_DEV_IOC_MAGIC) + return -ENOTTY; + + if (cmd == I3C_IOC_PRIV_XFER) + return i3cdev_ioc_priv_xfer(i3c, + (struct i3c_ioc_priv_xfer __user *)arg); + + return 0; +} + +static int i3cdev_open(struct inode *inode, struct file *file) +{ + unsigned int minor = iminor(inode); + struct i3cdev_data *i3cdev; + + i3cdev = i3cdev_get_by_minor(minor); + if (!i3cdev) + return -ENODEV; + + file->private_data = i3cdev->i3c; + + return 0; +} + +static int i3cdev_release(struct inode *inode, struct file *file) +{ + file->private_data = NULL; + + return 0; +} + +static const struct file_operations i3cdev_fops = { + .owner = THIS_MODULE, + .read = i3cdev_read, + .write = i3cdev_write, + .unlocked_ioctl = i3cdev_ioctl, + .open = i3cdev_open, + .release = i3cdev_release, +}; + +/* ------------------------------------------------------------------------- */ + +static struct class *i3cdev_class; + +static int i3cdev_attach(struct device *dev, void *dummy) +{ + struct i3c_device *i3c; + struct i3cdev_data *i3cdev; + int res; + + if (dev->type == &i3c_masterdev_type || dev->driver) + return 0; + + i3c = dev_to_i3cdev(dev); + + /* Get a device */ + i3cdev = get_free_i3cdev(i3c); + if (IS_ERR(i3cdev)) + return PTR_ERR(i3cdev); + + cdev_init(&i3cdev->cdev, &i3cdev_fops); + i3cdev->cdev.owner = THIS_MODULE; + res = cdev_add(&i3cdev->cdev, i3cdev->devt, 1); + if (res) + goto error_cdev; + + /* register this i3c device with the driver core */ + i3cdev->dev = device_create(i3cdev_class, &i3c->dev, + i3cdev->devt, NULL, + "i3c-%s", dev_name(&i3c->dev)); + if (IS_ERR(i3cdev->dev)) { + res = PTR_ERR(i3cdev->dev); + goto error; + } + pr_debug("i3c-cdev: I3C device [%s] registered as minor %d\n", + dev_name(&i3c->dev), MINOR(i3cdev->devt)); + return 0; + +error: + cdev_del(&i3cdev->cdev); +error_cdev: + put_i3cdev(i3cdev); + return res; +} + +static int i3cdev_detach(struct device *dev, void *dummy) +{ + struct i3c_device *i3c; + struct i3cdev_data *i3cdev; + + if (dev->type == &i3c_masterdev_type) + return 0; + + i3c = dev_to_i3cdev(dev); + + i3cdev = i3cdev_get_by_i3c(i3c); + if (!i3cdev) + return 0; + + clear_bit(MINOR(i3cdev->devt), minors); + cdev_del(&i3cdev->cdev); + device_destroy(i3cdev_class, i3cdev->devt); + put_i3cdev(i3cdev); + + pr_debug("i3c-busdev: bus [%s] unregistered\n", + dev_name(&i3c->dev)); + + return 0; +} + +static int i3cdev_notifier_call(struct notifier_block *nb, + unsigned long action, + void *data) +{ + struct device *dev = data; + + switch (action) { + case BUS_NOTIFY_ADD_DEVICE: + case BUS_NOTIFY_UNBOUND_DRIVER: + return i3cdev_attach(dev, NULL); + case BUS_NOTIFY_DEL_DEVICE: + case BUS_NOTIFY_BOUND_DRIVER: + return i3cdev_detach(dev, NULL); + } + + return 0; +} + +static struct notifier_block i3c_notifier = { + .notifier_call = i3cdev_notifier_call, +}; + +static int __init i3cdev_init(void) +{ + int res; + + pr_info("i3c /dev entries driver\n"); + + /* Dynamically request unused major number */ + res = alloc_chrdev_region(&i3cdev_number, 0, N_I3C_MINORS, "i3c"); + if (res) + goto out; + + /* Create a classe to populate sysfs entries*/ + i3cdev_class = class_create(THIS_MODULE, "i3c-dev"); + if (IS_ERR(i3cdev_class)) { + res = PTR_ERR(i3cdev_class); + goto out_unreg_chrdev; + } + + /* Keep track of busses which have devices to add or remove later */ + res = bus_register_notifier(&i3c_bus_type, &i3c_notifier); + if (res) + goto out_unreg_class; + + /* Bind to already existing device without driver right away */ + i3c_for_each_dev(NULL, i3cdev_attach); + + return 0; + +out_unreg_class: + class_destroy(i3cdev_class); +out_unreg_chrdev: + unregister_chrdev_region(i3cdev_number, I3C_MINORS); +out: + pr_err("%s: Driver Initialisation failed\n", __FILE__); + return res; +} + +static void __exit i3cdev_exit(void) +{ + bus_unregister_notifier(&i3c_bus_type, &i3c_notifier); + i3c_for_each_dev(NULL, i3cdev_detach); + class_destroy(i3cdev_class); + unregister_chrdev_region(i3cdev_number, I3C_MINORS); +} + +MODULE_AUTHOR("Vitor Soares "); +MODULE_DESCRIPTION("I3C /dev entries driver"); +MODULE_LICENSE("GPL"); + +module_init(i3cdev_init); +module_exit(i3cdev_exit); diff --git a/include/uapi/linux/i3c/i3cdev.h b/include/uapi/linux/i3c/i3cdev.h new file mode 100644 index 0000000..4030043 --- /dev/null +++ b/include/uapi/linux/i3c/i3cdev.h @@ -0,0 +1,27 @@ +/* SPDX-License-Identifier: GPL-2.0 */ +/* + * Copyright (c) 2019 Synopsys, Inc. and/or its affiliates. + * + * Author: Vitor Soares + */ + +#ifndef _UAPI_I3C_DEV_H_ +#define _UAPI_I3C_DEV_H_ + +#include +#include + +/* IOCTL commands */ +#define I3C_DEV_IOC_MAGIC 0x07 + +struct i3c_ioc_priv_xfer { + struct i3c_priv_xfer __user *xfers; /* pointers to i3c_priv_xfer */ + __u32 nxfers; /* number of i3c_priv_xfer */ +}; + +#define I3C_IOC_PRIV_XFER \ + _IOW(I3C_DEV_IOC_MAGIC, 30, struct i3c_ioc_priv_xfer) + +#define I3C_IOC_PRIV_XFER_MAX_MSGS 42 + +#endif