From patchwork Fri Jan 20 15:32:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Benjamin Gaignard X-Patchwork-Id: 92092 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp118849obz; Fri, 20 Jan 2017 07:32:57 -0800 (PST) X-Received: by 10.99.127.28 with SMTP id a28mr12000922pgd.60.1484926377288; Fri, 20 Jan 2017 07:32:57 -0800 (PST) Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id d14si2864166plj.83.2017.01.20.07.32.57; Fri, 20 Jan 2017 07:32:57 -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; dkim=pass header.i=@linaro.org; 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=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1752427AbdATPco (ORCPT + 25 others); Fri, 20 Jan 2017 10:32:44 -0500 Received: from mail-wm0-f54.google.com ([74.125.82.54]:35966 "EHLO mail-wm0-f54.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1752139AbdATPcm (ORCPT ); Fri, 20 Jan 2017 10:32:42 -0500 Received: by mail-wm0-f54.google.com with SMTP id c85so41981664wmi.1 for ; Fri, 20 Jan 2017 07:32:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id; bh=AXqAzUe7LpjYMFwQIjmxMfiKrUUFcpBaq86dGaQindE=; b=iHxW5wd2IIBBHGHUOaQxBpEnQ5AHCsupwu80J94TM0f0cqoCVA/RDCxdUSXaFJ3hQz bl9UdHmL9OH9FdKjfEzeLvhdGjwW2s3P5YVAcYRMCN2ihWh2RFTxSE47oax/JRJVAYom sBlp1BQryA/SEEO8xFzDcUGxJ0HhqRbc9LCuw= 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; bh=AXqAzUe7LpjYMFwQIjmxMfiKrUUFcpBaq86dGaQindE=; b=F/rp3VF7Y3z0W4CsdHOpzKOnA/AK6/PMz5JjULcKGGWMMViGiN0TsDEWOMhdtPgvmW ber31Cx6h/CIYRnGd1Xp/A8GqMyvwTlJ/+iMOgkhzCc5gGZayohSLS9AFyesBx/qLubQ NHyPbHbz1PCO4B0qfcwPznnlOd0qNI5k+ac/+/ZACPcluVlQF0yOt1rue7HKTft4cacr OpdJLkaFyzVaeP9jDAbT6wt/SKUQJXqvQC9JbgCUNig/8sSMgVSWZBBb6F/MIinB5s82 xTP3gSaTjvX5R8QuV4buStrMIIWx9M8TgiDLBqORLZdIFXacB8nhWHi/n4O1mL11DhP2 L9bQ== X-Gm-Message-State: AIkVDXLWcfKWJFRFXay3qX47GwP4DjsEumEq3NpsnZCOunsYVzMvXDbfLRhbC4VnAYsM3jBD X-Received: by 10.28.99.69 with SMTP id x66mr3698540wmb.91.1484926360403; Fri, 20 Jan 2017 07:32:40 -0800 (PST) Received: from lmenx321.st.com. ([80.214.31.157]) by smtp.gmail.com with ESMTPSA id 61sm252981wrs.29.2017.01.20.07.32.38 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 20 Jan 2017 07:32:39 -0800 (PST) From: Benjamin Gaignard To: linaro-kernel@lists.linaro.org, arnd@arndb.de, labbott@redhat.com, dri-devel@lists.freedesktop.org, linux-kernel@vger.kernel.org, linux-media@vger.kernel.org, daniel.vetter@ffwll.ch, laurent.pinchart@ideasonboard.com, robdclark@gmail.com Cc: broonie@kernel.org, Benjamin Gaignard Subject: [RFC simple allocator v1 0/2] Simple allocator Date: Fri, 20 Jan 2017 16:32:29 +0100 Message-Id: <1484926351-30185-1-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org The goal of this RFC is to understand if a common ioctl for specific memory regions allocations is needed/welcome. Obviously it will not replace allocation done in linux kernel frameworks like v4l2, drm/kms or others, but offer an alternative when you don't want/need to use them for buffer allocation. To keep a compatibility with what already exist allocated buffers are exported in userland as dmabuf file descriptor (like ION is doing). "Unix Device Memory Allocator" project [1] wants to create a userland library which may allow to select, depending of the devices constraint, the best back-end for allocation. With this RFC I would to propose to have common ioctl for a maximum of allocators to avoid to duplicated back-ends for this library. One of the issues that lead me to propose this RFC it is that since the beginning it is a problem to allocate contiguous memory (CMA) without using v4l2 or drm/kms so the first allocator available in this RFC use CMA memory. An other question is: do we have others memory regions that could be interested by this new framework ? I have in mind that some title memory regions could use it or replace ION heaps (system, carveout, etc...). Maybe it only solve CMA allocation issue, in this case there is no need to create a new framework but only a dedicated ioctl. Maybe the first thing to do is to change the name and the location of this module, suggestions are welcome. I have testing this code with the following program: #include #include #include #include #include #include #include #include #include #include #include "simple-allocator.h" #define LENGTH 1024*16 void main (void) { struct simple_allocate_data data; int fd = open("/dev/cma0", O_RDWR, 0); int ret; void *mem; if (fd < 0) { printf("Can't open /dev/cma0\n"); return; } memset(&data, 0, sizeof(data)); data.length = LENGTH; data.flags = O_RDWR | O_CLOEXEC; ret = ioctl(fd, SA_IOC_ALLOC, &data); if (ret) { printf("Buffer allocation failed\n"); goto end; } mem = mmap(0, LENGTH, PROT_READ | PROT_WRITE, MAP_SHARED, data.fd, 0); if (mem == MAP_FAILED) { printf("mmap failed\n"); } memset(mem, 0xFF, LENGTH); munmap(mem, LENGTH); printf("test simple allocator CMA OK\n"); end: close(fd); } [1] https://github.com/cubanismo/allocator Benjamin Gaignard (2): Create Simple Allocator module add CMA simple allocator module Documentation/simple-allocator.txt | 81 ++++++++++ drivers/Kconfig | 2 + drivers/Makefile | 1 + drivers/simpleallocator/Kconfig | 17 +++ drivers/simpleallocator/Makefile | 2 + drivers/simpleallocator/simple-allocator-cma.c | 187 ++++++++++++++++++++++++ drivers/simpleallocator/simple-allocator-priv.h | 33 +++++ drivers/simpleallocator/simple-allocator.c | 180 +++++++++++++++++++++++ include/uapi/linux/simple-allocator.h | 35 +++++ 9 files changed, 538 insertions(+) create mode 100644 Documentation/simple-allocator.txt create mode 100644 drivers/simpleallocator/Kconfig create mode 100644 drivers/simpleallocator/Makefile create mode 100644 drivers/simpleallocator/simple-allocator-cma.c create mode 100644 drivers/simpleallocator/simple-allocator-priv.h create mode 100644 drivers/simpleallocator/simple-allocator.c create mode 100644 include/uapi/linux/simple-allocator.h -- 1.9.1