From patchwork Tue Sep 26 12:07:04 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 114249 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3748129qgf; Tue, 26 Sep 2017 05:07:32 -0700 (PDT) X-Received: by 10.99.122.22 with SMTP id v22mr10562941pgc.394.1506427652322; Tue, 26 Sep 2017 05:07:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506427652; cv=none; d=google.com; s=arc-20160816; b=0TQ/dp7cMFz4Vw8EKtlxcqG8r4QS237FsjeGfKZ7jj+m9wNrpz9uJRPOdR07+MPOpN iAyGQDIaSv8Qwf95di4LTNMvjaflhXRYwYs57UeokeJGRoyr6O2TQ9zLDK3hiPagMQQk c909HerzSFNocQAAe7Ayd0m3wpiZQumtjc/tyc//Ojpz8gFihT1cnL+pQ3Bal0Zb+Dd+ GP/P5TadiRD5X3SYKx6x9JRVz9+MMrPmjSZ9e18i3yN5mzizfJTS5xiMZVqe/ggSy5yt JhYlrltffArVC0tn0X3P1AJmK8fDwU6caHZId0RR/++XFkHGDh4zq4bUvVs4qkJZ4HpD FCkw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:cc:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:delivered-to :arc-authentication-results; bh=jtTbrnGspbIUaZToJu9YAOm4uMkk9siYcECrWOfRYgU=; b=FEBhcdAyHSTviV23Fxnxe2IhqGQgQwPJy4TBQgt1ty9srCimXxzUsqcLVZZokUnrRa yJAxU4NC2OfYWn8cG7fB/X/waHtKjiMhm2JwLl8E+my6LasOpbL9p3Fr+emaXYEzfzIi RWzy5eLEkPpCLXck/+UgXqItebgzqK5a4wWwlWohAFfHNXmcW8gZihloe5EuE/Szal4i Qe8ItntPXVDWdEtZFuzneP8NrLnUSGKytoBGp15TUBBvvPnUBe+01361J1UIAnLKRO7D VJnhMygifHAWKiJZRvjCr1FsqBEmOAAvB5gemS8bX3efSDu1pKt2KJWBWZL1armjZaZe exiA== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=N2F3XPZa; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id 10si5576989pfj.239.2017.09.26.05.07.32 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Sep 2017 05:07:32 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=N2F3XPZa; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id E3C596E52E; Tue, 26 Sep 2017 12:07:30 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x235.google.com (mail-wm0-x235.google.com [IPv6:2a00:1450:400c:c09::235]) by gabe.freedesktop.org (Postfix) with ESMTPS id 88F986E52E for ; Tue, 26 Sep 2017 12:07:29 +0000 (UTC) Received: by mail-wm0-x235.google.com with SMTP id b195so7084952wmb.5 for ; Tue, 26 Sep 2017 05:07:29 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=E3q4+DnoJTevrgOB3IhP71fBhH7C18Z06tfGTavzLvI=; b=N2F3XPZajV6KvM2r5ctBENhJ+xKMtMINsAMIt/Nbze+WMMyYQ3u/02bKVEa91baBRJ 4XNaNXA05reA8RYkJgXViocgD4z7rlkrDsqSr5s62XnFn2xKQK2hvQrtZ+0CENMJAlT5 dXX4TLQNtVRFdquBfYXACE79JV2yop9crrl1c= 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; bh=E3q4+DnoJTevrgOB3IhP71fBhH7C18Z06tfGTavzLvI=; b=FSI6n+q5PyXRDXot5u+NnVWTCpoN30I5nSrC2qcW+0BcXTDbr3iKJKwOgpaNhE/hBM /5eZOm3IR53nREYVdGKt9RrsdKuMscF6Th7VDkMv3Q9xhExKmNmE2i9mqVR2pokx+ZUa COyfWqgY1pjYiuRsWi75UvN7DLlByIb7WajXMJQKZ25q/+pKvNS0aT1OFn/LgGKS6awV txzsi8qEECdbIp9BSrkn6BRQQ4q4zE63aJ26S2WAB4C3OQEWHfskAKshoHQni/fKQ5wr SlMc3SVZtUxUVnt4dMWkjN3ePcYtcFIpuqsO5GpWWpCw535/r18F7rb1EYD9tkuXIdm5 TDtg== X-Gm-Message-State: AHPjjUhkCruJKEZ99FBeWmnd6E1nkNjLNK5rQ5rhi8ZlHWxL0zVLLop1 L0xO77yq9xCUOzLCy5x27/owlw== X-Google-Smtp-Source: AOwi7QBKHC5HizM6V8hTpTVhhSC+B6xy24oBGkwnYa4ML3tdSwzuiss8XTAN26uj7v0weccFf1WqJw== X-Received: by 10.28.218.209 with SMTP id r200mr2861957wmg.97.1506427648008; Tue, 26 Sep 2017 05:07:28 -0700 (PDT) Received: from lmecxl0911.lme.st.com ([80.215.129.224]) by smtp.gmail.com with ESMTPSA id r6sm7815332wrg.40.2017.09.26.05.07.26 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Sep 2017 05:07:27 -0700 (PDT) From: Benjamin Gaignard To: labbott@redhat.com, sumit.semwal@linaro.org, gregkh@linuxfoundation.org, arve@android.com, riandrews@android.com, broonie@kernel.org, dan.carpenter@oracle.com Subject: [PATCH v4 1/2] staging: ion: simplify ioctl args checking function Date: Tue, 26 Sep 2017 14:07:04 +0200 Message-Id: <1506427625-19202-2-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506427625-19202-1-git-send-email-benjamin.gaignard@linaro.org> References: <1506427625-19202-1-git-send-email-benjamin.gaignard@linaro.org> Cc: devel@driverdev.osuosl.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Make arguments checking more easy to read. Signed-off-by: Benjamin Gaignard --- drivers/staging/android/ion/ion-ioctl.c | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/drivers/staging/android/ion/ion-ioctl.c b/drivers/staging/android/ion/ion-ioctl.c index d9f8b14..e26b786 100644 --- a/drivers/staging/android/ion/ion-ioctl.c +++ b/drivers/staging/android/ion/ion-ioctl.c @@ -27,19 +27,18 @@ union ion_ioctl_arg { static int validate_ioctl_arg(unsigned int cmd, union ion_ioctl_arg *arg) { - int ret = 0; - switch (cmd) { case ION_IOC_HEAP_QUERY: - ret = arg->query.reserved0 != 0; - ret |= arg->query.reserved1 != 0; - ret |= arg->query.reserved2 != 0; + if (arg->query.reserved0 || + arg->query.reserved1 || + arg->query.reserved2 ) + return -EINVAL; break; default: break; } - return ret ? -EINVAL : 0; + return 0; } /* fix up the cases where the ioctl direction bits are incorrect */ From patchwork Tue Sep 26 12:07:05 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 114250 Delivered-To: patch@linaro.org Received: by 10.140.106.117 with SMTP id d108csp3748203qgf; Tue, 26 Sep 2017 05:07:35 -0700 (PDT) X-Received: by 10.101.88.67 with SMTP id s3mr10576776pgr.285.1506427655786; Tue, 26 Sep 2017 05:07:35 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1506427655; cv=none; d=google.com; s=arc-20160816; b=oNToOhHZmDxi7XJ8txeHxCKarzlBxNKwno0QJBQzkfSWni5XBbABfb+0+KoMmbmFr0 V6OYq3UBk7IojZwXdlIrTtGylzP+TNi4THAwMYaOPo9gpx009OJb5uXUbm4eu8U5U7bQ we/ZbdhwG9xND7HH0w1IRU8o4DdeFVzMl8oNvF3nwy8ypR6PmKsV5cJ7iTFaONrZZA1G YM6xnA5GP6+5OTTeEWziNVl6hwScEzUiJymaWn6KTNvIbrYgn+FqrVQ1OlUchBhDTWti GawsFT47MZxxIBmZRgCO8g9cYaWbG8z9ROk5XeNoI3Dks3O5/Op8bWpwEm6qFRMtoX9m eV7Q== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:cc:references:in-reply-to:message-id:date :subject:to:from:dkim-signature:delivered-to :arc-authentication-results; bh=1CrcXhMTqgoyc5K23UbVcQsa7/jPplPO5n3NKX0woIg=; b=lhri9MNCCXK8ATVWarcqIQHx5WfQl0NvjhTpYSLGaMmdMgvMAbnKG+kfHyNcYB3rEn VWAmtt90Y83jbBHo77teO21TlAH7b0E3pu2fcsR8ixOmi/kSSe2pqZ/VpdtJy/S02ILK 8BRZ6UEcpKw9UKUvV122IwMMIrrtpAv3zVEE/VYQ2LZyw7PEpTYBPBtKfK/+uAFBiNxt dvrc3lWIN+2jgOEazlE+Vm+r6YT6GXfqGdchsoMMhzJrEb2/rmouTM6n2o778Gjj5Whq hy9yXisBRJHGQpwuNSEhJuVz2l9YqGgXlg6vV804k1xhxVJWO16b984b+OphCMyP8sXz cauw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=gAXhum8f; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id b1si5733688pld.79.2017.09.26.05.07.35 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 26 Sep 2017 05:07:35 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) client-ip=131.252.210.177; Authentication-Results: mx.google.com; dkim=neutral (body hash did not verify) header.i=@linaro.org header.s=google header.b=gAXhum8f; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 131.252.210.177 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 02CCF6E534; Tue, 26 Sep 2017 12:07:35 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x22f.google.com (mail-wm0-x22f.google.com [IPv6:2a00:1450:400c:c09::22f]) by gabe.freedesktop.org (Postfix) with ESMTPS id BD6A06E534 for ; Tue, 26 Sep 2017 12:07:31 +0000 (UTC) Received: by mail-wm0-x22f.google.com with SMTP id q124so7119648wmb.0 for ; Tue, 26 Sep 2017 05:07:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references; bh=9rym7jxC8SLp8ZgPSXFbUZ4RBbLn8JSxS873UZ+pJLg=; b=gAXhum8frOZAKDZv5KRhbmVLNQuRrKqQ8uJPC0KQmiTtG/O4qlLH1XKa1iBJtvAT1m xMd2hvhXg2BuYigQ+g65mRkPNXrrtdh7C0fi7YVwyCBDQceMzOp0Uuj6A4bw8fqE+c9P puvI6jLcukRDiP9B6c0s63hxag2YUqevFSzsc= 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; bh=9rym7jxC8SLp8ZgPSXFbUZ4RBbLn8JSxS873UZ+pJLg=; b=dPlA1M76QpAmg0L9SxNip5g2eZSHEV9e9LE4QYc7xf1hxyk6abcwABRvS+8GOZGXyx HdeO5j1lgWuaamOu06W3VDq6YW85csWTEdnB4IuBSqDykrmgSBorB4XA5dPiynEWUsWg JM9cWCnOKSjdt8GC1qK51qN5RXj2ntGVKEj9vaYvHm1xWqDhyD4Uk0iy0klFWc1SLan7 g4I0fhfvGOk/+gfkvDzF1ZbszDVZbvF1L1NXPxViZ+WQDVe9qPeFCB24KrcGo+HhGqko VcgRUcjmuwrZBqrV1TOhAREcyQ9G2y/6yA+ThLZXmmBwsHueJpLMtXBIF7qfh68PKFa+ n3Ow== X-Gm-Message-State: AHPjjUje/oO7swm9TKsaufUdoGrzdMBajJQA6GELnT9s8xgVEILPczaw RBGRB2FIsBAiojqYCsRG2yXfWw== X-Google-Smtp-Source: AOwi7QDvxG/3+f6crRzj3hLhgeP8meFOUy426jd4mE5H7dzroeR9LH2l4jpiI3RHDMzEdWrWI08LGQ== X-Received: by 10.28.54.162 with SMTP id y34mr2834676wmh.79.1506427650064; Tue, 26 Sep 2017 05:07:30 -0700 (PDT) Received: from lmecxl0911.lme.st.com ([80.215.129.224]) by smtp.gmail.com with ESMTPSA id r6sm7815332wrg.40.2017.09.26.05.07.28 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Tue, 26 Sep 2017 05:07:29 -0700 (PDT) From: Benjamin Gaignard To: labbott@redhat.com, sumit.semwal@linaro.org, gregkh@linuxfoundation.org, arve@android.com, riandrews@android.com, broonie@kernel.org, dan.carpenter@oracle.com Subject: [PATCH v4 2/2] staging: ion: create one device entry per heap Date: Tue, 26 Sep 2017 14:07:05 +0200 Message-Id: <1506427625-19202-3-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1506427625-19202-1-git-send-email-benjamin.gaignard@linaro.org> References: <1506427625-19202-1-git-send-email-benjamin.gaignard@linaro.org> Cc: devel@driverdev.osuosl.org, linux-api@vger.kernel.org, linux-kernel@vger.kernel.org, dri-devel@lists.freedesktop.org X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.18 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , MIME-Version: 1.0 Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Instead a getting one common device "/dev/ion" for all the heaps this patch allow to create one device entry ("/dev/ionX") per heap. Getting an entry per heap could allow to set security rules per heap and global ones for all heaps. Allocation requests will be only allowed if the mask_id match with device minor. Query request could be done on any of the devices. Signed-off-by: Benjamin Gaignard --- version 4: - add a configuration flag to switch between legacy Ion misc device and one device per heap version. version 3: - change ion_device_add_heap prototype to return a possible error. version 2: - simplify ioctl check like propose by Dan - make sure that we don't register more than ION_DEV_MAX heaps. drivers/staging/android/TODO | 1 - drivers/staging/android/ion/Kconfig | 8 ++++++++ drivers/staging/android/ion/ion-ioctl.c | 16 ++++++++++++++-- drivers/staging/android/ion/ion.c | 29 +++++++++++++++++++++++++++-- drivers/staging/android/ion/ion.h | 18 +++++++++++++++++- 5 files changed, 66 insertions(+), 6 deletions(-) diff --git a/drivers/staging/android/TODO b/drivers/staging/android/TODO index 5f14247..d770ffa 100644 --- a/drivers/staging/android/TODO +++ b/drivers/staging/android/TODO @@ -9,7 +9,6 @@ TODO: ion/ - Add dt-bindings for remaining heaps (chunk and carveout heaps). This would involve putting appropriate bindings in a memory node for Ion to find. - - Split /dev/ion up into multiple nodes (e.g. /dev/ion/heap0) - Better test framework (integration with VGEM was suggested) Please send patches to Greg Kroah-Hartman and Cc: diff --git a/drivers/staging/android/ion/Kconfig b/drivers/staging/android/ion/Kconfig index a517b2d..6bb07f6 100644 --- a/drivers/staging/android/ion/Kconfig +++ b/drivers/staging/android/ion/Kconfig @@ -10,6 +10,14 @@ menuconfig ION If you're not using Android its probably safe to say N here. +config ION_ONE_DEVICE_ENTRY_PER_HEAP + bool "Create one Ion device per heap" + depends on ION + help + Choose this option to have one device entry per heap. Each + device with named "/dev/ionX" where X is heap ID. + Selecting this option remove the legacy Ion misc device. + config ION_SYSTEM_HEAP bool "Ion system heap" depends on ION diff --git a/drivers/staging/android/ion/ion-ioctl.c b/drivers/staging/android/ion/ion-ioctl.c index e26b786..76492cc 100644 --- a/drivers/staging/android/ion/ion-ioctl.c +++ b/drivers/staging/android/ion/ion-ioctl.c @@ -25,7 +25,8 @@ union ion_ioctl_arg { struct ion_heap_query query; }; -static int validate_ioctl_arg(unsigned int cmd, union ion_ioctl_arg *arg) +static int validate_ioctl_arg(struct file *filp, + unsigned int cmd, union ion_ioctl_arg *arg) { switch (cmd) { case ION_IOC_HEAP_QUERY: @@ -34,6 +35,17 @@ static int validate_ioctl_arg(unsigned int cmd, union ion_ioctl_arg *arg) arg->query.reserved2 ) return -EINVAL; break; + +#ifdef CONFIG_ION_ONE_DEVICE_ENTRY_PER_HEAP + case ION_IOC_ALLOC: + { + int mask = 1 << iminor(filp->f_inode); + + if (!(arg->allocation.heap_id_mask & mask)) + return -EINVAL; + break; + } +#endif default: break; } @@ -69,7 +81,7 @@ long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) if (copy_from_user(&data, (void __user *)arg, _IOC_SIZE(cmd))) return -EFAULT; - ret = validate_ioctl_arg(cmd, &data); + ret = validate_ioctl_arg(filp, cmd, &data); if (WARN_ON_ONCE(ret)) return ret; diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 93e2c90..18a20d2 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -40,6 +40,10 @@ #include "ion.h" +#ifdef CONFIG_ION_ONE_DEVICE_ENTRY_PER_HEAP +#define ION_DEV_MAX 32 +#endif + static struct ion_device *internal_dev; static int heap_id; @@ -537,15 +541,30 @@ static int debug_shrink_get(void *data, u64 *val) DEFINE_SIMPLE_ATTRIBUTE(debug_shrink_fops, debug_shrink_get, debug_shrink_set, "%llu\n"); -void ion_device_add_heap(struct ion_heap *heap) +int ion_device_add_heap(struct ion_heap *heap) { struct dentry *debug_file; struct ion_device *dev = internal_dev; + int ret = 0; if (!heap->ops->allocate || !heap->ops->free) pr_err("%s: can not add heap with invalid ops struct.\n", __func__); +#ifdef CONFIG_ION_ONE_DEVICE_ENTRY_PER_HEAP + if (heap_id >= ION_DEV_MAX) + return -EBUSY; + + heap->ddev.devt = MKDEV(MAJOR(dev->devt), heap_id); + dev_set_name(&heap->ddev, "ion%d", heap_id); + device_initialize(&heap->ddev); + cdev_init(&heap->chrdev, &ion_fops); + heap->chrdev.owner = THIS_MODULE; + ret = cdev_device_add(&heap->chrdev, &heap->ddev); + if (ret < 0) + return ret; +#endif + spin_lock_init(&heap->free_lock); heap->free_list_size = 0; @@ -583,6 +602,8 @@ void ion_device_add_heap(struct ion_heap *heap) dev->heap_cnt++; up_write(&dev->lock); + + return ret; } EXPORT_SYMBOL(ion_device_add_heap); @@ -595,13 +616,17 @@ static int ion_device_create(void) if (!idev) return -ENOMEM; +#ifdef CONFIG_ION_ONE_DEVICE_ENTRY_PER_HEAP + ret = alloc_chrdev_region(&idev->devt, 0, ION_DEV_MAX, "ion"); +#else idev->dev.minor = MISC_DYNAMIC_MINOR; idev->dev.name = "ion"; idev->dev.fops = &ion_fops; idev->dev.parent = NULL; ret = misc_register(&idev->dev); +#endif if (ret) { - pr_err("ion: failed to register misc device.\n"); + pr_err("ion: unable to allocate device\n"); kfree(idev); return ret; } diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index 621e5f7..61ada2e 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -26,7 +26,12 @@ #include #include #include + +#ifdef CONFIG_ION_ONE_DEVICE_ENTRY_PER_HEAP +#include +#else #include +#endif #include "../uapi/ion.h" @@ -90,13 +95,18 @@ void ion_buffer_destroy(struct ion_buffer *buffer); /** * struct ion_device - the metadata of the ion device node + * @devt: Ion device if heap have own device entry * @dev: the actual misc device * @buffers: an rb tree of all the existing buffers * @buffer_lock: lock protecting the tree of buffers * @lock: rwsem protecting the tree of heaps and clients */ struct ion_device { +#ifdef CONFIG_ION_ONE_DEVICE_ENTRY_PER_HEAP + dev_t devt; +#else struct miscdevice dev; +#endif struct rb_root buffers; struct mutex buffer_lock; struct rw_semaphore lock; @@ -152,6 +162,8 @@ struct ion_heap_ops { * struct ion_heap - represents a heap in the system * @node: rb node to put the heap on the device's tree of heaps * @dev: back pointer to the ion_device + * @ddev: device structure + * @chrdev: associated character device * @type: type of heap * @ops: ops struct as above * @flags: flags @@ -176,6 +188,10 @@ struct ion_heap_ops { struct ion_heap { struct plist_node node; struct ion_device *dev; +#ifdef CONFIG_ION_ONE_DEVICE_ENTRY_PER_HEAP + struct device ddev; + struct cdev chrdev; +#endif enum ion_heap_type type; struct ion_heap_ops *ops; unsigned long flags; @@ -212,7 +228,7 @@ bool ion_buffer_fault_user_mappings(struct ion_buffer *buffer); * ion_device_add_heap - adds a heap to the ion device * @heap: the heap to add */ -void ion_device_add_heap(struct ion_heap *heap); +int ion_device_add_heap(struct ion_heap *heap); /** * some helpers for common operations on buffers using the sg_table