Skip to content

Commit

Permalink
Update types for class_code and subclass
Browse files Browse the repository at this point in the history
  • Loading branch information
bagggage committed Oct 9, 2024
1 parent cd6f017 commit d4e77ce
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions src/kernel/dev/stds/pci.zig
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ pub const Id = struct {

vendor_id: u16 = any,
device_id: u16 = any,
class_code: u16 = any,
subclass: u16 = any
class_code: ?config.ClassCode = null,
subclass: ?config.SubclassCode = null
};

pub const Device = struct {
Expand All @@ -30,8 +30,8 @@ pub const Device = struct {
.id = .{
.vendor_id = cfg.get(.vendor_id),
.device_id = cfg.get(.device_id),
.class_code = cfg.get(.class_code),
.subclass = cfg.get(.subclass)
.class_code = @enumFromInt(cfg.get(.class_code)),
.subclass = @bitCast(cfg.get(.subclass))
},
.intr_ctrl = intr.Control.init(cfg)
};
Expand All @@ -40,6 +40,10 @@ pub const Device = struct {
pub inline fn requestInterrupt(self: *Device, min: u8, max: u8, handler: *anyopaque, comptime types: intr.Types) !u8 {
return self.intr_ctrl.request(min, max, handler, types);
}

pub inline fn from(device: *const dev.Device) *Device {
return device.driver_data.as(Device) orelse unreachable;
}
};

pub const Driver = struct {
Expand Down Expand Up @@ -70,11 +74,11 @@ fn match(driver: *const dev.Driver, device: *const dev.Device) bool {
(pci_driver.match_id.device_id == Id.any or
pci_driver.match_id.device_id == pci_dev.id.device_id)
and
(pci_driver.match_id.class_code == Id.any or
(pci_driver.match_id.class_code == null or
pci_driver.match_id.class_code == pci_dev.id.class_code)
and
(pci_driver.match_id.subclass == Id.any or
pci_driver.match_id.subclass == pci_dev.id.subclass)
(pci_driver.match_id.subclass == null or
@as(u8, @bitCast(pci_driver.match_id.subclass.?)) == @as(u8, @bitCast(pci_dev.id.subclass.?)))
);
}

Expand Down

0 comments on commit d4e77ce

Please sign in to comment.