hpifunc.c 98 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877
  1. #include "hpi_internal.h"
  2. #include "hpimsginit.h"
  3. #include "hpidebug.h"
  4. struct hpi_handle {
  5. unsigned int obj_index:12;
  6. unsigned int obj_type:4;
  7. unsigned int adapter_index:14;
  8. unsigned int spare:1;
  9. unsigned int read_only:1;
  10. };
  11. union handle_word {
  12. struct hpi_handle h;
  13. u32 w;
  14. };
  15. u32 hpi_indexes_to_handle(const char c_object, const u16 adapter_index,
  16. const u16 object_index)
  17. {
  18. union handle_word handle;
  19. handle.h.adapter_index = adapter_index;
  20. handle.h.spare = 0;
  21. handle.h.read_only = 0;
  22. handle.h.obj_type = c_object;
  23. handle.h.obj_index = object_index;
  24. return handle.w;
  25. }
  26. void hpi_handle_to_indexes(const u32 handle, u16 *pw_adapter_index,
  27. u16 *pw_object_index)
  28. {
  29. union handle_word uhandle;
  30. uhandle.w = handle;
  31. if (pw_adapter_index)
  32. *pw_adapter_index = (u16)uhandle.h.adapter_index;
  33. if (pw_object_index)
  34. *pw_object_index = (u16)uhandle.h.obj_index;
  35. }
  36. char hpi_handle_object(const u32 handle)
  37. {
  38. union handle_word uhandle;
  39. uhandle.w = handle;
  40. return (char)uhandle.h.obj_type;
  41. }
  42. #define u32TOINDEX(h, i1) \
  43. do {\
  44. if (h == 0) \
  45. return HPI_ERROR_INVALID_OBJ; \
  46. else \
  47. hpi_handle_to_indexes(h, i1, NULL); \
  48. } while (0)
  49. #define u32TOINDEXES(h, i1, i2) \
  50. do {\
  51. if (h == 0) \
  52. return HPI_ERROR_INVALID_OBJ; \
  53. else \
  54. hpi_handle_to_indexes(h, i1, i2);\
  55. } while (0)
  56. void hpi_format_to_msg(struct hpi_msg_format *pMF,
  57. const struct hpi_format *pF)
  58. {
  59. pMF->sample_rate = pF->sample_rate;
  60. pMF->bit_rate = pF->bit_rate;
  61. pMF->attributes = pF->attributes;
  62. pMF->channels = pF->channels;
  63. pMF->format = pF->format;
  64. }
  65. static void hpi_msg_to_format(struct hpi_format *pF,
  66. struct hpi_msg_format *pMF)
  67. {
  68. pF->sample_rate = pMF->sample_rate;
  69. pF->bit_rate = pMF->bit_rate;
  70. pF->attributes = pMF->attributes;
  71. pF->channels = pMF->channels;
  72. pF->format = pMF->format;
  73. pF->mode_legacy = 0;
  74. pF->unused = 0;
  75. }
  76. void hpi_stream_response_to_legacy(struct hpi_stream_res *pSR)
  77. {
  78. pSR->u.legacy_stream_info.auxiliary_data_available =
  79. pSR->u.stream_info.auxiliary_data_available;
  80. pSR->u.legacy_stream_info.state = pSR->u.stream_info.state;
  81. }
  82. static struct hpi_hsubsys gh_subsys;
  83. struct hpi_hsubsys *hpi_subsys_create(void
  84. )
  85. {
  86. struct hpi_message hm;
  87. struct hpi_response hr;
  88. memset(&gh_subsys, 0, sizeof(struct hpi_hsubsys));
  89. {
  90. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  91. HPI_SUBSYS_OPEN);
  92. hpi_send_recv(&hm, &hr);
  93. if (hr.error == 0)
  94. return &gh_subsys;
  95. }
  96. return NULL;
  97. }
  98. void hpi_subsys_free(const struct hpi_hsubsys *ph_subsys)
  99. {
  100. struct hpi_message hm;
  101. struct hpi_response hr;
  102. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  103. HPI_SUBSYS_CLOSE);
  104. hpi_send_recv(&hm, &hr);
  105. }
  106. u16 hpi_subsys_get_version(const struct hpi_hsubsys *ph_subsys, u32 *pversion)
  107. {
  108. struct hpi_message hm;
  109. struct hpi_response hr;
  110. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  111. HPI_SUBSYS_GET_VERSION);
  112. hpi_send_recv(&hm, &hr);
  113. *pversion = hr.u.s.version;
  114. return hr.error;
  115. }
  116. u16 hpi_subsys_get_version_ex(const struct hpi_hsubsys *ph_subsys,
  117. u32 *pversion_ex)
  118. {
  119. struct hpi_message hm;
  120. struct hpi_response hr;
  121. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  122. HPI_SUBSYS_GET_VERSION);
  123. hpi_send_recv(&hm, &hr);
  124. *pversion_ex = hr.u.s.data;
  125. return hr.error;
  126. }
  127. u16 hpi_subsys_get_info(const struct hpi_hsubsys *ph_subsys, u32 *pversion,
  128. u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length)
  129. {
  130. struct hpi_message hm;
  131. struct hpi_response hr;
  132. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  133. HPI_SUBSYS_GET_INFO);
  134. hpi_send_recv(&hm, &hr);
  135. *pversion = hr.u.s.version;
  136. if (list_length > HPI_MAX_ADAPTERS)
  137. memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
  138. HPI_MAX_ADAPTERS);
  139. else
  140. memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list, list_length);
  141. *pw_num_adapters = hr.u.s.num_adapters;
  142. return hr.error;
  143. }
  144. u16 hpi_subsys_find_adapters(const struct hpi_hsubsys *ph_subsys,
  145. u16 *pw_num_adapters, u16 aw_adapter_list[], u16 list_length)
  146. {
  147. struct hpi_message hm;
  148. struct hpi_response hr;
  149. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  150. HPI_SUBSYS_FIND_ADAPTERS);
  151. hpi_send_recv(&hm, &hr);
  152. if (list_length > HPI_MAX_ADAPTERS) {
  153. memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
  154. HPI_MAX_ADAPTERS * sizeof(u16));
  155. memset(&aw_adapter_list[HPI_MAX_ADAPTERS], 0,
  156. (list_length - HPI_MAX_ADAPTERS) * sizeof(u16));
  157. } else
  158. memcpy(aw_adapter_list, &hr.u.s.aw_adapter_list,
  159. list_length * sizeof(u16));
  160. *pw_num_adapters = hr.u.s.num_adapters;
  161. return hr.error;
  162. }
  163. u16 hpi_subsys_create_adapter(const struct hpi_hsubsys *ph_subsys,
  164. const struct hpi_resource *p_resource, u16 *pw_adapter_index)
  165. {
  166. struct hpi_message hm;
  167. struct hpi_response hr;
  168. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  169. HPI_SUBSYS_CREATE_ADAPTER);
  170. hm.u.s.resource = *p_resource;
  171. hpi_send_recv(&hm, &hr);
  172. *pw_adapter_index = hr.u.s.adapter_index;
  173. return hr.error;
  174. }
  175. u16 hpi_subsys_delete_adapter(const struct hpi_hsubsys *ph_subsys,
  176. u16 adapter_index)
  177. {
  178. struct hpi_message hm;
  179. struct hpi_response hr;
  180. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  181. HPI_SUBSYS_DELETE_ADAPTER);
  182. hm.adapter_index = adapter_index;
  183. hpi_send_recv(&hm, &hr);
  184. return hr.error;
  185. }
  186. u16 hpi_subsys_get_num_adapters(const struct hpi_hsubsys *ph_subsys,
  187. int *pn_num_adapters)
  188. {
  189. struct hpi_message hm;
  190. struct hpi_response hr;
  191. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  192. HPI_SUBSYS_GET_NUM_ADAPTERS);
  193. hpi_send_recv(&hm, &hr);
  194. *pn_num_adapters = (int)hr.u.s.num_adapters;
  195. return hr.error;
  196. }
  197. u16 hpi_subsys_get_adapter(const struct hpi_hsubsys *ph_subsys, int iterator,
  198. u32 *padapter_index, u16 *pw_adapter_type)
  199. {
  200. struct hpi_message hm;
  201. struct hpi_response hr;
  202. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  203. HPI_SUBSYS_GET_ADAPTER);
  204. hm.adapter_index = (u16)iterator;
  205. hpi_send_recv(&hm, &hr);
  206. *padapter_index = (int)hr.u.s.adapter_index;
  207. *pw_adapter_type = hr.u.s.aw_adapter_list[0];
  208. return hr.error;
  209. }
  210. u16 hpi_subsys_set_host_network_interface(const struct hpi_hsubsys *ph_subsys,
  211. const char *sz_interface)
  212. {
  213. struct hpi_message hm;
  214. struct hpi_response hr;
  215. hpi_init_message_response(&hm, &hr, HPI_OBJ_SUBSYSTEM,
  216. HPI_SUBSYS_SET_NETWORK_INTERFACE);
  217. if (sz_interface == NULL)
  218. return HPI_ERROR_INVALID_RESOURCE;
  219. hm.u.s.resource.r.net_if = sz_interface;
  220. hpi_send_recv(&hm, &hr);
  221. return hr.error;
  222. }
  223. u16 hpi_adapter_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index)
  224. {
  225. struct hpi_message hm;
  226. struct hpi_response hr;
  227. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  228. HPI_ADAPTER_OPEN);
  229. hm.adapter_index = adapter_index;
  230. hpi_send_recv(&hm, &hr);
  231. return hr.error;
  232. }
  233. u16 hpi_adapter_close(const struct hpi_hsubsys *ph_subsys, u16 adapter_index)
  234. {
  235. struct hpi_message hm;
  236. struct hpi_response hr;
  237. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  238. HPI_ADAPTER_CLOSE);
  239. hm.adapter_index = adapter_index;
  240. hpi_send_recv(&hm, &hr);
  241. return hr.error;
  242. }
  243. u16 hpi_adapter_set_mode(const struct hpi_hsubsys *ph_subsys,
  244. u16 adapter_index, u32 adapter_mode)
  245. {
  246. return hpi_adapter_set_mode_ex(ph_subsys, adapter_index, adapter_mode,
  247. HPI_ADAPTER_MODE_SET);
  248. }
  249. u16 hpi_adapter_set_mode_ex(const struct hpi_hsubsys *ph_subsys,
  250. u16 adapter_index, u32 adapter_mode, u16 query_or_set)
  251. {
  252. struct hpi_message hm;
  253. struct hpi_response hr;
  254. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  255. HPI_ADAPTER_SET_MODE);
  256. hm.adapter_index = adapter_index;
  257. hm.u.a.adapter_mode = adapter_mode;
  258. hm.u.a.assert_id = query_or_set;
  259. hpi_send_recv(&hm, &hr);
  260. return hr.error;
  261. }
  262. u16 hpi_adapter_get_mode(const struct hpi_hsubsys *ph_subsys,
  263. u16 adapter_index, u32 *padapter_mode)
  264. {
  265. struct hpi_message hm;
  266. struct hpi_response hr;
  267. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  268. HPI_ADAPTER_GET_MODE);
  269. hm.adapter_index = adapter_index;
  270. hpi_send_recv(&hm, &hr);
  271. if (padapter_mode)
  272. *padapter_mode = hr.u.a.serial_number;
  273. return hr.error;
  274. }
  275. u16 hpi_adapter_get_info(const struct hpi_hsubsys *ph_subsys,
  276. u16 adapter_index, u16 *pw_num_outstreams, u16 *pw_num_instreams,
  277. u16 *pw_version, u32 *pserial_number, u16 *pw_adapter_type)
  278. {
  279. struct hpi_message hm;
  280. struct hpi_response hr;
  281. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  282. HPI_ADAPTER_GET_INFO);
  283. hm.adapter_index = adapter_index;
  284. hpi_send_recv(&hm, &hr);
  285. *pw_adapter_type = hr.u.a.adapter_type;
  286. *pw_num_outstreams = hr.u.a.num_outstreams;
  287. *pw_num_instreams = hr.u.a.num_instreams;
  288. *pw_version = hr.u.a.version;
  289. *pserial_number = hr.u.a.serial_number;
  290. return hr.error;
  291. }
  292. u16 hpi_adapter_get_module_by_index(const struct hpi_hsubsys *ph_subsys,
  293. u16 adapter_index, u16 module_index, u16 *pw_num_outputs,
  294. u16 *pw_num_inputs, u16 *pw_version, u32 *pserial_number,
  295. u16 *pw_module_type, u32 *ph_module)
  296. {
  297. struct hpi_message hm;
  298. struct hpi_response hr;
  299. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  300. HPI_ADAPTER_MODULE_INFO);
  301. hm.adapter_index = adapter_index;
  302. hm.u.ax.module_info.index = module_index;
  303. hpi_send_recv(&hm, &hr);
  304. *pw_module_type = hr.u.a.adapter_type;
  305. *pw_num_outputs = hr.u.a.num_outstreams;
  306. *pw_num_inputs = hr.u.a.num_instreams;
  307. *pw_version = hr.u.a.version;
  308. *pserial_number = hr.u.a.serial_number;
  309. *ph_module = 0;
  310. return hr.error;
  311. }
  312. u16 hpi_adapter_get_assert(const struct hpi_hsubsys *ph_subsys,
  313. u16 adapter_index, u16 *assert_present, char *psz_assert,
  314. u16 *pw_line_number)
  315. {
  316. struct hpi_message hm;
  317. struct hpi_response hr;
  318. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  319. HPI_ADAPTER_GET_ASSERT);
  320. hm.adapter_index = adapter_index;
  321. hpi_send_recv(&hm, &hr);
  322. *assert_present = 0;
  323. if (!hr.error) {
  324. *pw_line_number = (u16)hr.u.a.serial_number;
  325. if (*pw_line_number) {
  326. int i;
  327. char *src = (char *)hr.u.a.sz_adapter_assert;
  328. char *dst = psz_assert;
  329. *assert_present = 1;
  330. for (i = 0; i < HPI_STRING_LEN; i++) {
  331. char c;
  332. c = *src++;
  333. *dst++ = c;
  334. if (c == 0)
  335. break;
  336. }
  337. }
  338. }
  339. return hr.error;
  340. }
  341. u16 hpi_adapter_get_assert_ex(const struct hpi_hsubsys *ph_subsys,
  342. u16 adapter_index, u16 *assert_present, char *psz_assert,
  343. u32 *pline_number, u16 *pw_assert_on_dsp)
  344. {
  345. struct hpi_message hm;
  346. struct hpi_response hr;
  347. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  348. HPI_ADAPTER_GET_ASSERT);
  349. hm.adapter_index = adapter_index;
  350. hpi_send_recv(&hm, &hr);
  351. *assert_present = 0;
  352. if (!hr.error) {
  353. *pline_number = hr.u.a.serial_number;
  354. *assert_present = hr.u.a.adapter_type;
  355. *pw_assert_on_dsp = hr.u.a.adapter_index;
  356. if (!*assert_present && *pline_number)
  357. *assert_present = 1;
  358. if (*assert_present) {
  359. int i;
  360. char *src = (char *)hr.u.a.sz_adapter_assert;
  361. char *dst = psz_assert;
  362. for (i = 0; i < HPI_STRING_LEN; i++) {
  363. char c;
  364. c = *src++;
  365. *dst++ = c;
  366. if (c == 0)
  367. break;
  368. }
  369. } else {
  370. *psz_assert = 0;
  371. }
  372. }
  373. return hr.error;
  374. }
  375. u16 hpi_adapter_test_assert(const struct hpi_hsubsys *ph_subsys,
  376. u16 adapter_index, u16 assert_id)
  377. {
  378. struct hpi_message hm;
  379. struct hpi_response hr;
  380. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  381. HPI_ADAPTER_TEST_ASSERT);
  382. hm.adapter_index = adapter_index;
  383. hm.u.a.assert_id = assert_id;
  384. hpi_send_recv(&hm, &hr);
  385. return hr.error;
  386. }
  387. u16 hpi_adapter_enable_capability(const struct hpi_hsubsys *ph_subsys,
  388. u16 adapter_index, u16 capability, u32 key)
  389. {
  390. struct hpi_message hm;
  391. struct hpi_response hr;
  392. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  393. HPI_ADAPTER_ENABLE_CAPABILITY);
  394. hm.adapter_index = adapter_index;
  395. hm.u.a.assert_id = capability;
  396. hm.u.a.adapter_mode = key;
  397. hpi_send_recv(&hm, &hr);
  398. return hr.error;
  399. }
  400. u16 hpi_adapter_self_test(const struct hpi_hsubsys *ph_subsys,
  401. u16 adapter_index)
  402. {
  403. struct hpi_message hm;
  404. struct hpi_response hr;
  405. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  406. HPI_ADAPTER_SELFTEST);
  407. hm.adapter_index = adapter_index;
  408. hpi_send_recv(&hm, &hr);
  409. return hr.error;
  410. }
  411. u16 hpi_adapter_debug_read(const struct hpi_hsubsys *ph_subsys,
  412. u16 adapter_index, u32 dsp_address, char *p_buffer, int *count_bytes)
  413. {
  414. struct hpi_message hm;
  415. struct hpi_response hr;
  416. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  417. HPI_ADAPTER_DEBUG_READ);
  418. hr.size = sizeof(hr);
  419. hm.adapter_index = adapter_index;
  420. hm.u.ax.debug_read.dsp_address = dsp_address;
  421. if (*count_bytes > sizeof(hr.u.bytes))
  422. *count_bytes = sizeof(hr.u.bytes);
  423. hm.u.ax.debug_read.count_bytes = *count_bytes;
  424. hpi_send_recv(&hm, &hr);
  425. if (!hr.error) {
  426. *count_bytes = hr.size - 12;
  427. memcpy(p_buffer, &hr.u.bytes, *count_bytes);
  428. } else
  429. *count_bytes = 0;
  430. return hr.error;
  431. }
  432. u16 hpi_adapter_set_property(const struct hpi_hsubsys *ph_subsys,
  433. u16 adapter_index, u16 property, u16 parameter1, u16 parameter2)
  434. {
  435. struct hpi_message hm;
  436. struct hpi_response hr;
  437. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  438. HPI_ADAPTER_SET_PROPERTY);
  439. hm.adapter_index = adapter_index;
  440. hm.u.ax.property_set.property = property;
  441. hm.u.ax.property_set.parameter1 = parameter1;
  442. hm.u.ax.property_set.parameter2 = parameter2;
  443. hpi_send_recv(&hm, &hr);
  444. return hr.error;
  445. }
  446. u16 hpi_adapter_get_property(const struct hpi_hsubsys *ph_subsys,
  447. u16 adapter_index, u16 property, u16 *pw_parameter1,
  448. u16 *pw_parameter2)
  449. {
  450. struct hpi_message hm;
  451. struct hpi_response hr;
  452. hpi_init_message_response(&hm, &hr, HPI_OBJ_ADAPTER,
  453. HPI_ADAPTER_GET_PROPERTY);
  454. hm.adapter_index = adapter_index;
  455. hm.u.ax.property_set.property = property;
  456. hpi_send_recv(&hm, &hr);
  457. if (!hr.error) {
  458. if (pw_parameter1)
  459. *pw_parameter1 = hr.u.ax.property_get.parameter1;
  460. if (pw_parameter2)
  461. *pw_parameter2 = hr.u.ax.property_get.parameter2;
  462. }
  463. return hr.error;
  464. }
  465. u16 hpi_adapter_enumerate_property(const struct hpi_hsubsys *ph_subsys,
  466. u16 adapter_index, u16 index, u16 what_to_enumerate,
  467. u16 property_index, u32 *psetting)
  468. {
  469. return 0;
  470. }
  471. u16 hpi_format_create(struct hpi_format *p_format, u16 channels, u16 format,
  472. u32 sample_rate, u32 bit_rate, u32 attributes)
  473. {
  474. u16 error = 0;
  475. struct hpi_msg_format fmt;
  476. switch (channels) {
  477. case 1:
  478. case 2:
  479. case 4:
  480. case 6:
  481. case 8:
  482. case 16:
  483. break;
  484. default:
  485. error = HPI_ERROR_INVALID_CHANNELS;
  486. return error;
  487. }
  488. fmt.channels = channels;
  489. switch (format) {
  490. case HPI_FORMAT_PCM16_SIGNED:
  491. case HPI_FORMAT_PCM24_SIGNED:
  492. case HPI_FORMAT_PCM32_SIGNED:
  493. case HPI_FORMAT_PCM32_FLOAT:
  494. case HPI_FORMAT_PCM16_BIGENDIAN:
  495. case HPI_FORMAT_PCM8_UNSIGNED:
  496. case HPI_FORMAT_MPEG_L1:
  497. case HPI_FORMAT_MPEG_L2:
  498. case HPI_FORMAT_MPEG_L3:
  499. case HPI_FORMAT_DOLBY_AC2:
  500. case HPI_FORMAT_AA_TAGIT1_HITS:
  501. case HPI_FORMAT_AA_TAGIT1_INSERTS:
  502. case HPI_FORMAT_RAW_BITSTREAM:
  503. case HPI_FORMAT_AA_TAGIT1_HITS_EX1:
  504. case HPI_FORMAT_OEM1:
  505. case HPI_FORMAT_OEM2:
  506. break;
  507. default:
  508. error = HPI_ERROR_INVALID_FORMAT;
  509. return error;
  510. }
  511. fmt.format = format;
  512. if (sample_rate < 8000L) {
  513. error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
  514. sample_rate = 8000L;
  515. }
  516. if (sample_rate > 200000L) {
  517. error = HPI_ERROR_INCOMPATIBLE_SAMPLERATE;
  518. sample_rate = 200000L;
  519. }
  520. fmt.sample_rate = sample_rate;
  521. switch (format) {
  522. case HPI_FORMAT_MPEG_L1:
  523. case HPI_FORMAT_MPEG_L2:
  524. case HPI_FORMAT_MPEG_L3:
  525. fmt.bit_rate = bit_rate;
  526. break;
  527. case HPI_FORMAT_PCM16_SIGNED:
  528. case HPI_FORMAT_PCM16_BIGENDIAN:
  529. fmt.bit_rate = channels * sample_rate * 2;
  530. break;
  531. case HPI_FORMAT_PCM32_SIGNED:
  532. case HPI_FORMAT_PCM32_FLOAT:
  533. fmt.bit_rate = channels * sample_rate * 4;
  534. break;
  535. case HPI_FORMAT_PCM8_UNSIGNED:
  536. fmt.bit_rate = channels * sample_rate;
  537. break;
  538. default:
  539. fmt.bit_rate = 0;
  540. }
  541. switch (format) {
  542. case HPI_FORMAT_MPEG_L2:
  543. if ((channels == 1)
  544. && (attributes != HPI_MPEG_MODE_DEFAULT)) {
  545. attributes = HPI_MPEG_MODE_DEFAULT;
  546. error = HPI_ERROR_INVALID_FORMAT;
  547. } else if (attributes > HPI_MPEG_MODE_DUALCHANNEL) {
  548. attributes = HPI_MPEG_MODE_DEFAULT;
  549. error = HPI_ERROR_INVALID_FORMAT;
  550. }
  551. fmt.attributes = attributes;
  552. break;
  553. default:
  554. fmt.attributes = attributes;
  555. }
  556. hpi_msg_to_format(p_format, &fmt);
  557. return error;
  558. }
  559. u16 hpi_stream_estimate_buffer_size(struct hpi_format *p_format,
  560. u32 host_polling_rate_in_milli_seconds, u32 *recommended_buffer_size)
  561. {
  562. u32 bytes_per_second;
  563. u32 size;
  564. u16 channels;
  565. struct hpi_format *pF = p_format;
  566. channels = pF->channels;
  567. switch (pF->format) {
  568. case HPI_FORMAT_PCM16_BIGENDIAN:
  569. case HPI_FORMAT_PCM16_SIGNED:
  570. bytes_per_second = pF->sample_rate * 2L * channels;
  571. break;
  572. case HPI_FORMAT_PCM24_SIGNED:
  573. bytes_per_second = pF->sample_rate * 3L * channels;
  574. break;
  575. case HPI_FORMAT_PCM32_SIGNED:
  576. case HPI_FORMAT_PCM32_FLOAT:
  577. bytes_per_second = pF->sample_rate * 4L * channels;
  578. break;
  579. case HPI_FORMAT_PCM8_UNSIGNED:
  580. bytes_per_second = pF->sample_rate * 1L * channels;
  581. break;
  582. case HPI_FORMAT_MPEG_L1:
  583. case HPI_FORMAT_MPEG_L2:
  584. case HPI_FORMAT_MPEG_L3:
  585. bytes_per_second = pF->bit_rate / 8L;
  586. break;
  587. case HPI_FORMAT_DOLBY_AC2:
  588. bytes_per_second = 256000L / 8L;
  589. break;
  590. default:
  591. return HPI_ERROR_INVALID_FORMAT;
  592. }
  593. size = (bytes_per_second * host_polling_rate_in_milli_seconds * 2) /
  594. 1000L;
  595. *recommended_buffer_size =
  596. roundup_pow_of_two(((size + 4095L) & ~4095L));
  597. return 0;
  598. }
  599. u16 hpi_outstream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
  600. u16 outstream_index, u32 *ph_outstream)
  601. {
  602. struct hpi_message hm;
  603. struct hpi_response hr;
  604. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  605. HPI_OSTREAM_OPEN);
  606. hm.adapter_index = adapter_index;
  607. hm.obj_index = outstream_index;
  608. hpi_send_recv(&hm, &hr);
  609. if (hr.error == 0)
  610. *ph_outstream =
  611. hpi_indexes_to_handle(HPI_OBJ_OSTREAM, adapter_index,
  612. outstream_index);
  613. else
  614. *ph_outstream = 0;
  615. return hr.error;
  616. }
  617. u16 hpi_outstream_close(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
  618. {
  619. struct hpi_message hm;
  620. struct hpi_response hr;
  621. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  622. HPI_OSTREAM_HOSTBUFFER_FREE);
  623. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  624. hpi_send_recv(&hm, &hr);
  625. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  626. HPI_OSTREAM_GROUP_RESET);
  627. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  628. hpi_send_recv(&hm, &hr);
  629. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  630. HPI_OSTREAM_CLOSE);
  631. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  632. hpi_send_recv(&hm, &hr);
  633. return hr.error;
  634. }
  635. u16 hpi_outstream_get_info_ex(const struct hpi_hsubsys *ph_subsys,
  636. u32 h_outstream, u16 *pw_state, u32 *pbuffer_size, u32 *pdata_to_play,
  637. u32 *psamples_played, u32 *pauxiliary_data_to_play)
  638. {
  639. struct hpi_message hm;
  640. struct hpi_response hr;
  641. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  642. HPI_OSTREAM_GET_INFO);
  643. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  644. hpi_send_recv(&hm, &hr);
  645. if (pw_state)
  646. *pw_state = hr.u.d.u.stream_info.state;
  647. if (pbuffer_size)
  648. *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
  649. if (pdata_to_play)
  650. *pdata_to_play = hr.u.d.u.stream_info.data_available;
  651. if (psamples_played)
  652. *psamples_played = hr.u.d.u.stream_info.samples_transferred;
  653. if (pauxiliary_data_to_play)
  654. *pauxiliary_data_to_play =
  655. hr.u.d.u.stream_info.auxiliary_data_available;
  656. return hr.error;
  657. }
  658. u16 hpi_outstream_write_buf(const struct hpi_hsubsys *ph_subsys,
  659. u32 h_outstream, const u8 *pb_data, u32 bytes_to_write,
  660. const struct hpi_format *p_format)
  661. {
  662. struct hpi_message hm;
  663. struct hpi_response hr;
  664. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  665. HPI_OSTREAM_WRITE);
  666. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  667. hm.u.d.u.data.pb_data = (u8 *)pb_data;
  668. hm.u.d.u.data.data_size = bytes_to_write;
  669. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  670. hpi_send_recv(&hm, &hr);
  671. return hr.error;
  672. }
  673. u16 hpi_outstream_start(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
  674. {
  675. struct hpi_message hm;
  676. struct hpi_response hr;
  677. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  678. HPI_OSTREAM_START);
  679. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  680. hpi_send_recv(&hm, &hr);
  681. return hr.error;
  682. }
  683. u16 hpi_outstream_wait_start(const struct hpi_hsubsys *ph_subsys,
  684. u32 h_outstream)
  685. {
  686. struct hpi_message hm;
  687. struct hpi_response hr;
  688. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  689. HPI_OSTREAM_WAIT_START);
  690. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  691. hpi_send_recv(&hm, &hr);
  692. return hr.error;
  693. }
  694. u16 hpi_outstream_stop(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
  695. {
  696. struct hpi_message hm;
  697. struct hpi_response hr;
  698. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  699. HPI_OSTREAM_STOP);
  700. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  701. hpi_send_recv(&hm, &hr);
  702. return hr.error;
  703. }
  704. u16 hpi_outstream_sinegen(const struct hpi_hsubsys *ph_subsys,
  705. u32 h_outstream)
  706. {
  707. struct hpi_message hm;
  708. struct hpi_response hr;
  709. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  710. HPI_OSTREAM_SINEGEN);
  711. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  712. hpi_send_recv(&hm, &hr);
  713. return hr.error;
  714. }
  715. u16 hpi_outstream_reset(const struct hpi_hsubsys *ph_subsys, u32 h_outstream)
  716. {
  717. struct hpi_message hm;
  718. struct hpi_response hr;
  719. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  720. HPI_OSTREAM_RESET);
  721. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  722. hpi_send_recv(&hm, &hr);
  723. return hr.error;
  724. }
  725. u16 hpi_outstream_query_format(const struct hpi_hsubsys *ph_subsys,
  726. u32 h_outstream, struct hpi_format *p_format)
  727. {
  728. struct hpi_message hm;
  729. struct hpi_response hr;
  730. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  731. HPI_OSTREAM_QUERY_FORMAT);
  732. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  733. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  734. hpi_send_recv(&hm, &hr);
  735. return hr.error;
  736. }
  737. u16 hpi_outstream_set_format(const struct hpi_hsubsys *ph_subsys,
  738. u32 h_outstream, struct hpi_format *p_format)
  739. {
  740. struct hpi_message hm;
  741. struct hpi_response hr;
  742. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  743. HPI_OSTREAM_SET_FORMAT);
  744. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  745. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  746. hpi_send_recv(&hm, &hr);
  747. return hr.error;
  748. }
  749. u16 hpi_outstream_set_velocity(const struct hpi_hsubsys *ph_subsys,
  750. u32 h_outstream, short velocity)
  751. {
  752. struct hpi_message hm;
  753. struct hpi_response hr;
  754. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  755. HPI_OSTREAM_SET_VELOCITY);
  756. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  757. hm.u.d.u.velocity = velocity;
  758. hpi_send_recv(&hm, &hr);
  759. return hr.error;
  760. }
  761. u16 hpi_outstream_set_punch_in_out(const struct hpi_hsubsys *ph_subsys,
  762. u32 h_outstream, u32 punch_in_sample, u32 punch_out_sample)
  763. {
  764. struct hpi_message hm;
  765. struct hpi_response hr;
  766. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  767. HPI_OSTREAM_SET_PUNCHINOUT);
  768. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  769. hm.u.d.u.pio.punch_in_sample = punch_in_sample;
  770. hm.u.d.u.pio.punch_out_sample = punch_out_sample;
  771. hpi_send_recv(&hm, &hr);
  772. return hr.error;
  773. }
  774. u16 hpi_outstream_ancillary_reset(const struct hpi_hsubsys *ph_subsys,
  775. u32 h_outstream, u16 mode)
  776. {
  777. struct hpi_message hm;
  778. struct hpi_response hr;
  779. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  780. HPI_OSTREAM_ANC_RESET);
  781. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  782. hm.u.d.u.data.format.channels = mode;
  783. hpi_send_recv(&hm, &hr);
  784. return hr.error;
  785. }
  786. u16 hpi_outstream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys,
  787. u32 h_outstream, u32 *pframes_available)
  788. {
  789. struct hpi_message hm;
  790. struct hpi_response hr;
  791. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  792. HPI_OSTREAM_ANC_GET_INFO);
  793. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  794. hpi_send_recv(&hm, &hr);
  795. if (hr.error == 0) {
  796. if (pframes_available)
  797. *pframes_available =
  798. hr.u.d.u.stream_info.data_available /
  799. sizeof(struct hpi_anc_frame);
  800. }
  801. return hr.error;
  802. }
  803. u16 hpi_outstream_ancillary_read(const struct hpi_hsubsys *ph_subsys,
  804. u32 h_outstream, struct hpi_anc_frame *p_anc_frame_buffer,
  805. u32 anc_frame_buffer_size_in_bytes,
  806. u32 number_of_ancillary_frames_to_read)
  807. {
  808. struct hpi_message hm;
  809. struct hpi_response hr;
  810. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  811. HPI_OSTREAM_ANC_READ);
  812. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  813. hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
  814. hm.u.d.u.data.data_size =
  815. number_of_ancillary_frames_to_read *
  816. sizeof(struct hpi_anc_frame);
  817. if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
  818. hpi_send_recv(&hm, &hr);
  819. else
  820. hr.error = HPI_ERROR_INVALID_DATA_TRANSFER;
  821. return hr.error;
  822. }
  823. u16 hpi_outstream_set_time_scale(const struct hpi_hsubsys *ph_subsys,
  824. u32 h_outstream, u32 time_scale)
  825. {
  826. struct hpi_message hm;
  827. struct hpi_response hr;
  828. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  829. HPI_OSTREAM_SET_TIMESCALE);
  830. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  831. hm.u.d.u.time_scale = time_scale;
  832. hpi_send_recv(&hm, &hr);
  833. return hr.error;
  834. }
  835. u16 hpi_outstream_host_buffer_allocate(const struct hpi_hsubsys *ph_subsys,
  836. u32 h_outstream, u32 size_in_bytes)
  837. {
  838. struct hpi_message hm;
  839. struct hpi_response hr;
  840. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  841. HPI_OSTREAM_HOSTBUFFER_ALLOC);
  842. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  843. hm.u.d.u.data.data_size = size_in_bytes;
  844. hpi_send_recv(&hm, &hr);
  845. return hr.error;
  846. }
  847. u16 hpi_outstream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys,
  848. u32 h_outstream, u8 **pp_buffer,
  849. struct hpi_hostbuffer_status **pp_status)
  850. {
  851. struct hpi_message hm;
  852. struct hpi_response hr;
  853. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  854. HPI_OSTREAM_HOSTBUFFER_GET_INFO);
  855. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  856. hpi_send_recv(&hm, &hr);
  857. if (hr.error == 0) {
  858. if (pp_buffer)
  859. *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
  860. if (pp_status)
  861. *pp_status = hr.u.d.u.hostbuffer_info.p_status;
  862. }
  863. return hr.error;
  864. }
  865. u16 hpi_outstream_host_buffer_free(const struct hpi_hsubsys *ph_subsys,
  866. u32 h_outstream)
  867. {
  868. struct hpi_message hm;
  869. struct hpi_response hr;
  870. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  871. HPI_OSTREAM_HOSTBUFFER_FREE);
  872. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  873. hpi_send_recv(&hm, &hr);
  874. return hr.error;
  875. }
  876. u16 hpi_outstream_group_add(const struct hpi_hsubsys *ph_subsys,
  877. u32 h_outstream, u32 h_stream)
  878. {
  879. struct hpi_message hm;
  880. struct hpi_response hr;
  881. u16 adapter;
  882. char c_obj_type;
  883. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  884. HPI_OSTREAM_GROUP_ADD);
  885. hr.error = 0;
  886. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  887. c_obj_type = hpi_handle_object(h_stream);
  888. switch (c_obj_type) {
  889. case HPI_OBJ_OSTREAM:
  890. hm.u.d.u.stream.object_type = HPI_OBJ_OSTREAM;
  891. u32TOINDEXES(h_stream, &adapter,
  892. &hm.u.d.u.stream.stream_index);
  893. break;
  894. case HPI_OBJ_ISTREAM:
  895. hm.u.d.u.stream.object_type = HPI_OBJ_ISTREAM;
  896. u32TOINDEXES(h_stream, &adapter,
  897. &hm.u.d.u.stream.stream_index);
  898. break;
  899. default:
  900. return HPI_ERROR_INVALID_STREAM;
  901. }
  902. if (adapter != hm.adapter_index)
  903. return HPI_ERROR_NO_INTERADAPTER_GROUPS;
  904. hpi_send_recv(&hm, &hr);
  905. return hr.error;
  906. }
  907. u16 hpi_outstream_group_get_map(const struct hpi_hsubsys *ph_subsys,
  908. u32 h_outstream, u32 *poutstream_map, u32 *pinstream_map)
  909. {
  910. struct hpi_message hm;
  911. struct hpi_response hr;
  912. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  913. HPI_OSTREAM_GROUP_GETMAP);
  914. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  915. hpi_send_recv(&hm, &hr);
  916. if (poutstream_map)
  917. *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
  918. if (pinstream_map)
  919. *pinstream_map = hr.u.d.u.group_info.instream_group_map;
  920. return hr.error;
  921. }
  922. u16 hpi_outstream_group_reset(const struct hpi_hsubsys *ph_subsys,
  923. u32 h_outstream)
  924. {
  925. struct hpi_message hm;
  926. struct hpi_response hr;
  927. hpi_init_message_response(&hm, &hr, HPI_OBJ_OSTREAM,
  928. HPI_OSTREAM_GROUP_RESET);
  929. u32TOINDEXES(h_outstream, &hm.adapter_index, &hm.obj_index);
  930. hpi_send_recv(&hm, &hr);
  931. return hr.error;
  932. }
  933. u16 hpi_instream_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
  934. u16 instream_index, u32 *ph_instream)
  935. {
  936. struct hpi_message hm;
  937. struct hpi_response hr;
  938. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  939. HPI_ISTREAM_OPEN);
  940. hm.adapter_index = adapter_index;
  941. hm.obj_index = instream_index;
  942. hpi_send_recv(&hm, &hr);
  943. if (hr.error == 0)
  944. *ph_instream =
  945. hpi_indexes_to_handle(HPI_OBJ_ISTREAM, adapter_index,
  946. instream_index);
  947. else
  948. *ph_instream = 0;
  949. return hr.error;
  950. }
  951. u16 hpi_instream_close(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
  952. {
  953. struct hpi_message hm;
  954. struct hpi_response hr;
  955. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  956. HPI_ISTREAM_HOSTBUFFER_FREE);
  957. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  958. hpi_send_recv(&hm, &hr);
  959. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  960. HPI_ISTREAM_GROUP_RESET);
  961. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  962. hpi_send_recv(&hm, &hr);
  963. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  964. HPI_ISTREAM_CLOSE);
  965. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  966. hpi_send_recv(&hm, &hr);
  967. return hr.error;
  968. }
  969. u16 hpi_instream_query_format(const struct hpi_hsubsys *ph_subsys,
  970. u32 h_instream, const struct hpi_format *p_format)
  971. {
  972. struct hpi_message hm;
  973. struct hpi_response hr;
  974. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  975. HPI_ISTREAM_QUERY_FORMAT);
  976. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  977. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  978. hpi_send_recv(&hm, &hr);
  979. return hr.error;
  980. }
  981. u16 hpi_instream_set_format(const struct hpi_hsubsys *ph_subsys,
  982. u32 h_instream, const struct hpi_format *p_format)
  983. {
  984. struct hpi_message hm;
  985. struct hpi_response hr;
  986. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  987. HPI_ISTREAM_SET_FORMAT);
  988. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  989. hpi_format_to_msg(&hm.u.d.u.data.format, p_format);
  990. hpi_send_recv(&hm, &hr);
  991. return hr.error;
  992. }
  993. u16 hpi_instream_read_buf(const struct hpi_hsubsys *ph_subsys, u32 h_instream,
  994. u8 *pb_data, u32 bytes_to_read)
  995. {
  996. struct hpi_message hm;
  997. struct hpi_response hr;
  998. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  999. HPI_ISTREAM_READ);
  1000. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1001. hm.u.d.u.data.data_size = bytes_to_read;
  1002. hm.u.d.u.data.pb_data = pb_data;
  1003. hpi_send_recv(&hm, &hr);
  1004. return hr.error;
  1005. }
  1006. u16 hpi_instream_start(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
  1007. {
  1008. struct hpi_message hm;
  1009. struct hpi_response hr;
  1010. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1011. HPI_ISTREAM_START);
  1012. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1013. hpi_send_recv(&hm, &hr);
  1014. return hr.error;
  1015. }
  1016. u16 hpi_instream_wait_start(const struct hpi_hsubsys *ph_subsys,
  1017. u32 h_instream)
  1018. {
  1019. struct hpi_message hm;
  1020. struct hpi_response hr;
  1021. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1022. HPI_ISTREAM_WAIT_START);
  1023. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1024. hpi_send_recv(&hm, &hr);
  1025. return hr.error;
  1026. }
  1027. u16 hpi_instream_stop(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
  1028. {
  1029. struct hpi_message hm;
  1030. struct hpi_response hr;
  1031. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1032. HPI_ISTREAM_STOP);
  1033. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1034. hpi_send_recv(&hm, &hr);
  1035. return hr.error;
  1036. }
  1037. u16 hpi_instream_reset(const struct hpi_hsubsys *ph_subsys, u32 h_instream)
  1038. {
  1039. struct hpi_message hm;
  1040. struct hpi_response hr;
  1041. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1042. HPI_ISTREAM_RESET);
  1043. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1044. hpi_send_recv(&hm, &hr);
  1045. return hr.error;
  1046. }
  1047. u16 hpi_instream_get_info_ex(const struct hpi_hsubsys *ph_subsys,
  1048. u32 h_instream, u16 *pw_state, u32 *pbuffer_size, u32 *pdata_recorded,
  1049. u32 *psamples_recorded, u32 *pauxiliary_data_recorded)
  1050. {
  1051. struct hpi_message hm;
  1052. struct hpi_response hr;
  1053. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1054. HPI_ISTREAM_GET_INFO);
  1055. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1056. hpi_send_recv(&hm, &hr);
  1057. if (pw_state)
  1058. *pw_state = hr.u.d.u.stream_info.state;
  1059. if (pbuffer_size)
  1060. *pbuffer_size = hr.u.d.u.stream_info.buffer_size;
  1061. if (pdata_recorded)
  1062. *pdata_recorded = hr.u.d.u.stream_info.data_available;
  1063. if (psamples_recorded)
  1064. *psamples_recorded = hr.u.d.u.stream_info.samples_transferred;
  1065. if (pauxiliary_data_recorded)
  1066. *pauxiliary_data_recorded =
  1067. hr.u.d.u.stream_info.auxiliary_data_available;
  1068. return hr.error;
  1069. }
  1070. u16 hpi_instream_ancillary_reset(const struct hpi_hsubsys *ph_subsys,
  1071. u32 h_instream, u16 bytes_per_frame, u16 mode, u16 alignment,
  1072. u16 idle_bit)
  1073. {
  1074. struct hpi_message hm;
  1075. struct hpi_response hr;
  1076. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1077. HPI_ISTREAM_ANC_RESET);
  1078. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1079. hm.u.d.u.data.format.attributes = bytes_per_frame;
  1080. hm.u.d.u.data.format.format = (mode << 8) | (alignment & 0xff);
  1081. hm.u.d.u.data.format.channels = idle_bit;
  1082. hpi_send_recv(&hm, &hr);
  1083. return hr.error;
  1084. }
  1085. u16 hpi_instream_ancillary_get_info(const struct hpi_hsubsys *ph_subsys,
  1086. u32 h_instream, u32 *pframe_space)
  1087. {
  1088. struct hpi_message hm;
  1089. struct hpi_response hr;
  1090. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1091. HPI_ISTREAM_ANC_GET_INFO);
  1092. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1093. hpi_send_recv(&hm, &hr);
  1094. if (pframe_space)
  1095. *pframe_space =
  1096. (hr.u.d.u.stream_info.buffer_size -
  1097. hr.u.d.u.stream_info.data_available) /
  1098. sizeof(struct hpi_anc_frame);
  1099. return hr.error;
  1100. }
  1101. u16 hpi_instream_ancillary_write(const struct hpi_hsubsys *ph_subsys,
  1102. u32 h_instream, const struct hpi_anc_frame *p_anc_frame_buffer,
  1103. u32 anc_frame_buffer_size_in_bytes,
  1104. u32 number_of_ancillary_frames_to_write)
  1105. {
  1106. struct hpi_message hm;
  1107. struct hpi_response hr;
  1108. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1109. HPI_ISTREAM_ANC_WRITE);
  1110. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1111. hm.u.d.u.data.pb_data = (u8 *)p_anc_frame_buffer;
  1112. hm.u.d.u.data.data_size =
  1113. number_of_ancillary_frames_to_write *
  1114. sizeof(struct hpi_anc_frame);
  1115. if (hm.u.d.u.data.data_size <= anc_frame_buffer_size_in_bytes)
  1116. hpi_send_recv(&hm, &hr);
  1117. else
  1118. hr.error = HPI_ERROR_INVALID_DATA_TRANSFER;
  1119. return hr.error;
  1120. }
  1121. u16 hpi_instream_host_buffer_allocate(const struct hpi_hsubsys *ph_subsys,
  1122. u32 h_instream, u32 size_in_bytes)
  1123. {
  1124. struct hpi_message hm;
  1125. struct hpi_response hr;
  1126. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1127. HPI_ISTREAM_HOSTBUFFER_ALLOC);
  1128. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1129. hm.u.d.u.data.data_size = size_in_bytes;
  1130. hpi_send_recv(&hm, &hr);
  1131. return hr.error;
  1132. }
  1133. u16 hpi_instream_host_buffer_get_info(const struct hpi_hsubsys *ph_subsys,
  1134. u32 h_instream, u8 **pp_buffer,
  1135. struct hpi_hostbuffer_status **pp_status)
  1136. {
  1137. struct hpi_message hm;
  1138. struct hpi_response hr;
  1139. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1140. HPI_ISTREAM_HOSTBUFFER_GET_INFO);
  1141. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1142. hpi_send_recv(&hm, &hr);
  1143. if (hr.error == 0) {
  1144. if (pp_buffer)
  1145. *pp_buffer = hr.u.d.u.hostbuffer_info.p_buffer;
  1146. if (pp_status)
  1147. *pp_status = hr.u.d.u.hostbuffer_info.p_status;
  1148. }
  1149. return hr.error;
  1150. }
  1151. u16 hpi_instream_host_buffer_free(const struct hpi_hsubsys *ph_subsys,
  1152. u32 h_instream)
  1153. {
  1154. struct hpi_message hm;
  1155. struct hpi_response hr;
  1156. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1157. HPI_ISTREAM_HOSTBUFFER_FREE);
  1158. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1159. hpi_send_recv(&hm, &hr);
  1160. return hr.error;
  1161. }
  1162. u16 hpi_instream_group_add(const struct hpi_hsubsys *ph_subsys,
  1163. u32 h_instream, u32 h_stream)
  1164. {
  1165. struct hpi_message hm;
  1166. struct hpi_response hr;
  1167. u16 adapter;
  1168. char c_obj_type;
  1169. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1170. HPI_ISTREAM_GROUP_ADD);
  1171. hr.error = 0;
  1172. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1173. c_obj_type = hpi_handle_object(h_stream);
  1174. switch (c_obj_type) {
  1175. case HPI_OBJ_OSTREAM:
  1176. hm.u.d.u.stream.object_type = HPI_OBJ_OSTREAM;
  1177. u32TOINDEXES(h_stream, &adapter,
  1178. &hm.u.d.u.stream.stream_index);
  1179. break;
  1180. case HPI_OBJ_ISTREAM:
  1181. hm.u.d.u.stream.object_type = HPI_OBJ_ISTREAM;
  1182. u32TOINDEXES(h_stream, &adapter,
  1183. &hm.u.d.u.stream.stream_index);
  1184. break;
  1185. default:
  1186. return HPI_ERROR_INVALID_STREAM;
  1187. }
  1188. if (adapter != hm.adapter_index)
  1189. return HPI_ERROR_NO_INTERADAPTER_GROUPS;
  1190. hpi_send_recv(&hm, &hr);
  1191. return hr.error;
  1192. }
  1193. u16 hpi_instream_group_get_map(const struct hpi_hsubsys *ph_subsys,
  1194. u32 h_instream, u32 *poutstream_map, u32 *pinstream_map)
  1195. {
  1196. struct hpi_message hm;
  1197. struct hpi_response hr;
  1198. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1199. HPI_ISTREAM_HOSTBUFFER_FREE);
  1200. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1201. hpi_send_recv(&hm, &hr);
  1202. if (poutstream_map)
  1203. *poutstream_map = hr.u.d.u.group_info.outstream_group_map;
  1204. if (pinstream_map)
  1205. *pinstream_map = hr.u.d.u.group_info.instream_group_map;
  1206. return hr.error;
  1207. }
  1208. u16 hpi_instream_group_reset(const struct hpi_hsubsys *ph_subsys,
  1209. u32 h_instream)
  1210. {
  1211. struct hpi_message hm;
  1212. struct hpi_response hr;
  1213. hpi_init_message_response(&hm, &hr, HPI_OBJ_ISTREAM,
  1214. HPI_ISTREAM_GROUP_RESET);
  1215. u32TOINDEXES(h_instream, &hm.adapter_index, &hm.obj_index);
  1216. hpi_send_recv(&hm, &hr);
  1217. return hr.error;
  1218. }
  1219. u16 hpi_mixer_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
  1220. u32 *ph_mixer)
  1221. {
  1222. struct hpi_message hm;
  1223. struct hpi_response hr;
  1224. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_OPEN);
  1225. hm.adapter_index = adapter_index;
  1226. hpi_send_recv(&hm, &hr);
  1227. if (hr.error == 0)
  1228. *ph_mixer =
  1229. hpi_indexes_to_handle(HPI_OBJ_MIXER, adapter_index,
  1230. 0);
  1231. else
  1232. *ph_mixer = 0;
  1233. return hr.error;
  1234. }
  1235. u16 hpi_mixer_close(const struct hpi_hsubsys *ph_subsys, u32 h_mixer)
  1236. {
  1237. struct hpi_message hm;
  1238. struct hpi_response hr;
  1239. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_CLOSE);
  1240. u32TOINDEX(h_mixer, &hm.adapter_index);
  1241. hpi_send_recv(&hm, &hr);
  1242. return hr.error;
  1243. }
  1244. u16 hpi_mixer_get_control(const struct hpi_hsubsys *ph_subsys, u32 h_mixer,
  1245. u16 src_node_type, u16 src_node_type_index, u16 dst_node_type,
  1246. u16 dst_node_type_index, u16 control_type, u32 *ph_control)
  1247. {
  1248. struct hpi_message hm;
  1249. struct hpi_response hr;
  1250. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
  1251. HPI_MIXER_GET_CONTROL);
  1252. u32TOINDEX(h_mixer, &hm.adapter_index);
  1253. hm.u.m.node_type1 = src_node_type;
  1254. hm.u.m.node_index1 = src_node_type_index;
  1255. hm.u.m.node_type2 = dst_node_type;
  1256. hm.u.m.node_index2 = dst_node_type_index;
  1257. hm.u.m.control_type = control_type;
  1258. hpi_send_recv(&hm, &hr);
  1259. if (hr.error == 0)
  1260. *ph_control =
  1261. hpi_indexes_to_handle(HPI_OBJ_CONTROL,
  1262. hm.adapter_index, hr.u.m.control_index);
  1263. else
  1264. *ph_control = 0;
  1265. return hr.error;
  1266. }
  1267. u16 hpi_mixer_get_control_by_index(const struct hpi_hsubsys *ph_subsys,
  1268. u32 h_mixer, u16 control_index, u16 *pw_src_node_type,
  1269. u16 *pw_src_node_index, u16 *pw_dst_node_type, u16 *pw_dst_node_index,
  1270. u16 *pw_control_type, u32 *ph_control)
  1271. {
  1272. struct hpi_message hm;
  1273. struct hpi_response hr;
  1274. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER,
  1275. HPI_MIXER_GET_CONTROL_BY_INDEX);
  1276. u32TOINDEX(h_mixer, &hm.adapter_index);
  1277. hm.u.m.control_index = control_index;
  1278. hpi_send_recv(&hm, &hr);
  1279. if (pw_src_node_type) {
  1280. *pw_src_node_type =
  1281. hr.u.m.src_node_type + HPI_SOURCENODE_NONE;
  1282. *pw_src_node_index = hr.u.m.src_node_index;
  1283. *pw_dst_node_type = hr.u.m.dst_node_type + HPI_DESTNODE_NONE;
  1284. *pw_dst_node_index = hr.u.m.dst_node_index;
  1285. }
  1286. if (pw_control_type)
  1287. *pw_control_type = hr.u.m.control_index;
  1288. if (ph_control) {
  1289. if (hr.error == 0)
  1290. *ph_control =
  1291. hpi_indexes_to_handle(HPI_OBJ_CONTROL,
  1292. hm.adapter_index, control_index);
  1293. else
  1294. *ph_control = 0;
  1295. }
  1296. return hr.error;
  1297. }
  1298. u16 hpi_mixer_store(const struct hpi_hsubsys *ph_subsys, u32 h_mixer,
  1299. enum HPI_MIXER_STORE_COMMAND command, u16 index)
  1300. {
  1301. struct hpi_message hm;
  1302. struct hpi_response hr;
  1303. hpi_init_message_response(&hm, &hr, HPI_OBJ_MIXER, HPI_MIXER_STORE);
  1304. u32TOINDEX(h_mixer, &hm.adapter_index);
  1305. hm.u.mx.store.command = command;
  1306. hm.u.mx.store.index = index;
  1307. hpi_send_recv(&hm, &hr);
  1308. return hr.error;
  1309. }
  1310. static
  1311. u16 hpi_control_param_set(const struct hpi_hsubsys *ph_subsys,
  1312. const u32 h_control, const u16 attrib, const u32 param1,
  1313. const u32 param2)
  1314. {
  1315. struct hpi_message hm;
  1316. struct hpi_response hr;
  1317. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1318. HPI_CONTROL_SET_STATE);
  1319. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1320. hm.u.c.attribute = attrib;
  1321. hm.u.c.param1 = param1;
  1322. hm.u.c.param2 = param2;
  1323. hpi_send_recv(&hm, &hr);
  1324. return hr.error;
  1325. }
  1326. static
  1327. u16 hpi_control_param_get(const struct hpi_hsubsys *ph_subsys,
  1328. const u32 h_control, const u16 attrib, u32 param1, u32 param2,
  1329. u32 *pparam1, u32 *pparam2)
  1330. {
  1331. struct hpi_message hm;
  1332. struct hpi_response hr;
  1333. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1334. HPI_CONTROL_GET_STATE);
  1335. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1336. hm.u.c.attribute = attrib;
  1337. hm.u.c.param1 = param1;
  1338. hm.u.c.param2 = param2;
  1339. hpi_send_recv(&hm, &hr);
  1340. if (pparam1)
  1341. *pparam1 = hr.u.c.param1;
  1342. if (pparam2)
  1343. *pparam2 = hr.u.c.param2;
  1344. return hr.error;
  1345. }
  1346. #define hpi_control_param1_get(s, h, a, p1) \
  1347. hpi_control_param_get(s, h, a, 0, 0, p1, NULL)
  1348. #define hpi_control_param2_get(s, h, a, p1, p2) \
  1349. hpi_control_param_get(s, h, a, 0, 0, p1, p2)
  1350. #define hpi_control_ex_param1_get(s, h, a, p1) \
  1351. hpi_control_ex_param_get(s, h, a, 0, 0, p1, NULL)
  1352. #define hpi_control_ex_param2_get(s, h, a, p1, p2) \
  1353. hpi_control_ex_param_get(s, h, a, 0, 0, p1, p2)
  1354. static
  1355. u16 hpi_control_query(const struct hpi_hsubsys *ph_subsys,
  1356. const u32 h_control, const u16 attrib, const u32 index,
  1357. const u32 param, u32 *psetting)
  1358. {
  1359. struct hpi_message hm;
  1360. struct hpi_response hr;
  1361. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1362. HPI_CONTROL_GET_INFO);
  1363. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1364. hm.u.c.attribute = attrib;
  1365. hm.u.c.param1 = index;
  1366. hm.u.c.param2 = param;
  1367. hpi_send_recv(&hm, &hr);
  1368. *psetting = hr.u.c.param1;
  1369. return hr.error;
  1370. }
  1371. static u16 hpi_control_get_string(const struct hpi_hsubsys *ph_subsys,
  1372. const u32 h_control, const u16 attribute, char *psz_string,
  1373. const u32 string_length)
  1374. {
  1375. unsigned int sub_string_index = 0, j = 0;
  1376. char c = 0;
  1377. unsigned int n = 0;
  1378. u16 hE = 0;
  1379. if ((string_length < 1) || (string_length > 256))
  1380. return HPI_ERROR_INVALID_CONTROL_VALUE;
  1381. for (sub_string_index = 0; sub_string_index < string_length;
  1382. sub_string_index += 8) {
  1383. struct hpi_message hm;
  1384. struct hpi_response hr;
  1385. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1386. HPI_CONTROL_GET_STATE);
  1387. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1388. hm.u.c.attribute = attribute;
  1389. hm.u.c.param1 = sub_string_index;
  1390. hm.u.c.param2 = 0;
  1391. hpi_send_recv(&hm, &hr);
  1392. if (sub_string_index == 0
  1393. && (hr.u.cu.chars8.remaining_chars + 8) >
  1394. string_length)
  1395. return HPI_ERROR_INVALID_CONTROL_VALUE;
  1396. if (hr.error) {
  1397. hE = hr.error;
  1398. break;
  1399. }
  1400. for (j = 0; j < 8; j++) {
  1401. c = hr.u.cu.chars8.sz_data[j];
  1402. psz_string[sub_string_index + j] = c;
  1403. n++;
  1404. if (n >= string_length) {
  1405. psz_string[string_length - 1] = 0;
  1406. hE = HPI_ERROR_INVALID_CONTROL_VALUE;
  1407. break;
  1408. }
  1409. if (c == 0)
  1410. break;
  1411. }
  1412. if ((hr.u.cu.chars8.remaining_chars == 0)
  1413. && ((sub_string_index + j) < string_length)
  1414. && (c != 0)) {
  1415. c = 0;
  1416. psz_string[sub_string_index + j] = c;
  1417. }
  1418. if (c == 0)
  1419. break;
  1420. }
  1421. return hE;
  1422. }
  1423. u16 HPI_AESEBU__receiver_query_format(const struct hpi_hsubsys *ph_subsys,
  1424. const u32 h_aes_rx, const u32 index, u16 *pw_format)
  1425. {
  1426. u32 qr;
  1427. u16 err;
  1428. err = hpi_control_query(ph_subsys, h_aes_rx, HPI_AESEBURX_FORMAT,
  1429. index, 0, &qr);
  1430. *pw_format = (u16)qr;
  1431. return err;
  1432. }
  1433. u16 HPI_AESEBU__receiver_set_format(const struct hpi_hsubsys *ph_subsys,
  1434. u32 h_control, u16 format)
  1435. {
  1436. return hpi_control_param_set(ph_subsys, h_control,
  1437. HPI_AESEBURX_FORMAT, format, 0);
  1438. }
  1439. u16 HPI_AESEBU__receiver_get_format(const struct hpi_hsubsys *ph_subsys,
  1440. u32 h_control, u16 *pw_format)
  1441. {
  1442. u16 err;
  1443. u32 param;
  1444. err = hpi_control_param1_get(ph_subsys, h_control,
  1445. HPI_AESEBURX_FORMAT, &param);
  1446. if (!err && pw_format)
  1447. *pw_format = (u16)param;
  1448. return err;
  1449. }
  1450. u16 HPI_AESEBU__receiver_get_sample_rate(const struct hpi_hsubsys *ph_subsys,
  1451. u32 h_control, u32 *psample_rate)
  1452. {
  1453. return hpi_control_param1_get(ph_subsys, h_control,
  1454. HPI_AESEBURX_SAMPLERATE, psample_rate);
  1455. }
  1456. u16 HPI_AESEBU__receiver_get_user_data(const struct hpi_hsubsys *ph_subsys,
  1457. u32 h_control, u16 index, u16 *pw_data)
  1458. {
  1459. struct hpi_message hm;
  1460. struct hpi_response hr;
  1461. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1462. HPI_CONTROL_GET_STATE);
  1463. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1464. hm.u.c.attribute = HPI_AESEBURX_USERDATA;
  1465. hm.u.c.param1 = index;
  1466. hpi_send_recv(&hm, &hr);
  1467. if (pw_data)
  1468. *pw_data = (u16)hr.u.c.param2;
  1469. return hr.error;
  1470. }
  1471. u16 HPI_AESEBU__receiver_get_channel_status(const struct hpi_hsubsys
  1472. *ph_subsys, u32 h_control, u16 index, u16 *pw_data)
  1473. {
  1474. struct hpi_message hm;
  1475. struct hpi_response hr;
  1476. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1477. HPI_CONTROL_GET_STATE);
  1478. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1479. hm.u.c.attribute = HPI_AESEBURX_CHANNELSTATUS;
  1480. hm.u.c.param1 = index;
  1481. hpi_send_recv(&hm, &hr);
  1482. if (pw_data)
  1483. *pw_data = (u16)hr.u.c.param2;
  1484. return hr.error;
  1485. }
  1486. u16 HPI_AESEBU__receiver_get_error_status(const struct hpi_hsubsys *ph_subsys,
  1487. u32 h_control, u16 *pw_error_data)
  1488. {
  1489. u32 error_data = 0;
  1490. u16 error = 0;
  1491. error = hpi_control_param1_get(ph_subsys, h_control,
  1492. HPI_AESEBURX_ERRORSTATUS, &error_data);
  1493. if (pw_error_data)
  1494. *pw_error_data = (u16)error_data;
  1495. return error;
  1496. }
  1497. u16 HPI_AESEBU__transmitter_set_sample_rate(const struct hpi_hsubsys
  1498. *ph_subsys, u32 h_control, u32 sample_rate)
  1499. {
  1500. return hpi_control_param_set(ph_subsys, h_control,
  1501. HPI_AESEBUTX_SAMPLERATE, sample_rate, 0);
  1502. }
  1503. u16 HPI_AESEBU__transmitter_set_user_data(const struct hpi_hsubsys *ph_subsys,
  1504. u32 h_control, u16 index, u16 data)
  1505. {
  1506. return hpi_control_param_set(ph_subsys, h_control,
  1507. HPI_AESEBUTX_USERDATA, index, data);
  1508. }
  1509. u16 HPI_AESEBU__transmitter_set_channel_status(const struct hpi_hsubsys
  1510. *ph_subsys, u32 h_control, u16 index, u16 data)
  1511. {
  1512. return hpi_control_param_set(ph_subsys, h_control,
  1513. HPI_AESEBUTX_CHANNELSTATUS, index, data);
  1514. }
  1515. u16 HPI_AESEBU__transmitter_get_channel_status(const struct hpi_hsubsys
  1516. *ph_subsys, u32 h_control, u16 index, u16 *pw_data)
  1517. {
  1518. return HPI_ERROR_INVALID_OPERATION;
  1519. }
  1520. u16 HPI_AESEBU__transmitter_query_format(const struct hpi_hsubsys *ph_subsys,
  1521. const u32 h_aes_tx, const u32 index, u16 *pw_format)
  1522. {
  1523. u32 qr;
  1524. u16 err;
  1525. err = hpi_control_query(ph_subsys, h_aes_tx, HPI_AESEBUTX_FORMAT,
  1526. index, 0, &qr);
  1527. *pw_format = (u16)qr;
  1528. return err;
  1529. }
  1530. u16 HPI_AESEBU__transmitter_set_format(const struct hpi_hsubsys *ph_subsys,
  1531. u32 h_control, u16 output_format)
  1532. {
  1533. return hpi_control_param_set(ph_subsys, h_control,
  1534. HPI_AESEBUTX_FORMAT, output_format, 0);
  1535. }
  1536. u16 HPI_AESEBU__transmitter_get_format(const struct hpi_hsubsys *ph_subsys,
  1537. u32 h_control, u16 *pw_output_format)
  1538. {
  1539. u16 err;
  1540. u32 param;
  1541. err = hpi_control_param1_get(ph_subsys, h_control,
  1542. HPI_AESEBUTX_FORMAT, &param);
  1543. if (!err && pw_output_format)
  1544. *pw_output_format = (u16)param;
  1545. return err;
  1546. }
  1547. u16 hpi_bitstream_set_clock_edge(const struct hpi_hsubsys *ph_subsys,
  1548. u32 h_control, u16 edge_type)
  1549. {
  1550. return hpi_control_param_set(ph_subsys, h_control,
  1551. HPI_BITSTREAM_CLOCK_EDGE, edge_type, 0);
  1552. }
  1553. u16 hpi_bitstream_set_data_polarity(const struct hpi_hsubsys *ph_subsys,
  1554. u32 h_control, u16 polarity)
  1555. {
  1556. return hpi_control_param_set(ph_subsys, h_control,
  1557. HPI_BITSTREAM_DATA_POLARITY, polarity, 0);
  1558. }
  1559. u16 hpi_bitstream_get_activity(const struct hpi_hsubsys *ph_subsys,
  1560. u32 h_control, u16 *pw_clk_activity, u16 *pw_data_activity)
  1561. {
  1562. struct hpi_message hm;
  1563. struct hpi_response hr;
  1564. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1565. HPI_CONTROL_GET_STATE);
  1566. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1567. hm.u.c.attribute = HPI_BITSTREAM_ACTIVITY;
  1568. hpi_send_recv(&hm, &hr);
  1569. if (pw_clk_activity)
  1570. *pw_clk_activity = (u16)hr.u.c.param1;
  1571. if (pw_data_activity)
  1572. *pw_data_activity = (u16)hr.u.c.param2;
  1573. return hr.error;
  1574. }
  1575. u16 hpi_channel_mode_query_mode(const struct hpi_hsubsys *ph_subsys,
  1576. const u32 h_mode, const u32 index, u16 *pw_mode)
  1577. {
  1578. u32 qr;
  1579. u16 err;
  1580. err = hpi_control_query(ph_subsys, h_mode, HPI_CHANNEL_MODE_MODE,
  1581. index, 0, &qr);
  1582. *pw_mode = (u16)qr;
  1583. return err;
  1584. }
  1585. u16 hpi_channel_mode_set(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1586. u16 mode)
  1587. {
  1588. return hpi_control_param_set(ph_subsys, h_control,
  1589. HPI_CHANNEL_MODE_MODE, mode, 0);
  1590. }
  1591. u16 hpi_channel_mode_get(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1592. u16 *mode)
  1593. {
  1594. u32 mode32 = 0;
  1595. u16 error = hpi_control_param1_get(ph_subsys, h_control,
  1596. HPI_CHANNEL_MODE_MODE, &mode32);
  1597. if (mode)
  1598. *mode = (u16)mode32;
  1599. return error;
  1600. }
  1601. u16 hpi_cobranet_hmi_write(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1602. u32 hmi_address, u32 byte_count, u8 *pb_data)
  1603. {
  1604. struct hpi_message hm;
  1605. struct hpi_response hr;
  1606. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
  1607. HPI_CONTROL_SET_STATE);
  1608. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1609. hm.u.cx.u.cobranet_data.byte_count = byte_count;
  1610. hm.u.cx.u.cobranet_data.hmi_address = hmi_address;
  1611. if (byte_count <= 8) {
  1612. memcpy(hm.u.cx.u.cobranet_data.data, pb_data, byte_count);
  1613. hm.u.cx.attribute = HPI_COBRANET_SET;
  1614. } else {
  1615. hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
  1616. hm.u.cx.attribute = HPI_COBRANET_SET_DATA;
  1617. }
  1618. hpi_send_recv(&hm, &hr);
  1619. return hr.error;
  1620. }
  1621. u16 hpi_cobranet_hmi_read(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1622. u32 hmi_address, u32 max_byte_count, u32 *pbyte_count, u8 *pb_data)
  1623. {
  1624. struct hpi_message hm;
  1625. struct hpi_response hr;
  1626. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
  1627. HPI_CONTROL_GET_STATE);
  1628. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1629. hm.u.cx.u.cobranet_data.byte_count = max_byte_count;
  1630. hm.u.cx.u.cobranet_data.hmi_address = hmi_address;
  1631. if (max_byte_count <= 8) {
  1632. hm.u.cx.attribute = HPI_COBRANET_GET;
  1633. } else {
  1634. hm.u.cx.u.cobranet_bigdata.pb_data = pb_data;
  1635. hm.u.cx.attribute = HPI_COBRANET_GET_DATA;
  1636. }
  1637. hpi_send_recv(&hm, &hr);
  1638. if (!hr.error && pb_data) {
  1639. *pbyte_count = hr.u.cx.u.cobranet_data.byte_count;
  1640. if (*pbyte_count < max_byte_count)
  1641. max_byte_count = *pbyte_count;
  1642. if (hm.u.cx.attribute == HPI_COBRANET_GET) {
  1643. memcpy(pb_data, hr.u.cx.u.cobranet_data.data,
  1644. max_byte_count);
  1645. } else {
  1646. }
  1647. }
  1648. return hr.error;
  1649. }
  1650. u16 hpi_cobranet_hmi_get_status(const struct hpi_hsubsys *ph_subsys,
  1651. u32 h_control, u32 *pstatus, u32 *preadable_size,
  1652. u32 *pwriteable_size)
  1653. {
  1654. struct hpi_message hm;
  1655. struct hpi_response hr;
  1656. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROLEX,
  1657. HPI_CONTROL_GET_STATE);
  1658. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1659. hm.u.cx.attribute = HPI_COBRANET_GET_STATUS;
  1660. hpi_send_recv(&hm, &hr);
  1661. if (!hr.error) {
  1662. if (pstatus)
  1663. *pstatus = hr.u.cx.u.cobranet_status.status;
  1664. if (preadable_size)
  1665. *preadable_size =
  1666. hr.u.cx.u.cobranet_status.readable_size;
  1667. if (pwriteable_size)
  1668. *pwriteable_size =
  1669. hr.u.cx.u.cobranet_status.writeable_size;
  1670. }
  1671. return hr.error;
  1672. }
  1673. u16 hpi_cobranet_getI_paddress(const struct hpi_hsubsys *ph_subsys,
  1674. u32 h_control, u32 *pi_paddress)
  1675. {
  1676. u32 byte_count;
  1677. u32 iP;
  1678. u16 error;
  1679. error = hpi_cobranet_hmi_read(ph_subsys, h_control,
  1680. HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, &byte_count,
  1681. (u8 *)&iP);
  1682. *pi_paddress =
  1683. ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
  1684. 0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
  1685. if (error)
  1686. *pi_paddress = 0;
  1687. return error;
  1688. }
  1689. u16 hpi_cobranet_setI_paddress(const struct hpi_hsubsys *ph_subsys,
  1690. u32 h_control, u32 i_paddress)
  1691. {
  1692. u32 iP;
  1693. u16 error;
  1694. iP = ((i_paddress & 0xff000000) >> 8) | ((i_paddress & 0x00ff0000) <<
  1695. 8) | ((i_paddress & 0x0000ff00) >> 8) | ((i_paddress &
  1696. 0x000000ff) << 8);
  1697. error = hpi_cobranet_hmi_write(ph_subsys, h_control,
  1698. HPI_COBRANET_HMI_cobra_ip_mon_currentIP, 4, (u8 *)&iP);
  1699. return error;
  1700. }
  1701. u16 hpi_cobranet_get_staticI_paddress(const struct hpi_hsubsys *ph_subsys,
  1702. u32 h_control, u32 *pi_paddress)
  1703. {
  1704. u32 byte_count;
  1705. u32 iP;
  1706. u16 error;
  1707. error = hpi_cobranet_hmi_read(ph_subsys, h_control,
  1708. HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, &byte_count,
  1709. (u8 *)&iP);
  1710. *pi_paddress =
  1711. ((iP & 0xff000000) >> 8) | ((iP & 0x00ff0000) << 8) | ((iP &
  1712. 0x0000ff00) >> 8) | ((iP & 0x000000ff) << 8);
  1713. if (error)
  1714. *pi_paddress = 0;
  1715. return error;
  1716. }
  1717. u16 hpi_cobranet_set_staticI_paddress(const struct hpi_hsubsys *ph_subsys,
  1718. u32 h_control, u32 i_paddress)
  1719. {
  1720. u32 iP;
  1721. u16 error;
  1722. iP = ((i_paddress & 0xff000000) >> 8) | ((i_paddress & 0x00ff0000) <<
  1723. 8) | ((i_paddress & 0x0000ff00) >> 8) | ((i_paddress &
  1724. 0x000000ff) << 8);
  1725. error = hpi_cobranet_hmi_write(ph_subsys, h_control,
  1726. HPI_COBRANET_HMI_cobra_ip_mon_staticIP, 4, (u8 *)&iP);
  1727. return error;
  1728. }
  1729. u16 hpi_cobranet_getMA_caddress(const struct hpi_hsubsys *ph_subsys,
  1730. u32 h_control, u32 *pmAC_MS_bs, u32 *pmAC_LS_bs)
  1731. {
  1732. u32 byte_count;
  1733. u16 error;
  1734. u32 mAC;
  1735. error = hpi_cobranet_hmi_read(ph_subsys, h_control,
  1736. HPI_COBRANET_HMI_cobra_if_phy_address, 4, &byte_count,
  1737. (u8 *)&mAC);
  1738. *pmAC_MS_bs =
  1739. ((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC
  1740. & 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8);
  1741. error += hpi_cobranet_hmi_read(ph_subsys, h_control,
  1742. HPI_COBRANET_HMI_cobra_if_phy_address + 1, 4, &byte_count,
  1743. (u8 *)&mAC);
  1744. *pmAC_LS_bs =
  1745. ((mAC & 0xff000000) >> 8) | ((mAC & 0x00ff0000) << 8) | ((mAC
  1746. & 0x0000ff00) >> 8) | ((mAC & 0x000000ff) << 8);
  1747. if (error) {
  1748. *pmAC_MS_bs = 0;
  1749. *pmAC_LS_bs = 0;
  1750. }
  1751. return error;
  1752. }
  1753. u16 hpi_compander_set(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1754. u16 attack, u16 decay, short ratio100, short threshold0_01dB,
  1755. short makeup_gain0_01dB)
  1756. {
  1757. struct hpi_message hm;
  1758. struct hpi_response hr;
  1759. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1760. HPI_CONTROL_SET_STATE);
  1761. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1762. hm.u.c.param1 = attack + ((u32)ratio100 << 16);
  1763. hm.u.c.param2 = (decay & 0xFFFFL);
  1764. hm.u.c.an_log_value[0] = threshold0_01dB;
  1765. hm.u.c.an_log_value[1] = makeup_gain0_01dB;
  1766. hm.u.c.attribute = HPI_COMPANDER_PARAMS;
  1767. hpi_send_recv(&hm, &hr);
  1768. return hr.error;
  1769. }
  1770. u16 hpi_compander_get(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1771. u16 *pw_attack, u16 *pw_decay, short *pw_ratio100,
  1772. short *pn_threshold0_01dB, short *pn_makeup_gain0_01dB)
  1773. {
  1774. struct hpi_message hm;
  1775. struct hpi_response hr;
  1776. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1777. HPI_CONTROL_GET_STATE);
  1778. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1779. hm.u.c.attribute = HPI_COMPANDER_PARAMS;
  1780. hpi_send_recv(&hm, &hr);
  1781. if (pw_attack)
  1782. *pw_attack = (short)(hr.u.c.param1 & 0xFFFF);
  1783. if (pw_decay)
  1784. *pw_decay = (short)(hr.u.c.param2 & 0xFFFF);
  1785. if (pw_ratio100)
  1786. *pw_ratio100 = (short)(hr.u.c.param1 >> 16);
  1787. if (pn_threshold0_01dB)
  1788. *pn_threshold0_01dB = hr.u.c.an_log_value[0];
  1789. if (pn_makeup_gain0_01dB)
  1790. *pn_makeup_gain0_01dB = hr.u.c.an_log_value[1];
  1791. return hr.error;
  1792. }
  1793. u16 hpi_level_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1794. short *min_gain_01dB, short *max_gain_01dB, short *step_gain_01dB)
  1795. {
  1796. struct hpi_message hm;
  1797. struct hpi_response hr;
  1798. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1799. HPI_CONTROL_GET_STATE);
  1800. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1801. hm.u.c.attribute = HPI_LEVEL_RANGE;
  1802. hpi_send_recv(&hm, &hr);
  1803. if (hr.error) {
  1804. hr.u.c.an_log_value[0] = 0;
  1805. hr.u.c.an_log_value[1] = 0;
  1806. hr.u.c.param1 = 0;
  1807. }
  1808. if (min_gain_01dB)
  1809. *min_gain_01dB = hr.u.c.an_log_value[0];
  1810. if (max_gain_01dB)
  1811. *max_gain_01dB = hr.u.c.an_log_value[1];
  1812. if (step_gain_01dB)
  1813. *step_gain_01dB = (short)hr.u.c.param1;
  1814. return hr.error;
  1815. }
  1816. u16 hpi_level_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1817. short an_gain0_01dB[HPI_MAX_CHANNELS]
  1818. )
  1819. {
  1820. struct hpi_message hm;
  1821. struct hpi_response hr;
  1822. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1823. HPI_CONTROL_SET_STATE);
  1824. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1825. memcpy(hm.u.c.an_log_value, an_gain0_01dB,
  1826. sizeof(short) * HPI_MAX_CHANNELS);
  1827. hm.u.c.attribute = HPI_LEVEL_GAIN;
  1828. hpi_send_recv(&hm, &hr);
  1829. return hr.error;
  1830. }
  1831. u16 hpi_level_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1832. short an_gain0_01dB[HPI_MAX_CHANNELS]
  1833. )
  1834. {
  1835. struct hpi_message hm;
  1836. struct hpi_response hr;
  1837. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1838. HPI_CONTROL_GET_STATE);
  1839. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1840. hm.u.c.attribute = HPI_LEVEL_GAIN;
  1841. hpi_send_recv(&hm, &hr);
  1842. memcpy(an_gain0_01dB, hr.u.c.an_log_value,
  1843. sizeof(short) * HPI_MAX_CHANNELS);
  1844. return hr.error;
  1845. }
  1846. u16 hpi_meter_query_channels(const struct hpi_hsubsys *ph_subsys,
  1847. const u32 h_meter, u32 *p_channels)
  1848. {
  1849. return hpi_control_query(ph_subsys, h_meter, HPI_METER_NUM_CHANNELS,
  1850. 0, 0, p_channels);
  1851. }
  1852. u16 hpi_meter_get_peak(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1853. short an_peakdB[HPI_MAX_CHANNELS]
  1854. )
  1855. {
  1856. short i = 0;
  1857. struct hpi_message hm;
  1858. struct hpi_response hr;
  1859. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1860. HPI_CONTROL_GET_STATE);
  1861. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1862. hm.obj_index = hm.obj_index;
  1863. hm.u.c.attribute = HPI_METER_PEAK;
  1864. hpi_send_recv(&hm, &hr);
  1865. if (!hr.error)
  1866. memcpy(an_peakdB, hr.u.c.an_log_value,
  1867. sizeof(short) * HPI_MAX_CHANNELS);
  1868. else
  1869. for (i = 0; i < HPI_MAX_CHANNELS; i++)
  1870. an_peakdB[i] = HPI_METER_MINIMUM;
  1871. return hr.error;
  1872. }
  1873. u16 hpi_meter_get_rms(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  1874. short an_rmsdB[HPI_MAX_CHANNELS]
  1875. )
  1876. {
  1877. short i = 0;
  1878. struct hpi_message hm;
  1879. struct hpi_response hr;
  1880. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1881. HPI_CONTROL_GET_STATE);
  1882. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1883. hm.u.c.attribute = HPI_METER_RMS;
  1884. hpi_send_recv(&hm, &hr);
  1885. if (!hr.error)
  1886. memcpy(an_rmsdB, hr.u.c.an_log_value,
  1887. sizeof(short) * HPI_MAX_CHANNELS);
  1888. else
  1889. for (i = 0; i < HPI_MAX_CHANNELS; i++)
  1890. an_rmsdB[i] = HPI_METER_MINIMUM;
  1891. return hr.error;
  1892. }
  1893. u16 hpi_meter_set_rms_ballistics(const struct hpi_hsubsys *ph_subsys,
  1894. u32 h_control, u16 attack, u16 decay)
  1895. {
  1896. return hpi_control_param_set(ph_subsys, h_control,
  1897. HPI_METER_RMS_BALLISTICS, attack, decay);
  1898. }
  1899. u16 hpi_meter_get_rms_ballistics(const struct hpi_hsubsys *ph_subsys,
  1900. u32 h_control, u16 *pn_attack, u16 *pn_decay)
  1901. {
  1902. u32 attack;
  1903. u32 decay;
  1904. u16 error;
  1905. error = hpi_control_param2_get(ph_subsys, h_control,
  1906. HPI_METER_RMS_BALLISTICS, &attack, &decay);
  1907. if (pn_attack)
  1908. *pn_attack = (unsigned short)attack;
  1909. if (pn_decay)
  1910. *pn_decay = (unsigned short)decay;
  1911. return error;
  1912. }
  1913. u16 hpi_meter_set_peak_ballistics(const struct hpi_hsubsys *ph_subsys,
  1914. u32 h_control, u16 attack, u16 decay)
  1915. {
  1916. return hpi_control_param_set(ph_subsys, h_control,
  1917. HPI_METER_PEAK_BALLISTICS, attack, decay);
  1918. }
  1919. u16 hpi_meter_get_peak_ballistics(const struct hpi_hsubsys *ph_subsys,
  1920. u32 h_control, u16 *pn_attack, u16 *pn_decay)
  1921. {
  1922. u32 attack;
  1923. u32 decay;
  1924. u16 error;
  1925. error = hpi_control_param2_get(ph_subsys, h_control,
  1926. HPI_METER_PEAK_BALLISTICS, &attack, &decay);
  1927. if (pn_attack)
  1928. *pn_attack = (short)attack;
  1929. if (pn_decay)
  1930. *pn_decay = (short)decay;
  1931. return error;
  1932. }
  1933. u16 hpi_microphone_set_phantom_power(const struct hpi_hsubsys *ph_subsys,
  1934. u32 h_control, u16 on_off)
  1935. {
  1936. return hpi_control_param_set(ph_subsys, h_control,
  1937. HPI_MICROPHONE_PHANTOM_POWER, (u32)on_off, 0);
  1938. }
  1939. u16 hpi_microphone_get_phantom_power(const struct hpi_hsubsys *ph_subsys,
  1940. u32 h_control, u16 *pw_on_off)
  1941. {
  1942. u16 error = 0;
  1943. u32 on_off = 0;
  1944. error = hpi_control_param1_get(ph_subsys, h_control,
  1945. HPI_MICROPHONE_PHANTOM_POWER, &on_off);
  1946. if (pw_on_off)
  1947. *pw_on_off = (u16)on_off;
  1948. return error;
  1949. }
  1950. u16 hpi_multiplexer_set_source(const struct hpi_hsubsys *ph_subsys,
  1951. u32 h_control, u16 source_node_type, u16 source_node_index)
  1952. {
  1953. return hpi_control_param_set(ph_subsys, h_control,
  1954. HPI_MULTIPLEXER_SOURCE, source_node_type, source_node_index);
  1955. }
  1956. u16 hpi_multiplexer_get_source(const struct hpi_hsubsys *ph_subsys,
  1957. u32 h_control, u16 *source_node_type, u16 *source_node_index)
  1958. {
  1959. u32 node, index;
  1960. u16 error = hpi_control_param2_get(ph_subsys, h_control,
  1961. HPI_MULTIPLEXER_SOURCE, &node,
  1962. &index);
  1963. if (source_node_type)
  1964. *source_node_type = (u16)node;
  1965. if (source_node_index)
  1966. *source_node_index = (u16)index;
  1967. return error;
  1968. }
  1969. u16 hpi_multiplexer_query_source(const struct hpi_hsubsys *ph_subsys,
  1970. u32 h_control, u16 index, u16 *source_node_type,
  1971. u16 *source_node_index)
  1972. {
  1973. struct hpi_message hm;
  1974. struct hpi_response hr;
  1975. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  1976. HPI_CONTROL_GET_STATE);
  1977. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  1978. hm.u.c.attribute = HPI_MULTIPLEXER_QUERYSOURCE;
  1979. hm.u.c.param1 = index;
  1980. hpi_send_recv(&hm, &hr);
  1981. if (source_node_type)
  1982. *source_node_type = (u16)hr.u.c.param1;
  1983. if (source_node_index)
  1984. *source_node_index = (u16)hr.u.c.param2;
  1985. return hr.error;
  1986. }
  1987. u16 hpi_parametricEQ__get_info(const struct hpi_hsubsys *ph_subsys,
  1988. u32 h_control, u16 *pw_number_of_bands, u16 *pw_on_off)
  1989. {
  1990. u32 oB = 0;
  1991. u32 oO = 0;
  1992. u16 error = 0;
  1993. error = hpi_control_param2_get(ph_subsys, h_control,
  1994. HPI_EQUALIZER_NUM_FILTERS, &oO, &oB);
  1995. if (pw_number_of_bands)
  1996. *pw_number_of_bands = (u16)oB;
  1997. if (pw_on_off)
  1998. *pw_on_off = (u16)oO;
  1999. return error;
  2000. }
  2001. u16 hpi_parametricEQ__set_state(const struct hpi_hsubsys *ph_subsys,
  2002. u32 h_control, u16 on_off)
  2003. {
  2004. return hpi_control_param_set(ph_subsys, h_control,
  2005. HPI_EQUALIZER_NUM_FILTERS, on_off, 0);
  2006. }
  2007. u16 hpi_parametricEQ__get_band(const struct hpi_hsubsys *ph_subsys,
  2008. u32 h_control, u16 index, u16 *pn_type, u32 *pfrequency_hz,
  2009. short *pnQ100, short *pn_gain0_01dB)
  2010. {
  2011. struct hpi_message hm;
  2012. struct hpi_response hr;
  2013. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2014. HPI_CONTROL_GET_STATE);
  2015. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2016. hm.u.c.attribute = HPI_EQUALIZER_FILTER;
  2017. hm.u.c.param2 = index;
  2018. hpi_send_recv(&hm, &hr);
  2019. if (pfrequency_hz)
  2020. *pfrequency_hz = hr.u.c.param1;
  2021. if (pn_type)
  2022. *pn_type = (u16)(hr.u.c.param2 >> 16);
  2023. if (pnQ100)
  2024. *pnQ100 = hr.u.c.an_log_value[1];
  2025. if (pn_gain0_01dB)
  2026. *pn_gain0_01dB = hr.u.c.an_log_value[0];
  2027. return hr.error;
  2028. }
  2029. u16 hpi_parametricEQ__set_band(const struct hpi_hsubsys *ph_subsys,
  2030. u32 h_control, u16 index, u16 type, u32 frequency_hz, short q100,
  2031. short gain0_01dB)
  2032. {
  2033. struct hpi_message hm;
  2034. struct hpi_response hr;
  2035. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2036. HPI_CONTROL_SET_STATE);
  2037. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2038. hm.u.c.param1 = frequency_hz;
  2039. hm.u.c.param2 = (index & 0xFFFFL) + ((u32)type << 16);
  2040. hm.u.c.an_log_value[0] = gain0_01dB;
  2041. hm.u.c.an_log_value[1] = q100;
  2042. hm.u.c.attribute = HPI_EQUALIZER_FILTER;
  2043. hpi_send_recv(&hm, &hr);
  2044. return hr.error;
  2045. }
  2046. u16 hpi_parametricEQ__get_coeffs(const struct hpi_hsubsys *ph_subsys,
  2047. u32 h_control, u16 index, short coeffs[5]
  2048. )
  2049. {
  2050. struct hpi_message hm;
  2051. struct hpi_response hr;
  2052. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2053. HPI_CONTROL_GET_STATE);
  2054. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2055. hm.u.c.attribute = HPI_EQUALIZER_COEFFICIENTS;
  2056. hm.u.c.param2 = index;
  2057. hpi_send_recv(&hm, &hr);
  2058. coeffs[0] = (short)hr.u.c.an_log_value[0];
  2059. coeffs[1] = (short)hr.u.c.an_log_value[1];
  2060. coeffs[2] = (short)hr.u.c.param1;
  2061. coeffs[3] = (short)(hr.u.c.param1 >> 16);
  2062. coeffs[4] = (short)hr.u.c.param2;
  2063. return hr.error;
  2064. }
  2065. u16 hpi_sample_clock_query_source(const struct hpi_hsubsys *ph_subsys,
  2066. const u32 h_clock, const u32 index, u16 *pw_source)
  2067. {
  2068. u32 qr;
  2069. u16 err;
  2070. err = hpi_control_query(ph_subsys, h_clock, HPI_SAMPLECLOCK_SOURCE,
  2071. index, 0, &qr);
  2072. *pw_source = (u16)qr;
  2073. return err;
  2074. }
  2075. u16 hpi_sample_clock_set_source(const struct hpi_hsubsys *ph_subsys,
  2076. u32 h_control, u16 source)
  2077. {
  2078. return hpi_control_param_set(ph_subsys, h_control,
  2079. HPI_SAMPLECLOCK_SOURCE, source, 0);
  2080. }
  2081. u16 hpi_sample_clock_get_source(const struct hpi_hsubsys *ph_subsys,
  2082. u32 h_control, u16 *pw_source)
  2083. {
  2084. u16 error = 0;
  2085. u32 source = 0;
  2086. error = hpi_control_param1_get(ph_subsys, h_control,
  2087. HPI_SAMPLECLOCK_SOURCE, &source);
  2088. if (!error)
  2089. if (pw_source)
  2090. *pw_source = (u16)source;
  2091. return error;
  2092. }
  2093. u16 hpi_sample_clock_query_source_index(const struct hpi_hsubsys *ph_subsys,
  2094. const u32 h_clock, const u32 index, const u32 source,
  2095. u16 *pw_source_index)
  2096. {
  2097. u32 qr;
  2098. u16 err;
  2099. err = hpi_control_query(ph_subsys, h_clock,
  2100. HPI_SAMPLECLOCK_SOURCE_INDEX, index, source, &qr);
  2101. *pw_source_index = (u16)qr;
  2102. return err;
  2103. }
  2104. u16 hpi_sample_clock_set_source_index(const struct hpi_hsubsys *ph_subsys,
  2105. u32 h_control, u16 source_index)
  2106. {
  2107. return hpi_control_param_set(ph_subsys, h_control,
  2108. HPI_SAMPLECLOCK_SOURCE_INDEX, source_index, 0);
  2109. }
  2110. u16 hpi_sample_clock_get_source_index(const struct hpi_hsubsys *ph_subsys,
  2111. u32 h_control, u16 *pw_source_index)
  2112. {
  2113. u16 error = 0;
  2114. u32 source_index = 0;
  2115. error = hpi_control_param1_get(ph_subsys, h_control,
  2116. HPI_SAMPLECLOCK_SOURCE_INDEX, &source_index);
  2117. if (!error)
  2118. if (pw_source_index)
  2119. *pw_source_index = (u16)source_index;
  2120. return error;
  2121. }
  2122. u16 hpi_sample_clock_query_local_rate(const struct hpi_hsubsys *ph_subsys,
  2123. const u32 h_clock, const u32 index, u32 *prate)
  2124. {
  2125. u16 err;
  2126. err = hpi_control_query(ph_subsys, h_clock,
  2127. HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, index, 0, prate);
  2128. return err;
  2129. }
  2130. u16 hpi_sample_clock_set_local_rate(const struct hpi_hsubsys *ph_subsys,
  2131. u32 h_control, u32 sample_rate)
  2132. {
  2133. return hpi_control_param_set(ph_subsys, h_control,
  2134. HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, sample_rate, 0);
  2135. }
  2136. u16 hpi_sample_clock_get_local_rate(const struct hpi_hsubsys *ph_subsys,
  2137. u32 h_control, u32 *psample_rate)
  2138. {
  2139. u16 error = 0;
  2140. u32 sample_rate = 0;
  2141. error = hpi_control_param1_get(ph_subsys, h_control,
  2142. HPI_SAMPLECLOCK_LOCAL_SAMPLERATE, &sample_rate);
  2143. if (!error)
  2144. if (psample_rate)
  2145. *psample_rate = sample_rate;
  2146. return error;
  2147. }
  2148. u16 hpi_sample_clock_get_sample_rate(const struct hpi_hsubsys *ph_subsys,
  2149. u32 h_control, u32 *psample_rate)
  2150. {
  2151. u16 error = 0;
  2152. u32 sample_rate = 0;
  2153. error = hpi_control_param1_get(ph_subsys, h_control,
  2154. HPI_SAMPLECLOCK_SAMPLERATE, &sample_rate);
  2155. if (!error)
  2156. if (psample_rate)
  2157. *psample_rate = sample_rate;
  2158. return error;
  2159. }
  2160. u16 hpi_sample_clock_set_auto(const struct hpi_hsubsys *ph_subsys,
  2161. u32 h_control, u32 enable)
  2162. {
  2163. return hpi_control_param_set(ph_subsys, h_control,
  2164. HPI_SAMPLECLOCK_AUTO, enable, 0);
  2165. }
  2166. u16 hpi_sample_clock_get_auto(const struct hpi_hsubsys *ph_subsys,
  2167. u32 h_control, u32 *penable)
  2168. {
  2169. return hpi_control_param1_get(ph_subsys, h_control,
  2170. HPI_SAMPLECLOCK_AUTO, penable);
  2171. }
  2172. u16 hpi_sample_clock_set_local_rate_lock(const struct hpi_hsubsys *ph_subsys,
  2173. u32 h_control, u32 lock)
  2174. {
  2175. return hpi_control_param_set(ph_subsys, h_control,
  2176. HPI_SAMPLECLOCK_LOCAL_LOCK, lock, 0);
  2177. }
  2178. u16 hpi_sample_clock_get_local_rate_lock(const struct hpi_hsubsys *ph_subsys,
  2179. u32 h_control, u32 *plock)
  2180. {
  2181. return hpi_control_param1_get(ph_subsys, h_control,
  2182. HPI_SAMPLECLOCK_LOCAL_LOCK, plock);
  2183. }
  2184. u16 hpi_tone_detector_get_frequency(const struct hpi_hsubsys *ph_subsys,
  2185. u32 h_control, u32 index, u32 *frequency)
  2186. {
  2187. return hpi_control_param_get(ph_subsys, h_control,
  2188. HPI_TONEDETECTOR_FREQUENCY, index, 0, frequency, NULL);
  2189. }
  2190. u16 hpi_tone_detector_get_state(const struct hpi_hsubsys *ph_subsys,
  2191. u32 h_control, u32 *state)
  2192. {
  2193. return hpi_control_param_get(ph_subsys, h_control,
  2194. HPI_TONEDETECTOR_STATE, 0, 0, (u32 *)state, NULL);
  2195. }
  2196. u16 hpi_tone_detector_set_enable(const struct hpi_hsubsys *ph_subsys,
  2197. u32 h_control, u32 enable)
  2198. {
  2199. return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE,
  2200. (u32)enable, 0);
  2201. }
  2202. u16 hpi_tone_detector_get_enable(const struct hpi_hsubsys *ph_subsys,
  2203. u32 h_control, u32 *enable)
  2204. {
  2205. return hpi_control_param_get(ph_subsys, h_control, HPI_GENERIC_ENABLE,
  2206. 0, 0, (u32 *)enable, NULL);
  2207. }
  2208. u16 hpi_tone_detector_set_event_enable(const struct hpi_hsubsys *ph_subsys,
  2209. u32 h_control, u32 event_enable)
  2210. {
  2211. return hpi_control_param_set(ph_subsys, h_control,
  2212. HPI_GENERIC_EVENT_ENABLE, (u32)event_enable, 0);
  2213. }
  2214. u16 hpi_tone_detector_get_event_enable(const struct hpi_hsubsys *ph_subsys,
  2215. u32 h_control, u32 *event_enable)
  2216. {
  2217. return hpi_control_param_get(ph_subsys, h_control,
  2218. HPI_GENERIC_EVENT_ENABLE, 0, 0, (u32 *)event_enable, NULL);
  2219. }
  2220. u16 hpi_tone_detector_set_threshold(const struct hpi_hsubsys *ph_subsys,
  2221. u32 h_control, int threshold)
  2222. {
  2223. return hpi_control_param_set(ph_subsys, h_control,
  2224. HPI_TONEDETECTOR_THRESHOLD, (u32)threshold, 0);
  2225. }
  2226. u16 hpi_tone_detector_get_threshold(const struct hpi_hsubsys *ph_subsys,
  2227. u32 h_control, int *threshold)
  2228. {
  2229. return hpi_control_param_get(ph_subsys, h_control,
  2230. HPI_TONEDETECTOR_THRESHOLD, 0, 0, (u32 *)threshold, NULL);
  2231. }
  2232. u16 hpi_silence_detector_get_state(const struct hpi_hsubsys *ph_subsys,
  2233. u32 h_control, u32 *state)
  2234. {
  2235. return hpi_control_param_get(ph_subsys, h_control,
  2236. HPI_SILENCEDETECTOR_STATE, 0, 0, (u32 *)state, NULL);
  2237. }
  2238. u16 hpi_silence_detector_set_enable(const struct hpi_hsubsys *ph_subsys,
  2239. u32 h_control, u32 enable)
  2240. {
  2241. return hpi_control_param_set(ph_subsys, h_control, HPI_GENERIC_ENABLE,
  2242. (u32)enable, 0);
  2243. }
  2244. u16 hpi_silence_detector_get_enable(const struct hpi_hsubsys *ph_subsys,
  2245. u32 h_control, u32 *enable)
  2246. {
  2247. return hpi_control_param_get(ph_subsys, h_control, HPI_GENERIC_ENABLE,
  2248. 0, 0, (u32 *)enable, NULL);
  2249. }
  2250. u16 hpi_silence_detector_set_event_enable(const struct hpi_hsubsys *ph_subsys,
  2251. u32 h_control, u32 event_enable)
  2252. {
  2253. return hpi_control_param_set(ph_subsys, h_control,
  2254. HPI_GENERIC_EVENT_ENABLE, (u32)event_enable, 0);
  2255. }
  2256. u16 hpi_silence_detector_get_event_enable(const struct hpi_hsubsys *ph_subsys,
  2257. u32 h_control, u32 *event_enable)
  2258. {
  2259. return hpi_control_param_get(ph_subsys, h_control,
  2260. HPI_GENERIC_EVENT_ENABLE, 0, 0, (u32 *)event_enable, NULL);
  2261. }
  2262. u16 hpi_silence_detector_set_delay(const struct hpi_hsubsys *ph_subsys,
  2263. u32 h_control, u32 delay)
  2264. {
  2265. return hpi_control_param_set(ph_subsys, h_control,
  2266. HPI_SILENCEDETECTOR_DELAY, (u32)delay, 0);
  2267. }
  2268. u16 hpi_silence_detector_get_delay(const struct hpi_hsubsys *ph_subsys,
  2269. u32 h_control, u32 *delay)
  2270. {
  2271. return hpi_control_param_get(ph_subsys, h_control,
  2272. HPI_SILENCEDETECTOR_DELAY, 0, 0, (u32 *)delay, NULL);
  2273. }
  2274. u16 hpi_silence_detector_set_threshold(const struct hpi_hsubsys *ph_subsys,
  2275. u32 h_control, int threshold)
  2276. {
  2277. return hpi_control_param_set(ph_subsys, h_control,
  2278. HPI_SILENCEDETECTOR_THRESHOLD, (u32)threshold, 0);
  2279. }
  2280. u16 hpi_silence_detector_get_threshold(const struct hpi_hsubsys *ph_subsys,
  2281. u32 h_control, int *threshold)
  2282. {
  2283. return hpi_control_param_get(ph_subsys, h_control,
  2284. HPI_SILENCEDETECTOR_THRESHOLD, 0, 0, (u32 *)threshold, NULL);
  2285. }
  2286. u16 hpi_tuner_query_band(const struct hpi_hsubsys *ph_subsys,
  2287. const u32 h_tuner, const u32 index, u16 *pw_band)
  2288. {
  2289. u32 qr;
  2290. u16 err;
  2291. err = hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_BAND, index, 0,
  2292. &qr);
  2293. *pw_band = (u16)qr;
  2294. return err;
  2295. }
  2296. u16 hpi_tuner_set_band(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2297. u16 band)
  2298. {
  2299. return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_BAND,
  2300. band, 0);
  2301. }
  2302. u16 hpi_tuner_get_band(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2303. u16 *pw_band)
  2304. {
  2305. u32 band = 0;
  2306. u16 error = 0;
  2307. error = hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_BAND,
  2308. &band);
  2309. if (pw_band)
  2310. *pw_band = (u16)band;
  2311. return error;
  2312. }
  2313. u16 hpi_tuner_query_frequency(const struct hpi_hsubsys *ph_subsys,
  2314. const u32 h_tuner, const u32 index, const u16 band, u32 *pfreq)
  2315. {
  2316. return hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_FREQ, index,
  2317. band, pfreq);
  2318. }
  2319. u16 hpi_tuner_set_frequency(const struct hpi_hsubsys *ph_subsys,
  2320. u32 h_control, u32 freq_ink_hz)
  2321. {
  2322. return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_FREQ,
  2323. freq_ink_hz, 0);
  2324. }
  2325. u16 hpi_tuner_get_frequency(const struct hpi_hsubsys *ph_subsys,
  2326. u32 h_control, u32 *pw_freq_ink_hz)
  2327. {
  2328. return hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_FREQ,
  2329. pw_freq_ink_hz);
  2330. }
  2331. u16 hpi_tuner_query_gain(const struct hpi_hsubsys *ph_subsys,
  2332. const u32 h_tuner, const u32 index, u16 *pw_gain)
  2333. {
  2334. u32 qr;
  2335. u16 err;
  2336. err = hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_BAND, index, 0,
  2337. &qr);
  2338. *pw_gain = (u16)qr;
  2339. return err;
  2340. }
  2341. u16 hpi_tuner_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2342. short gain)
  2343. {
  2344. return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_GAIN,
  2345. gain, 0);
  2346. }
  2347. u16 hpi_tuner_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2348. short *pn_gain)
  2349. {
  2350. u32 gain = 0;
  2351. u16 error = 0;
  2352. error = hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_GAIN,
  2353. &gain);
  2354. if (pn_gain)
  2355. *pn_gain = (u16)gain;
  2356. return error;
  2357. }
  2358. u16 hpi_tuner_getRF_level(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2359. short *pw_level)
  2360. {
  2361. struct hpi_message hm;
  2362. struct hpi_response hr;
  2363. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2364. HPI_CONTROL_GET_STATE);
  2365. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2366. hm.u.c.attribute = HPI_TUNER_LEVEL;
  2367. hm.u.c.param1 = HPI_TUNER_LEVEL_AVERAGE;
  2368. hpi_send_recv(&hm, &hr);
  2369. if (pw_level)
  2370. *pw_level = (short)hr.u.c.param1;
  2371. return hr.error;
  2372. }
  2373. u16 hpi_tuner_get_rawRF_level(const struct hpi_hsubsys *ph_subsys,
  2374. u32 h_control, short *pw_level)
  2375. {
  2376. struct hpi_message hm;
  2377. struct hpi_response hr;
  2378. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2379. HPI_CONTROL_GET_STATE);
  2380. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2381. hm.u.c.attribute = HPI_TUNER_LEVEL;
  2382. hm.u.c.param1 = HPI_TUNER_LEVEL_RAW;
  2383. hpi_send_recv(&hm, &hr);
  2384. if (pw_level)
  2385. *pw_level = (short)hr.u.c.param1;
  2386. return hr.error;
  2387. }
  2388. u16 hpi_tuner_query_deemphasis(const struct hpi_hsubsys *ph_subsys,
  2389. const u32 h_tuner, const u32 index, const u16 band, u32 *pdeemphasis)
  2390. {
  2391. return hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_DEEMPHASIS,
  2392. index, band, pdeemphasis);
  2393. }
  2394. u16 hpi_tuner_set_deemphasis(const struct hpi_hsubsys *ph_subsys,
  2395. u32 h_control, u32 deemphasis)
  2396. {
  2397. return hpi_control_param_set(ph_subsys, h_control,
  2398. HPI_TUNER_DEEMPHASIS, deemphasis, 0);
  2399. }
  2400. u16 hpi_tuner_get_deemphasis(const struct hpi_hsubsys *ph_subsys,
  2401. u32 h_control, u32 *pdeemphasis)
  2402. {
  2403. return hpi_control_param1_get(ph_subsys, h_control,
  2404. HPI_TUNER_DEEMPHASIS, pdeemphasis);
  2405. }
  2406. u16 hpi_tuner_query_program(const struct hpi_hsubsys *ph_subsys,
  2407. const u32 h_tuner, u32 *pbitmap_program)
  2408. {
  2409. return hpi_control_query(ph_subsys, h_tuner, HPI_TUNER_PROGRAM, 0, 0,
  2410. pbitmap_program);
  2411. }
  2412. u16 hpi_tuner_set_program(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2413. u32 program)
  2414. {
  2415. return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_PROGRAM,
  2416. program, 0);
  2417. }
  2418. u16 hpi_tuner_get_program(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2419. u32 *pprogram)
  2420. {
  2421. return hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_PROGRAM,
  2422. pprogram);
  2423. }
  2424. u16 hpi_tuner_get_hd_radio_dsp_version(const struct hpi_hsubsys *ph_subsys,
  2425. u32 h_control, char *psz_dsp_version, const u32 string_size)
  2426. {
  2427. return hpi_control_get_string(ph_subsys, h_control,
  2428. HPI_TUNER_HDRADIO_DSP_VERSION, psz_dsp_version, string_size);
  2429. }
  2430. u16 hpi_tuner_get_hd_radio_sdk_version(const struct hpi_hsubsys *ph_subsys,
  2431. u32 h_control, char *psz_sdk_version, const u32 string_size)
  2432. {
  2433. return hpi_control_get_string(ph_subsys, h_control,
  2434. HPI_TUNER_HDRADIO_SDK_VERSION, psz_sdk_version, string_size);
  2435. }
  2436. u16 hpi_tuner_get_status(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2437. u16 *pw_status_mask, u16 *pw_status)
  2438. {
  2439. u32 status = 0;
  2440. u16 error = 0;
  2441. error = hpi_control_param1_get(ph_subsys, h_control, HPI_TUNER_STATUS,
  2442. &status);
  2443. if (pw_status) {
  2444. if (!error) {
  2445. *pw_status_mask = (u16)(status >> 16);
  2446. *pw_status = (u16)(status & 0xFFFF);
  2447. } else {
  2448. *pw_status_mask = 0;
  2449. *pw_status = 0;
  2450. }
  2451. }
  2452. return error;
  2453. }
  2454. u16 hpi_tuner_set_mode(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2455. u32 mode, u32 value)
  2456. {
  2457. return hpi_control_param_set(ph_subsys, h_control, HPI_TUNER_MODE,
  2458. mode, value);
  2459. }
  2460. u16 hpi_tuner_get_mode(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2461. u32 mode, u32 *pn_value)
  2462. {
  2463. return hpi_control_param_get(ph_subsys, h_control, HPI_TUNER_MODE,
  2464. mode, 0, pn_value, NULL);
  2465. }
  2466. u16 hpi_tuner_get_hd_radio_signal_quality(const struct hpi_hsubsys *ph_subsys,
  2467. u32 h_control, u32 *pquality)
  2468. {
  2469. return hpi_control_param_get(ph_subsys, h_control,
  2470. HPI_TUNER_HDRADIO_SIGNAL_QUALITY, 0, 0, pquality, NULL);
  2471. }
  2472. u16 hpi_tuner_get_hd_radio_signal_blend(const struct hpi_hsubsys *ph_subsys,
  2473. u32 h_control, u32 *pblend)
  2474. {
  2475. return hpi_control_param_get(ph_subsys, h_control,
  2476. HPI_TUNER_HDRADIO_BLEND, 0, 0, pblend, NULL);
  2477. }
  2478. u16 hpi_tuner_set_hd_radio_signal_blend(const struct hpi_hsubsys *ph_subsys,
  2479. u32 h_control, const u32 blend)
  2480. {
  2481. return hpi_control_param_set(ph_subsys, h_control,
  2482. HPI_TUNER_HDRADIO_BLEND, blend, 0);
  2483. }
  2484. u16 hpi_tuner_getRDS(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2485. char *p_data)
  2486. {
  2487. struct hpi_message hm;
  2488. struct hpi_response hr;
  2489. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2490. HPI_CONTROL_GET_STATE);
  2491. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2492. hm.u.c.attribute = HPI_TUNER_RDS;
  2493. hpi_send_recv(&hm, &hr);
  2494. if (p_data) {
  2495. *(u32 *)&p_data[0] = hr.u.cu.tuner.rds.data[0];
  2496. *(u32 *)&p_data[4] = hr.u.cu.tuner.rds.data[1];
  2497. *(u32 *)&p_data[8] = hr.u.cu.tuner.rds.bLER;
  2498. }
  2499. return hr.error;
  2500. }
  2501. u16 HPI_PAD__get_channel_name(const struct hpi_hsubsys *ph_subsys,
  2502. u32 h_control, char *psz_string, const u32 data_length)
  2503. {
  2504. return hpi_control_get_string(ph_subsys, h_control,
  2505. HPI_PAD_CHANNEL_NAME, psz_string, data_length);
  2506. }
  2507. u16 HPI_PAD__get_artist(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2508. char *psz_string, const u32 data_length)
  2509. {
  2510. return hpi_control_get_string(ph_subsys, h_control, HPI_PAD_ARTIST,
  2511. psz_string, data_length);
  2512. }
  2513. u16 HPI_PAD__get_title(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2514. char *psz_string, const u32 data_length)
  2515. {
  2516. return hpi_control_get_string(ph_subsys, h_control, HPI_PAD_TITLE,
  2517. psz_string, data_length);
  2518. }
  2519. u16 HPI_PAD__get_comment(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2520. char *psz_string, const u32 data_length)
  2521. {
  2522. return hpi_control_get_string(ph_subsys, h_control, HPI_PAD_COMMENT,
  2523. psz_string, data_length);
  2524. }
  2525. u16 HPI_PAD__get_program_type(const struct hpi_hsubsys *ph_subsys,
  2526. u32 h_control, u32 *ppTY)
  2527. {
  2528. return hpi_control_param_get(ph_subsys, h_control,
  2529. HPI_PAD_PROGRAM_TYPE, 0, 0, ppTY, NULL);
  2530. }
  2531. u16 HPI_PAD__get_rdsPI(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2532. u32 *ppI)
  2533. {
  2534. return hpi_control_param_get(ph_subsys, h_control, HPI_PAD_PROGRAM_ID,
  2535. 0, 0, ppI, NULL);
  2536. }
  2537. u16 hpi_volume_query_channels(const struct hpi_hsubsys *ph_subsys,
  2538. const u32 h_volume, u32 *p_channels)
  2539. {
  2540. return hpi_control_query(ph_subsys, h_volume, HPI_VOLUME_NUM_CHANNELS,
  2541. 0, 0, p_channels);
  2542. }
  2543. u16 hpi_volume_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2544. short an_log_gain[HPI_MAX_CHANNELS]
  2545. )
  2546. {
  2547. struct hpi_message hm;
  2548. struct hpi_response hr;
  2549. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2550. HPI_CONTROL_SET_STATE);
  2551. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2552. memcpy(hm.u.c.an_log_value, an_log_gain,
  2553. sizeof(short) * HPI_MAX_CHANNELS);
  2554. hm.u.c.attribute = HPI_VOLUME_GAIN;
  2555. hpi_send_recv(&hm, &hr);
  2556. return hr.error;
  2557. }
  2558. u16 hpi_volume_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2559. short an_log_gain[HPI_MAX_CHANNELS]
  2560. )
  2561. {
  2562. struct hpi_message hm;
  2563. struct hpi_response hr;
  2564. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2565. HPI_CONTROL_GET_STATE);
  2566. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2567. hm.u.c.attribute = HPI_VOLUME_GAIN;
  2568. hpi_send_recv(&hm, &hr);
  2569. memcpy(an_log_gain, hr.u.c.an_log_value,
  2570. sizeof(short) * HPI_MAX_CHANNELS);
  2571. return hr.error;
  2572. }
  2573. u16 hpi_volume_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2574. short *min_gain_01dB, short *max_gain_01dB, short *step_gain_01dB)
  2575. {
  2576. struct hpi_message hm;
  2577. struct hpi_response hr;
  2578. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2579. HPI_CONTROL_GET_STATE);
  2580. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2581. hm.u.c.attribute = HPI_VOLUME_RANGE;
  2582. hpi_send_recv(&hm, &hr);
  2583. if (hr.error) {
  2584. hr.u.c.an_log_value[0] = 0;
  2585. hr.u.c.an_log_value[1] = 0;
  2586. hr.u.c.param1 = 0;
  2587. }
  2588. if (min_gain_01dB)
  2589. *min_gain_01dB = hr.u.c.an_log_value[0];
  2590. if (max_gain_01dB)
  2591. *max_gain_01dB = hr.u.c.an_log_value[1];
  2592. if (step_gain_01dB)
  2593. *step_gain_01dB = (short)hr.u.c.param1;
  2594. return hr.error;
  2595. }
  2596. u16 hpi_volume_auto_fade_profile(const struct hpi_hsubsys *ph_subsys,
  2597. u32 h_control, short an_stop_gain0_01dB[HPI_MAX_CHANNELS],
  2598. u32 duration_ms, u16 profile)
  2599. {
  2600. struct hpi_message hm;
  2601. struct hpi_response hr;
  2602. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2603. HPI_CONTROL_SET_STATE);
  2604. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2605. memcpy(hm.u.c.an_log_value, an_stop_gain0_01dB,
  2606. sizeof(short) * HPI_MAX_CHANNELS);
  2607. hm.u.c.attribute = HPI_VOLUME_AUTOFADE;
  2608. hm.u.c.param1 = duration_ms;
  2609. hm.u.c.param2 = profile;
  2610. hpi_send_recv(&hm, &hr);
  2611. return hr.error;
  2612. }
  2613. u16 hpi_volume_auto_fade(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2614. short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms)
  2615. {
  2616. return hpi_volume_auto_fade_profile(ph_subsys, h_control,
  2617. an_stop_gain0_01dB, duration_ms, HPI_VOLUME_AUTOFADE_LOG);
  2618. }
  2619. u16 hpi_vox_set_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2620. short an_gain0_01dB)
  2621. {
  2622. struct hpi_message hm;
  2623. struct hpi_response hr;
  2624. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2625. HPI_CONTROL_SET_STATE);
  2626. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2627. hm.u.c.attribute = HPI_VOX_THRESHOLD;
  2628. hm.u.c.an_log_value[0] = an_gain0_01dB;
  2629. hpi_send_recv(&hm, &hr);
  2630. return hr.error;
  2631. }
  2632. u16 hpi_vox_get_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2633. short *an_gain0_01dB)
  2634. {
  2635. struct hpi_message hm;
  2636. struct hpi_response hr;
  2637. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2638. HPI_CONTROL_GET_STATE);
  2639. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2640. hm.u.c.attribute = HPI_VOX_THRESHOLD;
  2641. hpi_send_recv(&hm, &hr);
  2642. *an_gain0_01dB = hr.u.c.an_log_value[0];
  2643. return hr.error;
  2644. }
  2645. static size_t strv_packet_size = MIN_STRV_PACKET_SIZE;
  2646. static size_t entity_type_to_size[LAST_ENTITY_TYPE] = {
  2647. 0,
  2648. sizeof(struct hpi_entity),
  2649. sizeof(void *),
  2650. sizeof(int),
  2651. sizeof(float),
  2652. sizeof(double),
  2653. sizeof(char),
  2654. sizeof(char),
  2655. 4 * sizeof(char),
  2656. 16 * sizeof(char),
  2657. 6 * sizeof(char),
  2658. };
  2659. inline size_t hpi_entity_size(struct hpi_entity *entity_ptr)
  2660. {
  2661. return entity_ptr->header.size;
  2662. }
  2663. inline size_t hpi_entity_header_size(struct hpi_entity *entity_ptr)
  2664. {
  2665. return sizeof(entity_ptr->header);
  2666. }
  2667. inline size_t hpi_entity_value_size(struct hpi_entity *entity_ptr)
  2668. {
  2669. return hpi_entity_size(entity_ptr) -
  2670. hpi_entity_header_size(entity_ptr);
  2671. }
  2672. inline size_t hpi_entity_item_count(struct hpi_entity *entity_ptr)
  2673. {
  2674. return hpi_entity_value_size(entity_ptr) /
  2675. entity_type_to_size[entity_ptr->header.type];
  2676. }
  2677. inline struct hpi_entity *hpi_entity_ptr_to_next(struct hpi_entity
  2678. *entity_ptr)
  2679. {
  2680. return (void *)(((uint8_t *) entity_ptr) +
  2681. hpi_entity_size(entity_ptr));
  2682. }
  2683. inline u16 hpi_entity_check_type(const enum e_entity_type t)
  2684. {
  2685. if (t >= 0 && t < STR_TYPE_FIELD_MAX)
  2686. return 0;
  2687. return HPI_ERROR_ENTITY_TYPE_INVALID;
  2688. }
  2689. inline u16 hpi_entity_check_role(const enum e_entity_role r)
  2690. {
  2691. if (r >= 0 && r < STR_ROLE_FIELD_MAX)
  2692. return 0;
  2693. return HPI_ERROR_ENTITY_ROLE_INVALID;
  2694. }
  2695. static u16 hpi_entity_get_next(struct hpi_entity *entity, int recursive_flag,
  2696. void *guard_p, struct hpi_entity **next)
  2697. {
  2698. HPI_DEBUG_ASSERT(entity != NULL);
  2699. HPI_DEBUG_ASSERT(next != NULL);
  2700. HPI_DEBUG_ASSERT(hpi_entity_size(entity) != 0);
  2701. if (guard_p <= (void *)entity) {
  2702. *next = NULL;
  2703. return 0;
  2704. }
  2705. if (recursive_flag && entity->header.type == entity_type_sequence)
  2706. *next = (struct hpi_entity *)entity->value;
  2707. else
  2708. *next = (struct hpi_entity *)hpi_entity_ptr_to_next(entity);
  2709. if (guard_p <= (void *)*next) {
  2710. *next = NULL;
  2711. return 0;
  2712. }
  2713. HPI_DEBUG_ASSERT(guard_p >= (void *)hpi_entity_ptr_to_next(*next));
  2714. return 0;
  2715. }
  2716. u16 hpi_entity_find_next(struct hpi_entity *container_entity,
  2717. enum e_entity_type type, enum e_entity_role role, int recursive_flag,
  2718. struct hpi_entity **current_match)
  2719. {
  2720. struct hpi_entity *tmp = NULL;
  2721. void *guard_p = NULL;
  2722. HPI_DEBUG_ASSERT(container_entity != NULL);
  2723. guard_p = hpi_entity_ptr_to_next(container_entity);
  2724. if (*current_match != NULL)
  2725. hpi_entity_get_next(*current_match, recursive_flag, guard_p,
  2726. &tmp);
  2727. else
  2728. hpi_entity_get_next(container_entity, 1, guard_p, &tmp);
  2729. while (tmp) {
  2730. u16 err;
  2731. HPI_DEBUG_ASSERT((void *)tmp >= (void *)container_entity);
  2732. if ((!type || tmp->header.type == type) && (!role
  2733. || tmp->header.role == role)) {
  2734. *current_match = tmp;
  2735. return 0;
  2736. }
  2737. err = hpi_entity_get_next(tmp, recursive_flag, guard_p,
  2738. current_match);
  2739. if (err)
  2740. return err;
  2741. tmp = *current_match;
  2742. }
  2743. *current_match = NULL;
  2744. return 0;
  2745. }
  2746. void hpi_entity_free(struct hpi_entity *entity)
  2747. {
  2748. kfree(entity);
  2749. }
  2750. static u16 hpi_entity_alloc_and_copy(struct hpi_entity *src,
  2751. struct hpi_entity **dst)
  2752. {
  2753. size_t buf_size;
  2754. HPI_DEBUG_ASSERT(dst != NULL);
  2755. HPI_DEBUG_ASSERT(src != NULL);
  2756. buf_size = hpi_entity_size(src);
  2757. *dst = kmalloc(buf_size, GFP_KERNEL);
  2758. if (*dst == NULL)
  2759. return HPI_ERROR_MEMORY_ALLOC;
  2760. memcpy(*dst, src, buf_size);
  2761. return 0;
  2762. }
  2763. u16 hpi_universal_info(const struct hpi_hsubsys *ph_subsys, u32 hC,
  2764. struct hpi_entity **info)
  2765. {
  2766. struct hpi_msg_strv hm;
  2767. struct hpi_res_strv *phr;
  2768. u16 hpi_err;
  2769. int remaining_attempts = 2;
  2770. size_t resp_packet_size = 1024;
  2771. *info = NULL;
  2772. while (remaining_attempts--) {
  2773. phr = kmalloc(resp_packet_size, GFP_KERNEL);
  2774. HPI_DEBUG_ASSERT(phr != NULL);
  2775. hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h,
  2776. (u16)resp_packet_size, HPI_OBJ_CONTROL,
  2777. HPI_CONTROL_GET_INFO);
  2778. u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index);
  2779. hm.strv.header.size = sizeof(hm.strv);
  2780. phr->strv.header.size = resp_packet_size - sizeof(phr->h);
  2781. hpi_send_recv((struct hpi_message *)&hm.h,
  2782. (struct hpi_response *)&phr->h);
  2783. if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) {
  2784. HPI_DEBUG_ASSERT(phr->h.specific_error >
  2785. MIN_STRV_PACKET_SIZE
  2786. && phr->h.specific_error < 1500);
  2787. resp_packet_size = phr->h.specific_error;
  2788. } else {
  2789. remaining_attempts = 0;
  2790. if (!phr->h.error)
  2791. hpi_entity_alloc_and_copy(&phr->strv, info);
  2792. }
  2793. hpi_err = phr->h.error;
  2794. kfree(phr);
  2795. }
  2796. return hpi_err;
  2797. }
  2798. u16 hpi_universal_get(const struct hpi_hsubsys *ph_subsys, u32 hC,
  2799. struct hpi_entity **value)
  2800. {
  2801. struct hpi_msg_strv hm;
  2802. struct hpi_res_strv *phr;
  2803. u16 hpi_err;
  2804. int remaining_attempts = 2;
  2805. *value = NULL;
  2806. while (remaining_attempts--) {
  2807. phr = kmalloc(strv_packet_size, GFP_KERNEL);
  2808. if (!phr)
  2809. return HPI_ERROR_MEMORY_ALLOC;
  2810. hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h,
  2811. (u16)strv_packet_size, HPI_OBJ_CONTROL,
  2812. HPI_CONTROL_GET_STATE);
  2813. u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index);
  2814. hm.strv.header.size = sizeof(hm.strv);
  2815. phr->strv.header.size = strv_packet_size - sizeof(phr->h);
  2816. hpi_send_recv((struct hpi_message *)&hm.h,
  2817. (struct hpi_response *)&phr->h);
  2818. if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) {
  2819. HPI_DEBUG_ASSERT(phr->h.specific_error >
  2820. MIN_STRV_PACKET_SIZE
  2821. && phr->h.specific_error < 1000);
  2822. strv_packet_size = phr->h.specific_error;
  2823. } else {
  2824. remaining_attempts = 0;
  2825. if (!phr->h.error)
  2826. hpi_entity_alloc_and_copy(&phr->strv, value);
  2827. }
  2828. hpi_err = phr->h.error;
  2829. kfree(phr);
  2830. }
  2831. return hpi_err;
  2832. }
  2833. u16 hpi_universal_set(const struct hpi_hsubsys *ph_subsys, u32 hC,
  2834. struct hpi_entity *value)
  2835. {
  2836. struct hpi_msg_strv *phm;
  2837. struct hpi_res_strv hr;
  2838. phm = kmalloc(sizeof(phm->h) + value->header.size, GFP_KERNEL);
  2839. HPI_DEBUG_ASSERT(phm != NULL);
  2840. hpi_init_message_responseV1(&phm->h,
  2841. sizeof(phm->h) + value->header.size, &hr.h, sizeof(hr),
  2842. HPI_OBJ_CONTROL, HPI_CONTROL_SET_STATE);
  2843. u32TOINDEXES(hC, &phm->h.adapter_index, &phm->h.obj_index);
  2844. hr.strv.header.size = sizeof(hr.strv);
  2845. memcpy(&phm->strv, value, value->header.size);
  2846. hpi_send_recv((struct hpi_message *)&phm->h,
  2847. (struct hpi_response *)&hr.h);
  2848. return hr.h.error;
  2849. }
  2850. u16 hpi_entity_alloc_and_pack(const enum e_entity_type type,
  2851. const size_t item_count, const enum e_entity_role role, void *value,
  2852. struct hpi_entity **entity)
  2853. {
  2854. size_t bytes_to_copy, total_size;
  2855. u16 hE = 0;
  2856. *entity = NULL;
  2857. hE = hpi_entity_check_type(type);
  2858. if (hE)
  2859. return hE;
  2860. HPI_DEBUG_ASSERT(role > entity_role_null && type < LAST_ENTITY_TYPE);
  2861. bytes_to_copy = entity_type_to_size[type] * item_count;
  2862. total_size = hpi_entity_header_size(*entity) + bytes_to_copy;
  2863. HPI_DEBUG_ASSERT(total_size >= hpi_entity_header_size(*entity)
  2864. && total_size < STR_SIZE_FIELD_MAX);
  2865. *entity = kmalloc(total_size, GFP_KERNEL);
  2866. if (*entity == NULL)
  2867. return HPI_ERROR_MEMORY_ALLOC;
  2868. memcpy((*entity)->value, value, bytes_to_copy);
  2869. (*entity)->header.size =
  2870. hpi_entity_header_size(*entity) + bytes_to_copy;
  2871. (*entity)->header.type = type;
  2872. (*entity)->header.role = role;
  2873. return 0;
  2874. }
  2875. u16 hpi_entity_copy_value_from(struct hpi_entity *entity,
  2876. enum e_entity_type type, size_t item_count, void *value_dst_p)
  2877. {
  2878. size_t bytes_to_copy;
  2879. if (entity->header.type != type)
  2880. return HPI_ERROR_ENTITY_TYPE_MISMATCH;
  2881. if (hpi_entity_item_count(entity) != item_count)
  2882. return HPI_ERROR_ENTITY_ITEM_COUNT;
  2883. bytes_to_copy = entity_type_to_size[type] * item_count;
  2884. memcpy(value_dst_p, entity->value, bytes_to_copy);
  2885. return 0;
  2886. }
  2887. u16 hpi_entity_unpack(struct hpi_entity *entity, enum e_entity_type *type,
  2888. size_t *item_count, enum e_entity_role *role, void **value)
  2889. {
  2890. u16 err = 0;
  2891. HPI_DEBUG_ASSERT(entity != NULL);
  2892. if (type)
  2893. *type = entity->header.type;
  2894. if (role)
  2895. *role = entity->header.role;
  2896. if (value)
  2897. *value = entity->value;
  2898. if (item_count != NULL) {
  2899. if (entity->header.type == entity_type_sequence) {
  2900. void *guard_p = hpi_entity_ptr_to_next(entity);
  2901. struct hpi_entity *next = NULL;
  2902. void *contents = entity->value;
  2903. *item_count = 0;
  2904. while (contents < guard_p) {
  2905. (*item_count)++;
  2906. err = hpi_entity_get_next(contents, 0,
  2907. guard_p, &next);
  2908. if (next == NULL || err)
  2909. break;
  2910. contents = next;
  2911. }
  2912. } else {
  2913. *item_count = hpi_entity_item_count(entity);
  2914. }
  2915. }
  2916. return err;
  2917. }
  2918. u16 hpi_gpio_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
  2919. u32 *ph_gpio, u16 *pw_number_input_bits, u16 *pw_number_output_bits)
  2920. {
  2921. struct hpi_message hm;
  2922. struct hpi_response hr;
  2923. hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_OPEN);
  2924. hm.adapter_index = adapter_index;
  2925. hpi_send_recv(&hm, &hr);
  2926. if (hr.error == 0) {
  2927. *ph_gpio =
  2928. hpi_indexes_to_handle(HPI_OBJ_GPIO, adapter_index, 0);
  2929. if (pw_number_input_bits)
  2930. *pw_number_input_bits = hr.u.l.number_input_bits;
  2931. if (pw_number_output_bits)
  2932. *pw_number_output_bits = hr.u.l.number_output_bits;
  2933. } else
  2934. *ph_gpio = 0;
  2935. return hr.error;
  2936. }
  2937. u16 hpi_gpio_read_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
  2938. u16 bit_index, u16 *pw_bit_data)
  2939. {
  2940. struct hpi_message hm;
  2941. struct hpi_response hr;
  2942. hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_BIT);
  2943. u32TOINDEX(h_gpio, &hm.adapter_index);
  2944. hm.u.l.bit_index = bit_index;
  2945. hpi_send_recv(&hm, &hr);
  2946. *pw_bit_data = hr.u.l.bit_data[0];
  2947. return hr.error;
  2948. }
  2949. u16 hpi_gpio_read_all_bits(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
  2950. u16 aw_all_bit_data[4]
  2951. )
  2952. {
  2953. struct hpi_message hm;
  2954. struct hpi_response hr;
  2955. hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_ALL);
  2956. u32TOINDEX(h_gpio, &hm.adapter_index);
  2957. hpi_send_recv(&hm, &hr);
  2958. if (aw_all_bit_data) {
  2959. aw_all_bit_data[0] = hr.u.l.bit_data[0];
  2960. aw_all_bit_data[1] = hr.u.l.bit_data[1];
  2961. aw_all_bit_data[2] = hr.u.l.bit_data[2];
  2962. aw_all_bit_data[3] = hr.u.l.bit_data[3];
  2963. }
  2964. return hr.error;
  2965. }
  2966. u16 hpi_gpio_write_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
  2967. u16 bit_index, u16 bit_data)
  2968. {
  2969. struct hpi_message hm;
  2970. struct hpi_response hr;
  2971. hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_WRITE_BIT);
  2972. u32TOINDEX(h_gpio, &hm.adapter_index);
  2973. hm.u.l.bit_index = bit_index;
  2974. hm.u.l.bit_data = bit_data;
  2975. hpi_send_recv(&hm, &hr);
  2976. return hr.error;
  2977. }
  2978. u16 hpi_gpio_write_status(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
  2979. u16 aw_all_bit_data[4]
  2980. )
  2981. {
  2982. struct hpi_message hm;
  2983. struct hpi_response hr;
  2984. hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO,
  2985. HPI_GPIO_WRITE_STATUS);
  2986. u32TOINDEX(h_gpio, &hm.adapter_index);
  2987. hpi_send_recv(&hm, &hr);
  2988. if (aw_all_bit_data) {
  2989. aw_all_bit_data[0] = hr.u.l.bit_data[0];
  2990. aw_all_bit_data[1] = hr.u.l.bit_data[1];
  2991. aw_all_bit_data[2] = hr.u.l.bit_data[2];
  2992. aw_all_bit_data[3] = hr.u.l.bit_data[3];
  2993. }
  2994. return hr.error;
  2995. }
  2996. u16 hpi_async_event_open(const struct hpi_hsubsys *ph_subsys,
  2997. u16 adapter_index, u32 *ph_async)
  2998. {
  2999. struct hpi_message hm;
  3000. struct hpi_response hr;
  3001. hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
  3002. HPI_ASYNCEVENT_OPEN);
  3003. hm.adapter_index = adapter_index;
  3004. hpi_send_recv(&hm, &hr);
  3005. if (hr.error == 0)
  3006. *ph_async =
  3007. hpi_indexes_to_handle(HPI_OBJ_ASYNCEVENT,
  3008. adapter_index, 0);
  3009. else
  3010. *ph_async = 0;
  3011. return hr.error;
  3012. }
  3013. u16 hpi_async_event_close(const struct hpi_hsubsys *ph_subsys, u32 h_async)
  3014. {
  3015. struct hpi_message hm;
  3016. struct hpi_response hr;
  3017. hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
  3018. HPI_ASYNCEVENT_OPEN);
  3019. u32TOINDEX(h_async, &hm.adapter_index);
  3020. hpi_send_recv(&hm, &hr);
  3021. return hr.error;
  3022. }
  3023. u16 hpi_async_event_wait(const struct hpi_hsubsys *ph_subsys, u32 h_async,
  3024. u16 maximum_events, struct hpi_async_event *p_events,
  3025. u16 *pw_number_returned)
  3026. {
  3027. return 0;
  3028. }
  3029. u16 hpi_async_event_get_count(const struct hpi_hsubsys *ph_subsys,
  3030. u32 h_async, u16 *pw_count)
  3031. {
  3032. struct hpi_message hm;
  3033. struct hpi_response hr;
  3034. hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
  3035. HPI_ASYNCEVENT_GETCOUNT);
  3036. u32TOINDEX(h_async, &hm.adapter_index);
  3037. hpi_send_recv(&hm, &hr);
  3038. if (hr.error == 0)
  3039. if (pw_count)
  3040. *pw_count = hr.u.as.u.count.count;
  3041. return hr.error;
  3042. }
  3043. u16 hpi_async_event_get(const struct hpi_hsubsys *ph_subsys, u32 h_async,
  3044. u16 maximum_events, struct hpi_async_event *p_events,
  3045. u16 *pw_number_returned)
  3046. {
  3047. struct hpi_message hm;
  3048. struct hpi_response hr;
  3049. hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
  3050. HPI_ASYNCEVENT_GET);
  3051. u32TOINDEX(h_async, &hm.adapter_index);
  3052. hpi_send_recv(&hm, &hr);
  3053. if (!hr.error) {
  3054. memcpy(p_events, &hr.u.as.u.event,
  3055. sizeof(struct hpi_async_event));
  3056. *pw_number_returned = 1;
  3057. }
  3058. return hr.error;
  3059. }
  3060. u16 hpi_nv_memory_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
  3061. u32 *ph_nv_memory, u16 *pw_size_in_bytes)
  3062. {
  3063. struct hpi_message hm;
  3064. struct hpi_response hr;
  3065. hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
  3066. HPI_NVMEMORY_OPEN);
  3067. hm.adapter_index = adapter_index;
  3068. hpi_send_recv(&hm, &hr);
  3069. if (hr.error == 0) {
  3070. *ph_nv_memory =
  3071. hpi_indexes_to_handle(HPI_OBJ_NVMEMORY, adapter_index,
  3072. 0);
  3073. if (pw_size_in_bytes)
  3074. *pw_size_in_bytes = hr.u.n.size_in_bytes;
  3075. } else
  3076. *ph_nv_memory = 0;
  3077. return hr.error;
  3078. }
  3079. u16 hpi_nv_memory_read_byte(const struct hpi_hsubsys *ph_subsys,
  3080. u32 h_nv_memory, u16 index, u16 *pw_data)
  3081. {
  3082. struct hpi_message hm;
  3083. struct hpi_response hr;
  3084. hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
  3085. HPI_NVMEMORY_READ_BYTE);
  3086. u32TOINDEX(h_nv_memory, &hm.adapter_index);
  3087. hm.u.n.address = index;
  3088. hpi_send_recv(&hm, &hr);
  3089. *pw_data = hr.u.n.data;
  3090. return hr.error;
  3091. }
  3092. u16 hpi_nv_memory_write_byte(const struct hpi_hsubsys *ph_subsys,
  3093. u32 h_nv_memory, u16 index, u16 data)
  3094. {
  3095. struct hpi_message hm;
  3096. struct hpi_response hr;
  3097. hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
  3098. HPI_NVMEMORY_WRITE_BYTE);
  3099. u32TOINDEX(h_nv_memory, &hm.adapter_index);
  3100. hm.u.n.address = index;
  3101. hm.u.n.data = data;
  3102. hpi_send_recv(&hm, &hr);
  3103. return hr.error;
  3104. }
  3105. u16 hpi_profile_open_all(const struct hpi_hsubsys *ph_subsys,
  3106. u16 adapter_index, u16 profile_index, u32 *ph_profile,
  3107. u16 *pw_max_profiles)
  3108. {
  3109. struct hpi_message hm;
  3110. struct hpi_response hr;
  3111. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
  3112. HPI_PROFILE_OPEN_ALL);
  3113. hm.adapter_index = adapter_index;
  3114. hm.obj_index = profile_index;
  3115. hpi_send_recv(&hm, &hr);
  3116. *pw_max_profiles = hr.u.p.u.o.max_profiles;
  3117. if (hr.error == 0)
  3118. *ph_profile =
  3119. hpi_indexes_to_handle(HPI_OBJ_PROFILE, adapter_index,
  3120. profile_index);
  3121. else
  3122. *ph_profile = 0;
  3123. return hr.error;
  3124. }
  3125. u16 hpi_profile_get(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
  3126. u16 bin_index, u16 *pw_seconds, u32 *pmicro_seconds, u32 *pcall_count,
  3127. u32 *pmax_micro_seconds, u32 *pmin_micro_seconds)
  3128. {
  3129. struct hpi_message hm;
  3130. struct hpi_response hr;
  3131. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE, HPI_PROFILE_GET);
  3132. u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
  3133. hm.u.p.bin_index = bin_index;
  3134. hpi_send_recv(&hm, &hr);
  3135. if (pw_seconds)
  3136. *pw_seconds = hr.u.p.u.t.seconds;
  3137. if (pmicro_seconds)
  3138. *pmicro_seconds = hr.u.p.u.t.micro_seconds;
  3139. if (pcall_count)
  3140. *pcall_count = hr.u.p.u.t.call_count;
  3141. if (pmax_micro_seconds)
  3142. *pmax_micro_seconds = hr.u.p.u.t.max_micro_seconds;
  3143. if (pmin_micro_seconds)
  3144. *pmin_micro_seconds = hr.u.p.u.t.min_micro_seconds;
  3145. return hr.error;
  3146. }
  3147. u16 hpi_profile_get_utilization(const struct hpi_hsubsys *ph_subsys,
  3148. u32 h_profile, u32 *putilization)
  3149. {
  3150. struct hpi_message hm;
  3151. struct hpi_response hr;
  3152. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
  3153. HPI_PROFILE_GET_UTILIZATION);
  3154. u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
  3155. hpi_send_recv(&hm, &hr);
  3156. if (hr.error) {
  3157. if (putilization)
  3158. *putilization = 0;
  3159. } else {
  3160. if (putilization)
  3161. *putilization = hr.u.p.u.t.call_count;
  3162. }
  3163. return hr.error;
  3164. }
  3165. u16 hpi_profile_get_name(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
  3166. u16 bin_index, char *sz_name, u16 name_length)
  3167. {
  3168. struct hpi_message hm;
  3169. struct hpi_response hr;
  3170. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
  3171. HPI_PROFILE_GET_NAME);
  3172. u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
  3173. hm.u.p.bin_index = bin_index;
  3174. hpi_send_recv(&hm, &hr);
  3175. if (hr.error) {
  3176. if (sz_name)
  3177. strcpy(sz_name, "??");
  3178. } else {
  3179. if (sz_name)
  3180. memcpy(sz_name, (char *)hr.u.p.u.n.sz_name,
  3181. name_length);
  3182. }
  3183. return hr.error;
  3184. }
  3185. u16 hpi_profile_start_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile)
  3186. {
  3187. struct hpi_message hm;
  3188. struct hpi_response hr;
  3189. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
  3190. HPI_PROFILE_START_ALL);
  3191. u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
  3192. hpi_send_recv(&hm, &hr);
  3193. return hr.error;
  3194. }
  3195. u16 hpi_profile_stop_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile)
  3196. {
  3197. struct hpi_message hm;
  3198. struct hpi_response hr;
  3199. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
  3200. HPI_PROFILE_STOP_ALL);
  3201. u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
  3202. hpi_send_recv(&hm, &hr);
  3203. return hr.error;
  3204. }
  3205. u16 hpi_watchdog_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
  3206. u32 *ph_watchdog)
  3207. {
  3208. struct hpi_message hm;
  3209. struct hpi_response hr;
  3210. hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
  3211. HPI_WATCHDOG_OPEN);
  3212. hm.adapter_index = adapter_index;
  3213. hpi_send_recv(&hm, &hr);
  3214. if (hr.error == 0)
  3215. *ph_watchdog =
  3216. hpi_indexes_to_handle(HPI_OBJ_WATCHDOG, adapter_index,
  3217. 0);
  3218. else
  3219. *ph_watchdog = 0;
  3220. return hr.error;
  3221. }
  3222. u16 hpi_watchdog_set_time(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog,
  3223. u32 time_millisec)
  3224. {
  3225. struct hpi_message hm;
  3226. struct hpi_response hr;
  3227. hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
  3228. HPI_WATCHDOG_SET_TIME);
  3229. u32TOINDEX(h_watchdog, &hm.adapter_index);
  3230. hm.u.w.time_ms = time_millisec;
  3231. hpi_send_recv(&hm, &hr);
  3232. return hr.error;
  3233. }
  3234. u16 hpi_watchdog_ping(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog)
  3235. {
  3236. struct hpi_message hm;
  3237. struct hpi_response hr;
  3238. hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
  3239. HPI_WATCHDOG_PING);
  3240. u32TOINDEX(h_watchdog, &hm.adapter_index);
  3241. hpi_send_recv(&hm, &hr);
  3242. return hr.error;
  3243. }