From patchwork Wed Sep 9 09:17:11 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Baptiste Reynal X-Patchwork-Id: 7145311 Return-Path: X-Original-To: patchwork-kvm@patchwork.kernel.org Delivered-To: patchwork-parsemail@patchwork1.web.kernel.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.136]) by patchwork1.web.kernel.org (Postfix) with ESMTP id 74E749F314 for ; Wed, 9 Sep 2015 09:21:20 +0000 (UTC) Received: from mail.kernel.org (localhost [127.0.0.1]) by mail.kernel.org (Postfix) with ESMTP id A54982064B for ; Wed, 9 Sep 2015 09:21:19 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id C4B5420959 for ; Wed, 9 Sep 2015 09:21:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1754822AbbIIJVP (ORCPT ); Wed, 9 Sep 2015 05:21:15 -0400 Received: from mail-wi0-f180.google.com ([209.85.212.180]:37007 "EHLO mail-wi0-f180.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752694AbbIIJUX (ORCPT ); Wed, 9 Sep 2015 05:20:23 -0400 Received: by wicfx3 with SMTP id fx3so14029116wic.0 for ; Wed, 09 Sep 2015 02:20:21 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20130820; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references; bh=MaWILX0s7YIRqBjd5ikPl0iUOmaw9ah1BxQ83ToCCEA=; b=mYdzShPM1Jw8DVKf1C+Gel6no/Pg3kUZR0dfAM6AQqVTZLfzJkQ9D0GUs4TleTDTHW qsFLn9e2mYXOLeIQ+RnUA2OM5f8ruTWR7ob2dml0YYYb9ln37KW8c38K3nYy4vAWplHz tvGEdoRRBgQ9OoGIPYspvDjP3kM2y35KZNAelfeIatJG4w/Z8ahKJbL5bbfwCRRe1KZT /col+A7KUwJYp/qzoqiKTPBAoYMT+66XcZ/uYIsf92cWHxPvPpguiHgazPsRU0oi4pp8 o4bbjj3NFdoz6JOK1jpzpDF90DLSeQZ3llsZV1zh9a7j9N1MmNQQDy3MkfB5Xz56ckXQ sNAw== X-Gm-Message-State: ALoCoQm9Fuzmv18/xi6A5NYF33FAStiZTmE7fHAn4bcnTbg+oQpSX0K5jJFNdaQU70f4ms7iQf27 X-Received: by 10.194.92.166 with SMTP id cn6mr56077283wjb.6.1441790421745; Wed, 09 Sep 2015 02:20:21 -0700 (PDT) Received: from localhost (LPuteaux-656-1-278-113.w80-15.abo.wanadoo.fr. [80.15.154.113]) by smtp.gmail.com with ESMTPSA id r19sm2806889wib.7.2015.09.09.02.20.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Wed, 09 Sep 2015 02:20:21 -0700 (PDT) From: Baptiste Reynal To: kvmarm@lists.cs.columbia.edu, iommu@lists.linux-foundation.org Cc: alex.williamson@redhat.com, christoffer.dall@linaro.org, eric.auger@linaro.org, tech@virtualopensystems.com, Antonios Motakis , Baptiste Reynal , kvm@vger.kernel.org (open list:VFIO PLATFORM DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [RFC PATCH v4 3/3] vfio: platform: return device properties as arrays of unsigned integers Date: Wed, 9 Sep 2015 11:17:11 +0200 Message-Id: <1441790231-22920-4-git-send-email-b.reynal@virtualopensystems.com> X-Mailer: git-send-email 2.5.1 In-Reply-To: <1441790231-22920-1-git-send-email-b.reynal@virtualopensystems.com> References: <1441790231-22920-1-git-send-email-b.reynal@virtualopensystems.com> Sender: kvm-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org X-Spam-Status: No, score=-6.9 required=5.0 tests=BAYES_00, RCVD_IN_DNSWL_HI, T_RP_MATCHES_RCVD, UNPARSEABLE_RELAY autolearn=unavailable version=3.3.1 X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on mail.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP From: Antonios Motakis Certain properties of a device are accessible as an array of unsigned integers, either u64, u32, u16, or u8. Let the VFIO user query this type of device properties. Signed-off-by: Antonios Motakis Signed-off-by: Baptiste Reynal --- drivers/vfio/platform/properties.c | 62 +++++++++++++++++++++++++++++++++++++- 1 file changed, 61 insertions(+), 1 deletion(-) diff --git a/drivers/vfio/platform/properties.c b/drivers/vfio/platform/properties.c index 8bf9c8f..625e2d3 100644 --- a/drivers/vfio/platform/properties.c +++ b/drivers/vfio/platform/properties.c @@ -70,7 +70,67 @@ static int dev_property_get_uint(struct device *dev, uint32_t *flags, char *name, uint32_t type, unsigned *lenp, void __user *datap, unsigned long datasz) { - return -EINVAL; + int ret, n; + u8 *out; + size_t sz; + int (*func)(const struct device *, const char *, void *, size_t) + = NULL; + + switch (type) { + case VFIO_DEV_PROPERTY_TYPE_U64: + sz = sizeof(u64); + func = (int (*)(const struct device *, + const char *, void *, size_t)) + device_property_read_u64_array; + break; + case VFIO_DEV_PROPERTY_TYPE_U32: + sz = sizeof(u32); + func = (int (*)(const struct device *, + const char *, void *, size_t)) + device_property_read_u32_array; + break; + case VFIO_DEV_PROPERTY_TYPE_U16: + sz = sizeof(u16); + func = (int (*)(const struct device *, + const char *, void *, size_t)) + device_property_read_u16_array; + break; + case VFIO_DEV_PROPERTY_TYPE_U8: + sz = sizeof(u8); + func = (int (*)(const struct device *, + const char *, void *, size_t)) + device_property_read_u8_array; + break; + + default: + return -EINVAL; + } + + /* get size of array */ + n = func(dev, name, NULL, 0); + if (n < 0) + return n; + + if (lenp) + *lenp = n * sz; + + if (n * sz > datasz) + return -EOVERFLOW; + + out = kcalloc(n, sz, GFP_KERNEL); + if (!out) + return -ENOMEM; + + ret = func(dev, name, out, n); + if (ret) + goto out; + + if (copy_to_user(datap, out, n * sz)) + ret = -EFAULT; + +out: + kfree(out); + return ret; } int vfio_platform_dev_properties(struct device *dev, uint32_t *flags,