xref: /openbmc/linux/sound/pci/asihpi/hpi_internal.h (revision 95e9fd10)
1 /******************************************************************************
2 
3     AudioScience HPI driver
4     Copyright (C) 1997-2012  AudioScience Inc. <support@audioscience.com>
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 HPI internal definitions
20 
21 (C) Copyright AudioScience Inc. 1996-2009
22 ******************************************************************************/
23 
24 #ifndef _HPI_INTERNAL_H_
25 #define _HPI_INTERNAL_H_
26 
27 #include "hpi.h"
28 
29 /** maximum number of memory regions mapped to an adapter */
30 #define HPI_MAX_ADAPTER_MEM_SPACES (2)
31 
32 /* Each OS needs its own hpios.h */
33 #include "hpios.h"
34 
35 /* physical memory allocation */
36 
37 /** Allocate and map an area of locked memory for bus master DMA operations.
38 
39 On success, *pLockedMemeHandle is a valid handle, and 0 is returned
40 On error *pLockedMemHandle marked invalid, non-zero returned.
41 
42 If this function succeeds, then HpiOs_LockedMem_GetVirtAddr() and
43 HpiOs_LockedMem_GetPyhsAddr() will always succed on the returned handle.
44 */
45 u16 hpios_locked_mem_alloc(struct consistent_dma_area *p_locked_mem_handle,
46 							   /**< memory handle */
47 	u32 size, /**< Size in bytes to allocate */
48 	struct pci_dev *p_os_reference
49 	/**< OS specific data required for memory allocation */
50 	);
51 
52 /** Free mapping and memory represented by LockedMemHandle
53 
54 Frees any resources, then invalidates the handle.
55 Returns 0 on success, 1 if handle is invalid.
56 
57 */
58 u16 hpios_locked_mem_free(struct consistent_dma_area *locked_mem_handle);
59 
60 /** Get the physical PCI address of memory represented by LockedMemHandle.
61 
62 If handle is invalid *pPhysicalAddr is set to zero and return 1
63 */
64 u16 hpios_locked_mem_get_phys_addr(struct consistent_dma_area
65 	*locked_mem_handle, u32 *p_physical_addr);
66 
67 /** Get the CPU address of of memory represented by LockedMemHandle.
68 
69 If handle is NULL *ppvVirtualAddr is set to NULL and return 1
70 */
71 u16 hpios_locked_mem_get_virt_addr(struct consistent_dma_area
72 	*locked_mem_handle, void **ppv_virtual_addr);
73 
74 /** Check that handle is valid
75 i.e it represents a valid memory area
76 */
77 u16 hpios_locked_mem_valid(struct consistent_dma_area *locked_mem_handle);
78 
79 /* timing/delay */
80 void hpios_delay_micro_seconds(u32 num_micro_sec);
81 
82 struct hpi_message;
83 struct hpi_response;
84 
85 typedef void hpi_handler_func(struct hpi_message *, struct hpi_response *);
86 
87 /* If the assert fails, compiler complains
88    something like size of array `msg' is negative.
89    Unlike linux BUILD_BUG_ON, this works outside function scope.
90 */
91 #define compile_time_assert(cond, msg) \
92     typedef char ASSERT_##msg[(cond) ? 1 : -1]
93 
94 /******************************************* bus types */
95 enum HPI_BUSES {
96 	HPI_BUS_ISAPNP = 1,
97 	HPI_BUS_PCI = 2,
98 	HPI_BUS_USB = 3,
99 	HPI_BUS_NET = 4
100 };
101 
102 enum HPI_SUBSYS_OPTIONS {
103 	/* 0, 256 are invalid, 1..255 reserved for global options */
104 	HPI_SUBSYS_OPT_NET_ENABLE = 257,
105 	HPI_SUBSYS_OPT_NET_BROADCAST = 258,
106 	HPI_SUBSYS_OPT_NET_UNICAST = 259,
107 	HPI_SUBSYS_OPT_NET_ADDR = 260,
108 	HPI_SUBSYS_OPT_NET_MASK = 261,
109 	HPI_SUBSYS_OPT_NET_ADAPTER_ADDRESS_ADD = 262
110 };
111 
112 /** Volume flags
113 */
114 enum HPI_VOLUME_FLAGS {
115 	/** Set if the volume control is muted */
116 	HPI_VOLUME_FLAG_MUTED = (1 << 0),
117 	/** Set if the volume control has a mute function */
118 	HPI_VOLUME_FLAG_HAS_MUTE = (1 << 1),
119 	/** Set if volume control can do autofading */
120 	HPI_VOLUME_FLAG_HAS_AUTOFADE = (1 << 2)
121 		/* Note Flags >= (1<<8) are for DSP internal use only */
122 };
123 
124 /******************************************* CONTROL ATTRIBUTES ****/
125 /* (in order of control type ID */
126 
127 /* This allows for 255 control types, 256 unique attributes each */
128 #define HPI_CTL_ATTR(ctl, ai) ((HPI_CONTROL_##ctl << 8) + ai)
129 
130 /* Get the sub-index of the attribute for a control type */
131 #define HPI_CTL_ATTR_INDEX(i) (i & 0xff)
132 
133 /* Extract the control from the control attribute */
134 #define HPI_CTL_ATTR_CONTROL(i) (i >> 8)
135 
136 /** Enable event generation for a control.
137 0=disable, 1=enable
138 \note generic to all controls that can generate events
139 */
140 
141 /** Unique identifiers for every control attribute
142 */
143 enum HPI_CONTROL_ATTRIBUTES {
144 	HPI_GENERIC_ENABLE = HPI_CTL_ATTR(GENERIC, 1),
145 	HPI_GENERIC_EVENT_ENABLE = HPI_CTL_ATTR(GENERIC, 2),
146 
147 	HPI_VOLUME_GAIN = HPI_CTL_ATTR(VOLUME, 1),
148 	HPI_VOLUME_AUTOFADE = HPI_CTL_ATTR(VOLUME, 2),
149 	HPI_VOLUME_MUTE = HPI_CTL_ATTR(VOLUME, 3),
150 	HPI_VOLUME_GAIN_AND_FLAGS = HPI_CTL_ATTR(VOLUME, 4),
151 	HPI_VOLUME_NUM_CHANNELS = HPI_CTL_ATTR(VOLUME, 6),
152 	HPI_VOLUME_RANGE = HPI_CTL_ATTR(VOLUME, 10),
153 
154 	HPI_METER_RMS = HPI_CTL_ATTR(METER, 1),
155 	HPI_METER_PEAK = HPI_CTL_ATTR(METER, 2),
156 	HPI_METER_RMS_BALLISTICS = HPI_CTL_ATTR(METER, 3),
157 	HPI_METER_PEAK_BALLISTICS = HPI_CTL_ATTR(METER, 4),
158 	HPI_METER_NUM_CHANNELS = HPI_CTL_ATTR(METER, 5),
159 
160 	HPI_MULTIPLEXER_SOURCE = HPI_CTL_ATTR(MULTIPLEXER, 1),
161 	HPI_MULTIPLEXER_QUERYSOURCE = HPI_CTL_ATTR(MULTIPLEXER, 2),
162 
163 	HPI_AESEBUTX_FORMAT = HPI_CTL_ATTR(AESEBUTX, 1),
164 	HPI_AESEBUTX_SAMPLERATE = HPI_CTL_ATTR(AESEBUTX, 3),
165 	HPI_AESEBUTX_CHANNELSTATUS = HPI_CTL_ATTR(AESEBUTX, 4),
166 	HPI_AESEBUTX_USERDATA = HPI_CTL_ATTR(AESEBUTX, 5),
167 
168 	HPI_AESEBURX_FORMAT = HPI_CTL_ATTR(AESEBURX, 1),
169 	HPI_AESEBURX_ERRORSTATUS = HPI_CTL_ATTR(AESEBURX, 2),
170 	HPI_AESEBURX_SAMPLERATE = HPI_CTL_ATTR(AESEBURX, 3),
171 	HPI_AESEBURX_CHANNELSTATUS = HPI_CTL_ATTR(AESEBURX, 4),
172 	HPI_AESEBURX_USERDATA = HPI_CTL_ATTR(AESEBURX, 5),
173 
174 	HPI_LEVEL_GAIN = HPI_CTL_ATTR(LEVEL, 1),
175 	HPI_LEVEL_RANGE = HPI_CTL_ATTR(LEVEL, 10),
176 
177 	HPI_TUNER_BAND = HPI_CTL_ATTR(TUNER, 1),
178 	HPI_TUNER_FREQ = HPI_CTL_ATTR(TUNER, 2),
179 	HPI_TUNER_LEVEL_AVG = HPI_CTL_ATTR(TUNER, 3),
180 	HPI_TUNER_LEVEL_RAW = HPI_CTL_ATTR(TUNER, 4),
181 	HPI_TUNER_SNR = HPI_CTL_ATTR(TUNER, 5),
182 	HPI_TUNER_GAIN = HPI_CTL_ATTR(TUNER, 6),
183 	HPI_TUNER_STATUS = HPI_CTL_ATTR(TUNER, 7),
184 	HPI_TUNER_MODE = HPI_CTL_ATTR(TUNER, 8),
185 	HPI_TUNER_RDS = HPI_CTL_ATTR(TUNER, 9),
186 	HPI_TUNER_DEEMPHASIS = HPI_CTL_ATTR(TUNER, 10),
187 	HPI_TUNER_PROGRAM = HPI_CTL_ATTR(TUNER, 11),
188 	HPI_TUNER_HDRADIO_SIGNAL_QUALITY = HPI_CTL_ATTR(TUNER, 12),
189 	HPI_TUNER_HDRADIO_SDK_VERSION = HPI_CTL_ATTR(TUNER, 13),
190 	HPI_TUNER_HDRADIO_DSP_VERSION = HPI_CTL_ATTR(TUNER, 14),
191 	HPI_TUNER_HDRADIO_BLEND = HPI_CTL_ATTR(TUNER, 15),
192 
193 	HPI_VOX_THRESHOLD = HPI_CTL_ATTR(VOX, 1),
194 
195 	HPI_CHANNEL_MODE_MODE = HPI_CTL_ATTR(CHANNEL_MODE, 1),
196 
197 	HPI_BITSTREAM_DATA_POLARITY = HPI_CTL_ATTR(BITSTREAM, 1),
198 	HPI_BITSTREAM_CLOCK_EDGE = HPI_CTL_ATTR(BITSTREAM, 2),
199 	HPI_BITSTREAM_CLOCK_SOURCE = HPI_CTL_ATTR(BITSTREAM, 3),
200 	HPI_BITSTREAM_ACTIVITY = HPI_CTL_ATTR(BITSTREAM, 4),
201 
202 	HPI_SAMPLECLOCK_SOURCE = HPI_CTL_ATTR(SAMPLECLOCK, 1),
203 	HPI_SAMPLECLOCK_SAMPLERATE = HPI_CTL_ATTR(SAMPLECLOCK, 2),
204 	HPI_SAMPLECLOCK_SOURCE_INDEX = HPI_CTL_ATTR(SAMPLECLOCK, 3),
205 	HPI_SAMPLECLOCK_LOCAL_SAMPLERATE = HPI_CTL_ATTR(SAMPLECLOCK, 4),
206 	HPI_SAMPLECLOCK_AUTO = HPI_CTL_ATTR(SAMPLECLOCK, 5),
207 	HPI_SAMPLECLOCK_LOCAL_LOCK = HPI_CTL_ATTR(SAMPLECLOCK, 6),
208 
209 	HPI_MICROPHONE_PHANTOM_POWER = HPI_CTL_ATTR(MICROPHONE, 1),
210 
211 	HPI_EQUALIZER_NUM_FILTERS = HPI_CTL_ATTR(EQUALIZER, 1),
212 	HPI_EQUALIZER_FILTER = HPI_CTL_ATTR(EQUALIZER, 2),
213 	HPI_EQUALIZER_COEFFICIENTS = HPI_CTL_ATTR(EQUALIZER, 3),
214 
215 	HPI_COMPANDER_PARAMS = HPI_CTL_ATTR(COMPANDER, 1),
216 	HPI_COMPANDER_MAKEUPGAIN = HPI_CTL_ATTR(COMPANDER, 2),
217 	HPI_COMPANDER_THRESHOLD = HPI_CTL_ATTR(COMPANDER, 3),
218 	HPI_COMPANDER_RATIO = HPI_CTL_ATTR(COMPANDER, 4),
219 	HPI_COMPANDER_ATTACK = HPI_CTL_ATTR(COMPANDER, 5),
220 	HPI_COMPANDER_DECAY = HPI_CTL_ATTR(COMPANDER, 6),
221 
222 	HPI_COBRANET_SET = HPI_CTL_ATTR(COBRANET, 1),
223 	HPI_COBRANET_GET = HPI_CTL_ATTR(COBRANET, 2),
224 	HPI_COBRANET_GET_STATUS = HPI_CTL_ATTR(COBRANET, 5),
225 	HPI_COBRANET_SEND_PACKET = HPI_CTL_ATTR(COBRANET, 6),
226 	HPI_COBRANET_GET_PACKET = HPI_CTL_ATTR(COBRANET, 7),
227 
228 	HPI_TONEDETECTOR_THRESHOLD = HPI_CTL_ATTR(TONEDETECTOR, 1),
229 	HPI_TONEDETECTOR_STATE = HPI_CTL_ATTR(TONEDETECTOR, 2),
230 	HPI_TONEDETECTOR_FREQUENCY = HPI_CTL_ATTR(TONEDETECTOR, 3),
231 
232 	HPI_SILENCEDETECTOR_THRESHOLD = HPI_CTL_ATTR(SILENCEDETECTOR, 1),
233 	HPI_SILENCEDETECTOR_STATE = HPI_CTL_ATTR(SILENCEDETECTOR, 2),
234 	HPI_SILENCEDETECTOR_DELAY = HPI_CTL_ATTR(SILENCEDETECTOR, 3),
235 
236 	HPI_PAD_CHANNEL_NAME = HPI_CTL_ATTR(PAD, 1),
237 	HPI_PAD_ARTIST = HPI_CTL_ATTR(PAD, 2),
238 	HPI_PAD_TITLE = HPI_CTL_ATTR(PAD, 3),
239 	HPI_PAD_COMMENT = HPI_CTL_ATTR(PAD, 4),
240 	HPI_PAD_PROGRAM_TYPE = HPI_CTL_ATTR(PAD, 5),
241 	HPI_PAD_PROGRAM_ID = HPI_CTL_ATTR(PAD, 6),
242 	HPI_PAD_TA_SUPPORT = HPI_CTL_ATTR(PAD, 7),
243 	HPI_PAD_TA_ACTIVE = HPI_CTL_ATTR(PAD, 8),
244 
245 	HPI_UNIVERSAL_ENTITY = HPI_CTL_ATTR(UNIVERSAL, 1)
246 };
247 
248 #define HPI_POLARITY_POSITIVE           0
249 #define HPI_POLARITY_NEGATIVE           1
250 
251 /*------------------------------------------------------------
252  Cobranet Chip Bridge - copied from HMI.H
253 ------------------------------------------------------------*/
254 #define  HPI_COBRANET_HMI_cobra_bridge           0x20000
255 #define  HPI_COBRANET_HMI_cobra_bridge_tx_pkt_buf \
256 	(HPI_COBRANET_HMI_cobra_bridge + 0x1000)
257 #define  HPI_COBRANET_HMI_cobra_bridge_rx_pkt_buf \
258 	(HPI_COBRANET_HMI_cobra_bridge + 0x2000)
259 #define  HPI_COBRANET_HMI_cobra_if_table1         0x110000
260 #define  HPI_COBRANET_HMI_cobra_if_phy_address \
261 	(HPI_COBRANET_HMI_cobra_if_table1 + 0xd)
262 #define  HPI_COBRANET_HMI_cobra_protocolIP       0x72000
263 #define  HPI_COBRANET_HMI_cobra_ip_mon_currentIP \
264 	(HPI_COBRANET_HMI_cobra_protocolIP + 0x0)
265 #define  HPI_COBRANET_HMI_cobra_ip_mon_staticIP \
266 	(HPI_COBRANET_HMI_cobra_protocolIP + 0x2)
267 #define  HPI_COBRANET_HMI_cobra_sys              0x100000
268 #define  HPI_COBRANET_HMI_cobra_sys_desc \
269 		(HPI_COBRANET_HMI_cobra_sys + 0x0)
270 #define  HPI_COBRANET_HMI_cobra_sys_objectID \
271 	(HPI_COBRANET_HMI_cobra_sys + 0x100)
272 #define  HPI_COBRANET_HMI_cobra_sys_contact \
273 	(HPI_COBRANET_HMI_cobra_sys + 0x200)
274 #define  HPI_COBRANET_HMI_cobra_sys_name \
275 		(HPI_COBRANET_HMI_cobra_sys + 0x300)
276 #define  HPI_COBRANET_HMI_cobra_sys_location \
277 	(HPI_COBRANET_HMI_cobra_sys + 0x400)
278 
279 /*------------------------------------------------------------
280  Cobranet Chip Status bits
281 ------------------------------------------------------------*/
282 #define HPI_COBRANET_HMI_STATUS_RXPACKET 2
283 #define HPI_COBRANET_HMI_STATUS_TXPACKET 3
284 
285 /*------------------------------------------------------------
286  Ethernet header size
287 ------------------------------------------------------------*/
288 #define HPI_ETHERNET_HEADER_SIZE (16)
289 
290 /* These defines are used to fill in protocol information for an Ethernet packet
291     sent using HMI on CS18102 */
292 /** ID supplied by Cirrus for ASI packets. */
293 #define HPI_ETHERNET_PACKET_ID                  0x85
294 /** Simple packet - no special routing required */
295 #define HPI_ETHERNET_PACKET_V1                  0x01
296 /** This packet must make its way to the host across the HPI interface */
297 #define HPI_ETHERNET_PACKET_HOSTED_VIA_HMI      0x20
298 /** This packet must make its way to the host across the HPI interface */
299 #define HPI_ETHERNET_PACKET_HOSTED_VIA_HMI_V1   0x21
300 /** This packet must make its way to the host across the HPI interface */
301 #define HPI_ETHERNET_PACKET_HOSTED_VIA_HPI      0x40
302 /** This packet must make its way to the host across the HPI interface */
303 #define HPI_ETHERNET_PACKET_HOSTED_VIA_HPI_V1   0x41
304 
305 #define HPI_ETHERNET_UDP_PORT 44600 /**< HPI UDP service */
306 
307 /** Default network timeout in milli-seconds. */
308 #define HPI_ETHERNET_TIMEOUT_MS 500
309 
310 /** Locked memory buffer alloc/free phases */
311 enum HPI_BUFFER_CMDS {
312 	/** use one message to allocate or free physical memory */
313 	HPI_BUFFER_CMD_EXTERNAL = 0,
314 	/** alloc physical memory */
315 	HPI_BUFFER_CMD_INTERNAL_ALLOC = 1,
316 	/** send physical memory address to adapter */
317 	HPI_BUFFER_CMD_INTERNAL_GRANTADAPTER = 2,
318 	/** notify adapter to stop using physical buffer */
319 	HPI_BUFFER_CMD_INTERNAL_REVOKEADAPTER = 3,
320 	/** free physical buffer */
321 	HPI_BUFFER_CMD_INTERNAL_FREE = 4
322 };
323 
324 /*****************************************************************************/
325 /*****************************************************************************/
326 /********               HPI LOW LEVEL MESSAGES                  *******/
327 /*****************************************************************************/
328 /*****************************************************************************/
329 /** Pnp ids */
330 /** "ASI"  - actual is "ASX" - need to change */
331 #define HPI_ID_ISAPNP_AUDIOSCIENCE      0x0669
332 /** PCI vendor ID that AudioScience uses */
333 #define HPI_PCI_VENDOR_ID_AUDIOSCIENCE  0x175C
334 /** PCI vendor ID that the DSP56301 has */
335 #define HPI_PCI_VENDOR_ID_MOTOROLA      0x1057
336 /** PCI vendor ID that TI uses */
337 #define HPI_PCI_VENDOR_ID_TI            0x104C
338 
339 #define HPI_PCI_DEV_ID_PCI2040          0xAC60
340 /** TI's C6205 PCI interface has this ID */
341 #define HPI_PCI_DEV_ID_DSP6205          0xA106
342 
343 #define HPI_USB_VENDOR_ID_AUDIOSCIENCE  0x1257
344 #define HPI_USB_W2K_TAG                 0x57495341	/* "ASIW"       */
345 #define HPI_USB_LINUX_TAG               0x4C495341	/* "ASIL"       */
346 
347 /** Invalid Adapter index
348 Used in HPI messages that are not addressed to a specific adapter
349 Used in DLL to indicate device not present
350 */
351 #define HPI_ADAPTER_INDEX_INVALID 0xFFFF
352 
353 /** First 2 hex digits define the adapter family */
354 #define HPI_ADAPTER_FAMILY_MASK         0xff00
355 #define HPI_MODULE_FAMILY_MASK          0xfff0
356 
357 #define HPI_ADAPTER_FAMILY_ASI(f)   (f & HPI_ADAPTER_FAMILY_MASK)
358 #define HPI_MODULE_FAMILY_ASI(f)   (f & HPI_MODULE_FAMILY_MASK)
359 #define HPI_ADAPTER_ASI(f)   (f)
360 
361 enum HPI_MESSAGE_TYPES {
362 	HPI_TYPE_REQUEST = 1,
363 	HPI_TYPE_RESPONSE = 2,
364 	HPI_TYPE_DATA = 3,
365 	HPI_TYPE_SSX2BYPASS_MESSAGE = 4,
366 	HPI_TYPE_COMMAND = 5,
367 	HPI_TYPE_NOTIFICATION = 6
368 };
369 
370 enum HPI_OBJECT_TYPES {
371 	HPI_OBJ_SUBSYSTEM = 1,
372 	HPI_OBJ_ADAPTER = 2,
373 	HPI_OBJ_OSTREAM = 3,
374 	HPI_OBJ_ISTREAM = 4,
375 	HPI_OBJ_MIXER = 5,
376 	HPI_OBJ_NODE = 6,
377 	HPI_OBJ_CONTROL = 7,
378 	HPI_OBJ_NVMEMORY = 8,
379 	HPI_OBJ_GPIO = 9,
380 	HPI_OBJ_WATCHDOG = 10,
381 	HPI_OBJ_CLOCK = 11,
382 	HPI_OBJ_PROFILE = 12,
383 	/* HPI_ OBJ_ CONTROLEX  = 13, */
384 	HPI_OBJ_ASYNCEVENT = 14
385 #define HPI_OBJ_MAXINDEX 14
386 };
387 
388 #define HPI_OBJ_FUNCTION_SPACING 0x100
389 #define HPI_FUNC_ID(obj, i) (HPI_OBJ_##obj * HPI_OBJ_FUNCTION_SPACING + i)
390 
391 #define HPI_EXTRACT_INDEX(fn) (fn & 0xff)
392 
393 enum HPI_FUNCTION_IDS {
394 	HPI_SUBSYS_OPEN = HPI_FUNC_ID(SUBSYSTEM, 1),
395 	HPI_SUBSYS_GET_VERSION = HPI_FUNC_ID(SUBSYSTEM, 2),
396 	HPI_SUBSYS_GET_INFO = HPI_FUNC_ID(SUBSYSTEM, 3),
397 	HPI_SUBSYS_CREATE_ADAPTER = HPI_FUNC_ID(SUBSYSTEM, 5),
398 	HPI_SUBSYS_CLOSE = HPI_FUNC_ID(SUBSYSTEM, 6),
399 	HPI_SUBSYS_DRIVER_LOAD = HPI_FUNC_ID(SUBSYSTEM, 8),
400 	HPI_SUBSYS_DRIVER_UNLOAD = HPI_FUNC_ID(SUBSYSTEM, 9),
401 	HPI_SUBSYS_GET_NUM_ADAPTERS = HPI_FUNC_ID(SUBSYSTEM, 12),
402 	HPI_SUBSYS_GET_ADAPTER = HPI_FUNC_ID(SUBSYSTEM, 13),
403 	HPI_SUBSYS_SET_NETWORK_INTERFACE = HPI_FUNC_ID(SUBSYSTEM, 14),
404 	HPI_SUBSYS_OPTION_INFO = HPI_FUNC_ID(SUBSYSTEM, 15),
405 	HPI_SUBSYS_OPTION_GET = HPI_FUNC_ID(SUBSYSTEM, 16),
406 	HPI_SUBSYS_OPTION_SET = HPI_FUNC_ID(SUBSYSTEM, 17),
407 #define HPI_SUBSYS_FUNCTION_COUNT 17
408 
409 	HPI_ADAPTER_OPEN = HPI_FUNC_ID(ADAPTER, 1),
410 	HPI_ADAPTER_CLOSE = HPI_FUNC_ID(ADAPTER, 2),
411 	HPI_ADAPTER_GET_INFO = HPI_FUNC_ID(ADAPTER, 3),
412 	HPI_ADAPTER_GET_ASSERT = HPI_FUNC_ID(ADAPTER, 4),
413 	HPI_ADAPTER_TEST_ASSERT = HPI_FUNC_ID(ADAPTER, 5),
414 	HPI_ADAPTER_SET_MODE = HPI_FUNC_ID(ADAPTER, 6),
415 	HPI_ADAPTER_GET_MODE = HPI_FUNC_ID(ADAPTER, 7),
416 	HPI_ADAPTER_ENABLE_CAPABILITY = HPI_FUNC_ID(ADAPTER, 8),
417 	HPI_ADAPTER_SELFTEST = HPI_FUNC_ID(ADAPTER, 9),
418 	HPI_ADAPTER_FIND_OBJECT = HPI_FUNC_ID(ADAPTER, 10),
419 	HPI_ADAPTER_QUERY_FLASH = HPI_FUNC_ID(ADAPTER, 11),
420 	HPI_ADAPTER_START_FLASH = HPI_FUNC_ID(ADAPTER, 12),
421 	HPI_ADAPTER_PROGRAM_FLASH = HPI_FUNC_ID(ADAPTER, 13),
422 	HPI_ADAPTER_SET_PROPERTY = HPI_FUNC_ID(ADAPTER, 14),
423 	HPI_ADAPTER_GET_PROPERTY = HPI_FUNC_ID(ADAPTER, 15),
424 	HPI_ADAPTER_ENUM_PROPERTY = HPI_FUNC_ID(ADAPTER, 16),
425 	HPI_ADAPTER_MODULE_INFO = HPI_FUNC_ID(ADAPTER, 17),
426 	HPI_ADAPTER_DEBUG_READ = HPI_FUNC_ID(ADAPTER, 18),
427 	HPI_ADAPTER_IRQ_QUERY_AND_CLEAR = HPI_FUNC_ID(ADAPTER, 19),
428 	HPI_ADAPTER_IRQ_CALLBACK = HPI_FUNC_ID(ADAPTER, 20),
429 	HPI_ADAPTER_DELETE = HPI_FUNC_ID(ADAPTER, 21),
430 	HPI_ADAPTER_READ_FLASH = HPI_FUNC_ID(ADAPTER, 22),
431 	HPI_ADAPTER_END_FLASH = HPI_FUNC_ID(ADAPTER, 23),
432 	HPI_ADAPTER_FILESTORE_DELETE_ALL = HPI_FUNC_ID(ADAPTER, 24),
433 #define HPI_ADAPTER_FUNCTION_COUNT 24
434 
435 	HPI_OSTREAM_OPEN = HPI_FUNC_ID(OSTREAM, 1),
436 	HPI_OSTREAM_CLOSE = HPI_FUNC_ID(OSTREAM, 2),
437 	HPI_OSTREAM_WRITE = HPI_FUNC_ID(OSTREAM, 3),
438 	HPI_OSTREAM_START = HPI_FUNC_ID(OSTREAM, 4),
439 	HPI_OSTREAM_STOP = HPI_FUNC_ID(OSTREAM, 5),
440 	HPI_OSTREAM_RESET = HPI_FUNC_ID(OSTREAM, 6),
441 	HPI_OSTREAM_GET_INFO = HPI_FUNC_ID(OSTREAM, 7),
442 	HPI_OSTREAM_QUERY_FORMAT = HPI_FUNC_ID(OSTREAM, 8),
443 	HPI_OSTREAM_DATA = HPI_FUNC_ID(OSTREAM, 9),
444 	HPI_OSTREAM_SET_VELOCITY = HPI_FUNC_ID(OSTREAM, 10),
445 	HPI_OSTREAM_SET_PUNCHINOUT = HPI_FUNC_ID(OSTREAM, 11),
446 	HPI_OSTREAM_SINEGEN = HPI_FUNC_ID(OSTREAM, 12),
447 	HPI_OSTREAM_ANC_RESET = HPI_FUNC_ID(OSTREAM, 13),
448 	HPI_OSTREAM_ANC_GET_INFO = HPI_FUNC_ID(OSTREAM, 14),
449 	HPI_OSTREAM_ANC_READ = HPI_FUNC_ID(OSTREAM, 15),
450 	HPI_OSTREAM_SET_TIMESCALE = HPI_FUNC_ID(OSTREAM, 16),
451 	HPI_OSTREAM_SET_FORMAT = HPI_FUNC_ID(OSTREAM, 17),
452 	HPI_OSTREAM_HOSTBUFFER_ALLOC = HPI_FUNC_ID(OSTREAM, 18),
453 	HPI_OSTREAM_HOSTBUFFER_FREE = HPI_FUNC_ID(OSTREAM, 19),
454 	HPI_OSTREAM_GROUP_ADD = HPI_FUNC_ID(OSTREAM, 20),
455 	HPI_OSTREAM_GROUP_GETMAP = HPI_FUNC_ID(OSTREAM, 21),
456 	HPI_OSTREAM_GROUP_RESET = HPI_FUNC_ID(OSTREAM, 22),
457 	HPI_OSTREAM_HOSTBUFFER_GET_INFO = HPI_FUNC_ID(OSTREAM, 23),
458 	HPI_OSTREAM_WAIT_START = HPI_FUNC_ID(OSTREAM, 24),
459 	HPI_OSTREAM_WAIT = HPI_FUNC_ID(OSTREAM, 25),
460 #define HPI_OSTREAM_FUNCTION_COUNT 25
461 
462 	HPI_ISTREAM_OPEN = HPI_FUNC_ID(ISTREAM, 1),
463 	HPI_ISTREAM_CLOSE = HPI_FUNC_ID(ISTREAM, 2),
464 	HPI_ISTREAM_SET_FORMAT = HPI_FUNC_ID(ISTREAM, 3),
465 	HPI_ISTREAM_READ = HPI_FUNC_ID(ISTREAM, 4),
466 	HPI_ISTREAM_START = HPI_FUNC_ID(ISTREAM, 5),
467 	HPI_ISTREAM_STOP = HPI_FUNC_ID(ISTREAM, 6),
468 	HPI_ISTREAM_RESET = HPI_FUNC_ID(ISTREAM, 7),
469 	HPI_ISTREAM_GET_INFO = HPI_FUNC_ID(ISTREAM, 8),
470 	HPI_ISTREAM_QUERY_FORMAT = HPI_FUNC_ID(ISTREAM, 9),
471 	HPI_ISTREAM_ANC_RESET = HPI_FUNC_ID(ISTREAM, 10),
472 	HPI_ISTREAM_ANC_GET_INFO = HPI_FUNC_ID(ISTREAM, 11),
473 	HPI_ISTREAM_ANC_WRITE = HPI_FUNC_ID(ISTREAM, 12),
474 	HPI_ISTREAM_HOSTBUFFER_ALLOC = HPI_FUNC_ID(ISTREAM, 13),
475 	HPI_ISTREAM_HOSTBUFFER_FREE = HPI_FUNC_ID(ISTREAM, 14),
476 	HPI_ISTREAM_GROUP_ADD = HPI_FUNC_ID(ISTREAM, 15),
477 	HPI_ISTREAM_GROUP_GETMAP = HPI_FUNC_ID(ISTREAM, 16),
478 	HPI_ISTREAM_GROUP_RESET = HPI_FUNC_ID(ISTREAM, 17),
479 	HPI_ISTREAM_HOSTBUFFER_GET_INFO = HPI_FUNC_ID(ISTREAM, 18),
480 	HPI_ISTREAM_WAIT_START = HPI_FUNC_ID(ISTREAM, 19),
481 	HPI_ISTREAM_WAIT = HPI_FUNC_ID(ISTREAM, 20),
482 #define HPI_ISTREAM_FUNCTION_COUNT 20
483 
484 /* NOTE:
485    GET_NODE_INFO, SET_CONNECTION, GET_CONNECTIONS are not currently used */
486 	HPI_MIXER_OPEN = HPI_FUNC_ID(MIXER, 1),
487 	HPI_MIXER_CLOSE = HPI_FUNC_ID(MIXER, 2),
488 	HPI_MIXER_GET_INFO = HPI_FUNC_ID(MIXER, 3),
489 	HPI_MIXER_GET_NODE_INFO = HPI_FUNC_ID(MIXER, 4),
490 	HPI_MIXER_GET_CONTROL = HPI_FUNC_ID(MIXER, 5),
491 	HPI_MIXER_SET_CONNECTION = HPI_FUNC_ID(MIXER, 6),
492 	HPI_MIXER_GET_CONNECTIONS = HPI_FUNC_ID(MIXER, 7),
493 	HPI_MIXER_GET_CONTROL_BY_INDEX = HPI_FUNC_ID(MIXER, 8),
494 	HPI_MIXER_GET_CONTROL_ARRAY_BY_INDEX = HPI_FUNC_ID(MIXER, 9),
495 	HPI_MIXER_GET_CONTROL_MULTIPLE_VALUES = HPI_FUNC_ID(MIXER, 10),
496 	HPI_MIXER_STORE = HPI_FUNC_ID(MIXER, 11),
497 	HPI_MIXER_GET_CACHE_INFO = HPI_FUNC_ID(MIXER, 12),
498 	HPI_MIXER_GET_BLOCK_HANDLE = HPI_FUNC_ID(MIXER, 13),
499 	HPI_MIXER_GET_PARAMETER_HANDLE = HPI_FUNC_ID(MIXER, 14),
500 #define HPI_MIXER_FUNCTION_COUNT 14
501 
502 	HPI_CONTROL_GET_INFO = HPI_FUNC_ID(CONTROL, 1),
503 	HPI_CONTROL_GET_STATE = HPI_FUNC_ID(CONTROL, 2),
504 	HPI_CONTROL_SET_STATE = HPI_FUNC_ID(CONTROL, 3),
505 #define HPI_CONTROL_FUNCTION_COUNT 3
506 
507 	HPI_NVMEMORY_OPEN = HPI_FUNC_ID(NVMEMORY, 1),
508 	HPI_NVMEMORY_READ_BYTE = HPI_FUNC_ID(NVMEMORY, 2),
509 	HPI_NVMEMORY_WRITE_BYTE = HPI_FUNC_ID(NVMEMORY, 3),
510 #define HPI_NVMEMORY_FUNCTION_COUNT 3
511 
512 	HPI_GPIO_OPEN = HPI_FUNC_ID(GPIO, 1),
513 	HPI_GPIO_READ_BIT = HPI_FUNC_ID(GPIO, 2),
514 	HPI_GPIO_WRITE_BIT = HPI_FUNC_ID(GPIO, 3),
515 	HPI_GPIO_READ_ALL = HPI_FUNC_ID(GPIO, 4),
516 	HPI_GPIO_WRITE_STATUS = HPI_FUNC_ID(GPIO, 5),
517 #define HPI_GPIO_FUNCTION_COUNT 5
518 
519 	HPI_ASYNCEVENT_OPEN = HPI_FUNC_ID(ASYNCEVENT, 1),
520 	HPI_ASYNCEVENT_CLOSE = HPI_FUNC_ID(ASYNCEVENT, 2),
521 	HPI_ASYNCEVENT_WAIT = HPI_FUNC_ID(ASYNCEVENT, 3),
522 	HPI_ASYNCEVENT_GETCOUNT = HPI_FUNC_ID(ASYNCEVENT, 4),
523 	HPI_ASYNCEVENT_GET = HPI_FUNC_ID(ASYNCEVENT, 5),
524 	HPI_ASYNCEVENT_SENDEVENTS = HPI_FUNC_ID(ASYNCEVENT, 6),
525 #define HPI_ASYNCEVENT_FUNCTION_COUNT 6
526 
527 	HPI_WATCHDOG_OPEN = HPI_FUNC_ID(WATCHDOG, 1),
528 	HPI_WATCHDOG_SET_TIME = HPI_FUNC_ID(WATCHDOG, 2),
529 	HPI_WATCHDOG_PING = HPI_FUNC_ID(WATCHDOG, 3),
530 
531 	HPI_CLOCK_OPEN = HPI_FUNC_ID(CLOCK, 1),
532 	HPI_CLOCK_SET_TIME = HPI_FUNC_ID(CLOCK, 2),
533 	HPI_CLOCK_GET_TIME = HPI_FUNC_ID(CLOCK, 3),
534 
535 	HPI_PROFILE_OPEN_ALL = HPI_FUNC_ID(PROFILE, 1),
536 	HPI_PROFILE_START_ALL = HPI_FUNC_ID(PROFILE, 2),
537 	HPI_PROFILE_STOP_ALL = HPI_FUNC_ID(PROFILE, 3),
538 	HPI_PROFILE_GET = HPI_FUNC_ID(PROFILE, 4),
539 	HPI_PROFILE_GET_IDLECOUNT = HPI_FUNC_ID(PROFILE, 5),
540 	HPI_PROFILE_GET_NAME = HPI_FUNC_ID(PROFILE, 6),
541 	HPI_PROFILE_GET_UTILIZATION = HPI_FUNC_ID(PROFILE, 7)
542 #define HPI_PROFILE_FUNCTION_COUNT 7
543 };
544 
545 /* ////////////////////////////////////////////////////////////////////// */
546 /* STRUCTURES */
547 #ifndef DISABLE_PRAGMA_PACK1
548 #pragma pack(push, 1)
549 #endif
550 
551 /** PCI bus resource */
552 struct hpi_pci {
553 	u32 __iomem *ap_mem_base[HPI_MAX_ADAPTER_MEM_SPACES];
554 	struct pci_dev *pci_dev;
555 };
556 
557 struct hpi_resource {
558 	union {
559 		const struct hpi_pci *pci;
560 		const char *net_if;
561 	} r;
562 #ifndef HPI64BIT		/* keep structure size constant */
563 	u32 pad_to64;
564 #endif
565 	u16 bus_type;		/* HPI_BUS_PNPISA, _PCI, _USB etc */
566 	u16 padding;
567 
568 };
569 
570 /** Format info used inside struct hpi_message
571     Not the same as public API struct hpi_format */
572 struct hpi_msg_format {
573 	u32 sample_rate; /**< 11025, 32000, 44100 etc. */
574 	u32 bit_rate; /**< for MPEG */
575 	u32 attributes;	/**< stereo/joint_stereo/mono */
576 	u16 channels; /**< 1,2..., (or ancillary mode or idle bit */
577 	u16 format; /**< HPI_FORMAT_PCM16, _MPEG etc. see \ref HPI_FORMATS. */
578 };
579 
580 /**  Buffer+format structure.
581 	 Must be kept 7 * 32 bits to match public struct hpi_datastruct */
582 struct hpi_msg_data {
583 	struct hpi_msg_format format;
584 	u8 *pb_data;
585 #ifndef HPI64BIT
586 	u32 padding;
587 #endif
588 	u32 data_size;
589 };
590 
591 /** struct hpi_datastructure used up to 3.04 driver */
592 struct hpi_data_legacy32 {
593 	struct hpi_format format;
594 	u32 pb_data;
595 	u32 data_size;
596 };
597 
598 #ifdef HPI64BIT
599 /* Compatibility version of struct hpi_data*/
600 struct hpi_data_compat32 {
601 	struct hpi_msg_format format;
602 	u32 pb_data;
603 	u32 padding;
604 	u32 data_size;
605 };
606 #endif
607 
608 struct hpi_buffer {
609   /** placeholder for backward compatibility (see dwBufferSize) */
610 	struct hpi_msg_format reserved;
611 	u32 command; /**< HPI_BUFFER_CMD_xxx*/
612 	u32 pci_address; /**< PCI physical address of buffer for DSP DMA */
613 	u32 buffer_size; /**< must line up with data_size of HPI_DATA*/
614 };
615 
616 /*/////////////////////////////////////////////////////////////////////////// */
617 /* This is used for background buffer bus mastering stream buffers.           */
618 struct hpi_hostbuffer_status {
619 	u32 samples_processed;
620 	u32 auxiliary_data_available;
621 	u32 stream_state;
622 	/* DSP index in to the host bus master buffer. */
623 	u32 dsp_index;
624 	/* Host index in to the host bus master buffer. */
625 	u32 host_index;
626 	u32 size_in_bytes;
627 };
628 
629 struct hpi_streamid {
630 	u16 object_type;
631 		    /**< Type of object, HPI_OBJ_OSTREAM or HPI_OBJ_ISTREAM. */
632 	u16 stream_index; /**< outstream or instream index. */
633 };
634 
635 struct hpi_punchinout {
636 	u32 punch_in_sample;
637 	u32 punch_out_sample;
638 };
639 
640 struct hpi_subsys_msg {
641 	struct hpi_resource resource;
642 };
643 
644 struct hpi_subsys_res {
645 	u32 version;
646 	u32 data;		/* extended version */
647 	u16 num_adapters;
648 	u16 adapter_index;
649 	u16 adapter_type;
650 	u16 pad16;
651 };
652 
653 union hpi_adapterx_msg {
654 	struct {
655 		u32 dsp_address;
656 		u32 count_bytes;
657 	} debug_read;
658 	struct {
659 		u32 adapter_mode;
660 		u16 query_or_set;
661 	} mode;
662 	struct {
663 		u16 index;
664 	} module_info;
665 	struct {
666 		u16 index;
667 		u16 what;
668 		u16 property_index;
669 	} property_enum;
670 	struct {
671 		u16 property;
672 		u16 parameter1;
673 		u16 parameter2;
674 	} property_set;
675 	struct {
676 		u32 pad32;
677 		u16 key1;
678 		u16 key2;
679 	} restart;
680 	struct {
681 		u32 pad32;
682 		u16 value;
683 	} test_assert;
684 	struct {
685 		u32 yes;
686 	} irq_query;
687 	u32 pad[3];
688 };
689 
690 struct hpi_adapter_res {
691 	u32 serial_number;
692 	u16 adapter_type;
693 	u16 adapter_index;
694 	u16 num_instreams;
695 	u16 num_outstreams;
696 	u16 num_mixers;
697 	u16 version;
698 	u8 sz_adapter_assert[HPI_STRING_LEN];
699 };
700 
701 union hpi_adapterx_res {
702 	struct hpi_adapter_res info;
703 	struct {
704 		u32 p1;
705 		u16 count;
706 		u16 dsp_index;
707 		u32 p2;
708 		u32 dsp_msg_addr;
709 		char sz_message[HPI_STRING_LEN];
710 	} assert;
711 	struct {
712 		u32 adapter_mode;
713 	} mode;
714 	struct {
715 		u16 parameter1;
716 		u16 parameter2;
717 	} property_get;
718 	struct {
719 		u32 yes;
720 	} irq_query;
721 };
722 
723 struct hpi_stream_msg {
724 	union {
725 		struct hpi_msg_data data;
726 		struct hpi_data_legacy32 data32;
727 		u16 velocity;
728 		struct hpi_punchinout pio;
729 		u32 time_scale;
730 		struct hpi_buffer buffer;
731 		struct hpi_streamid stream;
732 		u32 threshold_bytes;
733 	} u;
734 };
735 
736 struct hpi_stream_res {
737 	union {
738 		struct {
739 			/* size of hardware buffer */
740 			u32 buffer_size;
741 			/* OutStream - data to play,
742 			   InStream - data recorded */
743 			u32 data_available;
744 			/* OutStream - samples played,
745 			   InStream - samples recorded */
746 			u32 samples_transferred;
747 			/* Adapter - OutStream - data to play,
748 			   InStream - data recorded */
749 			u32 auxiliary_data_available;
750 			u16 state;	/* HPI_STATE_PLAYING, _STATE_STOPPED */
751 			u16 padding;
752 		} stream_info;
753 		struct {
754 			u32 buffer_size;
755 			u32 data_available;
756 			u32 samples_transfered;
757 			u16 state;
758 			u16 outstream_index;
759 			u16 instream_index;
760 			u16 padding;
761 			u32 auxiliary_data_available;
762 		} legacy_stream_info;
763 		struct {
764 			/* bitmap of grouped OutStreams */
765 			u32 outstream_group_map;
766 			/* bitmap of grouped InStreams */
767 			u32 instream_group_map;
768 		} group_info;
769 		struct {
770 			/* pointer to the buffer */
771 			u8 *p_buffer;
772 			/* pointer to the hostbuffer status */
773 			struct hpi_hostbuffer_status *p_status;
774 		} hostbuffer_info;
775 	} u;
776 };
777 
778 struct hpi_mixer_msg {
779 	u16 control_index;
780 	u16 control_type;	/* = HPI_CONTROL_METER _VOLUME etc */
781 	u16 padding1;		/* Maintain alignment of subsequent fields */
782 	u16 node_type1;		/* = HPI_SOURCENODE_LINEIN etc */
783 	u16 node_index1;	/* = 0..N */
784 	u16 node_type2;
785 	u16 node_index2;
786 	u16 padding2;		/* round to 4 bytes */
787 };
788 
789 struct hpi_mixer_res {
790 	u16 src_node_type;	/* = HPI_SOURCENODE_LINEIN etc */
791 	u16 src_node_index;	/* = 0..N */
792 	u16 dst_node_type;
793 	u16 dst_node_index;
794 	/* Also controlType for MixerGetControlByIndex */
795 	u16 control_index;
796 	/* may indicate which DSP the control is located on */
797 	u16 dsp_index;
798 };
799 
800 union hpi_mixerx_msg {
801 	struct {
802 		u16 starting_index;
803 		u16 flags;
804 		u32 length_in_bytes;	/* length in bytes of p_data */
805 		u32 p_data;	/* pointer to a data array */
806 	} gcabi;
807 	struct {
808 		u16 command;
809 		u16 index;
810 	} store;		/* for HPI_MIXER_STORE message */
811 };
812 
813 union hpi_mixerx_res {
814 	struct {
815 		u32 bytes_returned;	/* size of items returned */
816 		u32 p_data;	/* pointer to data array */
817 		u16 more_to_do;	/* indicates if there is more to do */
818 	} gcabi;
819 	struct {
820 		u32 total_controls;	/* count of controls in the mixer */
821 		u32 cache_controls;	/* count of controls in the cac */
822 		u32 cache_bytes;	/* size of cache */
823 	} cache_info;
824 };
825 
826 struct hpi_control_msg {
827 	u16 attribute;		/* control attribute or property */
828 	u16 saved_index;
829 	u32 param1;		/* generic parameter 1 */
830 	u32 param2;		/* generic parameter 2 */
831 	short an_log_value[HPI_MAX_CHANNELS];
832 };
833 
834 struct hpi_control_union_msg {
835 	u16 attribute;		/* control attribute or property */
836 	u16 saved_index;	/* only used in ctrl save/restore */
837 	union {
838 		struct {
839 			u32 param1;	/* generic parameter 1 */
840 			u32 param2;	/* generic parameter 2 */
841 			short an_log_value[HPI_MAX_CHANNELS];
842 		} old;
843 		union {
844 			u32 frequency;
845 			u32 gain;
846 			u32 band;
847 			u32 deemphasis;
848 			u32 program;
849 			struct {
850 				u32 mode;
851 				u32 value;
852 			} mode;
853 			u32 blend;
854 		} tuner;
855 	} u;
856 };
857 
858 struct hpi_control_res {
859 	/* Could make union. dwParam, anLogValue never used in same response */
860 	u32 param1;
861 	u32 param2;
862 	short an_log_value[HPI_MAX_CHANNELS];
863 };
864 
865 union hpi_control_union_res {
866 	struct {
867 		u32 param1;
868 		u32 param2;
869 		short an_log_value[HPI_MAX_CHANNELS];
870 	} old;
871 	union {
872 		u32 band;
873 		u32 frequency;
874 		u32 gain;
875 		u32 deemphasis;
876 		struct {
877 			u32 data[2];
878 			u32 bLER;
879 		} rds;
880 		short s_level;
881 		struct {
882 			u16 value;
883 			u16 mask;
884 		} status;
885 	} tuner;
886 	struct {
887 		char sz_data[8];
888 		u32 remaining_chars;
889 	} chars8;
890 	char c_data12[12];
891 	union {
892 		struct {
893 			u32 status;
894 			u32 readable_size;
895 			u32 writeable_size;
896 		} status;
897 	} cobranet;
898 };
899 
900 struct hpi_nvmemory_msg {
901 	u16 address;
902 	u16 data;
903 };
904 
905 struct hpi_nvmemory_res {
906 	u16 size_in_bytes;
907 	u16 data;
908 };
909 
910 struct hpi_gpio_msg {
911 	u16 bit_index;
912 	u16 bit_data;
913 };
914 
915 struct hpi_gpio_res {
916 	u16 number_input_bits;
917 	u16 number_output_bits;
918 	u16 bit_data[4];
919 };
920 
921 struct hpi_async_msg {
922 	u32 events;
923 	u16 maximum_events;
924 	u16 padding;
925 };
926 
927 struct hpi_async_res {
928 	union {
929 		struct {
930 			u16 count;
931 		} count;
932 		struct {
933 			u32 events;
934 			u16 number_returned;
935 			u16 padding;
936 		} get;
937 		struct hpi_async_event event;
938 	} u;
939 };
940 
941 struct hpi_watchdog_msg {
942 	u32 time_ms;
943 };
944 
945 struct hpi_watchdog_res {
946 	u32 time_ms;
947 };
948 
949 struct hpi_clock_msg {
950 	u16 hours;
951 	u16 minutes;
952 	u16 seconds;
953 	u16 milli_seconds;
954 };
955 
956 struct hpi_clock_res {
957 	u16 size_in_bytes;
958 	u16 hours;
959 	u16 minutes;
960 	u16 seconds;
961 	u16 milli_seconds;
962 	u16 padding;
963 };
964 
965 struct hpi_profile_msg {
966 	u16 bin_index;
967 	u16 padding;
968 };
969 
970 struct hpi_profile_res_open {
971 	u16 max_profiles;
972 };
973 
974 struct hpi_profile_res_time {
975 	u32 total_tick_count;
976 	u32 call_count;
977 	u32 max_tick_count;
978 	u32 ticks_per_millisecond;
979 	u16 profile_interval;
980 };
981 
982 struct hpi_profile_res_name {
983 	u8 sz_name[32];
984 };
985 
986 struct hpi_profile_res {
987 	union {
988 		struct hpi_profile_res_open o;
989 		struct hpi_profile_res_time t;
990 		struct hpi_profile_res_name n;
991 	} u;
992 };
993 
994 struct hpi_message_header {
995 	u16 size;		/* total size in bytes */
996 	u8 type;		/* HPI_TYPE_MESSAGE  */
997 	u8 version;		/* message version */
998 	u16 object;		/* HPI_OBJ_* */
999 	u16 function;		/* HPI_SUBSYS_xxx, HPI_ADAPTER_xxx */
1000 	u16 adapter_index;	/* the adapter index */
1001 	u16 obj_index;		/* */
1002 };
1003 
1004 struct hpi_message {
1005 	/* following fields must match HPI_MESSAGE_HEADER */
1006 	u16 size;		/* total size in bytes */
1007 	u8 type;		/* HPI_TYPE_MESSAGE  */
1008 	u8 version;		/* message version */
1009 	u16 object;		/* HPI_OBJ_* */
1010 	u16 function;		/* HPI_SUBSYS_xxx, HPI_ADAPTER_xxx */
1011 	u16 adapter_index;	/* the adapter index */
1012 	u16 obj_index;		/*  */
1013 	union {
1014 		struct hpi_subsys_msg s;
1015 		union hpi_adapterx_msg ax;
1016 		struct hpi_stream_msg d;
1017 		struct hpi_mixer_msg m;
1018 		union hpi_mixerx_msg mx;	/* extended mixer; */
1019 		struct hpi_control_msg c;	/* mixer control; */
1020 		/* identical to struct hpi_control_msg,
1021 		   but field naming is improved */
1022 		struct hpi_control_union_msg cu;
1023 		struct hpi_nvmemory_msg n;
1024 		struct hpi_gpio_msg l;	/* digital i/o */
1025 		struct hpi_watchdog_msg w;
1026 		struct hpi_clock_msg t;	/* dsp time */
1027 		struct hpi_profile_msg p;
1028 		struct hpi_async_msg as;
1029 		char fixed_size[32];
1030 	} u;
1031 };
1032 
1033 #define HPI_MESSAGE_SIZE_BY_OBJECT { \
1034 	sizeof(struct hpi_message_header) ,   /* Default, no object type 0 */ \
1035 	sizeof(struct hpi_message_header) + sizeof(struct hpi_subsys_msg),\
1036 	sizeof(struct hpi_message_header) + sizeof(union hpi_adapterx_msg),\
1037 	sizeof(struct hpi_message_header) + sizeof(struct hpi_stream_msg),\
1038 	sizeof(struct hpi_message_header) + sizeof(struct hpi_stream_msg),\
1039 	sizeof(struct hpi_message_header) + sizeof(struct hpi_mixer_msg),\
1040 	sizeof(struct hpi_message_header) ,   /* no node message */ \
1041 	sizeof(struct hpi_message_header) + sizeof(struct hpi_control_msg),\
1042 	sizeof(struct hpi_message_header) + sizeof(struct hpi_nvmemory_msg),\
1043 	sizeof(struct hpi_message_header) + sizeof(struct hpi_gpio_msg),\
1044 	sizeof(struct hpi_message_header) + sizeof(struct hpi_watchdog_msg),\
1045 	sizeof(struct hpi_message_header) + sizeof(struct hpi_clock_msg),\
1046 	sizeof(struct hpi_message_header) + sizeof(struct hpi_profile_msg),\
1047 	sizeof(struct hpi_message_header), /* controlx obj removed */ \
1048 	sizeof(struct hpi_message_header) + sizeof(struct hpi_async_msg) \
1049 }
1050 
1051 /*
1052 Note that the wSpecificError error field should be inspected and potentially
1053 reported whenever HPI_ERROR_DSP_COMMUNICATION or HPI_ERROR_DSP_BOOTLOAD is
1054 returned in wError.
1055 */
1056 struct hpi_response_header {
1057 	u16 size;
1058 	u8 type;		/* HPI_TYPE_RESPONSE  */
1059 	u8 version;		/* response version */
1060 	u16 object;		/* HPI_OBJ_* */
1061 	u16 function;		/* HPI_SUBSYS_xxx, HPI_ADAPTER_xxx */
1062 	u16 error;		/* HPI_ERROR_xxx */
1063 	u16 specific_error;	/* adapter specific error */
1064 };
1065 
1066 struct hpi_response {
1067 /* following fields must match HPI_RESPONSE_HEADER */
1068 	u16 size;
1069 	u8 type;		/* HPI_TYPE_RESPONSE  */
1070 	u8 version;		/* response version */
1071 	u16 object;		/* HPI_OBJ_* */
1072 	u16 function;		/* HPI_SUBSYS_xxx, HPI_ADAPTER_xxx */
1073 	u16 error;		/* HPI_ERROR_xxx */
1074 	u16 specific_error;	/* adapter specific error */
1075 	union {
1076 		struct hpi_subsys_res s;
1077 		union hpi_adapterx_res ax;
1078 		struct hpi_stream_res d;
1079 		struct hpi_mixer_res m;
1080 		union hpi_mixerx_res mx;	/* extended mixer; */
1081 		struct hpi_control_res c;	/* mixer control; */
1082 		/* identical to hpi_control_res, but field naming is improved */
1083 		union hpi_control_union_res cu;
1084 		struct hpi_nvmemory_res n;
1085 		struct hpi_gpio_res l;	/* digital i/o */
1086 		struct hpi_watchdog_res w;
1087 		struct hpi_clock_res t;	/* dsp time */
1088 		struct hpi_profile_res p;
1089 		struct hpi_async_res as;
1090 		u8 bytes[52];
1091 	} u;
1092 };
1093 
1094 #define HPI_RESPONSE_SIZE_BY_OBJECT { \
1095 	sizeof(struct hpi_response_header) ,/* Default, no object type 0 */ \
1096 	sizeof(struct hpi_response_header) + sizeof(struct hpi_subsys_res),\
1097 	sizeof(struct hpi_response_header) + sizeof(union  hpi_adapterx_res),\
1098 	sizeof(struct hpi_response_header) + sizeof(struct hpi_stream_res),\
1099 	sizeof(struct hpi_response_header) + sizeof(struct hpi_stream_res),\
1100 	sizeof(struct hpi_response_header) + sizeof(struct hpi_mixer_res),\
1101 	sizeof(struct hpi_response_header) , /* no node response */ \
1102 	sizeof(struct hpi_response_header) + sizeof(struct hpi_control_res),\
1103 	sizeof(struct hpi_response_header) + sizeof(struct hpi_nvmemory_res),\
1104 	sizeof(struct hpi_response_header) + sizeof(struct hpi_gpio_res),\
1105 	sizeof(struct hpi_response_header) + sizeof(struct hpi_watchdog_res),\
1106 	sizeof(struct hpi_response_header) + sizeof(struct hpi_clock_res),\
1107 	sizeof(struct hpi_response_header) + sizeof(struct hpi_profile_res),\
1108 	sizeof(struct hpi_response_header), /* controlx obj removed */ \
1109 	sizeof(struct hpi_response_header) + sizeof(struct hpi_async_res) \
1110 }
1111 
1112 /*********************** version 1 message/response **************************/
1113 #define HPINET_ETHERNET_DATA_SIZE (1500)
1114 #define HPINET_IP_HDR_SIZE (20)
1115 #define HPINET_IP_DATA_SIZE (HPINET_ETHERNET_DATA_SIZE - HPINET_IP_HDR_SIZE)
1116 #define HPINET_UDP_HDR_SIZE (8)
1117 #define HPINET_UDP_DATA_SIZE (HPINET_IP_DATA_SIZE - HPINET_UDP_HDR_SIZE)
1118 #define HPINET_ASI_HDR_SIZE (2)
1119 #define HPINET_ASI_DATA_SIZE (HPINET_UDP_DATA_SIZE - HPINET_ASI_HDR_SIZE)
1120 
1121 #define HPI_MAX_PAYLOAD_SIZE (HPINET_ASI_DATA_SIZE - 2)
1122 
1123 /* New style message/response, but still V0 compatible */
1124 struct hpi_msg_adapter_get_info {
1125 	struct hpi_message_header h;
1126 };
1127 
1128 struct hpi_res_adapter_get_info {
1129 	struct hpi_response_header h;	/*v0 */
1130 	struct hpi_adapter_res p;
1131 };
1132 
1133 struct hpi_res_adapter_debug_read {
1134 	struct hpi_response_header h;
1135 	u8 bytes[1024];
1136 };
1137 
1138 struct hpi_msg_cobranet_hmi {
1139 	u16 attribute;
1140 	u16 padding;
1141 	u32 hmi_address;
1142 	u32 byte_count;
1143 };
1144 
1145 struct hpi_msg_cobranet_hmiwrite {
1146 	struct hpi_message_header h;
1147 	struct hpi_msg_cobranet_hmi p;
1148 	u8 bytes[256];
1149 };
1150 
1151 struct hpi_msg_cobranet_hmiread {
1152 	struct hpi_message_header h;
1153 	struct hpi_msg_cobranet_hmi p;
1154 };
1155 
1156 struct hpi_res_cobranet_hmiread {
1157 	struct hpi_response_header h;
1158 	u32 byte_count;
1159 	u8 bytes[256];
1160 };
1161 
1162 #if 1
1163 #define hpi_message_header_v1 hpi_message_header
1164 #define hpi_response_header_v1 hpi_response_header
1165 #else
1166 /* V1 headers in Addition to v0 headers */
1167 struct hpi_message_header_v1 {
1168 	struct hpi_message_header h0;
1169 /* struct {
1170 } h1; */
1171 };
1172 
1173 struct hpi_response_header_v1 {
1174 	struct hpi_response_header h0;
1175 	struct {
1176 		u16 adapter_index;	/* the adapter index */
1177 		u16 obj_index;	/* object index */
1178 	} h1;
1179 };
1180 #endif
1181 
1182 struct hpi_msg_payload_v0 {
1183 	struct hpi_message_header h;
1184 	union {
1185 		struct hpi_subsys_msg s;
1186 		union hpi_adapterx_msg ax;
1187 		struct hpi_stream_msg d;
1188 		struct hpi_mixer_msg m;
1189 		union hpi_mixerx_msg mx;
1190 		struct hpi_control_msg c;
1191 		struct hpi_control_union_msg cu;
1192 		struct hpi_nvmemory_msg n;
1193 		struct hpi_gpio_msg l;
1194 		struct hpi_watchdog_msg w;
1195 		struct hpi_clock_msg t;
1196 		struct hpi_profile_msg p;
1197 		struct hpi_async_msg as;
1198 	} u;
1199 };
1200 
1201 struct hpi_res_payload_v0 {
1202 	struct hpi_response_header h;
1203 	union {
1204 		struct hpi_subsys_res s;
1205 		union hpi_adapterx_res ax;
1206 		struct hpi_stream_res d;
1207 		struct hpi_mixer_res m;
1208 		union hpi_mixerx_res mx;
1209 		struct hpi_control_res c;
1210 		union hpi_control_union_res cu;
1211 		struct hpi_nvmemory_res n;
1212 		struct hpi_gpio_res l;
1213 		struct hpi_watchdog_res w;
1214 		struct hpi_clock_res t;
1215 		struct hpi_profile_res p;
1216 		struct hpi_async_res as;
1217 	} u;
1218 };
1219 
1220 union hpi_message_buffer_v1 {
1221 	struct hpi_message m0;	/* version 0 */
1222 	struct hpi_message_header_v1 h;
1223 	u8 buf[HPI_MAX_PAYLOAD_SIZE];
1224 };
1225 
1226 union hpi_response_buffer_v1 {
1227 	struct hpi_response r0;	/* version 0 */
1228 	struct hpi_response_header_v1 h;
1229 	u8 buf[HPI_MAX_PAYLOAD_SIZE];
1230 };
1231 
1232 compile_time_assert((sizeof(union hpi_message_buffer_v1) <=
1233 		HPI_MAX_PAYLOAD_SIZE), message_buffer_ok);
1234 compile_time_assert((sizeof(union hpi_response_buffer_v1) <=
1235 		HPI_MAX_PAYLOAD_SIZE), response_buffer_ok);
1236 
1237 /*////////////////////////////////////////////////////////////////////////// */
1238 /* declarations for compact control calls  */
1239 struct hpi_control_defn {
1240 	u8 type;
1241 	u8 channels;
1242 	u8 src_node_type;
1243 	u8 src_node_index;
1244 	u8 dest_node_type;
1245 	u8 dest_node_index;
1246 };
1247 
1248 /*////////////////////////////////////////////////////////////////////////// */
1249 /* declarations for control caching (internal to HPI<->DSP interaction)      */
1250 
1251 /** indicates a cached u16 value is invalid. */
1252 #define HPI_CACHE_INVALID_UINT16 0xFFFF
1253 /** indicates a cached short value is invalid. */
1254 #define HPI_CACHE_INVALID_SHORT -32768
1255 
1256 /** A compact representation of (part of) a controls state.
1257 Used for efficient transfer of the control state
1258 between DSP and host or across a network
1259 */
1260 struct hpi_control_cache_info {
1261 	/** one of HPI_CONTROL_* */
1262 	u8 control_type;
1263 	/** The total size of cached information in 32-bit words. */
1264 	u8 size_in32bit_words;
1265 	/** The original index of the control on the DSP */
1266 	u16 control_index;
1267 };
1268 
1269 struct hpi_control_cache_vol {
1270 	struct hpi_control_cache_info i;
1271 	short an_log[2];
1272 	unsigned short flags;
1273 	char padding[2];
1274 };
1275 
1276 struct hpi_control_cache_meter {
1277 	struct hpi_control_cache_info i;
1278 	short an_log_peak[2];
1279 	short an_logRMS[2];
1280 };
1281 
1282 struct hpi_control_cache_channelmode {
1283 	struct hpi_control_cache_info i;
1284 	u16 mode;
1285 	char temp_padding[6];
1286 };
1287 
1288 struct hpi_control_cache_mux {
1289 	struct hpi_control_cache_info i;
1290 	u16 source_node_type;
1291 	u16 source_node_index;
1292 	char temp_padding[4];
1293 };
1294 
1295 struct hpi_control_cache_level {
1296 	struct hpi_control_cache_info i;
1297 	short an_log[2];
1298 	char temp_padding[4];
1299 };
1300 
1301 struct hpi_control_cache_tuner {
1302 	struct hpi_control_cache_info i;
1303 	u32 freq_ink_hz;
1304 	u16 band;
1305 	short s_level_avg;
1306 };
1307 
1308 struct hpi_control_cache_aes3rx {
1309 	struct hpi_control_cache_info i;
1310 	u32 error_status;
1311 	u32 format;
1312 };
1313 
1314 struct hpi_control_cache_aes3tx {
1315 	struct hpi_control_cache_info i;
1316 	u32 format;
1317 	char temp_padding[4];
1318 };
1319 
1320 struct hpi_control_cache_tonedetector {
1321 	struct hpi_control_cache_info i;
1322 	u16 state;
1323 	char temp_padding[6];
1324 };
1325 
1326 struct hpi_control_cache_silencedetector {
1327 	struct hpi_control_cache_info i;
1328 	u32 state;
1329 	char temp_padding[4];
1330 };
1331 
1332 struct hpi_control_cache_sampleclock {
1333 	struct hpi_control_cache_info i;
1334 	u16 source;
1335 	u16 source_index;
1336 	u32 sample_rate;
1337 };
1338 
1339 struct hpi_control_cache_microphone {
1340 	struct hpi_control_cache_info i;
1341 	u16 phantom_state;
1342 	char temp_padding[6];
1343 };
1344 
1345 struct hpi_control_cache_single {
1346 	union {
1347 		struct hpi_control_cache_info i;
1348 		struct hpi_control_cache_vol vol;
1349 		struct hpi_control_cache_meter meter;
1350 		struct hpi_control_cache_channelmode mode;
1351 		struct hpi_control_cache_mux mux;
1352 		struct hpi_control_cache_level level;
1353 		struct hpi_control_cache_tuner tuner;
1354 		struct hpi_control_cache_aes3rx aes3rx;
1355 		struct hpi_control_cache_aes3tx aes3tx;
1356 		struct hpi_control_cache_tonedetector tone;
1357 		struct hpi_control_cache_silencedetector silence;
1358 		struct hpi_control_cache_sampleclock clk;
1359 		struct hpi_control_cache_microphone microphone;
1360 	} u;
1361 };
1362 
1363 struct hpi_control_cache_pad {
1364 	struct hpi_control_cache_info i;
1365 	u32 field_valid_flags;
1366 	u8 c_channel[8];
1367 	u8 c_artist[40];
1368 	u8 c_title[40];
1369 	u8 c_comment[200];
1370 	u32 pTY;
1371 	u32 pI;
1372 	u32 traffic_supported;
1373 	u32 traffic_anouncement;
1374 };
1375 
1376 /* 2^N sized FIFO buffer (internal to HPI<->DSP interaction) */
1377 struct hpi_fifo_buffer {
1378 	u32 size;
1379 	u32 dsp_index;
1380 	u32 host_index;
1381 };
1382 
1383 #ifndef DISABLE_PRAGMA_PACK1
1384 #pragma pack(pop)
1385 #endif
1386 
1387 /* skip host side function declarations for DSP
1388    compile and documentation extraction */
1389 
1390 char hpi_handle_object(const u32 handle);
1391 
1392 void hpi_handle_to_indexes(const u32 handle, u16 *pw_adapter_index,
1393 	u16 *pw_object_index);
1394 
1395 u32 hpi_indexes_to_handle(const char c_object, const u16 adapter_index,
1396 	const u16 object_index);
1397 
1398 /*////////////////////////////////////////////////////////////////////////// */
1399 
1400 /* main HPI entry point */
1401 void hpi_send_recv(struct hpi_message *phm, struct hpi_response *phr);
1402 
1403 /* used in PnP OS/driver */
1404 u16 hpi_subsys_create_adapter(const struct hpi_resource *p_resource,
1405 	u16 *pw_adapter_index);
1406 
1407 u16 hpi_outstream_host_buffer_get_info(u32 h_outstream, u8 **pp_buffer,
1408 	struct hpi_hostbuffer_status **pp_status);
1409 
1410 u16 hpi_instream_host_buffer_get_info(u32 h_instream, u8 **pp_buffer,
1411 	struct hpi_hostbuffer_status **pp_status);
1412 
1413 u16 hpi_adapter_restart(u16 adapter_index);
1414 
1415 /*
1416 The following 3 functions were last declared in header files for
1417 driver 3.10. HPI_ControlQuery() used to be the recommended way
1418 of getting a volume range. Declared here for binary asihpi32.dll
1419 compatibility.
1420 */
1421 
1422 void hpi_format_to_msg(struct hpi_msg_format *pMF,
1423 	const struct hpi_format *pF);
1424 void hpi_stream_response_to_legacy(struct hpi_stream_res *pSR);
1425 
1426 /*////////////////////////////////////////////////////////////////////////// */
1427 /* declarations for individual HPI entry points */
1428 hpi_handler_func HPI_6000;
1429 hpi_handler_func HPI_6205;
1430 
1431 #endif				/* _HPI_INTERNAL_H_ */
1432