@@ -65,7 +65,7 @@ extern char _start[];
65
65
void * _dtb_early_va __initdata ;
66
66
uintptr_t _dtb_early_pa __initdata ;
67
67
68
- static phys_addr_t dma32_phys_limit __initdata ;
68
+ phys_addr_t dma32_phys_limit __initdata ;
69
69
70
70
static void __init zone_sizes_init (void )
71
71
{
@@ -1333,151 +1333,32 @@ static inline void setup_vm_final(void)
1333
1333
}
1334
1334
#endif /* CONFIG_MMU */
1335
1335
1336
- /* Reserve 128M low memory by default for swiotlb buffer */
1337
- #define DEFAULT_CRASH_KERNEL_LOW_SIZE (128UL << 20)
1338
-
1339
- static int __init reserve_crashkernel_low (unsigned long long low_size )
1340
- {
1341
- unsigned long long low_base ;
1342
-
1343
- low_base = memblock_phys_alloc_range (low_size , PMD_SIZE , 0 , dma32_phys_limit );
1344
- if (!low_base ) {
1345
- pr_err ("cannot allocate crashkernel low memory (size:0x%llx).\n" , low_size );
1346
- return - ENOMEM ;
1347
- }
1348
-
1349
- pr_info ("crashkernel low memory reserved: 0x%016llx - 0x%016llx (%lld MB)\n" ,
1350
- low_base , low_base + low_size , low_size >> 20 );
1351
-
1352
- crashk_low_res .start = low_base ;
1353
- crashk_low_res .end = low_base + low_size - 1 ;
1354
-
1355
- return 0 ;
1356
- }
1357
-
1358
1336
/*
1359
1337
* reserve_crashkernel() - reserves memory for crash kernel
1360
1338
*
1361
1339
* This function reserves memory area given in "crashkernel=" kernel command
1362
1340
* line parameter. The memory reserved is used by dump capture kernel when
1363
1341
* primary kernel is crashing.
1364
1342
*/
1365
- static void __init reserve_crashkernel (void )
1343
+ static void __init arch_reserve_crashkernel (void )
1366
1344
{
1367
- unsigned long long crash_base = 0 ;
1368
- unsigned long long crash_size = 0 ;
1369
- unsigned long long crash_low_size = 0 ;
1370
- unsigned long search_start = memblock_start_of_DRAM ();
1371
- unsigned long search_end = (unsigned long )dma32_phys_limit ;
1345
+ unsigned long long low_size = 0 ;
1346
+ unsigned long long crash_base , crash_size ;
1372
1347
char * cmdline = boot_command_line ;
1373
- bool fixed_base = false;
1374
1348
bool high = false;
1375
-
1376
- int ret = 0 ;
1349
+ int ret ;
1377
1350
1378
1351
if (!IS_ENABLED (CONFIG_KEXEC_CORE ))
1379
1352
return ;
1380
- /*
1381
- * Don't reserve a region for a crash kernel on a crash kernel
1382
- * since it doesn't make much sense and we have limited memory
1383
- * resources.
1384
- */
1385
- if (is_kdump_kernel ()) {
1386
- pr_info ("crashkernel: ignoring reservation request\n" );
1387
- return ;
1388
- }
1389
1353
1390
1354
ret = parse_crashkernel (cmdline , memblock_phys_mem_size (),
1391
- & crash_size , & crash_base , NULL , NULL );
1392
- if (ret == - ENOENT ) {
1393
- /* Fallback to crashkernel=X,[high,low] */
1394
- ret = parse_crashkernel_high (cmdline , 0 , & crash_size , & crash_base );
1395
- if (ret || !crash_size )
1396
- return ;
1397
-
1398
- /*
1399
- * crashkernel=Y,low is valid only when crashkernel=X,high
1400
- * is passed.
1401
- */
1402
- ret = parse_crashkernel_low (cmdline , 0 , & crash_low_size , & crash_base );
1403
- if (ret == - ENOENT )
1404
- crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE ;
1405
- else if (ret )
1406
- return ;
1407
-
1408
- search_start = (unsigned long )dma32_phys_limit ;
1409
- search_end = memblock_end_of_DRAM ();
1410
- high = true;
1411
- } else if (ret || !crash_size ) {
1412
- /* Invalid argument value specified */
1355
+ & crash_size , & crash_base ,
1356
+ & low_size , & high );
1357
+ if (ret )
1413
1358
return ;
1414
- }
1415
-
1416
- crash_size = PAGE_ALIGN (crash_size );
1417
-
1418
- if (crash_base ) {
1419
- fixed_base = true;
1420
- search_start = crash_base ;
1421
- search_end = crash_base + crash_size ;
1422
- }
1423
-
1424
- /*
1425
- * Current riscv boot protocol requires 2MB alignment for
1426
- * RV64 and 4MB alignment for RV32 (hugepage size)
1427
- *
1428
- * Try to alloc from 32bit addressible physical memory so that
1429
- * swiotlb can work on the crash kernel.
1430
- */
1431
- crash_base = memblock_phys_alloc_range (crash_size , PMD_SIZE ,
1432
- search_start , search_end );
1433
- if (crash_base == 0 ) {
1434
- /*
1435
- * For crashkernel=size[KMG]@offset[KMG], print out failure
1436
- * message if can't reserve the specified region.
1437
- */
1438
- if (fixed_base ) {
1439
- pr_warn ("crashkernel: allocating failed with given size@offset\n" );
1440
- return ;
1441
- }
1442
-
1443
- if (high ) {
1444
- /*
1445
- * For crashkernel=size[KMG],high, if the first attempt was
1446
- * for high memory, fall back to low memory.
1447
- */
1448
- search_start = memblock_start_of_DRAM ();
1449
- search_end = (unsigned long )dma32_phys_limit ;
1450
- } else {
1451
- /*
1452
- * For crashkernel=size[KMG], if the first attempt was for
1453
- * low memory, fall back to high memory, the minimum required
1454
- * low memory will be reserved later.
1455
- */
1456
- search_start = (unsigned long )dma32_phys_limit ;
1457
- search_end = memblock_end_of_DRAM ();
1458
- crash_low_size = DEFAULT_CRASH_KERNEL_LOW_SIZE ;
1459
- }
1460
-
1461
- crash_base = memblock_phys_alloc_range (crash_size , PMD_SIZE ,
1462
- search_start , search_end );
1463
- if (crash_base == 0 ) {
1464
- pr_warn ("crashkernel: couldn't allocate %lldKB\n" ,
1465
- crash_size >> 10 );
1466
- return ;
1467
- }
1468
- }
1469
-
1470
- if ((crash_base >= dma32_phys_limit ) && crash_low_size &&
1471
- reserve_crashkernel_low (crash_low_size )) {
1472
- memblock_phys_free (crash_base , crash_size );
1473
- return ;
1474
- }
1475
-
1476
- pr_info ("crashkernel: reserved 0x%016llx - 0x%016llx (%lld MB)\n" ,
1477
- crash_base , crash_base + crash_size , crash_size >> 20 );
1478
1359
1479
- crashk_res . start = crash_base ;
1480
- crashk_res . end = crash_base + crash_size - 1 ;
1360
+ reserve_crashkernel_generic ( cmdline , crash_size , crash_base ,
1361
+ low_size , high ) ;
1481
1362
}
1482
1363
1483
1364
void __init paging_init (void )
@@ -1495,7 +1376,7 @@ void __init misc_mem_init(void)
1495
1376
arch_numa_init ();
1496
1377
sparse_init ();
1497
1378
zone_sizes_init ();
1498
- reserve_crashkernel ();
1379
+ arch_reserve_crashkernel ();
1499
1380
memblock_dump_all ();
1500
1381
}
1501
1382
0 commit comments