Commit Graph

480 Commits

Author SHA1 Message Date
Warner Losh
031beb4e23 sys: Remove $FreeBSD$: one-line sh pattern
Remove /^\s*#[#!]?\s*\$FreeBSD\$.*$\n/
2023-08-16 11:54:58 -06:00
Warner Losh
685dc743dc sys: Remove $FreeBSD$: one-line .c pattern
Remove /^[\s*]*__FBSDID\("\$FreeBSD\$"\);?\s*\n/
2023-08-16 11:54:36 -06:00
Warner Losh
95ee2897e9 sys: Remove $FreeBSD$: two-line .h pattern
Remove /^\s*\*\n \*\s+\$FreeBSD\$$\n/
2023-08-16 11:54:11 -06:00
Warner Losh
4d846d260e spdx: The BSD-2-Clause-FreeBSD identifier is obsolete, drop -FreeBSD
The SPDX folks have obsoleted the BSD-2-Clause-FreeBSD identifier. Catch
up to that fact and revert to their recommended match of BSD-2-Clause.

Discussed with:		pfg
MFC After:		3 days
Sponsored by:		Netflix
2023-05-12 10:44:03 -06:00
Kyle Evans
20d8d9809a Revert "uart(4): add Sunrise Point UART controllers"
This reverts commit d1b6271118.

I've received multiple reports of machines failing to boot with
this hardware; back it out for now until we can fix it.

PR:		271147
MFC after:	Morning coffee
2023-05-09 01:38:32 -05:00
Dimitry Andric
bab8274c09 Use bool for one-bit wide bit-fields
A signed one-bit wide bit-field can take only the values 0 and -1. Clang
16 introduced a warning that "implicit truncation from 'int' to a
one-bit wide bit-field changes value from 1 to -1". Fix the warnings by
using C99 bool.

Reported by:	Clang 16
Reviewed by:	emaste, jhb
MFC after:	3 days
Differential Revision: https://reviews.freebsd.org/D39705
2023-04-25 19:26:03 +02:00
Kyle Evans
d1b6271118 uart(4): add Sunrise Point UART controllers
Sponsored by:	Zenith Electronics LLC
Sponsored by:	Klara, Inc.
2023-04-14 09:58:00 -05:00
Wei Hu
8ea7fa16d9 uart: Don't change settings or throttle putc for Hyper-V
Azure setup does not like it when FreeBSD overrides the settings of the
UART device. When Hyper-V is detected, don't do this and also don't
throttle putc() output. This is a workaround for the early boot hang
of FreeBSD on Azure.

Tested on Azure, ESXi (VM with serial port), and SG-8200

PR:		264267
Reviewed by:	kevans, whu
Tested by:	whu
Obtained from:	Rubicon Communications, LLC (Netgate)
MFC after:	2 weeks
Sponsored by:	Rubicon Communications, LLC (Netgate)
2023-03-18 07:07:54 +00:00
Andrew Turner
f9ccec823a Add support for the new Arm Generic UART _HID
Historically the ACPI _HID for both the Arm PL011 and Generic UARTs
was ARMH0011. In the Arm Base Boot Requirements 2.0 the Generic UART
_HID is changed to ARMHB000. Use this new value in the PL011 driver
where we support both UART types.

This has been observed in some recent EDK2 builds.

Sponsored by: Arm Ltd
2022-12-22 14:24:40 +00:00
Stuart McLaren
68ca3a1553
uart(4): Add support for AMT virtual serial port (C610/X99 series)
PR:		267053
MFC after:	3 days
2022-12-20 23:56:00 +08:00
Colin Percival
5ad8c32c72 ns8250: Fix sense of LSR_TEMT FCR check
When flushing the UART, we need to drain manually if LSR_TEMT is
*not* asserted, aka. if the transmit FIFO is not empty.

