another api change

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7153 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper
2004-04-03 20:04:19 +00:00
parent faf78a3ae0
commit 749003c7a0
4 changed files with 93 additions and 93 deletions
@@ -5,14 +5,14 @@
status_t ichaudio_attach(audio_drv_t *drv, void **cookie); status_t ichaudio_attach(audio_drv_t *drv, void **cookie);
status_t ichaudio_powerctl(audio_drv_t *drv, void *cookie); status_t ichaudio_powerctl(audio_drv_t *drv, void *cookie);
status_t ichaudio_detach(audio_drv_t *drv, void *cookie); status_t ichaudio_detach(audio_drv_t *drv, void *cookie);
status_t ichaudio_stream_attach(audio_drv_t *drv, void **cookie, void *param); status_t ichaudio_stream_attach(audio_drv_t *drv, void *cookie, int stream);
status_t ichaudio_stream_detach(audio_drv_t *drv, void *cookie); status_t ichaudio_stream_detach(audio_drv_t *drv, void *cookie, int stream);
status_t ichaudio_stream_control(audio_drv_t *drv, void *cookie, int op); status_t ichaudio_stream_control(audio_drv_t *drv, void *cookie, int stream, int op);
status_t ichaudio_stream_set_buffers(audio_drv_t *drv, void *cookie, uint32 *buffer_size, stream_buffer_desc_t *desc); status_t ichaudio_stream_set_buffers(audio_drv_t *drv, void *cookie, int stream, uint32 *buffer_size, stream_buffer_desc_t *desc);
status_t ichaudio_stream_set_frame_rate(audio_drv_t *drv, void *cookie, uint32 *frame_rate); status_t ichaudio_stream_set_frame_rate(audio_drv_t *drv, void *cookie, int stream, uint32 *frame_rate);
id_table_t ichaudio_id_table[] = { pci_id_table_t ichaudio_id_table[] = {
{ 0x8086, 0x7195, -1, -1, -1, -1, -1, "Intel 82443MX AC97 audio" }, { 0x8086, 0x7195, -1, -1, -1, -1, -1, "Intel 82443MX AC97 audio" },
{ 0x8086, 0x2415, -1, -1, -1, -1, -1, "Intel 82801AA (ICH) AC97 audio" }, { 0x8086, 0x2415, -1, -1, -1, -1, -1, "Intel 82801AA (ICH) AC97 audio" },
{ 0x8086, 0x2425, -1, -1, -1, -1, -1, "Intel 82801AB (ICH0) AC97 audio" }, { 0x8086, 0x2425, -1, -1, -1, -1, -1, "Intel 82801AB (ICH0) AC97 audio" },
@@ -35,17 +35,21 @@ id_table_t ichaudio_id_table[] = {
driver_info_t driver_info = { driver_info_t driver_info = {
.id_table = ichaudio_id_table,
.basename = "audio/lala/ichaudio", .basename = "audio/lala/ichaudio",
.pci_id_table = ichaudio_id_table,
.attach = ichaudio_attach, .attach = ichaudio_attach,
.detach = ichaudio_detach, .detach = ichaudio_detach,
.powerctl = ichaudio_powerctl, .powerctl = ichaudio_powerctl,
}; };
enum {
STREAM_PO = 0,
STREAM_PI = 1,
};
stream_info_t po_stream = { stream_info_t po_stream = {
.flags = B_PLAYBACK_STREAM | B_BUFFER_SIZE_EXPONETIAL | B_SAMPLE_TYPE_INT16, .flags = B_PLAYBACK_STREAM | B_BUFFER_SIZE_EXPONETIAL | B_SAMPLE_TYPE_INT16,
.cookie_size = sizeof(ichaudio_stream_cookie), .cookie_size = sizeof(ichaudio_cookie),
.sample_bits = 16, .sample_bits = 16,
.channel_count = 2, .channel_count = 2,
.channel_mask = B_CHANNEL_LEFT | B_CHANNEL_RIGHT, .channel_mask = B_CHANNEL_LEFT | B_CHANNEL_RIGHT,
@@ -248,17 +252,15 @@ ichaudio_attach(audio_drv_t *drv, void **_cookie)
} }
} }
cookie->po_stream_id = create_stream(&po_stream, (void *)ICH_REG_PO_BASE); create_stream(drv, STREAM_PO, &po_stream);
cookie->pi_stream_id = create_stream(&pi_stream, (void *)ICH_REG_PI_BASE); create_stream(drv, STREAM_PI, &pi_stream);
if (cookie->po_stream_id < 0 || cookie->pi_stream_id < 0)
goto err;
return B_OK; return B_OK;
err: err:
// delete streams // delete streams
if (cookie->po_stream_id > 0) delete_stream(cookie->po_stream_id); delete_stream(drv, STREAM_PO);
if (cookie->pi_stream_id > 0) delete_stream(cookie->pi_stream_id); delete_stream(drv, STREAM_PI);
// unmap io memory // unmap io memory
if (cookie->area_mmbar > 0) delete_area(cookie->area_mmbar); if (cookie->area_mmbar > 0) delete_area(cookie->area_mmbar);
if (cookie->area_mbbar > 0) delete_area(cookie->area_mbbar); if (cookie->area_mbbar > 0) delete_area(cookie->area_mbbar);
@@ -275,8 +277,8 @@ ichaudio_detach(audio_drv_t *drv, void *_cookie)
dprintf("ichaudio_detach\n"); dprintf("ichaudio_detach\n");
// delete streams // delete streams
if (cookie->po_stream_id > 0) delete_stream(cookie->po_stream_id); delete_stream(drv, STREAM_PO);
if (cookie->pi_stream_id > 0) delete_stream(cookie->pi_stream_id); delete_stream(drv, STREAM_PI);
// unmap io memory // unmap io memory
if (cookie->area_mmbar > 0) delete_area(cookie->area_mmbar); if (cookie->area_mmbar > 0) delete_area(cookie->area_mmbar);
if (cookie->area_mbbar > 0) delete_area(cookie->area_mbbar); if (cookie->area_mbbar > 0) delete_area(cookie->area_mbbar);
@@ -294,16 +296,16 @@ ichaudio_powerctl(audio_drv_t *drv, void *_cookie)
} }
void void
stream_reset(ichaudio_stream_cookie *cookie) stream_reset(ichaudio_cookie *cookie, int stream)
{ {
int i; int i;
ich_reg_write_8(cookie, cookie->regbase + ICH_REG_X_CR, 0); ich_reg_write_8(cookie, cookie->stream[stream].regbase + ICH_REG_X_CR, 0);
ich_reg_read_8(cookie, cookie->regbase + ICH_REG_X_CR); // force PCI-to-PCI bridge cache flush ich_reg_read_8(cookie, cookie->stream[stream].regbase + ICH_REG_X_CR); // force PCI-to-PCI bridge cache flush
snooze(10000); // 10 ms snooze(10000); // 10 ms
ich_reg_write_8(cookie, cookie->regbase + ICH_REG_X_CR, CR_RR); ich_reg_write_8(cookie, cookie->stream[stream].regbase + ICH_REG_X_CR, CR_RR);
for (i = 0; i < 100; i++) { for (i = 0; i < 100; i++) {
uint8 cr = ich_reg_read_8(cookie, cookie->regbase + ICH_REG_X_CR); uint8 cr = ich_reg_read_8(cookie, cookie->stream[stream].regbase + ICH_REG_X_CR);
if (cr == 0) { if (cr == 0) {
LOG(("channel reset finished, %d\n",i)); LOG(("channel reset finished, %d\n",i));
return; return;
@@ -314,18 +316,18 @@ stream_reset(ichaudio_stream_cookie *cookie)
} }
status_t status_t
ichaudio_stream_attach(audio_drv_t *drv, void **_cookie, void *param) ichaudio_stream_attach(audio_drv_t *drv, void *_cookie, int stream)
{ {
ichaudio_stream_cookie *cookie; ichaudio_cookie *cookie = (ichaudio_cookie *) _cookie;
void *bd_virt_base; void *bd_virt_base;
void *bd_phys_base; void *bd_phys_base;
int i; int i;
*_cookie = cookie = (ichaudio_stream_cookie *) malloc(sizeof(ichaudio_stream_cookie)); uint32 stream_regbase[2] = { ICH_REG_PO_BASE, ICH_REG_PI_BASE };
cookie->regbase = (uint32) param; cookie->stream[stream].regbase = stream_regbase[stream];
cookie->lastindex = 0; cookie->stream[stream].lastindex = 0;
cookie->processed_samples = 0; cookie->stream[stream].processed_samples = 0;
stream_reset(cookie); stream_reset(cookie);
@@ -335,7 +337,7 @@ ichaudio_stream_attach(audio_drv_t *drv, void **_cookie, void *param)
goto err; goto err;
// set physical buffer descriptor base address // set physical buffer descriptor base address
ich_reg_write_32(cookie->regbase, (uint32)bd_phys_base); ich_reg_write_32(cookie->[stream].regbase, (uint32)bd_phys_base);
// setup descriptor pointers // setup descriptor pointers
for (i = 0; i < ICH_BD_COUNT; i++) for (i = 0; i < ICH_BD_COUNT; i++)
@@ -344,36 +346,34 @@ ichaudio_stream_attach(audio_drv_t *drv, void **_cookie, void *param)
return B_OK; return B_OK;
err: err:
free(cookie);
return B_ERROR; return B_ERROR;
} }
status_t status_t
ichaudio_stream_detach(audio_drv_t *drv, void *_cookie) ichaudio_stream_detach(audio_drv_t *drv, void *_cookie, int stream)
{ {
ichaudio_stream_cookie *cookie = (ichaudio_stream_cookie *)_cookie; ichaudio_cookie *cookie = (ichaudio_cookie *)_cookie;
stream_reset(cookie); stream_reset(cookie);
if (cookie->buffer_area > 0) delete_area(cookie->buffer_area); if (cookie->[stream].buffer_area > 0) delete_area(cookie->[stream].buffer_area);
if (cookie->bd_area > 0) delete_area(cookie->bd_area); if (cookie->[stream].bd_area > 0) delete_area(cookie->[stream].bd_area);
free(cookie);
return B_OK; return B_OK;
} }
status_t status_t
ichaudio_stream_control(audio_drv_t *drv, void *_cookie, int op) ichaudio_stream_control(audio_drv_t *drv, void *_cookie, int stream, int op)
{ {
} }
status_t status_t
ichaudio_stream_set_buffers(audio_drv_t *drv, void *_cookie, uint32 *buffer_size, stream_buffer_desc_t *desc) ichaudio_stream_set_buffers(audio_drv_t *drv, void *_cookie, int stream, uint32 *buffer_size, stream_buffer_desc_t *desc)
{ {
ichaudio_stream_cookie *cookie = (ichaudio_stream_cookie *)_cookie; ichaudio_cookie *cookie = (ichaudio_cookie *)_cookie;
void *buffer_virt_base; void *buffer_virt_base;
void *buffer_phys_base; void *buffer_phys_base;
@@ -401,15 +401,15 @@ ichaudio_stream_set_buffers(audio_drv_t *drv, void *_cookie, uint32 *buffer_size
// free old buffer memory // free old buffer memory
if (cookie->buffer_area > 0) if (cookie->buffer_area > 0)
delete_area(cookie->buffer_area); delete_area(cookie->[stream].buffer_area);
cookie->buffer_area = buffer_area; cookie->[stream].buffer_area = buffer_area;
return B_OK; return B_OK;
} }
status_t status_t
ichaudio_stream_set_frame_rate(audio_drv_t *drv, void *_cookie, uint32 *frame_rate) ichaudio_stream_set_frame_rate(audio_drv_t *drv, void *_cookie, int stream, uint32 *frame_rate)
{ {
} }
@@ -2,6 +2,21 @@
#include "hardware.h" #include "hardware.h"
#include "lala/lala.h" #include "lala/lala.h"
typedef struct
{
uint32 regbase;
ich_bd * bd[ICH_BD_COUNT];
void * buffer[ICH_BD_COUNT];
area_id bd_area;
area_id buffer_area;
volatile int lastindex;
volatile int64 processed_samples;
} ichaudio_stream;
typedef struct typedef struct
{ {
uint32 irq; uint32 irq;
@@ -16,8 +31,7 @@ typedef struct
uint32 input_rate; uint32 input_rate;
uint32 output_rate; uint32 output_rate;
stream_id po_stream_id; ichaudio_stream stream[2];
stream_id pi_stream_id;
pci_module_info * pci; pci_module_info * pci;
uint32 flags; uint32 flags;
@@ -25,20 +39,6 @@ typedef struct
} ichaudio_cookie; } ichaudio_cookie;
typedef struct
{
uint32 regbase;
ich_bd * bd[ICH_BD_COUNT];
void * buffer[ICH_BD_COUNT];
area_id bd_area;
area_id buffer_area;
volatile int lastindex;
volatile int64 processed_samples;
} ichaudio_stream_cookie;
#define TYPE_ICH4 0x01 #define TYPE_ICH4 0x01
#define TYPE_SIS7012 0x02 #define TYPE_SIS7012 0x02
@@ -56,25 +56,25 @@ init_driver(void)
// pciinfo->vendor_id, pciinfo->device_id, pciinfo->bus, pciinfo->device, pciinfo->function, // pciinfo->vendor_id, pciinfo->device_id, pciinfo->bus, pciinfo->device, pciinfo->function,
// pciinfo->revision, pciinfo->class_api, pciinfo->class_sub, pciinfo->class_base); // pciinfo->revision, pciinfo->class_api, pciinfo->class_sub, pciinfo->class_base);
for (devindex = 0; driver_info.id_table[devindex].vendor != 0; devindex++) { for (devindex = 0; driver_info.pci_id_table[devindex].vendor != 0; devindex++) {
if (driver_info.id_table[devindex].vendor != -1 && driver_info.id_table[devindex].vendor != pciinfo->vendor_id) if (driver_info.pci_id_table[devindex].vendor != -1 && driver_info.pci_id_table[devindex].vendor != pciinfo->vendor_id)
continue; continue;
if (driver_info.id_table[devindex].device != -1 && driver_info.id_table[devindex].device != pciinfo->device_id) if (driver_info.pci_id_table[devindex].device != -1 && driver_info.pci_id_table[devindex].device != pciinfo->device_id)
continue; continue;
if (driver_info.id_table[devindex].revision != -1 && driver_info.id_table[devindex].revision != pciinfo->revision) if (driver_info.pci_id_table[devindex].revision != -1 && driver_info.pci_id_table[devindex].revision != pciinfo->revision)
continue; continue;
if (driver_info.id_table[devindex].class != -1 && driver_info.id_table[devindex].class != pciinfo->class_base) if (driver_info.pci_id_table[devindex].class != -1 && driver_info.pci_id_table[devindex].class != pciinfo->class_base)
continue; continue;
if (driver_info.id_table[devindex].subclass != -1 && driver_info.id_table[devindex].subclass != pciinfo->class_sub) if (driver_info.pci_id_table[devindex].subclass != -1 && driver_info.pci_id_table[devindex].subclass != pciinfo->class_sub)
continue; continue;
if (pciinfo->header_type == 0) { if (pciinfo->header_type == 0) {
if (driver_info.id_table[devindex].subsystem_vendor != -1 && driver_info.id_table[devindex].subsystem_vendor != pciinfo->u.h0.subsystem_vendor_id) if (driver_info.pci_id_table[devindex].subsystem_vendor != -1 && driver_info.pci_id_table[devindex].subsystem_vendor != pciinfo->u.h0.subsystem_vendor_id)
continue; continue;
if (driver_info.id_table[devindex].subsystem_device != -1 && driver_info.id_table[devindex].subsystem_device != pciinfo->u.h0.subsystem_id) if (driver_info.pci_id_table[devindex].subsystem_device != -1 && driver_info.pci_id_table[devindex].subsystem_device != pciinfo->u.h0.subsystem_id)
continue; continue;
} }
dprintf("found device '%s'\n", driver_info.id_table[devindex].name); dprintf("found device '%s'\n", driver_info.pci_id_table[devindex].name);
drv_path[drv_count] = (char *) malloc(strlen(driver_info.basename) + 5); drv_path[drv_count] = (char *) malloc(strlen(driver_info.basename) + 5);
sprintf(drv_path[drv_count], "%s/%d", driver_info.basename, drv_count + 1); sprintf(drv_path[drv_count], "%s/%d", driver_info.basename, drv_count + 1);
@@ -84,8 +84,8 @@ init_driver(void)
drv_data[drv_count]->bus = pciinfo->bus; drv_data[drv_count]->bus = pciinfo->bus;
drv_data[drv_count]->device = pciinfo->device; drv_data[drv_count]->device = pciinfo->device;
drv_data[drv_count]->function = pciinfo->function; drv_data[drv_count]->function = pciinfo->function;
drv_data[drv_count]->name = driver_info.id_table[devindex].name; drv_data[drv_count]->name = driver_info.pci_id_table[devindex].name;
drv_data[drv_count]->param = driver_info.id_table[devindex].param; drv_data[drv_count]->param = driver_info.pci_id_table[devindex].param;
drv_open_count[drv_count] = 0; drv_open_count[drv_count] = 0;
drv_count++; drv_count++;
@@ -114,7 +114,7 @@ uninit_driver(void)
} }
static status_t static status_t
ich_open(const char *name, uint32 flags, void** cookie) driver_open(const char *name, uint32 flags, void** cookie)
{ {
int index; int index;
status_t res; status_t res;
@@ -145,14 +145,14 @@ ich_open(const char *name, uint32 flags, void** cookie)
} }
static status_t static status_t
ich_close(void* cookie) driver_close(void* cookie)
{ {
dprintf("close\n"); dprintf("close\n");
return B_OK; return B_OK;
} }
static status_t static status_t
ich_free(void* cookie) driver_free(void* cookie)
{ {
int index; int index;
status_t res; status_t res;
@@ -176,32 +176,32 @@ ich_free(void* cookie)
} }
static status_t static status_t
ich_control(void* cookie, uint32 op, void* arg, size_t len) driver_control(void* cookie, uint32 op, void* arg, size_t len)
{ {
return B_OK; return B_OK;
} }
static status_t static status_t
ich_read(void* cookie, off_t position, void *buf, size_t* num_bytes) driver_read(void* cookie, off_t position, void *buf, size_t* num_bytes)
{ {
*num_bytes = 0; *num_bytes = 0;
return B_IO_ERROR; return B_IO_ERROR;
} }
static status_t static status_t
ich_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes) driver_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes)
{ {
*num_bytes = 0; *num_bytes = 0;
return B_IO_ERROR; return B_IO_ERROR;
} }
device_hooks ich_hooks = { device_hooks driver_hooks = {
ich_open, driver_open,
ich_close, driver_close,
ich_free, driver_free,
ich_control, driver_control,
ich_read, driver_read,
ich_write driver_write
}; };
const char ** const char **
@@ -215,6 +215,6 @@ device_hooks*
find_device(const char* name) find_device(const char* name)
{ {
dprintf("find_device\n"); dprintf("find_device\n");
return &ich_hooks; return &driver_hooks;
} }
@@ -30,10 +30,9 @@ typedef struct
int32 subsystem_device; int32 subsystem_device;
const char * name; const char * name;
void * param; void * param;
} id_table_t; } pci_id_table_t;
typedef int32 stream_id;
typedef int32 control_id; typedef int32 control_id;
@@ -44,8 +43,8 @@ typedef status_t (*drv_detach) (audio_drv_t *drv, void *cookie);
typedef struct typedef struct
{ {
id_table_t * id_table;
const char * basename; const char * basename;
pci_id_table_t *pci_id_table;
uint32 _reserved1[16]; uint32 _reserved1[16];
@@ -65,12 +64,13 @@ typedef struct
} stream_buffer_desc_t; } stream_buffer_desc_t;
typedef status_t (*stream_attach) (audio_drv_t *drv, void **cookie, void *param); typedef status_t (*stream_attach) (audio_drv_t *drv, void *cookie, int stream);
typedef status_t (*stream_detach) (audio_drv_t *drv, void *cookie); typedef status_t (*stream_detach) (audio_drv_t *drv, void *cookie, int stream);
typedef status_t (*stream_control) (audio_drv_t *drv, void *cookie, int op); typedef status_t (*stream_control) (audio_drv_t *drv, void *cookie, int stream, int op);
typedef status_t (*stream_process) (audio_drv_t *drv, void *cookie, int buffer); typedef status_t (*stream_process) (audio_drv_t *drv, void *cookie, int stream, int buffer);
typedef status_t (*stream_set_buffers) (audio_drv_t *drv, void *cookie, uint32 *buffer_size, stream_buffer_desc_t *desc); typedef status_t (*stream_set_buffers) (audio_drv_t *drv, void *cookie, int stream, uint32 *buffer_size, stream_buffer_desc_t *desc);
typedef status_t (*stream_set_frame_rate) (audio_drv_t *drv, void *cookie, uint32 *frame_rate); typedef status_t (*stream_set_frame_rate) (audio_drv_t *drv, void *cookie, int stream, uint32 *frame_rate);
enum { enum {
B_RECORDING_STREAM = 0x00000001, B_RECORDING_STREAM = 0x00000001,
@@ -128,10 +128,10 @@ typedef struct
area_id alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *name); area_id alloc_mem(void **virt, void **phy, size_t size, uint32 protection, const char *name);
area_id map_mem(void **virt, void *phy, size_t size, uint32 protection, const char *name); area_id map_mem(void **virt, void *phy, size_t size, uint32 protection, const char *name);
stream_id create_stream(stream_info_t *info, void *param); status_t create_stream(audio_drv_t *drv, int stream, stream_info_t *info);
status_t delete_stream(stream_id stream); status_t delete_stream(audio_drv_t *drv, int stream);
void report_stream_buffer_ready(stream_id stream, int buffer, bigtime_t end_time, int64 total_frames); void report_stream_buffer_ready(audio_drv_t *drv, int stream, int buffer, bigtime_t end_time, int64 total_frames);
control_id create_control_group(control_id parent, audio_drv_t *dev); control_id create_control_group(control_id parent, audio_drv_t *dev);
control_id create_control(control_id parent, uint32 flags, void *get, void *set, const char *name); control_id create_control(control_id parent, uint32 flags, void *get, void *set, const char *name);