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