blob: 70549381e082833ffcf4489c22d6c778babf5b6e [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>
Ben Skeggs13de7f42015-08-20 14:54:22 +100023
24#include <core/gpuobj.h>
Ben Skeggsc79a1912015-08-20 14:54:19 +100025#include <engine/fifo.h>
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100026
Ben Skeggsc79a1912015-08-20 14:54:19 +100027static int
28nvkm_xtensa_oclass_get(struct nvkm_oclass *oclass, int index)
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100029{
Ben Skeggsc79a1912015-08-20 14:54:19 +100030 struct nvkm_xtensa *xtensa = nvkm_xtensa(oclass->engine);
31 int c = 0;
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100032
Ben Skeggsc79a1912015-08-20 14:54:19 +100033 while (xtensa->func->sclass[c].oclass) {
34 if (c++ == index) {
35 oclass->base = xtensa->func->sclass[index];
36 return index;
37 }
38 }
39
40 return c;
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100041}
42
Ben Skeggsc79a1912015-08-20 14:54:19 +100043static int
44nvkm_xtensa_cclass_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent,
45 int align, struct nvkm_gpuobj **pgpuobj)
46{
47 return nvkm_gpuobj_new(object->engine->subdev.device, 0x10000, align,
48 true, parent, pgpuobj);
49}
50
51static const struct nvkm_object_func
52nvkm_xtensa_cclass = {
53 .bind = nvkm_xtensa_cclass_bind,
54};
55
Ben Skeggs98b20c92015-08-20 14:54:21 +100056static void
57nvkm_xtensa_intr(struct nvkm_engine *engine)
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100058{
Ben Skeggs98b20c92015-08-20 14:54:21 +100059 struct nvkm_xtensa *xtensa = nvkm_xtensa(engine);
60 struct nvkm_subdev *subdev = &xtensa->engine.subdev;
61 struct nvkm_device *device = subdev->device;
Ben Skeggs9ccdc762015-08-20 14:54:13 +100062 const u32 base = xtensa->addr;
63 u32 unk104 = nvkm_rd32(device, base + 0xd04);
64 u32 intr = nvkm_rd32(device, base + 0xc20);
65 u32 chan = nvkm_rd32(device, base + 0xc28);
66 u32 unk10c = nvkm_rd32(device, base + 0xd0c);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100067
68 if (intr & 0x10)
Ben Skeggs7108bfe42015-08-20 14:54:12 +100069 nvkm_warn(subdev, "Watchdog interrupt, engine hung.\n");
Ben Skeggs9ccdc762015-08-20 14:54:13 +100070 nvkm_wr32(device, base + 0xc20, intr);
71 intr = nvkm_rd32(device, base + 0xc20);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100072 if (unk104 == 0x10001 && unk10c == 0x200 && chan && !intr) {
Ben Skeggs7108bfe42015-08-20 14:54:12 +100073 nvkm_debug(subdev, "Enabling FIFO_CTRL\n");
Ben Skeggs98b20c92015-08-20 14:54:21 +100074 nvkm_mask(device, xtensa->addr + 0xd94, 0, xtensa->func->fifo_val);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100075 }
76}
77
Ben Skeggs98b20c92015-08-20 14:54:21 +100078static int
79nvkm_xtensa_fini(struct nvkm_engine *engine, bool suspend)
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100080{
Ben Skeggs98b20c92015-08-20 14:54:21 +100081 struct nvkm_xtensa *xtensa = nvkm_xtensa(engine);
82 struct nvkm_device *device = xtensa->engine.subdev.device;
83 const u32 base = xtensa->addr;
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100084
Ben Skeggs98b20c92015-08-20 14:54:21 +100085 nvkm_wr32(device, base + 0xd84, 0); /* INTR_EN */
86 nvkm_wr32(device, base + 0xd94, 0); /* FIFO_CTRL */
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100087
Ben Skeggs98b20c92015-08-20 14:54:21 +100088 if (!suspend)
Ben Skeggs997a8902017-11-01 03:56:19 +100089 nvkm_memory_unref(&xtensa->gpu_fw);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100090 return 0;
91}
92
Ben Skeggs98b20c92015-08-20 14:54:21 +100093static int
94nvkm_xtensa_init(struct nvkm_engine *engine)
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +100095{
Ben Skeggs98b20c92015-08-20 14:54:21 +100096 struct nvkm_xtensa *xtensa = nvkm_xtensa(engine);
Ben Skeggs7108bfe42015-08-20 14:54:12 +100097 struct nvkm_subdev *subdev = &xtensa->engine.subdev;
98 struct nvkm_device *device = subdev->device;
Ben Skeggs9ccdc762015-08-20 14:54:13 +100099 const u32 base = xtensa->addr;
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000100 const struct firmware *fw;
101 char name[32];
102 int i, ret;
Ben Skeggsfaf46892015-08-20 14:54:17 +1000103 u64 addr, size;
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000104 u32 tmp;
105
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000106 if (!xtensa->gpu_fw) {
107 snprintf(name, sizeof(name), "nouveau/nv84_xuc%03x",
108 xtensa->addr >> 12);
109
Ben Skeggs26c9e8e2015-08-20 14:54:23 +1000110 ret = request_firmware(&fw, name, device->dev);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000111 if (ret) {
Ben Skeggs7108bfe42015-08-20 14:54:12 +1000112 nvkm_warn(subdev, "unable to load firmware %s\n", name);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000113 return ret;
114 }
115
Ilia Mirkinbfcd92a2013-07-19 06:27:45 -0400116 if (fw->size > 0x40000) {
Ben Skeggs7108bfe42015-08-20 14:54:12 +1000117 nvkm_warn(subdev, "firmware %s too large\n", name);
Ilia Mirkinbfcd92a2013-07-19 06:27:45 -0400118 release_firmware(fw);
119 return -EINVAL;
120 }
121
Ben Skeggsfaf46892015-08-20 14:54:17 +1000122 ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST,
123 0x40000, 0x1000, false,
Ben Skeggs50254072015-01-14 14:11:21 +1000124 &xtensa->gpu_fw);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000125 if (ret) {
126 release_firmware(fw);
127 return ret;
128 }
129
Ben Skeggsedb1dc52015-08-20 14:54:14 +1000130 nvkm_kmap(xtensa->gpu_fw);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000131 for (i = 0; i < fw->size / 4; i++)
Ben Skeggsedb1dc52015-08-20 14:54:14 +1000132 nvkm_wo32(xtensa->gpu_fw, i * 4, *((u32 *)fw->data + i));
133 nvkm_done(xtensa->gpu_fw);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000134 release_firmware(fw);
135 }
136
Ben Skeggsfaf46892015-08-20 14:54:17 +1000137 addr = nvkm_memory_addr(xtensa->gpu_fw);
138 size = nvkm_memory_size(xtensa->gpu_fw);
139
Ben Skeggs9ccdc762015-08-20 14:54:13 +1000140 nvkm_wr32(device, base + 0xd10, 0x1fffffff); /* ?? */
141 nvkm_wr32(device, base + 0xd08, 0x0fffffff); /* ?? */
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000142
Ben Skeggs98b20c92015-08-20 14:54:21 +1000143 nvkm_wr32(device, base + 0xd28, xtensa->func->unkd28); /* ?? */
Ben Skeggs9ccdc762015-08-20 14:54:13 +1000144 nvkm_wr32(device, base + 0xc20, 0x3f); /* INTR */
145 nvkm_wr32(device, base + 0xd84, 0x3f); /* INTR_EN */
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000146
Ben Skeggsfaf46892015-08-20 14:54:17 +1000147 nvkm_wr32(device, base + 0xcc0, addr >> 8); /* XT_REGION_BASE */
Ben Skeggs9ccdc762015-08-20 14:54:13 +1000148 nvkm_wr32(device, base + 0xcc4, 0x1c); /* XT_REGION_SETUP */
Ben Skeggsfaf46892015-08-20 14:54:17 +1000149 nvkm_wr32(device, base + 0xcc8, size >> 8); /* XT_REGION_LIMIT */
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000150
Ben Skeggs2ef770f2015-08-20 14:54:09 +1000151 tmp = nvkm_rd32(device, 0x0);
Ben Skeggs9ccdc762015-08-20 14:54:13 +1000152 nvkm_wr32(device, base + 0xde0, tmp); /* SCRATCH_H2X */
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000153
Ben Skeggs9ccdc762015-08-20 14:54:13 +1000154 nvkm_wr32(device, base + 0xce8, 0xf); /* XT_REGION_SETUP */
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000155
Ben Skeggs9ccdc762015-08-20 14:54:13 +1000156 nvkm_wr32(device, base + 0xc20, 0x3f); /* INTR */
157 nvkm_wr32(device, base + 0xd84, 0x3f); /* INTR_EN */
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000158 return 0;
159}
160
Ben Skeggs98b20c92015-08-20 14:54:21 +1000161static void *
162nvkm_xtensa_dtor(struct nvkm_engine *engine)
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000163{
Ben Skeggs98b20c92015-08-20 14:54:21 +1000164 return nvkm_xtensa(engine);
165}
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000166
Ben Skeggs98b20c92015-08-20 14:54:21 +1000167static const struct nvkm_engine_func
168nvkm_xtensa = {
169 .dtor = nvkm_xtensa_dtor,
170 .init = nvkm_xtensa_init,
171 .fini = nvkm_xtensa_fini,
172 .intr = nvkm_xtensa_intr,
173 .fifo.sclass = nvkm_xtensa_oclass_get,
174 .cclass = &nvkm_xtensa_cclass,
175};
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000176
Ben Skeggs98b20c92015-08-20 14:54:21 +1000177int
178nvkm_xtensa_new_(const struct nvkm_xtensa_func *func,
179 struct nvkm_device *device, int index, bool enable,
180 u32 addr, struct nvkm_engine **pengine)
181{
182 struct nvkm_xtensa *xtensa;
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000183
Ben Skeggs98b20c92015-08-20 14:54:21 +1000184 if (!(xtensa = kzalloc(sizeof(*xtensa), GFP_KERNEL)))
185 return -ENOMEM;
186 xtensa->func = func;
187 xtensa->addr = addr;
188 *pengine = &xtensa->engine;
189
Ben Skeggs56d06fa2016-04-08 17:24:40 +1000190 return nvkm_engine_ctor(&nvkm_xtensa, device, index,
Ben Skeggs98b20c92015-08-20 14:54:21 +1000191 enable, &xtensa->engine);
Ilia Mirkin44b1e3b2013-06-27 14:08:22 +1000192}