hpimsgx.c 21 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801
  1. /******************************************************************************
  2. AudioScience HPI driver
  3. Copyright (C) 1997-2010 AudioScience Inc. <support@audioscience.com>
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of version 2 of the GNU General Public License as
  6. published by the Free Software Foundation;
  7. This program is distributed in the hope that it will be useful,
  8. but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. GNU General Public License for more details.
  11. You should have received a copy of the GNU General Public License
  12. along with this program; if not, write to the Free Software
  13. Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
  14. Extended Message Function With Response Cacheing
  15. (C) Copyright AudioScience Inc. 2002
  16. *****************************************************************************/
  17. #define SOURCEFILE_NAME "hpimsgx.c"
  18. #include "hpi_internal.h"
  19. #include "hpimsginit.h"
  20. #include "hpicmn.h"
  21. #include "hpimsgx.h"
  22. #include "hpidebug.h"
  23. static struct pci_device_id asihpi_pci_tbl[] = {
  24. #include "hpipcida.h"
  25. };
  26. static struct hpios_spinlock msgx_lock;
  27. static hpi_handler_func *hpi_entry_points[HPI_MAX_ADAPTERS];
  28. static hpi_handler_func *hpi_lookup_entry_point_function(const struct hpi_pci
  29. *pci_info)
  30. {
  31. int i;
  32. for (i = 0; asihpi_pci_tbl[i].vendor != 0; i++) {
  33. if (asihpi_pci_tbl[i].vendor != PCI_ANY_ID
  34. && asihpi_pci_tbl[i].vendor !=
  35. pci_info->pci_dev->vendor)
  36. continue;
  37. if (asihpi_pci_tbl[i].device != PCI_ANY_ID
  38. && asihpi_pci_tbl[i].device !=
  39. pci_info->pci_dev->device)
  40. continue;
  41. if (asihpi_pci_tbl[i].subvendor != PCI_ANY_ID
  42. && asihpi_pci_tbl[i].subvendor !=
  43. pci_info->pci_dev->subsystem_vendor)
  44. continue;
  45. if (asihpi_pci_tbl[i].subdevice != PCI_ANY_ID
  46. && asihpi_pci_tbl[i].subdevice !=
  47. pci_info->pci_dev->subsystem_device)
  48. continue;
  49. /* HPI_DEBUG_LOG(DEBUG, " %x,%lx\n", i,
  50. asihpi_pci_tbl[i].driver_data); */
  51. return (hpi_handler_func *) asihpi_pci_tbl[i].driver_data;
  52. }
  53. return NULL;
  54. }
  55. static inline void hw_entry_point(struct hpi_message *phm,
  56. struct hpi_response *phr)
  57. {
  58. if ((phm->adapter_index < HPI_MAX_ADAPTERS)
  59. && hpi_entry_points[phm->adapter_index])
  60. hpi_entry_points[phm->adapter_index] (phm, phr);
  61. else
  62. hpi_init_response(phr, phm->object, phm->function,
  63. HPI_ERROR_PROCESSING_MESSAGE);
  64. }
  65. static void adapter_open(struct hpi_message *phm, struct hpi_response *phr);
  66. static void adapter_close(struct hpi_message *phm, struct hpi_response *phr);
  67. static void mixer_open(struct hpi_message *phm, struct hpi_response *phr);
  68. static void mixer_close(struct hpi_message *phm, struct hpi_response *phr);
  69. static void outstream_open(struct hpi_message *phm, struct hpi_response *phr,
  70. void *h_owner);
  71. static void outstream_close(struct hpi_message *phm, struct hpi_response *phr,
  72. void *h_owner);
  73. static void instream_open(struct hpi_message *phm, struct hpi_response *phr,
  74. void *h_owner);
  75. static void instream_close(struct hpi_message *phm, struct hpi_response *phr,
  76. void *h_owner);
  77. static void HPIMSGX__reset(u16 adapter_index);
  78. static u16 HPIMSGX__init(struct hpi_message *phm, struct hpi_response *phr);
  79. static void HPIMSGX__cleanup(u16 adapter_index, void *h_owner);
  80. #ifndef DISABLE_PRAGMA_PACK1
  81. #pragma pack(push, 1)
  82. #endif
  83. struct hpi_subsys_response {
  84. struct hpi_response_header h;
  85. struct hpi_subsys_res s;
  86. };
  87. struct hpi_adapter_response {
  88. struct hpi_response_header h;
  89. struct hpi_adapter_res a;
  90. };
  91. struct hpi_mixer_response {
  92. struct hpi_response_header h;
  93. struct hpi_mixer_res m;
  94. };
  95. struct hpi_stream_response {
  96. struct hpi_response_header h;
  97. struct hpi_stream_res d;
  98. };
  99. struct adapter_info {
  100. u16 type;
  101. u16 num_instreams;
  102. u16 num_outstreams;
  103. };
  104. struct asi_open_state {
  105. int open_flag;
  106. void *h_owner;
  107. };
  108. #ifndef DISABLE_PRAGMA_PACK1
  109. #pragma pack(pop)
  110. #endif
  111. /* Globals */
  112. static struct hpi_adapter_response rESP_HPI_ADAPTER_OPEN[HPI_MAX_ADAPTERS];
  113. static struct hpi_stream_response
  114. rESP_HPI_OSTREAM_OPEN[HPI_MAX_ADAPTERS][HPI_MAX_STREAMS];
  115. static struct hpi_stream_response
  116. rESP_HPI_ISTREAM_OPEN[HPI_MAX_ADAPTERS][HPI_MAX_STREAMS];
  117. static struct hpi_mixer_response rESP_HPI_MIXER_OPEN[HPI_MAX_ADAPTERS];
  118. static struct adapter_info aDAPTER_INFO[HPI_MAX_ADAPTERS];
  119. /* use these to keep track of opens from user mode apps/DLLs */
  120. static struct asi_open_state
  121. outstream_user_open[HPI_MAX_ADAPTERS][HPI_MAX_STREAMS];
  122. static struct asi_open_state
  123. instream_user_open[HPI_MAX_ADAPTERS][HPI_MAX_STREAMS];
  124. static void subsys_message(struct hpi_message *phm, struct hpi_response *phr,
  125. void *h_owner)
  126. {
  127. if (phm->adapter_index != HPI_ADAPTER_INDEX_INVALID)
  128. HPI_DEBUG_LOG(WARNING,
  129. "suspicious adapter index %d in subsys message 0x%x.\n",
  130. phm->adapter_index, phm->function);
  131. switch (phm->function) {
  132. case HPI_SUBSYS_GET_VERSION:
  133. hpi_init_response(phr, HPI_OBJ_SUBSYSTEM,
  134. HPI_SUBSYS_GET_VERSION, 0);
  135. phr->u.s.version = HPI_VER >> 8; /* return major.minor */
  136. phr->u.s.data = HPI_VER; /* return major.minor.release */
  137. break;
  138. case HPI_SUBSYS_OPEN:
  139. /*do not propagate the message down the chain */
  140. hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, HPI_SUBSYS_OPEN, 0);
  141. break;
  142. case HPI_SUBSYS_CLOSE:
  143. /*do not propagate the message down the chain */
  144. hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, HPI_SUBSYS_CLOSE,
  145. 0);
  146. HPIMSGX__cleanup(HPIMSGX_ALLADAPTERS, h_owner);
  147. break;
  148. case HPI_SUBSYS_DRIVER_LOAD:
  149. /* Initialize this module's internal state */
  150. hpios_msgxlock_init(&msgx_lock);
  151. memset(&hpi_entry_points, 0, sizeof(hpi_entry_points));
  152. hpios_locked_mem_init();
  153. /* Init subsys_findadapters response to no-adapters */
  154. HPIMSGX__reset(HPIMSGX_ALLADAPTERS);
  155. hpi_init_response(phr, HPI_OBJ_SUBSYSTEM,
  156. HPI_SUBSYS_DRIVER_LOAD, 0);
  157. /* individual HPIs dont implement driver load */
  158. HPI_COMMON(phm, phr);
  159. break;
  160. case HPI_SUBSYS_DRIVER_UNLOAD:
  161. HPI_COMMON(phm, phr);
  162. HPIMSGX__cleanup(HPIMSGX_ALLADAPTERS, h_owner);
  163. hpios_locked_mem_free_all();
  164. hpi_init_response(phr, HPI_OBJ_SUBSYSTEM,
  165. HPI_SUBSYS_DRIVER_UNLOAD, 0);
  166. return;
  167. case HPI_SUBSYS_GET_NUM_ADAPTERS:
  168. case HPI_SUBSYS_GET_ADAPTER:
  169. HPI_COMMON(phm, phr);
  170. break;
  171. case HPI_SUBSYS_CREATE_ADAPTER:
  172. HPIMSGX__init(phm, phr);
  173. break;
  174. default:
  175. /* Must explicitly handle every subsys message in this switch */
  176. hpi_init_response(phr, HPI_OBJ_SUBSYSTEM, phm->function,
  177. HPI_ERROR_INVALID_FUNC);
  178. break;
  179. }
  180. }
  181. static void adapter_message(struct hpi_message *phm, struct hpi_response *phr,
  182. void *h_owner)
  183. {
  184. switch (phm->function) {
  185. case HPI_ADAPTER_OPEN:
  186. adapter_open(phm, phr);
  187. break;
  188. case HPI_ADAPTER_CLOSE:
  189. adapter_close(phm, phr);
  190. break;
  191. case HPI_ADAPTER_DELETE:
  192. HPIMSGX__cleanup(phm->adapter_index, h_owner);
  193. {
  194. struct hpi_message hm;
  195. struct hpi_response hr;
  196. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  197. HPI_ADAPTER_CLOSE);
  198. hm.adapter_index = phm->adapter_index;
  199. hw_entry_point(&hm, &hr);
  200. }
  201. hw_entry_point(phm, phr);
  202. break;
  203. default:
  204. hw_entry_point(phm, phr);
  205. break;
  206. }
  207. }
  208. static void mixer_message(struct hpi_message *phm, struct hpi_response *phr)
  209. {
  210. switch (phm->function) {
  211. case HPI_MIXER_OPEN:
  212. mixer_open(phm, phr);
  213. break;
  214. case HPI_MIXER_CLOSE:
  215. mixer_close(phm, phr);
  216. break;
  217. default:
  218. hw_entry_point(phm, phr);
  219. break;
  220. }
  221. }
  222. static void outstream_message(struct hpi_message *phm,
  223. struct hpi_response *phr, void *h_owner)
  224. {
  225. if (phm->obj_index >= aDAPTER_INFO[phm->adapter_index].num_outstreams) {
  226. hpi_init_response(phr, HPI_OBJ_OSTREAM, phm->function,
  227. HPI_ERROR_INVALID_OBJ_INDEX);
  228. return;
  229. }
  230. switch (phm->function) {
  231. case HPI_OSTREAM_OPEN:
  232. outstream_open(phm, phr, h_owner);
  233. break;
  234. case HPI_OSTREAM_CLOSE:
  235. outstream_close(phm, phr, h_owner);
  236. break;
  237. default:
  238. hw_entry_point(phm, phr);
  239. break;
  240. }
  241. }
  242. static void instream_message(struct hpi_message *phm,
  243. struct hpi_response *phr, void *h_owner)
  244. {
  245. if (phm->obj_index >= aDAPTER_INFO[phm->adapter_index].num_instreams) {
  246. hpi_init_response(phr, HPI_OBJ_ISTREAM, phm->function,
  247. HPI_ERROR_INVALID_OBJ_INDEX);
  248. return;
  249. }
  250. switch (phm->function) {
  251. case HPI_ISTREAM_OPEN:
  252. instream_open(phm, phr, h_owner);
  253. break;
  254. case HPI_ISTREAM_CLOSE:
  255. instream_close(phm, phr, h_owner);
  256. break;
  257. default:
  258. hw_entry_point(phm, phr);
  259. break;
  260. }
  261. }
  262. /* NOTE: HPI_Message() must be defined in the driver as a wrapper for
  263. * HPI_MessageEx so that functions in hpifunc.c compile.
  264. */
  265. void hpi_send_recv_ex(struct hpi_message *phm, struct hpi_response *phr,
  266. void *h_owner)
  267. {
  268. HPI_DEBUG_MESSAGE(DEBUG, phm);
  269. if (phm->type != HPI_TYPE_MESSAGE) {
  270. hpi_init_response(phr, phm->object, phm->function,
  271. HPI_ERROR_INVALID_TYPE);
  272. return;
  273. }
  274. if (phm->adapter_index >= HPI_MAX_ADAPTERS
  275. && phm->adapter_index != HPIMSGX_ALLADAPTERS) {
  276. hpi_init_response(phr, phm->object, phm->function,
  277. HPI_ERROR_BAD_ADAPTER_NUMBER);
  278. return;
  279. }
  280. switch (phm->object) {
  281. case HPI_OBJ_SUBSYSTEM:
  282. subsys_message(phm, phr, h_owner);
  283. break;
  284. case HPI_OBJ_ADAPTER:
  285. adapter_message(phm, phr, h_owner);
  286. break;
  287. case HPI_OBJ_MIXER:
  288. mixer_message(phm, phr);
  289. break;
  290. case HPI_OBJ_OSTREAM:
  291. outstream_message(phm, phr, h_owner);
  292. break;
  293. case HPI_OBJ_ISTREAM:
  294. instream_message(phm, phr, h_owner);
  295. break;
  296. default:
  297. hw_entry_point(phm, phr);
  298. break;
  299. }
  300. HPI_DEBUG_RESPONSE(phr);
  301. }
  302. static void adapter_open(struct hpi_message *phm, struct hpi_response *phr)
  303. {
  304. HPI_DEBUG_LOG(VERBOSE, "adapter_open\n");
  305. memcpy(phr, &rESP_HPI_ADAPTER_OPEN[phm->adapter_index],
  306. sizeof(rESP_HPI_ADAPTER_OPEN[0]));
  307. }
  308. static void adapter_close(struct hpi_message *phm, struct hpi_response *phr)
  309. {
  310. HPI_DEBUG_LOG(VERBOSE, "adapter_close\n");
  311. hpi_init_response(phr, HPI_OBJ_ADAPTER, HPI_ADAPTER_CLOSE, 0);
  312. }
  313. static void mixer_open(struct hpi_message *phm, struct hpi_response *phr)
  314. {
  315. memcpy(phr, &rESP_HPI_MIXER_OPEN[phm->adapter_index],
  316. sizeof(rESP_HPI_MIXER_OPEN[0]));
  317. }
  318. static void mixer_close(struct hpi_message *phm, struct hpi_response *phr)
  319. {
  320. hpi_init_response(phr, HPI_OBJ_MIXER, HPI_MIXER_CLOSE, 0);
  321. }
  322. static void instream_open(struct hpi_message *phm, struct hpi_response *phr,
  323. void *h_owner)
  324. {
  325. struct hpi_message hm;
  326. struct hpi_response hr;
  327. hpi_init_response(phr, HPI_OBJ_ISTREAM, HPI_ISTREAM_OPEN, 0);
  328. hpios_msgxlock_lock(&msgx_lock);
  329. if (instream_user_open[phm->adapter_index][phm->obj_index].open_flag)
  330. phr->error = HPI_ERROR_OBJ_ALREADY_OPEN;
  331. else if (rESP_HPI_ISTREAM_OPEN[phm->adapter_index]
  332. [phm->obj_index].h.error)
  333. memcpy(phr,
  334. &rESP_HPI_ISTREAM_OPEN[phm->adapter_index][phm->
  335. obj_index],
  336. sizeof(rESP_HPI_ISTREAM_OPEN[0][0]));
  337. else {
  338. instream_user_open[phm->adapter_index][phm->
  339. obj_index].open_flag = 1;
  340. hpios_msgxlock_unlock(&msgx_lock);
  341. /* issue a reset */
  342. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  343. HPI_ISTREAM_RESET);
  344. hm.adapter_index = phm->adapter_index;
  345. hm.obj_index = phm->obj_index;
  346. hw_entry_point(&hm, &hr);
  347. hpios_msgxlock_lock(&msgx_lock);
  348. if (hr.error) {
  349. instream_user_open[phm->adapter_index][phm->
  350. obj_index].open_flag = 0;
  351. phr->error = hr.error;
  352. } else {
  353. instream_user_open[phm->adapter_index][phm->
  354. obj_index].open_flag = 1;
  355. instream_user_open[phm->adapter_index][phm->
  356. obj_index].h_owner = h_owner;
  357. memcpy(phr,
  358. &rESP_HPI_ISTREAM_OPEN[phm->adapter_index]
  359. [phm->obj_index],
  360. sizeof(rESP_HPI_ISTREAM_OPEN[0][0]));
  361. }
  362. }
  363. hpios_msgxlock_unlock(&msgx_lock);
  364. }
  365. static void instream_close(struct hpi_message *phm, struct hpi_response *phr,
  366. void *h_owner)
  367. {
  368. struct hpi_message hm;
  369. struct hpi_response hr;
  370. hpi_init_response(phr, HPI_OBJ_ISTREAM, HPI_ISTREAM_CLOSE, 0);
  371. hpios_msgxlock_lock(&msgx_lock);
  372. if (h_owner ==
  373. instream_user_open[phm->adapter_index][phm->
  374. obj_index].h_owner) {
  375. /* HPI_DEBUG_LOG(INFO,"closing adapter %d "
  376. "instream %d owned by %p\n",
  377. phm->wAdapterIndex, phm->wObjIndex, hOwner); */
  378. instream_user_open[phm->adapter_index][phm->
  379. obj_index].h_owner = NULL;
  380. hpios_msgxlock_unlock(&msgx_lock);
  381. /* issue a reset */
  382. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  383. HPI_ISTREAM_RESET);
  384. hm.adapter_index = phm->adapter_index;
  385. hm.obj_index = phm->obj_index;
  386. hw_entry_point(&hm, &hr);
  387. hpios_msgxlock_lock(&msgx_lock);
  388. if (hr.error) {
  389. instream_user_open[phm->adapter_index][phm->
  390. obj_index].h_owner = h_owner;
  391. phr->error = hr.error;
  392. } else {
  393. instream_user_open[phm->adapter_index][phm->
  394. obj_index].open_flag = 0;
  395. instream_user_open[phm->adapter_index][phm->
  396. obj_index].h_owner = NULL;
  397. }
  398. } else {
  399. HPI_DEBUG_LOG(WARNING,
  400. "%p trying to close %d instream %d owned by %p\n",
  401. h_owner, phm->adapter_index, phm->obj_index,
  402. instream_user_open[phm->adapter_index][phm->
  403. obj_index].h_owner);
  404. phr->error = HPI_ERROR_OBJ_NOT_OPEN;
  405. }
  406. hpios_msgxlock_unlock(&msgx_lock);
  407. }
  408. static void outstream_open(struct hpi_message *phm, struct hpi_response *phr,
  409. void *h_owner)
  410. {
  411. struct hpi_message hm;
  412. struct hpi_response hr;
  413. hpi_init_response(phr, HPI_OBJ_OSTREAM, HPI_OSTREAM_OPEN, 0);
  414. hpios_msgxlock_lock(&msgx_lock);
  415. if (outstream_user_open[phm->adapter_index][phm->obj_index].open_flag)
  416. phr->error = HPI_ERROR_OBJ_ALREADY_OPEN;
  417. else if (rESP_HPI_OSTREAM_OPEN[phm->adapter_index]
  418. [phm->obj_index].h.error)
  419. memcpy(phr,
  420. &rESP_HPI_OSTREAM_OPEN[phm->adapter_index][phm->
  421. obj_index],
  422. sizeof(rESP_HPI_OSTREAM_OPEN[0][0]));
  423. else {
  424. outstream_user_open[phm->adapter_index][phm->
  425. obj_index].open_flag = 1;
  426. hpios_msgxlock_unlock(&msgx_lock);
  427. /* issue a reset */
  428. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  429. HPI_OSTREAM_RESET);
  430. hm.adapter_index = phm->adapter_index;
  431. hm.obj_index = phm->obj_index;
  432. hw_entry_point(&hm, &hr);
  433. hpios_msgxlock_lock(&msgx_lock);
  434. if (hr.error) {
  435. outstream_user_open[phm->adapter_index][phm->
  436. obj_index].open_flag = 0;
  437. phr->error = hr.error;
  438. } else {
  439. outstream_user_open[phm->adapter_index][phm->
  440. obj_index].open_flag = 1;
  441. outstream_user_open[phm->adapter_index][phm->
  442. obj_index].h_owner = h_owner;
  443. memcpy(phr,
  444. &rESP_HPI_OSTREAM_OPEN[phm->adapter_index]
  445. [phm->obj_index],
  446. sizeof(rESP_HPI_OSTREAM_OPEN[0][0]));
  447. }
  448. }
  449. hpios_msgxlock_unlock(&msgx_lock);
  450. }
  451. static void outstream_close(struct hpi_message *phm, struct hpi_response *phr,
  452. void *h_owner)
  453. {
  454. struct hpi_message hm;
  455. struct hpi_response hr;
  456. hpi_init_response(phr, HPI_OBJ_OSTREAM, HPI_OSTREAM_CLOSE, 0);
  457. hpios_msgxlock_lock(&msgx_lock);
  458. if (h_owner ==
  459. outstream_user_open[phm->adapter_index][phm->
  460. obj_index].h_owner) {
  461. /* HPI_DEBUG_LOG(INFO,"closing adapter %d "
  462. "outstream %d owned by %p\n",
  463. phm->wAdapterIndex, phm->wObjIndex, hOwner); */
  464. outstream_user_open[phm->adapter_index][phm->
  465. obj_index].h_owner = NULL;
  466. hpios_msgxlock_unlock(&msgx_lock);
  467. /* issue a reset */
  468. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  469. HPI_OSTREAM_RESET);
  470. hm.adapter_index = phm->adapter_index;
  471. hm.obj_index = phm->obj_index;
  472. hw_entry_point(&hm, &hr);
  473. hpios_msgxlock_lock(&msgx_lock);
  474. if (hr.error) {
  475. outstream_user_open[phm->adapter_index][phm->
  476. obj_index].h_owner = h_owner;
  477. phr->error = hr.error;
  478. } else {
  479. outstream_user_open[phm->adapter_index][phm->
  480. obj_index].open_flag = 0;
  481. outstream_user_open[phm->adapter_index][phm->
  482. obj_index].h_owner = NULL;
  483. }
  484. } else {
  485. HPI_DEBUG_LOG(WARNING,
  486. "%p trying to close %d outstream %d owned by %p\n",
  487. h_owner, phm->adapter_index, phm->obj_index,
  488. outstream_user_open[phm->adapter_index][phm->
  489. obj_index].h_owner);
  490. phr->error = HPI_ERROR_OBJ_NOT_OPEN;
  491. }
  492. hpios_msgxlock_unlock(&msgx_lock);
  493. }
  494. static u16 adapter_prepare(u16 adapter)
  495. {
  496. struct hpi_message hm;
  497. struct hpi_response hr;
  498. /* Open the adapter and streams */
  499. u16 i;
  500. /* call to HPI_ADAPTER_OPEN */
  501. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  502. HPI_ADAPTER_OPEN);
  503. hm.adapter_index = adapter;
  504. hw_entry_point(&hm, &hr);
  505. memcpy(&rESP_HPI_ADAPTER_OPEN[adapter], &hr,
  506. sizeof(rESP_HPI_ADAPTER_OPEN[0]));
  507. if (hr.error)
  508. return hr.error;
  509. /* call to HPI_ADAPTER_GET_INFO */
  510. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  511. HPI_ADAPTER_GET_INFO);
  512. hm.adapter_index = adapter;
  513. hw_entry_point(&hm, &hr);
  514. if (hr.error)
  515. return hr.error;
  516. aDAPTER_INFO[adapter].num_outstreams = hr.u.ax.info.num_outstreams;
  517. aDAPTER_INFO[adapter].num_instreams = hr.u.ax.info.num_instreams;
  518. aDAPTER_INFO[adapter].type = hr.u.ax.info.adapter_type;
  519. /* call to HPI_OSTREAM_OPEN */
  520. for (i = 0; i < aDAPTER_INFO[adapter].num_outstreams; i++) {
  521. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  522. HPI_OSTREAM_OPEN);
  523. hm.adapter_index = adapter;
  524. hm.obj_index = i;
  525. hw_entry_point(&hm, &hr);
  526. memcpy(&rESP_HPI_OSTREAM_OPEN[adapter][i], &hr,
  527. sizeof(rESP_HPI_OSTREAM_OPEN[0][0]));
  528. outstream_user_open[adapter][i].open_flag = 0;
  529. outstream_user_open[adapter][i].h_owner = NULL;
  530. }
  531. /* call to HPI_ISTREAM_OPEN */
  532. for (i = 0; i < aDAPTER_INFO[adapter].num_instreams; i++) {
  533. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  534. HPI_ISTREAM_OPEN);
  535. hm.adapter_index = adapter;
  536. hm.obj_index = i;
  537. hw_entry_point(&hm, &hr);
  538. memcpy(&rESP_HPI_ISTREAM_OPEN[adapter][i], &hr,
  539. sizeof(rESP_HPI_ISTREAM_OPEN[0][0]));
  540. instream_user_open[adapter][i].open_flag = 0;
  541. instream_user_open[adapter][i].h_owner = NULL;
  542. }
  543. /* call to HPI_MIXER_OPEN */
  544. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN);
  545. hm.adapter_index = adapter;
  546. hw_entry_point(&hm, &hr);
  547. memcpy(&rESP_HPI_MIXER_OPEN[adapter], &hr,
  548. sizeof(rESP_HPI_MIXER_OPEN[0]));
  549. return 0;
  550. }
  551. static void HPIMSGX__reset(u16 adapter_index)
  552. {
  553. int i;
  554. u16 adapter;
  555. struct hpi_response hr;
  556. if (adapter_index == HPIMSGX_ALLADAPTERS) {
  557. for (adapter = 0; adapter < HPI_MAX_ADAPTERS; adapter++) {
  558. hpi_init_response(&hr, HPI_OBJ_ADAPTER,
  559. HPI_ADAPTER_OPEN, HPI_ERROR_BAD_ADAPTER);
  560. memcpy(&rESP_HPI_ADAPTER_OPEN[adapter], &hr,
  561. sizeof(rESP_HPI_ADAPTER_OPEN[adapter]));
  562. hpi_init_response(&hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN,
  563. HPI_ERROR_INVALID_OBJ);
  564. memcpy(&rESP_HPI_MIXER_OPEN[adapter], &hr,
  565. sizeof(rESP_HPI_MIXER_OPEN[adapter]));
  566. for (i = 0; i < HPI_MAX_STREAMS; i++) {
  567. hpi_init_response(&hr, HPI_OBJ_OSTREAM,
  568. HPI_OSTREAM_OPEN,
  569. HPI_ERROR_INVALID_OBJ);
  570. memcpy(&rESP_HPI_OSTREAM_OPEN[adapter][i],
  571. &hr,
  572. sizeof(rESP_HPI_OSTREAM_OPEN[adapter]
  573. [i]));
  574. hpi_init_response(&hr, HPI_OBJ_ISTREAM,
  575. HPI_ISTREAM_OPEN,
  576. HPI_ERROR_INVALID_OBJ);
  577. memcpy(&rESP_HPI_ISTREAM_OPEN[adapter][i],
  578. &hr,
  579. sizeof(rESP_HPI_ISTREAM_OPEN[adapter]
  580. [i]));
  581. }
  582. }
  583. } else if (adapter_index < HPI_MAX_ADAPTERS) {
  584. rESP_HPI_ADAPTER_OPEN[adapter_index].h.error =
  585. HPI_ERROR_BAD_ADAPTER;
  586. rESP_HPI_MIXER_OPEN[adapter_index].h.error =
  587. HPI_ERROR_INVALID_OBJ;
  588. for (i = 0; i < HPI_MAX_STREAMS; i++) {
  589. rESP_HPI_OSTREAM_OPEN[adapter_index][i].h.error =
  590. HPI_ERROR_INVALID_OBJ;
  591. rESP_HPI_ISTREAM_OPEN[adapter_index][i].h.error =
  592. HPI_ERROR_INVALID_OBJ;
  593. }
  594. }
  595. }
  596. static u16 HPIMSGX__init(struct hpi_message *phm,
  597. /* HPI_SUBSYS_CREATE_ADAPTER structure with */
  598. /* resource list or NULL=find all */
  599. struct hpi_response *phr
  600. /* response from HPI_ADAPTER_GET_INFO */
  601. )
  602. {
  603. hpi_handler_func *entry_point_func;
  604. struct hpi_response hr;
  605. /* Init response here so we can pass in previous adapter list */
  606. hpi_init_response(&hr, phm->object, phm->function,
  607. HPI_ERROR_INVALID_OBJ);
  608. entry_point_func =
  609. hpi_lookup_entry_point_function(phm->u.s.resource.r.pci);
  610. if (entry_point_func) {
  611. HPI_DEBUG_MESSAGE(DEBUG, phm);
  612. entry_point_func(phm, &hr);
  613. } else {
  614. phr->error = HPI_ERROR_PROCESSING_MESSAGE;
  615. return phr->error;
  616. }
  617. if (hr.error == 0) {
  618. /* the adapter was created successfully
  619. save the mapping for future use */
  620. hpi_entry_points[hr.u.s.adapter_index] = entry_point_func;
  621. /* prepare adapter (pre-open streams etc.) */
  622. HPI_DEBUG_LOG(DEBUG,
  623. "HPI_SUBSYS_CREATE_ADAPTER successful,"
  624. " preparing adapter\n");
  625. adapter_prepare(hr.u.s.adapter_index);
  626. }
  627. memcpy(phr, &hr, hr.size);
  628. return phr->error;
  629. }
  630. static void HPIMSGX__cleanup(u16 adapter_index, void *h_owner)
  631. {
  632. int i, adapter, adapter_limit;
  633. if (!h_owner)
  634. return;
  635. if (adapter_index == HPIMSGX_ALLADAPTERS) {
  636. adapter = 0;
  637. adapter_limit = HPI_MAX_ADAPTERS;
  638. } else {
  639. adapter = adapter_index;
  640. adapter_limit = adapter + 1;
  641. }
  642. for (; adapter < adapter_limit; adapter++) {
  643. /* printk(KERN_INFO "Cleanup adapter #%d\n",wAdapter); */
  644. for (i = 0; i < HPI_MAX_STREAMS; i++) {
  645. if (h_owner ==
  646. outstream_user_open[adapter][i].h_owner) {
  647. struct hpi_message hm;
  648. struct hpi_response hr;
  649. HPI_DEBUG_LOG(DEBUG,
  650. "Close adapter %d ostream %d\n",
  651. adapter, i);
  652. hpi_init_message_response(&hm, &hr,
  653. HPI_OBJ_OSTREAM, HPI_OSTREAM_RESET);
  654. hm.adapter_index = (u16)adapter;
  655. hm.obj_index = (u16)i;
  656. hw_entry_point(&hm, &hr);
  657. hm.function = HPI_OSTREAM_HOSTBUFFER_FREE;
  658. hw_entry_point(&hm, &hr);
  659. hm.function = HPI_OSTREAM_GROUP_RESET;
  660. hw_entry_point(&hm, &hr);
  661. outstream_user_open[adapter][i].open_flag = 0;
  662. outstream_user_open[adapter][i].h_owner =
  663. NULL;
  664. }
  665. if (h_owner == instream_user_open[adapter][i].h_owner) {
  666. struct hpi_message hm;
  667. struct hpi_response hr;
  668. HPI_DEBUG_LOG(DEBUG,
  669. "Close adapter %d istream %d\n",
  670. adapter, i);
  671. hpi_init_message_response(&hm, &hr,
  672. HPI_OBJ_ISTREAM, HPI_ISTREAM_RESET);
  673. hm.adapter_index = (u16)adapter;
  674. hm.obj_index = (u16)i;
  675. hw_entry_point(&hm, &hr);
  676. hm.function = HPI_ISTREAM_HOSTBUFFER_FREE;
  677. hw_entry_point(&hm, &hr);
  678. hm.function = HPI_ISTREAM_GROUP_RESET;
  679. hw_entry_point(&hm, &hr);
  680. instream_user_open[adapter][i].open_flag = 0;
  681. instream_user_open[adapter][i].h_owner = NULL;
  682. }
  683. }
  684. }
  685. }