Skip to main content

strat9_bus_drivers/
lib.rs

1#![no_std]
2#![feature(alloc_error_handler)]
3#![allow(unused_imports)]
4#![allow(unused_variables)]
5#![allow(dead_code)]
6
7extern crate alloc;
8
9pub mod mmio;
10pub mod probe;
11pub mod registry; // The list of bus drivers is here
12pub mod scheme;
13
14pub mod arm_cci;
15pub mod arm_integrator_lm;
16pub mod brcmstb_gisb;
17pub mod bt1_apb;
18pub mod bt1_axi;
19pub mod da8xx_mstpri;
20pub mod hisi_lpc;
21pub mod imx_aipstz;
22pub mod imx_weim;
23pub mod intel_ixp4xx_eb;
24pub mod mips_cdmm;
25pub mod moxtet;
26pub mod mvebu_mbus;
27pub mod omap_l3_noc;
28pub mod omap_l3_smx;
29pub mod omap_ocp2scp;
30pub mod qcom_ebi2;
31pub mod qcom_ssc_block_bus;
32pub mod simple_pm_bus;
33pub mod stm32_etzpc;
34pub mod stm32_firewall;
35pub mod stm32_rifsc;
36pub mod sun50i_de2;
37pub mod sunxi_rsb;
38pub mod tegra_aconnect;
39pub mod tegra_gmi;
40pub mod ti_pwmss;
41pub mod ti_sysc;
42pub mod ts_nbus;
43pub mod uniphier_system_bus;
44pub mod vexpress_config;
45
46use alloc::{string::String, vec::Vec};
47
48#[derive(Debug, Clone, Copy, PartialEq, Eq)]
49pub enum BusError {
50    InitFailed,
51    Timeout,
52    InvalidAddress,
53    PermissionDenied,
54    NotSupported,
55    IoError,
56    InvalidArgument,
57    DeviceNotFound,
58    BusFault,
59    SlaveError,
60    ProtocolError,
61}
62
63#[derive(Debug, Clone, Copy, PartialEq, Eq)]
64pub enum PowerState {
65    On,
66    Suspended,
67    Off,
68}
69
70#[derive(Debug, Clone)]
71pub struct BusChild {
72    pub name: String,
73    pub base_addr: u64,
74    pub size: u64,
75}
76
77pub trait BusDriver: Send + Sync {
78    /// Performs the name operation.
79    fn name(&self) -> &str;
80    /// Performs the compatible operation.
81    fn compatible(&self) -> &[&str] {
82        &[]
83    }
84    /// Returns the optional [`FirewallController`] capability, if any.
85    ///
86    /// Drivers managing hardware isolation (STM32 ETZPC/RIFSC) override
87    /// this to return `Some(self)`, which makes the scheme server publish
88    /// the `/bus/<driver>/firewall/...` paths. The default returns `None`:
89    /// no firewall capability.
90    fn as_firewall(&self) -> Option<&dyn stm32_firewall::FirewallController> {
91        None
92    }
93    /// Returns `true` if the driver believes the hardware is present.
94    ///
95    /// The default returns `true` (assume present : let `init()` decide).
96    /// Override to `false` for software-backed buses (GPIO, SPI, …) that
97    /// cannot auto-detect their hardware without platform configuration.
98    fn probe(&self) -> bool {
99        true
100    }
101    /// Performs the init operation.
102    fn init(&mut self, base: usize) -> Result<(), BusError>;
103    /// Performs the shutdown operation.
104    fn shutdown(&mut self) -> Result<(), BusError>;
105    /// Performs the suspend operation.
106    fn suspend(&mut self) -> Result<(), BusError> {
107        Ok(())
108    }
109    /// Performs the resume operation.
110    fn resume(&mut self) -> Result<(), BusError> {
111        Ok(())
112    }
113    /// Reads reg.
114    fn read_reg(&self, offset: usize) -> Result<u32, BusError>;
115    /// Writes reg.
116    fn write_reg(&mut self, offset: usize, value: u32) -> Result<(), BusError>;
117    /// Performs the error count operation.
118    fn error_count(&self) -> u64 {
119        0
120    }
121    /// Performs the children operation.
122    fn children(&self) -> Vec<BusChild> {
123        Vec::new()
124    }
125    /// Handles irq.
126    fn handle_irq(&mut self) -> bool {
127        false
128    }
129}