Skip to content

Commit

Permalink
drm/nouveau/fifo: unify handling of channel classes
Browse files Browse the repository at this point in the history
Adds the basic skeleton for common channel (group) interfaces.

- common behaviour between <gk104 and >=gk104 impl's
- separates priv/user channel objects
- passthrough to existing object for now, kludges removed later

Signed-off-by: Ben Skeggs <bskeggs@redhat.com>
Reviewed-by: Lyude Paul <lyude@redhat.com>
  • Loading branch information
Ben Skeggs committed Nov 9, 2022
1 parent 8c18138 commit f5e4568
Show file tree
Hide file tree
Showing 36 changed files with 410 additions and 191 deletions.
3 changes: 3 additions & 0 deletions drivers/gpu/drm/nouveau/include/nvif/class.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
#define NVIF_CLASS_DISP_CHAN /* if0014.h */ 0x80000014

#define NVIF_CLASS_CHAN /* if0020.h */ 0x80000020
#define NVIF_CLASS_CGRP /* if0021.h */ 0x80000021

/* the below match nvidia-assigned (either in hw, or sw) class numbers */
#define NV_NULL_CLASS 0x00000030
Expand Down Expand Up @@ -74,6 +75,8 @@
#define NV17_CHANNEL_DMA /* cl506b.h */ 0x0000176e
#define NV40_CHANNEL_DMA /* cl506b.h */ 0x0000406e

#define KEPLER_CHANNEL_GROUP_A /* if0021.h */ 0x0000a06c

#define NV50_CHANNEL_GPFIFO /* cl506f.h */ 0x0000506f
#define G82_CHANNEL_GPFIFO /* cl826f.h */ 0x0000826f
#define FERMI_CHANNEL_GPFIFO /* cl906f.h */ 0x0000906f
Expand Down
4 changes: 4 additions & 0 deletions drivers/gpu/drm/nouveau/include/nvkm/core/os.h
Original file line number Diff line number Diff line change
Expand Up @@ -35,4 +35,8 @@ nvkm_blob_dtor(struct nvkm_blob *blob)
blob->size = 0;
}

/*FIXME: remove after */
#define nvkm_fifo_chan nvkm_chan
#define nvkm_fifo_chan_func nvkm_chan_func
#define nvkm_fifo_cgrp nvkm_cgrp
#endif
5 changes: 3 additions & 2 deletions drivers/gpu/drm/nouveau/include/nvkm/engine/fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ struct nvkm_fifo_engn {
int usecount;
};

