@@ -51,6 +51,10 @@ static ulong ramoops_ftrace_size = MIN_MEM_SIZE;
5151module_param_named (ftrace_size , ramoops_ftrace_size , ulong , 0400 );
5252MODULE_PARM_DESC (ftrace_size , "size of ftrace log" );
5353
54+ static ulong ramoops_pmsg_size = MIN_MEM_SIZE ;
55+ module_param_named (pmsg_size , ramoops_pmsg_size , ulong , 0400 );
56+ MODULE_PARM_DESC (pmsg_size , "size of user space message log" );
57+
5458static ulong mem_address ;
5559module_param (mem_address , ulong , 0400 );
5660MODULE_PARM_DESC (mem_address ,
@@ -82,12 +86,14 @@ struct ramoops_context {
8286 struct persistent_ram_zone * * przs ;
8387 struct persistent_ram_zone * cprz ;
8488 struct persistent_ram_zone * fprz ;
89+ struct persistent_ram_zone * mprz ;
8590 phys_addr_t phys_addr ;
8691 unsigned long size ;
8792 unsigned int memtype ;
8893 size_t record_size ;
8994 size_t console_size ;
9095 size_t ftrace_size ;
96+ size_t pmsg_size ;
9197 int dump_oops ;
9298 struct persistent_ram_ecc_info ecc_info ;
9399 unsigned int max_dump_cnt ;
@@ -96,6 +102,7 @@ struct ramoops_context {
96102 unsigned int dump_read_cnt ;
97103 unsigned int console_read_cnt ;
98104 unsigned int ftrace_read_cnt ;
105+ unsigned int pmsg_read_cnt ;
99106 struct pstore_info pstore ;
100107};
101108
@@ -109,6 +116,7 @@ static int ramoops_pstore_open(struct pstore_info *psi)
109116 cxt -> dump_read_cnt = 0 ;
110117 cxt -> console_read_cnt = 0 ;
111118 cxt -> ftrace_read_cnt = 0 ;
119+ cxt -> pmsg_read_cnt = 0 ;
112120 return 0 ;
113121}
114122
@@ -164,6 +172,12 @@ static int ramoops_read_kmsg_hdr(char *buffer, struct timespec *time,
164172 return header_length ;
165173}
166174
175+ static bool prz_ok (struct persistent_ram_zone * prz )
176+ {
177+ return !!prz && !!(persistent_ram_old_size (prz ) +
178+ persistent_ram_ecc_string (prz , NULL , 0 ));
179+ }
180+
167181static ssize_t ramoops_pstore_read (u64 * id , enum pstore_type_id * type ,
168182 int * count , struct timespec * time ,
169183 char * * buf , bool * compressed ,
@@ -178,13 +192,16 @@ static ssize_t ramoops_pstore_read(u64 *id, enum pstore_type_id *type,
178192 prz = ramoops_get_next_prz (cxt -> przs , & cxt -> dump_read_cnt ,
179193 cxt -> max_dump_cnt , id , type ,
180194 PSTORE_TYPE_DMESG , 1 );
181- if (!prz )
195+ if (!prz_ok ( prz ) )
182196 prz = ramoops_get_next_prz (& cxt -> cprz , & cxt -> console_read_cnt ,
183197 1 , id , type , PSTORE_TYPE_CONSOLE , 0 );
184- if (!prz )
198+ if (!prz_ok ( prz ) )
185199 prz = ramoops_get_next_prz (& cxt -> fprz , & cxt -> ftrace_read_cnt ,
186200 1 , id , type , PSTORE_TYPE_FTRACE , 0 );
187- if (!prz )
201+ if (!prz_ok (prz ))
202+ prz = ramoops_get_next_prz (& cxt -> mprz , & cxt -> pmsg_read_cnt ,
203+ 1 , id , type , PSTORE_TYPE_PMSG , 0 );
204+ if (!prz_ok (prz ))
188205 return 0 ;
189206
190207 if (!persistent_ram_old (prz ))
@@ -252,6 +269,11 @@ static int notrace ramoops_pstore_write_buf(enum pstore_type_id type,
252269 return - ENOMEM ;
253270 persistent_ram_write (cxt -> fprz , buf , size );
254271 return 0 ;
272+ } else if (type == PSTORE_TYPE_PMSG ) {
273+ if (!cxt -> mprz )
274+ return - ENOMEM ;
275+ persistent_ram_write (cxt -> mprz , buf , size );
276+ return 0 ;
255277 }
256278
257279 if (type != PSTORE_TYPE_DMESG )
@@ -309,6 +331,9 @@ static int ramoops_pstore_erase(enum pstore_type_id type, u64 id, int count,
309331 case PSTORE_TYPE_FTRACE :
310332 prz = cxt -> fprz ;
311333 break ;
334+ case PSTORE_TYPE_PMSG :
335+ prz = cxt -> mprz ;
336+ break ;
312337 default :
313338 return - EINVAL ;
314339 }
@@ -435,7 +460,7 @@ static int ramoops_probe(struct platform_device *pdev)
435460 goto fail_out ;
436461
437462 if (!pdata -> mem_size || (!pdata -> record_size && !pdata -> console_size &&
438- !pdata -> ftrace_size )) {
463+ !pdata -> ftrace_size && ! pdata -> pmsg_size )) {
439464 pr_err ("The memory size and the record/console size must be "
440465 "non-zero\n" );
441466 goto fail_out ;
@@ -447,19 +472,23 @@ static int ramoops_probe(struct platform_device *pdev)
447472 pdata -> console_size = rounddown_pow_of_two (pdata -> console_size );
448473 if (pdata -> ftrace_size && !is_power_of_2 (pdata -> ftrace_size ))
449474 pdata -> ftrace_size = rounddown_pow_of_two (pdata -> ftrace_size );
475+ if (pdata -> pmsg_size && !is_power_of_2 (pdata -> pmsg_size ))
476+ pdata -> pmsg_size = rounddown_pow_of_two (pdata -> pmsg_size );
450477
451478 cxt -> size = pdata -> mem_size ;
452479 cxt -> phys_addr = pdata -> mem_address ;
453480 cxt -> memtype = pdata -> mem_type ;
454481 cxt -> record_size = pdata -> record_size ;
455482 cxt -> console_size = pdata -> console_size ;
456483 cxt -> ftrace_size = pdata -> ftrace_size ;
484+ cxt -> pmsg_size = pdata -> pmsg_size ;
457485 cxt -> dump_oops = pdata -> dump_oops ;
458486 cxt -> ecc_info = pdata -> ecc_info ;
459487
460488 paddr = cxt -> phys_addr ;
461489
462- dump_mem_sz = cxt -> size - cxt -> console_size - cxt -> ftrace_size ;
490+ dump_mem_sz = cxt -> size - cxt -> console_size - cxt -> ftrace_size
491+ - cxt -> pmsg_size ;
463492 err = ramoops_init_przs (dev , cxt , & paddr , dump_mem_sz );
464493 if (err )
465494 goto fail_out ;
@@ -474,13 +503,9 @@ static int ramoops_probe(struct platform_device *pdev)
474503 if (err )
475504 goto fail_init_fprz ;
476505
477- if (!cxt -> przs && !cxt -> cprz && !cxt -> fprz ) {
478- pr_err ("memory size too small, minimum is %zu\n" ,
479- cxt -> console_size + cxt -> record_size +
480- cxt -> ftrace_size );
481- err = - EINVAL ;
482- goto fail_cnt ;
483- }
506+ err = ramoops_init_prz (dev , cxt , & cxt -> mprz , & paddr , cxt -> pmsg_size , 0 );
507+ if (err )
508+ goto fail_init_mprz ;
484509
485510 cxt -> pstore .data = cxt ;
486511 /*
@@ -525,7 +550,8 @@ static int ramoops_probe(struct platform_device *pdev)
525550 kfree (cxt -> pstore .buf );
526551fail_clear :
527552 cxt -> pstore .bufsize = 0 ;
528- fail_cnt :
553+ kfree (cxt -> mprz );
554+ fail_init_mprz :
529555 kfree (cxt -> fprz );
530556fail_init_fprz :
531557 kfree (cxt -> cprz );
@@ -583,6 +609,7 @@ static void ramoops_register_dummy(void)
583609 dummy_data -> record_size = record_size ;
584610 dummy_data -> console_size = ramoops_console_size ;
585611 dummy_data -> ftrace_size = ramoops_ftrace_size ;
612+ dummy_data -> pmsg_size = ramoops_pmsg_size ;
586613 dummy_data -> dump_oops = dump_oops ;
587614 /*
588615 * For backwards compatibility ramoops.ecc=1 means 16 bytes ECC
0 commit comments