Reported by:	void <void@f-m.fm>
Fixes:		c4b68e7e53 "ns8250: Check if flush via FCR succeeded"
Differential Revision:	https://reviews.freebsd.org/D37185
2022-10-28 12:20:28 -07:00
Colin Percival
c4b68e7e53 ns8250: Check if flush via FCR succeeded
The emulated UART in the Firecracker VMM (aka the implementation in the
rust-vmm/vm-superio project) includes FIFOs but does not implement the
FCR register, which is used by ns8250_flush to flush the FIFOs.

Check the LSR to see if there is still data in the FIFOs and call
ns8250_drain if necessary.

Discussed with:	emaste, imp, jrtc27
Sponsored by:	https://patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D36979
2022-10-17 23:02:21 -07:00
Mitchell Horne
05b727fee5 Downgrade tty_intr_event from a global
It can be static within uart_tty.c. It is an open question whether there
remains any real benefit to having uart instances share a swi thread.

Reviewed by:	imp, markj, jhb
MFC after:	1 week
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D36938
2022-10-12 13:46:12 -03:00
Colin Percival
39d6144dcd ns8250_drain: Drain without DELAY first
In virtual machines with virtual UARTs which have fictitious baud
rates, it may be possible to drain the receive queue very quickly,
without needing to DELAY after each character.  Attempt to read
(and discard) the receive queue as fast as possible, stopping for
a DELAY only when LSR_RXRDY is no longer asserted; assume that we
have finished draining the queue when LSR_RXRDY is asserted both
before and after a DELAY.

This speeds up the boot process in FreeBSD/Firecracker by 27 ms.

Reviewed by:	imp, jrtc27
Sponsored by:	https://www.patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D36184
2022-10-07 17:51:54 -07:00
Kornel Dulęba
6bdc398832 uart_dev_snps: Fix device probing
The "uart_bus_probe" function is used as a generic part of uart probe
logic. It returns a driver priority(negative number) if successful and
an error code otherwise.
Fix the error checking condition to account for that.
Also, while here return "BUS_PROBE_VENDOR", instead of "0".
This fixes uart on clearfog pro with recent DT.

PR:		266657
Reviewed by:	mw
Obtained from:	Semihalf
Differential Revision: https://reviews.freebsd.org/D36880
2022-10-06 16:42:51 +02:00
Warner Losh
f341e9bad3 uart: Remove sbbc reference
sbbc support is for sparc64 only, which was removed in 58aa35d429.

Sponsored by:		Netflix
2022-09-30 18:26:45 -06:00
Warner Losh
881fca442f arm: Catch up with Samsung S3C2xx0 code removal
The code backing these uart_class was removed 7 years ago in
4648ee9525.

Sponsored by:		Netflix
2022-09-30 18:12:10 -06:00
Kyle Evans
4a4ad02da3 uart: uart_cpu_arm64: fix the build without FDT
clang 14 doesn't properly determine that we're unconditionally returning
if we have ACPI but not FDT.  Push FDT setup entirely into a new
function, much like we currently do with ACPI, and just return ENXIO if
that doesn't succeed.

Reviewed by:	andrew, manu (earlier version)
Differential Revision:	https://reviews.freebsd.org/D36788
2022-09-29 14:33:32 -05:00
Mateusz Kozyra
299b6c9cb1 uart_bus_acpi: Read clock frequency from bus
It is stored in the clock-frequency property.
In case of failure, fallback to the harcoded value stored in the
compat data.
Also, while here improve style.
Tested on LS1046ARDB and x86 PC.

Reviewed by:	mw
Obtained from:	Semihalf
Differential Revision: https://reviews.freebsd.org/D36326
2022-09-07 09:44:58 +02:00
Mateusz Kozyra
7cb73f654f uart: Add ACPI entry for LS1046A UART
NXP defines unique name for LS1046A UART - "NXP0018".
It is ns8250 compatible, adding a new uart compat data entry is enough
to make it work.
Tested on LS1046ARDB.

