xtensa.c 5.5 KB
Newer Older
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22
/*
 * Copyright 2013 Ilia Mirkin
 *
 * Permission is hereby granted, free of charge, to any person obtaining a
 * copy of this software and associated documentation files (the "Software"),
 * to deal in the Software without restriction, including without limitation
 * the rights to use, copy, modify, merge, publish, distribute, sublicense,
 * and/or sell copies of the Software, and to permit persons to whom the
 * Software is furnished to do so, subject to the following conditions:
 *
 * The above copyright notice and this permission notice shall be included in
 * all copies or substantial portions of the Software.
 *
 * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
 * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
 * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.  IN NO EVENT SHALL
 * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
 * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
 * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
 * OTHER DEALINGS IN THE SOFTWARE.
 */
#include <engine/xtensa.h>
23
#include <engine/fifo.h>
24

25 26
static int
nvkm_xtensa_oclass_get(struct nvkm_oclass *oclass, int index)
27
{
28 29 30 31 32 33 34 35 36
	struct nvkm_xtensa *xtensa = nvkm_xtensa(oclass->engine);
	int c = 0;

	while (xtensa->func->sclass[c].oclass) {
		if (c++ == index) {
			oclass->base = xtensa->func->sclass[index];
			return index;
		}
	}
37

38
	return c;
39 40
}

41 42 43 44 45 46 47 48 49 50 51 52 53
static int
nvkm_xtensa_cclass_bind(struct nvkm_object *object, struct nvkm_gpuobj *parent,
			int align, struct nvkm_gpuobj **pgpuobj)
{
	return nvkm_gpuobj_new(object->engine->subdev.device, 0x10000, align,
			       true, parent, pgpuobj);
}

static const struct nvkm_object_func
nvkm_xtensa_cclass = {
	.bind = nvkm_xtensa_cclass_bind,
};

54 55
static void
nvkm_xtensa_intr(struct nvkm_engine *engine)
56
{
57 58 59
	struct nvkm_xtensa *xtensa = nvkm_xtensa(engine);
	struct nvkm_subdev *subdev = &xtensa->engine.subdev;
	struct nvkm_device *device = subdev->device;
60 61 62 63 64
	const u32 base = xtensa->addr;
	u32 unk104 = nvkm_rd32(device, base + 0xd04);
	u32 intr = nvkm_rd32(device, base + 0xc20);
	u32 chan = nvkm_rd32(device, base + 0xc28);
	u32 unk10c = nvkm_rd32(device, base + 0xd0c);
65 66

	if (intr & 0x10)
67
		nvkm_warn(subdev, "Watchdog interrupt, engine hung.\n");
68 69
	nvkm_wr32(device, base + 0xc20, intr);
	intr = nvkm_rd32(device, base + 0xc20);
70
	if (unk104 == 0x10001 && unk10c == 0x200 && chan && !intr) {
71
		nvkm_debug(subdev, "Enabling FIFO_CTRL\n");
72
		nvkm_mask(device, xtensa->addr + 0xd94, 0, xtensa->func->fifo_val);
73 74 75
	}
}

76 77
static int
nvkm_xtensa_fini(struct nvkm_engine *engine, bool suspend)
78
{
79 80 81
	struct nvkm_xtensa *xtensa = nvkm_xtensa(engine);
	struct nvkm_device *device = xtensa->engine.subdev.device;
	const u32 base = xtensa->addr;
82

83 84
	nvkm_wr32(device, base + 0xd84, 0); /* INTR_EN */
	nvkm_wr32(device, base + 0xd94, 0); /* FIFO_CTRL */
85

86 87
	if (!suspend)
		nvkm_memory_del(&xtensa->gpu_fw);
88 89 90
	return 0;
}

