#pragma once
#include <stdint.h>
#include <stdbool.h>

typedef struct {
    uint8_t bus;
    uint8_t device;
    uint8_t function;
} pci_address_t;

typedef struct {
    pci_address_t addr;
    uint16_t vendor_id;
    uint16_t device_id;
    uint16_t class_code;     // (class << 8) | subclass
    uint8_t  prog_if;
    uint8_t  revision;
    uint32_t bar[6];
    bool     is_multifunction;
} pci_device_t;

#define PCI_CLASS_AUDIO     0x04
#define PCI_SUBCLASS_HDA    0x03

// Read/write config space (re-uses your existing uACPI PCI code)
uint8_t  pci_read8 (pci_address_t addr, uint16_t offset);
uint16_t pci_read16(pci_address_t addr, uint16_t offset);
uint32_t pci_read32(pci_address_t addr, uint16_t offset);

void pci_write8 (pci_address_t addr, uint16_t offset, uint8_t  val);
void pci_write16(pci_address_t addr, uint16_t offset, uint16_t val);
void pci_write32(pci_address_t addr, uint16_t offset, uint32_t val);

// Scan and print all PCI devices
void pci_init(void);
void pci_print_all(void);

// Find first HDA controller (returns true if found)
bool pci_find_hda(pci_device_t* out_dev);