76b75d80b4
Consolidate ~30 absorbed base patches into surviving carriers. Add new init service files, driver sources, and network/storage modules for the base recipe. Move absorbed patches to local/patches/base/absorbed/. Ultraworked with [Sisyphus](https://github.com/code-yeongyu/oh-my-openagent) Co-authored-by: Sisyphus <clio-agent@sisyphuslabs.ai>
226 lines
6.8 KiB
Diff
226 lines
6.8 KiB
Diff
--- a/drivers/inputd/src/main.rs
|
|
+++ b/drivers/inputd/src/main.rs
|
|
@@ -13,7 +13,7 @@
|
|
|
|
use core::mem::size_of;
|
|
use std::borrow::Cow;
|
|
-use std::collections::BTreeSet;
|
|
+use std::collections::{BTreeMap, BTreeSet};
|
|
use std::mem::transmute;
|
|
use std::ops::ControlFlow;
|
|
use std::sync::atomic::{AtomicUsize, Ordering};
|
|
@@ -37,6 +37,9 @@
|
|
|
|
enum Handle {
|
|
Producer,
|
|
+ NamedProducer {
|
|
+ name: String,
|
|
+ },
|
|
Consumer {
|
|
events: EventFlags,
|
|
pending: Vec<u8>,
|
|
@@ -60,8 +63,10 @@
|
|
|
|
struct InputScheme {
|
|
handles: HandleMap<Handle>,
|
|
+ devices: BTreeMap<String, u32>,
|
|
|
|
next_vt_id: AtomicUsize,
|
|
+ next_device_id: AtomicUsize,
|
|
|
|
display: Option<String>,
|
|
vts: BTreeSet<usize>,
|
|
@@ -74,12 +79,29 @@
|
|
has_new_events: bool,
|
|
}
|
|
|
|
+const RESERVED_DEVICE_NAMES: [&str; 7] = [
|
|
+ "producer",
|
|
+ "consumer",
|
|
+ "consumer_bootlog",
|
|
+ "events",
|
|
+ "handle",
|
|
+ "handle_early",
|
|
+ "control",
|
|
+];
|
|
+
|
|
+enum ProducerKind {
|
|
+ Legacy,
|
|
+ Named(String),
|
|
+}
|
|
+
|
|
impl InputScheme {
|
|
fn new() -> Self {
|
|
Self {
|
|
handles: HandleMap::new(),
|
|
+ devices: BTreeMap::new(),
|
|
|
|
next_vt_id: AtomicUsize::new(2), // VT 1 is reserved for the bootlog
|
|
+ next_device_id: AtomicUsize::new(0),
|
|
|
|
display: None,
|
|
vts: BTreeSet::new(),
|
|
@@ -91,6 +113,46 @@
|
|
rshift: false,
|
|
has_new_events: false,
|
|
}
|
|
+ }
|
|
+
|
|
+ fn register_named_producer(&mut self, name: &str) -> syscall::Result<Handle> {
|
|
+ if name.is_empty() || RESERVED_DEVICE_NAMES.contains(&name) {
|
|
+ return Err(SysError::new(EINVAL));
|
|
+ }
|
|
+
|
|
+ if self.devices.contains_key(name) {
|
|
+ return Err(SysError::new(EEXIST));
|
|
+ }
|
|
+
|
|
+ let device_id = self.next_device_id.fetch_add(1, Ordering::SeqCst) as u32;
|
|
+ self.devices.insert(name.to_owned(), device_id);
|
|
+ Ok(Handle::NamedProducer {
|
|
+ name: name.to_owned(),
|
|
+ })
|
|
+ }
|
|
+
|
|
+ fn route_legacy_consumer_events(&mut self, buf: &[u8]) {
|
|
+ if let Some(active_vt) = self.active_vt {
|
|
+ for handle in self.handles.values_mut() {
|
|
+ match handle {
|
|
+ Handle::Consumer {
|
|
+ pending,
|
|
+ notified,
|
|
+ vt,
|
|
+ ..
|
|
+ } if *vt == active_vt => {
|
|
+ pending.extend_from_slice(buf);
|
|
+ *notified = false;
|
|
+ }
|
|
+ _ => continue,
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+ }
|
|
+
|
|
+ fn route_named_producer_events(&mut self, _name: &str, _buf: &[u8]) {
|
|
+ // DeviceConsumer routing is added in a follow-up patch. Named producers already share the
|
|
+ // legacy consumer path, so existing callers continue to receive these events.
|
|
}
|
|
|
|
fn switch_vt(&mut self, new_active: usize) {
|
|
@@ -170,7 +232,13 @@
|
|
let command = path_parts.next().ok_or(SysError::new(EINVAL))?;
|
|
|
|
let handle_ty = match command {
|
|
- "producer" => Handle::Producer,
|
|
+ "producer" => match path_parts.next() {
|
|
+ None => Handle::Producer,
|
|
+ Some(name) if !name.is_empty() && path_parts.next().is_none() => {
|
|
+ self.register_named_producer(name)?
|
|
+ }
|
|
+ _ => return Err(SysError::new(EINVAL)),
|
|
+ },
|
|
"consumer" => {
|
|
let vt = self.next_vt_id.fetch_add(1, Ordering::Relaxed);
|
|
self.vts.insert(vt);
|
|
@@ -330,7 +398,7 @@
|
|
}
|
|
}
|
|
|
|
- Handle::Producer => {
|
|
+ Handle::Producer | Handle::NamedProducer { .. } => {
|
|
log::error!("producer tried to read");
|
|
return Err(SysError::new(EINVAL));
|
|
}
|
|
@@ -352,9 +420,7 @@
|
|
) -> syscall::Result<usize> {
|
|
self.has_new_events = true;
|
|
|
|
- let handle = self.handles.get_mut(id)?;
|
|
-
|
|
- match handle {
|
|
+ let producer_kind = match self.handles.get(id)? {
|
|
Handle::Control => {
|
|
if buf.len() != size_of::<ControlEvent>() {
|
|
log::error!("control tried to write incorrectly sized command");
|
|
@@ -383,9 +449,10 @@
|
|
log::error!("display tried to write");
|
|
return Err(SysError::new(EINVAL));
|
|
}
|
|
- Handle::Producer => {}
|
|
+ Handle::Producer => ProducerKind::Legacy,
|
|
+ Handle::NamedProducer { name } => ProducerKind::Named(name.clone()),
|
|
Handle::SchemeRoot => return Err(SysError::new(EBADF)),
|
|
- }
|
|
+ };
|
|
|
|
if buf.len() == 1 && buf[0] > 0xf4 {
|
|
return Ok(1);
|
|
@@ -437,9 +504,6 @@
|
|
}
|
|
}
|
|
|
|
- let handle = self.handles.get_mut(id)?;
|
|
- assert!(matches!(handle, Handle::Producer));
|
|
-
|
|
let buf = unsafe {
|
|
core::slice::from_raw_parts(
|
|
(events.as_ptr()) as *const u8,
|
|
@@ -447,26 +511,11 @@
|
|
)
|
|
};
|
|
|
|
- if let Some(active_vt) = self.active_vt {
|
|
- for handle in self.handles.values_mut() {
|
|
- match handle {
|
|
- Handle::Consumer {
|
|
- pending,
|
|
- notified,
|
|
- vt,
|
|
- ..
|
|
- } => {
|
|
- if *vt != active_vt {
|
|
- continue;
|
|
- }
|
|
-
|
|
- pending.extend_from_slice(buf);
|
|
- *notified = false;
|
|
- }
|
|
- _ => continue,
|
|
- }
|
|
- }
|
|
- }
|
|
+ if let ProducerKind::Named(name) = &producer_kind {
|
|
+ self.route_named_producer_events(name, buf);
|
|
+ }
|
|
+
|
|
+ self.route_legacy_consumer_events(buf);
|
|
|
|
Ok(buf.len())
|
|
}
|
|
@@ -496,7 +545,7 @@
|
|
*notified = false;
|
|
Ok(EventFlags::empty())
|
|
}
|
|
- Handle::Producer | Handle::Control => {
|
|
+ Handle::Producer | Handle::NamedProducer { .. } | Handle::Control => {
|
|
log::error!("producer or control tried to use an event queue");
|
|
Err(SysError::new(EINVAL))
|
|
}
|
|
@@ -505,7 +554,15 @@
|
|
}
|
|
|
|
fn on_close(&mut self, id: usize) {
|
|
- match self.handles.remove(id).unwrap() {
|
|
+ let Some(handle) = self.handles.remove(id) else {
|
|
+ log::warn!("received close for unknown input handle {id}");
|
|
+ return;
|
|
+ };
|
|
+
|
|
+ match handle {
|
|
+ Handle::NamedProducer { name } => {
|
|
+ self.devices.remove(&name);
|
|
+ }
|
|
Handle::Consumer { vt, .. } => {
|
|
self.vts.remove(&vt);
|
|
if self.active_vt == Some(vt) {
|