Return-Path: Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1751866AbdISL6m (ORCPT ); Tue, 19 Sep 2017 07:58:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:15525 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751800AbdISL6k (ORCPT ); Tue, 19 Sep 2017 07:58:40 -0400 DMARC-Filter: OpenDMARC Filter v1.3.2 mx1.redhat.com 031D0C04B936 Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; dmarc=none (p=none dis=none) header.from=redhat.com Authentication-Results: ext-mx07.extmail.prod.ext.phx2.redhat.com; spf=fail smtp.mailfrom=marcandre.lureau@redhat.com From: marcandre.lureau@redhat.com To: linux-kernel@vger.kernel.org Cc: somlo@cmu.edu, qemu-devel@nongnu.org, mst@redhat.com, =?UTF-8?q?Marc-Andr=C3=A9=20Lureau?= Subject: [PATCH v2 4/4] RFC: fw_cfg: add DMA write operation in sysfs Date: Tue, 19 Sep 2017 13:58:14 +0200 Message-Id: <20170919115814.14724-5-marcandre.lureau@redhat.com> In-Reply-To: <20170919115814.14724-1-marcandre.lureau@redhat.com> References: <20170919115814.14724-1-marcandre.lureau@redhat.com> MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.31]); Tue, 19 Sep 2017 11:58:40 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Length: 1525 Lines: 47 From: Marc-André Lureau Since qemu 2.9, DMA write operations are allowed. However, usage of this interface from kernel or user-space is strongly discouraged by the maintainers. This patch is meant for experimentations for now. Signed-off-by: Marc-André Lureau --- drivers/firmware/qemu_fw_cfg.c | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/drivers/firmware/qemu_fw_cfg.c b/drivers/firmware/qemu_fw_cfg.c index 26152bfc7805..1ca3382e98df 100644 --- a/drivers/firmware/qemu_fw_cfg.c +++ b/drivers/firmware/qemu_fw_cfg.c @@ -524,9 +524,28 @@ static ssize_t fw_cfg_sysfs_read_raw(struct file *filp, struct kobject *kobj, return fw_cfg_read_blob(entry->f.select, buf, pos, count, true); } +static ssize_t fw_cfg_sysfs_write_raw(struct file *filp, struct kobject *kobj, + struct bin_attribute *bin_attr, + char *buf, loff_t pos, size_t count) +{ + struct fw_cfg_sysfs_entry *entry = to_entry(kobj); + + if (!fw_cfg_dma_enabled()) + return -ENOTSUPP; + + if (pos > entry->f.size) + return -EINVAL; + + if (count > entry->f.size - pos) + count = entry->f.size - pos; + + return fw_cfg_write_blob(entry->f.select, buf, pos, count); +} + static struct bin_attribute fw_cfg_sysfs_attr_raw = { - .attr = { .name = "raw", .mode = S_IRUSR }, + .attr = { .name = "raw", .mode = S_IRUSR | S_IWUSR }, .read = fw_cfg_sysfs_read_raw, + .write = fw_cfg_sysfs_write_raw, }; /* -- 2.14.1.146.gd35faa819