Back to home page

OSCL-LXR

 
 

    


0001 // SPDX-License-Identifier: GPL-2.0-only
0002 /******************************************************************************
0003 
0004     AudioScience HPI driver
0005     Copyright (C) 1997-2014  AudioScience Inc. <support@audioscience.com>
0006 
0007 
0008  Hardware Programming Interface (HPI) Utility functions.
0009 
0010  (C) Copyright AudioScience Inc. 2007
0011 *******************************************************************************/
0012 
0013 #include "hpi_internal.h"
0014 #include "hpimsginit.h"
0015 #include <linux/nospec.h>
0016 
0017 /* The actual message size for each object type */
0018 static u16 msg_size[HPI_OBJ_MAXINDEX + 1] = HPI_MESSAGE_SIZE_BY_OBJECT;
0019 /* The actual response size for each object type */
0020 static u16 res_size[HPI_OBJ_MAXINDEX + 1] = HPI_RESPONSE_SIZE_BY_OBJECT;
0021 /* Flag to enable alternate message type for SSX2 bypass. */
0022 static u16 gwSSX2_bypass;
0023 
0024 /** \internal
0025   * initialize the HPI message structure
0026   */
0027 static void hpi_init_message(struct hpi_message *phm, u16 object,
0028     u16 function)
0029 {
0030     u16 size;
0031 
0032     if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
0033         object = array_index_nospec(object, HPI_OBJ_MAXINDEX + 1);
0034         size = msg_size[object];
0035     } else {
0036         size = sizeof(*phm);
0037     }
0038 
0039     memset(phm, 0, size);
0040     phm->size = size;
0041 
0042     if (gwSSX2_bypass)
0043         phm->type = HPI_TYPE_SSX2BYPASS_MESSAGE;
0044     else
0045         phm->type = HPI_TYPE_REQUEST;
0046     phm->object = object;
0047     phm->function = function;
0048     phm->version = 0;
0049     phm->adapter_index = HPI_ADAPTER_INDEX_INVALID;
0050     /* Expect actual adapter index to be set by caller */
0051 }
0052 
0053 /** \internal
0054   * initialize the HPI response structure
0055   */
0056 void hpi_init_response(struct hpi_response *phr, u16 object, u16 function,
0057     u16 error)
0058 {
0059     u16 size;
0060 
0061     if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
0062         object = array_index_nospec(object, HPI_OBJ_MAXINDEX + 1);
0063         size = res_size[object];
0064     } else {
0065         size = sizeof(*phr);
0066     }
0067 
0068     memset(phr, 0, sizeof(*phr));
0069     phr->size = size;
0070     phr->type = HPI_TYPE_RESPONSE;
0071     phr->object = object;
0072     phr->function = function;
0073     phr->error = error;
0074     phr->specific_error = 0;
0075     phr->version = 0;
0076 }
0077 
0078 void hpi_init_message_response(struct hpi_message *phm,
0079     struct hpi_response *phr, u16 object, u16 function)
0080 {
0081     hpi_init_message(phm, object, function);
0082     /* default error return if the response is
0083        not filled in by the callee */
0084     hpi_init_response(phr, object, function,
0085         HPI_ERROR_PROCESSING_MESSAGE);
0086 }
0087 
0088 static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size,
0089     u16 object, u16 function)
0090 {
0091     memset(phm, 0, size);
0092     if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) {
0093         phm->size = size;
0094         phm->type = HPI_TYPE_REQUEST;
0095         phm->object = object;
0096         phm->function = function;
0097         phm->version = 1;
0098         /* Expect adapter index to be set by caller */
0099     }
0100 }
0101 
0102 void hpi_init_responseV1(struct hpi_response_header *phr, u16 size,
0103     u16 object, u16 function)
0104 {
0105     (void)object;
0106     (void)function;
0107     memset(phr, 0, size);
0108     phr->size = size;
0109     phr->version = 1;
0110     phr->type = HPI_TYPE_RESPONSE;
0111     phr->error = HPI_ERROR_PROCESSING_MESSAGE;
0112 }
0113 
0114 void hpi_init_message_responseV1(struct hpi_message_header *phm, u16 msg_size,
0115     struct hpi_response_header *phr, u16 res_size, u16 object,
0116     u16 function)
0117 {
0118     hpi_init_messageV1(phm, msg_size, object, function);
0119     hpi_init_responseV1(phr, res_size, object, function);
0120 }