@@ -78,26 +78,38 @@ static struct cma *fadump_cma;
7878 * But for some reason even if it fails we still have the memory reservation
7979 * with us and we can still continue doing fadump.
8080 */
81- static int __init fadump_cma_init (void )
81+ void __init fadump_cma_init (void )
8282{
83- unsigned long long base , size ;
83+ unsigned long long base , size , end ;
8484 int rc ;
8585
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 ;
8989 /*
9090 * Do not use CMA if user has provided fadump=nocma kernel parameter.
91- * Return 1 to continue with fadump old behaviour.
9291 */
93- if (fw_dump .nocma )
94- return 1 ;
92+ if (fw_dump .nocma || ! fw_dump . boot_memory_size )
93+ return ;
9594
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+ */
96101 base = fw_dump .reserve_dump_area_start ;
97102 size = fw_dump .boot_memory_size ;
103+ end = base + size ;
98104
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+ }
101113
102114 rc = cma_init_reserved_mem (base , size , 0 , "fadump_cma" , & fadump_cma );
103115 if (rc ) {
@@ -108,7 +120,7 @@ static int __init fadump_cma_init(void)
108120 * blocked from production system usage. Hence return 1,
109121 * so that we can continue with fadump.
110122 */
111- return 1 ;
123+ return ;
112124 }
113125
114126 /*
@@ -120,15 +132,13 @@ static int __init fadump_cma_init(void)
120132 /*
121133 * So we now have successfully initialized cma area for fadump.
122134 */
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] "
124136 "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 ;
129141}
130- #else
131- static int __init fadump_cma_init (void ) { return 1 ; }
132142#endif /* CONFIG_CMA */
133143
134144/*
@@ -558,13 +568,6 @@ int __init fadump_reserve_mem(void)
558568 if (!fw_dump .dump_active ) {
559569 fw_dump .boot_memory_size =
560570 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
568571
569572 bootmem_min = fw_dump .ops -> fadump_get_bootmem_min ();
570573 if (fw_dump .boot_memory_size < bootmem_min ) {
@@ -637,8 +640,6 @@ int __init fadump_reserve_mem(void)
637640
638641 pr_info ("Reserved %lldMB of memory at %#016llx (System RAM: %lldMB)\n" ,
639642 (size >> 20 ), base , (memblock_phys_mem_size () >> 20 ));
640-
641- ret = fadump_cma_init ();
642643 }
643644
644645 return ret ;
0 commit comments