|
|
@ -22,6 +22,7 @@ const PCIM_CMD_MEMEN: u32 = 0x0002;
|
|
|
|
fn pci_read_config(pci_base: usize, bus: u8, slot: u8, func: u8, offset: u8) -> u32 {
|
|
|
|
fn pci_read_config(pci_base: usize, bus: u8, slot: u8, func: u8, offset: u8) -> u32 {
|
|
|
|
// write config address
|
|
|
|
// write config address
|
|
|
|
let address = (1 << 31) | ((bus as u32) << 16) | ((slot as u32) << 11) | ((func as u32) << 8) | (offset as u32);
|
|
|
|
let address = (1 << 31) | ((bus as u32) << 16) | ((slot as u32) << 11) | ((func as u32) << 8) | (offset as u32);
|
|
|
|
|
|
|
|
println!("Address: {:08x}", address);
|
|
|
|
write(pci_base + 0xcf8, address);
|
|
|
|
write(pci_base + 0xcf8, address);
|
|
|
|
// do the actual work
|
|
|
|
// do the actual work
|
|
|
|
read(pci_base + 0xcfc)
|
|
|
|
read(pci_base + 0xcfc)
|
|
|
@ -38,9 +39,14 @@ fn pci_write_config(pci_base: usize, bus: u8, slot: u8, func: u8, offset: u8, va
|
|
|
|
pub fn init(pci_base: usize, vga_base: usize, x_res: u16, y_res: u16) {
|
|
|
|
pub fn init(pci_base: usize, vga_base: usize, x_res: u16, y_res: u16) {
|
|
|
|
|
|
|
|
|
|
|
|
// enable PCI MMIO
|
|
|
|
// enable PCI MMIO
|
|
|
|
|
|
|
|
let pci_vendor = pci_read_config(pci_base, 0x00, 0x12, 0x00, 0x0);
|
|
|
|
|
|
|
|
println!("PCI Device ID: {:08x}", pci_vendor);
|
|
|
|
|
|
|
|
|
|
|
|
let pci_state = pci_read_config(pci_base, 0x00, 0x12, 0x00, PCIR_COMMAND);
|
|
|
|
let pci_state = pci_read_config(pci_base, 0x00, 0x12, 0x00, PCIR_COMMAND);
|
|
|
|
|
|
|
|
println!("PCI Config Status: {:08x}", pci_state);
|
|
|
|
pci_write_config(pci_base, 0x00, 0x12, 0x00, PCIR_COMMAND, pci_state | PCIM_CMD_PORTEN | PCIM_CMD_MEMEN);
|
|
|
|
pci_write_config(pci_base, 0x00, 0x12, 0x00, PCIR_COMMAND, pci_state | PCIM_CMD_PORTEN | PCIM_CMD_MEMEN);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// vga operations
|
|
|
|
// vga operations
|
|
|
|
let vga_write_io = |offset: u16, value: u8| {
|
|
|
|
let vga_write_io = |offset: u16, value: u8| {
|
|
|
|
write(vga_base + VGA_MMIO_OFFSET + (offset as usize), value);
|
|
|
|
write(vga_base + VGA_MMIO_OFFSET + (offset as usize), value);
|
|
|
@ -61,8 +67,9 @@ pub fn init(pci_base: usize, vga_base: usize, x_res: u16, y_res: u16) {
|
|
|
|
vga_write_vbe(VBE_DISPI_INDEX_YRES, y_res);
|
|
|
|
vga_write_vbe(VBE_DISPI_INDEX_YRES, y_res);
|
|
|
|
vga_write_vbe(VBE_DISPI_INDEX_BPP, 8);
|
|
|
|
vga_write_vbe(VBE_DISPI_INDEX_BPP, 8);
|
|
|
|
// enable vbe
|
|
|
|
// enable vbe
|
|
|
|
let vbe_enable = vga_read_vbe(VBE_DISPI_INDEX_ENABLE) | VBE_DISPI_ENABLED;
|
|
|
|
let vbe_enable = vga_read_vbe(VBE_DISPI_INDEX_ENABLE);
|
|
|
|
vga_write_vbe(VBE_DISPI_INDEX_ENABLE, vbe_enable);
|
|
|
|
println!("VBE Status: {:04x}", vbe_enable);
|
|
|
|
|
|
|
|
vga_write_vbe(VBE_DISPI_INDEX_ENABLE, vbe_enable | VBE_DISPI_ENABLED);
|
|
|
|
|
|
|
|
|
|
|
|
println!("QEMU STDVGA driver initialized @ {:x}", vga_base);
|
|
|
|
println!("QEMU STDVGA driver initialized @ {:x}", vga_base);
|
|
|
|
|
|
|
|
|
|
|
|