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 | */ |
Ben Skeggs | 1590700 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 24 | #include "disp.h" |
| 25 | #include "atom.h" |
| 26 | #include "core.h" |
| 27 | #include "head.h" |
| 28 | #include "wndw.h" |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 29 | |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 30 | #include <linux/dma-mapping.h> |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 31 | #include <linux/hdmi.h> |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 32 | |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 33 | #include <drm/drmP.h> |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 34 | #include <drm/drm_atomic_helper.h> |
David Howells | 760285e | 2012-10-02 18:01:07 +0100 | [diff] [blame] | 35 | #include <drm/drm_crtc_helper.h> |
Ben Skeggs | 4874322 | 2014-05-31 01:48:06 +1000 | [diff] [blame] | 36 | #include <drm/drm_dp_helper.h> |
Daniel Vetter | b516a9e | 2015-12-04 09:45:43 +0100 | [diff] [blame] | 37 | #include <drm/drm_fb_helper.h> |
Ben Skeggs | ad63361 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 38 | #include <drm/drm_plane_helper.h> |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 39 | #include <drm/drm_edid.h> |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 40 | |
Ben Skeggs | fdb751e | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 41 | #include <nvif/class.h> |
Ben Skeggs | 845f272 | 2015-11-08 12:16:40 +1000 | [diff] [blame] | 42 | #include <nvif/cl0002.h> |
Ben Skeggs | 7568b10 | 2015-11-08 10:44:19 +1000 | [diff] [blame] | 43 | #include <nvif/cl5070.h> |
Ben Skeggs | 7568b10 | 2015-11-08 10:44:19 +1000 | [diff] [blame] | 44 | #include <nvif/cl507d.h> |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 45 | #include <nvif/event.h> |
Ben Skeggs | fdb751e | 2014-08-10 04:10:23 +1000 | [diff] [blame] | 46 | |
Ben Skeggs | 4dc2813 | 2016-05-20 09:22:55 +1000 | [diff] [blame] | 47 | #include "nouveau_drv.h" |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 48 | #include "nouveau_dma.h" |
| 49 | #include "nouveau_gem.h" |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 50 | #include "nouveau_connector.h" |
| 51 | #include "nouveau_encoder.h" |
Ben Skeggs | f589be8 | 2012-07-22 11:55:54 +1000 | [diff] [blame] | 52 | #include "nouveau_fence.h" |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 53 | #include "nouveau_fbcon.h" |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 54 | |
Ben Skeggs | 34508f9 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 55 | #include <subdev/bios/dp.h> |
| 56 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 57 | /****************************************************************************** |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 58 | * Atomic state |
| 59 | *****************************************************************************/ |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 60 | |
| 61 | struct nv50_outp_atom { |
| 62 | struct list_head head; |
| 63 | |
| 64 | struct drm_encoder *encoder; |
| 65 | bool flush_disable; |
| 66 | |
Ben Skeggs | f88bc9d3 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 67 | union nv50_outp_atom_mask { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 68 | struct { |
| 69 | bool ctrl:1; |
| 70 | }; |
| 71 | u8 mask; |
Ben Skeggs | f88bc9d3 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 72 | } set, clr; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 73 | }; |
| 74 | |
Ben Skeggs | 3dbd036 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 75 | /****************************************************************************** |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 76 | * EVO channel |
| 77 | *****************************************************************************/ |
| 78 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 79 | static int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 80 | nv50_chan_create(struct nvif_device *device, struct nvif_object *disp, |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 81 | const s32 *oclass, u8 head, void *data, u32 size, |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 82 | struct nv50_chan *chan) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 83 | { |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 84 | struct nvif_sclass *sclass; |
| 85 | int ret, i, n; |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 86 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 87 | chan->device = device; |
| 88 | |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 89 | ret = n = nvif_object_sclass_get(disp, &sclass); |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 90 | if (ret < 0) |
| 91 | return ret; |
| 92 | |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 93 | while (oclass[0]) { |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 94 | for (i = 0; i < n; i++) { |
| 95 | if (sclass[i].oclass == oclass[0]) { |
Ben Skeggs | fcf3f91 | 2015-09-04 14:40:32 +1000 | [diff] [blame] | 96 | ret = nvif_object_init(disp, 0, oclass[0], |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 97 | data, size, &chan->user); |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 98 | if (ret == 0) |
Ben Skeggs | 0132605 | 2017-11-01 03:56:19 +1000 | [diff] [blame] | 99 | nvif_object_map(&chan->user, NULL, 0); |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 100 | nvif_object_sclass_put(&sclass); |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 101 | return ret; |
| 102 | } |
Ben Skeggs | b76f152 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 103 | } |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 104 | oclass++; |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 105 | } |
Ben Skeggs | 6af5289 | 2014-11-03 15:01:33 +1000 | [diff] [blame] | 106 | |
Ben Skeggs | 41a6340 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 107 | nvif_object_sclass_put(&sclass); |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 108 | return -ENOSYS; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 109 | } |
| 110 | |
| 111 | static void |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 112 | nv50_chan_destroy(struct nv50_chan *chan) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 113 | { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 114 | nvif_object_fini(&chan->user); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 115 | } |
| 116 | |
| 117 | /****************************************************************************** |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 118 | * DMA EVO channel |
| 119 | *****************************************************************************/ |
| 120 | |
Ben Skeggs | 1590700 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 121 | void |
Ben Skeggs | f565047 | 2018-05-08 20:39:46 +1000 | [diff] [blame] | 122 | nv50_dmac_destroy(struct nv50_dmac *dmac) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 123 | { |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 124 | nvif_object_fini(&dmac->vram); |
| 125 | nvif_object_fini(&dmac->sync); |
| 126 | |
| 127 | nv50_chan_destroy(&dmac->base); |
| 128 | |
Ben Skeggs | f565047 | 2018-05-08 20:39:46 +1000 | [diff] [blame] | 129 | nvif_mem_fini(&dmac->push); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 130 | } |
| 131 | |
Ben Skeggs | 1590700 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 132 | int |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 133 | nv50_dmac_create(struct nvif_device *device, struct nvif_object *disp, |
Ben Skeggs | 315a8b2 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 134 | const s32 *oclass, u8 head, void *data, u32 size, u64 syncbuf, |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 135 | struct nv50_dmac *dmac) |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 136 | { |
Ben Skeggs | f565047 | 2018-05-08 20:39:46 +1000 | [diff] [blame] | 137 | struct nouveau_cli *cli = (void *)device->object.client; |
Ben Skeggs | 648d4df | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 138 | struct nv50_disp_core_channel_dma_v0 *args = data; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 139 | int ret; |
| 140 | |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 141 | mutex_init(&dmac->lock); |
| 142 | |
Ben Skeggs | f565047 | 2018-05-08 20:39:46 +1000 | [diff] [blame] | 143 | ret = nvif_mem_init_map(&cli->mmu, NVIF_MEM_COHERENT, 0x1000, |
| 144 | &dmac->push); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 145 | if (ret) |
| 146 | return ret; |
| 147 | |
Ben Skeggs | f565047 | 2018-05-08 20:39:46 +1000 | [diff] [blame] | 148 | dmac->ptr = dmac->push.object.map.ptr; |
| 149 | |
| 150 | args->pushbuf = nvif_handle(&dmac->push.object); |
Ben Skeggs | bf81df9 | 2015-08-20 14:54:16 +1000 | [diff] [blame] | 151 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 152 | ret = nv50_chan_create(device, disp, oclass, head, data, size, |
| 153 | &dmac->base); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 154 | if (ret) |
| 155 | return ret; |
| 156 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 157 | ret = nvif_object_init(&dmac->base.user, 0xf0000000, NV_DMA_IN_MEMORY, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 158 | &(struct nv_dma_v0) { |
| 159 | .target = NV_DMA_V0_TARGET_VRAM, |
| 160 | .access = NV_DMA_V0_ACCESS_RDWR, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 161 | .start = syncbuf + 0x0000, |
| 162 | .limit = syncbuf + 0x0fff, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 163 | }, sizeof(struct nv_dma_v0), |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 164 | &dmac->sync); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 165 | if (ret) |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 166 | return ret; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 167 | |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 168 | ret = nvif_object_init(&dmac->base.user, 0xf0000001, NV_DMA_IN_MEMORY, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 169 | &(struct nv_dma_v0) { |
| 170 | .target = NV_DMA_V0_TARGET_VRAM, |
| 171 | .access = NV_DMA_V0_ACCESS_RDWR, |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 172 | .start = 0, |
Ben Skeggs | f392ec4 | 2014-08-10 04:10:28 +1000 | [diff] [blame] | 173 | .limit = device->info.ram_user - 1, |
Ben Skeggs | 4acfd70 | 2014-08-10 04:10:24 +1000 | [diff] [blame] | 174 | }, sizeof(struct nv_dma_v0), |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 175 | &dmac->vram); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 176 | if (ret) |
Ben Skeggs | 4705730 | 2012-11-16 13:58:48 +1000 | [diff] [blame] | 177 | return ret; |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 178 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 179 | return ret; |
| 180 | } |
| 181 | |
Ben Skeggs | 410f3ec | 2014-08-10 04:10:25 +1000 | [diff] [blame] | 182 | /****************************************************************************** |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 183 | * EVO channel helpers |
| 184 | *****************************************************************************/ |
Ben Skeggs | 1590700 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 185 | u32 * |
| 186 | evo_wait(struct nv50_dmac *evoc, int nr) |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 187 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 188 | struct nv50_dmac *dmac = evoc; |
Ben Skeggs | a01ca78 | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 189 | struct nvif_device *device = dmac->base.device; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 190 | u32 put = nvif_rd32(&dmac->base.user, 0x0000) / 4; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 191 | |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 192 | mutex_lock(&dmac->lock); |
Ben Skeggs | de8268c | 2012-11-16 10:24:31 +1000 | [diff] [blame] | 193 | if (put + nr >= (PAGE_SIZE / 4) - 8) { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 194 | dmac->ptr[put] = 0x20000000; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 195 | |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 196 | nvif_wr32(&dmac->base.user, 0x0000, 0x00000000); |
Ben Skeggs | 5444204 | 2015-08-20 14:54:11 +1000 | [diff] [blame] | 197 | if (nvif_msec(device, 2000, |
| 198 | if (!nvif_rd32(&dmac->base.user, 0x0004)) |
| 199 | break; |
| 200 | ) < 0) { |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 201 | mutex_unlock(&dmac->lock); |
Joe Perches | 8dfe162 | 2017-02-28 04:55:54 -0800 | [diff] [blame] | 202 | pr_err("nouveau: evo channel stalled\n"); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 203 | return NULL; |
| 204 | } |
| 205 | |
| 206 | put = 0; |
| 207 | } |
| 208 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 209 | return dmac->ptr + put; |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 210 | } |
| 211 | |
Ben Skeggs | 1590700 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 212 | void |
| 213 | evo_kick(u32 *push, struct nv50_dmac *evoc) |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 214 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 215 | struct nv50_dmac *dmac = evoc; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 216 | nvif_wr32(&dmac->base.user, 0x0000, (push - dmac->ptr) << 2); |
Daniel Vetter | 59ad146 | 2012-12-02 14:49:44 +0100 | [diff] [blame] | 217 | mutex_unlock(&dmac->lock); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 218 | } |
| 219 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 220 | /****************************************************************************** |
Ben Skeggs | d92c8ad | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 221 | * Output path helpers |
Ben Skeggs | a91d322 | 2014-12-22 16:30:13 +1000 | [diff] [blame] | 222 | *****************************************************************************/ |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 223 | static void |
| 224 | nv50_outp_release(struct nouveau_encoder *nv_encoder) |
| 225 | { |
| 226 | struct nv50_disp *disp = nv50_disp(nv_encoder->base.base.dev); |
| 227 | struct { |
| 228 | struct nv50_disp_mthd_v1 base; |
| 229 | } args = { |
| 230 | .base.version = 1, |
| 231 | .base.method = NV50_DISP_MTHD_V1_RELEASE, |
| 232 | .base.hasht = nv_encoder->dcb->hasht, |
| 233 | .base.hashm = nv_encoder->dcb->hashm, |
| 234 | }; |
| 235 | |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 236 | nvif_mthd(&disp->disp->object, 0, &args, sizeof(args)); |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 237 | nv_encoder->or = -1; |
| 238 | nv_encoder->link = 0; |
| 239 | } |
| 240 | |
| 241 | static int |
| 242 | nv50_outp_acquire(struct nouveau_encoder *nv_encoder) |
| 243 | { |
| 244 | struct nouveau_drm *drm = nouveau_drm(nv_encoder->base.base.dev); |
| 245 | struct nv50_disp *disp = nv50_disp(drm->dev); |
| 246 | struct { |
| 247 | struct nv50_disp_mthd_v1 base; |
| 248 | struct nv50_disp_acquire_v0 info; |
| 249 | } args = { |
| 250 | .base.version = 1, |
| 251 | .base.method = NV50_DISP_MTHD_V1_ACQUIRE, |
| 252 | .base.hasht = nv_encoder->dcb->hasht, |
| 253 | .base.hashm = nv_encoder->dcb->hashm, |
| 254 | }; |
| 255 | int ret; |
| 256 | |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 257 | ret = nvif_mthd(&disp->disp->object, 0, &args, sizeof(args)); |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 258 | if (ret) { |
| 259 | NV_ERROR(drm, "error acquiring output path: %d\n", ret); |
| 260 | return ret; |
| 261 | } |
| 262 | |
| 263 | nv_encoder->or = args.info.or; |
| 264 | nv_encoder->link = args.info.link; |
| 265 | return 0; |
| 266 | } |
| 267 | |
Ben Skeggs | d92c8ad | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 268 | static int |
| 269 | nv50_outp_atomic_check_view(struct drm_encoder *encoder, |
| 270 | struct drm_crtc_state *crtc_state, |
| 271 | struct drm_connector_state *conn_state, |
| 272 | struct drm_display_mode *native_mode) |
| 273 | { |
| 274 | struct drm_display_mode *adjusted_mode = &crtc_state->adjusted_mode; |
| 275 | struct drm_display_mode *mode = &crtc_state->mode; |
| 276 | struct drm_connector *connector = conn_state->connector; |
| 277 | struct nouveau_conn_atom *asyc = nouveau_conn_atom(conn_state); |
| 278 | struct nouveau_drm *drm = nouveau_drm(encoder->dev); |
| 279 | |
| 280 | NV_ATOMIC(drm, "%s atomic_check\n", encoder->name); |
| 281 | asyc->scaler.full = false; |
| 282 | if (!native_mode) |
| 283 | return 0; |
| 284 | |
| 285 | if (asyc->scaler.mode == DRM_MODE_SCALE_NONE) { |
| 286 | switch (connector->connector_type) { |
| 287 | case DRM_MODE_CONNECTOR_LVDS: |
| 288 | case DRM_MODE_CONNECTOR_eDP: |
| 289 | /* Force use of scaler for non-EDID modes. */ |
| 290 | if (adjusted_mode->type & DRM_MODE_TYPE_DRIVER) |
| 291 | break; |
| 292 | mode = native_mode; |
| 293 | asyc->scaler.full = true; |
| 294 | break; |
| 295 | default: |
| 296 | break; |
| 297 | } |
| 298 | } else { |
| 299 | mode = native_mode; |
| 300 | } |
| 301 | |
| 302 | if (!drm_mode_equal(adjusted_mode, mode)) { |
| 303 | drm_mode_copy(adjusted_mode, mode); |
| 304 | crtc_state->mode_changed = true; |
| 305 | } |
| 306 | |
| 307 | return 0; |
| 308 | } |
| 309 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 310 | static int |
| 311 | nv50_outp_atomic_check(struct drm_encoder *encoder, |
| 312 | struct drm_crtc_state *crtc_state, |
| 313 | struct drm_connector_state *conn_state) |
Ben Skeggs | a91d322 | 2014-12-22 16:30:13 +1000 | [diff] [blame] | 314 | { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 315 | struct nouveau_connector *nv_connector = |
| 316 | nouveau_connector(conn_state->connector); |
| 317 | return nv50_outp_atomic_check_view(encoder, crtc_state, conn_state, |
| 318 | nv_connector->native_mode); |
Ben Skeggs | a91d322 | 2014-12-22 16:30:13 +1000 | [diff] [blame] | 319 | } |
| 320 | |
| 321 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 322 | * DAC |
| 323 | *****************************************************************************/ |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 324 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 325 | nv50_dac_disable(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 326 | { |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 327 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 328 | struct nv50_core *core = nv50_disp(encoder->dev)->core; |
| 329 | if (nv_encoder->crtc) |
| 330 | core->func->dac->ctrl(core, nv_encoder->or, 0x00000000, NULL); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 331 | nv_encoder->crtc = NULL; |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 332 | nv50_outp_release(nv_encoder); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 333 | } |
| 334 | |
| 335 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 336 | nv50_dac_enable(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 337 | { |
| 338 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 339 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 340 | struct nv50_head_atom *asyh = nv50_head_atom(nv_crtc->base.state); |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 341 | struct nv50_core *core = nv50_disp(encoder->dev)->core; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 342 | |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 343 | nv50_outp_acquire(nv_encoder); |
| 344 | |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 345 | core->func->dac->ctrl(core, nv_encoder->or, 1 << nv_crtc->index, asyh); |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 346 | asyh->or.depth = 0; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 347 | |
| 348 | nv_encoder->crtc = encoder->crtc; |
| 349 | } |
| 350 | |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 351 | static enum drm_connector_status |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 352 | nv50_dac_detect(struct drm_encoder *encoder, struct drm_connector *connector) |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 353 | { |
Ben Skeggs | c4abd31 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 354 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 355 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | c4abd31 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 356 | struct { |
| 357 | struct nv50_disp_mthd_v1 base; |
| 358 | struct nv50_disp_dac_load_v0 load; |
| 359 | } args = { |
| 360 | .base.version = 1, |
| 361 | .base.method = NV50_DISP_MTHD_V1_DAC_LOAD, |
| 362 | .base.hasht = nv_encoder->dcb->hasht, |
| 363 | .base.hashm = nv_encoder->dcb->hashm, |
| 364 | }; |
| 365 | int ret; |
Ben Skeggs | b681993 | 2011-07-08 11:14:50 +1000 | [diff] [blame] | 366 | |
Ben Skeggs | c4abd31 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 367 | args.load.data = nouveau_drm(encoder->dev)->vbios.dactestval; |
| 368 | if (args.load.data == 0) |
| 369 | args.load.data = 340; |
| 370 | |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 371 | ret = nvif_mthd(&disp->disp->object, 0, &args, sizeof(args)); |
Ben Skeggs | c4abd31 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 372 | if (ret || !args.load.load) |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 373 | return connector_status_disconnected; |
Ben Skeggs | b681993 | 2011-07-08 11:14:50 +1000 | [diff] [blame] | 374 | |
Ben Skeggs | 35b21d3 | 2012-11-08 12:08:55 +1000 | [diff] [blame] | 375 | return connector_status_connected; |
Ben Skeggs | b6d8e7e | 2011-07-07 09:51:29 +1000 | [diff] [blame] | 376 | } |
| 377 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 378 | static const struct drm_encoder_helper_funcs |
| 379 | nv50_dac_help = { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 380 | .atomic_check = nv50_outp_atomic_check, |
| 381 | .enable = nv50_dac_enable, |
| 382 | .disable = nv50_dac_disable, |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 383 | .detect = nv50_dac_detect |
| 384 | }; |
| 385 | |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 386 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 387 | nv50_dac_destroy(struct drm_encoder *encoder) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 388 | { |
| 389 | drm_encoder_cleanup(encoder); |
| 390 | kfree(encoder); |
| 391 | } |
| 392 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 393 | static const struct drm_encoder_funcs |
| 394 | nv50_dac_func = { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 395 | .destroy = nv50_dac_destroy, |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 396 | }; |
| 397 | |
| 398 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 399 | nv50_dac_create(struct drm_connector *connector, struct dcb_output *dcbe) |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 400 | { |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 401 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 402 | struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device); |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 403 | struct nvkm_i2c_bus *bus; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 404 | struct nouveau_encoder *nv_encoder; |
| 405 | struct drm_encoder *encoder; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 406 | int type = DRM_MODE_ENCODER_DAC; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 407 | |
| 408 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 409 | if (!nv_encoder) |
| 410 | return -ENOMEM; |
| 411 | nv_encoder->dcb = dcbe; |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 412 | |
| 413 | bus = nvkm_i2c_bus_find(i2c, dcbe->i2c_index); |
| 414 | if (bus) |
| 415 | nv_encoder->i2c = &bus->i2c; |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 416 | |
| 417 | encoder = to_drm_encoder(nv_encoder); |
| 418 | encoder->possible_crtcs = dcbe->heads; |
| 419 | encoder->possible_clones = 0; |
Ben Skeggs | 5a223da | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 420 | drm_encoder_init(connector->dev, encoder, &nv50_dac_func, type, |
| 421 | "dac-%04x-%04x", dcbe->hasht, dcbe->hashm); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 422 | drm_encoder_helper_add(encoder, &nv50_dac_help); |
Ben Skeggs | 8eaa966 | 2011-07-06 15:25:47 +1000 | [diff] [blame] | 423 | |
| 424 | drm_mode_connector_attach_encoder(connector, encoder); |
| 425 | return 0; |
| 426 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 427 | |
| 428 | /****************************************************************************** |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 429 | * Audio |
| 430 | *****************************************************************************/ |
| 431 | static void |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 432 | nv50_audio_disable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc) |
| 433 | { |
| 434 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 435 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
| 436 | struct { |
| 437 | struct nv50_disp_mthd_v1 base; |
| 438 | struct nv50_disp_sor_hda_eld_v0 eld; |
| 439 | } args = { |
| 440 | .base.version = 1, |
| 441 | .base.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD, |
| 442 | .base.hasht = nv_encoder->dcb->hasht, |
| 443 | .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 444 | (0x0100 << nv_crtc->index), |
| 445 | }; |
| 446 | |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 447 | nvif_mthd(&disp->disp->object, 0, &args, sizeof(args)); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 448 | } |
| 449 | |
| 450 | static void |
| 451 | nv50_audio_enable(struct drm_encoder *encoder, struct drm_display_mode *mode) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 452 | { |
| 453 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | cc2a907 | 2014-09-15 21:29:05 +1000 | [diff] [blame] | 454 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 455 | struct nouveau_connector *nv_connector; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 456 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | d889c52 | 2014-09-15 21:11:51 +1000 | [diff] [blame] | 457 | struct __packed { |
| 458 | struct { |
| 459 | struct nv50_disp_mthd_v1 mthd; |
| 460 | struct nv50_disp_sor_hda_eld_v0 eld; |
| 461 | } base; |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 462 | u8 data[sizeof(nv_connector->base.eld)]; |
| 463 | } args = { |
Ben Skeggs | d889c52 | 2014-09-15 21:11:51 +1000 | [diff] [blame] | 464 | .base.mthd.version = 1, |
| 465 | .base.mthd.method = NV50_DISP_MTHD_V1_SOR_HDA_ELD, |
| 466 | .base.mthd.hasht = nv_encoder->dcb->hasht, |
Ben Skeggs | cc2a907 | 2014-09-15 21:29:05 +1000 | [diff] [blame] | 467 | .base.mthd.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 468 | (0x0100 << nv_crtc->index), |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 469 | }; |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 470 | |
| 471 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 472 | if (!drm_detect_monitor_audio(nv_connector->edid)) |
| 473 | return; |
| 474 | |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 475 | memcpy(args.data, nv_connector->base.eld, sizeof(args.data)); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 476 | |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 477 | nvif_mthd(&disp->disp->object, 0, &args, |
Jani Nikula | 938fd8a | 2014-10-28 16:20:48 +0200 | [diff] [blame] | 478 | sizeof(args.base) + drm_eld_size(args.data)); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 479 | } |
| 480 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 481 | /****************************************************************************** |
| 482 | * HDMI |
| 483 | *****************************************************************************/ |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 484 | static void |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 485 | nv50_hdmi_disable(struct drm_encoder *encoder, struct nouveau_crtc *nv_crtc) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 486 | { |
| 487 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 488 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 489 | struct { |
| 490 | struct nv50_disp_mthd_v1 base; |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 491 | struct nv50_disp_sor_hdmi_pwr_v0 pwr; |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 492 | } args = { |
| 493 | .base.version = 1, |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 494 | .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR, |
| 495 | .base.hasht = nv_encoder->dcb->hasht, |
| 496 | .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 497 | (0x0100 << nv_crtc->index), |
Ben Skeggs | 120b0c3 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 498 | }; |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 499 | |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 500 | nvif_mthd(&disp->disp->object, 0, &args, sizeof(args)); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 501 | } |
| 502 | |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 503 | static void |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 504 | nv50_hdmi_enable(struct drm_encoder *encoder, struct drm_display_mode *mode) |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 505 | { |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 506 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 507 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 508 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 509 | struct { |
| 510 | struct nv50_disp_mthd_v1 base; |
| 511 | struct nv50_disp_sor_hdmi_pwr_v0 pwr; |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 512 | u8 infoframes[2 * 17]; /* two frames, up to 17 bytes each */ |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 513 | } args = { |
| 514 | .base.version = 1, |
| 515 | .base.method = NV50_DISP_MTHD_V1_SOR_HDMI_PWR, |
| 516 | .base.hasht = nv_encoder->dcb->hasht, |
| 517 | .base.hashm = (0xf0ff & nv_encoder->dcb->hashm) | |
| 518 | (0x0100 << nv_crtc->index), |
| 519 | .pwr.state = 1, |
| 520 | .pwr.rekey = 56, /* binary driver, and tegra, constant */ |
| 521 | }; |
| 522 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 523 | u32 max_ac_packet; |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 524 | union hdmi_infoframe avi_frame; |
| 525 | union hdmi_infoframe vendor_frame; |
| 526 | int ret; |
| 527 | int size; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 528 | |
| 529 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 530 | if (!drm_detect_hdmi_monitor(nv_connector->edid)) |
| 531 | return; |
| 532 | |
Shashank Sharma | 0c1f528 | 2017-07-13 21:03:07 +0530 | [diff] [blame] | 533 | ret = drm_hdmi_avi_infoframe_from_display_mode(&avi_frame.avi, mode, |
| 534 | false); |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 535 | if (!ret) { |
| 536 | /* We have an AVI InfoFrame, populate it to the display */ |
| 537 | args.pwr.avi_infoframe_length |
| 538 | = hdmi_infoframe_pack(&avi_frame, args.infoframes, 17); |
| 539 | } |
| 540 | |
Ville Syrjälä | f1781e9 | 2017-11-13 19:04:19 +0200 | [diff] [blame] | 541 | ret = drm_hdmi_vendor_infoframe_from_display_mode(&vendor_frame.vendor.hdmi, |
| 542 | &nv_connector->base, mode); |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 543 | if (!ret) { |
| 544 | /* We have a Vendor InfoFrame, populate it to the display */ |
| 545 | args.pwr.vendor_infoframe_length |
| 546 | = hdmi_infoframe_pack(&vendor_frame, |
| 547 | args.infoframes |
| 548 | + args.pwr.avi_infoframe_length, |
| 549 | 17); |
| 550 | } |
| 551 | |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 552 | max_ac_packet = mode->htotal - mode->hdisplay; |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 553 | max_ac_packet -= args.pwr.rekey; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 554 | max_ac_packet -= 18; /* constant from tegra */ |
Ben Skeggs | e00f223 | 2014-08-10 04:10:26 +1000 | [diff] [blame] | 555 | args.pwr.max_ac_packet = max_ac_packet / 32; |
Ben Skeggs | 64d9cc0 | 2011-11-11 19:51:20 +1000 | [diff] [blame] | 556 | |
Alastair Bridgewater | 34fd3e5 | 2017-04-11 13:11:18 -0400 | [diff] [blame] | 557 | size = sizeof(args.base) |
| 558 | + sizeof(args.pwr) |
| 559 | + args.pwr.avi_infoframe_length |
| 560 | + args.pwr.vendor_infoframe_length; |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 561 | nvif_mthd(&disp->disp->object, 0, &args, size); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 562 | nv50_audio_enable(encoder, mode); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 563 | } |
| 564 | |
| 565 | /****************************************************************************** |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 566 | * MST |
| 567 | *****************************************************************************/ |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 568 | #define nv50_mstm(p) container_of((p), struct nv50_mstm, mgr) |
| 569 | #define nv50_mstc(p) container_of((p), struct nv50_mstc, connector) |
| 570 | #define nv50_msto(p) container_of((p), struct nv50_msto, encoder) |
| 571 | |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 572 | struct nv50_mstm { |
| 573 | struct nouveau_encoder *outp; |
| 574 | |
| 575 | struct drm_dp_mst_topology_mgr mgr; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 576 | struct nv50_msto *msto[4]; |
| 577 | |
| 578 | bool modified; |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 579 | bool disabled; |
| 580 | int links; |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 581 | }; |
| 582 | |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 583 | struct nv50_mstc { |
| 584 | struct nv50_mstm *mstm; |
| 585 | struct drm_dp_mst_port *port; |
| 586 | struct drm_connector connector; |
| 587 | |
| 588 | struct drm_display_mode *native; |
| 589 | struct edid *edid; |
| 590 | |
| 591 | int pbn; |
| 592 | }; |
| 593 | |
| 594 | struct nv50_msto { |
| 595 | struct drm_encoder encoder; |
| 596 | |
| 597 | struct nv50_head *head; |
| 598 | struct nv50_mstc *mstc; |
| 599 | bool disabled; |
| 600 | }; |
| 601 | |
| 602 | static struct drm_dp_payload * |
| 603 | nv50_msto_payload(struct nv50_msto *msto) |
| 604 | { |
| 605 | struct nouveau_drm *drm = nouveau_drm(msto->encoder.dev); |
| 606 | struct nv50_mstc *mstc = msto->mstc; |
| 607 | struct nv50_mstm *mstm = mstc->mstm; |
| 608 | int vcpi = mstc->port->vcpi.vcpi, i; |
| 609 | |
| 610 | NV_ATOMIC(drm, "%s: vcpi %d\n", msto->encoder.name, vcpi); |
| 611 | for (i = 0; i < mstm->mgr.max_payloads; i++) { |
| 612 | struct drm_dp_payload *payload = &mstm->mgr.payloads[i]; |
| 613 | NV_ATOMIC(drm, "%s: %d: vcpi %d start 0x%02x slots 0x%02x\n", |
| 614 | mstm->outp->base.base.name, i, payload->vcpi, |
| 615 | payload->start_slot, payload->num_slots); |
| 616 | } |
| 617 | |
| 618 | for (i = 0; i < mstm->mgr.max_payloads; i++) { |
| 619 | struct drm_dp_payload *payload = &mstm->mgr.payloads[i]; |
| 620 | if (payload->vcpi == vcpi) |
| 621 | return payload; |
| 622 | } |
| 623 | |
| 624 | return NULL; |
| 625 | } |
| 626 | |
| 627 | static void |
| 628 | nv50_msto_cleanup(struct nv50_msto *msto) |
| 629 | { |
| 630 | struct nouveau_drm *drm = nouveau_drm(msto->encoder.dev); |
| 631 | struct nv50_mstc *mstc = msto->mstc; |
| 632 | struct nv50_mstm *mstm = mstc->mstm; |
| 633 | |
| 634 | NV_ATOMIC(drm, "%s: msto cleanup\n", msto->encoder.name); |
| 635 | if (mstc->port && mstc->port->vcpi.vcpi > 0 && !nv50_msto_payload(msto)) |
| 636 | drm_dp_mst_deallocate_vcpi(&mstm->mgr, mstc->port); |
| 637 | if (msto->disabled) { |
| 638 | msto->mstc = NULL; |
| 639 | msto->head = NULL; |
| 640 | msto->disabled = false; |
| 641 | } |
| 642 | } |
| 643 | |
| 644 | static void |
| 645 | nv50_msto_prepare(struct nv50_msto *msto) |
| 646 | { |
| 647 | struct nouveau_drm *drm = nouveau_drm(msto->encoder.dev); |
| 648 | struct nv50_mstc *mstc = msto->mstc; |
| 649 | struct nv50_mstm *mstm = mstc->mstm; |
| 650 | struct { |
| 651 | struct nv50_disp_mthd_v1 base; |
| 652 | struct nv50_disp_sor_dp_mst_vcpi_v0 vcpi; |
| 653 | } args = { |
| 654 | .base.version = 1, |
| 655 | .base.method = NV50_DISP_MTHD_V1_SOR_DP_MST_VCPI, |
| 656 | .base.hasht = mstm->outp->dcb->hasht, |
| 657 | .base.hashm = (0xf0ff & mstm->outp->dcb->hashm) | |
| 658 | (0x0100 << msto->head->base.index), |
| 659 | }; |
| 660 | |
| 661 | NV_ATOMIC(drm, "%s: msto prepare\n", msto->encoder.name); |
| 662 | if (mstc->port && mstc->port->vcpi.vcpi > 0) { |
| 663 | struct drm_dp_payload *payload = nv50_msto_payload(msto); |
| 664 | if (payload) { |
| 665 | args.vcpi.start_slot = payload->start_slot; |
| 666 | args.vcpi.num_slots = payload->num_slots; |
| 667 | args.vcpi.pbn = mstc->port->vcpi.pbn; |
| 668 | args.vcpi.aligned_pbn = mstc->port->vcpi.aligned_pbn; |
| 669 | } |
| 670 | } |
| 671 | |
| 672 | NV_ATOMIC(drm, "%s: %s: %02x %02x %04x %04x\n", |
| 673 | msto->encoder.name, msto->head->base.base.name, |
| 674 | args.vcpi.start_slot, args.vcpi.num_slots, |
| 675 | args.vcpi.pbn, args.vcpi.aligned_pbn); |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 676 | nvif_mthd(&drm->display->disp.object, 0, &args, sizeof(args)); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 677 | } |
| 678 | |
| 679 | static int |
| 680 | nv50_msto_atomic_check(struct drm_encoder *encoder, |
| 681 | struct drm_crtc_state *crtc_state, |
| 682 | struct drm_connector_state *conn_state) |
| 683 | { |
| 684 | struct nv50_mstc *mstc = nv50_mstc(conn_state->connector); |
| 685 | struct nv50_mstm *mstm = mstc->mstm; |
| 686 | int bpp = conn_state->connector->display_info.bpc * 3; |
| 687 | int slots; |
| 688 | |
| 689 | mstc->pbn = drm_dp_calc_pbn_mode(crtc_state->adjusted_mode.clock, bpp); |
| 690 | |
| 691 | slots = drm_dp_find_vcpi_slots(&mstm->mgr, mstc->pbn); |
| 692 | if (slots < 0) |
| 693 | return slots; |
| 694 | |
| 695 | return nv50_outp_atomic_check_view(encoder, crtc_state, conn_state, |
| 696 | mstc->native); |
| 697 | } |
| 698 | |
| 699 | static void |
| 700 | nv50_msto_enable(struct drm_encoder *encoder) |
| 701 | { |
| 702 | struct nv50_head *head = nv50_head(encoder->crtc); |
| 703 | struct nv50_msto *msto = nv50_msto(encoder); |
| 704 | struct nv50_mstc *mstc = NULL; |
| 705 | struct nv50_mstm *mstm = NULL; |
| 706 | struct drm_connector *connector; |
Gustavo Padovan | 875dd62 | 2017-05-11 16:10:46 -0300 | [diff] [blame] | 707 | struct drm_connector_list_iter conn_iter; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 708 | u8 proto, depth; |
| 709 | int slots; |
| 710 | bool r; |
| 711 | |
Gustavo Padovan | 875dd62 | 2017-05-11 16:10:46 -0300 | [diff] [blame] | 712 | drm_connector_list_iter_begin(encoder->dev, &conn_iter); |
| 713 | drm_for_each_connector_iter(connector, &conn_iter) { |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 714 | if (connector->state->best_encoder == &msto->encoder) { |
| 715 | mstc = nv50_mstc(connector); |
| 716 | mstm = mstc->mstm; |
| 717 | break; |
| 718 | } |
| 719 | } |
Gustavo Padovan | 875dd62 | 2017-05-11 16:10:46 -0300 | [diff] [blame] | 720 | drm_connector_list_iter_end(&conn_iter); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 721 | |
| 722 | if (WARN_ON(!mstc)) |
| 723 | return; |
| 724 | |
Pandiyan, Dhinakaran | 1e797f5 | 2017-03-16 00:10:26 -0700 | [diff] [blame] | 725 | slots = drm_dp_find_vcpi_slots(&mstm->mgr, mstc->pbn); |
| 726 | r = drm_dp_mst_allocate_vcpi(&mstm->mgr, mstc->port, mstc->pbn, slots); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 727 | WARN_ON(!r); |
| 728 | |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 729 | if (!mstm->links++) |
| 730 | nv50_outp_acquire(mstm->outp); |
| 731 | |
| 732 | if (mstm->outp->link & 1) |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 733 | proto = 0x8; |
| 734 | else |
| 735 | proto = 0x9; |
| 736 | |
| 737 | switch (mstc->connector.display_info.bpc) { |
| 738 | case 6: depth = 0x2; break; |
| 739 | case 8: depth = 0x5; break; |
| 740 | case 10: |
| 741 | default: depth = 0x6; break; |
| 742 | } |
| 743 | |
| 744 | mstm->outp->update(mstm->outp, head->base.index, |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 745 | nv50_head_atom(head->base.base.state), proto, depth); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 746 | |
| 747 | msto->head = head; |
| 748 | msto->mstc = mstc; |
| 749 | mstm->modified = true; |
| 750 | } |
| 751 | |
| 752 | static void |
| 753 | nv50_msto_disable(struct drm_encoder *encoder) |
| 754 | { |
| 755 | struct nv50_msto *msto = nv50_msto(encoder); |
| 756 | struct nv50_mstc *mstc = msto->mstc; |
| 757 | struct nv50_mstm *mstm = mstc->mstm; |
| 758 | |
| 759 | if (mstc->port) |
| 760 | drm_dp_mst_reset_vcpi_slots(&mstm->mgr, mstc->port); |
| 761 | |
| 762 | mstm->outp->update(mstm->outp, msto->head->base.index, NULL, 0, 0); |
| 763 | mstm->modified = true; |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 764 | if (!--mstm->links) |
| 765 | mstm->disabled = true; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 766 | msto->disabled = true; |
| 767 | } |
| 768 | |
| 769 | static const struct drm_encoder_helper_funcs |
| 770 | nv50_msto_help = { |
| 771 | .disable = nv50_msto_disable, |
| 772 | .enable = nv50_msto_enable, |
| 773 | .atomic_check = nv50_msto_atomic_check, |
| 774 | }; |
| 775 | |
| 776 | static void |
| 777 | nv50_msto_destroy(struct drm_encoder *encoder) |
| 778 | { |
| 779 | struct nv50_msto *msto = nv50_msto(encoder); |
| 780 | drm_encoder_cleanup(&msto->encoder); |
| 781 | kfree(msto); |
| 782 | } |
| 783 | |
| 784 | static const struct drm_encoder_funcs |
| 785 | nv50_msto = { |
| 786 | .destroy = nv50_msto_destroy, |
| 787 | }; |
| 788 | |
| 789 | static int |
| 790 | nv50_msto_new(struct drm_device *dev, u32 heads, const char *name, int id, |
| 791 | struct nv50_msto **pmsto) |
| 792 | { |
| 793 | struct nv50_msto *msto; |
| 794 | int ret; |
| 795 | |
| 796 | if (!(msto = *pmsto = kzalloc(sizeof(*msto), GFP_KERNEL))) |
| 797 | return -ENOMEM; |
| 798 | |
| 799 | ret = drm_encoder_init(dev, &msto->encoder, &nv50_msto, |
| 800 | DRM_MODE_ENCODER_DPMST, "%s-mst-%d", name, id); |
| 801 | if (ret) { |
| 802 | kfree(*pmsto); |
| 803 | *pmsto = NULL; |
| 804 | return ret; |
| 805 | } |
| 806 | |
| 807 | drm_encoder_helper_add(&msto->encoder, &nv50_msto_help); |
| 808 | msto->encoder.possible_crtcs = heads; |
| 809 | return 0; |
| 810 | } |
| 811 | |
| 812 | static struct drm_encoder * |
| 813 | nv50_mstc_atomic_best_encoder(struct drm_connector *connector, |
| 814 | struct drm_connector_state *connector_state) |
| 815 | { |
| 816 | struct nv50_head *head = nv50_head(connector_state->crtc); |
| 817 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 818 | if (mstc->port) { |
| 819 | struct nv50_mstm *mstm = mstc->mstm; |
| 820 | return &mstm->msto[head->base.index]->encoder; |
| 821 | } |
| 822 | return NULL; |
| 823 | } |
| 824 | |
| 825 | static struct drm_encoder * |
| 826 | nv50_mstc_best_encoder(struct drm_connector *connector) |
| 827 | { |
| 828 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 829 | if (mstc->port) { |
| 830 | struct nv50_mstm *mstm = mstc->mstm; |
| 831 | return &mstm->msto[0]->encoder; |
| 832 | } |
| 833 | return NULL; |
| 834 | } |
| 835 | |
| 836 | static enum drm_mode_status |
| 837 | nv50_mstc_mode_valid(struct drm_connector *connector, |
| 838 | struct drm_display_mode *mode) |
| 839 | { |
| 840 | return MODE_OK; |
| 841 | } |
| 842 | |
| 843 | static int |
| 844 | nv50_mstc_get_modes(struct drm_connector *connector) |
| 845 | { |
| 846 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 847 | int ret = 0; |
| 848 | |
| 849 | mstc->edid = drm_dp_mst_get_edid(&mstc->connector, mstc->port->mgr, mstc->port); |
| 850 | drm_mode_connector_update_edid_property(&mstc->connector, mstc->edid); |
Jani Nikula | d471ed0 | 2017-11-01 16:21:02 +0200 | [diff] [blame] | 851 | if (mstc->edid) |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 852 | ret = drm_add_edid_modes(&mstc->connector, mstc->edid); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 853 | |
| 854 | if (!mstc->connector.display_info.bpc) |
| 855 | mstc->connector.display_info.bpc = 8; |
| 856 | |
| 857 | if (mstc->native) |
| 858 | drm_mode_destroy(mstc->connector.dev, mstc->native); |
| 859 | mstc->native = nouveau_conn_native_mode(&mstc->connector); |
| 860 | return ret; |
| 861 | } |
| 862 | |
| 863 | static const struct drm_connector_helper_funcs |
| 864 | nv50_mstc_help = { |
| 865 | .get_modes = nv50_mstc_get_modes, |
| 866 | .mode_valid = nv50_mstc_mode_valid, |
| 867 | .best_encoder = nv50_mstc_best_encoder, |
| 868 | .atomic_best_encoder = nv50_mstc_atomic_best_encoder, |
| 869 | }; |
| 870 | |
| 871 | static enum drm_connector_status |
| 872 | nv50_mstc_detect(struct drm_connector *connector, bool force) |
| 873 | { |
| 874 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 875 | if (!mstc->port) |
| 876 | return connector_status_disconnected; |
| 877 | return drm_dp_mst_detect_port(connector, mstc->port->mgr, mstc->port); |
| 878 | } |
| 879 | |
| 880 | static void |
| 881 | nv50_mstc_destroy(struct drm_connector *connector) |
| 882 | { |
| 883 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 884 | drm_connector_cleanup(&mstc->connector); |
| 885 | kfree(mstc); |
| 886 | } |
| 887 | |
| 888 | static const struct drm_connector_funcs |
| 889 | nv50_mstc = { |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 890 | .reset = nouveau_conn_reset, |
| 891 | .detect = nv50_mstc_detect, |
| 892 | .fill_modes = drm_helper_probe_single_connector_modes, |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 893 | .destroy = nv50_mstc_destroy, |
| 894 | .atomic_duplicate_state = nouveau_conn_atomic_duplicate_state, |
| 895 | .atomic_destroy_state = nouveau_conn_atomic_destroy_state, |
| 896 | .atomic_set_property = nouveau_conn_atomic_set_property, |
| 897 | .atomic_get_property = nouveau_conn_atomic_get_property, |
| 898 | }; |
| 899 | |
| 900 | static int |
| 901 | nv50_mstc_new(struct nv50_mstm *mstm, struct drm_dp_mst_port *port, |
| 902 | const char *path, struct nv50_mstc **pmstc) |
| 903 | { |
| 904 | struct drm_device *dev = mstm->outp->base.base.dev; |
| 905 | struct nv50_mstc *mstc; |
| 906 | int ret, i; |
| 907 | |
| 908 | if (!(mstc = *pmstc = kzalloc(sizeof(*mstc), GFP_KERNEL))) |
| 909 | return -ENOMEM; |
| 910 | mstc->mstm = mstm; |
| 911 | mstc->port = port; |
| 912 | |
| 913 | ret = drm_connector_init(dev, &mstc->connector, &nv50_mstc, |
| 914 | DRM_MODE_CONNECTOR_DisplayPort); |
| 915 | if (ret) { |
| 916 | kfree(*pmstc); |
| 917 | *pmstc = NULL; |
| 918 | return ret; |
| 919 | } |
| 920 | |
| 921 | drm_connector_helper_add(&mstc->connector, &nv50_mstc_help); |
| 922 | |
| 923 | mstc->connector.funcs->reset(&mstc->connector); |
| 924 | nouveau_conn_attach_properties(&mstc->connector); |
| 925 | |
Colin Ian King | 27a451e | 2017-08-17 23:03:23 +0100 | [diff] [blame] | 926 | for (i = 0; i < ARRAY_SIZE(mstm->msto) && mstm->msto[i]; i++) |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 927 | drm_mode_connector_attach_encoder(&mstc->connector, &mstm->msto[i]->encoder); |
| 928 | |
| 929 | drm_object_attach_property(&mstc->connector.base, dev->mode_config.path_property, 0); |
| 930 | drm_object_attach_property(&mstc->connector.base, dev->mode_config.tile_property, 0); |
| 931 | drm_mode_connector_set_path_property(&mstc->connector, path); |
| 932 | return 0; |
| 933 | } |
| 934 | |
| 935 | static void |
| 936 | nv50_mstm_cleanup(struct nv50_mstm *mstm) |
| 937 | { |
| 938 | struct nouveau_drm *drm = nouveau_drm(mstm->outp->base.base.dev); |
| 939 | struct drm_encoder *encoder; |
| 940 | int ret; |
| 941 | |
| 942 | NV_ATOMIC(drm, "%s: mstm cleanup\n", mstm->outp->base.base.name); |
| 943 | ret = drm_dp_check_act_status(&mstm->mgr); |
| 944 | |
| 945 | ret = drm_dp_update_payload_part2(&mstm->mgr); |
| 946 | |
| 947 | drm_for_each_encoder(encoder, mstm->outp->base.base.dev) { |
| 948 | if (encoder->encoder_type == DRM_MODE_ENCODER_DPMST) { |
| 949 | struct nv50_msto *msto = nv50_msto(encoder); |
| 950 | struct nv50_mstc *mstc = msto->mstc; |
| 951 | if (mstc && mstc->mstm == mstm) |
| 952 | nv50_msto_cleanup(msto); |
| 953 | } |
| 954 | } |
| 955 | |
| 956 | mstm->modified = false; |
| 957 | } |
| 958 | |
| 959 | static void |
| 960 | nv50_mstm_prepare(struct nv50_mstm *mstm) |
| 961 | { |
| 962 | struct nouveau_drm *drm = nouveau_drm(mstm->outp->base.base.dev); |
| 963 | struct drm_encoder *encoder; |
| 964 | int ret; |
| 965 | |
| 966 | NV_ATOMIC(drm, "%s: mstm prepare\n", mstm->outp->base.base.name); |
| 967 | ret = drm_dp_update_payload_part1(&mstm->mgr); |
| 968 | |
| 969 | drm_for_each_encoder(encoder, mstm->outp->base.base.dev) { |
| 970 | if (encoder->encoder_type == DRM_MODE_ENCODER_DPMST) { |
| 971 | struct nv50_msto *msto = nv50_msto(encoder); |
| 972 | struct nv50_mstc *mstc = msto->mstc; |
| 973 | if (mstc && mstc->mstm == mstm) |
| 974 | nv50_msto_prepare(msto); |
| 975 | } |
| 976 | } |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 977 | |
| 978 | if (mstm->disabled) { |
| 979 | if (!mstm->links) |
| 980 | nv50_outp_release(mstm->outp); |
| 981 | mstm->disabled = false; |
| 982 | } |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 983 | } |
| 984 | |
| 985 | static void |
| 986 | nv50_mstm_hotplug(struct drm_dp_mst_topology_mgr *mgr) |
| 987 | { |
| 988 | struct nv50_mstm *mstm = nv50_mstm(mgr); |
| 989 | drm_kms_helper_hotplug_event(mstm->outp->base.base.dev); |
| 990 | } |
| 991 | |
| 992 | static void |
| 993 | nv50_mstm_destroy_connector(struct drm_dp_mst_topology_mgr *mgr, |
| 994 | struct drm_connector *connector) |
| 995 | { |
| 996 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
| 997 | struct nv50_mstc *mstc = nv50_mstc(connector); |
| 998 | |
| 999 | drm_connector_unregister(&mstc->connector); |
| 1000 | |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1001 | drm_fb_helper_remove_one_connector(&drm->fbcon->helper, &mstc->connector); |
Lyude Paul | 352672d | 2018-05-02 19:38:48 -0400 | [diff] [blame] | 1002 | |
| 1003 | drm_modeset_lock(&drm->dev->mode_config.connection_mutex, NULL); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1004 | mstc->port = NULL; |
Lyude Paul | 352672d | 2018-05-02 19:38:48 -0400 | [diff] [blame] | 1005 | drm_modeset_unlock(&drm->dev->mode_config.connection_mutex); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1006 | |
| 1007 | drm_connector_unreference(&mstc->connector); |
| 1008 | } |
| 1009 | |
| 1010 | static void |
| 1011 | nv50_mstm_register_connector(struct drm_connector *connector) |
| 1012 | { |
| 1013 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
| 1014 | |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1015 | drm_fb_helper_add_one_connector(&drm->fbcon->helper, connector); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1016 | |
| 1017 | drm_connector_register(connector); |
| 1018 | } |
| 1019 | |
| 1020 | static struct drm_connector * |
| 1021 | nv50_mstm_add_connector(struct drm_dp_mst_topology_mgr *mgr, |
| 1022 | struct drm_dp_mst_port *port, const char *path) |
| 1023 | { |
| 1024 | struct nv50_mstm *mstm = nv50_mstm(mgr); |
| 1025 | struct nv50_mstc *mstc; |
| 1026 | int ret; |
| 1027 | |
| 1028 | ret = nv50_mstc_new(mstm, port, path, &mstc); |
| 1029 | if (ret) { |
| 1030 | if (mstc) |
| 1031 | mstc->connector.funcs->destroy(&mstc->connector); |
| 1032 | return NULL; |
| 1033 | } |
| 1034 | |
| 1035 | return &mstc->connector; |
| 1036 | } |
| 1037 | |
| 1038 | static const struct drm_dp_mst_topology_cbs |
| 1039 | nv50_mstm = { |
| 1040 | .add_connector = nv50_mstm_add_connector, |
| 1041 | .register_connector = nv50_mstm_register_connector, |
| 1042 | .destroy_connector = nv50_mstm_destroy_connector, |
| 1043 | .hotplug = nv50_mstm_hotplug, |
| 1044 | }; |
| 1045 | |
| 1046 | void |
| 1047 | nv50_mstm_service(struct nv50_mstm *mstm) |
| 1048 | { |
Ben Skeggs | 227f66d | 2017-10-03 16:24:28 +1000 | [diff] [blame] | 1049 | struct drm_dp_aux *aux = mstm ? mstm->mgr.aux : NULL; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1050 | bool handled = true; |
| 1051 | int ret; |
| 1052 | u8 esi[8] = {}; |
| 1053 | |
Ben Skeggs | 227f66d | 2017-10-03 16:24:28 +1000 | [diff] [blame] | 1054 | if (!aux) |
| 1055 | return; |
| 1056 | |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1057 | while (handled) { |
| 1058 | ret = drm_dp_dpcd_read(aux, DP_SINK_COUNT_ESI, esi, 8); |
| 1059 | if (ret != 8) { |
| 1060 | drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, false); |
| 1061 | return; |
| 1062 | } |
| 1063 | |
| 1064 | drm_dp_mst_hpd_irq(&mstm->mgr, esi, &handled); |
| 1065 | if (!handled) |
| 1066 | break; |
| 1067 | |
| 1068 | drm_dp_dpcd_write(aux, DP_SINK_COUNT_ESI + 1, &esi[1], 3); |
| 1069 | } |
| 1070 | } |
| 1071 | |
| 1072 | void |
| 1073 | nv50_mstm_remove(struct nv50_mstm *mstm) |
| 1074 | { |
| 1075 | if (mstm) |
| 1076 | drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, false); |
| 1077 | } |
| 1078 | |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1079 | static int |
| 1080 | nv50_mstm_enable(struct nv50_mstm *mstm, u8 dpcd, int state) |
| 1081 | { |
| 1082 | struct nouveau_encoder *outp = mstm->outp; |
| 1083 | struct { |
| 1084 | struct nv50_disp_mthd_v1 base; |
| 1085 | struct nv50_disp_sor_dp_mst_link_v0 mst; |
| 1086 | } args = { |
| 1087 | .base.version = 1, |
| 1088 | .base.method = NV50_DISP_MTHD_V1_SOR_DP_MST_LINK, |
| 1089 | .base.hasht = outp->dcb->hasht, |
| 1090 | .base.hashm = outp->dcb->hashm, |
| 1091 | .mst.state = state, |
| 1092 | }; |
| 1093 | struct nouveau_drm *drm = nouveau_drm(outp->base.base.dev); |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1094 | struct nvif_object *disp = &drm->display->disp.object; |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1095 | int ret; |
| 1096 | |
| 1097 | if (dpcd >= 0x12) { |
| 1098 | ret = drm_dp_dpcd_readb(mstm->mgr.aux, DP_MSTM_CTRL, &dpcd); |
| 1099 | if (ret < 0) |
| 1100 | return ret; |
| 1101 | |
| 1102 | dpcd &= ~DP_MST_EN; |
| 1103 | if (state) |
| 1104 | dpcd |= DP_MST_EN; |
| 1105 | |
| 1106 | ret = drm_dp_dpcd_writeb(mstm->mgr.aux, DP_MSTM_CTRL, dpcd); |
| 1107 | if (ret < 0) |
| 1108 | return ret; |
| 1109 | } |
| 1110 | |
| 1111 | return nvif_mthd(disp, 0, &args, sizeof(args)); |
| 1112 | } |
| 1113 | |
| 1114 | int |
| 1115 | nv50_mstm_detect(struct nv50_mstm *mstm, u8 dpcd[8], int allow) |
| 1116 | { |
| 1117 | int ret, state = 0; |
| 1118 | |
| 1119 | if (!mstm) |
| 1120 | return 0; |
| 1121 | |
Ben Skeggs | 3ca03ca | 2016-11-07 14:51:53 +1000 | [diff] [blame] | 1122 | if (dpcd[0] >= 0x12) { |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1123 | ret = drm_dp_dpcd_readb(mstm->mgr.aux, DP_MSTM_CAP, &dpcd[1]); |
| 1124 | if (ret < 0) |
| 1125 | return ret; |
| 1126 | |
Ben Skeggs | 3ca03ca | 2016-11-07 14:51:53 +1000 | [diff] [blame] | 1127 | if (!(dpcd[1] & DP_MST_CAP)) |
| 1128 | dpcd[0] = 0x11; |
| 1129 | else |
| 1130 | state = allow; |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1131 | } |
| 1132 | |
| 1133 | ret = nv50_mstm_enable(mstm, dpcd[0], state); |
| 1134 | if (ret) |
| 1135 | return ret; |
| 1136 | |
| 1137 | ret = drm_dp_mst_topology_mgr_set_mst(&mstm->mgr, state); |
| 1138 | if (ret) |
| 1139 | return nv50_mstm_enable(mstm, dpcd[0], 0); |
| 1140 | |
| 1141 | return mstm->mgr.mst_state; |
| 1142 | } |
| 1143 | |
| 1144 | static void |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1145 | nv50_mstm_fini(struct nv50_mstm *mstm) |
| 1146 | { |
| 1147 | if (mstm && mstm->mgr.mst_state) |
| 1148 | drm_dp_mst_topology_mgr_suspend(&mstm->mgr); |
| 1149 | } |
| 1150 | |
| 1151 | static void |
| 1152 | nv50_mstm_init(struct nv50_mstm *mstm) |
| 1153 | { |
| 1154 | if (mstm && mstm->mgr.mst_state) |
| 1155 | drm_dp_mst_topology_mgr_resume(&mstm->mgr); |
| 1156 | } |
| 1157 | |
| 1158 | static void |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1159 | nv50_mstm_del(struct nv50_mstm **pmstm) |
| 1160 | { |
| 1161 | struct nv50_mstm *mstm = *pmstm; |
| 1162 | if (mstm) { |
| 1163 | kfree(*pmstm); |
| 1164 | *pmstm = NULL; |
| 1165 | } |
| 1166 | } |
| 1167 | |
| 1168 | static int |
| 1169 | nv50_mstm_new(struct nouveau_encoder *outp, struct drm_dp_aux *aux, int aux_max, |
| 1170 | int conn_base_id, struct nv50_mstm **pmstm) |
| 1171 | { |
| 1172 | const int max_payloads = hweight8(outp->dcb->heads); |
| 1173 | struct drm_device *dev = outp->base.base.dev; |
| 1174 | struct nv50_mstm *mstm; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1175 | int ret, i; |
| 1176 | u8 dpcd; |
| 1177 | |
| 1178 | /* This is a workaround for some monitors not functioning |
| 1179 | * correctly in MST mode on initial module load. I think |
| 1180 | * some bad interaction with the VBIOS may be responsible. |
| 1181 | * |
| 1182 | * A good ol' off and on again seems to work here ;) |
| 1183 | */ |
| 1184 | ret = drm_dp_dpcd_readb(aux, DP_DPCD_REV, &dpcd); |
| 1185 | if (ret >= 0 && dpcd >= 0x12) |
| 1186 | drm_dp_dpcd_writeb(aux, DP_MSTM_CTRL, 0); |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1187 | |
| 1188 | if (!(mstm = *pmstm = kzalloc(sizeof(*mstm), GFP_KERNEL))) |
| 1189 | return -ENOMEM; |
| 1190 | mstm->outp = outp; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1191 | mstm->mgr.cbs = &nv50_mstm; |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1192 | |
Dhinakaran Pandiyan | 7b0a89a | 2017-01-24 15:49:29 -0800 | [diff] [blame] | 1193 | ret = drm_dp_mst_topology_mgr_init(&mstm->mgr, dev, aux, aux_max, |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1194 | max_payloads, conn_base_id); |
| 1195 | if (ret) |
| 1196 | return ret; |
| 1197 | |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1198 | for (i = 0; i < max_payloads; i++) { |
| 1199 | ret = nv50_msto_new(dev, outp->dcb->heads, outp->base.base.name, |
| 1200 | i, &mstm->msto[i]); |
| 1201 | if (ret) |
| 1202 | return ret; |
| 1203 | } |
| 1204 | |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1205 | return 0; |
| 1206 | } |
| 1207 | |
| 1208 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1209 | * SOR |
| 1210 | *****************************************************************************/ |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1211 | static void |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1212 | nv50_sor_update(struct nouveau_encoder *nv_encoder, u8 head, |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1213 | struct nv50_head_atom *asyh, u8 proto, u8 depth) |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1214 | { |
Ben Skeggs | 9ca6f1e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1215 | struct nv50_disp *disp = nv50_disp(nv_encoder->base.base.dev); |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1216 | struct nv50_core *core = disp->core; |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1217 | |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1218 | if (!asyh) { |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1219 | nv_encoder->ctrl &= ~BIT(head); |
| 1220 | if (!(nv_encoder->ctrl & 0x0000000f)) |
| 1221 | nv_encoder->ctrl = 0; |
| 1222 | } else { |
| 1223 | nv_encoder->ctrl |= proto << 8; |
| 1224 | nv_encoder->ctrl |= BIT(head); |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1225 | asyh->or.depth = depth; |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1226 | } |
| 1227 | |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1228 | core->func->sor->ctrl(core, nv_encoder->or, nv_encoder->ctrl, asyh); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1229 | } |
| 1230 | |
| 1231 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1232 | nv50_sor_disable(struct drm_encoder *encoder) |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 1233 | { |
| 1234 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1235 | struct nouveau_crtc *nv_crtc = nouveau_crtc(nv_encoder->crtc); |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1236 | |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1237 | nv_encoder->crtc = NULL; |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1238 | |
| 1239 | if (nv_crtc) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1240 | struct nvkm_i2c_aux *aux = nv_encoder->aux; |
| 1241 | u8 pwr; |
| 1242 | |
| 1243 | if (aux) { |
| 1244 | int ret = nvkm_rdaux(aux, DP_SET_POWER, &pwr, 1); |
| 1245 | if (ret == 0) { |
| 1246 | pwr &= ~DP_SET_POWER_MASK; |
| 1247 | pwr |= DP_SET_POWER_D3; |
| 1248 | nvkm_wraux(aux, DP_SET_POWER, &pwr, 1); |
| 1249 | } |
| 1250 | } |
| 1251 | |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1252 | nv_encoder->update(nv_encoder, nv_crtc->index, NULL, 0, 0); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1253 | nv50_audio_disable(encoder, nv_crtc); |
| 1254 | nv50_hdmi_disable(&nv_encoder->base.base, nv_crtc); |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 1255 | nv50_outp_release(nv_encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1256 | } |
Ben Skeggs | 4cbb0f8 | 2012-03-12 15:23:44 +1000 | [diff] [blame] | 1257 | } |
| 1258 | |
| 1259 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1260 | nv50_sor_enable(struct drm_encoder *encoder) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1261 | { |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1262 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1263 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1264 | struct nv50_head_atom *asyh = nv50_head_atom(nv_crtc->base.state); |
| 1265 | struct drm_display_mode *mode = &asyh->state.adjusted_mode; |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1266 | struct { |
| 1267 | struct nv50_disp_mthd_v1 base; |
| 1268 | struct nv50_disp_sor_lvds_script_v0 lvds; |
| 1269 | } lvds = { |
| 1270 | .base.version = 1, |
| 1271 | .base.method = NV50_DISP_MTHD_V1_SOR_LVDS_SCRIPT, |
| 1272 | .base.hasht = nv_encoder->dcb->hasht, |
| 1273 | .base.hashm = nv_encoder->dcb->hashm, |
| 1274 | }; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1275 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 78951d2 | 2011-11-11 18:13:13 +1000 | [diff] [blame] | 1276 | struct drm_device *dev = encoder->dev; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1277 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1278 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 1279 | struct nvbios *bios = &drm->vbios; |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1280 | u8 proto = 0xf; |
| 1281 | u8 depth = 0x0; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1282 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1283 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1284 | nv_encoder->crtc = encoder->crtc; |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 1285 | nv50_outp_acquire(nv_encoder); |
Ben Skeggs | e84a35a | 2014-06-05 10:59:55 +1000 | [diff] [blame] | 1286 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1287 | switch (nv_encoder->dcb->type) { |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 1288 | case DCB_OUTPUT_TMDS: |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 1289 | if (nv_encoder->link & 1) { |
Hauke Mehrtens | 16ef53a9 | 2015-11-03 21:00:10 -0500 | [diff] [blame] | 1290 | proto = 0x1; |
| 1291 | /* Only enable dual-link if: |
| 1292 | * - Need to (i.e. rate > 165MHz) |
| 1293 | * - DCB says we can |
| 1294 | * - Not an HDMI monitor, since there's no dual-link |
| 1295 | * on HDMI. |
| 1296 | */ |
| 1297 | if (mode->clock >= 165000 && |
| 1298 | nv_encoder->dcb->duallink_possible && |
| 1299 | !drm_detect_hdmi_monitor(nv_connector->edid)) |
| 1300 | proto |= 0x4; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1301 | } else { |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1302 | proto = 0x2; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1303 | } |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1304 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1305 | nv50_hdmi_enable(&nv_encoder->base.base, mode); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1306 | break; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 1307 | case DCB_OUTPUT_LVDS: |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1308 | proto = 0x0; |
| 1309 | |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1310 | if (bios->fp_no_ddc) { |
| 1311 | if (bios->fp.dual_link) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1312 | lvds.lvds.script |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1313 | if (bios->fp.if_is_24bit) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1314 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1315 | } else { |
Ben Skeggs | befb51e | 2011-11-18 10:23:59 +1000 | [diff] [blame] | 1316 | if (nv_connector->type == DCB_CONNECTOR_LVDS_SPWG) { |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1317 | if (((u8 *)nv_connector->edid)[121] == 2) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1318 | lvds.lvds.script |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1319 | } else |
| 1320 | if (mode->clock >= bios->fp.duallink_transition_clk) { |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1321 | lvds.lvds.script |= 0x0100; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1322 | } |
| 1323 | |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1324 | if (lvds.lvds.script & 0x0100) { |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1325 | if (bios->fp.strapless_is_24bit & 2) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1326 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1327 | } else { |
| 1328 | if (bios->fp.strapless_is_24bit & 1) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1329 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1330 | } |
| 1331 | |
| 1332 | if (nv_connector->base.display_info.bpc == 8) |
Ben Skeggs | a3761fa | 2014-08-10 04:10:27 +1000 | [diff] [blame] | 1333 | lvds.lvds.script |= 0x0200; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1334 | } |
Ben Skeggs | 4a230fa | 2012-11-09 11:25:37 +1000 | [diff] [blame] | 1335 | |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1336 | nvif_mthd(&disp->disp->object, 0, &lvds, sizeof(lvds)); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1337 | break; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 1338 | case DCB_OUTPUT_DP: |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1339 | if (nv_connector->base.display_info.bpc == 6) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1340 | depth = 0x2; |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1341 | else |
| 1342 | if (nv_connector->base.display_info.bpc == 8) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1343 | depth = 0x5; |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1344 | else |
Ben Skeggs | bf2c886 | 2012-11-21 14:49:54 +1000 | [diff] [blame] | 1345 | depth = 0x6; |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1346 | |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 1347 | if (nv_encoder->link & 1) |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1348 | proto = 0x8; |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1349 | else |
Ben Skeggs | 419e8dc | 2012-11-16 11:40:34 +1000 | [diff] [blame] | 1350 | proto = 0x9; |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1351 | |
| 1352 | nv50_audio_enable(encoder, mode); |
Ben Skeggs | 6e83fda | 2012-03-11 01:28:48 +1000 | [diff] [blame] | 1353 | break; |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1354 | default: |
Ben Skeggs | af7db03 | 2016-03-03 12:56:33 +1000 | [diff] [blame] | 1355 | BUG(); |
Ben Skeggs | 3b6d83d1 | 2011-07-08 12:52:14 +1000 | [diff] [blame] | 1356 | break; |
| 1357 | } |
Ben Skeggs | ff8ff50 | 2011-07-08 11:53:37 +1000 | [diff] [blame] | 1358 | |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1359 | nv_encoder->update(nv_encoder, nv_crtc->index, asyh, proto, depth); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1360 | } |
| 1361 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1362 | static const struct drm_encoder_helper_funcs |
| 1363 | nv50_sor_help = { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1364 | .atomic_check = nv50_outp_atomic_check, |
| 1365 | .enable = nv50_sor_enable, |
| 1366 | .disable = nv50_sor_disable, |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1367 | }; |
| 1368 | |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1369 | static void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1370 | nv50_sor_destroy(struct drm_encoder *encoder) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1371 | { |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1372 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1373 | nv50_mstm_del(&nv_encoder->dp.mstm); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1374 | drm_encoder_cleanup(encoder); |
| 1375 | kfree(encoder); |
| 1376 | } |
| 1377 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1378 | static const struct drm_encoder_funcs |
| 1379 | nv50_sor_func = { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1380 | .destroy = nv50_sor_destroy, |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1381 | }; |
| 1382 | |
| 1383 | static int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 1384 | nv50_sor_create(struct drm_connector *connector, struct dcb_output *dcbe) |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1385 | { |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1386 | struct nouveau_connector *nv_connector = nouveau_connector(connector); |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1387 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
Ben Skeggs | 34508f9 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1388 | struct nvkm_bios *bios = nvxx_bios(&drm->client.device); |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 1389 | struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1390 | struct nouveau_encoder *nv_encoder; |
| 1391 | struct drm_encoder *encoder; |
Ben Skeggs | 34508f9 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1392 | u8 ver, hdr, cnt, len; |
| 1393 | u32 data; |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1394 | int type, ret; |
Ben Skeggs | 5ed5020 | 2013-02-11 20:15:03 +1000 | [diff] [blame] | 1395 | |
| 1396 | switch (dcbe->type) { |
| 1397 | case DCB_OUTPUT_LVDS: type = DRM_MODE_ENCODER_LVDS; break; |
| 1398 | case DCB_OUTPUT_TMDS: |
| 1399 | case DCB_OUTPUT_DP: |
| 1400 | default: |
| 1401 | type = DRM_MODE_ENCODER_TMDS; |
| 1402 | break; |
| 1403 | } |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1404 | |
| 1405 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 1406 | if (!nv_encoder) |
| 1407 | return -ENOMEM; |
| 1408 | nv_encoder->dcb = dcbe; |
Ben Skeggs | d665c7e | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1409 | nv_encoder->update = nv50_sor_update; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1410 | |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1411 | encoder = to_drm_encoder(nv_encoder); |
| 1412 | encoder->possible_crtcs = dcbe->heads; |
| 1413 | encoder->possible_clones = 0; |
Ben Skeggs | 5a223da | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1414 | drm_encoder_init(connector->dev, encoder, &nv50_sor_func, type, |
| 1415 | "sor-%04x-%04x", dcbe->hasht, dcbe->hashm); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1416 | drm_encoder_helper_add(encoder, &nv50_sor_help); |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1417 | |
| 1418 | drm_mode_connector_attach_encoder(connector, encoder); |
| 1419 | |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1420 | if (dcbe->type == DCB_OUTPUT_DP) { |
Ben Skeggs | 13a8651 | 2017-07-19 16:49:59 +1000 | [diff] [blame] | 1421 | struct nv50_disp *disp = nv50_disp(encoder->dev); |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1422 | struct nvkm_i2c_aux *aux = |
| 1423 | nvkm_i2c_aux_find(i2c, dcbe->i2c_index); |
| 1424 | if (aux) { |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1425 | if (disp->disp->object.oclass < GF110_DISP) { |
Ben Skeggs | 13a8651 | 2017-07-19 16:49:59 +1000 | [diff] [blame] | 1426 | /* HW has no support for address-only |
| 1427 | * transactions, so we're required to |
| 1428 | * use custom I2C-over-AUX code. |
| 1429 | */ |
| 1430 | nv_encoder->i2c = &aux->i2c; |
| 1431 | } else { |
| 1432 | nv_encoder->i2c = &nv_connector->aux.ddc; |
| 1433 | } |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1434 | nv_encoder->aux = aux; |
| 1435 | } |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1436 | |
Ben Skeggs | 34508f9 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1437 | if ((data = nvbios_dp_table(bios, &ver, &hdr, &cnt, &len)) && |
| 1438 | ver >= 0x40 && (nvbios_rd08(bios, data + 0x08) & 0x04)) { |
Ben Skeggs | 52aa30f | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1439 | ret = nv50_mstm_new(nv_encoder, &nv_connector->aux, 16, |
| 1440 | nv_connector->base.base.id, |
| 1441 | &nv_encoder->dp.mstm); |
| 1442 | if (ret) |
| 1443 | return ret; |
| 1444 | } |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1445 | } else { |
| 1446 | struct nvkm_i2c_bus *bus = |
| 1447 | nvkm_i2c_bus_find(i2c, dcbe->i2c_index); |
| 1448 | if (bus) |
| 1449 | nv_encoder->i2c = &bus->i2c; |
| 1450 | } |
| 1451 | |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 1452 | return 0; |
| 1453 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 1454 | |
| 1455 | /****************************************************************************** |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1456 | * PIOR |
| 1457 | *****************************************************************************/ |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1458 | static int |
| 1459 | nv50_pior_atomic_check(struct drm_encoder *encoder, |
| 1460 | struct drm_crtc_state *crtc_state, |
| 1461 | struct drm_connector_state *conn_state) |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1462 | { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1463 | int ret = nv50_outp_atomic_check(encoder, crtc_state, conn_state); |
| 1464 | if (ret) |
| 1465 | return ret; |
| 1466 | crtc_state->adjusted_mode.clock *= 2; |
| 1467 | return 0; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1468 | } |
| 1469 | |
| 1470 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1471 | nv50_pior_disable(struct drm_encoder *encoder) |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1472 | { |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1473 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1474 | struct nv50_core *core = nv50_disp(encoder->dev)->core; |
| 1475 | if (nv_encoder->crtc) |
| 1476 | core->func->pior->ctrl(core, nv_encoder->or, 0x00000000, NULL); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1477 | nv_encoder->crtc = NULL; |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 1478 | nv50_outp_release(nv_encoder); |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1479 | } |
| 1480 | |
| 1481 | static void |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1482 | nv50_pior_enable(struct drm_encoder *encoder) |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1483 | { |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1484 | struct nouveau_encoder *nv_encoder = nouveau_encoder(encoder); |
| 1485 | struct nouveau_crtc *nv_crtc = nouveau_crtc(encoder->crtc); |
| 1486 | struct nouveau_connector *nv_connector; |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1487 | struct nv50_head_atom *asyh = nv50_head_atom(nv_crtc->base.state); |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1488 | struct nv50_core *core = nv50_disp(encoder->dev)->core; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1489 | u8 owner = 1 << nv_crtc->index; |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1490 | u8 proto; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1491 | |
Ben Skeggs | 6c22ea3 | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 1492 | nv50_outp_acquire(nv_encoder); |
| 1493 | |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1494 | nv_connector = nouveau_encoder_connector_get(nv_encoder); |
| 1495 | switch (nv_connector->base.display_info.bpc) { |
Ben Skeggs | 2ca7fb5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1496 | case 10: asyh->or.depth = 0x6; break; |
| 1497 | case 8: asyh->or.depth = 0x5; break; |
| 1498 | case 6: asyh->or.depth = 0x2; break; |
| 1499 | default: asyh->or.depth = 0x0; break; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1500 | } |
| 1501 | |
| 1502 | switch (nv_encoder->dcb->type) { |
| 1503 | case DCB_OUTPUT_TMDS: |
| 1504 | case DCB_OUTPUT_DP: |
| 1505 | proto = 0x0; |
| 1506 | break; |
| 1507 | default: |
Ben Skeggs | af7db03 | 2016-03-03 12:56:33 +1000 | [diff] [blame] | 1508 | BUG(); |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1509 | break; |
| 1510 | } |
| 1511 | |
Ben Skeggs | 0a36877 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1512 | core->func->pior->ctrl(core, nv_encoder->or, (proto << 8) | owner, asyh); |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1513 | nv_encoder->crtc = encoder->crtc; |
| 1514 | } |
| 1515 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1516 | static const struct drm_encoder_helper_funcs |
| 1517 | nv50_pior_help = { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1518 | .atomic_check = nv50_pior_atomic_check, |
| 1519 | .enable = nv50_pior_enable, |
| 1520 | .disable = nv50_pior_disable, |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1521 | }; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1522 | |
| 1523 | static void |
| 1524 | nv50_pior_destroy(struct drm_encoder *encoder) |
| 1525 | { |
| 1526 | drm_encoder_cleanup(encoder); |
| 1527 | kfree(encoder); |
| 1528 | } |
| 1529 | |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1530 | static const struct drm_encoder_funcs |
| 1531 | nv50_pior_func = { |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1532 | .destroy = nv50_pior_destroy, |
| 1533 | }; |
| 1534 | |
| 1535 | static int |
| 1536 | nv50_pior_create(struct drm_connector *connector, struct dcb_output *dcbe) |
| 1537 | { |
| 1538 | struct nouveau_drm *drm = nouveau_drm(connector->dev); |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 1539 | struct nvkm_i2c *i2c = nvxx_i2c(&drm->client.device); |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1540 | struct nvkm_i2c_bus *bus = NULL; |
| 1541 | struct nvkm_i2c_aux *aux = NULL; |
| 1542 | struct i2c_adapter *ddc; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1543 | struct nouveau_encoder *nv_encoder; |
| 1544 | struct drm_encoder *encoder; |
| 1545 | int type; |
| 1546 | |
| 1547 | switch (dcbe->type) { |
| 1548 | case DCB_OUTPUT_TMDS: |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1549 | bus = nvkm_i2c_bus_find(i2c, NVKM_I2C_BUS_EXT(dcbe->extdev)); |
| 1550 | ddc = bus ? &bus->i2c : NULL; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1551 | type = DRM_MODE_ENCODER_TMDS; |
| 1552 | break; |
| 1553 | case DCB_OUTPUT_DP: |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1554 | aux = nvkm_i2c_aux_find(i2c, NVKM_I2C_AUX_EXT(dcbe->extdev)); |
Ben Skeggs | 62b290f | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1555 | ddc = aux ? &aux->i2c : NULL; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1556 | type = DRM_MODE_ENCODER_TMDS; |
| 1557 | break; |
| 1558 | default: |
| 1559 | return -ENODEV; |
| 1560 | } |
| 1561 | |
| 1562 | nv_encoder = kzalloc(sizeof(*nv_encoder), GFP_KERNEL); |
| 1563 | if (!nv_encoder) |
| 1564 | return -ENOMEM; |
| 1565 | nv_encoder->dcb = dcbe; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1566 | nv_encoder->i2c = ddc; |
Ben Skeggs | 2aa5eac | 2015-08-20 14:54:15 +1000 | [diff] [blame] | 1567 | nv_encoder->aux = aux; |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1568 | |
| 1569 | encoder = to_drm_encoder(nv_encoder); |
| 1570 | encoder->possible_crtcs = dcbe->heads; |
| 1571 | encoder->possible_clones = 0; |
Ben Skeggs | 5a223da | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1572 | drm_encoder_init(connector->dev, encoder, &nv50_pior_func, type, |
| 1573 | "pior-%04x-%04x", dcbe->hasht, dcbe->hashm); |
Ben Skeggs | f20c665 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1574 | drm_encoder_helper_add(encoder, &nv50_pior_help); |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 1575 | |
| 1576 | drm_mode_connector_attach_encoder(connector, encoder); |
| 1577 | return 0; |
| 1578 | } |
| 1579 | |
| 1580 | /****************************************************************************** |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1581 | * Atomic |
| 1582 | *****************************************************************************/ |
| 1583 | |
| 1584 | static void |
Ben Skeggs | 53e0a3e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1585 | nv50_disp_atomic_commit_core(struct nouveau_drm *drm, u32 *interlock) |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1586 | { |
| 1587 | struct nv50_disp *disp = nv50_disp(drm->dev); |
Ben Skeggs | 09e1b78 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1588 | struct nv50_core *core = disp->core; |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1589 | struct nv50_mstm *mstm; |
| 1590 | struct drm_encoder *encoder; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1591 | |
Ben Skeggs | 53e0a3e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1592 | NV_ATOMIC(drm, "commit core %08x\n", interlock[NV50_DISP_INTERLOCK_BASE]); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1593 | |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1594 | drm_for_each_encoder(encoder, drm->dev) { |
| 1595 | if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) { |
| 1596 | mstm = nouveau_encoder(encoder)->dp.mstm; |
| 1597 | if (mstm && mstm->modified) |
| 1598 | nv50_mstm_prepare(mstm); |
| 1599 | } |
| 1600 | } |
| 1601 | |
Ben Skeggs | 09e1b78 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1602 | core->func->ntfy_init(disp->sync, NV50_DISP_CORE_NTFY); |
| 1603 | core->func->update(core, interlock, true); |
| 1604 | if (core->func->ntfy_wait_done(disp->sync, NV50_DISP_CORE_NTFY, |
| 1605 | disp->core->chan.base.device)) |
| 1606 | NV_ERROR(drm, "core notifier timeout\n"); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1607 | |
| 1608 | drm_for_each_encoder(encoder, drm->dev) { |
| 1609 | if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) { |
| 1610 | mstm = nouveau_encoder(encoder)->dp.mstm; |
| 1611 | if (mstm && mstm->modified) |
| 1612 | nv50_mstm_cleanup(mstm); |
| 1613 | } |
| 1614 | } |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1615 | } |
| 1616 | |
| 1617 | static void |
| 1618 | nv50_disp_atomic_commit_tail(struct drm_atomic_state *state) |
| 1619 | { |
| 1620 | struct drm_device *dev = state->dev; |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1621 | struct drm_crtc_state *new_crtc_state, *old_crtc_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1622 | struct drm_crtc *crtc; |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1623 | struct drm_plane_state *new_plane_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1624 | struct drm_plane *plane; |
| 1625 | struct nouveau_drm *drm = nouveau_drm(dev); |
| 1626 | struct nv50_disp *disp = nv50_disp(dev); |
| 1627 | struct nv50_atom *atom = nv50_atom(state); |
| 1628 | struct nv50_outp_atom *outp, *outt; |
Ben Skeggs | 53e0a3e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1629 | u32 interlock[NV50_DISP_INTERLOCK__SIZE] = {}; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1630 | int i; |
| 1631 | |
| 1632 | NV_ATOMIC(drm, "commit %d %d\n", atom->lock_core, atom->flush_disable); |
| 1633 | drm_atomic_helper_wait_for_fences(dev, state, false); |
| 1634 | drm_atomic_helper_wait_for_dependencies(state); |
| 1635 | drm_atomic_helper_update_legacy_modeset_state(dev, state); |
| 1636 | |
| 1637 | if (atom->lock_core) |
| 1638 | mutex_lock(&disp->mutex); |
| 1639 | |
| 1640 | /* Disable head(s). */ |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1641 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1642 | struct nv50_head_atom *asyh = nv50_head_atom(new_crtc_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1643 | struct nv50_head *head = nv50_head(crtc); |
| 1644 | |
| 1645 | NV_ATOMIC(drm, "%s: clr %04x (set %04x)\n", crtc->name, |
| 1646 | asyh->clr.mask, asyh->set.mask); |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1647 | if (old_crtc_state->active && !new_crtc_state->active) |
Ben Skeggs | 4a5431a | 2017-07-24 11:01:52 +1000 | [diff] [blame] | 1648 | drm_crtc_vblank_off(crtc); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1649 | |
| 1650 | if (asyh->clr.mask) { |
| 1651 | nv50_head_flush_clr(head, asyh, atom->flush_disable); |
Ben Skeggs | 53e0a3e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1652 | interlock[NV50_DISP_INTERLOCK_CORE] |= 1; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1653 | } |
| 1654 | } |
| 1655 | |
| 1656 | /* Disable plane(s). */ |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1657 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
| 1658 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1659 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 1660 | |
| 1661 | NV_ATOMIC(drm, "%s: clr %02x (set %02x)\n", plane->name, |
| 1662 | asyw->clr.mask, asyw->set.mask); |
| 1663 | if (!asyw->clr.mask) |
| 1664 | continue; |
| 1665 | |
Ben Skeggs | 53e0a3e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1666 | nv50_wndw_flush_clr(wndw, interlock, atom->flush_disable, asyw); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1667 | } |
| 1668 | |
| 1669 | /* Disable output path(s). */ |
| 1670 | list_for_each_entry(outp, &atom->outp, head) { |
| 1671 | const struct drm_encoder_helper_funcs *help; |
| 1672 | struct drm_encoder *encoder; |
| 1673 | |
| 1674 | encoder = outp->encoder; |
| 1675 | help = encoder->helper_private; |
| 1676 | |
| 1677 | NV_ATOMIC(drm, "%s: clr %02x (set %02x)\n", encoder->name, |
| 1678 | outp->clr.mask, outp->set.mask); |
| 1679 | |
| 1680 | if (outp->clr.mask) { |
| 1681 | help->disable(encoder); |
Ben Skeggs | 53e0a3e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1682 | interlock[NV50_DISP_INTERLOCK_CORE] |= 1; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1683 | if (outp->flush_disable) { |
Ben Skeggs | 53e0a3e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1684 | nv50_disp_atomic_commit_core(drm, interlock); |
| 1685 | memset(interlock, 0x00, sizeof(interlock)); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1686 | } |
| 1687 | } |
| 1688 | } |
| 1689 | |
| 1690 | /* Flush disable. */ |
Ben Skeggs | 53e0a3e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1691 | if (interlock[NV50_DISP_INTERLOCK_CORE]) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1692 | if (atom->flush_disable) { |
Ben Skeggs | 04fc14b | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1693 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
| 1694 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 1695 | if (interlock[wndw->interlock.type] & wndw->interlock.data) { |
| 1696 | if (wndw->func->update) |
| 1697 | wndw->func->update(wndw, interlock); |
| 1698 | } |
| 1699 | } |
| 1700 | |
Ben Skeggs | 53e0a3e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1701 | nv50_disp_atomic_commit_core(drm, interlock); |
| 1702 | memset(interlock, 0x00, sizeof(interlock)); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1703 | } |
| 1704 | } |
| 1705 | |
| 1706 | /* Update output path(s). */ |
| 1707 | list_for_each_entry_safe(outp, outt, &atom->outp, head) { |
| 1708 | const struct drm_encoder_helper_funcs *help; |
| 1709 | struct drm_encoder *encoder; |
| 1710 | |
| 1711 | encoder = outp->encoder; |
| 1712 | help = encoder->helper_private; |
| 1713 | |
| 1714 | NV_ATOMIC(drm, "%s: set %02x (clr %02x)\n", encoder->name, |
| 1715 | outp->set.mask, outp->clr.mask); |
| 1716 | |
| 1717 | if (outp->set.mask) { |
| 1718 | help->enable(encoder); |
Ben Skeggs | 53e0a3e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1719 | interlock[NV50_DISP_INTERLOCK_CORE] = 1; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1720 | } |
| 1721 | |
| 1722 | list_del(&outp->head); |
| 1723 | kfree(outp); |
| 1724 | } |
| 1725 | |
| 1726 | /* Update head(s). */ |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1727 | for_each_oldnew_crtc_in_state(state, crtc, old_crtc_state, new_crtc_state, i) { |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1728 | struct nv50_head_atom *asyh = nv50_head_atom(new_crtc_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1729 | struct nv50_head *head = nv50_head(crtc); |
| 1730 | |
| 1731 | NV_ATOMIC(drm, "%s: set %04x (clr %04x)\n", crtc->name, |
| 1732 | asyh->set.mask, asyh->clr.mask); |
| 1733 | |
| 1734 | if (asyh->set.mask) { |
| 1735 | nv50_head_flush_set(head, asyh); |
Ben Skeggs | 53e0a3e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1736 | interlock[NV50_DISP_INTERLOCK_CORE] = 1; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1737 | } |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1738 | |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1739 | if (new_crtc_state->active) { |
| 1740 | if (!old_crtc_state->active) |
Ben Skeggs | 4a5431a | 2017-07-24 11:01:52 +1000 | [diff] [blame] | 1741 | drm_crtc_vblank_on(crtc); |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1742 | if (new_crtc_state->event) |
Ben Skeggs | 4a5431a | 2017-07-24 11:01:52 +1000 | [diff] [blame] | 1743 | drm_crtc_vblank_get(crtc); |
| 1744 | } |
Ben Skeggs | 2b50789 | 2017-01-24 09:32:26 +1000 | [diff] [blame] | 1745 | } |
| 1746 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1747 | /* Update plane(s). */ |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1748 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
| 1749 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1750 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 1751 | |
| 1752 | NV_ATOMIC(drm, "%s: set %02x (clr %02x)\n", plane->name, |
| 1753 | asyw->set.mask, asyw->clr.mask); |
| 1754 | if ( !asyw->set.mask && |
| 1755 | (!asyw->clr.mask || atom->flush_disable)) |
| 1756 | continue; |
| 1757 | |
Ben Skeggs | 53e0a3e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1758 | nv50_wndw_flush_set(wndw, interlock, asyw); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1759 | } |
| 1760 | |
| 1761 | /* Flush update. */ |
Ben Skeggs | 04fc14b | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1762 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
| 1763 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 1764 | if (interlock[wndw->interlock.type] & wndw->interlock.data) { |
| 1765 | if (wndw->func->update) |
| 1766 | wndw->func->update(wndw, interlock); |
| 1767 | } |
| 1768 | } |
| 1769 | |
Ben Skeggs | 53e0a3e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1770 | if (interlock[NV50_DISP_INTERLOCK_CORE]) { |
| 1771 | if (interlock[NV50_DISP_INTERLOCK_BASE] || |
| 1772 | !atom->state.legacy_cursor_update) |
| 1773 | nv50_disp_atomic_commit_core(drm, interlock); |
Ben Skeggs | 09e1b78 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1774 | else |
Ben Skeggs | 53e0a3e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1775 | disp->core->func->update(disp->core, interlock, false); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1776 | } |
| 1777 | |
| 1778 | if (atom->lock_core) |
| 1779 | mutex_unlock(&disp->mutex); |
| 1780 | |
| 1781 | /* Wait for HW to signal completion. */ |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1782 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
| 1783 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1784 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 1785 | int ret = nv50_wndw_wait_armed(wndw, asyw); |
| 1786 | if (ret) |
| 1787 | NV_ERROR(drm, "%s: timeout\n", plane->name); |
| 1788 | } |
| 1789 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1790 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 1791 | if (new_crtc_state->event) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1792 | unsigned long flags; |
Mario Kleiner | bd9f660 | 2016-11-23 07:58:54 +0100 | [diff] [blame] | 1793 | /* Get correct count/ts if racing with vblank irq */ |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1794 | if (new_crtc_state->active) |
Dave Airlie | 0c697fa | 2017-08-15 16:16:58 +1000 | [diff] [blame] | 1795 | drm_crtc_accurate_vblank_count(crtc); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1796 | spin_lock_irqsave(&crtc->dev->event_lock, flags); |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1797 | drm_crtc_send_vblank_event(crtc, new_crtc_state->event); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1798 | spin_unlock_irqrestore(&crtc->dev->event_lock, flags); |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1799 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1800 | new_crtc_state->event = NULL; |
Maarten Lankhorst | efa4793 | 2017-08-15 10:52:50 +0200 | [diff] [blame] | 1801 | if (new_crtc_state->active) |
Ben Skeggs | 4a5431a | 2017-07-24 11:01:52 +1000 | [diff] [blame] | 1802 | drm_crtc_vblank_put(crtc); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1803 | } |
| 1804 | } |
| 1805 | |
| 1806 | drm_atomic_helper_commit_hw_done(state); |
| 1807 | drm_atomic_helper_cleanup_planes(dev, state); |
| 1808 | drm_atomic_helper_commit_cleanup_done(state); |
| 1809 | drm_atomic_state_put(state); |
| 1810 | } |
| 1811 | |
| 1812 | static void |
| 1813 | nv50_disp_atomic_commit_work(struct work_struct *work) |
| 1814 | { |
| 1815 | struct drm_atomic_state *state = |
| 1816 | container_of(work, typeof(*state), commit_work); |
| 1817 | nv50_disp_atomic_commit_tail(state); |
| 1818 | } |
| 1819 | |
| 1820 | static int |
| 1821 | nv50_disp_atomic_commit(struct drm_device *dev, |
| 1822 | struct drm_atomic_state *state, bool nonblock) |
| 1823 | { |
| 1824 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | d324c5b | 2017-11-01 09:12:25 +1000 | [diff] [blame] | 1825 | struct drm_plane_state *new_plane_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1826 | struct drm_plane *plane; |
| 1827 | struct drm_crtc *crtc; |
| 1828 | bool active = false; |
| 1829 | int ret, i; |
| 1830 | |
| 1831 | ret = pm_runtime_get_sync(dev->dev); |
| 1832 | if (ret < 0 && ret != -EACCES) |
| 1833 | return ret; |
| 1834 | |
| 1835 | ret = drm_atomic_helper_setup_commit(state, nonblock); |
| 1836 | if (ret) |
| 1837 | goto done; |
| 1838 | |
| 1839 | INIT_WORK(&state->commit_work, nv50_disp_atomic_commit_work); |
| 1840 | |
| 1841 | ret = drm_atomic_helper_prepare_planes(dev, state); |
| 1842 | if (ret) |
| 1843 | goto done; |
| 1844 | |
| 1845 | if (!nonblock) { |
| 1846 | ret = drm_atomic_helper_wait_for_fences(dev, state, true); |
| 1847 | if (ret) |
Maarten Lankhorst | 813a7e1 | 2017-07-11 16:33:03 +0200 | [diff] [blame] | 1848 | goto err_cleanup; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1849 | } |
| 1850 | |
Maarten Lankhorst | 8572636 | 2017-07-11 16:33:05 +0200 | [diff] [blame] | 1851 | ret = drm_atomic_helper_swap_state(state, true); |
| 1852 | if (ret) |
| 1853 | goto err_cleanup; |
| 1854 | |
Ben Skeggs | d324c5b | 2017-11-01 09:12:25 +1000 | [diff] [blame] | 1855 | for_each_new_plane_in_state(state, plane, new_plane_state, i) { |
| 1856 | struct nv50_wndw_atom *asyw = nv50_wndw_atom(new_plane_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1857 | struct nv50_wndw *wndw = nv50_wndw(plane); |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1858 | |
Ben Skeggs | ccd27db | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 1859 | if (asyw->set.image) |
| 1860 | nv50_wndw_ntfy_enable(wndw, asyw); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1861 | } |
| 1862 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1863 | drm_atomic_state_get(state); |
| 1864 | |
| 1865 | if (nonblock) |
| 1866 | queue_work(system_unbound_wq, &state->commit_work); |
| 1867 | else |
| 1868 | nv50_disp_atomic_commit_tail(state); |
| 1869 | |
| 1870 | drm_for_each_crtc(crtc, dev) { |
| 1871 | if (crtc->state->enable) { |
| 1872 | if (!drm->have_disp_power_ref) { |
| 1873 | drm->have_disp_power_ref = true; |
Maarten Lankhorst | 813a7e1 | 2017-07-11 16:33:03 +0200 | [diff] [blame] | 1874 | return 0; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1875 | } |
| 1876 | active = true; |
| 1877 | break; |
| 1878 | } |
| 1879 | } |
| 1880 | |
| 1881 | if (!active && drm->have_disp_power_ref) { |
| 1882 | pm_runtime_put_autosuspend(dev->dev); |
| 1883 | drm->have_disp_power_ref = false; |
| 1884 | } |
| 1885 | |
Maarten Lankhorst | 813a7e1 | 2017-07-11 16:33:03 +0200 | [diff] [blame] | 1886 | err_cleanup: |
| 1887 | if (ret) |
| 1888 | drm_atomic_helper_cleanup_planes(dev, state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1889 | done: |
| 1890 | pm_runtime_put_autosuspend(dev->dev); |
| 1891 | return ret; |
| 1892 | } |
| 1893 | |
| 1894 | static struct nv50_outp_atom * |
| 1895 | nv50_disp_outp_atomic_add(struct nv50_atom *atom, struct drm_encoder *encoder) |
| 1896 | { |
| 1897 | struct nv50_outp_atom *outp; |
| 1898 | |
| 1899 | list_for_each_entry(outp, &atom->outp, head) { |
| 1900 | if (outp->encoder == encoder) |
| 1901 | return outp; |
| 1902 | } |
| 1903 | |
| 1904 | outp = kzalloc(sizeof(*outp), GFP_KERNEL); |
| 1905 | if (!outp) |
| 1906 | return ERR_PTR(-ENOMEM); |
| 1907 | |
| 1908 | list_add(&outp->head, &atom->outp); |
| 1909 | outp->encoder = encoder; |
| 1910 | return outp; |
| 1911 | } |
| 1912 | |
| 1913 | static int |
| 1914 | nv50_disp_outp_atomic_check_clr(struct nv50_atom *atom, |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1915 | struct drm_connector_state *old_connector_state) |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1916 | { |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1917 | struct drm_encoder *encoder = old_connector_state->best_encoder; |
| 1918 | struct drm_crtc_state *old_crtc_state, *new_crtc_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1919 | struct drm_crtc *crtc; |
| 1920 | struct nv50_outp_atom *outp; |
| 1921 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1922 | if (!(crtc = old_connector_state->crtc)) |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1923 | return 0; |
| 1924 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1925 | old_crtc_state = drm_atomic_get_old_crtc_state(&atom->state, crtc); |
| 1926 | new_crtc_state = drm_atomic_get_new_crtc_state(&atom->state, crtc); |
| 1927 | if (old_crtc_state->active && drm_atomic_crtc_needs_modeset(new_crtc_state)) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1928 | outp = nv50_disp_outp_atomic_add(atom, encoder); |
| 1929 | if (IS_ERR(outp)) |
| 1930 | return PTR_ERR(outp); |
| 1931 | |
| 1932 | if (outp->encoder->encoder_type == DRM_MODE_ENCODER_DPMST) { |
| 1933 | outp->flush_disable = true; |
| 1934 | atom->flush_disable = true; |
| 1935 | } |
| 1936 | outp->clr.ctrl = true; |
| 1937 | atom->lock_core = true; |
| 1938 | } |
| 1939 | |
| 1940 | return 0; |
| 1941 | } |
| 1942 | |
| 1943 | static int |
| 1944 | nv50_disp_outp_atomic_check_set(struct nv50_atom *atom, |
| 1945 | struct drm_connector_state *connector_state) |
| 1946 | { |
| 1947 | struct drm_encoder *encoder = connector_state->best_encoder; |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1948 | struct drm_crtc_state *new_crtc_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1949 | struct drm_crtc *crtc; |
| 1950 | struct nv50_outp_atom *outp; |
| 1951 | |
| 1952 | if (!(crtc = connector_state->crtc)) |
| 1953 | return 0; |
| 1954 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1955 | new_crtc_state = drm_atomic_get_new_crtc_state(&atom->state, crtc); |
| 1956 | if (new_crtc_state->active && drm_atomic_crtc_needs_modeset(new_crtc_state)) { |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1957 | outp = nv50_disp_outp_atomic_add(atom, encoder); |
| 1958 | if (IS_ERR(outp)) |
| 1959 | return PTR_ERR(outp); |
| 1960 | |
| 1961 | outp->set.ctrl = true; |
| 1962 | atom->lock_core = true; |
| 1963 | } |
| 1964 | |
| 1965 | return 0; |
| 1966 | } |
| 1967 | |
| 1968 | static int |
| 1969 | nv50_disp_atomic_check(struct drm_device *dev, struct drm_atomic_state *state) |
| 1970 | { |
| 1971 | struct nv50_atom *atom = nv50_atom(state); |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1972 | struct drm_connector_state *old_connector_state, *new_connector_state; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1973 | struct drm_connector *connector; |
Ben Skeggs | 119608a | 2018-05-08 20:39:47 +1000 | [diff] [blame^] | 1974 | struct drm_crtc_state *new_crtc_state; |
| 1975 | struct drm_crtc *crtc; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1976 | int ret, i; |
| 1977 | |
Ben Skeggs | 119608a | 2018-05-08 20:39:47 +1000 | [diff] [blame^] | 1978 | /* We need to handle colour management on a per-plane basis. */ |
| 1979 | for_each_new_crtc_in_state(state, crtc, new_crtc_state, i) { |
| 1980 | if (new_crtc_state->color_mgmt_changed) { |
| 1981 | ret = drm_atomic_add_affected_planes(state, crtc); |
| 1982 | if (ret) |
| 1983 | return ret; |
| 1984 | } |
| 1985 | } |
| 1986 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1987 | ret = drm_atomic_helper_check(dev, state); |
| 1988 | if (ret) |
| 1989 | return ret; |
| 1990 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1991 | for_each_oldnew_connector_in_state(state, connector, old_connector_state, new_connector_state, i) { |
| 1992 | ret = nv50_disp_outp_atomic_check_clr(atom, old_connector_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1993 | if (ret) |
| 1994 | return ret; |
| 1995 | |
Maarten Lankhorst | 3c847d6 | 2017-07-19 16:39:19 +0200 | [diff] [blame] | 1996 | ret = nv50_disp_outp_atomic_check_set(atom, new_connector_state); |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 1997 | if (ret) |
| 1998 | return ret; |
| 1999 | } |
| 2000 | |
| 2001 | return 0; |
| 2002 | } |
| 2003 | |
| 2004 | static void |
| 2005 | nv50_disp_atomic_state_clear(struct drm_atomic_state *state) |
| 2006 | { |
| 2007 | struct nv50_atom *atom = nv50_atom(state); |
| 2008 | struct nv50_outp_atom *outp, *outt; |
| 2009 | |
| 2010 | list_for_each_entry_safe(outp, outt, &atom->outp, head) { |
| 2011 | list_del(&outp->head); |
| 2012 | kfree(outp); |
| 2013 | } |
| 2014 | |
| 2015 | drm_atomic_state_default_clear(state); |
| 2016 | } |
| 2017 | |
| 2018 | static void |
| 2019 | nv50_disp_atomic_state_free(struct drm_atomic_state *state) |
| 2020 | { |
| 2021 | struct nv50_atom *atom = nv50_atom(state); |
| 2022 | drm_atomic_state_default_release(&atom->state); |
| 2023 | kfree(atom); |
| 2024 | } |
| 2025 | |
| 2026 | static struct drm_atomic_state * |
| 2027 | nv50_disp_atomic_state_alloc(struct drm_device *dev) |
| 2028 | { |
| 2029 | struct nv50_atom *atom; |
| 2030 | if (!(atom = kzalloc(sizeof(*atom), GFP_KERNEL)) || |
| 2031 | drm_atomic_state_init(dev, &atom->state) < 0) { |
| 2032 | kfree(atom); |
| 2033 | return NULL; |
| 2034 | } |
| 2035 | INIT_LIST_HEAD(&atom->outp); |
| 2036 | return &atom->state; |
| 2037 | } |
| 2038 | |
| 2039 | static const struct drm_mode_config_funcs |
| 2040 | nv50_disp_func = { |
| 2041 | .fb_create = nouveau_user_framebuffer_create, |
Noralf Trønnes | d0f54f5 | 2017-12-05 19:25:00 +0100 | [diff] [blame] | 2042 | .output_poll_changed = drm_fb_helper_output_poll_changed, |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2043 | .atomic_check = nv50_disp_atomic_check, |
| 2044 | .atomic_commit = nv50_disp_atomic_commit, |
| 2045 | .atomic_state_alloc = nv50_disp_atomic_state_alloc, |
| 2046 | .atomic_state_clear = nv50_disp_atomic_state_clear, |
| 2047 | .atomic_state_free = nv50_disp_atomic_state_free, |
| 2048 | }; |
| 2049 | |
| 2050 | /****************************************************************************** |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2051 | * Init |
| 2052 | *****************************************************************************/ |
Ben Skeggs | ab0af55 | 2014-08-10 04:10:19 +1000 | [diff] [blame] | 2053 | |
Ben Skeggs | 2a44e49 | 2011-11-09 11:36:33 +1000 | [diff] [blame] | 2054 | void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2055 | nv50_display_fini(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2056 | { |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2057 | struct nouveau_encoder *nv_encoder; |
| 2058 | struct drm_encoder *encoder; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2059 | struct drm_plane *plane; |
| 2060 | |
| 2061 | drm_for_each_plane(plane, dev) { |
| 2062 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 2063 | if (plane->funcs != &nv50_wndw) |
| 2064 | continue; |
| 2065 | nv50_wndw_fini(wndw); |
| 2066 | } |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2067 | |
| 2068 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 2069 | if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) { |
| 2070 | nv_encoder = nouveau_encoder(encoder); |
| 2071 | nv50_mstm_fini(nv_encoder->dp.mstm); |
| 2072 | } |
| 2073 | } |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2074 | } |
| 2075 | |
| 2076 | int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2077 | nv50_display_init(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2078 | { |
Ben Skeggs | 09e1b78 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 2079 | struct nv50_core *core = nv50_disp(dev)->core; |
Ben Skeggs | 354d350 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2080 | struct drm_encoder *encoder; |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2081 | struct drm_plane *plane; |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 2082 | |
Ben Skeggs | 09e1b78 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 2083 | core->func->init(core); |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2084 | |
Ben Skeggs | 354d350 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2085 | list_for_each_entry(encoder, &dev->mode_config.encoder_list, head) { |
| 2086 | if (encoder->encoder_type != DRM_MODE_ENCODER_DPMST) { |
Ben Skeggs | 9c5753b | 2017-05-19 23:59:35 +1000 | [diff] [blame] | 2087 | struct nouveau_encoder *nv_encoder = |
| 2088 | nouveau_encoder(encoder); |
Ben Skeggs | f479c0b | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2089 | nv50_mstm_init(nv_encoder->dp.mstm); |
Ben Skeggs | 354d350 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2090 | } |
| 2091 | } |
| 2092 | |
Ben Skeggs | 973f10c | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2093 | drm_for_each_plane(plane, dev) { |
| 2094 | struct nv50_wndw *wndw = nv50_wndw(plane); |
| 2095 | if (plane->funcs != &nv50_wndw) |
| 2096 | continue; |
| 2097 | nv50_wndw_init(wndw); |
| 2098 | } |
| 2099 | |
Ben Skeggs | 9f9bdaa | 2013-03-02 13:21:31 +1000 | [diff] [blame] | 2100 | return 0; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2101 | } |
| 2102 | |
| 2103 | void |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2104 | nv50_display_destroy(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2105 | { |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2106 | struct nv50_disp *disp = nv50_disp(dev); |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2107 | |
Ben Skeggs | 9ca6f1e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 2108 | nv50_core_del(&disp->core); |
Ben Skeggs | bdb8c21 | 2011-11-12 01:30:24 +1000 | [diff] [blame] | 2109 | |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 2110 | nouveau_bo_unmap(disp->sync); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 2111 | if (disp->sync) |
| 2112 | nouveau_bo_unpin(disp->sync); |
Ben Skeggs | 816af2f | 2011-11-16 15:48:48 +1000 | [diff] [blame] | 2113 | nouveau_bo_ref(NULL, &disp->sync); |
Ben Skeggs | 51beb42 | 2011-07-05 10:33:08 +1000 | [diff] [blame] | 2114 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2115 | nouveau_display(dev)->priv = NULL; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2116 | kfree(disp); |
| 2117 | } |
| 2118 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2119 | MODULE_PARM_DESC(atomic, "Expose atomic ioctl (default: disabled)"); |
| 2120 | static int nouveau_atomic = 0; |
| 2121 | module_param_named(atomic, nouveau_atomic, int, 0400); |
| 2122 | |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2123 | int |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2124 | nv50_display_create(struct drm_device *dev) |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2125 | { |
Ben Skeggs | 1167c6b | 2016-05-18 13:57:42 +1000 | [diff] [blame] | 2126 | struct nvif_device *device = &nouveau_drm(dev)->client.device; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2127 | struct nouveau_drm *drm = nouveau_drm(dev); |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2128 | struct dcb_table *dcb = &drm->vbios.dcb; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2129 | struct drm_connector *connector, *tmp; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2130 | struct nv50_disp *disp; |
Ben Skeggs | cb75d97 | 2012-07-11 10:44:20 +1000 | [diff] [blame] | 2131 | struct dcb_output *dcbe; |
Ben Skeggs | 7c5f6a8 | 2012-03-04 16:25:59 +1000 | [diff] [blame] | 2132 | int crtcs, ret, i; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2133 | |
| 2134 | disp = kzalloc(sizeof(*disp), GFP_KERNEL); |
| 2135 | if (!disp) |
| 2136 | return -ENOMEM; |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2137 | |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2138 | mutex_init(&disp->mutex); |
| 2139 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2140 | nouveau_display(dev)->priv = disp; |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2141 | nouveau_display(dev)->dtor = nv50_display_destroy; |
| 2142 | nouveau_display(dev)->init = nv50_display_init; |
| 2143 | nouveau_display(dev)->fini = nv50_display_fini; |
Ben Skeggs | 0ad7286 | 2014-08-10 04:10:22 +1000 | [diff] [blame] | 2144 | disp->disp = &nouveau_display(dev)->disp; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2145 | dev->mode_config.funcs = &nv50_disp_func; |
Ilia Mirkin | c20bb15 | 2018-02-03 14:11:23 -0500 | [diff] [blame] | 2146 | dev->driver->driver_features |= DRIVER_PREFER_XBGR_30BPP; |
Ben Skeggs | 839ca90 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2147 | if (nouveau_atomic) |
| 2148 | dev->driver->driver_features |= DRIVER_ATOMIC; |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2149 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2150 | /* small shared memory area we use for notifiers and semaphores */ |
Ben Skeggs | bab7cc1 | 2016-05-24 17:26:48 +1000 | [diff] [blame] | 2151 | ret = nouveau_bo_new(&drm->client, 4096, 0x1000, TTM_PL_FLAG_VRAM, |
Maarten Lankhorst | bb6178b | 2014-01-09 11:03:15 +0100 | [diff] [blame] | 2152 | 0, 0x0000, NULL, NULL, &disp->sync); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2153 | if (!ret) { |
Ben Skeggs | 547ad07 | 2014-11-10 12:35:06 +1000 | [diff] [blame] | 2154 | ret = nouveau_bo_pin(disp->sync, TTM_PL_FLAG_VRAM, true); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 2155 | if (!ret) { |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2156 | ret = nouveau_bo_map(disp->sync); |
Marcin Slusarz | 04c8c21 | 2012-11-25 23:04:23 +0100 | [diff] [blame] | 2157 | if (ret) |
| 2158 | nouveau_bo_unpin(disp->sync); |
| 2159 | } |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2160 | if (ret) |
| 2161 | nouveau_bo_ref(NULL, &disp->sync); |
| 2162 | } |
| 2163 | |
| 2164 | if (ret) |
| 2165 | goto out; |
| 2166 | |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2167 | /* allocate master evo channel */ |
Ben Skeggs | 9ca6f1e | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 2168 | ret = nv50_core_new(drm, &disp->core); |
Ben Skeggs | b5a794b | 2012-10-16 14:18:32 +1000 | [diff] [blame] | 2169 | if (ret) |
| 2170 | goto out; |
| 2171 | |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2172 | /* create crtc objects to represent the hw heads */ |
Ben Skeggs | 0d4a2c5 | 2018-05-08 20:39:47 +1000 | [diff] [blame] | 2173 | if (disp->disp->object.oclass >= GF110_DISP) |
Ilia Mirkin | eba5e56 | 2017-07-03 13:06:26 -0400 | [diff] [blame] | 2174 | crtcs = nvif_rd32(&device->object, 0x612004) & 0xf; |
Ben Skeggs | 63718a0 | 2012-11-16 11:44:14 +1000 | [diff] [blame] | 2175 | else |
Ilia Mirkin | eba5e56 | 2017-07-03 13:06:26 -0400 | [diff] [blame] | 2176 | crtcs = 0x3; |
Ben Skeggs | 63718a0 | 2012-11-16 11:44:14 +1000 | [diff] [blame] | 2177 | |
Ilia Mirkin | eba5e56 | 2017-07-03 13:06:26 -0400 | [diff] [blame] | 2178 | for (i = 0; i < fls(crtcs); i++) { |
| 2179 | if (!(crtcs & (1 << i))) |
| 2180 | continue; |
Ben Skeggs | 9bfdee9 | 2016-11-04 17:20:36 +1000 | [diff] [blame] | 2181 | ret = nv50_head_create(dev, i); |
Ben Skeggs | 438d99e | 2011-07-05 16:48:06 +1000 | [diff] [blame] | 2182 | if (ret) |
| 2183 | goto out; |
| 2184 | } |
| 2185 | |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2186 | /* create encoder/connector objects based on VBIOS DCB table */ |
| 2187 | for (i = 0, dcbe = &dcb->entry[0]; i < dcb->entries; i++, dcbe++) { |
| 2188 | connector = nouveau_connector_create(dev, dcbe->connector); |
| 2189 | if (IS_ERR(connector)) |
| 2190 | continue; |
| 2191 | |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 2192 | if (dcbe->location == DCB_LOC_ON_CHIP) { |
| 2193 | switch (dcbe->type) { |
| 2194 | case DCB_OUTPUT_TMDS: |
| 2195 | case DCB_OUTPUT_LVDS: |
| 2196 | case DCB_OUTPUT_DP: |
| 2197 | ret = nv50_sor_create(connector, dcbe); |
| 2198 | break; |
| 2199 | case DCB_OUTPUT_ANALOG: |
| 2200 | ret = nv50_dac_create(connector, dcbe); |
| 2201 | break; |
| 2202 | default: |
| 2203 | ret = -ENODEV; |
| 2204 | break; |
| 2205 | } |
| 2206 | } else { |
| 2207 | ret = nv50_pior_create(connector, dcbe); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2208 | } |
| 2209 | |
Ben Skeggs | eb6313a | 2013-02-11 09:52:58 +1000 | [diff] [blame] | 2210 | if (ret) { |
| 2211 | NV_WARN(drm, "failed to create encoder %d/%d/%d: %d\n", |
| 2212 | dcbe->location, dcbe->type, |
| 2213 | ffs(dcbe->or) - 1, ret); |
Ben Skeggs | 94f54f5 | 2013-03-05 22:26:06 +1000 | [diff] [blame] | 2214 | ret = 0; |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2215 | } |
| 2216 | } |
| 2217 | |
| 2218 | /* cull any connectors we created that don't have an encoder */ |
| 2219 | list_for_each_entry_safe(connector, tmp, &dev->mode_config.connector_list, head) { |
| 2220 | if (connector->encoder_ids[0]) |
| 2221 | continue; |
| 2222 | |
Ben Skeggs | 77145f1 | 2012-07-31 16:16:21 +1000 | [diff] [blame] | 2223 | NV_WARN(drm, "%s has no encoders, removing\n", |
Jani Nikula | 8c6c361 | 2014-06-03 14:56:18 +0300 | [diff] [blame] | 2224 | connector->name); |
Ben Skeggs | 83fc083 | 2011-07-05 13:08:40 +1000 | [diff] [blame] | 2225 | connector->funcs->destroy(connector); |
| 2226 | } |
| 2227 | |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2228 | out: |
| 2229 | if (ret) |
Ben Skeggs | e225f44 | 2012-11-21 14:40:21 +1000 | [diff] [blame] | 2230 | nv50_display_destroy(dev); |
Ben Skeggs | 26f6d88 | 2011-07-04 16:25:18 +1000 | [diff] [blame] | 2231 | return ret; |
| 2232 | } |