Received: by 2002:a25:ab43:0:0:0:0:0 with SMTP id u61csp1543624ybi; Wed, 19 Jun 2019 23:08:11 -0700 (PDT) X-Google-Smtp-Source: APXvYqyYZ1vI1QQbNpxQewJ3mFjQgZ7DhmhVl7/SOnKFQOgoi+5m6KOKyHgcA4qbl/7uFMh6ADM1 X-Received: by 2002:aa7:90c9:: with SMTP id k9mr54053930pfk.171.1561010890913; Wed, 19 Jun 2019 23:08:10 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1561010890; cv=none; d=google.com; s=arc-20160816; b=r9L+c4vm59j9Lf+inQ2qxmr6/YwilCvBk5MW7c6AnmyOA8HfAHsZXbiSUY4V6LRUp6 BTtUnO9WJdnWfOe6ERN71T0hrGXf52mZ1TIMvZ7vQynLmD3BpF5yRv3NY2LfpsrxF4Cl IPslr3AjOFg18UWVjSwB9mdB5q9KY4LqZwdg9aC89t5aZR0Sc4jNnsZ4Bd8/fNvSJc8j 8OAKRf5qaQznqZtPJRVi2mAFZwH7LEKCq9QUF4nR7xMwXZ0+W1ofHhhcD6lH8+SIQaSt 7KmKLDcLh9MB4+q/A/ts6dOuWj5CNsCp9G00cR8dk+ulmZSNy8HPsrsfKYvq83tveXvd bxzA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:references:in-reply-to:message-id:date :subject:cc:to:from; bh=ZUoQdSz6Anj6cI0pqLUEWNV5C15jA6i9X4p2V2NLC6c=; b=Wfwbm2p5CIWCri3WlAOkD5xXfXtFL8j62CFozz8Jrk2NOA/89vMVTj/piTchwVilLl 3oPCbDZkkr1ClTQWiraLXtu7P5FMjdm/9VKcqcsPcztWKfie7m3VM3zFJao4VUhahtcz JawBY5mHy+FgU9uCixBsKMM8lD/87byYa0LX1OJIzy1azMb9FSzO1Vy6YxUtfSJibqHG GAmjWDV7668JL0kyNIMRrMTolQdz4BxPQA8gjMpB8/f35EhFWmXjclxR5KNrIr7D/eK1 VgxffY3KlXtsUiX8lvolGeH17AiDdx9ls91Q87nXeZzepKDSn8GBXec1+N0OAPoWv5Qv miZw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id a2si4871592pgq.298.2019.06.19.23.07.54; Wed, 19 Jun 2019 23:08:10 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=redhat.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730504AbfFTGHm (ORCPT + 99 others); Thu, 20 Jun 2019 02:07:42 -0400 Received: from mx1.redhat.com ([209.132.183.28]:35184 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726519AbfFTGHh (ORCPT ); Thu, 20 Jun 2019 02:07:37 -0400 Received: from smtp.corp.redhat.com (int-mx02.intmail.prod.int.phx2.redhat.com [10.5.11.12]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 0DACD30872C3; Thu, 20 Jun 2019 06:07:33 +0000 (UTC) Received: from sirius.home.kraxel.org (ovpn-116-212.ams2.redhat.com [10.36.116.212]) by smtp.corp.redhat.com (Postfix) with ESMTP id B50BD60FAB; Thu, 20 Jun 2019 06:07:30 +0000 (UTC) Received: by sirius.home.kraxel.org (Postfix, from userid 1000) id 092E01753A; Thu, 20 Jun 2019 08:07:27 +0200 (CEST) From: Gerd Hoffmann To: dri-devel@lists.freedesktop.org Cc: Gerd Hoffmann , David Airlie , Daniel Vetter , virtualization@lists.linux-foundation.org (open list:VIRTIO GPU DRIVER), linux-kernel@vger.kernel.org (open list) Subject: [PATCH v4 07/12] drm/virtio: add virtio_gpu_object_array & helpers Date: Thu, 20 Jun 2019 08:07:21 +0200 Message-Id: <20190620060726.926-8-kraxel@redhat.com> In-Reply-To: <20190620060726.926-1-kraxel@redhat.com> References: <20190620060726.926-1-kraxel@redhat.com> X-Scanned-By: MIMEDefang 2.79 on 10.5.11.12 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.5.110.47]); Thu, 20 Jun 2019 06:07:37 +0000 (UTC) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Some helper functions to manage an array of gem objects. v4: make them virtio-private instead of generic helpers. Signed-off-by: Gerd Hoffmann --- drivers/gpu/drm/virtio/virtgpu_drv.h | 10 ++++++ drivers/gpu/drm/virtio/virtgpu_gem.c | 50 ++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+) diff --git a/drivers/gpu/drm/virtio/virtgpu_drv.h b/drivers/gpu/drm/virtio/virtgpu_drv.h index 07f6001ea91e..98d646789d23 100644 --- a/drivers/gpu/drm/virtio/virtgpu_drv.h +++ b/drivers/gpu/drm/virtio/virtgpu_drv.h @@ -84,6 +84,11 @@ struct virtio_gpu_object { #define gem_to_virtio_gpu_obj(gobj) \ container_of((gobj), struct virtio_gpu_object, gem_base) +struct virtio_gpu_object_array { + u32 nents; + struct drm_gem_object *objs[]; +}; + struct virtio_gpu_vbuffer; struct virtio_gpu_device; @@ -251,6 +256,11 @@ int virtio_gpu_mode_dumb_mmap(struct drm_file *file_priv, struct drm_device *dev, uint32_t handle, uint64_t *offset_p); +struct virtio_gpu_object_array *virtio_gpu_array_alloc(u32 nents); +struct virtio_gpu_object_array* +virtio_gpu_array_from_handles(struct drm_file *drm_file, u32 *handles, u32 nents); +void virtio_gpu_array_put_free(struct virtio_gpu_object_array *objs); + /* virtio vg */ int virtio_gpu_alloc_vbufs(struct virtio_gpu_device *vgdev); void virtio_gpu_free_vbufs(struct virtio_gpu_device *vgdev); diff --git a/drivers/gpu/drm/virtio/virtgpu_gem.c b/drivers/gpu/drm/virtio/virtgpu_gem.c index 9c9ad3b14080..456cc382ce68 100644 --- a/drivers/gpu/drm/virtio/virtgpu_gem.c +++ b/drivers/gpu/drm/virtio/virtgpu_gem.c @@ -169,3 +169,53 @@ void virtio_gpu_gem_object_close(struct drm_gem_object *obj, qobj->hw_res_handle); virtio_gpu_object_unreserve(qobj); } + +struct virtio_gpu_object_array *virtio_gpu_array_alloc(u32 nents) +{ + struct virtio_gpu_object_array *objs; + size_t size = sizeof(*objs) + sizeof(objs->objs[0]) * nents; + + objs = kzalloc(size, GFP_KERNEL); + if (!objs) + return NULL; + + objs->nents = nents; + return objs; +} + +static void virtio_gpu_array_free(struct virtio_gpu_object_array *objs) +{ + kfree(objs); +} + +struct virtio_gpu_object_array* +virtio_gpu_array_from_handles(struct drm_file *drm_file, u32 *handles, u32 nents) +{ + struct virtio_gpu_object_array *objs; + u32 i; + + objs = virtio_gpu_array_alloc(nents); + if (!objs) + return NULL; + + for (i = 0; i < nents; i++) { + objs->objs[i] = drm_gem_object_lookup(drm_file, handles[i]); + if (!objs->objs[i]) { + virtio_gpu_array_put_free(objs); + return NULL; + } + } + return objs; +} + +void virtio_gpu_array_put_free(struct virtio_gpu_object_array *objs) +{ + u32 i; + + for (i = 0; i < objs->nents; i++) { + if (!objs->objs[i]) + continue; + drm_gem_object_put_unlocked(objs->objs[i]); + } + virtio_gpu_array_free(objs); +} -- 2.18.1