hpifunc.c 97 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864
  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_getRDS(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2473. char *p_data)
  2474. {
  2475. struct hpi_message hm;
  2476. struct hpi_response hr;
  2477. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2478. HPI_CONTROL_GET_STATE);
  2479. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2480. hm.u.c.attribute = HPI_TUNER_RDS;
  2481. hpi_send_recv(&hm, &hr);
  2482. if (p_data) {
  2483. *(u32 *)&p_data[0] = hr.u.cu.tuner.rds.data[0];
  2484. *(u32 *)&p_data[4] = hr.u.cu.tuner.rds.data[1];
  2485. *(u32 *)&p_data[8] = hr.u.cu.tuner.rds.bLER;
  2486. }
  2487. return hr.error;
  2488. }
  2489. u16 HPI_PAD__get_channel_name(const struct hpi_hsubsys *ph_subsys,
  2490. u32 h_control, char *psz_string, const u32 data_length)
  2491. {
  2492. return hpi_control_get_string(ph_subsys, h_control,
  2493. HPI_PAD_CHANNEL_NAME, psz_string, data_length);
  2494. }
  2495. u16 HPI_PAD__get_artist(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2496. char *psz_string, const u32 data_length)
  2497. {
  2498. return hpi_control_get_string(ph_subsys, h_control, HPI_PAD_ARTIST,
  2499. psz_string, data_length);
  2500. }
  2501. u16 HPI_PAD__get_title(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2502. char *psz_string, const u32 data_length)
  2503. {
  2504. return hpi_control_get_string(ph_subsys, h_control, HPI_PAD_TITLE,
  2505. psz_string, data_length);
  2506. }
  2507. u16 HPI_PAD__get_comment(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_COMMENT,
  2511. psz_string, data_length);
  2512. }
  2513. u16 HPI_PAD__get_program_type(const struct hpi_hsubsys *ph_subsys,
  2514. u32 h_control, u32 *ppTY)
  2515. {
  2516. return hpi_control_param_get(ph_subsys, h_control,
  2517. HPI_PAD_PROGRAM_TYPE, 0, 0, ppTY, NULL);
  2518. }
  2519. u16 HPI_PAD__get_rdsPI(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2520. u32 *ppI)
  2521. {
  2522. return hpi_control_param_get(ph_subsys, h_control, HPI_PAD_PROGRAM_ID,
  2523. 0, 0, ppI, NULL);
  2524. }
  2525. u16 hpi_volume_query_channels(const struct hpi_hsubsys *ph_subsys,
  2526. const u32 h_volume, u32 *p_channels)
  2527. {
  2528. return hpi_control_query(ph_subsys, h_volume, HPI_VOLUME_NUM_CHANNELS,
  2529. 0, 0, p_channels);
  2530. }
  2531. u16 hpi_volume_set_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2532. short an_log_gain[HPI_MAX_CHANNELS]
  2533. )
  2534. {
  2535. struct hpi_message hm;
  2536. struct hpi_response hr;
  2537. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2538. HPI_CONTROL_SET_STATE);
  2539. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2540. memcpy(hm.u.c.an_log_value, an_log_gain,
  2541. sizeof(short) * HPI_MAX_CHANNELS);
  2542. hm.u.c.attribute = HPI_VOLUME_GAIN;
  2543. hpi_send_recv(&hm, &hr);
  2544. return hr.error;
  2545. }
  2546. u16 hpi_volume_get_gain(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2547. short an_log_gain[HPI_MAX_CHANNELS]
  2548. )
  2549. {
  2550. struct hpi_message hm;
  2551. struct hpi_response hr;
  2552. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2553. HPI_CONTROL_GET_STATE);
  2554. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2555. hm.u.c.attribute = HPI_VOLUME_GAIN;
  2556. hpi_send_recv(&hm, &hr);
  2557. memcpy(an_log_gain, hr.u.c.an_log_value,
  2558. sizeof(short) * HPI_MAX_CHANNELS);
  2559. return hr.error;
  2560. }
  2561. u16 hpi_volume_query_range(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2562. short *min_gain_01dB, short *max_gain_01dB, short *step_gain_01dB)
  2563. {
  2564. struct hpi_message hm;
  2565. struct hpi_response hr;
  2566. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2567. HPI_CONTROL_GET_STATE);
  2568. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2569. hm.u.c.attribute = HPI_VOLUME_RANGE;
  2570. hpi_send_recv(&hm, &hr);
  2571. if (hr.error) {
  2572. hr.u.c.an_log_value[0] = 0;
  2573. hr.u.c.an_log_value[1] = 0;
  2574. hr.u.c.param1 = 0;
  2575. }
  2576. if (min_gain_01dB)
  2577. *min_gain_01dB = hr.u.c.an_log_value[0];
  2578. if (max_gain_01dB)
  2579. *max_gain_01dB = hr.u.c.an_log_value[1];
  2580. if (step_gain_01dB)
  2581. *step_gain_01dB = (short)hr.u.c.param1;
  2582. return hr.error;
  2583. }
  2584. u16 hpi_volume_auto_fade_profile(const struct hpi_hsubsys *ph_subsys,
  2585. u32 h_control, short an_stop_gain0_01dB[HPI_MAX_CHANNELS],
  2586. u32 duration_ms, u16 profile)
  2587. {
  2588. struct hpi_message hm;
  2589. struct hpi_response hr;
  2590. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2591. HPI_CONTROL_SET_STATE);
  2592. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2593. memcpy(hm.u.c.an_log_value, an_stop_gain0_01dB,
  2594. sizeof(short) * HPI_MAX_CHANNELS);
  2595. hm.u.c.attribute = HPI_VOLUME_AUTOFADE;
  2596. hm.u.c.param1 = duration_ms;
  2597. hm.u.c.param2 = profile;
  2598. hpi_send_recv(&hm, &hr);
  2599. return hr.error;
  2600. }
  2601. u16 hpi_volume_auto_fade(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2602. short an_stop_gain0_01dB[HPI_MAX_CHANNELS], u32 duration_ms)
  2603. {
  2604. return hpi_volume_auto_fade_profile(ph_subsys, h_control,
  2605. an_stop_gain0_01dB, duration_ms, HPI_VOLUME_AUTOFADE_LOG);
  2606. }
  2607. u16 hpi_vox_set_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2608. short an_gain0_01dB)
  2609. {
  2610. struct hpi_message hm;
  2611. struct hpi_response hr;
  2612. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2613. HPI_CONTROL_SET_STATE);
  2614. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2615. hm.u.c.attribute = HPI_VOX_THRESHOLD;
  2616. hm.u.c.an_log_value[0] = an_gain0_01dB;
  2617. hpi_send_recv(&hm, &hr);
  2618. return hr.error;
  2619. }
  2620. u16 hpi_vox_get_threshold(const struct hpi_hsubsys *ph_subsys, u32 h_control,
  2621. short *an_gain0_01dB)
  2622. {
  2623. struct hpi_message hm;
  2624. struct hpi_response hr;
  2625. hpi_init_message_response(&hm, &hr, HPI_OBJ_CONTROL,
  2626. HPI_CONTROL_GET_STATE);
  2627. u32TOINDEXES(h_control, &hm.adapter_index, &hm.obj_index);
  2628. hm.u.c.attribute = HPI_VOX_THRESHOLD;
  2629. hpi_send_recv(&hm, &hr);
  2630. *an_gain0_01dB = hr.u.c.an_log_value[0];
  2631. return hr.error;
  2632. }
  2633. static size_t strv_packet_size = MIN_STRV_PACKET_SIZE;
  2634. static size_t entity_type_to_size[LAST_ENTITY_TYPE] = {
  2635. 0,
  2636. sizeof(struct hpi_entity),
  2637. sizeof(void *),
  2638. sizeof(int),
  2639. sizeof(float),
  2640. sizeof(double),
  2641. sizeof(char),
  2642. sizeof(char),
  2643. 4 * sizeof(char),
  2644. 16 * sizeof(char),
  2645. 6 * sizeof(char),
  2646. };
  2647. inline size_t hpi_entity_size(struct hpi_entity *entity_ptr)
  2648. {
  2649. return entity_ptr->header.size;
  2650. }
  2651. inline size_t hpi_entity_header_size(struct hpi_entity *entity_ptr)
  2652. {
  2653. return sizeof(entity_ptr->header);
  2654. }
  2655. inline size_t hpi_entity_value_size(struct hpi_entity *entity_ptr)
  2656. {
  2657. return hpi_entity_size(entity_ptr) -
  2658. hpi_entity_header_size(entity_ptr);
  2659. }
  2660. inline size_t hpi_entity_item_count(struct hpi_entity *entity_ptr)
  2661. {
  2662. return hpi_entity_value_size(entity_ptr) /
  2663. entity_type_to_size[entity_ptr->header.type];
  2664. }
  2665. inline struct hpi_entity *hpi_entity_ptr_to_next(struct hpi_entity
  2666. *entity_ptr)
  2667. {
  2668. return (void *)(((uint8_t *) entity_ptr) +
  2669. hpi_entity_size(entity_ptr));
  2670. }
  2671. inline u16 hpi_entity_check_type(const enum e_entity_type t)
  2672. {
  2673. if (t >= 0 && t < STR_TYPE_FIELD_MAX)
  2674. return 0;
  2675. return HPI_ERROR_ENTITY_TYPE_INVALID;
  2676. }
  2677. inline u16 hpi_entity_check_role(const enum e_entity_role r)
  2678. {
  2679. if (r >= 0 && r < STR_ROLE_FIELD_MAX)
  2680. return 0;
  2681. return HPI_ERROR_ENTITY_ROLE_INVALID;
  2682. }
  2683. static u16 hpi_entity_get_next(struct hpi_entity *entity, int recursive_flag,
  2684. void *guard_p, struct hpi_entity **next)
  2685. {
  2686. HPI_DEBUG_ASSERT(entity != NULL);
  2687. HPI_DEBUG_ASSERT(next != NULL);
  2688. HPI_DEBUG_ASSERT(hpi_entity_size(entity) != 0);
  2689. if (guard_p <= (void *)entity) {
  2690. *next = NULL;
  2691. return 0;
  2692. }
  2693. if (recursive_flag && entity->header.type == entity_type_sequence)
  2694. *next = (struct hpi_entity *)entity->value;
  2695. else
  2696. *next = (struct hpi_entity *)hpi_entity_ptr_to_next(entity);
  2697. if (guard_p <= (void *)*next) {
  2698. *next = NULL;
  2699. return 0;
  2700. }
  2701. HPI_DEBUG_ASSERT(guard_p >= (void *)hpi_entity_ptr_to_next(*next));
  2702. return 0;
  2703. }
  2704. u16 hpi_entity_find_next(struct hpi_entity *container_entity,
  2705. enum e_entity_type type, enum e_entity_role role, int recursive_flag,
  2706. struct hpi_entity **current_match)
  2707. {
  2708. struct hpi_entity *tmp = NULL;
  2709. void *guard_p = NULL;
  2710. HPI_DEBUG_ASSERT(container_entity != NULL);
  2711. guard_p = hpi_entity_ptr_to_next(container_entity);
  2712. if (*current_match != NULL)
  2713. hpi_entity_get_next(*current_match, recursive_flag, guard_p,
  2714. &tmp);
  2715. else
  2716. hpi_entity_get_next(container_entity, 1, guard_p, &tmp);
  2717. while (tmp) {
  2718. u16 err;
  2719. HPI_DEBUG_ASSERT((void *)tmp >= (void *)container_entity);
  2720. if ((!type || tmp->header.type == type) && (!role
  2721. || tmp->header.role == role)) {
  2722. *current_match = tmp;
  2723. return 0;
  2724. }
  2725. err = hpi_entity_get_next(tmp, recursive_flag, guard_p,
  2726. current_match);
  2727. if (err)
  2728. return err;
  2729. tmp = *current_match;
  2730. }
  2731. *current_match = NULL;
  2732. return 0;
  2733. }
  2734. void hpi_entity_free(struct hpi_entity *entity)
  2735. {
  2736. if (entity != NULL)
  2737. kfree(entity);
  2738. }
  2739. static u16 hpi_entity_alloc_and_copy(struct hpi_entity *src,
  2740. struct hpi_entity **dst)
  2741. {
  2742. size_t buf_size;
  2743. HPI_DEBUG_ASSERT(dst != NULL);
  2744. HPI_DEBUG_ASSERT(src != NULL);
  2745. buf_size = hpi_entity_size(src);
  2746. *dst = kmalloc(buf_size, GFP_KERNEL);
  2747. if (*dst == NULL)
  2748. return HPI_ERROR_MEMORY_ALLOC;
  2749. memcpy(*dst, src, buf_size);
  2750. return 0;
  2751. }
  2752. u16 hpi_universal_info(const struct hpi_hsubsys *ph_subsys, u32 hC,
  2753. struct hpi_entity **info)
  2754. {
  2755. struct hpi_msg_strv hm;
  2756. struct hpi_res_strv *phr;
  2757. u16 hpi_err;
  2758. int remaining_attempts = 2;
  2759. size_t resp_packet_size = 1024;
  2760. *info = NULL;
  2761. while (remaining_attempts--) {
  2762. phr = kmalloc(resp_packet_size, GFP_KERNEL);
  2763. HPI_DEBUG_ASSERT(phr != NULL);
  2764. hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h,
  2765. (u16)resp_packet_size, HPI_OBJ_CONTROL,
  2766. HPI_CONTROL_GET_INFO);
  2767. u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index);
  2768. hm.strv.header.size = sizeof(hm.strv);
  2769. phr->strv.header.size = resp_packet_size - sizeof(phr->h);
  2770. hpi_send_recv((struct hpi_message *)&hm.h,
  2771. (struct hpi_response *)&phr->h);
  2772. if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) {
  2773. HPI_DEBUG_ASSERT(phr->h.specific_error >
  2774. MIN_STRV_PACKET_SIZE
  2775. && phr->h.specific_error < 1500);
  2776. resp_packet_size = phr->h.specific_error;
  2777. } else {
  2778. remaining_attempts = 0;
  2779. if (!phr->h.error)
  2780. hpi_entity_alloc_and_copy(&phr->strv, info);
  2781. }
  2782. hpi_err = phr->h.error;
  2783. kfree(phr);
  2784. }
  2785. return hpi_err;
  2786. }
  2787. u16 hpi_universal_get(const struct hpi_hsubsys *ph_subsys, u32 hC,
  2788. struct hpi_entity **value)
  2789. {
  2790. struct hpi_msg_strv hm;
  2791. struct hpi_res_strv *phr;
  2792. u16 hpi_err;
  2793. int remaining_attempts = 2;
  2794. *value = NULL;
  2795. while (remaining_attempts--) {
  2796. phr = kmalloc(strv_packet_size, GFP_KERNEL);
  2797. if (!phr)
  2798. return HPI_ERROR_MEMORY_ALLOC;
  2799. hpi_init_message_responseV1(&hm.h, (u16)sizeof(hm), &phr->h,
  2800. (u16)strv_packet_size, HPI_OBJ_CONTROL,
  2801. HPI_CONTROL_GET_STATE);
  2802. u32TOINDEXES(hC, &hm.h.adapter_index, &hm.h.obj_index);
  2803. hm.strv.header.size = sizeof(hm.strv);
  2804. phr->strv.header.size = strv_packet_size - sizeof(phr->h);
  2805. hpi_send_recv((struct hpi_message *)&hm.h,
  2806. (struct hpi_response *)&phr->h);
  2807. if (phr->h.error == HPI_ERROR_RESPONSE_BUFFER_TOO_SMALL) {
  2808. HPI_DEBUG_ASSERT(phr->h.specific_error >
  2809. MIN_STRV_PACKET_SIZE
  2810. && phr->h.specific_error < 1000);
  2811. strv_packet_size = phr->h.specific_error;
  2812. } else {
  2813. remaining_attempts = 0;
  2814. if (!phr->h.error)
  2815. hpi_entity_alloc_and_copy(&phr->strv, value);
  2816. }
  2817. hpi_err = phr->h.error;
  2818. kfree(phr);
  2819. }
  2820. return hpi_err;
  2821. }
  2822. u16 hpi_universal_set(const struct hpi_hsubsys *ph_subsys, u32 hC,
  2823. struct hpi_entity *value)
  2824. {
  2825. struct hpi_msg_strv *phm;
  2826. struct hpi_res_strv hr;
  2827. phm = kmalloc(sizeof(phm->h) + value->header.size, GFP_KERNEL);
  2828. HPI_DEBUG_ASSERT(phm != NULL);
  2829. hpi_init_message_responseV1(&phm->h,
  2830. sizeof(phm->h) + value->header.size, &hr.h, sizeof(hr),
  2831. HPI_OBJ_CONTROL, HPI_CONTROL_SET_STATE);
  2832. u32TOINDEXES(hC, &phm->h.adapter_index, &phm->h.obj_index);
  2833. hr.strv.header.size = sizeof(hr.strv);
  2834. memcpy(&phm->strv, value, value->header.size);
  2835. hpi_send_recv((struct hpi_message *)&phm->h,
  2836. (struct hpi_response *)&hr.h);
  2837. return hr.h.error;
  2838. }
  2839. u16 hpi_entity_alloc_and_pack(const enum e_entity_type type,
  2840. const size_t item_count, const enum e_entity_role role, void *value,
  2841. struct hpi_entity **entity)
  2842. {
  2843. size_t bytes_to_copy, total_size;
  2844. u16 hE = 0;
  2845. *entity = NULL;
  2846. hE = hpi_entity_check_type(type);
  2847. if (hE)
  2848. return hE;
  2849. HPI_DEBUG_ASSERT(role > entity_role_null && type < LAST_ENTITY_TYPE);
  2850. bytes_to_copy = entity_type_to_size[type] * item_count;
  2851. total_size = hpi_entity_header_size(*entity) + bytes_to_copy;
  2852. HPI_DEBUG_ASSERT(total_size >= hpi_entity_header_size(*entity)
  2853. && total_size < STR_SIZE_FIELD_MAX);
  2854. *entity = kmalloc(total_size, GFP_KERNEL);
  2855. if (*entity == NULL)
  2856. return HPI_ERROR_MEMORY_ALLOC;
  2857. memcpy((*entity)->value, value, bytes_to_copy);
  2858. (*entity)->header.size =
  2859. hpi_entity_header_size(*entity) + bytes_to_copy;
  2860. (*entity)->header.type = type;
  2861. (*entity)->header.role = role;
  2862. return 0;
  2863. }
  2864. u16 hpi_entity_copy_value_from(struct hpi_entity *entity,
  2865. enum e_entity_type type, size_t item_count, void *value_dst_p)
  2866. {
  2867. size_t bytes_to_copy;
  2868. if (entity->header.type != type)
  2869. return HPI_ERROR_ENTITY_TYPE_MISMATCH;
  2870. if (hpi_entity_item_count(entity) != item_count)
  2871. return HPI_ERROR_ENTITY_ITEM_COUNT;
  2872. bytes_to_copy = entity_type_to_size[type] * item_count;
  2873. memcpy(value_dst_p, entity->value, bytes_to_copy);
  2874. return 0;
  2875. }
  2876. u16 hpi_entity_unpack(struct hpi_entity *entity, enum e_entity_type *type,
  2877. size_t *item_count, enum e_entity_role *role, void **value)
  2878. {
  2879. u16 err = 0;
  2880. HPI_DEBUG_ASSERT(entity != NULL);
  2881. if (type)
  2882. *type = entity->header.type;
  2883. if (role)
  2884. *role = entity->header.role;
  2885. if (value)
  2886. *value = entity->value;
  2887. if (item_count != NULL) {
  2888. if (entity->header.type == entity_type_sequence) {
  2889. void *guard_p = hpi_entity_ptr_to_next(entity);
  2890. struct hpi_entity *next = NULL;
  2891. void *contents = entity->value;
  2892. *item_count = 0;
  2893. while (contents < guard_p) {
  2894. (*item_count)++;
  2895. err = hpi_entity_get_next(contents, 0,
  2896. guard_p, &next);
  2897. if (next == NULL || err)
  2898. break;
  2899. contents = next;
  2900. }
  2901. } else {
  2902. *item_count = hpi_entity_item_count(entity);
  2903. }
  2904. }
  2905. return err;
  2906. }
  2907. u16 hpi_gpio_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
  2908. u32 *ph_gpio, u16 *pw_number_input_bits, u16 *pw_number_output_bits)
  2909. {
  2910. struct hpi_message hm;
  2911. struct hpi_response hr;
  2912. hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_OPEN);
  2913. hm.adapter_index = adapter_index;
  2914. hpi_send_recv(&hm, &hr);
  2915. if (hr.error == 0) {
  2916. *ph_gpio =
  2917. hpi_indexes_to_handle(HPI_OBJ_GPIO, adapter_index, 0);
  2918. if (pw_number_input_bits)
  2919. *pw_number_input_bits = hr.u.l.number_input_bits;
  2920. if (pw_number_output_bits)
  2921. *pw_number_output_bits = hr.u.l.number_output_bits;
  2922. } else
  2923. *ph_gpio = 0;
  2924. return hr.error;
  2925. }
  2926. u16 hpi_gpio_read_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
  2927. u16 bit_index, u16 *pw_bit_data)
  2928. {
  2929. struct hpi_message hm;
  2930. struct hpi_response hr;
  2931. hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_BIT);
  2932. u32TOINDEX(h_gpio, &hm.adapter_index);
  2933. hm.u.l.bit_index = bit_index;
  2934. hpi_send_recv(&hm, &hr);
  2935. *pw_bit_data = hr.u.l.bit_data[0];
  2936. return hr.error;
  2937. }
  2938. u16 hpi_gpio_read_all_bits(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
  2939. u16 aw_all_bit_data[4]
  2940. )
  2941. {
  2942. struct hpi_message hm;
  2943. struct hpi_response hr;
  2944. hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_READ_ALL);
  2945. u32TOINDEX(h_gpio, &hm.adapter_index);
  2946. hpi_send_recv(&hm, &hr);
  2947. if (aw_all_bit_data) {
  2948. aw_all_bit_data[0] = hr.u.l.bit_data[0];
  2949. aw_all_bit_data[1] = hr.u.l.bit_data[1];
  2950. aw_all_bit_data[2] = hr.u.l.bit_data[2];
  2951. aw_all_bit_data[3] = hr.u.l.bit_data[3];
  2952. }
  2953. return hr.error;
  2954. }
  2955. u16 hpi_gpio_write_bit(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
  2956. u16 bit_index, u16 bit_data)
  2957. {
  2958. struct hpi_message hm;
  2959. struct hpi_response hr;
  2960. hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO, HPI_GPIO_WRITE_BIT);
  2961. u32TOINDEX(h_gpio, &hm.adapter_index);
  2962. hm.u.l.bit_index = bit_index;
  2963. hm.u.l.bit_data = bit_data;
  2964. hpi_send_recv(&hm, &hr);
  2965. return hr.error;
  2966. }
  2967. u16 hpi_gpio_write_status(const struct hpi_hsubsys *ph_subsys, u32 h_gpio,
  2968. u16 aw_all_bit_data[4]
  2969. )
  2970. {
  2971. struct hpi_message hm;
  2972. struct hpi_response hr;
  2973. hpi_init_message_response(&hm, &hr, HPI_OBJ_GPIO,
  2974. HPI_GPIO_WRITE_STATUS);
  2975. u32TOINDEX(h_gpio, &hm.adapter_index);
  2976. hpi_send_recv(&hm, &hr);
  2977. if (aw_all_bit_data) {
  2978. aw_all_bit_data[0] = hr.u.l.bit_data[0];
  2979. aw_all_bit_data[1] = hr.u.l.bit_data[1];
  2980. aw_all_bit_data[2] = hr.u.l.bit_data[2];
  2981. aw_all_bit_data[3] = hr.u.l.bit_data[3];
  2982. }
  2983. return hr.error;
  2984. }
  2985. u16 hpi_async_event_open(const struct hpi_hsubsys *ph_subsys,
  2986. u16 adapter_index, u32 *ph_async)
  2987. {
  2988. struct hpi_message hm;
  2989. struct hpi_response hr;
  2990. hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
  2991. HPI_ASYNCEVENT_OPEN);
  2992. hm.adapter_index = adapter_index;
  2993. hpi_send_recv(&hm, &hr);
  2994. if (hr.error == 0)
  2995. *ph_async =
  2996. hpi_indexes_to_handle(HPI_OBJ_ASYNCEVENT,
  2997. adapter_index, 0);
  2998. else
  2999. *ph_async = 0;
  3000. return hr.error;
  3001. }
  3002. u16 hpi_async_event_close(const struct hpi_hsubsys *ph_subsys, u32 h_async)
  3003. {
  3004. struct hpi_message hm;
  3005. struct hpi_response hr;
  3006. hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
  3007. HPI_ASYNCEVENT_OPEN);
  3008. u32TOINDEX(h_async, &hm.adapter_index);
  3009. hpi_send_recv(&hm, &hr);
  3010. return hr.error;
  3011. }
  3012. u16 hpi_async_event_wait(const struct hpi_hsubsys *ph_subsys, u32 h_async,
  3013. u16 maximum_events, struct hpi_async_event *p_events,
  3014. u16 *pw_number_returned)
  3015. {
  3016. return 0;
  3017. }
  3018. u16 hpi_async_event_get_count(const struct hpi_hsubsys *ph_subsys,
  3019. u32 h_async, u16 *pw_count)
  3020. {
  3021. struct hpi_message hm;
  3022. struct hpi_response hr;
  3023. hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
  3024. HPI_ASYNCEVENT_GETCOUNT);
  3025. u32TOINDEX(h_async, &hm.adapter_index);
  3026. hpi_send_recv(&hm, &hr);
  3027. if (hr.error == 0)
  3028. if (pw_count)
  3029. *pw_count = hr.u.as.u.count.count;
  3030. return hr.error;
  3031. }
  3032. u16 hpi_async_event_get(const struct hpi_hsubsys *ph_subsys, u32 h_async,
  3033. u16 maximum_events, struct hpi_async_event *p_events,
  3034. u16 *pw_number_returned)
  3035. {
  3036. struct hpi_message hm;
  3037. struct hpi_response hr;
  3038. hpi_init_message_response(&hm, &hr, HPI_OBJ_ASYNCEVENT,
  3039. HPI_ASYNCEVENT_GET);
  3040. u32TOINDEX(h_async, &hm.adapter_index);
  3041. hpi_send_recv(&hm, &hr);
  3042. if (!hr.error) {
  3043. memcpy(p_events, &hr.u.as.u.event,
  3044. sizeof(struct hpi_async_event));
  3045. *pw_number_returned = 1;
  3046. }
  3047. return hr.error;
  3048. }
  3049. u16 hpi_nv_memory_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
  3050. u32 *ph_nv_memory, u16 *pw_size_in_bytes)
  3051. {
  3052. struct hpi_message hm;
  3053. struct hpi_response hr;
  3054. hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
  3055. HPI_NVMEMORY_OPEN);
  3056. hm.adapter_index = adapter_index;
  3057. hpi_send_recv(&hm, &hr);
  3058. if (hr.error == 0) {
  3059. *ph_nv_memory =
  3060. hpi_indexes_to_handle(HPI_OBJ_NVMEMORY, adapter_index,
  3061. 0);
  3062. if (pw_size_in_bytes)
  3063. *pw_size_in_bytes = hr.u.n.size_in_bytes;
  3064. } else
  3065. *ph_nv_memory = 0;
  3066. return hr.error;
  3067. }
  3068. u16 hpi_nv_memory_read_byte(const struct hpi_hsubsys *ph_subsys,
  3069. u32 h_nv_memory, u16 index, u16 *pw_data)
  3070. {
  3071. struct hpi_message hm;
  3072. struct hpi_response hr;
  3073. hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
  3074. HPI_NVMEMORY_READ_BYTE);
  3075. u32TOINDEX(h_nv_memory, &hm.adapter_index);
  3076. hm.u.n.address = index;
  3077. hpi_send_recv(&hm, &hr);
  3078. *pw_data = hr.u.n.data;
  3079. return hr.error;
  3080. }
  3081. u16 hpi_nv_memory_write_byte(const struct hpi_hsubsys *ph_subsys,
  3082. u32 h_nv_memory, u16 index, u16 data)
  3083. {
  3084. struct hpi_message hm;
  3085. struct hpi_response hr;
  3086. hpi_init_message_response(&hm, &hr, HPI_OBJ_NVMEMORY,
  3087. HPI_NVMEMORY_WRITE_BYTE);
  3088. u32TOINDEX(h_nv_memory, &hm.adapter_index);
  3089. hm.u.n.address = index;
  3090. hm.u.n.data = data;
  3091. hpi_send_recv(&hm, &hr);
  3092. return hr.error;
  3093. }
  3094. u16 hpi_profile_open_all(const struct hpi_hsubsys *ph_subsys,
  3095. u16 adapter_index, u16 profile_index, u32 *ph_profile,
  3096. u16 *pw_max_profiles)
  3097. {
  3098. struct hpi_message hm;
  3099. struct hpi_response hr;
  3100. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
  3101. HPI_PROFILE_OPEN_ALL);
  3102. hm.adapter_index = adapter_index;
  3103. hm.obj_index = profile_index;
  3104. hpi_send_recv(&hm, &hr);
  3105. *pw_max_profiles = hr.u.p.u.o.max_profiles;
  3106. if (hr.error == 0)
  3107. *ph_profile =
  3108. hpi_indexes_to_handle(HPI_OBJ_PROFILE, adapter_index,
  3109. profile_index);
  3110. else
  3111. *ph_profile = 0;
  3112. return hr.error;
  3113. }
  3114. u16 hpi_profile_get(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
  3115. u16 bin_index, u16 *pw_seconds, u32 *pmicro_seconds, u32 *pcall_count,
  3116. u32 *pmax_micro_seconds, u32 *pmin_micro_seconds)
  3117. {
  3118. struct hpi_message hm;
  3119. struct hpi_response hr;
  3120. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE, HPI_PROFILE_GET);
  3121. u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
  3122. hm.u.p.bin_index = bin_index;
  3123. hpi_send_recv(&hm, &hr);
  3124. if (pw_seconds)
  3125. *pw_seconds = hr.u.p.u.t.seconds;
  3126. if (pmicro_seconds)
  3127. *pmicro_seconds = hr.u.p.u.t.micro_seconds;
  3128. if (pcall_count)
  3129. *pcall_count = hr.u.p.u.t.call_count;
  3130. if (pmax_micro_seconds)
  3131. *pmax_micro_seconds = hr.u.p.u.t.max_micro_seconds;
  3132. if (pmin_micro_seconds)
  3133. *pmin_micro_seconds = hr.u.p.u.t.min_micro_seconds;
  3134. return hr.error;
  3135. }
  3136. u16 hpi_profile_get_utilization(const struct hpi_hsubsys *ph_subsys,
  3137. u32 h_profile, u32 *putilization)
  3138. {
  3139. struct hpi_message hm;
  3140. struct hpi_response hr;
  3141. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
  3142. HPI_PROFILE_GET_UTILIZATION);
  3143. u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
  3144. hpi_send_recv(&hm, &hr);
  3145. if (hr.error) {
  3146. if (putilization)
  3147. *putilization = 0;
  3148. } else {
  3149. if (putilization)
  3150. *putilization = hr.u.p.u.t.call_count;
  3151. }
  3152. return hr.error;
  3153. }
  3154. u16 hpi_profile_get_name(const struct hpi_hsubsys *ph_subsys, u32 h_profile,
  3155. u16 bin_index, char *sz_name, u16 name_length)
  3156. {
  3157. struct hpi_message hm;
  3158. struct hpi_response hr;
  3159. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
  3160. HPI_PROFILE_GET_NAME);
  3161. u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
  3162. hm.u.p.bin_index = bin_index;
  3163. hpi_send_recv(&hm, &hr);
  3164. if (hr.error) {
  3165. if (sz_name)
  3166. strcpy(sz_name, "??");
  3167. } else {
  3168. if (sz_name)
  3169. memcpy(sz_name, (char *)hr.u.p.u.n.sz_name,
  3170. name_length);
  3171. }
  3172. return hr.error;
  3173. }
  3174. u16 hpi_profile_start_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile)
  3175. {
  3176. struct hpi_message hm;
  3177. struct hpi_response hr;
  3178. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
  3179. HPI_PROFILE_START_ALL);
  3180. u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
  3181. hpi_send_recv(&hm, &hr);
  3182. return hr.error;
  3183. }
  3184. u16 hpi_profile_stop_all(const struct hpi_hsubsys *ph_subsys, u32 h_profile)
  3185. {
  3186. struct hpi_message hm;
  3187. struct hpi_response hr;
  3188. hpi_init_message_response(&hm, &hr, HPI_OBJ_PROFILE,
  3189. HPI_PROFILE_STOP_ALL);
  3190. u32TOINDEXES(h_profile, &hm.adapter_index, &hm.obj_index);
  3191. hpi_send_recv(&hm, &hr);
  3192. return hr.error;
  3193. }
  3194. u16 hpi_watchdog_open(const struct hpi_hsubsys *ph_subsys, u16 adapter_index,
  3195. u32 *ph_watchdog)
  3196. {
  3197. struct hpi_message hm;
  3198. struct hpi_response hr;
  3199. hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
  3200. HPI_WATCHDOG_OPEN);
  3201. hm.adapter_index = adapter_index;
  3202. hpi_send_recv(&hm, &hr);
  3203. if (hr.error == 0)
  3204. *ph_watchdog =
  3205. hpi_indexes_to_handle(HPI_OBJ_WATCHDOG, adapter_index,
  3206. 0);
  3207. else
  3208. *ph_watchdog = 0;
  3209. return hr.error;
  3210. }
  3211. u16 hpi_watchdog_set_time(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog,
  3212. u32 time_millisec)
  3213. {
  3214. struct hpi_message hm;
  3215. struct hpi_response hr;
  3216. hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
  3217. HPI_WATCHDOG_SET_TIME);
  3218. u32TOINDEX(h_watchdog, &hm.adapter_index);
  3219. hm.u.w.time_ms = time_millisec;
  3220. hpi_send_recv(&hm, &hr);
  3221. return hr.error;
  3222. }
  3223. u16 hpi_watchdog_ping(const struct hpi_hsubsys *ph_subsys, u32 h_watchdog)
  3224. {
  3225. struct hpi_message hm;
  3226. struct hpi_response hr;
  3227. hpi_init_message_response(&hm, &hr, HPI_OBJ_WATCHDOG,
  3228. HPI_WATCHDOG_PING);
  3229. u32TOINDEX(h_watchdog, &hm.adapter_index);
  3230. hpi_send_recv(&hm, &hr);
  3231. return hr.error;
  3232. }