Approved by:	mw(mentor)
Reviewed by:	mw, kd
Obtained from:	Semihalf
Differential Revision:	https://reviews.freebsd.org/D36260
2022-08-22 09:16:08 +02:00
Colin Percival
07007f3147 uart: Don't check SPCR tables if !late_console
On x86 systems, the debug.late_console tunable makes it possible to set
up the console before we call pmap_bootstrap.  (The tunable is turned
on by default; setting late_console=0 results in consoles being probed
early.)

Unfortunately this is not compatible with using the ACPI SPCR table to
find the console, since consulting ACPI tables requires mapping memory
addresses.  As such, we skip the call to uart_cpu_acpi_spcr from
uart_cpu_x86 in the !late_console case.

Reviewed by:	imp
Sponsored by:	https://www.patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D35794
2022-07-13 23:17:44 -07:00
John Baldwin
c90ea83112 Remove unused uart_devclass. 2022-05-06 15:46:57 -07:00
Mateusz Guzik
f2edc91557 uart: plug a set-but-not-used var
Sponsored by:	Rubicon Communications, LLC ("Netgate")
2022-04-19 09:34:55 +00:00
John Baldwin
9e420b3742 uart_dev_lowrisc: Remove unused variables in stub functions. 2022-04-12 14:58:57 -07:00
John Baldwin
2fb87f5147 uart_mu: Remove unused variables. 2022-04-08 17:25:15 -07:00
Warner Losh
c8fe3923d8 quicc_bus_setsig: eliminate write only variable bas
Sponsored by:		Netflix
2022-04-04 22:30:20 -06:00
Colin Percival
ad93649d23 uart(4): Add a concept of "unique" serial devices
FreeBSD detects serial ports twice: First, very early in the boot
process, in order to obtain a usable console; and second, during
the device probe/attach process.  When a UART is discovered during
device probing, FreeBSD attempts to determine whether it is a
device which was already being used as a console; without this,
the console doesn't work in userland.

Unfortunately it's possible for a UART to be mapped to a different
location in memory when it is discovered on a bus than it has when
it is announced via the ACPI SPCR table; this breaks the matching
process, which relies on comparing bus addresses.

To address this, we introduce a concept of "unique" serial devices,
i.e. devices which are guaranteed to be present *only once* on any
system.  If we discover one of these during device probing, we can
match it to a same-PCI-vendor-and-device-numbers console which was
announced via the ACPI SPCR table, regardless of the differing bus
addresses.

At present, the only unique serial device is the "Amazon PCI serial
device" (vendor 0x1d0f, device 0x8250) found in some EC2 instances.
This unbreaks the serial console on those systems.

Reviewed by:	imp
MFC after:	3 days
Sponsored by:	https://www.patreon.com/cperciva
Differential Revision:	https://reviews.freebsd.org/D34703
2022-03-31 16:02:24 -07:00
Emmanuel Vadot
5c00765bf2 uart_dev_snps: Make ext_resources non-optional
EXT_RESOURCES have been introduced in 12-CURRENT and all supported
releases have it enabled in their kernel config.

MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33828
2022-02-21 17:28:54 +01:00
Emmanuel Vadot
4f64df4e32 uart_dev_imx: Make ext_resources non-optional
EXT_RESOURCES have been introduced in 12-CURRENT and all supported
releases have it enabled in their kernel config.

MFC after:      1 month
Differential Revision:	https://reviews.freebsd.org/D33826
2022-02-21 17:28:50 +01:00
Alexander Motin
c214c2c004 uart: Remove CTLFLAG_NEEDGIANT from sysctl.
MFC after:	2 weeks
2021-12-25 21:30:02 -05:00
Warner Losh
9eb5fd3599 uart: Match simple comm
Match the PCI simple comm devices (or try to). Be conservative and use
legacy interrupts rather than msi messages by default for this 'catch
all' since it matches what Linux does (it has opt-in generally for MSI,
but also matches more devices because it does a catch-all like
implemented in this commit).

