ALSA: asihpi - Interrelated HPI tidy up.
authorEliot Blennerhassett <eblennerhassett@audioscience.com>
Thu, 10 Feb 2011 04:25:58 +0000 (17:25 +1300)
committerTakashi Iwai <tiwai@suse.de>
Thu, 10 Feb 2011 17:22:40 +0000 (18:22 +0100)
Remove many unused functions.
Update some message and cache structs.
Use pci info directly from pci_dev.
Allow control cache elements with variable size, and handle
large message/response from dsp.
hpi6000 and hpi6205: fix error path when adapter bootload fails.
hpimsgx.c get rid of code duplicated in hpicmn.c

Signed-off-by: Eliot Blennerhassett <eblennerhassett@audioscience.com>
Signed-off-by: Takashi Iwai <tiwai@suse.de>
sound/pci/asihpi/hpi6000.c
sound/pci/asihpi/hpi6205.c
sound/pci/asihpi/hpi6205.h
sound/pci/asihpi/hpi_internal.h
sound/pci/asihpi/hpicmn.c
sound/pci/asihpi/hpicmn.h
sound/pci/asihpi/hpifunc.c
sound/pci/asihpi/hpimsginit.c
sound/pci/asihpi/hpimsgx.c
sound/pci/asihpi/hpioctl.c
sound/pci/asihpi/hpios.h

index 1b9bf9395cfe820f87b34fa14d57d5a667a67217..c85db49e5ec53a7ab82b4594bd02bb01f1f62107 100644 (file)
 #define HPI_HIF_ERROR_MASK      0x4000
 
 /* HPI6000 specific error codes */
-
-#define HPI6000_ERROR_BASE                              900
+#define HPI6000_ERROR_BASE                              900    /* not actually used anywhere */
+/* operational/messaging errors */
 #define HPI6000_ERROR_MSG_RESP_IDLE_TIMEOUT             901
-#define HPI6000_ERROR_MSG_RESP_SEND_MSG_ACK             902
+
 #define HPI6000_ERROR_MSG_RESP_GET_RESP_ACK             903
 #define HPI6000_ERROR_MSG_GET_ADR                       904
 #define HPI6000_ERROR_RESP_GET_ADR                      905
 #define HPI6000_ERROR_MSG_RESP_BLOCKWRITE32             906
 #define HPI6000_ERROR_MSG_RESP_BLOCKREAD32              907
-#define HPI6000_ERROR_MSG_INVALID_DSP_INDEX             908
+
 #define HPI6000_ERROR_CONTROL_CACHE_PARAMS              909
 
 #define HPI6000_ERROR_SEND_DATA_IDLE_TIMEOUT            911
@@ -62,7 +62,6 @@
 #define HPI6000_ERROR_SEND_DATA_CMD                     915
 #define HPI6000_ERROR_SEND_DATA_WRITE                   916
 #define HPI6000_ERROR_SEND_DATA_IDLECMD                 917
-#define HPI6000_ERROR_SEND_DATA_VERIFY                  918
 
 #define HPI6000_ERROR_GET_DATA_IDLE_TIMEOUT             921
 #define HPI6000_ERROR_GET_DATA_ACK                      922
@@ -76,9 +75,8 @@
 
 #define HPI6000_ERROR_MSG_RESP_GETRESPCMD               961
 #define HPI6000_ERROR_MSG_RESP_IDLECMD                  962
-#define HPI6000_ERROR_MSG_RESP_BLOCKVERIFY32            963
 
-/* adapter init errors */
+/* Initialisation/bootload errors */
 #define HPI6000_ERROR_UNHANDLED_SUBSYS_ID               930
 
 /* can't access PCI2040 */
