Ben Skeggs | 56d237d | 2014-05-19 14:54:33 +1000 | [diff] [blame] | 1 | /* |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2 | * Copyright 2011 Red Hat Inc. |
| 3 | * |
| 4 | * Permission is hereby granted, free of charge, to any person obtaining a |
| 5 | * copy of this software and associated documentation files (the "Software"), |
| 6 | * to deal in the Software without restriction, including without limitation |
| 7 | * the rights to use, copy, modify, merge, publish, distribute, sublicense, |
| 8 | * and/or sell copies of the Software, and to permit persons to whom the |
| 9 | * Software is furnished to do so, subject to the following conditions: |
| 10 | * |
| 11 | * The above copyright notice and this permission notice shall be included in |
| 12 | * all copies or substantial portions of the Software. |
| 13 | * |
| 14 | * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
| 15 | * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
| 16 | * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL |
| 17 | * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR |
| 18 | * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, |
| 19 | * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR |
| 20 | * OTHER DEALINGS IN THE SOFTWARE. |
| 21 | * |
| 22 | * Authors: Ben Skeggs |
| 23 | */ |
| 24 | |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 25 | #include <linux/dma-mapping.h> |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 26 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 27 | #include <drm/drmP.h> |
| 28 | #include <drm/drm_crtc_helper.h> |
Ben Skeggs | 4874322 | 2014-05-31 01:48:06 +1000 | [diff] [blame] | 29 | #include <drm/drm_dp_helper.h> |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 30 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 31 | #include "nouveau_drm.h" |
| 32 | #include "nouveau_dma.h" |
| 33 | #include "nouveau_gem.h" |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 34 | #include "nouveau_connector.h" |
| 35 | #include "nouveau_encoder.h" |
| 36 | #include "nouveau_crtc.h" |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 37 | #include "nouveau_fence.h" |
Ben Skeggs | 3a89cd0 | 2011-07-07 10:47:10 +1000 | [diff] [blame] | 38 | #include "nv50_display.h" |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 39 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 40 | #include <core/client.h> |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 41 | #include <core/gpuobj.h> |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 42 | #include <core/class.h> |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 43 | |
| 44 | #include <subdev/timer.h> |
| 45 | #include <subdev/bar.h> |
| 46 | #include <subdev/fb.h> |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 47 | #include <subdev/i2c.h> |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 48 | |
Ben Skeggs | 8a46438 | 2011-11-12 23:52:07 +1000 | [diff] [blame] | 49 | #define EVO_DMA_NR 9 |
| 50 | |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 51 | #define EVO_MASTER (0x00) |
Ben Skeggs | a63a97e | 2011-11-16 15:22:34 +1000 | [diff] [blame] | 52 | #define EVO_FLIP(c) (0x01 + (c)) |
Ben Skeggs | 8a46438 | 2011-11-12 23:52:07 +1000 | [diff] [blame] | 53 | #define EVO_OVLY(c) (0x05 + (c)) |
| 54 | #define EVO_OIMM(c) (0x09 + (c)) |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 55 | #define EVO_CURS(c) (0x0d + (c)) |
| 56 | |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 57 | /* offsets in shared sync bo of various structures */ |
| 58 | #define EVO_SYNC(c, o) ((c) * 0x0100 + (o)) |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 59 | #define EVO_MAST_NTFY EVO_SYNC( 0, 0x00) |
| 60 | #define EVO_FLIP_SEM0(c) EVO_SYNC((c) + 1, 0x00) |
| 61 | #define EVO_FLIP_SEM1(c) EVO_SYNC((c) + 1, 0x10) |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 62 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 63 | #define EVO_CORE_HANDLE (0xd1500000) |
| 64 | #define EVO_CHAN_HANDLE(t,i) (0xd15c0000 | (((t) & 0x00ff) << 8) | (i)) |
| 65 | #define EVO_CHAN_OCLASS(t,c) ((nv_hclass(c) & 0xff00) | ((t) & 0x00ff)) |
| 66 | #define EVO_PUSH_HANDLE(t,i) (0xd15b0000 | (i) | \ |
| 67 | (((NV50_DISP_##t##_CLASS) & 0x00ff) << 8)) |
| 68 | |
| 69 | /****************************************************************************** |
| 70 | * EVO channel |
| 71 | *****************************************************************************/ |
| 72 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 73 | struct nv50_chan { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 74 | struct nouveau_object *user; |
| 75 | u32 handle; |
| 76 | }; |
| 77 | |
| 78 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 79 | nv50_chan_create(struct nouveau_object *core, u32 bclass, u8 head, |
| 80 | void *data, u32 size, struct nv50_chan *chan) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 81 | { |
| 82 | struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS); |
| 83 | const u32 oclass = EVO_CHAN_OCLASS(bclass, core); |
| 84 | const u32 handle = EVO_CHAN_HANDLE(bclass, head); |
| 85 | int ret; |
| 86 | |
| 87 | ret = nouveau_object_new(client, EVO_CORE_HANDLE, handle, |
| 88 | oclass, data, size, &chan->user); |
| 89 | if (ret) |
| 90 | return ret; |
| 91 | |
| 92 | chan->handle = handle; |
| 93 | return 0; |
| 94 | } |
| 95 | |
| 96 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 97 | nv50_chan_destroy(struct nouveau_object *core, struct nv50_chan *chan) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 98 | { |
| 99 | struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS); |
| 100 | if (chan->handle) |
| 101 | nouveau_object_del(client, EVO_CORE_HANDLE, chan->handle); |
| 102 | } |
| 103 | |
| 104 | /****************************************************************************** |
| 105 | * PIO EVO channel |
| 106 | *****************************************************************************/ |
| 107 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 108 | struct nv50_pioc { |
| 109 | struct nv50_chan base; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 110 | }; |
| 111 | |
| 112 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 113 | nv50_pioc_destroy(struct nouveau_object *core, struct nv50_pioc *pioc) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 114 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 115 | nv50_chan_destroy(core, &pioc->base); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 116 | } |
| 117 | |
| 118 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 119 | nv50_pioc_create(struct nouveau_object *core, u32 bclass, u8 head, |
| 120 | void *data, u32 size, struct nv50_pioc *pioc) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 121 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 122 | return nv50_chan_create(core, bclass, head, data, size, &pioc->base); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 123 | } |
| 124 | |
| 125 | /****************************************************************************** |
| 126 | * DMA EVO channel |
| 127 | *****************************************************************************/ |
| 128 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 129 | struct nv50_dmac { |
| 130 | struct nv50_chan base; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 131 | dma_addr_t handle; |
| 132 | u32 *ptr; |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 133 | |
| 134 | /* Protects against concurrent pushbuf access to this channel, lock is |
| 135 | * grabbed by evo_wait (if the pushbuf reservation is successful) and |
| 136 | * dropped again by evo_kick. */ |
| 137 | struct mutex lock; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 138 | }; |
| 139 | |
| 140 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 141 | nv50_dmac_destroy(struct nouveau_object *core, struct nv50_dmac *dmac) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 142 | { |
| 143 | if (dmac->ptr) { |
| 144 | struct pci_dev *pdev = nv_device(core)->pdev; |
| 145 | pci_free_consistent(pdev, PAGE_SIZE, dmac->ptr, dmac->handle); |
| 146 | } |
| 147 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 148 | nv50_chan_destroy(core, &dmac->base); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 149 | } |
| 150 | |
| 151 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 152 | nv50_dmac_create(struct nouveau_object *core, u32 bclass, u8 head, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 153 | void *data, u32 size, u64 syncbuf, |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 154 | struct nv50_dmac *dmac) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 155 | { |
| 156 | struct nouveau_fb *pfb = nouveau_fb(core); |
| 157 | struct nouveau_object *client = nv_pclass(core, NV_CLIENT_CLASS); |
| 158 | struct nouveau_object *object; |
| 159 | u32 pushbuf = *(u32 *)data; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 160 | int ret; |
| 161 | |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 162 | mutex_init(&dmac->lock); |
| 163 | |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 164 | dmac->ptr = pci_alloc_consistent(nv_device(core)->pdev, PAGE_SIZE, |
| 165 | &dmac->handle); |
| 166 | if (!dmac->ptr) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 167 | return -ENOMEM; |
| 168 | |
| 169 | ret = nouveau_object_new(client, NVDRM_DEVICE, pushbuf, |
| 170 | NV_DMA_FROM_MEMORY_CLASS, |
| 171 | &(struct nv_dma_class) { |
| 172 | .flags = NV_DMA_TARGET_PCI_US | |
| 173 | NV_DMA_ACCESS_RD, |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 174 | .start = dmac->handle + 0x0000, |
| 175 | .limit = dmac->handle + 0x0fff, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 176 | }, sizeof(struct nv_dma_class), &object); |
| 177 | if (ret) |
| 178 | return ret; |
| 179 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 180 | ret = nv50_chan_create(core, bclass, head, data, size, &dmac->base); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 181 | if (ret) |
| 182 | return ret; |
| 183 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 184 | ret = nouveau_object_new(client, dmac->base.handle, NvEvoSync, |
| 185 | NV_DMA_IN_MEMORY_CLASS, |
| 186 | &(struct nv_dma_class) { |
| 187 | .flags = NV_DMA_TARGET_VRAM | |
| 188 | NV_DMA_ACCESS_RDWR, |
| 189 | .start = syncbuf + 0x0000, |
| 190 | .limit = syncbuf + 0x0fff, |
| 191 | }, sizeof(struct nv_dma_class), &object); |
| 192 | if (ret) |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 193 | return ret; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 194 | |
| 195 | ret = nouveau_object_new(client, dmac->base.handle, NvEvoVRAM, |
| 196 | NV_DMA_IN_MEMORY_CLASS, |
| 197 | &(struct nv_dma_class) { |
| 198 | .flags = NV_DMA_TARGET_VRAM | |
| 199 | NV_DMA_ACCESS_RDWR, |
| 200 | .start = 0, |
Ben Skeggs | dceef5d | 2013-03-04 13:01:21 +1000 | [diff] [blame] | 201 | .limit = pfb->ram->size - 1, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 202 | }, sizeof(struct nv_dma_class), &object); |
| 203 | if (ret) |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 204 | return ret; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 205 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 206 | return ret; |
| 207 | } |
| 208 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 209 | struct nv50_mast { |
| 210 | struct nv50_dmac base; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 211 | }; |
| 212 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 213 | struct nv50_curs { |
| 214 | struct nv50_pioc base; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 215 | }; |
| 216 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 217 | struct nv50_sync { |
| 218 | struct nv50_dmac base; |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 219 | u32 addr; |
| 220 | u32 data; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 221 | }; |
| 222 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 223 | struct nv50_ovly { |
| 224 | struct nv50_dmac base; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 225 | }; |
Ben Skeggs | f20ce96 | 2011-07-08 13:17:01 +1000 | [diff] [blame] | 226 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 227 | struct nv50_oimm { |
| 228 | struct nv50_pioc base; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 229 | }; |
| 230 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 231 | struct nv50_head { |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 232 | struct nouveau_crtc base; |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 233 | struct nouveau_bo *image; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 234 | struct nv50_curs curs; |
| 235 | struct nv50_sync sync; |
| 236 | struct nv50_ovly ovly; |
| 237 | struct nv50_oimm oimm; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 238 | }; |
| 239 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 240 | #define nv50_head(c) ((struct nv50_head *)nouveau_crtc(c)) |
| 241 | #define nv50_curs(c) (&nv50_head(c)->curs) |
| 242 | #define nv50_sync(c) (&nv50_head(c)->sync) |
| 243 | #define nv50_ovly(c) (&nv50_head(c)->ovly) |
| 244 | #define nv50_oimm(c) (&nv50_head(c)->oimm) |
| 245 | #define nv50_chan(c) (&(c)->base.base) |
| 246 | #define nv50_vers(c) nv_mclass(nv50_chan(c)->user) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 247 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 248 | struct nv50_disp { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 249 | struct nouveau_object *core; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 250 | struct nv50_mast mast; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 251 | |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 252 | struct list_head fbdma; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 253 | |
| 254 | struct nouveau_bo *sync; |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 255 | }; |
| 256 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 257 | static struct nv50_disp * |
| 258 | nv50_disp(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 259 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 260 | return nouveau_display(dev)->priv; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 261 | } |
| 262 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 263 | #define nv50_mast(d) (&nv50_disp(d)->mast) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 264 | |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 265 | static struct drm_crtc * |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 266 | nv50_display_crtc_get(struct drm_encoder *encoder) |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 267 | { |
| 268 | return nouveau_encoder(encoder)->crtc; |
| 269 | } |
| 270 | |
| 271 | /****************************************************************************** |
| 272 | * EVO channel helpers |
| 273 | *****************************************************************************/ |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 274 | static u32 * |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 275 | evo_wait(void *evoc, int nr) |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 276 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 277 | struct nv50_dmac *dmac = evoc; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 278 | u32 put = nv_ro32(dmac->base.user, 0x0000) / 4; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 279 | |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 280 | mutex_lock(&dmac->lock); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 281 | if (put + nr >= (PAGE_SIZE / 4) - 8) { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 282 | dmac->ptr[put] = 0x20000000; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 283 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 284 | nv_wo32(dmac->base.user, 0x0000, 0x00000000); |
| 285 | if (!nv_wait(dmac->base.user, 0x0004, ~0, 0x00000000)) { |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 286 | mutex_unlock(&dmac->lock); |
Ben Skeggs | fa2bade | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 287 | nv_error(dmac->base.user, "channel stalled\n"); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 288 | return NULL; |
| 289 | } |
| 290 | |
| 291 | put = 0; |
| 292 | } |
| 293 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 294 | return dmac->ptr + put; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 295 | } |
| 296 | |
| 297 | static void |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 298 | evo_kick(u32 *push, void *evoc) |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 299 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 300 | struct nv50_dmac *dmac = evoc; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 301 | nv_wo32(dmac->base.user, 0x0000, (push - dmac->ptr) << 2); |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 302 | mutex_unlock(&dmac->lock); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 303 | } |
| 304 | |
| 305 | #define evo_mthd(p,m,s) *((p)++) = (((s) << 18) | (m)) |
| 306 | #define evo_data(p,d) *((p)++) = (d) |
| 307 | |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 308 | static bool |
| 309 | evo_sync_wait(void *data) |
| 310 | { |
Ben Skeggs | 5cc027f | 2013-02-18 17:50:51 -0500 | [diff] [blame] | 311 | if (nouveau_bo_rd32(data, EVO_MAST_NTFY) != 0x00000000) |
| 312 | return true; |
| 313 | usleep_range(1, 2); |
| 314 | return false; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 315 | } |
| 316 | |
| 317 | static int |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 318 | evo_sync(struct drm_device *dev) |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 319 | { |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame^] | 320 | struct nvif_device *device = &nouveau_drm(dev)->device; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 321 | struct nv50_disp *disp = nv50_disp(dev); |
| 322 | struct nv50_mast *mast = nv50_mast(dev); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 323 | u32 *push = evo_wait(mast, 8); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 324 | if (push) { |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 325 | nouveau_bo_wr32(disp->sync, EVO_MAST_NTFY, 0x00000000); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 326 | evo_mthd(push, 0x0084, 1); |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 327 | evo_data(push, 0x80000000 | EVO_MAST_NTFY); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 328 | evo_mthd(push, 0x0080, 2); |
| 329 | evo_data(push, 0x00000000); |
| 330 | evo_data(push, 0x00000000); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 331 | evo_kick(push, mast); |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame^] | 332 | if (nv_wait_cb(nvkm_device(device), evo_sync_wait, disp->sync)) |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 333 | return 0; |
| 334 | } |
| 335 | |
| 336 | return -EBUSY; |
| 337 | } |
| 338 | |
| 339 | /****************************************************************************** |
Ben Skeggs | a63a97e | 2011-11-16 15:22:34 +1000 | [diff] [blame] | 340 | * Page flipping channel |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 341 | *****************************************************************************/ |
| 342 | struct nouveau_bo * |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 343 | nv50_display_crtc_sema(struct drm_device *dev, int crtc) |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 344 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 345 | return nv50_disp(dev)->sync; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 346 | } |
| 347 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 348 | struct nv50_display_flip { |
| 349 | struct nv50_disp *disp; |
| 350 | struct nv50_sync *chan; |
| 351 | }; |
| 352 | |
| 353 | static bool |
| 354 | nv50_display_flip_wait(void *data) |
| 355 | { |
| 356 | struct nv50_display_flip *flip = data; |
| 357 | if (nouveau_bo_rd32(flip->disp->sync, flip->chan->addr / 4) == |
Calvin Owens | b1ea3e6 | 2013-04-07 21:01:19 -0500 | [diff] [blame] | 358 | flip->chan->data) |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 359 | return true; |
| 360 | usleep_range(1, 2); |
| 361 | return false; |
| 362 | } |
| 363 | |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 364 | void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 365 | nv50_display_flip_stop(struct drm_crtc *crtc) |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 366 | { |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame^] | 367 | struct nvif_device *device = &nouveau_drm(crtc->dev)->device; |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 368 | struct nv50_display_flip flip = { |
| 369 | .disp = nv50_disp(crtc->dev), |
| 370 | .chan = nv50_sync(crtc), |
| 371 | }; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 372 | u32 *push; |
| 373 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 374 | push = evo_wait(flip.chan, 8); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 375 | if (push) { |
| 376 | evo_mthd(push, 0x0084, 1); |
| 377 | evo_data(push, 0x00000000); |
| 378 | evo_mthd(push, 0x0094, 1); |
| 379 | evo_data(push, 0x00000000); |
| 380 | evo_mthd(push, 0x00c0, 1); |
| 381 | evo_data(push, 0x00000000); |
| 382 | evo_mthd(push, 0x0080, 1); |
| 383 | evo_data(push, 0x00000000); |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 384 | evo_kick(push, flip.chan); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 385 | } |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 386 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame^] | 387 | nv_wait_cb(nvkm_device(device), nv50_display_flip_wait, &flip); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 388 | } |
| 389 | |
| 390 | int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 391 | nv50_display_flip_next(struct drm_crtc *crtc, struct drm_framebuffer *fb, |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 392 | struct nouveau_channel *chan, u32 swap_interval) |
| 393 | { |
| 394 | struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 395 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 396 | struct nv50_head *head = nv50_head(crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 397 | struct nv50_sync *sync = nv50_sync(crtc); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 398 | u32 *push; |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 399 | int ret; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 400 | |
| 401 | swap_interval <<= 4; |
| 402 | if (swap_interval == 0) |
| 403 | swap_interval |= 0x100; |
Ben Skeggs | f60b6e7 | 2013-03-19 15:20:00 +1000 | [diff] [blame] | 404 | if (chan == NULL) |
| 405 | evo_sync(crtc->dev); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 406 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 407 | push = evo_wait(sync, 128); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 408 | if (unlikely(push == NULL)) |
| 409 | return -EBUSY; |
| 410 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 411 | if (chan && nv_mclass(chan->object) < NV84_CHANNEL_IND_CLASS) { |
| 412 | ret = RING_SPACE(chan, 8); |
| 413 | if (ret) |
| 414 | return ret; |
Ben Skeggs | 67f9718 | 2013-02-26 12:02:54 +1000 | [diff] [blame] | 415 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 416 | BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 2); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 417 | OUT_RING (chan, NvEvoSema0 + nv_crtc->index); |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 418 | OUT_RING (chan, sync->addr ^ 0x10); |
| 419 | BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_RELEASE, 1); |
| 420 | OUT_RING (chan, sync->data + 1); |
| 421 | BEGIN_NV04(chan, 0, NV11_SUBCHAN_SEMAPHORE_OFFSET, 2); |
| 422 | OUT_RING (chan, sync->addr); |
| 423 | OUT_RING (chan, sync->data); |
| 424 | } else |
| 425 | if (chan && nv_mclass(chan->object) < NVC0_CHANNEL_IND_CLASS) { |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 426 | u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr; |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 427 | ret = RING_SPACE(chan, 12); |
| 428 | if (ret) |
| 429 | return ret; |
Ben Skeggs | a34caf7 | 2013-02-14 09:28:37 +1000 | [diff] [blame] | 430 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 431 | BEGIN_NV04(chan, 0, NV11_SUBCHAN_DMA_SEMAPHORE, 1); |
| 432 | OUT_RING (chan, chan->vram); |
| 433 | BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); |
| 434 | OUT_RING (chan, upper_32_bits(addr ^ 0x10)); |
| 435 | OUT_RING (chan, lower_32_bits(addr ^ 0x10)); |
| 436 | OUT_RING (chan, sync->data + 1); |
| 437 | OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG); |
| 438 | BEGIN_NV04(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); |
| 439 | OUT_RING (chan, upper_32_bits(addr)); |
| 440 | OUT_RING (chan, lower_32_bits(addr)); |
| 441 | OUT_RING (chan, sync->data); |
| 442 | OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL); |
| 443 | } else |
| 444 | if (chan) { |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 445 | u64 addr = nv84_fence_crtc(chan, nv_crtc->index) + sync->addr; |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 446 | ret = RING_SPACE(chan, 10); |
| 447 | if (ret) |
| 448 | return ret; |
Ben Skeggs | 67f9718 | 2013-02-26 12:02:54 +1000 | [diff] [blame] | 449 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 450 | BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); |
| 451 | OUT_RING (chan, upper_32_bits(addr ^ 0x10)); |
| 452 | OUT_RING (chan, lower_32_bits(addr ^ 0x10)); |
| 453 | OUT_RING (chan, sync->data + 1); |
| 454 | OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_WRITE_LONG | |
| 455 | NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD); |
| 456 | BEGIN_NVC0(chan, 0, NV84_SUBCHAN_SEMAPHORE_ADDRESS_HIGH, 4); |
| 457 | OUT_RING (chan, upper_32_bits(addr)); |
| 458 | OUT_RING (chan, lower_32_bits(addr)); |
| 459 | OUT_RING (chan, sync->data); |
| 460 | OUT_RING (chan, NV84_SUBCHAN_SEMAPHORE_TRIGGER_ACQUIRE_EQUAL | |
| 461 | NVC0_SUBCHAN_SEMAPHORE_TRIGGER_YIELD); |
| 462 | } |
Ben Skeggs | 35bcf5d | 2012-04-30 11:34:10 -0500 | [diff] [blame] | 463 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 464 | if (chan) { |
| 465 | sync->addr ^= 0x10; |
| 466 | sync->data++; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 467 | FIRE_RING (chan); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 468 | } |
| 469 | |
| 470 | /* queue the flip */ |
| 471 | evo_mthd(push, 0x0100, 1); |
| 472 | evo_data(push, 0xfffe0000); |
| 473 | evo_mthd(push, 0x0084, 1); |
| 474 | evo_data(push, swap_interval); |
| 475 | if (!(swap_interval & 0x00000100)) { |
| 476 | evo_mthd(push, 0x00e0, 1); |
| 477 | evo_data(push, 0x40000000); |
| 478 | } |
| 479 | evo_mthd(push, 0x0088, 4); |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 480 | evo_data(push, sync->addr); |
| 481 | evo_data(push, sync->data++); |
| 482 | evo_data(push, sync->data); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 483 | evo_data(push, NvEvoSync); |
| 484 | evo_mthd(push, 0x00a0, 2); |
| 485 | evo_data(push, 0x00000000); |
| 486 | evo_data(push, 0x00000000); |
| 487 | evo_mthd(push, 0x00c0, 1); |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 488 | evo_data(push, nv_fb->r_handle); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 489 | evo_mthd(push, 0x0110, 2); |
| 490 | evo_data(push, 0x00000000); |
| 491 | evo_data(push, 0x00000000); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 492 | if (nv50_vers(sync) < NVD0_DISP_SYNC_CLASS) { |
Ben Skeggs | ed5085a5 | 2012-11-16 13:16:51 +1000 | [diff] [blame] | 493 | evo_mthd(push, 0x0800, 5); |
| 494 | evo_data(push, nv_fb->nvbo->bo.offset >> 8); |
| 495 | evo_data(push, 0); |
| 496 | evo_data(push, (fb->height << 16) | fb->width); |
| 497 | evo_data(push, nv_fb->r_pitch); |
| 498 | evo_data(push, nv_fb->r_format); |
| 499 | } else { |
| 500 | evo_mthd(push, 0x0400, 5); |
| 501 | evo_data(push, nv_fb->nvbo->bo.offset >> 8); |
| 502 | evo_data(push, 0); |
| 503 | evo_data(push, (fb->height << 16) | fb->width); |
| 504 | evo_data(push, nv_fb->r_pitch); |
| 505 | evo_data(push, nv_fb->r_format); |
| 506 | } |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 507 | evo_mthd(push, 0x0080, 1); |
| 508 | evo_data(push, 0x00000000); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 509 | evo_kick(push, sync); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 510 | |
| 511 | nouveau_bo_ref(nv_fb->nvbo, &head->image); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 512 | return 0; |
| 513 | } |
| 514 | |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 515 | /****************************************************************************** |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 516 | * CRTC |
| 517 | *****************************************************************************/ |
| 518 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 519 | nv50_crtc_set_dither(struct nouveau_crtc *nv_crtc, bool update) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 520 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 521 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 522 | struct nouveau_connector *nv_connector; |
| 523 | struct drm_connector *connector; |
| 524 | u32 *push, mode = 0x00; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 525 | |
Ben Skeggs | 488ff20 | 2011-10-17 10:38:10 +1000 | [diff] [blame] | 526 | nv_connector = nouveau_crtc_connector_get(nv_crtc); |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 527 | connector = &nv_connector->base; |
| 528 | if (nv_connector->dithering_mode == DITHERING_MODE_AUTO) { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 529 | if (nv_crtc->base.primary->fb->depth > connector->display_info.bpc * 3) |
Ben Skeggs | de69185 | 2011-10-17 12:23:41 +1000 | [diff] [blame] | 530 | mode = DITHERING_MODE_DYNAMIC2X2; |
| 531 | } else { |
| 532 | mode = nv_connector->dithering_mode; |
| 533 | } |
| 534 | |
| 535 | if (nv_connector->dithering_depth == DITHERING_DEPTH_AUTO) { |
| 536 | if (connector->display_info.bpc >= 8) |
| 537 | mode |= DITHERING_DEPTH_8BPC; |
| 538 | } else { |
| 539 | mode |= nv_connector->dithering_depth; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 540 | } |
| 541 | |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 542 | push = evo_wait(mast, 4); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 543 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 544 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 545 | evo_mthd(push, 0x08a0 + (nv_crtc->index * 0x0400), 1); |
| 546 | evo_data(push, mode); |
| 547 | } else |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 548 | if (nv50_vers(mast) < NVE0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 549 | evo_mthd(push, 0x0490 + (nv_crtc->index * 0x0300), 1); |
| 550 | evo_data(push, mode); |
| 551 | } else { |
| 552 | evo_mthd(push, 0x04a0 + (nv_crtc->index * 0x0300), 1); |
| 553 | evo_data(push, mode); |
| 554 | } |
| 555 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 556 | if (update) { |
| 557 | evo_mthd(push, 0x0080, 1); |
| 558 | evo_data(push, 0x00000000); |
| 559 | } |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 560 | evo_kick(push, mast); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 561 | } |
| 562 | |
| 563 | return 0; |
| 564 | } |
| 565 | |
| 566 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 567 | nv50_crtc_set_scale(struct nouveau_crtc *nv_crtc, bool update) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 568 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 569 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | 9285462 | 2011-11-11 23:49:06 +1000 | [diff] [blame] | 570 | struct drm_display_mode *omode, *umode = &nv_crtc->base.mode; |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 571 | struct drm_crtc *crtc = &nv_crtc->base; |
Ben Skeggs | f3fdc52 | 2011-07-07 16:01:57 +1000 | [diff] [blame] | 572 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 9285462 | 2011-11-11 23:49:06 +1000 | [diff] [blame] | 573 | int mode = DRM_MODE_SCALE_NONE; |
| 574 | u32 oX, oY, *push; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 575 | |
Ben Skeggs | 9285462 | 2011-11-11 23:49:06 +1000 | [diff] [blame] | 576 | /* start off at the resolution we programmed the crtc for, this |
| 577 | * effectively handles NONE/FULL scaling |
| 578 | */ |
Ben Skeggs | f3fdc52 | 2011-07-07 16:01:57 +1000 | [diff] [blame] | 579 | nv_connector = nouveau_crtc_connector_get(nv_crtc); |
Ben Skeggs | 9285462 | 2011-11-11 23:49:06 +1000 | [diff] [blame] | 580 | if (nv_connector && nv_connector->native_mode) |
| 581 | mode = nv_connector->scaling_mode; |
Ben Skeggs | f3fdc52 | 2011-07-07 16:01:57 +1000 | [diff] [blame] | 582 | |
Ben Skeggs | 9285462 | 2011-11-11 23:49:06 +1000 | [diff] [blame] | 583 | if (mode != DRM_MODE_SCALE_NONE) |
| 584 | omode = nv_connector->native_mode; |
| 585 | else |
| 586 | omode = umode; |
| 587 | |
| 588 | oX = omode->hdisplay; |
| 589 | oY = omode->vdisplay; |
| 590 | if (omode->flags & DRM_MODE_FLAG_DBLSCAN) |
| 591 | oY *= 2; |
| 592 | |
| 593 | /* add overscan compensation if necessary, will keep the aspect |
| 594 | * ratio the same as the backend mode unless overridden by the |
| 595 | * user setting both hborder and vborder properties. |
| 596 | */ |
| 597 | if (nv_connector && ( nv_connector->underscan == UNDERSCAN_ON || |
| 598 | (nv_connector->underscan == UNDERSCAN_AUTO && |
| 599 | nv_connector->edid && |
| 600 | drm_detect_hdmi_monitor(nv_connector->edid)))) { |
| 601 | u32 bX = nv_connector->underscan_hborder; |
| 602 | u32 bY = nv_connector->underscan_vborder; |
| 603 | u32 aspect = (oY << 19) / oX; |
| 604 | |
| 605 | if (bX) { |
| 606 | oX -= (bX * 2); |
| 607 | if (bY) oY -= (bY * 2); |
| 608 | else oY = ((oX * aspect) + (aspect / 2)) >> 19; |
| 609 | } else { |
| 610 | oX -= (oX >> 4) + 32; |
| 611 | if (bY) oY -= (bY * 2); |
| 612 | else oY = ((oX * aspect) + (aspect / 2)) >> 19; |
Ben Skeggs | f3fdc52 | 2011-07-07 16:01:57 +1000 | [diff] [blame] | 613 | } |
| 614 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 615 | |
Ben Skeggs | 9285462 | 2011-11-11 23:49:06 +1000 | [diff] [blame] | 616 | /* handle CENTER/ASPECT scaling, taking into account the areas |
| 617 | * removed already for overscan compensation |
| 618 | */ |
| 619 | switch (mode) { |
| 620 | case DRM_MODE_SCALE_CENTER: |
| 621 | oX = min((u32)umode->hdisplay, oX); |
| 622 | oY = min((u32)umode->vdisplay, oY); |
| 623 | /* fall-through */ |
| 624 | case DRM_MODE_SCALE_ASPECT: |
| 625 | if (oY < oX) { |
| 626 | u32 aspect = (umode->hdisplay << 19) / umode->vdisplay; |
| 627 | oX = ((oY * aspect) + (aspect / 2)) >> 19; |
| 628 | } else { |
| 629 | u32 aspect = (umode->vdisplay << 19) / umode->hdisplay; |
| 630 | oY = ((oX * aspect) + (aspect / 2)) >> 19; |
| 631 | } |
| 632 | break; |
| 633 | default: |
| 634 | break; |
| 635 | } |
| 636 | |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 637 | push = evo_wait(mast, 8); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 638 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 639 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 640 | /*XXX: SCALE_CTRL_ACTIVE??? */ |
| 641 | evo_mthd(push, 0x08d8 + (nv_crtc->index * 0x400), 2); |
| 642 | evo_data(push, (oY << 16) | oX); |
| 643 | evo_data(push, (oY << 16) | oX); |
| 644 | evo_mthd(push, 0x08a4 + (nv_crtc->index * 0x400), 1); |
| 645 | evo_data(push, 0x00000000); |
| 646 | evo_mthd(push, 0x08c8 + (nv_crtc->index * 0x400), 1); |
| 647 | evo_data(push, umode->vdisplay << 16 | umode->hdisplay); |
| 648 | } else { |
| 649 | evo_mthd(push, 0x04c0 + (nv_crtc->index * 0x300), 3); |
| 650 | evo_data(push, (oY << 16) | oX); |
| 651 | evo_data(push, (oY << 16) | oX); |
| 652 | evo_data(push, (oY << 16) | oX); |
| 653 | evo_mthd(push, 0x0494 + (nv_crtc->index * 0x300), 1); |
| 654 | evo_data(push, 0x00000000); |
| 655 | evo_mthd(push, 0x04b8 + (nv_crtc->index * 0x300), 1); |
| 656 | evo_data(push, umode->vdisplay << 16 | umode->hdisplay); |
| 657 | } |
| 658 | |
| 659 | evo_kick(push, mast); |
| 660 | |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 661 | if (update) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 662 | nv50_display_flip_stop(crtc); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 663 | nv50_display_flip_next(crtc, crtc->primary->fb, |
| 664 | NULL, 1); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 665 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 666 | } |
| 667 | |
| 668 | return 0; |
| 669 | } |
| 670 | |
| 671 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 672 | nv50_crtc_set_color_vibrance(struct nouveau_crtc *nv_crtc, bool update) |
Ben Skeggs | f9887d0 | 2012-11-21 13:03:42 +1000 | [diff] [blame] | 673 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 674 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | f9887d0 | 2012-11-21 13:03:42 +1000 | [diff] [blame] | 675 | u32 *push, hue, vib; |
| 676 | int adj; |
| 677 | |
| 678 | adj = (nv_crtc->color_vibrance > 0) ? 50 : 0; |
| 679 | vib = ((nv_crtc->color_vibrance * 2047 + adj) / 100) & 0xfff; |
| 680 | hue = ((nv_crtc->vibrant_hue * 2047) / 100) & 0xfff; |
| 681 | |
| 682 | push = evo_wait(mast, 16); |
| 683 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 684 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | f9887d0 | 2012-11-21 13:03:42 +1000 | [diff] [blame] | 685 | evo_mthd(push, 0x08a8 + (nv_crtc->index * 0x400), 1); |
| 686 | evo_data(push, (hue << 20) | (vib << 8)); |
| 687 | } else { |
| 688 | evo_mthd(push, 0x0498 + (nv_crtc->index * 0x300), 1); |
| 689 | evo_data(push, (hue << 20) | (vib << 8)); |
| 690 | } |
| 691 | |
| 692 | if (update) { |
| 693 | evo_mthd(push, 0x0080, 1); |
| 694 | evo_data(push, 0x00000000); |
| 695 | } |
| 696 | evo_kick(push, mast); |
| 697 | } |
| 698 | |
| 699 | return 0; |
| 700 | } |
| 701 | |
| 702 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 703 | nv50_crtc_set_image(struct nouveau_crtc *nv_crtc, struct drm_framebuffer *fb, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 704 | int x, int y, bool update) |
| 705 | { |
| 706 | struct nouveau_framebuffer *nvfb = nouveau_framebuffer(fb); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 707 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 708 | u32 *push; |
| 709 | |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 710 | push = evo_wait(mast, 16); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 711 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 712 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 713 | evo_mthd(push, 0x0860 + (nv_crtc->index * 0x400), 1); |
| 714 | evo_data(push, nvfb->nvbo->bo.offset >> 8); |
| 715 | evo_mthd(push, 0x0868 + (nv_crtc->index * 0x400), 3); |
| 716 | evo_data(push, (fb->height << 16) | fb->width); |
| 717 | evo_data(push, nvfb->r_pitch); |
| 718 | evo_data(push, nvfb->r_format); |
| 719 | evo_mthd(push, 0x08c0 + (nv_crtc->index * 0x400), 1); |
| 720 | evo_data(push, (y << 16) | x); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 721 | if (nv50_vers(mast) > NV50_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 722 | evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1); |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 723 | evo_data(push, nvfb->r_handle); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 724 | } |
| 725 | } else { |
| 726 | evo_mthd(push, 0x0460 + (nv_crtc->index * 0x300), 1); |
| 727 | evo_data(push, nvfb->nvbo->bo.offset >> 8); |
| 728 | evo_mthd(push, 0x0468 + (nv_crtc->index * 0x300), 4); |
| 729 | evo_data(push, (fb->height << 16) | fb->width); |
| 730 | evo_data(push, nvfb->r_pitch); |
| 731 | evo_data(push, nvfb->r_format); |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 732 | evo_data(push, nvfb->r_handle); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 733 | evo_mthd(push, 0x04b0 + (nv_crtc->index * 0x300), 1); |
| 734 | evo_data(push, (y << 16) | x); |
| 735 | } |
| 736 | |
Ben Skeggs | a46232e | 2011-07-07 15:23:48 +1000 | [diff] [blame] | 737 | if (update) { |
| 738 | evo_mthd(push, 0x0080, 1); |
| 739 | evo_data(push, 0x00000000); |
| 740 | } |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 741 | evo_kick(push, mast); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 742 | } |
| 743 | |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 744 | nv_crtc->fb.handle = nvfb->r_handle; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 745 | return 0; |
| 746 | } |
| 747 | |
| 748 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 749 | nv50_crtc_cursor_show(struct nouveau_crtc *nv_crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 750 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 751 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 752 | u32 *push = evo_wait(mast, 16); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 753 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 754 | if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 755 | evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2); |
| 756 | evo_data(push, 0x85000000); |
| 757 | evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8); |
| 758 | } else |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 759 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 760 | evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 2); |
| 761 | evo_data(push, 0x85000000); |
| 762 | evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8); |
| 763 | evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1); |
| 764 | evo_data(push, NvEvoVRAM); |
| 765 | } else { |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 766 | evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 2); |
| 767 | evo_data(push, 0x85000000); |
| 768 | evo_data(push, nv_crtc->cursor.nvbo->bo.offset >> 8); |
| 769 | evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1); |
Ben Skeggs | 37b034a | 2011-07-08 14:43:19 +1000 | [diff] [blame] | 770 | evo_data(push, NvEvoVRAM); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 771 | } |
| 772 | evo_kick(push, mast); |
| 773 | } |
| 774 | } |
| 775 | |
| 776 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 777 | nv50_crtc_cursor_hide(struct nouveau_crtc *nv_crtc) |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 778 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 779 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 780 | u32 *push = evo_wait(mast, 16); |
| 781 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 782 | if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 783 | evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1); |
| 784 | evo_data(push, 0x05000000); |
| 785 | } else |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 786 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 787 | evo_mthd(push, 0x0880 + (nv_crtc->index * 0x400), 1); |
| 788 | evo_data(push, 0x05000000); |
| 789 | evo_mthd(push, 0x089c + (nv_crtc->index * 0x400), 1); |
| 790 | evo_data(push, 0x00000000); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 791 | } else { |
| 792 | evo_mthd(push, 0x0480 + (nv_crtc->index * 0x300), 1); |
| 793 | evo_data(push, 0x05000000); |
| 794 | evo_mthd(push, 0x048c + (nv_crtc->index * 0x300), 1); |
| 795 | evo_data(push, 0x00000000); |
| 796 | } |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 797 | evo_kick(push, mast); |
| 798 | } |
| 799 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 800 | |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 801 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 802 | nv50_crtc_cursor_show_hide(struct nouveau_crtc *nv_crtc, bool show, bool update) |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 803 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 804 | struct nv50_mast *mast = nv50_mast(nv_crtc->base.dev); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 805 | |
| 806 | if (show) |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 807 | nv50_crtc_cursor_show(nv_crtc); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 808 | else |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 809 | nv50_crtc_cursor_hide(nv_crtc); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 810 | |
| 811 | if (update) { |
| 812 | u32 *push = evo_wait(mast, 2); |
| 813 | if (push) { |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 814 | evo_mthd(push, 0x0080, 1); |
| 815 | evo_data(push, 0x00000000); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 816 | evo_kick(push, mast); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 817 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 818 | } |
| 819 | } |
| 820 | |
| 821 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 822 | nv50_crtc_dpms(struct drm_crtc *crtc, int mode) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 823 | { |
| 824 | } |
| 825 | |
| 826 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 827 | nv50_crtc_prepare(struct drm_crtc *crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 828 | { |
| 829 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 830 | struct nv50_mast *mast = nv50_mast(crtc->dev); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 831 | u32 *push; |
| 832 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 833 | nv50_display_flip_stop(crtc); |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 834 | |
Ben Skeggs | 56d237d | 2014-05-19 14:54:33 +1000 | [diff] [blame] | 835 | push = evo_wait(mast, 6); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 836 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 837 | if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 838 | evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1); |
| 839 | evo_data(push, 0x00000000); |
| 840 | evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1); |
| 841 | evo_data(push, 0x40000000); |
| 842 | } else |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 843 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 844 | evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1); |
| 845 | evo_data(push, 0x00000000); |
| 846 | evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 1); |
| 847 | evo_data(push, 0x40000000); |
| 848 | evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1); |
| 849 | evo_data(push, 0x00000000); |
| 850 | } else { |
| 851 | evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1); |
| 852 | evo_data(push, 0x00000000); |
| 853 | evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 1); |
| 854 | evo_data(push, 0x03000000); |
| 855 | evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1); |
| 856 | evo_data(push, 0x00000000); |
| 857 | } |
| 858 | |
| 859 | evo_kick(push, mast); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 860 | } |
| 861 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 862 | nv50_crtc_cursor_show_hide(nv_crtc, false, false); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 863 | } |
| 864 | |
| 865 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 866 | nv50_crtc_commit(struct drm_crtc *crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 867 | { |
| 868 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 869 | struct nv50_mast *mast = nv50_mast(crtc->dev); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 870 | u32 *push; |
| 871 | |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 872 | push = evo_wait(mast, 32); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 873 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 874 | if (nv50_vers(mast) < NV84_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 875 | evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1); |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 876 | evo_data(push, nv_crtc->fb.handle); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 877 | evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2); |
| 878 | evo_data(push, 0xc0000000); |
| 879 | evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8); |
| 880 | } else |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 881 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 882 | evo_mthd(push, 0x0874 + (nv_crtc->index * 0x400), 1); |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 883 | evo_data(push, nv_crtc->fb.handle); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 884 | evo_mthd(push, 0x0840 + (nv_crtc->index * 0x400), 2); |
| 885 | evo_data(push, 0xc0000000); |
| 886 | evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8); |
| 887 | evo_mthd(push, 0x085c + (nv_crtc->index * 0x400), 1); |
| 888 | evo_data(push, NvEvoVRAM); |
| 889 | } else { |
| 890 | evo_mthd(push, 0x0474 + (nv_crtc->index * 0x300), 1); |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 891 | evo_data(push, nv_crtc->fb.handle); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 892 | evo_mthd(push, 0x0440 + (nv_crtc->index * 0x300), 4); |
| 893 | evo_data(push, 0x83000000); |
| 894 | evo_data(push, nv_crtc->lut.nvbo->bo.offset >> 8); |
| 895 | evo_data(push, 0x00000000); |
| 896 | evo_data(push, 0x00000000); |
| 897 | evo_mthd(push, 0x045c + (nv_crtc->index * 0x300), 1); |
| 898 | evo_data(push, NvEvoVRAM); |
| 899 | evo_mthd(push, 0x0430 + (nv_crtc->index * 0x300), 1); |
| 900 | evo_data(push, 0xffffff00); |
| 901 | } |
| 902 | |
| 903 | evo_kick(push, mast); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 904 | } |
| 905 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 906 | nv50_crtc_cursor_show_hide(nv_crtc, nv_crtc->cursor.visible, true); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 907 | nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 908 | } |
| 909 | |
| 910 | static bool |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 911 | nv50_crtc_mode_fixup(struct drm_crtc *crtc, const struct drm_display_mode *mode, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 912 | struct drm_display_mode *adjusted_mode) |
| 913 | { |
Ben Skeggs | eb2e968 | 2014-01-24 10:13:23 +1000 | [diff] [blame] | 914 | drm_mode_set_crtcinfo(adjusted_mode, CRTC_INTERLACE_HALVE_V); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 915 | return true; |
| 916 | } |
| 917 | |
| 918 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 919 | nv50_crtc_swap_fbs(struct drm_crtc *crtc, struct drm_framebuffer *old_fb) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 920 | { |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 921 | struct nouveau_framebuffer *nvfb = nouveau_framebuffer(crtc->primary->fb); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 922 | struct nv50_head *head = nv50_head(crtc); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 923 | int ret; |
| 924 | |
| 925 | ret = nouveau_bo_pin(nvfb->nvbo, TTM_PL_FLAG_VRAM); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 926 | if (ret == 0) { |
| 927 | if (head->image) |
| 928 | nouveau_bo_unpin(head->image); |
| 929 | nouveau_bo_ref(nvfb->nvbo, &head->image); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 930 | } |
| 931 | |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 932 | return ret; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 933 | } |
| 934 | |
| 935 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 936 | nv50_crtc_mode_set(struct drm_crtc *crtc, struct drm_display_mode *umode, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 937 | struct drm_display_mode *mode, int x, int y, |
| 938 | struct drm_framebuffer *old_fb) |
| 939 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 940 | struct nv50_mast *mast = nv50_mast(crtc->dev); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 941 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 942 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 2d1d898 | 2011-11-11 23:39:22 +1000 | [diff] [blame] | 943 | u32 ilace = (mode->flags & DRM_MODE_FLAG_INTERLACE) ? 2 : 1; |
| 944 | u32 vscan = (mode->flags & DRM_MODE_FLAG_DBLSCAN) ? 2 : 1; |
| 945 | u32 hactive, hsynce, hbackp, hfrontp, hblanke, hblanks; |
| 946 | u32 vactive, vsynce, vbackp, vfrontp, vblanke, vblanks; |
| 947 | u32 vblan2e = 0, vblan2s = 1; |
Ben Skeggs | 3488c57 | 2012-03-12 11:42:20 +1000 | [diff] [blame] | 948 | u32 *push; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 949 | int ret; |
| 950 | |
Ben Skeggs | 2d1d898 | 2011-11-11 23:39:22 +1000 | [diff] [blame] | 951 | hactive = mode->htotal; |
| 952 | hsynce = mode->hsync_end - mode->hsync_start - 1; |
| 953 | hbackp = mode->htotal - mode->hsync_end; |
| 954 | hblanke = hsynce + hbackp; |
| 955 | hfrontp = mode->hsync_start - mode->hdisplay; |
| 956 | hblanks = mode->htotal - hfrontp - 1; |
| 957 | |
| 958 | vactive = mode->vtotal * vscan / ilace; |
| 959 | vsynce = ((mode->vsync_end - mode->vsync_start) * vscan / ilace) - 1; |
| 960 | vbackp = (mode->vtotal - mode->vsync_end) * vscan / ilace; |
| 961 | vblanke = vsynce + vbackp; |
| 962 | vfrontp = (mode->vsync_start - mode->vdisplay) * vscan / ilace; |
| 963 | vblanks = vactive - vfrontp - 1; |
| 964 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) { |
| 965 | vblan2e = vactive + vsynce + vbackp; |
| 966 | vblan2s = vblan2e + (mode->vdisplay * vscan / ilace); |
| 967 | vactive = (vactive * 2) + 1; |
Ben Skeggs | 2d1d898 | 2011-11-11 23:39:22 +1000 | [diff] [blame] | 968 | } |
| 969 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 970 | ret = nv50_crtc_swap_fbs(crtc, old_fb); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 971 | if (ret) |
| 972 | return ret; |
| 973 | |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 974 | push = evo_wait(mast, 64); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 975 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 976 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 977 | evo_mthd(push, 0x0804 + (nv_crtc->index * 0x400), 2); |
| 978 | evo_data(push, 0x00800000 | mode->clock); |
| 979 | evo_data(push, (ilace == 2) ? 2 : 0); |
| 980 | evo_mthd(push, 0x0810 + (nv_crtc->index * 0x400), 6); |
| 981 | evo_data(push, 0x00000000); |
| 982 | evo_data(push, (vactive << 16) | hactive); |
| 983 | evo_data(push, ( vsynce << 16) | hsynce); |
| 984 | evo_data(push, (vblanke << 16) | hblanke); |
| 985 | evo_data(push, (vblanks << 16) | hblanks); |
| 986 | evo_data(push, (vblan2e << 16) | vblan2s); |
| 987 | evo_mthd(push, 0x082c + (nv_crtc->index * 0x400), 1); |
| 988 | evo_data(push, 0x00000000); |
| 989 | evo_mthd(push, 0x0900 + (nv_crtc->index * 0x400), 2); |
| 990 | evo_data(push, 0x00000311); |
| 991 | evo_data(push, 0x00000100); |
| 992 | } else { |
| 993 | evo_mthd(push, 0x0410 + (nv_crtc->index * 0x300), 6); |
| 994 | evo_data(push, 0x00000000); |
| 995 | evo_data(push, (vactive << 16) | hactive); |
| 996 | evo_data(push, ( vsynce << 16) | hsynce); |
| 997 | evo_data(push, (vblanke << 16) | hblanke); |
| 998 | evo_data(push, (vblanks << 16) | hblanks); |
| 999 | evo_data(push, (vblan2e << 16) | vblan2s); |
| 1000 | evo_mthd(push, 0x042c + (nv_crtc->index * 0x300), 1); |
| 1001 | evo_data(push, 0x00000000); /* ??? */ |
| 1002 | evo_mthd(push, 0x0450 + (nv_crtc->index * 0x300), 3); |
| 1003 | evo_data(push, mode->clock * 1000); |
| 1004 | evo_data(push, 0x00200000); /* ??? */ |
| 1005 | evo_data(push, mode->clock * 1000); |
| 1006 | evo_mthd(push, 0x04d0 + (nv_crtc->index * 0x300), 2); |
| 1007 | evo_data(push, 0x00000311); |
| 1008 | evo_data(push, 0x00000100); |
| 1009 | } |
| 1010 | |
| 1011 | evo_kick(push, mast); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1012 | } |
| 1013 | |
| 1014 | nv_connector = nouveau_crtc_connector_get(nv_crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1015 | nv50_crtc_set_dither(nv_crtc, false); |
| 1016 | nv50_crtc_set_scale(nv_crtc, false); |
| 1017 | nv50_crtc_set_color_vibrance(nv_crtc, false); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1018 | nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, false); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1019 | return 0; |
| 1020 | } |
| 1021 | |
| 1022 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1023 | nv50_crtc_mode_set_base(struct drm_crtc *crtc, int x, int y, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1024 | struct drm_framebuffer *old_fb) |
| 1025 | { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1026 | struct nouveau_drm *drm = nouveau_drm(crtc->dev); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1027 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 1028 | int ret; |
| 1029 | |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1030 | if (!crtc->primary->fb) { |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1031 | NV_DEBUG(drm, "No FB bound\n"); |
Ben Skeggs | 84e2ad8 | 2011-08-26 09:40:39 +1000 | [diff] [blame] | 1032 | return 0; |
| 1033 | } |
| 1034 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1035 | ret = nv50_crtc_swap_fbs(crtc, old_fb); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1036 | if (ret) |
| 1037 | return ret; |
| 1038 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1039 | nv50_display_flip_stop(crtc); |
Matt Roper | f4510a2 | 2014-04-01 15:22:40 -0700 | [diff] [blame] | 1040 | nv50_crtc_set_image(nv_crtc, crtc->primary->fb, x, y, true); |
| 1041 | nv50_display_flip_next(crtc, crtc->primary->fb, NULL, 1); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1042 | return 0; |
| 1043 | } |
| 1044 | |
| 1045 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1046 | nv50_crtc_mode_set_base_atomic(struct drm_crtc *crtc, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1047 | struct drm_framebuffer *fb, int x, int y, |
| 1048 | enum mode_set_atomic state) |
| 1049 | { |
| 1050 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1051 | nv50_display_flip_stop(crtc); |
| 1052 | nv50_crtc_set_image(nv_crtc, fb, x, y, true); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1053 | return 0; |
| 1054 | } |
| 1055 | |
| 1056 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1057 | nv50_crtc_lut_load(struct drm_crtc *crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1058 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1059 | struct nv50_disp *disp = nv50_disp(crtc->dev); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1060 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 1061 | void __iomem *lut = nvbo_kmap_obj_iovirtual(nv_crtc->lut.nvbo); |
| 1062 | int i; |
| 1063 | |
| 1064 | for (i = 0; i < 256; i++) { |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 1065 | u16 r = nv_crtc->lut.r[i] >> 2; |
| 1066 | u16 g = nv_crtc->lut.g[i] >> 2; |
| 1067 | u16 b = nv_crtc->lut.b[i] >> 2; |
| 1068 | |
| 1069 | if (nv_mclass(disp->core) < NVD0_DISP_CLASS) { |
| 1070 | writew(r + 0x0000, lut + (i * 0x08) + 0); |
| 1071 | writew(g + 0x0000, lut + (i * 0x08) + 2); |
| 1072 | writew(b + 0x0000, lut + (i * 0x08) + 4); |
| 1073 | } else { |
| 1074 | writew(r + 0x6000, lut + (i * 0x20) + 0); |
| 1075 | writew(g + 0x6000, lut + (i * 0x20) + 2); |
| 1076 | writew(b + 0x6000, lut + (i * 0x20) + 4); |
| 1077 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1078 | } |
| 1079 | } |
| 1080 | |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 1081 | static void |
| 1082 | nv50_crtc_disable(struct drm_crtc *crtc) |
| 1083 | { |
| 1084 | struct nv50_head *head = nv50_head(crtc); |
Ben Skeggs | efa366f | 2014-06-05 12:56:35 +1000 | [diff] [blame] | 1085 | evo_sync(crtc->dev); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 1086 | if (head->image) |
| 1087 | nouveau_bo_unpin(head->image); |
| 1088 | nouveau_bo_ref(NULL, &head->image); |
| 1089 | } |
| 1090 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1091 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1092 | nv50_crtc_cursor_set(struct drm_crtc *crtc, struct drm_file *file_priv, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1093 | uint32_t handle, uint32_t width, uint32_t height) |
| 1094 | { |
| 1095 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
| 1096 | struct drm_device *dev = crtc->dev; |
| 1097 | struct drm_gem_object *gem; |
| 1098 | struct nouveau_bo *nvbo; |
| 1099 | bool visible = (handle != 0); |
| 1100 | int i, ret = 0; |
| 1101 | |
| 1102 | if (visible) { |
| 1103 | if (width != 64 || height != 64) |
| 1104 | return -EINVAL; |
| 1105 | |
| 1106 | gem = drm_gem_object_lookup(dev, file_priv, handle); |
| 1107 | if (unlikely(!gem)) |
| 1108 | return -ENOENT; |
| 1109 | nvbo = nouveau_gem_object(gem); |
| 1110 | |
| 1111 | ret = nouveau_bo_map(nvbo); |
| 1112 | if (ret == 0) { |
| 1113 | for (i = 0; i < 64 * 64; i++) { |
| 1114 | u32 v = nouveau_bo_rd32(nvbo, i); |
| 1115 | nouveau_bo_wr32(nv_crtc->cursor.nvbo, i, v); |
| 1116 | } |
| 1117 | nouveau_bo_unmap(nvbo); |
| 1118 | } |
| 1119 | |
| 1120 | drm_gem_object_unreference_unlocked(gem); |
| 1121 | } |
| 1122 | |
| 1123 | if (visible != nv_crtc->cursor.visible) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1124 | nv50_crtc_cursor_show_hide(nv_crtc, visible, true); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1125 | nv_crtc->cursor.visible = visible; |
| 1126 | } |
| 1127 | |
| 1128 | return ret; |
| 1129 | } |
| 1130 | |
| 1131 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1132 | nv50_crtc_cursor_move(struct drm_crtc *crtc, int x, int y) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1133 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1134 | struct nv50_curs *curs = nv50_curs(crtc); |
| 1135 | struct nv50_chan *chan = nv50_chan(curs); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1136 | nv_wo32(chan->user, 0x0084, (y << 16) | (x & 0xffff)); |
| 1137 | nv_wo32(chan->user, 0x0080, 0x00000000); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1138 | return 0; |
| 1139 | } |
| 1140 | |
| 1141 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1142 | nv50_crtc_gamma_set(struct drm_crtc *crtc, u16 *r, u16 *g, u16 *b, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1143 | uint32_t start, uint32_t size) |
| 1144 | { |
| 1145 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Dan Carpenter | bdefc8c | 2013-11-28 01:18:47 +0300 | [diff] [blame] | 1146 | u32 end = min_t(u32, start + size, 256); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1147 | u32 i; |
| 1148 | |
| 1149 | for (i = start; i < end; i++) { |
| 1150 | nv_crtc->lut.r[i] = r[i]; |
| 1151 | nv_crtc->lut.g[i] = g[i]; |
| 1152 | nv_crtc->lut.b[i] = b[i]; |
| 1153 | } |
| 1154 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1155 | nv50_crtc_lut_load(crtc); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1156 | } |
| 1157 | |
| 1158 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1159 | nv50_crtc_destroy(struct drm_crtc *crtc) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1160 | { |
| 1161 | struct nouveau_crtc *nv_crtc = nouveau_crtc(crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1162 | struct nv50_disp *disp = nv50_disp(crtc->dev); |
| 1163 | struct nv50_head *head = nv50_head(crtc); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 1164 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1165 | nv50_dmac_destroy(disp->core, &head->ovly.base); |
| 1166 | nv50_pioc_destroy(disp->core, &head->oimm.base); |
| 1167 | nv50_dmac_destroy(disp->core, &head->sync.base); |
| 1168 | nv50_pioc_destroy(disp->core, &head->curs.base); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 1169 | |
| 1170 | /*XXX: this shouldn't be necessary, but the core doesn't call |
| 1171 | * disconnect() during the cleanup paths |
| 1172 | */ |
| 1173 | if (head->image) |
| 1174 | nouveau_bo_unpin(head->image); |
| 1175 | nouveau_bo_ref(NULL, &head->image); |
| 1176 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1177 | nouveau_bo_unmap(nv_crtc->cursor.nvbo); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 1178 | if (nv_crtc->cursor.nvbo) |
| 1179 | nouveau_bo_unpin(nv_crtc->cursor.nvbo); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1180 | nouveau_bo_ref(NULL, &nv_crtc->cursor.nvbo); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 1181 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1182 | nouveau_bo_unmap(nv_crtc->lut.nvbo); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 1183 | if (nv_crtc->lut.nvbo) |
| 1184 | nouveau_bo_unpin(nv_crtc->lut.nvbo); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1185 | nouveau_bo_ref(NULL, &nv_crtc->lut.nvbo); |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 1186 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1187 | drm_crtc_cleanup(crtc); |
| 1188 | kfree(crtc); |
| 1189 | } |
| 1190 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1191 | static const struct drm_crtc_helper_funcs nv50_crtc_hfunc = { |
| 1192 | .dpms = nv50_crtc_dpms, |
| 1193 | .prepare = nv50_crtc_prepare, |
| 1194 | .commit = nv50_crtc_commit, |
| 1195 | .mode_fixup = nv50_crtc_mode_fixup, |
| 1196 | .mode_set = nv50_crtc_mode_set, |
| 1197 | .mode_set_base = nv50_crtc_mode_set_base, |
| 1198 | .mode_set_base_atomic = nv50_crtc_mode_set_base_atomic, |
| 1199 | .load_lut = nv50_crtc_lut_load, |
Ben Skeggs | 8dda53f | 2013-07-09 12:35:55 +1000 | [diff] [blame] | 1200 | .disable = nv50_crtc_disable, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1201 | }; |
| 1202 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1203 | static const struct drm_crtc_funcs nv50_crtc_func = { |
| 1204 | .cursor_set = nv50_crtc_cursor_set, |
| 1205 | .cursor_move = nv50_crtc_cursor_move, |
| 1206 | .gamma_set = nv50_crtc_gamma_set, |
Dave Airlie | 5addcf0 | 2012-09-10 14:20:51 +1000 | [diff] [blame] | 1207 | .set_config = nouveau_crtc_set_config, |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1208 | .destroy = nv50_crtc_destroy, |
Ben Skeggs | 3376ee3 | 2011-11-12 14:28:12 +1000 | [diff] [blame] | 1209 | .page_flip = nouveau_crtc_page_flip, |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1210 | }; |
| 1211 | |
Ben Skeggs | c20ab3e | 2011-08-25 14:09:43 +1000 | [diff] [blame] | 1212 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1213 | nv50_cursor_set_pos(struct nouveau_crtc *nv_crtc, int x, int y) |
Ben Skeggs | c20ab3e | 2011-08-25 14:09:43 +1000 | [diff] [blame] | 1214 | { |
| 1215 | } |
| 1216 | |
| 1217 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1218 | nv50_cursor_set_offset(struct nouveau_crtc *nv_crtc, uint32_t offset) |
Ben Skeggs | c20ab3e | 2011-08-25 14:09:43 +1000 | [diff] [blame] | 1219 | { |
| 1220 | } |
| 1221 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1222 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1223 | nv50_crtc_create(struct drm_device *dev, struct nouveau_object *core, int index) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1224 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1225 | struct nv50_disp *disp = nv50_disp(dev); |
| 1226 | struct nv50_head *head; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1227 | struct drm_crtc *crtc; |
| 1228 | int ret, i; |
| 1229 | |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1230 | head = kzalloc(sizeof(*head), GFP_KERNEL); |
| 1231 | if (!head) |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1232 | return -ENOMEM; |
| 1233 | |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1234 | head->base.index = index; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1235 | head->base.set_dither = nv50_crtc_set_dither; |
| 1236 | head->base.set_scale = nv50_crtc_set_scale; |
| 1237 | head->base.set_color_vibrance = nv50_crtc_set_color_vibrance; |
Ben Skeggs | f9887d0 | 2012-11-21 13:03:42 +1000 | [diff] [blame] | 1238 | head->base.color_vibrance = 50; |
| 1239 | head->base.vibrant_hue = 0; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1240 | head->base.cursor.set_offset = nv50_cursor_set_offset; |
| 1241 | head->base.cursor.set_pos = nv50_cursor_set_pos; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1242 | for (i = 0; i < 256; i++) { |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1243 | head->base.lut.r[i] = i << 8; |
| 1244 | head->base.lut.g[i] = i << 8; |
| 1245 | head->base.lut.b[i] = i << 8; |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1246 | } |
| 1247 | |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1248 | crtc = &head->base.base; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1249 | drm_crtc_init(dev, crtc, &nv50_crtc_func); |
| 1250 | drm_crtc_helper_add(crtc, &nv50_crtc_hfunc); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1251 | drm_mode_crtc_set_gamma_size(crtc, 256); |
| 1252 | |
Ben Skeggs | 8ea0d4a | 2011-07-07 14:49:24 +1000 | [diff] [blame] | 1253 | ret = nouveau_bo_new(dev, 8192, 0x100, TTM_PL_FLAG_VRAM, |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1254 | 0, 0x0000, NULL, &head->base.lut.nvbo); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1255 | if (!ret) { |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1256 | ret = nouveau_bo_pin(head->base.lut.nvbo, TTM_PL_FLAG_VRAM); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 1257 | if (!ret) { |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1258 | ret = nouveau_bo_map(head->base.lut.nvbo); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 1259 | if (ret) |
| 1260 | nouveau_bo_unpin(head->base.lut.nvbo); |
| 1261 | } |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1262 | if (ret) |
Ben Skeggs | dd0e3d5 | 2012-10-16 14:00:31 +1000 | [diff] [blame] | 1263 | nouveau_bo_ref(NULL, &head->base.lut.nvbo); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1264 | } |
| 1265 | |
| 1266 | if (ret) |
| 1267 | goto out; |
| 1268 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1269 | nv50_crtc_lut_load(crtc); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1270 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1271 | /* allocate cursor resources */ |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1272 | ret = nv50_pioc_create(disp->core, NV50_DISP_CURS_CLASS, index, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1273 | &(struct nv50_display_curs_class) { |
| 1274 | .head = index, |
| 1275 | }, sizeof(struct nv50_display_curs_class), |
| 1276 | &head->curs.base); |
| 1277 | if (ret) |
| 1278 | goto out; |
| 1279 | |
| 1280 | ret = nouveau_bo_new(dev, 64 * 64 * 4, 0x100, TTM_PL_FLAG_VRAM, |
| 1281 | 0, 0x0000, NULL, &head->base.cursor.nvbo); |
| 1282 | if (!ret) { |
| 1283 | ret = nouveau_bo_pin(head->base.cursor.nvbo, TTM_PL_FLAG_VRAM); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 1284 | if (!ret) { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1285 | ret = nouveau_bo_map(head->base.cursor.nvbo); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 1286 | if (ret) |
| 1287 | nouveau_bo_unpin(head->base.lut.nvbo); |
| 1288 | } |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1289 | if (ret) |
| 1290 | nouveau_bo_ref(NULL, &head->base.cursor.nvbo); |
| 1291 | } |
| 1292 | |
| 1293 | if (ret) |
| 1294 | goto out; |
| 1295 | |
| 1296 | /* allocate page flip / sync resources */ |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1297 | ret = nv50_dmac_create(disp->core, NV50_DISP_SYNC_CLASS, index, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1298 | &(struct nv50_display_sync_class) { |
| 1299 | .pushbuf = EVO_PUSH_HANDLE(SYNC, index), |
| 1300 | .head = index, |
| 1301 | }, sizeof(struct nv50_display_sync_class), |
| 1302 | disp->sync->bo.offset, &head->sync.base); |
| 1303 | if (ret) |
| 1304 | goto out; |
| 1305 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 1306 | head->sync.addr = EVO_FLIP_SEM0(index); |
| 1307 | head->sync.data = 0x00000000; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1308 | |
| 1309 | /* allocate overlay resources */ |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1310 | ret = nv50_pioc_create(disp->core, NV50_DISP_OIMM_CLASS, index, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1311 | &(struct nv50_display_oimm_class) { |
| 1312 | .head = index, |
| 1313 | }, sizeof(struct nv50_display_oimm_class), |
| 1314 | &head->oimm.base); |
| 1315 | if (ret) |
| 1316 | goto out; |
| 1317 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1318 | ret = nv50_dmac_create(disp->core, NV50_DISP_OVLY_CLASS, index, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 1319 | &(struct nv50_display_ovly_class) { |
| 1320 | .pushbuf = EVO_PUSH_HANDLE(OVLY, index), |
| 1321 | .head = index, |
| 1322 | }, sizeof(struct nv50_display_ovly_class), |
| 1323 | disp->sync->bo.offset, &head->ovly.base); |
| 1324 | if (ret) |
| 1325 | goto out; |
| 1326 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1327 | out: |
| 1328 | if (ret) |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1329 | nv50_crtc_destroy(crtc); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 1330 | return ret; |
| 1331 | } |
| 1332 | |
| 1333 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1334 | * DAC |
| 1335 | *****************************************************************************/ |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1336 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1337 | nv50_dac_dpms(struct drm_encoder *encoder, int mode) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1338 | { |
| 1339 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1340 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1341 | int or = nv_encoder->or; |
| 1342 | u32 dpms_ctrl; |
| 1343 | |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 1344 | dpms_ctrl = 0x00000000; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1345 | if (mode == DRM_MODE_DPMS_STANDBY || mode == DRM_MODE_DPMS_OFF) |
| 1346 | dpms_ctrl |= 0x00000001; |
| 1347 | if (mode == DRM_MODE_DPMS_SUSPEND || mode == DRM_MODE_DPMS_OFF) |
| 1348 | dpms_ctrl |= 0x00000004; |
| 1349 | |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 1350 | nv_call(disp->core, NV50_DISP_DAC_PWR + or, dpms_ctrl); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1351 | } |
| 1352 | |
| 1353 | static bool |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1354 | nv50_dac_mode_fixup(struct drm_encoder *encoder, |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 1355 | const struct drm_display_mode *mode, |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1356 | struct drm_display_mode *adjusted_mode) |
| 1357 | { |
| 1358 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1359 | struct nouveau_connector *nv_connector; |
| 1360 | |
| 1361 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 1362 | if (nv_connector && nv_connector->native_mode) { |
| 1363 | if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) { |
| 1364 | int id = adjusted_mode->base.id; |
| 1365 | *adjusted_mode = *nv_connector->native_mode; |
| 1366 | adjusted_mode->base.id = id; |
| 1367 | } |
| 1368 | } |
| 1369 | |
| 1370 | return true; |
| 1371 | } |
| 1372 | |
| 1373 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1374 | nv50_dac_commit(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1375 | { |
| 1376 | } |
| 1377 | |
| 1378 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1379 | nv50_dac_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1380 | struct drm_display_mode *adjusted_mode) |
| 1381 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1382 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1383 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1384 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1385 | u32 *push; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1386 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1387 | nv50_dac_dpms(encoder, DRM_MODE_DPMS_ON); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1388 | |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1389 | push = evo_wait(mast, 8); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1390 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1391 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1392 | u32 syncs = 0x00000000; |
| 1393 | |
| 1394 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 1395 | syncs |= 0x00000001; |
| 1396 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 1397 | syncs |= 0x00000002; |
| 1398 | |
| 1399 | evo_mthd(push, 0x0400 + (nv_encoder->or * 0x080), 2); |
| 1400 | evo_data(push, 1 << nv_crtc->index); |
| 1401 | evo_data(push, syncs); |
| 1402 | } else { |
| 1403 | u32 magic = 0x31ec6000 | (nv_crtc->index << 25); |
| 1404 | u32 syncs = 0x00000001; |
| 1405 | |
| 1406 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 1407 | syncs |= 0x00000008; |
| 1408 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 1409 | syncs |= 0x00000010; |
| 1410 | |
| 1411 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 1412 | magic |= 0x00000001; |
| 1413 | |
| 1414 | evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2); |
| 1415 | evo_data(push, syncs); |
| 1416 | evo_data(push, magic); |
| 1417 | evo_mthd(push, 0x0180 + (nv_encoder->or * 0x020), 1); |
| 1418 | evo_data(push, 1 << nv_crtc->index); |
| 1419 | } |
| 1420 | |
| 1421 | evo_kick(push, mast); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1422 | } |
| 1423 | |
| 1424 | nv_encoder->crtc = encoder->crtc; |
| 1425 | } |
| 1426 | |
| 1427 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1428 | nv50_dac_disconnect(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1429 | { |
| 1430 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1431 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1432 | const int or = nv_encoder->or; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1433 | u32 *push; |
| 1434 | |
| 1435 | if (nv_encoder->crtc) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1436 | nv50_crtc_prepare(nv_encoder->crtc); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1437 | |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1438 | push = evo_wait(mast, 4); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1439 | if (push) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1440 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1441 | evo_mthd(push, 0x0400 + (or * 0x080), 1); |
| 1442 | evo_data(push, 0x00000000); |
| 1443 | } else { |
| 1444 | evo_mthd(push, 0x0180 + (or * 0x020), 1); |
| 1445 | evo_data(push, 0x00000000); |
| 1446 | } |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1447 | evo_kick(push, mast); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1448 | } |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1449 | } |
Ben Skeggs | 97b19b5 | 2012-11-16 11:21:37 +1000 | [diff] [blame] | 1450 | |
| 1451 | nv_encoder->crtc = NULL; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1452 | } |
| 1453 | |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 1454 | static enum drm_connector_status |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1455 | nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector) |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 1456 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1457 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 1458 | int ret, or = nouveau_encoder(encoder)->or; |
Ben Skeggs | d40ee48 | 2013-06-03 16:40:14 +1000 | [diff] [blame] | 1459 | u32 load = nouveau_drm(encoder->dev)->vbios.dactestval; |
| 1460 | if (load == 0) |
| 1461 | load = 340; |
Ben Skeggs | b681993 | 2011-07-08 11:14:50 +1000 | [diff] [blame] | 1462 | |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 1463 | ret = nv_exec(disp->core, NV50_DISP_DAC_LOAD + or, &load, sizeof(load)); |
Ben Skeggs | 4b31ebc | 2013-09-04 11:01:42 +1000 | [diff] [blame] | 1464 | if (ret || !load) |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 1465 | return connector_status_disconnected; |
Ben Skeggs | b681993 | 2011-07-08 11:14:50 +1000 | [diff] [blame] | 1466 | |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 1467 | return connector_status_connected; |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 1468 | } |
| 1469 | |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1470 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1471 | nv50_dac_destroy(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1472 | { |
| 1473 | drm_encoder_cleanup(encoder); |
| 1474 | kfree(encoder); |
| 1475 | } |
| 1476 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1477 | static const struct drm_encoder_helper_funcs nv50_dac_hfunc = { |
| 1478 | .dpms = nv50_dac_dpms, |
| 1479 | .mode_fixup = nv50_dac_mode_fixup, |
| 1480 | .prepare = nv50_dac_disconnect, |
| 1481 | .commit = nv50_dac_commit, |
| 1482 | .mode_set = nv50_dac_mode_set, |
| 1483 | .disable = nv50_dac_disconnect, |
| 1484 | .get_crtc = nv50_display_crtc_get, |
| 1485 | .detect = nv50_dac_detect |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1486 | }; |
| 1487 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1488 | static const struct drm_encoder_funcs nv50_dac_func = { |
| 1489 | .destroy = nv50_dac_destroy, |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1490 | }; |
| 1491 | |
| 1492 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1493 | nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1494 | { |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1495 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame^] | 1496 | struct nouveau_i2c *i2c = nvkm_i2c(&drm->device); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1497 | struct nouveau_encoder *nv_encoder; |
| 1498 | struct drm_encoder *encoder; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1499 | int type = DRM_MODE_ENCODER_DAC; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1500 | |
| 1501 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 1502 | if (!nv_encoder) |
| 1503 | return -ENOMEM; |
| 1504 | nv_encoder->dcb = dcbe; |
| 1505 | nv_encoder->or = ffs(dcbe->or) - 1; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1506 | nv_encoder->i2c = i2c->find(i2c, dcbe->i2c_index); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1507 | |
| 1508 | encoder = to_drm_encoder(nv_encoder); |
| 1509 | encoder->possible_crtcs = dcbe->heads; |
| 1510 | encoder->possible_clones = 0; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1511 | drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1512 | drm_encoder_helper_add(encoder, &nv50_dac_hfunc); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 1513 | |
| 1514 | drm_mode_connector_attach_encoder(connector, encoder); |
| 1515 | return 0; |
| 1516 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1517 | |
| 1518 | /****************************************************************************** |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1519 | * Audio |
| 1520 | *****************************************************************************/ |
| 1521 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1522 | nv50_audio_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1523 | { |
| 1524 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1525 | struct nouveau_connector *nv_connector; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1526 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1527 | |
| 1528 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 1529 | if (!drm_detect_monitor_audio(nv_connector->edid)) |
| 1530 | return; |
| 1531 | |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1532 | drm_edid_to_eld(&nv_connector->base, nv_connector->edid); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1533 | |
Ben Skeggs | 0a9e2b95 | 2012-11-08 14:03:56 +1000 | [diff] [blame] | 1534 | nv_exec(disp->core, NVA3_DISP_SOR_HDA_ELD + nv_encoder->or, |
| 1535 | nv_connector->base.eld, |
| 1536 | nv_connector->base.eld[2] * 4); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1537 | } |
| 1538 | |
| 1539 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1540 | nv50_audio_disconnect(struct drm_encoder *encoder) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1541 | { |
| 1542 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1543 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1544 | |
Ben Skeggs | 0a9e2b95 | 2012-11-08 14:03:56 +1000 | [diff] [blame] | 1545 | nv_exec(disp->core, NVA3_DISP_SOR_HDA_ELD + nv_encoder->or, NULL, 0); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1546 | } |
| 1547 | |
| 1548 | /****************************************************************************** |
| 1549 | * HDMI |
| 1550 | *****************************************************************************/ |
| 1551 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1552 | nv50_hdmi_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1553 | { |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 1554 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1555 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
| 1556 | struct nouveau_connector *nv_connector; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1557 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 1c30cd0 | 2012-11-08 14:22:28 +1000 | [diff] [blame] | 1558 | const u32 moff = (nv_crtc->index << 3) | nv_encoder->or; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 1559 | u32 rekey = 56; /* binary driver, and tegra constant */ |
| 1560 | u32 max_ac_packet; |
| 1561 | |
| 1562 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 1563 | if (!drm_detect_hdmi_monitor(nv_connector->edid)) |
| 1564 | return; |
| 1565 | |
| 1566 | max_ac_packet = mode->htotal - mode->hdisplay; |
| 1567 | max_ac_packet -= rekey; |
| 1568 | max_ac_packet -= 18; /* constant from tegra */ |
| 1569 | max_ac_packet /= 32; |
| 1570 | |
Ben Skeggs | 1c30cd0 | 2012-11-08 14:22:28 +1000 | [diff] [blame] | 1571 | nv_call(disp->core, NV84_DISP_SOR_HDMI_PWR + moff, |
| 1572 | NV84_DISP_SOR_HDMI_PWR_STATE_ON | |
| 1573 | (max_ac_packet << 16) | rekey); |
Ben Skeggs | 091e40c | 2011-11-11 20:46:00 +1000 | [diff] [blame] | 1574 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1575 | nv50_audio_mode_set(encoder, mode); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1576 | } |
| 1577 | |
| 1578 | static void |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1579 | nv50_hdmi_disconnect(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1580 | { |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 1581 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1582 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 1c30cd0 | 2012-11-08 14:22:28 +1000 | [diff] [blame] | 1583 | const u32 moff = (nv_crtc->index << 3) | nv_encoder->or; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 1584 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1585 | nv50_audio_disconnect(encoder); |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 1586 | |
Ben Skeggs | 1c30cd0 | 2012-11-08 14:22:28 +1000 | [diff] [blame] | 1587 | nv_call(disp->core, NV84_DISP_SOR_HDMI_PWR + moff, 0x00000000); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1588 | } |
| 1589 | |
| 1590 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1591 | * SOR |
| 1592 | *****************************************************************************/ |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1593 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1594 | nv50_sor_dpms(struct drm_encoder *encoder, int mode) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1595 | { |
| 1596 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1597 | struct drm_device *dev = encoder->dev; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1598 | struct nv50_disp *disp = nv50_disp(dev); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1599 | struct drm_encoder *partner; |
Ben Skeggs | 4874322 | 2014-05-31 01:48:06 +1000 | [diff] [blame] | 1600 | u32 mthd; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1601 | |
| 1602 | nv_encoder->last_dpms = mode; |
| 1603 | |
| 1604 | list_for_each_entry(partner, &dev->mode_config.encoder_list, head) { |
| 1605 | struct nouveau_encoder *nv_partner = nouveau_encoder(partner); |
| 1606 | |
| 1607 | if (partner->encoder_type != DRM_MODE_ENCODER_TMDS) |
| 1608 | continue; |
| 1609 | |
| 1610 | if (nv_partner != nv_encoder && |
Ben Skeggs | 26cfa81 | 2011-11-17 09:10:02 +1000 | [diff] [blame] | 1611 | nv_partner->dcb->or == nv_encoder->dcb->or) { |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1612 | if (nv_partner->last_dpms == DRM_MODE_DPMS_ON) |
| 1613 | return; |
| 1614 | break; |
| 1615 | } |
| 1616 | } |
| 1617 | |
Ben Skeggs | 276e526 | 2014-06-30 11:10:02 +1000 | [diff] [blame] | 1618 | mthd = (ffs(nv_encoder->dcb->heads) - 1) << 3; |
| 1619 | mthd |= (ffs(nv_encoder->dcb->sorconf.link) - 1) << 2; |
Ben Skeggs | 4874322 | 2014-05-31 01:48:06 +1000 | [diff] [blame] | 1620 | mthd |= nv_encoder->or; |
| 1621 | |
| 1622 | if (nv_encoder->dcb->type == DCB_OUTPUT_DP) { |
| 1623 | nv_call(disp->core, NV50_DISP_SOR_PWR | mthd, 1); |
| 1624 | mthd |= NV94_DISP_SOR_DP_PWR; |
| 1625 | } else { |
| 1626 | mthd |= NV50_DISP_SOR_PWR; |
| 1627 | } |
| 1628 | |
| 1629 | nv_call(disp->core, mthd, (mode == DRM_MODE_DPMS_ON)); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1630 | } |
| 1631 | |
| 1632 | static bool |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1633 | nv50_sor_mode_fixup(struct drm_encoder *encoder, |
Laurent Pinchart | e811f5a | 2012-07-17 17:56:50 +0200 | [diff] [blame] | 1634 | const struct drm_display_mode *mode, |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1635 | struct drm_display_mode *adjusted_mode) |
| 1636 | { |
| 1637 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1638 | struct nouveau_connector *nv_connector; |
| 1639 | |
| 1640 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 1641 | if (nv_connector && nv_connector->native_mode) { |
| 1642 | if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) { |
| 1643 | int id = adjusted_mode->base.id; |
| 1644 | *adjusted_mode = *nv_connector->native_mode; |
| 1645 | adjusted_mode->base.id = id; |
| 1646 | } |
| 1647 | } |
| 1648 | |
| 1649 | return true; |
| 1650 | } |
| 1651 | |
| 1652 | static void |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1653 | nv50_sor_ctrl(struct nouveau_encoder *nv_encoder, u32 mask, u32 data) |
| 1654 | { |
| 1655 | struct nv50_mast *mast = nv50_mast(nv_encoder->base.base.dev); |
| 1656 | u32 temp = (nv_encoder->ctrl & ~mask) | (data & mask), *push; |
| 1657 | if (temp != nv_encoder->ctrl && (push = evo_wait(mast, 2))) { |
| 1658 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
| 1659 | evo_mthd(push, 0x0600 + (nv_encoder->or * 0x40), 1); |
| 1660 | evo_data(push, (nv_encoder->ctrl = temp)); |
| 1661 | } else { |
| 1662 | evo_mthd(push, 0x0200 + (nv_encoder->or * 0x20), 1); |
| 1663 | evo_data(push, (nv_encoder->ctrl = temp)); |
| 1664 | } |
| 1665 | evo_kick(push, mast); |
| 1666 | } |
| 1667 | } |
| 1668 | |
| 1669 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1670 | nv50_sor_disconnect(struct drm_encoder *encoder) |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 1671 | { |
| 1672 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1673 | struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc); |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1674 | |
| 1675 | nv_encoder->last_dpms = DRM_MODE_DPMS_OFF; |
| 1676 | nv_encoder->crtc = NULL; |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1677 | |
| 1678 | if (nv_crtc) { |
| 1679 | nv50_crtc_prepare(&nv_crtc->base); |
| 1680 | nv50_sor_ctrl(nv_encoder, 1 << nv_crtc->index, 0); |
| 1681 | nv50_hdmi_disconnect(&nv_encoder->base.base, nv_crtc); |
| 1682 | } |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 1683 | } |
| 1684 | |
| 1685 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1686 | nv50_sor_commit(struct drm_encoder *encoder) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1687 | { |
| 1688 | } |
| 1689 | |
| 1690 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1691 | nv50_sor_mode_set(struct drm_encoder *encoder, struct drm_display_mode *umode, |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1692 | struct drm_display_mode *mode) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1693 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1694 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
| 1695 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1696 | struct drm_device *dev = encoder->dev; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1697 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1698 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1699 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1700 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1701 | struct nvbios *bios = &drm->vbios; |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1702 | u32 lvds = 0, mask, ctrl; |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1703 | u8 owner = 1 << nv_crtc->index; |
| 1704 | u8 proto = 0xf; |
| 1705 | u8 depth = 0x0; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1706 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1707 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1708 | nv_encoder->crtc = encoder->crtc; |
| 1709 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1710 | switch (nv_encoder->dcb->type) { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 1711 | case DCB_OUTPUT_TMDS: |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1712 | if (nv_encoder->dcb->sorconf.link & 1) { |
| 1713 | if (mode->clock < 165000) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1714 | proto = 0x1; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1715 | else |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1716 | proto = 0x5; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1717 | } else { |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1718 | proto = 0x2; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1719 | } |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1720 | |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1721 | nv50_hdmi_mode_set(&nv_encoder->base.base, mode); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1722 | break; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 1723 | case DCB_OUTPUT_LVDS: |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1724 | proto = 0x0; |
| 1725 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1726 | if (bios->fp_no_ddc) { |
| 1727 | if (bios->fp.dual_link) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1728 | lvds |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1729 | if (bios->fp.if_is_24bit) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1730 | lvds |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1731 | } else { |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 1732 | if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) { |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1733 | if (((u8 *)nv_connector->edid)[121] == 2) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1734 | lvds |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1735 | } else |
| 1736 | if (mode->clock >= bios->fp.duallink_transition_clk) { |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1737 | lvds |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1738 | } |
| 1739 | |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1740 | if (lvds & 0x0100) { |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1741 | if (bios->fp.strapless_is_24bit & 2) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1742 | lvds |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1743 | } else { |
| 1744 | if (bios->fp.strapless_is_24bit & 1) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1745 | lvds |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1746 | } |
| 1747 | |
| 1748 | if (nv_connector->base.display_info.bpc == 8) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1749 | lvds |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1750 | } |
Ben Skeggs | 4a230fa | 2012-11-09 11:25:37 +1000 | [diff] [blame] | 1751 | |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1752 | nv_call(disp->core, NV50_DISP_SOR_LVDS_SCRIPT + nv_encoder->or, lvds); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1753 | break; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 1754 | case DCB_OUTPUT_DP: |
Ben Skeggs | 3488c57 | 2012-03-12 11:42:20 +1000 | [diff] [blame] | 1755 | if (nv_connector->base.display_info.bpc == 6) { |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1756 | nv_encoder->dp.datarate = mode->clock * 18 / 8; |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1757 | depth = 0x2; |
Ben Skeggs | bf2c886 | 2012-11-21 14:49:54 +1000 | [diff] [blame] | 1758 | } else |
| 1759 | if (nv_connector->base.display_info.bpc == 8) { |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1760 | nv_encoder->dp.datarate = mode->clock * 24 / 8; |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1761 | depth = 0x5; |
Ben Skeggs | bf2c886 | 2012-11-21 14:49:54 +1000 | [diff] [blame] | 1762 | } else { |
| 1763 | nv_encoder->dp.datarate = mode->clock * 30 / 8; |
| 1764 | depth = 0x6; |
Ben Skeggs | 3488c57 | 2012-03-12 11:42:20 +1000 | [diff] [blame] | 1765 | } |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1766 | |
| 1767 | if (nv_encoder->dcb->sorconf.link & 1) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1768 | proto = 0x8; |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1769 | else |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1770 | proto = 0x9; |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1771 | break; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1772 | default: |
| 1773 | BUG_ON(1); |
| 1774 | break; |
| 1775 | } |
Ben Skeggs | ff8ff50 | 2011-07-08 11:53:37 +1000 | [diff] [blame] | 1776 | |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1777 | nv50_sor_dpms(&nv_encoder->base.base, DRM_MODE_DPMS_ON); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1778 | |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1779 | if (nv50_vers(mast) >= NVD0_DISP_CLASS) { |
| 1780 | u32 *push = evo_wait(mast, 3); |
| 1781 | if (push) { |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1782 | u32 magic = 0x31ec6000 | (nv_crtc->index << 25); |
| 1783 | u32 syncs = 0x00000001; |
| 1784 | |
| 1785 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 1786 | syncs |= 0x00000008; |
| 1787 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 1788 | syncs |= 0x00000010; |
| 1789 | |
| 1790 | if (mode->flags & DRM_MODE_FLAG_INTERLACE) |
| 1791 | magic |= 0x00000001; |
| 1792 | |
| 1793 | evo_mthd(push, 0x0404 + (nv_crtc->index * 0x300), 2); |
| 1794 | evo_data(push, syncs | (depth << 6)); |
| 1795 | evo_data(push, magic); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1796 | evo_kick(push, mast); |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1797 | } |
| 1798 | |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1799 | ctrl = proto << 8; |
| 1800 | mask = 0x00000f00; |
| 1801 | } else { |
| 1802 | ctrl = (depth << 16) | (proto << 8); |
| 1803 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 1804 | ctrl |= 0x00001000; |
| 1805 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 1806 | ctrl |= 0x00002000; |
| 1807 | mask = 0x000f3f00; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1808 | } |
| 1809 | |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1810 | nv50_sor_ctrl(nv_encoder, mask | owner, ctrl | owner); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1811 | } |
| 1812 | |
| 1813 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1814 | nv50_sor_destroy(struct drm_encoder *encoder) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1815 | { |
| 1816 | drm_encoder_cleanup(encoder); |
| 1817 | kfree(encoder); |
| 1818 | } |
| 1819 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1820 | static const struct drm_encoder_helper_funcs nv50_sor_hfunc = { |
| 1821 | .dpms = nv50_sor_dpms, |
| 1822 | .mode_fixup = nv50_sor_mode_fixup, |
Ben Skeggs | 5a885f0 | 2013-02-20 14:34:18 +1000 | [diff] [blame] | 1823 | .prepare = nv50_sor_disconnect, |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1824 | .commit = nv50_sor_commit, |
| 1825 | .mode_set = nv50_sor_mode_set, |
| 1826 | .disable = nv50_sor_disconnect, |
| 1827 | .get_crtc = nv50_display_crtc_get, |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1828 | }; |
| 1829 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1830 | static const struct drm_encoder_funcs nv50_sor_func = { |
| 1831 | .destroy = nv50_sor_destroy, |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1832 | }; |
| 1833 | |
| 1834 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1835 | nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1836 | { |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1837 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame^] | 1838 | struct nouveau_i2c *i2c = nvkm_i2c(&drm->device); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1839 | struct nouveau_encoder *nv_encoder; |
| 1840 | struct drm_encoder *encoder; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1841 | int type; |
| 1842 | |
| 1843 | switch (dcbe->type) { |
| 1844 | case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break; |
| 1845 | case DCB_OUTPUT_TMDS: |
| 1846 | case DCB_OUTPUT_DP: |
| 1847 | default: |
| 1848 | type = DRM_MODE_ENCODER_TMDS; |
| 1849 | break; |
| 1850 | } |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1851 | |
| 1852 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 1853 | if (!nv_encoder) |
| 1854 | return -ENOMEM; |
| 1855 | nv_encoder->dcb = dcbe; |
| 1856 | nv_encoder->or = ffs(dcbe->or) - 1; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1857 | nv_encoder->i2c = i2c->find(i2c, dcbe->i2c_index); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1858 | nv_encoder->last_dpms = DRM_MODE_DPMS_OFF; |
| 1859 | |
| 1860 | encoder = to_drm_encoder(nv_encoder); |
| 1861 | encoder->possible_crtcs = dcbe->heads; |
| 1862 | encoder->possible_clones = 0; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1863 | drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1864 | drm_encoder_helper_add(encoder, &nv50_sor_hfunc); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1865 | |
| 1866 | drm_mode_connector_attach_encoder(connector, encoder); |
| 1867 | return 0; |
| 1868 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1869 | |
| 1870 | /****************************************************************************** |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1871 | * PIOR |
| 1872 | *****************************************************************************/ |
| 1873 | |
| 1874 | static void |
| 1875 | nv50_pior_dpms(struct drm_encoder *encoder, int mode) |
| 1876 | { |
| 1877 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1878 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
| 1879 | u32 mthd = (nv_encoder->dcb->type << 12) | nv_encoder->or; |
| 1880 | u32 ctrl = (mode == DRM_MODE_DPMS_ON); |
| 1881 | nv_call(disp->core, NV50_DISP_PIOR_PWR + mthd, ctrl); |
| 1882 | } |
| 1883 | |
| 1884 | static bool |
| 1885 | nv50_pior_mode_fixup(struct drm_encoder *encoder, |
| 1886 | const struct drm_display_mode *mode, |
| 1887 | struct drm_display_mode *adjusted_mode) |
| 1888 | { |
| 1889 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1890 | struct nouveau_connector *nv_connector; |
| 1891 | |
| 1892 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 1893 | if (nv_connector && nv_connector->native_mode) { |
| 1894 | if (nv_connector->scaling_mode != DRM_MODE_SCALE_NONE) { |
| 1895 | int id = adjusted_mode->base.id; |
| 1896 | *adjusted_mode = *nv_connector->native_mode; |
| 1897 | adjusted_mode->base.id = id; |
| 1898 | } |
| 1899 | } |
| 1900 | |
| 1901 | adjusted_mode->clock *= 2; |
| 1902 | return true; |
| 1903 | } |
| 1904 | |
| 1905 | static void |
| 1906 | nv50_pior_commit(struct drm_encoder *encoder) |
| 1907 | { |
| 1908 | } |
| 1909 | |
| 1910 | static void |
| 1911 | nv50_pior_mode_set(struct drm_encoder *encoder, struct drm_display_mode *mode, |
| 1912 | struct drm_display_mode *adjusted_mode) |
| 1913 | { |
| 1914 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
| 1915 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1916 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
| 1917 | struct nouveau_connector *nv_connector; |
| 1918 | u8 owner = 1 << nv_crtc->index; |
| 1919 | u8 proto, depth; |
| 1920 | u32 *push; |
| 1921 | |
| 1922 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 1923 | switch (nv_connector->base.display_info.bpc) { |
| 1924 | case 10: depth = 0x6; break; |
| 1925 | case 8: depth = 0x5; break; |
| 1926 | case 6: depth = 0x2; break; |
| 1927 | default: depth = 0x0; break; |
| 1928 | } |
| 1929 | |
| 1930 | switch (nv_encoder->dcb->type) { |
| 1931 | case DCB_OUTPUT_TMDS: |
| 1932 | case DCB_OUTPUT_DP: |
| 1933 | proto = 0x0; |
| 1934 | break; |
| 1935 | default: |
| 1936 | BUG_ON(1); |
| 1937 | break; |
| 1938 | } |
| 1939 | |
| 1940 | nv50_pior_dpms(encoder, DRM_MODE_DPMS_ON); |
| 1941 | |
| 1942 | push = evo_wait(mast, 8); |
| 1943 | if (push) { |
| 1944 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
| 1945 | u32 ctrl = (depth << 16) | (proto << 8) | owner; |
| 1946 | if (mode->flags & DRM_MODE_FLAG_NHSYNC) |
| 1947 | ctrl |= 0x00001000; |
| 1948 | if (mode->flags & DRM_MODE_FLAG_NVSYNC) |
| 1949 | ctrl |= 0x00002000; |
| 1950 | evo_mthd(push, 0x0700 + (nv_encoder->or * 0x040), 1); |
| 1951 | evo_data(push, ctrl); |
| 1952 | } |
| 1953 | |
| 1954 | evo_kick(push, mast); |
| 1955 | } |
| 1956 | |
| 1957 | nv_encoder->crtc = encoder->crtc; |
| 1958 | } |
| 1959 | |
| 1960 | static void |
| 1961 | nv50_pior_disconnect(struct drm_encoder *encoder) |
| 1962 | { |
| 1963 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1964 | struct nv50_mast *mast = nv50_mast(encoder->dev); |
| 1965 | const int or = nv_encoder->or; |
| 1966 | u32 *push; |
| 1967 | |
| 1968 | if (nv_encoder->crtc) { |
| 1969 | nv50_crtc_prepare(nv_encoder->crtc); |
| 1970 | |
| 1971 | push = evo_wait(mast, 4); |
| 1972 | if (push) { |
| 1973 | if (nv50_vers(mast) < NVD0_DISP_MAST_CLASS) { |
| 1974 | evo_mthd(push, 0x0700 + (or * 0x040), 1); |
| 1975 | evo_data(push, 0x00000000); |
| 1976 | } |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1977 | evo_kick(push, mast); |
| 1978 | } |
| 1979 | } |
| 1980 | |
| 1981 | nv_encoder->crtc = NULL; |
| 1982 | } |
| 1983 | |
| 1984 | static void |
| 1985 | nv50_pior_destroy(struct drm_encoder *encoder) |
| 1986 | { |
| 1987 | drm_encoder_cleanup(encoder); |
| 1988 | kfree(encoder); |
| 1989 | } |
| 1990 | |
| 1991 | static const struct drm_encoder_helper_funcs nv50_pior_hfunc = { |
| 1992 | .dpms = nv50_pior_dpms, |
| 1993 | .mode_fixup = nv50_pior_mode_fixup, |
| 1994 | .prepare = nv50_pior_disconnect, |
| 1995 | .commit = nv50_pior_commit, |
| 1996 | .mode_set = nv50_pior_mode_set, |
| 1997 | .disable = nv50_pior_disconnect, |
| 1998 | .get_crtc = nv50_display_crtc_get, |
| 1999 | }; |
| 2000 | |
| 2001 | static const struct drm_encoder_funcs nv50_pior_func = { |
| 2002 | .destroy = nv50_pior_destroy, |
| 2003 | }; |
| 2004 | |
| 2005 | static int |
| 2006 | nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe) |
| 2007 | { |
| 2008 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame^] | 2009 | struct nouveau_i2c *i2c = nvkm_i2c(&drm->device); |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 2010 | struct nouveau_i2c_port *ddc = NULL; |
| 2011 | struct nouveau_encoder *nv_encoder; |
| 2012 | struct drm_encoder *encoder; |
| 2013 | int type; |
| 2014 | |
| 2015 | switch (dcbe->type) { |
| 2016 | case DCB_OUTPUT_TMDS: |
| 2017 | ddc = i2c->find_type(i2c, NV_I2C_TYPE_EXTDDC(dcbe->extdev)); |
| 2018 | type = DRM_MODE_ENCODER_TMDS; |
| 2019 | break; |
| 2020 | case DCB_OUTPUT_DP: |
| 2021 | ddc = i2c->find_type(i2c, NV_I2C_TYPE_EXTAUX(dcbe->extdev)); |
| 2022 | type = DRM_MODE_ENCODER_TMDS; |
| 2023 | break; |
| 2024 | default: |
| 2025 | return -ENODEV; |
| 2026 | } |
| 2027 | |
| 2028 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 2029 | if (!nv_encoder) |
| 2030 | return -ENOMEM; |
| 2031 | nv_encoder->dcb = dcbe; |
| 2032 | nv_encoder->or = ffs(dcbe->or) - 1; |
| 2033 | nv_encoder->i2c = ddc; |
| 2034 | |
| 2035 | encoder = to_drm_encoder(nv_encoder); |
| 2036 | encoder->possible_crtcs = dcbe->heads; |
| 2037 | encoder->possible_clones = 0; |
| 2038 | drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type); |
| 2039 | drm_encoder_helper_add(encoder, &nv50_pior_hfunc); |
| 2040 | |
| 2041 | drm_mode_connector_attach_encoder(connector, encoder); |
| 2042 | return 0; |
| 2043 | } |
| 2044 | |
| 2045 | /****************************************************************************** |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2046 | * Framebuffer |
| 2047 | *****************************************************************************/ |
| 2048 | |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2049 | struct nv50_fbdma { |
| 2050 | struct list_head head; |
| 2051 | u32 name; |
| 2052 | }; |
| 2053 | |
| 2054 | static void |
| 2055 | nv50_fbdma_fini(struct drm_device *dev, struct nv50_fbdma *fbdma) |
| 2056 | { |
| 2057 | struct nv50_disp *disp = nv50_disp(dev); |
| 2058 | struct nv50_mast *mast = nv50_mast(dev); |
| 2059 | struct nouveau_object *client = nv_pclass(disp->core, NV_CLIENT_CLASS); |
| 2060 | struct drm_crtc *crtc; |
| 2061 | |
| 2062 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 2063 | struct nv50_sync *sync = nv50_sync(crtc); |
| 2064 | nouveau_object_del(client, sync->base.base.handle, fbdma->name); |
| 2065 | } |
| 2066 | |
| 2067 | nouveau_object_del(client, mast->base.base.handle, fbdma->name); |
| 2068 | list_del(&fbdma->head); |
| 2069 | kfree(fbdma); |
| 2070 | } |
| 2071 | |
| 2072 | static int |
| 2073 | nv50_fbdma_init(struct drm_device *dev, u32 name, u64 offset, u64 length, u8 kind) |
| 2074 | { |
| 2075 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 2076 | struct nv50_disp *disp = nv50_disp(dev); |
| 2077 | struct nv50_mast *mast = nv50_mast(dev); |
| 2078 | struct nouveau_object *client = nv_pclass(disp->core, NV_CLIENT_CLASS); |
| 2079 | struct nouveau_object *object; |
| 2080 | struct nv_dma_class args; |
| 2081 | struct nv50_fbdma *fbdma; |
| 2082 | struct drm_crtc *crtc; |
| 2083 | int ret; |
| 2084 | |
| 2085 | list_for_each_entry(fbdma, &disp->fbdma, head) { |
| 2086 | if (fbdma->name == name) |
| 2087 | return 0; |
| 2088 | } |
| 2089 | |
| 2090 | fbdma = kzalloc(sizeof(*fbdma), GFP_KERNEL); |
| 2091 | if (!fbdma) |
| 2092 | return -ENOMEM; |
| 2093 | list_add(&fbdma->head, &disp->fbdma); |
| 2094 | fbdma->name = name; |
| 2095 | |
| 2096 | args.flags = NV_DMA_TARGET_VRAM | NV_DMA_ACCESS_RDWR; |
| 2097 | args.start = offset; |
| 2098 | args.limit = offset + length - 1; |
| 2099 | args.conf0 = kind; |
| 2100 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame^] | 2101 | if (drm->device.info.chipset < 0x80) { |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2102 | args.conf0 = NV50_DMA_CONF0_ENABLE; |
| 2103 | args.conf0 |= NV50_DMA_CONF0_PART_256; |
| 2104 | } else |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame^] | 2105 | if (drm->device.info.chipset < 0xc0) { |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2106 | args.conf0 |= NV50_DMA_CONF0_ENABLE; |
| 2107 | args.conf0 |= NV50_DMA_CONF0_PART_256; |
| 2108 | } else |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame^] | 2109 | if (drm->device.info.chipset < 0xd0) { |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2110 | args.conf0 |= NVC0_DMA_CONF0_ENABLE; |
| 2111 | } else { |
| 2112 | args.conf0 |= NVD0_DMA_CONF0_ENABLE; |
| 2113 | args.conf0 |= NVD0_DMA_CONF0_PAGE_LP; |
| 2114 | } |
| 2115 | |
| 2116 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 2117 | struct nv50_sync *sync = nv50_sync(crtc); |
| 2118 | ret = nouveau_object_new(client, sync->base.base.handle, |
| 2119 | fbdma->name, NV_DMA_IN_MEMORY_CLASS, |
| 2120 | &args, sizeof(args), &object); |
| 2121 | if (ret) { |
| 2122 | printk(KERN_ERR "fail %d %08x %d\n", nv50_head(crtc)->base.index, fbdma->name, ret); |
| 2123 | nv50_fbdma_fini(dev, fbdma); |
| 2124 | return ret; |
| 2125 | } |
| 2126 | } |
| 2127 | |
| 2128 | ret = nouveau_object_new(client, mast->base.base.handle, fbdma->name, |
| 2129 | NV_DMA_IN_MEMORY_CLASS, &args, sizeof(args), |
| 2130 | &object); |
| 2131 | if (ret) { |
| 2132 | printk(KERN_ERR "fail %08x %d\n", fbdma->name, ret); |
| 2133 | nv50_fbdma_fini(dev, fbdma); |
| 2134 | return ret; |
| 2135 | } |
| 2136 | |
| 2137 | return 0; |
| 2138 | } |
| 2139 | |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2140 | static void |
| 2141 | nv50_fb_dtor(struct drm_framebuffer *fb) |
| 2142 | { |
| 2143 | } |
| 2144 | |
| 2145 | static int |
| 2146 | nv50_fb_ctor(struct drm_framebuffer *fb) |
| 2147 | { |
| 2148 | struct nouveau_framebuffer *nv_fb = nouveau_framebuffer(fb); |
| 2149 | struct nouveau_drm *drm = nouveau_drm(fb->dev); |
| 2150 | struct nouveau_bo *nvbo = nv_fb->nvbo; |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2151 | struct nv50_disp *disp = nv50_disp(fb->dev); |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame^] | 2152 | struct nouveau_fb *pfb = nvkm_fb(&drm->device); |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2153 | u8 kind = nouveau_bo_tile_layout(nvbo) >> 8; |
| 2154 | u8 tile = nvbo->tile_mode; |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2155 | |
| 2156 | if (nvbo->tile_flags & NOUVEAU_GEM_TILE_NONCONTIG) { |
| 2157 | NV_ERROR(drm, "framebuffer requires contiguous bo\n"); |
| 2158 | return -EINVAL; |
| 2159 | } |
| 2160 | |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame^] | 2161 | if (drm->device.info.chipset >= 0xc0) |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2162 | tile >>= 4; /* yep.. */ |
| 2163 | |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2164 | switch (fb->depth) { |
| 2165 | case 8: nv_fb->r_format = 0x1e00; break; |
| 2166 | case 15: nv_fb->r_format = 0xe900; break; |
| 2167 | case 16: nv_fb->r_format = 0xe800; break; |
| 2168 | case 24: |
| 2169 | case 32: nv_fb->r_format = 0xcf00; break; |
| 2170 | case 30: nv_fb->r_format = 0xd100; break; |
| 2171 | default: |
| 2172 | NV_ERROR(drm, "unknown depth %d\n", fb->depth); |
| 2173 | return -EINVAL; |
| 2174 | } |
| 2175 | |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2176 | if (nv_mclass(disp->core) < NV84_DISP_CLASS) { |
| 2177 | nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) : |
| 2178 | (fb->pitches[0] | 0x00100000); |
| 2179 | nv_fb->r_format |= kind << 16; |
| 2180 | } else |
| 2181 | if (nv_mclass(disp->core) < NVD0_DISP_CLASS) { |
| 2182 | nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) : |
| 2183 | (fb->pitches[0] | 0x00100000); |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2184 | } else { |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2185 | nv_fb->r_pitch = kind ? (((fb->pitches[0] / 4) << 4) | tile) : |
| 2186 | (fb->pitches[0] | 0x01000000); |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2187 | } |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2188 | nv_fb->r_handle = 0xffff0000 | kind; |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2189 | |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2190 | return nv50_fbdma_init(fb->dev, nv_fb->r_handle, 0, pfb->ram->size, kind); |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2191 | } |
| 2192 | |
| 2193 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2194 | * Init |
| 2195 | *****************************************************************************/ |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2196 | |
Ben Skeggs | 2a44e49 | 2011-11-09 11:36:33 +1000 | [diff] [blame] | 2197 | void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2198 | nv50_display_fini(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2199 | { |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2200 | } |
| 2201 | |
| 2202 | int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2203 | nv50_display_init(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2204 | { |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 2205 | struct nv50_disp *disp = nv50_disp(dev); |
| 2206 | struct drm_crtc *crtc; |
| 2207 | u32 *push; |
| 2208 | |
| 2209 | push = evo_wait(nv50_mast(dev), 32); |
| 2210 | if (!push) |
| 2211 | return -EBUSY; |
| 2212 | |
| 2213 | list_for_each_entry(crtc, &dev->mode_config.crtc_list, head) { |
| 2214 | struct nv50_sync *sync = nv50_sync(crtc); |
| 2215 | nouveau_bo_wr32(disp->sync, sync->addr / 4, sync->data); |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2216 | } |
| 2217 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 2218 | evo_mthd(push, 0x0088, 1); |
| 2219 | evo_data(push, NvEvoSync); |
| 2220 | evo_kick(push, nv50_mast(dev)); |
| 2221 | return 0; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2222 | } |
| 2223 | |
| 2224 | void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2225 | nv50_display_destroy(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2226 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2227 | struct nv50_disp *disp = nv50_disp(dev); |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2228 | struct nv50_fbdma *fbdma, *fbtmp; |
| 2229 | |
| 2230 | list_for_each_entry_safe(fbdma, fbtmp, &disp->fbdma, head) { |
| 2231 | nv50_fbdma_fini(dev, fbdma); |
| 2232 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2233 | |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2234 | nv50_dmac_destroy(disp->core, &disp->mast.base); |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 2235 | |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 2236 | nouveau_bo_unmap(disp->sync); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 2237 | if (disp->sync) |
| 2238 | nouveau_bo_unpin(disp->sync); |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 2239 | nouveau_bo_ref(NULL, &disp->sync); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 2240 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2241 | nouveau_display(dev)->priv = NULL; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2242 | kfree(disp); |
| 2243 | } |
| 2244 | |
| 2245 | int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2246 | nv50_display_create(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2247 | { |
Ben Skeggs | 967e7bd | 2014-08-10 04:10:22 +1000 | [diff] [blame^] | 2248 | struct nvif_device *device = &nouveau_drm(dev)->device; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2249 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2250 | struct dcb_table *dcb = &drm->vbios.dcb; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2251 | struct drm_connector *connector, *tmp; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2252 | struct nv50_disp *disp; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 2253 | struct dcb_output *dcbe; |
Ben Skeggs | 7c5f6a8 | 2012-03-04 16:25:59 +1000 | [diff] [blame] | 2254 | int crtcs, ret, i; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2255 | |
| 2256 | disp = kzalloc(sizeof(*disp), GFP_KERNEL); |
| 2257 | if (!disp) |
| 2258 | return -ENOMEM; |
Ben Skeggs | 8a42364 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2259 | INIT_LIST_HEAD(&disp->fbdma); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2260 | |
| 2261 | nouveau_display(dev)->priv = disp; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2262 | nouveau_display(dev)->dtor = nv50_display_destroy; |
| 2263 | nouveau_display(dev)->init = nv50_display_init; |
| 2264 | nouveau_display(dev)->fini = nv50_display_fini; |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2265 | nouveau_display(dev)->fb_ctor = nv50_fb_ctor; |
| 2266 | nouveau_display(dev)->fb_dtor = nv50_fb_dtor; |
Ben Skeggs | 2332b31 | 2014-01-22 12:58:12 +1000 | [diff] [blame] | 2267 | disp->core = nouveau_display(dev)->core; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2268 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2269 | /* small shared memory area we use for notifiers and semaphores */ |
| 2270 | ret = nouveau_bo_new(dev, 4096, 0x1000, TTM_PL_FLAG_VRAM, |
| 2271 | 0, 0x0000, NULL, &disp->sync); |
| 2272 | if (!ret) { |
| 2273 | ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 2274 | if (!ret) { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2275 | ret = nouveau_bo_map(disp->sync); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 2276 | if (ret) |
| 2277 | nouveau_bo_unpin(disp->sync); |
| 2278 | } |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2279 | if (ret) |
| 2280 | nouveau_bo_ref(NULL, &disp->sync); |
| 2281 | } |
| 2282 | |
| 2283 | if (ret) |
| 2284 | goto out; |
| 2285 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2286 | /* allocate master evo channel */ |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2287 | ret = nv50_dmac_create(disp->core, NV50_DISP_MAST_CLASS, 0, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2288 | &(struct nv50_display_mast_class) { |
| 2289 | .pushbuf = EVO_PUSH_HANDLE(MAST, 0), |
| 2290 | }, sizeof(struct nv50_display_mast_class), |
| 2291 | disp->sync->bo.offset, &disp->mast.base); |
| 2292 | if (ret) |
| 2293 | goto out; |
| 2294 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2295 | /* create crtc objects to represent the hw heads */ |
Ben Skeggs | 63718a0 | 2012-11-16 11:44:14 +1000 | [diff] [blame] | 2296 | if (nv_mclass(disp->core) >= NVD0_DISP_CLASS) |
Ben Skeggs | db2bec1 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 2297 | crtcs = nvif_rd32(device, 0x022448); |
Ben Skeggs | 63718a0 | 2012-11-16 11:44:14 +1000 | [diff] [blame] | 2298 | else |
| 2299 | crtcs = 2; |
| 2300 | |
Ben Skeggs | 7c5f6a8 | 2012-03-04 16:25:59 +1000 | [diff] [blame] | 2301 | for (i = 0; i < crtcs; i++) { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2302 | ret = nv50_crtc_create(dev, disp->core, i); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2303 | if (ret) |
| 2304 | goto out; |
| 2305 | } |
| 2306 | |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2307 | /* create encoder/connector objects based on VBIOS DCB table */ |
| 2308 | for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) { |
| 2309 | connector = nouveau_connector_create(dev, dcbe->connector); |
| 2310 | if (IS_ERR(connector)) |
| 2311 | continue; |
| 2312 | |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 2313 | if (dcbe->location == DCB_LOC_ON_CHIP) { |
| 2314 | switch (dcbe->type) { |
| 2315 | case DCB_OUTPUT_TMDS: |
| 2316 | case DCB_OUTPUT_LVDS: |
| 2317 | case DCB_OUTPUT_DP: |
| 2318 | ret = nv50_sor_create(connector, dcbe); |
| 2319 | break; |
| 2320 | case DCB_OUTPUT_ANALOG: |
| 2321 | ret = nv50_dac_create(connector, dcbe); |
| 2322 | break; |
| 2323 | default: |
| 2324 | ret = -ENODEV; |
| 2325 | break; |
| 2326 | } |
| 2327 | } else { |
| 2328 | ret = nv50_pior_create(connector, dcbe); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2329 | } |
| 2330 | |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 2331 | if (ret) { |
| 2332 | NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n", |
| 2333 | dcbe->location, dcbe->type, |
| 2334 | ffs(dcbe->or) - 1, ret); |
Ben Skeggs | 94f54f5 | 2013-03-05 22:26:06 +1000 | [diff] [blame] | 2335 | ret = 0; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2336 | } |
| 2337 | } |
| 2338 | |
| 2339 | /* cull any connectors we created that don't have an encoder */ |
| 2340 | list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) { |
| 2341 | if (connector->encoder_ids[0]) |
| 2342 | continue; |
| 2343 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2344 | NV_WARN(drm, "%s has no encoders, removing\n", |
Jani Nikula | 8c6c361 | 2014-06-03 14:56:18 +0300 | [diff] [blame] | 2345 | connector->name); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2346 | connector->funcs->destroy(connector); |
| 2347 | } |
| 2348 | |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2349 | out: |
| 2350 | if (ret) |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2351 | nv50_display_destroy(dev); |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2352 | return ret; |
| 2353 | } |