Skip to content

Commit

Permalink
* Made code more Coding Guidelines compliant
Browse files Browse the repository at this point in the history
* Fixed several sem/area leaks when restarting media services.



git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@21160 a95241bf-73f2-0310-859d-f6bbb57e9c96
  • Loading branch information
Ithamar R. Adema committed May 17, 2007
1 parent 9432d60 commit abc3549
Show file tree
Hide file tree
Showing 3 changed files with 74 additions and 10 deletions.
4 changes: 3 additions & 1 deletion src/add-ons/kernel/drivers/audio/hda/driver.h
Original file line number Diff line number Diff line change
Expand Up @@ -200,6 +200,7 @@ extern uint32 num_cards;

/* hda_codec.c */
hda_codec* hda_codec_new(hda_controller* ctrlr, uint32 cad);
void hda_codec_delete(hda_codec*);

/* hda_multi_audio.c */
status_t multi_audio_control(void* cookie, uint32 op, void* arg, size_t len);
Expand All @@ -211,7 +212,8 @@ void hda_hw_uninit(hda_controller* ctrlr);
status_t hda_send_verbs(hda_codec* codec, corb_t* verbs, uint32* responses, int count);

/* hda_controller.c: Stream support */
hda_stream* hda_stream_alloc(hda_controller* ctrlr, int type);
hda_stream* hda_stream_new(hda_controller* ctrlr, int type);
void hda_stream_delete(hda_stream* s);
status_t hda_stream_setup_buffers(hda_afg* afg, hda_stream* s, const char* desc);
status_t hda_stream_start(hda_controller* ctrlr, hda_stream* s);
status_t hda_stream_stop(hda_controller* ctrlr, hda_stream* s);
Expand Down
36 changes: 34 additions & 2 deletions src/add-ons/kernel/drivers/audio/hda/hda_codec.c
Original file line number Diff line number Diff line change
Expand Up @@ -300,6 +300,21 @@ hda_codec_afg_find_dac_path(hda_afg* afg, uint32 wid, uint32 depth)
return 0;
}

static void
hda_afg_delete(hda_afg* afg)
{
if (afg != NULL) {
if (afg->playback_stream != NULL)
hda_stream_delete(afg->playback_stream);

if (afg->record_stream != NULL)
hda_stream_delete(afg->record_stream);

free(afg->widgets);
free(afg);
}
}

static status_t
hda_codec_afg_new(hda_codec* codec, uint32 afg_nid)
{
Expand Down Expand Up @@ -357,8 +372,8 @@ hda_codec_afg_new(hda_codec* codec, uint32 afg_nid)
corb_t verb;

/* Setup playback/record streams for Multi Audio API */
afg->playback_stream = hda_stream_alloc(afg->codec->ctrlr, STRM_PLAYBACK);
afg->record_stream = hda_stream_alloc(afg->codec->ctrlr, STRM_RECORD);
afg->playback_stream = hda_stream_new(afg->codec->ctrlr, STRM_PLAYBACK);
afg->record_stream = hda_stream_new(afg->codec->ctrlr, STRM_RECORD);

afg->playback_stream->pin_wid = idx + afg->wid_start;
afg->playback_stream->io_wid = output_wid;
Expand Down Expand Up @@ -389,6 +404,23 @@ hda_codec_afg_new(hda_codec* codec, uint32 afg_nid)
return rc;
}

void
hda_codec_delete(hda_codec* codec)
{
if (codec != NULL) {
uint32 idx;

delete_sem(codec->response_sem);

for (idx=0; idx < codec->num_afgs; idx++) {
hda_afg_delete(codec->afgs[idx]);
codec->afgs[idx] = NULL;
}

free(codec);
}
}