@@ -210,6 +208,8 @@ static void adapter_get_asserts(struct hpi_adapter_obj *pao,
 static short create_adapter_obj(struct hpi_adapter_obj *pao,
        u32 *pos_error_code);
 
+static void delete_adapter_obj(struct hpi_adapter_obj *pao);
+
 /* local globals */
 
 static u16 gw_pci_read_asserts;        /* used to count PCI2040 errors */
@@ -217,17 +217,7 @@ static u16 gw_pci_write_asserts;   /* used to count PCI2040 errors */
 
 static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
 {
-
        switch (phm->function) {
-       case HPI_SUBSYS_OPEN:
-       case HPI_SUBSYS_CLOSE:
-       case HPI_SUBSYS_GET_INFO:
-       case HPI_SUBSYS_DRIVER_UNLOAD:
-       case HPI_SUBSYS_DRIVER_LOAD:
-       case HPI_SUBSYS_FIND_ADAPTERS:
-               /* messages that should not get here */
-               phr->error = HPI_ERROR_UNIMPLEMENTED;
-               break;
        case HPI_SUBSYS_CREATE_ADAPTER:
                subsys_create_adapter(phm, phr);
                break;
@@ -243,17 +233,13 @@ static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
 static void control_message(struct hpi_adapter_obj *pao,
        struct hpi_message *phm, struct hpi_response *phr)
 {
-
        switch (phm->function) {
        case HPI_CONTROL_GET_STATE:
                if (pao->has_control_cache) {
-                       u16 err;
-                       err = hpi6000_update_control_cache(pao, phm);
+                       phr->error = hpi6000_update_control_cache(pao, phm);
 
-                       if (err) {
-                               phr->error = err;
+                       if (phr->error)
                                break;
-                       }
 
                        if (hpi_check_control_cache(((struct hpi_hw_obj *)
                                                pao->priv)->p_cache, phm,
@@ -262,16 +248,15 @@ static void control_message(struct hpi_adapter_obj *pao,
                }
                hw_message(pao, phm, phr);
                break;
-       case HPI_CONTROL_GET_INFO:
-               hw_message(pao, phm, phr);
-               break;
        case HPI_CONTROL_SET_STATE:
                hw_message(pao, phm, phr);
-               hpi_sync_control_cache(((struct hpi_hw_obj *)pao->priv)->
-                       p_cache, phm, phr);
+               hpi_cmn_control_cache_sync_to_msg(((struct hpi_hw_obj *)pao->
+                               priv)->p_cache, phm, phr);
                break;
+
+       case HPI_CONTROL_GET_INFO:
        default:
-               phr->error = HPI_ERROR_INVALID_FUNC;
+               hw_message(pao, phm, phr);
                break;
        }
 }
@@ -280,26 +265,12 @@ static void adapter_message(struct hpi_adapter_obj *pao,
        struct hpi_message *phm, struct hpi_response *phr)
 {
        switch (phm->function) {
-       case HPI_ADAPTER_GET_INFO:
-               hw_message(pao, phm, phr);
-               break;
        case HPI_ADAPTER_GET_ASSERT:
                adapter_get_asserts(pao, phm, phr);
                break;
-       case HPI_ADAPTER_OPEN:
-       case HPI_ADAPTER_CLOSE:
-       case HPI_ADAPTER_TEST_ASSERT:
-       case HPI_ADAPTER_SELFTEST:
-       case HPI_ADAPTER_GET_MODE:
-       case HPI_ADAPTER_SET_MODE:
-       case HPI_ADAPTER_FIND_OBJECT:
-       case HPI_ADAPTER_GET_PROPERTY:
-       case HPI_ADAPTER_SET_PROPERTY:
-       case HPI_ADAPTER_ENUM_PROPERTY:
-               hw_message(pao, phm, phr);
-               break;
+
        default:
-               phr->error = HPI_ERROR_INVALID_FUNC;
+               hw_message(pao, phm, phr);
                break;
        }
 }
@@ -311,7 +282,7 @@ static void outstream_message(struct hpi_adapter_obj *pao,
        case HPI_OSTREAM_HOSTBUFFER_ALLOC:
        case HPI_OSTREAM_HOSTBUFFER_FREE:
                /* Don't let these messages go to the HW function because
-                * they're called without allocating the spinlock.
+                * they're called without locking the spinlock.
                 * For the HPI6000 adapters the HW would return
                 * HPI_ERROR_INVALID_FUNC anyway.
                 */
@@ -331,7 +302,7 @@ static void instream_message(struct hpi_adapter_obj *pao,
        case HPI_ISTREAM_HOSTBUFFER_ALLOC:
        case HPI_ISTREAM_HOSTBUFFER_FREE:
                /* Don't let these messages go to the HW function because
-                * they're called without allocating the spinlock.
+                * they're called without locking the spinlock.
                 * For the HPI6000 adapters the HW would return
                 * HPI_ERROR_INVALID_FUNC anyway.
                 */
@@ -355,7 +326,7 @@ void HPI_6000(struct hpi_message *phm, struct hpi_response *phr)
        /* subsytem messages get executed by every HPI. */
        /* All other messages are ignored unless the adapter index matches */
        /* an adapter in the HPI */
-       HPI_DEBUG_LOG(DEBUG, "O %d,F %x\n", phm->object, phm->function);
+       /*HPI_DEBUG_LOG(DEBUG, "O %d,F %x\n", phm->wObject, phm->wFunction); */
 
        /* if Dsp has crashed then do not communicate with it any more */
        if (phm->object != HPI_OBJ_SUBSYSTEM) {
@@ -440,14 +411,6 @@ static void subsys_create_adapter(struct hpi_message *phm,
 
        memset(&ao, 0, sizeof(ao));
 
-       /* this HPI only creates adapters for TI/PCI2040 based devices */
-       if (phm->u.s.resource.bus_type != HPI_BUS_PCI)
-               return;
-       if (phm->u.s.resource.r.pci->vendor_id != HPI_PCI_VENDOR_ID_TI)
-               return;
-       if (phm->u.s.resource.r.pci->device_id != HPI_PCI_DEV_ID_PCI2040)
-               return;
-
        ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);
        if (!ao.priv) {
                HPI_DEBUG_LOG(ERROR, "cant get mem for adapter object\n");
@@ -456,16 +419,13 @@ static void subsys_create_adapter(struct hpi_message *phm,
        }
 
        /* create the adapter object based on the resource information */
-       /*? memcpy(&ao.Pci,&phm->u.s.Resource.r.Pci,sizeof(ao.Pci)); */
        ao.pci = *phm->u.s.resource.r.pci;
 
        error = create_adapter_obj(&ao, &os_error_code);
-       if (!error)
-               error = hpi_add_adapter(&ao);
        if (error) {
-               phr->u.s.data = os_error_code;
-               kfree(ao.priv);
+               delete_adapter_obj(&ao);
                phr->error = error;
+               phr->u.s.data = os_error_code;
                return;
        }
        /* need to update paParentAdapter */
@@ -492,20 +452,13 @@ static void subsys_delete_adapter(struct hpi_message *phm,
        struct hpi_response *phr)
 {
        struct hpi_adapter_obj *pao = NULL;
-       struct hpi_hw_obj *phw;
 
-       pao = hpi_find_adapter(phm->adapter_index);
+       pao = hpi_find_adapter(phm->obj_index);
        if (!pao)
                return;
 
-       phw = (struct hpi_hw_obj *)pao->priv;
-
-       if (pao->has_control_cache)
-               hpi_free_control_cache(phw->p_cache);
-
+       delete_adapter_obj(pao);
        hpi_delete_adapter(pao);
-       kfree(phw);
-
        phr->error = 0;
 }
 
@@ -519,9 +472,6 @@ static short create_adapter_obj(struct hpi_adapter_obj *pao,
        u32 control_cache_count = 0;
        struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
 
-       /* init error reporting */
-       pao->dsp_crashed = 0;
-
        /* The PCI2040 has the following address map */
        /* BAR0 - 4K = HPI control and status registers on PCI2040 (HPI CSR) */
        /* BAR1 - 32K = HPI registers on DSP */
@@ -575,36 +525,36 @@ static short create_adapter_obj(struct hpi_adapter_obj *pao,
        /* get info about the adapter by asking the adapter */
        /* send a HPI_ADAPTER_GET_INFO message */
        {
-               struct hpi_message hM;
-               struct hpi_response hR0;        /* response from DSP 0 */
-               struct hpi_response hR1;        /* response from DSP 1 */
+               struct hpi_message hm;
+               struct hpi_response hr0;        /* response from DSP 0 */
+               struct hpi_response hr1;        /* response from DSP 1 */
                u16 error = 0;
 
                HPI_DEBUG_LOG(VERBOSE, "send ADAPTER_GET_INFO\n");
-               memset(&hM, 0, sizeof(hM));
-               hM.type = HPI_TYPE_MESSAGE;
-               hM.size = sizeof(struct hpi_message);
-               hM.object = HPI_OBJ_ADAPTER;
-               hM.function = HPI_ADAPTER_GET_INFO;
-               hM.adapter_index = 0;
-               memset(&hR0, 0, sizeof(hR0));
-               memset(&hR1, 0, sizeof(hR1));
-               hR0.size = sizeof(hR0);
-               hR1.size = sizeof(hR1);
-
-               error = hpi6000_message_response_sequence(pao, 0, &hM, &hR0);
-               if (hR0.error) {
-                       HPI_DEBUG_LOG(DEBUG, "message error %d\n", hR0.error);
-                       return hR0.error;
+               memset(&hm, 0, sizeof(hm));
+               hm.type = HPI_TYPE_MESSAGE;
+               hm.size = sizeof(struct hpi_message);
+               hm.object = HPI_OBJ_ADAPTER;
+               hm.function = HPI_ADAPTER_GET_INFO;
+               hm.adapter_index = 0;
+               memset(&hr0, 0, sizeof(hr0));
+               memset(&hr1, 0, sizeof(hr1));
+               hr0.size = sizeof(hr0);
+               hr1.size = sizeof(hr1);
+
+               error = hpi6000_message_response_sequence(pao, 0, &hm, &hr0);
+               if (hr0.error) {
+                       HPI_DEBUG_LOG(DEBUG, "message error %d\n", hr0.error);
+                       return hr0.error;
                }
                if (phw->num_dsp == 2) {
-                       error = hpi6000_message_response_sequence(pao, 1, &hM,
-                               &hR1);
+                       error = hpi6000_message_response_sequence(pao, 1, &hm,
+                               &hr1);
                        if (error)
                                return error;
                }
-               pao->adapter_type = hR0.u.a.adapter_type;
-               pao->index = hR0.u.a.adapter_index;
+               pao->adapter_type = hr0.u.ax.info.adapter_type;
+               pao->index = hr0.u.ax.info.adapter_index;
        }
 
        memset(&phw->control_cache[0], 0,
@@ -618,22 +568,34 @@ static short create_adapter_obj(struct hpi_adapter_obj *pao,
                control_cache_count =
                        hpi_read_word(&phw->ado[0],
                        HPI_HIF_ADDR(control_cache_count));
-               pao->has_control_cache = 1;
 
                phw->p_cache =
                        hpi_alloc_control_cache(control_cache_count,
-                       control_cache_size, (struct hpi_control_cache_info *)
+                       control_cache_size, (unsigned char *)
                        &phw->control_cache[0]
                        );
-               if (!phw->p_cache)
-                       pao->has_control_cache = 0;
-       } else
-               pao->has_control_cache = 0;
+               if (phw->p_cache)
+                       pao->has_control_cache = 1;
+       }
 
        HPI_DEBUG_LOG(DEBUG, "get adapter info ASI%04X index %d\n",
                pao->adapter_type, pao->index);
        pao->open = 0;  /* upon creation the adapter is closed */
-       return 0;
+
+       return hpi_add_adapter(pao);
+}
+
+static void delete_adapter_obj(struct hpi_adapter_obj *pao)
+{
+       struct hpi_hw_obj *phw = (struct hpi_hw_obj *)pao->priv;
+
+       if (pao->has_control_cache)
+               hpi_free_control_cache(phw->p_cache);
+
+       /* reset DSPs on adapter */
+       iowrite32(0x0003000F, phw->dw2040_HPICSR + HPI_RESET);
+
+       kfree(phw);
 }
 
 /************************************************************************/
@@ -645,11 +607,13 @@ static void adapter_get_asserts(struct hpi_adapter_obj *pao,
 #ifndef HIDE_PCI_ASSERTS
        /* if we have PCI2040 asserts then collect them */
        if ((gw_pci_read_asserts > 0) || (gw_pci_write_asserts > 0)) {
-               phr->u.a.serial_number =
+               phr->u.ax.assert.p1 =
                        gw_pci_read_asserts * 100 + gw_pci_write_asserts;
-               phr->u.a.adapter_index = 1;     /* assert count */
-               phr->u.a.adapter_type = -1;     /* "dsp index" */
-               strcpy(phr->u.a.sz_adapter_assert, "PCI2040 error");
+               phr->u.ax.assert.p2 = 0;
+               phr->u.ax.assert.count = 1;     /* assert count */
+               phr->u.ax.assert.dsp_index = -1;        /* "dsp index" */
+               strcpy(phr->u.ax.assert.sz_message, "PCI2040 error");
+               phr->u.ax.assert.dsp_msg_addr = 0;
                gw_pci_read_asserts = 0;
                gw_pci_write_asserts = 0;
                phr->error = 0;
@@ -686,10 +650,10 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
 
        /* NOTE don't use wAdapterType in this routine. It is not setup yet */
 
-       switch (pao->pci.subsys_device_id) {
+       switch (pao->pci.pci_dev->subsystem_device) {
        case 0x5100:
        case 0x5110:    /* ASI5100 revB or higher with C6711D */
-       case 0x5200:    /* ASI5200 PC_ie version of ASI5100 */
+       case 0x5200:    /* ASI5200 PCIe version of ASI5100 */
        case 0x6100:
        case 0x6200:
                boot_load_family = HPI_ADAPTER_FAMILY_ASI(0x6200);
@@ -709,8 +673,9 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
         * note that bits 4..15 are read-only and so should always return zero,
         * even though we wrote 1 to them
         */
-       for (i = 0; i < 1000; i++)
-               delay = ioread32(phw->dw2040_HPICSR + HPI_RESET);
+       hpios_delay_micro_seconds(1000);
+       delay = ioread32(phw->dw2040_HPICSR + HPI_RESET);
+
        if (delay != dw2040_reset) {
                HPI_DEBUG_LOG(ERROR, "INIT_PCI2040 %x %x\n", dw2040_reset,
                        delay);
@@ -743,8 +708,7 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
        dw2040_reset = dw2040_reset & (~0x00000008);
        iowrite32(dw2040_reset, phw->dw2040_HPICSR + HPI_RESET);
        /*delay to allow DSP to get going */
-       for (i = 0; i < 100; i++)
-               delay = ioread32(phw->dw2040_HPICSR + HPI_RESET);
+       hpios_delay_micro_seconds(100);
 
        /* loop through all DSPs, downloading DSP code */
        for (dsp_index = 0; dsp_index < phw->num_dsp; dsp_index++) {
@@ -783,27 +747,27 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
                         */
                        /* bypass PLL */
                        hpi_write_word(pdo, 0x01B7C100, 0x0000);
-                       for (i = 0; i < 100; i++)
-                               delay = ioread32(phw->dw2040_HPICSR +
-                                       HPI_RESET);
+                       hpios_delay_micro_seconds(100);
 
                        /*  ** use default of PLL  x7 ** */
                        /* EMIF = 225/3=75MHz */
                        hpi_write_word(pdo, 0x01B7C120, 0x8002);
+                       hpios_delay_micro_seconds(100);
+
                        /* peri = 225/2 */
                        hpi_write_word(pdo, 0x01B7C11C, 0x8001);
+                       hpios_delay_micro_seconds(100);
+
                        /* cpu  = 225/1 */
                        hpi_write_word(pdo, 0x01B7C118, 0x8000);
-                       /* ~200us delay */
-                       for (i = 0; i < 2000; i++)
-                               delay = ioread32(phw->dw2040_HPICSR +
-                                       HPI_RESET);
+
+                       /* ~2ms delay */
+                       hpios_delay_micro_seconds(2000);
+
                        /* PLL not bypassed */
                        hpi_write_word(pdo, 0x01B7C100, 0x0001);
-                       /* ~200us delay */
-                       for (i = 0; i < 2000; i++)
-                               delay = ioread32(phw->dw2040_HPICSR +
-                                       HPI_RESET);
+                       /* ~2ms delay */
+                       hpios_delay_micro_seconds(2000);
                }
 
                /* test r/w to internal DSP memory
@@ -927,9 +891,7 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
                }
 
                /* delay a little to allow SDRAM and DSP to "get going" */
-
-               for (i = 0; i < 1000; i++)
-                       delay = ioread32(phw->dw2040_HPICSR + HPI_RESET);
+               hpios_delay_micro_seconds(1000);
 
                /* test access to SDRAM */
                {
@@ -976,7 +938,7 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
 
                /* write the DSP code down into the DSPs memory */
                /*HpiDspCode_Open(nBootLoadFamily,&DspCode,pdwOsErrorCode); */
-               dsp_code.ps_dev = pao->pci.p_os_data;
+               dsp_code.ps_dev = pao->pci.pci_dev;
 
                error = hpi_dsp_code_open(boot_load_family, &dsp_code,
                        pos_error_code);
@@ -1073,8 +1035,7 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
 
                /* step 3. Start code by sending interrupt */
                iowrite32(0x00030003, pdo->prHPI_control);
-               for (i = 0; i < 10000; i++)
-                       delay = ioread32(phw->dw2040_HPICSR + HPI_RESET);
+               hpios_delay_micro_seconds(10000);
 
                /* wait for a non-zero value in hostcmd -
                 * indicating initialization is complete
@@ -1101,7 +1062,7 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
                         * locks up with a bluescreen (NOT GPF or pagefault).
                         */
                        else
-                               hpios_delay_micro_seconds(1000);
+                               hpios_delay_micro_seconds(10000);
                }
                if (timeout == 0)
                        return HPI6000_ERROR_INIT_NOACK;
@@ -1132,14 +1093,14 @@ static short hpi6000_adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
                                mask = 0xFFFFFF00L;
                                /* ASI5100 uses AX6 code, */
                                /* but has no PLD r/w register to test */
-                               if (HPI_ADAPTER_FAMILY_ASI(pao->pci.
-                                               subsys_device_id) ==
+                               if (HPI_ADAPTER_FAMILY_ASI(pao->pci.pci_dev->
+                                               subsystem_device) ==
                                        HPI_ADAPTER_FAMILY_ASI(0x5100))
                                        mask = 0x00000000L;
                                /* ASI5200 uses AX6 code, */
                                /* but has no PLD r/w register to test */
-                               if (HPI_ADAPTER_FAMILY_ASI(pao->pci.
-                                               subsys_device_id) ==
+                               if (HPI_ADAPTER_FAMILY_ASI(pao->pci.pci_dev->
+                                               subsystem_device) ==
                                        HPI_ADAPTER_FAMILY_ASI(0x5200))
                                        mask = 0x00000000L;
                                break;
@@ -1204,7 +1165,7 @@ static u32 hpi_read_word(struct dsp_obj *pdo, u32 address)
        u32 data = 0;
 
        if (hpi_set_address(pdo, address))
-               return 0;       /*? no way to return error */
+               return 0;       /*? No way to return error */
 
        /* take care of errata in revB DSP (2.0.1) */
        data = ioread32(pdo->prHPI_data);
@@ -1340,10 +1301,6 @@ static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
        u32 *p_data;
        u16 error = 0;
 
-       /* does the DSP we are referencing exist? */
-       if (dsp_index >= phw->num_dsp)
-               return HPI6000_ERROR_MSG_INVALID_DSP_INDEX;
-
        ack = hpi6000_wait_dsp_ack(pao, dsp_index, HPI_HIF_IDLE);
        if (ack & HPI_HIF_ERROR_MASK) {
                pao->dsp_crashed++;
@@ -1351,9 +1308,7 @@ static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
        }
        pao->dsp_crashed = 0;
 
-       /* send the message */
-
-       /* get the address and size */
+       /* get the message address and size */
        if (phw->message_buffer_address_on_dsp == 0) {
                timeout = TIMEOUT;
                do {
@@ -1368,10 +1323,9 @@ static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
        } else
                address = phw->message_buffer_address_on_dsp;
 
-       /*        dwLength = sizeof(struct hpi_message); */
        length = phm->size;
 
-       /* send it */
+       /* send the message */
        p_data = (u32 *)phm;
        if (hpi6000_dsp_block_write32(pao, dsp_index, address, p_data,
                        (u16)length / 4))
@@ -1385,7 +1339,7 @@ static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
        if (ack & HPI_HIF_ERROR_MASK)
                return HPI6000_ERROR_MSG_RESP_GET_RESP_ACK;
 
-       /* get the address and size */
+       /* get the response address */
        if (phw->response_buffer_address_on_dsp == 0) {
                timeout = TIMEOUT;
                do {
@@ -1409,7 +1363,7 @@ static short hpi6000_message_response_sequence(struct hpi_adapter_obj *pao,
        if (!timeout)
                length = sizeof(struct hpi_response);
 
-       /* get it */
+       /* get the response */
        p_data = (u32 *)phr;
        if (hpi6000_dsp_block_read32(pao, dsp_index, address, p_data,
                        (u16)length / 4))
@@ -1827,13 +1781,13 @@ static void hw_message(struct hpi_adapter_obj *pao, struct hpi_message *phm,
                error = hpi6000_get_data(pao, dsp_index, phm, phr);
                break;
        case HPI_ADAPTER_GET_ASSERT:
-               phr->u.a.adapter_index = 0;     /* dsp 0 default */
+               phr->u.ax.assert.dsp_index = 0; /* dsp 0 default */
                if (num_dsp == 2) {
-                       if (!phr->u.a.adapter_type) {
+                       if (!phr->u.ax.assert.count) {
                                /* no assert from dsp 0, check dsp 1 */
                                error = hpi6000_message_response_sequence(pao,
                                        1, phm, phr);
-                               phr->u.a.adapter_index = 1;
+                               phr->u.ax.assert.dsp_index = 1;
                        }
                }
        }
index 2672f6591ceb7246b9a0a24ecbfa8f4cf2c46288..b740edc29b1c904fc0af5b2a4d7e55d862733923 100644 (file)
 
 /*****************************************************************************/
 /* HPI6205 specific error codes */
-#define HPI6205_ERROR_BASE                      1000
-/*#define HPI6205_ERROR_MEM_ALLOC 1001 */
+#define HPI6205_ERROR_BASE                      1000   /* not actually used anywhere */
+
+/* operational/messaging errors */
+#define HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT     1015
+#define HPI6205_ERROR_MSG_RESP_TIMEOUT          1016
+
+/* initialization/bootload errors */
 #define HPI6205_ERROR_6205_NO_IRQ               1002
 #define HPI6205_ERROR_6205_INIT_FAILED          1003
-/*#define HPI6205_ERROR_MISSING_DSPCODE 1004 */
-#define HPI6205_ERROR_UNKNOWN_PCI_DEVICE        1005
 #define HPI6205_ERROR_6205_REG                  1006
 #define HPI6205_ERROR_6205_DSPPAGE              1007
-#define HPI6205_ERROR_BAD_DSPINDEX              1008
 #define HPI6205_ERROR_C6713_HPIC                1009
 #define HPI6205_ERROR_C6713_HPIA                1010
 #define HPI6205_ERROR_C6713_PLL                 1011
 #define HPI6205_ERROR_DSP_INTMEM                1012
 #define HPI6205_ERROR_DSP_EXTMEM                1013
 #define HPI6205_ERROR_DSP_PLD                   1014
-#define HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT     1015
-#define HPI6205_ERROR_MSG_RESP_TIMEOUT          1016
 #define HPI6205_ERROR_6205_EEPROM               1017
 #define HPI6205_ERROR_DSP_EMIF                  1018
 
-#define hpi6205_error(dsp_index, err) (err)
 /*****************************************************************************/
 /* for C6205 PCI i/f */
 /* Host Status Register (HSR) bitfields */
@@ -208,8 +207,8 @@ static void instream_start(struct hpi_adapter_obj *pao,
 static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,
        u32 address);
 
-static u16 boot_loader_write_mem32(struct hpi_adapter_obj *pao, int dsp_index,
-       u32 address, u32 data);
+static void boot_loader_write_mem32(struct hpi_adapter_obj *pao,
+       int dsp_index, u32 address, u32 data);
 
 static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao,
        int dsp_index);
@@ -229,17 +228,7 @@ static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index);
 
 static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
 {
-
        switch (phm->function) {
-       case HPI_SUBSYS_OPEN:
-       case HPI_SUBSYS_CLOSE:
-       case HPI_SUBSYS_GET_INFO:
-       case HPI_SUBSYS_DRIVER_UNLOAD:
-       case HPI_SUBSYS_DRIVER_LOAD:
-       case HPI_SUBSYS_FIND_ADAPTERS:
-               /* messages that should not get here */
-               phr->error = HPI_ERROR_UNIMPLEMENTED;
-               break;
        case HPI_SUBSYS_CREATE_ADAPTER:
                subsys_create_adapter(phm, phr);
                break;
@@ -257,15 +246,22 @@ static void control_message(struct hpi_adapter_obj *pao,
 {
 
        struct hpi_hw_obj *phw = pao->priv;
+       u16 pending_cache_error = 0;
 
        switch (phm->function) {
        case HPI_CONTROL_GET_STATE:
                if (pao->has_control_cache) {
-                       rmb();  /* make sure we see updates DM_aed from DSP */
-                       if (hpi_check_control_cache(phw->p_cache, phm, phr))
+                       rmb();  /* make sure we see updates DMAed from DSP */
+                       if (hpi_check_control_cache(phw->p_cache, phm, phr)) {
                                break;
+                       } else if (phm->u.c.attribute == HPI_METER_PEAK) {
+                               pending_cache_error =
+                                       HPI_ERROR_CONTROL_CACHING;
+                       }
                }
                hw_message(pao, phm, phr);
+               if (pending_cache_error && !phr->error)
+                       phr->error = pending_cache_error;
                break;
        case HPI_CONTROL_GET_INFO:
                hw_message(pao, phm, phr);
@@ -273,7 +269,8 @@ static void control_message(struct hpi_adapter_obj *pao,
        case HPI_CONTROL_SET_STATE:
                hw_message(pao, phm, phr);
                if (pao->has_control_cache)
-                       hpi_sync_control_cache(phw->p_cache, phm, phr);
+                       hpi_cmn_control_cache_sync_to_msg(phw->p_cache, phm,
+                               phr);
                break;
        default:
                phr->error = HPI_ERROR_INVALID_FUNC;
@@ -298,7 +295,7 @@ static void outstream_message(struct hpi_adapter_obj *pao,
        if (phm->obj_index >= HPI_MAX_STREAMS) {
                phr->error = HPI_ERROR_INVALID_STREAM;
                HPI_DEBUG_LOG(WARNING,
-                       "message referencing invalid stream %d "
+                       "Message referencing invalid stream %d "
                        "on adapter index %d\n", phm->obj_index,
                        phm->adapter_index);
                return;
@@ -342,7 +339,7 @@ static void instream_message(struct hpi_adapter_obj *pao,
        if (phm->obj_index >= HPI_MAX_STREAMS) {
                phr->error = HPI_ERROR_INVALID_STREAM;
                HPI_DEBUG_LOG(WARNING,
-                       "message referencing invalid stream %d "
+                       "Message referencing invalid stream %d "
                        "on adapter index %d\n", phm->obj_index,
                        phm->adapter_index);
                return;
@@ -385,8 +382,8 @@ void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
         * All other messages are ignored unless the adapter index matches
         * an adapter in the HPI
         */
-       HPI_DEBUG_LOG(DEBUG, "HPI obj=%d, func=%d\n", phm->object,
-               phm->function);
+       /* HPI_DEBUG_LOG(DEBUG, "HPI Obj=%d, Func=%d\n", phm->wObject,
+          phm->wFunction); */
 
        /* if Dsp has crashed then do not communicate with it any more */
        if (phm->object != HPI_OBJ_SUBSYSTEM) {
@@ -411,8 +408,7 @@ void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
 
        /* Init default response  */
        if (phm->function != HPI_SUBSYS_CREATE_ADAPTER)
-               hpi_init_response(phr, phm->object, phm->function,
-                       HPI_ERROR_PROCESSING_MESSAGE);
+               phr->error = HPI_ERROR_PROCESSING_MESSAGE;
 
        HPI_DEBUG_LOG(VERBOSE, "start of switch\n");
        switch (phm->type) {
@@ -423,9 +419,6 @@ void HPI_6205(struct hpi_message *phm, struct hpi_response *phr)
                        break;
 
                case HPI_OBJ_ADAPTER:
-                       phr->size =
-                               sizeof(struct hpi_response_header) +
-                               sizeof(struct hpi_adapter_res);
                        adapter_message(pao, phm, phr);
                        break;
 
@@ -474,14 +467,6 @@ static void subsys_create_adapter(struct hpi_message *phm,
 
        memset(&ao, 0, sizeof(ao));
 
-       /* this HPI only creates adapters for TI/PCI devices */
-       if (phm->u.s.resource.bus_type != HPI_BUS_PCI)
-               return;
-       if (phm->u.s.resource.r.pci->vendor_id != HPI_PCI_VENDOR_ID_TI)
-               return;
-       if (phm->u.s.resource.r.pci->device_id != HPI_PCI_DEV_ID_DSP6205)
-               return;
-
        ao.priv = kzalloc(sizeof(struct hpi_hw_obj), GFP_KERNEL);
        if (!ao.priv) {
                HPI_DEBUG_LOG(ERROR, "cant get mem for adapter object\n");
@@ -491,12 +476,10 @@ static void subsys_create_adapter(struct hpi_message *phm,
 
        ao.pci = *phm->u.s.resource.r.pci;
        err = create_adapter_obj(&ao, &os_error_code);
-       if (!err)
-               err = hpi_add_adapter(&ao);
        if (err) {
-               phr->u.s.data = os_error_code;
                delete_adapter_obj(&ao);
                phr->error = err;
+               phr->u.s.data = os_error_code;
                return;
        }
 
@@ -513,7 +496,7 @@ static void subsys_delete_adapter(struct hpi_message *phm,
        struct hpi_adapter_obj *pao;
        struct hpi_hw_obj *phw;
 
-       pao = hpi_find_adapter(phm->adapter_index);
+       pao = hpi_find_adapter(phm->obj_index);
        if (!pao) {
                phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
                return;
@@ -526,6 +509,7 @@ static void subsys_delete_adapter(struct hpi_message *phm,
        iowrite32(C6205_HDCR_WARMRESET, phw->prHDCR);
 
        delete_adapter_obj(pao);
+       hpi_delete_adapter(pao);
        phr->error = 0;
 }
 
@@ -566,7 +550,7 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
 
        if (hpios_locked_mem_alloc(&phw->h_locked_mem,
                        sizeof(struct bus_master_interface),
-                       pao->pci.p_os_data))
+                       pao->pci.pci_dev))
                phw->p_interface_buffer = NULL;
        else if (hpios_locked_mem_get_virt_addr(&phw->h_locked_mem,
                        (void *)&phw->p_interface_buffer))
@@ -591,7 +575,7 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
 
        /* allow boot load even if mem alloc wont work */
        if (!phw->p_interface_buffer)
-               return hpi6205_error(0, HPI_ERROR_MEMORY_ALLOC);
+               return HPI_ERROR_MEMORY_ALLOC;
 
        interface = phw->p_interface_buffer;
 
@@ -604,12 +588,12 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
 
        if (temp1 & C6205_HSR_INTSRC)
                HPI_DEBUG_LOG(INFO,
-                       "interrupt confirming DSP code running OK\n");
+                       "Interrupt confirming DSP code running OK\n");
        else {
                HPI_DEBUG_LOG(ERROR,
-                       "timed out waiting for interrupt "
+                       "Timed out waiting for interrupt "
                        "confirming DSP code running\n");
-               return hpi6205_error(0, HPI6205_ERROR_6205_NO_IRQ);
+               return HPI6205_ERROR_6205_NO_IRQ;
        }
 
        /* reset the interrupt */
@@ -619,21 +603,22 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
        /* make sure the DSP has started ok */
        if (!wait_dsp_ack(phw, H620_HIF_RESET, HPI6205_TIMEOUT * 10)) {
                HPI_DEBUG_LOG(ERROR, "timed out waiting reset state \n");
-               return hpi6205_error(0, HPI6205_ERROR_6205_INIT_FAILED);
+               return HPI6205_ERROR_6205_INIT_FAILED;
        }
        /* Note that *pao, *phw are zeroed after allocation,
         * so pointers and flags are NULL by default.
         * Allocate bus mastering control cache buffer and tell the DSP about it
         */
        if (interface->control_cache.number_of_controls) {
-               void *p_control_cache_virtual;
+               u8 *p_control_cache_virtual;
 
                err = hpios_locked_mem_alloc(&phw->h_control_cache,
                        interface->control_cache.size_in_bytes,
-                       pao->pci.p_os_data);
+                       pao->pci.pci_dev);
                if (!err)
                        err = hpios_locked_mem_get_virt_addr(&phw->
-                               h_control_cache, &p_control_cache_virtual);
+                               h_control_cache,
+                               (void *)&p_control_cache_virtual);
                if (!err) {
                        memset(p_control_cache_virtual, 0,
                                interface->control_cache.size_in_bytes);
@@ -642,7 +627,6 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
                                hpi_alloc_control_cache(interface->
                                control_cache.number_of_controls,
                                interface->control_cache.size_in_bytes,
-                               (struct hpi_control_cache_info *)
                                p_control_cache_virtual);
                        if (!phw->p_cache)
                                err = HPI_ERROR_MEMORY_ALLOC;
@@ -666,7 +650,7 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
        if (interface->async_buffer.b.size) {
                err = hpios_locked_mem_alloc(&phw->h_async_event_buffer,
                        interface->async_buffer.b.size *
-                       sizeof(struct hpi_async_event), pao->pci.p_os_data);
+                       sizeof(struct hpi_async_event), pao->pci.pci_dev);
                if (!err)
                        err = hpios_locked_mem_get_virt_addr
                                (&phw->h_async_event_buffer, (void *)
@@ -693,47 +677,50 @@ static u16 create_adapter_obj(struct hpi_adapter_obj *pao,
        send_dsp_command(phw, H620_HIF_IDLE);
 
        {
-               struct hpi_message hM;
-               struct hpi_response hR;
+               struct hpi_message hm;
+               struct hpi_response hr;
                u32 max_streams;
 
                HPI_DEBUG_LOG(VERBOSE, "init ADAPTER_GET_INFO\n");
-               memset(&hM, 0, sizeof(hM));
-               hM.type = HPI_TYPE_MESSAGE;
-               hM.size = sizeof(hM);
-               hM.object = HPI_OBJ_ADAPTER;
-               hM.function = HPI_ADAPTER_GET_INFO;
-               hM.adapter_index = 0;
-               memset(&hR, 0, sizeof(hR));
-               hR.size = sizeof(hR);
-
-               err = message_response_sequence(pao, &hM, &hR);
+               memset(&hm, 0, sizeof(hm));
+               hm.type = HPI_TYPE_MESSAGE;
+               hm.size = sizeof(hm);
+               hm.object = HPI_OBJ_ADAPTER;
+               hm.function = HPI_ADAPTER_GET_INFO;
+               hm.adapter_index = 0;
+               memset(&hr, 0, sizeof(hr));
+               hr.size = sizeof(hr);
+
+               err = message_response_sequence(pao, &hm, &hr);
                if (err) {
                        HPI_DEBUG_LOG(ERROR, "message transport error %d\n",
                                err);
                        return err;
                }
-               if (hR.error)
-                       return hR.error;
+               if (hr.error)
+                       return hr.error;
 
-               pao->adapter_type = hR.u.a.adapter_type;
-               pao->index = hR.u.a.adapter_index;
+               pao->adapter_type = hr.u.ax.info.adapter_type;
+               pao->index = hr.u.ax.info.adapter_index;
 
-               max_streams = hR.u.a.num_outstreams + hR.u.a.num_instreams;
+               max_streams =
+                       hr.u.ax.info.num_outstreams +
+                       hr.u.ax.info.num_instreams;
 
                hpios_locked_mem_prepare((max_streams * 6) / 10, max_streams,
-                       65536, pao->pci.p_os_data);
+                       65536, pao->pci.pci_dev);
 
                HPI_DEBUG_LOG(VERBOSE,
                        "got adapter info type %x index %d serial %d\n",
-                       hR.u.a.adapter_type, hR.u.a.adapter_index,
-                       hR.u.a.serial_number);
+                       hr.u.ax.info.adapter_type, hr.u.ax.info.adapter_index,
+                       hr.u.ax.info.serial_number);
        }
 
        pao->open = 0;  /* upon creation the adapter is closed */
 
        HPI_DEBUG_LOG(INFO, "bootload DSP OK\n");
-       return 0;
+
+       return hpi_add_adapter(pao);
 }
 
 /** Free memory areas allocated by adapter
@@ -776,9 +763,8 @@ static void delete_adapter_obj(struct hpi_adapter_obj *pao)
                        phw->outstream_host_buffer_size[i] = 0;
                }
 
-       hpios_locked_mem_unprepare(pao->pci.p_os_data);
+       hpios_locked_mem_unprepare(pao->pci.pci_dev);
 
-       hpi_delete_adapter(pao);
        kfree(phw);
 }
 
@@ -824,7 +810,7 @@ static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,
 
                err = hpios_locked_mem_alloc(&phw->outstream_host_buffers
                        [phm->obj_index], phm->u.d.u.buffer.buffer_size,
-                       pao->pci.p_os_data);
+                       pao->pci.pci_dev);
 
                if (err) {
                        phr->error = HPI_ERROR_INVALID_DATASIZE;
@@ -861,7 +847,7 @@ static void outstream_host_buffer_allocate(struct hpi_adapter_obj *pao,
                if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.
                                buffer_size - 1)) {
                        HPI_DEBUG_LOG(ERROR,
-                               "buffer size must be 2^N not %d\n",
+                               "Buffer size must be 2^N not %d\n",
                                phm->u.d.u.buffer.buffer_size);
                        phr->error = HPI_ERROR_INVALID_DATASIZE;
                        return;
@@ -966,51 +952,6 @@ static void outstream_write(struct hpi_adapter_obj *pao,
        hpi_init_response(phr, phm->object, phm->function, 0);
        status = &interface->outstream_host_buffer_status[phm->obj_index];
 
-       if (phw->flag_outstream_just_reset[phm->obj_index]) {
-               /* First OutStremWrite() call following reset will write data to the
-                  adapter's buffers, reducing delay before stream can start. The DSP
-                  takes care of setting the stream data format using format information
-                  embedded in phm.
-                */
-               int partial_write = 0;
-               unsigned int original_size = 0;
-
-               phw->flag_outstream_just_reset[phm->obj_index] = 0;
-
-               /* Send the first buffer to the DSP the old way. */
-               /* Limit size of first transfer - */
-               /* expect that this will not usually be triggered. */
-               if (phm->u.d.u.data.data_size > HPI6205_SIZEOF_DATA) {
-                       partial_write = 1;
-                       original_size = phm->u.d.u.data.data_size;
-                       phm->u.d.u.data.data_size = HPI6205_SIZEOF_DATA;
-               }
-               /* write it */
-               phm->function = HPI_OSTREAM_WRITE;
-               hw_message(pao, phm, phr);
-
-               if (phr->error)
-                       return;
-
-               /* update status information that the DSP would typically
-                * update (and will update next time the DSP
-                * buffer update task reads data from the host BBM buffer)
-                */
-               status->auxiliary_data_available = phm->u.d.u.data.data_size;
-               status->host_index += phm->u.d.u.data.data_size;
-               status->dSP_index += phm->u.d.u.data.data_size;
-
-               /* if we did a full write, we can return from here. */
-               if (!partial_write)
-                       return;
-
-               /* tweak buffer parameters and let the rest of the */
-               /* buffer land in internal BBM buffer */
-               phm->u.d.u.data.data_size =
-                       original_size - HPI6205_SIZEOF_DATA;
-               phm->u.d.u.data.pb_data += HPI6205_SIZEOF_DATA;
-       }
-
        space_available = outstream_get_space_available(status);
        if (space_available < phm->u.d.u.data.data_size) {
                phr->error = HPI_ERROR_INVALID_DATASIZE;
@@ -1047,6 +988,24 @@ static void outstream_write(struct hpi_adapter_obj *pao,
                memcpy(p_bbm_data, p_app_data + l_first_write,
                        phm->u.d.u.data.data_size - l_first_write);
        }
+
+       /*
+        * This version relies on the DSP code triggering an OStream buffer
+        * update immediately following a SET_FORMAT call. The host has
+        * already written data into the BBM buffer, but the DSP won't know about
+        * it until dwHostIndex is adjusted.
+        */
+       if (phw->flag_outstream_just_reset[phm->obj_index]) {
+               /* Format can only change after reset. Must tell DSP. */
+               u16 function = phm->function;
+               phw->flag_outstream_just_reset[phm->obj_index] = 0;
+               phm->function = HPI_OSTREAM_SET_FORMAT;
+               hw_message(pao, phm, phr);      /* send the format to the DSP */
+               phm->function = function;
+               if (phr->error)
+                       return;
+       }
+
        status->host_index += phm->u.d.u.data.data_size;
 }
 
@@ -1132,7 +1091,7 @@ static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,
 
                err = hpios_locked_mem_alloc(&phw->instream_host_buffers[phm->
                                obj_index], phm->u.d.u.buffer.buffer_size,
-                       pao->pci.p_os_data);
+                       pao->pci.pci_dev);
 
                if (err) {
                        phr->error = HPI_ERROR_INVALID_DATASIZE;
@@ -1163,7 +1122,7 @@ static void instream_host_buffer_allocate(struct hpi_adapter_obj *pao,
                if (phm->u.d.u.buffer.buffer_size & (phm->u.d.u.buffer.
                                buffer_size - 1)) {
                        HPI_DEBUG_LOG(ERROR,
-                               "buffer size must be 2^N not %d\n",
+                               "Buffer size must be 2^N not %d\n",
                                phm->u.d.u.buffer.buffer_size);
                        phr->error = HPI_ERROR_INVALID_DATASIZE;
                        return;
@@ -1344,7 +1303,7 @@ static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
        struct hpi_hw_obj *phw = pao->priv;
        struct dsp_code dsp_code;
        u16 boot_code_id[HPI6205_MAX_FILES_TO_LOAD];
-       u16 firmware_id = pao->pci.subsys_device_id;
+       u16 firmware_id = pao->pci.pci_dev->subsystem_device;
        u32 temp;
        int dsp = 0, i = 0;
        u16 err = 0;
@@ -1381,7 +1340,7 @@ static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
        temp = ioread32(phw->prHSR);
        if ((temp & (C6205_HSR_CFGERR | C6205_HSR_EEREAD)) !=
                C6205_HSR_EEREAD)
-               return hpi6205_error(0, HPI6205_ERROR_6205_EEPROM);
+               return HPI6205_ERROR_6205_EEPROM;
        temp |= 0x04;
        /* disable PINTA interrupt */
        iowrite32(temp, phw->prHSR);
@@ -1389,27 +1348,27 @@ static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
        /* check control register reports PCI boot mode */
        temp = ioread32(phw->prHDCR);
        if (!(temp & C6205_HDCR_PCIBOOT))
-               return hpi6205_error(0, HPI6205_ERROR_6205_REG);
+               return HPI6205_ERROR_6205_REG;
 
-       /* try writing a couple of numbers to the DSP page register */
+       /* try writing a few numbers to the DSP page register */
        /* and reading them back. */
-       temp = 1;
+       temp = 3;
        iowrite32(temp, phw->prDSPP);
        if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
-               return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE);
+               return HPI6205_ERROR_6205_DSPPAGE;
        temp = 2;
        iowrite32(temp, phw->prDSPP);
        if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
-               return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE);
-       temp = 3;
+               return HPI6205_ERROR_6205_DSPPAGE;
+       temp = 1;
        iowrite32(temp, phw->prDSPP);
        if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
-               return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE);
+               return HPI6205_ERROR_6205_DSPPAGE;
        /* reset DSP page to the correct number */
        temp = 0;
        iowrite32(temp, phw->prDSPP);
        if ((temp | C6205_DSPP_MAP1) != ioread32(phw->prDSPP))
-               return hpi6205_error(0, HPI6205_ERROR_6205_DSPPAGE);
+               return HPI6205_ERROR_6205_DSPPAGE;
        phw->dsp_page = 0;
 
        /* release 6713 from reset before 6205 is bootloaded.
@@ -1455,7 +1414,7 @@ static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
                        return err;
 
                /* write the DSP code down into the DSPs memory */
-               dsp_code.ps_dev = pao->pci.p_os_data;
+               dsp_code.ps_dev = pao->pci.pci_dev;
                err = hpi_dsp_code_open(boot_code_id[dsp], &dsp_code,
                        pos_error_code);
                if (err)
@@ -1484,10 +1443,8 @@ static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
                        if (err)
                                break;
                        for (i = 0; i < (int)length; i++) {
-                               err = boot_loader_write_mem32(pao, dsp,
-                                       address, *pcode);
-                               if (err)
-                                       break;
+                               boot_loader_write_mem32(pao, dsp, address,
+                                       *pcode);
                                /* dummy read every 4 words */
                                /* for 6205 advisory 1.4.4 */
                                if (i % 4 == 0)
@@ -1561,7 +1518,7 @@ static u16 adapter_boot_load_dsp(struct hpi_adapter_obj *pao,
                host_mailbox_address_on_dsp = 0x80000000;
                while ((physicalPC_iaddress != physicalPC_iaddress_verify)
                        && time_out--) {
-                       err = boot_loader_write_mem32(pao, 0,
+                       boot_loader_write_mem32(pao, 0,
                                host_mailbox_address_on_dsp,
                                physicalPC_iaddress);
                        physicalPC_iaddress_verify =
@@ -1631,11 +1588,10 @@ static u32 boot_loader_read_mem32(struct hpi_adapter_obj *pao, int dsp_index,
        return data;
 }
 
-static u16 boot_loader_write_mem32(struct hpi_adapter_obj *pao, int dsp_index,
-       u32 address, u32 data)
+static void boot_loader_write_mem32(struct hpi_adapter_obj *pao,
+       int dsp_index, u32 address, u32 data)
 {
        struct hpi_hw_obj *phw = pao->priv;
-       u16 err = 0;
        __iomem u32 *p_data;
        /*      u32 dwVerifyData=0; */
 
@@ -1675,15 +1631,11 @@ static u16 boot_loader_write_mem32(struct hpi_adapter_obj *pao, int dsp_index,
 
                /* dummy read every 4 words for 6205 advisory 1.4.4 */
                boot_loader_read_mem32(pao, 0, 0);
-       } else
-               err = hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX);
-       return err;
+       }
 }
 
 static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
 {
-       u16 err = 0;
-
        if (dsp_index == 0) {
                u32 setting;
 
@@ -1711,8 +1663,7 @@ static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
                boot_loader_write_mem32(pao, dsp_index, 0x01800008, setting);
                if (setting != boot_loader_read_mem32(pao, dsp_index,
                                0x01800008))
-                       return hpi6205_error(dsp_index,
-                               HPI6205_ERROR_DSP_EMIF);
+                       return HPI6205_ERROR_DSP_EMIF;
 
                /* EMIF CE1 setup - 32 bit async. This is 6713 #1 HPI, */
                /* which occupies D15..0. 6713 starts at 27MHz, so need */
@@ -1725,8 +1676,7 @@ static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
                boot_loader_write_mem32(pao, dsp_index, 0x01800004, setting);
                if (setting != boot_loader_read_mem32(pao, dsp_index,
                                0x01800004))
-                       return hpi6205_error(dsp_index,
-                               HPI6205_ERROR_DSP_EMIF);
+                       return HPI6205_ERROR_DSP_EMIF;
 
                /* EMIF CE2 setup - 32 bit async. This is 6713 #2 HPI, */
                /* which occupies D15..0. 6713 starts at 27MHz, so need */
@@ -1738,8 +1688,7 @@ static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
                boot_loader_write_mem32(pao, dsp_index, 0x01800010, setting);
                if (setting != boot_loader_read_mem32(pao, dsp_index,
                                0x01800010))
-                       return hpi6205_error(dsp_index,
-                               HPI6205_ERROR_DSP_EMIF);
+                       return HPI6205_ERROR_DSP_EMIF;
 
                /* EMIF CE3 setup - 32 bit async. */
                /* This is the PLD on the ASI5000 cards only */
@@ -1750,8 +1699,7 @@ static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
                boot_loader_write_mem32(pao, dsp_index, 0x01800014, setting);
                if (setting != boot_loader_read_mem32(pao, dsp_index,
                                0x01800014))
-                       return hpi6205_error(dsp_index,
-                               HPI6205_ERROR_DSP_EMIF);
+                       return HPI6205_ERROR_DSP_EMIF;
 
                /* set EMIF SDRAM control for 2Mx32 SDRAM (512x32x4 bank) */
                /*  need to use this else DSP code crashes? */
@@ -1775,12 +1723,9 @@ static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
                read_data =
                        0xFFF7 & boot_loader_read_mem32(pao, 0, HPICL_ADDR);
                if (write_data != read_data) {
-                       err = hpi6205_error(dsp_index,
-                               HPI6205_ERROR_C6713_HPIC);
                        HPI_DEBUG_LOG(ERROR, "HPICL %x %x\n", write_data,
                                read_data);
-
-                       return err;
+                       return HPI6205_ERROR_C6713_HPIC;
                }
                /* HPIA - walking ones test */
                write_data = 1;
@@ -1798,11 +1743,9 @@ static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
                                                HPIAH_ADDR))
                                << 16);
                        if (read_data != write_data) {
-                               err = hpi6205_error(dsp_index,
-                                       HPI6205_ERROR_C6713_HPIA);
                                HPI_DEBUG_LOG(ERROR, "HPIA %x %x\n",
                                        write_data, read_data);
-                               return err;
+                               return HPI6205_ERROR_C6713_HPIA;
                        }
                        write_data = write_data << 1;
                }
@@ -1847,9 +1790,7 @@ static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
                /* PLL should not be bypassed! */
                if ((boot_loader_read_mem32(pao, dsp_index, 0x01B7C100) & 0xF)
                        != 0x0001) {
-                       err = hpi6205_error(dsp_index,
-                               HPI6205_ERROR_C6713_PLL);
-                       return err;
+                       return HPI6205_ERROR_C6713_PLL;
                }
                /* setup C67x EMIF  (note this is the only use of
                   BAR1 via BootLoader_WriteMem32) */
@@ -1867,10 +1808,9 @@ static u16 boot_loader_config_emif(struct hpi_adapter_obj *pao, int dsp_index)
                hpios_delay_micro_seconds(1000);
        } else if (dsp_index == 2) {
                /* DSP 2 is a C6713 */
+       }
 
-       } else
-               err = hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX);
-       return err;
+       return 0;
 }
 
 static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
@@ -1896,7 +1836,7 @@ static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
                                test_addr);
                        if (data != test_data) {
                                HPI_DEBUG_LOG(VERBOSE,
-                                       "memtest error details  "
+                                       "Memtest error details  "
                                        "%08x %08x %08x %i\n", test_addr,
                                        test_data, data, dsp_index);
                                return 1;       /* error */
@@ -1916,7 +1856,7 @@ static u16 boot_loader_test_memory(struct hpi_adapter_obj *pao, int dsp_index,
                data = boot_loader_read_mem32(pao, dsp_index, test_addr);
                if (data != test_data) {
                        HPI_DEBUG_LOG(VERBOSE,
-                               "memtest error details  "
+                               "Memtest error details  "
                                "%08x %08x %08x %i\n", test_addr, test_data,
                                data, dsp_index);
                        return 1;       /* error */
@@ -1946,8 +1886,8 @@ static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,
                        /* 64K data mem */
                        err = boot_loader_test_memory(pao, dsp_index,
                                0x80000000, 0x10000);
-       } else if ((dsp_index == 1) || (dsp_index == 2)) {
-               /* DSP 1&2 are a C6713 */
+       } else if (dsp_index == 1) {
+               /* DSP 1 is a C6713 */
                /* 192K internal mem */
                err = boot_loader_test_memory(pao, dsp_index, 0x00000000,
                        0x30000);
@@ -1955,11 +1895,10 @@ static u16 boot_loader_test_internal_memory(struct hpi_adapter_obj *pao,
                        /* 64K internal mem / L2 cache */
                        err = boot_loader_test_memory(pao, dsp_index,
                                0x00030000, 0x10000);
-       } else
-               return hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX);
+       }
 
        if (err)
-               return hpi6205_error(dsp_index, HPI6205_ERROR_DSP_INTMEM);
+               return HPI6205_ERROR_DSP_INTMEM;
        else
                return 0;
 }
@@ -1972,24 +1911,23 @@ static u16 boot_loader_test_external_memory(struct hpi_adapter_obj *pao,
 
        if (dsp_index == 0) {
                /* only test for SDRAM if an ASI5000 card */
-               if (pao->pci.subsys_device_id == 0x5000) {
+               if (pao->pci.pci_dev->subsystem_device == 0x5000) {
                        /* DSP 0 is always C6205 */
                        dRAM_start_address = 0x00400000;
                        dRAM_size = 0x200000;
                        /*dwDRAMinc=1024; */
                } else
                        return 0;
-       } else if ((dsp_index == 1) || (dsp_index == 2)) {
+       } else if (dsp_index == 1) {
                /* DSP 1 is a C6713 */
                dRAM_start_address = 0x80000000;
                dRAM_size = 0x200000;
                /*dwDRAMinc=1024; */
-       } else
-               return hpi6205_error(dsp_index, HPI6205_ERROR_BAD_DSPINDEX);
+       }
 
        if (boot_loader_test_memory(pao, dsp_index, dRAM_start_address,
                        dRAM_size))
-               return hpi6205_error(dsp_index, HPI6205_ERROR_DSP_EXTMEM);
+               return HPI6205_ERROR_DSP_EXTMEM;
        return 0;
 }
 
@@ -1998,28 +1936,25 @@ static u16 boot_loader_test_pld(struct hpi_adapter_obj *pao, int dsp_index)
        u32 data = 0;
        if (dsp_index == 0) {
                /* only test for DSP0 PLD on ASI5000 card */
-               if (pao->pci.subsys_device_id == 0x5000) {
+               if (pao->pci.pci_dev->subsystem_device == 0x5000) {
                        /* PLD is located at CE3=0x03000000 */
                        data = boot_loader_read_mem32(pao, dsp_index,
                                0x03000008);
                        if ((data & 0xF) != 0x5)
-                               return hpi6205_error(dsp_index,
-                                       HPI6205_ERROR_DSP_PLD);
+                               return HPI6205_ERROR_DSP_PLD;
                        data = boot_loader_read_mem32(pao, dsp_index,
                                0x0300000C);
                        if ((data & 0xF) != 0xA)
-                               return hpi6205_error(dsp_index,
-                                       HPI6205_ERROR_DSP_PLD);
+                               return HPI6205_ERROR_DSP_PLD;
                }
        } else if (dsp_index == 1) {
                /* DSP 1 is a C6713 */
-               if (pao->pci.subsys_device_id == 0x8700) {
+               if (pao->pci.pci_dev->subsystem_device == 0x8700) {
                        /* PLD is located at CE1=0x90000000 */
                        data = boot_loader_read_mem32(pao, dsp_index,
                                0x90000010);
                        if ((data & 0xFF) != 0xAA)
-                               return hpi6205_error(dsp_index,
-                                       HPI6205_ERROR_DSP_PLD);
+                               return HPI6205_ERROR_DSP_PLD;
                        /* 8713 - LED on */
                        boot_loader_write_mem32(pao, dsp_index, 0x90000000,
                                0x02);
@@ -2079,7 +2014,7 @@ static short hpi6205_transfer_data(struct hpi_adapter_obj *pao, u8 *p_data,
                if (!temp2) {
                        /* timed out */
                        HPI_DEBUG_LOG(ERROR,
-                               "timed out waiting for " "state %d got %d\n",
+                               "Timed out waiting for " "state %d got %d\n",
                                operation, interface->dsp_ack);
 
                        break;
@@ -2099,7 +2034,7 @@ static short hpi6205_transfer_data(struct hpi_adapter_obj *pao, u8 *p_data,
                        HPI6205_TIMEOUT - time_out, this_copy);
                if (temp2 == C6205_HSR_INTSRC) {
                        HPI_DEBUG_LOG(VERBOSE,
-                               "interrupt from HIF <data> OK\n");
+                               "Interrupt from HIF <data> OK\n");
                        /*
                           if(interface->dwDspAck != nOperation) {
                           HPI_DEBUG_LOG(DEBUG("interface->dwDspAck=%d,
@@ -2111,7 +2046,7 @@ static short hpi6205_transfer_data(struct hpi_adapter_obj *pao, u8 *p_data,
 /* need to handle this differently... */
                else {
                        HPI_DEBUG_LOG(ERROR,
-                               "interrupt from HIF <data> BAD\n");
+                               "Interrupt from HIF <data> BAD\n");
                        err = HPI_ERROR_DSP_HARDWARE;
                }
 
@@ -2183,22 +2118,34 @@ static u16 message_response_sequence(struct hpi_adapter_obj *pao,
        u16 err = 0;
 
        message_count++;
+       if (phm->size > sizeof(interface->u)) {
+               /* really MESSAGE buffer too small */
+               phr->error = HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
+               phr->specific_error = sizeof(interface->u);
+               phr->size = sizeof(struct hpi_response_header);
+               HPI_DEBUG_LOG(ERROR,
+                       "message len %d too big for buffer %ld \n", phm->size,
+                       sizeof(interface->u));
+               return 0;
+       }
+
        /* Assume buffer of type struct bus_master_interface
           is allocated "noncacheable" */
 
        if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
                HPI_DEBUG_LOG(DEBUG, "timeout waiting for idle\n");
-               return hpi6205_error(0, HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT);
+               return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;
        }
-       interface->u.message_buffer = *phm;
+
+       memcpy(&interface->u.message_buffer, phm, phm->size);
        /* signal we want a response */
        send_dsp_command(phw, H620_HIF_GET_RESP);
 
        time_out2 = wait_dsp_ack(phw, H620_HIF_GET_RESP, HPI6205_TIMEOUT);
 
-       if (time_out2 == 0) {
+       if (!time_out2) {
                HPI_DEBUG_LOG(ERROR,
-                       "(%u) timed out waiting for " "GET_RESP state [%x]\n",
+                       "(%u) Timed out waiting for " "GET_RESP state [%x]\n",
                        message_count, interface->dsp_ack);
        } else {
                HPI_DEBUG_LOG(VERBOSE,
@@ -2232,7 +2179,7 @@ static u16 message_response_sequence(struct hpi_adapter_obj *pao,
        } else {
                /* can we do anything else in response to the error ? */
                HPI_DEBUG_LOG(ERROR,
-                       "interrupt from HIF module BAD (function %x)\n",
+                       "Interrupt from HIF module BAD (function %x)\n",
                        phm->function);
        }
 
@@ -2241,25 +2188,37 @@ static u16 message_response_sequence(struct hpi_adapter_obj *pao,
 #endif
 
        /* read the result */
-       if (time_out != 0)
-               *phr = interface->u.response_buffer;
-
+       if (time_out) {
+               if (interface->u.response_buffer.size <= phr->size)
+                       memcpy(phr, &interface->u.response_buffer,
+                               interface->u.response_buffer.size);
+               else {
+                       HPI_DEBUG_LOG(ERROR,
+                               "response len %d too big for buffer %d\n",
+                               interface->u.response_buffer.size, phr->size);
+                       memcpy(phr, &interface->u.response_buffer,
+                               sizeof(struct hpi_response_header));
+                       phr->error = HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
+                       phr->specific_error =
+                               interface->u.response_buffer.size;
+                       phr->size = sizeof(struct hpi_response_header);
+               }
+       }
        /* set interface back to idle */
        send_dsp_command(phw, H620_HIF_IDLE);
 
-       if ((time_out == 0) || (time_out2 == 0)) {
+       if (!time_out || !time_out2) {
                HPI_DEBUG_LOG(DEBUG, "something timed out!\n");
-               return hpi6205_error(0, HPI6205_ERROR_MSG_RESP_TIMEOUT);
+               return HPI6205_ERROR_MSG_RESP_TIMEOUT;
        }
        /* special case for adapter close - */
        /* wait for the DSP to indicate it is idle */
        if (phm->function == HPI_ADAPTER_CLOSE) {
                if (!wait_dsp_ack(phw, H620_HIF_IDLE, HPI6205_TIMEOUT)) {
                        HPI_DEBUG_LOG(DEBUG,
-                               "timeout waiting for idle "
+                               "Timeout waiting for idle "
                                "(on adapter_close)\n");
-                       return hpi6205_error(0,
-                               HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT);
+                       return HPI6205_ERROR_MSG_RESP_IDLE_TIMEOUT;
                }
        }
        err = hpi_validate_response(phm, phr);
index 1adae0857cda197e492d6ccbcad245c9abaee514..e00edb0ceddaf5df0a3fdb98335244adce3f9f24 100644 (file)
@@ -78,8 +78,8 @@ struct bus_master_interface {
        u32 dsp_ack;
        u32 transfer_size_in_bytes;
        union {
-               struct hpi_message message_buffer;
-               struct hpi_response response_buffer;
+               struct hpi_message_header message_buffer;
+               struct hpi_response_header response_buffer;
                u8 b_data[HPI6205_SIZEOF_DATA];
        } u;
        struct controlcache_6205 control_cache;
index 16f502d459deda02fee5e2f34e2b8d016fe3debd..0d500841f1a57bb42683d727bcaf2c9c00575f5f 100644 (file)
@@ -28,7 +28,7 @@ HPI internal definitions
 /** maximum number of memory regions mapped to an adapter */
 #define HPI_MAX_ADAPTER_MEM_SPACES (2)
 
-/* Each OS needs its own hpios.h, or specific define as above */
+/* Each OS needs its own hpios.h */
 #include "hpios.h"
 
 /* physical memory allocation */
@@ -49,7 +49,7 @@ HpiOs_LockedMem_GetPyhsAddr() will always succed on the returned handle.
 */
 u16 hpios_locked_mem_alloc(struct consistent_dma_area *p_locked_mem_handle,
                                                           /**< memory handle */
-       u32 size, /**< size in bytes to allocate */
+       u32 size, /**< Size in bytes to allocate */
        struct pci_dev *p_os_reference
        /**< OS specific data required for memory allocation */
        );
@@ -96,41 +96,6 @@ typedef void hpi_handler_func(struct hpi_message *, struct hpi_response *);
 #define compile_time_assert(cond, msg) \
     typedef char ASSERT_##msg[(cond) ? 1 : -1]
 
-/*/////////////////////////////////////////////////////////////////////////// */
-/* Private HPI Entity related definitions                                     */
-
-#define STR_SIZE_FIELD_MAX 65535U
-#define STR_TYPE_FIELD_MAX 255U
-#define STR_ROLE_FIELD_MAX 255U
-
-struct hpi_entity_str {
-       u16 size;
-       u8 type;
-       u8 role;
-};
-
-#if defined(_MSC_VER)
-#pragma warning(push)
-#pragma warning(disable : 4200)
-#endif
-
-struct hpi_entity {
-       struct hpi_entity_str header;
-#if ! defined(HPI_OS_DSP_C6000) || (defined(HPI_OS_DSP_C6000) && (__TI_COMPILER_VERSION__ > 6000008))
-       /* DSP C6000 compiler v6.0.8 and lower
-          do not support  flexible array member */
-       u8 value[];
-#else
-       /* NOTE! Using sizeof(struct hpi_entity) will give erroneous results */
-#define HPI_INTERNAL_WARN_ABOUT_ENTITY_VALUE
-       u8 value[1];
-#endif
-};
-
-#if defined(_MSC_VER)
-#pragma warning(pop)
-#endif
-
 /******************************************* bus types */
 enum HPI_BUSES {
        HPI_BUS_ISAPNP = 1,
@@ -143,202 +108,127 @@ enum HPI_BUSES {
 /* (in order of control type ID */
 
 /* This allows for 255 control types, 256 unique attributes each */
-#define HPI_CTL_ATTR(ctl, ai) (HPI_CONTROL_##ctl * 0x100 + ai)
+#define HPI_CTL_ATTR(ctl, ai) ((HPI_CONTROL_##ctl << 8) + ai)
 
 /* Get the sub-index of the attribute for a control type */
-#define HPI_CTL_ATTR_INDEX(i) (i&0xff)
+#define HPI_CTL_ATTR_INDEX(i) (i & 0xff)
 
 /* Extract the control from the control attribute */
-#define HPI_CTL_ATTR_CONTROL(i) (i>>8)
-
-/* Generic control attributes.  */
-
-/** Enable a control.
-0=disable, 1=enable
-\note generic to all mixer plugins?
-*/
-#define HPI_GENERIC_ENABLE HPI_CTL_ATTR(GENERIC, 1)
+#define HPI_CTL_ATTR_CONTROL(i) (i >> 8)
 
 /** Enable event generation for a control.
 0=disable, 1=enable
 \note generic to all controls that can generate events
 */
-#define HPI_GENERIC_EVENT_ENABLE HPI_CTL_ATTR(GENERIC, 2)
-
-/* Volume Control attributes */
-#define HPI_VOLUME_GAIN                 HPI_CTL_ATTR(VOLUME, 1)
-#define HPI_VOLUME_AUTOFADE             HPI_CTL_ATTR(VOLUME, 2)
-
-/** For HPI_ControlQuery() to get the number of channels of a volume control*/
-#define HPI_VOLUME_NUM_CHANNELS         HPI_CTL_ATTR(VOLUME, 6)
-#define HPI_VOLUME_RANGE                HPI_CTL_ATTR(VOLUME, 10)
-
-/** Level Control attributes */
-#define HPI_LEVEL_GAIN                  HPI_CTL_ATTR(LEVEL, 1)
-#define HPI_LEVEL_RANGE                 HPI_CTL_ATTR(LEVEL, 10)
-
-/* Meter Control attributes */
-/** return RMS signal level */
-#define HPI_METER_RMS                   HPI_CTL_ATTR(METER, 1)
-/** return peak signal level */
-#define HPI_METER_PEAK                  HPI_CTL_ATTR(METER, 2)
-/** ballistics for ALL rms meters on adapter */
-#define HPI_METER_RMS_BALLISTICS        HPI_CTL_ATTR(METER, 3)
-/** ballistics for ALL peak meters on adapter */
-#define HPI_METER_PEAK_BALLISTICS       HPI_CTL_ATTR(METER, 4)
-
-/** For HPI_ControlQuery() to get the number of channels of a meter control*/
-#define HPI_METER_NUM_CHANNELS          HPI_CTL_ATTR(METER, 5)
-
-/* Multiplexer control attributes */
-#define HPI_MULTIPLEXER_SOURCE          HPI_CTL_ATTR(MULTIPLEXER, 1)
-#define HPI_MULTIPLEXER_QUERYSOURCE     HPI_CTL_ATTR(MULTIPLEXER, 2)
-
-/** AES/EBU transmitter control attributes */
-/** AESEBU or SPDIF */
-#define HPI_AESEBUTX_FORMAT             HPI_CTL_ATTR(AESEBUTX, 1)
-#define HPI_AESEBUTX_SAMPLERATE         HPI_CTL_ATTR(AESEBUTX, 3)
-#define HPI_AESEBUTX_CHANNELSTATUS      HPI_CTL_ATTR(AESEBUTX, 4)
-#define HPI_AESEBUTX_USERDATA           HPI_CTL_ATTR(AESEBUTX, 5)
-
-/** AES/EBU receiver control attributes */
-#define HPI_AESEBURX_FORMAT             HPI_CTL_ATTR(AESEBURX, 1)
-#define HPI_AESEBURX_ERRORSTATUS        HPI_CTL_ATTR(AESEBURX, 2)
-#define HPI_AESEBURX_SAMPLERATE         HPI_CTL_ATTR(AESEBURX, 3)
-#define HPI_AESEBURX_CHANNELSTATUS      HPI_CTL_ATTR(AESEBURX, 4)
-#define HPI_AESEBURX_USERDATA           HPI_CTL_ATTR(AESEBURX, 5)
-
-/** \defgroup tuner_defs Tuners
-\{
-*/
-/** \defgroup tuner_attrs Tuner control attributes
-\{
-*/
-#define HPI_TUNER_BAND                  HPI_CTL_ATTR(TUNER, 1)
-#define HPI_TUNER_FREQ                  HPI_CTL_ATTR(TUNER, 2)
-#define HPI_TUNER_LEVEL                 HPI_CTL_ATTR(TUNER, 3)
-#define HPI_TUNER_AUDIOMUTE             HPI_CTL_ATTR(TUNER, 4)
-/* use TUNER_STATUS instead */
-#define HPI_TUNER_VIDEO_STATUS          HPI_CTL_ATTR(TUNER, 5)
-#define HPI_TUNER_GAIN                  HPI_CTL_ATTR(TUNER, 6)
-#define HPI_TUNER_STATUS                HPI_CTL_ATTR(TUNER, 7)
-#define HPI_TUNER_MODE                  HPI_CTL_ATTR(TUNER, 8)
-/** RDS data. */
-#define HPI_TUNER_RDS                   HPI_CTL_ATTR(TUNER, 9)
-/** Audio pre-emphasis. */
-#define HPI_TUNER_DEEMPHASIS            HPI_CTL_ATTR(TUNER, 10)
-/** HD Radio tuner program control. */
-#define HPI_TUNER_PROGRAM               HPI_CTL_ATTR(TUNER, 11)
-/** HD Radio tuner digital signal quality. */
-#define HPI_TUNER_HDRADIO_SIGNAL_QUALITY        HPI_CTL_ATTR(TUNER, 12)
-/** HD Radio SDK firmware version. */
-#define HPI_TUNER_HDRADIO_SDK_VERSION   HPI_CTL_ATTR(TUNER, 13)
-/** HD Radio DSP firmware version. */
-#define HPI_TUNER_HDRADIO_DSP_VERSION   HPI_CTL_ATTR(TUNER, 14)
-/** HD Radio signal blend (force analog, or automatic). */
-#define HPI_TUNER_HDRADIO_BLEND         HPI_CTL_ATTR(TUNER, 15)
-
-/** \} */
-
-/** \defgroup pads_attrs Tuner PADs control attributes
-\{
-*/
-/** The text string containing the station/channel combination. */
-#define HPI_PAD_CHANNEL_NAME            HPI_CTL_ATTR(PAD, 1)
-/** The text string containing the artist. */
-#define HPI_PAD_ARTIST                  HPI_CTL_ATTR(PAD, 2)
-/** The text string containing the title. */
-#define HPI_PAD_TITLE                   HPI_CTL_ATTR(PAD, 3)
-/** The text string containing the comment. */
-#define HPI_PAD_COMMENT                 HPI_CTL_ATTR(PAD, 4)
-/** The integer containing the PTY code. */
-#define HPI_PAD_PROGRAM_TYPE            HPI_CTL_ATTR(PAD, 5)
-/** The integer containing the program identification. */
-#define HPI_PAD_PROGRAM_ID              HPI_CTL_ATTR(PAD, 6)
-/** The integer containing whether traffic information is supported.
-Contains either 1 or 0. */
-#define HPI_PAD_TA_SUPPORT              HPI_CTL_ATTR(PAD, 7)
-/** The integer containing whether traffic announcement is in progress.
-Contains either 1 or 0. */
-#define HPI_PAD_TA_ACTIVE               HPI_CTL_ATTR(PAD, 8)
-/** \} */
-/** \} */
-
-/* VOX control attributes */
-#define HPI_VOX_THRESHOLD               HPI_CTL_ATTR(VOX, 1)
-
-/*?? channel mode used hpi_multiplexer_source attribute == 1 */
-#define HPI_CHANNEL_MODE_MODE HPI_CTL_ATTR(CHANNEL_MODE, 1)
-
-/** \defgroup channel_modes Channel Modes
-Used for HPI_ChannelModeSet/Get()
-\{
+
+/** Unique identifiers for every control attribute
 */
-/** Left channel out = left channel in, Right channel out = right channel in. */
-#define HPI_CHANNEL_MODE_NORMAL                 1
-/** Left channel out = right channel in, Right channel out = left channel in. */
-#define HPI_CHANNEL_MODE_SWAP                   2
-/** Left channel out = left channel in, Right channel out = left channel in. */
-#define HPI_CHANNEL_MODE_LEFT_TO_STEREO         3
-/** Left channel out = right channel in, Right channel out = right channel in.*/
-#define HPI_CHANNEL_MODE_RIGHT_TO_STEREO        4
-/** Left channel out = (left channel in + right channel in)/2,
-    Right channel out = mute. */
-#define HPI_CHANNEL_MODE_STEREO_TO_LEFT         5
-/** Left channel out = mute,
-    Right channel out = (right channel in + left channel in)/2. */
-#define HPI_CHANNEL_MODE_STEREO_TO_RIGHT        6
-#define HPI_CHANNEL_MODE_LAST                   6
-/** \} */
-
-/* Bitstream control set attributes */
-#define HPI_BITSTREAM_DATA_POLARITY     HPI_CTL_ATTR(BITSTREAM, 1)
-#define HPI_BITSTREAM_CLOCK_EDGE        HPI_CTL_ATTR(BITSTREAM, 2)
-#define HPI_BITSTREAM_CLOCK_SOURCE      HPI_CTL_ATTR(BITSTREAM, 3)
+enum HPI_CONTROL_ATTRIBUTES {
+       HPI_GENERIC_ENABLE = HPI_CTL_ATTR(GENERIC, 1),
+       HPI_GENERIC_EVENT_ENABLE = HPI_CTL_ATTR(GENERIC, 2),
+
+       HPI_VOLUME_GAIN = HPI_CTL_ATTR(VOLUME, 1),
+       HPI_VOLUME_AUTOFADE = HPI_CTL_ATTR(VOLUME, 2),
+       HPI_VOLUME_NUM_CHANNELS = HPI_CTL_ATTR(VOLUME, 6),
+       HPI_VOLUME_RANGE = HPI_CTL_ATTR(VOLUME, 10),
+
+       HPI_METER_RMS = HPI_CTL_ATTR(METER, 1),
+       HPI_METER_PEAK = HPI_CTL_ATTR(METER, 2),
+       HPI_METER_RMS_BALLISTICS = HPI_CTL_ATTR(METER, 3),
+       HPI_METER_PEAK_BALLISTICS = HPI_CTL_ATTR(METER, 4),
+       HPI_METER_NUM_CHANNELS = HPI_CTL_ATTR(METER, 5),
+
+       HPI_MULTIPLEXER_SOURCE = HPI_CTL_ATTR(MULTIPLEXER, 1),
+       HPI_MULTIPLEXER_QUERYSOURCE = HPI_CTL_ATTR(MULTIPLEXER, 2),
+
+       HPI_AESEBUTX_FORMAT = HPI_CTL_ATTR(AESEBUTX, 1),
+       HPI_AESEBUTX_SAMPLERATE = HPI_CTL_ATTR(AESEBUTX, 3),
+       HPI_AESEBUTX_CHANNELSTATUS = HPI_CTL_ATTR(AESEBUTX, 4),
+       HPI_AESEBUTX_USERDATA = HPI_CTL_ATTR(AESEBUTX, 5),
+
+       HPI_AESEBURX_FORMAT = HPI_CTL_ATTR(AESEBURX, 1),
+       HPI_AESEBURX_ERRORSTATUS = HPI_CTL_ATTR(AESEBURX, 2),
+       HPI_AESEBURX_SAMPLERATE = HPI_CTL_ATTR(AESEBURX, 3),
+       HPI_AESEBURX_CHANNELSTATUS = HPI_CTL_ATTR(AESEBURX, 4),
+       HPI_AESEBURX_USERDATA = HPI_CTL_ATTR(AESEBURX, 5),
+
+       HPI_LEVEL_GAIN = HPI_CTL_ATTR(LEVEL, 1),
+       HPI_LEVEL_RANGE = HPI_CTL_ATTR(LEVEL, 10),
+
+       HPI_TUNER_BAND = HPI_CTL_ATTR(TUNER, 1),
+       HPI_TUNER_FREQ = HPI_CTL_ATTR(TUNER, 2),
+       HPI_TUNER_LEVEL_AVG = HPI_CTL_ATTR(TUNER, 3),
+       HPI_TUNER_LEVEL_RAW = HPI_CTL_ATTR(TUNER, 4),
+       HPI_TUNER_SNR = HPI_CTL_ATTR(TUNER, 5),
+       HPI_TUNER_GAIN = HPI_CTL_ATTR(TUNER, 6),
+       HPI_TUNER_STATUS = HPI_CTL_ATTR(TUNER, 7),
+       HPI_TUNER_MODE = HPI_CTL_ATTR(TUNER, 8),
+       HPI_TUNER_RDS = HPI_CTL_ATTR(TUNER, 9),
+       HPI_TUNER_DEEMPHASIS = HPI_CTL_ATTR(TUNER, 10),
+       HPI_TUNER_PROGRAM = HPI_CTL_ATTR(TUNER, 11),
+       HPI_TUNER_HDRADIO_SIGNAL_QUALITY = HPI_CTL_ATTR(TUNER, 12),
+       HPI_TUNER_HDRADIO_SDK_VERSION = HPI_CTL_ATTR(TUNER, 13),
+       HPI_TUNER_HDRADIO_DSP_VERSION = HPI_CTL_ATTR(TUNER, 14),
+       HPI_TUNER_HDRADIO_BLEND = HPI_CTL_ATTR(TUNER, 15),
+
+       HPI_VOX_THRESHOLD = HPI_CTL_ATTR(VOX, 1),
+
+       HPI_CHANNEL_MODE_MODE = HPI_CTL_ATTR(CHANNEL_MODE, 1),
+
+       HPI_BITSTREAM_DATA_POLARITY = HPI_CTL_ATTR(BITSTREAM, 1),
+       HPI_BITSTREAM_CLOCK_EDGE = HPI_CTL_ATTR(BITSTREAM, 2),
+       HPI_BITSTREAM_CLOCK_SOURCE = HPI_CTL_ATTR(BITSTREAM, 3),
+       HPI_BITSTREAM_ACTIVITY = HPI_CTL_ATTR(BITSTREAM, 4),
+
+       HPI_SAMPLECLOCK_SOURCE = HPI_CTL_ATTR(SAMPLECLOCK, 1),
+       HPI_SAMPLECLOCK_SAMPLERATE = HPI_CTL_ATTR(SAMPLECLOCK, 2),
+       HPI_SAMPLECLOCK_SOURCE_INDEX = HPI_CTL_ATTR(SAMPLECLOCK, 3),
+       HPI_SAMPLECLOCK_LOCAL_SAMPLERATE = HPI_CTL_ATTR(SAMPLECLOCK, 4),
+       HPI_SAMPLECLOCK_AUTO = HPI_CTL_ATTR(SAMPLECLOCK, 5),
+       HPI_SAMPLECLOCK_LOCAL_LOCK = HPI_CTL_ATTR(SAMPLECLOCK, 6),
+
+       HPI_MICROPHONE_PHANTOM_POWER = HPI_CTL_ATTR(MICROPHONE, 1),
+
+       HPI_EQUALIZER_NUM_FILTERS = HPI_CTL_ATTR(EQUALIZER, 1),
+       HPI_EQUALIZER_FILTER = HPI_CTL_ATTR(EQUALIZER, 2),
+       HPI_EQUALIZER_COEFFICIENTS = HPI_CTL_ATTR(EQUALIZER, 3),
+
+       HPI_COMPANDER_PARAMS = HPI_CTL_ATTR(COMPANDER, 1),
+       HPI_COMPANDER_MAKEUPGAIN = HPI_CTL_ATTR(COMPANDER, 2),
+       HPI_COMPANDER_THRESHOLD = HPI_CTL_ATTR(COMPANDER, 3),
+       HPI_COMPANDER_RATIO = HPI_CTL_ATTR(COMPANDER, 4),
+       HPI_COMPANDER_ATTACK = HPI_CTL_ATTR(COMPANDER, 5),
+       HPI_COMPANDER_DECAY = HPI_CTL_ATTR(COMPANDER, 6),
+
+       HPI_COBRANET_SET = HPI_CTL_ATTR(COBRANET, 1),
+       HPI_COBRANET_GET = HPI_CTL_ATTR(COBRANET, 2),
+       HPI_COBRANET_SET_DATA = HPI_CTL_ATTR(COBRANET, 3),
+       HPI_COBRANET_GET_DATA = HPI_CTL_ATTR(COBRANET, 4),
+       HPI_COBRANET_GET_STATUS = HPI_CTL_ATTR(COBRANET, 5),
+       HPI_COBRANET_SEND_PACKET = HPI_CTL_ATTR(COBRANET, 6),
+       HPI_COBRANET_GET_PACKET = HPI_CTL_ATTR(COBRANET, 7),
+
+       HPI_TONEDETECTOR_THRESHOLD = HPI_CTL_ATTR(TONEDETECTOR, 1),
+       HPI_TONEDETECTOR_STATE = HPI_CTL_ATTR(TONEDETECTOR, 2),
+       HPI_TONEDETECTOR_FREQUENCY = HPI_CTL_ATTR(TONEDETECTOR, 3),
+
+       HPI_SILENCEDETECTOR_THRESHOLD = HPI_CTL_ATTR(SILENCEDETECTOR, 1),
+       HPI_SILENCEDETECTOR_STATE = HPI_CTL_ATTR(SILENCEDETECTOR, 2),
+       HPI_SILENCEDETECTOR_DELAY = HPI_CTL_ATTR(SILENCEDETECTOR, 3),
+
+       HPI_PAD_CHANNEL_NAME = HPI_CTL_ATTR(PAD, 1),
+       HPI_PAD_ARTIST = HPI_CTL_ATTR(PAD, 2),
+       HPI_PAD_TITLE = HPI_CTL_ATTR(PAD, 3),
+       HPI_PAD_COMMENT = HPI_CTL_ATTR(PAD, 4),
+       HPI_PAD_PROGRAM_TYPE = HPI_CTL_ATTR(PAD, 5),
+       HPI_PAD_PROGRAM_ID = HPI_CTL_ATTR(PAD, 6),
+       HPI_PAD_TA_SUPPORT = HPI_CTL_ATTR(PAD, 7),
+       HPI_PAD_TA_ACTIVE = HPI_CTL_ATTR(PAD, 8)
+};
 
 #define HPI_POLARITY_POSITIVE           0
 #define HPI_POLARITY_NEGATIVE           1
 
-/* Bitstream control get attributes */
-#define HPI_BITSTREAM_ACTIVITY          1
-
-/* SampleClock control attributes */
-#define HPI_SAMPLECLOCK_SOURCE                  HPI_CTL_ATTR(SAMPLECLOCK, 1)
-#define HPI_SAMPLECLOCK_SAMPLERATE              HPI_CTL_ATTR(SAMPLECLOCK, 2)
-#define HPI_SAMPLECLOCK_SOURCE_INDEX            HPI_CTL_ATTR(SAMPLECLOCK, 3)
-#define HPI_SAMPLECLOCK_LOCAL_SAMPLERATE\
-       HPI_CTL_ATTR(SAMPLECLOCK, 4)
-#define HPI_SAMPLECLOCK_AUTO                    HPI_CTL_ATTR(SAMPLECLOCK, 5)
-#define HPI_SAMPLECLOCK_LOCAL_LOCK                      HPI_CTL_ATTR(SAMPLECLOCK, 6)
-
-/* Microphone control attributes */
-#define HPI_MICROPHONE_PHANTOM_POWER HPI_CTL_ATTR(MICROPHONE, 1)
-
-/** Equalizer control attributes */
-/** Used to get number of filters in an EQ. (Can't set) */
-#define HPI_EQUALIZER_NUM_FILTERS HPI_CTL_ATTR(EQUALIZER, 1)
-/** Set/get the filter by type, freq, Q, gain */
-#define HPI_EQUALIZER_FILTER HPI_CTL_ATTR(EQUALIZER, 2)
-/** Get the biquad coefficients */
-#define HPI_EQUALIZER_COEFFICIENTS HPI_CTL_ATTR(EQUALIZER, 3)
-
-/* Note compander also uses HPI_GENERIC_ENABLE */
-#define HPI_COMPANDER_PARAMS     HPI_CTL_ATTR(COMPANDER, 1)
-#define HPI_COMPANDER_MAKEUPGAIN HPI_CTL_ATTR(COMPANDER, 2)
-#define HPI_COMPANDER_THRESHOLD  HPI_CTL_ATTR(COMPANDER, 3)
-#define HPI_COMPANDER_RATIO      HPI_CTL_ATTR(COMPANDER, 4)
-#define HPI_COMPANDER_ATTACK     HPI_CTL_ATTR(COMPANDER, 5)
-#define HPI_COMPANDER_DECAY      HPI_CTL_ATTR(COMPANDER, 6)
-
-/* Cobranet control attributes. */
-#define HPI_COBRANET_SET         HPI_CTL_ATTR(COBRANET, 1)
-#define HPI_COBRANET_GET         HPI_CTL_ATTR(COBRANET, 2)
-#define HPI_COBRANET_SET_DATA    HPI_CTL_ATTR(COBRANET, 3)
-#define HPI_COBRANET_GET_DATA    HPI_CTL_ATTR(COBRANET, 4)
-#define HPI_COBRANET_GET_STATUS  HPI_CTL_ATTR(COBRANET, 5)
-#define HPI_COBRANET_SEND_PACKET HPI_CTL_ATTR(COBRANET, 6)
-#define HPI_COBRANET_GET_PACKET  HPI_CTL_ATTR(COBRANET, 7)
-
 /*------------------------------------------------------------
  Cobranet Chip Bridge - copied from HMI.H
 ------------------------------------------------------------*/
@@ -398,66 +288,19 @@ Used for HPI_ChannelModeSet/Get()
 /** Base network time out is set to 100 milli-seconds. */
 #define HPI_ETHERNET_TIMEOUT_MS      (100)
 
-/** \defgroup tonedet_attr Tonedetector attributes
-\{
-Used by HPI_ToneDetector_Set() and HPI_ToneDetector_Get()
-*/
-
-/** Set the threshold level of a tonedetector,
-Threshold is a -ve number in units of dB/100,
-*/
-#define HPI_TONEDETECTOR_THRESHOLD HPI_CTL_ATTR(TONEDETECTOR, 1)
-
-/** Get the current state of tonedetection
-The result is a bitmap of detected tones.  pairs of bits represent the left
-and right channels, with left channel in LSB.
-The lowest frequency detector state is in the LSB
-*/
-#define HPI_TONEDETECTOR_STATE HPI_CTL_ATTR(TONEDETECTOR, 2)
-
-/** Get the frequency of a tonedetector band.
-*/
-#define HPI_TONEDETECTOR_FREQUENCY HPI_CTL_ATTR(TONEDETECTOR, 3)
-
-/**\}*/
-
-/** \defgroup silencedet_attr SilenceDetector attributes
-\{
-*/
-
-/** Get the current state of tonedetection
-The result is a bitmap with 1s for silent channels. Left channel is in LSB
-*/
-#define HPI_SILENCEDETECTOR_STATE \
-  HPI_CTL_ATTR(SILENCEDETECTOR, 2)
-
-/** Set the threshold level of a SilenceDetector,
-Threshold is a -ve number in units of dB/100,
-*/
-#define HPI_SILENCEDETECTOR_THRESHOLD \
-  HPI_CTL_ATTR(SILENCEDETECTOR, 1)
-
-/** get/set the silence time before the detector triggers
-*/
-#define HPI_SILENCEDETECTOR_DELAY \
-       HPI_CTL_ATTR(SILENCEDETECTOR, 3)
-
-/**\}*/
-
-/* Locked memory buffer alloc/free phases */
-/** use one message to allocate or free physical memory */
-#define HPI_BUFFER_CMD_EXTERNAL                 0
-/** alloc physical memory */
-#define HPI_BUFFER_CMD_INTERNAL_ALLOC           1
-/** send physical memory address to adapter */
-#define HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER    2
-/** notify adapter to stop using physical buffer */
-#define HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER   3
-/** free physical buffer */
-#define HPI_BUFFER_CMD_INTERNAL_FREE            4
-
-/******************************************* CONTROLX ATTRIBUTES ****/
-/* NOTE: All controlx attributes must be unique, unlike control attributes */
+/** Locked memory buffer alloc/free phases */
+enum HPI_BUFFER_CMDS {
+       /** use one message to allocate or free physical memory */
+       HPI_BUFFER_CMD_EXTERNAL = 0,
+       /** alloc physical memory */
+       HPI_BUFFER_CMD_INTERNAL_ALLOC = 1,
+       /** send physical memory address to adapter */
+       HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER = 2,
+       /** notify adapter to stop using physical buffer */
+       HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER = 3,
+       /** free physical buffer */
+       HPI_BUFFER_CMD_INTERNAL_FREE = 4
+};
 
 /*****************************************************************************/
 /*****************************************************************************/
@@ -482,6 +325,12 @@ Threshold is a -ve number in units of dB/100,
 #define HPI_USB_W2K_TAG                 0x57495341     /* "ASIW"       */
 #define HPI_USB_LINUX_TAG               0x4C495341     /* "ASIL"       */
 
+/** Invalid Adapter index
+Used in HPI messages that are not addressed to a specific adapter
+Used in DLL to indicate device not present
+*/
+#define HPI_ADAPTER_INDEX_INVALID 0xFFFF
+
 /** First 2 hex digits define the adapter family */
 #define HPI_ADAPTER_FAMILY_MASK         0xff00
 #define HPI_MODULE_FAMILY_MASK          0xfff0
@@ -490,178 +339,180 @@ Threshold is a -ve number in units of dB/100,
 #define HPI_MODULE_FAMILY_ASI(f)   (f & HPI_MODULE_FAMILY_MASK)
 #define HPI_ADAPTER_ASI(f)   (f)
 
-/******************************************* message types */
-#define HPI_TYPE_MESSAGE                        1
-#define HPI_TYPE_RESPONSE                       2
-#define HPI_TYPE_DATA                           3
-#define HPI_TYPE_SSX2BYPASS_MESSAGE             4
-
-/******************************************* object types */
-#define HPI_OBJ_SUBSYSTEM                       1
-#define HPI_OBJ_ADAPTER                         2
-#define HPI_OBJ_OSTREAM                         3
-#define HPI_OBJ_ISTREAM                         4
-#define HPI_OBJ_MIXER                           5
-#define HPI_OBJ_NODE                            6
-#define HPI_OBJ_CONTROL                         7
-#define HPI_OBJ_NVMEMORY                        8
-#define HPI_OBJ_GPIO                            9
-#define HPI_OBJ_WATCHDOG                        10
-#define HPI_OBJ_CLOCK                           11
-#define HPI_OBJ_PROFILE                         12
-#define HPI_OBJ_CONTROLEX                       13
-#define HPI_OBJ_ASYNCEVENT                      14
-
-#define HPI_OBJ_MAXINDEX                        14
-
-/******************************************* methods/functions */
-
-#define HPI_OBJ_FUNCTION_SPACING        0x100
-#define HPI_MAKE_INDEX(obj, index) (obj * HPI_OBJ_FUNCTION_SPACING + index)
+enum HPI_MESSAGE_TYPES {
+       HPI_TYPE_MESSAGE = 1,
+       HPI_TYPE_RESPONSE = 2,
+       HPI_TYPE_DATA = 3,
+       HPI_TYPE_SSX2BYPASS_MESSAGE = 4
+};
+
+enum HPI_OBJECT_TYPES {
+       HPI_OBJ_SUBSYSTEM = 1,
+       HPI_OBJ_ADAPTER = 2,
+       HPI_OBJ_OSTREAM = 3,
+       HPI_OBJ_ISTREAM = 4,
+       HPI_OBJ_MIXER = 5,
+       HPI_OBJ_NODE = 6,
+       HPI_OBJ_CONTROL = 7,
+       HPI_OBJ_NVMEMORY = 8,
+       HPI_OBJ_GPIO = 9,
+       HPI_OBJ_WATCHDOG = 10,
+       HPI_OBJ_CLOCK = 11,
+       HPI_OBJ_PROFILE = 12,
+       HPI_OBJ_CONTROLEX = 13,
+       HPI_OBJ_ASYNCEVENT = 14
+#define HPI_OBJ_MAXINDEX 14
+};
+
+#define HPI_OBJ_FUNCTION_SPACING 0x100
+#define HPI_FUNC_ID(obj, index) (HPI_OBJ_##obj * HPI_OBJ_FUNCTION_SPACING + index)
+
 #define HPI_EXTRACT_INDEX(fn) (fn & 0xff)
 
-/* SUB-SYSTEM */
-#define HPI_SUBSYS_OPEN                 HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 1)
-#define HPI_SUBSYS_GET_VERSION          HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 2)
-#define HPI_SUBSYS_GET_INFO             HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 3)
-#define HPI_SUBSYS_FIND_ADAPTERS        HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 4)
-#define HPI_SUBSYS_CREATE_ADAPTER       HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 5)
-#define HPI_SUBSYS_CLOSE                HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 6)
-#define HPI_SUBSYS_DELETE_ADAPTER       HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 7)
-#define HPI_SUBSYS_DRIVER_LOAD          HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 8)
-#define HPI_SUBSYS_DRIVER_UNLOAD        HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 9)
-#define HPI_SUBSYS_READ_PORT_8          HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 10)
-#define HPI_SUBSYS_WRITE_PORT_8         HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 11)
-#define HPI_SUBSYS_GET_NUM_ADAPTERS     HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 12)
-#define HPI_SUBSYS_GET_ADAPTER          HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 13)
-#define HPI_SUBSYS_SET_NETWORK_INTERFACE HPI_MAKE_INDEX(HPI_OBJ_SUBSYSTEM, 14)
-#define HPI_SUBSYS_FUNCTION_COUNT 14
-/* ADAPTER */
-#define HPI_ADAPTER_OPEN                HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 1)
-#define HPI_ADAPTER_CLOSE               HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 2)
-#define HPI_ADAPTER_GET_INFO            HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 3)
-#define HPI_ADAPTER_GET_ASSERT          HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 4)
-#define HPI_ADAPTER_TEST_ASSERT         HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 5)
-#define HPI_ADAPTER_SET_MODE            HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 6)
-#define HPI_ADAPTER_GET_MODE            HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 7)
-#define HPI_ADAPTER_ENABLE_CAPABILITY   HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 8)
-#define HPI_ADAPTER_SELFTEST            HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 9)
-#define HPI_ADAPTER_FIND_OBJECT         HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 10)
-#define HPI_ADAPTER_QUERY_FLASH         HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 11)
-#define HPI_ADAPTER_START_FLASH         HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 12)
-#define HPI_ADAPTER_PROGRAM_FLASH       HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 13)
-#define HPI_ADAPTER_SET_PROPERTY        HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 14)
-#define HPI_ADAPTER_GET_PROPERTY        HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 15)
-#define HPI_ADAPTER_ENUM_PROPERTY       HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 16)
-#define HPI_ADAPTER_MODULE_INFO         HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 17)
-#define HPI_ADAPTER_DEBUG_READ          HPI_MAKE_INDEX(HPI_OBJ_ADAPTER, 18)
+enum HPI_FUNCTION_IDS {
+       HPI_SUBSYS_OPEN = HPI_FUNC_ID(SUBSYSTEM, 1),
+       HPI_SUBSYS_GET_VERSION = HPI_FUNC_ID(SUBSYSTEM, 2),
+       HPI_SUBSYS_GET_INFO = HPI_FUNC_ID(SUBSYSTEM, 3),
+       HPI_SUBSYS_FIND_ADAPTERS = HPI_FUNC_ID(SUBSYSTEM, 4),
+       HPI_SUBSYS_CREATE_ADAPTER = HPI_FUNC_ID(SUBSYSTEM, 5),
+       HPI_SUBSYS_CLOSE = HPI_FUNC_ID(SUBSYSTEM, 6),
+       HPI_SUBSYS_DELETE_ADAPTER = HPI_FUNC_ID(SUBSYSTEM, 7),
+       HPI_SUBSYS_DRIVER_LOAD = HPI_FUNC_ID(SUBSYSTEM, 8),
+       HPI_SUBSYS_DRIVER_UNLOAD = HPI_FUNC_ID(SUBSYSTEM, 9),
+       HPI_SUBSYS_READ_PORT_8 = HPI_FUNC_ID(SUBSYSTEM, 10),
+       HPI_SUBSYS_WRITE_PORT_8 = HPI_FUNC_ID(SUBSYSTEM, 11),
+       HPI_SUBSYS_GET_NUM_ADAPTERS = HPI_FUNC_ID(SUBSYSTEM, 12),
+       HPI_SUBSYS_GET_ADAPTER = HPI_FUNC_ID(SUBSYSTEM, 13),
+       HPI_SUBSYS_SET_NETWORK_INTERFACE = HPI_FUNC_ID(SUBSYSTEM, 14),
+       HPI_SUBSYS_OPTION_INFO = HPI_FUNC_ID(SUBSYSTEM, 15),
+       HPI_SUBSYS_OPTION_GET = HPI_FUNC_ID(SUBSYSTEM, 16),
+       HPI_SUBSYS_OPTION_SET = HPI_FUNC_ID(SUBSYSTEM, 17),
+#define HPI_SUBSYS_FUNCTION_COUNT 17
+
+       HPI_ADAPTER_OPEN = HPI_FUNC_ID(ADAPTER, 1),
+       HPI_ADAPTER_CLOSE = HPI_FUNC_ID(ADAPTER, 2),
+       HPI_ADAPTER_GET_INFO = HPI_FUNC_ID(ADAPTER, 3),
+       HPI_ADAPTER_GET_ASSERT = HPI_FUNC_ID(ADAPTER, 4),
+       HPI_ADAPTER_TEST_ASSERT = HPI_FUNC_ID(ADAPTER, 5),
+       HPI_ADAPTER_SET_MODE = HPI_FUNC_ID(ADAPTER, 6),
+       HPI_ADAPTER_GET_MODE = HPI_FUNC_ID(ADAPTER, 7),
+       HPI_ADAPTER_ENABLE_CAPABILITY = HPI_FUNC_ID(ADAPTER, 8),
+       HPI_ADAPTER_SELFTEST = HPI_FUNC_ID(ADAPTER, 9),
+       HPI_ADAPTER_FIND_OBJECT = HPI_FUNC_ID(ADAPTER, 10),
+       HPI_ADAPTER_QUERY_FLASH = HPI_FUNC_ID(ADAPTER, 11),
+       HPI_ADAPTER_START_FLASH = HPI_FUNC_ID(ADAPTER, 12),
+       HPI_ADAPTER_PROGRAM_FLASH = HPI_FUNC_ID(ADAPTER, 13),
+       HPI_ADAPTER_SET_PROPERTY = HPI_FUNC_ID(ADAPTER, 14),
+       HPI_ADAPTER_GET_PROPERTY = HPI_FUNC_ID(ADAPTER, 15),
+       HPI_ADAPTER_ENUM_PROPERTY = HPI_FUNC_ID(ADAPTER, 16),
+       HPI_ADAPTER_MODULE_INFO = HPI_FUNC_ID(ADAPTER, 17),
+       HPI_ADAPTER_DEBUG_READ = HPI_FUNC_ID(ADAPTER, 18),
 #define HPI_ADAPTER_FUNCTION_COUNT 18
-/* OUTPUT STREAM */
-#define HPI_OSTREAM_OPEN                HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 1)
-#define HPI_OSTREAM_CLOSE               HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 2)
-#define HPI_OSTREAM_WRITE               HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 3)
-#define HPI_OSTREAM_START               HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 4)
-#define HPI_OSTREAM_STOP                HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 5)
-#define HPI_OSTREAM_RESET               HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 6)
-#define HPI_OSTREAM_GET_INFO            HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 7)
-#define HPI_OSTREAM_QUERY_FORMAT        HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 8)
-#define HPI_OSTREAM_DATA                HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 9)
-#define HPI_OSTREAM_SET_VELOCITY        HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 10)
-#define HPI_OSTREAM_SET_PUNCHINOUT      HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 11)
-#define HPI_OSTREAM_SINEGEN             HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 12)
-#define HPI_OSTREAM_ANC_RESET           HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 13)
-#define HPI_OSTREAM_ANC_GET_INFO        HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 14)
-#define HPI_OSTREAM_ANC_READ            HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 15)
-#define HPI_OSTREAM_SET_TIMESCALE       HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 16)
-#define HPI_OSTREAM_SET_FORMAT          HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 17)
-#define HPI_OSTREAM_HOSTBUFFER_ALLOC    HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 18)
-#define HPI_OSTREAM_HOSTBUFFER_FREE     HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 19)
-#define HPI_OSTREAM_GROUP_ADD           HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 20)
-#define HPI_OSTREAM_GROUP_GETMAP        HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 21)
-#define HPI_OSTREAM_GROUP_RESET         HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 22)
-#define HPI_OSTREAM_HOSTBUFFER_GET_INFO HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 23)
-#define HPI_OSTREAM_WAIT_START          HPI_MAKE_INDEX(HPI_OBJ_OSTREAM, 24)
-#define HPI_OSTREAM_FUNCTION_COUNT              24
-/* INPUT STREAM */
-#define HPI_ISTREAM_OPEN                HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 1)
-#define HPI_ISTREAM_CLOSE               HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 2)
-#define HPI_ISTREAM_SET_FORMAT          HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 3)
-#define HPI_ISTREAM_READ                HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 4)
-#define HPI_ISTREAM_START               HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 5)
-#define HPI_ISTREAM_STOP                HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 6)
-#define HPI_ISTREAM_RESET               HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 7)
-#define HPI_ISTREAM_GET_INFO            HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 8)
-#define HPI_ISTREAM_QUERY_FORMAT        HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 9)
-#define HPI_ISTREAM_ANC_RESET           HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 10)
-#define HPI_ISTREAM_ANC_GET_INFO        HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 11)
-#define HPI_ISTREAM_ANC_WRITE           HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 12)
-#define HPI_ISTREAM_HOSTBUFFER_ALLOC    HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 13)
-#define HPI_ISTREAM_HOSTBUFFER_FREE     HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 14)
-#define HPI_ISTREAM_GROUP_ADD           HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 15)
-#define HPI_ISTREAM_GROUP_GETMAP        HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 16)
-#define HPI_ISTREAM_GROUP_RESET         HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 17)
-#define HPI_ISTREAM_HOSTBUFFER_GET_INFO HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 18)
-#define HPI_ISTREAM_WAIT_START          HPI_MAKE_INDEX(HPI_OBJ_ISTREAM, 19)
-#define HPI_ISTREAM_FUNCTION_COUNT              19
-/* MIXER */
+
+       HPI_OSTREAM_OPEN = HPI_FUNC_ID(OSTREAM, 1),
+       HPI_OSTREAM_CLOSE = HPI_FUNC_ID(OSTREAM, 2),
+       HPI_OSTREAM_WRITE = HPI_FUNC_ID(OSTREAM, 3),
+       HPI_OSTREAM_START = HPI_FUNC_ID(OSTREAM, 4),
+       HPI_OSTREAM_STOP = HPI_FUNC_ID(OSTREAM, 5),
+       HPI_OSTREAM_RESET = HPI_FUNC_ID(OSTREAM, 6),
+       HPI_OSTREAM_GET_INFO = HPI_FUNC_ID(OSTREAM, 7),
+       HPI_OSTREAM_QUERY_FORMAT = HPI_FUNC_ID(OSTREAM, 8),
+       HPI_OSTREAM_DATA = HPI_FUNC_ID(OSTREAM, 9),
+       HPI_OSTREAM_SET_VELOCITY = HPI_FUNC_ID(OSTREAM, 10),
+       HPI_OSTREAM_SET_PUNCHINOUT = HPI_FUNC_ID(OSTREAM, 11),
+       HPI_OSTREAM_SINEGEN = HPI_FUNC_ID(OSTREAM, 12),
+       HPI_OSTREAM_ANC_RESET = HPI_FUNC_ID(OSTREAM, 13),
+       HPI_OSTREAM_ANC_GET_INFO = HPI_FUNC_ID(OSTREAM, 14),
+       HPI_OSTREAM_ANC_READ = HPI_FUNC_ID(OSTREAM, 15),
+       HPI_OSTREAM_SET_TIMESCALE = HPI_FUNC_ID(OSTREAM, 16),
+       HPI_OSTREAM_SET_FORMAT = HPI_FUNC_ID(OSTREAM, 17),
+       HPI_OSTREAM_HOSTBUFFER_ALLOC = HPI_FUNC_ID(OSTREAM, 18),
+       HPI_OSTREAM_HOSTBUFFER_FREE = HPI_FUNC_ID(OSTREAM, 19),
+       HPI_OSTREAM_GROUP_ADD = HPI_FUNC_ID(OSTREAM, 20),
+       HPI_OSTREAM_GROUP_GETMAP = HPI_FUNC_ID(OSTREAM, 21),
+       HPI_OSTREAM_GROUP_RESET = HPI_FUNC_ID(OSTREAM, 22),
+       HPI_OSTREAM_HOSTBUFFER_GET_INFO = HPI_FUNC_ID(OSTREAM, 23),
+       HPI_OSTREAM_WAIT_START = HPI_FUNC_ID(OSTREAM, 24),
+#define HPI_OSTREAM_FUNCTION_COUNT 24
+
+       HPI_ISTREAM_OPEN = HPI_FUNC_ID(ISTREAM, 1),
+       HPI_ISTREAM_CLOSE = HPI_FUNC_ID(ISTREAM, 2),
+       HPI_ISTREAM_SET_FORMAT = HPI_FUNC_ID(ISTREAM, 3),
+       HPI_ISTREAM_READ = HPI_FUNC_ID(ISTREAM, 4),
+       HPI_ISTREAM_START = HPI_FUNC_ID(ISTREAM, 5),
+       HPI_ISTREAM_STOP = HPI_FUNC_ID(ISTREAM, 6),
+       HPI_ISTREAM_RESET = HPI_FUNC_ID(ISTREAM, 7),
+       HPI_ISTREAM_GET_INFO = HPI_FUNC_ID(ISTREAM, 8),
+       HPI_ISTREAM_QUERY_FORMAT = HPI_FUNC_ID(ISTREAM, 9),
+       HPI_ISTREAM_ANC_RESET = HPI_FUNC_ID(ISTREAM, 10),
+       HPI_ISTREAM_ANC_GET_INFO = HPI_FUNC_ID(ISTREAM, 11),
+       HPI_ISTREAM_ANC_WRITE = HPI_FUNC_ID(ISTREAM, 12),
+       HPI_ISTREAM_HOSTBUFFER_ALLOC = HPI_FUNC_ID(ISTREAM, 13),
+       HPI_ISTREAM_HOSTBUFFER_FREE = HPI_FUNC_ID(ISTREAM, 14),
+       HPI_ISTREAM_GROUP_ADD = HPI_FUNC_ID(ISTREAM, 15),
+       HPI_ISTREAM_GROUP_GETMAP = HPI_FUNC_ID(ISTREAM, 16),
+       HPI_ISTREAM_GROUP_RESET = HPI_FUNC_ID(ISTREAM, 17),
+       HPI_ISTREAM_HOSTBUFFER_GET_INFO = HPI_FUNC_ID(ISTREAM, 18),
+       HPI_ISTREAM_WAIT_START = HPI_FUNC_ID(ISTREAM, 19),
+#define HPI_ISTREAM_FUNCTION_COUNT 19
+
 /* NOTE:
    GET_NODE_INFO, SET_CONNECTION, GET_CONNECTIONS are not currently used */
-#define HPI_MIXER_OPEN                  HPI_MAKE_INDEX(HPI_OBJ_MIXER, 1)
-#define HPI_MIXER_CLOSE                 HPI_MAKE_INDEX(HPI_OBJ_MIXER, 2)
-#define HPI_MIXER_GET_INFO              HPI_MAKE_INDEX(HPI_OBJ_MIXER, 3)
-#define HPI_MIXER_GET_NODE_INFO         HPI_MAKE_INDEX(HPI_OBJ_MIXER, 4)
-#define HPI_MIXER_GET_CONTROL           HPI_MAKE_INDEX(HPI_OBJ_MIXER, 5)
-#define HPI_MIXER_SET_CONNECTION        HPI_MAKE_INDEX(HPI_OBJ_MIXER, 6)
-#define HPI_MIXER_GET_CONNECTIONS       HPI_MAKE_INDEX(HPI_OBJ_MIXER, 7)
-#define HPI_MIXER_GET_CONTROL_BY_INDEX  HPI_MAKE_INDEX(HPI_OBJ_MIXER, 8)
-#define HPI_MIXER_GET_CONTROL_ARRAY_BY_INDEX  HPI_MAKE_INDEX(HPI_OBJ_MIXER, 9)
-#define HPI_MIXER_GET_CONTROL_MULTIPLE_VALUES HPI_MAKE_INDEX(HPI_OBJ_MIXER, 10)
-#define HPI_MIXER_STORE                 HPI_MAKE_INDEX(HPI_OBJ_MIXER, 11)
-#define HPI_MIXER_FUNCTION_COUNT        11
-/* MIXER CONTROLS */
-#define HPI_CONTROL_GET_INFO            HPI_MAKE_INDEX(HPI_OBJ_CONTROL, 1)
-#define HPI_CONTROL_GET_STATE           HPI_MAKE_INDEX(HPI_OBJ_CONTROL, 2)
-#define HPI_CONTROL_SET_STATE           HPI_MAKE_INDEX(HPI_OBJ_CONTROL, 3)
+       HPI_MIXER_OPEN = HPI_FUNC_ID(MIXER, 1),
+       HPI_MIXER_CLOSE = HPI_FUNC_ID(MIXER, 2),
+       HPI_MIXER_GET_INFO = HPI_FUNC_ID(MIXER, 3),
+       HPI_MIXER_GET_NODE_INFO = HPI_FUNC_ID(MIXER, 4),
+       HPI_MIXER_GET_CONTROL = HPI_FUNC_ID(MIXER, 5),
+       HPI_MIXER_SET_CONNECTION = HPI_FUNC_ID(MIXER, 6),
+       HPI_MIXER_GET_CONNECTIONS = HPI_FUNC_ID(MIXER, 7),
+       HPI_MIXER_GET_CONTROL_BY_INDEX = HPI_FUNC_ID(MIXER, 8),
+       HPI_MIXER_GET_CONTROL_ARRAY_BY_INDEX = HPI_FUNC_ID(MIXER, 9),
+       HPI_MIXER_GET_CONTROL_MULTIPLE_VALUES = HPI_FUNC_ID(MIXER, 10),
+       HPI_MIXER_STORE = HPI_FUNC_ID(MIXER, 11),
+#define HPI_MIXER_FUNCTION_COUNT 11
+
+       HPI_CONTROL_GET_INFO = HPI_FUNC_ID(CONTROL, 1),
+       HPI_CONTROL_GET_STATE = HPI_FUNC_ID(CONTROL, 2),
+       HPI_CONTROL_SET_STATE = HPI_FUNC_ID(CONTROL, 3),
 #define HPI_CONTROL_FUNCTION_COUNT 3
-/* NONVOL MEMORY */
-#define HPI_NVMEMORY_OPEN               HPI_MAKE_INDEX(HPI_OBJ_NVMEMORY, 1)
-#define HPI_NVMEMORY_READ_BYTE          HPI_MAKE_INDEX(HPI_OBJ_NVMEMORY, 2)
-#define HPI_NVMEMORY_WRITE_BYTE         HPI_MAKE_INDEX(HPI_OBJ_NVMEMORY, 3)
+
+       HPI_NVMEMORY_OPEN = HPI_FUNC_ID(NVMEMORY, 1),
+       HPI_NVMEMORY_READ_BYTE = HPI_FUNC_ID(NVMEMORY, 2),
+       HPI_NVMEMORY_WRITE_BYTE = HPI_FUNC_ID(NVMEMORY, 3),
 #define HPI_NVMEMORY_FUNCTION_COUNT 3
-/* GPIO */
-#define HPI_GPIO_OPEN                   HPI_MAKE_INDEX(HPI_OBJ_GPIO, 1)
-#define HPI_GPIO_READ_BIT               HPI_MAKE_INDEX(HPI_OBJ_GPIO, 2)
-#define HPI_GPIO_WRITE_BIT              HPI_MAKE_INDEX(HPI_OBJ_GPIO, 3)
-#define HPI_GPIO_READ_ALL               HPI_MAKE_INDEX(HPI_OBJ_GPIO, 4)
-#define HPI_GPIO_WRITE_STATUS           HPI_MAKE_INDEX(HPI_OBJ_GPIO, 5)
+
+       HPI_GPIO_OPEN = HPI_FUNC_ID(GPIO, 1),
+       HPI_GPIO_READ_BIT = HPI_FUNC_ID(GPIO, 2),
+       HPI_GPIO_WRITE_BIT = HPI_FUNC_ID(GPIO, 3),
+       HPI_GPIO_READ_ALL = HPI_FUNC_ID(GPIO, 4),
+       HPI_GPIO_WRITE_STATUS = HPI_FUNC_ID(GPIO, 5),
 #define HPI_GPIO_FUNCTION_COUNT 5
-/* ASYNC EVENT */
-#define HPI_ASYNCEVENT_OPEN             HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 1)
-#define HPI_ASYNCEVENT_CLOSE            HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 2)
-#define HPI_ASYNCEVENT_WAIT             HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 3)
-#define HPI_ASYNCEVENT_GETCOUNT         HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 4)
-#define HPI_ASYNCEVENT_GET              HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 5)
-#define HPI_ASYNCEVENT_SENDEVENTS       HPI_MAKE_INDEX(HPI_OBJ_ASYNCEVENT, 6)
+
+       HPI_ASYNCEVENT_OPEN = HPI_FUNC_ID(ASYNCEVENT, 1),
+       HPI_ASYNCEVENT_CLOSE = HPI_FUNC_ID(ASYNCEVENT, 2),
+       HPI_ASYNCEVENT_WAIT = HPI_FUNC_ID(ASYNCEVENT, 3),
+       HPI_ASYNCEVENT_GETCOUNT = HPI_FUNC_ID(ASYNCEVENT, 4),
+       HPI_ASYNCEVENT_GET = HPI_FUNC_ID(ASYNCEVENT, 5),
+       HPI_ASYNCEVENT_SENDEVENTS = HPI_FUNC_ID(ASYNCEVENT, 6),
 #define HPI_ASYNCEVENT_FUNCTION_COUNT 6
-/* WATCH-DOG */
-#define HPI_WATCHDOG_OPEN               HPI_MAKE_INDEX(HPI_OBJ_WATCHDOG, 1)
-#define HPI_WATCHDOG_SET_TIME           HPI_MAKE_INDEX(HPI_OBJ_WATCHDOG, 2)
-#define HPI_WATCHDOG_PING               HPI_MAKE_INDEX(HPI_OBJ_WATCHDOG, 3)
-/* CLOCK */
-#define HPI_CLOCK_OPEN                  HPI_MAKE_INDEX(HPI_OBJ_CLOCK, 1)
-#define HPI_CLOCK_SET_TIME              HPI_MAKE_INDEX(HPI_OBJ_CLOCK, 2)
-#define HPI_CLOCK_GET_TIME              HPI_MAKE_INDEX(HPI_OBJ_CLOCK, 3)
-/* PROFILE */
-#define HPI_PROFILE_OPEN_ALL            HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 1)
-#define HPI_PROFILE_START_ALL           HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 2)
-#define HPI_PROFILE_STOP_ALL            HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 3)
-#define HPI_PROFILE_GET                 HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 4)
-#define HPI_PROFILE_GET_IDLECOUNT       HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 5)
-#define HPI_PROFILE_GET_NAME            HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 6)
-#define HPI_PROFILE_GET_UTILIZATION     HPI_MAKE_INDEX(HPI_OBJ_PROFILE, 7)
+
+       HPI_WATCHDOG_OPEN = HPI_FUNC_ID(WATCHDOG, 1),
+       HPI_WATCHDOG_SET_TIME = HPI_FUNC_ID(WATCHDOG, 2),
+       HPI_WATCHDOG_PING = HPI_FUNC_ID(WATCHDOG, 3),
+
+       HPI_CLOCK_OPEN = HPI_FUNC_ID(CLOCK, 1),
+       HPI_CLOCK_SET_TIME = HPI_FUNC_ID(CLOCK, 2),
+       HPI_CLOCK_GET_TIME = HPI_FUNC_ID(CLOCK, 3),
+
+       HPI_PROFILE_OPEN_ALL = HPI_FUNC_ID(PROFILE, 1),
+       HPI_PROFILE_START_ALL = HPI_FUNC_ID(PROFILE, 2),
+       HPI_PROFILE_STOP_ALL = HPI_FUNC_ID(PROFILE, 3),
+       HPI_PROFILE_GET = HPI_FUNC_ID(PROFILE, 4),
+       HPI_PROFILE_GET_IDLECOUNT = HPI_FUNC_ID(PROFILE, 5),
+       HPI_PROFILE_GET_NAME = HPI_FUNC_ID(PROFILE, 6),
+       HPI_PROFILE_GET_UTILIZATION = HPI_FUNC_ID(PROFILE, 7)
 #define HPI_PROFILE_FUNCTION_COUNT 7
-/* ////////////////////////////////////////////////////////////////////// */
-/* PRIVATE ATTRIBUTES */
+};
 
 /* ////////////////////////////////////////////////////////////////////// */
 /* STRUCTURES */
@@ -672,18 +523,7 @@ Threshold is a -ve number in units of dB/100,
 /** PCI bus resource */
 struct hpi_pci {
        u32 __iomem *ap_mem_base[HPI_MAX_ADAPTER_MEM_SPACES];
-       struct pci_dev *p_os_data;
-
-#ifndef HPI64BIT               /* keep structure size constant */
-       u32 padding[HPI_MAX_ADAPTER_MEM_SPACES + 1];
-#endif
-       u16 vendor_id;
-       u16 device_id;
-       u16 subsys_vendor_id;
-       u16 subsys_device_id;
-       u16 bus_number;
-       u16 device_number;
-       u32 interrupt;
+       struct pci_dev *pci_dev;
 };
 
 struct hpi_resource {
@@ -783,24 +623,18 @@ struct hpi_subsys_res {
        u16 aw_adapter_list[HPI_MAX_ADAPTERS];
 };
 
-struct hpi_adapter_msg {
-       u32 adapter_mode;       /* adapter mode */
-       u16 assert_id;          /* assert number for "test assert" call
-                                  object_index for find object call
-                                  query_or_set for hpi_adapter_set_mode_ex() */
-       u16 object_type;        /* for adapter find object call */
-};
-
 union hpi_adapterx_msg {
-       struct hpi_adapter_msg adapter;
        struct {
-               u32 offset;
-       } query_flash;
+               u32 dsp_address;
+               u32 count_bytes;
+       } debug_read;
        struct {
-               u32 offset;
-               u32 length;
-               u32 key;
-       } start_flash;
+               u32 adapter_mode;
+               u16 query_or_set;
+       } mode;
+       struct {
+               u16 index;
+       } module_info;
        struct {
                u32 checksum;
                u16 sequence;
@@ -808,29 +642,39 @@ union hpi_adapterx_msg {
                u16 offset; /**< offset from start of msg to data */
                u16 unused;
        } program_flash;
+       struct {
+               u16 index;
+               u16 what;
+               u16 property_index;
+       } property_enum;
        struct {
                u16 property;
                u16 parameter1;
                u16 parameter2;
        } property_set;
        struct {
-               u16 index;
-               u16 what;
-               u16 property_index;
-       } property_enum;
+               u32 offset;
+       } query_flash;
        struct {
-               u16 index;
-       } module_info;
+               u32 pad32;
+               u16 key1;
+               u16 key2;
+       } restart;
        struct {
-               u32 dsp_address;
-               u32 count_bytes;
-       } debug_read;
+               u32 offset;
+               u32 length;
+               u32 key;
+       } start_flash;
+       struct {
+               u32 pad32;
+               u16 value;
+       } test_assert;
 };
 
 struct hpi_adapter_res {
        u32 serial_number;
        u16 adapter_type;
-       u16 adapter_index;      /* is this needed? also used for dsp_index */
+       u16 adapter_index;
        u16 num_instreams;
        u16 num_outstreams;
        u16 num_mixers;
@@ -839,12 +683,18 @@ struct hpi_adapter_res {
 };
 
 union hpi_adapterx_res {
-       struct hpi_adapter_res adapter;
+       struct hpi_adapter_res info;
        struct {
-               u32 checksum;
-               u32 length;
-               u32 version;
-       } query_flash;
+               u32 p1;
+               u16 count;
+               u16 dsp_index;
+               u32 p2;
+               u32 dsp_msg_addr;
+               char sz_message[HPI_STRING_LEN];
+       } assert;
+       struct {
+               u32 adapter_mode;
+       } mode;
        struct {
                u16 sequence;
        } program_flash;
@@ -852,6 +702,11 @@ union hpi_adapterx_res {
                u16 parameter1;
                u16 parameter2;
        } property_get;
+       struct {
+               u32 checksum;
+               u32 length;
+               u32 version;
+       } query_flash;
 };
 
 struct hpi_stream_msg {
@@ -911,7 +766,7 @@ struct hpi_stream_res {
 struct hpi_mixer_msg {
        u16 control_index;
        u16 control_type;       /* = HPI_CONTROL_METER _VOLUME etc */
-       u16 padding1;           /* maintain alignment of subsequent fields */
+       u16 padding1;           /* Maintain alignment of subsequent fields */
        u16 node_type1;         /* = HPI_SOURCENODE_LINEIN etc */
        u16 node_index1;        /* = 0..N */
        u16 node_type2;
@@ -1000,12 +855,16 @@ union hpi_control_union_res {
                u32 band;
                u32 frequency;
                u32 gain;
-               u32 level;
                u32 deemphasis;
                struct {
                        u32 data[2];
                        u32 bLER;
                } rds;
+               short s_level;
+               struct {
+                       u16 value;
+                       u16 mask;
+               } status;
        } tuner;
        struct {
                char sz_data[8];
@@ -1178,11 +1037,11 @@ struct hpi_profile_res_open {
 };
 
 struct hpi_profile_res_time {
-       u32 micro_seconds;
+       u32 total_tick_count;
        u32 call_count;
-       u32 max_micro_seconds;
-       u32 min_micro_seconds;
-       u16 seconds;
+       u32 max_tick_count;
+       u32 ticks_per_millisecond;
+       u16 profile_interval;
 };
 
 struct hpi_profile_res_name {
@@ -1218,7 +1077,6 @@ struct hpi_message {
        u16 obj_index;          /*  */
        union {
                struct hpi_subsys_msg s;
-               struct hpi_adapter_msg a;
                union hpi_adapterx_msg ax;
                struct hpi_stream_msg d;
                struct hpi_mixer_msg m;
@@ -1239,7 +1097,7 @@ struct hpi_message {
 };
 
 #define HPI_MESSAGE_SIZE_BY_OBJECT { \
-       sizeof(struct hpi_message_header) ,   /* default, no object type 0 */ \
+       sizeof(struct hpi_message_header) ,   /* Default, no object type 0 */ \
        sizeof(struct hpi_message_header) + sizeof(struct hpi_subsys_msg),\
        sizeof(struct hpi_message_header) + sizeof(union hpi_adapterx_msg),\
        sizeof(struct hpi_message_header) + sizeof(struct hpi_stream_msg),\
@@ -1277,7 +1135,6 @@ struct hpi_response {
        u16 specific_error;     /* adapter specific error */
        union {
                struct hpi_subsys_res s;
-               struct hpi_adapter_res a;
                union hpi_adapterx_res ax;
                struct hpi_stream_res d;
                struct hpi_mixer_res m;
@@ -1297,7 +1154,7 @@ struct hpi_response {
 };
 
 #define HPI_RESPONSE_SIZE_BY_OBJECT { \
-       sizeof(struct hpi_response_header) ,/* default, no object type 0 */ \
+       sizeof(struct hpi_response_header) ,/* Default, no object type 0 */ \
        sizeof(struct hpi_response_header) + sizeof(struct hpi_subsys_res),\
        sizeof(struct hpi_response_header) + sizeof(union  hpi_adapterx_res),\
        sizeof(struct hpi_response_header) + sizeof(struct hpi_stream_res),\
@@ -1394,6 +1251,17 @@ struct hpi_res_adapter_program_flash {
                sizeof(struct hpi_response_header) - sizeof(u16)];
 };
 
+struct hpi_msg_adapter_debug_read {
+       struct hpi_message_header h;
+       u32 dsp_address;
+       u32 count_bytes;
+};
+
+struct hpi_res_adapter_debug_read {
+       struct hpi_response_header h;
+       u8 bytes[256];
+};
+
 #if 1
 #define hpi_message_header_v1 hpi_message_header
 #define hpi_response_header_v1 hpi_response_header
@@ -1414,23 +1282,10 @@ struct hpi_response_header_v1 {
 };
 #endif
 
-/* STRV HPI Packet */
-struct hpi_msg_strv {
-       struct hpi_message_header h;
-       struct hpi_entity strv;
-};
-
-struct hpi_res_strv {
-       struct hpi_response_header h;
-       struct hpi_entity strv;
-};
-#define MIN_STRV_PACKET_SIZE sizeof(struct hpi_res_strv)
-
 struct hpi_msg_payload_v0 {
        struct hpi_message_header h;
        union {
                struct hpi_subsys_msg s;
-               struct hpi_adapter_msg a;
                union hpi_adapterx_msg ax;
                struct hpi_stream_msg d;
                struct hpi_mixer_msg m;
@@ -1451,7 +1306,6 @@ struct hpi_res_payload_v0 {
        struct hpi_response_header h;
        union {
                struct hpi_subsys_res s;
-               struct hpi_adapter_res a;
                union hpi_adapterx_res ax;
                struct hpi_stream_res d;
                struct hpi_mixer_res m;
@@ -1471,13 +1325,13 @@ struct hpi_res_payload_v0 {
 union hpi_message_buffer_v1 {
        struct hpi_message m0;  /* version 0 */
        struct hpi_message_header_v1 h;
-       unsigned char buf[HPI_MAX_PAYLOAD_SIZE];
+       u8 buf[HPI_MAX_PAYLOAD_SIZE];
 };
 
 union hpi_response_buffer_v1 {
        struct hpi_response r0; /* version 0 */
        struct hpi_response_header_v1 h;
-       unsigned char buf[HPI_MAX_PAYLOAD_SIZE];
+       u8 buf[HPI_MAX_PAYLOAD_SIZE];
 };
 
 compile_time_assert((sizeof(union hpi_message_buffer_v1) <=
@@ -1499,6 +1353,11 @@ struct hpi_control_defn {
 /*////////////////////////////////////////////////////////////////////////// */
 /* declarations for control caching (internal to HPI<->DSP interaction)      */
 
+/** indicates a cached u16 value is invalid. */
+#define HPI_CACHE_INVALID_UINT16 0xFFFF
+/** indicates a cached short value is invalid. */
+#define HPI_CACHE_INVALID_SHORT -32768
+
 /** A compact representation of (part of) a controls state.
 Used for efficient transfer of the control state
 between DSP and host or across a network
@@ -1512,58 +1371,103 @@ struct hpi_control_cache_info {
        u16 control_index;
 };
 
-struct hpi_control_cache_single {
+struct hpi_control_cache_vol {
+       struct hpi_control_cache_info i;
+       short an_log[2];
+       char temp_padding[4];
+};
+
+struct hpi_control_cache_meter {
+       struct hpi_control_cache_info i;
+       short an_log_peak[2];
+       short an_logRMS[2];
+};
+
+struct hpi_control_cache_channelmode {
+       struct hpi_control_cache_info i;
+       u16 mode;
+       char temp_padding[6];
+};
+
+struct hpi_control_cache_mux {
+       struct hpi_control_cache_info i;
+       u16 source_node_type;
+       u16 source_node_index;
+       char temp_padding[4];
+};
+
+struct hpi_control_cache_level {
+       struct hpi_control_cache_info i;
+       short an_log[2];
+       char temp_padding[4];
+};
+
+struct hpi_control_cache_tuner {
+       struct hpi_control_cache_info i;
+       u32 freq_ink_hz;
+       u16 band;
+       short s_level_avg;
+};
+
+struct hpi_control_cache_aes3rx {
+       struct hpi_control_cache_info i;
+       u32 error_status;
+       u32 format;
+};
+
+struct hpi_control_cache_aes3tx {
+       struct hpi_control_cache_info i;
+       u32 format;
+       char temp_padding[4];
+};
+
+struct hpi_control_cache_tonedetector {
+       struct hpi_control_cache_info i;
+       u16 state;
+       char temp_padding[6];
+};
+
+struct hpi_control_cache_silencedetector {
+       struct hpi_control_cache_info i;
+       u32 state;
+       char temp_padding[4];
+};
+
+struct hpi_control_cache_sampleclock {
+       struct hpi_control_cache_info i;
+       u16 source;
+       u16 source_index;
+       u32 sample_rate;
+};
+
+struct hpi_control_cache_microphone {
+       struct hpi_control_cache_info i;
+       u16 phantom_state;
+       char temp_padding[6];
+};
+
+struct hpi_control_cache_generic {
        struct hpi_control_cache_info i;
+       u32 dw1;
+       u32 dw2;
+};
+
+struct hpi_control_cache_single {
        union {
-               struct {        /* volume */
-                       short an_log[2];
-               } v;
-               struct {        /* peak meter */
-                       short an_log_peak[2];
-                       short an_logRMS[2];
-               } p;
-               struct {        /* channel mode */
-                       u16 mode;
-               } m;
-               struct {        /* multiplexer */
-                       u16 source_node_type;
-                       u16 source_node_index;
-               } x;
-               struct {        /* level/trim */
-                       short an_log[2];
-               } l;
-               struct {        /* tuner - partial caching.
-                                  some attributes go to the DSP. */
-                       u32 freq_ink_hz;
-                       u16 band;
-                       u16 level;
-               } t;
-               struct {        /* AESEBU rx status */
-                       u32 error_status;
-                       u32 source;
-               } aes3rx;
-               struct {        /* AESEBU tx */
-                       u32 format;
-               } aes3tx;
-               struct {        /* tone detector */
-                       u16 state;
-               } tone;
-               struct {        /* silence detector */
-                       u32 state;
-                       u32 count;
-               } silence;
-               struct {        /* sample clock */
-                       u16 source;
-                       u16 source_index;
-                       u32 sample_rate;
-               } clk;
-               struct {        /* microphone control */
-                       u16 state;
-               } phantom_power;
-               struct {        /* generic control */
-                       u32 dw1;
-                       u32 dw2;
-               } g;
+               struct hpi_control_cache_info i;
+               struct hpi_control_cache_vol vol;
+               struct hpi_control_cache_meter meter;
+               struct hpi_control_cache_channelmode mode;
+               struct hpi_control_cache_mux mux;
+               struct hpi_control_cache_level level;
+               struct hpi_control_cache_tuner tuner;
+               struct hpi_control_cache_aes3rx aes3rx;
+               struct hpi_control_cache_aes3tx aes3tx;
+               struct hpi_control_cache_tonedetector tone;
+               struct hpi_control_cache_silencedetector silence;
+               struct hpi_control_cache_sampleclock clk;
+               struct hpi_control_cache_microphone microphone;
+               struct hpi_control_cache_generic generic;
        } u;
 };
 
index d67f4d3db911dd9685d24e08f29d6b6bc23f16f9..793236ef0a540468d9aaa80ff3684fc797e586e4 100644 (file)
@@ -26,6 +26,8 @@
 
 #include "hpi_internal.h"
 #include "hpidebug.h"
+#include "hpimsginit.h"
+
 #include "hpicmn.h"
 
 struct hpi_adapters_list {
@@ -43,14 +45,22 @@ static struct hpi_adapters_list adapters;
 **/
 u16 hpi_validate_response(struct hpi_message *phm, struct hpi_response *phr)
 {
-       u16 error = 0;
+       if (phr->type != HPI_TYPE_RESPONSE) {
+               HPI_DEBUG_LOG(ERROR, "header type %d invalid", phr->type);
+               return HPI_ERROR_INVALID_RESPONSE;
+       }
+
+       if (phr->object != phm->object) {
+               HPI_DEBUG_LOG(ERROR, "header object %d invalid", phr->object);
+               return HPI_ERROR_INVALID_RESPONSE;
+       }
 
-       if ((phr->type != HPI_TYPE_RESPONSE)
-               || (phr->object != phm->object)
-               || (phr->function != phm->function))
-               error = HPI_ERROR_INVALID_RESPONSE;
+       if (phr->function != phm->function) {
+               HPI_DEBUG_LOG(ERROR, "header type %d invalid", phr->function);
+               return HPI_ERROR_INVALID_RESPONSE;
+       }
 
-       return error;
+       return 0;
 }
 
 u16 hpi_add_adapter(struct hpi_adapter_obj *pao)
@@ -76,17 +86,22 @@ u16 hpi_add_adapter(struct hpi_adapter_obj *pao)
        adapters.gw_num_adapters++;
 
 unlock:
-       hpios_alistlock_un_lock(&adapters);
+       hpios_alistlock_unlock(&adapters);
        return retval;
 }
 
 void hpi_delete_adapter(struct hpi_adapter_obj *pao)
 {
-       memset(pao, 0, sizeof(struct hpi_adapter_obj));
+       if (!pao->adapter_type) {
+               HPI_DEBUG_LOG(ERROR, "removing null adapter?\n");
+               return;
+       }
 
        hpios_alistlock_lock(&adapters);
-       adapters.gw_num_adapters--;     /* dec the number of adapters */
-       hpios_alistlock_un_lock(&adapters);
+       if (adapters.adapter[pao->index].adapter_type)
+               adapters.gw_num_adapters--;
+       memset(&adapters.adapter[pao->index], 0, sizeof(adapters.adapter[0]));
+       hpios_alistlock_unlock(&adapters);
 }
 
 /**
@@ -125,51 +140,35 @@ struct hpi_adapter_obj *hpi_find_adapter(u16 adapter_index)
 * wipe an HPI_ADAPTERS_LIST structure.
 *
 **/
-static void wipe_adapter_list(void
-       )
+static void wipe_adapter_list(void)
 {
        memset(&adapters, 0, sizeof(adapters));
 }
 
-/**
-* SubSysGetAdapters fills awAdapterList in an struct hpi_response structure
-* with all adapters in the given HPI_ADAPTERS_LIST.
-*
-*/
-static void subsys_get_adapters(struct hpi_response *phr)
+static void subsys_get_adapter(struct hpi_message *phm,
+       struct hpi_response *phr)
 {
-       /* fill in the response adapter array with the position */
-       /* identified by the adapter number/index of the adapters in */
-       /* this HPI */
-       /* i.e. if we have an A120 with it's jumper set to */
-       /* Adapter Number 2 then put an Adapter type A120 in the */
-       /* array in position 1 */
-       /* NOTE: AdapterNumber is 1..N, Index is 0..N-1 */
-
-       /* input:  NONE */
-       /* output: wNumAdapters */
-       /*                 awAdapter[] */
-       /* */
-
-       short i;
-       struct hpi_adapter_obj *pao = NULL;
+       int count = phm->obj_index;
+       u16 index = 0;
 
-       HPI_DEBUG_LOG(VERBOSE, "subsys_get_adapters\n");
-
-       /* for each adapter, place it's type in the position of the array */
-       /* corresponding to it's adapter number */
-       for (i = 0; i < adapters.gw_num_adapters; i++) {
-               pao = &adapters.adapter[i];
-               if (phr->u.s.aw_adapter_list[pao->index] != 0) {
-                       phr->error = HPI_DUPLICATE_ADAPTER_NUMBER;
-                       phr->specific_error = pao->index;
-                       return;
+       /* find the nCount'th nonzero adapter in array */
+       for (index = 0; index < HPI_MAX_ADAPTERS; index++) {
+               if (adapters.adapter[index].adapter_type) {
+                       if (count == 0)
+                               break;
+                       count--;
                }
-               phr->u.s.aw_adapter_list[pao->index] = pao->adapter_type;
        }
 
-       phr->u.s.num_adapters = adapters.gw_num_adapters;
-       phr->error = 0; /* the function completed OK; */
+       if (index < HPI_MAX_ADAPTERS) {
+               phr->u.s.adapter_index = adapters.adapter[index].index;
+               phr->u.s.aw_adapter_list[0] =
+                       adapters.adapter[index].adapter_type;
+       } else {
+               phr->u.s.adapter_index = 0;
+               phr->u.s.aw_adapter_list[0] = 0;
+               phr->error = HPI_ERROR_BAD_ADAPTER_NUMBER;
+       }
 }
 
 static unsigned int control_cache_alloc_check(struct hpi_control_cache *pC)
@@ -178,67 +177,88 @@ static unsigned int control_cache_alloc_check(struct hpi_control_cache *pC)
        int cached = 0;
        if (!pC)
                return 0;
-       if ((!pC->init) && (pC->p_cache != NULL) && (pC->control_count)
-               && (pC->cache_size_in_bytes)
-               ) {
-               u32 *p_master_cache;
-               pC->init = 1;
 
-               p_master_cache = (u32 *)pC->p_cache;
-               HPI_DEBUG_LOG(VERBOSE, "check %d controls\n",
+       if (pC->init)
+               return pC->init;
+
+       if (!pC->p_cache)
+               return 0;
+
+       if (pC->control_count && pC->cache_size_in_bytes) {
+               char *p_master_cache;
+               unsigned int byte_count = 0;
+
+               p_master_cache = (char *)pC->p_cache;
+               HPI_DEBUG_LOG(DEBUG, "check %d controls\n",
                        pC->control_count);
                for (i = 0; i < pC->control_count; i++) {
                        struct hpi_control_cache_info *info =
                                (struct hpi_control_cache_info *)
-                               p_master_cache;
+                               &p_master_cache[byte_count];
+
+                       if (!info->size_in32bit_words) {
+                               /* ? This is a severe error, the cache is probably
+                                  corrupted.  Minimum valid entry size is
+                                  sizeof(struct hpi_control_cache_info) */
+                               HPI_DEBUG_LOG(ERROR,
+                                       "zero size cache entry %d\n", i);
+                               break;
+                       }
 
                        if (info->control_type) {
-                               pC->p_info[i] = info;
+                               pC->p_info[info->control_index] = info;
                                cached++;
-                       } else
-                               pC->p_info[i] = NULL;
+                       } else  /* dummy cache entry */
+                               pC->p_info[info->control_index] = NULL;
 
-                       if (info->size_in32bit_words)
-                               p_master_cache += info->size_in32bit_words;
-                       else
-                               p_master_cache +=
-                                       sizeof(struct
-                                       hpi_control_cache_single) /
-                                       sizeof(u32);
+                       byte_count += info->size_in32bit_words * 4;
 
                        HPI_DEBUG_LOG(VERBOSE,
-                               "cached %d, pinfo %p index %d type %d\n",
-                               cached, pC->p_info[i], info->control_index,
-                               info->control_type);
+                               "cached %d, pinfo %p index %d type %d size %d\n",
+                               cached, pC->p_info[info->control_index],
+                               info->control_index, info->control_type,
+                               info->size_in32bit_words);
+
+                       /* quit loop early if whole cache has been scanned. */
+                       /* pC->dwControlCount is the maximum possible entries, */
+                       /* but some may not be in the cache at all */
+                       if (byte_count >= pC->cache_size_in_bytes)
+                               break;
+                       /* have seen last control index */
+                       if (info->control_index == pC->control_count - 1)
+                               break;
                }
-               /*
-                  We didn't find anything to cache, so try again later !
-                */
-               if (!cached)
-                       pC->init = 0;
+
+               if (byte_count != pC->cache_size_in_bytes)
+                       HPI_DEBUG_LOG(WARNING,
+                               "bytecount %d != cache size %d", byte_count,
+                               pC->cache_size_in_bytes);
+               else
+                       HPI_DEBUG_LOG(DEBUG,
+                               "cache good. bytecount == cache size = %d",
+                               byte_count);
+
+               pC->init = cached;
        }
        return pC->init;
 }
 
 /** Find a control.
 */
-static short find_control(struct hpi_message *phm,
-       struct hpi_control_cache *p_cache, struct hpi_control_cache_info **pI,
-       u16 *pw_control_index)
+static short find_control(u16 control_index,
+       struct hpi_control_cache *p_cache, struct hpi_control_cache_info **pI)
 {
-       *pw_control_index = phm->obj_index;
-
        if (!control_cache_alloc_check(p_cache)) {
                HPI_DEBUG_LOG(VERBOSE,
-                       "control_cache_alloc_check() failed. adap%d ci%d\n",
-                       phm->adapter_index, *pw_control_index);
+                       "control_cache_alloc_check() failed %d\n",
+                       control_index);
                return 0;
        }
 
-       *pI = p_cache->p_info[*pw_control_index];
+       *pI = p_cache->p_info[control_index];
        if (!*pI) {
-               HPI_DEBUG_LOG(VERBOSE, "uncached adap %d, control %d\n",
-                       phm->adapter_index, *pw_control_index);
+               HPI_DEBUG_LOG(VERBOSE, "Uncached Control %d\n",
+                       control_index);
                return 0;
        } else {
                HPI_DEBUG_LOG(VERBOSE, "find_control() type %d\n",
@@ -257,11 +277,14 @@ short hpi_check_buffer_mapping(struct hpi_control_cache *p_cache,
        if ((phm->function == HPI_CONTROL_GET_STATE)
                && (phm->object == HPI_OBJ_CONTROLEX)
                ) {
-               u16 control_index;
                struct hpi_control_cache_info *pI;
 
-               if (!find_control(phm, p_cache, &pI, &control_index))
+               if (!find_control(phm->obj_index, p_cache, &pI)) {
+                       HPI_DEBUG_LOG(VERBOSE,
+                               "HPICMN find_control() failed for adap %d\n",
+                               phm->adapter_index);
                        return 0;
+               }
        }
        return 0;
 }
@@ -290,13 +313,16 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,
        struct hpi_message *phm, struct hpi_response *phr)
 {
        short found = 1;
-       u16 control_index;
        struct hpi_control_cache_info *pI;
        struct hpi_control_cache_single *pC;
        struct hpi_control_cache_pad *p_pad;
 
-       if (!find_control(phm, p_cache, &pI, &control_index))
+       if (!find_control(phm->obj_index, p_cache, &pI)) {
+               HPI_DEBUG_LOG(VERBOSE,
+                       "HPICMN find_control() failed for adap %d\n",
+                       phm->adapter_index);
                return 0;
+       }
 
        phr->error = 0;
 
@@ -310,55 +336,66 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,
 
        case HPI_CONTROL_METER:
                if (phm->u.c.attribute == HPI_METER_PEAK) {
-                       phr->u.c.an_log_value[0] = pC->u.p.an_log_peak[0];
-                       phr->u.c.an_log_value[1] = pC->u.p.an_log_peak[1];
+                       phr->u.c.an_log_value[0] = pC->u.meter.an_log_peak[0];
+                       phr->u.c.an_log_value[1] = pC->u.meter.an_log_peak[1];
                } else if (phm->u.c.attribute == HPI_METER_RMS) {
-                       phr->u.c.an_log_value[0] = pC->u.p.an_logRMS[0];
-                       phr->u.c.an_log_value[1] = pC->u.p.an_logRMS[1];
+                       if (pC->u.meter.an_logRMS[0] ==
+                               HPI_CACHE_INVALID_SHORT) {
+                               phr->error =
+                                       HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;
+                               phr->u.c.an_log_value[0] = HPI_METER_MINIMUM;
+                               phr->u.c.an_log_value[1] = HPI_METER_MINIMUM;
+                       } else {
+                               phr->u.c.an_log_value[0] =
+                                       pC->u.meter.an_logRMS[0];
+                               phr->u.c.an_log_value[1] =
+                                       pC->u.meter.an_logRMS[1];
+                       }
                } else
                        found = 0;
                break;
        case HPI_CONTROL_VOLUME:
                if (phm->u.c.attribute == HPI_VOLUME_GAIN) {
-                       phr->u.c.an_log_value[0] = pC->u.v.an_log[0];
-                       phr->u.c.an_log_value[1] = pC->u.v.an_log[1];
+                       phr->u.c.an_log_value[0] = pC->u.vol.an_log[0];
+                       phr->u.c.an_log_value[1] = pC->u.vol.an_log[1];
                } else
                        found = 0;
                break;
        case HPI_CONTROL_MULTIPLEXER:
                if (phm->u.c.attribute == HPI_MULTIPLEXER_SOURCE) {
-                       phr->u.c.param1 = pC->u.x.source_node_type;
-                       phr->u.c.param2 = pC->u.x.source_node_index;
+                       phr->u.c.param1 = pC->u.mux.source_node_type;
+                       phr->u.c.param2 = pC->u.mux.source_node_index;
                } else {
                        found = 0;
                }
                break;
        case HPI_CONTROL_CHANNEL_MODE:
                if (phm->u.c.attribute == HPI_CHANNEL_MODE_MODE)
-                       phr->u.c.param1 = pC->u.m.mode;
+                       phr->u.c.param1 = pC->u.mode.mode;
                else
                        found = 0;
                break;
        case HPI_CONTROL_LEVEL:
                if (phm->u.c.attribute == HPI_LEVEL_GAIN) {
-                       phr->u.c.an_log_value[0] = pC->u.l.an_log[0];
-                       phr->u.c.an_log_value[1] = pC->u.l.an_log[1];
+                       phr->u.c.an_log_value[0] = pC->u.level.an_log[0];
+                       phr->u.c.an_log_value[1] = pC->u.level.an_log[1];
                } else
                        found = 0;
                break;
        case HPI_CONTROL_TUNER:
                if (phm->u.c.attribute == HPI_TUNER_FREQ)
-                       phr->u.c.param1 = pC->u.t.freq_ink_hz;
+                       phr->u.c.param1 = pC->u.tuner.freq_ink_hz;
                else if (phm->u.c.attribute == HPI_TUNER_BAND)
-                       phr->u.c.param1 = pC->u.t.band;
-               else if ((phm->u.c.attribute == HPI_TUNER_LEVEL)
-                       && (phm->u.c.param1 == HPI_TUNER_LEVEL_AVERAGE))
-                       if (pC->u.t.level == HPI_ERROR_ILLEGAL_CACHE_VALUE) {
-                               phr->u.c.param1 = 0;
+                       phr->u.c.param1 = pC->u.tuner.band;
+               else if (phm->u.c.attribute == HPI_TUNER_LEVEL_AVG)
+                       if (pC->u.tuner.s_level_avg ==
+                               HPI_CACHE_INVALID_SHORT) {
+                               phr->u.cu.tuner.s_level = 0;
                                phr->error =
                                        HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;
                        } else
-                               phr->u.c.param1 = pC->u.t.level;
+                               phr->u.cu.tuner.s_level =
+                                       pC->u.tuner.s_level_avg;
                else
                        found = 0;
                break;
@@ -366,7 +403,7 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,
                if (phm->u.c.attribute == HPI_AESEBURX_ERRORSTATUS)
                        phr->u.c.param1 = pC->u.aes3rx.error_status;
                else if (phm->u.c.attribute == HPI_AESEBURX_FORMAT)
-                       phr->u.c.param1 = pC->u.aes3rx.source;
+                       phr->u.c.param1 = pC->u.aes3rx.format;
                else
                        found = 0;
                break;
@@ -385,13 +422,13 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,
        case HPI_CONTROL_SILENCEDETECTOR:
                if (phm->u.c.attribute == HPI_SILENCEDETECTOR_STATE) {
                        phr->u.c.param1 = pC->u.silence.state;
-                       phr->u.c.param2 = pC->u.silence.count;
+                       /*? phr->u.c.dwParam2 = pC->u.silence.dwCount; */
                } else
                        found = 0;
                break;
        case HPI_CONTROL_MICROPHONE:
                if (phm->u.c.attribute == HPI_MICROPHONE_PHANTOM_POWER)
-                       phr->u.c.param1 = pC->u.phantom_power.state;
+                       phr->u.c.param1 = pC->u.microphone.phantom_state;
                else
                        found = 0;
                break;
@@ -400,7 +437,7 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,
                        phr->u.c.param1 = pC->u.clk.source;
                else if (phm->u.c.attribute == HPI_SAMPLECLOCK_SOURCE_INDEX) {
                        if (pC->u.clk.source_index ==
-                               HPI_ERROR_ILLEGAL_CACHE_VALUE) {
+                               HPI_CACHE_INVALID_UINT16) {
                                phr->u.c.param1 = 0;
                                phr->error =
                                        HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;
@@ -411,60 +448,63 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,
                else
                        found = 0;
                break;
-       case HPI_CONTROL_PAD:
-
-               if (!(p_pad->field_valid_flags & (1 <<
-                                       HPI_CTL_ATTR_INDEX(phm->u.c.
-                                               attribute)))) {
-                       phr->error = HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;
-                       break;
-               }
+       case HPI_CONTROL_PAD:{
+                       struct hpi_control_cache_pad *p_pad;
+                       p_pad = (struct hpi_control_cache_pad *)pI;
 
-               if (phm->u.c.attribute == HPI_PAD_PROGRAM_ID)
-                       phr->u.c.param1 = p_pad->pI;
-               else if (phm->u.c.attribute == HPI_PAD_PROGRAM_TYPE)
-                       phr->u.c.param1 = p_pad->pTY;
-               else {
-                       unsigned int index =
-                               HPI_CTL_ATTR_INDEX(phm->u.c.attribute) - 1;
-                       unsigned int offset = phm->u.c.param1;
-                       unsigned int pad_string_len, field_size;
-                       char *pad_string;
-                       unsigned int tocopy;
-
-                       HPI_DEBUG_LOG(VERBOSE, "PADS HPI_PADS_ %d\n",
-                               phm->u.c.attribute);
-
-                       if (index > ARRAY_SIZE(pad_desc) - 1) {
+                       if (!(p_pad->field_valid_flags & (1 <<
+                                               HPI_CTL_ATTR_INDEX(phm->u.c.
+                                                       attribute)))) {
                                phr->error =
                                        HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;
                                break;
                        }
 
-                       pad_string = ((char *)p_pad) + pad_desc[index].offset;
-                       field_size = pad_desc[index].field_size;
-                       /* Ensure null terminator */
-                       pad_string[field_size - 1] = 0;
-
-                       pad_string_len = strlen(pad_string) + 1;
-
-                       if (offset > pad_string_len) {
-                               phr->error = HPI_ERROR_INVALID_CONTROL_VALUE;
-                               break;
+                       if (phm->u.c.attribute == HPI_PAD_PROGRAM_ID)
+                               phr->u.c.param1 = p_pad->pI;
+                       else if (phm->u.c.attribute == HPI_PAD_PROGRAM_TYPE)
+                               phr->u.c.param1 = p_pad->pTY;
+                       else {
+                               unsigned int index =
+                                       HPI_CTL_ATTR_INDEX(phm->u.c.
+                                       attribute) - 1;
+                               unsigned int offset = phm->u.c.param1;
+                               unsigned int pad_string_len, field_size;
+                               char *pad_string;
+                               unsigned int tocopy;
+
+                               if (index > ARRAY_SIZE(pad_desc) - 1) {
+                                       phr->error =
+                                               HPI_ERROR_INVALID_CONTROL_ATTRIBUTE;
+                                       break;
+                               }
+
+                               pad_string =
+                                       ((char *)p_pad) +
+                                       pad_desc[index].offset;
+                               field_size = pad_desc[index].field_size;
+                               /* Ensure null terminator */
+                               pad_string[field_size - 1] = 0;
+
+                               pad_string_len = strlen(pad_string) + 1;
+
+                               if (offset > pad_string_len) {
+                                       phr->error =
+                                               HPI_ERROR_INVALID_CONTROL_VALUE;
+                                       break;
+                               }
+
+                               tocopy = pad_string_len - offset;
+                               if (tocopy > sizeof(phr->u.cu.chars8.sz_data))
+                                       tocopy = sizeof(phr->u.cu.chars8.
+                                               sz_data);
+
+                               memcpy(phr->u.cu.chars8.sz_data,
+                                       &pad_string[offset], tocopy);
+
+                               phr->u.cu.chars8.remaining_chars =
+                                       pad_string_len - offset - tocopy;
                        }
-
-                       tocopy = pad_string_len - offset;
-                       if (tocopy > sizeof(phr->u.cu.chars8.sz_data))
-                               tocopy = sizeof(phr->u.cu.chars8.sz_data);
-
-                       HPI_DEBUG_LOG(VERBOSE,
-                               "PADS memcpy(%d), offset %d \n", tocopy,
-                               offset);
-                       memcpy(phr->u.cu.chars8.sz_data, &pad_string[offset],
-                               tocopy);
-
-                       phr->u.cu.chars8.remaining_chars =
-                               pad_string_len - offset - tocopy;
                }
                break;
        default:
@@ -472,16 +512,9 @@ short hpi_check_control_cache(struct hpi_control_cache *p_cache,
                break;
        }
 
-       if (found)
-               HPI_DEBUG_LOG(VERBOSE,
-                       "cached adap %d, ctl %d, type %d, attr %d\n",
-                       phm->adapter_index, pI->control_index,
-                       pI->control_type, phm->u.c.attribute);
-       else
-               HPI_DEBUG_LOG(VERBOSE,
-                       "uncached adap %d, ctl %d, ctl type %d\n",
-                       phm->adapter_index, pI->control_index,
-                       pI->control_type);
+       HPI_DEBUG_LOG(VERBOSE, "%s Adap %d, Ctl %d, Type %d, Attr %d\n",
+               found ? "Cached" : "Uncached", phm->adapter_index,
+               pI->control_index, pI->control_type, phm->u.c.attribute);
 
        if (found)
                phr->size =
@@ -497,18 +530,21 @@ Only update if no error.
 Volume and Level return the limited values in the response, so use these
 Multiplexer does so use sent values
 */
-void hpi_sync_control_cache(struct hpi_control_cache *p_cache,
+void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *p_cache,
        struct hpi_message *phm, struct hpi_response *phr)
 {
-       u16 control_index;
        struct hpi_control_cache_single *pC;
        struct hpi_control_cache_info *pI;
 
        if (phr->error)
                return;
 
-       if (!find_control(phm, p_cache, &pI, &control_index))
+       if (!find_control(phm->obj_index, p_cache, &pI)) {
+               HPI_DEBUG_LOG(VERBOSE,
+                       "HPICMN find_control() failed for adap %d\n",
+                       phm->adapter_index);
                return;
+       }
 
        /* pC is the default cached control strucure.
           May be cast to something else in the following switch statement.
@@ -518,31 +554,31 @@ void hpi_sync_control_cache(struct hpi_control_cache *p_cache,
        switch (pI->control_type) {
        case HPI_CONTROL_VOLUME:
                if (phm->u.c.attribute == HPI_VOLUME_GAIN) {
-                       pC->u.v.an_log[0] = phr->u.c.an_log_value[0];
-                       pC->u.v.an_log[1] = phr->u.c.an_log_value[1];
+                       pC->u.vol.an_log[0] = phr->u.c.an_log_value[0];
+                       pC->u.vol.an_log[1] = phr->u.c.an_log_value[1];
                }
                break;
        case HPI_CONTROL_MULTIPLEXER:
                /* mux does not return its setting on Set command. */
                if (phm->u.c.attribute == HPI_MULTIPLEXER_SOURCE) {
-                       pC->u.x.source_node_type = (u16)phm->u.c.param1;
-                       pC->u.x.source_node_index = (u16)phm->u.c.param2;
+                       pC->u.mux.source_node_type = (u16)phm->u.c.param1;
+                       pC->u.mux.source_node_index = (u16)phm->u.c.param2;
                }
                break;
        case HPI_CONTROL_CHANNEL_MODE:
                /* mode does not return its setting on Set command. */
                if (phm->u.c.attribute == HPI_CHANNEL_MODE_MODE)
-                       pC->u.m.mode = (u16)phm->u.c.param1;
+                       pC->u.mode.mode = (u16)phm->u.c.param1;
                break;
        case HPI_CONTROL_LEVEL:
                if (phm->u.c.attribute == HPI_LEVEL_GAIN) {
-                       pC->u.v.an_log[0] = phr->u.c.an_log_value[0];
-                       pC->u.v.an_log[1] = phr->u.c.an_log_value[1];
+                       pC->u.vol.an_log[0] = phr->u.c.an_log_value[0];
+                       pC->u.vol.an_log[1] = phr->u.c.an_log_value[1];
                }
                break;
        case HPI_CONTROL_MICROPHONE:
                if (phm->u.c.attribute == HPI_MICROPHONE_PHANTOM_POWER)
-                       pC->u.phantom_power.state = (u16)phm->u.c.param1;
+                       pC->u.microphone.phantom_state = (u16)phm->u.c.param1;
                break;
        case HPI_CONTROL_AESEBU_TRANSMITTER:
                if (phm->u.c.attribute == HPI_AESEBUTX_FORMAT)
@@ -550,7 +586,7 @@ void hpi_sync_control_cache(struct hpi_control_cache *p_cache,
                break;
        case HPI_CONTROL_AESEBU_RECEIVER:
                if (phm->u.c.attribute == HPI_AESEBURX_FORMAT)
-                       pC->u.aes3rx.source = phm->u.c.param1;
+                       pC->u.aes3rx.format = phm->u.c.param1;
                break;
        case HPI_CONTROL_SAMPLECLOCK:
                if (phm->u.c.attribute == HPI_SAMPLECLOCK_SOURCE)
@@ -566,8 +602,7 @@ void hpi_sync_control_cache(struct hpi_control_cache *p_cache,
 }
 
 struct hpi_control_cache *hpi_alloc_control_cache(const u32
-       number_of_controls, const u32 size_in_bytes,
-       struct hpi_control_cache_info *pDSP_control_buffer)
+       number_of_controls, const u32 size_in_bytes, u8 *pDSP_control_buffer)
 {
        struct hpi_control_cache *p_cache =
                kmalloc(sizeof(*p_cache), GFP_KERNEL);
@@ -590,7 +625,7 @@ struct hpi_control_cache *hpi_alloc_control_cache(const u32
 
 void hpi_free_control_cache(struct hpi_control_cache *p_cache)
 {
-       if (p_cache->init) {
+       if (p_cache) {
                kfree(p_cache->p_info);
                p_cache->p_info = NULL;
                p_cache->init = 0;
@@ -600,24 +635,25 @@ void hpi_free_control_cache(struct hpi_control_cache *p_cache)
 
 static void subsys_message(struct hpi_message *phm, struct hpi_response *phr)
 {
+       hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, phm->function, 0);
 
        switch (phm->function) {
        case HPI_SUBSYS_OPEN:
        case HPI_SUBSYS_CLOSE:
        case HPI_SUBSYS_DRIVER_UNLOAD:
-               phr->error = 0;
                break;
        case HPI_SUBSYS_DRIVER_LOAD:
                wipe_adapter_list();
                hpios_alistlock_init(&adapters);
-               phr->error = 0;
                break;
-       case HPI_SUBSYS_GET_INFO:
-               subsys_get_adapters(phr);
+       case HPI_SUBSYS_GET_ADAPTER:
+               subsys_get_adapter(phm, phr);
+               break;
+       case HPI_SUBSYS_GET_NUM_ADAPTERS:
+               phr->u.s.num_adapters = adapters.gw_num_adapters;
                break;
        case HPI_SUBSYS_CREATE_ADAPTER:
        case HPI_SUBSYS_DELETE_ADAPTER:
-               phr->error = 0;
                break;
        default:
                phr->error = HPI_ERROR_INVALID_FUNC;
index 6229022f56cb0d910cef2b2a9c68cd06fc6c48fb..e2f6f1f11a668f16cd566da87e4c1cf540f809e4 100644 (file)
@@ -40,8 +40,7 @@ struct hpi_control_cache {
        struct hpi_control_cache_info
        **p_info;                /**< pointer to allocated memory of
                                lookup pointers. */
-       struct hpi_control_cache_single
-       *p_cache;                /**< pointer to DSP's control cache. */
+       u8 *p_cache;    /**< pointer to DSP's control cache. */
 };
 
 struct hpi_adapter_obj *hpi_find_adapter(u16 adapter_index);
@@ -52,12 +51,10 @@ void hpi_delete_adapter(struct hpi_adapter_obj *pao);
 short hpi_check_control_cache(struct hpi_control_cache *pC,
        struct hpi_message *phm, struct hpi_response *phr);
 struct hpi_control_cache *hpi_alloc_control_cache(const u32
-       number_of_controls, const u32 size_in_bytes,
-       struct hpi_control_cache_info
-       *pDSP_control_buffer);
+       number_of_controls, const u32 size_in_bytes, u8 *pDSP_control_buffer);
 void hpi_free_control_cache(struct hpi_control_cache *p_cache);
 
-void hpi_sync_control_cache(struct hpi_control_cache *pC,
+void hpi_cmn_control_cache_sync_to_msg(struct hpi_control_cache *pC,
        struct hpi_message *phm, struct hpi_response *phr);
 u16 hpi_validate_response(struct hpi_message *phm, struct hpi_response *phr);
 short hpi_check_buffer_mapping(struct hpi_control_cache *p_cache,
index 1e92eb6dd5091c8e5411fbac7000f4cc127beb99..aafb76955f69530428d7d4f98bc49a49e63dd85a 100644 (file)
@@ -98,21 +98,7 @@ static struct hpi_hsubsys gh_subsys;
 
 struct hpi_hsubsys *hpi_subsys_create(void)
 {
-       struct hpi_message hm;
-       struct hpi_response hr;
-
-       memset(&gh_subsys, 0, sizeof(struct hpi_hsubsys));
-
-       {
-               hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
-                       HPI_SUBSYS_OPEN);
-               hpi_send_recv(&hm, &hr);
-
-               if (hr.error == 0)
-                       return &gh_subsys;
-
-       }
-       return NULL;
+       return &gh_subsys;
 }
 
 void hpi_subsys_free(const struct hpi_hsubsys *ph_subsys)
@@ -126,18 +112,6 @@ void hpi_subsys_free(const struct hpi_hsubsys *ph_subsys)
 
 }
 
-u16 hpi_subsys_get_version(const struct hpi_hsubsys *ph_subsys, u32 *pversion)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
-               HPI_SUBSYS_GET_VERSION);
-       hpi_send_recv(&hm, &hr);
-       *pversion = hr.u.s.version;
-       return hr.error;
-}
-
 u16 hpi_subsys_get_version_ex(const struct hpi_hsubsys *ph_subsys,
        u32 *pversion_ex)
 {
@@ -151,49 +125,6 @@ u16 hpi_subsys_get_version_ex(const struct hpi_hsubsys *ph_subsys,
        return hr.error;
 }
 
-u16 hpi_subsys_get_info(const struct hpi_hsubsys *ph_subsys, u32 *pversion,
-       u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
-               HPI_SUBSYS_GET_INFO);
-
-       hpi_send_recv(&hm, &hr);
-
-       *pversion = hr.u.s.version;
-       if (list_length > HPI_MAX_ADAPTERS)
-               memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
-                       HPI_MAX_ADAPTERS);
-       else
-               memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list, list_length);
-       *pw_num_adapters = hr.u.s.num_adapters;
-       return hr.error;
-}
-
-u16 hpi_subsys_find_adapters(const struct hpi_hsubsys *ph_subsys,
-       u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
-               HPI_SUBSYS_FIND_ADAPTERS);
-
-       hpi_send_recv(&hm, &hr);
-
-       if (list_length > HPI_MAX_ADAPTERS) {
-               memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
-                       HPI_MAX_ADAPTERS * sizeof(u16));
-               memset(&aw_adapter_list[HPI_MAX_ADAPTERS], 0,
-                       (list_length - HPI_MAX_ADAPTERS) * sizeof(u16));
-       } else
-               memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
-                       list_length * sizeof(u16));
-       *pw_num_adapters = hr.u.s.num_adapters;
-
-       return hr.error;
-}
-
 u16 hpi_subsys_create_adapter(const struct hpi_hsubsys *ph_subsys,
        const struct hpi_resource *p_resource, u16 *pw_adapter_index)
 {
@@ -217,7 +148,7 @@ u16 hpi_subsys_delete_adapter(const struct hpi_hsubsys *ph_subsys,
        struct hpi_response hr;
        hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
                HPI_SUBSYS_DELETE_ADAPTER);
-       hm.adapter_index = adapter_index;
+       hm.obj_index = adapter_index;
        hpi_send_recv(&hm, &hr);
        return hr.error;
 }
@@ -241,27 +172,13 @@ u16 hpi_subsys_get_adapter(const struct hpi_hsubsys *ph_subsys, int iterator,
        struct hpi_response hr;
        hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
                HPI_SUBSYS_GET_ADAPTER);
-       hm.adapter_index = (u16)iterator;
+       hm.obj_index = (u16)iterator;
        hpi_send_recv(&hm, &hr);
        *padapter_index = (int)hr.u.s.adapter_index;
        *pw_adapter_type = hr.u.s.aw_adapter_list[0];
        return hr.error;
 }
 
-u16 hpi_subsys_set_host_network_interface(const struct hpi_hsubsys *ph_subsys,
-       const char *sz_interface)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
-               HPI_SUBSYS_SET_NETWORK_INTERFACE);
-       if (sz_interface == NULL)
-               return HPI_ERROR_INVALID_RESOURCE;
-       hm.u.s.resource.r.net_if = sz_interface;
-       hpi_send_recv(&hm, &hr);
-       return hr.error;
-}
-
 u16 hpi_adapter_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index)
 {
        struct hpi_message hm;
@@ -305,8 +222,8 @@ u16 hpi_adapter_set_mode_ex(const struct hpi_hsubsys *ph_subsys,
        hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
                HPI_ADAPTER_SET_MODE);
        hm.adapter_index = adapter_index;
-       hm.u.a.adapter_mode = adapter_mode;
-       hm.u.a.assert_id = query_or_set;
+       hm.u.ax.mode.adapter_mode = adapter_mode;
+       hm.u.ax.mode.query_or_set = query_or_set;
        hpi_send_recv(&hm, &hr);
        return hr.error;
 }
@@ -321,7 +238,7 @@ u16 hpi_adapter_get_mode(const struct hpi_hsubsys *ph_subsys,
        hm.adapter_index = adapter_index;
        hpi_send_recv(&hm, &hr);
        if (padapter_mode)
-               *padapter_mode = hr.u.a.serial_number;
+               *padapter_mode = hr.u.ax.mode.adapter_mode;
        return hr.error;
 }
 
@@ -337,11 +254,11 @@ u16 hpi_adapter_get_info(const struct hpi_hsubsys *ph_subsys,
 
        hpi_send_recv(&hm, &hr);
 
-       *pw_adapter_type = hr.u.a.adapter_type;
-       *pw_num_outstreams = hr.u.a.num_outstreams;
-       *pw_num_instreams = hr.u.a.num_instreams;
-       *pw_version = hr.u.a.version;
-       *pserial_number = hr.u.a.serial_number;
+       *pw_adapter_type = hr.u.ax.info.adapter_type;
+       *pw_num_outstreams = hr.u.ax.info.num_outstreams;
+       *pw_num_instreams = hr.u.ax.info.num_instreams;
+       *pw_version = hr.u.ax.info.version;
+       *pserial_number = hr.u.ax.info.serial_number;
        return hr.error;
 }
 
@@ -360,56 +277,20 @@ u16 hpi_adapter_get_module_by_index(const struct hpi_hsubsys *ph_subsys,
 
        hpi_send_recv(&hm, &hr);
 
-       *pw_module_type = hr.u.a.adapter_type;
-       *pw_num_outputs = hr.u.a.num_outstreams;
-       *pw_num_inputs = hr.u.a.num_instreams;
-       *pw_version = hr.u.a.version;
-       *pserial_number = hr.u.a.serial_number;
+       *pw_module_type = hr.u.ax.info.adapter_type;
+       *pw_num_outputs = hr.u.ax.info.num_outstreams;
+       *pw_num_inputs = hr.u.ax.info.num_instreams;
+       *pw_version = hr.u.ax.info.version;
+       *pserial_number = hr.u.ax.info.serial_number;
        *ph_module = 0;
 
        return hr.error;
 }
 
-u16 hpi_adapter_get_assert(const struct hpi_hsubsys *ph_subsys,
-       u16 adapter_index, u16 *assert_present, char *psz_assert,
-       u16 *pw_line_number)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
-               HPI_ADAPTER_GET_ASSERT);
-       hm.adapter_index = adapter_index;
-       hpi_send_recv(&hm, &hr);
-
-       *assert_present = 0;
-
-       if (!hr.error) {
-
-               *pw_line_number = (u16)hr.u.a.serial_number;
-               if (*pw_line_number) {
-
-                       int i;
-                       char *src = (char *)hr.u.a.sz_adapter_assert;
-                       char *dst = psz_assert;
-
-                       *assert_present = 1;
-
-                       for (i = 0; i < HPI_STRING_LEN; i++) {
-                               char c;
-                               c = *src++;
-                               *dst++ = c;
-                               if (c == 0)
-                                       break;
-                       }
-
-               }
-       }
-       return hr.error;
-}
-
-u16 hpi_adapter_get_assert_ex(const struct hpi_hsubsys *ph_subsys,
-       u16 adapter_index, u16 *assert_present, char *psz_assert,
-       u32 *pline_number, u16 *pw_assert_on_dsp)
+u16 hpi_adapter_get_assert2(const struct hpi_hsubsys *ph_subsys,
+       u16 adapter_index, u16 *p_assert_count, char *psz_assert,
+       u32 *p_param1, u32 *p_param2, u32 *p_dsp_string_addr,
+       u16 *p_processor_id)
 {
        struct hpi_message hm;
        struct hpi_response hr;
@@ -419,34 +300,18 @@ u16 hpi_adapter_get_assert_ex(const struct hpi_hsubsys *ph_subsys,
 
        hpi_send_recv(&hm, &hr);
 
-       *assert_present = 0;
+       *p_assert_count = 0;
 
        if (!hr.error) {
-
-               *pline_number = hr.u.a.serial_number;
-
-               *assert_present = hr.u.a.adapter_type;
-
-               *pw_assert_on_dsp = hr.u.a.adapter_index;
-
-               if (!*assert_present && *pline_number)
-
-                       *assert_present = 1;
-
-               if (*assert_present) {
-
-                       int i;
-                       char *src = (char *)hr.u.a.sz_adapter_assert;
-                       char *dst = psz_assert;
-
-                       for (i = 0; i < HPI_STRING_LEN; i++) {
-                               char c;
-                               c = *src++;
-                               *dst++ = c;
-                               if (c == 0)
-                                       break;
-                       }
-
+               *p_assert_count = hr.u.ax.assert.count;
+
+               if (*p_assert_count) {
+                       *p_param1 = hr.u.ax.assert.p1;
+                       *p_param2 = hr.u.ax.assert.p2;
+                       *p_processor_id = hr.u.ax.assert.dsp_index;
+                       *p_dsp_string_addr = hr.u.ax.assert.dsp_msg_addr;
+                       memcpy(psz_assert, hr.u.ax.assert.sz_message,
+                               HPI_STRING_LEN);
                } else {
                        *psz_assert = 0;
                }
@@ -462,7 +327,7 @@ u16 hpi_adapter_test_assert(const struct hpi_hsubsys *ph_subsys,
        hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
                HPI_ADAPTER_TEST_ASSERT);
        hm.adapter_index = adapter_index;
-       hm.u.a.assert_id = assert_id;
+       hm.u.ax.test_assert.value = assert_id;
 
        hpi_send_recv(&hm, &hr);
 
@@ -472,17 +337,21 @@ u16 hpi_adapter_test_assert(const struct hpi_hsubsys *ph_subsys,
 u16 hpi_adapter_enable_capability(const struct hpi_hsubsys *ph_subsys,
        u16 adapter_index, u16 capability, u32 key)
 {
+#if 1
+       return HPI_ERROR_UNIMPLEMENTED;
+#else
        struct hpi_message hm;
        struct hpi_response hr;
        hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
                HPI_ADAPTER_ENABLE_CAPABILITY);
        hm.adapter_index = adapter_index;
-       hm.u.a.assert_id = capability;
-       hm.u.a.adapter_mode = key;
+       hm.u.ax.enable_cap.cap = capability;
+       hm.u.ax.enable_cap.key = key;
 
        hpi_send_recv(&hm, &hr);
 
        return hr.error;
+#endif
 }
 
 u16 hpi_adapter_self_test(const struct hpi_hsubsys *ph_subsys,
@@ -500,29 +369,32 @@ u16 hpi_adapter_self_test(const struct hpi_hsubsys *ph_subsys,
 u16 hpi_adapter_debug_read(const struct hpi_hsubsys *ph_subsys,
        u16 adapter_index, u32 dsp_address, char *p_buffer, int *count_bytes)
 {
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
-               HPI_ADAPTER_DEBUG_READ);
+       struct hpi_msg_adapter_debug_read hm;
+       struct hpi_res_adapter_debug_read hr;
 
-       hr.size = sizeof(hr);
+       hpi_init_message_responseV1(&hm.h, sizeof(hm), &hr.h, sizeof(hr),
+               HPI_OBJ_ADAPTER, HPI_ADAPTER_DEBUG_READ);
 
-       hm.adapter_index = adapter_index;
-       hm.u.ax.debug_read.dsp_address = dsp_address;
+       hm.h.adapter_index = adapter_index;
+       hm.dsp_address = dsp_address;
 
-       if (*count_bytes > (int)sizeof(hr.u.bytes))
-               *count_bytes = sizeof(hr.u.bytes);
+       if (*count_bytes > (int)sizeof(hr.bytes))
+               *count_bytes = (int)sizeof(hr.bytes);
 
-       hm.u.ax.debug_read.count_bytes = *count_bytes;
+       hm.count_bytes = *count_bytes;
 
-       hpi_send_recv(&hm, &hr);
+       hpi_send_recv((struct hpi_message *)&hm, (struct hpi_response *)&hr);
 
-       if (!hr.error) {
-               *count_bytes = hr.size - 12;
-               memcpy(p_buffer, &hr.u.bytes, *count_bytes);
+       if (!hr.h.error) {
+               int res_bytes = hr.h.size - sizeof(hr.h);
+               if (res_bytes > *count_bytes)
+                       res_bytes = *count_bytes;
+               *count_bytes = res_bytes;
+               memcpy(p_buffer, &hr.bytes, res_bytes);
        } else
                *count_bytes = 0;
-       return hr.error;
+
+       return hr.h.error;
 }
 
 u16 hpi_adapter_set_property(const struct hpi_hsubsys *ph_subsys,
@@ -1682,7 +1554,7 @@ static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,
        unsigned int sub_string_index = 0, j = 0;
        char c = 0;
        unsigned int n = 0;
-       u16 hE = 0;
+       u16 err = 0;
 
        if ((string_length < 1) || (string_length > 256))
                return HPI_ERROR_INVALID_CONTROL_VALUE;
@@ -1705,7 +1577,7 @@ static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,
                        return HPI_ERROR_INVALID_CONTROL_VALUE;
 
                if (hr.error) {
-                       hE = hr.error;
+                       err = hr.error;
                        break;
                }
                for (j = 0; j < 8; j++) {
@@ -1714,7 +1586,7 @@ static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,
                        n++;
                        if (n >= string_length) {
                                psz_string[string_length - 1] = 0;
-                               hE = HPI_ERROR_INVALID_CONTROL_VALUE;
+                               err = HPI_ERROR_INVALID_CONTROL_VALUE;
                                break;
                        }
                        if (c == 0)
@@ -1730,7 +1602,7 @@ static u16 hpi_control_get_string(const u32 h_control, const u16 attribute,
                if (c == 0)
                        break;
        }
-       return hE;
+       return err;
 }
 
 u16 HPI_AESEBU__receiver_query_format(const struct hpi_hsubsys *ph_subsys,
@@ -2709,7 +2581,7 @@ u16 hpi_tone_detector_set_enable(const struct hpi_hsubsys *ph_subsys,
        u32 h_control, u32 enable)
 {
        return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE,
-               (u32)enable, 0);
+               enable, 0);
 }
 
 u16 hpi_tone_detector_get_enable(const struct hpi_hsubsys *ph_subsys,
@@ -2758,7 +2630,7 @@ u16 hpi_silence_detector_set_enable(const struct hpi_hsubsys *ph_subsys,
        u32 h_control, u32 enable)
 {
        return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE,
-               (u32)enable, 0);
+               enable, 0);
 }
 
 u16 hpi_silence_detector_get_enable(const struct hpi_hsubsys *ph_subsys,
@@ -2904,11 +2776,10 @@ u16 hpi_tuner_getRF_level(const struct hpi_hsubsys *ph_subsys, u32 h_control,
        hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
                HPI_CONTROL_GET_STATE);
        u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
-       hm.u.c.attribute = HPI_TUNER_LEVEL;
-       hm.u.c.param1 = HPI_TUNER_LEVEL_AVERAGE;
+       hm.u.cu.attribute = HPI_TUNER_LEVEL_AVG;
        hpi_send_recv(&hm, &hr);
        if (pw_level)
-               *pw_level = (short)hr.u.c.param1;
+               *pw_level = hr.u.cu.tuner.s_level;
        return hr.error;
 }
 
@@ -2921,11 +2792,10 @@ u16 hpi_tuner_get_rawRF_level(const struct hpi_hsubsys *ph_subsys,
        hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
                HPI_CONTROL_GET_STATE);
        u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
-       hm.u.c.attribute = HPI_TUNER_LEVEL;
-       hm.u.c.param1 = HPI_TUNER_LEVEL_RAW;
+       hm.u.cu.attribute = HPI_TUNER_LEVEL_RAW;
        hpi_send_recv(&hm, &hr);
        if (pw_level)
-               *pw_level = (short)hr.u.c.param1;
+               *pw_level = hr.u.cu.tuner.s_level;
        return hr.error;
 }
 
@@ -3213,728 +3083,3 @@ u16 hpi_vox_get_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,
 
        return hr.error;
 }
-
-static size_t strv_packet_size = MIN_STRV_PACKET_SIZE;
-
-static size_t entity_type_to_size[LAST_ENTITY_TYPE] = {
-       0,
-       sizeof(struct hpi_entity),
-       sizeof(void *),
-
-       sizeof(int),
-       sizeof(float),
-       sizeof(double),
-
-       sizeof(char),
-       sizeof(char),
-
-       4 * sizeof(char),
-       16 * sizeof(char),
-       6 * sizeof(char),
-};
-
-static inline size_t hpi_entity_size(struct hpi_entity *entity_ptr)
-{
-       return entity_ptr->header.size;
-}
-
-static inline size_t hpi_entity_header_size(struct hpi_entity *entity_ptr)
-{
-       return sizeof(entity_ptr->header);
-}
-
-static inline size_t hpi_entity_value_size(struct hpi_entity *entity_ptr)
-{
-       return hpi_entity_size(entity_ptr) -
-               hpi_entity_header_size(entity_ptr);
-}
-
-static inline size_t hpi_entity_item_count(struct hpi_entity *entity_ptr)
-{
-       return hpi_entity_value_size(entity_ptr) /
-               entity_type_to_size[entity_ptr->header.type];
-}
-
-static inline struct hpi_entity *hpi_entity_ptr_to_next(struct hpi_entity
-       *entity_ptr)
-{
-       return (void *)(((u8 *)entity_ptr) + hpi_entity_size(entity_ptr));
-}
-
-static inline u16 hpi_entity_check_type(const enum e_entity_type t)
-{
-       if (t >= 0 && t < STR_TYPE_FIELD_MAX)
-               return 0;
-       return HPI_ERROR_ENTITY_TYPE_INVALID;
-}
-
-static inline u16 hpi_entity_check_role(const enum e_entity_role r)
-{
-       if (r >= 0 && r < STR_ROLE_FIELD_MAX)
-               return 0;
-       return HPI_ERROR_ENTITY_ROLE_INVALID;
-}
-
-static u16 hpi_entity_get_next(struct hpi_entity *entity, int recursive_flag,
-       void *guard_p, struct hpi_entity **next)
-{
-       HPI_DEBUG_ASSERT(entity != NULL);
-       HPI_DEBUG_ASSERT(next != NULL);
-       HPI_DEBUG_ASSERT(hpi_entity_size(entity) != 0);
-
-       if (guard_p <= (void *)entity) {
-               *next = NULL;
-               return 0;
-       }
-
-       if (recursive_flag && entity->header.type == entity_type_sequence)
-               *next = (struct hpi_entity *)entity->value;
-       else
-               *next = (struct hpi_entity *)hpi_entity_ptr_to_next(entity);
-
-       if (guard_p <= (void *)*next) {
-               *next = NULL;
-               return 0;
-       }
-
-       HPI_DEBUG_ASSERT(guard_p >= (void *)hpi_entity_ptr_to_next(*next));
-       return 0;
-}
-
-u16 hpi_entity_find_next(struct hpi_entity *container_entity,
-       enum e_entity_type type, enum e_entity_role role, int recursive_flag,
-       struct hpi_entity **current_match)
-{
-       struct hpi_entity *tmp = NULL;
-       void *guard_p = NULL;
-
-       HPI_DEBUG_ASSERT(container_entity != NULL);
-       guard_p = hpi_entity_ptr_to_next(container_entity);
-
-       if (*current_match != NULL)
-               hpi_entity_get_next(*current_match, recursive_flag, guard_p,
-                       &tmp);
-       else
-               hpi_entity_get_next(container_entity, 1, guard_p, &tmp);
-
-       while (tmp) {
-               u16 err;
-
-               HPI_DEBUG_ASSERT((void *)tmp >= (void *)container_entity);
-
-               if ((!type || tmp->header.type == type) && (!role
-                               || tmp->header.role == role)) {
-                       *current_match = tmp;
-                       return 0;
-               }
-
-               err = hpi_entity_get_next(tmp, recursive_flag, guard_p,
-                       current_match);
-               if (err)
-                       return err;
-
-               tmp = *current_match;
-       }
-
-       *current_match = NULL;
-       return 0;
-}
-
-void hpi_entity_free(struct hpi_entity *entity)
-{
-       kfree(entity);
-}
-
-static u16 hpi_entity_alloc_and_copy(struct hpi_entity *src,
-       struct hpi_entity **dst)
-{
-       size_t buf_size;
-       HPI_DEBUG_ASSERT(dst != NULL);
-       HPI_DEBUG_ASSERT(src != NULL);
-
-       buf_size = hpi_entity_size(src);
-       *dst = kmalloc(buf_size, GFP_KERNEL);
-       if (*dst == NULL)
-               return HPI_ERROR_MEMORY_ALLOC;
-       memcpy(*dst, src, buf_size);
-       return 0;
-}
-
-u16 hpi_universal_info(const struct hpi_hsubsys *ph_subsys, u32 hC,
-       struct hpi_entity **info)
-{
-       struct hpi_msg_strv hm;
-       struct hpi_res_strv *phr;
-       u16 hpi_err;
-       int remaining_attempts = 2;
-       size_t resp_packet_size = 1024;
-
-       *info = NULL;
-
-       while (remaining_attempts--) {
-               phr = kmalloc(resp_packet_size, GFP_KERNEL);
-               HPI_DEBUG_ASSERT(phr != NULL);
-
-               hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h,
-                       (u16)resp_packet_size, HPI_OBJ_CONTROL,
-                       HPI_CONTROL_GET_INFO);
-               u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index);
-
-               hm.strv.header.size = sizeof(hm.strv);
-               phr->strv.header.size = resp_packet_size - sizeof(phr->h);
-
-               hpi_send_recv((struct hpi_message *)&hm.h,
-                       (struct hpi_response *)&phr->h);
-               if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) {
-
-                       HPI_DEBUG_ASSERT(phr->h.specific_error >
-                               MIN_STRV_PACKET_SIZE
-                               && phr->h.specific_error < 1500);
-                       resp_packet_size = phr->h.specific_error;
-               } else {
-                       remaining_attempts = 0;
-                       if (!phr->h.error)
-                               hpi_entity_alloc_and_copy(&phr->strv, info);
-               }
-
-               hpi_err = phr->h.error;
-               kfree(phr);
-       }
-
-       return hpi_err;
-}
-
-u16 hpi_universal_get(const struct hpi_hsubsys *ph_subsys, u32 hC,
-       struct hpi_entity **value)
-{
-       struct hpi_msg_strv hm;
-       struct hpi_res_strv *phr;
-       u16 hpi_err;
-       int remaining_attempts = 2;
-
-       *value = NULL;
-
-       while (remaining_attempts--) {
-               phr = kmalloc(strv_packet_size, GFP_KERNEL);
-               if (!phr)
-                       return HPI_ERROR_MEMORY_ALLOC;
-
-               hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h,
-                       (u16)strv_packet_size, HPI_OBJ_CONTROL,
-                       HPI_CONTROL_GET_STATE);
-               u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index);
-
-               hm.strv.header.size = sizeof(hm.strv);
-               phr->strv.header.size = strv_packet_size - sizeof(phr->h);
-
-               hpi_send_recv((struct hpi_message *)&hm.h,
-                       (struct hpi_response *)&phr->h);
-               if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) {
-
-                       HPI_DEBUG_ASSERT(phr->h.specific_error >
-                               MIN_STRV_PACKET_SIZE
-                               && phr->h.specific_error < 1000);
-                       strv_packet_size = phr->h.specific_error;
-               } else {
-                       remaining_attempts = 0;
-                       if (!phr->h.error)
-                               hpi_entity_alloc_and_copy(&phr->strv, value);
-               }
-
-               hpi_err = phr->h.error;
-               kfree(phr);
-       }
-
-       return hpi_err;
-}
-
-u16 hpi_universal_set(const struct hpi_hsubsys *ph_subsys, u32 hC,
-       struct hpi_entity *value)
-{
-       struct hpi_msg_strv *phm;
-       struct hpi_res_strv hr;
-
-       phm = kmalloc(sizeof(phm->h) + value->header.size, GFP_KERNEL);
-       HPI_DEBUG_ASSERT(phm != NULL);
-
-       hpi_init_message_responseV1(&phm->h,
-               sizeof(phm->h) + value->header.size, &hr.h, sizeof(hr),
-               HPI_OBJ_CONTROL, HPI_CONTROL_SET_STATE);
-       u32TOINDEXES(hC, &phm->h.adapter_index, &phm->h.obj_index);
-       hr.strv.header.size = sizeof(hr.strv);
-
-       memcpy(&phm->strv, value, value->header.size);
-       hpi_send_recv((struct hpi_message *)&phm->h,
-               (struct hpi_response *)&hr.h);
-
-       return hr.h.error;
-}
-
-u16 hpi_entity_alloc_and_pack(const enum e_entity_type type,
-       const size_t item_count, const enum e_entity_role role, void *value,
-       struct hpi_entity **entity)
-{
-       size_t bytes_to_copy, total_size;
-       u16 hE = 0;
-       *entity = NULL;
-
-       hE = hpi_entity_check_type(type);
-       if (hE)
-               return hE;
-
-       HPI_DEBUG_ASSERT(role > entity_role_null && type < LAST_ENTITY_TYPE);
-
-       bytes_to_copy = entity_type_to_size[type] * item_count;
-       total_size = hpi_entity_header_size(*entity) + bytes_to_copy;
-
-       HPI_DEBUG_ASSERT(total_size >= hpi_entity_header_size(*entity)
-               && total_size < STR_SIZE_FIELD_MAX);
-
-       *entity = kmalloc(total_size, GFP_KERNEL);
-       if (*entity == NULL)
-               return HPI_ERROR_MEMORY_ALLOC;
-       memcpy((*entity)->value, value, bytes_to_copy);
-       (*entity)->header.size =
-               hpi_entity_header_size(*entity) + bytes_to_copy;
-       (*entity)->header.type = type;
-       (*entity)->header.role = role;
-       return 0;
-}
-
-u16 hpi_entity_copy_value_from(struct hpi_entity *entity,
-       enum e_entity_type type, size_t item_count, void *value_dst_p)
-{
-       size_t bytes_to_copy;
-
-       if (entity->header.type != type)
-               return HPI_ERROR_ENTITY_TYPE_MISMATCH;
-
-       if (hpi_entity_item_count(entity) != item_count)
-               return HPI_ERROR_ENTITY_ITEM_COUNT;
-
-       bytes_to_copy = entity_type_to_size[type] * item_count;
-       memcpy(value_dst_p, entity->value, bytes_to_copy);
-       return 0;
-}
-
-u16 hpi_entity_unpack(struct hpi_entity *entity, enum e_entity_type *type,
-       size_t *item_count, enum e_entity_role *role, void **value)
-{
-       u16 err = 0;
-       HPI_DEBUG_ASSERT(entity != NULL);
-
-       if (type)
-               *type = entity->header.type;
-
-       if (role)
-               *role = entity->header.role;
-
-       if (value)
-               *value = entity->value;
-
-       if (item_count != NULL) {
-               if (entity->header.type == entity_type_sequence) {
-                       void *guard_p = hpi_entity_ptr_to_next(entity);
-                       struct hpi_entity *next = NULL;
-                       void *contents = entity->value;
-
-                       *item_count = 0;
-                       while (contents < guard_p) {
-                               (*item_count)++;
-                               err = hpi_entity_get_next(contents, 0,
-                                       guard_p, &next);
-                               if (next == NULL || err)
-                                       break;
-                               contents = next;
-                       }
-               } else {
-                       *item_count = hpi_entity_item_count(entity);
-               }
-       }
-       return err;
-}
-
-u16 hpi_gpio_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
-       u32 *ph_gpio, u16 *pw_number_input_bits, u16 *pw_number_output_bits)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_OPEN);
-       hm.adapter_index = adapter_index;
-
-       hpi_send_recv(&hm, &hr);
-
-       if (hr.error == 0) {
-               *ph_gpio =
-                       hpi_indexes_to_handle(HPI_OBJ_GPIO, adapter_index, 0);
-               if (pw_number_input_bits)
-                       *pw_number_input_bits = hr.u.l.number_input_bits;
-               if (pw_number_output_bits)
-                       *pw_number_output_bits = hr.u.l.number_output_bits;
-       } else
-               *ph_gpio = 0;
-       return hr.error;
-}
-
-u16 hpi_gpio_read_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
-       u16 bit_index, u16 *pw_bit_data)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_BIT);
-       u32TOINDEX(h_gpio, &hm.adapter_index);
-       hm.u.l.bit_index = bit_index;
-
-       hpi_send_recv(&hm, &hr);
-
-       *pw_bit_data = hr.u.l.bit_data[0];
-       return hr.error;
-}
-
-u16 hpi_gpio_read_all_bits(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
-       u16 aw_all_bit_data[4]
-       )
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_ALL);
-       u32TOINDEX(h_gpio, &hm.adapter_index);
-
-       hpi_send_recv(&hm, &hr);
-
-       if (aw_all_bit_data) {
-               aw_all_bit_data[0] = hr.u.l.bit_data[0];
-               aw_all_bit_data[1] = hr.u.l.bit_data[1];
-               aw_all_bit_data[2] = hr.u.l.bit_data[2];
-               aw_all_bit_data[3] = hr.u.l.bit_data[3];
-       }
-       return hr.error;
-}
-
-u16 hpi_gpio_write_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
-       u16 bit_index, u16 bit_data)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_WRITE_BIT);
-       u32TOINDEX(h_gpio, &hm.adapter_index);
-       hm.u.l.bit_index = bit_index;
-       hm.u.l.bit_data = bit_data;
-
-       hpi_send_recv(&hm, &hr);
-
-       return hr.error;
-}
-
-u16 hpi_gpio_write_status(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
-       u16 aw_all_bit_data[4]
-       )
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO,
-               HPI_GPIO_WRITE_STATUS);
-       u32TOINDEX(h_gpio, &hm.adapter_index);
-
-       hpi_send_recv(&hm, &hr);
-
-       if (aw_all_bit_data) {
-               aw_all_bit_data[0] = hr.u.l.bit_data[0];
-               aw_all_bit_data[1] = hr.u.l.bit_data[1];
-               aw_all_bit_data[2] = hr.u.l.bit_data[2];
-               aw_all_bit_data[3] = hr.u.l.bit_data[3];
-       }
-       return hr.error;
-}
-
-u16 hpi_async_event_open(const struct hpi_hsubsys *ph_subsys,
-       u16 adapter_index, u32 *ph_async)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
-               HPI_ASYNCEVENT_OPEN);
-       hm.adapter_index = adapter_index;
-
-       hpi_send_recv(&hm, &hr);
-
-       if (hr.error == 0)
-
-               *ph_async =
-                       hpi_indexes_to_handle(HPI_OBJ_ASYNCEVENT,
-                       adapter_index, 0);
-       else
-               *ph_async = 0;
-       return hr.error;
-
-}
-
-u16 hpi_async_event_close(const struct hpi_hsubsys *ph_subsys, u32 h_async)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
-               HPI_ASYNCEVENT_OPEN);
-       u32TOINDEX(h_async, &hm.adapter_index);
-
-       hpi_send_recv(&hm, &hr);
-
-       return hr.error;
-}
-
-u16 hpi_async_event_wait(const struct hpi_hsubsys *ph_subsys, u32 h_async,
-       u16 maximum_events, struct hpi_async_event *p_events,
-       u16 *pw_number_returned)
-{
-
-       return 0;
-}
-
-u16 hpi_async_event_get_count(const struct hpi_hsubsys *ph_subsys,
-       u32 h_async, u16 *pw_count)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
-               HPI_ASYNCEVENT_GETCOUNT);
-       u32TOINDEX(h_async, &hm.adapter_index);
-
-       hpi_send_recv(&hm, &hr);
-
-       if (hr.error == 0)
-               if (pw_count)
-                       *pw_count = hr.u.as.u.count.count;
-
-       return hr.error;
-}
-
-u16 hpi_async_event_get(const struct hpi_hsubsys *ph_subsys, u32 h_async,
-       u16 maximum_events, struct hpi_async_event *p_events,
-       u16 *pw_number_returned)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
-               HPI_ASYNCEVENT_GET);
-       u32TOINDEX(h_async, &hm.adapter_index);
-
-       hpi_send_recv(&hm, &hr);
-       if (!hr.error) {
-               memcpy(p_events, &hr.u.as.u.event,
-                       sizeof(struct hpi_async_event));
-               *pw_number_returned = 1;
-       }
-
-       return hr.error;
-}
-
-u16 hpi_nv_memory_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
-       u32 *ph_nv_memory, u16 *pw_size_in_bytes)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
-               HPI_NVMEMORY_OPEN);
-       hm.adapter_index = adapter_index;
-
-       hpi_send_recv(&hm, &hr);
-
-       if (hr.error == 0) {
-               *ph_nv_memory =
-                       hpi_indexes_to_handle(HPI_OBJ_NVMEMORY, adapter_index,
-                       0);
-               if (pw_size_in_bytes)
-                       *pw_size_in_bytes = hr.u.n.size_in_bytes;
-       } else
-               *ph_nv_memory = 0;
-       return hr.error;
-}
-
-u16 hpi_nv_memory_read_byte(const struct hpi_hsubsys *ph_subsys,
-       u32 h_nv_memory, u16 index, u16 *pw_data)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
-               HPI_NVMEMORY_READ_BYTE);
-       u32TOINDEX(h_nv_memory, &hm.adapter_index);
-       hm.u.n.address = index;
-
-       hpi_send_recv(&hm, &hr);
-
-       *pw_data = hr.u.n.data;
-       return hr.error;
-}
-
-u16 hpi_nv_memory_write_byte(const struct hpi_hsubsys *ph_subsys,
-       u32 h_nv_memory, u16 index, u16 data)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
-               HPI_NVMEMORY_WRITE_BYTE);
-       u32TOINDEX(h_nv_memory, &hm.adapter_index);
-       hm.u.n.address = index;
-       hm.u.n.data = data;
-
-       hpi_send_recv(&hm, &hr);
-
-       return hr.error;
-}
-
-u16 hpi_profile_open_all(const struct hpi_hsubsys *ph_subsys,
-       u16 adapter_index, u16 profile_index, u32 *ph_profile,
-       u16 *pw_max_profiles)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
-               HPI_PROFILE_OPEN_ALL);
-       hm.adapter_index = adapter_index;
-       hm.obj_index = profile_index;
-       hpi_send_recv(&hm, &hr);
-
-       *pw_max_profiles = hr.u.p.u.o.max_profiles;
-       if (hr.error == 0)
-               *ph_profile =
-                       hpi_indexes_to_handle(HPI_OBJ_PROFILE, adapter_index,
-                       profile_index);
-       else
-               *ph_profile = 0;
-       return hr.error;
-}
-
-u16 hpi_profile_get(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
-       u16 bin_index, u16 *pw_seconds, u32 *pmicro_seconds, u32 *pcall_count,
-       u32 *pmax_micro_seconds, u32 *pmin_micro_seconds)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE, HPI_PROFILE_GET);
-       u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
-       hm.u.p.bin_index = bin_index;
-       hpi_send_recv(&hm, &hr);
-       if (pw_seconds)
-               *pw_seconds = hr.u.p.u.t.seconds;
-       if (pmicro_seconds)
-               *pmicro_seconds = hr.u.p.u.t.micro_seconds;
-       if (pcall_count)
-               *pcall_count = hr.u.p.u.t.call_count;
-       if (pmax_micro_seconds)
-               *pmax_micro_seconds = hr.u.p.u.t.max_micro_seconds;
-       if (pmin_micro_seconds)
-               *pmin_micro_seconds = hr.u.p.u.t.min_micro_seconds;
-       return hr.error;
-}
-
-u16 hpi_profile_get_utilization(const struct hpi_hsubsys *ph_subsys,
-       u32 h_profile, u32 *putilization)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
-               HPI_PROFILE_GET_UTILIZATION);
-       u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
-       hpi_send_recv(&hm, &hr);
-       if (hr.error) {
-               if (putilization)
-                       *putilization = 0;
-       } else {
-               if (putilization)
-                       *putilization = hr.u.p.u.t.call_count;
-       }
-       return hr.error;
-}
-
-u16 hpi_profile_get_name(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
-       u16 bin_index, char *sz_name, u16 name_length)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
-               HPI_PROFILE_GET_NAME);
-       u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
-       hm.u.p.bin_index = bin_index;
-       hpi_send_recv(&hm, &hr);
-       if (hr.error) {
-               if (sz_name)
-                       strcpy(sz_name, "??");
-       } else {
-               if (sz_name)
-                       memcpy(sz_name, (char *)hr.u.p.u.n.sz_name,
-                               name_length);
-       }
-       return hr.error;
-}
-
-u16 hpi_profile_start_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
-               HPI_PROFILE_START_ALL);
-       u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
-       hpi_send_recv(&hm, &hr);
-
-       return hr.error;
-}
-
-u16 hpi_profile_stop_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
-               HPI_PROFILE_STOP_ALL);
-       u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
-       hpi_send_recv(&hm, &hr);
-
-       return hr.error;
-}
-
-u16 hpi_watchdog_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
-       u32 *ph_watchdog)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
-               HPI_WATCHDOG_OPEN);
-       hm.adapter_index = adapter_index;
-
-       hpi_send_recv(&hm, &hr);
-
-       if (hr.error == 0)
-               *ph_watchdog =
-                       hpi_indexes_to_handle(HPI_OBJ_WATCHDOG, adapter_index,
-                       0);
-       else
-               *ph_watchdog = 0;
-       return hr.error;
-}
-
-u16 hpi_watchdog_set_time(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog,
-       u32 time_millisec)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
-               HPI_WATCHDOG_SET_TIME);
-       u32TOINDEX(h_watchdog, &hm.adapter_index);
-       hm.u.w.time_ms = time_millisec;
-
-       hpi_send_recv(&hm, &hr);
-
-       return hr.error;
-}
-
-u16 hpi_watchdog_ping(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog)
-{
-       struct hpi_message hm;
-       struct hpi_response hr;
-       hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
-               HPI_WATCHDOG_PING);
-       u32TOINDEX(h_watchdog, &hm.adapter_index);
-
-       hpi_send_recv(&hm, &hr);
-
-       return hr.error;
-}
index 42f918220ee4f457370e952ed16b396f186f2638..628376ce4a4989456ce9170fee2f63d41f1969a0 100644 (file)
@@ -50,7 +50,7 @@ static void hpi_init_message(struct hpi_message *phm, u16 object,
        phm->object = object;
        phm->function = function;
        phm->version = 0;
-       phm->adapter_index = 0xFFFF;
+       phm->adapter_index = HPI_ADAPTER_INDEX_INVALID;
        /* Expect actual adapter index to be set by caller */
 }
 
index f01ab964f6022ba847c04b9fe4d23426ae4d5b92..b4e7d9a194724a100320aa8326abf9be1cc8b870 100644 (file)
@@ -23,6 +23,7 @@ Extended Message Function With Response Cacheing
 #define SOURCEFILE_NAME "hpimsgx.c"
 #include "hpi_internal.h"
 #include "hpimsginit.h"
+#include "hpicmn.h"
 #include "hpimsgx.h"
 #include "hpidebug.h"
 
@@ -42,22 +43,24 @@ static hpi_handler_func *hpi_lookup_entry_point_function(const struct hpi_pci
 
        for (i = 0; asihpi_pci_tbl[i].vendor != 0; i++) {
                if (asihpi_pci_tbl[i].vendor != PCI_ANY_ID
-                       && asihpi_pci_tbl[i].vendor != pci_info->vendor_id)
+                       && asihpi_pci_tbl[i].vendor !=
+                       pci_info->pci_dev->vendor)
                        continue;
                if (asihpi_pci_tbl[i].device != PCI_ANY_ID
-                       && asihpi_pci_tbl[i].device != pci_info->device_id)
+                       && asihpi_pci_tbl[i].device !=
+                       pci_info->pci_dev->device)
                        continue;
                if (asihpi_pci_tbl[i].subvendor != PCI_ANY_ID
                        && asihpi_pci_tbl[i].subvendor !=
-                       pci_info->subsys_vendor_id)
+                       pci_info->pci_dev->subsystem_vendor)
                        continue;
                if (asihpi_pci_tbl[i].subdevice != PCI_ANY_ID
                        && asihpi_pci_tbl[i].subdevice !=
-                       pci_info->subsys_device_id)
+                       pci_info->pci_dev->subsystem_device)
                        continue;
 
-               HPI_DEBUG_LOG(DEBUG, " %x,%lu\n", i,
-                       asihpi_pci_tbl[i].driver_data);
+               /* HPI_DEBUG_LOG(DEBUG, " %x,%lx\n", i,
+                  asihpi_pci_tbl[i].driver_data); */
                return (hpi_handler_func *) asihpi_pci_tbl[i].driver_data;
        }
 
@@ -67,21 +70,12 @@ static hpi_handler_func *hpi_lookup_entry_point_function(const struct hpi_pci
 static inline void hw_entry_point(struct hpi_message *phm,
        struct hpi_response *phr)
 {
-
-       hpi_handler_func *ep;
-
-       if (phm->adapter_index < HPI_MAX_ADAPTERS) {
-               ep = (hpi_handler_func *) hpi_entry_points[phm->
-                       adapter_index];
-               if (ep) {
-                       HPI_DEBUG_MESSAGE(DEBUG, phm);
-                       ep(phm, phr);
-                       HPI_DEBUG_RESPONSE(phr);
-                       return;
-               }
-       }
-       hpi_init_response(phr, phm->object, phm->function,
-               HPI_ERROR_PROCESSING_MESSAGE);
+       if ((phm->adapter_index < HPI_MAX_ADAPTERS)
+               && hpi_entry_points[phm->adapter_index])
+               hpi_entry_points[phm->adapter_index] (phm, phr);
+       else
+               hpi_init_response(phr, phm->object, phm->function,
+                       HPI_ERROR_PROCESSING_MESSAGE);
 }
 
 static void adapter_open(struct hpi_message *phm, struct hpi_response *phr);
@@ -100,6 +94,7 @@ static void instream_close(struct hpi_message *phm, struct hpi_response *phr,
        void *h_owner);
 
 static void HPIMSGX__reset(u16 adapter_index);
+
 static u16 HPIMSGX__init(struct hpi_message *phm, struct hpi_response *phr);
 static void HPIMSGX__cleanup(u16 adapter_index, void *h_owner);
 
@@ -153,8 +148,6 @@ static struct hpi_stream_response
 
 static struct hpi_mixer_response rESP_HPI_MIXER_OPEN[HPI_MAX_ADAPTERS];
 
-static struct hpi_subsys_response gRESP_HPI_SUBSYS_FIND_ADAPTERS;
-
 static struct adapter_info aDAPTER_INFO[HPI_MAX_ADAPTERS];
 
 /* use these to keep track of opens from user mode apps/DLLs */
@@ -167,6 +160,11 @@ static struct asi_open_state
 static void subsys_message(struct hpi_message *phm, struct hpi_response *phr,
        void *h_owner)
 {
+       if (phm->adapter_index != HPI_ADAPTER_INDEX_INVALID)
+               HPI_DEBUG_LOG(WARNING,
+                       "suspicious adapter index %d in subsys message 0x%x.\n",
+                       phm->adapter_index, phm->function);
+
        switch (phm->function) {
        case HPI_SUBSYS_GET_VERSION:
                hpi_init_response(phr, HPI_OBJ_SUBSYSTEM,
@@ -204,85 +202,37 @@ static void subsys_message(struct hpi_message *phm, struct hpi_response *phr,
                        HPI_SUBSYS_DRIVER_UNLOAD, 0);
                return;
 
-       case HPI_SUBSYS_GET_INFO:
-               HPI_COMMON(phm, phr);
-               break;
-
-       case HPI_SUBSYS_FIND_ADAPTERS:
-               memcpy(phr, &gRESP_HPI_SUBSYS_FIND_ADAPTERS,
-                       sizeof(gRESP_HPI_SUBSYS_FIND_ADAPTERS));
-               break;
        case HPI_SUBSYS_GET_NUM_ADAPTERS:
-               memcpy(phr, &gRESP_HPI_SUBSYS_FIND_ADAPTERS,
-                       sizeof(gRESP_HPI_SUBSYS_FIND_ADAPTERS));
-               phr->function = HPI_SUBSYS_GET_NUM_ADAPTERS;
-               break;
        case HPI_SUBSYS_GET_ADAPTER:
-               {
-                       int count = phm->adapter_index;
-                       int index = 0;
-                       hpi_init_response(phr, HPI_OBJ_SUBSYSTEM,
-                               HPI_SUBSYS_GET_ADAPTER, 0);
-
-                       /* This is complicated by the fact that we want to
-                        * "skip" 0's in the adapter list.
-                        * First, make sure we are pointing to a
-                        * non-zero adapter type.
-                        */
-                       while (gRESP_HPI_SUBSYS_FIND_ADAPTERS.
-                               s.aw_adapter_list[index] == 0) {
-                               index++;
-                               if (index >= HPI_MAX_ADAPTERS)
-                                       break;
-                       }
-                       while (count) {
-                               /* move on to the next adapter */
-                               index++;
-                               if (index >= HPI_MAX_ADAPTERS)
-                                       break;
-                               while (gRESP_HPI_SUBSYS_FIND_ADAPTERS.
-                                       s.aw_adapter_list[index] == 0) {
-                                       index++;
-                                       if (index >= HPI_MAX_ADAPTERS)
-                                               break;
-                               }
-                               count--;
-                       }
+               HPI_COMMON(phm, phr);
+               break;
 
-                       if (index < HPI_MAX_ADAPTERS) {
-                               phr->u.s.adapter_index = (u16)index;
-                               phr->u.s.aw_adapter_list[0] =
-                                       gRESP_HPI_SUBSYS_FIND_ADAPTERS.
-                                       s.aw_adapter_list[index];
-                       } else {
-                               phr->u.s.adapter_index = 0;
-                               phr->u.s.aw_adapter_list[0] = 0;
-                               phr->error = HPI_ERROR_BAD_ADAPTER_NUMBER;
-                       }
-                       break;
-               }
        case HPI_SUBSYS_CREATE_ADAPTER:
                HPIMSGX__init(phm, phr);
                break;
+
        case HPI_SUBSYS_DELETE_ADAPTER:
-               HPIMSGX__cleanup(phm->adapter_index, h_owner);
+               HPIMSGX__cleanup(phm->obj_index, h_owner);
                {
                        struct hpi_message hm;
                        struct hpi_response hr;
-                       /* call to HPI_ADAPTER_CLOSE */
                        hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
                                HPI_ADAPTER_CLOSE);
-                       hm.adapter_index = phm->adapter_index;
+                       hm.adapter_index = phm->obj_index;
                        hw_entry_point(&hm, &hr);
                }
-               hw_entry_point(phm, phr);
-               gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.
-                       aw_adapter_list[phm->adapter_index]
-                       = 0;
-               hpi_entry_points[phm->adapter_index] = NULL;
+               if ((phm->obj_index < HPI_MAX_ADAPTERS)
+                       && hpi_entry_points[phm->obj_index]) {
+                       hpi_entry_points[phm->obj_index] (phm, phr);
+                       hpi_entry_points[phm->obj_index] = NULL;
+               } else
+                       phr->error = HPI_ERROR_INVALID_OBJ_INDEX;
+
                break;
        default:
-               hw_entry_point(phm, phr);
+               /* Must explicitly send subsys messages to individual backends */
+               hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, phm->function,
+                       HPI_ERROR_INVALID_FUNC);
                break;
        }
 }
@@ -409,33 +359,7 @@ void hpi_send_recv_ex(struct hpi_message *phm, struct hpi_response *phr,
                break;
        }
        HPI_DEBUG_RESPONSE(phr);
-#if 1
-       if (phr->error >= HPI_ERROR_BACKEND_BASE) {
-               void *ep = NULL;
-               char *ep_name;
-
-               HPI_DEBUG_MESSAGE(ERROR, phm);
-
-               if (phm->adapter_index < HPI_MAX_ADAPTERS)
-                       ep = hpi_entry_points[phm->adapter_index];
-
-               /* Don't need this? Have adapter index in debug info
-                  Know at driver load time index->backend mapping */
-               if (ep == HPI_6000)
-                       ep_name = "HPI_6000";
-               else if (ep == HPI_6205)
-                       ep_name = "HPI_6205";
-               else
-                       ep_name = "unknown";
-
-               HPI_DEBUG_LOG(ERROR, "HPI %s response - error# %d\n", ep_name,
-                       phr->error);
-
-               if (hpi_debug_level >= HPI_DEBUG_LEVEL_VERBOSE)
-                       hpi_debug_data((u16 *)phm,
-                               sizeof(*phm) / sizeof(u16));
-       }
-#endif
+
 }
 
 static void adapter_open(struct hpi_message *phm, struct hpi_response *phr)
