1 /* 2 * Copyright © 2016 Broadcom 3 * Copyright © 2019 Collabora, Ltd. 4 * 5 * Permission is hereby granted, free of charge, to any person obtaining a 6 * copy of this software and associated documentation files (the "Software"), 7 * to deal in the Software without restriction, including without limitation 8 * the rights to use, copy, modify, merge, publish, distribute, sublicense, 9 * and/or sell copies of the Software, and to permit persons to whom the 10 * Software is furnished to do so, subject to the following conditions: 11 * 12 * The above copyright notice and this permission notice (including the next 13 * paragraph) shall be included in all copies or substantial portions of the 14 * Software. 15 * 16 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 17 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 18 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL 19 * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 20 * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING 21 * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS 22 * IN THE SOFTWARE. 23 */ 24 25 #include "igt.h" 26 #include "igt_panfrost.h" 27 #include <unistd.h> 28 #include <stdlib.h> 29 #include <stdio.h> 30 #include <string.h> 31 #include <fcntl.h> 32 #include <inttypes.h> 33 #include <errno.h> 34 #include <sys/stat.h> 35 #include <sys/ioctl.h> 36 #include "panfrost_drm.h" 37 38 igt_main 39 { 40 int fd, kms_fd; 41 42 igt_fixture { 43 kms_fd = drm_open_driver_master(DRIVER_ANY); 44 fd = drm_open_driver(DRIVER_PANFROST); 45 } 46 47 igt_subtest("gem-prime-import") { 48 struct panfrost_bo *bo; 49 uint32_t handle, dumb_handle; 50 struct drm_panfrost_get_bo_offset get_bo_offset = {0,}; 51 int dmabuf_fd; 52 53 /* Just to be sure that when we import the dumb buffer it has 54 * a non-NULL address. 55 */ 56 bo = igt_panfrost_gem_new(fd, 1024); 57 58 dumb_handle = kmstest_dumb_create(kms_fd, 1024, 1024, 32, NULL, NULL); 59 60 dmabuf_fd = prime_handle_to_fd(kms_fd, dumb_handle); 61 62 handle = prime_fd_to_handle(fd, dmabuf_fd); 63 64 get_bo_offset.handle = handle; 65 do_ioctl(fd, DRM_IOCTL_PANFROST_GET_BO_OFFSET, &get_bo_offset); 66 igt_assert(get_bo_offset.offset); 67 68 gem_close(fd, handle); 69 70 kmstest_dumb_destroy(kms_fd, dumb_handle); 71 72 igt_panfrost_free_bo(fd, bo); 73 } 74 75 igt_fixture { 76 close(fd); 77 close(kms_fd); 78 } 79 } 80