From: Petri Latvala <petri.latvala@intel.com> To: Rob Clark <robdclark@gmail.com> Cc: igt-dev@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Jordan Crouse <jordan@cosmicpenguin.net>, Akhil P Oommen <akhilpo@codeaurora.org>, Rob Clark <robdclark@chromium.org> Subject: Re: [PATCH igt v2 2/3] msm: Add helper library Date: Thu, 26 Aug 2021 08:28:11 +0300 [thread overview] Message-ID: <YScma3GeDyv+DIVn@platvala-desk.ger.corp.intel.com> (raw) In-Reply-To: <20210825233139.1066504-3-robdclark@gmail.com> On Wed, Aug 25, 2021 at 04:31:38PM -0700, Rob Clark wrote: > From: Rob Clark <robdclark@chromium.org> > > Handle some of the boilerplate for tests. > > Signed-off-by: Rob Clark <robdclark@chromium.org> > --- > lib/igt_msm.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++ > lib/igt_msm.h | 119 +++++++++++++++++++++++++++++++++ > lib/meson.build | 1 + > 3 files changed, 291 insertions(+) > create mode 100644 lib/igt_msm.c > create mode 100644 lib/igt_msm.h > > diff --git a/lib/igt_msm.c b/lib/igt_msm.c > new file mode 100644 > index 00000000..3bd0ee53 > --- /dev/null > +++ b/lib/igt_msm.c > @@ -0,0 +1,171 @@ > +/* > + * Copyright © 2021 Google, Inc. > + * > + * 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 <assert.h> > +#include <string.h> > +#include <signal.h> > +#include <errno.h> > +#include <sys/mman.h> > +#include <sys/types.h> > +#include <sys/stat.h> > +#include <sys/ioctl.h> > +#include <fcntl.h> > + > +#include "drmtest.h" > +#include "igt_aux.h" > +#include "igt_core.h" > +#include "igt_msm.h" > +#include "ioctl_wrappers.h" > + > +/** > + * SECTION:igt_msm > + * @short_description: msm support library > + * @title: msm > + * @include: igt_msm.h > + * > + * This library provides various auxiliary helper functions for writing msm > + * tests. > + */ > + > +static uint64_t > +get_param(struct msm_device *dev, uint32_t pipe, uint32_t param) > +{ > + struct drm_msm_param req = { > + .pipe = pipe, > + .param = param, > + }; > + > + do_ioctl(dev->fd, DRM_IOCTL_MSM_GET_PARAM, &req); > + > + return req.value; > +} > + > +struct msm_device * > +igt_msm_dev_open(void) > +{ > + struct msm_device *dev = calloc(1, sizeof(*dev)); > + > + dev->fd = drm_open_driver_render(DRIVER_MSM); > + if (dev->fd < 0) { > + free(dev); > + return NULL; > + } Note that drm_open_driver_render() cannot return < 0. > + > + dev->gen = (get_param(dev, MSM_PIPE_3D0, MSM_PARAM_CHIP_ID) >> 24) & 0xff; > + > + return dev; > +} > + > +void > +igt_msm_dev_close(struct msm_device *dev) > +{ > + close(dev->fd); > + free(dev); > +} > + > +struct msm_bo * > +igt_msm_bo_new(struct msm_device *dev, size_t size, uint32_t flags) > +{ > + struct msm_bo *bo = calloc(1, sizeof(*bo)); > + > + struct drm_msm_gem_new req = { > + .size = size, > + .flags = flags, > + }; > + > + bo->dev = dev; > + bo->size = size; > + > + do_ioctl(dev->fd, DRM_IOCTL_MSM_GEM_NEW, &req); > + > + bo->handle = req.handle; > + > + return bo; > +} > + > +void > +igt_msm_bo_free(struct msm_bo *bo) > +{ > + if (bo->map) > + munmap(bo->map, bo->size); > + gem_close(bo->dev->fd, bo->handle); > + free(bo); > +} > + > +void * > +igt_msm_bo_map(struct msm_bo *bo) > +{ > + if (!bo->map) { > + struct drm_msm_gem_info req = { > + .handle = bo->handle, > + .info = MSM_INFO_GET_OFFSET, > + }; > + void *ptr; > + > + do_ioctl(bo->dev->fd, DRM_IOCTL_MSM_GEM_INFO, &req); > + > + ptr = mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED, > + bo->dev->fd, req.value); > + if (ptr == MAP_FAILED) > + return NULL; > + > + bo->map = ptr; > + } > + return bo->map; > +} > + > +struct msm_pipe * > +igt_msm_pipe_open(struct msm_device *dev, uint32_t prio) > +{ > + struct msm_pipe *pipe = calloc(1, sizeof(*pipe)); > + struct drm_msm_submitqueue req = { > + .flags = 0, > + .prio = prio, > + }; > + > + pipe->dev = dev; > + pipe->pipe = MSM_PIPE_3D0; > + > + /* Note that kerenels prior to v4.15 did not support submitqueues. > + * Mesa maintains support for older kernels, but I do not think > + * that IGT needs to. > + */ > + do_ioctl(dev->fd, DRM_IOCTL_MSM_SUBMITQUEUE_NEW, &req); We try to maintain compatibility with older kernels to around "yay back". If you want to be perfect, this part could produce a skip if submitqueues don't exist, but most often such dancing is not worth the trouble. Letting it fail "normally" on an old kernel is fine, the error message received already points out which ioctl failed. You can remove the uncertainty from this comment, in other words. Also typo, kerenels -> kernels. -- Petri Latvala
WARNING: multiple messages have this Message-ID (diff)
From: Petri Latvala <petri.latvala@intel.com> To: Rob Clark <robdclark@gmail.com> Cc: igt-dev@lists.freedesktop.org, freedreno@lists.freedesktop.org, linux-arm-msm@vger.kernel.org, Jordan Crouse <jordan@cosmicpenguin.net>, Akhil P Oommen <akhilpo@codeaurora.org>, Rob Clark <robdclark@chromium.org> Subject: Re: [igt-dev] [PATCH igt v2 2/3] msm: Add helper library Date: Thu, 26 Aug 2021 08:28:11 +0300 [thread overview] Message-ID: <YScma3GeDyv+DIVn@platvala-desk.ger.corp.intel.com> (raw) In-Reply-To: <20210825233139.1066504-3-robdclark@gmail.com> On Wed, Aug 25, 2021 at 04:31:38PM -0700, Rob Clark wrote: > From: Rob Clark <robdclark@chromium.org> > > Handle some of the boilerplate for tests. > > Signed-off-by: Rob Clark <robdclark@chromium.org> > --- > lib/igt_msm.c | 171 ++++++++++++++++++++++++++++++++++++++++++++++++ > lib/igt_msm.h | 119 +++++++++++++++++++++++++++++++++ > lib/meson.build | 1 + > 3 files changed, 291 insertions(+) > create mode 100644 lib/igt_msm.c > create mode 100644 lib/igt_msm.h > > diff --git a/lib/igt_msm.c b/lib/igt_msm.c > new file mode 100644 > index 00000000..3bd0ee53 > --- /dev/null > +++ b/lib/igt_msm.c > @@ -0,0 +1,171 @@ > +/* > + * Copyright © 2021 Google, Inc. > + * > + * 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 <assert.h> > +#include <string.h> > +#include <signal.h> > +#include <errno.h> > +#include <sys/mman.h> > +#include <sys/types.h> > +#include <sys/stat.h> > +#include <sys/ioctl.h> > +#include <fcntl.h> > + > +#include "drmtest.h" > +#include "igt_aux.h" > +#include "igt_core.h" > +#include "igt_msm.h" > +#include "ioctl_wrappers.h" > + > +/** > + * SECTION:igt_msm > + * @short_description: msm support library > + * @title: msm > + * @include: igt_msm.h > + * > + * This library provides various auxiliary helper functions for writing msm > + * tests. > + */ > + > +static uint64_t > +get_param(struct msm_device *dev, uint32_t pipe, uint32_t param) > +{ > + struct drm_msm_param req = { > + .pipe = pipe, > + .param = param, > + }; > + > + do_ioctl(dev->fd, DRM_IOCTL_MSM_GET_PARAM, &req); > + > + return req.value; > +} > + > +struct msm_device * > +igt_msm_dev_open(void) > +{ > + struct msm_device *dev = calloc(1, sizeof(*dev)); > + > + dev->fd = drm_open_driver_render(DRIVER_MSM); > + if (dev->fd < 0) { > + free(dev); > + return NULL; > + } Note that drm_open_driver_render() cannot return < 0. > + > + dev->gen = (get_param(dev, MSM_PIPE_3D0, MSM_PARAM_CHIP_ID) >> 24) & 0xff; > + > + return dev; > +} > + > +void > +igt_msm_dev_close(struct msm_device *dev) > +{ > + close(dev->fd); > + free(dev); > +} > + > +struct msm_bo * > +igt_msm_bo_new(struct msm_device *dev, size_t size, uint32_t flags) > +{ > + struct msm_bo *bo = calloc(1, sizeof(*bo)); > + > + struct drm_msm_gem_new req = { > + .size = size, > + .flags = flags, > + }; > + > + bo->dev = dev; > + bo->size = size; > + > + do_ioctl(dev->fd, DRM_IOCTL_MSM_GEM_NEW, &req); > + > + bo->handle = req.handle; > + > + return bo; > +} > + > +void > +igt_msm_bo_free(struct msm_bo *bo) > +{ > + if (bo->map) > + munmap(bo->map, bo->size); > + gem_close(bo->dev->fd, bo->handle); > + free(bo); > +} > + > +void * > +igt_msm_bo_map(struct msm_bo *bo) > +{ > + if (!bo->map) { > + struct drm_msm_gem_info req = { > + .handle = bo->handle, > + .info = MSM_INFO_GET_OFFSET, > + }; > + void *ptr; > + > + do_ioctl(bo->dev->fd, DRM_IOCTL_MSM_GEM_INFO, &req); > + > + ptr = mmap(0, bo->size, PROT_READ | PROT_WRITE, MAP_SHARED, > + bo->dev->fd, req.value); > + if (ptr == MAP_FAILED) > + return NULL; > + > + bo->map = ptr; > + } > + return bo->map; > +} > + > +struct msm_pipe * > +igt_msm_pipe_open(struct msm_device *dev, uint32_t prio) > +{ > + struct msm_pipe *pipe = calloc(1, sizeof(*pipe)); > + struct drm_msm_submitqueue req = { > + .flags = 0, > + .prio = prio, > + }; > + > + pipe->dev = dev; > + pipe->pipe = MSM_PIPE_3D0; > + > + /* Note that kerenels prior to v4.15 did not support submitqueues. > + * Mesa maintains support for older kernels, but I do not think > + * that IGT needs to. > + */ > + do_ioctl(dev->fd, DRM_IOCTL_MSM_SUBMITQUEUE_NEW, &req); We try to maintain compatibility with older kernels to around "yay back". If you want to be perfect, this part could produce a skip if submitqueues don't exist, but most often such dancing is not worth the trouble. Letting it fail "normally" on an old kernel is fine, the error message received already points out which ioctl failed. You can remove the uncertainty from this comment, in other words. Also typo, kerenels -> kernels. -- Petri Latvala
next prev parent reply other threads:[~2021-08-26 5:25 UTC|newest] Thread overview: 24+ messages / expand[flat|nested] mbox.gz Atom feed top 2021-08-25 23:31 [PATCH igt v2 0/3] Initial igt tests for drm/msm ioctls Rob Clark 2021-08-25 23:31 ` [igt-dev] " Rob Clark 2021-08-25 23:31 ` [PATCH igt v2 1/3] drmtest: Add DRIVER_MSM support Rob Clark 2021-08-25 23:31 ` [igt-dev] " Rob Clark 2021-08-27 6:56 ` Petri Latvala 2021-08-27 6:56 ` [igt-dev] " Petri Latvala 2021-08-25 23:31 ` [PATCH igt v2 2/3] msm: Add helper library Rob Clark 2021-08-25 23:31 ` [igt-dev] " Rob Clark 2021-08-26 5:28 ` Petri Latvala [this message] 2021-08-26 5:28 ` Petri Latvala 2021-08-27 6:58 ` Petri Latvala 2021-08-27 6:58 ` [igt-dev] " Petri Latvala 2021-08-25 23:31 ` [PATCH igt v2 3/3] msm: Add submit ioctl tests Rob Clark 2021-08-25 23:31 ` [igt-dev] " Rob Clark 2021-08-26 5:31 ` Petri Latvala 2021-08-26 5:31 ` [igt-dev] " Petri Latvala 2021-08-26 15:37 ` Rob Clark 2021-08-26 15:37 ` [igt-dev] " Rob Clark 2021-08-27 5:37 ` Petri Latvala 2021-08-27 5:37 ` [igt-dev] " Petri Latvala 2021-08-27 6:59 ` Petri Latvala 2021-08-27 6:59 ` [igt-dev] " Petri Latvala 2021-08-26 0:20 ` [igt-dev] ✓ Fi.CI.BAT: success for Initial igt tests for drm/msm ioctls (rev2) Patchwork 2021-08-26 8:03 ` [igt-dev] ✗ Fi.CI.IGT: failure " Patchwork
Reply instructions: You may reply publicly to this message via plain-text email using any one of the following methods: * Save the following mbox file, import it into your mail client, and reply-to-all from there: mbox Avoid top-posting and favor interleaved quoting: https://en.wikipedia.org/wiki/Posting_style#Interleaved_style * Reply using the --to, --cc, and --in-reply-to switches of git-send-email(1): git send-email \ --in-reply-to=YScma3GeDyv+DIVn@platvala-desk.ger.corp.intel.com \ --to=petri.latvala@intel.com \ --cc=akhilpo@codeaurora.org \ --cc=freedreno@lists.freedesktop.org \ --cc=igt-dev@lists.freedesktop.org \ --cc=jordan@cosmicpenguin.net \ --cc=linux-arm-msm@vger.kernel.org \ --cc=robdclark@chromium.org \ --cc=robdclark@gmail.com \ /path/to/YOUR_REPLY https://kernel.org/pub/software/scm/git/docs/git-send-email.html * If your mail client supports setting the In-Reply-To header via mailto: links, try the mailto: linkBe sure your reply has a Subject: header at the top and a blank line before the message body.
This is an external index of several public inboxes, see mirroring instructions on how to clone and mirror all data and code used by this external index.