From patchwork Sat Mar 10 03:21:39 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: Jerome Glisse X-Patchwork-Id: 10273143 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork.web.codeaurora.org (Postfix) with ESMTP id EDE1B60236 for ; Sat, 10 Mar 2018 03:22:38 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id DF86229FEC for ; Sat, 10 Mar 2018 03:22:38 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D42D029FF1; Sat, 10 Mar 2018 03:22:38 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-4.2 required=2.0 tests=BAYES_00, RCVD_IN_DNSWL_MED autolearn=ham version=3.3.1 Received: from gabe.freedesktop.org (gabe.freedesktop.org [131.252.210.177]) (using TLSv1.2 with cipher DHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.wl.linuxfoundation.org (Postfix) with ESMTPS id 6C51A29FEC for ; Sat, 10 Mar 2018 03:22:38 +0000 (UTC) Received: from gabe.freedesktop.org (localhost [127.0.0.1]) by gabe.freedesktop.org (Postfix) with ESMTP id 9AE286EC7C; Sat, 10 Mar 2018 03:22:06 +0000 (UTC) X-Original-To: dri-devel@lists.freedesktop.org Delivered-To: dri-devel@lists.freedesktop.org Received: from mx1.redhat.com (mx3-rdu2.redhat.com [66.187.233.73]) by gabe.freedesktop.org (Postfix) with ESMTPS id DDA626EC76; Sat, 10 Mar 2018 03:22:01 +0000 (UTC) Received: from smtp.corp.redhat.com (int-mx04.intmail.prod.int.rdu2.redhat.com [10.11.54.4]) (using TLSv1.2 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by mx1.redhat.com (Postfix) with ESMTPS id 2899E4067F25; Sat, 10 Mar 2018 03:22:01 +0000 (UTC) Received: from localhost.localdomain.com (ovpn-120-68.rdu2.redhat.com [10.10.120.68]) by smtp.corp.redhat.com (Postfix) with ESMTP id B4A31202322A; Sat, 10 Mar 2018 03:22:00 +0000 (UTC) From: jglisse@redhat.com To: dri-devel@lists.freedesktop.org, nouveau@lists.freedesktop.org Subject: [RFC PATCH 11/13] drm/nouveau: add HMM area creation user interface Date: Fri, 9 Mar 2018 22:21:39 -0500 Message-Id: <20180310032141.6096-12-jglisse@redhat.com> In-Reply-To: <20180310032141.6096-1-jglisse@redhat.com> References: <20180310032141.6096-1-jglisse@redhat.com> MIME-Version: 1.0 X-Scanned-By: MIMEDefang 2.78 on 10.11.54.4 X-Greylist: Sender IP whitelisted, not delayed by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Sat, 10 Mar 2018 03:22:01 +0000 (UTC) X-Greylist: inspected by milter-greylist-4.5.16 (mx1.redhat.com [10.11.55.7]); Sat, 10 Mar 2018 03:22:01 +0000 (UTC) for IP:'10.11.54.4' DOMAIN:'int-mx04.intmail.prod.int.rdu2.redhat.com' HELO:'smtp.corp.redhat.com' FROM:'jglisse@redhat.com' RCPT:'' 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: Ralph Campbell , Evgeny Baskakov , linux-mm@kvack.org, =?UTF-8?q?J=C3=A9r=C3=B4me=20Glisse?= , Ben Skeggs , John Hubbard Errors-To: dri-devel-bounces@lists.freedesktop.org Sender: "dri-devel" X-Virus-Scanned: ClamAV using ClamSMTP From: Jérôme Glisse User API to create HMM area. Signed-off-by: Jérôme Glisse Cc: Ben Skeggs --- drivers/gpu/drm/nouveau/include/nvif/if000c.h | 9 +++++ drivers/gpu/drm/nouveau/include/nvif/vmm.h | 2 + drivers/gpu/drm/nouveau/nvif/vmm.c | 51 ++++++++++++++++++++++++++ drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c | 39 ++++++++++++++++++++ 4 files changed, 101 insertions(+) diff --git a/drivers/gpu/drm/nouveau/include/nvif/if000c.h b/drivers/gpu/drm/nouveau/include/nvif/if000c.h index 2c24817ca533..0383864b033b 100644 --- a/drivers/gpu/drm/nouveau/include/nvif/if000c.h +++ b/drivers/gpu/drm/nouveau/include/nvif/if000c.h @@ -16,6 +16,8 @@ struct nvif_vmm_v0 { #define NVIF_VMM_V0_UNMAP 0x04 #define NVIF_VMM_V0_HMM_MAP 0x05 #define NVIF_VMM_V0_HMM_UNMAP 0x06 +#define NVIF_VMM_V0_HMM_INIT 0x07 +#define NVIF_VMM_V0_HMM_FINI 0x08 struct nvif_vmm_page_v0 { __u8 version; @@ -78,4 +80,11 @@ struct nvif_vmm_hmm_unmap_v0 { __u64 addr; __u64 npages; }; + +struct nvif_vmm_hmm_v0 { + __u8 version; + __u8 pad01[7]; + __u64 start; + __u64 end; +}; #endif diff --git a/drivers/gpu/drm/nouveau/include/nvif/vmm.h b/drivers/gpu/drm/nouveau/include/nvif/vmm.h index c5e4adaa0e3c..f11f8c510ebd 100644 --- a/drivers/gpu/drm/nouveau/include/nvif/vmm.h +++ b/drivers/gpu/drm/nouveau/include/nvif/vmm.h @@ -39,6 +39,8 @@ void nvif_vmm_put(struct nvif_vmm *, struct nvif_vma *); int nvif_vmm_map(struct nvif_vmm *, u64 addr, u64 size, void *argv, u32 argc, struct nvif_mem *, u64 offset); int nvif_vmm_unmap(struct nvif_vmm *, u64); +int nvif_vmm_hmm_init(struct nvif_vmm *vmm, u64 hstart, u64 hend); +void nvif_vmm_hmm_fini(struct nvif_vmm *vmm, u64 hstart, u64 hend); int nvif_vmm_hmm_map(struct nvif_vmm *vmm, u64 addr, u64 npages, u64 *pages); int nvif_vmm_hmm_unmap(struct nvif_vmm *vmm, u64 addr, u64 npages); #endif diff --git a/drivers/gpu/drm/nouveau/nvif/vmm.c b/drivers/gpu/drm/nouveau/nvif/vmm.c index 27a7b95b4e9c..788e02e47750 100644 --- a/drivers/gpu/drm/nouveau/nvif/vmm.c +++ b/drivers/gpu/drm/nouveau/nvif/vmm.c @@ -32,6 +32,57 @@ nvif_vmm_unmap(struct nvif_vmm *vmm, u64 addr) sizeof(struct nvif_vmm_unmap_v0)); } +int +nvif_vmm_hmm_init(struct nvif_vmm *vmm, u64 hstart, u64 hend) +{ + struct nvif_vmm_hmm_v0 args; + int ret; + + if (hstart > PAGE_SIZE) { + args.version = 0; + args.start = PAGE_SIZE; + args.end = hstart; + ret = nvif_object_mthd(&vmm->object, NVIF_VMM_V0_HMM_INIT, + &args, sizeof(args)); + if (ret) + return ret; + } + + args.version = 0; + args.start = hend; + args.end = TASK_SIZE; + ret = nvif_object_mthd(&vmm->object, NVIF_VMM_V0_HMM_INIT, + &args, sizeof(args)); + if (ret && hstart > PAGE_SIZE) { + args.version = 0; + args.start = PAGE_SIZE; + args.end = hstart; + nvif_object_mthd(&vmm->object, NVIF_VMM_V0_HMM_FINI, + &args, sizeof(args)); + } + return ret; +} + +void +nvif_vmm_hmm_fini(struct nvif_vmm *vmm, u64 hstart, u64 hend) +{ + struct nvif_vmm_hmm_v0 args; + + if (hstart > PAGE_SIZE) { + args.version = 0; + args.start = PAGE_SIZE; + args.end = hstart; + nvif_object_mthd(&vmm->object, NVIF_VMM_V0_HMM_FINI, + &args, sizeof(args)); + } + + args.version = 0; + args.start = hend; + args.end = TASK_SIZE; + nvif_object_mthd(&vmm->object, NVIF_VMM_V0_HMM_FINI, + &args, sizeof(args)); +} + int nvif_vmm_hmm_map(struct nvif_vmm *vmm, u64 addr, u64 npages, u64 *pages) { diff --git a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c index 739f2af02552..34e00aa73fd0 100644 --- a/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c +++ b/drivers/gpu/drm/nouveau/nvkm/subdev/mmu/uvmm.c @@ -274,6 +274,43 @@ nvkm_uvmm_mthd_page(struct nvkm_uvmm *uvmm, void *argv, u32 argc) return 0; } +static int +nvkm_uvmm_mthd_hmm_init(struct nvkm_uvmm *uvmm, void *argv, u32 argc) +{ + union { + struct nvif_vmm_hmm_v0 v0; + } *args = argv; + struct nvkm_vmm *vmm = uvmm->vmm; + struct nvkm_vma *vma; + int ret = -ENOSYS; + + if ((ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) + return ret; + + mutex_lock(&vmm->mutex); + ret = nvkm_vmm_hmm_init(vmm, args->v0.start, args->v0.end, &vma); + mutex_unlock(&vmm->mutex); + return ret; +} + +static int +nvkm_uvmm_mthd_hmm_fini(struct nvkm_uvmm *uvmm, void *argv, u32 argc) +{ + union { + struct nvif_vmm_hmm_v0 v0; + } *args = argv; + struct nvkm_vmm *vmm = uvmm->vmm; + int ret = -ENOSYS; + + if ((ret = nvif_unpack(ret, &argv, &argc, args->v0, 0, 0, false))) + return ret; + + mutex_lock(&vmm->mutex); + nvkm_vmm_hmm_fini(vmm, args->v0.start, args->v0.end); + mutex_unlock(&vmm->mutex); + return 0; +} + static int nvkm_uvmm_mthd_hmm_map(struct nvkm_uvmm *uvmm, void *argv, u32 argc) { @@ -321,6 +358,8 @@ nvkm_uvmm_mthd(struct nvkm_object *object, u32 mthd, void *argv, u32 argc) case NVIF_VMM_V0_PUT : return nvkm_uvmm_mthd_put (uvmm, argv, argc); case NVIF_VMM_V0_MAP : return nvkm_uvmm_mthd_map (uvmm, argv, argc); case NVIF_VMM_V0_UNMAP : return nvkm_uvmm_mthd_unmap (uvmm, argv, argc); + case NVIF_VMM_V0_HMM_INIT : return nvkm_uvmm_mthd_hmm_init (uvmm, argv, argc); + case NVIF_VMM_V0_HMM_FINI : return nvkm_uvmm_mthd_hmm_fini (uvmm, argv, argc); case NVIF_VMM_V0_HMM_MAP : return nvkm_uvmm_mthd_hmm_map (uvmm, argv, argc); case NVIF_VMM_V0_HMM_UNMAP: return nvkm_uvmm_mthd_hmm_unmap(uvmm, argv, argc); default: