From patchwork Wed Oct 30 20:29:50 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sean Paul X-Patchwork-Id: 11220029 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 2583413B1 for ; Wed, 30 Oct 2019 20:30:30 +0000 (UTC) Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id 0CD13205C9 for ; Wed, 30 Oct 2019 20:30:30 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 0CD13205C9 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=poorly.run Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 2420E89B95; Wed, 30 Oct 2019 20:30:27 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-yw1-xc42.google.com (mail-yw1-xc42.google.com [IPv6:2607:f8b0:4864:20::c42]) by gabe.freedesktop.org (Postfix) with ESMTPS id 801BE6EB5B for ; Wed, 30 Oct 2019 20:30:25 +0000 (UTC) Received: by mail-yw1-xc42.google.com with SMTP id r134so1333503ywg.2 for ; Wed, 30 Oct 2019 13:30:25 -0700 (PDT) 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:mime-version:content-transfer-encoding; bh=Vv4E2R4DDduH7gOW5gr6nuzzSZrTCSv+byUyZpLRTTE=; b=V+G6stqAebjBtGVGqIHthCYp81IU8AIDq4M/FEaUSFL1KzltGEO8RKYeqLMUlE888D aT3+1a6FTVEbXC8xlL3WgDN/qxXU7bs/M9poClwqa3yhXyfNq0rbAfaZFDbQbkmdusMv cFchrG41I+pAXp7FIKnimShMzri6MDx/ofMOrseYUpL74pCjxzgwOQfgvpGEIoKHXNvB tZHPqk75qUyjIOmS++vMEcE5pZqYutbeNqzYQt0dw8WoCJhD/cdawceCbxIQI7yNrYxl XtCBMpnfLE0mhCpsGOfuHNVs7U1x7Fxwg++oXwtlzt7hPzHdUlYUAEfCwD4v9ace14km MSHQ== X-Gm-Message-State: APjAAAXTisLYa4/NZAxZgT6dQvdwn44prjHb5+SoYQc5lErXmGXvavo+ iK5bf4aoYh724Lt5iiPhA6/4KVAIONQ= X-Google-Smtp-Source: APXvYqxWQa4h4JkTIMMIPw8+wSWnljS+fSjFUjrenUtg2wWiliojvoZdcFfziCTdnlmoQN8+vMnxYw== X-Received: by 2002:a81:9a0c:: with SMTP id r12mr1123917ywg.25.1572467424309; Wed, 30 Oct 2019 13:30:24 -0700 (PDT) Received: from rosewood.cam.corp.google.com ([2620:0:1013:11:89c6:2139:5435:371d]) by smtp.gmail.com with ESMTPSA id h35sm416432ywk.63.2019.10.30.13.30.22 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 30 Oct 2019 13:30:23 -0700 (PDT) From: Sean Paul To: dri-devel@lists.freedesktop.org Subject: [PATCH 1/5] Revert "kselftests: Add dma-heap test" Date: Wed, 30 Oct 2019 16:29:50 -0400 Message-Id: <20191030203003.101156-2-sean@poorly.run> X-Mailer: git-send-email 2.24.0.rc0.303.g954a862665-goog In-Reply-To: <20191030203003.101156-1-sean@poorly.run> References: <20191030203003.101156-1-sean@poorly.run> MIME-Version: 1.0 X-Mailman-Original-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=poorly.run; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=Vv4E2R4DDduH7gOW5gr6nuzzSZrTCSv+byUyZpLRTTE=; b=F6ohvfSuD1K3dPQbLXW4qVT1ldk3EN9S3UYr2Fv+zB5StGxlIOGR3r99l9KqsCGPcU Nps9sxIV051Ttc9Ysghr+j/x2jUr2eoUHNqnPpxmh17a+Sx2Y8ifaFCpd2SXKa++b7sK BgE+DEnF47Je+DASfxaCbDOXIAMpGTozi87guTrDzQ2yoii4B88U3UMBk2FCCoIL2Poz dT/RstoVtc0+/p5caClnjEwULMfLbCK5VLhCoI9eZ3oDqVkI713TTRaIZero7YUS+q9u xUdnU9hBtloNUt5ihNEKk5fsCNCOxNDPV+EQ0cq8/+0dyPq/lv/cjEPr00RyFIDz4n+s MzDA== X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Hillf Danton , Vincent Donnefort , Sean Paul , Chenbo Feng , Alistair Strachan , Liam Mark , Christoph Hellwig , Sean Paul , "Andrew F . Davis" , Hridya Valsaraju , Sudipto Paul , Pratik Patel Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" From: Sean Paul This reverts commit ab87cc9754cdeb373c8ac030ac7aed92f450b767. This patchset doesn't meet the UAPI requirements set out in [1] for the DRM subsystem. Once the userspace component is reviewed and ready for merge we can try again. [1]- https://01.org/linuxgraphics/gfx-docs/drm/gpu/drm-uapi.html#open-source-userspace-requirements Fixes: ab87cc9754cd ("kselftests: Add dma-heap test") Cc: Benjamin Gaignard Cc: Sumit Semwal Cc: Liam Mark Cc: Pratik Patel Cc: Brian Starkey Cc: Vincent Donnefort Cc: Sudipto Paul Cc: Andrew F. Davis Cc: Christoph Hellwig Cc: Chenbo Feng Cc: Alistair Strachan Cc: Hridya Valsaraju Cc: Hillf Danton Cc: dri-devel@lists.freedesktop.org Cc: Brian Starkey Cc: Laura Abbott Cc: John Stultz Cc: Sean Paul Signed-off-by: Sean Paul --- tools/testing/selftests/dmabuf-heaps/Makefile | 9 - .../selftests/dmabuf-heaps/dmabuf-heap.c | 238 ------------------ 2 files changed, 247 deletions(-) delete mode 100644 tools/testing/selftests/dmabuf-heaps/Makefile delete mode 100644 tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c diff --git a/tools/testing/selftests/dmabuf-heaps/Makefile b/tools/testing/selftests/dmabuf-heaps/Makefile deleted file mode 100644 index 8c4c36e2972d..000000000000 --- a/tools/testing/selftests/dmabuf-heaps/Makefile +++ /dev/null @@ -1,9 +0,0 @@ -# SPDX-License-Identifier: GPL-2.0 -CFLAGS += -static -O3 -Wl,-no-as-needed -Wall -#LDLIBS += -lrt -lpthread -lm - -# these are all "safe" tests that don't modify -# system time or require escalated privileges -TEST_GEN_PROGS = dmabuf-heap - -include ../lib.mk diff --git a/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c deleted file mode 100644 index b36dd9f35c19..000000000000 --- a/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c +++ /dev/null @@ -1,238 +0,0 @@ -// SPDX-License-Identifier: GPL-2.0 - -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include -#include - -#include "../../../../include/uapi/linux/dma-heap.h" - -#define DEVPATH "/dev/dma_heap" - -static int check_vgem(int fd) -{ - drm_version_t version = { 0 }; - char name[5]; - int ret; - - version.name_len = 4; - version.name = name; - - ret = ioctl(fd, DRM_IOCTL_VERSION, &version); - if (ret) - return 0; - - return !strcmp(name, "vgem"); -} - -static int open_vgem(void) -{ - int i, fd; - const char *drmstr = "/dev/dri/card"; - - fd = -1; - for (i = 0; i < 16; i++) { - char name[80]; - - snprintf(name, 80, "%s%u", drmstr, i); - - fd = open(name, O_RDWR); - if (fd < 0) - continue; - - if (!check_vgem(fd)) { - close(fd); - fd = -1; - continue; - } else { - break; - } - } - return fd; -} - -static int import_vgem_fd(int vgem_fd, int dma_buf_fd, uint32_t *handle) -{ - struct drm_prime_handle import_handle = { - .fd = dma_buf_fd, - .flags = 0, - .handle = 0, - }; - int ret; - - ret = ioctl(vgem_fd, DRM_IOCTL_PRIME_FD_TO_HANDLE, &import_handle); - if (ret == 0) - *handle = import_handle.handle; - return ret; -} - -static void close_handle(int vgem_fd, uint32_t handle) -{ - struct drm_gem_close close = { - .handle = handle, - }; - - ioctl(vgem_fd, DRM_IOCTL_GEM_CLOSE, &close); -} - -static int dmabuf_heap_open(char *name) -{ - int ret, fd; - char buf[256]; - - ret = snprintf(buf, 256, "%s/%s", DEVPATH, name); - if (ret < 0) { - printf("snprintf failed!\n"); - return ret; - } - - fd = open(buf, O_RDWR); - if (fd < 0) - printf("open %s failed!\n", buf); - return fd; -} - -static int dmabuf_heap_alloc(int fd, size_t len, unsigned int flags, - int *dmabuf_fd) -{ - struct dma_heap_allocation_data data = { - .len = len, - .fd_flags = O_RDWR | O_CLOEXEC, - .heap_flags = flags, - }; - int ret; - - if (!dmabuf_fd) - return -EINVAL; - - ret = ioctl(fd, DMA_HEAP_IOC_ALLOC, &data); - if (ret < 0) - return ret; - *dmabuf_fd = (int)data.fd; - return ret; -} - -static void dmabuf_sync(int fd, int start_stop) -{ - struct dma_buf_sync sync = { - .flags = start_stop | DMA_BUF_SYNC_RW, - }; - int ret; - - ret = ioctl(fd, DMA_BUF_IOCTL_SYNC, &sync); - if (ret) - printf("sync failed %d\n", errno); -} - -#define ONE_MEG (1024 * 1024) - -static int do_test(char *heap_name) -{ - int heap_fd = -1, dmabuf_fd = -1, importer_fd = -1; - uint32_t handle = 0; - void *p = NULL; - int ret; - - printf("Testing heap: %s\n", heap_name); - - heap_fd = dmabuf_heap_open(heap_name); - if (heap_fd < 0) - return; - - printf("Allocating 1 MEG\n"); - ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0, &dmabuf_fd); - if (ret) { - printf("Allocation Failed!\n"); - ret = -1; - goto out; - } - /* mmap and write a simple pattern */ - p = mmap(NULL, - ONE_MEG, - PROT_READ | PROT_WRITE, - MAP_SHARED, - dmabuf_fd, - 0); - if (p == MAP_FAILED) { - printf("mmap() failed: %m\n"); - ret = -1; - goto out; - } - printf("mmap passed\n"); - - dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START); - memset(p, 1, ONE_MEG / 2); - memset((char *)p + ONE_MEG / 2, 0, ONE_MEG / 2); - dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_END); - - importer_fd = open_vgem(); - if (importer_fd < 0) { - ret = importer_fd; - printf("Failed to open vgem\n"); - goto out; - } - - ret = import_vgem_fd(importer_fd, dmabuf_fd, &handle); - if (ret < 0) { - printf("Failed to import buffer\n"); - goto out; - } - printf("import passed\n"); - - dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_START); - memset(p, 0xff, ONE_MEG); - dmabuf_sync(dmabuf_fd, DMA_BUF_SYNC_END); - printf("syncs passed\n"); - - close_handle(importer_fd, handle); - ret = 0; - -out: - if (p) - munmap(p, ONE_MEG); - if (importer_fd >= 0) - close(importer_fd); - if (dmabuf_fd >= 0) - close(dmabuf_fd); - if (heap_fd >= 0) - close(heap_fd); - - return ret; -} - -int main(void) -{ - DIR *d; - struct dirent *dir; - int ret = -1; - - d = opendir(DEVPATH); - if (!d) { - printf("No %s directory?\n", DEVPATH); - return -1; - } - - while ((dir = readdir(d)) != NULL) { - if (!strncmp(dir->d_name, ".", 2)) - continue; - if (!strncmp(dir->d_name, "..", 3)) - continue; - - ret = do_test(dir->d_name); - if (ret) - break; - } - closedir(d); - - return ret; -}