Skip to content

Commit 624c6f7

Browse files
Ben Skeggsairlied
authored andcommitted
drm/nouveau/imem/tu102-: prepare for GSP-RM
- move suspend/resume paths to HW-specific code - allow (future) RM paths to be based on nv50_instmem Signed-off-by: Ben Skeggs <bskeggs@redhat.com> Signed-off-by: Dave Airlie <airlied@redhat.com> Link: https://patchwork.freedesktop.org/patch/msgid/20230918202149.4343-15-skeggsb@gmail.com
1 parent a25a5d5 commit 624c6f7

6 files changed

Lines changed: 96 additions & 30 deletions

File tree

drivers/gpu/drm/nouveau/include/nvkm/subdev/instmem.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ struct nvkm_instmem {
88
const struct nvkm_instmem_func *func;
99
struct nvkm_subdev subdev;
1010

11+
bool suspend;
12+
1113
spinlock_t lock;
1214
struct list_head list;
1315
struct list_head boot;

drivers/gpu/drm/nouveau/nvkm/subdev/instmem/base.c

Lines changed: 13 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
/******************************************************************************
2929
* instmem object base implementation
3030
*****************************************************************************/
31-
static void
31+
void
3232
nvkm_instobj_load(struct nvkm_instobj *iobj)
3333
{
3434
struct nvkm_memory *memory = &iobj->memory;
@@ -48,7 +48,7 @@ nvkm_instobj_load(struct nvkm_instobj *iobj)
4848
iobj->suspend = NULL;
4949
}
5050

51-
static int
51+
int
5252
nvkm_instobj_save(struct nvkm_instobj *iobj)
5353
{
5454
struct nvkm_memory *memory = &iobj->memory;
@@ -179,24 +179,14 @@ static int
179179
nvkm_instmem_fini(struct nvkm_subdev *subdev, bool suspend)
180180
{
181181
struct nvkm_instmem *imem = nvkm_instmem(subdev);
182-
struct nvkm_instobj *iobj;
182+
int ret;
183183

184184
if (suspend) {
185-
list_for_each_entry(iobj, &imem->list, head) {
186-
if (iobj->preserve) {
187-
int ret = nvkm_instobj_save(iobj);
188-
if (ret)
189-
return ret;
190-
}
191-
}
192-
193-
nvkm_bar_bar2_fini(subdev->device);
185+
ret = imem->func->suspend(imem);
186+
if (ret)
187+
return ret;
194188

195-
list_for_each_entry(iobj, &imem->boot, head) {
196-
int ret = nvkm_instobj_save(iobj);
197-
if (ret)
198-
return ret;
199-
}
189+
imem->suspend = true;
200190
}
201191

202192
if (imem->func->fini)
@@ -209,20 +199,16 @@ static int
209199
nvkm_instmem_init(struct nvkm_subdev *subdev)
210200
{
211201
struct nvkm_instmem *imem = nvkm_instmem(subdev);
212-
struct nvkm_instobj *iobj;
213202

214-
list_for_each_entry(iobj, &imem->boot, head) {
215-
if (iobj->suspend)
216-
nvkm_instobj_load(iobj);
217-
}
203+
if (imem->suspend) {
204+
if (imem->func->resume)
205+
imem->func->resume(imem);
218206

219-
nvkm_bar_bar2_init(subdev->device);
220-
221-
list_for_each_entry(iobj, &imem->list, head) {
222-
if (iobj->suspend)
223-
nvkm_instobj_load(iobj);
207+
imem->suspend = false;
208+
return 0;
224209
}
225210

211+
nvkm_bar_bar2_init(subdev->device);
226212
return 0;
227213
}
228214

drivers/gpu/drm/nouveau/nvkm/subdev/instmem/gk20a.c

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -564,6 +564,8 @@ gk20a_instmem_dtor(struct nvkm_instmem *base)
564564
static const struct nvkm_instmem_func
565565
gk20a_instmem = {
566566
.dtor = gk20a_instmem_dtor,
567+
.suspend = nv04_instmem_suspend,
568+
.resume = nv04_instmem_resume,
567569
.memory_new = gk20a_instobj_new,
568570
.zero = false,
569571
};

drivers/gpu/drm/nouveau/nvkm/subdev/instmem/nv04.c

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@
2525
#include "priv.h"
2626

2727
#include <core/ramht.h>
28+
#include <subdev/bar.h>
2829

2930
struct nv04_instmem {
3031
struct nvkm_instmem base;
@@ -154,6 +155,48 @@ nv04_instmem_wr32(struct nvkm_instmem *imem, u32 addr, u32 data)
154155
nvkm_wr32(imem->subdev.device, 0x700000 + addr, data);
155156
}
156157

158+
void
159+
nv04_instmem_resume(struct nvkm_instmem *imem)
160+
{
161+
struct nvkm_instobj *iobj;
162+
163+
list_for_each_entry(iobj, &imem->boot, head) {
164+
if (iobj->suspend)
165+
nvkm_instobj_load(iobj);
166+
}
167+
168+
nvkm_bar_bar2_init(imem->subdev.device);
169+
170+
list_for_each_entry(iobj, &imem->list, head) {
171+
if (iobj->suspend)
172+
nvkm_instobj_load(iobj);
173+
}
174+
}
175+
176+
int
177+
nv04_instmem_suspend(struct nvkm_instmem *imem)
178+
{
179+
struct nvkm_instobj *iobj;
180+
181+
list_for_each_entry(iobj, &imem->list, head) {
182+
if (iobj->preserve) {
183+
int ret = nvkm_instobj_save(iobj);
184+
if (ret)
185+
return ret;
186+
}
187+
}
188+
189+
nvkm_bar_bar2_fini(imem->subdev.device);
190+
191+
list_for_each_entry(iobj, &imem->boot, head) {
192+
int ret = nvkm_instobj_save(iobj);
193+
if (ret)
194+
return ret;
195+
}
196+
197+
return 0;
198+
}
199+
157200
static int
158201
nv04_instmem_oneinit(struct nvkm_instmem *base)
159202
{
@@ -210,6 +253,8 @@ static const struct nvkm_instmem_func
210253
nv04_instmem = {
211254
.dtor = nv04_instmem_dtor,
212255
.oneinit = nv04_instmem_oneinit,
256+
.suspend = nv04_instmem_suspend,
257+
.resume = nv04_instmem_resume,
213258
.rd32 = nv04_instmem_rd32,
214259
.wr32 = nv04_instmem_wr32,
215260
.memory_new = nv04_instobj_new,

drivers/gpu/drm/nouveau/nvkm/subdev/instmem/nv50.c

Lines changed: 24 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
#include <core/memory.h>
2828
#include <subdev/bar.h>
2929
#include <subdev/fb.h>
30+
#include <subdev/gsp.h>
3031
#include <subdev/mmu.h>
3132

3233
struct nv50_instmem {
@@ -394,24 +395,44 @@ nv50_instmem_fini(struct nvkm_instmem *base)
394395
nv50_instmem(base)->addr = ~0ULL;
395396
}
396397

398+
static void *
399+
nv50_instmem_dtor(struct nvkm_instmem *base)
400+
{
401+
return nv50_instmem(base);
402+
}
403+
397404
static const struct nvkm_instmem_func
398405
nv50_instmem = {
406+
.dtor = nv50_instmem_dtor,
399407
.fini = nv50_instmem_fini,
408+
.suspend = nv04_instmem_suspend,
409+
.resume = nv04_instmem_resume,
400410
.memory_new = nv50_instobj_new,
401411
.memory_wrap = nv50_instobj_wrap,
402412
.zero = false,
403413
};
404414

405415
int
406-
nv50_instmem_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
407-
struct nvkm_instmem **pimem)
416+
nv50_instmem_new_(const struct nvkm_instmem_func *func,
417+
struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
418+
struct nvkm_instmem **pimem)
408419
{
409420
struct nv50_instmem *imem;
410421

411422
if (!(imem = kzalloc(sizeof(*imem), GFP_KERNEL)))
412423
return -ENOMEM;
413-
nvkm_instmem_ctor(&nv50_instmem, device, type, inst, &imem->base);
424+
nvkm_instmem_ctor(func, device, type, inst, &imem->base);
414425
INIT_LIST_HEAD(&imem->lru);
415426
*pimem = &imem->base;
416427
return 0;
417428
}
429+
430+
int
431+
nv50_instmem_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst,
432+
struct nvkm_instmem **pimem)
433+
{
434+
if (nvkm_gsp_rm(device->gsp))
435+
return -ENODEV;
436+
437+
return nv50_instmem_new_(&nv50_instmem, device, type, inst, pimem);
438+
}

drivers/gpu/drm/nouveau/nvkm/subdev/instmem/priv.h

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
struct nvkm_instmem_func {
88
void *(*dtor)(struct nvkm_instmem *);
99
int (*oneinit)(struct nvkm_instmem *);
10+
int (*suspend)(struct nvkm_instmem *);
11+
void (*resume)(struct nvkm_instmem *);
1012
void (*fini)(struct nvkm_instmem *);
1113
u32 (*rd32)(struct nvkm_instmem *, u32 addr);
1214
void (*wr32)(struct nvkm_instmem *, u32 addr, u32 data);
@@ -16,10 +18,16 @@ struct nvkm_instmem_func {
1618
bool zero;
1719
};
1820

21+
int nv50_instmem_new_(const struct nvkm_instmem_func *, struct nvkm_device *,
22+
enum nvkm_subdev_type, int, struct nvkm_instmem **);
23+
1924
void nvkm_instmem_ctor(const struct nvkm_instmem_func *, struct nvkm_device *,
2025
enum nvkm_subdev_type, int, struct nvkm_instmem *);
2126
void nvkm_instmem_boot(struct nvkm_instmem *);
2227

28+
int nv04_instmem_suspend(struct nvkm_instmem *);
29+
void nv04_instmem_resume(struct nvkm_instmem *);
30+
2331
#include <core/memory.h>
2432

2533
struct nvkm_instobj {
@@ -32,4 +40,6 @@ struct nvkm_instobj {
3240
void nvkm_instobj_ctor(const struct nvkm_memory_func *func,
3341
struct nvkm_instmem *, struct nvkm_instobj *);
3442
void nvkm_instobj_dtor(struct nvkm_instmem *, struct nvkm_instobj *);
43+
int nvkm_instobj_save(struct nvkm_instobj *);
44+
void nvkm_instobj_load(struct nvkm_instobj *);
3545
#endif

0 commit comments

Comments
 (0)