2013-06-27 12:08:22 +08:00
|
|
|
/*
|
|
|
|
* 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>
|
|
|
|
|
2015-01-14 12:11:21 +08:00
|
|
|
#include <core/engctx.h>
|
|
|
|
|
2013-06-27 12:08:22 +08:00
|
|
|
int
|
2015-01-14 12:11:21 +08:00
|
|
|
_nvkm_xtensa_engctx_ctor(struct nvkm_object *parent, struct nvkm_object *engine,
|
|
|
|
struct nvkm_oclass *oclass, void *data, u32 size,
|
|
|
|
struct nvkm_object **pobject)
|
2013-06-27 12:08:22 +08:00
|
|
|
{
|
2015-01-14 12:11:21 +08:00
|
|
|
struct nvkm_engctx *engctx;
|
2013-06-27 12:08:22 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-01-14 12:11:21 +08:00
|
|
|
ret = nvkm_engctx_create(parent, engine, oclass, NULL, 0x10000, 0x1000,
|
|
|
|
NVOBJ_FLAG_ZERO_ALLOC, &engctx);
|
2013-06-27 12:08:22 +08:00
|
|
|
*pobject = nv_object(engctx);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
|
|
|
void
|
2015-01-14 12:11:21 +08:00
|
|
|
_nvkm_xtensa_intr(struct nvkm_subdev *subdev)
|
2013-06-27 12:08:22 +08:00
|
|
|
{
|
2015-01-14 12:11:21 +08:00
|
|
|
struct nvkm_xtensa *xtensa = (void *)subdev;
|
2015-08-20 12:54:09 +08:00
|
|
|
struct nvkm_device *device = xtensa->engine.subdev.device;
|
2015-08-20 12:54:13 +08:00
|
|
|
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);
|
2013-06-27 12:08:22 +08:00
|
|
|
|
|
|
|
if (intr & 0x10)
|
2015-08-20 12:54:12 +08:00
|
|
|
nvkm_warn(subdev, "Watchdog interrupt, engine hung.\n");
|
2015-08-20 12:54:13 +08:00
|
|
|
nvkm_wr32(device, base + 0xc20, intr);
|
|
|
|
intr = nvkm_rd32(device, base + 0xc20);
|
2013-06-27 12:08:22 +08:00
|
|
|
if (unk104 == 0x10001 && unk10c == 0x200 && chan && !intr) {
|
2015-08-20 12:54:12 +08:00
|
|
|
nvkm_debug(subdev, "Enabling FIFO_CTRL\n");
|
2015-08-20 12:54:09 +08:00
|
|
|
nvkm_mask(device, xtensa->addr + 0xd94, 0, xtensa->fifo_val);
|
2013-06-27 12:08:22 +08:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 12:11:21 +08:00
|
|
|
nvkm_xtensa_create_(struct nvkm_object *parent, struct nvkm_object *engine,
|
|
|
|
struct nvkm_oclass *oclass, u32 addr, bool enable,
|
|
|
|
const char *iname, const char *fname,
|
|
|
|
int length, void **pobject)
|
2013-06-27 12:08:22 +08:00
|
|
|
{
|
2015-01-14 12:11:21 +08:00
|
|
|
struct nvkm_xtensa *xtensa;
|
2013-06-27 12:08:22 +08:00
|
|
|
int ret;
|
|
|
|
|
2015-01-14 12:11:21 +08:00
|
|
|
ret = nvkm_engine_create_(parent, engine, oclass, enable, iname,
|
|
|
|
fname, length, pobject);
|
2013-06-27 12:08:22 +08:00
|
|
|
xtensa = *pobject;
|
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
2015-01-14 12:11:21 +08:00
|
|
|
nv_subdev(xtensa)->intr = _nvkm_xtensa_intr;
|
2013-06-27 12:08:22 +08:00
|
|
|
xtensa->addr = addr;
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 12:11:21 +08:00
|
|
|
_nvkm_xtensa_init(struct nvkm_object *object)
|
2013-06-27 12:08:22 +08:00
|
|
|
{
|
2015-01-14 12:11:21 +08:00
|
|
|
struct nvkm_xtensa *xtensa = (void *)object;
|
2015-08-20 12:54:12 +08:00
|
|
|
struct nvkm_subdev *subdev = &xtensa->engine.subdev;
|
|
|
|
struct nvkm_device *device = subdev->device;
|
2015-08-20 12:54:13 +08:00
|
|
|
const u32 base = xtensa->addr;
|
2013-06-27 12:08:22 +08:00
|
|
|
const struct firmware *fw;
|
|
|
|
char name[32];
|
|
|
|
int i, ret;
|
2015-08-20 12:54:17 +08:00
|
|
|
u64 addr, size;
|
2013-06-27 12:08:22 +08:00
|
|
|
u32 tmp;
|
|
|
|
|
2015-08-20 12:54:16 +08:00
|
|
|
ret = nvkm_engine_init_old(&xtensa->engine);
|
2013-06-27 12:08:22 +08:00
|
|
|
if (ret)
|
|
|
|
return ret;
|
|
|
|
|
|
|
|
if (!xtensa->gpu_fw) {
|
|
|
|
snprintf(name, sizeof(name), "nouveau/nv84_xuc%03x",
|
|
|
|
xtensa->addr >> 12);
|
|
|
|
|
2014-02-17 14:17:26 +08:00
|
|
|
ret = request_firmware(&fw, name, nv_device_base(device));
|
2013-06-27 12:08:22 +08:00
|
|
|
if (ret) {
|
2015-08-20 12:54:12 +08:00
|
|
|
nvkm_warn(subdev, "unable to load firmware %s\n", name);
|
2013-06-27 12:08:22 +08:00
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2013-07-19 18:27:45 +08:00
|
|
|
if (fw->size > 0x40000) {
|
2015-08-20 12:54:12 +08:00
|
|
|
nvkm_warn(subdev, "firmware %s too large\n", name);
|
2013-07-19 18:27:45 +08:00
|
|
|
release_firmware(fw);
|
|
|
|
return -EINVAL;
|
|
|
|
}
|
|
|
|
|
2015-08-20 12:54:17 +08:00
|
|
|
ret = nvkm_memory_new(device, NVKM_MEM_TARGET_INST,
|
|
|
|
0x40000, 0x1000, false,
|
2015-01-14 12:11:21 +08:00
|
|
|
&xtensa->gpu_fw);
|
2013-06-27 12:08:22 +08:00
|
|
|
if (ret) {
|
|
|
|
release_firmware(fw);
|
|
|
|
return ret;
|
|
|
|
}
|
|
|
|
|
2015-08-20 12:54:14 +08:00
|
|
|
nvkm_kmap(xtensa->gpu_fw);
|
2013-06-27 12:08:22 +08:00
|
|
|
for (i = 0; i < fw->size / 4; i++)
|
2015-08-20 12:54:14 +08:00
|
|
|
nvkm_wo32(xtensa->gpu_fw, i * 4, *((u32 *)fw->data + i));
|
|
|
|
nvkm_done(xtensa->gpu_fw);
|
2013-06-27 12:08:22 +08:00
|
|
|
release_firmware(fw);
|
|
|
|
}
|
|
|
|
|
2015-08-20 12:54:17 +08:00
|
|
|
addr = nvkm_memory_addr(xtensa->gpu_fw);
|
|
|
|
size = nvkm_memory_size(xtensa->gpu_fw);
|
|
|
|
|
2015-08-20 12:54:13 +08:00
|
|
|
nvkm_wr32(device, base + 0xd10, 0x1fffffff); /* ?? */
|
|
|
|
nvkm_wr32(device, base + 0xd08, 0x0fffffff); /* ?? */
|
2013-06-27 12:08:22 +08:00
|
|
|
|
2015-08-20 12:54:13 +08:00
|
|
|
nvkm_wr32(device, base + 0xd28, xtensa->unkd28); /* ?? */
|
|
|
|
nvkm_wr32(device, base + 0xc20, 0x3f); /* INTR */
|
|
|
|
nvkm_wr32(device, base + 0xd84, 0x3f); /* INTR_EN */
|
2013-06-27 12:08:22 +08:00
|
|
|
|
2015-08-20 12:54:17 +08:00
|
|
|
nvkm_wr32(device, base + 0xcc0, addr >> 8); /* XT_REGION_BASE */
|
2015-08-20 12:54:13 +08:00
|
|
|
nvkm_wr32(device, base + 0xcc4, 0x1c); /* XT_REGION_SETUP */
|
2015-08-20 12:54:17 +08:00
|
|
|
nvkm_wr32(device, base + 0xcc8, size >> 8); /* XT_REGION_LIMIT */
|
2013-06-27 12:08:22 +08:00
|
|
|
|
2015-08-20 12:54:09 +08:00
|
|
|
tmp = nvkm_rd32(device, 0x0);
|
2015-08-20 12:54:13 +08:00
|
|
|
nvkm_wr32(device, base + 0xde0, tmp); /* SCRATCH_H2X */
|
2013-06-27 12:08:22 +08:00
|
|
|
|
2015-08-20 12:54:13 +08:00
|
|
|
nvkm_wr32(device, base + 0xce8, 0xf); /* XT_REGION_SETUP */
|
2013-06-27 12:08:22 +08:00
|
|
|
|
2015-08-20 12:54:13 +08:00
|
|
|
nvkm_wr32(device, base + 0xc20, 0x3f); /* INTR */
|
|
|
|
nvkm_wr32(device, base + 0xd84, 0x3f); /* INTR_EN */
|
2013-06-27 12:08:22 +08:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
int
|
2015-01-14 12:11:21 +08:00
|
|
|
_nvkm_xtensa_fini(struct nvkm_object *object, bool suspend)
|
2013-06-27 12:08:22 +08:00
|
|
|
{
|
2015-01-14 12:11:21 +08:00
|
|
|
struct nvkm_xtensa *xtensa = (void *)object;
|
2015-08-20 12:54:13 +08:00
|
|
|
struct nvkm_device *device = xtensa->engine.subdev.device;
|
|
|
|
const u32 base = xtensa->addr;
|
2013-06-27 12:08:22 +08:00
|
|
|
|
2015-08-20 12:54:13 +08:00
|
|
|
nvkm_wr32(device, base + 0xd84, 0); /* INTR_EN */
|
|
|
|
nvkm_wr32(device, base + 0xd94, 0); /* FIFO_CTRL */
|
2013-06-27 12:08:22 +08:00
|
|
|
|
|
|
|
if (!suspend)
|
2015-08-20 12:54:17 +08:00
|
|
|
nvkm_memory_del(&xtensa->gpu_fw);
|
2013-06-27 12:08:22 +08:00
|
|
|
|
2015-08-20 12:54:16 +08:00
|
|
|
return nvkm_engine_fini_old(&xtensa->engine, suspend);
|
2013-06-27 12:08:22 +08:00
|
|
|
}
|