@@ -484,7 +408,7 @@ static void instream_open(struct hpi_message *phm, struct hpi_response *phr,
        else {
                instream_user_open[phm->adapter_index][phm->
                        obj_index].open_flag = 1;
-               hpios_msgxlock_un_lock(&msgx_lock);
+               hpios_msgxlock_unlock(&msgx_lock);
 
                /* issue a reset */
                hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
@@ -509,7 +433,7 @@ static void instream_open(struct hpi_message *phm, struct hpi_response *phr,
                                sizeof(rESP_HPI_ISTREAM_OPEN[0][0]));
                }
        }
-       hpios_msgxlock_un_lock(&msgx_lock);
+       hpios_msgxlock_unlock(&msgx_lock);
 }
 
 static void instream_close(struct hpi_message *phm, struct hpi_response *phr,
@@ -530,7 +454,7 @@ static void instream_close(struct hpi_message *phm, struct hpi_response *phr,
                   phm->wAdapterIndex, phm->wObjIndex, hOwner); */
                instream_user_open[phm->adapter_index][phm->
                        obj_index].h_owner = NULL;
-               hpios_msgxlock_un_lock(&msgx_lock);
+               hpios_msgxlock_unlock(&msgx_lock);
                /* issue a reset */
                hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
                        HPI_ISTREAM_RESET);