struct nvkm_fifo_chan {
const struct nvkm_fifo_chan_func *func;
struct nvkm_chan {
const struct nvkm_chan_func *func;

struct nvkm_fifo *fifo;
u32 engm;
struct nvkm_object object;
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/Kbuild
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,5 @@ nvkm-y += nvkm/engine/fifo/gpfifogf100.o
nvkm-y += nvkm/engine/fifo/gpfifogk104.o
nvkm-y += nvkm/engine/fifo/gpfifogv100.o
nvkm-y += nvkm/engine/fifo/gpfifotu102.o

nvkm-y += nvkm/engine/fifo/uchan.o
43 changes: 14 additions & 29 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -155,27 +155,16 @@ nvkm_fifo_uevent(struct nvkm_fifo *fifo)
}

static int
nvkm_fifo_class_new_(struct nvkm_device *device,
const struct nvkm_oclass *oclass, void *data, u32 size,
struct nvkm_object **pobject)
nvkm_fifo_class_new(struct nvkm_device *device, const struct nvkm_oclass *oclass,
void *argv, u32 argc, struct nvkm_object **pobject)
{
struct nvkm_fifo *fifo = nvkm_fifo(oclass->engine);
return fifo->func->class_new(fifo, oclass, data, size, pobject);
}

static const struct nvkm_device_oclass
nvkm_fifo_class_ = {
.ctor = nvkm_fifo_class_new_,
};
if (oclass->engn == &fifo->func->chan.user)
return nvkm_uchan_new(fifo, NULL, oclass, argv, argc, pobject);

static int
nvkm_fifo_class_new(struct nvkm_device *device,
const struct nvkm_oclass *oclass, void *data, u32 size,
struct nvkm_object **pobject)
{
const struct nvkm_fifo_chan_oclass *sclass = oclass->engn;
struct nvkm_fifo *fifo = nvkm_fifo(oclass->engine);
return sclass->ctor(fifo, oclass, data, size, pobject);
WARN_ON(1);
return -ENOSYS;
}

static const struct nvkm_device_oclass
Expand All @@ -184,24 +173,20 @@ nvkm_fifo_class = {
};

static int
nvkm_fifo_class_get(struct nvkm_oclass *oclass, int index,
const struct nvkm_device_oclass **class)
nvkm_fifo_class_get(struct nvkm_oclass *oclass, int index, const struct nvkm_device_oclass **class)
{
struct nvkm_fifo *fifo = nvkm_fifo(oclass->engine);
const struct nvkm_fifo_chan_oclass *sclass;
const struct nvkm_fifo_func_chan *chan = &fifo->func->chan;
int c = 0;

if (fifo->func->class_get) {
int ret = fifo->func->class_get(fifo, index, oclass);
if (ret == 0)
*class = &nvkm_fifo_class_;
return ret;
}
if (fifo->func->engine_id == gk104_fifo_engine_id)
chan = &gk104_fifo(fifo)->func->chan;

while ((sclass = fifo->func->chan[c])) {
/* *_CHANNEL_DMA, *_CHANNEL_GPFIFO_* */
if (chan->user.oclass) {
if (c++ == index) {
oclass->base = sclass->base;
oclass->engn = sclass;
oclass->base = chan->user;
oclass->engn = &fifo->func->chan.user;
*class = &nvkm_fifo_class;
return 0;
}
Expand Down
11 changes: 7 additions & 4 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/cgrp.h
Original file line number Diff line number Diff line change
@@ -1,8 +1,11 @@
#ifndef __NVKM_FIFO_CGRP_H__
#define __NVKM_FIFO_CGRP_H__
#include "priv.h"
/* SPDX-License-Identifier: MIT */
#ifndef __NVKM_CGRP_H__
#define __NVKM_CGRP_H__
#include <core/os.h>

struct nvkm_fifo_cgrp {
struct nvkm_cgrp {
const struct nvkm_cgrp_func {
} *func;
int id;
struct list_head head;
struct list_head chan;
Expand Down
43 changes: 35 additions & 8 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/chan.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Authors: Ben Skeggs
*/
#include "chan.h"
#include "priv.h"

#include <core/client.h>
#include <core/gpuobj.h>
Expand Down Expand Up @@ -140,7 +141,7 @@ nvkm_fifo_chan_child_func = {
.fini[0] = nvkm_fifo_chan_child_fini,
};

static int
int
nvkm_fifo_chan_child_new(const struct nvkm_oclass *oclass, void *data, u32 size,
struct nvkm_object **pobject)
{
Expand Down Expand Up @@ -258,11 +259,6 @@ nvkm_fifo_chan_uevent(struct nvkm_object *object, void *argv, u32 argc, struct n
struct nvkm_fifo_chan *chan = nvkm_fifo_chan(object);
union nvif_chan_event_args *args = argv;

if (!uevent)
return 0;
if (argc != sizeof(args->v0) || args->v0.version != 0)
return -ENOSYS;

switch (args->v0.type) {
case NVIF_CHAN_EVENT_V0_NON_STALL_INTR:
return nvkm_uevent_add(uevent, &chan->fifo->uevent, 0,
Expand Down Expand Up @@ -304,6 +300,18 @@ nvkm_fifo_chan_init(struct nvkm_object *object)
return 0;
}

void
nvkm_chan_del(struct nvkm_chan **pchan)
{
struct nvkm_chan *chan = *pchan;

if (!chan)
return;

chan = nvkm_object_dtor(&chan->object);
kfree(chan);
}

static void *
nvkm_fifo_chan_dtor(struct nvkm_object *object)
{
Expand All @@ -326,6 +334,7 @@ nvkm_fifo_chan_dtor(struct nvkm_object *object)

nvkm_gpuobj_del(&chan->push);
nvkm_gpuobj_del(&chan->inst);
kfree(chan->func);
return data;
}

Expand All @@ -340,20 +349,38 @@ nvkm_fifo_chan_func = {
};

int
nvkm_fifo_chan_ctor(const struct nvkm_fifo_chan_func *func,
nvkm_fifo_chan_ctor(const struct nvkm_fifo_chan_func *fn,
struct nvkm_fifo *fifo, u32 size, u32 align, bool zero,
u64 hvmm, u64 push, u32 engm, int bar, u32 base,
u32 user, const struct nvkm_oclass *oclass,
struct nvkm_fifo_chan *chan)
{
struct nvkm_chan_func *func;
struct nvkm_client *client = oclass->client;
struct nvkm_device *device = fifo->engine.subdev.device;
struct nvkm_dmaobj *dmaobj;
unsigned long flags;
int ret;

nvkm_object_ctor(&nvkm_fifo_chan_func, oclass, &chan->object);
/*FIXME: temp kludge to ease transition, remove later */
if (!(func = kmalloc(sizeof(*func), GFP_KERNEL)))
return -ENOMEM;

*func = *fifo->func->chan.func;
func->dtor = fn->dtor;
func->init = fn->init;
func->fini = fn->fini;
func->engine_ctor = fn->engine_ctor;
func->engine_dtor = fn->engine_dtor;
func->engine_init = fn->engine_init;
func->engine_fini = fn->engine_fini;
func->object_ctor = fn->object_ctor;
func->object_dtor = fn->object_dtor;
func->submit_token = fn->submit_token;

chan->func = func;

nvkm_object_ctor(&nvkm_fifo_chan_func, oclass, &chan->object);
chan->fifo = fifo;
chan->engm = engm;
INIT_LIST_HEAD(&chan->head);
Expand Down
19 changes: 7 additions & 12 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/chan.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/* SPDX-License-Identifier: MIT */
#ifndef __NVKM_FIFO_CHAN_H__
#define __NVKM_FIFO_CHAN_H__
#define nvkm_fifo_chan(p) container_of((p), struct nvkm_fifo_chan, object)
#include "priv.h"
#ifndef __NVKM_CHAN_H__
#define __NVKM_CHAN_H__
#define nvkm_chan(p) container_of((p), struct nvkm_chan, object) /*FIXME: remove later */
#include <engine/fifo.h>

struct nvkm_fifo_chan_func {
struct nvkm_chan_func {
void *(*dtor)(struct nvkm_fifo_chan *);
void (*init)(struct nvkm_fifo_chan *);
void (*fini)(struct nvkm_fifo_chan *);
Expand All @@ -23,12 +23,7 @@ int nvkm_fifo_chan_ctor(const struct nvkm_fifo_chan_func *, struct nvkm_fifo *,
u32 size, u32 align, bool zero, u64 vm, u64 push,
u32 engm, int bar, u32 base, u32 user,
const struct nvkm_oclass *, struct nvkm_fifo_chan *);
void nvkm_chan_del(struct nvkm_chan **);

struct nvkm_fifo_chan_oclass {
int (*ctor)(struct nvkm_fifo *, const struct nvkm_oclass *,
void *data, u32 size, struct nvkm_object **);
struct nvkm_sclass base;
};

int gf100_fifo_chan_ntfy(struct nvkm_fifo_chan *, u32, struct nvkm_event **);
int nvkm_fifo_chan_child_new(const struct nvkm_oclass *, void *, u32, struct nvkm_object **);
#endif
4 changes: 0 additions & 4 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/dmanv04.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <core/ramht.h>
#include <subdev/instmem.h>

#include <nvif/class.h>
#include <nvif/cl006b.h>
#include <nvif/unpack.h>

Expand Down Expand Up @@ -219,8 +218,5 @@ nv04_fifo_dma_new(struct nvkm_fifo *base, const struct nvkm_oclass *oclass,

const struct nvkm_fifo_chan_oclass
nv04_fifo_dma_oclass = {
.base.oclass = NV03_CHANNEL_DMA,
.base.minver = 0,
.base.maxver = 0,
.ctor = nv04_fifo_dma_new,
};
4 changes: 0 additions & 4 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/dmanv10.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <core/gpuobj.h>
#include <subdev/instmem.h>

#include <nvif/class.h>
#include <nvif/cl006b.h>
#include <nvif/unpack.h>

Expand Down Expand Up @@ -90,8 +89,5 @@ nv10_fifo_dma_new(struct nvkm_fifo *base, const struct nvkm_oclass *oclass,

const struct nvkm_fifo_chan_oclass
nv10_fifo_dma_oclass = {
.base.oclass = NV10_CHANNEL_DMA,
.base.minver = 0,
.base.maxver = 0,
.ctor = nv10_fifo_dma_new,
};
4 changes: 0 additions & 4 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/dmanv17.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <core/gpuobj.h>
#include <subdev/instmem.h>

#include <nvif/class.h>
#include <nvif/cl006b.h>
#include <nvif/unpack.h>

Expand Down Expand Up @@ -91,8 +90,5 @@ nv17_fifo_dma_new(struct nvkm_fifo *base, const struct nvkm_oclass *oclass,

const struct nvkm_fifo_chan_oclass
nv17_fifo_dma_oclass = {
.base.oclass = NV17_CHANNEL_DMA,
.base.minver = 0,
.base.maxver = 0,
.ctor = nv17_fifo_dma_new,
};
4 changes: 0 additions & 4 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/dmanv40.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
#include <core/ramht.h>
#include <subdev/instmem.h>

#include <nvif/class.h>
#include <nvif/cl006b.h>
#include <nvif/unpack.h>

Expand Down Expand Up @@ -247,8 +246,5 @@ nv40_fifo_dma_new(struct nvkm_fifo *base, const struct nvkm_oclass *oclass,

const struct nvkm_fifo_chan_oclass
nv40_fifo_dma_oclass = {
.base.oclass = NV40_CHANNEL_DMA,
.base.minver = 0,
.base.maxver = 0,
.ctor = nv40_fifo_dma_new,
};
14 changes: 10 additions & 4 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/g84.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,17 @@
*
* Authors: Ben Skeggs
*/
#include "chan.h"

#include "nv50.h"
#include "channv50.h"

#include <nvif/class.h>

const struct nvkm_chan_func
g84_chan = {
};

static void
g84_fifo_uevent_fini(struct nvkm_fifo *fifo)
{
Expand Down Expand Up @@ -119,10 +127,8 @@ g84_fifo = {
.start = nv04_fifo_start,
.uevent_init = g84_fifo_uevent_init,
.uevent_fini = g84_fifo_uevent_fini,
.chan = {
&g84_fifo_gpfifo_oclass,
NULL
},
.cgrp = {{ }, &nv04_cgrp },
.chan = {{ 0, 0, G82_CHANNEL_GPFIFO }, &g84_chan, .oclass = &g84_fifo_gpfifo_oclass },
};

int
Expand Down
12 changes: 8 additions & 4 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/gf100.c
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,8 @@
*
* Authors: Ben Skeggs
*/
#include "chan.h"

#include "gf100.h"
#include "changf100.h"

Expand All @@ -47,6 +49,10 @@ gf100_fifo_uevent_fini(struct nvkm_fifo *fifo)
nvkm_mask(device, 0x002140, 0x80000000, 0x00000000);
}

static const struct nvkm_chan_func
gf100_chan = {
};

void
gf100_fifo_runlist_commit(struct gf100_fifo *fifo)
{
Expand Down Expand Up @@ -678,10 +684,8 @@ gf100_fifo = {
.id_engine = gf100_fifo_id_engine,
.uevent_init = gf100_fifo_uevent_init,
.uevent_fini = gf100_fifo_uevent_fini,
.chan = {
&gf100_fifo_gpfifo_oclass,
NULL
},
.cgrp = {{ }, &nv04_cgrp },
.chan = {{ 0, 0, FERMI_CHANNEL_GPFIFO }, &gf100_chan, .oclass = &gf100_fifo_gpfifo_oclass },
};

int
Expand Down
Loading

0 comments on commit f5e4568

Please sign in to comment.