0006-ipts.patch 195 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152115311541155115611571158115911601161116211631164116511661167116811691170117111721173117411751176117711781179118011811182118311841185118611871188118911901191119211931194119511961197119811991200120112021203120412051206120712081209121012111212121312141215121612171218121912201221122212231224122512261227122812291230123112321233123412351236123712381239124012411242124312441245124612471248124912501251125212531254125512561257125812591260126112621263126412651266126712681269127012711272127312741275127612771278127912801281128212831284128512861287128812891290129112921293129412951296129712981299130013011302130313041305130613071308130913101311131213131314131513161317131813191320132113221323132413251326132713281329133013311332133313341335133613371338133913401341134213431344134513461347134813491350135113521353135413551356135713581359136013611362136313641365136613671368136913701371137213731374137513761377137813791380138113821383138413851386138713881389139013911392139313941395139613971398139914001401140214031404140514061407140814091410141114121413141414151416141714181419142014211422142314241425142614271428142914301431143214331434143514361437143814391440144114421443144414451446144714481449145014511452145314541455145614571458145914601461146214631464146514661467146814691470147114721473147414751476147714781479148014811482148314841485148614871488148914901491149214931494149514961497149814991500150115021503150415051506150715081509151015111512151315141515151615171518151915201521152215231524152515261527152815291530153115321533153415351536153715381539154015411542154315441545154615471548154915501551155215531554155515561557155815591560156115621563156415651566156715681569157015711572157315741575157615771578157915801581158215831584158515861587158815891590159115921593159415951596159715981599160016011602160316041605160616071608160916101611161216131614161516161617161816191620162116221623162416251626162716281629163016311632163316341635163616371638163916401641164216431644164516461647164816491650165116521653165416551656165716581659166016611662166316641665166616671668166916701671167216731674167516761677167816791680168116821683168416851686168716881689169016911692169316941695169616971698169917001701170217031704170517061707170817091710171117121713171417151716171717181719172017211722172317241725172617271728172917301731173217331734173517361737173817391740174117421743174417451746174717481749175017511752175317541755175617571758175917601761176217631764176517661767176817691770177117721773177417751776177717781779178017811782178317841785178617871788178917901791179217931794179517961797179817991800180118021803180418051806180718081809181018111812181318141815181618171818181918201821182218231824182518261827182818291830183118321833183418351836183718381839184018411842184318441845184618471848184918501851185218531854185518561857185818591860186118621863186418651866186718681869187018711872187318741875187618771878187918801881188218831884188518861887188818891890189118921893189418951896189718981899190019011902190319041905190619071908190919101911191219131914191519161917191819191920192119221923192419251926192719281929193019311932193319341935193619371938193919401941194219431944194519461947194819491950195119521953195419551956195719581959196019611962196319641965196619671968196919701971197219731974197519761977197819791980198119821983198419851986198719881989199019911992199319941995199619971998199920002001200220032004200520062007200820092010201120122013201420152016201720182019202020212022202320242025202620272028202920302031203220332034203520362037203820392040204120422043204420452046204720482049205020512052205320542055205620572058205920602061206220632064206520662067206820692070207120722073207420752076207720782079208020812082208320842085208620872088208920902091209220932094209520962097209820992100210121022103210421052106210721082109211021112112211321142115211621172118211921202121212221232124212521262127212821292130213121322133213421352136213721382139214021412142214321442145214621472148214921502151215221532154215521562157215821592160216121622163216421652166216721682169217021712172217321742175217621772178217921802181218221832184218521862187218821892190219121922193219421952196219721982199220022012202220322042205220622072208220922102211221222132214221522162217221822192220222122222223222422252226222722282229223022312232223322342235223622372238223922402241224222432244224522462247224822492250225122522253225422552256225722582259226022612262226322642265226622672268226922702271227222732274227522762277227822792280228122822283228422852286228722882289229022912292229322942295229622972298229923002301230223032304230523062307230823092310231123122313231423152316231723182319232023212322232323242325232623272328232923302331233223332334233523362337233823392340234123422343234423452346234723482349235023512352235323542355235623572358235923602361236223632364236523662367236823692370237123722373237423752376237723782379238023812382238323842385238623872388238923902391239223932394239523962397239823992400240124022403240424052406240724082409241024112412241324142415241624172418241924202421242224232424242524262427242824292430243124322433243424352436243724382439244024412442244324442445244624472448244924502451245224532454245524562457245824592460246124622463246424652466246724682469247024712472247324742475247624772478247924802481248224832484248524862487248824892490249124922493249424952496249724982499250025012502250325042505250625072508250925102511251225132514251525162517251825192520252125222523252425252526252725282529253025312532253325342535253625372538253925402541254225432544254525462547254825492550255125522553255425552556255725582559256025612562256325642565256625672568256925702571257225732574257525762577257825792580258125822583258425852586258725882589259025912592259325942595259625972598259926002601260226032604260526062607260826092610261126122613261426152616261726182619262026212622262326242625262626272628262926302631263226332634263526362637263826392640264126422643264426452646264726482649265026512652265326542655265626572658265926602661266226632664266526662667266826692670267126722673267426752676267726782679268026812682268326842685268626872688268926902691269226932694269526962697269826992700270127022703270427052706270727082709271027112712271327142715271627172718271927202721272227232724272527262727272827292730273127322733273427352736273727382739274027412742274327442745274627472748274927502751275227532754275527562757275827592760276127622763276427652766276727682769277027712772277327742775277627772778277927802781278227832784278527862787278827892790279127922793279427952796279727982799280028012802280328042805280628072808280928102811281228132814281528162817281828192820282128222823282428252826282728282829283028312832283328342835283628372838283928402841284228432844284528462847284828492850285128522853285428552856285728582859286028612862286328642865286628672868286928702871287228732874287528762877287828792880288128822883288428852886288728882889289028912892289328942895289628972898289929002901290229032904290529062907290829092910291129122913291429152916291729182919292029212922292329242925292629272928292929302931293229332934293529362937293829392940294129422943294429452946294729482949295029512952295329542955295629572958295929602961296229632964296529662967296829692970297129722973297429752976297729782979298029812982298329842985298629872988298929902991299229932994299529962997299829993000300130023003300430053006300730083009301030113012301330143015301630173018301930203021302230233024302530263027302830293030303130323033303430353036303730383039304030413042304330443045304630473048304930503051305230533054305530563057305830593060306130623063306430653066306730683069307030713072307330743075307630773078307930803081308230833084308530863087308830893090309130923093309430953096309730983099310031013102310331043105310631073108310931103111311231133114311531163117311831193120312131223123312431253126312731283129313031313132313331343135313631373138313931403141314231433144314531463147314831493150315131523153315431553156315731583159316031613162316331643165316631673168316931703171317231733174317531763177317831793180318131823183318431853186318731883189319031913192319331943195319631973198319932003201320232033204320532063207320832093210321132123213321432153216321732183219322032213222322332243225322632273228322932303231323232333234323532363237323832393240324132423243324432453246324732483249325032513252325332543255325632573258325932603261326232633264326532663267326832693270327132723273327432753276327732783279328032813282328332843285328632873288328932903291329232933294329532963297329832993300330133023303330433053306330733083309331033113312331333143315331633173318331933203321332233233324332533263327332833293330333133323333333433353336333733383339334033413342334333443345334633473348334933503351335233533354335533563357335833593360336133623363336433653366336733683369337033713372337333743375337633773378337933803381338233833384338533863387338833893390339133923393339433953396339733983399340034013402340334043405340634073408340934103411341234133414341534163417341834193420342134223423342434253426342734283429343034313432343334343435343634373438343934403441344234433444344534463447344834493450345134523453345434553456345734583459346034613462346334643465346634673468346934703471347234733474347534763477347834793480348134823483348434853486348734883489349034913492349334943495349634973498349935003501350235033504350535063507350835093510351135123513351435153516351735183519352035213522352335243525352635273528352935303531353235333534353535363537353835393540354135423543354435453546354735483549355035513552355335543555355635573558355935603561356235633564356535663567356835693570357135723573357435753576357735783579358035813582358335843585358635873588358935903591359235933594359535963597359835993600360136023603360436053606360736083609361036113612361336143615361636173618361936203621362236233624362536263627362836293630363136323633363436353636363736383639364036413642364336443645364636473648364936503651365236533654365536563657365836593660366136623663366436653666366736683669367036713672367336743675367636773678367936803681368236833684368536863687368836893690369136923693369436953696369736983699370037013702370337043705370637073708370937103711371237133714371537163717371837193720372137223723372437253726372737283729373037313732373337343735373637373738373937403741374237433744374537463747374837493750375137523753375437553756375737583759376037613762376337643765376637673768376937703771377237733774377537763777377837793780378137823783378437853786378737883789379037913792379337943795379637973798379938003801380238033804380538063807380838093810381138123813381438153816381738183819382038213822382338243825382638273828382938303831383238333834383538363837383838393840384138423843384438453846384738483849385038513852385338543855385638573858385938603861386238633864386538663867386838693870387138723873387438753876387738783879388038813882388338843885388638873888388938903891389238933894389538963897389838993900390139023903390439053906390739083909391039113912391339143915391639173918391939203921392239233924392539263927392839293930393139323933393439353936393739383939394039413942394339443945394639473948394939503951395239533954395539563957395839593960396139623963396439653966396739683969397039713972397339743975397639773978397939803981398239833984398539863987398839893990399139923993399439953996399739983999400040014002400340044005400640074008400940104011401240134014401540164017401840194020402140224023402440254026402740284029403040314032403340344035403640374038403940404041404240434044404540464047404840494050405140524053405440554056405740584059406040614062406340644065406640674068406940704071407240734074407540764077407840794080408140824083408440854086408740884089409040914092409340944095409640974098409941004101410241034104410541064107410841094110411141124113411441154116411741184119412041214122412341244125412641274128412941304131413241334134413541364137413841394140414141424143414441454146414741484149415041514152415341544155415641574158415941604161416241634164416541664167416841694170417141724173417441754176417741784179418041814182418341844185418641874188418941904191419241934194419541964197419841994200420142024203420442054206420742084209421042114212421342144215421642174218421942204221422242234224422542264227422842294230423142324233423442354236423742384239424042414242424342444245424642474248424942504251425242534254425542564257425842594260426142624263426442654266426742684269427042714272427342744275427642774278427942804281428242834284428542864287428842894290429142924293429442954296429742984299430043014302430343044305430643074308430943104311431243134314431543164317431843194320432143224323432443254326432743284329433043314332433343344335433643374338433943404341434243434344434543464347434843494350435143524353435443554356435743584359436043614362436343644365436643674368436943704371437243734374437543764377437843794380438143824383438443854386438743884389439043914392439343944395439643974398439944004401440244034404440544064407440844094410441144124413441444154416441744184419442044214422442344244425442644274428442944304431443244334434443544364437443844394440444144424443444444454446444744484449445044514452445344544455445644574458445944604461446244634464446544664467446844694470447144724473447444754476447744784479448044814482448344844485448644874488448944904491449244934494449544964497449844994500450145024503450445054506450745084509451045114512451345144515451645174518451945204521452245234524452545264527452845294530453145324533453445354536453745384539454045414542454345444545454645474548454945504551455245534554455545564557455845594560456145624563456445654566456745684569457045714572457345744575457645774578457945804581458245834584458545864587458845894590459145924593459445954596459745984599460046014602460346044605460646074608460946104611461246134614461546164617461846194620462146224623462446254626462746284629463046314632463346344635463646374638463946404641464246434644464546464647464846494650465146524653465446554656465746584659466046614662466346644665466646674668466946704671467246734674467546764677467846794680468146824683468446854686468746884689469046914692469346944695469646974698469947004701470247034704470547064707470847094710471147124713471447154716471747184719472047214722472347244725472647274728472947304731473247334734473547364737473847394740474147424743474447454746474747484749475047514752475347544755475647574758475947604761476247634764476547664767476847694770477147724773477447754776477747784779478047814782478347844785478647874788478947904791479247934794479547964797479847994800480148024803480448054806480748084809481048114812481348144815481648174818481948204821482248234824482548264827482848294830483148324833483448354836483748384839484048414842484348444845484648474848484948504851485248534854485548564857485848594860486148624863486448654866486748684869487048714872487348744875487648774878487948804881488248834884488548864887488848894890489148924893489448954896489748984899490049014902490349044905490649074908490949104911491249134914491549164917491849194920492149224923492449254926492749284929493049314932493349344935493649374938493949404941494249434944494549464947494849494950495149524953495449554956495749584959496049614962496349644965496649674968496949704971497249734974497549764977497849794980498149824983498449854986498749884989499049914992499349944995499649974998499950005001500250035004500550065007500850095010501150125013501450155016501750185019502050215022502350245025502650275028502950305031503250335034503550365037503850395040504150425043504450455046504750485049505050515052505350545055505650575058505950605061506250635064506550665067506850695070507150725073507450755076507750785079508050815082508350845085508650875088508950905091509250935094509550965097509850995100510151025103510451055106510751085109511051115112511351145115511651175118511951205121512251235124512551265127512851295130513151325133513451355136513751385139514051415142514351445145514651475148514951505151515251535154515551565157515851595160516151625163516451655166516751685169517051715172517351745175517651775178517951805181518251835184518551865187518851895190519151925193519451955196519751985199520052015202520352045205520652075208520952105211521252135214521552165217521852195220522152225223522452255226522752285229523052315232523352345235523652375238523952405241524252435244524552465247524852495250525152525253525452555256525752585259526052615262526352645265526652675268526952705271527252735274527552765277527852795280528152825283528452855286528752885289529052915292529352945295529652975298529953005301530253035304530553065307530853095310531153125313531453155316531753185319532053215322532353245325532653275328532953305331533253335334533553365337533853395340534153425343534453455346534753485349535053515352535353545355535653575358535953605361536253635364536553665367536853695370537153725373537453755376537753785379538053815382538353845385538653875388538953905391539253935394539553965397539853995400540154025403540454055406540754085409541054115412541354145415541654175418541954205421542254235424542554265427542854295430543154325433543454355436543754385439544054415442544354445445544654475448544954505451545254535454545554565457545854595460546154625463546454655466546754685469547054715472547354745475547654775478547954805481548254835484548554865487548854895490549154925493549454955496549754985499550055015502550355045505550655075508550955105511551255135514551555165517551855195520552155225523552455255526552755285529553055315532553355345535553655375538553955405541554255435544554555465547554855495550555155525553555455555556555755585559556055615562556355645565556655675568556955705571557255735574557555765577557855795580558155825583558455855586558755885589559055915592559355945595559655975598559956005601560256035604560556065607560856095610561156125613561456155616561756185619562056215622562356245625562656275628562956305631563256335634563556365637563856395640564156425643564456455646564756485649565056515652565356545655565656575658565956605661566256635664566556665667566856695670567156725673567456755676567756785679568056815682568356845685568656875688568956905691569256935694569556965697569856995700570157025703570457055706570757085709571057115712571357145715571657175718571957205721572257235724572557265727572857295730573157325733573457355736573757385739574057415742574357445745574657475748574957505751575257535754575557565757575857595760576157625763576457655766576757685769577057715772577357745775577657775778577957805781578257835784578557865787578857895790579157925793579457955796579757985799580058015802580358045805580658075808580958105811581258135814581558165817581858195820582158225823582458255826582758285829583058315832583358345835583658375838583958405841584258435844584558465847584858495850585158525853585458555856585758585859586058615862586358645865586658675868586958705871587258735874587558765877587858795880588158825883588458855886588758885889589058915892589358945895589658975898589959005901590259035904590559065907590859095910591159125913591459155916591759185919592059215922592359245925592659275928592959305931593259335934593559365937593859395940594159425943594459455946594759485949595059515952595359545955595659575958595959605961596259635964596559665967596859695970597159725973597459755976597759785979598059815982598359845985598659875988598959905991599259935994599559965997599859996000600160026003600460056006600760086009601060116012601360146015601660176018601960206021602260236024602560266027602860296030603160326033603460356036603760386039604060416042604360446045604660476048604960506051605260536054605560566057605860596060606160626063606460656066606760686069607060716072607360746075607660776078607960806081608260836084608560866087608860896090609160926093609460956096609760986099610061016102610361046105610661076108610961106111611261136114611561166117611861196120612161226123612461256126612761286129613061316132613361346135613661376138613961406141614261436144614561466147614861496150615161526153615461556156615761586159616061616162616361646165616661676168616961706171617261736174617561766177617861796180618161826183618461856186618761886189619061916192619361946195619661976198619962006201620262036204620562066207620862096210621162126213621462156216621762186219622062216222622362246225622662276228622962306231623262336234623562366237623862396240624162426243624462456246624762486249625062516252625362546255625662576258625962606261626262636264626562666267626862696270627162726273627462756276627762786279628062816282628362846285628662876288628962906291629262936294629562966297629862996300630163026303630463056306630763086309631063116312631363146315631663176318631963206321632263236324632563266327632863296330633163326333633463356336633763386339634063416342634363446345634663476348634963506351635263536354635563566357635863596360636163626363636463656366636763686369637063716372637363746375637663776378637963806381638263836384638563866387638863896390639163926393639463956396639763986399640064016402640364046405640664076408640964106411641264136414641564166417641864196420642164226423642464256426642764286429643064316432643364346435643664376438643964406441644264436444644564466447644864496450645164526453645464556456645764586459646064616462646364646465646664676468646964706471647264736474647564766477647864796480648164826483648464856486648764886489649064916492649364946495649664976498649965006501650265036504650565066507650865096510651165126513651465156516651765186519652065216522652365246525652665276528652965306531653265336534653565366537653865396540654165426543654465456546654765486549655065516552655365546555655665576558655965606561656265636564656565666567656865696570657165726573657465756576657765786579658065816582658365846585658665876588658965906591659265936594659565966597659865996600660166026603660466056606660766086609661066116612661366146615661666176618661966206621662266236624662566266627662866296630663166326633663466356636663766386639664066416642664366446645664666476648664966506651665266536654665566566657665866596660666166626663666466656666666766686669667066716672667366746675667666776678667966806681668266836684668566866687668866896690669166926693669466956696669766986699670067016702670367046705670667076708670967106711671267136714671567166717671867196720672167226723672467256726672767286729673067316732673367346735673667376738673967406741674267436744674567466747674867496750675167526753675467556756675767586759676067616762676367646765676667676768676967706771677267736774677567766777677867796780678167826783678467856786678767886789679067916792679367946795679667976798679968006801680268036804680568066807680868096810681168126813681468156816681768186819682068216822682368246825682668276828682968306831683268336834683568366837683868396840684168426843684468456846684768486849685068516852685368546855685668576858685968606861686268636864686568666867686868696870687168726873687468756876687768786879688068816882688368846885688668876888688968906891689268936894689568966897689868996900690169026903690469056906690769086909691069116912691369146915691669176918691969206921692269236924692569266927692869296930693169326933693469356936693769386939694069416942694369446945694669476948694969506951695269536954695569566957695869596960696169626963696469656966696769686969697069716972697369746975697669776978697969806981698269836984698569866987698869896990699169926993699469956996699769986999700070017002700370047005700670077008700970107011701270137014701570167017701870197020702170227023702470257026702770287029703070317032703370347035703670377038703970407041704270437044704570467047704870497050705170527053705470557056705770587059706070617062706370647065706670677068706970707071707270737074707570767077707870797080708170827083708470857086708770887089709070917092709370947095709670977098709971007101710271037104710571067107710871097110711171127113711471157116711771187119712071217122712371247125712671277128712971307131713271337134713571367137713871397140714171427143714471457146714771487149715071517152715371547155715671577158715971607161716271637164716571667167716871697170717171727173717471757176717771787179718071817182718371847185718671877188718971907191719271937194719571967197719871997200720172027203720472057206720772087209721072117212721372147215721672177218721972207221722272237224722572267227722872297230723172327233723472357236723772387239724072417242724372447245724672477248724972507251725272537254725572567257725872597260726172627263726472657266726772687269727072717272727372747275727672777278727972807281728272837284728572867287728872897290729172927293729472957296729772987299730073017302730373047305730673077308730973107311731273137314
  1. From ab9cccbae943c29bf47ae3522da72af934cca6f8 Mon Sep 17 00:00:00 2001
  2. From: Maximilian Luz <luzmaximilian@gmail.com>
  3. Date: Sat, 28 Sep 2019 17:58:17 +0200
  4. Subject: [PATCH] Add support for Intel IPTS touch devices
  5. Patchset: ipts
  6. ---
  7. drivers/gpu/drm/i915/Makefile | 3 +
  8. drivers/gpu/drm/i915/i915_debugfs.c | 63 +-
  9. drivers/gpu/drm/i915/i915_drv.c | 9 +-
  10. drivers/gpu/drm/i915/i915_drv.h | 3 +
  11. drivers/gpu/drm/i915/i915_gem_context.c | 12 +
  12. drivers/gpu/drm/i915/i915_irq.c | 7 +-
  13. drivers/gpu/drm/i915/i915_params.c | 5 +-
  14. drivers/gpu/drm/i915/i915_params.h | 5 +-
  15. drivers/gpu/drm/i915/intel_guc.h | 1 +
  16. drivers/gpu/drm/i915/intel_guc_submission.c | 89 +-
  17. drivers/gpu/drm/i915/intel_guc_submission.h | 4 +
  18. drivers/gpu/drm/i915/intel_ipts.c | 650 ++++++++++++
  19. drivers/gpu/drm/i915/intel_ipts.h | 34 +
  20. drivers/gpu/drm/i915/intel_lrc.c | 12 +-
  21. drivers/gpu/drm/i915/intel_lrc.h | 8 +
  22. drivers/gpu/drm/i915/intel_panel.c | 7 +
  23. drivers/misc/Kconfig | 1 +
  24. drivers/misc/Makefile | 1 +
  25. drivers/misc/ipts/Kconfig | 12 +
  26. drivers/misc/ipts/Makefile | 19 +
  27. drivers/misc/ipts/companion.c | 211 ++++
  28. drivers/misc/ipts/companion.h | 25 +
  29. drivers/misc/ipts/companion/Kconfig | 8 +
  30. drivers/misc/ipts/companion/Makefile | 2 +
  31. drivers/misc/ipts/companion/ipts-surface.c | 157 +++
  32. drivers/misc/ipts/dbgfs.c | 277 +++++
  33. drivers/misc/ipts/gfx.c | 180 ++++
  34. drivers/misc/ipts/gfx.h | 25 +
  35. drivers/misc/ipts/hid.c | 469 +++++++++
  36. drivers/misc/ipts/hid.h | 21 +
  37. drivers/misc/ipts/ipts.c | 62 ++
  38. drivers/misc/ipts/ipts.h | 172 +++
  39. drivers/misc/ipts/kernel.c | 1047 +++++++++++++++++++
  40. drivers/misc/ipts/kernel.h | 17 +
  41. drivers/misc/ipts/mei-msgs.h | 901 ++++++++++++++++
  42. drivers/misc/ipts/mei.c | 238 +++++
  43. drivers/misc/ipts/msg-handler.c | 405 +++++++
  44. drivers/misc/ipts/msg-handler.h | 28 +
  45. drivers/misc/ipts/params.c | 42 +
  46. drivers/misc/ipts/params.h | 25 +
  47. drivers/misc/ipts/resource.c | 291 ++++++
  48. drivers/misc/ipts/resource.h | 26 +
  49. drivers/misc/ipts/sensor-regs.h | 834 +++++++++++++++
  50. drivers/misc/ipts/state.h | 22 +
  51. drivers/misc/mei/hw-me-regs.h | 1 +
  52. drivers/misc/mei/pci-me.c | 1 +
  53. include/linux/ipts-binary.h | 140 +++
  54. include/linux/ipts-companion.h | 29 +
  55. include/linux/ipts-gfx.h | 86 ++
  56. include/linux/ipts.h | 19 +
  57. 50 files changed, 6684 insertions(+), 22 deletions(-)
  58. create mode 100644 drivers/gpu/drm/i915/intel_ipts.c
  59. create mode 100644 drivers/gpu/drm/i915/intel_ipts.h
  60. create mode 100644 drivers/misc/ipts/Kconfig
  61. create mode 100644 drivers/misc/ipts/Makefile
  62. create mode 100644 drivers/misc/ipts/companion.c
  63. create mode 100644 drivers/misc/ipts/companion.h
  64. create mode 100644 drivers/misc/ipts/companion/Kconfig
  65. create mode 100644 drivers/misc/ipts/companion/Makefile
  66. create mode 100644 drivers/misc/ipts/companion/ipts-surface.c
  67. create mode 100644 drivers/misc/ipts/dbgfs.c
  68. create mode 100644 drivers/misc/ipts/gfx.c
  69. create mode 100644 drivers/misc/ipts/gfx.h
  70. create mode 100644 drivers/misc/ipts/hid.c
  71. create mode 100644 drivers/misc/ipts/hid.h
  72. create mode 100644 drivers/misc/ipts/ipts.c
  73. create mode 100644 drivers/misc/ipts/ipts.h
  74. create mode 100644 drivers/misc/ipts/kernel.c
  75. create mode 100644 drivers/misc/ipts/kernel.h
  76. create mode 100644 drivers/misc/ipts/mei-msgs.h
  77. create mode 100644 drivers/misc/ipts/mei.c
  78. create mode 100644 drivers/misc/ipts/msg-handler.c
  79. create mode 100644 drivers/misc/ipts/msg-handler.h
  80. create mode 100644 drivers/misc/ipts/params.c
  81. create mode 100644 drivers/misc/ipts/params.h
  82. create mode 100644 drivers/misc/ipts/resource.c
  83. create mode 100644 drivers/misc/ipts/resource.h
  84. create mode 100644 drivers/misc/ipts/sensor-regs.h
  85. create mode 100644 drivers/misc/ipts/state.h
  86. create mode 100644 include/linux/ipts-binary.h
  87. create mode 100644 include/linux/ipts-companion.h
  88. create mode 100644 include/linux/ipts-gfx.h
  89. create mode 100644 include/linux/ipts.h
  90. diff --git a/drivers/gpu/drm/i915/Makefile b/drivers/gpu/drm/i915/Makefile
  91. index 5794f102f9b8..6ae0e91a213a 100644
  92. --- a/drivers/gpu/drm/i915/Makefile
  93. +++ b/drivers/gpu/drm/i915/Makefile
  94. @@ -155,6 +155,9 @@ i915-y += dvo_ch7017.o \
  95. vlv_dsi.o \
  96. vlv_dsi_pll.o
  97. +# intel precise touch & stylus
  98. +i915-y += intel_ipts.o
  99. +
  100. # Post-mortem debug and GPU hang state capture
  101. i915-$(CONFIG_DRM_I915_CAPTURE_ERROR) += i915_gpu_error.o
  102. i915-$(CONFIG_DRM_I915_SELFTEST) += \
  103. diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
  104. index e063e98d1e82..99becb6aed68 100644
  105. --- a/drivers/gpu/drm/i915/i915_debugfs.c
  106. +++ b/drivers/gpu/drm/i915/i915_debugfs.c
  107. @@ -31,6 +31,7 @@
  108. #include <linux/sched/mm.h>
  109. #include "intel_drv.h"
  110. #include "intel_guc_submission.h"
  111. +#include "intel_ipts.h"
  112. static inline struct drm_i915_private *node_to_i915(struct drm_info_node *node)
  113. {
  114. @@ -4695,6 +4696,64 @@ static const struct file_operations i915_fifo_underrun_reset_ops = {
  115. .llseek = default_llseek,
  116. };
  117. +static ssize_t
  118. +i915_ipts_cleanup_write(struct file *filp,
  119. + const char __user *ubuf,
  120. + size_t cnt, loff_t *ppos)
  121. +{
  122. + struct drm_i915_private *dev_priv = filp->private_data;
  123. + struct drm_device *dev = &dev_priv->drm;
  124. + int ret;
  125. + bool flag;
  126. +
  127. + ret = kstrtobool_from_user(ubuf, cnt, &flag);
  128. + if (ret)
  129. + return ret;
  130. +
  131. + if (!flag)
  132. + return cnt;
  133. +
  134. + ipts_cleanup(dev);
  135. +
  136. + return cnt;
  137. +}
  138. +
  139. +static const struct file_operations i915_ipts_cleanup_ops = {
  140. + .owner = THIS_MODULE,
  141. + .open = simple_open,
  142. + .write = i915_ipts_cleanup_write,
  143. + .llseek = default_llseek,
  144. +};
  145. +
  146. +static ssize_t
  147. +i915_ipts_init_write(struct file *filp,
  148. + const char __user *ubuf,
  149. + size_t cnt, loff_t *ppos)
  150. +{
  151. + struct drm_i915_private *dev_priv = filp->private_data;
  152. + struct drm_device *dev = &dev_priv->drm;
  153. + int ret;
  154. + bool flag;
  155. +
  156. + ret = kstrtobool_from_user(ubuf, cnt, &flag);
  157. + if (ret)
  158. + return ret;
  159. +
  160. + if (!flag)
  161. + return cnt;
  162. +
  163. + ipts_init(dev);
  164. +
  165. + return cnt;
  166. +}
  167. +
  168. +static const struct file_operations i915_ipts_init_ops = {
  169. + .owner = THIS_MODULE,
  170. + .open = simple_open,
  171. + .write = i915_ipts_init_write,
  172. + .llseek = default_llseek,
  173. +};
  174. +
  175. static const struct drm_info_list i915_debugfs_list[] = {
  176. {"i915_capabilities", i915_capabilities, 0},
  177. {"i915_gem_objects", i915_gem_object_info, 0},
  178. @@ -4773,7 +4832,9 @@ static const struct i915_debugfs_files {
  179. {"i915_hpd_storm_ctl", &i915_hpd_storm_ctl_fops},
  180. {"i915_ipc_status", &i915_ipc_status_fops},
  181. {"i915_drrs_ctl", &i915_drrs_ctl_fops},
  182. - {"i915_edp_psr_debug", &i915_edp_psr_debug_fops}
  183. + {"i915_edp_psr_debug", &i915_edp_psr_debug_fops},
  184. + {"i915_ipts_cleanup", &i915_ipts_cleanup_ops},
  185. + {"i915_ipts_init", &i915_ipts_init_ops},
  186. };
  187. int i915_debugfs_register(struct drm_i915_private *dev_priv)
  188. diff --git a/drivers/gpu/drm/i915/i915_drv.c b/drivers/gpu/drm/i915/i915_drv.c
  189. index b0d76a7a0946..81fba8e5ab05 100644
  190. --- a/drivers/gpu/drm/i915/i915_drv.c
  191. +++ b/drivers/gpu/drm/i915/i915_drv.c
  192. @@ -47,11 +47,12 @@
  193. #include <drm/i915_drm.h>
  194. #include "i915_drv.h"
  195. -#include "i915_trace.h"
  196. #include "i915_pmu.h"
  197. #include "i915_query.h"
  198. +#include "i915_trace.h"
  199. #include "i915_vgpu.h"
  200. #include "intel_drv.h"
  201. +#include "intel_ipts.h"
  202. #include "intel_uc.h"
  203. static struct drm_driver driver;
  204. @@ -696,6 +697,9 @@ static int i915_load_modeset_init(struct drm_device *dev)
  205. /* Only enable hotplug handling once the fbdev is fully set up. */
  206. intel_hpd_init(dev_priv);
  207. + if (INTEL_GEN(dev_priv) >= 9 && i915_modparams.enable_guc && i915_modparams.enable_ipts)
  208. + ipts_init(dev);
  209. +
  210. return 0;
  211. cleanup_gem:
  212. @@ -1438,6 +1442,9 @@ void i915_driver_unload(struct drm_device *dev)
  213. struct drm_i915_private *dev_priv = to_i915(dev);
  214. struct pci_dev *pdev = dev_priv->drm.pdev;
  215. + if (INTEL_GEN(dev_priv) >= 9 && i915_modparams.enable_guc && i915_modparams.enable_ipts)
  216. + ipts_cleanup(dev);
  217. +
  218. i915_driver_unregister(dev_priv);
  219. if (i915_gem_suspend(dev_priv))
  220. diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
  221. index 37c80cfecd09..948eb874342d 100644
  222. --- a/drivers/gpu/drm/i915/i915_drv.h
  223. +++ b/drivers/gpu/drm/i915/i915_drv.h
  224. @@ -3236,6 +3236,9 @@ void i915_gem_object_do_bit_17_swizzle(struct drm_i915_gem_object *obj,
  225. void i915_gem_object_save_bit_17_swizzle(struct drm_i915_gem_object *obj,
  226. struct sg_table *pages);
  227. +struct i915_gem_context *
  228. +i915_gem_context_create_ipts(struct drm_device *dev);
  229. +
  230. static inline struct i915_gem_context *
  231. __i915_gem_context_lookup_rcu(struct drm_i915_file_private *file_priv, u32 id)
  232. {
  233. diff --git a/drivers/gpu/drm/i915/i915_gem_context.c b/drivers/gpu/drm/i915/i915_gem_context.c
  234. index ef383fd42988..89da4ff09431 100644
  235. --- a/drivers/gpu/drm/i915/i915_gem_context.c
  236. +++ b/drivers/gpu/drm/i915/i915_gem_context.c
  237. @@ -472,6 +472,18 @@ static bool needs_preempt_context(struct drm_i915_private *i915)
  238. return HAS_LOGICAL_RING_PREEMPTION(i915);
  239. }
  240. +struct i915_gem_context *i915_gem_context_create_ipts(struct drm_device *dev)
  241. +{
  242. + struct drm_i915_private *dev_priv = to_i915(dev);
  243. + struct i915_gem_context *ctx;
  244. +
  245. + BUG_ON(!mutex_is_locked(&dev->struct_mutex));
  246. +
  247. + ctx = i915_gem_create_context(dev_priv, NULL);
  248. +
  249. + return ctx;
  250. +}
  251. +
  252. int i915_gem_contexts_init(struct drm_i915_private *dev_priv)
  253. {
  254. struct i915_gem_context *ctx;
  255. diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
  256. index b7c398232136..adf168aed2fe 100644
  257. --- a/drivers/gpu/drm/i915/i915_irq.c
  258. +++ b/drivers/gpu/drm/i915/i915_irq.c
  259. @@ -36,6 +36,7 @@
  260. #include "i915_drv.h"
  261. #include "i915_trace.h"
  262. #include "intel_drv.h"
  263. +#include "intel_ipts.h"
  264. /**
  265. * DOC: interrupt handling
  266. @@ -1503,6 +1504,9 @@ gen8_cs_irq_handler(struct intel_engine_cs *engine, u32 iir)
  267. tasklet |= USES_GUC_SUBMISSION(engine->i915);
  268. }
  269. + if (iir & GT_RENDER_PIPECTL_NOTIFY_INTERRUPT && i915_modparams.enable_ipts)
  270. + ipts_notify_complete();
  271. +
  272. if (tasklet)
  273. tasklet_hi_schedule(&engine->execlists.tasklet);
  274. }
  275. @@ -4123,7 +4127,8 @@ static void gen8_gt_irq_postinstall(struct drm_i915_private *dev_priv)
  276. {
  277. /* These are interrupts we'll toggle with the ring mask register */
  278. uint32_t gt_interrupts[] = {
  279. - GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  280. + GT_RENDER_PIPECTL_NOTIFY_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  281. + GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  282. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  283. GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT |
  284. GT_CONTEXT_SWITCH_INTERRUPT << GEN8_BCS_IRQ_SHIFT,
  285. diff --git a/drivers/gpu/drm/i915/i915_params.c b/drivers/gpu/drm/i915/i915_params.c
  286. index 295e981e4a39..84415814c007 100644
  287. --- a/drivers/gpu/drm/i915/i915_params.c
  288. +++ b/drivers/gpu/drm/i915/i915_params.c
  289. @@ -145,7 +145,10 @@ i915_param_named_unsafe(edp_vswing, int, 0400,
  290. i915_param_named_unsafe(enable_guc, int, 0400,
  291. "Enable GuC load for GuC submission and/or HuC load. "
  292. "Required functionality can be selected using bitmask values. "
  293. - "(-1=auto, 0=disable [default], 1=GuC submission, 2=HuC load)");
  294. + "(-1=auto [default], 0=disable, 1=GuC submission, 2=HuC load)");
  295. +
  296. +i915_param_named_unsafe(enable_ipts, int, 0400,
  297. + "Enable IPTS Touchscreen and Pen support (default: 1)");
  298. i915_param_named(guc_log_level, int, 0400,
  299. "GuC firmware logging level. Requires GuC to be loaded. "
  300. diff --git a/drivers/gpu/drm/i915/i915_params.h b/drivers/gpu/drm/i915/i915_params.h
  301. index 6c4d4a21474b..4ab800c3de6d 100644
  302. --- a/drivers/gpu/drm/i915/i915_params.h
  303. +++ b/drivers/gpu/drm/i915/i915_params.h
  304. @@ -46,7 +46,7 @@ struct drm_printer;
  305. param(int, disable_power_well, -1) \
  306. param(int, enable_ips, 1) \
  307. param(int, invert_brightness, 0) \
  308. - param(int, enable_guc, 0) \
  309. + param(int, enable_guc, -1) \
  310. param(int, guc_log_level, -1) \
  311. param(char *, guc_firmware_path, NULL) \
  312. param(char *, huc_firmware_path, NULL) \
  313. @@ -68,7 +68,8 @@ struct drm_printer;
  314. param(bool, nuclear_pageflip, false) \
  315. param(bool, enable_dp_mst, true) \
  316. param(bool, enable_dpcd_backlight, false) \
  317. - param(bool, enable_gvt, false)
  318. + param(bool, enable_gvt, false) \
  319. + param(int, enable_ipts, 1)
  320. #define MEMBER(T, member, ...) T member;
  321. struct i915_params {
  322. diff --git a/drivers/gpu/drm/i915/intel_guc.h b/drivers/gpu/drm/i915/intel_guc.h
  323. index 4121928a495e..8967376accf3 100644
  324. --- a/drivers/gpu/drm/i915/intel_guc.h
  325. +++ b/drivers/gpu/drm/i915/intel_guc.h
  326. @@ -69,6 +69,7 @@ struct intel_guc {
  327. struct intel_guc_client *execbuf_client;
  328. struct intel_guc_client *preempt_client;
  329. + struct intel_guc_client *ipts_client;
  330. struct guc_preempt_work preempt_work[I915_NUM_ENGINES];
  331. struct workqueue_struct *preempt_wq;
  332. diff --git a/drivers/gpu/drm/i915/intel_guc_submission.c b/drivers/gpu/drm/i915/intel_guc_submission.c
  333. index 4aa5e6463e7b..da80c5f17fee 100644
  334. --- a/drivers/gpu/drm/i915/intel_guc_submission.c
  335. +++ b/drivers/gpu/drm/i915/intel_guc_submission.c
  336. @@ -88,12 +88,17 @@ static inline struct i915_priolist *to_priolist(struct rb_node *rb)
  337. static inline bool is_high_priority(struct intel_guc_client *client)
  338. {
  339. - return (client->priority == GUC_CLIENT_PRIORITY_KMD_HIGH ||
  340. - client->priority == GUC_CLIENT_PRIORITY_HIGH);
  341. + return (client->priority == GUC_CLIENT_PRIORITY_HIGH);
  342. +}
  343. +
  344. +static inline bool is_high_priority_kmd(struct intel_guc_client *client)
  345. +{
  346. + return (client->priority == GUC_CLIENT_PRIORITY_KMD_HIGH);
  347. }
  348. static int reserve_doorbell(struct intel_guc_client *client)
  349. {
  350. + struct drm_i915_private *dev_priv = guc_to_i915(client->guc);
  351. unsigned long offset;
  352. unsigned long end;
  353. u16 id;
  354. @@ -106,10 +111,14 @@ static int reserve_doorbell(struct intel_guc_client *client)
  355. * priority contexts, the second half for high-priority ones.
  356. */
  357. offset = 0;
  358. - end = GUC_NUM_DOORBELLS / 2;
  359. - if (is_high_priority(client)) {
  360. - offset = end;
  361. - end += offset;
  362. + if (IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv)) {
  363. + end = GUC_NUM_DOORBELLS;
  364. + } else {
  365. + end = GUC_NUM_DOORBELLS/2;
  366. + if (is_high_priority(client)) {
  367. + offset = end;
  368. + end += offset;
  369. + }
  370. }
  371. id = find_next_zero_bit(client->guc->doorbell_bitmap, end, offset);
  372. @@ -355,9 +364,15 @@ static void guc_stage_desc_init(struct intel_guc *guc,
  373. desc = __get_stage_desc(client);
  374. memset(desc, 0, sizeof(*desc));
  375. - desc->attribute = GUC_STAGE_DESC_ATTR_ACTIVE |
  376. - GUC_STAGE_DESC_ATTR_KERNEL;
  377. - if (is_high_priority(client))
  378. + desc->attribute = GUC_STAGE_DESC_ATTR_ACTIVE;
  379. + if ((client->priority == GUC_CLIENT_PRIORITY_KMD_NORMAL) ||
  380. + (client->priority == GUC_CLIENT_PRIORITY_KMD_HIGH)) {
  381. + desc->attribute |= GUC_STAGE_DESC_ATTR_KERNEL;
  382. + } else {
  383. + desc->attribute |= GUC_STAGE_DESC_ATTR_PCH;
  384. + }
  385. +
  386. + if (is_high_priority_kmd(client))
  387. desc->attribute |= GUC_STAGE_DESC_ATTR_PREEMPT;
  388. desc->stage_id = client->stage_id;
  389. desc->priority = client->priority;
  390. @@ -1204,7 +1219,8 @@ static void guc_interrupts_capture(struct drm_i915_private *dev_priv)
  391. I915_WRITE(RING_MODE_GEN7(engine), irqs);
  392. /* route USER_INTERRUPT to Host, all others are sent to GuC. */
  393. - irqs = GT_RENDER_USER_INTERRUPT << GEN8_RCS_IRQ_SHIFT |
  394. + irqs = (GT_RENDER_USER_INTERRUPT | GT_RENDER_PIPECTL_NOTIFY_INTERRUPT)
  395. + << GEN8_RCS_IRQ_SHIFT |
  396. GT_RENDER_USER_INTERRUPT << GEN8_BCS_IRQ_SHIFT;
  397. /* These three registers have the same bit definitions */
  398. I915_WRITE(GUC_BCS_RCS_IER, ~irqs);
  399. @@ -1349,6 +1365,59 @@ void intel_guc_submission_disable(struct intel_guc *guc)
  400. guc_clients_doorbell_fini(guc);
  401. }
  402. +int i915_guc_ipts_submission_enable(struct drm_i915_private *dev_priv,
  403. + struct i915_gem_context *ctx)
  404. +{
  405. + struct intel_guc *guc = &dev_priv->guc;
  406. + struct intel_guc_client *client;
  407. + int err;
  408. + int ret;
  409. +
  410. + /* client for execbuf submission */
  411. + client = guc_client_alloc(dev_priv,
  412. + INTEL_INFO(dev_priv)->ring_mask,
  413. + IS_SKYLAKE(dev_priv) || IS_KABYLAKE(dev_priv) ? GUC_CLIENT_PRIORITY_HIGH : GUC_CLIENT_PRIORITY_NORMAL,
  414. + ctx);
  415. + if (IS_ERR(client)) {
  416. + DRM_ERROR("Failed to create normal GuC client!\n");
  417. + return -ENOMEM;
  418. + }
  419. +
  420. + guc->ipts_client = client;
  421. +
  422. + err = intel_guc_sample_forcewake(guc);
  423. + if (err)
  424. + return err;
  425. +
  426. + ret = create_doorbell(guc->ipts_client);
  427. + if (ret)
  428. + return ret;
  429. +
  430. + return 0;
  431. +}
  432. +
  433. +void i915_guc_ipts_submission_disable(struct drm_i915_private *dev_priv)
  434. +{
  435. + struct intel_guc *guc = &dev_priv->guc;
  436. +
  437. + if (!guc->ipts_client)
  438. + return;
  439. +
  440. + destroy_doorbell(guc->ipts_client);
  441. + guc_client_free(guc->ipts_client);
  442. + guc->ipts_client = NULL;
  443. +}
  444. +
  445. +void i915_guc_ipts_reacquire_doorbell(struct drm_i915_private *dev_priv)
  446. +{
  447. + struct intel_guc *guc = &dev_priv->guc;
  448. +
  449. + int err = __guc_allocate_doorbell(guc, guc->ipts_client->stage_id);
  450. +
  451. + if (err)
  452. + DRM_ERROR("Not able to reacquire IPTS doorbell\n");
  453. +}
  454. +
  455. #if IS_ENABLED(CONFIG_DRM_I915_SELFTEST)
  456. #include "selftests/intel_guc.c"
  457. #endif
  458. diff --git a/drivers/gpu/drm/i915/intel_guc_submission.h b/drivers/gpu/drm/i915/intel_guc_submission.h
  459. index fb081cefef93..71fc7986585a 100644
  460. --- a/drivers/gpu/drm/i915/intel_guc_submission.h
  461. +++ b/drivers/gpu/drm/i915/intel_guc_submission.h
  462. @@ -79,5 +79,9 @@ void intel_guc_submission_disable(struct intel_guc *guc);
  463. void intel_guc_submission_fini(struct intel_guc *guc);
  464. int intel_guc_preempt_work_create(struct intel_guc *guc);
  465. void intel_guc_preempt_work_destroy(struct intel_guc *guc);
  466. +int i915_guc_ipts_submission_enable(struct drm_i915_private *dev_priv,
  467. + struct i915_gem_context *ctx);
  468. +void i915_guc_ipts_submission_disable(struct drm_i915_private *dev_priv);
  469. +void i915_guc_ipts_reacquire_doorbell(struct drm_i915_private *dev_priv);
  470. #endif
  471. diff --git a/drivers/gpu/drm/i915/intel_ipts.c b/drivers/gpu/drm/i915/intel_ipts.c
  472. new file mode 100644
  473. index 000000000000..c1199074924a
  474. --- /dev/null
  475. +++ b/drivers/gpu/drm/i915/intel_ipts.c
  476. @@ -0,0 +1,650 @@
  477. +/*
  478. + * Copyright 2016 Intel Corporation
  479. + *
  480. + * Permission is hereby granted, free of charge, to any person obtaining a
  481. + * copy of this software and associated documentation files (the "Software"),
  482. + * to deal in the Software without restriction, including without limitation
  483. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  484. + * and/or sell copies of the Software, and to permit persons to whom the
  485. + * Software is furnished to do so, subject to the following conditions:
  486. + *
  487. + * The above copyright notice and this permission notice (including the next
  488. + * paragraph) shall be included in all copies or substantial portions of the
  489. + * Software.
  490. + *
  491. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  492. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  493. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  494. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  495. + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  496. + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  497. + * IN THE SOFTWARE.
  498. + *
  499. + */
  500. +
  501. +#include <drm/drmP.h>
  502. +#include <linux/ipts-gfx.h>
  503. +#include <linux/kernel.h>
  504. +#include <linux/module.h>
  505. +#include <linux/types.h>
  506. +
  507. +#include "intel_guc_submission.h"
  508. +#include "i915_drv.h"
  509. +
  510. +#define SUPPORTED_IPTS_INTERFACE_VERSION 1
  511. +
  512. +#define REACQUIRE_DB_THRESHOLD 10
  513. +
  514. +#define DB_LOST_CHECK_STEP1_INTERVAL 2500 // ms
  515. +#define DB_LOST_CHECK_STEP2_INTERVAL 1000 // ms
  516. +
  517. +// CTX for ipts support
  518. +struct ipts {
  519. + struct drm_device *dev;
  520. + struct i915_gem_context *ipts_context;
  521. + struct ipts_callback ipts_clbks;
  522. +
  523. + // buffers' list
  524. + struct {
  525. + spinlock_t lock;
  526. + struct list_head list;
  527. + } buffers;
  528. +
  529. + void *data;
  530. +
  531. + struct delayed_work reacquire_db_work;
  532. + struct ipts_wq_info wq_info;
  533. + u32 old_tail;
  534. + u32 old_head;
  535. + bool need_reacquire_db;
  536. +
  537. + bool connected;
  538. + bool initialized;
  539. +};
  540. +
  541. +struct ipts ipts;
  542. +
  543. +struct ipts_object {
  544. + struct list_head list;
  545. + struct drm_i915_gem_object *gem_obj;
  546. + void *cpu_addr;
  547. +};
  548. +
  549. +static struct ipts_object *ipts_object_create(size_t size, u32 flags)
  550. +{
  551. + struct drm_i915_private *dev_priv = to_i915(ipts.dev);
  552. + struct ipts_object *obj = NULL;
  553. + struct drm_i915_gem_object *gem_obj = NULL;
  554. + int ret = 0;
  555. +
  556. + obj = kzalloc(sizeof(*obj), GFP_KERNEL);
  557. + if (!obj)
  558. + return NULL;
  559. +
  560. + size = roundup(size, PAGE_SIZE);
  561. + if (size == 0) {
  562. + ret = -EINVAL;
  563. + goto err_out;
  564. + }
  565. +
  566. + // Allocate the new object
  567. + gem_obj = i915_gem_object_create(dev_priv, size);
  568. + if (gem_obj == NULL) {
  569. + ret = -ENOMEM;
  570. + goto err_out;
  571. + }
  572. +
  573. + if (flags & IPTS_BUF_FLAG_CONTIGUOUS) {
  574. + ret = i915_gem_object_attach_phys(gem_obj, PAGE_SIZE);
  575. + if (ret) {
  576. + pr_info(">> ipts no contiguous : %d\n", ret);
  577. + goto err_out;
  578. + }
  579. + }
  580. +
  581. + obj->gem_obj = gem_obj;
  582. +
  583. + spin_lock(&ipts.buffers.lock);
  584. + list_add_tail(&obj->list, &ipts.buffers.list);
  585. + spin_unlock(&ipts.buffers.lock);
  586. +
  587. + return obj;
  588. +
  589. +err_out:
  590. +
  591. + if (gem_obj)
  592. + i915_gem_free_object(&gem_obj->base);
  593. +
  594. + kfree(obj);
  595. +
  596. + return NULL;
  597. +}
  598. +
  599. +static void ipts_object_free(struct ipts_object *obj)
  600. +{
  601. + spin_lock(&ipts.buffers.lock);
  602. + list_del(&obj->list);
  603. + spin_unlock(&ipts.buffers.lock);
  604. +
  605. + i915_gem_free_object(&obj->gem_obj->base);
  606. + kfree(obj);
  607. +}
  608. +
  609. +static int ipts_object_pin(struct ipts_object *obj,
  610. + struct i915_gem_context *ipts_ctx)
  611. +{
  612. + struct i915_address_space *vm = NULL;
  613. + struct i915_vma *vma = NULL;
  614. + struct drm_i915_private *dev_priv = to_i915(ipts.dev);
  615. + int ret = 0;
  616. +
  617. + if (ipts_ctx->ppgtt)
  618. + vm = &ipts_ctx->ppgtt->vm;
  619. + else
  620. + vm = &dev_priv->ggtt.vm;
  621. +
  622. + vma = i915_vma_instance(obj->gem_obj, vm, NULL);
  623. + if (IS_ERR(vma)) {
  624. + DRM_ERROR("cannot find or create vma\n");
  625. + return -1;
  626. + }
  627. +
  628. + ret = i915_vma_pin(vma, 0, PAGE_SIZE, PIN_USER);
  629. +
  630. + return ret;
  631. +}
  632. +
  633. +static void ipts_object_unpin(struct ipts_object *obj)
  634. +{
  635. + // TODO: Add support
  636. +}
  637. +
  638. +static void *ipts_object_map(struct ipts_object *obj)
  639. +{
  640. + return i915_gem_object_pin_map(obj->gem_obj, I915_MAP_WB);
  641. +}
  642. +
  643. +static void ipts_object_unmap(struct ipts_object *obj)
  644. +{
  645. + i915_gem_object_unpin_map(obj->gem_obj);
  646. + obj->cpu_addr = NULL;
  647. +}
  648. +
  649. +static int create_ipts_context(void)
  650. +{
  651. + struct i915_gem_context *ipts_ctx = NULL;
  652. + struct drm_i915_private *dev_priv = to_i915(ipts.dev);
  653. + struct intel_context *ce = NULL;
  654. + struct intel_context *pin_ret;
  655. + int ret = 0;
  656. +
  657. + // Initialize the context right away.
  658. + ret = i915_mutex_lock_interruptible(ipts.dev);
  659. + if (ret) {
  660. + DRM_ERROR("i915_mutex_lock_interruptible failed\n");
  661. + return ret;
  662. + }
  663. +
  664. + ipts_ctx = i915_gem_context_create_ipts(ipts.dev);
  665. + if (IS_ERR(ipts_ctx)) {
  666. + DRM_ERROR("Failed to create IPTS context (error %ld)\n",
  667. + PTR_ERR(ipts_ctx));
  668. + ret = PTR_ERR(ipts_ctx);
  669. + goto err_unlock;
  670. + }
  671. +
  672. + ce = to_intel_context(ipts_ctx, dev_priv->engine[RCS]);
  673. + if (IS_ERR(ce)) {
  674. + DRM_ERROR("Failed to create intel context (error %ld)\n",
  675. + PTR_ERR(ce));
  676. + ret = PTR_ERR(ce);
  677. + goto err_unlock;
  678. + }
  679. +
  680. + ret = execlists_context_deferred_alloc(ipts_ctx, dev_priv->engine[RCS], ce);
  681. + if (ret) {
  682. + DRM_DEBUG("lr context allocation failed: %d\n", ret);
  683. + goto err_ctx;
  684. + }
  685. +
  686. + pin_ret = execlists_context_pin(dev_priv->engine[RCS], ipts_ctx);
  687. + if (IS_ERR(pin_ret)) {
  688. + DRM_DEBUG("lr context pinning failed: %ld\n", PTR_ERR(pin_ret));
  689. + goto err_ctx;
  690. + }
  691. +
  692. + // Release the mutex
  693. + mutex_unlock(&ipts.dev->struct_mutex);
  694. +
  695. + spin_lock_init(&ipts.buffers.lock);
  696. + INIT_LIST_HEAD(&ipts.buffers.list);
  697. +
  698. + ipts.ipts_context = ipts_ctx;
  699. +
  700. + return 0;
  701. +
  702. +err_ctx:
  703. + if (ipts_ctx)
  704. + i915_gem_context_put(ipts_ctx);
  705. +
  706. +err_unlock:
  707. + mutex_unlock(&ipts.dev->struct_mutex);
  708. +
  709. + return ret;
  710. +}
  711. +
  712. +static void destroy_ipts_context(void)
  713. +{
  714. + struct i915_gem_context *ipts_ctx = NULL;
  715. + struct drm_i915_private *dev_priv = to_i915(ipts.dev);
  716. + struct intel_context *ce = NULL;
  717. + int ret = 0;
  718. +
  719. + ipts_ctx = ipts.ipts_context;
  720. +
  721. + ce = to_intel_context(ipts_ctx, dev_priv->engine[RCS]);
  722. +
  723. + // Initialize the context right away.
  724. + ret = i915_mutex_lock_interruptible(ipts.dev);
  725. + if (ret) {
  726. + DRM_ERROR("i915_mutex_lock_interruptible failed\n");
  727. + return;
  728. + }
  729. +
  730. + execlists_context_unpin(ce);
  731. + i915_gem_context_put(ipts_ctx);
  732. +
  733. + mutex_unlock(&ipts.dev->struct_mutex);
  734. +}
  735. +
  736. +int ipts_notify_complete(void)
  737. +{
  738. + if (ipts.ipts_clbks.workload_complete)
  739. + ipts.ipts_clbks.workload_complete(ipts.data);
  740. +
  741. + return 0;
  742. +}
  743. +
  744. +int ipts_notify_backlight_status(bool backlight_on)
  745. +{
  746. + if (ipts.ipts_clbks.notify_gfx_status) {
  747. + if (backlight_on) {
  748. + ipts.ipts_clbks.notify_gfx_status(
  749. + IPTS_NOTIFY_STA_BACKLIGHT_ON, ipts.data);
  750. + schedule_delayed_work(&ipts.reacquire_db_work,
  751. + msecs_to_jiffies(DB_LOST_CHECK_STEP1_INTERVAL));
  752. + } else {
  753. + ipts.ipts_clbks.notify_gfx_status(
  754. + IPTS_NOTIFY_STA_BACKLIGHT_OFF, ipts.data);
  755. + cancel_delayed_work(&ipts.reacquire_db_work);
  756. + }
  757. + }
  758. +
  759. + return 0;
  760. +}
  761. +
  762. +static void ipts_reacquire_db(struct ipts *ipts_p)
  763. +{
  764. + int ret = 0;
  765. +
  766. + ret = i915_mutex_lock_interruptible(ipts_p->dev);
  767. + if (ret) {
  768. + DRM_ERROR("i915_mutex_lock_interruptible failed\n");
  769. + return;
  770. + }
  771. +
  772. + // Reacquire the doorbell
  773. + i915_guc_ipts_reacquire_doorbell(ipts_p->dev->dev_private);
  774. +
  775. + mutex_unlock(&ipts_p->dev->struct_mutex);
  776. +}
  777. +
  778. +static int ipts_get_wq_info(uint64_t gfx_handle,
  779. + struct ipts_wq_info *wq_info)
  780. +{
  781. + if (gfx_handle != (uint64_t)&ipts) {
  782. + DRM_ERROR("invalid gfx handle\n");
  783. + return -EINVAL;
  784. + }
  785. +
  786. + *wq_info = ipts.wq_info;
  787. +
  788. + ipts_reacquire_db(&ipts);
  789. + schedule_delayed_work(&ipts.reacquire_db_work,
  790. + msecs_to_jiffies(DB_LOST_CHECK_STEP1_INTERVAL));
  791. +
  792. + return 0;
  793. +}
  794. +
  795. +static int set_wq_info(void)
  796. +{
  797. + struct drm_i915_private *dev_priv = to_i915(ipts.dev);
  798. + struct intel_guc *guc = &dev_priv->guc;
  799. + struct intel_guc_client *client;
  800. + struct guc_process_desc *desc;
  801. + struct ipts_wq_info *wq_info;
  802. + void *base = NULL;
  803. + u64 phy_base = 0;
  804. +
  805. + wq_info = &ipts.wq_info;
  806. +
  807. + client = guc->ipts_client;
  808. + if (!client) {
  809. + DRM_ERROR("IPTS GuC client is NOT available\n");
  810. + return -EINVAL;
  811. + }
  812. +
  813. + base = client->vaddr;
  814. + desc = (struct guc_process_desc *)
  815. + ((u64)base + client->proc_desc_offset);
  816. +
  817. + desc->wq_base_addr = (u64)base + GUC_DB_SIZE;
  818. + desc->db_base_addr = (u64)base + client->doorbell_offset;
  819. +
  820. + // IPTS expects physical addresses to pass it to ME
  821. + phy_base = sg_dma_address(client->vma->pages->sgl);
  822. +
  823. + wq_info->db_addr = desc->db_base_addr;
  824. + wq_info->db_phy_addr = phy_base + client->doorbell_offset;
  825. + wq_info->db_cookie_offset = offsetof(struct guc_doorbell_info, cookie);
  826. + wq_info->wq_addr = desc->wq_base_addr;
  827. + wq_info->wq_phy_addr = phy_base + GUC_DB_SIZE;
  828. + wq_info->wq_head_addr = (u64)&desc->head;
  829. + wq_info->wq_tail_addr = (u64)&desc->tail;
  830. + wq_info->wq_size = desc->wq_size_bytes;
  831. +
  832. + wq_info->wq_head_phy_addr = phy_base + client->proc_desc_offset +
  833. + offsetof(struct guc_process_desc, head);
  834. +
  835. + wq_info->wq_tail_phy_addr = phy_base + client->proc_desc_offset +
  836. + offsetof(struct guc_process_desc, tail);
  837. +
  838. + return 0;
  839. +}
  840. +
  841. +static int ipts_init_wq(void)
  842. +{
  843. + int ret = 0;
  844. +
  845. + ret = i915_mutex_lock_interruptible(ipts.dev);
  846. + if (ret) {
  847. + DRM_ERROR("i915_mutex_lock_interruptible failed\n");
  848. + return ret;
  849. + }
  850. +
  851. + // disable IPTS submission
  852. + i915_guc_ipts_submission_disable(ipts.dev->dev_private);
  853. +
  854. + // enable IPTS submission
  855. + ret = i915_guc_ipts_submission_enable(ipts.dev->dev_private,
  856. + ipts.ipts_context);
  857. + if (ret) {
  858. + DRM_ERROR("i915_guc_ipts_submission_enable failed: %d\n", ret);
  859. + goto out;
  860. + }
  861. +
  862. + ret = set_wq_info();
  863. + if (ret) {
  864. + DRM_ERROR("set_wq_info failed\n");
  865. + goto out;
  866. + }
  867. +
  868. +out:
  869. + mutex_unlock(&ipts.dev->struct_mutex);
  870. +
  871. + return ret;
  872. +}
  873. +
  874. +static void ipts_release_wq(void)
  875. +{
  876. + int ret = 0;
  877. +
  878. + ret = i915_mutex_lock_interruptible(ipts.dev);
  879. + if (ret) {
  880. + DRM_ERROR("i915_mutex_lock_interruptible failed\n");
  881. + return;
  882. + }
  883. +
  884. + // disable IPTS submission
  885. + i915_guc_ipts_submission_disable(ipts.dev->dev_private);
  886. +
  887. + mutex_unlock(&ipts.dev->struct_mutex);
  888. +}
  889. +
  890. +static int ipts_map_buffer(u64 gfx_handle, struct ipts_mapbuffer *mapbuf)
  891. +{
  892. + struct ipts_object *obj;
  893. + struct i915_gem_context *ipts_ctx = NULL;
  894. + struct drm_i915_private *dev_priv = to_i915(ipts.dev);
  895. + struct i915_address_space *vm = NULL;
  896. + struct i915_vma *vma = NULL;
  897. + int ret = 0;
  898. +
  899. + if (gfx_handle != (uint64_t)&ipts) {
  900. + DRM_ERROR("invalid gfx handle\n");
  901. + return -EINVAL;
  902. + }
  903. +
  904. + // Acquire mutex first
  905. + ret = i915_mutex_lock_interruptible(ipts.dev);
  906. + if (ret) {
  907. + DRM_ERROR("i915_mutex_lock_interruptible failed\n");
  908. + return -EINVAL;
  909. + }
  910. +
  911. + obj = ipts_object_create(mapbuf->size, mapbuf->flags);
  912. + if (!obj)
  913. + return -ENOMEM;
  914. +
  915. + ipts_ctx = ipts.ipts_context;
  916. + ret = ipts_object_pin(obj, ipts_ctx);
  917. + if (ret) {
  918. + DRM_ERROR("Not able to pin iTouch obj\n");
  919. + ipts_object_free(obj);
  920. + mutex_unlock(&ipts.dev->struct_mutex);
  921. + return -ENOMEM;
  922. + }
  923. +
  924. + if (mapbuf->flags & IPTS_BUF_FLAG_CONTIGUOUS)
  925. + obj->cpu_addr = obj->gem_obj->phys_handle->vaddr;
  926. + else
  927. + obj->cpu_addr = ipts_object_map(obj);
  928. +
  929. + if (ipts_ctx->ppgtt)
  930. + vm = &ipts_ctx->ppgtt->vm;
  931. + else
  932. + vm = &dev_priv->ggtt.vm;
  933. +
  934. + vma = i915_vma_instance(obj->gem_obj, vm, NULL);
  935. + if (IS_ERR(vma)) {
  936. + DRM_ERROR("cannot find or create vma\n");
  937. + return -EINVAL;
  938. + }
  939. +
  940. + mapbuf->gfx_addr = (void *)vma->node.start;
  941. + mapbuf->cpu_addr = (void *)obj->cpu_addr;
  942. + mapbuf->buf_handle = (u64)obj;
  943. + if (mapbuf->flags & IPTS_BUF_FLAG_CONTIGUOUS)
  944. + mapbuf->phy_addr = (u64)obj->gem_obj->phys_handle->busaddr;
  945. +
  946. + // Release the mutex
  947. + mutex_unlock(&ipts.dev->struct_mutex);
  948. +
  949. + return 0;
  950. +}
  951. +
  952. +static int ipts_unmap_buffer(uint64_t gfx_handle, uint64_t buf_handle)
  953. +{
  954. + struct ipts_object *obj = (struct ipts_object *)buf_handle;
  955. +
  956. + if (gfx_handle != (uint64_t)&ipts) {
  957. + DRM_ERROR("invalid gfx handle\n");
  958. + return -EINVAL;
  959. + }
  960. +
  961. + if (!obj->gem_obj->phys_handle)
  962. + ipts_object_unmap(obj);
  963. +
  964. + ipts_object_unpin(obj);
  965. + ipts_object_free(obj);
  966. +
  967. + return 0;
  968. +}
  969. +
  970. +int ipts_connect(struct ipts_connect *ipts_connect)
  971. +{
  972. + u32 flags = DL_FLAG_PM_RUNTIME | DL_FLAG_AUTOREMOVE_CONSUMER;
  973. + struct drm_i915_private *dev_priv = to_i915(ipts.dev);
  974. +
  975. + if (!ipts.initialized)
  976. + return -EIO;
  977. +
  978. + if (!ipts_connect)
  979. + return -EINVAL;
  980. +
  981. + if (ipts_connect->if_version > SUPPORTED_IPTS_INTERFACE_VERSION)
  982. + return -EINVAL;
  983. +
  984. + // set up device-link for PM
  985. + if (!device_link_add(ipts_connect->client, ipts.dev->dev, flags))
  986. + return -EFAULT;
  987. +
  988. + // return gpu operations for ipts
  989. + ipts_connect->ipts_ops.get_wq_info = ipts_get_wq_info;
  990. + ipts_connect->ipts_ops.map_buffer = ipts_map_buffer;
  991. + ipts_connect->ipts_ops.unmap_buffer = ipts_unmap_buffer;
  992. + ipts_connect->gfx_version = INTEL_INFO(dev_priv)->gen;
  993. + ipts_connect->gfx_handle = (uint64_t)&ipts;
  994. +
  995. + // save callback and data
  996. + ipts.data = ipts_connect->data;
  997. + ipts.ipts_clbks = ipts_connect->ipts_cb;
  998. +
  999. + ipts.connected = true;
  1000. +
  1001. + return 0;
  1002. +}
  1003. +EXPORT_SYMBOL_GPL(ipts_connect);
  1004. +
  1005. +void ipts_disconnect(uint64_t gfx_handle)
  1006. +{
  1007. + if (!ipts.initialized)
  1008. + return;
  1009. +
  1010. + if (gfx_handle != (uint64_t)&ipts || !ipts.connected) {
  1011. + DRM_ERROR("invalid gfx handle\n");
  1012. + return;
  1013. + }
  1014. +
  1015. + ipts.data = 0;
  1016. + memset(&ipts.ipts_clbks, 0, sizeof(struct ipts_callback));
  1017. +
  1018. + ipts.connected = false;
  1019. +}
  1020. +EXPORT_SYMBOL_GPL(ipts_disconnect);
  1021. +
  1022. +static void reacquire_db_work_func(struct work_struct *work)
  1023. +{
  1024. + struct delayed_work *d_work = container_of(work,
  1025. + struct delayed_work, work);
  1026. + struct ipts *ipts_p = container_of(d_work,
  1027. + struct ipts, reacquire_db_work);
  1028. + u32 head;
  1029. + u32 tail;
  1030. + u32 size;
  1031. + u32 load;
  1032. +
  1033. + head = *(u32 *)ipts_p->wq_info.wq_head_addr;
  1034. + tail = *(u32 *)ipts_p->wq_info.wq_tail_addr;
  1035. + size = ipts_p->wq_info.wq_size;
  1036. +
  1037. + if (head >= tail)
  1038. + load = head - tail;
  1039. + else
  1040. + load = head + size - tail;
  1041. +
  1042. + if (load < REACQUIRE_DB_THRESHOLD) {
  1043. + ipts_p->need_reacquire_db = false;
  1044. + goto reschedule_work;
  1045. + }
  1046. +
  1047. + if (ipts_p->need_reacquire_db) {
  1048. + if (ipts_p->old_head == head &&
  1049. + ipts_p->old_tail == tail)
  1050. + ipts_reacquire_db(ipts_p);
  1051. + ipts_p->need_reacquire_db = false;
  1052. + } else {
  1053. + ipts_p->old_head = head;
  1054. + ipts_p->old_tail = tail;
  1055. + ipts_p->need_reacquire_db = true;
  1056. +
  1057. + // recheck
  1058. + schedule_delayed_work(&ipts_p->reacquire_db_work,
  1059. + msecs_to_jiffies(DB_LOST_CHECK_STEP2_INTERVAL));
  1060. + return;
  1061. + }
  1062. +
  1063. +reschedule_work:
  1064. + schedule_delayed_work(&ipts_p->reacquire_db_work,
  1065. + msecs_to_jiffies(DB_LOST_CHECK_STEP1_INTERVAL));
  1066. +}
  1067. +
  1068. +/**
  1069. + * ipts_init - Initialize ipts support
  1070. + * @dev: drm device
  1071. + *
  1072. + * Setup the required structures for ipts.
  1073. + */
  1074. +int ipts_init(struct drm_device *dev)
  1075. +{
  1076. + int ret = 0;
  1077. +
  1078. + pr_info("ipts: initializing ipts\n");
  1079. +
  1080. + ipts.dev = dev;
  1081. + INIT_DELAYED_WORK(&ipts.reacquire_db_work,
  1082. + reacquire_db_work_func);
  1083. +
  1084. + ret = create_ipts_context();
  1085. + if (ret)
  1086. + return -ENOMEM;
  1087. +
  1088. + ret = ipts_init_wq();
  1089. + if (ret)
  1090. + return ret;
  1091. +
  1092. + ipts.initialized = true;
  1093. + pr_info("ipts: Intel iTouch framework initialized\n");
  1094. +
  1095. + return ret;
  1096. +}
  1097. +
  1098. +void ipts_cleanup(struct drm_device *dev)
  1099. +{
  1100. + struct ipts_object *obj, *n;
  1101. +
  1102. + if (ipts.dev != dev)
  1103. + return;
  1104. +
  1105. + list_for_each_entry_safe(obj, n, &ipts.buffers.list, list) {
  1106. + struct i915_vma *vma, *vn;
  1107. +
  1108. + list_for_each_entry_safe(vma, vn, &obj->list, obj_link) {
  1109. + vma->flags &= ~I915_VMA_PIN_MASK;
  1110. + i915_vma_destroy(vma);
  1111. + }
  1112. +
  1113. + list_del(&obj->list);
  1114. +
  1115. + if (!obj->gem_obj->phys_handle)
  1116. + ipts_object_unmap(obj);
  1117. +
  1118. + ipts_object_unpin(obj);
  1119. + i915_gem_free_object(&obj->gem_obj->base);
  1120. + kfree(obj);
  1121. + }
  1122. +
  1123. + ipts_release_wq();
  1124. + destroy_ipts_context();
  1125. + cancel_delayed_work(&ipts.reacquire_db_work);
  1126. +}
  1127. diff --git a/drivers/gpu/drm/i915/intel_ipts.h b/drivers/gpu/drm/i915/intel_ipts.h
  1128. new file mode 100644
  1129. index 000000000000..67f90b72f237
  1130. --- /dev/null
  1131. +++ b/drivers/gpu/drm/i915/intel_ipts.h
  1132. @@ -0,0 +1,34 @@
  1133. +/*
  1134. + * Copyright © 2016 Intel Corporation
  1135. + *
  1136. + * Permission is hereby granted, free of charge, to any person obtaining a
  1137. + * copy of this software and associated documentation files (the "Software"),
  1138. + * to deal in the Software without restriction, including without limitation
  1139. + * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  1140. + * and/or sell copies of the Software, and to permit persons to whom the
  1141. + * Software is furnished to do so, subject to the following conditions:
  1142. + *
  1143. + * The above copyright notice and this permission notice (including the next
  1144. + * paragraph) shall be included in all copies or substantial portions of the
  1145. + * Software.
  1146. + *
  1147. + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  1148. + * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  1149. + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  1150. + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
  1151. + * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
  1152. + * FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS
  1153. + * IN THE SOFTWARE.
  1154. + *
  1155. + */
  1156. +#ifndef _INTEL_IPTS_H_
  1157. +#define _INTEL_IPTS_H_
  1158. +
  1159. +#include <drm/drm_device.h>
  1160. +
  1161. +int ipts_init(struct drm_device *dev);
  1162. +void ipts_cleanup(struct drm_device *dev);
  1163. +int ipts_notify_backlight_status(bool backlight_on);
  1164. +int ipts_notify_complete(void);
  1165. +
  1166. +#endif //_INTEL_IPTS_H_
  1167. diff --git a/drivers/gpu/drm/i915/intel_lrc.c b/drivers/gpu/drm/i915/intel_lrc.c
  1168. index 13e97faabaa7..a4af67d3d6ff 100644
  1169. --- a/drivers/gpu/drm/i915/intel_lrc.c
  1170. +++ b/drivers/gpu/drm/i915/intel_lrc.c
  1171. @@ -164,9 +164,6 @@
  1172. #define WA_TAIL_DWORDS 2
  1173. #define WA_TAIL_BYTES (sizeof(u32) * WA_TAIL_DWORDS)
  1174. -static int execlists_context_deferred_alloc(struct i915_gem_context *ctx,
  1175. - struct intel_engine_cs *engine,
  1176. - struct intel_context *ce);
  1177. static void execlists_init_reg_state(u32 *reg_state,
  1178. struct i915_gem_context *ctx,
  1179. struct intel_engine_cs *engine,
  1180. @@ -1292,7 +1289,7 @@ static void execlists_context_destroy(struct intel_context *ce)
  1181. i915_gem_object_put(ce->state->obj);
  1182. }
  1183. -static void execlists_context_unpin(struct intel_context *ce)
  1184. +void execlists_context_unpin(struct intel_context *ce)
  1185. {
  1186. intel_ring_unpin(ce->ring);
  1187. @@ -1379,7 +1376,7 @@ static const struct intel_context_ops execlists_context_ops = {
  1188. .destroy = execlists_context_destroy,
  1189. };
  1190. -static struct intel_context *
  1191. +struct intel_context *
  1192. execlists_context_pin(struct intel_engine_cs *engine,
  1193. struct i915_gem_context *ctx)
  1194. {
  1195. @@ -2479,6 +2476,9 @@ int logical_render_ring_init(struct intel_engine_cs *engine)
  1196. logical_ring_setup(engine);
  1197. + engine->irq_keep_mask |= GT_RENDER_PIPECTL_NOTIFY_INTERRUPT
  1198. + << GEN8_RCS_IRQ_SHIFT;
  1199. +
  1200. if (HAS_L3_DPF(dev_priv))
  1201. engine->irq_keep_mask |= GT_RENDER_L3_PARITY_ERROR_INTERRUPT;
  1202. @@ -2743,7 +2743,7 @@ populate_lr_context(struct i915_gem_context *ctx,
  1203. return ret;
  1204. }
  1205. -static int execlists_context_deferred_alloc(struct i915_gem_context *ctx,
  1206. +int execlists_context_deferred_alloc(struct i915_gem_context *ctx,
  1207. struct intel_engine_cs *engine,
  1208. struct intel_context *ce)
  1209. {
  1210. diff --git a/drivers/gpu/drm/i915/intel_lrc.h b/drivers/gpu/drm/i915/intel_lrc.h
  1211. index 4dfb78e3ec7e..32159231a16e 100644
  1212. --- a/drivers/gpu/drm/i915/intel_lrc.h
  1213. +++ b/drivers/gpu/drm/i915/intel_lrc.h
  1214. @@ -106,4 +106,12 @@ void intel_lr_context_resume(struct drm_i915_private *dev_priv);
  1215. void intel_execlists_set_default_submission(struct intel_engine_cs *engine);
  1216. +struct intel_context *
  1217. +execlists_context_pin(struct intel_engine_cs *engine,
  1218. + struct i915_gem_context *ctx);
  1219. +void execlists_context_unpin(struct intel_context *ce);
  1220. +int execlists_context_deferred_alloc(struct i915_gem_context *ctx,
  1221. + struct intel_engine_cs *engine,
  1222. + struct intel_context *ce);
  1223. +
  1224. #endif /* _INTEL_LRC_H_ */
  1225. diff --git a/drivers/gpu/drm/i915/intel_panel.c b/drivers/gpu/drm/i915/intel_panel.c
  1226. index 4a9f139e7b73..c137a57f6702 100644
  1227. --- a/drivers/gpu/drm/i915/intel_panel.c
  1228. +++ b/drivers/gpu/drm/i915/intel_panel.c
  1229. @@ -34,6 +34,7 @@
  1230. #include <linux/moduleparam.h>
  1231. #include <linux/pwm.h>
  1232. #include "intel_drv.h"
  1233. +#include "intel_ipts.h"
  1234. #define CRC_PMIC_PWM_PERIOD_NS 21333
  1235. @@ -659,6 +660,9 @@ static void lpt_disable_backlight(const struct drm_connector_state *old_conn_sta
  1236. struct drm_i915_private *dev_priv = to_i915(connector->base.dev);
  1237. u32 tmp;
  1238. + if (INTEL_GEN(dev_priv) >= 9 && i915_modparams.enable_guc && i915_modparams.enable_ipts)
  1239. + ipts_notify_backlight_status(false);
  1240. +
  1241. intel_panel_actually_set_backlight(old_conn_state, 0);
  1242. /*
  1243. @@ -846,6 +850,9 @@ static void lpt_enable_backlight(const struct intel_crtc_state *crtc_state,
  1244. /* This won't stick until the above enable. */
  1245. intel_panel_actually_set_backlight(conn_state, panel->backlight.level);
  1246. +
  1247. + if (INTEL_GEN(dev_priv) >= 9 && i915_modparams.enable_guc && i915_modparams.enable_ipts)
  1248. + ipts_notify_backlight_status(true);
  1249. }
  1250. static void pch_enable_backlight(const struct intel_crtc_state *crtc_state,
  1251. diff --git a/drivers/misc/Kconfig b/drivers/misc/Kconfig
  1252. index 3726eacdf65d..77263b5f5915 100644
  1253. --- a/drivers/misc/Kconfig
  1254. +++ b/drivers/misc/Kconfig
  1255. @@ -520,6 +520,7 @@ source "drivers/misc/ti-st/Kconfig"
  1256. source "drivers/misc/lis3lv02d/Kconfig"
  1257. source "drivers/misc/altera-stapl/Kconfig"
  1258. source "drivers/misc/mei/Kconfig"
  1259. +source "drivers/misc/ipts/Kconfig"
  1260. source "drivers/misc/vmw_vmci/Kconfig"
  1261. source "drivers/misc/mic/Kconfig"
  1262. source "drivers/misc/genwqe/Kconfig"
  1263. diff --git a/drivers/misc/Makefile b/drivers/misc/Makefile
  1264. index af22bbc3d00c..eb1eb0d58c32 100644
  1265. --- a/drivers/misc/Makefile
  1266. +++ b/drivers/misc/Makefile
  1267. @@ -44,6 +44,7 @@ obj-y += lis3lv02d/
  1268. obj-$(CONFIG_USB_SWITCH_FSA9480) += fsa9480.o
  1269. obj-$(CONFIG_ALTERA_STAPL) +=altera-stapl/
  1270. obj-$(CONFIG_INTEL_MEI) += mei/
  1271. +obj-$(CONFIG_INTEL_IPTS) += ipts/
  1272. obj-$(CONFIG_VMWARE_VMCI) += vmw_vmci/
  1273. obj-$(CONFIG_LATTICE_ECP3_CONFIG) += lattice-ecp3-config.o
  1274. obj-$(CONFIG_SRAM) += sram.o
  1275. diff --git a/drivers/misc/ipts/Kconfig b/drivers/misc/ipts/Kconfig
  1276. new file mode 100644
  1277. index 000000000000..900d2c58ca74
  1278. --- /dev/null
  1279. +++ b/drivers/misc/ipts/Kconfig
  1280. @@ -0,0 +1,12 @@
  1281. +# SPDX-License-Identifier: GPL-2.0-or-later
  1282. +config INTEL_IPTS
  1283. + tristate "Intel Precise Touch & Stylus"
  1284. + select INTEL_MEI
  1285. + depends on X86 && PCI && HID && DRM_I915
  1286. + help
  1287. + Intel Precise Touch & Stylus support
  1288. + Supported SoCs:
  1289. + Intel Skylake
  1290. + Intel Kabylake
  1291. +
  1292. +source "drivers/misc/ipts/companion/Kconfig"
  1293. diff --git a/drivers/misc/ipts/Makefile b/drivers/misc/ipts/Makefile
  1294. new file mode 100644
  1295. index 000000000000..bb3982f48afc
  1296. --- /dev/null
  1297. +++ b/drivers/misc/ipts/Makefile
  1298. @@ -0,0 +1,19 @@
  1299. +# SPDX-License-Identifier: GPL-2.0-or-later
  1300. +#
  1301. +# Makefile - Intel Precise Touch & Stylus device driver
  1302. +# Copyright (c) 2016 Intel Corporation
  1303. +#
  1304. +
  1305. +obj-$(CONFIG_INTEL_IPTS)+= intel-ipts.o
  1306. +intel-ipts-objs += companion.o
  1307. +intel-ipts-objs += ipts.o
  1308. +intel-ipts-objs += mei.o
  1309. +intel-ipts-objs += hid.o
  1310. +intel-ipts-objs += msg-handler.o
  1311. +intel-ipts-objs += kernel.o
  1312. +intel-ipts-objs += params.o
  1313. +intel-ipts-objs += resource.o
  1314. +intel-ipts-objs += gfx.o
  1315. +intel-ipts-$(CONFIG_DEBUG_FS) += dbgfs.o
  1316. +
  1317. +obj-y += companion/
  1318. diff --git a/drivers/misc/ipts/companion.c b/drivers/misc/ipts/companion.c
  1319. new file mode 100644
  1320. index 000000000000..8f66b852f137
  1321. --- /dev/null
  1322. +++ b/drivers/misc/ipts/companion.c
  1323. @@ -0,0 +1,211 @@
  1324. +// SPDX-License-Identifier: GPL-2.0-or-later
  1325. +/*
  1326. + *
  1327. + * Intel Precise Touch & Stylus
  1328. + * Copyright (c) 2016 Intel Corporation
  1329. + *
  1330. + */
  1331. +
  1332. +#include <linux/firmware.h>
  1333. +#include <linux/ipts.h>
  1334. +#include <linux/ipts-binary.h>
  1335. +#include <linux/ipts-companion.h>
  1336. +#include <linux/mutex.h>
  1337. +
  1338. +#include "companion.h"
  1339. +#include "ipts.h"
  1340. +#include "params.h"
  1341. +
  1342. +#define IPTS_FW_PATH_FMT "intel/ipts/%s"
  1343. +#define IPTS_FW_CONFIG_FILE "ipts_fw_config.bin"
  1344. +
  1345. +struct ipts_companion *ipts_companion;
  1346. +DEFINE_MUTEX(ipts_companion_lock);
  1347. +
  1348. +bool ipts_companion_available(void)
  1349. +{
  1350. + bool ret;
  1351. +
  1352. + mutex_lock(&ipts_companion_lock);
  1353. +
  1354. + ret = ipts_companion != NULL;
  1355. +
  1356. + mutex_unlock(&ipts_companion_lock);
  1357. +
  1358. + return ret;
  1359. +}
  1360. +
  1361. +/*
  1362. + * General purpose API for adding or removing a companion driver
  1363. + * A companion driver is a driver that implements hardware specific
  1364. + * behaviour into IPTS, so it doesn't have to be hardcoded into the
  1365. + * main driver. All requests to the companion driver should be wrapped,
  1366. + * with a fallback in case a companion driver cannot be found.
  1367. + */
  1368. +
  1369. +int ipts_add_companion(struct ipts_companion *companion)
  1370. +{
  1371. + int ret;
  1372. +
  1373. + // Make sure that access to the companion is synchronized
  1374. + mutex_lock(&ipts_companion_lock);
  1375. +
  1376. + if (ipts_companion == NULL) {
  1377. + ret = 0;
  1378. + ipts_companion = companion;
  1379. + } else {
  1380. + ret = -EBUSY;
  1381. + }
  1382. +
  1383. + mutex_unlock(&ipts_companion_lock);
  1384. +
  1385. + return ret;
  1386. +}
  1387. +EXPORT_SYMBOL_GPL(ipts_add_companion);
  1388. +
  1389. +int ipts_remove_companion(struct ipts_companion *companion)
  1390. +{
  1391. + int ret;
  1392. +
  1393. + // Make sure that access to the companion is synchronized
  1394. + mutex_lock(&ipts_companion_lock);
  1395. +
  1396. + if (ipts_companion != NULL && companion != NULL &&
  1397. + ipts_companion->name != companion->name) {
  1398. + ret = -EPERM;
  1399. + } else {
  1400. + ret = 0;
  1401. + ipts_companion = NULL;
  1402. + }
  1403. +
  1404. + mutex_unlock(&ipts_companion_lock);
  1405. + return ret;
  1406. +}
  1407. +EXPORT_SYMBOL_GPL(ipts_remove_companion);
  1408. +
  1409. +/*
  1410. + * Utility functions for IPTS. These functions replace codepaths in the IPTS
  1411. + * driver, and redirect them to the companion driver, if one was found.
  1412. + * Otherwise the legacy code gets executed as a fallback.
  1413. + */
  1414. +
  1415. +int ipts_request_firmware(const struct firmware **fw, const char *name,
  1416. + struct device *device)
  1417. +{
  1418. + int ret = 0;
  1419. + char fw_path[MAX_IOCL_FILE_PATH_LEN];
  1420. +
  1421. + // Make sure that access to the companion is synchronized
  1422. + mutex_lock(&ipts_companion_lock);
  1423. +
  1424. + // Check if a companion was registered. If not, skip
  1425. + // forward and try to load the firmware from the legacy path
  1426. + if (ipts_companion == NULL || ipts_modparams.ignore_companion)
  1427. + goto request_firmware_fallback;
  1428. +
  1429. + ret = ipts_companion->firmware_request(ipts_companion, fw,
  1430. + name, device);
  1431. + if (!ret)
  1432. + goto request_firmware_return;
  1433. +
  1434. +request_firmware_fallback:
  1435. +
  1436. + // If fallback loading for firmware was disabled, abort.
  1437. + // Return -ENOENT as no firmware file was found.
  1438. + if (ipts_modparams.ignore_fw_fallback) {
  1439. + ret = -ENOENT;
  1440. + goto request_firmware_return;
  1441. + }
  1442. +
  1443. + // No firmware was found by the companion driver, try the generic path.
  1444. + snprintf(fw_path, MAX_IOCL_FILE_PATH_LEN, IPTS_FW_PATH_FMT, name);
  1445. + ret = request_firmware(fw, fw_path, device);
  1446. +
  1447. +request_firmware_return:
  1448. +
  1449. + mutex_unlock(&ipts_companion_lock);
  1450. +
  1451. + return ret;
  1452. +}
  1453. +
  1454. +static struct ipts_bin_fw_list *ipts_alloc_fw_list(
  1455. + struct ipts_bin_fw_info **fw)
  1456. +{
  1457. + int size, len, i, j;
  1458. + struct ipts_bin_fw_list *fw_list;
  1459. + char *itr;
  1460. +
  1461. + // Figure out the amount of firmware files inside of the array
  1462. + len = 0;
  1463. + while (fw[len] != NULL)
  1464. + len++;
  1465. +
  1466. + // Determine the size that the final list will need in memory
  1467. + size = sizeof(struct ipts_bin_fw_list);
  1468. + for (i = 0; i < len; i++) {
  1469. + size += sizeof(struct ipts_bin_fw_info);
  1470. + size += sizeof(struct ipts_bin_data_file_info) *
  1471. + fw[i]->num_of_data_files;
  1472. + }
  1473. +
  1474. + fw_list = kmalloc(size, GFP_KERNEL);
  1475. + fw_list->num_of_fws = len;
  1476. +
  1477. + itr = (char *)fw_list->fw_info;
  1478. + for (i = 0; i < len; i++) {
  1479. + *(struct ipts_bin_fw_info *)itr = *fw[i];
  1480. +
  1481. + itr += sizeof(struct ipts_bin_fw_info);
  1482. +
  1483. + for (j = 0; j < fw[i]->num_of_data_files; j++) {
  1484. + *(struct ipts_bin_data_file_info *)itr =
  1485. + fw[i]->data_file[j];
  1486. +
  1487. + itr += sizeof(struct ipts_bin_data_file_info);
  1488. + }
  1489. + }
  1490. +
  1491. + return fw_list;
  1492. +}
  1493. +
  1494. +int ipts_request_firmware_config(struct ipts_info *ipts,
  1495. + struct ipts_bin_fw_list **cfg)
  1496. +{
  1497. + int ret;
  1498. + const struct firmware *config_fw = NULL;
  1499. +
  1500. + // Make sure that access to the companion is synchronized
  1501. + mutex_lock(&ipts_companion_lock);
  1502. +
  1503. + // Check if a companion was registered. If not, skip
  1504. + // forward and try to load the firmware config from a file
  1505. + if (ipts_modparams.ignore_companion || ipts_companion == NULL) {
  1506. + mutex_unlock(&ipts_companion_lock);
  1507. + goto config_fallback;
  1508. + }
  1509. +
  1510. + if (ipts_companion->firmware_config != NULL) {
  1511. + *cfg = ipts_alloc_fw_list(ipts_companion->firmware_config);
  1512. + mutex_unlock(&ipts_companion_lock);
  1513. + return 0;
  1514. + }
  1515. +
  1516. +config_fallback:
  1517. +
  1518. + // If fallback loading for the firmware config was disabled, abort.
  1519. + // Return -ENOENT as no config file was found.
  1520. + if (ipts_modparams.ignore_config_fallback)
  1521. + return -ENOENT;
  1522. +
  1523. + // No firmware config was found by the companion driver,
  1524. + // try loading it from a file now
  1525. + ret = ipts_request_firmware(&config_fw, IPTS_FW_CONFIG_FILE,
  1526. + &ipts->cldev->dev);
  1527. + if (!ret)
  1528. + *cfg = (struct ipts_bin_fw_list *)config_fw->data;
  1529. + else
  1530. + release_firmware(config_fw);
  1531. +
  1532. + return ret;
  1533. +
  1534. +}
  1535. diff --git a/drivers/misc/ipts/companion.h b/drivers/misc/ipts/companion.h
  1536. new file mode 100644
  1537. index 000000000000..7a1e4b388c40
  1538. --- /dev/null
  1539. +++ b/drivers/misc/ipts/companion.h
  1540. @@ -0,0 +1,25 @@
  1541. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  1542. +/*
  1543. + *
  1544. + * Intel Precise Touch & Stylus
  1545. + * Copyright (c) 2016 Intel Corporation
  1546. + *
  1547. + */
  1548. +
  1549. +#ifndef _IPTS_COMPANION_H_
  1550. +#define _IPTS_COMPANION_H_
  1551. +
  1552. +#include <linux/firmware.h>
  1553. +#include <linux/ipts-binary.h>
  1554. +
  1555. +#include "ipts.h"
  1556. +
  1557. +bool ipts_companion_available(void);
  1558. +
  1559. +int ipts_request_firmware(const struct firmware **fw, const char *name,
  1560. + struct device *device);
  1561. +
  1562. +int ipts_request_firmware_config(struct ipts_info *ipts,
  1563. + struct ipts_bin_fw_list **firmware_config);
  1564. +
  1565. +#endif // _IPTS_COMPANION_H_
  1566. diff --git a/drivers/misc/ipts/companion/Kconfig b/drivers/misc/ipts/companion/Kconfig
  1567. new file mode 100644
  1568. index 000000000000..ef17d9bb5242
  1569. --- /dev/null
  1570. +++ b/drivers/misc/ipts/companion/Kconfig
  1571. @@ -0,0 +1,8 @@
  1572. +# SPDX-License-Identifier: GPL-2.0-or-later
  1573. +config INTEL_IPTS_SURFACE
  1574. + tristate "IPTS companion driver for Microsoft Surface"
  1575. + depends on INTEL_IPTS && ACPI
  1576. + help
  1577. + IPTS companion driver for Microsoft Surface. This driver is
  1578. + responsible for loading firmware using surface-specific hardware IDs.
  1579. + If you have a Microsoft Surface using IPTS, select y or m here.
  1580. diff --git a/drivers/misc/ipts/companion/Makefile b/drivers/misc/ipts/companion/Makefile
  1581. new file mode 100644
  1582. index 000000000000..b37f2f59937a
  1583. --- /dev/null
  1584. +++ b/drivers/misc/ipts/companion/Makefile
  1585. @@ -0,0 +1,2 @@
  1586. +# SPDX-License-Identifier: GPL-2.0-or-later
  1587. +obj-$(CONFIG_INTEL_IPTS_SURFACE)+= ipts-surface.o
  1588. diff --git a/drivers/misc/ipts/companion/ipts-surface.c b/drivers/misc/ipts/companion/ipts-surface.c
  1589. new file mode 100644
  1590. index 000000000000..a717dfcdfeba
  1591. --- /dev/null
  1592. +++ b/drivers/misc/ipts/companion/ipts-surface.c
  1593. @@ -0,0 +1,157 @@
  1594. +// SPDX-License-Identifier: GPL-2.0-or-later
  1595. +/*
  1596. + *
  1597. + * Intel Precise Touch & Stylus
  1598. + * Copyright (c) 2016 Intel Corporation
  1599. + * Copyright (c) 2019 Dorian Stoll
  1600. + *
  1601. + */
  1602. +
  1603. +#include <linux/acpi.h>
  1604. +#include <linux/firmware.h>
  1605. +#include <linux/ipts.h>
  1606. +#include <linux/ipts-companion.h>
  1607. +#include <linux/module.h>
  1608. +#include <linux/platform_device.h>
  1609. +
  1610. +#define IPTS_SURFACE_FW_PATH_FMT "intel/ipts/%s/%s"
  1611. +
  1612. +/*
  1613. + * checkpatch complains about this and wants it wrapped with do { } while(0);
  1614. + * Since this would absolutely not work, just ignore checkpatch in this case.
  1615. + */
  1616. +#define IPTS_SURFACE_FIRMWARE(X) \
  1617. + MODULE_FIRMWARE("intel/ipts/" X "/config.bin"); \
  1618. + MODULE_FIRMWARE("intel/ipts/" X "/intel_desc.bin"); \
  1619. + MODULE_FIRMWARE("intel/ipts/" X "/vendor_desc.bin"); \
  1620. + MODULE_FIRMWARE("intel/ipts/" X "/vendor_kernel.bin")
  1621. +
  1622. +/*
  1623. + * Checkpatch complains about the following lines because it sees them as
  1624. + * header files mixed with .c files. However, forward declaration is perfectly
  1625. + * fine in C, and this allows us to seperate the companion data from the
  1626. + * functions for the companion.
  1627. + */
  1628. +int ipts_surface_request_firmware(struct ipts_companion *companion,
  1629. + const struct firmware **fw, const char *name,
  1630. + struct device *device);
  1631. +
  1632. +unsigned int ipts_surface_get_quirks(struct ipts_companion *companion);
  1633. +
  1634. +static struct ipts_bin_fw_info ipts_surface_vendor_kernel = {
  1635. + .fw_name = "vendor_kernel.bin",
  1636. + .vendor_output = -1,
  1637. + .num_of_data_files = 3,
  1638. + .data_file = {
  1639. + {
  1640. + .io_buffer_type = IPTS_CONFIGURATION,
  1641. + .flags = IPTS_DATA_FILE_FLAG_NONE,
  1642. + .file_name = "config.bin",
  1643. + },
  1644. +
  1645. + // The following files are part of the config, but they don't
  1646. + // exist, and the driver never requests them.
  1647. + {
  1648. + .io_buffer_type = IPTS_CALIBRATION,
  1649. + .flags = IPTS_DATA_FILE_FLAG_NONE,
  1650. + .file_name = "calib.bin",
  1651. + },
  1652. + {
  1653. + .io_buffer_type = IPTS_FEATURE,
  1654. + .flags = IPTS_DATA_FILE_FLAG_SHARE,
  1655. + .file_name = "feature.bin",
  1656. + },
  1657. + },
  1658. +};
  1659. +
  1660. +static struct ipts_bin_fw_info *ipts_surface_fw_config[] = {
  1661. + &ipts_surface_vendor_kernel,
  1662. + NULL,
  1663. +};
  1664. +
  1665. +static struct ipts_companion ipts_surface_companion = {
  1666. + .firmware_request = &ipts_surface_request_firmware,
  1667. + .firmware_config = ipts_surface_fw_config,
  1668. + .name = "ipts_surface",
  1669. +};
  1670. +
  1671. +int ipts_surface_request_firmware(struct ipts_companion *companion,
  1672. + const struct firmware **fw, const char *name,
  1673. + struct device *device)
  1674. +{
  1675. + char fw_path[MAX_IOCL_FILE_PATH_LEN];
  1676. +
  1677. + if (companion == NULL || companion->data == NULL)
  1678. + return -ENOENT;
  1679. +
  1680. + snprintf(fw_path, MAX_IOCL_FILE_PATH_LEN, IPTS_SURFACE_FW_PATH_FMT,
  1681. + (const char *)companion->data, name);
  1682. + return request_firmware(fw, fw_path, device);
  1683. +}
  1684. +
  1685. +static int ipts_surface_probe(struct platform_device *pdev)
  1686. +{
  1687. + int r;
  1688. + struct acpi_device *adev = ACPI_COMPANION(&pdev->dev);
  1689. +
  1690. + if (!adev) {
  1691. + dev_err(&pdev->dev, "Unable to find ACPI info for device\n");
  1692. + return -ENODEV;
  1693. + }
  1694. +
  1695. + ipts_surface_companion.data = (void *)acpi_device_hid(adev);
  1696. +
  1697. + r = ipts_add_companion(&ipts_surface_companion);
  1698. + if (r) {
  1699. + dev_warn(&pdev->dev, "Adding IPTS companion failed: %d\n", r);
  1700. + return r;
  1701. + }
  1702. +
  1703. + return 0;
  1704. +}
  1705. +
  1706. +static int ipts_surface_remove(struct platform_device *pdev)
  1707. +{
  1708. + int r = ipts_remove_companion(&ipts_surface_companion);
  1709. +
  1710. + if (r) {
  1711. + dev_warn(&pdev->dev, "Removing IPTS companion failed: %d\n", r);
  1712. + return r;
  1713. + }
  1714. +
  1715. + return 0;
  1716. +}
  1717. +
  1718. +static const struct acpi_device_id ipts_surface_acpi_match[] = {
  1719. + { "MSHW0076", 0 }, // Surface Book 1 / Surface Studio
  1720. + { "MSHW0078", 0 }, // some Surface Pro 4
  1721. + { "MSHW0079", 0 }, // Surface Laptop 1 / 2
  1722. + { "MSHW0101", 0 }, // Surface Book 2 15"
  1723. + { "MSHW0102", 0 }, // Surface Pro 5 / 6
  1724. + { "MSHW0103", 0 }, // some Surface Pro 4
  1725. + { "MSHW0137", 0 }, // Surface Book 2
  1726. + { },
  1727. +};
  1728. +MODULE_DEVICE_TABLE(acpi, ipts_surface_acpi_match);
  1729. +
  1730. +static struct platform_driver ipts_surface_driver = {
  1731. + .probe = ipts_surface_probe,
  1732. + .remove = ipts_surface_remove,
  1733. + .driver = {
  1734. + .name = "ipts_surface",
  1735. + .acpi_match_table = ACPI_PTR(ipts_surface_acpi_match),
  1736. + },
  1737. +};
  1738. +module_platform_driver(ipts_surface_driver);
  1739. +
  1740. +MODULE_AUTHOR("Dorian Stoll <dorian.stoll@tmsp.io>");
  1741. +MODULE_DESCRIPTION("IPTS companion driver for Microsoft Surface");
  1742. +MODULE_LICENSE("GPL v2");
  1743. +
  1744. +IPTS_SURFACE_FIRMWARE("MSHW0076");
  1745. +IPTS_SURFACE_FIRMWARE("MSHW0078");
  1746. +IPTS_SURFACE_FIRMWARE("MSHW0079");
  1747. +IPTS_SURFACE_FIRMWARE("MSHW0101");
  1748. +IPTS_SURFACE_FIRMWARE("MSHW0102");
  1749. +IPTS_SURFACE_FIRMWARE("MSHW0103");
  1750. +IPTS_SURFACE_FIRMWARE("MSHW0137");
  1751. diff --git a/drivers/misc/ipts/dbgfs.c b/drivers/misc/ipts/dbgfs.c
  1752. new file mode 100644
  1753. index 000000000000..fd9388de17e7
  1754. --- /dev/null
  1755. +++ b/drivers/misc/ipts/dbgfs.c
  1756. @@ -0,0 +1,277 @@
  1757. +// SPDX-License-Identifier: GPL-2.0-or-later
  1758. +/*
  1759. + *
  1760. + * Intel Precise Touch & Stylus
  1761. + * Copyright (c) 2016 Intel Corporation
  1762. + *
  1763. + */
  1764. +
  1765. +#include <linux/ctype.h>
  1766. +#include <linux/debugfs.h>
  1767. +#include <linux/uaccess.h>
  1768. +
  1769. +#include "ipts.h"
  1770. +#include "msg-handler.h"
  1771. +#include "sensor-regs.h"
  1772. +#include "state.h"
  1773. +#include "../mei/mei_dev.h"
  1774. +
  1775. +static const char ipts_status_fmt[] = "ipts state : %01d\n";
  1776. +static const char ipts_debug_fmt[] = ">> tdt : fw status : %s\n"
  1777. + ">> == Doorbell status:%x, count:%x ==\n"
  1778. + ">> == Workqueue head:%u, tail:%u ==\n";
  1779. +
  1780. +static ssize_t ipts_dbgfs_status_read(struct file *fp, char __user *ubuf,
  1781. + size_t cnt, loff_t *ppos)
  1782. +{
  1783. + struct ipts_info *ipts = fp->private_data;
  1784. + char status[256];
  1785. + int len = 0;
  1786. +
  1787. + if (cnt < sizeof(ipts_status_fmt) - 3)
  1788. + return -EINVAL;
  1789. +
  1790. + len = scnprintf(status, 256, ipts_status_fmt, ipts->state);
  1791. + if (len < 0)
  1792. + return -EIO;
  1793. +
  1794. + return simple_read_from_buffer(ubuf, cnt, ppos, status, len);
  1795. +}
  1796. +
  1797. +static const struct file_operations ipts_status_dbgfs_fops = {
  1798. + .open = simple_open,
  1799. + .read = ipts_dbgfs_status_read,
  1800. + .llseek = generic_file_llseek,
  1801. +};
  1802. +
  1803. +static ssize_t ipts_dbgfs_quiesce_io_cmd_write(struct file *fp,
  1804. + const char __user *ubuf, size_t cnt, loff_t *ppos)
  1805. +{
  1806. + struct ipts_info *ipts = fp->private_data;
  1807. + bool result;
  1808. + int rc;
  1809. +
  1810. + rc = kstrtobool_from_user(ubuf, cnt, &result);
  1811. + if (rc)
  1812. + return rc;
  1813. +
  1814. + if (!result)
  1815. + return -EINVAL;
  1816. +
  1817. + ipts_send_sensor_quiesce_io_cmd(ipts);
  1818. + return cnt;
  1819. +}
  1820. +
  1821. +static const struct file_operations ipts_quiesce_io_cmd_dbgfs_fops = {
  1822. + .open = simple_open,
  1823. + .write = ipts_dbgfs_quiesce_io_cmd_write,
  1824. + .llseek = generic_file_llseek,
  1825. +};
  1826. +
  1827. +static ssize_t ipts_dbgfs_clear_mem_window_cmd_write(struct file *fp,
  1828. + const char __user *ubuf, size_t cnt, loff_t *ppos)
  1829. +{
  1830. + struct ipts_info *ipts = fp->private_data;
  1831. + bool result;
  1832. + int rc;
  1833. +
  1834. + rc = kstrtobool_from_user(ubuf, cnt, &result);
  1835. + if (rc)
  1836. + return rc;
  1837. +
  1838. + if (!result)
  1839. + return -EINVAL;
  1840. +
  1841. + ipts_send_sensor_clear_mem_window_cmd(ipts);
  1842. +
  1843. + return cnt;
  1844. +}
  1845. +
  1846. +static const struct file_operations ipts_clear_mem_window_cmd_dbgfs_fops = {
  1847. + .open = simple_open,
  1848. + .write = ipts_dbgfs_clear_mem_window_cmd_write,
  1849. + .llseek = generic_file_llseek,
  1850. +};
  1851. +
  1852. +static ssize_t ipts_dbgfs_debug_read(struct file *fp, char __user *ubuf,
  1853. + size_t cnt, loff_t *ppos)
  1854. +{
  1855. + struct ipts_info *ipts = fp->private_data;
  1856. + char dbg_info[1024];
  1857. + int len = 0;
  1858. +
  1859. + char fw_sts_str[MEI_FW_STATUS_STR_SZ];
  1860. + u32 *db, *head, *tail;
  1861. + struct ipts_wq_info *wq_info;
  1862. +
  1863. + wq_info = &ipts->resource.wq_info;
  1864. + mei_fw_status_str(ipts->cldev->bus, fw_sts_str, MEI_FW_STATUS_STR_SZ);
  1865. +
  1866. + db = (u32 *)wq_info->db_addr;
  1867. + head = (u32 *)wq_info->wq_head_addr;
  1868. + tail = (u32 *)wq_info->wq_tail_addr;
  1869. +
  1870. + if (cnt < sizeof(ipts_debug_fmt) - 3)
  1871. + return -EINVAL;
  1872. +
  1873. + len = scnprintf(dbg_info, 1024, ipts_debug_fmt,
  1874. + fw_sts_str, *db, *(db+1), *head, *tail);
  1875. +
  1876. + if (len < 0)
  1877. + return -EIO;
  1878. +
  1879. + return simple_read_from_buffer(ubuf, cnt, ppos, dbg_info, len);
  1880. +}
  1881. +
  1882. +static const struct file_operations ipts_debug_dbgfs_fops = {
  1883. + .open = simple_open,
  1884. + .read = ipts_dbgfs_debug_read,
  1885. + .llseek = generic_file_llseek,
  1886. +};
  1887. +
  1888. +static ssize_t ipts_dbgfs_ipts_restart_write(struct file *fp,
  1889. + const char __user *ubuf, size_t cnt, loff_t *ppos)
  1890. +{
  1891. + struct ipts_info *ipts = fp->private_data;
  1892. + bool result;
  1893. + int rc;
  1894. +
  1895. + rc = kstrtobool_from_user(ubuf, cnt, &result);
  1896. + if (rc)
  1897. + return rc;
  1898. + if (!result)
  1899. + return -EINVAL;
  1900. +
  1901. + ipts_restart(ipts);
  1902. + return cnt;
  1903. +}
  1904. +
  1905. +static const struct file_operations ipts_ipts_restart_dbgfs_fops = {
  1906. + .open = simple_open,
  1907. + .write = ipts_dbgfs_ipts_restart_write,
  1908. + .llseek = generic_file_llseek,
  1909. +};
  1910. +
  1911. +static ssize_t ipts_dbgfs_ipts_stop_write(struct file *fp,
  1912. + const char __user *ubuf, size_t cnt, loff_t *ppos)
  1913. +{
  1914. + struct ipts_info *ipts = fp->private_data;
  1915. + bool result;
  1916. + int rc;
  1917. +
  1918. + rc = kstrtobool_from_user(ubuf, cnt, &result);
  1919. + if (rc)
  1920. + return rc;
  1921. +
  1922. + if (!result)
  1923. + return -EINVAL;
  1924. +
  1925. + ipts_stop(ipts);
  1926. + return cnt;
  1927. +}
  1928. +
  1929. +static const struct file_operations ipts_ipts_stop_dbgfs_fops = {
  1930. + .open = simple_open,
  1931. + .write = ipts_dbgfs_ipts_stop_write,
  1932. + .llseek = generic_file_llseek,
  1933. +};
  1934. +
  1935. +static ssize_t ipts_dbgfs_ipts_start_write(struct file *fp,
  1936. + const char __user *ubuf, size_t cnt, loff_t *ppos)
  1937. +{
  1938. + struct ipts_info *ipts = fp->private_data;
  1939. + bool result;
  1940. + int rc;
  1941. +
  1942. + rc = kstrtobool_from_user(ubuf, cnt, &result);
  1943. + if (rc)
  1944. + return rc;
  1945. +
  1946. + if (!result)
  1947. + return -EINVAL;
  1948. +
  1949. + ipts_start(ipts);
  1950. + return cnt;
  1951. +}
  1952. +
  1953. +static const struct file_operations ipts_ipts_start_dbgfs_fops = {
  1954. + .open = simple_open,
  1955. + .write = ipts_dbgfs_ipts_start_write,
  1956. + .llseek = generic_file_llseek,
  1957. +};
  1958. +
  1959. +void ipts_dbgfs_deregister(struct ipts_info *ipts)
  1960. +{
  1961. + if (!ipts->dbgfs_dir)
  1962. + return;
  1963. +
  1964. + debugfs_remove_recursive(ipts->dbgfs_dir);
  1965. + ipts->dbgfs_dir = NULL;
  1966. +}
  1967. +
  1968. +int ipts_dbgfs_register(struct ipts_info *ipts, const char *name)
  1969. +{
  1970. + struct dentry *dir, *f;
  1971. +
  1972. + dir = debugfs_create_dir(name, NULL);
  1973. + if (!dir)
  1974. + return -ENOMEM;
  1975. +
  1976. + f = debugfs_create_file("status", 0200, dir, ipts,
  1977. + &ipts_status_dbgfs_fops);
  1978. + if (!f) {
  1979. + ipts_err(ipts, "debugfs status creation failed\n");
  1980. + goto err;
  1981. + }
  1982. +
  1983. + f = debugfs_create_file("quiesce_io_cmd", 0200, dir, ipts,
  1984. + &ipts_quiesce_io_cmd_dbgfs_fops);
  1985. + if (!f) {
  1986. + ipts_err(ipts, "debugfs quiesce_io_cmd creation failed\n");
  1987. + goto err;
  1988. + }
  1989. +
  1990. + f = debugfs_create_file("clear_mem_window_cmd", 0200, dir, ipts,
  1991. + &ipts_clear_mem_window_cmd_dbgfs_fops);
  1992. + if (!f) {
  1993. + ipts_err(ipts, "debugfs clear_mem_window_cmd creation failed\n");
  1994. + goto err;
  1995. + }
  1996. +
  1997. + f = debugfs_create_file("debug", 0200, dir, ipts,
  1998. + &ipts_debug_dbgfs_fops);
  1999. + if (!f) {
  2000. + ipts_err(ipts, "debugfs debug creation failed\n");
  2001. + goto err;
  2002. + }
  2003. +
  2004. + f = debugfs_create_file("ipts_restart", 0200, dir, ipts,
  2005. + &ipts_ipts_restart_dbgfs_fops);
  2006. + if (!f) {
  2007. + ipts_err(ipts, "debugfs ipts_restart creation failed\n");
  2008. + goto err;
  2009. + }
  2010. +
  2011. + f = debugfs_create_file("ipts_stop", 0200, dir, ipts,
  2012. + &ipts_ipts_stop_dbgfs_fops);
  2013. + if (!f) {
  2014. + ipts_err(ipts, "debugfs ipts_stop creation failed\n");
  2015. + goto err;
  2016. + }
  2017. +
  2018. + f = debugfs_create_file("ipts_start", 0200, dir, ipts,
  2019. + &ipts_ipts_start_dbgfs_fops);
  2020. + if (!f) {
  2021. + ipts_err(ipts, "debugfs ipts_start creation failed\n");
  2022. + goto err;
  2023. + }
  2024. +
  2025. + ipts->dbgfs_dir = dir;
  2026. +
  2027. + return 0;
  2028. +
  2029. +err:
  2030. + ipts_dbgfs_deregister(ipts);
  2031. +
  2032. + return -ENODEV;
  2033. +}
  2034. diff --git a/drivers/misc/ipts/gfx.c b/drivers/misc/ipts/gfx.c
  2035. new file mode 100644
  2036. index 000000000000..b8900f514c75
  2037. --- /dev/null
  2038. +++ b/drivers/misc/ipts/gfx.c
  2039. @@ -0,0 +1,180 @@
  2040. +// SPDX-License-Identifier: GPL-2.0-or-later
  2041. +/*
  2042. + *
  2043. + * Intel Precise Touch & Stylus
  2044. + * Copyright (c) 2016 Intel Corporation
  2045. + *
  2046. + */
  2047. +
  2048. +#include <linux/delay.h>
  2049. +#include <linux/kthread.h>
  2050. +
  2051. +#include "ipts.h"
  2052. +#include "msg-handler.h"
  2053. +#include "params.h"
  2054. +#include "state.h"
  2055. +#include "../mei/mei_dev.h"
  2056. +
  2057. +static void gfx_processing_complete(void *data)
  2058. +{
  2059. + struct ipts_info *ipts = data;
  2060. +
  2061. + if (ipts_get_state(ipts) == IPTS_STA_RAW_DATA_STARTED) {
  2062. + schedule_work(&ipts->raw_data_work);
  2063. + return;
  2064. + }
  2065. +
  2066. + ipts_dbg(ipts, "not ready to handle gfx event\n");
  2067. +}
  2068. +
  2069. +static void notify_gfx_status(u32 status, void *data)
  2070. +{
  2071. + struct ipts_info *ipts = data;
  2072. +
  2073. + ipts->gfx_status = status;
  2074. + schedule_work(&ipts->gfx_status_work);
  2075. +}
  2076. +
  2077. +static int connect_gfx(struct ipts_info *ipts)
  2078. +{
  2079. + int ret = 0;
  2080. + struct ipts_connect connect;
  2081. +
  2082. + connect.client = ipts->cldev->dev.parent;
  2083. + connect.if_version = IPTS_INTERFACE_V1;
  2084. + connect.ipts_cb.workload_complete = gfx_processing_complete;
  2085. + connect.ipts_cb.notify_gfx_status = notify_gfx_status;
  2086. + connect.data = (void *)ipts;
  2087. +
  2088. + ret = ipts_connect(&connect);
  2089. + if (ret)
  2090. + return ret;
  2091. +
  2092. + // TODO: GFX version check
  2093. + ipts->gfx_info.gfx_handle = connect.gfx_handle;
  2094. + ipts->gfx_info.ipts_ops = connect.ipts_ops;
  2095. +
  2096. + return ret;
  2097. +}
  2098. +
  2099. +static void disconnect_gfx(struct ipts_info *ipts)
  2100. +{
  2101. + ipts_disconnect(ipts->gfx_info.gfx_handle);
  2102. +}
  2103. +
  2104. +static struct task_struct *dbg_thread;
  2105. +
  2106. +static void ipts_print_dbg_info(struct ipts_info *ipts)
  2107. +{
  2108. + char fw_sts_str[MEI_FW_STATUS_STR_SZ];
  2109. + u32 *db, *head, *tail;
  2110. + struct ipts_wq_info *wq_info;
  2111. +
  2112. + wq_info = &ipts->resource.wq_info;
  2113. +
  2114. + mei_fw_status_str(ipts->cldev->bus, fw_sts_str, MEI_FW_STATUS_STR_SZ);
  2115. + pr_info(">> tdt : fw status : %s\n", fw_sts_str);
  2116. +
  2117. + db = (u32 *)wq_info->db_addr;
  2118. + head = (u32 *)wq_info->wq_head_addr;
  2119. + tail = (u32 *)wq_info->wq_tail_addr;
  2120. +
  2121. + // Every time the ME has filled up the touch input buffer, and the GuC
  2122. + // doorbell is rang, the doorbell count will increase by one
  2123. + // The workqueue is the queue of touch events that the GuC has to
  2124. + // process. Head is the currently processed event, while tail is
  2125. + // the last one that is currently available. If head and tail are
  2126. + // not equal, this can be an indicator for GuC / GPU hang.
  2127. + pr_info(">> == Doorbell status:%x, count:%x ==\n", *db, *(db+1));
  2128. + pr_info(">> == Workqueue head:%u, tail:%u ==\n", *head, *tail);
  2129. +}
  2130. +
  2131. +static int ipts_dbg_thread(void *data)
  2132. +{
  2133. + struct ipts_info *ipts = (struct ipts_info *)data;
  2134. +
  2135. + pr_info(">> start debug thread\n");
  2136. +
  2137. + while (!kthread_should_stop()) {
  2138. + if (ipts_get_state(ipts) != IPTS_STA_RAW_DATA_STARTED) {
  2139. + pr_info("state is not IPTS_STA_RAW_DATA_STARTED : %d\n",
  2140. + ipts_get_state(ipts));
  2141. +
  2142. + msleep(5000);
  2143. + continue;
  2144. + }
  2145. +
  2146. + ipts_print_dbg_info(ipts);
  2147. + msleep(3000);
  2148. + }
  2149. +
  2150. + return 0;
  2151. +}
  2152. +
  2153. +int ipts_open_gpu(struct ipts_info *ipts)
  2154. +{
  2155. + int ret = 0;
  2156. +
  2157. + ret = connect_gfx(ipts);
  2158. + if (ret) {
  2159. + ipts_dbg(ipts, "cannot connect GPU\n");
  2160. + return ret;
  2161. + }
  2162. +
  2163. + ret = ipts->gfx_info.ipts_ops.get_wq_info(ipts->gfx_info.gfx_handle,
  2164. + &ipts->resource.wq_info);
  2165. + if (ret) {
  2166. + ipts_dbg(ipts, "error in get_wq_info\n");
  2167. + return ret;
  2168. + }
  2169. +
  2170. + if (ipts_modparams.debug_thread)
  2171. + dbg_thread = kthread_run(
  2172. + ipts_dbg_thread, (void *)ipts, "ipts_debug");
  2173. +
  2174. + return 0;
  2175. +}
  2176. +
  2177. +void ipts_close_gpu(struct ipts_info *ipts)
  2178. +{
  2179. + disconnect_gfx(ipts);
  2180. +
  2181. + if (ipts_modparams.debug_thread)
  2182. + kthread_stop(dbg_thread);
  2183. +}
  2184. +
  2185. +struct ipts_mapbuffer *ipts_map_buffer(struct ipts_info *ipts,
  2186. + u32 size, u32 flags)
  2187. +{
  2188. + struct ipts_mapbuffer *buf;
  2189. + u64 handle;
  2190. + int ret;
  2191. +
  2192. + buf = devm_kzalloc(&ipts->cldev->dev, sizeof(*buf), GFP_KERNEL);
  2193. + if (!buf)
  2194. + return NULL;
  2195. +
  2196. + buf->size = size;
  2197. + buf->flags = flags;
  2198. +
  2199. + handle = ipts->gfx_info.gfx_handle;
  2200. + ret = ipts->gfx_info.ipts_ops.map_buffer(handle, buf);
  2201. + if (ret) {
  2202. + devm_kfree(&ipts->cldev->dev, buf);
  2203. + return NULL;
  2204. + }
  2205. +
  2206. + return buf;
  2207. +}
  2208. +
  2209. +void ipts_unmap_buffer(struct ipts_info *ipts, struct ipts_mapbuffer *buf)
  2210. +{
  2211. + u64 handle;
  2212. +
  2213. + if (!buf)
  2214. + return;
  2215. +
  2216. + handle = ipts->gfx_info.gfx_handle;
  2217. + ipts->gfx_info.ipts_ops.unmap_buffer(handle, buf->buf_handle);
  2218. + devm_kfree(&ipts->cldev->dev, buf);
  2219. +}
  2220. diff --git a/drivers/misc/ipts/gfx.h b/drivers/misc/ipts/gfx.h
  2221. new file mode 100644
  2222. index 000000000000..2880e122e9f9
  2223. --- /dev/null
  2224. +++ b/drivers/misc/ipts/gfx.h
  2225. @@ -0,0 +1,25 @@
  2226. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  2227. +/*
  2228. + *
  2229. + * Intel Precise Touch & Stylus
  2230. + * Copyright (c) 2016 Intel Corporation
  2231. + *
  2232. + */
  2233. +
  2234. +#ifndef _IPTS_GFX_H_
  2235. +#define _IPTS_GFX_H_
  2236. +
  2237. +#include <linux/ipts-gfx.h>
  2238. +
  2239. +#include "ipts.h"
  2240. +
  2241. +int ipts_open_gpu(struct ipts_info *ipts);
  2242. +void ipts_close_gpu(struct ipts_info *ipts);
  2243. +
  2244. +struct ipts_mapbuffer *ipts_map_buffer(struct ipts_info *ipts,
  2245. + u32 size, u32 flags);
  2246. +
  2247. +void ipts_unmap_buffer(struct ipts_info *ipts,
  2248. + struct ipts_mapbuffer *buf);
  2249. +
  2250. +#endif // _IPTS_GFX_H_
  2251. diff --git a/drivers/misc/ipts/hid.c b/drivers/misc/ipts/hid.c
  2252. new file mode 100644
  2253. index 000000000000..1b7ad2a774a8
  2254. --- /dev/null
  2255. +++ b/drivers/misc/ipts/hid.c
  2256. @@ -0,0 +1,469 @@
  2257. +// SPDX-License-Identifier: GPL-2.0-or-later
  2258. +/*
  2259. + *
  2260. + * Intel Precise Touch & Stylus
  2261. + * Copyright (c) 2016 Intel Corporation
  2262. + *
  2263. + */
  2264. +
  2265. +#include <linux/dmi.h>
  2266. +#include <linux/firmware.h>
  2267. +#include <linux/hid.h>
  2268. +#include <linux/ipts.h>
  2269. +#include <linux/module.h>
  2270. +#include <linux/vmalloc.h>
  2271. +
  2272. +#include "companion.h"
  2273. +#include "hid.h"
  2274. +#include "ipts.h"
  2275. +#include "msg-handler.h"
  2276. +#include "params.h"
  2277. +#include "resource.h"
  2278. +#include "sensor-regs.h"
  2279. +
  2280. +#define HID_DESC_INTEL "intel_desc.bin"
  2281. +#define HID_DESC_VENDOR "vendor_desc.bin"
  2282. +
  2283. +enum output_buffer_payload_type {
  2284. + OUTPUT_BUFFER_PAYLOAD_ERROR = 0,
  2285. + OUTPUT_BUFFER_PAYLOAD_HID_INPUT_REPORT,
  2286. + OUTPUT_BUFFER_PAYLOAD_HID_FEATURE_REPORT,
  2287. + OUTPUT_BUFFER_PAYLOAD_KERNEL_LOAD,
  2288. + OUTPUT_BUFFER_PAYLOAD_FEEDBACK_BUFFER
  2289. +};
  2290. +
  2291. +struct kernel_output_buffer_header {
  2292. + u16 length;
  2293. + u8 payload_type;
  2294. + u8 reserved1;
  2295. + struct touch_hid_private_data hid_private_data;
  2296. + u8 reserved2[28];
  2297. + u8 data[0];
  2298. +};
  2299. +
  2300. +struct kernel_output_payload_error {
  2301. + u16 severity;
  2302. + u16 source;
  2303. + u8 code[4];
  2304. + char string[128];
  2305. +};
  2306. +
  2307. +static int ipts_hid_get_descriptor(struct ipts_info *ipts,
  2308. + u8 **desc, int *size)
  2309. +{
  2310. + u8 *buf;
  2311. + int hid_size = 0, ret = 0;
  2312. + const struct firmware *intel_desc = NULL;
  2313. + const struct firmware *vendor_desc = NULL;
  2314. +
  2315. + ret = ipts_request_firmware(&intel_desc, HID_DESC_INTEL,
  2316. + &ipts->cldev->dev);
  2317. + if (ret)
  2318. + goto no_hid;
  2319. +
  2320. + hid_size = intel_desc->size;
  2321. +
  2322. + ret = ipts_request_firmware(&vendor_desc, HID_DESC_VENDOR,
  2323. + &ipts->cldev->dev);
  2324. + if (ret)
  2325. + ipts_dbg(ipts, "error in reading HID Vendor Descriptor\n");
  2326. + else
  2327. + hid_size += vendor_desc->size;
  2328. +
  2329. + ipts_dbg(ipts, "HID descriptor size = %d\n", hid_size);
  2330. +
  2331. + buf = vmalloc(hid_size);
  2332. + if (buf == NULL) {
  2333. + ret = -ENOMEM;
  2334. + goto no_mem;
  2335. + }
  2336. +
  2337. + memcpy(buf, intel_desc->data, intel_desc->size);
  2338. + if (vendor_desc) {
  2339. + memcpy(&buf[intel_desc->size], vendor_desc->data,
  2340. + vendor_desc->size);
  2341. + release_firmware(vendor_desc);
  2342. + }
  2343. + release_firmware(intel_desc);
  2344. +
  2345. + *desc = buf;
  2346. + *size = hid_size;
  2347. +
  2348. + return 0;
  2349. +
  2350. +no_mem:
  2351. + if (vendor_desc)
  2352. + release_firmware(vendor_desc);
  2353. +
  2354. + release_firmware(intel_desc);
  2355. +
  2356. +no_hid:
  2357. + return ret;
  2358. +}
  2359. +
  2360. +static int ipts_hid_parse(struct hid_device *hid)
  2361. +{
  2362. + struct ipts_info *ipts = hid->driver_data;
  2363. + int ret = 0, size;
  2364. + u8 *buf;
  2365. +
  2366. + ipts_dbg(ipts, "%s() start\n", __func__);
  2367. +
  2368. + ret = ipts_hid_get_descriptor(ipts, &buf, &size);
  2369. + if (ret != 0) {
  2370. + ipts_dbg(ipts, "ipts_hid_get_descriptor: %d\n",
  2371. + ret);
  2372. + return -EIO;
  2373. + }
  2374. +
  2375. + ret = hid_parse_report(hid, buf, size);
  2376. + vfree(buf);
  2377. + if (ret) {
  2378. + ipts_err(ipts, "hid_parse_report error : %d\n", ret);
  2379. + return ret;
  2380. + }
  2381. +
  2382. + ipts->hid_desc_ready = true;
  2383. +
  2384. + return 0;
  2385. +}
  2386. +
  2387. +static int ipts_hid_start(struct hid_device *hid)
  2388. +{
  2389. + return 0;
  2390. +}
  2391. +
  2392. +static void ipts_hid_stop(struct hid_device *hid)
  2393. +{
  2394. +
  2395. +}
  2396. +
  2397. +static int ipts_hid_open(struct hid_device *hid)
  2398. +{
  2399. + return 0;
  2400. +}
  2401. +
  2402. +static void ipts_hid_close(struct hid_device *hid)
  2403. +{
  2404. + struct ipts_info *ipts = hid->driver_data;
  2405. +
  2406. + ipts->hid_desc_ready = false;
  2407. +}
  2408. +
  2409. +static int ipts_hid_send_hid2me_feedback(struct ipts_info *ipts,
  2410. + u32 fb_data_type, __u8 *buf, size_t count)
  2411. +{
  2412. + struct ipts_buffer_info *fb_buf;
  2413. + struct touch_feedback_hdr *feedback;
  2414. + enum ipts_state state;
  2415. + u8 *payload;
  2416. + int header_size;
  2417. +
  2418. + header_size = sizeof(struct touch_feedback_hdr);
  2419. +
  2420. + if (count > ipts->resource.hid2me_buffer_size - header_size)
  2421. + return -EINVAL;
  2422. +
  2423. + state = ipts_get_state(ipts);
  2424. + if (state != IPTS_STA_RAW_DATA_STARTED &&
  2425. + state != IPTS_STA_HID_STARTED)
  2426. + return 0;
  2427. +
  2428. + fb_buf = ipts_get_hid2me_buffer(ipts);
  2429. + feedback = (struct touch_feedback_hdr *)fb_buf->addr;
  2430. + payload = fb_buf->addr + header_size;
  2431. + memset(feedback, 0, header_size);
  2432. +
  2433. + feedback->feedback_data_type = fb_data_type;
  2434. + feedback->feedback_cmd_type = TOUCH_FEEDBACK_CMD_TYPE_NONE;
  2435. + feedback->payload_size_bytes = count;
  2436. + feedback->buffer_id = TOUCH_HID_2_ME_BUFFER_ID;
  2437. + feedback->protocol_ver = 0;
  2438. + feedback->reserved[0] = 0xAC;
  2439. +
  2440. + // copy payload
  2441. + memcpy(payload, buf, count);
  2442. +
  2443. + ipts_send_feedback(ipts, TOUCH_HID_2_ME_BUFFER_ID, 0);
  2444. +
  2445. + return 0;
  2446. +}
  2447. +
  2448. +static int ipts_hid_raw_request(struct hid_device *hid,
  2449. + unsigned char report_number, __u8 *buf, size_t count,
  2450. + unsigned char report_type, int reqtype)
  2451. +{
  2452. + struct ipts_info *ipts = hid->driver_data;
  2453. + u32 fb_data_type;
  2454. +
  2455. + ipts_dbg(ipts, "hid raw request => report %d, request %d\n",
  2456. + (int)report_type, reqtype);
  2457. +
  2458. + if (report_type != HID_FEATURE_REPORT)
  2459. + return 0;
  2460. +
  2461. + switch (reqtype) {
  2462. + case HID_REQ_GET_REPORT:
  2463. + fb_data_type = TOUCH_FEEDBACK_DATA_TYPE_GET_FEATURES;
  2464. + break;
  2465. + case HID_REQ_SET_REPORT:
  2466. + fb_data_type = TOUCH_FEEDBACK_DATA_TYPE_SET_FEATURES;
  2467. + break;
  2468. + default:
  2469. + ipts_err(ipts, "raw request not supprted: %d\n", reqtype);
  2470. + return -EIO;
  2471. + }
  2472. +
  2473. + return ipts_hid_send_hid2me_feedback(ipts, fb_data_type, buf, count);
  2474. +}
  2475. +
  2476. +static int ipts_hid_output_report(struct hid_device *hid,
  2477. + __u8 *buf, size_t count)
  2478. +{
  2479. + struct ipts_info *ipts = hid->driver_data;
  2480. + u32 fb_data_type;
  2481. +
  2482. + ipts_dbg(ipts, "hid output report\n");
  2483. +
  2484. + fb_data_type = TOUCH_FEEDBACK_DATA_TYPE_OUTPUT_REPORT;
  2485. +
  2486. + return ipts_hid_send_hid2me_feedback(ipts, fb_data_type, buf, count);
  2487. +}
  2488. +
  2489. +static struct hid_ll_driver ipts_hid_ll_driver = {
  2490. + .parse = ipts_hid_parse,
  2491. + .start = ipts_hid_start,
  2492. + .stop = ipts_hid_stop,
  2493. + .open = ipts_hid_open,
  2494. + .close = ipts_hid_close,
  2495. + .raw_request = ipts_hid_raw_request,
  2496. + .output_report = ipts_hid_output_report,
  2497. +};
  2498. +
  2499. +int ipts_hid_init(struct ipts_info *ipts)
  2500. +{
  2501. + int ret = 0;
  2502. + struct hid_device *hid;
  2503. +
  2504. + hid = hid_allocate_device();
  2505. + if (IS_ERR(hid))
  2506. + return PTR_ERR(hid);
  2507. +
  2508. + hid->driver_data = ipts;
  2509. + hid->ll_driver = &ipts_hid_ll_driver;
  2510. + hid->dev.parent = &ipts->cldev->dev;
  2511. + hid->bus = BUS_MEI;
  2512. + hid->version = ipts->device_info.fw_rev;
  2513. + hid->vendor = ipts->device_info.vendor_id;
  2514. + hid->product = ipts->device_info.device_id;
  2515. +
  2516. + snprintf(hid->phys, sizeof(hid->phys), "heci3");
  2517. + snprintf(hid->name, sizeof(hid->name),
  2518. + "ipts %04hX:%04hX", hid->vendor, hid->product);
  2519. +
  2520. + ret = hid_add_device(hid);
  2521. + if (ret) {
  2522. + if (ret != -ENODEV)
  2523. + ipts_err(ipts, "can't add hid device: %d\n", ret);
  2524. +
  2525. + hid_destroy_device(hid);
  2526. +
  2527. + return ret;
  2528. + }
  2529. +
  2530. + ipts->hid = hid;
  2531. +
  2532. + return 0;
  2533. +}
  2534. +
  2535. +void ipts_hid_release(struct ipts_info *ipts)
  2536. +{
  2537. + if (!ipts->hid)
  2538. + return;
  2539. +
  2540. + hid_destroy_device(ipts->hid);
  2541. +}
  2542. +
  2543. +int ipts_handle_hid_data(struct ipts_info *ipts,
  2544. + struct touch_sensor_hid_ready_for_data_rsp_data *hid_rsp)
  2545. +{
  2546. + struct touch_raw_data_hdr *raw_header;
  2547. + struct ipts_buffer_info *buffer_info;
  2548. + struct touch_feedback_hdr *feedback;
  2549. + u8 *raw_data;
  2550. + int touch_data_buffer_index;
  2551. + int transaction_id;
  2552. + int ret = 0;
  2553. +
  2554. + touch_data_buffer_index = (int)hid_rsp->touch_data_buffer_index;
  2555. + buffer_info = ipts_get_touch_data_buffer_hid(ipts);
  2556. + raw_header = (struct touch_raw_data_hdr *)buffer_info->addr;
  2557. + transaction_id = raw_header->hid_private_data.transaction_id;
  2558. + raw_data = (u8 *)raw_header + sizeof(struct touch_raw_data_hdr);
  2559. +
  2560. + switch (raw_header->data_type) {
  2561. + case TOUCH_RAW_DATA_TYPE_HID_REPORT: {
  2562. + if (raw_header->raw_data_size_bytes > HID_MAX_BUFFER_SIZE) {
  2563. + ipts_err(ipts, "input report too large (%u bytes), skipping",
  2564. + raw_header->raw_data_size_bytes);
  2565. + break;
  2566. + }
  2567. +
  2568. + memcpy(ipts->hid_input_report, raw_data,
  2569. + raw_header->raw_data_size_bytes);
  2570. +
  2571. + ret = hid_input_report(ipts->hid, HID_INPUT_REPORT,
  2572. + (u8 *)ipts->hid_input_report,
  2573. + raw_header->raw_data_size_bytes, 1);
  2574. + if (ret)
  2575. + ipts_err(ipts, "error in hid_input_report: %d\n", ret);
  2576. +
  2577. + break;
  2578. + }
  2579. + case TOUCH_RAW_DATA_TYPE_GET_FEATURES: {
  2580. + // TODO: implement together with "get feature ioctl"
  2581. + break;
  2582. + }
  2583. + case TOUCH_RAW_DATA_TYPE_ERROR: {
  2584. + struct touch_error *touch_err = (struct touch_error *)raw_data;
  2585. +
  2586. + ipts_err(ipts, "error type: %d, me error: %x, err reg: %x\n",
  2587. + touch_err->touch_error_type,
  2588. + touch_err->touch_me_fw_error.value,
  2589. + touch_err->touch_error_register.reg_value);
  2590. +
  2591. + break;
  2592. + }
  2593. + default:
  2594. + break;
  2595. + }
  2596. +
  2597. + // send feedback data for HID mode
  2598. + buffer_info = ipts_get_feedback_buffer(ipts, touch_data_buffer_index);
  2599. + feedback = (struct touch_feedback_hdr *)buffer_info->addr;
  2600. + memset(feedback, 0, sizeof(struct touch_feedback_hdr));
  2601. + feedback->feedback_cmd_type = TOUCH_FEEDBACK_CMD_TYPE_NONE;
  2602. + feedback->payload_size_bytes = 0;
  2603. + feedback->buffer_id = touch_data_buffer_index;
  2604. + feedback->protocol_ver = 0;
  2605. + feedback->reserved[0] = 0xAC;
  2606. +
  2607. + ret = ipts_send_feedback(ipts, touch_data_buffer_index, transaction_id);
  2608. +
  2609. + return ret;
  2610. +}
  2611. +
  2612. +static int handle_outputs(struct ipts_info *ipts, int parallel_idx)
  2613. +{
  2614. + struct kernel_output_buffer_header *out_buf_hdr;
  2615. + struct ipts_buffer_info *output_buf;
  2616. + u8 *input_report, *payload;
  2617. + u8 tr_id;
  2618. + int i, payload_size, header_size;
  2619. + bool send_feedback = false;
  2620. +
  2621. + header_size = sizeof(struct kernel_output_buffer_header);
  2622. + output_buf = ipts_get_output_buffers_by_parallel_id(ipts,
  2623. + parallel_idx);
  2624. +
  2625. + for (i = 0; i < ipts->resource.num_of_outputs; i++) {
  2626. + out_buf_hdr = (struct kernel_output_buffer_header *)
  2627. + output_buf[i].addr;
  2628. +
  2629. + if (out_buf_hdr->length < header_size)
  2630. + continue;
  2631. +
  2632. + tr_id = *(u8 *)&out_buf_hdr->hid_private_data.transaction_id;
  2633. + send_feedback = true;
  2634. +
  2635. + payload_size = out_buf_hdr->length - header_size;
  2636. + payload = out_buf_hdr->data;
  2637. +
  2638. + switch (out_buf_hdr->payload_type) {
  2639. + case OUTPUT_BUFFER_PAYLOAD_HID_INPUT_REPORT: {
  2640. + input_report = ipts->hid_input_report;
  2641. + memcpy(input_report, payload, payload_size);
  2642. +
  2643. + hid_input_report(ipts->hid, HID_INPUT_REPORT,
  2644. + input_report, payload_size, 1);
  2645. +
  2646. + break;
  2647. + }
  2648. + case OUTPUT_BUFFER_PAYLOAD_HID_FEATURE_REPORT: {
  2649. + ipts_dbg(ipts, "output hid feature report\n");
  2650. + break;
  2651. + }
  2652. + case OUTPUT_BUFFER_PAYLOAD_KERNEL_LOAD: {
  2653. + ipts_dbg(ipts, "output kernel load\n");
  2654. + break;
  2655. + }
  2656. + case OUTPUT_BUFFER_PAYLOAD_FEEDBACK_BUFFER: {
  2657. + // Ignored
  2658. + break;
  2659. + }
  2660. + case OUTPUT_BUFFER_PAYLOAD_ERROR: {
  2661. + struct kernel_output_payload_error *err_payload;
  2662. +
  2663. + if (payload_size == 0)
  2664. + break;
  2665. +
  2666. + err_payload = (struct kernel_output_payload_error *)
  2667. + payload;
  2668. +
  2669. + ipts_err(ipts, "severity: %d, source: %d ",
  2670. + err_payload->severity,
  2671. + err_payload->source);
  2672. + ipts_err(ipts, "code : %d:%d:%d:%d\nstring %s\n",
  2673. + err_payload->code[0],
  2674. + err_payload->code[1],
  2675. + err_payload->code[2],
  2676. + err_payload->code[3],
  2677. + err_payload->string);
  2678. +
  2679. + break;
  2680. + }
  2681. + default:
  2682. + ipts_err(ipts, "invalid output buffer payload\n");
  2683. + break;
  2684. + }
  2685. + }
  2686. +
  2687. +
  2688. +
  2689. + if (send_feedback)
  2690. + return ipts_send_feedback(ipts, parallel_idx, tr_id);
  2691. +
  2692. + return 0;
  2693. +}
  2694. +
  2695. +static int handle_output_buffers(struct ipts_info *ipts,
  2696. + int cur_idx, int end_idx)
  2697. +{
  2698. + int max_num_of_buffers = ipts_get_num_of_parallel_buffers(ipts);
  2699. +
  2700. + do {
  2701. + cur_idx++; // cur_idx has last completed so starts with +1
  2702. + cur_idx %= max_num_of_buffers;
  2703. + handle_outputs(ipts, cur_idx);
  2704. + } while (cur_idx != end_idx);
  2705. +
  2706. + return 0;
  2707. +}
  2708. +
  2709. +int ipts_handle_processed_data(struct ipts_info *ipts)
  2710. +{
  2711. + int ret = 0;
  2712. + int current_buffer_idx;
  2713. + int last_buffer_idx;
  2714. +
  2715. + current_buffer_idx = *ipts->last_submitted_id;
  2716. + last_buffer_idx = ipts->last_buffer_completed;
  2717. +
  2718. + if (current_buffer_idx == last_buffer_idx)
  2719. + return 0;
  2720. +
  2721. + ipts->last_buffer_completed = current_buffer_idx;
  2722. + handle_output_buffers(ipts, last_buffer_idx, current_buffer_idx);
  2723. +
  2724. + return ret;
  2725. +}
  2726. diff --git a/drivers/misc/ipts/hid.h b/drivers/misc/ipts/hid.h
  2727. new file mode 100644
  2728. index 000000000000..c943979e0198
  2729. --- /dev/null
  2730. +++ b/drivers/misc/ipts/hid.h
  2731. @@ -0,0 +1,21 @@
  2732. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  2733. +/*
  2734. + *
  2735. + * Intel Precise Touch & Stylus
  2736. + * Copyright (c) 2016 Intel Corporation
  2737. + *
  2738. + */
  2739. +
  2740. +#ifndef _IPTS_HID_H_
  2741. +#define _IPTS_HID_H_
  2742. +
  2743. +#include "ipts.h"
  2744. +
  2745. +#define BUS_MEI 0x44
  2746. +
  2747. +int ipts_hid_init(struct ipts_info *ipts);
  2748. +void ipts_hid_release(struct ipts_info *ipts);
  2749. +int ipts_handle_hid_data(struct ipts_info *ipts,
  2750. + struct touch_sensor_hid_ready_for_data_rsp_data *hid_rsp);
  2751. +
  2752. +#endif // _IPTS_HID_H_
  2753. diff --git a/drivers/misc/ipts/ipts.c b/drivers/misc/ipts/ipts.c
  2754. new file mode 100644
  2755. index 000000000000..dfafabf8dd94
  2756. --- /dev/null
  2757. +++ b/drivers/misc/ipts/ipts.c
  2758. @@ -0,0 +1,62 @@
  2759. +// SPDX-License-Identifier: GPL-2.0-or-later
  2760. +/*
  2761. + *
  2762. + * Intel Precise Touch & Stylus
  2763. + * Copyright (c) 2016 Intel Corporation
  2764. + *
  2765. + */
  2766. +
  2767. +#include <linux/device.h>
  2768. +#include <stdarg.h>
  2769. +
  2770. +#include "ipts.h"
  2771. +#include "params.h"
  2772. +
  2773. +static void ipts_printk(const char *level, const struct device *dev,
  2774. + struct va_format *vaf)
  2775. +{
  2776. + if (dev) {
  2777. + dev_printk_emit(level[1] - '0', dev, "%s %s: %pV",
  2778. + dev_driver_string(dev), dev_name(dev), vaf);
  2779. + } else {
  2780. + // checkpatch wants this to be prefixed with KERN_*, but
  2781. + // since the level is passed as a parameter, ignore it
  2782. + printk("%s(NULL device *): %pV", level, vaf);
  2783. + }
  2784. +}
  2785. +
  2786. +void ipts_info(struct ipts_info *ipts, const char *fmt, ...)
  2787. +{
  2788. + va_list args;
  2789. + struct va_format vaf;
  2790. +
  2791. + if (!ipts_modparams.debug)
  2792. + return;
  2793. +
  2794. + va_start(args, fmt);
  2795. +
  2796. + vaf.fmt = fmt;
  2797. + vaf.va = &args;
  2798. +
  2799. + ipts_printk(KERN_INFO, &ipts->cldev->dev, &vaf);
  2800. +
  2801. + va_end(args);
  2802. +}
  2803. +
  2804. +void ipts_dbg(struct ipts_info *ipts, const char *fmt, ...)
  2805. +{
  2806. + va_list args;
  2807. + struct va_format vaf;
  2808. +
  2809. + if (!ipts_modparams.debug)
  2810. + return;
  2811. +
  2812. + va_start(args, fmt);
  2813. +
  2814. + vaf.fmt = fmt;
  2815. + vaf.va = &args;
  2816. +
  2817. + ipts_printk(KERN_DEBUG, &ipts->cldev->dev, &vaf);
  2818. +
  2819. + va_end(args);
  2820. +}
  2821. diff --git a/drivers/misc/ipts/ipts.h b/drivers/misc/ipts/ipts.h
  2822. new file mode 100644
  2823. index 000000000000..32eb3ffd68a3
  2824. --- /dev/null
  2825. +++ b/drivers/misc/ipts/ipts.h
  2826. @@ -0,0 +1,172 @@
  2827. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  2828. +/*
  2829. + *
  2830. + * Intel Precise Touch & Stylus
  2831. + * Copyright (c) 2016 Intel Corporation
  2832. + *
  2833. + */
  2834. +
  2835. +#ifndef _IPTS_H_
  2836. +#define _IPTS_H_
  2837. +
  2838. +#include <linux/hid.h>
  2839. +#include <linux/ipts-binary.h>
  2840. +#include <linux/ipts-gfx.h>
  2841. +#include <linux/mei_cl_bus.h>
  2842. +#include <linux/types.h>
  2843. +
  2844. +#include "mei-msgs.h"
  2845. +#include "state.h"
  2846. +
  2847. +#define HID_PARALLEL_DATA_BUFFERS TOUCH_SENSOR_MAX_DATA_BUFFERS
  2848. +
  2849. +#define IPTS_MAX_RETRY 3
  2850. +
  2851. +struct ipts_buffer_info {
  2852. + char *addr;
  2853. + dma_addr_t dma_addr;
  2854. +};
  2855. +
  2856. +struct ipts_gfx_info {
  2857. + u64 gfx_handle;
  2858. + struct ipts_ops ipts_ops;
  2859. +};
  2860. +
  2861. +struct ipts_resource {
  2862. + // ME & GFX resource
  2863. + struct ipts_buffer_info touch_data_buffer_raw
  2864. + [HID_PARALLEL_DATA_BUFFERS];
  2865. + struct ipts_buffer_info touch_data_buffer_hid;
  2866. + struct ipts_buffer_info feedback_buffer[HID_PARALLEL_DATA_BUFFERS];
  2867. + struct ipts_buffer_info hid2me_buffer;
  2868. + u32 hid2me_buffer_size;
  2869. +
  2870. + u8 wq_item_size;
  2871. + struct ipts_wq_info wq_info;
  2872. +
  2873. + // ME2HID buffer
  2874. + char *me2hid_buffer;
  2875. +
  2876. + // GFX specific resource
  2877. + struct ipts_buffer_info raw_data_mode_output_buffer
  2878. + [HID_PARALLEL_DATA_BUFFERS][MAX_NUM_OUTPUT_BUFFERS];
  2879. +
  2880. + int num_of_outputs;
  2881. + bool default_resource_ready;
  2882. + bool raw_data_resource_ready;
  2883. +};
  2884. +
  2885. +struct ipts_info {
  2886. + struct mei_cl_device *cldev;
  2887. + struct hid_device *hid;
  2888. +
  2889. + struct work_struct init_work;
  2890. + struct work_struct raw_data_work;
  2891. + struct work_struct gfx_status_work;
  2892. +
  2893. + struct task_struct *event_loop;
  2894. +
  2895. +#if IS_ENABLED(CONFIG_DEBUG_FS)
  2896. + struct dentry *dbgfs_dir;
  2897. +#endif
  2898. +
  2899. + enum ipts_state state;
  2900. +
  2901. + enum touch_sensor_mode sensor_mode;
  2902. + struct touch_sensor_get_device_info_rsp_data device_info;
  2903. + struct ipts_resource resource;
  2904. + u8 hid_input_report[HID_MAX_BUFFER_SIZE];
  2905. + int num_of_parallel_data_buffers;
  2906. + bool hid_desc_ready;
  2907. +
  2908. + int current_buffer_index;
  2909. + int last_buffer_completed;
  2910. + int *last_submitted_id;
  2911. +
  2912. + struct ipts_gfx_info gfx_info;
  2913. + u64 kernel_handle;
  2914. + int gfx_status;
  2915. + bool display_status;
  2916. +
  2917. + bool restart;
  2918. +};
  2919. +
  2920. +#if IS_ENABLED(CONFIG_DEBUG_FS)
  2921. +int ipts_dbgfs_register(struct ipts_info *ipts, const char *name);
  2922. +void ipts_dbgfs_deregister(struct ipts_info *ipts);
  2923. +#else
  2924. +static int ipts_dbgfs_register(struct ipts_info *ipts, const char *name);
  2925. +static void ipts_dbgfs_deregister(struct ipts_info *ipts);
  2926. +#endif
  2927. +
  2928. +void ipts_info(struct ipts_info *ipts, const char *fmt, ...);
  2929. +void ipts_dbg(struct ipts_info *ipts, const char *fmt, ...);
  2930. +
  2931. +// Because ipts_err is unconditional, this can stay a macro for now
  2932. +#define ipts_err(ipts, format, arg...) \
  2933. + dev_err(&ipts->cldev->dev, format, ##arg)
  2934. +
  2935. +/*
  2936. + * Inline functions
  2937. + */
  2938. +static inline void ipts_set_state(struct ipts_info *ipts,
  2939. + enum ipts_state state)
  2940. +{
  2941. + ipts->state = state;
  2942. +}
  2943. +
  2944. +static inline enum ipts_state ipts_get_state(const struct ipts_info *ipts)
  2945. +{
  2946. + return ipts->state;
  2947. +}
  2948. +
  2949. +static inline bool ipts_is_default_resource_ready(const struct ipts_info *ipts)
  2950. +{
  2951. + return ipts->resource.default_resource_ready;
  2952. +}
  2953. +
  2954. +static inline bool ipts_is_raw_data_resource_ready(const struct ipts_info *ipts)
  2955. +{
  2956. + return ipts->resource.raw_data_resource_ready;
  2957. +}
  2958. +
  2959. +static inline struct ipts_buffer_info *ipts_get_feedback_buffer(
  2960. + struct ipts_info *ipts, int buffer_idx)
  2961. +{
  2962. + return &ipts->resource.feedback_buffer[buffer_idx];
  2963. +}
  2964. +
  2965. +static inline struct ipts_buffer_info *ipts_get_touch_data_buffer_hid(
  2966. + struct ipts_info *ipts)
  2967. +{
  2968. + return &ipts->resource.touch_data_buffer_hid;
  2969. +}
  2970. +
  2971. +static inline struct ipts_buffer_info *ipts_get_output_buffers_by_parallel_id(
  2972. + struct ipts_info *ipts, int parallel_idx)
  2973. +{
  2974. + return &ipts->resource.raw_data_mode_output_buffer[parallel_idx][0];
  2975. +}
  2976. +
  2977. +static inline struct ipts_buffer_info *ipts_get_hid2me_buffer(
  2978. + struct ipts_info *ipts)
  2979. +{
  2980. + return &ipts->resource.hid2me_buffer;
  2981. +}
  2982. +
  2983. +static inline void ipts_set_wq_item_size(struct ipts_info *ipts, u8 size)
  2984. +{
  2985. + ipts->resource.wq_item_size = size;
  2986. +}
  2987. +
  2988. +static inline u8 ipts_get_wq_item_size(const struct ipts_info *ipts)
  2989. +{
  2990. + return ipts->resource.wq_item_size;
  2991. +}
  2992. +
  2993. +static inline int ipts_get_num_of_parallel_buffers(const struct ipts_info *ipts)
  2994. +{
  2995. + return ipts->num_of_parallel_data_buffers;
  2996. +}
  2997. +
  2998. +#endif // _IPTS_H_
  2999. diff --git a/drivers/misc/ipts/kernel.c b/drivers/misc/ipts/kernel.c
  3000. new file mode 100644
  3001. index 000000000000..a2c43228e2c7
  3002. --- /dev/null
  3003. +++ b/drivers/misc/ipts/kernel.c
  3004. @@ -0,0 +1,1047 @@
  3005. +// SPDX-License-Identifier: GPL-2.0-or-later
  3006. +/*
  3007. + *
  3008. + * Intel Precise Touch & Stylus
  3009. + * Copyright (c) 2016 Intel Corporation
  3010. + *
  3011. + */
  3012. +
  3013. +#include <linux/module.h>
  3014. +#include <linux/firmware.h>
  3015. +#include <linux/ipts.h>
  3016. +#include <linux/ipts-binary.h>
  3017. +#include <linux/vmalloc.h>
  3018. +
  3019. +#include "companion.h"
  3020. +#include "gfx.h"
  3021. +#include "ipts.h"
  3022. +#include "msg-handler.h"
  3023. +#include "resource.h"
  3024. +#include "state.h"
  3025. +
  3026. +#define BDW_SURFACE_BASE_ADDRESS 0x6101000e
  3027. +#define SURFACE_STATE_OFFSET_WORD 4
  3028. +#define SBA_OFFSET_BYTES 16384
  3029. +#define LASTSUBMITID_DEFAULT_VALUE -1
  3030. +
  3031. +#define IPTS_INPUT_ON ((u32)1 << IPTS_INPUT)
  3032. +#define IPTS_OUTPUT_ON ((u32)1 << IPTS_OUTPUT)
  3033. +#define IPTS_CONFIGURATION_ON ((u32)1 << IPTS_CONFIGURATION)
  3034. +#define IPTS_CALIBRATION_ON ((u32)1 << IPTS_CALIBRATION)
  3035. +#define IPTS_FEATURE_ON ((u32)1 << IPTS_FEATURE)
  3036. +
  3037. +// OpenCL kernel
  3038. +struct bin_workload {
  3039. + int cmdbuf_index;
  3040. + int iobuf_input;
  3041. + int iobuf_output[MAX_NUM_OUTPUT_BUFFERS];
  3042. +};
  3043. +
  3044. +struct bin_buffer {
  3045. + unsigned int handle;
  3046. + struct ipts_mapbuffer *buf;
  3047. +
  3048. + // only releasing vendor kernel unmaps output buffers
  3049. + bool no_unmap;
  3050. +};
  3051. +
  3052. +struct bin_alloc_info {
  3053. + struct bin_buffer *buffs;
  3054. + int num_of_allocations;
  3055. + int num_of_outputs;
  3056. +
  3057. + int num_of_buffers;
  3058. +};
  3059. +
  3060. +struct bin_guc_wq_item {
  3061. + unsigned int batch_offset;
  3062. + unsigned int size;
  3063. + char data[];
  3064. +};
  3065. +
  3066. +struct bin_kernel_info {
  3067. + struct bin_workload *wl;
  3068. + struct bin_alloc_info *alloc_info;
  3069. + struct bin_guc_wq_item *guc_wq_item;
  3070. + struct ipts_bin_bufid_patch bufid_patch;
  3071. +
  3072. + // 1: vendor, 0: postprocessing
  3073. + bool is_vendor;
  3074. +};
  3075. +
  3076. +struct bin_kernel_list {
  3077. + struct ipts_mapbuffer *bufid_buf;
  3078. + int num_of_kernels;
  3079. + struct bin_kernel_info kernels[];
  3080. +};
  3081. +
  3082. +struct bin_parse_info {
  3083. + u8 *data;
  3084. + int size;
  3085. + int parsed;
  3086. +
  3087. + struct ipts_bin_fw_info *fw_info;
  3088. +
  3089. + // only used by postprocessing
  3090. + struct bin_kernel_info *vendor_kernel;
  3091. +
  3092. + // interested vendor output index
  3093. + u32 interested_vendor_output;
  3094. +};
  3095. +
  3096. +static int bin_read_fw(struct ipts_info *ipts, const char *fw_name,
  3097. + u8 *data, int size)
  3098. +{
  3099. + const struct firmware *fw = NULL;
  3100. + int ret = 0;
  3101. +
  3102. + ret = ipts_request_firmware(&fw, fw_name, &ipts->cldev->dev);
  3103. + if (ret) {
  3104. + ipts_err(ipts, "cannot read fw %s\n", fw_name);
  3105. + return ret;
  3106. + }
  3107. +
  3108. + if (fw->size > size) {
  3109. + ipts_dbg(ipts, "too small buffer to contain fw data\n");
  3110. + ret = -EINVAL;
  3111. + } else {
  3112. + memcpy(data, fw->data, fw->size);
  3113. + }
  3114. +
  3115. + release_firmware(fw);
  3116. +
  3117. + return ret;
  3118. +}
  3119. +
  3120. +
  3121. +static struct ipts_bin_data_file_info *bin_get_data_file_info(
  3122. + struct ipts_bin_fw_info *fw_info, u32 io_buffer_type)
  3123. +{
  3124. + int i;
  3125. +
  3126. + for (i = 0; i < fw_info->num_of_data_files; i++) {
  3127. + if (fw_info->data_file[i].io_buffer_type == io_buffer_type)
  3128. + break;
  3129. + }
  3130. +
  3131. + if (i == fw_info->num_of_data_files)
  3132. + return NULL;
  3133. +
  3134. + return &fw_info->data_file[i];
  3135. +}
  3136. +
  3137. +static inline bool is_shared_data(
  3138. + const struct ipts_bin_data_file_info *data_file)
  3139. +{
  3140. + if (!data_file)
  3141. + return false;
  3142. +
  3143. + return (!!(data_file->flags & IPTS_DATA_FILE_FLAG_SHARE));
  3144. +}
  3145. +
  3146. +static inline bool is_alloc_cont_data(
  3147. + const struct ipts_bin_data_file_info *data_file)
  3148. +{
  3149. + if (!data_file)
  3150. + return false;
  3151. +
  3152. + return (!!(data_file->flags & IPTS_DATA_FILE_FLAG_ALLOC_CONTIGUOUS));
  3153. +}
  3154. +
  3155. +static inline bool is_parsing_vendor_kernel(
  3156. + const struct bin_parse_info *parse_info)
  3157. +{
  3158. + // vendor_kernel == null while loading itself
  3159. + return parse_info->vendor_kernel == NULL;
  3160. +}
  3161. +
  3162. +static int bin_read_allocation_list(struct ipts_info *ipts,
  3163. + struct bin_parse_info *parse_info,
  3164. + struct bin_alloc_info *alloc_info)
  3165. +{
  3166. + struct ipts_bin_alloc_list *alloc_list;
  3167. + int aidx, pidx, num_of_parallels, bidx, num_of_buffers;
  3168. + int parsed, size;
  3169. +
  3170. + parsed = parse_info->parsed;
  3171. + size = parse_info->size;
  3172. +
  3173. + alloc_list = (struct ipts_bin_alloc_list *)&parse_info->data[parsed];
  3174. +
  3175. + // validation check
  3176. + if (sizeof(alloc_list->num) > size - parsed)
  3177. + return -EINVAL;
  3178. +
  3179. + // read the number of aloocations
  3180. + parsed += sizeof(alloc_list->num);
  3181. +
  3182. + // validation check
  3183. + if (sizeof(alloc_list->alloc[0]) * alloc_list->num > size - parsed)
  3184. + return -EINVAL;
  3185. +
  3186. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  3187. + num_of_buffers = num_of_parallels * alloc_list->num + num_of_parallels;
  3188. + alloc_info->buffs = vmalloc(sizeof(struct bin_buffer) *
  3189. + num_of_buffers);
  3190. +
  3191. + if (alloc_info->buffs == NULL)
  3192. + return -ENOMEM;
  3193. +
  3194. + memset(alloc_info->buffs, 0, sizeof(struct bin_buffer) *
  3195. + num_of_buffers);
  3196. +
  3197. + for (aidx = 0; aidx < alloc_list->num; aidx++) {
  3198. + for (pidx = 0; pidx < num_of_parallels; pidx++) {
  3199. + bidx = aidx + (pidx * alloc_list->num);
  3200. + alloc_info->buffs[bidx].handle =
  3201. + alloc_list->alloc[aidx].handle;
  3202. + }
  3203. +
  3204. + parsed += sizeof(alloc_list->alloc[0]);
  3205. + }
  3206. +
  3207. + parse_info->parsed = parsed;
  3208. + alloc_info->num_of_allocations = alloc_list->num;
  3209. + alloc_info->num_of_buffers = num_of_buffers;
  3210. +
  3211. + ipts_dbg(ipts, "number of allocations = %d, buffers = %d\n",
  3212. + alloc_info->num_of_allocations,
  3213. + alloc_info->num_of_buffers);
  3214. +
  3215. + return 0;
  3216. +}
  3217. +
  3218. +static void patch_SBA(u32 *buf_addr, u64 gpu_addr, int size)
  3219. +{
  3220. + u64 *stateBase;
  3221. + u64 SBA;
  3222. + u32 inst;
  3223. + int i;
  3224. +
  3225. + SBA = gpu_addr + SBA_OFFSET_BYTES;
  3226. +
  3227. + for (i = 0; i < size / 4; i++) {
  3228. + inst = buf_addr[i];
  3229. + if (inst == BDW_SURFACE_BASE_ADDRESS) {
  3230. + stateBase = (u64 *)&buf_addr
  3231. + [i + SURFACE_STATE_OFFSET_WORD];
  3232. + *stateBase |= SBA;
  3233. + *stateBase |= 0x01; // enable
  3234. + break;
  3235. + }
  3236. + }
  3237. +}
  3238. +
  3239. +static int bin_read_cmd_buffer(struct ipts_info *ipts,
  3240. + struct bin_parse_info *parse_info,
  3241. + struct bin_alloc_info *alloc_info, struct bin_workload *wl)
  3242. +{
  3243. + struct ipts_bin_cmdbuf *cmd;
  3244. + struct ipts_mapbuffer *buf;
  3245. + int cidx, size, parsed, pidx, num_of_parallels;
  3246. +
  3247. + size = parse_info->size;
  3248. + parsed = parse_info->parsed;
  3249. +
  3250. + cmd = (struct ipts_bin_cmdbuf *)&parse_info->data[parsed];
  3251. +
  3252. + if (sizeof(cmd->size) > size - parsed)
  3253. + return -EINVAL;
  3254. +
  3255. + parsed += sizeof(cmd->size);
  3256. + if (cmd->size > size - parsed)
  3257. + return -EINVAL;
  3258. +
  3259. + ipts_dbg(ipts, "cmd buf size = %d\n", cmd->size);
  3260. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  3261. +
  3262. + // command buffers are located after the other allocations
  3263. + cidx = num_of_parallels * alloc_info->num_of_allocations;
  3264. + for (pidx = 0; pidx < num_of_parallels; pidx++) {
  3265. + buf = ipts_map_buffer(ipts, cmd->size, 0);
  3266. +
  3267. + if (buf == NULL)
  3268. + return -ENOMEM;
  3269. +
  3270. + ipts_dbg(ipts, "cmd_idx[%d] = %d, g:0x%p, c:0x%p\n", pidx,
  3271. + cidx, buf->gfx_addr, buf->cpu_addr);
  3272. +
  3273. + memcpy((void *)buf->cpu_addr, &(cmd->data[0]), cmd->size);
  3274. + patch_SBA(buf->cpu_addr, (u64)buf->gfx_addr, cmd->size);
  3275. +
  3276. + alloc_info->buffs[cidx].buf = buf;
  3277. + wl[pidx].cmdbuf_index = cidx;
  3278. + cidx++;
  3279. + }
  3280. +
  3281. + parsed += cmd->size;
  3282. + parse_info->parsed = parsed;
  3283. +
  3284. + return 0;
  3285. +}
  3286. +
  3287. +static int bin_find_alloc(struct ipts_info *ipts,
  3288. + struct bin_alloc_info *alloc_info, u32 handle)
  3289. +{
  3290. + int i;
  3291. +
  3292. + for (i = 0; i < alloc_info->num_of_allocations; i++) {
  3293. + if (alloc_info->buffs[i].handle == handle)
  3294. + return i;
  3295. + }
  3296. +
  3297. + return -1;
  3298. +}
  3299. +
  3300. +static struct ipts_mapbuffer *bin_get_vendor_kernel_output(
  3301. + struct bin_parse_info *parse_info, int pidx)
  3302. +{
  3303. + struct bin_kernel_info *vendor = parse_info->vendor_kernel;
  3304. + struct bin_alloc_info *alloc_info;
  3305. + int bidx, vidx;
  3306. +
  3307. + alloc_info = vendor->alloc_info;
  3308. + vidx = parse_info->interested_vendor_output;
  3309. +
  3310. + if (vidx >= alloc_info->num_of_outputs)
  3311. + return NULL;
  3312. +
  3313. + bidx = vendor->wl[pidx].iobuf_output[vidx];
  3314. +
  3315. + return alloc_info->buffs[bidx].buf;
  3316. +}
  3317. +
  3318. +static int bin_read_res_list(struct ipts_info *ipts,
  3319. + struct bin_parse_info *parse_info,
  3320. + struct bin_alloc_info *alloc_info, struct bin_workload *wl)
  3321. +{
  3322. + struct ipts_bin_res_list *res_list;
  3323. + struct ipts_bin_res *res;
  3324. + struct ipts_mapbuffer *buf;
  3325. + struct ipts_bin_data_file_info *data_file;
  3326. + u8 *bin_data;
  3327. + int i, size, parsed, pidx, num_of_parallels, oidx = -1;
  3328. + int bidx, num_of_alloc;
  3329. + u32 buf_size, flags, io_buf_type;
  3330. + bool initialize;
  3331. +
  3332. + parsed = parse_info->parsed;
  3333. + size = parse_info->size;
  3334. + bin_data = parse_info->data;
  3335. +
  3336. + res_list = (struct ipts_bin_res_list *)&parse_info->data[parsed];
  3337. +
  3338. + if (sizeof(res_list->num) > (size - parsed))
  3339. + return -EINVAL;
  3340. +
  3341. + parsed += sizeof(res_list->num);
  3342. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  3343. +
  3344. + ipts_dbg(ipts, "number of resources %u\n", res_list->num);
  3345. +
  3346. + for (i = 0; i < res_list->num; i++) {
  3347. + struct ipts_bin_io_header *io_hdr;
  3348. +
  3349. + initialize = false;
  3350. + io_buf_type = 0;
  3351. + flags = 0;
  3352. +
  3353. + // initial data
  3354. + data_file = NULL;
  3355. +
  3356. + res = (struct ipts_bin_res *)(&(bin_data[parsed]));
  3357. + if (sizeof(res[0]) > (size - parsed))
  3358. + return -EINVAL;
  3359. +
  3360. + ipts_dbg(ipts, "Resource(%d): handle 0x%08x type %u init %u size %u alsigned %u\n",
  3361. + i, res->handle, res->type, res->initialize,
  3362. + res->size, res->aligned_size);
  3363. +
  3364. + parsed += sizeof(res[0]);
  3365. +
  3366. + if (res->initialize) {
  3367. + if (res->size > (size - parsed))
  3368. + return -EINVAL;
  3369. + parsed += res->size;
  3370. + }
  3371. +
  3372. + initialize = res->initialize;
  3373. + if (!initialize || res->size <=
  3374. + sizeof(struct ipts_bin_io_header))
  3375. + goto read_res_list_no_init;
  3376. +
  3377. + io_hdr = (struct ipts_bin_io_header *)(&res->data[0]);
  3378. +
  3379. + if (strncmp(io_hdr->str, "INTELTOUCH", 10) != 0)
  3380. + goto read_res_list_no_init;
  3381. +
  3382. + data_file = bin_get_data_file_info(parse_info->fw_info,
  3383. + (u32)io_hdr->type);
  3384. +
  3385. + switch (io_hdr->type) {
  3386. + case IPTS_INPUT: {
  3387. + ipts_dbg(ipts, "input detected\n");
  3388. + io_buf_type = IPTS_INPUT_ON;
  3389. + flags = IPTS_BUF_FLAG_CONTIGUOUS;
  3390. + break;
  3391. + }
  3392. + case IPTS_OUTPUT: {
  3393. + ipts_dbg(ipts, "output detected\n");
  3394. + io_buf_type = IPTS_OUTPUT_ON;
  3395. + oidx++;
  3396. + break;
  3397. + }
  3398. + default: {
  3399. + if ((u32)io_hdr->type > 31) {
  3400. + ipts_err(ipts, "invalid io buffer : %u\n",
  3401. + (u32)io_hdr->type);
  3402. + continue;
  3403. + }
  3404. +
  3405. + if (is_alloc_cont_data(data_file))
  3406. + flags = IPTS_BUF_FLAG_CONTIGUOUS;
  3407. +
  3408. + io_buf_type = ((u32)1 << (u32)io_hdr->type);
  3409. + ipts_dbg(ipts, "special io buffer %u\n",
  3410. + io_hdr->type);
  3411. +
  3412. + break;
  3413. + }
  3414. + }
  3415. +
  3416. + initialize = false;
  3417. +
  3418. +read_res_list_no_init:
  3419. + num_of_alloc = alloc_info->num_of_allocations;
  3420. + bidx = bin_find_alloc(ipts, alloc_info, res->handle);
  3421. +
  3422. + if (bidx == -1) {
  3423. + ipts_dbg(ipts, "cannot find alloc info\n");
  3424. + return -EINVAL;
  3425. + }
  3426. +
  3427. + for (pidx = 0; pidx < num_of_parallels; pidx++,
  3428. + bidx += num_of_alloc) {
  3429. + if (!res->aligned_size)
  3430. + continue;
  3431. +
  3432. + if (!(pidx == 0 || (io_buf_type &&
  3433. + !is_shared_data(data_file))))
  3434. + continue;
  3435. +
  3436. + buf_size = res->aligned_size;
  3437. + if (io_buf_type & IPTS_INPUT_ON) {
  3438. + buf_size = max_t(u32, buf_size,
  3439. + ipts->device_info.frame_size);
  3440. +
  3441. + wl[pidx].iobuf_input = bidx;
  3442. + } else if (io_buf_type & IPTS_OUTPUT_ON) {
  3443. + wl[pidx].iobuf_output[oidx] = bidx;
  3444. +
  3445. + if (is_parsing_vendor_kernel(parse_info) ||
  3446. + oidx == 0)
  3447. + goto read_res_list_no_inout_err;
  3448. +
  3449. + ipts_err(ipts, "postproc with >1 inout is not supported: %d\n",
  3450. + oidx);
  3451. +
  3452. + return -EINVAL;
  3453. + }
  3454. +
  3455. +read_res_list_no_inout_err:
  3456. + if (!is_parsing_vendor_kernel(parse_info) &&
  3457. + io_buf_type & IPTS_OUTPUT_ON) {
  3458. + buf = bin_get_vendor_kernel_output(
  3459. + parse_info, pidx);
  3460. +
  3461. + alloc_info->buffs[bidx].no_unmap = true;
  3462. + } else {
  3463. + buf = ipts_map_buffer(ipts, buf_size, flags);
  3464. + }
  3465. +
  3466. + if (buf == NULL) {
  3467. + ipts_dbg(ipts, "ipts_map_buffer failed\n");
  3468. + return -ENOMEM;
  3469. + }
  3470. +
  3471. + if (initialize) {
  3472. + memcpy((void *)buf->cpu_addr, &(res->data[0]),
  3473. + res->size);
  3474. + } else if (data_file && strlen(data_file->file_name)) {
  3475. + bin_read_fw(ipts, data_file->file_name,
  3476. + buf->cpu_addr, buf_size);
  3477. + } else if (is_parsing_vendor_kernel(parse_info) ||
  3478. + !(io_buf_type & IPTS_OUTPUT_ON)) {
  3479. + memset((void *)buf->cpu_addr, 0, res->size);
  3480. + }
  3481. +
  3482. + alloc_info->buffs[bidx].buf = buf;
  3483. + }
  3484. + }
  3485. +
  3486. + alloc_info->num_of_outputs = oidx + 1;
  3487. + parse_info->parsed = parsed;
  3488. +
  3489. + return 0;
  3490. +}
  3491. +
  3492. +static int bin_read_patch_list(struct ipts_info *ipts,
  3493. + struct bin_parse_info *parse_info,
  3494. + struct bin_alloc_info *alloc_info, struct bin_workload *wl)
  3495. +{
  3496. + struct ipts_bin_patch_list *patch_list;
  3497. + struct ipts_bin_patch *patch;
  3498. + struct ipts_mapbuffer *cmd = NULL;
  3499. + u8 *batch;
  3500. + int parsed, size, i, pidx, num_of_parallels, cidx, bidx;
  3501. + unsigned int gtt_offset;
  3502. +
  3503. + parsed = parse_info->parsed;
  3504. + size = parse_info->size;
  3505. + patch_list = (struct ipts_bin_patch_list *)&parse_info->data[parsed];
  3506. +
  3507. + if (sizeof(patch_list->num) > (size - parsed))
  3508. + return -EFAULT;
  3509. + parsed += sizeof(patch_list->num);
  3510. +
  3511. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  3512. + patch = (struct ipts_bin_patch *)(&patch_list->patch[0]);
  3513. +
  3514. + for (i = 0; i < patch_list->num; i++) {
  3515. + if (sizeof(patch_list->patch[0]) > (size - parsed))
  3516. + return -EFAULT;
  3517. +
  3518. + for (pidx = 0; pidx < num_of_parallels; pidx++) {
  3519. + cidx = wl[pidx].cmdbuf_index;
  3520. + bidx = patch[i].index + pidx *
  3521. + alloc_info->num_of_allocations;
  3522. +
  3523. + // buffer is shared
  3524. + if (alloc_info->buffs[bidx].buf == NULL)
  3525. + bidx = patch[i].index;
  3526. +
  3527. + cmd = alloc_info->buffs[cidx].buf;
  3528. + batch = (char *)(u64)cmd->cpu_addr;
  3529. +
  3530. + gtt_offset = 0;
  3531. + if (alloc_info->buffs[bidx].buf != NULL) {
  3532. + gtt_offset = (u32)(u64)alloc_info->buffs
  3533. + [bidx].buf->gfx_addr;
  3534. + }
  3535. + gtt_offset += patch[i].alloc_offset;
  3536. +
  3537. + batch += patch[i].patch_offset;
  3538. + *(u32 *)batch = gtt_offset;
  3539. + }
  3540. +
  3541. + parsed += sizeof(patch_list->patch[0]);
  3542. + }
  3543. +
  3544. + parse_info->parsed = parsed;
  3545. +
  3546. + return 0;
  3547. +}
  3548. +
  3549. +static int bin_read_guc_wq_item(struct ipts_info *ipts,
  3550. + struct bin_parse_info *parse_info,
  3551. + struct bin_guc_wq_item **guc_wq_item)
  3552. +{
  3553. + struct ipts_bin_guc_wq_info *bin_guc_wq;
  3554. + struct bin_guc_wq_item *item;
  3555. + u8 *wi_data;
  3556. + int size, parsed, hdr_size, wi_size;
  3557. + int i, batch_offset;
  3558. +
  3559. + parsed = parse_info->parsed;
  3560. + size = parse_info->size;
  3561. + bin_guc_wq = (struct ipts_bin_guc_wq_info *)&parse_info->data[parsed];
  3562. +
  3563. + wi_size = bin_guc_wq->size;
  3564. + wi_data = bin_guc_wq->data;
  3565. + batch_offset = bin_guc_wq->batch_offset;
  3566. +
  3567. + ipts_dbg(ipts, "wi size = %d, bt offset = %d\n", wi_size, batch_offset);
  3568. +
  3569. + for (i = 0; i < wi_size / sizeof(u32); i++)
  3570. + ipts_dbg(ipts, "wi[%d] = 0x%08x\n", i, *((u32 *)wi_data + i));
  3571. +
  3572. + hdr_size = sizeof(bin_guc_wq->size) + sizeof(bin_guc_wq->batch_offset);
  3573. +
  3574. + if (hdr_size > (size - parsed))
  3575. + return -EINVAL;
  3576. +
  3577. + parsed += hdr_size;
  3578. + item = vmalloc(sizeof(struct bin_guc_wq_item) + wi_size);
  3579. +
  3580. + if (item == NULL)
  3581. + return -ENOMEM;
  3582. +
  3583. + item->size = wi_size;
  3584. + item->batch_offset = batch_offset;
  3585. + memcpy(item->data, wi_data, wi_size);
  3586. +
  3587. + *guc_wq_item = item;
  3588. +
  3589. + parsed += wi_size;
  3590. + parse_info->parsed = parsed;
  3591. +
  3592. + return 0;
  3593. +}
  3594. +
  3595. +static int bin_setup_guc_workqueue(struct ipts_info *ipts,
  3596. + struct bin_kernel_list *kernel_list)
  3597. +{
  3598. + struct bin_alloc_info *alloc_info;
  3599. + struct bin_workload *wl;
  3600. + struct bin_kernel_info *kernel;
  3601. + struct bin_buffer *bin_buf;
  3602. + u8 *wq_start, *wq_addr, *wi_data;
  3603. + int wq_size, wi_size, pidx, cidx, kidx, iter_size;
  3604. + int i, num_of_parallels, batch_offset, k_num, total_workload;
  3605. +
  3606. + wq_addr = (u8 *)ipts->resource.wq_info.wq_addr;
  3607. + wq_size = ipts->resource.wq_info.wq_size;
  3608. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  3609. + total_workload = ipts_get_wq_item_size(ipts);
  3610. + k_num = kernel_list->num_of_kernels;
  3611. +
  3612. + iter_size = total_workload * num_of_parallels;
  3613. + if (wq_size % iter_size) {
  3614. + ipts_err(ipts, "wq item cannot fit into wq\n");
  3615. + return -EINVAL;
  3616. + }
  3617. +
  3618. + wq_start = wq_addr;
  3619. + for (pidx = 0; pidx < num_of_parallels; pidx++) {
  3620. + kernel = &kernel_list->kernels[0];
  3621. +
  3622. + for (kidx = 0; kidx < k_num; kidx++, kernel++) {
  3623. + wl = kernel->wl;
  3624. + alloc_info = kernel->alloc_info;
  3625. +
  3626. + batch_offset = kernel->guc_wq_item->batch_offset;
  3627. + wi_size = kernel->guc_wq_item->size;
  3628. + wi_data = &kernel->guc_wq_item->data[0];
  3629. +
  3630. + cidx = wl[pidx].cmdbuf_index;
  3631. + bin_buf = &alloc_info->buffs[cidx];
  3632. +
  3633. + // Patch the WQ Data with proper batch buffer offset
  3634. + *(u32 *)(wi_data + batch_offset) =
  3635. + (u32)(unsigned long)(bin_buf->buf->gfx_addr);
  3636. +
  3637. + memcpy(wq_addr, wi_data, wi_size);
  3638. + wq_addr += wi_size;
  3639. + }
  3640. + }
  3641. +
  3642. + for (i = 0; i < (wq_size / iter_size) - 1; i++) {
  3643. + memcpy(wq_addr, wq_start, iter_size);
  3644. + wq_addr += iter_size;
  3645. + }
  3646. +
  3647. + return 0;
  3648. +}
  3649. +
  3650. +static int bin_read_bufid_patch(struct ipts_info *ipts,
  3651. + struct bin_parse_info *parse_info,
  3652. + struct ipts_bin_bufid_patch *bufid_patch)
  3653. +{
  3654. + struct ipts_bin_bufid_patch *patch;
  3655. + int size, parsed;
  3656. +
  3657. + parsed = parse_info->parsed;
  3658. + size = parse_info->size;
  3659. + patch = (struct ipts_bin_bufid_patch *)&parse_info->data[parsed];
  3660. +
  3661. + if (sizeof(struct ipts_bin_bufid_patch) > (size - parsed)) {
  3662. + ipts_dbg(ipts, "invalid bufid info\n");
  3663. + return -EINVAL;
  3664. + }
  3665. +
  3666. + parsed += sizeof(struct ipts_bin_bufid_patch);
  3667. + parse_info->parsed = parsed;
  3668. +
  3669. + memcpy(bufid_patch, patch, sizeof(struct ipts_bin_bufid_patch));
  3670. +
  3671. + return 0;
  3672. +}
  3673. +
  3674. +static int bin_setup_bufid_buffer(struct ipts_info *ipts,
  3675. + struct bin_kernel_list *kernel_list)
  3676. +{
  3677. + struct ipts_mapbuffer *buf, *cmd_buf;
  3678. + struct bin_kernel_info *last_kernel;
  3679. + struct bin_alloc_info *alloc_info;
  3680. + struct bin_workload *wl;
  3681. + u8 *batch;
  3682. + int pidx, num_of_parallels, cidx;
  3683. + u32 mem_offset, imm_offset;
  3684. +
  3685. + buf = ipts_map_buffer(ipts, PAGE_SIZE, 0);
  3686. + if (!buf)
  3687. + return -ENOMEM;
  3688. +
  3689. + last_kernel = &kernel_list->kernels[kernel_list->num_of_kernels - 1];
  3690. +
  3691. + mem_offset = last_kernel->bufid_patch.mem_offset;
  3692. + imm_offset = last_kernel->bufid_patch.imm_offset;
  3693. + wl = last_kernel->wl;
  3694. + alloc_info = last_kernel->alloc_info;
  3695. +
  3696. + // Initialize the buffer with default value
  3697. + *((u32 *)buf->cpu_addr) = LASTSUBMITID_DEFAULT_VALUE;
  3698. + ipts->current_buffer_index = LASTSUBMITID_DEFAULT_VALUE;
  3699. + ipts->last_buffer_completed = LASTSUBMITID_DEFAULT_VALUE;
  3700. + ipts->last_submitted_id = (int *)buf->cpu_addr;
  3701. +
  3702. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  3703. +
  3704. + for (pidx = 0; pidx < num_of_parallels; pidx++) {
  3705. + cidx = wl[pidx].cmdbuf_index;
  3706. + cmd_buf = alloc_info->buffs[cidx].buf;
  3707. + batch = (u8 *)(u64)cmd_buf->cpu_addr;
  3708. +
  3709. + *((u32 *)(batch + mem_offset)) = (u32)(u64)(buf->gfx_addr);
  3710. + *((u32 *)(batch + imm_offset)) = pidx;
  3711. + }
  3712. +
  3713. + kernel_list->bufid_buf = buf;
  3714. +
  3715. + return 0;
  3716. +}
  3717. +
  3718. +static void unmap_buffers(struct ipts_info *ipts,
  3719. + struct bin_alloc_info *alloc_info)
  3720. +{
  3721. + struct bin_buffer *buffs;
  3722. + int i, num_of_buffers;
  3723. +
  3724. + num_of_buffers = alloc_info->num_of_buffers;
  3725. + buffs = &alloc_info->buffs[0];
  3726. +
  3727. + for (i = 0; i < num_of_buffers; i++) {
  3728. + if (buffs[i].no_unmap != true && buffs[i].buf != NULL)
  3729. + ipts_unmap_buffer(ipts, buffs[i].buf);
  3730. + }
  3731. +}
  3732. +
  3733. +static int load_kernel(struct ipts_info *ipts,
  3734. + struct bin_parse_info *parse_info,
  3735. + struct bin_kernel_info *kernel)
  3736. +{
  3737. + struct ipts_bin_header *hdr;
  3738. + struct bin_workload *wl;
  3739. + struct bin_alloc_info *alloc_info;
  3740. + struct bin_guc_wq_item *guc_wq_item = NULL;
  3741. + struct ipts_bin_bufid_patch bufid_patch;
  3742. + int num_of_parallels, ret;
  3743. +
  3744. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  3745. +
  3746. + // check header version and magic numbers
  3747. + hdr = (struct ipts_bin_header *)parse_info->data;
  3748. + if (hdr->version != IPTS_BIN_HEADER_VERSION ||
  3749. + strncmp(hdr->str, "IOCL", 4) != 0) {
  3750. + ipts_err(ipts, "binary header is not correct version = %d, ",
  3751. + hdr->version);
  3752. +
  3753. + ipts_err(ipts, "string = %c%c%c%c\n", hdr->str[0], hdr->str[1],
  3754. + hdr->str[2], hdr->str[3]);
  3755. +
  3756. + return -EINVAL;
  3757. + }
  3758. +
  3759. + parse_info->parsed = sizeof(struct ipts_bin_header);
  3760. + wl = vmalloc(sizeof(struct bin_workload) * num_of_parallels);
  3761. +
  3762. + if (wl == NULL)
  3763. + return -ENOMEM;
  3764. +
  3765. + memset(wl, 0, sizeof(struct bin_workload) * num_of_parallels);
  3766. + alloc_info = vmalloc(sizeof(struct bin_alloc_info));
  3767. +
  3768. + if (alloc_info == NULL) {
  3769. + vfree(wl);
  3770. + return -ENOMEM;
  3771. + }
  3772. +
  3773. + memset(alloc_info, 0, sizeof(struct bin_alloc_info));
  3774. +
  3775. + ipts_dbg(ipts, "kernel setup(size : %d)\n", parse_info->size);
  3776. +
  3777. + ret = bin_read_allocation_list(ipts, parse_info, alloc_info);
  3778. + if (ret) {
  3779. + ipts_dbg(ipts, "error read_allocation_list\n");
  3780. + goto setup_error;
  3781. + }
  3782. +
  3783. + ret = bin_read_cmd_buffer(ipts, parse_info, alloc_info, wl);
  3784. + if (ret) {
  3785. + ipts_dbg(ipts, "error read_cmd_buffer\n");
  3786. + goto setup_error;
  3787. + }
  3788. +
  3789. + ret = bin_read_res_list(ipts, parse_info, alloc_info, wl);
  3790. + if (ret) {
  3791. + ipts_dbg(ipts, "error read_res_list\n");
  3792. + goto setup_error;
  3793. + }
  3794. +
  3795. + ret = bin_read_patch_list(ipts, parse_info, alloc_info, wl);
  3796. + if (ret) {
  3797. + ipts_dbg(ipts, "error read_patch_list\n");
  3798. + goto setup_error;
  3799. + }
  3800. +
  3801. + ret = bin_read_guc_wq_item(ipts, parse_info, &guc_wq_item);
  3802. + if (ret) {
  3803. + ipts_dbg(ipts, "error read_guc_workqueue\n");
  3804. + goto setup_error;
  3805. + }
  3806. +
  3807. + memset(&bufid_patch, 0, sizeof(bufid_patch));
  3808. +
  3809. + ret = bin_read_bufid_patch(ipts, parse_info, &bufid_patch);
  3810. + if (ret) {
  3811. + ipts_dbg(ipts, "error read_bufid_patch\n");
  3812. + goto setup_error;
  3813. + }
  3814. +
  3815. + kernel->wl = wl;
  3816. + kernel->alloc_info = alloc_info;
  3817. + kernel->is_vendor = is_parsing_vendor_kernel(parse_info);
  3818. + kernel->guc_wq_item = guc_wq_item;
  3819. +
  3820. + memcpy(&kernel->bufid_patch, &bufid_patch, sizeof(bufid_patch));
  3821. +
  3822. + return 0;
  3823. +
  3824. +setup_error:
  3825. + vfree(guc_wq_item);
  3826. +
  3827. + unmap_buffers(ipts, alloc_info);
  3828. +
  3829. + vfree(alloc_info->buffs);
  3830. + vfree(alloc_info);
  3831. + vfree(wl);
  3832. +
  3833. + return ret;
  3834. +}
  3835. +
  3836. +void bin_setup_input_output(struct ipts_info *ipts,
  3837. + struct bin_kernel_list *kernel_list)
  3838. +{
  3839. + struct bin_kernel_info *vendor_kernel;
  3840. + struct bin_workload *wl;
  3841. + struct ipts_mapbuffer *buf;
  3842. + struct bin_alloc_info *alloc_info;
  3843. + int pidx, num_of_parallels, i, bidx;
  3844. +
  3845. + vendor_kernel = &kernel_list->kernels[0];
  3846. +
  3847. + wl = vendor_kernel->wl;
  3848. + alloc_info = vendor_kernel->alloc_info;
  3849. + ipts->resource.num_of_outputs = alloc_info->num_of_outputs;
  3850. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  3851. +
  3852. + for (pidx = 0; pidx < num_of_parallels; pidx++) {
  3853. + bidx = wl[pidx].iobuf_input;
  3854. + buf = alloc_info->buffs[bidx].buf;
  3855. +
  3856. + ipts_dbg(ipts, "in_buf[%d](%d) c:%p, p:%p, g:%p\n",
  3857. + pidx, bidx, (void *)buf->cpu_addr,
  3858. + (void *)buf->phy_addr, (void *)buf->gfx_addr);
  3859. +
  3860. + ipts_set_input_buffer(ipts, pidx, buf->cpu_addr, buf->phy_addr);
  3861. +
  3862. + for (i = 0; i < alloc_info->num_of_outputs; i++) {
  3863. + bidx = wl[pidx].iobuf_output[i];
  3864. + buf = alloc_info->buffs[bidx].buf;
  3865. +
  3866. + ipts_dbg(ipts, "out_buf[%d][%d] c:%p, p:%p, g:%p\n",
  3867. + pidx, i, (void *)buf->cpu_addr,
  3868. + (void *)buf->phy_addr, (void *)buf->gfx_addr);
  3869. +
  3870. + ipts_set_output_buffer(ipts, pidx, i,
  3871. + buf->cpu_addr, buf->phy_addr);
  3872. + }
  3873. + }
  3874. +}
  3875. +
  3876. +static void unload_kernel(struct ipts_info *ipts,
  3877. + struct bin_kernel_info *kernel)
  3878. +{
  3879. + struct bin_alloc_info *alloc_info = kernel->alloc_info;
  3880. + struct bin_guc_wq_item *guc_wq_item = kernel->guc_wq_item;
  3881. +
  3882. + if (guc_wq_item)
  3883. + vfree(guc_wq_item);
  3884. +
  3885. + if (alloc_info) {
  3886. + unmap_buffers(ipts, alloc_info);
  3887. +
  3888. + vfree(alloc_info->buffs);
  3889. + vfree(alloc_info);
  3890. + }
  3891. +}
  3892. +
  3893. +static int setup_kernel(struct ipts_info *ipts,
  3894. + struct ipts_bin_fw_list *fw_list)
  3895. +{
  3896. + struct bin_kernel_list *kernel_list = NULL;
  3897. + struct bin_kernel_info *kernel = NULL;
  3898. + const struct firmware *fw = NULL;
  3899. + struct bin_workload *wl;
  3900. + struct ipts_bin_fw_info *fw_info;
  3901. + char *fw_name, *fw_data;
  3902. + struct bin_parse_info parse_info;
  3903. + int ret = 0, kidx = 0, num_of_kernels = 0;
  3904. + int vidx, total_workload = 0;
  3905. +
  3906. + num_of_kernels = fw_list->num_of_fws;
  3907. + kernel_list = vmalloc(sizeof(*kernel) *
  3908. + num_of_kernels + sizeof(*kernel_list));
  3909. +
  3910. + if (kernel_list == NULL)
  3911. + return -ENOMEM;
  3912. +
  3913. + memset(kernel_list, 0, sizeof(*kernel) *
  3914. + num_of_kernels + sizeof(*kernel_list));
  3915. +
  3916. + kernel_list->num_of_kernels = num_of_kernels;
  3917. + kernel = &kernel_list->kernels[0];
  3918. +
  3919. + fw_data = (char *)&fw_list->fw_info[0];
  3920. + for (kidx = 0; kidx < num_of_kernels; kidx++) {
  3921. + fw_info = (struct ipts_bin_fw_info *)fw_data;
  3922. + fw_name = &fw_info->fw_name[0];
  3923. + vidx = fw_info->vendor_output;
  3924. +
  3925. + ret = ipts_request_firmware(&fw, fw_name, &ipts->cldev->dev);
  3926. + if (ret) {
  3927. + ipts_err(ipts, "cannot read fw %s\n", fw_name);
  3928. + goto error_exit;
  3929. + }
  3930. +
  3931. + parse_info.data = (u8 *)fw->data;
  3932. + parse_info.size = fw->size;
  3933. + parse_info.parsed = 0;
  3934. + parse_info.fw_info = fw_info;
  3935. + parse_info.vendor_kernel = (kidx == 0) ? NULL : &kernel[0];
  3936. + parse_info.interested_vendor_output = vidx;
  3937. +
  3938. + ret = load_kernel(ipts, &parse_info, &kernel[kidx]);
  3939. + if (ret) {
  3940. + ipts_err(ipts, "do_setup_kernel error : %d\n", ret);
  3941. + release_firmware(fw);
  3942. + goto error_exit;
  3943. + }
  3944. +
  3945. + release_firmware(fw);
  3946. +
  3947. + total_workload += kernel[kidx].guc_wq_item->size;
  3948. +
  3949. + // advance to the next kernel
  3950. + fw_data += sizeof(struct ipts_bin_fw_info);
  3951. + fw_data += sizeof(struct ipts_bin_data_file_info) *
  3952. + fw_info->num_of_data_files;
  3953. + }
  3954. +
  3955. + ipts_set_wq_item_size(ipts, total_workload);
  3956. +
  3957. + ret = bin_setup_guc_workqueue(ipts, kernel_list);
  3958. + if (ret) {
  3959. + ipts_dbg(ipts, "error setup_guc_workqueue\n");
  3960. + goto error_exit;
  3961. + }
  3962. +
  3963. + ret = bin_setup_bufid_buffer(ipts, kernel_list);
  3964. + if (ret) {
  3965. + ipts_dbg(ipts, "error setup_lastbubmit_buffer\n");
  3966. + goto error_exit;
  3967. + }
  3968. +
  3969. + bin_setup_input_output(ipts, kernel_list);
  3970. +
  3971. + // workload is not needed during run-time so free them
  3972. + for (kidx = 0; kidx < num_of_kernels; kidx++) {
  3973. + wl = kernel[kidx].wl;
  3974. + vfree(wl);
  3975. + }
  3976. +
  3977. + ipts->kernel_handle = (u64)kernel_list;
  3978. +
  3979. + return 0;
  3980. +
  3981. +error_exit:
  3982. +
  3983. + for (kidx = 0; kidx < num_of_kernels; kidx++) {
  3984. + wl = kernel[kidx].wl;
  3985. + vfree(wl);
  3986. + unload_kernel(ipts, &kernel[kidx]);
  3987. + }
  3988. +
  3989. + vfree(kernel_list);
  3990. +
  3991. + return ret;
  3992. +}
  3993. +
  3994. +
  3995. +static void release_kernel(struct ipts_info *ipts)
  3996. +{
  3997. + struct bin_kernel_list *kernel_list;
  3998. + struct bin_kernel_info *kernel;
  3999. + int kidx, knum;
  4000. +
  4001. + kernel_list = (struct bin_kernel_list *)ipts->kernel_handle;
  4002. + knum = kernel_list->num_of_kernels;
  4003. + kernel = &kernel_list->kernels[0];
  4004. +
  4005. + for (kidx = 0; kidx < knum; kidx++) {
  4006. + unload_kernel(ipts, kernel);
  4007. + kernel++;
  4008. + }
  4009. +
  4010. + ipts_unmap_buffer(ipts, kernel_list->bufid_buf);
  4011. +
  4012. + vfree(kernel_list);
  4013. + ipts->kernel_handle = 0;
  4014. +}
  4015. +
  4016. +int ipts_init_kernels(struct ipts_info *ipts)
  4017. +{
  4018. + struct ipts_bin_fw_list *fw_list;
  4019. + int ret;
  4020. +
  4021. + ret = ipts_open_gpu(ipts);
  4022. + if (ret) {
  4023. + ipts_err(ipts, "open gpu error : %d\n", ret);
  4024. + return ret;
  4025. + }
  4026. +
  4027. + ret = ipts_request_firmware_config(ipts, &fw_list);
  4028. + if (ret) {
  4029. + ipts_err(ipts, "request firmware config error : %d\n", ret);
  4030. + goto close_gpu;
  4031. + }
  4032. +
  4033. + ret = setup_kernel(ipts, fw_list);
  4034. + if (ret) {
  4035. + ipts_err(ipts, "setup kernel error : %d\n", ret);
  4036. + goto close_gpu;
  4037. + }
  4038. +
  4039. + return ret;
  4040. +
  4041. +close_gpu:
  4042. + ipts_close_gpu(ipts);
  4043. +
  4044. + return ret;
  4045. +}
  4046. +
  4047. +void ipts_release_kernels(struct ipts_info *ipts)
  4048. +{
  4049. + release_kernel(ipts);
  4050. + ipts_close_gpu(ipts);
  4051. +}
  4052. diff --git a/drivers/misc/ipts/kernel.h b/drivers/misc/ipts/kernel.h
  4053. new file mode 100644
  4054. index 000000000000..7be45da01cfc
  4055. --- /dev/null
  4056. +++ b/drivers/misc/ipts/kernel.h
  4057. @@ -0,0 +1,17 @@
  4058. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  4059. +/*
  4060. + *
  4061. + * Intel Precise Touch & Stylus
  4062. + * Copyright (c) 2016 Intel Corporation
  4063. + *
  4064. + */
  4065. +
  4066. +#ifndef _IPTS_KERNEL_H_
  4067. +#define _IPTS_KERNEL_H_
  4068. +
  4069. +#include "ipts.h"
  4070. +
  4071. +int ipts_init_kernels(struct ipts_info *ipts);
  4072. +void ipts_release_kernels(struct ipts_info *ipts);
  4073. +
  4074. +#endif // _IPTS_KERNEL_H_
  4075. diff --git a/drivers/misc/ipts/mei-msgs.h b/drivers/misc/ipts/mei-msgs.h
  4076. new file mode 100644
  4077. index 000000000000..036b74f7234e
  4078. --- /dev/null
  4079. +++ b/drivers/misc/ipts/mei-msgs.h
  4080. @@ -0,0 +1,901 @@
  4081. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  4082. +/*
  4083. + *
  4084. + * Intel Precise Touch & Stylus
  4085. + * Copyright (c) 2013-2016 Intel Corporation
  4086. + *
  4087. + */
  4088. +
  4089. +#ifndef _IPTS_MEI_MSGS_H_
  4090. +#define _IPTS_MEI_MSGS_H_
  4091. +
  4092. +#include <linux/build_bug.h>
  4093. +
  4094. +#include "sensor-regs.h"
  4095. +
  4096. +#pragma pack(1)
  4097. +
  4098. +// Define static_assert macro (which will be available after 5.1
  4099. +// and not available on 4.19 yet) to check structure size and fail
  4100. +// compile for unexpected mismatch.
  4101. +// Taken from upstream commit 6bab69c65013bed5fce9f101a64a84d0385b3946.
  4102. +#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
  4103. +#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
  4104. +
  4105. +// Initial protocol version
  4106. +#define TOUCH_HECI_CLIENT_PROTOCOL_VERSION 10
  4107. +
  4108. +// GUID that identifies the Touch HECI client.
  4109. +#define TOUCH_HECI_CLIENT_GUID \
  4110. + {0x3e8d0870, 0x271a, 0x4208, \
  4111. + {0x8e, 0xb5, 0x9a, 0xcb, 0x94, 0x02, 0xae, 0x04} }
  4112. +
  4113. +#define TOUCH_SENSOR_GET_DEVICE_INFO_CMD 0x00000001
  4114. +#define TOUCH_SENSOR_GET_DEVICE_INFO_RSP 0x80000001
  4115. +
  4116. +#define TOUCH_SENSOR_SET_MODE_CMD 0x00000002
  4117. +#define TOUCH_SENSOR_SET_MODE_RSP 0x80000002
  4118. +
  4119. +#define TOUCH_SENSOR_SET_MEM_WINDOW_CMD 0x00000003
  4120. +#define TOUCH_SENSOR_SET_MEM_WINDOW_RSP 0x80000003
  4121. +
  4122. +#define TOUCH_SENSOR_QUIESCE_IO_CMD 0x00000004
  4123. +#define TOUCH_SENSOR_QUIESCE_IO_RSP 0x80000004
  4124. +
  4125. +#define TOUCH_SENSOR_HID_READY_FOR_DATA_CMD 0x00000005
  4126. +#define TOUCH_SENSOR_HID_READY_FOR_DATA_RSP 0x80000005
  4127. +
  4128. +#define TOUCH_SENSOR_FEEDBACK_READY_CMD 0x00000006
  4129. +#define TOUCH_SENSOR_FEEDBACK_READY_RSP 0x80000006
  4130. +
  4131. +#define TOUCH_SENSOR_CLEAR_MEM_WINDOW_CMD 0x00000007
  4132. +#define TOUCH_SENSOR_CLEAR_MEM_WINDOW_RSP 0x80000007
  4133. +
  4134. +#define TOUCH_SENSOR_NOTIFY_DEV_READY_CMD 0x00000008
  4135. +#define TOUCH_SENSOR_NOTIFY_DEV_READY_RSP 0x80000008
  4136. +
  4137. +#define TOUCH_SENSOR_SET_POLICIES_CMD 0x00000009
  4138. +#define TOUCH_SENSOR_SET_POLICIES_RSP 0x80000009
  4139. +
  4140. +#define TOUCH_SENSOR_GET_POLICIES_CMD 0x0000000A
  4141. +#define TOUCH_SENSOR_GET_POLICIES_RSP 0x8000000A
  4142. +
  4143. +#define TOUCH_SENSOR_RESET_CMD 0x0000000B
  4144. +#define TOUCH_SENSOR_RESET_RSP 0x8000000B
  4145. +
  4146. +#define TOUCH_SENSOR_READ_ALL_REGS_CMD 0x0000000C
  4147. +#define TOUCH_SENSOR_READ_ALL_REGS_RSP 0x8000000C
  4148. +
  4149. +// ME sends this message to indicate previous command was unrecognized
  4150. +#define TOUCH_SENSOR_CMD_ERROR_RSP 0x8FFFFFFF
  4151. +
  4152. +#define TOUCH_SENSOR_MAX_DATA_BUFFERS 16
  4153. +#define TOUCH_HID_2_ME_BUFFER_ID TOUCH_SENSOR_MAX_DATA_BUFFERS
  4154. +#define TOUCH_HID_2_ME_BUFFER_SIZE_MAX 1024
  4155. +#define TOUCH_INVALID_BUFFER_ID 0xFF
  4156. +
  4157. +#define TOUCH_DEFAULT_DOZE_TIMER_SECONDS 30
  4158. +
  4159. +#define TOUCH_MSG_SIZE_MAX_BYTES \
  4160. + (MAX(sizeof(struct touch_sensor_msg_m2h), \
  4161. + sizeof(struct touch_sensor_msg_h2m)))
  4162. +
  4163. +// indicates GuC got reset and ME must re-read GuC data such as
  4164. +// TailOffset and Doorbell Cookie values
  4165. +#define TOUCH_SENSOR_QUIESCE_FLAG_GUC_RESET BIT(0)
  4166. +
  4167. +/*
  4168. + * Debug Policy bits used by TOUCH_POLICY_DATA.DebugOverride
  4169. + */
  4170. +
  4171. +// Disable sensor startup timer
  4172. +#define TOUCH_DBG_POLICY_OVERRIDE_STARTUP_TIMER_DIS BIT(0)
  4173. +
  4174. +// Disable Sync Byte check
  4175. +#define TOUCH_DBG_POLICY_OVERRIDE_SYNC_BYTE_DIS BIT(1)
  4176. +
  4177. +// Disable error resets
  4178. +#define TOUCH_DBG_POLICY_OVERRIDE_ERR_RESET_DIS BIT(2)
  4179. +
  4180. +/*
  4181. + * Touch Sensor Status Codes
  4182. + */
  4183. +enum touch_status {
  4184. + // Requested operation was successful
  4185. + TOUCH_STATUS_SUCCESS = 0,
  4186. +
  4187. + // Invalid parameter(s) sent
  4188. + TOUCH_STATUS_INVALID_PARAMS,
  4189. +
  4190. + // Unable to validate address range
  4191. + TOUCH_STATUS_ACCESS_DENIED,
  4192. +
  4193. + // HECI message incorrect size for specified command
  4194. + TOUCH_STATUS_CMD_SIZE_ERROR,
  4195. +
  4196. + // Memory window not set or device is not armed for operation
  4197. + TOUCH_STATUS_NOT_READY,
  4198. +
  4199. + // There is already an outstanding message of the same type, must
  4200. + // wait for response before sending another request of that type
  4201. + TOUCH_STATUS_REQUEST_OUTSTANDING,
  4202. +
  4203. + // Sensor could not be found. Either no sensor is connected,
  4204. + // the sensor has not yet initialized, or the system is
  4205. + // improperly configured.
  4206. + TOUCH_STATUS_NO_SENSOR_FOUND,
  4207. +
  4208. + // Not enough memory/storage for requested operation
  4209. + TOUCH_STATUS_OUT_OF_MEMORY,
  4210. +
  4211. + // Unexpected error occurred
  4212. + TOUCH_STATUS_INTERNAL_ERROR,
  4213. +
  4214. + // Used in TOUCH_SENSOR_HID_READY_FOR_DATA_RSP to indicate sensor
  4215. + // has been disabled or reset and must be reinitialized.
  4216. + TOUCH_STATUS_SENSOR_DISABLED,
  4217. +
  4218. + // Used to indicate compatibility revision check between sensor and ME
  4219. + // failed, or protocol ver between ME/HID/Kernels failed.
  4220. + TOUCH_STATUS_COMPAT_CHECK_FAIL,
  4221. +
  4222. + // Indicates sensor went through a reset initiated by ME
  4223. + TOUCH_STATUS_SENSOR_EXPECTED_RESET,
  4224. +
  4225. + // Indicates sensor went through an unexpected reset
  4226. + TOUCH_STATUS_SENSOR_UNEXPECTED_RESET,
  4227. +
  4228. + // Requested sensor reset failed to complete
  4229. + TOUCH_STATUS_RESET_FAILED,
  4230. +
  4231. + // Operation timed out
  4232. + TOUCH_STATUS_TIMEOUT,
  4233. +
  4234. + // Test mode pattern did not match expected values
  4235. + TOUCH_STATUS_TEST_MODE_FAIL,
  4236. +
  4237. + // Indicates sensor reported fatal error during reset sequence.
  4238. + // Further progress is not possible.
  4239. + TOUCH_STATUS_SENSOR_FAIL_FATAL,
  4240. +
  4241. + // Indicates sensor reported non-fatal error during reset sequence.
  4242. + // HID/BIOS logs error and attempts to continue.
  4243. + TOUCH_STATUS_SENSOR_FAIL_NONFATAL,
  4244. +
  4245. + // Indicates sensor reported invalid capabilities, such as not
  4246. + // supporting required minimum frequency or I/O mode.
  4247. + TOUCH_STATUS_INVALID_DEVICE_CAPS,
  4248. +
  4249. + // Indicates that command cannot be complete until ongoing Quiesce I/O
  4250. + // flow has completed.
  4251. + TOUCH_STATUS_QUIESCE_IO_IN_PROGRESS,
  4252. +
  4253. + // Invalid value, never returned
  4254. + TOUCH_STATUS_MAX
  4255. +};
  4256. +static_assert(sizeof(enum touch_status) == 4);
  4257. +
  4258. +/*
  4259. + * Defines for message structures used for Host to ME communication
  4260. + */
  4261. +enum touch_sensor_mode {
  4262. + // Set mode to HID mode
  4263. + TOUCH_SENSOR_MODE_HID = 0,
  4264. +
  4265. + // Set mode to Raw Data mode
  4266. + TOUCH_SENSOR_MODE_RAW_DATA,
  4267. +
  4268. + // Used like TOUCH_SENSOR_MODE_HID but data coming from sensor is
  4269. + // not necessarily a HID packet.
  4270. + TOUCH_SENSOR_MODE_SENSOR_DEBUG = 4,
  4271. +
  4272. + // Invalid value
  4273. + TOUCH_SENSOR_MODE_MAX
  4274. +};
  4275. +static_assert(sizeof(enum touch_sensor_mode) == 4);
  4276. +
  4277. +struct touch_sensor_set_mode_cmd_data {
  4278. + // Indicate desired sensor mode
  4279. + enum touch_sensor_mode sensor_mode;
  4280. +
  4281. + // For future expansion
  4282. + u32 Reserved[3];
  4283. +};
  4284. +static_assert(sizeof(struct touch_sensor_set_mode_cmd_data) == 16);
  4285. +
  4286. +struct touch_sensor_set_mem_window_cmd_data {
  4287. + // Lower 32 bits of Touch Data Buffer physical address. Size of each
  4288. + // buffer should be TOUCH_SENSOR_GET_DEVICE_INFO_RSP_DATA.FrameSize
  4289. + u32 touch_data_buffer_addr_lower[TOUCH_SENSOR_MAX_DATA_BUFFERS];
  4290. +
  4291. + // Upper 32 bits of Touch Data Buffer physical address. Size of each
  4292. + // buffer should be TOUCH_SENSOR_GET_DEVICE_INFO_RSP_DATA.FrameSize
  4293. + u32 touch_data_buffer_addr_upper[TOUCH_SENSOR_MAX_DATA_BUFFERS];
  4294. +
  4295. + // Lower 32 bits of Tail Offset physical address
  4296. + u32 tail_offset_addr_lower;
  4297. +
  4298. + // Upper 32 bits of Tail Offset physical address, always 32 bit,
  4299. + // increment by WorkQueueItemSize
  4300. + u32 tail_offset_addr_upper;
  4301. +
  4302. + // Lower 32 bits of Doorbell register physical address
  4303. + u32 doorbell_cookie_addr_lower;
  4304. +
  4305. + // Upper 32 bits of Doorbell register physical address, always 32 bit,
  4306. + // increment as integer, rollover to 1
  4307. + u32 doorbell_cookie_addr_upper;
  4308. +
  4309. + // Lower 32 bits of Feedback Buffer physical address. Size of each
  4310. + // buffer should be TOUCH_SENSOR_GET_DEVICE_INFO_RSP_DATA.FeedbackSize
  4311. + u32 feedback_buffer_addr_lower[TOUCH_SENSOR_MAX_DATA_BUFFERS];
  4312. +
  4313. + // Upper 32 bits of Feedback Buffer physical address. Size of each
  4314. + // buffer should be TOUCH_SENSOR_GET_DEVICE_INFO_RSP_DATA.FeedbackSize
  4315. + u32 feedback_buffer_addr_upper[TOUCH_SENSOR_MAX_DATA_BUFFERS];
  4316. +
  4317. + // Lower 32 bits of dedicated HID to ME communication buffer.
  4318. + // Size is Hid2MeBufferSize.
  4319. + u32 hid2me_buffer_addr_lower;
  4320. +
  4321. + // Upper 32 bits of dedicated HID to ME communication buffer.
  4322. + // Size is Hid2MeBufferSize.
  4323. + u32 hid2me_buffer_addr_upper;
  4324. +
  4325. + // Size in bytes of Hid2MeBuffer, can be no bigger than
  4326. + // TOUCH_HID_2_ME_BUFFER_SIZE_MAX
  4327. + u32 hid2me_buffer_size;
  4328. +
  4329. + // For future expansion
  4330. + u8 reserved1;
  4331. +
  4332. + // Size in bytes of the GuC Work Queue Item pointed to by TailOffset
  4333. + u8 work_queue_item_size;
  4334. +
  4335. + // Size in bytes of the entire GuC Work Queue
  4336. + u16 work_queue_size;
  4337. +
  4338. + // For future expansion
  4339. + u32 reserved[8];
  4340. +};
  4341. +static_assert(sizeof(struct touch_sensor_set_mem_window_cmd_data) == 320);
  4342. +
  4343. +struct touch_sensor_quiesce_io_cmd_data {
  4344. + // Optionally set TOUCH_SENSOR_QUIESCE_FLAG_GUC_RESET
  4345. + u32 quiesce_flags;
  4346. + u32 reserved[2];
  4347. +};
  4348. +static_assert(sizeof(struct touch_sensor_quiesce_io_cmd_data) == 12);
  4349. +
  4350. +struct touch_sensor_feedback_ready_cmd_data {
  4351. + // Index value from 0 to TOUCH_HID_2_ME_BUFFER_ID used to indicate
  4352. + // which Feedback Buffer to use. Using special value
  4353. + // TOUCH_HID_2_ME_BUFFER_ID is an indication to ME to
  4354. + // get feedback data from the Hid2Me buffer instead of one
  4355. + // of the standard Feedback buffers.
  4356. + u8 feedback_index;
  4357. +
  4358. + // For future expansion
  4359. + u8 reserved1[3];
  4360. +
  4361. + // Transaction ID that was originally passed to host in
  4362. + // TOUCH_HID_PRIVATE_DATA. Used to track round trip of a given
  4363. + // transaction for performance measurements.
  4364. + u32 transaction_id;
  4365. +
  4366. + // For future expansion
  4367. + u32 reserved2[2];
  4368. +};
  4369. +static_assert(sizeof(struct touch_sensor_feedback_ready_cmd_data) == 16);
  4370. +
  4371. +enum touch_freq_override {
  4372. + // Do not apply any override
  4373. + TOUCH_FREQ_OVERRIDE_NONE,
  4374. +
  4375. + // Force frequency to 10MHz (not currently supported)
  4376. + TOUCH_FREQ_OVERRIDE_10MHZ,
  4377. +
  4378. + // Force frequency to 17MHz
  4379. + TOUCH_FREQ_OVERRIDE_17MHZ,
  4380. +
  4381. + // Force frequency to 30MHz
  4382. + TOUCH_FREQ_OVERRIDE_30MHZ,
  4383. +
  4384. + // Force frequency to 50MHz (not currently supported)
  4385. + TOUCH_FREQ_OVERRIDE_50MHZ,
  4386. +
  4387. + // Invalid value
  4388. + TOUCH_FREQ_OVERRIDE_MAX
  4389. +};
  4390. +static_assert(sizeof(enum touch_freq_override) == 4);
  4391. +
  4392. +enum touch_spi_io_mode_override {
  4393. + // Do not apply any override
  4394. + TOUCH_SPI_IO_MODE_OVERRIDE_NONE,
  4395. +
  4396. + // Force Single I/O
  4397. + TOUCH_SPI_IO_MODE_OVERRIDE_SINGLE,
  4398. +
  4399. + // Force Dual I/O
  4400. + TOUCH_SPI_IO_MODE_OVERRIDE_DUAL,
  4401. +
  4402. + // Force Quad I/O
  4403. + TOUCH_SPI_IO_MODE_OVERRIDE_QUAD,
  4404. +
  4405. + // Invalid value
  4406. + TOUCH_SPI_IO_MODE_OVERRIDE_MAX
  4407. +};
  4408. +static_assert(sizeof(enum touch_spi_io_mode_override) == 4);
  4409. +
  4410. +struct touch_policy_data {
  4411. + // For future expansion.
  4412. + u32 reserved0;
  4413. +
  4414. + // Value in seconds, after which ME will put the sensor into Doze power
  4415. + // state if no activity occurs. Set to 0 to disable Doze mode
  4416. + // (not recommended). Value will be set to
  4417. + // TOUCH_DEFAULT_DOZE_TIMER_SECONDS by default
  4418. + u32 doze_timer:16;
  4419. +
  4420. + // Override frequency requested by sensor
  4421. + enum touch_freq_override freq_override:3;
  4422. +
  4423. + // Override IO mode requested by sensor
  4424. + enum touch_spi_io_mode_override spi_io_override :3;
  4425. +
  4426. + // For future expansion
  4427. + u32 reserved1:10;
  4428. +
  4429. + // For future expansion
  4430. + u32 reserved2;
  4431. +
  4432. + // Normally all bits will be zero. Bits will be defined as needed
  4433. + // for enabling special debug features
  4434. + u32 debug_override;
  4435. +};
  4436. +static_assert(sizeof(struct touch_policy_data) == 16);
  4437. +
  4438. +struct touch_sensor_set_policies_cmd_data {
  4439. + // Contains the desired policy to be set
  4440. + struct touch_policy_data policy_data;
  4441. +};
  4442. +static_assert(sizeof(struct touch_sensor_set_policies_cmd_data) == 16);
  4443. +
  4444. +enum touch_sensor_reset_type {
  4445. + // Hardware Reset using dedicated GPIO pin
  4446. + TOUCH_SENSOR_RESET_TYPE_HARD,
  4447. +
  4448. + // Software Reset using command written over SPI interface
  4449. + TOUCH_SENSOR_RESET_TYPE_SOFT,
  4450. +
  4451. + // Invalid value
  4452. + TOUCH_SENSOR_RESET_TYPE_MAX
  4453. +};
  4454. +static_assert(sizeof(enum touch_sensor_reset_type) == 4);
  4455. +
  4456. +struct touch_sensor_reset_cmd_data {
  4457. + // Indicate desired reset type
  4458. + enum touch_sensor_reset_type reset_type;
  4459. +
  4460. + // For future expansion
  4461. + u32 reserved;
  4462. +};
  4463. +static_assert(sizeof(struct touch_sensor_reset_cmd_data) == 8);
  4464. +
  4465. +/*
  4466. + * Host to ME message
  4467. + */
  4468. +union touch_sensor_data_h2m {
  4469. + struct touch_sensor_set_mode_cmd_data set_mode_cmd_data;
  4470. + struct touch_sensor_set_mem_window_cmd_data set_window_cmd_data;
  4471. + struct touch_sensor_quiesce_io_cmd_data quiesce_io_cmd_data;
  4472. + struct touch_sensor_feedback_ready_cmd_data feedback_ready_cmd_data;
  4473. + struct touch_sensor_set_policies_cmd_data set_policies_cmd_data;
  4474. + struct touch_sensor_reset_cmd_data reset_cmd_data;
  4475. +};
  4476. +struct touch_sensor_msg_h2m {
  4477. + u32 command_code;
  4478. + union touch_sensor_data_h2m h2m_data;
  4479. +};
  4480. +static_assert(sizeof(struct touch_sensor_msg_h2m) == 324);
  4481. +
  4482. +/*
  4483. + * Message structures used for ME to Host communication
  4484. + */
  4485. +
  4486. +// I/O mode values used by TOUCH_SENSOR_GET_DEVICE_INFO_RSP_DATA.
  4487. +enum touch_spi_io_mode {
  4488. + // Sensor set for Single I/O SPI
  4489. + TOUCH_SPI_IO_MODE_SINGLE = 0,
  4490. +
  4491. + // Sensor set for Dual I/O SPI
  4492. + TOUCH_SPI_IO_MODE_DUAL,
  4493. +
  4494. + // Sensor set for Quad I/O SPI
  4495. + TOUCH_SPI_IO_MODE_QUAD,
  4496. +
  4497. + // Invalid value
  4498. + TOUCH_SPI_IO_MODE_MAX
  4499. +};
  4500. +static_assert(sizeof(enum touch_spi_io_mode) == 4);
  4501. +
  4502. +/*
  4503. + * TOUCH_SENSOR_GET_DEVICE_INFO_RSP code is sent in response to
  4504. + * TOUCH_SENSOR_GET_DEVICE_INFO_CMD. This code will be followed by
  4505. + * TOUCH_SENSOR_GET_DEVICE_INFO_RSP_DATA.
  4506. + *
  4507. + * Possible Status values:
  4508. + * TOUCH_STATUS_SUCCESS:
  4509. + * Command was processed successfully and sensor
  4510. + * details are reported.
  4511. + *
  4512. + * TOUCH_STATUS_CMD_SIZE_ERROR:
  4513. + * Command sent did not match expected size. Other fields will
  4514. + * not contain valid data.
  4515. + *
  4516. + * TOUCH_STATUS_NO_SENSOR_FOUND:
  4517. + * Sensor has not yet been detected. Other fields will
  4518. + * not contain valid data.
  4519. + *
  4520. + * TOUCH_STATUS_INVALID_DEVICE_CAPS:
  4521. + * Indicates sensor does not support minimum required Frequency
  4522. + * or I/O Mode. ME firmware will choose best possible option for
  4523. + * the errant field. Caller should attempt to continue.
  4524. + *
  4525. + * TOUCH_STATUS_COMPAT_CHECK_FAIL:
  4526. + * Indicates TouchIC/ME compatibility mismatch. Caller should
  4527. + * attempt to continue.
  4528. + */
  4529. +struct touch_sensor_get_device_info_rsp_data {
  4530. + // Touch Sensor vendor ID
  4531. + u16 vendor_id;
  4532. +
  4533. + // Touch Sensor device ID
  4534. + u16 device_id;
  4535. +
  4536. + // Touch Sensor Hardware Revision
  4537. + u32 hw_rev;
  4538. +
  4539. + // Touch Sensor Firmware Revision
  4540. + u32 fw_rev;
  4541. +
  4542. + // Max size of one frame returned by Touch IC in bytes. This data
  4543. + // will be TOUCH_RAW_DATA_HDR followed by a payload. The payload can be
  4544. + // raw data or a HID structure depending on mode.
  4545. + u32 frame_size;
  4546. +
  4547. + // Max size of one Feedback structure in bytes
  4548. + u32 feedback_size;
  4549. +
  4550. + // Current operating mode of the sensor
  4551. + enum touch_sensor_mode sensor_mode;
  4552. +
  4553. + // Maximum number of simultaneous touch points that
  4554. + // can be reported by sensor
  4555. + u32 max_touch_points:8;
  4556. +
  4557. + // SPI bus Frequency supported by sensor and ME firmware
  4558. + enum touch_freq spi_frequency:8;
  4559. +
  4560. + // SPI bus I/O Mode supported by sensor and ME firmware
  4561. + enum touch_spi_io_mode spi_io_mode:8;
  4562. +
  4563. + // For future expansion
  4564. + u32 reserved0:8;
  4565. +
  4566. + // Minor version number of EDS spec supported by
  4567. + // sensor (from Compat Rev ID Reg)
  4568. + u8 sensor_minor_eds_rev;
  4569. +
  4570. + // Major version number of EDS spec supported by
  4571. + // sensor (from Compat Rev ID Reg)
  4572. + u8 sensor_major_eds_rev;
  4573. +
  4574. + // Minor version number of EDS spec supported by ME
  4575. + u8 me_minor_eds_rev;
  4576. +
  4577. + // Major version number of EDS spec supported by ME
  4578. + u8 me_major_eds_rev;
  4579. +
  4580. + // EDS Interface Revision Number supported by
  4581. + // sensor (from Compat Rev ID Reg)
  4582. + u8 sensor_eds_intf_rev;
  4583. +
  4584. + // EDS Interface Revision Number supported by ME
  4585. + u8 me_eds_intf_rev;
  4586. +
  4587. + // EU Kernel Compatibility Version (from Compat Rev ID Reg)
  4588. + u8 kernel_compat_ver;
  4589. +
  4590. + // For future expansion
  4591. + u8 reserved1;
  4592. +
  4593. + // For future expansion
  4594. + u32 reserved2[2];
  4595. +};
  4596. +static_assert(sizeof(struct touch_sensor_get_device_info_rsp_data) == 44);
  4597. +
  4598. +/*
  4599. + * TOUCH_SENSOR_SET_MODE_RSP code is sent in response to
  4600. + * TOUCH_SENSOR_SET_MODE_CMD. This code will be followed by
  4601. + * TOUCH_SENSOR_SET_MODE_RSP_DATA.
  4602. + *
  4603. + * Possible Status values:
  4604. + * TOUCH_STATUS_SUCCESS:
  4605. + * Command was processed successfully and mode was set.
  4606. + *
  4607. + * TOUCH_STATUS_CMD_SIZE_ERROR:
  4608. + * Command sent did not match expected size. Other fields will
  4609. + * not contain valid data.
  4610. + *
  4611. + * TOUCH_STATUS_INVALID_PARAMS:
  4612. + * Input parameters are out of range.
  4613. + */
  4614. +struct touch_sensor_set_mode_rsp_data {
  4615. + // For future expansion
  4616. + u32 reserved[3];
  4617. +};
  4618. +static_assert(sizeof(struct touch_sensor_set_mode_rsp_data) == 12);
  4619. +
  4620. +/*
  4621. + * TOUCH_SENSOR_SET_MEM_WINDOW_RSP code is sent in response to
  4622. + * TOUCH_SENSOR_SET_MEM_WINDOW_CMD. This code will be followed
  4623. + * by TOUCH_SENSOR_SET_MEM_WINDOW_RSP_DATA.
  4624. + *
  4625. + * Possible Status values:
  4626. + * TOUCH_STATUS_SUCCESS:
  4627. + * Command was processed successfully and memory window was set.
  4628. + *
  4629. + * TOUCH_STATUS_CMD_SIZE_ERROR:
  4630. + * Command sent did not match expected size. Other fields will
  4631. + * not contain valid data.
  4632. + *
  4633. + * TOUCH_STATUS_INVALID_PARAMS:
  4634. + * Input parameters are out of range.
  4635. + *
  4636. + * TOUCH_STATUS_ACCESS_DENIED:
  4637. + * Unable to map host address ranges for DMA.
  4638. + *
  4639. + * TOUCH_STATUS_OUT_OF_MEMORY:
  4640. + * Unable to allocate enough space for needed buffers.
  4641. + */
  4642. +struct touch_sensor_set_mem_window_rsp_data {
  4643. + // For future expansion
  4644. + u32 reserved[3];
  4645. +};
  4646. +static_assert(sizeof(struct touch_sensor_set_mem_window_rsp_data) == 12);
  4647. +
  4648. +/*
  4649. + * TOUCH_SENSOR_QUIESCE_IO_RSP code is sent in response to
  4650. + * TOUCH_SENSOR_QUIESCE_IO_CMD. This code will be followed
  4651. + * by TOUCH_SENSOR_QUIESCE_IO_RSP_DATA.
  4652. + *
  4653. + * Possible Status values:
  4654. + * TOUCH_STATUS_SUCCESS:
  4655. + * Command was processed successfully and touch flow has stopped.
  4656. + *
  4657. + * TOUCH_STATUS_CMD_SIZE_ERROR:
  4658. + * Command sent did not match expected size. Other fields will
  4659. + * not contain valid data.
  4660. + *
  4661. + * TOUCH_STATUS_QUIESCE_IO_IN_PROGRESS:
  4662. + * Indicates that Quiesce I/O is already in progress and this
  4663. + * command cannot be accepted at this time.
  4664. + *
  4665. + * TOUCH_STATIS_TIMEOUT:
  4666. + * Indicates ME timed out waiting for Quiesce I/O flow to complete.
  4667. + */
  4668. +struct touch_sensor_quiesce_io_rsp_data {
  4669. + // For future expansion
  4670. + u32 reserved[3];
  4671. +};
  4672. +static_assert(sizeof(struct touch_sensor_quiesce_io_rsp_data) == 12);
  4673. +
  4674. +// Reset Reason values used in TOUCH_SENSOR_HID_READY_FOR_DATA_RSP_DATA
  4675. +enum touch_reset_reason {
  4676. + // Reason for sensor reset is not known
  4677. + TOUCH_RESET_REASON_UNKNOWN = 0,
  4678. +
  4679. + // Reset was requested as part of TOUCH_SENSOR_FEEDBACK_READY_CMD
  4680. + TOUCH_RESET_REASON_FEEDBACK_REQUEST,
  4681. +
  4682. + // Reset was requested via TOUCH_SENSOR_RESET_CMD
  4683. + TOUCH_RESET_REASON_HECI_REQUEST,
  4684. +
  4685. + TOUCH_RESET_REASON_MAX
  4686. +};
  4687. +static_assert(sizeof(enum touch_reset_reason) == 4);
  4688. +
  4689. +/*
  4690. + * TOUCH_SENSOR_HID_READY_FOR_DATA_RSP code is sent in response to
  4691. + * TOUCH_SENSOR_HID_READY_FOR_DATA_CMD. This code will be followed
  4692. + * by TOUCH_SENSOR_HID_READY_FOR_DATA_RSP_DATA.
  4693. + *
  4694. + * Possible Status values:
  4695. + * TOUCH_STATUS_SUCCESS:
  4696. + * Command was processed successfully and HID data was sent by DMA.
  4697. + * This will only be sent in HID mode.
  4698. + *
  4699. + * TOUCH_STATUS_CMD_SIZE_ERROR:
  4700. + * Command sent did not match expected size. Other fields will
  4701. + * not contain valid data.
  4702. + *
  4703. + * TOUCH_STATUS_REQUEST_OUTSTANDING:
  4704. + * Previous request is still outstanding, ME FW cannot handle
  4705. + * another request for the same command.
  4706. + *
  4707. + * TOUCH_STATUS_NOT_READY:
  4708. + * Indicates memory window has not yet been set by BIOS/HID.
  4709. + *
  4710. + * TOUCH_STATUS_SENSOR_DISABLED:
  4711. + * Indicates that ME to HID communication has been stopped either
  4712. + * by TOUCH_SENSOR_QUIESCE_IO_CMD or
  4713. + * TOUCH_SENSOR_CLEAR_MEM_WINDOW_CMD.
  4714. + *
  4715. + * TOUCH_STATUS_SENSOR_UNEXPECTED_RESET:
  4716. + * Sensor signaled a Reset Interrupt. ME did not expect this and
  4717. + * has no info about why this occurred.
  4718. + *
  4719. + * TOUCH_STATUS_SENSOR_EXPECTED_RESET:
  4720. + * Sensor signaled a Reset Interrupt. ME either directly requested
  4721. + * this reset, or it was expected as part of a defined flow
  4722. + * in the EDS.
  4723. + *
  4724. + * TOUCH_STATUS_QUIESCE_IO_IN_PROGRESS:
  4725. + * Indicates that Quiesce I/O is already in progress and this
  4726. + * command cannot be accepted at this time.
  4727. + *
  4728. + * TOUCH_STATUS_TIMEOUT:
  4729. + * Sensor did not generate a reset interrupt in the time allotted.
  4730. + * Could indicate sensor is not connected or malfunctioning.
  4731. + */
  4732. +struct touch_sensor_hid_ready_for_data_rsp_data {
  4733. + // Size of the data the ME DMA'd into a RawDataBuffer.
  4734. + // Valid only when Status == TOUCH_STATUS_SUCCESS
  4735. + u32 data_size;
  4736. +
  4737. + // Index to indicate which RawDataBuffer was used.
  4738. + // Valid only when Status == TOUCH_STATUS_SUCCESS
  4739. + u8 touch_data_buffer_index;
  4740. +
  4741. + // If Status is TOUCH_STATUS_SENSOR_EXPECTED_RESET, ME will provide
  4742. + // the cause. See TOUCH_RESET_REASON.
  4743. + u8 reset_reason;
  4744. +
  4745. + // For future expansion
  4746. + u8 reserved1[2];
  4747. + u32 reserved2[5];
  4748. +};
  4749. +static_assert(sizeof(struct touch_sensor_hid_ready_for_data_rsp_data) == 28);
  4750. +
  4751. +/*
  4752. + * TOUCH_SENSOR_FEEDBACK_READY_RSP code is sent in response to
  4753. + * TOUCH_SENSOR_FEEDBACK_READY_CMD. This code will be followed
  4754. + * by TOUCH_SENSOR_FEEDBACK_READY_RSP_DATA.
  4755. + *
  4756. + * Possible Status values:
  4757. + * TOUCH_STATUS_SUCCESS:
  4758. + * Command was processed successfully and any feedback or
  4759. + * commands were sent to sensor.
  4760. + *
  4761. + * TOUCH_STATUS_CMD_SIZE_ERROR:
  4762. + * Command sent did not match expected size. Other fields will
  4763. + * not contain valid data.
  4764. + *
  4765. + * TOUCH_STATUS_INVALID_PARAMS:
  4766. + * Input parameters are out of range.
  4767. + *
  4768. + * TOUCH_STATUS_COMPAT_CHECK_FAIL:
  4769. + * Indicates ProtocolVer does not match ME supported
  4770. + * version. (non-fatal error)
  4771. + *
  4772. + * TOUCH_STATUS_INTERNAL_ERROR:
  4773. + * Unexpected error occurred. This should not normally be seen.
  4774. + *
  4775. + * TOUCH_STATUS_OUT_OF_MEMORY:
  4776. + * Insufficient space to store Calibration Data
  4777. + */
  4778. +struct touch_sensor_feedback_ready_rsp_data {
  4779. + // Index value from 0 to TOUCH_SENSOR_MAX_DATA_BUFFERS used
  4780. + // to indicate which Feedback Buffer to use
  4781. + u8 feedback_index;
  4782. +
  4783. + // For future expansion
  4784. + u8 reserved1[3];
  4785. + u32 reserved2[6];
  4786. +};
  4787. +static_assert(sizeof(struct touch_sensor_feedback_ready_rsp_data) == 28);
  4788. +
  4789. +/*
  4790. + * TOUCH_SENSOR_CLEAR_MEM_WINDOW_RSP code is sent in response to
  4791. + * TOUCH_SENSOR_CLEAR_MEM_WINDOW_CMD. This code will be followed
  4792. + * by TOUCH_SENSOR_CLEAR_MEM_WINDOW_RSP_DATA.
  4793. + *
  4794. + * Possible Status values:
  4795. + * TOUCH_STATUS_SUCCESS:
  4796. + * Command was processed successfully and memory window was set.
  4797. + *
  4798. + * TOUCH_STATUS_CMD_SIZE_ERROR:
  4799. + * Command sent did not match expected size. Other fields will
  4800. + * not contain valid data.
  4801. + *
  4802. + * TOUCH_STATUS_INVALID_PARAMS:
  4803. + * Input parameters are out of range.
  4804. + *
  4805. + * TOUCH_STATUS_QUIESCE_IO_IN_PROGRESS:
  4806. + * Indicates that Quiesce I/O is already in progress and this
  4807. + * command cannot be accepted at this time.
  4808. + */
  4809. +struct touch_sensor_clear_mem_window_rsp_data {
  4810. + // For future expansion
  4811. + u32 reserved[3];
  4812. +};
  4813. +static_assert(sizeof(struct touch_sensor_clear_mem_window_rsp_data) == 12);
  4814. +
  4815. +/*
  4816. + * TOUCH_SENSOR_NOTIFY_DEV_READY_RSP code is sent in response to
  4817. + * TOUCH_SENSOR_NOTIFY_DEV_READY_CMD. This code will be followed
  4818. + * by TOUCH_SENSOR_NOTIFY_DEV_READY_RSP_DATA.
  4819. + *
  4820. + * Possible Status values:
  4821. + * TOUCH_STATUS_SUCCESS:
  4822. + * Command was processed successfully and sensor has
  4823. + * been detected by ME FW.
  4824. + *
  4825. + * TOUCH_STATUS_CMD_SIZE_ERROR:
  4826. + * Command sent did not match expected size.
  4827. + *
  4828. + * TOUCH_STATUS_REQUEST_OUTSTANDING:
  4829. + * Previous request is still outstanding, ME FW cannot handle
  4830. + * another request for the same command.
  4831. + *
  4832. + * TOUCH_STATUS_TIMEOUT:
  4833. + * Sensor did not generate a reset interrupt in the time allotted.
  4834. + * Could indicate sensor is not connected or malfunctioning.
  4835. + *
  4836. + * TOUCH_STATUS_SENSOR_FAIL_FATAL:
  4837. + * Sensor indicated a fatal error, further operation is not
  4838. + * possible. Error details can be found in ErrReg.
  4839. + *
  4840. + * TOUCH_STATUS_SENSOR_FAIL_NONFATAL:
  4841. + * Sensor indicated a non-fatal error. Error should be logged by
  4842. + * caller and init flow can continue. Error details can be found
  4843. + * in ErrReg.
  4844. + */
  4845. +struct touch_sensor_notify_dev_ready_rsp_data {
  4846. + // Value of sensor Error Register, field is only valid for
  4847. + // Status == TOUCH_STATUS_SENSOR_FAIL_FATAL or
  4848. + // TOUCH_STATUS_SENSOR_FAIL_NONFATAL
  4849. + union touch_err_reg err_reg;
  4850. +
  4851. + // For future expansion
  4852. + u32 reserved[2];
  4853. +};
  4854. +static_assert(sizeof(struct touch_sensor_notify_dev_ready_rsp_data) == 12);
  4855. +
  4856. +/*
  4857. + * TOUCH_SENSOR_SET_POLICIES_RSP code is sent in response to
  4858. + * TOUCH_SENSOR_SET_POLICIES_CMD. This code will be followed
  4859. + * by TOUCH_SENSOR_SET_POLICIES_RSP_DATA.
  4860. + *
  4861. + * Possible Status values:
  4862. + * TOUCH_STATUS_SUCCESS:
  4863. + * Command was processed successfully and new policies were set.
  4864. + *
  4865. + * TOUCH_STATUS_CMD_SIZE_ERROR:
  4866. + * Command sent did not match expected size. Other fields will
  4867. + * not contain valid data.
  4868. + *
  4869. + * TOUCH_STATUS_INVALID_PARAMS:
  4870. + * Input parameters are out of range.
  4871. + */
  4872. +struct touch_sensor_set_policies_rsp_data {
  4873. + // For future expansion
  4874. + u32 reserved[3];
  4875. +};
  4876. +static_assert(sizeof(struct touch_sensor_set_policies_rsp_data) == 12);
  4877. +
  4878. +/*
  4879. + * TOUCH_SENSOR_GET_POLICIES_RSP code is sent in response to
  4880. + * TOUCH_SENSOR_GET_POLICIES_CMD. This code will be followed
  4881. + * by TOUCH_SENSOR_GET_POLICIES_RSP_DATA.
  4882. + *
  4883. + * Possible Status values:
  4884. + * TOUCH_STATUS_SUCCESS:
  4885. + * Command was processed successfully and new policies were set.
  4886. + *
  4887. + * TOUCH_STATUS_CMD_SIZE_ERROR:
  4888. + * Command sent did not match expected size. Other fields will
  4889. + * not contain valid data.
  4890. + */
  4891. +struct touch_sensor_get_policies_rsp_data {
  4892. + // Contains the current policy
  4893. + struct touch_policy_data policy_data;
  4894. +};
  4895. +static_assert(sizeof(struct touch_sensor_get_policies_rsp_data) == 16);
  4896. +
  4897. +
  4898. +/*
  4899. + * TOUCH_SENSOR_RESET_RSP code is sent in response to
  4900. + * TOUCH_SENSOR_RESET_CMD. This code will be followed
  4901. + * by TOUCH_SENSOR_RESET_RSP_DATA.
  4902. + *
  4903. + * Possible Status values:
  4904. + * TOUCH_STATUS_SUCCESS:
  4905. + * Command was processed successfully and
  4906. + * sensor reset was completed.
  4907. + *
  4908. + * TOUCH_STATUS_CMD_SIZE_ERROR:
  4909. + * Command sent did not match expected size. Other fields will
  4910. + * not contain valid data.
  4911. + *
  4912. + * TOUCH_STATUS_INVALID_PARAMS:
  4913. + * Input parameters are out of range.
  4914. + *
  4915. + * TOUCH_STATUS_TIMEOUT:
  4916. + * Sensor did not generate a reset interrupt in the time allotted.
  4917. + * Could indicate sensor is not connected or malfunctioning.
  4918. + *
  4919. + * TOUCH_STATUS_RESET_FAILED:
  4920. + * Sensor generated an invalid or unexpected interrupt.
  4921. + *
  4922. + * TOUCH_STATUS_QUIESCE_IO_IN_PROGRESS:
  4923. + * Indicates that Quiesce I/O is already in progress and this
  4924. + * command cannot be accepted at this time.
  4925. + */
  4926. +struct touch_sensor_reset_rsp_data {
  4927. + // For future expansion
  4928. + u32 reserved[3];
  4929. +};
  4930. +static_assert(sizeof(struct touch_sensor_reset_rsp_data) == 12);
  4931. +
  4932. +/*
  4933. + * TOUCH_SENSOR_READ_ALL_REGS_RSP code is sent in response to
  4934. + * TOUCH_SENSOR_READ_ALL_REGS_CMD. This code will be followed
  4935. + * by TOUCH_SENSOR_READ_ALL_REGS_RSP_DATA.
  4936. + *
  4937. + * Possible Status values:
  4938. + * TOUCH_STATUS_SUCCESS:
  4939. + * Command was processed successfully and new policies were set.
  4940. + * TOUCH_STATUS_CMD_SIZE_ERROR:
  4941. + * Command sent did not match expected size. Other fields will
  4942. + * not contain valid data.
  4943. + */
  4944. +struct touch_sensor_read_all_regs_rsp_data {
  4945. + // Returns first 64 bytes of register space used for normal
  4946. + // touch operation. Does not include test mode register.
  4947. + struct touch_reg_block sensor_regs;
  4948. + u32 reserved[4];
  4949. +};
  4950. +static_assert(sizeof(struct touch_sensor_read_all_regs_rsp_data) == 80);
  4951. +
  4952. +/*
  4953. + * ME to Host Message
  4954. + */
  4955. +union touch_sensor_data_m2h {
  4956. + struct touch_sensor_get_device_info_rsp_data device_info_rsp_data;
  4957. + struct touch_sensor_set_mode_rsp_data set_mode_rsp_data;
  4958. + struct touch_sensor_set_mem_window_rsp_data set_mem_window_rsp_data;
  4959. + struct touch_sensor_quiesce_io_rsp_data quiesce_io_rsp_data;
  4960. +
  4961. + struct touch_sensor_hid_ready_for_data_rsp_data
  4962. + hid_ready_for_data_rsp_data;
  4963. +
  4964. + struct touch_sensor_feedback_ready_rsp_data feedback_ready_rsp_data;
  4965. + struct touch_sensor_clear_mem_window_rsp_data clear_mem_window_rsp_data;
  4966. + struct touch_sensor_notify_dev_ready_rsp_data notify_dev_ready_rsp_data;
  4967. + struct touch_sensor_set_policies_rsp_data set_policies_rsp_data;
  4968. + struct touch_sensor_get_policies_rsp_data get_policies_rsp_data;
  4969. + struct touch_sensor_reset_rsp_data reset_rsp_data;
  4970. + struct touch_sensor_read_all_regs_rsp_data read_all_regs_rsp_data;
  4971. +};
  4972. +struct touch_sensor_msg_m2h {
  4973. + u32 command_code;
  4974. + enum touch_status status;
  4975. + union touch_sensor_data_m2h m2h_data;
  4976. +};
  4977. +static_assert(sizeof(struct touch_sensor_msg_m2h) == 88);
  4978. +
  4979. +#pragma pack()
  4980. +
  4981. +#endif // _IPTS_MEI_MSGS_H_
  4982. diff --git a/drivers/misc/ipts/mei.c b/drivers/misc/ipts/mei.c
  4983. new file mode 100644
  4984. index 000000000000..03b5d747a728
  4985. --- /dev/null
  4986. +++ b/drivers/misc/ipts/mei.c
  4987. @@ -0,0 +1,238 @@
  4988. +// SPDX-License-Identifier: GPL-2.0-or-later
  4989. +/*
  4990. + *
  4991. + * Intel Precise Touch & Stylus
  4992. + * Copyright (c) 2016 Intel Corporation
  4993. + *
  4994. + */
  4995. +
  4996. +#include <linux/dma-mapping.h>
  4997. +#include <linux/hid.h>
  4998. +#include <linux/ipts-binary.h>
  4999. +#include <linux/kthread.h>
  5000. +#include <linux/mei_cl_bus.h>
  5001. +#include <linux/module.h>
  5002. +#include <linux/mod_devicetable.h>
  5003. +
  5004. +#include "companion.h"
  5005. +#include "hid.h"
  5006. +#include "ipts.h"
  5007. +#include "params.h"
  5008. +#include "msg-handler.h"
  5009. +#include "mei-msgs.h"
  5010. +#include "state.h"
  5011. +
  5012. +#define IPTS_DRIVER_NAME "ipts"
  5013. +#define IPTS_MEI_UUID UUID_LE(0x3e8d0870, 0x271a, 0x4208, \
  5014. + 0x8e, 0xb5, 0x9a, 0xcb, 0x94, 0x02, 0xae, 0x04)
  5015. +
  5016. +static struct mei_cl_device_id ipts_mei_cl_tbl[] = {
  5017. + { "", IPTS_MEI_UUID, MEI_CL_VERSION_ANY },
  5018. + { }
  5019. +};
  5020. +MODULE_DEVICE_TABLE(mei, ipts_mei_cl_tbl);
  5021. +
  5022. +static ssize_t device_info_show(struct device *dev,
  5023. + struct device_attribute *attr, char *buf)
  5024. +{
  5025. + struct ipts_info *ipts;
  5026. +
  5027. + ipts = dev_get_drvdata(dev);
  5028. + return sprintf(buf, "vendor id = 0x%04hX\ndevice id = 0x%04hX\n"
  5029. + "HW rev = 0x%08X\nfirmware rev = 0x%08X\n",
  5030. + ipts->device_info.vendor_id, ipts->device_info.device_id,
  5031. + ipts->device_info.hw_rev, ipts->device_info.fw_rev);
  5032. +}
  5033. +static DEVICE_ATTR_RO(device_info);
  5034. +
  5035. +static struct attribute *ipts_attrs[] = {
  5036. + &dev_attr_device_info.attr,
  5037. + NULL
  5038. +};
  5039. +
  5040. +static const struct attribute_group ipts_grp = {
  5041. + .attrs = ipts_attrs,
  5042. +};
  5043. +
  5044. +static void raw_data_work_func(struct work_struct *work)
  5045. +{
  5046. + struct ipts_info *ipts = container_of(work,
  5047. + struct ipts_info, raw_data_work);
  5048. +
  5049. + ipts_handle_processed_data(ipts);
  5050. +}
  5051. +
  5052. +static void gfx_status_work_func(struct work_struct *work)
  5053. +{
  5054. + struct ipts_info *ipts = container_of(work, struct ipts_info,
  5055. + gfx_status_work);
  5056. + enum ipts_state state;
  5057. + int status = ipts->gfx_status;
  5058. +
  5059. + ipts_dbg(ipts, "notify gfx status : %d\n", status);
  5060. +
  5061. + state = ipts_get_state(ipts);
  5062. +
  5063. + if (state != IPTS_STA_RAW_DATA_STARTED && state != IPTS_STA_HID_STARTED)
  5064. + return;
  5065. +
  5066. + if (status == IPTS_NOTIFY_STA_BACKLIGHT_ON && !ipts->display_status) {
  5067. + ipts_send_sensor_clear_mem_window_cmd(ipts);
  5068. + ipts->display_status = true;
  5069. + }
  5070. +
  5071. + if (status == IPTS_NOTIFY_STA_BACKLIGHT_OFF && ipts->display_status) {
  5072. + ipts_send_sensor_quiesce_io_cmd(ipts);
  5073. + ipts->display_status = false;
  5074. + }
  5075. +}
  5076. +
  5077. +// event loop
  5078. +static int ipts_mei_cl_event_thread(void *data)
  5079. +{
  5080. + struct ipts_info *ipts = (struct ipts_info *)data;
  5081. + struct mei_cl_device *cldev = ipts->cldev;
  5082. + ssize_t msg_len;
  5083. + struct touch_sensor_msg_m2h m2h_msg;
  5084. +
  5085. + while (!kthread_should_stop()) {
  5086. + msg_len = mei_cldev_recv(cldev,
  5087. + (u8 *)&m2h_msg, sizeof(m2h_msg));
  5088. + if (msg_len <= 0) {
  5089. + ipts_err(ipts, "error in reading m2h msg\n");
  5090. + continue;
  5091. + }
  5092. +
  5093. + if (ipts_handle_resp(ipts, &m2h_msg, msg_len) != 0)
  5094. + ipts_err(ipts, "error in handling resp msg\n");
  5095. + }
  5096. +
  5097. + ipts_dbg(ipts, "!! end event loop !!\n");
  5098. +
  5099. + return 0;
  5100. +}
  5101. +
  5102. +static void init_work_func(struct work_struct *work)
  5103. +{
  5104. + struct ipts_info *ipts = container_of(work,
  5105. + struct ipts_info, init_work);
  5106. +
  5107. + ipts->sensor_mode = TOUCH_SENSOR_MODE_RAW_DATA;
  5108. + ipts->display_status = true;
  5109. +
  5110. + ipts_start(ipts);
  5111. +}
  5112. +
  5113. +static int ipts_mei_cl_probe(struct mei_cl_device *cldev,
  5114. + const struct mei_cl_device_id *id)
  5115. +{
  5116. + int ret = 0;
  5117. + struct ipts_info *ipts = NULL;
  5118. +
  5119. + // Check if a companion driver for firmware loading was registered
  5120. + // If not, defer probing until it was properly registered
  5121. + if (!ipts_companion_available() && !ipts_modparams.ignore_companion)
  5122. + return -EPROBE_DEFER;
  5123. +
  5124. + pr_info("probing Intel Precise Touch & Stylus\n");
  5125. +
  5126. + // setup the DMA BIT mask, the system will choose the best possible
  5127. + if (dma_coerce_mask_and_coherent(&cldev->dev, DMA_BIT_MASK(64)) == 0) {
  5128. + pr_info("IPTS using DMA_BIT_MASK(64)\n");
  5129. + } else if (dma_coerce_mask_and_coherent(&cldev->dev,
  5130. + DMA_BIT_MASK(32)) == 0) {
  5131. + pr_info("IPTS using DMA_BIT_MASK(32)\n");
  5132. + } else {
  5133. + pr_err("IPTS: No suitable DMA available\n");
  5134. + return -EFAULT;
  5135. + }
  5136. +
  5137. + ret = mei_cldev_enable(cldev);
  5138. + if (ret < 0) {
  5139. + pr_err("cannot enable IPTS\n");
  5140. + return ret;
  5141. + }
  5142. +
  5143. + ipts = devm_kzalloc(&cldev->dev, sizeof(struct ipts_info), GFP_KERNEL);
  5144. + if (ipts == NULL) {
  5145. + ret = -ENOMEM;
  5146. + goto disable_mei;
  5147. + }
  5148. +
  5149. + ipts->cldev = cldev;
  5150. + mei_cldev_set_drvdata(cldev, ipts);
  5151. + ipts->event_loop = kthread_run(ipts_mei_cl_event_thread, (void *)ipts,
  5152. + "ipts_event_thread");
  5153. +
  5154. + if (ipts_dbgfs_register(ipts, "ipts"))
  5155. + pr_debug("cannot register debugfs for IPTS\n");
  5156. +
  5157. + INIT_WORK(&ipts->init_work, init_work_func);
  5158. + INIT_WORK(&ipts->raw_data_work, raw_data_work_func);
  5159. + INIT_WORK(&ipts->gfx_status_work, gfx_status_work_func);
  5160. +
  5161. + ret = sysfs_create_group(&cldev->dev.kobj, &ipts_grp);
  5162. + if (ret != 0)
  5163. + pr_debug("cannot create sysfs for IPTS\n");
  5164. +
  5165. + schedule_work(&ipts->init_work);
  5166. +
  5167. + return 0;
  5168. +
  5169. +disable_mei:
  5170. + mei_cldev_disable(cldev);
  5171. +
  5172. + return ret;
  5173. +}
  5174. +
  5175. +static int ipts_mei_cl_remove(struct mei_cl_device *cldev)
  5176. +{
  5177. + struct ipts_info *ipts = mei_cldev_get_drvdata(cldev);
  5178. +
  5179. + ipts_stop(ipts);
  5180. +
  5181. + sysfs_remove_group(&cldev->dev.kobj, &ipts_grp);
  5182. + ipts_hid_release(ipts);
  5183. + ipts_dbgfs_deregister(ipts);
  5184. + mei_cldev_disable(cldev);
  5185. +
  5186. + kthread_stop(ipts->event_loop);
  5187. +
  5188. + pr_info("IPTS removed\n");
  5189. +
  5190. + return 0;
  5191. +}
  5192. +
  5193. +static struct mei_cl_driver ipts_mei_cl_driver = {
  5194. + .id_table = ipts_mei_cl_tbl,
  5195. + .name = IPTS_DRIVER_NAME,
  5196. + .probe = ipts_mei_cl_probe,
  5197. + .remove = ipts_mei_cl_remove,
  5198. +};
  5199. +
  5200. +static int ipts_mei_cl_init(void)
  5201. +{
  5202. + int ret;
  5203. +
  5204. + pr_info("IPTS %s() is called\n", __func__);
  5205. +
  5206. + ret = mei_cldev_driver_register(&ipts_mei_cl_driver);
  5207. + if (ret) {
  5208. + pr_err("unable to register IPTS mei client driver\n");
  5209. + return ret;
  5210. + }
  5211. +
  5212. + return 0;
  5213. +}
  5214. +
  5215. +static void __exit ipts_mei_cl_exit(void)
  5216. +{
  5217. + pr_info("IPTS %s() is called\n", __func__);
  5218. + mei_cldev_driver_unregister(&ipts_mei_cl_driver);
  5219. +}
  5220. +
  5221. +module_init(ipts_mei_cl_init);
  5222. +module_exit(ipts_mei_cl_exit);
  5223. +
  5224. +MODULE_DESCRIPTION("Intel(R) ME Interface Client Driver for IPTS");
  5225. +MODULE_LICENSE("GPL");
  5226. diff --git a/drivers/misc/ipts/msg-handler.c b/drivers/misc/ipts/msg-handler.c
  5227. new file mode 100644
  5228. index 000000000000..9431b1dfc6e0
  5229. --- /dev/null
  5230. +++ b/drivers/misc/ipts/msg-handler.c
  5231. @@ -0,0 +1,405 @@
  5232. +// SPDX-License-Identifier: GPL-2.0-or-later
  5233. +/*
  5234. + *
  5235. + * Intel Precise Touch & Stylus
  5236. + * Copyright (c) 2016 Intel Corporation
  5237. + *
  5238. + */
  5239. +
  5240. +#include <linux/mei_cl_bus.h>
  5241. +
  5242. +#include "hid.h"
  5243. +#include "ipts.h"
  5244. +#include "mei-msgs.h"
  5245. +#include "resource.h"
  5246. +
  5247. +#define rsp_failed(ipts, cmd, status) \
  5248. + ipts_err(ipts, "0x%08x failed status = %d\n", cmd, status)
  5249. +
  5250. +int ipts_handle_cmd(struct ipts_info *ipts, u32 cmd, void *data, int data_size)
  5251. +{
  5252. + int ret = 0;
  5253. + int len = 0;
  5254. + struct touch_sensor_msg_h2m h2m_msg;
  5255. +
  5256. + memset(&h2m_msg, 0, sizeof(h2m_msg));
  5257. +
  5258. + h2m_msg.command_code = cmd;
  5259. + len = sizeof(h2m_msg.command_code) + data_size;
  5260. +
  5261. + if (data != NULL && data_size != 0)
  5262. + memcpy(&h2m_msg.h2m_data, data, data_size); // copy payload
  5263. +
  5264. + ret = mei_cldev_send(ipts->cldev, (u8 *)&h2m_msg, len);
  5265. + if (ret < 0) {
  5266. + ipts_err(ipts, "mei_cldev_send() error 0x%X:%d\n", cmd, ret);
  5267. + return ret;
  5268. + }
  5269. +
  5270. + return 0;
  5271. +}
  5272. +
  5273. +int ipts_send_feedback(struct ipts_info *ipts, int buffer_idx,
  5274. + u32 transaction_id)
  5275. +{
  5276. + struct ipts_buffer_info feedback_buffer;
  5277. + struct touch_feedback_hdr *feedback;
  5278. + struct touch_sensor_feedback_ready_cmd_data cmd;
  5279. +
  5280. + feedback_buffer = ipts->resource.feedback_buffer[buffer_idx];
  5281. + feedback = (struct touch_feedback_hdr *)feedback_buffer.addr;
  5282. +
  5283. + memset(feedback, 0, sizeof(struct touch_feedback_hdr));
  5284. + memset(&cmd, 0, sizeof(struct touch_sensor_feedback_ready_cmd_data));
  5285. +
  5286. + feedback->feedback_cmd_type = TOUCH_FEEDBACK_CMD_TYPE_NONE;
  5287. + feedback->buffer_id = transaction_id;
  5288. +
  5289. + cmd.feedback_index = buffer_idx;
  5290. + cmd.transaction_id = transaction_id;
  5291. +
  5292. + return ipts_handle_cmd(ipts, TOUCH_SENSOR_FEEDBACK_READY_CMD,
  5293. + &cmd, sizeof(struct touch_sensor_feedback_ready_cmd_data));
  5294. +}
  5295. +
  5296. +int ipts_send_sensor_quiesce_io_cmd(struct ipts_info *ipts)
  5297. +{
  5298. + int cmd_len = sizeof(struct touch_sensor_quiesce_io_cmd_data);
  5299. + struct touch_sensor_quiesce_io_cmd_data quiesce_io_cmd;
  5300. +
  5301. + memset(&quiesce_io_cmd, 0, cmd_len);
  5302. +
  5303. + return ipts_handle_cmd(ipts, TOUCH_SENSOR_QUIESCE_IO_CMD,
  5304. + &quiesce_io_cmd, cmd_len);
  5305. +}
  5306. +
  5307. +int ipts_send_sensor_hid_ready_for_data_cmd(struct ipts_info *ipts)
  5308. +{
  5309. + return ipts_handle_cmd(ipts,
  5310. + TOUCH_SENSOR_HID_READY_FOR_DATA_CMD, NULL, 0);
  5311. +}
  5312. +
  5313. +int ipts_send_sensor_clear_mem_window_cmd(struct ipts_info *ipts)
  5314. +{
  5315. + return ipts_handle_cmd(ipts,
  5316. + TOUCH_SENSOR_CLEAR_MEM_WINDOW_CMD, NULL, 0);
  5317. +}
  5318. +
  5319. +static int check_validity(struct touch_sensor_msg_m2h *m2h_msg, u32 msg_len)
  5320. +{
  5321. + int ret = 0;
  5322. + int valid_msg_len = sizeof(m2h_msg->command_code);
  5323. + u32 cmd_code = m2h_msg->command_code;
  5324. +
  5325. + switch (cmd_code) {
  5326. + case TOUCH_SENSOR_SET_MODE_RSP:
  5327. + valid_msg_len +=
  5328. + sizeof(struct touch_sensor_set_mode_rsp_data);
  5329. + break;
  5330. + case TOUCH_SENSOR_SET_MEM_WINDOW_RSP:
  5331. + valid_msg_len +=
  5332. + sizeof(struct touch_sensor_set_mem_window_rsp_data);
  5333. + break;
  5334. + case TOUCH_SENSOR_QUIESCE_IO_RSP:
  5335. + valid_msg_len +=
  5336. + sizeof(struct touch_sensor_quiesce_io_rsp_data);
  5337. + break;
  5338. + case TOUCH_SENSOR_HID_READY_FOR_DATA_RSP:
  5339. + valid_msg_len +=
  5340. + sizeof(struct touch_sensor_hid_ready_for_data_rsp_data);
  5341. + break;
  5342. + case TOUCH_SENSOR_FEEDBACK_READY_RSP:
  5343. + valid_msg_len +=
  5344. + sizeof(struct touch_sensor_feedback_ready_rsp_data);
  5345. + break;
  5346. + case TOUCH_SENSOR_CLEAR_MEM_WINDOW_RSP:
  5347. + valid_msg_len +=
  5348. + sizeof(struct touch_sensor_clear_mem_window_rsp_data);
  5349. + break;
  5350. + case TOUCH_SENSOR_NOTIFY_DEV_READY_RSP:
  5351. + valid_msg_len +=
  5352. + sizeof(struct touch_sensor_notify_dev_ready_rsp_data);
  5353. + break;
  5354. + case TOUCH_SENSOR_SET_POLICIES_RSP:
  5355. + valid_msg_len +=
  5356. + sizeof(struct touch_sensor_set_policies_rsp_data);
  5357. + break;
  5358. + case TOUCH_SENSOR_GET_POLICIES_RSP:
  5359. + valid_msg_len +=
  5360. + sizeof(struct touch_sensor_get_policies_rsp_data);
  5361. + break;
  5362. + case TOUCH_SENSOR_RESET_RSP:
  5363. + valid_msg_len +=
  5364. + sizeof(struct touch_sensor_reset_rsp_data);
  5365. + break;
  5366. + }
  5367. +
  5368. + if (valid_msg_len != msg_len)
  5369. + return -EINVAL;
  5370. + return ret;
  5371. +}
  5372. +
  5373. +int ipts_start(struct ipts_info *ipts)
  5374. +{
  5375. + /*
  5376. + * TODO: check if we need to do SET_POLICIES_CMD we need to do this
  5377. + * when protocol version doesn't match with reported one how we keep
  5378. + * vendor specific data is the first thing to solve.
  5379. + */
  5380. + ipts_set_state(ipts, IPTS_STA_INIT);
  5381. + ipts->num_of_parallel_data_buffers = TOUCH_SENSOR_MAX_DATA_BUFFERS;
  5382. +
  5383. + // start with RAW_DATA
  5384. + ipts->sensor_mode = TOUCH_SENSOR_MODE_RAW_DATA;
  5385. +
  5386. + return ipts_handle_cmd(ipts,
  5387. + TOUCH_SENSOR_NOTIFY_DEV_READY_CMD, NULL, 0);
  5388. +}
  5389. +
  5390. +void ipts_stop(struct ipts_info *ipts)
  5391. +{
  5392. + enum ipts_state old_state = ipts_get_state(ipts);
  5393. +
  5394. + ipts_set_state(ipts, IPTS_STA_STOPPING);
  5395. +
  5396. + ipts_send_sensor_quiesce_io_cmd(ipts);
  5397. + ipts_send_sensor_clear_mem_window_cmd(ipts);
  5398. +
  5399. + if (old_state < IPTS_STA_RESOURCE_READY)
  5400. + return;
  5401. +
  5402. + if (old_state == IPTS_STA_RAW_DATA_STARTED ||
  5403. + old_state == IPTS_STA_HID_STARTED) {
  5404. + ipts_free_default_resource(ipts);
  5405. + ipts_free_raw_data_resource(ipts);
  5406. + }
  5407. +}
  5408. +
  5409. +int ipts_restart(struct ipts_info *ipts)
  5410. +{
  5411. + ipts_dbg(ipts, "ipts restart\n");
  5412. + ipts_stop(ipts);
  5413. +
  5414. + ipts_send_sensor_quiesce_io_cmd(ipts);
  5415. + ipts->restart = true;
  5416. +
  5417. + return 0;
  5418. +}
  5419. +
  5420. +int ipts_handle_resp(struct ipts_info *ipts,
  5421. + struct touch_sensor_msg_m2h *m2h_msg, u32 msg_len)
  5422. +{
  5423. + int ret = 0;
  5424. + int rsp_status = 0;
  5425. + int cmd_status = 0;
  5426. + int cmd_len = 0;
  5427. + u32 cmd;
  5428. +
  5429. + if (!check_validity(m2h_msg, msg_len)) {
  5430. + ipts_err(ipts, "wrong rsp\n");
  5431. + return -EINVAL;
  5432. + }
  5433. +
  5434. + rsp_status = m2h_msg->status;
  5435. + cmd = m2h_msg->command_code;
  5436. +
  5437. + switch (cmd) {
  5438. + case TOUCH_SENSOR_NOTIFY_DEV_READY_RSP: {
  5439. + if (rsp_status != TOUCH_STATUS_SENSOR_FAIL_NONFATAL &&
  5440. + rsp_status != 0) {
  5441. + rsp_failed(ipts, cmd, rsp_status);
  5442. + break;
  5443. + }
  5444. +
  5445. + cmd_status = ipts_handle_cmd(ipts,
  5446. + TOUCH_SENSOR_GET_DEVICE_INFO_CMD, NULL, 0);
  5447. +
  5448. + break;
  5449. + }
  5450. + case TOUCH_SENSOR_GET_DEVICE_INFO_RSP: {
  5451. + if (rsp_status != TOUCH_STATUS_COMPAT_CHECK_FAIL &&
  5452. + rsp_status != 0) {
  5453. + rsp_failed(ipts, cmd, rsp_status);
  5454. + break;
  5455. + }
  5456. +
  5457. + memcpy(&ipts->device_info,
  5458. + &m2h_msg->m2h_data.device_info_rsp_data,
  5459. + sizeof(struct touch_sensor_get_device_info_rsp_data));
  5460. +
  5461. + /*
  5462. + * TODO: support raw_request during HID init. Although HID
  5463. + * init happens here, technically most of reports
  5464. + * (for both direction) can be issued only after
  5465. + * SET_MEM_WINDOWS_CMD since they may require ME or touch IC.
  5466. + * If ipts vendor requires raw_request during HID init, we
  5467. + * need to consider to move HID init.
  5468. + */
  5469. + if (ipts->hid_desc_ready == false) {
  5470. + ret = ipts_hid_init(ipts);
  5471. + if (ret)
  5472. + break;
  5473. + }
  5474. +
  5475. + cmd_status = ipts_send_sensor_clear_mem_window_cmd(ipts);
  5476. +
  5477. + break;
  5478. + }
  5479. + case TOUCH_SENSOR_CLEAR_MEM_WINDOW_RSP: {
  5480. + struct touch_sensor_set_mode_cmd_data sensor_mode_cmd;
  5481. +
  5482. + if (rsp_status != TOUCH_STATUS_TIMEOUT && rsp_status != 0) {
  5483. + rsp_failed(ipts, cmd, rsp_status);
  5484. + break;
  5485. + }
  5486. +
  5487. + if (ipts_get_state(ipts) == IPTS_STA_STOPPING)
  5488. + break;
  5489. +
  5490. + // allocate default resource: common & hid only
  5491. + if (!ipts_is_default_resource_ready(ipts)) {
  5492. + ret = ipts_allocate_default_resource(ipts);
  5493. + if (ret)
  5494. + break;
  5495. + }
  5496. +
  5497. + if (ipts->sensor_mode == TOUCH_SENSOR_MODE_RAW_DATA &&
  5498. + !ipts_is_raw_data_resource_ready(ipts)) {
  5499. + ret = ipts_allocate_raw_data_resource(ipts);
  5500. + if (ret) {
  5501. + ipts_free_default_resource(ipts);
  5502. + break;
  5503. + }
  5504. + }
  5505. +
  5506. + ipts_set_state(ipts, IPTS_STA_RESOURCE_READY);
  5507. +
  5508. + cmd_len = sizeof(struct touch_sensor_set_mode_cmd_data);
  5509. + memset(&sensor_mode_cmd, 0, cmd_len);
  5510. +
  5511. + sensor_mode_cmd.sensor_mode = ipts->sensor_mode;
  5512. + cmd_status = ipts_handle_cmd(ipts, TOUCH_SENSOR_SET_MODE_CMD,
  5513. + &sensor_mode_cmd, cmd_len);
  5514. +
  5515. + break;
  5516. + }
  5517. + case TOUCH_SENSOR_SET_MODE_RSP: {
  5518. + struct touch_sensor_set_mem_window_cmd_data smw_cmd;
  5519. +
  5520. + if (rsp_status != 0) {
  5521. + rsp_failed(ipts, cmd, rsp_status);
  5522. + break;
  5523. + }
  5524. +
  5525. + cmd_len = sizeof(struct touch_sensor_set_mem_window_cmd_data);
  5526. + memset(&smw_cmd, 0, cmd_len);
  5527. +
  5528. + ipts_get_set_mem_window_cmd_data(ipts, &smw_cmd);
  5529. + cmd_status = ipts_handle_cmd(ipts,
  5530. + TOUCH_SENSOR_SET_MEM_WINDOW_CMD, &smw_cmd, cmd_len);
  5531. +
  5532. + break;
  5533. + }
  5534. + case TOUCH_SENSOR_SET_MEM_WINDOW_RSP: {
  5535. + if (rsp_status != 0) {
  5536. + rsp_failed(ipts, cmd, rsp_status);
  5537. + break;
  5538. + }
  5539. +
  5540. + cmd_status = ipts_send_sensor_hid_ready_for_data_cmd(ipts);
  5541. + if (cmd_status)
  5542. + break;
  5543. +
  5544. + if (ipts->sensor_mode == TOUCH_SENSOR_MODE_HID)
  5545. + ipts_set_state(ipts, IPTS_STA_HID_STARTED);
  5546. + else if (ipts->sensor_mode == TOUCH_SENSOR_MODE_RAW_DATA)
  5547. + ipts_set_state(ipts, IPTS_STA_RAW_DATA_STARTED);
  5548. +
  5549. + ipts_dbg(ipts, "touch enabled %d\n", ipts_get_state(ipts));
  5550. +
  5551. + break;
  5552. + }
  5553. + case TOUCH_SENSOR_HID_READY_FOR_DATA_RSP: {
  5554. + struct touch_sensor_hid_ready_for_data_rsp_data *hid_data;
  5555. + enum ipts_state state;
  5556. +
  5557. + if (rsp_status != TOUCH_STATUS_SENSOR_DISABLED &&
  5558. + rsp_status != 0) {
  5559. + rsp_failed(ipts, cmd, rsp_status);
  5560. + break;
  5561. + }
  5562. +
  5563. + state = ipts_get_state(ipts);
  5564. + if (ipts->sensor_mode == TOUCH_SENSOR_MODE_HID &&
  5565. + state == IPTS_STA_HID_STARTED) {
  5566. + hid_data =
  5567. + &m2h_msg->m2h_data.hid_ready_for_data_rsp_data;
  5568. +
  5569. + // HID mode only uses buffer 0
  5570. + if (hid_data->touch_data_buffer_index != 0)
  5571. + break;
  5572. +
  5573. + // handle hid data
  5574. + ipts_handle_hid_data(ipts, hid_data);
  5575. + }
  5576. +
  5577. + break;
  5578. + }
  5579. + case TOUCH_SENSOR_FEEDBACK_READY_RSP: {
  5580. + if (rsp_status != TOUCH_STATUS_COMPAT_CHECK_FAIL &&
  5581. + rsp_status != TOUCH_STATUS_INVALID_PARAMS &&
  5582. + rsp_status != 0) {
  5583. + rsp_failed(ipts, cmd, rsp_status);
  5584. + break;
  5585. + }
  5586. +
  5587. + if (m2h_msg->m2h_data.feedback_ready_rsp_data.feedback_index
  5588. + == TOUCH_HID_2_ME_BUFFER_ID)
  5589. + break;
  5590. +
  5591. + if (ipts->sensor_mode == TOUCH_SENSOR_MODE_HID)
  5592. + cmd_status = ipts_handle_cmd(ipts,
  5593. + TOUCH_SENSOR_HID_READY_FOR_DATA_CMD, NULL, 0);
  5594. +
  5595. + break;
  5596. + }
  5597. + case TOUCH_SENSOR_QUIESCE_IO_RSP: {
  5598. + enum ipts_state state;
  5599. +
  5600. + if (rsp_status != 0) {
  5601. + rsp_failed(ipts, cmd, rsp_status);
  5602. + break;
  5603. + }
  5604. +
  5605. + state = ipts_get_state(ipts);
  5606. + if (state == IPTS_STA_STOPPING && ipts->restart) {
  5607. + ipts_dbg(ipts, "restart\n");
  5608. + ipts_start(ipts);
  5609. + ipts->restart = 0;
  5610. + break;
  5611. + }
  5612. +
  5613. + break;
  5614. + }
  5615. + }
  5616. +
  5617. + // handle error in rsp_status
  5618. + if (rsp_status != 0) {
  5619. + switch (rsp_status) {
  5620. + case TOUCH_STATUS_SENSOR_EXPECTED_RESET:
  5621. + case TOUCH_STATUS_SENSOR_UNEXPECTED_RESET:
  5622. + ipts_dbg(ipts, "sensor reset %d\n", rsp_status);
  5623. + ipts_restart(ipts);
  5624. + break;
  5625. + default:
  5626. + ipts_dbg(ipts, "cmd : 0x%08x, status %d\n",
  5627. + cmd, rsp_status);
  5628. + break;
  5629. + }
  5630. + }
  5631. +
  5632. + if (cmd_status)
  5633. + ipts_restart(ipts);
  5634. +
  5635. + return ret;
  5636. +}
  5637. diff --git a/drivers/misc/ipts/msg-handler.h b/drivers/misc/ipts/msg-handler.h
  5638. new file mode 100644
  5639. index 000000000000..eca4238adf4b
  5640. --- /dev/null
  5641. +++ b/drivers/misc/ipts/msg-handler.h
  5642. @@ -0,0 +1,28 @@
  5643. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  5644. +/*
  5645. + *
  5646. + * Intel Precise Touch & Stylus
  5647. + * Copyright (c) 2016 Intel Corporation
  5648. + *
  5649. + */
  5650. +
  5651. +#ifndef _IPTS_MSG_HANDLER_H_
  5652. +#define _IPTS_MSG_HANDLER_H_
  5653. +
  5654. +int ipts_start(struct ipts_info *ipts);
  5655. +void ipts_stop(struct ipts_info *ipts);
  5656. +int ipts_handle_cmd(struct ipts_info *ipts, u32 cmd, void *data, int data_size);
  5657. +
  5658. +int ipts_handle_resp(struct ipts_info *ipts,
  5659. + struct touch_sensor_msg_m2h *m2h_msg, u32 msg_len);
  5660. +
  5661. +int ipts_send_feedback(struct ipts_info *ipts,
  5662. + int buffer_idx, u32 transaction_id);
  5663. +
  5664. +int ipts_handle_processed_data(struct ipts_info *ipts);
  5665. +int ipts_send_sensor_quiesce_io_cmd(struct ipts_info *ipts);
  5666. +int ipts_send_sensor_hid_ready_for_data_cmd(struct ipts_info *ipts);
  5667. +int ipts_send_sensor_clear_mem_window_cmd(struct ipts_info *ipts);
  5668. +int ipts_restart(struct ipts_info *ipts);
  5669. +
  5670. +#endif /* _IPTS_MSG_HANDLER_H */
  5671. diff --git a/drivers/misc/ipts/params.c b/drivers/misc/ipts/params.c
  5672. new file mode 100644
  5673. index 000000000000..3ea76ca8342a
  5674. --- /dev/null
  5675. +++ b/drivers/misc/ipts/params.c
  5676. @@ -0,0 +1,42 @@
  5677. +// SPDX-License-Identifier: GPL-2.0-or-later
  5678. +/*
  5679. + *
  5680. + * Intel Precise Touch & Stylus
  5681. + * Copyright (c) 2016 Intel Corporation
  5682. + *
  5683. + */
  5684. +
  5685. +#include <linux/moduleparam.h>
  5686. +
  5687. +#include "params.h"
  5688. +
  5689. +#define IPTS_PARAM(NAME, TYPE, PERM, DESC) \
  5690. + module_param_named(NAME, ipts_modparams.NAME, TYPE, PERM); \
  5691. + MODULE_PARM_DESC(NAME, DESC)
  5692. +
  5693. +struct ipts_params ipts_modparams = {
  5694. + .ignore_fw_fallback = false,
  5695. + .ignore_config_fallback = false,
  5696. + .ignore_companion = false,
  5697. +
  5698. + .debug = false,
  5699. + .debug_thread = false,
  5700. +};
  5701. +
  5702. +IPTS_PARAM(ignore_fw_fallback, bool, 0400,
  5703. + "Don't use the IPTS firmware fallback path. (default: false)"
  5704. +);
  5705. +IPTS_PARAM(ignore_config_fallback, bool, 0400,
  5706. + "Don't try to load the IPTS firmware config from a file. (default: false)"
  5707. +);
  5708. +IPTS_PARAM(ignore_companion, bool, 0400,
  5709. + "Don't use a companion driver to load firmware. (default: false)"
  5710. +);
  5711. +
  5712. +IPTS_PARAM(debug, bool, 0400,
  5713. + "Enable IPTS debugging output. (default: false)"
  5714. +);
  5715. +IPTS_PARAM(debug_thread, bool, 0400,
  5716. + "Periodically print the ME status into the kernel log. (default: false)"
  5717. +);
  5718. +
  5719. diff --git a/drivers/misc/ipts/params.h b/drivers/misc/ipts/params.h
  5720. new file mode 100644
  5721. index 000000000000..c20546bacb08
  5722. --- /dev/null
  5723. +++ b/drivers/misc/ipts/params.h
  5724. @@ -0,0 +1,25 @@
  5725. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  5726. +/*
  5727. + *
  5728. + * Intel Precise Touch & Stylus
  5729. + * Copyright (c) 2016 Intel Corporation
  5730. + *
  5731. + */
  5732. +
  5733. +#ifndef _IPTS_PARAMS_H_
  5734. +#define _IPTS_PARAMS_H_
  5735. +
  5736. +#include <linux/types.h>
  5737. +
  5738. +struct ipts_params {
  5739. + bool ignore_fw_fallback;
  5740. + bool ignore_config_fallback;
  5741. + bool ignore_companion;
  5742. +
  5743. + bool debug;
  5744. + bool debug_thread;
  5745. +};
  5746. +
  5747. +extern struct ipts_params ipts_modparams;
  5748. +
  5749. +#endif // _IPTS_PARAMS_H_
  5750. diff --git a/drivers/misc/ipts/resource.c b/drivers/misc/ipts/resource.c
  5751. new file mode 100644
  5752. index 000000000000..cfd212f2cac0
  5753. --- /dev/null
  5754. +++ b/drivers/misc/ipts/resource.c
  5755. @@ -0,0 +1,291 @@
  5756. +// SPDX-License-Identifier: GPL-2.0-or-later
  5757. +/*
  5758. + *
  5759. + * Intel Precise Touch & Stylus
  5760. + * Copyright (c) 2016 Intel Corporation
  5761. + *
  5762. + */
  5763. +
  5764. +#include <linux/dma-mapping.h>
  5765. +
  5766. +#include "ipts.h"
  5767. +#include "kernel.h"
  5768. +#include "mei-msgs.h"
  5769. +
  5770. +static void free_common_resource(struct ipts_info *ipts)
  5771. +{
  5772. + char *addr;
  5773. + struct ipts_buffer_info *feedback_buffer;
  5774. + dma_addr_t dma_addr;
  5775. + u32 buffer_size;
  5776. + int i, num_of_parallels;
  5777. +
  5778. + if (ipts->resource.me2hid_buffer) {
  5779. + devm_kfree(&ipts->cldev->dev, ipts->resource.me2hid_buffer);
  5780. + ipts->resource.me2hid_buffer = 0;
  5781. + }
  5782. +
  5783. + addr = ipts->resource.hid2me_buffer.addr;
  5784. + dma_addr = ipts->resource.hid2me_buffer.dma_addr;
  5785. + buffer_size = ipts->resource.hid2me_buffer_size;
  5786. +
  5787. + if (ipts->resource.hid2me_buffer.addr) {
  5788. + dmam_free_coherent(&ipts->cldev->dev, buffer_size,
  5789. + addr, dma_addr);
  5790. +
  5791. + ipts->resource.hid2me_buffer.addr = 0;
  5792. + ipts->resource.hid2me_buffer.dma_addr = 0;
  5793. + ipts->resource.hid2me_buffer_size = 0;
  5794. + }
  5795. +
  5796. + feedback_buffer = ipts->resource.feedback_buffer;
  5797. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  5798. + for (i = 0; i < num_of_parallels; i++) {
  5799. +
  5800. + if (!feedback_buffer[i].addr)
  5801. + continue;
  5802. +
  5803. + dmam_free_coherent(&ipts->cldev->dev,
  5804. + ipts->device_info.feedback_size,
  5805. + feedback_buffer[i].addr, feedback_buffer[i].dma_addr);
  5806. +
  5807. + feedback_buffer[i].addr = 0;
  5808. + feedback_buffer[i].dma_addr = 0;
  5809. + }
  5810. +}
  5811. +
  5812. +static int allocate_common_resource(struct ipts_info *ipts)
  5813. +{
  5814. + char *addr, *me2hid_addr;
  5815. + struct ipts_buffer_info *feedback_buffer;
  5816. + dma_addr_t dma_addr;
  5817. + int i, ret = 0, num_of_parallels;
  5818. + u32 buffer_size;
  5819. +
  5820. + buffer_size = ipts->device_info.feedback_size;
  5821. +
  5822. + addr = dmam_alloc_coherent(&ipts->cldev->dev, buffer_size, &dma_addr,
  5823. + GFP_ATOMIC | __GFP_ZERO);
  5824. + if (addr == NULL)
  5825. + return -ENOMEM;
  5826. +
  5827. + me2hid_addr = devm_kzalloc(&ipts->cldev->dev, buffer_size, GFP_KERNEL);
  5828. + if (me2hid_addr == NULL) {
  5829. + ret = -ENOMEM;
  5830. + goto release_resource;
  5831. + }
  5832. +
  5833. + ipts->resource.hid2me_buffer.addr = addr;
  5834. + ipts->resource.hid2me_buffer.dma_addr = dma_addr;
  5835. + ipts->resource.hid2me_buffer_size = buffer_size;
  5836. + ipts->resource.me2hid_buffer = me2hid_addr;
  5837. +
  5838. + feedback_buffer = ipts->resource.feedback_buffer;
  5839. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  5840. +
  5841. + for (i = 0; i < num_of_parallels; i++) {
  5842. + feedback_buffer[i].addr = dmam_alloc_coherent(&ipts->cldev->dev,
  5843. + ipts->device_info.feedback_size,
  5844. + &feedback_buffer[i].dma_addr, GFP_ATOMIC|__GFP_ZERO);
  5845. +
  5846. + if (feedback_buffer[i].addr == NULL) {
  5847. + ret = -ENOMEM;
  5848. + goto release_resource;
  5849. + }
  5850. + }
  5851. +
  5852. + return 0;
  5853. +
  5854. +release_resource:
  5855. + free_common_resource(ipts);
  5856. +
  5857. + return ret;
  5858. +}
  5859. +
  5860. +void ipts_free_raw_data_resource(struct ipts_info *ipts)
  5861. +{
  5862. + if (ipts_is_raw_data_resource_ready(ipts)) {
  5863. + ipts->resource.raw_data_resource_ready = false;
  5864. + ipts_release_kernels(ipts);
  5865. + }
  5866. +}
  5867. +
  5868. +static int allocate_hid_resource(struct ipts_info *ipts)
  5869. +{
  5870. + struct ipts_buffer_info *buffer_hid;
  5871. +
  5872. + // hid mode uses only one touch data buffer
  5873. + buffer_hid = &ipts->resource.touch_data_buffer_hid;
  5874. + buffer_hid->addr = dmam_alloc_coherent(&ipts->cldev->dev,
  5875. + ipts->device_info.frame_size, &buffer_hid->dma_addr,
  5876. + GFP_ATOMIC|__GFP_ZERO);
  5877. +
  5878. + if (buffer_hid->addr == NULL)
  5879. + return -ENOMEM;
  5880. +
  5881. + return 0;
  5882. +}
  5883. +
  5884. +static void free_hid_resource(struct ipts_info *ipts)
  5885. +{
  5886. + struct ipts_buffer_info *buffer_hid;
  5887. +
  5888. + buffer_hid = &ipts->resource.touch_data_buffer_hid;
  5889. + if (buffer_hid->addr) {
  5890. + dmam_free_coherent(&ipts->cldev->dev,
  5891. + ipts->device_info.frame_size,
  5892. + buffer_hid->addr, buffer_hid->dma_addr);
  5893. +
  5894. + buffer_hid->addr = 0;
  5895. + buffer_hid->dma_addr = 0;
  5896. + }
  5897. +}
  5898. +
  5899. +int ipts_allocate_default_resource(struct ipts_info *ipts)
  5900. +{
  5901. + int ret;
  5902. +
  5903. + ret = allocate_common_resource(ipts);
  5904. + if (ret) {
  5905. + ipts_dbg(ipts, "cannot allocate common resource\n");
  5906. + return ret;
  5907. + }
  5908. +
  5909. + ret = allocate_hid_resource(ipts);
  5910. + if (ret) {
  5911. + ipts_dbg(ipts, "cannot allocate hid resource\n");
  5912. + free_common_resource(ipts);
  5913. + return ret;
  5914. + }
  5915. +
  5916. + ipts->resource.default_resource_ready = true;
  5917. +
  5918. + return 0;
  5919. +}
  5920. +
  5921. +void ipts_free_default_resource(struct ipts_info *ipts)
  5922. +{
  5923. + if (ipts_is_default_resource_ready(ipts)) {
  5924. + ipts->resource.default_resource_ready = false;
  5925. + free_hid_resource(ipts);
  5926. + free_common_resource(ipts);
  5927. + }
  5928. +}
  5929. +
  5930. +int ipts_allocate_raw_data_resource(struct ipts_info *ipts)
  5931. +{
  5932. + int ret = 0;
  5933. +
  5934. + ret = ipts_init_kernels(ipts);
  5935. + if (ret)
  5936. + return ret;
  5937. +
  5938. + ipts->resource.raw_data_resource_ready = true;
  5939. + return 0;
  5940. +}
  5941. +
  5942. +static void get_hid_only_smw_cmd_data(struct ipts_info *ipts,
  5943. + struct touch_sensor_set_mem_window_cmd_data *data,
  5944. + struct ipts_resource *resrc)
  5945. +{
  5946. + struct ipts_buffer_info *touch_buf;
  5947. + struct ipts_buffer_info *feedback_buf;
  5948. +
  5949. + touch_buf = &resrc->touch_data_buffer_hid;
  5950. + feedback_buf = &resrc->feedback_buffer[0];
  5951. +
  5952. + data->touch_data_buffer_addr_lower[0] =
  5953. + lower_32_bits(touch_buf->dma_addr);
  5954. +
  5955. + data->touch_data_buffer_addr_upper[0] =
  5956. + upper_32_bits(touch_buf->dma_addr);
  5957. +
  5958. + data->feedback_buffer_addr_lower[0] =
  5959. + lower_32_bits(feedback_buf->dma_addr);
  5960. +
  5961. + data->feedback_buffer_addr_upper[0] =
  5962. + upper_32_bits(feedback_buf->dma_addr);
  5963. +}
  5964. +
  5965. +static void get_raw_data_only_smw_cmd_data(struct ipts_info *ipts,
  5966. + struct touch_sensor_set_mem_window_cmd_data *data,
  5967. + struct ipts_resource *resrc)
  5968. +{
  5969. + u64 wq_tail_phy_addr;
  5970. + u64 cookie_phy_addr;
  5971. + struct ipts_buffer_info *touch_buf;
  5972. + struct ipts_buffer_info *feedback_buf;
  5973. + int i, num_of_parallels;
  5974. +
  5975. + touch_buf = resrc->touch_data_buffer_raw;
  5976. + feedback_buf = resrc->feedback_buffer;
  5977. +
  5978. + num_of_parallels = ipts_get_num_of_parallel_buffers(ipts);
  5979. + for (i = 0; i < num_of_parallels; i++) {
  5980. + data->touch_data_buffer_addr_lower[i] =
  5981. + lower_32_bits(touch_buf[i].dma_addr);
  5982. +
  5983. + data->touch_data_buffer_addr_upper[i] =
  5984. + upper_32_bits(touch_buf[i].dma_addr);
  5985. +
  5986. + data->feedback_buffer_addr_lower[i] =
  5987. + lower_32_bits(feedback_buf[i].dma_addr);
  5988. +
  5989. + data->feedback_buffer_addr_upper[i] =
  5990. + upper_32_bits(feedback_buf[i].dma_addr);
  5991. + }
  5992. +
  5993. + wq_tail_phy_addr = resrc->wq_info.wq_tail_phy_addr;
  5994. + data->tail_offset_addr_lower = lower_32_bits(wq_tail_phy_addr);
  5995. + data->tail_offset_addr_upper = upper_32_bits(wq_tail_phy_addr);
  5996. +
  5997. + cookie_phy_addr = resrc->wq_info.db_phy_addr +
  5998. + resrc->wq_info.db_cookie_offset;
  5999. +
  6000. + data->doorbell_cookie_addr_lower = lower_32_bits(cookie_phy_addr);
  6001. + data->doorbell_cookie_addr_upper = upper_32_bits(cookie_phy_addr);
  6002. + data->work_queue_size = resrc->wq_info.wq_size;
  6003. + data->work_queue_item_size = resrc->wq_item_size;
  6004. +}
  6005. +
  6006. +void ipts_get_set_mem_window_cmd_data(struct ipts_info *ipts,
  6007. + struct touch_sensor_set_mem_window_cmd_data *data)
  6008. +{
  6009. + struct ipts_resource *resrc = &ipts->resource;
  6010. +
  6011. + if (ipts->sensor_mode == TOUCH_SENSOR_MODE_RAW_DATA)
  6012. + get_raw_data_only_smw_cmd_data(ipts, data, resrc);
  6013. + else if (ipts->sensor_mode == TOUCH_SENSOR_MODE_HID)
  6014. + get_hid_only_smw_cmd_data(ipts, data, resrc);
  6015. +
  6016. + // hid2me is common for "raw data" and "hid"
  6017. + data->hid2me_buffer_addr_lower =
  6018. + lower_32_bits(resrc->hid2me_buffer.dma_addr);
  6019. +
  6020. + data->hid2me_buffer_addr_upper =
  6021. + upper_32_bits(resrc->hid2me_buffer.dma_addr);
  6022. +
  6023. + data->hid2me_buffer_size = resrc->hid2me_buffer_size;
  6024. +}
  6025. +
  6026. +void ipts_set_input_buffer(struct ipts_info *ipts, int parallel_idx,
  6027. + u8 *cpu_addr, u64 dma_addr)
  6028. +{
  6029. + struct ipts_buffer_info *touch_buf;
  6030. +
  6031. + touch_buf = ipts->resource.touch_data_buffer_raw;
  6032. + touch_buf[parallel_idx].dma_addr = dma_addr;
  6033. + touch_buf[parallel_idx].addr = cpu_addr;
  6034. +}
  6035. +
  6036. +void ipts_set_output_buffer(struct ipts_info *ipts, int parallel_idx,
  6037. + int output_idx, u8 *cpu_addr, u64 dma_addr)
  6038. +{
  6039. + struct ipts_buffer_info *output_buf;
  6040. +
  6041. + output_buf = &ipts->resource.raw_data_mode_output_buffer
  6042. + [parallel_idx][output_idx];
  6043. +
  6044. + output_buf->dma_addr = dma_addr;
  6045. + output_buf->addr = cpu_addr;
  6046. +}
  6047. diff --git a/drivers/misc/ipts/resource.h b/drivers/misc/ipts/resource.h
  6048. new file mode 100644
  6049. index 000000000000..27b9c17fcb89
  6050. --- /dev/null
  6051. +++ b/drivers/misc/ipts/resource.h
  6052. @@ -0,0 +1,26 @@
  6053. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  6054. +/*
  6055. + *
  6056. + * Intel Precise Touch & Stylus
  6057. + * Copyright (c) 2016 Intel Corporation
  6058. + *
  6059. + */
  6060. +
  6061. +#ifndef _IPTS_RESOURCE_H_
  6062. +#define _IPTS_RESOURCE_H_
  6063. +
  6064. +int ipts_allocate_default_resource(struct ipts_info *ipts);
  6065. +void ipts_free_default_resource(struct ipts_info *ipts);
  6066. +int ipts_allocate_raw_data_resource(struct ipts_info *ipts);
  6067. +void ipts_free_raw_data_resource(struct ipts_info *ipts);
  6068. +
  6069. +void ipts_get_set_mem_window_cmd_data(struct ipts_info *ipts,
  6070. + struct touch_sensor_set_mem_window_cmd_data *data);
  6071. +
  6072. +void ipts_set_input_buffer(struct ipts_info *ipts, int parallel_idx,
  6073. + u8 *cpu_addr, u64 dma_addr);
  6074. +
  6075. +void ipts_set_output_buffer(struct ipts_info *ipts, int parallel_idx,
  6076. + int output_idx, u8 *cpu_addr, u64 dma_addr);
  6077. +
  6078. +#endif // _IPTS_RESOURCE_H_
  6079. diff --git a/drivers/misc/ipts/sensor-regs.h b/drivers/misc/ipts/sensor-regs.h
  6080. new file mode 100644
  6081. index 000000000000..c1afab48249b
  6082. --- /dev/null
  6083. +++ b/drivers/misc/ipts/sensor-regs.h
  6084. @@ -0,0 +1,834 @@
  6085. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  6086. +/*
  6087. + *
  6088. + * Intel Precise Touch & Stylus
  6089. + * Copyright (c) 2013-2016 Intel Corporation
  6090. + *
  6091. + */
  6092. +
  6093. +#ifndef _IPTS_SENSOR_REGS_H_
  6094. +#define _IPTS_SENSOR_REGS_H_
  6095. +
  6096. +#include <linux/build_bug.h>
  6097. +
  6098. +#pragma pack(1)
  6099. +
  6100. +// Define static_assert macro (which will be available after 5.1
  6101. +// and not available on 4.19 yet) to check structure size and fail
  6102. +// compile for unexpected mismatch.
  6103. +// Taken from upstream commit 6bab69c65013bed5fce9f101a64a84d0385b3946.
  6104. +#define static_assert(expr, ...) __static_assert(expr, ##__VA_ARGS__, #expr)
  6105. +#define __static_assert(expr, msg, ...) _Static_assert(expr, msg)
  6106. +
  6107. +/*
  6108. + * Compatibility versions for this header file
  6109. + */
  6110. +#define TOUCH_EDS_REV_MINOR 0
  6111. +#define TOUCH_EDS_REV_MAJOR 1
  6112. +#define TOUCH_EDS_INTF_REV 1
  6113. +#define TOUCH_PROTOCOL_VER 0
  6114. +
  6115. +/*
  6116. + * Offset 00h: TOUCH_STS: Status Register
  6117. + * This register is read by the SPI Controller immediately following
  6118. + * an interrupt.
  6119. + */
  6120. +#define TOUCH_STS_REG_OFFSET 0x00
  6121. +
  6122. +#define TOUCH_SYNC_BYTE_VALUE 0x5A
  6123. +
  6124. +/*
  6125. + * Offset 04h: TOUCH_FRAME_CHAR: Frame Characteristics Register
  6126. + * This registers describes the characteristics of each data frame read by the
  6127. + * SPI Controller in response to a touch interrupt.
  6128. + */
  6129. +#define TOUCH_FRAME_CHAR_REG_OFFSET 0x04
  6130. +
  6131. +/*
  6132. + * Offset 08h: Touch Error Register
  6133. + */
  6134. +#define TOUCH_ERR_REG_OFFSET 0x08
  6135. +
  6136. +/*
  6137. + * Offset 10h: Touch Identification Register
  6138. + */
  6139. +#define TOUCH_ID_REG_OFFSET 0x10
  6140. +#define TOUCH_ID_REG_VALUE 0x43495424
  6141. +
  6142. +/*
  6143. + * Offset 14h: TOUCH_DATA_SZ: Touch Data Size Register
  6144. + * This register describes the maximum size of frames and feedback data
  6145. + */
  6146. +#define TOUCH_DATA_SZ_REG_OFFSET 0x14
  6147. +
  6148. +#define TOUCH_MAX_FRAME_SIZE_INCREMENT 64
  6149. +#define TOUCH_MAX_FEEDBACK_SIZE_INCREMENT 64
  6150. +
  6151. +/*
  6152. + * Max allowed frame size 32KB
  6153. + * Max allowed feedback size 16KB
  6154. + */
  6155. +#define TOUCH_SENSOR_MAX_FRAME_SIZE (32 * 1024)
  6156. +#define TOUCH_SENSOR_MAX_FEEDBACK_SIZE (16 * 1024)
  6157. +
  6158. +/*
  6159. + * Offset 18h: TOUCH_CAPABILITIES: Touch Capabilities Register
  6160. + * This register informs the host as to the capabilities of the touch IC.
  6161. + */
  6162. +#define TOUCH_CAPS_REG_OFFSET 0x18
  6163. +
  6164. +#define TOUCH_BULK_DATA_MAX_WRITE_INCREMENT 64
  6165. +
  6166. +/*
  6167. + * Offset 1Ch: TOUCH_CFG: Touch Configuration Register
  6168. + * This register allows the SPI Controller to configure the touch sensor as
  6169. + * needed during touch operations.
  6170. + */
  6171. +#define TOUCH_CFG_REG_OFFSET 0x1C
  6172. +
  6173. +/*
  6174. + * Offset 20h: TOUCH_CMD: Touch Command Register
  6175. + * This register is used for sending commands to the Touch IC.
  6176. + */
  6177. +#define TOUCH_CMD_REG_OFFSET 0x20
  6178. +
  6179. +/*
  6180. + * Offset 24h: Power Management Control
  6181. + * This register is used for active power management. The Touch IC is allowed
  6182. + * to mover from Doze or Armed to Sensing after a touch has occurred. All other
  6183. + * transitions will be made at the request of the SPI Controller.
  6184. + */
  6185. +#define TOUCH_PWR_MGMT_CTRL_REG_OFFSET 0x24
  6186. +
  6187. +/*
  6188. + * Offset 28h: Vendor HW Information Register
  6189. + * This register is used to relay Intel-assigned vendor ID information to the
  6190. + * SPI Controller, which may be forwarded to SW running on the host CPU.
  6191. + */
  6192. +#define TOUCH_VEN_HW_INFO_REG_OFFSET 0x28
  6193. +
  6194. +/*
  6195. + * Offset 2Ch: HW Revision ID Register
  6196. + * This register is used to relay vendor HW revision information to the SPI
  6197. + * Controller which may be forwarded to SW running on the host CPU.
  6198. + */
  6199. +#define TOUCH_HW_REV_REG_OFFSET 0x2C
  6200. +
  6201. +/*
  6202. + * Offset 30h: FW Revision ID Register
  6203. + * This register is used to relay vendor FW revision information to the SPI
  6204. + * Controller which may be forwarded to SW running on the host CPU.
  6205. + */
  6206. +#define TOUCH_FW_REV_REG_OFFSET 0x30
  6207. +
  6208. +/*
  6209. + * Offset 34h: Compatibility Revision ID Register
  6210. + * This register is used to relay vendor compatibility information to the SPI
  6211. + * Controller which may be forwarded to SW running on the host CPU.
  6212. + * Compatibility Information is a numeric value given by Intel to the Touch IC
  6213. + * vendor based on the major and minor revision of the EDS supported. From a
  6214. + * nomenclature point of view in an x.y revision number of the EDS, the major
  6215. + * version is the value of x and the minor version is the value of y. For
  6216. + * example, a Touch IC supporting an EDS version of 0.61 would contain a major
  6217. + * version of 0 and a minor version of 61 in the register.
  6218. + */
  6219. +#define TOUCH_COMPAT_REV_REG_OFFSET 0x34
  6220. +
  6221. +/*
  6222. + * Touch Register Block is the full set of registers from offset 0x00h to 0x3F
  6223. + * This is the entire set of registers needed for normal touch operation. It
  6224. + * does not include test registers such as TOUCH_TEST_CTRL_REG
  6225. + */
  6226. +#define TOUCH_REG_BLOCK_OFFSET TOUCH_STS_REG_OFFSET
  6227. +
  6228. +/*
  6229. + * Offset 40h: Test Control Register
  6230. + * This register
  6231. + */
  6232. +#define TOUCH_TEST_CTRL_REG_OFFSET 0x40
  6233. +
  6234. +/*
  6235. + * Offsets 0x000 to 0xFFF are reserved for Intel-defined Registers
  6236. + */
  6237. +#define TOUCH_REGISTER_LIMIT 0xFFF
  6238. +
  6239. +/*
  6240. + * Data Window: Address 0x1000-0x1FFFF
  6241. + * The data window is reserved for writing and reading large quantities of
  6242. + * data to and from the sensor.
  6243. + */
  6244. +#define TOUCH_DATA_WINDOW_OFFSET 0x1000
  6245. +#define TOUCH_DATA_WINDOW_LIMIT 0x1FFFF
  6246. +
  6247. +#define TOUCH_SENSOR_MAX_OFFSET TOUCH_DATA_WINDOW_LIMIT
  6248. +
  6249. +enum touch_sts_reg_int_type {
  6250. + // Touch Data Available
  6251. + TOUCH_STS_REG_INT_TYPE_DATA_AVAIL = 0,
  6252. +
  6253. + // Reset Occurred
  6254. + TOUCH_STS_REG_INT_TYPE_RESET_OCCURRED,
  6255. +
  6256. + // Error Occurred
  6257. + TOUCH_STS_REG_INT_TYPE_ERROR_OCCURRED,
  6258. +
  6259. + // Vendor specific data, treated same as raw frame
  6260. + TOUCH_STS_REG_INT_TYPE_VENDOR_DATA,
  6261. +
  6262. + // Get Features response data available
  6263. + TOUCH_STS_REG_INT_TYPE_GET_FEATURES,
  6264. +
  6265. + TOUCH_STS_REG_INT_TYPE_MAX
  6266. +};
  6267. +static_assert(sizeof(enum touch_sts_reg_int_type) == 4);
  6268. +
  6269. +enum touch_sts_reg_pwr_state {
  6270. + // Sleep
  6271. + TOUCH_STS_REG_PWR_STATE_SLEEP = 0,
  6272. +
  6273. + // Doze
  6274. + TOUCH_STS_REG_PWR_STATE_DOZE,
  6275. +
  6276. + // Armed
  6277. + TOUCH_STS_REG_PWR_STATE_ARMED,
  6278. +
  6279. + // Sensing
  6280. + TOUCH_STS_REG_PWR_STATE_SENSING,
  6281. +
  6282. + TOUCH_STS_REG_PWR_STATE_MAX
  6283. +};
  6284. +static_assert(sizeof(enum touch_sts_reg_pwr_state) == 4);
  6285. +
  6286. +enum touch_sts_reg_init_state {
  6287. + // Ready for normal operation
  6288. + TOUCH_STS_REG_INIT_STATE_READY_FOR_OP = 0,
  6289. +
  6290. + // Touch IC needs its Firmware loaded
  6291. + TOUCH_STS_REG_INIT_STATE_FW_NEEDED,
  6292. +
  6293. + // Touch IC needs its Data loaded
  6294. + TOUCH_STS_REG_INIT_STATE_DATA_NEEDED,
  6295. +
  6296. + // Error info in TOUCH_ERR_REG
  6297. + TOUCH_STS_REG_INIT_STATE_INIT_ERROR,
  6298. +
  6299. + TOUCH_STS_REG_INIT_STATE_MAX
  6300. +};
  6301. +static_assert(sizeof(enum touch_sts_reg_init_state) == 4);
  6302. +
  6303. +union touch_sts_reg {
  6304. + u32 reg_value;
  6305. + struct {
  6306. + // When set, this indicates the hardware has data
  6307. + // that needs to be read.
  6308. + u32 int_status:1;
  6309. +
  6310. + // see TOUCH_STS_REG_INT_TYPE
  6311. + u32 int_type:4;
  6312. +
  6313. + // see TOUCH_STS_REG_PWR_STATE
  6314. + u32 pwr_state:2;
  6315. +
  6316. + // see TOUCH_STS_REG_INIT_STATE
  6317. + u32 init_state:2;
  6318. +
  6319. + // Busy bit indicates that sensor cannot
  6320. + // accept writes at this time
  6321. + u32 busy:1;
  6322. +
  6323. + // Reserved
  6324. + u32 reserved:14;
  6325. +
  6326. + // Synchronization bit, should always be TOUCH_SYNC_BYTE_VALUE
  6327. + u32 sync_byte:8;
  6328. + } fields;
  6329. +};
  6330. +static_assert(sizeof(union touch_sts_reg) == 4);
  6331. +
  6332. +union touch_frame_char_reg {
  6333. + u32 reg_value;
  6334. + struct {
  6335. + // Micro-Frame Size (MFS): Indicates the size of a touch
  6336. + // micro-frame in byte increments. When a micro-frame is to be
  6337. + // read for processing (in data mode), this is the total number
  6338. + // of bytes that must be read per interrupt, split into
  6339. + // multiple read commands no longer than RPS.
  6340. + // Maximum micro-frame size is 256KB.
  6341. + u32 microframe_size:18;
  6342. +
  6343. + // Micro-Frames per Frame (MFPF): Indicates the number of
  6344. + // micro-frames per frame. If a sensor's frame does not contain
  6345. + // micro-frames this value will be 1. Valid values are 1-31.
  6346. + u32 microframes_per_frame:5;
  6347. +
  6348. + // Micro-Frame Index (MFI): Indicates the index of the
  6349. + // micro-frame within a frame. This allows the SPI Controller
  6350. + // to maintain synchronization with the sensor and determine
  6351. + // when the final micro-frame has arrived.
  6352. + // Valid values are 1-31.
  6353. + u32 microframe_index:5;
  6354. +
  6355. + // HID/Raw Data: This bit describes whether the data from the
  6356. + // sensor is Raw data or a HID report. When set, the data
  6357. + // is a HID report.
  6358. + u32 hid_report:1;
  6359. +
  6360. + // Reserved
  6361. + u32 reserved:3;
  6362. + } fields;
  6363. +};
  6364. +static_assert(sizeof(union touch_frame_char_reg) == 4);
  6365. +
  6366. +// bit definition is vendor specific
  6367. +union touch_err_reg {
  6368. + u32 reg_value;
  6369. + struct {
  6370. + u32 invalid_fw:1;
  6371. + u32 invalid_data:1;
  6372. + u32 self_test_failed:1;
  6373. + u32 reserved:12;
  6374. + u32 fatal_error:1;
  6375. + u32 vendor_errors:16;
  6376. + } fields;
  6377. +};
  6378. +static_assert(sizeof(union touch_err_reg) == 4);
  6379. +
  6380. +union touch_data_sz_reg {
  6381. + u32 reg_value;
  6382. + struct {
  6383. + // This value describes the maximum frame size in
  6384. + // 64byte increments.
  6385. + u32 max_frame_size:12;
  6386. +
  6387. + // This value describes the maximum feedback size in
  6388. + // 64byte increments.
  6389. + u32 max_feedback_size:8;
  6390. +
  6391. + // Reserved
  6392. + u32 reserved:12;
  6393. + } fields;
  6394. +};
  6395. +static_assert(sizeof(union touch_data_sz_reg) == 4);
  6396. +
  6397. +enum touch_caps_reg_read_delay_time {
  6398. + TOUCH_CAPS_REG_READ_DELAY_TIME_0,
  6399. + TOUCH_CAPS_REG_READ_DELAY_TIME_10uS,
  6400. + TOUCH_CAPS_REG_READ_DELAY_TIME_50uS,
  6401. + TOUCH_CAPS_REG_READ_DELAY_TIME_100uS,
  6402. + TOUCH_CAPS_REG_READ_DELAY_TIME_150uS,
  6403. + TOUCH_CAPS_REG_READ_DELAY_TIME_250uS,
  6404. + TOUCH_CAPS_REG_READ_DELAY_TIME_500uS,
  6405. + TOUCH_CAPS_REG_READ_DELAY_TIME_1mS,
  6406. +};
  6407. +static_assert(sizeof(enum touch_caps_reg_read_delay_time) == 4);
  6408. +
  6409. +union touch_caps_reg {
  6410. + u32 reg_value;
  6411. + struct {
  6412. + // Reserved for future frequency
  6413. + u32 reserved0:1;
  6414. +
  6415. + // 17 MHz (14 MHz on Atom) Supported
  6416. + // 0b - Not supported, 1b - Supported
  6417. + u32 supported_17Mhz:1;
  6418. +
  6419. + // 30 MHz (25MHz on Atom) Supported
  6420. + // 0b - Not supported, 1b - Supported
  6421. + u32 supported_30Mhz:1;
  6422. +
  6423. + // 50 MHz Supported
  6424. + // 0b - Not supported, 1b - Supported
  6425. + u32 supported_50Mhz:1;
  6426. +
  6427. + // Reserved
  6428. + u32 reserved1:4;
  6429. +
  6430. + // Single I/O Supported
  6431. + // 0b - Not supported, 1b - Supported
  6432. + u32 supported_single_io:1;
  6433. +
  6434. + // Dual I/O Supported
  6435. + // 0b - Not supported, 1b - Supported
  6436. + u32 supported_dual_io:1;
  6437. +
  6438. + // Quad I/O Supported
  6439. + // 0b - Not supported, 1b - Supported
  6440. + u32 supported_quad_io:1;
  6441. +
  6442. + // Bulk Data Area Max Write Size: The amount of data the SPI
  6443. + // Controller can write to the bulk data area before it has to
  6444. + // poll the busy bit. This field is in multiples of 64 bytes.
  6445. + // The SPI Controller will write the amount of data specified
  6446. + // in this field, then check and wait for the Status.Busy bit
  6447. + // to be zero before writing the next data chunk. This field is
  6448. + // 6 bits long, allowing for 4KB of contiguous writes w/o a
  6449. + // poll of the busy bit. If this field is 0x00 the Touch IC has
  6450. + // no limit in the amount of data the SPI Controller can write
  6451. + // to the bulk data area.
  6452. + u32 bulk_data_max_write:6;
  6453. +
  6454. + // Read Delay Timer Value: This field describes the delay the
  6455. + // SPI Controller will initiate when a read interrupt follows
  6456. + // a write data command. Uses values from
  6457. + // TOUCH_CAPS_REG_READ_DELAY_TIME
  6458. + u32 read_delay_timer_value:3;
  6459. +
  6460. + // Reserved
  6461. + u32 reserved2:4;
  6462. +
  6463. + // Maximum Touch Points: A byte value based on the
  6464. + // HID descriptor definition.
  6465. + u32 max_touch_points:8;
  6466. + } fields;
  6467. +};
  6468. +static_assert(sizeof(union touch_caps_reg) == 4);
  6469. +
  6470. +enum touch_cfg_reg_bulk_xfer_size {
  6471. + // Bulk Data Transfer Size is 4 bytes
  6472. + TOUCH_CFG_REG_BULK_XFER_SIZE_4B = 0,
  6473. +
  6474. + // Bulk Data Transfer Size is 8 bytes
  6475. + TOUCH_CFG_REG_BULK_XFER_SIZE_8B,
  6476. +
  6477. + // Bulk Data Transfer Size is 16 bytes
  6478. + TOUCH_CFG_REG_BULK_XFER_SIZE_16B,
  6479. +
  6480. + // Bulk Data Transfer Size is 32 bytes
  6481. + TOUCH_CFG_REG_BULK_XFER_SIZE_32B,
  6482. +
  6483. + // Bulk Data Transfer Size is 64 bytes
  6484. + TOUCH_CFG_REG_BULK_XFER_SIZE_64B,
  6485. +
  6486. + TOUCH_CFG_REG_BULK_XFER_SIZE_MAX
  6487. +};
  6488. +static_assert(sizeof(enum touch_cfg_reg_bulk_xfer_size) == 4);
  6489. +
  6490. +/*
  6491. + * Frequency values used by TOUCH_CFG_REG
  6492. + * and TOUCH_SENSOR_GET_DEVICE_INFO_RSP_DATA.
  6493. + */
  6494. +enum touch_freq {
  6495. + // Reserved value
  6496. + TOUCH_FREQ_RSVD = 0,
  6497. +
  6498. + // Sensor set for 17MHz operation (14MHz on Atom)
  6499. + TOUCH_FREQ_17MHZ,
  6500. +
  6501. + // Sensor set for 30MHz operation (25MHz on Atom)
  6502. + TOUCH_FREQ_30MHZ,
  6503. +
  6504. + // Invalid value
  6505. + TOUCH_FREQ_MAX
  6506. +};
  6507. +static_assert(sizeof(enum touch_freq) == 4);
  6508. +
  6509. +union touch_cfg_reg {
  6510. + u32 reg_value;
  6511. + struct {
  6512. + // Touch Enable (TE): This bit is used as a HW semaphore for
  6513. + // the Touch IC to guarantee to the SPI Controller to that
  6514. + // (when 0) no sensing operations will occur and only the Reset
  6515. + // interrupt will be generated.
  6516. + //
  6517. + // When TE is cleared by the SPI
  6518. + // Controller:
  6519. + // - TICs must flush all output buffers
  6520. + // - TICs must De-assert any pending interrupt
  6521. + // - ME must throw away any partial frame and pending
  6522. + // interrupt must be cleared/not serviced.
  6523. + //
  6524. + // The SPI Controller will only modify the configuration of the
  6525. + // TIC when TE is cleared.
  6526. + // TE is defaulted to 0h on a power-on reset.
  6527. + u32 touch_enable:1;
  6528. +
  6529. + // Data/HID Packet Mode (DHPM)
  6530. + // Raw Data Mode: 0h, HID Packet Mode: 1h
  6531. + u32 dhpm:1;
  6532. +
  6533. + // Bulk Data Transfer Size: This field represents the amount
  6534. + // of data written to the Bulk Data Area
  6535. + // (SPI Offset 0x1000-0x2FFF) in a single SPI write protocol
  6536. + u32 bulk_xfer_size:4;
  6537. +
  6538. + // Frequency Select: Frequency for the TouchIC to run at.
  6539. + // Use values from TOUCH_FREQ
  6540. + u32 freq_select:3;
  6541. +
  6542. + // Reserved
  6543. + u32 reserved:23;
  6544. + } fields;
  6545. +};
  6546. +static_assert(sizeof(union touch_cfg_reg) == 4);
  6547. +
  6548. +enum touch_cmd_reg_code {
  6549. + // No Operation
  6550. + TOUCH_CMD_REG_CODE_NOP = 0,
  6551. +
  6552. + // Soft Reset
  6553. + TOUCH_CMD_REG_CODE_SOFT_RESET,
  6554. +
  6555. + // Prepare All Registers for Read
  6556. + TOUCH_CMD_REG_CODE_PREP_4_READ,
  6557. +
  6558. + // Generate Test Packets according to value in TOUCH_TEST_CTRL_REG
  6559. + TOUCH_CMD_REG_CODE_GEN_TEST_PACKETS,
  6560. +
  6561. + TOUCH_CMD_REG_CODE_MAX
  6562. +};
  6563. +static_assert(sizeof(enum touch_cmd_reg_code) == 4);
  6564. +
  6565. +union touch_cmd_reg {
  6566. + u32 reg_value;
  6567. + struct {
  6568. + // Command Code: See TOUCH_CMD_REG_CODE
  6569. + u32 command_code:8;
  6570. +
  6571. + // Reserved
  6572. + u32 reserved:24;
  6573. + } fields;
  6574. +};
  6575. +static_assert(sizeof(union touch_cmd_reg) == 4);
  6576. +
  6577. +enum touch_pwr_mgmt_ctrl_reg_cmd {
  6578. + // No change to power state
  6579. + TOUCH_PWR_MGMT_CTRL_REG_CMD_NOP = 0,
  6580. +
  6581. + // Sleep - set when the system goes into connected standby
  6582. + TOUCH_PWR_MGMT_CTRL_REG_CMD_SLEEP,
  6583. +
  6584. + // Doze - set after 300 seconds of inactivity
  6585. + TOUCH_PWR_MGMT_CTRL_REG_CMD_DOZE,
  6586. +
  6587. + // Armed - Set by FW when a "finger off" message is
  6588. + // received from the EUs
  6589. + TOUCH_PWR_MGMT_CTRL_REG_CMD_ARMED,
  6590. +
  6591. + // Sensing - not typically set by FW
  6592. + TOUCH_PWR_MGMT_CTRL_REG_CMD_SENSING,
  6593. +
  6594. + // Values will result in no change to the power state of the Touch IC
  6595. + TOUCH_PWR_MGMT_CTRL_REG_CMD_MAX
  6596. +};
  6597. +static_assert(sizeof(enum touch_pwr_mgmt_ctrl_reg_cmd) == 4);
  6598. +
  6599. +union touch_pwr_mgmt_ctrl_reg {
  6600. + u32 reg_value;
  6601. + struct {
  6602. + // Power State Command: See TOUCH_PWR_MGMT_CTRL_REG_CMD
  6603. + u32 pwr_state_cmd:3;
  6604. +
  6605. + // Reserved
  6606. + u32 reserved:29;
  6607. + } fields;
  6608. +};
  6609. +static_assert(sizeof(union touch_pwr_mgmt_ctrl_reg) == 4);
  6610. +
  6611. +union touch_ven_hw_info_reg {
  6612. + u32 reg_value;
  6613. + struct {
  6614. + // Touch Sensor Vendor ID
  6615. + u32 vendor_id:16;
  6616. +
  6617. + // Touch Sensor Device ID
  6618. + u32 device_id:16;
  6619. + } fields;
  6620. +};
  6621. +static_assert(sizeof(union touch_ven_hw_info_reg) == 4);
  6622. +
  6623. +union touch_compat_rev_reg {
  6624. + u32 reg_value;
  6625. +
  6626. + struct {
  6627. + // EDS Minor Revision
  6628. + u8 minor;
  6629. +
  6630. + // EDS Major Revision
  6631. + u8 major;
  6632. +
  6633. + // Interface Revision Number (from EDS)
  6634. + u8 intf_rev;
  6635. +
  6636. + // EU Kernel Compatibility Version - vendor specific value
  6637. + u8 kernel_compat_ver;
  6638. + } fields;
  6639. +};
  6640. +static_assert(sizeof(union touch_compat_rev_reg) == 4);
  6641. +
  6642. +struct touch_reg_block {
  6643. + // 0x00
  6644. + union touch_sts_reg sts_reg;
  6645. +
  6646. + // 0x04
  6647. + union touch_frame_char_reg frame_char_reg;
  6648. +
  6649. + // 0x08
  6650. + union touch_err_reg error_reg;
  6651. +
  6652. + // 0x0C
  6653. + u32 reserved0;
  6654. +
  6655. + // 0x10 - expected value is "$TIC" or 0x43495424
  6656. + u32 id_reg;
  6657. +
  6658. + // 0x14
  6659. + union touch_data_sz_reg data_size_reg;
  6660. +
  6661. + // 0x18
  6662. + union touch_caps_reg caps_reg;
  6663. +
  6664. + // 0x1C
  6665. + union touch_cfg_reg cfg_reg;
  6666. +
  6667. + // 0x20
  6668. + union touch_cmd_reg cmd_reg;
  6669. +
  6670. + // 0x24
  6671. + union touch_pwr_mgmt_ctrl_reg pwm_mgme_ctrl_reg;
  6672. +
  6673. + // 0x28
  6674. + union touch_ven_hw_info_reg ven_hw_info_reg;
  6675. +
  6676. + // 0x2C
  6677. + u32 hw_rev_reg;
  6678. +
  6679. + // 0x30
  6680. + u32 fw_rev_reg;
  6681. +
  6682. + // 0x34
  6683. + union touch_compat_rev_reg compat_rev_reg;
  6684. +
  6685. + // 0x38
  6686. + u32 reserved1;
  6687. +
  6688. + // 0x3C
  6689. + u32 reserved2;
  6690. +};
  6691. +static_assert(sizeof(struct touch_reg_block) == 64);
  6692. +
  6693. +union touch_test_ctrl_reg {
  6694. + u32 reg_value;
  6695. + struct {
  6696. + // Size of Test Frame in Raw Data Mode: This field specifies
  6697. + // the test frame size in raw data mode in multiple of 64 bytes.
  6698. + // For example, if this field value is 16, the test frame size
  6699. + // will be 16x64 = 1K.
  6700. + u32 raw_test_frame_size:16;
  6701. +
  6702. + // Number of Raw Data Frames or HID Report Packets Generation.
  6703. + // This field represents the number of test frames or HID
  6704. + // reports to be generated when test mode is enabled. When
  6705. + // multiple packets/frames are generated, they need be
  6706. + // generated at 100 Hz frequency, i.e. 10ms per packet/frame.
  6707. + u32 num_test_frames:16;
  6708. + } fields;
  6709. +};
  6710. +static_assert(sizeof(union touch_test_ctrl_reg) == 4);
  6711. +
  6712. +/*
  6713. + * The following data structures represent the headers defined in the Data
  6714. + * Structures chapter of the Intel Integrated Touch EDS
  6715. + */
  6716. +
  6717. +// Enumeration used in TOUCH_RAW_DATA_HDR
  6718. +enum touch_raw_data_types {
  6719. + TOUCH_RAW_DATA_TYPE_FRAME = 0,
  6720. +
  6721. + // RawData will be the TOUCH_ERROR struct below
  6722. + TOUCH_RAW_DATA_TYPE_ERROR,
  6723. +
  6724. + // Set when InterruptType is Vendor Data
  6725. + TOUCH_RAW_DATA_TYPE_VENDOR_DATA,
  6726. +
  6727. + TOUCH_RAW_DATA_TYPE_HID_REPORT,
  6728. + TOUCH_RAW_DATA_TYPE_GET_FEATURES,
  6729. + TOUCH_RAW_DATA_TYPE_MAX
  6730. +};
  6731. +static_assert(sizeof(enum touch_raw_data_types) == 4);
  6732. +
  6733. +// Private data structure. Kernels must copy to HID driver buffer
  6734. +struct touch_hid_private_data {
  6735. + u32 transaction_id;
  6736. + u8 reserved[28];
  6737. +};
  6738. +static_assert(sizeof(struct touch_hid_private_data) == 32);
  6739. +
  6740. +// This is the data structure sent from the PCH FW to the EU kernel
  6741. +struct touch_raw_data_hdr {
  6742. + // use values from TOUCH_RAW_DATA_TYPES
  6743. + u32 data_type;
  6744. +
  6745. + // The size in bytes of the raw data read from the sensor, does not
  6746. + // include TOUCH_RAW_DATA_HDR. Will be the sum of all uFrames, or size
  6747. + // of TOUCH_ERROR for if DataType is TOUCH_RAW_DATA_TYPE_ERROR
  6748. + u32 raw_data_size_bytes;
  6749. +
  6750. + // An ID to qualify with the feedback data to track buffer usage
  6751. + u32 buffer_id;
  6752. +
  6753. + // Must match protocol version of the EDS
  6754. + u32 protocol_ver;
  6755. +
  6756. + // Copied from the Compatibility Revision ID Reg
  6757. + u8 kernel_compat_id;
  6758. +
  6759. + // Padding to extend header to full 64 bytes and allow for growth
  6760. + u8 reserved[15];
  6761. +
  6762. + // Private data structure. Kernels must copy to HID driver buffer
  6763. + struct touch_hid_private_data hid_private_data;
  6764. +};
  6765. +static_assert(sizeof(struct touch_raw_data_hdr) == 64);
  6766. +
  6767. +struct touch_raw_data {
  6768. + struct touch_raw_data_hdr header;
  6769. +
  6770. + // used to access the raw data as an array and keep the compilers
  6771. + // happy. Actual size of this array is Header.RawDataSizeBytes
  6772. + u8 raw_data[1];
  6773. +};
  6774. +
  6775. +/*
  6776. + * The following section describes the data passed in TOUCH_RAW_DATA.RawData
  6777. + * when DataType equals TOUCH_RAW_DATA_TYPE_ERROR
  6778. + * Note: This data structure is also applied to HID mode
  6779. + */
  6780. +enum touch_err_types {
  6781. + TOUCH_RAW_DATA_ERROR = 0,
  6782. + TOUCH_RAW_ERROR_MAX
  6783. +};
  6784. +static_assert(sizeof(enum touch_err_types) == 4);
  6785. +
  6786. +union touch_me_fw_error {
  6787. + u32 value;
  6788. + struct {
  6789. + u32 invalid_frame_characteristics:1;
  6790. + u32 microframe_index_invalid:1;
  6791. + u32 reserved:30;
  6792. + } fields;
  6793. +};
  6794. +static_assert(sizeof(union touch_me_fw_error) == 4);
  6795. +
  6796. +struct touch_error {
  6797. + // This must be a value from TOUCH_ERROR_TYPES
  6798. + u8 touch_error_type;
  6799. + u8 reserved[3];
  6800. + union touch_me_fw_error touch_me_fw_error;
  6801. +
  6802. + // Contains the value copied from the Touch Error Reg
  6803. + union touch_err_reg touch_error_register;
  6804. +};
  6805. +static_assert(sizeof(struct touch_error) == 12);
  6806. +
  6807. +// Enumeration used in TOUCH_FEEDBACK_BUFFER
  6808. +enum touch_feedback_cmd_types {
  6809. + TOUCH_FEEDBACK_CMD_TYPE_NONE = 0,
  6810. + TOUCH_FEEDBACK_CMD_TYPE_SOFT_RESET,
  6811. + TOUCH_FEEDBACK_CMD_TYPE_GOTO_ARMED,
  6812. + TOUCH_FEEDBACK_CMD_TYPE_GOTO_SENSING,
  6813. + TOUCH_FEEDBACK_CMD_TYPE_GOTO_SLEEP,
  6814. + TOUCH_FEEDBACK_CMD_TYPE_GOTO_DOZE,
  6815. + TOUCH_FEEDBACK_CMD_TYPE_HARD_RESET,
  6816. + TOUCH_FEEDBACK_CMD_TYPE_MAX
  6817. +};
  6818. +static_assert(sizeof(enum touch_feedback_cmd_types) == 4);
  6819. +
  6820. +// Enumeration used in TOUCH_FEEDBACK_HDR
  6821. +enum touch_feedback_data_types {
  6822. + // This is vendor specific feedback to be written to the sensor
  6823. + TOUCH_FEEDBACK_DATA_TYPE_FEEDBACK = 0,
  6824. +
  6825. + // This is a set features command to be written to the sensor
  6826. + TOUCH_FEEDBACK_DATA_TYPE_SET_FEATURES,
  6827. +
  6828. + // This is a get features command to be written to the sensor
  6829. + TOUCH_FEEDBACK_DATA_TYPE_GET_FEATURES,
  6830. +
  6831. + // This is a HID output report to be written to the sensor
  6832. + TOUCH_FEEDBACK_DATA_TYPE_OUTPUT_REPORT,
  6833. +
  6834. + // This is calibration data to be written to system flash
  6835. + TOUCH_FEEDBACK_DATA_TYPE_STORE_DATA,
  6836. +
  6837. + TOUCH_FEEDBACK_DATA_TYPE_MAX
  6838. +};
  6839. +static_assert(sizeof(enum touch_feedback_data_types) == 4);
  6840. +
  6841. +/*
  6842. + * This is the data structure sent from the EU kernels back to the ME FW.
  6843. + * In addition to "feedback" data, the FW can execute a "command" described by
  6844. + * the command type parameter. Any payload data will always be sent to the TIC
  6845. + * first, then any command will be issued.
  6846. + */
  6847. +struct touch_feedback_hdr {
  6848. + // use values from TOUCH_FEEDBACK_CMD_TYPES
  6849. + u32 feedback_cmd_type;
  6850. +
  6851. + // The amount of data to be written to the sensor,
  6852. + // not including the header
  6853. + u32 payload_size_bytes;
  6854. +
  6855. + // The ID of the raw data buffer that generated this feedback data
  6856. + u32 buffer_id;
  6857. +
  6858. + // Must match protocol version of the EDS
  6859. + u32 protocol_ver;
  6860. +
  6861. + // use values from TOUCH_FEEDBACK_DATA_TYPES. This is not relevant
  6862. + // if PayloadSizeBytes is 0
  6863. + u32 feedback_data_type;
  6864. +
  6865. + // The offset from TOUCH_DATA_WINDOW_OFFSET at which to write the
  6866. + // Payload data. Maximum offset is 0x1EFFF.
  6867. + u32 spi_offest;
  6868. +
  6869. + // Padding to extend header to full 64 bytes and allow for growth
  6870. + u8 reserved[40];
  6871. +};
  6872. +static_assert(sizeof(struct touch_feedback_hdr) == 64);
  6873. +
  6874. +struct touch_feedback_buffer {
  6875. + struct touch_feedback_hdr Header;
  6876. +
  6877. + // used to access the feedback data as an array and keep the compilers
  6878. + // happy. Actual size of this array is Header.PayloadSizeBytes
  6879. + u8 feedback_data[1];
  6880. +};
  6881. +
  6882. +/*
  6883. + * This data structure describes the header prepended to all data
  6884. + * written to the touch IC at the bulk data write
  6885. + * (TOUCH_DATA_WINDOW_OFFSET + TOUCH_FEEDBACK_HDR.SpiOffest) address.
  6886. + */
  6887. +enum touch_write_data_type {
  6888. + TOUCH_WRITE_DATA_TYPE_FW_LOAD = 0,
  6889. + TOUCH_WRITE_DATA_TYPE_DATA_LOAD,
  6890. + TOUCH_WRITE_DATA_TYPE_FEEDBACK,
  6891. + TOUCH_WRITE_DATA_TYPE_SET_FEATURES,
  6892. + TOUCH_WRITE_DATA_TYPE_GET_FEATURES,
  6893. + TOUCH_WRITE_DATA_TYPE_OUTPUT_REPORT,
  6894. + TOUCH_WRITE_DATA_TYPE_NO_DATA_USE_DEFAULTS,
  6895. + TOUCH_WRITE_DATA_TYPE_MAX
  6896. +};
  6897. +static_assert(sizeof(enum touch_write_data_type) == 4);
  6898. +
  6899. +struct touch_write_hdr {
  6900. + // Use values from TOUCH_WRITE_DATA_TYPE
  6901. + u32 write_data_type;
  6902. +
  6903. + // This field designates the amount of data to follow
  6904. + u32 write_data_len;
  6905. +};
  6906. +static_assert(sizeof(struct touch_write_hdr) == 8);
  6907. +
  6908. +struct touch_write_data {
  6909. + struct touch_write_hdr header;
  6910. +
  6911. + // used to access the write data as an array and keep the compilers
  6912. + // happy. Actual size of this array is Header.WriteDataLen
  6913. + u8 write_data[1];
  6914. +};
  6915. +
  6916. +#pragma pack()
  6917. +
  6918. +#endif // _IPTS_SENSOR_REGS_H_
  6919. diff --git a/drivers/misc/ipts/state.h b/drivers/misc/ipts/state.h
  6920. new file mode 100644
  6921. index 000000000000..ef73d28db47c
  6922. --- /dev/null
  6923. +++ b/drivers/misc/ipts/state.h
  6924. @@ -0,0 +1,22 @@
  6925. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  6926. +/*
  6927. + *
  6928. + * Intel Precise Touch & Stylus
  6929. + * Copyright (c) 2016 Intel Corporation
  6930. + *
  6931. + */
  6932. +
  6933. +#ifndef _IPTS_STATE_H_
  6934. +#define _IPTS_STATE_H_
  6935. +
  6936. +// IPTS driver states
  6937. +enum ipts_state {
  6938. + IPTS_STA_NONE,
  6939. + IPTS_STA_INIT,
  6940. + IPTS_STA_RESOURCE_READY,
  6941. + IPTS_STA_HID_STARTED,
  6942. + IPTS_STA_RAW_DATA_STARTED,
  6943. + IPTS_STA_STOPPING
  6944. +};
  6945. +
  6946. +#endif // _IPTS_STATE_H_
  6947. diff --git a/drivers/misc/mei/hw-me-regs.h b/drivers/misc/mei/hw-me-regs.h
  6948. index 2ac1dc5104b7..5daa857a4938 100644
  6949. --- a/drivers/misc/mei/hw-me-regs.h
  6950. +++ b/drivers/misc/mei/hw-me-regs.h
  6951. @@ -119,6 +119,7 @@
  6952. #define MEI_DEV_ID_SPT 0x9D3A /* Sunrise Point */
  6953. #define MEI_DEV_ID_SPT_2 0x9D3B /* Sunrise Point 2 */
  6954. +#define MEI_DEV_ID_SPT_4 0x9D3E /* Sunrise Point 4 */
  6955. #define MEI_DEV_ID_SPT_H 0xA13A /* Sunrise Point H */
  6956. #define MEI_DEV_ID_SPT_H_2 0xA13B /* Sunrise Point H 2 */
  6957. diff --git a/drivers/misc/mei/pci-me.c b/drivers/misc/mei/pci-me.c
  6958. index b4bf12f27caf..34f4338fa641 100644
  6959. --- a/drivers/misc/mei/pci-me.c
  6960. +++ b/drivers/misc/mei/pci-me.c
  6961. @@ -86,6 +86,7 @@ static const struct pci_device_id mei_me_pci_tbl[] = {
  6962. {MEI_PCI_DEVICE(MEI_DEV_ID_SPT, MEI_ME_PCH8_CFG)},
  6963. {MEI_PCI_DEVICE(MEI_DEV_ID_SPT_2, MEI_ME_PCH8_CFG)},
  6964. + {MEI_PCI_DEVICE(MEI_DEV_ID_SPT_4, MEI_ME_PCH8_CFG)},
  6965. {MEI_PCI_DEVICE(MEI_DEV_ID_SPT_H, MEI_ME_PCH8_SPS_CFG)},
  6966. {MEI_PCI_DEVICE(MEI_DEV_ID_SPT_H_2, MEI_ME_PCH8_SPS_CFG)},
  6967. {MEI_PCI_DEVICE(MEI_DEV_ID_LBG, MEI_ME_PCH12_CFG)},
  6968. diff --git a/include/linux/ipts-binary.h b/include/linux/ipts-binary.h
  6969. new file mode 100644
  6970. index 000000000000..98b54d74ff88
  6971. --- /dev/null
  6972. +++ b/include/linux/ipts-binary.h
  6973. @@ -0,0 +1,140 @@
  6974. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  6975. +/*
  6976. + *
  6977. + * Intel Precise Touch & Stylus
  6978. + * Copyright (c) 2016 Intel Corporation
  6979. + *
  6980. + */
  6981. +
  6982. +#ifndef IPTS_BINARY_H
  6983. +#define IPTS_BINARY_H
  6984. +
  6985. +#include <linux/ipts.h>
  6986. +#include <linux/types.h>
  6987. +
  6988. +#define IPTS_BIN_HEADER_VERSION 2
  6989. +
  6990. +#pragma pack(1)
  6991. +
  6992. +// we support 16 output buffers (1:feedback, 15:HID)
  6993. +#define MAX_NUM_OUTPUT_BUFFERS 16
  6994. +
  6995. +enum ipts_bin_res_type {
  6996. + IPTS_BIN_KERNEL,
  6997. + IPTS_BIN_RO_DATA,
  6998. + IPTS_BIN_RW_DATA,
  6999. + IPTS_BIN_SENSOR_FRAME,
  7000. + IPTS_BIN_OUTPUT,
  7001. + IPTS_BIN_DYNAMIC_STATE_HEAP,
  7002. + IPTS_BIN_PATCH_LOCATION_LIST,
  7003. + IPTS_BIN_ALLOCATION_LIST,
  7004. + IPTS_BIN_COMMAND_BUFFER_PACKET,
  7005. + IPTS_BIN_TAG,
  7006. +};
  7007. +
  7008. +struct ipts_bin_header {
  7009. + char str[4];
  7010. + u32 version;
  7011. +
  7012. +#if IPTS_BIN_HEADER_VERSION > 1
  7013. + u32 gfxcore;
  7014. + u32 revid;
  7015. +#endif
  7016. +};
  7017. +
  7018. +struct ipts_bin_alloc {
  7019. + u32 handle;
  7020. + u32 reserved;
  7021. +};
  7022. +
  7023. +struct ipts_bin_alloc_list {
  7024. + u32 num;
  7025. + struct ipts_bin_alloc alloc[];
  7026. +};
  7027. +
  7028. +struct ipts_bin_cmdbuf {
  7029. + u32 size;
  7030. + char data[];
  7031. +};
  7032. +
  7033. +struct ipts_bin_res {
  7034. + u32 handle;
  7035. + enum ipts_bin_res_type type;
  7036. + u32 initialize;
  7037. + u32 aligned_size;
  7038. + u32 size;
  7039. + char data[];
  7040. +};
  7041. +
  7042. +enum ipts_bin_io_buffer_type {
  7043. + IPTS_INPUT,
  7044. + IPTS_OUTPUT,
  7045. + IPTS_CONFIGURATION,
  7046. + IPTS_CALIBRATION,
  7047. + IPTS_FEATURE,
  7048. +};
  7049. +
  7050. +struct ipts_bin_io_header {
  7051. + char str[10];
  7052. + u16 type;
  7053. +};
  7054. +
  7055. +struct ipts_bin_res_list {
  7056. + u32 num;
  7057. + struct ipts_bin_res res[];
  7058. +};
  7059. +
  7060. +struct ipts_bin_patch {
  7061. + u32 index;
  7062. + u32 reserved1[2];
  7063. + u32 alloc_offset;
  7064. + u32 patch_offset;
  7065. + u32 reserved2;
  7066. +};
  7067. +
  7068. +struct ipts_bin_patch_list {
  7069. + u32 num;
  7070. + struct ipts_bin_patch patch[];
  7071. +};
  7072. +
  7073. +struct ipts_bin_guc_wq_info {
  7074. + u32 batch_offset;
  7075. + u32 size;
  7076. + char data[];
  7077. +};
  7078. +
  7079. +struct ipts_bin_bufid_patch {
  7080. + u32 imm_offset;
  7081. + u32 mem_offset;
  7082. +};
  7083. +
  7084. +enum ipts_bin_data_file_flags {
  7085. + IPTS_DATA_FILE_FLAG_NONE = 0,
  7086. + IPTS_DATA_FILE_FLAG_SHARE = 1,
  7087. + IPTS_DATA_FILE_FLAG_ALLOC_CONTIGUOUS = 2,
  7088. +};
  7089. +
  7090. +struct ipts_bin_data_file_info {
  7091. + u32 io_buffer_type;
  7092. + u32 flags;
  7093. + char file_name[MAX_IOCL_FILE_NAME_LEN];
  7094. +};
  7095. +
  7096. +struct ipts_bin_fw_info {
  7097. + char fw_name[MAX_IOCL_FILE_NAME_LEN];
  7098. +
  7099. + // output index. -1 for no use
  7100. + s32 vendor_output;
  7101. +
  7102. + u32 num_of_data_files;
  7103. + struct ipts_bin_data_file_info data_file[];
  7104. +};
  7105. +
  7106. +struct ipts_bin_fw_list {
  7107. + u32 num_of_fws;
  7108. + struct ipts_bin_fw_info fw_info[];
  7109. +};
  7110. +
  7111. +#pragma pack()
  7112. +
  7113. +#endif // IPTS_BINARY_H
  7114. diff --git a/include/linux/ipts-companion.h b/include/linux/ipts-companion.h
  7115. new file mode 100644
  7116. index 000000000000..de31f5e0b186
  7117. --- /dev/null
  7118. +++ b/include/linux/ipts-companion.h
  7119. @@ -0,0 +1,29 @@
  7120. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  7121. +/*
  7122. + *
  7123. + * Intel Precise Touch & Stylus
  7124. + * Copyright (c) 2016 Intel Corporation
  7125. + * Copyright (c) 2019 Dorian Stoll
  7126. + *
  7127. + */
  7128. +
  7129. +#ifndef IPTS_COMPANION_H
  7130. +#define IPTS_COMPANION_H
  7131. +
  7132. +#include <linux/firmware.h>
  7133. +#include <linux/ipts-binary.h>
  7134. +
  7135. +struct ipts_companion {
  7136. + int (*firmware_request)(struct ipts_companion *companion,
  7137. + const struct firmware **fw,
  7138. + const char *name, struct device *device);
  7139. +
  7140. + struct ipts_bin_fw_info **firmware_config;
  7141. + void *data;
  7142. + const char *name;
  7143. +};
  7144. +
  7145. +int ipts_add_companion(struct ipts_companion *companion);
  7146. +int ipts_remove_companion(struct ipts_companion *companion);
  7147. +
  7148. +#endif // IPTS_COMPANION_H
  7149. diff --git a/include/linux/ipts-gfx.h b/include/linux/ipts-gfx.h
  7150. new file mode 100644
  7151. index 000000000000..cb9d98fe96e4
  7152. --- /dev/null
  7153. +++ b/include/linux/ipts-gfx.h
  7154. @@ -0,0 +1,86 @@
  7155. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  7156. +/*
  7157. + *
  7158. + * Intel Precise Touch & Stylus
  7159. + * Copyright (c) 2016 Intel Corporation
  7160. + *
  7161. + */
  7162. +
  7163. +#ifndef IPTS_GFX_H
  7164. +#define IPTS_GFX_H
  7165. +
  7166. +enum {
  7167. + IPTS_INTERFACE_V1 = 1,
  7168. +};
  7169. +
  7170. +#define IPTS_BUF_FLAG_CONTIGUOUS 0x01
  7171. +
  7172. +#define IPTS_NOTIFY_STA_BACKLIGHT_OFF 0x00
  7173. +#define IPTS_NOTIFY_STA_BACKLIGHT_ON 0x01
  7174. +
  7175. +struct ipts_mapbuffer {
  7176. + u32 size;
  7177. + u32 flags;
  7178. + void *gfx_addr;
  7179. + void *cpu_addr;
  7180. + u64 buf_handle;
  7181. + u64 phy_addr;
  7182. +};
  7183. +
  7184. +struct ipts_wq_info {
  7185. + u64 db_addr;
  7186. + u64 db_phy_addr;
  7187. + u32 db_cookie_offset;
  7188. + u32 wq_size;
  7189. + u64 wq_addr;
  7190. + u64 wq_phy_addr;
  7191. +
  7192. + // head of wq is managed by GPU
  7193. + u64 wq_head_addr;
  7194. + u64 wq_head_phy_addr;
  7195. +
  7196. + // tail of wq is managed by CSME
  7197. + u64 wq_tail_addr;
  7198. + u64 wq_tail_phy_addr;
  7199. +};
  7200. +
  7201. +struct ipts_ops {
  7202. + int (*get_wq_info)(uint64_t gfx_handle,
  7203. + struct ipts_wq_info *wq_info);
  7204. + int (*map_buffer)(uint64_t gfx_handle,
  7205. + struct ipts_mapbuffer *mapbuffer);
  7206. + int (*unmap_buffer)(uint64_t gfx_handle, uint64_t buf_handle);
  7207. +};
  7208. +
  7209. +struct ipts_callback {
  7210. + void (*workload_complete)(void *data);
  7211. + void (*notify_gfx_status)(u32 status, void *data);
  7212. +};
  7213. +
  7214. +struct ipts_connect {
  7215. + // input: Client device for PM setup
  7216. + struct device *client;
  7217. +
  7218. + // input: Callback addresses
  7219. + struct ipts_callback ipts_cb;
  7220. +
  7221. + // input: Callback data
  7222. + void *data;
  7223. +
  7224. + // input: interface version
  7225. + u32 if_version;
  7226. +
  7227. + // output: GFX version
  7228. + u32 gfx_version;
  7229. +
  7230. + // output: GFX handle
  7231. + u64 gfx_handle;
  7232. +
  7233. + // output: GFX ops for IPTS
  7234. + struct ipts_ops ipts_ops;
  7235. +};
  7236. +
  7237. +int ipts_connect(struct ipts_connect *ipts_connect);
  7238. +void ipts_disconnect(uint64_t gfx_handle);
  7239. +
  7240. +#endif // IPTS_GFX_H
  7241. diff --git a/include/linux/ipts.h b/include/linux/ipts.h
  7242. new file mode 100644
  7243. index 000000000000..f229a3436851
  7244. --- /dev/null
  7245. +++ b/include/linux/ipts.h
  7246. @@ -0,0 +1,19 @@
  7247. +/* SPDX-License-Identifier: GPL-2.0-or-later */
  7248. +/*
  7249. + *
  7250. + * Intel Precise Touch & Stylus
  7251. + * Copyright (c) 2016 Intel Corporation
  7252. + *
  7253. + */
  7254. +
  7255. +#ifndef IPTS_H
  7256. +#define IPTS_H
  7257. +
  7258. +#include <linux/bits.h>
  7259. +
  7260. +#define MAX_IOCL_FILE_NAME_LEN 80
  7261. +#define MAX_IOCL_FILE_PATH_LEN 256
  7262. +
  7263. +#define IPTS_QUIRK_NONE 0
  7264. +
  7265. +#endif // IPTS_H
  7266. --
  7267. 2.33.0