@@ -556,7 +480,7 @@ static void instream_close(struct hpi_message *phm, struct hpi_response *phr,
                                obj_index].h_owner);
                phr->error = HPI_ERROR_OBJ_NOT_OPEN;
        }
-       hpios_msgxlock_un_lock(&msgx_lock);
+       hpios_msgxlock_unlock(&msgx_lock);
 }
 
 static void outstream_open(struct hpi_message *phm, struct hpi_response *phr,
@@ -581,7 +505,7 @@ static void outstream_open(struct hpi_message *phm, struct hpi_response *phr,
        else {
                outstream_user_open[phm->adapter_index][phm->
                        obj_index].open_flag = 1;
-               hpios_msgxlock_un_lock(&msgx_lock);
+               hpios_msgxlock_unlock(&msgx_lock);
 
                /* issue a reset */
                hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
@@ -606,7 +530,7 @@ static void outstream_open(struct hpi_message *phm, struct hpi_response *phr,
                                sizeof(rESP_HPI_OSTREAM_OPEN[0][0]));
                }
        }
-       hpios_msgxlock_un_lock(&msgx_lock);
+       hpios_msgxlock_unlock(&msgx_lock);
 }
 
 static void outstream_close(struct hpi_message *phm, struct hpi_response *phr,
@@ -628,7 +552,7 @@ static void outstream_close(struct hpi_message *phm, struct hpi_response *phr,
                   phm->wAdapterIndex, phm->wObjIndex, hOwner); */
                outstream_user_open[phm->adapter_index][phm->
                        obj_index].h_owner = NULL;
-               hpios_msgxlock_un_lock(&msgx_lock);
+               hpios_msgxlock_unlock(&msgx_lock);
                /* issue a reset */
                hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
                        HPI_OSTREAM_RESET);