hda_codec*
hda_codec_new(hda_controller* ctrlr, uint32 cad)
{
Expand Down
44 changes: 37 additions & 7 deletions src/add-ons/kernel/drivers/audio/hda/hda_controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,23 @@

#include "driver.h"

void
hda_stream_delete(hda_stream* s)
{
if (s->buffer_ready_sem >= B_OK)
delete_sem(s->buffer_ready_sem);

if (s->buffer_area >= B_OK)
delete_area(s->buffer_area);

if (s->bdl_area >= B_OK)
delete_area(s->bdl_area);

free(s);
}

hda_stream*
hda_stream_alloc(hda_controller* ctrlr, int type)
hda_stream_new(hda_controller* ctrlr, int type)
{
hda_stream* s = calloc(1, sizeof(hda_stream));
if (s != NULL) {
Expand Down Expand Up @@ -45,7 +60,7 @@ hda_stream_start(hda_controller* ctrlr, hda_stream* s)
{
OREG8(ctrlr,s->off,CTL0) |= CTL0_RUN;

while(!(OREG8(ctrlr,s->off,CTL0) & CTL0_RUN))
while (!(OREG8(ctrlr,s->off,CTL0) & CTL0_RUN))
snooze(1);

s->running = true;
Expand Down Expand Up @@ -84,7 +99,7 @@ hda_stream_stop(hda_controller* ctrlr, hda_stream* s)
{
OREG8(ctrlr,s->off,CTL0) &= ~CTL0_RUN;

while(OREG8(ctrlr,s->off,CTL0) & CTL0_RUN)
while (OREG8(ctrlr,s->off,CTL0) & CTL0_RUN)
snooze(1);

s->running = false;
Expand Down Expand Up @@ -262,7 +277,7 @@ hda_interrupt_handler(hda_controller* ctrlr)

if (rirbsts & RIRBSTS_RINTFL) {
uint16 rirbwp = REG16(ctrlr,RIRBWP);
while(ctrlr->rirbrp <= rirbwp) {
while (ctrlr->rirbrp <= rirbwp) {
uint32 resp_ex = ctrlr->rirb[ctrlr->rirbrp].resp_ex;
uint32 cad = resp_ex & HDA_MAXCODECS;
hda_codec* codec = ctrlr->codecs[cad];
Expand Down Expand Up @@ -326,7 +341,7 @@ hda_hw_start(hda_controller* ctrlr)

do {
snooze(100);
} while(--timeout && !(REG32(ctrlr,GCTL) & GCTL_CRST));
} while (--timeout && !(REG32(ctrlr,GCTL) & GCTL_CRST));

return timeout ? B_OK : B_TIMED_OUT;
}
Expand Down Expand Up @@ -383,7 +398,7 @@ hda_hw_corb_rirb_init(hda_controller* ctrlr)

if ((rc=get_memory_map(ctrlr->corb, memsz, &pe, 1)) != B_OK) {
delete_area(ctrlr->rb_area);
return ctrlr->rb_area;
return rc;
}

/* Program CORB/RIRB for these locations */
Expand All @@ -395,7 +410,7 @@ hda_hw_corb_rirb_init(hda_controller* ctrlr)
REG16(ctrlr,CORBRP) = CORBRP_RST;
do {
snooze(10);
} while( !(REG16(ctrlr,CORBRP) & CORBRP_RST) );
} while ( !(REG16(ctrlr,CORBRP) & CORBRP_RST) );
REG16(ctrlr,CORBRP) = 0;

/* Reset RIRB write pointer */
Expand Down Expand Up @@ -522,6 +537,8 @@ void
hda_hw_uninit(hda_controller* ctrlr)
{
if (ctrlr != NULL) {
uint32 idx;

/* Stop all audio streams */
hda_hw_stop(ctrlr);

Expand All @@ -535,12 +552,25 @@ hda_hw_uninit(hda_controller* ctrlr)
remove_io_interrupt_handler(ctrlr->irq,
(interrupt_handler)hda_interrupt_handler,
ctrlr);

/* Delete corb/rirb area */
if (ctrlr->rb_area >= 0) {
delete_area(ctrlr->rb_area);
ctrlr->rb_area = B_ERROR;
ctrlr->corb = NULL;
ctrlr->rirb = NULL;
}

/* Unmap registers */
if (ctrlr->regs_area >= 0) {
delete_area(ctrlr->regs_area);
ctrlr->regs_area = B_ERROR;
ctrlr->regs = NULL;
}

/* Now delete all codecs */
for (idx=0; idx < HDA_MAXCODECS; idx++)
if (ctrlr->codecs[idx] != NULL)
hda_codec_delete(ctrlr->codecs[idx]);
}
}

0 comments on commit abc3549

Please sign in to comment.