From 2aef37bf20fc0d166f925bf1d73dab8080e3fb59 Mon Sep 17 00:00:00 2001 From: beveloper Date: Mon, 29 Mar 2004 21:45:14 +0000 Subject: [PATCH] more experimenting git-svn-id: file:///srv/svn/repos/haiku/trunk/current@7106 a95241bf-73f2-0310-859d-f6bbb57e9c96 --- .../drivers/audio/ac97/ichaudio/ichaudio.c | 14 +-- .../drivers/audio/ac97/ichaudio/lala/driver.c | 90 +++++++++++++++++-- .../drivers/audio/ac97/ichaudio/lala/lala.h | 20 ++++- 3 files changed, 104 insertions(+), 20 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 d396e8fecc..ce2eea1c71 100644 --- a/src/add-ons/kernel/drivers/audio/ac97/ichaudio/ichaudio.c +++ b/src/add-ons/kernel/drivers/audio/ac97/ichaudio/ichaudio.c @@ -1,9 +1,9 @@ #include "lala/lala.h" #include "ichaudio.h" -status_t ichaudio_attach(drv_t *dev, void **cookie, int id_table_index); -status_t ichaudio_powerctl(void *cookie); -status_t ichaudio_detach(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); id_table_t ichaudio_id_table[] = { { 0x8086, 0x7195, -1, -1, -1, -1, -1, "Intel 82443MX AC97 audio" }, @@ -19,7 +19,7 @@ id_table_t ichaudio_id_table[] = { { 0x10DE, 0x00DA, -1, -1, -1, -1, -1, "NVIDIA nForce 3 (MCP3) AC97 audio" }, { 0x1022, 0x764D, -1, -1, -1, -1, -1, "AMD AMD8111 AC97 audio" }, { 0x1022, 0x7445, -1, -1, -1, -1, -1, "AMD AMD768 AC97 audio" }, - { 0x1003, 0x0004, -1, -1, -1, -1, -1, "Highpoint HPT372 RAID" }, + { 0x1103, 0x0004, -1, -1, -1, -1, -1, "Highpoint HPT372 RAID" }, { 0x1095, 0x3112, -1, -1, -1, -1, -1, "Silicon Image SATA Si3112" }, { 0x8086, 0x244b, -1, -1, -1, -1, -1, "Intel IDE Controller" }, { 0x8979, 0x6456, -1, -1, -1, -1, -1, "does not exist" }, @@ -37,7 +37,7 @@ driver_info_t driver_info = { status_t -ichaudio_attach(drv_t *dev, void **_cookie, int id_table_index) +ichaudio_attach(drv_t *drv, void **_cookie) { ichaudio_cookie *cookie = (ichaudio_cookie *) malloc(sizeof(ichaudio_cookie)); if (!cookie) return B_ERROR; @@ -56,7 +56,7 @@ err: status_t -ichaudio_detach(void *_cookie) +ichaudio_detach(drv_t *drv, void *_cookie) { ichaudio_cookie *cookie = (ichaudio_cookie *)_cookie; @@ -66,7 +66,7 @@ ichaudio_detach(void *_cookie) status_t -ichaudio_powerctl(void *_cookie) +ichaudio_powerctl(drv_t *drv, void *_cookie) { ichaudio_cookie *cookie = (ichaudio_cookie *)_cookie; 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 9e3d2c7444..7a14aa15be 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 @@ -2,14 +2,23 @@ #include #include #include +#include #include +#include +#include + +#include "lala.h" int32 api_version = B_CUR_DRIVER_API_VERSION; #define MAX_DEVICES 8 -char * device_names[MAX_DEVICES]; -int device_count = 0; +char * drv_path[MAX_DEVICES + 1]; +drv_t * drv_data[MAX_DEVICES]; +int drv_count; + +pci_module_info *pcimodule; + status_t init_hardware(void) @@ -18,34 +27,102 @@ init_hardware(void) return B_OK; } + status_t init_driver(void) { + struct pci_info info; + struct pci_info *pciinfo = &info; + int pciindex; + int devindex; + dprintf("init_driver\n"); + dprintf("driver base name '%s'\n", driver_info.basename); + + if (get_module(B_PCI_MODULE_NAME,(module_info **)&pcimodule) < 0) { + return B_ERROR; + } + + 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); + + 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) + continue; + if (driver_info.table[devindex].device != -1 && driver_info.table[devindex].device != pciinfo->device_id) + continue; + if (driver_info.table[devindex].revision != -1 && driver_info.table[devindex].revision != pciinfo->revision) + continue; + if (driver_info.table[devindex].class != -1 && driver_info.table[devindex].class != pciinfo->class_base) + continue; + if (driver_info.table[devindex].subclass != -1 && driver_info.table[devindex].subclass != pciinfo->class_sub) + continue; + if (pciinfo->header_type == 0) { + if (driver_info.table[devindex].subsystem_vendor != -1 && driver_info.table[devindex].subsystem_vendor != pciinfo->u.h0.subsystem_vendor_id) + continue; + if (driver_info.table[devindex].subsystem_device != -1 && driver_info.table[devindex].subsystem_device != pciinfo->u.h0.subsystem_id) + continue; + } + + dprintf("found device '%s'\n", driver_info.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); + + drv_data[drv_count] = (drv_t *) malloc(sizeof(drv_t)); + drv_data[drv_count]->pci = pcimodule; + 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.table[devindex].name; + drv_data[drv_count]->flags = driver_info.table[devindex].flags; + + drv_count++; + break; + } + if (drv_count == MAX_DEVICES) + break; + } + + drv_path[drv_count + 1] = NULL; + return B_OK; } void uninit_driver(void) { + int i; dprintf("uninit_driver\n"); + + for (i = 0; i < drv_count; i++) { + free(drv_path[i]); + free(drv_data[i]); + } } static status_t ich_open(const char *name, uint32 flags, void** cookie) { + dprintf("open\n"); return B_OK; } static status_t ich_close(void* cookie) { + dprintf("close\n"); return B_OK; } static status_t ich_free(void* cookie) { + dprintf("free\n"); return B_OK; } @@ -69,11 +146,6 @@ ich_write(void* cookie, off_t position, const void* buffer, size_t* num_bytes) return B_IO_ERROR; } -static const char *ich_name[] = { - "audio/lala/ichaudio/1", - NULL -}; - device_hooks ich_hooks = { ich_open, ich_close, @@ -83,11 +155,11 @@ device_hooks ich_hooks = { ich_write }; -const char** +const char ** publish_devices(void) { dprintf("publish_devices\n"); - return ich_name; + return (const char **) drv_path; } device_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 ceaad63ec5..1ec4708e53 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 @@ -4,7 +4,19 @@ #include #include -typedef void drv_t; +typedef struct +{ + pci_module_info * pci; + + uint8 bus; + uint8 device; + uint8 function; + + const char * name; + uint32 flags; + +} drv_t; + typedef void stream_id; typedef void control_id; @@ -20,9 +32,9 @@ typedef struct { uint32 flags; } id_table_t; -typedef status_t (*drv_attach) (drv_t *dev, void **cookie, int id_table_index); -typedef status_t (*drv_powerctl) (void *cookie); -typedef status_t (*drv_detach) (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); typedef struct {