From patchwork Mon Feb 13 14:45: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: 93894 Delivered-To: patch@linaro.org Received: by 10.182.3.34 with SMTP id 2csp938371obz; Mon, 13 Feb 2017 06:45:22 -0800 (PST) X-Received: by 10.84.233.206 with SMTP id m14mr30568994pln.104.1486997122242; Mon, 13 Feb 2017 06:45:22 -0800 (PST) Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [131.252.210.177]) by mx.google.com with ESMTPS id 1si10255713pli.149.2017.02.13.06.45.21 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Mon, 13 Feb 2017 06:45:22 -0800 (PST) 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; 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 2146A6E412; Mon, 13 Feb 2017 14:45:21 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-wm0-x22b.google.com (mail-wm0-x22b.google.com [IPv6:2a00:1450:400c:c09::22b]) by gabe.freedesktop.org (Postfix) with ESMTPS id 110586E0EF for ; Mon, 13 Feb 2017 14:45:19 +0000 (UTC) Received: by mail-wm0-x22b.google.com with SMTP id c85so309750402wmi.1 for ; Mon, 13 Feb 2017 06:45:18 -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=d2IjJ4nLj0qf/mA5sDkrU8j5LhweTEKP9+vgJ3HFliQ=; b=OMT91O8m3qxMPd8OBRKEFVEwrjuSHY9GMeWi4AwttFFh8DLjmxdryzZy/mW8sxTbDW tPOiBIkL255sljD+UvdCUdUc+SelkW58SFVflMTcd1CfmGKb8hmCiVGhIq8X4pCV811t yxeMhlFhpW0yVnpp5XLQNmbZeRjkuD5ALc8/k= 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=d2IjJ4nLj0qf/mA5sDkrU8j5LhweTEKP9+vgJ3HFliQ=; b=iTnlsapK539ijgLwI513+cIc001lCGPj4+Zhb4rfB67dXogcahOPwBynjtIE4iGxM5 acllT/zQGRwVJgfd9IX1EgGDkotFFZ1MddFUxSwvAKytO/QNXOe4G4oKbhMBsCSQhwVj frCpt8Jl9xv+sVju5p0A2OhLSQr8kwL90/QafmOqLnWsen9sCRoko+E7ueGLmGf+xuc/ PS61hdetr91ZXW9deLVW9YiV3hkBtj80dk52+20ZjRGQgDbDtT/IEDJRUDF1m8q3+AyL DPDAue9+f5ToEyEeBoo2Wz66p+EDKVihFwSWpz1LewWw8s5qJ+wmdo2Iv4gnPtkqeDYv vrag== X-Gm-Message-State: AMke39kYNUXU0NDgZhnKsu2Ugy0AomjL/ci8L8SDUV1IBP+Rs85jW6MI04lhaMnABI/Cvjr7 X-Received: by 10.28.94.2 with SMTP id s2mr18113774wmb.127.1486997117603; Mon, 13 Feb 2017 06:45:17 -0800 (PST) Received: from lmenx321.st.com. ([80.215.84.161]) by smtp.gmail.com with ESMTPSA id m84sm5634788wmf.10.2017.02.13.06.45.15 (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Mon, 13 Feb 2017 06:45:16 -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, akpm@linux-foundation.org, hverkuil@xs4all.nl Subject: [RFC simple allocator v2 0/2] Simple allocator Date: Mon, 13 Feb 2017 15:45:04 +0100 Message-Id: <1486997106-23277-1-git-send-email-benjamin.gaignard@linaro.org> X-Mailer: git-send-email 1.9.1 Cc: broonie@kernel.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" version 2: - rebase code on 4.10-rc7 - fix bug in CMA allocator - do more tests with wayland dmabuf protocol: https://git.linaro.org/people/benjamin.gaignard/simple_allocator.git 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