2022-02-12 03:25:02 -06:00
|
|
|
pub mod character_devs;
|
2022-02-28 06:48:56 -06:00
|
|
|
pub mod id;
|
2022-02-12 03:25:02 -06:00
|
|
|
pub mod pci_inner;
|
|
|
|
|
2022-02-09 07:08:40 -06:00
|
|
|
use alloc::{
|
|
|
|
boxed::Box,
|
|
|
|
string::{String, ToString},
|
|
|
|
};
|
|
|
|
use hashbrown::HashMap;
|
2022-02-12 03:25:02 -06:00
|
|
|
use pci::PCIDevice;
|
2022-02-09 07:08:40 -06:00
|
|
|
|
|
|
|
use crate::character_device::CharacterDevice;
|
|
|
|
|
|
|
|
// FIXME: This is a hack to hold a device.
|
2022-02-12 03:25:02 -06:00
|
|
|
// #[derive(Debug)]
|
2022-02-09 07:08:40 -06:00
|
|
|
pub enum Device {
|
2022-02-12 03:25:02 -06:00
|
|
|
Character(Box<dyn CharacterDevice>),
|
|
|
|
Pci(PCIDevice),
|
2022-02-09 07:08:40 -06:00
|
|
|
}
|
|
|
|
unsafe impl Sync for Device {}
|
|
|
|
unsafe impl Send for Device {}
|
|
|
|
|
|
|
|
pub struct DeviceTable {
|
|
|
|
pub devices: HashMap<String, Device>,
|
|
|
|
}
|
2022-02-12 03:25:02 -06:00
|
|
|
use self::character_devs::{dev_null::DevNull, dev_unicode::DevUnicode, dev_zero::DevZero};
|
2022-02-09 07:08:40 -06:00
|
|
|
pub use self::Device::*;
|
|
|
|
impl DeviceTable {
|
|
|
|
pub fn new() -> Self {
|
|
|
|
let mut table: HashMap<String, Device> = HashMap::new();
|
2022-02-12 03:25:02 -06:00
|
|
|
table.insert("null".to_string(), Character(Box::new(DevNull)));
|
|
|
|
table.insert("zero".to_string(), Character(Box::new(DevZero)));
|
|
|
|
table.insert(
|
|
|
|
"unicode".to_string(),
|
|
|
|
Character(Box::new(DevUnicode {
|
|
|
|
next_write_char: 0x00 as char,
|
|
|
|
next_read_char: 0x00 as char,
|
|
|
|
})),
|
|
|
|
);
|
2022-02-09 07:08:40 -06:00
|
|
|
DeviceTable { devices: table }
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
lazy_static::lazy_static!(
|
2022-02-12 03:25:02 -06:00
|
|
|
pub static ref DEVICE_TABLE: spin::Mutex<DeviceTable> =
|
|
|
|
spin::Mutex::new(DeviceTable::new());
|
2022-02-09 07:08:40 -06:00
|
|
|
);
|