Skip to content

Commit

Permalink
Improvements (#140)
Browse files Browse the repository at this point in the history
Improvements
  • Loading branch information
pimnik98 authored Feb 13, 2024
2 parents ba4a5d6 + 6d9d1bf commit 0e40d06
Show file tree
Hide file tree
Showing 19 changed files with 276 additions and 199 deletions.
1 change: 1 addition & 0 deletions config.mk
Original file line number Diff line number Diff line change
Expand Up @@ -199,6 +199,7 @@ SOURCES=\
kernel/src/drv/audio/hda.c \
kernel/src/sys/grub_modules.c \
kernel/src/drv/disk/mbr.c \
kernel/src/sys/lapic.c \
$(GAMEBOY) \
kernel/src/kernel.c \
# kernel/src/lib/duktape.c \
Expand Down
9 changes: 1 addition & 8 deletions kernel/include/common.h
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,4 @@ typedef struct registers registers_t;
} while(0)
#else
#define ON_NULLPTR(ptr, code)
#endif

#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)))
#endif
1 change: 1 addition & 0 deletions kernel/include/drv/audio/hda.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,5 +4,6 @@

#pragma once

void hda_disable_interrupts();
void hda_init();
void hda_reset();
10 changes: 8 additions & 2 deletions kernel/include/drv/disk/ahci.h
Original file line number Diff line number Diff line change
Expand Up @@ -66,15 +66,21 @@ typedef enum {
} AHCI_FIS_TYPE;

typedef struct {
// 0
uint8_t fis_type; // FIS_TYPE_REG_H2D

// 1
uint8_t pmport:4; // Port multiplier
uint8_t rsv0:3; // Reserved
uint8_t c:1; // 1: Command, 0: Control

// 2
uint8_t command; // Command register
uint8_t featurel; // Feature register, 7:0

// 3
uint8_t featurel; // Feature register, 7:0

// 4 - 8
uint8_t lba0; // LBA low register, 7:0
uint8_t lba1; // LBA mid register, 15:8
uint8_t lba2; // LBA high register, 23:16
Expand Down Expand Up @@ -301,4 +307,4 @@ void ahci_rebase_memory_for(size_t port_num);
void ahci_eject_cdrom(size_t port_num);
void ahci_read_sectors(size_t port_num, size_t location, size_t sector_count, void* buffer);
void ahci_write_sectors(size_t port_num, size_t location, size_t sector_count, void* buffer);
void ahci_identify(size_t port_num);
void ahci_identify(size_t port_num, bool is_atapi);
3 changes: 0 additions & 3 deletions kernel/include/drv/disk/ata.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,6 @@
#define ATA_IDENT_COMMANDSETS 82
#define ATA_IDENT_MAX_LBA_EXT 100

#define IDE_ATA 0x00
#define IDE_ATAPI 0x01

#define ATA_MASTER 0x00
#define ATA_SLAVE 0x01

Expand Down
12 changes: 12 additions & 0 deletions kernel/include/drv/disk/dpm.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,19 @@ typedef struct {
dpm_disk_rw_cmd Write; ///< Команда для записи данных
} __attribute__((packed)) DPM_Disk;

// TODO: Save model, manufacturer, serial number, firmware version in that dpm structure.
enum dpm_disk_type {
NONE,
MEMORY,
IDE_ATA,
IDE_ATAPI,
AHCI_SATA,
AHCI_SATAPI
};

struct dpm_disk_info {
enum dpm_disk_type type;
};

void* dpm_metadata_read(char Letter);
void dpm_metadata_write(char Letter, uint32_t Addr);
Expand Down
2 changes: 1 addition & 1 deletion kernel/include/sys/acpi.h
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,5 @@ extern uint32_t system_processors_found;

RSDPDescriptor* rsdp_find();
void find_facp(size_t rsdt_addr);
void find_apic(size_t rsdt_addr);
void find_apic(size_t rsdt_addr, size_t *lapic_addr);
void acpi_scan_all_tables(uint32_t rsdt_addr);
7 changes: 7 additions & 0 deletions kernel/include/sys/lapic.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
//
// Created by ndraey on 2/13/24.
//

#pragma once

void lapic_init(RSDPDescriptor *rsdp);
32 changes: 32 additions & 0 deletions kernel/src/drv/audio/hda.c
Original file line number Diff line number Diff line change
Expand Up @@ -17,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 @@ -41,6 +48,27 @@ void hda_init() {

hda_reset();

size_t data = READ16(0x00);

size_t input_streams = (data >> 8) & 0b1111;
size_t output_streams = (data >> 12) & 0b1111;

hda_disable_interrupts();

//turn off dma position transfer
WRITE32(0x70, 0);
WRITE32(0x74, 0);

//disable synchronization
WRITE32(0x34, 0);
WRITE32(0x38, 0);

//stop CORB and RIRB
WRITE8(0x4C, 0x0);
WRITE8(0x5C, 0x0);

qemu_note("HDA: I: %d; O: %d;", input_streams, output_streams);

tty_printf("HDA RESET OKAY!\n");
}

Expand All @@ -58,3 +86,7 @@ void hda_reset() {

qemu_ok("Reset ok!");
}

void hda_disable_interrupts() {
WRITE32(0x20, 0);
}
Loading

0 comments on commit 0e40d06

Please sign in to comment.