Initial PCI interface
Closes #244 Move PCI to arch Plus spelling Added new out and in functions Added new out and in to mocking Return pci devices as a list Improved comment Removed mask for the return Removed type for OUT Added new types
This commit is contained in:
parent
dacba0ca03
commit
abc712233b
14 changed files with 677 additions and 147 deletions
|
@ -2,6 +2,7 @@ const std = @import("std");
|
|||
const Allocator = std.mem.Allocator;
|
||||
const mem = @import("mem_mock.zig");
|
||||
const MemProfile = mem.MemProfile;
|
||||
const pci = @import("pci_mock.zig");
|
||||
const gdt = @import("gdt_mock.zig");
|
||||
const idt = @import("idt_mock.zig");
|
||||
const vmm = @import("vmm_mock.zig");
|
||||
|
@ -12,6 +13,8 @@ const Keyboard = @import("../../../src/kernel/keyboard.zig").Keyboard;
|
|||
|
||||
pub const task = @import("task_mock.zig");
|
||||
|
||||
pub const Device = pci.PciDeviceInfo;
|
||||
|
||||
const mock_framework = @import("mock_framework.zig");
|
||||
pub const initTest = mock_framework.initTest;
|
||||
pub const freeTest = mock_framework.freeTest;
|
||||
|
@ -57,12 +60,12 @@ var KERNEL_VADDR_START: u32 = 0xC0100000;
|
|||
var KERNEL_VADDR_END: u32 = 0xC1100000;
|
||||
var KERNEL_ADDR_OFFSET: u32 = 0xC0000000;
|
||||
|
||||
pub fn outb(port: u16, data: u8) void {
|
||||
return mock_framework.performAction("outb", void, .{ port, data });
|
||||
pub fn out(port: u16, data: anytype) void {
|
||||
return mock_framework.performAction("out", void, .{ port, data });
|
||||
}
|
||||
|
||||
pub fn inb(port: u16) u8 {
|
||||
return mock_framework.performAction("inb", u8, .{port});
|
||||
pub fn in(comptime Type: type, port: u16) Type {
|
||||
return mock_framework.performAction("in", Type, .{port});
|
||||
}
|
||||
|
||||
pub fn ioWait() void {
|
||||
|
@ -147,6 +150,10 @@ pub fn initKeyboard(allocator: *Allocator) Allocator.Error!?*Keyboard {
|
|||
return null;
|
||||
}
|
||||
|
||||
pub fn getDevices(allocator: *Allocator) Allocator.Error![]Device {
|
||||
return &[_]Device{};
|
||||
}
|
||||
|
||||
pub fn init(mem_profile: *const MemProfile) void {
|
||||
// I'll get back to this as this doesn't effect the current testing.
|
||||
// When I come on to the mem.zig testing, I'll fix :)
|
||||
|
|
|
@ -46,9 +46,9 @@ const DataElementType = enum {
|
|||
FN_OIDTPTR,
|
||||
FN_IU8_OVOID,
|
||||
FN_IU8_OBOOL,
|
||||
FN_IU8_IFNCCNAKEDOVOID_EIDTERROR_OVOID,
|
||||
FN_IU16_OVOID,
|
||||
FN_IU16_OU8,
|
||||
FN_IU16_OU32,
|
||||
FN_IUSIZE_OBOOL,
|
||||
FN_IRTCREGISTER_OU8,
|
||||
FN_IIDTENTRY_OBOOL,
|
||||
|
@ -56,8 +56,10 @@ const DataElementType = enum {
|
|||
FN_IPTRCONSTIDTPTR_OVOID,
|
||||
FN_IU4_IU4_OU8,
|
||||
FN_IU8_IU8_OU16,
|
||||
FN_IU8_IFNCCNAKEDOVOID_EIDTERROR_OVOID,
|
||||
FN_IU16_IU8_OVOID,
|
||||
FN_IU16_IU16_OVOID,
|
||||
FN_IU16_IU32_OVOID,
|
||||
FN_ISTATUSREGISTER_IBOOL_OU8,
|
||||
FN_IPTRTASK_IUSIZE_OVOID,
|
||||
FN_IPTRTASK_IPTRALLOCATOR_OVOID,
|
||||
|
@ -98,9 +100,9 @@ const DataElement = union(DataElementType) {
|
|||
FN_OIDTPTR: fn () IdtPtr,
|
||||
FN_IU8_OVOID: fn (u8) void,
|
||||
FN_IU8_OBOOL: fn (u8) bool,
|
||||
FN_IU8_IFNCCNAKEDOVOID_EIDTERROR_OVOID: fn (u8, fn () callconv(.Naked) void) IdtError!void,
|
||||
FN_IU16_OVOID: fn (u16) void,
|
||||
FN_IU16_OU8: fn (u16) u8,
|
||||
FN_IU16_OU32: fn (u16) u32,
|
||||
FN_IUSIZE_OBOOL: fn (usize) bool,
|
||||
FN_IRTCREGISTER_OU8: fn (RtcRegister) u8,
|
||||
FN_IIDTENTRY_OBOOL: fn (IdtEntry) bool,
|
||||
|
@ -108,8 +110,10 @@ const DataElement = union(DataElementType) {
|
|||
FN_IPTRCONSTIDTPTR_OVOID: fn (*const IdtPtr) void,
|
||||
FN_IU4_IU4_OU8: fn (u4, u4) u8,
|
||||
FN_IU8_IU8_OU16: fn (u8, u8) u16,
|
||||
FN_IU8_IFNCCNAKEDOVOID_EIDTERROR_OVOID: fn (u8, fn () callconv(.Naked) void) IdtError!void,
|
||||
FN_IU16_IU8_OVOID: fn (u16, u8) void,
|
||||
FN_IU16_IU16_OVOID: fn (u16, u16) void,
|
||||
FN_IU16_IU32_OVOID: fn (u16, u32) void,
|
||||
FN_ISTATUSREGISTER_IBOOL_OU8: fn (StatusRegister, bool) u8,
|
||||
FN_IPTRTASK_IUSIZE_OVOID: fn (*Task, usize) void,
|
||||
FN_IPTRTASK_IPTRALLOCATOR_OVOID: fn (*Task, *Allocator) void,
|
||||
|
@ -214,9 +218,9 @@ fn Mock() type {
|
|||
fn () IdtPtr => DataElement{ .FN_OIDTPTR = arg },
|
||||
fn (u8) void => DataElement{ .FN_IU8_OVOID = arg },
|
||||
fn (u8) bool => DataElement{ .FN_IU8_OBOOL = arg },
|
||||
fn (u8, fn () callconv(.Naked) void) IdtError!void => DataElement{ .FN_IU8_IFNCCNAKEDOVOID_EIDTERROR_OVOID = arg },
|
||||
fn (u16) void => DataElement{ .FN_IU16_OVOID = arg },
|
||||
fn (u16) u8 => DataElement{ .FN_IU16_OU8 = arg },
|
||||
fn (u16) u32 => DataElement{ .FN_IU16_OU32 = arg },
|
||||
fn (usize) bool => DataElement{ .FN_IUSIZE_OBOOL = arg },
|
||||
fn (RtcRegister) u8 => DataElement{ .FN_IRTCREGISTER_OU8 = arg },
|
||||
fn (IdtEntry) bool => DataElement{ .FN_IIDTENTRY_OBOOL = arg },
|
||||
|
@ -224,8 +228,10 @@ fn Mock() type {
|
|||
fn (*const IdtPtr) void => DataElement{ .FN_IPTRCONSTIDTPTR_OVOID = arg },
|
||||
fn (u4, u4) u8 => DataElement{ .FN_IU4_IU4_OU8 = arg },
|
||||
fn (u8, u8) u16 => DataElement{ .FN_IU8_IU8_OU16 = arg },
|
||||
fn (u8, fn () callconv(.Naked) void) IdtError!void => DataElement{ .FN_IU8_IFNCCNAKEDOVOID_EIDTERROR_OVOID = arg },
|
||||
fn (u16, u8) void => DataElement{ .FN_IU16_IU8_OVOID = arg },
|
||||
fn (u16, u16) void => DataElement{ .FN_IU16_IU16_OVOID = arg },
|
||||
fn (u16, u32) void => DataElement{ .FN_IU16_IU32_OVOID = arg },
|
||||
fn (StatusRegister, bool) u8 => DataElement{ .FN_ISTATUSREGISTER_IBOOL_OU8 = arg },
|
||||
fn (*Task, usize) void => DataElement{ .FN_IPTRTASK_IUSIZE_OVOID = arg },
|
||||
fn (*Task, *Allocator) void => DataElement{ .FN_IPTRTASK_IPTRALLOCATOR_OVOID = arg },
|
||||
|
@ -270,9 +276,9 @@ fn Mock() type {
|
|||
fn () IdtPtr => DataElement.FN_OIDTPTR,
|
||||
fn (u8) void => DataElement.FN_IU8_OVOID,
|
||||
fn (u8) bool => DataElement.FN_IU8_OBOOL,
|
||||
fn (u8, fn () callconv(.Naked) void) IdtError!void => DataElement.FN_IU8_IFNCCNAKEDOVOID_EIDTERROR_OVOID,
|
||||
fn (u16) void => DataElement.FN_IU16_OVOID,
|
||||
fn (u16) u8 => DataElement.FN_IU16_OU8,
|
||||
fn (u16) u32 => DataElement.FN_IU16_OU32,
|
||||
fn (usize) bool => DataElement.FN_IUSIZE_OBOOL,
|
||||
fn (RtcRegister) u8 => DataElement.FN_IRTCREGISTER_OU8,
|
||||
fn (IdtEntry) bool => DataElement.FN_IIDTENTRY_OBOOL,
|
||||
|
@ -280,8 +286,10 @@ fn Mock() type {
|
|||
fn (*const IdtPtr) void => DataElement.FN_IPTRCONSTIDTPTR_OVOID,
|
||||
fn (u4, u4) u8 => DataElement.FN_IU4_IU4_OU8,
|
||||
fn (u8, u8) u16 => DataElement.FN_IU8_IU8_OU16,
|
||||
fn (u8, fn () callconv(.Naked) void) IdtError!void => DataElement.FN_IU8_IFNCCNAKEDOVOID_EIDTERROR_OVOID,
|
||||
fn (u16, u8) void => DataElement.FN_IU16_IU8_OVOID,
|
||||
fn (u16, u16) void => DataElement.FN_IU16_IU16_OVOID,
|
||||
fn (u16, u32) void => DataElement.FN_IU16_IU32_OVOID,
|
||||
fn (StatusRegister, bool) u8 => DataElement.FN_ISTATUSREGISTER_IBOOL_OU8,
|
||||
fn (*Task, usize) void => DataElement.FN_IPTRTASK_IUSIZE_OVOID,
|
||||
fn (*Task, *Allocator) void => DataElement.FN_IPTRTASK_IPTRALLOCATOR_OVOID,
|
||||
|
@ -328,9 +336,9 @@ fn Mock() type {
|
|||
fn () IdtPtr => element.FN_OIDTPTR,
|
||||
fn (u8) void => element.FN_IU8_OVOID,
|
||||
fn (u8) bool => element.FN_IU8_OBOOL,
|
||||
fn (u8, fn () callconv(.Naked) void) IdtError!void => element.FN_IU8_IFNCCNAKEDOVOID_EIDTERROR_OVOID,
|
||||
fn (u16) void => element.FN_IU16_OVOID,
|
||||
fn (u16) u8 => element.FN_IU16_OU8,
|
||||
fn (u16) u32 => element.FN_IU16_OU32,
|
||||
fn (usize) bool => element.FN_IUSIZE_OBOOL,
|
||||
fn (RtcRegister) u8 => element.FN_IRTCREGISTER_OU8,
|
||||
fn (IdtEntry) bool => element.FN_IIDTENTRY_OBOOL,
|
||||
|
@ -338,8 +346,10 @@ fn Mock() type {
|
|||
fn (*const IdtPtr) void => element.FN_IPTRCONSTIDTPTR_OVOID,
|
||||
fn (u4, u4) u8 => element.FN_IU4_IU4_OU8,
|
||||
fn (u8, u8) u16 => element.FN_IU8_IU8_OU16,
|
||||
fn (u8, fn () callconv(.Naked) void) IdtError!void => element.FN_IU8_IFNCCNAKEDOVOID_EIDTERROR_OVOID,
|
||||
fn (u16, u8) void => element.FN_IU16_IU8_OVOID,
|
||||
fn (u16, u16) void => element.FN_IU16_IU16_OVOID,
|
||||
fn (u16, u32) void => element.FN_IU16_IU32_OVOID,
|
||||
fn (StatusRegister, bool) u8 => element.FN_ISTATUSREGISTER_IBOOL_OU8,
|
||||
fn (*Task, usize) void => element.FN_IPTRTASK_IUSIZE_OVOID,
|
||||
fn (*Task, *Allocator) void => element.FN_IPTRTASK_IPTRALLOCATOR_OVOID,
|
||||
|
|
108
test/mock/kernel/pci_mock.zig
Normal file
108
test/mock/kernel/pci_mock.zig
Normal file
|
@ -0,0 +1,108 @@
|
|||
const std = @import("std");
|
||||
const Allocator = std.mem.Allocator;
|
||||
const arch = @import("arch_mock.zig");
|
||||
|
||||
const mock_framework = @import("mock_framework.zig");
|
||||
pub const initTest = mock_framework.initTest;
|
||||
pub const freeTest = mock_framework.freeTest;
|
||||
pub const addTestParams = mock_framework.addTestParams;
|
||||
pub const addConsumeFunction = mock_framework.addConsumeFunction;
|
||||
pub const addRepeatFunction = mock_framework.addRepeatFunction;
|
||||
|
||||
const PciRegisters = enum(u8) {
|
||||
VenderId = 0x00,
|
||||
DeviceId = 0x02,
|
||||
Command = 0x04,
|
||||
Status = 0x06,
|
||||
RevisionId = 0x08,
|
||||
ProgrammingInterface = 0x09,
|
||||
Subclass = 0x0A,
|
||||
ClassCode = 0x0B,
|
||||
CacheLineSize = 0x0C,
|
||||
LatencyTimer = 0x0D,
|
||||
HeaderType = 0x0E,
|
||||
BIST = 0x0F,
|
||||
BaseAddr0 = 0x10,
|
||||
BaseAddr1 = 0x14,
|
||||
BaseAddr2 = 0x18,
|
||||
BaseAddr3 = 0x1C,
|
||||
BaseAddr4 = 0x20,
|
||||
BaseAddr5 = 0x24,
|
||||
CardbusCISPtr = 0x28,
|
||||
SubsystemVenderId = 0x2C,
|
||||
SubsystemId = 0x2E,
|
||||
ExpansionROMBaseAddr = 0x30,
|
||||
CapabilitiesPtr = 0x34,
|
||||
InterruptLine = 0x3C,
|
||||
InterruptPin = 0x3D,
|
||||
MinGrant = 0x3E,
|
||||
MaxLatency = 0x3F,
|
||||
|
||||
pub fn getWidth(comptime pci_reg: PciRegisters) type {
|
||||
return switch (pci_reg) {
|
||||
.RevisionId, .ProgrammingInterface, .Subclass, .ClassCode, .CacheLineSize, .LatencyTimer, .HeaderType, .BIST, .InterruptLine, .InterruptPin, .MinGrant, .MaxLatency, .CapabilitiesPtr => u8,
|
||||
.VenderId, .DeviceId, .Command, .Status, .SubsystemVenderId, .SubsystemId => u16,
|
||||
.BaseAddr0, .BaseAddr1, .BaseAddr2, .BaseAddr3, .BaseAddr4, .BaseAddr5, .CardbusCISPtr, .ExpansionROMBaseAddr => u32,
|
||||
};
|
||||
}
|
||||
};
|
||||
|
||||
const PciAddress = packed struct {
|
||||
register_offset: u8,
|
||||
function: u3,
|
||||
device: u5,
|
||||
bus: u8,
|
||||
reserved: u7 = 0,
|
||||
enable: u1 = 1,
|
||||
};
|
||||
|
||||
const PciDevice = struct {
|
||||
bus: u8,
|
||||
device: u5,
|
||||
|
||||
const Self = @This();
|
||||
|
||||
pub fn getAddress(self: Self, function: u3, comptime pci_reg: PciRegisters) PciAddress {
|
||||
return PciAddress{
|
||||
.bus = self.bus,
|
||||
.device = self.device,
|
||||
.function = function,
|
||||
.register_offset = @enumToInt(pci_reg),
|
||||
};
|
||||
}
|
||||
|
||||
pub fn configReadData(self: Self, function: u3, comptime pci_reg: PciRegisters) pci_reg.getWidth() {
|
||||
return mock_framework.performAction("PciDevice.configReadData", pci_reg.getWidth(), .{ self, function, pci_reg });
|
||||
}
|
||||
};
|
||||
|
||||
pub const PciDeviceInfo = struct {
|
||||
pci_device: PciDevice,
|
||||
function: u3,
|
||||
vender_id: u16,
|
||||
device_id: u16,
|
||||
subclass: u8,
|
||||
class_code: u8,
|
||||
|
||||
pub const Error = error{NoFunction};
|
||||
|
||||
pub fn create(pci_device: PciDevice, function: u3) Error!PciDeviceInfo {
|
||||
return mock_framework.performAction("PciDeviceInfo.create", Error!PciDeviceInfo, .{ pci_device, function });
|
||||
}
|
||||
|
||||
pub fn print(device: arch.Device) void {
|
||||
std.debug.print("BUS: 0x{X}, DEV: 0x{X}, FUN: 0x{X}, VID: 0x{X}, DID: 0x{X}, SC: 0x{X}, CC: 0x{X}\n", .{
|
||||
device.pci_device.bus,
|
||||
device.pci_device.device,
|
||||
device.function,
|
||||
device.vender_id,
|
||||
device.device_id,
|
||||
device.subclass,
|
||||
device.class_code,
|
||||
});
|
||||
}
|
||||
};
|
||||
|
||||
pub fn getDevices(allocator: *Allocator) Allocator.Error![]PciDeviceInfo {
|
||||
return mock_framework.performAction("getDevices", Allocator.Error![]PciDeviceInfo, .{allocator});
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue