Skip to content

Ps2 incremental#38

Open
domnudragota wants to merge 23 commits into
masterfrom
ps2-incremental
Open

Ps2 incremental#38
domnudragota wants to merge 23 commits into
masterfrom
ps2-incremental

Conversation

@domnudragota

@domnudragota domnudragota commented Jul 28, 2025

Copy link
Copy Markdown

Pull Request Overview

This pull request adds the i8042 controller over x86/naked_functions branch plus keyboard stubs for the future keyboard driver.

Testing Strategy

This pull request was tested by checking the ring buffer in unit tests + controller debug! macro messages during init. sequence.

TODO or Help Wanted

This pull request needs review

Formatting

  • Ran make prepush.

@domnudragota
domnudragota marked this pull request as ready for review August 1, 2025 09:14
@alexandruradovici

Copy link
Copy Markdown

Please rebase this.

@domnudragota

Copy link
Copy Markdown
Author

I completely forgot, will do

@domnudragota

Copy link
Copy Markdown
Author

After ae0670b, I added some health components to display status of the controller (rx, timeouts, overruns, parity, etc) every N bytes.

Main goal of these changes is the following: make sure the kernel doesn't crash if the controller/a device breaks down. Also the devices should be "plug & play" (I don't think I'll reach this state but is good to try atleast :) )

Comment thread boards/qemu_i486_q35/src/main.rs Outdated
Comment on lines +286 to +291
// Tiny breadcrumb: PS/2 bring-up ran in the chip already.
debug!("ps/2: controller initialized (chip ran init_early)");

// Now we can safely log via `debug!()`
debug!("ps/2 health: {}", chip.ps2.health_snapshot());

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
// Tiny breadcrumb: PS/2 bring-up ran in the chip already.
debug!("ps/2: controller initialized (chip ran init_early)");
// Now we can safely log via `debug!()`
debug!("ps/2 health: {}", chip.ps2.health_snapshot());

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 766d0f7

Comment thread chips/x86_q35/src/chip.rs Outdated
pt: &'a mut PT,

/// Holds the PS/2 controller passed in by the board
ps2: Option<&'a crate::ps2::Ps2Controller>,

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is there a reason why this is an Option?

@domnudragota domnudragota Sep 4, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Leftover from a while ago. Wanted to init. the controller similarly with new().with_ps2(...).finalize(...), and to give an expect() if someone forgets to call with_ps2. But since PS/2 is a hard requirement in PcComponent::new, I'll remove that option.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in 766d0f7

Comment thread chips/x86_q35/src/chip.rs Outdated
Comment thread chips/x86_q35/src/ps2.rs Outdated
/// Depth of the scan-code ring buffer
const BUFFER_SIZE: usize = 32;

/// Timeout limit for spin loops

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What is the measuring unit?

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It’s not time-based, it's just a count of polling iterations (how many times we spin reading 0x64 and checking bits). So the "unit" should be spins/loops.

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the code or comment to reflect that, we need to document what this means.

Comment thread chips/x86_q35/src/ps2.rs Outdated
Comment thread chips/x86_q35/src/ps2.rs Outdated
/// Depth of the scan-code ring buffer
const BUFFER_SIZE: usize = 32;

/// Timeout limit for spin loops

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please change the code or comment to reflect that, we need to document what this means.

Comment thread chips/x86_q35/src/ps2.rs Outdated

@alexandruradovici alexandruradovici left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's send it to upstream, make sure to use a better title.

Comment thread chips/x86_q35/src/ps2.rs Outdated
/// Producer-side enqueue. Safe without masking: on x86_q35, IRQs and
/// deferred calls are serialized by the main loop (no preemption).
#[inline(always)]
fn push_code_atomic(&self, b: u8) {

@alexandruradovici alexandruradovici Sep 11, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not atomic anymore.

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

fixed in f2c1262

step1: PS/2 controller self-test (clock & IRQ still disabled)

step2: enable keyboard clock (IRQ 1 still masked)

step3: full PS/2 driver – self-test, clock on, IRQ1 unmasked, single-byte buffering

step4: drain-loop IRQ handler; full ring-buffer active

step5: add send_with_ack() with RESEND retry; enable keyboard scanning (0xF4)

step7: implemented some unit tests to debug buffers

fix: readded comments from previous controller, moved ps2.init() to enable debug macro

feature: added IRQ1 self-test when init.
workflow: rebased with upstream
…for init, reworked ISR to handle drop parity/timeout => make/break logs + prefixes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants