1 1.2 riastrad /* $NetBSD: nouveau_dma.h,v 1.3 2021/12/18 23:45:32 riastradh Exp $ */ 2 1.2 riastrad 3 1.1 riastrad /* 4 1.1 riastrad * Copyright (C) 2007 Ben Skeggs. 5 1.1 riastrad * All Rights Reserved. 6 1.1 riastrad * 7 1.1 riastrad * Permission is hereby granted, free of charge, to any person obtaining 8 1.1 riastrad * a copy of this software and associated documentation files (the 9 1.1 riastrad * "Software"), to deal in the Software without restriction, including 10 1.1 riastrad * without limitation the rights to use, copy, modify, merge, publish, 11 1.1 riastrad * distribute, sublicense, and/or sell copies of the Software, and to 12 1.1 riastrad * permit persons to whom the Software is furnished to do so, subject to 13 1.1 riastrad * the following conditions: 14 1.1 riastrad * 15 1.1 riastrad * The above copyright notice and this permission notice (including the 16 1.1 riastrad * next paragraph) shall be included in all copies or substantial 17 1.1 riastrad * portions of the Software. 18 1.1 riastrad * 19 1.1 riastrad * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, 20 1.1 riastrad * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF 21 1.1 riastrad * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. 22 1.1 riastrad * IN NO EVENT SHALL THE COPYRIGHT OWNER(S) AND/OR ITS SUPPLIERS BE 23 1.1 riastrad * LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION 24 1.1 riastrad * OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION 25 1.1 riastrad * WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. 26 1.1 riastrad * 27 1.1 riastrad */ 28 1.1 riastrad 29 1.1 riastrad #ifndef __NOUVEAU_DMA_H__ 30 1.1 riastrad #define __NOUVEAU_DMA_H__ 31 1.1 riastrad 32 1.1 riastrad #include "nouveau_bo.h" 33 1.1 riastrad #include "nouveau_chan.h" 34 1.1 riastrad 35 1.1 riastrad int nouveau_dma_wait(struct nouveau_channel *, int slots, int size); 36 1.3 riastrad void nv50_dma_push(struct nouveau_channel *, u64 addr, int length); 37 1.1 riastrad 38 1.1 riastrad /* 39 1.1 riastrad * There's a hw race condition where you can't jump to your PUT offset, 40 1.1 riastrad * to avoid this we jump to offset + SKIPS and fill the difference with 41 1.1 riastrad * NOPs. 42 1.1 riastrad * 43 1.1 riastrad * xf86-video-nv configures the DMA fetch size to 32 bytes, and uses 44 1.1 riastrad * a SKIPS value of 8. Lets assume that the race condition is to do 45 1.1 riastrad * with writing into the fetch area, we configure a fetch size of 128 46 1.1 riastrad * bytes so we need a larger SKIPS value. 47 1.1 riastrad */ 48 1.1 riastrad #define NOUVEAU_DMA_SKIPS (128 / 4) 49 1.1 riastrad 50 1.1 riastrad /* Hardcoded object assignments to subchannels (subchannel id). */ 51 1.1 riastrad enum { 52 1.1 riastrad NvSubCtxSurf2D = 0, 53 1.1 riastrad NvSubSw = 1, 54 1.1 riastrad NvSubImageBlit = 2, 55 1.1 riastrad NvSubGdiRect = 3, 56 1.1 riastrad 57 1.1 riastrad NvSub2D = 3, /* DO NOT CHANGE - hardcoded for kepler gr fifo */ 58 1.1 riastrad NvSubCopy = 4, /* DO NOT CHANGE - hardcoded for kepler gr fifo */ 59 1.1 riastrad }; 60 1.1 riastrad 61 1.2 riastrad /* Object handles - for stuff that's doesn't use handle == oclass. */ 62 1.1 riastrad enum { 63 1.1 riastrad NvDmaFB = 0x80000002, 64 1.1 riastrad NvDmaTT = 0x80000003, 65 1.1 riastrad NvNotify0 = 0x80000006, 66 1.1 riastrad NvSema = 0x8000000f, 67 1.1 riastrad NvEvoSema0 = 0x80000010, 68 1.1 riastrad NvEvoSema1 = 0x80000011, 69 1.1 riastrad }; 70 1.1 riastrad 71 1.1 riastrad #define NV_MEMORY_TO_MEMORY_FORMAT 0x00000039 72 1.1 riastrad #define NV_MEMORY_TO_MEMORY_FORMAT_NAME 0x00000000 73 1.1 riastrad #define NV_MEMORY_TO_MEMORY_FORMAT_SET_REF 0x00000050 74 1.1 riastrad #define NV_MEMORY_TO_MEMORY_FORMAT_NOP 0x00000100 75 1.1 riastrad #define NV_MEMORY_TO_MEMORY_FORMAT_NOTIFY 0x00000104 76 1.1 riastrad #define NV_MEMORY_TO_MEMORY_FORMAT_NOTIFY_STYLE_WRITE 0x00000000 77 1.1 riastrad #define NV_MEMORY_TO_MEMORY_FORMAT_NOTIFY_STYLE_WRITE_LE_AWAKEN 0x00000001 78 1.1 riastrad #define NV_MEMORY_TO_MEMORY_FORMAT_DMA_NOTIFY 0x00000180 79 1.1 riastrad #define NV_MEMORY_TO_MEMORY_FORMAT_DMA_SOURCE 0x00000184 80 1.1 riastrad #define NV_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN 0x0000030c 81 1.1 riastrad 82 1.1 riastrad #define NV50_MEMORY_TO_MEMORY_FORMAT 0x00005039 83 1.1 riastrad #define NV50_MEMORY_TO_MEMORY_FORMAT_UNK200 0x00000200 84 1.1 riastrad #define NV50_MEMORY_TO_MEMORY_FORMAT_UNK21C 0x0000021c 85 1.1 riastrad #define NV50_MEMORY_TO_MEMORY_FORMAT_OFFSET_IN_HIGH 0x00000238 86 1.1 riastrad #define NV50_MEMORY_TO_MEMORY_FORMAT_OFFSET_OUT_HIGH 0x0000023c 87 1.1 riastrad 88 1.1 riastrad static __must_check inline int 89 1.1 riastrad RING_SPACE(struct nouveau_channel *chan, int size) 90 1.1 riastrad { 91 1.1 riastrad int ret; 92 1.1 riastrad 93 1.1 riastrad ret = nouveau_dma_wait(chan, 1, size); 94 1.1 riastrad if (ret) 95 1.1 riastrad return ret; 96 1.1 riastrad 97 1.1 riastrad chan->dma.free -= size; 98 1.1 riastrad return 0; 99 1.1 riastrad } 100 1.1 riastrad 101 1.1 riastrad static inline void 102 1.1 riastrad OUT_RING(struct nouveau_channel *chan, int data) 103 1.1 riastrad { 104 1.1 riastrad nouveau_bo_wr32(chan->push.buffer, chan->dma.cur++, data); 105 1.1 riastrad } 106 1.1 riastrad 107 1.1 riastrad extern void 108 1.1 riastrad OUT_RINGp(struct nouveau_channel *chan, const void *data, unsigned nr_dwords); 109 1.1 riastrad 110 1.1 riastrad static inline void 111 1.1 riastrad BEGIN_NV04(struct nouveau_channel *chan, int subc, int mthd, int size) 112 1.1 riastrad { 113 1.1 riastrad OUT_RING(chan, 0x00000000 | (subc << 13) | (size << 18) | mthd); 114 1.1 riastrad } 115 1.1 riastrad 116 1.1 riastrad static inline void 117 1.1 riastrad BEGIN_NI04(struct nouveau_channel *chan, int subc, int mthd, int size) 118 1.1 riastrad { 119 1.1 riastrad OUT_RING(chan, 0x40000000 | (subc << 13) | (size << 18) | mthd); 120 1.1 riastrad } 121 1.1 riastrad 122 1.1 riastrad static inline void 123 1.1 riastrad BEGIN_NVC0(struct nouveau_channel *chan, int subc, int mthd, int size) 124 1.1 riastrad { 125 1.1 riastrad OUT_RING(chan, 0x20000000 | (size << 16) | (subc << 13) | (mthd >> 2)); 126 1.1 riastrad } 127 1.1 riastrad 128 1.1 riastrad static inline void 129 1.1 riastrad BEGIN_NIC0(struct nouveau_channel *chan, int subc, int mthd, int size) 130 1.1 riastrad { 131 1.1 riastrad OUT_RING(chan, 0x60000000 | (size << 16) | (subc << 13) | (mthd >> 2)); 132 1.1 riastrad } 133 1.1 riastrad 134 1.1 riastrad static inline void 135 1.1 riastrad BEGIN_IMC0(struct nouveau_channel *chan, int subc, int mthd, u16 data) 136 1.1 riastrad { 137 1.1 riastrad OUT_RING(chan, 0x80000000 | (data << 16) | (subc << 13) | (mthd >> 2)); 138 1.1 riastrad } 139 1.1 riastrad 140 1.1 riastrad #define WRITE_PUT(val) do { \ 141 1.1 riastrad mb(); \ 142 1.1 riastrad nouveau_bo_rd32(chan->push.buffer, 0); \ 143 1.3 riastrad nvif_wr32(&chan->user, chan->user_put, ((val) << 2) + chan->push.addr);\ 144 1.1 riastrad } while (0) 145 1.1 riastrad 146 1.1 riastrad static inline void 147 1.1 riastrad FIRE_RING(struct nouveau_channel *chan) 148 1.1 riastrad { 149 1.1 riastrad if (chan->dma.cur == chan->dma.put) 150 1.1 riastrad return; 151 1.1 riastrad chan->accel_done = true; 152 1.1 riastrad 153 1.1 riastrad if (chan->dma.ib_max) { 154 1.3 riastrad nv50_dma_push(chan, chan->push.addr + (chan->dma.put << 2), 155 1.1 riastrad (chan->dma.cur - chan->dma.put) << 2); 156 1.1 riastrad } else { 157 1.1 riastrad WRITE_PUT(chan->dma.cur); 158 1.1 riastrad } 159 1.1 riastrad 160 1.1 riastrad chan->dma.put = chan->dma.cur; 161 1.1 riastrad } 162 1.1 riastrad 163 1.1 riastrad static inline void 164 1.1 riastrad WIND_RING(struct nouveau_channel *chan) 165 1.1 riastrad { 166 1.1 riastrad chan->dma.cur = chan->dma.put; 167 1.1 riastrad } 168 1.1 riastrad 169 1.1 riastrad /* FIFO methods */ 170 1.1 riastrad #define NV01_SUBCHAN_OBJECT 0x00000000 171 1.1 riastrad #define NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH 0x00000010 172 1.1 riastrad #define NV84_SUBCHAN_SEMAPHORE_ADDRESS_LOW 0x00000014 173 1.1 riastrad #define NV84_SUBCHAN_SEMAPHORE_SEQUENCE 0x00000018 174 1.1 riastrad #define NV84_SUBCHAN_SEMAPHORE_TRIGGER 0x0000001c 175 1.1 riastrad #define NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL 0x00000001 176 1.1 riastrad #define NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG 0x00000002 177 1.1 riastrad #define NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_GEQUAL 0x00000004 178 1.1 riastrad #define NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD 0x00001000 179 1.1 riastrad #define NV84_SUBCHAN_UEVENT 0x00000020 180 1.1 riastrad #define NV84_SUBCHAN_WRCACHE_FLUSH 0x00000024 181 1.1 riastrad #define NV10_SUBCHAN_REF_CNT 0x00000050 182 1.1 riastrad #define NV11_SUBCHAN_DMA_SEMAPHORE 0x00000060 183 1.1 riastrad #define NV11_SUBCHAN_SEMAPHORE_OFFSET 0x00000064 184 1.1 riastrad #define NV11_SUBCHAN_SEMAPHORE_ACQUIRE 0x00000068 185 1.1 riastrad #define NV11_SUBCHAN_SEMAPHORE_RELEASE 0x0000006c 186 1.1 riastrad #define NV40_SUBCHAN_YIELD 0x00000080 187 1.1 riastrad 188 1.1 riastrad /* NV_SW object class */ 189 1.1 riastrad #define NV_SW_DMA_VBLSEM 0x0000018c 190 1.1 riastrad #define NV_SW_VBLSEM_OFFSET 0x00000400 191 1.1 riastrad #define NV_SW_VBLSEM_RELEASE_VALUE 0x00000404 192 1.1 riastrad #define NV_SW_VBLSEM_RELEASE 0x00000408 193 1.1 riastrad #define NV_SW_PAGE_FLIP 0x00000500 194 1.1 riastrad 195 1.1 riastrad #endif 196