@@ -115,91 +115,85 @@ static int ttm_mem_io_evict(struct ttm_mem_type_manager *man)
115
115
{
116
116
struct ttm_buffer_object * bo ;
117
117
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 )
119
122
return - ENOSPC ;
120
123
121
- bo = list_first_entry (& man -> io_reserve_lru ,
122
- struct ttm_buffer_object ,
123
- io_reserve_lru );
124
124
list_del_init (& bo -> io_reserve_lru );
125
125
ttm_bo_unmap_virtual_locked (bo );
126
-
127
126
return 0 ;
128
127
}
129
128
130
-
131
129
int ttm_mem_io_reserve (struct ttm_bo_device * bdev ,
132
130
struct ttm_mem_reg * mem )
133
131
{
134
132
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 ;
136
137
137
138
if (!bdev -> driver -> io_mem_reserve )
138
139
return 0 ;
139
- if (likely (!man -> use_io_reserve_lru ))
140
- return bdev -> driver -> io_mem_reserve (bdev , mem );
141
140
142
- if (bdev -> driver -> io_mem_reserve &&
143
- mem -> bus .io_reserved_count ++ == 0 ) {
144
141
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 ;
151
147
}
152
148
return ret ;
153
149
}
154
150
155
151
void ttm_mem_io_free (struct ttm_bo_device * bdev ,
156
152
struct ttm_mem_reg * mem )
157
153
{
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 )
161
155
return ;
162
156
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 ;
167
159
160
+ bdev -> driver -> io_mem_free (bdev , mem );
168
161
}
169
162
170
163
int ttm_mem_io_reserve_vm (struct ttm_buffer_object * bo )
171
164
{
165
+ struct ttm_mem_type_manager * man = & bo -> bdev -> man [bo -> mem .mem_type ];
172
166
struct ttm_mem_reg * mem = & bo -> mem ;
173
167
int ret ;
174
168
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 ;
178
171
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 );
187
179
return 0 ;
188
180
}
189
181
190
182
void ttm_mem_io_free_vm (struct ttm_buffer_object * bo )
191
183
{
192
184
struct ttm_mem_reg * mem = & bo -> mem ;
193
185
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 );
199
192
}
200
193
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 )
203
197
{
204
198
struct ttm_mem_type_manager * man = & bdev -> man [mem -> mem_type ];
205
199
int ret ;
@@ -216,9 +210,11 @@ static int ttm_mem_reg_ioremap(struct ttm_bo_device *bdev, struct ttm_mem_reg *m
216
210
addr = mem -> bus .addr ;
217
211
} else {
218
212
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 );
220
215
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 );
222
218
if (!addr ) {
223
219
(void ) ttm_mem_io_lock (man , false);
224
220
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
230
226
return 0 ;
231
227
}
232
228
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 )
235
232
{
236
233
struct ttm_mem_type_manager * man ;
237
234
@@ -513,11 +510,13 @@ static int ttm_bo_ioremap(struct ttm_buffer_object *bo,
513
510
} else {
514
511
map -> bo_kmap_type = ttm_bo_map_iomap ;
515
512
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 ,
517
515
size );
518
516
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 );
521
520
}
522
521
return (!map -> virtual ) ? - ENOMEM : 0 ;
523
522
}
0 commit comments