186037742SBen Skeggs /*
286037742SBen Skeggs * Copyright 2018 Red Hat Inc.
386037742SBen Skeggs *
486037742SBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
586037742SBen Skeggs * copy of this software and associated documentation files (the "Software"),
686037742SBen Skeggs * to deal in the Software without restriction, including without limitation
786037742SBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
886037742SBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
986037742SBen Skeggs * Software is furnished to do so, subject to the following conditions:
1086037742SBen Skeggs *
1186037742SBen Skeggs * The above copyright notice and this permission notice shall be included in
1286037742SBen Skeggs * all copies or substantial portions of the Software.
1386037742SBen Skeggs *
1486037742SBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1586037742SBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1686037742SBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1786037742SBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1886037742SBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1986037742SBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2086037742SBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
2186037742SBen Skeggs */
22acbe9ecfSBen Skeggs #include "chan.h"
2392fba5d3SBen Skeggs #include "priv.h"
2486037742SBen Skeggs #include "head.h"
2586037742SBen Skeggs #include "ior.h"
2686037742SBen Skeggs
2786037742SBen Skeggs #include <core/gpuobj.h>
2886037742SBen Skeggs #include <subdev/timer.h>
2986037742SBen Skeggs
30168c0299SBen Skeggs #include <nvif/class.h>
31168c0299SBen Skeggs
32acbe9ecfSBen Skeggs void
tu102_sor_dp_vcpi(struct nvkm_ior * sor,int head,u8 slot,u8 slot_nr,u16 pbn,u16 aligned)33acbe9ecfSBen Skeggs tu102_sor_dp_vcpi(struct nvkm_ior *sor, int head, u8 slot, u8 slot_nr, u16 pbn, u16 aligned)
34acbe9ecfSBen Skeggs {
35acbe9ecfSBen Skeggs struct nvkm_device *device = sor->disp->engine.subdev.device;
36acbe9ecfSBen Skeggs const u32 hoff = head * 0x800;
37acbe9ecfSBen Skeggs
38acbe9ecfSBen Skeggs nvkm_mask(device, 0x61657c + hoff, 0xffffffff, (aligned << 16) | pbn);
39acbe9ecfSBen Skeggs nvkm_mask(device, 0x616578 + hoff, 0x00003f3f, (slot_nr << 8) | slot);
40acbe9ecfSBen Skeggs }
41acbe9ecfSBen Skeggs
42acbe9ecfSBen Skeggs static int
tu102_sor_dp_links(struct nvkm_ior * sor,struct nvkm_i2c_aux * aux)43acbe9ecfSBen Skeggs tu102_sor_dp_links(struct nvkm_ior *sor, struct nvkm_i2c_aux *aux)
44acbe9ecfSBen Skeggs {
45acbe9ecfSBen Skeggs struct nvkm_device *device = sor->disp->engine.subdev.device;
46acbe9ecfSBen Skeggs const u32 soff = nv50_ior_base(sor);
47acbe9ecfSBen Skeggs const u32 loff = nv50_sor_link(sor);
48acbe9ecfSBen Skeggs u32 dpctrl = 0x00000000;
49acbe9ecfSBen Skeggs u32 clksor = 0x00000000;
50acbe9ecfSBen Skeggs
51acbe9ecfSBen Skeggs clksor |= sor->dp.bw << 18;
52acbe9ecfSBen Skeggs dpctrl |= ((1 << sor->dp.nr) - 1) << 16;
53acbe9ecfSBen Skeggs if (sor->dp.mst)
54acbe9ecfSBen Skeggs dpctrl |= 0x40000000;
55acbe9ecfSBen Skeggs if (sor->dp.ef)
56acbe9ecfSBen Skeggs dpctrl |= 0x00004000;
57acbe9ecfSBen Skeggs
58acbe9ecfSBen Skeggs nvkm_mask(device, 0x612300 + soff, 0x007c0000, clksor);
59acbe9ecfSBen Skeggs
60acbe9ecfSBen Skeggs /*XXX*/
61acbe9ecfSBen Skeggs nvkm_msec(device, 40, NVKM_DELAY);
62acbe9ecfSBen Skeggs nvkm_mask(device, 0x612300 + soff, 0x00030000, 0x00010000);
63acbe9ecfSBen Skeggs nvkm_mask(device, 0x61c10c + loff, 0x00000003, 0x00000001);
64acbe9ecfSBen Skeggs
65acbe9ecfSBen Skeggs nvkm_mask(device, 0x61c10c + loff, 0x401f4000, dpctrl);
66acbe9ecfSBen Skeggs return 0;
67acbe9ecfSBen Skeggs }
68acbe9ecfSBen Skeggs
699a4514fbSBen Skeggs static const struct nvkm_ior_func_dp
709a4514fbSBen Skeggs tu102_sor_dp = {
719a4514fbSBen Skeggs .lanes = { 0, 1, 2, 3 },
729a4514fbSBen Skeggs .links = tu102_sor_dp_links,
739a4514fbSBen Skeggs .power = g94_sor_dp_power,
749a4514fbSBen Skeggs .pattern = gm107_sor_dp_pattern,
759a4514fbSBen Skeggs .drive = gm200_sor_dp_drive,
769a4514fbSBen Skeggs .vcpi = tu102_sor_dp_vcpi,
779a4514fbSBen Skeggs .audio = gv100_sor_dp_audio,
789a4514fbSBen Skeggs .audio_sym = gv100_sor_dp_audio_sym,
799a4514fbSBen Skeggs .watermark = gv100_sor_dp_watermark,
809a4514fbSBen Skeggs };
819a4514fbSBen Skeggs
82acbe9ecfSBen Skeggs static const struct nvkm_ior_func
8379c453afSBen Skeggs tu102_sor = {
84acbe9ecfSBen Skeggs .route = {
85acbe9ecfSBen Skeggs .get = gm200_sor_route_get,
86acbe9ecfSBen Skeggs .set = gm200_sor_route_set,
87acbe9ecfSBen Skeggs },
88acbe9ecfSBen Skeggs .state = gv100_sor_state,
89acbe9ecfSBen Skeggs .power = nv50_sor_power,
90acbe9ecfSBen Skeggs .clock = gf119_sor_clock,
91*f530bc60SBen Skeggs .hdmi = &gv100_sor_hdmi,
929a4514fbSBen Skeggs .dp = &tu102_sor_dp,
937bcf89eeSBen Skeggs .hda = &gv100_sor_hda,
94acbe9ecfSBen Skeggs };
95acbe9ecfSBen Skeggs
96acbe9ecfSBen Skeggs static int
tu102_sor_new(struct nvkm_disp * disp,int id)97acbe9ecfSBen Skeggs tu102_sor_new(struct nvkm_disp *disp, int id)
98acbe9ecfSBen Skeggs {
99acbe9ecfSBen Skeggs struct nvkm_device *device = disp->engine.subdev.device;
100acbe9ecfSBen Skeggs u32 hda = nvkm_rd32(device, 0x08a15c);
10179c453afSBen Skeggs
10279c453afSBen Skeggs return nvkm_ior_new_(&tu102_sor, disp, SOR, id, hda & BIT(id));
103acbe9ecfSBen Skeggs }
104acbe9ecfSBen Skeggs
1058ef23b6fSBen Skeggs int
tu102_disp_init(struct nvkm_disp * disp)10692fba5d3SBen Skeggs tu102_disp_init(struct nvkm_disp *disp)
10786037742SBen Skeggs {
10892fba5d3SBen Skeggs struct nvkm_device *device = disp->engine.subdev.device;
10986037742SBen Skeggs struct nvkm_head *head;
11086037742SBen Skeggs int i, j;
11186037742SBen Skeggs u32 tmp;
11286037742SBen Skeggs
11386037742SBen Skeggs /* Claim ownership of display. */
11486037742SBen Skeggs if (nvkm_rd32(device, 0x6254e8) & 0x00000002) {
11586037742SBen Skeggs nvkm_mask(device, 0x6254e8, 0x00000001, 0x00000000);
11686037742SBen Skeggs if (nvkm_msec(device, 2000,
11786037742SBen Skeggs if (!(nvkm_rd32(device, 0x6254e8) & 0x00000002))
11886037742SBen Skeggs break;
11986037742SBen Skeggs ) < 0)
12086037742SBen Skeggs return -EBUSY;
12186037742SBen Skeggs }
12286037742SBen Skeggs
12386037742SBen Skeggs /* Lock pin capabilities. */
12486037742SBen Skeggs tmp = 0x00000021; /*XXX*/
12586037742SBen Skeggs nvkm_wr32(device, 0x640008, tmp);
12686037742SBen Skeggs
12786037742SBen Skeggs /* SOR capabilities. */
12886037742SBen Skeggs for (i = 0; i < disp->sor.nr; i++) {
12986037742SBen Skeggs tmp = nvkm_rd32(device, 0x61c000 + (i * 0x800));
13086037742SBen Skeggs nvkm_mask(device, 0x640000, 0x00000100 << i, 0x00000100 << i);
13186037742SBen Skeggs nvkm_wr32(device, 0x640144 + (i * 0x08), tmp);
13286037742SBen Skeggs }
13386037742SBen Skeggs
13486037742SBen Skeggs /* Head capabilities. */
13592fba5d3SBen Skeggs list_for_each_entry(head, &disp->heads, head) {
13686037742SBen Skeggs const int id = head->id;
13786037742SBen Skeggs
13886037742SBen Skeggs /* RG. */
13986037742SBen Skeggs tmp = nvkm_rd32(device, 0x616300 + (id * 0x800));
14086037742SBen Skeggs nvkm_wr32(device, 0x640048 + (id * 0x020), tmp);
14186037742SBen Skeggs
14286037742SBen Skeggs /* POSTCOMP. */
14386037742SBen Skeggs for (j = 0; j < 5 * 4; j += 4) {
14486037742SBen Skeggs tmp = nvkm_rd32(device, 0x616140 + (id * 0x800) + j);
14586037742SBen Skeggs nvkm_wr32(device, 0x640680 + (id * 0x20) + j, tmp);
14686037742SBen Skeggs }
14786037742SBen Skeggs }
14886037742SBen Skeggs
14986037742SBen Skeggs /* Window capabilities. */
15086037742SBen Skeggs for (i = 0; i < disp->wndw.nr; i++) {
15186037742SBen Skeggs nvkm_mask(device, 0x640004, 1 << i, 1 << i);
15286037742SBen Skeggs for (j = 0; j < 6 * 4; j += 4) {
15386037742SBen Skeggs tmp = nvkm_rd32(device, 0x630100 + (i * 0x800) + j);
15486037742SBen Skeggs nvkm_mask(device, 0x640780 + (i * 0x20) + j, 0xffffffff, tmp);
15586037742SBen Skeggs }
15686037742SBen Skeggs nvkm_mask(device, 0x64000c, 0x00000100, 0x00000100);
15786037742SBen Skeggs }
15886037742SBen Skeggs
15986037742SBen Skeggs /* IHUB capabilities. */
16086037742SBen Skeggs for (i = 0; i < 3; i++) {
16186037742SBen Skeggs tmp = nvkm_rd32(device, 0x62e000 + (i * 0x04));
16286037742SBen Skeggs nvkm_wr32(device, 0x640010 + (i * 0x04), tmp);
16386037742SBen Skeggs }
16486037742SBen Skeggs
16586037742SBen Skeggs nvkm_mask(device, 0x610078, 0x00000001, 0x00000001);
16686037742SBen Skeggs
16786037742SBen Skeggs /* Setup instance memory. */
16886037742SBen Skeggs switch (nvkm_memory_target(disp->inst->memory)) {
16986037742SBen Skeggs case NVKM_MEM_TARGET_VRAM: tmp = 0x00000001; break;
17086037742SBen Skeggs case NVKM_MEM_TARGET_NCOH: tmp = 0x00000002; break;
17186037742SBen Skeggs case NVKM_MEM_TARGET_HOST: tmp = 0x00000003; break;
17286037742SBen Skeggs default:
17386037742SBen Skeggs break;
17486037742SBen Skeggs }
17586037742SBen Skeggs nvkm_wr32(device, 0x610010, 0x00000008 | tmp);
17686037742SBen Skeggs nvkm_wr32(device, 0x610014, disp->inst->addr >> 16);
17786037742SBen Skeggs
17886037742SBen Skeggs /* CTRL_DISP: AWAKEN, ERROR, SUPERVISOR[1-3]. */
17986037742SBen Skeggs nvkm_wr32(device, 0x611cf0, 0x00000187); /* MSK. */
18086037742SBen Skeggs nvkm_wr32(device, 0x611db0, 0x00000187); /* EN. */
18186037742SBen Skeggs
18286037742SBen Skeggs /* EXC_OTHER: CURSn, CORE. */
18386037742SBen Skeggs nvkm_wr32(device, 0x611cec, disp->head.mask << 16 |
18486037742SBen Skeggs 0x00000001); /* MSK. */
18586037742SBen Skeggs nvkm_wr32(device, 0x611dac, 0x00000000); /* EN. */
18686037742SBen Skeggs
18786037742SBen Skeggs /* EXC_WINIM. */
18886037742SBen Skeggs nvkm_wr32(device, 0x611ce8, disp->wndw.mask); /* MSK. */
18986037742SBen Skeggs nvkm_wr32(device, 0x611da8, 0x00000000); /* EN. */
19086037742SBen Skeggs
19186037742SBen Skeggs /* EXC_WIN. */
19286037742SBen Skeggs nvkm_wr32(device, 0x611ce4, disp->wndw.mask); /* MSK. */
19386037742SBen Skeggs nvkm_wr32(device, 0x611da4, 0x00000000); /* EN. */
19486037742SBen Skeggs
19586037742SBen Skeggs /* HEAD_TIMING(n): VBLANK. */
19692fba5d3SBen Skeggs list_for_each_entry(head, &disp->heads, head) {
19786037742SBen Skeggs const u32 hoff = head->id * 4;
19886037742SBen Skeggs nvkm_wr32(device, 0x611cc0 + hoff, 0x00000004); /* MSK. */
19986037742SBen Skeggs nvkm_wr32(device, 0x611d80 + hoff, 0x00000000); /* EN. */
20086037742SBen Skeggs }
20186037742SBen Skeggs
20286037742SBen Skeggs /* OR. */
20386037742SBen Skeggs nvkm_wr32(device, 0x611cf4, 0x00000000); /* MSK. */
20486037742SBen Skeggs nvkm_wr32(device, 0x611db4, 0x00000000); /* EN. */
20586037742SBen Skeggs return 0;
20686037742SBen Skeggs }
20786037742SBen Skeggs
2080407b33fSBen Skeggs static const struct nvkm_disp_func
20986037742SBen Skeggs tu102_disp = {
210acbe9ecfSBen Skeggs .oneinit = nv50_disp_oneinit,
21192fba5d3SBen Skeggs .init = tu102_disp_init,
21292fba5d3SBen Skeggs .fini = gv100_disp_fini,
21392fba5d3SBen Skeggs .intr = gv100_disp_intr,
21486037742SBen Skeggs .super = gv100_disp_super,
21592fba5d3SBen Skeggs .uevent = &gv100_disp_chan_uevent,
21686037742SBen Skeggs .wndw = { .cnt = gv100_disp_wndw_cnt },
21786037742SBen Skeggs .head = { .cnt = gv100_head_cnt, .new = gv100_head_new },
21886037742SBen Skeggs .sor = { .cnt = gv100_sor_cnt, .new = tu102_sor_new },
21986037742SBen Skeggs .ramht_size = 0x2000,
220168c0299SBen Skeggs .root = { 0, 0,TU102_DISP },
221168c0299SBen Skeggs .user = {
222168c0299SBen Skeggs {{-1,-1,GV100_DISP_CAPS }, gv100_disp_caps_new },
223889fcbe9SBen Skeggs {{ 0, 0,TU102_DISP_CURSOR }, nvkm_disp_chan_new, &gv100_disp_curs },
224889fcbe9SBen Skeggs {{ 0, 0,TU102_DISP_WINDOW_IMM_CHANNEL_DMA}, nvkm_disp_wndw_new, &gv100_disp_wimm },
225889fcbe9SBen Skeggs {{ 0, 0,TU102_DISP_CORE_CHANNEL_DMA }, nvkm_disp_core_new, &gv100_disp_core },
226889fcbe9SBen Skeggs {{ 0, 0,TU102_DISP_WINDOW_CHANNEL_DMA }, nvkm_disp_wndw_new, &gv100_disp_wndw },
227168c0299SBen Skeggs {}
228168c0299SBen Skeggs },
22986037742SBen Skeggs };
23086037742SBen Skeggs
23186037742SBen Skeggs int
tu102_disp_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_disp ** pdisp)232a7f000ecSBen Skeggs tu102_disp_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
233a7f000ecSBen Skeggs struct nvkm_disp **pdisp)
23486037742SBen Skeggs {
2351c6aab75SBen Skeggs return nvkm_disp_new_(&tu102_disp, device, type, inst, pdisp);
23686037742SBen Skeggs }
237