From bbd6936229b8294986aba2a102bac355f53f1243 Mon Sep 17 00:00:00 2001 From: beveloper Date: Mon, 29 Mar 2004 23:43:00 +0000 Subject: [PATCH] the cookie is now allocated by the framework git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7109 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../kernel/drivers/audio/ac97/ichaudio/ichaudio.c | 9 ++++----- .../drivers/audio/ac97/ichaudio/lala/driver.c | 14 ++++++++------ .../kernel/drivers/audio/ac97/ichaudio/lala/lala.h | 3 ++- 3 files changed, 14 insertions(+), 12 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 91cce758c1..92c13051fd 100644 --- a/src/add-ons/kernel/drivers/audio/ac97/ichaudio/ichaudio.c +++ b/src/add-ons/kernel/drivers/audio/ac97/ichaudio/ichaudio.c @@ -1,7 +1,7 @@ #include "lala/lala.h" #include "ichaudio.h" -status_t ichaudio_attach(drv_t *drv, void **cookie); +status_t ichaudio_attach(drv_t *drv, void *cookie); status_t ichaudio_powerctl(drv_t *drv, void *cookie); status_t ichaudio_detach(drv_t *drv, void *cookie); @@ -30,6 +30,7 @@ id_table_t ichaudio_id_table[] = { driver_info_t driver_info = { ichaudio_id_table, "audio/lala/ichaudio", + sizeof(ichaudio_cookie), ichaudio_attach, ichaudio_detach, ichaudio_powerctl, @@ -37,11 +38,9 @@ driver_info_t driver_info = { status_t -ichaudio_attach(drv_t *drv, void **_cookie) +ichaudio_attach(drv_t *drv, void *cookie) { - ichaudio_cookie *cookie = (ichaudio_cookie *) malloc(sizeof(ichaudio_cookie)); - if (!cookie) return B_ERROR; - *_cookie = cookie; + ichaudio_cookie *cookie = (ichaudio_cookie *)_cookie; dprintf("ichaudio_attach\n"); 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 d9ba0ba55f..ed8eedb6ed 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 @@ -49,9 +49,9 @@ init_driver(void) drv_count = 0; for (pciindex = 0; B_OK == pcimodule->get_nth_pci_info(pciindex, pciinfo); pciindex++) { - dprintf("Checking PCI device, vendor 0x%04x, id 0x%04x, bus 0x%02x, dev 0x%02x, func 0x%02x, rev 0x%02x, api 0x%02x, sub 0x%02x, base 0x%02x\n", - pciinfo->vendor_id, pciinfo->device_id, pciinfo->bus, pciinfo->device, pciinfo->function, - pciinfo->revision, pciinfo->class_api, pciinfo->class_sub, pciinfo->class_base); +// dprintf("Checking PCI device, vendor 0x%04x, id 0x%04x, bus 0x%02x, dev 0x%02x, func 0x%02x, rev 0x%02x, api 0x%02x, sub 0x%02x, base 0x%02x\n", +// 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.table[devindex].vendor != 0; devindex++) { if (driver_info.table[devindex].vendor != -1 && driver_info.table[devindex].vendor != pciinfo->vendor_id) @@ -84,8 +84,8 @@ init_driver(void) drv_data[drv_count]->name = driver_info.table[devindex].name; drv_data[drv_count]->flags = driver_info.table[devindex].flags; drv_data[drv_count]->open_count = 0; - drv_data[drv_count]->cookie = 0; - + drv_data[drv_count]->cookie = malloc(driver_info.cookie_size); + drv_count++; break; } @@ -106,6 +106,7 @@ uninit_driver(void) for (i = 0; i < drv_count; i++) { free(drv_path[i]); + free(drv_data[i]->cookie); free(drv_data[i]); } delete_sem(drv_sem); @@ -130,7 +131,8 @@ ich_open(const char *name, uint32 flags, void** cookie) *cookie = (void *) index; if (drv_data[index]->open_count == 0) { - res = driver_info.attach(drv_data[index], &drv_data[index]->cookie); + memset(drv_data[index]->cookie, 0, driver_info.cookie_size); + res = driver_info.attach(drv_data[index], drv_data[index]->cookie); drv_data[index]->open_count = (res == B_OK) ? 1 : 0; } else { res = B_OK; 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 ecdc69f7cc..6cbccc4de8 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 @@ -35,7 +35,7 @@ typedef struct { uint32 flags; } id_table_t; -typedef status_t (*drv_attach) (drv_t *drv, void **cookie); +typedef status_t (*drv_attach) (drv_t *drv, void *cookie); typedef status_t (*drv_powerctl) (drv_t *drv, void *cookie); typedef status_t (*drv_detach) (drv_t *drv, void *cookie); @@ -43,6 +43,7 @@ typedef struct { id_table_t * table; const char * basename; + size_t cookie_size; drv_attach attach; drv_detach detach; drv_powerctl powerctl;