Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 1 | /****************************************************************************** |
| 2 | |
| 3 | AudioScience HPI driver |
Eliot Blennerhassett | 51e6f47 | 2014-11-20 16:22:57 +1300 | [diff] [blame] | 4 | Copyright (C) 1997-2014 AudioScience Inc. <support@audioscience.com> |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 5 | |
| 6 | This program is free software; you can redistribute it and/or modify |
| 7 | it under the terms of version 2 of the GNU General Public License as |
| 8 | published by the Free Software Foundation; |
| 9 | |
| 10 | This program is distributed in the hope that it will be useful, |
| 11 | but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 13 | GNU General Public License for more details. |
| 14 | |
| 15 | You should have received a copy of the GNU General Public License |
| 16 | along with this program; if not, write to the Free Software |
| 17 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 18 | |
| 19 | Hardware Programming Interface (HPI) Utility functions. |
| 20 | |
| 21 | (C) Copyright AudioScience Inc. 2007 |
| 22 | *******************************************************************************/ |
| 23 | |
| 24 | #include "hpi_internal.h" |
| 25 | #include "hpimsginit.h" |
| 26 | |
| 27 | /* The actual message size for each object type */ |
| 28 | static u16 msg_size[HPI_OBJ_MAXINDEX + 1] = HPI_MESSAGE_SIZE_BY_OBJECT; |
| 29 | /* The actual response size for each object type */ |
| 30 | static u16 res_size[HPI_OBJ_MAXINDEX + 1] = HPI_RESPONSE_SIZE_BY_OBJECT; |
| 31 | /* Flag to enable alternate message type for SSX2 bypass. */ |
| 32 | static u16 gwSSX2_bypass; |
| 33 | |
| 34 | /** \internal |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 35 | * initialize the HPI message structure |
| 36 | */ |
| 37 | static void hpi_init_message(struct hpi_message *phm, u16 object, |
| 38 | u16 function) |
| 39 | { |
Eliot Blennerhassett | 51e6f47 | 2014-11-20 16:22:57 +1300 | [diff] [blame] | 40 | u16 size; |
| 41 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 42 | if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) |
Eliot Blennerhassett | 51e6f47 | 2014-11-20 16:22:57 +1300 | [diff] [blame] | 43 | size = msg_size[object]; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 44 | else |
Eliot Blennerhassett | 51e6f47 | 2014-11-20 16:22:57 +1300 | [diff] [blame] | 45 | size = sizeof(*phm); |
| 46 | |
| 47 | memset(phm, 0, size); |
| 48 | phm->size = size; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 49 | |
| 50 | if (gwSSX2_bypass) |
| 51 | phm->type = HPI_TYPE_SSX2BYPASS_MESSAGE; |
| 52 | else |
Eliot Blennerhassett | 82b5774 | 2011-07-22 15:52:36 +1200 | [diff] [blame] | 53 | phm->type = HPI_TYPE_REQUEST; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 54 | phm->object = object; |
| 55 | phm->function = function; |
| 56 | phm->version = 0; |
Eliot Blennerhassett | 3285ea1 | 2011-02-10 17:25:58 +1300 | [diff] [blame] | 57 | phm->adapter_index = HPI_ADAPTER_INDEX_INVALID; |
Eliot Blennerhassett | 0a1602c | 2011-02-10 17:25:55 +1300 | [diff] [blame] | 58 | /* Expect actual adapter index to be set by caller */ |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 59 | } |
| 60 | |
| 61 | /** \internal |
| 62 | * initialize the HPI response structure |
| 63 | */ |
| 64 | void hpi_init_response(struct hpi_response *phr, u16 object, u16 function, |
| 65 | u16 error) |
| 66 | { |
Eliot Blennerhassett | 51e6f47 | 2014-11-20 16:22:57 +1300 | [diff] [blame] | 67 | u16 size; |
| 68 | |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 69 | if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) |
Eliot Blennerhassett | 51e6f47 | 2014-11-20 16:22:57 +1300 | [diff] [blame] | 70 | size = res_size[object]; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 71 | else |
Eliot Blennerhassett | 51e6f47 | 2014-11-20 16:22:57 +1300 | [diff] [blame] | 72 | size = sizeof(*phr); |
| 73 | |
| 74 | memset(phr, 0, sizeof(*phr)); |
| 75 | phr->size = size; |
| 76 | phr->type = HPI_TYPE_RESPONSE; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 77 | phr->object = object; |
| 78 | phr->function = function; |
| 79 | phr->error = error; |
| 80 | phr->specific_error = 0; |
| 81 | phr->version = 0; |
| 82 | } |
| 83 | |
| 84 | void hpi_init_message_response(struct hpi_message *phm, |
| 85 | struct hpi_response *phr, u16 object, u16 function) |
| 86 | { |
| 87 | hpi_init_message(phm, object, function); |
| 88 | /* default error return if the response is |
| 89 | not filled in by the callee */ |
| 90 | hpi_init_response(phr, object, function, |
| 91 | HPI_ERROR_PROCESSING_MESSAGE); |
| 92 | } |
| 93 | |
| 94 | static void hpi_init_messageV1(struct hpi_message_header *phm, u16 size, |
| 95 | u16 object, u16 function) |
| 96 | { |
Eliot Blennerhassett | 51e6f47 | 2014-11-20 16:22:57 +1300 | [diff] [blame] | 97 | memset(phm, 0, size); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 98 | if ((object > 0) && (object <= HPI_OBJ_MAXINDEX)) { |
| 99 | phm->size = size; |
Eliot Blennerhassett | 82b5774 | 2011-07-22 15:52:36 +1200 | [diff] [blame] | 100 | phm->type = HPI_TYPE_REQUEST; |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 101 | phm->object = object; |
| 102 | phm->function = function; |
| 103 | phm->version = 1; |
| 104 | /* Expect adapter index to be set by caller */ |
| 105 | } |
| 106 | } |
| 107 | |
| 108 | void hpi_init_responseV1(struct hpi_response_header *phr, u16 size, |
| 109 | u16 object, u16 function) |
| 110 | { |
Eliot Blennerhassett | 51e6f47 | 2014-11-20 16:22:57 +1300 | [diff] [blame] | 111 | (void)object; |
| 112 | (void)function; |
| 113 | memset(phr, 0, size); |
Eliot Blennerhassett | 719f82d | 2010-04-21 18:17:39 +0200 | [diff] [blame] | 114 | phr->size = size; |
| 115 | phr->version = 1; |
| 116 | phr->type = HPI_TYPE_RESPONSE; |
| 117 | phr->error = HPI_ERROR_PROCESSING_MESSAGE; |
| 118 | } |
| 119 | |
| 120 | void hpi_init_message_responseV1(struct hpi_message_header *phm, u16 msg_size, |
| 121 | struct hpi_response_header *phr, u16 res_size, u16 object, |
| 122 | u16 function) |
| 123 | { |
| 124 | hpi_init_messageV1(phm, msg_size, object, function); |
| 125 | hpi_init_responseV1(phr, res_size, object, function); |
| 126 | } |