@@ -78,26 +78,38 @@ static struct cma *fadump_cma;
78
78
* But for some reason even if it fails we still have the memory reservation
79
79
* with us and we can still continue doing fadump.
80
80
*/
81
- static int __init fadump_cma_init (void )
81
+ void __init fadump_cma_init (void )
82
82
{
83
- unsigned long long base , size ;
83
+ unsigned long long base , size , end ;
84
84
int rc ;
85
85
86
- if (!fw_dump .fadump_enabled )
87
- return 0 ;
88
-
86
+ if (!fw_dump .fadump_supported || ! fw_dump . fadump_enabled ||
87
+ fw_dump . dump_active )
88
+ return ;
89
89
/*
90
90
* Do not use CMA if user has provided fadump=nocma kernel parameter.
91
- * Return 1 to continue with fadump old behaviour.
92
91
*/
93
- if (fw_dump .nocma )
94
- return 1 ;
92
+ if (fw_dump .nocma || ! fw_dump . boot_memory_size )
93
+ return ;
95
94
95
+ /*
96
+ * [base, end) should be reserved during early init in
97
+ * fadump_reserve_mem(). No need to check this here as
98
+ * cma_init_reserved_mem() already checks for overlap.
99
+ * Here we give the aligned chunk of this reserved memory to CMA.
100
+ */
96
101
base = fw_dump .reserve_dump_area_start ;
97
102
size = fw_dump .boot_memory_size ;
103
+ end = base + size ;
98
104
99
- if (!size )
100
- return 0 ;
105
+ base = ALIGN (base , CMA_MIN_ALIGNMENT_BYTES );
106
+ end = ALIGN_DOWN (end , CMA_MIN_ALIGNMENT_BYTES );
107
+ size = end - base ;
108
+
109
+ if (end <= base ) {
110
+ pr_warn ("%s: Too less memory to give to CMA\n" , __func__ );
111
+ return ;
112
+ }
101
113
102
114
rc = cma_init_reserved_mem (base , size , 0 , "fadump_cma" , & fadump_cma );
103
115
if (rc ) {
@@ -108,7 +120,7 @@ static int __init fadump_cma_init(void)
108
120
* blocked from production system usage. Hence return 1,
109
121
* so that we can continue with fadump.
110
122
*/
111
- return 1 ;
123
+ return ;
112
124
}
113
125
114
126
/*
@@ -120,15 +132,13 @@ static int __init fadump_cma_init(void)
120
132
/*
121
133
* So we now have successfully initialized cma area for fadump.
122
134
*/
123
- pr_info ("Initialized 0x%lx bytes cma area at %ldMB from 0x%lx "
135
+ pr_info ("Initialized [ 0x%llx, %luMB] cma area from [ 0x%lx, %luMB] "
124
136
"bytes of memory reserved for firmware-assisted dump\n" ,
125
- cma_get_size (fadump_cma ),
126
- ( unsigned long ) cma_get_base ( fadump_cma ) >> 20 ,
127
- fw_dump .reserve_dump_area_size );
128
- return 1 ;
137
+ cma_get_base ( fadump_cma ), cma_get_size (fadump_cma ) >> 20 ,
138
+ fw_dump . reserve_dump_area_start ,
139
+ fw_dump .boot_memory_size >> 20 );
140
+ return ;
129
141
}
130
- #else
131
- static int __init fadump_cma_init (void ) { return 1 ; }
132
142
#endif /* CONFIG_CMA */
133
143
134
144
/*
@@ -558,13 +568,6 @@ int __init fadump_reserve_mem(void)
558
568
if (!fw_dump .dump_active ) {
559
569
fw_dump .boot_memory_size =
560
570
PAGE_ALIGN (fadump_calculate_reserve_size ());
561
- #ifdef CONFIG_CMA
562
- if (!fw_dump .nocma ) {
563
- fw_dump .boot_memory_size =
564
- ALIGN (fw_dump .boot_memory_size ,
565
- CMA_MIN_ALIGNMENT_BYTES );
566
- }
567
- #endif
568
571
569
572
bootmem_min = fw_dump .ops -> fadump_get_bootmem_min ();
570
573
if (fw_dump .boot_memory_size < bootmem_min ) {
@@ -637,8 +640,6 @@ int __init fadump_reserve_mem(void)
637
640
638
641
pr_info ("Reserved %lldMB of memory at %#016llx (System RAM: %lldMB)\n" ,
639
642
(size >> 20 ), base , (memblock_phys_mem_size () >> 20 ));
640
-
641
- ret = fadump_cma_init ();
642
643
}
643
644
644
645
return ret ;
0 commit comments