xref: /DragonOS/kernel/src/arch/mod.rs (revision 9029414af2089cbe7d2d2097be2e116c09beb6dd)
1 pub mod x86_64;
2 #[cfg(target_arch = "x86_64")]
3 pub use self::x86_64::*; //公开x86_64架构下的函数,使外界接口统一
4 
5 use crate::{
6     driver::pci::pci::{BusDeviceFunction, PciAddr, PciError, PciRoot, SegmentGroupNumber},
7     mm::PhysAddr,
8 };
9 
10 /// TraitPciArch Pci架构相关函数,任何架构都应独立实现trait里的函数
11 pub trait TraitPciArch {
12     /// @brief 读取寄存器值,x86_64架构通过读取两个特定io端口实现
13     /// @param bus_device_function 设备的唯一标识符
14     /// @param offset 寄存器偏移值
15     /// @return 读取到的值
16     fn read_config(bus_device_function: &BusDeviceFunction, offset: u8) -> u32;
17     /// @brief 写入寄存器值,x86_64架构通过读取两个特定io端口实现
18     /// @param bus_device_function 设备的唯一标识符
19     /// @param offset 寄存器偏移值
20     /// @param data 要写入的值
21     fn write_config(bus_device_function: &BusDeviceFunction, offset: u8, data: u32);
22     /// @brief PCI域地址到存储器域地址的转换,x86_64架构为一一对应
23     /// @param address PCI域地址
24     /// @return usize 转换结果
25     fn address_pci_to_physical(pci_address: PciAddr) -> PhysAddr;
26     /// @brief 获取Segement的root地址,x86_64架构为acpi mcfg表中读取
27     /// @param segement 组id
28     /// @return  Result<PciRoot, PciError> 转换结果或出错原因
29     fn ecam_root(segement: SegmentGroupNumber) -> Result<PciRoot, PciError>;
30 }
31