Sponsored by:		Netflix
Reviewed by:		kbowling
Differential Revision:	https://reviews.freebsd.org/D32228
2021-09-30 14:16:19 -06:00
Warner Losh
bf40080762 uart: Allow PCI quirk for not using MSI interrupts
Some setups claim to have one MSI, but they don't actually work. Allow
these to be flagged.

Sponsored by:		Netflix
Reviewed by:		kbowling
Differential Revision:	https://reviews.freebsd.org/D32229
2021-09-30 14:15:32 -06:00
Sean Bruno
fb640be4e9 uart: Add PCI ID for intel 100 Series/C230 Series AMT
Reviewed by:	kib
Tested by:	kbowling
Differential Revision:	https://reviews.freebsd.org/D32146
2021-09-25 15:24:34 -07:00
Ed Maste
9feff969a0 Remove "All Rights Reserved" from FreeBSD Foundation sys/ copyrights
These ones were unambiguous cases where the Foundation was the only
listed copyright holder (in the associated license block).

Sponsored by:	The FreeBSD Foundation
2021-08-08 10:42:24 -04:00
Mark Johnston
4a9a41650c uart: Fix an out-of-bounds read in ns8250_bus_probe()
The problem is that ns8250_bus_probe() accesses a field from the
ns8250_softc, which embeds the generic UART softc, but the ns8250_softc
hasn't yet been allocated because we're still probing.

This is a regression from commit 0aefb0a63c.  This fixed a problem
where one of the upper four IER bits, which are usually reserved, needs
to be set in order to get RX interrupts before the RX FIFO is full.  At
the same time, we avoid clearing those reserved bits (see commit
58957d8717, though other UART drivers I looked at do not bother with
this).

So, copy what ns8250_init() does to disable interrupts, since we don't
know what the "right" mask is at this point.

Reported by:	syzbot+f256beefd0df9eb796e7@syzkaller.appspotmail.com
Reviewed by:	imp
MFC after:	2 weeks
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D31124
2021-07-13 17:49:39 -04:00
Marcin Wojtas
9cf66a0458 uart_dev_ns8250: Switch ACPI UART subtype for Marvell SoCs
DBG2 ACPI table description [1] specifies three subtypes
related to 16550 UART:
0x0 - 16550 compatible
0x1 - 16550 subset
0x12 - 16550 compatible with parameters defined in Generic Address Structure (GAS)

It turned out however, that the Windows OS treats 0x0 subtype as
legacy x86 UART with 8-bit access. ARM SoCs can use types 0x1 (16550 with
fixed mmio32 access) or 0x12 (16550 with fully respected GAS contents).

Switch Marvell SoCs ACPI UART subtype to 0x1 - thanks to that the same firmware
can run properly with UART output in FreeBSD, Windows 10, Linux and ESXI
hypervisor. Tests showed the older firmware versions that use 0x0
UART subtype in SPCR table continue to display output properly.

[1] https://docs.microsoft.com/en-us/windows-hardware/drivers/bringup/acpi-debug-port-table

Obtained from: Semihalf
Sponsored by: ARM
Differential revision: https://reviews.freebsd.org/D30386
MFC after: 2 weeks
2021-06-02 09:55:19 +02:00
Konstantin Belousov
eaf00819bc Add support for Gemini Lake LPSS UARTs.
With this patch:
% dmesg | grep -i uart
uart2: <Intel Gemini Lake SIO/LPSS UART 0> mem 0xa1426000-0xa1426fff,0xa1425000-0xa1425fff irq 4 at device 24.0 on pci0
uart3: <Intel Gemini Lake SIO/LPSS UART 1> mem 0xa1424000-0xa1424fff,0xa1423000-0xa1423fff irq 5 at device 24.1 on pci0
uart4: <Intel Gemini Lake SIO/LPSS UART 2> mem 0xfea10000-0xfea10fff irq 6 at device 24.2 on pci0
uart5: <Intel Gemini Lake SIO/LPSS UART 3> mem 0xa1422000-0xa1422fff,0xa1421000-0xa1421fff irq 7 at device 24.3 on pci0

