Skip to content

Commit 830f54f

Browse files
lai_host: pci read functions
Signed-off-by: Andy-Python-Programmer <[email protected]>
1 parent 1469c6a commit 830f54f

File tree

2 files changed

+21
-5
lines changed

2 files changed

+21
-5
lines changed

src/aero_kernel/src/drivers/lai.rs

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,8 @@ use crate::mem::paging::PhysAddr;
88
use crate::userland::scheduler;
99
use crate::utils::io;
1010

11+
use super::pci::PciHeader;
12+
1113
struct LaiHost;
1214

1315
impl lai::Host for LaiHost {
@@ -68,6 +70,24 @@ impl lai::Host for LaiHost {
6870
fn ind(&self, port: u16) -> u32 {
6971
unsafe { io::inl(port) }
7072
}
73+
74+
// PCI read functions:
75+
//
76+
// todo: do not ignore the segment once we use MCFG.
77+
fn pci_readb(&self, _seg: u16, bus: u8, slot: u8, fun: u8, offset: u16) -> u8 {
78+
let header = PciHeader::new(bus, slot, fun);
79+
unsafe { header.read::<u8>(offset as u32) as u8 }
80+
}
81+
82+
fn pci_readw(&self, _seg: u16, bus: u8, slot: u8, fun: u8, offset: u16) -> u16 {
83+
let header = PciHeader::new(bus, slot, fun);
84+
unsafe { header.read::<u16>(offset as u32) as u16 }
85+
}
86+
87+
fn pci_readd(&self, _seg: u16, bus: u8, slot: u8, fun: u8, offset: u16) -> u32 {
88+
let header = PciHeader::new(bus, slot, fun);
89+
unsafe { header.read::<u32>(offset as u32) }
90+
}
7191
}
7292

7393
pub fn init_lai() {

src/aero_kernel/src/drivers/pci.rs

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,7 @@ impl PciHeader {
419419
self.0.get_bits(0..3) as u8
420420
}
421421

422-
unsafe fn read<T>(&self, offset: u32) -> u32 {
422+
pub unsafe fn read<T>(&self, offset: u32) -> u32 {
423423
let bus = self.bus() as u32;
424424
let device = self.device() as u32;
425425
let func = self.function() as u32;
@@ -490,10 +490,6 @@ impl PciHeader {
490490
unsafe { self.read::<u32>(0x0c) }.get_bit(23)
491491
}
492492

493-
pub fn pin(&self) -> u8 {
494-
unsafe { (self.read::<u32>(0x3D) >> (0x3D & 0b11) * 8) as u8 }
495-
}
496-
497493
/// Returnes the value stored in the PCI header type register which is used to
498494
/// indicate layout for bytes,of the device’s configuration space.
499495
pub fn get_header_type(&self) -> u8 {

0 commit comments

Comments
 (0)