@@ -654,7 +578,7 @@ static void outstream_close(struct hpi_message *phm, struct hpi_response *phr,
                                obj_index].h_owner);
                phr->error = HPI_ERROR_OBJ_NOT_OPEN;
        }
-       hpios_msgxlock_un_lock(&msgx_lock);
+       hpios_msgxlock_unlock(&msgx_lock);
 }
 
 static u16 adapter_prepare(u16 adapter)
@@ -683,16 +607,9 @@ static u16 adapter_prepare(u16 adapter)
        if (hr.error)
                return hr.error;
 
-       aDAPTER_INFO[adapter].num_outstreams = hr.u.a.num_outstreams;
-       aDAPTER_INFO[adapter].num_instreams = hr.u.a.num_instreams;
-       aDAPTER_INFO[adapter].type = hr.u.a.adapter_type;
-
-       gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.aw_adapter_list[adapter] =
-               hr.u.a.adapter_type;
-       gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.num_adapters++;
-       if (gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.num_adapters > HPI_MAX_ADAPTERS)
-               gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.num_adapters =
-                       HPI_MAX_ADAPTERS;
+       aDAPTER_INFO[adapter].num_outstreams = hr.u.ax.info.num_outstreams;
+       aDAPTER_INFO[adapter].num_instreams = hr.u.ax.info.num_instreams;
+       aDAPTER_INFO[adapter].type = hr.u.ax.info.adapter_type;
 
        /* call to HPI_OSTREAM_OPEN */
        for (i = 0; i < aDAPTER_INFO[adapter].num_outstreams; i++) {
@@ -727,7 +644,7 @@ static u16 adapter_prepare(u16 adapter)
        memcpy(&rESP_HPI_MIXER_OPEN[adapter], &hr,
                sizeof(rESP_HPI_MIXER_OPEN[0]));
 
-       return gRESP_HPI_SUBSYS_FIND_ADAPTERS.h.error;
+       return 0;
 }
 
 static void HPIMSGX__reset(u16 adapter_index)
