code lint

This commit is contained in:
Daniel Samson
2026-07-12 19:36:10 +01:00
parent 1cdffe21b1
commit 78582d24d2
2 changed files with 39 additions and 39 deletions
+15 -15
View File
@@ -118,8 +118,8 @@ pub fn main() void {
maybe_controller = controller; maybe_controller = controller;
maybe_interrupt_index = findInterruptResourceIndex(controller_device_descriptor); maybe_interrupt_index = findInterruptResourceIndex(controller_device_descriptor);
controller.disablePort(.One); controller.disablePort(.one);
controller.disablePort(.Two); controller.disablePort(.two);
controller.flushOutputBuffer(); controller.flushOutputBuffer();
const current = controller.readConfigurationByte() orelse { const current = controller.readConfigurationByte() orelse {
@@ -154,20 +154,20 @@ pub fn main() void {
if (has_two_channels) { if (has_two_channels) {
_ = runtime.system.write("system/drivers/ps2-bus: has two channels\n"); _ = runtime.system.write("system/drivers/ps2-bus: has two channels\n");
// keep the bus quiet until we have tested the ports and are ready to use them // keep the bus quiet until we have tested the ports and are ready to use them
controller.disablePort(.Two); controller.disablePort(.two);
} else { } else {
_ = runtime.system.write("system/drivers/ps2-bus: has one channel\n"); _ = runtime.system.write("system/drivers/ps2-bus: has one channel\n");
} }
// interface tests: always test port 1, test port 2 only if it exists // interface tests: always test port 1, test port 2 only if it exists
const port_one_works = (controller.testPort(.One) orelse { const port_one_works = (controller.testPort(.one) orelse {
_ = runtime.system.write("system/drivers/ps2-bus: port 1 test timed out\n"); _ = runtime.system.write("system/drivers/ps2-bus: port 1 test timed out\n");
return; return;
}) == ps2.response_port_test_passed; }) == ps2.response_port_test_passed;
var port_two_works = false; var port_two_works = false;
if (has_two_channels) { if (has_two_channels) {
port_two_works = (controller.testPort(.Two) orelse { port_two_works = (controller.testPort(.two) orelse {
_ = runtime.system.write("system/drivers/ps2-bus: port 2 test timed out\n"); _ = runtime.system.write("system/drivers/ps2-bus: port 2 test timed out\n");
return; return;
}) == ps2.response_port_test_passed; }) == ps2.response_port_test_passed;
@@ -181,20 +181,20 @@ pub fn main() void {
// Enable the working ports. Their interrupts stay off until IRQ1 is bound // Enable the working ports. Their interrupts stay off until IRQ1 is bound
// below — reset and identify use polled reads, which must never race the // below — reset and identify use polled reads, which must never race the
// interrupt-driven drain loop for bytes. // interrupt-driven drain loop for bytes.
controller.enablePort(.One); controller.enablePort(.one);
if (port_two_works) controller.enablePort(.Two); if (port_two_works) controller.enablePort(.two);
// reset each working device; a failing device is logged but does not // reset each working device; a failing device is logged but does not
// abort bring-up of the other one // abort bring-up of the other one
if (port_one_works) { if (port_one_works) {
if (controller.resetDevice(.One)) |passed| { if (controller.resetDevice(.one)) |passed| {
if (!passed) _ = runtime.system.write("system/drivers/ps2-bus: port 1 device reset failed\n"); if (!passed) _ = runtime.system.write("system/drivers/ps2-bus: port 1 device reset failed\n");
} else { } else {
_ = runtime.system.write("system/drivers/ps2-bus: port 1 device reset timed out\n"); _ = runtime.system.write("system/drivers/ps2-bus: port 1 device reset timed out\n");
} }
} }
if (port_two_works) { if (port_two_works) {
if (controller.resetDevice(.Two)) |passed| { if (controller.resetDevice(.two)) |passed| {
if (!passed) _ = runtime.system.write("system/drivers/ps2-bus: port 2 device reset failed\n"); if (!passed) _ = runtime.system.write("system/drivers/ps2-bus: port 2 device reset failed\n");
} else { } else {
_ = runtime.system.write("system/drivers/ps2-bus: port 2 device reset timed out\n"); _ = runtime.system.write("system/drivers/ps2-bus: port 2 device reset timed out\n");
@@ -204,8 +204,8 @@ pub fn main() void {
// Identify the device on each working port and hand it off to the driver // Identify the device on each working port and hand it off to the driver
// that matches what it reported — a port is not assumed to be a keyboard // that matches what it reported — a port is not assumed to be a keyboard
// or a mouse by its number. // or a mouse by its number.
if (port_one_works) port_device_types[@intFromEnum(ps2.Port.One)] = spawnIdentifiedDriver(controller, .One); if (port_one_works) port_device_types[@intFromEnum(ps2.Port.one)] = spawnIdentifiedDriver(controller, .one);
if (port_two_works) port_device_types[@intFromEnum(ps2.Port.Two)] = spawnIdentifiedDriver(controller, .Two); if (port_two_works) port_device_types[@intFromEnum(ps2.Port.two)] = spawnIdentifiedDriver(controller, .two);
} else { } else {
_ = runtime.system.write("system/drivers/ps2-bus: no PS/2 controller found\n"); _ = runtime.system.write("system/drivers/ps2-bus: no PS/2 controller found\n");
return; return;
@@ -243,7 +243,7 @@ pub fn main() void {
// claim that node too and route its IRQ to the same endpoint. The IRQ belongs // claim that node too and route its IRQ to the same endpoint. The IRQ belongs
// to the *port*, whatever device identify found on it. // to the *port*, whatever device identify found on it.
var maybe_auxiliary_interrupt: ?struct { device_id: u64, interrupt_index: u64, gsi: u64 } = null; var maybe_auxiliary_interrupt: ?struct { device_id: u64, interrupt_index: u64, gsi: u64 } = null;
if (port_device_types[@intFromEnum(ps2.Port.Two)] != null) { if (port_device_types[@intFromEnum(ps2.Port.two)] != null) {
if (device.findDeviceDescriptorByHid(buffer, acpi_ids.HardwareId.ps2_mouse.hid())) |descriptor| { if (device.findDeviceDescriptorByHid(buffer, acpi_ids.HardwareId.ps2_mouse.hid())) |descriptor| {
if (findInterruptResourceIndex(descriptor)) |auxiliary_index| { if (findInterruptResourceIndex(descriptor)) |auxiliary_index| {
if (device.claim(descriptor.id) and device.irqBind(descriptor.id, auxiliary_index, endpoint)) { if (device.claim(descriptor.id) and device.irqBind(descriptor.id, auxiliary_index, endpoint)) {
@@ -263,8 +263,8 @@ pub fn main() void {
_ = runtime.system.write("system/drivers/ps2-bus: controller configuration timed out\n"); _ = runtime.system.write("system/drivers/ps2-bus: controller configuration timed out\n");
return; return;
}; };
if (port_device_types[@intFromEnum(ps2.Port.One)] != null) configuration |= ps2.Port.One.interruptBit(); if (port_device_types[@intFromEnum(ps2.Port.one)] != null) configuration |= ps2.Port.one.interruptBit();
if (maybe_auxiliary_interrupt != null) configuration |= ps2.Port.Two.interruptBit(); if (maybe_auxiliary_interrupt != null) configuration |= ps2.Port.two.interruptBit();
_ = controller.writeConfigurationByte(configuration); _ = controller.writeConfigurationByte(configuration);
_ = runtime.system.write("system/drivers/ps2-bus: ok\n"); _ = runtime.system.write("system/drivers/ps2-bus: ok\n");
@@ -284,7 +284,7 @@ pub fn main() void {
const current_status = ps2.status(controller.device_id, controller.status_index); const current_status = ps2.status(controller.device_id, controller.status_index);
if (current_status & ps2.status_output_buffer_full == 0) break; if (current_status & ps2.status_output_buffer_full == 0) break;
const byte = device.ioRead(controller.device_id, controller.data_index, 0, 1) orelse break; const byte = device.ioRead(controller.device_id, controller.data_index, 0, 1) orelse break;
const port: ps2.Port = if (current_status & ps2.status_auxiliary_output != 0) .Two else .One; const port: ps2.Port = if (current_status & ps2.status_auxiliary_output != 0) .two else .one;
if (port_endpoints[@intFromEnum(port)]) |child| { if (port_endpoints[@intFromEnum(port)]) |child| {
const forwarded = ps2.ForwardedByte{ .port = @intFromEnum(port), .byte = byte }; const forwarded = ps2.ForwardedByte{ .port = @intFromEnum(port), .byte = byte };
_ = ipc.send(child, std.mem.asBytes(&forwarded)); _ = ipc.send(child, std.mem.asBytes(&forwarded));
+24 -24
View File
@@ -153,46 +153,46 @@ pub fn writeData(id: u64, status_index: u64, data_index: u64, byte: u8, timeout_
} }
pub const Port = enum(u2) { pub const Port = enum(u2) {
One, one,
Two, two,
/// Command register byte that disables this port. /// Command register byte that disables this port.
fn disableCommand(self: Port) u8 { fn disableCommand(self: Port) u8 {
return switch (self) { return switch (self) {
.One => cmd_disable_first_port, .one => cmd_disable_first_port,
.Two => cmd_disable_second_port, .two => cmd_disable_second_port,
}; };
} }
/// Command register byte that enables this port (and its clock). /// Command register byte that enables this port (and its clock).
fn enableCommand(self: Port) u8 { fn enableCommand(self: Port) u8 {
return switch (self) { return switch (self) {
.One => cmd_enable_first_port, .one => cmd_enable_first_port,
.Two => cmd_enable_second_port, .two => cmd_enable_second_port,
}; };
} }
/// Command register byte that runs this port's interface test. /// Command register byte that runs this port's interface test.
fn testCommand(self: Port) u8 { fn testCommand(self: Port) u8 {
return switch (self) { return switch (self) {
.One => cmd_test_first_port, .one => cmd_test_first_port,
.Two => cmd_test_second_port, .two => cmd_test_second_port,
}; };
} }
/// Configuration-byte bit that, when set, disables this port's clock. /// Configuration-byte bit that, when set, disables this port's clock.
pub fn clockDisabledBit(self: Port) u8 { pub fn clockDisabledBit(self: Port) u8 {
return switch (self) { return switch (self) {
.One => configuration_first_port_clock_disabled, .one => configuration_first_port_clock_disabled,
.Two => configuration_second_port_clock_disabled, .two => configuration_second_port_clock_disabled,
}; };
} }
/// Configuration-byte bit that, when set, enables this port's interrupt. /// Configuration-byte bit that, when set, enables this port's interrupt.
pub fn interruptBit(self: Port) u8 { pub fn interruptBit(self: Port) u8 {
return switch (self) { return switch (self) {
.One => configuration_first_port_interrupt, .one => configuration_first_port_interrupt,
.Two => configuration_second_port_interrupt, .two => configuration_second_port_interrupt,
}; };
} }
@@ -200,8 +200,8 @@ pub const Port = enum(u2) {
/// output buffer (makes a byte appear as if it came from the device). /// output buffer (makes a byte appear as if it came from the device).
pub fn writeOutputBufferCommand(self: Port) u8 { pub fn writeOutputBufferCommand(self: Port) u8 {
return switch (self) { return switch (self) {
.One => cmd_write_first_port_output, .one => cmd_write_first_port_output,
.Two => cmd_write_second_port_output, .two => cmd_write_second_port_output,
}; };
} }
@@ -210,24 +210,24 @@ pub const Port = enum(u2) {
/// prefix (null); port 2 requires the "write second port input" command. /// prefix (null); port 2 requires the "write second port input" command.
pub fn deviceInputCommand(self: Port) ?u8 { pub fn deviceInputCommand(self: Port) ?u8 {
return switch (self) { return switch (self) {
.One => null, .one => null,
.Two => cmd_write_second_port_input, .two => cmd_write_second_port_input,
}; };
} }
/// Controller output-port bit driving this port's clock line. /// Controller output-port bit driving this port's clock line.
pub fn outputPortClockBit(self: Port) u8 { pub fn outputPortClockBit(self: Port) u8 {
return switch (self) { return switch (self) {
.One => output_port_first_port_clock, .one => output_port_first_port_clock,
.Two => output_port_second_port_clock, .two => output_port_second_port_clock,
}; };
} }
/// Controller output-port bit driving this port's data line. /// Controller output-port bit driving this port's data line.
pub fn outputPortDataBit(self: Port) u8 { pub fn outputPortDataBit(self: Port) u8 {
return switch (self) { return switch (self) {
.One => output_port_first_port_data, .one => output_port_first_port_data,
.Two => output_port_second_port_data, .two => output_port_second_port_data,
}; };
} }
@@ -235,8 +235,8 @@ pub const Port = enum(u2) {
/// (wired to the port's IRQ line). /// (wired to the port's IRQ line).
pub fn outputPortBufferFullBit(self: Port) u8 { pub fn outputPortBufferFullBit(self: Port) u8 {
return switch (self) { return switch (self) {
.One => output_port_first_port_output_full, .one => output_port_first_port_output_full,
.Two => output_port_second_port_output_full, .two => output_port_second_port_output_full,
}; };
} }
}; };
@@ -393,9 +393,9 @@ pub const Controller = struct {
/// enabled; the caller should disable it again to keep the bus quiet until /// enabled; the caller should disable it again to keep the bus quiet until
/// device bring-up. /// device bring-up.
pub fn hasTwoChannels(self: Controller) ?bool { pub fn hasTwoChannels(self: Controller) ?bool {
self.enablePort(.Two); self.enablePort(.two);
const configuration = self.readConfigurationByte() orelse return null; const configuration = self.readConfigurationByte() orelse return null;
return (configuration & Port.Two.clockDisabledBit()) == 0; return (configuration & Port.two.clockDisabledBit()) == 0;
} }
/// Reset the device attached to `port` (device command 0xFF) and wait for /// Reset the device attached to `port` (device command 0xFF) and wait for