@@ -711,24 +711,14 @@ static void serial8250_set_sleep(struct uart_8250_port *p, int sleep)
711
711
serial8250_rpm_put (p );
712
712
}
713
713
714
- /*
715
- * Only to be used directly by the callback helper serial8250_console_write(),
716
- * which may not require the port lock. Use serial8250_clear_IER() instead for
717
- * all other cases.
718
- */
719
- static void __serial8250_clear_IER (struct uart_8250_port * up )
714
+ static void serial8250_clear_IER (struct uart_8250_port * up )
720
715
{
721
716
if (up -> capabilities & UART_CAP_UUE )
722
717
serial_out (up , UART_IER , UART_IER_UUE );
723
718
else
724
719
serial_out (up , UART_IER , 0 );
725
720
}
726
721
727
- static inline void serial8250_clear_IER (struct uart_8250_port * up )
728
- {
729
- __serial8250_clear_IER (up );
730
- }
731
-
732
722
#ifdef CONFIG_SERIAL_8250_RSA
733
723
/*
734
724
* Attempts to turn on the RSA FIFO. Returns zero on failure.
@@ -1416,6 +1406,9 @@ void serial8250_em485_stop_tx(struct uart_8250_port *p, bool toggle_ier)
1416
1406
{
1417
1407
unsigned char mcr = serial8250_in_MCR (p );
1418
1408
1409
+ /* Port locked to synchronize UART_IER access against the console. */
1410
+ lockdep_assert_held_once (& p -> port .lock );
1411
+
1419
1412
if (p -> port .rs485 .flags & SER_RS485_RTS_AFTER_SEND )
1420
1413
mcr |= UART_MCR_RTS ;
1421
1414
else
@@ -1431,16 +1424,6 @@ void serial8250_em485_stop_tx(struct uart_8250_port *p, bool toggle_ier)
1431
1424
serial8250_clear_and_reinit_fifos (p );
1432
1425
1433
1426
if (toggle_ier ) {
1434
- /*
1435
- * Port locked to synchronize UART_IER access against
1436
- * the console. The lockdep_assert must be restricted
1437
- * to this condition because only here is it
1438
- * guaranteed that the port lock is held. The other
1439
- * hardware access in this function is synchronized
1440
- * by console ownership.
1441
- */
1442
- lockdep_assert_held_once (& p -> port .lock );
1443
-
1444
1427
p -> ier |= UART_IER_RLSI | UART_IER_RDI ;
1445
1428
serial_port_out (& p -> port , UART_IER , p -> ier );
1446
1429
}
@@ -3320,11 +3303,7 @@ EXPORT_SYMBOL_GPL(serial8250_set_defaults);
3320
3303
3321
3304
static void serial8250_console_putchar (struct uart_port * port , unsigned char ch )
3322
3305
{
3323
- struct uart_8250_port * up = up_to_u8250p (port );
3324
-
3325
3306
serial_port_out (port , UART_TX , ch );
3326
-
3327
- up -> console_line_ended = (ch == '\n' );
3328
3307
}
3329
3308
3330
3309
static void serial8250_console_wait_putchar (struct uart_port * port , unsigned char ch )
@@ -3361,22 +3340,11 @@ static void serial8250_console_restore(struct uart_8250_port *up)
3361
3340
serial8250_out_MCR (up , up -> mcr | UART_MCR_DTR | UART_MCR_RTS );
3362
3341
}
3363
3342
3364
- static void fifo_wait_for_lsr (struct uart_8250_port * up ,
3365
- struct nbcon_write_context * wctxt ,
3366
- unsigned int count )
3343
+ static void fifo_wait_for_lsr (struct uart_8250_port * up , unsigned int count )
3367
3344
{
3368
3345
unsigned int i ;
3369
3346
3370
3347
for (i = 0 ; i < count ; i ++ ) {
3371
- /*
3372
- * Pass the ownership as quickly as possible to a higher
3373
- * priority context. Otherwise, its attempt to take over
3374
- * the ownership might timeout. The new owner will wait
3375
- * for UART_LSR_THRE before reusing the fifo.
3376
- */
3377
- if (!nbcon_can_proceed (wctxt ))
3378
- return ;
3379
-
3380
3348
if (wait_for_lsr (up , UART_LSR_THRE ))
3381
3349
return ;
3382
3350
}
@@ -3389,38 +3357,27 @@ static void fifo_wait_for_lsr(struct uart_8250_port *up,
3389
3357
* to get empty.
3390
3358
*/
3391
3359
static void serial8250_console_fifo_write (struct uart_8250_port * up ,
3392
- struct nbcon_write_context * wctxt )
3360
+ const char * s , unsigned int count )
3393
3361
{
3362
+ const char * end = s + count ;
3394
3363
unsigned int fifosize = up -> tx_loadsz ;
3395
3364
struct uart_port * port = & up -> port ;
3396
- const char * s = wctxt -> outbuf ;
3397
- const char * end = s + wctxt -> len ;
3398
3365
unsigned int tx_count = 0 ;
3399
3366
bool cr_sent = false;
3400
3367
unsigned int i ;
3401
3368
3402
3369
while (s != end ) {
3403
3370
/* Allow timeout for each byte of a possibly full FIFO */
3404
- fifo_wait_for_lsr (up , wctxt , fifosize );
3371
+ fifo_wait_for_lsr (up , fifosize );
3405
3372
3406
- /*
3407
- * Fill the FIFO. If a handover or takeover occurs, writing
3408
- * must be aborted since wctxt->outbuf and wctxt->len are no
3409
- * longer valid.
3410
- */
3411
3373
for (i = 0 ; i < fifosize && s != end ; ++ i ) {
3412
- if (!nbcon_enter_unsafe (wctxt ))
3413
- return ;
3414
-
3415
3374
if (* s == '\n' && !cr_sent ) {
3416
3375
serial8250_console_putchar (port , '\r' );
3417
3376
cr_sent = true;
3418
3377
} else {
3419
3378
serial8250_console_putchar (port , * s ++ );
3420
3379
cr_sent = false;
3421
3380
}
3422
-
3423
- nbcon_exit_unsafe (wctxt );
3424
3381
}
3425
3382
tx_count = i ;
3426
3383
}
@@ -3429,57 +3386,39 @@ static void serial8250_console_fifo_write(struct uart_8250_port *up,
3429
3386
* Allow timeout for each byte written since the caller will only wait
3430
3387
* for UART_LSR_BOTH_EMPTY using the timeout of a single character
3431
3388
*/
3432
- fifo_wait_for_lsr (up , wctxt , tx_count );
3433
- }
3434
-
3435
- static void serial8250_console_byte_write (struct uart_8250_port * up ,
3436
- struct nbcon_write_context * wctxt )
3437
- {
3438
- struct uart_port * port = & up -> port ;
3439
- const char * s = wctxt -> outbuf ;
3440
- const char * end = s + wctxt -> len ;
3441
-
3442
- /*
3443
- * Write out the message. If a handover or takeover occurs, writing
3444
- * must be aborted since wctxt->outbuf and wctxt->len are no longer
3445
- * valid.
3446
- */
3447
- while (s != end ) {
3448
- if (!nbcon_enter_unsafe (wctxt ))
3449
- return ;
3450
-
3451
- uart_console_write (port , s ++ , 1 , serial8250_console_wait_putchar );
3452
-
3453
- nbcon_exit_unsafe (wctxt );
3454
- }
3389
+ fifo_wait_for_lsr (up , tx_count );
3455
3390
}
3456
3391
3457
3392
/*
3458
- * Print a string to the serial port trying not to disturb
3459
- * any possible real use of the port...
3393
+ * Print a string to the serial port trying not to disturb
3394
+ * any possible real use of the port...
3395
+ *
3396
+ * The console_lock must be held when we get here.
3460
3397
*
3461
- * Doing runtime PM is really a bad idea for the kernel console.
3462
- * Thus, assume it is called when device is powered up.
3398
+ * Doing runtime PM is really a bad idea for the kernel console.
3399
+ * Thus, we assume the function is called when device is powered up.
3463
3400
*/
3464
- void serial8250_console_write (struct uart_8250_port * up ,
3465
- struct nbcon_write_context * wctxt ,
3466
- bool is_atomic )
3401
+ void serial8250_console_write (struct uart_8250_port * up , const char * s ,
3402
+ unsigned int count )
3467
3403
{
3468
3404
struct uart_8250_em485 * em485 = up -> em485 ;
3469
3405
struct uart_port * port = & up -> port ;
3470
- unsigned int ier ;
3471
- bool use_fifo ;
3406
+ unsigned long flags ;
3407
+ unsigned int ier , use_fifo ;
3408
+ int locked = 1 ;
3472
3409
3473
- if (!nbcon_enter_unsafe (wctxt ))
3474
- return ;
3410
+ touch_nmi_watchdog ();
3411
+
3412
+ if (oops_in_progress )
3413
+ locked = uart_port_trylock_irqsave (port , & flags );
3414
+ else
3415
+ uart_port_lock_irqsave (port , & flags );
3475
3416
3476
3417
/*
3477
- * First, save the IER, then disable the interrupts. The special
3478
- * variant to clear the IER is used because console printing may
3479
- * occur without holding the port lock.
3418
+ * First save the IER then disable the interrupts
3480
3419
*/
3481
3420
ier = serial_port_in (port , UART_IER );
3482
- __serial8250_clear_IER (up );
3421
+ serial8250_clear_IER (up );
3483
3422
3484
3423
/* check scratch reg to see if port powered off during system sleep */
3485
3424
if (up -> canary && (up -> canary != serial_port_in (port , UART_SCR ))) {
@@ -3493,18 +3432,6 @@ void serial8250_console_write(struct uart_8250_port *up,
3493
3432
mdelay (port -> rs485 .delay_rts_before_send );
3494
3433
}
3495
3434
3496
- /* If ownership was lost, no writing is allowed */
3497
- if (!nbcon_can_proceed (wctxt ))
3498
- goto skip_write ;
3499
-
3500
- /*
3501
- * If console printer did not fully output the previous line, it must
3502
- * have been handed or taken over. Insert a newline in order to
3503
- * maintain clean output.
3504
- */
3505
- if (!up -> console_line_ended )
3506
- uart_console_write (port , "\n" , 1 , serial8250_console_wait_putchar );
3507
-
3508
3435
use_fifo = (up -> capabilities & UART_CAP_FIFO ) &&
3509
3436
/*
3510
3437
* BCM283x requires to check the fifo
@@ -3525,23 +3452,10 @@ void serial8250_console_write(struct uart_8250_port *up,
3525
3452
*/
3526
3453
!(up -> port .flags & UPF_CONS_FLOW );
3527
3454
3528
- nbcon_exit_unsafe (wctxt );
3529
-
3530
3455
if (likely (use_fifo ))
3531
- serial8250_console_fifo_write (up , wctxt );
3456
+ serial8250_console_fifo_write (up , s , count );
3532
3457
else
3533
- serial8250_console_byte_write (up , wctxt );
3534
- skip_write :
3535
- /*
3536
- * If ownership was lost, this context must reacquire ownership and
3537
- * re-enter the unsafe section in order to perform final actions
3538
- * (such as re-enabling interrupts).
3539
- */
3540
- if (!nbcon_can_proceed (wctxt )) {
3541
- do {
3542
- nbcon_reacquire_nobuf (wctxt );
3543
- } while (!nbcon_enter_unsafe (wctxt ));
3544
- }
3458
+ uart_console_write (port , s , count , serial8250_console_wait_putchar );
3545
3459
3546
3460
/*
3547
3461
* Finally, wait for transmitter to become empty
@@ -3564,18 +3478,11 @@ void serial8250_console_write(struct uart_8250_port *up,
3564
3478
* call it if we have saved something in the saved flags
3565
3479
* while processing with interrupts off.
3566
3480
*/
3567
- if (up -> msr_saved_flags ) {
3568
- /*
3569
- * For atomic, it must be deferred to irq_work because this
3570
- * may be a context that does not permit waking up tasks.
3571
- */
3572
- if (is_atomic )
3573
- irq_work_queue (& up -> modem_status_work );
3574
- else
3575
- serial8250_modem_status (up );
3576
- }
3481
+ if (up -> msr_saved_flags )
3482
+ serial8250_modem_status (up );
3577
3483
3578
- nbcon_exit_unsafe (wctxt );
3484
+ if (locked )
3485
+ uart_port_unlock_irqrestore (port , flags );
3579
3486
}
3580
3487
3581
3488
static unsigned int probe_baud (struct uart_port * port )
@@ -3593,24 +3500,8 @@ static unsigned int probe_baud(struct uart_port *port)
3593
3500
return (port -> uartclk / 16 ) / quot ;
3594
3501
}
3595
3502
3596
- /*
3597
- * irq_work handler to perform modem control. Only triggered via
3598
- * ->write_atomic() callback because it may be in a scheduler or
3599
- * NMI context, unable to wake tasks.
3600
- */
3601
- static void modem_status_handler (struct irq_work * iwp )
3602
- {
3603
- struct uart_8250_port * up = container_of (iwp , struct uart_8250_port , modem_status_work );
3604
- struct uart_port * port = & up -> port ;
3605
-
3606
- uart_port_lock (port );
3607
- serial8250_modem_status (up );
3608
- uart_port_unlock (port );
3609
- }
3610
-
3611
3503
int serial8250_console_setup (struct uart_port * port , char * options , bool probe )
3612
3504
{
3613
- struct uart_8250_port * up = up_to_u8250p (port );
3614
3505
int baud = 9600 ;
3615
3506
int bits = 8 ;
3616
3507
int parity = 'n' ;
@@ -3620,9 +3511,6 @@ int serial8250_console_setup(struct uart_port *port, char *options, bool probe)
3620
3511
if (!port -> iobase && !port -> membase )
3621
3512
return - ENODEV ;
3622
3513
3623
- up -> console_line_ended = true;
3624
- init_irq_work (& up -> modem_status_work , modem_status_handler );
3625
-
3626
3514
if (options )
3627
3515
uart_parse_options (options , & baud , & parity , & bits , & flow );
3628
3516
else if (probe )
0 commit comments