blob: 6ffc6c4315b6ca9b8841838116b223d71651ad9a [file] [log] [blame]
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +10001/*
2 * Copyright 2013 Ilia Mirkin
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 */
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100022#include <engine/xtensa.h>
23
Ben Skeggs50254072015-01-14 14:11:21 +100024#include <core/engctx.h>
25
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100026int
Ben Skeggs50254072015-01-14 14:11:21 +100027_nvkm_xtensa_engctx_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
28 struct nvkm_oclass *oclass, void *data, u32 size,
29 struct nvkm_object **pobject)
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100030{
Ben Skeggs50254072015-01-14 14:11:21 +100031 struct nvkm_engctx *engctx;
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100032 int ret;
33
Ben Skeggs50254072015-01-14 14:11:21 +100034 ret = nvkm_engctx_create(parent, engine, oclass, NULL, 0x10000, 0x1000,
35 NVOBJ_FLAG_ZERO_ALLOC, &engctx);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100036 *pobject = nv_object(engctx);
37 return ret;
38}
39
40void
Ben Skeggs50254072015-01-14 14:11:21 +100041_nvkm_xtensa_intr(struct nvkm_subdev *subdev)
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100042{
Ben Skeggs50254072015-01-14 14:11:21 +100043 struct nvkm_xtensa *xtensa = (void *)subdev;
Ben Skeggs2ef770f2015-08-20 14:54:09 +100044 struct nvkm_device *device = xtensa->engine.subdev.device;
Ben Skeggs9ccdc762015-08-20 14:54:13 +100045 const u32 base = xtensa->addr;
46 u32 unk104 = nvkm_rd32(device, base + 0xd04);
47 u32 intr = nvkm_rd32(device, base + 0xc20);
48 u32 chan = nvkm_rd32(device, base + 0xc28);
49 u32 unk10c = nvkm_rd32(device, base + 0xd0c);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100050
51 if (intr & 0x10)
Ben Skeggs7108bfe42015-08-20 14:54:12 +100052 nvkm_warn(subdev, "Watchdog interrupt, engine hung.\n");
Ben Skeggs9ccdc762015-08-20 14:54:13 +100053 nvkm_wr32(device, base + 0xc20, intr);
54 intr = nvkm_rd32(device, base + 0xc20);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100055 if (unk104 == 0x10001 && unk10c == 0x200 && chan && !intr) {
Ben Skeggs7108bfe42015-08-20 14:54:12 +100056 nvkm_debug(subdev, "Enabling FIFO_CTRL\n");
Ben Skeggs2ef770f2015-08-20 14:54:09 +100057 nvkm_mask(device, xtensa->addr + 0xd94, 0, xtensa->fifo_val);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100058 }
59}
60
61int
Ben Skeggs50254072015-01-14 14:11:21 +100062nvkm_xtensa_create_(struct nvkm_object *parent, struct nvkm_object *engine,
63 struct nvkm_oclass *oclass, u32 addr, bool enable,
64 const char *iname, const char *fname,
65 int length, void **pobject)
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100066{
Ben Skeggs50254072015-01-14 14:11:21 +100067 struct nvkm_xtensa *xtensa;
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100068 int ret;
69
Ben Skeggs50254072015-01-14 14:11:21 +100070 ret = nvkm_engine_create_(parent, engine, oclass, enable, iname,
71 fname, length, pobject);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100072 xtensa = *pobject;
73 if (ret)
74 return ret;
75
Ben Skeggs50254072015-01-14 14:11:21 +100076 nv_subdev(xtensa)->intr = _nvkm_xtensa_intr;
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100077 xtensa->addr = addr;
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100078 return 0;
79}
80
81int
Ben Skeggs50254072015-01-14 14:11:21 +100082_nvkm_xtensa_init(struct nvkm_object *object)
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100083{
Ben Skeggs50254072015-01-14 14:11:21 +100084 struct nvkm_xtensa *xtensa = (void *)object;
Ben Skeggs7108bfe42015-08-20 14:54:12 +100085 struct nvkm_subdev *subdev = &xtensa->engine.subdev;
86 struct nvkm_device *device = subdev->device;
Ben Skeggs9ccdc762015-08-20 14:54:13 +100087 const u32 base = xtensa->addr;
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100088 const struct firmware *fw;
89 char name[32];
90 int i, ret;
Ben Skeggsfaf46892015-08-20 14:54:17 +100091 u64 addr, size;
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100092 u32 tmp;
93
Ben Skeggs89c651e2015-08-20 14:54:16 +100094 ret = nvkm_engine_init_old(&xtensa->engine);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100095 if (ret)
96 return ret;
97
98 if (!xtensa->gpu_fw) {
99 snprintf(name, sizeof(name), "nouveau/nv84_xuc%03x",
100 xtensa->addr >> 12);
101
Alexandre Courbot420b9462014-02-17 15:17:26 +0900102 ret = request_firmware(&fw, name, nv_device_base(device));
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000103 if (ret) {
Ben Skeggs7108bfe42015-08-20 14:54:12 +1000104 nvkm_warn(subdev, "unable to load firmware %s\n", name);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000105 return ret;
106 }
107
Ilia Mirkinbfcd92a2013-07-19 06:27:45 -0400108 if (fw->size > 0x40000) {
Ben Skeggs7108bfe42015-08-20 14:54:12 +1000109 nvkm_warn(subdev, "firmware %s too large\n", name);
Ilia Mirkinbfcd92a2013-07-19 06:27:45 -0400110 release_firmware(fw);
111 return -EINVAL;
112 }
113
Ben Skeggsfaf46892015-08-20 14:54:17 +1000114 ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST,
115 0x40000, 0x1000, false,
Ben Skeggs50254072015-01-14 14:11:21 +1000116 &xtensa->gpu_fw);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000117 if (ret) {
118 release_firmware(fw);
119 return ret;
120 }
121
Ben Skeggsedb1dc52015-08-20 14:54:14 +1000122 nvkm_kmap(xtensa->gpu_fw);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000123 for (i = 0; i < fw->size / 4; i++)
Ben Skeggsedb1dc52015-08-20 14:54:14 +1000124 nvkm_wo32(xtensa->gpu_fw, i * 4, *((u32 *)fw->data + i));
125 nvkm_done(xtensa->gpu_fw);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000126 release_firmware(fw);
127 }
128
Ben Skeggsfaf46892015-08-20 14:54:17 +1000129 addr = nvkm_memory_addr(xtensa->gpu_fw);
130 size = nvkm_memory_size(xtensa->gpu_fw);
131
Ben Skeggs9ccdc762015-08-20 14:54:13 +1000132 nvkm_wr32(device, base + 0xd10, 0x1fffffff); /* ?? */
133 nvkm_wr32(device, base + 0xd08, 0x0fffffff); /* ?? */
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000134
Ben Skeggs9ccdc762015-08-20 14:54:13 +1000135 nvkm_wr32(device, base + 0xd28, xtensa->unkd28); /* ?? */
136 nvkm_wr32(device, base + 0xc20, 0x3f); /* INTR */
137 nvkm_wr32(device, base + 0xd84, 0x3f); /* INTR_EN */
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000138
Ben Skeggsfaf46892015-08-20 14:54:17 +1000139 nvkm_wr32(device, base + 0xcc0, addr >> 8); /* XT_REGION_BASE */
Ben Skeggs9ccdc762015-08-20 14:54:13 +1000140 nvkm_wr32(device, base + 0xcc4, 0x1c); /* XT_REGION_SETUP */
Ben Skeggsfaf46892015-08-20 14:54:17 +1000141 nvkm_wr32(device, base + 0xcc8, size >> 8); /* XT_REGION_LIMIT */
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000142
Ben Skeggs2ef770f2015-08-20 14:54:09 +1000143 tmp = nvkm_rd32(device, 0x0);
Ben Skeggs9ccdc762015-08-20 14:54:13 +1000144 nvkm_wr32(device, base + 0xde0, tmp); /* SCRATCH_H2X */
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000145
Ben Skeggs9ccdc762015-08-20 14:54:13 +1000146 nvkm_wr32(device, base + 0xce8, 0xf); /* XT_REGION_SETUP */
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000147
Ben Skeggs9ccdc762015-08-20 14:54:13 +1000148 nvkm_wr32(device, base + 0xc20, 0x3f); /* INTR */
149 nvkm_wr32(device, base + 0xd84, 0x3f); /* INTR_EN */
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000150 return 0;
151}
152
153int
Ben Skeggs50254072015-01-14 14:11:21 +1000154_nvkm_xtensa_fini(struct nvkm_object *object, bool suspend)
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000155{
Ben Skeggs50254072015-01-14 14:11:21 +1000156 struct nvkm_xtensa *xtensa = (void *)object;
Ben Skeggs9ccdc762015-08-20 14:54:13 +1000157 struct nvkm_device *device = xtensa->engine.subdev.device;
158 const u32 base = xtensa->addr;
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000159
Ben Skeggs9ccdc762015-08-20 14:54:13 +1000160 nvkm_wr32(device, base + 0xd84, 0); /* INTR_EN */
161 nvkm_wr32(device, base + 0xd94, 0); /* FIFO_CTRL */
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000162
163 if (!suspend)
Ben Skeggsfaf46892015-08-20 14:54:17 +1000164 nvkm_memory_del(&xtensa->gpu_fw);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000165
Ben Skeggs89c651e2015-08-20 14:54:16 +1000166 return nvkm_engine_fini_old(&xtensa->engine, suspend);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000167}