-
-
Notifications
You must be signed in to change notification settings - Fork 158
Patch pci pcie #235
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Patch pci pcie #235
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,27 @@ | ||
pub mod x86_64; | ||
#[cfg(target_arch = "x86_64")] | ||
pub use self::x86_64::pci::pci::X86_64PciArch as PciArch; | ||
#[cfg(target_arch = "x86_64")] | ||
pub use self::x86_64::*; //公开x86_64架构下的函数,使外界接口统一 | ||
use crate::driver::pci::pci::{BusDeviceFunction, PciError, PciRoot, SegmentGroupNumber}; | ||
/// TraitPciArch Pci架构相关函数,任何架构都应独立实现trait里的函数 | ||
pub trait TraitPciArch { | ||
/// @brief 读取寄存器值,x86_64架构通过读取两个特定io端口实现 | ||
/// @param bus_device_function 设备的唯一标识符 | ||
/// @param offset 寄存器偏移值 | ||
/// @return 读取到的值 | ||
fn read_config(bus_device_function: &BusDeviceFunction, offset: u8) -> u32; | ||
/// @brief 写入寄存器值,x86_64架构通过读取两个特定io端口实现 | ||
/// @param bus_device_function 设备的唯一标识符 | ||
/// @param offset 寄存器偏移值 | ||
/// @param data 要写入的值 | ||
fn write_config(bus_device_function: &BusDeviceFunction, offset: u8, data: u32); | ||
/// @brief PCI域地址到存储器域地址的转换,x86_64架构为一一对应 | ||
/// @param address PCI域地址 | ||
/// @return Result<usize, PciError> 转换结果或出错原因 | ||
fn address_pci_to_address_memory(address: usize) -> Result<usize, PciError>; | ||
/// @brief 获取Segement的root地址,x86_64架构为acpi mcfg表中读取 | ||
/// @param segement 组id | ||
/// @return Result<PciRoot, PciError> 转换结果或出错原因 | ||
fn ecam_root(segement: SegmentGroupNumber) -> Result<PciRoot, PciError>; | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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 @@ | ||
pub mod pci; |
This file contains hidden or 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,70 @@ | ||
use crate::arch::TraitPciArch; | ||
use crate::driver::acpi::acpi::mcfg_find_segment; | ||
use crate::driver::pci::pci::{ | ||
BusDeviceFunction, PciError, PciRoot, SegmentGroupNumber, PORT_PCI_CONFIG_ADDRESS, | ||
PORT_PCI_CONFIG_DATA, | ||
}; | ||
use crate::include::bindings::bindings::{ | ||
acpi_get_MCFG, acpi_iter_SDT, acpi_system_description_table_header_t, io_in32, io_out32, | ||
}; | ||
|
||
use core::ffi::c_void; | ||
use core::ptr::NonNull; | ||
pub struct X86_64PciArch {} | ||
impl TraitPciArch for X86_64PciArch { | ||
fn read_config(bus_device_function: &BusDeviceFunction, offset: u8) -> u32 { | ||
// 构造pci配置空间地址 | ||
let address = ((bus_device_function.bus as u32) << 16) | ||
| ((bus_device_function.device as u32) << 11) | ||
| ((bus_device_function.function as u32 & 7) << 8) | ||
| (offset & 0xfc) as u32 | ||
| (0x80000000); | ||
let ret = unsafe { | ||
io_out32(PORT_PCI_CONFIG_ADDRESS, address); | ||
let temp = io_in32(PORT_PCI_CONFIG_DATA); | ||
temp | ||
}; | ||
return ret; | ||
} | ||
|
||
fn write_config(bus_device_function: &BusDeviceFunction, offset: u8, data: u32) { | ||
let address = ((bus_device_function.bus as u32) << 16) | ||
| ((bus_device_function.device as u32) << 11) | ||
| ((bus_device_function.function as u32 & 7) << 8) | ||
| (offset & 0xfc) as u32 | ||
| (0x80000000); | ||
unsafe { | ||
io_out32(PORT_PCI_CONFIG_ADDRESS, address); | ||
// 写入数据 | ||
io_out32(PORT_PCI_CONFIG_DATA, data); | ||
} | ||
} | ||
|
||
fn address_pci_to_address_memory(address: usize) -> Result<usize, PciError> { | ||
Ok(address) | ||
} | ||
|
||
fn ecam_root(segement: SegmentGroupNumber) -> Result<PciRoot, PciError> { | ||
let mut data: usize = 0; | ||
let data_point = &mut data; | ||
unsafe { | ||
acpi_iter_SDT(Some(acpi_get_MCFG), data_point as *mut usize as *mut c_void); | ||
}; | ||
//kdebug!("{}",data); | ||
//loop{} | ||
let head = NonNull::new(data as *mut acpi_system_description_table_header_t).unwrap(); | ||
let outcome = unsafe { mcfg_find_segment(head).as_ref() }; | ||
for segmentgroupconfiguration in outcome { | ||
if segmentgroupconfiguration.segement_group_number == segement { | ||
return Ok(PciRoot { | ||
physical_address_base: segmentgroupconfiguration.base_address, | ||
mmio_base: None, | ||
segement_group_number: segement, | ||
bus_begin: segmentgroupconfiguration.bus_begin, | ||
bus_end: segmentgroupconfiguration.bus_end, | ||
}); | ||
} | ||
} | ||
return Err(PciError::SegmentNotFound); | ||
} | ||
} |
Empty file.
Empty file.
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,27 @@ | ||
use crate::driver::pci::pci::SegmentGroupNumber; | ||
use crate::include::bindings::bindings::acpi_system_description_table_header_t; | ||
use core::ptr::{slice_from_raw_parts_mut, NonNull}; | ||
// MCFG表中的Segement配置部分,开始位置为44+16*n | ||
#[repr(C, packed)] | ||
pub struct Segement_Configuration_Space { | ||
pub base_address: u64, | ||
pub segement_group_number: SegmentGroupNumber, | ||
pub bus_begin: u8, | ||
pub bus_end: u8, | ||
pub reverse: u32, | ||
} | ||
|
||
/// @brief 获取Segement_Configuration_Space的数量并返回对应数量的Segement_Configuration_Space的切片指针 | ||
/// @param head acpi_system_description_table_header_t的指针 | ||
/// @return NonNull<[Segement_Configuration_Space]> | ||
pub fn mcfg_find_segment( | ||
head: NonNull<acpi_system_description_table_header_t>, | ||
) -> NonNull<[Segement_Configuration_Space]> { | ||
let table_length = unsafe { (*head.as_ptr()).Length }; | ||
let number_of_segments = ((table_length - 44) / 16) as u16; | ||
NonNull::new(slice_from_raw_parts_mut( | ||
(head.as_ptr() as usize + 44) as *mut _, | ||
number_of_segments as usize, | ||
)) | ||
.unwrap() | ||
} |
This file contains hidden or 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 @@ | ||
pub mod acpi; |
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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,2 +1,2 @@ | ||
pub mod device; | ||
pub mod platform; | ||
pub mod device; |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.