@@ -737,12 +654,6 @@ static void HPIMSGX__reset(u16 adapter_index)
        struct hpi_response hr;
 
        if (adapter_index == HPIMSGX_ALLADAPTERS) {
-               /* reset all responses to contain errors */
-               hpi_init_response(&hr, HPI_OBJ_SUBSYSTEM,
-                       HPI_SUBSYS_FIND_ADAPTERS, 0);
-               memcpy(&gRESP_HPI_SUBSYS_FIND_ADAPTERS, &hr,
-                       sizeof(gRESP_HPI_SUBSYS_FIND_ADAPTERS));
-
                for (adapter = 0; adapter < HPI_MAX_ADAPTERS; adapter++) {
 
                        hpi_init_response(&hr, HPI_OBJ_ADAPTER,
@@ -783,12 +694,6 @@ static void HPIMSGX__reset(u16 adapter_index)
                        rESP_HPI_ISTREAM_OPEN[adapter_index][i].h.error =
                                HPI_ERROR_INVALID_OBJ;
                }
-               if (gRESP_HPI_SUBSYS_FIND_ADAPTERS.
-                       s.aw_adapter_list[adapter_index]) {
-                       gRESP_HPI_SUBSYS_FIND_ADAPTERS.
-                               s.aw_adapter_list[adapter_index] = 0;
-                       gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.num_adapters--;
-               }
        }
 }
 
