good_os_framework/drivers/
mod.rs

1use crate::memory::FRAME_ALLOCATOR;
2use x86_64::structures::paging::{FrameDeallocator, PhysFrame};
3use x86_64::{PhysAddr, VirtAddr};
4
5pub mod display;
6pub mod fpu;
7pub mod hpet;
8pub mod keyboard;
9pub mod mouse;
10pub mod nvme;
11pub mod pci;
12pub mod rtc;
13pub mod serial;
14pub mod xhci;
15
16pub fn init() {
17    hpet::init();
18    mouse::init();
19}
20
21/// Allocate memory for the DMA drivers, `cnt` is the number of physical memory frames you need.
22pub fn alloc_for_dma(cnt: usize) -> (PhysAddr, VirtAddr) {
23    let phys = FRAME_ALLOCATOR.lock().allocate_frames(cnt).unwrap();
24    let phys = PhysAddr::new(phys);
25    let virt = crate::memory::convert_physical_to_virtual(phys);
26    (phys, virt)
27}
28
29/// deallocates the physical memory.
30pub fn dealloc_for_dma(virt_addr: VirtAddr, _cnt: usize) {
31    let phys = crate::memory::convert_virtual_to_physical(virt_addr);
32    unsafe {
33        FRAME_ALLOCATOR
34            .lock()
35            .deallocate_frame(PhysFrame::containing_address(phys));
36    }
37}