@@ -370,12 +370,8 @@ static int __opal_put_chars(uint32_t vtermno, const char *data, int total_len, b
370
370
olen = cpu_to_be64 (total_len );
371
371
rc = opal_console_write (vtermno , & olen , data );
372
372
if (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT ) {
373
- if (rc == OPAL_BUSY_EVENT ) {
374
- mdelay (OPAL_BUSY_DELAY_MS );
373
+ if (rc == OPAL_BUSY_EVENT )
375
374
opal_poll_events (NULL );
376
- } else if (rc == OPAL_BUSY_EVENT ) {
377
- mdelay (OPAL_BUSY_DELAY_MS );
378
- }
379
375
written = - EAGAIN ;
380
376
goto out ;
381
377
}
@@ -401,15 +397,6 @@ static int __opal_put_chars(uint32_t vtermno, const char *data, int total_len, b
401
397
if (atomic )
402
398
spin_unlock_irqrestore (& opal_write_lock , flags );
403
399
404
- /* In the -EAGAIN case, callers loop, so we have to flush the console
405
- * here in case they have interrupts off (and we don't want to wait
406
- * for async flushing if we can make immediate progress here). If
407
- * necessary the API could be made entirely non-flushing if the
408
- * callers had a ->flush API to use.
409
- */
410
- if (written == - EAGAIN )
411
- opal_flush_console (vtermno );
412
-
413
400
return written ;
414
401
}
415
402
@@ -429,40 +416,74 @@ int opal_put_chars_atomic(uint32_t vtermno, const char *data, int total_len)
429
416
return __opal_put_chars (vtermno , data , total_len , true);
430
417
}
431
418
432
- int opal_flush_console (uint32_t vtermno )
419
+ static s64 __opal_flush_console (uint32_t vtermno )
433
420
{
434
421
s64 rc ;
435
422
436
423
if (!opal_check_token (OPAL_CONSOLE_FLUSH )) {
437
424
__be64 evt ;
438
425
439
- WARN_ONCE (1 , "opal: OPAL_CONSOLE_FLUSH missing.\n" );
440
426
/*
441
427
* If OPAL_CONSOLE_FLUSH is not implemented in the firmware,
442
428
* the console can still be flushed by calling the polling
443
429
* function while it has OPAL_EVENT_CONSOLE_OUTPUT events.
444
430
*/
445
- do {
446
- opal_poll_events (& evt );
447
- } while (be64_to_cpu (evt ) & OPAL_EVENT_CONSOLE_OUTPUT );
431
+ WARN_ONCE (1 , "opal: OPAL_CONSOLE_FLUSH missing.\n" );
432
+
433
+ opal_poll_events (& evt );
434
+ if (!(be64_to_cpu (evt ) & OPAL_EVENT_CONSOLE_OUTPUT ))
435
+ return OPAL_SUCCESS ;
436
+ return OPAL_BUSY ;
448
437
449
- return OPAL_SUCCESS ;
438
+ } else {
439
+ rc = opal_console_flush (vtermno );
440
+ if (rc == OPAL_BUSY_EVENT ) {
441
+ opal_poll_events (NULL );
442
+ rc = OPAL_BUSY ;
443
+ }
444
+ return rc ;
450
445
}
451
446
452
- do {
453
- rc = OPAL_BUSY ;
454
- while (rc == OPAL_BUSY || rc == OPAL_BUSY_EVENT ) {
455
- rc = opal_console_flush (vtermno );
456
- if (rc == OPAL_BUSY_EVENT ) {
457
- mdelay (OPAL_BUSY_DELAY_MS );
458
- opal_poll_events (NULL );
459
- } else if (rc == OPAL_BUSY ) {
460
- mdelay (OPAL_BUSY_DELAY_MS );
447
+ }
448
+
449
+ /*
450
+ * opal_flush_console spins until the console is flushed
451
+ */
452
+ int opal_flush_console (uint32_t vtermno )
453
+ {
454
+ for (;;) {
455
+ s64 rc = __opal_flush_console (vtermno );
456
+
457
+ if (rc == OPAL_BUSY || rc == OPAL_PARTIAL ) {
458
+ mdelay (1 );
459
+ continue ;
460
+ }
461
+
462
+ return opal_error_code (rc );
463
+ }
464
+ }
465
+
466
+ /*
467
+ * opal_flush_chars is an hvc interface that sleeps until the console is
468
+ * flushed if wait, otherwise it will return -EBUSY if the console has data,
469
+ * -EAGAIN if it has data and some of it was flushed.
470
+ */
471
+ int opal_flush_chars (uint32_t vtermno , bool wait )
472
+ {
473
+ for (;;) {
474
+ s64 rc = __opal_flush_console (vtermno );
475
+
476
+ if (rc == OPAL_BUSY || rc == OPAL_PARTIAL ) {
477
+ if (wait ) {
478
+ msleep (OPAL_BUSY_DELAY_MS );
479
+ continue ;
461
480
}
481
+ if (rc == OPAL_PARTIAL )
482
+ return - EAGAIN ;
462
483
}
463
- } while (rc == OPAL_PARTIAL ); /* More to flush */
464
484
465
- return opal_error_code (rc );
485
+ return opal_error_code (rc );
486
+ }
466
487
}
467
488
468
489
static int opal_recover_mce (struct pt_regs * regs ,
0 commit comments