@@ -225,41 +225,16 @@ static void swiotlb_init_io_tlb_mem(struct io_tlb_mem *mem, phys_addr_t start,
225
225
return ;
226
226
}
227
227
228
- int __init swiotlb_init_with_tbl (char * tlb , unsigned long nslabs ,
229
- unsigned int flags )
230
- {
231
- struct io_tlb_mem * mem = & io_tlb_default_mem ;
232
- size_t alloc_size ;
233
-
234
- if (swiotlb_force_disable )
235
- return 0 ;
236
-
237
- /* protect against double initialization */
238
- if (WARN_ON_ONCE (mem -> nslabs ))
239
- return - ENOMEM ;
240
-
241
- alloc_size = PAGE_ALIGN (array_size (sizeof (* mem -> slots ), nslabs ));
242
- mem -> slots = memblock_alloc (alloc_size , PAGE_SIZE );
243
- if (!mem -> slots )
244
- panic ("%s: Failed to allocate %zu bytes align=0x%lx\n" ,
245
- __func__ , alloc_size , PAGE_SIZE );
246
-
247
- swiotlb_init_io_tlb_mem (mem , __pa (tlb ), nslabs , false);
248
- mem -> force_bounce = flags & SWIOTLB_FORCE ;
249
-
250
- if (flags & SWIOTLB_VERBOSE )
251
- swiotlb_print_info ();
252
- return 0 ;
253
- }
254
-
255
228
/*
256
229
* Statically reserve bounce buffer space and initialize bounce buffer data
257
230
* structures for the software IO TLB used to implement the DMA API.
258
231
*/
259
232
void __init swiotlb_init_remap (bool addressing_limit , unsigned int flags ,
260
233
int (* remap )(void * tlb , unsigned long nslabs ))
261
234
{
235
+ struct io_tlb_mem * mem = & io_tlb_default_mem ;
262
236
unsigned long nslabs = default_nslabs ;
237
+ size_t alloc_size = PAGE_ALIGN (array_size (sizeof (* mem -> slots ), nslabs ));
263
238
size_t bytes ;
264
239
void * tlb ;
265
240
@@ -280,7 +255,8 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
280
255
else
281
256
tlb = memblock_alloc_low (bytes , PAGE_SIZE );
282
257
if (!tlb )
283
- goto fail ;
258
+ panic ("%s: failed to allocate tlb structure\n" , __func__ );
259
+
284
260
if (remap && remap (tlb , nslabs ) < 0 ) {
285
261
memblock_free (tlb , PAGE_ALIGN (bytes ));
286
262
@@ -290,14 +266,17 @@ void __init swiotlb_init_remap(bool addressing_limit, unsigned int flags,
290
266
__func__ , bytes );
291
267
goto retry ;
292
268
}
293
- if (swiotlb_init_with_tbl (tlb , default_nslabs , flags ))
294
- goto fail_free_mem ;
295
- return ;
296
269
297
- fail_free_mem :
298
- memblock_free (tlb , bytes );
299
- fail :
300
- pr_warn ("Cannot allocate buffer" );
270
+ mem -> slots = memblock_alloc (alloc_size , PAGE_SIZE );
271
+ if (!mem -> slots )
272
+ panic ("%s: Failed to allocate %zu bytes align=0x%lx\n" ,
273
+ __func__ , alloc_size , PAGE_SIZE );
274
+
275
+ swiotlb_init_io_tlb_mem (mem , __pa (tlb ), default_nslabs , false);
276
+ mem -> force_bounce = flags & SWIOTLB_FORCE ;
277
+
278
+ if (flags & SWIOTLB_VERBOSE )
279
+ swiotlb_print_info ();
301
280
}
302
281
303
282
void __init swiotlb_init (bool addressing_limit , unsigned int flags )
@@ -313,6 +292,7 @@ void __init swiotlb_init(bool addressing_limit, unsigned int flags)
313
292
int swiotlb_init_late (size_t size , gfp_t gfp_mask ,
314
293
int (* remap )(void * tlb , unsigned long nslabs ))
315
294
{
295
+ struct io_tlb_mem * mem = & io_tlb_default_mem ;
316
296
unsigned long nslabs = ALIGN (size >> IO_TLB_SHIFT , IO_TLB_SEGSIZE );
317
297
unsigned long bytes ;
318
298
unsigned char * vstart = NULL ;
@@ -353,33 +333,16 @@ int swiotlb_init_late(size_t size, gfp_t gfp_mask,
353
333
return rc ;
354
334
goto retry ;
355
335
}
356
- rc = swiotlb_late_init_with_tbl (vstart , nslabs );
357
- if (rc )
358
- free_pages ((unsigned long )vstart , order );
359
-
360
- return rc ;
361
- }
362
-
363
- int
364
- swiotlb_late_init_with_tbl (char * tlb , unsigned long nslabs )
365
- {
366
- struct io_tlb_mem * mem = & io_tlb_default_mem ;
367
- unsigned long bytes = nslabs << IO_TLB_SHIFT ;
368
-
369
- if (swiotlb_force_disable )
370
- return 0 ;
371
-
372
- /* protect against double initialization */
373
- if (WARN_ON_ONCE (mem -> nslabs ))
374
- return - ENOMEM ;
375
336
376
337
mem -> slots = (void * )__get_free_pages (GFP_KERNEL | __GFP_ZERO ,
377
338
get_order (array_size (sizeof (* mem -> slots ), nslabs )));
378
- if (!mem -> slots )
339
+ if (!mem -> slots ) {
340
+ free_pages ((unsigned long )vstart , order );
379
341
return - ENOMEM ;
342
+ }
380
343
381
- set_memory_decrypted ((unsigned long )tlb , bytes >> PAGE_SHIFT );
382
- swiotlb_init_io_tlb_mem (mem , virt_to_phys (tlb ), nslabs , true);
344
+ set_memory_decrypted ((unsigned long )vstart , bytes >> PAGE_SHIFT );
345
+ swiotlb_init_io_tlb_mem (mem , virt_to_phys (vstart ), nslabs , true);
383
346
384
347
swiotlb_print_info ();
385
348
return 0 ;
0 commit comments