powerpc: Split CPU flags into separate file and include in ELF header
This change fixes Bug 239621, where FreeBSD on powerpc deviates from
userspace expectations on other architectures (arm) and operating
systems (Linux)
Approved by: jhibbits (mentor)
MFC after: 1 week
arm64: Add MediaTek SoC support skeleton
Add the SOC_MEDIATEK and SOC_MEDIATEK_MT7986 options, list them in
NOTES, add std.mediatek, include it in GENERIC and in a MEDIATEK kernel
configuration, and add a DTB module that builds the Banana Pi BPI-R3
(MT7986A) DTB.
Reviewed by: mmel
Approved by: markj (mentor)
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61186
clk/mediatek: Add common MediaTek clock and reset support
MediaTek SoCs split their clock tree over several controllers built from
the same blocks. Add a base driver that maps a controller's registers
and registers its table of clocks, and the node types the tables use:
- PLL with the MT7986 register layout: the rate is set by the
frequency control word and the post divider. A new control word is
only taken over when the PLL is enabled, so a running PLL is stopped
while its rate is changed, and a PLL that cannot stop keeps its rate.
Without a lock bit, a PLL that was never programmed cannot be told
from a stopped one, so the node has no gate: firmware starts the
PLLs, and a PLL that is off reports 0 Hz and cannot be set.
- Mux with an optional gate bit and an optional update latch, changed
by read-modify-write or, where the mux register is read-only,
through set/clear registers.
- Gate, changed in the same two ways.
Clocks of other controllers are linked clocks, so the registration order
[15 lines not shown]
uart: Add a flags field to struct uart_bas
uart_bus_probe() sets UART_BAS_IN_PROBE in it while the hardware driver
probes. The softc is then still a plain struct uart_softc, so code that
the probe method shares with attached devices can check the flag before
using the class specific fields.
No functional change.
Reviewed by: mmel
Approved by: markj (mentor)
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61620
uart: Factor out the ns8250 baud rate generator code
Move the code that programs the divisor latch out of ns8250_param()
into ns8250_set_baudrate(), and the code that computes the rate from
it out of the UART_IOCTL_BAUD handler into ns8250_get_baudrate().
ns8250_get_divisor() now returns the input clock cycles per bit,
prescaler included, in units of 1 / NS8250_DIVISOR_SCALE, and the
rate, the delays and the rclk guess are derived from it. This leaves
room for other prescalers and for fractional dividers.
ns8250_delay() is now computed in 64 bits with one formula. The old
code split at a divisor of 134 to keep 16000000 * divisor within an int
(ebecffe93038), and above 134 divided by rclk / 1000 rounded down. With
a clock that is not a multiple of 1 kHz this made the delay longer by
(rclk % 1000) / (rclk - rclk % 1000): 0.011% with a 1.8432 MHz clock,
e.g. 20002 instead of 20000 us at 50 baud. Up to a divisor of 134 the
result is the same. The delay is only a polling interval for
ns8250_drain() and the FIFO size probe.
[7 lines not shown]
clk/mediatek: Add MT7986 INFRACFG clock and reset controller
INFRACFG provides the clock muxes and gates of the infrastructure
peripherals, and is their reset controller (the binding requires
#reset-cells). It attaches after TOPCKGEN.
The gate and mux status registers are read-only (checked on a Banana
Pi BPI-R3), so gates and muxes are changed through their set and clear
registers.
The resets come in three banks, each with an assert register, a deassert
register at +4 and a status register at +8. Reset id n is bit n % 32 of
bank n / 32. Bank 0 at 0x70 is the one MediaTek's TF-A uses for the
TRNG [1]. Banks 1 (0x80) and 2 (0x90) were found on a Banana Pi BPI-R3
by resetting known blocks.
The clocks follow the MT7986 drivers of Linux [2] and U-Boot [3], which
were used for hardware facts only, with two changes:
[19 lines not shown]
uart: Add MediaTek UART driver
The MediaTek UART is a 16550 with 32-bit spaced registers and a
fractional baud rate generator. The driver gives that generator to the
ns8250 code through its set_baudrate, get_baudrate and get_divisor
functions, and uses the ns8250 code for everything else. The low-level
console uses the ns8250 code too, so it keeps the rate the firmware set.
For the 30 MHz clock of Table 2-6 of the reference manual [1], the
divisor, SAMPLE_COUNT, SAMPLE_POINT and the number of extended bits are
the table's, except at 7200 baud, where one extended bit is closer than
the table's two. Rates that need fewer than 8 samples per bit are
rejected: below that, the manual requires guard time from the sender.
Probe enables the clocks while it runs, attach applies the assigned
clocks and enables them, and detach releases them. The console is
probed on the clocks the firmware left running and keeps its clocks on
detach. Until there is an MT7986 pinctrl driver, UART1 and UART2 rely
on the firmware's pin setup.
[9 lines not shown]
uart: Let ns8250 drivers provide their own baud rate generator
Add set_baudrate, get_baudrate and get_divisor function pointers to
struct ns8250_softc. A driver for a UART with a baud rate generator of
its own sets them before calling ns8250_bus_attach(), which sets the
ones left NULL to the 16550 functions. The param, ioctl, flush and
transmit methods use them, and ns8250_delay(), ns8250_drain() and
ns8250_flush() now take the softc to reach them.
While probing, the softc is not yet an ns8250_softc, so ns8250_delay()
uses the 16550 divisor when UART_BAS_IN_PROBE is set. The low-level
console code, which has no softc, also uses the 16550 functions.
No functional change for existing drivers.
Reviewed by: mmel
Approved by: markj (mentor)
Sponsored by: Alchemilla Ventures Private Limited
Differential Revision: https://reviews.freebsd.org/D61611
arm64/pmap: Ignore pmap_advise() for stage 2 pmaps
When vm_fault() handles a sequential fault that needs pager I/O, it
calls vm_fault_dontneed(), which passes MADV_DONTNEED to pmap_advise()
for the pages behind the fault. For vmm(4) guest memory the pmap is a
stage 2 pmap, so a guest that reads paged-out memory sequentially
panics an INVARIANTS kernel on the stage 1 assertion in pmap_advise().
MADV_DONTNEED and MADV_FREE are only hints, so ignore them for stage 2
pmaps.
Reviewed by: markj
Approved by: markj (mentor)
Sponsored by: Alchemilla Ventures Private Limited
MFC after: 1 week
Differential Revision: https://reviews.freebsd.org/D61622
elf_common.h: Correct R_X86_64_JUMP_SLOT name
x86-64 ABI dated March 12, 2025 lists this relocation type as
R_X86_64_JUMP_SLOT. Update the name, and add R_X86_64_JMP_SLOT (without
a "U") as an alias.
Reviewed by: kib
Sponsored by: The FreeBSD Foundation
Differential Revision: https://reviews.freebsd.org/D61776
bhyve/riscv: fix PCIe FDT interrupt-map entry stride
In bhyve arm64, each PCIe interrupt-map entry spans 10 cells because the
ARM GIC specifies #interrupt-cells = 3. On RISC-V, the APLIC uses
#interrupt-cells = 2, so each entry spans only 9 cells.
When the PCIe FDT code was originally adapted from arm64, the property
allocation size and cell assignments were reduced to 9 cells per entry,
but the loop multiplier retained the 10-cell stride. This caused the
interrupt-map array to be packed incorrectly with gaps, breaking PCI
interrupt routing in guest operating systems and overflowing the
allocation by 16 cells.
Correct the loop stride to 9 cells so the interrupt map is properly
formed.
Approved by: re (cperciva)
Reviewed by: jrtc27
Fixes: 7ab1a32cd43c ("bhyve/riscv: Initial import")
[28 lines not shown]
contrib/kyua: update config.h for 0.15.1 -> 0.15.2
This was accidentally missed in the prior commit.
This commit addresses a largely cosmetic issue.
MFC after: 6 days
MFC with: c16da33701d0
Fixes: c16da33701d0 contrib/kyua: update to 0.15.2
Remove {ATF,PLAIN}_REQUIRE_KERNEL_MODULE macros
These macros predated the `require.kmod` (ATF) and `required_kmods`
(kyua) test metadata and are no longer needed.
Add a hint to freebsd_test_suite/macros.h about the `*FEATURE*` macros
going away soon. See [this kyua issue][kyua-issue] for more details.
MFC after: 1 month
Differential Revision: https://reviews.freebsd.org/D61082
[kyua-issue]: https://github.com/freebsd/kyua/issues/346
mii: call only PHY_STATUS() from mii_pollstat()
When we are in mii_pollstat() which effectively is called only from
ue_mii_sts methods of various drivers, we are interested in polling the
status and not making any actions.
What PHY_SERVICE(,, MII_POLLSTAT) effectively did was PHY_STATUS()
followed by mii_phy_update(). The latter is undesired, as we already may
be servicing a link state change event and posting a second one is not
what we want. Usually mostly harmless, this second event would panic when
device is calling into mii during its detach (e.g. USB device).
NB: there are few drivers that would do extra stuff between PHY_STATUS()
and mii_phy_update() in their mii_service methods. This seems irrelevant
to me when we are in ue_mii_stat/mii_pollstat. But I could be wrong.
See the PR for longer discussion.
PR: 290417
tests/ssl_sendfile: size socket buffers before connecting
The :grow, :truncate and :eagain_vs_eof cases rely on the socket buffers
filling up before the whole file has been sent. :grow and :truncate shrank
SO_SNDBUF and SO_RCVBUF only after the connection was established, when
the receiver had already advertised a window based on the default buffer
size; TCP does not shrink an advertised window. :eagain_vs_eof used the
default, autosized buffers. With a large net.inet.tcp.recvspace, or once
autosizing has grown the buffers, the whole 2 MB file fits in the socket
buffers:
:grow and :truncate: sendfile(2) returns before the file is resized, and
the poll loop that waits for the sender to block spins forever on a
writable socket.
:eagain_vs_eof: the loop that keeps writing until
EAGAIN never sees it, since sendfile(2) returns 0 at EOF.
Either way kyua reports a timeout, which is why doubling the timeouts did
not help. Apply a 128 KB buffer size to the listening socket, which the
[12 lines not shown]
bhyve/riscv: fix PCIe FDT interrupt-map entry stride
In bhyve arm64, each PCIe interrupt-map entry spans 10 cells because the
ARM GIC specifies #interrupt-cells = 3. On RISC-V, the APLIC uses
#interrupt-cells = 2, so each entry spans only 9 cells.
When the PCIe FDT code was originally adapted from arm64, the property
allocation size and cell assignments were reduced to 9 cells per entry,
but the loop multiplier retained the 10-cell stride. This caused the
interrupt-map array to be packed incorrectly with gaps, breaking PCI
interrupt routing in guest operating systems and overflowing the
allocation by 16 cells.
Correct the loop stride to 9 cells so the interrupt map is properly
formed.
Reviewed by: jrtc27
Fixes: 7ab1a32cd43c ("bhyve/riscv: Initial import")
MFC after: 3 days
[3 lines not shown]
Revert "bhyve/riscv: fix PCIe FDT interrupt-map entry stride"
Thanks to past me's foolish choice not to alter the commit message such
that none of its lines start with a #, Git got very confused the
cherry-pick and included its own commented-out instructions. Reverting
to re-land with a fixed body.
This is a direct commit to stable/15.
This reverts commit 69f76efd01a72fe0d6cb68442d2c15d3174a268f.
bhyve/riscv: fix PCIe FDT interrupt-map entry stride
In bhyve arm64, each PCIe interrupt-map entry spans 10 cells because the
ARM GIC specifies #interrupt-cells = 3. On RISC-V, the APLIC uses
#interrupt-cells = 2, so each entry spans only 9 cells.
When the PCIe FDT code was originally adapted from arm64, the property
allocation size and cell assignments were reduced to 9 cells per entry,
but the loop multiplier retained the 10-cell stride. This caused the
interrupt-map array to be packed incorrectly with gaps, breaking PCI
interrupt routing in guest operating systems and overflowing the
allocation by 16 cells.
Correct the loop stride to 9 cells so the interrupt map is properly
formed.
Reviewed by: jrtc27
Fixes: 7ab1a32cd43c ("bhyve/riscv: Initial import")
MFC after: 3 days
[25 lines not shown]