History log of /openbsd-current/sys/dev/ic/com.c
Revision (<<< Hide revision tags) (Show revision tags >>>) Date Author Comments
# 1.179 13-May-2024 jsg

remove prototypes with no matching function
ok mpi@


Revision tags: OPENBSD_7_4_BASE OPENBSD_7_5_BASE
# 1.178 11-Sep-2023 mvs

Remove unnecessary <sys/selinfo.h> includes.

ok jsg


# 1.177 23-May-2023 denis

Force comport initialization for some class of device

Some com@acpi devices will fail the comprobe1() check which can lead to
hang or reboot of the machine.

Input from deraadt@ kettenis@
OK miod@


# 1.176 18-Apr-2023 jsg

Add another check to com probe

With this bentley@'s Steam Deck no longer attaches these:
com0 at isa0 port 0x3f8/8 irq 4: ns8250, no fifo
com1 at isa0 port 0x2f8/8 irq 3: ns8250, no fifo
com2 at isa0 port 0x3e8/8 irq 5: ns8250, no fifo

From Matthias Drochner in NetBSD rev 1.154
ok kettenis@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.175 11-Jan-2022 uaa

add Synopsys Degisnware UART (dw-apb-uart) support

To fix Allwinner H6's UART problem, need to add dw-apb-uart special code.
ok kettenis@


Revision tags: OPENBSD_7_0_BASE
# 1.174 06-May-2021 kettenis

Fix bogus return statement.

From miod@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.173 14-Aug-2020 jcs

Re-commit Exar XR17V35x serial port support previously backed out:

The Exar XR17V354 has 4 ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

To avoid probing for these ports in com_attach_subr which requires
access to registers that may be reserved on certain platforms, pass
the sc_uarttype from com_puc_attach since the port type is already
known based on the puc device vendor/id.

Input from kettenis, tested in snaps


Revision tags: OPENBSD_6_7_BASE
# 1.172 09-Mar-2020 yasuoka

Update the console device always when attaching the real device
driver. The information by the driver is supposed more reliable than
the information which was set up earlier.

ok patrick


# 1.171 05-Feb-2020 mpi

Detach timeouts and the softint handler before freeing memory.

As more and more teardown functions include barriers, or any kind of
context change, it is unsafe to continue to assume that such code paths
are atomic. So a good practise is to only free descriptor when we're
sure that no other context can access them.

Found while looking at visa@'s ttkqflush() replacement diff. The same
pattern is present in many USB drivers as found with Peter Stuge.

ok visa@


Revision tags: OPENBSD_6_6_BASE
# 1.170 19-Jul-2019 cheloha

ttysleep(): drop unused timeout parameter

All callers sleep indefinitely.

With help from visa@.

ok visa@, ratchov@, kn@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.169 14-May-2018 kettenis

Add support for register shift/io-width to the console code as well.

ok visa@, patrick@


# 1.168 02-May-2018 kettenis

Revert previous commit; the XR17V35X probe that was added accesses registers
that aren't guaranteed to be there and may even belong to a different device.
This triggers a fault on hppa machines like the C3000 for example.


# 1.167 15-Apr-2018 jcs

The Exar XR17V354 has 4 com ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

ok mlarkin deraadt


# 1.166 02-Apr-2018 kettenis

Add support for register shift/io-width. This allows us to support UARTs
that are mostly NS16550 compatible but use 32-bit instead of 8-bit registers
such as the Synopsys Designware UARTs found on many armv7, arm64 and amd64
SoCs.

tested by florian@, blum@
ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.165 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.164 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.163 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.162 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.161 04-Sep-2016 tedu

remove some more sparc remnants. ok deraadt


# 1.160 03-Sep-2016 jsg

de-zaurus com.c
"looks correct" deraadt@ guenther@ on an earlier rev


# 1.159 16-Aug-2016 kettenis

Only probe the UART type if sc_uarttype is set to COM_UART_UNKNOWN.
This allows glue drivers to set the type based on other information (such as
Oopen Firmware or device tree properties) without going through to risky
code paths.

ok deraadt@, visa@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.158 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.157 13-Apr-2014 deraadt

wrap a long line


Revision tags: OPENBSD_5_5_BASE
# 1.156 09-Dec-2013 deraadt

At resume, do not spin flushing characters in from the chip. There shouldn't
be any characters. If the chip is not actually there for some reason, we'd
be spinning so early in the resume sequence, we'd probably go mad trying to
find the reason..
ok kettenis
request: people with serial ports on their laptops, try to run a "cu" over
a suspend/resume cycle, and see if you see "input noise"


# 1.155 09-Dec-2013 deraadt

At suspend/resume time cope with timeouts, DTR on resume in a bus
bus-independent fashion.
ok kettenis


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.154 14-Feb-2013 kettenis

No need to treat amd64 specially; always return CN_HIGHPRI.

ok miod@


# 1.153 17-Oct-2012 deraadt

Narrow the spltty/splx pair in com_activate to only enclose the minimum
operation which requires it.


# 1.152 25-Aug-2012 kettenis

Better detection of the st16650 v1 (with the broken fifo). Gets rid of
false positives like the DUART on the MPC8347 as found on socppc.

ok deraadt@


# 1.151 25-Aug-2012 kettenis

Turns out the v445 isn't happy at all if we touch the registers that deal
with sleep mode. So skip the wakeup code as well if we are a serial console.
The port on the v445 almost certainly isn't a real st16650 and probably
doesn't implement sleep mode (perhaps someone cut the soft core down a bit
too much?). But it is indistinguishable from it, so we have to deal with it.

ok deraadt@


# 1.150 19-Aug-2012 kettenis

Skip putting a port in sleep mode when it is used as serial console. In that
case the kernel will still be using the port even after the last process closes
it. And on machines like the v445 the firmware won't be happy if the console
port is in sleep mode when the kernel reboots or halts.

ok miod@


Revision tags: OPENBSD_5_2_BASE
# 1.149 12-May-2012 kettenis

Remove unused variable.

ok mpi@, miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.148 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.147 22-May-2011 drahn

Fix a problem found where one SOC has a uart implementation that causes bus
errors if the fifo is read when the fifo is empty. Dont read an empty fifo.
ok deraaadt@ fgsch@


# 1.146 23-Mar-2011 fgsch

only read from the UART if there is something to read. fix beagle, otherwise
it will crash with 'External Non-Linefetch Abort (S)'.
similar diff provided by drahn@. tested by jasper@, deraadt@ ok.


Revision tags: OPENBSD_4_9_BASE
# 1.145 28-Aug-2010 miod

ansify function definitions, and constify a few arrays while there.
no functional change.


Revision tags: OPENBSD_4_8_BASE
# 1.144 07-Aug-2010 kettenis

Add resume support for serial consoles.

Tested by sthen@, ok deraadt@


# 1.143 06-Aug-2010 kettenis

Initial stab at making com@puc suspend and resume properly. Works fine
for using cu(1) between two OpenBSD machines. Probably doesn't work for
serial consoles but we don't support those on puc(4) anyway.

ok deraadt@


# 1.142 02-Jul-2010 nicm

Move common code for waking up writers on a tty into a function.

ok deraadt matthew millert


# 1.141 28-Jun-2010 deraadt

Allow tty drivers to request larger buffers at attach time using a
max-baud-rate hint. Adjust TTYHOG (the nearly full logic) to this new
situation. The larger buffers are required by the very high speed
KDDI devices in Japan (CF com, or USB ucom) so those are the only two
drivers which currently ask for a larger buffer size.
ok yasuoka miod


# 1.140 28-Jun-2010 ckuethe

Use a more moderate fifo trigger level (4) for moderately quick
(sub-38400) port speeds. Inspired by netbsd. ok fgsch krw deraadt miod


# 1.139 26-Jun-2010 guenther

Don't #include <sys/user.h> into files that don't need the stuff
it defines. In some cases, this means pulling in uvm.h or pcb.h
instead, but most of the inclusions were just noise. Tested on
alpha, amd64, armish, hppa, i386, macpcc, sgi, sparc64, and vax,
mostly by krw and naddy.
ok krw@


# 1.138 12-Apr-2010 tedu

Some of the line disciplines want to check for suser. Better to pass them
a process instead of using curproc. ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.137 09-Nov-2009 nicm

Every selwakeup() should have a matching KNOTE() (even if kqueue isn't
supported it doesn't do any harm), so put the KNOTE() in selwakeup() itself and
remove it from any occurences where both are used, except one for kqueue itself
and one in sys_pipe.c (where the selwakeup is under a PIPE_SEL flag).

Based on a diff from tedu.

ok deraadt


# 1.136 04-Nov-2009 kettenis

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@


# 1.135 01-Nov-2009 nicm

Call selwakeup()/KNOTE() even if the queue has emptied completely.

ok miod


# 1.134 31-Oct-2009 fgsch

Use suser when possible. Suggested by miod@.
miod@ deraadt@ ok.


# 1.133 31-Oct-2009 deraadt

Add missing KNOTE() calls after selwakeup(), until we decide if the KNOTE()
calls can go directly into selwakeup() safely
long discussion with nicm, murmers of consent from tedu and miod, noone
else seems to care of kqueue is busted as long as it makes their sockets
move data fast... pretty sad.


# 1.132 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.131 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.130 23-Nov-2008 deraadt

pccom can finally die; ok kettenis dlg drahn, tested by okan


# 1.129 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


Revision tags: OPENBSD_4_4_BASE
# 1.128 08-Jun-2008 kettenis

Make serial console on non-primary ports work to on i386.

tested by jbg@, "it is right" deraadt@


# 1.127 25-Apr-2008 dlg

the code that parses arguments from the boot loader on amd64 wasnt checking
what type of console was specified, so when a glass console was used it was
still configuring serial bits. this makes it so serial config only occurs
for serial console devices.

found by jolan@, thib@, and maybe sthen@
sorry guys


# 1.126 24-Apr-2008 jsing

MD_ISA_IOT is not defined anywhere so get rid of it.

Spotted by drahn@, ok dlg@


# 1.125 24-Apr-2008 jsing

Keep order of "#if defined..." consistent.

ok dlg@


# 1.124 24-Apr-2008 jsing

Clean up comments.


# 1.123 24-Apr-2008 jsing

Cleanup serial console handling and remove some of the MD code from com.c.
Specify the serial configuration from within the MD code, rather than
passing things via macros. This will allow other platforms to more readily
change the serial console configuration.

Committing this so it actually gets tested.

ok dlg@


# 1.122 09-Apr-2008 deraadt

Increase buffer size sent to the fifo, and clamp the size correctly.
Scrub the buffer afterwards, too


Revision tags: OPENBSD_4_3_BASE
# 1.121 23-Jan-2008 jsing

Cleanup cn_pri. Change constants to more meaningful names, rather than
the hp300 related ones currently in use. CN_NORMAL becomes CN_LOWPRI,
CN_INTERNAL becomes CN_MIDPRI and CN_REMOTE becomes CN_HIGHPRI.

ok miod@


# 1.120 12-Jan-2008 miod

Make comconsrate initialized to TTYDEF_SPEED at compile-time, for ports
which need to setup the chip before comcnattach() is invoked.


# 1.119 08-Jan-2008 dlg

the rsc-console on the v880 operates at 115200, not the 9600 we think we
have to force all console devices to. this change passes the right speed
to the com code, and continues to use it when the device is opened as the
console device.

figured out by kettenis@
ok kettenis@ miod@


# 1.118 22-Aug-2007 jasper

fix compilation with KDGB
from Nicholas Marriott

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.117 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.116 22-Jun-2007 jasper

ansify/de-register
no binary change


# 1.115 08-May-2007 deraadt

backout while the amd64 puc situation is rethought


# 1.114 08-May-2007 deraadt

move com_activate() to where it belongs


# 1.113 08-May-2007 deraadt

put more foo_detach() routines where they are used


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.112 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.111 27-Apr-2006 deraadt

2 lines of code in most drivers, to do the timestamping; ok miod kettenis


# 1.110 27-Mar-2006 deraadt

in detach, mark device with COM_SW_DEAD, so that close() will not go
tapping additional registes. allows it to work on macppc, where doing
such a tap after unplug is very bad. drahn helped fkr@bytemine.de
ok miod and drahn


Revision tags: OPENBSD_3_9_BASE
# 1.109 01-Jan-2006 miod

Let cons_init() and cons_init_bell() initialize the whole consdev structure,
thus removing the need for drivers to initialize cn_pri to CN_DEAD when
hardware probe fails.


# 1.108 21-Nov-2005 millert

Move contents of sys/select.h to sys/selinfo.h in preparation for a
userland-visible sys/select.h. Consistent with what Net and Free do.
OK deraadt@, tested with full ports build by naddy@.


# 1.107 11-Nov-2005 fgsch

fix kgdb compilation; input and ok miod@.


# 1.106 26-Sep-2005 miod

Share com probe code between com and pccom; allows us to get rid of awkward
code duplication in cardbus, pcmcia and puc attachments.

Joint effort with fgs@; blessed deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.105 18-Jul-2005 deraadt

fix sparc64 console; same diff as miod


# 1.104 18-Jul-2005 deraadt

COM_CONSOLE & DDB fix


# 1.103 17-Jul-2005 miod

Allow the console support code not to be compiled in; this will be
necessary for and only used on sparc, shortly.

Reluctantely ok deraadt@


# 1.102 11-Jul-2005 uwe

Enable IR receive mode only for infrared capable PXA2x0 UARTs. Normal
reception is blocked while the IR receiver or transmitter is enabled.

Also enable the PXA2x0 UART before clearing the FIFO (suggested by
drahn@ some time ago), and disable the UART in compwroff().

ok deraadt@


# 1.101 02-Jul-2005 uwe

xscale UART FIFOs are 32 bytes deep; found by deraadt@


# 1.100 27-May-2005 uwe

- Merge changes from pxacom back into the common com driver.

Changes to the common com driver (partly from NetBSD):
- Multiply before divide in comspeed() to avoid overflow (from NetBSD).
- Don't call getc() and send -1 if the output queue is empty.
- Take UART clock frequency as a parameter instead of using COM_FREQ.

ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.99 20-Oct-2004 pefo

Use bus_addr_t instead of int for port address/offset, ok mickey


Revision tags: OPENBSD_3_6_BASE
# 1.98 09-Aug-2004 pefo

remove old arc stuff and add sgi support.
ok mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.97 30-May-2004 deraadt

serial console hack from tom. who, after having been told a few times
to commit it, has not. what is going on guys?


# 1.96 03-May-2004 drahn

Remove OpenBSD/pegaos, this has been announced before but delayed until
the tree was stable. No point in code supporting a company which screws
its employees being in the OpenBSD tree.


Revision tags: OPENBSD_3_5_BASE
# 1.95 31-Oct-2003 drahn

Use isa iot for pegasos com console attachment, perhaps this could
be adopted MI?


# 1.94 03-Oct-2003 miod

Merge tty_attach() in ttymalloc() and tty_detach() in ttyfree(). The need for
separate tty registering is gone now that sparc has switched to wscons, and
this makes the code less error-prone.

Also, remove tests for ttymalloc() failure, since it uses M_WAITOK.

ok millert@ deraadt@, tested by various people as well besides me...


# 1.93 23-Sep-2003 millert

Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater
poll(2) functionality instead of emulating it via the select backend.
Adapted from NetBSD and including some changes from FreeBSD.
Tested by many, deraadt@ OK


Revision tags: OPENBSD_3_4_BASE
# 1.92 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.91 15-Jul-2003 jason

move prototype for com_raisedtr() to comvar.h (just like pccom).


# 1.90 03-Jun-2003 deraadt

terms 3 & 4 cleanup based on "terms" file


# 1.89 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.88 19-Dec-2002 mickey

comparam() does not need an spltty() for it, already called there.
time-bound loops in com_common_cnputc() and lower to spltty(),
which i guess is left from times when timeouts were processed at splhigh().
jason@ tested and ok, art@ ok


Revision tags: UBC_SYNC_B
# 1.87 17-Oct-2002 art

ifndef __HAVE_GENERIC_SOFT_INTERRUPTS leaved a label without a statement after it. Fix.


Revision tags: OPENBSD_3_2_BASE
# 1.86 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.85 11-Jun-2002 miod

com.c is not a block device, no bdev_decl() for it.


Revision tags: OPENBSD_3_1_BASE
# 1.84 09-Apr-2002 pefo

Don't enable interrupts until an open() is done. Until then the driver
is not handling them and may throw the kernel into a spurious interrupt
loop. ok art@


# 1.83 14-Mar-2002 millert

First round of __P removal in sys


# 1.82 14-Mar-2002 jason

compare pointers with NULL not 0


# 1.81 05-Feb-2002 mickey

restore CN_REMOTE priority, as it always was there.
anyway, only i386 uses that path and only if forced anyway.
also do not do comprobe1() on hppa since that hoses the port.


# 1.80 30-Jan-2002 nordin

Move SET/CLR/ISSET macros to param.h. fgsch@ and millert@ ok


# 1.79 25-Jan-2002 mickey

CONADDR is defined elsewhere for hppa


# 1.78 23-Jan-2002 ericj

oops, make the kgdb var's non-static


# 1.77 23-Jan-2002 ericj

allow this to compile with KGDB


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.76 05-Oct-2001 mickey

branches: 1.76.4;
restore some of that dead code needed for dev/cons functionality


# 1.75 02-Oct-2001 art

#ifdef FOO works much better when FOO isn't misspelled.


# 1.74 30-Sep-2001 art

Enable break interrupt earlier.


# 1.73 30-Sep-2001 art

Next round of cleanups.
- some KNF.
- disable interrupts earlier in attach.
- give it some more time in attach to finish earlier output.
- explicit bus_space_barrier in comcnputc.
- dead code.


# 1.72 30-Sep-2001 art

Remove dead code.


# 1.71 30-Sep-2001 art

Remove the COM_HAYESP code. It doesn't appear to have been ever used and
it's very intrusive and makes the code less readable.


# 1.70 30-Sep-2001 art

Move out the com at commulti attachment into an ownfile.
Same story as isapnp - not tested because i386 uses pccom.


# 1.69 30-Sep-2001 art

Move out com at isapnp attachment into an own file.
Not tested because the only system with isapnp is i386 and i386 uses pccom.


# 1.68 29-Sep-2001 art

Next step in making the com driver improvable.
Split out the com at isa attachment into its own file.


# 1.67 29-Sep-2001 art

- compoll is now scheduled once for every sc instead of just one timeout for
all ports and looping over them.
- support for generic soft interrupts.


# 1.66 27-Sep-2001 art

Simplify comstart a bit.


# 1.65 27-Sep-2001 millert

Enable #if 0'd code in comcnputc() so serial console works correctly;
art@openbsd.org


# 1.64 27-Sep-2001 art

Split out comattach that does isa and isapnp attachment and initialization,
into comattach that does the isa stuff and com_attach_subr that does the
init.


Revision tags: OPENBSD_2_9_BASE
# 1.63 17-Apr-2001 aaron

Implement cnbell(), an optional entrypoint that rings the console bell; from
NetBSD. deraadt@ ok


# 1.62 15-Mar-2001 art

Put back new timeouts. This time with correct timeout for compoll.


# 1.61 15-Mar-2001 deraadt

typo


# 1.60 15-Mar-2001 art

back out new timeouts until I find out why they break alpha.


# 1.59 15-Mar-2001 deraadt

support puc devices with higher speeds (not tested yet)


# 1.58 13-Mar-2001 mickey

new timeouts


# 1.57 24-Jan-2001 hugh

KGDB for i386 from NetBSD via niklas, with tweaks and accommodations.
Tested by various, vetted by mickey & theo.


# 1.56 08-Nov-2000 art

Add comcnattach that does the basic steps needed to attach
a com as a serial console. (idea from NetBSD).

If cn_tab->cn_dev == NODEV, try to find comopen in cdevsw and set cn_dev
to the right device.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE SMP_BASE
# 1.55 27-Jan-2000 mickey

branches: 1.55.2;
isa-avoidance


# 1.54 11-Jan-2000 mickey

a few ifdef accomodations for hppa, also a few knf spaces


Revision tags: kame_19991208
# 1.53 28-Nov-1999 downsj

Enable TI16750 UART support.


# 1.52 09-Nov-1999 rahnds

in the ifdef POWERPC section, do use ppc, not p4e, for the iohandle
for the console configuration.


# 1.51 26-Oct-1999 downsj

This file has my code in it, attach my copyright.


Revision tags: OPENBSD_2_6_BASE
# 1.50 08-Aug-1999 niklas

pasto from pccom.c


# 1.49 08-Aug-1999 niklas

revert function accidentally committed


# 1.48 08-Aug-1999 niklas

Detach support for com; NetBSD and me


# 1.47 26-Jul-1999 niklas

Move over the ISA PnP support from pccom.c to com.c


# 1.46 26-Jul-1999 niklas

fix my last commit where I committed more than intended


# 1.45 26-Jul-1999 niklas

Remove obsolete detach code that has been dead for very long


# 1.44 25-Jun-1999 rees

Don't turn off uart when closing cua device if tty is waiting.
Instead just drop dtr briefly.


Revision tags: OPENBSD_2_5_BASE
# 1.43 09-Feb-1999 rees

Fix cua device to not block on open.
Turn off chip (and dtr) on interrupted open.


# 1.42 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.41 20-Sep-1998 rahnds

Powerpc port uses com.c not just power4e.


# 1.40 18-Aug-1998 pefo

Remove clearing of interrupt after character output in cnputci(). Clearing
the int will make the tty stop if output is currently active.


# 1.39 07-Aug-1998 pefo

com.c needs to know about mem mapped ports in ppc systems.

ncr.c and if_de.c needs some hooks for systems with ncr and dec
ether chips on the motherboard that runs on odd clocks and doesn't
support a srom. srom is emulated in machine dependent code.

big endian support for ncr and dec ether finished. the 21040
have some more coding requirements if it is to run BE since
it does not have the descriptor endian swap configuration bit.


Revision tags: OPENBSD_2_3_BASE
# 1.38 23-Feb-1998 downsj

New probe routine and support for ST16650.

Compiles, but completely untested.


# 1.37 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


Revision tags: OPENBSD_2_2_BASE
# 1.36 03-Sep-1997 deraadt

fix cua/tty locking


# 1.35 07-Jul-1997 niklas

Removed an unused arg


Revision tags: OPENBSD_2_1_BASE
# 1.34 10-Apr-1997 pefo

Need to separate i/o and mem on mips


# 1.33 17-Mar-1997 pefo

Serial console trouble again...


# 1.32 12-Mar-1997 pefo

The stupid "use console before configured" scheeme strikes again :-)


# 1.31 06-Mar-1997 tholo

Initial implementation of support for calling hardpps() on carrier enable


# 1.30 10-Dec-1996 deraadt

the real changes by niklas... I did not merge correctly


# 1.29 10-Dec-1996 deraadt

clr TS_WOPEN if bailing on cua opens
As well, at this point I've also done fancy cvs repository mangling to
ensure that the com* files in sys/dev/ic maintain the history we had
before. (Yes, I cleaned up the 2.0 tags too..)


# 1.28 29-Nov-1996 niklas

Missing pieces of new bus.h that CVS lost behind my back


# 1.27 12-Nov-1996 niklas

s/bus.h/bus.old.h/ to make the transit to the bus_space bus.h an easy road
possibly taken in small steps


# 1.26 09-Nov-1996 tholo

Break shall be handled as data == 0 and FE bit set; from Theo


# 1.25 30-Oct-1996 niklas

cominit is used from the outside (the alpha port)


# 1.24 22-Oct-1996 downsj

patch com speed initialization


# 1.23 16-Oct-1996 deraadt

contextual usage


# 1.22 16-Oct-1996 deraadt

unused variables


# 1.21 29-Aug-1996 deraadt

sunos-like cua behaviour; inspired by budd@cs.bu.edu in his scn.c


# 1.20 02-Jul-1996 downsj

better FIFO enabling code; netbsd pr#2574, cliff@wport.com


# 1.19 24-Jun-1996 pefo

pica changes backed out. does not belong here


# 1.18 22-Jun-1996 pefo

Pica bus support added


# 1.17 10-Jun-1996 niklas

Some cleanup for -Wall -Wstrict-prototypes


# 1.16 10-Jun-1996 deraadt

tty_attach()


# 1.15 26-May-1996 deraadt

sync 0521


# 1.14 10-May-1996 deraadt

proto change


# 1.13 07-May-1996 deraadt

sync with 0504 -- prototypes and bus.h


# 1.12 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.11 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.10 18-Apr-1996 niklas

NetBSD 960317 merge


# 1.9 20-Mar-1996 mickey

Fix back wrong patches.


# 1.8 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.7 08-Mar-1996 niklas

From NetBSD: merge of 960217


# 1.6 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.5 16-Jan-1996 hvozda

Last of the glue and devices for for PCMCIA support from Stefan Grefen
<grefen@convex.com> with modifications by John Kohl <jtk@kolvir.blrc.ma.us>


# 1.4 03-Jan-1996 deraadt

Patches to use Hayes ESP with com.c; from banshee@gabriella.resort.com;
netbsd pr#1865. the ESP card code is always enabled -- we will have to
see if that fails on any chipsets.


# 1.3 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.


# 1.2 15-Dec-1995 deraadt

update from netbsd


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.178 11-Sep-2023 mvs

Remove unnecessary <sys/selinfo.h> includes.

ok jsg


# 1.177 23-May-2023 denis

Force comport initialization for some class of device

Some com@acpi devices will fail the comprobe1() check which can lead to
hang or reboot of the machine.

Input from deraadt@ kettenis@
OK miod@


# 1.176 18-Apr-2023 jsg

Add another check to com probe

With this bentley@'s Steam Deck no longer attaches these:
com0 at isa0 port 0x3f8/8 irq 4: ns8250, no fifo
com1 at isa0 port 0x2f8/8 irq 3: ns8250, no fifo
com2 at isa0 port 0x3e8/8 irq 5: ns8250, no fifo

From Matthias Drochner in NetBSD rev 1.154
ok kettenis@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.175 11-Jan-2022 uaa

add Synopsys Degisnware UART (dw-apb-uart) support

To fix Allwinner H6's UART problem, need to add dw-apb-uart special code.
ok kettenis@


Revision tags: OPENBSD_7_0_BASE
# 1.174 06-May-2021 kettenis

Fix bogus return statement.

From miod@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.173 14-Aug-2020 jcs

Re-commit Exar XR17V35x serial port support previously backed out:

The Exar XR17V354 has 4 ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

To avoid probing for these ports in com_attach_subr which requires
access to registers that may be reserved on certain platforms, pass
the sc_uarttype from com_puc_attach since the port type is already
known based on the puc device vendor/id.

Input from kettenis, tested in snaps


Revision tags: OPENBSD_6_7_BASE
# 1.172 09-Mar-2020 yasuoka

Update the console device always when attaching the real device
driver. The information by the driver is supposed more reliable than
the information which was set up earlier.

ok patrick


# 1.171 05-Feb-2020 mpi

Detach timeouts and the softint handler before freeing memory.

As more and more teardown functions include barriers, or any kind of
context change, it is unsafe to continue to assume that such code paths
are atomic. So a good practise is to only free descriptor when we're
sure that no other context can access them.

Found while looking at visa@'s ttkqflush() replacement diff. The same
pattern is present in many USB drivers as found with Peter Stuge.

ok visa@


Revision tags: OPENBSD_6_6_BASE
# 1.170 19-Jul-2019 cheloha

ttysleep(): drop unused timeout parameter

All callers sleep indefinitely.

With help from visa@.

ok visa@, ratchov@, kn@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.169 14-May-2018 kettenis

Add support for register shift/io-width to the console code as well.

ok visa@, patrick@


# 1.168 02-May-2018 kettenis

Revert previous commit; the XR17V35X probe that was added accesses registers
that aren't guaranteed to be there and may even belong to a different device.
This triggers a fault on hppa machines like the C3000 for example.


# 1.167 15-Apr-2018 jcs

The Exar XR17V354 has 4 com ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

ok mlarkin deraadt


# 1.166 02-Apr-2018 kettenis

Add support for register shift/io-width. This allows us to support UARTs
that are mostly NS16550 compatible but use 32-bit instead of 8-bit registers
such as the Synopsys Designware UARTs found on many armv7, arm64 and amd64
SoCs.

tested by florian@, blum@
ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.165 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.164 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.163 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.162 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.161 04-Sep-2016 tedu

remove some more sparc remnants. ok deraadt


# 1.160 03-Sep-2016 jsg

de-zaurus com.c
"looks correct" deraadt@ guenther@ on an earlier rev


# 1.159 16-Aug-2016 kettenis

Only probe the UART type if sc_uarttype is set to COM_UART_UNKNOWN.
This allows glue drivers to set the type based on other information (such as
Oopen Firmware or device tree properties) without going through to risky
code paths.

ok deraadt@, visa@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.158 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.157 13-Apr-2014 deraadt

wrap a long line


Revision tags: OPENBSD_5_5_BASE
# 1.156 09-Dec-2013 deraadt

At resume, do not spin flushing characters in from the chip. There shouldn't
be any characters. If the chip is not actually there for some reason, we'd
be spinning so early in the resume sequence, we'd probably go mad trying to
find the reason..
ok kettenis
request: people with serial ports on their laptops, try to run a "cu" over
a suspend/resume cycle, and see if you see "input noise"


# 1.155 09-Dec-2013 deraadt

At suspend/resume time cope with timeouts, DTR on resume in a bus
bus-independent fashion.
ok kettenis


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.154 14-Feb-2013 kettenis

No need to treat amd64 specially; always return CN_HIGHPRI.

ok miod@


# 1.153 17-Oct-2012 deraadt

Narrow the spltty/splx pair in com_activate to only enclose the minimum
operation which requires it.


# 1.152 25-Aug-2012 kettenis

Better detection of the st16650 v1 (with the broken fifo). Gets rid of
false positives like the DUART on the MPC8347 as found on socppc.

ok deraadt@


# 1.151 25-Aug-2012 kettenis

Turns out the v445 isn't happy at all if we touch the registers that deal
with sleep mode. So skip the wakeup code as well if we are a serial console.
The port on the v445 almost certainly isn't a real st16650 and probably
doesn't implement sleep mode (perhaps someone cut the soft core down a bit
too much?). But it is indistinguishable from it, so we have to deal with it.

ok deraadt@


# 1.150 19-Aug-2012 kettenis

Skip putting a port in sleep mode when it is used as serial console. In that
case the kernel will still be using the port even after the last process closes
it. And on machines like the v445 the firmware won't be happy if the console
port is in sleep mode when the kernel reboots or halts.

ok miod@


Revision tags: OPENBSD_5_2_BASE
# 1.149 12-May-2012 kettenis

Remove unused variable.

ok mpi@, miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.148 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.147 22-May-2011 drahn

Fix a problem found where one SOC has a uart implementation that causes bus
errors if the fifo is read when the fifo is empty. Dont read an empty fifo.
ok deraaadt@ fgsch@


# 1.146 23-Mar-2011 fgsch

only read from the UART if there is something to read. fix beagle, otherwise
it will crash with 'External Non-Linefetch Abort (S)'.
similar diff provided by drahn@. tested by jasper@, deraadt@ ok.


Revision tags: OPENBSD_4_9_BASE
# 1.145 28-Aug-2010 miod

ansify function definitions, and constify a few arrays while there.
no functional change.


Revision tags: OPENBSD_4_8_BASE
# 1.144 07-Aug-2010 kettenis

Add resume support for serial consoles.

Tested by sthen@, ok deraadt@


# 1.143 06-Aug-2010 kettenis

Initial stab at making com@puc suspend and resume properly. Works fine
for using cu(1) between two OpenBSD machines. Probably doesn't work for
serial consoles but we don't support those on puc(4) anyway.

ok deraadt@


# 1.142 02-Jul-2010 nicm

Move common code for waking up writers on a tty into a function.

ok deraadt matthew millert


# 1.141 28-Jun-2010 deraadt

Allow tty drivers to request larger buffers at attach time using a
max-baud-rate hint. Adjust TTYHOG (the nearly full logic) to this new
situation. The larger buffers are required by the very high speed
KDDI devices in Japan (CF com, or USB ucom) so those are the only two
drivers which currently ask for a larger buffer size.
ok yasuoka miod


# 1.140 28-Jun-2010 ckuethe

Use a more moderate fifo trigger level (4) for moderately quick
(sub-38400) port speeds. Inspired by netbsd. ok fgsch krw deraadt miod


# 1.139 26-Jun-2010 guenther

Don't #include <sys/user.h> into files that don't need the stuff
it defines. In some cases, this means pulling in uvm.h or pcb.h
instead, but most of the inclusions were just noise. Tested on
alpha, amd64, armish, hppa, i386, macpcc, sgi, sparc64, and vax,
mostly by krw and naddy.
ok krw@


# 1.138 12-Apr-2010 tedu

Some of the line disciplines want to check for suser. Better to pass them
a process instead of using curproc. ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.137 09-Nov-2009 nicm

Every selwakeup() should have a matching KNOTE() (even if kqueue isn't
supported it doesn't do any harm), so put the KNOTE() in selwakeup() itself and
remove it from any occurences where both are used, except one for kqueue itself
and one in sys_pipe.c (where the selwakeup is under a PIPE_SEL flag).

Based on a diff from tedu.

ok deraadt


# 1.136 04-Nov-2009 kettenis

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@


# 1.135 01-Nov-2009 nicm

Call selwakeup()/KNOTE() even if the queue has emptied completely.

ok miod


# 1.134 31-Oct-2009 fgsch

Use suser when possible. Suggested by miod@.
miod@ deraadt@ ok.


# 1.133 31-Oct-2009 deraadt

Add missing KNOTE() calls after selwakeup(), until we decide if the KNOTE()
calls can go directly into selwakeup() safely
long discussion with nicm, murmers of consent from tedu and miod, noone
else seems to care of kqueue is busted as long as it makes their sockets
move data fast... pretty sad.


# 1.132 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.131 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.130 23-Nov-2008 deraadt

pccom can finally die; ok kettenis dlg drahn, tested by okan


# 1.129 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


Revision tags: OPENBSD_4_4_BASE
# 1.128 08-Jun-2008 kettenis

Make serial console on non-primary ports work to on i386.

tested by jbg@, "it is right" deraadt@


# 1.127 25-Apr-2008 dlg

the code that parses arguments from the boot loader on amd64 wasnt checking
what type of console was specified, so when a glass console was used it was
still configuring serial bits. this makes it so serial config only occurs
for serial console devices.

found by jolan@, thib@, and maybe sthen@
sorry guys


# 1.126 24-Apr-2008 jsing

MD_ISA_IOT is not defined anywhere so get rid of it.

Spotted by drahn@, ok dlg@


# 1.125 24-Apr-2008 jsing

Keep order of "#if defined..." consistent.

ok dlg@


# 1.124 24-Apr-2008 jsing

Clean up comments.


# 1.123 24-Apr-2008 jsing

Cleanup serial console handling and remove some of the MD code from com.c.
Specify the serial configuration from within the MD code, rather than
passing things via macros. This will allow other platforms to more readily
change the serial console configuration.

Committing this so it actually gets tested.

ok dlg@


# 1.122 09-Apr-2008 deraadt

Increase buffer size sent to the fifo, and clamp the size correctly.
Scrub the buffer afterwards, too


Revision tags: OPENBSD_4_3_BASE
# 1.121 23-Jan-2008 jsing

Cleanup cn_pri. Change constants to more meaningful names, rather than
the hp300 related ones currently in use. CN_NORMAL becomes CN_LOWPRI,
CN_INTERNAL becomes CN_MIDPRI and CN_REMOTE becomes CN_HIGHPRI.

ok miod@


# 1.120 12-Jan-2008 miod

Make comconsrate initialized to TTYDEF_SPEED at compile-time, for ports
which need to setup the chip before comcnattach() is invoked.


# 1.119 08-Jan-2008 dlg

the rsc-console on the v880 operates at 115200, not the 9600 we think we
have to force all console devices to. this change passes the right speed
to the com code, and continues to use it when the device is opened as the
console device.

figured out by kettenis@
ok kettenis@ miod@


# 1.118 22-Aug-2007 jasper

fix compilation with KDGB
from Nicholas Marriott

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.117 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.116 22-Jun-2007 jasper

ansify/de-register
no binary change


# 1.115 08-May-2007 deraadt

backout while the amd64 puc situation is rethought


# 1.114 08-May-2007 deraadt

move com_activate() to where it belongs


# 1.113 08-May-2007 deraadt

put more foo_detach() routines where they are used


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.112 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.111 27-Apr-2006 deraadt

2 lines of code in most drivers, to do the timestamping; ok miod kettenis


# 1.110 27-Mar-2006 deraadt

in detach, mark device with COM_SW_DEAD, so that close() will not go
tapping additional registes. allows it to work on macppc, where doing
such a tap after unplug is very bad. drahn helped fkr@bytemine.de
ok miod and drahn


Revision tags: OPENBSD_3_9_BASE
# 1.109 01-Jan-2006 miod

Let cons_init() and cons_init_bell() initialize the whole consdev structure,
thus removing the need for drivers to initialize cn_pri to CN_DEAD when
hardware probe fails.


# 1.108 21-Nov-2005 millert

Move contents of sys/select.h to sys/selinfo.h in preparation for a
userland-visible sys/select.h. Consistent with what Net and Free do.
OK deraadt@, tested with full ports build by naddy@.


# 1.107 11-Nov-2005 fgsch

fix kgdb compilation; input and ok miod@.


# 1.106 26-Sep-2005 miod

Share com probe code between com and pccom; allows us to get rid of awkward
code duplication in cardbus, pcmcia and puc attachments.

Joint effort with fgs@; blessed deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.105 18-Jul-2005 deraadt

fix sparc64 console; same diff as miod


# 1.104 18-Jul-2005 deraadt

COM_CONSOLE & DDB fix


# 1.103 17-Jul-2005 miod

Allow the console support code not to be compiled in; this will be
necessary for and only used on sparc, shortly.

Reluctantely ok deraadt@


# 1.102 11-Jul-2005 uwe

Enable IR receive mode only for infrared capable PXA2x0 UARTs. Normal
reception is blocked while the IR receiver or transmitter is enabled.

Also enable the PXA2x0 UART before clearing the FIFO (suggested by
drahn@ some time ago), and disable the UART in compwroff().

ok deraadt@


# 1.101 02-Jul-2005 uwe

xscale UART FIFOs are 32 bytes deep; found by deraadt@


# 1.100 27-May-2005 uwe

- Merge changes from pxacom back into the common com driver.

Changes to the common com driver (partly from NetBSD):
- Multiply before divide in comspeed() to avoid overflow (from NetBSD).
- Don't call getc() and send -1 if the output queue is empty.
- Take UART clock frequency as a parameter instead of using COM_FREQ.

ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.99 20-Oct-2004 pefo

Use bus_addr_t instead of int for port address/offset, ok mickey


Revision tags: OPENBSD_3_6_BASE
# 1.98 09-Aug-2004 pefo

remove old arc stuff and add sgi support.
ok mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.97 30-May-2004 deraadt

serial console hack from tom. who, after having been told a few times
to commit it, has not. what is going on guys?


# 1.96 03-May-2004 drahn

Remove OpenBSD/pegaos, this has been announced before but delayed until
the tree was stable. No point in code supporting a company which screws
its employees being in the OpenBSD tree.


Revision tags: OPENBSD_3_5_BASE
# 1.95 31-Oct-2003 drahn

Use isa iot for pegasos com console attachment, perhaps this could
be adopted MI?


# 1.94 03-Oct-2003 miod

Merge tty_attach() in ttymalloc() and tty_detach() in ttyfree(). The need for
separate tty registering is gone now that sparc has switched to wscons, and
this makes the code less error-prone.

Also, remove tests for ttymalloc() failure, since it uses M_WAITOK.

ok millert@ deraadt@, tested by various people as well besides me...


# 1.93 23-Sep-2003 millert

Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater
poll(2) functionality instead of emulating it via the select backend.
Adapted from NetBSD and including some changes from FreeBSD.
Tested by many, deraadt@ OK


Revision tags: OPENBSD_3_4_BASE
# 1.92 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.91 15-Jul-2003 jason

move prototype for com_raisedtr() to comvar.h (just like pccom).


# 1.90 03-Jun-2003 deraadt

terms 3 & 4 cleanup based on "terms" file


# 1.89 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.88 19-Dec-2002 mickey

comparam() does not need an spltty() for it, already called there.
time-bound loops in com_common_cnputc() and lower to spltty(),
which i guess is left from times when timeouts were processed at splhigh().
jason@ tested and ok, art@ ok


Revision tags: UBC_SYNC_B
# 1.87 17-Oct-2002 art

ifndef __HAVE_GENERIC_SOFT_INTERRUPTS leaved a label without a statement after it. Fix.


Revision tags: OPENBSD_3_2_BASE
# 1.86 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.85 11-Jun-2002 miod

com.c is not a block device, no bdev_decl() for it.


Revision tags: OPENBSD_3_1_BASE
# 1.84 09-Apr-2002 pefo

Don't enable interrupts until an open() is done. Until then the driver
is not handling them and may throw the kernel into a spurious interrupt
loop. ok art@


# 1.83 14-Mar-2002 millert

First round of __P removal in sys


# 1.82 14-Mar-2002 jason

compare pointers with NULL not 0


# 1.81 05-Feb-2002 mickey

restore CN_REMOTE priority, as it always was there.
anyway, only i386 uses that path and only if forced anyway.
also do not do comprobe1() on hppa since that hoses the port.


# 1.80 30-Jan-2002 nordin

Move SET/CLR/ISSET macros to param.h. fgsch@ and millert@ ok


# 1.79 25-Jan-2002 mickey

CONADDR is defined elsewhere for hppa


# 1.78 23-Jan-2002 ericj

oops, make the kgdb var's non-static


# 1.77 23-Jan-2002 ericj

allow this to compile with KGDB


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.76 05-Oct-2001 mickey

branches: 1.76.4;
restore some of that dead code needed for dev/cons functionality


# 1.75 02-Oct-2001 art

#ifdef FOO works much better when FOO isn't misspelled.


# 1.74 30-Sep-2001 art

Enable break interrupt earlier.


# 1.73 30-Sep-2001 art

Next round of cleanups.
- some KNF.
- disable interrupts earlier in attach.
- give it some more time in attach to finish earlier output.
- explicit bus_space_barrier in comcnputc.
- dead code.


# 1.72 30-Sep-2001 art

Remove dead code.


# 1.71 30-Sep-2001 art

Remove the COM_HAYESP code. It doesn't appear to have been ever used and
it's very intrusive and makes the code less readable.


# 1.70 30-Sep-2001 art

Move out the com at commulti attachment into an ownfile.
Same story as isapnp - not tested because i386 uses pccom.


# 1.69 30-Sep-2001 art

Move out com at isapnp attachment into an own file.
Not tested because the only system with isapnp is i386 and i386 uses pccom.


# 1.68 29-Sep-2001 art

Next step in making the com driver improvable.
Split out the com at isa attachment into its own file.


# 1.67 29-Sep-2001 art

- compoll is now scheduled once for every sc instead of just one timeout for
all ports and looping over them.
- support for generic soft interrupts.


# 1.66 27-Sep-2001 art

Simplify comstart a bit.


# 1.65 27-Sep-2001 millert

Enable #if 0'd code in comcnputc() so serial console works correctly;
art@openbsd.org


# 1.64 27-Sep-2001 art

Split out comattach that does isa and isapnp attachment and initialization,
into comattach that does the isa stuff and com_attach_subr that does the
init.


Revision tags: OPENBSD_2_9_BASE
# 1.63 17-Apr-2001 aaron

Implement cnbell(), an optional entrypoint that rings the console bell; from
NetBSD. deraadt@ ok


# 1.62 15-Mar-2001 art

Put back new timeouts. This time with correct timeout for compoll.


# 1.61 15-Mar-2001 deraadt

typo


# 1.60 15-Mar-2001 art

back out new timeouts until I find out why they break alpha.


# 1.59 15-Mar-2001 deraadt

support puc devices with higher speeds (not tested yet)


# 1.58 13-Mar-2001 mickey

new timeouts


# 1.57 24-Jan-2001 hugh

KGDB for i386 from NetBSD via niklas, with tweaks and accommodations.
Tested by various, vetted by mickey & theo.


# 1.56 08-Nov-2000 art

Add comcnattach that does the basic steps needed to attach
a com as a serial console. (idea from NetBSD).

If cn_tab->cn_dev == NODEV, try to find comopen in cdevsw and set cn_dev
to the right device.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE SMP_BASE
# 1.55 27-Jan-2000 mickey

branches: 1.55.2;
isa-avoidance


# 1.54 11-Jan-2000 mickey

a few ifdef accomodations for hppa, also a few knf spaces


Revision tags: kame_19991208
# 1.53 28-Nov-1999 downsj

Enable TI16750 UART support.


# 1.52 09-Nov-1999 rahnds

in the ifdef POWERPC section, do use ppc, not p4e, for the iohandle
for the console configuration.


# 1.51 26-Oct-1999 downsj

This file has my code in it, attach my copyright.


Revision tags: OPENBSD_2_6_BASE
# 1.50 08-Aug-1999 niklas

pasto from pccom.c


# 1.49 08-Aug-1999 niklas

revert function accidentally committed


# 1.48 08-Aug-1999 niklas

Detach support for com; NetBSD and me


# 1.47 26-Jul-1999 niklas

Move over the ISA PnP support from pccom.c to com.c


# 1.46 26-Jul-1999 niklas

fix my last commit where I committed more than intended


# 1.45 26-Jul-1999 niklas

Remove obsolete detach code that has been dead for very long


# 1.44 25-Jun-1999 rees

Don't turn off uart when closing cua device if tty is waiting.
Instead just drop dtr briefly.


Revision tags: OPENBSD_2_5_BASE
# 1.43 09-Feb-1999 rees

Fix cua device to not block on open.
Turn off chip (and dtr) on interrupted open.


# 1.42 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.41 20-Sep-1998 rahnds

Powerpc port uses com.c not just power4e.


# 1.40 18-Aug-1998 pefo

Remove clearing of interrupt after character output in cnputci(). Clearing
the int will make the tty stop if output is currently active.


# 1.39 07-Aug-1998 pefo

com.c needs to know about mem mapped ports in ppc systems.

ncr.c and if_de.c needs some hooks for systems with ncr and dec
ether chips on the motherboard that runs on odd clocks and doesn't
support a srom. srom is emulated in machine dependent code.

big endian support for ncr and dec ether finished. the 21040
have some more coding requirements if it is to run BE since
it does not have the descriptor endian swap configuration bit.


Revision tags: OPENBSD_2_3_BASE
# 1.38 23-Feb-1998 downsj

New probe routine and support for ST16650.

Compiles, but completely untested.


# 1.37 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


Revision tags: OPENBSD_2_2_BASE
# 1.36 03-Sep-1997 deraadt

fix cua/tty locking


# 1.35 07-Jul-1997 niklas

Removed an unused arg


Revision tags: OPENBSD_2_1_BASE
# 1.34 10-Apr-1997 pefo

Need to separate i/o and mem on mips


# 1.33 17-Mar-1997 pefo

Serial console trouble again...


# 1.32 12-Mar-1997 pefo

The stupid "use console before configured" scheeme strikes again :-)


# 1.31 06-Mar-1997 tholo

Initial implementation of support for calling hardpps() on carrier enable


# 1.30 10-Dec-1996 deraadt

the real changes by niklas... I did not merge correctly


# 1.29 10-Dec-1996 deraadt

clr TS_WOPEN if bailing on cua opens
As well, at this point I've also done fancy cvs repository mangling to
ensure that the com* files in sys/dev/ic maintain the history we had
before. (Yes, I cleaned up the 2.0 tags too..)


# 1.28 29-Nov-1996 niklas

Missing pieces of new bus.h that CVS lost behind my back


# 1.27 12-Nov-1996 niklas

s/bus.h/bus.old.h/ to make the transit to the bus_space bus.h an easy road
possibly taken in small steps


# 1.26 09-Nov-1996 tholo

Break shall be handled as data == 0 and FE bit set; from Theo


# 1.25 30-Oct-1996 niklas

cominit is used from the outside (the alpha port)


# 1.24 22-Oct-1996 downsj

patch com speed initialization


# 1.23 16-Oct-1996 deraadt

contextual usage


# 1.22 16-Oct-1996 deraadt

unused variables


# 1.21 29-Aug-1996 deraadt

sunos-like cua behaviour; inspired by budd@cs.bu.edu in his scn.c


# 1.20 02-Jul-1996 downsj

better FIFO enabling code; netbsd pr#2574, cliff@wport.com


# 1.19 24-Jun-1996 pefo

pica changes backed out. does not belong here


# 1.18 22-Jun-1996 pefo

Pica bus support added


# 1.17 10-Jun-1996 niklas

Some cleanup for -Wall -Wstrict-prototypes


# 1.16 10-Jun-1996 deraadt

tty_attach()


# 1.15 26-May-1996 deraadt

sync 0521


# 1.14 10-May-1996 deraadt

proto change


# 1.13 07-May-1996 deraadt

sync with 0504 -- prototypes and bus.h


# 1.12 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.11 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.10 18-Apr-1996 niklas

NetBSD 960317 merge


# 1.9 20-Mar-1996 mickey

Fix back wrong patches.


# 1.8 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.7 08-Mar-1996 niklas

From NetBSD: merge of 960217


# 1.6 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.5 16-Jan-1996 hvozda

Last of the glue and devices for for PCMCIA support from Stefan Grefen
<grefen@convex.com> with modifications by John Kohl <jtk@kolvir.blrc.ma.us>


# 1.4 03-Jan-1996 deraadt

Patches to use Hayes ESP with com.c; from banshee@gabriella.resort.com;
netbsd pr#1865. the ESP card code is always enabled -- we will have to
see if that fails on any chipsets.


# 1.3 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.


# 1.2 15-Dec-1995 deraadt

update from netbsd


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.177 23-May-2023 denis

Force comport initialization for some class of device

Some com@acpi devices will fail the comprobe1() check which can lead to
hang or reboot of the machine.

Input from deraadt@ kettenis@
OK miod@


# 1.176 18-Apr-2023 jsg

Add another check to com probe

With this bentley@'s Steam Deck no longer attaches these:
com0 at isa0 port 0x3f8/8 irq 4: ns8250, no fifo
com1 at isa0 port 0x2f8/8 irq 3: ns8250, no fifo
com2 at isa0 port 0x3e8/8 irq 5: ns8250, no fifo

From Matthias Drochner in NetBSD rev 1.154
ok kettenis@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.175 11-Jan-2022 uaa

add Synopsys Degisnware UART (dw-apb-uart) support

To fix Allwinner H6's UART problem, need to add dw-apb-uart special code.
ok kettenis@


Revision tags: OPENBSD_7_0_BASE
# 1.174 06-May-2021 kettenis

Fix bogus return statement.

From miod@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.173 14-Aug-2020 jcs

Re-commit Exar XR17V35x serial port support previously backed out:

The Exar XR17V354 has 4 ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

To avoid probing for these ports in com_attach_subr which requires
access to registers that may be reserved on certain platforms, pass
the sc_uarttype from com_puc_attach since the port type is already
known based on the puc device vendor/id.

Input from kettenis, tested in snaps


Revision tags: OPENBSD_6_7_BASE
# 1.172 09-Mar-2020 yasuoka

Update the console device always when attaching the real device
driver. The information by the driver is supposed more reliable than
the information which was set up earlier.

ok patrick


# 1.171 05-Feb-2020 mpi

Detach timeouts and the softint handler before freeing memory.

As more and more teardown functions include barriers, or any kind of
context change, it is unsafe to continue to assume that such code paths
are atomic. So a good practise is to only free descriptor when we're
sure that no other context can access them.

Found while looking at visa@'s ttkqflush() replacement diff. The same
pattern is present in many USB drivers as found with Peter Stuge.

ok visa@


Revision tags: OPENBSD_6_6_BASE
# 1.170 19-Jul-2019 cheloha

ttysleep(): drop unused timeout parameter

All callers sleep indefinitely.

With help from visa@.

ok visa@, ratchov@, kn@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.169 14-May-2018 kettenis

Add support for register shift/io-width to the console code as well.

ok visa@, patrick@


# 1.168 02-May-2018 kettenis

Revert previous commit; the XR17V35X probe that was added accesses registers
that aren't guaranteed to be there and may even belong to a different device.
This triggers a fault on hppa machines like the C3000 for example.


# 1.167 15-Apr-2018 jcs

The Exar XR17V354 has 4 com ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

ok mlarkin deraadt


# 1.166 02-Apr-2018 kettenis

Add support for register shift/io-width. This allows us to support UARTs
that are mostly NS16550 compatible but use 32-bit instead of 8-bit registers
such as the Synopsys Designware UARTs found on many armv7, arm64 and amd64
SoCs.

tested by florian@, blum@
ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.165 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.164 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.163 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.162 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.161 04-Sep-2016 tedu

remove some more sparc remnants. ok deraadt


# 1.160 03-Sep-2016 jsg

de-zaurus com.c
"looks correct" deraadt@ guenther@ on an earlier rev


# 1.159 16-Aug-2016 kettenis

Only probe the UART type if sc_uarttype is set to COM_UART_UNKNOWN.
This allows glue drivers to set the type based on other information (such as
Oopen Firmware or device tree properties) without going through to risky
code paths.

ok deraadt@, visa@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.158 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.157 13-Apr-2014 deraadt

wrap a long line


Revision tags: OPENBSD_5_5_BASE
# 1.156 09-Dec-2013 deraadt

At resume, do not spin flushing characters in from the chip. There shouldn't
be any characters. If the chip is not actually there for some reason, we'd
be spinning so early in the resume sequence, we'd probably go mad trying to
find the reason..
ok kettenis
request: people with serial ports on their laptops, try to run a "cu" over
a suspend/resume cycle, and see if you see "input noise"


# 1.155 09-Dec-2013 deraadt

At suspend/resume time cope with timeouts, DTR on resume in a bus
bus-independent fashion.
ok kettenis


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.154 14-Feb-2013 kettenis

No need to treat amd64 specially; always return CN_HIGHPRI.

ok miod@


# 1.153 17-Oct-2012 deraadt

Narrow the spltty/splx pair in com_activate to only enclose the minimum
operation which requires it.


# 1.152 25-Aug-2012 kettenis

Better detection of the st16650 v1 (with the broken fifo). Gets rid of
false positives like the DUART on the MPC8347 as found on socppc.

ok deraadt@


# 1.151 25-Aug-2012 kettenis

Turns out the v445 isn't happy at all if we touch the registers that deal
with sleep mode. So skip the wakeup code as well if we are a serial console.
The port on the v445 almost certainly isn't a real st16650 and probably
doesn't implement sleep mode (perhaps someone cut the soft core down a bit
too much?). But it is indistinguishable from it, so we have to deal with it.

ok deraadt@


# 1.150 19-Aug-2012 kettenis

Skip putting a port in sleep mode when it is used as serial console. In that
case the kernel will still be using the port even after the last process closes
it. And on machines like the v445 the firmware won't be happy if the console
port is in sleep mode when the kernel reboots or halts.

ok miod@


Revision tags: OPENBSD_5_2_BASE
# 1.149 12-May-2012 kettenis

Remove unused variable.

ok mpi@, miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.148 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.147 22-May-2011 drahn

Fix a problem found where one SOC has a uart implementation that causes bus
errors if the fifo is read when the fifo is empty. Dont read an empty fifo.
ok deraaadt@ fgsch@


# 1.146 23-Mar-2011 fgsch

only read from the UART if there is something to read. fix beagle, otherwise
it will crash with 'External Non-Linefetch Abort (S)'.
similar diff provided by drahn@. tested by jasper@, deraadt@ ok.


Revision tags: OPENBSD_4_9_BASE
# 1.145 28-Aug-2010 miod

ansify function definitions, and constify a few arrays while there.
no functional change.


Revision tags: OPENBSD_4_8_BASE
# 1.144 07-Aug-2010 kettenis

Add resume support for serial consoles.

Tested by sthen@, ok deraadt@


# 1.143 06-Aug-2010 kettenis

Initial stab at making com@puc suspend and resume properly. Works fine
for using cu(1) between two OpenBSD machines. Probably doesn't work for
serial consoles but we don't support those on puc(4) anyway.

ok deraadt@


# 1.142 02-Jul-2010 nicm

Move common code for waking up writers on a tty into a function.

ok deraadt matthew millert


# 1.141 28-Jun-2010 deraadt

Allow tty drivers to request larger buffers at attach time using a
max-baud-rate hint. Adjust TTYHOG (the nearly full logic) to this new
situation. The larger buffers are required by the very high speed
KDDI devices in Japan (CF com, or USB ucom) so those are the only two
drivers which currently ask for a larger buffer size.
ok yasuoka miod


# 1.140 28-Jun-2010 ckuethe

Use a more moderate fifo trigger level (4) for moderately quick
(sub-38400) port speeds. Inspired by netbsd. ok fgsch krw deraadt miod


# 1.139 26-Jun-2010 guenther

Don't #include <sys/user.h> into files that don't need the stuff
it defines. In some cases, this means pulling in uvm.h or pcb.h
instead, but most of the inclusions were just noise. Tested on
alpha, amd64, armish, hppa, i386, macpcc, sgi, sparc64, and vax,
mostly by krw and naddy.
ok krw@


# 1.138 12-Apr-2010 tedu

Some of the line disciplines want to check for suser. Better to pass them
a process instead of using curproc. ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.137 09-Nov-2009 nicm

Every selwakeup() should have a matching KNOTE() (even if kqueue isn't
supported it doesn't do any harm), so put the KNOTE() in selwakeup() itself and
remove it from any occurences where both are used, except one for kqueue itself
and one in sys_pipe.c (where the selwakeup is under a PIPE_SEL flag).

Based on a diff from tedu.

ok deraadt


# 1.136 04-Nov-2009 kettenis

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@


# 1.135 01-Nov-2009 nicm

Call selwakeup()/KNOTE() even if the queue has emptied completely.

ok miod


# 1.134 31-Oct-2009 fgsch

Use suser when possible. Suggested by miod@.
miod@ deraadt@ ok.


# 1.133 31-Oct-2009 deraadt

Add missing KNOTE() calls after selwakeup(), until we decide if the KNOTE()
calls can go directly into selwakeup() safely
long discussion with nicm, murmers of consent from tedu and miod, noone
else seems to care of kqueue is busted as long as it makes their sockets
move data fast... pretty sad.


# 1.132 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.131 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.130 23-Nov-2008 deraadt

pccom can finally die; ok kettenis dlg drahn, tested by okan


# 1.129 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


Revision tags: OPENBSD_4_4_BASE
# 1.128 08-Jun-2008 kettenis

Make serial console on non-primary ports work to on i386.

tested by jbg@, "it is right" deraadt@


# 1.127 25-Apr-2008 dlg

the code that parses arguments from the boot loader on amd64 wasnt checking
what type of console was specified, so when a glass console was used it was
still configuring serial bits. this makes it so serial config only occurs
for serial console devices.

found by jolan@, thib@, and maybe sthen@
sorry guys


# 1.126 24-Apr-2008 jsing

MD_ISA_IOT is not defined anywhere so get rid of it.

Spotted by drahn@, ok dlg@


# 1.125 24-Apr-2008 jsing

Keep order of "#if defined..." consistent.

ok dlg@


# 1.124 24-Apr-2008 jsing

Clean up comments.


# 1.123 24-Apr-2008 jsing

Cleanup serial console handling and remove some of the MD code from com.c.
Specify the serial configuration from within the MD code, rather than
passing things via macros. This will allow other platforms to more readily
change the serial console configuration.

Committing this so it actually gets tested.

ok dlg@


# 1.122 09-Apr-2008 deraadt

Increase buffer size sent to the fifo, and clamp the size correctly.
Scrub the buffer afterwards, too


Revision tags: OPENBSD_4_3_BASE
# 1.121 23-Jan-2008 jsing

Cleanup cn_pri. Change constants to more meaningful names, rather than
the hp300 related ones currently in use. CN_NORMAL becomes CN_LOWPRI,
CN_INTERNAL becomes CN_MIDPRI and CN_REMOTE becomes CN_HIGHPRI.

ok miod@


# 1.120 12-Jan-2008 miod

Make comconsrate initialized to TTYDEF_SPEED at compile-time, for ports
which need to setup the chip before comcnattach() is invoked.


# 1.119 08-Jan-2008 dlg

the rsc-console on the v880 operates at 115200, not the 9600 we think we
have to force all console devices to. this change passes the right speed
to the com code, and continues to use it when the device is opened as the
console device.

figured out by kettenis@
ok kettenis@ miod@


# 1.118 22-Aug-2007 jasper

fix compilation with KDGB
from Nicholas Marriott

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.117 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.116 22-Jun-2007 jasper

ansify/de-register
no binary change


# 1.115 08-May-2007 deraadt

backout while the amd64 puc situation is rethought


# 1.114 08-May-2007 deraadt

move com_activate() to where it belongs


# 1.113 08-May-2007 deraadt

put more foo_detach() routines where they are used


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.112 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.111 27-Apr-2006 deraadt

2 lines of code in most drivers, to do the timestamping; ok miod kettenis


# 1.110 27-Mar-2006 deraadt

in detach, mark device with COM_SW_DEAD, so that close() will not go
tapping additional registes. allows it to work on macppc, where doing
such a tap after unplug is very bad. drahn helped fkr@bytemine.de
ok miod and drahn


Revision tags: OPENBSD_3_9_BASE
# 1.109 01-Jan-2006 miod

Let cons_init() and cons_init_bell() initialize the whole consdev structure,
thus removing the need for drivers to initialize cn_pri to CN_DEAD when
hardware probe fails.


# 1.108 21-Nov-2005 millert

Move contents of sys/select.h to sys/selinfo.h in preparation for a
userland-visible sys/select.h. Consistent with what Net and Free do.
OK deraadt@, tested with full ports build by naddy@.


# 1.107 11-Nov-2005 fgsch

fix kgdb compilation; input and ok miod@.


# 1.106 26-Sep-2005 miod

Share com probe code between com and pccom; allows us to get rid of awkward
code duplication in cardbus, pcmcia and puc attachments.

Joint effort with fgs@; blessed deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.105 18-Jul-2005 deraadt

fix sparc64 console; same diff as miod


# 1.104 18-Jul-2005 deraadt

COM_CONSOLE & DDB fix


# 1.103 17-Jul-2005 miod

Allow the console support code not to be compiled in; this will be
necessary for and only used on sparc, shortly.

Reluctantely ok deraadt@


# 1.102 11-Jul-2005 uwe

Enable IR receive mode only for infrared capable PXA2x0 UARTs. Normal
reception is blocked while the IR receiver or transmitter is enabled.

Also enable the PXA2x0 UART before clearing the FIFO (suggested by
drahn@ some time ago), and disable the UART in compwroff().

ok deraadt@


# 1.101 02-Jul-2005 uwe

xscale UART FIFOs are 32 bytes deep; found by deraadt@


# 1.100 27-May-2005 uwe

- Merge changes from pxacom back into the common com driver.

Changes to the common com driver (partly from NetBSD):
- Multiply before divide in comspeed() to avoid overflow (from NetBSD).
- Don't call getc() and send -1 if the output queue is empty.
- Take UART clock frequency as a parameter instead of using COM_FREQ.

ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.99 20-Oct-2004 pefo

Use bus_addr_t instead of int for port address/offset, ok mickey


Revision tags: OPENBSD_3_6_BASE
# 1.98 09-Aug-2004 pefo

remove old arc stuff and add sgi support.
ok mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.97 30-May-2004 deraadt

serial console hack from tom. who, after having been told a few times
to commit it, has not. what is going on guys?


# 1.96 03-May-2004 drahn

Remove OpenBSD/pegaos, this has been announced before but delayed until
the tree was stable. No point in code supporting a company which screws
its employees being in the OpenBSD tree.


Revision tags: OPENBSD_3_5_BASE
# 1.95 31-Oct-2003 drahn

Use isa iot for pegasos com console attachment, perhaps this could
be adopted MI?


# 1.94 03-Oct-2003 miod

Merge tty_attach() in ttymalloc() and tty_detach() in ttyfree(). The need for
separate tty registering is gone now that sparc has switched to wscons, and
this makes the code less error-prone.

Also, remove tests for ttymalloc() failure, since it uses M_WAITOK.

ok millert@ deraadt@, tested by various people as well besides me...


# 1.93 23-Sep-2003 millert

Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater
poll(2) functionality instead of emulating it via the select backend.
Adapted from NetBSD and including some changes from FreeBSD.
Tested by many, deraadt@ OK


Revision tags: OPENBSD_3_4_BASE
# 1.92 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.91 15-Jul-2003 jason

move prototype for com_raisedtr() to comvar.h (just like pccom).


# 1.90 03-Jun-2003 deraadt

terms 3 & 4 cleanup based on "terms" file


# 1.89 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.88 19-Dec-2002 mickey

comparam() does not need an spltty() for it, already called there.
time-bound loops in com_common_cnputc() and lower to spltty(),
which i guess is left from times when timeouts were processed at splhigh().
jason@ tested and ok, art@ ok


Revision tags: UBC_SYNC_B
# 1.87 17-Oct-2002 art

ifndef __HAVE_GENERIC_SOFT_INTERRUPTS leaved a label without a statement after it. Fix.


Revision tags: OPENBSD_3_2_BASE
# 1.86 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.85 11-Jun-2002 miod

com.c is not a block device, no bdev_decl() for it.


Revision tags: OPENBSD_3_1_BASE
# 1.84 09-Apr-2002 pefo

Don't enable interrupts until an open() is done. Until then the driver
is not handling them and may throw the kernel into a spurious interrupt
loop. ok art@


# 1.83 14-Mar-2002 millert

First round of __P removal in sys


# 1.82 14-Mar-2002 jason

compare pointers with NULL not 0


# 1.81 05-Feb-2002 mickey

restore CN_REMOTE priority, as it always was there.
anyway, only i386 uses that path and only if forced anyway.
also do not do comprobe1() on hppa since that hoses the port.


# 1.80 30-Jan-2002 nordin

Move SET/CLR/ISSET macros to param.h. fgsch@ and millert@ ok


# 1.79 25-Jan-2002 mickey

CONADDR is defined elsewhere for hppa


# 1.78 23-Jan-2002 ericj

oops, make the kgdb var's non-static


# 1.77 23-Jan-2002 ericj

allow this to compile with KGDB


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.76 05-Oct-2001 mickey

branches: 1.76.4;
restore some of that dead code needed for dev/cons functionality


# 1.75 02-Oct-2001 art

#ifdef FOO works much better when FOO isn't misspelled.


# 1.74 30-Sep-2001 art

Enable break interrupt earlier.


# 1.73 30-Sep-2001 art

Next round of cleanups.
- some KNF.
- disable interrupts earlier in attach.
- give it some more time in attach to finish earlier output.
- explicit bus_space_barrier in comcnputc.
- dead code.


# 1.72 30-Sep-2001 art

Remove dead code.


# 1.71 30-Sep-2001 art

Remove the COM_HAYESP code. It doesn't appear to have been ever used and
it's very intrusive and makes the code less readable.


# 1.70 30-Sep-2001 art

Move out the com at commulti attachment into an ownfile.
Same story as isapnp - not tested because i386 uses pccom.


# 1.69 30-Sep-2001 art

Move out com at isapnp attachment into an own file.
Not tested because the only system with isapnp is i386 and i386 uses pccom.


# 1.68 29-Sep-2001 art

Next step in making the com driver improvable.
Split out the com at isa attachment into its own file.


# 1.67 29-Sep-2001 art

- compoll is now scheduled once for every sc instead of just one timeout for
all ports and looping over them.
- support for generic soft interrupts.


# 1.66 27-Sep-2001 art

Simplify comstart a bit.


# 1.65 27-Sep-2001 millert

Enable #if 0'd code in comcnputc() so serial console works correctly;
art@openbsd.org


# 1.64 27-Sep-2001 art

Split out comattach that does isa and isapnp attachment and initialization,
into comattach that does the isa stuff and com_attach_subr that does the
init.


Revision tags: OPENBSD_2_9_BASE
# 1.63 17-Apr-2001 aaron

Implement cnbell(), an optional entrypoint that rings the console bell; from
NetBSD. deraadt@ ok


# 1.62 15-Mar-2001 art

Put back new timeouts. This time with correct timeout for compoll.


# 1.61 15-Mar-2001 deraadt

typo


# 1.60 15-Mar-2001 art

back out new timeouts until I find out why they break alpha.


# 1.59 15-Mar-2001 deraadt

support puc devices with higher speeds (not tested yet)


# 1.58 13-Mar-2001 mickey

new timeouts


# 1.57 24-Jan-2001 hugh

KGDB for i386 from NetBSD via niklas, with tweaks and accommodations.
Tested by various, vetted by mickey & theo.


# 1.56 08-Nov-2000 art

Add comcnattach that does the basic steps needed to attach
a com as a serial console. (idea from NetBSD).

If cn_tab->cn_dev == NODEV, try to find comopen in cdevsw and set cn_dev
to the right device.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE SMP_BASE
# 1.55 27-Jan-2000 mickey

branches: 1.55.2;
isa-avoidance


# 1.54 11-Jan-2000 mickey

a few ifdef accomodations for hppa, also a few knf spaces


Revision tags: kame_19991208
# 1.53 28-Nov-1999 downsj

Enable TI16750 UART support.


# 1.52 09-Nov-1999 rahnds

in the ifdef POWERPC section, do use ppc, not p4e, for the iohandle
for the console configuration.


# 1.51 26-Oct-1999 downsj

This file has my code in it, attach my copyright.


Revision tags: OPENBSD_2_6_BASE
# 1.50 08-Aug-1999 niklas

pasto from pccom.c


# 1.49 08-Aug-1999 niklas

revert function accidentally committed


# 1.48 08-Aug-1999 niklas

Detach support for com; NetBSD and me


# 1.47 26-Jul-1999 niklas

Move over the ISA PnP support from pccom.c to com.c


# 1.46 26-Jul-1999 niklas

fix my last commit where I committed more than intended


# 1.45 26-Jul-1999 niklas

Remove obsolete detach code that has been dead for very long


# 1.44 25-Jun-1999 rees

Don't turn off uart when closing cua device if tty is waiting.
Instead just drop dtr briefly.


Revision tags: OPENBSD_2_5_BASE
# 1.43 09-Feb-1999 rees

Fix cua device to not block on open.
Turn off chip (and dtr) on interrupted open.


# 1.42 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.41 20-Sep-1998 rahnds

Powerpc port uses com.c not just power4e.


# 1.40 18-Aug-1998 pefo

Remove clearing of interrupt after character output in cnputci(). Clearing
the int will make the tty stop if output is currently active.


# 1.39 07-Aug-1998 pefo

com.c needs to know about mem mapped ports in ppc systems.

ncr.c and if_de.c needs some hooks for systems with ncr and dec
ether chips on the motherboard that runs on odd clocks and doesn't
support a srom. srom is emulated in machine dependent code.

big endian support for ncr and dec ether finished. the 21040
have some more coding requirements if it is to run BE since
it does not have the descriptor endian swap configuration bit.


Revision tags: OPENBSD_2_3_BASE
# 1.38 23-Feb-1998 downsj

New probe routine and support for ST16650.

Compiles, but completely untested.


# 1.37 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


Revision tags: OPENBSD_2_2_BASE
# 1.36 03-Sep-1997 deraadt

fix cua/tty locking


# 1.35 07-Jul-1997 niklas

Removed an unused arg


Revision tags: OPENBSD_2_1_BASE
# 1.34 10-Apr-1997 pefo

Need to separate i/o and mem on mips


# 1.33 17-Mar-1997 pefo

Serial console trouble again...


# 1.32 12-Mar-1997 pefo

The stupid "use console before configured" scheeme strikes again :-)


# 1.31 06-Mar-1997 tholo

Initial implementation of support for calling hardpps() on carrier enable


# 1.30 10-Dec-1996 deraadt

the real changes by niklas... I did not merge correctly


# 1.29 10-Dec-1996 deraadt

clr TS_WOPEN if bailing on cua opens
As well, at this point I've also done fancy cvs repository mangling to
ensure that the com* files in sys/dev/ic maintain the history we had
before. (Yes, I cleaned up the 2.0 tags too..)


# 1.28 29-Nov-1996 niklas

Missing pieces of new bus.h that CVS lost behind my back


# 1.27 12-Nov-1996 niklas

s/bus.h/bus.old.h/ to make the transit to the bus_space bus.h an easy road
possibly taken in small steps


# 1.26 09-Nov-1996 tholo

Break shall be handled as data == 0 and FE bit set; from Theo


# 1.25 30-Oct-1996 niklas

cominit is used from the outside (the alpha port)


# 1.24 22-Oct-1996 downsj

patch com speed initialization


# 1.23 16-Oct-1996 deraadt

contextual usage


# 1.22 16-Oct-1996 deraadt

unused variables


# 1.21 29-Aug-1996 deraadt

sunos-like cua behaviour; inspired by budd@cs.bu.edu in his scn.c


# 1.20 02-Jul-1996 downsj

better FIFO enabling code; netbsd pr#2574, cliff@wport.com


# 1.19 24-Jun-1996 pefo

pica changes backed out. does not belong here


# 1.18 22-Jun-1996 pefo

Pica bus support added


# 1.17 10-Jun-1996 niklas

Some cleanup for -Wall -Wstrict-prototypes


# 1.16 10-Jun-1996 deraadt

tty_attach()


# 1.15 26-May-1996 deraadt

sync 0521


# 1.14 10-May-1996 deraadt

proto change


# 1.13 07-May-1996 deraadt

sync with 0504 -- prototypes and bus.h


# 1.12 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.11 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.10 18-Apr-1996 niklas

NetBSD 960317 merge


# 1.9 20-Mar-1996 mickey

Fix back wrong patches.


# 1.8 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.7 08-Mar-1996 niklas

From NetBSD: merge of 960217


# 1.6 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.5 16-Jan-1996 hvozda

Last of the glue and devices for for PCMCIA support from Stefan Grefen
<grefen@convex.com> with modifications by John Kohl <jtk@kolvir.blrc.ma.us>


# 1.4 03-Jan-1996 deraadt

Patches to use Hayes ESP with com.c; from banshee@gabriella.resort.com;
netbsd pr#1865. the ESP card code is always enabled -- we will have to
see if that fails on any chipsets.


# 1.3 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.


# 1.2 15-Dec-1995 deraadt

update from netbsd


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.176 18-Apr-2023 jsg

Add another check to com probe

With this bentley@'s Steam Deck no longer attaches these:
com0 at isa0 port 0x3f8/8 irq 4: ns8250, no fifo
com1 at isa0 port 0x2f8/8 irq 3: ns8250, no fifo
com2 at isa0 port 0x3e8/8 irq 5: ns8250, no fifo

From Matthias Drochner in NetBSD rev 1.154
ok kettenis@


Revision tags: OPENBSD_7_1_BASE OPENBSD_7_2_BASE OPENBSD_7_3_BASE
# 1.175 11-Jan-2022 uaa

add Synopsys Degisnware UART (dw-apb-uart) support

To fix Allwinner H6's UART problem, need to add dw-apb-uart special code.
ok kettenis@


Revision tags: OPENBSD_7_0_BASE
# 1.174 06-May-2021 kettenis

Fix bogus return statement.

From miod@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.173 14-Aug-2020 jcs

Re-commit Exar XR17V35x serial port support previously backed out:

The Exar XR17V354 has 4 ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

To avoid probing for these ports in com_attach_subr which requires
access to registers that may be reserved on certain platforms, pass
the sc_uarttype from com_puc_attach since the port type is already
known based on the puc device vendor/id.

Input from kettenis, tested in snaps


Revision tags: OPENBSD_6_7_BASE
# 1.172 09-Mar-2020 yasuoka

Update the console device always when attaching the real device
driver. The information by the driver is supposed more reliable than
the information which was set up earlier.

ok patrick


# 1.171 05-Feb-2020 mpi

Detach timeouts and the softint handler before freeing memory.

As more and more teardown functions include barriers, or any kind of
context change, it is unsafe to continue to assume that such code paths
are atomic. So a good practise is to only free descriptor when we're
sure that no other context can access them.

Found while looking at visa@'s ttkqflush() replacement diff. The same
pattern is present in many USB drivers as found with Peter Stuge.

ok visa@


Revision tags: OPENBSD_6_6_BASE
# 1.170 19-Jul-2019 cheloha

ttysleep(): drop unused timeout parameter

All callers sleep indefinitely.

With help from visa@.

ok visa@, ratchov@, kn@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.169 14-May-2018 kettenis

Add support for register shift/io-width to the console code as well.

ok visa@, patrick@


# 1.168 02-May-2018 kettenis

Revert previous commit; the XR17V35X probe that was added accesses registers
that aren't guaranteed to be there and may even belong to a different device.
This triggers a fault on hppa machines like the C3000 for example.


# 1.167 15-Apr-2018 jcs

The Exar XR17V354 has 4 com ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

ok mlarkin deraadt


# 1.166 02-Apr-2018 kettenis

Add support for register shift/io-width. This allows us to support UARTs
that are mostly NS16550 compatible but use 32-bit instead of 8-bit registers
such as the Synopsys Designware UARTs found on many armv7, arm64 and amd64
SoCs.

tested by florian@, blum@
ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.165 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.164 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.163 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.162 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.161 04-Sep-2016 tedu

remove some more sparc remnants. ok deraadt


# 1.160 03-Sep-2016 jsg

de-zaurus com.c
"looks correct" deraadt@ guenther@ on an earlier rev


# 1.159 16-Aug-2016 kettenis

Only probe the UART type if sc_uarttype is set to COM_UART_UNKNOWN.
This allows glue drivers to set the type based on other information (such as
Oopen Firmware or device tree properties) without going through to risky
code paths.

ok deraadt@, visa@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.158 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.157 13-Apr-2014 deraadt

wrap a long line


Revision tags: OPENBSD_5_5_BASE
# 1.156 09-Dec-2013 deraadt

At resume, do not spin flushing characters in from the chip. There shouldn't
be any characters. If the chip is not actually there for some reason, we'd
be spinning so early in the resume sequence, we'd probably go mad trying to
find the reason..
ok kettenis
request: people with serial ports on their laptops, try to run a "cu" over
a suspend/resume cycle, and see if you see "input noise"


# 1.155 09-Dec-2013 deraadt

At suspend/resume time cope with timeouts, DTR on resume in a bus
bus-independent fashion.
ok kettenis


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.154 14-Feb-2013 kettenis

No need to treat amd64 specially; always return CN_HIGHPRI.

ok miod@


# 1.153 17-Oct-2012 deraadt

Narrow the spltty/splx pair in com_activate to only enclose the minimum
operation which requires it.


# 1.152 25-Aug-2012 kettenis

Better detection of the st16650 v1 (with the broken fifo). Gets rid of
false positives like the DUART on the MPC8347 as found on socppc.

ok deraadt@


# 1.151 25-Aug-2012 kettenis

Turns out the v445 isn't happy at all if we touch the registers that deal
with sleep mode. So skip the wakeup code as well if we are a serial console.
The port on the v445 almost certainly isn't a real st16650 and probably
doesn't implement sleep mode (perhaps someone cut the soft core down a bit
too much?). But it is indistinguishable from it, so we have to deal with it.

ok deraadt@


# 1.150 19-Aug-2012 kettenis

Skip putting a port in sleep mode when it is used as serial console. In that
case the kernel will still be using the port even after the last process closes
it. And on machines like the v445 the firmware won't be happy if the console
port is in sleep mode when the kernel reboots or halts.

ok miod@


Revision tags: OPENBSD_5_2_BASE
# 1.149 12-May-2012 kettenis

Remove unused variable.

ok mpi@, miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.148 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.147 22-May-2011 drahn

Fix a problem found where one SOC has a uart implementation that causes bus
errors if the fifo is read when the fifo is empty. Dont read an empty fifo.
ok deraaadt@ fgsch@


# 1.146 23-Mar-2011 fgsch

only read from the UART if there is something to read. fix beagle, otherwise
it will crash with 'External Non-Linefetch Abort (S)'.
similar diff provided by drahn@. tested by jasper@, deraadt@ ok.


Revision tags: OPENBSD_4_9_BASE
# 1.145 28-Aug-2010 miod

ansify function definitions, and constify a few arrays while there.
no functional change.


Revision tags: OPENBSD_4_8_BASE
# 1.144 07-Aug-2010 kettenis

Add resume support for serial consoles.

Tested by sthen@, ok deraadt@


# 1.143 06-Aug-2010 kettenis

Initial stab at making com@puc suspend and resume properly. Works fine
for using cu(1) between two OpenBSD machines. Probably doesn't work for
serial consoles but we don't support those on puc(4) anyway.

ok deraadt@


# 1.142 02-Jul-2010 nicm

Move common code for waking up writers on a tty into a function.

ok deraadt matthew millert


# 1.141 28-Jun-2010 deraadt

Allow tty drivers to request larger buffers at attach time using a
max-baud-rate hint. Adjust TTYHOG (the nearly full logic) to this new
situation. The larger buffers are required by the very high speed
KDDI devices in Japan (CF com, or USB ucom) so those are the only two
drivers which currently ask for a larger buffer size.
ok yasuoka miod


# 1.140 28-Jun-2010 ckuethe

Use a more moderate fifo trigger level (4) for moderately quick
(sub-38400) port speeds. Inspired by netbsd. ok fgsch krw deraadt miod


# 1.139 26-Jun-2010 guenther

Don't #include <sys/user.h> into files that don't need the stuff
it defines. In some cases, this means pulling in uvm.h or pcb.h
instead, but most of the inclusions were just noise. Tested on
alpha, amd64, armish, hppa, i386, macpcc, sgi, sparc64, and vax,
mostly by krw and naddy.
ok krw@


# 1.138 12-Apr-2010 tedu

Some of the line disciplines want to check for suser. Better to pass them
a process instead of using curproc. ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.137 09-Nov-2009 nicm

Every selwakeup() should have a matching KNOTE() (even if kqueue isn't
supported it doesn't do any harm), so put the KNOTE() in selwakeup() itself and
remove it from any occurences where both are used, except one for kqueue itself
and one in sys_pipe.c (where the selwakeup is under a PIPE_SEL flag).

Based on a diff from tedu.

ok deraadt


# 1.136 04-Nov-2009 kettenis

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@


# 1.135 01-Nov-2009 nicm

Call selwakeup()/KNOTE() even if the queue has emptied completely.

ok miod


# 1.134 31-Oct-2009 fgsch

Use suser when possible. Suggested by miod@.
miod@ deraadt@ ok.


# 1.133 31-Oct-2009 deraadt

Add missing KNOTE() calls after selwakeup(), until we decide if the KNOTE()
calls can go directly into selwakeup() safely
long discussion with nicm, murmers of consent from tedu and miod, noone
else seems to care of kqueue is busted as long as it makes their sockets
move data fast... pretty sad.


# 1.132 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.131 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.130 23-Nov-2008 deraadt

pccom can finally die; ok kettenis dlg drahn, tested by okan


# 1.129 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


Revision tags: OPENBSD_4_4_BASE
# 1.128 08-Jun-2008 kettenis

Make serial console on non-primary ports work to on i386.

tested by jbg@, "it is right" deraadt@


# 1.127 25-Apr-2008 dlg

the code that parses arguments from the boot loader on amd64 wasnt checking
what type of console was specified, so when a glass console was used it was
still configuring serial bits. this makes it so serial config only occurs
for serial console devices.

found by jolan@, thib@, and maybe sthen@
sorry guys


# 1.126 24-Apr-2008 jsing

MD_ISA_IOT is not defined anywhere so get rid of it.

Spotted by drahn@, ok dlg@


# 1.125 24-Apr-2008 jsing

Keep order of "#if defined..." consistent.

ok dlg@


# 1.124 24-Apr-2008 jsing

Clean up comments.


# 1.123 24-Apr-2008 jsing

Cleanup serial console handling and remove some of the MD code from com.c.
Specify the serial configuration from within the MD code, rather than
passing things via macros. This will allow other platforms to more readily
change the serial console configuration.

Committing this so it actually gets tested.

ok dlg@


# 1.122 09-Apr-2008 deraadt

Increase buffer size sent to the fifo, and clamp the size correctly.
Scrub the buffer afterwards, too


Revision tags: OPENBSD_4_3_BASE
# 1.121 23-Jan-2008 jsing

Cleanup cn_pri. Change constants to more meaningful names, rather than
the hp300 related ones currently in use. CN_NORMAL becomes CN_LOWPRI,
CN_INTERNAL becomes CN_MIDPRI and CN_REMOTE becomes CN_HIGHPRI.

ok miod@


# 1.120 12-Jan-2008 miod

Make comconsrate initialized to TTYDEF_SPEED at compile-time, for ports
which need to setup the chip before comcnattach() is invoked.


# 1.119 08-Jan-2008 dlg

the rsc-console on the v880 operates at 115200, not the 9600 we think we
have to force all console devices to. this change passes the right speed
to the com code, and continues to use it when the device is opened as the
console device.

figured out by kettenis@
ok kettenis@ miod@


# 1.118 22-Aug-2007 jasper

fix compilation with KDGB
from Nicholas Marriott

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.117 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.116 22-Jun-2007 jasper

ansify/de-register
no binary change


# 1.115 08-May-2007 deraadt

backout while the amd64 puc situation is rethought


# 1.114 08-May-2007 deraadt

move com_activate() to where it belongs


# 1.113 08-May-2007 deraadt

put more foo_detach() routines where they are used


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.112 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.111 27-Apr-2006 deraadt

2 lines of code in most drivers, to do the timestamping; ok miod kettenis


# 1.110 27-Mar-2006 deraadt

in detach, mark device with COM_SW_DEAD, so that close() will not go
tapping additional registes. allows it to work on macppc, where doing
such a tap after unplug is very bad. drahn helped fkr@bytemine.de
ok miod and drahn


Revision tags: OPENBSD_3_9_BASE
# 1.109 01-Jan-2006 miod

Let cons_init() and cons_init_bell() initialize the whole consdev structure,
thus removing the need for drivers to initialize cn_pri to CN_DEAD when
hardware probe fails.


# 1.108 21-Nov-2005 millert

Move contents of sys/select.h to sys/selinfo.h in preparation for a
userland-visible sys/select.h. Consistent with what Net and Free do.
OK deraadt@, tested with full ports build by naddy@.


# 1.107 11-Nov-2005 fgsch

fix kgdb compilation; input and ok miod@.


# 1.106 26-Sep-2005 miod

Share com probe code between com and pccom; allows us to get rid of awkward
code duplication in cardbus, pcmcia and puc attachments.

Joint effort with fgs@; blessed deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.105 18-Jul-2005 deraadt

fix sparc64 console; same diff as miod


# 1.104 18-Jul-2005 deraadt

COM_CONSOLE & DDB fix


# 1.103 17-Jul-2005 miod

Allow the console support code not to be compiled in; this will be
necessary for and only used on sparc, shortly.

Reluctantely ok deraadt@


# 1.102 11-Jul-2005 uwe

Enable IR receive mode only for infrared capable PXA2x0 UARTs. Normal
reception is blocked while the IR receiver or transmitter is enabled.

Also enable the PXA2x0 UART before clearing the FIFO (suggested by
drahn@ some time ago), and disable the UART in compwroff().

ok deraadt@


# 1.101 02-Jul-2005 uwe

xscale UART FIFOs are 32 bytes deep; found by deraadt@


# 1.100 27-May-2005 uwe

- Merge changes from pxacom back into the common com driver.

Changes to the common com driver (partly from NetBSD):
- Multiply before divide in comspeed() to avoid overflow (from NetBSD).
- Don't call getc() and send -1 if the output queue is empty.
- Take UART clock frequency as a parameter instead of using COM_FREQ.

ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.99 20-Oct-2004 pefo

Use bus_addr_t instead of int for port address/offset, ok mickey


Revision tags: OPENBSD_3_6_BASE
# 1.98 09-Aug-2004 pefo

remove old arc stuff and add sgi support.
ok mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.97 30-May-2004 deraadt

serial console hack from tom. who, after having been told a few times
to commit it, has not. what is going on guys?


# 1.96 03-May-2004 drahn

Remove OpenBSD/pegaos, this has been announced before but delayed until
the tree was stable. No point in code supporting a company which screws
its employees being in the OpenBSD tree.


Revision tags: OPENBSD_3_5_BASE
# 1.95 31-Oct-2003 drahn

Use isa iot for pegasos com console attachment, perhaps this could
be adopted MI?


# 1.94 03-Oct-2003 miod

Merge tty_attach() in ttymalloc() and tty_detach() in ttyfree(). The need for
separate tty registering is gone now that sparc has switched to wscons, and
this makes the code less error-prone.

Also, remove tests for ttymalloc() failure, since it uses M_WAITOK.

ok millert@ deraadt@, tested by various people as well besides me...


# 1.93 23-Sep-2003 millert

Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater
poll(2) functionality instead of emulating it via the select backend.
Adapted from NetBSD and including some changes from FreeBSD.
Tested by many, deraadt@ OK


Revision tags: OPENBSD_3_4_BASE
# 1.92 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.91 15-Jul-2003 jason

move prototype for com_raisedtr() to comvar.h (just like pccom).


# 1.90 03-Jun-2003 deraadt

terms 3 & 4 cleanup based on "terms" file


# 1.89 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.88 19-Dec-2002 mickey

comparam() does not need an spltty() for it, already called there.
time-bound loops in com_common_cnputc() and lower to spltty(),
which i guess is left from times when timeouts were processed at splhigh().
jason@ tested and ok, art@ ok


Revision tags: UBC_SYNC_B
# 1.87 17-Oct-2002 art

ifndef __HAVE_GENERIC_SOFT_INTERRUPTS leaved a label without a statement after it. Fix.


Revision tags: OPENBSD_3_2_BASE
# 1.86 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.85 11-Jun-2002 miod

com.c is not a block device, no bdev_decl() for it.


Revision tags: OPENBSD_3_1_BASE
# 1.84 09-Apr-2002 pefo

Don't enable interrupts until an open() is done. Until then the driver
is not handling them and may throw the kernel into a spurious interrupt
loop. ok art@


# 1.83 14-Mar-2002 millert

First round of __P removal in sys


# 1.82 14-Mar-2002 jason

compare pointers with NULL not 0


# 1.81 05-Feb-2002 mickey

restore CN_REMOTE priority, as it always was there.
anyway, only i386 uses that path and only if forced anyway.
also do not do comprobe1() on hppa since that hoses the port.


# 1.80 30-Jan-2002 nordin

Move SET/CLR/ISSET macros to param.h. fgsch@ and millert@ ok


# 1.79 25-Jan-2002 mickey

CONADDR is defined elsewhere for hppa


# 1.78 23-Jan-2002 ericj

oops, make the kgdb var's non-static


# 1.77 23-Jan-2002 ericj

allow this to compile with KGDB


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.76 05-Oct-2001 mickey

branches: 1.76.4;
restore some of that dead code needed for dev/cons functionality


# 1.75 02-Oct-2001 art

#ifdef FOO works much better when FOO isn't misspelled.


# 1.74 30-Sep-2001 art

Enable break interrupt earlier.


# 1.73 30-Sep-2001 art

Next round of cleanups.
- some KNF.
- disable interrupts earlier in attach.
- give it some more time in attach to finish earlier output.
- explicit bus_space_barrier in comcnputc.
- dead code.


# 1.72 30-Sep-2001 art

Remove dead code.


# 1.71 30-Sep-2001 art

Remove the COM_HAYESP code. It doesn't appear to have been ever used and
it's very intrusive and makes the code less readable.


# 1.70 30-Sep-2001 art

Move out the com at commulti attachment into an ownfile.
Same story as isapnp - not tested because i386 uses pccom.


# 1.69 30-Sep-2001 art

Move out com at isapnp attachment into an own file.
Not tested because the only system with isapnp is i386 and i386 uses pccom.


# 1.68 29-Sep-2001 art

Next step in making the com driver improvable.
Split out the com at isa attachment into its own file.


# 1.67 29-Sep-2001 art

- compoll is now scheduled once for every sc instead of just one timeout for
all ports and looping over them.
- support for generic soft interrupts.


# 1.66 27-Sep-2001 art

Simplify comstart a bit.


# 1.65 27-Sep-2001 millert

Enable #if 0'd code in comcnputc() so serial console works correctly;
art@openbsd.org


# 1.64 27-Sep-2001 art

Split out comattach that does isa and isapnp attachment and initialization,
into comattach that does the isa stuff and com_attach_subr that does the
init.


Revision tags: OPENBSD_2_9_BASE
# 1.63 17-Apr-2001 aaron

Implement cnbell(), an optional entrypoint that rings the console bell; from
NetBSD. deraadt@ ok


# 1.62 15-Mar-2001 art

Put back new timeouts. This time with correct timeout for compoll.


# 1.61 15-Mar-2001 deraadt

typo


# 1.60 15-Mar-2001 art

back out new timeouts until I find out why they break alpha.


# 1.59 15-Mar-2001 deraadt

support puc devices with higher speeds (not tested yet)


# 1.58 13-Mar-2001 mickey

new timeouts


# 1.57 24-Jan-2001 hugh

KGDB for i386 from NetBSD via niklas, with tweaks and accommodations.
Tested by various, vetted by mickey & theo.


# 1.56 08-Nov-2000 art

Add comcnattach that does the basic steps needed to attach
a com as a serial console. (idea from NetBSD).

If cn_tab->cn_dev == NODEV, try to find comopen in cdevsw and set cn_dev
to the right device.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE SMP_BASE
# 1.55 27-Jan-2000 mickey

branches: 1.55.2;
isa-avoidance


# 1.54 11-Jan-2000 mickey

a few ifdef accomodations for hppa, also a few knf spaces


Revision tags: kame_19991208
# 1.53 28-Nov-1999 downsj

Enable TI16750 UART support.


# 1.52 09-Nov-1999 rahnds

in the ifdef POWERPC section, do use ppc, not p4e, for the iohandle
for the console configuration.


# 1.51 26-Oct-1999 downsj

This file has my code in it, attach my copyright.


Revision tags: OPENBSD_2_6_BASE
# 1.50 08-Aug-1999 niklas

pasto from pccom.c


# 1.49 08-Aug-1999 niklas

revert function accidentally committed


# 1.48 08-Aug-1999 niklas

Detach support for com; NetBSD and me


# 1.47 26-Jul-1999 niklas

Move over the ISA PnP support from pccom.c to com.c


# 1.46 26-Jul-1999 niklas

fix my last commit where I committed more than intended


# 1.45 26-Jul-1999 niklas

Remove obsolete detach code that has been dead for very long


# 1.44 25-Jun-1999 rees

Don't turn off uart when closing cua device if tty is waiting.
Instead just drop dtr briefly.


Revision tags: OPENBSD_2_5_BASE
# 1.43 09-Feb-1999 rees

Fix cua device to not block on open.
Turn off chip (and dtr) on interrupted open.


# 1.42 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.41 20-Sep-1998 rahnds

Powerpc port uses com.c not just power4e.


# 1.40 18-Aug-1998 pefo

Remove clearing of interrupt after character output in cnputci(). Clearing
the int will make the tty stop if output is currently active.


# 1.39 07-Aug-1998 pefo

com.c needs to know about mem mapped ports in ppc systems.

ncr.c and if_de.c needs some hooks for systems with ncr and dec
ether chips on the motherboard that runs on odd clocks and doesn't
support a srom. srom is emulated in machine dependent code.

big endian support for ncr and dec ether finished. the 21040
have some more coding requirements if it is to run BE since
it does not have the descriptor endian swap configuration bit.


Revision tags: OPENBSD_2_3_BASE
# 1.38 23-Feb-1998 downsj

New probe routine and support for ST16650.

Compiles, but completely untested.


# 1.37 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


Revision tags: OPENBSD_2_2_BASE
# 1.36 03-Sep-1997 deraadt

fix cua/tty locking


# 1.35 07-Jul-1997 niklas

Removed an unused arg


Revision tags: OPENBSD_2_1_BASE
# 1.34 10-Apr-1997 pefo

Need to separate i/o and mem on mips


# 1.33 17-Mar-1997 pefo

Serial console trouble again...


# 1.32 12-Mar-1997 pefo

The stupid "use console before configured" scheeme strikes again :-)


# 1.31 06-Mar-1997 tholo

Initial implementation of support for calling hardpps() on carrier enable


# 1.30 10-Dec-1996 deraadt

the real changes by niklas... I did not merge correctly


# 1.29 10-Dec-1996 deraadt

clr TS_WOPEN if bailing on cua opens
As well, at this point I've also done fancy cvs repository mangling to
ensure that the com* files in sys/dev/ic maintain the history we had
before. (Yes, I cleaned up the 2.0 tags too..)


# 1.28 29-Nov-1996 niklas

Missing pieces of new bus.h that CVS lost behind my back


# 1.27 12-Nov-1996 niklas

s/bus.h/bus.old.h/ to make the transit to the bus_space bus.h an easy road
possibly taken in small steps


# 1.26 09-Nov-1996 tholo

Break shall be handled as data == 0 and FE bit set; from Theo


# 1.25 30-Oct-1996 niklas

cominit is used from the outside (the alpha port)


# 1.24 22-Oct-1996 downsj

patch com speed initialization


# 1.23 16-Oct-1996 deraadt

contextual usage


# 1.22 16-Oct-1996 deraadt

unused variables


# 1.21 29-Aug-1996 deraadt

sunos-like cua behaviour; inspired by budd@cs.bu.edu in his scn.c


# 1.20 02-Jul-1996 downsj

better FIFO enabling code; netbsd pr#2574, cliff@wport.com


# 1.19 24-Jun-1996 pefo

pica changes backed out. does not belong here


# 1.18 22-Jun-1996 pefo

Pica bus support added


# 1.17 10-Jun-1996 niklas

Some cleanup for -Wall -Wstrict-prototypes


# 1.16 10-Jun-1996 deraadt

tty_attach()


# 1.15 26-May-1996 deraadt

sync 0521


# 1.14 10-May-1996 deraadt

proto change


# 1.13 07-May-1996 deraadt

sync with 0504 -- prototypes and bus.h


# 1.12 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.11 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.10 18-Apr-1996 niklas

NetBSD 960317 merge


# 1.9 20-Mar-1996 mickey

Fix back wrong patches.


# 1.8 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.7 08-Mar-1996 niklas

From NetBSD: merge of 960217


# 1.6 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.5 16-Jan-1996 hvozda

Last of the glue and devices for for PCMCIA support from Stefan Grefen
<grefen@convex.com> with modifications by John Kohl <jtk@kolvir.blrc.ma.us>


# 1.4 03-Jan-1996 deraadt

Patches to use Hayes ESP with com.c; from banshee@gabriella.resort.com;
netbsd pr#1865. the ESP card code is always enabled -- we will have to
see if that fails on any chipsets.


# 1.3 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.


# 1.2 15-Dec-1995 deraadt

update from netbsd


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.175 11-Jan-2022 uaa

add Synopsys Degisnware UART (dw-apb-uart) support

To fix Allwinner H6's UART problem, need to add dw-apb-uart special code.
ok kettenis@


Revision tags: OPENBSD_7_0_BASE
# 1.174 06-May-2021 kettenis

Fix bogus return statement.

From miod@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.173 14-Aug-2020 jcs

Re-commit Exar XR17V35x serial port support previously backed out:

The Exar XR17V354 has 4 ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

To avoid probing for these ports in com_attach_subr which requires
access to registers that may be reserved on certain platforms, pass
the sc_uarttype from com_puc_attach since the port type is already
known based on the puc device vendor/id.

Input from kettenis, tested in snaps


Revision tags: OPENBSD_6_7_BASE
# 1.172 09-Mar-2020 yasuoka

Update the console device always when attaching the real device
driver. The information by the driver is supposed more reliable than
the information which was set up earlier.

ok patrick


# 1.171 05-Feb-2020 mpi

Detach timeouts and the softint handler before freeing memory.

As more and more teardown functions include barriers, or any kind of
context change, it is unsafe to continue to assume that such code paths
are atomic. So a good practise is to only free descriptor when we're
sure that no other context can access them.

Found while looking at visa@'s ttkqflush() replacement diff. The same
pattern is present in many USB drivers as found with Peter Stuge.

ok visa@


Revision tags: OPENBSD_6_6_BASE
# 1.170 19-Jul-2019 cheloha

ttysleep(): drop unused timeout parameter

All callers sleep indefinitely.

With help from visa@.

ok visa@, ratchov@, kn@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.169 14-May-2018 kettenis

Add support for register shift/io-width to the console code as well.

ok visa@, patrick@


# 1.168 02-May-2018 kettenis

Revert previous commit; the XR17V35X probe that was added accesses registers
that aren't guaranteed to be there and may even belong to a different device.
This triggers a fault on hppa machines like the C3000 for example.


# 1.167 15-Apr-2018 jcs

The Exar XR17V354 has 4 com ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

ok mlarkin deraadt


# 1.166 02-Apr-2018 kettenis

Add support for register shift/io-width. This allows us to support UARTs
that are mostly NS16550 compatible but use 32-bit instead of 8-bit registers
such as the Synopsys Designware UARTs found on many armv7, arm64 and amd64
SoCs.

tested by florian@, blum@
ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.165 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.164 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.163 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.162 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.161 04-Sep-2016 tedu

remove some more sparc remnants. ok deraadt


# 1.160 03-Sep-2016 jsg

de-zaurus com.c
"looks correct" deraadt@ guenther@ on an earlier rev


# 1.159 16-Aug-2016 kettenis

Only probe the UART type if sc_uarttype is set to COM_UART_UNKNOWN.
This allows glue drivers to set the type based on other information (such as
Oopen Firmware or device tree properties) without going through to risky
code paths.

ok deraadt@, visa@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.158 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.157 13-Apr-2014 deraadt

wrap a long line


Revision tags: OPENBSD_5_5_BASE
# 1.156 09-Dec-2013 deraadt

At resume, do not spin flushing characters in from the chip. There shouldn't
be any characters. If the chip is not actually there for some reason, we'd
be spinning so early in the resume sequence, we'd probably go mad trying to
find the reason..
ok kettenis
request: people with serial ports on their laptops, try to run a "cu" over
a suspend/resume cycle, and see if you see "input noise"


# 1.155 09-Dec-2013 deraadt

At suspend/resume time cope with timeouts, DTR on resume in a bus
bus-independent fashion.
ok kettenis


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.154 14-Feb-2013 kettenis

No need to treat amd64 specially; always return CN_HIGHPRI.

ok miod@


# 1.153 17-Oct-2012 deraadt

Narrow the spltty/splx pair in com_activate to only enclose the minimum
operation which requires it.


# 1.152 25-Aug-2012 kettenis

Better detection of the st16650 v1 (with the broken fifo). Gets rid of
false positives like the DUART on the MPC8347 as found on socppc.

ok deraadt@


# 1.151 25-Aug-2012 kettenis

Turns out the v445 isn't happy at all if we touch the registers that deal
with sleep mode. So skip the wakeup code as well if we are a serial console.
The port on the v445 almost certainly isn't a real st16650 and probably
doesn't implement sleep mode (perhaps someone cut the soft core down a bit
too much?). But it is indistinguishable from it, so we have to deal with it.

ok deraadt@


# 1.150 19-Aug-2012 kettenis

Skip putting a port in sleep mode when it is used as serial console. In that
case the kernel will still be using the port even after the last process closes
it. And on machines like the v445 the firmware won't be happy if the console
port is in sleep mode when the kernel reboots or halts.

ok miod@


Revision tags: OPENBSD_5_2_BASE
# 1.149 12-May-2012 kettenis

Remove unused variable.

ok mpi@, miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.148 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.147 22-May-2011 drahn

Fix a problem found where one SOC has a uart implementation that causes bus
errors if the fifo is read when the fifo is empty. Dont read an empty fifo.
ok deraaadt@ fgsch@


# 1.146 23-Mar-2011 fgsch

only read from the UART if there is something to read. fix beagle, otherwise
it will crash with 'External Non-Linefetch Abort (S)'.
similar diff provided by drahn@. tested by jasper@, deraadt@ ok.


Revision tags: OPENBSD_4_9_BASE
# 1.145 28-Aug-2010 miod

ansify function definitions, and constify a few arrays while there.
no functional change.


Revision tags: OPENBSD_4_8_BASE
# 1.144 07-Aug-2010 kettenis

Add resume support for serial consoles.

Tested by sthen@, ok deraadt@


# 1.143 06-Aug-2010 kettenis

Initial stab at making com@puc suspend and resume properly. Works fine
for using cu(1) between two OpenBSD machines. Probably doesn't work for
serial consoles but we don't support those on puc(4) anyway.

ok deraadt@


# 1.142 02-Jul-2010 nicm

Move common code for waking up writers on a tty into a function.

ok deraadt matthew millert


# 1.141 28-Jun-2010 deraadt

Allow tty drivers to request larger buffers at attach time using a
max-baud-rate hint. Adjust TTYHOG (the nearly full logic) to this new
situation. The larger buffers are required by the very high speed
KDDI devices in Japan (CF com, or USB ucom) so those are the only two
drivers which currently ask for a larger buffer size.
ok yasuoka miod


# 1.140 28-Jun-2010 ckuethe

Use a more moderate fifo trigger level (4) for moderately quick
(sub-38400) port speeds. Inspired by netbsd. ok fgsch krw deraadt miod


# 1.139 26-Jun-2010 guenther

Don't #include <sys/user.h> into files that don't need the stuff
it defines. In some cases, this means pulling in uvm.h or pcb.h
instead, but most of the inclusions were just noise. Tested on
alpha, amd64, armish, hppa, i386, macpcc, sgi, sparc64, and vax,
mostly by krw and naddy.
ok krw@


# 1.138 12-Apr-2010 tedu

Some of the line disciplines want to check for suser. Better to pass them
a process instead of using curproc. ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.137 09-Nov-2009 nicm

Every selwakeup() should have a matching KNOTE() (even if kqueue isn't
supported it doesn't do any harm), so put the KNOTE() in selwakeup() itself and
remove it from any occurences where both are used, except one for kqueue itself
and one in sys_pipe.c (where the selwakeup is under a PIPE_SEL flag).

Based on a diff from tedu.

ok deraadt


# 1.136 04-Nov-2009 kettenis

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@


# 1.135 01-Nov-2009 nicm

Call selwakeup()/KNOTE() even if the queue has emptied completely.

ok miod


# 1.134 31-Oct-2009 fgsch

Use suser when possible. Suggested by miod@.
miod@ deraadt@ ok.


# 1.133 31-Oct-2009 deraadt

Add missing KNOTE() calls after selwakeup(), until we decide if the KNOTE()
calls can go directly into selwakeup() safely
long discussion with nicm, murmers of consent from tedu and miod, noone
else seems to care of kqueue is busted as long as it makes their sockets
move data fast... pretty sad.


# 1.132 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.131 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.130 23-Nov-2008 deraadt

pccom can finally die; ok kettenis dlg drahn, tested by okan


# 1.129 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


Revision tags: OPENBSD_4_4_BASE
# 1.128 08-Jun-2008 kettenis

Make serial console on non-primary ports work to on i386.

tested by jbg@, "it is right" deraadt@


# 1.127 25-Apr-2008 dlg

the code that parses arguments from the boot loader on amd64 wasnt checking
what type of console was specified, so when a glass console was used it was
still configuring serial bits. this makes it so serial config only occurs
for serial console devices.

found by jolan@, thib@, and maybe sthen@
sorry guys


# 1.126 24-Apr-2008 jsing

MD_ISA_IOT is not defined anywhere so get rid of it.

Spotted by drahn@, ok dlg@


# 1.125 24-Apr-2008 jsing

Keep order of "#if defined..." consistent.

ok dlg@


# 1.124 24-Apr-2008 jsing

Clean up comments.


# 1.123 24-Apr-2008 jsing

Cleanup serial console handling and remove some of the MD code from com.c.
Specify the serial configuration from within the MD code, rather than
passing things via macros. This will allow other platforms to more readily
change the serial console configuration.

Committing this so it actually gets tested.

ok dlg@


# 1.122 09-Apr-2008 deraadt

Increase buffer size sent to the fifo, and clamp the size correctly.
Scrub the buffer afterwards, too


Revision tags: OPENBSD_4_3_BASE
# 1.121 23-Jan-2008 jsing

Cleanup cn_pri. Change constants to more meaningful names, rather than
the hp300 related ones currently in use. CN_NORMAL becomes CN_LOWPRI,
CN_INTERNAL becomes CN_MIDPRI and CN_REMOTE becomes CN_HIGHPRI.

ok miod@


# 1.120 12-Jan-2008 miod

Make comconsrate initialized to TTYDEF_SPEED at compile-time, for ports
which need to setup the chip before comcnattach() is invoked.


# 1.119 08-Jan-2008 dlg

the rsc-console on the v880 operates at 115200, not the 9600 we think we
have to force all console devices to. this change passes the right speed
to the com code, and continues to use it when the device is opened as the
console device.

figured out by kettenis@
ok kettenis@ miod@


# 1.118 22-Aug-2007 jasper

fix compilation with KDGB
from Nicholas Marriott

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.117 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.116 22-Jun-2007 jasper

ansify/de-register
no binary change


# 1.115 08-May-2007 deraadt

backout while the amd64 puc situation is rethought


# 1.114 08-May-2007 deraadt

move com_activate() to where it belongs


# 1.113 08-May-2007 deraadt

put more foo_detach() routines where they are used


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.112 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.111 27-Apr-2006 deraadt

2 lines of code in most drivers, to do the timestamping; ok miod kettenis


# 1.110 27-Mar-2006 deraadt

in detach, mark device with COM_SW_DEAD, so that close() will not go
tapping additional registes. allows it to work on macppc, where doing
such a tap after unplug is very bad. drahn helped fkr@bytemine.de
ok miod and drahn


Revision tags: OPENBSD_3_9_BASE
# 1.109 01-Jan-2006 miod

Let cons_init() and cons_init_bell() initialize the whole consdev structure,
thus removing the need for drivers to initialize cn_pri to CN_DEAD when
hardware probe fails.


# 1.108 21-Nov-2005 millert

Move contents of sys/select.h to sys/selinfo.h in preparation for a
userland-visible sys/select.h. Consistent with what Net and Free do.
OK deraadt@, tested with full ports build by naddy@.


# 1.107 11-Nov-2005 fgsch

fix kgdb compilation; input and ok miod@.


# 1.106 26-Sep-2005 miod

Share com probe code between com and pccom; allows us to get rid of awkward
code duplication in cardbus, pcmcia and puc attachments.

Joint effort with fgs@; blessed deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.105 18-Jul-2005 deraadt

fix sparc64 console; same diff as miod


# 1.104 18-Jul-2005 deraadt

COM_CONSOLE & DDB fix


# 1.103 17-Jul-2005 miod

Allow the console support code not to be compiled in; this will be
necessary for and only used on sparc, shortly.

Reluctantely ok deraadt@


# 1.102 11-Jul-2005 uwe

Enable IR receive mode only for infrared capable PXA2x0 UARTs. Normal
reception is blocked while the IR receiver or transmitter is enabled.

Also enable the PXA2x0 UART before clearing the FIFO (suggested by
drahn@ some time ago), and disable the UART in compwroff().

ok deraadt@


# 1.101 02-Jul-2005 uwe

xscale UART FIFOs are 32 bytes deep; found by deraadt@


# 1.100 27-May-2005 uwe

- Merge changes from pxacom back into the common com driver.

Changes to the common com driver (partly from NetBSD):
- Multiply before divide in comspeed() to avoid overflow (from NetBSD).
- Don't call getc() and send -1 if the output queue is empty.
- Take UART clock frequency as a parameter instead of using COM_FREQ.

ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.99 20-Oct-2004 pefo

Use bus_addr_t instead of int for port address/offset, ok mickey


Revision tags: OPENBSD_3_6_BASE
# 1.98 09-Aug-2004 pefo

remove old arc stuff and add sgi support.
ok mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.97 30-May-2004 deraadt

serial console hack from tom. who, after having been told a few times
to commit it, has not. what is going on guys?


# 1.96 03-May-2004 drahn

Remove OpenBSD/pegaos, this has been announced before but delayed until
the tree was stable. No point in code supporting a company which screws
its employees being in the OpenBSD tree.


Revision tags: OPENBSD_3_5_BASE
# 1.95 31-Oct-2003 drahn

Use isa iot for pegasos com console attachment, perhaps this could
be adopted MI?


# 1.94 03-Oct-2003 miod

Merge tty_attach() in ttymalloc() and tty_detach() in ttyfree(). The need for
separate tty registering is gone now that sparc has switched to wscons, and
this makes the code less error-prone.

Also, remove tests for ttymalloc() failure, since it uses M_WAITOK.

ok millert@ deraadt@, tested by various people as well besides me...


# 1.93 23-Sep-2003 millert

Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater
poll(2) functionality instead of emulating it via the select backend.
Adapted from NetBSD and including some changes from FreeBSD.
Tested by many, deraadt@ OK


Revision tags: OPENBSD_3_4_BASE
# 1.92 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.91 15-Jul-2003 jason

move prototype for com_raisedtr() to comvar.h (just like pccom).


# 1.90 03-Jun-2003 deraadt

terms 3 & 4 cleanup based on "terms" file


# 1.89 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.88 19-Dec-2002 mickey

comparam() does not need an spltty() for it, already called there.
time-bound loops in com_common_cnputc() and lower to spltty(),
which i guess is left from times when timeouts were processed at splhigh().
jason@ tested and ok, art@ ok


Revision tags: UBC_SYNC_B
# 1.87 17-Oct-2002 art

ifndef __HAVE_GENERIC_SOFT_INTERRUPTS leaved a label without a statement after it. Fix.


Revision tags: OPENBSD_3_2_BASE
# 1.86 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.85 11-Jun-2002 miod

com.c is not a block device, no bdev_decl() for it.


Revision tags: OPENBSD_3_1_BASE
# 1.84 09-Apr-2002 pefo

Don't enable interrupts until an open() is done. Until then the driver
is not handling them and may throw the kernel into a spurious interrupt
loop. ok art@


# 1.83 14-Mar-2002 millert

First round of __P removal in sys


# 1.82 14-Mar-2002 jason

compare pointers with NULL not 0


# 1.81 05-Feb-2002 mickey

restore CN_REMOTE priority, as it always was there.
anyway, only i386 uses that path and only if forced anyway.
also do not do comprobe1() on hppa since that hoses the port.


# 1.80 30-Jan-2002 nordin

Move SET/CLR/ISSET macros to param.h. fgsch@ and millert@ ok


# 1.79 25-Jan-2002 mickey

CONADDR is defined elsewhere for hppa


# 1.78 23-Jan-2002 ericj

oops, make the kgdb var's non-static


# 1.77 23-Jan-2002 ericj

allow this to compile with KGDB


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.76 05-Oct-2001 mickey

branches: 1.76.4;
restore some of that dead code needed for dev/cons functionality


# 1.75 02-Oct-2001 art

#ifdef FOO works much better when FOO isn't misspelled.


# 1.74 30-Sep-2001 art

Enable break interrupt earlier.


# 1.73 30-Sep-2001 art

Next round of cleanups.
- some KNF.
- disable interrupts earlier in attach.
- give it some more time in attach to finish earlier output.
- explicit bus_space_barrier in comcnputc.
- dead code.


# 1.72 30-Sep-2001 art

Remove dead code.


# 1.71 30-Sep-2001 art

Remove the COM_HAYESP code. It doesn't appear to have been ever used and
it's very intrusive and makes the code less readable.


# 1.70 30-Sep-2001 art

Move out the com at commulti attachment into an ownfile.
Same story as isapnp - not tested because i386 uses pccom.


# 1.69 30-Sep-2001 art

Move out com at isapnp attachment into an own file.
Not tested because the only system with isapnp is i386 and i386 uses pccom.


# 1.68 29-Sep-2001 art

Next step in making the com driver improvable.
Split out the com at isa attachment into its own file.


# 1.67 29-Sep-2001 art

- compoll is now scheduled once for every sc instead of just one timeout for
all ports and looping over them.
- support for generic soft interrupts.


# 1.66 27-Sep-2001 art

Simplify comstart a bit.


# 1.65 27-Sep-2001 millert

Enable #if 0'd code in comcnputc() so serial console works correctly;
art@openbsd.org


# 1.64 27-Sep-2001 art

Split out comattach that does isa and isapnp attachment and initialization,
into comattach that does the isa stuff and com_attach_subr that does the
init.


Revision tags: OPENBSD_2_9_BASE
# 1.63 17-Apr-2001 aaron

Implement cnbell(), an optional entrypoint that rings the console bell; from
NetBSD. deraadt@ ok


# 1.62 15-Mar-2001 art

Put back new timeouts. This time with correct timeout for compoll.


# 1.61 15-Mar-2001 deraadt

typo


# 1.60 15-Mar-2001 art

back out new timeouts until I find out why they break alpha.


# 1.59 15-Mar-2001 deraadt

support puc devices with higher speeds (not tested yet)


# 1.58 13-Mar-2001 mickey

new timeouts


# 1.57 24-Jan-2001 hugh

KGDB for i386 from NetBSD via niklas, with tweaks and accommodations.
Tested by various, vetted by mickey & theo.


# 1.56 08-Nov-2000 art

Add comcnattach that does the basic steps needed to attach
a com as a serial console. (idea from NetBSD).

If cn_tab->cn_dev == NODEV, try to find comopen in cdevsw and set cn_dev
to the right device.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE SMP_BASE
# 1.55 27-Jan-2000 mickey

branches: 1.55.2;
isa-avoidance


# 1.54 11-Jan-2000 mickey

a few ifdef accomodations for hppa, also a few knf spaces


Revision tags: kame_19991208
# 1.53 28-Nov-1999 downsj

Enable TI16750 UART support.


# 1.52 09-Nov-1999 rahnds

in the ifdef POWERPC section, do use ppc, not p4e, for the iohandle
for the console configuration.


# 1.51 26-Oct-1999 downsj

This file has my code in it, attach my copyright.


Revision tags: OPENBSD_2_6_BASE
# 1.50 08-Aug-1999 niklas

pasto from pccom.c


# 1.49 08-Aug-1999 niklas

revert function accidentally committed


# 1.48 08-Aug-1999 niklas

Detach support for com; NetBSD and me


# 1.47 26-Jul-1999 niklas

Move over the ISA PnP support from pccom.c to com.c


# 1.46 26-Jul-1999 niklas

fix my last commit where I committed more than intended


# 1.45 26-Jul-1999 niklas

Remove obsolete detach code that has been dead for very long


# 1.44 25-Jun-1999 rees

Don't turn off uart when closing cua device if tty is waiting.
Instead just drop dtr briefly.


Revision tags: OPENBSD_2_5_BASE
# 1.43 09-Feb-1999 rees

Fix cua device to not block on open.
Turn off chip (and dtr) on interrupted open.


# 1.42 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.41 20-Sep-1998 rahnds

Powerpc port uses com.c not just power4e.


# 1.40 18-Aug-1998 pefo

Remove clearing of interrupt after character output in cnputci(). Clearing
the int will make the tty stop if output is currently active.


# 1.39 07-Aug-1998 pefo

com.c needs to know about mem mapped ports in ppc systems.

ncr.c and if_de.c needs some hooks for systems with ncr and dec
ether chips on the motherboard that runs on odd clocks and doesn't
support a srom. srom is emulated in machine dependent code.

big endian support for ncr and dec ether finished. the 21040
have some more coding requirements if it is to run BE since
it does not have the descriptor endian swap configuration bit.


Revision tags: OPENBSD_2_3_BASE
# 1.38 23-Feb-1998 downsj

New probe routine and support for ST16650.

Compiles, but completely untested.


# 1.37 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


Revision tags: OPENBSD_2_2_BASE
# 1.36 03-Sep-1997 deraadt

fix cua/tty locking


# 1.35 07-Jul-1997 niklas

Removed an unused arg


Revision tags: OPENBSD_2_1_BASE
# 1.34 10-Apr-1997 pefo

Need to separate i/o and mem on mips


# 1.33 17-Mar-1997 pefo

Serial console trouble again...


# 1.32 12-Mar-1997 pefo

The stupid "use console before configured" scheeme strikes again :-)


# 1.31 06-Mar-1997 tholo

Initial implementation of support for calling hardpps() on carrier enable


# 1.30 10-Dec-1996 deraadt

the real changes by niklas... I did not merge correctly


# 1.29 10-Dec-1996 deraadt

clr TS_WOPEN if bailing on cua opens
As well, at this point I've also done fancy cvs repository mangling to
ensure that the com* files in sys/dev/ic maintain the history we had
before. (Yes, I cleaned up the 2.0 tags too..)


# 1.28 29-Nov-1996 niklas

Missing pieces of new bus.h that CVS lost behind my back


# 1.27 12-Nov-1996 niklas

s/bus.h/bus.old.h/ to make the transit to the bus_space bus.h an easy road
possibly taken in small steps


# 1.26 09-Nov-1996 tholo

Break shall be handled as data == 0 and FE bit set; from Theo


# 1.25 30-Oct-1996 niklas

cominit is used from the outside (the alpha port)


# 1.24 22-Oct-1996 downsj

patch com speed initialization


# 1.23 16-Oct-1996 deraadt

contextual usage


# 1.22 16-Oct-1996 deraadt

unused variables


# 1.21 29-Aug-1996 deraadt

sunos-like cua behaviour; inspired by budd@cs.bu.edu in his scn.c


# 1.20 02-Jul-1996 downsj

better FIFO enabling code; netbsd pr#2574, cliff@wport.com


# 1.19 24-Jun-1996 pefo

pica changes backed out. does not belong here


# 1.18 22-Jun-1996 pefo

Pica bus support added


# 1.17 10-Jun-1996 niklas

Some cleanup for -Wall -Wstrict-prototypes


# 1.16 10-Jun-1996 deraadt

tty_attach()


# 1.15 26-May-1996 deraadt

sync 0521


# 1.14 10-May-1996 deraadt

proto change


# 1.13 07-May-1996 deraadt

sync with 0504 -- prototypes and bus.h


# 1.12 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.11 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.10 18-Apr-1996 niklas

NetBSD 960317 merge


# 1.9 20-Mar-1996 mickey

Fix back wrong patches.


# 1.8 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.7 08-Mar-1996 niklas

From NetBSD: merge of 960217


# 1.6 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.5 16-Jan-1996 hvozda

Last of the glue and devices for for PCMCIA support from Stefan Grefen
<grefen@convex.com> with modifications by John Kohl <jtk@kolvir.blrc.ma.us>


# 1.4 03-Jan-1996 deraadt

Patches to use Hayes ESP with com.c; from banshee@gabriella.resort.com;
netbsd pr#1865. the ESP card code is always enabled -- we will have to
see if that fails on any chipsets.


# 1.3 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.


# 1.2 15-Dec-1995 deraadt

update from netbsd


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.174 06-May-2021 kettenis

Fix bogus return statement.

From miod@


Revision tags: OPENBSD_6_8_BASE OPENBSD_6_9_BASE
# 1.173 14-Aug-2020 jcs

Re-commit Exar XR17V35x serial port support previously backed out:

The Exar XR17V354 has 4 ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

To avoid probing for these ports in com_attach_subr which requires
access to registers that may be reserved on certain platforms, pass
the sc_uarttype from com_puc_attach since the port type is already
known based on the puc device vendor/id.

Input from kettenis, tested in snaps


Revision tags: OPENBSD_6_7_BASE
# 1.172 09-Mar-2020 yasuoka

Update the console device always when attaching the real device
driver. The information by the driver is supposed more reliable than
the information which was set up earlier.

ok patrick


# 1.171 05-Feb-2020 mpi

Detach timeouts and the softint handler before freeing memory.

As more and more teardown functions include barriers, or any kind of
context change, it is unsafe to continue to assume that such code paths
are atomic. So a good practise is to only free descriptor when we're
sure that no other context can access them.

Found while looking at visa@'s ttkqflush() replacement diff. The same
pattern is present in many USB drivers as found with Peter Stuge.

ok visa@


Revision tags: OPENBSD_6_6_BASE
# 1.170 19-Jul-2019 cheloha

ttysleep(): drop unused timeout parameter

All callers sleep indefinitely.

With help from visa@.

ok visa@, ratchov@, kn@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.169 14-May-2018 kettenis

Add support for register shift/io-width to the console code as well.

ok visa@, patrick@


# 1.168 02-May-2018 kettenis

Revert previous commit; the XR17V35X probe that was added accesses registers
that aren't guaranteed to be there and may even belong to a different device.
This triggers a fault on hppa machines like the C3000 for example.


# 1.167 15-Apr-2018 jcs

The Exar XR17V354 has 4 com ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

ok mlarkin deraadt


# 1.166 02-Apr-2018 kettenis

Add support for register shift/io-width. This allows us to support UARTs
that are mostly NS16550 compatible but use 32-bit instead of 8-bit registers
such as the Synopsys Designware UARTs found on many armv7, arm64 and amd64
SoCs.

tested by florian@, blum@
ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.165 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.164 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.163 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.162 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.161 04-Sep-2016 tedu

remove some more sparc remnants. ok deraadt


# 1.160 03-Sep-2016 jsg

de-zaurus com.c
"looks correct" deraadt@ guenther@ on an earlier rev


# 1.159 16-Aug-2016 kettenis

Only probe the UART type if sc_uarttype is set to COM_UART_UNKNOWN.
This allows glue drivers to set the type based on other information (such as
Oopen Firmware or device tree properties) without going through to risky
code paths.

ok deraadt@, visa@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.158 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.157 13-Apr-2014 deraadt

wrap a long line


Revision tags: OPENBSD_5_5_BASE
# 1.156 09-Dec-2013 deraadt

At resume, do not spin flushing characters in from the chip. There shouldn't
be any characters. If the chip is not actually there for some reason, we'd
be spinning so early in the resume sequence, we'd probably go mad trying to
find the reason..
ok kettenis
request: people with serial ports on their laptops, try to run a "cu" over
a suspend/resume cycle, and see if you see "input noise"


# 1.155 09-Dec-2013 deraadt

At suspend/resume time cope with timeouts, DTR on resume in a bus
bus-independent fashion.
ok kettenis


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.154 14-Feb-2013 kettenis

No need to treat amd64 specially; always return CN_HIGHPRI.

ok miod@


# 1.153 17-Oct-2012 deraadt

Narrow the spltty/splx pair in com_activate to only enclose the minimum
operation which requires it.


# 1.152 25-Aug-2012 kettenis

Better detection of the st16650 v1 (with the broken fifo). Gets rid of
false positives like the DUART on the MPC8347 as found on socppc.

ok deraadt@


# 1.151 25-Aug-2012 kettenis

Turns out the v445 isn't happy at all if we touch the registers that deal
with sleep mode. So skip the wakeup code as well if we are a serial console.
The port on the v445 almost certainly isn't a real st16650 and probably
doesn't implement sleep mode (perhaps someone cut the soft core down a bit
too much?). But it is indistinguishable from it, so we have to deal with it.

ok deraadt@


# 1.150 19-Aug-2012 kettenis

Skip putting a port in sleep mode when it is used as serial console. In that
case the kernel will still be using the port even after the last process closes
it. And on machines like the v445 the firmware won't be happy if the console
port is in sleep mode when the kernel reboots or halts.

ok miod@


Revision tags: OPENBSD_5_2_BASE
# 1.149 12-May-2012 kettenis

Remove unused variable.

ok mpi@, miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.148 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.147 22-May-2011 drahn

Fix a problem found where one SOC has a uart implementation that causes bus
errors if the fifo is read when the fifo is empty. Dont read an empty fifo.
ok deraaadt@ fgsch@


# 1.146 23-Mar-2011 fgsch

only read from the UART if there is something to read. fix beagle, otherwise
it will crash with 'External Non-Linefetch Abort (S)'.
similar diff provided by drahn@. tested by jasper@, deraadt@ ok.


Revision tags: OPENBSD_4_9_BASE
# 1.145 28-Aug-2010 miod

ansify function definitions, and constify a few arrays while there.
no functional change.


Revision tags: OPENBSD_4_8_BASE
# 1.144 07-Aug-2010 kettenis

Add resume support for serial consoles.

Tested by sthen@, ok deraadt@


# 1.143 06-Aug-2010 kettenis

Initial stab at making com@puc suspend and resume properly. Works fine
for using cu(1) between two OpenBSD machines. Probably doesn't work for
serial consoles but we don't support those on puc(4) anyway.

ok deraadt@


# 1.142 02-Jul-2010 nicm

Move common code for waking up writers on a tty into a function.

ok deraadt matthew millert


# 1.141 28-Jun-2010 deraadt

Allow tty drivers to request larger buffers at attach time using a
max-baud-rate hint. Adjust TTYHOG (the nearly full logic) to this new
situation. The larger buffers are required by the very high speed
KDDI devices in Japan (CF com, or USB ucom) so those are the only two
drivers which currently ask for a larger buffer size.
ok yasuoka miod


# 1.140 28-Jun-2010 ckuethe

Use a more moderate fifo trigger level (4) for moderately quick
(sub-38400) port speeds. Inspired by netbsd. ok fgsch krw deraadt miod


# 1.139 26-Jun-2010 guenther

Don't #include <sys/user.h> into files that don't need the stuff
it defines. In some cases, this means pulling in uvm.h or pcb.h
instead, but most of the inclusions were just noise. Tested on
alpha, amd64, armish, hppa, i386, macpcc, sgi, sparc64, and vax,
mostly by krw and naddy.
ok krw@


# 1.138 12-Apr-2010 tedu

Some of the line disciplines want to check for suser. Better to pass them
a process instead of using curproc. ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.137 09-Nov-2009 nicm

Every selwakeup() should have a matching KNOTE() (even if kqueue isn't
supported it doesn't do any harm), so put the KNOTE() in selwakeup() itself and
remove it from any occurences where both are used, except one for kqueue itself
and one in sys_pipe.c (where the selwakeup is under a PIPE_SEL flag).

Based on a diff from tedu.

ok deraadt


# 1.136 04-Nov-2009 kettenis

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@


# 1.135 01-Nov-2009 nicm

Call selwakeup()/KNOTE() even if the queue has emptied completely.

ok miod


# 1.134 31-Oct-2009 fgsch

Use suser when possible. Suggested by miod@.
miod@ deraadt@ ok.


# 1.133 31-Oct-2009 deraadt

Add missing KNOTE() calls after selwakeup(), until we decide if the KNOTE()
calls can go directly into selwakeup() safely
long discussion with nicm, murmers of consent from tedu and miod, noone
else seems to care of kqueue is busted as long as it makes their sockets
move data fast... pretty sad.


# 1.132 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.131 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.130 23-Nov-2008 deraadt

pccom can finally die; ok kettenis dlg drahn, tested by okan


# 1.129 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


Revision tags: OPENBSD_4_4_BASE
# 1.128 08-Jun-2008 kettenis

Make serial console on non-primary ports work to on i386.

tested by jbg@, "it is right" deraadt@


# 1.127 25-Apr-2008 dlg

the code that parses arguments from the boot loader on amd64 wasnt checking
what type of console was specified, so when a glass console was used it was
still configuring serial bits. this makes it so serial config only occurs
for serial console devices.

found by jolan@, thib@, and maybe sthen@
sorry guys


# 1.126 24-Apr-2008 jsing

MD_ISA_IOT is not defined anywhere so get rid of it.

Spotted by drahn@, ok dlg@


# 1.125 24-Apr-2008 jsing

Keep order of "#if defined..." consistent.

ok dlg@


# 1.124 24-Apr-2008 jsing

Clean up comments.


# 1.123 24-Apr-2008 jsing

Cleanup serial console handling and remove some of the MD code from com.c.
Specify the serial configuration from within the MD code, rather than
passing things via macros. This will allow other platforms to more readily
change the serial console configuration.

Committing this so it actually gets tested.

ok dlg@


# 1.122 09-Apr-2008 deraadt

Increase buffer size sent to the fifo, and clamp the size correctly.
Scrub the buffer afterwards, too


Revision tags: OPENBSD_4_3_BASE
# 1.121 23-Jan-2008 jsing

Cleanup cn_pri. Change constants to more meaningful names, rather than
the hp300 related ones currently in use. CN_NORMAL becomes CN_LOWPRI,
CN_INTERNAL becomes CN_MIDPRI and CN_REMOTE becomes CN_HIGHPRI.

ok miod@


# 1.120 12-Jan-2008 miod

Make comconsrate initialized to TTYDEF_SPEED at compile-time, for ports
which need to setup the chip before comcnattach() is invoked.


# 1.119 08-Jan-2008 dlg

the rsc-console on the v880 operates at 115200, not the 9600 we think we
have to force all console devices to. this change passes the right speed
to the com code, and continues to use it when the device is opened as the
console device.

figured out by kettenis@
ok kettenis@ miod@


# 1.118 22-Aug-2007 jasper

fix compilation with KDGB
from Nicholas Marriott

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.117 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.116 22-Jun-2007 jasper

ansify/de-register
no binary change


# 1.115 08-May-2007 deraadt

backout while the amd64 puc situation is rethought


# 1.114 08-May-2007 deraadt

move com_activate() to where it belongs


# 1.113 08-May-2007 deraadt

put more foo_detach() routines where they are used


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.112 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.111 27-Apr-2006 deraadt

2 lines of code in most drivers, to do the timestamping; ok miod kettenis


# 1.110 27-Mar-2006 deraadt

in detach, mark device with COM_SW_DEAD, so that close() will not go
tapping additional registes. allows it to work on macppc, where doing
such a tap after unplug is very bad. drahn helped fkr@bytemine.de
ok miod and drahn


Revision tags: OPENBSD_3_9_BASE
# 1.109 01-Jan-2006 miod

Let cons_init() and cons_init_bell() initialize the whole consdev structure,
thus removing the need for drivers to initialize cn_pri to CN_DEAD when
hardware probe fails.


# 1.108 21-Nov-2005 millert

Move contents of sys/select.h to sys/selinfo.h in preparation for a
userland-visible sys/select.h. Consistent with what Net and Free do.
OK deraadt@, tested with full ports build by naddy@.


# 1.107 11-Nov-2005 fgsch

fix kgdb compilation; input and ok miod@.


# 1.106 26-Sep-2005 miod

Share com probe code between com and pccom; allows us to get rid of awkward
code duplication in cardbus, pcmcia and puc attachments.

Joint effort with fgs@; blessed deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.105 18-Jul-2005 deraadt

fix sparc64 console; same diff as miod


# 1.104 18-Jul-2005 deraadt

COM_CONSOLE & DDB fix


# 1.103 17-Jul-2005 miod

Allow the console support code not to be compiled in; this will be
necessary for and only used on sparc, shortly.

Reluctantely ok deraadt@


# 1.102 11-Jul-2005 uwe

Enable IR receive mode only for infrared capable PXA2x0 UARTs. Normal
reception is blocked while the IR receiver or transmitter is enabled.

Also enable the PXA2x0 UART before clearing the FIFO (suggested by
drahn@ some time ago), and disable the UART in compwroff().

ok deraadt@


# 1.101 02-Jul-2005 uwe

xscale UART FIFOs are 32 bytes deep; found by deraadt@


# 1.100 27-May-2005 uwe

- Merge changes from pxacom back into the common com driver.

Changes to the common com driver (partly from NetBSD):
- Multiply before divide in comspeed() to avoid overflow (from NetBSD).
- Don't call getc() and send -1 if the output queue is empty.
- Take UART clock frequency as a parameter instead of using COM_FREQ.

ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.99 20-Oct-2004 pefo

Use bus_addr_t instead of int for port address/offset, ok mickey


Revision tags: OPENBSD_3_6_BASE
# 1.98 09-Aug-2004 pefo

remove old arc stuff and add sgi support.
ok mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.97 30-May-2004 deraadt

serial console hack from tom. who, after having been told a few times
to commit it, has not. what is going on guys?


# 1.96 03-May-2004 drahn

Remove OpenBSD/pegaos, this has been announced before but delayed until
the tree was stable. No point in code supporting a company which screws
its employees being in the OpenBSD tree.


Revision tags: OPENBSD_3_5_BASE
# 1.95 31-Oct-2003 drahn

Use isa iot for pegasos com console attachment, perhaps this could
be adopted MI?


# 1.94 03-Oct-2003 miod

Merge tty_attach() in ttymalloc() and tty_detach() in ttyfree(). The need for
separate tty registering is gone now that sparc has switched to wscons, and
this makes the code less error-prone.

Also, remove tests for ttymalloc() failure, since it uses M_WAITOK.

ok millert@ deraadt@, tested by various people as well besides me...


# 1.93 23-Sep-2003 millert

Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater
poll(2) functionality instead of emulating it via the select backend.
Adapted from NetBSD and including some changes from FreeBSD.
Tested by many, deraadt@ OK


Revision tags: OPENBSD_3_4_BASE
# 1.92 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.91 15-Jul-2003 jason

move prototype for com_raisedtr() to comvar.h (just like pccom).


# 1.90 03-Jun-2003 deraadt

terms 3 & 4 cleanup based on "terms" file


# 1.89 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.88 19-Dec-2002 mickey

comparam() does not need an spltty() for it, already called there.
time-bound loops in com_common_cnputc() and lower to spltty(),
which i guess is left from times when timeouts were processed at splhigh().
jason@ tested and ok, art@ ok


Revision tags: UBC_SYNC_B
# 1.87 17-Oct-2002 art

ifndef __HAVE_GENERIC_SOFT_INTERRUPTS leaved a label without a statement after it. Fix.


Revision tags: OPENBSD_3_2_BASE
# 1.86 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.85 11-Jun-2002 miod

com.c is not a block device, no bdev_decl() for it.


Revision tags: OPENBSD_3_1_BASE
# 1.84 09-Apr-2002 pefo

Don't enable interrupts until an open() is done. Until then the driver
is not handling them and may throw the kernel into a spurious interrupt
loop. ok art@


# 1.83 14-Mar-2002 millert

First round of __P removal in sys


# 1.82 14-Mar-2002 jason

compare pointers with NULL not 0


# 1.81 05-Feb-2002 mickey

restore CN_REMOTE priority, as it always was there.
anyway, only i386 uses that path and only if forced anyway.
also do not do comprobe1() on hppa since that hoses the port.


# 1.80 30-Jan-2002 nordin

Move SET/CLR/ISSET macros to param.h. fgsch@ and millert@ ok


# 1.79 25-Jan-2002 mickey

CONADDR is defined elsewhere for hppa


# 1.78 23-Jan-2002 ericj

oops, make the kgdb var's non-static


# 1.77 23-Jan-2002 ericj

allow this to compile with KGDB


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.76 05-Oct-2001 mickey

branches: 1.76.4;
restore some of that dead code needed for dev/cons functionality


# 1.75 02-Oct-2001 art

#ifdef FOO works much better when FOO isn't misspelled.


# 1.74 30-Sep-2001 art

Enable break interrupt earlier.


# 1.73 30-Sep-2001 art

Next round of cleanups.
- some KNF.
- disable interrupts earlier in attach.
- give it some more time in attach to finish earlier output.
- explicit bus_space_barrier in comcnputc.
- dead code.


# 1.72 30-Sep-2001 art

Remove dead code.


# 1.71 30-Sep-2001 art

Remove the COM_HAYESP code. It doesn't appear to have been ever used and
it's very intrusive and makes the code less readable.


# 1.70 30-Sep-2001 art

Move out the com at commulti attachment into an ownfile.
Same story as isapnp - not tested because i386 uses pccom.


# 1.69 30-Sep-2001 art

Move out com at isapnp attachment into an own file.
Not tested because the only system with isapnp is i386 and i386 uses pccom.


# 1.68 29-Sep-2001 art

Next step in making the com driver improvable.
Split out the com at isa attachment into its own file.


# 1.67 29-Sep-2001 art

- compoll is now scheduled once for every sc instead of just one timeout for
all ports and looping over them.
- support for generic soft interrupts.


# 1.66 27-Sep-2001 art

Simplify comstart a bit.


# 1.65 27-Sep-2001 millert

Enable #if 0'd code in comcnputc() so serial console works correctly;
art@openbsd.org


# 1.64 27-Sep-2001 art

Split out comattach that does isa and isapnp attachment and initialization,
into comattach that does the isa stuff and com_attach_subr that does the
init.


Revision tags: OPENBSD_2_9_BASE
# 1.63 17-Apr-2001 aaron

Implement cnbell(), an optional entrypoint that rings the console bell; from
NetBSD. deraadt@ ok


# 1.62 15-Mar-2001 art

Put back new timeouts. This time with correct timeout for compoll.


# 1.61 15-Mar-2001 deraadt

typo


# 1.60 15-Mar-2001 art

back out new timeouts until I find out why they break alpha.


# 1.59 15-Mar-2001 deraadt

support puc devices with higher speeds (not tested yet)


# 1.58 13-Mar-2001 mickey

new timeouts


# 1.57 24-Jan-2001 hugh

KGDB for i386 from NetBSD via niklas, with tweaks and accommodations.
Tested by various, vetted by mickey & theo.


# 1.56 08-Nov-2000 art

Add comcnattach that does the basic steps needed to attach
a com as a serial console. (idea from NetBSD).

If cn_tab->cn_dev == NODEV, try to find comopen in cdevsw and set cn_dev
to the right device.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE SMP_BASE
# 1.55 27-Jan-2000 mickey

branches: 1.55.2;
isa-avoidance


# 1.54 11-Jan-2000 mickey

a few ifdef accomodations for hppa, also a few knf spaces


Revision tags: kame_19991208
# 1.53 28-Nov-1999 downsj

Enable TI16750 UART support.


# 1.52 09-Nov-1999 rahnds

in the ifdef POWERPC section, do use ppc, not p4e, for the iohandle
for the console configuration.


# 1.51 26-Oct-1999 downsj

This file has my code in it, attach my copyright.


Revision tags: OPENBSD_2_6_BASE
# 1.50 08-Aug-1999 niklas

pasto from pccom.c


# 1.49 08-Aug-1999 niklas

revert function accidentally committed


# 1.48 08-Aug-1999 niklas

Detach support for com; NetBSD and me


# 1.47 26-Jul-1999 niklas

Move over the ISA PnP support from pccom.c to com.c


# 1.46 26-Jul-1999 niklas

fix my last commit where I committed more than intended


# 1.45 26-Jul-1999 niklas

Remove obsolete detach code that has been dead for very long


# 1.44 25-Jun-1999 rees

Don't turn off uart when closing cua device if tty is waiting.
Instead just drop dtr briefly.


Revision tags: OPENBSD_2_5_BASE
# 1.43 09-Feb-1999 rees

Fix cua device to not block on open.
Turn off chip (and dtr) on interrupted open.


# 1.42 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.41 20-Sep-1998 rahnds

Powerpc port uses com.c not just power4e.


# 1.40 18-Aug-1998 pefo

Remove clearing of interrupt after character output in cnputci(). Clearing
the int will make the tty stop if output is currently active.


# 1.39 07-Aug-1998 pefo

com.c needs to know about mem mapped ports in ppc systems.

ncr.c and if_de.c needs some hooks for systems with ncr and dec
ether chips on the motherboard that runs on odd clocks and doesn't
support a srom. srom is emulated in machine dependent code.

big endian support for ncr and dec ether finished. the 21040
have some more coding requirements if it is to run BE since
it does not have the descriptor endian swap configuration bit.


Revision tags: OPENBSD_2_3_BASE
# 1.38 23-Feb-1998 downsj

New probe routine and support for ST16650.

Compiles, but completely untested.


# 1.37 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


Revision tags: OPENBSD_2_2_BASE
# 1.36 03-Sep-1997 deraadt

fix cua/tty locking


# 1.35 07-Jul-1997 niklas

Removed an unused arg


Revision tags: OPENBSD_2_1_BASE
# 1.34 10-Apr-1997 pefo

Need to separate i/o and mem on mips


# 1.33 17-Mar-1997 pefo

Serial console trouble again...


# 1.32 12-Mar-1997 pefo

The stupid "use console before configured" scheeme strikes again :-)


# 1.31 06-Mar-1997 tholo

Initial implementation of support for calling hardpps() on carrier enable


# 1.30 10-Dec-1996 deraadt

the real changes by niklas... I did not merge correctly


# 1.29 10-Dec-1996 deraadt

clr TS_WOPEN if bailing on cua opens
As well, at this point I've also done fancy cvs repository mangling to
ensure that the com* files in sys/dev/ic maintain the history we had
before. (Yes, I cleaned up the 2.0 tags too..)


# 1.28 29-Nov-1996 niklas

Missing pieces of new bus.h that CVS lost behind my back


# 1.27 12-Nov-1996 niklas

s/bus.h/bus.old.h/ to make the transit to the bus_space bus.h an easy road
possibly taken in small steps


# 1.26 09-Nov-1996 tholo

Break shall be handled as data == 0 and FE bit set; from Theo


# 1.25 30-Oct-1996 niklas

cominit is used from the outside (the alpha port)


# 1.24 22-Oct-1996 downsj

patch com speed initialization


# 1.23 16-Oct-1996 deraadt

contextual usage


# 1.22 16-Oct-1996 deraadt

unused variables


# 1.21 29-Aug-1996 deraadt

sunos-like cua behaviour; inspired by budd@cs.bu.edu in his scn.c


# 1.20 02-Jul-1996 downsj

better FIFO enabling code; netbsd pr#2574, cliff@wport.com


# 1.19 24-Jun-1996 pefo

pica changes backed out. does not belong here


# 1.18 22-Jun-1996 pefo

Pica bus support added


# 1.17 10-Jun-1996 niklas

Some cleanup for -Wall -Wstrict-prototypes


# 1.16 10-Jun-1996 deraadt

tty_attach()


# 1.15 26-May-1996 deraadt

sync 0521


# 1.14 10-May-1996 deraadt

proto change


# 1.13 07-May-1996 deraadt

sync with 0504 -- prototypes and bus.h


# 1.12 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.11 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.10 18-Apr-1996 niklas

NetBSD 960317 merge


# 1.9 20-Mar-1996 mickey

Fix back wrong patches.


# 1.8 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.7 08-Mar-1996 niklas

From NetBSD: merge of 960217


# 1.6 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.5 16-Jan-1996 hvozda

Last of the glue and devices for for PCMCIA support from Stefan Grefen
<grefen@convex.com> with modifications by John Kohl <jtk@kolvir.blrc.ma.us>


# 1.4 03-Jan-1996 deraadt

Patches to use Hayes ESP with com.c; from banshee@gabriella.resort.com;
netbsd pr#1865. the ESP card code is always enabled -- we will have to
see if that fails on any chipsets.


# 1.3 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.


# 1.2 15-Dec-1995 deraadt

update from netbsd


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.173 14-Aug-2020 jcs

Re-commit Exar XR17V35x serial port support previously backed out:

The Exar XR17V354 has 4 ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

To avoid probing for these ports in com_attach_subr which requires
access to registers that may be reserved on certain platforms, pass
the sc_uarttype from com_puc_attach since the port type is already
known based on the puc device vendor/id.

Input from kettenis, tested in snaps


Revision tags: OPENBSD_6_7_BASE
# 1.172 09-Mar-2020 yasuoka

Update the console device always when attaching the real device
driver. The information by the driver is supposed more reliable than
the information which was set up earlier.

ok patrick


# 1.171 05-Feb-2020 mpi

Detach timeouts and the softint handler before freeing memory.

As more and more teardown functions include barriers, or any kind of
context change, it is unsafe to continue to assume that such code paths
are atomic. So a good practise is to only free descriptor when we're
sure that no other context can access them.

Found while looking at visa@'s ttkqflush() replacement diff. The same
pattern is present in many USB drivers as found with Peter Stuge.

ok visa@


Revision tags: OPENBSD_6_6_BASE
# 1.170 19-Jul-2019 cheloha

ttysleep(): drop unused timeout parameter

All callers sleep indefinitely.

With help from visa@.

ok visa@, ratchov@, kn@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.169 14-May-2018 kettenis

Add support for register shift/io-width to the console code as well.

ok visa@, patrick@


# 1.168 02-May-2018 kettenis

Revert previous commit; the XR17V35X probe that was added accesses registers
that aren't guaranteed to be there and may even belong to a different device.
This triggers a fault on hppa machines like the C3000 for example.


# 1.167 15-Apr-2018 jcs

The Exar XR17V354 has 4 com ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

ok mlarkin deraadt


# 1.166 02-Apr-2018 kettenis

Add support for register shift/io-width. This allows us to support UARTs
that are mostly NS16550 compatible but use 32-bit instead of 8-bit registers
such as the Synopsys Designware UARTs found on many armv7, arm64 and amd64
SoCs.

tested by florian@, blum@
ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.165 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.164 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.163 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.162 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.161 04-Sep-2016 tedu

remove some more sparc remnants. ok deraadt


# 1.160 03-Sep-2016 jsg

de-zaurus com.c
"looks correct" deraadt@ guenther@ on an earlier rev


# 1.159 16-Aug-2016 kettenis

Only probe the UART type if sc_uarttype is set to COM_UART_UNKNOWN.
This allows glue drivers to set the type based on other information (such as
Oopen Firmware or device tree properties) without going through to risky
code paths.

ok deraadt@, visa@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.158 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.157 13-Apr-2014 deraadt

wrap a long line


Revision tags: OPENBSD_5_5_BASE
# 1.156 09-Dec-2013 deraadt

At resume, do not spin flushing characters in from the chip. There shouldn't
be any characters. If the chip is not actually there for some reason, we'd
be spinning so early in the resume sequence, we'd probably go mad trying to
find the reason..
ok kettenis
request: people with serial ports on their laptops, try to run a "cu" over
a suspend/resume cycle, and see if you see "input noise"


# 1.155 09-Dec-2013 deraadt

At suspend/resume time cope with timeouts, DTR on resume in a bus
bus-independent fashion.
ok kettenis


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.154 14-Feb-2013 kettenis

No need to treat amd64 specially; always return CN_HIGHPRI.

ok miod@


# 1.153 17-Oct-2012 deraadt

Narrow the spltty/splx pair in com_activate to only enclose the minimum
operation which requires it.


# 1.152 25-Aug-2012 kettenis

Better detection of the st16650 v1 (with the broken fifo). Gets rid of
false positives like the DUART on the MPC8347 as found on socppc.

ok deraadt@


# 1.151 25-Aug-2012 kettenis

Turns out the v445 isn't happy at all if we touch the registers that deal
with sleep mode. So skip the wakeup code as well if we are a serial console.
The port on the v445 almost certainly isn't a real st16650 and probably
doesn't implement sleep mode (perhaps someone cut the soft core down a bit
too much?). But it is indistinguishable from it, so we have to deal with it.

ok deraadt@


# 1.150 19-Aug-2012 kettenis

Skip putting a port in sleep mode when it is used as serial console. In that
case the kernel will still be using the port even after the last process closes
it. And on machines like the v445 the firmware won't be happy if the console
port is in sleep mode when the kernel reboots or halts.

ok miod@


Revision tags: OPENBSD_5_2_BASE
# 1.149 12-May-2012 kettenis

Remove unused variable.

ok mpi@, miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.148 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.147 22-May-2011 drahn

Fix a problem found where one SOC has a uart implementation that causes bus
errors if the fifo is read when the fifo is empty. Dont read an empty fifo.
ok deraaadt@ fgsch@


# 1.146 23-Mar-2011 fgsch

only read from the UART if there is something to read. fix beagle, otherwise
it will crash with 'External Non-Linefetch Abort (S)'.
similar diff provided by drahn@. tested by jasper@, deraadt@ ok.


Revision tags: OPENBSD_4_9_BASE
# 1.145 28-Aug-2010 miod

ansify function definitions, and constify a few arrays while there.
no functional change.


Revision tags: OPENBSD_4_8_BASE
# 1.144 07-Aug-2010 kettenis

Add resume support for serial consoles.

Tested by sthen@, ok deraadt@


# 1.143 06-Aug-2010 kettenis

Initial stab at making com@puc suspend and resume properly. Works fine
for using cu(1) between two OpenBSD machines. Probably doesn't work for
serial consoles but we don't support those on puc(4) anyway.

ok deraadt@


# 1.142 02-Jul-2010 nicm

Move common code for waking up writers on a tty into a function.

ok deraadt matthew millert


# 1.141 28-Jun-2010 deraadt

Allow tty drivers to request larger buffers at attach time using a
max-baud-rate hint. Adjust TTYHOG (the nearly full logic) to this new
situation. The larger buffers are required by the very high speed
KDDI devices in Japan (CF com, or USB ucom) so those are the only two
drivers which currently ask for a larger buffer size.
ok yasuoka miod


# 1.140 28-Jun-2010 ckuethe

Use a more moderate fifo trigger level (4) for moderately quick
(sub-38400) port speeds. Inspired by netbsd. ok fgsch krw deraadt miod


# 1.139 26-Jun-2010 guenther

Don't #include <sys/user.h> into files that don't need the stuff
it defines. In some cases, this means pulling in uvm.h or pcb.h
instead, but most of the inclusions were just noise. Tested on
alpha, amd64, armish, hppa, i386, macpcc, sgi, sparc64, and vax,
mostly by krw and naddy.
ok krw@


# 1.138 12-Apr-2010 tedu

Some of the line disciplines want to check for suser. Better to pass them
a process instead of using curproc. ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.137 09-Nov-2009 nicm

Every selwakeup() should have a matching KNOTE() (even if kqueue isn't
supported it doesn't do any harm), so put the KNOTE() in selwakeup() itself and
remove it from any occurences where both are used, except one for kqueue itself
and one in sys_pipe.c (where the selwakeup is under a PIPE_SEL flag).

Based on a diff from tedu.

ok deraadt


# 1.136 04-Nov-2009 kettenis

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@


# 1.135 01-Nov-2009 nicm

Call selwakeup()/KNOTE() even if the queue has emptied completely.

ok miod


# 1.134 31-Oct-2009 fgsch

Use suser when possible. Suggested by miod@.
miod@ deraadt@ ok.


# 1.133 31-Oct-2009 deraadt

Add missing KNOTE() calls after selwakeup(), until we decide if the KNOTE()
calls can go directly into selwakeup() safely
long discussion with nicm, murmers of consent from tedu and miod, noone
else seems to care of kqueue is busted as long as it makes their sockets
move data fast... pretty sad.


# 1.132 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.131 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.130 23-Nov-2008 deraadt

pccom can finally die; ok kettenis dlg drahn, tested by okan


# 1.129 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


Revision tags: OPENBSD_4_4_BASE
# 1.128 08-Jun-2008 kettenis

Make serial console on non-primary ports work to on i386.

tested by jbg@, "it is right" deraadt@


# 1.127 25-Apr-2008 dlg

the code that parses arguments from the boot loader on amd64 wasnt checking
what type of console was specified, so when a glass console was used it was
still configuring serial bits. this makes it so serial config only occurs
for serial console devices.

found by jolan@, thib@, and maybe sthen@
sorry guys


# 1.126 24-Apr-2008 jsing

MD_ISA_IOT is not defined anywhere so get rid of it.

Spotted by drahn@, ok dlg@


# 1.125 24-Apr-2008 jsing

Keep order of "#if defined..." consistent.

ok dlg@


# 1.124 24-Apr-2008 jsing

Clean up comments.


# 1.123 24-Apr-2008 jsing

Cleanup serial console handling and remove some of the MD code from com.c.
Specify the serial configuration from within the MD code, rather than
passing things via macros. This will allow other platforms to more readily
change the serial console configuration.

Committing this so it actually gets tested.

ok dlg@


# 1.122 09-Apr-2008 deraadt

Increase buffer size sent to the fifo, and clamp the size correctly.
Scrub the buffer afterwards, too


Revision tags: OPENBSD_4_3_BASE
# 1.121 23-Jan-2008 jsing

Cleanup cn_pri. Change constants to more meaningful names, rather than
the hp300 related ones currently in use. CN_NORMAL becomes CN_LOWPRI,
CN_INTERNAL becomes CN_MIDPRI and CN_REMOTE becomes CN_HIGHPRI.

ok miod@


# 1.120 12-Jan-2008 miod

Make comconsrate initialized to TTYDEF_SPEED at compile-time, for ports
which need to setup the chip before comcnattach() is invoked.


# 1.119 08-Jan-2008 dlg

the rsc-console on the v880 operates at 115200, not the 9600 we think we
have to force all console devices to. this change passes the right speed
to the com code, and continues to use it when the device is opened as the
console device.

figured out by kettenis@
ok kettenis@ miod@


# 1.118 22-Aug-2007 jasper

fix compilation with KDGB
from Nicholas Marriott

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.117 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.116 22-Jun-2007 jasper

ansify/de-register
no binary change


# 1.115 08-May-2007 deraadt

backout while the amd64 puc situation is rethought


# 1.114 08-May-2007 deraadt

move com_activate() to where it belongs


# 1.113 08-May-2007 deraadt

put more foo_detach() routines where they are used


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.112 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.111 27-Apr-2006 deraadt

2 lines of code in most drivers, to do the timestamping; ok miod kettenis


# 1.110 27-Mar-2006 deraadt

in detach, mark device with COM_SW_DEAD, so that close() will not go
tapping additional registes. allows it to work on macppc, where doing
such a tap after unplug is very bad. drahn helped fkr@bytemine.de
ok miod and drahn


Revision tags: OPENBSD_3_9_BASE
# 1.109 01-Jan-2006 miod

Let cons_init() and cons_init_bell() initialize the whole consdev structure,
thus removing the need for drivers to initialize cn_pri to CN_DEAD when
hardware probe fails.


# 1.108 21-Nov-2005 millert

Move contents of sys/select.h to sys/selinfo.h in preparation for a
userland-visible sys/select.h. Consistent with what Net and Free do.
OK deraadt@, tested with full ports build by naddy@.


# 1.107 11-Nov-2005 fgsch

fix kgdb compilation; input and ok miod@.


# 1.106 26-Sep-2005 miod

Share com probe code between com and pccom; allows us to get rid of awkward
code duplication in cardbus, pcmcia and puc attachments.

Joint effort with fgs@; blessed deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.105 18-Jul-2005 deraadt

fix sparc64 console; same diff as miod


# 1.104 18-Jul-2005 deraadt

COM_CONSOLE & DDB fix


# 1.103 17-Jul-2005 miod

Allow the console support code not to be compiled in; this will be
necessary for and only used on sparc, shortly.

Reluctantely ok deraadt@


# 1.102 11-Jul-2005 uwe

Enable IR receive mode only for infrared capable PXA2x0 UARTs. Normal
reception is blocked while the IR receiver or transmitter is enabled.

Also enable the PXA2x0 UART before clearing the FIFO (suggested by
drahn@ some time ago), and disable the UART in compwroff().

ok deraadt@


# 1.101 02-Jul-2005 uwe

xscale UART FIFOs are 32 bytes deep; found by deraadt@


# 1.100 27-May-2005 uwe

- Merge changes from pxacom back into the common com driver.

Changes to the common com driver (partly from NetBSD):
- Multiply before divide in comspeed() to avoid overflow (from NetBSD).
- Don't call getc() and send -1 if the output queue is empty.
- Take UART clock frequency as a parameter instead of using COM_FREQ.

ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.99 20-Oct-2004 pefo

Use bus_addr_t instead of int for port address/offset, ok mickey


Revision tags: OPENBSD_3_6_BASE
# 1.98 09-Aug-2004 pefo

remove old arc stuff and add sgi support.
ok mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.97 30-May-2004 deraadt

serial console hack from tom. who, after having been told a few times
to commit it, has not. what is going on guys?


# 1.96 03-May-2004 drahn

Remove OpenBSD/pegaos, this has been announced before but delayed until
the tree was stable. No point in code supporting a company which screws
its employees being in the OpenBSD tree.


Revision tags: OPENBSD_3_5_BASE
# 1.95 31-Oct-2003 drahn

Use isa iot for pegasos com console attachment, perhaps this could
be adopted MI?


# 1.94 03-Oct-2003 miod

Merge tty_attach() in ttymalloc() and tty_detach() in ttyfree(). The need for
separate tty registering is gone now that sparc has switched to wscons, and
this makes the code less error-prone.

Also, remove tests for ttymalloc() failure, since it uses M_WAITOK.

ok millert@ deraadt@, tested by various people as well besides me...


# 1.93 23-Sep-2003 millert

Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater
poll(2) functionality instead of emulating it via the select backend.
Adapted from NetBSD and including some changes from FreeBSD.
Tested by many, deraadt@ OK


Revision tags: OPENBSD_3_4_BASE
# 1.92 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.91 15-Jul-2003 jason

move prototype for com_raisedtr() to comvar.h (just like pccom).


# 1.90 03-Jun-2003 deraadt

terms 3 & 4 cleanup based on "terms" file


# 1.89 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.88 19-Dec-2002 mickey

comparam() does not need an spltty() for it, already called there.
time-bound loops in com_common_cnputc() and lower to spltty(),
which i guess is left from times when timeouts were processed at splhigh().
jason@ tested and ok, art@ ok


Revision tags: UBC_SYNC_B
# 1.87 17-Oct-2002 art

ifndef __HAVE_GENERIC_SOFT_INTERRUPTS leaved a label without a statement after it. Fix.


Revision tags: OPENBSD_3_2_BASE
# 1.86 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.85 11-Jun-2002 miod

com.c is not a block device, no bdev_decl() for it.


Revision tags: OPENBSD_3_1_BASE
# 1.84 09-Apr-2002 pefo

Don't enable interrupts until an open() is done. Until then the driver
is not handling them and may throw the kernel into a spurious interrupt
loop. ok art@


# 1.83 14-Mar-2002 millert

First round of __P removal in sys


# 1.82 14-Mar-2002 jason

compare pointers with NULL not 0


# 1.81 05-Feb-2002 mickey

restore CN_REMOTE priority, as it always was there.
anyway, only i386 uses that path and only if forced anyway.
also do not do comprobe1() on hppa since that hoses the port.


# 1.80 30-Jan-2002 nordin

Move SET/CLR/ISSET macros to param.h. fgsch@ and millert@ ok


# 1.79 25-Jan-2002 mickey

CONADDR is defined elsewhere for hppa


# 1.78 23-Jan-2002 ericj

oops, make the kgdb var's non-static


# 1.77 23-Jan-2002 ericj

allow this to compile with KGDB


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.76 05-Oct-2001 mickey

branches: 1.76.4;
restore some of that dead code needed for dev/cons functionality


# 1.75 02-Oct-2001 art

#ifdef FOO works much better when FOO isn't misspelled.


# 1.74 30-Sep-2001 art

Enable break interrupt earlier.


# 1.73 30-Sep-2001 art

Next round of cleanups.
- some KNF.
- disable interrupts earlier in attach.
- give it some more time in attach to finish earlier output.
- explicit bus_space_barrier in comcnputc.
- dead code.


# 1.72 30-Sep-2001 art

Remove dead code.


# 1.71 30-Sep-2001 art

Remove the COM_HAYESP code. It doesn't appear to have been ever used and
it's very intrusive and makes the code less readable.


# 1.70 30-Sep-2001 art

Move out the com at commulti attachment into an ownfile.
Same story as isapnp - not tested because i386 uses pccom.


# 1.69 30-Sep-2001 art

Move out com at isapnp attachment into an own file.
Not tested because the only system with isapnp is i386 and i386 uses pccom.


# 1.68 29-Sep-2001 art

Next step in making the com driver improvable.
Split out the com at isa attachment into its own file.


# 1.67 29-Sep-2001 art

- compoll is now scheduled once for every sc instead of just one timeout for
all ports and looping over them.
- support for generic soft interrupts.


# 1.66 27-Sep-2001 art

Simplify comstart a bit.


# 1.65 27-Sep-2001 millert

Enable #if 0'd code in comcnputc() so serial console works correctly;
art@openbsd.org


# 1.64 27-Sep-2001 art

Split out comattach that does isa and isapnp attachment and initialization,
into comattach that does the isa stuff and com_attach_subr that does the
init.


Revision tags: OPENBSD_2_9_BASE
# 1.63 17-Apr-2001 aaron

Implement cnbell(), an optional entrypoint that rings the console bell; from
NetBSD. deraadt@ ok


# 1.62 15-Mar-2001 art

Put back new timeouts. This time with correct timeout for compoll.


# 1.61 15-Mar-2001 deraadt

typo


# 1.60 15-Mar-2001 art

back out new timeouts until I find out why they break alpha.


# 1.59 15-Mar-2001 deraadt

support puc devices with higher speeds (not tested yet)


# 1.58 13-Mar-2001 mickey

new timeouts


# 1.57 24-Jan-2001 hugh

KGDB for i386 from NetBSD via niklas, with tweaks and accommodations.
Tested by various, vetted by mickey & theo.


# 1.56 08-Nov-2000 art

Add comcnattach that does the basic steps needed to attach
a com as a serial console. (idea from NetBSD).

If cn_tab->cn_dev == NODEV, try to find comopen in cdevsw and set cn_dev
to the right device.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE SMP_BASE
# 1.55 27-Jan-2000 mickey

branches: 1.55.2;
isa-avoidance


# 1.54 11-Jan-2000 mickey

a few ifdef accomodations for hppa, also a few knf spaces


Revision tags: kame_19991208
# 1.53 28-Nov-1999 downsj

Enable TI16750 UART support.


# 1.52 09-Nov-1999 rahnds

in the ifdef POWERPC section, do use ppc, not p4e, for the iohandle
for the console configuration.


# 1.51 26-Oct-1999 downsj

This file has my code in it, attach my copyright.


Revision tags: OPENBSD_2_6_BASE
# 1.50 08-Aug-1999 niklas

pasto from pccom.c


# 1.49 08-Aug-1999 niklas

revert function accidentally committed


# 1.48 08-Aug-1999 niklas

Detach support for com; NetBSD and me


# 1.47 26-Jul-1999 niklas

Move over the ISA PnP support from pccom.c to com.c


# 1.46 26-Jul-1999 niklas

fix my last commit where I committed more than intended


# 1.45 26-Jul-1999 niklas

Remove obsolete detach code that has been dead for very long


# 1.44 25-Jun-1999 rees

Don't turn off uart when closing cua device if tty is waiting.
Instead just drop dtr briefly.


Revision tags: OPENBSD_2_5_BASE
# 1.43 09-Feb-1999 rees

Fix cua device to not block on open.
Turn off chip (and dtr) on interrupted open.


# 1.42 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.41 20-Sep-1998 rahnds

Powerpc port uses com.c not just power4e.


# 1.40 18-Aug-1998 pefo

Remove clearing of interrupt after character output in cnputci(). Clearing
the int will make the tty stop if output is currently active.


# 1.39 07-Aug-1998 pefo

com.c needs to know about mem mapped ports in ppc systems.

ncr.c and if_de.c needs some hooks for systems with ncr and dec
ether chips on the motherboard that runs on odd clocks and doesn't
support a srom. srom is emulated in machine dependent code.

big endian support for ncr and dec ether finished. the 21040
have some more coding requirements if it is to run BE since
it does not have the descriptor endian swap configuration bit.


Revision tags: OPENBSD_2_3_BASE
# 1.38 23-Feb-1998 downsj

New probe routine and support for ST16650.

Compiles, but completely untested.


# 1.37 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


Revision tags: OPENBSD_2_2_BASE
# 1.36 03-Sep-1997 deraadt

fix cua/tty locking


# 1.35 07-Jul-1997 niklas

Removed an unused arg


Revision tags: OPENBSD_2_1_BASE
# 1.34 10-Apr-1997 pefo

Need to separate i/o and mem on mips


# 1.33 17-Mar-1997 pefo

Serial console trouble again...


# 1.32 12-Mar-1997 pefo

The stupid "use console before configured" scheeme strikes again :-)


# 1.31 06-Mar-1997 tholo

Initial implementation of support for calling hardpps() on carrier enable


# 1.30 10-Dec-1996 deraadt

the real changes by niklas... I did not merge correctly


# 1.29 10-Dec-1996 deraadt

clr TS_WOPEN if bailing on cua opens
As well, at this point I've also done fancy cvs repository mangling to
ensure that the com* files in sys/dev/ic maintain the history we had
before. (Yes, I cleaned up the 2.0 tags too..)


# 1.28 29-Nov-1996 niklas

Missing pieces of new bus.h that CVS lost behind my back


# 1.27 12-Nov-1996 niklas

s/bus.h/bus.old.h/ to make the transit to the bus_space bus.h an easy road
possibly taken in small steps


# 1.26 09-Nov-1996 tholo

Break shall be handled as data == 0 and FE bit set; from Theo


# 1.25 30-Oct-1996 niklas

cominit is used from the outside (the alpha port)


# 1.24 22-Oct-1996 downsj

patch com speed initialization


# 1.23 16-Oct-1996 deraadt

contextual usage


# 1.22 16-Oct-1996 deraadt

unused variables


# 1.21 29-Aug-1996 deraadt

sunos-like cua behaviour; inspired by budd@cs.bu.edu in his scn.c


# 1.20 02-Jul-1996 downsj

better FIFO enabling code; netbsd pr#2574, cliff@wport.com


# 1.19 24-Jun-1996 pefo

pica changes backed out. does not belong here


# 1.18 22-Jun-1996 pefo

Pica bus support added


# 1.17 10-Jun-1996 niklas

Some cleanup for -Wall -Wstrict-prototypes


# 1.16 10-Jun-1996 deraadt

tty_attach()


# 1.15 26-May-1996 deraadt

sync 0521


# 1.14 10-May-1996 deraadt

proto change


# 1.13 07-May-1996 deraadt

sync with 0504 -- prototypes and bus.h


# 1.12 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.11 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.10 18-Apr-1996 niklas

NetBSD 960317 merge


# 1.9 20-Mar-1996 mickey

Fix back wrong patches.


# 1.8 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.7 08-Mar-1996 niklas

From NetBSD: merge of 960217


# 1.6 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.5 16-Jan-1996 hvozda

Last of the glue and devices for for PCMCIA support from Stefan Grefen
<grefen@convex.com> with modifications by John Kohl <jtk@kolvir.blrc.ma.us>


# 1.4 03-Jan-1996 deraadt

Patches to use Hayes ESP with com.c; from banshee@gabriella.resort.com;
netbsd pr#1865. the ESP card code is always enabled -- we will have to
see if that fails on any chipsets.


# 1.3 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.


# 1.2 15-Dec-1995 deraadt

update from netbsd


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.172 09-Mar-2020 yasuoka

Update the console device always when attaching the real device
driver. The information by the driver is supposed more reliable than
the information which was set up earlier.

ok patrick


# 1.171 05-Feb-2020 mpi

Detach timeouts and the softint handler before freeing memory.

As more and more teardown functions include barriers, or any kind of
context change, it is unsafe to continue to assume that such code paths
are atomic. So a good practise is to only free descriptor when we're
sure that no other context can access them.

Found while looking at visa@'s ttkqflush() replacement diff. The same
pattern is present in many USB drivers as found with Peter Stuge.

ok visa@


Revision tags: OPENBSD_6_6_BASE
# 1.170 19-Jul-2019 cheloha

ttysleep(): drop unused timeout parameter

All callers sleep indefinitely.

With help from visa@.

ok visa@, ratchov@, kn@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.169 14-May-2018 kettenis

Add support for register shift/io-width to the console code as well.

ok visa@, patrick@


# 1.168 02-May-2018 kettenis

Revert previous commit; the XR17V35X probe that was added accesses registers
that aren't guaranteed to be there and may even belong to a different device.
This triggers a fault on hppa machines like the C3000 for example.


# 1.167 15-Apr-2018 jcs

The Exar XR17V354 has 4 com ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

ok mlarkin deraadt


# 1.166 02-Apr-2018 kettenis

Add support for register shift/io-width. This allows us to support UARTs
that are mostly NS16550 compatible but use 32-bit instead of 8-bit registers
such as the Synopsys Designware UARTs found on many armv7, arm64 and amd64
SoCs.

tested by florian@, blum@
ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.165 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.164 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.163 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.162 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.161 04-Sep-2016 tedu

remove some more sparc remnants. ok deraadt


# 1.160 03-Sep-2016 jsg

de-zaurus com.c
"looks correct" deraadt@ guenther@ on an earlier rev


# 1.159 16-Aug-2016 kettenis

Only probe the UART type if sc_uarttype is set to COM_UART_UNKNOWN.
This allows glue drivers to set the type based on other information (such as
Oopen Firmware or device tree properties) without going through to risky
code paths.

ok deraadt@, visa@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.158 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.157 13-Apr-2014 deraadt

wrap a long line


Revision tags: OPENBSD_5_5_BASE
# 1.156 09-Dec-2013 deraadt

At resume, do not spin flushing characters in from the chip. There shouldn't
be any characters. If the chip is not actually there for some reason, we'd
be spinning so early in the resume sequence, we'd probably go mad trying to
find the reason..
ok kettenis
request: people with serial ports on their laptops, try to run a "cu" over
a suspend/resume cycle, and see if you see "input noise"


# 1.155 09-Dec-2013 deraadt

At suspend/resume time cope with timeouts, DTR on resume in a bus
bus-independent fashion.
ok kettenis


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.154 14-Feb-2013 kettenis

No need to treat amd64 specially; always return CN_HIGHPRI.

ok miod@


# 1.153 17-Oct-2012 deraadt

Narrow the spltty/splx pair in com_activate to only enclose the minimum
operation which requires it.


# 1.152 25-Aug-2012 kettenis

Better detection of the st16650 v1 (with the broken fifo). Gets rid of
false positives like the DUART on the MPC8347 as found on socppc.

ok deraadt@


# 1.151 25-Aug-2012 kettenis

Turns out the v445 isn't happy at all if we touch the registers that deal
with sleep mode. So skip the wakeup code as well if we are a serial console.
The port on the v445 almost certainly isn't a real st16650 and probably
doesn't implement sleep mode (perhaps someone cut the soft core down a bit
too much?). But it is indistinguishable from it, so we have to deal with it.

ok deraadt@


# 1.150 19-Aug-2012 kettenis

Skip putting a port in sleep mode when it is used as serial console. In that
case the kernel will still be using the port even after the last process closes
it. And on machines like the v445 the firmware won't be happy if the console
port is in sleep mode when the kernel reboots or halts.

ok miod@


Revision tags: OPENBSD_5_2_BASE
# 1.149 12-May-2012 kettenis

Remove unused variable.

ok mpi@, miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.148 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.147 22-May-2011 drahn

Fix a problem found where one SOC has a uart implementation that causes bus
errors if the fifo is read when the fifo is empty. Dont read an empty fifo.
ok deraaadt@ fgsch@


# 1.146 23-Mar-2011 fgsch

only read from the UART if there is something to read. fix beagle, otherwise
it will crash with 'External Non-Linefetch Abort (S)'.
similar diff provided by drahn@. tested by jasper@, deraadt@ ok.


Revision tags: OPENBSD_4_9_BASE
# 1.145 28-Aug-2010 miod

ansify function definitions, and constify a few arrays while there.
no functional change.


Revision tags: OPENBSD_4_8_BASE
# 1.144 07-Aug-2010 kettenis

Add resume support for serial consoles.

Tested by sthen@, ok deraadt@


# 1.143 06-Aug-2010 kettenis

Initial stab at making com@puc suspend and resume properly. Works fine
for using cu(1) between two OpenBSD machines. Probably doesn't work for
serial consoles but we don't support those on puc(4) anyway.

ok deraadt@


# 1.142 02-Jul-2010 nicm

Move common code for waking up writers on a tty into a function.

ok deraadt matthew millert


# 1.141 28-Jun-2010 deraadt

Allow tty drivers to request larger buffers at attach time using a
max-baud-rate hint. Adjust TTYHOG (the nearly full logic) to this new
situation. The larger buffers are required by the very high speed
KDDI devices in Japan (CF com, or USB ucom) so those are the only two
drivers which currently ask for a larger buffer size.
ok yasuoka miod


# 1.140 28-Jun-2010 ckuethe

Use a more moderate fifo trigger level (4) for moderately quick
(sub-38400) port speeds. Inspired by netbsd. ok fgsch krw deraadt miod


# 1.139 26-Jun-2010 guenther

Don't #include <sys/user.h> into files that don't need the stuff
it defines. In some cases, this means pulling in uvm.h or pcb.h
instead, but most of the inclusions were just noise. Tested on
alpha, amd64, armish, hppa, i386, macpcc, sgi, sparc64, and vax,
mostly by krw and naddy.
ok krw@


# 1.138 12-Apr-2010 tedu

Some of the line disciplines want to check for suser. Better to pass them
a process instead of using curproc. ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.137 09-Nov-2009 nicm

Every selwakeup() should have a matching KNOTE() (even if kqueue isn't
supported it doesn't do any harm), so put the KNOTE() in selwakeup() itself and
remove it from any occurences where both are used, except one for kqueue itself
and one in sys_pipe.c (where the selwakeup is under a PIPE_SEL flag).

Based on a diff from tedu.

ok deraadt


# 1.136 04-Nov-2009 kettenis

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@


# 1.135 01-Nov-2009 nicm

Call selwakeup()/KNOTE() even if the queue has emptied completely.

ok miod


# 1.134 31-Oct-2009 fgsch

Use suser when possible. Suggested by miod@.
miod@ deraadt@ ok.


# 1.133 31-Oct-2009 deraadt

Add missing KNOTE() calls after selwakeup(), until we decide if the KNOTE()
calls can go directly into selwakeup() safely
long discussion with nicm, murmers of consent from tedu and miod, noone
else seems to care of kqueue is busted as long as it makes their sockets
move data fast... pretty sad.


# 1.132 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.131 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.130 23-Nov-2008 deraadt

pccom can finally die; ok kettenis dlg drahn, tested by okan


# 1.129 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


Revision tags: OPENBSD_4_4_BASE
# 1.128 08-Jun-2008 kettenis

Make serial console on non-primary ports work to on i386.

tested by jbg@, "it is right" deraadt@


# 1.127 25-Apr-2008 dlg

the code that parses arguments from the boot loader on amd64 wasnt checking
what type of console was specified, so when a glass console was used it was
still configuring serial bits. this makes it so serial config only occurs
for serial console devices.

found by jolan@, thib@, and maybe sthen@
sorry guys


# 1.126 24-Apr-2008 jsing

MD_ISA_IOT is not defined anywhere so get rid of it.

Spotted by drahn@, ok dlg@


# 1.125 24-Apr-2008 jsing

Keep order of "#if defined..." consistent.

ok dlg@


# 1.124 24-Apr-2008 jsing

Clean up comments.


# 1.123 24-Apr-2008 jsing

Cleanup serial console handling and remove some of the MD code from com.c.
Specify the serial configuration from within the MD code, rather than
passing things via macros. This will allow other platforms to more readily
change the serial console configuration.

Committing this so it actually gets tested.

ok dlg@


# 1.122 09-Apr-2008 deraadt

Increase buffer size sent to the fifo, and clamp the size correctly.
Scrub the buffer afterwards, too


Revision tags: OPENBSD_4_3_BASE
# 1.121 23-Jan-2008 jsing

Cleanup cn_pri. Change constants to more meaningful names, rather than
the hp300 related ones currently in use. CN_NORMAL becomes CN_LOWPRI,
CN_INTERNAL becomes CN_MIDPRI and CN_REMOTE becomes CN_HIGHPRI.

ok miod@


# 1.120 12-Jan-2008 miod

Make comconsrate initialized to TTYDEF_SPEED at compile-time, for ports
which need to setup the chip before comcnattach() is invoked.


# 1.119 08-Jan-2008 dlg

the rsc-console on the v880 operates at 115200, not the 9600 we think we
have to force all console devices to. this change passes the right speed
to the com code, and continues to use it when the device is opened as the
console device.

figured out by kettenis@
ok kettenis@ miod@


# 1.118 22-Aug-2007 jasper

fix compilation with KDGB
from Nicholas Marriott

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.117 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.116 22-Jun-2007 jasper

ansify/de-register
no binary change


# 1.115 08-May-2007 deraadt

backout while the amd64 puc situation is rethought


# 1.114 08-May-2007 deraadt

move com_activate() to where it belongs


# 1.113 08-May-2007 deraadt

put more foo_detach() routines where they are used


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.112 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.111 27-Apr-2006 deraadt

2 lines of code in most drivers, to do the timestamping; ok miod kettenis


# 1.110 27-Mar-2006 deraadt

in detach, mark device with COM_SW_DEAD, so that close() will not go
tapping additional registes. allows it to work on macppc, where doing
such a tap after unplug is very bad. drahn helped fkr@bytemine.de
ok miod and drahn


Revision tags: OPENBSD_3_9_BASE
# 1.109 01-Jan-2006 miod

Let cons_init() and cons_init_bell() initialize the whole consdev structure,
thus removing the need for drivers to initialize cn_pri to CN_DEAD when
hardware probe fails.


# 1.108 21-Nov-2005 millert

Move contents of sys/select.h to sys/selinfo.h in preparation for a
userland-visible sys/select.h. Consistent with what Net and Free do.
OK deraadt@, tested with full ports build by naddy@.


# 1.107 11-Nov-2005 fgsch

fix kgdb compilation; input and ok miod@.


# 1.106 26-Sep-2005 miod

Share com probe code between com and pccom; allows us to get rid of awkward
code duplication in cardbus, pcmcia and puc attachments.

Joint effort with fgs@; blessed deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.105 18-Jul-2005 deraadt

fix sparc64 console; same diff as miod


# 1.104 18-Jul-2005 deraadt

COM_CONSOLE & DDB fix


# 1.103 17-Jul-2005 miod

Allow the console support code not to be compiled in; this will be
necessary for and only used on sparc, shortly.

Reluctantely ok deraadt@


# 1.102 11-Jul-2005 uwe

Enable IR receive mode only for infrared capable PXA2x0 UARTs. Normal
reception is blocked while the IR receiver or transmitter is enabled.

Also enable the PXA2x0 UART before clearing the FIFO (suggested by
drahn@ some time ago), and disable the UART in compwroff().

ok deraadt@


# 1.101 02-Jul-2005 uwe

xscale UART FIFOs are 32 bytes deep; found by deraadt@


# 1.100 27-May-2005 uwe

- Merge changes from pxacom back into the common com driver.

Changes to the common com driver (partly from NetBSD):
- Multiply before divide in comspeed() to avoid overflow (from NetBSD).
- Don't call getc() and send -1 if the output queue is empty.
- Take UART clock frequency as a parameter instead of using COM_FREQ.

ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.99 20-Oct-2004 pefo

Use bus_addr_t instead of int for port address/offset, ok mickey


Revision tags: OPENBSD_3_6_BASE
# 1.98 09-Aug-2004 pefo

remove old arc stuff and add sgi support.
ok mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.97 30-May-2004 deraadt

serial console hack from tom. who, after having been told a few times
to commit it, has not. what is going on guys?


# 1.96 03-May-2004 drahn

Remove OpenBSD/pegaos, this has been announced before but delayed until
the tree was stable. No point in code supporting a company which screws
its employees being in the OpenBSD tree.


Revision tags: OPENBSD_3_5_BASE
# 1.95 31-Oct-2003 drahn

Use isa iot for pegasos com console attachment, perhaps this could
be adopted MI?


# 1.94 03-Oct-2003 miod

Merge tty_attach() in ttymalloc() and tty_detach() in ttyfree(). The need for
separate tty registering is gone now that sparc has switched to wscons, and
this makes the code less error-prone.

Also, remove tests for ttymalloc() failure, since it uses M_WAITOK.

ok millert@ deraadt@, tested by various people as well besides me...


# 1.93 23-Sep-2003 millert

Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater
poll(2) functionality instead of emulating it via the select backend.
Adapted from NetBSD and including some changes from FreeBSD.
Tested by many, deraadt@ OK


Revision tags: OPENBSD_3_4_BASE
# 1.92 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.91 15-Jul-2003 jason

move prototype for com_raisedtr() to comvar.h (just like pccom).


# 1.90 03-Jun-2003 deraadt

terms 3 & 4 cleanup based on "terms" file


# 1.89 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.88 19-Dec-2002 mickey

comparam() does not need an spltty() for it, already called there.
time-bound loops in com_common_cnputc() and lower to spltty(),
which i guess is left from times when timeouts were processed at splhigh().
jason@ tested and ok, art@ ok


Revision tags: UBC_SYNC_B
# 1.87 17-Oct-2002 art

ifndef __HAVE_GENERIC_SOFT_INTERRUPTS leaved a label without a statement after it. Fix.


Revision tags: OPENBSD_3_2_BASE
# 1.86 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.85 11-Jun-2002 miod

com.c is not a block device, no bdev_decl() for it.


Revision tags: OPENBSD_3_1_BASE
# 1.84 09-Apr-2002 pefo

Don't enable interrupts until an open() is done. Until then the driver
is not handling them and may throw the kernel into a spurious interrupt
loop. ok art@


# 1.83 14-Mar-2002 millert

First round of __P removal in sys


# 1.82 14-Mar-2002 jason

compare pointers with NULL not 0


# 1.81 05-Feb-2002 mickey

restore CN_REMOTE priority, as it always was there.
anyway, only i386 uses that path and only if forced anyway.
also do not do comprobe1() on hppa since that hoses the port.


# 1.80 30-Jan-2002 nordin

Move SET/CLR/ISSET macros to param.h. fgsch@ and millert@ ok


# 1.79 25-Jan-2002 mickey

CONADDR is defined elsewhere for hppa


# 1.78 23-Jan-2002 ericj

oops, make the kgdb var's non-static


# 1.77 23-Jan-2002 ericj

allow this to compile with KGDB


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.76 05-Oct-2001 mickey

branches: 1.76.4;
restore some of that dead code needed for dev/cons functionality


# 1.75 02-Oct-2001 art

#ifdef FOO works much better when FOO isn't misspelled.


# 1.74 30-Sep-2001 art

Enable break interrupt earlier.


# 1.73 30-Sep-2001 art

Next round of cleanups.
- some KNF.
- disable interrupts earlier in attach.
- give it some more time in attach to finish earlier output.
- explicit bus_space_barrier in comcnputc.
- dead code.


# 1.72 30-Sep-2001 art

Remove dead code.


# 1.71 30-Sep-2001 art

Remove the COM_HAYESP code. It doesn't appear to have been ever used and
it's very intrusive and makes the code less readable.


# 1.70 30-Sep-2001 art

Move out the com at commulti attachment into an ownfile.
Same story as isapnp - not tested because i386 uses pccom.


# 1.69 30-Sep-2001 art

Move out com at isapnp attachment into an own file.
Not tested because the only system with isapnp is i386 and i386 uses pccom.


# 1.68 29-Sep-2001 art

Next step in making the com driver improvable.
Split out the com at isa attachment into its own file.


# 1.67 29-Sep-2001 art

- compoll is now scheduled once for every sc instead of just one timeout for
all ports and looping over them.
- support for generic soft interrupts.


# 1.66 27-Sep-2001 art

Simplify comstart a bit.


# 1.65 27-Sep-2001 millert

Enable #if 0'd code in comcnputc() so serial console works correctly;
art@openbsd.org


# 1.64 27-Sep-2001 art

Split out comattach that does isa and isapnp attachment and initialization,
into comattach that does the isa stuff and com_attach_subr that does the
init.


Revision tags: OPENBSD_2_9_BASE
# 1.63 17-Apr-2001 aaron

Implement cnbell(), an optional entrypoint that rings the console bell; from
NetBSD. deraadt@ ok


# 1.62 15-Mar-2001 art

Put back new timeouts. This time with correct timeout for compoll.


# 1.61 15-Mar-2001 deraadt

typo


# 1.60 15-Mar-2001 art

back out new timeouts until I find out why they break alpha.


# 1.59 15-Mar-2001 deraadt

support puc devices with higher speeds (not tested yet)


# 1.58 13-Mar-2001 mickey

new timeouts


# 1.57 24-Jan-2001 hugh

KGDB for i386 from NetBSD via niklas, with tweaks and accommodations.
Tested by various, vetted by mickey & theo.


# 1.56 08-Nov-2000 art

Add comcnattach that does the basic steps needed to attach
a com as a serial console. (idea from NetBSD).

If cn_tab->cn_dev == NODEV, try to find comopen in cdevsw and set cn_dev
to the right device.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE SMP_BASE
# 1.55 27-Jan-2000 mickey

branches: 1.55.2;
isa-avoidance


# 1.54 11-Jan-2000 mickey

a few ifdef accomodations for hppa, also a few knf spaces


Revision tags: kame_19991208
# 1.53 28-Nov-1999 downsj

Enable TI16750 UART support.


# 1.52 09-Nov-1999 rahnds

in the ifdef POWERPC section, do use ppc, not p4e, for the iohandle
for the console configuration.


# 1.51 26-Oct-1999 downsj

This file has my code in it, attach my copyright.


Revision tags: OPENBSD_2_6_BASE
# 1.50 08-Aug-1999 niklas

pasto from pccom.c


# 1.49 08-Aug-1999 niklas

revert function accidentally committed


# 1.48 08-Aug-1999 niklas

Detach support for com; NetBSD and me


# 1.47 26-Jul-1999 niklas

Move over the ISA PnP support from pccom.c to com.c


# 1.46 26-Jul-1999 niklas

fix my last commit where I committed more than intended


# 1.45 26-Jul-1999 niklas

Remove obsolete detach code that has been dead for very long


# 1.44 25-Jun-1999 rees

Don't turn off uart when closing cua device if tty is waiting.
Instead just drop dtr briefly.


Revision tags: OPENBSD_2_5_BASE
# 1.43 09-Feb-1999 rees

Fix cua device to not block on open.
Turn off chip (and dtr) on interrupted open.


# 1.42 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.41 20-Sep-1998 rahnds

Powerpc port uses com.c not just power4e.


# 1.40 18-Aug-1998 pefo

Remove clearing of interrupt after character output in cnputci(). Clearing
the int will make the tty stop if output is currently active.


# 1.39 07-Aug-1998 pefo

com.c needs to know about mem mapped ports in ppc systems.

ncr.c and if_de.c needs some hooks for systems with ncr and dec
ether chips on the motherboard that runs on odd clocks and doesn't
support a srom. srom is emulated in machine dependent code.

big endian support for ncr and dec ether finished. the 21040
have some more coding requirements if it is to run BE since
it does not have the descriptor endian swap configuration bit.


Revision tags: OPENBSD_2_3_BASE
# 1.38 23-Feb-1998 downsj

New probe routine and support for ST16650.

Compiles, but completely untested.


# 1.37 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


Revision tags: OPENBSD_2_2_BASE
# 1.36 03-Sep-1997 deraadt

fix cua/tty locking


# 1.35 07-Jul-1997 niklas

Removed an unused arg


Revision tags: OPENBSD_2_1_BASE
# 1.34 10-Apr-1997 pefo

Need to separate i/o and mem on mips


# 1.33 17-Mar-1997 pefo

Serial console trouble again...


# 1.32 12-Mar-1997 pefo

The stupid "use console before configured" scheeme strikes again :-)


# 1.31 06-Mar-1997 tholo

Initial implementation of support for calling hardpps() on carrier enable


# 1.30 10-Dec-1996 deraadt

the real changes by niklas... I did not merge correctly


# 1.29 10-Dec-1996 deraadt

clr TS_WOPEN if bailing on cua opens
As well, at this point I've also done fancy cvs repository mangling to
ensure that the com* files in sys/dev/ic maintain the history we had
before. (Yes, I cleaned up the 2.0 tags too..)


# 1.28 29-Nov-1996 niklas

Missing pieces of new bus.h that CVS lost behind my back


# 1.27 12-Nov-1996 niklas

s/bus.h/bus.old.h/ to make the transit to the bus_space bus.h an easy road
possibly taken in small steps


# 1.26 09-Nov-1996 tholo

Break shall be handled as data == 0 and FE bit set; from Theo


# 1.25 30-Oct-1996 niklas

cominit is used from the outside (the alpha port)


# 1.24 22-Oct-1996 downsj

patch com speed initialization


# 1.23 16-Oct-1996 deraadt

contextual usage


# 1.22 16-Oct-1996 deraadt

unused variables


# 1.21 29-Aug-1996 deraadt

sunos-like cua behaviour; inspired by budd@cs.bu.edu in his scn.c


# 1.20 02-Jul-1996 downsj

better FIFO enabling code; netbsd pr#2574, cliff@wport.com


# 1.19 24-Jun-1996 pefo

pica changes backed out. does not belong here


# 1.18 22-Jun-1996 pefo

Pica bus support added


# 1.17 10-Jun-1996 niklas

Some cleanup for -Wall -Wstrict-prototypes


# 1.16 10-Jun-1996 deraadt

tty_attach()


# 1.15 26-May-1996 deraadt

sync 0521


# 1.14 10-May-1996 deraadt

proto change


# 1.13 07-May-1996 deraadt

sync with 0504 -- prototypes and bus.h


# 1.12 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.11 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.10 18-Apr-1996 niklas

NetBSD 960317 merge


# 1.9 20-Mar-1996 mickey

Fix back wrong patches.


# 1.8 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.7 08-Mar-1996 niklas

From NetBSD: merge of 960217


# 1.6 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.5 16-Jan-1996 hvozda

Last of the glue and devices for for PCMCIA support from Stefan Grefen
<grefen@convex.com> with modifications by John Kohl <jtk@kolvir.blrc.ma.us>


# 1.4 03-Jan-1996 deraadt

Patches to use Hayes ESP with com.c; from banshee@gabriella.resort.com;
netbsd pr#1865. the ESP card code is always enabled -- we will have to
see if that fails on any chipsets.


# 1.3 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.


# 1.2 15-Dec-1995 deraadt

update from netbsd


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.171 05-Feb-2020 mpi

Detach timeouts and the softint handler before freeing memory.

As more and more teardown functions include barriers, or any kind of
context change, it is unsafe to continue to assume that such code paths
are atomic. So a good practise is to only free descriptor when we're
sure that no other context can access them.

Found while looking at visa@'s ttkqflush() replacement diff. The same
pattern is present in many USB drivers as found with Peter Stuge.

ok visa@


Revision tags: OPENBSD_6_6_BASE
# 1.170 19-Jul-2019 cheloha

ttysleep(): drop unused timeout parameter

All callers sleep indefinitely.

With help from visa@.

ok visa@, ratchov@, kn@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.169 14-May-2018 kettenis

Add support for register shift/io-width to the console code as well.

ok visa@, patrick@


# 1.168 02-May-2018 kettenis

Revert previous commit; the XR17V35X probe that was added accesses registers
that aren't guaranteed to be there and may even belong to a different device.
This triggers a fault on hppa machines like the C3000 for example.


# 1.167 15-Apr-2018 jcs

The Exar XR17V354 has 4 com ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

ok mlarkin deraadt


# 1.166 02-Apr-2018 kettenis

Add support for register shift/io-width. This allows us to support UARTs
that are mostly NS16550 compatible but use 32-bit instead of 8-bit registers
such as the Synopsys Designware UARTs found on many armv7, arm64 and amd64
SoCs.

tested by florian@, blum@
ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.165 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.164 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.163 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.162 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.161 04-Sep-2016 tedu

remove some more sparc remnants. ok deraadt


# 1.160 03-Sep-2016 jsg

de-zaurus com.c
"looks correct" deraadt@ guenther@ on an earlier rev


# 1.159 16-Aug-2016 kettenis

Only probe the UART type if sc_uarttype is set to COM_UART_UNKNOWN.
This allows glue drivers to set the type based on other information (such as
Oopen Firmware or device tree properties) without going through to risky
code paths.

ok deraadt@, visa@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.158 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.157 13-Apr-2014 deraadt

wrap a long line


Revision tags: OPENBSD_5_5_BASE
# 1.156 09-Dec-2013 deraadt

At resume, do not spin flushing characters in from the chip. There shouldn't
be any characters. If the chip is not actually there for some reason, we'd
be spinning so early in the resume sequence, we'd probably go mad trying to
find the reason..
ok kettenis
request: people with serial ports on their laptops, try to run a "cu" over
a suspend/resume cycle, and see if you see "input noise"


# 1.155 09-Dec-2013 deraadt

At suspend/resume time cope with timeouts, DTR on resume in a bus
bus-independent fashion.
ok kettenis


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.154 14-Feb-2013 kettenis

No need to treat amd64 specially; always return CN_HIGHPRI.

ok miod@


# 1.153 17-Oct-2012 deraadt

Narrow the spltty/splx pair in com_activate to only enclose the minimum
operation which requires it.


# 1.152 25-Aug-2012 kettenis

Better detection of the st16650 v1 (with the broken fifo). Gets rid of
false positives like the DUART on the MPC8347 as found on socppc.

ok deraadt@


# 1.151 25-Aug-2012 kettenis

Turns out the v445 isn't happy at all if we touch the registers that deal
with sleep mode. So skip the wakeup code as well if we are a serial console.
The port on the v445 almost certainly isn't a real st16650 and probably
doesn't implement sleep mode (perhaps someone cut the soft core down a bit
too much?). But it is indistinguishable from it, so we have to deal with it.

ok deraadt@


# 1.150 19-Aug-2012 kettenis

Skip putting a port in sleep mode when it is used as serial console. In that
case the kernel will still be using the port even after the last process closes
it. And on machines like the v445 the firmware won't be happy if the console
port is in sleep mode when the kernel reboots or halts.

ok miod@


Revision tags: OPENBSD_5_2_BASE
# 1.149 12-May-2012 kettenis

Remove unused variable.

ok mpi@, miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.148 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.147 22-May-2011 drahn

Fix a problem found where one SOC has a uart implementation that causes bus
errors if the fifo is read when the fifo is empty. Dont read an empty fifo.
ok deraaadt@ fgsch@


# 1.146 23-Mar-2011 fgsch

only read from the UART if there is something to read. fix beagle, otherwise
it will crash with 'External Non-Linefetch Abort (S)'.
similar diff provided by drahn@. tested by jasper@, deraadt@ ok.


Revision tags: OPENBSD_4_9_BASE
# 1.145 28-Aug-2010 miod

ansify function definitions, and constify a few arrays while there.
no functional change.


Revision tags: OPENBSD_4_8_BASE
# 1.144 07-Aug-2010 kettenis

Add resume support for serial consoles.

Tested by sthen@, ok deraadt@


# 1.143 06-Aug-2010 kettenis

Initial stab at making com@puc suspend and resume properly. Works fine
for using cu(1) between two OpenBSD machines. Probably doesn't work for
serial consoles but we don't support those on puc(4) anyway.

ok deraadt@


# 1.142 02-Jul-2010 nicm

Move common code for waking up writers on a tty into a function.

ok deraadt matthew millert


# 1.141 28-Jun-2010 deraadt

Allow tty drivers to request larger buffers at attach time using a
max-baud-rate hint. Adjust TTYHOG (the nearly full logic) to this new
situation. The larger buffers are required by the very high speed
KDDI devices in Japan (CF com, or USB ucom) so those are the only two
drivers which currently ask for a larger buffer size.
ok yasuoka miod


# 1.140 28-Jun-2010 ckuethe

Use a more moderate fifo trigger level (4) for moderately quick
(sub-38400) port speeds. Inspired by netbsd. ok fgsch krw deraadt miod


# 1.139 26-Jun-2010 guenther

Don't #include <sys/user.h> into files that don't need the stuff
it defines. In some cases, this means pulling in uvm.h or pcb.h
instead, but most of the inclusions were just noise. Tested on
alpha, amd64, armish, hppa, i386, macpcc, sgi, sparc64, and vax,
mostly by krw and naddy.
ok krw@


# 1.138 12-Apr-2010 tedu

Some of the line disciplines want to check for suser. Better to pass them
a process instead of using curproc. ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.137 09-Nov-2009 nicm

Every selwakeup() should have a matching KNOTE() (even if kqueue isn't
supported it doesn't do any harm), so put the KNOTE() in selwakeup() itself and
remove it from any occurences where both are used, except one for kqueue itself
and one in sys_pipe.c (where the selwakeup is under a PIPE_SEL flag).

Based on a diff from tedu.

ok deraadt


# 1.136 04-Nov-2009 kettenis

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@


# 1.135 01-Nov-2009 nicm

Call selwakeup()/KNOTE() even if the queue has emptied completely.

ok miod


# 1.134 31-Oct-2009 fgsch

Use suser when possible. Suggested by miod@.
miod@ deraadt@ ok.


# 1.133 31-Oct-2009 deraadt

Add missing KNOTE() calls after selwakeup(), until we decide if the KNOTE()
calls can go directly into selwakeup() safely
long discussion with nicm, murmers of consent from tedu and miod, noone
else seems to care of kqueue is busted as long as it makes their sockets
move data fast... pretty sad.


# 1.132 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.131 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.130 23-Nov-2008 deraadt

pccom can finally die; ok kettenis dlg drahn, tested by okan


# 1.129 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


Revision tags: OPENBSD_4_4_BASE
# 1.128 08-Jun-2008 kettenis

Make serial console on non-primary ports work to on i386.

tested by jbg@, "it is right" deraadt@


# 1.127 25-Apr-2008 dlg

the code that parses arguments from the boot loader on amd64 wasnt checking
what type of console was specified, so when a glass console was used it was
still configuring serial bits. this makes it so serial config only occurs
for serial console devices.

found by jolan@, thib@, and maybe sthen@
sorry guys


# 1.126 24-Apr-2008 jsing

MD_ISA_IOT is not defined anywhere so get rid of it.

Spotted by drahn@, ok dlg@


# 1.125 24-Apr-2008 jsing

Keep order of "#if defined..." consistent.

ok dlg@


# 1.124 24-Apr-2008 jsing

Clean up comments.


# 1.123 24-Apr-2008 jsing

Cleanup serial console handling and remove some of the MD code from com.c.
Specify the serial configuration from within the MD code, rather than
passing things via macros. This will allow other platforms to more readily
change the serial console configuration.

Committing this so it actually gets tested.

ok dlg@


# 1.122 09-Apr-2008 deraadt

Increase buffer size sent to the fifo, and clamp the size correctly.
Scrub the buffer afterwards, too


Revision tags: OPENBSD_4_3_BASE
# 1.121 23-Jan-2008 jsing

Cleanup cn_pri. Change constants to more meaningful names, rather than
the hp300 related ones currently in use. CN_NORMAL becomes CN_LOWPRI,
CN_INTERNAL becomes CN_MIDPRI and CN_REMOTE becomes CN_HIGHPRI.

ok miod@


# 1.120 12-Jan-2008 miod

Make comconsrate initialized to TTYDEF_SPEED at compile-time, for ports
which need to setup the chip before comcnattach() is invoked.


# 1.119 08-Jan-2008 dlg

the rsc-console on the v880 operates at 115200, not the 9600 we think we
have to force all console devices to. this change passes the right speed
to the com code, and continues to use it when the device is opened as the
console device.

figured out by kettenis@
ok kettenis@ miod@


# 1.118 22-Aug-2007 jasper

fix compilation with KDGB
from Nicholas Marriott

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.117 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.116 22-Jun-2007 jasper

ansify/de-register
no binary change


# 1.115 08-May-2007 deraadt

backout while the amd64 puc situation is rethought


# 1.114 08-May-2007 deraadt

move com_activate() to where it belongs


# 1.113 08-May-2007 deraadt

put more foo_detach() routines where they are used


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.112 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.111 27-Apr-2006 deraadt

2 lines of code in most drivers, to do the timestamping; ok miod kettenis


# 1.110 27-Mar-2006 deraadt

in detach, mark device with COM_SW_DEAD, so that close() will not go
tapping additional registes. allows it to work on macppc, where doing
such a tap after unplug is very bad. drahn helped fkr@bytemine.de
ok miod and drahn


Revision tags: OPENBSD_3_9_BASE
# 1.109 01-Jan-2006 miod

Let cons_init() and cons_init_bell() initialize the whole consdev structure,
thus removing the need for drivers to initialize cn_pri to CN_DEAD when
hardware probe fails.


# 1.108 21-Nov-2005 millert

Move contents of sys/select.h to sys/selinfo.h in preparation for a
userland-visible sys/select.h. Consistent with what Net and Free do.
OK deraadt@, tested with full ports build by naddy@.


# 1.107 11-Nov-2005 fgsch

fix kgdb compilation; input and ok miod@.


# 1.106 26-Sep-2005 miod

Share com probe code between com and pccom; allows us to get rid of awkward
code duplication in cardbus, pcmcia and puc attachments.

Joint effort with fgs@; blessed deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.105 18-Jul-2005 deraadt

fix sparc64 console; same diff as miod


# 1.104 18-Jul-2005 deraadt

COM_CONSOLE & DDB fix


# 1.103 17-Jul-2005 miod

Allow the console support code not to be compiled in; this will be
necessary for and only used on sparc, shortly.

Reluctantely ok deraadt@


# 1.102 11-Jul-2005 uwe

Enable IR receive mode only for infrared capable PXA2x0 UARTs. Normal
reception is blocked while the IR receiver or transmitter is enabled.

Also enable the PXA2x0 UART before clearing the FIFO (suggested by
drahn@ some time ago), and disable the UART in compwroff().

ok deraadt@


# 1.101 02-Jul-2005 uwe

xscale UART FIFOs are 32 bytes deep; found by deraadt@


# 1.100 27-May-2005 uwe

- Merge changes from pxacom back into the common com driver.

Changes to the common com driver (partly from NetBSD):
- Multiply before divide in comspeed() to avoid overflow (from NetBSD).
- Don't call getc() and send -1 if the output queue is empty.
- Take UART clock frequency as a parameter instead of using COM_FREQ.

ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.99 20-Oct-2004 pefo

Use bus_addr_t instead of int for port address/offset, ok mickey


Revision tags: OPENBSD_3_6_BASE
# 1.98 09-Aug-2004 pefo

remove old arc stuff and add sgi support.
ok mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.97 30-May-2004 deraadt

serial console hack from tom. who, after having been told a few times
to commit it, has not. what is going on guys?


# 1.96 03-May-2004 drahn

Remove OpenBSD/pegaos, this has been announced before but delayed until
the tree was stable. No point in code supporting a company which screws
its employees being in the OpenBSD tree.


Revision tags: OPENBSD_3_5_BASE
# 1.95 31-Oct-2003 drahn

Use isa iot for pegasos com console attachment, perhaps this could
be adopted MI?


# 1.94 03-Oct-2003 miod

Merge tty_attach() in ttymalloc() and tty_detach() in ttyfree(). The need for
separate tty registering is gone now that sparc has switched to wscons, and
this makes the code less error-prone.

Also, remove tests for ttymalloc() failure, since it uses M_WAITOK.

ok millert@ deraadt@, tested by various people as well besides me...


# 1.93 23-Sep-2003 millert

Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater
poll(2) functionality instead of emulating it via the select backend.
Adapted from NetBSD and including some changes from FreeBSD.
Tested by many, deraadt@ OK


Revision tags: OPENBSD_3_4_BASE
# 1.92 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.91 15-Jul-2003 jason

move prototype for com_raisedtr() to comvar.h (just like pccom).


# 1.90 03-Jun-2003 deraadt

terms 3 & 4 cleanup based on "terms" file


# 1.89 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.88 19-Dec-2002 mickey

comparam() does not need an spltty() for it, already called there.
time-bound loops in com_common_cnputc() and lower to spltty(),
which i guess is left from times when timeouts were processed at splhigh().
jason@ tested and ok, art@ ok


Revision tags: UBC_SYNC_B
# 1.87 17-Oct-2002 art

ifndef __HAVE_GENERIC_SOFT_INTERRUPTS leaved a label without a statement after it. Fix.


Revision tags: OPENBSD_3_2_BASE
# 1.86 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.85 11-Jun-2002 miod

com.c is not a block device, no bdev_decl() for it.


Revision tags: OPENBSD_3_1_BASE
# 1.84 09-Apr-2002 pefo

Don't enable interrupts until an open() is done. Until then the driver
is not handling them and may throw the kernel into a spurious interrupt
loop. ok art@


# 1.83 14-Mar-2002 millert

First round of __P removal in sys


# 1.82 14-Mar-2002 jason

compare pointers with NULL not 0


# 1.81 05-Feb-2002 mickey

restore CN_REMOTE priority, as it always was there.
anyway, only i386 uses that path and only if forced anyway.
also do not do comprobe1() on hppa since that hoses the port.


# 1.80 30-Jan-2002 nordin

Move SET/CLR/ISSET macros to param.h. fgsch@ and millert@ ok


# 1.79 25-Jan-2002 mickey

CONADDR is defined elsewhere for hppa


# 1.78 23-Jan-2002 ericj

oops, make the kgdb var's non-static


# 1.77 23-Jan-2002 ericj

allow this to compile with KGDB


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.76 05-Oct-2001 mickey

branches: 1.76.4;
restore some of that dead code needed for dev/cons functionality


# 1.75 02-Oct-2001 art

#ifdef FOO works much better when FOO isn't misspelled.


# 1.74 30-Sep-2001 art

Enable break interrupt earlier.


# 1.73 30-Sep-2001 art

Next round of cleanups.
- some KNF.
- disable interrupts earlier in attach.
- give it some more time in attach to finish earlier output.
- explicit bus_space_barrier in comcnputc.
- dead code.


# 1.72 30-Sep-2001 art

Remove dead code.


# 1.71 30-Sep-2001 art

Remove the COM_HAYESP code. It doesn't appear to have been ever used and
it's very intrusive and makes the code less readable.


# 1.70 30-Sep-2001 art

Move out the com at commulti attachment into an ownfile.
Same story as isapnp - not tested because i386 uses pccom.


# 1.69 30-Sep-2001 art

Move out com at isapnp attachment into an own file.
Not tested because the only system with isapnp is i386 and i386 uses pccom.


# 1.68 29-Sep-2001 art

Next step in making the com driver improvable.
Split out the com at isa attachment into its own file.


# 1.67 29-Sep-2001 art

- compoll is now scheduled once for every sc instead of just one timeout for
all ports and looping over them.
- support for generic soft interrupts.


# 1.66 27-Sep-2001 art

Simplify comstart a bit.


# 1.65 27-Sep-2001 millert

Enable #if 0'd code in comcnputc() so serial console works correctly;
art@openbsd.org


# 1.64 27-Sep-2001 art

Split out comattach that does isa and isapnp attachment and initialization,
into comattach that does the isa stuff and com_attach_subr that does the
init.


Revision tags: OPENBSD_2_9_BASE
# 1.63 17-Apr-2001 aaron

Implement cnbell(), an optional entrypoint that rings the console bell; from
NetBSD. deraadt@ ok


# 1.62 15-Mar-2001 art

Put back new timeouts. This time with correct timeout for compoll.


# 1.61 15-Mar-2001 deraadt

typo


# 1.60 15-Mar-2001 art

back out new timeouts until I find out why they break alpha.


# 1.59 15-Mar-2001 deraadt

support puc devices with higher speeds (not tested yet)


# 1.58 13-Mar-2001 mickey

new timeouts


# 1.57 24-Jan-2001 hugh

KGDB for i386 from NetBSD via niklas, with tweaks and accommodations.
Tested by various, vetted by mickey & theo.


# 1.56 08-Nov-2000 art

Add comcnattach that does the basic steps needed to attach
a com as a serial console. (idea from NetBSD).

If cn_tab->cn_dev == NODEV, try to find comopen in cdevsw and set cn_dev
to the right device.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE SMP_BASE
# 1.55 27-Jan-2000 mickey

branches: 1.55.2;
isa-avoidance


# 1.54 11-Jan-2000 mickey

a few ifdef accomodations for hppa, also a few knf spaces


Revision tags: kame_19991208
# 1.53 28-Nov-1999 downsj

Enable TI16750 UART support.


# 1.52 09-Nov-1999 rahnds

in the ifdef POWERPC section, do use ppc, not p4e, for the iohandle
for the console configuration.


# 1.51 26-Oct-1999 downsj

This file has my code in it, attach my copyright.


Revision tags: OPENBSD_2_6_BASE
# 1.50 08-Aug-1999 niklas

pasto from pccom.c


# 1.49 08-Aug-1999 niklas

revert function accidentally committed


# 1.48 08-Aug-1999 niklas

Detach support for com; NetBSD and me


# 1.47 26-Jul-1999 niklas

Move over the ISA PnP support from pccom.c to com.c


# 1.46 26-Jul-1999 niklas

fix my last commit where I committed more than intended


# 1.45 26-Jul-1999 niklas

Remove obsolete detach code that has been dead for very long


# 1.44 25-Jun-1999 rees

Don't turn off uart when closing cua device if tty is waiting.
Instead just drop dtr briefly.


Revision tags: OPENBSD_2_5_BASE
# 1.43 09-Feb-1999 rees

Fix cua device to not block on open.
Turn off chip (and dtr) on interrupted open.


# 1.42 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.41 20-Sep-1998 rahnds

Powerpc port uses com.c not just power4e.


# 1.40 18-Aug-1998 pefo

Remove clearing of interrupt after character output in cnputci(). Clearing
the int will make the tty stop if output is currently active.


# 1.39 07-Aug-1998 pefo

com.c needs to know about mem mapped ports in ppc systems.

ncr.c and if_de.c needs some hooks for systems with ncr and dec
ether chips on the motherboard that runs on odd clocks and doesn't
support a srom. srom is emulated in machine dependent code.

big endian support for ncr and dec ether finished. the 21040
have some more coding requirements if it is to run BE since
it does not have the descriptor endian swap configuration bit.


Revision tags: OPENBSD_2_3_BASE
# 1.38 23-Feb-1998 downsj

New probe routine and support for ST16650.

Compiles, but completely untested.


# 1.37 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


Revision tags: OPENBSD_2_2_BASE
# 1.36 03-Sep-1997 deraadt

fix cua/tty locking


# 1.35 07-Jul-1997 niklas

Removed an unused arg


Revision tags: OPENBSD_2_1_BASE
# 1.34 10-Apr-1997 pefo

Need to separate i/o and mem on mips


# 1.33 17-Mar-1997 pefo

Serial console trouble again...


# 1.32 12-Mar-1997 pefo

The stupid "use console before configured" scheeme strikes again :-)


# 1.31 06-Mar-1997 tholo

Initial implementation of support for calling hardpps() on carrier enable


# 1.30 10-Dec-1996 deraadt

the real changes by niklas... I did not merge correctly


# 1.29 10-Dec-1996 deraadt

clr TS_WOPEN if bailing on cua opens
As well, at this point I've also done fancy cvs repository mangling to
ensure that the com* files in sys/dev/ic maintain the history we had
before. (Yes, I cleaned up the 2.0 tags too..)


# 1.28 29-Nov-1996 niklas

Missing pieces of new bus.h that CVS lost behind my back


# 1.27 12-Nov-1996 niklas

s/bus.h/bus.old.h/ to make the transit to the bus_space bus.h an easy road
possibly taken in small steps


# 1.26 09-Nov-1996 tholo

Break shall be handled as data == 0 and FE bit set; from Theo


# 1.25 30-Oct-1996 niklas

cominit is used from the outside (the alpha port)


# 1.24 22-Oct-1996 downsj

patch com speed initialization


# 1.23 16-Oct-1996 deraadt

contextual usage


# 1.22 16-Oct-1996 deraadt

unused variables


# 1.21 29-Aug-1996 deraadt

sunos-like cua behaviour; inspired by budd@cs.bu.edu in his scn.c


# 1.20 02-Jul-1996 downsj

better FIFO enabling code; netbsd pr#2574, cliff@wport.com


# 1.19 24-Jun-1996 pefo

pica changes backed out. does not belong here


# 1.18 22-Jun-1996 pefo

Pica bus support added


# 1.17 10-Jun-1996 niklas

Some cleanup for -Wall -Wstrict-prototypes


# 1.16 10-Jun-1996 deraadt

tty_attach()


# 1.15 26-May-1996 deraadt

sync 0521


# 1.14 10-May-1996 deraadt

proto change


# 1.13 07-May-1996 deraadt

sync with 0504 -- prototypes and bus.h


# 1.12 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.11 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.10 18-Apr-1996 niklas

NetBSD 960317 merge


# 1.9 20-Mar-1996 mickey

Fix back wrong patches.


# 1.8 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.7 08-Mar-1996 niklas

From NetBSD: merge of 960217


# 1.6 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.5 16-Jan-1996 hvozda

Last of the glue and devices for for PCMCIA support from Stefan Grefen
<grefen@convex.com> with modifications by John Kohl <jtk@kolvir.blrc.ma.us>


# 1.4 03-Jan-1996 deraadt

Patches to use Hayes ESP with com.c; from banshee@gabriella.resort.com;
netbsd pr#1865. the ESP card code is always enabled -- we will have to
see if that fails on any chipsets.


# 1.3 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.


# 1.2 15-Dec-1995 deraadt

update from netbsd


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.170 19-Jul-2019 cheloha

ttysleep(): drop unused timeout parameter

All callers sleep indefinitely.

With help from visa@.

ok visa@, ratchov@, kn@


Revision tags: OPENBSD_6_4_BASE OPENBSD_6_5_BASE
# 1.169 14-May-2018 kettenis

Add support for register shift/io-width to the console code as well.

ok visa@, patrick@


# 1.168 02-May-2018 kettenis

Revert previous commit; the XR17V35X probe that was added accesses registers
that aren't guaranteed to be there and may even belong to a different device.
This triggers a fault on hppa machines like the C3000 for example.


# 1.167 15-Apr-2018 jcs

The Exar XR17V354 has 4 com ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

ok mlarkin deraadt


# 1.166 02-Apr-2018 kettenis

Add support for register shift/io-width. This allows us to support UARTs
that are mostly NS16550 compatible but use 32-bit instead of 8-bit registers
such as the Synopsys Designware UARTs found on many armv7, arm64 and amd64
SoCs.

tested by florian@, blum@
ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.165 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.164 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.163 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.162 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.161 04-Sep-2016 tedu

remove some more sparc remnants. ok deraadt


# 1.160 03-Sep-2016 jsg

de-zaurus com.c
"looks correct" deraadt@ guenther@ on an earlier rev


# 1.159 16-Aug-2016 kettenis

Only probe the UART type if sc_uarttype is set to COM_UART_UNKNOWN.
This allows glue drivers to set the type based on other information (such as
Oopen Firmware or device tree properties) without going through to risky
code paths.

ok deraadt@, visa@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.158 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.157 13-Apr-2014 deraadt

wrap a long line


Revision tags: OPENBSD_5_5_BASE
# 1.156 09-Dec-2013 deraadt

At resume, do not spin flushing characters in from the chip. There shouldn't
be any characters. If the chip is not actually there for some reason, we'd
be spinning so early in the resume sequence, we'd probably go mad trying to
find the reason..
ok kettenis
request: people with serial ports on their laptops, try to run a "cu" over
a suspend/resume cycle, and see if you see "input noise"


# 1.155 09-Dec-2013 deraadt

At suspend/resume time cope with timeouts, DTR on resume in a bus
bus-independent fashion.
ok kettenis


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.154 14-Feb-2013 kettenis

No need to treat amd64 specially; always return CN_HIGHPRI.

ok miod@


# 1.153 17-Oct-2012 deraadt

Narrow the spltty/splx pair in com_activate to only enclose the minimum
operation which requires it.


# 1.152 25-Aug-2012 kettenis

Better detection of the st16650 v1 (with the broken fifo). Gets rid of
false positives like the DUART on the MPC8347 as found on socppc.

ok deraadt@


# 1.151 25-Aug-2012 kettenis

Turns out the v445 isn't happy at all if we touch the registers that deal
with sleep mode. So skip the wakeup code as well if we are a serial console.
The port on the v445 almost certainly isn't a real st16650 and probably
doesn't implement sleep mode (perhaps someone cut the soft core down a bit
too much?). But it is indistinguishable from it, so we have to deal with it.

ok deraadt@


# 1.150 19-Aug-2012 kettenis

Skip putting a port in sleep mode when it is used as serial console. In that
case the kernel will still be using the port even after the last process closes
it. And on machines like the v445 the firmware won't be happy if the console
port is in sleep mode when the kernel reboots or halts.

ok miod@


Revision tags: OPENBSD_5_2_BASE
# 1.149 12-May-2012 kettenis

Remove unused variable.

ok mpi@, miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.148 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.147 22-May-2011 drahn

Fix a problem found where one SOC has a uart implementation that causes bus
errors if the fifo is read when the fifo is empty. Dont read an empty fifo.
ok deraaadt@ fgsch@


# 1.146 23-Mar-2011 fgsch

only read from the UART if there is something to read. fix beagle, otherwise
it will crash with 'External Non-Linefetch Abort (S)'.
similar diff provided by drahn@. tested by jasper@, deraadt@ ok.


Revision tags: OPENBSD_4_9_BASE
# 1.145 28-Aug-2010 miod

ansify function definitions, and constify a few arrays while there.
no functional change.


Revision tags: OPENBSD_4_8_BASE
# 1.144 07-Aug-2010 kettenis

Add resume support for serial consoles.

Tested by sthen@, ok deraadt@


# 1.143 06-Aug-2010 kettenis

Initial stab at making com@puc suspend and resume properly. Works fine
for using cu(1) between two OpenBSD machines. Probably doesn't work for
serial consoles but we don't support those on puc(4) anyway.

ok deraadt@


# 1.142 02-Jul-2010 nicm

Move common code for waking up writers on a tty into a function.

ok deraadt matthew millert


# 1.141 28-Jun-2010 deraadt

Allow tty drivers to request larger buffers at attach time using a
max-baud-rate hint. Adjust TTYHOG (the nearly full logic) to this new
situation. The larger buffers are required by the very high speed
KDDI devices in Japan (CF com, or USB ucom) so those are the only two
drivers which currently ask for a larger buffer size.
ok yasuoka miod


# 1.140 28-Jun-2010 ckuethe

Use a more moderate fifo trigger level (4) for moderately quick
(sub-38400) port speeds. Inspired by netbsd. ok fgsch krw deraadt miod


# 1.139 26-Jun-2010 guenther

Don't #include <sys/user.h> into files that don't need the stuff
it defines. In some cases, this means pulling in uvm.h or pcb.h
instead, but most of the inclusions were just noise. Tested on
alpha, amd64, armish, hppa, i386, macpcc, sgi, sparc64, and vax,
mostly by krw and naddy.
ok krw@


# 1.138 12-Apr-2010 tedu

Some of the line disciplines want to check for suser. Better to pass them
a process instead of using curproc. ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.137 09-Nov-2009 nicm

Every selwakeup() should have a matching KNOTE() (even if kqueue isn't
supported it doesn't do any harm), so put the KNOTE() in selwakeup() itself and
remove it from any occurences where both are used, except one for kqueue itself
and one in sys_pipe.c (where the selwakeup is under a PIPE_SEL flag).

Based on a diff from tedu.

ok deraadt


# 1.136 04-Nov-2009 kettenis

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@


# 1.135 01-Nov-2009 nicm

Call selwakeup()/KNOTE() even if the queue has emptied completely.

ok miod


# 1.134 31-Oct-2009 fgsch

Use suser when possible. Suggested by miod@.
miod@ deraadt@ ok.


# 1.133 31-Oct-2009 deraadt

Add missing KNOTE() calls after selwakeup(), until we decide if the KNOTE()
calls can go directly into selwakeup() safely
long discussion with nicm, murmers of consent from tedu and miod, noone
else seems to care of kqueue is busted as long as it makes their sockets
move data fast... pretty sad.


# 1.132 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.131 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.130 23-Nov-2008 deraadt

pccom can finally die; ok kettenis dlg drahn, tested by okan


# 1.129 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


Revision tags: OPENBSD_4_4_BASE
# 1.128 08-Jun-2008 kettenis

Make serial console on non-primary ports work to on i386.

tested by jbg@, "it is right" deraadt@


# 1.127 25-Apr-2008 dlg

the code that parses arguments from the boot loader on amd64 wasnt checking
what type of console was specified, so when a glass console was used it was
still configuring serial bits. this makes it so serial config only occurs
for serial console devices.

found by jolan@, thib@, and maybe sthen@
sorry guys


# 1.126 24-Apr-2008 jsing

MD_ISA_IOT is not defined anywhere so get rid of it.

Spotted by drahn@, ok dlg@


# 1.125 24-Apr-2008 jsing

Keep order of "#if defined..." consistent.

ok dlg@


# 1.124 24-Apr-2008 jsing

Clean up comments.


# 1.123 24-Apr-2008 jsing

Cleanup serial console handling and remove some of the MD code from com.c.
Specify the serial configuration from within the MD code, rather than
passing things via macros. This will allow other platforms to more readily
change the serial console configuration.

Committing this so it actually gets tested.

ok dlg@


# 1.122 09-Apr-2008 deraadt

Increase buffer size sent to the fifo, and clamp the size correctly.
Scrub the buffer afterwards, too


Revision tags: OPENBSD_4_3_BASE
# 1.121 23-Jan-2008 jsing

Cleanup cn_pri. Change constants to more meaningful names, rather than
the hp300 related ones currently in use. CN_NORMAL becomes CN_LOWPRI,
CN_INTERNAL becomes CN_MIDPRI and CN_REMOTE becomes CN_HIGHPRI.

ok miod@


# 1.120 12-Jan-2008 miod

Make comconsrate initialized to TTYDEF_SPEED at compile-time, for ports
which need to setup the chip before comcnattach() is invoked.


# 1.119 08-Jan-2008 dlg

the rsc-console on the v880 operates at 115200, not the 9600 we think we
have to force all console devices to. this change passes the right speed
to the com code, and continues to use it when the device is opened as the
console device.

figured out by kettenis@
ok kettenis@ miod@


# 1.118 22-Aug-2007 jasper

fix compilation with KDGB
from Nicholas Marriott

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.117 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.116 22-Jun-2007 jasper

ansify/de-register
no binary change


# 1.115 08-May-2007 deraadt

backout while the amd64 puc situation is rethought


# 1.114 08-May-2007 deraadt

move com_activate() to where it belongs


# 1.113 08-May-2007 deraadt

put more foo_detach() routines where they are used


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.112 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.111 27-Apr-2006 deraadt

2 lines of code in most drivers, to do the timestamping; ok miod kettenis


# 1.110 27-Mar-2006 deraadt

in detach, mark device with COM_SW_DEAD, so that close() will not go
tapping additional registes. allows it to work on macppc, where doing
such a tap after unplug is very bad. drahn helped fkr@bytemine.de
ok miod and drahn


Revision tags: OPENBSD_3_9_BASE
# 1.109 01-Jan-2006 miod

Let cons_init() and cons_init_bell() initialize the whole consdev structure,
thus removing the need for drivers to initialize cn_pri to CN_DEAD when
hardware probe fails.


# 1.108 21-Nov-2005 millert

Move contents of sys/select.h to sys/selinfo.h in preparation for a
userland-visible sys/select.h. Consistent with what Net and Free do.
OK deraadt@, tested with full ports build by naddy@.


# 1.107 11-Nov-2005 fgsch

fix kgdb compilation; input and ok miod@.


# 1.106 26-Sep-2005 miod

Share com probe code between com and pccom; allows us to get rid of awkward
code duplication in cardbus, pcmcia and puc attachments.

Joint effort with fgs@; blessed deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.105 18-Jul-2005 deraadt

fix sparc64 console; same diff as miod


# 1.104 18-Jul-2005 deraadt

COM_CONSOLE & DDB fix


# 1.103 17-Jul-2005 miod

Allow the console support code not to be compiled in; this will be
necessary for and only used on sparc, shortly.

Reluctantely ok deraadt@


# 1.102 11-Jul-2005 uwe

Enable IR receive mode only for infrared capable PXA2x0 UARTs. Normal
reception is blocked while the IR receiver or transmitter is enabled.

Also enable the PXA2x0 UART before clearing the FIFO (suggested by
drahn@ some time ago), and disable the UART in compwroff().

ok deraadt@


# 1.101 02-Jul-2005 uwe

xscale UART FIFOs are 32 bytes deep; found by deraadt@


# 1.100 27-May-2005 uwe

- Merge changes from pxacom back into the common com driver.

Changes to the common com driver (partly from NetBSD):
- Multiply before divide in comspeed() to avoid overflow (from NetBSD).
- Don't call getc() and send -1 if the output queue is empty.
- Take UART clock frequency as a parameter instead of using COM_FREQ.

ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.99 20-Oct-2004 pefo

Use bus_addr_t instead of int for port address/offset, ok mickey


Revision tags: OPENBSD_3_6_BASE
# 1.98 09-Aug-2004 pefo

remove old arc stuff and add sgi support.
ok mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.97 30-May-2004 deraadt

serial console hack from tom. who, after having been told a few times
to commit it, has not. what is going on guys?


# 1.96 03-May-2004 drahn

Remove OpenBSD/pegaos, this has been announced before but delayed until
the tree was stable. No point in code supporting a company which screws
its employees being in the OpenBSD tree.


Revision tags: OPENBSD_3_5_BASE
# 1.95 31-Oct-2003 drahn

Use isa iot for pegasos com console attachment, perhaps this could
be adopted MI?


# 1.94 03-Oct-2003 miod

Merge tty_attach() in ttymalloc() and tty_detach() in ttyfree(). The need for
separate tty registering is gone now that sparc has switched to wscons, and
this makes the code less error-prone.

Also, remove tests for ttymalloc() failure, since it uses M_WAITOK.

ok millert@ deraadt@, tested by various people as well besides me...


# 1.93 23-Sep-2003 millert

Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater
poll(2) functionality instead of emulating it via the select backend.
Adapted from NetBSD and including some changes from FreeBSD.
Tested by many, deraadt@ OK


Revision tags: OPENBSD_3_4_BASE
# 1.92 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.91 15-Jul-2003 jason

move prototype for com_raisedtr() to comvar.h (just like pccom).


# 1.90 03-Jun-2003 deraadt

terms 3 & 4 cleanup based on "terms" file


# 1.89 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.88 19-Dec-2002 mickey

comparam() does not need an spltty() for it, already called there.
time-bound loops in com_common_cnputc() and lower to spltty(),
which i guess is left from times when timeouts were processed at splhigh().
jason@ tested and ok, art@ ok


Revision tags: UBC_SYNC_B
# 1.87 17-Oct-2002 art

ifndef __HAVE_GENERIC_SOFT_INTERRUPTS leaved a label without a statement after it. Fix.


Revision tags: OPENBSD_3_2_BASE
# 1.86 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.85 11-Jun-2002 miod

com.c is not a block device, no bdev_decl() for it.


Revision tags: OPENBSD_3_1_BASE
# 1.84 09-Apr-2002 pefo

Don't enable interrupts until an open() is done. Until then the driver
is not handling them and may throw the kernel into a spurious interrupt
loop. ok art@


# 1.83 14-Mar-2002 millert

First round of __P removal in sys


# 1.82 14-Mar-2002 jason

compare pointers with NULL not 0


# 1.81 05-Feb-2002 mickey

restore CN_REMOTE priority, as it always was there.
anyway, only i386 uses that path and only if forced anyway.
also do not do comprobe1() on hppa since that hoses the port.


# 1.80 30-Jan-2002 nordin

Move SET/CLR/ISSET macros to param.h. fgsch@ and millert@ ok


# 1.79 25-Jan-2002 mickey

CONADDR is defined elsewhere for hppa


# 1.78 23-Jan-2002 ericj

oops, make the kgdb var's non-static


# 1.77 23-Jan-2002 ericj

allow this to compile with KGDB


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.76 05-Oct-2001 mickey

branches: 1.76.4;
restore some of that dead code needed for dev/cons functionality


# 1.75 02-Oct-2001 art

#ifdef FOO works much better when FOO isn't misspelled.


# 1.74 30-Sep-2001 art

Enable break interrupt earlier.


# 1.73 30-Sep-2001 art

Next round of cleanups.
- some KNF.
- disable interrupts earlier in attach.
- give it some more time in attach to finish earlier output.
- explicit bus_space_barrier in comcnputc.
- dead code.


# 1.72 30-Sep-2001 art

Remove dead code.


# 1.71 30-Sep-2001 art

Remove the COM_HAYESP code. It doesn't appear to have been ever used and
it's very intrusive and makes the code less readable.


# 1.70 30-Sep-2001 art

Move out the com at commulti attachment into an ownfile.
Same story as isapnp - not tested because i386 uses pccom.


# 1.69 30-Sep-2001 art

Move out com at isapnp attachment into an own file.
Not tested because the only system with isapnp is i386 and i386 uses pccom.


# 1.68 29-Sep-2001 art

Next step in making the com driver improvable.
Split out the com at isa attachment into its own file.


# 1.67 29-Sep-2001 art

- compoll is now scheduled once for every sc instead of just one timeout for
all ports and looping over them.
- support for generic soft interrupts.


# 1.66 27-Sep-2001 art

Simplify comstart a bit.


# 1.65 27-Sep-2001 millert

Enable #if 0'd code in comcnputc() so serial console works correctly;
art@openbsd.org


# 1.64 27-Sep-2001 art

Split out comattach that does isa and isapnp attachment and initialization,
into comattach that does the isa stuff and com_attach_subr that does the
init.


Revision tags: OPENBSD_2_9_BASE
# 1.63 17-Apr-2001 aaron

Implement cnbell(), an optional entrypoint that rings the console bell; from
NetBSD. deraadt@ ok


# 1.62 15-Mar-2001 art

Put back new timeouts. This time with correct timeout for compoll.


# 1.61 15-Mar-2001 deraadt

typo


# 1.60 15-Mar-2001 art

back out new timeouts until I find out why they break alpha.


# 1.59 15-Mar-2001 deraadt

support puc devices with higher speeds (not tested yet)


# 1.58 13-Mar-2001 mickey

new timeouts


# 1.57 24-Jan-2001 hugh

KGDB for i386 from NetBSD via niklas, with tweaks and accommodations.
Tested by various, vetted by mickey & theo.


# 1.56 08-Nov-2000 art

Add comcnattach that does the basic steps needed to attach
a com as a serial console. (idea from NetBSD).

If cn_tab->cn_dev == NODEV, try to find comopen in cdevsw and set cn_dev
to the right device.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE SMP_BASE
# 1.55 27-Jan-2000 mickey

branches: 1.55.2;
isa-avoidance


# 1.54 11-Jan-2000 mickey

a few ifdef accomodations for hppa, also a few knf spaces


Revision tags: kame_19991208
# 1.53 28-Nov-1999 downsj

Enable TI16750 UART support.


# 1.52 09-Nov-1999 rahnds

in the ifdef POWERPC section, do use ppc, not p4e, for the iohandle
for the console configuration.


# 1.51 26-Oct-1999 downsj

This file has my code in it, attach my copyright.


Revision tags: OPENBSD_2_6_BASE
# 1.50 08-Aug-1999 niklas

pasto from pccom.c


# 1.49 08-Aug-1999 niklas

revert function accidentally committed


# 1.48 08-Aug-1999 niklas

Detach support for com; NetBSD and me


# 1.47 26-Jul-1999 niklas

Move over the ISA PnP support from pccom.c to com.c


# 1.46 26-Jul-1999 niklas

fix my last commit where I committed more than intended


# 1.45 26-Jul-1999 niklas

Remove obsolete detach code that has been dead for very long


# 1.44 25-Jun-1999 rees

Don't turn off uart when closing cua device if tty is waiting.
Instead just drop dtr briefly.


Revision tags: OPENBSD_2_5_BASE
# 1.43 09-Feb-1999 rees

Fix cua device to not block on open.
Turn off chip (and dtr) on interrupted open.


# 1.42 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.41 20-Sep-1998 rahnds

Powerpc port uses com.c not just power4e.


# 1.40 18-Aug-1998 pefo

Remove clearing of interrupt after character output in cnputci(). Clearing
the int will make the tty stop if output is currently active.


# 1.39 07-Aug-1998 pefo

com.c needs to know about mem mapped ports in ppc systems.

ncr.c and if_de.c needs some hooks for systems with ncr and dec
ether chips on the motherboard that runs on odd clocks and doesn't
support a srom. srom is emulated in machine dependent code.

big endian support for ncr and dec ether finished. the 21040
have some more coding requirements if it is to run BE since
it does not have the descriptor endian swap configuration bit.


Revision tags: OPENBSD_2_3_BASE
# 1.38 23-Feb-1998 downsj

New probe routine and support for ST16650.

Compiles, but completely untested.


# 1.37 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


Revision tags: OPENBSD_2_2_BASE
# 1.36 03-Sep-1997 deraadt

fix cua/tty locking


# 1.35 07-Jul-1997 niklas

Removed an unused arg


Revision tags: OPENBSD_2_1_BASE
# 1.34 10-Apr-1997 pefo

Need to separate i/o and mem on mips


# 1.33 17-Mar-1997 pefo

Serial console trouble again...


# 1.32 12-Mar-1997 pefo

The stupid "use console before configured" scheeme strikes again :-)


# 1.31 06-Mar-1997 tholo

Initial implementation of support for calling hardpps() on carrier enable


# 1.30 10-Dec-1996 deraadt

the real changes by niklas... I did not merge correctly


# 1.29 10-Dec-1996 deraadt

clr TS_WOPEN if bailing on cua opens
As well, at this point I've also done fancy cvs repository mangling to
ensure that the com* files in sys/dev/ic maintain the history we had
before. (Yes, I cleaned up the 2.0 tags too..)


# 1.28 29-Nov-1996 niklas

Missing pieces of new bus.h that CVS lost behind my back


# 1.27 12-Nov-1996 niklas

s/bus.h/bus.old.h/ to make the transit to the bus_space bus.h an easy road
possibly taken in small steps


# 1.26 09-Nov-1996 tholo

Break shall be handled as data == 0 and FE bit set; from Theo


# 1.25 30-Oct-1996 niklas

cominit is used from the outside (the alpha port)


# 1.24 22-Oct-1996 downsj

patch com speed initialization


# 1.23 16-Oct-1996 deraadt

contextual usage


# 1.22 16-Oct-1996 deraadt

unused variables


# 1.21 29-Aug-1996 deraadt

sunos-like cua behaviour; inspired by budd@cs.bu.edu in his scn.c


# 1.20 02-Jul-1996 downsj

better FIFO enabling code; netbsd pr#2574, cliff@wport.com


# 1.19 24-Jun-1996 pefo

pica changes backed out. does not belong here


# 1.18 22-Jun-1996 pefo

Pica bus support added


# 1.17 10-Jun-1996 niklas

Some cleanup for -Wall -Wstrict-prototypes


# 1.16 10-Jun-1996 deraadt

tty_attach()


# 1.15 26-May-1996 deraadt

sync 0521


# 1.14 10-May-1996 deraadt

proto change


# 1.13 07-May-1996 deraadt

sync with 0504 -- prototypes and bus.h


# 1.12 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.11 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.10 18-Apr-1996 niklas

NetBSD 960317 merge


# 1.9 20-Mar-1996 mickey

Fix back wrong patches.


# 1.8 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.7 08-Mar-1996 niklas

From NetBSD: merge of 960217


# 1.6 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.5 16-Jan-1996 hvozda

Last of the glue and devices for for PCMCIA support from Stefan Grefen
<grefen@convex.com> with modifications by John Kohl <jtk@kolvir.blrc.ma.us>


# 1.4 03-Jan-1996 deraadt

Patches to use Hayes ESP with com.c; from banshee@gabriella.resort.com;
netbsd pr#1865. the ESP card code is always enabled -- we will have to
see if that fails on any chipsets.


# 1.3 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.


# 1.2 15-Dec-1995 deraadt

update from netbsd


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.169 14-May-2018 kettenis

Add support for register shift/io-width to the console code as well.

ok visa@, patrick@


# 1.168 02-May-2018 kettenis

Revert previous commit; the XR17V35X probe that was added accesses registers
that aren't guaranteed to be there and may even belong to a different device.
This triggers a fault on hppa machines like the C3000 for example.


# 1.167 15-Apr-2018 jcs

The Exar XR17V354 has 4 com ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

ok mlarkin deraadt


# 1.166 02-Apr-2018 kettenis

Add support for register shift/io-width. This allows us to support UARTs
that are mostly NS16550 compatible but use 32-bit instead of 8-bit registers
such as the Synopsys Designware UARTs found on many armv7, arm64 and amd64
SoCs.

tested by florian@, blum@
ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.165 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.164 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.163 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.162 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.161 04-Sep-2016 tedu

remove some more sparc remnants. ok deraadt


# 1.160 03-Sep-2016 jsg

de-zaurus com.c
"looks correct" deraadt@ guenther@ on an earlier rev


# 1.159 16-Aug-2016 kettenis

Only probe the UART type if sc_uarttype is set to COM_UART_UNKNOWN.
This allows glue drivers to set the type based on other information (such as
Oopen Firmware or device tree properties) without going through to risky
code paths.

ok deraadt@, visa@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.158 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.157 13-Apr-2014 deraadt

wrap a long line


Revision tags: OPENBSD_5_5_BASE
# 1.156 09-Dec-2013 deraadt

At resume, do not spin flushing characters in from the chip. There shouldn't
be any characters. If the chip is not actually there for some reason, we'd
be spinning so early in the resume sequence, we'd probably go mad trying to
find the reason..
ok kettenis
request: people with serial ports on their laptops, try to run a "cu" over
a suspend/resume cycle, and see if you see "input noise"


# 1.155 09-Dec-2013 deraadt

At suspend/resume time cope with timeouts, DTR on resume in a bus
bus-independent fashion.
ok kettenis


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.154 14-Feb-2013 kettenis

No need to treat amd64 specially; always return CN_HIGHPRI.

ok miod@


# 1.153 17-Oct-2012 deraadt

Narrow the spltty/splx pair in com_activate to only enclose the minimum
operation which requires it.


# 1.152 25-Aug-2012 kettenis

Better detection of the st16650 v1 (with the broken fifo). Gets rid of
false positives like the DUART on the MPC8347 as found on socppc.

ok deraadt@


# 1.151 25-Aug-2012 kettenis

Turns out the v445 isn't happy at all if we touch the registers that deal
with sleep mode. So skip the wakeup code as well if we are a serial console.
The port on the v445 almost certainly isn't a real st16650 and probably
doesn't implement sleep mode (perhaps someone cut the soft core down a bit
too much?). But it is indistinguishable from it, so we have to deal with it.

ok deraadt@


# 1.150 19-Aug-2012 kettenis

Skip putting a port in sleep mode when it is used as serial console. In that
case the kernel will still be using the port even after the last process closes
it. And on machines like the v445 the firmware won't be happy if the console
port is in sleep mode when the kernel reboots or halts.

ok miod@


Revision tags: OPENBSD_5_2_BASE
# 1.149 12-May-2012 kettenis

Remove unused variable.

ok mpi@, miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.148 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.147 22-May-2011 drahn

Fix a problem found where one SOC has a uart implementation that causes bus
errors if the fifo is read when the fifo is empty. Dont read an empty fifo.
ok deraaadt@ fgsch@


# 1.146 23-Mar-2011 fgsch

only read from the UART if there is something to read. fix beagle, otherwise
it will crash with 'External Non-Linefetch Abort (S)'.
similar diff provided by drahn@. tested by jasper@, deraadt@ ok.


Revision tags: OPENBSD_4_9_BASE
# 1.145 28-Aug-2010 miod

ansify function definitions, and constify a few arrays while there.
no functional change.


Revision tags: OPENBSD_4_8_BASE
# 1.144 07-Aug-2010 kettenis

Add resume support for serial consoles.

Tested by sthen@, ok deraadt@


# 1.143 06-Aug-2010 kettenis

Initial stab at making com@puc suspend and resume properly. Works fine
for using cu(1) between two OpenBSD machines. Probably doesn't work for
serial consoles but we don't support those on puc(4) anyway.

ok deraadt@


# 1.142 02-Jul-2010 nicm

Move common code for waking up writers on a tty into a function.

ok deraadt matthew millert


# 1.141 28-Jun-2010 deraadt

Allow tty drivers to request larger buffers at attach time using a
max-baud-rate hint. Adjust TTYHOG (the nearly full logic) to this new
situation. The larger buffers are required by the very high speed
KDDI devices in Japan (CF com, or USB ucom) so those are the only two
drivers which currently ask for a larger buffer size.
ok yasuoka miod


# 1.140 28-Jun-2010 ckuethe

Use a more moderate fifo trigger level (4) for moderately quick
(sub-38400) port speeds. Inspired by netbsd. ok fgsch krw deraadt miod


# 1.139 26-Jun-2010 guenther

Don't #include <sys/user.h> into files that don't need the stuff
it defines. In some cases, this means pulling in uvm.h or pcb.h
instead, but most of the inclusions were just noise. Tested on
alpha, amd64, armish, hppa, i386, macpcc, sgi, sparc64, and vax,
mostly by krw and naddy.
ok krw@


# 1.138 12-Apr-2010 tedu

Some of the line disciplines want to check for suser. Better to pass them
a process instead of using curproc. ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.137 09-Nov-2009 nicm

Every selwakeup() should have a matching KNOTE() (even if kqueue isn't
supported it doesn't do any harm), so put the KNOTE() in selwakeup() itself and
remove it from any occurences where both are used, except one for kqueue itself
and one in sys_pipe.c (where the selwakeup is under a PIPE_SEL flag).

Based on a diff from tedu.

ok deraadt


# 1.136 04-Nov-2009 kettenis

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@


# 1.135 01-Nov-2009 nicm

Call selwakeup()/KNOTE() even if the queue has emptied completely.

ok miod


# 1.134 31-Oct-2009 fgsch

Use suser when possible. Suggested by miod@.
miod@ deraadt@ ok.


# 1.133 31-Oct-2009 deraadt

Add missing KNOTE() calls after selwakeup(), until we decide if the KNOTE()
calls can go directly into selwakeup() safely
long discussion with nicm, murmers of consent from tedu and miod, noone
else seems to care of kqueue is busted as long as it makes their sockets
move data fast... pretty sad.


# 1.132 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.131 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.130 23-Nov-2008 deraadt

pccom can finally die; ok kettenis dlg drahn, tested by okan


# 1.129 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


Revision tags: OPENBSD_4_4_BASE
# 1.128 08-Jun-2008 kettenis

Make serial console on non-primary ports work to on i386.

tested by jbg@, "it is right" deraadt@


# 1.127 25-Apr-2008 dlg

the code that parses arguments from the boot loader on amd64 wasnt checking
what type of console was specified, so when a glass console was used it was
still configuring serial bits. this makes it so serial config only occurs
for serial console devices.

found by jolan@, thib@, and maybe sthen@
sorry guys


# 1.126 24-Apr-2008 jsing

MD_ISA_IOT is not defined anywhere so get rid of it.

Spotted by drahn@, ok dlg@


# 1.125 24-Apr-2008 jsing

Keep order of "#if defined..." consistent.

ok dlg@


# 1.124 24-Apr-2008 jsing

Clean up comments.


# 1.123 24-Apr-2008 jsing

Cleanup serial console handling and remove some of the MD code from com.c.
Specify the serial configuration from within the MD code, rather than
passing things via macros. This will allow other platforms to more readily
change the serial console configuration.

Committing this so it actually gets tested.

ok dlg@


# 1.122 09-Apr-2008 deraadt

Increase buffer size sent to the fifo, and clamp the size correctly.
Scrub the buffer afterwards, too


Revision tags: OPENBSD_4_3_BASE
# 1.121 23-Jan-2008 jsing

Cleanup cn_pri. Change constants to more meaningful names, rather than
the hp300 related ones currently in use. CN_NORMAL becomes CN_LOWPRI,
CN_INTERNAL becomes CN_MIDPRI and CN_REMOTE becomes CN_HIGHPRI.

ok miod@


# 1.120 12-Jan-2008 miod

Make comconsrate initialized to TTYDEF_SPEED at compile-time, for ports
which need to setup the chip before comcnattach() is invoked.


# 1.119 08-Jan-2008 dlg

the rsc-console on the v880 operates at 115200, not the 9600 we think we
have to force all console devices to. this change passes the right speed
to the com code, and continues to use it when the device is opened as the
console device.

figured out by kettenis@
ok kettenis@ miod@


# 1.118 22-Aug-2007 jasper

fix compilation with KDGB
from Nicholas Marriott

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.117 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.116 22-Jun-2007 jasper

ansify/de-register
no binary change


# 1.115 08-May-2007 deraadt

backout while the amd64 puc situation is rethought


# 1.114 08-May-2007 deraadt

move com_activate() to where it belongs


# 1.113 08-May-2007 deraadt

put more foo_detach() routines where they are used


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.112 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.111 27-Apr-2006 deraadt

2 lines of code in most drivers, to do the timestamping; ok miod kettenis


# 1.110 27-Mar-2006 deraadt

in detach, mark device with COM_SW_DEAD, so that close() will not go
tapping additional registes. allows it to work on macppc, where doing
such a tap after unplug is very bad. drahn helped fkr@bytemine.de
ok miod and drahn


Revision tags: OPENBSD_3_9_BASE
# 1.109 01-Jan-2006 miod

Let cons_init() and cons_init_bell() initialize the whole consdev structure,
thus removing the need for drivers to initialize cn_pri to CN_DEAD when
hardware probe fails.


# 1.108 21-Nov-2005 millert

Move contents of sys/select.h to sys/selinfo.h in preparation for a
userland-visible sys/select.h. Consistent with what Net and Free do.
OK deraadt@, tested with full ports build by naddy@.


# 1.107 11-Nov-2005 fgsch

fix kgdb compilation; input and ok miod@.


# 1.106 26-Sep-2005 miod

Share com probe code between com and pccom; allows us to get rid of awkward
code duplication in cardbus, pcmcia and puc attachments.

Joint effort with fgs@; blessed deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.105 18-Jul-2005 deraadt

fix sparc64 console; same diff as miod


# 1.104 18-Jul-2005 deraadt

COM_CONSOLE & DDB fix


# 1.103 17-Jul-2005 miod

Allow the console support code not to be compiled in; this will be
necessary for and only used on sparc, shortly.

Reluctantely ok deraadt@


# 1.102 11-Jul-2005 uwe

Enable IR receive mode only for infrared capable PXA2x0 UARTs. Normal
reception is blocked while the IR receiver or transmitter is enabled.

Also enable the PXA2x0 UART before clearing the FIFO (suggested by
drahn@ some time ago), and disable the UART in compwroff().

ok deraadt@


# 1.101 02-Jul-2005 uwe

xscale UART FIFOs are 32 bytes deep; found by deraadt@


# 1.100 27-May-2005 uwe

- Merge changes from pxacom back into the common com driver.

Changes to the common com driver (partly from NetBSD):
- Multiply before divide in comspeed() to avoid overflow (from NetBSD).
- Don't call getc() and send -1 if the output queue is empty.
- Take UART clock frequency as a parameter instead of using COM_FREQ.

ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.99 20-Oct-2004 pefo

Use bus_addr_t instead of int for port address/offset, ok mickey


Revision tags: OPENBSD_3_6_BASE
# 1.98 09-Aug-2004 pefo

remove old arc stuff and add sgi support.
ok mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.97 30-May-2004 deraadt

serial console hack from tom. who, after having been told a few times
to commit it, has not. what is going on guys?


# 1.96 03-May-2004 drahn

Remove OpenBSD/pegaos, this has been announced before but delayed until
the tree was stable. No point in code supporting a company which screws
its employees being in the OpenBSD tree.


Revision tags: OPENBSD_3_5_BASE
# 1.95 31-Oct-2003 drahn

Use isa iot for pegasos com console attachment, perhaps this could
be adopted MI?


# 1.94 03-Oct-2003 miod

Merge tty_attach() in ttymalloc() and tty_detach() in ttyfree(). The need for
separate tty registering is gone now that sparc has switched to wscons, and
this makes the code less error-prone.

Also, remove tests for ttymalloc() failure, since it uses M_WAITOK.

ok millert@ deraadt@, tested by various people as well besides me...


# 1.93 23-Sep-2003 millert

Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater
poll(2) functionality instead of emulating it via the select backend.
Adapted from NetBSD and including some changes from FreeBSD.
Tested by many, deraadt@ OK


Revision tags: OPENBSD_3_4_BASE
# 1.92 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.91 15-Jul-2003 jason

move prototype for com_raisedtr() to comvar.h (just like pccom).


# 1.90 03-Jun-2003 deraadt

terms 3 & 4 cleanup based on "terms" file


# 1.89 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.88 19-Dec-2002 mickey

comparam() does not need an spltty() for it, already called there.
time-bound loops in com_common_cnputc() and lower to spltty(),
which i guess is left from times when timeouts were processed at splhigh().
jason@ tested and ok, art@ ok


Revision tags: UBC_SYNC_B
# 1.87 17-Oct-2002 art

ifndef __HAVE_GENERIC_SOFT_INTERRUPTS leaved a label without a statement after it. Fix.


Revision tags: OPENBSD_3_2_BASE
# 1.86 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.85 11-Jun-2002 miod

com.c is not a block device, no bdev_decl() for it.


Revision tags: OPENBSD_3_1_BASE
# 1.84 09-Apr-2002 pefo

Don't enable interrupts until an open() is done. Until then the driver
is not handling them and may throw the kernel into a spurious interrupt
loop. ok art@


# 1.83 14-Mar-2002 millert

First round of __P removal in sys


# 1.82 14-Mar-2002 jason

compare pointers with NULL not 0


# 1.81 05-Feb-2002 mickey

restore CN_REMOTE priority, as it always was there.
anyway, only i386 uses that path and only if forced anyway.
also do not do comprobe1() on hppa since that hoses the port.


# 1.80 30-Jan-2002 nordin

Move SET/CLR/ISSET macros to param.h. fgsch@ and millert@ ok


# 1.79 25-Jan-2002 mickey

CONADDR is defined elsewhere for hppa


# 1.78 23-Jan-2002 ericj

oops, make the kgdb var's non-static


# 1.77 23-Jan-2002 ericj

allow this to compile with KGDB


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.76 05-Oct-2001 mickey

branches: 1.76.4;
restore some of that dead code needed for dev/cons functionality


# 1.75 02-Oct-2001 art

#ifdef FOO works much better when FOO isn't misspelled.


# 1.74 30-Sep-2001 art

Enable break interrupt earlier.


# 1.73 30-Sep-2001 art

Next round of cleanups.
- some KNF.
- disable interrupts earlier in attach.
- give it some more time in attach to finish earlier output.
- explicit bus_space_barrier in comcnputc.
- dead code.


# 1.72 30-Sep-2001 art

Remove dead code.


# 1.71 30-Sep-2001 art

Remove the COM_HAYESP code. It doesn't appear to have been ever used and
it's very intrusive and makes the code less readable.


# 1.70 30-Sep-2001 art

Move out the com at commulti attachment into an ownfile.
Same story as isapnp - not tested because i386 uses pccom.


# 1.69 30-Sep-2001 art

Move out com at isapnp attachment into an own file.
Not tested because the only system with isapnp is i386 and i386 uses pccom.


# 1.68 29-Sep-2001 art

Next step in making the com driver improvable.
Split out the com at isa attachment into its own file.


# 1.67 29-Sep-2001 art

- compoll is now scheduled once for every sc instead of just one timeout for
all ports and looping over them.
- support for generic soft interrupts.


# 1.66 27-Sep-2001 art

Simplify comstart a bit.


# 1.65 27-Sep-2001 millert

Enable #if 0'd code in comcnputc() so serial console works correctly;
art@openbsd.org


# 1.64 27-Sep-2001 art

Split out comattach that does isa and isapnp attachment and initialization,
into comattach that does the isa stuff and com_attach_subr that does the
init.


Revision tags: OPENBSD_2_9_BASE
# 1.63 17-Apr-2001 aaron

Implement cnbell(), an optional entrypoint that rings the console bell; from
NetBSD. deraadt@ ok


# 1.62 15-Mar-2001 art

Put back new timeouts. This time with correct timeout for compoll.


# 1.61 15-Mar-2001 deraadt

typo


# 1.60 15-Mar-2001 art

back out new timeouts until I find out why they break alpha.


# 1.59 15-Mar-2001 deraadt

support puc devices with higher speeds (not tested yet)


# 1.58 13-Mar-2001 mickey

new timeouts


# 1.57 24-Jan-2001 hugh

KGDB for i386 from NetBSD via niklas, with tweaks and accommodations.
Tested by various, vetted by mickey & theo.


# 1.56 08-Nov-2000 art

Add comcnattach that does the basic steps needed to attach
a com as a serial console. (idea from NetBSD).

If cn_tab->cn_dev == NODEV, try to find comopen in cdevsw and set cn_dev
to the right device.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE SMP_BASE
# 1.55 27-Jan-2000 mickey

branches: 1.55.2;
isa-avoidance


# 1.54 11-Jan-2000 mickey

a few ifdef accomodations for hppa, also a few knf spaces


Revision tags: kame_19991208
# 1.53 28-Nov-1999 downsj

Enable TI16750 UART support.


# 1.52 09-Nov-1999 rahnds

in the ifdef POWERPC section, do use ppc, not p4e, for the iohandle
for the console configuration.


# 1.51 26-Oct-1999 downsj

This file has my code in it, attach my copyright.


Revision tags: OPENBSD_2_6_BASE
# 1.50 08-Aug-1999 niklas

pasto from pccom.c


# 1.49 08-Aug-1999 niklas

revert function accidentally committed


# 1.48 08-Aug-1999 niklas

Detach support for com; NetBSD and me


# 1.47 26-Jul-1999 niklas

Move over the ISA PnP support from pccom.c to com.c


# 1.46 26-Jul-1999 niklas

fix my last commit where I committed more than intended


# 1.45 26-Jul-1999 niklas

Remove obsolete detach code that has been dead for very long


# 1.44 25-Jun-1999 rees

Don't turn off uart when closing cua device if tty is waiting.
Instead just drop dtr briefly.


Revision tags: OPENBSD_2_5_BASE
# 1.43 09-Feb-1999 rees

Fix cua device to not block on open.
Turn off chip (and dtr) on interrupted open.


# 1.42 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.41 20-Sep-1998 rahnds

Powerpc port uses com.c not just power4e.


# 1.40 18-Aug-1998 pefo

Remove clearing of interrupt after character output in cnputci(). Clearing
the int will make the tty stop if output is currently active.


# 1.39 07-Aug-1998 pefo

com.c needs to know about mem mapped ports in ppc systems.

ncr.c and if_de.c needs some hooks for systems with ncr and dec
ether chips on the motherboard that runs on odd clocks and doesn't
support a srom. srom is emulated in machine dependent code.

big endian support for ncr and dec ether finished. the 21040
have some more coding requirements if it is to run BE since
it does not have the descriptor endian swap configuration bit.


Revision tags: OPENBSD_2_3_BASE
# 1.38 23-Feb-1998 downsj

New probe routine and support for ST16650.

Compiles, but completely untested.


# 1.37 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


Revision tags: OPENBSD_2_2_BASE
# 1.36 03-Sep-1997 deraadt

fix cua/tty locking


# 1.35 07-Jul-1997 niklas

Removed an unused arg


Revision tags: OPENBSD_2_1_BASE
# 1.34 10-Apr-1997 pefo

Need to separate i/o and mem on mips


# 1.33 17-Mar-1997 pefo

Serial console trouble again...


# 1.32 12-Mar-1997 pefo

The stupid "use console before configured" scheeme strikes again :-)


# 1.31 06-Mar-1997 tholo

Initial implementation of support for calling hardpps() on carrier enable


# 1.30 10-Dec-1996 deraadt

the real changes by niklas... I did not merge correctly


# 1.29 10-Dec-1996 deraadt

clr TS_WOPEN if bailing on cua opens
As well, at this point I've also done fancy cvs repository mangling to
ensure that the com* files in sys/dev/ic maintain the history we had
before. (Yes, I cleaned up the 2.0 tags too..)


# 1.28 29-Nov-1996 niklas

Missing pieces of new bus.h that CVS lost behind my back


# 1.27 12-Nov-1996 niklas

s/bus.h/bus.old.h/ to make the transit to the bus_space bus.h an easy road
possibly taken in small steps


# 1.26 09-Nov-1996 tholo

Break shall be handled as data == 0 and FE bit set; from Theo


# 1.25 30-Oct-1996 niklas

cominit is used from the outside (the alpha port)


# 1.24 22-Oct-1996 downsj

patch com speed initialization


# 1.23 16-Oct-1996 deraadt

contextual usage


# 1.22 16-Oct-1996 deraadt

unused variables


# 1.21 29-Aug-1996 deraadt

sunos-like cua behaviour; inspired by budd@cs.bu.edu in his scn.c


# 1.20 02-Jul-1996 downsj

better FIFO enabling code; netbsd pr#2574, cliff@wport.com


# 1.19 24-Jun-1996 pefo

pica changes backed out. does not belong here


# 1.18 22-Jun-1996 pefo

Pica bus support added


# 1.17 10-Jun-1996 niklas

Some cleanup for -Wall -Wstrict-prototypes


# 1.16 10-Jun-1996 deraadt

tty_attach()


# 1.15 26-May-1996 deraadt

sync 0521


# 1.14 10-May-1996 deraadt

proto change


# 1.13 07-May-1996 deraadt

sync with 0504 -- prototypes and bus.h


# 1.12 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.11 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.10 18-Apr-1996 niklas

NetBSD 960317 merge


# 1.9 20-Mar-1996 mickey

Fix back wrong patches.


# 1.8 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.7 08-Mar-1996 niklas

From NetBSD: merge of 960217


# 1.6 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.5 16-Jan-1996 hvozda

Last of the glue and devices for for PCMCIA support from Stefan Grefen
<grefen@convex.com> with modifications by John Kohl <jtk@kolvir.blrc.ma.us>


# 1.4 03-Jan-1996 deraadt

Patches to use Hayes ESP with com.c; from banshee@gabriella.resort.com;
netbsd pr#1865. the ESP card code is always enabled -- we will have to
see if that fails on any chipsets.


# 1.3 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.


# 1.2 15-Dec-1995 deraadt

update from netbsd


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.168 02-May-2018 kettenis

Revert previous commit; the XR17V35X probe that was added accesses registers
that aren't guaranteed to be there and may even belong to a different device.
This triggers a fault on hppa machines like the C3000 for example.


# 1.167 15-Apr-2018 jcs

The Exar XR17V354 has 4 com ports that have a 256-byte FIFO, use a
frequency of 125Mhz, and have a unique sleep register. A custom
interrupt handler is setup in puc for these ports so it can check a
register which reports which ports triggered the interrupt, rather
than having to run comintr for every port every time.

ok mlarkin deraadt


# 1.166 02-Apr-2018 kettenis

Add support for register shift/io-width. This allows us to support UARTs
that are mostly NS16550 compatible but use 32-bit instead of 8-bit registers
such as the Synopsys Designware UARTs found on many armv7, arm64 and amd64
SoCs.

tested by florian@, blum@
ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.165 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.164 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.163 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.162 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.161 04-Sep-2016 tedu

remove some more sparc remnants. ok deraadt


# 1.160 03-Sep-2016 jsg

de-zaurus com.c
"looks correct" deraadt@ guenther@ on an earlier rev


# 1.159 16-Aug-2016 kettenis

Only probe the UART type if sc_uarttype is set to COM_UART_UNKNOWN.
This allows glue drivers to set the type based on other information (such as
Oopen Firmware or device tree properties) without going through to risky
code paths.

ok deraadt@, visa@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.158 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.157 13-Apr-2014 deraadt

wrap a long line


Revision tags: OPENBSD_5_5_BASE
# 1.156 09-Dec-2013 deraadt

At resume, do not spin flushing characters in from the chip. There shouldn't
be any characters. If the chip is not actually there for some reason, we'd
be spinning so early in the resume sequence, we'd probably go mad trying to
find the reason..
ok kettenis
request: people with serial ports on their laptops, try to run a "cu" over
a suspend/resume cycle, and see if you see "input noise"


# 1.155 09-Dec-2013 deraadt

At suspend/resume time cope with timeouts, DTR on resume in a bus
bus-independent fashion.
ok kettenis


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.154 14-Feb-2013 kettenis

No need to treat amd64 specially; always return CN_HIGHPRI.

ok miod@


# 1.153 17-Oct-2012 deraadt

Narrow the spltty/splx pair in com_activate to only enclose the minimum
operation which requires it.


# 1.152 25-Aug-2012 kettenis

Better detection of the st16650 v1 (with the broken fifo). Gets rid of
false positives like the DUART on the MPC8347 as found on socppc.

ok deraadt@


# 1.151 25-Aug-2012 kettenis

Turns out the v445 isn't happy at all if we touch the registers that deal
with sleep mode. So skip the wakeup code as well if we are a serial console.
The port on the v445 almost certainly isn't a real st16650 and probably
doesn't implement sleep mode (perhaps someone cut the soft core down a bit
too much?). But it is indistinguishable from it, so we have to deal with it.

ok deraadt@


# 1.150 19-Aug-2012 kettenis

Skip putting a port in sleep mode when it is used as serial console. In that
case the kernel will still be using the port even after the last process closes
it. And on machines like the v445 the firmware won't be happy if the console
port is in sleep mode when the kernel reboots or halts.

ok miod@


Revision tags: OPENBSD_5_2_BASE
# 1.149 12-May-2012 kettenis

Remove unused variable.

ok mpi@, miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.148 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.147 22-May-2011 drahn

Fix a problem found where one SOC has a uart implementation that causes bus
errors if the fifo is read when the fifo is empty. Dont read an empty fifo.
ok deraaadt@ fgsch@


# 1.146 23-Mar-2011 fgsch

only read from the UART if there is something to read. fix beagle, otherwise
it will crash with 'External Non-Linefetch Abort (S)'.
similar diff provided by drahn@. tested by jasper@, deraadt@ ok.


Revision tags: OPENBSD_4_9_BASE
# 1.145 28-Aug-2010 miod

ansify function definitions, and constify a few arrays while there.
no functional change.


Revision tags: OPENBSD_4_8_BASE
# 1.144 07-Aug-2010 kettenis

Add resume support for serial consoles.

Tested by sthen@, ok deraadt@


# 1.143 06-Aug-2010 kettenis

Initial stab at making com@puc suspend and resume properly. Works fine
for using cu(1) between two OpenBSD machines. Probably doesn't work for
serial consoles but we don't support those on puc(4) anyway.

ok deraadt@


# 1.142 02-Jul-2010 nicm

Move common code for waking up writers on a tty into a function.

ok deraadt matthew millert


# 1.141 28-Jun-2010 deraadt

Allow tty drivers to request larger buffers at attach time using a
max-baud-rate hint. Adjust TTYHOG (the nearly full logic) to this new
situation. The larger buffers are required by the very high speed
KDDI devices in Japan (CF com, or USB ucom) so those are the only two
drivers which currently ask for a larger buffer size.
ok yasuoka miod


# 1.140 28-Jun-2010 ckuethe

Use a more moderate fifo trigger level (4) for moderately quick
(sub-38400) port speeds. Inspired by netbsd. ok fgsch krw deraadt miod


# 1.139 26-Jun-2010 guenther

Don't #include <sys/user.h> into files that don't need the stuff
it defines. In some cases, this means pulling in uvm.h or pcb.h
instead, but most of the inclusions were just noise. Tested on
alpha, amd64, armish, hppa, i386, macpcc, sgi, sparc64, and vax,
mostly by krw and naddy.
ok krw@


# 1.138 12-Apr-2010 tedu

Some of the line disciplines want to check for suser. Better to pass them
a process instead of using curproc. ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.137 09-Nov-2009 nicm

Every selwakeup() should have a matching KNOTE() (even if kqueue isn't
supported it doesn't do any harm), so put the KNOTE() in selwakeup() itself and
remove it from any occurences where both are used, except one for kqueue itself
and one in sys_pipe.c (where the selwakeup is under a PIPE_SEL flag).

Based on a diff from tedu.

ok deraadt


# 1.136 04-Nov-2009 kettenis

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@


# 1.135 01-Nov-2009 nicm

Call selwakeup()/KNOTE() even if the queue has emptied completely.

ok miod


# 1.134 31-Oct-2009 fgsch

Use suser when possible. Suggested by miod@.
miod@ deraadt@ ok.


# 1.133 31-Oct-2009 deraadt

Add missing KNOTE() calls after selwakeup(), until we decide if the KNOTE()
calls can go directly into selwakeup() safely
long discussion with nicm, murmers of consent from tedu and miod, noone
else seems to care of kqueue is busted as long as it makes their sockets
move data fast... pretty sad.


# 1.132 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.131 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.130 23-Nov-2008 deraadt

pccom can finally die; ok kettenis dlg drahn, tested by okan


# 1.129 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


Revision tags: OPENBSD_4_4_BASE
# 1.128 08-Jun-2008 kettenis

Make serial console on non-primary ports work to on i386.

tested by jbg@, "it is right" deraadt@


# 1.127 25-Apr-2008 dlg

the code that parses arguments from the boot loader on amd64 wasnt checking
what type of console was specified, so when a glass console was used it was
still configuring serial bits. this makes it so serial config only occurs
for serial console devices.

found by jolan@, thib@, and maybe sthen@
sorry guys


# 1.126 24-Apr-2008 jsing

MD_ISA_IOT is not defined anywhere so get rid of it.

Spotted by drahn@, ok dlg@


# 1.125 24-Apr-2008 jsing

Keep order of "#if defined..." consistent.

ok dlg@


# 1.124 24-Apr-2008 jsing

Clean up comments.


# 1.123 24-Apr-2008 jsing

Cleanup serial console handling and remove some of the MD code from com.c.
Specify the serial configuration from within the MD code, rather than
passing things via macros. This will allow other platforms to more readily
change the serial console configuration.

Committing this so it actually gets tested.

ok dlg@


# 1.122 09-Apr-2008 deraadt

Increase buffer size sent to the fifo, and clamp the size correctly.
Scrub the buffer afterwards, too


Revision tags: OPENBSD_4_3_BASE
# 1.121 23-Jan-2008 jsing

Cleanup cn_pri. Change constants to more meaningful names, rather than
the hp300 related ones currently in use. CN_NORMAL becomes CN_LOWPRI,
CN_INTERNAL becomes CN_MIDPRI and CN_REMOTE becomes CN_HIGHPRI.

ok miod@


# 1.120 12-Jan-2008 miod

Make comconsrate initialized to TTYDEF_SPEED at compile-time, for ports
which need to setup the chip before comcnattach() is invoked.


# 1.119 08-Jan-2008 dlg

the rsc-console on the v880 operates at 115200, not the 9600 we think we
have to force all console devices to. this change passes the right speed
to the com code, and continues to use it when the device is opened as the
console device.

figured out by kettenis@
ok kettenis@ miod@


# 1.118 22-Aug-2007 jasper

fix compilation with KDGB
from Nicholas Marriott

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.117 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.116 22-Jun-2007 jasper

ansify/de-register
no binary change


# 1.115 08-May-2007 deraadt

backout while the amd64 puc situation is rethought


# 1.114 08-May-2007 deraadt

move com_activate() to where it belongs


# 1.113 08-May-2007 deraadt

put more foo_detach() routines where they are used


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.112 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.111 27-Apr-2006 deraadt

2 lines of code in most drivers, to do the timestamping; ok miod kettenis


# 1.110 27-Mar-2006 deraadt

in detach, mark device with COM_SW_DEAD, so that close() will not go
tapping additional registes. allows it to work on macppc, where doing
such a tap after unplug is very bad. drahn helped fkr@bytemine.de
ok miod and drahn


Revision tags: OPENBSD_3_9_BASE
# 1.109 01-Jan-2006 miod

Let cons_init() and cons_init_bell() initialize the whole consdev structure,
thus removing the need for drivers to initialize cn_pri to CN_DEAD when
hardware probe fails.


# 1.108 21-Nov-2005 millert

Move contents of sys/select.h to sys/selinfo.h in preparation for a
userland-visible sys/select.h. Consistent with what Net and Free do.
OK deraadt@, tested with full ports build by naddy@.


# 1.107 11-Nov-2005 fgsch

fix kgdb compilation; input and ok miod@.


# 1.106 26-Sep-2005 miod

Share com probe code between com and pccom; allows us to get rid of awkward
code duplication in cardbus, pcmcia and puc attachments.

Joint effort with fgs@; blessed deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.105 18-Jul-2005 deraadt

fix sparc64 console; same diff as miod


# 1.104 18-Jul-2005 deraadt

COM_CONSOLE & DDB fix


# 1.103 17-Jul-2005 miod

Allow the console support code not to be compiled in; this will be
necessary for and only used on sparc, shortly.

Reluctantely ok deraadt@


# 1.102 11-Jul-2005 uwe

Enable IR receive mode only for infrared capable PXA2x0 UARTs. Normal
reception is blocked while the IR receiver or transmitter is enabled.

Also enable the PXA2x0 UART before clearing the FIFO (suggested by
drahn@ some time ago), and disable the UART in compwroff().

ok deraadt@


# 1.101 02-Jul-2005 uwe

xscale UART FIFOs are 32 bytes deep; found by deraadt@


# 1.100 27-May-2005 uwe

- Merge changes from pxacom back into the common com driver.

Changes to the common com driver (partly from NetBSD):
- Multiply before divide in comspeed() to avoid overflow (from NetBSD).
- Don't call getc() and send -1 if the output queue is empty.
- Take UART clock frequency as a parameter instead of using COM_FREQ.

ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.99 20-Oct-2004 pefo

Use bus_addr_t instead of int for port address/offset, ok mickey


Revision tags: OPENBSD_3_6_BASE
# 1.98 09-Aug-2004 pefo

remove old arc stuff and add sgi support.
ok mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.97 30-May-2004 deraadt

serial console hack from tom. who, after having been told a few times
to commit it, has not. what is going on guys?


# 1.96 03-May-2004 drahn

Remove OpenBSD/pegaos, this has been announced before but delayed until
the tree was stable. No point in code supporting a company which screws
its employees being in the OpenBSD tree.


Revision tags: OPENBSD_3_5_BASE
# 1.95 31-Oct-2003 drahn

Use isa iot for pegasos com console attachment, perhaps this could
be adopted MI?


# 1.94 03-Oct-2003 miod

Merge tty_attach() in ttymalloc() and tty_detach() in ttyfree(). The need for
separate tty registering is gone now that sparc has switched to wscons, and
this makes the code less error-prone.

Also, remove tests for ttymalloc() failure, since it uses M_WAITOK.

ok millert@ deraadt@, tested by various people as well besides me...


# 1.93 23-Sep-2003 millert

Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater
poll(2) functionality instead of emulating it via the select backend.
Adapted from NetBSD and including some changes from FreeBSD.
Tested by many, deraadt@ OK


Revision tags: OPENBSD_3_4_BASE
# 1.92 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.91 15-Jul-2003 jason

move prototype for com_raisedtr() to comvar.h (just like pccom).


# 1.90 03-Jun-2003 deraadt

terms 3 & 4 cleanup based on "terms" file


# 1.89 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.88 19-Dec-2002 mickey

comparam() does not need an spltty() for it, already called there.
time-bound loops in com_common_cnputc() and lower to spltty(),
which i guess is left from times when timeouts were processed at splhigh().
jason@ tested and ok, art@ ok


Revision tags: UBC_SYNC_B
# 1.87 17-Oct-2002 art

ifndef __HAVE_GENERIC_SOFT_INTERRUPTS leaved a label without a statement after it. Fix.


Revision tags: OPENBSD_3_2_BASE
# 1.86 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.85 11-Jun-2002 miod

com.c is not a block device, no bdev_decl() for it.


Revision tags: OPENBSD_3_1_BASE
# 1.84 09-Apr-2002 pefo

Don't enable interrupts until an open() is done. Until then the driver
is not handling them and may throw the kernel into a spurious interrupt
loop. ok art@


# 1.83 14-Mar-2002 millert

First round of __P removal in sys


# 1.82 14-Mar-2002 jason

compare pointers with NULL not 0


# 1.81 05-Feb-2002 mickey

restore CN_REMOTE priority, as it always was there.
anyway, only i386 uses that path and only if forced anyway.
also do not do comprobe1() on hppa since that hoses the port.


# 1.80 30-Jan-2002 nordin

Move SET/CLR/ISSET macros to param.h. fgsch@ and millert@ ok


# 1.79 25-Jan-2002 mickey

CONADDR is defined elsewhere for hppa


# 1.78 23-Jan-2002 ericj

oops, make the kgdb var's non-static


# 1.77 23-Jan-2002 ericj

allow this to compile with KGDB


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.76 05-Oct-2001 mickey

branches: 1.76.4;
restore some of that dead code needed for dev/cons functionality


# 1.75 02-Oct-2001 art

#ifdef FOO works much better when FOO isn't misspelled.


# 1.74 30-Sep-2001 art

Enable break interrupt earlier.


# 1.73 30-Sep-2001 art

Next round of cleanups.
- some KNF.
- disable interrupts earlier in attach.
- give it some more time in attach to finish earlier output.
- explicit bus_space_barrier in comcnputc.
- dead code.


# 1.72 30-Sep-2001 art

Remove dead code.


# 1.71 30-Sep-2001 art

Remove the COM_HAYESP code. It doesn't appear to have been ever used and
it's very intrusive and makes the code less readable.


# 1.70 30-Sep-2001 art

Move out the com at commulti attachment into an ownfile.
Same story as isapnp - not tested because i386 uses pccom.


# 1.69 30-Sep-2001 art

Move out com at isapnp attachment into an own file.
Not tested because the only system with isapnp is i386 and i386 uses pccom.


# 1.68 29-Sep-2001 art

Next step in making the com driver improvable.
Split out the com at isa attachment into its own file.


# 1.67 29-Sep-2001 art

- compoll is now scheduled once for every sc instead of just one timeout for
all ports and looping over them.
- support for generic soft interrupts.


# 1.66 27-Sep-2001 art

Simplify comstart a bit.


# 1.65 27-Sep-2001 millert

Enable #if 0'd code in comcnputc() so serial console works correctly;
art@openbsd.org


# 1.64 27-Sep-2001 art

Split out comattach that does isa and isapnp attachment and initialization,
into comattach that does the isa stuff and com_attach_subr that does the
init.


Revision tags: OPENBSD_2_9_BASE
# 1.63 17-Apr-2001 aaron

Implement cnbell(), an optional entrypoint that rings the console bell; from
NetBSD. deraadt@ ok


# 1.62 15-Mar-2001 art

Put back new timeouts. This time with correct timeout for compoll.


# 1.61 15-Mar-2001 deraadt

typo


# 1.60 15-Mar-2001 art

back out new timeouts until I find out why they break alpha.


# 1.59 15-Mar-2001 deraadt

support puc devices with higher speeds (not tested yet)


# 1.58 13-Mar-2001 mickey

new timeouts


# 1.57 24-Jan-2001 hugh

KGDB for i386 from NetBSD via niklas, with tweaks and accommodations.
Tested by various, vetted by mickey & theo.


# 1.56 08-Nov-2000 art

Add comcnattach that does the basic steps needed to attach
a com as a serial console. (idea from NetBSD).

If cn_tab->cn_dev == NODEV, try to find comopen in cdevsw and set cn_dev
to the right device.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE SMP_BASE
# 1.55 27-Jan-2000 mickey

branches: 1.55.2;
isa-avoidance


# 1.54 11-Jan-2000 mickey

a few ifdef accomodations for hppa, also a few knf spaces


Revision tags: kame_19991208
# 1.53 28-Nov-1999 downsj

Enable TI16750 UART support.


# 1.52 09-Nov-1999 rahnds

in the ifdef POWERPC section, do use ppc, not p4e, for the iohandle
for the console configuration.


# 1.51 26-Oct-1999 downsj

This file has my code in it, attach my copyright.


Revision tags: OPENBSD_2_6_BASE
# 1.50 08-Aug-1999 niklas

pasto from pccom.c


# 1.49 08-Aug-1999 niklas

revert function accidentally committed


# 1.48 08-Aug-1999 niklas

Detach support for com; NetBSD and me


# 1.47 26-Jul-1999 niklas

Move over the ISA PnP support from pccom.c to com.c


# 1.46 26-Jul-1999 niklas

fix my last commit where I committed more than intended


# 1.45 26-Jul-1999 niklas

Remove obsolete detach code that has been dead for very long


# 1.44 25-Jun-1999 rees

Don't turn off uart when closing cua device if tty is waiting.
Instead just drop dtr briefly.


Revision tags: OPENBSD_2_5_BASE
# 1.43 09-Feb-1999 rees

Fix cua device to not block on open.
Turn off chip (and dtr) on interrupted open.


# 1.42 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.41 20-Sep-1998 rahnds

Powerpc port uses com.c not just power4e.


# 1.40 18-Aug-1998 pefo

Remove clearing of interrupt after character output in cnputci(). Clearing
the int will make the tty stop if output is currently active.


# 1.39 07-Aug-1998 pefo

com.c needs to know about mem mapped ports in ppc systems.

ncr.c and if_de.c needs some hooks for systems with ncr and dec
ether chips on the motherboard that runs on odd clocks and doesn't
support a srom. srom is emulated in machine dependent code.

big endian support for ncr and dec ether finished. the 21040
have some more coding requirements if it is to run BE since
it does not have the descriptor endian swap configuration bit.


Revision tags: OPENBSD_2_3_BASE
# 1.38 23-Feb-1998 downsj

New probe routine and support for ST16650.

Compiles, but completely untested.


# 1.37 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


Revision tags: OPENBSD_2_2_BASE
# 1.36 03-Sep-1997 deraadt

fix cua/tty locking


# 1.35 07-Jul-1997 niklas

Removed an unused arg


Revision tags: OPENBSD_2_1_BASE
# 1.34 10-Apr-1997 pefo

Need to separate i/o and mem on mips


# 1.33 17-Mar-1997 pefo

Serial console trouble again...


# 1.32 12-Mar-1997 pefo

The stupid "use console before configured" scheeme strikes again :-)


# 1.31 06-Mar-1997 tholo

Initial implementation of support for calling hardpps() on carrier enable


# 1.30 10-Dec-1996 deraadt

the real changes by niklas... I did not merge correctly


# 1.29 10-Dec-1996 deraadt

clr TS_WOPEN if bailing on cua opens
As well, at this point I've also done fancy cvs repository mangling to
ensure that the com* files in sys/dev/ic maintain the history we had
before. (Yes, I cleaned up the 2.0 tags too..)


# 1.28 29-Nov-1996 niklas

Missing pieces of new bus.h that CVS lost behind my back


# 1.27 12-Nov-1996 niklas

s/bus.h/bus.old.h/ to make the transit to the bus_space bus.h an easy road
possibly taken in small steps


# 1.26 09-Nov-1996 tholo

Break shall be handled as data == 0 and FE bit set; from Theo


# 1.25 30-Oct-1996 niklas

cominit is used from the outside (the alpha port)


# 1.24 22-Oct-1996 downsj

patch com speed initialization


# 1.23 16-Oct-1996 deraadt

contextual usage


# 1.22 16-Oct-1996 deraadt

unused variables


# 1.21 29-Aug-1996 deraadt

sunos-like cua behaviour; inspired by budd@cs.bu.edu in his scn.c


# 1.20 02-Jul-1996 downsj

better FIFO enabling code; netbsd pr#2574, cliff@wport.com


# 1.19 24-Jun-1996 pefo

pica changes backed out. does not belong here


# 1.18 22-Jun-1996 pefo

Pica bus support added


# 1.17 10-Jun-1996 niklas

Some cleanup for -Wall -Wstrict-prototypes


# 1.16 10-Jun-1996 deraadt

tty_attach()


# 1.15 26-May-1996 deraadt

sync 0521


# 1.14 10-May-1996 deraadt

proto change


# 1.13 07-May-1996 deraadt

sync with 0504 -- prototypes and bus.h


# 1.12 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.11 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.10 18-Apr-1996 niklas

NetBSD 960317 merge


# 1.9 20-Mar-1996 mickey

Fix back wrong patches.


# 1.8 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.7 08-Mar-1996 niklas

From NetBSD: merge of 960217


# 1.6 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.5 16-Jan-1996 hvozda

Last of the glue and devices for for PCMCIA support from Stefan Grefen
<grefen@convex.com> with modifications by John Kohl <jtk@kolvir.blrc.ma.us>


# 1.4 03-Jan-1996 deraadt

Patches to use Hayes ESP with com.c; from banshee@gabriella.resort.com;
netbsd pr#1865. the ESP card code is always enabled -- we will have to
see if that fails on any chipsets.


# 1.3 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.


# 1.2 15-Dec-1995 deraadt

update from netbsd


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.166 02-Apr-2018 kettenis

Add support for register shift/io-width. This allows us to support UARTs
that are mostly NS16550 compatible but use 32-bit instead of 8-bit registers
such as the Synopsys Designware UARTs found on many armv7, arm64 and amd64
SoCs.

tested by florian@, blum@
ok deraadt@


Revision tags: OPENBSD_6_3_BASE
# 1.165 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.164 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.163 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.162 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.161 04-Sep-2016 tedu

remove some more sparc remnants. ok deraadt


# 1.160 03-Sep-2016 jsg

de-zaurus com.c
"looks correct" deraadt@ guenther@ on an earlier rev


# 1.159 16-Aug-2016 kettenis

Only probe the UART type if sc_uarttype is set to COM_UART_UNKNOWN.
This allows glue drivers to set the type based on other information (such as
Oopen Firmware or device tree properties) without going through to risky
code paths.

ok deraadt@, visa@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.158 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.157 13-Apr-2014 deraadt

wrap a long line


Revision tags: OPENBSD_5_5_BASE
# 1.156 09-Dec-2013 deraadt

At resume, do not spin flushing characters in from the chip. There shouldn't
be any characters. If the chip is not actually there for some reason, we'd
be spinning so early in the resume sequence, we'd probably go mad trying to
find the reason..
ok kettenis
request: people with serial ports on their laptops, try to run a "cu" over
a suspend/resume cycle, and see if you see "input noise"


# 1.155 09-Dec-2013 deraadt

At suspend/resume time cope with timeouts, DTR on resume in a bus
bus-independent fashion.
ok kettenis


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.154 14-Feb-2013 kettenis

No need to treat amd64 specially; always return CN_HIGHPRI.

ok miod@


# 1.153 17-Oct-2012 deraadt

Narrow the spltty/splx pair in com_activate to only enclose the minimum
operation which requires it.


# 1.152 25-Aug-2012 kettenis

Better detection of the st16650 v1 (with the broken fifo). Gets rid of
false positives like the DUART on the MPC8347 as found on socppc.

ok deraadt@


# 1.151 25-Aug-2012 kettenis

Turns out the v445 isn't happy at all if we touch the registers that deal
with sleep mode. So skip the wakeup code as well if we are a serial console.
The port on the v445 almost certainly isn't a real st16650 and probably
doesn't implement sleep mode (perhaps someone cut the soft core down a bit
too much?). But it is indistinguishable from it, so we have to deal with it.

ok deraadt@


# 1.150 19-Aug-2012 kettenis

Skip putting a port in sleep mode when it is used as serial console. In that
case the kernel will still be using the port even after the last process closes
it. And on machines like the v445 the firmware won't be happy if the console
port is in sleep mode when the kernel reboots or halts.

ok miod@


Revision tags: OPENBSD_5_2_BASE
# 1.149 12-May-2012 kettenis

Remove unused variable.

ok mpi@, miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.148 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.147 22-May-2011 drahn

Fix a problem found where one SOC has a uart implementation that causes bus
errors if the fifo is read when the fifo is empty. Dont read an empty fifo.
ok deraaadt@ fgsch@


# 1.146 23-Mar-2011 fgsch

only read from the UART if there is something to read. fix beagle, otherwise
it will crash with 'External Non-Linefetch Abort (S)'.
similar diff provided by drahn@. tested by jasper@, deraadt@ ok.


Revision tags: OPENBSD_4_9_BASE
# 1.145 28-Aug-2010 miod

ansify function definitions, and constify a few arrays while there.
no functional change.


Revision tags: OPENBSD_4_8_BASE
# 1.144 07-Aug-2010 kettenis

Add resume support for serial consoles.

Tested by sthen@, ok deraadt@


# 1.143 06-Aug-2010 kettenis

Initial stab at making com@puc suspend and resume properly. Works fine
for using cu(1) between two OpenBSD machines. Probably doesn't work for
serial consoles but we don't support those on puc(4) anyway.

ok deraadt@


# 1.142 02-Jul-2010 nicm

Move common code for waking up writers on a tty into a function.

ok deraadt matthew millert


# 1.141 28-Jun-2010 deraadt

Allow tty drivers to request larger buffers at attach time using a
max-baud-rate hint. Adjust TTYHOG (the nearly full logic) to this new
situation. The larger buffers are required by the very high speed
KDDI devices in Japan (CF com, or USB ucom) so those are the only two
drivers which currently ask for a larger buffer size.
ok yasuoka miod


# 1.140 28-Jun-2010 ckuethe

Use a more moderate fifo trigger level (4) for moderately quick
(sub-38400) port speeds. Inspired by netbsd. ok fgsch krw deraadt miod


# 1.139 26-Jun-2010 guenther

Don't #include <sys/user.h> into files that don't need the stuff
it defines. In some cases, this means pulling in uvm.h or pcb.h
instead, but most of the inclusions were just noise. Tested on
alpha, amd64, armish, hppa, i386, macpcc, sgi, sparc64, and vax,
mostly by krw and naddy.
ok krw@


# 1.138 12-Apr-2010 tedu

Some of the line disciplines want to check for suser. Better to pass them
a process instead of using curproc. ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.137 09-Nov-2009 nicm

Every selwakeup() should have a matching KNOTE() (even if kqueue isn't
supported it doesn't do any harm), so put the KNOTE() in selwakeup() itself and
remove it from any occurences where both are used, except one for kqueue itself
and one in sys_pipe.c (where the selwakeup is under a PIPE_SEL flag).

Based on a diff from tedu.

ok deraadt


# 1.136 04-Nov-2009 kettenis

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@


# 1.135 01-Nov-2009 nicm

Call selwakeup()/KNOTE() even if the queue has emptied completely.

ok miod


# 1.134 31-Oct-2009 fgsch

Use suser when possible. Suggested by miod@.
miod@ deraadt@ ok.


# 1.133 31-Oct-2009 deraadt

Add missing KNOTE() calls after selwakeup(), until we decide if the KNOTE()
calls can go directly into selwakeup() safely
long discussion with nicm, murmers of consent from tedu and miod, noone
else seems to care of kqueue is busted as long as it makes their sockets
move data fast... pretty sad.


# 1.132 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.131 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.130 23-Nov-2008 deraadt

pccom can finally die; ok kettenis dlg drahn, tested by okan


# 1.129 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


Revision tags: OPENBSD_4_4_BASE
# 1.128 08-Jun-2008 kettenis

Make serial console on non-primary ports work to on i386.

tested by jbg@, "it is right" deraadt@


# 1.127 25-Apr-2008 dlg

the code that parses arguments from the boot loader on amd64 wasnt checking
what type of console was specified, so when a glass console was used it was
still configuring serial bits. this makes it so serial config only occurs
for serial console devices.

found by jolan@, thib@, and maybe sthen@
sorry guys


# 1.126 24-Apr-2008 jsing

MD_ISA_IOT is not defined anywhere so get rid of it.

Spotted by drahn@, ok dlg@


# 1.125 24-Apr-2008 jsing

Keep order of "#if defined..." consistent.

ok dlg@


# 1.124 24-Apr-2008 jsing

Clean up comments.


# 1.123 24-Apr-2008 jsing

Cleanup serial console handling and remove some of the MD code from com.c.
Specify the serial configuration from within the MD code, rather than
passing things via macros. This will allow other platforms to more readily
change the serial console configuration.

Committing this so it actually gets tested.

ok dlg@


# 1.122 09-Apr-2008 deraadt

Increase buffer size sent to the fifo, and clamp the size correctly.
Scrub the buffer afterwards, too


Revision tags: OPENBSD_4_3_BASE
# 1.121 23-Jan-2008 jsing

Cleanup cn_pri. Change constants to more meaningful names, rather than
the hp300 related ones currently in use. CN_NORMAL becomes CN_LOWPRI,
CN_INTERNAL becomes CN_MIDPRI and CN_REMOTE becomes CN_HIGHPRI.

ok miod@


# 1.120 12-Jan-2008 miod

Make comconsrate initialized to TTYDEF_SPEED at compile-time, for ports
which need to setup the chip before comcnattach() is invoked.


# 1.119 08-Jan-2008 dlg

the rsc-console on the v880 operates at 115200, not the 9600 we think we
have to force all console devices to. this change passes the right speed
to the com code, and continues to use it when the device is opened as the
console device.

figured out by kettenis@
ok kettenis@ miod@


# 1.118 22-Aug-2007 jasper

fix compilation with KDGB
from Nicholas Marriott

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.117 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.116 22-Jun-2007 jasper

ansify/de-register
no binary change


# 1.115 08-May-2007 deraadt

backout while the amd64 puc situation is rethought


# 1.114 08-May-2007 deraadt

move com_activate() to where it belongs


# 1.113 08-May-2007 deraadt

put more foo_detach() routines where they are used


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.112 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.111 27-Apr-2006 deraadt

2 lines of code in most drivers, to do the timestamping; ok miod kettenis


# 1.110 27-Mar-2006 deraadt

in detach, mark device with COM_SW_DEAD, so that close() will not go
tapping additional registes. allows it to work on macppc, where doing
such a tap after unplug is very bad. drahn helped fkr@bytemine.de
ok miod and drahn


Revision tags: OPENBSD_3_9_BASE
# 1.109 01-Jan-2006 miod

Let cons_init() and cons_init_bell() initialize the whole consdev structure,
thus removing the need for drivers to initialize cn_pri to CN_DEAD when
hardware probe fails.


# 1.108 21-Nov-2005 millert

Move contents of sys/select.h to sys/selinfo.h in preparation for a
userland-visible sys/select.h. Consistent with what Net and Free do.
OK deraadt@, tested with full ports build by naddy@.


# 1.107 11-Nov-2005 fgsch

fix kgdb compilation; input and ok miod@.


# 1.106 26-Sep-2005 miod

Share com probe code between com and pccom; allows us to get rid of awkward
code duplication in cardbus, pcmcia and puc attachments.

Joint effort with fgs@; blessed deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.105 18-Jul-2005 deraadt

fix sparc64 console; same diff as miod


# 1.104 18-Jul-2005 deraadt

COM_CONSOLE & DDB fix


# 1.103 17-Jul-2005 miod

Allow the console support code not to be compiled in; this will be
necessary for and only used on sparc, shortly.

Reluctantely ok deraadt@


# 1.102 11-Jul-2005 uwe

Enable IR receive mode only for infrared capable PXA2x0 UARTs. Normal
reception is blocked while the IR receiver or transmitter is enabled.

Also enable the PXA2x0 UART before clearing the FIFO (suggested by
drahn@ some time ago), and disable the UART in compwroff().

ok deraadt@


# 1.101 02-Jul-2005 uwe

xscale UART FIFOs are 32 bytes deep; found by deraadt@


# 1.100 27-May-2005 uwe

- Merge changes from pxacom back into the common com driver.

Changes to the common com driver (partly from NetBSD):
- Multiply before divide in comspeed() to avoid overflow (from NetBSD).
- Don't call getc() and send -1 if the output queue is empty.
- Take UART clock frequency as a parameter instead of using COM_FREQ.

ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.99 20-Oct-2004 pefo

Use bus_addr_t instead of int for port address/offset, ok mickey


Revision tags: OPENBSD_3_6_BASE
# 1.98 09-Aug-2004 pefo

remove old arc stuff and add sgi support.
ok mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.97 30-May-2004 deraadt

serial console hack from tom. who, after having been told a few times
to commit it, has not. what is going on guys?


# 1.96 03-May-2004 drahn

Remove OpenBSD/pegaos, this has been announced before but delayed until
the tree was stable. No point in code supporting a company which screws
its employees being in the OpenBSD tree.


Revision tags: OPENBSD_3_5_BASE
# 1.95 31-Oct-2003 drahn

Use isa iot for pegasos com console attachment, perhaps this could
be adopted MI?


# 1.94 03-Oct-2003 miod

Merge tty_attach() in ttymalloc() and tty_detach() in ttyfree(). The need for
separate tty registering is gone now that sparc has switched to wscons, and
this makes the code less error-prone.

Also, remove tests for ttymalloc() failure, since it uses M_WAITOK.

ok millert@ deraadt@, tested by various people as well besides me...


# 1.93 23-Sep-2003 millert

Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater
poll(2) functionality instead of emulating it via the select backend.
Adapted from NetBSD and including some changes from FreeBSD.
Tested by many, deraadt@ OK


Revision tags: OPENBSD_3_4_BASE
# 1.92 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.91 15-Jul-2003 jason

move prototype for com_raisedtr() to comvar.h (just like pccom).


# 1.90 03-Jun-2003 deraadt

terms 3 & 4 cleanup based on "terms" file


# 1.89 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.88 19-Dec-2002 mickey

comparam() does not need an spltty() for it, already called there.
time-bound loops in com_common_cnputc() and lower to spltty(),
which i guess is left from times when timeouts were processed at splhigh().
jason@ tested and ok, art@ ok


Revision tags: UBC_SYNC_B
# 1.87 17-Oct-2002 art

ifndef __HAVE_GENERIC_SOFT_INTERRUPTS leaved a label without a statement after it. Fix.


Revision tags: OPENBSD_3_2_BASE
# 1.86 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.85 11-Jun-2002 miod

com.c is not a block device, no bdev_decl() for it.


Revision tags: OPENBSD_3_1_BASE
# 1.84 09-Apr-2002 pefo

Don't enable interrupts until an open() is done. Until then the driver
is not handling them and may throw the kernel into a spurious interrupt
loop. ok art@


# 1.83 14-Mar-2002 millert

First round of __P removal in sys


# 1.82 14-Mar-2002 jason

compare pointers with NULL not 0


# 1.81 05-Feb-2002 mickey

restore CN_REMOTE priority, as it always was there.
anyway, only i386 uses that path and only if forced anyway.
also do not do comprobe1() on hppa since that hoses the port.


# 1.80 30-Jan-2002 nordin

Move SET/CLR/ISSET macros to param.h. fgsch@ and millert@ ok


# 1.79 25-Jan-2002 mickey

CONADDR is defined elsewhere for hppa


# 1.78 23-Jan-2002 ericj

oops, make the kgdb var's non-static


# 1.77 23-Jan-2002 ericj

allow this to compile with KGDB


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.76 05-Oct-2001 mickey

branches: 1.76.4;
restore some of that dead code needed for dev/cons functionality


# 1.75 02-Oct-2001 art

#ifdef FOO works much better when FOO isn't misspelled.


# 1.74 30-Sep-2001 art

Enable break interrupt earlier.


# 1.73 30-Sep-2001 art

Next round of cleanups.
- some KNF.
- disable interrupts earlier in attach.
- give it some more time in attach to finish earlier output.
- explicit bus_space_barrier in comcnputc.
- dead code.


# 1.72 30-Sep-2001 art

Remove dead code.


# 1.71 30-Sep-2001 art

Remove the COM_HAYESP code. It doesn't appear to have been ever used and
it's very intrusive and makes the code less readable.


# 1.70 30-Sep-2001 art

Move out the com at commulti attachment into an ownfile.
Same story as isapnp - not tested because i386 uses pccom.


# 1.69 30-Sep-2001 art

Move out com at isapnp attachment into an own file.
Not tested because the only system with isapnp is i386 and i386 uses pccom.


# 1.68 29-Sep-2001 art

Next step in making the com driver improvable.
Split out the com at isa attachment into its own file.


# 1.67 29-Sep-2001 art

- compoll is now scheduled once for every sc instead of just one timeout for
all ports and looping over them.
- support for generic soft interrupts.


# 1.66 27-Sep-2001 art

Simplify comstart a bit.


# 1.65 27-Sep-2001 millert

Enable #if 0'd code in comcnputc() so serial console works correctly;
art@openbsd.org


# 1.64 27-Sep-2001 art

Split out comattach that does isa and isapnp attachment and initialization,
into comattach that does the isa stuff and com_attach_subr that does the
init.


Revision tags: OPENBSD_2_9_BASE
# 1.63 17-Apr-2001 aaron

Implement cnbell(), an optional entrypoint that rings the console bell; from
NetBSD. deraadt@ ok


# 1.62 15-Mar-2001 art

Put back new timeouts. This time with correct timeout for compoll.


# 1.61 15-Mar-2001 deraadt

typo


# 1.60 15-Mar-2001 art

back out new timeouts until I find out why they break alpha.


# 1.59 15-Mar-2001 deraadt

support puc devices with higher speeds (not tested yet)


# 1.58 13-Mar-2001 mickey

new timeouts


# 1.57 24-Jan-2001 hugh

KGDB for i386 from NetBSD via niklas, with tweaks and accommodations.
Tested by various, vetted by mickey & theo.


# 1.56 08-Nov-2000 art

Add comcnattach that does the basic steps needed to attach
a com as a serial console. (idea from NetBSD).

If cn_tab->cn_dev == NODEV, try to find comopen in cdevsw and set cn_dev
to the right device.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE SMP_BASE
# 1.55 27-Jan-2000 mickey

branches: 1.55.2;
isa-avoidance


# 1.54 11-Jan-2000 mickey

a few ifdef accomodations for hppa, also a few knf spaces


Revision tags: kame_19991208
# 1.53 28-Nov-1999 downsj

Enable TI16750 UART support.


# 1.52 09-Nov-1999 rahnds

in the ifdef POWERPC section, do use ppc, not p4e, for the iohandle
for the console configuration.


# 1.51 26-Oct-1999 downsj

This file has my code in it, attach my copyright.


Revision tags: OPENBSD_2_6_BASE
# 1.50 08-Aug-1999 niklas

pasto from pccom.c


# 1.49 08-Aug-1999 niklas

revert function accidentally committed


# 1.48 08-Aug-1999 niklas

Detach support for com; NetBSD and me


# 1.47 26-Jul-1999 niklas

Move over the ISA PnP support from pccom.c to com.c


# 1.46 26-Jul-1999 niklas

fix my last commit where I committed more than intended


# 1.45 26-Jul-1999 niklas

Remove obsolete detach code that has been dead for very long


# 1.44 25-Jun-1999 rees

Don't turn off uart when closing cua device if tty is waiting.
Instead just drop dtr briefly.


Revision tags: OPENBSD_2_5_BASE
# 1.43 09-Feb-1999 rees

Fix cua device to not block on open.
Turn off chip (and dtr) on interrupted open.


# 1.42 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.41 20-Sep-1998 rahnds

Powerpc port uses com.c not just power4e.


# 1.40 18-Aug-1998 pefo

Remove clearing of interrupt after character output in cnputci(). Clearing
the int will make the tty stop if output is currently active.


# 1.39 07-Aug-1998 pefo

com.c needs to know about mem mapped ports in ppc systems.

ncr.c and if_de.c needs some hooks for systems with ncr and dec
ether chips on the motherboard that runs on odd clocks and doesn't
support a srom. srom is emulated in machine dependent code.

big endian support for ncr and dec ether finished. the 21040
have some more coding requirements if it is to run BE since
it does not have the descriptor endian swap configuration bit.


Revision tags: OPENBSD_2_3_BASE
# 1.38 23-Feb-1998 downsj

New probe routine and support for ST16650.

Compiles, but completely untested.


# 1.37 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


Revision tags: OPENBSD_2_2_BASE
# 1.36 03-Sep-1997 deraadt

fix cua/tty locking


# 1.35 07-Jul-1997 niklas

Removed an unused arg


Revision tags: OPENBSD_2_1_BASE
# 1.34 10-Apr-1997 pefo

Need to separate i/o and mem on mips


# 1.33 17-Mar-1997 pefo

Serial console trouble again...


# 1.32 12-Mar-1997 pefo

The stupid "use console before configured" scheeme strikes again :-)


# 1.31 06-Mar-1997 tholo

Initial implementation of support for calling hardpps() on carrier enable


# 1.30 10-Dec-1996 deraadt

the real changes by niklas... I did not merge correctly


# 1.29 10-Dec-1996 deraadt

clr TS_WOPEN if bailing on cua opens
As well, at this point I've also done fancy cvs repository mangling to
ensure that the com* files in sys/dev/ic maintain the history we had
before. (Yes, I cleaned up the 2.0 tags too..)


# 1.28 29-Nov-1996 niklas

Missing pieces of new bus.h that CVS lost behind my back


# 1.27 12-Nov-1996 niklas

s/bus.h/bus.old.h/ to make the transit to the bus_space bus.h an easy road
possibly taken in small steps


# 1.26 09-Nov-1996 tholo

Break shall be handled as data == 0 and FE bit set; from Theo


# 1.25 30-Oct-1996 niklas

cominit is used from the outside (the alpha port)


# 1.24 22-Oct-1996 downsj

patch com speed initialization


# 1.23 16-Oct-1996 deraadt

contextual usage


# 1.22 16-Oct-1996 deraadt

unused variables


# 1.21 29-Aug-1996 deraadt

sunos-like cua behaviour; inspired by budd@cs.bu.edu in his scn.c


# 1.20 02-Jul-1996 downsj

better FIFO enabling code; netbsd pr#2574, cliff@wport.com


# 1.19 24-Jun-1996 pefo

pica changes backed out. does not belong here


# 1.18 22-Jun-1996 pefo

Pica bus support added


# 1.17 10-Jun-1996 niklas

Some cleanup for -Wall -Wstrict-prototypes


# 1.16 10-Jun-1996 deraadt

tty_attach()


# 1.15 26-May-1996 deraadt

sync 0521


# 1.14 10-May-1996 deraadt

proto change


# 1.13 07-May-1996 deraadt

sync with 0504 -- prototypes and bus.h


# 1.12 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.11 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.10 18-Apr-1996 niklas

NetBSD 960317 merge


# 1.9 20-Mar-1996 mickey

Fix back wrong patches.


# 1.8 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.7 08-Mar-1996 niklas

From NetBSD: merge of 960217


# 1.6 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.5 16-Jan-1996 hvozda

Last of the glue and devices for for PCMCIA support from Stefan Grefen
<grefen@convex.com> with modifications by John Kohl <jtk@kolvir.blrc.ma.us>


# 1.4 03-Jan-1996 deraadt

Patches to use Hayes ESP with com.c; from banshee@gabriella.resort.com;
netbsd pr#1865. the ESP card code is always enabled -- we will have to
see if that fails on any chipsets.


# 1.3 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.


# 1.2 15-Dec-1995 deraadt

update from netbsd


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.165 19-Feb-2018 mpi

Remove almost unused `flags' argument of suser().

The account flag `ASU' will no longer be set but that makes suser()
mpsafe since it no longer mess with a per-process field.

No objection from millert@, ok tedu@, bluhm@


# 1.164 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.163 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.162 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.161 04-Sep-2016 tedu

remove some more sparc remnants. ok deraadt


# 1.160 03-Sep-2016 jsg

de-zaurus com.c
"looks correct" deraadt@ guenther@ on an earlier rev


# 1.159 16-Aug-2016 kettenis

Only probe the UART type if sc_uarttype is set to COM_UART_UNKNOWN.
This allows glue drivers to set the type based on other information (such as
Oopen Firmware or device tree properties) without going through to risky
code paths.

ok deraadt@, visa@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.158 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.157 13-Apr-2014 deraadt

wrap a long line


Revision tags: OPENBSD_5_5_BASE
# 1.156 09-Dec-2013 deraadt

At resume, do not spin flushing characters in from the chip. There shouldn't
be any characters. If the chip is not actually there for some reason, we'd
be spinning so early in the resume sequence, we'd probably go mad trying to
find the reason..
ok kettenis
request: people with serial ports on their laptops, try to run a "cu" over
a suspend/resume cycle, and see if you see "input noise"


# 1.155 09-Dec-2013 deraadt

At suspend/resume time cope with timeouts, DTR on resume in a bus
bus-independent fashion.
ok kettenis


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.154 14-Feb-2013 kettenis

No need to treat amd64 specially; always return CN_HIGHPRI.

ok miod@


# 1.153 17-Oct-2012 deraadt

Narrow the spltty/splx pair in com_activate to only enclose the minimum
operation which requires it.


# 1.152 25-Aug-2012 kettenis

Better detection of the st16650 v1 (with the broken fifo). Gets rid of
false positives like the DUART on the MPC8347 as found on socppc.

ok deraadt@


# 1.151 25-Aug-2012 kettenis

Turns out the v445 isn't happy at all if we touch the registers that deal
with sleep mode. So skip the wakeup code as well if we are a serial console.
The port on the v445 almost certainly isn't a real st16650 and probably
doesn't implement sleep mode (perhaps someone cut the soft core down a bit
too much?). But it is indistinguishable from it, so we have to deal with it.

ok deraadt@


# 1.150 19-Aug-2012 kettenis

Skip putting a port in sleep mode when it is used as serial console. In that
case the kernel will still be using the port even after the last process closes
it. And on machines like the v445 the firmware won't be happy if the console
port is in sleep mode when the kernel reboots or halts.

ok miod@


Revision tags: OPENBSD_5_2_BASE
# 1.149 12-May-2012 kettenis

Remove unused variable.

ok mpi@, miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.148 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.147 22-May-2011 drahn

Fix a problem found where one SOC has a uart implementation that causes bus
errors if the fifo is read when the fifo is empty. Dont read an empty fifo.
ok deraaadt@ fgsch@


# 1.146 23-Mar-2011 fgsch

only read from the UART if there is something to read. fix beagle, otherwise
it will crash with 'External Non-Linefetch Abort (S)'.
similar diff provided by drahn@. tested by jasper@, deraadt@ ok.


Revision tags: OPENBSD_4_9_BASE
# 1.145 28-Aug-2010 miod

ansify function definitions, and constify a few arrays while there.
no functional change.


Revision tags: OPENBSD_4_8_BASE
# 1.144 07-Aug-2010 kettenis

Add resume support for serial consoles.

Tested by sthen@, ok deraadt@


# 1.143 06-Aug-2010 kettenis

Initial stab at making com@puc suspend and resume properly. Works fine
for using cu(1) between two OpenBSD machines. Probably doesn't work for
serial consoles but we don't support those on puc(4) anyway.

ok deraadt@


# 1.142 02-Jul-2010 nicm

Move common code for waking up writers on a tty into a function.

ok deraadt matthew millert


# 1.141 28-Jun-2010 deraadt

Allow tty drivers to request larger buffers at attach time using a
max-baud-rate hint. Adjust TTYHOG (the nearly full logic) to this new
situation. The larger buffers are required by the very high speed
KDDI devices in Japan (CF com, or USB ucom) so those are the only two
drivers which currently ask for a larger buffer size.
ok yasuoka miod


# 1.140 28-Jun-2010 ckuethe

Use a more moderate fifo trigger level (4) for moderately quick
(sub-38400) port speeds. Inspired by netbsd. ok fgsch krw deraadt miod


# 1.139 26-Jun-2010 guenther

Don't #include <sys/user.h> into files that don't need the stuff
it defines. In some cases, this means pulling in uvm.h or pcb.h
instead, but most of the inclusions were just noise. Tested on
alpha, amd64, armish, hppa, i386, macpcc, sgi, sparc64, and vax,
mostly by krw and naddy.
ok krw@


# 1.138 12-Apr-2010 tedu

Some of the line disciplines want to check for suser. Better to pass them
a process instead of using curproc. ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.137 09-Nov-2009 nicm

Every selwakeup() should have a matching KNOTE() (even if kqueue isn't
supported it doesn't do any harm), so put the KNOTE() in selwakeup() itself and
remove it from any occurences where both are used, except one for kqueue itself
and one in sys_pipe.c (where the selwakeup is under a PIPE_SEL flag).

Based on a diff from tedu.

ok deraadt


# 1.136 04-Nov-2009 kettenis

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@


# 1.135 01-Nov-2009 nicm

Call selwakeup()/KNOTE() even if the queue has emptied completely.

ok miod


# 1.134 31-Oct-2009 fgsch

Use suser when possible. Suggested by miod@.
miod@ deraadt@ ok.


# 1.133 31-Oct-2009 deraadt

Add missing KNOTE() calls after selwakeup(), until we decide if the KNOTE()
calls can go directly into selwakeup() safely
long discussion with nicm, murmers of consent from tedu and miod, noone
else seems to care of kqueue is busted as long as it makes their sockets
move data fast... pretty sad.


# 1.132 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.131 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.130 23-Nov-2008 deraadt

pccom can finally die; ok kettenis dlg drahn, tested by okan


# 1.129 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


Revision tags: OPENBSD_4_4_BASE
# 1.128 08-Jun-2008 kettenis

Make serial console on non-primary ports work to on i386.

tested by jbg@, "it is right" deraadt@


# 1.127 25-Apr-2008 dlg

the code that parses arguments from the boot loader on amd64 wasnt checking
what type of console was specified, so when a glass console was used it was
still configuring serial bits. this makes it so serial config only occurs
for serial console devices.

found by jolan@, thib@, and maybe sthen@
sorry guys


# 1.126 24-Apr-2008 jsing

MD_ISA_IOT is not defined anywhere so get rid of it.

Spotted by drahn@, ok dlg@


# 1.125 24-Apr-2008 jsing

Keep order of "#if defined..." consistent.

ok dlg@


# 1.124 24-Apr-2008 jsing

Clean up comments.


# 1.123 24-Apr-2008 jsing

Cleanup serial console handling and remove some of the MD code from com.c.
Specify the serial configuration from within the MD code, rather than
passing things via macros. This will allow other platforms to more readily
change the serial console configuration.

Committing this so it actually gets tested.

ok dlg@


# 1.122 09-Apr-2008 deraadt

Increase buffer size sent to the fifo, and clamp the size correctly.
Scrub the buffer afterwards, too


Revision tags: OPENBSD_4_3_BASE
# 1.121 23-Jan-2008 jsing

Cleanup cn_pri. Change constants to more meaningful names, rather than
the hp300 related ones currently in use. CN_NORMAL becomes CN_LOWPRI,
CN_INTERNAL becomes CN_MIDPRI and CN_REMOTE becomes CN_HIGHPRI.

ok miod@


# 1.120 12-Jan-2008 miod

Make comconsrate initialized to TTYDEF_SPEED at compile-time, for ports
which need to setup the chip before comcnattach() is invoked.


# 1.119 08-Jan-2008 dlg

the rsc-console on the v880 operates at 115200, not the 9600 we think we
have to force all console devices to. this change passes the right speed
to the com code, and continues to use it when the device is opened as the
console device.

figured out by kettenis@
ok kettenis@ miod@


# 1.118 22-Aug-2007 jasper

fix compilation with KDGB
from Nicholas Marriott

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.117 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.116 22-Jun-2007 jasper

ansify/de-register
no binary change


# 1.115 08-May-2007 deraadt

backout while the amd64 puc situation is rethought


# 1.114 08-May-2007 deraadt

move com_activate() to where it belongs


# 1.113 08-May-2007 deraadt

put more foo_detach() routines where they are used


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.112 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.111 27-Apr-2006 deraadt

2 lines of code in most drivers, to do the timestamping; ok miod kettenis


# 1.110 27-Mar-2006 deraadt

in detach, mark device with COM_SW_DEAD, so that close() will not go
tapping additional registes. allows it to work on macppc, where doing
such a tap after unplug is very bad. drahn helped fkr@bytemine.de
ok miod and drahn


Revision tags: OPENBSD_3_9_BASE
# 1.109 01-Jan-2006 miod

Let cons_init() and cons_init_bell() initialize the whole consdev structure,
thus removing the need for drivers to initialize cn_pri to CN_DEAD when
hardware probe fails.


# 1.108 21-Nov-2005 millert

Move contents of sys/select.h to sys/selinfo.h in preparation for a
userland-visible sys/select.h. Consistent with what Net and Free do.
OK deraadt@, tested with full ports build by naddy@.


# 1.107 11-Nov-2005 fgsch

fix kgdb compilation; input and ok miod@.


# 1.106 26-Sep-2005 miod

Share com probe code between com and pccom; allows us to get rid of awkward
code duplication in cardbus, pcmcia and puc attachments.

Joint effort with fgs@; blessed deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.105 18-Jul-2005 deraadt

fix sparc64 console; same diff as miod


# 1.104 18-Jul-2005 deraadt

COM_CONSOLE & DDB fix


# 1.103 17-Jul-2005 miod

Allow the console support code not to be compiled in; this will be
necessary for and only used on sparc, shortly.

Reluctantely ok deraadt@


# 1.102 11-Jul-2005 uwe

Enable IR receive mode only for infrared capable PXA2x0 UARTs. Normal
reception is blocked while the IR receiver or transmitter is enabled.

Also enable the PXA2x0 UART before clearing the FIFO (suggested by
drahn@ some time ago), and disable the UART in compwroff().

ok deraadt@


# 1.101 02-Jul-2005 uwe

xscale UART FIFOs are 32 bytes deep; found by deraadt@


# 1.100 27-May-2005 uwe

- Merge changes from pxacom back into the common com driver.

Changes to the common com driver (partly from NetBSD):
- Multiply before divide in comspeed() to avoid overflow (from NetBSD).
- Don't call getc() and send -1 if the output queue is empty.
- Take UART clock frequency as a parameter instead of using COM_FREQ.

ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.99 20-Oct-2004 pefo

Use bus_addr_t instead of int for port address/offset, ok mickey


Revision tags: OPENBSD_3_6_BASE
# 1.98 09-Aug-2004 pefo

remove old arc stuff and add sgi support.
ok mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.97 30-May-2004 deraadt

serial console hack from tom. who, after having been told a few times
to commit it, has not. what is going on guys?


# 1.96 03-May-2004 drahn

Remove OpenBSD/pegaos, this has been announced before but delayed until
the tree was stable. No point in code supporting a company which screws
its employees being in the OpenBSD tree.


Revision tags: OPENBSD_3_5_BASE
# 1.95 31-Oct-2003 drahn

Use isa iot for pegasos com console attachment, perhaps this could
be adopted MI?


# 1.94 03-Oct-2003 miod

Merge tty_attach() in ttymalloc() and tty_detach() in ttyfree(). The need for
separate tty registering is gone now that sparc has switched to wscons, and
this makes the code less error-prone.

Also, remove tests for ttymalloc() failure, since it uses M_WAITOK.

ok millert@ deraadt@, tested by various people as well besides me...


# 1.93 23-Sep-2003 millert

Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater
poll(2) functionality instead of emulating it via the select backend.
Adapted from NetBSD and including some changes from FreeBSD.
Tested by many, deraadt@ OK


Revision tags: OPENBSD_3_4_BASE
# 1.92 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.91 15-Jul-2003 jason

move prototype for com_raisedtr() to comvar.h (just like pccom).


# 1.90 03-Jun-2003 deraadt

terms 3 & 4 cleanup based on "terms" file


# 1.89 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.88 19-Dec-2002 mickey

comparam() does not need an spltty() for it, already called there.
time-bound loops in com_common_cnputc() and lower to spltty(),
which i guess is left from times when timeouts were processed at splhigh().
jason@ tested and ok, art@ ok


Revision tags: UBC_SYNC_B
# 1.87 17-Oct-2002 art

ifndef __HAVE_GENERIC_SOFT_INTERRUPTS leaved a label without a statement after it. Fix.


Revision tags: OPENBSD_3_2_BASE
# 1.86 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.85 11-Jun-2002 miod

com.c is not a block device, no bdev_decl() for it.


Revision tags: OPENBSD_3_1_BASE
# 1.84 09-Apr-2002 pefo

Don't enable interrupts until an open() is done. Until then the driver
is not handling them and may throw the kernel into a spurious interrupt
loop. ok art@


# 1.83 14-Mar-2002 millert

First round of __P removal in sys


# 1.82 14-Mar-2002 jason

compare pointers with NULL not 0


# 1.81 05-Feb-2002 mickey

restore CN_REMOTE priority, as it always was there.
anyway, only i386 uses that path and only if forced anyway.
also do not do comprobe1() on hppa since that hoses the port.


# 1.80 30-Jan-2002 nordin

Move SET/CLR/ISSET macros to param.h. fgsch@ and millert@ ok


# 1.79 25-Jan-2002 mickey

CONADDR is defined elsewhere for hppa


# 1.78 23-Jan-2002 ericj

oops, make the kgdb var's non-static


# 1.77 23-Jan-2002 ericj

allow this to compile with KGDB


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.76 05-Oct-2001 mickey

branches: 1.76.4;
restore some of that dead code needed for dev/cons functionality


# 1.75 02-Oct-2001 art

#ifdef FOO works much better when FOO isn't misspelled.


# 1.74 30-Sep-2001 art

Enable break interrupt earlier.


# 1.73 30-Sep-2001 art

Next round of cleanups.
- some KNF.
- disable interrupts earlier in attach.
- give it some more time in attach to finish earlier output.
- explicit bus_space_barrier in comcnputc.
- dead code.


# 1.72 30-Sep-2001 art

Remove dead code.


# 1.71 30-Sep-2001 art

Remove the COM_HAYESP code. It doesn't appear to have been ever used and
it's very intrusive and makes the code less readable.


# 1.70 30-Sep-2001 art

Move out the com at commulti attachment into an ownfile.
Same story as isapnp - not tested because i386 uses pccom.


# 1.69 30-Sep-2001 art

Move out com at isapnp attachment into an own file.
Not tested because the only system with isapnp is i386 and i386 uses pccom.


# 1.68 29-Sep-2001 art

Next step in making the com driver improvable.
Split out the com at isa attachment into its own file.


# 1.67 29-Sep-2001 art

- compoll is now scheduled once for every sc instead of just one timeout for
all ports and looping over them.
- support for generic soft interrupts.


# 1.66 27-Sep-2001 art

Simplify comstart a bit.


# 1.65 27-Sep-2001 millert

Enable #if 0'd code in comcnputc() so serial console works correctly;
art@openbsd.org


# 1.64 27-Sep-2001 art

Split out comattach that does isa and isapnp attachment and initialization,
into comattach that does the isa stuff and com_attach_subr that does the
init.


Revision tags: OPENBSD_2_9_BASE
# 1.63 17-Apr-2001 aaron

Implement cnbell(), an optional entrypoint that rings the console bell; from
NetBSD. deraadt@ ok


# 1.62 15-Mar-2001 art

Put back new timeouts. This time with correct timeout for compoll.


# 1.61 15-Mar-2001 deraadt

typo


# 1.60 15-Mar-2001 art

back out new timeouts until I find out why they break alpha.


# 1.59 15-Mar-2001 deraadt

support puc devices with higher speeds (not tested yet)


# 1.58 13-Mar-2001 mickey

new timeouts


# 1.57 24-Jan-2001 hugh

KGDB for i386 from NetBSD via niklas, with tweaks and accommodations.
Tested by various, vetted by mickey & theo.


# 1.56 08-Nov-2000 art

Add comcnattach that does the basic steps needed to attach
a com as a serial console. (idea from NetBSD).

If cn_tab->cn_dev == NODEV, try to find comopen in cdevsw and set cn_dev
to the right device.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE SMP_BASE
# 1.55 27-Jan-2000 mickey

branches: 1.55.2;
isa-avoidance


# 1.54 11-Jan-2000 mickey

a few ifdef accomodations for hppa, also a few knf spaces


Revision tags: kame_19991208
# 1.53 28-Nov-1999 downsj

Enable TI16750 UART support.


# 1.52 09-Nov-1999 rahnds

in the ifdef POWERPC section, do use ppc, not p4e, for the iohandle
for the console configuration.


# 1.51 26-Oct-1999 downsj

This file has my code in it, attach my copyright.


Revision tags: OPENBSD_2_6_BASE
# 1.50 08-Aug-1999 niklas

pasto from pccom.c


# 1.49 08-Aug-1999 niklas

revert function accidentally committed


# 1.48 08-Aug-1999 niklas

Detach support for com; NetBSD and me


# 1.47 26-Jul-1999 niklas

Move over the ISA PnP support from pccom.c to com.c


# 1.46 26-Jul-1999 niklas

fix my last commit where I committed more than intended


# 1.45 26-Jul-1999 niklas

Remove obsolete detach code that has been dead for very long


# 1.44 25-Jun-1999 rees

Don't turn off uart when closing cua device if tty is waiting.
Instead just drop dtr briefly.


Revision tags: OPENBSD_2_5_BASE
# 1.43 09-Feb-1999 rees

Fix cua device to not block on open.
Turn off chip (and dtr) on interrupted open.


# 1.42 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.41 20-Sep-1998 rahnds

Powerpc port uses com.c not just power4e.


# 1.40 18-Aug-1998 pefo

Remove clearing of interrupt after character output in cnputci(). Clearing
the int will make the tty stop if output is currently active.


# 1.39 07-Aug-1998 pefo

com.c needs to know about mem mapped ports in ppc systems.

ncr.c and if_de.c needs some hooks for systems with ncr and dec
ether chips on the motherboard that runs on odd clocks and doesn't
support a srom. srom is emulated in machine dependent code.

big endian support for ncr and dec ether finished. the 21040
have some more coding requirements if it is to run BE since
it does not have the descriptor endian swap configuration bit.


Revision tags: OPENBSD_2_3_BASE
# 1.38 23-Feb-1998 downsj

New probe routine and support for ST16650.

Compiles, but completely untested.


# 1.37 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


Revision tags: OPENBSD_2_2_BASE
# 1.36 03-Sep-1997 deraadt

fix cua/tty locking


# 1.35 07-Jul-1997 niklas

Removed an unused arg


Revision tags: OPENBSD_2_1_BASE
# 1.34 10-Apr-1997 pefo

Need to separate i/o and mem on mips


# 1.33 17-Mar-1997 pefo

Serial console trouble again...


# 1.32 12-Mar-1997 pefo

The stupid "use console before configured" scheeme strikes again :-)


# 1.31 06-Mar-1997 tholo

Initial implementation of support for calling hardpps() on carrier enable


# 1.30 10-Dec-1996 deraadt

the real changes by niklas... I did not merge correctly


# 1.29 10-Dec-1996 deraadt

clr TS_WOPEN if bailing on cua opens
As well, at this point I've also done fancy cvs repository mangling to
ensure that the com* files in sys/dev/ic maintain the history we had
before. (Yes, I cleaned up the 2.0 tags too..)


# 1.28 29-Nov-1996 niklas

Missing pieces of new bus.h that CVS lost behind my back


# 1.27 12-Nov-1996 niklas

s/bus.h/bus.old.h/ to make the transit to the bus_space bus.h an easy road
possibly taken in small steps


# 1.26 09-Nov-1996 tholo

Break shall be handled as data == 0 and FE bit set; from Theo


# 1.25 30-Oct-1996 niklas

cominit is used from the outside (the alpha port)


# 1.24 22-Oct-1996 downsj

patch com speed initialization


# 1.23 16-Oct-1996 deraadt

contextual usage


# 1.22 16-Oct-1996 deraadt

unused variables


# 1.21 29-Aug-1996 deraadt

sunos-like cua behaviour; inspired by budd@cs.bu.edu in his scn.c


# 1.20 02-Jul-1996 downsj

better FIFO enabling code; netbsd pr#2574, cliff@wport.com


# 1.19 24-Jun-1996 pefo

pica changes backed out. does not belong here


# 1.18 22-Jun-1996 pefo

Pica bus support added


# 1.17 10-Jun-1996 niklas

Some cleanup for -Wall -Wstrict-prototypes


# 1.16 10-Jun-1996 deraadt

tty_attach()


# 1.15 26-May-1996 deraadt

sync 0521


# 1.14 10-May-1996 deraadt

proto change


# 1.13 07-May-1996 deraadt

sync with 0504 -- prototypes and bus.h


# 1.12 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.11 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.10 18-Apr-1996 niklas

NetBSD 960317 merge


# 1.9 20-Mar-1996 mickey

Fix back wrong patches.


# 1.8 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.7 08-Mar-1996 niklas

From NetBSD: merge of 960217


# 1.6 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.5 16-Jan-1996 hvozda

Last of the glue and devices for for PCMCIA support from Stefan Grefen
<grefen@convex.com> with modifications by John Kohl <jtk@kolvir.blrc.ma.us>


# 1.4 03-Jan-1996 deraadt

Patches to use Hayes ESP with com.c; from banshee@gabriella.resort.com;
netbsd pr#1865. the ESP card code is always enabled -- we will have to
see if that fails on any chipsets.


# 1.3 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.


# 1.2 15-Dec-1995 deraadt

update from netbsd


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision


# 1.164 30-Dec-2017 guenther

Don't pull in <sys/file.h> just to get fcntl.h

ok deraadt@ krw@


Revision tags: OPENBSD_6_2_BASE
# 1.163 30-Apr-2017 mpi

Rename Debugger() into db_enter().

Using a name with the 'db_' prefix makes it invisible from the dynamic
profiler.

ok deraadt@, kettenis@, visa@


# 1.162 30-Apr-2017 mpi

Unifdef KGDB.

It doesn't compile und hasn't been working during the last decade.

ok kettenis@, deraadt@


Revision tags: OPENBSD_6_1_BASE
# 1.161 04-Sep-2016 tedu

remove some more sparc remnants. ok deraadt


# 1.160 03-Sep-2016 jsg

de-zaurus com.c
"looks correct" deraadt@ guenther@ on an earlier rev


# 1.159 16-Aug-2016 kettenis

Only probe the UART type if sc_uarttype is set to COM_UART_UNKNOWN.
This allows glue drivers to set the type based on other information (such as
Oopen Firmware or device tree properties) without going through to risky
code paths.

ok deraadt@, visa@


Revision tags: OPENBSD_5_7_BASE OPENBSD_5_8_BASE OPENBSD_5_9_BASE OPENBSD_6_0_BASE
# 1.158 14-Sep-2014 jsg

remove uneeded proc.h includes
ok mpi@ kspillner@


Revision tags: OPENBSD_5_6_BASE
# 1.157 13-Apr-2014 deraadt

wrap a long line


Revision tags: OPENBSD_5_5_BASE
# 1.156 09-Dec-2013 deraadt

At resume, do not spin flushing characters in from the chip. There shouldn't
be any characters. If the chip is not actually there for some reason, we'd
be spinning so early in the resume sequence, we'd probably go mad trying to
find the reason..
ok kettenis
request: people with serial ports on their laptops, try to run a "cu" over
a suspend/resume cycle, and see if you see "input noise"


# 1.155 09-Dec-2013 deraadt

At suspend/resume time cope with timeouts, DTR on resume in a bus
bus-independent fashion.
ok kettenis


Revision tags: OPENBSD_5_3_BASE OPENBSD_5_4_BASE
# 1.154 14-Feb-2013 kettenis

No need to treat amd64 specially; always return CN_HIGHPRI.

ok miod@


# 1.153 17-Oct-2012 deraadt

Narrow the spltty/splx pair in com_activate to only enclose the minimum
operation which requires it.


# 1.152 25-Aug-2012 kettenis

Better detection of the st16650 v1 (with the broken fifo). Gets rid of
false positives like the DUART on the MPC8347 as found on socppc.

ok deraadt@


# 1.151 25-Aug-2012 kettenis

Turns out the v445 isn't happy at all if we touch the registers that deal
with sleep mode. So skip the wakeup code as well if we are a serial console.
The port on the v445 almost certainly isn't a real st16650 and probably
doesn't implement sleep mode (perhaps someone cut the soft core down a bit
too much?). But it is indistinguishable from it, so we have to deal with it.

ok deraadt@


# 1.150 19-Aug-2012 kettenis

Skip putting a port in sleep mode when it is used as serial console. In that
case the kernel will still be using the port even after the last process closes
it. And on machines like the v445 the firmware won't be happy if the console
port is in sleep mode when the kernel reboots or halts.

ok miod@


Revision tags: OPENBSD_5_2_BASE
# 1.149 12-May-2012 kettenis

Remove unused variable.

ok mpi@, miod@


Revision tags: OPENBSD_5_0_BASE OPENBSD_5_1_BASE
# 1.148 03-Jul-2011 matthew

Remove config_activate() and DVACT_ACTIVATE. PCMCIA's the only thing
that's ever used it, and it's long since been changed to use
DVACT_{QUIESCE,SUSPEND,RESUME} instead.

ok deraadt@, dlg@; miod@ also agreed with this idea when I brought it
up a few weeks ago


# 1.147 22-May-2011 drahn

Fix a problem found where one SOC has a uart implementation that causes bus
errors if the fifo is read when the fifo is empty. Dont read an empty fifo.
ok deraaadt@ fgsch@


# 1.146 23-Mar-2011 fgsch

only read from the UART if there is something to read. fix beagle, otherwise
it will crash with 'External Non-Linefetch Abort (S)'.
similar diff provided by drahn@. tested by jasper@, deraadt@ ok.


Revision tags: OPENBSD_4_9_BASE
# 1.145 28-Aug-2010 miod

ansify function definitions, and constify a few arrays while there.
no functional change.


Revision tags: OPENBSD_4_8_BASE
# 1.144 07-Aug-2010 kettenis

Add resume support for serial consoles.

Tested by sthen@, ok deraadt@


# 1.143 06-Aug-2010 kettenis

Initial stab at making com@puc suspend and resume properly. Works fine
for using cu(1) between two OpenBSD machines. Probably doesn't work for
serial consoles but we don't support those on puc(4) anyway.

ok deraadt@


# 1.142 02-Jul-2010 nicm

Move common code for waking up writers on a tty into a function.

ok deraadt matthew millert


# 1.141 28-Jun-2010 deraadt

Allow tty drivers to request larger buffers at attach time using a
max-baud-rate hint. Adjust TTYHOG (the nearly full logic) to this new
situation. The larger buffers are required by the very high speed
KDDI devices in Japan (CF com, or USB ucom) so those are the only two
drivers which currently ask for a larger buffer size.
ok yasuoka miod


# 1.140 28-Jun-2010 ckuethe

Use a more moderate fifo trigger level (4) for moderately quick
(sub-38400) port speeds. Inspired by netbsd. ok fgsch krw deraadt miod


# 1.139 26-Jun-2010 guenther

Don't #include <sys/user.h> into files that don't need the stuff
it defines. In some cases, this means pulling in uvm.h or pcb.h
instead, but most of the inclusions were just noise. Tested on
alpha, amd64, armish, hppa, i386, macpcc, sgi, sparc64, and vax,
mostly by krw and naddy.
ok krw@


# 1.138 12-Apr-2010 tedu

Some of the line disciplines want to check for suser. Better to pass them
a process instead of using curproc. ok deraadt


Revision tags: OPENBSD_4_7_BASE
# 1.137 09-Nov-2009 nicm

Every selwakeup() should have a matching KNOTE() (even if kqueue isn't
supported it doesn't do any harm), so put the KNOTE() in selwakeup() itself and
remove it from any occurences where both are used, except one for kqueue itself
and one in sys_pipe.c (where the selwakeup is under a PIPE_SEL flag).

Based on a diff from tedu.

ok deraadt


# 1.136 04-Nov-2009 kettenis

Get rid of __HAVE_GENERIC_SOFT_INTERRUPTS now that all our platforms support it.

ok jsing@, miod@


# 1.135 01-Nov-2009 nicm

Call selwakeup()/KNOTE() even if the queue has emptied completely.

ok miod


# 1.134 31-Oct-2009 fgsch

Use suser when possible. Suggested by miod@.
miod@ deraadt@ ok.


# 1.133 31-Oct-2009 deraadt

Add missing KNOTE() calls after selwakeup(), until we decide if the KNOTE()
calls can go directly into selwakeup() safely
long discussion with nicm, murmers of consent from tedu and miod, noone
else seems to care of kqueue is busted as long as it makes their sockets
move data fast... pretty sad.


# 1.132 13-Oct-2009 pirofti

Get rid of devact enum, substitute it with an int and coresponding defines.

This is needed for the addition of further suspend/resume actions.

Okay deraadt@, marco@.


Revision tags: OPENBSD_4_5_BASE OPENBSD_4_6_BASE
# 1.131 11-Jan-2009 blambert

Actual final round of timeout_add(to, n * hz) -> timeout_add_sec(to, n)
conversions.

ok kettenis@
ok krw@ (possibly for the second time :)


# 1.130 23-Nov-2008 deraadt

pccom can finally die; ok kettenis dlg drahn, tested by okan


# 1.129 15-Oct-2008 blambert

Second pass of simple timeout_add -> timeout_add_sec conversions
This should take care of the simpler ones (i.e., timeout values of
integer multiples of hz).

ok krw@, art@


Revision tags: OPENBSD_4_4_BASE
# 1.128 08-Jun-2008 kettenis

Make serial console on non-primary ports work to on i386.

tested by jbg@, "it is right" deraadt@


# 1.127 25-Apr-2008 dlg

the code that parses arguments from the boot loader on amd64 wasnt checking
what type of console was specified, so when a glass console was used it was
still configuring serial bits. this makes it so serial config only occurs
for serial console devices.

found by jolan@, thib@, and maybe sthen@
sorry guys


# 1.126 24-Apr-2008 jsing

MD_ISA_IOT is not defined anywhere so get rid of it.

Spotted by drahn@, ok dlg@


# 1.125 24-Apr-2008 jsing

Keep order of "#if defined..." consistent.

ok dlg@


# 1.124 24-Apr-2008 jsing

Clean up comments.


# 1.123 24-Apr-2008 jsing

Cleanup serial console handling and remove some of the MD code from com.c.
Specify the serial configuration from within the MD code, rather than
passing things via macros. This will allow other platforms to more readily
change the serial console configuration.

Committing this so it actually gets tested.

ok dlg@


# 1.122 09-Apr-2008 deraadt

Increase buffer size sent to the fifo, and clamp the size correctly.
Scrub the buffer afterwards, too


Revision tags: OPENBSD_4_3_BASE
# 1.121 23-Jan-2008 jsing

Cleanup cn_pri. Change constants to more meaningful names, rather than
the hp300 related ones currently in use. CN_NORMAL becomes CN_LOWPRI,
CN_INTERNAL becomes CN_MIDPRI and CN_REMOTE becomes CN_HIGHPRI.

ok miod@


# 1.120 12-Jan-2008 miod

Make comconsrate initialized to TTYDEF_SPEED at compile-time, for ports
which need to setup the chip before comcnattach() is invoked.


# 1.119 08-Jan-2008 dlg

the rsc-console on the v880 operates at 115200, not the 9600 we think we
have to force all console devices to. this change passes the right speed
to the com code, and continues to use it when the device is opened as the
console device.

figured out by kettenis@
ok kettenis@ miod@


# 1.118 22-Aug-2007 jasper

fix compilation with KDGB
from Nicholas Marriott

ok deraadt@


Revision tags: OPENBSD_4_2_BASE
# 1.117 15-Jul-2007 kettenis

Delay switching to the real serial console until we attach the serial device.
The variety of different serial devices is just too big to make a decision up
front. This should make the second serial port on four-digit B/C/J-class
workstation work as a serial console too.

ok miod@


# 1.116 22-Jun-2007 jasper

ansify/de-register
no binary change


# 1.115 08-May-2007 deraadt

backout while the amd64 puc situation is rethought


# 1.114 08-May-2007 deraadt

move com_activate() to where it belongs


# 1.113 08-May-2007 deraadt

put more foo_detach() routines where they are used


Revision tags: OPENBSD_4_0_BASE OPENBSD_4_1_BASE
# 1.112 23-Jun-2006 miod

In a drivers activate() entry point, if on DVACT_DEACTIVATE it does
something, then it MUST return zero on DVACT_ACTIVATE, not EOPNOTSUPP;
this very popular bug has been cut and pasted a lot of times...
ok deraadt@ mickey@


# 1.111 27-Apr-2006 deraadt

2 lines of code in most drivers, to do the timestamping; ok miod kettenis


# 1.110 27-Mar-2006 deraadt

in detach, mark device with COM_SW_DEAD, so that close() will not go
tapping additional registes. allows it to work on macppc, where doing
such a tap after unplug is very bad. drahn helped fkr@bytemine.de
ok miod and drahn


Revision tags: OPENBSD_3_9_BASE
# 1.109 01-Jan-2006 miod

Let cons_init() and cons_init_bell() initialize the whole consdev structure,
thus removing the need for drivers to initialize cn_pri to CN_DEAD when
hardware probe fails.


# 1.108 21-Nov-2005 millert

Move contents of sys/select.h to sys/selinfo.h in preparation for a
userland-visible sys/select.h. Consistent with what Net and Free do.
OK deraadt@, tested with full ports build by naddy@.


# 1.107 11-Nov-2005 fgsch

fix kgdb compilation; input and ok miod@.


# 1.106 26-Sep-2005 miod

Share com probe code between com and pccom; allows us to get rid of awkward
code duplication in cardbus, pcmcia and puc attachments.

Joint effort with fgs@; blessed deraadt@


Revision tags: OPENBSD_3_8_BASE
# 1.105 18-Jul-2005 deraadt

fix sparc64 console; same diff as miod


# 1.104 18-Jul-2005 deraadt

COM_CONSOLE & DDB fix


# 1.103 17-Jul-2005 miod

Allow the console support code not to be compiled in; this will be
necessary for and only used on sparc, shortly.

Reluctantely ok deraadt@


# 1.102 11-Jul-2005 uwe

Enable IR receive mode only for infrared capable PXA2x0 UARTs. Normal
reception is blocked while the IR receiver or transmitter is enabled.

Also enable the PXA2x0 UART before clearing the FIFO (suggested by
drahn@ some time ago), and disable the UART in compwroff().

ok deraadt@


# 1.101 02-Jul-2005 uwe

xscale UART FIFOs are 32 bytes deep; found by deraadt@


# 1.100 27-May-2005 uwe

- Merge changes from pxacom back into the common com driver.

Changes to the common com driver (partly from NetBSD):
- Multiply before divide in comspeed() to avoid overflow (from NetBSD).
- Don't call getc() and send -1 if the output queue is empty.
- Take UART clock frequency as a parameter instead of using COM_FREQ.

ok deraadt@


Revision tags: OPENBSD_3_7_BASE
# 1.99 20-Oct-2004 pefo

Use bus_addr_t instead of int for port address/offset, ok mickey


Revision tags: OPENBSD_3_6_BASE
# 1.98 09-Aug-2004 pefo

remove old arc stuff and add sgi support.
ok mickey@


Revision tags: SMP_SYNC_A SMP_SYNC_B
# 1.97 30-May-2004 deraadt

serial console hack from tom. who, after having been told a few times
to commit it, has not. what is going on guys?


# 1.96 03-May-2004 drahn

Remove OpenBSD/pegaos, this has been announced before but delayed until
the tree was stable. No point in code supporting a company which screws
its employees being in the OpenBSD tree.


Revision tags: OPENBSD_3_5_BASE
# 1.95 31-Oct-2003 drahn

Use isa iot for pegasos com console attachment, perhaps this could
be adopted MI?


# 1.94 03-Oct-2003 miod

Merge tty_attach() in ttymalloc() and tty_detach() in ttyfree(). The need for
separate tty registering is gone now that sparc has switched to wscons, and
this makes the code less error-prone.

Also, remove tests for ttymalloc() failure, since it uses M_WAITOK.

ok millert@ deraadt@, tested by various people as well besides me...


# 1.93 23-Sep-2003 millert

Replace select backends with poll backends. selscan() and pollscan()
now call the poll backend. With this change we implement greater
poll(2) functionality instead of emulating it via the select backend.
Adapted from NetBSD and including some changes from FreeBSD.
Tested by many, deraadt@ OK


Revision tags: OPENBSD_3_4_BASE
# 1.92 15-Aug-2003 tedu

change arguments to suser. suser now takes the process, and a flags
argument. old cred only calls user suser_ucred. this will allow future
work to more flexibly implement the idea of a root process. looks like
something i saw in freebsd, but a little different.
use of suser_ucred vs suser in file system code should be looked at again,
for the moment semantics remain unchanged.
review and input from art@ testing and further review miod@


# 1.91 15-Jul-2003 jason

move prototype for com_raisedtr() to comvar.h (just like pccom).


# 1.90 03-Jun-2003 deraadt

terms 3 & 4 cleanup based on "terms" file


# 1.89 02-Jun-2003 millert

Remove the advertising clause in the UCB license which Berkeley
rescinded 22 July 1999. Proofed by myself and Theo.


Revision tags: OPENBSD_3_3_BASE UBC_SYNC_A
# 1.88 19-Dec-2002 mickey

comparam() does not need an spltty() for it, already called there.
time-bound loops in com_common_cnputc() and lower to spltty(),
which i guess is left from times when timeouts were processed at splhigh().
jason@ tested and ok, art@ ok


Revision tags: UBC_SYNC_B
# 1.87 17-Oct-2002 art

ifndef __HAVE_GENERIC_SOFT_INTERRUPTS leaved a label without a statement after it. Fix.


Revision tags: OPENBSD_3_2_BASE
# 1.86 06-Jul-2002 nordin

Remove kernel support for NTP. ok deraadt@ and tholo@


# 1.85 11-Jun-2002 miod

com.c is not a block device, no bdev_decl() for it.


Revision tags: OPENBSD_3_1_BASE
# 1.84 09-Apr-2002 pefo

Don't enable interrupts until an open() is done. Until then the driver
is not handling them and may throw the kernel into a spurious interrupt
loop. ok art@


# 1.83 14-Mar-2002 millert

First round of __P removal in sys


# 1.82 14-Mar-2002 jason

compare pointers with NULL not 0


# 1.81 05-Feb-2002 mickey

restore CN_REMOTE priority, as it always was there.
anyway, only i386 uses that path and only if forced anyway.
also do not do comprobe1() on hppa since that hoses the port.


# 1.80 30-Jan-2002 nordin

Move SET/CLR/ISSET macros to param.h. fgsch@ and millert@ ok


# 1.79 25-Jan-2002 mickey

CONADDR is defined elsewhere for hppa


# 1.78 23-Jan-2002 ericj

oops, make the kgdb var's non-static


# 1.77 23-Jan-2002 ericj

allow this to compile with KGDB


Revision tags: OPENBSD_3_0_BASE UBC_BASE
# 1.76 05-Oct-2001 mickey

branches: 1.76.4;
restore some of that dead code needed for dev/cons functionality


# 1.75 02-Oct-2001 art

#ifdef FOO works much better when FOO isn't misspelled.


# 1.74 30-Sep-2001 art

Enable break interrupt earlier.


# 1.73 30-Sep-2001 art

Next round of cleanups.
- some KNF.
- disable interrupts earlier in attach.
- give it some more time in attach to finish earlier output.
- explicit bus_space_barrier in comcnputc.
- dead code.


# 1.72 30-Sep-2001 art

Remove dead code.


# 1.71 30-Sep-2001 art

Remove the COM_HAYESP code. It doesn't appear to have been ever used and
it's very intrusive and makes the code less readable.


# 1.70 30-Sep-2001 art

Move out the com at commulti attachment into an ownfile.
Same story as isapnp - not tested because i386 uses pccom.


# 1.69 30-Sep-2001 art

Move out com at isapnp attachment into an own file.
Not tested because the only system with isapnp is i386 and i386 uses pccom.


# 1.68 29-Sep-2001 art

Next step in making the com driver improvable.
Split out the com at isa attachment into its own file.


# 1.67 29-Sep-2001 art

- compoll is now scheduled once for every sc instead of just one timeout for
all ports and looping over them.
- support for generic soft interrupts.


# 1.66 27-Sep-2001 art

Simplify comstart a bit.


# 1.65 27-Sep-2001 millert

Enable #if 0'd code in comcnputc() so serial console works correctly;
art@openbsd.org


# 1.64 27-Sep-2001 art

Split out comattach that does isa and isapnp attachment and initialization,
into comattach that does the isa stuff and com_attach_subr that does the
init.


Revision tags: OPENBSD_2_9_BASE
# 1.63 17-Apr-2001 aaron

Implement cnbell(), an optional entrypoint that rings the console bell; from
NetBSD. deraadt@ ok


# 1.62 15-Mar-2001 art

Put back new timeouts. This time with correct timeout for compoll.


# 1.61 15-Mar-2001 deraadt

typo


# 1.60 15-Mar-2001 art

back out new timeouts until I find out why they break alpha.


# 1.59 15-Mar-2001 deraadt

support puc devices with higher speeds (not tested yet)


# 1.58 13-Mar-2001 mickey

new timeouts


# 1.57 24-Jan-2001 hugh

KGDB for i386 from NetBSD via niklas, with tweaks and accommodations.
Tested by various, vetted by mickey & theo.


# 1.56 08-Nov-2000 art

Add comcnattach that does the basic steps needed to attach
a com as a serial console. (idea from NetBSD).

If cn_tab->cn_dev == NODEV, try to find comopen in cdevsw and set cn_dev
to the right device.


Revision tags: OPENBSD_2_7_BASE OPENBSD_2_8_BASE SMP_BASE
# 1.55 27-Jan-2000 mickey

branches: 1.55.2;
isa-avoidance


# 1.54 11-Jan-2000 mickey

a few ifdef accomodations for hppa, also a few knf spaces


Revision tags: kame_19991208
# 1.53 28-Nov-1999 downsj

Enable TI16750 UART support.


# 1.52 09-Nov-1999 rahnds

in the ifdef POWERPC section, do use ppc, not p4e, for the iohandle
for the console configuration.


# 1.51 26-Oct-1999 downsj

This file has my code in it, attach my copyright.


Revision tags: OPENBSD_2_6_BASE
# 1.50 08-Aug-1999 niklas

pasto from pccom.c


# 1.49 08-Aug-1999 niklas

revert function accidentally committed


# 1.48 08-Aug-1999 niklas

Detach support for com; NetBSD and me


# 1.47 26-Jul-1999 niklas

Move over the ISA PnP support from pccom.c to com.c


# 1.46 26-Jul-1999 niklas

fix my last commit where I committed more than intended


# 1.45 26-Jul-1999 niklas

Remove obsolete detach code that has been dead for very long


# 1.44 25-Jun-1999 rees

Don't turn off uart when closing cua device if tty is waiting.
Instead just drop dtr briefly.


Revision tags: OPENBSD_2_5_BASE
# 1.43 09-Feb-1999 rees

Fix cua device to not block on open.
Turn off chip (and dtr) on interrupted open.


# 1.42 11-Jan-1999 millert

panic prints a newline for you, don't do it in the panic string


Revision tags: OPENBSD_2_4_BASE
# 1.41 20-Sep-1998 rahnds

Powerpc port uses com.c not just power4e.


# 1.40 18-Aug-1998 pefo

Remove clearing of interrupt after character output in cnputci(). Clearing
the int will make the tty stop if output is currently active.


# 1.39 07-Aug-1998 pefo

com.c needs to know about mem mapped ports in ppc systems.

ncr.c and if_de.c needs some hooks for systems with ncr and dec
ether chips on the motherboard that runs on odd clocks and doesn't
support a srom. srom is emulated in machine dependent code.

big endian support for ncr and dec ether finished. the 21040
have some more coding requirements if it is to run BE since
it does not have the descriptor endian swap configuration bit.


Revision tags: OPENBSD_2_3_BASE
# 1.38 23-Feb-1998 downsj

New probe routine and support for ST16650.

Compiles, but completely untested.


# 1.37 05-Feb-1998 deraadt

rename ddb.panic_ddb, and add ddb.console. Now you can stop console ddb entry
with a sysctl. There will be architectures and drivers that lack function,
and I trust the maintainers of those will forget to add the code..


Revision tags: OPENBSD_2_2_BASE
# 1.36 03-Sep-1997 deraadt

fix cua/tty locking


# 1.35 07-Jul-1997 niklas

Removed an unused arg


Revision tags: OPENBSD_2_1_BASE
# 1.34 10-Apr-1997 pefo

Need to separate i/o and mem on mips


# 1.33 17-Mar-1997 pefo

Serial console trouble again...


# 1.32 12-Mar-1997 pefo

The stupid "use console before configured" scheeme strikes again :-)


# 1.31 06-Mar-1997 tholo

Initial implementation of support for calling hardpps() on carrier enable


# 1.30 10-Dec-1996 deraadt

the real changes by niklas... I did not merge correctly


# 1.29 10-Dec-1996 deraadt

clr TS_WOPEN if bailing on cua opens
As well, at this point I've also done fancy cvs repository mangling to
ensure that the com* files in sys/dev/ic maintain the history we had
before. (Yes, I cleaned up the 2.0 tags too..)


# 1.28 29-Nov-1996 niklas

Missing pieces of new bus.h that CVS lost behind my back


# 1.27 12-Nov-1996 niklas

s/bus.h/bus.old.h/ to make the transit to the bus_space bus.h an easy road
possibly taken in small steps


# 1.26 09-Nov-1996 tholo

Break shall be handled as data == 0 and FE bit set; from Theo


# 1.25 30-Oct-1996 niklas

cominit is used from the outside (the alpha port)


# 1.24 22-Oct-1996 downsj

patch com speed initialization


# 1.23 16-Oct-1996 deraadt

contextual usage


# 1.22 16-Oct-1996 deraadt

unused variables


# 1.21 29-Aug-1996 deraadt

sunos-like cua behaviour; inspired by budd@cs.bu.edu in his scn.c


# 1.20 02-Jul-1996 downsj

better FIFO enabling code; netbsd pr#2574, cliff@wport.com


# 1.19 24-Jun-1996 pefo

pica changes backed out. does not belong here


# 1.18 22-Jun-1996 pefo

Pica bus support added


# 1.17 10-Jun-1996 niklas

Some cleanup for -Wall -Wstrict-prototypes


# 1.16 10-Jun-1996 deraadt

tty_attach()


# 1.15 26-May-1996 deraadt

sync 0521


# 1.14 10-May-1996 deraadt

proto change


# 1.13 07-May-1996 deraadt

sync with 0504 -- prototypes and bus.h


# 1.12 29-Apr-1996 hvozda

Pull in John Kohl's [jtk@netbsd.org] most recent (15Apr96) APM and PCMCIA work
(original PCMCIA framework by Stefan Grefen [grefen@convex.com]).


# 1.11 21-Apr-1996 deraadt

partial sync with netbsd 960418, more to come


# 1.10 18-Apr-1996 niklas

NetBSD 960317 merge


# 1.9 20-Mar-1996 mickey

Fix back wrong patches.


# 1.8 19-Mar-1996 mickey

Merging w/ NetBSD 021796.
speaker upgraded to the current.
some changes to the VM stuff (ie kern_thread.c added and so).


# 1.7 08-Mar-1996 niklas

From NetBSD: merge of 960217


# 1.6 20-Feb-1996 tholo

Pass device name to interrupt establish routines so it can be recorded in
the device interrupt chain structures (isa, pci)

Move interrupt chain structure definition to <machine/psl.h> so vmstat can
get at it (i386)

Remove hack to count interrupts the old way (i386)


# 1.5 16-Jan-1996 hvozda

Last of the glue and devices for for PCMCIA support from Stefan Grefen
<grefen@convex.com> with modifications by John Kohl <jtk@kolvir.blrc.ma.us>


# 1.4 03-Jan-1996 deraadt

Patches to use Hayes ESP with com.c; from banshee@gabriella.resort.com;
netbsd pr#1865. the ESP card code is always enabled -- we will have to
see if that fails on any chipsets.


# 1.3 27-Dec-1995 deraadt

from netbsd:
The IST_* and IPL_* constants are not bus-specific; don't treat them as such.
Change splimp -> splnet in Ethernet, ARCnet, and FDDI drivers.


# 1.2 15-Dec-1995 deraadt

update from netbsd


# 1.1 18-Oct-1995 deraadt

branches: 1.1.1;
Initial revision