mirror of
https://github.com/DragonOS-Community/DragonOS.git
synced 2025-06-09 11:16:47 +00:00
把pci驱动的读取acpi mcfg的代码,调整为从新的acpi驱动来读取 (#413)
* 把pci驱动的读取acpi mcfg的代码,调整为从新的acpi驱动来读取
This commit is contained in:
parent
971462be94
commit
8b3d1688da
@ -1,17 +1,16 @@
|
|||||||
use crate::arch::TraitPciArch;
|
use crate::arch::TraitPciArch;
|
||||||
use crate::driver::acpi::old::mcfg_find_segment;
|
use crate::driver::acpi::acpi_manager;
|
||||||
use crate::driver::pci::pci::{
|
use crate::driver::pci::pci::{
|
||||||
BusDeviceFunction, PciAddr, PciError, PciRoot, SegmentGroupNumber, PORT_PCI_CONFIG_ADDRESS,
|
BusDeviceFunction, PciAddr, PciError, PciRoot, SegmentGroupNumber, PORT_PCI_CONFIG_ADDRESS,
|
||||||
PORT_PCI_CONFIG_DATA,
|
PORT_PCI_CONFIG_DATA,
|
||||||
};
|
};
|
||||||
use crate::include::bindings::bindings::{
|
use crate::include::bindings::bindings::{acpi_get_MCFG, acpi_iter_SDT, io_in32, io_out32};
|
||||||
acpi_get_MCFG, acpi_iter_SDT, acpi_system_description_table_header_t, io_in32, io_out32,
|
|
||||||
};
|
|
||||||
use crate::mm::PhysAddr;
|
use crate::mm::PhysAddr;
|
||||||
|
|
||||||
|
use acpi::mcfg::Mcfg;
|
||||||
use core::ffi::c_void;
|
use core::ffi::c_void;
|
||||||
use core::ptr::NonNull;
|
|
||||||
pub struct X86_64PciArch {}
|
pub struct X86_64PciArch;
|
||||||
impl TraitPciArch for X86_64PciArch {
|
impl TraitPciArch for X86_64PciArch {
|
||||||
fn read_config(bus_device_function: &BusDeviceFunction, offset: u8) -> u32 {
|
fn read_config(bus_device_function: &BusDeviceFunction, offset: u8) -> u32 {
|
||||||
// 构造pci配置空间地址
|
// 构造pci配置空间地址
|
||||||
@ -57,21 +56,24 @@ impl TraitPciArch for X86_64PciArch {
|
|||||||
}
|
}
|
||||||
//kdebug!("{}",data);
|
//kdebug!("{}",data);
|
||||||
//loop{}
|
//loop{}
|
||||||
let head = NonNull::new(data as *mut acpi_system_description_table_header_t).unwrap();
|
|
||||||
let outcome = unsafe { mcfg_find_segment(head).as_ref() };
|
let binding = acpi_manager()
|
||||||
for segmentgroupconfiguration in outcome {
|
.tables()
|
||||||
if segmentgroupconfiguration.segement_group_number == segement {
|
.expect("get acpi_manager table error")
|
||||||
|
.find_table::<Mcfg>();
|
||||||
|
if let Ok(mcfg) = binding {
|
||||||
|
for mcfg_entry in mcfg.entries() {
|
||||||
|
if mcfg_entry.pci_segment_group == segement {
|
||||||
return Ok(PciRoot {
|
return Ok(PciRoot {
|
||||||
physical_address_base: PhysAddr::new(
|
physical_address_base: PhysAddr::new(mcfg_entry.base_address as usize),
|
||||||
segmentgroupconfiguration.base_address as usize,
|
|
||||||
),
|
|
||||||
mmio_guard: None,
|
mmio_guard: None,
|
||||||
segement_group_number: segement,
|
segement_group_number: segement,
|
||||||
bus_begin: segmentgroupconfiguration.bus_begin,
|
bus_begin: mcfg_entry.bus_number_start,
|
||||||
bus_end: segmentgroupconfiguration.bus_end,
|
bus_end: mcfg_entry.bus_number_end,
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return Err(PciError::SegmentNotFound);
|
return Err(PciError::SegmentNotFound);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ extern crate acpi;
|
|||||||
pub mod bus;
|
pub mod bus;
|
||||||
mod c_adapter;
|
mod c_adapter;
|
||||||
pub mod glue;
|
pub mod glue;
|
||||||
pub mod old;
|
|
||||||
pub mod pmtmr;
|
pub mod pmtmr;
|
||||||
mod sysfs;
|
mod sysfs;
|
||||||
|
|
||||||
|
@ -1,27 +0,0 @@
|
|||||||
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 SegementConfigurationSpace {
|
|
||||||
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<[SegementConfigurationSpace]> {
|
|
||||||
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()
|
|
||||||
}
|
|
@ -15,8 +15,7 @@ use crate::{
|
|||||||
kobject::{KObjType, KObject, KObjectState},
|
kobject::{KObjType, KObject, KObjectState},
|
||||||
},
|
},
|
||||||
virtio::virtio_impl::HalImpl,
|
virtio::virtio_impl::HalImpl,
|
||||||
},
|
}, kerror, kinfo,
|
||||||
kdebug, kerror, kinfo,
|
|
||||||
libs::spinlock::SpinLock,
|
libs::spinlock::SpinLock,
|
||||||
net::{generate_iface_id, NET_DRIVERS},
|
net::{generate_iface_id, NET_DRIVERS},
|
||||||
syscall::SystemError,
|
syscall::SystemError,
|
||||||
|
Loading…
x
Reference in New Issue
Block a user