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    /// Returns `true` if the driver believes the hardware is present.
83    ///
84    /// The default returns `true` (assume present : let `init()` decide).
85    /// Override to `false` for software-backed buses (GPIO, SPI, …) that
86    /// cannot auto-detect their hardware without platform configuration.
87    fn probe(&self) -> bool {
88        true
89    }
90    /// Performs the init operation.
91    fn init(&mut self, base: usize) -> Result<(), BusError>;
92    /// Performs the shutdown operation.
93    fn shutdown(&mut self) -> Result<(), BusError>;
94    /// Performs the suspend operation.
95    fn suspend(&mut self) -> Result<(), BusError> {
96        Ok(())
97    }
98    /// Performs the resume operation.
99    fn resume(&mut self) -> Result<(), BusError> {
100        Ok(())
101    }
102    /// Reads reg.
103    fn read_reg(&self, offset: usize) -> Result<u32, BusError>;
104    /// Writes reg.
105    fn write_reg(&mut self, offset: usize, value: u32) -> Result<(), BusError>;
106    /// Performs the error count operation.
107    fn error_count(&self) -> u64 {
108        0
109    }
110    /// Performs the children operation.
111    fn children(&self) -> Vec<BusChild> {
112        Vec::new()
113    }
114    /// Handles irq.
115    fn handle_irq(&mut self) -> bool {
116        false
117    }
118}