1*370472f7SLoGin use crate::mm::PhysAddr; 2*370472f7SLoGin 3*370472f7SLoGin use super::{ 4*370472f7SLoGin pci::{PciCam, SegmentGroupNumber}, 5*370472f7SLoGin root::{pci_root_manager, PciRoot}, 6*370472f7SLoGin }; 7*370472f7SLoGin 8*370472f7SLoGin #[inline(always)] 9*370472f7SLoGin pub fn pci_ecam_root_info_manager() -> &'static EcamRootInfoManager { 10*370472f7SLoGin &EcamRootInfoManager 11*370472f7SLoGin } 12*370472f7SLoGin 13*370472f7SLoGin /// Ecam pci root info 14*370472f7SLoGin #[derive(Clone, Copy)] 15*370472f7SLoGin pub struct EcamRootInfo { 16*370472f7SLoGin pub segement_group_number: SegmentGroupNumber, 17*370472f7SLoGin pub bus_begin: u8, 18*370472f7SLoGin pub bus_end: u8, 19*370472f7SLoGin pub physical_address_base: PhysAddr, 20*370472f7SLoGin } 21*370472f7SLoGin 22*370472f7SLoGin impl EcamRootInfo { 23*370472f7SLoGin pub fn new( 24*370472f7SLoGin segement_group_number: SegmentGroupNumber, 25*370472f7SLoGin bus_begin: u8, 26*370472f7SLoGin bus_end: u8, 27*370472f7SLoGin physical_address_base: PhysAddr, 28*370472f7SLoGin ) -> Self { 29*370472f7SLoGin Self { 30*370472f7SLoGin segement_group_number, 31*370472f7SLoGin bus_begin, 32*370472f7SLoGin bus_end, 33*370472f7SLoGin physical_address_base, 34*370472f7SLoGin } 35*370472f7SLoGin } 36*370472f7SLoGin } 37*370472f7SLoGin 38*370472f7SLoGin pub struct EcamRootInfoManager; 39*370472f7SLoGin 40*370472f7SLoGin impl EcamRootInfoManager { 41*370472f7SLoGin /// # add_ecam_root_info - 向EcamRootInfoManager添加EcamRootInfo 42*370472f7SLoGin /// 43*370472f7SLoGin /// 将一个新的EcamRootInfo添加到EcamRootInfoManager中。 44*370472f7SLoGin /// 45*370472f7SLoGin /// ## 参数 46*370472f7SLoGin /// 47*370472f7SLoGin /// - `ecam_root_info`: EcamRootInfo - 要添加的EcamRootInfo实例 48*370472f7SLoGin pub fn add_ecam_root_info(&self, ecam_root_info: EcamRootInfo) { 49*370472f7SLoGin if !pci_root_manager().has_root(ecam_root_info.segement_group_number) { 50*370472f7SLoGin let root = PciRoot::new( 51*370472f7SLoGin ecam_root_info.segement_group_number, 52*370472f7SLoGin PciCam::Ecam, 53*370472f7SLoGin ecam_root_info.physical_address_base, 54*370472f7SLoGin ecam_root_info.bus_begin, 55*370472f7SLoGin ecam_root_info.bus_end, 56*370472f7SLoGin ); 57*370472f7SLoGin 58*370472f7SLoGin if let Err(err) = root { 59*370472f7SLoGin kerror!("add_ecam_root_info(): failed to create PciRoot: {:?}", err); 60*370472f7SLoGin return; 61*370472f7SLoGin } 62*370472f7SLoGin 63*370472f7SLoGin pci_root_manager().add_pci_root(root.unwrap()); 64*370472f7SLoGin } else { 65*370472f7SLoGin kwarn!( 66*370472f7SLoGin "add_ecam_root_info(): root {} already exists", 67*370472f7SLoGin ecam_root_info.segement_group_number 68*370472f7SLoGin ); 69*370472f7SLoGin } 70*370472f7SLoGin } 71*370472f7SLoGin } 72