Merge branch 'update_pci_types' into 'master'
Several pcid cleanups See merge request redox-os/drivers!156
This commit is contained in:
Generated
+2
-2
@@ -907,9 +907,9 @@ checksum = "7f0b59668fe80c5afe998f0c0bf93322bf2cd66cafeeb80581f291716f3467f2"
|
||||
|
||||
[[package]]
|
||||
name = "pci_types"
|
||||
version = "0.6.2"
|
||||
version = "0.9.0"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "ebac2b2ee11791f721a51184b632a916b3044f2ee7b2374e7fdcfdf3eaf29c79"
|
||||
checksum = "6f966dfb3dde50a726cc62ae44dc48efd10a211db15296c00cd88550ad8ef24c"
|
||||
dependencies = [
|
||||
"bit_field",
|
||||
"bitflags 2.5.0",
|
||||
|
||||
+1
-1
@@ -20,7 +20,7 @@ fdt = { git = "https://gitlab.redox-os.org/rosehuds/fdt.git" }
|
||||
libc = "0.2"
|
||||
log = "0.4"
|
||||
paw = "1.0"
|
||||
pci_types = "0.6.1"
|
||||
pci_types = "0.9.0"
|
||||
plain = "0.2"
|
||||
redox-log = "0.1"
|
||||
redox_syscall = "0.5"
|
||||
|
||||
@@ -255,22 +255,19 @@ pub(crate) fn recv<R: Read, T: DeserializeOwned>(r: &mut R) -> Result<T> {
|
||||
}
|
||||
|
||||
impl PcidServerHandle {
|
||||
pub fn connect(pcid_to_client: RawFd, pcid_from_client: RawFd) -> Result<Self> {
|
||||
Ok(Self {
|
||||
pcid_to_client: unsafe { File::from_raw_fd(pcid_to_client) },
|
||||
pcid_from_client: unsafe { File::from_raw_fd(pcid_from_client) },
|
||||
})
|
||||
}
|
||||
pub fn connect_default() -> Result<Self> {
|
||||
let pcid_to_client_fd = env::var("PCID_TO_CLIENT_FD")?.parse::<RawFd>().map_err(PcidClientHandleError::EnvValidityError)?;
|
||||
let pcid_from_client_fd = env::var("PCID_FROM_CLIENT_FD")?.parse::<RawFd>().map_err(PcidClientHandleError::EnvValidityError)?;
|
||||
|
||||
Self::connect(pcid_to_client_fd, pcid_from_client_fd)
|
||||
Ok(Self {
|
||||
pcid_to_client: unsafe { File::from_raw_fd(pcid_to_client_fd) },
|
||||
pcid_from_client: unsafe { File::from_raw_fd(pcid_from_client_fd) },
|
||||
})
|
||||
}
|
||||
pub(crate) fn send(&mut self, req: &PcidClientRequest) -> Result<()> {
|
||||
fn send(&mut self, req: &PcidClientRequest) -> Result<()> {
|
||||
send(&mut self.pcid_from_client, req)
|
||||
}
|
||||
pub(crate) fn recv(&mut self) -> Result<PcidClientResponse> {
|
||||
fn recv(&mut self) -> Result<PcidClientResponse> {
|
||||
recv(&mut self.pcid_to_client)
|
||||
}
|
||||
pub fn fetch_config(&mut self) -> Result<SubdriverArguments> {
|
||||
|
||||
+11
-18
@@ -1,6 +1,3 @@
|
||||
// Already stabilized, TODO: remove when Redox's rustc is updated
|
||||
#![feature(result_option_inspect)]
|
||||
|
||||
use std::fs::{File, metadata, read_dir};
|
||||
use std::io::prelude::*;
|
||||
use std::os::unix::io::{FromRawFd, RawFd};
|
||||
@@ -212,9 +209,9 @@ pub struct State {
|
||||
pcie: Pcie,
|
||||
}
|
||||
|
||||
fn print_pci_function(addr: PciAddress, header: &PciHeader) {
|
||||
fn print_pci_function(header: &PciHeader) {
|
||||
let mut string = format!("PCI {} {:>04X}:{:>04X} {:>02X}.{:>02X}.{:>02X}.{:>02X} {:?}",
|
||||
addr, header.vendor_id(), header.device_id(), header.class(),
|
||||
header.address(), header.vendor_id(), header.device_id(), header.class(),
|
||||
header.subclass(), header.interface(), header.revision(), header.class());
|
||||
let device_type = DeviceType::from((header.class(), header.subclass()));
|
||||
match device_type {
|
||||
@@ -237,7 +234,7 @@ fn print_pci_function(addr: PciAddress, header: &PciHeader) {
|
||||
info!("{}", string);
|
||||
}
|
||||
|
||||
fn handle_parsed_header(state: Arc<State>, config: &Config, addr: PciAddress, header: PciEndpointHeader) {
|
||||
fn handle_parsed_header(state: Arc<State>, config: &Config, header: PciEndpointHeader) {
|
||||
for driver in config.drivers.iter() {
|
||||
if !driver.match_function(header.full_device_id()) {
|
||||
continue;
|
||||
@@ -272,15 +269,16 @@ fn handle_parsed_header(state: Arc<State>, config: &Config, addr: PciAddress, he
|
||||
let mut irq;
|
||||
let interrupt_pin;
|
||||
|
||||
// FIXME use pci_types' update_interrupt once it is released to crates.io
|
||||
unsafe {
|
||||
let mut data = state.pcie.read(addr, 0x3C);
|
||||
let mut data = state.pcie.read(header.address(), 0x3C);
|
||||
irq = (data & 0xFF) as u8;
|
||||
interrupt_pin = ((data & 0x0000_FF00) >> 8) as u8;
|
||||
if irq == 0xFF {
|
||||
irq = 9;
|
||||
}
|
||||
data = (data & 0xFFFFFF00) | irq as u32;
|
||||
state.pcie.write(addr, 0x3C, data);
|
||||
state.pcie.write(header.address(), 0x3C, data);
|
||||
};
|
||||
|
||||
let legacy_interrupt_enabled = match interrupt_pin {
|
||||
@@ -296,7 +294,7 @@ fn handle_parsed_header(state: Arc<State>, config: &Config, addr: PciAddress, he
|
||||
let capabilities = if endpoint_header.status(&state.pcie).has_capability_list() {
|
||||
let func = PciFunc {
|
||||
pci: &state.pcie,
|
||||
addr
|
||||
addr: header.address(),
|
||||
};
|
||||
crate::pci::cap::CapabilitiesIter { inner: crate::pci::cap::CapabilityOffsetsIter::new(header.cap_pointer(), &func) }.collect::<Vec<_>>()
|
||||
} else {
|
||||
@@ -306,7 +304,7 @@ fn handle_parsed_header(state: Arc<State>, config: &Config, addr: PciAddress, he
|
||||
|
||||
let func = driver_interface::PciFunction {
|
||||
bars,
|
||||
addr,
|
||||
addr: header.address(),
|
||||
legacy_interrupt_line: if legacy_interrupt_enabled {
|
||||
Some(LegacyInterruptLine(irq))
|
||||
} else {
|
||||
@@ -356,7 +354,7 @@ fn handle_parsed_header(state: Arc<State>, config: &Config, addr: PciAddress, he
|
||||
match command.envs(envs).spawn() {
|
||||
Ok(mut child) => {
|
||||
let driver_handler = DriverHandler {
|
||||
addr,
|
||||
addr: header.address(),
|
||||
state: Arc::clone(&state),
|
||||
capabilities,
|
||||
};
|
||||
@@ -475,15 +473,10 @@ fn main(args: Args) {
|
||||
let func_addr = PciAddress::new(0, bus_num, dev_num, func_num);
|
||||
match PciHeader::from_reader(&state.pcie, func_addr) {
|
||||
Ok(header) => {
|
||||
print_pci_function(func_addr, &header);
|
||||
print_pci_function(&header);
|
||||
match header {
|
||||
PciHeader::General(endpoint_header) => {
|
||||
handle_parsed_header(
|
||||
Arc::clone(&state),
|
||||
&config,
|
||||
func_addr,
|
||||
endpoint_header,
|
||||
);
|
||||
handle_parsed_header(Arc::clone(&state), &config, endpoint_header);
|
||||
}
|
||||
PciHeader::PciToPci {
|
||||
secondary_bus_num, ..
|
||||
|
||||
@@ -112,6 +112,14 @@ impl PciHeader {
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the PCI address.
|
||||
pub fn address(&self) -> PciAddress {
|
||||
match self {
|
||||
PciHeader::General(header) => header.address(),
|
||||
PciHeader::PciToPci { shared, .. } => shared.addr,
|
||||
}
|
||||
}
|
||||
|
||||
/// Return the Vendor ID field.
|
||||
pub fn vendor_id(&self) -> u16 {
|
||||
self.full_device_id().vendor_id
|
||||
@@ -144,6 +152,10 @@ impl PciHeader {
|
||||
}
|
||||
|
||||
impl PciEndpointHeader {
|
||||
pub fn address(&self) -> PciAddress {
|
||||
self.shared.addr
|
||||
}
|
||||
|
||||
pub fn endpoint_header(&self, access: &impl ConfigRegionAccess) -> EndpointHeader {
|
||||
EndpointHeader::from_header(TyPciHeader::new(self.shared.addr), access).unwrap()
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
#![deny(trivial_numeric_casts, unused_allocation)]
|
||||
#![feature(int_roundings, async_fn_in_trait)]
|
||||
#![feature(int_roundings)]
|
||||
|
||||
// TODO(andypython): driver panic with an empty disk.
|
||||
|
||||
|
||||
Reference in New Issue
Block a user