Skip to content

Commit 834a712

Browse files
Ben Skeggsairlied
authored andcommitted
drm/nouveau/fb/tu102-: prepare for GSP-RM
- add (initial) R535 implementation of FB, need VRAM size etc for boot - expose a way to "wrap" vram at a specific address/size as a standard nvkm_memory allocation, which will be used to write PTEs etc for RM- defined memory regions 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-11-skeggsb@gmail.com
1 parent a613e7f commit 834a712

8 files changed

Lines changed: 113 additions & 8 deletions

File tree

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -158,9 +158,9 @@ struct nvkm_ram {
158158
struct nvkm_ram_data target;
159159
};
160160

161-
int
162-
nvkm_ram_get(struct nvkm_device *, u8 heap, u8 type, u8 page, u64 size,
163-
bool contig, bool back, struct nvkm_memory **);
161+
int nvkm_ram_wrap(struct nvkm_device *, u64 addr, u64 size, struct nvkm_memory **);
162+
int nvkm_ram_get(struct nvkm_device *, u8 heap, u8 type, u8 page, u64 size,
163+
bool contig, bool back, struct nvkm_memory **);
164164

165165
struct nvkm_ram_func {
166166
u64 upper;

drivers/gpu/drm/nouveau/nvkm/subdev/fb/Kbuild

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ nvkm-y += nvkm/subdev/fb/tu102.o
3636
nvkm-y += nvkm/subdev/fb/ga100.o
3737
nvkm-y += nvkm/subdev/fb/ga102.o
3838

39+
nvkm-y += nvkm/subdev/fb/r535.o
40+
3941
nvkm-y += nvkm/subdev/fb/ram.o
4042
nvkm-y += nvkm/subdev/fb/ramnv04.o
4143
nvkm-y += nvkm/subdev/fb/ramnv10.o

drivers/gpu/drm/nouveau/nvkm/subdev/fb/ga100.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "gf100.h"
2323
#include "ram.h"
2424

25+
#include <subdev/gsp.h>
26+
2527
static const struct nvkm_fb_func
2628
ga100_fb = {
2729
.dtor = gf100_fb_dtor,
@@ -38,5 +40,8 @@ ga100_fb = {
3840
int
3941
ga100_fb_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst, struct nvkm_fb **pfb)
4042
{
43+
if (nvkm_gsp_rm(device->gsp))
44+
return r535_fb_new(&ga100_fb, device, type, inst, pfb);
45+
4146
return gf100_fb_new_(&ga100_fb, device, type, inst, pfb);
4247
}

drivers/gpu/drm/nouveau/nvkm/subdev/fb/ga102.c

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@
2222
#include "gf100.h"
2323
#include "ram.h"
2424

25+
#include <subdev/gsp.h>
2526
#include <engine/nvdec.h>
2627

2728
static u64
@@ -59,6 +60,9 @@ ga102_fb = {
5960
int
6061
ga102_fb_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst, struct nvkm_fb **pfb)
6162
{
63+
if (nvkm_gsp_rm(device->gsp))
64+
return r535_fb_new(&ga102_fb, device, type, inst, pfb);
65+
6266
return gf100_fb_new_(&ga102_fb, device, type, inst, pfb);
6367
}
6468

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include <subdev/therm.h>
77
struct nvkm_bios;
88

9+
int r535_fb_new(const struct nvkm_fb_func *,
10+
struct nvkm_device *, enum nvkm_subdev_type, int inst, struct nvkm_fb **);
11+
912
struct nvkm_fb_func {
1013
void *(*dtor)(struct nvkm_fb *);
1114
u32 (*tags)(struct nvkm_fb *);
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
/*
2+
* Copyright 2023 Red Hat Inc.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a
5+
* copy of this software and associated documentation files (the "Software"),
6+
* to deal in the Software without restriction, including without limitation
7+
* the rights to use, copy, modify, merge, publish, distribute, sublicense,
8+
* and/or sell copies of the Software, and to permit persons to whom the
9+
* Software is furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in
12+
* all copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
17+
* THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
18+
* OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
19+
* ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
20+
* OTHER DEALINGS IN THE SOFTWARE.
21+
*/
22+
#include "priv.h"
23+
24+
static void *
25+
r535_fb_dtor(struct nvkm_fb *fb)
26+
{
27+
kfree(fb->func);
28+
return fb;
29+
}
30+
31+
int
32+
r535_fb_new(const struct nvkm_fb_func *hw,
33+
struct nvkm_device *device, enum nvkm_subdev_type type, int inst, struct nvkm_fb **pfb)
34+
{
35+
struct nvkm_fb_func *rm;
36+
int ret;
37+
38+
if (!(rm = kzalloc(sizeof(*rm), GFP_KERNEL)))
39+
return -ENOMEM;
40+
41+
rm->dtor = r535_fb_dtor;
42+
rm->sysmem.flush_page_init = hw->sysmem.flush_page_init;
43+
rm->vidmem.size = hw->vidmem.size;
44+
45+
ret = nvkm_fb_new_(rm, device, type, inst, pfb);
46+
if (ret)
47+
kfree(rm);
48+
49+
return ret;
50+
}

drivers/gpu/drm/nouveau/nvkm/subdev/fb/ram.c

Lines changed: 41 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,12 +88,20 @@ nvkm_vram_dtor(struct nvkm_memory *memory)
8888
struct nvkm_vram *vram = nvkm_vram(memory);
8989
struct nvkm_mm_node *next = vram->mn;
9090
struct nvkm_mm_node *node;
91-
mutex_lock(&vram->ram->mutex);
92-
while ((node = next)) {
93-
next = node->next;
94-
nvkm_mm_free(&vram->ram->vram, &node);
91+
92+
if (next) {
93+
if (likely(next->nl_entry.next)){
94+
mutex_lock(&vram->ram->mutex);
95+
while ((node = next)) {
96+
next = node->next;
97+
nvkm_mm_free(&vram->ram->vram, &node);
98+
}
99+
mutex_unlock(&vram->ram->mutex);
100+
} else {
101+
kfree(vram->mn);
102+
}
95103
}
96-
mutex_unlock(&vram->ram->mutex);
104+
97105
return vram;
98106
}
99107

@@ -108,6 +116,34 @@ nvkm_vram = {
108116
.kmap = nvkm_vram_kmap,
109117
};
110118

119+
int
120+
nvkm_ram_wrap(struct nvkm_device *device, u64 addr, u64 size,
121+
struct nvkm_memory **pmemory)
122+
{
123+
struct nvkm_ram *ram;
124+
struct nvkm_vram *vram;
125+
126+
if (!device->fb || !(ram = device->fb->ram))
127+
return -ENODEV;
128+
ram = device->fb->ram;
129+
130+
if (!(vram = kzalloc(sizeof(*vram), GFP_KERNEL)))
131+
return -ENOMEM;
132+
133+
nvkm_memory_ctor(&nvkm_vram, &vram->memory);
134+
vram->ram = ram;
135+
vram->page = NVKM_RAM_MM_SHIFT;
136+
*pmemory = &vram->memory;
137+
138+
vram->mn = kzalloc(sizeof(*vram->mn), GFP_KERNEL);
139+
if (!vram->mn)
140+
return -ENOMEM;
141+
142+
vram->mn->offset = addr >> NVKM_RAM_MM_SHIFT;
143+
vram->mn->length = size >> NVKM_RAM_MM_SHIFT;
144+
return 0;
145+
}
146+
111147
int
112148
nvkm_ram_get(struct nvkm_device *device, u8 heap, u8 type, u8 rpage, u64 size,
113149
bool contig, bool back, struct nvkm_memory **pmemory)

drivers/gpu/drm/nouveau/nvkm/subdev/fb/tu102.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
#include "gf100.h"
2323
#include "ram.h"
2424

25+
#include <subdev/gsp.h>
26+
2527
bool
2628
tu102_fb_vpr_scrub_required(struct nvkm_fb *fb)
2729
{
@@ -46,6 +48,9 @@ tu102_fb = {
4648
int
4749
tu102_fb_new(struct nvkm_device *device, enum nvkm_subdev_type type, int inst, struct nvkm_fb **pfb)
4850
{
51+
if (nvkm_gsp_rm(device->gsp))
52+
return r535_fb_new(&tu102_fb, device, type, inst, pfb);
53+
4954
return gf100_fb_new_(&tu102_fb, device, type, inst, pfb);
5055
}
5156

0 commit comments

Comments
 (0)