-
-
Notifications
You must be signed in to change notification settings - Fork 141
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
pci: 使得riscv能够正常扫描pci设备.
- Loading branch information
Showing
16 changed files
with
490 additions
and
214 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
use fdt::{node::FdtNode, Fdt}; | ||
use system_error::SystemError; | ||
|
||
use crate::{ | ||
driver::{ | ||
open_firmware::fdt::open_firmware_fdt_driver, | ||
pci::ecam::{pci_ecam_root_info_manager, EcamRootInfo}, | ||
}, | ||
kdebug, | ||
mm::PhysAddr, | ||
}; | ||
|
||
// static PCI_ECAM_HOST | ||
|
||
pub(super) fn pci_host_ecam_driver_init(fdt: &Fdt<'_>) -> Result<(), SystemError> { | ||
let do_check = |node: FdtNode| -> Result<(), SystemError> { | ||
let reg = node | ||
.reg() | ||
.ok_or(SystemError::EINVAL)? | ||
.next() | ||
.ok_or(SystemError::EINVAL)?; | ||
let paddr = reg.starting_address as usize; | ||
let size = reg.size.unwrap_or(0); | ||
let bus_range: &[u8] = node.property("bus-range").ok_or(SystemError::EINVAL)?.value; | ||
|
||
let (bus_begin, bus_end) = match bus_range.len() { | ||
8 => ( | ||
u32::from_be_bytes(bus_range[0..4].try_into().unwrap()), | ||
u32::from_be_bytes(bus_range[4..8].try_into().unwrap()), | ||
), | ||
_ => panic!("Unexpected bus-range length"), | ||
}; | ||
|
||
let segement_group_number: &[u8] = node | ||
.property("linux,pci-domain") | ||
.ok_or(SystemError::EINVAL)? | ||
.value; | ||
|
||
let segement_group_number = match segement_group_number.len() { | ||
4 => u32::from_be_bytes(segement_group_number[0..4].try_into().unwrap()), | ||
_ => panic!("Unexpected linux,pci-domain length"), | ||
}; | ||
|
||
kdebug!( | ||
"pci_host_ecam_driver_init(): {} paddr: {:#x} size: {:#x} bus-range: {}-{} segement_group_number: {}", | ||
node.name, | ||
paddr, | ||
size, | ||
bus_begin, | ||
bus_end, | ||
segement_group_number | ||
); | ||
|
||
pci_ecam_root_info_manager().add_ecam_root_info(EcamRootInfo::new( | ||
segement_group_number.try_into().unwrap(), | ||
bus_begin as u8, | ||
bus_end as u8, | ||
PhysAddr::new(paddr), | ||
)); | ||
|
||
Ok(()) | ||
}; | ||
|
||
for node in open_firmware_fdt_driver().find_node_by_compatible(&fdt, "pci-host-ecam-generic") { | ||
if let Err(err) = do_check(node) { | ||
kdebug!( | ||
"pci_host_ecam_driver_init(): check {} error: {:?}", | ||
node.name, | ||
err | ||
); | ||
} | ||
} | ||
|
||
return Ok(()); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
use crate::mm::PhysAddr; | ||
|
||
use super::{ | ||
pci::{PciCam, SegmentGroupNumber}, | ||
root::{pci_root_manager, PciRoot}, | ||
}; | ||
|
||
#[inline(always)] | ||
pub fn pci_ecam_root_info_manager() -> &'static EcamRootInfoManager { | ||
&EcamRootInfoManager | ||
} | ||
|
||
/// Ecam pci root info | ||
#[derive(Clone, Copy)] | ||
pub struct EcamRootInfo { | ||
pub segement_group_number: SegmentGroupNumber, | ||
pub bus_begin: u8, | ||
pub bus_end: u8, | ||
pub physical_address_base: PhysAddr, | ||
} | ||
|
||
impl EcamRootInfo { | ||
pub fn new( | ||
segement_group_number: SegmentGroupNumber, | ||
bus_begin: u8, | ||
bus_end: u8, | ||
physical_address_base: PhysAddr, | ||
) -> Self { | ||
Self { | ||
segement_group_number, | ||
bus_begin, | ||
bus_end, | ||
physical_address_base, | ||
} | ||
} | ||
} | ||
|
||
pub struct EcamRootInfoManager; | ||
|
||
impl EcamRootInfoManager { | ||
/// # add_ecam_root_info - 向EcamRootInfoManager添加EcamRootInfo | ||
/// | ||
/// 将一个新的EcamRootInfo添加到EcamRootInfoManager中。 | ||
/// | ||
/// ## 参数 | ||
/// | ||
/// - `ecam_root_info`: EcamRootInfo - 要添加的EcamRootInfo实例 | ||
pub fn add_ecam_root_info(&self, ecam_root_info: EcamRootInfo) { | ||
if !pci_root_manager().has_root(ecam_root_info.segement_group_number) { | ||
let root = PciRoot::new( | ||
ecam_root_info.segement_group_number, | ||
PciCam::Ecam, | ||
ecam_root_info.physical_address_base, | ||
ecam_root_info.bus_begin, | ||
ecam_root_info.bus_end, | ||
); | ||
|
||
if let Err(err) = root { | ||
kerror!("add_ecam_root_info(): failed to create PciRoot: {:?}", err); | ||
return; | ||
} | ||
|
||
pci_root_manager().add_pci_root(root.unwrap()); | ||
} else { | ||
kwarn!( | ||
"add_ecam_root_info(): root {} already exists", | ||
ecam_root_info.segement_group_number | ||
); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,5 @@ | ||
pub mod ecam; | ||
#[allow(clippy::module_inception)] | ||
pub mod pci; | ||
pub mod pci_irq; | ||
pub mod root; |
Oops, something went wrong.