Commit Graph

192 Commits

Author SHA1 Message Date
Marius Strobl
97202af2dc - Add a uart_rxready() and corresponding device-specific implementations
that can be used to check whether receive data is ready, i.e. whether
  the subsequent call of uart_poll() should return a char, and unlike
  uart_poll() doesn't actually receive data.
- Remove the device-specific implementations of uart_poll() and implement
  uart_poll() in terms of uart_getc() and the newly added uart_rxready()
  in order to minimize code duplication.
- In sunkbd(4) take advantage of uart_rxready() and use it to implement
  the polled mode part of sunkbd_check() so we don't need to buffer a
  potentially read char in the softc.
- Fix some mis-indentation in sunkbd_read_char().

Discussed with:	marcel
2007-01-18 22:01:19 +00:00
Marius Strobl
65deb9d947 - In sunkbd_probe_keyboard() don't bother to determine the keyboard layout
as we have no use for that info. Instead let this function return the
  keyboard ID and verify at its invocation in sunkbd_configure() that we're
  talking to a Sun type 4/5/6 keyboard, i.e. a keyboard supported by this
  driver.
- Add an option SUNKBD_EMULATE_ATKBD whose code is based on the respective
  code in ukbd(4) and like UKBD_EMULATE_ATSCANCODE causes this driver to
  emit AT keyboard/KB_101 compatible scan codes in K_RAW mode as assumed by
  kbdmux(4). Unlike UKBD_EMULATE_ATSCANCODE, SUNKBD_EMULATE_ATKBD also
  triggers the use of AT keyboard maps and thus allows to use the map files
  in share/syscons/keymaps with this driver at the cost of an additional
  translation (in ukbd(4) this just is the way of operation).
- Implement an option SUNKBD_DFLT_KEYMAP, which like the equivalent options
  of the other keyboard drivers allows to specify the default in-kernel
  keyboard map. For obvious reasons this made to only work when also using
  SUNKBD_EMULATE_ATKBD.
- Implement sunkbd_check(), sunkbd_check_char() and sunkbd_clear_state(),
  which are also required for interoperability with kbdmux(4).
- Implement K_CODE mode and FreeBSD keypad compose.
- As a minor hack define KBD_DFLT_KEYMAP also in the !SUNKBD_EMULATE_ATKBD
  case so we can obtain fkey_tab from <dev/kbd/kbdtables.h> rather than
  having to duplicate it and #ifdef some more code.
