Skip to content

Commit c9da4a4

Browse files
Michel Dänzeralexdeucher
authored andcommitted
drm/radeon: Try placing NO_CPU_ACCESS BOs outside of CPU accessible VRAM
This avoids them getting in the way of BOs which might be accessed by the CPU. They can still go to the CPU accessible part of VRAM though if there's no space outside of it. Signed-off-by: Michel Dänzer <[email protected]> Signed-off-by: Alex Deucher <[email protected]>
1 parent fcf93f6 commit c9da4a4

File tree

2 files changed

+36
-8
lines changed

2 files changed

+36
-8
lines changed

drivers/gpu/drm/radeon/radeon.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -474,7 +474,7 @@ struct radeon_bo {
474474
struct list_head list;
475475
/* Protected by tbo.reserved */
476476
u32 initial_domain;
477-
struct ttm_place placements[3];
477+
struct ttm_place placements[4];
478478
struct ttm_placement placement;
479479
struct ttm_buffer_object tbo;
480480
struct ttm_bo_kmap_obj kmap;

drivers/gpu/drm/radeon/radeon_object.c

Lines changed: 35 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -99,53 +99,75 @@ void radeon_ttm_placement_from_domain(struct radeon_bo *rbo, u32 domain)
9999

100100
rbo->placement.placement = rbo->placements;
101101
rbo->placement.busy_placement = rbo->placements;
102-
if (domain & RADEON_GEM_DOMAIN_VRAM)
102+
if (domain & RADEON_GEM_DOMAIN_VRAM) {
103+
/* Try placing BOs which don't need CPU access outside of the
104+
* CPU accessible part of VRAM
105+
*/
106+
if ((rbo->flags & RADEON_GEM_NO_CPU_ACCESS) &&
107+
rbo->rdev->mc.visible_vram_size < rbo->rdev->mc.real_vram_size) {
108+
rbo->placements[c].fpfn =
109+
rbo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
110+
rbo->placements[c++].flags = TTM_PL_FLAG_WC |
111+
TTM_PL_FLAG_UNCACHED |
112+
TTM_PL_FLAG_VRAM;
113+
}
114+
115+
rbo->placements[c].fpfn = 0;
103116
rbo->placements[c++].flags = TTM_PL_FLAG_WC |
104117
TTM_PL_FLAG_UNCACHED |
105118
TTM_PL_FLAG_VRAM;
119+
}
106120

107121
if (domain & RADEON_GEM_DOMAIN_GTT) {
108122
if (rbo->flags & RADEON_GEM_GTT_UC) {
123+
rbo->placements[c].fpfn = 0;
109124
rbo->placements[c++].flags = TTM_PL_FLAG_UNCACHED |
110125
TTM_PL_FLAG_TT;
111126

112127
} else if ((rbo->flags & RADEON_GEM_GTT_WC) ||
113128
(rbo->rdev->flags & RADEON_IS_AGP)) {
129+
rbo->placements[c].fpfn = 0;
114130
rbo->placements[c++].flags = TTM_PL_FLAG_WC |
115131
TTM_PL_FLAG_UNCACHED |
116132
TTM_PL_FLAG_TT;
117133
} else {
134+
rbo->placements[c].fpfn = 0;
118135
rbo->placements[c++].flags = TTM_PL_FLAG_CACHED |
119136
TTM_PL_FLAG_TT;
120137
}
121138
}
122139

123140
if (domain & RADEON_GEM_DOMAIN_CPU) {
124141
if (rbo->flags & RADEON_GEM_GTT_UC) {
142+
rbo->placements[c].fpfn = 0;
125143
rbo->placements[c++].flags = TTM_PL_FLAG_UNCACHED |
126144
TTM_PL_FLAG_SYSTEM;
127145

128146
} else if ((rbo->flags & RADEON_GEM_GTT_WC) ||
129147
rbo->rdev->flags & RADEON_IS_AGP) {
148+
rbo->placements[c].fpfn = 0;
130149
rbo->placements[c++].flags = TTM_PL_FLAG_WC |
131150
TTM_PL_FLAG_UNCACHED |
132151
TTM_PL_FLAG_SYSTEM;
133152
} else {
153+
rbo->placements[c].fpfn = 0;
134154
rbo->placements[c++].flags = TTM_PL_FLAG_CACHED |
135155
TTM_PL_FLAG_SYSTEM;
136156
}
137157
}
138-
if (!c)
158+
if (!c) {
159+
rbo->placements[c].fpfn = 0;
139160
rbo->placements[c++].flags = TTM_PL_MASK_CACHING |
140161
TTM_PL_FLAG_SYSTEM;
162+
}
141163

142164
rbo->placement.num_placement = c;
143165
rbo->placement.num_busy_placement = c;
144166

145167
for (i = 0; i < c; ++i) {
146-
rbo->placements[i].fpfn = 0;
147168
if ((rbo->flags & RADEON_GEM_CPU_ACCESS) &&
148-
(rbo->placements[i].flags & TTM_PL_FLAG_VRAM))
169+
(rbo->placements[i].flags & TTM_PL_FLAG_VRAM) &&
170+
!rbo->placements[i].fpfn)
149171
rbo->placements[i].lpfn =
150172
rbo->rdev->mc.visible_vram_size >> PAGE_SHIFT;
151173
else
@@ -743,8 +765,8 @@ int radeon_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
743765
{
744766
struct radeon_device *rdev;
745767
struct radeon_bo *rbo;
746-
unsigned long offset, size;
747-
int r;
768+
unsigned long offset, size, lpfn;
769+
int i, r;
748770

749771
if (!radeon_ttm_bo_is_radeon_bo(bo))
750772
return 0;
@@ -761,7 +783,13 @@ int radeon_bo_fault_reserve_notify(struct ttm_buffer_object *bo)
761783

762784
/* hurrah the memory is not visible ! */
763785
radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_VRAM);
764-
rbo->placements[0].lpfn = rdev->mc.visible_vram_size >> PAGE_SHIFT;
786+
lpfn = rdev->mc.visible_vram_size >> PAGE_SHIFT;
787+
for (i = 0; i < rbo->placement.num_placement; i++) {
788+
/* Force into visible VRAM */
789+
if ((rbo->placements[i].flags & TTM_PL_FLAG_VRAM) &&
790+
(!rbo->placements[i].lpfn || rbo->placements[i].lpfn > lpfn))
791+
rbo->placements[i].lpfn = lpfn;
792+
}
765793
r = ttm_bo_validate(bo, &rbo->placement, false, false);
766794
if (unlikely(r == -ENOMEM)) {
767795
radeon_ttm_placement_from_domain(rbo, RADEON_GEM_DOMAIN_GTT);

0 commit comments

Comments
 (0)