-
Notifications
You must be signed in to change notification settings - Fork 9
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Starting to rewrite HDA driver in C (#124)
Also: Disable Rust
- Loading branch information
Showing
12 changed files
with
132 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ | |
*.sea | ||
*.vhd | ||
*.tmp | ||
*.pcap | ||
.vscode/ | ||
*.d | ||
/rust/target | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
// | ||
// Created by ndraey on 21.01.24. | ||
// | ||
|
||
#pragma once | ||
|
||
void hda_init(); | ||
void hda_reset(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,67 @@ | ||
// | ||
// Created by ndraey on 21.01.24. | ||
// | ||
|
||
#include "drv/pci.h" | ||
#include "drv/audio/hda.h" | ||
#include "io/ports.h" | ||
#include "io/tty.h" | ||
#include "mem/pmm.h" | ||
|
||
uint8_t hda_bus = 0, | ||
hda_slot = 0, | ||
hda_func = 0; | ||
|
||
uint16_t hda_vendor = 0, | ||
hda_device = 0; | ||
|
||
uint32_t hda_addr = 0; | ||
|
||
#define WRITE32(reg, value) *(volatile uint32_t*)(hda_addr + (reg)) = (value) | ||
#define READ32(reg) (*(volatile uint32_t*)(hda_addr + (reg))) | ||
#define WRITE16(reg, value) *(volatile uint16_t*)(hda_addr + (reg)) = (value) | ||
#define READ16(reg) (*(volatile uint16_t*)(hda_addr + (reg))) | ||
#define WRITE8(reg, value) *(volatile uint8_t*)(hda_addr + (reg)) = (value) | ||
#define READ8(reg) (*(volatile uint8_t*)(hda_addr + (reg))) | ||
|
||
void hda_init() { | ||
pci_find_device_by_class_and_subclass(4, 3, &hda_vendor, &hda_device, &hda_bus, &hda_slot, &hda_func); | ||
|
||
if(hda_vendor && hda_device) { | ||
qemu_ok("Found Intel HDA! (%x:%x)", hda_vendor, hda_device); | ||
} else { | ||
return; | ||
} | ||
|
||
hda_addr = pci_read32(hda_bus, hda_slot, hda_func, 0x10) & ~0x10; | ||
|
||
qemu_ok("HDA address: %x", hda_addr); | ||
tty_printf("HDA address: %x\n", hda_addr); | ||
|
||
map_pages( | ||
get_kernel_page_directory(), | ||
hda_addr, | ||
hda_addr, | ||
PAGE_SIZE, | ||
PAGE_WRITEABLE | PAGE_CACHE_DISABLE // PAGE_PRESENT is set automatically | ||
); | ||
|
||
hda_reset(); | ||
|
||
tty_printf("HDA RESET OKAY!\n"); | ||
} | ||
|
||
void hda_reset() { | ||
if(!hda_vendor) | ||
return; | ||
|
||
WRITE32(0x08, 0); | ||
|
||
while((READ32(0x08) & 1) != 0); | ||
|
||
WRITE32(0x8, 1); | ||
|
||
while ((READ32(0x08) & 1) != 1); | ||
|
||
qemu_ok("Reset ok!"); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.