- Don't use the TX-buffer for writing the two command bytes for setting the
  keyboard LEDs as this consequently requires a hardware FIFO that is at
  least two bytes in depth, which the NMOS-variant of the Zilog SCCs doesn't
  have. Thus use an inlined version of uart_putc() to consecutively write
  the command bytes (a cleaner approach would be to do this via the soft
  interrupt handler but that variant wouldn't work while in ddb(4)). [1]
- Fix some minor style(9) bugs.

PR:		90316 [1]
Reviewed by:	marcel [1]
2006-11-02 00:01:15 +00:00
Ruslan Ermilov
9fddcc6661 Fix our ioctl(2) implementation when the argument is "int". New
ioctls passing integer arguments should use the _IOWINT() macro.
This fixes a lot of ioctl's not working on sparc64, most notable
being keyboard/syscons ioctls.

Full ABI compatibility is provided, with the bonus of fixing the
handling of old ioctls on sparc64.

Reviewed by:	bde (with contributions)
Tested by:	emax, marius
MFC after:	1 week
2006-09-27 19:57:02 +00:00
Maksim Yevmenkin
8c3c9a505f Do not try to call keyboard callback unless keyboard is active and busy.
This should fix 'kbdcontrol -K < /dev/console' panic on sparc64 with sunkbd(4).

PR:		sparc64/96798
MFC after:	1 week
2006-09-18 22:56:59 +00:00
Marcel Moolenaar
dd5b096f42 Properly propagate overrun conditions to the TTY layer.
MFC after: 3 days
2006-07-27 00:07:10 +00:00
Marcel Moolenaar
54cfafcf98 On PowerPC the clock for the BRG comes from RTxC, not PCLK. Add a
quick hack to deal with this. We may need to formalize this better
and have this information come from the bus attachments.
2006-07-26 17:29:37 +00:00
Marcel Moolenaar
afd396ac93 Implement UART_IOCTL_BAUD for the Z8530. This allows a serial console
on PowerPC use the current setting of the hardware and not second
guess what the OFW does on various machines.
2006-07-26 17:21:59 +00:00
Marcel Moolenaar
e997db5d3a Implement uart_cpu_eqres() and uart_cpu_getdev(). This allows
FreeBSD to use a serial console, as per the OFW settings.
2006-07-26 17:17:23 +00:00
Poul-Henning Kamp
7672c95932 Convert to new console api 2006-05-26 13:54:27 +00:00
Poul-Henning Kamp
9b188af13c Eliminate gdb_checkc member from GDB_DBGPORT(), it is never used.
Use polling behaviour for gdb_getc() where convenient, this edges us
closer to the console code.
2006-05-26 11:54:32 +00:00
Marcel Moolenaar
eb2198ec84 Remove definitions of uart_[gs]etdreg. They are not used anymore and
were in fact wrong.
2006-05-23 22:33:44 +00:00
Benno Rice
8bceca4f48 The lcr variable in ns8250_probe is now unused. Remove it.
Missed by:	benno
2006-05-23 06:04:45 +00:00
Benno Rice
58957d8717 Allow uart(4)'s ns8250 driver to work with devices whose regshift is > 0.
- Rename REG_DL to REG_DLL and REG_DLH.
- Always treat DLL and DLH as two separate 8-bit registers instead of one
  16-bit register.

Additionally, remove the probe for the high 4 bits of IER being 0 and don't
assume we can always read/write 0 to/from those bits.

These changes allow uart(4) to drive the UARTs on the Intel XScale PXA255.

Reviewed by:	marcel
2006-05-23 00:41:12 +00:00
Marcel Moolenaar
ace86f3f27 o A divisor of 0 is perfectly valid. Reserve -1 for an invalid
divisor. This allows us to set the line speed to the maximum
   of 1/4 of the device clock.
o  Disable the baudrate generator before programming the line
   settings, including baudrate, and enable it afterwards.
2006-05-12 23:24:45 +00:00
John Baldwin
67ab9fd759 First pass at removing Alpha kernel support. 2006-05-11 22:25:28 +00:00
Marcel Moolenaar
64220a7e28 Rewrite of puc(4). Significant changes are:
o  Properly use rman(9) to manage resources. This eliminates the
   need to puc-specific hacks to rman. It also allows devinfo(8)
   to be used to find out the specific assignment of resources to
   serial/parallel ports.
o  Compress the PCI device "database" by optimizing for the common
   case and to use a procedural interface to handle the exceptions.
   The procedural interface also generalizes the need to setup the
   hardware (program chipsets, program clock frequencies).
o  Eliminate the need for PUC_FASTINTR. Serdev devices are fast by
   default and non-serdev devices are handled by the bus.
o  Use the serdev I/F to collect interrupt status and to handle
   interrupts across ports in priority order.
o  Sync the PCI device configuration to include devices found in
   NetBSD and not yet merged to FreeBSD.
o  Add support for Quatech 2, 4 and 8 port UARTs.
o  Add support for a couple dozen Timedia serial cards as found
   in Linux.
2006-04-28 21:21:53 +00:00
Marcel Moolenaar
a31f91a061 Implement the ipend() method of the serdev I/F. 2006-04-28 18:29:23 +00:00
Marcel Moolenaar
ab2b8832cb o Add 5 Timedia single port serial cards.
o  While here, break long lines.
2006-04-27 17:08:30 +00:00
Marcel Moolenaar
d902fb71da Use 115200 and not 9600 as the initial baudrate. This speeds up
detection of the FIFO size. Especially for large FIFOs.
2006-04-27 05:43:10 +00:00
Marcel Moolenaar
51841e9df9 o Add 2 HP Diva single port UARTs. 2006-04-27 03:17:39 +00:00
Marcel Moolenaar
24f9da031c o Add 2 NEC cards
o  Add 2 Dell cards
o  Add Quatech card
o  Add support for non-standard rclk values.
o  Update descriptions to match PCI id database.
2006-04-26 21:31:31 +00:00
Marcel Moolenaar
63f8efd314 MFp4: Calculate the divisor before setting the DLAB bit. This
prevents that there's a control flow that leaves the DLAB
	bit set.
2006-04-23 21:15:07 +00:00
Marcel Moolenaar
a24d2e121e In z8530_divisor() return 0 if the calculated divisor is less than 0.
This happens when the baudrate is too high for the given RCLK.
2006-04-04 01:16:16 +00:00
Marcel Moolenaar
4437e2615f Remove unused variable 'error'. Forgotten in previous commit. 2006-04-02 21:58:09 +00:00
Marcel Moolenaar
5418a8aead Don't claim a SAB82532. We have scc(4) for that. 2006-04-02 21:50:45 +00:00
Marcel Moolenaar
8d1289fe6d Eliminate the sc_hasfifo flag from the softc. It was only used by
the NS8250 class driver. The UART has FIFOs if sc_rxfifosz>1, so
test for that instead.
While here properly initialize sc_rxfifosz and sc_txfifosz in the
case the UART doesn't have FIFOs.
2006-04-02 21:45:54 +00:00
Marcel Moolenaar
634e63c986 Don't hold the hardware mutex across getc(). It can wait indefinitely
for a character to be received. Instead let getc() do any necesary
locking.
2006-04-01 19:04:54 +00:00
Marcel Moolenaar
ce8f00136f Allow uart(4) to be built on PowerPC. 2006-03-31 01:42:55 +00:00
Marcel Moolenaar
8af03381d8 Add support for scc(4). 2006-03-30 18:37:03 +00:00
Marcel Moolenaar
6174e6ed12 Add scc(4), a driver for serial communications controllers. These
controllers typically have multiple channels and support a number
of serial communications protocols. The scc(4) driver is itself
an umbrella driver that delegates the control over each channel
and mode to a subordinate driver (like uart(4)).
The scc(4) driver supports the Siemens SAB 82532 and the Zilog
Z8530 and replaces puc(4) for these devices.
2006-03-30 18:33:22 +00:00
Marcel Moolenaar
793bcd17d5 Don't open if we're going away. 2006-03-30 03:26:52 +00:00
Marcel Moolenaar
ea54941449 Replace our local UART_SIGMASK_* with the global SER_MASK_*. 2006-02-24 05:40:17 +00:00
Marcel Moolenaar
0bb90c9d57 When we probe a SAB82532, return BUS_PROBE_GENERIC. This allows puc(4)
or scc(4) to grab the device by default. In fact, we probably shouldn't
even claim the device at all...
2006-02-24 05:36:44 +00:00
Marcel Moolenaar
2d5118050a MFp4:
Stop using our local UART_IPEND_* and instead use the global SER_INT_*
as defined in <sys/serial.h>.
2006-02-24 02:42:26 +00:00
John Baldwin
57fb5e6097 - Use bus_setup_intr() and bus_teardown_intr() to register device driver
interrupt handlers rather than BUS_SETUP_INTR() and BUS_TEARDOWN_INTR().
  Uses of the BUS_*() versions in the implementation of foo_intr methods
  in bus drivers were not changed.  Mostly this just means that some
  drivers might start printing diagnostic messages like [FAST] when
  appropriate as well as honoring mpsafenet=0.
- Fix two more of the ppbus drivers' identify routines to function
  correctly in the mythical case of a machine with more than one ppbus.
2006-02-22 18:16:26 +00:00
Marius Strobl
ea227b498b - Add support for using LOM (Lights Out Management) and RSC (Remote System
Control) devices as console. These are microcontrollers which are either
  on-board or part of an add-on card and provide terminal server, remote
  power switch and monitoring functionality. For console usage these are
  connected to the rest of the system via a SCC or an UART. This commit adds
  support for the following variants (corresponds to what 'input-device' and
  'output-device' have to be set to):
  rsc		found on-board in E250 and supposedly some Netra, connected
		via a SAB82532, com. parameters can be determined via OFW
  rsc-console	RSC card found in E280R, Fire V4x0, Fire V8x0, connected
		via a NS16550, hardwired to 115200 8N1
  lom-console	LOMlite2 card found in Netra 20/T4, connected via a NS16550,
		hardwired to 9600 8N1

- Add my copyright to uart_cpu_sparc64.c as I've rewritten about one third
  of that file over time.

Tested on:	E250, E280R
Thanks to:	dwhite@ for providing access to an E280R
OK'ed by:	marcel
MFC after:	1 week
2006-02-04 23:27:16 +00:00
Warner Losh
fbd68c4b4c Make uart_getenv() not be ns8250 dependent. This will allow, in the future,
compilation of kernels without ns8250 support but using the uart framework.
These kernels will be for machines where size matters more, so including code
that can never be executed is undesriable...
2005-12-12 21:00:58 +00:00
Marcel Moolenaar
b923a71020 In uart_bus_probe() return BUS_PROBE_DEFAULT when the probe is
successful.
2005-10-28 06:30:39 +00:00
Marcel Moolenaar
3a45066f19 o Style(9) nits
o  Fix typo in comment
o  s/-100/BUS_PROBE_GENERIC/
o  s/err/error/ for consistency
o  Remove non-applicable comment
o  Allow uart_bus_probe() to return the predefined BUS_PROBE_*
   contants. In this case: explicitly test for error > 0.
2005-10-28 06:27:53 +00:00
Marcel Moolenaar
17ef9ca46d Allow uart_bus_probe() to return the predefined BUS_PROBE_*
constants. In this case: just return what uart_bus_probe()
returns.
2005-10-28 06:24:09 +00:00
John Baldwin
284b6708c4 - Use swi_remove() to teardown swi handlers rather than
intr_event_remove_handler().
- Remove tty: prefix from a couple of swi handler names.
2005-10-26 15:52:16 +00:00
Marcel Moolenaar
f3b996b6b8 Remove PCI IDs for multiport cards:
o Oxford Semiconductor PCI Dual Port Serial
o Netmos Nm9845 PCI Bridge with Dual UART

Add PCI IDs for single-port cards:
o Various SIIG Cyber Serial
o Oxford Semiconductor OXCB950 UART

Update description as per puc(4).
2005-10-26 01:49:11 +00:00
John Baldwin
e0f66ef861 Reorganize the interrupt handling code a bit to make a few things cleaner
and increase flexibility to allow various different approaches to be tried
in the future.
- Split struct ithd up into two pieces.  struct intr_event holds the list
  of interrupt handlers associated with interrupt sources.
  struct intr_thread contains the data relative to an interrupt thread.
  Currently we still provide a 1:1 relationship of events to threads
  with the exception that events only have an associated thread if there
  is at least one threaded interrupt handler attached to the event.  This
  means that on x86 we no longer have 4 bazillion interrupt threads with
  no handlers.  It also means that interrupt events with only INTR_FAST
  handlers no longer have an associated thread either.
- Renamed struct intrhand to struct intr_handler to follow the struct
  intr_foo naming convention.  This did require renaming the powerpc
  MD struct intr_handler to struct ppc_intr_handler.
- INTR_FAST no longer implies INTR_EXCL on all architectures except for
  powerpc.  This means that multiple INTR_FAST handlers can attach to the
  same interrupt and that INTR_FAST and non-INTR_FAST handlers can attach
  to the same interrupt.  Sharing INTR_FAST handlers may not always be
  desirable, but having sio(4) and uhci(4) fight over an IRQ isn't fun
  either.  Drivers can always still use INTR_EXCL to ask for an interrupt
  exclusively.  The way this sharing works is that when an interrupt
  comes in, all the INTR_FAST handlers are executed first, and if any
  threaded handlers exist, the interrupt thread is scheduled afterwards.
  This type of layout also makes it possible to investigate using interrupt
  filters ala OS X where the filter determines whether or not its companion
  threaded handler should run.
- Aside from the INTR_FAST changes above, the impact on MD interrupt code
  is mostly just 's/ithread/intr_event/'.
- A new MI ddb command 'show intrs' walks the list of interrupt events
  dumping their state.  It also has a '/v' verbose switch which dumps
  info about all of the handlers attached to each event.
- We currently don't destroy an interrupt thread when the last threaded
  handler is removed because it would suck for things like ppbus(8)'s
  braindead behavior.  The code is present, though, it is just under
  #if 0 for now.
- Move the code to actually execute the threaded handlers for an interrrupt
  event into a separate function so that ithread_loop() becomes more
  readable.  Previously this code was all in the middle of ithread_loop()
  and indented halfway across the screen.
- Made struct intr_thread private to kern_intr.c and replaced td_ithd
  with a thread private flag TDP_ITHREAD.
- In statclock, check curthread against idlethread directly rather than
  curthread's proc against idlethread's proc. (Not really related to intr
  changes)

Tested on:	alpha, amd64, i386, sparc64
Tested on:	arm, ia64 (older version of patch by cognet and marcel)
2005-10-25 19:48:48 +00:00
Poul-Henning Kamp
733634738e Eliminate two unused arguments to ttycreate(). 2005-10-16 20:22:56 +00:00
Warner Losh
7132e1b9ae Remove OLDCARD shims 2005-09-21 22:45:14 +00:00
Marius Strobl
1b279bfb52 - Change the code that determines whether to use a serial console and
which serial device to use in that case respectively to not rely on
  the OFW names of the input/output and stdin/stdout devices. Instead
  check whether input and output refers to the same device and is of
  type serial (uart(4) was already doing this) and for the fallback
  to a serial console in case a keyboard is the selected input device
  but unplugged do the same for stdin and stdout in case the input
  device is nonexistent (PS/2 and USB keyboards) or has a 'keyboard'
  property (RS232 keyboards). Additionally also check whether the OFW
  did a fallback to a serial console in the same way in case the
  output device is nonexistent. While at it save on some variables
  and for sys/boot/sparc64/loader/metadata.c move the code in question
  to a new function md_bootserial() so it can be kept in sync with
  uart_cpu_getdev_console() more easily.
  This fixes selecting a serial console and the appropriate device
  when using a device path for the 'input-device' and 'output-device'
  OFW environment variables instead of an alias for the serial device
  to use or when using a screen alias that additionally denotes a
  video mode (like e.g. 'screen:r1024x768x60') but no keyboard is
  plugged in (amongst others). It also makes the code select a serial
  console in case the OFW did the same due to a misconfiguration like
  both 'input-device' and 'output-device' set to 'keyboard' or to a
  nonexisting device (whether the OFW does a fallback to a serial
  console in case of a misconfiguration or one ends up with just no
  console at all highly depends on the OBP version however).
- Reduce the size of buffers that only ever need to hold the string
  'serial' accordingly. Double the size of buffers that may need to
  hold a device path as e.g. '/pci@8,700000/ebus@5/serial@1,400000:a'
  exceeds 32 chars.
- Remove the package handle of the '/options' node from the argument
  list of uart_cpu_getdev_dbgport() as it's unused there and future
  use is also unlikely.

MFC after:	1 week
2005-08-15 20:58:36 +00:00
Marius Strobl
079f9edfef Recognize the SAB82532 in USIII machines. 2005-08-07 13:37:25 +00:00
Marcel Moolenaar
d382695820 Some chipset drivers redefine the busspace_isa_{io|mem} tags. This
not only means that it's possible (though unlikely) that we hand out
differing tags for the same bus space, it also means that the tags
we handed out are not used during bus enumeration. Both affect our
ability to compare tags. Fix the first by initializing our tags only
once. Fix the second by testing if one of the tags to compare is our
tag and the other is a busspace_isa_{io|mem} tag and declare them
equal if so.

This fixes using uart(4) as the serial console on a ds10. That is,
the low-level console worked, but we could not match the resources
to one of the UARTs found during bus enumeration, which prevented
uart(4) from becoming the console in single- or multi-user mode.

Approved by: re (kensmith)
MFC after: 2 days
Thanks to: all involved in getting a ds10 to me; directly or indirectly.
Special thanks to: Dave Knight, ISC (for not scratching my Porsche :-)
2005-06-16 18:06:38 +00:00
Marius Strobl
3a61f787fb Replace the band-aid for allowing to call sunkbd_configure() multiple
times which was added in the last revision with what should be a proper
solution as long as keyboards that were pluggged in after the kernel
has fully booted aren't supported. I.e. when sunkbd_configure() is
called for the high-level console probe make sure that the keyboard is
both successfully configured (i.e. also probed) and attached. The band-
aid left the possibility to attach the keyboard device to the high-level
console without attaching the keyboard device itself when the keyboard
is plugged in after uart(4) attached but before syscons(4) does.
2005-06-04 21:54:31 +00:00
Marius Strobl
852962d3c5 On AXi and AXmp boards the NS16550 (used to connect keyboard and mouse)
share their IRQ lines with the i8042. Any IRQ activity (typically during
attach) on the NS16550 used to connect the keyboard when actually the
PS/2 keyboard is selected in OFW causes interaction with the OBP i8042
driver resulting in a hang (and vice versa). As RS232 keyboards and mice
obviously aren't meant to be used in parallel with PS/2 ones on these
boards don't attach to these NS16550 in case the RS232 keyboard isn't
selected in order to prevent such hangs.

Ok'ed by:	marcel
2005-06-04 21:52:56 +00:00
Marius Strobl
ecf4269527 Change the semantics of uart_cpu_getdev_keyboard() to only match SCCs/
UARTs used to connect keyboards and not also PS/2 keyboards and only
return their package handle in case the keyboard is the preferred one
according to the OFW but otherwise still regardless of whether the
keyboard is used for stdin or not. This is simply achieved by looking
at the 'keyboard' alias and returning the corresponding package handle
in case it refers to a SCC/UART. This is change is done in order to
give the keyboard which the OFW or the user selected in OFW on boards
that support additional types of keyboards besides the RS232 ones also
preference in FreeBSD. It will be also used to determine on Sun AXi and
Sun AXmp boards whether a PS/2 or a RS232 is to be used as these are
sort of mutual exclusive there (see upcoming commit to uart_bus_ebus.c).
Note that Tatung AXi boards have the same issue but the former code
happened to already give the PS/2 keyboard preference by not identifying
the respective UART as keyboard system device there because the PS/2
keyboard node precedes the keyboard UART one in the OFW device tree of
these boards (which isn't the case for the Sun AXi).

Ok'ed by:	marcel
2005-06-04 21:33:18 +00:00
Marius Strobl
3b8c3ece32 - Sprinkle some KBD_IS_* and KBD_*_DONE macros in sunkbd_configure() as
a band-aid allowing to call this function savely multiple times, e.g.
  during sckbdprobe() and sc_probe_unit(). Otherwise calling it a second
  time results in a non-working keyboard. This needs a lot of more work
  to actually do the right thing and work like expected.
- Let sunkbd_configure() return the number of the found keyboards, i.e.
  1 in case probing succeeds, as it's expected. The return values of the
  keyboard configure functions however currently aren't checked so this
  doesn't make a difference at the moment.
- Use FBSDID.
2005-05-21 20:26:30 +00:00
Marcel Moolenaar
9f0974f96d In uart_cnprobe(), fill in the cn_name field of the consdev structure.
The core console code checks this field when a console is added and
emits a warning if it's empty. In practice the warning is harmless for
uart(4), because the cn_name is filled in as soon as the device name is
known; which is when the device is enumerated.
To avoid the warning, to avoid possible complications caused by emitting
the warning without there (possibly) being a console selected yet and to
avoid complications when the UART isn't found during bus enumeration, we
just preset the cn_name field here to the name of the driver.
2005-05-08 20:25:09 +00:00
Marcel Moolenaar
ca83142fc3 Make the Z8530 more reliable as low-level console by making use of the
fact that access to RR0 does not need a prior write to the register
index because the index always reverts to 0 after the indexed register
has been accessed.

Typically when a RR or WR is to accessed, one programs the index (which
is a write to the control register), followed by a read or write to the
actual indexed register (a read pr write to the same control register).
When this non-atomic sequence is interrupted after having written the
index and low-level console I/O is done in that situation, the write to
program the index will actually write to the indexed register and nuke
state. This almost always yields a wedge.

By not programming the index register and instead just reading from RR0,
the worst case scenario is non-fatal. For if we don't actually read from
RR0 but some other register we get an invalid status, which may lead us
to conclude that the transit data register is empty when it's not or that
the receive data register contains data when it doesn't. Hence, we may
lose an output character or get a sporadic input character, but given
the situation this is a non-issue.

Full serialization is not possible due to the fact that this code needs
to work from DDB and before mutex initialization has happened.

In collaboration with: kris@, marius@
Tested by: kris@
MFC after: 1 day
X-MFC: 5.4-RELEASE candidate
2005-04-27 21:57:51 +00:00
Marius Strobl
082c434426 In uart_cpu_getdev_console() when determinig whether we should use
a serial console anyway because input-device is set to keyboard and
output-device is set to screen but no keyboard is plugged in don't
assume that a device node for the input-device alias exists. While
this is true for RS232 keyboards (the node of the SCC and UART
respectively which controls the keyboard doesn't disappear when no
keyboard is plugged in) this assumption breaks for USB keyboards.
It's most likely also not true for PS/2 keyboards but OFW doesn't
reliably switch to a serial console when the potential keyboard is
a PS/2 one which isn't plugged in so this couldn't be verified
properly.

Reported by:	Will Andrews <will@csociety.org>, obrien
MFC after:	1 week
2005-03-12 17:06:03 +00:00
Marius Strobl
2682e7b661 - Allocate the interrupt resource as RF_SHAREABLE allowing uart(4) to work
with shared IRQs in case the bus code, MD interrupt code, etc. permits.
  Together with sys/sparc64/sparc64/intr_machdep.c rev. 1.21 this fixes
  an endless loop in uart_intr() when using the second NS16550 on the ISA
  bus of sparc64 machines.
- Destroy the hardware mutex on detach and in case attaching fails.

Approved by:	marcel
2005-03-02 11:30:14 +00:00
Marius Strobl
2b2250b149 - Re-write OF_decode_addr() with a bus-neutral approach, adding support
for nodes hanging off of Central (untested), FireHose (untested) and
  PCI (tested) busses.
- Add an additional parameter to OF_decode_addr() which specifies the
  index of the register bank to decode.

These should allow to eventually add support for the Z8530 hanging off of
FireHose to uart(4) and to write support for PCI-based graphics adapters.

Suggested by:	tmm (back in '03)
2005-02-12 19:13:51 +00:00
Marcel Moolenaar
a2e25ee10d Add the keyboard system device before we probe for the keyboard.
The presence or absence of a keyboard does not change whether an
UART is designed as a keyboard port or not and thus whether we
can use the port as a TTY or not.
We now call sunkbd_attach() even when we didn't previously find
a keyboard. Emit a useful message stating that no keyboard was
found, but don't do anything else.

MFC after: 5 days
2005-01-31 04:31:22 +00:00
Marcel Moolenaar
e6fff3fa54 Fix a logic bug that caused DSR to never be deasserted.
MFC after: 5 days
2005-01-30 22:14:30 +00:00
Marcel Moolenaar
c3c16fcb7b o Fix the various interrupt related problems caused by reverse
engineering the pending interrupt sources from the current
   state of the controller. For channel A we can always read the
   interrupt pending register (RR3). For channel B we can read
   the interrupt vector register (RR2) because it contains the
   modified vector and thus includes the interrupt source.
   Since we currently need puc(4) for the Z8530, we know that
   the interrupt handler for both channels will be called and
   thus that RR3 will always be read at least once, even if ch A
   has no pending interrupt.
   NOTE: The modified interrupt vector has no value that represent
   a lack of pending interrupt for channel B. That is, the
   value read when no interrupts are pending is the same as the
   value for the special receive condition. Fortunately, we don't
   actually have to depend on that interrupt source. This does
   mean that we need to properly handle the overflow condition,
   when we read received character from the chip.
o  The DSR signal is represented by the SYNC bit in the external
   status register (RR0). We now properly track DSR.
o  It's save to enable the external/status interrupt source. We
   now get interrupts when line signals (DSR, DCD or CTS) change.

Problems fixes:
o  interrupt storms.
o  blocked open(2).
o  lack of (hardware) flow control.
o  unable to report DSR.

MFC after: 5 days
2005-01-30 09:00:50 +00:00
Warner Losh
098ca2bda9 Start each of the license/copyright comments with /*-, minor shuffle of lines 2005-01-06 01:43:34 +00:00
Marcel Moolenaar
f5929532f1 Don't obtain the HCDP address directly from the bootinfo structure.
Use a function to keep the details at arms length from uart(4).
2004-12-08 05:46:54 +00:00
Marius Strobl
36bdb858fa - Don't blindly use the return value of uart_cpu_channel() to calculate
the address of a channel on a SCC, it returns 0 on failure. [1]
- Hardcode channel 1 for the keyboard on Z8530, the information present
  in the Open Firmware device tree doesn't allow to determine this via
  uart_cpu_channel(). This makes the keyboard (if one backs out rev. 1.5
  of sys/dev/puc/puc_sbus.c and has both keyboard and mouse plugged in to
  avoid the hang that revision works around) and consequently syscons(4)
  on Ultra 2 work. There's a problem with the keyboard LEDs similar to
  the one on Ultra 60 (LEDs don't get lit under X) though, instead of
  lighting just a specific single one all get lit and can't be turned off
  again. [1]
- Add comments about what uart_cpu_channel() and uart_cpu_getdev_keyboard()
  do and their constraints.
- Improve the comments about what uart_cpu_getdev_[console,dbgport]() do,
  they don't return an address (as in bus) but an Open Firmware package
  handle.

Reviewed by:	marcel (modulo the comments) [1]
2004-11-28 16:00:36 +00:00
Yoshihiro Takahashi
ea54c3694c uart_i8251_ops is gone. 2004-11-21 15:18:35 +00:00
Marcel Moolenaar
57a8f01dc1 o Support for the i8251 wasn't there. Remove the files.
o  Remove the headers with IC register definitions. The headers are
   now taken from sys/dev/ic
2004-11-21 01:51:37 +00:00
Marcel Moolenaar
0204ed7a3f Include the header with the register definitions from sys/dev/ic. They
are shared now.
2004-11-21 01:43:27 +00:00
Marcel Moolenaar
76563bea53 Include the common <dev/ic/ns16550.h> instead of the private
<dev/uart_dev_ns8250.h>. The latter can be removed now.
2004-11-20 23:22:04 +00:00
Marius Strobl
37f37506de Remove the whole uart_cpu_identify() stuff again. Now that it's no longer
used on sparc64 they are only stubs on all architectures and it doesn't
look like if we would need it in the near future again.

Ok'ed by:	marcel
2004-11-17 20:01:43 +00:00
Marius Strobl
8ff995cc5f o sparc64/isa/isa.c:
- The claim in the commit log of rev. 1.11 of dev/uart/uart_cpu_sparc64.c
    etc. that UARTs are the only relevant ISA devices on sparc64 turned out
    to be false. While there are sparc64 models where UARTs are the only
    devices on the ISA bus there are in fact also low-cost models where all
    devices traditionally found on the EBus are hooked up to the ISA bus.
    There are also models that use a mix between EBus and ISA devices with
    things like an AT keyboard controller and other rather interesting
    devices that we might want to support in the futute hook up to the ISA
    bus.
    In order to not need to add sparc64 specific device_identify methods to
    all of the respective ISA drivers and also not add OFW specific code to
    the common ISA code make the sparc64 ISA bus code fake up PnP devices so
    most ISA drivers probe their devices without further changes.
    Unfortunately Sun doesn't adhere to the ISA bindings defined in IEEE
    1275-1994 for the properties of most of the ISA devices which would
    allow to obtain the vendor and logical IDs from their properties. So we
    we just use a simple table which maps the name properties to PnP IDs.
    This could be done in a more sophisticated way but I courrently don't
    see the need for this. [1]
  - Add the children with fully mapped and specified resources (in the OFW
    sense) similar to what is done in the EBus code for the IRQ resources
    of the children as adjusting the resources and the resource list entries
    respectively in isa_alloc_resource() as done perviously causes trouble
    with drivers which use rman_get_start(), pass-through or allocate and
    release resources multiple times, etc.
    Adjusting the resources might be better off in a bus_activate_resource
    method but the common ISA code currently doesn't allow for an
    isa_activate_resource(). [2]
    With this change:
    - ppbus(4) and lpt(4) attach and work (modulo ECP mode, which requires
      real ISADMA code but it currently only consists of stubs on sparc64).
    - atkbdc(4) and atkbdc(4) attach, no further testing done.
    - fdc(4) itself attaches but causes a hang while attaching fd0 also
      when is DMA disabled, further work in fdc(4) is required here as e.g.
      fd0 uses the address of fd1 on sparc64 (not sure if sparc64 supports
      more than one floppy drive at all).
    All of these drivers previously caused panics in the sparc64 ISA code.
  - Minor changes, e.g. use __FBSDID, remove a dupe word in a comment and
    declare one global variable which isn't used outside of isa.c static.
o dev/uart/uart_cpu_sparc64.c and modules/uart/Makefile:
  - Remove the code for registering the UARTs on the ISA bus from the
    sparc64 uart_cpu_identify() again and rely on probing them via PnP.

Original idea by:	tmm [1]
No objections by:	tmm [1], [2]
2004-11-17 14:44:10 +00:00
Marcel Moolenaar
bfa307a39c Be slightly more paranoid about using the divisor in a division and
the calculated baudrate. Neither should be 0.
2004-11-15 00:00:24 +00:00
Marcel Moolenaar
d8518925d0 Implement UART_IOCTL_BAUD. Consequently, when the baudrate was unset
for the console, we emit the actual baudrate during bus enumeration.
2004-11-14 23:31:19 +00:00
Marcel Moolenaar
54e2bcc7ad Add UART_IOCTL_BAUD to allow us to query the hardware about the
current baudrate setting. Use this ioctl() when we don't know the
baudrate of the sysdev (as represented by a 0 value). When the
ioctl() fails, e.g. when the backend hasn't implemented it or the
hardware doesn't provide the means to determine its current baudrate
setting, we invalidate the baudrate setting by setting it to -1.
None of the backends currently implement the new ioctl().
2004-11-14 23:12:14 +00:00
Marcel Moolenaar
ecf4dc2505 Make sure the baudrate specified with the BR tag is somewhat sane.
A baudrate we consider insane is silently replaced with 0. When the
baudrate is 0, we will not try to program the hardware. Instead we
leave the communication speed unaltered, maximizing the chance to
have a working console. Obviously this means we allow specifying a
0 baudrate for exactly that purpose.
2004-11-14 21:38:22 +00:00
Poul-Henning Kamp
fbbec42fe4 Remove asserts which are not correct if the port is a tty. 2004-10-12 21:00:19 +00:00
Poul-Henning Kamp
79a8d927d3 Use generic tty code instead of (comparatively little) local copies. 2004-10-12 08:22:31 +00:00
Poul-Henning Kamp
9e51d6f15d Use tty->t_sc to find out softc. 2004-09-18 16:43:44 +00:00
Poul-Henning Kamp
a45b36ad47 Use ttyalloc() instead of ttymalloc(NULL) 2004-09-17 07:28:07 +00:00
Marius Strobl
8f0882f544 Don't call uart_bus_probe() for non-matching PnP-devices. Trying to probe
the keyboard controller with uart_bus_probe() caused a hang here on an i386
machine.

Approved by:	marcel
2004-08-25 22:15:33 +00:00
Marius Strobl
115e9ac656 Fix a style(9) bug (variable definitions inside a nested scope) a patch
of mine introduced in revision 1.10.

Approved by:	marcel
Prodded by:	marcel
2004-08-15 02:17:20 +00:00
Marius Strobl
efa79eb77e - Introduce an uart_cpu_identify() which is implemented in uart_cpu_<arch>.c
and that can be used as an identify function for all kinds of busses on a
  certain platform. Expect for sparc64 these are only stubs right now. [1]
- For sparc64, add code to its uart_cpu_identify() for registering the on-
  board ISA UARTs and their resources based on information obtained from
  Open Firmware.
  It would be better if this would be done in the OFW ISA code. However, due
  to the common FreeBSD ISA code and PNP-IDs not always being present in the
  properties of the ISA nodes there seems to be no good way to implement that.
  Therefore special casing UARTs as the sole really relevant ISA devices on
  sparc64 seemed reasonable. [2]

Approved by:	marcel
Discussed with:	marcel [1], tmm [2]
Tested by:	make universe
2004-08-14 23:54:27 +00:00
Marius Strobl
26280d88d7 - Introduce an ofw_bus kobj-interface for retrieving the OFW node and a
subset ("compatible", "device_type", "model" and "name") of the standard
  properties in drivers for devices on Open Firmware supported busses. The
  standard properties "reg", "interrupts" und "address" are not covered by
  this interface because they are only of interest in the respective bridge
  code. There's a remaining standard property "status" which is unclear how
  to support properly but which also isn't used in FreeBSD at present.
  This ofw_bus kobj-interface allows to replace the various (ebus_get_node(),
  ofw_pci_get_node(), etc.) and partially inconsistent (central_get_type()
  vs. sbus_get_device_type(), etc.) existing IVAR ones with a common one.
  This in turn allows to simplify and remove code-duplication in drivers for
  devices that can hang off of more than one OFW supported bus.
- Convert the sparc64 Central, EBus, FHC, PCI and SBus bus drivers and the
  drivers for their children to use the ofw_bus kobj-interface. The IVAR-
  interfaces of the Central, EBus and FHC are entirely replaced by this. The
  PCI bus driver used its own kobj-interface and now also uses the ofw_bus
  one. The IVARs special to the SBus, e.g. for retrieving the burst size,
  remain.
  Beware: this causes an ABI-breakage for modules of drivers which used the
  IVAR-interfaces, i.e. esp(4), hme(4), isp(4) and uart(4), which need to be
  recompiled.
  The style-inconsistencies introduced in some of the bus drivers will be
  fixed by tmm@ in a generic clean-up of the respective drivers later (he
  requested to add the changes in the "new" style).
- Convert the powerpc MacIO bus driver and the drivers for its children to
  use the ofw_bus kobj-interface. This invloves removing the IVARs related
  to the "reg" property which were unused and a leftover from the NetBSD
  origini of the code. There's no ABI-breakage caused by this because none
  of these driver are currently built as modules.
  There are other powerpc bus drivers which can be converted to the ofw_bus
  kobj-interface, e.g. the PCI bus driver, which should be done together
  with converting powerpc to use the OFW PCI code from sparc64.
- Make the SBus and FHC front-end of zs(4) and the sparc64 eeprom(4) take
  advantage of the ofw_bus kobj-interface and simplify them a bit.

Reviewed by:	grehan, tmm
Approved by:	re (scottl)
Discussed with:	tmm
Tested with:	Sun AX1105, AXe, Ultra 2, Ultra 60; PPC cross-build on i386
2004-08-12 17:41:33 +00:00
Marcel Moolenaar
dc70e792a6 Do not use hardware flow control for the moment. There are some issues
with it that need to be understood better before they can be resolved.
This takes time and time is already in short supply.

Reported & tested by: glebius@
2004-08-06 15:51:31 +00:00
Marcel Moolenaar
d882cf921f When sizing the FIFO, don't count all the way up to 1030 if any FIFO
size larger than 128 is considered an incompatible size. Stop counting
when we reach 130 in the loop.
2004-07-26 03:54:40 +00:00
Poul-Henning Kamp
672c05d49c Preparation commit for the tty cleanups that will follow in the near
future:

rename ttyopen() -> tty_open() and ttyclose() -> tty_close().

We need the ttyopen() and ttyclose() for the new generic cdevsw
functions for tty devices in order to have consistent naming.
2004-07-15 20:47:41 +00:00
Marcel Moolenaar
591bc192b3 Update for the KDB framework:
o  Call kdb_enter() instead of breakpoint().
o  Call kdb_alt_break() instead of db_alt_break().
o  Make debugging code conditional upon KDB instead of DDB.
2004-07-10 21:16:01 +00:00
Marcel Moolenaar
89438367ae Add support for uart(4) being a debug port for the GDB backend. 2004-07-10 18:08:38 +00:00
Poul-Henning Kamp
b4994e318a Define the tty methods as typedefs.
Change the return type for t_break to void.

Add t_ioctl (more about this later).
2004-06-30 21:38:08 +00:00
Poul-Henning Kamp
96df2b0bfb Use generic support for BREAK and modem control ioctls. 2004-06-25 10:54:05 +00:00
Poul-Henning Kamp
28710806cb Use the new serial port definitions for modemsignals. 2004-06-24 10:07:28 +00:00
Poul-Henning Kamp
ee531086ca save a few redundant lines by moving the retry loop further backwards. 2004-06-23 10:28:09 +00:00
Poul-Henning Kamp
89c9c53da0 Do the dreaded s/dev_t/struct cdev */
Bump __FreeBSD_version accordingly.
2004-06-16 09:47:26 +00:00
Poul-Henning Kamp
2140d01b27 Machine generated patch which changes linedisc calls from accessing
linesw[] directly to using the ttyld...() functions

The ttyld...() functions ar inline so there is no performance hit.
2004-06-04 16:02:56 +00:00
Poul-Henning Kamp
e451f9b758 Make the remaining serial drivers call ttyioctl() rather than calling
the linedisc directly.
2004-06-04 08:02:37 +00:00
Poul-Henning Kamp
186f2b9e04 Add missing <sys/module.h> includes currently relying on nested include
in <sys/kernel.h>
2004-06-03 06:10:02 +00:00
Warner Losh
2e31e339d1 Fix disordering of pccarddevs.h noticed by bde. Also remove a few
redundant includes and fix some of the include disordering.

Submitted by: bde
2004-05-27 03:49:45 +00:00
Thomas Moestl
89eef2de47 It seems that clearing the MCR_IE bit in the modem control register
does not reliably prevent the triggering of interrupts for all supported
configurations. Thus, the FIFO size probe could cause an interrupt,
which could lead to an interrupt storm in the shared interrupt case.

To prevent this, change ns8250_bus_probe() to use the overflow bit in
the line status register instead of the RX ready bit in the interrupt
identification register to detect whether the FIFO has filled up.
This allows us to clear all bits in the interrupt enable register during
the probe, which should prevent interrupts reliably.
Additionally, the detected FIFO size may be a bit more accurate, because
the overflow bit is only set when the FIFO did actually fill up, while
interrupts would trigger a bit early.

Reviewed and tested on a lot of hardware by:	marcel
2004-05-26 21:59:01 +00:00
Warner Losh
dba6dd177b Move to generating pccarddevs.h on the fly, both for the kernel and
the modules.

Also generate usbdevs.h automatically now, but a non-kernel file is
stopping that at the moment.
2004-05-26 00:53:10 +00:00
Yoshihiro Takahashi
d385ba7313 - Initialize uart_bus_space_io and uart_bus_space_mem.
- Fix wrong comment.
2004-05-16 14:12:05 +00:00
Marcel Moolenaar
eced428604 Fix hangs caused by z8530_bus_ipend() returning UART_IPEND_TXIDLE
not as a pending interrupt status, but as a matter of status quo.
Consequently, when there's no data to be transmitted the condition
is not cleared and uart_intr() is stuck in an infinite loop trying
to clear the UART_IPEND_TXIDLE status.
The z8530_bus_ipend() function is changed to return idle only once
after having sent any data.

The root cause for this problem is that we cannot use the interrupt
status bits of the SCC itself. The register that holds the interrupt
status can only be accessed by channel A and holds the status for
both channels. Using the interrupt status register would complicate
the driver because we need to synchronize access to the SCC between
the channels.

Elementary testing: marius
2004-05-04 06:58:10 +00:00
Marcel Moolenaar
5918c72d28 When the interrupt cannot be INTR_FAST, it still is INTR_MPSAFE.
Mark it as such.
2004-05-04 05:54:02 +00:00