From 749003c7a05bf310183f9c04d49e70fe43a9acfe Mon Sep 17 00:00:00 2001 From: beveloper Date: Sat, 3 Apr 2004 20:04:19 +0000 Subject: [PATCH] another api change git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7153 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../drivers/audio/ac97/ichaudio/ichaudio.c | 80 +++++++++---------- .../drivers/audio/ac97/ichaudio/ichaudio.h | 32 ++++---- .../drivers/audio/ac97/ichaudio/lala/driver.c | 50 ++++++------ .../drivers/audio/ac97/ichaudio/lala/lala.h | 24 +++--- 4 files changed, 93 insertions(+), 93 deletions(-) diff --git a/src/add-ons/kernel/drivers/audio/ac97/ichaudio/ichaudio.c b/src/add-ons/kernel/drivers/audio/ac97/ichaudio/ichaudio.c index c020e7a7f8..0e23d9b83a 100644 --- a/src/add-ons/kernel/drivers/audio/ac97/ichaudio/ichaudio.c +++ b/src/add-ons/kernel/drivers/audio/ac97/ichaudio/ichaudio.c @@ -5,14 +5,14 @@ status_t ichaudio_attach(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_stream_attach(audio_drv_t *drv, void **cookie, void *param); -status_t ichaudio_stream_detach(audio_drv_t *drv, void *cookie); -status_t ichaudio_stream_control(audio_drv_t *drv, void *cookie, 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_frame_rate(audio_drv_t *drv, void *cookie, uint32 *frame_rate); +status_t ichaudio_stream_attach(audio_drv_t *drv, void *cookie, int stream); +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 stream, int op); +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, 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, 0x2415, -1, -1, -1, -1, -1, "Intel 82801AA (ICH) 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 = { - .id_table = ichaudio_id_table, .basename = "audio/lala/ichaudio", + .pci_id_table = ichaudio_id_table, .attach = ichaudio_attach, .detach = ichaudio_detach, .powerctl = ichaudio_powerctl, }; +enum { + STREAM_PO = 0, + STREAM_PI = 1, +}; stream_info_t po_stream = { .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, .channel_count = 2, .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); - cookie->pi_stream_id = create_stream(&pi_stream, (void *)ICH_REG_PI_BASE); - if (cookie->po_stream_id < 0 || cookie->pi_stream_id < 0) - goto err; + create_stream(drv, STREAM_PO, &po_stream); + create_stream(drv, STREAM_PI, &pi_stream); return B_OK; err: // delete streams - if (cookie->po_stream_id > 0) delete_stream(cookie->po_stream_id); - if (cookie->pi_stream_id > 0) delete_stream(cookie->pi_stream_id); + delete_stream(drv, STREAM_PO); + delete_stream(drv, STREAM_PI); // unmap io memory if (cookie->area_mmbar > 0) delete_area(cookie->area_mmbar); 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"); // delete streams - if (cookie->po_stream_id > 0) delete_stream(cookie->po_stream_id); - if (cookie->pi_stream_id > 0) delete_stream(cookie->pi_stream_id); + delete_stream(drv, STREAM_PO); + delete_stream(drv, STREAM_PI); // unmap io memory if (cookie->area_mmbar > 0) delete_area(cookie->area_mmbar); if (cookie->area_mbbar > 0) delete_area(cookie->area_mbbar); @@ -294,16 +296,16 @@ ichaudio_powerctl(audio_drv_t *drv, void *_cookie) } void -stream_reset(ichaudio_stream_cookie *cookie) +stream_reset(ichaudio_cookie *cookie, int stream) { int i; - ich_reg_write_8(cookie, cookie->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_write_8(cookie, cookie->stream[stream].regbase + ICH_REG_X_CR, 0); + ich_reg_read_8(cookie, cookie->stream[stream].regbase + ICH_REG_X_CR); // force PCI-to-PCI bridge cache flush 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++) { - 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) { LOG(("channel reset finished, %d\n",i)); return; @@ -314,18 +316,18 @@ stream_reset(ichaudio_stream_cookie *cookie) } 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_phys_base; 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->lastindex = 0; - cookie->processed_samples = 0; + cookie->stream[stream].regbase = stream_regbase[stream]; + cookie->stream[stream].lastindex = 0; + cookie->stream[stream].processed_samples = 0; stream_reset(cookie); @@ -335,7 +337,7 @@ ichaudio_stream_attach(audio_drv_t *drv, void **_cookie, void *param) goto err; // 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 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; err: - free(cookie); return B_ERROR; } 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); - if (cookie->buffer_area > 0) delete_area(cookie->buffer_area); - if (cookie->bd_area > 0) delete_area(cookie->bd_area); - free(cookie); + if (cookie->[stream].buffer_area > 0) delete_area(cookie->[stream].buffer_area); + if (cookie->[stream].bd_area > 0) delete_area(cookie->[stream].bd_area); return B_OK; } 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 -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_phys_base; @@ -401,15 +401,15 @@ ichaudio_stream_set_buffers(audio_drv_t *drv, void *_cookie, uint32 *buffer_size // free old buffer memory 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; } 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) { } diff --git a/src/add-ons/kernel/drivers/audio/ac97/ichaudio/ichaudio.h b/src/add-ons/kernel/drivers/audio/ac97/ichaudio/ichaudio.h index 9f5e3fb4d2..c6f77eac5e 100644 --- a/src/add-ons/kernel/drivers/audio/ac97/ichaudio/ichaudio.h +++ b/src/add-ons/kernel/drivers/audio/ac97/ichaudio/ichaudio.h @@ -2,6 +2,21 @@ #include "hardware.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 { uint32 irq; @@ -16,8 +31,7 @@ typedef struct uint32 input_rate; uint32 output_rate; - stream_id po_stream_id; - stream_id pi_stream_id; + ichaudio_stream stream[2]; pci_module_info * pci; uint32 flags; @@ -25,20 +39,6 @@ typedef struct } 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_SIS7012 0x02 diff --git a/src/add-ons/kernel/drivers/audio/ac97/ichaudio/lala/driver.c b/src/add-ons/kernel/drivers/audio/ac97/ichaudio/lala/driver.c index f3f93ae120..32fb0bf416 100644 --- a/src/add-ons/kernel/drivers/audio/ac97/ichaudio/lala/driver.c +++ b/src/add-ons/kernel/drivers/audio/ac97/ichaudio/lala/driver.c @@ -56,25 +56,25 @@ init_driver(void) // pciinfo->vendor_id, pciinfo->device_id, pciinfo->bus, pciinfo->device, pciinfo->function, // pciinfo->revision, pciinfo->class_api, pciinfo->class_sub, pciinfo->class_base); - for (devindex = 0; driver_info.id_table[devindex].vendor != 0; devindex++) { - if (driver_info.id_table[devindex].vendor != -1 && driver_info.id_table[devindex].vendor != pciinfo->vendor_id) + for (devindex = 0; driver_info.pci_id_table[devindex].vendor != 0; devindex++) { + if (driver_info.pci_id_table[devindex].vendor != -1 && driver_info.pci_id_table[devindex].vendor != pciinfo->vendor_id) 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; - 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; - 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; - 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; 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; - 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; } - 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); 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]->device = pciinfo->device; drv_data[drv_count]->function = pciinfo->function; - drv_data[drv_count]->name = driver_info.id_table[devindex].name; - drv_data[drv_count]->param = driver_info.id_table[devindex].param; + drv_data[drv_count]->name = driver_info.pci_id_table[devindex].name; + drv_data[drv_count]->param = driver_info.pci_id_table[devindex].param; drv_open_count[drv_count] = 0; drv_count++; @@ -114,7 +114,7 @@ uninit_driver(void) } static status_t -ich_open(const char *name, uint32 flags, void** cookie) +driver_open(const char *name, uint32 flags, void** cookie) { int index; status_t res; @@ -145,14 +145,14 @@ ich_open(const char *name, uint32 flags, void** cookie) } static status_t -ich_close(void* cookie) +driver_close(void* cookie) { dprintf("close\n"); return B_OK; } static status_t -ich_free(void* cookie) +driver_free(void* cookie) { int index; status_t res; @@ -176,32 +176,32 @@ ich_free(void* cookie) } 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; } 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; return B_IO_ERROR; } 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; return B_IO_ERROR; } -device_hooks ich_hooks = { - ich_open, - ich_close, - ich_free, - ich_control, - ich_read, - ich_write +device_hooks driver_hooks = { + driver_open, + driver_close, + driver_free, + driver_control, + driver_read, + driver_write }; const char ** @@ -215,6 +215,6 @@ device_hooks* find_device(const char* name) { dprintf("find_device\n"); - return &ich_hooks; + return &driver_hooks; } diff --git a/src/add-ons/kernel/drivers/audio/ac97/ichaudio/lala/lala.h b/src/add-ons/kernel/drivers/audio/ac97/ichaudio/lala/lala.h index 74cf65a3dd..fd11244592 100644 --- a/src/add-ons/kernel/drivers/audio/ac97/ichaudio/lala/lala.h +++ b/src/add-ons/kernel/drivers/audio/ac97/ichaudio/lala/lala.h @@ -30,10 +30,9 @@ typedef struct int32 subsystem_device; const char * name; void * param; -} id_table_t; +} pci_id_table_t; -typedef int32 stream_id; typedef int32 control_id; @@ -44,8 +43,8 @@ typedef status_t (*drv_detach) (audio_drv_t *drv, void *cookie); typedef struct { - id_table_t * id_table; const char * basename; + pci_id_table_t *pci_id_table; uint32 _reserved1[16]; @@ -65,12 +64,13 @@ typedef struct } stream_buffer_desc_t; -typedef status_t (*stream_attach) (audio_drv_t *drv, void **cookie, void *param); -typedef status_t (*stream_detach) (audio_drv_t *drv, void *cookie); -typedef status_t (*stream_control) (audio_drv_t *drv, void *cookie, int op); -typedef status_t (*stream_process) (audio_drv_t *drv, void *cookie, 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_frame_rate) (audio_drv_t *drv, void *cookie, uint32 *frame_rate); +typedef status_t (*stream_attach) (audio_drv_t *drv, void *cookie, int stream); +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 stream, int op); +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, int stream, uint32 *buffer_size, stream_buffer_desc_t *desc); +typedef status_t (*stream_set_frame_rate) (audio_drv_t *drv, void *cookie, int stream, uint32 *frame_rate); + enum { 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 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 delete_stream(stream_id stream); +status_t create_stream(audio_drv_t *drv, int stream, stream_info_t *info); +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(control_id parent, uint32 flags, void *get, void *set, const char *name);