Skip to content

Commit c1c440d

Browse files
drm/ttm: cleanup coding style and implementation.
Only functional change is to always keep io_reserved_count up to date for debugging even when it is not used otherwise. Signed-off-by: Christian König <[email protected]> Reviewed-by: Daniel Vetter <[email protected]> Link: https://patchwork.freedesktop.org/patch/378242/
1 parent ce74773 commit c1c440d

File tree

1 file changed

+48
-49
lines changed

1 file changed

+48
-49
lines changed

drivers/gpu/drm/ttm/ttm_bo_util.c

Lines changed: 48 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -115,91 +115,85 @@ static int ttm_mem_io_evict(struct ttm_mem_type_manager *man)
115115
{
116116
struct ttm_buffer_object *bo;
117117

118-
if (!man->use_io_reserve_lru || list_empty(&man->io_reserve_lru))
118+
bo = list_first_entry_or_null(&man->io_reserve_lru,
119+
struct ttm_buffer_object,
120+
io_reserve_lru);
121+
if (!bo)
119122
return -ENOSPC;
120123

121-
bo = list_first_entry(&man->io_reserve_lru,
122-
struct ttm_buffer_object,
123-
io_reserve_lru);
124124
list_del_init(&bo->io_reserve_lru);
125125
ttm_bo_unmap_virtual_locked(bo);
126-
127126
return 0;
128127
}
129128