@@ -802,15 +707,9 @@ static u16 HPIMSGX__init(struct hpi_message *phm,
        hpi_handler_func *entry_point_func;
        struct hpi_response hr;
 
-       if (gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.num_adapters >= HPI_MAX_ADAPTERS)
-               return HPI_ERROR_BAD_ADAPTER_NUMBER;
-
        /* Init response here so we can pass in previous adapter list */
        hpi_init_response(&hr, phm->object, phm->function,
                HPI_ERROR_INVALID_OBJ);
-       memcpy(hr.u.s.aw_adapter_list,
-               gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.aw_adapter_list,
-               sizeof(gRESP_HPI_SUBSYS_FIND_ADAPTERS.s.aw_adapter_list));
 
        entry_point_func =
                hpi_lookup_entry_point_function(phm->u.s.resource.r.pci);
@@ -860,7 +759,7 @@ static void HPIMSGX__cleanup(u16 adapter_index, void *h_owner)
                                struct hpi_response hr;
 
                                HPI_DEBUG_LOG(DEBUG,
-                                       "close adapter %d ostream %d\n",
+                                       "Close adapter %d ostream %d\n",
                                        adapter, i);
 
                                hpi_init_message_response(&hm, &hr,
@@ -884,7 +783,7 @@ static void HPIMSGX__cleanup(u16 adapter_index, void *h_owner)
                                struct hpi_response hr;
 
                                HPI_DEBUG_LOG(DEBUG,
-                                       "close adapter %d istream %d\n",
+                                       "Close adapter %d istream %d\n",
                                        adapter, i);
 
                                hpi_init_message_response(&hm, &hr,
index 22dbd91811a4e61398a9b9077c5cbe26c0139119..dd8cadf1e68642fae81ccfd625be913c01e07715 100644 (file)
@@ -30,6 +30,7 @@ Common Linux HPI ioctl and module probe/remove functions
 #include <linux/slab.h>
 #include <linux/moduleparam.h>
 #include <asm/uaccess.h>
+#include <linux/pci.h>
 #include <linux/stringify.h>
 
 #ifdef MODULE_FIRMWARE
@@ -45,7 +46,7 @@ MODULE_FIRMWARE("asihpi/dsp8900.bin");
 static int prealloc_stream_buf;
 module_param(prealloc_stream_buf, int, S_IRUGO);
 MODULE_PARM_DESC(prealloc_stream_buf,
-       "preallocate size for per-adapter stream buffer");
+       "Preallocate size for per-adapter stream buffer");
 
 /* Allow the debug level to be changed after module load.
  E.g.   echo 2 > /sys/module/asihpi/parameters/hpiDebugLevel
@@ -121,8 +122,8 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        phpi_ioctl_data = (struct hpi_ioctl_linux __user *)arg;
 
        /* Read the message and response pointers from user space.  */
-       if (get_user(puhm, &phpi_ioctl_data->phm) ||
-           get_user(puhr, &phpi_ioctl_data->phr)) {
+       if (get_user(puhm, &phpi_ioctl_data->phm)
+               || get_user(puhr, &phpi_ioctl_data->phr)) {
                err = -EFAULT;
                goto out;
        }
@@ -135,7 +136,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        if (hm->h.size > sizeof(*hm))
                hm->h.size = sizeof(*hm);
 
-       /*printk(KERN_INFO "message size %d\n", hm->h.wSize); */
+       /* printk(KERN_INFO "message size %d\n", hm->h.wSize); */
 
        uncopied_bytes = copy_from_user(hm, puhm, hm->h.size);
        if (uncopied_bytes) {
@@ -156,7 +157,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        }
 
        pa = &adapters[hm->h.adapter_index];
-       hr->h.size = 0;
+       hr->h.size = res_max_size;
        if (hm->h.object == HPI_OBJ_SUBSYSTEM) {
                switch (hm->h.function) {
                case HPI_SUBSYS_CREATE_ADAPTER:
@@ -216,7 +217,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                                 */
                                if (pa->buffer_size < size) {
                                        HPI_DEBUG_LOG(DEBUG,
-                                               "realloc adapter %d stream "
+                                               "Realloc adapter %d stream "
                                                "buffer from %zd to %d\n",
                                                hm->h.adapter_index,
                                                pa->buffer_size, size);
@@ -259,7 +260,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                                copy_from_user(pa->p_buffer, ptr, size);
                        if (uncopied_bytes)
                                HPI_DEBUG_LOG(WARNING,
-                                       "missed %d of %d "
+                                       "Missed %d of %d "
                                        "bytes from user\n", uncopied_bytes,
                                        size);
                }
@@ -271,7 +272,7 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
                                copy_to_user(ptr, pa->p_buffer, size);
                        if (uncopied_bytes)
                                HPI_DEBUG_LOG(WARNING,
-                                       "missed %d of %d " "bytes to user\n",
+                                       "Missed %d of %d " "bytes to user\n",
                                        uncopied_bytes, size);
                }
 
@@ -290,9 +291,9 @@ long asihpi_hpi_ioctl(struct file *file, unsigned int cmd, unsigned long arg)
        if (hr->h.size > res_max_size) {
                HPI_DEBUG_LOG(ERROR, "response too big %d %d\n", hr->h.size,
                        res_max_size);
-               /*HPI_DEBUG_MESSAGE(ERROR, hm); */
-               err = -EFAULT;
-               goto out;
+               hr->h.error = HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL;
+               hr->h.specific_error = hr->h.size;
+               hr->h.size = sizeof(hr->h);
        }
 
        uncopied_bytes = copy_to_user(puhr, hr, hr->h.size);
@@ -320,18 +321,26 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
 
        memset(&adapter, 0, sizeof(adapter));
 
-       printk(KERN_DEBUG "probe PCI device (%04x:%04x,%04x:%04x,%04x)\n",
-               pci_dev->vendor, pci_dev->device, pci_dev->subsystem_vendor,
+       dev_printk(KERN_DEBUG, &pci_dev->dev,
+               "probe %04x:%04x,%04x:%04x,%04x\n", pci_dev->vendor,
+               pci_dev->device, pci_dev->subsystem_vendor,
                pci_dev->subsystem_device, pci_dev->devfn);
 
+       if (pci_enable_device(pci_dev) < 0) {
+               dev_printk(KERN_ERR, &pci_dev->dev,
+                       "pci_enable_device failed, disabling device\n");
+               return -EIO;
+       }
+
+       pci_set_master(pci_dev);        /* also sets latency timer if < 16 */
+
        hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
                HPI_SUBSYS_CREATE_ADAPTER);
        hpi_init_response(&hr, HPI_OBJ_SUBSYSTEM, HPI_SUBSYS_CREATE_ADAPTER,
                HPI_ERROR_PROCESSING_MESSAGE);
 
-       hm.adapter_index = -1;  /* an invalid index */
+       hm.adapter_index = HPI_ADAPTER_INDEX_INVALID;
 
-       /* fill in HPI_PCI information from kernel provided information */
        adapter.pci = pci_dev;
 
        nm = HPI_MAX_ADAPTER_MEM_SPACES;
@@ -359,19 +368,7 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
                pci.ap_mem_base[idx] = adapter.ap_remapped_mem_base[idx];
        }
 
-       /* could replace Pci with direct pointer to pci_dev for linux
-          Instead wrap accessor functions for IDs etc.
-          Would it work for windows?
-        */
-       pci.bus_number = pci_dev->bus->number;
-       pci.vendor_id = (u16)pci_dev->vendor;
-       pci.device_id = (u16)pci_dev->device;
-       pci.subsys_vendor_id = (u16)(pci_dev->subsystem_vendor & 0xffff);
-       pci.subsys_device_id = (u16)(pci_dev->subsystem_device & 0xffff);
-       pci.device_number = pci_dev->devfn;
-       pci.interrupt = pci_dev->irq;
-       pci.p_os_data = pci_dev;
-
+       pci.pci_dev = pci_dev;
        hm.u.s.resource.bus_type = HPI_BUS_PCI;
        hm.u.s.resource.r.pci = &pci;
 
@@ -407,8 +404,9 @@ int __devinit asihpi_adapter_probe(struct pci_dev *pci_dev,
        mutex_init(&adapters[adapter.index].mutex);
        pci_set_drvdata(pci_dev, &adapters[adapter.index]);
 
-       printk(KERN_INFO "probe found adapter ASI%04X HPI index #%d.\n",
-               adapter.type, adapter.index);
+       dev_printk(KERN_INFO, &pci_dev->dev,
+               "probe succeeded for ASI%04X HPI index %d\n", adapter.type,
+               adapter.index);
 
        return 0;
 
@@ -439,7 +437,8 @@ void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev)
 
        hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
                HPI_SUBSYS_DELETE_ADAPTER);
-       hm.adapter_index = pa->index;
+       hm.obj_index = pa->index;
+       hm.adapter_index = HPI_ADAPTER_INDEX_INVALID;
        hpi_send_recv_ex(&hm, &hr, HOWNER_KERNEL);
 
        /* unmap PCI memory space, mapped during device init. */
@@ -456,14 +455,12 @@ void __devexit asihpi_adapter_remove(struct pci_dev *pci_dev)
        }
 
        pci_set_drvdata(pci_dev, NULL);
-       /*
-          printk(KERN_INFO "PCI device (%04x:%04x,%04x:%04x,%04x),"
-          " HPI index # %d, removed.\n",
-          pci_dev->vendor, pci_dev->device,
-          pci_dev->subsystem_vendor,
-          pci_dev->subsystem_device, pci_dev->devfn,
-          pa->index);
-        */
+       if (1)
+               dev_printk(KERN_INFO, &pci_dev->dev,
+                       "remove %04x:%04x,%04x:%04x,%04x," " HPI index %d.\n",
+                       pci_dev->vendor, pci_dev->device,
+                       pci_dev->subsystem_vendor, pci_dev->subsystem_device,
+                       pci_dev->devfn, pa->index);
 }
 
 void __init asihpi_init(void)
