1*2eab6dd7S曾俊 use log::{error, warn}; 2*2eab6dd7S曾俊 3370472f7SLoGin use crate::mm::PhysAddr; 4370472f7SLoGin 5370472f7SLoGin use super::{ 6370472f7SLoGin pci::{PciCam, SegmentGroupNumber}, 7370472f7SLoGin root::{pci_root_manager, PciRoot}, 8370472f7SLoGin }; 9370472f7SLoGin 10370472f7SLoGin #[inline(always)] 11370472f7SLoGin pub fn pci_ecam_root_info_manager() -> &'static EcamRootInfoManager { 12370472f7SLoGin &EcamRootInfoManager 13370472f7SLoGin } 14370472f7SLoGin 15370472f7SLoGin /// Ecam pci root info 16370472f7SLoGin #[derive(Clone, Copy)] 17370472f7SLoGin pub struct EcamRootInfo { 18370472f7SLoGin pub segement_group_number: SegmentGroupNumber, 19370472f7SLoGin pub bus_begin: u8, 20370472f7SLoGin pub bus_end: u8, 21370472f7SLoGin pub physical_address_base: PhysAddr, 22370472f7SLoGin } 23370472f7SLoGin 24370472f7SLoGin impl EcamRootInfo { 25370472f7SLoGin pub fn new( 26370472f7SLoGin segement_group_number: SegmentGroupNumber, 27370472f7SLoGin bus_begin: u8, 28370472f7SLoGin bus_end: u8, 29370472f7SLoGin physical_address_base: PhysAddr, 30370472f7SLoGin ) -> Self { 31370472f7SLoGin Self { 32370472f7SLoGin segement_group_number, 33370472f7SLoGin bus_begin, 34370472f7SLoGin bus_end, 35370472f7SLoGin physical_address_base, 36370472f7SLoGin } 37370472f7SLoGin } 38370472f7SLoGin } 39370472f7SLoGin 40370472f7SLoGin pub struct EcamRootInfoManager; 41370472f7SLoGin 42370472f7SLoGin impl EcamRootInfoManager { 43370472f7SLoGin /// # add_ecam_root_info - 向EcamRootInfoManager添加EcamRootInfo 44370472f7SLoGin /// 45370472f7SLoGin /// 将一个新的EcamRootInfo添加到EcamRootInfoManager中。 46370472f7SLoGin /// 47370472f7SLoGin /// ## 参数 48370472f7SLoGin /// 49370472f7SLoGin /// - `ecam_root_info`: EcamRootInfo - 要添加的EcamRootInfo实例 50370472f7SLoGin pub fn add_ecam_root_info(&self, ecam_root_info: EcamRootInfo) { 51370472f7SLoGin if !pci_root_manager().has_root(ecam_root_info.segement_group_number) { 52370472f7SLoGin let root = PciRoot::new( 53370472f7SLoGin ecam_root_info.segement_group_number, 54370472f7SLoGin PciCam::Ecam, 55370472f7SLoGin ecam_root_info.physical_address_base, 56370472f7SLoGin ecam_root_info.bus_begin, 57370472f7SLoGin ecam_root_info.bus_end, 58370472f7SLoGin ); 59370472f7SLoGin 60370472f7SLoGin if let Err(err) = root { 61*2eab6dd7S曾俊 error!("add_ecam_root_info(): failed to create PciRoot: {:?}", err); 62370472f7SLoGin return; 63370472f7SLoGin } 64370472f7SLoGin 65370472f7SLoGin pci_root_manager().add_pci_root(root.unwrap()); 66370472f7SLoGin } else { 67*2eab6dd7S曾俊 warn!( 68370472f7SLoGin "add_ecam_root_info(): root {} already exists", 69370472f7SLoGin ecam_root_info.segement_group_number 70370472f7SLoGin ); 71370472f7SLoGin } 72370472f7SLoGin } 73370472f7SLoGin } 74