Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1 | /* |
| 2 | * Copyright 2007 Dave Airlied |
| 3 | * All Rights Reserved. |
| 4 | * |
| 5 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 6 | * copy of this software and associated documentation files (the "Software"), |
| 7 | * to deal in the Software without restriction, including without limitation |
| 8 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 9 | * and/or sell copies of the Software, and to permit persons to whom the |
| 10 | * Software is furnished to do so, subject to the following conditions: |
| 11 | * |
| 12 | * The above copyright notice and this permission notice (including the next |
| 13 | * paragraph) shall be included in all copies or substantial portions of the |
| 14 | * Software. |
| 15 | * |
| 16 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 17 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 18 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 19 | * VA LINUX SYSTEMS AND/OR ITS SUPPLIERS BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 20 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 21 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 22 | * OTHER DEALINGS IN THE SOFTWARE. |
| 23 | */ |
| 24 | /* |
| 25 | * Authors: Dave Airlied <airlied@linux.ie> |
| 26 | * Ben Skeggs <darktama@iinet.net.au> |
| 27 | * Jeremy Kolb <jkolb@brandeis.edu> |
| 28 | */ |
| 29 | |
Ben Skeggs | fdb751e | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 30 | #include <linux/dma-mapping.h> |
Chris Metcalf | 3e2b756 | 2013-02-01 13:44:33 -0500 | [diff] [blame] | 31 | #include <linux/swiotlb.h> |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 32 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 33 | #include "nouveau_drm.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 34 | #include "nouveau_dma.h" |
Ben Skeggs | d375e7d5 | 2012-04-30 13:30:00 +1000 | [diff] [blame] | 35 | #include "nouveau_fence.h" |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 36 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 37 | #include "nouveau_bo.h" |
| 38 | #include "nouveau_ttm.h" |
| 39 | #include "nouveau_gem.h" |
Maarten Maathuis | a510604 | 2009-12-26 21:46:36 +0100 | [diff] [blame] | 40 | |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 41 | /* |
| 42 | * NV10-NV40 tiling helpers |
| 43 | */ |
| 44 | |
| 45 | static void |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 46 | nv10_bo_update_tile_region(struct drm_device *dev, struct nouveau_drm_tile *reg, |
| 47 | u32 addr, u32 size, u32 pitch, u32 flags) |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 48 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 49 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 50 | int i = reg - drm->tile.reg; |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 51 | struct nouveau_fb *pfb = nvkm_fb(&drm->device); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 52 | struct nouveau_fb_tile *tile = &pfb->tile.region[i]; |
| 53 | struct nouveau_engine *engine; |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 54 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 55 | nouveau_fence_unref(®->fence); |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 56 | |
| 57 | if (tile->pitch) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 58 | pfb->tile.fini(pfb, i, tile); |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 59 | |
| 60 | if (pitch) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 61 | pfb->tile.init(pfb, i, addr, size, pitch, flags, tile); |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 62 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 63 | pfb->tile.prog(pfb, i, tile); |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 64 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 65 | if ((engine = nouveau_engine(pfb, NVDEV_ENGINE_GR))) |
| 66 | engine->tile_prog(engine, i); |
| 67 | if ((engine = nouveau_engine(pfb, NVDEV_ENGINE_MPEG))) |
| 68 | engine->tile_prog(engine, i); |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 69 | } |
| 70 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 71 | static struct nouveau_drm_tile * |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 72 | nv10_bo_get_tile_region(struct drm_device *dev, int i) |
| 73 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 74 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 75 | struct nouveau_drm_tile *tile = &drm->tile.reg[i]; |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 76 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 77 | spin_lock(&drm->tile.lock); |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 78 | |
| 79 | if (!tile->used && |
| 80 | (!tile->fence || nouveau_fence_done(tile->fence))) |
| 81 | tile->used = true; |
| 82 | else |
| 83 | tile = NULL; |
| 84 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 85 | spin_unlock(&drm->tile.lock); |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 86 | return tile; |
| 87 | } |
| 88 | |
| 89 | static void |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 90 | nv10_bo_put_tile_region(struct drm_device *dev, struct nouveau_drm_tile *tile, |
Maarten Lankhorst | f2c24b8 | 2014-04-02 17:14:48 +0200 | [diff] [blame] | 91 | struct fence *fence) |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 92 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 93 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 94 | |
| 95 | if (tile) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 96 | spin_lock(&drm->tile.lock); |
Maarten Lankhorst | 809e944 | 2014-04-09 16:19:30 +0200 | [diff] [blame] | 97 | tile->fence = (struct nouveau_fence *)fence_get(fence); |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 98 | tile->used = false; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 99 | spin_unlock(&drm->tile.lock); |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 100 | } |
| 101 | } |
| 102 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 103 | static struct nouveau_drm_tile * |
| 104 | nv10_bo_set_tiling(struct drm_device *dev, u32 addr, |
| 105 | u32 size, u32 pitch, u32 flags) |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 106 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 107 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 108 | struct nouveau_fb *pfb = nvkm_fb(&drm->device); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 109 | struct nouveau_drm_tile *tile, *found = NULL; |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 110 | int i; |
| 111 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 112 | for (i = 0; i < pfb->tile.regions; i++) { |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 113 | tile = nv10_bo_get_tile_region(dev, i); |
| 114 | |
| 115 | if (pitch && !found) { |
| 116 | found = tile; |
| 117 | continue; |
| 118 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 119 | } else if (tile && pfb->tile.region[i].pitch) { |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 120 | /* Kill an unused tile region. */ |
| 121 | nv10_bo_update_tile_region(dev, tile, 0, 0, 0, 0); |
| 122 | } |
| 123 | |
| 124 | nv10_bo_put_tile_region(dev, tile, NULL); |
| 125 | } |
| 126 | |
| 127 | if (found) |
| 128 | nv10_bo_update_tile_region(dev, found, addr, size, |
| 129 | pitch, flags); |
| 130 | return found; |
| 131 | } |
| 132 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 133 | static void |
| 134 | nouveau_bo_del_ttm(struct ttm_buffer_object *bo) |
| 135 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 136 | struct nouveau_drm *drm = nouveau_bdev(bo->bdev); |
| 137 | struct drm_device *dev = drm->dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 138 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 139 | |
David Herrmann | 55fb74a | 2013-10-02 10:15:17 +0200 | [diff] [blame] | 140 | if (unlikely(nvbo->gem.filp)) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 141 | DRM_ERROR("bo %p still attached to GEM object\n", bo); |
Maarten Lankhorst | 4f38559 | 2013-07-07 10:37:35 +0200 | [diff] [blame] | 142 | WARN_ON(nvbo->pin_refcnt > 0); |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 143 | nv10_bo_put_tile_region(dev, nvbo->tile, NULL); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 144 | kfree(nvbo); |
| 145 | } |
| 146 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 147 | static void |
Ben Skeggs | db5c8e2 | 2011-02-10 13:41:01 +1000 | [diff] [blame] | 148 | nouveau_bo_fixup_align(struct nouveau_bo *nvbo, u32 flags, |
Ben Skeggs | f91bac5 | 2011-06-06 14:15:46 +1000 | [diff] [blame] | 149 | int *align, int *size) |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 150 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 151 | struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev); |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 152 | struct nvif_device *device = &drm->device; |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 153 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 154 | if (device->info.family < NV_DEVICE_INFO_V0_TESLA) { |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame] | 155 | if (nvbo->tile_mode) { |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 156 | if (device->info.chipset >= 0x40) { |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 157 | *align = 65536; |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame] | 158 | *size = roundup(*size, 64 * nvbo->tile_mode); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 159 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 160 | } else if (device->info.chipset >= 0x30) { |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 161 | *align = 32768; |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame] | 162 | *size = roundup(*size, 64 * nvbo->tile_mode); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 163 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 164 | } else if (device->info.chipset >= 0x20) { |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 165 | *align = 16384; |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame] | 166 | *size = roundup(*size, 64 * nvbo->tile_mode); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 167 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 168 | } else if (device->info.chipset >= 0x10) { |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 169 | *align = 16384; |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame] | 170 | *size = roundup(*size, 32 * nvbo->tile_mode); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 171 | } |
| 172 | } |
Ben Skeggs | bfd83ac | 2010-11-12 15:12:51 +1000 | [diff] [blame] | 173 | } else { |
Ben Skeggs | f91bac5 | 2011-06-06 14:15:46 +1000 | [diff] [blame] | 174 | *size = roundup(*size, (1 << nvbo->page_shift)); |
| 175 | *align = max((1 << nvbo->page_shift), *align); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 176 | } |
| 177 | |
Maarten Maathuis | 1c7059e | 2009-12-25 18:51:17 +0100 | [diff] [blame] | 178 | *size = roundup(*size, PAGE_SIZE); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 179 | } |
| 180 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 181 | int |
Ben Skeggs | 7375c95 | 2011-06-07 14:21:29 +1000 | [diff] [blame] | 182 | nouveau_bo_new(struct drm_device *dev, int size, int align, |
| 183 | uint32_t flags, uint32_t tile_mode, uint32_t tile_flags, |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 184 | struct sg_table *sg, |
Ben Skeggs | 7375c95 | 2011-06-07 14:21:29 +1000 | [diff] [blame] | 185 | struct nouveau_bo **pnvbo) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 186 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 187 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 188 | struct nouveau_bo *nvbo; |
Jerome Glisse | 57de4ba | 2011-11-11 15:42:57 -0500 | [diff] [blame] | 189 | size_t acc_size; |
Ben Skeggs | f91bac5 | 2011-06-06 14:15:46 +1000 | [diff] [blame] | 190 | int ret; |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 191 | int type = ttm_bo_type_device; |
Maarten Lankhorst | 35095f7 | 2013-07-27 10:17:12 +0200 | [diff] [blame] | 192 | int lpg_shift = 12; |
| 193 | int max_size; |
| 194 | |
Ben Skeggs | 3ee6f5b | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 195 | if (drm->client.vm) |
| 196 | lpg_shift = drm->client.vm->vmm->lpg_shift; |
Maarten Lankhorst | 35095f7 | 2013-07-27 10:17:12 +0200 | [diff] [blame] | 197 | max_size = INT_MAX & ~((1 << lpg_shift) - 1); |
Maarten Lankhorst | 0108bc8 | 2013-07-07 10:40:19 +0200 | [diff] [blame] | 198 | |
| 199 | if (size <= 0 || size > max_size) { |
Ben Skeggs | fa2bade | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 200 | NV_WARN(drm, "skipped size %x\n", (u32)size); |
Maarten Lankhorst | 0108bc8 | 2013-07-07 10:40:19 +0200 | [diff] [blame] | 201 | return -EINVAL; |
| 202 | } |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 203 | |
| 204 | if (sg) |
| 205 | type = ttm_bo_type_sg; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 206 | |
| 207 | nvbo = kzalloc(sizeof(struct nouveau_bo), GFP_KERNEL); |
| 208 | if (!nvbo) |
| 209 | return -ENOMEM; |
| 210 | INIT_LIST_HEAD(&nvbo->head); |
| 211 | INIT_LIST_HEAD(&nvbo->entry); |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 212 | INIT_LIST_HEAD(&nvbo->vma_list); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 213 | nvbo->tile_mode = tile_mode; |
| 214 | nvbo->tile_flags = tile_flags; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 215 | nvbo->bo.bdev = &drm->ttm.bdev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 216 | |
Ben Skeggs | f91bac5 | 2011-06-06 14:15:46 +1000 | [diff] [blame] | 217 | nvbo->page_shift = 12; |
Ben Skeggs | 3ee6f5b | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 218 | if (drm->client.vm) { |
Ben Skeggs | f91bac5 | 2011-06-06 14:15:46 +1000 | [diff] [blame] | 219 | if (!(flags & TTM_PL_FLAG_TT) && size > 256 * 1024) |
Ben Skeggs | 3ee6f5b | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 220 | nvbo->page_shift = drm->client.vm->vmm->lpg_shift; |
Ben Skeggs | f91bac5 | 2011-06-06 14:15:46 +1000 | [diff] [blame] | 221 | } |
| 222 | |
| 223 | nouveau_bo_fixup_align(nvbo, flags, &align, &size); |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 224 | nvbo->bo.mem.num_pages = size >> PAGE_SHIFT; |
| 225 | nouveau_bo_placement_set(nvbo, flags, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 226 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 227 | acc_size = ttm_bo_dma_acc_size(&drm->ttm.bdev, size, |
Jerome Glisse | 57de4ba | 2011-11-11 15:42:57 -0500 | [diff] [blame] | 228 | sizeof(struct nouveau_bo)); |
| 229 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 230 | ret = ttm_bo_init(&drm->ttm.bdev, &nvbo->bo, size, |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 231 | type, &nvbo->placement, |
Marcin Slusarz | 0b91c4a | 2012-11-06 21:49:51 +0000 | [diff] [blame] | 232 | align >> PAGE_SHIFT, false, NULL, acc_size, sg, |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 233 | nouveau_bo_del_ttm); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 234 | if (ret) { |
| 235 | /* ttm will call nouveau_bo_del_ttm if it fails.. */ |
| 236 | return ret; |
| 237 | } |
| 238 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 239 | *pnvbo = nvbo; |
| 240 | return 0; |
| 241 | } |
| 242 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 243 | static void |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 244 | set_placement_list(struct ttm_place *pl, unsigned *n, uint32_t type, uint32_t flags) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 245 | { |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 246 | *n = 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 247 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 248 | if (type & TTM_PL_FLAG_VRAM) |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 249 | pl[(*n)++].flags = TTM_PL_FLAG_VRAM | flags; |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 250 | if (type & TTM_PL_FLAG_TT) |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 251 | pl[(*n)++].flags = TTM_PL_FLAG_TT | flags; |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 252 | if (type & TTM_PL_FLAG_SYSTEM) |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 253 | pl[(*n)++].flags = TTM_PL_FLAG_SYSTEM | flags; |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 254 | } |
Ben Skeggs | 37cb3e08 | 2009-12-16 16:22:42 +1000 | [diff] [blame] | 255 | |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 256 | static void |
| 257 | set_placement_range(struct nouveau_bo *nvbo, uint32_t type) |
| 258 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 259 | struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev); |
Ben Skeggs | f392ec4 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 260 | u32 vram_pages = drm->device.info.ram_size >> PAGE_SHIFT; |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 261 | unsigned i, fpfn, lpfn; |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 262 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 263 | if (drm->device.info.family == NV_DEVICE_INFO_V0_CELSIUS && |
Francisco Jerez | 812f219 | 2011-02-03 01:49:33 +0100 | [diff] [blame] | 264 | nvbo->tile_mode && (type & TTM_PL_FLAG_VRAM) && |
Francisco Jerez | 4beb116 | 2011-11-06 21:21:28 +0100 | [diff] [blame] | 265 | nvbo->bo.mem.num_pages < vram_pages / 4) { |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 266 | /* |
| 267 | * Make sure that the color and depth buffers are handled |
| 268 | * by independent memory controller units. Up to a 9x |
| 269 | * speed up when alpha-blending and depth-test are enabled |
| 270 | * at the same time. |
| 271 | */ |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 272 | if (nvbo->tile_flags & NOUVEAU_GEM_TILE_ZETA) { |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 273 | fpfn = vram_pages / 2; |
| 274 | lpfn = ~0; |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 275 | } else { |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 276 | fpfn = 0; |
| 277 | lpfn = vram_pages / 2; |
| 278 | } |
| 279 | for (i = 0; i < nvbo->placement.num_placement; ++i) { |
| 280 | nvbo->placements[i].fpfn = fpfn; |
| 281 | nvbo->placements[i].lpfn = lpfn; |
| 282 | } |
| 283 | for (i = 0; i < nvbo->placement.num_busy_placement; ++i) { |
| 284 | nvbo->busy_placements[i].fpfn = fpfn; |
| 285 | nvbo->busy_placements[i].lpfn = lpfn; |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 286 | } |
| 287 | } |
| 288 | } |
| 289 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 290 | void |
| 291 | nouveau_bo_placement_set(struct nouveau_bo *nvbo, uint32_t type, uint32_t busy) |
| 292 | { |
| 293 | struct ttm_placement *pl = &nvbo->placement; |
| 294 | uint32_t flags = TTM_PL_MASK_CACHING | |
| 295 | (nvbo->pin_refcnt ? TTM_PL_FLAG_NO_EVICT : 0); |
| 296 | |
| 297 | pl->placement = nvbo->placements; |
| 298 | set_placement_list(nvbo->placements, &pl->num_placement, |
| 299 | type, flags); |
| 300 | |
| 301 | pl->busy_placement = nvbo->busy_placements; |
| 302 | set_placement_list(nvbo->busy_placements, &pl->num_busy_placement, |
| 303 | type | busy, flags); |
Francisco Jerez | 699ddfd | 2010-10-10 06:07:32 +0200 | [diff] [blame] | 304 | |
| 305 | set_placement_range(nvbo, type); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 306 | } |
| 307 | |
| 308 | int |
| 309 | nouveau_bo_pin(struct nouveau_bo *nvbo, uint32_t memtype) |
| 310 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 311 | struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 312 | struct ttm_buffer_object *bo = &nvbo->bo; |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 313 | int ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 314 | |
Thierry Reding | ee3939e | 2014-07-21 13:15:51 +0200 | [diff] [blame] | 315 | ret = ttm_bo_reserve(bo, false, false, false, NULL); |
Daniel Vetter | 0ae6d7b | 2012-12-11 21:52:30 +0100 | [diff] [blame] | 316 | if (ret) |
| 317 | goto out; |
| 318 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 319 | if (nvbo->pin_refcnt && !(memtype & (1 << bo->mem.mem_type))) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 320 | NV_ERROR(drm, "bo %p pinned elsewhere: 0x%08x vs 0x%08x\n", bo, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 321 | 1 << bo->mem.mem_type, memtype); |
Daniel Vetter | 0ae6d7b | 2012-12-11 21:52:30 +0100 | [diff] [blame] | 322 | ret = -EINVAL; |
| 323 | goto out; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 324 | } |
| 325 | |
| 326 | if (nvbo->pin_refcnt++) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 327 | goto out; |
| 328 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 329 | nouveau_bo_placement_set(nvbo, memtype, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 330 | |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 331 | ret = nouveau_bo_validate(nvbo, false, false); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 332 | if (ret == 0) { |
| 333 | switch (bo->mem.mem_type) { |
| 334 | case TTM_PL_VRAM: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 335 | drm->gem.vram_available -= bo->mem.size; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 336 | break; |
| 337 | case TTM_PL_TT: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 338 | drm->gem.gart_available -= bo->mem.size; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 339 | break; |
| 340 | default: |
| 341 | break; |
| 342 | } |
| 343 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 344 | out: |
Daniel Vetter | 0ae6d7b | 2012-12-11 21:52:30 +0100 | [diff] [blame] | 345 | ttm_bo_unreserve(bo); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 346 | return ret; |
| 347 | } |
| 348 | |
| 349 | int |
| 350 | nouveau_bo_unpin(struct nouveau_bo *nvbo) |
| 351 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 352 | struct nouveau_drm *drm = nouveau_bdev(nvbo->bo.bdev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 353 | struct ttm_buffer_object *bo = &nvbo->bo; |
Maarten Lankhorst | 4f38559 | 2013-07-07 10:37:35 +0200 | [diff] [blame] | 354 | int ret, ref; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 355 | |
Thierry Reding | ee3939e | 2014-07-21 13:15:51 +0200 | [diff] [blame] | 356 | ret = ttm_bo_reserve(bo, false, false, false, NULL); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 357 | if (ret) |
| 358 | return ret; |
| 359 | |
Maarten Lankhorst | 4f38559 | 2013-07-07 10:37:35 +0200 | [diff] [blame] | 360 | ref = --nvbo->pin_refcnt; |
| 361 | WARN_ON_ONCE(ref < 0); |
| 362 | if (ref) |
Daniel Vetter | 0ae6d7b | 2012-12-11 21:52:30 +0100 | [diff] [blame] | 363 | goto out; |
| 364 | |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 365 | nouveau_bo_placement_set(nvbo, bo->mem.placement, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 366 | |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 367 | ret = nouveau_bo_validate(nvbo, false, false); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 368 | if (ret == 0) { |
| 369 | switch (bo->mem.mem_type) { |
| 370 | case TTM_PL_VRAM: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 371 | drm->gem.vram_available += bo->mem.size; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 372 | break; |
| 373 | case TTM_PL_TT: |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 374 | drm->gem.gart_available += bo->mem.size; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 375 | break; |
| 376 | default: |
| 377 | break; |
| 378 | } |
| 379 | } |
| 380 | |
Daniel Vetter | 0ae6d7b | 2012-12-11 21:52:30 +0100 | [diff] [blame] | 381 | out: |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 382 | ttm_bo_unreserve(bo); |
| 383 | return ret; |
| 384 | } |
| 385 | |
| 386 | int |
| 387 | nouveau_bo_map(struct nouveau_bo *nvbo) |
| 388 | { |
| 389 | int ret; |
| 390 | |
Thierry Reding | ee3939e | 2014-07-21 13:15:51 +0200 | [diff] [blame] | 391 | ret = ttm_bo_reserve(&nvbo->bo, false, false, false, NULL); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 392 | if (ret) |
| 393 | return ret; |
| 394 | |
| 395 | ret = ttm_bo_kmap(&nvbo->bo, 0, nvbo->bo.mem.num_pages, &nvbo->kmap); |
| 396 | ttm_bo_unreserve(&nvbo->bo); |
| 397 | return ret; |
| 398 | } |
| 399 | |
| 400 | void |
| 401 | nouveau_bo_unmap(struct nouveau_bo *nvbo) |
| 402 | { |
Ben Skeggs | 9d59e8a | 2010-08-27 13:04:41 +1000 | [diff] [blame] | 403 | if (nvbo) |
| 404 | ttm_bo_kunmap(&nvbo->kmap); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 405 | } |
| 406 | |
Ben Skeggs | 7a45d76 | 2010-11-22 08:50:27 +1000 | [diff] [blame] | 407 | int |
| 408 | nouveau_bo_validate(struct nouveau_bo *nvbo, bool interruptible, |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 409 | bool no_wait_gpu) |
Ben Skeggs | 7a45d76 | 2010-11-22 08:50:27 +1000 | [diff] [blame] | 410 | { |
| 411 | int ret; |
| 412 | |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 413 | ret = ttm_bo_validate(&nvbo->bo, &nvbo->placement, |
| 414 | interruptible, no_wait_gpu); |
Ben Skeggs | 7a45d76 | 2010-11-22 08:50:27 +1000 | [diff] [blame] | 415 | if (ret) |
| 416 | return ret; |
| 417 | |
| 418 | return 0; |
| 419 | } |
| 420 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 421 | u16 |
| 422 | nouveau_bo_rd16(struct nouveau_bo *nvbo, unsigned index) |
| 423 | { |
| 424 | bool is_iomem; |
| 425 | u16 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem); |
| 426 | mem = &mem[index]; |
| 427 | if (is_iomem) |
| 428 | return ioread16_native((void __force __iomem *)mem); |
| 429 | else |
| 430 | return *mem; |
| 431 | } |
| 432 | |
| 433 | void |
| 434 | nouveau_bo_wr16(struct nouveau_bo *nvbo, unsigned index, u16 val) |
| 435 | { |
| 436 | bool is_iomem; |
| 437 | u16 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem); |
| 438 | mem = &mem[index]; |
| 439 | if (is_iomem) |
| 440 | iowrite16_native(val, (void __force __iomem *)mem); |
| 441 | else |
| 442 | *mem = val; |
| 443 | } |
| 444 | |
| 445 | u32 |
| 446 | nouveau_bo_rd32(struct nouveau_bo *nvbo, unsigned index) |
| 447 | { |
| 448 | bool is_iomem; |
| 449 | u32 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem); |
| 450 | mem = &mem[index]; |
| 451 | if (is_iomem) |
| 452 | return ioread32_native((void __force __iomem *)mem); |
| 453 | else |
| 454 | return *mem; |
| 455 | } |
| 456 | |
| 457 | void |
| 458 | nouveau_bo_wr32(struct nouveau_bo *nvbo, unsigned index, u32 val) |
| 459 | { |
| 460 | bool is_iomem; |
| 461 | u32 *mem = ttm_kmap_obj_virtual(&nvbo->kmap, &is_iomem); |
| 462 | mem = &mem[index]; |
| 463 | if (is_iomem) |
| 464 | iowrite32_native(val, (void __force __iomem *)mem); |
| 465 | else |
| 466 | *mem = val; |
| 467 | } |
| 468 | |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 469 | static struct ttm_tt * |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 470 | nouveau_ttm_tt_create(struct ttm_bo_device *bdev, unsigned long size, |
| 471 | uint32_t page_flags, struct page *dummy_read) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 472 | { |
Max Filippov | df1b4b9 | 2012-10-14 01:58:26 +0400 | [diff] [blame] | 473 | #if __OS_HAS_AGP |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 474 | struct nouveau_drm *drm = nouveau_bdev(bdev); |
| 475 | struct drm_device *dev = drm->dev; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 476 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 477 | if (drm->agp.stat == ENABLED) { |
| 478 | return ttm_agp_tt_create(bdev, dev->agp->bridge, size, |
| 479 | page_flags, dummy_read); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 480 | } |
Max Filippov | df1b4b9 | 2012-10-14 01:58:26 +0400 | [diff] [blame] | 481 | #endif |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 482 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 483 | return nouveau_sgdma_create_ttm(bdev, size, page_flags, dummy_read); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 484 | } |
| 485 | |
| 486 | static int |
| 487 | nouveau_bo_invalidate_caches(struct ttm_bo_device *bdev, uint32_t flags) |
| 488 | { |
| 489 | /* We'll do this from user space. */ |
| 490 | return 0; |
| 491 | } |
| 492 | |
| 493 | static int |
| 494 | nouveau_bo_init_mem_type(struct ttm_bo_device *bdev, uint32_t type, |
| 495 | struct ttm_mem_type_manager *man) |
| 496 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 497 | struct nouveau_drm *drm = nouveau_bdev(bdev); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 498 | |
| 499 | switch (type) { |
| 500 | case TTM_PL_SYSTEM: |
| 501 | man->flags = TTM_MEMTYPE_FLAG_MAPPABLE; |
| 502 | man->available_caching = TTM_PL_MASK_CACHING; |
| 503 | man->default_caching = TTM_PL_FLAG_CACHED; |
| 504 | break; |
| 505 | case TTM_PL_VRAM: |
Alexandre Courbot | e2a4e78 | 2014-06-27 19:28:50 +0900 | [diff] [blame] | 506 | man->flags = TTM_MEMTYPE_FLAG_FIXED | |
| 507 | TTM_MEMTYPE_FLAG_MAPPABLE; |
| 508 | man->available_caching = TTM_PL_FLAG_UNCACHED | |
| 509 | TTM_PL_FLAG_WC; |
| 510 | man->default_caching = TTM_PL_FLAG_WC; |
| 511 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 512 | if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) { |
Alexandre Courbot | e2a4e78 | 2014-06-27 19:28:50 +0900 | [diff] [blame] | 513 | /* Some BARs do not support being ioremapped WC */ |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 514 | if (nvkm_bar(&drm->device)->iomap_uncached) { |
Alexandre Courbot | e2a4e78 | 2014-06-27 19:28:50 +0900 | [diff] [blame] | 515 | man->available_caching = TTM_PL_FLAG_UNCACHED; |
| 516 | man->default_caching = TTM_PL_FLAG_UNCACHED; |
| 517 | } |
| 518 | |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 519 | man->func = &nouveau_vram_manager; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 520 | man->io_reserve_fastpath = false; |
| 521 | man->use_io_reserve_lru = true; |
| 522 | } else { |
Ben Skeggs | 573a2a3 | 2010-08-25 15:26:04 +1000 | [diff] [blame] | 523 | man->func = &ttm_bo_manager_func; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 524 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 525 | break; |
| 526 | case TTM_PL_TT: |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 527 | if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) |
Ben Skeggs | 26c0c9e | 2011-02-10 12:59:51 +1000 | [diff] [blame] | 528 | man->func = &nouveau_gart_manager; |
| 529 | else |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 530 | if (drm->agp.stat != ENABLED) |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame] | 531 | man->func = &nv04_gart_manager; |
| 532 | else |
Ben Skeggs | 26c0c9e | 2011-02-10 12:59:51 +1000 | [diff] [blame] | 533 | man->func = &ttm_bo_manager_func; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 534 | |
| 535 | if (drm->agp.stat == ENABLED) { |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 536 | man->flags = TTM_MEMTYPE_FLAG_MAPPABLE; |
Francisco Jerez | a3d487e | 2010-11-20 22:11:22 +0100 | [diff] [blame] | 537 | man->available_caching = TTM_PL_FLAG_UNCACHED | |
| 538 | TTM_PL_FLAG_WC; |
| 539 | man->default_caching = TTM_PL_FLAG_WC; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 540 | } else { |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 541 | man->flags = TTM_MEMTYPE_FLAG_MAPPABLE | |
| 542 | TTM_MEMTYPE_FLAG_CMA; |
| 543 | man->available_caching = TTM_PL_MASK_CACHING; |
| 544 | man->default_caching = TTM_PL_FLAG_CACHED; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 545 | } |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 546 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 547 | break; |
| 548 | default: |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 549 | return -EINVAL; |
| 550 | } |
| 551 | return 0; |
| 552 | } |
| 553 | |
| 554 | static void |
| 555 | nouveau_bo_evict_flags(struct ttm_buffer_object *bo, struct ttm_placement *pl) |
| 556 | { |
| 557 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 558 | |
| 559 | switch (bo->mem.mem_type) { |
Francisco Jerez | 22fbd53 | 2009-12-11 18:40:17 +0100 | [diff] [blame] | 560 | case TTM_PL_VRAM: |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 561 | nouveau_bo_placement_set(nvbo, TTM_PL_FLAG_TT, |
| 562 | TTM_PL_FLAG_SYSTEM); |
Francisco Jerez | 22fbd53 | 2009-12-11 18:40:17 +0100 | [diff] [blame] | 563 | break; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 564 | default: |
Francisco Jerez | 78ad0f7 | 2010-03-18 13:07:47 +0100 | [diff] [blame] | 565 | nouveau_bo_placement_set(nvbo, TTM_PL_FLAG_SYSTEM, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 566 | break; |
| 567 | } |
Francisco Jerez | 22fbd53 | 2009-12-11 18:40:17 +0100 | [diff] [blame] | 568 | |
| 569 | *pl = nvbo->placement; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 570 | } |
| 571 | |
| 572 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 573 | static int |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 574 | nve0_bo_move_init(struct nouveau_channel *chan, u32 handle) |
| 575 | { |
| 576 | int ret = RING_SPACE(chan, 2); |
| 577 | if (ret == 0) { |
| 578 | BEGIN_NVC0(chan, NvSubCopy, 0x0000, 1); |
Ben Skeggs | 00fc6f6 | 2013-07-09 14:20:15 +1000 | [diff] [blame] | 579 | OUT_RING (chan, handle & 0x0000ffff); |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 580 | FIRE_RING (chan); |
| 581 | } |
| 582 | return ret; |
| 583 | } |
| 584 | |
| 585 | static int |
Ben Skeggs | c6b7e89 | 2012-03-20 14:36:04 +1000 | [diff] [blame] | 586 | nve0_bo_move_copy(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
| 587 | struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem) |
| 588 | { |
| 589 | struct nouveau_mem *node = old_mem->mm_node; |
| 590 | int ret = RING_SPACE(chan, 10); |
| 591 | if (ret == 0) { |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 592 | BEGIN_NVC0(chan, NvSubCopy, 0x0400, 8); |
Ben Skeggs | c6b7e89 | 2012-03-20 14:36:04 +1000 | [diff] [blame] | 593 | OUT_RING (chan, upper_32_bits(node->vma[0].offset)); |
| 594 | OUT_RING (chan, lower_32_bits(node->vma[0].offset)); |
| 595 | OUT_RING (chan, upper_32_bits(node->vma[1].offset)); |
| 596 | OUT_RING (chan, lower_32_bits(node->vma[1].offset)); |
| 597 | OUT_RING (chan, PAGE_SIZE); |
| 598 | OUT_RING (chan, PAGE_SIZE); |
| 599 | OUT_RING (chan, PAGE_SIZE); |
| 600 | OUT_RING (chan, new_mem->num_pages); |
Ben Skeggs | 6d59702 | 2012-04-01 21:09:13 +1000 | [diff] [blame] | 601 | BEGIN_IMC0(chan, NvSubCopy, 0x0300, 0x0386); |
Ben Skeggs | c6b7e89 | 2012-03-20 14:36:04 +1000 | [diff] [blame] | 602 | } |
| 603 | return ret; |
| 604 | } |
| 605 | |
| 606 | static int |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 607 | nvc0_bo_move_init(struct nouveau_channel *chan, u32 handle) |
| 608 | { |
| 609 | int ret = RING_SPACE(chan, 2); |
| 610 | if (ret == 0) { |
| 611 | BEGIN_NVC0(chan, NvSubCopy, 0x0000, 1); |
| 612 | OUT_RING (chan, handle); |
| 613 | } |
| 614 | return ret; |
| 615 | } |
| 616 | |
| 617 | static int |
Ben Skeggs | 1a46098 | 2012-05-04 15:17:28 +1000 | [diff] [blame] | 618 | nvc0_bo_move_copy(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
| 619 | struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem) |
| 620 | { |
| 621 | struct nouveau_mem *node = old_mem->mm_node; |
| 622 | u64 src_offset = node->vma[0].offset; |
| 623 | u64 dst_offset = node->vma[1].offset; |
| 624 | u32 page_count = new_mem->num_pages; |
| 625 | int ret; |
| 626 | |
| 627 | page_count = new_mem->num_pages; |
| 628 | while (page_count) { |
| 629 | int line_count = (page_count > 8191) ? 8191 : page_count; |
| 630 | |
| 631 | ret = RING_SPACE(chan, 11); |
| 632 | if (ret) |
| 633 | return ret; |
| 634 | |
| 635 | BEGIN_NVC0(chan, NvSubCopy, 0x030c, 8); |
| 636 | OUT_RING (chan, upper_32_bits(src_offset)); |
| 637 | OUT_RING (chan, lower_32_bits(src_offset)); |
| 638 | OUT_RING (chan, upper_32_bits(dst_offset)); |
| 639 | OUT_RING (chan, lower_32_bits(dst_offset)); |
| 640 | OUT_RING (chan, PAGE_SIZE); |
| 641 | OUT_RING (chan, PAGE_SIZE); |
| 642 | OUT_RING (chan, PAGE_SIZE); |
| 643 | OUT_RING (chan, line_count); |
| 644 | BEGIN_NVC0(chan, NvSubCopy, 0x0300, 1); |
| 645 | OUT_RING (chan, 0x00000110); |
| 646 | |
| 647 | page_count -= line_count; |
| 648 | src_offset += (PAGE_SIZE * line_count); |
| 649 | dst_offset += (PAGE_SIZE * line_count); |
| 650 | } |
| 651 | |
| 652 | return 0; |
| 653 | } |
| 654 | |
| 655 | static int |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 656 | nvc0_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
| 657 | struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem) |
| 658 | { |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 659 | struct nouveau_mem *node = old_mem->mm_node; |
| 660 | u64 src_offset = node->vma[0].offset; |
| 661 | u64 dst_offset = node->vma[1].offset; |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 662 | u32 page_count = new_mem->num_pages; |
| 663 | int ret; |
| 664 | |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 665 | page_count = new_mem->num_pages; |
| 666 | while (page_count) { |
| 667 | int line_count = (page_count > 2047) ? 2047 : page_count; |
| 668 | |
| 669 | ret = RING_SPACE(chan, 12); |
| 670 | if (ret) |
| 671 | return ret; |
| 672 | |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 673 | BEGIN_NVC0(chan, NvSubCopy, 0x0238, 2); |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 674 | OUT_RING (chan, upper_32_bits(dst_offset)); |
| 675 | OUT_RING (chan, lower_32_bits(dst_offset)); |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 676 | BEGIN_NVC0(chan, NvSubCopy, 0x030c, 6); |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 677 | OUT_RING (chan, upper_32_bits(src_offset)); |
| 678 | OUT_RING (chan, lower_32_bits(src_offset)); |
| 679 | OUT_RING (chan, PAGE_SIZE); /* src_pitch */ |
| 680 | OUT_RING (chan, PAGE_SIZE); /* dst_pitch */ |
| 681 | OUT_RING (chan, PAGE_SIZE); /* line_length */ |
| 682 | OUT_RING (chan, line_count); |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 683 | BEGIN_NVC0(chan, NvSubCopy, 0x0300, 1); |
Ben Skeggs | 183720b | 2010-12-09 15:17:10 +1000 | [diff] [blame] | 684 | OUT_RING (chan, 0x00100110); |
| 685 | |
| 686 | page_count -= line_count; |
| 687 | src_offset += (PAGE_SIZE * line_count); |
| 688 | dst_offset += (PAGE_SIZE * line_count); |
| 689 | } |
| 690 | |
| 691 | return 0; |
| 692 | } |
| 693 | |
| 694 | static int |
Ben Skeggs | fdf5324 | 2012-05-04 15:15:12 +1000 | [diff] [blame] | 695 | nva3_bo_move_copy(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
| 696 | struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem) |
| 697 | { |
| 698 | struct nouveau_mem *node = old_mem->mm_node; |
| 699 | u64 src_offset = node->vma[0].offset; |
| 700 | u64 dst_offset = node->vma[1].offset; |
| 701 | u32 page_count = new_mem->num_pages; |
| 702 | int ret; |
| 703 | |
| 704 | page_count = new_mem->num_pages; |
| 705 | while (page_count) { |
| 706 | int line_count = (page_count > 8191) ? 8191 : page_count; |
| 707 | |
| 708 | ret = RING_SPACE(chan, 11); |
| 709 | if (ret) |
| 710 | return ret; |
| 711 | |
| 712 | BEGIN_NV04(chan, NvSubCopy, 0x030c, 8); |
| 713 | OUT_RING (chan, upper_32_bits(src_offset)); |
| 714 | OUT_RING (chan, lower_32_bits(src_offset)); |
| 715 | OUT_RING (chan, upper_32_bits(dst_offset)); |
| 716 | OUT_RING (chan, lower_32_bits(dst_offset)); |
| 717 | OUT_RING (chan, PAGE_SIZE); |
| 718 | OUT_RING (chan, PAGE_SIZE); |
| 719 | OUT_RING (chan, PAGE_SIZE); |
| 720 | OUT_RING (chan, line_count); |
| 721 | BEGIN_NV04(chan, NvSubCopy, 0x0300, 1); |
| 722 | OUT_RING (chan, 0x00000110); |
| 723 | |
| 724 | page_count -= line_count; |
| 725 | src_offset += (PAGE_SIZE * line_count); |
| 726 | dst_offset += (PAGE_SIZE * line_count); |
| 727 | } |
| 728 | |
| 729 | return 0; |
| 730 | } |
| 731 | |
| 732 | static int |
Ben Skeggs | 5490e5d | 2012-05-04 14:34:16 +1000 | [diff] [blame] | 733 | nv98_bo_move_exec(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
| 734 | struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem) |
| 735 | { |
| 736 | struct nouveau_mem *node = old_mem->mm_node; |
| 737 | int ret = RING_SPACE(chan, 7); |
| 738 | if (ret == 0) { |
| 739 | BEGIN_NV04(chan, NvSubCopy, 0x0320, 6); |
| 740 | OUT_RING (chan, upper_32_bits(node->vma[0].offset)); |
| 741 | OUT_RING (chan, lower_32_bits(node->vma[0].offset)); |
| 742 | OUT_RING (chan, upper_32_bits(node->vma[1].offset)); |
| 743 | OUT_RING (chan, lower_32_bits(node->vma[1].offset)); |
| 744 | OUT_RING (chan, 0x00000000 /* COPY */); |
| 745 | OUT_RING (chan, new_mem->num_pages << PAGE_SHIFT); |
| 746 | } |
| 747 | return ret; |
| 748 | } |
| 749 | |
| 750 | static int |
Ben Skeggs | 4c193d2 | 2012-05-04 14:21:15 +1000 | [diff] [blame] | 751 | nv84_bo_move_exec(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
| 752 | struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem) |
| 753 | { |
| 754 | struct nouveau_mem *node = old_mem->mm_node; |
| 755 | int ret = RING_SPACE(chan, 7); |
| 756 | if (ret == 0) { |
| 757 | BEGIN_NV04(chan, NvSubCopy, 0x0304, 6); |
| 758 | OUT_RING (chan, new_mem->num_pages << PAGE_SHIFT); |
| 759 | OUT_RING (chan, upper_32_bits(node->vma[0].offset)); |
| 760 | OUT_RING (chan, lower_32_bits(node->vma[0].offset)); |
| 761 | OUT_RING (chan, upper_32_bits(node->vma[1].offset)); |
| 762 | OUT_RING (chan, lower_32_bits(node->vma[1].offset)); |
| 763 | OUT_RING (chan, 0x00000000 /* MODE_COPY, QUERY_NONE */); |
| 764 | } |
| 765 | return ret; |
| 766 | } |
| 767 | |
| 768 | static int |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 769 | nv50_bo_move_init(struct nouveau_channel *chan, u32 handle) |
| 770 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 771 | int ret = RING_SPACE(chan, 6); |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 772 | if (ret == 0) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 773 | BEGIN_NV04(chan, NvSubCopy, 0x0000, 1); |
| 774 | OUT_RING (chan, handle); |
| 775 | BEGIN_NV04(chan, NvSubCopy, 0x0180, 3); |
Ben Skeggs | f45f55c | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 776 | OUT_RING (chan, chan->drm->ntfy.handle); |
| 777 | OUT_RING (chan, chan->vram.handle); |
| 778 | OUT_RING (chan, chan->vram.handle); |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 779 | } |
| 780 | |
| 781 | return ret; |
| 782 | } |
| 783 | |
| 784 | static int |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 785 | nv50_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
| 786 | struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 787 | { |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 788 | struct nouveau_mem *node = old_mem->mm_node; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 789 | u64 length = (new_mem->num_pages << PAGE_SHIFT); |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 790 | u64 src_offset = node->vma[0].offset; |
| 791 | u64 dst_offset = node->vma[1].offset; |
Maarten Lankhorst | ce8f769 | 2013-11-12 13:34:08 +0100 | [diff] [blame] | 792 | int src_tiled = !!node->memtype; |
| 793 | int dst_tiled = !!((struct nouveau_mem *)new_mem->mm_node)->memtype; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 794 | int ret; |
| 795 | |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 796 | while (length) { |
| 797 | u32 amount, stride, height; |
| 798 | |
Maarten Lankhorst | ce8f769 | 2013-11-12 13:34:08 +0100 | [diff] [blame] | 799 | ret = RING_SPACE(chan, 18 + 6 * (src_tiled + dst_tiled)); |
| 800 | if (ret) |
| 801 | return ret; |
| 802 | |
Ben Skeggs | 5220b3c | 2010-09-23 15:21:17 +1000 | [diff] [blame] | 803 | amount = min(length, (u64)(4 * 1024 * 1024)); |
| 804 | stride = 16 * 4; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 805 | height = amount / stride; |
| 806 | |
Maarten Lankhorst | ce8f769 | 2013-11-12 13:34:08 +0100 | [diff] [blame] | 807 | if (src_tiled) { |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 808 | BEGIN_NV04(chan, NvSubCopy, 0x0200, 7); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 809 | OUT_RING (chan, 0); |
Ben Skeggs | 5220b3c | 2010-09-23 15:21:17 +1000 | [diff] [blame] | 810 | OUT_RING (chan, 0); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 811 | OUT_RING (chan, stride); |
| 812 | OUT_RING (chan, height); |
| 813 | OUT_RING (chan, 1); |
| 814 | OUT_RING (chan, 0); |
| 815 | OUT_RING (chan, 0); |
| 816 | } else { |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 817 | BEGIN_NV04(chan, NvSubCopy, 0x0200, 1); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 818 | OUT_RING (chan, 1); |
| 819 | } |
Maarten Lankhorst | ce8f769 | 2013-11-12 13:34:08 +0100 | [diff] [blame] | 820 | if (dst_tiled) { |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 821 | BEGIN_NV04(chan, NvSubCopy, 0x021c, 7); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 822 | OUT_RING (chan, 0); |
Ben Skeggs | 5220b3c | 2010-09-23 15:21:17 +1000 | [diff] [blame] | 823 | OUT_RING (chan, 0); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 824 | OUT_RING (chan, stride); |
| 825 | OUT_RING (chan, height); |
| 826 | OUT_RING (chan, 1); |
| 827 | OUT_RING (chan, 0); |
| 828 | OUT_RING (chan, 0); |
| 829 | } else { |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 830 | BEGIN_NV04(chan, NvSubCopy, 0x021c, 1); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 831 | OUT_RING (chan, 1); |
| 832 | } |
| 833 | |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 834 | BEGIN_NV04(chan, NvSubCopy, 0x0238, 2); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 835 | OUT_RING (chan, upper_32_bits(src_offset)); |
| 836 | OUT_RING (chan, upper_32_bits(dst_offset)); |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 837 | BEGIN_NV04(chan, NvSubCopy, 0x030c, 8); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 838 | OUT_RING (chan, lower_32_bits(src_offset)); |
| 839 | OUT_RING (chan, lower_32_bits(dst_offset)); |
| 840 | OUT_RING (chan, stride); |
| 841 | OUT_RING (chan, stride); |
| 842 | OUT_RING (chan, stride); |
| 843 | OUT_RING (chan, height); |
| 844 | OUT_RING (chan, 0x00000101); |
| 845 | OUT_RING (chan, 0x00000000); |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 846 | BEGIN_NV04(chan, NvSubCopy, NV_MEMORY_TO_MEMORY_FORMAT_NOP, 1); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 847 | OUT_RING (chan, 0); |
| 848 | |
| 849 | length -= amount; |
| 850 | src_offset += amount; |
| 851 | dst_offset += amount; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 852 | } |
| 853 | |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 854 | return 0; |
| 855 | } |
| 856 | |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 857 | static int |
| 858 | nv04_bo_move_init(struct nouveau_channel *chan, u32 handle) |
| 859 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 860 | int ret = RING_SPACE(chan, 4); |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 861 | if (ret == 0) { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 862 | BEGIN_NV04(chan, NvSubCopy, 0x0000, 1); |
| 863 | OUT_RING (chan, handle); |
| 864 | BEGIN_NV04(chan, NvSubCopy, 0x0180, 1); |
Ben Skeggs | f45f55c | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 865 | OUT_RING (chan, chan->drm->ntfy.handle); |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 866 | } |
| 867 | |
| 868 | return ret; |
| 869 | } |
| 870 | |
Ben Skeggs | a670478 | 2011-02-16 09:10:20 +1000 | [diff] [blame] | 871 | static inline uint32_t |
| 872 | nouveau_bo_mem_ctxdma(struct ttm_buffer_object *bo, |
| 873 | struct nouveau_channel *chan, struct ttm_mem_reg *mem) |
| 874 | { |
| 875 | if (mem->mem_type == TTM_PL_TT) |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 876 | return NvDmaTT; |
Ben Skeggs | f45f55c | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 877 | return chan->vram.handle; |
Ben Skeggs | a670478 | 2011-02-16 09:10:20 +1000 | [diff] [blame] | 878 | } |
| 879 | |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 880 | static int |
| 881 | nv04_bo_move_m2mf(struct nouveau_channel *chan, struct ttm_buffer_object *bo, |
| 882 | struct ttm_mem_reg *old_mem, struct ttm_mem_reg *new_mem) |
| 883 | { |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 884 | u32 src_offset = old_mem->start << PAGE_SHIFT; |
| 885 | u32 dst_offset = new_mem->start << PAGE_SHIFT; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 886 | u32 page_count = new_mem->num_pages; |
| 887 | int ret; |
| 888 | |
| 889 | ret = RING_SPACE(chan, 3); |
| 890 | if (ret) |
| 891 | return ret; |
| 892 | |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 893 | BEGIN_NV04(chan, NvSubCopy, NV_MEMORY_TO_MEMORY_FORMAT_DMA_SOURCE, 2); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 894 | OUT_RING (chan, nouveau_bo_mem_ctxdma(bo, chan, old_mem)); |
| 895 | OUT_RING (chan, nouveau_bo_mem_ctxdma(bo, chan, new_mem)); |
| 896 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 897 | page_count = new_mem->num_pages; |
| 898 | while (page_count) { |
| 899 | int line_count = (page_count > 2047) ? 2047 : page_count; |
| 900 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 901 | ret = RING_SPACE(chan, 11); |
| 902 | if (ret) |
| 903 | return ret; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 904 | |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 905 | BEGIN_NV04(chan, NvSubCopy, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 906 | NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN, 8); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 907 | OUT_RING (chan, src_offset); |
| 908 | OUT_RING (chan, dst_offset); |
| 909 | OUT_RING (chan, PAGE_SIZE); /* src_pitch */ |
| 910 | OUT_RING (chan, PAGE_SIZE); /* dst_pitch */ |
| 911 | OUT_RING (chan, PAGE_SIZE); /* line_length */ |
| 912 | OUT_RING (chan, line_count); |
| 913 | OUT_RING (chan, 0x00000101); |
| 914 | OUT_RING (chan, 0x00000000); |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 915 | BEGIN_NV04(chan, NvSubCopy, NV_MEMORY_TO_MEMORY_FORMAT_NOP, 1); |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 916 | OUT_RING (chan, 0); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 917 | |
| 918 | page_count -= line_count; |
| 919 | src_offset += (PAGE_SIZE * line_count); |
| 920 | dst_offset += (PAGE_SIZE * line_count); |
| 921 | } |
| 922 | |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 923 | return 0; |
| 924 | } |
| 925 | |
| 926 | static int |
Ben Skeggs | 3c57d85 | 2013-11-22 10:35:25 +1000 | [diff] [blame] | 927 | nouveau_bo_move_prep(struct nouveau_drm *drm, struct ttm_buffer_object *bo, |
| 928 | struct ttm_mem_reg *mem) |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 929 | { |
Ben Skeggs | 3c57d85 | 2013-11-22 10:35:25 +1000 | [diff] [blame] | 930 | struct nouveau_mem *old_node = bo->mem.mm_node; |
| 931 | struct nouveau_mem *new_node = mem->mm_node; |
| 932 | u64 size = (u64)mem->num_pages << PAGE_SHIFT; |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 933 | int ret; |
| 934 | |
Ben Skeggs | 3ee6f5b | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 935 | ret = nouveau_vm_get(drm->client.vm, size, old_node->page_shift, |
Ben Skeggs | 3c57d85 | 2013-11-22 10:35:25 +1000 | [diff] [blame] | 936 | NV_MEM_ACCESS_RW, &old_node->vma[0]); |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 937 | if (ret) |
| 938 | return ret; |
| 939 | |
Ben Skeggs | 3ee6f5b | 2014-08-10 04:10:20 +1000 | [diff] [blame] | 940 | ret = nouveau_vm_get(drm->client.vm, size, new_node->page_shift, |
Ben Skeggs | 3c57d85 | 2013-11-22 10:35:25 +1000 | [diff] [blame] | 941 | NV_MEM_ACCESS_RW, &old_node->vma[1]); |
| 942 | if (ret) { |
| 943 | nouveau_vm_put(&old_node->vma[0]); |
| 944 | return ret; |
| 945 | } |
| 946 | |
| 947 | nouveau_vm_map(&old_node->vma[0], old_node); |
| 948 | nouveau_vm_map(&old_node->vma[1], new_node); |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 949 | return 0; |
| 950 | } |
| 951 | |
| 952 | static int |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 953 | nouveau_bo_move_m2mf(struct ttm_buffer_object *bo, int evict, bool intr, |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 954 | bool no_wait_gpu, struct ttm_mem_reg *new_mem) |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 955 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 956 | struct nouveau_drm *drm = nouveau_bdev(bo->bdev); |
Dave Jones | 1934a2a | 2013-09-17 17:26:34 -0400 | [diff] [blame] | 957 | struct nouveau_channel *chan = drm->ttm.chan; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 958 | struct nouveau_cli *cli = (void *)nvif_client(&chan->device->base); |
Ben Skeggs | 35b8141 | 2013-11-22 10:39:57 +1000 | [diff] [blame] | 959 | struct nouveau_fence *fence; |
Ben Skeggs | f1ab0cc | 2010-08-26 11:32:01 +1000 | [diff] [blame] | 960 | int ret; |
| 961 | |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 962 | /* create temporary vmas for the transfer and attach them to the |
| 963 | * old nouveau_mem node, these will get cleaned up after ttm has |
| 964 | * destroyed the ttm_mem_reg |
Ben Skeggs | 3425df4 | 2011-02-10 11:22:12 +1000 | [diff] [blame] | 965 | */ |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 966 | if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) { |
Ben Skeggs | 3c57d85 | 2013-11-22 10:35:25 +1000 | [diff] [blame] | 967 | ret = nouveau_bo_move_prep(drm, bo, new_mem); |
Ben Skeggs | d2f96666 | 2011-06-06 20:54:42 +1000 | [diff] [blame] | 968 | if (ret) |
Ben Skeggs | 3c57d85 | 2013-11-22 10:35:25 +1000 | [diff] [blame] | 969 | return ret; |
Ben Skeggs | 3425df4 | 2011-02-10 11:22:12 +1000 | [diff] [blame] | 970 | } |
| 971 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 972 | mutex_lock_nested(&cli->mutex, SINGLE_DEPTH_NESTING); |
Maarten Lankhorst | e3be4c2 | 2014-09-16 11:15:07 +0200 | [diff] [blame^] | 973 | ret = nouveau_fence_sync(nouveau_bo(bo), chan, true, intr); |
Ben Skeggs | 6a6b73f | 2010-10-05 16:53:48 +1000 | [diff] [blame] | 974 | if (ret == 0) { |
Ben Skeggs | 35b8141 | 2013-11-22 10:39:57 +1000 | [diff] [blame] | 975 | ret = drm->ttm.move(chan, bo, &bo->mem, new_mem); |
| 976 | if (ret == 0) { |
| 977 | ret = nouveau_fence_new(chan, false, &fence); |
| 978 | if (ret == 0) { |
Maarten Lankhorst | f2c24b8 | 2014-04-02 17:14:48 +0200 | [diff] [blame] | 979 | ret = ttm_bo_move_accel_cleanup(bo, |
| 980 | &fence->base, |
Ben Skeggs | 35b8141 | 2013-11-22 10:39:57 +1000 | [diff] [blame] | 981 | evict, |
| 982 | no_wait_gpu, |
| 983 | new_mem); |
| 984 | nouveau_fence_unref(&fence); |
| 985 | } |
| 986 | } |
Ben Skeggs | 6a6b73f | 2010-10-05 16:53:48 +1000 | [diff] [blame] | 987 | } |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 988 | mutex_unlock(&cli->mutex); |
Ben Skeggs | 6a6b73f | 2010-10-05 16:53:48 +1000 | [diff] [blame] | 989 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 990 | } |
| 991 | |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 992 | void |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 993 | nouveau_bo_move_init(struct nouveau_drm *drm) |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 994 | { |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 995 | static const struct { |
| 996 | const char *name; |
Ben Skeggs | 1a46098 | 2012-05-04 15:17:28 +1000 | [diff] [blame] | 997 | int engine; |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 998 | u32 oclass; |
| 999 | int (*exec)(struct nouveau_channel *, |
| 1000 | struct ttm_buffer_object *, |
| 1001 | struct ttm_mem_reg *, struct ttm_mem_reg *); |
| 1002 | int (*init)(struct nouveau_channel *, u32 handle); |
| 1003 | } _methods[] = { |
Ben Skeggs | 00fc6f6 | 2013-07-09 14:20:15 +1000 | [diff] [blame] | 1004 | { "COPY", 4, 0xa0b5, nve0_bo_move_copy, nve0_bo_move_init }, |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 1005 | { "GRCE", 0, 0xa0b5, nve0_bo_move_copy, nvc0_bo_move_init }, |
Ben Skeggs | 1a46098 | 2012-05-04 15:17:28 +1000 | [diff] [blame] | 1006 | { "COPY1", 5, 0x90b8, nvc0_bo_move_copy, nvc0_bo_move_init }, |
| 1007 | { "COPY0", 4, 0x90b5, nvc0_bo_move_copy, nvc0_bo_move_init }, |
| 1008 | { "COPY", 0, 0x85b5, nva3_bo_move_copy, nv50_bo_move_init }, |
| 1009 | { "CRYPT", 0, 0x74c1, nv84_bo_move_exec, nv50_bo_move_init }, |
| 1010 | { "M2MF", 0, 0x9039, nvc0_bo_move_m2mf, nvc0_bo_move_init }, |
| 1011 | { "M2MF", 0, 0x5039, nv50_bo_move_m2mf, nv50_bo_move_init }, |
| 1012 | { "M2MF", 0, 0x0039, nv04_bo_move_m2mf, nv04_bo_move_init }, |
Ben Skeggs | 5490e5d | 2012-05-04 14:34:16 +1000 | [diff] [blame] | 1013 | {}, |
Ben Skeggs | 1a46098 | 2012-05-04 15:17:28 +1000 | [diff] [blame] | 1014 | { "CRYPT", 0, 0x88b4, nv98_bo_move_exec, nv50_bo_move_init }, |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 1015 | }, *mthd = _methods; |
| 1016 | const char *name = "CPU"; |
| 1017 | int ret; |
| 1018 | |
| 1019 | do { |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 1020 | struct nouveau_channel *chan; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1021 | |
Ben Skeggs | 00fc6f6 | 2013-07-09 14:20:15 +1000 | [diff] [blame] | 1022 | if (mthd->engine) |
Ben Skeggs | 4998104 | 2012-08-06 19:38:25 +1000 | [diff] [blame] | 1023 | chan = drm->cechan; |
| 1024 | else |
| 1025 | chan = drm->channel; |
| 1026 | if (chan == NULL) |
| 1027 | continue; |
| 1028 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1029 | ret = nvif_object_init(chan->object, NULL, |
| 1030 | mthd->oclass | (mthd->engine << 16), |
| 1031 | mthd->oclass, NULL, 0, |
| 1032 | &drm->ttm.copy); |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 1033 | if (ret == 0) { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1034 | ret = mthd->init(chan, drm->ttm.copy.handle); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1035 | if (ret) { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1036 | nvif_object_fini(&drm->ttm.copy); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1037 | continue; |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 1038 | } |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1039 | |
| 1040 | drm->ttm.move = mthd->exec; |
Ben Skeggs | 1bb3f6a | 2013-07-08 10:40:35 +1000 | [diff] [blame] | 1041 | drm->ttm.chan = chan; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1042 | name = mthd->name; |
| 1043 | break; |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 1044 | } |
| 1045 | } while ((++mthd)->exec); |
| 1046 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1047 | NV_INFO(drm, "MM: using %s for buffer copies\n", name); |
Ben Skeggs | d1b167e | 2012-05-04 14:01:52 +1000 | [diff] [blame] | 1048 | } |
| 1049 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1050 | static int |
| 1051 | nouveau_bo_move_flipd(struct ttm_buffer_object *bo, bool evict, bool intr, |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 1052 | bool no_wait_gpu, struct ttm_mem_reg *new_mem) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1053 | { |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 1054 | struct ttm_place placement_memtype = { |
| 1055 | .fpfn = 0, |
| 1056 | .lpfn = 0, |
| 1057 | .flags = TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING |
| 1058 | }; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1059 | struct ttm_placement placement; |
| 1060 | struct ttm_mem_reg tmp_mem; |
| 1061 | int ret; |
| 1062 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1063 | placement.num_placement = placement.num_busy_placement = 1; |
Francisco Jerez | 77e2b5e | 2009-12-16 19:05:00 +0100 | [diff] [blame] | 1064 | placement.placement = placement.busy_placement = &placement_memtype; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1065 | |
| 1066 | tmp_mem = *new_mem; |
| 1067 | tmp_mem.mm_node = NULL; |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 1068 | ret = ttm_bo_mem_space(bo, &placement, &tmp_mem, intr, no_wait_gpu); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1069 | if (ret) |
| 1070 | return ret; |
| 1071 | |
| 1072 | ret = ttm_tt_bind(bo->ttm, &tmp_mem); |
| 1073 | if (ret) |
| 1074 | goto out; |
| 1075 | |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 1076 | ret = nouveau_bo_move_m2mf(bo, true, intr, no_wait_gpu, &tmp_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1077 | if (ret) |
| 1078 | goto out; |
| 1079 | |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 1080 | ret = ttm_bo_move_ttm(bo, true, no_wait_gpu, new_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1081 | out: |
Ben Skeggs | 42311ff | 2010-08-04 12:07:08 +1000 | [diff] [blame] | 1082 | ttm_bo_mem_put(bo, &tmp_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1083 | return ret; |
| 1084 | } |
| 1085 | |
| 1086 | static int |
| 1087 | nouveau_bo_move_flips(struct ttm_buffer_object *bo, bool evict, bool intr, |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 1088 | bool no_wait_gpu, struct ttm_mem_reg *new_mem) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1089 | { |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 1090 | struct ttm_place placement_memtype = { |
| 1091 | .fpfn = 0, |
| 1092 | .lpfn = 0, |
| 1093 | .flags = TTM_PL_FLAG_TT | TTM_PL_MASK_CACHING |
| 1094 | }; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1095 | struct ttm_placement placement; |
| 1096 | struct ttm_mem_reg tmp_mem; |
| 1097 | int ret; |
| 1098 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1099 | placement.num_placement = placement.num_busy_placement = 1; |
Francisco Jerez | 77e2b5e | 2009-12-16 19:05:00 +0100 | [diff] [blame] | 1100 | placement.placement = placement.busy_placement = &placement_memtype; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1101 | |
| 1102 | tmp_mem = *new_mem; |
| 1103 | tmp_mem.mm_node = NULL; |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 1104 | ret = ttm_bo_mem_space(bo, &placement, &tmp_mem, intr, no_wait_gpu); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1105 | if (ret) |
| 1106 | return ret; |
| 1107 | |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 1108 | ret = ttm_bo_move_ttm(bo, true, no_wait_gpu, &tmp_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1109 | if (ret) |
| 1110 | goto out; |
| 1111 | |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 1112 | ret = nouveau_bo_move_m2mf(bo, true, intr, no_wait_gpu, new_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1113 | if (ret) |
| 1114 | goto out; |
| 1115 | |
| 1116 | out: |
Ben Skeggs | 42311ff | 2010-08-04 12:07:08 +1000 | [diff] [blame] | 1117 | ttm_bo_mem_put(bo, &tmp_mem); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1118 | return ret; |
| 1119 | } |
| 1120 | |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 1121 | static void |
| 1122 | nouveau_bo_move_ntfy(struct ttm_buffer_object *bo, struct ttm_mem_reg *new_mem) |
| 1123 | { |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 1124 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 1125 | struct nouveau_vma *vma; |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 1126 | |
Ben Skeggs | 9f1feed | 2012-01-25 15:34:22 +1000 | [diff] [blame] | 1127 | /* ttm can now (stupidly) pass the driver bos it didn't create... */ |
| 1128 | if (bo->destroy != nouveau_bo_del_ttm) |
| 1129 | return; |
| 1130 | |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 1131 | list_for_each_entry(vma, &nvbo->vma_list, head) { |
Ben Skeggs | 2e2cfbe | 2013-11-15 11:56:49 +1000 | [diff] [blame] | 1132 | if (new_mem && new_mem->mem_type != TTM_PL_SYSTEM && |
| 1133 | (new_mem->mem_type == TTM_PL_VRAM || |
| 1134 | nvbo->page_shift != vma->vm->vmm->lpg_shift)) { |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 1135 | nouveau_vm_map(vma, new_mem->mm_node); |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 1136 | } else { |
| 1137 | nouveau_vm_unmap(vma); |
| 1138 | } |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 1139 | } |
| 1140 | } |
| 1141 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1142 | static int |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1143 | nouveau_bo_vm_bind(struct ttm_buffer_object *bo, struct ttm_mem_reg *new_mem, |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1144 | struct nouveau_drm_tile **new_tile) |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1145 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1146 | struct nouveau_drm *drm = nouveau_bdev(bo->bdev); |
| 1147 | struct drm_device *dev = drm->dev; |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1148 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 1149 | u64 offset = new_mem->start << PAGE_SHIFT; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1150 | |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 1151 | *new_tile = NULL; |
| 1152 | if (new_mem->mem_type != TTM_PL_VRAM) |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1153 | return 0; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1154 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1155 | if (drm->device.info.family >= NV_DEVICE_INFO_V0_CELSIUS) { |
Ben Skeggs | bc9e7b9 | 2012-07-19 17:54:21 +1000 | [diff] [blame] | 1156 | *new_tile = nv10_bo_set_tiling(dev, offset, new_mem->size, |
Francisco Jerez | a5cf68b | 2010-10-24 16:14:41 +0200 | [diff] [blame] | 1157 | nvbo->tile_mode, |
| 1158 | nvbo->tile_flags); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1159 | } |
| 1160 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1161 | return 0; |
| 1162 | } |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1163 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1164 | static void |
| 1165 | nouveau_bo_vm_cleanup(struct ttm_buffer_object *bo, |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1166 | struct nouveau_drm_tile *new_tile, |
| 1167 | struct nouveau_drm_tile **old_tile) |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1168 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1169 | struct nouveau_drm *drm = nouveau_bdev(bo->bdev); |
| 1170 | struct drm_device *dev = drm->dev; |
Maarten Lankhorst | f2c24b8 | 2014-04-02 17:14:48 +0200 | [diff] [blame] | 1171 | struct fence *fence = reservation_object_get_excl(bo->resv); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1172 | |
Maarten Lankhorst | f2c24b8 | 2014-04-02 17:14:48 +0200 | [diff] [blame] | 1173 | nv10_bo_put_tile_region(dev, *old_tile, fence); |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 1174 | *old_tile = new_tile; |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1175 | } |
| 1176 | |
| 1177 | static int |
| 1178 | nouveau_bo_move(struct ttm_buffer_object *bo, bool evict, bool intr, |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 1179 | bool no_wait_gpu, struct ttm_mem_reg *new_mem) |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1180 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1181 | struct nouveau_drm *drm = nouveau_bdev(bo->bdev); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1182 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 1183 | struct ttm_mem_reg *old_mem = &bo->mem; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1184 | struct nouveau_drm_tile *new_tile = NULL; |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1185 | int ret = 0; |
| 1186 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1187 | if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA) { |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 1188 | ret = nouveau_bo_vm_bind(bo, new_mem, &new_tile); |
| 1189 | if (ret) |
| 1190 | return ret; |
| 1191 | } |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1192 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1193 | /* Fake bo copy. */ |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1194 | if (old_mem->mem_type == TTM_PL_SYSTEM && !bo->ttm) { |
| 1195 | BUG_ON(bo->mem.mm_node != NULL); |
| 1196 | bo->mem = *new_mem; |
| 1197 | new_mem->mm_node = NULL; |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1198 | goto out; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1199 | } |
| 1200 | |
Ben Skeggs | cef9e99 | 2013-11-22 10:52:54 +1000 | [diff] [blame] | 1201 | /* Hardware assisted copy. */ |
| 1202 | if (drm->ttm.move) { |
| 1203 | if (new_mem->mem_type == TTM_PL_SYSTEM) |
| 1204 | ret = nouveau_bo_move_flipd(bo, evict, intr, |
| 1205 | no_wait_gpu, new_mem); |
| 1206 | else if (old_mem->mem_type == TTM_PL_SYSTEM) |
| 1207 | ret = nouveau_bo_move_flips(bo, evict, intr, |
| 1208 | no_wait_gpu, new_mem); |
| 1209 | else |
| 1210 | ret = nouveau_bo_move_m2mf(bo, evict, intr, |
| 1211 | no_wait_gpu, new_mem); |
| 1212 | if (!ret) |
| 1213 | goto out; |
Ben Skeggs | b8a6a80 | 2010-08-27 11:55:43 +1000 | [diff] [blame] | 1214 | } |
| 1215 | |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1216 | /* Fallback to software copy. */ |
Ben Skeggs | cef9e99 | 2013-11-22 10:52:54 +1000 | [diff] [blame] | 1217 | ret = ttm_bo_wait(bo, true, intr, no_wait_gpu); |
Ben Skeggs | cef9e99 | 2013-11-22 10:52:54 +1000 | [diff] [blame] | 1218 | if (ret == 0) |
| 1219 | ret = ttm_bo_move_memcpy(bo, evict, no_wait_gpu, new_mem); |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1220 | |
| 1221 | out: |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1222 | if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA) { |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 1223 | if (ret) |
| 1224 | nouveau_bo_vm_cleanup(bo, NULL, &new_tile); |
| 1225 | else |
| 1226 | nouveau_bo_vm_cleanup(bo, new_tile, &nvbo->tile); |
| 1227 | } |
Francisco Jerez | a0af9ad | 2009-12-11 16:51:09 +0100 | [diff] [blame] | 1228 | |
| 1229 | return ret; |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1230 | } |
| 1231 | |
| 1232 | static int |
| 1233 | nouveau_bo_verify_access(struct ttm_buffer_object *bo, struct file *filp) |
| 1234 | { |
David Herrmann | acb4652 | 2013-08-25 18:28:59 +0200 | [diff] [blame] | 1235 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
| 1236 | |
David Herrmann | 55fb74a | 2013-10-02 10:15:17 +0200 | [diff] [blame] | 1237 | return drm_vma_node_verify_access(&nvbo->gem.vma_node, filp); |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1238 | } |
| 1239 | |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 1240 | static int |
| 1241 | nouveau_ttm_io_mem_reserve(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem) |
| 1242 | { |
| 1243 | struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type]; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1244 | struct nouveau_drm *drm = nouveau_bdev(bdev); |
Maarten Lankhorst | a554090 | 2013-11-12 13:34:09 +0100 | [diff] [blame] | 1245 | struct nouveau_mem *node = mem->mm_node; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 1246 | int ret; |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 1247 | |
| 1248 | mem->bus.addr = NULL; |
| 1249 | mem->bus.offset = 0; |
| 1250 | mem->bus.size = mem->num_pages << PAGE_SHIFT; |
| 1251 | mem->bus.base = 0; |
| 1252 | mem->bus.is_iomem = false; |
| 1253 | if (!(man->flags & TTM_MEMTYPE_FLAG_MAPPABLE)) |
| 1254 | return -EINVAL; |
| 1255 | switch (mem->mem_type) { |
| 1256 | case TTM_PL_SYSTEM: |
| 1257 | /* System memory */ |
| 1258 | return 0; |
| 1259 | case TTM_PL_TT: |
| 1260 | #if __OS_HAS_AGP |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1261 | if (drm->agp.stat == ENABLED) { |
Ben Skeggs | d961db7 | 2010-08-05 10:48:18 +1000 | [diff] [blame] | 1262 | mem->bus.offset = mem->start << PAGE_SHIFT; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1263 | mem->bus.base = drm->agp.base; |
Ben Skeggs | 5c13cac | 2014-08-10 12:39:09 +1000 | [diff] [blame] | 1264 | mem->bus.is_iomem = !drm->dev->agp->cant_use_aperture; |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 1265 | } |
| 1266 | #endif |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1267 | if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA || !node->memtype) |
Maarten Lankhorst | a554090 | 2013-11-12 13:34:09 +0100 | [diff] [blame] | 1268 | /* untiled */ |
| 1269 | break; |
| 1270 | /* fallthrough, tiled memory */ |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 1271 | case TTM_PL_VRAM: |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame] | 1272 | mem->bus.offset = mem->start << PAGE_SHIFT; |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1273 | mem->bus.base = nv_device_resource_start(nvkm_device(&drm->device), 1); |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 1274 | mem->bus.is_iomem = true; |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1275 | if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA) { |
| 1276 | struct nouveau_bar *bar = nvkm_bar(&drm->device); |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame] | 1277 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1278 | ret = bar->umap(bar, node, NV_MEM_ACCESS_RW, |
Ben Skeggs | 3863c9b | 2012-07-14 19:09:17 +1000 | [diff] [blame] | 1279 | &node->bar_vma); |
| 1280 | if (ret) |
| 1281 | return ret; |
| 1282 | |
| 1283 | mem->bus.offset = node->bar_vma.offset; |
| 1284 | } |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 1285 | break; |
| 1286 | default: |
| 1287 | return -EINVAL; |
| 1288 | } |
| 1289 | return 0; |
| 1290 | } |
| 1291 | |
| 1292 | static void |
| 1293 | nouveau_ttm_io_mem_free(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem) |
| 1294 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1295 | struct nouveau_drm *drm = nouveau_bdev(bdev); |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1296 | struct nouveau_bar *bar = nvkm_bar(&drm->device); |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 1297 | struct nouveau_mem *node = mem->mm_node; |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 1298 | |
Ben Skeggs | d5f4239 | 2011-02-10 12:22:52 +1000 | [diff] [blame] | 1299 | if (!node->bar_vma.node) |
Ben Skeggs | f869ef8 | 2010-11-15 11:53:16 +1000 | [diff] [blame] | 1300 | return; |
| 1301 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1302 | bar->unmap(bar, &node->bar_vma); |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 1303 | } |
| 1304 | |
| 1305 | static int |
| 1306 | nouveau_ttm_fault_reserve_notify(struct ttm_buffer_object *bo) |
| 1307 | { |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1308 | struct nouveau_drm *drm = nouveau_bdev(bo->bdev); |
Ben Skeggs | e1429b4 | 2010-09-10 11:12:25 +1000 | [diff] [blame] | 1309 | struct nouveau_bo *nvbo = nouveau_bo(bo); |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1310 | struct nvif_device *device = &drm->device; |
| 1311 | u32 mappable = nv_device_resource_len(nvkm_device(device), 1) >> PAGE_SHIFT; |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 1312 | int i, ret; |
Ben Skeggs | e1429b4 | 2010-09-10 11:12:25 +1000 | [diff] [blame] | 1313 | |
| 1314 | /* as long as the bo isn't in vram, and isn't tiled, we've got |
| 1315 | * nothing to do here. |
| 1316 | */ |
| 1317 | if (bo->mem.mem_type != TTM_PL_VRAM) { |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1318 | if (drm->device.info.family < NV_DEVICE_INFO_V0_TESLA || |
Francisco Jerez | f13b326 | 2010-10-10 06:01:08 +0200 | [diff] [blame] | 1319 | !nouveau_bo_tile_layout(nvbo)) |
Ben Skeggs | e1429b4 | 2010-09-10 11:12:25 +1000 | [diff] [blame] | 1320 | return 0; |
Maarten Lankhorst | a554090 | 2013-11-12 13:34:09 +0100 | [diff] [blame] | 1321 | |
| 1322 | if (bo->mem.mem_type == TTM_PL_SYSTEM) { |
| 1323 | nouveau_bo_placement_set(nvbo, TTM_PL_TT, 0); |
| 1324 | |
| 1325 | ret = nouveau_bo_validate(nvbo, false, false); |
| 1326 | if (ret) |
| 1327 | return ret; |
| 1328 | } |
| 1329 | return 0; |
Ben Skeggs | e1429b4 | 2010-09-10 11:12:25 +1000 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | /* make sure bo is in mappable vram */ |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1333 | if (drm->device.info.family >= NV_DEVICE_INFO_V0_TESLA || |
Maarten Lankhorst | a554090 | 2013-11-12 13:34:09 +0100 | [diff] [blame] | 1334 | bo->mem.start + bo->mem.num_pages < mappable) |
Ben Skeggs | e1429b4 | 2010-09-10 11:12:25 +1000 | [diff] [blame] | 1335 | return 0; |
| 1336 | |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 1337 | for (i = 0; i < nvbo->placement.num_placement; ++i) { |
| 1338 | nvbo->placements[i].fpfn = 0; |
| 1339 | nvbo->placements[i].lpfn = mappable; |
| 1340 | } |
Ben Skeggs | e1429b4 | 2010-09-10 11:12:25 +1000 | [diff] [blame] | 1341 | |
Christian König | f1217ed | 2014-08-27 13:16:04 +0200 | [diff] [blame] | 1342 | for (i = 0; i < nvbo->placement.num_busy_placement; ++i) { |
| 1343 | nvbo->busy_placements[i].fpfn = 0; |
| 1344 | nvbo->busy_placements[i].lpfn = mappable; |
| 1345 | } |
| 1346 | |
Dave Airlie | c284815 | 2012-05-18 15:31:12 +0100 | [diff] [blame] | 1347 | nouveau_bo_placement_set(nvbo, TTM_PL_FLAG_VRAM, 0); |
Maarten Lankhorst | 97a875c | 2012-11-28 11:25:44 +0000 | [diff] [blame] | 1348 | return nouveau_bo_validate(nvbo, false, false); |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 1349 | } |
| 1350 | |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1351 | static int |
| 1352 | nouveau_ttm_tt_populate(struct ttm_tt *ttm) |
| 1353 | { |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 1354 | struct ttm_dma_tt *ttm_dma = (void *)ttm; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1355 | struct nouveau_drm *drm; |
Alexandre Courbot | 420b946 | 2014-02-17 15:17:26 +0900 | [diff] [blame] | 1356 | struct nouveau_device *device; |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1357 | struct drm_device *dev; |
Alexandre Courbot | fd1496a | 2014-07-31 18:09:42 +0900 | [diff] [blame] | 1358 | struct device *pdev; |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1359 | unsigned i; |
| 1360 | int r; |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 1361 | bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG); |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1362 | |
| 1363 | if (ttm->state != tt_unpopulated) |
| 1364 | return 0; |
| 1365 | |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 1366 | if (slave && ttm->sg) { |
| 1367 | /* make userspace faulting work */ |
| 1368 | drm_prime_sg_to_page_addr_arrays(ttm->sg, ttm->pages, |
| 1369 | ttm_dma->dma_address, ttm->num_pages); |
| 1370 | ttm->state = tt_unbound; |
| 1371 | return 0; |
| 1372 | } |
| 1373 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1374 | drm = nouveau_bdev(ttm->bdev); |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1375 | device = nvkm_device(&drm->device); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1376 | dev = drm->dev; |
Alexandre Courbot | fd1496a | 2014-07-31 18:09:42 +0900 | [diff] [blame] | 1377 | pdev = nv_device_base(device); |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1378 | |
Jerome Glisse | dea7e0a | 2012-01-03 17:37:37 -0500 | [diff] [blame] | 1379 | #if __OS_HAS_AGP |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1380 | if (drm->agp.stat == ENABLED) { |
Jerome Glisse | dea7e0a | 2012-01-03 17:37:37 -0500 | [diff] [blame] | 1381 | return ttm_agp_tt_populate(ttm); |
| 1382 | } |
| 1383 | #endif |
| 1384 | |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1385 | #ifdef CONFIG_SWIOTLB |
| 1386 | if (swiotlb_nr_tbl()) { |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 1387 | return ttm_dma_populate((void *)ttm, dev->dev); |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1388 | } |
| 1389 | #endif |
| 1390 | |
| 1391 | r = ttm_pool_populate(ttm); |
| 1392 | if (r) { |
| 1393 | return r; |
| 1394 | } |
| 1395 | |
| 1396 | for (i = 0; i < ttm->num_pages; i++) { |
Alexandre Courbot | fd1496a | 2014-07-31 18:09:42 +0900 | [diff] [blame] | 1397 | dma_addr_t addr; |
| 1398 | |
| 1399 | addr = dma_map_page(pdev, ttm->pages[i], 0, PAGE_SIZE, |
| 1400 | DMA_BIDIRECTIONAL); |
| 1401 | |
| 1402 | if (dma_mapping_error(pdev, addr)) { |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1403 | while (--i) { |
Alexandre Courbot | fd1496a | 2014-07-31 18:09:42 +0900 | [diff] [blame] | 1404 | dma_unmap_page(pdev, ttm_dma->dma_address[i], |
| 1405 | PAGE_SIZE, DMA_BIDIRECTIONAL); |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 1406 | ttm_dma->dma_address[i] = 0; |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1407 | } |
| 1408 | ttm_pool_unpopulate(ttm); |
| 1409 | return -EFAULT; |
| 1410 | } |
Alexandre Courbot | fd1496a | 2014-07-31 18:09:42 +0900 | [diff] [blame] | 1411 | |
| 1412 | ttm_dma->dma_address[i] = addr; |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1413 | } |
| 1414 | return 0; |
| 1415 | } |
| 1416 | |
| 1417 | static void |
| 1418 | nouveau_ttm_tt_unpopulate(struct ttm_tt *ttm) |
| 1419 | { |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 1420 | struct ttm_dma_tt *ttm_dma = (void *)ttm; |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1421 | struct nouveau_drm *drm; |
Alexandre Courbot | 420b946 | 2014-02-17 15:17:26 +0900 | [diff] [blame] | 1422 | struct nouveau_device *device; |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1423 | struct drm_device *dev; |
Alexandre Courbot | fd1496a | 2014-07-31 18:09:42 +0900 | [diff] [blame] | 1424 | struct device *pdev; |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1425 | unsigned i; |
Dave Airlie | 22b33e8 | 2012-04-02 11:53:06 +0100 | [diff] [blame] | 1426 | bool slave = !!(ttm->page_flags & TTM_PAGE_FLAG_SG); |
| 1427 | |
| 1428 | if (slave) |
| 1429 | return; |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1430 | |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1431 | drm = nouveau_bdev(ttm->bdev); |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 1432 | device = nvkm_device(&drm->device); |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1433 | dev = drm->dev; |
Alexandre Courbot | fd1496a | 2014-07-31 18:09:42 +0900 | [diff] [blame] | 1434 | pdev = nv_device_base(device); |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1435 | |
Jerome Glisse | dea7e0a | 2012-01-03 17:37:37 -0500 | [diff] [blame] | 1436 | #if __OS_HAS_AGP |
Ben Skeggs | ebb945a | 2012-07-20 08:17:34 +1000 | [diff] [blame] | 1437 | if (drm->agp.stat == ENABLED) { |
Jerome Glisse | dea7e0a | 2012-01-03 17:37:37 -0500 | [diff] [blame] | 1438 | ttm_agp_tt_unpopulate(ttm); |
| 1439 | return; |
| 1440 | } |
| 1441 | #endif |
| 1442 | |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1443 | #ifdef CONFIG_SWIOTLB |
| 1444 | if (swiotlb_nr_tbl()) { |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 1445 | ttm_dma_unpopulate((void *)ttm, dev->dev); |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1446 | return; |
| 1447 | } |
| 1448 | #endif |
| 1449 | |
| 1450 | for (i = 0; i < ttm->num_pages; i++) { |
Jerome Glisse | 8e7e705 | 2011-11-09 17:15:26 -0500 | [diff] [blame] | 1451 | if (ttm_dma->dma_address[i]) { |
Alexandre Courbot | fd1496a | 2014-07-31 18:09:42 +0900 | [diff] [blame] | 1452 | dma_unmap_page(pdev, ttm_dma->dma_address[i], PAGE_SIZE, |
| 1453 | DMA_BIDIRECTIONAL); |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1454 | } |
| 1455 | } |
| 1456 | |
| 1457 | ttm_pool_unpopulate(ttm); |
| 1458 | } |
| 1459 | |
Maarten Lankhorst | dd7cfd6 | 2014-01-21 13:07:31 +0100 | [diff] [blame] | 1460 | void |
Maarten Lankhorst | 809e944 | 2014-04-09 16:19:30 +0200 | [diff] [blame] | 1461 | nouveau_bo_fence(struct nouveau_bo *nvbo, struct nouveau_fence *fence, bool exclusive) |
Maarten Lankhorst | dd7cfd6 | 2014-01-21 13:07:31 +0100 | [diff] [blame] | 1462 | { |
Maarten Lankhorst | 29ba89b | 2014-01-09 11:03:11 +0100 | [diff] [blame] | 1463 | struct reservation_object *resv = nvbo->bo.resv; |
Maarten Lankhorst | dd7cfd6 | 2014-01-21 13:07:31 +0100 | [diff] [blame] | 1464 | |
Maarten Lankhorst | 809e944 | 2014-04-09 16:19:30 +0200 | [diff] [blame] | 1465 | if (exclusive) |
| 1466 | reservation_object_add_excl_fence(resv, &fence->base); |
| 1467 | else if (fence) |
| 1468 | reservation_object_add_shared_fence(resv, &fence->base); |
Maarten Lankhorst | dd7cfd6 | 2014-01-21 13:07:31 +0100 | [diff] [blame] | 1469 | } |
| 1470 | |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1471 | struct ttm_bo_driver nouveau_bo_driver = { |
Jerome Glisse | 649bf3c | 2011-11-01 20:46:13 -0400 | [diff] [blame] | 1472 | .ttm_tt_create = &nouveau_ttm_tt_create, |
Konrad Rzeszutek Wilk | 3230cfc | 2011-10-17 17:14:26 -0400 | [diff] [blame] | 1473 | .ttm_tt_populate = &nouveau_ttm_tt_populate, |
| 1474 | .ttm_tt_unpopulate = &nouveau_ttm_tt_unpopulate, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1475 | .invalidate_caches = nouveau_bo_invalidate_caches, |
| 1476 | .init_mem_type = nouveau_bo_init_mem_type, |
| 1477 | .evict_flags = nouveau_bo_evict_flags, |
Ben Skeggs | a4154bb | 2011-02-10 10:35:16 +1000 | [diff] [blame] | 1478 | .move_notify = nouveau_bo_move_ntfy, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1479 | .move = nouveau_bo_move, |
| 1480 | .verify_access = nouveau_bo_verify_access, |
Jerome Glisse | f32f02f | 2010-04-09 14:39:25 +0200 | [diff] [blame] | 1481 | .fault_reserve_notify = &nouveau_ttm_fault_reserve_notify, |
| 1482 | .io_mem_reserve = &nouveau_ttm_io_mem_reserve, |
| 1483 | .io_mem_free = &nouveau_ttm_io_mem_free, |
Ben Skeggs | 6ee7386 | 2009-12-11 19:24:15 +1000 | [diff] [blame] | 1484 | }; |
| 1485 | |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 1486 | struct nouveau_vma * |
| 1487 | nouveau_bo_vma_find(struct nouveau_bo *nvbo, struct nouveau_vm *vm) |
| 1488 | { |
| 1489 | struct nouveau_vma *vma; |
| 1490 | list_for_each_entry(vma, &nvbo->vma_list, head) { |
| 1491 | if (vma->vm == vm) |
| 1492 | return vma; |
| 1493 | } |
| 1494 | |
| 1495 | return NULL; |
| 1496 | } |
| 1497 | |
| 1498 | int |
| 1499 | nouveau_bo_vma_add(struct nouveau_bo *nvbo, struct nouveau_vm *vm, |
| 1500 | struct nouveau_vma *vma) |
| 1501 | { |
| 1502 | const u32 size = nvbo->bo.mem.num_pages << PAGE_SHIFT; |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 1503 | int ret; |
| 1504 | |
| 1505 | ret = nouveau_vm_get(vm, size, nvbo->page_shift, |
| 1506 | NV_MEM_ACCESS_RW, vma); |
| 1507 | if (ret) |
| 1508 | return ret; |
| 1509 | |
Ben Skeggs | 2e2cfbe | 2013-11-15 11:56:49 +1000 | [diff] [blame] | 1510 | if ( nvbo->bo.mem.mem_type != TTM_PL_SYSTEM && |
| 1511 | (nvbo->bo.mem.mem_type == TTM_PL_VRAM || |
| 1512 | nvbo->page_shift != vma->vm->vmm->lpg_shift)) |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 1513 | nouveau_vm_map(vma, nvbo->bo.mem.mm_node); |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 1514 | |
| 1515 | list_add_tail(&vma->head, &nvbo->vma_list); |
Ben Skeggs | 2fd3db6 | 2011-06-07 15:25:12 +1000 | [diff] [blame] | 1516 | vma->refcount = 1; |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 1517 | return 0; |
| 1518 | } |
| 1519 | |
| 1520 | void |
| 1521 | nouveau_bo_vma_del(struct nouveau_bo *nvbo, struct nouveau_vma *vma) |
| 1522 | { |
| 1523 | if (vma->node) { |
Ben Skeggs | c4c7044 | 2013-05-07 09:48:30 +1000 | [diff] [blame] | 1524 | if (nvbo->bo.mem.mem_type != TTM_PL_SYSTEM) |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 1525 | nouveau_vm_unmap(vma); |
Ben Skeggs | fd2871a | 2011-06-06 14:07:04 +1000 | [diff] [blame] | 1526 | nouveau_vm_put(vma); |
| 1527 | list_del(&vma->head); |
| 1528 | } |
| 1529 | } |