1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265 |
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/call.c linux-2.6.22.1/drivers/char/fusion/call.c
- --- linux-2.6.22.1-0rig/drivers/char/fusion/call.c 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/call.c 2007-01-20 05:03:01.000000000 +0100
- @@ -0,0 +1,478 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifdef HAVE_LINUX_CONFIG_H
- +#include <linux/config.h>
- +#endif
- +#include <linux/types.h>
- +#include <linux/kernel.h>
- +#include <linux/slab.h>
- +#include <linux/smp_lock.h>
- +#include <linux/sched.h>
- +
- +#include <linux/fusion.h>
- +
- +#include "fusiondev.h"
- +#include "fusionee.h"
- +#include "list.h"
- +#include "call.h"
- +
- +typedef struct {
- + FusionLink link;
- +
- + Fusionee *caller;
- +
- + int ret_val;
- +
- + bool executed;
- +
- + wait_queue_head_t wait;
- +} FusionCallExecution;
- +
- +typedef struct {
- + FusionLink link;
- +
- + struct semaphore lock;
- +
- + int id; /* call id */
- +
- + int pid; /* owner pid */
- + int fusion_id; /* owner fusion id */
- +
- + void *handler;
- + void *ctx;
- +
- + FusionLink *executions; /* prepending! */
- + FusionLink *last; /* points to the last item of executions */
- +
- + int count; /* number of calls ever made */
- +} FusionCall;
- +
- +/******************************************************************************/
- +
- +static int lookup_call (FusionDev *dev, int id, FusionCall **ret_call);
- +static int lock_call (FusionDev *dev, int id, FusionCall **ret_call);
- +static void unlock_call (FusionCall *call);
- +
- +static FusionCallExecution *add_execution (FusionCall *call,
- + Fusionee *caller,
- + FusionCallExecute *execute);
- +static void remove_execution (FusionCall *call,
- + FusionCallExecution *execution);
- +static void free_all_executions (FusionCall *call);
- +
- +/******************************************************************************/
- +
- +static int
- +fusion_call_read_proc (char *buf, char **start, off_t offset,
- + int len, int *eof, void *private)
- +{
- + FusionLink *l, *e;
- + FusionDev *dev = private;
- + int written = 0;
- +
- + if (down_interruptible (&dev->call.lock))
- + return -EINTR;
- +
- + fusion_list_foreach (l, dev->call.list) {
- + bool idle = true;
- + FusionCall *call = (FusionCall*) l;
- +
- + if (call->executions)
- + idle = ((FusionCallExecution*) call->executions)->executed;
- +
- + written += sprintf(buf+written,
- + "(%5d) 0x%08x (%d calls) %s",
- + call->pid, call->id, call->count,
- + idle ? "idle" : "executing");
- +
- + fusion_list_foreach (e, call->executions) {
- + FusionCallExecution *exec = (FusionCallExecution *) e;
- +
- + written += sprintf(buf+written, " [0x%08lx]", exec->caller ? fusionee_id( exec->caller ) : 0);
- + }
- +
- + written += sprintf(buf+written, "\n");
- +
- + if (written < offset) {
- + offset -= written;
- + written = 0;
- + }
- +
- + if (written >= len)
- + break;
- + }
- +
- + up (&dev->call.lock);
- +
- + *start = buf + offset;
- + written -= offset;
- + if (written > len) {
- + *eof = 0;
- + return len;
- + }
- +
- + *eof = 1;
- + return(written<0) ? 0 : written;
- +}
- +
- +int
- +fusion_call_init (FusionDev *dev)
- +{
- + create_proc_read_entry("calls", 0, dev->proc_dir,
- + fusion_call_read_proc, dev);
- +
- + init_MUTEX(&dev->call.lock);
- +
- + return 0;
- +}
- +
- +void
- +fusion_call_deinit (FusionDev *dev)
- +{
- + FusionLink *l;
- +
- + down (&dev->call.lock);
- +
- + remove_proc_entry ("calls", dev->proc_dir);
- +
- + l = dev->call.list;
- + while (l) {
- + FusionLink *next = l->next;
- + FusionCall *call = (FusionCall *) l;
- +
- + free_all_executions (call);
- +
- + kfree (call);
- +
- + l = next;
- + }
- +
- + up (&dev->call.lock);
- +}
- +
- +/******************************************************************************/
- +
- +int
- +fusion_call_new (FusionDev *dev, int fusion_id, FusionCallNew *call_new)
- +{
- + FusionCall *call;
- +
- + call = kmalloc (sizeof(FusionCall), GFP_KERNEL);
- + if (!call)
- + return -ENOMEM;
- +
- + memset (call, 0, sizeof(FusionCall));
- +
- + if (down_interruptible (&dev->call.lock)) {
- + kfree (call);
- + return -EINTR;
- + }
- +
- + call->id = dev->call.ids++;
- + call->pid = current->pid;
- + call->fusion_id = fusion_id;
- + call->handler = call_new->handler;
- + call->ctx = call_new->ctx;
- +
- + init_MUTEX (&call->lock);
- +
- + fusion_list_prepend (&dev->call.list, &call->link);
- +
- + up (&dev->call.lock);
- +
- + call_new->call_id = call->id;
- +
- + return 0;
- +}
- +
- +int
- +fusion_call_execute (FusionDev *dev, Fusionee *fusionee, FusionCallExecute *execute)
- +{
- + int ret;
- + FusionCall *call;
- + FusionCallExecution *execution;
- + FusionCallMessage message;
- +
- + ret = lock_call (dev, execute->call_id, &call);
- + if (ret)
- + return ret;
- +
- + execution = add_execution (call, fusionee, execute);
- + if (!execution) {
- + unlock_call (call);
- + return -ENOMEM;
- + }
- +
- + /* Send call message. */
- + message.handler = call->handler;
- + message.ctx = call->ctx;
- +
- + message.caller = fusionee ? fusionee_id( fusionee ) : 0;
- +
- + message.call_arg = execute->call_arg;
- + message.call_ptr = execute->call_ptr;
- +
- + ret = fusionee_send_message (dev, fusionee, call->fusion_id, FMT_CALL,
- + call->id, sizeof(message), &message);
- + if (ret) {
- + remove_execution (call, execution);
- + kfree (execution);
- + unlock_call (call);
- + return ret;
- + }
- +
- + call->count++;
- +
- + if (fusionee && !(execute->flags & FCEF_ONEWAY)) {
- + /* TODO: implement timeout */
- + fusion_sleep_on (&execution->wait, &call->lock, 0);
- +
- + ret = lock_call (dev, execute->call_id, &call);
- + if (ret)
- + return ret == -EINVAL ? -EIDRM : ret;
- +
- + if (signal_pending(current)) {
- + execution->caller = 0;
- + unlock_call (call);
- + return -EINTR;
- + }
- +
- + execute->ret_val = execution->ret_val;
- +
- + remove_execution (call, execution);
- +
- + kfree (execution);
- + }
- +
- + unlock_call (call);
- +
- + return 0;
- +}
- +
- +int
- +fusion_call_return (FusionDev *dev, int fusion_id, FusionCallReturn *call_ret)
- +{
- + int ret;
- + FusionLink *l;
- + FusionCall *call;
- +
- + ret = lock_call (dev, call_ret->call_id, &call);
- + if (ret)
- + return ret;
- +
- + l = call->last;
- + while (l) {
- + FusionCallExecution *execution = (FusionCallExecution*) l;
- +
- + if (execution->executed) {
- + l = l->prev;
- + continue;
- + }
- +
- + if (execution->caller) {
- + execution->ret_val = call_ret->val;
- + execution->executed = true;
- +
- + wake_up_interruptible_all (&execution->wait);
- + }
- + else {
- + remove_execution (call, execution);
- +
- + kfree (execution);
- + }
- +
- + unlock_call (call);
- +
- + return 0;
- + }
- +
- + unlock_call (call);
- +
- + return -EIO;
- +}
- +
- +int
- +fusion_call_destroy (FusionDev *dev, int fusion_id, int call_id)
- +{
- + int ret;
- + FusionCall *call;
- +
- + ret = lookup_call (dev, call_id, &call);
- + if (ret)
- + return ret;
- +
- + if (call->fusion_id != fusion_id) {
- + up (&dev->call.lock);
- + return -EIO;
- + }
- +
- + if (down_interruptible (&call->lock)) {
- + up (&dev->call.lock);
- + return -EINTR;
- + }
- +
- + fusion_list_remove (&dev->call.list, &call->link);
- +
- + free_all_executions (call);
- +
- + up (&dev->call.lock);
- +
- + up (&call->lock);
- +
- + kfree (call);
- +
- + return 0;
- +}
- +
- +void
- +fusion_call_destroy_all (FusionDev *dev, int fusion_id)
- +{
- + FusionLink *l;
- +
- + down (&dev->call.lock);
- +
- + l = dev->call.list;
- +
- + while (l) {
- + FusionLink *next = l->next;
- + FusionCall *call = (FusionCall *) l;
- +
- + down (&call->lock);
- +
- + if (call->fusion_id == fusion_id) {
- + free_all_executions (call);
- +
- + fusion_list_remove (&dev->call.list, &call->link);
- +
- + up (&call->lock);
- +
- + kfree (call);
- + }
- + else
- + up (&call->lock);
- +
- + l = next;
- + }
- +
- + up (&dev->call.lock);
- +}
- +
- +/******************************************************************************/
- +
- +static int
- +lookup_call (FusionDev *dev, int id, FusionCall **ret_call)
- +{
- + FusionLink *l;
- +
- + if (down_interruptible (&dev->call.lock))
- + return -EINTR;
- +
- + fusion_list_foreach (l, dev->call.list) {
- + FusionCall *call = (FusionCall *) l;
- +
- + if (call->id == id) {
- + *ret_call = call;
- + return 0;
- + }
- + }
- +
- + up (&dev->call.lock);
- +
- + return -EINVAL;
- +}
- +
- +static int
- +lock_call (FusionDev *dev, int id, FusionCall **ret_call)
- +{
- + int ret;
- + FusionCall *call;
- +
- + ret = lookup_call (dev, id, &call);
- + if (ret)
- + return ret;
- +
- + if (call) {
- + fusion_list_move_to_front (&dev->call.list, &call->link);
- +
- + if (down_interruptible (&call->lock)) {
- + up (&dev->call.lock);
- + return -EINTR;
- + }
- +
- + up (&dev->call.lock);
- + }
- +
- + *ret_call = call;
- +
- + return 0;
- +}
- +
- +static void
- +unlock_call (FusionCall *call)
- +{
- + up (&call->lock);
- +}
- +
- +static FusionCallExecution *
- +add_execution (FusionCall *call,
- + Fusionee *caller,
- + FusionCallExecute *execute)
- +{
- + FusionCallExecution *execution;
- +
- + /* Allocate execution. */
- + execution = kmalloc (sizeof(FusionCallExecution), GFP_KERNEL);
- + if (!execution)
- + return NULL;
- +
- + /* Initialize execution. */
- + memset (execution, 0, sizeof(FusionCallExecution));
- +
- + execution->caller = caller;
- +
- + init_waitqueue_head (&execution->wait);
- +
- + /* Add execution. */
- + fusion_list_prepend (&call->executions, &execution->link);
- +
- + if (!call->last)
- + call->last = &execution->link;
- +
- + return execution;
- +}
- +
- +static void
- +remove_execution (FusionCall *call,
- + FusionCallExecution *execution)
- +{
- + if (call->last == &execution->link)
- + call->last = execution->link.prev;
- +
- + fusion_list_remove (&call->executions, &execution->link);
- +}
- +
- +static void
- +free_all_executions (FusionCall *call)
- +{
- + while (call->last) {
- + FusionCallExecution *execution = (FusionCallExecution *) call->last;
- +
- + remove_execution (call, execution);
- +
- + wake_up_interruptible_all (&execution->wait);
- +
- + kfree (execution);
- + }
- +}
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/call.h linux-2.6.22.1/drivers/char/fusion/call.h
- --- linux-2.6.22.1-0rig/drivers/char/fusion/call.h 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/call.h 2007-01-20 05:03:01.000000000 +0100
- @@ -0,0 +1,52 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifndef __FUSION__CALL_H__
- +#define __FUSION__CALL_H__
- +
- +#include <linux/fusion.h>
- +
- +#include "fusiondev.h"
- +
- +/* module init/cleanup */
- +
- +int fusion_call_init (FusionDev *dev);
- +void fusion_call_deinit (FusionDev *dev);
- +
- +
- +/* public API */
- +
- +int fusion_call_new (FusionDev *dev,
- + int fusion_id,
- + FusionCallNew *call);
- +
- +int fusion_call_execute (FusionDev *dev,
- + Fusionee *fusionee, /* NULL if call is from kernel */
- + FusionCallExecute *execute);
- +
- +int fusion_call_return (FusionDev *dev,
- + int fusion_id,
- + FusionCallReturn *call_ret);
- +
- +int fusion_call_destroy (FusionDev *dev,
- + int fusion_id,
- + int call_id);
- +
- +
- +/* internal functions */
- +
- +void fusion_call_destroy_all (FusionDev *dev,
- + int fusion_id);
- +
- +#endif
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/.cvsignore linux-2.6.22.1/drivers/char/fusion/.cvsignore
- --- linux-2.6.22.1-0rig/drivers/char/fusion/.cvsignore 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/.cvsignore 2005-10-29 07:11:10.000000000 +0200
- @@ -0,0 +1,6 @@
- +*.o.flags
- +*.cmd
- +Makefile
- +fusion.ko
- +fusion.mod.c
- +.tmp_versions
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/entries.c linux-2.6.22.1/drivers/char/fusion/entries.c
- --- linux-2.6.22.1-0rig/drivers/char/fusion/entries.c 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/entries.c 2007-03-08 14:02:04.000000000 +0100
- @@ -0,0 +1,438 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifdef HAVE_LINUX_CONFIG_H
- +#include <linux/config.h>
- +#endif
- +#include <linux/types.h>
- +#include <linux/kernel.h>
- +#include <linux/slab.h>
- +#include <linux/smp_lock.h>
- +#include <linux/sched.h>
- +#include <linux/time.h>
- +#include <linux/version.h>
- +
- +#include <linux/fusion.h>
- +
- +#include "fusiondev.h"
- +#include "entries.h"
- +
- +
- +void
- +fusion_entries_init( FusionEntries *entries,
- + FusionEntryClass *class,
- + void *ctx )
- +{
- + FUSION_ASSERT( entries != NULL );
- + FUSION_ASSERT( class != NULL );
- + FUSION_ASSERT( class->object_size >= sizeof(FusionEntry) );
- +
- + memset( entries, 0, sizeof(FusionEntries) );
- +
- + entries->class = class;
- + entries->ctx = ctx;
- +
- + init_MUTEX( &entries->lock );
- +}
- +
- +void
- +fusion_entries_deinit( FusionEntries *entries )
- +{
- + FusionLink *tmp;
- + FusionEntry *entry;
- + FusionEntryClass *class;
- +
- + FUSION_ASSERT( entries != NULL );
- + FUSION_ASSERT( entries->class != NULL );
- +
- + class = entries->class;
- +
- + down( &entries->lock );
- +
- + fusion_list_foreach_safe (entry, tmp, entries->list) {
- + if (class->Destroy)
- + class->Destroy( entry, entries->ctx );
- +
- + kfree( entry );
- + }
- +
- + up( &entries->lock );
- +}
- +
- +int
- +fusion_entries_read_proc(char *buf, char **start, off_t offset,
- + int len, int *eof, void *private)
- +{
- + FusionEntry *entry;
- + FusionEntryClass *class;
- + FusionEntries *entries = private;
- + int written = 0;
- + struct timeval now;
- +
- + FUSION_ASSERT( entries != NULL );
- + FUSION_ASSERT( entries->class != NULL );
- +
- + class = entries->class;
- +
- + if (!class->Print)
- + return -ENOTSUPP;
- +
- + if (down_interruptible (&entries->lock))
- + return -EINTR;
- +
- + do_gettimeofday( &now );
- +
- + fusion_list_foreach (entry, entries->list) {
- + if (entry->last_lock.tv_sec) {
- + int diff = ((now.tv_sec - entry->last_lock.tv_sec) * 1000 +
- + (now.tv_usec - entry->last_lock.tv_usec) / 1000);
- +
- + if (diff < 1000) {
- + written += sprintf( buf + written, "%3d ms ", diff );
- + }
- + else if (diff < 1000000) {
- + written += sprintf( buf + written, "%3d.%d s ",
- + diff / 1000, (diff % 1000) / 100 );
- + }
- + else {
- + diff = ( now.tv_sec - entry->last_lock.tv_sec +
- + (now.tv_usec - entry->last_lock.tv_usec) / 1000000);
- +
- + written += sprintf( buf + written, "%3d.%d h ",
- + diff / 3600, (diff % 3600) / 360 );
- + }
- + }
- + else
- + written += sprintf( buf + written, " -.- " );
- +
- +
- + written += sprintf( buf + written, "(%5d) 0x%08x ", entry->pid, entry->id );
- +
- + written += sprintf( buf + written, "%-24s ", entry->name[0] ? entry->name : "" );
- +
- + written += class->Print( entry, entries->ctx, buf + written );
- +
- + if (written < offset) {
- + offset -= written;
- + written = 0;
- + }
- +
- + if (written >= len)
- + break;
- + }
- +
- + up (&entries->lock);
- +
- + *start = buf + offset;
- + written -= offset;
- + if (written > len) {
- + *eof = 0;
- + return len;
- + }
- +
- + *eof = 1;
- +
- + return (written<0) ? 0 : written;
- +}
- +
- +int
- +fusion_entry_create( FusionEntries *entries,
- + int *ret_id,
- + void *create_ctx )
- +{
- + int ret;
- + FusionEntry *entry;
- + FusionEntryClass *class;
- +
- + FUSION_ASSERT( entries != NULL );
- + FUSION_ASSERT( entries->class != NULL );
- + FUSION_ASSERT( ret_id != NULL );
- +
- + class = entries->class;
- +
- + entry = kmalloc( class->object_size, GFP_KERNEL );
- + if (!entry)
- + return -ENOMEM;
- +
- + memset( entry, 0, class->object_size );
- +
- + if (down_interruptible( &entries->lock )) {
- + kfree( entry );
- + return -EINTR;
- + }
- +
- + entry->entries = entries;
- + entry->id = entries->ids++;
- + entry->pid = current->pid;
- +
- + init_MUTEX( &entry->lock );
- +
- + init_waitqueue_head( &entry->wait );
- +
- + if (class->Init) {
- + ret = class->Init( entry, entries->ctx, create_ctx );
- + if (ret) {
- + up( &entries->lock );
- + kfree( entry );
- + return ret;
- + }
- + }
- +
- + fusion_list_prepend( &entries->list, &entry->link );
- +
- + up( &entries->lock );
- +
- + *ret_id = entry->id;
- +
- + return 0;
- +}
- +
- +int
- +fusion_entry_destroy( FusionEntries *entries,
- + int id )
- +{
- + FusionEntry *entry;
- + FusionEntryClass *class;
- +
- + FUSION_ASSERT( entries != NULL );
- + FUSION_ASSERT( entries->class != NULL );
- +
- + class = entries->class;
- +
- + /* Lock entries. */
- + if (down_interruptible( &entries->lock ))
- + return -EINTR;
- +
- + /* Lookup the entry. */
- + fusion_list_foreach (entry, entries->list) {
- + if (entry->id == id)
- + break;
- + }
- +
- + /* Check if no entry was found. */
- + if (!entry) {
- + up( &entries->lock );
- + return -EINVAL;
- + }
- +
- + /* Lock the entry. */
- + if (down_interruptible( &entry->lock )) {
- + up( &entries->lock );
- + return -EINTR;
- + }
- +
- + /* Destroy it now. */
- + fusion_entry_destroy_locked( entries, entry );
- +
- + /* Unlock entries. */
- + up( &entries->lock );
- +
- + return 0;
- +}
- +
- +void
- +fusion_entry_destroy_locked( FusionEntries *entries,
- + FusionEntry *entry )
- +{
- + FusionEntryClass *class;
- +
- + FUSION_ASSERT( entries != NULL );
- + FUSION_ASSERT( entries->class != NULL );
- +
- + class = entries->class;
- +
- + /* Remove the entry from the list. */
- + fusion_list_remove( &entries->list, &entry->link );
- +
- + /* Wake up any waiting process. */
- + wake_up_interruptible_all( &entry->wait );
- +
- + /* Call the destroy function. */
- + if (class->Destroy)
- + class->Destroy( entry, entries->ctx );
- +
- + /* Unlock the entry. */
- + up( &entry->lock );
- +
- + /* Deallocate the entry. */
- + kfree( entry );
- +}
- +
- +int
- +fusion_entry_set_info( FusionEntries *entries,
- + const FusionEntryInfo *info )
- +{
- + int ret;
- + FusionEntry *entry;
- +
- + FUSION_ASSERT( entries != NULL );
- + FUSION_ASSERT( info != NULL );
- +
- + ret = fusion_entry_lock( entries, info->id, false, &entry );
- + if (ret)
- + return ret;
- +
- + snprintf( entry->name, FUSION_ENTRY_INFO_NAME_LENGTH, info->name );
- +
- + fusion_entry_unlock( entry );
- +
- + return 0;
- +}
- +
- +int
- +fusion_entry_get_info( FusionEntries *entries,
- + FusionEntryInfo *info )
- +{
- + int ret;
- + FusionEntry *entry;
- +
- + FUSION_ASSERT( entries != NULL );
- + FUSION_ASSERT( info != NULL );
- +
- + ret = fusion_entry_lock( entries, info->id, false, &entry );
- + if (ret)
- + return ret;
- +
- + snprintf( info->name, FUSION_ENTRY_INFO_NAME_LENGTH, entry->name );
- +
- + fusion_entry_unlock( entry );
- +
- + return 0;
- +}
- +
- +int
- +fusion_entry_lock( FusionEntries *entries,
- + int id,
- + bool keep_entries_lock,
- + FusionEntry **ret_entry )
- +{
- + FusionEntry *entry;
- +
- + FUSION_ASSERT( entries != NULL );
- + FUSION_ASSERT( ret_entry != NULL );
- +
- + /* Lock entries. */
- + if (down_interruptible( &entries->lock ))
- + return -EINTR;
- +
- + /* Lookup the entry. */
- + fusion_list_foreach (entry, entries->list) {
- + if (entry->id == id)
- + break;
- + }
- +
- + /* Check if no entry was found. */
- + if (!entry) {
- + up( &entries->lock );
- + return -EINVAL;
- + }
- +
- + FUSION_ASSUME( entry->lock_pid != current->pid );
- +
- + /* Move the entry to the front of all entries. */
- + fusion_list_move_to_front( &entries->list, &entry->link );
- +
- + /* Lock the entry. */
- + if (down_interruptible( &entry->lock )) {
- + up( &entries->lock );
- + return -EINTR;
- + }
- +
- + /* Mark as locked. */
- + entry->lock_pid = current->pid;
- +
- + /* Keep timestamp, but use the slightly
- + inexact version to avoid performance impacts. */
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0) && defined _STRUCT_TIMESPEC
- + entry->last_lock.tv_sec = xtime.tv_sec;
- + entry->last_lock.tv_usec = xtime.tv_nsec / 1000;
- +#else
- + entry->last_lock = xtime;
- +#endif
- +
- + /* Unlock entries. */
- + if (!keep_entries_lock)
- + up( &entries->lock );
- +
- + /* Return the locked entry. */
- + *ret_entry = entry;
- +
- + return 0;
- +}
- +
- +void
- +fusion_entry_unlock( FusionEntry *entry )
- +{
- + FUSION_ASSERT( entry != NULL );
- + FUSION_ASSUME( entry->lock_pid == current->pid );
- +
- + entry->lock_pid = 0;
- +
- + /* Unlock the entry. */
- + up( &entry->lock );
- +}
- +
- +int
- +fusion_entry_wait( FusionEntry *entry, long *timeout )
- +{
- + int ret;
- + int id;
- + FusionEntries *entries;
- + FusionEntry *entry2;
- +
- + FUSION_ASSERT( entry != NULL );
- + FUSION_ASSERT( entry->entries != NULL );
- + FUSION_ASSUME( entry->lock_pid == current->pid );
- +
- + id = entry->id;
- + entries = entry->entries;
- +
- + entry->waiters++;
- +
- + entry->lock_pid = 0;
- + fusion_sleep_on( &entry->wait, &entry->lock, timeout );
- +
- + entry->waiters--;
- +
- + if (signal_pending(current))
- + return -EINTR;
- +
- + if (timeout && !*timeout)
- + return -ETIMEDOUT;
- +
- + ret = fusion_entry_lock( entries, id, false, &entry2 );
- + switch (ret) {
- + case -EINVAL:
- + return -EIDRM;
- +
- + case 0:
- + if (entry != entry2)
- + BUG();
- + }
- +
- + return ret;
- +}
- +
- +void
- +fusion_entry_notify( FusionEntry *entry, bool all )
- +{
- + FUSION_ASSERT( entry != NULL );
- + FUSION_ASSUME( entry->lock_pid == current->pid );
- +
- + if (all)
- + wake_up_interruptible_all( &entry->wait );
- + else
- + wake_up_interruptible( &entry->wait );
- +}
- +
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/entries.h linux-2.6.22.1/drivers/char/fusion/entries.h
- --- linux-2.6.22.1-0rig/drivers/char/fusion/entries.h 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/entries.h 2006-09-03 13:50:55.000000000 +0200
- @@ -0,0 +1,179 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifndef __FUSION__ENTRIES_H__
- +#define __FUSION__ENTRIES_H__
- +
- +#include "types.h"
- +#include "list.h"
- +
- +
- +typedef struct __FD_FusionEntry FusionEntry;
- +
- +
- +typedef const struct {
- + int object_size;
- +
- + int (*Init) ( FusionEntry *entry, void *ctx, void *create_ctx );
- + void (*Destroy)( FusionEntry *entry, void *ctx );
- + int (*Print) ( FusionEntry *entry, void *ctx, char *buf );
- +} FusionEntryClass;
- +
- +
- +typedef struct {
- + FusionEntryClass *class;
- + void *ctx;
- +
- + FusionLink *list;
- + int ids;
- + struct semaphore lock;
- +} FusionEntries;
- +
- +
- +struct __FD_FusionEntry {
- + FusionLink link;
- +
- + FusionEntries *entries;
- +
- + int id;
- + pid_t pid;
- +
- + pid_t lock_pid;
- +
- + struct semaphore lock;
- + wait_queue_head_t wait;
- + int waiters;
- +
- + struct timeval last_lock;
- +
- + char name[FUSION_ENTRY_INFO_NAME_LENGTH];
- +};
- +
- +
- +/* Entries Init & DeInit */
- +
- +void fusion_entries_init ( FusionEntries *entries,
- + FusionEntryClass *class,
- + void *ctx );
- +
- +void fusion_entries_deinit( FusionEntries *entries );
- +
- +
- +/* '/proc' support */
- +
- +int fusion_entries_read_proc( char *buf, char **start, off_t offset,
- + int len, int *eof, void *private );
- +
- +
- +/* Create & Destroy */
- +
- +int fusion_entry_create ( FusionEntries *entries,
- + int *ret_id,
- + void *create_ctx );
- +
- +int fusion_entry_destroy ( FusionEntries *entries,
- + int id );
- +
- +void fusion_entry_destroy_locked( FusionEntries *entries,
- + FusionEntry *entry );
- +
- +/* Information */
- +
- +int fusion_entry_set_info( FusionEntries *entries,
- + const FusionEntryInfo *info );
- +
- +int fusion_entry_get_info( FusionEntries *entries,
- + FusionEntryInfo *info );
- +
- +
- +/* Lock & Unlock */
- +
- +int fusion_entry_lock ( FusionEntries *entries,
- + int id,
- + bool keep_entries_lock,
- + FusionEntry **ret_entry );
- +
- +void fusion_entry_unlock ( FusionEntry *entry );
- +
- +
- +/** Wait & Notify **/
- +
- +/*
- + * Wait for the entry to be notified with an optional timeout.
- + *
- + * The entry
- + * (1) has to be locked prior to calling this function.
- + * (2) is temporarily unlocked while being waited for.
- + *
- + * If this function returns an error, the entry is not locked again!
- + *
- + * Possible errors are:
- + * -EIDRM Entry has been removed while being waited for.
- + * -ETIMEDOUT Timeout occured.
- + * -EINTR A signal has been received.
- + */
- +int fusion_entry_wait ( FusionEntry *entry,
- + long *timeout );
- +
- +/*
- + * Wake up one or all processes waiting for the entry to be notified.
- + *
- + * The entry has to be locked prior to calling this function.
- + */
- +void fusion_entry_notify ( FusionEntry *entry,
- + bool all );
- +
- +
- +#define FUSION_ENTRY_CLASS( Type, name, init_func, destroy_func, print_func ) \
- + \
- + static FusionEntryClass name##_class = { \
- + .object_size = sizeof(Type), \
- + .Init = init_func, \
- + .Destroy = destroy_func, \
- + .Print = print_func \
- + }; \
- + \
- + static inline int fusion_##name##_lock( FusionEntries *entries, \
- + int id, \
- + bool keep, \
- + Type **ret_##name ) \
- + { \
- + int ret; \
- + FusionEntry *entry; \
- + \
- + ret = fusion_entry_lock( entries, id, keep, &entry ); \
- + \
- + if (!ret) \
- + *ret_##name = (Type *) entry; \
- + \
- + return ret; \
- + } \
- + \
- + static inline void fusion_##name##_unlock( Type *name ) \
- + { \
- + fusion_entry_unlock( (FusionEntry*) name ); \
- + } \
- + \
- + static inline int fusion_##name##_wait( Type *name, long *timeout ) \
- + { \
- + return fusion_entry_wait( (FusionEntry*) name, timeout ); \
- + } \
- + \
- + static inline void fusion_##name##_notify( Type *name, bool all ) \
- + { \
- + fusion_entry_notify( (FusionEntry*) name, all ); \
- + }
- +
- +
- +#endif
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/fifo.c linux-2.6.22.1/drivers/char/fusion/fifo.c
- --- linux-2.6.22.1-0rig/drivers/char/fusion/fifo.c 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/fifo.c 2003-06-16 19:47:03.000000000 +0200
- @@ -0,0 +1,53 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#include <linux/types.h>
- +
- +#include "fifo.h"
- +
- +void
- +fusion_fifo_put (FusionFifo *fifo, FusionLink *link)
- +{
- + link->prev = fifo->last;
- + link->next = NULL;
- +
- + if (fifo->last)
- + fifo->last->next = link;
- + else
- + fifo->first = link;
- +
- + fifo->last = link;
- +
- + fifo->count++;
- +}
- +
- +FusionLink *
- +fusion_fifo_get (FusionFifo *fifo)
- +{
- + FusionLink *first = fifo->first;
- +
- + if (!first)
- + return NULL;
- +
- + fifo->first = first->next;
- +
- + if (fifo->last == first)
- + fifo->last = NULL;
- + else
- + fifo->first->prev = NULL;
- +
- + fifo->count--;
- +
- + return first;
- +}
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/fifo.h linux-2.6.22.1/drivers/char/fusion/fifo.h
- --- linux-2.6.22.1-0rig/drivers/char/fusion/fifo.h 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/fifo.h 2003-06-16 19:47:03.000000000 +0200
- @@ -0,0 +1,36 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifndef __FUSION__FIFO_H__
- +#define __FUSION__FIFO_H__
- +
- +#include "types.h"
- +#include "list.h"
- +
- +typedef struct {
- + FusionLink *first;
- + FusionLink *last;
- +
- + int count;
- +} FusionFifo;
- +
- +void fusion_fifo_put (FusionFifo *fifo,
- + FusionLink *link);
- +
- +FusionLink *fusion_fifo_get (FusionFifo *fifo);
- +
- +int fusion_fifo_count (FusionFifo *fifo);
- +
- +#endif /* __FUSION__LIST_H__ */
- +
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/fusiondev.c linux-2.6.22.1/drivers/char/fusion/fusiondev.c
- --- linux-2.6.22.1-0rig/drivers/char/fusion/fusiondev.c 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/fusiondev.c 2007-03-08 14:02:47.000000000 +0100
- @@ -0,0 +1,1187 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#include <linux/version.h>
- +#include <linux/module.h>
- +#ifdef HAVE_LINUX_CONFIG_H
- +#include <linux/config.h>
- +#endif
- +#include <linux/types.h>
- +#include <linux/kernel.h>
- +#include <linux/fs.h>
- +#include <linux/slab.h>
- +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
- +#include <linux/devfs_fs_kernel.h>
- +#endif
- +#if LINUX_VERSION_CODE > KERNEL_VERSION(2, 6, 19)
- +#include <linux/page-flags.h>
- +#include <linux/mm.h>
- +#endif
- +
- +#include <linux/proc_fs.h>
- +#include <linux/poll.h>
- +#include <linux/init.h>
- +#include <asm/io.h>
- +#include <asm/uaccess.h>
- +
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2)
- +#include <linux/device.h>
- +#endif
- +
- +#include <linux/fusion.h>
- +
- +#include "call.h"
- +#include "fusiondev.h"
- +#include "fusionee.h"
- +#include "property.h"
- +#include "reactor.h"
- +#include "ref.h"
- +#include "skirmish.h"
- +#include "shmpool.h"
- +
- +#if 0
- +#define DEBUG(x...) printk (KERN_DEBUG "Fusion: " x)
- +#else
- +#define DEBUG(x...) do {} while (0)
- +#endif
- +
- +#ifndef FUSION_MAJOR
- +#define FUSION_MAJOR 252
- +#endif
- +
- +MODULE_LICENSE("GPL");
- +MODULE_AUTHOR("Denis Oliver Kropp <dok@directfb.org>");
- +
- +struct proc_dir_entry *proc_fusion_dir;
- +
- +#define NUM_MINORS 8
- +
- +static FusionDev *fusion_devs[NUM_MINORS] = { 0 };
- +static DECLARE_MUTEX(devs_lock);
- +
- +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 0)
- +static devfs_handle_t devfs_handles[NUM_MINORS];
- +static inline unsigned iminor(struct inode *inode)
- +{
- + return MINOR(inode->i_rdev);
- +}
- +#endif
- +
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2)
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
- +static struct class *fusion_class;
- +#else
- +static struct class_simple *fusion_class;
- +#endif
- +#endif
- +
- +/******************************************************************************/
- +
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
- +void
- +fusion_sleep_on(wait_queue_head_t *q, struct semaphore *lock, signed long *timeout)
- +{
- + DEFINE_WAIT(wait);
- +
- + prepare_to_wait( q, &wait, TASK_INTERRUPTIBLE );
- +
- + up( lock );
- +
- + if (timeout)
- + *timeout = schedule_timeout(*timeout);
- + else
- + schedule();
- +
- + finish_wait( q, &wait );
- +}
- +#else
- +void
- +fusion_sleep_on(wait_queue_head_t *q, struct semaphore *lock, signed long *timeout)
- +{
- + wait_queue_t wait;
- +
- + init_waitqueue_entry (&wait, current);
- +
- + current->state = TASK_INTERRUPTIBLE;
- +
- + write_lock (&q->lock);
- + __add_wait_queue (q, &wait);
- + write_unlock (&q->lock);
- +
- + up (lock);
- +
- + if (timeout)
- + *timeout = schedule_timeout(*timeout);
- + else
- + schedule();
- +
- + write_lock (&q->lock);
- + __remove_wait_queue (q, &wait);
- + write_unlock (&q->lock);
- +}
- +#endif
- +
- +/******************************************************************************/
- +
- +static int
- +fusiondev_stat_read_proc(char *buf, char **start, off_t offset,
- + int len, int *eof, void *private)
- +{
- + FusionDev *dev = private;
- + int written = 0;
- +
- + written += snprintf( buf, len,
- + "lease/purchase cede attach detach "
- + "ref up ref down prevail/swoop dismiss\n" );
- + if (written < offset) {
- + offset -= written;
- + written = 0;
- + }
- +
- + if (written < len) {
- + written += snprintf( buf+written, len - written,
- + "%10d %10d %10d %10d %10d %10d %10d %10d\n",
- + dev->stat.property_lease_purchase,
- + dev->stat.property_cede,
- + dev->stat.reactor_attach,
- + dev->stat.reactor_detach,
- + dev->stat.ref_up,
- + dev->stat.ref_down,
- + dev->stat.skirmish_prevail_swoop,
- + dev->stat.skirmish_dismiss );
- + if (written < offset) {
- + offset -= written;
- + written = 0;
- + }
- + }
- +
- + *start = buf + offset;
- + written -= offset;
- + if (written > len) {
- + *eof = 0;
- + return len;
- + }
- +
- + *eof = 1;
- + return(written<0) ? 0 : written;
- +}
- +
- +/******************************************************************************/
- +
- +static int
- +fusiondev_init (FusionDev *dev)
- +{
- + int ret;
- +
- + init_MUTEX( &dev->enter_lock );
- + init_waitqueue_head( &dev->enter_wait );
- +
- + ret = fusionee_init (dev);
- + if (ret)
- + goto error_fusionee;
- +
- + ret = fusion_ref_init (dev);
- + if (ret)
- + goto error_ref;
- +
- + ret = fusion_skirmish_init (dev);
- + if (ret)
- + goto error_skirmish;
- +
- + ret = fusion_property_init (dev);
- + if (ret)
- + goto error_property;
- +
- + ret = fusion_reactor_init (dev);
- + if (ret)
- + goto error_reactor;
- +
- + ret = fusion_shmpool_init (dev);
- + if (ret)
- + goto error_shmpool;
- +
- + ret = fusion_call_init (dev);
- + if (ret)
- + goto error_call;
- +
- + create_proc_read_entry( "stat", 0, dev->proc_dir,
- + fusiondev_stat_read_proc, dev );
- +
- + return 0;
- +
- +
- +error_call:
- + fusion_shmpool_deinit (dev);
- +
- +error_shmpool:
- + fusion_reactor_deinit (dev);
- +
- +error_reactor:
- + fusion_property_deinit (dev);
- +
- +error_property:
- + fusion_skirmish_deinit (dev);
- +
- +error_skirmish:
- + fusion_ref_deinit (dev);
- +
- +error_ref:
- + fusionee_deinit (dev);
- +
- +error_fusionee:
- + return ret;
- +}
- +
- +static void
- +fusiondev_deinit (FusionDev *dev)
- +{
- + remove_proc_entry ("stat", dev->proc_dir);
- +
- + fusion_call_deinit (dev);
- + fusion_shmpool_deinit (dev);
- + fusion_reactor_deinit (dev);
- + fusion_property_deinit (dev);
- + fusion_skirmish_deinit (dev);
- + fusion_ref_deinit (dev);
- + fusionee_deinit (dev);
- +
- + if (dev->shared_area) {
- + ClearPageReserved( virt_to_page(dev->shared_area) );
- + free_page( dev->shared_area );
- + }
- +}
- +
- +/******************************************************************************/
- +
- +static int
- +fusion_open (struct inode *inode, struct file *file)
- +{
- + int ret;
- + Fusionee *fusionee;
- + int minor = iminor(inode);
- +
- + DEBUG( "fusion_open( %p, %d )\n", file, atomic_read(&file->f_count) );
- +
- + if (down_interruptible (&devs_lock))
- + return -EINTR;
- +
- + if (!fusion_devs[minor]) {
- + char buf[4];
- +
- + fusion_devs[minor] = kmalloc (sizeof(FusionDev), GFP_KERNEL);
- + if (!fusion_devs[minor]) {
- + up (&devs_lock);
- + return -ENOMEM;
- + }
- +
- + memset (fusion_devs[minor], 0, sizeof(FusionDev));
- +
- + snprintf (buf, 4, "%d", minor);
- +
- + fusion_devs[minor]->proc_dir = proc_mkdir (buf, proc_fusion_dir);
- + fusion_devs[minor]->index = minor;
- +
- + ret = fusiondev_init (fusion_devs[minor]);
- + if (ret) {
- + remove_proc_entry (buf, proc_fusion_dir);
- +
- + kfree (fusion_devs[minor]);
- + fusion_devs[minor] = NULL;
- +
- + up (&devs_lock);
- +
- + return ret;
- + }
- + }
- + else if (file->f_flags & O_EXCL) {
- + if (fusion_devs[minor]->fusionee.last_id) {
- + up (&devs_lock);
- + return -EBUSY;
- + }
- + }
- +
- + ret = fusionee_new (fusion_devs[minor], !!(file->f_flags & O_APPEND), &fusionee);
- + if (ret) {
- + if (!fusion_devs[minor]->refs) {
- + fusiondev_deinit (fusion_devs[minor]);
- +
- + remove_proc_entry (fusion_devs[minor]->proc_dir->name,
- + proc_fusion_dir);
- +
- + kfree (fusion_devs[minor]);
- + fusion_devs[minor] = NULL;
- + }
- +
- + up (&devs_lock);
- +
- + return ret;
- + }
- +
- + fusion_devs[minor]->refs++;
- +
- + up (&devs_lock);
- +
- +
- + file->private_data = fusionee;
- +
- + return 0;
- +}
- +
- +static int
- +fusion_release (struct inode *inode, struct file *file)
- +{
- + int minor = iminor(inode);
- + Fusionee *fusionee = file->private_data;
- +
- + DEBUG( "fusion_release( %p, %d )\n", file, atomic_read(&file->f_count) );
- +
- + fusionee_destroy (fusion_devs[minor], fusionee);
- +
- + down (&devs_lock);
- +
- + if (! --fusion_devs[minor]->refs) {
- + fusiondev_deinit (fusion_devs[minor]);
- +
- + remove_proc_entry (fusion_devs[minor]->proc_dir->name,
- + proc_fusion_dir);
- +
- + kfree (fusion_devs[minor]);
- + fusion_devs[minor] = NULL;
- + }
- +
- + up (&devs_lock);
- +
- + return 0;
- +}
- +
- +static int
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 18)
- +fusion_flush (struct file *file, fl_owner_t id)
- +#else
- +fusion_flush (struct file *file)
- +#endif
- +{
- + Fusionee *fusionee = file->private_data;
- + FusionDev *dev = fusion_devs[iminor(file->f_dentry->d_inode)];
- +
- + (void) fusionee;
- +
- + DEBUG( "fusion_flush( %p, %d, 0x%08x %d )\n", file, atomic_read(&file->f_count), fusionee_id(fusionee), current->pid );
- +
- + if (current->flags & PF_EXITING)
- + fusion_skirmish_dismiss_all_from_pid (dev, current->pid);
- +
- + return 0;
- +}
- +
- +static ssize_t
- +fusion_read (struct file *file, char *buf, size_t count, loff_t *ppos)
- +{
- + Fusionee *fusionee = file->private_data;
- + FusionDev *dev = fusion_devs[iminor(file->f_dentry->d_inode)];
- +
- + DEBUG( "fusion_read( %p, %d, %d )\n", file, atomic_read(&file->f_count), count );
- +
- + return fusionee_get_messages (dev, fusionee, buf, count,
- + !(file->f_flags & O_NONBLOCK));
- +}
- +
- +static unsigned int
- +fusion_poll (struct file *file, poll_table * wait)
- +{
- + Fusionee *fusionee = file->private_data;
- + FusionDev *dev = fusion_devs[iminor(file->f_dentry->d_inode)];
- +
- + DEBUG( "fusion_poll( %p, %d )\n", file, atomic_read(&file->f_count) );
- +
- + return fusionee_poll (dev, fusionee, file, wait);
- +}
- +
- +static int
- +lounge_ioctl (struct file *file, FusionDev *dev, Fusionee *fusionee,
- + unsigned int cmd, unsigned long arg)
- +{
- + int ret;
- + FusionEnter enter;
- + FusionKill kill;
- + FusionEntryInfo info;
- + FusionFork fork = {0};
- +
- + switch (_IOC_NR(cmd)) {
- + case _IOC_NR(FUSION_ENTER):
- + if (copy_from_user (&enter, (FusionEnter*) arg, sizeof(enter)))
- + return -EFAULT;
- +
- + ret = fusionee_enter( dev, &enter, fusionee );
- + if (ret)
- + return ret;
- +
- + if (copy_to_user ((FusionEnter*) arg, &enter, sizeof(enter)))
- + return -EFAULT;
- +
- + return 0;
- +
- + case _IOC_NR(FUSION_UNBLOCK):
- + if (fusionee_id( fusionee ) != FUSION_ID_MASTER)
- + return -EPERM;
- +
- + if (down_interruptible( &dev->enter_lock ))
- + return -EINTR;
- +
- + dev->enter_ok = 1;
- +
- + wake_up_interruptible_all( &dev->enter_wait );
- +
- + up( &dev->enter_lock );
- +
- + return 0;
- +
- + case _IOC_NR(FUSION_KILL):
- + if (copy_from_user (&kill, (FusionKill*) arg, sizeof(kill)))
- + return -EFAULT;
- +
- + return fusionee_kill (dev, fusionee,
- + kill.fusion_id, kill.signal, kill.timeout_ms);
- +
- + case _IOC_NR(FUSION_ENTRY_SET_INFO):
- + if (copy_from_user (&info, (FusionEntryInfo*) arg, sizeof(info)))
- + return -EFAULT;
- +
- + switch (info.type) {
- + case FT_SKIRMISH:
- + return fusion_entry_set_info (&dev->skirmish, &info);
- +
- + case FT_PROPERTY:
- + return fusion_entry_set_info (&dev->properties, &info);
- +
- + case FT_REACTOR:
- + return fusion_entry_set_info (&dev->reactor, &info);
- +
- + case FT_REF:
- + return fusion_entry_set_info (&dev->ref, &info);
- +
- + case FT_SHMPOOL:
- + return fusion_entry_set_info (&dev->shmpool, &info);
- +
- + default:
- + return -ENOSYS;
- + }
- +
- + case _IOC_NR(FUSION_ENTRY_GET_INFO):
- + if (copy_from_user (&info, (FusionEntryInfo*) arg, sizeof(info)))
- + return -EFAULT;
- +
- + switch (info.type) {
- + case FT_SKIRMISH:
- + ret = fusion_entry_get_info (&dev->skirmish, &info);
- + break;
- +
- + case FT_PROPERTY:
- + ret = fusion_entry_get_info (&dev->properties, &info);
- + break;
- +
- + case FT_REACTOR:
- + ret = fusion_entry_get_info (&dev->reactor, &info);
- + break;
- +
- + case FT_REF:
- + ret = fusion_entry_get_info (&dev->ref, &info);
- + break;
- +
- + case FT_SHMPOOL:
- + ret = fusion_entry_get_info (&dev->shmpool, &info);
- + break;
- +
- + default:
- + return -ENOSYS;
- + }
- +
- + if (ret)
- + return ret;
- +
- + if (copy_to_user ((FusionEntryInfo*) arg, &info, sizeof(info)))
- + return -EFAULT;
- +
- + return 0;
- +
- + case _IOC_NR(FUSION_FORK):
- + if (copy_from_user( &fork, (FusionFork*) arg, sizeof(fork) ))
- + return -EFAULT;
- +
- + ret = fusionee_fork( dev, &fork, fusionee );
- + if (ret)
- + return ret;
- +
- + if (copy_to_user( (FusionFork*) arg, &fork, sizeof(fork) ))
- + return -EFAULT;
- +
- + return 0;
- + }
- +
- + return -ENOSYS;
- +}
- +
- +static int
- +messaging_ioctl (FusionDev *dev, Fusionee *fusionee,
- + unsigned int cmd, unsigned long arg)
- +{
- + FusionSendMessage send;
- +
- + switch (_IOC_NR(cmd)) {
- + case _IOC_NR(FUSION_SEND_MESSAGE):
- + if (copy_from_user (&send, (FusionSendMessage*) arg, sizeof(send)))
- + return -EFAULT;
- +
- + if (send.msg_size <= 0)
- + return -EINVAL;
- +
- + /* message data > 64k should be stored in shared memory */
- + if (send.msg_size > 0x10000)
- + return -EMSGSIZE;
- +
- + return fusionee_send_message (dev, fusionee, send.fusion_id, FMT_SEND,
- + send.msg_id, send.msg_size, send.msg_data);
- + }
- +
- + return -ENOSYS;
- +}
- +
- +static int
- +call_ioctl (FusionDev *dev, Fusionee *fusionee,
- + unsigned int cmd, unsigned long arg)
- +{
- + int id;
- + int ret;
- + FusionCallNew call;
- + FusionCallExecute execute;
- + FusionCallReturn call_ret;
- + FusionID fusion_id = fusionee_id( fusionee );
- +
- + switch (_IOC_NR(cmd)) {
- + case _IOC_NR(FUSION_CALL_NEW):
- + if (copy_from_user (&call, (FusionCallNew*) arg, sizeof(call)))
- + return -EFAULT;
- +
- + ret = fusion_call_new (dev, fusion_id, &call);
- + if (ret)
- + return ret;
- +
- + if (put_user (call.call_id, (int*) arg)) {
- + fusion_call_destroy (dev, fusion_id, call.call_id);
- + return -EFAULT;
- + }
- + return 0;
- +
- + case _IOC_NR(FUSION_CALL_EXECUTE):
- + if (copy_from_user (&execute, (FusionCallExecute*) arg, sizeof(execute)))
- + return -EFAULT;
- +
- + ret = fusion_call_execute (dev, fusionee, &execute);
- + if (ret)
- + return ret;
- +
- + if (put_user (execute.ret_val, (int*) arg))
- + return -EFAULT;
- + return 0;
- +
- + case _IOC_NR(FUSION_CALL_RETURN):
- + if (copy_from_user (&call_ret, (FusionCallReturn*) arg, sizeof(call_ret)))
- + return -EFAULT;
- +
- + return fusion_call_return (dev, fusion_id, &call_ret);
- +
- + case _IOC_NR(FUSION_CALL_DESTROY):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_call_destroy (dev, fusion_id, id);
- + }
- +
- + return -ENOSYS;
- +}
- +
- +static int
- +ref_ioctl (FusionDev *dev, Fusionee *fusionee,
- + unsigned int cmd, unsigned long arg)
- +{
- + int id;
- + int ret;
- + int refs;
- + FusionRefWatch watch;
- + FusionRefInherit inherit;
- + FusionID fusion_id = fusionee_id( fusionee );
- +
- + switch (_IOC_NR(cmd)) {
- + case _IOC_NR(FUSION_REF_NEW):
- + ret = fusion_ref_new (dev, &id);
- + if (ret)
- + return ret;
- +
- + if (put_user (id, (int*) arg)) {
- + fusion_ref_destroy (dev, id);
- + return -EFAULT;
- + }
- + return 0;
- +
- + case _IOC_NR(FUSION_REF_UP):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_ref_up (dev, id, fusion_id);
- +
- + case _IOC_NR(FUSION_REF_UP_GLOBAL):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_ref_up (dev, id, 0);
- +
- + case _IOC_NR(FUSION_REF_DOWN):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_ref_down (dev, id, fusion_id);
- +
- + case _IOC_NR(FUSION_REF_DOWN_GLOBAL):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_ref_down (dev, id, 0);
- +
- + case _IOC_NR(FUSION_REF_ZERO_LOCK):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_ref_zero_lock (dev, id, fusion_id);
- +
- + case _IOC_NR(FUSION_REF_ZERO_TRYLOCK):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_ref_zero_trylock (dev, id, fusion_id);
- +
- + case _IOC_NR(FUSION_REF_UNLOCK):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_ref_zero_unlock (dev, id, fusion_id);
- +
- + case _IOC_NR(FUSION_REF_STAT):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + ret = fusion_ref_stat (dev, id, &refs);
- + if (ret)
- + return ret;
- +
- + return refs;
- +
- + case _IOC_NR(FUSION_REF_WATCH):
- + if (copy_from_user (&watch, (FusionRefWatch*) arg, sizeof(watch)))
- + return -EFAULT;
- +
- + return fusion_ref_watch (dev, watch.id, watch.call_id, watch.call_arg);
- +
- + case _IOC_NR(FUSION_REF_INHERIT):
- + if (copy_from_user (&inherit, (FusionRefInherit*) arg, sizeof(inherit)))
- + return -EFAULT;
- +
- + return fusion_ref_inherit (dev, inherit.id, inherit.from);
- +
- + case _IOC_NR(FUSION_REF_DESTROY):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_ref_destroy (dev, id);
- + }
- +
- + return -ENOSYS;
- +}
- +
- +static int
- +skirmish_ioctl (FusionDev *dev, Fusionee *fusionee,
- + unsigned int cmd, unsigned long arg)
- +{
- + int id;
- + int ret;
- + int lock_count;
- + FusionID fusion_id = fusionee_id( fusionee );
- +
- + switch (_IOC_NR(cmd)) {
- + case _IOC_NR(FUSION_SKIRMISH_NEW):
- + ret = fusion_skirmish_new (dev, &id);
- + if (ret)
- + return ret;
- +
- + if (put_user (id, (int*) arg)) {
- + fusion_skirmish_destroy (dev, id);
- + return -EFAULT;
- + }
- + return 0;
- +
- + case _IOC_NR(FUSION_SKIRMISH_PREVAIL):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_skirmish_prevail (dev, id, fusion_id);
- +
- + case _IOC_NR(FUSION_SKIRMISH_SWOOP):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_skirmish_swoop (dev, id, fusion_id);
- +
- + case _IOC_NR(FUSION_SKIRMISH_DISMISS):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_skirmish_dismiss (dev, id, fusion_id);
- +
- + case _IOC_NR(FUSION_SKIRMISH_DESTROY):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_skirmish_destroy (dev, id);
- +
- + case _IOC_NR(FUSION_SKIRMISH_LOCK_COUNT):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + ret = fusion_skirmish_lock_count (dev, id, fusion_id, &lock_count);
- + if (put_user(lock_count, ((int*)arg)+1))
- + return -EFAULT;
- +
- + return ret;
- + }
- +
- + return -ENOSYS;
- +}
- +
- +static int
- +property_ioctl (FusionDev *dev, Fusionee *fusionee,
- + unsigned int cmd, unsigned long arg)
- +{
- + int id;
- + int ret;
- + FusionID fusion_id = fusionee_id( fusionee );
- +
- + switch (_IOC_NR(cmd)) {
- + case _IOC_NR(FUSION_PROPERTY_NEW):
- + ret = fusion_property_new (dev, &id);
- + if (ret)
- + return ret;
- +
- + if (put_user (id, (int*) arg)) {
- + fusion_property_destroy (dev, id);
- + return -EFAULT;
- + }
- + return 0;
- +
- + case _IOC_NR(FUSION_PROPERTY_LEASE):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_property_lease (dev, id, fusion_id);
- +
- + case _IOC_NR(FUSION_PROPERTY_PURCHASE):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_property_purchase (dev, id, fusion_id);
- +
- + case _IOC_NR(FUSION_PROPERTY_CEDE):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_property_cede (dev, id, fusion_id);
- +
- + case _IOC_NR(FUSION_PROPERTY_HOLDUP):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_property_holdup (dev, id, fusionee);
- +
- + case _IOC_NR(FUSION_PROPERTY_DESTROY):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_property_destroy (dev, id);
- + }
- +
- + return -ENOSYS;
- +}
- +
- +static int
- +reactor_ioctl (FusionDev *dev, Fusionee *fusionee,
- + unsigned int cmd, unsigned long arg)
- +{
- + int id;
- + int ret;
- + FusionReactorDispatch dispatch;
- + FusionID fusion_id = fusionee_id( fusionee );
- +
- + switch (_IOC_NR(cmd)) {
- + case _IOC_NR(FUSION_REACTOR_NEW):
- + ret = fusion_reactor_new (dev, &id);
- + if (ret)
- + return ret;
- +
- + if (put_user (id, (int*) arg)) {
- + fusion_reactor_destroy (dev, id);
- + return -EFAULT;
- + }
- + return 0;
- +
- + case _IOC_NR(FUSION_REACTOR_ATTACH):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_reactor_attach (dev, id, fusion_id);
- +
- + case _IOC_NR(FUSION_REACTOR_DETACH):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_reactor_detach (dev, id, fusion_id);
- +
- + case _IOC_NR(FUSION_REACTOR_DISPATCH):
- + if (copy_from_user (&dispatch,
- + (FusionReactorDispatch*) arg, sizeof(dispatch)))
- + return -EFAULT;
- +
- + if (dispatch.msg_size <= 0)
- + return -EINVAL;
- +
- + /* message data > 64k should be stored in shared memory */
- + if (dispatch.msg_size > 0x10000)
- + return -EMSGSIZE;
- +
- + return fusion_reactor_dispatch (dev, dispatch.reactor_id,
- + dispatch.self ? NULL : fusionee,
- + dispatch.msg_size, dispatch.msg_data);
- +
- + case _IOC_NR(FUSION_REACTOR_DESTROY):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_reactor_destroy (dev, id);
- + }
- +
- + return -ENOSYS;
- +}
- +
- +static int
- +shmpool_ioctl (FusionDev *dev, Fusionee *fusionee,
- + unsigned int cmd, unsigned long arg)
- +{
- + int id;
- + int ret;
- + FusionSHMPoolNew pool;
- + FusionSHMPoolAttach attach;
- + FusionSHMPoolDispatch dispatch;
- + FusionID fusion_id = fusionee_id( fusionee );
- +
- + switch (_IOC_NR(cmd)) {
- + case _IOC_NR(FUSION_SHMPOOL_NEW):
- + if (copy_from_user (&pool, (FusionSHMPoolNew*) arg, sizeof(pool)))
- + return -EFAULT;
- +
- + ret = fusion_shmpool_new (dev, &pool);
- + if (ret)
- + return ret;
- +
- + if (copy_to_user ((FusionSHMPoolNew*) arg, &pool, sizeof(pool))) {
- + fusion_shmpool_destroy (dev, pool.pool_id);
- + return -EFAULT;
- + }
- +
- + return 0;
- +
- + case _IOC_NR(FUSION_SHMPOOL_ATTACH):
- + if (copy_from_user (&attach,
- + (FusionSHMPoolAttach*) arg, sizeof(attach)))
- + return -EFAULT;
- +
- + ret = fusion_shmpool_attach (dev, &attach, fusion_id);
- + if (ret)
- + return ret;
- +
- + if (copy_to_user ((FusionSHMPoolAttach*) arg, &attach, sizeof(attach))) {
- + fusion_shmpool_detach (dev, attach.pool_id, fusion_id);
- + return -EFAULT;
- + }
- +
- + return 0;
- +
- + case _IOC_NR(FUSION_SHMPOOL_DETACH):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_shmpool_detach (dev, id, fusion_id);
- +
- + case _IOC_NR(FUSION_SHMPOOL_DISPATCH):
- + if (copy_from_user (&dispatch,
- + (FusionSHMPoolDispatch*) arg, sizeof(dispatch)))
- + return -EFAULT;
- +
- + return fusion_shmpool_dispatch (dev, &dispatch, fusionee);
- +
- + case _IOC_NR(FUSION_SHMPOOL_DESTROY):
- + if (get_user (id, (int*) arg))
- + return -EFAULT;
- +
- + return fusion_shmpool_destroy (dev, id);
- + }
- +
- + return -ENOSYS;
- +}
- +
- +static int
- +fusion_ioctl (struct inode *inode, struct file *file,
- + unsigned int cmd, unsigned long arg)
- +{
- + Fusionee *fusionee = file->private_data;
- + FusionDev *dev = fusion_devs[iminor(inode)];
- +
- + DEBUG( "fusion_ioctl (0x%08x)\n", cmd );
- +
- + switch (_IOC_TYPE(cmd)) {
- + case FT_LOUNGE:
- + return lounge_ioctl( file, dev, fusionee, cmd, arg );
- +
- + case FT_MESSAGING:
- + return messaging_ioctl( dev, fusionee, cmd, arg );
- +
- + case FT_CALL:
- + return call_ioctl( dev, fusionee, cmd, arg );
- +
- + case FT_REF:
- + return ref_ioctl( dev, fusionee, cmd, arg );
- +
- + case FT_SKIRMISH:
- + return skirmish_ioctl( dev, fusionee, cmd, arg );
- +
- + case FT_PROPERTY:
- + return property_ioctl( dev, fusionee, cmd, arg );
- +
- + case FT_REACTOR:
- + return reactor_ioctl( dev, fusionee, cmd, arg );
- +
- + case FT_SHMPOOL:
- + return shmpool_ioctl( dev, fusionee, cmd, arg );
- + }
- +
- + return -ENOSYS;
- +}
- +
- +static int
- +fusion_mmap( struct file *file,
- + struct vm_area_struct *vma )
- +{
- + Fusionee *fusionee = file->private_data;
- + FusionDev *dev = fusion_devs[iminor(file->f_dentry->d_inode)];
- + unsigned int size;
- +
- + if (vma->vm_pgoff != 0)
- + return -EINVAL;
- +
- + size = vma->vm_end - vma->vm_start;
- + if (!size || size > PAGE_SIZE)
- + return -EINVAL;
- +
- + if (!dev->shared_area) {
- + if (fusionee_id( fusionee ) != FUSION_ID_MASTER)
- + return -EPERM;
- +
- + dev->shared_area = get_zeroed_page( GFP_KERNEL );
- + if (!dev->shared_area)
- + return -ENOMEM;
- +
- + SetPageReserved( virt_to_page(dev->shared_area) );
- + }
- +
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
- + return remap_pfn_range( vma, vma->vm_start,
- + virt_to_phys((void*)dev->shared_area) >> PAGE_SHIFT,
- + PAGE_SIZE, vma->vm_page_prot );
- +#else
- + return io_remap_page_range( vma->vm_start,
- + virt_to_phys((void*)dev->shared_area),
- + PAGE_SIZE, vma->vm_page_prot );
- +#endif
- +}
- +
- +static struct file_operations fusion_fops = {
- + .owner = THIS_MODULE,
- + .open = fusion_open,
- + .flush = fusion_flush,
- + .release = fusion_release,
- + .read = fusion_read,
- + .poll = fusion_poll,
- + .ioctl = fusion_ioctl,
- + .mmap = fusion_mmap
- +};
- +
- +/******************************************************************************/
- +
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
- +static int __init
- +register_devices(void)
- +{
- + int i;
- +
- + if (register_chrdev (FUSION_MAJOR, "fusion", &fusion_fops)) {
- + printk (KERN_ERR "fusion: unable to get major %d\n", FUSION_MAJOR);
- + return -EIO;
- + }
- +
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2)
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
- + fusion_class = class_create (THIS_MODULE, "fusion");
- +#else
- + fusion_class = class_simple_create (THIS_MODULE, "fusion");
- +#endif
- + if (IS_ERR(fusion_class)) {
- + unregister_chrdev (FUSION_MAJOR, "fusion");
- + return PTR_ERR(fusion_class);
- + }
- +#endif
- +
- +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
- + devfs_mk_dir("fusion");
- +#endif
- +
- + for (i=0; i<NUM_MINORS; i++) {
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 15)
- + class_device_create (fusion_class,
- + NULL,
- + MKDEV(FUSION_MAJOR, i),
- + NULL, "fusion%d", i);
- +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
- + class_device_create (fusion_class,
- + MKDEV(FUSION_MAJOR, i),
- + NULL, "fusion%d", i);
- +#elif LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2)
- + class_simple_device_add (fusion_class,
- + MKDEV(FUSION_MAJOR, i),
- + NULL, "fusion%d", i);
- +#endif
- +
- +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
- + devfs_mk_cdev (MKDEV(FUSION_MAJOR, i),
- + S_IFCHR | S_IRUSR | S_IWUSR,
- + "fusion/%d", i);
- +#endif
- + }
- +
- + return 0;
- +}
- +#else
- +static int __init
- +register_devices(void)
- +{
- + int i;
- + char buf[16];
- +
- + if (devfs_register_chrdev (FUSION_MAJOR, "fusion", &fusion_fops)) {
- + printk (KERN_ERR "fusion: unable to get major %d\n", FUSION_MAJOR);
- + return -EIO;
- + }
- +
- + for (i=0; i<NUM_MINORS; i++) {
- + snprintf (buf, 16, "fusion/%d", i);
- +
- + devfs_handles[i] = devfs_register (NULL, buf, DEVFS_FL_DEFAULT,
- + FUSION_MAJOR, i,
- + S_IFCHR | S_IRUSR | S_IWUSR,
- + &fusion_fops, NULL);
- + }
- +
- + return 0;
- +}
- +#endif
- +
- +int __init
- +fusion_init(void)
- +{
- + int ret;
- +
- + ret = register_devices();
- + if (ret)
- + return ret;
- +
- + proc_fusion_dir = proc_mkdir ("fusion", NULL);
- +
- + return 0;
- +}
- +
- +/******************************************************************************/
- +
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 0)
- +static void __exit
- +deregister_devices(void)
- +{
- + int i;
- +
- + unregister_chrdev (FUSION_MAJOR, "fusion");
- +
- + for (i=0; i<NUM_MINORS; i++) {
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2)
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
- + class_device_destroy (fusion_class, MKDEV(FUSION_MAJOR, i));
- +#else
- + class_simple_device_remove (MKDEV(FUSION_MAJOR, i));
- +#endif
- +#endif
- +
- +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
- + devfs_remove ("fusion/%d", i);
- +#endif
- + }
- +
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 2)
- +#if LINUX_VERSION_CODE >= KERNEL_VERSION(2, 6, 13)
- + class_destroy (fusion_class);
- +#else
- + class_simple_destroy (fusion_class);
- +#endif
- +#endif
- +
- +#if LINUX_VERSION_CODE < KERNEL_VERSION(2, 6, 18)
- + devfs_remove ("fusion");
- +#endif
- +}
- +#else
- +static void __exit
- +deregister_devices(void)
- +{
- + int i;
- +
- + devfs_unregister_chrdev (FUSION_MAJOR, "fusion");
- +
- + for (i=0; i<NUM_MINORS; i++)
- + devfs_unregister (devfs_handles[i]);
- +}
- +#endif
- +
- +void __exit
- +fusion_exit(void)
- +{
- + deregister_devices();
- +
- + remove_proc_entry ("fusion", NULL);
- +}
- +
- +module_init(fusion_init);
- +module_exit(fusion_exit);
- +
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/fusiondev.h linux-2.6.22.1/drivers/char/fusion/fusiondev.h
- --- linux-2.6.22.1-0rig/drivers/char/fusion/fusiondev.h 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/fusiondev.h 2006-08-04 18:28:01.000000000 +0200
- @@ -0,0 +1,83 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifndef __FUSIONDEV_H__
- +#define __FUSIONDEV_H__
- +
- +#include <linux/proc_fs.h>
- +
- +#include "entries.h"
- +#include "list.h"
- +
- +#define FUSION_ASSERT(exp) if (!(exp)) BUG()
- +#define FUSION_ASSUME(exp) if (!(exp)) printk( KERN_ERR "fusiondev: assumption '" #exp "' failed!\n" )
- +
- +typedef struct {
- + int refs;
- + int index;
- +
- + struct semaphore enter_lock;
- + int enter_ok;
- + wait_queue_head_t enter_wait;
- +
- + unsigned long shared_area;
- +
- + struct proc_dir_entry *proc_dir;
- +
- + struct {
- + int property_lease_purchase;
- + int property_cede;
- +
- + int reactor_attach;
- + int reactor_detach;
- +
- + int ref_up;
- + int ref_down;
- +
- + int skirmish_prevail_swoop;
- + int skirmish_dismiss;
- +
- + int shmpool_attach;
- + int shmpool_detach;
- + } stat;
- +
- + struct {
- + int ids;
- + FusionLink *list;
- + struct semaphore lock;
- + } call;
- +
- + struct {
- + int last_id;
- + FusionLink *list;
- + struct semaphore lock;
- + wait_queue_head_t wait;
- + } fusionee;
- +
- + FusionEntries properties;
- + FusionEntries reactor;
- + FusionEntries ref;
- + FusionEntries shmpool;
- + FusionEntries skirmish;
- +} FusionDev;
- +
- +/*
- + * Special version of interruptible_sleep_on() that unlocks the mutex
- + * after adding the entry to the queue (just before schedule).
- + */
- +void fusion_sleep_on (wait_queue_head_t *q,
- + struct semaphore *lock,
- + signed long *timeout_ms);
- +
- +#endif
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/fusionee.c linux-2.6.22.1/drivers/char/fusion/fusionee.c
- --- linux-2.6.22.1-0rig/drivers/char/fusion/fusionee.c 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/fusionee.c 2007-01-29 00:31:00.000000000 +0100
- @@ -0,0 +1,584 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifdef HAVE_LINUX_CONFIG_H
- +#include <linux/config.h>
- +#endif
- +#include <linux/types.h>
- +#include <linux/kernel.h>
- +#include <linux/slab.h>
- +#include <linux/smp_lock.h>
- +#include <asm/uaccess.h>
- +
- +#include <linux/fusion.h>
- +
- +#include "call.h"
- +#include "fifo.h"
- +#include "list.h"
- +#include "fusiondev.h"
- +#include "fusionee.h"
- +#include "property.h"
- +#include "reactor.h"
- +#include "ref.h"
- +#include "skirmish.h"
- +#include "shmpool.h"
- +
- +#if 0
- +#define DEBUG(x...) printk (KERN_DEBUG "Fusion: " x)
- +#else
- +#define DEBUG(x...) do {} while (0)
- +#endif
- +
- +struct __Fusion_Fusionee {
- + FusionLink link;
- +
- + struct semaphore lock;
- +
- + FusionID id;
- + int pid;
- +
- + FusionFifo messages;
- +
- + int rcv_total; /* Total number of messages received. */
- + int snd_total; /* Total number of messages sent. */
- +
- + wait_queue_head_t wait;
- +
- + bool force_slave;
- +};
- +
- +typedef struct {
- + FusionLink link;
- +
- + FusionMessageType type;
- + FusionID id;
- + int size;
- + void *data;
- +} Message;
- +
- +/******************************************************************************/
- +
- +static int lookup_fusionee (FusionDev *dev, FusionID id, Fusionee **ret_fusionee);
- +static int lock_fusionee (FusionDev *dev, FusionID id, Fusionee **ret_fusionee);
- +static void unlock_fusionee (Fusionee *fusionee);
- +
- +/******************************************************************************/
- +
- +static int
- +fusionees_read_proc(char *buf, char **start, off_t offset,
- + int len, int *eof, void *private)
- +{
- + FusionLink *l;
- + FusionDev *dev = private;
- + int written = 0;
- +
- + if (down_interruptible (&dev->fusionee.lock))
- + return -EINTR;
- +
- + fusion_list_foreach (l, dev->fusionee.list) {
- + Fusionee *fusionee = (Fusionee*) l;
- +
- + written += sprintf(buf+written, "(%5d) 0x%08lx (%4d messages waiting, %7d received, %7d sent)\n",
- + fusionee->pid, fusionee->id, fusionee->messages.count, fusionee->rcv_total, fusionee->snd_total);
- + if (written < offset) {
- + offset -= written;
- + written = 0;
- + }
- +
- + if (written >= len)
- + break;
- + }
- +
- + up (&dev->fusionee.lock);
- +
- + *start = buf + offset;
- + written -= offset;
- + if (written > len) {
- + *eof = 0;
- + return len;
- + }
- +
- + *eof = 1;
- + return(written<0) ? 0 : written;
- +}
- +
- +int
- +fusionee_init (FusionDev *dev)
- +{
- + init_waitqueue_head (&dev->fusionee.wait);
- +
- + init_MUTEX (&dev->fusionee.lock);
- +
- + create_proc_read_entry("fusionees", 0, dev->proc_dir,
- + fusionees_read_proc, dev);
- +
- + return 0;
- +}
- +
- +void
- +fusionee_deinit (FusionDev *dev)
- +{
- + FusionLink *l;
- +
- + down (&dev->fusionee.lock);
- +
- + remove_proc_entry ("fusionees", dev->proc_dir);
- +
- + l = dev->fusionee.list;
- + while (l) {
- + FusionLink *next = l->next;
- + Fusionee *fusionee = (Fusionee *) l;
- +
- + while (fusionee->messages.count) {
- + Message *message = (Message*) fusion_fifo_get (&fusionee->messages);
- +
- + kfree (message);
- + }
- +
- + kfree (fusionee);
- +
- + l = next;
- + }
- +
- + up (&dev->fusionee.lock);
- +}
- +
- +/******************************************************************************/
- +
- +int
- +fusionee_new( FusionDev *dev,
- + bool force_slave,
- + Fusionee **ret_fusionee )
- +{
- + Fusionee *fusionee;
- +
- + fusionee = kmalloc (sizeof(Fusionee), GFP_KERNEL);
- + if (!fusionee)
- + return -ENOMEM;
- +
- + memset (fusionee, 0, sizeof(Fusionee));
- +
- + if (down_interruptible (&dev->fusionee.lock)) {
- + kfree (fusionee);
- + return -EINTR;
- + }
- +
- + fusionee->pid = current->pid;
- + fusionee->force_slave = force_slave;
- +
- + init_MUTEX (&fusionee->lock);
- +
- + init_waitqueue_head (&fusionee->wait);
- +
- + fusion_list_prepend (&dev->fusionee.list, &fusionee->link);
- +
- + up (&dev->fusionee.lock);
- +
- + *ret_fusionee = fusionee;
- +
- + return 0;
- +}
- +
- +int
- +fusionee_enter( FusionDev *dev,
- + FusionEnter *enter,
- + Fusionee *fusionee )
- +{
- + if (enter->api.major != FUSION_API_MAJOR || enter->api.minor > FUSION_API_MINOR)
- + return -ENOPROTOOPT;
- +
- + if (down_interruptible( &dev->enter_lock ))
- + return -EINTR;
- +
- + if (dev->fusionee.last_id || fusionee->force_slave) {
- + while (!dev->enter_ok) {
- + fusion_sleep_on( &dev->enter_wait, &dev->enter_lock, NULL );
- +
- + if (signal_pending(current))
- + return -EINTR;
- +
- + if (down_interruptible( &dev->enter_lock ))
- + return -EINTR;
- + }
- +
- + FUSION_ASSERT( dev->fusionee.last_id != 0 );
- + }
- +
- + fusionee->id = ++dev->fusionee.last_id;
- +
- + up( &dev->enter_lock );
- +
- + enter->fusion_id = fusionee->id;
- +
- + return 0;
- +}
- +
- +int
- +fusionee_fork( FusionDev *dev,
- + FusionFork *fork,
- + Fusionee *fusionee )
- +{
- + int ret;
- +
- + ret = fusion_shmpool_fork_all( dev, fusionee->id, fork->fusion_id );
- + if (ret)
- + return ret;
- +
- + ret = fusion_reactor_fork_all( dev, fusionee->id, fork->fusion_id );
- + if (ret)
- + return ret;
- +
- + ret = fusion_ref_fork_all_local( dev, fusionee->id, fork->fusion_id );
- + if (ret)
- + return ret;
- +
- + fork->fusion_id = fusionee->id;
- +
- + return 0;
- +}
- +
- +int
- +fusionee_send_message (FusionDev *dev,
- + Fusionee *sender,
- + FusionID recipient,
- + FusionMessageType msg_type,
- + int msg_id,
- + int msg_size,
- + const void *msg_data)
- +{
- + int ret;
- + Message *message;
- + Fusionee *fusionee;
- +
- + DEBUG( "fusionee_send_message (%d -> %d, type %d, id %d, size %d)\n",
- + fusionee->id, recipient, msg_type, msg_id, msg_size );
- +
- + ret = lookup_fusionee (dev, recipient, &fusionee);
- + if (ret)
- + return ret;
- +
- + if (down_interruptible (&fusionee->lock)) {
- + up (&dev->fusionee.lock);
- + return -EINTR;
- + }
- +
- + if (sender && sender != fusionee) {
- + if (down_interruptible (&sender->lock)) {
- + unlock_fusionee (fusionee);
- + up (&dev->fusionee.lock);
- + return -EINTR;
- + }
- + }
- +
- + up (&dev->fusionee.lock);
- +
- +
- + message = kmalloc (sizeof(Message) + msg_size, GFP_KERNEL);
- + if (!message) {
- + if (sender && sender != fusionee)
- + unlock_fusionee (sender);
- + unlock_fusionee (fusionee);
- + return -ENOMEM;
- + }
- +
- + message->data = message + 1;
- +
- + if (msg_type == FMT_CALL || msg_type == FMT_SHMPOOL)
- + memcpy (message->data, msg_data, msg_size);
- + else if (copy_from_user (message->data, msg_data, msg_size)) {
- + kfree (message);
- + if (sender && sender != fusionee)
- + unlock_fusionee (sender);
- + unlock_fusionee (fusionee);
- + return -EFAULT;
- + }
- +
- + message->type = msg_type;
- + message->id = msg_id;
- + message->size = msg_size;
- +
- + fusion_fifo_put (&fusionee->messages, &message->link);
- +
- + fusionee->rcv_total++;
- + if (sender)
- + sender->snd_total++;
- +
- + wake_up_interruptible_all (&fusionee->wait);
- +
- + if (sender && sender != fusionee)
- + unlock_fusionee (sender);
- +
- + unlock_fusionee (fusionee);
- +
- + return 0;
- +}
- +
- +int
- +fusionee_get_messages (FusionDev *dev,
- + Fusionee *fusionee,
- + void *buf,
- + int buf_size,
- + bool block)
- +{
- + int written = 0;
- +
- + if (down_interruptible (&fusionee->lock))
- + return -EINTR;
- +
- + while (!fusionee->messages.count) {
- + if (!block) {
- + unlock_fusionee (fusionee);
- + return -EAGAIN;
- + }
- +
- + fusion_sleep_on (&fusionee->wait, &fusionee->lock, 0);
- +
- + if (signal_pending(current))
- + return -EINTR;
- +
- + if (down_interruptible (&fusionee->lock))
- + return -EINTR;
- + }
- +
- + while (fusionee->messages.count) {
- + FusionReadMessage header;
- + Message *message = (Message*) fusionee->messages.first;
- + int bytes = message->size + sizeof(header);
- +
- + if (bytes > buf_size) {
- + if (!written) {
- + unlock_fusionee (fusionee);
- + return -EMSGSIZE;
- + }
- +
- + break;
- + }
- +
- + header.msg_type = message->type;
- + header.msg_id = message->id;
- + header.msg_size = message->size;
- +
- + if (copy_to_user (buf, &header, sizeof(header)) ||
- + copy_to_user (buf + sizeof(header), message->data, message->size)) {
- + unlock_fusionee (fusionee);
- + return -EFAULT;
- + }
- +
- + written += bytes;
- + buf += bytes;
- + buf_size -= bytes;
- +
- + fusion_fifo_get (&fusionee->messages);
- +
- + kfree (message);
- + }
- +
- + unlock_fusionee (fusionee);
- +
- + return written;
- +}
- +
- +unsigned int
- +fusionee_poll (FusionDev *dev,
- + Fusionee *fusionee,
- + struct file *file,
- + poll_table *wait)
- +{
- + int ret;
- + FusionID id = fusionee->id;
- +
- + poll_wait (file, &fusionee->wait, wait);
- +
- +
- + ret = lock_fusionee (dev, id, &fusionee);
- + if (ret)
- + return POLLERR;
- +
- + if (fusionee->messages.count) {
- + unlock_fusionee (fusionee);
- +
- + return POLLIN | POLLRDNORM;
- + }
- +
- + unlock_fusionee (fusionee);
- +
- + return 0;
- +}
- +
- +int
- +fusionee_kill (FusionDev *dev,
- + Fusionee *fusionee,
- + FusionID target,
- + int signal,
- + int timeout_ms)
- +{
- + long timeout = -1;
- +
- + while (true) {
- + FusionLink *l;
- + int killed = 0;
- +
- + if (down_interruptible (&dev->fusionee.lock))
- + return -EINTR;
- +
- + fusion_list_foreach (l, dev->fusionee.list) {
- + Fusionee *f = (Fusionee*) l;
- +
- + if (f != fusionee && (!target || target == f->id)) {
- + kill_proc (f->pid, signal, 0);
- + killed++;
- + }
- + }
- +
- + if (!killed || timeout_ms < 0) {
- + up (&dev->fusionee.lock);
- + break;
- + }
- +
- + if (timeout_ms) {
- + switch (timeout) {
- + case 0: /* timed out */
- + up (&dev->fusionee.lock);
- + return -ETIMEDOUT;
- +
- + case -1: /* setup timeout */
- + timeout = (timeout_ms * HZ + 500) / 1000;
- + if (!timeout)
- + timeout = 1;
- +
- + /* fall through */
- +
- + default:
- + fusion_sleep_on (&dev->fusionee.wait,
- + &dev->fusionee.lock, &timeout);
- + break;
- + }
- + }
- + else
- + fusion_sleep_on (&dev->fusionee.wait, &dev->fusionee.lock, NULL);
- +
- + if (signal_pending(current))
- + return -EINTR;
- + }
- +
- + return 0;
- +}
- +
- +void
- +fusionee_destroy (FusionDev *dev,
- + Fusionee *fusionee)
- +{
- + /* Lock list. */
- + down (&dev->fusionee.lock);
- +
- + /* Lock fusionee. */
- + down (&fusionee->lock);
- +
- + /* Remove from list. */
- + fusion_list_remove (&dev->fusionee.list, &fusionee->link);
- +
- + /* Wake up waiting killer. */
- + wake_up_interruptible_all (&dev->fusionee.wait);
- +
- + /* Unlock list. */
- + up (&dev->fusionee.lock);
- +
- +
- + /* Release locks, references, ... */
- + fusion_call_destroy_all (dev, fusionee->id);
- + fusion_skirmish_dismiss_all (dev, fusionee->id);
- + fusion_reactor_detach_all (dev, fusionee->id);
- + fusion_property_cede_all (dev, fusionee->id);
- + fusion_ref_clear_all_local (dev, fusionee->id);
- + fusion_shmpool_detach_all (dev, fusionee->id);
- +
- + /* Free all pending messages. */
- + while (fusionee->messages.count) {
- + Message *message = (Message*) fusion_fifo_get (&fusionee->messages);
- +
- + kfree (message);
- + }
- +
- + /* Unlock fusionee. */
- + up (&fusionee->lock);
- +
- +
- + /* Free fusionee data. */
- + kfree (fusionee);
- +}
- +
- +FusionID
- +fusionee_id( const Fusionee *fusionee )
- +{
- + return fusionee->id;
- +}
- +
- +/******************************************************************************/
- +
- +static int
- +lookup_fusionee (FusionDev *dev,
- + FusionID id,
- + Fusionee **ret_fusionee)
- +{
- + FusionLink *l;
- +
- + if (down_interruptible (&dev->fusionee.lock))
- + return -EINTR;
- +
- + fusion_list_foreach (l, dev->fusionee.list) {
- + Fusionee *fusionee = (Fusionee *) l;
- +
- + if (fusionee->id == id) {
- + *ret_fusionee = fusionee;
- + return 0;
- + }
- + }
- +
- + up (&dev->fusionee.lock);
- +
- + return -EINVAL;
- +}
- +
- +static int
- +lock_fusionee (FusionDev *dev,
- + FusionID id,
- + Fusionee **ret_fusionee)
- +{
- + int ret;
- + Fusionee *fusionee;
- +
- + ret = lookup_fusionee (dev, id, &fusionee);
- + if (ret)
- + return ret;
- +
- + fusion_list_move_to_front (&dev->fusionee.list, &fusionee->link);
- +
- + if (down_interruptible (&fusionee->lock)) {
- + up (&dev->fusionee.lock);
- + return -EINTR;
- + }
- +
- + up (&dev->fusionee.lock);
- +
- + *ret_fusionee = fusionee;
- +
- + return 0;
- +}
- +
- +static void
- +unlock_fusionee (Fusionee *fusionee)
- +{
- + up (&fusionee->lock);
- +}
- +
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/fusionee.h linux-2.6.22.1/drivers/char/fusion/fusionee.h
- --- linux-2.6.22.1-0rig/drivers/char/fusion/fusionee.h 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/fusionee.h 2007-01-23 22:19:25.000000000 +0100
- @@ -0,0 +1,75 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifndef __FUSIONEE_H__
- +#define __FUSIONEE_H__
- +
- +#include <linux/poll.h>
- +#include <linux/fusion.h>
- +
- +#include "fusiondev.h"
- +#include "types.h"
- +
- +/* module init/cleanup */
- +
- +int fusionee_init (FusionDev *dev);
- +void fusionee_deinit (FusionDev *dev);
- +
- +
- +/* internal functions */
- +
- +int fusionee_new (FusionDev *dev,
- + bool force_slave,
- + Fusionee **ret_fusionee);
- +
- +int fusionee_enter (FusionDev *dev,
- + FusionEnter *enter,
- + Fusionee *fusionee);
- +
- +int fusionee_fork (FusionDev *dev,
- + FusionFork *fork,
- + Fusionee *fusionee);
- +
- +int fusionee_send_message (FusionDev *dev,
- + Fusionee *fusionee,
- + FusionID recipient,
- + FusionMessageType msg_type,
- + int msg_id,
- + int msg_size,
- + const void *msg_data);
- +
- +int fusionee_get_messages (FusionDev *dev,
- + Fusionee *fusionee,
- + void *buf,
- + int buf_size,
- + bool block);
- +
- +unsigned
- +int fusionee_poll (FusionDev *dev,
- + Fusionee *fusionee,
- + struct file *file,
- + poll_table *wait);
- +
- +int fusionee_kill (FusionDev *dev,
- + Fusionee *fusionee,
- + FusionID target,
- + int signal,
- + int timeout_ms);
- +
- +void fusionee_destroy (FusionDev *dev,
- + Fusionee *fusionee);
- +
- +FusionID fusionee_id( const Fusionee *fusionee );
- +
- +#endif
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/Kconfig linux-2.6.22.1/drivers/char/fusion/Kconfig
- --- linux-2.6.22.1-0rig/drivers/char/fusion/Kconfig 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/Kconfig 2007-08-12 19:33:38.000000000 +0200
- @@ -0,0 +1,8 @@
- +config FUSION_DEVICE
- + tristate "Fusion device for DirectFB"
- + default m
- + ---help---
- + The fusion device is a software device allowing the DirectFB
- + (Direct Frame Buffer) to support multiple applications
- + It is safe to say N unless you need to run several DirectFB
- + applications concurrently.
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/list.c linux-2.6.22.1/drivers/char/fusion/list.c
- --- linux-2.6.22.1-0rig/drivers/char/fusion/list.c 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/list.c 2003-06-16 19:47:03.000000000 +0200
- @@ -0,0 +1,62 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#include <linux/types.h>
- +
- +#include "list.h"
- +
- +void
- +fusion_list_prepend (FusionLink **list, FusionLink *link)
- +{
- + link->prev = NULL;
- + link->next = *list;
- +
- + if (*list)
- + (*list)->prev = link;
- +
- + *list = link;
- +}
- +
- +void
- +fusion_list_remove (FusionLink **list, FusionLink *link)
- +{
- + if (link->prev)
- + link->prev->next = link->next;
- + else
- + *list = link->next;
- +
- + if (link->next)
- + link->next->prev = link->prev;
- +
- + link->next = link->prev = NULL;
- +}
- +
- +void
- +fusion_list_move_to_front (FusionLink **list, FusionLink *link)
- +{
- + if (*list == link)
- + return;
- +
- + link->prev->next = link->next;
- +
- + if (link->next)
- + link->next->prev = link->prev;
- +
- + link->prev = NULL;
- + link->next = *list;
- +
- + (*list)->prev = link;
- +
- + *list = link;
- +}
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/list.h linux-2.6.22.1/drivers/char/fusion/list.h
- --- linux-2.6.22.1-0rig/drivers/char/fusion/list.h 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/list.h 2004-08-17 19:24:36.000000000 +0200
- @@ -0,0 +1,39 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifndef __FUSION__LIST_H__
- +#define __FUSION__LIST_H__
- +
- +typedef struct _FusionLink {
- + struct _FusionLink *next;
- + struct _FusionLink *prev;
- +} FusionLink;
- +
- +void fusion_list_prepend (FusionLink **list, FusionLink *link);
- +void fusion_list_remove (FusionLink **list, FusionLink *link);
- +void fusion_list_move_to_front (FusionLink **list, FusionLink *link);
- +
- +
- +#define fusion_list_foreach(elem, list) \
- + for (elem = (void*)(list); \
- + elem; \
- + elem = (void*)(((FusionLink*)(elem))->next))
- +
- +#define fusion_list_foreach_safe(elem, temp, list) \
- + for (elem = (void*)(list), temp = ((elem) ? (void*)(((FusionLink*)(elem))->next) : NULL); \
- + elem; \
- + elem = (void*)(temp), temp = ((elem) ? (void*)(((FusionLink*)(elem))->next) : NULL))
- +
- +#endif /* __FUSION__LIST_H__ */
- +
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/Makefile linux-2.6.22.1/drivers/char/fusion/Makefile
- --- linux-2.6.22.1-0rig/drivers/char/fusion/Makefile 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/Makefile 2005-10-29 02:38:05.000000000 +0200
- @@ -0,0 +1,3 @@
- +obj-$(CONFIG_FUSION_DEVICE) += fusion.o
- +
- +fusion-y := call.o entries.o fifo.o fusiondev.o fusionee.o list.o property.o reactor.o ref.o skirmish.o shmpool.o
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/property.c linux-2.6.22.1/drivers/char/fusion/property.c
- --- linux-2.6.22.1-0rig/drivers/char/fusion/property.c 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/property.c 2007-01-20 05:03:01.000000000 +0100
- @@ -0,0 +1,340 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifdef HAVE_LINUX_CONFIG_H
- +#include <linux/config.h>
- +#endif
- +#include <linux/types.h>
- +#include <linux/kernel.h>
- +#include <linux/slab.h>
- +#include <linux/smp_lock.h>
- +#include <linux/sched.h>
- +
- +#ifndef yield
- +#define yield schedule
- +#endif
- +
- +#include <linux/fusion.h>
- +
- +#include "entries.h"
- +#include "fusiondev.h"
- +#include "fusionee.h"
- +#include "list.h"
- +#include "property.h"
- +
- +typedef enum {
- + FUSION_PROPERTY_AVAILABLE = 0,
- + FUSION_PROPERTY_LEASED,
- + FUSION_PROPERTY_PURCHASED
- +} FusionPropertyState;
- +
- +typedef struct {
- + FusionEntry entry;
- +
- + FusionPropertyState state;
- + int fusion_id; /* non-zero if leased/purchased */
- + unsigned long purchase_stamp;
- + int lock_pid;
- + int count; /* lock counter */
- +} FusionProperty;
- +
- +static int
- +fusion_property_print( FusionEntry *entry,
- + void *ctx,
- + char *buf )
- +{
- + FusionProperty *property = (FusionProperty*) entry;
- +
- + if (property->state != FUSION_PROPERTY_AVAILABLE) {
- + return sprintf( buf, "%s by 0x%08x (%d) %dx\n",
- + property->state == FUSION_PROPERTY_LEASED ? "leased" : "purchased",
- + property->fusion_id, property->lock_pid, property->count );
- + }
- +
- + return sprintf( buf, "\n" );
- +}
- +
- +FUSION_ENTRY_CLASS( FusionProperty, property, NULL, NULL, fusion_property_print )
- +
- +/******************************************************************************/
- +
- +int
- +fusion_property_init( FusionDev *dev )
- +{
- + fusion_entries_init( &dev->properties, &property_class, dev );
- +
- + create_proc_read_entry( "properties", 0, dev->proc_dir,
- + fusion_entries_read_proc, &dev->properties );
- +
- + return 0;
- +}
- +
- +void
- +fusion_property_deinit( FusionDev *dev )
- +{
- + remove_proc_entry( "properties", dev->proc_dir );
- +
- + fusion_entries_deinit( &dev->properties );
- +}
- +
- +/******************************************************************************/
- +
- +int
- +fusion_property_new( FusionDev *dev, int *ret_id )
- +{
- + return fusion_entry_create( &dev->properties, ret_id, NULL );
- +}
- +
- +int
- +fusion_property_lease( FusionDev *dev, int id, int fusion_id )
- +{
- + int ret;
- + FusionProperty *property;
- + long timeout = -1;
- +
- + dev->stat.property_lease_purchase++;
- +
- + ret = fusion_property_lock( &dev->properties, id, false, &property );
- + if (ret)
- + return ret;
- +
- + while (true) {
- + switch (property->state) {
- + case FUSION_PROPERTY_AVAILABLE:
- + property->state = FUSION_PROPERTY_LEASED;
- + property->fusion_id = fusion_id;
- + property->lock_pid = current->pid;
- + property->count = 1;
- +
- + fusion_property_unlock( property );
- + return 0;
- +
- + case FUSION_PROPERTY_LEASED:
- + if (property->lock_pid == current->pid) {
- + property->count++;
- +
- + fusion_property_unlock( property );
- + return 0;
- + }
- +
- + ret = fusion_property_wait( property, NULL );
- + if (ret)
- + return ret;
- +
- + break;
- +
- + case FUSION_PROPERTY_PURCHASED:
- + if (property->lock_pid == current->pid) {
- + fusion_property_unlock( property );
- + return -EIO;
- + }
- +
- + if (timeout == -1) {
- + if (jiffies - property->purchase_stamp > HZ / 10) {
- + fusion_property_unlock( property );
- + return -EAGAIN;
- + }
- +
- + timeout = HZ / 10;
- + }
- +
- + ret = fusion_property_wait( property, &timeout );
- + if (ret)
- + return ret;
- +
- + break;
- +
- + default:
- + BUG();
- + }
- + }
- +
- + BUG();
- +
- + /* won't reach this */
- + return -1;
- +}
- +
- +int
- +fusion_property_purchase( FusionDev *dev, int id, int fusion_id )
- +{
- + int ret;
- + FusionProperty *property;
- + signed long timeout = -1;
- +
- + dev->stat.property_lease_purchase++;
- +
- + ret = fusion_property_lock( &dev->properties, id, false, &property );
- + if (ret)
- + return ret;
- +
- + while (true) {
- + switch (property->state) {
- + case FUSION_PROPERTY_AVAILABLE:
- + property->state = FUSION_PROPERTY_PURCHASED;
- + property->fusion_id = fusion_id;
- + property->purchase_stamp = jiffies;
- + property->lock_pid = current->pid;
- + property->count = 1;
- +
- + fusion_property_notify( property, true );
- +
- + fusion_property_unlock( property );
- + return 0;
- +
- + case FUSION_PROPERTY_LEASED:
- + if (property->lock_pid == current->pid) {
- + fusion_property_unlock( property );
- + return -EIO;
- + }
- +
- + ret = fusion_property_wait( property, NULL );
- + if (ret)
- + return ret;
- +
- + break;
- +
- + case FUSION_PROPERTY_PURCHASED:
- + if (property->lock_pid == current->pid) {
- + property->count++;
- +
- + fusion_property_unlock( property );
- + return 0;
- + }
- +
- + if (timeout == -1) {
- + if (jiffies - property->purchase_stamp > HZ) {
- + fusion_property_unlock( property );
- + return -EAGAIN;
- + }
- +
- + timeout = HZ;
- + }
- +
- + ret = fusion_property_wait( property, &timeout );
- + if (ret)
- + return ret;
- +
- + break;
- +
- + default:
- + BUG();
- + }
- + }
- +
- + BUG();
- +
- + /* won't reach this */
- + return -1;
- +}
- +
- +int
- +fusion_property_cede( FusionDev *dev, int id, int fusion_id )
- +{
- + int ret;
- + FusionProperty *property;
- + bool purchased;
- +
- + dev->stat.property_cede++;
- +
- + ret = fusion_property_lock( &dev->properties, id, false, &property );
- + if (ret)
- + return ret;
- +
- + if (property->lock_pid != current->pid) {
- + fusion_property_unlock( property );
- + return -EIO;
- + }
- +
- + if (--property->count) {
- + fusion_property_unlock( property );
- + return 0;
- + }
- +
- + purchased = (property->state == FUSION_PROPERTY_PURCHASED);
- +
- + property->state = FUSION_PROPERTY_AVAILABLE;
- + property->fusion_id = 0;
- + property->lock_pid = 0;
- +
- + fusion_property_notify( property, true );
- +
- + fusion_property_unlock( property );
- +
- + if (purchased)
- + yield();
- +
- + return 0;
- +}
- +
- +int
- +fusion_property_holdup( FusionDev *dev, int id, Fusionee *fusionee )
- +{
- + int ret;
- + FusionProperty *property;
- + FusionID fusion_id = fusionee_id( fusionee );
- +
- + if (fusion_id > 1)
- + return -EPERM;
- +
- + ret = fusion_property_lock( &dev->properties, id, false, &property );
- + if (ret)
- + return ret;
- +
- + if (property->state == FUSION_PROPERTY_PURCHASED) {
- + if (property->fusion_id == fusion_id) {
- + fusion_property_unlock( property );
- + return -EIO;
- + }
- +
- + fusionee_kill( dev, fusionee, property->fusion_id, SIGKILL, -1 );
- + }
- +
- + fusion_property_unlock( property );
- +
- + return 0;
- +}
- +
- +int
- +fusion_property_destroy( FusionDev *dev, int id )
- +{
- + return fusion_entry_destroy( &dev->properties, id );
- +}
- +
- +void
- +fusion_property_cede_all( FusionDev *dev, int fusion_id )
- +{
- + FusionLink *l;
- +
- + down( &dev->properties.lock );
- +
- + fusion_list_foreach (l, dev->properties.list) {
- + FusionProperty *property = (FusionProperty *) l;
- +
- + down( &property->entry.lock );
- +
- + if (property->fusion_id == fusion_id) {
- + property->state = FUSION_PROPERTY_AVAILABLE;
- + property->fusion_id = 0;
- + property->lock_pid = 0;
- +
- + wake_up_interruptible_all (&property->entry.wait);
- + }
- +
- + up( &property->entry.lock );
- + }
- +
- + up( &dev->properties.lock );
- +}
- +
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/property.h linux-2.6.22.1/drivers/char/fusion/property.h
- --- linux-2.6.22.1-0rig/drivers/char/fusion/property.h 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/property.h 2007-01-20 05:03:01.000000000 +0100
- @@ -0,0 +1,58 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifndef __FUSION__PROPERTY_H__
- +#define __FUSION__PROPERTY_H__
- +
- +#include "fusiondev.h"
- +#include "types.h"
- +
- +
- +/* module init/cleanup */
- +
- +int fusion_property_init (FusionDev *dev);
- +void fusion_property_deinit (FusionDev *dev);
- +
- +
- +/* public API */
- +
- +int fusion_property_new (FusionDev *dev,
- + int *ret_id);
- +
- +int fusion_property_lease (FusionDev *dev,
- + int id,
- + int fusion_id);
- +
- +int fusion_property_purchase (FusionDev *dev,
- + int id,
- + int fusion_id);
- +
- +int fusion_property_cede (FusionDev *dev,
- + int id,
- + int fusion_id);
- +
- +int fusion_property_holdup (FusionDev *dev,
- + int id,
- + Fusionee *fusionee);
- +
- +int fusion_property_destroy (FusionDev *dev,
- + int id);
- +
- +
- +/* internal functions */
- +
- +void fusion_property_cede_all (FusionDev *dev,
- + int fusion_id);
- +
- +#endif
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/reactor.c linux-2.6.22.1/drivers/char/fusion/reactor.c
- --- linux-2.6.22.1-0rig/drivers/char/fusion/reactor.c 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/reactor.c 2007-01-20 05:03:01.000000000 +0100
- @@ -0,0 +1,367 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifdef HAVE_LINUX_CONFIG_H
- +#include <linux/config.h>
- +#endif
- +#include <linux/types.h>
- +#include <linux/kernel.h>
- +#include <linux/slab.h>
- +#include <linux/smp_lock.h>
- +#include <linux/sched.h>
- +
- +#include <linux/fusion.h>
- +
- +#include "fusiondev.h"
- +#include "fusionee.h"
- +#include "list.h"
- +#include "reactor.h"
- +
- +typedef struct {
- + FusionLink link;
- +
- + int fusion_id;
- +
- + int count; /* number of attach calls */
- +} ReactorNode;
- +
- +typedef struct {
- + FusionEntry entry;
- +
- + FusionLink *nodes;
- +
- + int dispatch_count;
- +
- + bool destroyed;
- +} FusionReactor;
- +
- +/******************************************************************************/
- +
- +static int fork_node ( FusionReactor *reactor,
- + FusionID fusion_id,
- + FusionID from_id );
- +
- +static void free_all_nodes( FusionReactor *reactor );
- +
- +/******************************************************************************/
- +
- +static inline ReactorNode *
- +get_node (FusionReactor *reactor,
- + FusionID fusion_id)
- +{
- + ReactorNode *node;
- +
- + fusion_list_foreach (node, reactor->nodes) {
- + if (node->fusion_id == fusion_id)
- + return node;
- + }
- +
- + return NULL;
- +}
- +
- +/******************************************************************************/
- +
- +static void
- +fusion_reactor_destruct( FusionEntry *entry,
- + void *ctx )
- +{
- + FusionReactor *reactor = (FusionReactor*) entry;
- +
- + free_all_nodes( reactor );
- +}
- +
- +static int
- +fusion_reactor_print( FusionEntry *entry,
- + void *ctx,
- + char *buf )
- +{
- + int num = 0;
- + FusionReactor *reactor = (FusionReactor*) entry;
- + FusionLink *node = reactor->nodes;
- +
- + fusion_list_foreach (node, reactor->nodes) {
- + num++;
- + }
- +
- + return sprintf( buf, "%5dx dispatch, %d nodes%s\n", reactor->dispatch_count, num,
- + reactor->destroyed ? " DESTROYED" : "" );
- +}
- +
- +
- +FUSION_ENTRY_CLASS( FusionReactor, reactor, NULL,
- + fusion_reactor_destruct, fusion_reactor_print )
- +
- +/******************************************************************************/
- +
- +int
- +fusion_reactor_init (FusionDev *dev)
- +{
- + fusion_entries_init( &dev->reactor, &reactor_class, dev );
- +
- + create_proc_read_entry( "reactors", 0, dev->proc_dir,
- + fusion_entries_read_proc, &dev->reactor );
- +
- + return 0;
- +}
- +
- +void
- +fusion_reactor_deinit (FusionDev *dev)
- +{
- + remove_proc_entry ("reactors", dev->proc_dir);
- +
- + fusion_entries_deinit( &dev->reactor );
- +}
- +
- +/******************************************************************************/
- +
- +int
- +fusion_reactor_new (FusionDev *dev, int *ret_id)
- +{
- + return fusion_entry_create( &dev->reactor, ret_id, NULL );
- +}
- +
- +int
- +fusion_reactor_attach (FusionDev *dev, int id, FusionID fusion_id)
- +{
- + int ret;
- + ReactorNode *node;
- + FusionReactor *reactor;
- +
- + ret = fusion_reactor_lock( &dev->reactor, id, false, &reactor );
- + if (ret)
- + return ret;
- +
- + if (reactor->destroyed) {
- + fusion_reactor_unlock( reactor );
- + return -EIDRM;
- + }
- +
- + dev->stat.reactor_attach++;
- +
- + node = get_node (reactor, fusion_id);
- + if (!node) {
- + node = kmalloc (sizeof(ReactorNode), GFP_KERNEL);
- + if (!node) {
- + fusion_reactor_unlock( reactor );
- + return -ENOMEM;
- + }
- +
- + node->fusion_id = fusion_id;
- + node->count = 1;
- +
- + fusion_list_prepend (&reactor->nodes, &node->link);
- + }
- + else
- + node->count++;
- +
- + fusion_reactor_unlock( reactor );
- +
- + return 0;
- +}
- +
- +int
- +fusion_reactor_detach (FusionDev *dev, int id, FusionID fusion_id)
- +{
- + int ret;
- + ReactorNode *node;
- + FusionReactor *reactor;
- +
- + ret = fusion_reactor_lock( &dev->reactor, id, true, &reactor );
- + if (ret)
- + return ret;
- +
- + dev->stat.reactor_detach++;
- +
- + node = get_node (reactor, fusion_id);
- + if (!node) {
- + fusion_reactor_unlock( reactor );
- + up( &dev->reactor.lock );
- + return -EIO;
- + }
- +
- + if (! --node->count) {
- + fusion_list_remove (&reactor->nodes, &node->link);
- + kfree (node);
- + }
- +
- + if (reactor->destroyed && !reactor->nodes)
- + fusion_entry_destroy_locked( &dev->reactor, &reactor->entry );
- + else
- + fusion_reactor_unlock( reactor );
- +
- + up( &dev->reactor.lock );
- +
- + return 0;
- +}
- +
- +int
- +fusion_reactor_dispatch (FusionDev *dev, int id, Fusionee *fusionee,
- + int msg_size, const void *msg_data)
- +{
- + int ret;
- + FusionLink *l;
- + FusionReactor *reactor;
- + FusionID fusion_id = fusionee ? fusionee_id( fusionee ) : 0;
- +
- + ret = fusion_reactor_lock( &dev->reactor, id, false, &reactor );
- + if (ret)
- + return ret;
- +
- + if (reactor->destroyed) {
- + fusion_reactor_unlock( reactor );
- + return -EIDRM;
- + }
- +
- + reactor->dispatch_count++;
- +
- + fusion_list_foreach (l, reactor->nodes) {
- + ReactorNode *node = (ReactorNode *) l;
- +
- + if (node->fusion_id == fusion_id)
- + continue;
- +
- + fusionee_send_message (dev, fusionee, node->fusion_id, FMT_REACTOR,
- + reactor->entry.id, msg_size, msg_data);
- + }
- +
- + fusion_reactor_unlock( reactor );
- +
- + return 0;
- +}
- +
- +int
- +fusion_reactor_destroy (FusionDev *dev, int id)
- +{
- + int ret;
- + FusionReactor *reactor;
- +
- + ret = fusion_reactor_lock( &dev->reactor, id, true, &reactor );
- + if (ret)
- + return ret;
- +
- + if (reactor->destroyed) {
- + fusion_reactor_unlock( reactor );
- + up( &dev->reactor.lock );
- + return -EIDRM;
- + }
- +
- + reactor->destroyed = true;
- +
- + if (!reactor->nodes)
- + fusion_entry_destroy_locked( &dev->reactor, &reactor->entry );
- + else
- + fusion_reactor_unlock( reactor );
- +
- + up( &dev->reactor.lock );
- +
- + return 0;
- +}
- +
- +void
- +fusion_reactor_detach_all (FusionDev *dev, FusionID fusion_id)
- +{
- + FusionLink *l, *n;
- +
- + down (&dev->reactor.lock);
- +
- + fusion_list_foreach_safe (l, n, dev->reactor.list) {
- + ReactorNode *node;
- + FusionReactor *reactor = (FusionReactor *) l;
- +
- + down (&reactor->entry.lock);
- +
- + fusion_list_foreach (node, reactor->nodes) {
- + if (node->fusion_id == fusion_id) {
- + fusion_list_remove (&reactor->nodes, &node->link);
- + kfree (node);
- + break;
- + }
- + }
- +
- + if (reactor->destroyed && !reactor->nodes)
- + fusion_entry_destroy_locked( &dev->reactor, &reactor->entry );
- + else
- + up (&reactor->entry.lock);
- + }
- +
- + up (&dev->reactor.lock);
- +}
- +
- +int
- +fusion_reactor_fork_all (FusionDev *dev, FusionID fusion_id, FusionID from_id)
- +{
- + FusionLink *l;
- + int ret = 0;
- +
- + down (&dev->reactor.lock);
- +
- + fusion_list_foreach (l, dev->reactor.list) {
- + FusionReactor *reactor = (FusionReactor *) l;
- +
- + ret = fork_node (reactor, fusion_id, from_id);
- + if (ret)
- + break;
- + }
- +
- + up (&dev->reactor.lock);
- +
- + return ret;
- +}
- +
- +/******************************************************************************/
- +
- +static int
- +fork_node (FusionReactor *reactor, FusionID fusion_id, FusionID from_id)
- +{
- + ReactorNode *node;
- +
- + down (&reactor->entry.lock);
- +
- + fusion_list_foreach (node, reactor->nodes) {
- + if (node->fusion_id == from_id) {
- + ReactorNode *new_node;
- +
- + new_node = kmalloc (sizeof(ReactorNode), GFP_KERNEL);
- + if (!new_node) {
- + up (&reactor->entry.lock);
- + return -ENOMEM;
- + }
- +
- + new_node->fusion_id = fusion_id;
- + new_node->count = node->count;
- +
- + fusion_list_prepend (&reactor->nodes, &new_node->link);
- +
- + break;
- + }
- + }
- +
- + up (&reactor->entry.lock);
- +
- + return 0;
- +}
- +
- +static void
- +free_all_nodes (FusionReactor *reactor)
- +
- +{
- + FusionLink *n;
- + ReactorNode *node;
- +
- + fusion_list_foreach_safe (node, n, reactor->nodes) {
- + kfree (node);
- + }
- +
- + reactor->nodes = NULL;
- +}
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/reactor.h linux-2.6.22.1/drivers/char/fusion/reactor.h
- --- linux-2.6.22.1-0rig/drivers/char/fusion/reactor.h 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/reactor.h 2007-01-20 05:03:01.000000000 +0100
- @@ -0,0 +1,59 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifndef __FUSION__REACTOR_H__
- +#define __FUSION__REACTOR_H__
- +
- +#include "fusiondev.h"
- +#include "types.h"
- +
- +
- +/* module init/cleanup */
- +
- +int fusion_reactor_init (FusionDev *dev);
- +void fusion_reactor_deinit (FusionDev *dev);
- +
- +
- +/* public API */
- +
- +int fusion_reactor_new (FusionDev *dev,
- + int *id);
- +
- +int fusion_reactor_attach (FusionDev *dev,
- + int id,
- + FusionID fusion_id);
- +
- +int fusion_reactor_detach (FusionDev *dev,
- + int id,
- + FusionID fusion_id);
- +
- +int fusion_reactor_dispatch (FusionDev *dev,
- + int id,
- + Fusionee *fusionee,
- + int msg_size,
- + const void *msg_data);
- +
- +int fusion_reactor_destroy (FusionDev *dev,
- + int id);
- +
- +
- +/* internal functions */
- +
- +void fusion_reactor_detach_all (FusionDev *dev,
- + FusionID fusion_id);
- +
- +int fusion_reactor_fork_all (FusionDev *dev,
- + FusionID fusion_id,
- + FusionID from_id);
- +#endif
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/ref.c linux-2.6.22.1/drivers/char/fusion/ref.c
- --- linux-2.6.22.1-0rig/drivers/char/fusion/ref.c 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/ref.c 2007-01-06 14:09:45.000000000 +0100
- @@ -0,0 +1,680 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifdef HAVE_LINUX_CONFIG_H
- +#include <linux/config.h>
- +#endif
- +#include <linux/types.h>
- +#include <linux/kernel.h>
- +#include <linux/slab.h>
- +#include <linux/smp_lock.h>
- +#include <linux/sched.h>
- +
- +#include <linux/fusion.h>
- +
- +#include "fusiondev.h"
- +#include "list.h"
- +#include "call.h"
- +#include "ref.h"
- +
- +typedef struct __Fusion_FusionRef FusionRef;
- +
- +typedef struct {
- + FusionLink link;
- + FusionID fusion_id;
- + int refs;
- +} LocalRef;
- +
- +typedef struct {
- + FusionLink link;
- + FusionRef *ref;
- +} Inheritor;
- +
- +struct __Fusion_FusionRef {
- + FusionEntry entry;
- +
- + int global;
- + int local;
- +
- + int locked; /* non-zero fusion id of lock owner */
- +
- + bool watched; /* true if watch has been installed */
- + int call_id; /* id of call registered with a watch */
- + int call_arg; /* optional call parameter */
- +
- + FusionRef *inherited;
- + FusionLink *inheritors;
- +
- + FusionLink *local_refs;
- +};
- +
- +/**********************************************************************************************************************/
- +
- +static int add_local ( FusionRef *ref, FusionID fusion_id, int add );
- +static void clear_local ( FusionDev *dev, FusionRef *ref, FusionID fusion_id );
- +static int fork_local ( FusionDev *dev, FusionRef *ref, FusionID fusion_id, FusionID from_id );
- +static void free_all_local ( FusionRef *ref );
- +
- +static int propagate_local ( FusionDev *dev, FusionRef *ref, int diff );
- +
- +static void notify_ref ( FusionDev *dev, FusionRef *ref );
- +
- +static int add_inheritor ( FusionRef *ref, FusionRef *from );
- +static void remove_inheritor( FusionRef *ref, FusionRef *from );
- +static void drop_inheritors ( FusionDev *dev, FusionRef *ref );
- +
- +/**********************************************************************************************************************/
- +
- +static void
- +fusion_ref_destruct( FusionEntry *entry,
- + void *ctx )
- +{
- + FusionRef *ref = (FusionRef*) entry;
- + FusionDev *dev = (FusionDev*) ctx;
- +
- + drop_inheritors( dev, ref );
- +
- + if (ref->inherited)
- + remove_inheritor( ref, ref->inherited );
- +
- + free_all_local( ref );
- +}
- +
- +static int
- +fusion_ref_print( FusionEntry *entry,
- + void *ctx,
- + char *buf )
- +{
- + FusionRef *ref = (FusionRef*) entry;
- +
- + if (ref->locked)
- + return sprintf( buf, "%2d %2d (locked by %d)\n", ref->global, ref->local, ref->locked );
- +
- + return sprintf( buf, "%2d %2d\n", ref->global, ref->local );
- +}
- +
- +FUSION_ENTRY_CLASS( FusionRef, ref, NULL,
- + fusion_ref_destruct, fusion_ref_print );
- +
- +/**********************************************************************************************************************/
- +
- +int
- +fusion_ref_init( FusionDev *dev )
- +{
- + fusion_entries_init( &dev->ref, &ref_class, dev );
- +
- + create_proc_read_entry( "refs", 0, dev->proc_dir, fusion_entries_read_proc, &dev->ref );
- +
- + return 0;
- +}
- +
- +void
- +fusion_ref_deinit( FusionDev *dev )
- +{
- + remove_proc_entry( "refs", dev->proc_dir );
- +
- + fusion_entries_deinit( &dev->ref );
- +}
- +
- +/**********************************************************************************************************************/
- +
- +int
- +fusion_ref_new( FusionDev *dev, int *ret_id )
- +{
- + return fusion_entry_create( &dev->ref, ret_id, NULL );
- +}
- +
- +int
- +fusion_ref_up (FusionDev *dev, int id, FusionID fusion_id)
- +{
- + int ret;
- + FusionRef *ref;
- +
- + ret = fusion_ref_lock( &dev->ref, id, true, &ref );
- + if (ret)
- + return ret;
- +
- + dev->stat.ref_up++;
- +
- + if (ref->locked) {
- + ret = -EAGAIN;
- + goto out;
- + }
- +
- + if (fusion_id) {
- + ret = add_local (ref, fusion_id, 1);
- + if (ret)
- + goto out;
- +
- + ret = propagate_local( dev, ref, 1 );
- + }
- + else
- + ref->global++;
- +
- +
- +out:
- + fusion_ref_unlock( ref );
- + up( &dev->ref.lock );
- +
- + return ret;
- +}
- +
- +int
- +fusion_ref_down (FusionDev *dev, int id, FusionID fusion_id)
- +{
- + int ret;
- + FusionRef *ref;
- +
- + ret = fusion_ref_lock( &dev->ref, id, true, &ref );
- + if (ret)
- + return ret;
- +
- + dev->stat.ref_down++;
- +
- + if (ref->locked) {
- + ret = -EAGAIN;
- + goto out;
- + }
- +
- + if (fusion_id) {
- + ret = -EIO;
- + if (!ref->local)
- + goto out;
- +
- + ret = add_local (ref, fusion_id, -1);
- + if (ret)
- + goto out;
- +
- + ret = propagate_local( dev, ref, -1 );
- + }
- + else {
- + if (!ref->global) {
- + ret = -EIO;
- + goto out;
- + }
- +
- + ref->global--;
- +
- + if (ref->local + ref->global == 0)
- + notify_ref (dev, ref);
- + }
- +
- +
- +out:
- + fusion_ref_unlock( ref );
- + up( &dev->ref.lock );
- +
- + return ret;
- +}
- +
- +int
- +fusion_ref_zero_lock (FusionDev *dev, int id, FusionID fusion_id)
- +{
- + int ret;
- + FusionRef *ref;
- +
- + ret = fusion_ref_lock( &dev->ref, id, false, &ref );
- + if (ret)
- + return ret;
- +
- + while (true) {
- + if (ref->watched) {
- + fusion_ref_unlock( ref );
- + return -EACCES;
- + }
- +
- + if (ref->locked) {
- + fusion_ref_unlock( ref );
- + return ref->locked == fusion_id ? -EIO : -EAGAIN;
- + }
- +
- + if (ref->global || ref->local) {
- + ret = fusion_ref_wait( ref, NULL );
- + if (ret)
- + return ret;
- + }
- + else
- + break;
- + }
- +
- + ref->locked = fusion_id;
- +
- + fusion_ref_unlock( ref );
- +
- + return 0;
- +}
- +
- +int
- +fusion_ref_zero_trylock (FusionDev *dev, int id, FusionID fusion_id)
- +{
- + int ret;
- + FusionRef *ref;
- +
- + ret = fusion_ref_lock( &dev->ref, id, false, &ref );
- + if (ret)
- + return ret;
- +
- + if (ref->locked) {
- + fusion_ref_unlock( ref );
- + return ref->locked == fusion_id ? -EIO : -EAGAIN;
- + }
- +
- + if (ref->global || ref->local)
- + ret = -ETOOMANYREFS;
- + else
- + ref->locked = fusion_id;
- +
- + fusion_ref_unlock( ref );
- +
- + return ret;
- +}
- +
- +int
- +fusion_ref_zero_unlock (FusionDev *dev, int id, FusionID fusion_id)
- +{
- + int ret;
- + FusionRef *ref;
- +
- + ret = fusion_ref_lock( &dev->ref, id, false, &ref );
- + if (ret)
- + return ret;
- +
- + if (ref->locked != fusion_id) {
- + fusion_ref_unlock( ref );
- + return -EIO;
- + }
- +
- + ref->locked = 0;
- +
- + fusion_ref_unlock( ref );
- +
- + return 0;
- +}
- +
- +int
- +fusion_ref_stat (FusionDev *dev, int id, int *refs)
- +{
- + int ret;
- + FusionRef *ref;
- +
- + ret = fusion_ref_lock( &dev->ref, id, false, &ref );
- + if (ret)
- + return ret;
- +
- + *refs = ref->global + ref->local;
- +
- + fusion_ref_unlock( ref );
- +
- + return 0;
- +}
- +
- +int
- +fusion_ref_watch (FusionDev *dev,
- + int id,
- + int call_id,
- + int call_arg)
- +{
- + int ret;
- + FusionRef *ref;
- +
- + ret = fusion_ref_lock( &dev->ref, id, false, &ref );
- + if (ret)
- + return ret;
- +
- + if (ref->entry.pid != current->pid) {
- + fusion_ref_unlock( ref );
- + return -EACCES;
- + }
- +
- + if (ref->global + ref->local == 0) {
- + fusion_ref_unlock( ref );
- + return -EIO;
- + }
- +
- + if (ref->watched) {
- + fusion_ref_unlock( ref );
- + return -EBUSY;
- + }
- +
- + ref->watched = true;
- + ref->call_id = call_id;
- + ref->call_arg = call_arg;
- +
- + fusion_ref_notify( ref, true );
- +
- + fusion_ref_unlock( ref );
- +
- + return 0;
- +}
- +
- +int
- +fusion_ref_inherit (FusionDev *dev,
- + int id,
- + int from_id)
- +{
- + int ret;
- + FusionRef *ref;
- + FusionRef *from = NULL;
- +
- + ret = fusion_ref_lock( &dev->ref, id, true, &ref );
- + if (ret)
- + return ret;
- +
- + ret = -EBUSY;
- + if (ref->inherited)
- + goto out;
- +
- + ret = -EINVAL;
- + fusion_list_foreach (from, dev->ref.list) {
- + if (from->entry.id == from_id) {
- + if (down_interruptible( &from->entry.lock )) {
- + ret = -EINTR;
- + from = NULL;
- + }
- +
- + break;
- + }
- + }
- + if (!from)
- + goto out;
- +
- + ret = add_inheritor( ref, from );
- + if (ret)
- + goto out;
- +
- + ret = propagate_local( dev, ref, from->local );
- + if (ret)
- + goto out;
- +
- + ref->inherited = from;
- +
- +out:
- + if (from)
- + up( &from->entry.lock );
- +
- + fusion_ref_unlock( ref );
- + up ( &dev->ref.lock );
- +
- + return ret;
- +}
- +
- +int
- +fusion_ref_destroy (FusionDev *dev, int id)
- +{
- + return fusion_entry_destroy( &dev->ref, id );
- +}
- +
- +void
- +fusion_ref_clear_all_local( FusionDev *dev, FusionID fusion_id )
- +{
- + FusionRef *ref;
- +
- + down( &dev->ref.lock );
- +
- + fusion_list_foreach (ref, dev->ref.list)
- + clear_local( dev, ref, fusion_id );
- +
- + up( &dev->ref.lock );
- +}
- +
- +int
- +fusion_ref_fork_all_local( FusionDev *dev, FusionID fusion_id, FusionID from_id )
- +{
- + FusionRef *ref;
- + int ret = 0;
- +
- + down( &dev->ref.lock );
- +
- + fusion_list_foreach (ref, dev->ref.list) {
- + ret = fork_local( dev, ref, fusion_id, from_id );
- + if (ret)
- + break;
- + }
- +
- + up( &dev->ref.lock );
- +
- + return ret;
- +}
- +
- +/**********************************************************************************************************************/
- +
- +static int
- +add_local (FusionRef *ref, FusionID fusion_id, int add)
- +{
- + FusionLink *l;
- + LocalRef *local;
- +
- + fusion_list_foreach (l, ref->local_refs) {
- + local = (LocalRef *) l;
- +
- + if (local->fusion_id == fusion_id) {
- + fusion_list_move_to_front( &ref->local_refs, l );
- +
- + if (local->refs + add < 0)
- + return -EIO;
- +
- + local->refs += add;
- + return 0;
- + }
- + }
- +
- + /* Can only create local node if value is positive. */
- + if (add <= 0)
- + return -EIO;
- +
- + local = kmalloc (sizeof(LocalRef), GFP_KERNEL);
- + if (!local)
- + return -ENOMEM;
- +
- + local->fusion_id = fusion_id;
- + local->refs = add;
- +
- + fusion_list_prepend (&ref->local_refs, &local->link);
- +
- + return 0;
- +}
- +
- +static void
- +clear_local (FusionDev *dev, FusionRef *ref, FusionID fusion_id)
- +{
- + FusionLink *l;
- +
- + down (&ref->entry.lock);
- +
- + if (ref->locked == fusion_id) {
- + ref->locked = 0;
- + wake_up_interruptible_all (&ref->entry.wait);
- + }
- +
- + fusion_list_foreach (l, ref->local_refs) {
- + LocalRef *local = (LocalRef *) l;
- +
- + if (local->fusion_id == fusion_id) {
- + if (local->refs)
- + propagate_local( dev, ref, - local->refs );
- +
- + fusion_list_remove( &ref->local_refs, l );
- +
- + kfree (l);
- + break;
- + }
- + }
- +
- + up (&ref->entry.lock);
- +}
- +
- +static int
- +fork_local (FusionDev *dev, FusionRef *ref, FusionID fusion_id, FusionID from_id)
- +{
- + FusionLink *l;
- + int ret = 0;
- +
- + down (&ref->entry.lock);
- +
- + fusion_list_foreach (l, ref->local_refs) {
- + LocalRef *local = (LocalRef *) l;
- +
- + if (local->fusion_id == from_id) {
- + if (local->refs) {
- + LocalRef *new_local;
- +
- + new_local = kmalloc (sizeof(LocalRef), GFP_KERNEL);
- + if (!new_local) {
- + ret = -ENOMEM;
- + break;
- + }
- +
- + new_local->fusion_id = fusion_id;
- + new_local->refs = local->refs;
- +
- + fusion_list_prepend( &ref->local_refs, &new_local->link );
- +
- + propagate_local( dev, ref, local->refs );
- + }
- + break;
- + }
- + }
- +
- + up (&ref->entry.lock);
- +
- + return ret;
- +}
- +
- +static void
- +free_all_local (FusionRef *ref)
- +{
- + FusionLink *l = ref->local_refs;
- +
- + while (l) {
- + FusionLink *next = l->next;
- +
- + kfree (l);
- +
- + l = next;
- + }
- +
- + ref->local_refs = NULL;
- +}
- +
- +static void
- +notify_ref (FusionDev *dev, FusionRef *ref)
- +{
- + if (ref->watched) {
- + FusionCallExecute execute;
- +
- + execute.call_id = ref->call_id;
- + execute.call_arg = ref->call_arg;
- + execute.call_ptr = NULL;
- +
- + fusion_call_execute (dev, 0, &execute);
- + }
- + else
- + wake_up_interruptible_all (&ref->entry.wait);
- +}
- +
- +static int
- +propagate_local( FusionDev *dev, FusionRef *ref, int diff )
- +{
- + FusionLink *l;
- +
- + /* Recurse into inheritors. */
- + fusion_list_foreach (l, ref->inheritors) {
- + FusionRef *inheritor = ((Inheritor*) l)->ref;
- +
- + if (down_interruptible( &inheritor->entry.lock )) {
- + printk( KERN_ERR "fusion_ref: propagate_local() interrupted!\n" );
- + //return -EINTR;
- + }
- +
- + propagate_local( dev, inheritor, diff );
- +
- + up( &inheritor->entry.lock );
- + }
- +
- + /* Apply difference. */
- + ref->local += diff;
- +
- + /* Notify zero count. */
- + if (ref->local + ref->global == 0)
- + notify_ref( dev, ref );
- +
- + return 0;
- +}
- +
- +static int
- +add_inheritor(FusionRef *ref, FusionRef *from)
- +{
- + Inheritor *inheritor;
- +
- + inheritor = kmalloc (sizeof(Inheritor), GFP_KERNEL);
- + if (!inheritor)
- + return -ENOMEM;
- +
- + inheritor->ref = ref;
- +
- + fusion_list_prepend( &from->inheritors, &inheritor->link );
- +
- + return 0;
- +}
- +
- +static void
- +remove_inheritor(FusionRef *ref, FusionRef *from)
- +{
- + FusionLink *l;
- +
- + down( &from->entry.lock );
- +
- + fusion_list_foreach (l, from->inheritors) {
- + Inheritor *inheritor = (Inheritor*) l;
- +
- + if (inheritor->ref == ref) {
- + fusion_list_remove( &from->inheritors, &inheritor->link );
- +
- + kfree( l );
- + break;
- + }
- + }
- +
- + up( &from->entry.lock );
- +}
- +
- +static void
- +drop_inheritors( FusionDev *dev, FusionRef *ref )
- +{
- + FusionLink *l = ref->inheritors;
- +
- + while (l) {
- + FusionLink *next = l->next;
- + FusionRef *inheritor = ((Inheritor*) l)->ref;
- +
- + if (down_interruptible( &inheritor->entry.lock )) {
- + printk( KERN_ERR "fusion_ref: drop_inheritors() interrupted!\n" );
- + //return;
- + }
- +
- + propagate_local( dev, inheritor, - ref->local );
- +
- + inheritor->inherited = NULL;
- +
- + up( &inheritor->entry.lock );
- +
- +
- + kfree (l);
- +
- + l = next;
- + }
- +
- + ref->inheritors = NULL;
- +}
- +
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/ref.h linux-2.6.22.1/drivers/char/fusion/ref.h
- --- linux-2.6.22.1-0rig/drivers/char/fusion/ref.h 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/ref.h 2006-08-14 11:16:54.000000000 +0200
- @@ -0,0 +1,79 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifndef __FUSION__REF_H__
- +#define __FUSION__REF_H__
- +
- +#include "fusiondev.h"
- +#include "types.h"
- +
- +
- +/* module init/cleanup */
- +
- +int fusion_ref_init (FusionDev *dev);
- +void fusion_ref_deinit (FusionDev *dev);
- +
- +
- +/* public API */
- +
- +int fusion_ref_new (FusionDev *dev,
- + int *id);
- +
- +int fusion_ref_up (FusionDev *dev,
- + int id,
- + FusionID fusion_id);
- +
- +int fusion_ref_down (FusionDev *dev,
- + int id,
- + FusionID fusion_id);
- +
- +int fusion_ref_zero_lock (FusionDev *dev,
- + int id,
- + FusionID fusion_id);
- +
- +int fusion_ref_zero_trylock (FusionDev *dev,
- + int id,
- + FusionID fusion_id);
- +
- +int fusion_ref_zero_unlock (FusionDev *dev,
- + int id,
- + FusionID fusion_id);
- +
- +int fusion_ref_stat (FusionDev *dev,
- + int id,
- + int *refs);
- +
- +int fusion_ref_watch (FusionDev *dev,
- + int id,
- + int call_id,
- + int call_arg);
- +
- +int fusion_ref_inherit (FusionDev *dev,
- + int id,
- + int from);
- +
- +int fusion_ref_destroy (FusionDev *dev,
- + int id);
- +
- +
- +/* internal functions */
- +
- +void fusion_ref_clear_all_local (FusionDev *dev,
- + FusionID fusion_id);
- +
- +int fusion_ref_fork_all_local (FusionDev *dev,
- + FusionID fusion_id,
- + FusionID from_id);
- +
- +#endif
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/shmpool.c linux-2.6.22.1/drivers/char/fusion/shmpool.c
- --- linux-2.6.22.1-0rig/drivers/char/fusion/shmpool.c 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/shmpool.c 2007-01-20 05:03:01.000000000 +0100
- @@ -0,0 +1,444 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifdef HAVE_LINUX_CONFIG_H
- +#include <linux/config.h>
- +#endif
- +#include <linux/types.h>
- +#include <linux/kernel.h>
- +#include <linux/slab.h>
- +#include <linux/smp_lock.h>
- +#include <linux/sched.h>
- +
- +#include <linux/fusion.h>
- +
- +#include "fusiondev.h"
- +#include "fusionee.h"
- +#include "list.h"
- +#include "shmpool.h"
- +
- +
- +#define SHM_BASE 0x20010000 /* virtual base address */
- +#define SHM_SIZE 0x1FFEF000 /* size of virtual address space */
- +
- +
- +typedef struct {
- + FusionLink link;
- + unsigned long next_base;
- +} AddrEntry;
- +
- +
- +typedef struct {
- + FusionLink link;
- +
- + FusionID fusion_id;
- +
- + int count; /* number of attach calls */
- +} SHMPoolNode;
- +
- +typedef struct {
- + FusionEntry entry;
- +
- + int max_size;
- +
- + void *addr_base;
- + int size;
- +
- + AddrEntry *addr_entry;
- +
- + FusionLink *nodes;
- +
- + int dispatch_count;
- +} FusionSHMPool;
- +
- +/******************************************************************************/
- +
- +static SHMPoolNode *get_node ( FusionSHMPool *shmpool,
- + FusionID fusion_id );
- +
- +static void remove_node ( FusionSHMPool *shmpool,
- + FusionID fusion_id );
- +
- +static int fork_node ( FusionSHMPool *shmpool,
- + FusionID fusion_id,
- + FusionID from_id );
- +
- +static void free_all_nodes( FusionSHMPool *shmpool );
- +
- +/******************************************************************************/
- +
- +
- +static DECLARE_MUTEX (addr_lock);
- +static FusionLink *addr_entries;
- +static unsigned long addr_base = SHM_BASE;
- +
- +/******************************************************************************/
- +
- +static AddrEntry *
- +add_addr_entry( unsigned long next_base )
- +{
- + AddrEntry *entry = kmalloc( sizeof(AddrEntry), GFP_KERNEL );
- +
- + entry->next_base = next_base;
- +
- + fusion_list_prepend( &addr_entries, &entry->link );
- +
- + return entry;
- +}
- +
- +/******************************************************************************/
- +
- +static int
- +fusion_shmpool_construct( FusionEntry *entry,
- + void *ctx,
- + void *create_ctx )
- +{
- + FusionSHMPool *shmpool = (FusionSHMPool*) entry;
- + FusionSHMPoolNew *poolnew = create_ctx;
- +
- + down( &addr_lock );
- +
- + if (addr_base + poolnew->max_size >= SHM_BASE + SHM_SIZE) {
- + up( &addr_lock );
- + printk( KERN_WARNING "%s: virtual address space exhausted! (FIXME)\n", __FUNCTION__ );
- + return -ENOSPC;
- + }
- +
- + shmpool->max_size = poolnew->max_size;
- + shmpool->addr_base = poolnew->addr_base = (void*) addr_base;
- +
- + addr_base += PAGE_ALIGN(poolnew->max_size) + PAGE_SIZE; /* fence page */
- +
- + shmpool->addr_entry = add_addr_entry( addr_base );
- +
- + up( &addr_lock );
- +
- + return 0;
- +}
- +
- +static void
- +fusion_shmpool_destruct( FusionEntry *entry,
- + void *ctx )
- +{
- + AddrEntry *addr_entry;
- + FusionSHMPool *shmpool = (FusionSHMPool*) entry;
- +
- + free_all_nodes( shmpool );
- +
- +
- + down( &addr_lock );
- +
- + fusion_list_remove( &addr_entries, &shmpool->addr_entry->link );
- +
- +
- + /*
- + * free trailing address space
- + */
- +
- + addr_base = SHM_BASE;
- +
- + fusion_list_foreach (addr_entry, addr_entries) {
- + if (addr_entry->next_base > addr_base)
- + addr_base = addr_entry->next_base;
- + }
- +
- + up( &addr_lock );
- +}
- +
- +static int
- +fusion_shmpool_print( FusionEntry *entry,
- + void *ctx,
- + char *buf )
- +{
- + int num = 0;
- + FusionSHMPool *shmpool = (FusionSHMPool*) entry;
- + FusionLink *node = shmpool->nodes;
- +
- + fusion_list_foreach (node, shmpool->nodes) {
- + num++;
- + }
- +
- + return sprintf( buf, "0x%p [0x%x] - 0x%x, %dx dispatch, %d nodes\n",
- + shmpool->addr_base, shmpool->max_size, shmpool->size,
- + shmpool->dispatch_count, num );
- +}
- +
- +
- +FUSION_ENTRY_CLASS( FusionSHMPool, shmpool, fusion_shmpool_construct,
- + fusion_shmpool_destruct, fusion_shmpool_print )
- +
- +/******************************************************************************/
- +
- +int
- +fusion_shmpool_init (FusionDev *dev)
- +{
- + fusion_entries_init( &dev->shmpool, &shmpool_class, dev );
- +
- + create_proc_read_entry( "shmpools", 0, dev->proc_dir,
- + fusion_entries_read_proc, &dev->shmpool );
- +
- + return 0;
- +}
- +
- +void
- +fusion_shmpool_deinit (FusionDev *dev)
- +{
- + remove_proc_entry ("shmpools", dev->proc_dir);
- +
- + fusion_entries_deinit( &dev->shmpool );
- +}
- +
- +/******************************************************************************/
- +
- +int
- +fusion_shmpool_new (FusionDev *dev,
- + FusionSHMPoolNew *pool)
- +{
- + if (pool->max_size <= 0)
- + return -EINVAL;
- +
- + return fusion_entry_create( &dev->shmpool, &pool->pool_id, pool );
- +}
- +
- +int
- +fusion_shmpool_attach (FusionDev *dev,
- + FusionSHMPoolAttach *attach,
- + FusionID fusion_id)
- +{
- + int ret;
- + SHMPoolNode *node;
- + FusionSHMPool *shmpool;
- +
- + ret = fusion_shmpool_lock( &dev->shmpool, attach->pool_id, false, &shmpool );
- + if (ret)
- + return ret;
- +
- + dev->stat.shmpool_attach++;
- +
- + node = get_node (shmpool, fusion_id);
- + if (!node) {
- + node = kmalloc (sizeof(SHMPoolNode), GFP_KERNEL);
- + if (!node) {
- + fusion_shmpool_unlock( shmpool );
- + return -ENOMEM;
- + }
- +
- + node->fusion_id = fusion_id;
- + node->count = 1;
- +
- + fusion_list_prepend (&shmpool->nodes, &node->link);
- + }
- + else
- + node->count++;
- +
- + attach->addr_base = shmpool->addr_base;
- + attach->size = shmpool->size;
- +
- + fusion_shmpool_unlock( shmpool );
- +
- + return 0;
- +}
- +
- +int
- +fusion_shmpool_detach (FusionDev *dev, int id, FusionID fusion_id)
- +{
- + int ret;
- + SHMPoolNode *node;
- + FusionSHMPool *shmpool;
- +
- + ret = fusion_shmpool_lock( &dev->shmpool, id, false, &shmpool );
- + if (ret)
- + return ret;
- +
- + dev->stat.shmpool_detach++;
- +
- + node = get_node (shmpool, fusion_id);
- + if (!node) {
- + fusion_shmpool_unlock( shmpool );
- + return -EIO;
- + }
- +
- + if (! --node->count) {
- + fusion_list_remove (&shmpool->nodes, &node->link);
- + kfree (node);
- + }
- +
- + fusion_shmpool_unlock( shmpool );
- +
- + return 0;
- +}
- +
- +int
- +fusion_shmpool_dispatch( FusionDev *dev,
- + FusionSHMPoolDispatch *dispatch,
- + Fusionee *fusionee )
- +{
- + int ret;
- + FusionLink *l;
- + FusionSHMPool *shmpool;
- + FusionSHMPoolMessage message;
- + FusionID fusion_id = fusionee_id( fusionee );
- +
- + if (dispatch->size <= 0)
- + return -EINVAL;
- +
- + ret = fusion_shmpool_lock( &dev->shmpool, dispatch->pool_id, false, &shmpool );
- + if (ret)
- + return ret;
- +
- + message.type = FSMT_REMAP;
- + message.size = dispatch->size;
- +
- + shmpool->dispatch_count++;
- +
- + shmpool->size = dispatch->size;
- +
- + fusion_list_foreach (l, shmpool->nodes) {
- + SHMPoolNode *node = (SHMPoolNode *) l;
- +
- + if (node->fusion_id == fusion_id)
- + continue;
- +
- + fusionee_send_message (dev, fusionee, node->fusion_id, FMT_SHMPOOL,
- + shmpool->entry.id, sizeof(message), &message);
- + }
- +
- + fusion_shmpool_unlock( shmpool );
- +
- + return 0;
- +}
- +
- +int
- +fusion_shmpool_destroy (FusionDev *dev, int id)
- +{
- + return fusion_entry_destroy( &dev->shmpool, id );
- +}
- +
- +void
- +fusion_shmpool_detach_all (FusionDev *dev, FusionID fusion_id)
- +{
- + FusionLink *l;
- +
- + down (&dev->shmpool.lock);
- +
- + fusion_list_foreach (l, dev->shmpool.list) {
- + FusionSHMPool *shmpool = (FusionSHMPool *) l;
- +
- + remove_node (shmpool, fusion_id);
- + }
- +
- + up (&dev->shmpool.lock);
- +}
- +
- +int
- +fusion_shmpool_fork_all( FusionDev *dev,
- + FusionID fusion_id,
- + FusionID from_id )
- +{
- + FusionLink *l;
- + int ret = 0;
- +
- + down (&dev->shmpool.lock);
- +
- + fusion_list_foreach (l, dev->shmpool.list) {
- + FusionSHMPool *shmpool = (FusionSHMPool *) l;
- +
- + ret = fork_node( shmpool, fusion_id, from_id );
- + if (ret)
- + break;
- + }
- +
- + up (&dev->shmpool.lock);
- +
- + return ret;
- +}
- +
- +/******************************************************************************/
- +
- +static SHMPoolNode *
- +get_node (FusionSHMPool *shmpool,
- + FusionID fusion_id)
- +{
- + SHMPoolNode *node;
- +
- + fusion_list_foreach (node, shmpool->nodes) {
- + if (node->fusion_id == fusion_id)
- + return node;
- + }
- +
- + return NULL;
- +}
- +
- +static void
- +remove_node (FusionSHMPool *shmpool, FusionID fusion_id)
- +{
- + SHMPoolNode *node;
- +
- + down (&shmpool->entry.lock);
- +
- + fusion_list_foreach (node, shmpool->nodes) {
- + if (node->fusion_id == fusion_id) {
- + fusion_list_remove (&shmpool->nodes, &node->link);
- + break;
- + }
- + }
- +
- + up (&shmpool->entry.lock);
- +}
- +
- +static int
- +fork_node (FusionSHMPool *shmpool, FusionID fusion_id, FusionID from_id)
- +{
- + int ret = 0;
- + SHMPoolNode *node;
- +
- + down (&shmpool->entry.lock);
- +
- + fusion_list_foreach (node, shmpool->nodes) {
- + if (node->fusion_id == from_id) {
- + SHMPoolNode *new_node;
- +
- + new_node = kmalloc (sizeof(SHMPoolNode), GFP_KERNEL);
- + if (!new_node) {
- + ret = -ENOMEM;
- + break;
- + }
- +
- + new_node->fusion_id = fusion_id;
- + new_node->count = node->count;
- +
- + fusion_list_prepend (&shmpool->nodes, &new_node->link);
- +
- + break;
- + }
- + }
- +
- + up (&shmpool->entry.lock);
- +
- + return ret;
- +}
- +
- +static void
- +free_all_nodes (FusionSHMPool *shmpool)
- +
- +{
- + FusionLink *n;
- + SHMPoolNode *node;
- +
- + fusion_list_foreach_safe (node, n, shmpool->nodes) {
- + kfree (node);
- + }
- +
- + shmpool->nodes = NULL;
- +}
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/shmpool.h linux-2.6.22.1/drivers/char/fusion/shmpool.h
- --- linux-2.6.22.1-0rig/drivers/char/fusion/shmpool.h 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/shmpool.h 2007-01-20 05:03:01.000000000 +0100
- @@ -0,0 +1,59 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifndef __FUSION__SHMPOOL_H__
- +#define __FUSION__SHMPOOL_H__
- +
- +#include "fusiondev.h"
- +#include "types.h"
- +
- +
- +/* module init/cleanup */
- +
- +int fusion_shmpool_init (FusionDev *dev);
- +void fusion_shmpool_deinit (FusionDev *dev);
- +
- +
- +/* public API */
- +
- +int fusion_shmpool_new (FusionDev *dev,
- + FusionSHMPoolNew *pool);
- +
- +int fusion_shmpool_attach (FusionDev *dev,
- + FusionSHMPoolAttach *attach,
- + FusionID fusion_id);
- +
- +int fusion_shmpool_detach (FusionDev *dev,
- + int id,
- + FusionID fusion_id);
- +
- +int fusion_shmpool_dispatch (FusionDev *dev,
- + FusionSHMPoolDispatch *dispatch,
- + Fusionee *fusionee );
- +
- +int fusion_shmpool_destroy (FusionDev *dev,
- + int id);
- +
- +
- +/* internal functions */
- +
- +void fusion_shmpool_detach_all (FusionDev *dev,
- + FusionID fusion_id);
- +
- +int fusion_shmpool_fork_all (FusionDev *dev,
- + FusionID fusion_id,
- + FusionID from_id);
- +
- +#endif
- +
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/skirmish.c linux-2.6.22.1/drivers/char/fusion/skirmish.c
- --- linux-2.6.22.1-0rig/drivers/char/fusion/skirmish.c 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/skirmish.c 2007-01-06 14:09:45.000000000 +0100
- @@ -0,0 +1,397 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifdef HAVE_LINUX_CONFIG_H
- +#include <linux/config.h>
- +#endif
- +#include <linux/types.h>
- +#include <linux/kernel.h>
- +#include <linux/slab.h>
- +#include <linux/smp_lock.h>
- +#include <linux/sched.h>
- +
- +#include <linux/fusion.h>
- +
- +#include "fusiondev.h"
- +#include "fusionee.h"
- +#include "list.h"
- +#include "skirmish.h"
- +
- +
- +#define MAX_PRE_ACQUISITIONS 32
- +
- +
- +typedef struct __FUSION_FusionSkirmish FusionSkirmish;
- +
- +struct __FUSION_FusionSkirmish {
- + FusionEntry entry;
- +
- + int lock_fid; /* non-zero if locked */
- + int lock_pid;
- + int lock_count;
- +
- + int lock_total;
- +
- +#ifdef FUSION_DEBUG_SKIRMISH_DEADLOCK
- + int pre_acquis[MAX_PRE_ACQUISITIONS];
- +
- + bool outer;
- +#endif
- +};
- +
- +static int
- +fusion_skirmish_print( FusionEntry *entry,
- + void *ctx,
- + char *buf )
- +{
- + int written = 0;
- + FusionSkirmish *skirmish = (FusionSkirmish*) entry;
- +
- +#ifdef FUSION_DEBUG_SKIRMISH_DEADLOCK
- + int i, n;
- +
- +
- + for (i=0, n=0; i<MAX_PRE_ACQUISITIONS; i++) {
- + if (skirmish->pre_acquis[i]) {
- + n++;
- + }
- + }
- +
- + written += sprintf( buf + written, "[%2d]%s", n, skirmish->outer ? "." : " " );
- +
- + for (i=0, n=0; i<MAX_PRE_ACQUISITIONS; i++) {
- + if (skirmish->pre_acquis[i]) {
- + written += sprintf( buf + written, "%s%02x", n ? "," : "", skirmish->pre_acquis[i] - 1 );
- +
- + n++;
- + }
- + }
- +#endif
- +
- + if (skirmish->lock_fid) {
- + if (skirmish->entry.waiters)
- + return sprintf( buf + written, " - %dx [0x%08x] (%d) %d WAITING\n",
- + skirmish->lock_count, skirmish->lock_fid,
- + skirmish->lock_pid, skirmish->entry.waiters ) + written;
- + else
- + return sprintf( buf + written, " - %dx [0x%08x] (%d)\n",
- + skirmish->lock_count, skirmish->lock_fid,
- + skirmish->lock_pid ) + written;
- + }
- +
- + return sprintf( buf + written, "\n" ) + written;
- +}
- +
- +FUSION_ENTRY_CLASS( FusionSkirmish, skirmish, NULL, NULL, fusion_skirmish_print )
- +
- +/******************************************************************************/
- +
- +int
- +fusion_skirmish_init (FusionDev *dev)
- +{
- + fusion_entries_init( &dev->skirmish, &skirmish_class, dev );
- +
- + create_proc_read_entry( "skirmishs", 0, dev->proc_dir,
- + fusion_entries_read_proc, &dev->skirmish );
- +
- + return 0;
- +}
- +
- +void
- +fusion_skirmish_deinit (FusionDev *dev)
- +{
- + remove_proc_entry ("skirmishs", dev->proc_dir);
- +
- + fusion_entries_deinit( &dev->skirmish );
- +}
- +
- +/******************************************************************************/
- +
- +int
- +fusion_skirmish_new (FusionDev *dev, int *ret_id)
- +{
- + return fusion_entry_create( &dev->skirmish, ret_id, NULL );
- +}
- +
- +int
- +fusion_skirmish_prevail (FusionDev *dev, int id, int fusion_id)
- +{
- + int ret;
- + FusionSkirmish *skirmish;
- +#ifdef FUSION_DEBUG_SKIRMISH_DEADLOCK
- + FusionSkirmish *s;
- + int i;
- + bool outer = true;
- +#endif
- +
- + dev->stat.skirmish_prevail_swoop++;
- +
- + ret = fusion_skirmish_lock( &dev->skirmish, id, true, &skirmish );
- + if (ret)
- + return ret;
- +
- + if (skirmish->lock_pid == current->pid) {
- + skirmish->lock_count++;
- + skirmish->lock_total++;
- + fusion_skirmish_unlock( skirmish );
- + up( &dev->skirmish.lock );
- + return 0;
- + }
- +
- +#ifdef FUSION_DEBUG_SKIRMISH_DEADLOCK
- + /* look in currently acquired skirmishs for this one being
- + a pre-acquisition, indicating a potential deadlock */
- + fusion_list_foreach (s, dev->skirmish.list) {
- + if (s->lock_pid != current->pid)
- + continue;
- +
- + outer = false;
- +
- + for (i=0; i<MAX_PRE_ACQUISITIONS; i++) {
- + if (s->pre_acquis[i] == id + 1) {
- + printk( KERN_DEBUG "FusionSkirmish: Potential deadlock "
- + "between locked 0x%x and to be locked 0x%x in world %d!\n",
- + s->entry.id, skirmish->entry.id, dev->index );
- + }
- + }
- + }
- +
- + if (outer)
- + skirmish->outer = true;
- +
- + /* remember all previously acquired skirmishs being pre-acquisitions for
- + this one, to detect potential deadlocks due to a lock order twist */
- + fusion_list_foreach (s, dev->skirmish.list) {
- + int free = -1;
- +
- + if (s->lock_pid != current->pid)
- + continue;
- +
- + for (i=0; i<MAX_PRE_ACQUISITIONS; i++) {
- + if (skirmish->pre_acquis[i]) {
- + if (skirmish->pre_acquis[i] == s->entry.id + 1) {
- + break;
- + }
- + }
- + else
- + free = i;
- + }
- +
- + /* not found? */
- + if (i == MAX_PRE_ACQUISITIONS) {
- + if (free != -1) {
- + skirmish->pre_acquis[free] = s->entry.id + 1;
- + }
- + else {
- + printk( KERN_DEBUG "FusionSkirmish: Too many pre-acquisitions to remember.\n" );
- +
- + printk( KERN_DEBUG " [ '%s' ] <- ", skirmish->entry.name );
- +
- + for (i=0; i<MAX_PRE_ACQUISITIONS; i++)
- + printk( "0x%03x ", skirmish->pre_acquis[i] - 1 );
- +
- + printk( "\n" );
- + }
- + }
- + }
- +#endif
- +
- + up( &dev->skirmish.lock );
- +
- + while (skirmish->lock_pid) {
- + ret = fusion_skirmish_wait( skirmish, NULL );
- + if (ret)
- + return ret;
- + }
- +
- + skirmish->lock_fid = fusion_id;
- + skirmish->lock_pid = current->pid;
- + skirmish->lock_count = 1;
- +
- + skirmish->lock_total++;
- +
- + fusion_skirmish_unlock( skirmish );
- +
- + return 0;
- +}
- +
- +int
- +fusion_skirmish_swoop (FusionDev *dev, int id, int fusion_id)
- +{
- + int ret;
- + FusionSkirmish *skirmish;
- +
- + ret = fusion_skirmish_lock( &dev->skirmish, id, false, &skirmish );
- + if (ret)
- + return ret;
- +
- + dev->stat.skirmish_prevail_swoop++;
- +
- + if (skirmish->lock_fid) {
- + if (skirmish->lock_pid == current->pid) {
- + skirmish->lock_count++;
- + skirmish->lock_total++;
- + fusion_skirmish_unlock( skirmish );
- + return 0;
- + }
- +
- + fusion_skirmish_unlock( skirmish );
- +
- + return -EAGAIN;
- + }
- +
- + skirmish->lock_fid = fusion_id;
- + skirmish->lock_pid = current->pid;
- + skirmish->lock_count = 1;
- +
- + skirmish->lock_total++;
- +
- + fusion_skirmish_unlock( skirmish );
- +
- + return 0;
- +}
- +
- +int
- +fusion_skirmish_lock_count (FusionDev *dev, int id, int fusion_id, int *ret_lock_count)
- +{
- + int ret;
- + FusionSkirmish *skirmish;
- +
- + ret = fusion_skirmish_lock( &dev->skirmish, id, false, &skirmish );
- + if (ret)
- + return ret;
- +
- + if (skirmish->lock_fid == fusion_id &&
- + skirmish->lock_pid == current->pid)
- + {
- + *ret_lock_count = skirmish->lock_count;
- + }
- + else
- + {
- + *ret_lock_count = 0;
- + }
- +
- + fusion_skirmish_unlock( skirmish );
- +
- + return 0;
- +}
- +
- +int
- +fusion_skirmish_dismiss (FusionDev *dev, int id, int fusion_id)
- +{
- + int ret;
- + FusionSkirmish *skirmish;
- +
- + ret = fusion_skirmish_lock( &dev->skirmish, id, false, &skirmish );
- + if (ret)
- + return ret;
- +
- + dev->stat.skirmish_dismiss++;
- +
- + if (skirmish->lock_pid != current->pid) {
- + fusion_skirmish_unlock( skirmish );
- + return -EIO;
- + }
- +
- + if (--skirmish->lock_count == 0) {
- + skirmish->lock_fid = 0;
- + skirmish->lock_pid = 0;
- +
- + fusion_skirmish_notify( skirmish, true );
- + }
- +
- + fusion_skirmish_unlock( skirmish );
- +
- + return 0;
- +}
- +
- +int
- +fusion_skirmish_destroy (FusionDev *dev, int id)
- +{
- +#ifdef FUSION_DEBUG_SKIRMISH_DEADLOCK
- + int i;
- + FusionSkirmish *s;
- +
- + /* Lock entries. */
- + if (down_interruptible( &dev->skirmish.lock ))
- + return -EINTR;
- +
- + /* remove from all pre-acquisition lists */
- + fusion_list_foreach (s, dev->skirmish.list) {
- + for (i=0; i<MAX_PRE_ACQUISITIONS; i++) {
- + if (s->pre_acquis[i] == id + 1)
- + s->pre_acquis[i] = 0;
- + }
- + }
- +
- + up( &dev->skirmish.lock );
- +
- + /* FIXME: gap? */
- +#endif
- +
- + return fusion_entry_destroy( &dev->skirmish, id );
- +}
- +
- +void
- +fusion_skirmish_dismiss_all (FusionDev *dev, int fusion_id)
- +{
- + FusionLink *l;
- +
- + down (&dev->skirmish.lock);
- +
- + fusion_list_foreach (l, dev->skirmish.list) {
- + FusionSkirmish *skirmish = (FusionSkirmish *) l;
- +
- + down (&skirmish->entry.lock);
- +
- + if (skirmish->lock_fid == fusion_id) {
- + skirmish->lock_fid = 0;
- + skirmish->lock_pid = 0;
- + skirmish->lock_count = 0;
- +
- + wake_up_interruptible_all (&skirmish->entry.wait);
- + }
- +
- + up (&skirmish->entry.lock);
- + }
- +
- + up (&dev->skirmish.lock);
- +}
- +
- +void
- +fusion_skirmish_dismiss_all_from_pid (FusionDev *dev, int pid)
- +{
- + FusionLink *l;
- +
- + down (&dev->skirmish.lock);
- +
- + fusion_list_foreach (l, dev->skirmish.list) {
- + FusionSkirmish *skirmish = (FusionSkirmish *) l;
- +
- + down (&skirmish->entry.lock);
- +
- + if (skirmish->lock_pid == pid) {
- + skirmish->lock_fid = 0;
- + skirmish->lock_pid = 0;
- + skirmish->lock_count = 0;
- +
- + wake_up_interruptible_all (&skirmish->entry.wait);
- + }
- +
- + up (&skirmish->entry.lock);
- + }
- +
- + up (&dev->skirmish.lock);
- +}
- +
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/skirmish.h linux-2.6.22.1/drivers/char/fusion/skirmish.h
- --- linux-2.6.22.1-0rig/drivers/char/fusion/skirmish.h 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/skirmish.h 2006-06-30 10:54:55.000000000 +0200
- @@ -0,0 +1,62 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002-2003 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifndef __FUSION__SKIRMISH_H__
- +#define __FUSION__SKIRMISH_H__
- +
- +#include "fusiondev.h"
- +#include "types.h"
- +
- +
- +/* module init/cleanup */
- +
- +int fusion_skirmish_init (FusionDev *dev);
- +void fusion_skirmish_deinit (FusionDev *dev);
- +
- +
- +/* public API */
- +
- +int fusion_skirmish_new (FusionDev *dev,
- + int *id);
- +
- +int fusion_skirmish_prevail (FusionDev *dev,
- + int id,
- + int fusion_id);
- +
- +int fusion_skirmish_swoop (FusionDev *dev,
- + int id,
- + int fusion_id);
- +
- +int fusion_skirmish_lock_count (FusionDev *dev,
- + int id,
- + int fusion_id,
- + int *ret_lock_count);
- +
- +int fusion_skirmish_dismiss (FusionDev *dev,
- + int id,
- + int fusion_id);
- +
- +int fusion_skirmish_destroy (FusionDev *dev,
- + int id);
- +
- +
- +/* internal functions */
- +
- +void fusion_skirmish_dismiss_all (FusionDev *dev,
- + int fusion_id);
- +
- +void fusion_skirmish_dismiss_all_from_pid (FusionDev *dev,
- + int pid);
- +
- +#endif
- diff -urN linux-2.6.22.1-0rig/drivers/char/fusion/types.h linux-2.6.22.1/drivers/char/fusion/types.h
- --- linux-2.6.22.1-0rig/drivers/char/fusion/types.h 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/drivers/char/fusion/types.h 2007-01-20 05:03:01.000000000 +0100
- @@ -0,0 +1,29 @@
- +/*
- + * Fusion Kernel Module
- + *
- + * (c) Copyright 2002 Convergence GmbH
- + *
- + * Written by Denis Oliver Kropp <dok@directfb.org>
- + *
- + *
- + * This program is free software; you can redistribute it and/or
- + * modify it under the terms of the GNU General Public License
- + * as published by the Free Software Foundation; either version
- + * 2 of the License, or (at your option) any later version.
- + */
- +
- +#ifndef __FUSION__TYPES_H__
- +#define __FUSION__TYPES_H__
- +
- +#include <linux/version.h>
- +
- +#if LINUX_VERSION_CODE <= KERNEL_VERSION(2, 6, 18)
- +typedef enum {
- + false = 0,
- + true = !false
- +} bool;
- +#endif
- +
- +typedef struct __Fusion_Fusionee Fusionee;
- +
- +#endif
- diff -urN linux-2.6.22.1-0rig/drivers/char/Kconfig linux-2.6.22.1/drivers/char/Kconfig
- --- linux-2.6.22.1-0rig/drivers/char/Kconfig 2007-07-10 20:56:30.000000000 +0200
- +++ linux-2.6.22.1/drivers/char/Kconfig 2007-08-12 19:30:42.000000000 +0200
- @@ -484,6 +484,8 @@
- All modern Linux systems use the Unix98 ptys. Say Y unless
- you're on an embedded system and want to conserve memory.
-
- +source "drivers/char/fusion/Kconfig"
- +
- config LEGACY_PTYS
- bool "Legacy (BSD) PTY support"
- default y
- diff -urN linux-2.6.22.1-0rig/drivers/char/Makefile linux-2.6.22.1/drivers/char/Makefile
- --- linux-2.6.22.1-0rig/drivers/char/Makefile 2007-07-10 20:56:30.000000000 +0200
- +++ linux-2.6.22.1/drivers/char/Makefile 2007-08-12 19:45:20.000000000 +0200
- @@ -100,6 +100,7 @@
- obj-$(CONFIG_DRM) += drm/
- obj-$(CONFIG_PCMCIA) += pcmcia/
- obj-$(CONFIG_IPMI_HANDLER) += ipmi/
- +obj-$(CONFIG_FUSION_DEVICE) += fusion/
-
- obj-$(CONFIG_HANGCHECK_TIMER) += hangcheck-timer.o
- obj-$(CONFIG_TCG_TPM) += tpm/
- diff -urN linux-2.6.22.1-0rig/include/linux/fusion.h linux-2.6.22.1/include/linux/fusion.h
- --- linux-2.6.22.1-0rig/include/linux/fusion.h 1970-01-01 01:00:00.000000000 +0100
- +++ linux-2.6.22.1/include/linux/fusion.h 2007-01-29 01:43:50.000000000 +0100
- @@ -0,0 +1,277 @@
- +#ifndef __LINUX__FUSION_H__
- +#define __LINUX__FUSION_H__
- +
- +#include <asm/ioctl.h>
- +
- +/*
- + * Fusion Kernel Device API Version
- + */
- +#define FUSION_API_MAJOR 3 /* Increased if backward compatibility is dropped. */
- +#define FUSION_API_MINOR 2 /* Increased if new features are added. */
- +
- +/*
- + * The Fusion ID is a unique identifier for one process consisting of threads.
- + */
- +typedef unsigned long FusionID;
- +
- +#define FUSION_ID_MASTER 1 /* This is the fusion id of the master (first process). */
- +
- +/*
- + * Entering a world
- + */
- +typedef struct {
- + struct {
- + int major; /* Must be set to FUSION_API_MAJOR before entering. */
- + int minor; /* Must be set to FUSION_API_MINOR before entering. */
- + } api;
- +
- + FusionID fusion_id; /* Returns the fusion id of the entering process. */
- +} FusionEnter;
- +
- +/*
- + * Forking in world
- + */
- +typedef struct {
- + FusionID fusion_id; /* Returns the fusion id of the new (forked) fusionee. */
- +} FusionFork;
- +
- +/*
- + * Sending a message
- + */
- +typedef struct {
- + FusionID fusion_id; /* recipient */
- +
- + int msg_id; /* optional message identifier */
- + int msg_size; /* message size, must be greater than zero */
- + const void *msg_data; /* message data, must not be NULL */
- +} FusionSendMessage;
- +
- +/*
- + * Receiving a message
- + */
- +typedef enum {
- + FMT_SEND, /* msg_id is an optional custom id */
- + FMT_CALL, /* msg_id is the call id */
- + FMT_REACTOR, /* msg_id is the reactor id */
- + FMT_SHMPOOL /* msg_id is the pool id */
- +} FusionMessageType;
- +
- +typedef struct {
- + FusionMessageType msg_type; /* type (origin) of message */
- +
- + int msg_id; /* message id (custom id or call/reactor/pool id) */
- + int msg_size; /* size of the following message data */
- +
- + /* message data follows */
- +} FusionReadMessage;
- +
- +/*
- + * Dispatching a message via a reactor
- + */
- +typedef struct {
- + int reactor_id;
- + int self;
- +
- + int msg_size; /* message size, must be greater than zero */
- + const void *msg_data; /* message data, must not be NULL */
- +} FusionReactorDispatch;
- +
- +/*
- + * Calling (synchronous RPC)
- + */
- +typedef struct {
- + int call_id; /* new call id returned */
- +
- + void *handler; /* function pointer of handler to install */
- + void *ctx; /* optional handler context */
- +} FusionCallNew;
- +
- +typedef enum {
- + FCEF_NONE = 0x00000000,
- + FCEF_ONEWAY = 0x00000001,
- + FCEF_ALL = 0x00000001
- +} FusionCallExecFlags;
- +
- +typedef struct {
- + int ret_val; /* return value of the call */
- +
- + int call_id; /* id of the requested call, each call has a fixed owner */
- +
- + int call_arg; /* optional int argument */
- + void *call_ptr; /* optional pointer argument (shared memory) */
- +
- + FusionCallExecFlags flags; /* execution flags */
- +} FusionCallExecute;
- +
- +typedef struct {
- + int call_id; /* id of currently executing call */
- +
- + int val; /* value to return */
- +} FusionCallReturn;
- +
- +typedef struct {
- + void *handler; /* function pointer of handler to call */
- + void *ctx; /* optional handler context */
- +
- + int caller; /* fusion id of the caller or zero if called from Fusion */
- + int call_arg; /* optional call parameter */
- + void *call_ptr; /* optional call parameter */
- +} FusionCallMessage;
- +
- +/*
- + * Watching a reference
- + *
- + * This information is needed to have a specific call being executed if the
- + * reference count reaches zero. Currently one watch per reference is allowed.
- + *
- + * The call is made by Fusion and therefor has a caller id of zero.
- + *
- + */
- +typedef struct {
- + int id; /* id of the reference to watch */
- +
- + int call_id; /* id of the call to execute */
- + int call_arg; /* optional call parameter, e.g. the id of a user
- + space resource associated with that reference */
- +} FusionRefWatch;
- +
- +/*
- + * Inheriting local count from other reference
- + */
- +typedef struct {
- + int id; /* own reference id */
- + int from; /* id of the reference to inherit from */
- +} FusionRefInherit;
- +
- +/*
- + * Killing other fusionees (experimental)
- + */
- +typedef struct {
- + FusionID fusion_id; /* fusionee to kill, zero means all but ourself */
- + int signal; /* signal to be delivered, e.g. SIGTERM */
- + int timeout_ms; /* -1 means no timeout, 0 means infinite, otherwise the
- + max. time to wait until the fusionee(s) terminated */
- +} FusionKill;
- +
- +
- +/*
- + * Shared memory pools
- + */
- +typedef struct {
- + int max_size; /* Maximum size that this pool will be allowed to grow to. */
- +
- + int pool_id; /* Returns the new pool id. */
- + void *addr_base; /* Returns the base of the reserved virtual memory address space. */
- +} FusionSHMPoolNew;
- +
- +typedef struct {
- + int pool_id; /* The id of the pool to attach to. */
- +
- + void *addr_base; /* Returns the base of the reserved virtual memory address space. */
- + int size; /* Returns the current size of the pool. */
- +} FusionSHMPoolAttach;
- +
- +typedef struct {
- + int pool_id; /* The id of the pool to notify. */
- +
- + int size; /* New size of the pool. */
- +} FusionSHMPoolDispatch;
- +
- +typedef enum {
- + FSMT_REMAP, /* Remap the pool due to a change of its size. */
- + FSMT_UNMAP /* Unmap the pool due to its destruction. */
- +} FusionSHMPoolMessageType;
- +
- +typedef struct {
- + FusionSHMPoolMessageType type; /* Type of the message. */
- +
- + int size; /* New size of the pool, if type is FSMT_REMAP. */
- +} FusionSHMPoolMessage;
- +
- +
- +/*
- + * Fusion types
- + */
- +typedef enum {
- + FT_LOUNGE,
- + FT_MESSAGING,
- + FT_CALL,
- + FT_REF,
- + FT_SKIRMISH,
- + FT_PROPERTY,
- + FT_REACTOR,
- + FT_SHMPOOL
- +} FusionType;
- +
- +
- +/*
- + * Set attributes like 'name' for an entry of the specified type.
- + */
- +#define FUSION_ENTRY_INFO_NAME_LENGTH 24
- +
- +typedef struct {
- + FusionType type;
- + int id;
- +
- + char name[FUSION_ENTRY_INFO_NAME_LENGTH];
- +} FusionEntryInfo;
- +
- +
- +
- +#define FUSION_ENTER _IOR(FT_LOUNGE, 0x00, FusionEnter)
- +#define FUSION_UNBLOCK _IO (FT_LOUNGE, 0x01)
- +#define FUSION_KILL _IOW(FT_LOUNGE, 0x02, FusionKill)
- +
- +#define FUSION_ENTRY_SET_INFO _IOW(FT_LOUNGE, 0x03, FusionEntryInfo)
- +#define FUSION_ENTRY_GET_INFO _IOW(FT_LOUNGE, 0x04, FusionEntryInfo)
- +
- +#define FUSION_FORK _IOW(FT_LOUNGE, 0x05, FusionFork)
- +
- +#define FUSION_SEND_MESSAGE _IOW(FT_MESSAGING, 0x00, FusionSendMessage)
- +
- +#define FUSION_CALL_NEW _IOW(FT_CALL, 0x00, FusionCallNew)
- +#define FUSION_CALL_EXECUTE _IOW(FT_CALL, 0x01, FusionCallExecute)
- +#define FUSION_CALL_RETURN _IOW(FT_CALL, 0x02, FusionCallReturn)
- +#define FUSION_CALL_DESTROY _IOW(FT_CALL, 0x03, int)
- +
- +#define FUSION_REF_NEW _IOW(FT_REF, 0x00, int)
- +#define FUSION_REF_UP _IOW(FT_REF, 0x01, int)
- +#define FUSION_REF_UP_GLOBAL _IOW(FT_REF, 0x02, int)
- +#define FUSION_REF_DOWN _IOW(FT_REF, 0x03, int)
- +#define FUSION_REF_DOWN_GLOBAL _IOW(FT_REF, 0x04, int)
- +#define FUSION_REF_ZERO_LOCK _IOW(FT_REF, 0x05, int)
- +#define FUSION_REF_ZERO_TRYLOCK _IOW(FT_REF, 0x06, int)
- +#define FUSION_REF_UNLOCK _IOW(FT_REF, 0x07, int)
- +#define FUSION_REF_STAT _IOW(FT_REF, 0x08, int)
- +#define FUSION_REF_WATCH _IOW(FT_REF, 0x09, FusionRefWatch)
- +#define FUSION_REF_INHERIT _IOW(FT_REF, 0x0A, FusionRefInherit)
- +#define FUSION_REF_DESTROY _IOW(FT_REF, 0x0B, int)
- +
- +#define FUSION_SKIRMISH_NEW _IOW(FT_SKIRMISH, 0x00, int)
- +#define FUSION_SKIRMISH_PREVAIL _IOW(FT_SKIRMISH, 0x01, int)
- +#define FUSION_SKIRMISH_SWOOP _IOW(FT_SKIRMISH, 0x02, int)
- +#define FUSION_SKIRMISH_DISMISS _IOW(FT_SKIRMISH, 0x03, int)
- +#define FUSION_SKIRMISH_DESTROY _IOW(FT_SKIRMISH, 0x04, int)
- +#define FUSION_SKIRMISH_LOCK_COUNT _IOW(FT_SKIRMISH, 0x05, int)
- +
- +#define FUSION_PROPERTY_NEW _IOW(FT_PROPERTY, 0x00, int)
- +#define FUSION_PROPERTY_LEASE _IOW(FT_PROPERTY, 0x01, int)
- +#define FUSION_PROPERTY_PURCHASE _IOW(FT_PROPERTY, 0x02, int)
- +#define FUSION_PROPERTY_CEDE _IOW(FT_PROPERTY, 0x03, int)
- +#define FUSION_PROPERTY_HOLDUP _IOW(FT_PROPERTY, 0x04, int)
- +#define FUSION_PROPERTY_DESTROY _IOW(FT_PROPERTY, 0x05, int)
- +
- +#define FUSION_REACTOR_NEW _IOW(FT_REACTOR, 0x00, int)
- +#define FUSION_REACTOR_ATTACH _IOW(FT_REACTOR, 0x01, int)
- +#define FUSION_REACTOR_DETACH _IOW(FT_REACTOR, 0x02, int)
- +#define FUSION_REACTOR_DISPATCH _IOW(FT_REACTOR, 0x03, FusionReactorDispatch)
- +#define FUSION_REACTOR_DESTROY _IOW(FT_REACTOR, 0x04, int)
- +
- +#define FUSION_SHMPOOL_NEW _IOW(FT_SHMPOOL, 0x00, FusionSHMPoolNew)
- +#define FUSION_SHMPOOL_ATTACH _IOW(FT_SHMPOOL, 0x01, FusionSHMPoolAttach)
- +#define FUSION_SHMPOOL_DETACH _IOW(FT_SHMPOOL, 0x02, int)
- +#define FUSION_SHMPOOL_DISPATCH _IOW(FT_SHMPOOL, 0x03, FusionSHMPoolDispatch)
- +#define FUSION_SHMPOOL_DESTROY _IOW(FT_SHMPOOL, 0x04, int)
- +
- +#endif
- +
|