From patchwork Thu Aug 8 22:21:54 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Rob Herring \(Arm\)" X-Patchwork-Id: 170869 Delivered-To: patch@linaro.org Received: by 2002:a92:512:0:0:0:0:0 with SMTP id q18csp9165289ile; Thu, 8 Aug 2019 15:22:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqwp9/3njdsj8RXqz57y7BIA3psJEmlU4ifLDKFPUx7vISLvLGiOtX+qyiW4Ad7Julgpmg+D X-Received: by 2002:a62:be02:: with SMTP id l2mr18292803pff.63.1565302935572; Thu, 08 Aug 2019 15:22:15 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1565302935; cv=none; d=google.com; s=arc-20160816; b=LZkMoPYBNS4CmmNhmfrfi5Nd2g7J9wqgf/3DP9lzuyFObGILI6wUgie+Y7f/cR5GM4 k8WaN57IWJ5PT5qttM2sAB0l8jHfn/hTW03HC6Yf5OlJGLismdtXXITRNQvgR0G/rTbY Z0IayS/xdh+lNKCJY3YicGsNhfVQahRu/8Bd05qZkV5x2IO1tV//DA8zDHsgee1ftJ5L HUoNRlvYlAE1ezU9z7fn0FzdlXFSXsW9ocuTm9ZvuQkoIK7u1onhAxvGLWg2550LxKIr wpSeubSCbKxh6fbg4DQb6DMJIBck1UvrpnDYd1a2aNdWp8JZhY29EMIsWMFwfdr76adx vyWA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:mime-version:references:in-reply-to:message-id:date :subject:to:from:delivered-to; bh=hkOGDxao1cmftX5Isf+8SRBzLHjyUu/EU3itkmdYjKs=; b=bHkQYaJPBmwLDzOGkFiE0BHSVDyFG1zpAZYLFsHY6VgaPSKCUBwc4Nh9OSIMwpRiAy Of5aiH2cKpWLgq6OwPOzyU+/1RG9tdlqsCt162uxLX8oG3dh+7zyu5htZSq+PcN6yGzV rRSlzgzZCuH56mZTv7C64BGNd30BWQvTiRqs/cM4m4Uhps7XRPMPnGUxO+9v/lYuH0VF hPaZve/+ViDzfricBjWVqJm8tZy0YtVdIF/Hv0IHlsqOeRPXzMZIeB891i1KI9lZPm1P Oua4nn8p8G+42btFAPBX0HzhY/eQQ7FXUc0I44UxER8Xd75tDbkkOHCvmvaFgtAhk3mb zwyA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from gabe.freedesktop.org (gabe.freedesktop.org. [2610:10:20:722:a800:ff:fe36:1795]) by mx.google.com with ESMTPS id y65si51001682pgd.487.2019.08.08.15.22.15 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Thu, 08 Aug 2019 15:22:15 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) client-ip=2610:10:20:722:a800:ff:fe36:1795; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of dri-devel-bounces@lists.freedesktop.org designates 2610:10:20:722:a800:ff:fe36:1795 as permitted sender) smtp.mailfrom=dri-devel-bounces@lists.freedesktop.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id ED5616ECD1; Thu, 8 Aug 2019 22:22:11 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mail-ot1-f67.google.com (mail-ot1-f67.google.com [209.85.210.67]) by gabe.freedesktop.org (Postfix) with ESMTPS id 7BA546ECCF for ; Thu, 8 Aug 2019 22:22:07 +0000 (UTC) Received: by mail-ot1-f67.google.com with SMTP id r6so125062371oti.3 for ; Thu, 08 Aug 2019 15:22:07 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=9XWAdju+IoI2fqlCu19mLm3Rct7rl0h7CjpFgTCovt8=; b=aHVPlM5JuHjJt8CxCmvPp8tI74mY8j8aERx0Ta46gvXuoh66DWrLDcApxVsBknQS4T C2E3SODconWz7CoFTflmlhjObBaUdJVzeq70DXarmUejRBAqsuicV/5qe9RDqCjixpUk km6w8f36MFQ+vIOaPn6j5UU8Hj9n0BSibBZPud2MxgGP4bI3IvPLSqoxuLhUqsFJPGgZ 0yGQl3C8qDYwBwVrPx3QBsy5gY7KeN5JhUcWzE89np4+Jjc6qcWm4zq/eCVw+EvKub6r VrU1BFByNjoVdRYIgAPJJP5hzuhPsXIeM6Sp3z61lhaxB4LohQpneET6cbnw98SmXkDY z5Ig== X-Gm-Message-State: APjAAAVwzVSaEoBfZQuhnrhT4nv2+l2FAoSRhPQKF2DrbqSv3Ns0AzoA rJ36A4MHqpdo7AnVDSncecHyGuA= X-Received: by 2002:a6b:cdcc:: with SMTP id d195mr4793841iog.78.1565302926193; Thu, 08 Aug 2019 15:22:06 -0700 (PDT) Received: from xps15.herring.priv ([64.188.179.254]) by smtp.googlemail.com with ESMTPSA id i4sm118528553iog.31.2019.08.08.15.22.04 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Thu, 08 Aug 2019 15:22:05 -0700 (PDT) From: Rob Herring To: dri-devel@lists.freedesktop.org Subject: [PATCH v4 3/9] drm/panfrost: Restructure the GEM object creation Date: Thu, 8 Aug 2019 16:21:54 -0600 Message-Id: <20190808222200.13176-4-robh@kernel.org> X-Mailer: git-send-email 2.20.1 In-Reply-To: <20190808222200.13176-1-robh@kernel.org> References: <20190808222200.13176-1-robh@kernel.org> MIME-Version: 1.0 X-BeenThere: dri-devel@lists.freedesktop.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: Direct Rendering Infrastructure - Development List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: Tomeu Vizoso , Maxime Ripard , Robin Murphy , Steven Price , David Airlie , Boris Brezillon , Alyssa Rosenzweig , Sean Paul Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" Setting the GPU VA when creating the GEM object doesn't allow for any conditional adjustments to the mapping. In preparation to support adjusting the mapping and per FD address spaces, restructure the GEM object creation to map and unmap the GEM object in the GEM object .open() and .close() hooks. While panfrost_gem_free_object() and panfrost_gem_prime_import_sg_table() are not really needed after this commit, keep them as we'll need them in subsequent commits. Cc: Tomeu Vizoso Cc: Boris Brezillon Cc: Robin Murphy Reviewed-by: Steven Price Acked-by: Alyssa Rosenzweig Signed-off-by: Rob Herring --- Steven, Alyssa, I kept your tags, but please take another look as things moved around a bit here. drivers/gpu/drm/panfrost/panfrost_drv.c | 9 ---- drivers/gpu/drm/panfrost/panfrost_gem.c | 67 ++++++++++++++----------- 2 files changed, 37 insertions(+), 39 deletions(-) -- 2.20.1 diff --git a/drivers/gpu/drm/panfrost/panfrost_drv.c b/drivers/gpu/drm/panfrost/panfrost_drv.c index 926d021ee202..2894cfbbce2b 100644 --- a/drivers/gpu/drm/panfrost/panfrost_drv.c +++ b/drivers/gpu/drm/panfrost/panfrost_drv.c @@ -78,7 +78,6 @@ static int panfrost_ioctl_get_param(struct drm_device *ddev, void *data, struct static int panfrost_ioctl_create_bo(struct drm_device *dev, void *data, struct drm_file *file) { - int ret; struct drm_gem_shmem_object *shmem; struct drm_panfrost_create_bo *args = data; @@ -90,17 +89,9 @@ static int panfrost_ioctl_create_bo(struct drm_device *dev, void *data, if (IS_ERR(shmem)) return PTR_ERR(shmem); - ret = panfrost_mmu_map(to_panfrost_bo(&shmem->base)); - if (ret) - goto err_free; - args->offset = to_panfrost_bo(&shmem->base)->node.start << PAGE_SHIFT; return 0; - -err_free: - drm_gem_handle_delete(file, args->handle); - return ret; } /** diff --git a/drivers/gpu/drm/panfrost/panfrost_gem.c b/drivers/gpu/drm/panfrost/panfrost_gem.c index 67d374184340..3933f83ba6b0 100644 --- a/drivers/gpu/drm/panfrost/panfrost_gem.c +++ b/drivers/gpu/drm/panfrost/panfrost_gem.c @@ -15,6 +15,39 @@ * BO. */ static void panfrost_gem_free_object(struct drm_gem_object *obj) +{ + mutex_lock(&pfdev->shrinker_lock); + if (!list_empty(&bo->base.madv_list)) + list_del(&bo->base.madv_list); + mutex_unlock(&pfdev->shrinker_lock); + + drm_gem_shmem_free_object(obj); +} + +static int panfrost_gem_open(struct drm_gem_object *obj, struct drm_file *file_priv) +{ + int ret; + size_t size = obj->size; + u64 align = size >= SZ_2M ? SZ_2M >> PAGE_SHIFT : 0; + struct panfrost_gem_object *bo = to_panfrost_bo(obj); + struct panfrost_device *pfdev = obj->dev->dev_private; + + spin_lock(&pfdev->mm_lock); + ret = drm_mm_insert_node_generic(&pfdev->mm, &bo->node, + size >> PAGE_SHIFT, align, 0, 0); + if (ret) + goto out; + + ret = panfrost_mmu_map(bo); + if (ret) + drm_mm_remove_node(&bo->node); + +out: + spin_unlock(&pfdev->mm_lock); + return ret; +} + +static void panfrost_gem_close(struct drm_gem_object *obj, struct drm_file *file_priv) { struct panfrost_gem_object *bo = to_panfrost_bo(obj); struct panfrost_device *pfdev = obj->dev->dev_private; @@ -23,19 +56,15 @@ static void panfrost_gem_free_object(struct drm_gem_object *obj) panfrost_mmu_unmap(bo); spin_lock(&pfdev->mm_lock); - drm_mm_remove_node(&bo->node); + if (drm_mm_node_allocated(&bo->node)) + drm_mm_remove_node(&bo->node); spin_unlock(&pfdev->mm_lock); - - mutex_lock(&pfdev->shrinker_lock); - if (!list_empty(&bo->base.madv_list)) - list_del(&bo->base.madv_list); - mutex_unlock(&pfdev->shrinker_lock); - - drm_gem_shmem_free_object(obj); } static const struct drm_gem_object_funcs panfrost_gem_funcs = { .free = panfrost_gem_free_object, + .open = panfrost_gem_open, + .close = panfrost_gem_close, .print_info = drm_gem_shmem_print_info, .pin = drm_gem_shmem_pin, .unpin = drm_gem_shmem_unpin, @@ -55,10 +84,7 @@ static const struct drm_gem_object_funcs panfrost_gem_funcs = { */ struct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_t size) { - int ret; - struct panfrost_device *pfdev = dev->dev_private; struct panfrost_gem_object *obj; - u64 align; obj = kzalloc(sizeof(*obj), GFP_KERNEL); if (!obj) @@ -66,21 +92,7 @@ struct drm_gem_object *panfrost_gem_create_object(struct drm_device *dev, size_t obj->base.base.funcs = &panfrost_gem_funcs; - size = roundup(size, PAGE_SIZE); - align = size >= SZ_2M ? SZ_2M >> PAGE_SHIFT : 0; - - spin_lock(&pfdev->mm_lock); - ret = drm_mm_insert_node_generic(&pfdev->mm, &obj->node, - size >> PAGE_SHIFT, align, 0, 0); - spin_unlock(&pfdev->mm_lock); - if (ret) - goto free_obj; - return &obj->base.base; - -free_obj: - kfree(obj); - return ERR_PTR(ret); } struct drm_gem_object * @@ -89,15 +101,10 @@ panfrost_gem_prime_import_sg_table(struct drm_device *dev, struct sg_table *sgt) { struct drm_gem_object *obj; - struct panfrost_gem_object *pobj; obj = drm_gem_shmem_prime_import_sg_table(dev, attach, sgt); if (IS_ERR(obj)) return ERR_CAST(obj); - pobj = to_panfrost_bo(obj); - - panfrost_mmu_map(pobj); - return obj; }