index 370f39b43f853fb1ad9a50c117e391965df8007f..90879b15d3c629da3ae996a9fc84ea152cea689e 100644 (file)
@@ -135,7 +135,7 @@ static inline void cond_unlock(struct hpios_spinlock *l)
 
 #define hpios_msgxlock_init(obj)      spin_lock_init(&(obj)->lock)
 #define hpios_msgxlock_lock(obj)   cond_lock(obj)
-#define hpios_msgxlock_un_lock(obj) cond_unlock(obj)
+#define hpios_msgxlock_unlock(obj) cond_unlock(obj)
 
 #define hpios_dsplock_init(obj)       spin_lock_init(&(obj)->dsp_lock.lock)
 #define hpios_dsplock_lock(obj)    cond_lock(&(obj)->dsp_lock)
@@ -148,7 +148,7 @@ static inline void cond_unlock(struct hpios_spinlock *l)
 #define HPI_ALIST_LOCKING
 #define hpios_alistlock_init(obj)    spin_lock_init(&((obj)->list_lock.lock))
 #define hpios_alistlock_lock(obj) spin_lock(&((obj)->list_lock.lock))
-#define hpios_alistlock_un_lock(obj) spin_unlock(&((obj)->list_lock.lock))
+#define hpios_alistlock_unlock(obj) spin_unlock(&((obj)->list_lock.lock))
 
 struct hpi_adapter {
        /* mutex prevents contention for one card