Skip to content

Commit

Permalink
drm/nouveau/fifo: add chid allocator
Browse files Browse the repository at this point in the history
We need to be able to allocate TSG IDs as well as channel IDs, also,
Ampere has per-runlist channel IDs.

- holds per-ID private data, which will be used for/to protect lookup
- holds an nvkm_event which will be used for events tied to IDs
- not used yet beyond setup, and switching use of "fifo->nr - 1" for
  channel ID mask to "chid->mask"

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 9be9c60 commit 800ac1f
Show file tree
Hide file tree
Showing 26 changed files with 209 additions and 21 deletions.
3 changes: 3 additions & 0 deletions drivers/gpu/drm/nouveau/include/nvkm/engine/fifo.h
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,9 @@ struct nvkm_fifo {
const struct nvkm_fifo_func *func;
struct nvkm_engine engine;

struct nvkm_chid *chid;
struct nvkm_chid *cgid;

DECLARE_BITMAP(mask, NVKM_FIFO_CHID_NR);
int nr;
struct list_head chan;
Expand Down
4 changes: 3 additions & 1 deletion drivers/gpu/drm/nouveau/nvkm/engine/fifo/Kbuild
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
# SPDX-License-Identifier: MIT
nvkm-y += nvkm/engine/fifo/base.o
nvkm-y += nvkm/engine/fifo/chan.o
nvkm-y += nvkm/engine/fifo/chid.o

nvkm-y += nvkm/engine/fifo/nv04.o
nvkm-y += nvkm/engine/fifo/nv10.o
nvkm-y += nvkm/engine/fifo/nv17.o
Expand All @@ -18,7 +21,6 @@ nvkm-y += nvkm/engine/fifo/gv100.o
nvkm-y += nvkm/engine/fifo/tu102.o
nvkm-y += nvkm/engine/fifo/ga102.o

nvkm-y += nvkm/engine/fifo/chan.o
nvkm-y += nvkm/engine/fifo/channv50.o
nvkm-y += nvkm/engine/fifo/chang84.o

Expand Down
20 changes: 18 additions & 2 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/base.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
#include "priv.h"
#include "chan.h"
#include "chid.h"

#include <core/gpuobj.h>
#include <subdev/mc.h>
Expand Down Expand Up @@ -218,22 +219,34 @@ static int
nvkm_fifo_info(struct nvkm_engine *engine, u64 mthd, u64 *data)
{
struct nvkm_fifo *fifo = nvkm_fifo(engine);

switch (mthd) {
case NV_DEVICE_HOST_CHANNELS: *data = fifo->nr; return 0;
case NV_DEVICE_HOST_CHANNELS: *data = fifo->chid ? fifo->chid->nr : 0; return 0;
default:
if (fifo->func->info)
return fifo->func->info(fifo, mthd, data);
break;
}

return -ENOSYS;
}

static int
nvkm_fifo_oneinit(struct nvkm_engine *engine)
{
struct nvkm_fifo *fifo = nvkm_fifo(engine);
int ret;

/* Initialise CHID/CGID allocator(s) on GPUs where they aren't per-runlist. */
if (fifo->func->chid_nr) {
ret = fifo->func->chid_ctor(fifo, fifo->func->chid_nr(fifo));
if (ret)
return ret;
}

if (fifo->func->oneinit)
return fifo->func->oneinit(fifo);

return 0;
}

Expand All @@ -248,6 +261,10 @@ nvkm_fifo_dtor(struct nvkm_engine *engine)
{
struct nvkm_fifo *fifo = nvkm_fifo(engine);
void *data = fifo;

nvkm_chid_unref(&fifo->cgid);
nvkm_chid_unref(&fifo->chid);

if (fifo->func->dtor)
data = fifo->func->dtor(fifo);
nvkm_event_fini(&fifo->kevent);
Expand Down Expand Up @@ -289,7 +306,6 @@ nvkm_fifo_ctor(const struct nvkm_fifo_func *func, struct nvkm_device *device,
fifo->nr = NVKM_FIFO_CHID_NR;
else
fifo->nr = nr;
bitmap_clear(fifo->mask, 0, fifo->nr);

if (func->uevent_init) {
ret = nvkm_event_init(&nvkm_fifo_uevent_func, &fifo->engine.subdev, 1, 1,
Expand Down
4 changes: 4 additions & 0 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/chan.c
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,10 @@

#include <nvif/if0020.h>

const struct nvkm_event_func
nvkm_chan_event = {
};

struct nvkm_fifo_chan_object {
struct nvkm_oproxy oproxy;
struct nvkm_fifo_chan *chan;
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/chan.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
#define nvkm_chan(p) container_of((p), struct nvkm_chan, object) /*FIXME: remove later */
#include <engine/fifo.h>

extern const struct nvkm_event_func nvkm_chan_event;

struct nvkm_chan_func {
void *(*dtor)(struct nvkm_fifo_chan *);
void (*init)(struct nvkm_fifo_chan *);
Expand Down
82 changes: 82 additions & 0 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/chid.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
/*
* Copyright 2020 Red Hat Inc.
*
* 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 "chid.h"

static void
nvkm_chid_del(struct kref *kref)
{
struct nvkm_chid *chid = container_of(kref, typeof(*chid), kref);

nvkm_event_fini(&chid->event);

kvfree(chid->data);
kfree(chid);
}

void
nvkm_chid_unref(struct nvkm_chid **pchid)
{
struct nvkm_chid *chid = *pchid;

if (!chid)
return;

kref_put(&chid->kref, nvkm_chid_del);
*pchid = NULL;
}

struct nvkm_chid *
nvkm_chid_ref(struct nvkm_chid *chid)
{
if (chid)
kref_get(&chid->kref);

return chid;
}

int
nvkm_chid_new(const struct nvkm_event_func *func, struct nvkm_subdev *subdev,
int nr, int first, int count, struct nvkm_chid **pchid)
{
struct nvkm_chid *chid;
int id;

if (!(chid = *pchid = kzalloc(struct_size(chid, used, nr), GFP_KERNEL)))
return -ENOMEM;

kref_init(&chid->kref);
chid->nr = nr;
chid->mask = chid->nr - 1;
spin_lock_init(&chid->lock);

if (!(chid->data = kvzalloc(sizeof(*chid->data) * nr, GFP_KERNEL))) {
nvkm_chid_unref(pchid);
return -ENOMEM;
}

for (id = 0; id < first; id++)
__set_bit(id, chid->used);
for (id = first + count; id < nr; id++)
__set_bit(id, chid->used);

return nvkm_event_init(func, subdev, 1, nr, &chid->event);
}
23 changes: 23 additions & 0 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/chid.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* SPDX-License-Identifier: MIT */
#ifndef __NVKM_CHID_H__
#define __NVKM_CHID_H__
#include <core/event.h>

struct nvkm_chid {
struct kref kref;
int nr;
u32 mask;

struct nvkm_event event;

void **data;

spinlock_t lock;
unsigned long used[];
};

int nvkm_chid_new(const struct nvkm_event_func *, struct nvkm_subdev *,
int nr, int first, int count, struct nvkm_chid **pchid);
struct nvkm_chid *nvkm_chid_ref(struct nvkm_chid *);
void nvkm_chid_unref(struct nvkm_chid **);
#endif
1 change: 1 addition & 0 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/g84.c
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,7 @@ g84_fifo = {
.dtor = nv50_fifo_dtor,
.oneinit = nv50_fifo_oneinit,
.chid_nr = nv50_fifo_chid_nr,
.chid_ctor = nv50_fifo_chid_ctor,
.init = nv50_fifo_init,
.intr = nv04_fifo_intr,
.engine_id = g84_fifo_engine_id,
Expand Down
8 changes: 8 additions & 0 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/gf100.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Authors: Ben Skeggs
*/
#include "chan.h"
#include "chid.h"

#include "gf100.h"
#include "changf100.h"
Expand Down Expand Up @@ -624,6 +625,12 @@ gf100_fifo_init(struct nvkm_fifo *base)
nvkm_wr32(device, 0x002628, 0x00000001); /* ENGINE_INTR_EN */
}

int
gf100_fifo_chid_ctor(struct nvkm_fifo *fifo, int nr)
{
return nvkm_chid_new(&nvkm_chan_event, &fifo->engine.subdev, nr, 0, nr, &fifo->chid);
}

static int
gf100_fifo_oneinit(struct nvkm_fifo *base)
{
Expand Down Expand Up @@ -681,6 +688,7 @@ gf100_fifo = {
.dtor = gf100_fifo_dtor,
.oneinit = gf100_fifo_oneinit,
.chid_nr = nv50_fifo_chid_nr,
.chid_ctor = gf100_fifo_chid_ctor,
.init = gf100_fifo_init,
.fini = gf100_fifo_fini,
.intr = gf100_fifo_intr,
Expand Down
2 changes: 2 additions & 0 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/gk104.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@
* Authors: Ben Skeggs
*/
#include "chan.h"
#include "chid.h"

#include "gk104.h"
#include "cgrp.h"
Expand Down Expand Up @@ -1193,6 +1194,7 @@ gk104_fifo = {
.dtor = gk104_fifo_dtor,
.oneinit = gk104_fifo_oneinit,
.chid_nr = gk104_fifo_chid_nr,
.chid_ctor = gf100_fifo_chid_ctor,
.info = gk104_fifo_info,
.init = gk104_fifo_init,
.fini = gk104_fifo_fini,
Expand Down
2 changes: 1 addition & 1 deletion drivers/gpu/drm/nouveau/nvkm/engine/fifo/gk104.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ void gk104_fifo_intr_pbdma_1(struct gk104_fifo *fifo, int unit);
void gk104_fifo_intr_runlist(struct gk104_fifo *fifo);
void gk104_fifo_intr_engine(struct gk104_fifo *fifo);
void *gk104_fifo_dtor(struct nvkm_fifo *base);
int gk104_fifo_oneinit(struct nvkm_fifo *base);
int gk104_fifo_oneinit(struct nvkm_fifo *);
int gk104_fifo_info(struct nvkm_fifo *base, u64 mthd, u64 *data);
void gk104_fifo_init(struct nvkm_fifo *base);
void gk104_fifo_fini(struct nvkm_fifo *base);
Expand Down
14 changes: 14 additions & 0 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/gk110.c
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
*/
#include "cgrp.h"
#include "chan.h"
#include "chid.h"

#include "gk104.h"
#include "changk104.h"
Expand Down Expand Up @@ -56,11 +57,24 @@ gk110_fifo_runlist = {
.commit = gk104_fifo_runlist_commit,
};

int
gk110_fifo_chid_ctor(struct nvkm_fifo *fifo, int nr)
{
int ret;

ret = nvkm_chid_new(&nvkm_chan_event, &fifo->engine.subdev, nr, 0, nr, &fifo->cgid);
if (ret)
return ret;

return gf100_fifo_chid_ctor(fifo, nr);
}

static const struct nvkm_fifo_func
gk110_fifo = {
.dtor = gk104_fifo_dtor,
.oneinit = gk104_fifo_oneinit,
.chid_nr = gk104_fifo_chid_nr,
.chid_ctor = gk110_fifo_chid_ctor,
.info = gk104_fifo_info,
.init = gk104_fifo_init,
.fini = gk104_fifo_fini,
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/gk208.c
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@ gk208_fifo = {
.dtor = gk104_fifo_dtor,
.oneinit = gk104_fifo_oneinit,
.chid_nr = gk208_fifo_chid_nr,
.chid_ctor = gk110_fifo_chid_ctor,
.info = gk104_fifo_info,
.init = gk104_fifo_init,
.fini = gk104_fifo_fini,
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/gk20a.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ gk20a_fifo = {
.dtor = gk104_fifo_dtor,
.oneinit = gk104_fifo_oneinit,
.chid_nr = nv50_fifo_chid_nr,
.chid_ctor = gk110_fifo_chid_ctor,
.info = gk104_fifo_info,
.init = gk104_fifo_init,
.fini = gk104_fifo_fini,
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/gm107.c
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,7 @@ gm107_fifo = {
.dtor = gk104_fifo_dtor,
.oneinit = gk104_fifo_oneinit,
.chid_nr = gm107_fifo_chid_nr,
.chid_ctor = gk110_fifo_chid_ctor,
.info = gk104_fifo_info,
.init = gk104_fifo_init,
.fini = gk104_fifo_fini,
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/gm200.c
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ gm200_fifo = {
.dtor = gk104_fifo_dtor,
.oneinit = gk104_fifo_oneinit,
.chid_nr = gm200_fifo_chid_nr,
.chid_ctor = gk110_fifo_chid_ctor,
.info = gk104_fifo_info,
.init = gk104_fifo_init,
.fini = gk104_fifo_fini,
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/gp100.c
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ gp100_fifo = {
.dtor = gk104_fifo_dtor,
.oneinit = gk104_fifo_oneinit,
.chid_nr = gm200_fifo_chid_nr,
.chid_ctor = gk110_fifo_chid_ctor,
.info = gk104_fifo_info,
.init = gk104_fifo_init,
.fini = gk104_fifo_fini,
Expand Down
1 change: 1 addition & 0 deletions drivers/gpu/drm/nouveau/nvkm/engine/fifo/gv100.c
Original file line number Diff line number Diff line change
Expand Up @@ -301,6 +301,7 @@ gv100_fifo = {
.dtor = gk104_fifo_dtor,
.oneinit = gk104_fifo_oneinit,
.chid_nr = gm200_fifo_chid_nr,
.chid_ctor = gk110_fifo_chid_ctor,
.info = gk104_fifo_info,
.init = gk104_fifo_init,
.fini = gk104_fifo_fini,
Expand Down
Loading

0 comments on commit 800ac1f

Please sign in to comment.