PR:	256101
Submitted by:	 Daniel Ponte <amigan@gmail.com>
MFC after:	1 week
2021-05-23 20:46:32 +03:00
Jose Luis Duran
8f1562430f Add Apollo Lake SIO/LPSS UARTs PCI IDs
Add PCI IDs for Intel Apollo Lake Series HSUARTs:

    # pciconf -ll
    drv   selector      class    rev  hdr  vendor device subven subdev
    uart0@pci0:0:24:0:  118000   0b   00   8086   5abc   8086   7270
    uart1@pci0:0:24:1:  118000   0b   00   8086   5abe   8086   7270
    uart2@pci0:0:24:2:  118000   0b   00   8086   5ac0   8086   7270
    uart3@pci0:0:24:3:  118000   0b   00   8086   5aee   8086   7270

NB (Intel Document Number 336256-004US):
1. The E3900 and A3900 Series Processors support four LPSS_UART ports,
   while the N- and J- Series Processors support only LPSS_UART [2:1]
   ports.
2. The LPSS_UART1 port is dedicated for discrete Global Navigation
   Satellite System (GNSS).  This port can be used for generic UART
   functionality if GNSS is not used.
3. The LPSS_UART2 port is dedicated for host OS debug.
4. The LPSS_UART0 and LPSS_UART3 ports are for generic UART functionality.
5. Only UART [1:0] ports support DMA.

PR:	255556
Submitted by:	Jose Luis Duran <jlduran@gmail.com>
MFC after:	1 week
2021-05-03 14:38:52 +03:00
Jose Luis Duran
5b8b6b26e4 uart_bus_pci.c: Style
Wrap long lines, use tab instead of spaces.

PR:	255556
Submitted by:	Jose Luis Duran <jlduran@gmail.com>
MFC after:	1 week
2021-05-03 14:38:52 +03:00
Mitchell Horne
7e7f7beee7 ns8250: don't drop IER_TXRDY on bus_grab/ungrab
It has been observed that some systems are often unable to resume from
ddb after entering with debug.kdb.enter=1. Checking the status further
shows the terminal is blocked waiting in tty_drain(), but it never makes
progress in clearing the output queue, because sc->sc_txbusy is high.

I noticed that when entering polling mode for the debugger, IER_TXRDY is
set in the failure case. Since this bit is never tracked by the softc,
it will not be restored by ns8250_bus_ungrab(). This creates a race in
which a TX interrupt can be lost, creating the hang described above.
Ensuring that this bit is restored is enough to prevent this, and resume
from ddb as expected.

The solution is to track this bit in the sc->ier field, for the same
lifetime that TX interrupts are enabled.

PR:		223917, 240122
Reviewed by:	imp, manu
Tested by:	bz
MFC after:	5 days
Sponsored by:	The FreeBSD Foundation
Differential Revision:	https://reviews.freebsd.org/D29130
2021-03-10 11:04:42 -04:00
Warner Losh
955b6109bb uart: only use MSI on devices that advertise 1 MSI vector
This updates r311987/fb1d9b7f4113d which allowed any number of vectors to be
used. Since we're just attaching one instance, the meaning of more than one
vector is not clear and seems to cause problems. Fall back to old methods for
these cards.

PR: 235016
Submitted by: David Cross
2021-02-17 15:08:19 -07:00
Warner Losh
d1949353e5 uart: Improve console specification parsing
Print warning when we can't parse a console specification (this may
not appear on the console, but will appear in dmesg).

Also, accept key:value and key=value. There's no reason not to
and it makes this more forgiving of mistakes.

Reviewed by: rpokala@
Differential Revision: https://reviews.freebsd.org/D28168
2021-01-14 17:47:04 -07:00
Warner Losh
ba29d48c7c pccard: Remove uart(4) PC Card attachment
pccard is going away, so remove uart's attachment.

