Subject: Re: should cngetc block?
To: None <>
From: Kin Cho <>
List: tech-kern
Date: 02/05/2002 19:55:41 writes:

> cnpollc() is there to enable or disable interrupts so the console
> device can enter and exit polled I/O mode, not to change the 
> behavior of cngetc().

I see.

> Changing that interface will require modifications to all drivers
> that support that console interface, not just the `com' driver.

I agree.

> If you want to change that interface so that cngetc() does not
> block, you need to put together a proposal explaining what you
> want to do, how you want to do it, and why it's needed.

My proposal is this:

* To provide a way to poll for keyboard input in the interface
  "struct consdev".  However, only the "com" driver will support

Changes overview:
* Overload cn_pollc in "struct consdev" to enable non-blocking
  cn_getc.  For example, cn_pollc(dev, 0xa000) makes cn_getc
  non-blocking, while cn_pollc(dev, 0xb000) makes cn_getc


In cons.h:
#define	CN_NONBLOCKING	0xa000
#define	CN_BLOCKING	0xb000

In com.c:
* add static global poll_com_common_getc flag of type int,
  initialized to 1
* comcnpollc checks "on" parameter, if equal to CN_NONBLOCKING,
  set poll_com_common_getc to 0, if equal to CN_BLOCKING, sets
  poll_com_common_getc to 1,
* in com_common_getc, change polling loop to this:

	 * block until a character becomes available if polling,
	 * else return if none available now
	while (!ISSET(stat = bus_space_read_1(iot, ioh, com_lsr), LSR_RXRDY))
		if (!poll_com_common_getc) {
			c = -1;
			goto L_quit;
	return (c);

End of proposal.