91 92
static int
nvkm_xtensa_init(struct nvkm_engine *engine)
93
{
94
	struct nvkm_xtensa *xtensa = nvkm_xtensa(engine);
95 96
	struct nvkm_subdev *subdev = &xtensa->engine.subdev;
	struct nvkm_device *device = subdev->device;
97
	const u32 base = xtensa->addr;
98 99 100
	const struct firmware *fw;
	char name[32];
	int i, ret;
101
	u64 addr, size;
102 103 104 105 106 107
	u32 tmp;

	if (!xtensa->gpu_fw) {
		snprintf(name, sizeof(name), "nouveau/nv84_xuc%03x",
			 xtensa->addr >> 12);

A
Alexandre Courbot 已提交
108
		ret = request_firmware(&fw, name, nv_device_base(device));
109
		if (ret) {
110
			nvkm_warn(subdev, "unable to load firmware %s\n", name);
111 112 113
			return ret;
		}

114
		if (fw->size > 0x40000) {
115
			nvkm_warn(subdev, "firmware %s too large\n", name);
116 117 118 119
			release_firmware(fw);
			return -EINVAL;
		}

120 121
		ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST,
				      0x40000, 0x1000, false,
122
				      &xtensa->gpu_fw);
123 124 125 126 127
		if (ret) {
			release_firmware(fw);
			return ret;
		}

128
		nvkm_kmap(xtensa->gpu_fw);
129
		for (i = 0; i < fw->size / 4; i++)
130 131
			nvkm_wo32(xtensa->gpu_fw, i * 4, *((u32 *)fw->data + i));
		nvkm_done(xtensa->gpu_fw);
132 133 134
		release_firmware(fw);
	}

135 136 137
	addr = nvkm_memory_addr(xtensa->gpu_fw);
	size = nvkm_memory_size(xtensa->gpu_fw);

138 139
	nvkm_wr32(device, base + 0xd10, 0x1fffffff); /* ?? */
	nvkm_wr32(device, base + 0xd08, 0x0fffffff); /* ?? */
140

141
	nvkm_wr32(device, base + 0xd28, xtensa->func->unkd28); /* ?? */
142 143
	nvkm_wr32(device, base + 0xc20, 0x3f); /* INTR */
	nvkm_wr32(device, base + 0xd84, 0x3f); /* INTR_EN */
144

145
	nvkm_wr32(device, base + 0xcc0, addr >> 8); /* XT_REGION_BASE */
146
	nvkm_wr32(device, base + 0xcc4, 0x1c); /* XT_REGION_SETUP */
147
	nvkm_wr32(device, base + 0xcc8, size >> 8); /* XT_REGION_LIMIT */
148

149
	tmp = nvkm_rd32(device, 0x0);
150
	nvkm_wr32(device, base + 0xde0, tmp); /* SCRATCH_H2X */
151

152
	nvkm_wr32(device, base + 0xce8, 0xf); /* XT_REGION_SETUP */
153

154 155
	nvkm_wr32(device, base + 0xc20, 0x3f); /* INTR */
	nvkm_wr32(device, base + 0xd84, 0x3f); /* INTR_EN */
156 157 158
	return 0;
}

159 160
static void *
nvkm_xtensa_dtor(struct nvkm_engine *engine)
161
{
162 163
	return nvkm_xtensa(engine);
}
164

165 166 167 168 169 170 171 172 173
static const struct nvkm_engine_func
nvkm_xtensa = {
	.dtor = nvkm_xtensa_dtor,
	.init = nvkm_xtensa_init,
	.fini = nvkm_xtensa_fini,
	.intr = nvkm_xtensa_intr,
	.fifo.sclass = nvkm_xtensa_oclass_get,
	.cclass = &nvkm_xtensa_cclass,
};
174

175 176 177 178 179 180 181 182 183 184 185 186
int
nvkm_xtensa_new_(const struct nvkm_xtensa_func *func,
		 struct nvkm_device *device, int index, bool enable,
		 u32 addr, struct nvkm_engine **pengine)
{
	struct nvkm_xtensa *xtensa;

	if (!(xtensa = kzalloc(sizeof(*xtensa), GFP_KERNEL)))
		return -ENOMEM;
	xtensa->func = func;
	xtensa->addr = addr;
	*pengine = &xtensa->engine;
187

188 189
	return nvkm_engine_ctor(&nvkm_xtensa, device, index, func->pmc_enable,
				enable, &xtensa->engine);
190
}