ns16550a: extract reusable uart16550_core#226
Open
SolAstrius wants to merge 2 commits into
Open
Conversation
Signed-off-by: Sol Astrius <sol@astrius.ink>
Signed-off-by: Sol Astrius <sol@astrius.ink>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Splits the 16550 register decode + state machine out of
ns16550a.cinto a standalone, backend-agnostic module, then rewritesns16550a.cas a thin wrapper around it. Two commits: the extraction, then the rewrite.uart16550_core
The bus wrapper (rvvm_reg MMIO/PIO for ns16550a, BAR-windowed multi-port for an Exar PCIe combo card, etc.) embeds a
uart16550_core_t, drives byte-wide register access viauart16550_core_read/write, and supplies an IRQ callback so the core stays unaware of whether the line is wired via wired INTx, PCI INTx, or MSI.The register handlers are otherwise identical to the in-tree
ns16550aimplementation: same DLAB banking, same IIR priority encoding, same LSR composition, sameMSR=0xB0stub. Pure extraction, plus two behaviours the historicalns16550a.clacked:serial8250_do_startup's two junk-drain RBR reads. The core suppresses chardev draining until the guest writes IER with the RECV bit (kernel signalling "ready to receive"); it flips true once and stays true until cleanup, so flow-control toggles don't silently re-enable the junk-drain path on the next port reopen.uart16550_core_suspend()serializes/deserializes the core's seven register fields plusrx_armedviarvvm_snapshot_field; wrappers open the snapshot section themselves so multi-instance consumers (Exar) can name their per-port sections distinctly.ns16550a rewrite
The MMIO device, IRQ wiring, FDT registration, and snapshot section are all that remain ns16550a-specific; this file now just translates between
rvvm_reg_dev_tcallbacks anduart16550_core_read/write/update/suspend. 281 LOC → 137 LOC. Public API unchanged —rvvm_ns16550a_initsignature is identical, including theattr & RVVM_REG_ATTR_PIOtoggle for 8-byte PIO vs 4 KiB MMIO.Behaviour change worth noting
The RX-arm gate now applies on the canonical MMIO path too (previously it lived only in out-of-tree paths). The upside: Linux's startup junk-RBR-drain no longer eats the first character arriving on the serial console. The snapshot section keeps the
serial-ns16550aname; old snapshots withoutrx_armeddeserialize withrx_armed=0(equivalent to "kernel hasn't enabled RX yet on this restored instance"), which the next IER write fixes immediately — a small, self-correcting forward-compat break for a field that wasn't in the prior format.