Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 1 | /* |
| 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 Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 22 | #include <engine/xtensa.h> |
Ben Skeggs | 13de7f4 | 2015-08-20 14:54:22 +1000 | [diff] [blame] | 23 | |
| 24 | #include <core/gpuobj.h> |
Ben Skeggs | c79a191 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 25 | #include <engine/fifo.h> |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 26 | |
Ben Skeggs | c79a191 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 27 | static int |
| 28 | nvkm_xtensa_oclass_get(struct nvkm_oclass *oclass, int index) |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 29 | { |
Ben Skeggs | c79a191 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 30 | struct nvkm_xtensa *xtensa = nvkm_xtensa(oclass->engine); |
| 31 | int c = 0; |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 32 | |
Ben Skeggs | c79a191 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 33 | 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 Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 41 | } |
| 42 | |
Ben Skeggs | c79a191 | 2015-08-20 14:54:19 +1000 | [diff] [blame] | 43 | static int |
| 44 | nvkm_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 | |
| 51 | static const struct nvkm_object_func |
| 52 | nvkm_xtensa_cclass = { |
| 53 | .bind = nvkm_xtensa_cclass_bind, |
| 54 | }; |
| 55 | |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 56 | static void |
| 57 | nvkm_xtensa_intr(struct nvkm_engine *engine) |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 58 | { |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 59 | struct nvkm_xtensa *xtensa = nvkm_xtensa(engine); |
| 60 | struct nvkm_subdev *subdev = &xtensa->engine.subdev; |
| 61 | struct nvkm_device *device = subdev->device; |
Ben Skeggs | 9ccdc76 | 2015-08-20 14:54:13 +1000 | [diff] [blame] | 62 | 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 Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 67 | |
| 68 | if (intr & 0x10) |
Ben Skeggs | 7108bfe4 | 2015-08-20 14:54:12 +1000 | [diff] [blame] | 69 | nvkm_warn(subdev, "Watchdog interrupt, engine hung.\n"); |
Ben Skeggs | 9ccdc76 | 2015-08-20 14:54:13 +1000 | [diff] [blame] | 70 | nvkm_wr32(device, base + 0xc20, intr); |
| 71 | intr = nvkm_rd32(device, base + 0xc20); |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 72 | if (unk104 == 0x10001 && unk10c == 0x200 && chan && !intr) { |
Ben Skeggs | 7108bfe4 | 2015-08-20 14:54:12 +1000 | [diff] [blame] | 73 | nvkm_debug(subdev, "Enabling FIFO_CTRL\n"); |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 74 | nvkm_mask(device, xtensa->addr + 0xd94, 0, xtensa->func->fifo_val); |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 75 | } |
| 76 | } |
| 77 | |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 78 | static int |
| 79 | nvkm_xtensa_fini(struct nvkm_engine *engine, bool suspend) |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 80 | { |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 81 | struct nvkm_xtensa *xtensa = nvkm_xtensa(engine); |
| 82 | struct nvkm_device *device = xtensa->engine.subdev.device; |
| 83 | const u32 base = xtensa->addr; |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 84 | |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 85 | nvkm_wr32(device, base + 0xd84, 0); /* INTR_EN */ |
| 86 | nvkm_wr32(device, base + 0xd94, 0); /* FIFO_CTRL */ |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 87 | |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 88 | if (!suspend) |
Ben Skeggs | 997a890 | 2017-11-01 03:56:19 +1000 | [diff] [blame^] | 89 | nvkm_memory_unref(&xtensa->gpu_fw); |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 90 | return 0; |
| 91 | } |
| 92 | |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 93 | static int |
| 94 | nvkm_xtensa_init(struct nvkm_engine *engine) |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 95 | { |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 96 | struct nvkm_xtensa *xtensa = nvkm_xtensa(engine); |
Ben Skeggs | 7108bfe4 | 2015-08-20 14:54:12 +1000 | [diff] [blame] | 97 | struct nvkm_subdev *subdev = &xtensa->engine.subdev; |
| 98 | struct nvkm_device *device = subdev->device; |
Ben Skeggs | 9ccdc76 | 2015-08-20 14:54:13 +1000 | [diff] [blame] | 99 | const u32 base = xtensa->addr; |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 100 | const struct firmware *fw; |
| 101 | char name[32]; |
| 102 | int i, ret; |
Ben Skeggs | faf4689 | 2015-08-20 14:54:17 +1000 | [diff] [blame] | 103 | u64 addr, size; |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 104 | u32 tmp; |
| 105 | |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 106 | if (!xtensa->gpu_fw) { |
| 107 | snprintf(name, sizeof(name), "nouveau/nv84_xuc%03x", |
| 108 | xtensa->addr >> 12); |
| 109 | |
Ben Skeggs | 26c9e8e | 2015-08-20 14:54:23 +1000 | [diff] [blame] | 110 | ret = request_firmware(&fw, name, device->dev); |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 111 | if (ret) { |
Ben Skeggs | 7108bfe4 | 2015-08-20 14:54:12 +1000 | [diff] [blame] | 112 | nvkm_warn(subdev, "unable to load firmware %s\n", name); |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 113 | return ret; |
| 114 | } |
| 115 | |
Ilia Mirkin | bfcd92a | 2013-07-19 06:27:45 -0400 | [diff] [blame] | 116 | if (fw->size > 0x40000) { |
Ben Skeggs | 7108bfe4 | 2015-08-20 14:54:12 +1000 | [diff] [blame] | 117 | nvkm_warn(subdev, "firmware %s too large\n", name); |
Ilia Mirkin | bfcd92a | 2013-07-19 06:27:45 -0400 | [diff] [blame] | 118 | release_firmware(fw); |
| 119 | return -EINVAL; |
| 120 | } |
| 121 | |
Ben Skeggs | faf4689 | 2015-08-20 14:54:17 +1000 | [diff] [blame] | 122 | ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST, |
| 123 | 0x40000, 0x1000, false, |
Ben Skeggs | 5025407 | 2015-01-14 14:11:21 +1000 | [diff] [blame] | 124 | &xtensa->gpu_fw); |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 125 | if (ret) { |
| 126 | release_firmware(fw); |
| 127 | return ret; |
| 128 | } |
| 129 | |
Ben Skeggs | edb1dc5 | 2015-08-20 14:54:14 +1000 | [diff] [blame] | 130 | nvkm_kmap(xtensa->gpu_fw); |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 131 | for (i = 0; i < fw->size / 4; i++) |
Ben Skeggs | edb1dc5 | 2015-08-20 14:54:14 +1000 | [diff] [blame] | 132 | nvkm_wo32(xtensa->gpu_fw, i * 4, *((u32 *)fw->data + i)); |
| 133 | nvkm_done(xtensa->gpu_fw); |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 134 | release_firmware(fw); |
| 135 | } |
| 136 | |
Ben Skeggs | faf4689 | 2015-08-20 14:54:17 +1000 | [diff] [blame] | 137 | addr = nvkm_memory_addr(xtensa->gpu_fw); |
| 138 | size = nvkm_memory_size(xtensa->gpu_fw); |
| 139 | |
Ben Skeggs | 9ccdc76 | 2015-08-20 14:54:13 +1000 | [diff] [blame] | 140 | nvkm_wr32(device, base + 0xd10, 0x1fffffff); /* ?? */ |
| 141 | nvkm_wr32(device, base + 0xd08, 0x0fffffff); /* ?? */ |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 142 | |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 143 | nvkm_wr32(device, base + 0xd28, xtensa->func->unkd28); /* ?? */ |
Ben Skeggs | 9ccdc76 | 2015-08-20 14:54:13 +1000 | [diff] [blame] | 144 | nvkm_wr32(device, base + 0xc20, 0x3f); /* INTR */ |
| 145 | nvkm_wr32(device, base + 0xd84, 0x3f); /* INTR_EN */ |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 146 | |
Ben Skeggs | faf4689 | 2015-08-20 14:54:17 +1000 | [diff] [blame] | 147 | nvkm_wr32(device, base + 0xcc0, addr >> 8); /* XT_REGION_BASE */ |
Ben Skeggs | 9ccdc76 | 2015-08-20 14:54:13 +1000 | [diff] [blame] | 148 | nvkm_wr32(device, base + 0xcc4, 0x1c); /* XT_REGION_SETUP */ |
Ben Skeggs | faf4689 | 2015-08-20 14:54:17 +1000 | [diff] [blame] | 149 | nvkm_wr32(device, base + 0xcc8, size >> 8); /* XT_REGION_LIMIT */ |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 150 | |
Ben Skeggs | 2ef770f | 2015-08-20 14:54:09 +1000 | [diff] [blame] | 151 | tmp = nvkm_rd32(device, 0x0); |
Ben Skeggs | 9ccdc76 | 2015-08-20 14:54:13 +1000 | [diff] [blame] | 152 | nvkm_wr32(device, base + 0xde0, tmp); /* SCRATCH_H2X */ |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 153 | |
Ben Skeggs | 9ccdc76 | 2015-08-20 14:54:13 +1000 | [diff] [blame] | 154 | nvkm_wr32(device, base + 0xce8, 0xf); /* XT_REGION_SETUP */ |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 155 | |
Ben Skeggs | 9ccdc76 | 2015-08-20 14:54:13 +1000 | [diff] [blame] | 156 | nvkm_wr32(device, base + 0xc20, 0x3f); /* INTR */ |
| 157 | nvkm_wr32(device, base + 0xd84, 0x3f); /* INTR_EN */ |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 158 | return 0; |
| 159 | } |
| 160 | |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 161 | static void * |
| 162 | nvkm_xtensa_dtor(struct nvkm_engine *engine) |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 163 | { |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 164 | return nvkm_xtensa(engine); |
| 165 | } |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 166 | |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 167 | static const struct nvkm_engine_func |
| 168 | nvkm_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 Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 176 | |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 177 | int |
| 178 | nvkm_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 Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 183 | |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 184 | if (!(xtensa = kzalloc(sizeof(*xtensa), GFP_KERNEL))) |
| 185 | return -ENOMEM; |
| 186 | xtensa->func = func; |
| 187 | xtensa->addr = addr; |
| 188 | *pengine = &xtensa->engine; |
| 189 | |
Ben Skeggs | 56d06fa | 2016-04-08 17:24:40 +1000 | [diff] [blame] | 190 | return nvkm_engine_ctor(&nvkm_xtensa, device, index, |
Ben Skeggs | 98b20c9 | 2015-08-20 14:54:21 +1000 | [diff] [blame] | 191 | enable, &xtensa->engine); |
Ilia Mirkin | 44b1e3b | 2013-06-27 14:08:22 +1000 | [diff] [blame] | 192 | } |