Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add runtime registers, testing for TLB to XHCI
- Loading branch information
Showing
5 changed files
with
289 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
use syscall::io::Mmio; | ||
|
||
pub struct EventRingSte { | ||
pub address: Mmio<u64>, | ||
pub size: Mmio<u16>, | ||
_rsvd: Mmio<u16>, | ||
_rsvd2: Mmio<u32>, | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,102 @@ | ||
use std::cell::RefCell; | ||
use std::ops::{Deref, DerefMut}; | ||
use std::rc::Weak; | ||
|
||
use syscall::error::{Error, Result, EBADF, EINVAL, EPIPE}; | ||
use syscall::flag::{F_GETFL, F_SETFL, O_ACCMODE}; | ||
|
||
use pty::Pty; | ||
use resource::Resource; | ||
|
||
/// Read side of a pipe | ||
#[derive(Clone)] | ||
pub struct PtyTermios { | ||
pty: Weak<RefCell<Pty>>, | ||
flags: usize, | ||
} | ||
|
||
impl PtyTermios { | ||
pub fn new(pty: Weak<RefCell<Pty>>, flags: usize) -> Self { | ||
PtyTermios { | ||
pty: pty, | ||
flags: flags, | ||
} | ||
} | ||
} | ||
|
||
impl Resource for PtyTermios { | ||
fn boxed_clone(&self) -> Box<Resource> { | ||
Box::new(self.clone()) | ||
} | ||
|
||
fn pty(&self) -> Weak<RefCell<Pty>> { | ||
self.pty.clone() | ||
} | ||
|
||
fn flags(&self) -> usize { | ||
self.flags | ||
} | ||
|
||
fn path(&self, buf: &mut [u8]) -> Result<usize> { | ||
if let Some(pty_lock) = self.pty.upgrade() { | ||
pty_lock.borrow_mut().path(buf) | ||
} else { | ||
Err(Error::new(EPIPE)) | ||
} | ||
} | ||
|
||
fn read(&self, buf: &mut [u8]) -> Result<usize> { | ||
if let Some(pty_lock) = self.pty.upgrade() { | ||
let pty = pty_lock.borrow(); | ||
let termios: &[u8] = pty.termios.deref(); | ||
|
||
let mut i = 0; | ||
while i < buf.len() && i < termios.len() { | ||
buf[i] = termios[i]; | ||
i += 1; | ||
} | ||
Ok(i) | ||
} else { | ||
Ok(0) | ||
} | ||
} | ||
|
||
fn write(&self, buf: &[u8]) -> Result<usize> { | ||
if let Some(pty_lock) = self.pty.upgrade() { | ||
let mut pty = pty_lock.borrow_mut(); | ||
let termios: &mut [u8] = pty.termios.deref_mut(); | ||
|
||
let mut i = 0; | ||
while i < buf.len() && i < termios.len() { | ||
termios[i] = buf[i]; | ||
i += 1; | ||
} | ||
Ok(i) | ||
} else { | ||
Err(Error::new(EPIPE)) | ||
} | ||
} | ||
|
||
fn sync(&self) -> Result<usize> { | ||
Ok(0) | ||
} | ||
|
||
fn fcntl(&mut self, cmd: usize, arg: usize) -> Result<usize> { | ||
match cmd { | ||
F_GETFL => Ok(self.flags), | ||
F_SETFL => { | ||
self.flags = (self.flags & O_ACCMODE) | (arg & ! O_ACCMODE); | ||
Ok(0) | ||
}, | ||
_ => Err(Error::new(EINVAL)) | ||
} | ||
} | ||
|
||
fn fevent(&self) -> Result<()> { | ||
Err(Error::new(EBADF)) | ||
} | ||
|
||
fn fevent_count(&self) -> Option<usize> { | ||
None | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,123 @@ | ||
use syscall::io::{Io, Mmio}; | ||
|
||
#[repr(u8)] | ||
pub enum TrbType { | ||
Reserved, | ||
/* Transfer */ | ||
Normal, | ||
SetupStage, | ||
DataStage, | ||
StatusStage, | ||
Isoch, | ||
Link, | ||
EventData, | ||
NoOp, | ||
/* Command */ | ||
EnableSlot, | ||
DisableSlot, | ||
AddressDevice, | ||
ConfigureEndpoint, | ||
EvaluateContext, | ||
ResetEndpoint, | ||
StopEndpoint, | ||
SetTrDequeuePointer, | ||
ResetDevice, | ||
ForceEvent, | ||
NegotiateBandwidth, | ||
SetLatencyToleranceValue, | ||
GetPortBandwidth, | ||
ForceHeader, | ||
NoOpCmd, | ||
/* Reserved */ | ||
Rsv24, | ||
Rsv25, | ||
Rsv26, | ||
Rsv27, | ||
Rsv28, | ||
Rsv29, | ||
Rsv30, | ||
Rsv31, | ||
/* Events */ | ||
Transfer, | ||
CommandCompletion, | ||
PortStatusChange, | ||
BandwidthRequest, | ||
Doorbell, | ||
HostController, | ||
DeviceNotification, | ||
MfindexWrap, | ||
/* Reserved from 40 to 47, vendor devined from 48 to 63 */ | ||
} | ||
|
||
#[repr(u8)] | ||
pub enum TrbCompletionCode { | ||
Invalid, | ||
Success, | ||
DataBuffer, | ||
BabbleDetected, | ||
UsbTransaction, | ||
Trb, | ||
Stall, | ||
Resource, | ||
Bandwidth, | ||
NoSlotsAvailable, | ||
InvalidStreamType, | ||
SlotNotEnabled, | ||
EndpointNotEnabled, | ||
ShortPacket, | ||
RingUnderrun, | ||
RingOverrun, | ||
VfEventRingFull, | ||
Parameter, | ||
BandwidthOverrun, | ||
ContextState, | ||
NoPingResponse, | ||
EventRingFull, | ||
IncompatibleDevice, | ||
MissedService, | ||
CommandRingStopped, | ||
CommandAborted, | ||
Stopped, | ||
StoppedLengthInvalid, | ||
StoppedShortPacket, | ||
MaxExitLatencyTooLarge, | ||
Rsv30, | ||
IsochBuffer, | ||
EventLost, | ||
Undefined, | ||
InvalidStreamId, | ||
SecondaryBandwidth, | ||
SplitTransaction, | ||
/* Values from 37 to 191 are reserved */ | ||
/* 192 to 223 are vendor defined errors */ | ||
/* 224 to 255 are vendor defined information */ | ||
} | ||
|
||
#[repr(packed)] | ||
pub struct Trb { | ||
pub data: Mmio<u64>, | ||
pub status: Mmio<u32>, | ||
pub control: Mmio<u32>, | ||
} | ||
|
||
impl Trb { | ||
pub fn reset(&mut self, param: u64, status: u32, control: u16, trb_type: TrbType, evaluate_next: bool, cycle: bool) { | ||
let full_control = | ||
(control as u32) << 16 | | ||
((trb_type as u32) & 0x3F) << 10 | | ||
if evaluate_next { 1 << 1 } else { 0 } | | ||
if cycle { 1 << 0 } else { 0 }; | ||
|
||
self.data.write(param); | ||
self.status.write(status); | ||
self.control.write(full_control); | ||
} | ||
|
||
pub fn no_op_cmd(&mut self, cycle: bool) { | ||
self.reset(0, 0, 0, TrbType::NoOpCmd, false, cycle); | ||
} | ||
|
||
pub fn enable_slot(&mut self, slot_type: u8, cycle: bool) { | ||
self.reset(0, 0, (slot_type as u16) & 0x1F, TrbType::EnableSlot, false, cycle); | ||
} | ||
} |