Merge branch 'daemonize_pcid_correctly' into 'master'

Handle daemonization of pcid in a better way

See merge request redox-os/drivers!188
This commit is contained in:
Jeremy Soller
2024-07-20 22:13:49 +00:00
7 changed files with 30 additions and 17 deletions
Generated
+1
View File
@@ -937,6 +937,7 @@ dependencies = [
"paw",
"pci_types",
"plain",
"redox-daemon",
"redox-log",
"redox_syscall 0.5.3",
"serde",
+1
View File
@@ -22,4 +22,5 @@ fmt graphics/bgad \
graphics/virtio-gpud \
inputd \
net/virtio-netd \
pcid \
virtio-core
+1
View File
@@ -21,6 +21,7 @@ log = "0.4"
paw = "1.0"
pci_types = "0.10"
plain = "0.2"
redox-daemon = "0.1"
redox-log = "0.1"
redox_syscall = "0.5"
serde = { version = "1", features = ["derive"] }
+3 -4
View File
@@ -74,18 +74,17 @@ impl DriverHandler {
Ok(mut child) => {
let driver_handler = DriverHandler {
addr: func.addr,
state,
state: state.clone(),
capabilities,
};
let _handle = thread::spawn(move || {
let handle = thread::spawn(move || {
driver_handler.handle_spawn(
pcid_to_client_write,
pcid_from_client_read,
subdriver_args,
);
});
// FIXME this currently deadlocks as pcid doesn't daemonize
//state.threads.lock().unwrap().push(handle);
state.threads.lock().unwrap().push(handle);
match child.wait() {
Ok(_status) => (),
Err(err) => error!("pcid: failed to wait for {:?}: {}", command, err),
+1 -4
View File
@@ -8,10 +8,7 @@ pub struct VendorSpecificCapability {
}
impl VendorSpecificCapability {
pub unsafe fn parse(
addr: PciCapabilityAddress,
access: &dyn ConfigRegionAccess,
) -> Self {
pub unsafe fn parse(addr: PciCapabilityAddress, access: &dyn ConfigRegionAccess) -> Self {
let dword = access.read(addr.address, addr.offset);
let next = (dword >> 8) & 0xFF;
let length = ((dword >> 16) & 0xFF) as u16;
+15 -9
View File
@@ -137,14 +137,15 @@ pub fn allocate_aligned_interrupt_vectors(
}
// if found, reserve the irq
let irq_handle = match File::create(format!("/scheme/irq/cpu-{:02x}/{}", cpu_id, irq_number)) {
Ok(handle) => handle,
let irq_handle =
match File::create(format!("/scheme/irq/cpu-{:02x}/{}", cpu_id, irq_number)) {
Ok(handle) => handle,
// return early if the entire range couldn't be allocated
Err(err) if err.kind() == io::ErrorKind::NotFound => break,
// return early if the entire range couldn't be allocated
Err(err) if err.kind() == io::ErrorKind::NotFound => break,
Err(err) => return Err(err),
};
Err(err) => return Err(err),
};
handles.push(irq_handle);
index += 1;
}
@@ -191,8 +192,13 @@ pub fn allocate_single_interrupt_vector_for_msi(cpu_id: usize) -> (MsiAddrAndDat
let (vector, interrupt_handle) = allocate_single_interrupt_vector(cpu_id)
.expect("failed to allocate interrupt vector")
.expect("no interrupt vectors left");
let msg_data =
x86_msix::message_data_edge_triggered(x86_msix::DeliveryMode::Fixed, vector);
let msg_data = x86_msix::message_data_edge_triggered(x86_msix::DeliveryMode::Fixed, vector);
(MsiAddrAndData { addr, data: msg_data }, interrupt_handle)
(
MsiAddrAndData {
addr,
data: msg_data,
},
interrupt_handle,
)
}
+8
View File
@@ -248,6 +248,10 @@ fn main(args: Args) {
let _logger_ref = setup_logging(args.verbose);
redox_daemon::Daemon::new(move |daemon| main_inner(config, daemon)).unwrap();
}
fn main_inner(config: Config, daemon: redox_daemon::Daemon) -> ! {
let state = Arc::new(State {
pcie: Pcie::new(),
threads: Mutex::new(Vec::new()),
@@ -312,7 +316,11 @@ fn main(args: Args) {
}
}
daemon.ready().unwrap();
for thread in state.threads.lock().unwrap().drain(..) {
thread.join().unwrap();
}
std::process::exit(0);
}