diff options
author | Linus Torvalds <torvalds@linux-foundation.org> | 2020-01-30 19:04:01 +0300 |
---|---|---|
committer | Linus Torvalds <torvalds@linux-foundation.org> | 2020-01-30 19:04:01 +0300 |
commit | 9f68e3655aae6d49d6ba05dd263f99f33c2567af (patch) | |
tree | 42c2c4579c4acbbb456695326af4f4ad8f402813 /tools | |
parent | 4cadc60d6bcfee9c626d4b55e9dc1475d21ad3bb (diff) | |
parent | d47c7f06268082bc0082a15297a07c0da59b0fc4 (diff) | |
download | linux-9f68e3655aae6d49d6ba05dd263f99f33c2567af.tar.xz |
Merge tag 'drm-next-2020-01-30' of git://anongit.freedesktop.org/drm/drm
Pull drm updates from Davbe Airlie:
"This is the main pull request for graphics for 5.6. Usual selection of
changes all over.
I've got one outstanding vmwgfx pull that touches mm so kept it
separate until after all of this lands. I'll try and get it to you
soon after this, but it might be early next week (nothing wrong with
code, just my schedule is messy)
This also hits a lot of fbdev drivers with some cleanups.
Other notables:
- vulkan timeline semaphore support added to syncobjs
- nouveau turing secureboot/graphics support
- Displayport MST display stream compression support
Detailed summary:
uapi:
- dma-buf heaps added (and fixed)
- command line add support for panel oreientation
- command line allow overriding penguin count
drm:
- mipi dsi definition updates
- lockdep annotations for dma_resv
- remove dma-buf kmap/kunmap support
- constify fb_ops in all fbdev drivers
- MST fix for daisy chained hotplug-
- CTA-861-G modes with VIC >= 193 added
- fix drm_panel_of_backlight export
- LVDS decoder support
- more device based logging support
- scanline alighment for dumb buffers
- MST DSC helpers
scheduler:
- documentation fixes
- job distribution improvements
panel:
- Logic PD type 28 panel support
- Jimax8729d MIPI-DSI
- igenic JZ4770
- generic DSI devicetree bindings
- sony acx424AKP panel
- Leadtek LTK500HD1829
- xinpeng XPP055C272
- AUO B116XAK01
- GiantPlus GPM940B0
- BOE NV140FHM-N49
- Satoz SAT050AT40H12R2
- Sharp LS020B1DD01D panels.
ttm:
- use blocking WW lock
i915:
- hw/uapi state separation
- Lock annotation improvements
- selftest improvements
- ICL/TGL DSI VDSC support
- VBT parsing improvments
- Display refactoring
- DSI updates + fixes
- HDCP 2.2 for CFL
- CML PCI ID fixes
- GLK+ fbc fix
- PSR fixes
- GEN/GT refactor improvments
- DP MST fixes
- switch context id alloc to xarray
- workaround updates
- LMEM debugfs support
- tiled monitor fixes
- ICL+ clock gating programming removed
- DP MST disable sequence fixed
- LMEM discontiguous object maps
- prefaulting for discontiguous objects
- use LMEM for dumb buffers if possible
- add LMEM mmap support
amdgpu:
- enable sync object timelines for vulkan
- MST atomic routines
- enable MST DSC support
- add DMCUB display microengine support
- DC OEM i2c support
- Renoir DC fixes
- Initial HDCP 2.x support
- BACO support for Arcturus
- Use BACO for runtime PM power save
- gfxoff on navi10
- gfx10 golden updates and fixes
- DCN support on POWER
- GFXOFF for raven1 refresh
- MM engine idle handlers cleanup
- 10bpc EDP panel fixes
- renoir watermark fixes
- SR-IOV fixes
- Arcturus VCN fixes
- GDDR6 training fixes
- freesync fixes
- Pollock support
amdkfd:
- unify more codepath with amdgpu
- use KIQ to setup HIQ rather than MMIO
radeon:
- fix vma fault handler race
- PPC DMA fix
- register check fixes for r100/r200
nouveau:
- mmap_sem vs dma_resv fix
- rewrite the ACR secure boot code for Turing
- TU10x graphics engine support (TU11x pending)
- Page kind mapping for turing
- 10-bit LUT support
- GP10B Tegra fixes
- HD audio regression fix
hisilicon/hibmc:
- use generic fbdev code and helpers
rockchip:
- dsi/px30 support
virtio:
- fb damage support
- static some functions
vc4:
- use dma_resv lock wrappers
msm:
- use dma_resv lock wrappers
- sc7180 display + DSI support
- a618 support
- UBWC support improvements
vmwgfx:
- updates + new logging uapi
exynos:
- enable/disable callback cleanups
etnaviv:
- use dma_resv lock wrappers
atmel-hlcdc:
- clock fixes
mediatek:
- cmdq support
- non-smooth cursor fixes
- ctm property support
sun4i:
- suspend support
- A64 mipi dsi support
rcar-du:
- Color management module support
- LVDS encoder dual-link support
- R8A77980 support
analogic:
- add support for an6345
ast:
- atomic modeset support
- primary plane garbage fix
arcgpu:
- fixes for fourcc handling
tegra:
- minor fixes and improvments
mcde:
- vblank support
meson:
- OSD1 plane AFBC commit
gma500:
- add pageflip support
- reomve global drm_dev
komeda:
- tweak debugfs output
- d32 support
- runtime PM suppotr
udl:
- use generic shmem helpers
- cleanup and fixes"
* tag 'drm-next-2020-01-30' of git://anongit.freedesktop.org/drm/drm: (1998 commits)
drm/nouveau/fb/gp102-: allow module to load even when scrubber binary is missing
drm/nouveau/acr: return error when registering LSF if ACR not supported
drm/nouveau/disp/gv100-: not all channel types support reporting error codes
drm/nouveau/disp/nv50-: prevent oops when no channel method map provided
drm/nouveau: support synchronous pushbuf submission
drm/nouveau: signal pending fences when channel has been killed
drm/nouveau: reject attempts to submit to dead channels
drm/nouveau: zero vma pointer even if we only unreference it rather than free
drm/nouveau: Add HD-audio component notifier support
drm/nouveau: fix build error without CONFIG_IOMMU_API
drm/nouveau/kms/nv04: remove set but not used variable 'width'
drm/nouveau/kms/nv50: remove set but not unused variable 'nv_connector'
drm/nouveau/mmu: fix comptag memory leak
drm/nouveau/gr/gp10b: Use gp100_grctx and gp100_gr_zbc
drm/nouveau/pmu/gm20b,gp10b: Fix Falcon bootstrapping
drm/exynos: Rename Exynos to lowercase
drm/exynos: change callback names
drm/mst: Don't do atomic checks over disabled managers
drm/amdgpu: add the lost mutex_init back
drm/amd/display: skip opp blank or unblank if test pattern enabled
...
Diffstat (limited to 'tools')
-rw-r--r-- | tools/testing/selftests/dmabuf-heaps/Makefile | 6 | ||||
-rw-r--r-- | tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c | 396 |
2 files changed, 402 insertions, 0 deletions
diff --git a/tools/testing/selftests/dmabuf-heaps/Makefile b/tools/testing/selftests/dmabuf-heaps/Makefile new file mode 100644 index 000000000000..607c2acd2082 --- /dev/null +++ b/tools/testing/selftests/dmabuf-heaps/Makefile @@ -0,0 +1,6 @@ +# SPDX-License-Identifier: GPL-2.0 +CFLAGS += -static -O3 -Wl,-no-as-needed -Wall -I../../../../usr/include + +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 new file mode 100644 index 000000000000..cd5e1f602ac9 --- /dev/null +++ b/tools/testing/selftests/dmabuf-heaps/dmabuf-heap.c @@ -0,0 +1,396 @@ +// SPDX-License-Identifier: GPL-2.0 + +#include <dirent.h> +#include <errno.h> +#include <fcntl.h> +#include <stdio.h> +#include <stdlib.h> +#include <stdint.h> +#include <string.h> +#include <unistd.h> +#include <sys/ioctl.h> +#include <sys/mman.h> +#include <sys/types.h> + +#include <linux/dma-buf.h> +#include <drm/drm.h> + +#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_fdflags(int fd, size_t len, unsigned int fd_flags, + unsigned int heap_flags, int *dmabuf_fd) +{ + struct dma_heap_allocation_data data = { + .len = len, + .fd = 0, + .fd_flags = fd_flags, + .heap_flags = heap_flags, + }; + int ret; + + if (!dmabuf_fd) + return -EINVAL; + + ret = ioctl(fd, DMA_HEAP_IOCTL_ALLOC, &data); + if (ret < 0) + return ret; + *dmabuf_fd = (int)data.fd; + return ret; +} + +static int dmabuf_heap_alloc(int fd, size_t len, unsigned int flags, + int *dmabuf_fd) +{ + return dmabuf_heap_alloc_fdflags(fd, len, O_RDWR | O_CLOEXEC, flags, + dmabuf_fd); +} + +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 test_alloc_and_import(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 -1; + + 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; +} + +/* Test the ioctl version compatibility w/ a smaller structure then expected */ +static int dmabuf_heap_alloc_older(int fd, size_t len, unsigned int flags, + int *dmabuf_fd) +{ + int ret; + unsigned int older_alloc_ioctl; + struct dma_heap_allocation_data_smaller { + __u64 len; + __u32 fd; + __u32 fd_flags; + } data = { + .len = len, + .fd = 0, + .fd_flags = O_RDWR | O_CLOEXEC, + }; + + older_alloc_ioctl = _IOWR(DMA_HEAP_IOC_MAGIC, 0x0, + struct dma_heap_allocation_data_smaller); + if (!dmabuf_fd) + return -EINVAL; + + ret = ioctl(fd, older_alloc_ioctl, &data); + if (ret < 0) + return ret; + *dmabuf_fd = (int)data.fd; + return ret; +} + +/* Test the ioctl version compatibility w/ a larger structure then expected */ +static int dmabuf_heap_alloc_newer(int fd, size_t len, unsigned int flags, + int *dmabuf_fd) +{ + int ret; + unsigned int newer_alloc_ioctl; + struct dma_heap_allocation_data_bigger { + __u64 len; + __u32 fd; + __u32 fd_flags; + __u64 heap_flags; + __u64 garbage1; + __u64 garbage2; + __u64 garbage3; + } data = { + .len = len, + .fd = 0, + .fd_flags = O_RDWR | O_CLOEXEC, + .heap_flags = flags, + .garbage1 = 0xffffffff, + .garbage2 = 0x88888888, + .garbage3 = 0x11111111, + }; + + newer_alloc_ioctl = _IOWR(DMA_HEAP_IOC_MAGIC, 0x0, + struct dma_heap_allocation_data_bigger); + if (!dmabuf_fd) + return -EINVAL; + + ret = ioctl(fd, newer_alloc_ioctl, &data); + if (ret < 0) + return ret; + + *dmabuf_fd = (int)data.fd; + return ret; +} + +static int test_alloc_compat(char *heap_name) +{ + int heap_fd = -1, dmabuf_fd = -1; + int ret; + + heap_fd = dmabuf_heap_open(heap_name); + if (heap_fd < 0) + return -1; + + printf("Testing (theoretical)older alloc compat\n"); + ret = dmabuf_heap_alloc_older(heap_fd, ONE_MEG, 0, &dmabuf_fd); + if (ret) { + printf("Older compat allocation failed!\n"); + ret = -1; + goto out; + } + close(dmabuf_fd); + + printf("Testing (theoretical)newer alloc compat\n"); + ret = dmabuf_heap_alloc_newer(heap_fd, ONE_MEG, 0, &dmabuf_fd); + if (ret) { + printf("Newer compat allocation failed!\n"); + ret = -1; + goto out; + } + printf("Ioctl compatibility tests passed\n"); +out: + if (dmabuf_fd >= 0) + close(dmabuf_fd); + if (heap_fd >= 0) + close(heap_fd); + + return ret; +} + +static int test_alloc_errors(char *heap_name) +{ + int heap_fd = -1, dmabuf_fd = -1; + int ret; + + heap_fd = dmabuf_heap_open(heap_name); + if (heap_fd < 0) + return -1; + + printf("Testing expected error cases\n"); + ret = dmabuf_heap_alloc(0, ONE_MEG, 0x111111, &dmabuf_fd); + if (!ret) { + printf("Did not see expected error (invalid fd)!\n"); + ret = -1; + goto out; + } + + ret = dmabuf_heap_alloc(heap_fd, ONE_MEG, 0x111111, &dmabuf_fd); + if (!ret) { + printf("Did not see expected error (invalid heap flags)!\n"); + ret = -1; + goto out; + } + + ret = dmabuf_heap_alloc_fdflags(heap_fd, ONE_MEG, + ~(O_RDWR | O_CLOEXEC), 0, &dmabuf_fd); + if (!ret) { + printf("Did not see expected error (invalid fd flags)!\n"); + ret = -1; + goto out; + } + + printf("Expected error checking passed\n"); +out: + 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 = test_alloc_and_import(dir->d_name); + if (ret) + break; + + ret = test_alloc_compat(dir->d_name); + if (ret) + break; + + ret = test_alloc_errors(dir->d_name); + if (ret) + break; + } + closedir(d); + + return ret; +} |