the cookie is now allocated by the framework

git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7109 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
beveloper
2004-03-29 23:43:00 +00:00
parent 0b67beb4a1
commit bbd6936229
3 changed files with 14 additions and 12 deletions
@@ -1,7 +1,7 @@
#include "lala/lala.h" #include "lala/lala.h"
#include "ichaudio.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_powerctl(drv_t *drv, void *cookie);
status_t ichaudio_detach(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 = { driver_info_t driver_info = {
ichaudio_id_table, ichaudio_id_table,
"audio/lala/ichaudio", "audio/lala/ichaudio",
sizeof(ichaudio_cookie),
ichaudio_attach, ichaudio_attach,
ichaudio_detach, ichaudio_detach,
ichaudio_powerctl, ichaudio_powerctl,
@@ -37,11 +38,9 @@ driver_info_t driver_info = {
status_t 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)); ichaudio_cookie *cookie = (ichaudio_cookie *)_cookie;
if (!cookie) return B_ERROR;
*_cookie = cookie;
dprintf("ichaudio_attach\n"); dprintf("ichaudio_attach\n");
@@ -49,9 +49,9 @@ init_driver(void)
drv_count = 0; drv_count = 0;
for (pciindex = 0; B_OK == pcimodule->get_nth_pci_info(pciindex, pciinfo); pciindex++) { 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", // 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->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.table[devindex].vendor != 0; devindex++) { 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) 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]->name = driver_info.table[devindex].name;
drv_data[drv_count]->flags = driver_info.table[devindex].flags; drv_data[drv_count]->flags = driver_info.table[devindex].flags;
drv_data[drv_count]->open_count = 0; 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++; drv_count++;
break; break;
} }
@@ -106,6 +106,7 @@ uninit_driver(void)
for (i = 0; i < drv_count; i++) { for (i = 0; i < drv_count; i++) {
free(drv_path[i]); free(drv_path[i]);
free(drv_data[i]->cookie);
free(drv_data[i]); free(drv_data[i]);
} }
delete_sem(drv_sem); delete_sem(drv_sem);
@@ -130,7 +131,8 @@ ich_open(const char *name, uint32 flags, void** cookie)
*cookie = (void *) index; *cookie = (void *) index;
if (drv_data[index]->open_count == 0) { 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; drv_data[index]->open_count = (res == B_OK) ? 1 : 0;
} else { } else {
res = B_OK; res = B_OK;
@@ -35,7 +35,7 @@ typedef struct {
uint32 flags; uint32 flags;
} id_table_t; } 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_powerctl) (drv_t *drv, void *cookie);
typedef status_t (*drv_detach) (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; id_table_t * table;
const char * basename; const char * basename;
size_t cookie_size;
drv_attach attach; drv_attach attach;
drv_detach detach; drv_detach detach;
drv_powerctl powerctl; drv_powerctl powerctl;