Skip to content

Commit

Permalink
HDA: Reset now works in real hardware
Browse files Browse the repository at this point in the history
  • Loading branch information
NDRAEY committed Jan 21, 2024
1 parent b119374 commit 92ef5a1
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 2 deletions.
3 changes: 2 additions & 1 deletion kernel/include/drv/audio/hda.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

#pragma once

void hda_init();
void hda_init();
void hda_reset();
37 changes: 36 additions & 1 deletion kernel/src/drv/audio/hda.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@
#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,
Expand All @@ -16,6 +17,13 @@ uint16_t hda_vendor = 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);

Expand All @@ -28,5 +36,32 @@ void hda_init() {
hda_addr = pci_read32(hda_bus, hda_slot, hda_func, 0x10) & ~0x10;

qemu_ok("HDA address: %x", hda_addr);
tty_printf("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!");
}
Binary file modified netdump.pcap
Binary file not shown.

0 comments on commit 92ef5a1

Please sign in to comment.