130-
131129
int ttm_mem_io_reserve(struct ttm_bo_device *bdev,
132130
struct ttm_mem_reg *mem)
133131
{
134132
struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
135-
int ret = 0;
133+
int ret;
134+
135+
if (mem->bus.io_reserved_count++)
136+
return 0;
136137

137138
if (!bdev->driver->io_mem_reserve)
138139
return 0;
139-
if (likely(!man->use_io_reserve_lru))
140-
return bdev->driver->io_mem_reserve(bdev, mem);
141140

142-
if (bdev->driver->io_mem_reserve &&
143-
mem->bus.io_reserved_count++ == 0) {
144141
retry:
145-
ret = bdev->driver->io_mem_reserve(bdev, mem);
146-
if (ret == -ENOSPC) {
147-
ret = ttm_mem_io_evict(man);
148-
if (ret == 0)
149-
goto retry;
150-
}
142+
ret = bdev->driver->io_mem_reserve(bdev, mem);
143+
if (ret == -ENOSPC) {
144+
ret = ttm_mem_io_evict(man);
145+
if (ret == 0)
146+
goto retry;
151147
}
152148
return ret;
153149
}
154150

155151
void ttm_mem_io_free(struct ttm_bo_device *bdev,
156152
struct ttm_mem_reg *mem)
157153
{
158-
struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
159-
160-
if (likely(!man->use_io_reserve_lru))
154+
if (--mem->bus.io_reserved_count)
161155
return;
162156

163-
if (bdev->driver->io_mem_reserve &&
164-
--mem->bus.io_reserved_count == 0 &&
165-
bdev->driver->io_mem_free)
166-
bdev->driver->io_mem_free(bdev, mem);
157+
if (!bdev->driver->io_mem_free)
158+
return;
167159

160+
bdev->driver->io_mem_free(bdev, mem);
168161
}
169162

170163
int ttm_mem_io_reserve_vm(struct ttm_buffer_object *bo)
171164
{
165+
struct ttm_mem_type_manager *man = &bo->bdev->man[bo->mem.mem_type];
172166
struct ttm_mem_reg *mem = &bo->mem;
173167
int ret;
174168

175-
if (!mem->bus.io_reserved_vm) {
176-
struct ttm_mem_type_manager *man =
177-
&bo->bdev->man[mem->mem_type];
169+
if (mem->bus.io_reserved_vm)
170+
return 0;
178171

179-
ret = ttm_mem_io_reserve(bo->bdev, mem);
180-
if (unlikely(ret != 0))
181-
return ret;
182-
mem->bus.io_reserved_vm = true;
183-
if (man->use_io_reserve_lru)
184-
list_add_tail(&bo->io_reserve_lru,
185-
&man->io_reserve_lru);
186-
}
172+
ret = ttm_mem_io_reserve(bo->bdev, mem);
173+
if (unlikely(ret != 0))
174+
return ret;
175+
mem->bus.io_reserved_vm = true;
176+
if (man->use_io_reserve_lru)
177+
list_add_tail(&bo->io_reserve_lru,
178+
&man->io_reserve_lru);
187179
return 0;
188180
}
189181

190182
void ttm_mem_io_free_vm(struct ttm_buffer_object *bo)
191183
{
192184
struct ttm_mem_reg *mem = &bo->mem;
193185

194-
if (mem->bus.io_reserved_vm) {
195-
mem->bus.io_reserved_vm = false;
196-
list_del_init(&bo->io_reserve_lru);
197-
ttm_mem_io_free(bo->bdev, mem);
198-
}
186+
if (!mem->bus.io_reserved_vm)
187+
return;
188+
189+
mem->bus.io_reserved_vm = false;
190+
list_del_init(&bo->io_reserve_lru);
191+
ttm_mem_io_free(bo->bdev, mem);
199192
}
200193

201-
static int ttm_mem_reg_ioremap(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem,
202-
void **virtual)
194+
static int ttm_mem_reg_ioremap(struct ttm_bo_device *bdev,
195+
struct ttm_mem_reg *mem,
196+
void **virtual)
203197
{
204198
struct ttm_mem_type_manager *man = &bdev->man[mem->mem_type];
205199
int ret;
@@ -216,9 +210,11 @@ static int ttm_mem_reg_ioremap(struct ttm_bo_device *bdev, struct ttm_mem_reg *m
216210
addr = mem->bus.addr;
217211
} else {
218212
if (mem->placement & TTM_PL_FLAG_WC)
219-
addr = ioremap_wc(mem->bus.base + mem->bus.offset, mem->bus.size);
213+
addr = ioremap_wc(mem->bus.base + mem->bus.offset,
214+
mem->bus.size);
220215
else
221-
addr = ioremap(mem->bus.base + mem->bus.offset, mem->bus.size);
216+
addr = ioremap(mem->bus.base + mem->bus.offset,
217+
mem->bus.size);
222218
if (!addr) {
223219
(void) ttm_mem_io_lock(man, false);
224220
ttm_mem_io_free(bdev, mem);
@@ -230,8 +226,9 @@ static int ttm_mem_reg_ioremap(struct ttm_bo_device *bdev, struct ttm_mem_reg *m
230226
return 0;
231227
}
232228

233-
static void ttm_mem_reg_iounmap(struct ttm_bo_device *bdev, struct ttm_mem_reg *mem,
234-
void *virtual)
229+
static void ttm_mem_reg_iounmap(struct ttm_bo_device *bdev,
230+
struct ttm_mem_reg *mem,
231+
void *virtual)
235232
{
236233
struct ttm_mem_type_manager *man;
237234

@@ -513,11 +510,13 @@ static int ttm_bo_ioremap(struct ttm_buffer_object *bo,
513510
} else {
514511
map->bo_kmap_type = ttm_bo_map_iomap;
515512
if (mem->placement & TTM_PL_FLAG_WC)
516-
map->virtual = ioremap_wc(bo->mem.bus.base + bo->mem.bus.offset + offset,
513+
map->virtual = ioremap_wc(bo->mem.bus.base +
514+
bo->mem.bus.offset + offset,
517515
size);
518516
else
519-
map->virtual = ioremap(bo->mem.bus.base + bo->mem.bus.offset + offset,
520-
size);
517+
map->virtual = ioremap(bo->mem.bus.base +
518+
bo->mem.bus.offset + offset,
519+
size);
521520
}
522521
return (!map->virtual) ? -ENOMEM : 0;
523522
}

0 commit comments

Comments
 (0)