bugfixed and renamed stream parameter to stream_id

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7155 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper
2004-04-03 21:42:11 +00:00
parent ee0cded9b8
commit efbf097f79
2 changed files with 48 additions and 43 deletions
@@ -5,11 +5,13 @@
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, int stream); status_t ichaudio_stream_attach(audio_drv_t *drv, void *cookie, int stream_id);
status_t ichaudio_stream_detach(audio_drv_t *drv, void *cookie, int stream); status_t ichaudio_stream_detach(audio_drv_t *drv, void *cookie, int stream_id);
status_t ichaudio_stream_control(audio_drv_t *drv, void *cookie, int stream, int op); status_t ichaudio_stream_control(audio_drv_t *drv, void *cookie, int stream_id, 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_buffers(audio_drv_t *drv, void *cookie, int stream_id, 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); status_t ichaudio_stream_set_frame_rate(audio_drv_t *drv, void *cookie, int stream_id, uint32 *frame_rate);
void stream_reset(ichaudio_cookie *cookie, uint32 regbase);
pci_id_table_t ichaudio_id_table[] = { pci_id_table_t ichaudio_id_table[] = {
@@ -46,6 +48,8 @@ enum {
STREAM_PO = 0, STREAM_PO = 0,
STREAM_PI = 1, STREAM_PI = 1,
}; };
const uint32 STREAM_REGBASE[2] = { ICH_REG_PO_BASE, ICH_REG_PI_BASE };
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,
@@ -296,16 +300,16 @@ ichaudio_powerctl(audio_drv_t *drv, void *_cookie)
} }
void void
stream_reset(ichaudio_cookie *cookie, int stream) stream_reset(ichaudio_cookie *cookie, uint32 regbase)
{ {
int i; int i;
ich_reg_write_8(cookie, cookie->stream[stream].regbase + ICH_REG_X_CR, 0); ich_reg_write_8(cookie, 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 ich_reg_read_8(cookie, 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->stream[stream].regbase + ICH_REG_X_CR, CR_RR); ich_reg_write_8(cookie, 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->stream[stream].regbase + ICH_REG_X_CR); uint8 cr = ich_reg_read_8(cookie, 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;
@@ -316,32 +320,31 @@ stream_reset(ichaudio_cookie *cookie, int stream)
} }
status_t status_t
ichaudio_stream_attach(audio_drv_t *drv, void *_cookie, int stream) ichaudio_stream_attach(audio_drv_t *drv, void *_cookie, int stream_id)
{ {
ichaudio_cookie *cookie = (ichaudio_cookie *) _cookie; ichaudio_cookie *cookie = (ichaudio_cookie *) _cookie;
ichaudio_stream *stream = &cookie->stream[stream_id];
void *bd_virt_base; void *bd_virt_base;
void *bd_phys_base; void *bd_phys_base;
int i; int i;
uint32 stream_regbase[2] = { ICH_REG_PO_BASE, ICH_REG_PI_BASE }; stream->regbase = STREAM_REGBASE[stream_id];
stream->lastindex = 0;
stream->processed_samples = 0;
cookie->stream[stream].regbase = stream_regbase[stream]; stream_reset(cookie, stream->regbase);
cookie->stream[stream].lastindex = 0;
cookie->stream[stream].processed_samples = 0;
stream_reset(cookie);
// allocate memory for buffer descriptors // allocate memory for buffer descriptors
cookie->bd_area = alloc_mem(&bd_virt_base, &bd_phys_base, ICH_BD_COUNT * sizeof(ich_bd), 0, "ich_ac97 buffer descriptor"); stream->bd_area = alloc_mem(&bd_virt_base, &bd_phys_base, ICH_BD_COUNT * sizeof(ich_bd), 0, "ich_ac97 buffer descriptor");
if (cookie->bd_area < B_OK) if (stream->bd_area < B_OK)
goto err; goto err;
// set physical buffer descriptor base address // set physical buffer descriptor base address
ich_reg_write_32(cookie->[stream].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++)
cookie->bd[i] = (ich_bd *) ((char *)bd_virt_base + i * sizeof(ich_bd)); stream->bd[i] = (ich_bd *) ((char *)bd_virt_base + i * sizeof(ich_bd));
return B_OK; return B_OK;
@@ -351,29 +354,31 @@ err:
status_t status_t
ichaudio_stream_detach(audio_drv_t *drv, void *_cookie, int stream) ichaudio_stream_detach(audio_drv_t *drv, void *_cookie, int stream_id)
{ {
ichaudio_cookie *cookie = (ichaudio_cookie *)_cookie; ichaudio_cookie *cookie = (ichaudio_cookie *)_cookie;
ichaudio_stream *stream = &cookie->stream[stream_id];
stream_reset(cookie); stream_reset(cookie, stream->regbase);
if (cookie->[stream].buffer_area > 0) delete_area(cookie->[stream].buffer_area); if (stream->buffer_area > 0) delete_area(stream->buffer_area);
if (cookie->[stream].bd_area > 0) delete_area(cookie->[stream].bd_area); if (stream->bd_area > 0) delete_area(stream->bd_area);
return B_OK; return B_OK;
} }
status_t status_t
ichaudio_stream_control(audio_drv_t *drv, void *_cookie, int stream, int op) ichaudio_stream_control(audio_drv_t *drv, void *_cookie, int stream_id, int op)
{ {
} }
status_t status_t
ichaudio_stream_set_buffers(audio_drv_t *drv, void *_cookie, int stream, uint32 *buffer_size, stream_buffer_desc_t *desc) ichaudio_stream_set_buffers(audio_drv_t *drv, void *_cookie, int stream_id, uint32 *buffer_size, stream_buffer_desc_t *desc)
{ {
ichaudio_cookie *cookie = (ichaudio_cookie *)_cookie; ichaudio_cookie *cookie = (ichaudio_cookie *)_cookie;
ichaudio_stream *stream = &cookie->stream[stream_id];
void *buffer_virt_base; void *buffer_virt_base;
void *buffer_phys_base; void *buffer_phys_base;
@@ -394,22 +399,22 @@ ichaudio_stream_set_buffers(audio_drv_t *drv, void *_cookie, int stream, uint32
// initalize buffer descriptors // initalize buffer descriptors
for (i = 0; i < ICH_BD_COUNT; i++) { for (i = 0; i < ICH_BD_COUNT; i++) {
cookie->bd[i].buffer = (uint32)buffer_phy_base + (i % 2) * *buffer_size; stream->bd[i]->buffer = (uint32)buffer_phys_base + (i % 2) * *buffer_size;
cookie->bd[i].length = *buffer_size / GET_HW_SAMPLE_SIZE(cookie); stream->bd[i]->length = *buffer_size / GET_HW_SAMPLE_SIZE(cookie);
cookie->bd[i].flags = ICH_BDC_FLAG_IOC; stream->bd[i]->flags = ICH_BDC_FLAG_IOC;
} }
// free old buffer memory // free old buffer memory
if (cookie->buffer_area > 0) if (stream->buffer_area > 0)
delete_area(cookie->[stream].buffer_area); delete_area(stream->buffer_area);
cookie->[stream].buffer_area = buffer_area; 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, int stream, uint32 *frame_rate) ichaudio_stream_set_frame_rate(audio_drv_t *drv, void *_cookie, int stream_id, uint32 *frame_rate)
{ {
} }
@@ -64,12 +64,12 @@ typedef struct
} stream_buffer_desc_t; } stream_buffer_desc_t;
typedef status_t (*stream_attach) (audio_drv_t *drv, void *cookie, int stream); typedef status_t (*stream_attach) (audio_drv_t *drv, void *cookie, int stream_id);
typedef status_t (*stream_detach) (audio_drv_t *drv, void *cookie, int stream); typedef status_t (*stream_detach) (audio_drv_t *drv, void *cookie, int stream_id);
typedef status_t (*stream_control) (audio_drv_t *drv, void *cookie, int stream, int op); typedef status_t (*stream_control) (audio_drv_t *drv, void *cookie, int stream_id, int op);
typedef status_t (*stream_process) (audio_drv_t *drv, void *cookie, int stream, int buffer); typedef status_t (*stream_process) (audio_drv_t *drv, void *cookie, int stream_id, 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_buffers) (audio_drv_t *drv, void *cookie, int stream_id, 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); typedef status_t (*stream_set_frame_rate) (audio_drv_t *drv, void *cookie, int stream_id, uint32 *frame_rate);
enum { enum {
@@ -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);
status_t create_stream(audio_drv_t *drv, int stream, stream_info_t *info); status_t create_stream(audio_drv_t *drv, int stream_id, stream_info_t *info);
status_t delete_stream(audio_drv_t *drv, int stream); status_t delete_stream(audio_drv_t *drv, int stream_id);
void report_stream_buffer_ready(audio_drv_t *drv, int stream, int buffer, bigtime_t end_time, int64 total_frames); void report_stream_buffer_ready(audio_drv_t *drv, int stream_id, 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);