Use map_device_memory where possible
This commit is contained in:
@@ -6,13 +6,10 @@ use spin::Mutex;
|
||||
#[cfg(feature = "acpi")]
|
||||
use crate::{
|
||||
acpi::madt::{self, Madt, MadtEntry, MadtIntSrcOverride, MadtIoApic},
|
||||
memory::{Frame, PageFlags, PhysicalAddress, RmmA, RmmArch},
|
||||
memory::{map_device_memory, PhysicalAddress},
|
||||
};
|
||||
|
||||
use crate::{
|
||||
arch::{cpuid::cpuid, interrupt::irq},
|
||||
memory::KernelMapper,
|
||||
};
|
||||
use crate::arch::{cpuid::cpuid, interrupt::irq};
|
||||
|
||||
use super::{local_apic::ApicId, pic};
|
||||
|
||||
@@ -236,21 +233,10 @@ pub fn src_overrides() -> &'static [Override] {
|
||||
}
|
||||
|
||||
#[cfg(feature = "acpi")]
|
||||
pub unsafe fn handle_ioapic(mapper: &mut KernelMapper<true>, madt_ioapic: &'static MadtIoApic) {
|
||||
pub unsafe fn handle_ioapic(madt_ioapic: &'static MadtIoApic) {
|
||||
unsafe {
|
||||
// map the I/O APIC registers
|
||||
|
||||
let frame = Frame::containing(PhysicalAddress::new(madt_ioapic.address as usize));
|
||||
|
||||
assert!(mapper.translate(RmmA::phys_to_virt(frame.base())).is_none());
|
||||
|
||||
let (virt, flush) = mapper
|
||||
.map_linearly(
|
||||
frame.base(),
|
||||
PageFlags::new().write(true).device_memory(true),
|
||||
)
|
||||
.expect("failed to map I/O APIC");
|
||||
flush.flush();
|
||||
let virt = map_device_memory(PhysicalAddress::new(madt_ioapic.address as usize), 4096);
|
||||
|
||||
let ioapic_registers = virt.data() as *const u32;
|
||||
let ioapic = IoApic::new(ioapic_registers, madt_ioapic.gsi_base);
|
||||
@@ -302,7 +288,7 @@ pub unsafe fn handle_src_override(src_override: &'static MadtIntSrcOverride) {
|
||||
}
|
||||
|
||||
#[allow(dead_code)]
|
||||
pub unsafe fn init(active_table: &mut KernelMapper<true>) {
|
||||
pub unsafe fn init() {
|
||||
unsafe {
|
||||
let bsp_apic_id = ApicId::new(u32::from(
|
||||
cpuid().get_feature_info().unwrap().initial_local_apic_id(),
|
||||
@@ -324,7 +310,7 @@ pub unsafe fn init(active_table: &mut KernelMapper<true>) {
|
||||
|
||||
for entry in madt.iter() {
|
||||
match entry {
|
||||
MadtEntry::IoApic(ioapic) => handle_ioapic(active_table, ioapic),
|
||||
MadtEntry::IoApic(ioapic) => handle_ioapic(ioapic),
|
||||
MadtEntry::IntSrcOverride(src_override) => handle_src_override(src_override),
|
||||
_ => (),
|
||||
}
|
||||
|
||||
@@ -5,13 +5,12 @@ use core::{
|
||||
use x86::msr::*;
|
||||
|
||||
use crate::{
|
||||
arch::cpuid::cpuid,
|
||||
ipi::IpiKind,
|
||||
memory::{PageFlags, PhysicalAddress},
|
||||
memory::{map_device_memory, PhysicalAddress},
|
||||
percpu::PercpuBlock,
|
||||
};
|
||||
|
||||
use crate::{arch::cpuid::cpuid, memory::KernelMapper};
|
||||
|
||||
#[derive(Clone, Copy, Debug)]
|
||||
pub struct ApicId(u32);
|
||||
|
||||
@@ -33,9 +32,9 @@ pub unsafe fn the_local_apic() -> &'static mut LocalApic {
|
||||
unsafe { &mut *LOCAL_APIC.get() }
|
||||
}
|
||||
|
||||
pub unsafe fn init(active_table: &mut KernelMapper<true>) {
|
||||
pub unsafe fn init() {
|
||||
unsafe {
|
||||
the_local_apic().init(active_table);
|
||||
the_local_apic().init();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -52,7 +51,7 @@ pub struct LocalApic {
|
||||
}
|
||||
|
||||
impl LocalApic {
|
||||
unsafe fn init(&mut self, mapper: &mut KernelMapper<true>) {
|
||||
unsafe fn init(&mut self) {
|
||||
unsafe {
|
||||
let physaddr = PhysicalAddress::new(rdmsr(IA32_APIC_BASE) as usize & 0xFFFF_0000);
|
||||
|
||||
@@ -62,11 +61,7 @@ impl LocalApic {
|
||||
|
||||
if !self.x2 {
|
||||
debug!("Detected xAPIC at {:#x}", physaddr.data());
|
||||
let (virt, flush) = mapper
|
||||
.map_linearly(physaddr, PageFlags::new().write(true))
|
||||
.expect("failed to map local APIC memory");
|
||||
flush.flush();
|
||||
self.address = virt.data();
|
||||
self.address = map_device_memory(physaddr, 4096).data();
|
||||
} else {
|
||||
debug!("Detected x2APIC");
|
||||
}
|
||||
|
||||
@@ -1,4 +1,3 @@
|
||||
use crate::memory::KernelMapper;
|
||||
use core::cell::Cell;
|
||||
|
||||
pub mod cpu;
|
||||
@@ -18,7 +17,7 @@ pub mod tsc;
|
||||
pub unsafe fn init() {
|
||||
unsafe {
|
||||
pic::init();
|
||||
local_apic::init(&mut KernelMapper::lock_rw());
|
||||
local_apic::init();
|
||||
|
||||
// Run here for the side effect of printing if KVM was used to avoid interleaved logs.
|
||||
tsc::get_kvm_support();
|
||||
|
||||
@@ -1,5 +1,6 @@
|
||||
use crate::{
|
||||
devices::{serial::SerialKind, uart_16550::SerialPort},
|
||||
memory::map_device_memory,
|
||||
syscall::io::{Mmio, Pio},
|
||||
};
|
||||
use spin::Mutex;
|
||||
@@ -32,21 +33,12 @@ pub unsafe fn init() {
|
||||
return;
|
||||
}
|
||||
|
||||
let virt = {
|
||||
use crate::memory::{KernelMapper, PageFlags, PhysicalAddress};
|
||||
|
||||
// TODO: Make this configurable
|
||||
let phys = PhysicalAddress::new(0xFE032000);
|
||||
|
||||
let mut mapper = KernelMapper::lock_rw();
|
||||
let flags = PageFlags::new().write(true).execute(false);
|
||||
let (virt, flush) = unsafe {
|
||||
mapper
|
||||
.map_linearly(phys, flags)
|
||||
.expect("failed to map frame")
|
||||
};
|
||||
flush.flush();
|
||||
virt
|
||||
let virt = unsafe {
|
||||
map_device_memory(
|
||||
// TODO: Make this configurable
|
||||
crate::memory::PhysicalAddress::new(0xFE032000),
|
||||
4,
|
||||
)
|
||||
};
|
||||
|
||||
let lpss = unsafe { SerialPort::<Mmio<u32>>::new(virt.data()) };
|
||||
|
||||
Reference in New Issue
Block a user