1 /******************************************************************************
3 AudioScience HPI driver
4 Copyright (C) 1997-2010 AudioScience Inc. <support@audioscience.com>
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;
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.
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
19 Extended Message Function With Response Cacheing
21 (C) Copyright AudioScience Inc. 2002
22 *****************************************************************************/
23 #define SOURCEFILE_NAME "hpimsgx.c"
24 #include "hpi_internal.h"
25 #include "hpimsginit.h"
30 static struct pci_device_id asihpi_pci_tbl
[] = {
34 static struct hpios_spinlock msgx_lock
;
36 static hpi_handler_func
*hpi_entry_points
[HPI_MAX_ADAPTERS
];
38 static hpi_handler_func
*hpi_lookup_entry_point_function(const struct hpi_pci
44 for (i
= 0; asihpi_pci_tbl
[i
].vendor
!= 0; i
++) {
45 if (asihpi_pci_tbl
[i
].vendor
!= PCI_ANY_ID
46 && asihpi_pci_tbl
[i
].vendor
!=
47 pci_info
->pci_dev
->vendor
)
49 if (asihpi_pci_tbl
[i
].device
!= PCI_ANY_ID
50 && asihpi_pci_tbl
[i
].device
!=
51 pci_info
->pci_dev
->device
)
53 if (asihpi_pci_tbl
[i
].subvendor
!= PCI_ANY_ID
54 && asihpi_pci_tbl
[i
].subvendor
!=
55 pci_info
->pci_dev
->subsystem_vendor
)
57 if (asihpi_pci_tbl
[i
].subdevice
!= PCI_ANY_ID
58 && asihpi_pci_tbl
[i
].subdevice
!=
59 pci_info
->pci_dev
->subsystem_device
)
62 /* HPI_DEBUG_LOG(DEBUG, " %x,%lx\n", i,
63 asihpi_pci_tbl[i].driver_data); */
64 return (hpi_handler_func
*) asihpi_pci_tbl
[i
].driver_data
;
70 static inline void hw_entry_point(struct hpi_message
*phm
,
71 struct hpi_response
*phr
)
73 if ((phm
->adapter_index
< HPI_MAX_ADAPTERS
)
74 && hpi_entry_points
[phm
->adapter_index
])
75 hpi_entry_points
[phm
->adapter_index
] (phm
, phr
);
77 hpi_init_response(phr
, phm
->object
, phm
->function
,
78 HPI_ERROR_PROCESSING_MESSAGE
);
81 static void adapter_open(struct hpi_message
*phm
, struct hpi_response
*phr
);
82 static void adapter_close(struct hpi_message
*phm
, struct hpi_response
*phr
);
84 static void mixer_open(struct hpi_message
*phm
, struct hpi_response
*phr
);
85 static void mixer_close(struct hpi_message
*phm
, struct hpi_response
*phr
);
87 static void outstream_open(struct hpi_message
*phm
, struct hpi_response
*phr
,
89 static void outstream_close(struct hpi_message
*phm
, struct hpi_response
*phr
,
91 static void instream_open(struct hpi_message
*phm
, struct hpi_response
*phr
,
93 static void instream_close(struct hpi_message
*phm
, struct hpi_response
*phr
,
96 static void HPIMSGX__reset(u16 adapter_index
);
98 static u16
HPIMSGX__init(struct hpi_message
*phm
, struct hpi_response
*phr
);
99 static void HPIMSGX__cleanup(u16 adapter_index
, void *h_owner
);
101 #ifndef DISABLE_PRAGMA_PACK1
102 #pragma pack(push, 1)
105 struct hpi_subsys_response
{
106 struct hpi_response_header h
;
107 struct hpi_subsys_res s
;
110 struct hpi_adapter_response
{
111 struct hpi_response_header h
;
112 struct hpi_adapter_res a
;
115 struct hpi_mixer_response
{
116 struct hpi_response_header h
;
117 struct hpi_mixer_res m
;
120 struct hpi_stream_response
{
121 struct hpi_response_header h
;
122 struct hpi_stream_res d
;
125 struct adapter_info
{
131 struct asi_open_state
{
136 #ifndef DISABLE_PRAGMA_PACK1
141 static struct hpi_adapter_response rESP_HPI_ADAPTER_OPEN
[HPI_MAX_ADAPTERS
];
143 static struct hpi_stream_response
144 rESP_HPI_OSTREAM_OPEN
[HPI_MAX_ADAPTERS
][HPI_MAX_STREAMS
];
146 static struct hpi_stream_response
147 rESP_HPI_ISTREAM_OPEN
[HPI_MAX_ADAPTERS
][HPI_MAX_STREAMS
];
149 static struct hpi_mixer_response rESP_HPI_MIXER_OPEN
[HPI_MAX_ADAPTERS
];
151 static struct adapter_info aDAPTER_INFO
[HPI_MAX_ADAPTERS
];
153 /* use these to keep track of opens from user mode apps/DLLs */
154 static struct asi_open_state
155 outstream_user_open
[HPI_MAX_ADAPTERS
][HPI_MAX_STREAMS
];
157 static struct asi_open_state
158 instream_user_open
[HPI_MAX_ADAPTERS
][HPI_MAX_STREAMS
];
160 static void subsys_message(struct hpi_message
*phm
, struct hpi_response
*phr
,
163 if (phm
->adapter_index
!= HPI_ADAPTER_INDEX_INVALID
)
164 HPI_DEBUG_LOG(WARNING
,
165 "suspicious adapter index %d in subsys message 0x%x.\n",
166 phm
->adapter_index
, phm
->function
);
168 switch (phm
->function
) {
169 case HPI_SUBSYS_GET_VERSION
:
170 hpi_init_response(phr
, HPI_OBJ_SUBSYSTEM
,
171 HPI_SUBSYS_GET_VERSION
, 0);
172 phr
->u
.s
.version
= HPI_VER
>> 8; /* return major.minor */
173 phr
->u
.s
.data
= HPI_VER
; /* return major.minor.release */
175 case HPI_SUBSYS_OPEN
:
176 /*do not propagate the message down the chain */
177 hpi_init_response(phr
, HPI_OBJ_SUBSYSTEM
, HPI_SUBSYS_OPEN
, 0);
179 case HPI_SUBSYS_CLOSE
:
180 /*do not propagate the message down the chain */
181 hpi_init_response(phr
, HPI_OBJ_SUBSYSTEM
, HPI_SUBSYS_CLOSE
,
183 HPIMSGX__cleanup(HPIMSGX_ALLADAPTERS
, h_owner
);
185 case HPI_SUBSYS_DRIVER_LOAD
:
186 /* Initialize this module's internal state */
187 hpios_msgxlock_init(&msgx_lock
);
188 memset(&hpi_entry_points
, 0, sizeof(hpi_entry_points
));
189 hpios_locked_mem_init();
190 /* Init subsys_findadapters response to no-adapters */
191 HPIMSGX__reset(HPIMSGX_ALLADAPTERS
);
192 hpi_init_response(phr
, HPI_OBJ_SUBSYSTEM
,
193 HPI_SUBSYS_DRIVER_LOAD
, 0);
194 /* individual HPIs dont implement driver load */
195 HPI_COMMON(phm
, phr
);
197 case HPI_SUBSYS_DRIVER_UNLOAD
:
198 HPI_COMMON(phm
, phr
);
199 HPIMSGX__cleanup(HPIMSGX_ALLADAPTERS
, h_owner
);
200 hpios_locked_mem_free_all();
201 hpi_init_response(phr
, HPI_OBJ_SUBSYSTEM
,
202 HPI_SUBSYS_DRIVER_UNLOAD
, 0);
205 case HPI_SUBSYS_GET_NUM_ADAPTERS
:
206 case HPI_SUBSYS_GET_ADAPTER
:
207 HPI_COMMON(phm
, phr
);
210 case HPI_SUBSYS_CREATE_ADAPTER
:
211 HPIMSGX__init(phm
, phr
);
214 case HPI_SUBSYS_DELETE_ADAPTER
:
215 HPIMSGX__cleanup(phm
->obj_index
, h_owner
);
217 struct hpi_message hm
;
218 struct hpi_response hr
;
219 hpi_init_message_response(&hm
, &hr
, HPI_OBJ_ADAPTER
,
221 hm
.adapter_index
= phm
->obj_index
;
222 hw_entry_point(&hm
, &hr
);
224 if ((phm
->obj_index
< HPI_MAX_ADAPTERS
)
225 && hpi_entry_points
[phm
->obj_index
]) {
226 hpi_entry_points
[phm
->obj_index
] (phm
, phr
);
227 hpi_entry_points
[phm
->obj_index
] = NULL
;
229 phr
->error
= HPI_ERROR_INVALID_OBJ_INDEX
;
233 /* Must explicitly handle every subsys message in this switch */
234 hpi_init_response(phr
, HPI_OBJ_SUBSYSTEM
, phm
->function
,
235 HPI_ERROR_INVALID_FUNC
);
240 static void adapter_message(struct hpi_message
*phm
, struct hpi_response
*phr
,
243 switch (phm
->function
) {
244 case HPI_ADAPTER_OPEN
:
245 adapter_open(phm
, phr
);
247 case HPI_ADAPTER_CLOSE
:
248 adapter_close(phm
, phr
);
251 hw_entry_point(phm
, phr
);
256 static void mixer_message(struct hpi_message
*phm
, struct hpi_response
*phr
)
258 switch (phm
->function
) {
260 mixer_open(phm
, phr
);
262 case HPI_MIXER_CLOSE
:
263 mixer_close(phm
, phr
);
266 hw_entry_point(phm
, phr
);
271 static void outstream_message(struct hpi_message
*phm
,
272 struct hpi_response
*phr
, void *h_owner
)
274 if (phm
->obj_index
>= aDAPTER_INFO
[phm
->adapter_index
].num_outstreams
) {
275 hpi_init_response(phr
, HPI_OBJ_OSTREAM
, phm
->function
,
276 HPI_ERROR_INVALID_OBJ_INDEX
);
280 switch (phm
->function
) {
281 case HPI_OSTREAM_OPEN
:
282 outstream_open(phm
, phr
, h_owner
);
284 case HPI_OSTREAM_CLOSE
:
285 outstream_close(phm
, phr
, h_owner
);
288 hw_entry_point(phm
, phr
);
293 static void instream_message(struct hpi_message
*phm
,
294 struct hpi_response
*phr
, void *h_owner
)
296 if (phm
->obj_index
>= aDAPTER_INFO
[phm
->adapter_index
].num_instreams
) {
297 hpi_init_response(phr
, HPI_OBJ_ISTREAM
, phm
->function
,
298 HPI_ERROR_INVALID_OBJ_INDEX
);
302 switch (phm
->function
) {
303 case HPI_ISTREAM_OPEN
:
304 instream_open(phm
, phr
, h_owner
);
306 case HPI_ISTREAM_CLOSE
:
307 instream_close(phm
, phr
, h_owner
);
310 hw_entry_point(phm
, phr
);
315 /* NOTE: HPI_Message() must be defined in the driver as a wrapper for
316 * HPI_MessageEx so that functions in hpifunc.c compile.
318 void hpi_send_recv_ex(struct hpi_message
*phm
, struct hpi_response
*phr
,
321 HPI_DEBUG_MESSAGE(DEBUG
, phm
);
323 if (phm
->type
!= HPI_TYPE_MESSAGE
) {
324 hpi_init_response(phr
, phm
->object
, phm
->function
,
325 HPI_ERROR_INVALID_TYPE
);
329 if (phm
->adapter_index
>= HPI_MAX_ADAPTERS
330 && phm
->adapter_index
!= HPIMSGX_ALLADAPTERS
) {
331 hpi_init_response(phr
, phm
->object
, phm
->function
,
332 HPI_ERROR_BAD_ADAPTER_NUMBER
);
336 switch (phm
->object
) {
337 case HPI_OBJ_SUBSYSTEM
:
338 subsys_message(phm
, phr
, h_owner
);
341 case HPI_OBJ_ADAPTER
:
342 adapter_message(phm
, phr
, h_owner
);
346 mixer_message(phm
, phr
);
349 case HPI_OBJ_OSTREAM
:
350 outstream_message(phm
, phr
, h_owner
);
353 case HPI_OBJ_ISTREAM
:
354 instream_message(phm
, phr
, h_owner
);
358 hw_entry_point(phm
, phr
);
361 HPI_DEBUG_RESPONSE(phr
);
365 static void adapter_open(struct hpi_message
*phm
, struct hpi_response
*phr
)
367 HPI_DEBUG_LOG(VERBOSE
, "adapter_open\n");
368 memcpy(phr
, &rESP_HPI_ADAPTER_OPEN
[phm
->adapter_index
],
369 sizeof(rESP_HPI_ADAPTER_OPEN
[0]));
372 static void adapter_close(struct hpi_message
*phm
, struct hpi_response
*phr
)
374 HPI_DEBUG_LOG(VERBOSE
, "adapter_close\n");
375 hpi_init_response(phr
, HPI_OBJ_ADAPTER
, HPI_ADAPTER_CLOSE
, 0);
378 static void mixer_open(struct hpi_message
*phm
, struct hpi_response
*phr
)
380 memcpy(phr
, &rESP_HPI_MIXER_OPEN
[phm
->adapter_index
],
381 sizeof(rESP_HPI_MIXER_OPEN
[0]));
384 static void mixer_close(struct hpi_message
*phm
, struct hpi_response
*phr
)
386 hpi_init_response(phr
, HPI_OBJ_MIXER
, HPI_MIXER_CLOSE
, 0);
389 static void instream_open(struct hpi_message
*phm
, struct hpi_response
*phr
,
393 struct hpi_message hm
;
394 struct hpi_response hr
;
396 hpi_init_response(phr
, HPI_OBJ_ISTREAM
, HPI_ISTREAM_OPEN
, 0);
398 hpios_msgxlock_lock(&msgx_lock
);
400 if (instream_user_open
[phm
->adapter_index
][phm
->obj_index
].open_flag
)
401 phr
->error
= HPI_ERROR_OBJ_ALREADY_OPEN
;
402 else if (rESP_HPI_ISTREAM_OPEN
[phm
->adapter_index
]
403 [phm
->obj_index
].h
.error
)
405 &rESP_HPI_ISTREAM_OPEN
[phm
->adapter_index
][phm
->
407 sizeof(rESP_HPI_ISTREAM_OPEN
[0][0]));
409 instream_user_open
[phm
->adapter_index
][phm
->
410 obj_index
].open_flag
= 1;
411 hpios_msgxlock_unlock(&msgx_lock
);
414 hpi_init_message_response(&hm
, &hr
, HPI_OBJ_ISTREAM
,
416 hm
.adapter_index
= phm
->adapter_index
;
417 hm
.obj_index
= phm
->obj_index
;
418 hw_entry_point(&hm
, &hr
);
420 hpios_msgxlock_lock(&msgx_lock
);
422 instream_user_open
[phm
->adapter_index
][phm
->
423 obj_index
].open_flag
= 0;
424 phr
->error
= hr
.error
;
426 instream_user_open
[phm
->adapter_index
][phm
->
427 obj_index
].open_flag
= 1;
428 instream_user_open
[phm
->adapter_index
][phm
->
429 obj_index
].h_owner
= h_owner
;
431 &rESP_HPI_ISTREAM_OPEN
[phm
->adapter_index
]
433 sizeof(rESP_HPI_ISTREAM_OPEN
[0][0]));
436 hpios_msgxlock_unlock(&msgx_lock
);
439 static void instream_close(struct hpi_message
*phm
, struct hpi_response
*phr
,
443 struct hpi_message hm
;
444 struct hpi_response hr
;
446 hpi_init_response(phr
, HPI_OBJ_ISTREAM
, HPI_ISTREAM_CLOSE
, 0);
448 hpios_msgxlock_lock(&msgx_lock
);
450 instream_user_open
[phm
->adapter_index
][phm
->
451 obj_index
].h_owner
) {
452 /* HPI_DEBUG_LOG(INFO,"closing adapter %d "
453 "instream %d owned by %p\n",
454 phm->wAdapterIndex, phm->wObjIndex, hOwner); */
455 instream_user_open
[phm
->adapter_index
][phm
->
456 obj_index
].h_owner
= NULL
;
457 hpios_msgxlock_unlock(&msgx_lock
);
459 hpi_init_message_response(&hm
, &hr
, HPI_OBJ_ISTREAM
,
461 hm
.adapter_index
= phm
->adapter_index
;
462 hm
.obj_index
= phm
->obj_index
;
463 hw_entry_point(&hm
, &hr
);
464 hpios_msgxlock_lock(&msgx_lock
);
466 instream_user_open
[phm
->adapter_index
][phm
->
467 obj_index
].h_owner
= h_owner
;
468 phr
->error
= hr
.error
;
470 instream_user_open
[phm
->adapter_index
][phm
->
471 obj_index
].open_flag
= 0;
472 instream_user_open
[phm
->adapter_index
][phm
->
473 obj_index
].h_owner
= NULL
;
476 HPI_DEBUG_LOG(WARNING
,
477 "%p trying to close %d instream %d owned by %p\n",
478 h_owner
, phm
->adapter_index
, phm
->obj_index
,
479 instream_user_open
[phm
->adapter_index
][phm
->
481 phr
->error
= HPI_ERROR_OBJ_NOT_OPEN
;
483 hpios_msgxlock_unlock(&msgx_lock
);
486 static void outstream_open(struct hpi_message
*phm
, struct hpi_response
*phr
,
490 struct hpi_message hm
;
491 struct hpi_response hr
;
493 hpi_init_response(phr
, HPI_OBJ_OSTREAM
, HPI_OSTREAM_OPEN
, 0);
495 hpios_msgxlock_lock(&msgx_lock
);
497 if (outstream_user_open
[phm
->adapter_index
][phm
->obj_index
].open_flag
)
498 phr
->error
= HPI_ERROR_OBJ_ALREADY_OPEN
;
499 else if (rESP_HPI_OSTREAM_OPEN
[phm
->adapter_index
]
500 [phm
->obj_index
].h
.error
)
502 &rESP_HPI_OSTREAM_OPEN
[phm
->adapter_index
][phm
->
504 sizeof(rESP_HPI_OSTREAM_OPEN
[0][0]));
506 outstream_user_open
[phm
->adapter_index
][phm
->
507 obj_index
].open_flag
= 1;
508 hpios_msgxlock_unlock(&msgx_lock
);
511 hpi_init_message_response(&hm
, &hr
, HPI_OBJ_OSTREAM
,
513 hm
.adapter_index
= phm
->adapter_index
;
514 hm
.obj_index
= phm
->obj_index
;
515 hw_entry_point(&hm
, &hr
);
517 hpios_msgxlock_lock(&msgx_lock
);
519 outstream_user_open
[phm
->adapter_index
][phm
->
520 obj_index
].open_flag
= 0;
521 phr
->error
= hr
.error
;
523 outstream_user_open
[phm
->adapter_index
][phm
->
524 obj_index
].open_flag
= 1;
525 outstream_user_open
[phm
->adapter_index
][phm
->
526 obj_index
].h_owner
= h_owner
;
528 &rESP_HPI_OSTREAM_OPEN
[phm
->adapter_index
]
530 sizeof(rESP_HPI_OSTREAM_OPEN
[0][0]));
533 hpios_msgxlock_unlock(&msgx_lock
);
536 static void outstream_close(struct hpi_message
*phm
, struct hpi_response
*phr
,
540 struct hpi_message hm
;
541 struct hpi_response hr
;
543 hpi_init_response(phr
, HPI_OBJ_OSTREAM
, HPI_OSTREAM_CLOSE
, 0);
545 hpios_msgxlock_lock(&msgx_lock
);
548 outstream_user_open
[phm
->adapter_index
][phm
->
549 obj_index
].h_owner
) {
550 /* HPI_DEBUG_LOG(INFO,"closing adapter %d "
551 "outstream %d owned by %p\n",
552 phm->wAdapterIndex, phm->wObjIndex, hOwner); */
553 outstream_user_open
[phm
->adapter_index
][phm
->
554 obj_index
].h_owner
= NULL
;
555 hpios_msgxlock_unlock(&msgx_lock
);
557 hpi_init_message_response(&hm
, &hr
, HPI_OBJ_OSTREAM
,
559 hm
.adapter_index
= phm
->adapter_index
;
560 hm
.obj_index
= phm
->obj_index
;
561 hw_entry_point(&hm
, &hr
);
562 hpios_msgxlock_lock(&msgx_lock
);
564 outstream_user_open
[phm
->adapter_index
][phm
->
565 obj_index
].h_owner
= h_owner
;
566 phr
->error
= hr
.error
;
568 outstream_user_open
[phm
->adapter_index
][phm
->
569 obj_index
].open_flag
= 0;
570 outstream_user_open
[phm
->adapter_index
][phm
->
571 obj_index
].h_owner
= NULL
;
574 HPI_DEBUG_LOG(WARNING
,
575 "%p trying to close %d outstream %d owned by %p\n",
576 h_owner
, phm
->adapter_index
, phm
->obj_index
,
577 outstream_user_open
[phm
->adapter_index
][phm
->
579 phr
->error
= HPI_ERROR_OBJ_NOT_OPEN
;
581 hpios_msgxlock_unlock(&msgx_lock
);
584 static u16
adapter_prepare(u16 adapter
)
586 struct hpi_message hm
;
587 struct hpi_response hr
;
589 /* Open the adapter and streams */
592 /* call to HPI_ADAPTER_OPEN */
593 hpi_init_message_response(&hm
, &hr
, HPI_OBJ_ADAPTER
,
595 hm
.adapter_index
= adapter
;
596 hw_entry_point(&hm
, &hr
);
597 memcpy(&rESP_HPI_ADAPTER_OPEN
[adapter
], &hr
,
598 sizeof(rESP_HPI_ADAPTER_OPEN
[0]));
602 /* call to HPI_ADAPTER_GET_INFO */
603 hpi_init_message_response(&hm
, &hr
, HPI_OBJ_ADAPTER
,
604 HPI_ADAPTER_GET_INFO
);
605 hm
.adapter_index
= adapter
;
606 hw_entry_point(&hm
, &hr
);
610 aDAPTER_INFO
[adapter
].num_outstreams
= hr
.u
.ax
.info
.num_outstreams
;
611 aDAPTER_INFO
[adapter
].num_instreams
= hr
.u
.ax
.info
.num_instreams
;
612 aDAPTER_INFO
[adapter
].type
= hr
.u
.ax
.info
.adapter_type
;
614 /* call to HPI_OSTREAM_OPEN */
615 for (i
= 0; i
< aDAPTER_INFO
[adapter
].num_outstreams
; i
++) {
616 hpi_init_message_response(&hm
, &hr
, HPI_OBJ_OSTREAM
,
618 hm
.adapter_index
= adapter
;
620 hw_entry_point(&hm
, &hr
);
621 memcpy(&rESP_HPI_OSTREAM_OPEN
[adapter
][i
], &hr
,
622 sizeof(rESP_HPI_OSTREAM_OPEN
[0][0]));
623 outstream_user_open
[adapter
][i
].open_flag
= 0;
624 outstream_user_open
[adapter
][i
].h_owner
= NULL
;
627 /* call to HPI_ISTREAM_OPEN */
628 for (i
= 0; i
< aDAPTER_INFO
[adapter
].num_instreams
; i
++) {
629 hpi_init_message_response(&hm
, &hr
, HPI_OBJ_ISTREAM
,
631 hm
.adapter_index
= adapter
;
633 hw_entry_point(&hm
, &hr
);
634 memcpy(&rESP_HPI_ISTREAM_OPEN
[adapter
][i
], &hr
,
635 sizeof(rESP_HPI_ISTREAM_OPEN
[0][0]));
636 instream_user_open
[adapter
][i
].open_flag
= 0;
637 instream_user_open
[adapter
][i
].h_owner
= NULL
;
640 /* call to HPI_MIXER_OPEN */
641 hpi_init_message_response(&hm
, &hr
, HPI_OBJ_MIXER
, HPI_MIXER_OPEN
);
642 hm
.adapter_index
= adapter
;
643 hw_entry_point(&hm
, &hr
);
644 memcpy(&rESP_HPI_MIXER_OPEN
[adapter
], &hr
,
645 sizeof(rESP_HPI_MIXER_OPEN
[0]));
650 static void HPIMSGX__reset(u16 adapter_index
)
654 struct hpi_response hr
;
656 if (adapter_index
== HPIMSGX_ALLADAPTERS
) {
657 for (adapter
= 0; adapter
< HPI_MAX_ADAPTERS
; adapter
++) {
659 hpi_init_response(&hr
, HPI_OBJ_ADAPTER
,
660 HPI_ADAPTER_OPEN
, HPI_ERROR_BAD_ADAPTER
);
661 memcpy(&rESP_HPI_ADAPTER_OPEN
[adapter
], &hr
,
662 sizeof(rESP_HPI_ADAPTER_OPEN
[adapter
]));
664 hpi_init_response(&hr
, HPI_OBJ_MIXER
, HPI_MIXER_OPEN
,
665 HPI_ERROR_INVALID_OBJ
);
666 memcpy(&rESP_HPI_MIXER_OPEN
[adapter
], &hr
,
667 sizeof(rESP_HPI_MIXER_OPEN
[adapter
]));
669 for (i
= 0; i
< HPI_MAX_STREAMS
; i
++) {
670 hpi_init_response(&hr
, HPI_OBJ_OSTREAM
,
672 HPI_ERROR_INVALID_OBJ
);
673 memcpy(&rESP_HPI_OSTREAM_OPEN
[adapter
][i
],
675 sizeof(rESP_HPI_OSTREAM_OPEN
[adapter
]
677 hpi_init_response(&hr
, HPI_OBJ_ISTREAM
,
679 HPI_ERROR_INVALID_OBJ
);
680 memcpy(&rESP_HPI_ISTREAM_OPEN
[adapter
][i
],
682 sizeof(rESP_HPI_ISTREAM_OPEN
[adapter
]
686 } else if (adapter_index
< HPI_MAX_ADAPTERS
) {
687 rESP_HPI_ADAPTER_OPEN
[adapter_index
].h
.error
=
688 HPI_ERROR_BAD_ADAPTER
;
689 rESP_HPI_MIXER_OPEN
[adapter_index
].h
.error
=
690 HPI_ERROR_INVALID_OBJ
;
691 for (i
= 0; i
< HPI_MAX_STREAMS
; i
++) {
692 rESP_HPI_OSTREAM_OPEN
[adapter_index
][i
].h
.error
=
693 HPI_ERROR_INVALID_OBJ
;
694 rESP_HPI_ISTREAM_OPEN
[adapter_index
][i
].h
.error
=
695 HPI_ERROR_INVALID_OBJ
;
700 static u16
HPIMSGX__init(struct hpi_message
*phm
,
701 /* HPI_SUBSYS_CREATE_ADAPTER structure with */
702 /* resource list or NULL=find all */
703 struct hpi_response
*phr
704 /* response from HPI_ADAPTER_GET_INFO */
707 hpi_handler_func
*entry_point_func
;
708 struct hpi_response hr
;
710 /* Init response here so we can pass in previous adapter list */
711 hpi_init_response(&hr
, phm
->object
, phm
->function
,
712 HPI_ERROR_INVALID_OBJ
);
715 hpi_lookup_entry_point_function(phm
->u
.s
.resource
.r
.pci
);
717 if (entry_point_func
) {
718 HPI_DEBUG_MESSAGE(DEBUG
, phm
);
719 entry_point_func(phm
, &hr
);
721 phr
->error
= HPI_ERROR_PROCESSING_MESSAGE
;
725 /* the adapter was created succesfully
726 save the mapping for future use */
727 hpi_entry_points
[hr
.u
.s
.adapter_index
] = entry_point_func
;
728 /* prepare adapter (pre-open streams etc.) */
730 "HPI_SUBSYS_CREATE_ADAPTER successful,"
731 " preparing adapter\n");
732 adapter_prepare(hr
.u
.s
.adapter_index
);
734 memcpy(phr
, &hr
, hr
.size
);
738 static void HPIMSGX__cleanup(u16 adapter_index
, void *h_owner
)
740 int i
, adapter
, adapter_limit
;
745 if (adapter_index
== HPIMSGX_ALLADAPTERS
) {
747 adapter_limit
= HPI_MAX_ADAPTERS
;
749 adapter
= adapter_index
;
750 adapter_limit
= adapter
+ 1;
753 for (; adapter
< adapter_limit
; adapter
++) {
754 /* printk(KERN_INFO "Cleanup adapter #%d\n",wAdapter); */
755 for (i
= 0; i
< HPI_MAX_STREAMS
; i
++) {
757 outstream_user_open
[adapter
][i
].h_owner
) {
758 struct hpi_message hm
;
759 struct hpi_response hr
;
762 "Close adapter %d ostream %d\n",
765 hpi_init_message_response(&hm
, &hr
,
766 HPI_OBJ_OSTREAM
, HPI_OSTREAM_RESET
);
767 hm
.adapter_index
= (u16
)adapter
;
768 hm
.obj_index
= (u16
)i
;
769 hw_entry_point(&hm
, &hr
);
771 hm
.function
= HPI_OSTREAM_HOSTBUFFER_FREE
;
772 hw_entry_point(&hm
, &hr
);
774 hm
.function
= HPI_OSTREAM_GROUP_RESET
;
775 hw_entry_point(&hm
, &hr
);
777 outstream_user_open
[adapter
][i
].open_flag
= 0;
778 outstream_user_open
[adapter
][i
].h_owner
=
781 if (h_owner
== instream_user_open
[adapter
][i
].h_owner
) {
782 struct hpi_message hm
;
783 struct hpi_response hr
;
786 "Close adapter %d istream %d\n",
789 hpi_init_message_response(&hm
, &hr
,
790 HPI_OBJ_ISTREAM
, HPI_ISTREAM_RESET
);
791 hm
.adapter_index
= (u16
)adapter
;
792 hm
.obj_index
= (u16
)i
;
793 hw_entry_point(&hm
, &hr
);
795 hm
.function
= HPI_ISTREAM_HOSTBUFFER_FREE
;
796 hw_entry_point(&hm
, &hr
);
798 hm
.function
= HPI_ISTREAM_GROUP_RESET
;
799 hw_entry_point(&hm
, &hr
);
801 instream_user_open
[adapter
][i
].open_flag
= 0;
802 instream_user_open
[adapter
][i
].h_owner
= NULL
;