Received: by 10.223.164.202 with SMTP id h10csp4218789wrb; Mon, 20 Nov 2017 11:50:04 -0800 (PST) X-Google-Smtp-Source: AGs4zMZKByAevvfLqH6vEuJSVMzUSbTZsTG7YHdgXm+5LWPkneO0BvX3kQcE/lPLjqU8EmbvLD1W X-Received: by 10.101.77.210 with SMTP id q18mr14603806pgt.145.1511207404183; Mon, 20 Nov 2017 11:50:04 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1511207404; cv=none; d=google.com; s=arc-20160816; b=aIjX7TVPlXqMuNP0uQSAyL3YwT7LGdF36VdfX0Yoo7ites5KqvkxEF/kIAaNgIfU3e Y6VF5Gwf7s2legtQcJpIYo/pGO5CJwRb6JcFiF/wCedRDsHEbFGPlXvtq84MDvW41ogv M4jAWDaGTcL17ipOQeTmxy49aBgMpUmW+5zZ4LF4kUmkxKHcRxxfcv7j/E4ga6fpXrQU Mg0M73VHUQIa3zxDRx6/g12QF/rkw+DwGGwEygxAU/OgZMpal3SMFa9VpGCOWHHWdywi tYKkXDH0bx6/rTevqmPWT7AO8PfDXpsqSaqY7YFa/aqKE5W+cECoopZiRW0uPJZANT4s KzeA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:references:in-reply-to:date :subject:cc:to:from:arc-authentication-results; bh=f1r1gus1b2xiCtkNToklwNsKCrbkpK0OJa2QGSrCHlo=; b=dO9aTZBhDOyO6GE2vLBiWeTCWedB9tZ667+5HgHt4ITSksJtqddVKH82gyEHkRWhb2 2Rex27zNwdDlEt+TFFTwgDR6JDXU+HgODJh1c4N4fzUMlCfuDeqMS0SpPMicWZZ7oUMS cOeEpDDllZUJ2LTibv9kv39XkJQayo8LQPDRhqsoDB8KCu+GqbScu7o2PnUAyv5JcwBo EUmMiuvK7OEvtwDs3CzgAq11o9pouih7/dPf7/I2Ugp+tbRxtQLEA6FbSVZtTZcMz7Tm KuxgFNmRXyKA8LgKiu5rJy1ZvLvDkNu8wctnIF/CMbP5olsPTd1ZFN+VG3lybNnMTN1Y CeQA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a92si9169969pla.28.2017.11.20.11.49.54; Mon, 20 Nov 2017 11:50:04 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752787AbdKTTsY (ORCPT + 67 others); Mon, 20 Nov 2017 14:48:24 -0500 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:45030 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752632AbdKTTrN (ORCPT ); Mon, 20 Nov 2017 14:47:13 -0500 Received: from pps.filterd (m0098394.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.21/8.16.0.21) with SMTP id vAKJi3vi109039 for ; Mon, 20 Nov 2017 14:47:13 -0500 Received: from e32.co.us.ibm.com (e32.co.us.ibm.com [32.97.110.150]) by mx0a-001b2d01.pphosted.com with ESMTP id 2ec1fs566u-1 (version=TLSv1.2 cipher=AES256-SHA bits=256 verify=NOT) for ; Mon, 20 Nov 2017 14:47:12 -0500 Received: from localhost by e32.co.us.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Mon, 20 Nov 2017 12:47:11 -0700 Received: from b03cxnp08026.gho.boulder.ibm.com (9.17.130.18) by e32.co.us.ibm.com (192.168.1.132) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; Mon, 20 Nov 2017 12:47:08 -0700 Received: from b03ledav006.gho.boulder.ibm.com (b03ledav006.gho.boulder.ibm.com [9.17.130.237]) by b03cxnp08026.gho.boulder.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id vAKJl7n958589278; Mon, 20 Nov 2017 12:47:07 -0700 Received: from b03ledav006.gho.boulder.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id D9495C603E; Mon, 20 Nov 2017 12:47:07 -0700 (MST) Received: from oc3016140333.ibm.com (unknown [9.41.174.252]) by b03ledav006.gho.boulder.ibm.com (Postfix) with ESMTP id 57FC6C6037; Mon, 20 Nov 2017 12:47:07 -0700 (MST) From: Eddie James To: linux-kernel@vger.kernel.org Cc: gregkh@linuxfoundation.org, devicetree@vger.kernel.org, robh+dt@kernel.org, mark.rutland@arm.com, bradleyb@fuzziesquirrel.com, cbostic@linux.vnet.ibm.com, joel@jms.id.au, eajames@linux.vnet.ibm.com, "Edward A. James" Subject: [PATCH v5 4/8] drivers/fsi: sbefifo: Add in-kernel API Date: Mon, 20 Nov 2017 13:46:53 -0600 X-Mailer: git-send-email 1.8.3.1 In-Reply-To: <1511207217-14075-1-git-send-email-eajames@linux.vnet.ibm.com> References: <1511207217-14075-1-git-send-email-eajames@linux.vnet.ibm.com> X-TM-AS-GCONF: 00 x-cbid: 17112019-0004-0000-0000-0000133FC776 X-IBM-SpamModules-Scores: X-IBM-SpamModules-Versions: BY=3.00008100; HX=3.00000241; KW=3.00000007; PH=3.00000004; SC=3.00000240; SDB=6.00948744; UDB=6.00479090; IPR=6.00729025; BA=6.00005702; NDR=6.00000001; ZLA=6.00000005; ZF=6.00000009; ZB=6.00000000; ZP=6.00000000; ZH=6.00000000; ZU=6.00000002; MB=3.00018111; XFM=3.00000015; UTC=2017-11-20 19:47:11 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 17112019-0005-0000-0000-000084F39F3B Message-Id: <1511207217-14075-5-git-send-email-eajames@linux.vnet.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10432:,, definitions=2017-11-20_11:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=1 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 impostorscore=0 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1709140000 definitions=main-1711200264 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Edward A. James" Refactor the user interface of the SBEFIFO driver to allow for an in-kernel read/write API. Add exported functions for other drivers to call, and add an include file with those functions. Also parse the device tree for child nodes and create child platform devices accordingly. Signed-off-by: Edward A. James --- drivers/fsi/fsi-sbefifo.c | 137 +++++++++++++++++++++++++++++++++++++------- include/linux/fsi-sbefifo.h | 30 ++++++++++ 2 files changed, 146 insertions(+), 21 deletions(-) create mode 100644 include/linux/fsi-sbefifo.h diff --git a/drivers/fsi/fsi-sbefifo.c b/drivers/fsi/fsi-sbefifo.c index fed3739..b622c70 100644 --- a/drivers/fsi/fsi-sbefifo.c +++ b/drivers/fsi/fsi-sbefifo.c @@ -15,12 +15,16 @@ #include #include #include +#include #include #include #include #include #include #include +#include +#include +#include #include #include #include @@ -92,6 +96,7 @@ struct sbefifo_client { struct list_head xfrs; struct sbefifo *dev; struct kref kref; + unsigned long f_flags; }; static DEFINE_IDA(sbefifo_ida); @@ -541,6 +546,7 @@ static int sbefifo_open(struct inode *inode, struct file *file) return -ENOMEM; file->private_data = client; + client->f_flags = file->f_flags; return 0; } @@ -580,10 +586,9 @@ static bool sbefifo_read_ready(struct sbefifo *sbefifo, (xfr && test_bit(SBEFIFO_XFR_COMPLETE, &xfr->flags)); } -static ssize_t sbefifo_read(struct file *file, char __user *buf, size_t len, - loff_t *offset) +static ssize_t sbefifo_read_common(struct sbefifo_client *client, + char __user *ubuf, char *kbuf, size_t len) { - struct sbefifo_client *client = file->private_data; struct sbefifo *sbefifo = client->dev; struct sbefifo_xfr *xfr; size_t n; @@ -592,7 +597,7 @@ static ssize_t sbefifo_read(struct file *file, char __user *buf, size_t len, if ((len >> 2) << 2 != len) return -EINVAL; - if ((file->f_flags & O_NONBLOCK) && !sbefifo_xfr_rsp_pending(client)) + if ((client->f_flags & O_NONBLOCK) && !sbefifo_xfr_rsp_pending(client)) return -EAGAIN; sbefifo_get_client(client); @@ -610,9 +615,13 @@ static ssize_t sbefifo_read(struct file *file, char __user *buf, size_t len, n = min_t(size_t, n, len); - if (copy_to_user(buf, READ_ONCE(client->rbuf.rpos), n)) { - ret = -EFAULT; - goto out; + if (ubuf) { + if (copy_to_user(ubuf, READ_ONCE(client->rbuf.rpos), n)) { + ret = -EFAULT; + goto out; + } + } else { + memcpy(kbuf, READ_ONCE(client->rbuf.rpos), n); } if (sbefifo_buf_readnb(&client->rbuf, n)) { @@ -644,6 +653,14 @@ static ssize_t sbefifo_read(struct file *file, char __user *buf, size_t len, return ret; } +static ssize_t sbefifo_read(struct file *file, char __user *buf, size_t len, + loff_t *offset) +{ + struct sbefifo_client *client = file->private_data; + + return sbefifo_read_common(client, buf, NULL, len); +} + static bool sbefifo_write_ready(struct sbefifo *sbefifo, struct sbefifo_xfr *xfr, struct sbefifo_client *client, size_t *n) @@ -656,11 +673,11 @@ static bool sbefifo_write_ready(struct sbefifo *sbefifo, return READ_ONCE(sbefifo->rc) || (next == xfr && *n); } -static ssize_t sbefifo_write(struct file *file, const char __user *buf, - size_t len, loff_t *offset) +static ssize_t sbefifo_write_common(struct sbefifo_client *client, + const char __user *ubuf, const char *kbuf, + size_t len) { unsigned long flags; - struct sbefifo_client *client = file->private_data; struct sbefifo *sbefifo = client->dev; struct sbefifo_xfr *xfr; ssize_t ret = 0; @@ -678,7 +695,7 @@ static ssize_t sbefifo_write(struct file *file, const char __user *buf, spin_lock_irqsave(&sbefifo->lock, flags); xfr = sbefifo_next_xfr(sbefifo); /* next xfr to be executed */ - if ((file->f_flags & O_NONBLOCK) && xfr && n < len) { + if ((client->f_flags & O_NONBLOCK) && xfr && n < len) { spin_unlock_irqrestore(&sbefifo->lock, flags); ret = -EAGAIN; goto out; @@ -719,16 +736,22 @@ static ssize_t sbefifo_write(struct file *file, const char __user *buf, n = min_t(size_t, n, len); - if (copy_from_user(READ_ONCE(client->wbuf.wpos), buf, n)) { - set_bit(SBEFIFO_XFR_CANCEL, &xfr->flags); - sbefifo_get(sbefifo); - if (mod_timer(&sbefifo->poll_timer, jiffies)) - sbefifo_put(sbefifo); - ret = -EFAULT; - goto out; - } + if (ubuf) { + if (copy_from_user(READ_ONCE(client->wbuf.wpos), ubuf, + n)) { + set_bit(SBEFIFO_XFR_CANCEL, &xfr->flags); + sbefifo_get(sbefifo); + if (mod_timer(&sbefifo->poll_timer, jiffies)) + sbefifo_put(sbefifo); + ret = -EFAULT; + goto out; + } - buf += n; + ubuf += n; + } else { + memcpy(READ_ONCE(client->wbuf.wpos), kbuf, n); + kbuf += n; + } sbefifo_buf_wrotenb(&client->wbuf, n); len -= n; @@ -752,6 +775,14 @@ static ssize_t sbefifo_write(struct file *file, const char __user *buf, return ret; } +static ssize_t sbefifo_write(struct file *file, const char __user *buf, + size_t len, loff_t *offset) +{ + struct sbefifo_client *client = file->private_data; + + return sbefifo_write_common(client, buf, NULL, len); +} + static int sbefifo_release(struct inode *inode, struct file *file) { struct sbefifo_client *client = file->private_data; @@ -771,6 +802,56 @@ static int sbefifo_release(struct inode *inode, struct file *file) .release = sbefifo_release, }; +struct sbefifo_client *sbefifo_drv_open(struct device *dev, + unsigned long flags) +{ + struct sbefifo_client *client; + struct sbefifo *sbefifo = dev_get_drvdata(dev); + + if (!sbefifo) + return NULL; + + client = sbefifo_new_client(sbefifo); + if (client) + client->f_flags = flags; + + return client; +} +EXPORT_SYMBOL_GPL(sbefifo_drv_open); + +int sbefifo_drv_read(struct sbefifo_client *client, char *buf, size_t len) +{ + return sbefifo_read_common(client, NULL, buf, len); +} +EXPORT_SYMBOL_GPL(sbefifo_drv_read); + +int sbefifo_drv_write(struct sbefifo_client *client, const char *buf, + size_t len) +{ + return sbefifo_write_common(client, NULL, buf, len); +} +EXPORT_SYMBOL_GPL(sbefifo_drv_write); + +void sbefifo_drv_release(struct sbefifo_client *client) +{ + if (!client) + return; + + sbefifo_put_client(client); +} +EXPORT_SYMBOL_GPL(sbefifo_drv_release); + +static int sbefifo_unregister_child(struct device *dev, void *data) +{ + struct platform_device *child = to_platform_device(dev); + + of_device_unregister(child); + if (dev->of_node) + of_node_clear_flag(dev->of_node, OF_POPULATED); + + return 0; +} + static int sbefifo_request_reset(struct sbefifo *sbefifo) { int ret; @@ -805,8 +886,11 @@ static int sbefifo_probe(struct device *dev) { struct fsi_device *fsi_dev = to_fsi_dev(dev); struct sbefifo *sbefifo; + struct device_node *np; + struct platform_device *child; + char child_name[32]; u32 up, down; - int ret; + int ret, child_idx = 0; dev_dbg(dev, "Found sbefifo device\n"); sbefifo = kzalloc(sizeof(*sbefifo), GFP_KERNEL); @@ -857,6 +941,16 @@ static int sbefifo_probe(struct device *dev) return ret; } + /* create platform devs for dts child nodes (occ, etc) */ + for_each_available_child_of_node(dev->of_node, np) { + snprintf(child_name, sizeof(child_name), "%s-dev%d", + sbefifo->name, child_idx++); + child = of_platform_device_create(np, child_name, dev); + if (!child) + dev_warn(dev, "failed to create child %s dev\n", + child_name); + } + dev_set_drvdata(dev, sbefifo); return 0; @@ -883,6 +977,7 @@ static int sbefifo_remove(struct device *dev) wake_up_all(&sbefifo->wait); misc_deregister(&sbefifo->mdev); + device_for_each_child(dev, NULL, sbefifo_unregister_child); ida_simple_remove(&sbefifo_ida, sbefifo->idx); diff --git a/include/linux/fsi-sbefifo.h b/include/linux/fsi-sbefifo.h new file mode 100644 index 0000000..8e55891 --- /dev/null +++ b/include/linux/fsi-sbefifo.h @@ -0,0 +1,30 @@ +/* + * SBEFIFO FSI Client device driver + * + * Copyright (C) IBM Corporation 2017 + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License version 2 as + * published by the Free Software Foundation. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERGCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + */ + +#ifndef LINUX_FSI_SBEFIFO_H +#define LINUX_FSI_SBEFIFO_H + +struct device; +struct sbefifo_client; + +extern struct sbefifo_client *sbefifo_drv_open(struct device *dev, + unsigned long flags); +extern int sbefifo_drv_read(struct sbefifo_client *client, char *buf, + size_t len); +extern int sbefifo_drv_write(struct sbefifo_client *client, const char *buf, + size_t len); +extern void sbefifo_drv_release(struct sbefifo_client *client); + +#endif /* LINUX_FSI_SBEFIFO_H */ -- 1.8.3.1 From 1585179296262955489@xxx Mon Nov 27 01:06:21 +0000 2017 X-GM-THRID: 1585179296262955489 X-Gmail-Labels: Inbox,Category Forums,HistoricalUnread