Introduce PciBar::physmap_mem helper
This commit is contained in:
+4
-10
@@ -82,22 +82,16 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
|
||||
let mut name = pci_config.func.name();
|
||||
name.push_str("_ahci");
|
||||
|
||||
let (bar, bar_size) = pci_config.func.bars[5].expect_mem();
|
||||
let bar = &pci_config.func.bars[5];
|
||||
let (bar_ptr, bar_size) = bar.expect_mem();
|
||||
|
||||
let irq = pci_config.func.legacy_interrupt_line.expect("ahcid: no legacy interrupts supported");
|
||||
|
||||
let _logger_ref = setup_logging(&name);
|
||||
|
||||
info!(" + AHCI {} on: {} size: {} IRQ: {}", name, bar, bar_size, irq);
|
||||
info!(" + AHCI {} on: {} size: {} IRQ: {}", name, bar_ptr, bar_size, irq);
|
||||
|
||||
let address = unsafe {
|
||||
common::physmap(
|
||||
bar,
|
||||
bar_size,
|
||||
common::Prot { read: true, write: true },
|
||||
common::MemoryType::Uncacheable,
|
||||
).expect("ahcid: failed to map address")
|
||||
};
|
||||
let address = unsafe { bar.physmap_mem("ahcid") };
|
||||
{
|
||||
let scheme_name = format!("disk.{}", name);
|
||||
let socket_fd = syscall::open(
|
||||
|
||||
+4
-6
@@ -68,11 +68,12 @@ fn main() {
|
||||
let mut name = pci_config.func.name();
|
||||
name.push_str("_e1000");
|
||||
|
||||
let (bar, bar_size) = pci_config.func.bars[0].expect_mem();
|
||||
let bar = &pci_config.func.bars[0];
|
||||
let (bar_ptr, bar_size) = bar.expect_mem();
|
||||
|
||||
let irq = pci_config.func.legacy_interrupt_line.expect("e1000d: no legacy interrupts supported");
|
||||
|
||||
eprintln!(" + E1000 {} on: {:X} size: {} IRQ: {}", name, bar, bar_size, irq);
|
||||
eprintln!(" + E1000 {} on: {:X} size: {} IRQ: {}", name, bar_ptr, bar_size, irq);
|
||||
|
||||
redox_daemon::Daemon::new(move |daemon| {
|
||||
let socket_fd = syscall::open(
|
||||
@@ -86,10 +87,7 @@ fn main() {
|
||||
|
||||
let mut irq_file = irq.irq_handle("e1000d");
|
||||
|
||||
let address = unsafe {
|
||||
common::physmap(bar, bar_size, common::Prot::RW, common::MemoryType::Uncacheable)
|
||||
.expect("e1000d: failed to map address")
|
||||
} as usize;
|
||||
let address = unsafe { bar.physmap_mem("e1000d") } as usize;
|
||||
{
|
||||
let device = Arc::new(RefCell::new(unsafe {
|
||||
device::Intel8254x::new(address).expect("e1000d: failed to allocate device")
|
||||
|
||||
+3
-5
@@ -155,14 +155,12 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
|
||||
let mut name = pci_config.func.name();
|
||||
name.push_str("_ihda");
|
||||
|
||||
let (bar_ptr, bar_size) = pci_config.func.bars[0].expect_mem();
|
||||
let bar = &pci_config.func.bars[0];
|
||||
let (bar_ptr, bar_size) = bar.expect_mem();
|
||||
|
||||
log::info!(" + IHDA {} on: {:#X} size: {}", name, bar_ptr, bar_size);
|
||||
|
||||
let address = unsafe {
|
||||
common::physmap(bar_ptr, bar_size, common::Prot::RW, common::MemoryType::Uncacheable)
|
||||
.expect("ihdad: failed to map address") as usize
|
||||
};
|
||||
let address = unsafe { bar.physmap_mem("ihdad") } as usize;
|
||||
|
||||
//TODO: MSI-X
|
||||
let mut irq_file = get_int_method(&mut pcid_handle);
|
||||
|
||||
+10
-13
@@ -48,7 +48,12 @@ impl Bar {
|
||||
|
||||
impl Drop for Bar {
|
||||
fn drop(&mut self) {
|
||||
let _ = unsafe { syscall::funmap(self.physical, self.bar_size.next_multiple_of(PAGE_SIZE)) };
|
||||
let _ = unsafe {
|
||||
syscall::funmap(
|
||||
self.ptr.as_ptr() as usize,
|
||||
self.bar_size.next_multiple_of(PAGE_SIZE),
|
||||
)
|
||||
};
|
||||
}
|
||||
}
|
||||
|
||||
@@ -288,24 +293,16 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
|
||||
|
||||
let _logger_ref = setup_logging(&scheme_name);
|
||||
|
||||
let (bar, bar_size) = pci_config.func.bars[0].expect_mem();
|
||||
let irq = pci_config.func.legacy_interrupt_line;
|
||||
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 {
|
||||
common::physmap(
|
||||
bar,
|
||||
bar_size,
|
||||
common::Prot { read: true, write: true },
|
||||
common::MemoryType::Uncacheable,
|
||||
)
|
||||
.expect("nvmed: failed to map address")
|
||||
} as usize;
|
||||
let address = unsafe { bar.physmap_mem("nvmed") } as usize;
|
||||
*allocated_bars.0[0].lock().unwrap() = Some(Bar {
|
||||
physical: bar,
|
||||
physical: bar_ptr,
|
||||
bar_size,
|
||||
ptr: NonNull::new(address as *mut u8).expect("Physmapping BAR gave nullptr"),
|
||||
});
|
||||
|
||||
@@ -41,4 +41,18 @@ impl PciBar {
|
||||
PciBar::None => panic!("expected BAR to exist"),
|
||||
}
|
||||
}
|
||||
|
||||
pub unsafe fn physmap_mem(&self, driver: &str) -> *mut () {
|
||||
let (bar, bar_size) = self.expect_mem();
|
||||
unsafe {
|
||||
common::physmap(
|
||||
bar,
|
||||
bar_size,
|
||||
common::Prot::RW,
|
||||
// FIXME once the kernel supports this use write-through for prefetchable BAR
|
||||
common::MemoryType::Uncacheable,
|
||||
)
|
||||
}
|
||||
.unwrap_or_else(|err| panic!("{driver}: failed to map BAR at {bar:016X}: {err}"))
|
||||
}
|
||||
}
|
||||
|
||||
@@ -169,12 +169,10 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File {
|
||||
let pba_base = capability.pba_base_pointer(pci_config.func.bars);
|
||||
|
||||
let bir = capability.table_bir() as usize;
|
||||
let (bar_ptr, bar_size) = pci_config.func.bars[bir].expect_mem();
|
||||
let bar = &pci_config.func.bars[bir];
|
||||
let (bar_ptr, bar_size) = bar.expect_mem();
|
||||
|
||||
let address = unsafe {
|
||||
common::physmap(bar_ptr, bar_size, common::Prot::RW, common::MemoryType::Uncacheable)
|
||||
.expect("rtl8139d: failed to map address") as usize
|
||||
};
|
||||
let address = unsafe { bar.physmap_mem("rtl8139d") } as usize;
|
||||
|
||||
if !(bar_ptr as u64..bar_ptr as u64 + bar_size as u64).contains(&(table_base as u64 + table_min_length as u64)) {
|
||||
panic!("Table {:#x}{:#x} outside of BAR {:#x}:{:#x}", table_base, table_base + table_min_length as usize, bar_ptr, bar_ptr + bar_size);
|
||||
|
||||
@@ -167,12 +167,10 @@ fn get_int_method(pcid_handle: &mut PcidServerHandle) -> File {
|
||||
let pba_base = capability.pba_base_pointer(pci_config.func.bars);
|
||||
|
||||
let bir = capability.table_bir() as usize;
|
||||
let (bar_ptr, bar_size) = pci_config.func.bars[bir].expect_mem();
|
||||
let bar = &pci_config.func.bars[bir];
|
||||
let (bar_ptr, bar_size) = bar.expect_mem();
|
||||
|
||||
let address = unsafe {
|
||||
common::physmap(bar_ptr, bar_size, common::Prot::RW, common::MemoryType::Uncacheable)
|
||||
.expect("rtl8168d: failed to map address") as usize
|
||||
};
|
||||
let address = unsafe { bar.physmap_mem("rtl8168d") } as usize;
|
||||
|
||||
if !(bar_ptr as u64..bar_ptr as u64 + bar_size as u64).contains(&(table_base as u64 + table_min_length as u64)) {
|
||||
panic!("Table {:#x}{:#x} outside of BAR {:#x}:{:#x}", table_base, table_base + table_min_length as usize, bar_ptr, bar_ptr + bar_size);
|
||||
|
||||
+4
-3
@@ -196,11 +196,12 @@ fn main() {
|
||||
|
||||
let bar0 = pci_config.func.bars[0].expect_port();
|
||||
|
||||
let (bar1, _) = pci_config.func.bars[1].expect_mem();
|
||||
let bar1 = &pci_config.func.bars[1];
|
||||
let (bar1_ptr, _) = bar1.expect_mem();
|
||||
|
||||
let irq = pci_config.func.legacy_interrupt_line.expect("vboxd: no legacy interrupts supported");
|
||||
|
||||
print!("{}", format!(" + VirtualBox {} on: {:X}, {:X}, IRQ {}\n", name, bar0, bar1, irq));
|
||||
print!("{}", format!(" + VirtualBox {} on: {:X}, {:X}, IRQ {}\n", name, bar0, bar1_ptr, irq));
|
||||
|
||||
// Daemonize
|
||||
redox_daemon::Daemon::new(move |daemon| {
|
||||
@@ -224,7 +225,7 @@ fn main() {
|
||||
let mut irq_file = irq.irq_handle("vboxd");
|
||||
|
||||
let mut port = Pio::<u32>::new(bar0 as u16);
|
||||
let address = unsafe { common::physmap(bar1, 4096, common::Prot::RW, common::MemoryType::Uncacheable).expect("vboxd: failed to map address") };
|
||||
let address = unsafe { bar1.physmap_mem("vboxd") };
|
||||
{
|
||||
let vmmdev = unsafe { &mut *(address as *mut VboxVmmDev) };
|
||||
|
||||
|
||||
@@ -27,16 +27,10 @@ pub fn enable_msix(pcid_handle: &mut PcidServerHandle) -> Result<File, Error> {
|
||||
let pba_base = capability.pba_base_pointer(pci_config.func.bars);
|
||||
|
||||
let bir = capability.table_bir() as usize;
|
||||
let (bar_ptr, bar_size) = pci_config.func.bars[bir].expect_mem();
|
||||
let bar = &pci_config.func.bars[bir];
|
||||
let (bar_ptr, bar_size) = bar.expect_mem();
|
||||
|
||||
let address = unsafe {
|
||||
common::physmap(
|
||||
bar_ptr,
|
||||
bar_size,
|
||||
common::Prot::RW,
|
||||
common::MemoryType::Uncacheable,
|
||||
)? as usize
|
||||
};
|
||||
let address = unsafe { bar.physmap_mem("virtio-core") } as usize;
|
||||
|
||||
// Ensure that the table and PBA are be within the BAR.
|
||||
{
|
||||
|
||||
+3
-5
@@ -232,12 +232,10 @@ fn daemon(daemon: redox_daemon::Daemon) -> ! {
|
||||
let _logger_ref = setup_logging(&name);
|
||||
|
||||
log::debug!("XHCI PCI CONFIG: {:?}", pci_config);
|
||||
let (bar_ptr, bar_size) = pci_config.func.bars[0].expect_mem();
|
||||
let bar = &pci_config.func.bars[0];
|
||||
let (bar_ptr, _) = bar.expect_mem();
|
||||
|
||||
let address = unsafe {
|
||||
common::physmap(bar_ptr, bar_size, common::Prot::RW, common::MemoryType::Uncacheable)
|
||||
.expect("xhcid: failed to map address") as usize
|
||||
};
|
||||
let address = unsafe { bar.physmap_mem("xhcid") } as usize;
|
||||
|
||||
let (mut irq_file, interrupt_method) = get_int_method(&mut pcid_handle, address);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user