#ifndef _DEV_PCI_AUVIA_H_
#define _DEV_PCI_AUVIA_H_
#include <Drivers.h>
#include <SupportDefs.h>
#include <OS.h>
#include <PCI.h>
#include "auviareg.h"
#include "config.h"
#include "queue.h"
#include "hmulti_audio.h"
#include "multi.h"
#define VIATECH_VENDOR_ID 0x1106
#define VIATECH_82C686_AC97_DEVICE_ID 0x3058
#define VIATECH_8233_AC97_DEVICE_ID 0x3059
#define VIATECH_8233_AC97_REV_8233_10 0x10
#define VIATECH_8233_AC97_REV_8233C 0x20
#define VIATECH_8233_AC97_REV_8233 0x30
#define VIATECH_8233_AC97_REV_8233A 0x40
#define VIATECH_8233_AC97_REV_8235 0x50
#define VIATECH_8233_AC97_REV_8237 0x60
#define VERSION "Version alpha 2, Copyright (c) 2003 Jérôme Duval, compiled on " __DATE__ " " __TIME__
#define DRIVER_NAME "auvia"
#define FRIENDLY_NAME "Auvia"
#define FRIENDLY_NAME_686 FRIENDLY_NAME" 82C686"
#define FRIENDLY_NAME_8233C FRIENDLY_NAME" 8233C"
#define FRIENDLY_NAME_8233 FRIENDLY_NAME" 8233"
#define FRIENDLY_NAME_8233A FRIENDLY_NAME" 8233A"
#define FRIENDLY_NAME_8235 FRIENDLY_NAME" 8235"
#define FRIENDLY_NAME_8237 FRIENDLY_NAME" 8237"
#define AUTHOR "Jérôme Duval"
#define VIA_TABLE_SIZE 255
#define AUVIA_USE_PLAY (1 << 0)
#define AUVIA_USE_RECORD (1 << 1)
#define AUVIA_STATE_STARTED (1 << 0)
typedef struct _auvia_mem {
LIST_ENTRY(_auvia_mem) next;
void* log_base;
phys_addr_t phy_base;
area_id area;
size_t size;
} auvia_mem;
typedef struct _auvia_stream {
struct _auvia_dev *card;
uint8 use;
uint8 state;
uint8 b16;
uint32 sample_rate;
uint8 channels;
uint32 bufframes;
uint8 bufcount;
uint32 base;
LIST_ENTRY(_auvia_stream) next;
void (*inth) (void *);
void *inthparam;
void* dmaops_log_base;
phys_addr_t dmaops_phy_base;
area_id dmaops_area;
auvia_mem* buffer;
uint16 blksize;
uint16 trigblk;
uint16 blkmod;
volatile int64 frames_count;
volatile bigtime_t real_time;
volatile int32 buffer_cycle;
int32 first_channel;
bool update_needed;
} auvia_stream;
typedef struct _auvia_dev {
char name[DEVNAME];
pci_info info;
device_config config;
void *ptb_log_base;
void *ptb_phy_base;
area_id ptb_area;
sem_id buffer_ready_sem;
uint32 interrupt_mask;
LIST_HEAD(, _auvia_stream) streams;
LIST_HEAD(, _auvia_mem) mems;
auvia_stream *pstream;
auvia_stream *rstream;
multi_dev multi;
} auvia_dev;
extern int32 num_cards;
extern auvia_dev cards[NUM_CARDS];
status_t auvia_stream_set_audioparms(auvia_stream *stream, uint8 channels,
uint8 b16, uint32 sample_rate);
status_t auvia_stream_commit_parms(auvia_stream *stream);
status_t auvia_stream_get_nth_buffer(auvia_stream *stream, uint8 chan, uint8 buf,
char** buffer, size_t *stride);
void auvia_stream_start(auvia_stream *stream, void (*inth) (void *), void *inthparam);
void auvia_stream_halt(auvia_stream *stream);
auvia_stream *auvia_stream_new(auvia_dev *card, uint8 use, uint32 bufframes, uint8 bufcount);
void auvia_stream_delete(auvia_stream *stream);
#endif