2022-02-12 09:25:02 +00:00
|
|
|
pub mod character_devs;
|
2022-04-25 18:39:39 +00:00
|
|
|
mod dev_vterm;
|
|
|
|
|
2022-02-28 12:48:56 +00:00
|
|
|
pub mod id;
|
2022-04-25 18:39:39 +00:00
|
|
|
pub mod pci;
|
2022-02-12 09:25:02 +00:00
|
|
|
|
2022-04-11 22:23:11 +00:00
|
|
|
pub use self::Device::*;
|
|
|
|
|
2022-03-16 14:38:47 +00:00
|
|
|
use crate::devices::dev_vterm::VTerm;
|
2022-04-11 22:23:11 +00:00
|
|
|
use character_devs::{dev_null::DevNull, dev_unicode::DevUnicode, dev_zero::DevZero};
|
|
|
|
use hashbrown::HashMap;
|
2022-08-08 17:07:43 +00:00
|
|
|
use kernel::device_interface::{BlockDevice, CharacterDevice};
|
2022-04-11 22:23:11 +00:00
|
|
|
use spin::Lazy;
|
|
|
|
|
|
|
|
pub static DEVICE_TABLE: Lazy<spin::Mutex<DeviceTable>> =
|
|
|
|
Lazy::new(|| spin::Mutex::new(DeviceTable::new()));
|
|
|
|
|
2022-02-09 13:08:40 +00:00
|
|
|
// FIXME: This is a hack to hold a device.
|
2022-02-12 09:25:02 +00:00
|
|
|
// #[derive(Debug)]
|
2022-02-09 13:08:40 +00:00
|
|
|
pub enum Device {
|
2022-08-08 17:07:43 +00:00
|
|
|
Block(Box<dyn BlockDevice>),
|
2022-02-12 09:25:02 +00:00
|
|
|
Character(Box<dyn CharacterDevice>),
|
2022-04-11 20:51:54 +00:00
|
|
|
Vterm(Box<VTerm>),
|
2022-02-09 13:08:40 +00:00
|
|
|
}
|
2022-04-11 22:23:11 +00:00
|
|
|
|
2022-02-09 13:08:40 +00:00
|
|
|
unsafe impl Sync for Device {}
|
|
|
|
unsafe impl Send for Device {}
|
|
|
|
|
|
|
|
pub struct DeviceTable {
|
|
|
|
pub devices: HashMap<String, Device>,
|
|
|
|
}
|
2022-04-11 22:23:11 +00:00
|
|
|
|
2022-02-09 13:08:40 +00:00
|
|
|
impl DeviceTable {
|
|
|
|
pub fn new() -> Self {
|
2022-04-11 22:23:11 +00:00
|
|
|
DeviceTable {
|
|
|
|
devices: [
|
|
|
|
("null", Character(Box::new(DevNull))),
|
|
|
|
("zero", Character(Box::new(DevZero))),
|
|
|
|
(
|
|
|
|
"unicode",
|
|
|
|
Character(Box::new(DevUnicode {
|
|
|
|
next_write_char: 0x00 as char,
|
|
|
|
next_read_char: 0x00 as char,
|
|
|
|
})),
|
|
|
|
),
|
|
|
|
("kvterm", Vterm(Box::new(VTerm::new()))),
|
|
|
|
]
|
|
|
|
.into_iter()
|
|
|
|
.map(|(k, v)| (k.to_string(), v))
|
|
|
|
.collect(),
|
|
|
|
}
|
2022-02-09 13:08:40 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-04-11 21:07:01 +00:00
|
|
|
impl Default for DeviceTable {
|
|
|
|
fn default() -> Self {
|
|
|
|
Self::new()
|
|
|
|
}
|
|
|
|
}
|