Commit b553e1dd authored by Jeremy Soller's avatar Jeremy Soller Committed by GitHub

Merge pull request #19 from redox-os/cap

Use capability mode (null namespace) for drivers
parents e3a9314a bd8a377c
......@@ -48,6 +48,9 @@ fn main() {
let mut event_file = File::open("event:").expect("ahcid: failed to open event file");
let scheme = DiskScheme::new(scheme_name, ahci::disks(address, &name));
syscall::setrens(0, 0).expect("ahcid: failed to enter null namespace");
loop {
let mut event = Event::default();
if event_file.read(&mut event).expect("ahcid: failed to read event file") == 0 {
......
......@@ -41,18 +41,21 @@ fn main() {
let socket_fd = syscall::open(":network", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK).expect("alxd: failed to create network scheme");
let socket = Arc::new(RefCell::new(unsafe { File::from_raw_fd(socket_fd) }));
let mut irq_file = File::open(format!("irq:{}", irq)).expect("alxd: failed to open IRQ file");
let address = unsafe { syscall::physmap(bar, 128*1024, MAP_WRITE).expect("alxd: failed to map address") };
{
let device = Arc::new(RefCell::new(unsafe { device::Alx::new(address).expect("alxd: failed to allocate device") }));
let mut event_queue = EventQueue::<usize>::new().expect("alxd: failed to create event queue");
syscall::setrens(0, 0).expect("alxd: failed to enter null namespace");
let todo = Arc::new(RefCell::new(Vec::<Packet>::new()));
let device_irq = device.clone();
let socket_irq = socket.clone();
let todo_irq = todo.clone();
let mut irq_file = File::open(format!("irq:{}", irq)).expect("alxd: failed to open IRQ file");
event_queue.add(irq_file.as_raw_fd(), move |_count: usize| -> Result<Option<usize>> {
let mut irq = [0; 8];
irq_file.read(&mut irq)?;
......
......@@ -40,6 +40,9 @@ fn main() {
bga: bga,
display: File::open("display:input").ok()
};
syscall::setrens(0, 0).expect("bgad: failed to enter null namespace");
loop {
let mut packet = Packet::default();
socket.read(&mut packet).expect("bgad: failed to read events from bga scheme");
......
......@@ -36,18 +36,21 @@ fn main() {
let socket_fd = syscall::open(":network", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK).expect("e1000d: failed to create network scheme");
let socket = Arc::new(RefCell::new(unsafe { File::from_raw_fd(socket_fd) }));
let mut irq_file = File::open(format!("irq:{}", irq)).expect("e1000d: failed to open IRQ file");
let address = unsafe { syscall::physmap(bar, 128*1024, MAP_WRITE).expect("e1000d: failed to map address") };
{
let device = Arc::new(unsafe { device::Intel8254x::new(address).expect("e1000d: failed to allocate device") });
let mut event_queue = EventQueue::<usize>::new().expect("e1000d: failed to create event queue");
syscall::setrens(0, 0).expect("e1000d: failed to enter null namespace");
let todo = Arc::new(RefCell::new(Vec::<Packet>::new()));
let device_irq = device.clone();
let socket_irq = socket.clone();
let todo_irq = todo.clone();
let mut irq_file = File::open(format!("irq:{}", irq)).expect("e1000d: failed to open IRQ file");
event_queue.add(irq_file.as_raw_fd(), move |_count: usize| -> Result<Option<usize>> {
let mut irq = [0; 8];
irq_file.read(&mut irq)?;
......
......@@ -20,7 +20,7 @@ use syscall::error::EWOULDBLOCK;
pub mod HDA;
use HDA::IntelHDA;
......@@ -28,11 +28,11 @@ use HDA::IntelHDA;
/*
/*
VEND:PROD
Virtualbox 8086:2668
QEMU ICH9 8086:293E
82801H ICH8 8086:284B
82801H ICH8 8086:284B
*/
fn main() {
......@@ -47,54 +47,43 @@ fn main() {
let irq_str = args.next().expect("ihda: no irq provided");
let irq = irq_str.parse::<u8>().expect("ihda: failed to parse irq");
let vend_str = args.next().expect("ihda: no vendor id provided");
let vend = usize::from_str_radix(&vend_str, 16).expect("ihda: failed to parse vendor id");
let prod_str = args.next().expect("ihda: no product id provided");
let prod = usize::from_str_radix(&prod_str, 16).expect("ihda: failed to parse product id");
print!("{}", format!(" + ihda {} on: {:X} IRQ: {}\n", name, bar, irq));
// Daemonize
if unsafe { syscall::clone(0).unwrap() } == 0 {
let address = unsafe { syscall::physmap(bar, 0x4000, MAP_WRITE).expect("ihdad: failed to map address") };
{
let mut irq_file = File::open(format!("irq:{}", irq)).expect("IHDA: failed to open IRQ file");
let vend_prod:u32 = ((vend as u32) << 16) | (prod as u32);
let vend_prod:u32 = ((vend as u32) << 16) | (prod as u32);
let device = Arc::new(RefCell::new(unsafe { HDA::IntelHDA::new(address, vend_prod).expect("ihdad: failed to allocate device") }));
let socket_fd = syscall::open(":audio", syscall::O_RDWR | syscall::O_CREAT | syscall::O_NONBLOCK).expect("IHDA: failed to create audio scheme");
let socket = Arc::new(RefCell::new(unsafe { File::from_raw_fd(socket_fd) }));
let mut event_queue = EventQueue::<usize>::new().expect("IHDA: Could not create event queue.");
syscall::setrens(0, 0).expect("ihdad: failed to enter null namespace");
let todo = Arc::new(RefCell::new(Vec::<Packet>::new()));
let todo_irq = todo.clone();
let device_irq = device.clone();
let socket_irq = socket.clone();
let device_loop = device.clone();
event_queue.add(irq_file.as_raw_fd(), move |_count: usize| -> Result<Option<usize>> {
let mut irq = [0; 8];
irq_file.read(&mut irq)?;
let _irq = unsafe { device_irq.borrow_mut().irq()};
if _irq {
irq_file.write(&mut irq)?;
......@@ -161,10 +150,7 @@ fn main() {
}).expect("IHDA: failed to write event");
}
loop {
loop {
{
//device_loop.borrow_mut().handle_interrupts();
}
......@@ -186,5 +172,3 @@ fn main() {
unsafe { let _ = syscall::physunmap(address); }
}
}
......@@ -58,6 +58,9 @@ fn main() {
let mut event_file = File::open("event:").expect("nvmed: failed to open event file");
let scheme = DiskScheme::new(nvme::disks(address, &name));
syscall::setrens(0, 0).expect("nvmed: failed to enter null namespace");
loop {
let mut event = Event::default();
if event_file.read(&mut event).expect("nvmed: failed to read event file") == 0 {
......
......@@ -269,11 +269,17 @@ fn daemon(input: File) {
},
None => (keymap::us::get_char)
};
let mut key_irq = File::open("irq:1").expect("ps2d: failed to open irq:1");
let mut mouse_irq = File::open("irq:12").expect("ps2d: failed to open irq:12");
let ps2d = Arc::new(RefCell::new(Ps2d::new(input, keymap)));
let mut event_queue = EventQueue::<()>::new().expect("ps2d: failed to create event queue");
let mut key_irq = File::open("irq:1").expect("ps2d: failed to open irq:1");
syscall::setrens(0, 0).expect("ps2d: failed to enter null namespace");
let key_ps2d = ps2d.clone();
event_queue.add(key_irq.as_raw_fd(), move |_count: usize| -> Result<Option<()>> {
let mut irq = [0; 8];
......@@ -284,7 +290,6 @@ fn daemon(input: File) {
Ok(None)
}).expect("ps2d: failed to poll irq:1");
let mut mouse_irq = File::open("irq:12").expect("ps2d: failed to open irq:12");
let mouse_ps2d = ps2d;
event_queue.add(mouse_irq.as_raw_fd(), move |_count: usize| -> Result<Option<()>> {
let mut irq = [0; 8];
......
......@@ -44,6 +44,8 @@ fn main() {
let mut event_queue = EventQueue::<usize>::new().expect("rtl8168d: failed to create event queue");
syscall::setrens(0, 0).expect("rtl8168d: failed to enter null namespace");
let todo = Arc::new(RefCell::new(Vec::<Packet>::new()));
let device_irq = device.clone();
......
......@@ -238,6 +238,8 @@ fn main() {
let mut event_queue = EventQueue::<()>::new().expect("vboxd: failed to create event queue");
syscall::setrens(0, 0).expect("vboxd: failed to enter null namespace");
let mut bga = Bga::new();
let get_mouse = VboxGetMouse::new().expect("vboxd: failed to map GetMouse");
let display_change = VboxDisplayChange::new().expect("vboxd: failed to map DisplayChange");
......
......@@ -62,6 +62,8 @@ fn main() {
let mut scheme = DisplayScheme::new(width, height, onscreen, &spec);
syscall::setrens(0, 0).expect("vesad: failed to enter null namespace");
let mut blocked = Vec::new();
loop {
let mut packet = Packet::default();
......
......@@ -49,6 +49,8 @@ fn main() {
let mut event_queue = EventQueue::<()>::new().expect("xhcid: failed to create event queue");
syscall::setrens(0, 0).expect("xhcid: failed to enter null namespace");
let todo = Arc::new(RefCell::new(Vec::<Packet>::new()));
let hci_irq = hci.clone();
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment