pcid: Also return bar size from physmap_mem and use it in two more drivers

This commit is contained in:
bjorn3
2024-06-14 19:21:37 +02:00
parent aaa3b89a1d
commit 3299a070f2
11 changed files with 30 additions and 46 deletions
+1 -1
View File
@@ -146,7 +146,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
log::info!(" + IHDA {}", pci_config.func.display());
let address = unsafe { bar.physmap_mem("ihdad") } as usize;
let address = unsafe { bar.physmap_mem("ihdad") }.0 as usize;
//TODO: MSI-X
let mut irq_file = get_int_method(&mut pcid_handle);
+1 -1
View File
@@ -33,7 +33,7 @@ fn main() {
redox_daemon::Daemon::new(move |daemon| {
let mut irq_file = irq.irq_handle("e1000d");
let address = unsafe { bar.physmap_mem("e1000d") } as usize;
let address = unsafe { bar.physmap_mem("e1000d") }.0 as usize;
let device =
unsafe { device::Intel8254x::new(address).expect("e1000d: failed to allocate device") };
+3 -13
View File
@@ -13,8 +13,6 @@ pub mod device;
#[rustfmt::skip]
mod ixgbe;
const IXGBE_MMIO_SIZE: usize = 512 * 1024;
fn main() {
let mut pcid_handle =
PcidServerHandle::connect_default().expect("ixgbed: failed to setup channel to pcid");
@@ -25,8 +23,6 @@ fn main() {
let mut name = pci_config.func.name();
name.push_str("_ixgbe");
let (bar, _) = pci_config.func.bars[0].expect_mem();
let irq = pci_config
.func
.legacy_interrupt_line
@@ -37,17 +33,11 @@ fn main() {
redox_daemon::Daemon::new(move |daemon| {
let mut irq_file = irq.irq_handle("ixgbed");
let address = unsafe {
common::physmap(
bar,
IXGBE_MMIO_SIZE,
common::Prot::RW,
common::MemoryType::Uncacheable,
)
.expect("ixgbed: failed to map address") as usize
let (address, size) = unsafe {
pci_config.func.bars[0].physmap_mem("ixgbed")
};
let device = device::Intel8259x::new(address, IXGBE_MMIO_SIZE)
let device = device::Intel8259x::new(address as usize, size)
.expect("ixgbed: failed to allocate device");
let mut scheme = NetworkScheme::new(device, format!("network.{name}"));
+1 -1
View File
@@ -136,7 +136,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File {
msix_info.validate(pci_config.func.bars);
let bar = &pci_config.func.bars[msix_info.table_bar as usize];
let bar_address = unsafe { bar.physmap_mem("rtl8139d") } as usize;
let bar_address = unsafe { bar.physmap_mem("rtl8139d") }.0 as usize;
let virt_table_base = (bar_address + msix_info.table_offset as usize) as *mut MsixTableEntry;
+1 -1
View File
@@ -131,7 +131,7 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File {
msix_info.validate(pci_config.func.bars);
let bar = &pci_config.func.bars[msix_info.table_bar as usize];
let bar_address = unsafe { bar.physmap_mem("rtl8168d") } as usize;
let bar_address = unsafe { bar.physmap_mem("rtl8168d") }.0 as usize;
let virt_table_base = (bar_address + msix_info.table_offset as usize) as *mut MsixTableEntry;
+4 -3
View File
@@ -53,9 +53,9 @@ impl PciBar {
}
}
pub unsafe fn physmap_mem(&self, driver: &str) -> *mut () {
pub unsafe fn physmap_mem(&self, driver: &str) -> (*mut (), usize) {
let (bar, bar_size) = self.expect_mem();
unsafe {
let addr = unsafe {
common::physmap(
bar,
bar_size,
@@ -64,6 +64,7 @@ impl PciBar {
common::MemoryType::Uncacheable,
)
}
.unwrap_or_else(|err| panic!("{driver}: failed to map BAR at {bar:016X}: {err}"))
.unwrap_or_else(|err| panic!("{driver}: failed to map BAR at {bar:016X}: {err}"));
(addr, bar_size)
}
}
+1 -1
View File
@@ -88,7 +88,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
info!(" + AHCI {}", pci_config.func.display());
let address = unsafe { bar.physmap_mem("ahcid") };
let (address, _) = unsafe { bar.physmap_mem("ahcid") };
{
let scheme_name = format!("disk.{}", name);
let socket = Socket::<V2>::nonblock(&scheme_name).expect("ahcid: failed to create disk scheme");
+15 -22
View File
@@ -27,22 +27,12 @@ mod scheme;
/// A wrapper for a BAR allocation.
pub struct Bar {
ptr: NonNull<u8>,
physical: usize,
bar_size: usize,
}
impl Bar {
pub fn allocate(bar: usize, bar_size: usize) -> Result<Self> {
pub fn new(ptr: *mut (), bar_size: usize) -> Result<Self> {
Ok(Self {
ptr: NonNull::new(
unsafe { common::physmap(
bar,
bar_size,
common::Prot { read: true, write: true },
common::MemoryType::Uncacheable,
)? as *mut u8 },
)
.expect("Mapping a BAR resulted in a nullptr"),
physical: bar,
ptr: NonNull::new(ptr.cast::<u8>()).expect("Mapping a BAR resulted in a nullptr"),
bar_size,
})
}
@@ -101,9 +91,9 @@ fn get_int_method(
match &mut *bar_guard {
&mut Some(ref bar) => Ok(bar.ptr),
bar_to_set @ &mut None => {
let (bar, bar_size) = function.bars[bir].expect_mem();
let (ptr, bar_size) = unsafe { function.bars[bir].physmap_mem("nvmed") };
let bar = Bar::allocate(bar, bar_size)?;
let bar = Bar::new(ptr, bar_size)?;
*bar_to_set = Some(bar);
Ok(bar_to_set.as_ref().unwrap().ptr)
}
@@ -265,18 +255,16 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
let _logger_ref = setup_logging(&scheme_name);
let bar = &pci_config.func.bars[0];
let (bar_ptr, bar_size) = bar.expect_mem();
log::debug!("NVME PCI CONFIG: {:?}", pci_config);
let allocated_bars = AllocatedBars::default();
let address = unsafe { bar.physmap_mem("nvmed") } as usize;
let bar = &pci_config.func.bars[0];
let (address, bar_size) = unsafe { bar.physmap_mem("nvmed") };
*allocated_bars.0[0].lock().unwrap() = Some(Bar {
physical: bar_ptr,
bar_size,
ptr: NonNull::new(address as *mut u8).expect("Physmapping BAR gave nullptr"),
ptr: NonNull::new(address.cast::<u8>()).expect("Physmapping BAR gave nullptr"),
});
let socket = Socket::<V2>::create(&scheme_name).expect("nvmed: failed to create disk scheme");
@@ -287,8 +275,13 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
let (interrupt_method, interrupt_sources) =
get_int_method(&mut pcid_handle, &pci_config.func, &allocated_bars)
.expect("nvmed: failed to find a suitable interrupt method");
let mut nvme = Nvme::new(address, interrupt_method, pcid_handle, reactor_sender)
.expect("nvmed: failed to allocate driver data");
let mut nvme = Nvme::new(
address as usize,
interrupt_method,
pcid_handle,
reactor_sender,
)
.expect("nvmed: failed to allocate driver data");
unsafe { nvme.init() }
log::debug!("Finished base initialization");
let nvme = Arc::new(nvme);
+1 -1
View File
@@ -217,7 +217,7 @@ fn main() {
let mut irq_file = irq.irq_handle("vboxd");
let mut port = Pio::<u32>::new(bar0 as u16);
let address = unsafe { bar1.physmap_mem("vboxd") };
let (address, _) = unsafe { bar1.physmap_mem("vboxd") };
{
let vmmdev = unsafe { &mut *(address as *mut VboxVmmDev) };
+1 -1
View File
@@ -19,7 +19,7 @@ pub fn enable_msix(pcid_handle: &mut PcidServerHandle) -> Result<File, Error> {
msix_info.validate(pci_config.func.bars);
let bar = &pci_config.func.bars[msix_info.table_bar as usize];
let bar_address = unsafe { bar.physmap_mem("virtio-core") } as usize;
let bar_address = unsafe { bar.physmap_mem("virtio-core") }.0 as usize;
let virt_table_base = (bar_address + msix_info.table_offset as usize) as *mut MsixTableEntry;
let mut info = MappedMsixRegs {
+1 -1
View File
@@ -195,7 +195,7 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
log::debug!("XHCI PCI CONFIG: {:?}", pci_config);
let bar = &pci_config.func.bars[0];
let address = unsafe { bar.physmap_mem("xhcid") } as usize;
let address = unsafe { bar.physmap_mem("xhcid") }.0 as usize;
let (irq_file, interrupt_method) = (None, InterruptMethod::Polling); //TODO: get_int_method(&mut pcid_handle, address);