blob: 6d3764b416f43d8401cf56c182234f2cc8dc402f [file] [log] [blame]
Ben Skeggsa11c3192010-08-27 10:00:25 +10001/*
2 * Copyright 2010 Red Hat Inc.
3 *
4 * Permission is hereby granted, free of charge, to any person obtaining a
5 * copy of this software and associated documentation files (the "Software"),
6 * to deal in the Software without restriction, including without limitation
7 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
8 * and/or sell copies of the Software, and to permit persons to whom the
9 * Software is furnished to do so, subject to the following conditions:
10 *
11 * The above copyright notice and this permission notice shall be included in
12 * all copies or substantial portions of the Software.
13 *
14 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20 * OTHER DEALINGS IN THE SOFTWARE.
21 *
22 * Authors: Ben Skeggs
23 */
24
25#ifndef __NOUVEAU_VM_H__
26#define __NOUVEAU_VM_H__
27
Ben Skeggs02a841d2012-07-04 23:44:54 +100028#include <core/mm.h>
Ben Skeggsa11c3192010-08-27 10:00:25 +100029
Ben Skeggs861d2102012-07-11 19:05:01 +100030struct nouveau_mem;
31
Ben Skeggsa11c3192010-08-27 10:00:25 +100032struct nouveau_vm_pgt {
Ben Skeggs3ee01282010-12-15 11:04:39 +100033 struct nouveau_gpuobj *obj[2];
34 u32 refcount[2];
Ben Skeggsa11c3192010-08-27 10:00:25 +100035};
36
37struct nouveau_vm_pgd {
38 struct list_head head;
39 struct nouveau_gpuobj *obj;
40};
41
42struct nouveau_vma {
Ben Skeggsfd2871a2011-06-06 14:07:04 +100043 struct list_head head;
Ben Skeggs2fd3db62011-06-07 15:25:12 +100044 int refcount;
Ben Skeggsa11c3192010-08-27 10:00:25 +100045 struct nouveau_vm *vm;
46 struct nouveau_mm_node *node;
47 u64 offset;
48 u32 access;
49};
50
51struct nouveau_vm {
52 struct drm_device *dev;
Ben Skeggs987eec12011-06-24 10:14:07 +100053 struct nouveau_mm mm;
Ben Skeggsa11c3192010-08-27 10:00:25 +100054 int refcount;
55
56 struct list_head pgd_list;
Ben Skeggs6dfdd7a2011-03-31 15:40:43 +100057 atomic_t engref[16];
Ben Skeggsa11c3192010-08-27 10:00:25 +100058
59 struct nouveau_vm_pgt *pgt;
60 u32 fpde;
61 u32 lpde;
62
63 u32 pgt_bits;
64 u8 spg_shift;
65 u8 lpg_shift;
66
Ben Skeggs3ee01282010-12-15 11:04:39 +100067 void (*map_pgt)(struct nouveau_gpuobj *pgd, u32 pde,
68 struct nouveau_gpuobj *pgt[2]);
Ben Skeggsa11c3192010-08-27 10:00:25 +100069 void (*map)(struct nouveau_vma *, struct nouveau_gpuobj *,
Ben Skeggs8f7286f2011-02-14 09:57:35 +100070 struct nouveau_mem *, u32 pte, u32 cnt,
71 u64 phys, u64 delta);
Ben Skeggsa11c3192010-08-27 10:00:25 +100072 void (*map_sg)(struct nouveau_vma *, struct nouveau_gpuobj *,
Ben Skeggs26c0c9e2011-02-10 12:59:51 +100073 struct nouveau_mem *, u32 pte, u32 cnt, dma_addr_t *);
Dave Airlie22b33e82012-04-02 11:53:06 +010074
75 void (*map_sg_table)(struct nouveau_vma *, struct nouveau_gpuobj *,
76 struct nouveau_mem *, u32 pte, u32 cnt, dma_addr_t *);
Ben Skeggsa11c3192010-08-27 10:00:25 +100077 void (*unmap)(struct nouveau_gpuobj *pgt, u32 pte, u32 cnt);
78 void (*flush)(struct nouveau_vm *);
79};
80
81/* nouveau_vm.c */
82int nouveau_vm_new(struct drm_device *, u64 offset, u64 length, u64 mm_offset,
Ben Skeggsa11c3192010-08-27 10:00:25 +100083 struct nouveau_vm **);
84int nouveau_vm_ref(struct nouveau_vm *, struct nouveau_vm **,
85 struct nouveau_gpuobj *pgd);
86int nouveau_vm_get(struct nouveau_vm *, u64 size, u32 page_shift,
87 u32 access, struct nouveau_vma *);
88void nouveau_vm_put(struct nouveau_vma *);
Ben Skeggsd5f42392011-02-10 12:22:52 +100089void nouveau_vm_map(struct nouveau_vma *, struct nouveau_mem *);
90void nouveau_vm_map_at(struct nouveau_vma *, u64 offset, struct nouveau_mem *);
Ben Skeggsa11c3192010-08-27 10:00:25 +100091void nouveau_vm_unmap(struct nouveau_vma *);
92void nouveau_vm_unmap_at(struct nouveau_vma *, u64 offset, u64 length);
93void nouveau_vm_map_sg(struct nouveau_vma *, u64 offset, u64 length,
Ben Skeggsf7b24c42011-12-22 15:20:21 +100094 struct nouveau_mem *);
Dave Airlie22b33e82012-04-02 11:53:06 +010095void nouveau_vm_map_sg_table(struct nouveau_vma *vma, u64 delta, u64 length,
96 struct nouveau_mem *mem);
Ben Skeggsa11c3192010-08-27 10:00:25 +100097/* nv50_vm.c */
Ben Skeggs3ee01282010-12-15 11:04:39 +100098void nv50_vm_map_pgt(struct nouveau_gpuobj *pgd, u32 pde,
99 struct nouveau_gpuobj *pgt[2]);
Ben Skeggsa11c3192010-08-27 10:00:25 +1000100void nv50_vm_map(struct nouveau_vma *, struct nouveau_gpuobj *,
Ben Skeggs8f7286f2011-02-14 09:57:35 +1000101 struct nouveau_mem *, u32 pte, u32 cnt, u64 phys, u64 delta);
Ben Skeggsa11c3192010-08-27 10:00:25 +1000102void nv50_vm_map_sg(struct nouveau_vma *, struct nouveau_gpuobj *,
Ben Skeggs26c0c9e2011-02-10 12:59:51 +1000103 struct nouveau_mem *, u32 pte, u32 cnt, dma_addr_t *);
Ben Skeggsa11c3192010-08-27 10:00:25 +1000104void nv50_vm_unmap(struct nouveau_gpuobj *, u32 pte, u32 cnt);
105void nv50_vm_flush(struct nouveau_vm *);
106void nv50_vm_flush_engine(struct drm_device *, int engine);
107
Ben Skeggs4c74eb72010-11-10 14:10:04 +1000108/* nvc0_vm.c */
109void nvc0_vm_map_pgt(struct nouveau_gpuobj *pgd, u32 pde,
110 struct nouveau_gpuobj *pgt[2]);
111void nvc0_vm_map(struct nouveau_vma *, struct nouveau_gpuobj *,
Ben Skeggs8f7286f2011-02-14 09:57:35 +1000112 struct nouveau_mem *, u32 pte, u32 cnt, u64 phys, u64 delta);
Ben Skeggs4c74eb72010-11-10 14:10:04 +1000113void nvc0_vm_map_sg(struct nouveau_vma *, struct nouveau_gpuobj *,
Ben Skeggs26c0c9e2011-02-10 12:59:51 +1000114 struct nouveau_mem *, u32 pte, u32 cnt, dma_addr_t *);
Ben Skeggs4c74eb72010-11-10 14:10:04 +1000115void nvc0_vm_unmap(struct nouveau_gpuobj *, u32 pte, u32 cnt);
116void nvc0_vm_flush(struct nouveau_vm *);
117
Ben Skeggsa11c3192010-08-27 10:00:25 +1000118#endif