Skip to content

Commit

Permalink
Merge pull request #425 from imp/pci-refactor
Browse files Browse the repository at this point in the history
Pci refactor
  • Loading branch information
jackpot51 committed Jan 4, 2016
2 parents 4b79652 + 755381a commit 687bdd2
Show file tree
Hide file tree
Showing 2 changed files with 36 additions and 22 deletions.
18 changes: 18 additions & 0 deletions kernel/drivers/pci/common.rs
Original file line number Diff line number Diff line change
Expand Up @@ -97,3 +97,21 @@ pub mod programming_interface {
pub const EHCI: u8 = 0x20;
pub const XHCI: u8 = 0x30;
}

pub mod vendorid {
pub const INTEL: u16 = 0x8086;
pub const REALTEK: u16 = 0x10EC;
pub const REDHAT: u16 = 0x1AF4;
pub const ILLEGAL: u16 = 0xFFFF;
}

pub mod deviceid {
// Realtek
pub const RTL8139: u16 = 0x8139; // RTL-8100/8101L/8139 PCI Fast Ethernet Adapter

// Intel
pub const GBE_82540EM: u16 = 0x100E; // 82540EM Gigabit Ethernet Controller
pub const AC97_82801AA: u16 = 0x2415; // 82801AA AC'97 Audio Controller
pub const AC97_ICH4: u16 = 0x24C5; // 82801DB/DBL/DBM (ICH4/ICH4-L/ICH4-M) AC'97 Audio
pub const INTELHDA_ICH6: u16 = 0x2668; // 82801FB/FBM/FR/FW/FRW High Definition Audio
}
40 changes: 18 additions & 22 deletions kernel/drivers/pci/init.rs
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ use super::config::PciConfig;
use super::common::class::*;
use super::common::subclass::*;
use super::common::programming_interface::*;
use super::common::vendorid::*;
use super::common::deviceid::*;

/// PCI device
pub unsafe fn pci_device(env: &mut Environment,
Expand Down Expand Up @@ -65,28 +67,22 @@ pub unsafe fn pci_device(env: &mut Environment,
debug!("Unknown USB interface version {:X}\n", interface_id);
}
} else {
match vendor_code {
0x10EC => match device_code { // REALTEK
0x8139 => env.schemes.push(UnsafeCell::new(Rtl8139::new(pci))),
_ => (),
},
0x8086 => match device_code { // INTEL
0x100E => env.schemes.push(UnsafeCell::new(Intel8254x::new(pci))),
0x2415 => env.schemes.push(UnsafeCell::new(AC97::new(pci))),
0x24C5 => env.schemes.push(UnsafeCell::new(AC97::new(pci))),
0x2668 => {
let base = pci.read(0x10) as usize;
let mut module = box IntelHDA {
pci: pci,
base: base & 0xFFFFFFF0,
memory_mapped: base & 1 == 0,
irq: pci.read(0x3C) as u8 & 0xF,
};
module.init();
env.schemes.push(UnsafeCell::new(module));
}
_ => (),
},
match (vendor_code, device_code) {
(REALTEK, RTL8139) => env.schemes.push(UnsafeCell::new(Rtl8139::new(pci))),
(INTEL, GBE_82540EM) => env.schemes.push(UnsafeCell::new(Intel8254x::new(pci))),
(INTEL, AC97_82801AA) => env.schemes.push(UnsafeCell::new(AC97::new(pci))),
(INTEL, AC97_ICH4) => env.schemes.push(UnsafeCell::new(AC97::new(pci))),
(INTEL, INTELHDA_ICH6) => {
let base = pci.read(0x10) as usize;
let mut module = box IntelHDA {
pci: pci,
base: base & 0xFFFFFFF0,
memory_mapped: base & 1 == 0,
irq: pci.read(0x3C) as u8 & 0xF,
};
module.init();
env.schemes.push(UnsafeCell::new(module));
}
_ => (),
}
}
Expand Down

0 comments on commit 687bdd2

Please sign in to comment.