Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
54 changes: 54 additions & 0 deletions Cargo.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion Cargo.toml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
[workspace]
members = ["kernel", "bootstrap", "shell", "libuser", "clock", "sm", "vi", "ahci", "libutils", "libkern", "swipc-gen", "swipc-parser"]
members = ["kernel", "bootstrap", "shell", "libuser", "clock", "sm", "vi", "ahci", "libutils", "libkern", "swipc-gen", "swipc-parser", "virtio"]

[profile.release]
debug = true
Expand Down
64 changes: 57 additions & 7 deletions Makefile.toml
Original file line number Diff line number Diff line change
Expand Up @@ -138,15 +138,30 @@ dependencies = ["install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none-user", "--package=sunrise-ahci", "--release"]

[tasks.virtio]
workspace = false
description = "Compiles sunrise-virtio"
dependencies = ["install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none-user", "--package=sunrise-virtio"]

[tasks.virtio-release]
workspace = false
description = "Compiles sunrise-virtio"
dependencies = ["install-rust-src"]
command = "cargo"
args = ["xbuild", "--target=i386-unknown-none-user", "--package=sunrise-virtio", "--release"]


[tasks.userspace]
workspace = false
description = "Compiles userspace apps"
dependencies = ["shell", "clock", "sm", "vi", "ahci"]
dependencies = ["shell", "clock", "sm", "vi", "ahci", "virtio"]

[tasks.userspace-release]
workspace = false
description = "Compiles userspace apps"
dependencies = ["shell-release", "clock-release", "sm-release", "vi-release", "ahci-release"]
dependencies = ["shell-release", "clock-release", "sm-release", "vi-release", "ahci-release", "virtio-release"]

[tasks.iso]
workspace = false
Expand All @@ -162,6 +177,7 @@ cp target/i386-unknown-none-user/debug/sunrise-clock isofiles/boot/
cp target/i386-unknown-none-user/debug/sunrise-sm isofiles/boot/
cp target/i386-unknown-none-user/debug/sunrise-vi isofiles/boot/
cp target/i386-unknown-none-user/debug/sunrise-ahci isofiles/boot/
cp target/i386-unknown-none-user/debug/sunrise-virtio isofiles/boot/
mkisofs-rs external/grub/isofiles isofiles -o os.iso -b boot/grub/i386-pc/eltorito.img --no-emul-boot --boot-info-table --embedded-boot external/grub/embedded.img
'''
]
Expand All @@ -180,6 +196,7 @@ cp target/i386-unknown-none-user/release/sunrise-clock isofiles/boot/
cp target/i386-unknown-none-user/release/sunrise-sm isofiles/boot/
cp target/i386-unknown-none-user/release/sunrise-vi isofiles/boot/
cp target/i386-unknown-none-user/release/sunrise-ahci isofiles/boot/
cp target/i386-unknown-none-user/release/sunrise-virtio isofiles/boot/
mkisofs-rs external/grub/isofiles isofiles -o os.iso -b boot/grub/i386-pc/eltorito.img --no-emul-boot --boot-info-table --embedded-boot external/grub/embedded.img
'''
]
Expand Down Expand Up @@ -213,13 +230,28 @@ description = "Runs the bootable ISO in qemu."
dependencies = ["iso-release", "create-disk-if-not-exist"]
command = "qemu-system-i386"
args = [
# Boot device
"-cdrom", "os.iso",
"-serial", "stdio",
# Redirect serial to STDIO
"-serial", "mon:stdio",
# Redirect graphics to VNC
"-vnc", "${VNC_PORT}",
# Don't reboot on triple fault
"-no-reboot",
"-enable-kvm",
# Enable hardware acceleration
#"-enable-kvm",
# Setup an AHCI device, with a disk on the first IDE port.
"-drive", "id=diskA,file=DISK.img,format=raw,if=none", "-device", "ahci,id=ahci", "-device", "ide-drive,drive=diskA,bus=ahci.0",
"-machine", "q35",
# Setup a network device, using virtio-net.
# TODO: iommu_platform=true
"-device", "virtio-net,disable-legacy=on,netdev=u1", "-netdev", "user,id=u1",
# Dump packets going on the vlan
"-object", "filter-dump,id=f1,netdev=u1,file=dump.dat",
# Trace virtio-related events
"--trace", "virtio_set_status,file=trace", "--trace", "virtio_queue_notify,file=trace", "--trace", "virtio_notify,file=trace", "--trace", "virtio_input_queue_full,file=trace",
"--trace", "virtio_net_announce_notify,file=trace", "--trace", "virtio_net_announce_timer,file=trace", "--trace", "virtio_net_handle_announce,file=trace",
"--trace", "virtio_net_post_load_device,file=trace", "--trace", "virtio_notify_irqfd,file=trace",
]