Relnotes: Yes
2021-01-07 20:23:09 -07:00
Marius Strobl
b63eeef41f scc(4)/uart(4): Remove obsolete support for Siemens SAB 82532
It's no longer used since 58aa35d429
and r357455 respectively.
2020-12-26 13:48:06 +01:00
Mitchell Horne
1c5d066a72 uart: allow UART_DEV_DBGPORT for fdt consoles
Allow fdt devices to be used as debug ports for gdb(4).

A debug console can be specified with the "freebsd,debug-path" property
in the device tree's /chosen node, or using the environment variable
hw.fdt.dbgport.

The device should be specified by its name in the device tree, for
example hw.fdt.dbgport="serial2".

PR:		251053
Submitted by:	Dmitry Salychev <dsl@mcusim.org>
Submitted by:   stevek (original patch, D5986)
Reviewed by:	andrew, mhorne
Differential Revision:	https://reviews.freebsd.org/D27422
2020-12-02 21:01:52 +00:00
Mateusz Guzik
bf10325475 uart: clean up empty lines in .c and .h files 2020-09-01 21:50:00 +00:00
Warner Losh
e0d14216c1 Tag pccard drivers with gone in 13.
MFC After: 3 days
Reviewed by: emaste, brooks, adrian (on twitter)
Differential Revision: https://reviews.freebsd.org/D26095
2020-08-20 17:19:40 +00:00
Michal Meloun
0050ea2415 Move Ti AM335x to dev/extres/clk framework.
Re-implement clocks for these SoC by using now standard extres/clk framework.
This is necessary for future expansion of these. The new  implementation
is (due to the size of the patch) only the initial (minimum) version.
It will be updated/expanded with a subsequent set of particular patches.

This patch is also not tested on OMAP4 based boards (BeagleBone),
so all possible issues should be (and will be) fixed by ASAP once
identified.

Submited by:		Oskar Holmlund (oskar.holmlund@ohdata.se)
Differential Revision:  https://reviews.freebsd.org/D25118
2020-07-30 14:45:05 +00:00
Oleksandr Tymoshenko
94bc2117b4 Add i.MX 8M Quad support
- Add CCM driver and clocks implementations for i.MX 8M
- Add GPC driver for iMX8
- Add clock tree for i.MX 8M Quad
- Add clocks support and new compat strings (where required) for existing i.MX 6 UART, I2C, and GPIO drivers
- Enable aarch64-compatible drivers form i.MX 6 in arm64 GENERIC kernel config
- Add dtb/imx8 kernel module with DTBs for Nitrogen8M and iMX8MQ EVK

With this patch both Nitrogen8M and iMX8MQ EVK boot with NFS root up to multiuser login prompt

Reviewed by:	manu
Differential Revision:	https://reviews.freebsd.org/D25274
2020-07-01 00:33:16 +00:00
Marcin Wojtas
fab2a758cc Fix AccessWidth and BitWidth parsing in SPCR table
The ACPI Specification defines a Generic Address Structure (GAS),
which is used to describe UART controller register layout in the
SPCR table. The driver responsible for parsing it (uart_cpu_acpi)
wrongly associates the Access Size field to the uart_bas's regshft
and the register BitWidth to the regiowidth - according to
the definitions it should be opposite.

This problem remained hidden most likely because the majority of platforms
use 32-bit registers (BitWidth) which are accessed with the according
size (Dword). However on Marvell Armada 8k / Cn913x platforms,
the 32-bit registers should be accessed with Byte granulity, which
unveiled the issue.

This patch fixes above by proper values assignment and slightly improved
parsing.

Note that handling of the AccessWidth set to EFI_ACPI_6_0_UNDEFINED is
needed to work around a buggy SPCR table on EC2 x86 "bare metal" instances.

Reviewed by: manu, imp, cperciva, greg_unrelenting.technology
Obtained from: Semihalf
MFC after: 2 weeks
Differential Revision: https://reviews.freebsd.org/D25373
2020-06-24 12:15:27 +00:00