From 67c012b3fcc7aec0e22aeae4a38134930041f61b Mon Sep 17 00:00:00 2001 From: David van Moolenbroek Date: Mon, 5 Dec 2011 10:54:58 +0100 Subject: [PATCH] printer: perform probe on startup This stops the printer driver from hanging the entire system when /dev/lp is opened on systems that do not have a parallel port. With this change, the printer driver shuts down immediately after loading on such systems. --- drivers/printer/printer.c | 28 +++++++++++++++++++++++----- 1 file changed, 23 insertions(+), 5 deletions(-) diff --git a/drivers/printer/printer.c b/drivers/printer/printer.c index bb1374885..331d04828 100644 --- a/drivers/printer/printer.c +++ b/drivers/printer/printer.c @@ -107,6 +107,7 @@ FORWARD _PROTOTYPE( void output_done, (void) ); FORWARD _PROTOTYPE( void do_write, (message *m_ptr) ); FORWARD _PROTOTYPE( void do_status, (message *m_ptr) ); FORWARD _PROTOTYPE( void prepare_output, (void) ); +FORWARD _PROTOTYPE( int do_probe, (void) ); FORWARD _PROTOTYPE( void do_initialize, (void) ); FORWARD _PROTOTYPE( void reply, (int code,int replyee,int proc,int status)); FORWARD _PROTOTYPE( void do_printer_output, (void) ); @@ -193,6 +194,11 @@ PRIVATE void sef_local_startup() PRIVATE int sef_cb_init_fresh(int UNUSED(type), sef_init_info_t *UNUSED(info)) { /* Initialize the printer driver. */ + + /* If no printer is present, do not start. */ + if (!do_probe()) + return ENODEV; /* arbitrary error code */ + /* Announce we are up! */ chardriver_announce(); @@ -352,6 +358,23 @@ int status; /* number of chars printed or error code */ send(replyee, &pr_mess); /* send the message */ } +/*===========================================================================* + * do_probe * + *===========================================================================*/ +PRIVATE int do_probe(void) +{ +/* See if there is a printer at all. */ + + /* Get the base port for first printer. */ + if(sys_vircopy(SELF, BIOS_SEG, LPT1_IO_PORT_ADDR, + SELF, D, (vir_bytes) &port_base, LPT1_IO_PORT_SIZE) != OK) { + panic("do_initialize: sys_vircopy failed"); + } + + /* If the port is zero, the parallel port is not available at all. */ + return (port_base != 0); +} + /*===========================================================================* * do_initialize * *===========================================================================*/ @@ -362,11 +385,6 @@ PRIVATE void do_initialize() if (initialized) return; initialized = TRUE; - /* Get the base port for first printer. */ - if(sys_vircopy(SELF, BIOS_SEG, LPT1_IO_PORT_ADDR, - SELF, D, (vir_bytes) &port_base, LPT1_IO_PORT_SIZE) != OK) { - panic("do_initialize: sys_vircopy failed"); - } if(sys_outb(port_base + 2, INIT_PRINTER) != OK) { printf("printer: sys_outb of %x failed\n", port_base+2); panic("do_initialize: sys_outb init failed"); -- 2.44.0