[tasks.qemu-debug]
Expand All @@ -228,14 +260,32 @@ description = "Runs the bootable ISO in qemu with gdb support"
dependencies = ["iso", "create-disk-if-not-exist"]
command = "qemu-system-i386"
args = [
# Boot device
"-cdrom", "os.iso",
"-serial", "stdio",
# Redirect serial to STDIO
"-serial", "mon:stdio",
# Redirect graphics to VNC
"-vnc", "${VNC_PORT}",
"-no-reboot",
# Enable hardware acceleration
#"-enable-kvm",
# Setup an AHCI device, with a disk on the first IDE port.
"-drive", "id=diskA,file=DISK.img,format=raw,if=none", "-device", "ahci,id=ahci", "-device", "ide-drive,drive=diskA,bus=ahci.0",
# Setup a network device, using virtio-net.
# TODO: ,iommu_platform=true
"-device", "virtio-net,disable-legacy=on,netdev=u1", "-netdev", "user,id=u1",
# Dump packets going on the vlan
"-object", "filter-dump,id=f1,netdev=u1,file=dump.dat",

# Enable GDB
"-gdb", "tcp::${GDB_PORT}", "-S",
# Print state on CPU reset
"-d", "cpu_reset",
"-drive", "id=diskA,file=DISK.img,format=raw,if=none", "-device", "ahci,id=ahci", "-device", "ide-drive,drive=diskA,bus=ahci.0",
"-machine", "q35",
# Trace virtio-related events
"--trace", "virtio_set_status,file=trace", "--trace", "virtio_queue_notify,file=trace", "--trace", "virtio_notify,file=trace", "--trace", "virtio_input_queue_full,file=trace",
"--trace", "virtio_net_announce_notify,file=trace", "--trace", "virtio_net_announce_timer,file=trace", "--trace", "virtio_net_handle_announce,file=trace",
"--trace", "virtio_net_post_load_device,file=trace", "--trace", "virtio_notify_irqfd,file=trace",
]

[tasks.doc]
Expand Down Expand Up @@ -274,7 +324,7 @@ args = ["-c", "kernel/src/main.rs", "bootstrap/src/main.rs",
"shell/src/main.rs", "libuser/src/lib.rs", "clock/src/main.rs",
"sm/src/main.rs", "vi/src/main.rs", "ahci/src/main.rs",
"libutils/src/lib.rs", "libkern/src/lib.rs", "swipc-gen/src/lib.rs",
"swipc-parser/src/lib.rs"
"swipc-parser/src/lib.rs", "virtio/src/main.rs",
]

[tasks.clippy-sunrise-target]
Expand Down
18 changes: 16 additions & 2 deletions ahci/src/main.rs
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,6 @@ extern crate log;
#[macro_use]
extern crate bitfield;

mod pci;
mod hba;
mod fis;
mod disk;
Expand All @@ -80,6 +79,8 @@ use spin::Mutex;
use sunrise_libuser::syscalls;
use sunrise_libuser::ipc::server::SessionWrapper;
use sunrise_libuser::ahci::{AhciInterface as IAhciInterface, IDiskProxy, IDisk as _};
use sunrise_libuser::pci;
use sunrise_libuser::pci::{PciHeader, BAR};

/// Array of discovered disk.
///
Expand All @@ -101,7 +102,20 @@ static DISKS: Mutex<Vec<Arc<Mutex<Disk>>>> = Mutex::new(Vec::new());
/// 3. Start the event loop.
fn main() {
debug!("AHCI driver starting up");
let ahci_controllers = pci::get_ahci_controllers();
let ahci_controllers = pci::discover()
.filter(|device| device.class() == 0x01 && device.subclass() == 0x06 && device.prog_if() == 0x01)
.map(|device| {
match device.header() {
PciHeader::GeneralDevice(header00) => {
match header00.bar(5) {
Ok(BAR::Memory(memory)) => (memory.phys_addr(), memory.size()),
_ => panic!("PCI device with unexpected BAR 5")
}
},
_ => panic!("PCI device with unexpected header")
}
});

debug!("AHCI controllers : {:#x?}", ahci_controllers);
for (bar5, _) in ahci_controllers {
DISKS.lock().extend(
Expand Down
Loading