linux-2.6.22.1-008-fusion.patch 171 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265
  1. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/call.c linux-2.6.22.1/drivers/char/fusion/call.c
  2. --- linux-2.6.22.1-0rig/drivers/char/fusion/call.c 1970-01-01 01:00:00.000000000 +0100
  3. +++ linux-2.6.22.1/drivers/char/fusion/call.c 2007-01-20 05:03:01.000000000 +0100
  4. @@ -0,0 +1,478 @@
  5. +/*
  6. + * Fusion Kernel Module
  7. + *
  8. + * (c) Copyright 2002-2003 Convergence GmbH
  9. + *
  10. + * Written by Denis Oliver Kropp <dok@directfb.org>
  11. + *
  12. + *
  13. + * This program is free software; you can redistribute it and/or
  14. + * modify it under the terms of the GNU General Public License
  15. + * as published by the Free Software Foundation; either version
  16. + * 2 of the License, or (at your option) any later version.
  17. + */
  18. +
  19. +#ifdef HAVE_LINUX_CONFIG_H
  20. +#include <linux/config.h>
  21. +#endif
  22. +#include <linux/types.h>
  23. +#include <linux/kernel.h>
  24. +#include <linux/slab.h>
  25. +#include <linux/smp_lock.h>
  26. +#include <linux/sched.h>
  27. +
  28. +#include <linux/fusion.h>
  29. +
  30. +#include "fusiondev.h"
  31. +#include "fusionee.h"
  32. +#include "list.h"
  33. +#include "call.h"
  34. +
  35. +typedef struct {
  36. + FusionLink link;
  37. +
  38. + Fusionee *caller;
  39. +
  40. + int ret_val;
  41. +
  42. + bool executed;
  43. +
  44. + wait_queue_head_t wait;
  45. +} FusionCallExecution;
  46. +
  47. +typedef struct {
  48. + FusionLink link;
  49. +
  50. + struct semaphore lock;
  51. +
  52. + int id; /* call id */
  53. +
  54. + int pid; /* owner pid */
  55. + int fusion_id; /* owner fusion id */
  56. +
  57. + void *handler;
  58. + void *ctx;
  59. +
  60. + FusionLink *executions; /* prepending! */
  61. + FusionLink *last; /* points to the last item of executions */
  62. +
  63. + int count; /* number of calls ever made */
  64. +} FusionCall;
  65. +
  66. +/******************************************************************************/
  67. +
  68. +static int lookup_call (FusionDev *dev, int id, FusionCall **ret_call);
  69. +static int lock_call (FusionDev *dev, int id, FusionCall **ret_call);
  70. +static void unlock_call (FusionCall *call);
  71. +
  72. +static FusionCallExecution *add_execution (FusionCall *call,
  73. + Fusionee *caller,
  74. + FusionCallExecute *execute);
  75. +static void remove_execution (FusionCall *call,
  76. + FusionCallExecution *execution);
  77. +static void free_all_executions (FusionCall *call);
  78. +
  79. +/******************************************************************************/
  80. +
  81. +static int
  82. +fusion_call_read_proc (char *buf, char **start, off_t offset,
  83. + int len, int *eof, void *private)
  84. +{
  85. + FusionLink *l, *e;
  86. + FusionDev *dev = private;
  87. + int written = 0;
  88. +
  89. + if (down_interruptible (&dev->call.lock))
  90. + return -EINTR;
  91. +
  92. + fusion_list_foreach (l, dev->call.list) {
  93. + bool idle = true;
  94. + FusionCall *call = (FusionCall*) l;
  95. +
  96. + if (call->executions)
  97. + idle = ((FusionCallExecution*) call->executions)->executed;
  98. +
  99. + written += sprintf(buf+written,
  100. + "(%5d) 0x%08x (%d calls) %s",
  101. + call->pid, call->id, call->count,
  102. + idle ? "idle" : "executing");
  103. +
  104. + fusion_list_foreach (e, call->executions) {
  105. + FusionCallExecution *exec = (FusionCallExecution *) e;
  106. +
  107. + written += sprintf(buf+written, " [0x%08lx]", exec->caller ? fusionee_id( exec->caller ) : 0);
  108. + }
  109. +
  110. + written += sprintf(buf+written, "\n");
  111. +
  112. + if (written < offset) {
  113. + offset -= written;
  114. + written = 0;
  115. + }
  116. +
  117. + if (written >= len)
  118. + break;
  119. + }
  120. +
  121. + up (&dev->call.lock);
  122. +
  123. + *start = buf + offset;
  124. + written -= offset;
  125. + if (written > len) {
  126. + *eof = 0;
  127. + return len;
  128. + }
  129. +
  130. + *eof = 1;
  131. + return(written<0) ? 0 : written;
  132. +}
  133. +
  134. +int
  135. +fusion_call_init (FusionDev *dev)
  136. +{
  137. + create_proc_read_entry("calls", 0, dev->proc_dir,
  138. + fusion_call_read_proc, dev);
  139. +
  140. + init_MUTEX(&dev->call.lock);
  141. +
  142. + return 0;
  143. +}
  144. +
  145. +void
  146. +fusion_call_deinit (FusionDev *dev)
  147. +{
  148. + FusionLink *l;
  149. +
  150. + down (&dev->call.lock);
  151. +
  152. + remove_proc_entry ("calls", dev->proc_dir);
  153. +
  154. + l = dev->call.list;
  155. + while (l) {
  156. + FusionLink *next = l->next;
  157. + FusionCall *call = (FusionCall *) l;
  158. +
  159. + free_all_executions (call);
  160. +
  161. + kfree (call);
  162. +
  163. + l = next;
  164. + }
  165. +
  166. + up (&dev->call.lock);
  167. +}
  168. +
  169. +/******************************************************************************/
  170. +
  171. +int
  172. +fusion_call_new (FusionDev *dev, int fusion_id, FusionCallNew *call_new)
  173. +{
  174. + FusionCall *call;
  175. +
  176. + call = kmalloc (sizeof(FusionCall), GFP_KERNEL);
  177. + if (!call)
  178. + return -ENOMEM;
  179. +
  180. + memset (call, 0, sizeof(FusionCall));
  181. +
  182. + if (down_interruptible (&dev->call.lock)) {
  183. + kfree (call);
  184. + return -EINTR;
  185. + }
  186. +
  187. + call->id = dev->call.ids++;
  188. + call->pid = current->pid;
  189. + call->fusion_id = fusion_id;
  190. + call->handler = call_new->handler;
  191. + call->ctx = call_new->ctx;
  192. +
  193. + init_MUTEX (&call->lock);
  194. +
  195. + fusion_list_prepend (&dev->call.list, &call->link);
  196. +
  197. + up (&dev->call.lock);
  198. +
  199. + call_new->call_id = call->id;
  200. +
  201. + return 0;
  202. +}
  203. +
  204. +int
  205. +fusion_call_execute (FusionDev *dev, Fusionee *fusionee, FusionCallExecute *execute)
  206. +{
  207. + int ret;
  208. + FusionCall *call;
  209. + FusionCallExecution *execution;
  210. + FusionCallMessage message;
  211. +
  212. + ret = lock_call (dev, execute->call_id, &call);
  213. + if (ret)
  214. + return ret;
  215. +
  216. + execution = add_execution (call, fusionee, execute);
  217. + if (!execution) {
  218. + unlock_call (call);
  219. + return -ENOMEM;
  220. + }
  221. +
  222. + /* Send call message. */
  223. + message.handler = call->handler;
  224. + message.ctx = call->ctx;
  225. +
  226. + message.caller = fusionee ? fusionee_id( fusionee ) : 0;
  227. +
  228. + message.call_arg = execute->call_arg;
  229. + message.call_ptr = execute->call_ptr;
  230. +
  231. + ret = fusionee_send_message (dev, fusionee, call->fusion_id, FMT_CALL,
  232. + call->id, sizeof(message), &message);
  233. + if (ret) {
  234. + remove_execution (call, execution);
  235. + kfree (execution);
  236. + unlock_call (call);
  237. + return ret;
  238. + }
  239. +
  240. + call->count++;
  241. +
  242. + if (fusionee && !(execute->flags & FCEF_ONEWAY)) {
  243. + /* TODO: implement timeout */
  244. + fusion_sleep_on (&execution->wait, &call->lock, 0);
  245. +
  246. + ret = lock_call (dev, execute->call_id, &call);
  247. + if (ret)
  248. + return ret == -EINVAL ? -EIDRM : ret;
  249. +
  250. + if (signal_pending(current)) {
  251. + execution->caller = 0;
  252. + unlock_call (call);
  253. + return -EINTR;
  254. + }
  255. +
  256. + execute->ret_val = execution->ret_val;
  257. +
  258. + remove_execution (call, execution);
  259. +
  260. + kfree (execution);
  261. + }
  262. +
  263. + unlock_call (call);
  264. +
  265. + return 0;
  266. +}
  267. +
  268. +int
  269. +fusion_call_return (FusionDev *dev, int fusion_id, FusionCallReturn *call_ret)
  270. +{
  271. + int ret;
  272. + FusionLink *l;
  273. + FusionCall *call;
  274. +
  275. + ret = lock_call (dev, call_ret->call_id, &call);
  276. + if (ret)
  277. + return ret;
  278. +
  279. + l = call->last;
  280. + while (l) {
  281. + FusionCallExecution *execution = (FusionCallExecution*) l;
  282. +
  283. + if (execution->executed) {
  284. + l = l->prev;
  285. + continue;
  286. + }
  287. +
  288. + if (execution->caller) {
  289. + execution->ret_val = call_ret->val;
  290. + execution->executed = true;
  291. +
  292. + wake_up_interruptible_all (&execution->wait);
  293. + }
  294. + else {
  295. + remove_execution (call, execution);
  296. +
  297. + kfree (execution);
  298. + }
  299. +
  300. + unlock_call (call);
  301. +
  302. + return 0;
  303. + }
  304. +
  305. + unlock_call (call);
  306. +
  307. + return -EIO;
  308. +}
  309. +
  310. +int
  311. +fusion_call_destroy (FusionDev *dev, int fusion_id, int call_id)
  312. +{
  313. + int ret;
  314. + FusionCall *call;
  315. +
  316. + ret = lookup_call (dev, call_id, &call);
  317. + if (ret)
  318. + return ret;
  319. +
  320. + if (call->fusion_id != fusion_id) {
  321. + up (&dev->call.lock);
  322. + return -EIO;
  323. + }
  324. +
  325. + if (down_interruptible (&call->lock)) {
  326. + up (&dev->call.lock);
  327. + return -EINTR;
  328. + }
  329. +
  330. + fusion_list_remove (&dev->call.list, &call->link);
  331. +
  332. + free_all_executions (call);
  333. +
  334. + up (&dev->call.lock);
  335. +
  336. + up (&call->lock);
  337. +
  338. + kfree (call);
  339. +
  340. + return 0;
  341. +}
  342. +
  343. +void
  344. +fusion_call_destroy_all (FusionDev *dev, int fusion_id)
  345. +{
  346. + FusionLink *l;
  347. +
  348. + down (&dev->call.lock);
  349. +
  350. + l = dev->call.list;
  351. +
  352. + while (l) {
  353. + FusionLink *next = l->next;
  354. + FusionCall *call = (FusionCall *) l;
  355. +
  356. + down (&call->lock);
  357. +
  358. + if (call->fusion_id == fusion_id) {
  359. + free_all_executions (call);
  360. +
  361. + fusion_list_remove (&dev->call.list, &call->link);
  362. +
  363. + up (&call->lock);
  364. +
  365. + kfree (call);
  366. + }
  367. + else
  368. + up (&call->lock);
  369. +
  370. + l = next;
  371. + }
  372. +
  373. + up (&dev->call.lock);
  374. +}
  375. +
  376. +/******************************************************************************/
  377. +
  378. +static int
  379. +lookup_call (FusionDev *dev, int id, FusionCall **ret_call)
  380. +{
  381. + FusionLink *l;
  382. +
  383. + if (down_interruptible (&dev->call.lock))
  384. + return -EINTR;
  385. +
  386. + fusion_list_foreach (l, dev->call.list) {
  387. + FusionCall *call = (FusionCall *) l;
  388. +
  389. + if (call->id == id) {
  390. + *ret_call = call;
  391. + return 0;
  392. + }
  393. + }
  394. +
  395. + up (&dev->call.lock);
  396. +
  397. + return -EINVAL;
  398. +}
  399. +
  400. +static int
  401. +lock_call (FusionDev *dev, int id, FusionCall **ret_call)
  402. +{
  403. + int ret;
  404. + FusionCall *call;
  405. +
  406. + ret = lookup_call (dev, id, &call);
  407. + if (ret)
  408. + return ret;
  409. +
  410. + if (call) {
  411. + fusion_list_move_to_front (&dev->call.list, &call->link);
  412. +
  413. + if (down_interruptible (&call->lock)) {
  414. + up (&dev->call.lock);
  415. + return -EINTR;
  416. + }
  417. +
  418. + up (&dev->call.lock);
  419. + }
  420. +
  421. + *ret_call = call;
  422. +
  423. + return 0;
  424. +}
  425. +
  426. +static void
  427. +unlock_call (FusionCall *call)
  428. +{
  429. + up (&call->lock);
  430. +}
  431. +
  432. +static FusionCallExecution *
  433. +add_execution (FusionCall *call,
  434. + Fusionee *caller,
  435. + FusionCallExecute *execute)
  436. +{
  437. + FusionCallExecution *execution;
  438. +
  439. + /* Allocate execution. */
  440. + execution = kmalloc (sizeof(FusionCallExecution), GFP_KERNEL);
  441. + if (!execution)
  442. + return NULL;
  443. +
  444. + /* Initialize execution. */
  445. + memset (execution, 0, sizeof(FusionCallExecution));
  446. +
  447. + execution->caller = caller;
  448. +
  449. + init_waitqueue_head (&execution->wait);
  450. +
  451. + /* Add execution. */
  452. + fusion_list_prepend (&call->executions, &execution->link);
  453. +
  454. + if (!call->last)
  455. + call->last = &execution->link;
  456. +
  457. + return execution;
  458. +}
  459. +
  460. +static void
  461. +remove_execution (FusionCall *call,
  462. + FusionCallExecution *execution)
  463. +{
  464. + if (call->last == &execution->link)
  465. + call->last = execution->link.prev;
  466. +
  467. + fusion_list_remove (&call->executions, &execution->link);
  468. +}
  469. +
  470. +static void
  471. +free_all_executions (FusionCall *call)
  472. +{
  473. + while (call->last) {
  474. + FusionCallExecution *execution = (FusionCallExecution *) call->last;
  475. +
  476. + remove_execution (call, execution);
  477. +
  478. + wake_up_interruptible_all (&execution->wait);
  479. +
  480. + kfree (execution);
  481. + }
  482. +}
  483. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/call.h linux-2.6.22.1/drivers/char/fusion/call.h
  484. --- linux-2.6.22.1-0rig/drivers/char/fusion/call.h 1970-01-01 01:00:00.000000000 +0100
  485. +++ linux-2.6.22.1/drivers/char/fusion/call.h 2007-01-20 05:03:01.000000000 +0100
  486. @@ -0,0 +1,52 @@
  487. +/*
  488. + * Fusion Kernel Module
  489. + *
  490. + * (c) Copyright 2002-2003 Convergence GmbH
  491. + *
  492. + * Written by Denis Oliver Kropp <dok@directfb.org>
  493. + *
  494. + *
  495. + * This program is free software; you can redistribute it and/or
  496. + * modify it under the terms of the GNU General Public License
  497. + * as published by the Free Software Foundation; either version
  498. + * 2 of the License, or (at your option) any later version.
  499. + */
  500. +
  501. +#ifndef __FUSION__CALL_H__
  502. +#define __FUSION__CALL_H__
  503. +
  504. +#include <linux/fusion.h>
  505. +
  506. +#include "fusiondev.h"
  507. +
  508. +/* module init/cleanup */
  509. +
  510. +int fusion_call_init (FusionDev *dev);
  511. +void fusion_call_deinit (FusionDev *dev);
  512. +
  513. +
  514. +/* public API */
  515. +
  516. +int fusion_call_new (FusionDev *dev,
  517. + int fusion_id,
  518. + FusionCallNew *call);
  519. +
  520. +int fusion_call_execute (FusionDev *dev,
  521. + Fusionee *fusionee, /* NULL if call is from kernel */
  522. + FusionCallExecute *execute);
  523. +
  524. +int fusion_call_return (FusionDev *dev,
  525. + int fusion_id,
  526. + FusionCallReturn *call_ret);
  527. +
  528. +int fusion_call_destroy (FusionDev *dev,
  529. + int fusion_id,
  530. + int call_id);
  531. +
  532. +
  533. +/* internal functions */
  534. +
  535. +void fusion_call_destroy_all (FusionDev *dev,
  536. + int fusion_id);
  537. +
  538. +#endif
  539. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/.cvsignore linux-2.6.22.1/drivers/char/fusion/.cvsignore
  540. --- linux-2.6.22.1-0rig/drivers/char/fusion/.cvsignore 1970-01-01 01:00:00.000000000 +0100
  541. +++ linux-2.6.22.1/drivers/char/fusion/.cvsignore 2005-10-29 07:11:10.000000000 +0200
  542. @@ -0,0 +1,6 @@
  543. +*.o.flags
  544. +*.cmd
  545. +Makefile
  546. +fusion.ko
  547. +fusion.mod.c
  548. +.tmp_versions
  549. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/entries.c linux-2.6.22.1/drivers/char/fusion/entries.c
  550. --- linux-2.6.22.1-0rig/drivers/char/fusion/entries.c 1970-01-01 01:00:00.000000000 +0100
  551. +++ linux-2.6.22.1/drivers/char/fusion/entries.c 2007-03-08 14:02:04.000000000 +0100
  552. @@ -0,0 +1,438 @@
  553. +/*
  554. + * Fusion Kernel Module
  555. + *
  556. + * (c) Copyright 2002-2003 Convergence GmbH
  557. + *
  558. + * Written by Denis Oliver Kropp <dok@directfb.org>
  559. + *
  560. + *
  561. + * This program is free software; you can redistribute it and/or
  562. + * modify it under the terms of the GNU General Public License
  563. + * as published by the Free Software Foundation; either version
  564. + * 2 of the License, or (at your option) any later version.
  565. + */
  566. +
  567. +#ifdef HAVE_LINUX_CONFIG_H
  568. +#include <linux/config.h>
  569. +#endif
  570. +#include <linux/types.h>
  571. +#include <linux/kernel.h>
  572. +#include <linux/slab.h>
  573. +#include <linux/smp_lock.h>
  574. +#include <linux/sched.h>
  575. +#include <linux/time.h>
  576. +#include <linux/version.h>
  577. +
  578. +#include <linux/fusion.h>
  579. +
  580. +#include "fusiondev.h"
  581. +#include "entries.h"
  582. +
  583. +
  584. +void
  585. +fusion_entries_init( FusionEntries *entries,
  586. + FusionEntryClass *class,
  587. + void *ctx )
  588. +{
  589. + FUSION_ASSERT( entries != NULL );
  590. + FUSION_ASSERT( class != NULL );
  591. + FUSION_ASSERT( class->object_size >= sizeof(FusionEntry) );
  592. +
  593. + memset( entries, 0, sizeof(FusionEntries) );
  594. +
  595. + entries->class = class;
  596. + entries->ctx = ctx;
  597. +
  598. + init_MUTEX( &entries->lock );
  599. +}
  600. +
  601. +void
  602. +fusion_entries_deinit( FusionEntries *entries )
  603. +{
  604. + FusionLink *tmp;
  605. + FusionEntry *entry;
  606. + FusionEntryClass *class;
  607. +
  608. + FUSION_ASSERT( entries != NULL );
  609. + FUSION_ASSERT( entries->class != NULL );
  610. +
  611. + class = entries->class;
  612. +
  613. + down( &entries->lock );
  614. +
  615. + fusion_list_foreach_safe (entry, tmp, entries->list) {
  616. + if (class->Destroy)
  617. + class->Destroy( entry, entries->ctx );
  618. +
  619. + kfree( entry );
  620. + }
  621. +
  622. + up( &entries->lock );
  623. +}
  624. +
  625. +int
  626. +fusion_entries_read_proc(char *buf, char **start, off_t offset,
  627. + int len, int *eof, void *private)
  628. +{
  629. + FusionEntry *entry;
  630. + FusionEntryClass *class;
  631. + FusionEntries *entries = private;
  632. + int written = 0;
  633. + struct timeval now;
  634. +
  635. + FUSION_ASSERT( entries != NULL );
  636. + FUSION_ASSERT( entries->class != NULL );
  637. +
  638. + class = entries->class;
  639. +
  640. + if (!class->Print)
  641. + return -ENOTSUPP;
  642. +
  643. + if (down_interruptible (&entries->lock))
  644. + return -EINTR;
  645. +
  646. + do_gettimeofday( &now );
  647. +
  648. + fusion_list_foreach (entry, entries->list) {
  649. + if (entry->last_lock.tv_sec) {
  650. + int diff = ((now.tv_sec - entry->last_lock.tv_sec) * 1000 +
  651. + (now.tv_usec - entry->last_lock.tv_usec) / 1000);
  652. +
  653. + if (diff < 1000) {
  654. + written += sprintf( buf + written, "%3d ms ", diff );
  655. + }
  656. + else if (diff < 1000000) {
  657. + written += sprintf( buf + written, "%3d.%d s ",
  658. + diff / 1000, (diff % 1000) / 100 );
  659. + }
  660. + else {
  661. + diff = ( now.tv_sec - entry->last_lock.tv_sec +
  662. + (now.tv_usec - entry->last_lock.tv_usec) / 1000000);
  663. +
  664. + written += sprintf( buf + written, "%3d.%d h ",
  665. + diff / 3600, (diff % 3600) / 360 );
  666. + }
  667. + }
  668. + else
  669. + written += sprintf( buf + written, " -.- " );
  670. +
  671. +
  672. + written += sprintf( buf + written, "(%5d) 0x%08x ", entry->pid, entry->id );
  673. +
  674. + written += sprintf( buf + written, "%-24s ", entry->name[0] ? entry->name : "" );
  675. +
  676. + written += class->Print( entry, entries->ctx, buf + written );
  677. +
  678. + if (written < offset) {
  679. + offset -= written;
  680. + written = 0;
  681. + }
  682. +
  683. + if (written >= len)
  684. + break;
  685. + }
  686. +
  687. + up (&entries->lock);
  688. +
  689. + *start = buf + offset;
  690. + written -= offset;
  691. + if (written > len) {
  692. + *eof = 0;
  693. + return len;
  694. + }
  695. +
  696. + *eof = 1;
  697. +
  698. + return (written<0) ? 0 : written;
  699. +}
  700. +
  701. +int
  702. +fusion_entry_create( FusionEntries *entries,
  703. + int *ret_id,
  704. + void *create_ctx )
  705. +{
  706. + int ret;
  707. + FusionEntry *entry;
  708. + FusionEntryClass *class;
  709. +
  710. + FUSION_ASSERT( entries != NULL );
  711. + FUSION_ASSERT( entries->class != NULL );
  712. + FUSION_ASSERT( ret_id != NULL );
  713. +
  714. + class = entries->class;
  715. +
  716. + entry = kmalloc( class->object_size, GFP_KERNEL );
  717. + if (!entry)
  718. + return -ENOMEM;
  719. +
  720. + memset( entry, 0, class->object_size );
  721. +
  722. + if (down_interruptible( &entries->lock )) {
  723. + kfree( entry );
  724. + return -EINTR;
  725. + }
  726. +
  727. + entry->entries = entries;
  728. + entry->id = entries->ids++;
  729. + entry->pid = current->pid;
  730. +
  731. + init_MUTEX( &entry->lock );
  732. +
  733. + init_waitqueue_head( &entry->wait );
  734. +
  735. + if (class->Init) {
  736. + ret = class->Init( entry, entries->ctx, create_ctx );
  737. + if (ret) {
  738. + up( &entries->lock );
  739. + kfree( entry );
  740. + return ret;
  741. + }
  742. + }
  743. +
  744. + fusion_list_prepend( &entries->list, &entry->link );
  745. +
  746. + up( &entries->lock );
  747. +
  748. + *ret_id = entry->id;
  749. +
  750. + return 0;
  751. +}
  752. +
  753. +int
  754. +fusion_entry_destroy( FusionEntries *entries,
  755. + int id )
  756. +{
  757. + FusionEntry *entry;
  758. + FusionEntryClass *class;
  759. +
  760. + FUSION_ASSERT( entries != NULL );
  761. + FUSION_ASSERT( entries->class != NULL );
  762. +
  763. + class = entries->class;
  764. +
  765. + /* Lock entries. */
  766. + if (down_interruptible( &entries->lock ))
  767. + return -EINTR;
  768. +
  769. + /* Lookup the entry. */
  770. + fusion_list_foreach (entry, entries->list) {
  771. + if (entry->id == id)
  772. + break;
  773. + }
  774. +
  775. + /* Check if no entry was found. */
  776. + if (!entry) {
  777. + up( &entries->lock );
  778. + return -EINVAL;
  779. + }
  780. +
  781. + /* Lock the entry. */
  782. + if (down_interruptible( &entry->lock )) {
  783. + up( &entries->lock );
  784. + return -EINTR;
  785. + }
  786. +
  787. + /* Destroy it now. */
  788. + fusion_entry_destroy_locked( entries, entry );
  789. +
  790. + /* Unlock entries. */
  791. + up( &entries->lock );
  792. +
  793. + return 0;
  794. +}
  795. +
  796. +void
  797. +fusion_entry_destroy_locked( FusionEntries *entries,
  798. + FusionEntry *entry )
  799. +{
  800. + FusionEntryClass *class;
  801. +
  802. + FUSION_ASSERT( entries != NULL );
  803. + FUSION_ASSERT( entries->class != NULL );
  804. +
  805. + class = entries->class;
  806. +
  807. + /* Remove the entry from the list. */
  808. + fusion_list_remove( &entries->list, &entry->link );
  809. +
  810. + /* Wake up any waiting process. */
  811. + wake_up_interruptible_all( &entry->wait );
  812. +
  813. + /* Call the destroy function. */
  814. + if (class->Destroy)
  815. + class->Destroy( entry, entries->ctx );
  816. +
  817. + /* Unlock the entry. */
  818. + up( &entry->lock );
  819. +
  820. + /* Deallocate the entry. */
  821. + kfree( entry );
  822. +}
  823. +
  824. +int
  825. +fusion_entry_set_info( FusionEntries *entries,
  826. + const FusionEntryInfo *info )
  827. +{
  828. + int ret;
  829. + FusionEntry *entry;
  830. +
  831. + FUSION_ASSERT( entries != NULL );
  832. + FUSION_ASSERT( info != NULL );
  833. +
  834. + ret = fusion_entry_lock( entries, info->id, false, &entry );
  835. + if (ret)
  836. + return ret;
  837. +
  838. + snprintf( entry->name, FUSION_ENTRY_INFO_NAME_LENGTH, info->name );
  839. +
  840. + fusion_entry_unlock( entry );
  841. +
  842. + return 0;
  843. +}
  844. +
  845. +int
  846. +fusion_entry_get_info( FusionEntries *entries,
  847. + FusionEntryInfo *info )
  848. +{
  849. + int ret;
  850. + FusionEntry *entry;
  851. +
  852. + FUSION_ASSERT( entries != NULL );
  853. + FUSION_ASSERT( info != NULL );
  854. +
  855. + ret = fusion_entry_lock( entries, info->id, false, &entry );
  856. + if (ret)
  857. + return ret;
  858. +
  859. + snprintf( info->name, FUSION_ENTRY_INFO_NAME_LENGTH, entry->name );
  860. +
  861. + fusion_entry_unlock( entry );
  862. +
  863. + return 0;
  864. +}
  865. +
  866. +int
  867. +fusion_entry_lock( FusionEntries *entries,
  868. + int id,
  869. + bool keep_entries_lock,
  870. + FusionEntry **ret_entry )
  871. +{
  872. + FusionEntry *entry;
  873. +
  874. + FUSION_ASSERT( entries != NULL );
  875. + FUSION_ASSERT( ret_entry != NULL );
  876. +
  877. + /* Lock entries. */
  878. + if (down_interruptible( &entries->lock ))
  879. + return -EINTR;
  880. +
  881. + /* Lookup the entry. */
  882. + fusion_list_foreach (entry, entries->list) {
  883. + if (entry->id == id)
  884. + break;
  885. + }
  886. +
  887. + /* Check if no entry was found. */
  888. + if (!entry) {
  889. + up( &entries->lock );
  890. + return -EINVAL;
  891. + }
  892. +
  893. + FUSION_ASSUME( entry->lock_pid != current->pid );
  894. +
  895. + /* Move the entry to the front of all entries. */
  896. + fusion_list_move_to_front( &entries->list, &entry->link );
  897. +
  898. + /* Lock the entry. */
  899. + if (down_interruptible( &entry->lock )) {
  900. + up( &entries->lock );
  901. + return -EINTR;
  902. + }
  903. +
  904. + /* Mark as locked. */
  905. + entry->lock_pid = current->pid;
  906. +
  907. + /* Keep timestamp, but use the slightly
  908. + inexact version to avoid performance impacts. */
  909. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) && defined _STRUCT_TIMESPEC
  910. + entry->last_lock.tv_sec = xtime.tv_sec;
  911. + entry->last_lock.tv_usec = xtime.tv_nsec / 1000;
  912. +#else
  913. + entry->last_lock = xtime;
  914. +#endif
  915. +
  916. + /* Unlock entries. */
  917. + if (!keep_entries_lock)
  918. + up( &entries->lock );
  919. +
  920. + /* Return the locked entry. */
  921. + *ret_entry = entry;
  922. +
  923. + return 0;
  924. +}
  925. +
  926. +void
  927. +fusion_entry_unlock( FusionEntry *entry )
  928. +{
  929. + FUSION_ASSERT( entry != NULL );
  930. + FUSION_ASSUME( entry->lock_pid == current->pid );
  931. +
  932. + entry->lock_pid = 0;
  933. +
  934. + /* Unlock the entry. */
  935. + up( &entry->lock );
  936. +}
  937. +
  938. +int
  939. +fusion_entry_wait( FusionEntry *entry, long *timeout )
  940. +{
  941. + int ret;
  942. + int id;
  943. + FusionEntries *entries;
  944. + FusionEntry *entry2;
  945. +
  946. + FUSION_ASSERT( entry != NULL );
  947. + FUSION_ASSERT( entry->entries != NULL );
  948. + FUSION_ASSUME( entry->lock_pid == current->pid );
  949. +
  950. + id = entry->id;
  951. + entries = entry->entries;
  952. +
  953. + entry->waiters++;
  954. +
  955. + entry->lock_pid = 0;
  956. + fusion_sleep_on( &entry->wait, &entry->lock, timeout );
  957. +
  958. + entry->waiters--;
  959. +
  960. + if (signal_pending(current))
  961. + return -EINTR;
  962. +
  963. + if (timeout && !*timeout)
  964. + return -ETIMEDOUT;
  965. +
  966. + ret = fusion_entry_lock( entries, id, false, &entry2 );
  967. + switch (ret) {
  968. + case -EINVAL:
  969. + return -EIDRM;
  970. +
  971. + case 0:
  972. + if (entry != entry2)
  973. + BUG();
  974. + }
  975. +
  976. + return ret;
  977. +}
  978. +
  979. +void
  980. +fusion_entry_notify( FusionEntry *entry, bool all )
  981. +{
  982. + FUSION_ASSERT( entry != NULL );
  983. + FUSION_ASSUME( entry->lock_pid == current->pid );
  984. +
  985. + if (all)
  986. + wake_up_interruptible_all( &entry->wait );
  987. + else
  988. + wake_up_interruptible( &entry->wait );
  989. +}
  990. +
  991. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/entries.h linux-2.6.22.1/drivers/char/fusion/entries.h
  992. --- linux-2.6.22.1-0rig/drivers/char/fusion/entries.h 1970-01-01 01:00:00.000000000 +0100
  993. +++ linux-2.6.22.1/drivers/char/fusion/entries.h 2006-09-03 13:50:55.000000000 +0200
  994. @@ -0,0 +1,179 @@
  995. +/*
  996. + * Fusion Kernel Module
  997. + *
  998. + * (c) Copyright 2002-2003 Convergence GmbH
  999. + *
  1000. + * Written by Denis Oliver Kropp <dok@directfb.org>
  1001. + *
  1002. + *
  1003. + * This program is free software; you can redistribute it and/or
  1004. + * modify it under the terms of the GNU General Public License
  1005. + * as published by the Free Software Foundation; either version
  1006. + * 2 of the License, or (at your option) any later version.
  1007. + */
  1008. +
  1009. +#ifndef __FUSION__ENTRIES_H__
  1010. +#define __FUSION__ENTRIES_H__
  1011. +
  1012. +#include "types.h"
  1013. +#include "list.h"
  1014. +
  1015. +
  1016. +typedef struct __FD_FusionEntry FusionEntry;
  1017. +
  1018. +
  1019. +typedef const struct {
  1020. + int object_size;
  1021. +
  1022. + int (*Init) ( FusionEntry *entry, void *ctx, void *create_ctx );
  1023. + void (*Destroy)( FusionEntry *entry, void *ctx );
  1024. + int (*Print) ( FusionEntry *entry, void *ctx, char *buf );
  1025. +} FusionEntryClass;
  1026. +
  1027. +
  1028. +typedef struct {
  1029. + FusionEntryClass *class;
  1030. + void *ctx;
  1031. +
  1032. + FusionLink *list;
  1033. + int ids;
  1034. + struct semaphore lock;
  1035. +} FusionEntries;
  1036. +
  1037. +
  1038. +struct __FD_FusionEntry {
  1039. + FusionLink link;
  1040. +
  1041. + FusionEntries *entries;
  1042. +
  1043. + int id;
  1044. + pid_t pid;
  1045. +
  1046. + pid_t lock_pid;
  1047. +
  1048. + struct semaphore lock;
  1049. + wait_queue_head_t wait;
  1050. + int waiters;
  1051. +
  1052. + struct timeval last_lock;
  1053. +
  1054. + char name[FUSION_ENTRY_INFO_NAME_LENGTH];
  1055. +};
  1056. +
  1057. +
  1058. +/* Entries Init & DeInit */
  1059. +
  1060. +void fusion_entries_init ( FusionEntries *entries,
  1061. + FusionEntryClass *class,
  1062. + void *ctx );
  1063. +
  1064. +void fusion_entries_deinit( FusionEntries *entries );
  1065. +
  1066. +
  1067. +/* '/proc' support */
  1068. +
  1069. +int fusion_entries_read_proc( char *buf, char **start, off_t offset,
  1070. + int len, int *eof, void *private );
  1071. +
  1072. +
  1073. +/* Create & Destroy */
  1074. +
  1075. +int fusion_entry_create ( FusionEntries *entries,
  1076. + int *ret_id,
  1077. + void *create_ctx );
  1078. +
  1079. +int fusion_entry_destroy ( FusionEntries *entries,
  1080. + int id );
  1081. +
  1082. +void fusion_entry_destroy_locked( FusionEntries *entries,
  1083. + FusionEntry *entry );
  1084. +
  1085. +/* Information */
  1086. +
  1087. +int fusion_entry_set_info( FusionEntries *entries,
  1088. + const FusionEntryInfo *info );
  1089. +
  1090. +int fusion_entry_get_info( FusionEntries *entries,
  1091. + FusionEntryInfo *info );
  1092. +
  1093. +
  1094. +/* Lock & Unlock */
  1095. +
  1096. +int fusion_entry_lock ( FusionEntries *entries,
  1097. + int id,
  1098. + bool keep_entries_lock,
  1099. + FusionEntry **ret_entry );
  1100. +
  1101. +void fusion_entry_unlock ( FusionEntry *entry );
  1102. +
  1103. +
  1104. +/** Wait & Notify **/
  1105. +
  1106. +/*
  1107. + * Wait for the entry to be notified with an optional timeout.
  1108. + *
  1109. + * The entry
  1110. + * (1) has to be locked prior to calling this function.
  1111. + * (2) is temporarily unlocked while being waited for.
  1112. + *
  1113. + * If this function returns an error, the entry is not locked again!
  1114. + *
  1115. + * Possible errors are:
  1116. + * -EIDRM Entry has been removed while being waited for.
  1117. + * -ETIMEDOUT Timeout occured.
  1118. + * -EINTR A signal has been received.
  1119. + */
  1120. +int fusion_entry_wait ( FusionEntry *entry,
  1121. + long *timeout );
  1122. +
  1123. +/*
  1124. + * Wake up one or all processes waiting for the entry to be notified.
  1125. + *
  1126. + * The entry has to be locked prior to calling this function.
  1127. + */
  1128. +void fusion_entry_notify ( FusionEntry *entry,
  1129. + bool all );
  1130. +
  1131. +
  1132. +#define FUSION_ENTRY_CLASS( Type, name, init_func, destroy_func, print_func ) \
  1133. + \
  1134. + static FusionEntryClass name##_class = { \
  1135. + .object_size = sizeof(Type), \
  1136. + .Init = init_func, \
  1137. + .Destroy = destroy_func, \
  1138. + .Print = print_func \
  1139. + }; \
  1140. + \
  1141. + static inline int fusion_##name##_lock( FusionEntries *entries, \
  1142. + int id, \
  1143. + bool keep, \
  1144. + Type **ret_##name ) \
  1145. + { \
  1146. + int ret; \
  1147. + FusionEntry *entry; \
  1148. + \
  1149. + ret = fusion_entry_lock( entries, id, keep, &entry ); \
  1150. + \
  1151. + if (!ret) \
  1152. + *ret_##name = (Type *) entry; \
  1153. + \
  1154. + return ret; \
  1155. + } \
  1156. + \
  1157. + static inline void fusion_##name##_unlock( Type *name ) \
  1158. + { \
  1159. + fusion_entry_unlock( (FusionEntry*) name ); \
  1160. + } \
  1161. + \
  1162. + static inline int fusion_##name##_wait( Type *name, long *timeout ) \
  1163. + { \
  1164. + return fusion_entry_wait( (FusionEntry*) name, timeout ); \
  1165. + } \
  1166. + \
  1167. + static inline void fusion_##name##_notify( Type *name, bool all ) \
  1168. + { \
  1169. + fusion_entry_notify( (FusionEntry*) name, all ); \
  1170. + }
  1171. +
  1172. +
  1173. +#endif
  1174. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/fifo.c linux-2.6.22.1/drivers/char/fusion/fifo.c
  1175. --- linux-2.6.22.1-0rig/drivers/char/fusion/fifo.c 1970-01-01 01:00:00.000000000 +0100
  1176. +++ linux-2.6.22.1/drivers/char/fusion/fifo.c 2003-06-16 19:47:03.000000000 +0200
  1177. @@ -0,0 +1,53 @@
  1178. +/*
  1179. + * Fusion Kernel Module
  1180. + *
  1181. + * (c) Copyright 2002-2003 Convergence GmbH
  1182. + *
  1183. + * Written by Denis Oliver Kropp <dok@directfb.org>
  1184. + *
  1185. + *
  1186. + * This program is free software; you can redistribute it and/or
  1187. + * modify it under the terms of the GNU General Public License
  1188. + * as published by the Free Software Foundation; either version
  1189. + * 2 of the License, or (at your option) any later version.
  1190. + */
  1191. +
  1192. +#include <linux/types.h>
  1193. +
  1194. +#include "fifo.h"
  1195. +
  1196. +void
  1197. +fusion_fifo_put (FusionFifo *fifo, FusionLink *link)
  1198. +{
  1199. + link->prev = fifo->last;
  1200. + link->next = NULL;
  1201. +
  1202. + if (fifo->last)
  1203. + fifo->last->next = link;
  1204. + else
  1205. + fifo->first = link;
  1206. +
  1207. + fifo->last = link;
  1208. +
  1209. + fifo->count++;
  1210. +}
  1211. +
  1212. +FusionLink *
  1213. +fusion_fifo_get (FusionFifo *fifo)
  1214. +{
  1215. + FusionLink *first = fifo->first;
  1216. +
  1217. + if (!first)
  1218. + return NULL;
  1219. +
  1220. + fifo->first = first->next;
  1221. +
  1222. + if (fifo->last == first)
  1223. + fifo->last = NULL;
  1224. + else
  1225. + fifo->first->prev = NULL;
  1226. +
  1227. + fifo->count--;
  1228. +
  1229. + return first;
  1230. +}
  1231. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/fifo.h linux-2.6.22.1/drivers/char/fusion/fifo.h
  1232. --- linux-2.6.22.1-0rig/drivers/char/fusion/fifo.h 1970-01-01 01:00:00.000000000 +0100
  1233. +++ linux-2.6.22.1/drivers/char/fusion/fifo.h 2003-06-16 19:47:03.000000000 +0200
  1234. @@ -0,0 +1,36 @@
  1235. +/*
  1236. + * Fusion Kernel Module
  1237. + *
  1238. + * (c) Copyright 2002-2003 Convergence GmbH
  1239. + *
  1240. + * Written by Denis Oliver Kropp <dok@directfb.org>
  1241. + *
  1242. + *
  1243. + * This program is free software; you can redistribute it and/or
  1244. + * modify it under the terms of the GNU General Public License
  1245. + * as published by the Free Software Foundation; either version
  1246. + * 2 of the License, or (at your option) any later version.
  1247. + */
  1248. +
  1249. +#ifndef __FUSION__FIFO_H__
  1250. +#define __FUSION__FIFO_H__
  1251. +
  1252. +#include "types.h"
  1253. +#include "list.h"
  1254. +
  1255. +typedef struct {
  1256. + FusionLink *first;
  1257. + FusionLink *last;
  1258. +
  1259. + int count;
  1260. +} FusionFifo;
  1261. +
  1262. +void fusion_fifo_put (FusionFifo *fifo,
  1263. + FusionLink *link);
  1264. +
  1265. +FusionLink *fusion_fifo_get (FusionFifo *fifo);
  1266. +
  1267. +int fusion_fifo_count (FusionFifo *fifo);
  1268. +
  1269. +#endif /* __FUSION__LIST_H__ */
  1270. +
  1271. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/fusiondev.c linux-2.6.22.1/drivers/char/fusion/fusiondev.c
  1272. --- linux-2.6.22.1-0rig/drivers/char/fusion/fusiondev.c 1970-01-01 01:00:00.000000000 +0100
  1273. +++ linux-2.6.22.1/drivers/char/fusion/fusiondev.c 2007-03-08 14:02:47.000000000 +0100
  1274. @@ -0,0 +1,1187 @@
  1275. +/*
  1276. + * Fusion Kernel Module
  1277. + *
  1278. + * (c) Copyright 2002-2003 Convergence GmbH
  1279. + *
  1280. + * Written by Denis Oliver Kropp <dok@directfb.org>
  1281. + *
  1282. + *
  1283. + * This program is free software; you can redistribute it and/or
  1284. + * modify it under the terms of the GNU General Public License
  1285. + * as published by the Free Software Foundation; either version
  1286. + * 2 of the License, or (at your option) any later version.
  1287. + */
  1288. +
  1289. +#include <linux/version.h>
  1290. +#include <linux/module.h>
  1291. +#ifdef HAVE_LINUX_CONFIG_H
  1292. +#include <linux/config.h>
  1293. +#endif
  1294. +#include <linux/types.h>
  1295. +#include <linux/kernel.h>
  1296. +#include <linux/fs.h>
  1297. +#include <linux/slab.h>
  1298. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
  1299. +#include <linux/devfs_fs_kernel.h>
  1300. +#endif
  1301. +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 19)
  1302. +#include <linux/page-flags.h>
  1303. +#include <linux/mm.h>
  1304. +#endif
  1305. +
  1306. +#include <linux/proc_fs.h>
  1307. +#include <linux/poll.h>
  1308. +#include <linux/init.h>
  1309. +#include <asm/io.h>
  1310. +#include <asm/uaccess.h>
  1311. +
  1312. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2)
  1313. +#include <linux/device.h>
  1314. +#endif
  1315. +
  1316. +#include <linux/fusion.h>
  1317. +
  1318. +#include "call.h"
  1319. +#include "fusiondev.h"
  1320. +#include "fusionee.h"
  1321. +#include "property.h"
  1322. +#include "reactor.h"
  1323. +#include "ref.h"
  1324. +#include "skirmish.h"
  1325. +#include "shmpool.h"
  1326. +
  1327. +#if 0
  1328. +#define DEBUG(x...) printk (KERN_DEBUG "Fusion: " x)
  1329. +#else
  1330. +#define DEBUG(x...) do {} while (0)
  1331. +#endif
  1332. +
  1333. +#ifndef FUSION_MAJOR
  1334. +#define FUSION_MAJOR 252
  1335. +#endif
  1336. +
  1337. +MODULE_LICENSE("GPL");
  1338. +MODULE_AUTHOR("Denis Oliver Kropp <dok@directfb.org>");
  1339. +
  1340. +struct proc_dir_entry *proc_fusion_dir;
  1341. +
  1342. +#define NUM_MINORS 8
  1343. +
  1344. +static FusionDev *fusion_devs[NUM_MINORS] = { 0 };
  1345. +static DECLARE_MUTEX(devs_lock);
  1346. +
  1347. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
  1348. +static devfs_handle_t devfs_handles[NUM_MINORS];
  1349. +static inline unsigned iminor(struct inode *inode)
  1350. +{
  1351. + return MINOR(inode->i_rdev);
  1352. +}
  1353. +#endif
  1354. +
  1355. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2)
  1356. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
  1357. +static struct class *fusion_class;
  1358. +#else
  1359. +static struct class_simple *fusion_class;
  1360. +#endif
  1361. +#endif
  1362. +
  1363. +/******************************************************************************/
  1364. +
  1365. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
  1366. +void
  1367. +fusion_sleep_on(wait_queue_head_t *q, struct semaphore *lock, signed long *timeout)
  1368. +{
  1369. + DEFINE_WAIT(wait);
  1370. +
  1371. + prepare_to_wait( q, &wait, TASK_INTERRUPTIBLE );
  1372. +
  1373. + up( lock );
  1374. +
  1375. + if (timeout)
  1376. + *timeout = schedule_timeout(*timeout);
  1377. + else
  1378. + schedule();
  1379. +
  1380. + finish_wait( q, &wait );
  1381. +}
  1382. +#else
  1383. +void
  1384. +fusion_sleep_on(wait_queue_head_t *q, struct semaphore *lock, signed long *timeout)
  1385. +{
  1386. + wait_queue_t wait;
  1387. +
  1388. + init_waitqueue_entry (&wait, current);
  1389. +
  1390. + current->state = TASK_INTERRUPTIBLE;
  1391. +
  1392. + write_lock (&q->lock);
  1393. + __add_wait_queue (q, &wait);
  1394. + write_unlock (&q->lock);
  1395. +
  1396. + up (lock);
  1397. +
  1398. + if (timeout)
  1399. + *timeout = schedule_timeout(*timeout);
  1400. + else
  1401. + schedule();
  1402. +
  1403. + write_lock (&q->lock);
  1404. + __remove_wait_queue (q, &wait);
  1405. + write_unlock (&q->lock);
  1406. +}
  1407. +#endif
  1408. +
  1409. +/******************************************************************************/
  1410. +
  1411. +static int
  1412. +fusiondev_stat_read_proc(char *buf, char **start, off_t offset,
  1413. + int len, int *eof, void *private)
  1414. +{
  1415. + FusionDev *dev = private;
  1416. + int written = 0;
  1417. +
  1418. + written += snprintf( buf, len,
  1419. + "lease/purchase cede attach detach "
  1420. + "ref up ref down prevail/swoop dismiss\n" );
  1421. + if (written < offset) {
  1422. + offset -= written;
  1423. + written = 0;
  1424. + }
  1425. +
  1426. + if (written < len) {
  1427. + written += snprintf( buf+written, len - written,
  1428. + "%10d %10d %10d %10d %10d %10d %10d %10d\n",
  1429. + dev->stat.property_lease_purchase,
  1430. + dev->stat.property_cede,
  1431. + dev->stat.reactor_attach,
  1432. + dev->stat.reactor_detach,
  1433. + dev->stat.ref_up,
  1434. + dev->stat.ref_down,
  1435. + dev->stat.skirmish_prevail_swoop,
  1436. + dev->stat.skirmish_dismiss );
  1437. + if (written < offset) {
  1438. + offset -= written;
  1439. + written = 0;
  1440. + }
  1441. + }
  1442. +
  1443. + *start = buf + offset;
  1444. + written -= offset;
  1445. + if (written > len) {
  1446. + *eof = 0;
  1447. + return len;
  1448. + }
  1449. +
  1450. + *eof = 1;
  1451. + return(written<0) ? 0 : written;
  1452. +}
  1453. +
  1454. +/******************************************************************************/
  1455. +
  1456. +static int
  1457. +fusiondev_init (FusionDev *dev)
  1458. +{
  1459. + int ret;
  1460. +
  1461. + init_MUTEX( &dev->enter_lock );
  1462. + init_waitqueue_head( &dev->enter_wait );
  1463. +
  1464. + ret = fusionee_init (dev);
  1465. + if (ret)
  1466. + goto error_fusionee;
  1467. +
  1468. + ret = fusion_ref_init (dev);
  1469. + if (ret)
  1470. + goto error_ref;
  1471. +
  1472. + ret = fusion_skirmish_init (dev);
  1473. + if (ret)
  1474. + goto error_skirmish;
  1475. +
  1476. + ret = fusion_property_init (dev);
  1477. + if (ret)
  1478. + goto error_property;
  1479. +
  1480. + ret = fusion_reactor_init (dev);
  1481. + if (ret)
  1482. + goto error_reactor;
  1483. +
  1484. + ret = fusion_shmpool_init (dev);
  1485. + if (ret)
  1486. + goto error_shmpool;
  1487. +
  1488. + ret = fusion_call_init (dev);
  1489. + if (ret)
  1490. + goto error_call;
  1491. +
  1492. + create_proc_read_entry( "stat", 0, dev->proc_dir,
  1493. + fusiondev_stat_read_proc, dev );
  1494. +
  1495. + return 0;
  1496. +
  1497. +
  1498. +error_call:
  1499. + fusion_shmpool_deinit (dev);
  1500. +
  1501. +error_shmpool:
  1502. + fusion_reactor_deinit (dev);
  1503. +
  1504. +error_reactor:
  1505. + fusion_property_deinit (dev);
  1506. +
  1507. +error_property:
  1508. + fusion_skirmish_deinit (dev);
  1509. +
  1510. +error_skirmish:
  1511. + fusion_ref_deinit (dev);
  1512. +
  1513. +error_ref:
  1514. + fusionee_deinit (dev);
  1515. +
  1516. +error_fusionee:
  1517. + return ret;
  1518. +}
  1519. +
  1520. +static void
  1521. +fusiondev_deinit (FusionDev *dev)
  1522. +{
  1523. + remove_proc_entry ("stat", dev->proc_dir);
  1524. +
  1525. + fusion_call_deinit (dev);
  1526. + fusion_shmpool_deinit (dev);
  1527. + fusion_reactor_deinit (dev);
  1528. + fusion_property_deinit (dev);
  1529. + fusion_skirmish_deinit (dev);
  1530. + fusion_ref_deinit (dev);
  1531. + fusionee_deinit (dev);
  1532. +
  1533. + if (dev->shared_area) {
  1534. + ClearPageReserved( virt_to_page(dev->shared_area) );
  1535. + free_page( dev->shared_area );
  1536. + }
  1537. +}
  1538. +
  1539. +/******************************************************************************/
  1540. +
  1541. +static int
  1542. +fusion_open (struct inode *inode, struct file *file)
  1543. +{
  1544. + int ret;
  1545. + Fusionee *fusionee;
  1546. + int minor = iminor(inode);
  1547. +
  1548. + DEBUG( "fusion_open( %p, %d )\n", file, atomic_read(&file->f_count) );
  1549. +
  1550. + if (down_interruptible (&devs_lock))
  1551. + return -EINTR;
  1552. +
  1553. + if (!fusion_devs[minor]) {
  1554. + char buf[4];
  1555. +
  1556. + fusion_devs[minor] = kmalloc (sizeof(FusionDev), GFP_KERNEL);
  1557. + if (!fusion_devs[minor]) {
  1558. + up (&devs_lock);
  1559. + return -ENOMEM;
  1560. + }
  1561. +
  1562. + memset (fusion_devs[minor], 0, sizeof(FusionDev));
  1563. +
  1564. + snprintf (buf, 4, "%d", minor);
  1565. +
  1566. + fusion_devs[minor]->proc_dir = proc_mkdir (buf, proc_fusion_dir);
  1567. + fusion_devs[minor]->index = minor;
  1568. +
  1569. + ret = fusiondev_init (fusion_devs[minor]);
  1570. + if (ret) {
  1571. + remove_proc_entry (buf, proc_fusion_dir);
  1572. +
  1573. + kfree (fusion_devs[minor]);
  1574. + fusion_devs[minor] = NULL;
  1575. +
  1576. + up (&devs_lock);
  1577. +
  1578. + return ret;
  1579. + }
  1580. + }
  1581. + else if (file->f_flags & O_EXCL) {
  1582. + if (fusion_devs[minor]->fusionee.last_id) {
  1583. + up (&devs_lock);
  1584. + return -EBUSY;
  1585. + }
  1586. + }
  1587. +
  1588. + ret = fusionee_new (fusion_devs[minor], !!(file->f_flags & O_APPEND), &fusionee);
  1589. + if (ret) {
  1590. + if (!fusion_devs[minor]->refs) {
  1591. + fusiondev_deinit (fusion_devs[minor]);
  1592. +
  1593. + remove_proc_entry (fusion_devs[minor]->proc_dir->name,
  1594. + proc_fusion_dir);
  1595. +
  1596. + kfree (fusion_devs[minor]);
  1597. + fusion_devs[minor] = NULL;
  1598. + }
  1599. +
  1600. + up (&devs_lock);
  1601. +
  1602. + return ret;
  1603. + }
  1604. +
  1605. + fusion_devs[minor]->refs++;
  1606. +
  1607. + up (&devs_lock);
  1608. +
  1609. +
  1610. + file->private_data = fusionee;
  1611. +
  1612. + return 0;
  1613. +}
  1614. +
  1615. +static int
  1616. +fusion_release (struct inode *inode, struct file *file)
  1617. +{
  1618. + int minor = iminor(inode);
  1619. + Fusionee *fusionee = file->private_data;
  1620. +
  1621. + DEBUG( "fusion_release( %p, %d )\n", file, atomic_read(&file->f_count) );
  1622. +
  1623. + fusionee_destroy (fusion_devs[minor], fusionee);
  1624. +
  1625. + down (&devs_lock);
  1626. +
  1627. + if (! --fusion_devs[minor]->refs) {
  1628. + fusiondev_deinit (fusion_devs[minor]);
  1629. +
  1630. + remove_proc_entry (fusion_devs[minor]->proc_dir->name,
  1631. + proc_fusion_dir);
  1632. +
  1633. + kfree (fusion_devs[minor]);
  1634. + fusion_devs[minor] = NULL;
  1635. + }
  1636. +
  1637. + up (&devs_lock);
  1638. +
  1639. + return 0;
  1640. +}
  1641. +
  1642. +static int
  1643. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18)
  1644. +fusion_flush (struct file *file, fl_owner_t id)
  1645. +#else
  1646. +fusion_flush (struct file *file)
  1647. +#endif
  1648. +{
  1649. + Fusionee *fusionee = file->private_data;
  1650. + FusionDev *dev = fusion_devs[iminor(file->f_dentry->d_inode)];
  1651. +
  1652. + (void) fusionee;
  1653. +
  1654. + DEBUG( "fusion_flush( %p, %d, 0x%08x %d )\n", file, atomic_read(&file->f_count), fusionee_id(fusionee), current->pid );
  1655. +
  1656. + if (current->flags & PF_EXITING)
  1657. + fusion_skirmish_dismiss_all_from_pid (dev, current->pid);
  1658. +
  1659. + return 0;
  1660. +}
  1661. +
  1662. +static ssize_t
  1663. +fusion_read (struct file *file, char *buf, size_t count, loff_t *ppos)
  1664. +{
  1665. + Fusionee *fusionee = file->private_data;
  1666. + FusionDev *dev = fusion_devs[iminor(file->f_dentry->d_inode)];
  1667. +
  1668. + DEBUG( "fusion_read( %p, %d, %d )\n", file, atomic_read(&file->f_count), count );
  1669. +
  1670. + return fusionee_get_messages (dev, fusionee, buf, count,
  1671. + !(file->f_flags & O_NONBLOCK));
  1672. +}
  1673. +
  1674. +static unsigned int
  1675. +fusion_poll (struct file *file, poll_table * wait)
  1676. +{
  1677. + Fusionee *fusionee = file->private_data;
  1678. + FusionDev *dev = fusion_devs[iminor(file->f_dentry->d_inode)];
  1679. +
  1680. + DEBUG( "fusion_poll( %p, %d )\n", file, atomic_read(&file->f_count) );
  1681. +
  1682. + return fusionee_poll (dev, fusionee, file, wait);
  1683. +}
  1684. +
  1685. +static int
  1686. +lounge_ioctl (struct file *file, FusionDev *dev, Fusionee *fusionee,
  1687. + unsigned int cmd, unsigned long arg)
  1688. +{
  1689. + int ret;
  1690. + FusionEnter enter;
  1691. + FusionKill kill;
  1692. + FusionEntryInfo info;
  1693. + FusionFork fork = {0};
  1694. +
  1695. + switch (_IOC_NR(cmd)) {
  1696. + case _IOC_NR(FUSION_ENTER):
  1697. + if (copy_from_user (&enter, (FusionEnter*) arg, sizeof(enter)))
  1698. + return -EFAULT;
  1699. +
  1700. + ret = fusionee_enter( dev, &enter, fusionee );
  1701. + if (ret)
  1702. + return ret;
  1703. +
  1704. + if (copy_to_user ((FusionEnter*) arg, &enter, sizeof(enter)))
  1705. + return -EFAULT;
  1706. +
  1707. + return 0;
  1708. +
  1709. + case _IOC_NR(FUSION_UNBLOCK):
  1710. + if (fusionee_id( fusionee ) != FUSION_ID_MASTER)
  1711. + return -EPERM;
  1712. +
  1713. + if (down_interruptible( &dev->enter_lock ))
  1714. + return -EINTR;
  1715. +
  1716. + dev->enter_ok = 1;
  1717. +
  1718. + wake_up_interruptible_all( &dev->enter_wait );
  1719. +
  1720. + up( &dev->enter_lock );
  1721. +
  1722. + return 0;
  1723. +
  1724. + case _IOC_NR(FUSION_KILL):
  1725. + if (copy_from_user (&kill, (FusionKill*) arg, sizeof(kill)))
  1726. + return -EFAULT;
  1727. +
  1728. + return fusionee_kill (dev, fusionee,
  1729. + kill.fusion_id, kill.signal, kill.timeout_ms);
  1730. +
  1731. + case _IOC_NR(FUSION_ENTRY_SET_INFO):
  1732. + if (copy_from_user (&info, (FusionEntryInfo*) arg, sizeof(info)))
  1733. + return -EFAULT;
  1734. +
  1735. + switch (info.type) {
  1736. + case FT_SKIRMISH:
  1737. + return fusion_entry_set_info (&dev->skirmish, &info);
  1738. +
  1739. + case FT_PROPERTY:
  1740. + return fusion_entry_set_info (&dev->properties, &info);
  1741. +
  1742. + case FT_REACTOR:
  1743. + return fusion_entry_set_info (&dev->reactor, &info);
  1744. +
  1745. + case FT_REF:
  1746. + return fusion_entry_set_info (&dev->ref, &info);
  1747. +
  1748. + case FT_SHMPOOL:
  1749. + return fusion_entry_set_info (&dev->shmpool, &info);
  1750. +
  1751. + default:
  1752. + return -ENOSYS;
  1753. + }
  1754. +
  1755. + case _IOC_NR(FUSION_ENTRY_GET_INFO):
  1756. + if (copy_from_user (&info, (FusionEntryInfo*) arg, sizeof(info)))
  1757. + return -EFAULT;
  1758. +
  1759. + switch (info.type) {
  1760. + case FT_SKIRMISH:
  1761. + ret = fusion_entry_get_info (&dev->skirmish, &info);
  1762. + break;
  1763. +
  1764. + case FT_PROPERTY:
  1765. + ret = fusion_entry_get_info (&dev->properties, &info);
  1766. + break;
  1767. +
  1768. + case FT_REACTOR:
  1769. + ret = fusion_entry_get_info (&dev->reactor, &info);
  1770. + break;
  1771. +
  1772. + case FT_REF:
  1773. + ret = fusion_entry_get_info (&dev->ref, &info);
  1774. + break;
  1775. +
  1776. + case FT_SHMPOOL:
  1777. + ret = fusion_entry_get_info (&dev->shmpool, &info);
  1778. + break;
  1779. +
  1780. + default:
  1781. + return -ENOSYS;
  1782. + }
  1783. +
  1784. + if (ret)
  1785. + return ret;
  1786. +
  1787. + if (copy_to_user ((FusionEntryInfo*) arg, &info, sizeof(info)))
  1788. + return -EFAULT;
  1789. +
  1790. + return 0;
  1791. +
  1792. + case _IOC_NR(FUSION_FORK):
  1793. + if (copy_from_user( &fork, (FusionFork*) arg, sizeof(fork) ))
  1794. + return -EFAULT;
  1795. +
  1796. + ret = fusionee_fork( dev, &fork, fusionee );
  1797. + if (ret)
  1798. + return ret;
  1799. +
  1800. + if (copy_to_user( (FusionFork*) arg, &fork, sizeof(fork) ))
  1801. + return -EFAULT;
  1802. +
  1803. + return 0;
  1804. + }
  1805. +
  1806. + return -ENOSYS;
  1807. +}
  1808. +
  1809. +static int
  1810. +messaging_ioctl (FusionDev *dev, Fusionee *fusionee,
  1811. + unsigned int cmd, unsigned long arg)
  1812. +{
  1813. + FusionSendMessage send;
  1814. +
  1815. + switch (_IOC_NR(cmd)) {
  1816. + case _IOC_NR(FUSION_SEND_MESSAGE):
  1817. + if (copy_from_user (&send, (FusionSendMessage*) arg, sizeof(send)))
  1818. + return -EFAULT;
  1819. +
  1820. + if (send.msg_size <= 0)
  1821. + return -EINVAL;
  1822. +
  1823. + /* message data > 64k should be stored in shared memory */
  1824. + if (send.msg_size > 0x10000)
  1825. + return -EMSGSIZE;
  1826. +
  1827. + return fusionee_send_message (dev, fusionee, send.fusion_id, FMT_SEND,
  1828. + send.msg_id, send.msg_size, send.msg_data);
  1829. + }
  1830. +
  1831. + return -ENOSYS;
  1832. +}
  1833. +
  1834. +static int
  1835. +call_ioctl (FusionDev *dev, Fusionee *fusionee,
  1836. + unsigned int cmd, unsigned long arg)
  1837. +{
  1838. + int id;
  1839. + int ret;
  1840. + FusionCallNew call;
  1841. + FusionCallExecute execute;
  1842. + FusionCallReturn call_ret;
  1843. + FusionID fusion_id = fusionee_id( fusionee );
  1844. +
  1845. + switch (_IOC_NR(cmd)) {
  1846. + case _IOC_NR(FUSION_CALL_NEW):
  1847. + if (copy_from_user (&call, (FusionCallNew*) arg, sizeof(call)))
  1848. + return -EFAULT;
  1849. +
  1850. + ret = fusion_call_new (dev, fusion_id, &call);
  1851. + if (ret)
  1852. + return ret;
  1853. +
  1854. + if (put_user (call.call_id, (int*) arg)) {
  1855. + fusion_call_destroy (dev, fusion_id, call.call_id);
  1856. + return -EFAULT;
  1857. + }
  1858. + return 0;
  1859. +
  1860. + case _IOC_NR(FUSION_CALL_EXECUTE):
  1861. + if (copy_from_user (&execute, (FusionCallExecute*) arg, sizeof(execute)))
  1862. + return -EFAULT;
  1863. +
  1864. + ret = fusion_call_execute (dev, fusionee, &execute);
  1865. + if (ret)
  1866. + return ret;
  1867. +
  1868. + if (put_user (execute.ret_val, (int*) arg))
  1869. + return -EFAULT;
  1870. + return 0;
  1871. +
  1872. + case _IOC_NR(FUSION_CALL_RETURN):
  1873. + if (copy_from_user (&call_ret, (FusionCallReturn*) arg, sizeof(call_ret)))
  1874. + return -EFAULT;
  1875. +
  1876. + return fusion_call_return (dev, fusion_id, &call_ret);
  1877. +
  1878. + case _IOC_NR(FUSION_CALL_DESTROY):
  1879. + if (get_user (id, (int*) arg))
  1880. + return -EFAULT;
  1881. +
  1882. + return fusion_call_destroy (dev, fusion_id, id);
  1883. + }
  1884. +
  1885. + return -ENOSYS;
  1886. +}
  1887. +
  1888. +static int
  1889. +ref_ioctl (FusionDev *dev, Fusionee *fusionee,
  1890. + unsigned int cmd, unsigned long arg)
  1891. +{
  1892. + int id;
  1893. + int ret;
  1894. + int refs;
  1895. + FusionRefWatch watch;
  1896. + FusionRefInherit inherit;
  1897. + FusionID fusion_id = fusionee_id( fusionee );
  1898. +
  1899. + switch (_IOC_NR(cmd)) {
  1900. + case _IOC_NR(FUSION_REF_NEW):
  1901. + ret = fusion_ref_new (dev, &id);
  1902. + if (ret)
  1903. + return ret;
  1904. +
  1905. + if (put_user (id, (int*) arg)) {
  1906. + fusion_ref_destroy (dev, id);
  1907. + return -EFAULT;
  1908. + }
  1909. + return 0;
  1910. +
  1911. + case _IOC_NR(FUSION_REF_UP):
  1912. + if (get_user (id, (int*) arg))
  1913. + return -EFAULT;
  1914. +
  1915. + return fusion_ref_up (dev, id, fusion_id);
  1916. +
  1917. + case _IOC_NR(FUSION_REF_UP_GLOBAL):
  1918. + if (get_user (id, (int*) arg))
  1919. + return -EFAULT;
  1920. +
  1921. + return fusion_ref_up (dev, id, 0);
  1922. +
  1923. + case _IOC_NR(FUSION_REF_DOWN):
  1924. + if (get_user (id, (int*) arg))
  1925. + return -EFAULT;
  1926. +
  1927. + return fusion_ref_down (dev, id, fusion_id);
  1928. +
  1929. + case _IOC_NR(FUSION_REF_DOWN_GLOBAL):
  1930. + if (get_user (id, (int*) arg))
  1931. + return -EFAULT;
  1932. +
  1933. + return fusion_ref_down (dev, id, 0);
  1934. +
  1935. + case _IOC_NR(FUSION_REF_ZERO_LOCK):
  1936. + if (get_user (id, (int*) arg))
  1937. + return -EFAULT;
  1938. +
  1939. + return fusion_ref_zero_lock (dev, id, fusion_id);
  1940. +
  1941. + case _IOC_NR(FUSION_REF_ZERO_TRYLOCK):
  1942. + if (get_user (id, (int*) arg))
  1943. + return -EFAULT;
  1944. +
  1945. + return fusion_ref_zero_trylock (dev, id, fusion_id);
  1946. +
  1947. + case _IOC_NR(FUSION_REF_UNLOCK):
  1948. + if (get_user (id, (int*) arg))
  1949. + return -EFAULT;
  1950. +
  1951. + return fusion_ref_zero_unlock (dev, id, fusion_id);
  1952. +
  1953. + case _IOC_NR(FUSION_REF_STAT):
  1954. + if (get_user (id, (int*) arg))
  1955. + return -EFAULT;
  1956. +
  1957. + ret = fusion_ref_stat (dev, id, &refs);
  1958. + if (ret)
  1959. + return ret;
  1960. +
  1961. + return refs;
  1962. +
  1963. + case _IOC_NR(FUSION_REF_WATCH):
  1964. + if (copy_from_user (&watch, (FusionRefWatch*) arg, sizeof(watch)))
  1965. + return -EFAULT;
  1966. +
  1967. + return fusion_ref_watch (dev, watch.id, watch.call_id, watch.call_arg);
  1968. +
  1969. + case _IOC_NR(FUSION_REF_INHERIT):
  1970. + if (copy_from_user (&inherit, (FusionRefInherit*) arg, sizeof(inherit)))
  1971. + return -EFAULT;
  1972. +
  1973. + return fusion_ref_inherit (dev, inherit.id, inherit.from);
  1974. +
  1975. + case _IOC_NR(FUSION_REF_DESTROY):
  1976. + if (get_user (id, (int*) arg))
  1977. + return -EFAULT;
  1978. +
  1979. + return fusion_ref_destroy (dev, id);
  1980. + }
  1981. +
  1982. + return -ENOSYS;
  1983. +}
  1984. +
  1985. +static int
  1986. +skirmish_ioctl (FusionDev *dev, Fusionee *fusionee,
  1987. + unsigned int cmd, unsigned long arg)
  1988. +{
  1989. + int id;
  1990. + int ret;
  1991. + int lock_count;
  1992. + FusionID fusion_id = fusionee_id( fusionee );
  1993. +
  1994. + switch (_IOC_NR(cmd)) {
  1995. + case _IOC_NR(FUSION_SKIRMISH_NEW):
  1996. + ret = fusion_skirmish_new (dev, &id);
  1997. + if (ret)
  1998. + return ret;
  1999. +
  2000. + if (put_user (id, (int*) arg)) {
  2001. + fusion_skirmish_destroy (dev, id);
  2002. + return -EFAULT;
  2003. + }
  2004. + return 0;
  2005. +
  2006. + case _IOC_NR(FUSION_SKIRMISH_PREVAIL):
  2007. + if (get_user (id, (int*) arg))
  2008. + return -EFAULT;
  2009. +
  2010. + return fusion_skirmish_prevail (dev, id, fusion_id);
  2011. +
  2012. + case _IOC_NR(FUSION_SKIRMISH_SWOOP):
  2013. + if (get_user (id, (int*) arg))
  2014. + return -EFAULT;
  2015. +
  2016. + return fusion_skirmish_swoop (dev, id, fusion_id);
  2017. +
  2018. + case _IOC_NR(FUSION_SKIRMISH_DISMISS):
  2019. + if (get_user (id, (int*) arg))
  2020. + return -EFAULT;
  2021. +
  2022. + return fusion_skirmish_dismiss (dev, id, fusion_id);
  2023. +
  2024. + case _IOC_NR(FUSION_SKIRMISH_DESTROY):
  2025. + if (get_user (id, (int*) arg))
  2026. + return -EFAULT;
  2027. +
  2028. + return fusion_skirmish_destroy (dev, id);
  2029. +
  2030. + case _IOC_NR(FUSION_SKIRMISH_LOCK_COUNT):
  2031. + if (get_user (id, (int*) arg))
  2032. + return -EFAULT;
  2033. +
  2034. + ret = fusion_skirmish_lock_count (dev, id, fusion_id, &lock_count);
  2035. + if (put_user(lock_count, ((int*)arg)+1))
  2036. + return -EFAULT;
  2037. +
  2038. + return ret;
  2039. + }
  2040. +
  2041. + return -ENOSYS;
  2042. +}
  2043. +
  2044. +static int
  2045. +property_ioctl (FusionDev *dev, Fusionee *fusionee,
  2046. + unsigned int cmd, unsigned long arg)
  2047. +{
  2048. + int id;
  2049. + int ret;
  2050. + FusionID fusion_id = fusionee_id( fusionee );
  2051. +
  2052. + switch (_IOC_NR(cmd)) {
  2053. + case _IOC_NR(FUSION_PROPERTY_NEW):
  2054. + ret = fusion_property_new (dev, &id);
  2055. + if (ret)
  2056. + return ret;
  2057. +
  2058. + if (put_user (id, (int*) arg)) {
  2059. + fusion_property_destroy (dev, id);
  2060. + return -EFAULT;
  2061. + }
  2062. + return 0;
  2063. +
  2064. + case _IOC_NR(FUSION_PROPERTY_LEASE):
  2065. + if (get_user (id, (int*) arg))
  2066. + return -EFAULT;
  2067. +
  2068. + return fusion_property_lease (dev, id, fusion_id);
  2069. +
  2070. + case _IOC_NR(FUSION_PROPERTY_PURCHASE):
  2071. + if (get_user (id, (int*) arg))
  2072. + return -EFAULT;
  2073. +
  2074. + return fusion_property_purchase (dev, id, fusion_id);
  2075. +
  2076. + case _IOC_NR(FUSION_PROPERTY_CEDE):
  2077. + if (get_user (id, (int*) arg))
  2078. + return -EFAULT;
  2079. +
  2080. + return fusion_property_cede (dev, id, fusion_id);
  2081. +
  2082. + case _IOC_NR(FUSION_PROPERTY_HOLDUP):
  2083. + if (get_user (id, (int*) arg))
  2084. + return -EFAULT;
  2085. +
  2086. + return fusion_property_holdup (dev, id, fusionee);
  2087. +
  2088. + case _IOC_NR(FUSION_PROPERTY_DESTROY):
  2089. + if (get_user (id, (int*) arg))
  2090. + return -EFAULT;
  2091. +
  2092. + return fusion_property_destroy (dev, id);
  2093. + }
  2094. +
  2095. + return -ENOSYS;
  2096. +}
  2097. +
  2098. +static int
  2099. +reactor_ioctl (FusionDev *dev, Fusionee *fusionee,
  2100. + unsigned int cmd, unsigned long arg)
  2101. +{
  2102. + int id;
  2103. + int ret;
  2104. + FusionReactorDispatch dispatch;
  2105. + FusionID fusion_id = fusionee_id( fusionee );
  2106. +
  2107. + switch (_IOC_NR(cmd)) {
  2108. + case _IOC_NR(FUSION_REACTOR_NEW):
  2109. + ret = fusion_reactor_new (dev, &id);
  2110. + if (ret)
  2111. + return ret;
  2112. +
  2113. + if (put_user (id, (int*) arg)) {
  2114. + fusion_reactor_destroy (dev, id);
  2115. + return -EFAULT;
  2116. + }
  2117. + return 0;
  2118. +
  2119. + case _IOC_NR(FUSION_REACTOR_ATTACH):
  2120. + if (get_user (id, (int*) arg))
  2121. + return -EFAULT;
  2122. +
  2123. + return fusion_reactor_attach (dev, id, fusion_id);
  2124. +
  2125. + case _IOC_NR(FUSION_REACTOR_DETACH):
  2126. + if (get_user (id, (int*) arg))
  2127. + return -EFAULT;
  2128. +
  2129. + return fusion_reactor_detach (dev, id, fusion_id);
  2130. +
  2131. + case _IOC_NR(FUSION_REACTOR_DISPATCH):
  2132. + if (copy_from_user (&dispatch,
  2133. + (FusionReactorDispatch*) arg, sizeof(dispatch)))
  2134. + return -EFAULT;
  2135. +
  2136. + if (dispatch.msg_size <= 0)
  2137. + return -EINVAL;
  2138. +
  2139. + /* message data > 64k should be stored in shared memory */
  2140. + if (dispatch.msg_size > 0x10000)
  2141. + return -EMSGSIZE;
  2142. +
  2143. + return fusion_reactor_dispatch (dev, dispatch.reactor_id,
  2144. + dispatch.self ? NULL : fusionee,
  2145. + dispatch.msg_size, dispatch.msg_data);
  2146. +
  2147. + case _IOC_NR(FUSION_REACTOR_DESTROY):
  2148. + if (get_user (id, (int*) arg))
  2149. + return -EFAULT;
  2150. +
  2151. + return fusion_reactor_destroy (dev, id);
  2152. + }
  2153. +
  2154. + return -ENOSYS;
  2155. +}
  2156. +
  2157. +static int
  2158. +shmpool_ioctl (FusionDev *dev, Fusionee *fusionee,
  2159. + unsigned int cmd, unsigned long arg)
  2160. +{
  2161. + int id;
  2162. + int ret;
  2163. + FusionSHMPoolNew pool;
  2164. + FusionSHMPoolAttach attach;
  2165. + FusionSHMPoolDispatch dispatch;
  2166. + FusionID fusion_id = fusionee_id( fusionee );
  2167. +
  2168. + switch (_IOC_NR(cmd)) {
  2169. + case _IOC_NR(FUSION_SHMPOOL_NEW):
  2170. + if (copy_from_user (&pool, (FusionSHMPoolNew*) arg, sizeof(pool)))
  2171. + return -EFAULT;
  2172. +
  2173. + ret = fusion_shmpool_new (dev, &pool);
  2174. + if (ret)
  2175. + return ret;
  2176. +
  2177. + if (copy_to_user ((FusionSHMPoolNew*) arg, &pool, sizeof(pool))) {
  2178. + fusion_shmpool_destroy (dev, pool.pool_id);
  2179. + return -EFAULT;
  2180. + }
  2181. +
  2182. + return 0;
  2183. +
  2184. + case _IOC_NR(FUSION_SHMPOOL_ATTACH):
  2185. + if (copy_from_user (&attach,
  2186. + (FusionSHMPoolAttach*) arg, sizeof(attach)))
  2187. + return -EFAULT;
  2188. +
  2189. + ret = fusion_shmpool_attach (dev, &attach, fusion_id);
  2190. + if (ret)
  2191. + return ret;
  2192. +
  2193. + if (copy_to_user ((FusionSHMPoolAttach*) arg, &attach, sizeof(attach))) {
  2194. + fusion_shmpool_detach (dev, attach.pool_id, fusion_id);
  2195. + return -EFAULT;
  2196. + }
  2197. +
  2198. + return 0;
  2199. +
  2200. + case _IOC_NR(FUSION_SHMPOOL_DETACH):
  2201. + if (get_user (id, (int*) arg))
  2202. + return -EFAULT;
  2203. +
  2204. + return fusion_shmpool_detach (dev, id, fusion_id);
  2205. +
  2206. + case _IOC_NR(FUSION_SHMPOOL_DISPATCH):
  2207. + if (copy_from_user (&dispatch,
  2208. + (FusionSHMPoolDispatch*) arg, sizeof(dispatch)))
  2209. + return -EFAULT;
  2210. +
  2211. + return fusion_shmpool_dispatch (dev, &dispatch, fusionee);
  2212. +
  2213. + case _IOC_NR(FUSION_SHMPOOL_DESTROY):
  2214. + if (get_user (id, (int*) arg))
  2215. + return -EFAULT;
  2216. +
  2217. + return fusion_shmpool_destroy (dev, id);
  2218. + }
  2219. +
  2220. + return -ENOSYS;
  2221. +}
  2222. +
  2223. +static int
  2224. +fusion_ioctl (struct inode *inode, struct file *file,
  2225. + unsigned int cmd, unsigned long arg)
  2226. +{
  2227. + Fusionee *fusionee = file->private_data;
  2228. + FusionDev *dev = fusion_devs[iminor(inode)];
  2229. +
  2230. + DEBUG( "fusion_ioctl (0x%08x)\n", cmd );
  2231. +
  2232. + switch (_IOC_TYPE(cmd)) {
  2233. + case FT_LOUNGE:
  2234. + return lounge_ioctl( file, dev, fusionee, cmd, arg );
  2235. +
  2236. + case FT_MESSAGING:
  2237. + return messaging_ioctl( dev, fusionee, cmd, arg );
  2238. +
  2239. + case FT_CALL:
  2240. + return call_ioctl( dev, fusionee, cmd, arg );
  2241. +
  2242. + case FT_REF:
  2243. + return ref_ioctl( dev, fusionee, cmd, arg );
  2244. +
  2245. + case FT_SKIRMISH:
  2246. + return skirmish_ioctl( dev, fusionee, cmd, arg );
  2247. +
  2248. + case FT_PROPERTY:
  2249. + return property_ioctl( dev, fusionee, cmd, arg );
  2250. +
  2251. + case FT_REACTOR:
  2252. + return reactor_ioctl( dev, fusionee, cmd, arg );
  2253. +
  2254. + case FT_SHMPOOL:
  2255. + return shmpool_ioctl( dev, fusionee, cmd, arg );
  2256. + }
  2257. +
  2258. + return -ENOSYS;
  2259. +}
  2260. +
  2261. +static int
  2262. +fusion_mmap( struct file *file,
  2263. + struct vm_area_struct *vma )
  2264. +{
  2265. + Fusionee *fusionee = file->private_data;
  2266. + FusionDev *dev = fusion_devs[iminor(file->f_dentry->d_inode)];
  2267. + unsigned int size;
  2268. +
  2269. + if (vma->vm_pgoff != 0)
  2270. + return -EINVAL;
  2271. +
  2272. + size = vma->vm_end - vma->vm_start;
  2273. + if (!size || size > PAGE_SIZE)
  2274. + return -EINVAL;
  2275. +
  2276. + if (!dev->shared_area) {
  2277. + if (fusionee_id( fusionee ) != FUSION_ID_MASTER)
  2278. + return -EPERM;
  2279. +
  2280. + dev->shared_area = get_zeroed_page( GFP_KERNEL );
  2281. + if (!dev->shared_area)
  2282. + return -ENOMEM;
  2283. +
  2284. + SetPageReserved( virt_to_page(dev->shared_area) );
  2285. + }
  2286. +
  2287. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
  2288. + return remap_pfn_range( vma, vma->vm_start,
  2289. + virt_to_phys((void*)dev->shared_area) >> PAGE_SHIFT,
  2290. + PAGE_SIZE, vma->vm_page_prot );
  2291. +#else
  2292. + return io_remap_page_range( vma->vm_start,
  2293. + virt_to_phys((void*)dev->shared_area),
  2294. + PAGE_SIZE, vma->vm_page_prot );
  2295. +#endif
  2296. +}
  2297. +
  2298. +static struct file_operations fusion_fops = {
  2299. + .owner = THIS_MODULE,
  2300. + .open = fusion_open,
  2301. + .flush = fusion_flush,
  2302. + .release = fusion_release,
  2303. + .read = fusion_read,
  2304. + .poll = fusion_poll,
  2305. + .ioctl = fusion_ioctl,
  2306. + .mmap = fusion_mmap
  2307. +};
  2308. +
  2309. +/******************************************************************************/
  2310. +
  2311. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
  2312. +static int __init
  2313. +register_devices(void)
  2314. +{
  2315. + int i;
  2316. +
  2317. + if (register_chrdev (FUSION_MAJOR, "fusion", &fusion_fops)) {
  2318. + printk (KERN_ERR "fusion: unable to get major %d\n", FUSION_MAJOR);
  2319. + return -EIO;
  2320. + }
  2321. +
  2322. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2)
  2323. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
  2324. + fusion_class = class_create (THIS_MODULE, "fusion");
  2325. +#else
  2326. + fusion_class = class_simple_create (THIS_MODULE, "fusion");
  2327. +#endif
  2328. + if (IS_ERR(fusion_class)) {
  2329. + unregister_chrdev (FUSION_MAJOR, "fusion");
  2330. + return PTR_ERR(fusion_class);
  2331. + }
  2332. +#endif
  2333. +
  2334. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
  2335. + devfs_mk_dir("fusion");
  2336. +#endif
  2337. +
  2338. + for (i=0; i<NUM_MINORS; i++) {
  2339. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 15)
  2340. + class_device_create (fusion_class,
  2341. + NULL,
  2342. + MKDEV(FUSION_MAJOR, i),
  2343. + NULL, "fusion%d", i);
  2344. +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
  2345. + class_device_create (fusion_class,
  2346. + MKDEV(FUSION_MAJOR, i),
  2347. + NULL, "fusion%d", i);
  2348. +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2)
  2349. + class_simple_device_add (fusion_class,
  2350. + MKDEV(FUSION_MAJOR, i),
  2351. + NULL, "fusion%d", i);
  2352. +#endif
  2353. +
  2354. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
  2355. + devfs_mk_cdev (MKDEV(FUSION_MAJOR, i),
  2356. + S_IFCHR | S_IRUSR | S_IWUSR,
  2357. + "fusion/%d", i);
  2358. +#endif
  2359. + }
  2360. +
  2361. + return 0;
  2362. +}
  2363. +#else
  2364. +static int __init
  2365. +register_devices(void)
  2366. +{
  2367. + int i;
  2368. + char buf[16];
  2369. +
  2370. + if (devfs_register_chrdev (FUSION_MAJOR, "fusion", &fusion_fops)) {
  2371. + printk (KERN_ERR "fusion: unable to get major %d\n", FUSION_MAJOR);
  2372. + return -EIO;
  2373. + }
  2374. +
  2375. + for (i=0; i<NUM_MINORS; i++) {
  2376. + snprintf (buf, 16, "fusion/%d", i);
  2377. +
  2378. + devfs_handles[i] = devfs_register (NULL, buf, DEVFS_FL_DEFAULT,
  2379. + FUSION_MAJOR, i,
  2380. + S_IFCHR | S_IRUSR | S_IWUSR,
  2381. + &fusion_fops, NULL);
  2382. + }
  2383. +
  2384. + return 0;
  2385. +}
  2386. +#endif
  2387. +
  2388. +int __init
  2389. +fusion_init(void)
  2390. +{
  2391. + int ret;
  2392. +
  2393. + ret = register_devices();
  2394. + if (ret)
  2395. + return ret;
  2396. +
  2397. + proc_fusion_dir = proc_mkdir ("fusion", NULL);
  2398. +
  2399. + return 0;
  2400. +}
  2401. +
  2402. +/******************************************************************************/
  2403. +
  2404. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
  2405. +static void __exit
  2406. +deregister_devices(void)
  2407. +{
  2408. + int i;
  2409. +
  2410. + unregister_chrdev (FUSION_MAJOR, "fusion");
  2411. +
  2412. + for (i=0; i<NUM_MINORS; i++) {
  2413. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2)
  2414. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
  2415. + class_device_destroy (fusion_class, MKDEV(FUSION_MAJOR, i));
  2416. +#else
  2417. + class_simple_device_remove (MKDEV(FUSION_MAJOR, i));
  2418. +#endif
  2419. +#endif
  2420. +
  2421. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
  2422. + devfs_remove ("fusion/%d", i);
  2423. +#endif
  2424. + }
  2425. +
  2426. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2)
  2427. +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
  2428. + class_destroy (fusion_class);
  2429. +#else
  2430. + class_simple_destroy (fusion_class);
  2431. +#endif
  2432. +#endif
  2433. +
  2434. +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
  2435. + devfs_remove ("fusion");
  2436. +#endif
  2437. +}
  2438. +#else
  2439. +static void __exit
  2440. +deregister_devices(void)
  2441. +{
  2442. + int i;
  2443. +
  2444. + devfs_unregister_chrdev (FUSION_MAJOR, "fusion");
  2445. +
  2446. + for (i=0; i<NUM_MINORS; i++)
  2447. + devfs_unregister (devfs_handles[i]);
  2448. +}
  2449. +#endif
  2450. +
  2451. +void __exit
  2452. +fusion_exit(void)
  2453. +{
  2454. + deregister_devices();
  2455. +
  2456. + remove_proc_entry ("fusion", NULL);
  2457. +}
  2458. +
  2459. +module_init(fusion_init);
  2460. +module_exit(fusion_exit);
  2461. +
  2462. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/fusiondev.h linux-2.6.22.1/drivers/char/fusion/fusiondev.h
  2463. --- linux-2.6.22.1-0rig/drivers/char/fusion/fusiondev.h 1970-01-01 01:00:00.000000000 +0100
  2464. +++ linux-2.6.22.1/drivers/char/fusion/fusiondev.h 2006-08-04 18:28:01.000000000 +0200
  2465. @@ -0,0 +1,83 @@
  2466. +/*
  2467. + * Fusion Kernel Module
  2468. + *
  2469. + * (c) Copyright 2002-2003 Convergence GmbH
  2470. + *
  2471. + * Written by Denis Oliver Kropp <dok@directfb.org>
  2472. + *
  2473. + *
  2474. + * This program is free software; you can redistribute it and/or
  2475. + * modify it under the terms of the GNU General Public License
  2476. + * as published by the Free Software Foundation; either version
  2477. + * 2 of the License, or (at your option) any later version.
  2478. + */
  2479. +
  2480. +#ifndef __FUSIONDEV_H__
  2481. +#define __FUSIONDEV_H__
  2482. +
  2483. +#include <linux/proc_fs.h>
  2484. +
  2485. +#include "entries.h"
  2486. +#include "list.h"
  2487. +
  2488. +#define FUSION_ASSERT(exp) if (!(exp)) BUG()
  2489. +#define FUSION_ASSUME(exp) if (!(exp)) printk( KERN_ERR "fusiondev: assumption '" #exp "' failed!\n" )
  2490. +
  2491. +typedef struct {
  2492. + int refs;
  2493. + int index;
  2494. +
  2495. + struct semaphore enter_lock;
  2496. + int enter_ok;
  2497. + wait_queue_head_t enter_wait;
  2498. +
  2499. + unsigned long shared_area;
  2500. +
  2501. + struct proc_dir_entry *proc_dir;
  2502. +
  2503. + struct {
  2504. + int property_lease_purchase;
  2505. + int property_cede;
  2506. +
  2507. + int reactor_attach;
  2508. + int reactor_detach;
  2509. +
  2510. + int ref_up;
  2511. + int ref_down;
  2512. +
  2513. + int skirmish_prevail_swoop;
  2514. + int skirmish_dismiss;
  2515. +
  2516. + int shmpool_attach;
  2517. + int shmpool_detach;
  2518. + } stat;
  2519. +
  2520. + struct {
  2521. + int ids;
  2522. + FusionLink *list;
  2523. + struct semaphore lock;
  2524. + } call;
  2525. +
  2526. + struct {
  2527. + int last_id;
  2528. + FusionLink *list;
  2529. + struct semaphore lock;
  2530. + wait_queue_head_t wait;
  2531. + } fusionee;
  2532. +
  2533. + FusionEntries properties;
  2534. + FusionEntries reactor;
  2535. + FusionEntries ref;
  2536. + FusionEntries shmpool;
  2537. + FusionEntries skirmish;
  2538. +} FusionDev;
  2539. +
  2540. +/*
  2541. + * Special version of interruptible_sleep_on() that unlocks the mutex
  2542. + * after adding the entry to the queue (just before schedule).
  2543. + */
  2544. +void fusion_sleep_on (wait_queue_head_t *q,
  2545. + struct semaphore *lock,
  2546. + signed long *timeout_ms);
  2547. +
  2548. +#endif
  2549. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/fusionee.c linux-2.6.22.1/drivers/char/fusion/fusionee.c
  2550. --- linux-2.6.22.1-0rig/drivers/char/fusion/fusionee.c 1970-01-01 01:00:00.000000000 +0100
  2551. +++ linux-2.6.22.1/drivers/char/fusion/fusionee.c 2007-01-29 00:31:00.000000000 +0100
  2552. @@ -0,0 +1,584 @@
  2553. +/*
  2554. + * Fusion Kernel Module
  2555. + *
  2556. + * (c) Copyright 2002-2003 Convergence GmbH
  2557. + *
  2558. + * Written by Denis Oliver Kropp <dok@directfb.org>
  2559. + *
  2560. + *
  2561. + * This program is free software; you can redistribute it and/or
  2562. + * modify it under the terms of the GNU General Public License
  2563. + * as published by the Free Software Foundation; either version
  2564. + * 2 of the License, or (at your option) any later version.
  2565. + */
  2566. +
  2567. +#ifdef HAVE_LINUX_CONFIG_H
  2568. +#include <linux/config.h>
  2569. +#endif
  2570. +#include <linux/types.h>
  2571. +#include <linux/kernel.h>
  2572. +#include <linux/slab.h>
  2573. +#include <linux/smp_lock.h>
  2574. +#include <asm/uaccess.h>
  2575. +
  2576. +#include <linux/fusion.h>
  2577. +
  2578. +#include "call.h"
  2579. +#include "fifo.h"
  2580. +#include "list.h"
  2581. +#include "fusiondev.h"
  2582. +#include "fusionee.h"
  2583. +#include "property.h"
  2584. +#include "reactor.h"
  2585. +#include "ref.h"
  2586. +#include "skirmish.h"
  2587. +#include "shmpool.h"
  2588. +
  2589. +#if 0
  2590. +#define DEBUG(x...) printk (KERN_DEBUG "Fusion: " x)
  2591. +#else
  2592. +#define DEBUG(x...) do {} while (0)
  2593. +#endif
  2594. +
  2595. +struct __Fusion_Fusionee {
  2596. + FusionLink link;
  2597. +
  2598. + struct semaphore lock;
  2599. +
  2600. + FusionID id;
  2601. + int pid;
  2602. +
  2603. + FusionFifo messages;
  2604. +
  2605. + int rcv_total; /* Total number of messages received. */
  2606. + int snd_total; /* Total number of messages sent. */
  2607. +
  2608. + wait_queue_head_t wait;
  2609. +
  2610. + bool force_slave;
  2611. +};
  2612. +
  2613. +typedef struct {
  2614. + FusionLink link;
  2615. +
  2616. + FusionMessageType type;
  2617. + FusionID id;
  2618. + int size;
  2619. + void *data;
  2620. +} Message;
  2621. +
  2622. +/******************************************************************************/
  2623. +
  2624. +static int lookup_fusionee (FusionDev *dev, FusionID id, Fusionee **ret_fusionee);
  2625. +static int lock_fusionee (FusionDev *dev, FusionID id, Fusionee **ret_fusionee);
  2626. +static void unlock_fusionee (Fusionee *fusionee);
  2627. +
  2628. +/******************************************************************************/
  2629. +
  2630. +static int
  2631. +fusionees_read_proc(char *buf, char **start, off_t offset,
  2632. + int len, int *eof, void *private)
  2633. +{
  2634. + FusionLink *l;
  2635. + FusionDev *dev = private;
  2636. + int written = 0;
  2637. +
  2638. + if (down_interruptible (&dev->fusionee.lock))
  2639. + return -EINTR;
  2640. +
  2641. + fusion_list_foreach (l, dev->fusionee.list) {
  2642. + Fusionee *fusionee = (Fusionee*) l;
  2643. +
  2644. + written += sprintf(buf+written, "(%5d) 0x%08lx (%4d messages waiting, %7d received, %7d sent)\n",
  2645. + fusionee->pid, fusionee->id, fusionee->messages.count, fusionee->rcv_total, fusionee->snd_total);
  2646. + if (written < offset) {
  2647. + offset -= written;
  2648. + written = 0;
  2649. + }
  2650. +
  2651. + if (written >= len)
  2652. + break;
  2653. + }
  2654. +
  2655. + up (&dev->fusionee.lock);
  2656. +
  2657. + *start = buf + offset;
  2658. + written -= offset;
  2659. + if (written > len) {
  2660. + *eof = 0;
  2661. + return len;
  2662. + }
  2663. +
  2664. + *eof = 1;
  2665. + return(written<0) ? 0 : written;
  2666. +}
  2667. +
  2668. +int
  2669. +fusionee_init (FusionDev *dev)
  2670. +{
  2671. + init_waitqueue_head (&dev->fusionee.wait);
  2672. +
  2673. + init_MUTEX (&dev->fusionee.lock);
  2674. +
  2675. + create_proc_read_entry("fusionees", 0, dev->proc_dir,
  2676. + fusionees_read_proc, dev);
  2677. +
  2678. + return 0;
  2679. +}
  2680. +
  2681. +void
  2682. +fusionee_deinit (FusionDev *dev)
  2683. +{
  2684. + FusionLink *l;
  2685. +
  2686. + down (&dev->fusionee.lock);
  2687. +
  2688. + remove_proc_entry ("fusionees", dev->proc_dir);
  2689. +
  2690. + l = dev->fusionee.list;
  2691. + while (l) {
  2692. + FusionLink *next = l->next;
  2693. + Fusionee *fusionee = (Fusionee *) l;
  2694. +
  2695. + while (fusionee->messages.count) {
  2696. + Message *message = (Message*) fusion_fifo_get (&fusionee->messages);
  2697. +
  2698. + kfree (message);
  2699. + }
  2700. +
  2701. + kfree (fusionee);
  2702. +
  2703. + l = next;
  2704. + }
  2705. +
  2706. + up (&dev->fusionee.lock);
  2707. +}
  2708. +
  2709. +/******************************************************************************/
  2710. +
  2711. +int
  2712. +fusionee_new( FusionDev *dev,
  2713. + bool force_slave,
  2714. + Fusionee **ret_fusionee )
  2715. +{
  2716. + Fusionee *fusionee;
  2717. +
  2718. + fusionee = kmalloc (sizeof(Fusionee), GFP_KERNEL);
  2719. + if (!fusionee)
  2720. + return -ENOMEM;
  2721. +
  2722. + memset (fusionee, 0, sizeof(Fusionee));
  2723. +
  2724. + if (down_interruptible (&dev->fusionee.lock)) {
  2725. + kfree (fusionee);
  2726. + return -EINTR;
  2727. + }
  2728. +
  2729. + fusionee->pid = current->pid;
  2730. + fusionee->force_slave = force_slave;
  2731. +
  2732. + init_MUTEX (&fusionee->lock);
  2733. +
  2734. + init_waitqueue_head (&fusionee->wait);
  2735. +
  2736. + fusion_list_prepend (&dev->fusionee.list, &fusionee->link);
  2737. +
  2738. + up (&dev->fusionee.lock);
  2739. +
  2740. + *ret_fusionee = fusionee;
  2741. +
  2742. + return 0;
  2743. +}
  2744. +
  2745. +int
  2746. +fusionee_enter( FusionDev *dev,
  2747. + FusionEnter *enter,
  2748. + Fusionee *fusionee )
  2749. +{
  2750. + if (enter->api.major != FUSION_API_MAJOR || enter->api.minor > FUSION_API_MINOR)
  2751. + return -ENOPROTOOPT;
  2752. +
  2753. + if (down_interruptible( &dev->enter_lock ))
  2754. + return -EINTR;
  2755. +
  2756. + if (dev->fusionee.last_id || fusionee->force_slave) {
  2757. + while (!dev->enter_ok) {
  2758. + fusion_sleep_on( &dev->enter_wait, &dev->enter_lock, NULL );
  2759. +
  2760. + if (signal_pending(current))
  2761. + return -EINTR;
  2762. +
  2763. + if (down_interruptible( &dev->enter_lock ))
  2764. + return -EINTR;
  2765. + }
  2766. +
  2767. + FUSION_ASSERT( dev->fusionee.last_id != 0 );
  2768. + }
  2769. +
  2770. + fusionee->id = ++dev->fusionee.last_id;
  2771. +
  2772. + up( &dev->enter_lock );
  2773. +
  2774. + enter->fusion_id = fusionee->id;
  2775. +
  2776. + return 0;
  2777. +}
  2778. +
  2779. +int
  2780. +fusionee_fork( FusionDev *dev,
  2781. + FusionFork *fork,
  2782. + Fusionee *fusionee )
  2783. +{
  2784. + int ret;
  2785. +
  2786. + ret = fusion_shmpool_fork_all( dev, fusionee->id, fork->fusion_id );
  2787. + if (ret)
  2788. + return ret;
  2789. +
  2790. + ret = fusion_reactor_fork_all( dev, fusionee->id, fork->fusion_id );
  2791. + if (ret)
  2792. + return ret;
  2793. +
  2794. + ret = fusion_ref_fork_all_local( dev, fusionee->id, fork->fusion_id );
  2795. + if (ret)
  2796. + return ret;
  2797. +
  2798. + fork->fusion_id = fusionee->id;
  2799. +
  2800. + return 0;
  2801. +}
  2802. +
  2803. +int
  2804. +fusionee_send_message (FusionDev *dev,
  2805. + Fusionee *sender,
  2806. + FusionID recipient,
  2807. + FusionMessageType msg_type,
  2808. + int msg_id,
  2809. + int msg_size,
  2810. + const void *msg_data)
  2811. +{
  2812. + int ret;
  2813. + Message *message;
  2814. + Fusionee *fusionee;
  2815. +
  2816. + DEBUG( "fusionee_send_message (%d -> %d, type %d, id %d, size %d)\n",
  2817. + fusionee->id, recipient, msg_type, msg_id, msg_size );
  2818. +
  2819. + ret = lookup_fusionee (dev, recipient, &fusionee);
  2820. + if (ret)
  2821. + return ret;
  2822. +
  2823. + if (down_interruptible (&fusionee->lock)) {
  2824. + up (&dev->fusionee.lock);
  2825. + return -EINTR;
  2826. + }
  2827. +
  2828. + if (sender && sender != fusionee) {
  2829. + if (down_interruptible (&sender->lock)) {
  2830. + unlock_fusionee (fusionee);
  2831. + up (&dev->fusionee.lock);
  2832. + return -EINTR;
  2833. + }
  2834. + }
  2835. +
  2836. + up (&dev->fusionee.lock);
  2837. +
  2838. +
  2839. + message = kmalloc (sizeof(Message) + msg_size, GFP_KERNEL);
  2840. + if (!message) {
  2841. + if (sender && sender != fusionee)
  2842. + unlock_fusionee (sender);
  2843. + unlock_fusionee (fusionee);
  2844. + return -ENOMEM;
  2845. + }
  2846. +
  2847. + message->data = message + 1;
  2848. +
  2849. + if (msg_type == FMT_CALL || msg_type == FMT_SHMPOOL)
  2850. + memcpy (message->data, msg_data, msg_size);
  2851. + else if (copy_from_user (message->data, msg_data, msg_size)) {
  2852. + kfree (message);
  2853. + if (sender && sender != fusionee)
  2854. + unlock_fusionee (sender);
  2855. + unlock_fusionee (fusionee);
  2856. + return -EFAULT;
  2857. + }
  2858. +
  2859. + message->type = msg_type;
  2860. + message->id = msg_id;
  2861. + message->size = msg_size;
  2862. +
  2863. + fusion_fifo_put (&fusionee->messages, &message->link);
  2864. +
  2865. + fusionee->rcv_total++;
  2866. + if (sender)
  2867. + sender->snd_total++;
  2868. +
  2869. + wake_up_interruptible_all (&fusionee->wait);
  2870. +
  2871. + if (sender && sender != fusionee)
  2872. + unlock_fusionee (sender);
  2873. +
  2874. + unlock_fusionee (fusionee);
  2875. +
  2876. + return 0;
  2877. +}
  2878. +
  2879. +int
  2880. +fusionee_get_messages (FusionDev *dev,
  2881. + Fusionee *fusionee,
  2882. + void *buf,
  2883. + int buf_size,
  2884. + bool block)
  2885. +{
  2886. + int written = 0;
  2887. +
  2888. + if (down_interruptible (&fusionee->lock))
  2889. + return -EINTR;
  2890. +
  2891. + while (!fusionee->messages.count) {
  2892. + if (!block) {
  2893. + unlock_fusionee (fusionee);
  2894. + return -EAGAIN;
  2895. + }
  2896. +
  2897. + fusion_sleep_on (&fusionee->wait, &fusionee->lock, 0);
  2898. +
  2899. + if (signal_pending(current))
  2900. + return -EINTR;
  2901. +
  2902. + if (down_interruptible (&fusionee->lock))
  2903. + return -EINTR;
  2904. + }
  2905. +
  2906. + while (fusionee->messages.count) {
  2907. + FusionReadMessage header;
  2908. + Message *message = (Message*) fusionee->messages.first;
  2909. + int bytes = message->size + sizeof(header);
  2910. +
  2911. + if (bytes > buf_size) {
  2912. + if (!written) {
  2913. + unlock_fusionee (fusionee);
  2914. + return -EMSGSIZE;
  2915. + }
  2916. +
  2917. + break;
  2918. + }
  2919. +
  2920. + header.msg_type = message->type;
  2921. + header.msg_id = message->id;
  2922. + header.msg_size = message->size;
  2923. +
  2924. + if (copy_to_user (buf, &header, sizeof(header)) ||
  2925. + copy_to_user (buf + sizeof(header), message->data, message->size)) {
  2926. + unlock_fusionee (fusionee);
  2927. + return -EFAULT;
  2928. + }
  2929. +
  2930. + written += bytes;
  2931. + buf += bytes;
  2932. + buf_size -= bytes;
  2933. +
  2934. + fusion_fifo_get (&fusionee->messages);
  2935. +
  2936. + kfree (message);
  2937. + }
  2938. +
  2939. + unlock_fusionee (fusionee);
  2940. +
  2941. + return written;
  2942. +}
  2943. +
  2944. +unsigned int
  2945. +fusionee_poll (FusionDev *dev,
  2946. + Fusionee *fusionee,
  2947. + struct file *file,
  2948. + poll_table *wait)
  2949. +{
  2950. + int ret;
  2951. + FusionID id = fusionee->id;
  2952. +
  2953. + poll_wait (file, &fusionee->wait, wait);
  2954. +
  2955. +
  2956. + ret = lock_fusionee (dev, id, &fusionee);
  2957. + if (ret)
  2958. + return POLLERR;
  2959. +
  2960. + if (fusionee->messages.count) {
  2961. + unlock_fusionee (fusionee);
  2962. +
  2963. + return POLLIN | POLLRDNORM;
  2964. + }
  2965. +
  2966. + unlock_fusionee (fusionee);
  2967. +
  2968. + return 0;
  2969. +}
  2970. +
  2971. +int
  2972. +fusionee_kill (FusionDev *dev,
  2973. + Fusionee *fusionee,
  2974. + FusionID target,
  2975. + int signal,
  2976. + int timeout_ms)
  2977. +{
  2978. + long timeout = -1;
  2979. +
  2980. + while (true) {
  2981. + FusionLink *l;
  2982. + int killed = 0;
  2983. +
  2984. + if (down_interruptible (&dev->fusionee.lock))
  2985. + return -EINTR;
  2986. +
  2987. + fusion_list_foreach (l, dev->fusionee.list) {
  2988. + Fusionee *f = (Fusionee*) l;
  2989. +
  2990. + if (f != fusionee && (!target || target == f->id)) {
  2991. + kill_proc (f->pid, signal, 0);
  2992. + killed++;
  2993. + }
  2994. + }
  2995. +
  2996. + if (!killed || timeout_ms < 0) {
  2997. + up (&dev->fusionee.lock);
  2998. + break;
  2999. + }
  3000. +
  3001. + if (timeout_ms) {
  3002. + switch (timeout) {
  3003. + case 0: /* timed out */
  3004. + up (&dev->fusionee.lock);
  3005. + return -ETIMEDOUT;
  3006. +
  3007. + case -1: /* setup timeout */
  3008. + timeout = (timeout_ms * HZ + 500) / 1000;
  3009. + if (!timeout)
  3010. + timeout = 1;
  3011. +
  3012. + /* fall through */
  3013. +
  3014. + default:
  3015. + fusion_sleep_on (&dev->fusionee.wait,
  3016. + &dev->fusionee.lock, &timeout);
  3017. + break;
  3018. + }
  3019. + }
  3020. + else
  3021. + fusion_sleep_on (&dev->fusionee.wait, &dev->fusionee.lock, NULL);
  3022. +
  3023. + if (signal_pending(current))
  3024. + return -EINTR;
  3025. + }
  3026. +
  3027. + return 0;
  3028. +}
  3029. +
  3030. +void
  3031. +fusionee_destroy (FusionDev *dev,
  3032. + Fusionee *fusionee)
  3033. +{
  3034. + /* Lock list. */
  3035. + down (&dev->fusionee.lock);
  3036. +
  3037. + /* Lock fusionee. */
  3038. + down (&fusionee->lock);
  3039. +
  3040. + /* Remove from list. */
  3041. + fusion_list_remove (&dev->fusionee.list, &fusionee->link);
  3042. +
  3043. + /* Wake up waiting killer. */
  3044. + wake_up_interruptible_all (&dev->fusionee.wait);
  3045. +
  3046. + /* Unlock list. */
  3047. + up (&dev->fusionee.lock);
  3048. +
  3049. +
  3050. + /* Release locks, references, ... */
  3051. + fusion_call_destroy_all (dev, fusionee->id);
  3052. + fusion_skirmish_dismiss_all (dev, fusionee->id);
  3053. + fusion_reactor_detach_all (dev, fusionee->id);
  3054. + fusion_property_cede_all (dev, fusionee->id);
  3055. + fusion_ref_clear_all_local (dev, fusionee->id);
  3056. + fusion_shmpool_detach_all (dev, fusionee->id);
  3057. +
  3058. + /* Free all pending messages. */
  3059. + while (fusionee->messages.count) {
  3060. + Message *message = (Message*) fusion_fifo_get (&fusionee->messages);
  3061. +
  3062. + kfree (message);
  3063. + }
  3064. +
  3065. + /* Unlock fusionee. */
  3066. + up (&fusionee->lock);
  3067. +
  3068. +
  3069. + /* Free fusionee data. */
  3070. + kfree (fusionee);
  3071. +}
  3072. +
  3073. +FusionID
  3074. +fusionee_id( const Fusionee *fusionee )
  3075. +{
  3076. + return fusionee->id;
  3077. +}
  3078. +
  3079. +/******************************************************************************/
  3080. +
  3081. +static int
  3082. +lookup_fusionee (FusionDev *dev,
  3083. + FusionID id,
  3084. + Fusionee **ret_fusionee)
  3085. +{
  3086. + FusionLink *l;
  3087. +
  3088. + if (down_interruptible (&dev->fusionee.lock))
  3089. + return -EINTR;
  3090. +
  3091. + fusion_list_foreach (l, dev->fusionee.list) {
  3092. + Fusionee *fusionee = (Fusionee *) l;
  3093. +
  3094. + if (fusionee->id == id) {
  3095. + *ret_fusionee = fusionee;
  3096. + return 0;
  3097. + }
  3098. + }
  3099. +
  3100. + up (&dev->fusionee.lock);
  3101. +
  3102. + return -EINVAL;
  3103. +}
  3104. +
  3105. +static int
  3106. +lock_fusionee (FusionDev *dev,
  3107. + FusionID id,
  3108. + Fusionee **ret_fusionee)
  3109. +{
  3110. + int ret;
  3111. + Fusionee *fusionee;
  3112. +
  3113. + ret = lookup_fusionee (dev, id, &fusionee);
  3114. + if (ret)
  3115. + return ret;
  3116. +
  3117. + fusion_list_move_to_front (&dev->fusionee.list, &fusionee->link);
  3118. +
  3119. + if (down_interruptible (&fusionee->lock)) {
  3120. + up (&dev->fusionee.lock);
  3121. + return -EINTR;
  3122. + }
  3123. +
  3124. + up (&dev->fusionee.lock);
  3125. +
  3126. + *ret_fusionee = fusionee;
  3127. +
  3128. + return 0;
  3129. +}
  3130. +
  3131. +static void
  3132. +unlock_fusionee (Fusionee *fusionee)
  3133. +{
  3134. + up (&fusionee->lock);
  3135. +}
  3136. +
  3137. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/fusionee.h linux-2.6.22.1/drivers/char/fusion/fusionee.h
  3138. --- linux-2.6.22.1-0rig/drivers/char/fusion/fusionee.h 1970-01-01 01:00:00.000000000 +0100
  3139. +++ linux-2.6.22.1/drivers/char/fusion/fusionee.h 2007-01-23 22:19:25.000000000 +0100
  3140. @@ -0,0 +1,75 @@
  3141. +/*
  3142. + * Fusion Kernel Module
  3143. + *
  3144. + * (c) Copyright 2002-2003 Convergence GmbH
  3145. + *
  3146. + * Written by Denis Oliver Kropp <dok@directfb.org>
  3147. + *
  3148. + *
  3149. + * This program is free software; you can redistribute it and/or
  3150. + * modify it under the terms of the GNU General Public License
  3151. + * as published by the Free Software Foundation; either version
  3152. + * 2 of the License, or (at your option) any later version.
  3153. + */
  3154. +
  3155. +#ifndef __FUSIONEE_H__
  3156. +#define __FUSIONEE_H__
  3157. +
  3158. +#include <linux/poll.h>
  3159. +#include <linux/fusion.h>
  3160. +
  3161. +#include "fusiondev.h"
  3162. +#include "types.h"
  3163. +
  3164. +/* module init/cleanup */
  3165. +
  3166. +int fusionee_init (FusionDev *dev);
  3167. +void fusionee_deinit (FusionDev *dev);
  3168. +
  3169. +
  3170. +/* internal functions */
  3171. +
  3172. +int fusionee_new (FusionDev *dev,
  3173. + bool force_slave,
  3174. + Fusionee **ret_fusionee);
  3175. +
  3176. +int fusionee_enter (FusionDev *dev,
  3177. + FusionEnter *enter,
  3178. + Fusionee *fusionee);
  3179. +
  3180. +int fusionee_fork (FusionDev *dev,
  3181. + FusionFork *fork,
  3182. + Fusionee *fusionee);
  3183. +
  3184. +int fusionee_send_message (FusionDev *dev,
  3185. + Fusionee *fusionee,
  3186. + FusionID recipient,
  3187. + FusionMessageType msg_type,
  3188. + int msg_id,
  3189. + int msg_size,
  3190. + const void *msg_data);
  3191. +
  3192. +int fusionee_get_messages (FusionDev *dev,
  3193. + Fusionee *fusionee,
  3194. + void *buf,
  3195. + int buf_size,
  3196. + bool block);
  3197. +
  3198. +unsigned
  3199. +int fusionee_poll (FusionDev *dev,
  3200. + Fusionee *fusionee,
  3201. + struct file *file,
  3202. + poll_table *wait);
  3203. +
  3204. +int fusionee_kill (FusionDev *dev,
  3205. + Fusionee *fusionee,
  3206. + FusionID target,
  3207. + int signal,
  3208. + int timeout_ms);
  3209. +
  3210. +void fusionee_destroy (FusionDev *dev,
  3211. + Fusionee *fusionee);
  3212. +
  3213. +FusionID fusionee_id( const Fusionee *fusionee );
  3214. +
  3215. +#endif
  3216. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/Kconfig linux-2.6.22.1/drivers/char/fusion/Kconfig
  3217. --- linux-2.6.22.1-0rig/drivers/char/fusion/Kconfig 1970-01-01 01:00:00.000000000 +0100
  3218. +++ linux-2.6.22.1/drivers/char/fusion/Kconfig 2007-08-12 19:33:38.000000000 +0200
  3219. @@ -0,0 +1,8 @@
  3220. +config FUSION_DEVICE
  3221. + tristate "Fusion device for DirectFB"
  3222. + default m
  3223. + ---help---
  3224. + The fusion device is a software device allowing the DirectFB
  3225. + (Direct Frame Buffer) to support multiple applications
  3226. + It is safe to say N unless you need to run several DirectFB
  3227. + applications concurrently.
  3228. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/list.c linux-2.6.22.1/drivers/char/fusion/list.c
  3229. --- linux-2.6.22.1-0rig/drivers/char/fusion/list.c 1970-01-01 01:00:00.000000000 +0100
  3230. +++ linux-2.6.22.1/drivers/char/fusion/list.c 2003-06-16 19:47:03.000000000 +0200
  3231. @@ -0,0 +1,62 @@
  3232. +/*
  3233. + * Fusion Kernel Module
  3234. + *
  3235. + * (c) Copyright 2002-2003 Convergence GmbH
  3236. + *
  3237. + * Written by Denis Oliver Kropp <dok@directfb.org>
  3238. + *
  3239. + *
  3240. + * This program is free software; you can redistribute it and/or
  3241. + * modify it under the terms of the GNU General Public License
  3242. + * as published by the Free Software Foundation; either version
  3243. + * 2 of the License, or (at your option) any later version.
  3244. + */
  3245. +
  3246. +#include <linux/types.h>
  3247. +
  3248. +#include "list.h"
  3249. +
  3250. +void
  3251. +fusion_list_prepend (FusionLink **list, FusionLink *link)
  3252. +{
  3253. + link->prev = NULL;
  3254. + link->next = *list;
  3255. +
  3256. + if (*list)
  3257. + (*list)->prev = link;
  3258. +
  3259. + *list = link;
  3260. +}
  3261. +
  3262. +void
  3263. +fusion_list_remove (FusionLink **list, FusionLink *link)
  3264. +{
  3265. + if (link->prev)
  3266. + link->prev->next = link->next;
  3267. + else
  3268. + *list = link->next;
  3269. +
  3270. + if (link->next)
  3271. + link->next->prev = link->prev;
  3272. +
  3273. + link->next = link->prev = NULL;
  3274. +}
  3275. +
  3276. +void
  3277. +fusion_list_move_to_front (FusionLink **list, FusionLink *link)
  3278. +{
  3279. + if (*list == link)
  3280. + return;
  3281. +
  3282. + link->prev->next = link->next;
  3283. +
  3284. + if (link->next)
  3285. + link->next->prev = link->prev;
  3286. +
  3287. + link->prev = NULL;
  3288. + link->next = *list;
  3289. +
  3290. + (*list)->prev = link;
  3291. +
  3292. + *list = link;
  3293. +}
  3294. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/list.h linux-2.6.22.1/drivers/char/fusion/list.h
  3295. --- linux-2.6.22.1-0rig/drivers/char/fusion/list.h 1970-01-01 01:00:00.000000000 +0100
  3296. +++ linux-2.6.22.1/drivers/char/fusion/list.h 2004-08-17 19:24:36.000000000 +0200
  3297. @@ -0,0 +1,39 @@
  3298. +/*
  3299. + * Fusion Kernel Module
  3300. + *
  3301. + * (c) Copyright 2002-2003 Convergence GmbH
  3302. + *
  3303. + * Written by Denis Oliver Kropp <dok@directfb.org>
  3304. + *
  3305. + *
  3306. + * This program is free software; you can redistribute it and/or
  3307. + * modify it under the terms of the GNU General Public License
  3308. + * as published by the Free Software Foundation; either version
  3309. + * 2 of the License, or (at your option) any later version.
  3310. + */
  3311. +
  3312. +#ifndef __FUSION__LIST_H__
  3313. +#define __FUSION__LIST_H__
  3314. +
  3315. +typedef struct _FusionLink {
  3316. + struct _FusionLink *next;
  3317. + struct _FusionLink *prev;
  3318. +} FusionLink;
  3319. +
  3320. +void fusion_list_prepend (FusionLink **list, FusionLink *link);
  3321. +void fusion_list_remove (FusionLink **list, FusionLink *link);
  3322. +void fusion_list_move_to_front (FusionLink **list, FusionLink *link);
  3323. +
  3324. +
  3325. +#define fusion_list_foreach(elem, list) \
  3326. + for (elem = (void*)(list); \
  3327. + elem; \
  3328. + elem = (void*)(((FusionLink*)(elem))->next))
  3329. +
  3330. +#define fusion_list_foreach_safe(elem, temp, list) \
  3331. + for (elem = (void*)(list), temp = ((elem) ? (void*)(((FusionLink*)(elem))->next) : NULL); \
  3332. + elem; \
  3333. + elem = (void*)(temp), temp = ((elem) ? (void*)(((FusionLink*)(elem))->next) : NULL))
  3334. +
  3335. +#endif /* __FUSION__LIST_H__ */
  3336. +
  3337. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/Makefile linux-2.6.22.1/drivers/char/fusion/Makefile
  3338. --- linux-2.6.22.1-0rig/drivers/char/fusion/Makefile 1970-01-01 01:00:00.000000000 +0100
  3339. +++ linux-2.6.22.1/drivers/char/fusion/Makefile 2005-10-29 02:38:05.000000000 +0200
  3340. @@ -0,0 +1,3 @@
  3341. +obj-$(CONFIG_FUSION_DEVICE) += fusion.o
  3342. +
  3343. +fusion-y := call.o entries.o fifo.o fusiondev.o fusionee.o list.o property.o reactor.o ref.o skirmish.o shmpool.o
  3344. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/property.c linux-2.6.22.1/drivers/char/fusion/property.c
  3345. --- linux-2.6.22.1-0rig/drivers/char/fusion/property.c 1970-01-01 01:00:00.000000000 +0100
  3346. +++ linux-2.6.22.1/drivers/char/fusion/property.c 2007-01-20 05:03:01.000000000 +0100
  3347. @@ -0,0 +1,340 @@
  3348. +/*
  3349. + * Fusion Kernel Module
  3350. + *
  3351. + * (c) Copyright 2002-2003 Convergence GmbH
  3352. + *
  3353. + * Written by Denis Oliver Kropp <dok@directfb.org>
  3354. + *
  3355. + *
  3356. + * This program is free software; you can redistribute it and/or
  3357. + * modify it under the terms of the GNU General Public License
  3358. + * as published by the Free Software Foundation; either version
  3359. + * 2 of the License, or (at your option) any later version.
  3360. + */
  3361. +
  3362. +#ifdef HAVE_LINUX_CONFIG_H
  3363. +#include <linux/config.h>
  3364. +#endif
  3365. +#include <linux/types.h>
  3366. +#include <linux/kernel.h>
  3367. +#include <linux/slab.h>
  3368. +#include <linux/smp_lock.h>
  3369. +#include <linux/sched.h>
  3370. +
  3371. +#ifndef yield
  3372. +#define yield schedule
  3373. +#endif
  3374. +
  3375. +#include <linux/fusion.h>
  3376. +
  3377. +#include "entries.h"
  3378. +#include "fusiondev.h"
  3379. +#include "fusionee.h"
  3380. +#include "list.h"
  3381. +#include "property.h"
  3382. +
  3383. +typedef enum {
  3384. + FUSION_PROPERTY_AVAILABLE = 0,
  3385. + FUSION_PROPERTY_LEASED,
  3386. + FUSION_PROPERTY_PURCHASED
  3387. +} FusionPropertyState;
  3388. +
  3389. +typedef struct {
  3390. + FusionEntry entry;
  3391. +
  3392. + FusionPropertyState state;
  3393. + int fusion_id; /* non-zero if leased/purchased */
  3394. + unsigned long purchase_stamp;
  3395. + int lock_pid;
  3396. + int count; /* lock counter */
  3397. +} FusionProperty;
  3398. +
  3399. +static int
  3400. +fusion_property_print( FusionEntry *entry,
  3401. + void *ctx,
  3402. + char *buf )
  3403. +{
  3404. + FusionProperty *property = (FusionProperty*) entry;
  3405. +
  3406. + if (property->state != FUSION_PROPERTY_AVAILABLE) {
  3407. + return sprintf( buf, "%s by 0x%08x (%d) %dx\n",
  3408. + property->state == FUSION_PROPERTY_LEASED ? "leased" : "purchased",
  3409. + property->fusion_id, property->lock_pid, property->count );
  3410. + }
  3411. +
  3412. + return sprintf( buf, "\n" );
  3413. +}
  3414. +
  3415. +FUSION_ENTRY_CLASS( FusionProperty, property, NULL, NULL, fusion_property_print )
  3416. +
  3417. +/******************************************************************************/
  3418. +
  3419. +int
  3420. +fusion_property_init( FusionDev *dev )
  3421. +{
  3422. + fusion_entries_init( &dev->properties, &property_class, dev );
  3423. +
  3424. + create_proc_read_entry( "properties", 0, dev->proc_dir,
  3425. + fusion_entries_read_proc, &dev->properties );
  3426. +
  3427. + return 0;
  3428. +}
  3429. +
  3430. +void
  3431. +fusion_property_deinit( FusionDev *dev )
  3432. +{
  3433. + remove_proc_entry( "properties", dev->proc_dir );
  3434. +
  3435. + fusion_entries_deinit( &dev->properties );
  3436. +}
  3437. +
  3438. +/******************************************************************************/
  3439. +
  3440. +int
  3441. +fusion_property_new( FusionDev *dev, int *ret_id )
  3442. +{
  3443. + return fusion_entry_create( &dev->properties, ret_id, NULL );
  3444. +}
  3445. +
  3446. +int
  3447. +fusion_property_lease( FusionDev *dev, int id, int fusion_id )
  3448. +{
  3449. + int ret;
  3450. + FusionProperty *property;
  3451. + long timeout = -1;
  3452. +
  3453. + dev->stat.property_lease_purchase++;
  3454. +
  3455. + ret = fusion_property_lock( &dev->properties, id, false, &property );
  3456. + if (ret)
  3457. + return ret;
  3458. +
  3459. + while (true) {
  3460. + switch (property->state) {
  3461. + case FUSION_PROPERTY_AVAILABLE:
  3462. + property->state = FUSION_PROPERTY_LEASED;
  3463. + property->fusion_id = fusion_id;
  3464. + property->lock_pid = current->pid;
  3465. + property->count = 1;
  3466. +
  3467. + fusion_property_unlock( property );
  3468. + return 0;
  3469. +
  3470. + case FUSION_PROPERTY_LEASED:
  3471. + if (property->lock_pid == current->pid) {
  3472. + property->count++;
  3473. +
  3474. + fusion_property_unlock( property );
  3475. + return 0;
  3476. + }
  3477. +
  3478. + ret = fusion_property_wait( property, NULL );
  3479. + if (ret)
  3480. + return ret;
  3481. +
  3482. + break;
  3483. +
  3484. + case FUSION_PROPERTY_PURCHASED:
  3485. + if (property->lock_pid == current->pid) {
  3486. + fusion_property_unlock( property );
  3487. + return -EIO;
  3488. + }
  3489. +
  3490. + if (timeout == -1) {
  3491. + if (jiffies - property->purchase_stamp > HZ / 10) {
  3492. + fusion_property_unlock( property );
  3493. + return -EAGAIN;
  3494. + }
  3495. +
  3496. + timeout = HZ / 10;
  3497. + }
  3498. +
  3499. + ret = fusion_property_wait( property, &timeout );
  3500. + if (ret)
  3501. + return ret;
  3502. +
  3503. + break;
  3504. +
  3505. + default:
  3506. + BUG();
  3507. + }
  3508. + }
  3509. +
  3510. + BUG();
  3511. +
  3512. + /* won't reach this */
  3513. + return -1;
  3514. +}
  3515. +
  3516. +int
  3517. +fusion_property_purchase( FusionDev *dev, int id, int fusion_id )
  3518. +{
  3519. + int ret;
  3520. + FusionProperty *property;
  3521. + signed long timeout = -1;
  3522. +
  3523. + dev->stat.property_lease_purchase++;
  3524. +
  3525. + ret = fusion_property_lock( &dev->properties, id, false, &property );
  3526. + if (ret)
  3527. + return ret;
  3528. +
  3529. + while (true) {
  3530. + switch (property->state) {
  3531. + case FUSION_PROPERTY_AVAILABLE:
  3532. + property->state = FUSION_PROPERTY_PURCHASED;
  3533. + property->fusion_id = fusion_id;
  3534. + property->purchase_stamp = jiffies;
  3535. + property->lock_pid = current->pid;
  3536. + property->count = 1;
  3537. +
  3538. + fusion_property_notify( property, true );
  3539. +
  3540. + fusion_property_unlock( property );
  3541. + return 0;
  3542. +
  3543. + case FUSION_PROPERTY_LEASED:
  3544. + if (property->lock_pid == current->pid) {
  3545. + fusion_property_unlock( property );
  3546. + return -EIO;
  3547. + }
  3548. +
  3549. + ret = fusion_property_wait( property, NULL );
  3550. + if (ret)
  3551. + return ret;
  3552. +
  3553. + break;
  3554. +
  3555. + case FUSION_PROPERTY_PURCHASED:
  3556. + if (property->lock_pid == current->pid) {
  3557. + property->count++;
  3558. +
  3559. + fusion_property_unlock( property );
  3560. + return 0;
  3561. + }
  3562. +
  3563. + if (timeout == -1) {
  3564. + if (jiffies - property->purchase_stamp > HZ) {
  3565. + fusion_property_unlock( property );
  3566. + return -EAGAIN;
  3567. + }
  3568. +
  3569. + timeout = HZ;
  3570. + }
  3571. +
  3572. + ret = fusion_property_wait( property, &timeout );
  3573. + if (ret)
  3574. + return ret;
  3575. +
  3576. + break;
  3577. +
  3578. + default:
  3579. + BUG();
  3580. + }
  3581. + }
  3582. +
  3583. + BUG();
  3584. +
  3585. + /* won't reach this */
  3586. + return -1;
  3587. +}
  3588. +
  3589. +int
  3590. +fusion_property_cede( FusionDev *dev, int id, int fusion_id )
  3591. +{
  3592. + int ret;
  3593. + FusionProperty *property;
  3594. + bool purchased;
  3595. +
  3596. + dev->stat.property_cede++;
  3597. +
  3598. + ret = fusion_property_lock( &dev->properties, id, false, &property );
  3599. + if (ret)
  3600. + return ret;
  3601. +
  3602. + if (property->lock_pid != current->pid) {
  3603. + fusion_property_unlock( property );
  3604. + return -EIO;
  3605. + }
  3606. +
  3607. + if (--property->count) {
  3608. + fusion_property_unlock( property );
  3609. + return 0;
  3610. + }
  3611. +
  3612. + purchased = (property->state == FUSION_PROPERTY_PURCHASED);
  3613. +
  3614. + property->state = FUSION_PROPERTY_AVAILABLE;
  3615. + property->fusion_id = 0;
  3616. + property->lock_pid = 0;
  3617. +
  3618. + fusion_property_notify( property, true );
  3619. +
  3620. + fusion_property_unlock( property );
  3621. +
  3622. + if (purchased)
  3623. + yield();
  3624. +
  3625. + return 0;
  3626. +}
  3627. +
  3628. +int
  3629. +fusion_property_holdup( FusionDev *dev, int id, Fusionee *fusionee )
  3630. +{
  3631. + int ret;
  3632. + FusionProperty *property;
  3633. + FusionID fusion_id = fusionee_id( fusionee );
  3634. +
  3635. + if (fusion_id > 1)
  3636. + return -EPERM;
  3637. +
  3638. + ret = fusion_property_lock( &dev->properties, id, false, &property );
  3639. + if (ret)
  3640. + return ret;
  3641. +
  3642. + if (property->state == FUSION_PROPERTY_PURCHASED) {
  3643. + if (property->fusion_id == fusion_id) {
  3644. + fusion_property_unlock( property );
  3645. + return -EIO;
  3646. + }
  3647. +
  3648. + fusionee_kill( dev, fusionee, property->fusion_id, SIGKILL, -1 );
  3649. + }
  3650. +
  3651. + fusion_property_unlock( property );
  3652. +
  3653. + return 0;
  3654. +}
  3655. +
  3656. +int
  3657. +fusion_property_destroy( FusionDev *dev, int id )
  3658. +{
  3659. + return fusion_entry_destroy( &dev->properties, id );
  3660. +}
  3661. +
  3662. +void
  3663. +fusion_property_cede_all( FusionDev *dev, int fusion_id )
  3664. +{
  3665. + FusionLink *l;
  3666. +
  3667. + down( &dev->properties.lock );
  3668. +
  3669. + fusion_list_foreach (l, dev->properties.list) {
  3670. + FusionProperty *property = (FusionProperty *) l;
  3671. +
  3672. + down( &property->entry.lock );
  3673. +
  3674. + if (property->fusion_id == fusion_id) {
  3675. + property->state = FUSION_PROPERTY_AVAILABLE;
  3676. + property->fusion_id = 0;
  3677. + property->lock_pid = 0;
  3678. +
  3679. + wake_up_interruptible_all (&property->entry.wait);
  3680. + }
  3681. +
  3682. + up( &property->entry.lock );
  3683. + }
  3684. +
  3685. + up( &dev->properties.lock );
  3686. +}
  3687. +
  3688. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/property.h linux-2.6.22.1/drivers/char/fusion/property.h
  3689. --- linux-2.6.22.1-0rig/drivers/char/fusion/property.h 1970-01-01 01:00:00.000000000 +0100
  3690. +++ linux-2.6.22.1/drivers/char/fusion/property.h 2007-01-20 05:03:01.000000000 +0100
  3691. @@ -0,0 +1,58 @@
  3692. +/*
  3693. + * Fusion Kernel Module
  3694. + *
  3695. + * (c) Copyright 2002-2003 Convergence GmbH
  3696. + *
  3697. + * Written by Denis Oliver Kropp <dok@directfb.org>
  3698. + *
  3699. + *
  3700. + * This program is free software; you can redistribute it and/or
  3701. + * modify it under the terms of the GNU General Public License
  3702. + * as published by the Free Software Foundation; either version
  3703. + * 2 of the License, or (at your option) any later version.
  3704. + */
  3705. +
  3706. +#ifndef __FUSION__PROPERTY_H__
  3707. +#define __FUSION__PROPERTY_H__
  3708. +
  3709. +#include "fusiondev.h"
  3710. +#include "types.h"
  3711. +
  3712. +
  3713. +/* module init/cleanup */
  3714. +
  3715. +int fusion_property_init (FusionDev *dev);
  3716. +void fusion_property_deinit (FusionDev *dev);
  3717. +
  3718. +
  3719. +/* public API */
  3720. +
  3721. +int fusion_property_new (FusionDev *dev,
  3722. + int *ret_id);
  3723. +
  3724. +int fusion_property_lease (FusionDev *dev,
  3725. + int id,
  3726. + int fusion_id);
  3727. +
  3728. +int fusion_property_purchase (FusionDev *dev,
  3729. + int id,
  3730. + int fusion_id);
  3731. +
  3732. +int fusion_property_cede (FusionDev *dev,
  3733. + int id,
  3734. + int fusion_id);
  3735. +
  3736. +int fusion_property_holdup (FusionDev *dev,
  3737. + int id,
  3738. + Fusionee *fusionee);
  3739. +
  3740. +int fusion_property_destroy (FusionDev *dev,
  3741. + int id);
  3742. +
  3743. +
  3744. +/* internal functions */
  3745. +
  3746. +void fusion_property_cede_all (FusionDev *dev,
  3747. + int fusion_id);
  3748. +
  3749. +#endif
  3750. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/reactor.c linux-2.6.22.1/drivers/char/fusion/reactor.c
  3751. --- linux-2.6.22.1-0rig/drivers/char/fusion/reactor.c 1970-01-01 01:00:00.000000000 +0100
  3752. +++ linux-2.6.22.1/drivers/char/fusion/reactor.c 2007-01-20 05:03:01.000000000 +0100
  3753. @@ -0,0 +1,367 @@
  3754. +/*
  3755. + * Fusion Kernel Module
  3756. + *
  3757. + * (c) Copyright 2002-2003 Convergence GmbH
  3758. + *
  3759. + * Written by Denis Oliver Kropp <dok@directfb.org>
  3760. + *
  3761. + *
  3762. + * This program is free software; you can redistribute it and/or
  3763. + * modify it under the terms of the GNU General Public License
  3764. + * as published by the Free Software Foundation; either version
  3765. + * 2 of the License, or (at your option) any later version.
  3766. + */
  3767. +
  3768. +#ifdef HAVE_LINUX_CONFIG_H
  3769. +#include <linux/config.h>
  3770. +#endif
  3771. +#include <linux/types.h>
  3772. +#include <linux/kernel.h>
  3773. +#include <linux/slab.h>
  3774. +#include <linux/smp_lock.h>
  3775. +#include <linux/sched.h>
  3776. +
  3777. +#include <linux/fusion.h>
  3778. +
  3779. +#include "fusiondev.h"
  3780. +#include "fusionee.h"
  3781. +#include "list.h"
  3782. +#include "reactor.h"
  3783. +
  3784. +typedef struct {
  3785. + FusionLink link;
  3786. +
  3787. + int fusion_id;
  3788. +
  3789. + int count; /* number of attach calls */
  3790. +} ReactorNode;
  3791. +
  3792. +typedef struct {
  3793. + FusionEntry entry;
  3794. +
  3795. + FusionLink *nodes;
  3796. +
  3797. + int dispatch_count;
  3798. +
  3799. + bool destroyed;
  3800. +} FusionReactor;
  3801. +
  3802. +/******************************************************************************/
  3803. +
  3804. +static int fork_node ( FusionReactor *reactor,
  3805. + FusionID fusion_id,
  3806. + FusionID from_id );
  3807. +
  3808. +static void free_all_nodes( FusionReactor *reactor );
  3809. +
  3810. +/******************************************************************************/
  3811. +
  3812. +static inline ReactorNode *
  3813. +get_node (FusionReactor *reactor,
  3814. + FusionID fusion_id)
  3815. +{
  3816. + ReactorNode *node;
  3817. +
  3818. + fusion_list_foreach (node, reactor->nodes) {
  3819. + if (node->fusion_id == fusion_id)
  3820. + return node;
  3821. + }
  3822. +
  3823. + return NULL;
  3824. +}
  3825. +
  3826. +/******************************************************************************/
  3827. +
  3828. +static void
  3829. +fusion_reactor_destruct( FusionEntry *entry,
  3830. + void *ctx )
  3831. +{
  3832. + FusionReactor *reactor = (FusionReactor*) entry;
  3833. +
  3834. + free_all_nodes( reactor );
  3835. +}
  3836. +
  3837. +static int
  3838. +fusion_reactor_print( FusionEntry *entry,
  3839. + void *ctx,
  3840. + char *buf )
  3841. +{
  3842. + int num = 0;
  3843. + FusionReactor *reactor = (FusionReactor*) entry;
  3844. + FusionLink *node = reactor->nodes;
  3845. +
  3846. + fusion_list_foreach (node, reactor->nodes) {
  3847. + num++;
  3848. + }
  3849. +
  3850. + return sprintf( buf, "%5dx dispatch, %d nodes%s\n", reactor->dispatch_count, num,
  3851. + reactor->destroyed ? " DESTROYED" : "" );
  3852. +}
  3853. +
  3854. +
  3855. +FUSION_ENTRY_CLASS( FusionReactor, reactor, NULL,
  3856. + fusion_reactor_destruct, fusion_reactor_print )
  3857. +
  3858. +/******************************************************************************/
  3859. +
  3860. +int
  3861. +fusion_reactor_init (FusionDev *dev)
  3862. +{
  3863. + fusion_entries_init( &dev->reactor, &reactor_class, dev );
  3864. +
  3865. + create_proc_read_entry( "reactors", 0, dev->proc_dir,
  3866. + fusion_entries_read_proc, &dev->reactor );
  3867. +
  3868. + return 0;
  3869. +}
  3870. +
  3871. +void
  3872. +fusion_reactor_deinit (FusionDev *dev)
  3873. +{
  3874. + remove_proc_entry ("reactors", dev->proc_dir);
  3875. +
  3876. + fusion_entries_deinit( &dev->reactor );
  3877. +}
  3878. +
  3879. +/******************************************************************************/
  3880. +
  3881. +int
  3882. +fusion_reactor_new (FusionDev *dev, int *ret_id)
  3883. +{
  3884. + return fusion_entry_create( &dev->reactor, ret_id, NULL );
  3885. +}
  3886. +
  3887. +int
  3888. +fusion_reactor_attach (FusionDev *dev, int id, FusionID fusion_id)
  3889. +{
  3890. + int ret;
  3891. + ReactorNode *node;
  3892. + FusionReactor *reactor;
  3893. +
  3894. + ret = fusion_reactor_lock( &dev->reactor, id, false, &reactor );
  3895. + if (ret)
  3896. + return ret;
  3897. +
  3898. + if (reactor->destroyed) {
  3899. + fusion_reactor_unlock( reactor );
  3900. + return -EIDRM;
  3901. + }
  3902. +
  3903. + dev->stat.reactor_attach++;
  3904. +
  3905. + node = get_node (reactor, fusion_id);
  3906. + if (!node) {
  3907. + node = kmalloc (sizeof(ReactorNode), GFP_KERNEL);
  3908. + if (!node) {
  3909. + fusion_reactor_unlock( reactor );
  3910. + return -ENOMEM;
  3911. + }
  3912. +
  3913. + node->fusion_id = fusion_id;
  3914. + node->count = 1;
  3915. +
  3916. + fusion_list_prepend (&reactor->nodes, &node->link);
  3917. + }
  3918. + else
  3919. + node->count++;
  3920. +
  3921. + fusion_reactor_unlock( reactor );
  3922. +
  3923. + return 0;
  3924. +}
  3925. +
  3926. +int
  3927. +fusion_reactor_detach (FusionDev *dev, int id, FusionID fusion_id)
  3928. +{
  3929. + int ret;
  3930. + ReactorNode *node;
  3931. + FusionReactor *reactor;
  3932. +
  3933. + ret = fusion_reactor_lock( &dev->reactor, id, true, &reactor );
  3934. + if (ret)
  3935. + return ret;
  3936. +
  3937. + dev->stat.reactor_detach++;
  3938. +
  3939. + node = get_node (reactor, fusion_id);
  3940. + if (!node) {
  3941. + fusion_reactor_unlock( reactor );
  3942. + up( &dev->reactor.lock );
  3943. + return -EIO;
  3944. + }
  3945. +
  3946. + if (! --node->count) {
  3947. + fusion_list_remove (&reactor->nodes, &node->link);
  3948. + kfree (node);
  3949. + }
  3950. +
  3951. + if (reactor->destroyed && !reactor->nodes)
  3952. + fusion_entry_destroy_locked( &dev->reactor, &reactor->entry );
  3953. + else
  3954. + fusion_reactor_unlock( reactor );
  3955. +
  3956. + up( &dev->reactor.lock );
  3957. +
  3958. + return 0;
  3959. +}
  3960. +
  3961. +int
  3962. +fusion_reactor_dispatch (FusionDev *dev, int id, Fusionee *fusionee,
  3963. + int msg_size, const void *msg_data)
  3964. +{
  3965. + int ret;
  3966. + FusionLink *l;
  3967. + FusionReactor *reactor;
  3968. + FusionID fusion_id = fusionee ? fusionee_id( fusionee ) : 0;
  3969. +
  3970. + ret = fusion_reactor_lock( &dev->reactor, id, false, &reactor );
  3971. + if (ret)
  3972. + return ret;
  3973. +
  3974. + if (reactor->destroyed) {
  3975. + fusion_reactor_unlock( reactor );
  3976. + return -EIDRM;
  3977. + }
  3978. +
  3979. + reactor->dispatch_count++;
  3980. +
  3981. + fusion_list_foreach (l, reactor->nodes) {
  3982. + ReactorNode *node = (ReactorNode *) l;
  3983. +
  3984. + if (node->fusion_id == fusion_id)
  3985. + continue;
  3986. +
  3987. + fusionee_send_message (dev, fusionee, node->fusion_id, FMT_REACTOR,
  3988. + reactor->entry.id, msg_size, msg_data);
  3989. + }
  3990. +
  3991. + fusion_reactor_unlock( reactor );
  3992. +
  3993. + return 0;
  3994. +}
  3995. +
  3996. +int
  3997. +fusion_reactor_destroy (FusionDev *dev, int id)
  3998. +{
  3999. + int ret;
  4000. + FusionReactor *reactor;
  4001. +
  4002. + ret = fusion_reactor_lock( &dev->reactor, id, true, &reactor );
  4003. + if (ret)
  4004. + return ret;
  4005. +
  4006. + if (reactor->destroyed) {
  4007. + fusion_reactor_unlock( reactor );
  4008. + up( &dev->reactor.lock );
  4009. + return -EIDRM;
  4010. + }
  4011. +
  4012. + reactor->destroyed = true;
  4013. +
  4014. + if (!reactor->nodes)
  4015. + fusion_entry_destroy_locked( &dev->reactor, &reactor->entry );
  4016. + else
  4017. + fusion_reactor_unlock( reactor );
  4018. +
  4019. + up( &dev->reactor.lock );
  4020. +
  4021. + return 0;
  4022. +}
  4023. +
  4024. +void
  4025. +fusion_reactor_detach_all (FusionDev *dev, FusionID fusion_id)
  4026. +{
  4027. + FusionLink *l, *n;
  4028. +
  4029. + down (&dev->reactor.lock);
  4030. +
  4031. + fusion_list_foreach_safe (l, n, dev->reactor.list) {
  4032. + ReactorNode *node;
  4033. + FusionReactor *reactor = (FusionReactor *) l;
  4034. +
  4035. + down (&reactor->entry.lock);
  4036. +
  4037. + fusion_list_foreach (node, reactor->nodes) {
  4038. + if (node->fusion_id == fusion_id) {
  4039. + fusion_list_remove (&reactor->nodes, &node->link);
  4040. + kfree (node);
  4041. + break;
  4042. + }
  4043. + }
  4044. +
  4045. + if (reactor->destroyed && !reactor->nodes)
  4046. + fusion_entry_destroy_locked( &dev->reactor, &reactor->entry );
  4047. + else
  4048. + up (&reactor->entry.lock);
  4049. + }
  4050. +
  4051. + up (&dev->reactor.lock);
  4052. +}
  4053. +
  4054. +int
  4055. +fusion_reactor_fork_all (FusionDev *dev, FusionID fusion_id, FusionID from_id)
  4056. +{
  4057. + FusionLink *l;
  4058. + int ret = 0;
  4059. +
  4060. + down (&dev->reactor.lock);
  4061. +
  4062. + fusion_list_foreach (l, dev->reactor.list) {
  4063. + FusionReactor *reactor = (FusionReactor *) l;
  4064. +
  4065. + ret = fork_node (reactor, fusion_id, from_id);
  4066. + if (ret)
  4067. + break;
  4068. + }
  4069. +
  4070. + up (&dev->reactor.lock);
  4071. +
  4072. + return ret;
  4073. +}
  4074. +
  4075. +/******************************************************************************/
  4076. +
  4077. +static int
  4078. +fork_node (FusionReactor *reactor, FusionID fusion_id, FusionID from_id)
  4079. +{
  4080. + ReactorNode *node;
  4081. +
  4082. + down (&reactor->entry.lock);
  4083. +
  4084. + fusion_list_foreach (node, reactor->nodes) {
  4085. + if (node->fusion_id == from_id) {
  4086. + ReactorNode *new_node;
  4087. +
  4088. + new_node = kmalloc (sizeof(ReactorNode), GFP_KERNEL);
  4089. + if (!new_node) {
  4090. + up (&reactor->entry.lock);
  4091. + return -ENOMEM;
  4092. + }
  4093. +
  4094. + new_node->fusion_id = fusion_id;
  4095. + new_node->count = node->count;
  4096. +
  4097. + fusion_list_prepend (&reactor->nodes, &new_node->link);
  4098. +
  4099. + break;
  4100. + }
  4101. + }
  4102. +
  4103. + up (&reactor->entry.lock);
  4104. +
  4105. + return 0;
  4106. +}
  4107. +
  4108. +static void
  4109. +free_all_nodes (FusionReactor *reactor)
  4110. +
  4111. +{
  4112. + FusionLink *n;
  4113. + ReactorNode *node;
  4114. +
  4115. + fusion_list_foreach_safe (node, n, reactor->nodes) {
  4116. + kfree (node);
  4117. + }
  4118. +
  4119. + reactor->nodes = NULL;
  4120. +}
  4121. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/reactor.h linux-2.6.22.1/drivers/char/fusion/reactor.h
  4122. --- linux-2.6.22.1-0rig/drivers/char/fusion/reactor.h 1970-01-01 01:00:00.000000000 +0100
  4123. +++ linux-2.6.22.1/drivers/char/fusion/reactor.h 2007-01-20 05:03:01.000000000 +0100
  4124. @@ -0,0 +1,59 @@
  4125. +/*
  4126. + * Fusion Kernel Module
  4127. + *
  4128. + * (c) Copyright 2002-2003 Convergence GmbH
  4129. + *
  4130. + * Written by Denis Oliver Kropp <dok@directfb.org>
  4131. + *
  4132. + *
  4133. + * This program is free software; you can redistribute it and/or
  4134. + * modify it under the terms of the GNU General Public License
  4135. + * as published by the Free Software Foundation; either version
  4136. + * 2 of the License, or (at your option) any later version.
  4137. + */
  4138. +
  4139. +#ifndef __FUSION__REACTOR_H__
  4140. +#define __FUSION__REACTOR_H__
  4141. +
  4142. +#include "fusiondev.h"
  4143. +#include "types.h"
  4144. +
  4145. +
  4146. +/* module init/cleanup */
  4147. +
  4148. +int fusion_reactor_init (FusionDev *dev);
  4149. +void fusion_reactor_deinit (FusionDev *dev);
  4150. +
  4151. +
  4152. +/* public API */
  4153. +
  4154. +int fusion_reactor_new (FusionDev *dev,
  4155. + int *id);
  4156. +
  4157. +int fusion_reactor_attach (FusionDev *dev,
  4158. + int id,
  4159. + FusionID fusion_id);
  4160. +
  4161. +int fusion_reactor_detach (FusionDev *dev,
  4162. + int id,
  4163. + FusionID fusion_id);
  4164. +
  4165. +int fusion_reactor_dispatch (FusionDev *dev,
  4166. + int id,
  4167. + Fusionee *fusionee,
  4168. + int msg_size,
  4169. + const void *msg_data);
  4170. +
  4171. +int fusion_reactor_destroy (FusionDev *dev,
  4172. + int id);
  4173. +
  4174. +
  4175. +/* internal functions */
  4176. +
  4177. +void fusion_reactor_detach_all (FusionDev *dev,
  4178. + FusionID fusion_id);
  4179. +
  4180. +int fusion_reactor_fork_all (FusionDev *dev,
  4181. + FusionID fusion_id,
  4182. + FusionID from_id);
  4183. +#endif
  4184. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/ref.c linux-2.6.22.1/drivers/char/fusion/ref.c
  4185. --- linux-2.6.22.1-0rig/drivers/char/fusion/ref.c 1970-01-01 01:00:00.000000000 +0100
  4186. +++ linux-2.6.22.1/drivers/char/fusion/ref.c 2007-01-06 14:09:45.000000000 +0100
  4187. @@ -0,0 +1,680 @@
  4188. +/*
  4189. + * Fusion Kernel Module
  4190. + *
  4191. + * (c) Copyright 2002-2003 Convergence GmbH
  4192. + *
  4193. + * Written by Denis Oliver Kropp <dok@directfb.org>
  4194. + *
  4195. + *
  4196. + * This program is free software; you can redistribute it and/or
  4197. + * modify it under the terms of the GNU General Public License
  4198. + * as published by the Free Software Foundation; either version
  4199. + * 2 of the License, or (at your option) any later version.
  4200. + */
  4201. +
  4202. +#ifdef HAVE_LINUX_CONFIG_H
  4203. +#include <linux/config.h>
  4204. +#endif
  4205. +#include <linux/types.h>
  4206. +#include <linux/kernel.h>
  4207. +#include <linux/slab.h>
  4208. +#include <linux/smp_lock.h>
  4209. +#include <linux/sched.h>
  4210. +
  4211. +#include <linux/fusion.h>
  4212. +
  4213. +#include "fusiondev.h"
  4214. +#include "list.h"
  4215. +#include "call.h"
  4216. +#include "ref.h"
  4217. +
  4218. +typedef struct __Fusion_FusionRef FusionRef;
  4219. +
  4220. +typedef struct {
  4221. + FusionLink link;
  4222. + FusionID fusion_id;
  4223. + int refs;
  4224. +} LocalRef;
  4225. +
  4226. +typedef struct {
  4227. + FusionLink link;
  4228. + FusionRef *ref;
  4229. +} Inheritor;
  4230. +
  4231. +struct __Fusion_FusionRef {
  4232. + FusionEntry entry;
  4233. +
  4234. + int global;
  4235. + int local;
  4236. +
  4237. + int locked; /* non-zero fusion id of lock owner */
  4238. +
  4239. + bool watched; /* true if watch has been installed */
  4240. + int call_id; /* id of call registered with a watch */
  4241. + int call_arg; /* optional call parameter */
  4242. +
  4243. + FusionRef *inherited;
  4244. + FusionLink *inheritors;
  4245. +
  4246. + FusionLink *local_refs;
  4247. +};
  4248. +
  4249. +/**********************************************************************************************************************/
  4250. +
  4251. +static int add_local ( FusionRef *ref, FusionID fusion_id, int add );
  4252. +static void clear_local ( FusionDev *dev, FusionRef *ref, FusionID fusion_id );
  4253. +static int fork_local ( FusionDev *dev, FusionRef *ref, FusionID fusion_id, FusionID from_id );
  4254. +static void free_all_local ( FusionRef *ref );
  4255. +
  4256. +static int propagate_local ( FusionDev *dev, FusionRef *ref, int diff );
  4257. +
  4258. +static void notify_ref ( FusionDev *dev, FusionRef *ref );
  4259. +
  4260. +static int add_inheritor ( FusionRef *ref, FusionRef *from );
  4261. +static void remove_inheritor( FusionRef *ref, FusionRef *from );
  4262. +static void drop_inheritors ( FusionDev *dev, FusionRef *ref );
  4263. +
  4264. +/**********************************************************************************************************************/
  4265. +
  4266. +static void
  4267. +fusion_ref_destruct( FusionEntry *entry,
  4268. + void *ctx )
  4269. +{
  4270. + FusionRef *ref = (FusionRef*) entry;
  4271. + FusionDev *dev = (FusionDev*) ctx;
  4272. +
  4273. + drop_inheritors( dev, ref );
  4274. +
  4275. + if (ref->inherited)
  4276. + remove_inheritor( ref, ref->inherited );
  4277. +
  4278. + free_all_local( ref );
  4279. +}
  4280. +
  4281. +static int
  4282. +fusion_ref_print( FusionEntry *entry,
  4283. + void *ctx,
  4284. + char *buf )
  4285. +{
  4286. + FusionRef *ref = (FusionRef*) entry;
  4287. +
  4288. + if (ref->locked)
  4289. + return sprintf( buf, "%2d %2d (locked by %d)\n", ref->global, ref->local, ref->locked );
  4290. +
  4291. + return sprintf( buf, "%2d %2d\n", ref->global, ref->local );
  4292. +}
  4293. +
  4294. +FUSION_ENTRY_CLASS( FusionRef, ref, NULL,
  4295. + fusion_ref_destruct, fusion_ref_print );
  4296. +
  4297. +/**********************************************************************************************************************/
  4298. +
  4299. +int
  4300. +fusion_ref_init( FusionDev *dev )
  4301. +{
  4302. + fusion_entries_init( &dev->ref, &ref_class, dev );
  4303. +
  4304. + create_proc_read_entry( "refs", 0, dev->proc_dir, fusion_entries_read_proc, &dev->ref );
  4305. +
  4306. + return 0;
  4307. +}
  4308. +
  4309. +void
  4310. +fusion_ref_deinit( FusionDev *dev )
  4311. +{
  4312. + remove_proc_entry( "refs", dev->proc_dir );
  4313. +
  4314. + fusion_entries_deinit( &dev->ref );
  4315. +}
  4316. +
  4317. +/**********************************************************************************************************************/
  4318. +
  4319. +int
  4320. +fusion_ref_new( FusionDev *dev, int *ret_id )
  4321. +{
  4322. + return fusion_entry_create( &dev->ref, ret_id, NULL );
  4323. +}
  4324. +
  4325. +int
  4326. +fusion_ref_up (FusionDev *dev, int id, FusionID fusion_id)
  4327. +{
  4328. + int ret;
  4329. + FusionRef *ref;
  4330. +
  4331. + ret = fusion_ref_lock( &dev->ref, id, true, &ref );
  4332. + if (ret)
  4333. + return ret;
  4334. +
  4335. + dev->stat.ref_up++;
  4336. +
  4337. + if (ref->locked) {
  4338. + ret = -EAGAIN;
  4339. + goto out;
  4340. + }
  4341. +
  4342. + if (fusion_id) {
  4343. + ret = add_local (ref, fusion_id, 1);
  4344. + if (ret)
  4345. + goto out;
  4346. +
  4347. + ret = propagate_local( dev, ref, 1 );
  4348. + }
  4349. + else
  4350. + ref->global++;
  4351. +
  4352. +
  4353. +out:
  4354. + fusion_ref_unlock( ref );
  4355. + up( &dev->ref.lock );
  4356. +
  4357. + return ret;
  4358. +}
  4359. +
  4360. +int
  4361. +fusion_ref_down (FusionDev *dev, int id, FusionID fusion_id)
  4362. +{
  4363. + int ret;
  4364. + FusionRef *ref;
  4365. +
  4366. + ret = fusion_ref_lock( &dev->ref, id, true, &ref );
  4367. + if (ret)
  4368. + return ret;
  4369. +
  4370. + dev->stat.ref_down++;
  4371. +
  4372. + if (ref->locked) {
  4373. + ret = -EAGAIN;
  4374. + goto out;
  4375. + }
  4376. +
  4377. + if (fusion_id) {
  4378. + ret = -EIO;
  4379. + if (!ref->local)
  4380. + goto out;
  4381. +
  4382. + ret = add_local (ref, fusion_id, -1);
  4383. + if (ret)
  4384. + goto out;
  4385. +
  4386. + ret = propagate_local( dev, ref, -1 );
  4387. + }
  4388. + else {
  4389. + if (!ref->global) {
  4390. + ret = -EIO;
  4391. + goto out;
  4392. + }
  4393. +
  4394. + ref->global--;
  4395. +
  4396. + if (ref->local + ref->global == 0)
  4397. + notify_ref (dev, ref);
  4398. + }
  4399. +
  4400. +
  4401. +out:
  4402. + fusion_ref_unlock( ref );
  4403. + up( &dev->ref.lock );
  4404. +
  4405. + return ret;
  4406. +}
  4407. +
  4408. +int
  4409. +fusion_ref_zero_lock (FusionDev *dev, int id, FusionID fusion_id)
  4410. +{
  4411. + int ret;
  4412. + FusionRef *ref;
  4413. +
  4414. + ret = fusion_ref_lock( &dev->ref, id, false, &ref );
  4415. + if (ret)
  4416. + return ret;
  4417. +
  4418. + while (true) {
  4419. + if (ref->watched) {
  4420. + fusion_ref_unlock( ref );
  4421. + return -EACCES;
  4422. + }
  4423. +
  4424. + if (ref->locked) {
  4425. + fusion_ref_unlock( ref );
  4426. + return ref->locked == fusion_id ? -EIO : -EAGAIN;
  4427. + }
  4428. +
  4429. + if (ref->global || ref->local) {
  4430. + ret = fusion_ref_wait( ref, NULL );
  4431. + if (ret)
  4432. + return ret;
  4433. + }
  4434. + else
  4435. + break;
  4436. + }
  4437. +
  4438. + ref->locked = fusion_id;
  4439. +
  4440. + fusion_ref_unlock( ref );
  4441. +
  4442. + return 0;
  4443. +}
  4444. +
  4445. +int
  4446. +fusion_ref_zero_trylock (FusionDev *dev, int id, FusionID fusion_id)
  4447. +{
  4448. + int ret;
  4449. + FusionRef *ref;
  4450. +
  4451. + ret = fusion_ref_lock( &dev->ref, id, false, &ref );
  4452. + if (ret)
  4453. + return ret;
  4454. +
  4455. + if (ref->locked) {
  4456. + fusion_ref_unlock( ref );
  4457. + return ref->locked == fusion_id ? -EIO : -EAGAIN;
  4458. + }
  4459. +
  4460. + if (ref->global || ref->local)
  4461. + ret = -ETOOMANYREFS;
  4462. + else
  4463. + ref->locked = fusion_id;
  4464. +
  4465. + fusion_ref_unlock( ref );
  4466. +
  4467. + return ret;
  4468. +}
  4469. +
  4470. +int
  4471. +fusion_ref_zero_unlock (FusionDev *dev, int id, FusionID fusion_id)
  4472. +{
  4473. + int ret;
  4474. + FusionRef *ref;
  4475. +
  4476. + ret = fusion_ref_lock( &dev->ref, id, false, &ref );
  4477. + if (ret)
  4478. + return ret;
  4479. +
  4480. + if (ref->locked != fusion_id) {
  4481. + fusion_ref_unlock( ref );
  4482. + return -EIO;
  4483. + }
  4484. +
  4485. + ref->locked = 0;
  4486. +
  4487. + fusion_ref_unlock( ref );
  4488. +
  4489. + return 0;
  4490. +}
  4491. +
  4492. +int
  4493. +fusion_ref_stat (FusionDev *dev, int id, int *refs)
  4494. +{
  4495. + int ret;
  4496. + FusionRef *ref;
  4497. +
  4498. + ret = fusion_ref_lock( &dev->ref, id, false, &ref );
  4499. + if (ret)
  4500. + return ret;
  4501. +
  4502. + *refs = ref->global + ref->local;
  4503. +
  4504. + fusion_ref_unlock( ref );
  4505. +
  4506. + return 0;
  4507. +}
  4508. +
  4509. +int
  4510. +fusion_ref_watch (FusionDev *dev,
  4511. + int id,
  4512. + int call_id,
  4513. + int call_arg)
  4514. +{
  4515. + int ret;
  4516. + FusionRef *ref;
  4517. +
  4518. + ret = fusion_ref_lock( &dev->ref, id, false, &ref );
  4519. + if (ret)
  4520. + return ret;
  4521. +
  4522. + if (ref->entry.pid != current->pid) {
  4523. + fusion_ref_unlock( ref );
  4524. + return -EACCES;
  4525. + }
  4526. +
  4527. + if (ref->global + ref->local == 0) {
  4528. + fusion_ref_unlock( ref );
  4529. + return -EIO;
  4530. + }
  4531. +
  4532. + if (ref->watched) {
  4533. + fusion_ref_unlock( ref );
  4534. + return -EBUSY;
  4535. + }
  4536. +
  4537. + ref->watched = true;
  4538. + ref->call_id = call_id;
  4539. + ref->call_arg = call_arg;
  4540. +
  4541. + fusion_ref_notify( ref, true );
  4542. +
  4543. + fusion_ref_unlock( ref );
  4544. +
  4545. + return 0;
  4546. +}
  4547. +
  4548. +int
  4549. +fusion_ref_inherit (FusionDev *dev,
  4550. + int id,
  4551. + int from_id)
  4552. +{
  4553. + int ret;
  4554. + FusionRef *ref;
  4555. + FusionRef *from = NULL;
  4556. +
  4557. + ret = fusion_ref_lock( &dev->ref, id, true, &ref );
  4558. + if (ret)
  4559. + return ret;
  4560. +
  4561. + ret = -EBUSY;
  4562. + if (ref->inherited)
  4563. + goto out;
  4564. +
  4565. + ret = -EINVAL;
  4566. + fusion_list_foreach (from, dev->ref.list) {
  4567. + if (from->entry.id == from_id) {
  4568. + if (down_interruptible( &from->entry.lock )) {
  4569. + ret = -EINTR;
  4570. + from = NULL;
  4571. + }
  4572. +
  4573. + break;
  4574. + }
  4575. + }
  4576. + if (!from)
  4577. + goto out;
  4578. +
  4579. + ret = add_inheritor( ref, from );
  4580. + if (ret)
  4581. + goto out;
  4582. +
  4583. + ret = propagate_local( dev, ref, from->local );
  4584. + if (ret)
  4585. + goto out;
  4586. +
  4587. + ref->inherited = from;
  4588. +
  4589. +out:
  4590. + if (from)
  4591. + up( &from->entry.lock );
  4592. +
  4593. + fusion_ref_unlock( ref );
  4594. + up ( &dev->ref.lock );
  4595. +
  4596. + return ret;
  4597. +}
  4598. +
  4599. +int
  4600. +fusion_ref_destroy (FusionDev *dev, int id)
  4601. +{
  4602. + return fusion_entry_destroy( &dev->ref, id );
  4603. +}
  4604. +
  4605. +void
  4606. +fusion_ref_clear_all_local( FusionDev *dev, FusionID fusion_id )
  4607. +{
  4608. + FusionRef *ref;
  4609. +
  4610. + down( &dev->ref.lock );
  4611. +
  4612. + fusion_list_foreach (ref, dev->ref.list)
  4613. + clear_local( dev, ref, fusion_id );
  4614. +
  4615. + up( &dev->ref.lock );
  4616. +}
  4617. +
  4618. +int
  4619. +fusion_ref_fork_all_local( FusionDev *dev, FusionID fusion_id, FusionID from_id )
  4620. +{
  4621. + FusionRef *ref;
  4622. + int ret = 0;
  4623. +
  4624. + down( &dev->ref.lock );
  4625. +
  4626. + fusion_list_foreach (ref, dev->ref.list) {
  4627. + ret = fork_local( dev, ref, fusion_id, from_id );
  4628. + if (ret)
  4629. + break;
  4630. + }
  4631. +
  4632. + up( &dev->ref.lock );
  4633. +
  4634. + return ret;
  4635. +}
  4636. +
  4637. +/**********************************************************************************************************************/
  4638. +
  4639. +static int
  4640. +add_local (FusionRef *ref, FusionID fusion_id, int add)
  4641. +{
  4642. + FusionLink *l;
  4643. + LocalRef *local;
  4644. +
  4645. + fusion_list_foreach (l, ref->local_refs) {
  4646. + local = (LocalRef *) l;
  4647. +
  4648. + if (local->fusion_id == fusion_id) {
  4649. + fusion_list_move_to_front( &ref->local_refs, l );
  4650. +
  4651. + if (local->refs + add < 0)
  4652. + return -EIO;
  4653. +
  4654. + local->refs += add;
  4655. + return 0;
  4656. + }
  4657. + }
  4658. +
  4659. + /* Can only create local node if value is positive. */
  4660. + if (add <= 0)
  4661. + return -EIO;
  4662. +
  4663. + local = kmalloc (sizeof(LocalRef), GFP_KERNEL);
  4664. + if (!local)
  4665. + return -ENOMEM;
  4666. +
  4667. + local->fusion_id = fusion_id;
  4668. + local->refs = add;
  4669. +
  4670. + fusion_list_prepend (&ref->local_refs, &local->link);
  4671. +
  4672. + return 0;
  4673. +}
  4674. +
  4675. +static void
  4676. +clear_local (FusionDev *dev, FusionRef *ref, FusionID fusion_id)
  4677. +{
  4678. + FusionLink *l;
  4679. +
  4680. + down (&ref->entry.lock);
  4681. +
  4682. + if (ref->locked == fusion_id) {
  4683. + ref->locked = 0;
  4684. + wake_up_interruptible_all (&ref->entry.wait);
  4685. + }
  4686. +
  4687. + fusion_list_foreach (l, ref->local_refs) {
  4688. + LocalRef *local = (LocalRef *) l;
  4689. +
  4690. + if (local->fusion_id == fusion_id) {
  4691. + if (local->refs)
  4692. + propagate_local( dev, ref, - local->refs );
  4693. +
  4694. + fusion_list_remove( &ref->local_refs, l );
  4695. +
  4696. + kfree (l);
  4697. + break;
  4698. + }
  4699. + }
  4700. +
  4701. + up (&ref->entry.lock);
  4702. +}
  4703. +
  4704. +static int
  4705. +fork_local (FusionDev *dev, FusionRef *ref, FusionID fusion_id, FusionID from_id)
  4706. +{
  4707. + FusionLink *l;
  4708. + int ret = 0;
  4709. +
  4710. + down (&ref->entry.lock);
  4711. +
  4712. + fusion_list_foreach (l, ref->local_refs) {
  4713. + LocalRef *local = (LocalRef *) l;
  4714. +
  4715. + if (local->fusion_id == from_id) {
  4716. + if (local->refs) {
  4717. + LocalRef *new_local;
  4718. +
  4719. + new_local = kmalloc (sizeof(LocalRef), GFP_KERNEL);
  4720. + if (!new_local) {
  4721. + ret = -ENOMEM;
  4722. + break;
  4723. + }
  4724. +
  4725. + new_local->fusion_id = fusion_id;
  4726. + new_local->refs = local->refs;
  4727. +
  4728. + fusion_list_prepend( &ref->local_refs, &new_local->link );
  4729. +
  4730. + propagate_local( dev, ref, local->refs );
  4731. + }
  4732. + break;
  4733. + }
  4734. + }
  4735. +
  4736. + up (&ref->entry.lock);
  4737. +
  4738. + return ret;
  4739. +}
  4740. +
  4741. +static void
  4742. +free_all_local (FusionRef *ref)
  4743. +{
  4744. + FusionLink *l = ref->local_refs;
  4745. +
  4746. + while (l) {
  4747. + FusionLink *next = l->next;
  4748. +
  4749. + kfree (l);
  4750. +
  4751. + l = next;
  4752. + }
  4753. +
  4754. + ref->local_refs = NULL;
  4755. +}
  4756. +
  4757. +static void
  4758. +notify_ref (FusionDev *dev, FusionRef *ref)
  4759. +{
  4760. + if (ref->watched) {
  4761. + FusionCallExecute execute;
  4762. +
  4763. + execute.call_id = ref->call_id;
  4764. + execute.call_arg = ref->call_arg;
  4765. + execute.call_ptr = NULL;
  4766. +
  4767. + fusion_call_execute (dev, 0, &execute);
  4768. + }
  4769. + else
  4770. + wake_up_interruptible_all (&ref->entry.wait);
  4771. +}
  4772. +
  4773. +static int
  4774. +propagate_local( FusionDev *dev, FusionRef *ref, int diff )
  4775. +{
  4776. + FusionLink *l;
  4777. +
  4778. + /* Recurse into inheritors. */
  4779. + fusion_list_foreach (l, ref->inheritors) {
  4780. + FusionRef *inheritor = ((Inheritor*) l)->ref;
  4781. +
  4782. + if (down_interruptible( &inheritor->entry.lock )) {
  4783. + printk( KERN_ERR "fusion_ref: propagate_local() interrupted!\n" );
  4784. + //return -EINTR;
  4785. + }
  4786. +
  4787. + propagate_local( dev, inheritor, diff );
  4788. +
  4789. + up( &inheritor->entry.lock );
  4790. + }
  4791. +
  4792. + /* Apply difference. */
  4793. + ref->local += diff;
  4794. +
  4795. + /* Notify zero count. */
  4796. + if (ref->local + ref->global == 0)
  4797. + notify_ref( dev, ref );
  4798. +
  4799. + return 0;
  4800. +}
  4801. +
  4802. +static int
  4803. +add_inheritor(FusionRef *ref, FusionRef *from)
  4804. +{
  4805. + Inheritor *inheritor;
  4806. +
  4807. + inheritor = kmalloc (sizeof(Inheritor), GFP_KERNEL);
  4808. + if (!inheritor)
  4809. + return -ENOMEM;
  4810. +
  4811. + inheritor->ref = ref;
  4812. +
  4813. + fusion_list_prepend( &from->inheritors, &inheritor->link );
  4814. +
  4815. + return 0;
  4816. +}
  4817. +
  4818. +static void
  4819. +remove_inheritor(FusionRef *ref, FusionRef *from)
  4820. +{
  4821. + FusionLink *l;
  4822. +
  4823. + down( &from->entry.lock );
  4824. +
  4825. + fusion_list_foreach (l, from->inheritors) {
  4826. + Inheritor *inheritor = (Inheritor*) l;
  4827. +
  4828. + if (inheritor->ref == ref) {
  4829. + fusion_list_remove( &from->inheritors, &inheritor->link );
  4830. +
  4831. + kfree( l );
  4832. + break;
  4833. + }
  4834. + }
  4835. +
  4836. + up( &from->entry.lock );
  4837. +}
  4838. +
  4839. +static void
  4840. +drop_inheritors( FusionDev *dev, FusionRef *ref )
  4841. +{
  4842. + FusionLink *l = ref->inheritors;
  4843. +
  4844. + while (l) {
  4845. + FusionLink *next = l->next;
  4846. + FusionRef *inheritor = ((Inheritor*) l)->ref;
  4847. +
  4848. + if (down_interruptible( &inheritor->entry.lock )) {
  4849. + printk( KERN_ERR "fusion_ref: drop_inheritors() interrupted!\n" );
  4850. + //return;
  4851. + }
  4852. +
  4853. + propagate_local( dev, inheritor, - ref->local );
  4854. +
  4855. + inheritor->inherited = NULL;
  4856. +
  4857. + up( &inheritor->entry.lock );
  4858. +
  4859. +
  4860. + kfree (l);
  4861. +
  4862. + l = next;
  4863. + }
  4864. +
  4865. + ref->inheritors = NULL;
  4866. +}
  4867. +
  4868. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/ref.h linux-2.6.22.1/drivers/char/fusion/ref.h
  4869. --- linux-2.6.22.1-0rig/drivers/char/fusion/ref.h 1970-01-01 01:00:00.000000000 +0100
  4870. +++ linux-2.6.22.1/drivers/char/fusion/ref.h 2006-08-14 11:16:54.000000000 +0200
  4871. @@ -0,0 +1,79 @@
  4872. +/*
  4873. + * Fusion Kernel Module
  4874. + *
  4875. + * (c) Copyright 2002-2003 Convergence GmbH
  4876. + *
  4877. + * Written by Denis Oliver Kropp <dok@directfb.org>
  4878. + *
  4879. + *
  4880. + * This program is free software; you can redistribute it and/or
  4881. + * modify it under the terms of the GNU General Public License
  4882. + * as published by the Free Software Foundation; either version
  4883. + * 2 of the License, or (at your option) any later version.
  4884. + */
  4885. +
  4886. +#ifndef __FUSION__REF_H__
  4887. +#define __FUSION__REF_H__
  4888. +
  4889. +#include "fusiondev.h"
  4890. +#include "types.h"
  4891. +
  4892. +
  4893. +/* module init/cleanup */
  4894. +
  4895. +int fusion_ref_init (FusionDev *dev);
  4896. +void fusion_ref_deinit (FusionDev *dev);
  4897. +
  4898. +
  4899. +/* public API */
  4900. +
  4901. +int fusion_ref_new (FusionDev *dev,
  4902. + int *id);
  4903. +
  4904. +int fusion_ref_up (FusionDev *dev,
  4905. + int id,
  4906. + FusionID fusion_id);
  4907. +
  4908. +int fusion_ref_down (FusionDev *dev,
  4909. + int id,
  4910. + FusionID fusion_id);
  4911. +
  4912. +int fusion_ref_zero_lock (FusionDev *dev,
  4913. + int id,
  4914. + FusionID fusion_id);
  4915. +
  4916. +int fusion_ref_zero_trylock (FusionDev *dev,
  4917. + int id,
  4918. + FusionID fusion_id);
  4919. +
  4920. +int fusion_ref_zero_unlock (FusionDev *dev,
  4921. + int id,
  4922. + FusionID fusion_id);
  4923. +
  4924. +int fusion_ref_stat (FusionDev *dev,
  4925. + int id,
  4926. + int *refs);
  4927. +
  4928. +int fusion_ref_watch (FusionDev *dev,
  4929. + int id,
  4930. + int call_id,
  4931. + int call_arg);
  4932. +
  4933. +int fusion_ref_inherit (FusionDev *dev,
  4934. + int id,
  4935. + int from);
  4936. +
  4937. +int fusion_ref_destroy (FusionDev *dev,
  4938. + int id);
  4939. +
  4940. +
  4941. +/* internal functions */
  4942. +
  4943. +void fusion_ref_clear_all_local (FusionDev *dev,
  4944. + FusionID fusion_id);
  4945. +
  4946. +int fusion_ref_fork_all_local (FusionDev *dev,
  4947. + FusionID fusion_id,
  4948. + FusionID from_id);
  4949. +
  4950. +#endif
  4951. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/shmpool.c linux-2.6.22.1/drivers/char/fusion/shmpool.c
  4952. --- linux-2.6.22.1-0rig/drivers/char/fusion/shmpool.c 1970-01-01 01:00:00.000000000 +0100
  4953. +++ linux-2.6.22.1/drivers/char/fusion/shmpool.c 2007-01-20 05:03:01.000000000 +0100
  4954. @@ -0,0 +1,444 @@
  4955. +/*
  4956. + * Fusion Kernel Module
  4957. + *
  4958. + * (c) Copyright 2002-2003 Convergence GmbH
  4959. + *
  4960. + * Written by Denis Oliver Kropp <dok@directfb.org>
  4961. + *
  4962. + *
  4963. + * This program is free software; you can redistribute it and/or
  4964. + * modify it under the terms of the GNU General Public License
  4965. + * as published by the Free Software Foundation; either version
  4966. + * 2 of the License, or (at your option) any later version.
  4967. + */
  4968. +
  4969. +#ifdef HAVE_LINUX_CONFIG_H
  4970. +#include <linux/config.h>
  4971. +#endif
  4972. +#include <linux/types.h>
  4973. +#include <linux/kernel.h>
  4974. +#include <linux/slab.h>
  4975. +#include <linux/smp_lock.h>
  4976. +#include <linux/sched.h>
  4977. +
  4978. +#include <linux/fusion.h>
  4979. +
  4980. +#include "fusiondev.h"
  4981. +#include "fusionee.h"
  4982. +#include "list.h"
  4983. +#include "shmpool.h"
  4984. +
  4985. +
  4986. +#define SHM_BASE 0x20010000 /* virtual base address */
  4987. +#define SHM_SIZE 0x1FFEF000 /* size of virtual address space */
  4988. +
  4989. +
  4990. +typedef struct {
  4991. + FusionLink link;
  4992. + unsigned long next_base;
  4993. +} AddrEntry;
  4994. +
  4995. +
  4996. +typedef struct {
  4997. + FusionLink link;
  4998. +
  4999. + FusionID fusion_id;
  5000. +
  5001. + int count; /* number of attach calls */
  5002. +} SHMPoolNode;
  5003. +
  5004. +typedef struct {
  5005. + FusionEntry entry;
  5006. +
  5007. + int max_size;
  5008. +
  5009. + void *addr_base;
  5010. + int size;
  5011. +
  5012. + AddrEntry *addr_entry;
  5013. +
  5014. + FusionLink *nodes;
  5015. +
  5016. + int dispatch_count;
  5017. +} FusionSHMPool;
  5018. +
  5019. +/******************************************************************************/
  5020. +
  5021. +static SHMPoolNode *get_node ( FusionSHMPool *shmpool,
  5022. + FusionID fusion_id );
  5023. +
  5024. +static void remove_node ( FusionSHMPool *shmpool,
  5025. + FusionID fusion_id );
  5026. +
  5027. +static int fork_node ( FusionSHMPool *shmpool,
  5028. + FusionID fusion_id,
  5029. + FusionID from_id );
  5030. +
  5031. +static void free_all_nodes( FusionSHMPool *shmpool );
  5032. +
  5033. +/******************************************************************************/
  5034. +
  5035. +
  5036. +static DECLARE_MUTEX (addr_lock);
  5037. +static FusionLink *addr_entries;
  5038. +static unsigned long addr_base = SHM_BASE;
  5039. +
  5040. +/******************************************************************************/
  5041. +
  5042. +static AddrEntry *
  5043. +add_addr_entry( unsigned long next_base )
  5044. +{
  5045. + AddrEntry *entry = kmalloc( sizeof(AddrEntry), GFP_KERNEL );
  5046. +
  5047. + entry->next_base = next_base;
  5048. +
  5049. + fusion_list_prepend( &addr_entries, &entry->link );
  5050. +
  5051. + return entry;
  5052. +}
  5053. +
  5054. +/******************************************************************************/
  5055. +
  5056. +static int
  5057. +fusion_shmpool_construct( FusionEntry *entry,
  5058. + void *ctx,
  5059. + void *create_ctx )
  5060. +{
  5061. + FusionSHMPool *shmpool = (FusionSHMPool*) entry;
  5062. + FusionSHMPoolNew *poolnew = create_ctx;
  5063. +
  5064. + down( &addr_lock );
  5065. +
  5066. + if (addr_base + poolnew->max_size >= SHM_BASE + SHM_SIZE) {
  5067. + up( &addr_lock );
  5068. + printk( KERN_WARNING "%s: virtual address space exhausted! (FIXME)\n", __FUNCTION__ );
  5069. + return -ENOSPC;
  5070. + }
  5071. +
  5072. + shmpool->max_size = poolnew->max_size;
  5073. + shmpool->addr_base = poolnew->addr_base = (void*) addr_base;
  5074. +
  5075. + addr_base += PAGE_ALIGN(poolnew->max_size) + PAGE_SIZE; /* fence page */
  5076. +
  5077. + shmpool->addr_entry = add_addr_entry( addr_base );
  5078. +
  5079. + up( &addr_lock );
  5080. +
  5081. + return 0;
  5082. +}
  5083. +
  5084. +static void
  5085. +fusion_shmpool_destruct( FusionEntry *entry,
  5086. + void *ctx )
  5087. +{
  5088. + AddrEntry *addr_entry;
  5089. + FusionSHMPool *shmpool = (FusionSHMPool*) entry;
  5090. +
  5091. + free_all_nodes( shmpool );
  5092. +
  5093. +
  5094. + down( &addr_lock );
  5095. +
  5096. + fusion_list_remove( &addr_entries, &shmpool->addr_entry->link );
  5097. +
  5098. +
  5099. + /*
  5100. + * free trailing address space
  5101. + */
  5102. +
  5103. + addr_base = SHM_BASE;
  5104. +
  5105. + fusion_list_foreach (addr_entry, addr_entries) {
  5106. + if (addr_entry->next_base > addr_base)
  5107. + addr_base = addr_entry->next_base;
  5108. + }
  5109. +
  5110. + up( &addr_lock );
  5111. +}
  5112. +
  5113. +static int
  5114. +fusion_shmpool_print( FusionEntry *entry,
  5115. + void *ctx,
  5116. + char *buf )
  5117. +{
  5118. + int num = 0;
  5119. + FusionSHMPool *shmpool = (FusionSHMPool*) entry;
  5120. + FusionLink *node = shmpool->nodes;
  5121. +
  5122. + fusion_list_foreach (node, shmpool->nodes) {
  5123. + num++;
  5124. + }
  5125. +
  5126. + return sprintf( buf, "0x%p [0x%x] - 0x%x, %dx dispatch, %d nodes\n",
  5127. + shmpool->addr_base, shmpool->max_size, shmpool->size,
  5128. + shmpool->dispatch_count, num );
  5129. +}
  5130. +
  5131. +
  5132. +FUSION_ENTRY_CLASS( FusionSHMPool, shmpool, fusion_shmpool_construct,
  5133. + fusion_shmpool_destruct, fusion_shmpool_print )
  5134. +
  5135. +/******************************************************************************/
  5136. +
  5137. +int
  5138. +fusion_shmpool_init (FusionDev *dev)
  5139. +{
  5140. + fusion_entries_init( &dev->shmpool, &shmpool_class, dev );
  5141. +
  5142. + create_proc_read_entry( "shmpools", 0, dev->proc_dir,
  5143. + fusion_entries_read_proc, &dev->shmpool );
  5144. +
  5145. + return 0;
  5146. +}
  5147. +
  5148. +void
  5149. +fusion_shmpool_deinit (FusionDev *dev)
  5150. +{
  5151. + remove_proc_entry ("shmpools", dev->proc_dir);
  5152. +
  5153. + fusion_entries_deinit( &dev->shmpool );
  5154. +}
  5155. +
  5156. +/******************************************************************************/
  5157. +
  5158. +int
  5159. +fusion_shmpool_new (FusionDev *dev,
  5160. + FusionSHMPoolNew *pool)
  5161. +{
  5162. + if (pool->max_size <= 0)
  5163. + return -EINVAL;
  5164. +
  5165. + return fusion_entry_create( &dev->shmpool, &pool->pool_id, pool );
  5166. +}
  5167. +
  5168. +int
  5169. +fusion_shmpool_attach (FusionDev *dev,
  5170. + FusionSHMPoolAttach *attach,
  5171. + FusionID fusion_id)
  5172. +{
  5173. + int ret;
  5174. + SHMPoolNode *node;
  5175. + FusionSHMPool *shmpool;
  5176. +
  5177. + ret = fusion_shmpool_lock( &dev->shmpool, attach->pool_id, false, &shmpool );
  5178. + if (ret)
  5179. + return ret;
  5180. +
  5181. + dev->stat.shmpool_attach++;
  5182. +
  5183. + node = get_node (shmpool, fusion_id);
  5184. + if (!node) {
  5185. + node = kmalloc (sizeof(SHMPoolNode), GFP_KERNEL);
  5186. + if (!node) {
  5187. + fusion_shmpool_unlock( shmpool );
  5188. + return -ENOMEM;
  5189. + }
  5190. +
  5191. + node->fusion_id = fusion_id;
  5192. + node->count = 1;
  5193. +
  5194. + fusion_list_prepend (&shmpool->nodes, &node->link);
  5195. + }
  5196. + else
  5197. + node->count++;
  5198. +
  5199. + attach->addr_base = shmpool->addr_base;
  5200. + attach->size = shmpool->size;
  5201. +
  5202. + fusion_shmpool_unlock( shmpool );
  5203. +
  5204. + return 0;
  5205. +}
  5206. +
  5207. +int
  5208. +fusion_shmpool_detach (FusionDev *dev, int id, FusionID fusion_id)
  5209. +{
  5210. + int ret;
  5211. + SHMPoolNode *node;
  5212. + FusionSHMPool *shmpool;
  5213. +
  5214. + ret = fusion_shmpool_lock( &dev->shmpool, id, false, &shmpool );
  5215. + if (ret)
  5216. + return ret;
  5217. +
  5218. + dev->stat.shmpool_detach++;
  5219. +
  5220. + node = get_node (shmpool, fusion_id);
  5221. + if (!node) {
  5222. + fusion_shmpool_unlock( shmpool );
  5223. + return -EIO;
  5224. + }
  5225. +
  5226. + if (! --node->count) {
  5227. + fusion_list_remove (&shmpool->nodes, &node->link);
  5228. + kfree (node);
  5229. + }
  5230. +
  5231. + fusion_shmpool_unlock( shmpool );
  5232. +
  5233. + return 0;
  5234. +}
  5235. +
  5236. +int
  5237. +fusion_shmpool_dispatch( FusionDev *dev,
  5238. + FusionSHMPoolDispatch *dispatch,
  5239. + Fusionee *fusionee )
  5240. +{
  5241. + int ret;
  5242. + FusionLink *l;
  5243. + FusionSHMPool *shmpool;
  5244. + FusionSHMPoolMessage message;
  5245. + FusionID fusion_id = fusionee_id( fusionee );
  5246. +
  5247. + if (dispatch->size <= 0)
  5248. + return -EINVAL;
  5249. +
  5250. + ret = fusion_shmpool_lock( &dev->shmpool, dispatch->pool_id, false, &shmpool );
  5251. + if (ret)
  5252. + return ret;
  5253. +
  5254. + message.type = FSMT_REMAP;
  5255. + message.size = dispatch->size;
  5256. +
  5257. + shmpool->dispatch_count++;
  5258. +
  5259. + shmpool->size = dispatch->size;
  5260. +
  5261. + fusion_list_foreach (l, shmpool->nodes) {
  5262. + SHMPoolNode *node = (SHMPoolNode *) l;
  5263. +
  5264. + if (node->fusion_id == fusion_id)
  5265. + continue;
  5266. +
  5267. + fusionee_send_message (dev, fusionee, node->fusion_id, FMT_SHMPOOL,
  5268. + shmpool->entry.id, sizeof(message), &message);
  5269. + }
  5270. +
  5271. + fusion_shmpool_unlock( shmpool );
  5272. +
  5273. + return 0;
  5274. +}
  5275. +
  5276. +int
  5277. +fusion_shmpool_destroy (FusionDev *dev, int id)
  5278. +{
  5279. + return fusion_entry_destroy( &dev->shmpool, id );
  5280. +}
  5281. +
  5282. +void
  5283. +fusion_shmpool_detach_all (FusionDev *dev, FusionID fusion_id)
  5284. +{
  5285. + FusionLink *l;
  5286. +
  5287. + down (&dev->shmpool.lock);
  5288. +
  5289. + fusion_list_foreach (l, dev->shmpool.list) {
  5290. + FusionSHMPool *shmpool = (FusionSHMPool *) l;
  5291. +
  5292. + remove_node (shmpool, fusion_id);
  5293. + }
  5294. +
  5295. + up (&dev->shmpool.lock);
  5296. +}
  5297. +
  5298. +int
  5299. +fusion_shmpool_fork_all( FusionDev *dev,
  5300. + FusionID fusion_id,
  5301. + FusionID from_id )
  5302. +{
  5303. + FusionLink *l;
  5304. + int ret = 0;
  5305. +
  5306. + down (&dev->shmpool.lock);
  5307. +
  5308. + fusion_list_foreach (l, dev->shmpool.list) {
  5309. + FusionSHMPool *shmpool = (FusionSHMPool *) l;
  5310. +
  5311. + ret = fork_node( shmpool, fusion_id, from_id );
  5312. + if (ret)
  5313. + break;
  5314. + }
  5315. +
  5316. + up (&dev->shmpool.lock);
  5317. +
  5318. + return ret;
  5319. +}
  5320. +
  5321. +/******************************************************************************/
  5322. +
  5323. +static SHMPoolNode *
  5324. +get_node (FusionSHMPool *shmpool,
  5325. + FusionID fusion_id)
  5326. +{
  5327. + SHMPoolNode *node;
  5328. +
  5329. + fusion_list_foreach (node, shmpool->nodes) {
  5330. + if (node->fusion_id == fusion_id)
  5331. + return node;
  5332. + }
  5333. +
  5334. + return NULL;
  5335. +}
  5336. +
  5337. +static void
  5338. +remove_node (FusionSHMPool *shmpool, FusionID fusion_id)
  5339. +{
  5340. + SHMPoolNode *node;
  5341. +
  5342. + down (&shmpool->entry.lock);
  5343. +
  5344. + fusion_list_foreach (node, shmpool->nodes) {
  5345. + if (node->fusion_id == fusion_id) {
  5346. + fusion_list_remove (&shmpool->nodes, &node->link);
  5347. + break;
  5348. + }
  5349. + }
  5350. +
  5351. + up (&shmpool->entry.lock);
  5352. +}
  5353. +
  5354. +static int
  5355. +fork_node (FusionSHMPool *shmpool, FusionID fusion_id, FusionID from_id)
  5356. +{
  5357. + int ret = 0;
  5358. + SHMPoolNode *node;
  5359. +
  5360. + down (&shmpool->entry.lock);
  5361. +
  5362. + fusion_list_foreach (node, shmpool->nodes) {
  5363. + if (node->fusion_id == from_id) {
  5364. + SHMPoolNode *new_node;
  5365. +
  5366. + new_node = kmalloc (sizeof(SHMPoolNode), GFP_KERNEL);
  5367. + if (!new_node) {
  5368. + ret = -ENOMEM;
  5369. + break;
  5370. + }
  5371. +
  5372. + new_node->fusion_id = fusion_id;
  5373. + new_node->count = node->count;
  5374. +
  5375. + fusion_list_prepend (&shmpool->nodes, &new_node->link);
  5376. +
  5377. + break;
  5378. + }
  5379. + }
  5380. +
  5381. + up (&shmpool->entry.lock);
  5382. +
  5383. + return ret;
  5384. +}
  5385. +
  5386. +static void
  5387. +free_all_nodes (FusionSHMPool *shmpool)
  5388. +
  5389. +{
  5390. + FusionLink *n;
  5391. + SHMPoolNode *node;
  5392. +
  5393. + fusion_list_foreach_safe (node, n, shmpool->nodes) {
  5394. + kfree (node);
  5395. + }
  5396. +
  5397. + shmpool->nodes = NULL;
  5398. +}
  5399. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/shmpool.h linux-2.6.22.1/drivers/char/fusion/shmpool.h
  5400. --- linux-2.6.22.1-0rig/drivers/char/fusion/shmpool.h 1970-01-01 01:00:00.000000000 +0100
  5401. +++ linux-2.6.22.1/drivers/char/fusion/shmpool.h 2007-01-20 05:03:01.000000000 +0100
  5402. @@ -0,0 +1,59 @@
  5403. +/*
  5404. + * Fusion Kernel Module
  5405. + *
  5406. + * (c) Copyright 2002-2003 Convergence GmbH
  5407. + *
  5408. + * Written by Denis Oliver Kropp <dok@directfb.org>
  5409. + *
  5410. + *
  5411. + * This program is free software; you can redistribute it and/or
  5412. + * modify it under the terms of the GNU General Public License
  5413. + * as published by the Free Software Foundation; either version
  5414. + * 2 of the License, or (at your option) any later version.
  5415. + */
  5416. +
  5417. +#ifndef __FUSION__SHMPOOL_H__
  5418. +#define __FUSION__SHMPOOL_H__
  5419. +
  5420. +#include "fusiondev.h"
  5421. +#include "types.h"
  5422. +
  5423. +
  5424. +/* module init/cleanup */
  5425. +
  5426. +int fusion_shmpool_init (FusionDev *dev);
  5427. +void fusion_shmpool_deinit (FusionDev *dev);
  5428. +
  5429. +
  5430. +/* public API */
  5431. +
  5432. +int fusion_shmpool_new (FusionDev *dev,
  5433. + FusionSHMPoolNew *pool);
  5434. +
  5435. +int fusion_shmpool_attach (FusionDev *dev,
  5436. + FusionSHMPoolAttach *attach,
  5437. + FusionID fusion_id);
  5438. +
  5439. +int fusion_shmpool_detach (FusionDev *dev,
  5440. + int id,
  5441. + FusionID fusion_id);
  5442. +
  5443. +int fusion_shmpool_dispatch (FusionDev *dev,
  5444. + FusionSHMPoolDispatch *dispatch,
  5445. + Fusionee *fusionee );
  5446. +
  5447. +int fusion_shmpool_destroy (FusionDev *dev,
  5448. + int id);
  5449. +
  5450. +
  5451. +/* internal functions */
  5452. +
  5453. +void fusion_shmpool_detach_all (FusionDev *dev,
  5454. + FusionID fusion_id);
  5455. +
  5456. +int fusion_shmpool_fork_all (FusionDev *dev,
  5457. + FusionID fusion_id,
  5458. + FusionID from_id);
  5459. +
  5460. +#endif
  5461. +
  5462. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/skirmish.c linux-2.6.22.1/drivers/char/fusion/skirmish.c
  5463. --- linux-2.6.22.1-0rig/drivers/char/fusion/skirmish.c 1970-01-01 01:00:00.000000000 +0100
  5464. +++ linux-2.6.22.1/drivers/char/fusion/skirmish.c 2007-01-06 14:09:45.000000000 +0100
  5465. @@ -0,0 +1,397 @@
  5466. +/*
  5467. + * Fusion Kernel Module
  5468. + *
  5469. + * (c) Copyright 2002-2003 Convergence GmbH
  5470. + *
  5471. + * Written by Denis Oliver Kropp <dok@directfb.org>
  5472. + *
  5473. + *
  5474. + * This program is free software; you can redistribute it and/or
  5475. + * modify it under the terms of the GNU General Public License
  5476. + * as published by the Free Software Foundation; either version
  5477. + * 2 of the License, or (at your option) any later version.
  5478. + */
  5479. +
  5480. +#ifdef HAVE_LINUX_CONFIG_H
  5481. +#include <linux/config.h>
  5482. +#endif
  5483. +#include <linux/types.h>
  5484. +#include <linux/kernel.h>
  5485. +#include <linux/slab.h>
  5486. +#include <linux/smp_lock.h>
  5487. +#include <linux/sched.h>
  5488. +
  5489. +#include <linux/fusion.h>
  5490. +
  5491. +#include "fusiondev.h"
  5492. +#include "fusionee.h"
  5493. +#include "list.h"
  5494. +#include "skirmish.h"
  5495. +
  5496. +
  5497. +#define MAX_PRE_ACQUISITIONS 32
  5498. +
  5499. +
  5500. +typedef struct __FUSION_FusionSkirmish FusionSkirmish;
  5501. +
  5502. +struct __FUSION_FusionSkirmish {
  5503. + FusionEntry entry;
  5504. +
  5505. + int lock_fid; /* non-zero if locked */
  5506. + int lock_pid;
  5507. + int lock_count;
  5508. +
  5509. + int lock_total;
  5510. +
  5511. +#ifdef FUSION_DEBUG_SKIRMISH_DEADLOCK
  5512. + int pre_acquis[MAX_PRE_ACQUISITIONS];
  5513. +
  5514. + bool outer;
  5515. +#endif
  5516. +};
  5517. +
  5518. +static int
  5519. +fusion_skirmish_print( FusionEntry *entry,
  5520. + void *ctx,
  5521. + char *buf )
  5522. +{
  5523. + int written = 0;
  5524. + FusionSkirmish *skirmish = (FusionSkirmish*) entry;
  5525. +
  5526. +#ifdef FUSION_DEBUG_SKIRMISH_DEADLOCK
  5527. + int i, n;
  5528. +
  5529. +
  5530. + for (i=0, n=0; i<MAX_PRE_ACQUISITIONS; i++) {
  5531. + if (skirmish->pre_acquis[i]) {
  5532. + n++;
  5533. + }
  5534. + }
  5535. +
  5536. + written += sprintf( buf + written, "[%2d]%s", n, skirmish->outer ? "." : " " );
  5537. +
  5538. + for (i=0, n=0; i<MAX_PRE_ACQUISITIONS; i++) {
  5539. + if (skirmish->pre_acquis[i]) {
  5540. + written += sprintf( buf + written, "%s%02x", n ? "," : "", skirmish->pre_acquis[i] - 1 );
  5541. +
  5542. + n++;
  5543. + }
  5544. + }
  5545. +#endif
  5546. +
  5547. + if (skirmish->lock_fid) {
  5548. + if (skirmish->entry.waiters)
  5549. + return sprintf( buf + written, " - %dx [0x%08x] (%d) %d WAITING\n",
  5550. + skirmish->lock_count, skirmish->lock_fid,
  5551. + skirmish->lock_pid, skirmish->entry.waiters ) + written;
  5552. + else
  5553. + return sprintf( buf + written, " - %dx [0x%08x] (%d)\n",
  5554. + skirmish->lock_count, skirmish->lock_fid,
  5555. + skirmish->lock_pid ) + written;
  5556. + }
  5557. +
  5558. + return sprintf( buf + written, "\n" ) + written;
  5559. +}
  5560. +
  5561. +FUSION_ENTRY_CLASS( FusionSkirmish, skirmish, NULL, NULL, fusion_skirmish_print )
  5562. +
  5563. +/******************************************************************************/
  5564. +
  5565. +int
  5566. +fusion_skirmish_init (FusionDev *dev)
  5567. +{
  5568. + fusion_entries_init( &dev->skirmish, &skirmish_class, dev );
  5569. +
  5570. + create_proc_read_entry( "skirmishs", 0, dev->proc_dir,
  5571. + fusion_entries_read_proc, &dev->skirmish );
  5572. +
  5573. + return 0;
  5574. +}
  5575. +
  5576. +void
  5577. +fusion_skirmish_deinit (FusionDev *dev)
  5578. +{
  5579. + remove_proc_entry ("skirmishs", dev->proc_dir);
  5580. +
  5581. + fusion_entries_deinit( &dev->skirmish );
  5582. +}
  5583. +
  5584. +/******************************************************************************/
  5585. +
  5586. +int
  5587. +fusion_skirmish_new (FusionDev *dev, int *ret_id)
  5588. +{
  5589. + return fusion_entry_create( &dev->skirmish, ret_id, NULL );
  5590. +}
  5591. +
  5592. +int
  5593. +fusion_skirmish_prevail (FusionDev *dev, int id, int fusion_id)
  5594. +{
  5595. + int ret;
  5596. + FusionSkirmish *skirmish;
  5597. +#ifdef FUSION_DEBUG_SKIRMISH_DEADLOCK
  5598. + FusionSkirmish *s;
  5599. + int i;
  5600. + bool outer = true;
  5601. +#endif
  5602. +
  5603. + dev->stat.skirmish_prevail_swoop++;
  5604. +
  5605. + ret = fusion_skirmish_lock( &dev->skirmish, id, true, &skirmish );
  5606. + if (ret)
  5607. + return ret;
  5608. +
  5609. + if (skirmish->lock_pid == current->pid) {
  5610. + skirmish->lock_count++;
  5611. + skirmish->lock_total++;
  5612. + fusion_skirmish_unlock( skirmish );
  5613. + up( &dev->skirmish.lock );
  5614. + return 0;
  5615. + }
  5616. +
  5617. +#ifdef FUSION_DEBUG_SKIRMISH_DEADLOCK
  5618. + /* look in currently acquired skirmishs for this one being
  5619. + a pre-acquisition, indicating a potential deadlock */
  5620. + fusion_list_foreach (s, dev->skirmish.list) {
  5621. + if (s->lock_pid != current->pid)
  5622. + continue;
  5623. +
  5624. + outer = false;
  5625. +
  5626. + for (i=0; i<MAX_PRE_ACQUISITIONS; i++) {
  5627. + if (s->pre_acquis[i] == id + 1) {
  5628. + printk( KERN_DEBUG "FusionSkirmish: Potential deadlock "
  5629. + "between locked 0x%x and to be locked 0x%x in world %d!\n",
  5630. + s->entry.id, skirmish->entry.id, dev->index );
  5631. + }
  5632. + }
  5633. + }
  5634. +
  5635. + if (outer)
  5636. + skirmish->outer = true;
  5637. +
  5638. + /* remember all previously acquired skirmishs being pre-acquisitions for
  5639. + this one, to detect potential deadlocks due to a lock order twist */
  5640. + fusion_list_foreach (s, dev->skirmish.list) {
  5641. + int free = -1;
  5642. +
  5643. + if (s->lock_pid != current->pid)
  5644. + continue;
  5645. +
  5646. + for (i=0; i<MAX_PRE_ACQUISITIONS; i++) {
  5647. + if (skirmish->pre_acquis[i]) {
  5648. + if (skirmish->pre_acquis[i] == s->entry.id + 1) {
  5649. + break;
  5650. + }
  5651. + }
  5652. + else
  5653. + free = i;
  5654. + }
  5655. +
  5656. + /* not found? */
  5657. + if (i == MAX_PRE_ACQUISITIONS) {
  5658. + if (free != -1) {
  5659. + skirmish->pre_acquis[free] = s->entry.id + 1;
  5660. + }
  5661. + else {
  5662. + printk( KERN_DEBUG "FusionSkirmish: Too many pre-acquisitions to remember.\n" );
  5663. +
  5664. + printk( KERN_DEBUG " [ '%s' ] <- ", skirmish->entry.name );
  5665. +
  5666. + for (i=0; i<MAX_PRE_ACQUISITIONS; i++)
  5667. + printk( "0x%03x ", skirmish->pre_acquis[i] - 1 );
  5668. +
  5669. + printk( "\n" );
  5670. + }
  5671. + }
  5672. + }
  5673. +#endif
  5674. +
  5675. + up( &dev->skirmish.lock );
  5676. +
  5677. + while (skirmish->lock_pid) {
  5678. + ret = fusion_skirmish_wait( skirmish, NULL );
  5679. + if (ret)
  5680. + return ret;
  5681. + }
  5682. +
  5683. + skirmish->lock_fid = fusion_id;
  5684. + skirmish->lock_pid = current->pid;
  5685. + skirmish->lock_count = 1;
  5686. +
  5687. + skirmish->lock_total++;
  5688. +
  5689. + fusion_skirmish_unlock( skirmish );
  5690. +
  5691. + return 0;
  5692. +}
  5693. +
  5694. +int
  5695. +fusion_skirmish_swoop (FusionDev *dev, int id, int fusion_id)
  5696. +{
  5697. + int ret;
  5698. + FusionSkirmish *skirmish;
  5699. +
  5700. + ret = fusion_skirmish_lock( &dev->skirmish, id, false, &skirmish );
  5701. + if (ret)
  5702. + return ret;
  5703. +
  5704. + dev->stat.skirmish_prevail_swoop++;
  5705. +
  5706. + if (skirmish->lock_fid) {
  5707. + if (skirmish->lock_pid == current->pid) {
  5708. + skirmish->lock_count++;
  5709. + skirmish->lock_total++;
  5710. + fusion_skirmish_unlock( skirmish );
  5711. + return 0;
  5712. + }
  5713. +
  5714. + fusion_skirmish_unlock( skirmish );
  5715. +
  5716. + return -EAGAIN;
  5717. + }
  5718. +
  5719. + skirmish->lock_fid = fusion_id;
  5720. + skirmish->lock_pid = current->pid;
  5721. + skirmish->lock_count = 1;
  5722. +
  5723. + skirmish->lock_total++;
  5724. +
  5725. + fusion_skirmish_unlock( skirmish );
  5726. +
  5727. + return 0;
  5728. +}
  5729. +
  5730. +int
  5731. +fusion_skirmish_lock_count (FusionDev *dev, int id, int fusion_id, int *ret_lock_count)
  5732. +{
  5733. + int ret;
  5734. + FusionSkirmish *skirmish;
  5735. +
  5736. + ret = fusion_skirmish_lock( &dev->skirmish, id, false, &skirmish );
  5737. + if (ret)
  5738. + return ret;
  5739. +
  5740. + if (skirmish->lock_fid == fusion_id &&
  5741. + skirmish->lock_pid == current->pid)
  5742. + {
  5743. + *ret_lock_count = skirmish->lock_count;
  5744. + }
  5745. + else
  5746. + {
  5747. + *ret_lock_count = 0;
  5748. + }
  5749. +
  5750. + fusion_skirmish_unlock( skirmish );
  5751. +
  5752. + return 0;
  5753. +}
  5754. +
  5755. +int
  5756. +fusion_skirmish_dismiss (FusionDev *dev, int id, int fusion_id)
  5757. +{
  5758. + int ret;
  5759. + FusionSkirmish *skirmish;
  5760. +
  5761. + ret = fusion_skirmish_lock( &dev->skirmish, id, false, &skirmish );
  5762. + if (ret)
  5763. + return ret;
  5764. +
  5765. + dev->stat.skirmish_dismiss++;
  5766. +
  5767. + if (skirmish->lock_pid != current->pid) {
  5768. + fusion_skirmish_unlock( skirmish );
  5769. + return -EIO;
  5770. + }
  5771. +
  5772. + if (--skirmish->lock_count == 0) {
  5773. + skirmish->lock_fid = 0;
  5774. + skirmish->lock_pid = 0;
  5775. +
  5776. + fusion_skirmish_notify( skirmish, true );
  5777. + }
  5778. +
  5779. + fusion_skirmish_unlock( skirmish );
  5780. +
  5781. + return 0;
  5782. +}
  5783. +
  5784. +int
  5785. +fusion_skirmish_destroy (FusionDev *dev, int id)
  5786. +{
  5787. +#ifdef FUSION_DEBUG_SKIRMISH_DEADLOCK
  5788. + int i;
  5789. + FusionSkirmish *s;
  5790. +
  5791. + /* Lock entries. */
  5792. + if (down_interruptible( &dev->skirmish.lock ))
  5793. + return -EINTR;
  5794. +
  5795. + /* remove from all pre-acquisition lists */
  5796. + fusion_list_foreach (s, dev->skirmish.list) {
  5797. + for (i=0; i<MAX_PRE_ACQUISITIONS; i++) {
  5798. + if (s->pre_acquis[i] == id + 1)
  5799. + s->pre_acquis[i] = 0;
  5800. + }
  5801. + }
  5802. +
  5803. + up( &dev->skirmish.lock );
  5804. +
  5805. + /* FIXME: gap? */
  5806. +#endif
  5807. +
  5808. + return fusion_entry_destroy( &dev->skirmish, id );
  5809. +}
  5810. +
  5811. +void
  5812. +fusion_skirmish_dismiss_all (FusionDev *dev, int fusion_id)
  5813. +{
  5814. + FusionLink *l;
  5815. +
  5816. + down (&dev->skirmish.lock);
  5817. +
  5818. + fusion_list_foreach (l, dev->skirmish.list) {
  5819. + FusionSkirmish *skirmish = (FusionSkirmish *) l;
  5820. +
  5821. + down (&skirmish->entry.lock);
  5822. +
  5823. + if (skirmish->lock_fid == fusion_id) {
  5824. + skirmish->lock_fid = 0;
  5825. + skirmish->lock_pid = 0;
  5826. + skirmish->lock_count = 0;
  5827. +
  5828. + wake_up_interruptible_all (&skirmish->entry.wait);
  5829. + }
  5830. +
  5831. + up (&skirmish->entry.lock);
  5832. + }
  5833. +
  5834. + up (&dev->skirmish.lock);
  5835. +}
  5836. +
  5837. +void
  5838. +fusion_skirmish_dismiss_all_from_pid (FusionDev *dev, int pid)
  5839. +{
  5840. + FusionLink *l;
  5841. +
  5842. + down (&dev->skirmish.lock);
  5843. +
  5844. + fusion_list_foreach (l, dev->skirmish.list) {
  5845. + FusionSkirmish *skirmish = (FusionSkirmish *) l;
  5846. +
  5847. + down (&skirmish->entry.lock);
  5848. +
  5849. + if (skirmish->lock_pid == pid) {
  5850. + skirmish->lock_fid = 0;
  5851. + skirmish->lock_pid = 0;
  5852. + skirmish->lock_count = 0;
  5853. +
  5854. + wake_up_interruptible_all (&skirmish->entry.wait);
  5855. + }
  5856. +
  5857. + up (&skirmish->entry.lock);
  5858. + }
  5859. +
  5860. + up (&dev->skirmish.lock);
  5861. +}
  5862. +
  5863. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/skirmish.h linux-2.6.22.1/drivers/char/fusion/skirmish.h
  5864. --- linux-2.6.22.1-0rig/drivers/char/fusion/skirmish.h 1970-01-01 01:00:00.000000000 +0100
  5865. +++ linux-2.6.22.1/drivers/char/fusion/skirmish.h 2006-06-30 10:54:55.000000000 +0200
  5866. @@ -0,0 +1,62 @@
  5867. +/*
  5868. + * Fusion Kernel Module
  5869. + *
  5870. + * (c) Copyright 2002-2003 Convergence GmbH
  5871. + *
  5872. + * Written by Denis Oliver Kropp <dok@directfb.org>
  5873. + *
  5874. + *
  5875. + * This program is free software; you can redistribute it and/or
  5876. + * modify it under the terms of the GNU General Public License
  5877. + * as published by the Free Software Foundation; either version
  5878. + * 2 of the License, or (at your option) any later version.
  5879. + */
  5880. +
  5881. +#ifndef __FUSION__SKIRMISH_H__
  5882. +#define __FUSION__SKIRMISH_H__
  5883. +
  5884. +#include "fusiondev.h"
  5885. +#include "types.h"
  5886. +
  5887. +
  5888. +/* module init/cleanup */
  5889. +
  5890. +int fusion_skirmish_init (FusionDev *dev);
  5891. +void fusion_skirmish_deinit (FusionDev *dev);
  5892. +
  5893. +
  5894. +/* public API */
  5895. +
  5896. +int fusion_skirmish_new (FusionDev *dev,
  5897. + int *id);
  5898. +
  5899. +int fusion_skirmish_prevail (FusionDev *dev,
  5900. + int id,
  5901. + int fusion_id);
  5902. +
  5903. +int fusion_skirmish_swoop (FusionDev *dev,
  5904. + int id,
  5905. + int fusion_id);
  5906. +
  5907. +int fusion_skirmish_lock_count (FusionDev *dev,
  5908. + int id,
  5909. + int fusion_id,
  5910. + int *ret_lock_count);
  5911. +
  5912. +int fusion_skirmish_dismiss (FusionDev *dev,
  5913. + int id,
  5914. + int fusion_id);
  5915. +
  5916. +int fusion_skirmish_destroy (FusionDev *dev,
  5917. + int id);
  5918. +
  5919. +
  5920. +/* internal functions */
  5921. +
  5922. +void fusion_skirmish_dismiss_all (FusionDev *dev,
  5923. + int fusion_id);
  5924. +
  5925. +void fusion_skirmish_dismiss_all_from_pid (FusionDev *dev,
  5926. + int pid);
  5927. +
  5928. +#endif
  5929. diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/types.h linux-2.6.22.1/drivers/char/fusion/types.h
  5930. --- linux-2.6.22.1-0rig/drivers/char/fusion/types.h 1970-01-01 01:00:00.000000000 +0100
  5931. +++ linux-2.6.22.1/drivers/char/fusion/types.h 2007-01-20 05:03:01.000000000 +0100
  5932. @@ -0,0 +1,29 @@
  5933. +/*
  5934. + * Fusion Kernel Module
  5935. + *
  5936. + * (c) Copyright 2002 Convergence GmbH
  5937. + *
  5938. + * Written by Denis Oliver Kropp <dok@directfb.org>
  5939. + *
  5940. + *
  5941. + * This program is free software; you can redistribute it and/or
  5942. + * modify it under the terms of the GNU General Public License
  5943. + * as published by the Free Software Foundation; either version
  5944. + * 2 of the License, or (at your option) any later version.
  5945. + */
  5946. +
  5947. +#ifndef __FUSION__TYPES_H__
  5948. +#define __FUSION__TYPES_H__
  5949. +
  5950. +#include <linux/version.h>
  5951. +
  5952. +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 18)
  5953. +typedef enum {
  5954. + false = 0,
  5955. + true = !false
  5956. +} bool;
  5957. +#endif
  5958. +
  5959. +typedef struct __Fusion_Fusionee Fusionee;
  5960. +
  5961. +#endif
  5962. diff -urN linux-2.6.22.1-0rig/drivers/char/Kconfig linux-2.6.22.1/drivers/char/Kconfig
  5963. --- linux-2.6.22.1-0rig/drivers/char/Kconfig 2007-07-10 20:56:30.000000000 +0200
  5964. +++ linux-2.6.22.1/drivers/char/Kconfig 2007-08-12 19:30:42.000000000 +0200
  5965. @@ -484,6 +484,8 @@
  5966. All modern Linux systems use the Unix98 ptys. Say Y unless
  5967. you're on an embedded system and want to conserve memory.
  5968. +source "drivers/char/fusion/Kconfig"
  5969. +
  5970. config LEGACY_PTYS
  5971. bool "Legacy (BSD) PTY support"
  5972. default y
  5973. diff -urN linux-2.6.22.1-0rig/drivers/char/Makefile linux-2.6.22.1/drivers/char/Makefile
  5974. --- linux-2.6.22.1-0rig/drivers/char/Makefile 2007-07-10 20:56:30.000000000 +0200
  5975. +++ linux-2.6.22.1/drivers/char/Makefile 2007-08-12 19:45:20.000000000 +0200
  5976. @@ -100,6 +100,7 @@
  5977. obj-$(CONFIG_DRM) += drm/
  5978. obj-$(CONFIG_PCMCIA) += pcmcia/
  5979. obj-$(CONFIG_IPMI_HANDLER) += ipmi/
  5980. +obj-$(CONFIG_FUSION_DEVICE) += fusion/
  5981. obj-$(CONFIG_HANGCHECK_TIMER) += hangcheck-timer.o
  5982. obj-$(CONFIG_TCG_TPM) += tpm/
  5983. diff -urN linux-2.6.22.1-0rig/include/linux/fusion.h linux-2.6.22.1/include/linux/fusion.h
  5984. --- linux-2.6.22.1-0rig/include/linux/fusion.h 1970-01-01 01:00:00.000000000 +0100
  5985. +++ linux-2.6.22.1/include/linux/fusion.h 2007-01-29 01:43:50.000000000 +0100
  5986. @@ -0,0 +1,277 @@
  5987. +#ifndef __LINUX__FUSION_H__
  5988. +#define __LINUX__FUSION_H__
  5989. +
  5990. +#include <asm/ioctl.h>
  5991. +
  5992. +/*
  5993. + * Fusion Kernel Device API Version
  5994. + */
  5995. +#define FUSION_API_MAJOR 3 /* Increased if backward compatibility is dropped. */
  5996. +#define FUSION_API_MINOR 2 /* Increased if new features are added. */
  5997. +
  5998. +/*
  5999. + * The Fusion ID is a unique identifier for one process consisting of threads.
  6000. + */
  6001. +typedef unsigned long FusionID;
  6002. +
  6003. +#define FUSION_ID_MASTER 1 /* This is the fusion id of the master (first process). */
  6004. +
  6005. +/*
  6006. + * Entering a world
  6007. + */
  6008. +typedef struct {
  6009. + struct {
  6010. + int major; /* Must be set to FUSION_API_MAJOR before entering. */
  6011. + int minor; /* Must be set to FUSION_API_MINOR before entering. */
  6012. + } api;
  6013. +
  6014. + FusionID fusion_id; /* Returns the fusion id of the entering process. */
  6015. +} FusionEnter;
  6016. +
  6017. +/*
  6018. + * Forking in world
  6019. + */
  6020. +typedef struct {
  6021. + FusionID fusion_id; /* Returns the fusion id of the new (forked) fusionee. */
  6022. +} FusionFork;
  6023. +
  6024. +/*
  6025. + * Sending a message
  6026. + */
  6027. +typedef struct {
  6028. + FusionID fusion_id; /* recipient */
  6029. +
  6030. + int msg_id; /* optional message identifier */
  6031. + int msg_size; /* message size, must be greater than zero */
  6032. + const void *msg_data; /* message data, must not be NULL */
  6033. +} FusionSendMessage;
  6034. +
  6035. +/*
  6036. + * Receiving a message
  6037. + */
  6038. +typedef enum {
  6039. + FMT_SEND, /* msg_id is an optional custom id */
  6040. + FMT_CALL, /* msg_id is the call id */
  6041. + FMT_REACTOR, /* msg_id is the reactor id */
  6042. + FMT_SHMPOOL /* msg_id is the pool id */
  6043. +} FusionMessageType;
  6044. +
  6045. +typedef struct {
  6046. + FusionMessageType msg_type; /* type (origin) of message */
  6047. +
  6048. + int msg_id; /* message id (custom id or call/reactor/pool id) */
  6049. + int msg_size; /* size of the following message data */
  6050. +
  6051. + /* message data follows */
  6052. +} FusionReadMessage;
  6053. +
  6054. +/*
  6055. + * Dispatching a message via a reactor
  6056. + */
  6057. +typedef struct {
  6058. + int reactor_id;
  6059. + int self;
  6060. +
  6061. + int msg_size; /* message size, must be greater than zero */
  6062. + const void *msg_data; /* message data, must not be NULL */
  6063. +} FusionReactorDispatch;
  6064. +
  6065. +/*
  6066. + * Calling (synchronous RPC)
  6067. + */
  6068. +typedef struct {
  6069. + int call_id; /* new call id returned */
  6070. +
  6071. + void *handler; /* function pointer of handler to install */
  6072. + void *ctx; /* optional handler context */
  6073. +} FusionCallNew;
  6074. +
  6075. +typedef enum {
  6076. + FCEF_NONE = 0x00000000,
  6077. + FCEF_ONEWAY = 0x00000001,
  6078. + FCEF_ALL = 0x00000001
  6079. +} FusionCallExecFlags;
  6080. +
  6081. +typedef struct {
  6082. + int ret_val; /* return value of the call */
  6083. +
  6084. + int call_id; /* id of the requested call, each call has a fixed owner */
  6085. +
  6086. + int call_arg; /* optional int argument */
  6087. + void *call_ptr; /* optional pointer argument (shared memory) */
  6088. +
  6089. + FusionCallExecFlags flags; /* execution flags */
  6090. +} FusionCallExecute;
  6091. +
  6092. +typedef struct {
  6093. + int call_id; /* id of currently executing call */
  6094. +
  6095. + int val; /* value to return */
  6096. +} FusionCallReturn;
  6097. +
  6098. +typedef struct {
  6099. + void *handler; /* function pointer of handler to call */
  6100. + void *ctx; /* optional handler context */
  6101. +
  6102. + int caller; /* fusion id of the caller or zero if called from Fusion */
  6103. + int call_arg; /* optional call parameter */
  6104. + void *call_ptr; /* optional call parameter */
  6105. +} FusionCallMessage;
  6106. +
  6107. +/*
  6108. + * Watching a reference
  6109. + *
  6110. + * This information is needed to have a specific call being executed if the
  6111. + * reference count reaches zero. Currently one watch per reference is allowed.
  6112. + *
  6113. + * The call is made by Fusion and therefor has a caller id of zero.
  6114. + *
  6115. + */
  6116. +typedef struct {
  6117. + int id; /* id of the reference to watch */
  6118. +
  6119. + int call_id; /* id of the call to execute */
  6120. + int call_arg; /* optional call parameter, e.g. the id of a user
  6121. + space resource associated with that reference */
  6122. +} FusionRefWatch;
  6123. +
  6124. +/*
  6125. + * Inheriting local count from other reference
  6126. + */
  6127. +typedef struct {
  6128. + int id; /* own reference id */
  6129. + int from; /* id of the reference to inherit from */
  6130. +} FusionRefInherit;
  6131. +
  6132. +/*
  6133. + * Killing other fusionees (experimental)
  6134. + */
  6135. +typedef struct {
  6136. + FusionID fusion_id; /* fusionee to kill, zero means all but ourself */
  6137. + int signal; /* signal to be delivered, e.g. SIGTERM */
  6138. + int timeout_ms; /* -1 means no timeout, 0 means infinite, otherwise the
  6139. + max. time to wait until the fusionee(s) terminated */
  6140. +} FusionKill;
  6141. +
  6142. +
  6143. +/*
  6144. + * Shared memory pools
  6145. + */
  6146. +typedef struct {
  6147. + int max_size; /* Maximum size that this pool will be allowed to grow to. */
  6148. +
  6149. + int pool_id; /* Returns the new pool id. */
  6150. + void *addr_base; /* Returns the base of the reserved virtual memory address space. */
  6151. +} FusionSHMPoolNew;
  6152. +
  6153. +typedef struct {
  6154. + int pool_id; /* The id of the pool to attach to. */
  6155. +
  6156. + void *addr_base; /* Returns the base of the reserved virtual memory address space. */
  6157. + int size; /* Returns the current size of the pool. */
  6158. +} FusionSHMPoolAttach;
  6159. +
  6160. +typedef struct {
  6161. + int pool_id; /* The id of the pool to notify. */
  6162. +
  6163. + int size; /* New size of the pool. */
  6164. +} FusionSHMPoolDispatch;
  6165. +
  6166. +typedef enum {
  6167. + FSMT_REMAP, /* Remap the pool due to a change of its size. */
  6168. + FSMT_UNMAP /* Unmap the pool due to its destruction. */
  6169. +} FusionSHMPoolMessageType;
  6170. +
  6171. +typedef struct {
  6172. + FusionSHMPoolMessageType type; /* Type of the message. */
  6173. +
  6174. + int size; /* New size of the pool, if type is FSMT_REMAP. */
  6175. +} FusionSHMPoolMessage;
  6176. +
  6177. +
  6178. +/*
  6179. + * Fusion types
  6180. + */
  6181. +typedef enum {
  6182. + FT_LOUNGE,
  6183. + FT_MESSAGING,
  6184. + FT_CALL,
  6185. + FT_REF,
  6186. + FT_SKIRMISH,
  6187. + FT_PROPERTY,
  6188. + FT_REACTOR,
  6189. + FT_SHMPOOL
  6190. +} FusionType;
  6191. +
  6192. +
  6193. +/*
  6194. + * Set attributes like 'name' for an entry of the specified type.
  6195. + */
  6196. +#define FUSION_ENTRY_INFO_NAME_LENGTH 24
  6197. +
  6198. +typedef struct {
  6199. + FusionType type;
  6200. + int id;
  6201. +
  6202. + char name[FUSION_ENTRY_INFO_NAME_LENGTH];
  6203. +} FusionEntryInfo;
  6204. +
  6205. +
  6206. +
  6207. +#define FUSION_ENTER _IOR(FT_LOUNGE, 0x00, FusionEnter)
  6208. +#define FUSION_UNBLOCK _IO (FT_LOUNGE, 0x01)
  6209. +#define FUSION_KILL _IOW(FT_LOUNGE, 0x02, FusionKill)
  6210. +
  6211. +#define FUSION_ENTRY_SET_INFO _IOW(FT_LOUNGE, 0x03, FusionEntryInfo)
  6212. +#define FUSION_ENTRY_GET_INFO _IOW(FT_LOUNGE, 0x04, FusionEntryInfo)
  6213. +
  6214. +#define FUSION_FORK _IOW(FT_LOUNGE, 0x05, FusionFork)
  6215. +
  6216. +#define FUSION_SEND_MESSAGE _IOW(FT_MESSAGING, 0x00, FusionSendMessage)
  6217. +
  6218. +#define FUSION_CALL_NEW _IOW(FT_CALL, 0x00, FusionCallNew)
  6219. +#define FUSION_CALL_EXECUTE _IOW(FT_CALL, 0x01, FusionCallExecute)
  6220. +#define FUSION_CALL_RETURN _IOW(FT_CALL, 0x02, FusionCallReturn)
  6221. +#define FUSION_CALL_DESTROY _IOW(FT_CALL, 0x03, int)
  6222. +
  6223. +#define FUSION_REF_NEW _IOW(FT_REF, 0x00, int)
  6224. +#define FUSION_REF_UP _IOW(FT_REF, 0x01, int)
  6225. +#define FUSION_REF_UP_GLOBAL _IOW(FT_REF, 0x02, int)
  6226. +#define FUSION_REF_DOWN _IOW(FT_REF, 0x03, int)
  6227. +#define FUSION_REF_DOWN_GLOBAL _IOW(FT_REF, 0x04, int)
  6228. +#define FUSION_REF_ZERO_LOCK _IOW(FT_REF, 0x05, int)
  6229. +#define FUSION_REF_ZERO_TRYLOCK _IOW(FT_REF, 0x06, int)
  6230. +#define FUSION_REF_UNLOCK _IOW(FT_REF, 0x07, int)
  6231. +#define FUSION_REF_STAT _IOW(FT_REF, 0x08, int)
  6232. +#define FUSION_REF_WATCH _IOW(FT_REF, 0x09, FusionRefWatch)
  6233. +#define FUSION_REF_INHERIT _IOW(FT_REF, 0x0A, FusionRefInherit)
  6234. +#define FUSION_REF_DESTROY _IOW(FT_REF, 0x0B, int)
  6235. +
  6236. +#define FUSION_SKIRMISH_NEW _IOW(FT_SKIRMISH, 0x00, int)
  6237. +#define FUSION_SKIRMISH_PREVAIL _IOW(FT_SKIRMISH, 0x01, int)
  6238. +#define FUSION_SKIRMISH_SWOOP _IOW(FT_SKIRMISH, 0x02, int)
  6239. +#define FUSION_SKIRMISH_DISMISS _IOW(FT_SKIRMISH, 0x03, int)
  6240. +#define FUSION_SKIRMISH_DESTROY _IOW(FT_SKIRMISH, 0x04, int)
  6241. +#define FUSION_SKIRMISH_LOCK_COUNT _IOW(FT_SKIRMISH, 0x05, int)
  6242. +
  6243. +#define FUSION_PROPERTY_NEW _IOW(FT_PROPERTY, 0x00, int)
  6244. +#define FUSION_PROPERTY_LEASE _IOW(FT_PROPERTY, 0x01, int)
  6245. +#define FUSION_PROPERTY_PURCHASE _IOW(FT_PROPERTY, 0x02, int)
  6246. +#define FUSION_PROPERTY_CEDE _IOW(FT_PROPERTY, 0x03, int)
  6247. +#define FUSION_PROPERTY_HOLDUP _IOW(FT_PROPERTY, 0x04, int)
  6248. +#define FUSION_PROPERTY_DESTROY _IOW(FT_PROPERTY, 0x05, int)
  6249. +
  6250. +#define FUSION_REACTOR_NEW _IOW(FT_REACTOR, 0x00, int)
  6251. +#define FUSION_REACTOR_ATTACH _IOW(FT_REACTOR, 0x01, int)
  6252. +#define FUSION_REACTOR_DETACH _IOW(FT_REACTOR, 0x02, int)
  6253. +#define FUSION_REACTOR_DISPATCH _IOW(FT_REACTOR, 0x03, FusionReactorDispatch)
  6254. +#define FUSION_REACTOR_DESTROY _IOW(FT_REACTOR, 0x04, int)
  6255. +
  6256. +#define FUSION_SHMPOOL_NEW _IOW(FT_SHMPOOL, 0x00, FusionSHMPoolNew)
  6257. +#define FUSION_SHMPOOL_ATTACH _IOW(FT_SHMPOOL, 0x01, FusionSHMPoolAttach)
  6258. +#define FUSION_SHMPOOL_DETACH _IOW(FT_SHMPOOL, 0x02, int)
  6259. +#define FUSION_SHMPOOL_DISPATCH _IOW(FT_SHMPOOL, 0x03, FusionSHMPoolDispatch)
  6260. +#define FUSION_SHMPOOL_DESTROY _IOW(FT_SHMPOOL, 0x04, int)
  6261. +
  6262. +#endif
  6263. +