diff --git a/CHANGELOG.md b/CHANGELOG.md index b6265829d..7ff3b1eda 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -141,6 +141,16 @@ hashes are given where a change is easiest to understand by reading the commit. - A pattern can name a device slot (`hpc3/c1`, `xio15/pci0/2`, `slot_b`) in place of its modules, for `log`, `--log`, `[debug] log` and `startup`. +### Keyboard + +- `headless` unplugs the keyboard, through a `keyboard` slot and device that + `--list-slots` shows (not on the Origin 200, Origin 2000 and Onyx2, which + have none), so a PROM that finds none can use its serial console. The O2 + already did; the others kept their keyboard. +- `headless` no longer drops the Indy's and Indigo2's Newport. Leave graphics + out with a `none` entry at `graphics`; the bench and cpu-test machines and + the snapshot fixtures do. + ### Serial ports - A port's host ends are a `serial` device at it: `backend` is one string or a diff --git a/FEATURES.md b/FEATURES.md index 1b8d9dfa9..9d9d0c2f7 100644 --- a/FEATURES.md +++ b/FEATURES.md @@ -256,7 +256,7 @@ the first `[section]`, because TOML tables continue until the next header. | `nveeprom` | `"nveeprom.bin"` | Indigo2 motherboard EEPROM file. GUI paths are relative to the selected machine folder. | | `banks` | `[128,128,0,0]` | RAM bank sizes in MB, up to eight entries (two banks on the Fuel, eight on the Tezro and the IP35 brick machines, four elsewhere; entries beyond the profile's bank count must be 0). On the O2 each entry is a DIMM pair's kit (32, 64, 128 or 256), largest first. On the Octane each entry is a pair of DIMMs, 64, 128, 256, 512, 1024 or 2048, filled from bank 0, 8192 in all. See profile constraints below. | | `scale` | `1` | Standalone window scale: 1–4. GUI uses its separate vm_scale. | -| `headless` | `false` | Suppress the standalone window. Newport is not fitted; O2 uses a serial console. Other graphics boards can remain fitted. Audio is independent. | +| `headless` | `false` | Suppress the standalone window and unplug the keyboard (the `keyboard` slot stays empty), so a PROM that finds none uses its serial console. Hardware is otherwise unchanged: every graphics board stays fitted, and a `none` entry at `graphics` leaves it out. Audio is independent. | | `no_audio` | `false` | Disable host audio output. The Indy and Indigo2 then have no HAL2; the O2's MACE audio, the Octane's and Onyx2's RAD1 and the Tezro's ICE1724 stay fitted and run silently. | | `keyboard` | `ansi` | Physical shape of the host keyboard: `ansi` (US, `\|` above Enter), `iso` (European) or `jis` (Japanese 106/109; use it with the PROM's `keybd` set to Japanese). It decides which SGI key the host's ambiguous key left of Enter sends; the guest applies the character layout. `--keyboard` overrides. | | `gdb_port` | `unset` | Start the GDB TCP stub; debugging is unavailable in lightning builds. | @@ -430,6 +430,7 @@ takes; `--device [NAME:]TYPE[@SLOT][,KEY=VALUE]...` adds or replaces one from th | `hostserial` | a serial port, `serialN`, N the number on the machine's case (`serial1` and `serial2`; the Onyx2's MediaIO adds `serial3` and `serial4`); `at` is required | `path` (required): a host serial port such as `"/dev/ttyUSB0"`. Its rate, framing, DTR, RTS and break follow the guest; its CTS, DCD, DSR and RI are the guest's modem inputs. Linux and macOS. See the serial ports section of [HELP.md](HELP.md). | | `midi_synth` | a serial port, as `hostserial` | `path` (required): a General MIDI SoundFont (`.sf2`), loaded at start. `gain` (`1.0`, 0 to 16): times the synth's own level, which leaves room for many voices; the host mix clips above full scale. `backend` (the host's default): where it plays, as an `audio` entry's backend (`default`, `pulse`, `wasapi`, `coreaudio`, `null` or `file:PATH`), whatever the machine's own sound does. It plays as a stream of its own (muted by `no_audio`); with a `file:` backend, into a file beside it (`out.wav` → `out-midi.wav`); `IRIS_MIDI_CAPTURE=file.wav` also records it. | | `midi_raw` | a serial port, as `hostserial` | `path` (required): a host MIDI port. A raw MIDI device (Linux: `"/dev/snd/midiC1D0"` or `"/dev/midi1"`) passes the bytes as they are, both ways; a host serial port with a MIDI interface (`"/dev/ttyUSB0"`) is set up as `hostserial` does. | +| `keyboard` | the `keyboard` slot, on every machine but the Origin 200, Origin 2000 and Onyx2 | The keyboard (PS/2, or USB on the machines whose keyboard is), placed by default. `headless`, or `none` at `keyboard`, leaves the slot empty unless an entry places one. | | `newport`, `express`, `impact`, `vpro`, `kona` | the graphics slot (alias `graphics`) | A graphics board; see [Graphics boards](#graphics-boards). | | `none` | any slot; `at` is required | Leaves the slot empty, so the default for it is not placed. A graphics board slot stays free for another board; any other slot stays held. At a serial, Ethernet or sound port it also drops the host end, as a `serial` with no `backend`; an Ethernet port's MAC goes too, and the machine's own is used, and a sound port's chip keeps running with its sound discarded. The Indy and Indigo2 always have their Ethernet. | @@ -579,7 +580,7 @@ its environment; the DS1687's RAM goes beside it in `.rtc`, the Octane's 512-byte image, and its clock in `.rtc.clock`), `banks` (the kit in each of the four DIMM pairs: 32, 64, 128 or 256 MB, largest first), `serial_log`, -`headless` (serial console instead of the graphics console and keyboard), +`headless` (no keyboard, so a serial console instead of the graphics console), `[clock] fixed_mhz` (CP0 Count; the CPU runs at twice it, so 90 MHz is a 180 MHz O2), a `net` device for the Ethernet (`mac`, or a `none` device at `ethernet` for an unplugged cable), `[[port_forward]]`, `nat_subnet`, `[nfs]` and `[[devices]]` @@ -689,7 +690,7 @@ iris-gui does not parse this standalone option set; use its named-machine UI. | `--rsh-dir` | Let the guest `rsh cat\|dd\|ls\|echo\|pwd` against this directory, read-only, through a built-in rsh server at the gateway (TCP 514). Nothing is executed on the host. Off when unset. | | `--perfetto FILE` | Record a Perfetto trace from startup (`perfetto` builds). `--perfetto-cats LIST` (default `all`) and `--perfetto-clock host\|guest` (default `host`) select what and on which timeline. See [docs/perfetto.md](docs/perfetto.md). | | `--load-elf` | Load a static ELF32 MSB (big-endian MIPS) binary into RAM before the CPU starts and set PC to its entry point, instead of booting the PROM. For bare-metal test binaries; see also the monitor's `loadelf`. | -| `--ci` | CI mode: enable the control socket and apply speed-favoring fidelity shortcuts. Hides the window unless --ci-display is set; offscreen graphics remain active unless --headless is explicitly set. | +| `--ci` | CI mode: enable the control socket and apply speed-favoring fidelity shortcuts. Hides the window unless --ci-display is set; offscreen graphics remain active. | | `--ci-socket` | Override the default control-socket path (`iris.sock` in `$TMPDIR`, else `/tmp`; `iris-ci` finds it there only under the same `TMPDIR`). | | `--ci-display` | With --ci, keep the Newport window visible for interactive test development (deferred rendering at 10–15 fps). | | `--serial-log` | Write every byte the guest emits on its serial console to this file, as `serial_log`. Useful for live tailing during an install. | diff --git a/HELP.md b/HELP.md index 61895d01d..e271dc7f6 100644 --- a/HELP.md +++ b/HELP.md @@ -737,8 +737,8 @@ WireGuard) instead of relying on it. It works with every graphics board through the common display interface, with the normal window open or under `--ci` with no window. A graphics board must be -fitted and producing frames: a serial-only machine, or an Indy or Indigo2 -whose Newport `--headless` removed, has no screen to serve. The window, the +fitted and producing frames: a machine with a `none` entry at `graphics` has no +screen to serve. The window, the monitor and any number of viewers can type and click at the same time. **iris-gui** serves the screen too: set **Serve on** in the Performance tab @@ -799,7 +799,7 @@ nveeprom = "nveeprom.bin" # 93CS56 NVRAM EEPROM file (Indigo2 only) banks = [128, 128, 0, 0] scale = 1 # window scale, kept across guest mode changes; --2x overrides -headless = false # no window; drops Newport, the O2 boots on its serial console (audio unaffected) +headless = false # no window, no keyboard; hardware otherwise unchanged (audio unaffected) no_audio = false # no sound device output (graphics unaffected) lock_aspect_ratio = true # false = free resize with letterboxing vsync = false # true = wait for the host monitor's vertical sync @@ -1114,7 +1114,7 @@ Display and audio --renderer gl (default) or wgpu (builds with the wgpu feature) --raster VPro, IMPACT: cpu (default) or wgpu --keyboard Host keyboard: ansi (default), iso or jis - --headless No window; drops Newport (other boards stay fitted), O2 uses serial + --headless No window, no keyboard; hardware otherwise unchanged --noaudio Disable sound device output (graphics unaffected) Networking @@ -1177,7 +1177,8 @@ iris --config /opt/iris/my_machine.toml # Headless — no window, suitable for Docker/CI (audio still active) iris --headless -# Headless with audio also disabled (lightest possible server mode) +# Headless with audio also disabled (the graphics board is still fitted; +# for a machine with none, add `--device none@graphics`) iris --headless --noaudio # Network-boot from the PROM: then `boot -f bootp()/unix` at the PROM monitor diff --git a/README.md b/README.md index 205ad4f4b..f982d8043 100644 --- a/README.md +++ b/README.md @@ -264,8 +264,7 @@ is incomplete; that guide states the limits. ### CI control socket and `iris-ci` Use [STORAGE.md](STORAGE.md#ci-control-socket-and-iris-ci) for Unix/TCP setup, -commands, serial capture, and scripts. `--ci` keeps offscreen graphics alive -unless `--headless` is explicitly selected. +commands, serial capture, and scripts. `--ci` keeps offscreen graphics alive. ### Scratch volume — file injection without networking diff --git a/STORAGE.md b/STORAGE.md index 62ddc2640..b7726999f 100644 --- a/STORAGE.md +++ b/STORAGE.md @@ -294,9 +294,8 @@ directory (`$TMPDIR`, else `/tmp`); on Windows it is TCP `127.0.0.1:19851`. default only when they run with the same `TMPDIR`; otherwise give both the path, `--ci-socket` to iris and `--socket` or `$IRIS_SOCKET` to iris-ci. `--ci` hides the host window unless you add `--ci-display`, while keeping -offscreen graphics alive for screenshots. Explicit `--headless` -disables Newport graphics. Use `--serial-log FILE` to keep a transcript of the -IRIX console. +offscreen graphics alive for screenshots. Use `--serial-log FILE` to keep a +transcript of the IRIX console. ``` cargo run --release --features lightning -- --ci diff --git a/bench/run/bare.toml b/bench/run/bare.toml index b55908a63..4c6ddca56 100644 --- a/bench/run/bare.toml +++ b/bench/run/bare.toml @@ -10,10 +10,13 @@ # it always is here. banks = [128, 128, 0, 0] -headless = true no_audio = true [machine] profile = "indy_ip24" +[[devices]] +type = "none" +at = "graphics" + [scsi] diff --git a/bench/run/run-local.sh b/bench/run/run-local.sh index 98f7880a4..91d676419 100755 --- a/bench/run/run-local.sh +++ b/bench/run/run-local.sh @@ -29,7 +29,7 @@ timeout "$TIMEOUT" "$IRIS" \ --config run/bare.toml \ --load-elf "$ELF" \ --test-device \ - --headless --noaudio \ + --noaudio \ "$@" 2>&1 | tee "$LOG" rc=${PIPESTATUS[0]} diff --git a/bench/run/run-prom.sh b/bench/run/run-prom.sh index cbe844718..6d41f18d5 100755 --- a/bench/run/run-prom.sh +++ b/bench/run/run-prom.sh @@ -29,12 +29,15 @@ cat > build/prom.toml <<'TOML' # The image goes on SCSI ID 2 so nothing mistakes it for a system disk and so # `boot -f dksc(0,2,8)irisbench` reads naturally. banks = [128, 128, 0, 0] -headless = true no_audio = true [machine] profile = "indy_ip24" +[[devices]] +type = "none" +at = "graphics" + [scsi] [scsi.2] @@ -44,7 +47,7 @@ TOML rm -f "$SOCK" "$LOG" "$IRIS" --config build/prom.toml --ci --ci-socket "$SOCK" \ - --test-device --headless --noaudio --serial-log "$LOG" --serial-log-overwrite \ + --test-device --noaudio --serial-log "$LOG" --serial-log-overwrite \ > build/prom-stdout.log 2>&1 & IRIS_PID=$! trap 'kill $IRIS_PID 2>/dev/null' EXIT diff --git a/clanker/irix/irix-install.md b/clanker/irix/irix-install.md index b0596dc69..a069276ff 100644 --- a/clanker/irix/irix-install.md +++ b/clanker/irix/irix-install.md @@ -82,8 +82,8 @@ into normal operation. Two ready-to-edit templates live at the repo root: `iris-irix53.toml` for 5.3, `iris-irix65.toml` for 6.5.22. Launch with `--config --ci --ci-display`. -> ⚠️ **`headless = false` is mandatory for the install — both -> versions.** With `headless = true`, iris doesn't map REX3 and +> ⚠️ **The install needs a Newport — both versions.** With +> a `none` entry at `graphics` (once, `headless = true`), iris doesn't map REX3 and > miniroot's hinv records `GFXBOARD=SERVER`. Inst then applies its > `RGFXBOARD!=SERVER` tag filters and strips every Newport-specific > file — `Xsgi`, `gfxinit`, `/hw/gfx` autoconfig, board-specific diff --git a/cpu-tests/run/bare.toml b/cpu-tests/run/bare.toml index 891d99997..a1dd24226 100644 --- a/cpu-tests/run/bare.toml +++ b/cpu-tests/run/bare.toml @@ -8,12 +8,15 @@ # well under 8 MB, so this is far more than it needs. banks = [128, 128, 0, 0] -headless = true no_audio = true [machine] profile = "indy_ip24" +[[devices]] +type = "none" +at = "graphics" + # No SCSI at all. The `scsi` key must be present-but-empty: when it is # missing entirely, serde falls back to default_scsi(), which attaches # scsi1.raw and cdrom4.iso and makes startup fatal if they are absent. diff --git a/cpu-tests/run/boot.toml b/cpu-tests/run/boot.toml index fea7a2f33..3e129c45e 100644 --- a/cpu-tests/run/boot.toml +++ b/cpu-tests/run/boot.toml @@ -5,12 +5,15 @@ # reads naturally. banks = [128, 128, 0, 0] -headless = true no_audio = true [machine] profile = "indy_ip24" +[[devices]] +type = "none" +at = "graphics" + [scsi] [scsi.2] diff --git a/cpu-tests/run/run-local.sh b/cpu-tests/run/run-local.sh index 04f0d7ec4..174356c76 100755 --- a/cpu-tests/run/run-local.sh +++ b/cpu-tests/run/run-local.sh @@ -23,14 +23,14 @@ DUMP="${DUMP:-build/dump.json}" mkdir -p "$(dirname "$LOG")" rm -f "$LOG" "$DUMP" -# --headless: no window. --noaudio: no cpal device in CI. +# --noaudio: no cpal device in CI. The bare machine has no graphics board, so no window. # --test-device: PUTC/DUMP/EXIT, and the exit code we propagate. # --config run/bare.toml: a bare-metal binary touches no disk, and bare.toml's # present-but-empty [scsi] keeps SCSI out. Without it the default config # attaches scsi1.raw and startup is fatal when that file is absent, which is # always — nothing in this suite creates one. # -# The log is a tee of stdout, not --serial-log: headless IRIS already writes +# The log is a tee of stdout, not --serial-log: IRIS already writes # the guest's console to its own stdout, and --serial-log tees the channel-B # *backend*, which in non-CI mode is the TCP listener nothing is attached to — # so it produced an empty file and the diagnostics below had nothing to show. @@ -39,7 +39,7 @@ timeout "$TIMEOUT" "$IRIS" \ --config run/bare.toml \ --load-elf "$ELF" \ --test-device --test-device-dump "$DUMP" \ - --headless --noaudio \ + --noaudio \ "$@" 2>&1 | tee "$LOG" rc=${PIPESTATUS[0]} diff --git a/cpu-tests/run/run-prom.sh b/cpu-tests/run/run-prom.sh index 650f5e874..265a5f204 100755 --- a/cpu-tests/run/run-prom.sh +++ b/cpu-tests/run/run-prom.sh @@ -30,7 +30,7 @@ LOG="build/prom.log" rm -f "$SOCK" "$LOG" "$IRIS" --config run/boot.toml --ci --ci-socket "$SOCK" \ - --test-device --headless --noaudio --serial-log "$LOG" \ + --test-device --noaudio --serial-log "$LOG" \ > build/prom-stdout.log 2>&1 & IRIS_PID=$! trap 'kill $IRIS_PID 2>/dev/null' EXIT diff --git a/docs/octane-ip30.md b/docs/octane-ip30.md index cbca0e613..56e75a9bb 100644 --- a/docs/octane-ip30.md +++ b/docs/octane-ip30.md @@ -37,7 +37,7 @@ only it has. (`[machine] flash` is the older spelling, still read.) # prom = "IP30prom.bin" # optional: overrides the built-in 4.17 PROM nvram = "nvram.bin" # the DS1685 clock's NVRAM: the PROM's settings banks = [128] # MB in each HEART bank -headless = true # no window; console=d in the NVRAM for a serial console +headless = true # no window, no keyboard serial_log = "serial.log" nat_subnet = "192.0.2.0/24" @@ -48,6 +48,9 @@ flash = "flash-ip30.bin" # keep the PROM's flash records between runs # The graphics board is a device entry: type = "impact" (default model "solid"; "high", "max"), # type = "vpro" (model "v6", "v8", "v10" or "v12"), or type = "none" at = "graphics". +[[devices]] # headless: no board +type = "none" +at = "graphics" [[port_forward]] proto = "tcp" @@ -149,9 +152,14 @@ The console is IOC3's first serial port, `serial1`, on TCP 127.0.0.1 (8880 unless a `serial` device says otherwise), and `serial_log` copies what it sends to a file, adding to an existing log unless `serial_log_overwrite` is set; the second port is `serial2`. The PROM's `console` variable picks between the -serial and graphics consoles; `headless` only removes the window. - -A PS/2 keyboard and mouse are always plugged into IOC3's two PS/2 ports; +serial and graphics consoles; `headless` removes the window and unplugs the +keyboard. With no keyboard the Octane PROM sends its console to serial itself. +A power-on with blank NVRAM stops at "Diagnostics failed. [Press any key to +continue.]" until one key arrives on `serial1`. Whether real hardware stops there +too is unknown. + +A PS/2 keyboard and mouse are plugged into IOC3's two PS/2 ports (the keyboard +is left out under `headless`); the iris window (or iris-gui) and the monitor's `ps2` commands type and move them. The PROM and IRIX run the keyboard in scan code set 3. How the controller works and what each driver does with it is in diff --git a/iris-gui/core/src/controller/app.rs b/iris-gui/core/src/controller/app.rs index 6766439f4..a90704f80 100644 --- a/iris-gui/core/src/controller/app.rs +++ b/iris-gui/core/src/controller/app.rs @@ -1608,7 +1608,7 @@ mod tests { let mut cfg = MachineConfig::default(); cfg.banks = iris::config::banks_from4([8, 8, 0, 0]); crate::model::hardware::clear_disks(&mut cfg); - cfg.headless = true; + cfg.set_graphics(None); cfg.monitor_port = Some(0); prefs.save_machine("indy", &mut cfg).unwrap(); prefs.active_machine = Some("indy".into()); diff --git a/iris-gui/core/src/controller/overview.rs b/iris-gui/core/src/controller/overview.rs index 6582caaee..e232ba943 100644 --- a/iris-gui/core/src/controller/overview.rs +++ b/iris-gui/core/src/controller/overview.rs @@ -85,9 +85,7 @@ impl AppController { HardwareRow { icon: Icon::DisplayScale, label: t!("ov-graphics"), - value: if cfg.headless { - t!("ov-headless") - } else if cfg.machine.profile == iris::config::MachineProfile::O2Ip32 { + value: if cfg.machine.profile == iris::config::MachineProfile::O2Ip32 { // The O2's display is built in; the board key does not apply. t!("extra-gbe") } else { diff --git a/iris-gui/core/src/controller/serial.rs b/iris-gui/core/src/controller/serial.rs index 264f98d29..5852ac7f0 100644 --- a/iris-gui/core/src/controller/serial.rs +++ b/iris-gui/core/src/controller/serial.rs @@ -98,10 +98,28 @@ impl SerialConsoleController { } } - /// A new machine started: an open console reconnects to its listener. + /// A new machine started: an open console reconnects to its listener. A headless machine has + /// no keyboard and no display, so its console opens. pub(crate) fn reconnect(&mut self, cfg: &iris::config::MachineConfig, notify: Arc) { - if self.console.is_some() { + if self.console.is_some() || cfg.headless { self.console = console_port(cfg).map(|port| SerialConsole::connect(port, notify)); } } } + +#[cfg(test)] +mod tests { + use super::*; + use crate::model::job::NoWake; + + #[test] + fn a_headless_machine_opens_the_serial_console_when_it_starts() { + let mut cfg = iris::config::MachineConfig::default(); + let mut console = SerialConsoleController::default(); + console.reconnect(&cfg, Arc::new(NoWake)); + assert!(!console.is_open()); + cfg.headless = true; + console.reconnect(&cfg, Arc::new(NoWake)); + assert!(console.is_open()); + } +} diff --git a/iris-gui/core/src/controller/settings.rs b/iris-gui/core/src/controller/settings.rs index 0245b9c87..7f016bb60 100644 --- a/iris-gui/core/src/controller/settings.rs +++ b/iris-gui/core/src/controller/settings.rs @@ -605,7 +605,7 @@ impl SettingsController { enabled: if boards.len() < 2 { Enabled::No(t!("settings-one-board")) } else { at_power_on() }, }); } - let newport = hardware::mc_machine(p) && board == Some(GraphicsBoard::Newport) && !cfg.headless; + let newport = hardware::mc_machine(p) && board == Some(GraphicsBoard::Newport); if newport { f.push(Field { id: field::RESOLUTION, diff --git a/iris-gui/core/src/model/machines.rs b/iris-gui/core/src/model/machines.rs index 4ab687b0d..7019d308a 100644 --- a/iris-gui/core/src/model/machines.rs +++ b/iris-gui/core/src/model/machines.rs @@ -167,7 +167,7 @@ pub fn visit_paths(cfg: &mut MachineConfig, mut visit: impl FnMut(&mut String)) a.backend = format!("file:{path}"); } } - DeviceModel::Net(_) | DeviceModel::Camera(_) | DeviceModel::XioBoard(_) | DeviceModel::PciBridge | DeviceModel::Ice1724 | DeviceModel::Qla2200 | DeviceModel::Ultra64 | DeviceModel::Empty => {} + DeviceModel::Net(_) | DeviceModel::Camera(_) | DeviceModel::XioBoard(_) | DeviceModel::PciBridge | DeviceModel::Ice1724 | DeviceModel::Qla2200 | DeviceModel::Ultra64 | DeviceModel::Empty | DeviceModel::Keyboard => {} } } if let Some(nfs) = &mut cfg.nfs { diff --git a/iris-gui/locales/en/overview.ftl b/iris-gui/locales/en/overview.ftl index b10d61c38..3a3db37c1 100644 --- a/iris-gui/locales/en/overview.ftl +++ b/iris-gui/locales/en/overview.ftl @@ -4,7 +4,6 @@ ov-spec = { $model } ({ $board }) ov-processor = Processor ov-memory = Memory ov-graphics = Graphics -ov-headless = None (serial console) ov-prom = PROM ov-prom-builtin = Built-in PROM ov-scsi = SCSI { $id } diff --git a/iris-gui/src/config_ui.rs b/iris-gui/src/config_ui.rs index 954e9a937..c662ac26b 100644 --- a/iris-gui/src/config_ui.rs +++ b/iris-gui/src/config_ui.rs @@ -634,7 +634,7 @@ fn show_octane_graphics_picker(ui: &mut Ui, cfg: &mut MachineConfig, running: bo fn show_resolution_picker(ui: &mut Ui, cfg: &mut MachineConfig, running: bool) { let board = cfg.graphics_entry().filter(|b| b.model == GraphicsBoard::Newport); - let newport = crate::extra_ui::mc_machine(cfg.machine.profile) && board.is_some() && !cfg.headless; + let newport = crate::extra_ui::mc_machine(cfg.machine.profile) && board.is_some(); ui.horizontal(|ui| { let label = ui.label(t!("config-resolution")); if !newport { diff --git a/iris-gui/src/main.rs b/iris-gui/src/main.rs index cf4fb64da..144129696 100644 --- a/iris-gui/src/main.rs +++ b/iris-gui/src/main.rs @@ -2880,7 +2880,7 @@ mod machine_storage_integration { let mut cfg = iris::config::MachineConfig::default(); cfg.banks = iris::config::banks_from4([8, 8, 0, 0]); cfg.devices.clear(); - cfg.headless = true; + cfg.set_graphics(None); cfg.monitor_port = Some(0); cfg.ci_socket = "control.sock".into(); prefs.save_machine("alpha", &mut cfg).unwrap(); diff --git a/iris.toml b/iris.toml index 0c52db459..86eb73b00 100644 --- a/iris.toml +++ b/iris.toml @@ -2,8 +2,9 @@ # All paths are relative to the directory you run iris from. # Command-line flags override any value set here. -# Run without a window. On the Indy and Indigo2 this leaves out Newport (REX3); -# other graphics boards stay fitted, and the O2 boots on its serial console. +# Run without a window and with the keyboard unplugged, so a PROM that finds none +# uses its serial console. Every graphics board stays fitted; to leave graphics +# out, place a `none` device at `graphics` (HELP.md shows how). # Independent of audio. Can also be set with the --headless command-line flag. headless = false diff --git a/src/bench_runner.rs b/src/bench_runner.rs index ab4736d49..cb6790dba 100644 --- a/src/bench_runner.rs +++ b/src/bench_runner.rs @@ -331,7 +331,6 @@ pub const BENCH_CPUS: &[&Part] = &[ pub fn bench_config(banks: [u32; 4], cpu: &Part) -> MachineConfig { let mut cfg = MachineConfig { banks: crate::config::banks_from4(banks), - headless: true, no_audio: true, ..Default::default() }; @@ -339,6 +338,7 @@ pub fn bench_config(banks: [u32; 4], cpu: &Part) -> MachineConfig { // when the file is absent — and here it always is. Same reason // bench/run/bare.toml carries a present-but-empty `[scsi]`. cfg.devices.clear(); + cfg.set_graphics(None); cfg.set_cpu(cpu); cfg } @@ -564,8 +564,8 @@ mod tests { #[test] fn the_bench_machine_has_no_disks() { let cfg = bench_config(BENCH_BANKS, &parts::R4400_150); - assert!(cfg.devices.is_empty(), "a bench machine must not try to open a disk image"); - assert!(cfg.headless && cfg.no_audio); + assert!(cfg.disks().is_empty(), "a bench machine must not try to open a disk image"); + assert!(cfg.no_audio && cfg.graphics_board().is_none()); } #[test] diff --git a/src/bin/iris_bench.rs b/src/bin/iris_bench.rs index 95180d497..6ad3f0098 100644 --- a/src/bin/iris_bench.rs +++ b/src/bin/iris_bench.rs @@ -118,7 +118,6 @@ fn run_guest( .arg("--config").arg(&config) .arg("--load-elf").arg(&elf) .arg("--test-device") - .arg("--headless") .arg("--noaudio"); for e in extra { cmd.arg(e); } diff --git a/src/chime_tests.rs b/src/chime_tests.rs index 1ab83b207..9b10982e8 100644 --- a/src/chime_tests.rs +++ b/src/chime_tests.rs @@ -102,7 +102,11 @@ fn indy_hal2_chime() { #[test] fn o2_mace_chime() { - let (rate, frames) = boot(MachineProfile::O2Ip32, "r5000", 34000, |_| {}); + let (rate, frames) = boot(MachineProfile::O2Ip32, "r5000", 34000, |c| { + c.headless = true; + // The O2's display is built in; its graphics slot takes no `none`. + c.devices.retain(|d| !matches!(d.device, crate::devices::DeviceModel::Empty)); + }); check(rate, 34000, &frames, "9:100 9:104 9:101 9:60 10:104 10:62 9:62 9:62 8:62 8:62 7:62 7:62 6:62 6:62 6:62 6:62 5:62 5:63"); } diff --git a/src/ci.rs b/src/ci.rs index 01a0bf1b7..5eb15089c 100644 --- a/src/ci.rs +++ b/src/ci.rs @@ -66,7 +66,7 @@ pub struct CiServer { /// machine is dropped, so a CI command can never reach a freed machine. machine: MachineSlot, ci_serial: Arc, - /// Optional in case --headless is also passed (no REX3). Screenshot + /// Optional in case the machine has no graphics board. Screenshot /// commands return an error in that case. displays: Vec>, /// In-flight command connections; bounded so long waits cannot exhaust @@ -649,7 +649,7 @@ fn cmd_serial_read(server: &CiServer) -> Response { fn cmd_screenshot(server: &CiServer, args: &Value) -> Response { let head = args.get("head").and_then(|v| v.as_u64()).unwrap_or(0); let Some(display) = server.displays.get(head as usize) else { - return Response::err(format!("screenshot: display head {head} not present (headless, or the machine has fewer heads)")); + return Response::err(format!("screenshot: display head {head} not present (no graphics board, or the machine has fewer heads)")); }; let Some(path) = args.get("path").and_then(|v| v.as_str()) else { return Response::err("screenshot: missing 'path' arg"); diff --git a/src/config.rs b/src/config.rs index be4454173..612fd209f 100644 --- a/src/config.rs +++ b/src/config.rs @@ -1515,7 +1515,7 @@ impl MachineSection { /// What only an O2 has (`[o2]` section). The rest of an O2 is the shared /// keys: `prom` (an override of its built-in PROM image), `nvram` (the PROM's flash, /// which holds its environment), `banks` (the kit in each DIMM pair), -/// `serial_log`, `headless` (a serial +/// `serial_log`, `headless` (no keyboard, so a serial /// console instead of the graphics console), `[clock] fixed_mhz` (CP0 Count, /// half the CPU clock), `[network]`, `[[port_forward]]` and `[scsi.N]`. The /// deprecated keys below are the old O2-only spellings of those: @@ -2420,9 +2420,10 @@ pub struct MachineConfig { #[serde(default = "default_scale")] pub scale: u32, - /// Suppress the standalone window. Newport is not fitted in this mode; - /// O2 selects a serial console. Other graphics boards can remain fitted. - /// Use `no_audio` independently to suppress host audio output. + /// Suppress the standalone window and unplug the keyboard, so a PROM that + /// finds none uses its serial console. Every graphics board stays fitted; + /// leave graphics out with a `none` entry at `graphics`. Use `no_audio` + /// independently to suppress host audio output. #[serde(default)] pub headless: bool, @@ -4195,7 +4196,7 @@ pub struct Cli { /// CI mode: enable the control socket and apply speed-favoring fidelity /// shortcuts. Hides the window unless --ci-display is set; offscreen - /// graphics remain active unless --headless is explicitly set. + /// graphics remain active. #[arg(long, default_value_t = false)] pub ci: bool, @@ -4307,8 +4308,8 @@ impl Cli { if self.serial_log_overwrite { cfg.serial_log_overwrite = true; } if let Some(mode) = self.serial_log_timestamps { cfg.serial_log_timestamps = mode; } if let Some(mhz) = self.clock_fixed_mhz { cfg.clock.fixed_mhz = Some(mhz); } - // NB: --ci does NOT imply --headless. REX3 stays alive so screenshots - // work; main.rs simply skips the host window when ci && !ci_display. + // NB: --ci does NOT imply --headless: the keyboard stays plugged in, and + // main.rs simply skips the host window when ci && !ci_display. // NFS: --nfs-dir enables the in-core NFS export. if let Some(dir) = &self.nfs_dir { diff --git a/src/config/legacy.rs b/src/config/legacy.rs index 5bad0ba50..9263dc473 100644 --- a/src/config/legacy.rs +++ b/src/config/legacy.rs @@ -743,6 +743,9 @@ mod tests { assert_eq!(cfg.validate().unwrap_err(), e); let mut cfg = MachineConfig::from_toml_str("test_device = true\n[graphics]\nheads = 2\n").unwrap(); assert!(cfg.resolve_slots().unwrap_err().contains("gio0 is taken by the newport")); + // `headless` leaves the second head where it is. + let mut cfg = MachineConfig::from_toml_str("test_device = true\nheadless = true\n[graphics]\nheads = 2\n").unwrap(); + assert!(cfg.resolve_slots().unwrap_err().contains("gio0 is taken by the newport")); } fn boards(cfg: &MachineConfig) -> Vec<(String, GraphicsBoard, u8, bool)> { diff --git a/src/dev/ioc3/tests.rs b/src/dev/ioc3/tests.rs index 17ed932f0..de97a6191 100644 --- a/src/dev/ioc3/tests.rs +++ b/src/dev/ioc3/tests.rs @@ -698,6 +698,21 @@ fn the_ps2_keyboard_round_trips() { assert_eq!(v & (1 << 27), 0, "from the keyboard"); } +#[test] +fn an_unplugged_ps2_keyboard_reads_with_no_valid_bits_and_answers_nothing() { + let r = Rig::new(); + r.c.ps2().unplug_keyboard(); + r.w32(CTRL, 0x00c0_0000); + for cmd in [0xf2, 0xff, 0xf4] { + r.w32(K_TX, cmd); + assert_eq!(r.r32(CTRL) & 3, 0, "the transmit is not left pending"); + assert_eq!(r.r32(K_RX) & (VALID[0] | VALID[1] | VALID[2]), 0, "{cmd:#x}"); + } + assert_eq!(r.r32(reg::INT_STATUS) & int::KEYBOARD, 0); + r.w32(M_TX, 0xf2); + assert_ne!(r.r32(M_RX) & VALID[2], 0, "the mouse still answers"); +} + #[test] fn the_ps2_mouse_round_trips() { let r = Rig::new(); diff --git a/src/dev/ng1/rex3_lifecycle_tests.rs b/src/dev/ng1/rex3_lifecycle_tests.rs index 5e9d8470b..8ef7a07fe 100644 --- a/src/dev/ng1/rex3_lifecycle_tests.rs +++ b/src/dev/ng1/rex3_lifecycle_tests.rs @@ -358,7 +358,6 @@ fn resident_lifecycle_machine_head1_checkpoint_round_trip() { .is_some_and(|name| name.starts_with("iris-resident-m7-head1-"))); on_large_stack(|| { let mut cfg = crate::bench_runner::bench_config([16, 0, 0, 0], &crate::cpu::parts::R4400_150); - cfg.headless = false; cfg.set_graphics(Some(crate::devices::BoardConfig { resolution: crate::dev::ng1::vc2_timings::NewportResolution::Res1024x768, ..Default::default() })); cfg.set_dual_head(true); cfg.nvram.clear(); diff --git a/src/dev/ng1/rex3_tests.rs b/src/dev/ng1/rex3_tests.rs index d71e02cad..e8e5ea055 100644 --- a/src/dev/ng1/rex3_tests.rs +++ b/src/dev/ng1/rex3_tests.rs @@ -451,7 +451,7 @@ mod resident_gate_tests { fn resident_board_loss_reaches_machine_with_the_event_queue_full() { with_big_stack(|| { let mut cfg = crate::bench_runner::bench_config([16, 0, 0, 0], &crate::cpu::parts::R4400_150); - cfg.headless = false; + cfg.set_graphics(Some(Default::default())); // This test must not load or overwrite a user's battery-backed state. cfg.nvram.clear(); cfg.nveeprom.clear(); diff --git a/src/dev/ohci/hid.rs b/src/dev/ohci/hid.rs index 3510b219f..06e1cfab4 100644 --- a/src/dev/ohci/hid.rs +++ b/src/dev/ohci/hid.rs @@ -595,17 +595,24 @@ fn usage_of(key: KeyCode) -> Option { /// The host's keyboard and mouse as the two USB functions. pub struct UsbHidInput { - keyboard: Arc, + keyboard: Option>, mouse: Arc, } impl UsbHidInput { pub fn new(keyboard: Arc, mouse: Arc) -> Arc { - Arc::new(Self { keyboard, mouse }) + Arc::new(Self { keyboard: Some(keyboard), mouse }) + } + + /// A machine whose keyboard is unplugged: the host's keys go nowhere. + pub fn without_keyboard(mouse: Arc) -> Arc { + Arc::new(Self { keyboard: None, mouse }) } } impl InputSink for UsbHidInput { fn key(&self, key: KeyCode, pressed: bool) { - self.keyboard.key(key, pressed); + if let Some(keyboard) = &self.keyboard { + keyboard.key(key, pressed); + } } fn mouse(&self, buttons: u8, dx: i32, dy: i32, _wheel: i32) { self.mouse.pointer(buttons, dx, dy); diff --git a/src/dev/ohci/hid_tests.rs b/src/dev/ohci/hid_tests.rs index 14a803ac1..8bea62985 100644 --- a/src/dev/ohci/hid_tests.rs +++ b/src/dev/ohci/hid_tests.rs @@ -335,6 +335,19 @@ fn mouse_motion_and_buttons_become_boot_mouse_reports() { assert_eq!(bus.poll(6), None); } +/// With the keyboard unplugged the sink drops the host's keys and the mouse still works. +#[test] +fn a_sink_without_a_keyboard_drops_keys_and_keeps_the_mouse() { + let bus = Bus::new(); + let mouse = HidFunction::mouse(); + bus.plug(0, mouse.clone()); + let sink = UsbHidInput::without_keyboard(mouse); + bus.enumerate(6); + sink.key(KeyCode::KeyA, true); + sink.mouse(1, 5, -3, 0); + assert_eq!(bus.poll(6).unwrap(), [1, 5, 0xfd]); +} + /// A host that does not poll gets the moves summed, not dropped. #[test] fn a_slow_host_gets_mouse_moves_folded_together() { diff --git a/src/dev/ps2.rs b/src/dev/ps2.rs index a98007e5e..777a3bfab 100644 --- a/src/dev/ps2.rs +++ b/src/dev/ps2.rs @@ -78,6 +78,9 @@ pub struct Ps2Controller { /// Host keyboard shape (`KeyboardLayout as u8`). Host config, not guest /// state, so it is not in snapshots. layout: AtomicU8, + /// Whether a keyboard is plugged in. Host config, not guest state, so it + /// is not in snapshots. + keyboard: AtomicBool, /// Whether an 8042 sits between the keyboard and the guest, so that /// command-byte bit 6 translates the keyboard's codes to set 1. Hosts /// that reach each device on its own port ([`Self::write_to`]) have no @@ -150,6 +153,7 @@ impl Ps2Controller { irq, running: AtomicBool::new(false), layout: AtomicU8::new(KeyboardLayout::Ansi as u8), + keyboard: AtomicBool::new(true), has_8042, } } @@ -183,6 +187,15 @@ impl Ps2Controller { assert!(self.sink.set(sink).is_ok(), "input redirected twice"); } + /// Unplug the keyboard: its commands go unanswered and the host's keys go nowhere. The mouse stays. + pub fn unplug_keyboard(&self) { + self.keyboard.store(false, Ordering::Relaxed); + } + + pub fn has_keyboard(&self) -> bool { + self.keyboard.load(Ordering::Relaxed) + } + /// Set the host keyboard's physical shape; see [`KeyboardLayout`]. pub fn set_layout(&self, layout: KeyboardLayout) { self.layout.store(layout as u8, Ordering::Relaxed); @@ -331,6 +344,9 @@ impl Ps2Controller { } } } + } else if !self.has_keyboard() && !matches!(state.command_state, CommandState::WriteConfig | CommandState::MouseData) { + // Nothing answers a keyboard command with no keyboard to hear it. + return; } else { // Set-3 per-key mode commands accept scan codes until the next // command. IRIX exempts Caps Lock and Num Lock from typematic. @@ -490,7 +506,9 @@ impl Ps2Controller { dlog!(LogModule::Ps2, "PS2: Command Self-Test (AA)"); } state.rx_queue.push_back((0x55, Ps2Source::Keyboard)); // controller self-test pass - state.rx_queue.push_back((0xAA, Ps2Source::Keyboard)); // keyboard BAT success + if self.has_keyboard() { + state.rx_queue.push_back((0xAA, Ps2Source::Keyboard)); // keyboard BAT success + } state.next_write_is_mouse = false; } 0x20 => { @@ -628,6 +646,7 @@ impl Ps2Controller { /// Push a scancode byte to the keyboard queue (called from UI) pub fn push_kb(&self, key: KeyCode, pressed: bool) { + if !self.has_keyboard() { return; } if let Some(sink) = self.sink.get() { return sink.key(key, pressed); } @@ -1453,6 +1472,25 @@ mod tests { assert_eq!(p.mouse_pending(), 7); } + /// With the keyboard unplugged its commands get no answer and the host's + /// keys go nowhere, while the mouse still answers. + #[test] + fn an_unplugged_keyboard_is_silent_and_the_mouse_is_not() { + let p = Ps2Controller::new(None); + p.start(); + p.write_to(0xF4, false); + assert_eq!(p.pop_from(false), Some(0xFA), "a plugged keyboard acknowledges"); + p.unplug_keyboard(); + p.write_to(0xFF, false); + p.push_kb(KeyCode::KeyA, true); + assert_eq!(p.pop_from(false), None); + p.write_command(0xAA); + assert_eq!(p.pop_from(false), Some(0x55), "the controller's self-test passes"); + assert_eq!(p.pop_from(false), None, "no keyboard reports its BAT"); + p.write_to(0xFF, true); + assert_eq!(p.pop_from(true), Some(0xFA)); + } + /// `type_char` sends what the keys themselves would: Shift around a /// shifted character, Enter for a newline, and nothing for a character /// with no key. diff --git a/src/devices.rs b/src/devices.rs index 215ac5b23..57ceef78c 100644 --- a/src/devices.rs +++ b/src/devices.rs @@ -39,6 +39,8 @@ pub enum DeviceModel { Board(BoardConfig), /// `none`: the slot stays empty, with no default. Empty, + /// The keyboard a machine has, in its `keyboard` slot. + Keyboard, VirtioSerial(VirtioSerialConfig), Virtio9p(Virtio9pConfig), /// A device on a serial port: `hostserial`, `midi_synth` or `midi_raw`, by its kind. @@ -152,6 +154,7 @@ pub const DEVICE_TYPES: &[DeviceTypeSpec] = &[ DeviceTypeSpec { name: "vpro", family: DeviceFamily::Gfx, keys: &["model"], parse: board, slots: None }, DeviceTypeSpec { name: "kona", family: DeviceFamily::Gfx, keys: &["model", "raster_managers", "flash"], parse: board, slots: None }, DeviceTypeSpec { name: "none", family: DeviceFamily::Empty, keys: &[], parse: |_, _| Ok(DeviceModel::Empty), slots: None }, + DeviceTypeSpec { name: "keyboard", family: DeviceFamily::Keyboard, keys: &[], parse: |_, _| Ok(DeviceModel::Keyboard), slots: None }, DeviceTypeSpec { name: "virtio_serial", family: DeviceFamily::Virtio, @@ -237,6 +240,7 @@ impl DeviceModel { DeviceModel::TestDevice(_) => "test_device", DeviceModel::Board(b) => b.model.family(), DeviceModel::Empty => "none", + DeviceModel::Keyboard => "keyboard", DeviceModel::VirtioSerial(_) => "virtio_serial", DeviceModel::Virtio9p(_) => "virtio_9p", DeviceModel::Serial(d) => d.kind.name(), @@ -302,7 +306,7 @@ impl DeviceModel { DeviceModel::Net(d) => changed(d, keys), DeviceModel::Camera(d) => changed(d, keys), DeviceModel::Audio(d) => changed(d, keys), - DeviceModel::XioBoard(_) | DeviceModel::PciBridge | DeviceModel::Ice1724 | DeviceModel::Qla2200 | DeviceModel::Ultra64 | DeviceModel::Empty => toml::Table::new(), + DeviceModel::XioBoard(_) | DeviceModel::PciBridge | DeviceModel::Ice1724 | DeviceModel::Qla2200 | DeviceModel::Ultra64 | DeviceModel::Empty | DeviceModel::Keyboard => toml::Table::new(), } } } diff --git a/src/display_stop_tests.rs b/src/display_stop_tests.rs index 3b9359f48..142451238 100644 --- a/src/display_stop_tests.rs +++ b/src/display_stop_tests.rs @@ -12,7 +12,7 @@ use std::sync::{mpsc, Arc}; use std::time::{Duration, Instant}; use crate::config::{GraphicsBoard, MachineConfig, MachineProfile}; -use crate::devices::BoardConfig; +use crate::devices::{BoardConfig, DeviceModel}; use crate::dev::ng1::rex3::Renderer; use crate::test_temp::TempPath; use crate::workstation::Workstation; @@ -76,7 +76,6 @@ pub(crate) fn config(dir: &Path, profile: MachineProfile, board: Option Result<(usize, usize, Vec, bool), String> { - let d = self.display.as_ref().ok_or("no display (headless)")?; + let d = self.display.as_ref().ok_or("no display (no graphics board)")?; let fresh = crate::gfx_display::wait_fresh_frame(&**d, Duration::from_millis(250)); let mut px = Vec::new(); let (w, h, _) = crate::gfx_display::copy_frame(&**d, &mut px).ok_or("the display has no video mode yet")?; diff --git a/src/ip32_machine.rs b/src/ip32_machine.rs index 04fa261e3..aa4486ca9 100644 --- a/src/ip32_machine.rs +++ b/src/ip32_machine.rs @@ -183,9 +183,9 @@ impl O2Machine { let kits = cfg.o2_kits(); let mem = O2Memory::from_kits(&kits)?; // The PROM's flash, and so its environment, lives in `nvram`. - // The net entry's `mac` is the address in the 1-Wire ID chip. `headless`: - // no keyboard, so the PROM and the OS take the serial console, as on - // an O2 booted without one. The GBE stays: it is part of every O2. + // The net entry's `mac` is the address in the 1-Wire ID chip. With no keyboard + // placed the PROM and the OS take the serial console, as on an O2 + // booted without one. The GBE stays: it is part of every O2. let mac = cfg.net_end().mac.as_deref().map(crate::config::parse_mac).transpose()?; // The SCSI devices: scsi0 is the internal bus, scsi1 the external // one. The buses are filled before the controllers exist. @@ -195,7 +195,7 @@ impl O2Machine { let opts = Ip32Options { scsi: Some(scsi), flash_file: Some(cfg.nvram.clone().into()), - keyboard: (!cfg.headless).then_some(o2.mouse), + keyboard: resolved.keyboard().is_some().then_some(o2.mouse), mac, // Beside the flash, as the clock reference is beside its image. rtc_file: Some(format!("{}.rtc", cfg.nvram).into()), @@ -222,7 +222,7 @@ impl O2Machine { "iris: O2 with {} MB ({}), {}", kits.iter().sum::(), kits.iter().map(|k| format!("{k}")).collect::>().join("+"), - if cfg.headless { "serial console" } else { "graphics console" } + if resolved.keyboard().is_some() { "graphics console" } else { "serial console" } ); // The first UART is the console unless `machine.console` names the second. let ci_serial = cfg.ci.then(|| Arc::new(crate::dev::serial_host::CiSerialBackend::new())); @@ -614,7 +614,11 @@ impl O2Machine { match self.bus.mace.ps2.devices() { Some(d) => d.clone(), // Serial console: a keyboard nothing reads. - None => Arc::new(crate::dev::ps2::Ps2Controller::new(None)), + None => { + let ps2 = crate::dev::ps2::Ps2Controller::new(None); + ps2.unplug_keyboard(); + Arc::new(ps2) + } } } diff --git a/src/ip34_machine.rs b/src/ip34_machine.rs index 0a1c34e7b..d0bef2ca9 100644 --- a/src/ip34_machine.rs +++ b/src/ip34_machine.rs @@ -143,7 +143,8 @@ fn build_baseio( scsi.set_heartbeat(heartbeat.clone()); ioc3.set_heartbeat(heartbeat); pci.attach(DevFn { device: SCSI_DEVICE, function: 0 }, scsi.clone()); - let usb = attach_usb(pci, &ioc3, timers, cfg.fuel.usb_input)?; + let mut resolved = crate::topology::DevicePlacement::new(cfg)?; + let usb = attach_usb(pci, &ioc3, timers, cfg.fuel.usb_input, resolved.keyboard().is_some())?; let (reset_ioc3, reset_scsi, reset_usb) = (ioc3.clone(), scsi.clone(), usb.clone()); let reset_vpro = vpro.as_ref().map(Arc::downgrade); xbridge.set_reset_output(Arc::new(move |port| { @@ -161,7 +162,6 @@ fn build_baseio( })); let (table, product) = (cfg.machine.profile.table_name().unwrap_or_default(), cfg.machine.profile.product_name().unwrap_or_default()); let buses = [0, 1].map(|c| scsi.bus_for_channel(c).expect("the ISP12160 has two channels")); - let mut resolved = crate::topology::DevicePlacement::new(cfg)?; for head in [HEAD_E, HEAD_F] { resolved.bind_pci(&format!("xio{head}/pci0"), xbridge.bus(head).clone())?; } diff --git a/src/ip34_machine/tests.rs b/src/ip34_machine/tests.rs index 654e6c9e4..365547d6e 100644 --- a/src/ip34_machine/tests.rs +++ b/src/ip34_machine/tests.rs @@ -113,9 +113,10 @@ fn the_fuel_plugs_a_usb_keyboard_and_mouse_only_when_configured_on() { let dir = TempPath::dir("fuel-usb"); // The OHCI controller is device 5 of head F; its root ports' status registers are at 0x54 // and 0x58 of its first BAR, and a port is powered by writing 0x100 there. - let ports = |usb_input| { + let ports = |usb_input, keyboard| { let mut cfg = fuel_config(&dir); cfg.fuel.usb_input = usb_input; + cfg.headless = !keyboard; with_machine(cfg, |m| { let win = Head::new(m.nodes[0].chip.pio(), 15).map_bar(5, 0x10, 0x0300_0000); win.write32(0x54, 0x100); @@ -127,13 +128,15 @@ fn the_fuel_plugs_a_usb_keyboard_and_mouse_only_when_configured_on() { (status, ps2.mouse_enabled()) }) }; - let (status, mouse) = ports(true); + let (status, mouse) = ports(true, true); for s in status { assert_eq!(s & 1, 1, "device connected"); assert_eq!(s & 0x200, 0x200, "low speed"); } assert!(!mouse, "the USB mouse answers for the host's pointer"); - let (status, mouse) = ports(false); + let (status, _) = ports(true, false); + assert_eq!(status.map(|s| s & 1), [0, 1], "headless leaves the keyboard's port empty and keeps the mouse"); + let (status, mouse) = ports(false, true); assert_eq!(status.map(|s| s & 1), [0, 0], "nothing plugged in"); assert!(mouse, "without the USB pair the PS/2 mouse does"); } diff --git a/src/ip35.rs b/src/ip35.rs index 1518d83ab..e5c42aa63 100644 --- a/src/ip35.rs +++ b/src/ip35.rs @@ -87,16 +87,22 @@ pub(crate) fn attach_ioc3(timers: &Arc, pci: &PciBus, board: &'sta ioc3 } -/// The OHCI controller at device 5 of head `pci`. With `input`, a USB keyboard and mouse sit on its -/// first two root ports and take the host's input instead of `ioc3`'s PS/2 pair, or a guest that -/// opened both would see every key twice. -pub(crate) fn attach_usb(pci: &PciBus, ioc3: &Ioc3, timers: &Arc, input: bool) -> Result, String> { +/// The OHCI controller at device 5 of head `pci`. With `input`, a USB keyboard (unless `keyboard` is +/// false, an empty slot) and mouse sit on its first two root ports and take the host's input instead of +/// `ioc3`'s PS/2 pair, or a guest that opened both would see every key twice. +pub(crate) fn attach_usb(pci: &PciBus, ioc3: &Ioc3, timers: &Arc, input: bool, keyboard: bool) -> Result, String> { let usb = Ohci::new(timers); if input { - let (keyboard, mouse) = (HidFunction::keyboard(), HidFunction::mouse()); - usb.attach(0, keyboard.clone())?; - usb.attach(1, mouse.clone())?; - ioc3.ps2().redirect_input(UsbHidInput::new(keyboard, mouse)); + let mouse = HidFunction::mouse(); + let sink = if keyboard { + let kb = HidFunction::keyboard(); + usb.attach(0, kb.clone())?; + UsbHidInput::new(kb, mouse.clone()) + } else { + UsbHidInput::without_keyboard(mouse.clone()) + }; + usb.attach(1, mouse)?; + ioc3.ps2().redirect_input(sink); } pci.attach(DevFn { device: 5, function: 0 }, usb.clone()); Ok(usb) diff --git a/src/ip35_machine.rs b/src/ip35_machine.rs index f2f180350..caa8a3e09 100644 --- a/src/ip35_machine.rs +++ b/src/ip35_machine.rs @@ -252,7 +252,7 @@ fn build_baseio( ioc3.set_heartbeat(heartbeat); let eth = ioc3.eth().expect("the IO7's IOC3 has Ethernet").clone(); // The I-brick's keyboard and mouse are USB, not the IOC3's PS/2 ports. - let usb = attach_usb(pci, &ioc3, timers, true)?; + let usb = attach_usb(pci, &ioc3, timers, true, resolved.keyboard().is_some())?; let (reset_ioc3, reset_usb) = (ioc3.clone(), usb.clone()); xbridge.set_reset_output(Arc::new(move |port| { if port == HEAD_F { diff --git a/src/machine.rs b/src/machine.rs index 248cc1660..f2f0dbe63 100644 --- a/src/machine.rs +++ b/src/machine.rs @@ -154,7 +154,7 @@ pub struct Machine { nvram_path: String, /// Host-forced Newport resolution from a `newport` entry's `resolution` at construction. display_resolution: [crate::dev::ng1::vc2_timings::NewportResolution; 2], - /// Whether Newport is active (not headless and Newport is selected). + /// Whether Newport is the selected graphics board. newport_active: bool, /// Indigo2 IP22 fullhouse layout (`!guinness`). fullhouse: bool, @@ -249,7 +249,7 @@ impl Machine { let head = resolved.heads().next().map(|b| b.model); let display_resolution = [board.as_ref(), resolved.heads().next()].map(|b| b.map_or_else(Default::default, |b| b.resolution)); let board = board.map(|b| b.model); - let newport_active = !cfg.headless && board == Some(GraphicsBoard::Newport); + let newport_active = board == Some(GraphicsBoard::Newport); let monitor_port = cfg.monitor_port.unwrap_or(crate::monitor::DEFAULT_PORT); let cfg_cpu_model = cfg.cpu_part().expect("validate() accepted the cpu"); @@ -438,8 +438,8 @@ impl Machine { crate::dev::ng1::rex3::ResidentDisplayMode::ReadbackCompatibility, }; - // REX3 Graphics — Newport only; skipped in headless mode or when non-Newport board selected. - let rex3: Option> = if cfg.headless || board != Some(GraphicsBoard::Newport) { + // REX3 Graphics — Newport only; skipped when another board, or none, is selected. + let rex3: Option> = if board != Some(GraphicsBoard::Newport) { None } else { let r = Rex3::new(status.clone()); @@ -460,7 +460,7 @@ impl Machine { Some(r) }; - let rex3_head1: Option> = if cfg.headless || head != Some(GraphicsBoard::Newport) { + let rex3_head1: Option> = if head != Some(GraphicsBoard::Newport) { None } else { let r = Rex3::new(status.clone()); @@ -493,8 +493,7 @@ impl Machine { Some(r) }; - // GR2 (XZ / Extreme) in the GIO gfx slot. Created even when headless: - // selecting the board is explicit, and the PROM needs it to probe. + // GR2 (XZ / Extreme) in the GIO gfx slot, when the board is selected. let gr2: Option> = match board { Some(GraphicsBoard::Xz | GraphicsBoard::Elan | GraphicsBoard::Extreme) => { use crate::dev::gr2::{Gr2, Gr2Variant}; @@ -2117,7 +2116,7 @@ mod stop_order_tests { let mut machine = big_stack(move || { let mut cfg = crate::bench_runner::bench_config([16, 0, 0, 0], &parts::R4400_150); crate::test_temp::nvram_in(&mut cfg, &nv); - cfg.headless = false; + cfg.set_graphics(Some(crate::devices::BoardConfig::default())); Box::new(Machine::new(cfg)) }); let hpc3 = machine.hpc3.clone(); @@ -2324,12 +2323,14 @@ mod gr2_checkpoint_tests { .contains("running board")); extreme.stop(); - let mut newport = Box::new(Machine::new(config(&path, GraphicsBoard::Newport))); - assert!(newport + let mut cfg = config(&path, GraphicsBoard::Xz); + cfg.set_graphics(None); + let mut bare = Box::new(Machine::new(cfg)); + assert!(bare .load_snapshot_paused("gr2-m15") .unwrap_err() .contains("machine has no GR2 board")); - newport.stop(); + bare.stop(); }); } } @@ -2654,3 +2655,29 @@ mod virtio_tests { assert_eq!(places(both).unwrap(), ["xio15/pci0/7", "xio15/pci0/5"]); } } + +#[cfg(test)] +mod headless_tests { + use super::*; + use crate::display_stop_tests::{big_stack, scratch}; + + fn build(dir: &std::path::Path, profile: MachineProfile) -> Box { + let nv = dir.to_path_buf(); + big_stack(move || { + let mut cfg = crate::bench_runner::bench_config([16, 0, 0, 0], &parts::R4400_150); + crate::test_temp::nvram_in(&mut cfg, &nv); + cfg.machine.profile = profile; + cfg.headless = true; + cfg.set_graphics(Some(crate::devices::BoardConfig::default())); + Box::new(Machine::new(cfg)) + }) + } + + #[test] + fn headless_keeps_the_newport() { + for (profile, name) in [(MachineProfile::IndyIp24, "headless-indy"), (MachineProfile::Indigo2Ip22, "headless-indigo2")] { + let dir = scratch(name); + assert!(build(&dir, profile).board.rex3.is_some(), "{profile:?}"); + } + } +} diff --git a/src/main.rs b/src/main.rs index efc0d481c..062fa99e3 100644 --- a/src/main.rs +++ b/src/main.rs @@ -178,7 +178,7 @@ fn main() { let show_window = !headless && !no_board && !(ci_enabled && !ci_display); if !show_window { if headless { - eprintln!("iris: running headless (no REX3, no window)"); + eprintln!("iris: running headless (no window)"); } else if no_board { eprintln!("iris: no graphics board attached: running on the serial console, no window"); } else if ci_enabled { diff --git a/src/slot_path.rs b/src/slot_path.rs index c82d9946a..dfc622b3a 100644 --- a/src/slot_path.rs +++ b/src/slot_path.rs @@ -26,6 +26,7 @@ const TAGS: &[(&str, bool)] = &[ ("vino", false), ("video", false), // the video input of the part above it ("audio", false), // the audio output of the part above it + ("keyboard", false), ]; const BARE: u8 = 3; @@ -171,7 +172,7 @@ mod tests { #[test] fn every_grammar_example_round_trips() { for s in [ - "hpc3/c0/t1", "hpc3/c1/t4", "gio0", "gfx", "pci0/1/t2", "pci0/3", "xio15/pci0/1/t2", "xio11", + "hpc3/c0/t1", "hpc3/c1/t4", "gio0", "gfx", "keyboard", "pci0/1/t2", "pci0/3", "xio15/pci0/1/t2", "xio11", "xio10/pci0/1/pci0/0", "node1/xio11", "xio15/pci0/1/c1/t2", "xio15/pci0/5/usb0", "xio15/pci0/1/loop3", "xio15/pci1/1", "xio15/pci0/0/f1", ] { diff --git a/src/topology.rs b/src/topology.rs index 1f2bc90bc..37db30d8e 100644 --- a/src/topology.rs +++ b/src/topology.rs @@ -33,6 +33,7 @@ pub enum DeviceFamily { /// The host output of a sound chip. Audio, Empty, + Keyboard, } impl DeviceFamily { @@ -50,6 +51,7 @@ impl DeviceFamily { DeviceFamily::Video => "cameras", DeviceFamily::Audio => "audio backends", DeviceFamily::Empty => "nothing", + DeviceFamily::Keyboard => "a keyboard", } } } @@ -305,6 +307,9 @@ impl MachineProfile { P::TezroIp53 => crate::ip53_machine::slots(&mut s), P::Origin3200Ip35 | P::Onyx3000Ip35 => crate::ip35_machine::slots(&mut s, self == P::Onyx3000Ip35), } + if !matches!(self, P::Origin200Ip29 | P::Origin2000Ip27 | P::Onyx2Ip27) { + open_slot(&mut s, "keyboard", &[DeviceFamily::Keyboard], &[]); + } // The serial ports a device can take, by the number on the case. for (n, _) in crate::dev::serial_dev::ports(self) { open_slot(&mut s, &format!("serial{n}"), &[DeviceFamily::Serial], &[]); @@ -429,6 +434,15 @@ impl DevicePlacement { devices.push(ConfiguredDevice { default: true, ..ConfiguredDevice::new(&slot.path.to_string(), DeviceModel::Board(BoardConfig::new(model))) }); } } + // A machine with a keyboard slot has a keyboard in it, unless `headless` leaves it empty or an entry places one or says `none`. + let kb = |d: &ConfiguredDevice| match &d.device { + DeviceModel::Keyboard => true, + DeviceModel::Empty => d.at.as_deref().is_some_and(|at| expand(machine, &slots, at, &mut |_| Ok(None)).is_ok_and(|p| p.to_string() == "keyboard")), + _ => false, + }; + if !cfg.headless && slots_take(&slots, DeviceFamily::Keyboard) && !devices.iter().any(kb) { + devices.push(ConfiguredDevice { default: true, ..ConfiguredDevice::new("keyboard", DeviceModel::Keyboard) }); + } // A port no entry takes keeps its default listener. for (n, tcp) in crate::dev::serial_dev::ports(cfg.machine.profile).iter().filter_map(|p| Some((p.0, p.1?))) { let line = crate::dev::serial_dev::SerialDeviceConfig { kind: crate::dev::serial_dev::SerialKind::Line, backend: vec![format!("tcp:{tcp}")], ..Default::default() }; @@ -490,6 +504,11 @@ impl DevicePlacement { self.boards(true).map(|b| b.0) } + /// Where the keyboard is plugged in, if one is. + pub fn keyboard(&self) -> Option<&MachineSlotPath> { + self.placed().find(|(d, _)| matches!(d.device, DeviceModel::Keyboard)).map(|p| p.1) + } + /// The slot with this path. pub fn slot(&self, at: &MachineSlotPath) -> Option<&MachineSlot> { self.slots.iter().find(|s| &s.path == at) @@ -751,6 +770,24 @@ mod tests { Map(cfg) } + #[test] + fn headless_leaves_the_keyboard_slot_empty_unless_an_entry_fills_it() { + for p in MachineProfile::EVERY { + let mut cfg = MachineConfig::default(); + cfg.machine.profile = p; + let at = |cfg: &MachineConfig, devices: &[ConfiguredDevice]| DevicePlacement::lenient(cfg, devices).keyboard().map(|at| at.to_string()); + // The Origin 200, Origin 2000 and Onyx2 have no keyboard to plug in. + let has = !matches!(p, MachineProfile::Origin200Ip29 | MachineProfile::Origin2000Ip27 | MachineProfile::Onyx2Ip27); + assert_eq!(at(&cfg, &[]).is_some(), has, "{p:?}"); + let unplugged = [ConfiguredDevice::new("keyboard", DeviceModel::Empty)]; + assert_eq!(at(&cfg, &unplugged), None, "{p:?}: none at keyboard"); + cfg.headless = true; + assert_eq!(at(&cfg, &[]), None, "{p:?}"); + let plugged = [ConfiguredDevice::new("keyboard", DeviceModel::Keyboard)]; + assert_eq!(at(&cfg, &plugged).is_some(), has, "{p:?}"); + } + } + impl Map { /// `devs` after `none` at the graphics slot, if open, and how many came first. fn without_board(&self, devs: &[ConfiguredDevice]) -> (Vec, usize) { diff --git a/src/tree.rs b/src/tree.rs index 2182070c3..ca8bbb1d4 100644 --- a/src/tree.rs +++ b/src/tree.rs @@ -161,6 +161,7 @@ mod tests { "|-- gio0 - takes: gio cards, virtio devices, a graphics board (newport)", "|-- vino vino built-in", "| `-- video (video) - takes: cameras", + "|-- keyboard keyboard default", "|-- serial1 serial tcp:8881 default", "`-- serial2 serial tcp:8880 default", ]); diff --git a/src/vnc/mod.rs b/src/vnc/mod.rs index b50a87a89..73b9f36ad 100644 --- a/src/vnc/mod.rs +++ b/src/vnc/mod.rs @@ -84,7 +84,7 @@ impl VncServer { input: Arc, listen: &str, max_fps: Option, name: &str, password: Option, ) -> Result { let display = input.display().cloned() - .ok_or("VNC needs a display: this machine runs without one (--headless, or no graphics board)")?; + .ok_or("VNC needs a display: this machine runs without one (no graphics board)")?; let listen = if listen.parse::().is_ok() { format!("127.0.0.1:{listen}") } else { listen.to_string() }; let listener = TcpListener::bind(&listen).map_err(|e| format!("VNC: bind {listen}: {e}"))?; let addr = listener.local_addr().map_err(|e| e.to_string())?; diff --git a/src/workstation.rs b/src/workstation.rs index 35a5f19c4..3f4094cd4 100644 --- a/src/workstation.rs +++ b/src/workstation.rs @@ -41,7 +41,11 @@ use crate::traits::{Device, MachineEvent, MachineEventQueue, MachineFatal}; /// a thread with a large one, as `main.rs` and iris-gui do. pub fn build(cfg: MachineConfig) -> Result, String> { let startup = cfg.debug.startup.clone(); + let keyboard = crate::topology::DevicePlacement::lenient(&cfg, &cfg.devices).keyboard().is_some(); let machine = build_machine(cfg)?; + if !keyboard { + machine.get_ps2().unplug_keyboard(); + } for line in &startup { eprint!("{}", machine.monitor().run_line(line).map_err(|e| format!("startup {line}: {e}"))?); } @@ -263,7 +267,7 @@ pub trait Workstation: Send { /// The display of graphics head `n`, or None when the machine has no such head. fn display(&self, n: usize) -> Option>; - /// The display of the first graphics head, or None when headless. + /// The display of the first graphics head, or None when no board is fitted. fn get_display(&self) -> Option> { self.display(0) } @@ -1162,9 +1166,10 @@ mod placement_tests { let dev = ScsiDeviceConfig { path: disk.to_string_lossy().into_owned(), overlay: true, ..Default::default() }; cfg.devices = buses.iter().map(|b| ConfiguredDevice::new(&format!("{}/t1", b.1), DeviceModel::Scsi(dev.clone()))).collect(); assert_eq!(cfg.disks().len(), buses.len(), "{p:?}"); - let built = crate::display_stop_tests::big_stack(move || super::build(cfg).map(|m| m.disk_activity().len())); - let n = built.unwrap_or_else(|e| panic!("{p:?}: {e}")); + let built = crate::display_stop_tests::big_stack(move || super::build(cfg).map(|m| (m.disk_activity().len(), m.get_ps2().has_keyboard()))); + let (n, keyboard) = built.unwrap_or_else(|e| panic!("{p:?}: {e}")); assert!(n >= buses.len(), "{p:?}: {n} disk buses for {} in the map", buses.len()); + assert!(!keyboard, "{p:?}: headless leaves the keyboard unplugged"); } } } diff --git a/tests/common/mod.rs b/tests/common/mod.rs index 4e090c414..11de77ad5 100644 --- a/tests/common/mod.rs +++ b/tests/common/mod.rs @@ -70,9 +70,10 @@ pub fn run_dir(name: &str) -> PathBuf { pub fn machine_config(suite_config: &str, dir: &Path) -> PathBuf { let base = std::fs::read_to_string(repo(suite_config)) .unwrap_or_else(|e| panic!("{}: {}", suite_config, e)); - // Top-level keys, so they go before the file's first table. + // An inline `devices = [..]` would collide with the suite file's own + // `[[devices]]` tables, so the serial entries are appended as tables too. let text = format!( - "monitor_port = 0\ndevices = [ {{ type = \"serial\", at = \"serial1\", backend = \"tcp:0\" }}, {{ type = \"serial\", at = \"serial2\", backend = \"tcp:0\" }} ]\n\n{}", + "monitor_port = 0\n\n{}\n[[devices]]\ntype = \"serial\"\nat = \"serial1\"\nbackend = \"tcp:0\"\n\n[[devices]]\ntype = \"serial\"\nat = \"serial2\"\nbackend = \"tcp:0\"\n", base ); let path = dir.join("run").join("bare.toml"); diff --git a/tests/monitor_ready.rs b/tests/monitor_ready.rs index 69a1ad9e7..3d283e366 100644 --- a/tests/monitor_ready.rs +++ b/tests/monitor_ready.rs @@ -61,7 +61,7 @@ fn write_config(dir: &Path, monitor: u16, serial_a: u16, serial_b: u16, ci_socke "headless = true\n\ no_audio = true\n\ monitor_port = {monitor}\n\ - devices = [ {{ type = \"serial\", at = \"serial1\", backend = \"tcp:{serial_a}\" }}, {{ type = \"serial\", at = \"serial2\", backend = \"tcp:{serial_b}\" }} ]\n\ + devices = [ {{ type = \"serial\", at = \"serial1\", backend = \"tcp:{serial_a}\" }}, {{ type = \"serial\", at = \"serial2\", backend = \"tcp:{serial_b}\" }}, {{ type = \"none\", at = \"graphics\" }} ]\n\ ci_socket = \"{}\"\n\ \n\ # No disk: the embedded PROM is enough for this test, and the default\n\ diff --git a/tests/snapshot_schemas.rs b/tests/snapshot_schemas.rs index b83708505..5bb3a1f8b 100644 --- a/tests/snapshot_schemas.rs +++ b/tests/snapshot_schemas.rs @@ -148,8 +148,8 @@ fn loads(fixture: &str, profile: &str, prom_bytes: usize, banks: &str, older: Op devices = [ {{ type = \"serial\", at = \"serial1\", backend = \"tcp:0\" }}, {{ type = \"serial\", at = \"serial2\", backend = \"tcp:0\" }}{} ]\n\ scsi = {{}}\n\ [machine]\nprofile = \"{profile}\"\ncache = \"{cache}\"\n", - // Only the Octane has a graphics board to leave out. - if profile == "octane_ip30" { ", { type = \"none\", at = \"graphics\" }" } else { "" } + // The O2's display is part of the machine; the others leave theirs out. + if profile != "o2_ip32" { ", { type = \"none\", at = \"graphics\" }" } else { "" } ), ) .unwrap(); diff --git a/tests/snapshots/generate.sh b/tests/snapshots/generate.sh index 0d0809bf9..9e583239a 100755 --- a/tests/snapshots/generate.sh +++ b/tests/snapshots/generate.sh @@ -24,8 +24,8 @@ head -c $prom /dev/zero > prom.bin # The old build prints the port it was asked for, not the one it bound, so # this picks one. port=$((20000 + RANDOM % 20000)) -# Only the Octane has a graphics board to leave out. -gfx=; [ "$machine" = octane ] && gfx=', { type = "none", at = "graphics" }' +# The O2's display is part of the machine; the others leave theirs out. +gfx=; [ "$machine" != o2 ] && gfx=', { type = "none", at = "graphics" }' cat > iris.toml <