2019-05-27 08:55:05 +02:00
// SPDX-License-Identifier: GPL-2.0-or-later
2005-04-16 15:20:36 -07:00
/*
2022-10-01 00:32:07 +02:00
* PDC early console support - use PDC firmware to dump text via boot console
2005-04-16 15:20:36 -07:00
*
2022-10-01 00:32:07 +02:00
* Copyright ( C ) 2001 - 2022 Helge Deller < deller @ gmx . de >
2005-04-16 15:20:36 -07:00
*/
# include <linux/console.h>
# include <linux/init.h>
2022-10-01 00:32:07 +02:00
# include <linux/serial_core.h>
# include <linux/kgdb.h>
parisc: move definition of PAGE0 to asm/page.h
This was defined in asm/pdc.h which needs to include asm/page.h for
__PAGE_OFFSET. This leads to an include loop so that page.h eventually will
include pdc.h again. While this is no problem because of header guards, it is
a problem because some symbols may be undefined. Such an error is this:
In file included from include/linux/bitops.h:35:0,
from include/asm-generic/getorder.h:7,
from arch/parisc/include/asm/page.h:162,
from arch/parisc/include/asm/pdc.h:346,
from arch/parisc/include/asm/processor.h:16,
from arch/parisc/include/asm/spinlock.h:6,
from arch/parisc/include/asm/atomic.h:20,
from include/linux/atomic.h:4,
from include/linux/sysfs.h:20,
from include/linux/kobject.h:21,
from include/linux/device.h:17,
from include/linux/eisa.h:5,
from arch/parisc/kernel/pci.c:11:
arch/parisc/include/asm/bitops.h: In function ‘set_bit’:
arch/parisc/include/asm/bitops.h:82:2: error: implicit declaration of function ‘_atomic_spin_lock_irqsave’ [-Werror=implicit-function-declaration]
arch/parisc/include/asm/bitops.h:84:2: error: implicit declaration of function ‘_atomic_spin_unlock_irqrestore’ [-Werror=implicit-function-declaration]
Signed-off-by: Rolf Eike Beer <eike-kernel@sf-tec.de>
Signed-off-by: Linus Torvalds <torvalds@linux-foundation.org>
2012-05-10 23:08:17 +02:00
# include <asm/page.h> /* for PAGE0 */
2005-04-16 15:20:36 -07:00
# include <asm/pdc.h> /* for iodc_call() proto and friends */
2008-12-25 19:33:11 +00:00
static DEFINE_SPINLOCK ( pdc_console_lock ) ;
2005-04-16 15:20:36 -07:00
static void pdc_console_write ( struct console * co , const char * s , unsigned count )
{
2008-02-18 23:34:34 -08:00
int i = 0 ;
unsigned long flags ;
spin_lock_irqsave ( & pdc_console_lock , flags ) ;
do {
i + = pdc_iodc_print ( s + i , count - i ) ;
} while ( i < count ) ;
spin_unlock_irqrestore ( & pdc_console_lock , flags ) ;
2005-04-16 15:20:36 -07:00
}
2022-10-01 00:32:07 +02:00
# ifdef CONFIG_KGDB
static int kgdb_pdc_read_char ( void )
2005-04-16 15:20:36 -07:00
{
2008-02-18 23:34:34 -08:00
int c ;
unsigned long flags ;
spin_lock_irqsave ( & pdc_console_lock , flags ) ;
c = pdc_iodc_getc ( ) ;
spin_unlock_irqrestore ( & pdc_console_lock , flags ) ;
2022-10-01 00:32:07 +02:00
return ( c < = 0 ) ? NO_POLL_CHAR : c ;
2010-06-14 19:24:41 +02:00
}
2022-10-01 00:32:07 +02:00
static void kgdb_pdc_write_char ( u8 chr )
2010-06-14 19:24:41 +02:00
{
2022-10-01 00:32:07 +02:00
if ( PAGE0 - > mem_cons . cl_class ! = CL_DUPLEX )
pdc_console_write ( NULL , & chr , 1 ) ;
2010-06-14 19:24:41 +02:00
}
2022-10-01 00:32:07 +02:00
static struct kgdb_io kgdb_pdc_io_ops = {
. name = " kgdb_pdc " ,
. read_char = kgdb_pdc_read_char ,
. write_char = kgdb_pdc_write_char ,
2010-06-14 19:24:41 +02:00
} ;
2005-04-16 15:20:36 -07:00
# endif
2022-10-01 00:32:07 +02:00
static int __init pdc_earlycon_setup ( struct earlycon_device * device ,
const char * opt )
2005-04-16 15:20:36 -07:00
{
2022-10-01 00:32:07 +02:00
struct console * earlycon_console ;
2005-04-16 15:20:36 -07:00
/* If the console is duplex then copy the COUT parameters to CIN. */
if ( PAGE0 - > mem_cons . cl_class = = CL_DUPLEX )
memcpy ( & PAGE0 - > mem_kbd , & PAGE0 - > mem_cons , sizeof ( PAGE0 - > mem_cons ) ) ;
2022-10-01 00:32:07 +02:00
earlycon_console = device - > con ;
earlycon_console - > write = pdc_console_write ;
device - > port . iotype = UPIO_MEM32BE ;
2005-04-16 15:20:36 -07:00
2022-10-01 00:32:07 +02:00
# ifdef CONFIG_KGDB
kgdb_register_io_module ( & kgdb_pdc_io_ops ) ;
2005-04-16 15:20:36 -07:00
# endif
2022-10-01 00:32:07 +02:00
return 0 ;
2005-04-16 15:20:36 -07:00
}
2022-10-01 00:32:07 +02:00
EARLYCON_DECLARE ( pdc , pdc_earlycon_setup ) ;