105d271c3SBen Skeggs /*
205d271c3SBen Skeggs * Copyright 2021 Red Hat Inc.
305d271c3SBen Skeggs *
405d271c3SBen Skeggs * Permission is hereby granted, free of charge, to any person obtaining a
505d271c3SBen Skeggs * copy of this software and associated documentation files (the "Software"),
605d271c3SBen Skeggs * to deal in the Software without restriction, including without limitation
705d271c3SBen Skeggs * the rights to use, copy, modify, merge, publish, distribute, sublicense,
805d271c3SBen Skeggs * and/or sell copies of the Software, and to permit persons to whom the
905d271c3SBen Skeggs * Software is furnished to do so, subject to the following conditions:
1005d271c3SBen Skeggs *
1105d271c3SBen Skeggs * The above copyright notice and this permission notice shall be included in
1205d271c3SBen Skeggs * all copies or substantial portions of the Software.
1305d271c3SBen Skeggs *
1405d271c3SBen Skeggs * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
1505d271c3SBen Skeggs * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
1605d271c3SBen Skeggs * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
1705d271c3SBen Skeggs * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
1805d271c3SBen Skeggs * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
1905d271c3SBen Skeggs * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
2005d271c3SBen Skeggs * OTHER DEALINGS IN THE SOFTWARE.
2105d271c3SBen Skeggs */
2205d271c3SBen Skeggs #include "priv.h"
2305d271c3SBen Skeggs
2405d271c3SBen Skeggs #include <subdev/vfn.h>
2505d271c3SBen Skeggs
2605d271c3SBen Skeggs #include <nvif/class.h>
2705d271c3SBen Skeggs
2805d271c3SBen Skeggs static irqreturn_t
ga100_ce_intr(struct nvkm_inth * inth)2905d271c3SBen Skeggs ga100_ce_intr(struct nvkm_inth *inth)
3005d271c3SBen Skeggs {
3105d271c3SBen Skeggs struct nvkm_subdev *subdev = container_of(inth, typeof(*subdev), inth);
3205d271c3SBen Skeggs
3305d271c3SBen Skeggs /*TODO*/
3405d271c3SBen Skeggs nvkm_error(subdev, "intr\n");
3505d271c3SBen Skeggs return IRQ_NONE;
3605d271c3SBen Skeggs }
3705d271c3SBen Skeggs
3805d271c3SBen Skeggs int
ga100_ce_nonstall(struct nvkm_engine * engine)39*55e1a599SBen Skeggs ga100_ce_nonstall(struct nvkm_engine *engine)
40*55e1a599SBen Skeggs {
41*55e1a599SBen Skeggs struct nvkm_subdev *subdev = &engine->subdev;
42*55e1a599SBen Skeggs struct nvkm_device *device = subdev->device;
43*55e1a599SBen Skeggs
44*55e1a599SBen Skeggs return nvkm_rd32(device, 0x104424 + (subdev->inst * 0x80)) & 0x00000fff;
45*55e1a599SBen Skeggs }
46*55e1a599SBen Skeggs
47*55e1a599SBen Skeggs int
ga100_ce_fini(struct nvkm_engine * engine,bool suspend)4805d271c3SBen Skeggs ga100_ce_fini(struct nvkm_engine *engine, bool suspend)
4905d271c3SBen Skeggs {
5005d271c3SBen Skeggs nvkm_inth_block(&engine->subdev.inth);
5105d271c3SBen Skeggs return 0;
5205d271c3SBen Skeggs }
5305d271c3SBen Skeggs
5405d271c3SBen Skeggs int
ga100_ce_init(struct nvkm_engine * engine)5505d271c3SBen Skeggs ga100_ce_init(struct nvkm_engine *engine)
5605d271c3SBen Skeggs {
5705d271c3SBen Skeggs nvkm_inth_allow(&engine->subdev.inth);
5805d271c3SBen Skeggs return 0;
5905d271c3SBen Skeggs }
6005d271c3SBen Skeggs
6105d271c3SBen Skeggs int
ga100_ce_oneinit(struct nvkm_engine * engine)6205d271c3SBen Skeggs ga100_ce_oneinit(struct nvkm_engine *engine)
6305d271c3SBen Skeggs {
6405d271c3SBen Skeggs struct nvkm_subdev *subdev = &engine->subdev;
6505d271c3SBen Skeggs struct nvkm_device *device = subdev->device;
6605d271c3SBen Skeggs u32 vector;
6705d271c3SBen Skeggs
6805d271c3SBen Skeggs vector = nvkm_rd32(device, 0x10442c + (subdev->inst * 0x80)) & 0x00000fff;
6905d271c3SBen Skeggs
7005d271c3SBen Skeggs return nvkm_inth_add(&device->vfn->intr, vector, NVKM_INTR_PRIO_NORMAL,
7105d271c3SBen Skeggs subdev, ga100_ce_intr, &subdev->inth);
7205d271c3SBen Skeggs }
7305d271c3SBen Skeggs
7405d271c3SBen Skeggs static const struct nvkm_engine_func
7505d271c3SBen Skeggs ga100_ce = {
7605d271c3SBen Skeggs .oneinit = ga100_ce_oneinit,
7705d271c3SBen Skeggs .init = ga100_ce_init,
7805d271c3SBen Skeggs .fini = ga100_ce_fini,
79*55e1a599SBen Skeggs .nonstall = ga100_ce_nonstall,
8005d271c3SBen Skeggs .cclass = &gv100_ce_cclass,
8105d271c3SBen Skeggs .sclass = {
8205d271c3SBen Skeggs { -1, -1, AMPERE_DMA_COPY_A },
8305d271c3SBen Skeggs {}
8405d271c3SBen Skeggs }
8505d271c3SBen Skeggs };
8605d271c3SBen Skeggs
8705d271c3SBen Skeggs int
ga100_ce_new(struct nvkm_device * device,enum nvkm_subdev_type type,int inst,struct nvkm_engine ** pengine)8805d271c3SBen Skeggs ga100_ce_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
8905d271c3SBen Skeggs struct nvkm_engine **pengine)
9005d271c3SBen Skeggs {
9105d271c3SBen Skeggs return nvkm_engine_new_(&ga100_ce, device, type, inst, true, pengine);
9205d271c3SBen Skeggs }
93