Re: [Intel-gfx] [PATCH i-g-t 3/4] Add v3d helper library

2018-11-21 Thread Petri Latvala
On Wed, Nov 14, 2018 at 02:28:31PM -0800, Eric Anholt wrote:
> Just a few little ioctl wrappers that v3d tests will use.
> 
> Signed-off-by: Eric Anholt 

Acked-by: Petri Latvala 


> ---
>  lib/Makefile.sources |   2 +
>  lib/drmtest.c|   3 +
>  lib/drmtest.h|   1 +
>  lib/igt_v3d.c| 130 +++
>  lib/igt_v3d.h|  46 +++
>  lib/meson.build  |   1 +
>  6 files changed, 183 insertions(+)
>  create mode 100644 lib/igt_v3d.c
>  create mode 100644 lib/igt_v3d.h
> 
> diff --git a/lib/Makefile.sources b/lib/Makefile.sources
> index e98989ff8ed9..808b9617eca2 100644
> --- a/lib/Makefile.sources
> +++ b/lib/Makefile.sources
> @@ -107,6 +107,8 @@ lib_source_list = \
>   igt_syncobj.h   \
>   igt_psr.c   \
>   igt_psr.h   \
> + igt_v3d.c   \
> + igt_v3d.h   \
>   $(NULL)
>  
>  .PHONY: version.h.tmp
> diff --git a/lib/drmtest.c b/lib/drmtest.c
> index fee9d33ad2a5..d2aa1c19154f 100644
> --- a/lib/drmtest.c
> +++ b/lib/drmtest.c
> @@ -202,6 +202,7 @@ static const struct module {
>  } modules[] = {
>   { DRIVER_AMDGPU, "amdgpu" },
>   { DRIVER_INTEL, "i915", modprobe_i915 },
> + { DRIVER_V3D, "v3d" },
>   { DRIVER_VC4, "vc4" },
>   { DRIVER_VGEM, "vgem" },
>   { DRIVER_VIRTIO, "virtio-gpu" },
> @@ -340,6 +341,8 @@ static const char *chipset_to_str(int chipset)
>   switch (chipset) {
>   case DRIVER_INTEL:
>   return "intel";
> + case DRIVER_V3D:
> + return "v3d";
>   case DRIVER_VC4:
>   return "vc4";
>   case DRIVER_VGEM:
> diff --git a/lib/drmtest.h b/lib/drmtest.h
> index 949865ee54dd..96ee517e2ec1 100644
> --- a/lib/drmtest.h
> +++ b/lib/drmtest.h
> @@ -43,6 +43,7 @@
>  #define DRIVER_VGEM  (1 << 2)
>  #define DRIVER_VIRTIO(1 << 3)
>  #define DRIVER_AMDGPU(1 << 4)
> +#define DRIVER_V3D   (1 << 5)
>  /*
>   * Exclude DRVER_VGEM from DRIVER_ANY since if you run on a system
>   * with vgem as well as a supported driver, you can end up with a
> diff --git a/lib/igt_v3d.c b/lib/igt_v3d.c
> new file mode 100644
> index ..1a5ede1bd5fc
> --- /dev/null
> +++ b/lib/igt_v3d.c
> @@ -0,0 +1,130 @@
> +/*
> + * Copyright © 2016 Broadcom
> + *
> + * Permission is hereby granted, free of charge, to any person obtaining a
> + * copy of this software and associated documentation files (the "Software"),
> + * to deal in the Software without restriction, including without limitation
> + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
> + * and/or sell copies of the Software, and to permit persons to whom the
> + * Software is furnished to do so, subject to the following conditions:
> + *
> + * The above copyright notice and this permission notice (including the next
> + * paragraph) shall be included in all copies or substantial portions of the
> + * Software.
> + *
> + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
> + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
> + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
> + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
> + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
> + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER 
> DEALINGS
> + * IN THE SOFTWARE.
> + */
> +
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +#include 
> +
> +#include "drmtest.h"
> +#include "igt_aux.h"
> +#include "igt_core.h"
> +#include "igt_v3d.h"
> +#include "ioctl_wrappers.h"
> +#include "intel_reg.h"
> +#include "intel_chipset.h"
> +#include "v3d_drm.h"
> +
> +#if NEW_CONTEXT_PARAM_NO_ERROR_CAPTURE_API
> +#define LOCAL_CONTEXT_PARAM_NO_ERROR_CAPTURE 0x4
> +#endif
> +
> +/**
> + * SECTION:igt_v3d
> + * @short_description: V3D support library
> + * @title: V3D
> + * @include: igt.h
> + *
> + * This library provides various auxiliary helper functions for writing V3D
> + * tests.
> + */
> +
> +struct v3d_bo *
> +igt_v3d_create_bo(int fd, size_t size)
> +{
> + struct v3d_bo *bo = calloc(1, sizeof(*bo));
> +
> + struct drm_v3d_create_bo create = {
> + .size = size,
> + };
> +
> + do_ioctl(fd, DRM_IOCTL_V3D_CREATE_BO, );
> +
> + bo->handle = create.handle;
> + bo->offset = create.offset;
> + bo->size = size;
> +
> + return bo;
> +}
> +
> +void
> +igt_v3d_free_bo(int fd, struct v3d_bo *bo)
> +{
> + if (bo->map)
> + munmap(bo->map, bo->size);
> + gem_close(fd, bo->handle);
> + free(bo);
> +}
> +
> +uint32_t
> +igt_v3d_get_bo_offset(int fd, uint32_t handle)
> +{
> + struct drm_v3d_get_bo_offset get = {
> + .handle = handle,
> + };
> +
> + do_ioctl(fd, DRM_IOCTL_V3D_GET_BO_OFFSET, );
> +
> + return 

[Intel-gfx] [PATCH i-g-t 3/4] Add v3d helper library

2018-11-14 Thread Eric Anholt
Just a few little ioctl wrappers that v3d tests will use.

Signed-off-by: Eric Anholt 
---
 lib/Makefile.sources |   2 +
 lib/drmtest.c|   3 +
 lib/drmtest.h|   1 +
 lib/igt_v3d.c| 130 +++
 lib/igt_v3d.h|  46 +++
 lib/meson.build  |   1 +
 6 files changed, 183 insertions(+)
 create mode 100644 lib/igt_v3d.c
 create mode 100644 lib/igt_v3d.h

diff --git a/lib/Makefile.sources b/lib/Makefile.sources
index e98989ff8ed9..808b9617eca2 100644
--- a/lib/Makefile.sources
+++ b/lib/Makefile.sources
@@ -107,6 +107,8 @@ lib_source_list =   \
igt_syncobj.h   \
igt_psr.c   \
igt_psr.h   \
+   igt_v3d.c   \
+   igt_v3d.h   \
$(NULL)
 
 .PHONY: version.h.tmp
diff --git a/lib/drmtest.c b/lib/drmtest.c
index fee9d33ad2a5..d2aa1c19154f 100644
--- a/lib/drmtest.c
+++ b/lib/drmtest.c
@@ -202,6 +202,7 @@ static const struct module {
 } modules[] = {
{ DRIVER_AMDGPU, "amdgpu" },
{ DRIVER_INTEL, "i915", modprobe_i915 },
+   { DRIVER_V3D, "v3d" },
{ DRIVER_VC4, "vc4" },
{ DRIVER_VGEM, "vgem" },
{ DRIVER_VIRTIO, "virtio-gpu" },
@@ -340,6 +341,8 @@ static const char *chipset_to_str(int chipset)
switch (chipset) {
case DRIVER_INTEL:
return "intel";
+   case DRIVER_V3D:
+   return "v3d";
case DRIVER_VC4:
return "vc4";
case DRIVER_VGEM:
diff --git a/lib/drmtest.h b/lib/drmtest.h
index 949865ee54dd..96ee517e2ec1 100644
--- a/lib/drmtest.h
+++ b/lib/drmtest.h
@@ -43,6 +43,7 @@
 #define DRIVER_VGEM(1 << 2)
 #define DRIVER_VIRTIO  (1 << 3)
 #define DRIVER_AMDGPU  (1 << 4)
+#define DRIVER_V3D (1 << 5)
 /*
  * Exclude DRVER_VGEM from DRIVER_ANY since if you run on a system
  * with vgem as well as a supported driver, you can end up with a
diff --git a/lib/igt_v3d.c b/lib/igt_v3d.c
new file mode 100644
index ..1a5ede1bd5fc
--- /dev/null
+++ b/lib/igt_v3d.c
@@ -0,0 +1,130 @@
+/*
+ * Copyright © 2016 Broadcom
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a
+ * copy of this software and associated documentation files (the "Software"),
+ * to deal in the Software without restriction, including without limitation
+ * the rights to use, copy, modify, merge, publish, distribute, sublicense,
+ * and/or sell copies of the Software, and to permit persons to whom the
+ * Software is furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice (including the next
+ * paragraph) shall be included in all copies or substantial portions of the
+ * Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
+ * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
+ * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
+ * IN THE SOFTWARE.
+ */
+
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+#include 
+
+#include "drmtest.h"
+#include "igt_aux.h"
+#include "igt_core.h"
+#include "igt_v3d.h"
+#include "ioctl_wrappers.h"
+#include "intel_reg.h"
+#include "intel_chipset.h"
+#include "v3d_drm.h"
+
+#if NEW_CONTEXT_PARAM_NO_ERROR_CAPTURE_API
+#define LOCAL_CONTEXT_PARAM_NO_ERROR_CAPTURE 0x4
+#endif
+
+/**
+ * SECTION:igt_v3d
+ * @short_description: V3D support library
+ * @title: V3D
+ * @include: igt.h
+ *
+ * This library provides various auxiliary helper functions for writing V3D
+ * tests.
+ */
+
+struct v3d_bo *
+igt_v3d_create_bo(int fd, size_t size)
+{
+   struct v3d_bo *bo = calloc(1, sizeof(*bo));
+
+   struct drm_v3d_create_bo create = {
+   .size = size,
+   };
+
+   do_ioctl(fd, DRM_IOCTL_V3D_CREATE_BO, );
+
+   bo->handle = create.handle;
+   bo->offset = create.offset;
+   bo->size = size;
+
+   return bo;
+}
+
+void
+igt_v3d_free_bo(int fd, struct v3d_bo *bo)
+{
+   if (bo->map)
+   munmap(bo->map, bo->size);
+   gem_close(fd, bo->handle);
+   free(bo);
+}
+
+uint32_t
+igt_v3d_get_bo_offset(int fd, uint32_t handle)
+{
+   struct drm_v3d_get_bo_offset get = {
+   .handle = handle,
+   };
+
+   do_ioctl(fd, DRM_IOCTL_V3D_GET_BO_OFFSET, );
+
+   return get.offset;
+}
+
+uint32_t
+igt_v3d_get_param(int fd, enum drm_v3d_param param)
+{
+   struct drm_v3d_get_param get = {
+   .param = param,
+   };
+
+   do_ioctl(fd, DRM_IOCTL_V3D_GET_PARAM, );
+
+   return get.value;
+}
+
+void *
+igt_v3d_mmap_bo(int fd, uint32_t handle, uint32_t size, unsigned prot)
+{
+