Skip to content

Commit

Permalink
把pci驱动的读取acpi mcfg的代码,调整为从新的acpi驱动来读取 (#413)
Browse files Browse the repository at this point in the history
* 把pci驱动的读取acpi mcfg的代码,调整为从新的acpi驱动来读取
  • Loading branch information
yuyi2439 authored Nov 1, 2023
1 parent 971462b commit 8b3d168
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 49 deletions.
40 changes: 21 additions & 19 deletions kernel/src/arch/x86_64/pci/pci.rs
Original file line number Diff line number Diff line change
@@ -1,17 +1,16 @@
use crate::arch::TraitPciArch;
use crate::driver::acpi::old::mcfg_find_segment;
use crate::driver::acpi::acpi_manager;
use crate::driver::pci::pci::{
BusDeviceFunction, PciAddr, 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 crate::include::bindings::bindings::{acpi_get_MCFG, acpi_iter_SDT, io_in32, io_out32};
use crate::mm::PhysAddr;

use acpi::mcfg::Mcfg;
use core::ffi::c_void;
use core::ptr::NonNull;
pub struct X86_64PciArch {}

pub struct X86_64PciArch;
impl TraitPciArch for X86_64PciArch {
fn read_config(bus_device_function: &BusDeviceFunction, offset: u8) -> u32 {
// 构造pci配置空间地址
Expand Down Expand Up @@ -57,19 +56,22 @@ impl TraitPciArch for X86_64PciArch {
}
//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: PhysAddr::new(
segmentgroupconfiguration.base_address as usize,
),
mmio_guard: None,
segement_group_number: segement,
bus_begin: segmentgroupconfiguration.bus_begin,
bus_end: segmentgroupconfiguration.bus_end,
});

let binding = acpi_manager()
.tables()
.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 {
physical_address_base: PhysAddr::new(mcfg_entry.base_address as usize),
mmio_guard: None,
segement_group_number: segement,
bus_begin: mcfg_entry.bus_number_start,
bus_end: mcfg_entry.bus_number_end,
});
}
}
}
return Err(PciError::SegmentNotFound);
Expand Down
1 change: 0 additions & 1 deletion kernel/src/driver/acpi/mod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ extern crate acpi;
pub mod bus;
mod c_adapter;
pub mod glue;
pub mod old;
pub mod pmtmr;
mod sysfs;

Expand Down
27 changes: 0 additions & 27 deletions kernel/src/driver/acpi/old.rs

This file was deleted.

3 changes: 1 addition & 2 deletions kernel/src/driver/net/virtio_net.rs
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ use crate::{
kobject::{KObjType, KObject, KObjectState},
},
virtio::virtio_impl::HalImpl,
},
kdebug, kerror, kinfo,
}, kerror, kinfo,
libs::spinlock::SpinLock,
net::{generate_iface_id, NET_DRIVERS},
syscall::SystemError,
Expand Down

0 comments on commit 8b3d168

Please sign in to comment.