From patchwork Fri Feb 15 20:24:09 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 158546 Delivered-To: patches@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1112754jaa; Fri, 15 Feb 2019 12:24:17 -0800 (PST) X-Received: by 2002:a62:109b:: with SMTP id 27mr11393895pfq.227.1550262257317; Fri, 15 Feb 2019 12:24:17 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550262257; cv=none; d=google.com; s=arc-20160816; b=PR6heY7PAQOG+DWw/ZF6/VEs0y2QQDtNJEb64lMoYQ1nRMRjBH8mC0n7/eHbTs0uks Vw4WclFcniYUJ5iySotuDRt7a+UZYo9kg9ZX1zfv7oXZEPfrC0qTJI6POtEhglIJ5YwF CrrpFEkDiYi2Juo2zU4Mwt0RVdxlL0OAk2IKI6m4qsa6GHBT4P8kayQdOX56hWrC9nFt oFVyeKXRIO6/mOeXpehNkqNsjvupNB+Sot6BUnMnE9RyIsJL6KVWHkGJtB7tPaBalIeT 5/XaiGjtpPqAewT5ACCUPDncAejwQ1m91YLSc6McmaFgmvXv4BEQaA8mLlxD6fE/bsMW dVGw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=l8LmucLfEKB+cfAfRLnCfkwfcUHBvOoCjWKFJEb2a4A=; b=XV3lqmwfRz7Hb1yuC9PJWFlL21WZ3o6EUHKSv/7udyNKNl9m4uzBlXcny0rT+N3XGe i0L9GuLiEMJk9fWEz2NZ6Sge+iLgJ77Lde4ri92ZIiuwBD9im42IL6e54+PKJ0TcR6BJ LxkAtjS9CU7+Eh/1aTsB2HjMk7XBoP9C/23gCdPELCBD2I/k32BuCl2QyLbK9Az/kSjz rHnMUATTabO5WE6RC2WoqAiw69L0Hl3baqwMg66PAe0AWkfVGo2sDY15s6s9AVgJAmDj ypFarYfEHN3kxu0oCDIPoCiiMNAQKoexDPb1AFE9xvX8z2YQk7qD0XPGXRHrb3Lhldgx Kujg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W+qEui45; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id z13sor10213294pgp.62.2019.02.15.12.24.17 for (Google Transport Security); Fri, 15 Feb 2019 12:24:17 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=W+qEui45; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=l8LmucLfEKB+cfAfRLnCfkwfcUHBvOoCjWKFJEb2a4A=; b=W+qEui45OwZvRtcQVAV/tDyjyqZFIcovPkwDB9aPtRZK5sARVU5W2vJtKKtCLnJP+Q jwtK5ekpa8HCbN/fWCTrn/rW90oPL7+Wvim+nyRFr1GILoyYoKqjHiGgBGy21gdp9G4p Jp3p/Bza+ma4JERyQc3OFFGRJpeiPzz3k9yhJZAMth6J3OGmon2MlWNrmnm6pSbZC2Xy cpmX+QXoH05x37xJMc2RoNU2FbcpPxcE7CvDs/U6tike8Q+g/uq/UsKNzgfOUPnrPyP/ Yu02PRGWmdKIJW1gaDl1v4t5jrwCWOAORWEPcMMMxJdlhXl0+AcQmf20NtOvMItohMq3 EaKg== 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=l8LmucLfEKB+cfAfRLnCfkwfcUHBvOoCjWKFJEb2a4A=; b=NGNRr/zV3zv0jq9HSbdyIrVRrpMsDBOo1thdgaWs1cK7jVRLGsPULx77xnqMYwskCO 2+VdfxiJC8AKduLRvXeHYysQL3cSTrr4lkijvhOUcg52Ay7b13kaJFQLxVIc07UonpU4 gLbwv+/rx8z7A7GJApzAU49hZjox1/+9hv/osCEq0lTdRThUhiT3lfxd7zR2diWsptSu UBEH2yDi1MDHuR5Hlp70aRBsuqTt6hGEnOyY+vdP22S85iML3LXB98bxz+tAf3Q33XCt v20yE0dutyxVyDPJcOiWjs/ef9tnxLqt2irPMG1lfZsBCcEQ0W2nnohWDuwq4pMR4w1X HIww== X-Gm-Message-State: AHQUAubJ95HAkHCnpydz1mZqeBuveFdaaYvcZtPVRZcDt7LSzld+oEfJ ob7kC/zt1c+Pc39nSUYs2tFms5Yn X-Google-Smtp-Source: AHgI3IZwFDz9ufmc6empzvnFKyBRidpfEM0aaAU1Y497aFf7eV1LiCv/WiOWx0mEPWK7pYrL3osYBA== X-Received: by 2002:a63:545:: with SMTP id 66mr6933595pgf.102.1550262256890; Fri, 15 Feb 2019 12:24:16 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id l2sm7593340pgn.52.2019.02.15.12.24.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Feb 2019 12:24:15 -0800 (PST) From: John Stultz To: Laura Abbott Cc: John Stultz , Sumit Semwal , Liam Mark , Brian Starkey , "Andrew F . Davis" , Alistair Strachan , dri-devel@lists.freedesktop.org Subject: [EARLY RFC][PATCH 1/4] ion: Add ION_VERSION ioctl Date: Fri, 15 Feb 2019 12:24:09 -0800 Message-Id: <1550262252-15558-2-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550262252-15558-1-git-send-email-john.stultz@linaro.org> References: <1550262252-15558-1-git-send-email-john.stultz@linaro.org> With all the slight interface changes ion has had through its time in staging, keeping userland working properly has been a pain. Assuming more churn going forward, provide a proper version interface. Cc: Laura Abbott Cc: Sumit Semwal Cc: Liam Mark Cc: Brian Starkey Cc: Andrew F. Davis Cc: Alistair Strachan Cc: dri-devel@lists.freedesktop.org Signed-off-by: John Stultz --- drivers/staging/android/ion/ion-ioctl.c | 4 ++++ drivers/staging/android/ion/ion.h | 2 ++ drivers/staging/android/uapi/ion.h | 7 +++++++ 3 files changed, 13 insertions(+) -- 2.7.4 diff --git a/drivers/staging/android/ion/ion-ioctl.c b/drivers/staging/android/ion/ion-ioctl.c index a8d3cc4..458a9f2 100644 --- a/drivers/staging/android/ion/ion-ioctl.c +++ b/drivers/staging/android/ion/ion-ioctl.c @@ -13,6 +13,7 @@ union ion_ioctl_arg { struct ion_allocation_data allocation; struct ion_heap_query query; + u32 version; }; static int validate_ioctl_arg(unsigned int cmd, union ion_ioctl_arg *arg) @@ -86,6 +87,9 @@ long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) case ION_IOC_HEAP_QUERY: ret = ion_query_heaps(&data.query); break; + case ION_IOC_VERSION: + data.version = ION_VERSION; + break; default: return -ENOTTY; } diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index 47b594c..439e682 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -21,6 +21,8 @@ #include "../uapi/ion.h" +#define ION_VERSION 3 + /** * struct ion_platform_heap - defines a heap in the given platform * @type: type of the heap from ion_heap_type enum diff --git a/drivers/staging/android/uapi/ion.h b/drivers/staging/android/uapi/ion.h index 5d70098..c480448 100644 --- a/drivers/staging/android/uapi/ion.h +++ b/drivers/staging/android/uapi/ion.h @@ -124,4 +124,11 @@ struct ion_heap_query { #define ION_IOC_HEAP_QUERY _IOWR(ION_IOC_MAGIC, 8, \ struct ion_heap_query) +/** + * DOC: ION_IOC_VERSION - Get ION interface version + * + * Takes a u32 and returns the ION interface version + */ +#define ION_IOC_VERSION _IOR(ION_IOC_MAGIC, 9, u32) + #endif /* _UAPI_LINUX_ION_H */ From patchwork Fri Feb 15 20:24:10 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 158547 Delivered-To: patches@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1112787jaa; Fri, 15 Feb 2019 12:24:19 -0800 (PST) X-Received: by 2002:a17:902:7c94:: with SMTP id y20mr9257323pll.215.1550262258966; Fri, 15 Feb 2019 12:24:18 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550262258; cv=none; d=google.com; s=arc-20160816; b=ID34Xe1IJW/KxMeIADYyPZkDRNvmyCPU2TBcnw+Ke6cewLvTLqcNi/mLVKQ2JFfIew 60mTGXI5R0JCYeSFYXmGVh0e26vqt+r+Z3dcKc/XbSotQTWEseOuTcWU+dtXuMw8yMJ0 0DtZji9287PsiILMiP1CgWSvAIxRjwcHBWJBGXuv65d4Y89HE6fZqRlLhbZG1FjWP12y JeLILwo/SSXgqIjgoC6L+Z7Anqx1QbxRmL9gNrqMUw1zYhs4TFiPpm/wkNV9vx11V3vS hu938qcjCW84HQ0VtRGN+fzprQAWL/2C8DvcpaY161p11mgoXoCTFAYuJpYGVaWbx5tM g7PA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=qgSoL3sPUhUXrm+KHH2TQxC/dij0S3K2jiUD0UBuiec=; b=Wdlo7hE1E/bFKMU/B1fn9vVl26EhQhdGVmIEUVQCTX+bFnGd0n0RJNJ/fJdl5ePzpz aCMtM2j8S3oFbKNfqX6AiqNnHNj902AsBXuejdji3Mg+wW/3YZTnTPjWrDo9JJDO8n4G mx7WnAQGzik3M/7h6jJfusKs90XX0whlytSaG7pEuh6rajlJj4zb2jMg4kXk2ssrDzCa q45vs5nT4I8Yo+ai5ovRXriq57fYszCiSainafk0//4tiqk4oJKeP9VMMeWGhJ+r82+X P+ERXYBanQkD2CyNBToJy3Sg9DtELUNBopBp4zF+kEc265cJkf99flWaNU3a9uaKPuDE OE/A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xyT2Daga; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id b9sor10046882pgw.87.2019.02.15.12.24.18 for (Google Transport Security); Fri, 15 Feb 2019 12:24:18 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=xyT2Daga; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=qgSoL3sPUhUXrm+KHH2TQxC/dij0S3K2jiUD0UBuiec=; b=xyT2DagagGyByc7FoMJuoFKQ1YOXjHRdAtRQOYIvmOGjCtmtCX8p+tvm8qFMgQ40XP 8+OVuFjOfnCq3ubO/zie8qeS/APGuJCclzMGdRXIzETcjmoztHre+73VjKDE1nK7dXnf jSnqk6dpObuQwYI+ZXMP+jrjB7pxizohYJpFd7cHLb5Z7tMUshp9mqSRz2K1foR2nUfB PkrXCdm6+sHpg4h2Zf3QJs6qQ1nZCI4JBsyjIwSEdHhj8Y1qX2NlqlomJNqDgvafDrkw BWi3zuZksCfjlibKZhEY1AyymxUq4zLOi1c6rBPB2uO68cUGTUMVnY98nswcEZvfC7ac rdHQ== 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=qgSoL3sPUhUXrm+KHH2TQxC/dij0S3K2jiUD0UBuiec=; b=e6KwHKMRo262Tm/+IALV15GM1Jr4t7u5G/KEFD4rv2jSypK+poXdVcD4TxdXShtvsD /Lvl6fuioLK3ZWv99HmcGHq3qHsZCmslXmG9Hj3rCG5Nd/GFScgx2hpCYNWri0Y0npiI fS98d8lraI4DRWHFXFDROTK4GcFHkYEw32dx0GNPP9dss6+R22ADzsblyjq87/BXBtT8 yP8sFbQ5PzVEXLLn1SEC2NHBSOpzGJ0i9m7jLFeBnj2fY8ckt4xI0PZbIUsVnLtzN4iW uv+9TeMx9z1zHvolavWPcHdhn70Ss/FaKoWVJcGUdIlarYhBFqHEdElI/tIdU3Juw8kF 91Kg== X-Gm-Message-State: AHQUAub4UMDH3MV3GWiRIyZu2fBkqFjCmbsZOC5Nqwh8vADty0Q3mT3l fXo1AZ1OgfdxnnSCn/joCpfBTf+Y X-Google-Smtp-Source: AHgI3IabETWIuKQMQnYeypc6pgbawX8bsnEaBBLfbHArSSd43iihCGS5RxhuMS5vxUM8ZbmSsBHMrA== X-Received: by 2002:a63:e553:: with SMTP id z19mr7033729pgj.331.1550262258524; Fri, 15 Feb 2019 12:24:18 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id l2sm7593340pgn.52.2019.02.15.12.24.16 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Feb 2019 12:24:17 -0800 (PST) From: John Stultz To: Laura Abbott Cc: John Stultz , Sumit Semwal , Liam Mark , Brian Starkey , "Andrew F . Davis" , Alistair Strachan , dri-devel@lists.freedesktop.org Subject: [EARLY RFC][PATCH 2/4] ion: Initial hack to create per heap devices Date: Fri, 15 Feb 2019 12:24:10 -0800 Message-Id: <1550262252-15558-3-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550262252-15558-1-git-send-email-john.stultz@linaro.org> References: <1550262252-15558-1-git-send-email-john.stultz@linaro.org> One of the issues w/ the /dev/ion interface is that we have to provide the complexity of a heap query interface and we end up multiplexing all the heap access through that one interface via a bit mask (which currently limits the heaps to 32). There has been a long running todo to provide per-heap devices which would make the heap discovery/query interface "ls", and would allow for different heaps to have different permisisons and sepolicy rules. TODOs: * Android doesn't use udev so "ion_heaps/%s" names don't automatically create a /dev/ subdir. I need to rework from miscdev to creating a proper device class and add a "subsystem" entry for the DeviceHandler to match with * Each CMA region is exposed via a separate heap, not sure if this is desired or not, and we may need to improve the naming. Cc: Laura Abbott Cc: Sumit Semwal Cc: Liam Mark Cc: Brian Starkey Cc: Andrew F. Davis Cc: Alistair Strachan Cc: dri-devel@lists.freedesktop.org Signed-off-by: John Stultz --- drivers/staging/android/ion/ion-ioctl.c | 62 +++++++++++++++++++++++++++++++++ drivers/staging/android/ion/ion.c | 18 ++++++++++ drivers/staging/android/ion/ion.h | 2 ++ drivers/staging/android/uapi/ion.h | 28 +++++++++++++++ 4 files changed, 110 insertions(+) -- 2.7.4 diff --git a/drivers/staging/android/ion/ion-ioctl.c b/drivers/staging/android/ion/ion-ioctl.c index 458a9f2..ea8d263 100644 --- a/drivers/staging/android/ion/ion-ioctl.c +++ b/drivers/staging/android/ion/ion-ioctl.c @@ -12,6 +12,7 @@ union ion_ioctl_arg { struct ion_allocation_data allocation; + struct ion_heap_allocation_data heap_allocation; struct ion_heap_query query; u32 version; }; @@ -100,3 +101,64 @@ long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) } return ret; } + +long ion_heap_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) +{ + int ret = 0; + unsigned int dir; + union ion_ioctl_arg data; + + dir = ion_ioctl_dir(cmd); + + if (_IOC_SIZE(cmd) > sizeof(data)) + return -EINVAL; + + /* + * The copy_from_user is unconditional here for both read and write + * to do the validate. If there is no write for the ioctl, the + * buffer is cleared + */ + if (copy_from_user(&data, (void __user *)arg, _IOC_SIZE(cmd))) + return -EFAULT; + + ret = validate_ioctl_arg(cmd, &data); + if (ret) { + pr_warn_once("%s: ioctl validate failed\n", __func__); + return ret; + } + + if (!(dir & _IOC_WRITE)) + memset(&data, 0, sizeof(data)); + + switch (cmd) { + case ION_IOC_HEAP_ALLOC: + { + struct miscdevice *miscdev = filp->private_data; + struct ion_heap *heap; + int fd; + + heap = container_of(miscdev, struct ion_heap, heap_dev); + + fd = ion_alloc(data.heap_allocation.len, + (1 << heap->id), + data.heap_allocation.flags); + if (fd < 0) + return fd; + + data.heap_allocation.fd = fd; + + break; + } + case ION_IOC_VERSION: + data.version = ION_VERSION; + break; + default: + return -ENOTTY; + } + + if (dir & _IOC_READ) { + if (copy_to_user((void __user *)arg, &data, _IOC_SIZE(cmd))) + return -EFAULT; + } + return ret; +} diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 6f5afab..1f7c893 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -492,6 +492,14 @@ int ion_query_heaps(struct ion_heap_query *query) return ret; } +static const struct file_operations ion_heap_fops = { + .owner = THIS_MODULE, + .unlocked_ioctl = ion_heap_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = ion_heap_ioctl, +#endif +}; + static const struct file_operations ion_fops = { .owner = THIS_MODULE, .unlocked_ioctl = ion_ioctl, @@ -540,12 +548,22 @@ void ion_device_add_heap(struct ion_heap *heap) struct ion_device *dev = internal_dev; int ret; struct dentry *heap_root; + char *heap_name; char debug_name[64]; if (!heap->ops->allocate || !heap->ops->free) pr_err("%s: can not add heap with invalid ops struct.\n", __func__); + heap_name = kasprintf(GFP_KERNEL, "ion_heaps/%s", heap->name); + heap->heap_dev.name = heap_name; + heap->heap_dev.minor = MISC_DYNAMIC_MINOR; + heap->heap_dev.fops = &ion_heap_fops; + heap->heap_dev.parent = NULL; + ret = misc_register(&heap->heap_dev); + if (ret) + pr_err("ion: failed to register misc device.\n"); + spin_lock_init(&heap->free_lock); spin_lock_init(&heap->stat_lock); heap->free_list_size = 0; diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index 439e682..7ed4a6a 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -170,6 +170,7 @@ struct ion_heap_ops { */ struct ion_heap { struct plist_node node; + struct miscdevice heap_dev; struct ion_device *dev; enum ion_heap_type type; struct ion_heap_ops *ops; @@ -333,6 +334,7 @@ int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask, int nr_to_scan); long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); +long ion_heap_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); int ion_query_heaps(struct ion_heap_query *query); diff --git a/drivers/staging/android/uapi/ion.h b/drivers/staging/android/uapi/ion.h index c480448..20db09f 100644 --- a/drivers/staging/android/uapi/ion.h +++ b/drivers/staging/android/uapi/ion.h @@ -57,6 +57,25 @@ enum ion_heap_type { */ /** + * struct ion_heap_allocation_data - metadata passed from userspace for + * allocations + * @len: size of the allocation + * @heap_id_mask: mask of heap ids to allocate from + * @flags: flags passed to heap + * @handle: pointer that will be populated with a cookie to use to + * refer to this allocation + * + * Provided by userspace as an argument to the ioctl + */ +struct ion_heap_allocation_data { + __u64 len; + __u32 flags; + __u32 fd; + __u32 reserved0; + __u32 reserved1; +}; + +/** * struct ion_allocation_data - metadata passed from userspace for allocations * @len: size of the allocation * @heap_id_mask: mask of heap ids to allocate from @@ -131,4 +150,13 @@ struct ion_heap_query { */ #define ION_IOC_VERSION _IOR(ION_IOC_MAGIC, 9, u32) +/** + * DOC: ION_IOC_HEAP_ALLOC - allocate memory from heap + * + * Takes an ion_heap_allocation_data struct and returns it with the handle field + * populated with the opaque handle for the allocation. + */ +#define ION_IOC_HEAP_ALLOC _IOWR(ION_IOC_MAGIC, 10, \ + struct ion_heap_allocation_data) + #endif /* _UAPI_LINUX_ION_H */ From patchwork Fri Feb 15 20:24:11 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 158548 Delivered-To: patches@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1112811jaa; Fri, 15 Feb 2019 12:24:20 -0800 (PST) X-Received: by 2002:a63:cc41:: with SMTP id q1mr7115144pgi.323.1550262260429; Fri, 15 Feb 2019 12:24:20 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550262260; cv=none; d=google.com; s=arc-20160816; b=TM8vbj9cFZ0cdguj/QWr6m3wF9GzykmadlnZd2SOrbIRMsgjDS4pIu5e3oTesywn3h YGvdnJI7Kjsp0b3zG8n4ztFgik85jn9S/vFfypscPEC9BMSyBPmlpXJK4N6pvpMS6iiO RHe8ADIMOqyRYYsyZrIxavoDByYWe2hv9UUZpXwJLjrYuoAesIrtg+qA/Sl3NTz6yrMO ExrbreB86jTveBbXnnpP+YyDsUOWaNsk6MwuZ/hRfLMnSORDPfkWAE6ZwdTfqC8huMl3 /rueN2j7xwI6sSooq93lU5qjCfc5zA7n3JpyrNqBJFb6qe/IfOLaytFdJG87devB/F3o FtLw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=N5a5nZaqsWgGJm38LQouQeiDJ/DSJD63RRCa/mm8Ip8=; b=Hx0gcFEb8E8M4ng7H9zS1xHfklSrLH83lSRM+BVa1ef/avnAEflH7U4jLA4hm3Q4pU 7XaAqg8BR6g5Ru1fh+zhHMo4pnyeVmDqRxGosmIfgJamUyL2K94felkR4aZkhVPLI8sC Khqrfjvv80WqAg37+PqbZvDR/HlWfP8KBubifDuFt6sIkID6U8rT5DnBEyzYXm28GyN+ 8vBJFN+00Q0Hycv+QzasVbFpWhd6cQE8sUrWExpQWavlVfNkG2IpKnRCTO/ATE0MdCy/ IA1uZfKE11SUU18wE1BKGlvP5Wsg//fznFen///BJ80LjBthVq0vb0MMoU5NsAdnNk4y iW7A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gJHuN1JA; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id 75sor10061837pgc.15.2019.02.15.12.24.20 for (Google Transport Security); Fri, 15 Feb 2019 12:24:20 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=gJHuN1JA; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=N5a5nZaqsWgGJm38LQouQeiDJ/DSJD63RRCa/mm8Ip8=; b=gJHuN1JAxX5Ndch8U8vilfFEsjOsgsaFC9e50UdCpiVQLghsvvCjSOAsGtswpmYmu8 wTp6SX9RYSi9J31vk9xpgTI53od4d7g9ZOkuT5busILitYOCzbpkJ2pxeuVBa+u+cNoO YOiGjdmscJZHWdQOq8amMwmqVdZp3J5f28pGZz+VTWE2J7y6lOZiky74CiJUR2VI8khP 4ZJoQhU7llk/48ubblCLJc7ETr1ju1BqXB/ZnQ6yjNRNXUCRTz6kXncT0Fq+kT54wcfe lwWKHBVWIXLa0z8kHtIQYrWBiQtAuulgyg+vqKrgiDq65NS0GLTHNZZVLKfWL5qbCDhk Xx1w== 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=N5a5nZaqsWgGJm38LQouQeiDJ/DSJD63RRCa/mm8Ip8=; b=DnZLQrJ2dVRKvQNPAoD/lKqSy+5/hmyJO5M+wLy4JMSZbpXu1Vx1/knv2OJxId5DaL W6hEfKxzL1wOHdvjr1mYLrXzBfuLLxEO9kkI7OK7mD6fVvG3nbo0fN+kKgvMNSWNr+iJ y6zEmCih65LvdvfqsrROL6GXIn22MwOuEJu7ywxSgqus1VavLgCUOT9LMg54fiNsLk2m QuJsa+EzNVzPavSdp6u3KZf24jmEzbiH2i5xFbwZTVLtFr2aH/gXRfl/pUIGZ0ZliCSd kVfFrhJizcDKmJrFsCmNCdrWOaUcTSqNR8cmi5YP1xfrvpmVUfWI9A3mwI1plawSJrT8 CuBw== X-Gm-Message-State: AHQUAuZTDZ2BW7f3C7pt4IglBRZ9Jm+KtQEsrOcyW9OxAok3hw9e4Td+ zy/Oj5DpgJS6OofglV05sv8HHFrK X-Google-Smtp-Source: AHgI3Ia7PhtR7y3HyFo2loPhbkSaACN1YSiofUkgC390u4/IQkYp9FkDp9/lY5bLbZtNYx9uZNni3g== X-Received: by 2002:a63:1e17:: with SMTP id e23mr6984808pge.130.1550262260015; Fri, 15 Feb 2019 12:24:20 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id l2sm7593340pgn.52.2019.02.15.12.24.18 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Feb 2019 12:24:19 -0800 (PST) From: John Stultz To: Laura Abbott Cc: John Stultz , Sumit Semwal , Liam Mark , Brian Starkey , "Andrew F . Davis" , Alistair Strachan , dri-devel@lists.freedesktop.org Subject: [EARLY RFC][PATCH 3/4] ion: Add HEAP_INFO ioctl to be able to fetch heap type Date: Fri, 15 Feb 2019 12:24:11 -0800 Message-Id: <1550262252-15558-4-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550262252-15558-1-git-send-email-john.stultz@linaro.org> References: <1550262252-15558-1-git-send-email-john.stultz@linaro.org> The per-device heaps don't support HEAP_QUERY ioctl, since the name is provided in the devnode path and the heapid isn't useful with the new interface (one uses the fd of heapdevice). But, one missing bit of functionality is a way to find the heap type. So provide a HEAP_INFO ioctl which exposes the heap type out so there is the potential for some sort of dynamic heap matching/discovery. Most likely this IOCTL will be useful when extended to allow some sort of opaque constraint bitfield to be shared so userland can match heaps with devices in a fully dynamic way. Cc: Laura Abbott Cc: Sumit Semwal Cc: Liam Mark Cc: Brian Starkey Cc: Andrew F. Davis Cc: Alistair Strachan Cc: dri-devel@lists.freedesktop.org Signed-off-by: John Stultz --- drivers/staging/android/ion/ion-ioctl.c | 12 ++++++++++++ drivers/staging/android/uapi/ion.h | 22 ++++++++++++++++++++++ 2 files changed, 34 insertions(+) -- 2.7.4 diff --git a/drivers/staging/android/ion/ion-ioctl.c b/drivers/staging/android/ion/ion-ioctl.c index ea8d263..6db5969 100644 --- a/drivers/staging/android/ion/ion-ioctl.c +++ b/drivers/staging/android/ion/ion-ioctl.c @@ -14,6 +14,7 @@ union ion_ioctl_arg { struct ion_allocation_data allocation; struct ion_heap_allocation_data heap_allocation; struct ion_heap_query query; + struct ion_heap_info heap_info; u32 version; }; @@ -149,6 +150,17 @@ long ion_heap_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) break; } + case ION_IOC_HEAP_INFO: + { + struct miscdevice *miscdev = filp->private_data; + struct ion_heap *heap; + + heap = container_of(miscdev, struct ion_heap, heap_dev); + + data.heap_info.type = heap->type; + + break; + } case ION_IOC_VERSION: data.version = ION_VERSION; break; diff --git a/drivers/staging/android/uapi/ion.h b/drivers/staging/android/uapi/ion.h index 20db09f..1b3ca1e 100644 --- a/drivers/staging/android/uapi/ion.h +++ b/drivers/staging/android/uapi/ion.h @@ -111,6 +111,19 @@ struct ion_heap_data { }; /** + * struct ion_heap_info - Info about the heap + * + */ +struct ion_heap_info { + __u32 type; + __u32 reserved0; + __u32 reserved1; + __u32 reserved2; + __u32 reserved3; + __u32 reserved4; +}; + +/** * struct ion_heap_query - collection of data about all heaps * @cnt - total number of heaps to be copied * @heaps - buffer to copy heap data @@ -159,4 +172,13 @@ struct ion_heap_query { #define ION_IOC_HEAP_ALLOC _IOWR(ION_IOC_MAGIC, 10, \ struct ion_heap_allocation_data) +/** + * DOC: ION_IOC_HEAP_INFO - allocate memory from heap + * + * Takes an ion_heap_query structure and populates information about + * available Ion heaps. + */ +#define ION_IOC_HEAP_INFO _IOWR(ION_IOC_MAGIC, 11, \ + struct ion_heap_allocation_data) + #endif /* _UAPI_LINUX_ION_H */ From patchwork Fri Feb 15 20:24:12 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: John Stultz X-Patchwork-Id: 158549 Delivered-To: patches@linaro.org Received: by 2002:a02:48:0:0:0:0:0 with SMTP id 69csp1112835jaa; Fri, 15 Feb 2019 12:24:22 -0800 (PST) X-Received: by 2002:a17:902:22f:: with SMTP id 44mr12005407plc.137.1550262262098; Fri, 15 Feb 2019 12:24:22 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1550262262; cv=none; d=google.com; s=arc-20160816; b=cByWMHPRbku1e1Ryd4SqvXT9qgZwfRk9GNLE6Whg/ASOZ9czrqoE0x8heOaKMFPIkH /r5AjkQEYAiAZsTQcNMghcwEqnZIzHQHz6Wx2Z4LnXvhjsStwjgEwL72BVL0wdWCZT51 Yci2aUy5mZBvXSrCRtuz+nQCDO/vTebm5V534hkM2UwQKq8HmuKDDQ2o5fg2VhM3oPkK XsNxC2r0fPONVP3Da5lrBti82Rg5v2y32lbuKsfvcYqfUiOjkPkrS6OkTpNakK5nPiFA jdLm73zNbHMuEajP61ck2OlVP0FWont4YwUPHb+cyiz0WYNIPKf8dA5vIqMAgk4PhVxy p2Ig== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=Q5G2GKGbywqAdnaJODcSwGYr0iOLzvSrGO5crfVUvyk=; b=EIEYB0nCPnN0a8Pdm+W7GGWJCW7HFkhWYY2W9xFHE942i4OADoGhryi3qK4HxF4t9y c89yD8/skY8r99OK3ggxu8AIuJexjNrL4I2UyYfaHgFyIdChcBty9CF7If00Uml4k4p4 pP3yIyzsFS56sCEfu3UUWtjesltC0J4QwQndxXTowpSFUKNXrQXTlFjhFDUl6o62udUJ FtuL277wBsfslqXN5kg5x3BxEDj6IHq8KVOAcJ2/TaJBdDK+6N+xzkr4Ae/6pjAkXRPU 24PT9PQqODtILDYxe1nqEc6jfXobWrSFXIyTASjmdp8ksJpXgZq5olWG2cWcQ1YRrFBI p52A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QN4tdNTX; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from mail-sor-f65.google.com (mail-sor-f65.google.com. [209.85.220.65]) by mx.google.com with SMTPS id x13sor10619999pge.29.2019.02.15.12.24.22 for (Google Transport Security); Fri, 15 Feb 2019 12:24:22 -0800 (PST) Received-SPF: pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) client-ip=209.85.220.65; Authentication-Results: mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=QN4tdNTX; spf=pass (google.com: domain of john.stultz@linaro.org designates 209.85.220.65 as permitted sender) smtp.mailfrom=john.stultz@linaro.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org 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=Q5G2GKGbywqAdnaJODcSwGYr0iOLzvSrGO5crfVUvyk=; b=QN4tdNTXPKeyZUXD9Rd25oxEJMMZuwjVgauQFc4/FdPSUsI1l5NZfav2NtbcPzz7j0 eB7cF33o6naOZVbfaex4f8PsN0jvCYikdYtePTqjz0yO2Xp5OYpiBUPIayipPEdz406W nZw04FjZ4tfz0FtzRVXkdS5W7fnRxsm1lijeUfS6P0hMbRu61WACGw91ERljXkXPAryH 5MRoHsxRfyXYq42tjUV7zv5mnXLdDY+R7N7xQltppz9yOoaojY4zAWdkZnZzqy5jCwwm Qfr2n3aBrWXLggG6/XR7qNQIhkAKvK73AwX7bu71RnNMe1V8c5VW2CzfVDb1C974HWyJ LVpA== 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=Q5G2GKGbywqAdnaJODcSwGYr0iOLzvSrGO5crfVUvyk=; b=n00MnPciNSr1g/AeUsclXsqonkyzdpf+TcBuqxK5lTl5IIyoVh1jpPs1I/f0L1z3S8 UpiC7+c4/0ECVXUCk8UCHQa2aNTflq1TnKYEwY0yo0wV24mTt95KRR1WTxTTFtrqHFhk s4si9l8GvBz7Eupp85CVdV/qsCmnvAm69SkLADlfP14mzdxK7hxr4W5FETI/V2YDMbBv 3KUOQl3eZcHe7JaGtb81Vh2jTqtEd8bdY8IKQiwvdJWlxRtPSniq+8Gvle9Aeg5U1jtA c+FvMl47cV97zy5W43Y1bT/YQV/Uf/gywAG9jZHAE6rEWOO7KH1kGpQNR0KqQDZnHykb TR7Q== X-Gm-Message-State: AHQUAuZGYZU9Ot/HJ++ADvpTAAH0rZIXjT4wW7lZgzzWg7RlsF6r8CAj VE55UeSdTx9ICnSAsiyP8eeiFtuY X-Google-Smtp-Source: AHgI3IZ4x7fp44gShXXsEXVj8S70EIJVnisXDbNNmgEjjNVjSCGYBrGpt0dPYK9Wjo5lFYYA7PjeYA== X-Received: by 2002:a63:8b4b:: with SMTP id j72mr7040440pge.100.1550262261718; Fri, 15 Feb 2019 12:24:21 -0800 (PST) Return-Path: Received: from localhost.localdomain ([2601:1c2:680:1319:4e72:b9ff:fe99:466a]) by smtp.gmail.com with ESMTPSA id l2sm7593340pgn.52.2019.02.15.12.24.20 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 15 Feb 2019 12:24:20 -0800 (PST) From: John Stultz To: Laura Abbott Cc: John Stultz , Sumit Semwal , Liam Mark , Brian Starkey , "Andrew F . Davis" , Alistair Strachan , dri-devel@lists.freedesktop.org Subject: [EARLY RFC][PATCH 4/4] ion: Make "legacy" /dev/ion support optional Date: Fri, 15 Feb 2019 12:24:12 -0800 Message-Id: <1550262252-15558-5-git-send-email-john.stultz@linaro.org> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1550262252-15558-1-git-send-email-john.stultz@linaro.org> References: <1550262252-15558-1-git-send-email-john.stultz@linaro.org> Add a config option to make the "legacy" /dev/ion interface optional. Not yet clear if this will come out of staging or not, but to help with the transition. Cc: Laura Abbott Cc: Sumit Semwal Cc: Liam Mark Cc: Brian Starkey Cc: Andrew F. Davis Cc: Alistair Strachan Cc: dri-devel@lists.freedesktop.org Signed-off-by: John Stultz --- drivers/staging/android/ion/Kconfig | 7 ++++++ drivers/staging/android/ion/ion-ioctl.c | 2 ++ drivers/staging/android/ion/ion.c | 43 +++++++++++++++++++++------------ drivers/staging/android/ion/ion.h | 2 ++ 4 files changed, 39 insertions(+), 15 deletions(-) -- 2.7.4 diff --git a/drivers/staging/android/ion/Kconfig b/drivers/staging/android/ion/Kconfig index 0fdda6f..7f5a0b2 100644 --- a/drivers/staging/android/ion/Kconfig +++ b/drivers/staging/android/ion/Kconfig @@ -42,3 +42,10 @@ config ION_CMA_HEAP Choose this option to enable CMA heaps with Ion. This heap is backed by the Contiguous Memory Allocator (CMA). If your system has these regions, you should say Y here. + +config ION_COMPAT_INTERFACE + bool "Legacy /dev/ion interface support" + depends on ION + help + Choose this option to enable the legacy /dev/ion interface which + provides compatibility with userspace designed for 4.12+ kernels diff --git a/drivers/staging/android/ion/ion-ioctl.c b/drivers/staging/android/ion/ion-ioctl.c index 6db5969..427980c 100644 --- a/drivers/staging/android/ion/ion-ioctl.c +++ b/drivers/staging/android/ion/ion-ioctl.c @@ -43,6 +43,7 @@ static unsigned int ion_ioctl_dir(unsigned int cmd) } } +#ifdef CONFIG_ION_COMPAT_INTERFACE long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { int ret = 0; @@ -102,6 +103,7 @@ long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) } return ret; } +#endif long ion_heap_ioctl(struct file *filp, unsigned int cmd, unsigned long arg) { diff --git a/drivers/staging/android/ion/ion.c b/drivers/staging/android/ion/ion.c index 1f7c893..9a73526 100644 --- a/drivers/staging/android/ion/ion.c +++ b/drivers/staging/android/ion/ion.c @@ -500,14 +500,6 @@ static const struct file_operations ion_heap_fops = { #endif }; -static const struct file_operations ion_fops = { - .owner = THIS_MODULE, - .unlocked_ioctl = ion_ioctl, -#ifdef CONFIG_COMPAT - .compat_ioctl = ion_ioctl, -#endif -}; - static int debug_shrink_set(void *data, u64 val) { struct ion_heap *heap = data; @@ -619,15 +611,19 @@ void ion_device_add_heap(struct ion_heap *heap) } EXPORT_SYMBOL(ion_device_add_heap); -static int ion_device_create(void) +#ifdef CONFIG_ION_COMPAT_INTERFACE +static const struct file_operations ion_fops = { + .owner = THIS_MODULE, + .unlocked_ioctl = ion_ioctl, +#ifdef CONFIG_COMPAT + .compat_ioctl = ion_ioctl, +#endif +}; + +static int ion_create_legacy_interface(struct ion_device *idev) { - struct ion_device *idev; int ret; - idev = kzalloc(sizeof(*idev), GFP_KERNEL); - if (!idev) - return -ENOMEM; - idev->dev.minor = MISC_DYNAMIC_MINOR; idev->dev.name = "ion"; idev->dev.fops = &ion_fops; @@ -636,8 +632,25 @@ static int ion_device_create(void) if (ret) { pr_err("ion: failed to register misc device.\n"); kfree(idev); - return ret; } + return ret; +} +#else +#define ion_create_legacy_interface(x) 0 +#endif + +static int ion_device_create(void) +{ + struct ion_device *idev; + int ret; + + idev = kzalloc(sizeof(*idev), GFP_KERNEL); + if (!idev) + return -ENOMEM; + + ret = ion_create_legacy_interface(idev); + if (ret) + return ret; idev->debug_root = debugfs_create_dir("ion", NULL); idev->buffers = RB_ROOT; diff --git a/drivers/staging/android/ion/ion.h b/drivers/staging/android/ion/ion.h index 7ed4a6a..a82178b 100644 --- a/drivers/staging/android/ion/ion.h +++ b/drivers/staging/android/ion/ion.h @@ -333,7 +333,9 @@ void ion_page_pool_free(struct ion_page_pool *pool, struct page *page); int ion_page_pool_shrink(struct ion_page_pool *pool, gfp_t gfp_mask, int nr_to_scan); +#ifdef CONFIG_ION_COMPAT_INTERFACE long ion_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); +#endif long ion_heap_ioctl(struct file *filp, unsigned int cmd, unsigned long arg); int ion_query_heaps(struct ion_heap_query *query);