riscv-04032017.patch 245 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316631763186319632063216322632363246325632663276328632963306331633263336334633563366337633863396340634163426343634463456346634763486349635063516352635363546355635663576358635963606361636263636364636563666367636863696370637163726373637463756376637763786379638063816382638363846385638663876388638963906391639263936394639563966397639863996400640164026403640464056406640764086409641064116412641364146415641664176418641964206421642264236424642564266427642864296430643164326433643464356436643764386439644064416442644364446445644664476448644964506451645264536454645564566457645864596460646164626463646464656466646764686469647064716472647364746475647664776478647964806481648264836484648564866487648864896490649164926493649464956496649764986499650065016502650365046505650665076508650965106511651265136514651565166517651865196520652165226523652465256526652765286529653065316532653365346535653665376538653965406541654265436544654565466547654865496550655165526553655465556556655765586559656065616562656365646565656665676568656965706571657265736574657565766577657865796580658165826583658465856586658765886589659065916592659365946595659665976598659966006601660266036604660566066607660866096610661166126613661466156616661766186619662066216622662366246625662666276628662966306631663266336634663566366637663866396640664166426643664466456646664766486649665066516652665366546655665666576658665966606661666266636664666566666667666866696670667166726673667466756676667766786679668066816682668366846685668666876688668966906691669266936694669566966697669866996700670167026703670467056706670767086709671067116712671367146715671667176718671967206721672267236724672567266727672867296730673167326733673467356736673767386739674067416742674367446745674667476748674967506751675267536754675567566757675867596760676167626763676467656766676767686769677067716772677367746775677667776778677967806781678267836784678567866787678867896790679167926793679467956796679767986799680068016802680368046805680668076808680968106811681268136814681568166817681868196820682168226823682468256826682768286829683068316832683368346835683668376838683968406841684268436844684568466847684868496850685168526853685468556856685768586859686068616862686368646865686668676868686968706871687268736874687568766877687868796880688168826883688468856886688768886889689068916892689368946895689668976898689969006901690269036904690569066907690869096910691169126913691469156916691769186919692069216922692369246925692669276928692969306931693269336934693569366937693869396940694169426943694469456946694769486949695069516952695369546955695669576958695969606961696269636964696569666967696869696970697169726973697469756976697769786979698069816982698369846985698669876988698969906991699269936994699569966997699869997000700170027003700470057006700770087009701070117012701370147015701670177018701970207021702270237024702570267027702870297030703170327033703470357036703770387039704070417042704370447045704670477048704970507051705270537054705570567057705870597060706170627063706470657066706770687069707070717072707370747075707670777078707970807081708270837084708570867087708870897090709170927093709470957096709770987099710071017102710371047105710671077108710971107111711271137114711571167117711871197120712171227123712471257126712771287129713071317132713371347135713671377138713971407141714271437144714571467147714871497150715171527153715471557156715771587159716071617162716371647165716671677168716971707171717271737174717571767177717871797180718171827183718471857186718771887189719071917192719371947195719671977198719972007201720272037204720572067207720872097210721172127213721472157216721772187219722072217222722372247225722672277228722972307231723272337234723572367237723872397240724172427243724472457246724772487249725072517252725372547255725672577258725972607261726272637264726572667267726872697270727172727273727472757276727772787279728072817282728372847285728672877288728972907291729272937294729572967297729872997300730173027303730473057306730773087309731073117312731373147315731673177318731973207321732273237324732573267327732873297330733173327333733473357336733773387339734073417342734373447345734673477348734973507351735273537354735573567357735873597360736173627363736473657366736773687369737073717372737373747375737673777378737973807381738273837384738573867387738873897390739173927393739473957396739773987399740074017402740374047405740674077408740974107411741274137414741574167417741874197420742174227423742474257426742774287429743074317432743374347435743674377438743974407441744274437444744574467447744874497450745174527453745474557456745774587459746074617462746374647465746674677468746974707471747274737474747574767477747874797480748174827483748474857486748774887489749074917492749374947495749674977498749975007501750275037504750575067507750875097510751175127513751475157516751775187519752075217522752375247525752675277528752975307531753275337534753575367537753875397540754175427543754475457546754775487549755075517552755375547555755675577558755975607561756275637564756575667567756875697570757175727573757475757576757775787579758075817582758375847585758675877588758975907591759275937594759575967597759875997600760176027603760476057606760776087609761076117612761376147615761676177618761976207621762276237624762576267627762876297630763176327633763476357636763776387639764076417642764376447645764676477648764976507651765276537654765576567657765876597660766176627663766476657666766776687669767076717672767376747675767676777678767976807681768276837684768576867687768876897690769176927693769476957696769776987699770077017702770377047705770677077708770977107711771277137714771577167717771877197720772177227723772477257726772777287729773077317732773377347735773677377738773977407741774277437744774577467747774877497750775177527753775477557756775777587759776077617762776377647765776677677768776977707771777277737774777577767777777877797780778177827783778477857786778777887789779077917792779377947795779677977798779978007801780278037804780578067807780878097810781178127813781478157816781778187819782078217822782378247825782678277828782978307831783278337834783578367837783878397840784178427843784478457846784778487849785078517852785378547855785678577858785978607861786278637864786578667867786878697870787178727873787478757876787778787879788078817882788378847885788678877888788978907891789278937894789578967897789878997900790179027903790479057906790779087909791079117912791379147915791679177918791979207921792279237924792579267927792879297930793179327933793479357936793779387939794079417942794379447945794679477948794979507951795279537954795579567957795879597960796179627963796479657966796779687969797079717972797379747975797679777978797979807981798279837984798579867987798879897990799179927993799479957996799779987999800080018002800380048005800680078008800980108011801280138014801580168017801880198020802180228023802480258026802780288029803080318032803380348035803680378038803980408041804280438044804580468047804880498050805180528053805480558056805780588059806080618062806380648065806680678068806980708071807280738074807580768077807880798080808180828083808480858086808780888089809080918092809380948095809680978098809981008101810281038104810581068107810881098110811181128113811481158116811781188119812081218122812381248125812681278128812981308131813281338134813581368137813881398140814181428143814481458146814781488149815081518152815381548155815681578158815981608161816281638164816581668167816881698170817181728173817481758176817781788179818081818182818381848185818681878188818981908191819281938194819581968197819881998200820182028203820482058206820782088209821082118212821382148215821682178218821982208221822282238224822582268227822882298230823182328233823482358236823782388239824082418242824382448245824682478248824982508251825282538254825582568257825882598260826182628263826482658266826782688269827082718272827382748275827682778278827982808281828282838284828582868287828882898290829182928293829482958296829782988299830083018302830383048305830683078308830983108311831283138314831583168317831883198320832183228323832483258326832783288329833083318332833383348335833683378338833983408341834283438344834583468347834883498350835183528353835483558356835783588359836083618362836383648365836683678368836983708371837283738374837583768377837883798380838183828383838483858386838783888389839083918392839383948395839683978398839984008401840284038404840584068407840884098410841184128413841484158416841784188419842084218422842384248425842684278428842984308431843284338434843584368437843884398440844184428443844484458446844784488449845084518452845384548455845684578458845984608461846284638464846584668467846884698470847184728473847484758476847784788479848084818482848384848485848684878488848984908491849284938494849584968497849884998500850185028503850485058506850785088509851085118512851385148515851685178518851985208521852285238524852585268527852885298530853185328533853485358536853785388539854085418542854385448545854685478548854985508551855285538554855585568557855885598560856185628563856485658566856785688569857085718572857385748575857685778578857985808581858285838584858585868587858885898590859185928593859485958596859785988599860086018602860386048605860686078608860986108611861286138614861586168617861886198620862186228623862486258626862786288629863086318632863386348635863686378638863986408641864286438644864586468647864886498650865186528653865486558656865786588659866086618662866386648665866686678668866986708671867286738674867586768677867886798680868186828683868486858686868786888689869086918692869386948695869686978698869987008701870287038704870587068707870887098710871187128713871487158716871787188719872087218722872387248725872687278728872987308731873287338734873587368737873887398740874187428743874487458746874787488749875087518752875387548755875687578758875987608761876287638764876587668767876887698770877187728773877487758776877787788779878087818782878387848785878687878788878987908791879287938794879587968797879887998800880188028803880488058806880788088809881088118812881388148815881688178818881988208821882288238824882588268827882888298830883188328833883488358836883788388839884088418842884388448845884688478848884988508851885288538854885588568857885888598860886188628863886488658866886788688869887088718872887388748875887688778878887988808881888288838884888588868887888888898890889188928893889488958896889788988899890089018902890389048905890689078908890989108911891289138914891589168917891889198920892189228923892489258926892789288929893089318932893389348935893689378938893989408941894289438944894589468947894889498950895189528953895489558956895789588959896089618962896389648965896689678968896989708971897289738974897589768977897889798980898189828983898489858986898789888989899089918992899389948995899689978998899990009001900290039004900590069007900890099010901190129013901490159016901790189019902090219022902390249025902690279028902990309031903290339034903590369037903890399040904190429043904490459046904790489049905090519052905390549055905690579058905990609061906290639064906590669067906890699070907190729073907490759076907790789079908090819082908390849085908690879088908990909091909290939094909590969097909890999100910191029103910491059106910791089109911091119112911391149115911691179118911991209121912291239124912591269127912891299130913191329133913491359136913791389139914091419142914391449145914691479148914991509151915291539154915591569157915891599160916191629163916491659166916791689169917091719172917391749175917691779178917991809181918291839184918591869187918891899190919191929193919491959196919791989199920092019202920392049205920692079208920992109211921292139214921592169217921892199220922192229223922492259226922792289229923092319232923392349235923692379238923992409241924292439244924592469247924892499250925192529253925492559256925792589259926092619262926392649265926692679268926992709271927292739274927592769277927892799280928192829283928492859286928792889289929092919292929392949295929692979298929993009301930293039304930593069307930893099310931193129313931493159316931793189319932093219322932393249325932693279328932993309331933293339334933593369337933893399340934193429343934493459346934793489349935093519352935393549355935693579358935993609361936293639364936593669367936893699370937193729373937493759376937793789379938093819382938393849385938693879388938993909391939293939394939593969397939893999400940194029403940494059406940794089409941094119412941394149415941694179418941994209421942294239424
  1. diff -Nur linux-4.6.2/arch/.gitignore linux-4.6.2.riscv/arch/.gitignore
  2. --- linux-4.6.2/arch/.gitignore 2016-06-08 03:23:53.000000000 +0200
  3. +++ linux-4.6.2.riscv/arch/.gitignore 2017-03-04 02:48:34.162887952 +0100
  4. @@ -1,2 +1,3 @@
  5. -i386
  6. -x86_64
  7. +# In ../, we ignored everything, so suppress that.
  8. +!riscv/
  9. +
  10. diff -Nur linux-4.6.2/arch/riscv/configs/riscv64_qemu linux-4.6.2.riscv/arch/riscv/configs/riscv64_qemu
  11. --- linux-4.6.2/arch/riscv/configs/riscv64_qemu 1970-01-01 01:00:00.000000000 +0100
  12. +++ linux-4.6.2.riscv/arch/riscv/configs/riscv64_qemu 2017-03-04 02:48:34.162887952 +0100
  13. @@ -0,0 +1,64 @@
  14. +# CONFIG_COMPACTION is not set
  15. +# CONFIG_CROSS_MEMORY_ATTACH is not set
  16. +CONFIG_HZ_100=y
  17. +CONFIG_CROSS_COMPILE="riscv64-unknown-linux-gnu-"
  18. +CONFIG_DEFAULT_HOSTNAME="ucbvax"
  19. +CONFIG_NAMESPACES=y
  20. +CONFIG_EMBEDDED=y
  21. +# CONFIG_BLK_DEV_BSG is not set
  22. +CONFIG_PARTITION_ADVANCED=y
  23. +# CONFIG_IOSCHED_DEADLINE is not set
  24. +CONFIG_NET=y
  25. +CONFIG_PACKET=y
  26. +CONFIG_UNIX=y
  27. +CONFIG_INET=y
  28. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  29. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  30. +# CONFIG_INET_XFRM_MODE_BEET is not set
  31. +# CONFIG_INET_LRO is not set
  32. +# CONFIG_INET_DIAG is not set
  33. +# CONFIG_IPV6 is not set
  34. +# CONFIG_WIRELESS is not set
  35. +CONFIG_DEVTMPFS=y
  36. +CONFIG_DEVTMPFS_MOUNT=y
  37. +# CONFIG_FIRMWARE_IN_KERNEL is not set
  38. +# CONFIG_BLK_DEV is not set
  39. +CONFIG_SCSI=y
  40. +CONFIG_BLK_DEV_SD=y
  41. +CONFIG_SCSI_VIRTIO=y
  42. +CONFIG_NETDEVICES=y
  43. +CONFIG_VIRTIO_NET=y
  44. +# CONFIG_ETHERNET is not set
  45. +# CONFIG_WLAN is not set
  46. +# CONFIG_INPUT_MOUSEDEV is not set
  47. +# CONFIG_INPUT_KEYBOARD is not set
  48. +# CONFIG_INPUT_MOUSE is not set
  49. +# CONFIG_VT is not set
  50. +CONFIG_SERIAL_8250=y
  51. +# CONFIG_SERIAL_8250_DEPRECATED_OPTIONS is not set
  52. +CONFIG_SERIAL_8250_CONSOLE=y
  53. +CONFIG_SERIAL_8250_NR_UARTS=1
  54. +CONFIG_SERIAL_8250_RUNTIME_UARTS=1
  55. +CONFIG_VIRTIO_CONSOLE=y
  56. +# CONFIG_HW_RANDOM is not set
  57. +# CONFIG_HWMON is not set
  58. +CONFIG_FB=y
  59. +# CONFIG_USB_SUPPORT is not set
  60. +CONFIG_VIRTIO_MMIO=y
  61. +CONFIG_VIRTIO_MMIO_CMDLINE_DEVICES=y
  62. +# CONFIG_IOMMU_SUPPORT is not set
  63. +CONFIG_EXT4_FS=y
  64. +# CONFIG_FILE_LOCKING is not set
  65. +# CONFIG_DNOTIFY is not set
  66. +# CONFIG_INOTIFY_USER is not set
  67. +# CONFIG_PROC_PAGE_MONITOR is not set
  68. +CONFIG_TMPFS=y
  69. +# CONFIG_MISC_FILESYSTEMS is not set
  70. +# CONFIG_NETWORK_FILESYSTEMS is not set
  71. +CONFIG_CMDLINE_BOOL=y
  72. +CONFIG_CMDLINE="virtio_mmio.device=0x200@0x400:1 virtio_mmio.device=0x200@0x600:2 virtio_mmio.device=0x200@0x800:3 lpj=100000"
  73. +CONFIG_CMDLINE_OVERRIDE=y
  74. +CONFIG_PRINTK_TIME=y
  75. +CONFIG_DEBUG_SECTION_MISMATCH=y
  76. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  77. +# CONFIG_CRYPTO_HW is not set
  78. diff -Nur linux-4.6.2/arch/riscv/configs/riscv64_spike linux-4.6.2.riscv/arch/riscv/configs/riscv64_spike
  79. --- linux-4.6.2/arch/riscv/configs/riscv64_spike 1970-01-01 01:00:00.000000000 +0100
  80. +++ linux-4.6.2.riscv/arch/riscv/configs/riscv64_spike 2017-03-04 02:48:34.162887952 +0100
  81. @@ -0,0 +1,929 @@
  82. +#
  83. +# Automatically generated file; DO NOT EDIT.
  84. +# Linux/riscv 3.14.29 Kernel Configuration
  85. +#
  86. +CONFIG_RISCV=y
  87. +CONFIG_MMU=y
  88. +CONFIG_PCI=y
  89. +CONFIG_STACKTRACE_SUPPORT=y
  90. +CONFIG_RWSEM_GENERIC_SPINLOCK=y
  91. +CONFIG_GENERIC_BUG=y
  92. +CONFIG_GENERIC_BUG_RELATIVE_POINTERS=y
  93. +CONFIG_GENERIC_CALIBRATE_DELAY=y
  94. +CONFIG_GENERIC_CSUM=y
  95. +CONFIG_GENERIC_HWEIGHT=y
  96. +
  97. +#
  98. +# Platform type
  99. +#
  100. +CONFIG_CPU_RV_ROCKET=y
  101. +# CONFIG_CPU_RV_GENERIC is not set
  102. +CONFIG_CPU_SUPPORTS_64BIT_KERNEL=y
  103. +CONFIG_RV_ATOMIC=y
  104. +# CONFIG_RV_SYSRISCV_ATOMIC is not set
  105. +CONFIG_SBI_CONSOLE=y
  106. +
  107. +#
  108. +# Kernel type
  109. +#
  110. +CONFIG_64BIT=y
  111. +CONFIG_FLATMEM=y
  112. +CONFIG_FLAT_NODE_MEM_MAP=y
  113. +CONFIG_HAVE_MEMBLOCK=y
  114. +CONFIG_HAVE_MEMBLOCK_NODE_MAP=y
  115. +# CONFIG_HAVE_BOOTMEM_INFO_NODE is not set
  116. +CONFIG_PAGEFLAGS_EXTENDED=y
  117. +CONFIG_SPLIT_PTLOCK_CPUS=4
  118. +# CONFIG_COMPACTION is not set
  119. +CONFIG_PHYS_ADDR_T_64BIT=y
  120. +CONFIG_ZONE_DMA_FLAG=0
  121. +# CONFIG_KSM is not set
  122. +CONFIG_DEFAULT_MMAP_MIN_ADDR=4096
  123. +# CONFIG_CROSS_MEMORY_ATTACH is not set
  124. +CONFIG_NEED_PER_CPU_KM=y
  125. +# CONFIG_CLEANCACHE is not set
  126. +# CONFIG_FRONTSWAP is not set
  127. +# CONFIG_CMA is not set
  128. +# CONFIG_ZBUD is not set
  129. +# CONFIG_ZSMALLOC is not set
  130. +CONFIG_PREEMPT_NONE=y
  131. +# CONFIG_PREEMPT_VOLUNTARY is not set
  132. +# CONFIG_PREEMPT is not set
  133. +CONFIG_HZ_100=y
  134. +# CONFIG_HZ_250 is not set
  135. +# CONFIG_HZ_300 is not set
  136. +# CONFIG_HZ_1000 is not set
  137. +CONFIG_HZ=100
  138. +# CONFIG_SCHED_HRTICK is not set
  139. +CONFIG_DEFCONFIG_LIST="/lib/modules/$UNAME_RELEASE/.config"
  140. +CONFIG_IRQ_WORK=y
  141. +
  142. +#
  143. +# General setup
  144. +#
  145. +CONFIG_BROKEN_ON_SMP=y
  146. +CONFIG_INIT_ENV_ARG_LIMIT=32
  147. +CONFIG_CROSS_COMPILE="riscv64-unknown-linux-gnu-"
  148. +# CONFIG_COMPILE_TEST is not set
  149. +CONFIG_LOCALVERSION=""
  150. +CONFIG_LOCALVERSION_AUTO=y
  151. +CONFIG_DEFAULT_HOSTNAME="ucbvax"
  152. +CONFIG_SWAP=y
  153. +# CONFIG_SYSVIPC is not set
  154. +# CONFIG_POSIX_MQUEUE is not set
  155. +# CONFIG_FHANDLE is not set
  156. +# CONFIG_AUDIT is not set
  157. +
  158. +#
  159. +# IRQ subsystem
  160. +#
  161. +CONFIG_GENERIC_IRQ_SHOW=y
  162. +CONFIG_GENERIC_CLOCKEVENTS=y
  163. +CONFIG_GENERIC_CLOCKEVENTS_BUILD=y
  164. +
  165. +#
  166. +# Timers subsystem
  167. +#
  168. +CONFIG_HZ_PERIODIC=y
  169. +# CONFIG_NO_HZ_IDLE is not set
  170. +# CONFIG_NO_HZ is not set
  171. +# CONFIG_HIGH_RES_TIMERS is not set
  172. +
  173. +#
  174. +# CPU/Task time and stats accounting
  175. +#
  176. +CONFIG_TICK_CPU_ACCOUNTING=y
  177. +# CONFIG_BSD_PROCESS_ACCT is not set
  178. +# CONFIG_TASKSTATS is not set
  179. +
  180. +#
  181. +# RCU Subsystem
  182. +#
  183. +CONFIG_TINY_RCU=y
  184. +# CONFIG_PREEMPT_RCU is not set
  185. +# CONFIG_RCU_STALL_COMMON is not set
  186. +# CONFIG_TREE_RCU_TRACE is not set
  187. +# CONFIG_IKCONFIG is not set
  188. +CONFIG_LOG_BUF_SHIFT=17
  189. +# CONFIG_CGROUPS is not set
  190. +# CONFIG_CHECKPOINT_RESTORE is not set
  191. +CONFIG_NAMESPACES=y
  192. +CONFIG_UTS_NS=y
  193. +# CONFIG_USER_NS is not set
  194. +CONFIG_PID_NS=y
  195. +CONFIG_NET_NS=y
  196. +# CONFIG_SCHED_AUTOGROUP is not set
  197. +# CONFIG_RELAY is not set
  198. +# CONFIG_BLK_DEV_INITRD is not set
  199. +# CONFIG_CC_OPTIMIZE_FOR_SIZE is not set
  200. +CONFIG_SYSCTL=y
  201. +CONFIG_ANON_INODES=y
  202. +CONFIG_SYSCTL_EXCEPTION_TRACE=y
  203. +CONFIG_EXPERT=y
  204. +# CONFIG_SYSCTL_SYSCALL is not set
  205. +CONFIG_KALLSYMS=y
  206. +# CONFIG_KALLSYMS_ALL is not set
  207. +CONFIG_PRINTK=y
  208. +CONFIG_BUG=y
  209. +CONFIG_ELF_CORE=y
  210. +CONFIG_BASE_FULL=y
  211. +CONFIG_FUTEX=y
  212. +CONFIG_EPOLL=y
  213. +CONFIG_SIGNALFD=y
  214. +CONFIG_TIMERFD=y
  215. +CONFIG_EVENTFD=y
  216. +CONFIG_SHMEM=y
  217. +CONFIG_AIO=y
  218. +CONFIG_EMBEDDED=y
  219. +
  220. +#
  221. +# Kernel Performance Events And Counters
  222. +#
  223. +CONFIG_VM_EVENT_COUNTERS=y
  224. +CONFIG_COMPAT_BRK=y
  225. +# CONFIG_SLAB is not set
  226. +CONFIG_SLUB=y
  227. +# CONFIG_SLOB is not set
  228. +# CONFIG_PROFILING is not set
  229. +CONFIG_HAVE_64BIT_ALIGNED_ACCESS=y
  230. +# CONFIG_CC_STACKPROTECTOR is not set
  231. +CONFIG_HAVE_VIRT_CPU_ACCOUNTING_GEN=y
  232. +CONFIG_CLONE_BACKWARDS=y
  233. +
  234. +#
  235. +# GCOV-based kernel profiling
  236. +#
  237. +# CONFIG_HAVE_GENERIC_DMA_COHERENT is not set
  238. +CONFIG_RT_MUTEXES=y
  239. +CONFIG_BASE_SMALL=0
  240. +# CONFIG_MODULES is not set
  241. +CONFIG_BLOCK=y
  242. +# CONFIG_BLK_DEV_BSG is not set
  243. +# CONFIG_BLK_DEV_BSGLIB is not set
  244. +# CONFIG_BLK_DEV_INTEGRITY is not set
  245. +# CONFIG_BLK_CMDLINE_PARSER is not set
  246. +
  247. +#
  248. +# Partition Types
  249. +#
  250. +CONFIG_PARTITION_ADVANCED=y
  251. +# CONFIG_ACORN_PARTITION is not set
  252. +# CONFIG_AIX_PARTITION is not set
  253. +# CONFIG_OSF_PARTITION is not set
  254. +# CONFIG_AMIGA_PARTITION is not set
  255. +# CONFIG_ATARI_PARTITION is not set
  256. +# CONFIG_MAC_PARTITION is not set
  257. +CONFIG_MSDOS_PARTITION=y
  258. +# CONFIG_BSD_DISKLABEL is not set
  259. +# CONFIG_MINIX_SUBPARTITION is not set
  260. +# CONFIG_SOLARIS_X86_PARTITION is not set
  261. +# CONFIG_UNIXWARE_DISKLABEL is not set
  262. +# CONFIG_LDM_PARTITION is not set
  263. +# CONFIG_SGI_PARTITION is not set
  264. +# CONFIG_ULTRIX_PARTITION is not set
  265. +# CONFIG_SUN_PARTITION is not set
  266. +# CONFIG_KARMA_PARTITION is not set
  267. +# CONFIG_EFI_PARTITION is not set
  268. +# CONFIG_SYSV68_PARTITION is not set
  269. +# CONFIG_CMDLINE_PARTITION is not set
  270. +
  271. +#
  272. +# IO Schedulers
  273. +#
  274. +CONFIG_IOSCHED_NOOP=y
  275. +# CONFIG_IOSCHED_DEADLINE is not set
  276. +CONFIG_IOSCHED_CFQ=y
  277. +CONFIG_DEFAULT_CFQ=y
  278. +# CONFIG_DEFAULT_NOOP is not set
  279. +CONFIG_DEFAULT_IOSCHED="cfq"
  280. +CONFIG_INLINE_SPIN_UNLOCK_IRQ=y
  281. +CONFIG_INLINE_READ_UNLOCK=y
  282. +CONFIG_INLINE_READ_UNLOCK_IRQ=y
  283. +CONFIG_INLINE_WRITE_UNLOCK=y
  284. +CONFIG_INLINE_WRITE_UNLOCK_IRQ=y
  285. +# CONFIG_FREEZER is not set
  286. +
  287. +#
  288. +# Executable file formats
  289. +#
  290. +CONFIG_BINFMT_ELF=y
  291. +CONFIG_CORE_DUMP_DEFAULT_ELF_HEADERS=y
  292. +CONFIG_BINFMT_SCRIPT=y
  293. +# CONFIG_HAVE_AOUT is not set
  294. +# CONFIG_BINFMT_MISC is not set
  295. +CONFIG_COREDUMP=y
  296. +
  297. +#
  298. +# Power management options
  299. +#
  300. +# CONFIG_PM_RUNTIME is not set
  301. +CONFIG_NET=y
  302. +
  303. +#
  304. +# Networking options
  305. +#
  306. +# CONFIG_PACKET is not set
  307. +CONFIG_UNIX=y
  308. +# CONFIG_UNIX_DIAG is not set
  309. +# CONFIG_XFRM_USER is not set
  310. +# CONFIG_NET_KEY is not set
  311. +CONFIG_INET=y
  312. +# CONFIG_IP_MULTICAST is not set
  313. +# CONFIG_IP_ADVANCED_ROUTER is not set
  314. +# CONFIG_IP_PNP is not set
  315. +# CONFIG_NET_IPIP is not set
  316. +# CONFIG_NET_IPGRE_DEMUX is not set
  317. +# CONFIG_NET_IP_TUNNEL is not set
  318. +# CONFIG_SYN_COOKIES is not set
  319. +# CONFIG_INET_AH is not set
  320. +# CONFIG_INET_ESP is not set
  321. +# CONFIG_INET_IPCOMP is not set
  322. +# CONFIG_INET_XFRM_TUNNEL is not set
  323. +# CONFIG_INET_TUNNEL is not set
  324. +# CONFIG_INET_XFRM_MODE_TRANSPORT is not set
  325. +# CONFIG_INET_XFRM_MODE_TUNNEL is not set
  326. +# CONFIG_INET_XFRM_MODE_BEET is not set
  327. +# CONFIG_INET_LRO is not set
  328. +# CONFIG_INET_DIAG is not set
  329. +# CONFIG_TCP_CONG_ADVANCED is not set
  330. +CONFIG_TCP_CONG_CUBIC=y
  331. +CONFIG_DEFAULT_TCP_CONG="cubic"
  332. +# CONFIG_TCP_MD5SIG is not set
  333. +# CONFIG_IPV6 is not set
  334. +# CONFIG_NETWORK_SECMARK is not set
  335. +# CONFIG_NETWORK_PHY_TIMESTAMPING is not set
  336. +# CONFIG_NETFILTER is not set
  337. +# CONFIG_IP_DCCP is not set
  338. +# CONFIG_IP_SCTP is not set
  339. +# CONFIG_RDS is not set
  340. +# CONFIG_TIPC is not set
  341. +# CONFIG_ATM is not set
  342. +# CONFIG_L2TP is not set
  343. +# CONFIG_BRIDGE is not set
  344. +# CONFIG_VLAN_8021Q is not set
  345. +# CONFIG_DECNET is not set
  346. +# CONFIG_LLC2 is not set
  347. +# CONFIG_IPX is not set
  348. +# CONFIG_ATALK is not set
  349. +# CONFIG_X25 is not set
  350. +# CONFIG_LAPB is not set
  351. +# CONFIG_PHONET is not set
  352. +# CONFIG_IEEE802154 is not set
  353. +# CONFIG_NET_SCHED is not set
  354. +# CONFIG_DCB is not set
  355. +# CONFIG_BATMAN_ADV is not set
  356. +# CONFIG_OPENVSWITCH is not set
  357. +# CONFIG_VSOCKETS is not set
  358. +# CONFIG_NETLINK_MMAP is not set
  359. +# CONFIG_NETLINK_DIAG is not set
  360. +# CONFIG_NET_MPLS_GSO is not set
  361. +# CONFIG_HSR is not set
  362. +CONFIG_NET_RX_BUSY_POLL=y
  363. +
  364. +#
  365. +# Network testing
  366. +#
  367. +# CONFIG_NET_PKTGEN is not set
  368. +# CONFIG_HAMRADIO is not set
  369. +# CONFIG_CAN is not set
  370. +# CONFIG_IRDA is not set
  371. +# CONFIG_BT is not set
  372. +# CONFIG_AF_RXRPC is not set
  373. +# CONFIG_WIRELESS is not set
  374. +# CONFIG_WIMAX is not set
  375. +# CONFIG_RFKILL is not set
  376. +# CONFIG_NET_9P is not set
  377. +# CONFIG_CAIF is not set
  378. +# CONFIG_CEPH_LIB is not set
  379. +# CONFIG_NFC is not set
  380. +
  381. +#
  382. +# Device Drivers
  383. +#
  384. +
  385. +#
  386. +# Generic Driver Options
  387. +#
  388. +CONFIG_UEVENT_HELPER_PATH=""
  389. +CONFIG_DEVTMPFS=y
  390. +CONFIG_DEVTMPFS_MOUNT=y
  391. +CONFIG_STANDALONE=y
  392. +CONFIG_PREVENT_FIRMWARE_BUILD=y
  393. +CONFIG_FW_LOADER=y
  394. +# CONFIG_FIRMWARE_IN_KERNEL is not set
  395. +CONFIG_EXTRA_FIRMWARE=""
  396. +CONFIG_FW_LOADER_USER_HELPER=y
  397. +# CONFIG_DEBUG_DRIVER is not set
  398. +# CONFIG_DEBUG_DEVRES is not set
  399. +# CONFIG_SYS_HYPERVISOR is not set
  400. +CONFIG_GENERIC_CPU_DEVICES=y
  401. +# CONFIG_DMA_SHARED_BUFFER is not set
  402. +
  403. +#
  404. +# Bus devices
  405. +#
  406. +# CONFIG_CONNECTOR is not set
  407. +# CONFIG_MTD is not set
  408. +# CONFIG_PARPORT is not set
  409. +# CONFIG_BLK_DEV is not set
  410. +
  411. +#
  412. +# Misc devices
  413. +#
  414. +# CONFIG_SENSORS_LIS3LV02D is not set
  415. +# CONFIG_DUMMY_IRQ is not set
  416. +# CONFIG_ATMEL_SSC is not set
  417. +# CONFIG_ENCLOSURE_SERVICES is not set
  418. +# CONFIG_SRAM is not set
  419. +# CONFIG_C2PORT is not set
  420. +
  421. +#
  422. +# EEPROM support
  423. +#
  424. +# CONFIG_EEPROM_93CX6 is not set
  425. +
  426. +#
  427. +# Texas Instruments shared transport line discipline
  428. +#
  429. +
  430. +#
  431. +# Altera FPGA firmware download module
  432. +#
  433. +
  434. +#
  435. +# Intel MIC Host Driver
  436. +#
  437. +
  438. +#
  439. +# Intel MIC Card Driver
  440. +#
  441. +
  442. +#
  443. +# SCSI device support
  444. +#
  445. +CONFIG_SCSI_MOD=y
  446. +# CONFIG_RAID_ATTRS is not set
  447. +# CONFIG_SCSI is not set
  448. +# CONFIG_SCSI_DMA is not set
  449. +# CONFIG_SCSI_NETLINK is not set
  450. +# CONFIG_ATA is not set
  451. +# CONFIG_MD is not set
  452. +# CONFIG_NETDEVICES is not set
  453. +
  454. +#
  455. +# Input device support
  456. +#
  457. +CONFIG_INPUT=y
  458. +# CONFIG_INPUT_FF_MEMLESS is not set
  459. +# CONFIG_INPUT_POLLDEV is not set
  460. +# CONFIG_INPUT_SPARSEKMAP is not set
  461. +# CONFIG_INPUT_MATRIXKMAP is not set
  462. +
  463. +#
  464. +# Userland interfaces
  465. +#
  466. +# CONFIG_INPUT_MOUSEDEV is not set
  467. +# CONFIG_INPUT_JOYDEV is not set
  468. +# CONFIG_INPUT_EVDEV is not set
  469. +# CONFIG_INPUT_EVBUG is not set
  470. +
  471. +#
  472. +# Input Device Drivers
  473. +#
  474. +# CONFIG_INPUT_KEYBOARD is not set
  475. +# CONFIG_INPUT_MOUSE is not set
  476. +# CONFIG_INPUT_JOYSTICK is not set
  477. +# CONFIG_INPUT_TABLET is not set
  478. +# CONFIG_INPUT_TOUCHSCREEN is not set
  479. +# CONFIG_INPUT_MISC is not set
  480. +
  481. +#
  482. +# Hardware I/O ports
  483. +#
  484. +CONFIG_SERIO=y
  485. +CONFIG_SERIO_SERPORT=y
  486. +# CONFIG_SERIO_LIBPS2 is not set
  487. +# CONFIG_SERIO_RAW is not set
  488. +# CONFIG_SERIO_ALTERA_PS2 is not set
  489. +# CONFIG_SERIO_PS2MULT is not set
  490. +# CONFIG_SERIO_ARC_PS2 is not set
  491. +# CONFIG_GAMEPORT is not set
  492. +
  493. +#
  494. +# Character devices
  495. +#
  496. +CONFIG_TTY=y
  497. +# CONFIG_VT is not set
  498. +CONFIG_UNIX98_PTYS=y
  499. +# CONFIG_DEVPTS_MULTIPLE_INSTANCES is not set
  500. +CONFIG_LEGACY_PTYS=y
  501. +CONFIG_LEGACY_PTY_COUNT=256
  502. +# CONFIG_SERIAL_NONSTANDARD is not set
  503. +# CONFIG_N_GSM is not set
  504. +# CONFIG_TRACE_SINK is not set
  505. +CONFIG_DEVKMEM=y
  506. +
  507. +#
  508. +# Serial drivers
  509. +#
  510. +# CONFIG_SERIAL_8250 is not set
  511. +
  512. +#
  513. +# Non-8250 serial port support
  514. +#
  515. +# CONFIG_SERIAL_SCCNXP is not set
  516. +# CONFIG_SERIAL_TIMBERDALE is not set
  517. +# CONFIG_SERIAL_ALTERA_JTAGUART is not set
  518. +# CONFIG_SERIAL_ALTERA_UART is not set
  519. +# CONFIG_SERIAL_ARC is not set
  520. +# CONFIG_SERIAL_FSL_LPUART is not set
  521. +# CONFIG_TTY_PRINTK is not set
  522. +# CONFIG_IPMI_HANDLER is not set
  523. +# CONFIG_HW_RANDOM is not set
  524. +# CONFIG_RTC is not set
  525. +# CONFIG_GEN_RTC is not set
  526. +# CONFIG_R3964 is not set
  527. +
  528. +#
  529. +# PCMCIA character devices
  530. +#
  531. +# CONFIG_RAW_DRIVER is not set
  532. +# CONFIG_TCG_TPM is not set
  533. +# CONFIG_I2C is not set
  534. +# CONFIG_SPI is not set
  535. +# CONFIG_HSI is not set
  536. +
  537. +#
  538. +# PPS support
  539. +#
  540. +# CONFIG_PPS is not set
  541. +
  542. +#
  543. +# PPS generators support
  544. +#
  545. +
  546. +#
  547. +# PTP clock support
  548. +#
  549. +# CONFIG_PTP_1588_CLOCK is not set
  550. +
  551. +#
  552. +# Enable PHYLIB and NETWORK_PHY_TIMESTAMPING to see the additional clocks.
  553. +#
  554. +# CONFIG_W1 is not set
  555. +# CONFIG_POWER_SUPPLY is not set
  556. +# CONFIG_POWER_AVS is not set
  557. +# CONFIG_HWMON is not set
  558. +# CONFIG_THERMAL is not set
  559. +# CONFIG_WATCHDOG is not set
  560. +
  561. +#
  562. +# Multifunction device drivers
  563. +#
  564. +# CONFIG_MFD_CORE is not set
  565. +# CONFIG_MFD_CROS_EC is not set
  566. +# CONFIG_HTC_PASIC3 is not set
  567. +# CONFIG_MFD_KEMPLD is not set
  568. +# CONFIG_MFD_SM501 is not set
  569. +# CONFIG_ABX500_CORE is not set
  570. +# CONFIG_MFD_SYSCON is not set
  571. +# CONFIG_MFD_TI_AM335X_TSCADC is not set
  572. +# CONFIG_MFD_TMIO is not set
  573. +# CONFIG_REGULATOR is not set
  574. +# CONFIG_MEDIA_SUPPORT is not set
  575. +
  576. +#
  577. +# Graphics support
  578. +#
  579. +# CONFIG_VGASTATE is not set
  580. +# CONFIG_VIDEO_OUTPUT_CONTROL is not set
  581. +CONFIG_FB=y
  582. +# CONFIG_FIRMWARE_EDID is not set
  583. +# CONFIG_FB_DDC is not set
  584. +# CONFIG_FB_BOOT_VESA_SUPPORT is not set
  585. +# CONFIG_FB_CFB_FILLRECT is not set
  586. +# CONFIG_FB_CFB_COPYAREA is not set
  587. +# CONFIG_FB_CFB_IMAGEBLIT is not set
  588. +# CONFIG_FB_CFB_REV_PIXELS_IN_BYTE is not set
  589. +# CONFIG_FB_SYS_FILLRECT is not set
  590. +# CONFIG_FB_SYS_COPYAREA is not set
  591. +# CONFIG_FB_SYS_IMAGEBLIT is not set
  592. +# CONFIG_FB_FOREIGN_ENDIAN is not set
  593. +# CONFIG_FB_SYS_FOPS is not set
  594. +# CONFIG_FB_SVGALIB is not set
  595. +# CONFIG_FB_MACMODES is not set
  596. +# CONFIG_FB_BACKLIGHT is not set
  597. +# CONFIG_FB_MODE_HELPERS is not set
  598. +# CONFIG_FB_TILEBLITTING is not set
  599. +
  600. +#
  601. +# Frame buffer hardware drivers
  602. +#
  603. +# CONFIG_FB_OPENCORES is not set
  604. +# CONFIG_FB_S1D13XXX is not set
  605. +# CONFIG_FB_VIRTUAL is not set
  606. +# CONFIG_FB_METRONOME is not set
  607. +# CONFIG_FB_BROADSHEET is not set
  608. +# CONFIG_FB_AUO_K190X is not set
  609. +# CONFIG_FB_SIMPLE is not set
  610. +# CONFIG_EXYNOS_VIDEO is not set
  611. +# CONFIG_BACKLIGHT_LCD_SUPPORT is not set
  612. +# CONFIG_LOGO is not set
  613. +# CONFIG_SOUND is not set
  614. +
  615. +#
  616. +# HID support
  617. +#
  618. +CONFIG_HID=y
  619. +# CONFIG_HIDRAW is not set
  620. +# CONFIG_UHID is not set
  621. +CONFIG_HID_GENERIC=y
  622. +
  623. +#
  624. +# Special HID drivers
  625. +#
  626. +# CONFIG_HID_A4TECH is not set
  627. +# CONFIG_HID_ACRUX is not set
  628. +# CONFIG_HID_APPLE is not set
  629. +# CONFIG_HID_AUREAL is not set
  630. +# CONFIG_HID_BELKIN is not set
  631. +# CONFIG_HID_CHERRY is not set
  632. +# CONFIG_HID_CHICONY is not set
  633. +# CONFIG_HID_CYPRESS is not set
  634. +# CONFIG_HID_DRAGONRISE is not set
  635. +# CONFIG_HID_EMS_FF is not set
  636. +# CONFIG_HID_ELECOM is not set
  637. +# CONFIG_HID_EZKEY is not set
  638. +# CONFIG_HID_KEYTOUCH is not set
  639. +# CONFIG_HID_KYE is not set
  640. +# CONFIG_HID_UCLOGIC is not set
  641. +# CONFIG_HID_WALTOP is not set
  642. +# CONFIG_HID_GYRATION is not set
  643. +# CONFIG_HID_ICADE is not set
  644. +# CONFIG_HID_TWINHAN is not set
  645. +# CONFIG_HID_KENSINGTON is not set
  646. +# CONFIG_HID_LCPOWER is not set
  647. +# CONFIG_HID_LENOVO_TPKBD is not set
  648. +# CONFIG_HID_LOGITECH is not set
  649. +# CONFIG_HID_MAGICMOUSE is not set
  650. +# CONFIG_HID_MICROSOFT is not set
  651. +# CONFIG_HID_MONTEREY is not set
  652. +# CONFIG_HID_MULTITOUCH is not set
  653. +# CONFIG_HID_ORTEK is not set
  654. +# CONFIG_HID_PANTHERLORD is not set
  655. +# CONFIG_HID_PETALYNX is not set
  656. +# CONFIG_HID_PICOLCD is not set
  657. +# CONFIG_HID_PRIMAX is not set
  658. +# CONFIG_HID_SAITEK is not set
  659. +# CONFIG_HID_SAMSUNG is not set
  660. +# CONFIG_HID_SPEEDLINK is not set
  661. +# CONFIG_HID_STEELSERIES is not set
  662. +# CONFIG_HID_SUNPLUS is not set
  663. +# CONFIG_HID_GREENASIA is not set
  664. +# CONFIG_HID_SMARTJOYPLUS is not set
  665. +# CONFIG_HID_TIVO is not set
  666. +# CONFIG_HID_TOPSEED is not set
  667. +# CONFIG_HID_THRUSTMASTER is not set
  668. +# CONFIG_HID_XINMO is not set
  669. +# CONFIG_HID_ZEROPLUS is not set
  670. +# CONFIG_HID_ZYDACRON is not set
  671. +# CONFIG_HID_SENSOR_HUB is not set
  672. +CONFIG_USB_OHCI_LITTLE_ENDIAN=y
  673. +# CONFIG_USB_SUPPORT is not set
  674. +# CONFIG_MMC is not set
  675. +# CONFIG_MEMSTICK is not set
  676. +# CONFIG_NEW_LEDS is not set
  677. +# CONFIG_ACCESSIBILITY is not set
  678. +# CONFIG_RTC_CLASS is not set
  679. +# CONFIG_AUXDISPLAY is not set
  680. +# CONFIG_UIO is not set
  681. +# CONFIG_VIRT_DRIVERS is not set
  682. +
  683. +#
  684. +# Virtio drivers
  685. +#
  686. +# CONFIG_VIRTIO_MMIO is not set
  687. +
  688. +#
  689. +# Microsoft Hyper-V guest support
  690. +#
  691. +# CONFIG_STAGING is not set
  692. +
  693. +#
  694. +# Hardware Spinlock drivers
  695. +#
  696. +# CONFIG_MAILBOX is not set
  697. +# CONFIG_IOMMU_SUPPORT is not set
  698. +
  699. +#
  700. +# Remoteproc drivers
  701. +#
  702. +
  703. +#
  704. +# Rpmsg drivers
  705. +#
  706. +# CONFIG_PM_DEVFREQ is not set
  707. +# CONFIG_EXTCON is not set
  708. +# CONFIG_MEMORY is not set
  709. +# CONFIG_IIO is not set
  710. +# CONFIG_PWM is not set
  711. +# CONFIG_IPACK_BUS is not set
  712. +# CONFIG_RESET_CONTROLLER is not set
  713. +# CONFIG_FMC is not set
  714. +
  715. +#
  716. +# PHY Subsystem
  717. +#
  718. +# CONFIG_GENERIC_PHY is not set
  719. +# CONFIG_PHY_EXYNOS_MIPI_VIDEO is not set
  720. +# CONFIG_POWERCAP is not set
  721. +
  722. +#
  723. +# File systems
  724. +#
  725. +CONFIG_EXT2_FS=y
  726. +# CONFIG_EXT2_FS_XATTR is not set
  727. +# CONFIG_EXT2_FS_XIP is not set
  728. +# CONFIG_EXT3_FS is not set
  729. +# CONFIG_EXT4_FS is not set
  730. +# CONFIG_REISERFS_FS is not set
  731. +# CONFIG_JFS_FS is not set
  732. +# CONFIG_XFS_FS is not set
  733. +# CONFIG_GFS2_FS is not set
  734. +# CONFIG_BTRFS_FS is not set
  735. +# CONFIG_NILFS2_FS is not set
  736. +# CONFIG_FS_POSIX_ACL is not set
  737. +# CONFIG_FILE_LOCKING is not set
  738. +# CONFIG_FSNOTIFY is not set
  739. +# CONFIG_DNOTIFY is not set
  740. +# CONFIG_INOTIFY_USER is not set
  741. +# CONFIG_FANOTIFY is not set
  742. +# CONFIG_QUOTA is not set
  743. +# CONFIG_QUOTACTL is not set
  744. +# CONFIG_AUTOFS4_FS is not set
  745. +# CONFIG_FUSE_FS is not set
  746. +
  747. +#
  748. +# Caches
  749. +#
  750. +# CONFIG_FSCACHE is not set
  751. +
  752. +#
  753. +# CD-ROM/DVD Filesystems
  754. +#
  755. +# CONFIG_ISO9660_FS is not set
  756. +# CONFIG_UDF_FS is not set
  757. +
  758. +#
  759. +# DOS/FAT/NT Filesystems
  760. +#
  761. +# CONFIG_MSDOS_FS is not set
  762. +# CONFIG_VFAT_FS is not set
  763. +# CONFIG_NTFS_FS is not set
  764. +
  765. +#
  766. +# Pseudo filesystems
  767. +#
  768. +CONFIG_PROC_FS=y
  769. +# CONFIG_PROC_KCORE is not set
  770. +CONFIG_PROC_SYSCTL=y
  771. +# CONFIG_PROC_PAGE_MONITOR is not set
  772. +# CONFIG_SYSFS is not set
  773. +CONFIG_TMPFS=y
  774. +# CONFIG_TMPFS_POSIX_ACL is not set
  775. +# CONFIG_TMPFS_XATTR is not set
  776. +# CONFIG_HUGETLB_PAGE is not set
  777. +# CONFIG_CONFIGFS_FS is not set
  778. +# CONFIG_MISC_FILESYSTEMS is not set
  779. +# CONFIG_NETWORK_FILESYSTEMS is not set
  780. +# CONFIG_NLS is not set
  781. +
  782. +#
  783. +# Kernel hacking
  784. +#
  785. +# CONFIG_CMDLINE_BOOL is not set
  786. +# CONFIG_EARLY_PRINTK is not set
  787. +
  788. +#
  789. +# printk and dmesg options
  790. +#
  791. +CONFIG_PRINTK_TIME=y
  792. +CONFIG_DEFAULT_MESSAGE_LOGLEVEL=4
  793. +# CONFIG_BOOT_PRINTK_DELAY is not set
  794. +
  795. +#
  796. +# Compile-time checks and compiler options
  797. +#
  798. +# CONFIG_DEBUG_INFO is not set
  799. +CONFIG_ENABLE_WARN_DEPRECATED=y
  800. +CONFIG_ENABLE_MUST_CHECK=y
  801. +CONFIG_FRAME_WARN=2048
  802. +# CONFIG_STRIP_ASM_SYMS is not set
  803. +# CONFIG_READABLE_ASM is not set
  804. +# CONFIG_UNUSED_SYMBOLS is not set
  805. +# CONFIG_DEBUG_FS is not set
  806. +# CONFIG_HEADERS_CHECK is not set
  807. +CONFIG_DEBUG_SECTION_MISMATCH=y
  808. +CONFIG_ARCH_WANT_FRAME_POINTERS=y
  809. +# CONFIG_FRAME_POINTER is not set
  810. +# CONFIG_DEBUG_FORCE_WEAK_PER_CPU is not set
  811. +# CONFIG_MAGIC_SYSRQ is not set
  812. +CONFIG_DEBUG_KERNEL=y
  813. +
  814. +#
  815. +# Memory Debugging
  816. +#
  817. +# CONFIG_DEBUG_PAGEALLOC is not set
  818. +# CONFIG_DEBUG_OBJECTS is not set
  819. +# CONFIG_DEBUG_STACK_USAGE is not set
  820. +# CONFIG_DEBUG_VM is not set
  821. +# CONFIG_DEBUG_MEMORY_INIT is not set
  822. +# CONFIG_DEBUG_SHIRQ is not set
  823. +
  824. +#
  825. +# Debug Lockups and Hangs
  826. +#
  827. +# CONFIG_LOCKUP_DETECTOR is not set
  828. +# CONFIG_DETECT_HUNG_TASK is not set
  829. +# CONFIG_PANIC_ON_OOPS is not set
  830. +CONFIG_PANIC_ON_OOPS_VALUE=0
  831. +CONFIG_PANIC_TIMEOUT=0
  832. +CONFIG_SCHED_DEBUG=y
  833. +# CONFIG_SCHEDSTATS is not set
  834. +# CONFIG_TIMER_STATS is not set
  835. +
  836. +#
  837. +# Lock Debugging (spinlocks, mutexes, etc...)
  838. +#
  839. +# CONFIG_DEBUG_RT_MUTEXES is not set
  840. +# CONFIG_RT_MUTEX_TESTER is not set
  841. +# CONFIG_DEBUG_SPINLOCK is not set
  842. +# CONFIG_DEBUG_MUTEXES is not set
  843. +# CONFIG_DEBUG_ATOMIC_SLEEP is not set
  844. +# CONFIG_DEBUG_LOCKING_API_SELFTESTS is not set
  845. +# CONFIG_DEBUG_KOBJECT is not set
  846. +CONFIG_DEBUG_BUGVERBOSE=y
  847. +# CONFIG_DEBUG_WRITECOUNT is not set
  848. +# CONFIG_DEBUG_LIST is not set
  849. +# CONFIG_DEBUG_SG is not set
  850. +# CONFIG_DEBUG_NOTIFIERS is not set
  851. +# CONFIG_DEBUG_CREDENTIALS is not set
  852. +
  853. +#
  854. +# RCU Debugging
  855. +#
  856. +# CONFIG_SPARSE_RCU_POINTER is not set
  857. +# CONFIG_RCU_TORTURE_TEST is not set
  858. +# CONFIG_RCU_TRACE is not set
  859. +# CONFIG_DEBUG_BLOCK_EXT_DEVT is not set
  860. +# CONFIG_NOTIFIER_ERROR_INJECTION is not set
  861. +# CONFIG_FAULT_INJECTION is not set
  862. +
  863. +#
  864. +# Runtime Testing
  865. +#
  866. +# CONFIG_TEST_LIST_SORT is not set
  867. +# CONFIG_BACKTRACE_SELF_TEST is not set
  868. +# CONFIG_RBTREE_TEST is not set
  869. +# CONFIG_ATOMIC64_SELFTEST is not set
  870. +# CONFIG_TEST_STRING_HELPERS is not set
  871. +# CONFIG_TEST_KSTRTOX is not set
  872. +# CONFIG_SAMPLES is not set
  873. +
  874. +#
  875. +# Security options
  876. +#
  877. +# CONFIG_KEYS is not set
  878. +# CONFIG_SECURITY_DMESG_RESTRICT is not set
  879. +# CONFIG_SECURITYFS is not set
  880. +CONFIG_DEFAULT_SECURITY_DAC=y
  881. +CONFIG_DEFAULT_SECURITY=""
  882. +CONFIG_CRYPTO=y
  883. +
  884. +#
  885. +# Crypto core or helper
  886. +#
  887. +CONFIG_CRYPTO_ALGAPI=y
  888. +CONFIG_CRYPTO_ALGAPI2=y
  889. +# CONFIG_CRYPTO_MANAGER is not set
  890. +# CONFIG_CRYPTO_MANAGER2 is not set
  891. +# CONFIG_CRYPTO_USER is not set
  892. +# CONFIG_CRYPTO_GF128MUL is not set
  893. +# CONFIG_CRYPTO_NULL is not set
  894. +# CONFIG_CRYPTO_CRYPTD is not set
  895. +# CONFIG_CRYPTO_AUTHENC is not set
  896. +
  897. +#
  898. +# Authenticated Encryption with Associated Data
  899. +#
  900. +# CONFIG_CRYPTO_CCM is not set
  901. +# CONFIG_CRYPTO_GCM is not set
  902. +# CONFIG_CRYPTO_SEQIV is not set
  903. +
  904. +#
  905. +# Block modes
  906. +#
  907. +# CONFIG_CRYPTO_CBC is not set
  908. +# CONFIG_CRYPTO_CTR is not set
  909. +# CONFIG_CRYPTO_CTS is not set
  910. +# CONFIG_CRYPTO_ECB is not set
  911. +# CONFIG_CRYPTO_LRW is not set
  912. +# CONFIG_CRYPTO_PCBC is not set
  913. +# CONFIG_CRYPTO_XTS is not set
  914. +
  915. +#
  916. +# Hash modes
  917. +#
  918. +# CONFIG_CRYPTO_CMAC is not set
  919. +# CONFIG_CRYPTO_HMAC is not set
  920. +# CONFIG_CRYPTO_XCBC is not set
  921. +# CONFIG_CRYPTO_VMAC is not set
  922. +
  923. +#
  924. +# Digest
  925. +#
  926. +# CONFIG_CRYPTO_CRC32C is not set
  927. +# CONFIG_CRYPTO_CRC32 is not set
  928. +# CONFIG_CRYPTO_CRCT10DIF is not set
  929. +# CONFIG_CRYPTO_GHASH is not set
  930. +# CONFIG_CRYPTO_MD4 is not set
  931. +# CONFIG_CRYPTO_MD5 is not set
  932. +# CONFIG_CRYPTO_MICHAEL_MIC is not set
  933. +# CONFIG_CRYPTO_RMD128 is not set
  934. +# CONFIG_CRYPTO_RMD160 is not set
  935. +# CONFIG_CRYPTO_RMD256 is not set
  936. +# CONFIG_CRYPTO_RMD320 is not set
  937. +# CONFIG_CRYPTO_SHA1 is not set
  938. +# CONFIG_CRYPTO_SHA256 is not set
  939. +# CONFIG_CRYPTO_SHA512 is not set
  940. +# CONFIG_CRYPTO_TGR192 is not set
  941. +# CONFIG_CRYPTO_WP512 is not set
  942. +
  943. +#
  944. +# Ciphers
  945. +#
  946. +CONFIG_CRYPTO_AES=y
  947. +# CONFIG_CRYPTO_ANUBIS is not set
  948. +# CONFIG_CRYPTO_ARC4 is not set
  949. +# CONFIG_CRYPTO_BLOWFISH is not set
  950. +# CONFIG_CRYPTO_CAMELLIA is not set
  951. +# CONFIG_CRYPTO_CAST5 is not set
  952. +# CONFIG_CRYPTO_CAST6 is not set
  953. +# CONFIG_CRYPTO_DES is not set
  954. +# CONFIG_CRYPTO_FCRYPT is not set
  955. +# CONFIG_CRYPTO_KHAZAD is not set
  956. +# CONFIG_CRYPTO_SALSA20 is not set
  957. +# CONFIG_CRYPTO_SEED is not set
  958. +# CONFIG_CRYPTO_SERPENT is not set
  959. +# CONFIG_CRYPTO_TEA is not set
  960. +# CONFIG_CRYPTO_TWOFISH is not set
  961. +
  962. +#
  963. +# Compression
  964. +#
  965. +# CONFIG_CRYPTO_DEFLATE is not set
  966. +# CONFIG_CRYPTO_ZLIB is not set
  967. +# CONFIG_CRYPTO_LZO is not set
  968. +# CONFIG_CRYPTO_LZ4 is not set
  969. +# CONFIG_CRYPTO_LZ4HC is not set
  970. +
  971. +#
  972. +# Random Number Generation
  973. +#
  974. +# CONFIG_CRYPTO_ANSI_CPRNG is not set
  975. +# CONFIG_CRYPTO_USER_API_HASH is not set
  976. +# CONFIG_CRYPTO_USER_API_SKCIPHER is not set
  977. +# CONFIG_CRYPTO_HW is not set
  978. +# CONFIG_BINARY_PRINTF is not set
  979. +
  980. +#
  981. +# Library routines
  982. +#
  983. +CONFIG_BITREVERSE=y
  984. +CONFIG_GENERIC_STRNCPY_FROM_USER=y
  985. +CONFIG_GENERIC_STRNLEN_USER=y
  986. +CONFIG_GENERIC_NET_UTILS=y
  987. +CONFIG_GENERIC_IO=y
  988. +# CONFIG_CRC_CCITT is not set
  989. +# CONFIG_CRC16 is not set
  990. +# CONFIG_CRC_T10DIF is not set
  991. +# CONFIG_CRC_ITU_T is not set
  992. +CONFIG_CRC32=y
  993. +# CONFIG_CRC32_SELFTEST is not set
  994. +CONFIG_CRC32_SLICEBY8=y
  995. +# CONFIG_CRC32_SLICEBY4 is not set
  996. +# CONFIG_CRC32_SARWATE is not set
  997. +# CONFIG_CRC32_BIT is not set
  998. +# CONFIG_CRC7 is not set
  999. +# CONFIG_LIBCRC32C is not set
  1000. +# CONFIG_CRC8 is not set
  1001. +# CONFIG_RANDOM32_SELFTEST is not set
  1002. +# CONFIG_XZ_DEC is not set
  1003. +# CONFIG_XZ_DEC_BCJ is not set
  1004. +CONFIG_HAS_IOMEM=y
  1005. +CONFIG_HAS_IOPORT=y
  1006. +CONFIG_NLATTR=y
  1007. +CONFIG_ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE=y
  1008. +# CONFIG_AVERAGE is not set
  1009. +# CONFIG_CORDIC is not set
  1010. +# CONFIG_DDR is not set
  1011. diff -Nur linux-4.6.2/arch/riscv/.gitignore linux-4.6.2.riscv/arch/riscv/.gitignore
  1012. --- linux-4.6.2/arch/riscv/.gitignore 1970-01-01 01:00:00.000000000 +0100
  1013. +++ linux-4.6.2.riscv/arch/riscv/.gitignore 2017-03-04 02:48:34.162887952 +0100
  1014. @@ -0,0 +1,35 @@
  1015. +# Now un-ignore all files.
  1016. +!*
  1017. +
  1018. +# But then re-ignore the files listed in the Linux .gitignore
  1019. +# Normal rules
  1020. +#
  1021. +.*
  1022. +*.o
  1023. +*.o.*
  1024. +*.a
  1025. +*.s
  1026. +*.ko
  1027. +*.so
  1028. +*.so.dbg
  1029. +*.mod.c
  1030. +*.i
  1031. +*.lst
  1032. +*.symtypes
  1033. +*.order
  1034. +modules.builtin
  1035. +*.elf
  1036. +*.bin
  1037. +*.gz
  1038. +*.bz2
  1039. +*.lzma
  1040. +*.xz
  1041. +*.lzo
  1042. +*.patch
  1043. +*.gcno
  1044. +
  1045. +include/generated
  1046. +kernel/vmlinux.lds
  1047. +
  1048. +# Then reinclude .gitignore.
  1049. +!.gitignore
  1050. diff -Nur linux-4.6.2/arch/riscv/include/asm/asm.h linux-4.6.2.riscv/arch/riscv/include/asm/asm.h
  1051. --- linux-4.6.2/arch/riscv/include/asm/asm.h 1970-01-01 01:00:00.000000000 +0100
  1052. +++ linux-4.6.2.riscv/arch/riscv/include/asm/asm.h 2017-03-04 02:48:34.162887952 +0100
  1053. @@ -0,0 +1,51 @@
  1054. +#ifndef _ASM_RISCV_ASM_H
  1055. +#define _ASM_RISCV_ASM_H
  1056. +
  1057. +#ifdef __ASSEMBLY__
  1058. +#define __ASM_STR(x) x
  1059. +#else
  1060. +#define __ASM_STR(x) #x
  1061. +#endif
  1062. +
  1063. +#if __riscv_xlen == 64
  1064. +#define __REG_SEL(a,b) __ASM_STR(a)
  1065. +#elif __riscv_xlen == 32
  1066. +#define __REG_SEL(a,b) __ASM_STR(b)
  1067. +#else
  1068. +#error "Unexpected __riscv_xlen"
  1069. +#endif
  1070. +
  1071. +#define REG_L __REG_SEL(ld, lw)
  1072. +#define REG_S __REG_SEL(sd, sw)
  1073. +#define SZREG __REG_SEL(8, 4)
  1074. +#define LGREG __REG_SEL(3, 2)
  1075. +
  1076. +#if __SIZEOF_POINTER__ == 8
  1077. +#define __PTR_SEL(a,b) __ASM_STR(a)
  1078. +#elif __SIZEOF_POINTER__ == 4
  1079. +#define __PTR_SEL(a,b) __ASM_STR(b)
  1080. +#else
  1081. +#error "Unexpected __SIZEOF_POINTER__"
  1082. +#endif
  1083. +
  1084. +#define PTR __PTR_SEL(.dword, .word)
  1085. +#define SZPTR __PTR_SEL(8, 4)
  1086. +#define LGPTR __PTR_SEL(3, 2)
  1087. +
  1088. +#if (__SIZEOF_INT__ == 4)
  1089. +#define INT __ASM_STR(.word)
  1090. +#define SZINT __ASM_STR(4)
  1091. +#define LGINT __ASM_STR(2)
  1092. +#else
  1093. +#error "Unexpected __SIZEOF_INT__"
  1094. +#endif
  1095. +
  1096. +#if (__SIZEOF_SHORT__ == 2)
  1097. +#define SHORT __ASM_STR(.half)
  1098. +#define SZSHORT __ASM_STR(2)
  1099. +#define LGSHORT __ASM_STR(1)
  1100. +#else
  1101. +#error "Unexpected __SIZEOF_SHORT__"
  1102. +#endif
  1103. +
  1104. +#endif /* _ASM_RISCV_ASM_H */
  1105. diff -Nur linux-4.6.2/arch/riscv/include/asm/asm-offsets.h linux-4.6.2.riscv/arch/riscv/include/asm/asm-offsets.h
  1106. --- linux-4.6.2/arch/riscv/include/asm/asm-offsets.h 1970-01-01 01:00:00.000000000 +0100
  1107. +++ linux-4.6.2.riscv/arch/riscv/include/asm/asm-offsets.h 2017-03-04 02:48:34.162887952 +0100
  1108. @@ -0,0 +1 @@
  1109. +#include <generated/asm-offsets.h>
  1110. diff -Nur linux-4.6.2/arch/riscv/include/asm/atomic64.h linux-4.6.2.riscv/arch/riscv/include/asm/atomic64.h
  1111. --- linux-4.6.2/arch/riscv/include/asm/atomic64.h 1970-01-01 01:00:00.000000000 +0100
  1112. +++ linux-4.6.2.riscv/arch/riscv/include/asm/atomic64.h 2017-03-04 02:48:34.166888015 +0100
  1113. @@ -0,0 +1,287 @@
  1114. +#ifndef _ASM_RISCV_ATOMIC64_H
  1115. +#define _ASM_RISCV_ATOMIC64_H
  1116. +
  1117. +#ifdef CONFIG_GENERIC_ATOMIC64
  1118. +#include <asm-generic/atomic64.h>
  1119. +#else /* !CONFIG_GENERIC_ATOMIC64 */
  1120. +
  1121. +#include <linux/types.h>
  1122. +
  1123. +#define ATOMIC64_INIT(i) { (i) }
  1124. +
  1125. +/**
  1126. + * atomic64_read - read atomic64 variable
  1127. + * @v: pointer of type atomic64_t
  1128. + *
  1129. + * Atomically reads the value of @v.
  1130. + */
  1131. +static inline s64 atomic64_read(const atomic64_t *v)
  1132. +{
  1133. + return *((volatile long *)(&(v->counter)));
  1134. +}
  1135. +
  1136. +/**
  1137. + * atomic64_set - set atomic64 variable
  1138. + * @v: pointer to type atomic64_t
  1139. + * @i: required value
  1140. + *
  1141. + * Atomically sets the value of @v to @i.
  1142. + */
  1143. +static inline void atomic64_set(atomic64_t *v, s64 i)
  1144. +{
  1145. + v->counter = i;
  1146. +}
  1147. +
  1148. +/**
  1149. + * atomic64_add - add integer to atomic64 variable
  1150. + * @i: integer value to add
  1151. + * @v: pointer to type atomic64_t
  1152. + *
  1153. + * Atomically adds @i to @v.
  1154. + */
  1155. +static inline void atomic64_add(s64 a, atomic64_t *v)
  1156. +{
  1157. + __asm__ __volatile__ (
  1158. + "amoadd.d zero, %1, %0"
  1159. + : "+A" (v->counter)
  1160. + : "r" (a));
  1161. +}
  1162. +
  1163. +/**
  1164. + * atomic64_sub - subtract the atomic64 variable
  1165. + * @i: integer value to subtract
  1166. + * @v: pointer to type atomic64_t
  1167. + *
  1168. + * Atomically subtracts @i from @v.
  1169. + */
  1170. +static inline void atomic64_sub(s64 a, atomic64_t *v)
  1171. +{
  1172. + atomic64_add(-a, v);
  1173. +}
  1174. +
  1175. +/**
  1176. + * atomic64_add_return - add and return
  1177. + * @i: integer value to add
  1178. + * @v: pointer to type atomic64_t
  1179. + *
  1180. + * Atomically adds @i to @v and returns @i + @v
  1181. + */
  1182. +static inline s64 atomic64_add_return(s64 a, atomic64_t *v)
  1183. +{
  1184. + register s64 c;
  1185. + __asm__ __volatile__ (
  1186. + "amoadd.d %0, %2, %1"
  1187. + : "=r" (c), "+A" (v->counter)
  1188. + : "r" (a));
  1189. + return (c + a);
  1190. +}
  1191. +
  1192. +static inline s64 atomic64_sub_return(s64 a, atomic64_t *v)
  1193. +{
  1194. + return atomic64_add_return(-a, v);
  1195. +}
  1196. +
  1197. +/**
  1198. + * atomic64_inc - increment atomic64 variable
  1199. + * @v: pointer to type atomic64_t
  1200. + *
  1201. + * Atomically increments @v by 1.
  1202. + */
  1203. +static inline void atomic64_inc(atomic64_t *v)
  1204. +{
  1205. + atomic64_add(1L, v);
  1206. +}
  1207. +
  1208. +/**
  1209. + * atomic64_dec - decrement atomic64 variable
  1210. + * @v: pointer to type atomic64_t
  1211. + *
  1212. + * Atomically decrements @v by 1.
  1213. + */
  1214. +static inline void atomic64_dec(atomic64_t *v)
  1215. +{
  1216. + atomic64_add(-1L, v);
  1217. +}
  1218. +
  1219. +static inline s64 atomic64_inc_return(atomic64_t *v)
  1220. +{
  1221. + return atomic64_add_return(1L, v);
  1222. +}
  1223. +
  1224. +static inline s64 atomic64_dec_return(atomic64_t *v)
  1225. +{
  1226. + return atomic64_add_return(-1L, v);
  1227. +}
  1228. +
  1229. +/**
  1230. + * atomic64_inc_and_test - increment and test
  1231. + * @v: pointer to type atomic64_t
  1232. + *
  1233. + * Atomically increments @v by 1
  1234. + * and returns true if the result is zero, or false for all
  1235. + * other cases.
  1236. + */
  1237. +static inline int atomic64_inc_and_test(atomic64_t *v)
  1238. +{
  1239. + return (atomic64_inc_return(v) == 0);
  1240. +}
  1241. +
  1242. +/**
  1243. + * atomic64_dec_and_test - decrement and test
  1244. + * @v: pointer to type atomic64_t
  1245. + *
  1246. + * Atomically decrements @v by 1 and
  1247. + * returns true if the result is 0, or false for all other
  1248. + * cases.
  1249. + */
  1250. +static inline int atomic64_dec_and_test(atomic64_t *v)
  1251. +{
  1252. + return (atomic64_dec_return(v) == 0);
  1253. +}
  1254. +
  1255. +/**
  1256. + * atomic64_sub_and_test - subtract value from variable and test result
  1257. + * @a: integer value to subtract
  1258. + * @v: pointer to type atomic64_t
  1259. + *
  1260. + * Atomically subtracts @a from @v and returns
  1261. + * true if the result is zero, or false for all
  1262. + * other cases.
  1263. + */
  1264. +static inline int atomic64_sub_and_test(s64 a, atomic64_t *v)
  1265. +{
  1266. + return (atomic64_sub_return(a, v) == 0);
  1267. +}
  1268. +
  1269. +/**
  1270. + * atomic64_add_negative - add and test if negative
  1271. + * @a: integer value to add
  1272. + * @v: pointer to type atomic64_t
  1273. + *
  1274. + * Atomically adds @a to @v and returns true
  1275. + * if the result is negative, or false when
  1276. + * result is greater than or equal to zero.
  1277. + */
  1278. +static inline int atomic64_add_negative(s64 a, atomic64_t *v)
  1279. +{
  1280. + return (atomic64_add_return(a, v) < 0);
  1281. +}
  1282. +
  1283. +
  1284. +static inline s64 atomic64_xchg(atomic64_t *v, s64 n)
  1285. +{
  1286. + register s64 c;
  1287. + __asm__ __volatile__ (
  1288. + "amoswap.d %0, %2, %1"
  1289. + : "=r" (c), "+A" (v->counter)
  1290. + : "r" (n));
  1291. + return c;
  1292. +}
  1293. +
  1294. +static inline s64 atomic64_cmpxchg(atomic64_t *v, s64 o, s64 n)
  1295. +{
  1296. + return cmpxchg(&(v->counter), o, n);
  1297. +}
  1298. +
  1299. +/*
  1300. + * atomic64_dec_if_positive - decrement by 1 if old value positive
  1301. + * @v: pointer of type atomic_t
  1302. + *
  1303. + * The function returns the old value of *v minus 1, even if
  1304. + * the atomic variable, v, was not decremented.
  1305. + */
  1306. +static inline s64 atomic64_dec_if_positive(atomic64_t *v)
  1307. +{
  1308. + register s64 prev, rc;
  1309. + __asm__ __volatile__ (
  1310. + "0:"
  1311. + "lr.d %0, %2\n"
  1312. + "add %0, %0, -1\n"
  1313. + "bltz %0, 1f\n"
  1314. + "sc.w %1, %0, %2\n"
  1315. + "bnez %1, 0b\n"
  1316. + "1:"
  1317. + : "=&r" (prev), "=r" (rc), "+A" (v->counter));
  1318. + return prev;
  1319. +}
  1320. +
  1321. +/**
  1322. + * atomic64_add_unless - add unless the number is a given value
  1323. + * @v: pointer of type atomic64_t
  1324. + * @a: the amount to add to v...
  1325. + * @u: ...unless v is equal to u.
  1326. + *
  1327. + * Atomically adds @a to @v, so long as it was not @u.
  1328. + * Returns true if the addition occurred and false otherwise.
  1329. + */
  1330. +static inline int atomic64_add_unless(atomic64_t *v, s64 a, s64 u)
  1331. +{
  1332. + register s64 tmp;
  1333. + register int rc = 1;
  1334. +
  1335. + __asm__ __volatile__ (
  1336. + "0:"
  1337. + "lr.d %0, %2\n"
  1338. + "beq %0, %z4, 1f\n"
  1339. + "add %0, %0, %3\n"
  1340. + "sc.d %1, %0, %2\n"
  1341. + "bnez %1, 0b\n"
  1342. + "1:"
  1343. + : "=&r" (tmp), "=&r" (rc), "+A" (v->counter)
  1344. + : "rI" (a), "rJ" (u));
  1345. + return !rc;
  1346. +}
  1347. +
  1348. +static inline int atomic64_inc_not_zero(atomic64_t *v)
  1349. +{
  1350. + return atomic64_add_unless(v, 1, 0);
  1351. +}
  1352. +
  1353. +/**
  1354. + * atomic64_and - Atomically clear bits in atomic variable
  1355. + * @mask: Mask of the bits to be retained
  1356. + * @v: pointer of type atomic_t
  1357. + *
  1358. + * Atomically retains the bits set in @mask from @v
  1359. + */
  1360. +static inline void atomic64_and(s64 mask, atomic64_t *v)
  1361. +{
  1362. + __asm__ __volatile__ (
  1363. + "amoand.d zero, %1, %0"
  1364. + : "+A" (v->counter)
  1365. + : "r" (mask));
  1366. +}
  1367. +
  1368. +/**
  1369. + * atomic64_or - Atomically set bits in atomic variable
  1370. + * @mask: Mask of the bits to be set
  1371. + * @v: pointer of type atomic_t
  1372. + *
  1373. + * Atomically sets the bits set in @mask in @v
  1374. + */
  1375. +static inline void atomic64_or(s64 mask, atomic64_t *v)
  1376. +{
  1377. + __asm__ __volatile__ (
  1378. + "amoor.d zero, %1, %0"
  1379. + : "+A" (v->counter)
  1380. + : "r" (mask));
  1381. +}
  1382. +
  1383. +/**
  1384. + * atomic64_xor - Atomically flips bits in atomic variable
  1385. + * @mask: Mask of the bits to be flipped
  1386. + * @v: pointer of type atomic_t
  1387. + *
  1388. + * Atomically flips the bits set in @mask in @v
  1389. + */
  1390. +static inline void atomic64_xor(s64 mask, atomic64_t *v)
  1391. +{
  1392. + __asm__ __volatile__ (
  1393. + "amoxor.d zero, %1, %0"
  1394. + : "+A" (v->counter)
  1395. + : "r" (mask));
  1396. +}
  1397. +
  1398. +#endif /* CONFIG_GENERIC_ATOMIC64 */
  1399. +
  1400. +#endif /* _ASM_RISCV_ATOMIC64_H */
  1401. diff -Nur linux-4.6.2/arch/riscv/include/asm/atomic.h linux-4.6.2.riscv/arch/riscv/include/asm/atomic.h
  1402. --- linux-4.6.2/arch/riscv/include/asm/atomic.h 1970-01-01 01:00:00.000000000 +0100
  1403. +++ linux-4.6.2.riscv/arch/riscv/include/asm/atomic.h 2017-03-04 02:48:34.166888015 +0100
  1404. @@ -0,0 +1,276 @@
  1405. +#ifndef _ASM_RISCV_ATOMIC_H
  1406. +#define _ASM_RISCV_ATOMIC_H
  1407. +
  1408. +#ifdef CONFIG_RV_ATOMIC
  1409. +
  1410. +#include <asm/cmpxchg.h>
  1411. +#include <asm/barrier.h>
  1412. +
  1413. +#define ATOMIC_INIT(i) { (i) }
  1414. +
  1415. +/**
  1416. + * atomic_read - read atomic variable
  1417. + * @v: pointer of type atomic_t
  1418. + *
  1419. + * Atomically reads the value of @v.
  1420. + */
  1421. +static inline int atomic_read(const atomic_t *v)
  1422. +{
  1423. + return *((volatile int *)(&(v->counter)));
  1424. +}
  1425. +
  1426. +/**
  1427. + * atomic_set - set atomic variable
  1428. + * @v: pointer of type atomic_t
  1429. + * @i: required value
  1430. + *
  1431. + * Atomically sets the value of @v to @i.
  1432. + */
  1433. +static inline void atomic_set(atomic_t *v, int i)
  1434. +{
  1435. + v->counter = i;
  1436. +}
  1437. +
  1438. +/**
  1439. + * atomic_add - add integer to atomic variable
  1440. + * @i: integer value to add
  1441. + * @v: pointer of type atomic_t
  1442. + *
  1443. + * Atomically adds @i to @v.
  1444. + */
  1445. +static inline void atomic_add(int i, atomic_t *v)
  1446. +{
  1447. + __asm__ __volatile__ (
  1448. + "amoadd.w zero, %1, %0"
  1449. + : "+A" (v->counter)
  1450. + : "r" (i));
  1451. +}
  1452. +
  1453. +/**
  1454. + * atomic_sub - subtract integer from atomic variable
  1455. + * @i: integer value to subtract
  1456. + * @v: pointer of type atomic_t
  1457. + *
  1458. + * Atomically subtracts @i from @v.
  1459. + */
  1460. +static inline void atomic_sub(int i, atomic_t *v)
  1461. +{
  1462. + atomic_add(-i, v);
  1463. +}
  1464. +
  1465. +/**
  1466. + * atomic_add_return - add integer to atomic variable
  1467. + * @i: integer value to add
  1468. + * @v: pointer of type atomic_t
  1469. + *
  1470. + * Atomically adds @i to @v and returns the result
  1471. + */
  1472. +static inline int atomic_add_return(int i, atomic_t *v)
  1473. +{
  1474. + register int c;
  1475. + __asm__ __volatile__ (
  1476. + "amoadd.w %0, %2, %1"
  1477. + : "=r" (c), "+A" (v->counter)
  1478. + : "r" (i));
  1479. + return (c + i);
  1480. +}
  1481. +
  1482. +/**
  1483. + * atomic_sub_return - subtract integer from atomic variable
  1484. + * @i: integer value to subtract
  1485. + * @v: pointer of type atomic_t
  1486. + *
  1487. + * Atomically subtracts @i from @v and returns the result
  1488. + */
  1489. +static inline int atomic_sub_return(int i, atomic_t *v)
  1490. +{
  1491. + return atomic_add_return(-i, v);
  1492. +}
  1493. +
  1494. +/**
  1495. + * atomic_inc - increment atomic variable
  1496. + * @v: pointer of type atomic_t
  1497. + *
  1498. + * Atomically increments @v by 1.
  1499. + */
  1500. +static inline void atomic_inc(atomic_t *v)
  1501. +{
  1502. + atomic_add(1, v);
  1503. +}
  1504. +
  1505. +/**
  1506. + * atomic_dec - decrement atomic variable
  1507. + * @v: pointer of type atomic_t
  1508. + *
  1509. + * Atomically decrements @v by 1.
  1510. + */
  1511. +static inline void atomic_dec(atomic_t *v)
  1512. +{
  1513. + atomic_add(-1, v);
  1514. +}
  1515. +
  1516. +static inline int atomic_inc_return(atomic_t *v)
  1517. +{
  1518. + return atomic_add_return(1, v);
  1519. +}
  1520. +
  1521. +static inline int atomic_dec_return(atomic_t *v)
  1522. +{
  1523. + return atomic_sub_return(1, v);
  1524. +}
  1525. +
  1526. +/**
  1527. + * atomic_sub_and_test - subtract value from variable and test result
  1528. + * @i: integer value to subtract
  1529. + * @v: pointer of type atomic_t
  1530. + *
  1531. + * Atomically subtracts @i from @v and returns
  1532. + * true if the result is zero, or false for all
  1533. + * other cases.
  1534. + */
  1535. +static inline int atomic_sub_and_test(int i, atomic_t *v)
  1536. +{
  1537. + return (atomic_sub_return(i, v) == 0);
  1538. +}
  1539. +
  1540. +/**
  1541. + * atomic_inc_and_test - increment and test
  1542. + * @v: pointer of type atomic_t
  1543. + *
  1544. + * Atomically increments @v by 1
  1545. + * and returns true if the result is zero, or false for all
  1546. + * other cases.
  1547. + */
  1548. +static inline int atomic_inc_and_test(atomic_t *v)
  1549. +{
  1550. + return (atomic_inc_return(v) == 0);
  1551. +}
  1552. +
  1553. +/**
  1554. + * atomic_dec_and_test - decrement and test
  1555. + * @v: pointer of type atomic_t
  1556. + *
  1557. + * Atomically decrements @v by 1 and
  1558. + * returns true if the result is 0, or false for all other
  1559. + * cases.
  1560. + */
  1561. +static inline int atomic_dec_and_test(atomic_t *v)
  1562. +{
  1563. + return (atomic_dec_return(v) == 0);
  1564. +}
  1565. +
  1566. +/**
  1567. + * atomic_add_negative - add and test if negative
  1568. + * @i: integer value to add
  1569. + * @v: pointer of type atomic_t
  1570. + *
  1571. + * Atomically adds @i to @v and returns true
  1572. + * if the result is negative, or false when
  1573. + * result is greater than or equal to zero.
  1574. + */
  1575. +static inline int atomic_add_negative(int i, atomic_t *v)
  1576. +{
  1577. + return (atomic_add_return(i, v) < 0);
  1578. +}
  1579. +
  1580. +
  1581. +static inline int atomic_xchg(atomic_t *v, int n)
  1582. +{
  1583. + register int c;
  1584. + __asm__ __volatile__ (
  1585. + "amoswap.w %0, %2, %1"
  1586. + : "=r" (c), "+A" (v->counter)
  1587. + : "r" (n));
  1588. + return c;
  1589. +}
  1590. +
  1591. +static inline int atomic_cmpxchg(atomic_t *v, int o, int n)
  1592. +{
  1593. + return cmpxchg(&(v->counter), o, n);
  1594. +}
  1595. +
  1596. +/**
  1597. + * __atomic_add_unless - add unless the number is already a given value
  1598. + * @v: pointer of type atomic_t
  1599. + * @a: the amount to add to v...
  1600. + * @u: ...unless v is equal to u.
  1601. + *
  1602. + * Atomically adds @a to @v, so long as @v was not already @u.
  1603. + * Returns the old value of @v.
  1604. + */
  1605. +static inline int __atomic_add_unless(atomic_t *v, int a, int u)
  1606. +{
  1607. + register int prev, rc;
  1608. + __asm__ __volatile__ (
  1609. + "0:"
  1610. + "lr.w %0, %2\n"
  1611. + "beq %0, %4, 1f\n"
  1612. + "add %1, %0, %3\n"
  1613. + "sc.w %1, %1, %2\n"
  1614. + "bnez %1, 0b\n"
  1615. + "1:"
  1616. + : "=&r" (prev), "=&r" (rc), "+A" (v->counter)
  1617. + : "r" (a), "r" (u));
  1618. + return prev;
  1619. +}
  1620. +
  1621. +/**
  1622. + * atomic_and - Atomically clear bits in atomic variable
  1623. + * @mask: Mask of the bits to be retained
  1624. + * @v: pointer of type atomic_t
  1625. + *
  1626. + * Atomically retains the bits set in @mask from @v
  1627. + */
  1628. +static inline void atomic_and(unsigned int mask, atomic_t *v)
  1629. +{
  1630. + __asm__ __volatile__ (
  1631. + "amoand.w zero, %1, %0"
  1632. + : "+A" (v->counter)
  1633. + : "r" (mask));
  1634. +}
  1635. +
  1636. +/**
  1637. + * atomic_or - Atomically set bits in atomic variable
  1638. + * @mask: Mask of the bits to be set
  1639. + * @v: pointer of type atomic_t
  1640. + *
  1641. + * Atomically sets the bits set in @mask in @v
  1642. + */
  1643. +static inline void atomic_or(unsigned int mask, atomic_t *v)
  1644. +{
  1645. + __asm__ __volatile__ (
  1646. + "amoor.w zero, %1, %0"
  1647. + : "+A" (v->counter)
  1648. + : "r" (mask));
  1649. +}
  1650. +
  1651. +/**
  1652. + * atomic_xor - Atomically flips bits in atomic variable
  1653. + * @mask: Mask of the bits to be flipped
  1654. + * @v: pointer of type atomic_t
  1655. + *
  1656. + * Atomically flips the bits set in @mask in @v
  1657. + */
  1658. +static inline void atomic_xor(unsigned int mask, atomic_t *v)
  1659. +{
  1660. + __asm__ __volatile__ (
  1661. + "amoxor.w zero, %1, %0"
  1662. + : "+A" (v->counter)
  1663. + : "r" (mask));
  1664. +}
  1665. +
  1666. +/* Assume that atomic operations are already serializing */
  1667. +#define smp_mb__before_atomic_dec() barrier()
  1668. +#define smp_mb__after_atomic_dec() barrier()
  1669. +#define smp_mb__before_atomic_inc() barrier()
  1670. +#define smp_mb__after_atomic_inc() barrier()
  1671. +
  1672. +#else /* !CONFIG_RV_ATOMIC */
  1673. +
  1674. +#include <asm-generic/atomic.h>
  1675. +
  1676. +#endif /* CONFIG_RV_ATOMIC */
  1677. +
  1678. +#include <asm/atomic64.h>
  1679. +
  1680. +#endif /* _ASM_RISCV_ATOMIC_H */
  1681. diff -Nur linux-4.6.2/arch/riscv/include/asm/barrier.h linux-4.6.2.riscv/arch/riscv/include/asm/barrier.h
  1682. --- linux-4.6.2/arch/riscv/include/asm/barrier.h 1970-01-01 01:00:00.000000000 +0100
  1683. +++ linux-4.6.2.riscv/arch/riscv/include/asm/barrier.h 2017-03-04 02:48:34.166888015 +0100
  1684. @@ -0,0 +1,14 @@
  1685. +#ifndef _ASM_RISCV_BARRIER_H
  1686. +#define _ASM_RISCV_BARRIER_H
  1687. +
  1688. +#ifndef __ASSEMBLY__
  1689. +
  1690. +#define nop() __asm__ __volatile__ ("nop")
  1691. +
  1692. +#define mb() __asm__ __volatile__ ("fence" : : : "memory")
  1693. +
  1694. +#include <asm-generic/barrier.h>
  1695. +
  1696. +#endif /* __ASSEMBLY__ */
  1697. +
  1698. +#endif /* _ASM_RISCV_BARRIER_H */
  1699. diff -Nur linux-4.6.2/arch/riscv/include/asm/bitops.h linux-4.6.2.riscv/arch/riscv/include/asm/bitops.h
  1700. --- linux-4.6.2/arch/riscv/include/asm/bitops.h 1970-01-01 01:00:00.000000000 +0100
  1701. +++ linux-4.6.2.riscv/arch/riscv/include/asm/bitops.h 2017-03-04 02:48:34.166888015 +0100
  1702. @@ -0,0 +1,271 @@
  1703. +#ifndef _ASM_RISCV_BITOPS_H
  1704. +#define _ASM_RISCV_BITOPS_H
  1705. +
  1706. +#ifndef _LINUX_BITOPS_H
  1707. +#error "Only <linux/bitops.h> can be included directly"
  1708. +#endif /* _LINUX_BITOPS_H */
  1709. +
  1710. +#ifdef __KERNEL__
  1711. +
  1712. +#include <linux/compiler.h>
  1713. +#include <linux/irqflags.h>
  1714. +#include <asm/barrier.h>
  1715. +#include <asm/bitsperlong.h>
  1716. +
  1717. +#ifdef CONFIG_RV_ATOMIC
  1718. +
  1719. +#ifndef smp_mb__before_clear_bit
  1720. +#define smp_mb__before_clear_bit() smp_mb()
  1721. +#define smp_mb__after_clear_bit() smp_mb()
  1722. +#endif /* smp_mb__before_clear_bit */
  1723. +
  1724. +/**
  1725. + * __ffs - find first bit in word.
  1726. + * @word: The word to search
  1727. + *
  1728. + * Undefined if no bit exists, so code should check against 0 first.
  1729. + */
  1730. +/*
  1731. +static __always_inline unsigned long __ffs(unsigned long word)
  1732. +{
  1733. + return 0;
  1734. +}
  1735. +*/
  1736. +#include <asm-generic/bitops/__ffs.h>
  1737. +
  1738. +#include <asm-generic/bitops/ffz.h>
  1739. +
  1740. +/**
  1741. + * fls - find last (most-significant) bit set
  1742. + * @x: the word to search
  1743. + *
  1744. + * This is defined the same way as ffs.
  1745. + * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
  1746. + */
  1747. +/*
  1748. +static __always_inline int fls(int x)
  1749. +{
  1750. + return 0;
  1751. +}
  1752. +*/
  1753. +#include <asm-generic/bitops/fls.h>
  1754. +
  1755. +/**
  1756. + * __fls - find last (most-significant) set bit in a long word
  1757. + * @word: the word to search
  1758. + *
  1759. + * Undefined if no set bit exists, so code should check against 0 first.
  1760. + */
  1761. +/*
  1762. +static __always_inline unsigned long __fls(unsigned long word)
  1763. +{
  1764. + return 0;
  1765. +}
  1766. +*/
  1767. +#include <asm-generic/bitops/__fls.h>
  1768. +
  1769. +#include <asm-generic/bitops/fls64.h>
  1770. +#include <asm-generic/bitops/find.h>
  1771. +#include <asm-generic/bitops/sched.h>
  1772. +
  1773. +/**
  1774. + * ffs - find first bit set
  1775. + * @x: the word to search
  1776. + *
  1777. + * This is defined the same way as
  1778. + * the libc and compiler builtin ffs routines, therefore
  1779. + * differs in spirit from the above ffz (man ffs).
  1780. + */
  1781. +/*
  1782. +static __always_inline int ffs(int x)
  1783. +{
  1784. + return 0;
  1785. +}
  1786. +*/
  1787. +#include <asm-generic/bitops/ffs.h>
  1788. +
  1789. +#include <asm-generic/bitops/hweight.h>
  1790. +
  1791. +#if (BITS_PER_LONG == 64)
  1792. +#define __AMO(op) "amo" #op ".d"
  1793. +#elif (BITS_PER_LONG == 32)
  1794. +#define __AMO(op) "amo" #op ".w"
  1795. +#else
  1796. +#error "Unexpected BITS_PER_LONG"
  1797. +#endif
  1798. +
  1799. +#define __test_and_op_bit(op, mod, nr, addr) \
  1800. +({ \
  1801. + unsigned long __res, __mask; \
  1802. + __mask = BIT_MASK(nr); \
  1803. + __asm__ __volatile__ ( \
  1804. + __AMO(op) " %0, %2, %1" \
  1805. + : "=r" (__res), "+A" (addr[BIT_WORD(nr)]) \
  1806. + : "r" (mod(__mask))); \
  1807. + ((__res & __mask) != 0); \
  1808. +})
  1809. +
  1810. +#define __op_bit(op, mod, nr, addr) \
  1811. + __asm__ __volatile__ ( \
  1812. + __AMO(op) " zero, %1, %0" \
  1813. + : "+A" (addr[BIT_WORD(nr)]) \
  1814. + : "r" (mod(BIT_MASK(nr))))
  1815. +
  1816. +/* Bitmask modifiers */
  1817. +#define __NOP(x) (x)
  1818. +#define __NOT(x) (~(x))
  1819. +
  1820. +/**
  1821. + * test_and_set_bit - Set a bit and return its old value
  1822. + * @nr: Bit to set
  1823. + * @addr: Address to count from
  1824. + *
  1825. + * This operation is atomic and cannot be reordered.
  1826. + * It may be reordered on other architectures than x86.
  1827. + * It also implies a memory barrier.
  1828. + */
  1829. +static inline int test_and_set_bit(int nr, volatile unsigned long *addr)
  1830. +{
  1831. + return __test_and_op_bit(or, __NOP, nr, addr);
  1832. +}
  1833. +
  1834. +/**
  1835. + * test_and_clear_bit - Clear a bit and return its old value
  1836. + * @nr: Bit to clear
  1837. + * @addr: Address to count from
  1838. + *
  1839. + * This operation is atomic and cannot be reordered.
  1840. + * It can be reordered on other architectures other than x86.
  1841. + * It also implies a memory barrier.
  1842. + */
  1843. +static inline int test_and_clear_bit(int nr, volatile unsigned long *addr)
  1844. +{
  1845. + return __test_and_op_bit(and, __NOT, nr, addr);
  1846. +}
  1847. +
  1848. +/**
  1849. + * test_and_change_bit - Change a bit and return its old value
  1850. + * @nr: Bit to change
  1851. + * @addr: Address to count from
  1852. + *
  1853. + * This operation is atomic and cannot be reordered.
  1854. + * It also implies a memory barrier.
  1855. + */
  1856. +static inline int test_and_change_bit(int nr, volatile unsigned long *addr)
  1857. +{
  1858. + return __test_and_op_bit(xor, __NOP, nr, addr);
  1859. +}
  1860. +
  1861. +/**
  1862. + * set_bit - Atomically set a bit in memory
  1863. + * @nr: the bit to set
  1864. + * @addr: the address to start counting from
  1865. + *
  1866. + * This function is atomic and may not be reordered. See __set_bit()
  1867. + * if you do not require the atomic guarantees.
  1868. + *
  1869. + * Note: there are no guarantees that this function will not be reordered
  1870. + * on non x86 architectures, so if you are writing portable code,
  1871. + * make sure not to rely on its reordering guarantees.
  1872. + *
  1873. + * Note that @nr may be almost arbitrarily large; this function is not
  1874. + * restricted to acting on a single-word quantity.
  1875. + */
  1876. +static inline void set_bit(int nr, volatile unsigned long *addr)
  1877. +{
  1878. + __op_bit(or, __NOP, nr, addr);
  1879. +}
  1880. +
  1881. +/**
  1882. + * clear_bit - Clears a bit in memory
  1883. + * @nr: Bit to clear
  1884. + * @addr: Address to start counting from
  1885. + *
  1886. + * clear_bit() is atomic and may not be reordered. However, it does
  1887. + * not contain a memory barrier, so if it is used for locking purposes,
  1888. + * you should call smp_mb__before_clear_bit() and/or smp_mb__after_clear_bit()
  1889. + * in order to ensure changes are visible on other processors.
  1890. + */
  1891. +static inline void clear_bit(int nr, volatile unsigned long *addr)
  1892. +{
  1893. + __op_bit(and, __NOT, nr, addr);
  1894. +}
  1895. +
  1896. +/**
  1897. + * change_bit - Toggle a bit in memory
  1898. + * @nr: Bit to change
  1899. + * @addr: Address to start counting from
  1900. + *
  1901. + * change_bit() is atomic and may not be reordered. It may be
  1902. + * reordered on other architectures than x86.
  1903. + * Note that @nr may be almost arbitrarily large; this function is not
  1904. + * restricted to acting on a single-word quantity.
  1905. + */
  1906. +static inline void change_bit(int nr, volatile unsigned long *addr)
  1907. +{
  1908. + __op_bit(xor, __NOP, nr, addr);
  1909. +}
  1910. +
  1911. +/**
  1912. + * test_and_set_bit_lock - Set a bit and return its old value, for lock
  1913. + * @nr: Bit to set
  1914. + * @addr: Address to count from
  1915. + *
  1916. + * This operation is atomic and provides acquire barrier semantics.
  1917. + * It can be used to implement bit locks.
  1918. + */
  1919. +static inline int test_and_set_bit_lock(
  1920. + unsigned long nr, volatile unsigned long *addr)
  1921. +{
  1922. + return test_and_set_bit(nr, addr);
  1923. +}
  1924. +
  1925. +/**
  1926. + * clear_bit_unlock - Clear a bit in memory, for unlock
  1927. + * @nr: the bit to set
  1928. + * @addr: the address to start counting from
  1929. + *
  1930. + * This operation is atomic and provides release barrier semantics.
  1931. + */
  1932. +static inline void clear_bit_unlock(
  1933. + unsigned long nr, volatile unsigned long *addr)
  1934. +{
  1935. + clear_bit(nr, addr);
  1936. +}
  1937. +
  1938. +/**
  1939. + * __clear_bit_unlock - Clear a bit in memory, for unlock
  1940. + * @nr: the bit to set
  1941. + * @addr: the address to start counting from
  1942. + *
  1943. + * This operation is like clear_bit_unlock, however it is not atomic.
  1944. + * It does provide release barrier semantics so it can be used to unlock
  1945. + * a bit lock, however it would only be used if no other CPU can modify
  1946. + * any bits in the memory until the lock is released (a good example is
  1947. + * if the bit lock itself protects access to the other bits in the word).
  1948. + */
  1949. +static inline void __clear_bit_unlock(
  1950. + unsigned long nr, volatile unsigned long *addr)
  1951. +{
  1952. + clear_bit(nr, addr);
  1953. +}
  1954. +
  1955. +#undef __test_and_op_bit
  1956. +#undef __op_bit
  1957. +#undef __NOP
  1958. +#undef __NOT
  1959. +#undef __AMO
  1960. +
  1961. +#include <asm-generic/bitops/non-atomic.h>
  1962. +#include <asm-generic/bitops/le.h>
  1963. +#include <asm-generic/bitops/ext2-atomic.h>
  1964. +
  1965. +#else /* !CONFIG_RV_ATOMIC */
  1966. +
  1967. +#include <asm-generic/bitops.h>
  1968. +
  1969. +#endif /* CONFIG_RV_ATOMIC */
  1970. +
  1971. +#endif /* __KERNEL__ */
  1972. +
  1973. +#endif /* _ASM_RISCV_BITOPS_H */
  1974. diff -Nur linux-4.6.2/arch/riscv/include/asm/bug.h linux-4.6.2.riscv/arch/riscv/include/asm/bug.h
  1975. --- linux-4.6.2/arch/riscv/include/asm/bug.h 1970-01-01 01:00:00.000000000 +0100
  1976. +++ linux-4.6.2.riscv/arch/riscv/include/asm/bug.h 2017-03-04 02:48:34.166888015 +0100
  1977. @@ -0,0 +1,67 @@
  1978. +#ifndef _ASM_RISCV_BUG_H
  1979. +#define _ASM_RISCV_BUG_H
  1980. +
  1981. +#include <linux/compiler.h>
  1982. +#include <linux/const.h>
  1983. +#include <linux/types.h>
  1984. +
  1985. +#include <asm/asm.h>
  1986. +
  1987. +#ifdef CONFIG_GENERIC_BUG
  1988. +#define __BUG_INSN _AC(0x00100073,UL) /* sbreak */
  1989. +
  1990. +#ifndef __ASSEMBLY__
  1991. +typedef u32 bug_insn_t;
  1992. +
  1993. +#ifdef CONFIG_GENERIC_BUG_RELATIVE_POINTERS
  1994. +#define __BUG_ENTRY_ADDR INT " 1b - 2b"
  1995. +#define __BUG_ENTRY_FILE INT " %0 - 2b"
  1996. +#else
  1997. +#define __BUG_ENTRY_ADDR PTR " 1b"
  1998. +#define __BUG_ENTRY_FILE PTR " %0"
  1999. +#endif
  2000. +
  2001. +#ifdef CONFIG_DEBUG_BUGVERBOSE
  2002. +#define __BUG_ENTRY \
  2003. + __BUG_ENTRY_ADDR "\n\t" \
  2004. + __BUG_ENTRY_FILE "\n\t" \
  2005. + SHORT " %1"
  2006. +#else
  2007. +#define __BUG_ENTRY \
  2008. + __BUG_ENTRY_ADDR
  2009. +#endif
  2010. +
  2011. +#define BUG() \
  2012. +do { \
  2013. + __asm__ __volatile__ ( \
  2014. + "1:\n\t" \
  2015. + "sbreak\n" \
  2016. + ".pushsection __bug_table,\"a\"\n\t" \
  2017. + "2:\n\t" \
  2018. + __BUG_ENTRY "\n\t" \
  2019. + ".org 2b + %2\n\t" \
  2020. + ".popsection" \
  2021. + : \
  2022. + : "i" (__FILE__), "i" (__LINE__), \
  2023. + "i" (sizeof(struct bug_entry))); \
  2024. + unreachable(); \
  2025. +} while (0)
  2026. +
  2027. +#define HAVE_ARCH_BUG
  2028. +#endif /* !__ASSEMBLY__ */
  2029. +#endif /* CONFIG_GENERIC_BUG */
  2030. +
  2031. +#include <asm-generic/bug.h>
  2032. +
  2033. +#ifndef __ASSEMBLY__
  2034. +
  2035. +struct pt_regs;
  2036. +struct task_struct;
  2037. +
  2038. +extern void die(struct pt_regs *regs, const char *str);
  2039. +extern void do_trap(struct pt_regs *regs, int signo, int code,
  2040. + unsigned long addr, struct task_struct *tsk);
  2041. +
  2042. +#endif /* !__ASSEMBLY__ */
  2043. +
  2044. +#endif /* _ASM_RISCV_BUG_H */
  2045. diff -Nur linux-4.6.2/arch/riscv/include/asm/cacheflush.h linux-4.6.2.riscv/arch/riscv/include/asm/cacheflush.h
  2046. --- linux-4.6.2/arch/riscv/include/asm/cacheflush.h 1970-01-01 01:00:00.000000000 +0100
  2047. +++ linux-4.6.2.riscv/arch/riscv/include/asm/cacheflush.h 2017-03-04 02:48:34.166888015 +0100
  2048. @@ -0,0 +1,26 @@
  2049. +#ifndef _ASM_RISCV_CACHEFLUSH_H
  2050. +#define _ASM_RISCV_CACHEFLUSH_H
  2051. +
  2052. +#include <asm-generic/cacheflush.h>
  2053. +
  2054. +#undef flush_icache_range
  2055. +#undef flush_icache_user_range
  2056. +
  2057. +static inline void local_flush_icache_all(void)
  2058. +{
  2059. + asm volatile ("fence.i" ::: "memory");
  2060. +}
  2061. +
  2062. +#ifndef CONFIG_SMP
  2063. +
  2064. +#define flush_icache_range(start, end) local_flush_icache_all()
  2065. +#define flush_icache_user_range(vma, pg, addr, len) local_flush_icache_all()
  2066. +
  2067. +#else /* CONFIG_SMP */
  2068. +
  2069. +#define flush_icache_range(start, end) sbi_remote_fence_i(0)
  2070. +#define flush_icache_user_range(vma, pg, addr, len) sbi_remote_fence_i(0)
  2071. +
  2072. +#endif /* CONFIG_SMP */
  2073. +
  2074. +#endif /* _ASM_RISCV_CACHEFLUSH_H */
  2075. diff -Nur linux-4.6.2/arch/riscv/include/asm/cache.h linux-4.6.2.riscv/arch/riscv/include/asm/cache.h
  2076. --- linux-4.6.2/arch/riscv/include/asm/cache.h 1970-01-01 01:00:00.000000000 +0100
  2077. +++ linux-4.6.2.riscv/arch/riscv/include/asm/cache.h 2017-03-04 02:48:34.166888015 +0100
  2078. @@ -0,0 +1,12 @@
  2079. +#ifndef _ASM_RISCV_CACHE_H
  2080. +#define _ASM_RISCV_CACHE_H
  2081. +
  2082. +#if defined(CONFIG_CPU_RV_ROCKET)
  2083. +#define L1_CACHE_SHIFT 6
  2084. +#else
  2085. +#define L1_CACHE_SHIFT 5
  2086. +#endif
  2087. +
  2088. +#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
  2089. +
  2090. +#endif /* _ASM_RISCV_CACHE_H */
  2091. diff -Nur linux-4.6.2/arch/riscv/include/asm/cmpxchg.h linux-4.6.2.riscv/arch/riscv/include/asm/cmpxchg.h
  2092. --- linux-4.6.2/arch/riscv/include/asm/cmpxchg.h 1970-01-01 01:00:00.000000000 +0100
  2093. +++ linux-4.6.2.riscv/arch/riscv/include/asm/cmpxchg.h 2017-03-04 02:48:34.166888015 +0100
  2094. @@ -0,0 +1,111 @@
  2095. +#ifndef _ASM_RISCV_CMPXCHG_H
  2096. +#define _ASM_RISCV_CMPXCHG_H
  2097. +
  2098. +#include <linux/bug.h>
  2099. +
  2100. +#ifdef CONFIG_RV_ATOMIC
  2101. +
  2102. +#include <asm/barrier.h>
  2103. +
  2104. +#define __xchg(new, ptr, size) \
  2105. +({ \
  2106. + __typeof__(ptr) __ptr = (ptr); \
  2107. + __typeof__(new) __new = (new); \
  2108. + __typeof__(*(ptr)) __ret; \
  2109. + switch (size) { \
  2110. + case 4: \
  2111. + __asm__ __volatile__ ( \
  2112. + "amoswap.w %0, %2, %1" \
  2113. + : "=r" (__ret), "+A" (*__ptr) \
  2114. + : "r" (__new)); \
  2115. + break; \
  2116. + case 8: \
  2117. + __asm__ __volatile__ ( \
  2118. + "amoswap.d %0, %2, %1" \
  2119. + : "=r" (__ret), "+A" (*__ptr) \
  2120. + : "r" (__new)); \
  2121. + break; \
  2122. + default: \
  2123. + BUILD_BUG(); \
  2124. + } \
  2125. + __ret; \
  2126. +})
  2127. +
  2128. +#define xchg(ptr, x) (__xchg((x), (ptr), sizeof(*(ptr))))
  2129. +
  2130. +
  2131. +/*
  2132. + * Atomic compare and exchange. Compare OLD with MEM, if identical,
  2133. + * store NEW in MEM. Return the initial value in MEM. Success is
  2134. + * indicated by comparing RETURN with OLD.
  2135. + */
  2136. +#define __cmpxchg(ptr, old, new, size) \
  2137. +({ \
  2138. + __typeof__(ptr) __ptr = (ptr); \
  2139. + __typeof__(old) __old = (old); \
  2140. + __typeof__(new) __new = (new); \
  2141. + __typeof__(*(ptr)) __ret; \
  2142. + register unsigned int __rc; \
  2143. + switch (size) { \
  2144. + case 4: \
  2145. + __asm__ __volatile__ ( \
  2146. + "0:" \
  2147. + "lr.w %0, %2\n" \
  2148. + "bne %0, %z3, 1f\n" \
  2149. + "sc.w %1, %z4, %2\n" \
  2150. + "bnez %1, 0b\n" \
  2151. + "1:" \
  2152. + : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \
  2153. + : "rJ" (__old), "rJ" (__new)); \
  2154. + break; \
  2155. + case 8: \
  2156. + __asm__ __volatile__ ( \
  2157. + "0:" \
  2158. + "lr.d %0, %2\n" \
  2159. + "bne %0, %z3, 1f\n" \
  2160. + "sc.d %1, %z4, %2\n" \
  2161. + "bnez %1, 0b\n" \
  2162. + "1:" \
  2163. + : "=&r" (__ret), "=&r" (__rc), "+A" (*__ptr) \
  2164. + : "rJ" (__old), "rJ" (__new)); \
  2165. + break; \
  2166. + default: \
  2167. + BUILD_BUG(); \
  2168. + } \
  2169. + __ret; \
  2170. +})
  2171. +
  2172. +#define __cmpxchg_mb(ptr, old, new, size) \
  2173. +({ \
  2174. + __typeof__(*(ptr)) __ret; \
  2175. + smp_mb(); \
  2176. + __ret = __cmpxchg((ptr), (old), (new), (size)); \
  2177. + smp_mb(); \
  2178. + __ret; \
  2179. +})
  2180. +
  2181. +#define cmpxchg(ptr, o, n) \
  2182. + (__cmpxchg_mb((ptr), (o), (n), sizeof(*(ptr))))
  2183. +
  2184. +#define cmpxchg_local(ptr, o, n) \
  2185. + (__cmpxchg((ptr), (o), (n), sizeof(*(ptr))))
  2186. +
  2187. +#define cmpxchg64(ptr, o, n) \
  2188. +({ \
  2189. + BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
  2190. + cmpxchg((ptr), (o), (n)); \
  2191. +})
  2192. +
  2193. +#define cmpxchg64_local(ptr, o, n) \
  2194. +({ \
  2195. + BUILD_BUG_ON(sizeof(*(ptr)) != 8); \
  2196. + cmpxchg_local((ptr), (o), (n)); \
  2197. +})
  2198. +
  2199. +#else /* !CONFIG_RV_ATOMIC */
  2200. +
  2201. +#include <asm-generic/cmpxchg.h>
  2202. +
  2203. +#endif /* CONFIG_RV_ATOMIC */
  2204. +
  2205. +#endif /* _ASM_RISCV_CMPXCHG_H */
  2206. diff -Nur linux-4.6.2/arch/riscv/include/asm/csr.h linux-4.6.2.riscv/arch/riscv/include/asm/csr.h
  2207. --- linux-4.6.2/arch/riscv/include/asm/csr.h 1970-01-01 01:00:00.000000000 +0100
  2208. +++ linux-4.6.2.riscv/arch/riscv/include/asm/csr.h 2017-03-04 02:48:34.166888015 +0100
  2209. @@ -0,0 +1,137 @@
  2210. +#ifndef _ASM_RISCV_CSR_H
  2211. +#define _ASM_RISCV_CSR_H
  2212. +
  2213. +#include <linux/const.h>
  2214. +
  2215. +/* Status register flags */
  2216. +#define SR_IE _AC(0x00000002,UL) /* Interrupt Enable */
  2217. +#define SR_PIE _AC(0x00000020,UL) /* Previous IE */
  2218. +#define SR_PS _AC(0x00000100,UL) /* Previously Supervisor */
  2219. +#define SR_PUM _AC(0x00040000,UL) /* Protect User Memory */
  2220. +
  2221. +#define SR_FS _AC(0x00006000,UL) /* Floating-point Status */
  2222. +#define SR_FS_OFF _AC(0x00000000,UL)
  2223. +#define SR_FS_INITIAL _AC(0x00002000,UL)
  2224. +#define SR_FS_CLEAN _AC(0x00004000,UL)
  2225. +#define SR_FS_DIRTY _AC(0x00006000,UL)
  2226. +
  2227. +#define SR_XS _AC(0x00018000,UL) /* Extension Status */
  2228. +#define SR_XS_OFF _AC(0x00000000,UL)
  2229. +#define SR_XS_INITIAL _AC(0x00008000,UL)
  2230. +#define SR_XS_CLEAN _AC(0x00010000,UL)
  2231. +#define SR_XS_DIRTY _AC(0x00018000,UL)
  2232. +
  2233. +#ifndef CONFIG_64BIT
  2234. +#define SR_SD _AC(0x80000000,UL) /* FS/XS dirty */
  2235. +#else
  2236. +#define SR_SD _AC(0x8000000000000000,UL) /* FS/XS dirty */
  2237. +#endif
  2238. +
  2239. +/* Interrupt Enable and Interrupt Pending flags */
  2240. +#define SIE_SSIE _AC(0x00000002,UL) /* Software Interrupt Enable */
  2241. +#define SIE_STIE _AC(0x00000020,UL) /* Timer Interrupt Enable */
  2242. +
  2243. +#define EXC_INST_MISALIGNED 0
  2244. +#define EXC_INST_ACCESS 1
  2245. +#define EXC_BREAKPOINT 3
  2246. +#define EXC_LOAD_ACCESS 5
  2247. +#define EXC_STORE_ACCESS 7
  2248. +#define EXC_SYSCALL 8
  2249. +
  2250. +#ifndef __ASSEMBLY__
  2251. +
  2252. +#define CSR_ZIMM(val) \
  2253. + (__builtin_constant_p(val) && ((unsigned long)(val) < 0x20))
  2254. +
  2255. +#define csr_swap(csr,val) \
  2256. +({ \
  2257. + unsigned long __v = (unsigned long)(val); \
  2258. + if (CSR_ZIMM(__v)) { \
  2259. + __asm__ __volatile__ ( \
  2260. + "csrrw %0, " #csr ", %1" \
  2261. + : "=r" (__v) : "i" (__v)); \
  2262. + } else { \
  2263. + __asm__ __volatile__ ( \
  2264. + "csrrw %0, " #csr ", %1" \
  2265. + : "=r" (__v) : "r" (__v)); \
  2266. + } \
  2267. + __v; \
  2268. +})
  2269. +
  2270. +#define csr_read(csr) \
  2271. +({ \
  2272. + register unsigned long __v; \
  2273. + __asm__ __volatile__ ( \
  2274. + "csrr %0, " #csr : "=r" (__v)); \
  2275. + __v; \
  2276. +})
  2277. +
  2278. +#define csr_write(csr,val) \
  2279. +({ \
  2280. + unsigned long __v = (unsigned long)(val); \
  2281. + if (CSR_ZIMM(__v)) { \
  2282. + __asm__ __volatile__ ( \
  2283. + "csrw " #csr ", %0" : : "i" (__v)); \
  2284. + } else { \
  2285. + __asm__ __volatile__ ( \
  2286. + "csrw " #csr ", %0" : : "r" (__v)); \
  2287. + } \
  2288. +})
  2289. +
  2290. +#define csr_read_set(csr,val) \
  2291. +({ \
  2292. + unsigned long __v = (unsigned long)(val); \
  2293. + if (CSR_ZIMM(val)) { \
  2294. + __asm__ __volatile__ ( \
  2295. + "csrrs %0, " #csr ", %1" \
  2296. + : "=r" (__v) : "i" (__v)); \
  2297. + } else { \
  2298. + __asm__ __volatile__ ( \
  2299. + "csrrs %0, " #csr ", %1" \
  2300. + : "=r" (__v) : "r" (__v)); \
  2301. + } \
  2302. + __v; \
  2303. +})
  2304. +
  2305. +#define csr_set(csr,val) \
  2306. +({ \
  2307. + unsigned long __v = (unsigned long)(val); \
  2308. + if (CSR_ZIMM(__v)) { \
  2309. + __asm__ __volatile__ ( \
  2310. + "csrs " #csr ", %0" : : "i" (__v)); \
  2311. + } else { \
  2312. + __asm__ __volatile__ ( \
  2313. + "csrs " #csr ", %0" : : "r" (__v)); \
  2314. + } \
  2315. +})
  2316. +
  2317. +#define csr_read_clear(csr,val) \
  2318. +({ \
  2319. + unsigned long __v = (unsigned long)(val); \
  2320. + if (CSR_ZIMM(__v)) { \
  2321. + __asm__ __volatile__ ( \
  2322. + "csrrc %0, " #csr ", %1" \
  2323. + : "=r" (__v) : "i" (__v)); \
  2324. + } else { \
  2325. + __asm__ __volatile__ ( \
  2326. + "csrrc %0, " #csr ", %1" \
  2327. + : "=r" (__v) : "r" (__v)); \
  2328. + } \
  2329. + __v; \
  2330. +})
  2331. +
  2332. +#define csr_clear(csr,val) \
  2333. +({ \
  2334. + unsigned long __v = (unsigned long)(val); \
  2335. + if (CSR_ZIMM(__v)) { \
  2336. + __asm__ __volatile__ ( \
  2337. + "csrc " #csr ", %0" : : "i" (__v)); \
  2338. + } else { \
  2339. + __asm__ __volatile__ ( \
  2340. + "csrc " #csr ", %0" : : "r" (__v)); \
  2341. + } \
  2342. +})
  2343. +
  2344. +#endif /* __ASSEMBLY__ */
  2345. +
  2346. +#endif /* _ASM_RISCV_CSR_H */
  2347. diff -Nur linux-4.6.2/arch/riscv/include/asm/current.h linux-4.6.2.riscv/arch/riscv/include/asm/current.h
  2348. --- linux-4.6.2/arch/riscv/include/asm/current.h 1970-01-01 01:00:00.000000000 +0100
  2349. +++ linux-4.6.2.riscv/arch/riscv/include/asm/current.h 2017-03-04 02:48:34.166888015 +0100
  2350. @@ -0,0 +1,16 @@
  2351. +#ifndef _ASM_RISCV_CURRENT_H
  2352. +#define _ASM_RISCV_CURRENT_H
  2353. +
  2354. +#include <asm/csr.h>
  2355. +
  2356. +struct task_struct;
  2357. +
  2358. +static inline struct task_struct *get_current(void)
  2359. +{
  2360. + register struct task_struct * tp asm("tp");
  2361. + return tp;
  2362. +}
  2363. +
  2364. +#define current (get_current())
  2365. +
  2366. +#endif /* _ASM_RISCV_CURRENT_H */
  2367. diff -Nur linux-4.6.2/arch/riscv/include/asm/delay.h linux-4.6.2.riscv/arch/riscv/include/asm/delay.h
  2368. --- linux-4.6.2/arch/riscv/include/asm/delay.h 1970-01-01 01:00:00.000000000 +0100
  2369. +++ linux-4.6.2.riscv/arch/riscv/include/asm/delay.h 2017-03-04 02:48:34.166888015 +0100
  2370. @@ -0,0 +1,14 @@
  2371. +#ifndef _ASM_RISCV_DELAY_H
  2372. +#define _ASM_RISCV_DELAY_H
  2373. +
  2374. +extern unsigned long timebase;
  2375. +
  2376. +#define udelay udelay
  2377. +extern void udelay(unsigned long usecs);
  2378. +
  2379. +#define ndelay ndelay
  2380. +extern void ndelay(unsigned long nsecs);
  2381. +
  2382. +extern void __delay(unsigned long cycles);
  2383. +
  2384. +#endif /* _ASM_RISCV_DELAY_H */
  2385. diff -Nur linux-4.6.2/arch/riscv/include/asm/device.h linux-4.6.2.riscv/arch/riscv/include/asm/device.h
  2386. --- linux-4.6.2/arch/riscv/include/asm/device.h 1970-01-01 01:00:00.000000000 +0100
  2387. +++ linux-4.6.2.riscv/arch/riscv/include/asm/device.h 2017-03-04 02:48:34.166888015 +0100
  2388. @@ -0,0 +1,13 @@
  2389. +#ifndef _ASM_RISCV_DEVICE_H
  2390. +#define _ASM_RISCV_DEVICE_H
  2391. +
  2392. +#include <linux/sysfs.h>
  2393. +
  2394. +struct dev_archdata {
  2395. + struct dma_map_ops *dma_ops;
  2396. +};
  2397. +
  2398. +struct pdev_archdata {
  2399. +};
  2400. +
  2401. +#endif /* _ASM_RISCV_DEVICE_H */
  2402. diff -Nur linux-4.6.2/arch/riscv/include/asm/dma-mapping.h linux-4.6.2.riscv/arch/riscv/include/asm/dma-mapping.h
  2403. --- linux-4.6.2/arch/riscv/include/asm/dma-mapping.h 1970-01-01 01:00:00.000000000 +0100
  2404. +++ linux-4.6.2.riscv/arch/riscv/include/asm/dma-mapping.h 2017-03-04 02:48:34.166888015 +0100
  2405. @@ -0,0 +1,63 @@
  2406. +/*
  2407. + * Copyright (C) 2003-2004 Hewlett-Packard Co
  2408. + * David Mosberger-Tang <davidm@hpl.hp.com>
  2409. + * Copyright (C) 2012 ARM Ltd.
  2410. + * Copyright (C) 2016 SiFive, Inc.
  2411. + *
  2412. + * This program is free software; you can redistribute it and/or modify
  2413. + * it under the terms of the GNU General Public License version 2 as
  2414. + * published by the Free Software Foundation.
  2415. + *
  2416. + * This program is distributed in the hope that it will be useful,
  2417. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  2418. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  2419. + * GNU General Public License for more details.
  2420. + *
  2421. + * You should have received a copy of the GNU General Public License
  2422. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  2423. + */
  2424. +#ifndef __ASM_RISCV_DMA_MAPPING_H
  2425. +#define __ASM_RISCV_DMA_MAPPING_H
  2426. +
  2427. +#ifdef __KERNEL__
  2428. +
  2429. +/* Use ops->dma_mapping_error (if it exists) or assume success */
  2430. +// #undef DMA_ERROR_CODE
  2431. +
  2432. +static inline struct dma_map_ops *get_dma_ops(struct device *dev)
  2433. +{
  2434. + if (unlikely(dev->archdata.dma_ops))
  2435. + return dev->archdata.dma_ops;
  2436. + else
  2437. + return &dma_noop_ops;
  2438. +}
  2439. +
  2440. +static inline bool dma_capable(struct device *dev, dma_addr_t addr, size_t size)
  2441. +{
  2442. + if (!dev->dma_mask)
  2443. + return false;
  2444. +
  2445. + return addr + size - 1 <= *dev->dma_mask;
  2446. +}
  2447. +
  2448. +static inline dma_addr_t phys_to_dma(struct device *dev, phys_addr_t paddr)
  2449. +{
  2450. + return (dma_addr_t)paddr;
  2451. +}
  2452. +
  2453. +static inline phys_addr_t dma_to_phys(struct device *dev, dma_addr_t dev_addr)
  2454. +{
  2455. + return (phys_addr_t)dev_addr;
  2456. +}
  2457. +
  2458. +static inline void dma_cache_sync(struct device *dev, void *vaddr, size_t size, enum dma_data_direction dir)
  2459. +{
  2460. + /*
  2461. + * RISC-V is cache-coherent, so this is mostly a no-op. However, we do need to
  2462. + * ensure that dma_cache_sync() enforces order, hence the mb().
  2463. + */
  2464. + mb();
  2465. +}
  2466. +
  2467. +#endif /* __KERNEL__ */
  2468. +#endif /* __ASM_RISCV_DMA_MAPPING_H */
  2469. diff -Nur linux-4.6.2/arch/riscv/include/asm/elf.h linux-4.6.2.riscv/arch/riscv/include/asm/elf.h
  2470. --- linux-4.6.2/arch/riscv/include/asm/elf.h 1970-01-01 01:00:00.000000000 +0100
  2471. +++ linux-4.6.2.riscv/arch/riscv/include/asm/elf.h 2017-03-04 02:48:34.166888015 +0100
  2472. @@ -0,0 +1,72 @@
  2473. +#ifndef _ASM_RISCV_ELF_H
  2474. +#define _ASM_RISCV_ELF_H
  2475. +
  2476. +#include <uapi/asm/elf.h>
  2477. +#include <asm/auxvec.h>
  2478. +#include <asm/byteorder.h>
  2479. +
  2480. +/* TODO: Move definition into include/uapi/linux/elf-em.h */
  2481. +#define EM_RISCV 0xF3
  2482. +
  2483. +/*
  2484. + * These are used to set parameters in the core dumps.
  2485. + */
  2486. +#define ELF_ARCH EM_RISCV
  2487. +
  2488. +#ifdef CONFIG_64BIT
  2489. +#define ELF_CLASS ELFCLASS64
  2490. +#else
  2491. +#define ELF_CLASS ELFCLASS32
  2492. +#endif
  2493. +
  2494. +#if defined(__LITTLE_ENDIAN)
  2495. +#define ELF_DATA ELFDATA2LSB
  2496. +#elif defined(__BIG_ENDIAN)
  2497. +#define ELF_DATA ELFDATA2MSB
  2498. +#else
  2499. +#error "Unknown endianness"
  2500. +#endif
  2501. +
  2502. +/*
  2503. + * This is used to ensure we don't load something for the wrong architecture.
  2504. + */
  2505. +#define elf_check_arch(x) ((x)->e_machine == EM_RISCV)
  2506. +
  2507. +#define CORE_DUMP_USE_REGSET
  2508. +#define ELF_EXEC_PAGESIZE (PAGE_SIZE)
  2509. +
  2510. +/*
  2511. + * This is the location that an ET_DYN program is loaded if exec'ed. Typical
  2512. + * use of this is to invoke "./ld.so someprog" to test out a new version of
  2513. + * the loader. We need to make sure that it is out of the way of the program
  2514. + * that it will "exec", and that there is sufficient room for the brk.
  2515. + */
  2516. +#define ELF_ET_DYN_BASE ((TASK_SIZE / 3) * 2)
  2517. +
  2518. +/*
  2519. + * This yields a mask that user programs can use to figure out what
  2520. + * instruction set this CPU supports. This could be done in user space,
  2521. + * but it's not easy, and we've already done it here.
  2522. + */
  2523. +#define ELF_HWCAP (0)
  2524. +
  2525. +/*
  2526. + * This yields a string that ld.so will use to load implementation
  2527. + * specific libraries for optimization. This is more specific in
  2528. + * intent than poking at uname or /proc/cpuinfo.
  2529. + */
  2530. +#define ELF_PLATFORM (NULL)
  2531. +
  2532. +#define ARCH_DLINFO \
  2533. +do { \
  2534. + NEW_AUX_ENT(AT_SYSINFO_EHDR, \
  2535. + (elf_addr_t)current->mm->context.vdso); \
  2536. +} while (0)
  2537. +
  2538. +
  2539. +#define ARCH_HAS_SETUP_ADDITIONAL_PAGES
  2540. +struct linux_binprm;
  2541. +extern int arch_setup_additional_pages(struct linux_binprm *bprm,
  2542. + int uses_interp);
  2543. +
  2544. +#endif /* _ASM_RISCV_ELF_H */
  2545. diff -Nur linux-4.6.2/arch/riscv/include/asm/io.h linux-4.6.2.riscv/arch/riscv/include/asm/io.h
  2546. --- linux-4.6.2/arch/riscv/include/asm/io.h 1970-01-01 01:00:00.000000000 +0100
  2547. +++ linux-4.6.2.riscv/arch/riscv/include/asm/io.h 2017-03-04 02:48:34.166888015 +0100
  2548. @@ -0,0 +1,63 @@
  2549. +#ifndef _ASM_RISCV_IO_H
  2550. +#define _ASM_RISCV_IO_H
  2551. +
  2552. +#include <asm-generic/io.h>
  2553. +
  2554. +#ifdef __KERNEL__
  2555. +
  2556. +#ifdef CONFIG_MMU
  2557. +
  2558. +extern void __iomem *ioremap(phys_addr_t offset, unsigned long size);
  2559. +
  2560. +/*
  2561. + * ioremap_nocache - map bus memory into CPU space
  2562. + * @offset: bus address of the memory
  2563. + * @size: size of the resource to map
  2564. + *
  2565. + * ioremap_nocache performs a platform specific sequence of operations to
  2566. + * make bus memory CPU accessible via the readb/readw/readl/writeb/
  2567. + * writew/writel functions and the other mmio helpers. The returned
  2568. + * address is not guaranteed to be usable directly as a virtual
  2569. + * address.
  2570. + *
  2571. + * This version of ioremap ensures that the memory is marked uncachable
  2572. + * on the CPU as well as honouring existing caching rules from things like
  2573. + * the PCI bus. Note that there are other caches and buffers on many
  2574. + * busses. In particular driver authors should read up on PCI writes.
  2575. + *
  2576. + * It's useful if some control registers are in such an area and
  2577. + * write combining or read caching is not desirable.
  2578. + *
  2579. + * Must be freed with iounmap.
  2580. + */
  2581. +static inline void __iomem *ioremap_nocache(
  2582. + phys_addr_t offset, unsigned long size)
  2583. +{
  2584. + return ioremap(offset, size);
  2585. +}
  2586. +
  2587. +/**
  2588. + * ioremap_wc - map memory into CPU space write combined
  2589. + * @offset: bus address of the memory
  2590. + * @size: size of the resource to map
  2591. + *
  2592. + * This version of ioremap ensures that the memory is marked write combining.
  2593. + * Write combining allows faster writes to some hardware devices.
  2594. + *
  2595. + * Must be freed with iounmap.
  2596. + */
  2597. +static inline void __iomem *ioremap_wc(
  2598. + phys_addr_t offset, unsigned long size)
  2599. +{
  2600. + return ioremap(offset, size);
  2601. +}
  2602. +
  2603. +#define ioremap_wt ioremap_nocache
  2604. +
  2605. +extern void iounmap(void __iomem *addr);
  2606. +
  2607. +#endif /* CONFIG_MMU */
  2608. +
  2609. +#endif /* __KERNEL__ */
  2610. +
  2611. +#endif /* _ASM_RISCV_IO_H */
  2612. diff -Nur linux-4.6.2/arch/riscv/include/asm/irqflags.h linux-4.6.2.riscv/arch/riscv/include/asm/irqflags.h
  2613. --- linux-4.6.2/arch/riscv/include/asm/irqflags.h 1970-01-01 01:00:00.000000000 +0100
  2614. +++ linux-4.6.2.riscv/arch/riscv/include/asm/irqflags.h 2017-03-04 02:48:34.166888015 +0100
  2615. @@ -0,0 +1,49 @@
  2616. +#ifndef _ASM_RISCV_IRQFLAGS_H
  2617. +#define _ASM_RISCV_IRQFLAGS_H
  2618. +
  2619. +#include <asm/processor.h>
  2620. +#include <asm/csr.h>
  2621. +
  2622. +/* read interrupt enabled status */
  2623. +static inline unsigned long arch_local_save_flags(void)
  2624. +{
  2625. + return csr_read(sstatus);
  2626. +}
  2627. +
  2628. +/* unconditionally enable interrupts */
  2629. +static inline void arch_local_irq_enable(void)
  2630. +{
  2631. + csr_set(sstatus, SR_IE);
  2632. +}
  2633. +
  2634. +/* unconditionally disable interrupts */
  2635. +static inline void arch_local_irq_disable(void)
  2636. +{
  2637. + csr_clear(sstatus, SR_IE);
  2638. +}
  2639. +
  2640. +/* get status and disable interrupts */
  2641. +static inline unsigned long arch_local_irq_save(void)
  2642. +{
  2643. + return csr_read_clear(sstatus, SR_IE);
  2644. +}
  2645. +
  2646. +/* test flags */
  2647. +static inline int arch_irqs_disabled_flags(unsigned long flags)
  2648. +{
  2649. + return !(flags & SR_IE);
  2650. +}
  2651. +
  2652. +/* test hardware interrupt enable bit */
  2653. +static inline int arch_irqs_disabled(void)
  2654. +{
  2655. + return arch_irqs_disabled_flags(arch_local_save_flags());
  2656. +}
  2657. +
  2658. +/* set interrupt enabled status */
  2659. +static inline void arch_local_irq_restore(unsigned long flags)
  2660. +{
  2661. + csr_set(sstatus, flags & SR_IE);
  2662. +}
  2663. +
  2664. +#endif /* _ASM_RISCV_IRQFLAGS_H */
  2665. diff -Nur linux-4.6.2/arch/riscv/include/asm/irq.h linux-4.6.2.riscv/arch/riscv/include/asm/irq.h
  2666. --- linux-4.6.2/arch/riscv/include/asm/irq.h 1970-01-01 01:00:00.000000000 +0100
  2667. +++ linux-4.6.2.riscv/arch/riscv/include/asm/irq.h 2017-03-04 02:48:34.166888015 +0100
  2668. @@ -0,0 +1,14 @@
  2669. +#ifndef _ASM_RISCV_IRQ_H
  2670. +#define _ASM_RISCV_IRQ_H
  2671. +
  2672. +#define NR_IRQS 0
  2673. +
  2674. +#define INTERRUPT_CAUSE_SOFTWARE 1
  2675. +#define INTERRUPT_CAUSE_TIMER 5
  2676. +#define INTERRUPT_CAUSE_EXTERNAL 9
  2677. +
  2678. +void riscv_timer_interrupt(void);
  2679. +
  2680. +#include <asm-generic/irq.h>
  2681. +
  2682. +#endif /* _ASM_RISCV_IRQ_H */
  2683. diff -Nur linux-4.6.2/arch/riscv/include/asm/Kbuild linux-4.6.2.riscv/arch/riscv/include/asm/Kbuild
  2684. --- linux-4.6.2/arch/riscv/include/asm/Kbuild 1970-01-01 01:00:00.000000000 +0100
  2685. +++ linux-4.6.2.riscv/arch/riscv/include/asm/Kbuild 2017-03-04 02:48:34.162887952 +0100
  2686. @@ -0,0 +1,59 @@
  2687. +generic-y += bugs.h
  2688. +generic-y += cacheflush.h
  2689. +generic-y += checksum.h
  2690. +generic-y += clkdev.h
  2691. +generic-y += cputime.h
  2692. +generic-y += div64.h
  2693. +generic-y += dma.h
  2694. +generic-y += emergency-restart.h
  2695. +generic-y += errno.h
  2696. +generic-y += exec.h
  2697. +generic-y += fb.h
  2698. +generic-y += fcntl.h
  2699. +generic-y += ftrace.h
  2700. +generic-y += futex.h
  2701. +generic-y += hardirq.h
  2702. +generic-y += hash.h
  2703. +generic-y += hw_irq.h
  2704. +generic-y += ioctl.h
  2705. +generic-y += ioctls.h
  2706. +generic-y += ipcbuf.h
  2707. +generic-y += irq_regs.h
  2708. +generic-y += irq_work.h
  2709. +generic-y += kdebug.h
  2710. +generic-y += kmap_types.h
  2711. +generic-y += kvm_para.h
  2712. +generic-y += local.h
  2713. +generic-y += mm-arch-hooks.h
  2714. +generic-y += mman.h
  2715. +generic-y += module.h
  2716. +generic-y += msgbuf.h
  2717. +generic-y += mutex.h
  2718. +generic-y += param.h
  2719. +generic-y += percpu.h
  2720. +generic-y += poll.h
  2721. +generic-y += posix_types.h
  2722. +generic-y += preempt.h
  2723. +generic-y += resource.h
  2724. +generic-y += scatterlist.h
  2725. +generic-y += sections.h
  2726. +generic-y += sembuf.h
  2727. +generic-y += shmbuf.h
  2728. +generic-y += shmparam.h
  2729. +generic-y += signal.h
  2730. +generic-y += socket.h
  2731. +generic-y += sockios.h
  2732. +generic-y += stat.h
  2733. +generic-y += statfs.h
  2734. +generic-y += swab.h
  2735. +generic-y += termbits.h
  2736. +generic-y += termios.h
  2737. +generic-y += topology.h
  2738. +generic-y += trace_clock.h
  2739. +generic-y += types.h
  2740. +generic-y += ucontext.h
  2741. +generic-y += unaligned.h
  2742. +generic-y += user.h
  2743. +generic-y += vga.h
  2744. +generic-y += vmlinux.lds.h
  2745. +generic-y += xor.h
  2746. diff -Nur linux-4.6.2/arch/riscv/include/asm/linkage.h linux-4.6.2.riscv/arch/riscv/include/asm/linkage.h
  2747. --- linux-4.6.2/arch/riscv/include/asm/linkage.h 1970-01-01 01:00:00.000000000 +0100
  2748. +++ linux-4.6.2.riscv/arch/riscv/include/asm/linkage.h 2017-03-04 02:48:34.166888015 +0100
  2749. @@ -0,0 +1,7 @@
  2750. +#ifndef _ASM_RISCV_LINKAGE_H
  2751. +#define _ASM_RISCV_LINKAGE_H
  2752. +
  2753. +#define __ALIGN .balign 4
  2754. +#define __ALIGN_STR ".balign 4"
  2755. +
  2756. +#endif /* _ASM_RISCV_LINKAGE_H */
  2757. diff -Nur linux-4.6.2/arch/riscv/include/asm/mmu_context.h linux-4.6.2.riscv/arch/riscv/include/asm/mmu_context.h
  2758. --- linux-4.6.2/arch/riscv/include/asm/mmu_context.h 1970-01-01 01:00:00.000000000 +0100
  2759. +++ linux-4.6.2.riscv/arch/riscv/include/asm/mmu_context.h 2017-03-04 02:48:34.166888015 +0100
  2760. @@ -0,0 +1,46 @@
  2761. +#ifndef _ASM_RISCV_MMU_CONTEXT_H
  2762. +#define _ASM_RISCV_MMU_CONTEXT_H
  2763. +
  2764. +#include <asm-generic/mm_hooks.h>
  2765. +
  2766. +#include <linux/mm.h>
  2767. +#include <linux/sched.h>
  2768. +#include <asm/tlbflush.h>
  2769. +
  2770. +static inline void enter_lazy_tlb(struct mm_struct *mm,
  2771. + struct task_struct *task)
  2772. +{
  2773. +}
  2774. +
  2775. +/* Initialize context-related info for a new mm_struct */
  2776. +static inline int init_new_context(struct task_struct *task,
  2777. + struct mm_struct *mm)
  2778. +{
  2779. + return 0;
  2780. +}
  2781. +
  2782. +static inline void destroy_context(struct mm_struct *mm)
  2783. +{
  2784. +}
  2785. +
  2786. +static inline void switch_mm(struct mm_struct *prev,
  2787. + struct mm_struct *next, struct task_struct *task)
  2788. +{
  2789. + if (likely(prev != next)) {
  2790. + csr_write(sptbr, virt_to_pfn(next->pgd));
  2791. + local_flush_tlb_all();
  2792. + }
  2793. +}
  2794. +
  2795. +static inline void activate_mm(struct mm_struct *prev,
  2796. + struct mm_struct *next)
  2797. +{
  2798. + switch_mm(prev, next, NULL);
  2799. +}
  2800. +
  2801. +static inline void deactivate_mm(struct task_struct *task,
  2802. + struct mm_struct *mm)
  2803. +{
  2804. +}
  2805. +
  2806. +#endif /* _ASM_RISCV_MMU_CONTEXT_H */
  2807. diff -Nur linux-4.6.2/arch/riscv/include/asm/mmu.h linux-4.6.2.riscv/arch/riscv/include/asm/mmu.h
  2808. --- linux-4.6.2/arch/riscv/include/asm/mmu.h 1970-01-01 01:00:00.000000000 +0100
  2809. +++ linux-4.6.2.riscv/arch/riscv/include/asm/mmu.h 2017-03-04 02:48:34.166888015 +0100
  2810. @@ -0,0 +1,12 @@
  2811. +#ifndef _ASM_RISCV_MMU_H
  2812. +#define _ASM_RISCV_MMU_H
  2813. +
  2814. +#ifndef __ASSEMBLY__
  2815. +
  2816. +typedef struct {
  2817. + void *vdso;
  2818. +} mm_context_t;
  2819. +
  2820. +#endif /* __ASSEMBLY__ */
  2821. +
  2822. +#endif /* _ASM_RISCV_MMU_H */
  2823. diff -Nur linux-4.6.2/arch/riscv/include/asm/page.h linux-4.6.2.riscv/arch/riscv/include/asm/page.h
  2824. --- linux-4.6.2/arch/riscv/include/asm/page.h 1970-01-01 01:00:00.000000000 +0100
  2825. +++ linux-4.6.2.riscv/arch/riscv/include/asm/page.h 2017-03-04 02:48:34.166888015 +0100
  2826. @@ -0,0 +1,119 @@
  2827. +#ifndef _ASM_RISCV_PAGE_H
  2828. +#define _ASM_RISCV_PAGE_H
  2829. +
  2830. +#include <linux/pfn.h>
  2831. +#include <linux/const.h>
  2832. +
  2833. +#define PAGE_SHIFT (12)
  2834. +#define PAGE_SIZE (_AC(1,UL) << PAGE_SHIFT)
  2835. +#define PAGE_MASK (~(PAGE_SIZE - 1))
  2836. +
  2837. +#ifdef __KERNEL__
  2838. +
  2839. +/*
  2840. + * PAGE_OFFSET -- the first address of the first page of memory.
  2841. + * When not using MMU this corresponds to the first free page in
  2842. + * physical memory (aligned on a page boundary).
  2843. + */
  2844. +#ifdef CONFIG_64BIT
  2845. +#define PAGE_OFFSET _AC(0xffffffff80000000,UL)
  2846. +#else
  2847. +#define PAGE_OFFSET _AC(0xc0000000,UL)
  2848. +#endif
  2849. +
  2850. +#ifndef __ASSEMBLY__
  2851. +
  2852. +#define PAGE_UP(addr) (((addr)+((PAGE_SIZE)-1))&(~((PAGE_SIZE)-1)))
  2853. +#define PAGE_DOWN(addr) ((addr)&(~((PAGE_SIZE)-1)))
  2854. +
  2855. +/* align addr on a size boundary - adjust address up/down if needed */
  2856. +#define _ALIGN_UP(addr, size) (((addr)+((size)-1))&(~((size)-1)))
  2857. +#define _ALIGN_DOWN(addr, size) ((addr)&(~((size)-1)))
  2858. +
  2859. +/* align addr on a size boundary - adjust address up if needed */
  2860. +#define _ALIGN(addr, size) _ALIGN_UP(addr, size)
  2861. +
  2862. +#define clear_page(pgaddr) memset((pgaddr), 0, PAGE_SIZE)
  2863. +#define copy_page(to, from) memcpy((to), (from), PAGE_SIZE)
  2864. +
  2865. +#define clear_user_page(pgaddr, vaddr, page) memset((pgaddr), 0, PAGE_SIZE)
  2866. +#define copy_user_page(vto, vfrom, vaddr, topg) \
  2867. + memcpy((vto), (vfrom), PAGE_SIZE)
  2868. +
  2869. +/*
  2870. + * Use struct definitions to apply C type checking
  2871. + */
  2872. +
  2873. +/* Page Global Directory entry */
  2874. +typedef struct {
  2875. + unsigned long pgd;
  2876. +} pgd_t;
  2877. +
  2878. +/* Page Table entry */
  2879. +typedef struct {
  2880. + unsigned long pte;
  2881. +} pte_t;
  2882. +
  2883. +typedef struct {
  2884. + unsigned long pgprot;
  2885. +} pgprot_t;
  2886. +
  2887. +typedef struct page *pgtable_t;
  2888. +
  2889. +#define pte_val(x) ((x).pte)
  2890. +#define pgd_val(x) ((x).pgd)
  2891. +#define pgprot_val(x) ((x).pgprot)
  2892. +
  2893. +#define __pte(x) ((pte_t) { (x) })
  2894. +#define __pgd(x) ((pgd_t) { (x) })
  2895. +#define __pgprot(x) ((pgprot_t) { (x) })
  2896. +
  2897. +#ifdef CONFIG_64BITS
  2898. +#define PTE_FMT "%016lx"
  2899. +#else
  2900. +#define PTE_FMT "%08lx"
  2901. +#endif
  2902. +
  2903. +extern unsigned long va_pa_offset;
  2904. +extern unsigned long pfn_base;
  2905. +
  2906. +extern unsigned long max_low_pfn;
  2907. +extern unsigned long min_low_pfn;
  2908. +
  2909. +#define __pa(x) ((unsigned long)(x) - va_pa_offset)
  2910. +#define __va(x) ((void *)((unsigned long) (x) + va_pa_offset))
  2911. +
  2912. +#define phys_to_pfn(phys) (PFN_DOWN(phys))
  2913. +#define pfn_to_phys(pfn) (PFN_PHYS(pfn))
  2914. +
  2915. +#define virt_to_pfn(vaddr) (phys_to_pfn(__pa(vaddr)))
  2916. +#define pfn_to_virt(pfn) (__va(pfn_to_phys(pfn)))
  2917. +
  2918. +#define virt_to_page(vaddr) (pfn_to_page(virt_to_pfn(vaddr)))
  2919. +#define page_to_virt(page) (pfn_to_virt(page_to_pfn(page)))
  2920. +
  2921. +#define page_to_phys(page) (pfn_to_phys(page_to_pfn(page)))
  2922. +#define page_to_bus(page) (page_to_phys(page))
  2923. +#define phys_to_page(paddr) (pfn_to_page(phys_to_pfn(paddr)))
  2924. +
  2925. +#define pfn_valid(pfn) (((pfn) >= pfn_base) && (((pfn)-pfn_base) < max_mapnr))
  2926. +
  2927. +#define ARCH_PFN_OFFSET (pfn_base)
  2928. +
  2929. +#endif /* __ASSEMBLY__ */
  2930. +
  2931. +#define virt_addr_valid(vaddr) (pfn_valid(virt_to_pfn(vaddr)))
  2932. +
  2933. +#endif /* __KERNEL__ */
  2934. +
  2935. +#define VM_DATA_DEFAULT_FLAGS (VM_READ | VM_WRITE | VM_EXEC | \
  2936. + VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
  2937. +
  2938. +#include <asm-generic/memory_model.h>
  2939. +#include <asm-generic/getorder.h>
  2940. +
  2941. +/* vDSO support */
  2942. +/* We do define AT_SYSINFO_EHDR but don't use the gate mechanism */
  2943. +#define __HAVE_ARCH_GATE_AREA
  2944. +
  2945. +#endif /* _ASM_RISCV_PAGE_H */
  2946. diff -Nur linux-4.6.2/arch/riscv/include/asm/pci.h linux-4.6.2.riscv/arch/riscv/include/asm/pci.h
  2947. --- linux-4.6.2/arch/riscv/include/asm/pci.h 1970-01-01 01:00:00.000000000 +0100
  2948. +++ linux-4.6.2.riscv/arch/riscv/include/asm/pci.h 2017-03-04 02:48:34.166888015 +0100
  2949. @@ -0,0 +1,37 @@
  2950. +#ifndef __ASM_RISCV_PCI_H
  2951. +#define __ASM_RISCV_PCI_H
  2952. +#ifdef __KERNEL__
  2953. +
  2954. +#include <linux/types.h>
  2955. +#include <linux/slab.h>
  2956. +#include <linux/dma-mapping.h>
  2957. +
  2958. +#include <asm/io.h>
  2959. +
  2960. +#define PCIBIOS_MIN_IO 0x1000
  2961. +#define PCIBIOS_MIN_MEM 0
  2962. +
  2963. +/* RISC-V shim does not initialize PCI bus */
  2964. +#define pcibios_assign_all_busses() 1
  2965. +
  2966. +/* RISC-V TileLink and PCIe share the share address space */
  2967. +#define PCI_DMA_BUS_IS_PHYS 1
  2968. +
  2969. +extern int isa_dma_bridge_buggy;
  2970. +
  2971. +#ifdef CONFIG_PCI
  2972. +static inline int pci_get_legacy_ide_irq(struct pci_dev *dev, int channel)
  2973. +{
  2974. + /* no legacy IRQ on risc-v */
  2975. + return -ENODEV;
  2976. +}
  2977. +
  2978. +static inline int pci_proc_domain(struct pci_bus *bus)
  2979. +{
  2980. + /* always show the domain in /proc */
  2981. + return 1;
  2982. +}
  2983. +#endif /* CONFIG_PCI */
  2984. +
  2985. +#endif /* __KERNEL__ */
  2986. +#endif /* __ASM_PCI_H */
  2987. diff -Nur linux-4.6.2/arch/riscv/include/asm/pgalloc.h linux-4.6.2.riscv/arch/riscv/include/asm/pgalloc.h
  2988. --- linux-4.6.2/arch/riscv/include/asm/pgalloc.h 1970-01-01 01:00:00.000000000 +0100
  2989. +++ linux-4.6.2.riscv/arch/riscv/include/asm/pgalloc.h 2017-03-04 02:48:34.166888015 +0100
  2990. @@ -0,0 +1,107 @@
  2991. +#ifndef _ASM_RISCV_PGALLOC_H
  2992. +#define _ASM_RISCV_PGALLOC_H
  2993. +
  2994. +#include <linux/mm.h>
  2995. +#include <asm/tlb.h>
  2996. +
  2997. +static inline void pmd_populate_kernel(struct mm_struct *mm,
  2998. + pmd_t *pmd, pte_t *pte)
  2999. +{
  3000. + unsigned long pfn = virt_to_pfn(pte);
  3001. + set_pmd(pmd, __pmd((pfn << _PAGE_PFN_SHIFT) | _PAGE_TABLE));
  3002. +}
  3003. +
  3004. +static inline void pmd_populate(struct mm_struct *mm,
  3005. + pmd_t *pmd, pgtable_t pte)
  3006. +{
  3007. + unsigned long pfn = virt_to_pfn(page_address(pte));
  3008. + set_pmd(pmd, __pmd((pfn << _PAGE_PFN_SHIFT) | _PAGE_TABLE));
  3009. +}
  3010. +
  3011. +#ifndef __PAGETABLE_PMD_FOLDED
  3012. +static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
  3013. +{
  3014. + unsigned long pfn = virt_to_pfn(pmd);
  3015. + set_pud(pud, __pud((pfn << _PAGE_PFN_SHIFT) | _PAGE_TABLE));
  3016. +}
  3017. +#endif /* __PAGETABLE_PMD_FOLDED */
  3018. +
  3019. +#define pmd_pgtable(pmd) pmd_page(pmd)
  3020. +
  3021. +static inline pgd_t *pgd_alloc(struct mm_struct *mm)
  3022. +{
  3023. + pgd_t *pgd;
  3024. +
  3025. + pgd = (pgd_t *)__get_free_page(GFP_KERNEL);
  3026. + if (likely(pgd != NULL)) {
  3027. + memset(pgd, 0, USER_PTRS_PER_PGD * sizeof(pgd_t));
  3028. + /* Copy kernel mappings */
  3029. + memcpy(pgd + USER_PTRS_PER_PGD,
  3030. + init_mm.pgd + USER_PTRS_PER_PGD,
  3031. + (PTRS_PER_PGD - USER_PTRS_PER_PGD) * sizeof(pgd_t));
  3032. + }
  3033. + return pgd;
  3034. +}
  3035. +
  3036. +static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
  3037. +{
  3038. + free_page((unsigned long)pgd);
  3039. +}
  3040. +
  3041. +#ifndef __PAGETABLE_PMD_FOLDED
  3042. +
  3043. +static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
  3044. +{
  3045. + return (pmd_t *)__get_free_page(
  3046. + GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
  3047. +}
  3048. +
  3049. +static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
  3050. +{
  3051. + free_page((unsigned long)pmd);
  3052. +}
  3053. +
  3054. +#define __pmd_free_tlb(tlb, pmd, addr) pmd_free((tlb)->mm, pmd)
  3055. +
  3056. +#endif /* __PAGETABLE_PMD_FOLDED */
  3057. +
  3058. +static inline pte_t *pte_alloc_one_kernel(struct mm_struct *mm,
  3059. + unsigned long address)
  3060. +{
  3061. + return (pte_t *)__get_free_page(
  3062. + GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
  3063. +}
  3064. +
  3065. +static inline struct page *pte_alloc_one(struct mm_struct *mm,
  3066. + unsigned long address)
  3067. +{
  3068. + struct page *pte;
  3069. + pte = alloc_page(GFP_KERNEL | __GFP_REPEAT | __GFP_ZERO);
  3070. + if (likely(pte != NULL)) {
  3071. + pgtable_page_ctor(pte);
  3072. + }
  3073. + return pte;
  3074. +}
  3075. +
  3076. +static inline void pte_free_kernel(struct mm_struct *mm, pte_t *pte)
  3077. +{
  3078. + free_page((unsigned long)pte);
  3079. +}
  3080. +
  3081. +static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
  3082. +{
  3083. + pgtable_page_dtor(pte);
  3084. + __free_page(pte);
  3085. +}
  3086. +
  3087. +#define __pte_free_tlb(tlb, pte, buf) \
  3088. +do { \
  3089. + pgtable_page_dtor(pte); \
  3090. + tlb_remove_page((tlb), pte); \
  3091. +} while (0)
  3092. +
  3093. +static inline void check_pgt_cache(void)
  3094. +{
  3095. +}
  3096. +
  3097. +#endif /* _ASM_RISCV_PGALLOC_H */
  3098. diff -Nur linux-4.6.2/arch/riscv/include/asm/pgtable-32.h linux-4.6.2.riscv/arch/riscv/include/asm/pgtable-32.h
  3099. --- linux-4.6.2/arch/riscv/include/asm/pgtable-32.h 1970-01-01 01:00:00.000000000 +0100
  3100. +++ linux-4.6.2.riscv/arch/riscv/include/asm/pgtable-32.h 2017-03-04 02:48:34.166888015 +0100
  3101. @@ -0,0 +1,12 @@
  3102. +#ifndef _ASM_RISCV_PGTABLE_32_H
  3103. +#define _ASM_RISCV_PGTABLE_32_H
  3104. +
  3105. +#include <asm-generic/pgtable-nopmd.h>
  3106. +#include <linux/const.h>
  3107. +
  3108. +/* Size of region mapped by a page global directory */
  3109. +#define PGDIR_SHIFT 22
  3110. +#define PGDIR_SIZE (_AC(1,UL) << PGDIR_SHIFT)
  3111. +#define PGDIR_MASK (~(PGDIR_SIZE - 1))
  3112. +
  3113. +#endif /* _ASM_RISCV_PGTABLE_32_H */
  3114. diff -Nur linux-4.6.2/arch/riscv/include/asm/pgtable-64.h linux-4.6.2.riscv/arch/riscv/include/asm/pgtable-64.h
  3115. --- linux-4.6.2/arch/riscv/include/asm/pgtable-64.h 1970-01-01 01:00:00.000000000 +0100
  3116. +++ linux-4.6.2.riscv/arch/riscv/include/asm/pgtable-64.h 2017-03-04 02:48:34.166888015 +0100
  3117. @@ -0,0 +1,66 @@
  3118. +#ifndef _ASM_RISCV_PGTABLE_64_H
  3119. +#define _ASM_RISCV_PGTABLE_64_H
  3120. +
  3121. +#include <linux/const.h>
  3122. +
  3123. +#define PGDIR_SHIFT 30
  3124. +/* Size of region mapped by a page global directory */
  3125. +#define PGDIR_SIZE (_AC(1,UL) << PGDIR_SHIFT)
  3126. +#define PGDIR_MASK (~(PGDIR_SIZE - 1))
  3127. +
  3128. +#define PMD_SHIFT 21
  3129. +/* Size of region mapped by a page middle directory */
  3130. +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
  3131. +#define PMD_MASK (~(PMD_SIZE - 1))
  3132. +
  3133. +/* Page Middle Directory entry */
  3134. +typedef struct {
  3135. + unsigned long pmd;
  3136. +} pmd_t;
  3137. +
  3138. +#define pmd_val(x) ((x).pmd)
  3139. +#define __pmd(x) ((pmd_t) { (x) })
  3140. +
  3141. +#define PTRS_PER_PMD (PAGE_SIZE / sizeof(pmd_t))
  3142. +
  3143. +static inline int pud_present(pud_t pud)
  3144. +{
  3145. + return (pud_val(pud) & _PAGE_PRESENT);
  3146. +}
  3147. +
  3148. +static inline int pud_none(pud_t pud)
  3149. +{
  3150. + return (pud_val(pud) == 0);
  3151. +}
  3152. +
  3153. +static inline int pud_bad(pud_t pud)
  3154. +{
  3155. + return !pud_present(pud);
  3156. +}
  3157. +
  3158. +static inline void set_pud(pud_t *pudp, pud_t pud)
  3159. +{
  3160. + *pudp = pud;
  3161. +}
  3162. +
  3163. +static inline void pud_clear(pud_t *pudp)
  3164. +{
  3165. + set_pud(pudp, __pud(0));
  3166. +}
  3167. +
  3168. +static inline unsigned long pud_page_vaddr(pud_t pud)
  3169. +{
  3170. + return (unsigned long)pfn_to_virt(pud_val(pud) >> _PAGE_PFN_SHIFT);
  3171. +}
  3172. +
  3173. +#define pmd_index(addr) (((addr) >> PMD_SHIFT) & (PTRS_PER_PMD - 1))
  3174. +
  3175. +static inline pmd_t *pmd_offset(pud_t *pud, unsigned long addr)
  3176. +{
  3177. + return (pmd_t *)pud_page_vaddr(*pud) + pmd_index(addr);
  3178. +}
  3179. +
  3180. +#define pmd_ERROR(e) \
  3181. + pr_err("%s:%d: bad pmd %016lx.\n", __FILE__, __LINE__, pmd_val(e))
  3182. +
  3183. +#endif /* _ASM_RISCV_PGTABLE_64_H */
  3184. diff -Nur linux-4.6.2/arch/riscv/include/asm/pgtable-bits.h linux-4.6.2.riscv/arch/riscv/include/asm/pgtable-bits.h
  3185. --- linux-4.6.2/arch/riscv/include/asm/pgtable-bits.h 1970-01-01 01:00:00.000000000 +0100
  3186. +++ linux-4.6.2.riscv/arch/riscv/include/asm/pgtable-bits.h 2017-03-04 02:48:34.166888015 +0100
  3187. @@ -0,0 +1,37 @@
  3188. +#ifndef _ASM_RISCV_PGTABLE_BITS_H
  3189. +#define _ASM_RISCV_PGTABLE_BITS_H
  3190. +
  3191. +/*
  3192. + * RV32Sv32 page table entry:
  3193. + * | 31 10 | 9 7 | 6 | 5 | 4 1 | 0
  3194. + * PFN reserved for SW D R TYPE V
  3195. + *
  3196. + * RV64Sv39 / RV64Sv48 page table entry:
  3197. + * | 63 48 | 47 10 | 9 7 | 6 | 5 | 4 1 | 0
  3198. + * reserved for HW PFN reserved for SW D R TYPE V
  3199. + */
  3200. +
  3201. +#define _PAGE_PRESENT (1 << 0)
  3202. +#define _PAGE_READ (1 << 1) /* Readable */
  3203. +#define _PAGE_WRITE (1 << 2) /* Writable */
  3204. +#define _PAGE_EXEC (1 << 3) /* Executable */
  3205. +#define _PAGE_USER (1 << 4) /* User */
  3206. +#define _PAGE_GLOBAL (1 << 5) /* Global */
  3207. +#define _PAGE_ACCESSED (1 << 6) /* Set by hardware on any access */
  3208. +#define _PAGE_DIRTY (1 << 7) /* Set by hardware on any write */
  3209. +#define _PAGE_SOFT (1 << 8) /* Reserved for software */
  3210. +
  3211. +#define _PAGE_SPECIAL _PAGE_SOFT
  3212. +#define _PAGE_TABLE _PAGE_PRESENT
  3213. +
  3214. +#define _PAGE_PFN_SHIFT 10
  3215. +
  3216. +/* Set of bits to preserve across pte_modify() */
  3217. +#define _PAGE_CHG_MASK (~(unsigned long)(_PAGE_PRESENT | _PAGE_READ | \
  3218. + _PAGE_WRITE | _PAGE_EXEC | \
  3219. + _PAGE_USER | _PAGE_GLOBAL))
  3220. +
  3221. +/* Advertise support for _PAGE_SPECIAL */
  3222. +#define __HAVE_ARCH_PTE_SPECIAL
  3223. +
  3224. +#endif /* _ASM_RISCV_PGTABLE_BITS_H */
  3225. diff -Nur linux-4.6.2/arch/riscv/include/asm/pgtable.h linux-4.6.2.riscv/arch/riscv/include/asm/pgtable.h
  3226. --- linux-4.6.2/arch/riscv/include/asm/pgtable.h 1970-01-01 01:00:00.000000000 +0100
  3227. +++ linux-4.6.2.riscv/arch/riscv/include/asm/pgtable.h 2017-03-04 02:48:34.166888015 +0100
  3228. @@ -0,0 +1,329 @@
  3229. +#ifndef _ASM_RISCV_PGTABLE_H
  3230. +#define _ASM_RISCV_PGTABLE_H
  3231. +
  3232. +#include <linux/mmzone.h>
  3233. +
  3234. +#include <asm/pgtable-bits.h>
  3235. +
  3236. +#ifndef __ASSEMBLY__
  3237. +
  3238. +#ifdef CONFIG_MMU
  3239. +
  3240. +/* Page Upper Directory not used in RISC-V */
  3241. +#include <asm-generic/pgtable-nopud.h>
  3242. +#include <asm/page.h>
  3243. +#include <linux/mm_types.h>
  3244. +
  3245. +#ifdef CONFIG_64BIT
  3246. +#include <asm/pgtable-64.h>
  3247. +#else
  3248. +#include <asm/pgtable-32.h>
  3249. +#endif /* CONFIG_64BIT */
  3250. +
  3251. +/* Number of entries in the page global directory */
  3252. +#define PTRS_PER_PGD (PAGE_SIZE / sizeof(pgd_t))
  3253. +/* Number of entries in the page table */
  3254. +#define PTRS_PER_PTE (PAGE_SIZE / sizeof(pte_t))
  3255. +
  3256. +/* Number of PGD entries that a user-mode program can use */
  3257. +#define USER_PTRS_PER_PGD (TASK_SIZE / PGDIR_SIZE)
  3258. +#define FIRST_USER_ADDRESS 0
  3259. +
  3260. +/* Page protection bits */
  3261. +#define _PAGE_BASE (_PAGE_PRESENT | _PAGE_ACCESSED | _PAGE_USER)
  3262. +
  3263. +#define PAGE_NONE __pgprot(0)
  3264. +#define PAGE_READ __pgprot(_PAGE_BASE | _PAGE_READ)
  3265. +#define PAGE_WRITE __pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_WRITE)
  3266. +#define PAGE_EXEC __pgprot(_PAGE_BASE | _PAGE_EXEC)
  3267. +#define PAGE_READ_EXEC __pgprot(_PAGE_BASE | _PAGE_READ | _PAGE_EXEC)
  3268. +#define PAGE_WRITE_EXEC __pgprot(_PAGE_BASE | _PAGE_READ | \
  3269. + _PAGE_EXEC | _PAGE_WRITE)
  3270. +
  3271. +#define PAGE_COPY PAGE_READ
  3272. +#define PAGE_COPY_EXEC PAGE_EXEC
  3273. +#define PAGE_COPY_READ_EXEC PAGE_READ_EXEC
  3274. +#define PAGE_SHARED PAGE_WRITE
  3275. +#define PAGE_SHARED_EXEC PAGE_WRITE_EXEC
  3276. +
  3277. +#define PAGE_KERNEL __pgprot(_PAGE_READ | _PAGE_WRITE | \
  3278. + _PAGE_PRESENT | _PAGE_ACCESSED)
  3279. +
  3280. +#define swapper_pg_dir NULL
  3281. +
  3282. +/* MAP_PRIVATE permissions: xwr (copy-on-write) */
  3283. +#define __P000 PAGE_NONE
  3284. +#define __P001 PAGE_READ
  3285. +#define __P010 PAGE_COPY
  3286. +#define __P011 PAGE_COPY
  3287. +#define __P100 PAGE_EXEC
  3288. +#define __P101 PAGE_READ_EXEC
  3289. +#define __P110 PAGE_COPY_EXEC
  3290. +#define __P111 PAGE_COPY_READ_EXEC
  3291. +
  3292. +/* MAP_SHARED permissions: xwr */
  3293. +#define __S000 PAGE_NONE
  3294. +#define __S001 PAGE_READ
  3295. +#define __S010 PAGE_SHARED
  3296. +#define __S011 PAGE_SHARED
  3297. +#define __S100 PAGE_EXEC
  3298. +#define __S101 PAGE_READ_EXEC
  3299. +#define __S110 PAGE_SHARED_EXEC
  3300. +#define __S111 PAGE_SHARED_EXEC
  3301. +
  3302. +/*
  3303. + * ZERO_PAGE is a global shared page that is always zero,
  3304. + * used for zero-mapped memory areas, etc.
  3305. + */
  3306. +extern unsigned long empty_zero_page[PAGE_SIZE / sizeof(unsigned long)];
  3307. +#define ZERO_PAGE(vaddr) (virt_to_page(empty_zero_page))
  3308. +
  3309. +static inline int pmd_present(pmd_t pmd)
  3310. +{
  3311. + return (pmd_val(pmd) & _PAGE_PRESENT);
  3312. +}
  3313. +
  3314. +static inline int pmd_none(pmd_t pmd)
  3315. +{
  3316. + return (pmd_val(pmd) == 0);
  3317. +}
  3318. +
  3319. +static inline int pmd_bad(pmd_t pmd)
  3320. +{
  3321. + return !pmd_present(pmd);
  3322. +}
  3323. +
  3324. +static inline void set_pmd(pmd_t *pmdp, pmd_t pmd)
  3325. +{
  3326. + *pmdp = pmd;
  3327. +}
  3328. +
  3329. +static inline void pmd_clear(pmd_t *pmdp)
  3330. +{
  3331. + set_pmd(pmdp, __pmd(0));
  3332. +}
  3333. +
  3334. +
  3335. +#define pgd_index(addr) (((addr) >> PGDIR_SHIFT) & (PTRS_PER_PGD - 1))
  3336. +
  3337. +/* Locate an entry in the page global directory */
  3338. +static inline pgd_t *pgd_offset(const struct mm_struct *mm, unsigned long addr)
  3339. +{
  3340. + return mm->pgd + pgd_index(addr);
  3341. +}
  3342. +/* Locate an entry in the kernel page global directory */
  3343. +#define pgd_offset_k(addr) pgd_offset(&init_mm, (addr))
  3344. +
  3345. +static inline struct page *pmd_page(pmd_t pmd)
  3346. +{
  3347. + return pfn_to_page(pmd_val(pmd) >> _PAGE_PFN_SHIFT);
  3348. +}
  3349. +
  3350. +static inline unsigned long pmd_page_vaddr(pmd_t pmd)
  3351. +{
  3352. + return (unsigned long)pfn_to_virt(pmd_val(pmd) >> _PAGE_PFN_SHIFT);
  3353. +}
  3354. +
  3355. +/* Yields the page frame number (PFN) of a page table entry */
  3356. +static inline unsigned long pte_pfn(pte_t pte)
  3357. +{
  3358. + return (pte_val(pte) >> _PAGE_PFN_SHIFT);
  3359. +}
  3360. +
  3361. +#define pte_page(x) pfn_to_page(pte_pfn(x))
  3362. +
  3363. +/* Constructs a page table entry */
  3364. +static inline pte_t pfn_pte(unsigned long pfn, pgprot_t prot)
  3365. +{
  3366. + return __pte((pfn << _PAGE_PFN_SHIFT) | pgprot_val(prot));
  3367. +}
  3368. +
  3369. +static inline pte_t mk_pte(struct page *page, pgprot_t prot)
  3370. +{
  3371. + return pfn_pte(page_to_pfn(page), prot);
  3372. +}
  3373. +
  3374. +#define pte_index(addr) (((addr) >> PAGE_SHIFT) & (PTRS_PER_PTE - 1))
  3375. +
  3376. +static inline pte_t *pte_offset_kernel(pmd_t *pmd, unsigned long addr)
  3377. +{
  3378. + return (pte_t *)pmd_page_vaddr(*pmd) + pte_index(addr);
  3379. +}
  3380. +
  3381. +#define pte_offset_map(dir, addr) pte_offset_kernel((dir), (addr))
  3382. +#define pte_unmap(pte) ((void)(pte))
  3383. +
  3384. +/*
  3385. + * Certain architectures need to do special things when PTEs within
  3386. + * a page table are directly modified. Thus, the following hook is
  3387. + * made available.
  3388. + */
  3389. +static inline void set_pte(pte_t *ptep, pte_t pteval)
  3390. +{
  3391. + *ptep = pteval;
  3392. +}
  3393. +
  3394. +static inline void set_pte_at(struct mm_struct *mm,
  3395. + unsigned long addr, pte_t *ptep, pte_t pteval)
  3396. +{
  3397. + set_pte(ptep, pteval);
  3398. +}
  3399. +
  3400. +static inline void pte_clear(struct mm_struct *mm,
  3401. + unsigned long addr, pte_t *ptep)
  3402. +{
  3403. + set_pte_at(mm, addr, ptep, __pte(0));
  3404. +}
  3405. +
  3406. +static inline int pte_present(pte_t pte)
  3407. +{
  3408. + return (pte_val(pte) & _PAGE_PRESENT);
  3409. +}
  3410. +
  3411. +static inline int pte_none(pte_t pte)
  3412. +{
  3413. + return (pte_val(pte) == 0);
  3414. +}
  3415. +
  3416. +/* static inline int pte_read(pte_t pte) */
  3417. +
  3418. +static inline int pte_write(pte_t pte)
  3419. +{
  3420. + return pte_val(pte) & _PAGE_WRITE;
  3421. +}
  3422. +
  3423. +static inline int pte_huge(pte_t pte)
  3424. +{
  3425. + return pte_present(pte)
  3426. + && (pte_val(pte) & (_PAGE_READ | _PAGE_WRITE | _PAGE_EXEC));
  3427. +}
  3428. +
  3429. +/* static inline int pte_exec(pte_t pte) */
  3430. +
  3431. +static inline int pte_dirty(pte_t pte)
  3432. +{
  3433. + return pte_val(pte) & _PAGE_DIRTY;
  3434. +}
  3435. +
  3436. +static inline int pte_young(pte_t pte)
  3437. +{
  3438. + return pte_val(pte) & _PAGE_ACCESSED;
  3439. +}
  3440. +
  3441. +static inline int pte_special(pte_t pte)
  3442. +{
  3443. + return pte_val(pte) & _PAGE_SPECIAL;
  3444. +}
  3445. +
  3446. +/* static inline pte_t pte_rdprotect(pte_t pte) */
  3447. +
  3448. +static inline pte_t pte_wrprotect(pte_t pte)
  3449. +{
  3450. + return __pte(pte_val(pte) & ~(_PAGE_WRITE));
  3451. +}
  3452. +
  3453. +/* static inline pte_t pte_mkread(pte_t pte) */
  3454. +
  3455. +static inline pte_t pte_mkwrite(pte_t pte)
  3456. +{
  3457. + return __pte(pte_val(pte) | _PAGE_WRITE);
  3458. +}
  3459. +
  3460. +/* static inline pte_t pte_mkexec(pte_t pte) */
  3461. +
  3462. +static inline pte_t pte_mkdirty(pte_t pte)
  3463. +{
  3464. + return __pte(pte_val(pte) | _PAGE_DIRTY);
  3465. +}
  3466. +
  3467. +static inline pte_t pte_mkclean(pte_t pte)
  3468. +{
  3469. + return __pte(pte_val(pte) & ~(_PAGE_DIRTY));
  3470. +}
  3471. +
  3472. +static inline pte_t pte_mkyoung(pte_t pte)
  3473. +{
  3474. + return __pte(pte_val(pte) & ~(_PAGE_ACCESSED));
  3475. +}
  3476. +
  3477. +static inline pte_t pte_mkold(pte_t pte)
  3478. +{
  3479. + return __pte(pte_val(pte) | _PAGE_ACCESSED);
  3480. +}
  3481. +
  3482. +static inline pte_t pte_mkspecial(pte_t pte)
  3483. +{
  3484. + return __pte(pte_val(pte) | _PAGE_SPECIAL);
  3485. +}
  3486. +
  3487. +/* Modify page protection bits */
  3488. +static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
  3489. +{
  3490. + return __pte((pte_val(pte) & _PAGE_CHG_MASK) | pgprot_val(newprot));
  3491. +}
  3492. +
  3493. +#define pgd_ERROR(e) \
  3494. + pr_err("%s:%d: bad pgd " PTE_FMT ".\n", __FILE__, __LINE__, pgd_val(e))
  3495. +
  3496. +
  3497. +/* Commit new configuration to MMU hardware */
  3498. +static inline void update_mmu_cache(struct vm_area_struct *vma,
  3499. + unsigned long address, pte_t *ptep)
  3500. +{
  3501. +}
  3502. +
  3503. +/*
  3504. + * Encode and decode a swap entry
  3505. + *
  3506. + * Format of swap PTE:
  3507. + * bit 0: _PAGE_PRESENT (zero)
  3508. + * bit 1: reserved for future use (zero)
  3509. + * bits 2 to 6: swap type
  3510. + * bits 7 to XLEN-1: swap offset
  3511. + */
  3512. +#define __SWP_TYPE_SHIFT 2
  3513. +#define __SWP_TYPE_BITS 5
  3514. +#define __SWP_TYPE_MASK ((1UL << __SWP_TYPE_BITS) - 1)
  3515. +#define __SWP_OFFSET_SHIFT (__SWP_TYPE_BITS + __SWP_TYPE_SHIFT)
  3516. +
  3517. +#define MAX_SWAPFILES_CHECK() \
  3518. + BUILD_BUG_ON(MAX_SWAPFILES_SHIFT > __SWP_TYPE_BITS)
  3519. +
  3520. +#define __swp_type(x) (((x).val >> __SWP_TYPE_SHIFT) & __SWP_TYPE_MASK)
  3521. +#define __swp_offset(x) ((x).val >> __SWP_OFFSET_SHIFT)
  3522. +#define __swp_entry(type, offset) ((swp_entry_t) \
  3523. + { ((type) << __SWP_TYPE_SHIFT) | ((offset) << __SWP_OFFSET_SHIFT) })
  3524. +
  3525. +#define __pte_to_swp_entry(pte) ((swp_entry_t) { pte_val(pte) })
  3526. +#define __swp_entry_to_pte(x) ((pte_t) { (x).val })
  3527. +
  3528. +#ifdef CONFIG_FLATMEM
  3529. +#define kern_addr_valid(addr) (1) /* FIXME */
  3530. +#endif
  3531. +
  3532. +extern void paging_init(void);
  3533. +
  3534. +static inline void pgtable_cache_init(void)
  3535. +{
  3536. + /* No page table caches to initialize */
  3537. +}
  3538. +
  3539. +#endif /* CONFIG_MMU */
  3540. +
  3541. +#define VMALLOC_SIZE _AC(0x8000000,UL)
  3542. +#define VMALLOC_END (PAGE_OFFSET - 1)
  3543. +#define VMALLOC_START (PAGE_OFFSET - VMALLOC_SIZE)
  3544. +
  3545. +/* Task size is 0x40000000000 for RV64 or 0xb800000 for RV32.
  3546. + Note that PGDIR_SIZE must evenly divide TASK_SIZE. */
  3547. +#ifdef CONFIG_64BIT
  3548. +#define TASK_SIZE (PGDIR_SIZE * PTRS_PER_PGD / 2)
  3549. +#else
  3550. +#define TASK_SIZE VMALLOC_START
  3551. +#endif
  3552. +
  3553. +#include <asm-generic/pgtable.h>
  3554. +
  3555. +#endif /* !__ASSEMBLY__ */
  3556. +
  3557. +#endif /* _ASM_RISCV_PGTABLE_H */
  3558. diff -Nur linux-4.6.2/arch/riscv/include/asm/processor.h linux-4.6.2.riscv/arch/riscv/include/asm/processor.h
  3559. --- linux-4.6.2/arch/riscv/include/asm/processor.h 1970-01-01 01:00:00.000000000 +0100
  3560. +++ linux-4.6.2.riscv/arch/riscv/include/asm/processor.h 2017-03-04 02:48:34.166888015 +0100
  3561. @@ -0,0 +1,87 @@
  3562. +#ifndef _ASM_RISCV_PROCESSOR_H
  3563. +#define _ASM_RISCV_PROCESSOR_H
  3564. +
  3565. +#include <linux/const.h>
  3566. +
  3567. +#include <asm/ptrace.h>
  3568. +
  3569. +/*
  3570. + * This decides where the kernel will search for a free chunk of vm
  3571. + * space during mmap's.
  3572. + */
  3573. +#define TASK_UNMAPPED_BASE PAGE_ALIGN(TASK_SIZE >> 1)
  3574. +
  3575. +#ifdef __KERNEL__
  3576. +#define STACK_TOP TASK_SIZE
  3577. +#define STACK_TOP_MAX STACK_TOP
  3578. +#endif /* __KERNEL__ */
  3579. +
  3580. +#ifndef __ASSEMBLY__
  3581. +
  3582. +struct task_struct;
  3583. +struct pt_regs;
  3584. +
  3585. +/*
  3586. + * Default implementation of macro that returns current
  3587. + * instruction pointer ("program counter").
  3588. + */
  3589. +#define current_text_addr() ({ __label__ _l; _l: &&_l;})
  3590. +
  3591. +/* CPU-specific state of a task */
  3592. +struct thread_struct {
  3593. + /* Callee-saved registers */
  3594. + unsigned long ra;
  3595. + unsigned long sp; /* Kernel mode stack */
  3596. + unsigned long s[12]; /* s[0]: frame pointer */
  3597. + struct user_fpregs_struct fstate;
  3598. +};
  3599. +
  3600. +#define INIT_THREAD { \
  3601. + .sp = sizeof(init_stack) + (long)&init_stack, \
  3602. +}
  3603. +
  3604. +/* Return saved (kernel) PC of a blocked thread. */
  3605. +#define thread_saved_pc(t) ((t)->thread.ra)
  3606. +#define thread_saved_sp(t) ((t)->thread.sp)
  3607. +#define thread_saved_fp(t) ((t)->thread.s[0])
  3608. +
  3609. +#define task_pt_regs(tsk) \
  3610. + ((struct pt_regs *)(task_stack_page(tsk) + THREAD_SIZE) - 1)
  3611. +
  3612. +#define KSTK_EIP(tsk) (task_pt_regs(tsk)->sepc)
  3613. +#define KSTK_ESP(tsk) (task_pt_regs(tsk)->sp)
  3614. +
  3615. +
  3616. +/* Do necessary setup to start up a newly executed thread. */
  3617. +extern void start_thread(struct pt_regs *regs,
  3618. + unsigned long pc, unsigned long sp);
  3619. +
  3620. +/* Free all resources held by a thread. */
  3621. +static inline void release_thread(struct task_struct *dead_task)
  3622. +{
  3623. +}
  3624. +
  3625. +/* Free current thread data structures, etc. */
  3626. +static inline void exit_thread(void)
  3627. +{
  3628. +}
  3629. +
  3630. +extern unsigned long get_wchan(struct task_struct *p);
  3631. +
  3632. +
  3633. +static inline void cpu_relax(void)
  3634. +{
  3635. + int dummy;
  3636. + /* In lieu of a halt instruction, induce a long-latency stall. */
  3637. + __asm__ __volatile__ ("div %0, %0, zero" : "=r" (dummy));
  3638. + barrier();
  3639. +}
  3640. +
  3641. +static inline void wait_for_interrupt(void)
  3642. +{
  3643. + __asm__ __volatile__ ("wfi");
  3644. +}
  3645. +
  3646. +#endif /* __ASSEMBLY__ */
  3647. +
  3648. +#endif /* _ASM_RISCV_PROCESSOR_H */
  3649. diff -Nur linux-4.6.2/arch/riscv/include/asm/ptrace.h linux-4.6.2.riscv/arch/riscv/include/asm/ptrace.h
  3650. --- linux-4.6.2/arch/riscv/include/asm/ptrace.h 1970-01-01 01:00:00.000000000 +0100
  3651. +++ linux-4.6.2.riscv/arch/riscv/include/asm/ptrace.h 2017-03-04 02:48:34.166888015 +0100
  3652. @@ -0,0 +1,103 @@
  3653. +#ifndef _ASM_RISCV_PTRACE_H
  3654. +#define _ASM_RISCV_PTRACE_H
  3655. +
  3656. +#include <uapi/asm/ptrace.h>
  3657. +#include <asm/csr.h>
  3658. +
  3659. +#ifndef __ASSEMBLY__
  3660. +
  3661. +struct pt_regs {
  3662. + unsigned long sepc;
  3663. + unsigned long ra;
  3664. + unsigned long sp;
  3665. + unsigned long gp;
  3666. + unsigned long tp;
  3667. + unsigned long t0;
  3668. + unsigned long t1;
  3669. + unsigned long t2;
  3670. + unsigned long s0;
  3671. + unsigned long s1;
  3672. + unsigned long a0;
  3673. + unsigned long a1;
  3674. + unsigned long a2;
  3675. + unsigned long a3;
  3676. + unsigned long a4;
  3677. + unsigned long a5;
  3678. + unsigned long a6;
  3679. + unsigned long a7;
  3680. + unsigned long s2;
  3681. + unsigned long s3;
  3682. + unsigned long s4;
  3683. + unsigned long s5;
  3684. + unsigned long s6;
  3685. + unsigned long s7;
  3686. + unsigned long s8;
  3687. + unsigned long s9;
  3688. + unsigned long s10;
  3689. + unsigned long s11;
  3690. + unsigned long t3;
  3691. + unsigned long t4;
  3692. + unsigned long t5;
  3693. + unsigned long t6;
  3694. + /* Supervisor CSRs */
  3695. + unsigned long sstatus;
  3696. + unsigned long sbadaddr;
  3697. + unsigned long scause;
  3698. +};
  3699. +
  3700. +#ifdef CONFIG_64BIT
  3701. +#define REG_FMT "%016lx"
  3702. +#else
  3703. +#define REG_FMT "%08lx"
  3704. +#endif
  3705. +
  3706. +#define user_mode(regs) (((regs)->sstatus & SR_PS) == 0)
  3707. +
  3708. +
  3709. +/* Helpers for working with the instruction pointer */
  3710. +#define GET_IP(regs) ((regs)->sepc)
  3711. +#define SET_IP(regs, val) (GET_IP(regs) = (val))
  3712. +
  3713. +static inline unsigned long instruction_pointer(struct pt_regs *regs)
  3714. +{
  3715. + return GET_IP(regs);
  3716. +}
  3717. +static inline void instruction_pointer_set(struct pt_regs *regs,
  3718. + unsigned long val)
  3719. +{
  3720. + SET_IP(regs, val);
  3721. +}
  3722. +
  3723. +#define profile_pc(regs) instruction_pointer(regs)
  3724. +
  3725. +/* Helpers for working with the user stack pointer */
  3726. +#define GET_USP(regs) ((regs)->sp)
  3727. +#define SET_USP(regs, val) (GET_USP(regs) = (val))
  3728. +
  3729. +static inline unsigned long user_stack_pointer(struct pt_regs *regs)
  3730. +{
  3731. + return GET_USP(regs);
  3732. +}
  3733. +static inline void user_stack_pointer_set(struct pt_regs *regs,
  3734. + unsigned long val)
  3735. +{
  3736. + SET_USP(regs, val);
  3737. +}
  3738. +
  3739. +/* Helpers for working with the frame pointer */
  3740. +#define GET_FP(regs) ((regs)->s0)
  3741. +#define SET_FP(regs, val) (GET_FP(regs) = (val))
  3742. +
  3743. +static inline unsigned long frame_pointer(struct pt_regs *regs)
  3744. +{
  3745. + return GET_FP(regs);
  3746. +}
  3747. +static inline void frame_pointer_set(struct pt_regs *regs,
  3748. + unsigned long val)
  3749. +{
  3750. + SET_FP(regs, val);
  3751. +}
  3752. +
  3753. +#endif /* __ASSEMBLY__ */
  3754. +
  3755. +#endif /* _ASM_RISCV_PTRACE_H */
  3756. diff -Nur linux-4.6.2/arch/riscv/include/asm/sbi-con.h linux-4.6.2.riscv/arch/riscv/include/asm/sbi-con.h
  3757. --- linux-4.6.2/arch/riscv/include/asm/sbi-con.h 1970-01-01 01:00:00.000000000 +0100
  3758. +++ linux-4.6.2.riscv/arch/riscv/include/asm/sbi-con.h 2017-03-04 02:48:34.166888015 +0100
  3759. @@ -0,0 +1,8 @@
  3760. +#ifndef _ASM_RISCV_SBI_CON_H
  3761. +#define _ASM_RISCV_SBI_CON_H
  3762. +
  3763. +#include <linux/irqreturn.h>
  3764. +
  3765. +irqreturn_t sbi_console_isr(void);
  3766. +
  3767. +#endif /* _ASM_RISCV_SBI_CON_H */
  3768. diff -Nur linux-4.6.2/arch/riscv/include/asm/sbi.h linux-4.6.2.riscv/arch/riscv/include/asm/sbi.h
  3769. --- linux-4.6.2/arch/riscv/include/asm/sbi.h 1970-01-01 01:00:00.000000000 +0100
  3770. +++ linux-4.6.2.riscv/arch/riscv/include/asm/sbi.h 2017-03-04 02:48:34.166888015 +0100
  3771. @@ -0,0 +1,30 @@
  3772. +#ifndef _ASM_RISCV_SBI_H
  3773. +#define _ASM_RISCV_SBI_H
  3774. +
  3775. +typedef struct {
  3776. + unsigned long base;
  3777. + unsigned long size;
  3778. + unsigned long node_id;
  3779. +} memory_block_info;
  3780. +
  3781. +unsigned long sbi_query_memory(unsigned long id, memory_block_info *p);
  3782. +
  3783. +unsigned long sbi_hart_id(void);
  3784. +unsigned long sbi_num_harts(void);
  3785. +unsigned long sbi_timebase(void);
  3786. +void sbi_set_timer(unsigned long long stime_value);
  3787. +void sbi_send_ipi(unsigned long hart_id);
  3788. +unsigned long sbi_clear_ipi(void);
  3789. +void sbi_shutdown(void);
  3790. +
  3791. +void sbi_console_putchar(unsigned char ch);
  3792. +int sbi_console_getchar(void);
  3793. +
  3794. +void sbi_remote_sfence_vm(unsigned long hart_mask_ptr, unsigned long asid);
  3795. +void sbi_remote_sfence_vm_range(unsigned long hart_mask_ptr, unsigned long asid, unsigned long start, unsigned long size);
  3796. +void sbi_remote_fence_i(unsigned long hart_mask_ptr);
  3797. +
  3798. +unsigned long sbi_mask_interrupt(unsigned long which);
  3799. +unsigned long sbi_unmask_interrupt(unsigned long which);
  3800. +
  3801. +#endif
  3802. diff -Nur linux-4.6.2/arch/riscv/include/asm/serial.h linux-4.6.2.riscv/arch/riscv/include/asm/serial.h
  3803. --- linux-4.6.2/arch/riscv/include/asm/serial.h 1970-01-01 01:00:00.000000000 +0100
  3804. +++ linux-4.6.2.riscv/arch/riscv/include/asm/serial.h 2017-03-04 02:48:34.166888015 +0100
  3805. @@ -0,0 +1,29 @@
  3806. +#ifndef _ASM_RISCV_SERIAL_H
  3807. +#define _ASM_RISCV_SERIAL_H
  3808. +
  3809. +/*
  3810. + * FIXME: interim serial support for riscv-qemu
  3811. + *
  3812. + * Currently requires that the emulator itself create a hole at addresses
  3813. + * 0x3f8 - 0x3ff without looking through page tables.
  3814. + *
  3815. + * This assumes you have a 1.8432 MHz clock for your UART.
  3816. + */
  3817. +#define BASE_BAUD ( 1843200 / 16 )
  3818. +
  3819. +/* Standard COM flags */
  3820. +#ifdef CONFIG_SERIAL_DETECT_IRQ
  3821. +#define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST | ASYNC_AUTO_IRQ)
  3822. +#else
  3823. +#define STD_COM_FLAGS (ASYNC_BOOT_AUTOCONF | ASYNC_SKIP_TEST)
  3824. +#endif
  3825. +
  3826. +#define SERIAL_PORT_DFNS \
  3827. + { /* ttyS0 */ \
  3828. + .baud_base = BASE_BAUD, \
  3829. + .port = 0x3F8, \
  3830. + .irq = 4, \
  3831. + .flags = STD_COM_FLAGS, \
  3832. + },
  3833. +
  3834. +#endif /* _ASM_RISCV_SERIAL_H */
  3835. diff -Nur linux-4.6.2/arch/riscv/include/asm/setup.h linux-4.6.2.riscv/arch/riscv/include/asm/setup.h
  3836. --- linux-4.6.2/arch/riscv/include/asm/setup.h 1970-01-01 01:00:00.000000000 +0100
  3837. +++ linux-4.6.2.riscv/arch/riscv/include/asm/setup.h 2017-03-04 02:48:34.166888015 +0100
  3838. @@ -0,0 +1,6 @@
  3839. +#ifndef _ASM_RISCV_SETUP_H
  3840. +#define _ASM_RISCV_SETUP_H
  3841. +
  3842. +#include <asm-generic/setup.h>
  3843. +
  3844. +#endif /* _ASM_RISCV_SETUP_H */
  3845. diff -Nur linux-4.6.2/arch/riscv/include/asm/smp.h linux-4.6.2.riscv/arch/riscv/include/asm/smp.h
  3846. --- linux-4.6.2/arch/riscv/include/asm/smp.h 1970-01-01 01:00:00.000000000 +0100
  3847. +++ linux-4.6.2.riscv/arch/riscv/include/asm/smp.h 2017-03-04 02:48:34.166888015 +0100
  3848. @@ -0,0 +1,28 @@
  3849. +#ifndef _ASM_RISCV_SMP_H
  3850. +#define _ASM_RISCV_SMP_H
  3851. +
  3852. +#include <linux/cpumask.h>
  3853. +#include <linux/irqreturn.h>
  3854. +
  3855. +#ifdef CONFIG_SMP
  3856. +
  3857. +/* SMP initialization hook for setup_arch */
  3858. +void __init init_clockevent(void);
  3859. +
  3860. +/* SMP initialization hook for setup_arch */
  3861. +void __init setup_smp(void);
  3862. +
  3863. +/* Hook for the generic smp_call_function_many() routine. */
  3864. +void arch_send_call_function_ipi_mask(struct cpumask *mask);
  3865. +
  3866. +/* Hook for the generic smp_call_function_single() routine. */
  3867. +void arch_send_call_function_single_ipi(int cpu);
  3868. +
  3869. +#define raw_smp_processor_id() (current_thread_info()->cpu)
  3870. +
  3871. +/* Interprocessor interrupt handler */
  3872. +irqreturn_t handle_ipi(void);
  3873. +
  3874. +#endif /* CONFIG_SMP */
  3875. +
  3876. +#endif /* _ASM_RISCV_SMP_H */
  3877. diff -Nur linux-4.6.2/arch/riscv/include/asm/spinlock.h linux-4.6.2.riscv/arch/riscv/include/asm/spinlock.h
  3878. --- linux-4.6.2/arch/riscv/include/asm/spinlock.h 1970-01-01 01:00:00.000000000 +0100
  3879. +++ linux-4.6.2.riscv/arch/riscv/include/asm/spinlock.h 2017-03-04 02:48:34.166888015 +0100
  3880. @@ -0,0 +1,142 @@
  3881. +#ifndef _ASM_RISCV_SPINLOCK_H
  3882. +#define _ASM_RISCV_SPINLOCK_H
  3883. +
  3884. +#include <linux/kernel.h>
  3885. +#include <asm/current.h>
  3886. +
  3887. +/*
  3888. + * Simple spin lock operations. These provide no fairness guarantees.
  3889. + */
  3890. +
  3891. +#define arch_spin_lock_flags(lock, flags) arch_spin_lock(lock)
  3892. +#define arch_spin_is_locked(x) ((x)->lock != 0)
  3893. +#define arch_spin_unlock_wait(x) \
  3894. + do { cpu_relax(); } while ((x)->lock)
  3895. +
  3896. +static inline void arch_spin_unlock(arch_spinlock_t *lock)
  3897. +{
  3898. + __asm__ __volatile__ (
  3899. + "amoswap.w.rl x0, x0, %0"
  3900. + : "=A" (lock->lock)
  3901. + :: "memory");
  3902. +}
  3903. +
  3904. +static inline int arch_spin_trylock(arch_spinlock_t *lock)
  3905. +{
  3906. + int tmp = 1, busy;
  3907. +
  3908. + __asm__ __volatile__ (
  3909. + "amoswap.w.aq %0, %2, %1"
  3910. + : "=r" (busy), "+A" (lock->lock)
  3911. + : "r" (tmp)
  3912. + : "memory");
  3913. +
  3914. + return !busy;
  3915. +}
  3916. +
  3917. +static inline void arch_spin_lock(arch_spinlock_t *lock)
  3918. +{
  3919. + while (1) {
  3920. + if (arch_spin_is_locked(lock))
  3921. + continue;
  3922. +
  3923. + if (arch_spin_trylock(lock))
  3924. + break;
  3925. + }
  3926. +}
  3927. +
  3928. +/***********************************************************/
  3929. +
  3930. +static inline int arch_read_can_lock(arch_rwlock_t *lock)
  3931. +{
  3932. + return lock->lock >= 0;
  3933. +}
  3934. +
  3935. +static inline int arch_write_can_lock(arch_rwlock_t *lock)
  3936. +{
  3937. + return lock->lock == 0;
  3938. +}
  3939. +
  3940. +static inline void arch_read_lock(arch_rwlock_t *lock)
  3941. +{
  3942. + int tmp;
  3943. +
  3944. + __asm__ __volatile__(
  3945. + "1: lr.w %1, %0\n"
  3946. + " bltz %1, 1b\n"
  3947. + " addi %1, %1, 1\n"
  3948. + " sc.w.aq %1, %1, %0\n"
  3949. + " bnez %1, 1b\n"
  3950. + : "+A" (lock->lock), "=&r" (tmp)
  3951. + :: "memory");
  3952. +}
  3953. +
  3954. +static inline void arch_write_lock(arch_rwlock_t *lock)
  3955. +{
  3956. + int tmp;
  3957. +
  3958. + __asm__ __volatile__(
  3959. + "1: lr.w %1, %0\n"
  3960. + " bnez %1, 1b\n"
  3961. + " li %1, -1\n"
  3962. + " sc.w.aq %1, %1, %0\n"
  3963. + " bnez %1, 1b\n"
  3964. + : "+A" (lock->lock), "=&r" (tmp)
  3965. + :: "memory");
  3966. +}
  3967. +
  3968. +static inline int arch_read_trylock(arch_rwlock_t * lock)
  3969. +{
  3970. + int busy;
  3971. +
  3972. + __asm__ __volatile__(
  3973. + "1: lr.w %1, %0\n"
  3974. + " bltz %1, 1f\n"
  3975. + " addi %1, %1, 1\n"
  3976. + " sc.w.aq %1, %1, %0\n"
  3977. + " bnez %1, 1b\n"
  3978. + "1:\n"
  3979. + : "+A" (lock->lock), "=&r" (busy)
  3980. + :: "memory");
  3981. +
  3982. + return !busy;
  3983. +}
  3984. +
  3985. +static inline int arch_write_trylock(arch_rwlock_t * lock)
  3986. +{
  3987. + int busy;
  3988. +
  3989. + __asm__ __volatile__(
  3990. + "1: lr.w %1, %0\n"
  3991. + " bnez %1, 1f\n"
  3992. + " li %1, -1\n"
  3993. + " sc.w.aq %1, %1, %0\n"
  3994. + " bnez %1, 1b\n"
  3995. + "1:\n"
  3996. + : "+A" (lock->lock), "=&r" (busy)
  3997. + :: "memory");
  3998. +
  3999. + return !busy;
  4000. +}
  4001. +
  4002. +static inline void arch_read_unlock(arch_rwlock_t * lock)
  4003. +{
  4004. + __asm__ __volatile__(
  4005. + "amoadd.w.rl x0, %1, %0"
  4006. + : "+A" (lock->lock)
  4007. + : "r" (-1)
  4008. + : "memory");
  4009. +}
  4010. +
  4011. +static inline void arch_write_unlock(arch_rwlock_t * lock)
  4012. +{
  4013. + __asm__ __volatile__ (
  4014. + "amoswap.w.rl x0, x0, %0"
  4015. + : "=A" (lock->lock)
  4016. + :: "memory");
  4017. +}
  4018. +
  4019. +#define arch_read_lock_flags(lock, flags) arch_read_lock(lock)
  4020. +#define arch_write_lock_flags(lock, flags) arch_write_lock(lock)
  4021. +
  4022. +#endif /* _ASM_RISCV_SPINLOCK_H */
  4023. diff -Nur linux-4.6.2/arch/riscv/include/asm/spinlock_types.h linux-4.6.2.riscv/arch/riscv/include/asm/spinlock_types.h
  4024. --- linux-4.6.2/arch/riscv/include/asm/spinlock_types.h 1970-01-01 01:00:00.000000000 +0100
  4025. +++ linux-4.6.2.riscv/arch/riscv/include/asm/spinlock_types.h 2017-03-04 02:48:34.166888015 +0100
  4026. @@ -0,0 +1,20 @@
  4027. +#ifndef _ASM_RISCV_SPINLOCK_TYPES_H
  4028. +#define _ASM_RISCV_SPINLOCK_TYPES_H
  4029. +
  4030. +#ifndef __LINUX_SPINLOCK_TYPES_H
  4031. +# error "please don't include this file directly"
  4032. +#endif
  4033. +
  4034. +typedef struct {
  4035. + volatile unsigned int lock;
  4036. +} arch_spinlock_t;
  4037. +
  4038. +#define __ARCH_SPIN_LOCK_UNLOCKED { 0 }
  4039. +
  4040. +typedef struct {
  4041. + volatile unsigned int lock;
  4042. +} arch_rwlock_t;
  4043. +
  4044. +#define __ARCH_RW_LOCK_UNLOCKED { 0 }
  4045. +
  4046. +#endif
  4047. diff -Nur linux-4.6.2/arch/riscv/include/asm/string.h linux-4.6.2.riscv/arch/riscv/include/asm/string.h
  4048. --- linux-4.6.2/arch/riscv/include/asm/string.h 1970-01-01 01:00:00.000000000 +0100
  4049. +++ linux-4.6.2.riscv/arch/riscv/include/asm/string.h 2017-03-04 02:48:34.166888015 +0100
  4050. @@ -0,0 +1,17 @@
  4051. +#ifndef _ASM_RISCV_STRING_H
  4052. +#define _ASM_RISCV_STRING_H
  4053. +
  4054. +#ifdef __KERNEL__
  4055. +
  4056. +#include <linux/types.h>
  4057. +#include <linux/linkage.h>
  4058. +
  4059. +#define __HAVE_ARCH_MEMSET
  4060. +extern asmlinkage void *memset(void *, int, size_t);
  4061. +
  4062. +#define __HAVE_ARCH_MEMCPY
  4063. +extern asmlinkage void *memcpy(void *, const void *, size_t);
  4064. +
  4065. +#endif /* __KERNEL__ */
  4066. +
  4067. +#endif /* _ASM_RISCV_STRING_H */
  4068. diff -Nur linux-4.6.2/arch/riscv/include/asm/switch_to.h linux-4.6.2.riscv/arch/riscv/include/asm/switch_to.h
  4069. --- linux-4.6.2/arch/riscv/include/asm/switch_to.h 1970-01-01 01:00:00.000000000 +0100
  4070. +++ linux-4.6.2.riscv/arch/riscv/include/asm/switch_to.h 2017-03-04 02:48:34.166888015 +0100
  4071. @@ -0,0 +1,57 @@
  4072. +#ifndef _ASM_RISCV_SWITCH_TO_H
  4073. +#define _ASM_RISCV_SWITCH_TO_H
  4074. +
  4075. +#include <asm/processor.h>
  4076. +#include <asm/ptrace.h>
  4077. +#include <asm/csr.h>
  4078. +
  4079. +extern void __fstate_save(struct task_struct *);
  4080. +extern void __fstate_restore(struct task_struct *);
  4081. +
  4082. +static inline void __fstate_clean(struct pt_regs *regs)
  4083. +{
  4084. + regs->sstatus |= (regs->sstatus & ~(SR_FS)) | SR_FS_CLEAN;
  4085. +}
  4086. +
  4087. +static inline void fstate_save(struct task_struct *task,
  4088. + struct pt_regs *regs)
  4089. +{
  4090. + if ((regs->sstatus & SR_FS) == SR_FS_DIRTY) {
  4091. + __fstate_save(task);
  4092. + __fstate_clean(regs);
  4093. + }
  4094. +}
  4095. +
  4096. +static inline void fstate_restore(struct task_struct *task,
  4097. + struct pt_regs *regs)
  4098. +{
  4099. + if ((regs->sstatus & SR_FS) != SR_FS_OFF) {
  4100. + __fstate_restore(task);
  4101. + __fstate_clean(regs);
  4102. + }
  4103. +}
  4104. +
  4105. +static inline void __switch_to_aux(struct task_struct *prev,
  4106. + struct task_struct *next)
  4107. +{
  4108. + struct pt_regs *regs;
  4109. +
  4110. + regs = task_pt_regs(prev);
  4111. + if (unlikely(regs->sstatus & SR_SD)) {
  4112. + fstate_save(prev, regs);
  4113. + }
  4114. + fstate_restore(next, task_pt_regs(next));
  4115. +}
  4116. +
  4117. +extern struct task_struct *__switch_to(struct task_struct *,
  4118. + struct task_struct *);
  4119. +
  4120. +#define switch_to(prev, next, last) \
  4121. +do { \
  4122. + struct task_struct *__prev = (prev); \
  4123. + struct task_struct *__next = (next); \
  4124. + __switch_to_aux(__prev, __next); \
  4125. + ((last) = __switch_to(__prev, __next)); \
  4126. +} while (0)
  4127. +
  4128. +#endif /* _ASM_RISCV_SWITCH_TO_H */
  4129. diff -Nur linux-4.6.2/arch/riscv/include/asm/syscall.h linux-4.6.2.riscv/arch/riscv/include/asm/syscall.h
  4130. --- linux-4.6.2/arch/riscv/include/asm/syscall.h 1970-01-01 01:00:00.000000000 +0100
  4131. +++ linux-4.6.2.riscv/arch/riscv/include/asm/syscall.h 2017-03-04 02:48:34.166888015 +0100
  4132. @@ -0,0 +1,90 @@
  4133. +/*
  4134. + * Copyright (C) 2008-2009 Red Hat, Inc. All rights reserved.
  4135. + * Copyright 2010 Tilera Corporation. All Rights Reserved.
  4136. + * Copyright 2015 Regents of the University of California, Berkeley
  4137. + *
  4138. + * This program is free software; you can redistribute it and/or
  4139. + * modify it under the terms of the GNU General Public License
  4140. + * as published by the Free Software Foundation, version 2.
  4141. + *
  4142. + * This program is distributed in the hope that it will be useful, but
  4143. + * WITHOUT ANY WARRANTY; without even the implied warranty of
  4144. + * MERCHANTABILITY OR FITNESS FOR A PARTICULAR PURPOSE, GOOD TITLE or
  4145. + * NON INFRINGEMENT. See the GNU General Public License for
  4146. + * more details.
  4147. + *
  4148. + * See asm-generic/syscall.h for descriptions of what we must do here.
  4149. + */
  4150. +
  4151. +#ifndef _ASM_RISCV_SYSCALL_H
  4152. +#define _ASM_RISCV_SYSCALL_H
  4153. +
  4154. +#include <linux/sched.h>
  4155. +#include <linux/err.h>
  4156. +
  4157. +/* The array of function pointers for syscalls. */
  4158. +extern void *sys_call_table[];
  4159. +
  4160. +/*
  4161. + * Only the low 32 bits of orig_r0 are meaningful, so we return int.
  4162. + * This importantly ignores the high bits on 64-bit, so comparisons
  4163. + * sign-extend the low 32 bits.
  4164. + */
  4165. +static inline int syscall_get_nr(struct task_struct *task,
  4166. + struct pt_regs *regs)
  4167. +{
  4168. + return regs->a7;
  4169. +}
  4170. +
  4171. +static inline void syscall_set_nr(struct task_struct *task,
  4172. + struct pt_regs *regs,
  4173. + int sysno)
  4174. +{
  4175. + regs->a7 = sysno;
  4176. +}
  4177. +
  4178. +static inline void syscall_rollback(struct task_struct *task,
  4179. + struct pt_regs *regs)
  4180. +{
  4181. + /* FIXME: We can't do this... */
  4182. +}
  4183. +
  4184. +static inline long syscall_get_error(struct task_struct *task,
  4185. + struct pt_regs *regs)
  4186. +{
  4187. + unsigned long error = regs->a0;
  4188. + return IS_ERR_VALUE(error) ? error : 0;
  4189. +}
  4190. +
  4191. +static inline long syscall_get_return_value(struct task_struct *task,
  4192. + struct pt_regs *regs)
  4193. +{
  4194. + return regs->a0;
  4195. +}
  4196. +
  4197. +static inline void syscall_set_return_value(struct task_struct *task,
  4198. + struct pt_regs *regs,
  4199. + int error, long val)
  4200. +{
  4201. + regs->a0 = (long) error ?: val;
  4202. +}
  4203. +
  4204. +static inline void syscall_get_arguments(struct task_struct *task,
  4205. + struct pt_regs *regs,
  4206. + unsigned int i, unsigned int n,
  4207. + unsigned long *args)
  4208. +{
  4209. + BUG_ON(i + n > 6);
  4210. + memcpy(args, &regs->a0 + i * sizeof(regs->a0), n * sizeof(args[0]));
  4211. +}
  4212. +
  4213. +static inline void syscall_set_arguments(struct task_struct *task,
  4214. + struct pt_regs *regs,
  4215. + unsigned int i, unsigned int n,
  4216. + const unsigned long *args)
  4217. +{
  4218. + BUG_ON(i + n > 6);
  4219. + memcpy(&regs->a0 + i * sizeof(regs->a0), args, n * sizeof(regs->a0));
  4220. +}
  4221. +
  4222. +#endif /* _ASM_TILE_SYSCALL_H */
  4223. diff -Nur linux-4.6.2/arch/riscv/include/asm/syscalls.h linux-4.6.2.riscv/arch/riscv/include/asm/syscalls.h
  4224. --- linux-4.6.2/arch/riscv/include/asm/syscalls.h 1970-01-01 01:00:00.000000000 +0100
  4225. +++ linux-4.6.2.riscv/arch/riscv/include/asm/syscalls.h 2017-03-04 02:48:34.166888015 +0100
  4226. @@ -0,0 +1,12 @@
  4227. +#ifndef _ASM_RISCV_SYSCALLS_H
  4228. +#define _ASM_RISCV_SYSCALLS_H
  4229. +
  4230. +#include <linux/linkage.h>
  4231. +
  4232. +#include <asm-generic/syscalls.h>
  4233. +
  4234. +/* kernel/sys_riscv.c */
  4235. +asmlinkage long sys_sysriscv(unsigned long, unsigned long,
  4236. + unsigned long, unsigned long);
  4237. +
  4238. +#endif /* _ASM_RISCV_SYSCALLS_H */
  4239. diff -Nur linux-4.6.2/arch/riscv/include/asm/thread_info.h linux-4.6.2.riscv/arch/riscv/include/asm/thread_info.h
  4240. --- linux-4.6.2/arch/riscv/include/asm/thread_info.h 1970-01-01 01:00:00.000000000 +0100
  4241. +++ linux-4.6.2.riscv/arch/riscv/include/asm/thread_info.h 2017-03-04 02:48:34.166888015 +0100
  4242. @@ -0,0 +1,89 @@
  4243. +#ifndef _ASM_RISCV_THREAD_INFO_H
  4244. +#define _ASM_RISCV_THREAD_INFO_H
  4245. +
  4246. +#ifdef __KERNEL__
  4247. +
  4248. +#include <asm/page.h>
  4249. +#include <linux/const.h>
  4250. +
  4251. +/* thread information allocation */
  4252. +#define THREAD_SIZE_ORDER (1)
  4253. +#define THREAD_SIZE (PAGE_SIZE << THREAD_SIZE_ORDER)
  4254. +
  4255. +#ifndef __ASSEMBLY__
  4256. +
  4257. +#include <asm/processor.h>
  4258. +#include <asm/csr.h>
  4259. +
  4260. +typedef unsigned long mm_segment_t;
  4261. +
  4262. +/*
  4263. + * low level task data that entry.S needs immediate access to
  4264. + * - this struct should fit entirely inside of one cache line
  4265. + * - this struct resides at the bottom of the supervisor stack
  4266. + * - if the members of this struct changes, the assembly constants
  4267. + * in asm-offsets.c must be updated accordingly
  4268. + */
  4269. +struct thread_info {
  4270. + struct task_struct *task; /* main task structure */
  4271. + unsigned long flags; /* low level flags */
  4272. + __u32 cpu; /* current CPU */
  4273. + int preempt_count; /* 0 => preemptable, <0 => BUG */
  4274. + mm_segment_t addr_limit;
  4275. +};
  4276. +
  4277. +/*
  4278. + * macros/functions for gaining access to the thread information structure
  4279. + *
  4280. + * preempt_count needs to be 1 initially, until the scheduler is functional.
  4281. + */
  4282. +#define INIT_THREAD_INFO(tsk) \
  4283. +{ \
  4284. + .task = &tsk, \
  4285. + .flags = 0, \
  4286. + .cpu = 0, \
  4287. + .preempt_count = INIT_PREEMPT_COUNT, \
  4288. + .addr_limit = KERNEL_DS, \
  4289. +}
  4290. +
  4291. +#define init_thread_info (init_thread_union.thread_info)
  4292. +#define init_stack (init_thread_union.stack)
  4293. +
  4294. +/*
  4295. + * Pointer to the thread_info struct of the current process
  4296. + * Assumes that the kernel mode stack (thread_union) is THREAD_SIZE-aligned
  4297. + */
  4298. +static inline struct thread_info *current_thread_info(void)
  4299. +{
  4300. + register unsigned long sp __asm__ ("sp");
  4301. + return (struct thread_info *)(sp & ~(THREAD_SIZE - 1));
  4302. +}
  4303. +
  4304. +#endif /* !__ASSEMBLY__ */
  4305. +
  4306. +/*
  4307. + * thread information flags
  4308. + * - these are process state flags that various assembly files may need to
  4309. + * access
  4310. + * - pending work-to-be-done flags are in lowest half-word
  4311. + * - other flags in upper half-word(s)
  4312. + */
  4313. +#define TIF_SYSCALL_TRACE 0 /* syscall trace active */
  4314. +#define TIF_NOTIFY_RESUME 1 /* callback before returning to user */
  4315. +#define TIF_SIGPENDING 2 /* signal pending */
  4316. +#define TIF_NEED_RESCHED 3 /* rescheduling necessary */
  4317. +#define TIF_RESTORE_SIGMASK 4 /* restore signal mask in do_signal() */
  4318. +#define TIF_MEMDIE 5 /* is terminating due to OOM killer */
  4319. +#define TIF_SYSCALL_TRACEPOINT 6 /* syscall tracepoint instrumentation */
  4320. +
  4321. +#define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
  4322. +#define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
  4323. +#define _TIF_SIGPENDING (1 << TIF_SIGPENDING)
  4324. +#define _TIF_NEED_RESCHED (1 << TIF_NEED_RESCHED)
  4325. +
  4326. +#define _TIF_WORK_MASK \
  4327. + (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING | _TIF_NEED_RESCHED)
  4328. +
  4329. +#endif /* __KERNEL__ */
  4330. +
  4331. +#endif /* _ASM_RISCV_THREAD_INFO_H */
  4332. diff -Nur linux-4.6.2/arch/riscv/include/asm/timex.h linux-4.6.2.riscv/arch/riscv/include/asm/timex.h
  4333. --- linux-4.6.2/arch/riscv/include/asm/timex.h 1970-01-01 01:00:00.000000000 +0100
  4334. +++ linux-4.6.2.riscv/arch/riscv/include/asm/timex.h 2017-03-04 02:48:34.166888015 +0100
  4335. @@ -0,0 +1,39 @@
  4336. +#ifndef _ASM_RISCV_TIMEX_H
  4337. +#define _ASM_RISCV_TIMEX_H
  4338. +
  4339. +#include <asm/param.h>
  4340. +
  4341. +#define CLOCK_TICK_RATE (HZ * 100UL)
  4342. +
  4343. +typedef unsigned long cycles_t;
  4344. +
  4345. +static inline cycles_t get_cycles(void)
  4346. +{
  4347. +#if __riscv_xlen >= 64
  4348. + cycles_t n;
  4349. + __asm__ __volatile__ (
  4350. + "rdtime %0"
  4351. + : "=r" (n));
  4352. + return n;
  4353. +#else
  4354. + u32 lo, hi, tmp;
  4355. + __asm__ __volatile__ (
  4356. + "1:\n"
  4357. + "rdtimeh %0\n"
  4358. + "rdtime %1\n"
  4359. + "rdtimeh %2\n"
  4360. + "bne %0, %2, 1b"
  4361. + : "=&r" (hi), "=&r" (lo), "=&r" (tmp));
  4362. + return ((u64)hi << 32) | lo;
  4363. +#endif
  4364. +}
  4365. +
  4366. +#define ARCH_HAS_READ_CURRENT_TIMER
  4367. +
  4368. +static inline int read_current_timer(unsigned long *timer_val)
  4369. +{
  4370. + *timer_val = get_cycles();
  4371. + return 0;
  4372. +}
  4373. +
  4374. +#endif /* _ASM_RISCV_TIMEX_H */
  4375. diff -Nur linux-4.6.2/arch/riscv/include/asm/tlbflush.h linux-4.6.2.riscv/arch/riscv/include/asm/tlbflush.h
  4376. --- linux-4.6.2/arch/riscv/include/asm/tlbflush.h 1970-01-01 01:00:00.000000000 +0100
  4377. +++ linux-4.6.2.riscv/arch/riscv/include/asm/tlbflush.h 2017-03-04 02:48:34.166888015 +0100
  4378. @@ -0,0 +1,84 @@
  4379. +#ifndef _ASM_RISCV_TLBFLUSH_H
  4380. +#define _ASM_RISCV_TLBFLUSH_H
  4381. +
  4382. +#ifdef CONFIG_MMU
  4383. +
  4384. +#include <linux/mm.h>
  4385. +#include <linux/bug.h>
  4386. +#include <asm/csr.h>
  4387. +
  4388. +/* Flush entire local TLB */
  4389. +static inline void local_flush_tlb_all(void)
  4390. +{
  4391. + __asm__ __volatile__ ("sfence.vm");
  4392. +}
  4393. +
  4394. +/* Flush one page from local TLB */
  4395. +static inline void local_flush_tlb_page(unsigned long addr)
  4396. +{
  4397. + __asm__ __volatile__ ("sfence.vm %0" : : "r" (addr));
  4398. +}
  4399. +
  4400. +#ifndef CONFIG_SMP
  4401. +
  4402. +#define flush_tlb_all() local_flush_tlb_all()
  4403. +#define flush_tlb_page(vma, addr) local_flush_tlb_page(addr)
  4404. +#define flush_tlb_range(vma, start, end) local_flush_tlb_all()
  4405. +
  4406. +#else /* CONFIG_SMP */
  4407. +
  4408. +#include <asm/sbi.h>
  4409. +
  4410. +#define flush_tlb_all() sbi_remote_sfence_vm(0, 0)
  4411. +#define flush_tlb_page(vma, addr) flush_tlb_range(vma, (addr), (addr) + 1)
  4412. +#define flush_tlb_range(vma, start, end) \
  4413. + sbi_remote_sfence_vm_range(0, 0, (start), (end) - (start))
  4414. +
  4415. +#endif /* CONFIG_SMP */
  4416. +
  4417. +/* Flush the TLB entries of the specified mm context */
  4418. +static inline void flush_tlb_mm(struct mm_struct *mm)
  4419. +{
  4420. + flush_tlb_all();
  4421. +}
  4422. +
  4423. +/* Flush a range of kernel pages */
  4424. +static inline void flush_tlb_kernel_range(unsigned long start,
  4425. + unsigned long end)
  4426. +{
  4427. + flush_tlb_all();
  4428. +}
  4429. +
  4430. +#else /* !CONFIG_MMU */
  4431. +
  4432. +static inline void flush_tlb_all(void)
  4433. +{
  4434. + BUG();
  4435. +}
  4436. +
  4437. +static inline void flush_tlb_mm(struct mm_struct *mm)
  4438. +{
  4439. + BUG();
  4440. +}
  4441. +
  4442. +static inline void flush_tlb_page(struct vm_area_struct *vma,
  4443. + unsigned long addr)
  4444. +{
  4445. + BUG();
  4446. +}
  4447. +
  4448. +static inline void flush_tlb_range(struct vm_area_struct *vma,
  4449. + unsigned long start, unsigned long end)
  4450. +{
  4451. + BUG();
  4452. +}
  4453. +
  4454. +static inline void flush_tlb_kernel_range(unsigned long start,
  4455. + unsigned long end)
  4456. +{
  4457. + BUG();
  4458. +}
  4459. +
  4460. +#endif /* CONFIG_MMU */
  4461. +
  4462. +#endif /* _ASM_RISCV_TLBFLUSH_H */
  4463. diff -Nur linux-4.6.2/arch/riscv/include/asm/tlb.h linux-4.6.2.riscv/arch/riscv/include/asm/tlb.h
  4464. --- linux-4.6.2/arch/riscv/include/asm/tlb.h 1970-01-01 01:00:00.000000000 +0100
  4465. +++ linux-4.6.2.riscv/arch/riscv/include/asm/tlb.h 2017-03-04 02:48:34.166888015 +0100
  4466. @@ -0,0 +1,11 @@
  4467. +#ifndef _ASM_RISCV_TLB_H
  4468. +#define _ASM_RISCV_TLB_H
  4469. +
  4470. +#include <asm-generic/tlb.h>
  4471. +
  4472. +static inline void tlb_flush(struct mmu_gather *tlb)
  4473. +{
  4474. + flush_tlb_mm(tlb->mm);
  4475. +}
  4476. +
  4477. +#endif /* _ASM_RISCV_TLB_H */
  4478. diff -Nur linux-4.6.2/arch/riscv/include/asm/uaccess.h linux-4.6.2.riscv/arch/riscv/include/asm/uaccess.h
  4479. --- linux-4.6.2/arch/riscv/include/asm/uaccess.h 1970-01-01 01:00:00.000000000 +0100
  4480. +++ linux-4.6.2.riscv/arch/riscv/include/asm/uaccess.h 2017-03-04 02:48:34.166888015 +0100
  4481. @@ -0,0 +1,460 @@
  4482. +#ifndef _ASM_RISCV_UACCESS_H
  4483. +#define _ASM_RISCV_UACCESS_H
  4484. +
  4485. +/*
  4486. + * User space memory access functions
  4487. + */
  4488. +#include <linux/errno.h>
  4489. +#include <linux/compiler.h>
  4490. +#include <linux/thread_info.h>
  4491. +#include <asm/byteorder.h>
  4492. +#include <asm/asm.h>
  4493. +
  4494. +#ifdef CONFIG_RV_PUM
  4495. +#define __enable_user_access() \
  4496. + __asm__ __volatile__ ("csrc sstatus, %0" : : "r" (SR_PUM))
  4497. +#define __disable_user_access() \
  4498. + __asm__ __volatile__ ("csrs sstatus, %0" : : "r" (SR_PUM))
  4499. +#else
  4500. +#define __enable_user_access()
  4501. +#define __disable_user_access()
  4502. +#endif
  4503. +
  4504. +/*
  4505. + * The fs value determines whether argument validity checking should be
  4506. + * performed or not. If get_fs() == USER_DS, checking is performed, with
  4507. + * get_fs() == KERNEL_DS, checking is bypassed.
  4508. + *
  4509. + * For historical reasons, these macros are grossly misnamed.
  4510. + */
  4511. +
  4512. +#define KERNEL_DS (~0UL)
  4513. +#define USER_DS (TASK_SIZE)
  4514. +
  4515. +#define get_ds() (KERNEL_DS)
  4516. +#define get_fs() (current_thread_info()->addr_limit)
  4517. +
  4518. +static inline void set_fs(mm_segment_t fs)
  4519. +{
  4520. + current_thread_info()->addr_limit = fs;
  4521. +}
  4522. +
  4523. +#define segment_eq(a, b) ((a) == (b))
  4524. +
  4525. +#define user_addr_max() (get_fs())
  4526. +
  4527. +
  4528. +#define VERIFY_READ 0
  4529. +#define VERIFY_WRITE 1
  4530. +
  4531. +/**
  4532. + * access_ok: - Checks if a user space pointer is valid
  4533. + * @type: Type of access: %VERIFY_READ or %VERIFY_WRITE. Note that
  4534. + * %VERIFY_WRITE is a superset of %VERIFY_READ - if it is safe
  4535. + * to write to a block, it is always safe to read from it.
  4536. + * @addr: User space pointer to start of block to check
  4537. + * @size: Size of block to check
  4538. + *
  4539. + * Context: User context only. This function may sleep.
  4540. + *
  4541. + * Checks if a pointer to a block of memory in user space is valid.
  4542. + *
  4543. + * Returns true (nonzero) if the memory block may be valid, false (zero)
  4544. + * if it is definitely invalid.
  4545. + *
  4546. + * Note that, depending on architecture, this function probably just
  4547. + * checks that the pointer is in the user space range - after calling
  4548. + * this function, memory access functions may still return -EFAULT.
  4549. + */
  4550. +#define access_ok(type, addr, size) ({ \
  4551. + __chk_user_ptr(addr); \
  4552. + likely(__access_ok((unsigned long __force)(addr), (size))); \
  4553. +})
  4554. +
  4555. +/* Ensure that the range [addr, addr+size) is within the process's
  4556. + * address space
  4557. + */
  4558. +static inline int __access_ok(unsigned long addr, unsigned long size)
  4559. +{
  4560. + const mm_segment_t fs = get_fs();
  4561. + return (size <= fs) && (addr <= (fs - size));
  4562. +}
  4563. +
  4564. +/*
  4565. + * The exception table consists of pairs of addresses: the first is the
  4566. + * address of an instruction that is allowed to fault, and the second is
  4567. + * the address at which the program should continue. No registers are
  4568. + * modified, so it is entirely up to the continuation code to figure out
  4569. + * what to do.
  4570. + *
  4571. + * All the routines below use bits of fixup code that are out of line
  4572. + * with the main instruction path. This means when everything is well,
  4573. + * we don't even have to jump over them. Further, they do not intrude
  4574. + * on our cache or tlb entries.
  4575. + */
  4576. +
  4577. +struct exception_table_entry {
  4578. + unsigned long insn, fixup;
  4579. +};
  4580. +
  4581. +extern int fixup_exception(struct pt_regs *);
  4582. +
  4583. +#if defined(__LITTLE_ENDIAN)
  4584. +#define __MSW 1
  4585. +#define __LSW 0
  4586. +#elif defined(__BIG_ENDIAN)
  4587. +#define __MSW 0
  4588. +#define __LSW 1
  4589. +#else
  4590. +#error "Unknown endianness"
  4591. +#endif
  4592. +
  4593. +/*
  4594. + * The "__xxx" versions of the user access functions do not verify the address
  4595. + * space - it must have been done previously with a separate "access_ok()"
  4596. + * call.
  4597. + */
  4598. +
  4599. +#ifdef CONFIG_MMU
  4600. +#define __get_user_asm(insn, x, ptr, err) \
  4601. +do { \
  4602. + uintptr_t __tmp; \
  4603. + __enable_user_access(); \
  4604. + __asm__ __volatile__ ( \
  4605. + "1:\n" \
  4606. + " " insn " %1, %3\n" \
  4607. + "2:\n" \
  4608. + " .section .fixup,\"ax\"\n" \
  4609. + " .balign 4\n" \
  4610. + "3:\n" \
  4611. + " li %0, %4\n" \
  4612. + " li %1, 0\n" \
  4613. + " jump 2b, %2\n" \
  4614. + " .previous\n" \
  4615. + " .section __ex_table,\"a\"\n" \
  4616. + " .balign " SZPTR "\n" \
  4617. + " " PTR " 1b, 3b\n" \
  4618. + " .previous" \
  4619. + : "+r" (err), "=&r" (x), "=r" (__tmp) \
  4620. + : "m" (*(ptr)), "i" (-EFAULT)); \
  4621. + __disable_user_access(); \
  4622. +} while (0)
  4623. +#else /* !CONFIG_MMU */
  4624. +#define __get_user_asm(insn, x, ptr, err) \
  4625. + __asm__ __volatile__ ( \
  4626. + insn " %0, %1" \
  4627. + : "=r" (x) \
  4628. + : "m" (*(ptr)))
  4629. +#endif /* CONFIG_MMU */
  4630. +
  4631. +
  4632. +#ifdef CONFIG_64BIT
  4633. +#define __get_user_8(x, ptr, err) \
  4634. + __get_user_asm("ld", x, ptr, err)
  4635. +#else /* !CONFIG_64BIT */
  4636. +#ifdef CONFIG_MMU
  4637. +#define __get_user_8(x, ptr, err) \
  4638. +do { \
  4639. + u32 __user *__ptr = (u32 __user *)(ptr); \
  4640. + u32 __lo, __hi; \
  4641. + uintptr_t __tmp; \
  4642. + __enable_user_access(); \
  4643. + __asm__ __volatile__ ( \
  4644. + "1:\n" \
  4645. + " lw %1, %4\n" \
  4646. + "2:\n" \
  4647. + " lw %2, %5\n" \
  4648. + "3:\n" \
  4649. + " .section .fixup,\"ax\"\n" \
  4650. + " .balign 4\n" \
  4651. + "4:\n" \
  4652. + " li %0, %6\n" \
  4653. + " li %1, 0\n" \
  4654. + " li %2, 0\n" \
  4655. + " jump 3b, %3\n" \
  4656. + " .previous\n" \
  4657. + " .section __ex_table,\"a\"\n" \
  4658. + " .balign " SZPTR "\n" \
  4659. + " " PTR " 1b, 4b\n" \
  4660. + " " PTR " 2b, 4b\n" \
  4661. + " .previous" \
  4662. + : "+r" (err), "=&r" (__lo), "=r" (__hi), \
  4663. + "=r" (__tmp) \
  4664. + : "m" (__ptr[__LSW]), "m" (__ptr[__MSW]), \
  4665. + "i" (-EFAULT)); \
  4666. + __disable_user_access(); \
  4667. + (x) = (__typeof__(x))((__typeof__((x)-(x)))( \
  4668. + (((u64)__hi << 32) | __lo))); \
  4669. +} while (0)
  4670. +#else /* !CONFIG_MMU */
  4671. +#define __get_user_8(x, ptr, err) \
  4672. + (x) = (__typeof__(x))(*((u64 __user *)(ptr)))
  4673. +#endif /* CONFIG_MMU */
  4674. +#endif /* CONFIG_64BIT */
  4675. +
  4676. +
  4677. +/**
  4678. + * __get_user: - Get a simple variable from user space, with less checking.
  4679. + * @x: Variable to store result.
  4680. + * @ptr: Source address, in user space.
  4681. + *
  4682. + * Context: User context only. This function may sleep.
  4683. + *
  4684. + * This macro copies a single simple variable from user space to kernel
  4685. + * space. It supports simple types like char and int, but not larger
  4686. + * data types like structures or arrays.
  4687. + *
  4688. + * @ptr must have pointer-to-simple-variable type, and the result of
  4689. + * dereferencing @ptr must be assignable to @x without a cast.
  4690. + *
  4691. + * Caller must check the pointer with access_ok() before calling this
  4692. + * function.
  4693. + *
  4694. + * Returns zero on success, or -EFAULT on error.
  4695. + * On error, the variable @x is set to zero.
  4696. + */
  4697. +#define __get_user(x, ptr) \
  4698. +({ \
  4699. + register int __gu_err = 0; \
  4700. + const __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \
  4701. + __chk_user_ptr(__gu_ptr); \
  4702. + switch (sizeof(*__gu_ptr)) { \
  4703. + case 1: \
  4704. + __get_user_asm("lb", (x), __gu_ptr, __gu_err); \
  4705. + break; \
  4706. + case 2: \
  4707. + __get_user_asm("lh", (x), __gu_ptr, __gu_err); \
  4708. + break; \
  4709. + case 4: \
  4710. + __get_user_asm("lw", (x), __gu_ptr, __gu_err); \
  4711. + break; \
  4712. + case 8: \
  4713. + __get_user_8((x), __gu_ptr, __gu_err); \
  4714. + break; \
  4715. + default: \
  4716. + BUILD_BUG(); \
  4717. + } \
  4718. + __gu_err; \
  4719. +})
  4720. +
  4721. +/**
  4722. + * get_user: - Get a simple variable from user space.
  4723. + * @x: Variable to store result.
  4724. + * @ptr: Source address, in user space.
  4725. + *
  4726. + * Context: User context only. This function may sleep.
  4727. + *
  4728. + * This macro copies a single simple variable from user space to kernel
  4729. + * space. It supports simple types like char and int, but not larger
  4730. + * data types like structures or arrays.
  4731. + *
  4732. + * @ptr must have pointer-to-simple-variable type, and the result of
  4733. + * dereferencing @ptr must be assignable to @x without a cast.
  4734. + *
  4735. + * Returns zero on success, or -EFAULT on error.
  4736. + * On error, the variable @x is set to zero.
  4737. + */
  4738. +#define get_user(x, ptr) \
  4739. +({ \
  4740. + const __typeof__(*(ptr)) __user *__p = (ptr); \
  4741. + might_fault(); \
  4742. + access_ok(VERIFY_READ, __p, sizeof(*__p)) ? \
  4743. + __get_user((x), __p) : \
  4744. + ((x) = 0, -EFAULT); \
  4745. +})
  4746. +
  4747. +
  4748. +#ifdef CONFIG_MMU
  4749. +#define __put_user_asm(insn, x, ptr, err) \
  4750. +do { \
  4751. + uintptr_t __tmp; \
  4752. + __typeof__(*(ptr)) __x = x; \
  4753. + __enable_user_access(); \
  4754. + __asm__ __volatile__ ( \
  4755. + "1:\n" \
  4756. + " " insn " %z3, %2\n" \
  4757. + "2:\n" \
  4758. + " .section .fixup,\"ax\"\n" \
  4759. + " .balign 4\n" \
  4760. + "3:\n" \
  4761. + " li %0, %4\n" \
  4762. + " jump 2b, %1\n" \
  4763. + " .previous\n" \
  4764. + " .section __ex_table,\"a\"\n" \
  4765. + " .balign " SZPTR "\n" \
  4766. + " " PTR " 1b, 3b\n" \
  4767. + " .previous" \
  4768. + : "+r" (err), "=r" (__tmp), "=m" (*(ptr)) \
  4769. + : "rJ" (__x), "i" (-EFAULT)); \
  4770. + __disable_user_access(); \
  4771. +} while (0)
  4772. +#else /* !CONFIG_MMU */
  4773. +#define __put_user_asm(insn, x, ptr, err) \
  4774. + __asm__ __volatile__ ( \
  4775. + insn " %z1, %0" \
  4776. + : "=m" (*(ptr)) \
  4777. + : "rJ" ((__typeof__(*(ptr))) x))
  4778. +#endif /* CONFIG_MMU */
  4779. +
  4780. +
  4781. +#ifdef CONFIG_64BIT
  4782. +#define __put_user_8(x, ptr, err) \
  4783. + __put_user_asm("sd", x, ptr, err)
  4784. +#else /* !CONFIG_64BIT */
  4785. +#ifdef CONFIG_MMU
  4786. +#define __put_user_8(x, ptr, err) \
  4787. +do { \
  4788. + u32 __user *__ptr = (u32 __user *)(ptr); \
  4789. + u64 __x = (__typeof__((x)-(x)))(x); \
  4790. + uintptr_t __tmp; \
  4791. + __enable_user_access(); \
  4792. + __asm__ __volatile__ ( \
  4793. + "1:\n" \
  4794. + " sw %z4, %2\n" \
  4795. + "2:\n" \
  4796. + " sw %z5, %3\n" \
  4797. + "3:\n" \
  4798. + " .section .fixup,\"ax\"\n" \
  4799. + " .balign 4\n" \
  4800. + "4:\n" \
  4801. + " li %0, %6\n" \
  4802. + " jump 2b, %1\n" \
  4803. + " .previous\n" \
  4804. + " .section __ex_table,\"a\"\n" \
  4805. + " .balign " SZPTR "\n" \
  4806. + " " PTR " 1b, 4b\n" \
  4807. + " " PTR " 2b, 4b\n" \
  4808. + " .previous" \
  4809. + : "+r" (err), "=r" (__tmp), \
  4810. + "=m" (__ptr[__LSW]), \
  4811. + "=m" (__ptr[__MSW]) \
  4812. + : "rJ" (__x), "rJ" (__x >> 32), "i" (-EFAULT)); \
  4813. + __disable_user_access(); \
  4814. +} while (0)
  4815. +#else /* !CONFIG_MMU */
  4816. +#define __put_user_8(x, ptr, err) \
  4817. + *((u64 __user *)(ptr)) = (u64)(x)
  4818. +#endif /* CONFIG_MMU */
  4819. +#endif /* CONFIG_64BIT */
  4820. +
  4821. +
  4822. +/**
  4823. + * __put_user: - Write a simple value into user space, with less checking.
  4824. + * @x: Value to copy to user space.
  4825. + * @ptr: Destination address, in user space.
  4826. + *
  4827. + * Context: User context only. This function may sleep.
  4828. + *
  4829. + * This macro copies a single simple value from kernel space to user
  4830. + * space. It supports simple types like char and int, but not larger
  4831. + * data types like structures or arrays.
  4832. + *
  4833. + * @ptr must have pointer-to-simple-variable type, and @x must be assignable
  4834. + * to the result of dereferencing @ptr.
  4835. + *
  4836. + * Caller must check the pointer with access_ok() before calling this
  4837. + * function.
  4838. + *
  4839. + * Returns zero on success, or -EFAULT on error.
  4840. + */
  4841. +#define __put_user(x, ptr) \
  4842. +({ \
  4843. + register int __pu_err = 0; \
  4844. + __typeof__(*(ptr)) __user *__gu_ptr = (ptr); \
  4845. + __chk_user_ptr(__gu_ptr); \
  4846. + switch (sizeof(*__gu_ptr)) { \
  4847. + case 1: \
  4848. + __put_user_asm("sb", (x), __gu_ptr, __pu_err); \
  4849. + break; \
  4850. + case 2: \
  4851. + __put_user_asm("sh", (x), __gu_ptr, __pu_err); \
  4852. + break; \
  4853. + case 4: \
  4854. + __put_user_asm("sw", (x), __gu_ptr, __pu_err); \
  4855. + break; \
  4856. + case 8: \
  4857. + __put_user_8((x), __gu_ptr, __pu_err); \
  4858. + break; \
  4859. + default: \
  4860. + BUILD_BUG(); \
  4861. + } \
  4862. + __pu_err; \
  4863. +})
  4864. +
  4865. +/**
  4866. + * put_user: - Write a simple value into user space.
  4867. + * @x: Value to copy to user space.
  4868. + * @ptr: Destination address, in user space.
  4869. + *
  4870. + * Context: User context only. This function may sleep.
  4871. + *
  4872. + * This macro copies a single simple value from kernel space to user
  4873. + * space. It supports simple types like char and int, but not larger
  4874. + * data types like structures or arrays.
  4875. + *
  4876. + * @ptr must have pointer-to-simple-variable type, and @x must be assignable
  4877. + * to the result of dereferencing @ptr.
  4878. + *
  4879. + * Returns zero on success, or -EFAULT on error.
  4880. + */
  4881. +#define put_user(x, ptr) \
  4882. +({ \
  4883. + __typeof__(*(ptr)) __user *__p = (ptr); \
  4884. + might_fault(); \
  4885. + access_ok(VERIFY_WRITE, __p, sizeof(*__p)) ? \
  4886. + __put_user((x), __p) : \
  4887. + -EFAULT; \
  4888. +})
  4889. +
  4890. +
  4891. +extern unsigned long __must_check __copy_user(void __user *to,
  4892. + const void __user *from, unsigned long n);
  4893. +
  4894. +static inline long __must_check __copy_from_user(void *to,
  4895. + const void __user *from, unsigned long n)
  4896. +{
  4897. + return __copy_user(to, from, n);
  4898. +}
  4899. +
  4900. +static inline long __must_check __copy_to_user(void __user *to,
  4901. + const void *from, unsigned long n)
  4902. +{
  4903. + return __copy_user(to, from, n);
  4904. +}
  4905. +
  4906. +#define __copy_from_user_inatomic(to, from, n) \
  4907. + __copy_from_user((to), (from), (n))
  4908. +#define __copy_to_user_inatomic(to, from, n) \
  4909. + __copy_to_user((to), (from), (n))
  4910. +
  4911. +static inline long copy_from_user(void *to,
  4912. + const void __user * from, unsigned long n)
  4913. +{
  4914. + might_fault();
  4915. + return access_ok(VERIFY_READ, from, n) ?
  4916. + __copy_from_user(to, from, n) : n;
  4917. +}
  4918. +
  4919. +static inline long copy_to_user(void __user *to,
  4920. + const void *from, unsigned long n)
  4921. +{
  4922. + might_fault();
  4923. + return access_ok(VERIFY_WRITE, to, n) ?
  4924. + __copy_to_user(to, from, n) : n;
  4925. +}
  4926. +
  4927. +extern long strncpy_from_user(char *dest, const char __user *src, long count);
  4928. +
  4929. +extern long __must_check strlen_user(const char __user *str);
  4930. +extern long __must_check strnlen_user(const char __user *str, long n);
  4931. +
  4932. +extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
  4933. +
  4934. +static inline unsigned long __must_check clear_user(void __user *to, unsigned long n)
  4935. +{
  4936. + might_fault();
  4937. + return access_ok(VERIFY_WRITE, to, n) ?
  4938. + __clear_user(to, n) : n;
  4939. +}
  4940. +
  4941. +#endif /* _ASM_RISCV_UACCESS_H */
  4942. diff -Nur linux-4.6.2/arch/riscv/include/asm/unistd.h linux-4.6.2.riscv/arch/riscv/include/asm/unistd.h
  4943. --- linux-4.6.2/arch/riscv/include/asm/unistd.h 1970-01-01 01:00:00.000000000 +0100
  4944. +++ linux-4.6.2.riscv/arch/riscv/include/asm/unistd.h 2017-03-04 02:48:34.166888015 +0100
  4945. @@ -0,0 +1,3 @@
  4946. +#define __ARCH_HAVE_MMU
  4947. +#define __ARCH_WANT_SYS_CLONE
  4948. +#include <uapi/asm/unistd.h>
  4949. diff -Nur linux-4.6.2/arch/riscv/include/asm/vdso.h linux-4.6.2.riscv/arch/riscv/include/asm/vdso.h
  4950. --- linux-4.6.2/arch/riscv/include/asm/vdso.h 1970-01-01 01:00:00.000000000 +0100
  4951. +++ linux-4.6.2.riscv/arch/riscv/include/asm/vdso.h 2017-03-04 02:48:34.166888015 +0100
  4952. @@ -0,0 +1,15 @@
  4953. +#ifndef _ASM_RISCV_VDSO_H
  4954. +#define _ASM_RISCV_VDSO_H
  4955. +
  4956. +#include <linux/types.h>
  4957. +
  4958. +struct vdso_data {
  4959. +};
  4960. +
  4961. +#define VDSO_SYMBOL(base, name) \
  4962. +({ \
  4963. + extern const char __vdso_##name[]; \
  4964. + (void __user *)((unsigned long)(base) + __vdso_##name); \
  4965. +})
  4966. +
  4967. +#endif /* _ASM_RISCV_VDSO_H */
  4968. diff -Nur linux-4.6.2/arch/riscv/include/asm/word-at-a-time.h linux-4.6.2.riscv/arch/riscv/include/asm/word-at-a-time.h
  4969. --- linux-4.6.2/arch/riscv/include/asm/word-at-a-time.h 1970-01-01 01:00:00.000000000 +0100
  4970. +++ linux-4.6.2.riscv/arch/riscv/include/asm/word-at-a-time.h 2017-03-04 02:48:34.166888015 +0100
  4971. @@ -0,0 +1,42 @@
  4972. +#ifndef _ASM_RISCV_WORD_AT_A_TIME_H
  4973. +#define _ASM_RISCV_WORD_AT_A_TIME_H
  4974. +
  4975. +/* Derived from arch/x86/include/asm/word-at-a-time.h */
  4976. +
  4977. +#include <linux/kernel.h>
  4978. +
  4979. +struct word_at_a_time {
  4980. + const unsigned long one_bits, high_bits;
  4981. +};
  4982. +
  4983. +#define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
  4984. +
  4985. +static inline unsigned long has_zero(unsigned long val,
  4986. + unsigned long *bits, const struct word_at_a_time *c)
  4987. +{
  4988. + unsigned long mask = ((val - c->one_bits) & ~val) & c->high_bits;
  4989. + *bits = mask;
  4990. + return mask;
  4991. +}
  4992. +
  4993. +static inline unsigned long prep_zero_mask(unsigned long val,
  4994. + unsigned long bits, const struct word_at_a_time *c)
  4995. +{
  4996. + return bits;
  4997. +}
  4998. +
  4999. +static inline unsigned long create_zero_mask(unsigned long bits)
  5000. +{
  5001. + bits = (bits - 1) & ~bits;
  5002. + return bits >> 7;
  5003. +}
  5004. +
  5005. +static inline unsigned long find_zero(unsigned long mask)
  5006. +{
  5007. + return fls64(mask) >> 3;
  5008. +}
  5009. +
  5010. +/* The mask we created is directly usable as a bytemask */
  5011. +#define zero_bytemask(mask) (mask)
  5012. +
  5013. +#endif /* _ASM_RISCV_WORD_AT_A_TIME_H */
  5014. diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/auxvec.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/auxvec.h
  5015. --- linux-4.6.2/arch/riscv/include/uapi/asm/auxvec.h 1970-01-01 01:00:00.000000000 +0100
  5016. +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/auxvec.h 2017-03-04 02:48:34.166888015 +0100
  5017. @@ -0,0 +1,7 @@
  5018. +#ifndef _UAPI_ASM_RISCV_AUXVEC_H
  5019. +#define _UAPI_ASM_RISCV_AUXVEC_H
  5020. +
  5021. +/* vDSO location */
  5022. +#define AT_SYSINFO_EHDR 33
  5023. +
  5024. +#endif /* _UAPI_ASM_RISCV_AUXVEC_H */
  5025. diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/bitsperlong.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/bitsperlong.h
  5026. --- linux-4.6.2/arch/riscv/include/uapi/asm/bitsperlong.h 1970-01-01 01:00:00.000000000 +0100
  5027. +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/bitsperlong.h 2017-03-04 02:48:34.166888015 +0100
  5028. @@ -0,0 +1,8 @@
  5029. +#ifndef _UAPI_ASM_RISCV_BITSPERLONG_H
  5030. +#define _UAPI_ASM_RISCV_BITSPERLONG_H
  5031. +
  5032. +#define __BITS_PER_LONG (__SIZEOF_POINTER__ * 8)
  5033. +
  5034. +#include <asm-generic/bitsperlong.h>
  5035. +
  5036. +#endif /* _UAPI_ASM_RISCV_BITSPERLONG_H */
  5037. diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/byteorder.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/byteorder.h
  5038. --- linux-4.6.2/arch/riscv/include/uapi/asm/byteorder.h 1970-01-01 01:00:00.000000000 +0100
  5039. +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/byteorder.h 2017-03-04 02:48:34.166888015 +0100
  5040. @@ -0,0 +1,6 @@
  5041. +#ifndef _UAPI_ASM_RISCV_BYTEORDER_H
  5042. +#define _UAPI_ASM_RISCV_BYTEORDER_H
  5043. +
  5044. +#include <linux/byteorder/little_endian.h>
  5045. +
  5046. +#endif /* _UAPI_ASM_RISCV_BYTEORDER_H */
  5047. diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/elf.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/elf.h
  5048. --- linux-4.6.2/arch/riscv/include/uapi/asm/elf.h 1970-01-01 01:00:00.000000000 +0100
  5049. +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/elf.h 2017-03-04 02:48:34.166888015 +0100
  5050. @@ -0,0 +1,64 @@
  5051. +#ifndef _UAPI_ASM_ELF_H
  5052. +#define _UAPI_ASM_ELF_H
  5053. +
  5054. +#include <asm/ptrace.h>
  5055. +
  5056. +/* ELF register definitions */
  5057. +typedef unsigned long elf_greg_t;
  5058. +typedef struct user_regs_struct elf_gregset_t;
  5059. +#define ELF_NGREG (sizeof(elf_gregset_t) / sizeof(elf_greg_t))
  5060. +
  5061. +typedef struct user_fpregs_struct elf_fpregset_t;
  5062. +
  5063. +
  5064. +/*
  5065. + * RISC-V relocation types
  5066. + */
  5067. +
  5068. +/* Relocation types used by the dynamic linker */
  5069. +#define R_RISCV_NONE 0
  5070. +#define R_RISCV_32 1
  5071. +#define R_RISCV_64 2
  5072. +#define R_RISCV_RELATIVE 3
  5073. +#define R_RISCV_COPY 4
  5074. +#define R_RISCV_JUMP_SLOT 5
  5075. +#define R_RISCV_TLS_DTPMOD32 6
  5076. +#define R_RISCV_TLS_DTPMOD64 7
  5077. +#define R_RISCV_TLS_DTPREL32 8
  5078. +#define R_RISCV_TLS_DTPREL64 9
  5079. +#define R_RISCV_TLS_TPREL32 10
  5080. +#define R_RISCV_TLS_TPREL64 11
  5081. +
  5082. +/* Relocation types not used by the dynamic linker */
  5083. +#define R_RISCV_BRANCH 16
  5084. +#define R_RISCV_JAL 17
  5085. +#define R_RISCV_CALL 18
  5086. +#define R_RISCV_CALL_PLT 19
  5087. +#define R_RISCV_GOT_HI20 20
  5088. +#define R_RISCV_TLS_GOT_HI20 21
  5089. +#define R_RISCV_TLS_GD_HI20 22
  5090. +#define R_RISCV_PCREL_HI20 23
  5091. +#define R_RISCV_PCREL_LO12_I 24
  5092. +#define R_RISCV_PCREL_LO12_S 25
  5093. +#define R_RISCV_HI20 26
  5094. +#define R_RISCV_LO12_I 27
  5095. +#define R_RISCV_LO12_S 28
  5096. +#define R_RISCV_TPREL_HI20 29
  5097. +#define R_RISCV_TPREL_LO12_I 30
  5098. +#define R_RISCV_TPREL_LO12_S 31
  5099. +#define R_RISCV_TPREL_ADD 32
  5100. +#define R_RISCV_ADD8 33
  5101. +#define R_RISCV_ADD16 34
  5102. +#define R_RISCV_ADD32 35
  5103. +#define R_RISCV_ADD64 36
  5104. +#define R_RISCV_SUB8 37
  5105. +#define R_RISCV_SUB16 38
  5106. +#define R_RISCV_SUB32 39
  5107. +#define R_RISCV_SUB64 40
  5108. +#define R_RISCV_GNU_VTINHERIT 41
  5109. +#define R_RISCV_GNU_VTENTRY 42
  5110. +#define R_RISCV_ALIGN 43
  5111. +#define R_RISCV_RVC_BRANCH 44
  5112. +#define R_RISCV_RVC_JUMP 45
  5113. +
  5114. +#endif /* _UAPI_ASM_ELF_H */
  5115. diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/Kbuild linux-4.6.2.riscv/arch/riscv/include/uapi/asm/Kbuild
  5116. --- linux-4.6.2/arch/riscv/include/uapi/asm/Kbuild 1970-01-01 01:00:00.000000000 +0100
  5117. +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/Kbuild 2017-03-04 02:48:34.166888015 +0100
  5118. @@ -0,0 +1,10 @@
  5119. +# UAPI Header export list
  5120. +include include/uapi/asm-generic/Kbuild.asm
  5121. +
  5122. +header-y += auxvec.h
  5123. +header-y += bitsperlong.h
  5124. +header-y += byteorder.h
  5125. +header-y += ptrace.h
  5126. +header-y += sigcontext.h
  5127. +header-y += siginfo.h
  5128. +header-y += unistd.h
  5129. diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/ptrace.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/ptrace.h
  5130. --- linux-4.6.2/arch/riscv/include/uapi/asm/ptrace.h 1970-01-01 01:00:00.000000000 +0100
  5131. +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/ptrace.h 2017-03-04 02:48:34.166888015 +0100
  5132. @@ -0,0 +1,55 @@
  5133. +#ifndef _UAPI_ASM_RISCV_PTRACE_H
  5134. +#define _UAPI_ASM_RISCV_PTRACE_H
  5135. +
  5136. +#ifndef __ASSEMBLY__
  5137. +
  5138. +#include <linux/types.h>
  5139. +
  5140. +/* User-mode register state for core dumps, ptrace, sigcontext
  5141. + *
  5142. + * This decouples struct pt_regs from the userspace ABI.
  5143. + * struct user_regs_struct must form a prefix of struct pt_regs.
  5144. + */
  5145. +struct user_regs_struct {
  5146. + unsigned long pc;
  5147. + unsigned long ra;
  5148. + unsigned long sp;
  5149. + unsigned long gp;
  5150. + unsigned long tp;
  5151. + unsigned long t0;
  5152. + unsigned long t1;
  5153. + unsigned long t2;
  5154. + unsigned long s0;
  5155. + unsigned long s1;
  5156. + unsigned long a0;
  5157. + unsigned long a1;
  5158. + unsigned long a2;
  5159. + unsigned long a3;
  5160. + unsigned long a4;
  5161. + unsigned long a5;
  5162. + unsigned long a6;
  5163. + unsigned long a7;
  5164. + unsigned long s2;
  5165. + unsigned long s3;
  5166. + unsigned long s4;
  5167. + unsigned long s5;
  5168. + unsigned long s6;
  5169. + unsigned long s7;
  5170. + unsigned long s8;
  5171. + unsigned long s9;
  5172. + unsigned long s10;
  5173. + unsigned long s11;
  5174. + unsigned long t3;
  5175. + unsigned long t4;
  5176. + unsigned long t5;
  5177. + unsigned long t6;
  5178. +};
  5179. +
  5180. +struct user_fpregs_struct {
  5181. + __u64 f[32];
  5182. + __u32 fcsr;
  5183. +};
  5184. +
  5185. +#endif /* __ASSEMBLY__ */
  5186. +
  5187. +#endif /* _UAPI_ASM_RISCV_PTRACE_H */
  5188. diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/sigcontext.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/sigcontext.h
  5189. --- linux-4.6.2/arch/riscv/include/uapi/asm/sigcontext.h 1970-01-01 01:00:00.000000000 +0100
  5190. +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/sigcontext.h 2017-03-04 02:48:34.166888015 +0100
  5191. @@ -0,0 +1,16 @@
  5192. +#ifndef _UAPI_ASM_RISCV_SIGCONTEXT_H
  5193. +#define _UAPI_ASM_RISCV_SIGCONTEXT_H
  5194. +
  5195. +#include <asm/ptrace.h>
  5196. +
  5197. +/* Signal context structure
  5198. + *
  5199. + * This contains the context saved before a signal handler is invoked;
  5200. + * it is restored by sys_sigreturn / sys_rt_sigreturn.
  5201. + */
  5202. +struct sigcontext {
  5203. + struct user_regs_struct sc_regs;
  5204. + struct user_fpregs_struct sc_fpregs;
  5205. +};
  5206. +
  5207. +#endif /* _UAPI_ASM_RISCV_SIGCONTEXT_H */
  5208. diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/siginfo.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/siginfo.h
  5209. --- linux-4.6.2/arch/riscv/include/uapi/asm/siginfo.h 1970-01-01 01:00:00.000000000 +0100
  5210. +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/siginfo.h 2017-03-04 02:48:34.166888015 +0100
  5211. @@ -0,0 +1,24 @@
  5212. +/*
  5213. + * Copyright (C) 2012 ARM Ltd.
  5214. + * Copyright (C) 2016 SiFive, Inc.
  5215. + *
  5216. + * This program is free software; you can redistribute it and/or modify
  5217. + * it under the terms of the GNU General Public License version 2 as
  5218. + * published by the Free Software Foundation.
  5219. + *
  5220. + * This program is distributed in the hope that it will be useful,
  5221. + * but WITHOUT ANY WARRANTY; without even the implied warranty of
  5222. + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  5223. + * GNU General Public License for more details.
  5224. + *
  5225. + * You should have received a copy of the GNU General Public License
  5226. + * along with this program. If not, see <http://www.gnu.org/licenses/>.
  5227. + */
  5228. +#ifndef __ASM_SIGINFO_H
  5229. +#define __ASM_SIGINFO_H
  5230. +
  5231. +#define __ARCH_SI_PREAMBLE_SIZE (4 * sizeof(int))
  5232. +
  5233. +#include <asm-generic/siginfo.h>
  5234. +
  5235. +#endif
  5236. diff -Nur linux-4.6.2/arch/riscv/include/uapi/asm/unistd.h linux-4.6.2.riscv/arch/riscv/include/uapi/asm/unistd.h
  5237. --- linux-4.6.2/arch/riscv/include/uapi/asm/unistd.h 1970-01-01 01:00:00.000000000 +0100
  5238. +++ linux-4.6.2.riscv/arch/riscv/include/uapi/asm/unistd.h 2017-03-04 02:48:34.166888015 +0100
  5239. @@ -0,0 +1,9 @@
  5240. +#include <asm-generic/unistd.h>
  5241. +
  5242. +#define __NR_sysriscv __NR_arch_specific_syscall
  5243. +#ifndef __riscv_atomic
  5244. +__SYSCALL(__NR_sysriscv, sys_sysriscv)
  5245. +#endif
  5246. +
  5247. +#define RISCV_ATOMIC_CMPXCHG 1
  5248. +#define RISCV_ATOMIC_CMPXCHG64 2
  5249. diff -Nur linux-4.6.2/arch/riscv/initramfs.txt linux-4.6.2.riscv/arch/riscv/initramfs.txt
  5250. --- linux-4.6.2/arch/riscv/initramfs.txt 1970-01-01 01:00:00.000000000 +0100
  5251. +++ linux-4.6.2.riscv/arch/riscv/initramfs.txt 2017-03-04 02:48:34.166888015 +0100
  5252. @@ -0,0 +1,9 @@
  5253. +dir /bin 755 0 0
  5254. +file /bin/busybox tmp/bin/busybox 755 0 0
  5255. +dir /etc 755 0 0
  5256. +file /etc/inittab tmp/etc/inittab 755 0 0
  5257. +
  5258. +dir /dev 755 0 0
  5259. +nod /dev/console 644 0 0 c 5 1
  5260. +nod /dev/null 644 0 0 c 1 3
  5261. +slink /init /bin/busybox 755 0 0
  5262. diff -Nur linux-4.6.2/arch/riscv/Kconfig linux-4.6.2.riscv/arch/riscv/Kconfig
  5263. --- linux-4.6.2/arch/riscv/Kconfig 1970-01-01 01:00:00.000000000 +0100
  5264. +++ linux-4.6.2.riscv/arch/riscv/Kconfig 2017-03-04 02:48:34.162887952 +0100
  5265. @@ -0,0 +1,284 @@
  5266. +#
  5267. +# For a description of the syntax of this configuration file,
  5268. +# see Documentation/kbuild/kconfig-language.txt.
  5269. +#
  5270. +
  5271. +config RISCV
  5272. + def_bool y
  5273. + select ARCH_HAS_ATOMIC64_DEC_IF_POSITIVE
  5274. + select ARCH_WANT_FRAME_POINTERS
  5275. + select CLONE_BACKWARDS
  5276. + select COMMON_CLK
  5277. + select GENERIC_CLOCKEVENTS
  5278. + select GENERIC_CPU_DEVICES
  5279. + select GENERIC_IRQ_SHOW
  5280. + select GENERIC_PCI_IOMAP
  5281. + select GENERIC_STRNCPY_FROM_USER
  5282. + select GENERIC_STRNLEN_USER
  5283. + select GENERIC_SMP_IDLE_THREAD
  5284. + select GENERIC_ATOMIC64 if !64BIT || !RV_ATOMIC
  5285. + select ARCH_WANT_OPTIONAL_GPIOLIB
  5286. + select HAVE_MEMBLOCK
  5287. + select HAVE_MEMBLOCK_NODE_MAP
  5288. + select HAVE_DMA_API_DEBUG
  5289. + select HAVE_DMA_CONTIGUOUS
  5290. + select HAVE_GENERIC_DMA_COHERENT
  5291. + select IRQ_DOMAIN
  5292. + select NO_BOOTMEM
  5293. + select RV_ATOMIC if SMP
  5294. + select RV_SYSRISCV_ATOMIC if !RV_ATOMIC
  5295. + select SPARSE_IRQ
  5296. + select SYSCTL_EXCEPTION_TRACE
  5297. + select HAVE_ARCH_TRACEHOOK
  5298. +
  5299. +config MMU
  5300. + def_bool y
  5301. +
  5302. +# even on 32-bit, physical (and DMA) addresses are > 32-bits
  5303. +config ARCH_PHYS_ADDR_T_64BIT
  5304. + def_bool y
  5305. +
  5306. +config ARCH_DMA_ADDR_T_64BIT
  5307. + def_bool y
  5308. +
  5309. +config STACKTRACE_SUPPORT
  5310. + def_bool y
  5311. +
  5312. +config RWSEM_GENERIC_SPINLOCK
  5313. + def_bool y
  5314. +
  5315. +config GENERIC_BUG
  5316. + def_bool y
  5317. + depends on BUG
  5318. + select GENERIC_BUG_RELATIVE_POINTERS if 64BIT
  5319. +
  5320. +config GENERIC_BUG_RELATIVE_POINTERS
  5321. + bool
  5322. +
  5323. +config GENERIC_CALIBRATE_DELAY
  5324. + def_bool y
  5325. +
  5326. +config GENERIC_CSUM
  5327. + def_bool y
  5328. +
  5329. +config GENERIC_HWEIGHT
  5330. + def_bool y
  5331. +
  5332. +config PGTABLE_LEVELS
  5333. + int
  5334. + default 3 if 64BIT
  5335. + default 2
  5336. +
  5337. +menu "Platform type"
  5338. +
  5339. +config SMP
  5340. + bool "Symmetric Multi-Processing"
  5341. + help
  5342. + This enables support for systems with more than one CPU. If
  5343. + you say N here, the kernel will run on single and
  5344. + multiprocessor machines, but will use only one CPU of a
  5345. + multiprocessor machine. If you say Y here, the kernel will run
  5346. + on many, but not all, single processor machines. On a single
  5347. + processor machine, the kernel will run faster if you say N
  5348. + here.
  5349. +
  5350. + If you don't know what to do here, say N.
  5351. +
  5352. +config NR_CPUS
  5353. + int "Maximum number of CPUs (2-32)"
  5354. + range 2 32
  5355. + depends on SMP
  5356. + default "8"
  5357. +
  5358. +choice
  5359. + prompt "CPU selection"
  5360. + default CPU_RV_ROCKET
  5361. +
  5362. +config CPU_RV_ROCKET
  5363. + bool "Rocket"
  5364. + select CPU_SUPPORTS_64BIT_KERNEL
  5365. +
  5366. +config CPU_RV_GENERIC
  5367. + bool "Generic RISC-V"
  5368. + select CPU_SUPPORTS_32BIT_KERNEL
  5369. + select CPU_SUPPORTS_64BIT_KERNEL
  5370. +
  5371. +endchoice
  5372. +
  5373. +config CPU_SUPPORTS_32BIT_KERNEL
  5374. + bool
  5375. +config CPU_SUPPORTS_64BIT_KERNEL
  5376. + bool
  5377. +
  5378. +config SBI_CONSOLE
  5379. + tristate "SBI console support"
  5380. + select TTY
  5381. + default y
  5382. +
  5383. +config RVC
  5384. + bool "Use compressed instructions (RV32C or RV64C)"
  5385. + default n
  5386. +
  5387. +config RV_ATOMIC
  5388. + bool "Use atomic memory instructions (RV32A or RV64A)"
  5389. + default y
  5390. +
  5391. +config RV_SYSRISCV_ATOMIC
  5392. + bool "Include support for atomic operation syscalls"
  5393. + default n
  5394. + help
  5395. + If atomic memory instructions are present, i.e.,
  5396. + CONFIG_RV_ATOMIC, this includes support for the syscall that
  5397. + provides atomic accesses. This is only useful to run
  5398. + binaries that require atomic access but were compiled with
  5399. + -mno-atomic.
  5400. +
  5401. + If CONFIG_RV_ATOMIC is unset, this option is mandatory.
  5402. +
  5403. +config RV_PUM
  5404. + def_bool y
  5405. + prompt "Protect User Memory" if EXPERT
  5406. + ---help---
  5407. + Protect User Memory (PUM) prevents the kernel from inadvertently
  5408. + accessing user-space memory. There is a small performance cost
  5409. + and kernel size increase if this is enabled.
  5410. +
  5411. + If unsure, say Y.
  5412. +
  5413. +endmenu
  5414. +
  5415. +menu "Kernel type"
  5416. +
  5417. +choice
  5418. + prompt "Kernel code model"
  5419. + default 64BIT
  5420. +
  5421. +config 32BIT
  5422. + bool "32-bit kernel"
  5423. + depends on CPU_SUPPORTS_32BIT_KERNEL
  5424. + help
  5425. + Select this option to build a 32-bit kernel.
  5426. +
  5427. +config 64BIT
  5428. + bool "64-bit kernel"
  5429. + depends on CPU_SUPPORTS_64BIT_KERNEL
  5430. + help
  5431. + Select this option to build a 64-bit kernel.
  5432. +
  5433. +endchoice
  5434. +
  5435. +source "mm/Kconfig"
  5436. +
  5437. +source "kernel/Kconfig.preempt"
  5438. +
  5439. +source "kernel/Kconfig.hz"
  5440. +
  5441. +endmenu
  5442. +
  5443. +menu "Bus support"
  5444. +
  5445. +config PCI
  5446. + bool "PCI support"
  5447. + select PCI_MSI
  5448. + help
  5449. + This feature enables support for PCI bus system. If you say Y
  5450. + here, the kernel will include drivers and infrastructure code
  5451. + to support PCI bus devices.
  5452. +
  5453. +config PCI_DOMAINS
  5454. + def_bool PCI
  5455. +
  5456. +config PCI_DOMAINS_GENERIC
  5457. + def_bool PCI
  5458. +
  5459. +config PCI_SYSCALL
  5460. + def_bool PCI
  5461. +
  5462. +source "drivers/pci/Kconfig"
  5463. +
  5464. +endmenu
  5465. +
  5466. +source "init/Kconfig"
  5467. +
  5468. +source "kernel/Kconfig.freezer"
  5469. +
  5470. +menu "Executable file formats"
  5471. +
  5472. +source "fs/Kconfig.binfmt"
  5473. +
  5474. +endmenu
  5475. +
  5476. +menu "Power management options"
  5477. +
  5478. +source kernel/power/Kconfig
  5479. +
  5480. +endmenu
  5481. +
  5482. +source "net/Kconfig"
  5483. +
  5484. +source "drivers/Kconfig"
  5485. +
  5486. +source "fs/Kconfig"
  5487. +
  5488. +menu "Kernel hacking"
  5489. +
  5490. +config CMDLINE_BOOL
  5491. + bool "Built-in kernel command line"
  5492. + default n
  5493. + help
  5494. + For most platforms, it is firmware or second stage bootloader
  5495. + that by default specifies the kernel command line options.
  5496. + However, it might be necessary or advantageous to either override
  5497. + the default kernel command line or add a few extra options to it.
  5498. + For such cases, this option allows hardcoding command line options
  5499. + directly into the kernel.
  5500. +
  5501. + For that, choose 'Y' here and fill in the extra boot parameters
  5502. + in CONFIG_CMDLINE.
  5503. +
  5504. + The built-in options will be concatenated to the default command
  5505. + line if CMDLINE_OVERRIDE is set to 'N'. Otherwise, the default
  5506. + command line will be ignored and replaced by the built-in string.
  5507. +
  5508. +config CMDLINE
  5509. + string "Built-in kernel command string"
  5510. + depends on CMDLINE_BOOL
  5511. + default ""
  5512. + help
  5513. + Supply command-line options at build time by entering them here.
  5514. +
  5515. +config CMDLINE_OVERRIDE
  5516. + bool "Built-in command line overrides bootloader arguments"
  5517. + default n
  5518. + depends on CMDLINE_BOOL
  5519. + help
  5520. + Set this option to 'Y' to have the kernel ignore the bootloader
  5521. + or firmware command line. Instead, the built-in command line
  5522. + will be used exclusively.
  5523. +
  5524. +config EARLY_PRINTK
  5525. + bool "Early printk"
  5526. + default n
  5527. + help
  5528. + This option enables special console drivers which allow the kernel
  5529. + to print messages very early in the bootup process.
  5530. +
  5531. + This is useful for kernel debugging when your machine crashes very
  5532. + early before the console code is initialized. For normal operation
  5533. + it is not recommended because it looks ugly and doesn't cooperate
  5534. + with klogd/syslogd or the X server. You should normally N here,
  5535. + unless you want to debug such a crash.
  5536. +
  5537. +
  5538. +source "lib/Kconfig.debug"
  5539. +
  5540. +config CMDLINE_BOOL
  5541. + bool
  5542. +endmenu
  5543. +
  5544. +source "security/Kconfig"
  5545. +
  5546. +source "crypto/Kconfig"
  5547. +
  5548. +source "lib/Kconfig"
  5549. +
  5550. diff -Nur linux-4.6.2/arch/riscv/kernel/asm-offsets.c linux-4.6.2.riscv/arch/riscv/kernel/asm-offsets.c
  5551. --- linux-4.6.2/arch/riscv/kernel/asm-offsets.c 1970-01-01 01:00:00.000000000 +0100
  5552. +++ linux-4.6.2.riscv/arch/riscv/kernel/asm-offsets.c 2017-03-04 02:48:34.166888015 +0100
  5553. @@ -0,0 +1,99 @@
  5554. +#include <linux/kbuild.h>
  5555. +#include <linux/sched.h>
  5556. +#include <asm/thread_info.h>
  5557. +#include <asm/ptrace.h>
  5558. +
  5559. +void asm_offsets(void)
  5560. +{
  5561. + OFFSET(TASK_THREAD_INFO, task_struct, stack);
  5562. + OFFSET(THREAD_RA, task_struct, thread.ra);
  5563. + OFFSET(THREAD_SP, task_struct, thread.sp);
  5564. + OFFSET(THREAD_S0, task_struct, thread.s[0]);
  5565. + OFFSET(THREAD_S1, task_struct, thread.s[1]);
  5566. + OFFSET(THREAD_S2, task_struct, thread.s[2]);
  5567. + OFFSET(THREAD_S3, task_struct, thread.s[3]);
  5568. + OFFSET(THREAD_S4, task_struct, thread.s[4]);
  5569. + OFFSET(THREAD_S5, task_struct, thread.s[5]);
  5570. + OFFSET(THREAD_S6, task_struct, thread.s[6]);
  5571. + OFFSET(THREAD_S7, task_struct, thread.s[7]);
  5572. + OFFSET(THREAD_S8, task_struct, thread.s[8]);
  5573. + OFFSET(THREAD_S9, task_struct, thread.s[9]);
  5574. + OFFSET(THREAD_S10, task_struct, thread.s[10]);
  5575. + OFFSET(THREAD_S11, task_struct, thread.s[11]);
  5576. + OFFSET(THREAD_SP, task_struct, thread.sp);
  5577. + OFFSET(TI_TASK, thread_info, task);
  5578. + OFFSET(TI_FLAGS, thread_info, flags);
  5579. + OFFSET(TI_CPU, thread_info, cpu);
  5580. +
  5581. + OFFSET(THREAD_F0, task_struct, thread.fstate.f[0]);
  5582. + OFFSET(THREAD_F1, task_struct, thread.fstate.f[1]);
  5583. + OFFSET(THREAD_F2, task_struct, thread.fstate.f[2]);
  5584. + OFFSET(THREAD_F3, task_struct, thread.fstate.f[3]);
  5585. + OFFSET(THREAD_F4, task_struct, thread.fstate.f[4]);
  5586. + OFFSET(THREAD_F5, task_struct, thread.fstate.f[5]);
  5587. + OFFSET(THREAD_F6, task_struct, thread.fstate.f[6]);
  5588. + OFFSET(THREAD_F7, task_struct, thread.fstate.f[7]);
  5589. + OFFSET(THREAD_F8, task_struct, thread.fstate.f[8]);
  5590. + OFFSET(THREAD_F9, task_struct, thread.fstate.f[9]);
  5591. + OFFSET(THREAD_F10, task_struct, thread.fstate.f[10]);
  5592. + OFFSET(THREAD_F11, task_struct, thread.fstate.f[11]);
  5593. + OFFSET(THREAD_F12, task_struct, thread.fstate.f[12]);
  5594. + OFFSET(THREAD_F13, task_struct, thread.fstate.f[13]);
  5595. + OFFSET(THREAD_F14, task_struct, thread.fstate.f[14]);
  5596. + OFFSET(THREAD_F15, task_struct, thread.fstate.f[15]);
  5597. + OFFSET(THREAD_F16, task_struct, thread.fstate.f[16]);
  5598. + OFFSET(THREAD_F17, task_struct, thread.fstate.f[17]);
  5599. + OFFSET(THREAD_F18, task_struct, thread.fstate.f[18]);
  5600. + OFFSET(THREAD_F19, task_struct, thread.fstate.f[19]);
  5601. + OFFSET(THREAD_F20, task_struct, thread.fstate.f[20]);
  5602. + OFFSET(THREAD_F21, task_struct, thread.fstate.f[21]);
  5603. + OFFSET(THREAD_F22, task_struct, thread.fstate.f[22]);
  5604. + OFFSET(THREAD_F23, task_struct, thread.fstate.f[23]);
  5605. + OFFSET(THREAD_F24, task_struct, thread.fstate.f[24]);
  5606. + OFFSET(THREAD_F25, task_struct, thread.fstate.f[25]);
  5607. + OFFSET(THREAD_F26, task_struct, thread.fstate.f[26]);
  5608. + OFFSET(THREAD_F27, task_struct, thread.fstate.f[27]);
  5609. + OFFSET(THREAD_F28, task_struct, thread.fstate.f[28]);
  5610. + OFFSET(THREAD_F29, task_struct, thread.fstate.f[29]);
  5611. + OFFSET(THREAD_F30, task_struct, thread.fstate.f[30]);
  5612. + OFFSET(THREAD_F31, task_struct, thread.fstate.f[31]);
  5613. + OFFSET(THREAD_FCSR, task_struct, thread.fstate.fcsr);
  5614. +
  5615. + DEFINE(PT_SIZE, sizeof(struct pt_regs));
  5616. + OFFSET(PT_SEPC, pt_regs, sepc);
  5617. + OFFSET(PT_RA, pt_regs, ra);
  5618. + OFFSET(PT_FP, pt_regs, s0);
  5619. + OFFSET(PT_S0, pt_regs, s0);
  5620. + OFFSET(PT_S1, pt_regs, s1);
  5621. + OFFSET(PT_S2, pt_regs, s2);
  5622. + OFFSET(PT_S3, pt_regs, s3);
  5623. + OFFSET(PT_S4, pt_regs, s4);
  5624. + OFFSET(PT_S5, pt_regs, s5);
  5625. + OFFSET(PT_S6, pt_regs, s6);
  5626. + OFFSET(PT_S7, pt_regs, s7);
  5627. + OFFSET(PT_S8, pt_regs, s8);
  5628. + OFFSET(PT_S9, pt_regs, s9);
  5629. + OFFSET(PT_S10, pt_regs, s10);
  5630. + OFFSET(PT_S11, pt_regs, s11);
  5631. + OFFSET(PT_SP, pt_regs, sp);
  5632. + OFFSET(PT_TP, pt_regs, tp);
  5633. + OFFSET(PT_A0, pt_regs, a0);
  5634. + OFFSET(PT_A1, pt_regs, a1);
  5635. + OFFSET(PT_A2, pt_regs, a2);
  5636. + OFFSET(PT_A3, pt_regs, a3);
  5637. + OFFSET(PT_A4, pt_regs, a4);
  5638. + OFFSET(PT_A5, pt_regs, a5);
  5639. + OFFSET(PT_A6, pt_regs, a6);
  5640. + OFFSET(PT_A7, pt_regs, a7);
  5641. + OFFSET(PT_T0, pt_regs, t0);
  5642. + OFFSET(PT_T1, pt_regs, t1);
  5643. + OFFSET(PT_T2, pt_regs, t2);
  5644. + OFFSET(PT_T3, pt_regs, t3);
  5645. + OFFSET(PT_T4, pt_regs, t4);
  5646. + OFFSET(PT_T5, pt_regs, t5);
  5647. + OFFSET(PT_T6, pt_regs, t6);
  5648. + OFFSET(PT_GP, pt_regs, gp);
  5649. + OFFSET(PT_SSTATUS, pt_regs, sstatus);
  5650. + OFFSET(PT_SBADADDR, pt_regs, sbadaddr);
  5651. + OFFSET(PT_SCAUSE, pt_regs, scause);
  5652. +}
  5653. diff -Nur linux-4.6.2/arch/riscv/kernel/cpu.c linux-4.6.2.riscv/arch/riscv/kernel/cpu.c
  5654. --- linux-4.6.2/arch/riscv/kernel/cpu.c 1970-01-01 01:00:00.000000000 +0100
  5655. +++ linux-4.6.2.riscv/arch/riscv/kernel/cpu.c 2017-03-04 02:48:34.166888015 +0100
  5656. @@ -0,0 +1,41 @@
  5657. +#include <linux/init.h>
  5658. +#include <linux/seq_file.h>
  5659. +
  5660. +#ifdef CONFIG_PROC_FS
  5661. +
  5662. +static void *c_start(struct seq_file *m, loff_t *pos)
  5663. +{
  5664. + *pos = cpumask_next(*pos - 1, cpu_online_mask);
  5665. + if ((*pos) < nr_cpu_ids)
  5666. + return (void *)(uintptr_t)(1 + *pos);
  5667. + return NULL;
  5668. +}
  5669. +
  5670. +static void *c_next(struct seq_file *m, void *v, loff_t *pos)
  5671. +{
  5672. + (*pos)++;
  5673. + return c_start(m, pos);
  5674. +}
  5675. +
  5676. +static void c_stop(struct seq_file *m, void *v)
  5677. +{
  5678. +}
  5679. +
  5680. +static int c_show(struct seq_file *m, void *v)
  5681. +{
  5682. + unsigned long hart_id = (unsigned long)v - 1;
  5683. +
  5684. + seq_printf(m, "hart\t: %lu\n", hart_id);
  5685. + seq_printf(m, "isa\t: RV%zuG\n", sizeof(void *) * 8);
  5686. + seq_printf(m, "\n");
  5687. + return 0;
  5688. +}
  5689. +
  5690. +const struct seq_operations cpuinfo_op = {
  5691. + .start = c_start,
  5692. + .next = c_next,
  5693. + .stop = c_stop,
  5694. + .show = c_show
  5695. +};
  5696. +
  5697. +#endif /* CONFIG_PROC_FS */
  5698. diff -Nur linux-4.6.2/arch/riscv/kernel/entry.S linux-4.6.2.riscv/arch/riscv/kernel/entry.S
  5699. --- linux-4.6.2/arch/riscv/kernel/entry.S 1970-01-01 01:00:00.000000000 +0100
  5700. +++ linux-4.6.2.riscv/arch/riscv/kernel/entry.S 2017-03-04 02:48:34.166888015 +0100
  5701. @@ -0,0 +1,399 @@
  5702. +#include <linux/init.h>
  5703. +#include <linux/linkage.h>
  5704. +
  5705. +#include <asm/asm.h>
  5706. +#include <asm/csr.h>
  5707. +#include <asm/unistd.h>
  5708. +#include <asm/thread_info.h>
  5709. +#include <asm/asm-offsets.h>
  5710. +
  5711. + .text
  5712. + .altmacro
  5713. + .macro SAVE_ALL
  5714. + LOCAL _restore_kernel_sp
  5715. + LOCAL _save_context
  5716. +
  5717. + /* If coming from userspace, preserve the user stack pointer and load
  5718. + the kernel stack pointer. If we came from the kernel, sscratch
  5719. + will contain 0, and we should continue on the current stack. */
  5720. + csrrw sp, sscratch, sp
  5721. + bnez sp, _save_context
  5722. +
  5723. +_restore_kernel_sp:
  5724. + csrr sp, sscratch
  5725. +_save_context:
  5726. + addi sp, sp, -(PT_SIZE)
  5727. + REG_S x1, PT_RA(sp)
  5728. + REG_S x3, PT_GP(sp)
  5729. + REG_S x4, PT_TP(sp)
  5730. + REG_S x5, PT_T0(sp)
  5731. + REG_S x6, PT_T1(sp)
  5732. + REG_S x7, PT_T2(sp)
  5733. + REG_S x8, PT_S0(sp)
  5734. + REG_S x9, PT_S1(sp)
  5735. + REG_S x10, PT_A0(sp)
  5736. + REG_S x11, PT_A1(sp)
  5737. + REG_S x12, PT_A2(sp)
  5738. + REG_S x13, PT_A3(sp)
  5739. + REG_S x14, PT_A4(sp)
  5740. + REG_S x15, PT_A5(sp)
  5741. + REG_S x16, PT_A6(sp)
  5742. + REG_S x17, PT_A7(sp)
  5743. + REG_S x18, PT_S2(sp)
  5744. + REG_S x19, PT_S3(sp)
  5745. + REG_S x20, PT_S4(sp)
  5746. + REG_S x21, PT_S5(sp)
  5747. + REG_S x22, PT_S6(sp)
  5748. + REG_S x23, PT_S7(sp)
  5749. + REG_S x24, PT_S8(sp)
  5750. + REG_S x25, PT_S9(sp)
  5751. + REG_S x26, PT_S10(sp)
  5752. + REG_S x27, PT_S11(sp)
  5753. + REG_S x28, PT_T3(sp)
  5754. + REG_S x29, PT_T4(sp)
  5755. + REG_S x30, PT_T5(sp)
  5756. + REG_S x31, PT_T6(sp)
  5757. +
  5758. + /* Disable FPU to detect illegal usage of
  5759. + floating point in kernel space */
  5760. + li t0, SR_FS
  5761. +
  5762. + csrr s0, sscratch
  5763. + csrrc s1, sstatus, t0
  5764. + csrr s2, sepc
  5765. + csrr s3, sbadaddr
  5766. + csrr s4, scause
  5767. + REG_S s0, PT_SP(sp)
  5768. + REG_S s1, PT_SSTATUS(sp)
  5769. + REG_S s2, PT_SEPC(sp)
  5770. + REG_S s3, PT_SBADADDR(sp)
  5771. + REG_S s4, PT_SCAUSE(sp)
  5772. + .endm
  5773. +
  5774. + .macro RESTORE_ALL
  5775. + REG_L a0, PT_SSTATUS(sp)
  5776. + REG_L a2, PT_SEPC(sp)
  5777. + csrw sstatus, a0
  5778. + csrw sepc, a2
  5779. +
  5780. + REG_L x1, PT_RA(sp)
  5781. + REG_L x3, PT_GP(sp)
  5782. + REG_L x4, PT_TP(sp)
  5783. + REG_L x5, PT_T0(sp)
  5784. + REG_L x6, PT_T1(sp)
  5785. + REG_L x7, PT_T2(sp)
  5786. + REG_L x8, PT_S0(sp)
  5787. + REG_L x9, PT_S1(sp)
  5788. + REG_L x10, PT_A0(sp)
  5789. + REG_L x11, PT_A1(sp)
  5790. + REG_L x12, PT_A2(sp)
  5791. + REG_L x13, PT_A3(sp)
  5792. + REG_L x14, PT_A4(sp)
  5793. + REG_L x15, PT_A5(sp)
  5794. + REG_L x16, PT_A6(sp)
  5795. + REG_L x17, PT_A7(sp)
  5796. + REG_L x18, PT_S2(sp)
  5797. + REG_L x19, PT_S3(sp)
  5798. + REG_L x20, PT_S4(sp)
  5799. + REG_L x21, PT_S5(sp)
  5800. + REG_L x22, PT_S6(sp)
  5801. + REG_L x23, PT_S7(sp)
  5802. + REG_L x24, PT_S8(sp)
  5803. + REG_L x25, PT_S9(sp)
  5804. + REG_L x26, PT_S10(sp)
  5805. + REG_L x27, PT_S11(sp)
  5806. + REG_L x28, PT_T3(sp)
  5807. + REG_L x29, PT_T4(sp)
  5808. + REG_L x30, PT_T5(sp)
  5809. + REG_L x31, PT_T6(sp)
  5810. +
  5811. + REG_L x2, PT_SP(sp)
  5812. + .endm
  5813. +
  5814. +ENTRY(handle_exception)
  5815. + SAVE_ALL
  5816. +
  5817. + /* Set sscratch register to 0, so that if a recursive exception
  5818. + occurs, the exception vector knows it came from the kernel */
  5819. + csrw sscratch, x0
  5820. +
  5821. + /* Compute address of current thread_info */
  5822. + li tp, ~(THREAD_SIZE-1)
  5823. + and tp, tp, sp
  5824. + /* Set current pointer */
  5825. + REG_L tp, TI_TASK(tp)
  5826. +
  5827. +1: auipc gp, %pcrel_hi(_gp)
  5828. + addi gp, gp, %pcrel_lo(1b)
  5829. +
  5830. + la ra, ret_from_exception
  5831. + /* MSB of cause differentiates between
  5832. + interrupts and exceptions */
  5833. + bge s4, zero, 1f
  5834. +
  5835. + /* Handle interrupts */
  5836. + slli a0, s4, 1
  5837. + srli a0, a0, 1
  5838. + move a1, sp /* pt_regs */
  5839. + tail do_IRQ
  5840. +1:
  5841. + /* Handle syscalls */
  5842. + li t0, EXC_SYSCALL
  5843. + beq s4, t0, handle_syscall
  5844. +
  5845. + /* Handle other exceptions */
  5846. + slli t0, s4, LGPTR
  5847. + la t1, excp_vect_table
  5848. + la t2, excp_vect_table_end
  5849. + move a0, sp /* pt_regs */
  5850. + add t0, t1, t0
  5851. + /* Check if exception code lies within bounds */
  5852. + bgeu t0, t2, 1f
  5853. + REG_L t0, 0(t0)
  5854. + jr t0
  5855. +1:
  5856. + tail do_trap_unknown
  5857. +
  5858. +handle_syscall:
  5859. + /* Advance SEPC to avoid executing the original
  5860. + scall instruction on sret */
  5861. + addi s2, s2, 0x4
  5862. + REG_S s2, PT_SEPC(sp)
  5863. + /* System calls run with interrupts enabled */
  5864. + csrs sstatus, SR_IE
  5865. + /* Trace syscalls, but only if requested by the user. */
  5866. + REG_L t0, TASK_THREAD_INFO(tp)
  5867. + REG_L t0, TI_FLAGS(t0)
  5868. + andi t0, t0, _TIF_SYSCALL_TRACE
  5869. + bnez t0, handle_syscall_trace_enter
  5870. +check_syscall_nr:
  5871. + /* Check to make sure we don't jump to a bogus syscall number. */
  5872. + li t0, __NR_syscalls
  5873. + la s0, sys_ni_syscall
  5874. + /* Syscall number held in a7 */
  5875. + bgeu a7, t0, 1f
  5876. + la s0, sys_call_table
  5877. + slli t0, a7, LGPTR
  5878. + add s0, s0, t0
  5879. + REG_L s0, 0(s0)
  5880. +1:
  5881. + jalr s0
  5882. +
  5883. +ret_from_syscall:
  5884. + /* Set user a0 to kernel a0 */
  5885. + REG_S a0, PT_A0(sp)
  5886. + /* Trace syscalls, but only if requested by the user. */
  5887. + REG_L t0, TASK_THREAD_INFO(tp)
  5888. + REG_L t0, TI_FLAGS(t0)
  5889. + andi t0, t0, _TIF_SYSCALL_TRACE
  5890. + bnez t0, handle_syscall_trace_exit
  5891. +
  5892. +ret_from_exception:
  5893. + REG_L s0, PT_SSTATUS(sp)
  5894. + csrc sstatus, SR_IE
  5895. + andi s0, s0, SR_PS
  5896. + bnez s0, restore_all
  5897. +
  5898. +resume_userspace:
  5899. + /* Interrupts must be disabled here so flags are checked atomically */
  5900. + REG_L s0, TASK_THREAD_INFO(tp)
  5901. + REG_L s0, TI_FLAGS(s0) /* current_thread_info->flags */
  5902. + andi s1, s0, _TIF_WORK_MASK
  5903. + bnez s1, work_pending
  5904. +
  5905. + /* Save unwound kernel stack pointer in sscratch */
  5906. + addi s0, sp, PT_SIZE
  5907. + csrw sscratch, s0
  5908. +restore_all:
  5909. + RESTORE_ALL
  5910. + sret
  5911. +
  5912. +work_pending:
  5913. + /* Enter slow path for supplementary processing */
  5914. + la ra, ret_from_exception
  5915. + andi s1, s0, _TIF_NEED_RESCHED
  5916. + bnez s1, work_resched
  5917. +work_notifysig:
  5918. + /* Handle pending signals and notify-resume requests */
  5919. + csrs sstatus, SR_IE /* Enable interrupts for do_notify_resume() */
  5920. + move a0, sp /* pt_regs */
  5921. + move a1, s0 /* current_thread_info->flags */
  5922. + tail do_notify_resume
  5923. +work_resched:
  5924. + tail schedule
  5925. +
  5926. +/* Slow paths for ptrace. */
  5927. +handle_syscall_trace_enter:
  5928. + move a0, sp
  5929. + call do_syscall_trace_enter
  5930. + REG_L a0, PT_A0(sp)
  5931. + REG_L a1, PT_A1(sp)
  5932. + REG_L a2, PT_A2(sp)
  5933. + REG_L a3, PT_A3(sp)
  5934. + REG_L a4, PT_A4(sp)
  5935. + REG_L a5, PT_A5(sp)
  5936. + REG_L a6, PT_A6(sp)
  5937. + REG_L a7, PT_A7(sp)
  5938. + j check_syscall_nr
  5939. +handle_syscall_trace_exit:
  5940. + move a0, sp
  5941. + call do_syscall_trace_exit
  5942. + j ret_from_exception
  5943. +
  5944. +END(handle_exception)
  5945. +
  5946. +ENTRY(ret_from_fork)
  5947. + la ra, ret_from_exception
  5948. + tail schedule_tail
  5949. +ENDPROC(ret_from_fork)
  5950. +
  5951. +ENTRY(ret_from_kernel_thread)
  5952. + call schedule_tail
  5953. + /* Call fn(arg) */
  5954. + la ra, ret_from_exception
  5955. + move a0, s1
  5956. + jr s0
  5957. +ENDPROC(ret_from_kernel_thread)
  5958. +
  5959. +
  5960. +/*
  5961. + * Integer register context switch
  5962. + * The callee-saved registers must be saved and restored.
  5963. + *
  5964. + * a0: previous task_struct (must be preserved across the switch)
  5965. + * a1: next task_struct
  5966. + */
  5967. +ENTRY(__switch_to)
  5968. + /* Save context into prev->thread */
  5969. + REG_S ra, THREAD_RA(a0)
  5970. + REG_S sp, THREAD_SP(a0)
  5971. + REG_S s0, THREAD_S0(a0)
  5972. + REG_S s1, THREAD_S1(a0)
  5973. + REG_S s2, THREAD_S2(a0)
  5974. + REG_S s3, THREAD_S3(a0)
  5975. + REG_S s4, THREAD_S4(a0)
  5976. + REG_S s5, THREAD_S5(a0)
  5977. + REG_S s6, THREAD_S6(a0)
  5978. + REG_S s7, THREAD_S7(a0)
  5979. + REG_S s8, THREAD_S8(a0)
  5980. + REG_S s9, THREAD_S9(a0)
  5981. + REG_S s10, THREAD_S10(a0)
  5982. + REG_S s11, THREAD_S11(a0)
  5983. + /* Restore context from next->thread */
  5984. + REG_L ra, THREAD_RA(a1)
  5985. + REG_L sp, THREAD_SP(a1)
  5986. + REG_L s0, THREAD_S0(a1)
  5987. + REG_L s1, THREAD_S1(a1)
  5988. + REG_L s2, THREAD_S2(a1)
  5989. + REG_L s3, THREAD_S3(a1)
  5990. + REG_L s4, THREAD_S4(a1)
  5991. + REG_L s5, THREAD_S5(a1)
  5992. + REG_L s6, THREAD_S6(a1)
  5993. + REG_L s7, THREAD_S7(a1)
  5994. + REG_L s8, THREAD_S8(a1)
  5995. + REG_L s9, THREAD_S9(a1)
  5996. + REG_L s10, THREAD_S10(a1)
  5997. + REG_L s11, THREAD_S11(a1)
  5998. + mv tp, a1 /* Next current pointer */
  5999. + ret
  6000. +ENDPROC(__switch_to)
  6001. +
  6002. +ENTRY(__fstate_save)
  6003. + li t1, SR_FS
  6004. + csrs sstatus, t1
  6005. + frcsr t0
  6006. + fsd f0, THREAD_F0(a0)
  6007. + fsd f1, THREAD_F1(a0)
  6008. + fsd f2, THREAD_F2(a0)
  6009. + fsd f3, THREAD_F3(a0)
  6010. + fsd f4, THREAD_F4(a0)
  6011. + fsd f5, THREAD_F5(a0)
  6012. + fsd f6, THREAD_F6(a0)
  6013. + fsd f7, THREAD_F7(a0)
  6014. + fsd f8, THREAD_F8(a0)
  6015. + fsd f9, THREAD_F9(a0)
  6016. + fsd f10, THREAD_F10(a0)
  6017. + fsd f11, THREAD_F11(a0)
  6018. + fsd f12, THREAD_F12(a0)
  6019. + fsd f13, THREAD_F13(a0)
  6020. + fsd f14, THREAD_F14(a0)
  6021. + fsd f15, THREAD_F15(a0)
  6022. + fsd f16, THREAD_F16(a0)
  6023. + fsd f17, THREAD_F17(a0)
  6024. + fsd f18, THREAD_F18(a0)
  6025. + fsd f19, THREAD_F19(a0)
  6026. + fsd f20, THREAD_F20(a0)
  6027. + fsd f21, THREAD_F21(a0)
  6028. + fsd f22, THREAD_F22(a0)
  6029. + fsd f23, THREAD_F23(a0)
  6030. + fsd f24, THREAD_F24(a0)
  6031. + fsd f25, THREAD_F25(a0)
  6032. + fsd f26, THREAD_F26(a0)
  6033. + fsd f27, THREAD_F27(a0)
  6034. + fsd f28, THREAD_F28(a0)
  6035. + fsd f29, THREAD_F29(a0)
  6036. + fsd f30, THREAD_F30(a0)
  6037. + fsd f31, THREAD_F31(a0)
  6038. + sw t0, THREAD_FCSR(a0)
  6039. + csrc sstatus, t1
  6040. + ret
  6041. +ENDPROC(__fstate_save)
  6042. +
  6043. +ENTRY(__fstate_restore)
  6044. + li t1, SR_FS
  6045. + lw t0, THREAD_FCSR(a0)
  6046. + csrs sstatus, t1
  6047. + fld f0, THREAD_F0(a0)
  6048. + fld f1, THREAD_F1(a0)
  6049. + fld f2, THREAD_F2(a0)
  6050. + fld f3, THREAD_F3(a0)
  6051. + fld f4, THREAD_F4(a0)
  6052. + fld f5, THREAD_F5(a0)
  6053. + fld f6, THREAD_F6(a0)
  6054. + fld f7, THREAD_F7(a0)
  6055. + fld f8, THREAD_F8(a0)
  6056. + fld f9, THREAD_F9(a0)
  6057. + fld f10, THREAD_F10(a0)
  6058. + fld f11, THREAD_F11(a0)
  6059. + fld f12, THREAD_F12(a0)
  6060. + fld f13, THREAD_F13(a0)
  6061. + fld f14, THREAD_F14(a0)
  6062. + fld f15, THREAD_F15(a0)
  6063. + fld f16, THREAD_F16(a0)
  6064. + fld f17, THREAD_F17(a0)
  6065. + fld f18, THREAD_F18(a0)
  6066. + fld f19, THREAD_F19(a0)
  6067. + fld f20, THREAD_F20(a0)
  6068. + fld f21, THREAD_F21(a0)
  6069. + fld f22, THREAD_F22(a0)
  6070. + fld f23, THREAD_F23(a0)
  6071. + fld f24, THREAD_F24(a0)
  6072. + fld f25, THREAD_F25(a0)
  6073. + fld f26, THREAD_F26(a0)
  6074. + fld f27, THREAD_F27(a0)
  6075. + fld f28, THREAD_F28(a0)
  6076. + fld f29, THREAD_F29(a0)
  6077. + fld f30, THREAD_F30(a0)
  6078. + fld f31, THREAD_F31(a0)
  6079. + fscsr t0
  6080. + csrc sstatus, t1
  6081. + ret
  6082. +ENDPROC(__fstate_restore)
  6083. +
  6084. +
  6085. + .section ".rodata"
  6086. + /* Exception vector table */
  6087. +ENTRY(excp_vect_table)
  6088. + PTR do_trap_insn_misaligned
  6089. + PTR do_page_fault
  6090. + PTR do_trap_insn_illegal
  6091. + PTR do_trap_unknown
  6092. + PTR do_trap_unknown
  6093. + PTR do_page_fault
  6094. + PTR do_trap_amo_misaligned
  6095. + PTR do_page_fault
  6096. + PTR 0 /* handle_syscall */
  6097. + PTR do_trap_break
  6098. +excp_vect_table_end:
  6099. +END(excp_vect_table)
  6100. +
  6101. diff -Nur linux-4.6.2/arch/riscv/kernel/head.S linux-4.6.2.riscv/arch/riscv/kernel/head.S
  6102. --- linux-4.6.2/arch/riscv/kernel/head.S 1970-01-01 01:00:00.000000000 +0100
  6103. +++ linux-4.6.2.riscv/arch/riscv/kernel/head.S 2017-03-04 02:48:34.166888015 +0100
  6104. @@ -0,0 +1,77 @@
  6105. +#include <asm/thread_info.h>
  6106. +#include <asm/asm-offsets.h>
  6107. +#include <asm/asm.h>
  6108. +#include <linux/init.h>
  6109. +#include <linux/linkage.h>
  6110. +#include <asm/thread_info.h>
  6111. +#include <asm/page.h>
  6112. +#include <asm/csr.h>
  6113. +
  6114. +__INIT
  6115. +ENTRY(_start)
  6116. + /* Load the global pointer (before any use of la) */
  6117. +1: auipc gp, %pcrel_hi(_gp)
  6118. + addi gp, gp, %pcrel_lo(1b)
  6119. +
  6120. + /* Disable FPU to detect illegal usage of
  6121. + floating point in kernel space */
  6122. + li t0, SR_FS
  6123. + csrc sstatus, t0
  6124. +
  6125. +#ifdef CONFIG_RV_PUM
  6126. + /* Prevent inadvertent access to user memory */
  6127. + li t0, SR_PUM
  6128. + csrs sstatus, t0
  6129. +#endif
  6130. +
  6131. + /* See if we're the main hart */
  6132. + call sbi_hart_id
  6133. + bnez a0, .Lsecondary_start
  6134. +
  6135. + /* Clear the .bss segment */
  6136. + la a0, __bss_start
  6137. + li a1, 0
  6138. + la a2, __bss_stop
  6139. + sub a2, a2, a0
  6140. + call memset
  6141. +
  6142. + /* Initialize stack pointer */
  6143. + la sp, init_thread_union + THREAD_SIZE
  6144. + /* Initialize current task_struct pointer */
  6145. + la tp, init_task
  6146. +
  6147. + tail start_kernel
  6148. +
  6149. +.Lsecondary_start:
  6150. +#ifdef CONFIG_SMP
  6151. + li a1, CONFIG_NR_CPUS
  6152. + bgeu a0, a1, .Lsecondary_park
  6153. +
  6154. + la a1, __cpu_up_stack_pointer
  6155. + slli a0, a0, LGREG
  6156. + add a0, a0, a1
  6157. +
  6158. +.Lwait_for_cpu_up:
  6159. + REG_L sp, (a0)
  6160. + beqz sp, .Lwait_for_cpu_up
  6161. +
  6162. + /* Initialize task_struct pointer */
  6163. + li tp, -THREAD_SIZE
  6164. + add tp, tp, sp
  6165. + REG_L tp, (tp)
  6166. +
  6167. + tail smp_callin
  6168. +#endif
  6169. +
  6170. +.Lsecondary_park:
  6171. + /* We lack SMP support or have too many harts, so park this hart */
  6172. + wfi
  6173. + j .Lsecondary_park
  6174. +END(_start)
  6175. +
  6176. +__PAGE_ALIGNED_BSS
  6177. + /* Empty zero page */
  6178. + .balign PAGE_SIZE
  6179. +ENTRY(empty_zero_page)
  6180. + .fill (empty_zero_page + PAGE_SIZE) - ., 1, 0x00
  6181. +END(empty_zero_page)
  6182. diff -Nur linux-4.6.2/arch/riscv/kernel/irq.c linux-4.6.2.riscv/arch/riscv/kernel/irq.c
  6183. --- linux-4.6.2/arch/riscv/kernel/irq.c 1970-01-01 01:00:00.000000000 +0100
  6184. +++ linux-4.6.2.riscv/arch/riscv/kernel/irq.c 2017-03-04 02:48:34.166888015 +0100
  6185. @@ -0,0 +1,102 @@
  6186. +#include <linux/interrupt.h>
  6187. +#include <linux/ftrace.h>
  6188. +#include <linux/seq_file.h>
  6189. +
  6190. +#include <asm/ptrace.h>
  6191. +#include <asm/sbi.h>
  6192. +#include <asm/sbi-con.h>
  6193. +#include <asm/smp.h>
  6194. +
  6195. +struct plic_context {
  6196. + volatile int priority_threshold;
  6197. + volatile int claim;
  6198. +};
  6199. +
  6200. +static DEFINE_PER_CPU(struct plic_context *, plic_context);
  6201. +static DEFINE_PER_CPU(unsigned int, irq_in_progress);
  6202. +
  6203. +static void riscv_software_interrupt(void)
  6204. +{
  6205. + irqreturn_t ret;
  6206. +
  6207. +#ifdef CONFIG_SMP
  6208. + ret = handle_ipi();
  6209. + if (ret != IRQ_NONE)
  6210. + return;
  6211. +#endif
  6212. +
  6213. + ret = sbi_console_isr();
  6214. + if (ret != IRQ_NONE)
  6215. + return;
  6216. +
  6217. + BUG();
  6218. +}
  6219. +
  6220. +static void plic_interrupt(void)
  6221. +{
  6222. + unsigned int cpu = smp_processor_id();
  6223. + unsigned int irq = per_cpu(plic_context, cpu)->claim;
  6224. +
  6225. + BUG_ON(per_cpu(irq_in_progress, cpu) != 0);
  6226. +
  6227. + if (irq) {
  6228. + per_cpu(irq_in_progress, cpu) = irq;
  6229. + generic_handle_irq(irq);
  6230. + }
  6231. +}
  6232. +
  6233. +asmlinkage void __irq_entry do_IRQ(unsigned int cause, struct pt_regs *regs)
  6234. +{
  6235. + struct pt_regs *old_regs = set_irq_regs(regs);
  6236. + irq_enter();
  6237. +
  6238. + /* There are three classes of interrupt: timer, software, and
  6239. + external devices. We dispatch between them here. External
  6240. + device interrupts use the generic IRQ mechanisms. */
  6241. + switch (cause) {
  6242. + case INTERRUPT_CAUSE_TIMER:
  6243. + riscv_timer_interrupt();
  6244. + break;
  6245. + case INTERRUPT_CAUSE_SOFTWARE:
  6246. + riscv_software_interrupt();
  6247. + break;
  6248. + case INTERRUPT_CAUSE_EXTERNAL:
  6249. + plic_interrupt();
  6250. + break;
  6251. + default:
  6252. + BUG();
  6253. + }
  6254. +
  6255. + irq_exit();
  6256. + set_irq_regs(old_regs);
  6257. +}
  6258. +
  6259. +static void plic_irq_mask(struct irq_data *d)
  6260. +{
  6261. + unsigned int cpu = smp_processor_id();
  6262. +
  6263. + BUG_ON(d->irq != per_cpu(irq_in_progress, cpu));
  6264. +}
  6265. +
  6266. +static void plic_irq_unmask(struct irq_data *d)
  6267. +{
  6268. + unsigned int cpu = smp_processor_id();
  6269. +
  6270. + BUG_ON(d->irq != per_cpu(irq_in_progress, cpu));
  6271. +
  6272. + per_cpu(plic_context, cpu)->claim = per_cpu(irq_in_progress, cpu);
  6273. + per_cpu(irq_in_progress, cpu) = 0;
  6274. +}
  6275. +
  6276. +struct irq_chip plic_irq_chip = {
  6277. + .name = "riscv",
  6278. + .irq_mask = plic_irq_mask,
  6279. + .irq_mask_ack = plic_irq_mask,
  6280. + .irq_unmask = plic_irq_unmask,
  6281. +};
  6282. +
  6283. +void __init init_IRQ(void)
  6284. +{
  6285. + /* Enable software interrupts (and disable the others) */
  6286. + csr_write(sie, SIE_SSIE);
  6287. +}
  6288. diff -Nur linux-4.6.2/arch/riscv/kernel/Makefile linux-4.6.2.riscv/arch/riscv/kernel/Makefile
  6289. --- linux-4.6.2/arch/riscv/kernel/Makefile 1970-01-01 01:00:00.000000000 +0100
  6290. +++ linux-4.6.2.riscv/arch/riscv/kernel/Makefile 2017-03-04 02:48:34.166888015 +0100
  6291. @@ -0,0 +1,15 @@
  6292. +#
  6293. +# Makefile for the RISC-V Linux kernel
  6294. +#
  6295. +
  6296. +extra-y := head.o vmlinux.lds
  6297. +
  6298. +obj-y := cpu.o entry.o irq.o process.o ptrace.o reset.o setup.o \
  6299. + sbi.o signal.o syscall_table.o sys_riscv.o time.o traps.o \
  6300. + stacktrace.o vdso.o vdso/
  6301. +
  6302. +obj-$(CONFIG_SMP) += smpboot.o smp.o
  6303. +obj-$(CONFIG_SBI_CONSOLE) += sbi-con.o
  6304. +obj-$(CONFIG_PCI) += pci.o
  6305. +
  6306. +clean:
  6307. diff -Nur linux-4.6.2/arch/riscv/kernel/pci.c linux-4.6.2.riscv/arch/riscv/kernel/pci.c
  6308. --- linux-4.6.2/arch/riscv/kernel/pci.c 1970-01-01 01:00:00.000000000 +0100
  6309. +++ linux-4.6.2.riscv/arch/riscv/kernel/pci.c 2017-03-04 02:48:34.166888015 +0100
  6310. @@ -0,0 +1,23 @@
  6311. +#include <linux/init.h>
  6312. +#include <linux/io.h>
  6313. +#include <linux/kernel.h>
  6314. +#include <linux/mm.h>
  6315. +#include <linux/slab.h>
  6316. +#include <linux/pci.h>
  6317. +
  6318. +/*
  6319. + * Called after each bus is probed, but before its children are examined
  6320. + */
  6321. +void pcibios_fixup_bus(struct pci_bus *bus)
  6322. +{
  6323. + /* nothing to do, expected to be removed in the future */
  6324. +}
  6325. +
  6326. +/*
  6327. + * We don't have to worry about legacy ISA devices, so nothing to do here
  6328. + */
  6329. +resource_size_t pcibios_align_resource(void *data, const struct resource *res,
  6330. + resource_size_t size, resource_size_t align)
  6331. +{
  6332. + return res->start;
  6333. +}
  6334. diff -Nur linux-4.6.2/arch/riscv/kernel/process.c linux-4.6.2.riscv/arch/riscv/kernel/process.c
  6335. --- linux-4.6.2/arch/riscv/kernel/process.c 1970-01-01 01:00:00.000000000 +0100
  6336. +++ linux-4.6.2.riscv/arch/riscv/kernel/process.c 2017-03-04 02:48:34.166888015 +0100
  6337. @@ -0,0 +1,106 @@
  6338. +#include <linux/kernel.h>
  6339. +#include <linux/sched.h>
  6340. +#include <linux/tick.h>
  6341. +#include <linux/ptrace.h>
  6342. +
  6343. +#include <asm/unistd.h>
  6344. +#include <asm/uaccess.h>
  6345. +#include <asm/processor.h>
  6346. +#include <asm/csr.h>
  6347. +#include <asm/string.h>
  6348. +#include <asm/switch_to.h>
  6349. +
  6350. +extern asmlinkage void ret_from_fork(void);
  6351. +extern asmlinkage void ret_from_kernel_thread(void);
  6352. +
  6353. +void arch_cpu_idle(void)
  6354. +{
  6355. + wait_for_interrupt();
  6356. + local_irq_enable();
  6357. +}
  6358. +
  6359. +void show_regs(struct pt_regs *regs)
  6360. +{
  6361. + show_regs_print_info(KERN_DEFAULT);
  6362. +
  6363. + printk("sepc: " REG_FMT " ra : " REG_FMT " sp : " REG_FMT "\n",
  6364. + regs->sepc, regs->ra, regs->sp);
  6365. + printk(" gp : " REG_FMT " tp : " REG_FMT " t0 : " REG_FMT "\n",
  6366. + regs->gp, regs->tp, regs->t0);
  6367. + printk(" t1 : " REG_FMT " t2 : " REG_FMT " s0 : " REG_FMT "\n",
  6368. + regs->t1, regs->t2, regs->s0);
  6369. + printk(" s1 : " REG_FMT " a0 : " REG_FMT " a1 : " REG_FMT "\n",
  6370. + regs->s1, regs->a0, regs->a1);
  6371. + printk(" a2 : " REG_FMT " a3 : " REG_FMT " a4 : " REG_FMT "\n",
  6372. + regs->a2, regs->a3, regs->a4);
  6373. + printk(" a5 : " REG_FMT " a6 : " REG_FMT " a7 : " REG_FMT "\n",
  6374. + regs->a5, regs->a6, regs->a7);
  6375. + printk(" s2 : " REG_FMT " s3 : " REG_FMT " s4 : " REG_FMT "\n",
  6376. + regs->s2, regs->s3, regs->s4);
  6377. + printk(" s5 : " REG_FMT " s6 : " REG_FMT " s7 : " REG_FMT "\n",
  6378. + regs->s5, regs->s6, regs->s7);
  6379. + printk(" s8 : " REG_FMT " s9 : " REG_FMT " s10: " REG_FMT "\n",
  6380. + regs->s8, regs->s9, regs->s10);
  6381. + printk(" s11: " REG_FMT " t3 : " REG_FMT " t4 : " REG_FMT "\n",
  6382. + regs->s11, regs->t3, regs->t4);
  6383. + printk(" t5 : " REG_FMT " t6 : " REG_FMT "\n",
  6384. + regs->t5, regs->t6);
  6385. +
  6386. + printk("sstatus: " REG_FMT " sbadaddr: " REG_FMT " scause: " REG_FMT "\n",
  6387. + regs->sstatus, regs->sbadaddr, regs->scause);
  6388. +}
  6389. +
  6390. +void start_thread(struct pt_regs *regs, unsigned long pc,
  6391. + unsigned long sp)
  6392. +{
  6393. + regs->sstatus = SR_PIE /* User mode, irqs on */ | SR_FS_INITIAL;
  6394. + regs->sepc = pc;
  6395. + regs->sp = sp;
  6396. + set_fs(USER_DS);
  6397. +}
  6398. +
  6399. +void flush_thread(void)
  6400. +{
  6401. + /* Reset FPU context
  6402. + * frm: round to nearest, ties to even (IEEE default)
  6403. + * fflags: accrued exceptions cleared
  6404. + */
  6405. + memset(&current->thread.fstate, 0,
  6406. + sizeof(struct user_fpregs_struct));
  6407. +}
  6408. +
  6409. +int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src)
  6410. +{
  6411. + fstate_save(src, task_pt_regs(src));
  6412. + *dst = *src;
  6413. + return 0;
  6414. +}
  6415. +
  6416. +int copy_thread(unsigned long clone_flags, unsigned long usp,
  6417. + unsigned long arg, struct task_struct *p)
  6418. +{
  6419. + struct pt_regs *childregs = task_pt_regs(p);
  6420. +
  6421. + /* p->thread holds context to be restored by __switch_to() */
  6422. + if (unlikely(p->flags & PF_KTHREAD)) {
  6423. + /* Kernel thread */
  6424. + const register unsigned long gp __asm__ ("gp");
  6425. + memset(childregs, 0, sizeof(struct pt_regs));
  6426. + childregs->gp = gp;
  6427. + childregs->sstatus = SR_PS | SR_PIE; /* Supervisor, irqs on */
  6428. +
  6429. + p->thread.ra = (unsigned long)ret_from_kernel_thread;
  6430. + p->thread.s[0] = usp; /* fn */
  6431. + p->thread.s[1] = arg;
  6432. + } else {
  6433. + *childregs = *(current_pt_regs());
  6434. + if (usp) /* User fork */
  6435. + childregs->sp = usp;
  6436. + if (clone_flags & CLONE_SETTLS)
  6437. + childregs->tp = childregs->a5;
  6438. + childregs->a0 = 0; /* Return value of fork() */
  6439. + p->thread.ra = (unsigned long)ret_from_fork;
  6440. + }
  6441. + p->thread.sp = (unsigned long)childregs; /* kernel sp */
  6442. + return 0;
  6443. +}
  6444. diff -Nur linux-4.6.2/arch/riscv/kernel/ptrace.c linux-4.6.2.riscv/arch/riscv/kernel/ptrace.c
  6445. --- linux-4.6.2/arch/riscv/kernel/ptrace.c 1970-01-01 01:00:00.000000000 +0100
  6446. +++ linux-4.6.2.riscv/arch/riscv/kernel/ptrace.c 2017-03-04 02:48:34.166888015 +0100
  6447. @@ -0,0 +1,128 @@
  6448. +#include <asm/ptrace.h>
  6449. +#include <asm/syscall.h>
  6450. +#include <asm/thread_info.h>
  6451. +#include <linux/ptrace.h>
  6452. +#include <linux/elf.h>
  6453. +#include <linux/regset.h>
  6454. +#include <linux/tracehook.h>
  6455. +#include <trace/events/syscalls.h>
  6456. +
  6457. +enum riscv_regset {
  6458. + REGSET_X,
  6459. +};
  6460. +
  6461. +/*
  6462. + * Get registers from task and ready the result for userspace.
  6463. + */
  6464. +static char *getregs(struct task_struct *child, struct pt_regs *uregs)
  6465. +{
  6466. + *uregs = *task_pt_regs(child);
  6467. + return (char *)uregs;
  6468. +}
  6469. +
  6470. +/* Put registers back to task. */
  6471. +static void putregs(struct task_struct *child, struct pt_regs *uregs)
  6472. +{
  6473. + struct pt_regs *regs = task_pt_regs(child);
  6474. + *regs = *uregs;
  6475. +}
  6476. +
  6477. +static int riscv_gpr_get(struct task_struct *target,
  6478. + const struct user_regset *regset,
  6479. + unsigned int pos, unsigned int count,
  6480. + void *kbuf, void __user *ubuf)
  6481. +{
  6482. + struct pt_regs regs;
  6483. +
  6484. + getregs(target, &regs);
  6485. +
  6486. + return user_regset_copyout(&pos, &count, &kbuf, &ubuf, &regs, 0,
  6487. + sizeof(regs));
  6488. +}
  6489. +
  6490. +static int riscv_gpr_set(struct task_struct *target,
  6491. + const struct user_regset *regset,
  6492. + unsigned int pos, unsigned int count,
  6493. + const void *kbuf, const void __user *ubuf)
  6494. +{
  6495. + int ret;
  6496. + struct pt_regs regs;
  6497. +
  6498. + ret = user_regset_copyin(&pos, &count, &kbuf, &ubuf, &regs, 0,
  6499. + sizeof(regs));
  6500. + if (ret)
  6501. + return ret;
  6502. +
  6503. + putregs(target, &regs);
  6504. +
  6505. + return 0;
  6506. +}
  6507. +
  6508. +
  6509. +static const struct user_regset riscv_user_regset[] = {
  6510. + [REGSET_X] = {
  6511. + .core_note_type = NT_PRSTATUS,
  6512. + .n = ELF_NGREG,
  6513. + .size = sizeof(elf_greg_t),
  6514. + .align = sizeof(elf_greg_t),
  6515. + .get = &riscv_gpr_get,
  6516. + .set = &riscv_gpr_set,
  6517. + },
  6518. +};
  6519. +
  6520. +static const struct user_regset_view riscv_user_native_view = {
  6521. + .name = "riscv",
  6522. + .e_machine = EM_RISCV,
  6523. + .regsets = riscv_user_regset,
  6524. + .n = ARRAY_SIZE(riscv_user_regset),
  6525. +};
  6526. +
  6527. +const struct user_regset_view *task_user_regset_view(struct task_struct *task)
  6528. +{
  6529. + return &riscv_user_native_view;
  6530. +}
  6531. +
  6532. +void ptrace_disable(struct task_struct *child)
  6533. +{
  6534. + clear_tsk_thread_flag(child, TIF_SYSCALL_TRACE);
  6535. +}
  6536. +
  6537. +long arch_ptrace(struct task_struct *child, long request,
  6538. + unsigned long addr, unsigned long data)
  6539. +{
  6540. + long ret = -EIO;
  6541. +
  6542. + switch (request) {
  6543. + default:
  6544. + ret = ptrace_request(child, request, addr, data);
  6545. + break;
  6546. + }
  6547. +
  6548. + return ret;
  6549. +}
  6550. +
  6551. +/* Allows PTRACE_SYSCALL to work. These are called from entry.S in
  6552. + * {handle,ret_from}_syscall. */
  6553. +void do_syscall_trace_enter(struct pt_regs *regs)
  6554. +{
  6555. + if (test_thread_flag(TIF_SYSCALL_TRACE)) {
  6556. + if (tracehook_report_syscall_entry(regs))
  6557. + syscall_set_nr(current, regs, -1);
  6558. + }
  6559. +
  6560. +#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
  6561. + if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
  6562. + trace_sys_enter(regs, syscall_get_nr(current, regs));
  6563. +#endif
  6564. +}
  6565. +
  6566. +void do_syscall_trace_exit(struct pt_regs *regs)
  6567. +{
  6568. + if (test_thread_flag(TIF_SYSCALL_TRACE))
  6569. + tracehook_report_syscall_exit(regs, 0);
  6570. +
  6571. +#ifdef CONFIG_HAVE_SYSCALL_TRACEPOINTS
  6572. + if (test_thread_flag(TIF_SYSCALL_TRACEPOINT))
  6573. + trace_sys_exit(regs, regs->regs[0]);
  6574. +#endif
  6575. +}
  6576. diff -Nur linux-4.6.2/arch/riscv/kernel/reset.c linux-4.6.2.riscv/arch/riscv/kernel/reset.c
  6577. --- linux-4.6.2/arch/riscv/kernel/reset.c 1970-01-01 01:00:00.000000000 +0100
  6578. +++ linux-4.6.2.riscv/arch/riscv/kernel/reset.c 2017-03-04 02:48:34.166888015 +0100
  6579. @@ -0,0 +1,19 @@
  6580. +#include <linux/reboot.h>
  6581. +#include <linux/export.h>
  6582. +#include <asm/sbi.h>
  6583. +
  6584. +void (*pm_power_off)(void) = machine_power_off;
  6585. +EXPORT_SYMBOL(pm_power_off);
  6586. +
  6587. +void machine_restart(char *cmd)
  6588. +{
  6589. +}
  6590. +
  6591. +void machine_halt(void)
  6592. +{
  6593. +}
  6594. +
  6595. +void machine_power_off(void)
  6596. +{
  6597. + sbi_shutdown();
  6598. +}
  6599. diff -Nur linux-4.6.2/arch/riscv/kernel/sbi-con.c linux-4.6.2.riscv/arch/riscv/kernel/sbi-con.c
  6600. --- linux-4.6.2/arch/riscv/kernel/sbi-con.c 1970-01-01 01:00:00.000000000 +0100
  6601. +++ linux-4.6.2.riscv/arch/riscv/kernel/sbi-con.c 2017-03-04 02:48:34.166888015 +0100
  6602. @@ -0,0 +1,155 @@
  6603. +#include <linux/init.h>
  6604. +#include <linux/console.h>
  6605. +#include <linux/tty.h>
  6606. +#include <linux/tty_flip.h>
  6607. +#include <linux/tty_driver.h>
  6608. +#include <linux/module.h>
  6609. +#include <linux/interrupt.h>
  6610. +
  6611. +#include <asm/sbi.h>
  6612. +
  6613. +static DEFINE_SPINLOCK(sbi_tty_port_lock);
  6614. +static struct tty_port sbi_tty_port;
  6615. +static struct tty_driver *sbi_tty_driver;
  6616. +
  6617. +irqreturn_t sbi_console_isr(void)
  6618. +{
  6619. + int ch = sbi_console_getchar();
  6620. + if (ch < 0)
  6621. + return IRQ_NONE;
  6622. +
  6623. + spin_lock(&sbi_tty_port_lock);
  6624. + tty_insert_flip_char(&sbi_tty_port, ch, TTY_NORMAL);
  6625. + tty_flip_buffer_push(&sbi_tty_port);
  6626. + spin_unlock(&sbi_tty_port_lock);
  6627. +
  6628. + return IRQ_HANDLED;
  6629. +}
  6630. +
  6631. +static int sbi_tty_open(struct tty_struct *tty, struct file *filp)
  6632. +{
  6633. + return 0;
  6634. +}
  6635. +
  6636. +static int sbi_tty_write(struct tty_struct *tty,
  6637. + const unsigned char *buf, int count)
  6638. +{
  6639. + const unsigned char *end;
  6640. +
  6641. + for (end = buf + count; buf < end; buf++) {
  6642. + sbi_console_putchar(*buf);
  6643. + }
  6644. + return count;
  6645. +}
  6646. +
  6647. +static int sbi_tty_write_room(struct tty_struct *tty)
  6648. +{
  6649. + return 1024; /* arbitrary */
  6650. +}
  6651. +
  6652. +static const struct tty_operations sbi_tty_ops = {
  6653. + .open = sbi_tty_open,
  6654. + .write = sbi_tty_write,
  6655. + .write_room = sbi_tty_write_room,
  6656. +};
  6657. +
  6658. +
  6659. +static void sbi_console_write(struct console *co, const char *buf, unsigned n)
  6660. +{
  6661. + for ( ; n > 0; n--, buf++) {
  6662. + if (*buf == '\n')
  6663. + sbi_console_putchar('\r');
  6664. + sbi_console_putchar(*buf);
  6665. + }
  6666. +}
  6667. +
  6668. +static struct tty_driver *sbi_console_device(struct console *co, int *index)
  6669. +{
  6670. + *index = co->index;
  6671. + return sbi_tty_driver;
  6672. +}
  6673. +
  6674. +static int sbi_console_setup(struct console *co, char *options)
  6675. +{
  6676. + return co->index != 0 ? -ENODEV : 0;
  6677. +}
  6678. +
  6679. +static struct console sbi_console = {
  6680. + .name = "sbi_console",
  6681. + .write = sbi_console_write,
  6682. + .device = sbi_console_device,
  6683. + .setup = sbi_console_setup,
  6684. + .flags = CON_PRINTBUFFER,
  6685. + .index = -1
  6686. +};
  6687. +
  6688. +static int __init sbi_console_init(void)
  6689. +{
  6690. + int ret;
  6691. +
  6692. + register_console(&sbi_console);
  6693. +
  6694. + sbi_tty_driver = tty_alloc_driver(1,
  6695. + TTY_DRIVER_REAL_RAW | TTY_DRIVER_DYNAMIC_DEV);
  6696. + if (unlikely(IS_ERR(sbi_tty_driver)))
  6697. + return PTR_ERR(sbi_tty_driver);
  6698. +
  6699. + sbi_tty_driver->driver_name = "sbi";
  6700. + sbi_tty_driver->name = "ttySBI";
  6701. + sbi_tty_driver->major = TTY_MAJOR;
  6702. + sbi_tty_driver->minor_start = 0;
  6703. + sbi_tty_driver->type = TTY_DRIVER_TYPE_SERIAL;
  6704. + sbi_tty_driver->subtype = SERIAL_TYPE_NORMAL;
  6705. + sbi_tty_driver->init_termios = tty_std_termios;
  6706. + tty_set_operations(sbi_tty_driver, &sbi_tty_ops);
  6707. +
  6708. + tty_port_init(&sbi_tty_port);
  6709. + tty_port_link_device(&sbi_tty_port, sbi_tty_driver, 0);
  6710. +
  6711. + ret = tty_register_driver(sbi_tty_driver);
  6712. + if (unlikely(ret))
  6713. + goto out_tty_put;
  6714. +
  6715. + /* Poll the console once, which will trigger future interrupts */
  6716. + sbi_console_isr();
  6717. +
  6718. + return ret;
  6719. +
  6720. +out_tty_put:
  6721. + put_tty_driver(sbi_tty_driver);
  6722. + return ret;
  6723. +}
  6724. +
  6725. +static void __exit sbi_console_exit(void)
  6726. +{
  6727. + tty_unregister_driver(sbi_tty_driver);
  6728. + put_tty_driver(sbi_tty_driver);
  6729. +}
  6730. +
  6731. +module_init(sbi_console_init);
  6732. +module_exit(sbi_console_exit);
  6733. +
  6734. +MODULE_DESCRIPTION("RISC-V SBI console driver");
  6735. +MODULE_LICENSE("GPL");
  6736. +
  6737. +#ifdef CONFIG_EARLY_PRINTK
  6738. +
  6739. +static struct console early_console_dev __initdata = {
  6740. + .name = "early",
  6741. + .write = sbi_console_write,
  6742. + .flags = CON_PRINTBUFFER | CON_BOOT,
  6743. + .index = -1
  6744. +};
  6745. +
  6746. +static int __init setup_early_printk(char *str)
  6747. +{
  6748. + if (early_console == NULL) {
  6749. + early_console = &early_console_dev;
  6750. + register_console(early_console);
  6751. + }
  6752. + return 0;
  6753. +}
  6754. +
  6755. +early_param("earlyprintk", setup_early_printk);
  6756. +
  6757. +#endif
  6758. diff -Nur linux-4.6.2/arch/riscv/kernel/sbi.S linux-4.6.2.riscv/arch/riscv/kernel/sbi.S
  6759. --- linux-4.6.2/arch/riscv/kernel/sbi.S 1970-01-01 01:00:00.000000000 +0100
  6760. +++ linux-4.6.2.riscv/arch/riscv/kernel/sbi.S 2017-03-04 02:48:34.166888015 +0100
  6761. @@ -0,0 +1,15 @@
  6762. +.globl sbi_hart_id; sbi_hart_id = -2048
  6763. +.globl sbi_num_harts; sbi_num_harts = -2032
  6764. +.globl sbi_query_memory; sbi_query_memory = -2016
  6765. +.globl sbi_console_putchar; sbi_console_putchar = -2000
  6766. +.globl sbi_console_getchar; sbi_console_getchar = -1984
  6767. +.globl sbi_send_ipi; sbi_send_ipi = -1952
  6768. +.globl sbi_clear_ipi; sbi_clear_ipi = -1936
  6769. +.globl sbi_timebase; sbi_timebase = -1920
  6770. +.globl sbi_shutdown; sbi_shutdown = -1904
  6771. +.globl sbi_set_timer; sbi_set_timer = -1888
  6772. +.globl sbi_mask_interrupt; sbi_mask_interrupt = -1872
  6773. +.globl sbi_unmask_interrupt; sbi_unmask_interrupt = -1856
  6774. +.globl sbi_remote_sfence_vm; sbi_remote_sfence_vm = -1840
  6775. +.globl sbi_remote_sfence_vm_range; sbi_remote_sfence_vm_range = -1824
  6776. +.globl sbi_remote_fence_i; sbi_remote_fence_i = -1808
  6777. diff -Nur linux-4.6.2/arch/riscv/kernel/setup.c linux-4.6.2.riscv/arch/riscv/kernel/setup.c
  6778. --- linux-4.6.2/arch/riscv/kernel/setup.c 1970-01-01 01:00:00.000000000 +0100
  6779. +++ linux-4.6.2.riscv/arch/riscv/kernel/setup.c 2017-03-04 02:48:34.166888015 +0100
  6780. @@ -0,0 +1,161 @@
  6781. +#include <linux/init.h>
  6782. +#include <linux/mm.h>
  6783. +#include <linux/memblock.h>
  6784. +#include <linux/sched.h>
  6785. +#include <linux/initrd.h>
  6786. +#include <linux/console.h>
  6787. +#include <linux/screen_info.h>
  6788. +
  6789. +#include <asm/setup.h>
  6790. +#include <asm/sections.h>
  6791. +#include <asm/pgtable.h>
  6792. +#include <asm/smp.h>
  6793. +#include <asm/sbi.h>
  6794. +
  6795. +#ifdef CONFIG_DUMMY_CONSOLE
  6796. +struct screen_info screen_info = {
  6797. + .orig_video_lines = 30,
  6798. + .orig_video_cols = 80,
  6799. + .orig_video_mode = 0,
  6800. + .orig_video_ega_bx = 0,
  6801. + .orig_video_isVGA = 1,
  6802. + .orig_video_points = 8
  6803. +};
  6804. +#endif
  6805. +
  6806. +static char __initdata command_line[COMMAND_LINE_SIZE];
  6807. +#ifdef CONFIG_CMDLINE_BOOL
  6808. +static char __initdata builtin_cmdline[COMMAND_LINE_SIZE] = CONFIG_CMDLINE;
  6809. +#endif /* CONFIG_CMDLINE_BOOL */
  6810. +
  6811. +unsigned long va_pa_offset;
  6812. +unsigned long pfn_base;
  6813. +
  6814. +#ifdef CONFIG_BLK_DEV_INITRD
  6815. +static void __init setup_initrd(void)
  6816. +{
  6817. + extern char __initramfs_start[];
  6818. + extern unsigned long __initramfs_size;
  6819. + unsigned long size;
  6820. +
  6821. + if (__initramfs_size > 0) {
  6822. + initrd_start = (unsigned long)(&__initramfs_start);
  6823. + initrd_end = initrd_start + __initramfs_size;
  6824. + }
  6825. +
  6826. + if (initrd_start >= initrd_end) {
  6827. + printk(KERN_INFO "initrd not found or empty");
  6828. + goto disable;
  6829. + }
  6830. + if (__pa(initrd_end) > PFN_PHYS(max_low_pfn)) {
  6831. + printk(KERN_ERR "initrd extends beyond end of memory");
  6832. + goto disable;
  6833. + }
  6834. +
  6835. + size = initrd_end - initrd_start;
  6836. + memblock_reserve(__pa(initrd_start), size);
  6837. + initrd_below_start_ok = 1;
  6838. +
  6839. + printk(KERN_INFO "Initial ramdisk at: 0x%p (%lu bytes)\n",
  6840. + (void *)(initrd_start), size);
  6841. + return;
  6842. +disable:
  6843. + printk(KERN_CONT " - disabling initrd\n");
  6844. + initrd_start = 0;
  6845. + initrd_end = 0;
  6846. +}
  6847. +#endif /* CONFIG_BLK_DEV_INITRD */
  6848. +
  6849. +static resource_size_t __initdata mem_size;
  6850. +
  6851. +/* Parse "mem=nn[KkMmGg]" */
  6852. +static int __init early_mem(char *p)
  6853. +{
  6854. + if (!p)
  6855. + return -EINVAL;
  6856. + mem_size = memparse(p, &p) & PMD_MASK;
  6857. + if (mem_size == 0)
  6858. + return -EINVAL;
  6859. + return 0;
  6860. +}
  6861. +early_param("mem", early_mem);
  6862. +
  6863. +static void __init reserve_boot_page_table(pte_t *table)
  6864. +{
  6865. + unsigned long i;
  6866. +
  6867. + memblock_reserve(__pa(table), PAGE_SIZE);
  6868. +
  6869. + for (i = 0; i < PTRS_PER_PTE; i++) {
  6870. + if (pte_present(table[i]) && !pte_huge(table[i]))
  6871. + reserve_boot_page_table(pfn_to_virt(pte_pfn(table[i])));
  6872. + }
  6873. +}
  6874. +
  6875. +static void __init setup_bootmem(void)
  6876. +{
  6877. + unsigned long ret;
  6878. + memory_block_info info;
  6879. +
  6880. + ret = sbi_query_memory(0, &info);
  6881. + BUG_ON(ret != 0);
  6882. + BUG_ON((info.base & ~PMD_MASK) != 0);
  6883. + BUG_ON((info.size & ~PMD_MASK) != 0);
  6884. + pr_info("Available physical memory: %ldMB\n", info.size >> 20);
  6885. +
  6886. + /* The kernel image is mapped at VA=PAGE_OFFSET and PA=info.base */
  6887. + va_pa_offset = PAGE_OFFSET - info.base;
  6888. + pfn_base = PFN_DOWN(info.base);
  6889. +
  6890. + if ((mem_size != 0) && (mem_size < info.size)) {
  6891. + memblock_enforce_memory_limit(mem_size);
  6892. + info.size = mem_size;
  6893. + pr_notice("Physical memory usage limited to %lluMB\n",
  6894. + (unsigned long long)(mem_size >> 20));
  6895. + }
  6896. + set_max_mapnr(PFN_DOWN(info.size));
  6897. + max_low_pfn = PFN_DOWN(info.base + info.size);
  6898. +
  6899. +#ifdef CONFIG_BLK_DEV_INITRD
  6900. + setup_initrd();
  6901. +#endif /* CONFIG_BLK_DEV_INITRD */
  6902. +
  6903. + memblock_reserve(info.base, __pa(_end) - info.base);
  6904. + reserve_boot_page_table(pfn_to_virt(csr_read(sptbr)));
  6905. + memblock_allow_resize();
  6906. +}
  6907. +
  6908. +void __init setup_arch(char **cmdline_p)
  6909. +{
  6910. +#ifdef CONFIG_CMDLINE_BOOL
  6911. +#ifdef CONFIG_CMDLINE_OVERRIDE
  6912. + strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  6913. +#else
  6914. + if (builtin_cmdline[0] != '\0') {
  6915. + /* Append bootloader command line to built-in */
  6916. + strlcat(builtin_cmdline, " ", COMMAND_LINE_SIZE);
  6917. + strlcat(builtin_cmdline, boot_command_line, COMMAND_LINE_SIZE);
  6918. + strlcpy(boot_command_line, builtin_cmdline, COMMAND_LINE_SIZE);
  6919. + }
  6920. +#endif /* CONFIG_CMDLINE_OVERRIDE */
  6921. +#endif /* CONFIG_CMDLINE_BOOL */
  6922. + strlcpy(command_line, boot_command_line, COMMAND_LINE_SIZE);
  6923. + *cmdline_p = command_line;
  6924. +
  6925. + parse_early_param();
  6926. +
  6927. + init_mm.start_code = (unsigned long) _stext;
  6928. + init_mm.end_code = (unsigned long) _etext;
  6929. + init_mm.end_data = (unsigned long) _edata;
  6930. + init_mm.brk = (unsigned long) _end;
  6931. +
  6932. + setup_bootmem();
  6933. +#ifdef CONFIG_SMP
  6934. + setup_smp();
  6935. +#endif
  6936. + paging_init();
  6937. +
  6938. +#ifdef CONFIG_DUMMY_CONSOLE
  6939. + conswitchp = &dummy_con;
  6940. +#endif
  6941. +}
  6942. diff -Nur linux-4.6.2/arch/riscv/kernel/signal.c linux-4.6.2.riscv/arch/riscv/kernel/signal.c
  6943. --- linux-4.6.2/arch/riscv/kernel/signal.c 1970-01-01 01:00:00.000000000 +0100
  6944. +++ linux-4.6.2.riscv/arch/riscv/kernel/signal.c 2017-03-04 02:48:34.166888015 +0100
  6945. @@ -0,0 +1,236 @@
  6946. +#include <linux/signal.h>
  6947. +#include <linux/uaccess.h>
  6948. +#include <linux/syscalls.h>
  6949. +#include <linux/tracehook.h>
  6950. +#include <linux/linkage.h>
  6951. +
  6952. +#include <asm/ucontext.h>
  6953. +#include <asm/vdso.h>
  6954. +#include <asm/switch_to.h>
  6955. +#include <asm/csr.h>
  6956. +
  6957. +#define DEBUG_SIG 0
  6958. +
  6959. +struct rt_sigframe {
  6960. + struct siginfo info;
  6961. + struct ucontext uc;
  6962. +};
  6963. +
  6964. +static long restore_sigcontext(struct pt_regs *regs,
  6965. + struct sigcontext __user *sc)
  6966. +{
  6967. + struct task_struct *task = current;
  6968. + long err;
  6969. + /* sc_regs is structured the same as the start of pt_regs */
  6970. + err = __copy_from_user(regs, &sc->sc_regs, sizeof(sc->sc_regs));
  6971. + err |= __copy_from_user(&task->thread.fstate, &sc->sc_fpregs,
  6972. + sizeof(sc->sc_fpregs));
  6973. + if (likely(!err))
  6974. + fstate_restore(task, regs);
  6975. + return err;
  6976. +}
  6977. +
  6978. +SYSCALL_DEFINE0(rt_sigreturn)
  6979. +{
  6980. + struct pt_regs *regs = current_pt_regs();
  6981. + struct rt_sigframe __user *frame;
  6982. + struct task_struct *task;
  6983. + sigset_t set;
  6984. +
  6985. + /* Always make any pending restarted system calls return -EINTR */
  6986. + current->restart_block.fn = do_no_restart_syscall;
  6987. +
  6988. + frame = (struct rt_sigframe __user *)regs->sp;
  6989. +
  6990. + if (!access_ok(VERIFY_READ, frame, sizeof(*frame)))
  6991. + goto badframe;
  6992. +
  6993. + if (__copy_from_user(&set, &frame->uc.uc_sigmask, sizeof(set)))
  6994. + goto badframe;
  6995. +
  6996. + set_current_blocked(&set);
  6997. +
  6998. + if (restore_sigcontext(regs, &frame->uc.uc_mcontext))
  6999. + goto badframe;
  7000. +
  7001. + if (restore_altstack(&frame->uc.uc_stack))
  7002. + goto badframe;
  7003. +
  7004. + return regs->a0;
  7005. +
  7006. +badframe:
  7007. + task = current;
  7008. + if (show_unhandled_signals) {
  7009. + pr_info_ratelimited("%s[%d]: bad frame in %s: "
  7010. + "frame=%p pc=%p sp=%p\n",
  7011. + task->comm, task_pid_nr(task), __func__,
  7012. + frame, (void *)regs->sepc, (void *)regs->sp);
  7013. + }
  7014. + force_sig(SIGSEGV, task);
  7015. + return 0;
  7016. +}
  7017. +
  7018. +static long setup_sigcontext(struct sigcontext __user *sc,
  7019. + struct pt_regs *regs)
  7020. +{
  7021. + struct task_struct *task = current;
  7022. + long err;
  7023. + /* sc_regs is structured the same as the start of pt_regs */
  7024. + err = __copy_to_user(&sc->sc_regs, regs, sizeof(sc->sc_regs));
  7025. + fstate_save(task, regs);
  7026. + err |= __copy_to_user(&sc->sc_fpregs, &task->thread.fstate,
  7027. + sizeof(sc->sc_fpregs));
  7028. + return err;
  7029. +}
  7030. +
  7031. +static inline void __user *get_sigframe(struct ksignal *ksig,
  7032. + struct pt_regs *regs, size_t framesize)
  7033. +{
  7034. + unsigned long sp;
  7035. + /* Default to using normal stack */
  7036. + sp = regs->sp;
  7037. +
  7038. + /*
  7039. + * If we are on the alternate signal stack and would overflow it, don't.
  7040. + * Return an always-bogus address instead so we will die with SIGSEGV.
  7041. + */
  7042. + if (on_sig_stack(sp) && !likely(on_sig_stack(sp - framesize)))
  7043. + return (void __user __force *)(-1UL);
  7044. +
  7045. + /* This is the X/Open sanctioned signal stack switching. */
  7046. + sp = sigsp(sp, ksig) - framesize;
  7047. +
  7048. + /* Align the stack frame. */
  7049. + sp &= ~0xfUL;
  7050. +
  7051. + return (void __user *)sp;
  7052. +}
  7053. +
  7054. +
  7055. +static int setup_rt_frame(struct ksignal *ksig, sigset_t *set,
  7056. + struct pt_regs *regs)
  7057. +{
  7058. + struct rt_sigframe __user *frame;
  7059. + long err = 0;
  7060. +
  7061. + frame = get_sigframe(ksig, regs, sizeof(*frame));
  7062. + if (!access_ok(VERIFY_WRITE, frame, sizeof(*frame)))
  7063. + return -EFAULT;
  7064. +
  7065. + err |= copy_siginfo_to_user(&frame->info, &ksig->info);
  7066. +
  7067. + /* Create the ucontext. */
  7068. + err |= __put_user(0, &frame->uc.uc_flags);
  7069. + err |= __put_user(NULL, &frame->uc.uc_link);
  7070. + err |= __save_altstack(&frame->uc.uc_stack, regs->sp);
  7071. + err |= setup_sigcontext(&frame->uc.uc_mcontext, regs);
  7072. + err |= __copy_to_user(&frame->uc.uc_sigmask, set, sizeof(*set));
  7073. + if (err)
  7074. + return -EFAULT;
  7075. +
  7076. + /* Set up to return from userspace. */
  7077. + regs->ra = (unsigned long)VDSO_SYMBOL(
  7078. + current->mm->context.vdso, rt_sigreturn);
  7079. +
  7080. + /*
  7081. + * Set up registers for signal handler.
  7082. + * Registers that we don't modify keep the value they had from
  7083. + * user-space at the time we took the signal.
  7084. + * We always pass siginfo and mcontext, regardless of SA_SIGINFO,
  7085. + * since some things rely on this (e.g. glibc's debug/segfault.c).
  7086. + */
  7087. + regs->sepc = (unsigned long)ksig->ka.sa.sa_handler;
  7088. + regs->sp = (unsigned long)frame;
  7089. + regs->a0 = ksig->sig; /* a0: signal number */
  7090. + regs->a1 = (unsigned long)(&frame->info); /* a1: siginfo pointer */
  7091. + regs->a2 = (unsigned long)(&frame->uc); /* a2: ucontext pointer */
  7092. +
  7093. +#if DEBUG_SIG
  7094. + pr_info("SIG deliver (%s:%d): sig=%d pc=%p ra=%p sp=%p\n",
  7095. + current->comm, task_pid_nr(current), ksig->sig,
  7096. + (void *)regs->sepc, (void *)regs->ra, frame);
  7097. +#endif
  7098. +
  7099. + return 0;
  7100. +}
  7101. +
  7102. +static void handle_signal(struct ksignal *ksig, struct pt_regs *regs)
  7103. +{
  7104. + sigset_t *oldset = sigmask_to_save();
  7105. + int ret;
  7106. +
  7107. + /* Are we from a system call? */
  7108. + if (regs->scause == EXC_SYSCALL) {
  7109. + /* If so, check system call restarting.. */
  7110. + switch (regs->a0) {
  7111. + case -ERESTART_RESTARTBLOCK:
  7112. + case -ERESTARTNOHAND:
  7113. + regs->a0 = -EINTR;
  7114. + break;
  7115. +
  7116. + case -ERESTARTSYS:
  7117. + if (!(ksig->ka.sa.sa_flags & SA_RESTART)) {
  7118. + regs->a0 = -EINTR;
  7119. + break;
  7120. + }
  7121. + /* fallthrough */
  7122. + case -ERESTARTNOINTR:
  7123. + regs->sepc -= 0x4;
  7124. + break;
  7125. + }
  7126. + }
  7127. +
  7128. + /* Set up the stack frame */
  7129. + ret = setup_rt_frame(ksig, oldset, regs);
  7130. +
  7131. + signal_setup_done(ret, ksig, 0);
  7132. +}
  7133. +
  7134. +static void do_signal(struct pt_regs *regs)
  7135. +{
  7136. + struct ksignal ksig;
  7137. +
  7138. + if (get_signal(&ksig)) {
  7139. + /* Actually deliver the signal */
  7140. + handle_signal(&ksig, regs);
  7141. + return;
  7142. + }
  7143. +
  7144. + /* Did we come from a system call? */
  7145. + if (regs->scause == EXC_SYSCALL) {
  7146. + /* Restart the system call - no handlers present */
  7147. + switch (regs->a0) {
  7148. + case -ERESTARTNOHAND:
  7149. + case -ERESTARTSYS:
  7150. + case -ERESTARTNOINTR:
  7151. + regs->sepc -= 0x4;
  7152. + break;
  7153. + case -ERESTART_RESTARTBLOCK:
  7154. + regs->a7 = __NR_restart_syscall;
  7155. + regs->sepc -= 0x4;
  7156. + break;
  7157. + }
  7158. + }
  7159. +
  7160. + /* If there is no signal to deliver, we just put the saved
  7161. + sigmask back. */
  7162. + restore_saved_sigmask();
  7163. +}
  7164. +
  7165. +/*
  7166. + * notification of userspace execution resumption
  7167. + * - triggered by the _TIF_WORK_MASK flags
  7168. + */
  7169. +asmlinkage void do_notify_resume(struct pt_regs *regs,
  7170. + unsigned long thread_info_flags)
  7171. +{
  7172. + /* Handle pending signal delivery */
  7173. + if (thread_info_flags & _TIF_SIGPENDING) {
  7174. + do_signal(regs);
  7175. + }
  7176. +
  7177. + if (thread_info_flags & _TIF_NOTIFY_RESUME) {
  7178. + clear_thread_flag(TIF_NOTIFY_RESUME);
  7179. + tracehook_notify_resume(regs);
  7180. + }
  7181. +}
  7182. diff -Nur linux-4.6.2/arch/riscv/kernel/smpboot.c linux-4.6.2.riscv/arch/riscv/kernel/smpboot.c
  7183. --- linux-4.6.2/arch/riscv/kernel/smpboot.c 1970-01-01 01:00:00.000000000 +0100
  7184. +++ linux-4.6.2.riscv/arch/riscv/kernel/smpboot.c 2017-03-04 02:48:34.166888015 +0100
  7185. @@ -0,0 +1,72 @@
  7186. +#include <linux/module.h>
  7187. +#include <linux/init.h>
  7188. +#include <linux/kernel.h>
  7189. +#include <linux/mm.h>
  7190. +#include <linux/sched.h>
  7191. +#include <linux/kernel_stat.h>
  7192. +#include <linux/notifier.h>
  7193. +#include <linux/cpu.h>
  7194. +#include <linux/percpu.h>
  7195. +#include <linux/delay.h>
  7196. +#include <linux/err.h>
  7197. +#include <linux/irq.h>
  7198. +#include <asm/mmu_context.h>
  7199. +#include <asm/tlbflush.h>
  7200. +#include <asm/sections.h>
  7201. +#include <asm/sbi.h>
  7202. +
  7203. +void *__cpu_up_stack_pointer[NR_CPUS];
  7204. +
  7205. +void __init smp_prepare_boot_cpu(void)
  7206. +{
  7207. +}
  7208. +
  7209. +void __init smp_prepare_cpus(unsigned int max_cpus)
  7210. +{
  7211. +}
  7212. +
  7213. +void __init setup_smp(void)
  7214. +{
  7215. + int i, num_cpus = sbi_num_harts();
  7216. +
  7217. + for (i = 0; i < min(num_cpus, NR_CPUS); i++) {
  7218. + set_cpu_possible(i, true);
  7219. + set_cpu_present(i, true);
  7220. + }
  7221. +}
  7222. +
  7223. +int __cpu_up(unsigned int cpu, struct task_struct *tidle)
  7224. +{
  7225. + /* Signal cpu to start */
  7226. + __cpu_up_stack_pointer[cpu] = task_stack_page(tidle) + THREAD_SIZE;
  7227. +
  7228. + while (!cpu_online(cpu))
  7229. + ;
  7230. +
  7231. + return 0;
  7232. +}
  7233. +
  7234. +void __init smp_cpus_done(unsigned int max_cpus)
  7235. +{
  7236. +}
  7237. +
  7238. +/*
  7239. + * C entry point for a secondary processor.
  7240. + */
  7241. +asmlinkage void __init smp_callin(void)
  7242. +{
  7243. + struct mm_struct *mm = &init_mm;
  7244. +
  7245. + /* All kernel threads share the same mm context. */
  7246. + atomic_inc(&mm->mm_count);
  7247. + current->active_mm = mm;
  7248. +
  7249. + trap_init();
  7250. + init_clockevent();
  7251. + notify_cpu_starting(smp_processor_id());
  7252. + set_cpu_online(smp_processor_id(), 1);
  7253. + local_flush_tlb_all();
  7254. + local_irq_enable();
  7255. + preempt_disable();
  7256. + cpu_startup_entry(CPUHP_AP_ONLINE_IDLE);
  7257. +}
  7258. diff -Nur linux-4.6.2/arch/riscv/kernel/smp.c linux-4.6.2.riscv/arch/riscv/kernel/smp.c
  7259. --- linux-4.6.2/arch/riscv/kernel/smp.c 1970-01-01 01:00:00.000000000 +0100
  7260. +++ linux-4.6.2.riscv/arch/riscv/kernel/smp.c 2017-03-04 02:48:34.166888015 +0100
  7261. @@ -0,0 +1,85 @@
  7262. +#include <linux/interrupt.h>
  7263. +#include <linux/smp.h>
  7264. +#include <linux/sched.h>
  7265. +
  7266. +#include <asm/sbi.h>
  7267. +#include <asm/tlbflush.h>
  7268. +#include <asm/cacheflush.h>
  7269. +
  7270. +/* A collection of single bit ipi messages. */
  7271. +static struct {
  7272. + unsigned long bits ____cacheline_aligned;
  7273. +} ipi_data[NR_CPUS] __cacheline_aligned;
  7274. +
  7275. +enum ipi_message_type {
  7276. + IPI_RESCHEDULE,
  7277. + IPI_CALL_FUNC,
  7278. + IPI_MAX
  7279. +};
  7280. +
  7281. +irqreturn_t handle_ipi(void)
  7282. +{
  7283. + unsigned long *pending_ipis = &ipi_data[smp_processor_id()].bits;
  7284. + unsigned long ops;
  7285. +
  7286. + /* Clear pending IPI */
  7287. + if (!sbi_clear_ipi())
  7288. + return IRQ_NONE;
  7289. +
  7290. + mb(); /* Order interrupt and bit testing. */
  7291. + while ((ops = xchg(pending_ipis, 0)) != 0) {
  7292. + mb(); /* Order bit clearing and data access. */
  7293. +
  7294. + if (ops & (1 << IPI_RESCHEDULE))
  7295. + scheduler_ipi();
  7296. +
  7297. + if (ops & (1 << IPI_CALL_FUNC))
  7298. + generic_smp_call_function_interrupt();
  7299. +
  7300. + BUG_ON((ops >> IPI_MAX) != 0);
  7301. +
  7302. + mb(); /* Order data access and bit testing. */
  7303. + }
  7304. +
  7305. + return IRQ_HANDLED;
  7306. +}
  7307. +
  7308. +static void
  7309. +send_ipi_message(const struct cpumask *to_whom, enum ipi_message_type operation)
  7310. +{
  7311. + int i;
  7312. +
  7313. + mb();
  7314. + for_each_cpu(i, to_whom)
  7315. + set_bit(operation, &ipi_data[i].bits);
  7316. +
  7317. + mb();
  7318. + for_each_cpu(i, to_whom)
  7319. + sbi_send_ipi(i);
  7320. +}
  7321. +
  7322. +void arch_send_call_function_ipi_mask(struct cpumask *mask)
  7323. +{
  7324. + send_ipi_message(mask, IPI_CALL_FUNC);
  7325. +}
  7326. +
  7327. +void arch_send_call_function_single_ipi(int cpu)
  7328. +{
  7329. + send_ipi_message(cpumask_of(cpu), IPI_CALL_FUNC);
  7330. +}
  7331. +
  7332. +static void ipi_stop(void *unused)
  7333. +{
  7334. + while (1)
  7335. + wait_for_interrupt();
  7336. +}
  7337. +
  7338. +void smp_send_stop(void)
  7339. +{
  7340. + on_each_cpu(ipi_stop, NULL, 1);
  7341. +}
  7342. +
  7343. +void smp_send_reschedule(int cpu)
  7344. +{
  7345. + send_ipi_message(cpumask_of(cpu), IPI_RESCHEDULE);
  7346. +}
  7347. diff -Nur linux-4.6.2/arch/riscv/kernel/stacktrace.c linux-4.6.2.riscv/arch/riscv/kernel/stacktrace.c
  7348. --- linux-4.6.2/arch/riscv/kernel/stacktrace.c 1970-01-01 01:00:00.000000000 +0100
  7349. +++ linux-4.6.2.riscv/arch/riscv/kernel/stacktrace.c 2017-03-04 02:48:34.166888015 +0100
  7350. @@ -0,0 +1,163 @@
  7351. +#include <linux/export.h>
  7352. +#include <linux/kallsyms.h>
  7353. +#include <linux/sched.h>
  7354. +#include <linux/stacktrace.h>
  7355. +
  7356. +#ifdef CONFIG_FRAME_POINTER
  7357. +
  7358. +struct stackframe {
  7359. + unsigned long fp;
  7360. + unsigned long ra;
  7361. +};
  7362. +
  7363. +static void notrace walk_stackframe(struct task_struct *task,
  7364. + struct pt_regs *regs, bool (*fn)(unsigned long, void *), void *arg)
  7365. +{
  7366. + unsigned long fp, sp, pc;
  7367. +
  7368. + if (regs) {
  7369. + fp = GET_FP(regs);
  7370. + sp = GET_USP(regs);
  7371. + pc = GET_IP(regs);
  7372. + } else if (task == NULL || task == current) {
  7373. + const register unsigned long current_sp __asm__ ("sp");
  7374. + fp = (unsigned long)__builtin_frame_address(0);
  7375. + sp = current_sp;
  7376. + pc = (unsigned long)walk_stackframe;
  7377. + } else {
  7378. + /* task blocked in __switch_to */
  7379. + fp = task->thread.s[0];
  7380. + sp = task->thread.sp;
  7381. + pc = task->thread.ra;
  7382. + }
  7383. +
  7384. + for (;;) {
  7385. + unsigned long low, high;
  7386. + struct stackframe *frame;
  7387. +
  7388. + if (unlikely(!__kernel_text_address(pc) || fn(pc, arg)))
  7389. + break;
  7390. +
  7391. + /* Validate frame pointer */
  7392. + low = sp + sizeof(struct stackframe);
  7393. + high = ALIGN(sp, THREAD_SIZE);
  7394. + if (unlikely(fp < low || fp > high || fp & 0x7))
  7395. + break;
  7396. + /* Unwind stack frame */
  7397. + frame = (struct stackframe *)fp - 1;
  7398. + sp = fp;
  7399. + fp = frame->fp;
  7400. + pc = frame->ra - 0x4;
  7401. + }
  7402. +}
  7403. +
  7404. +#else /* !CONFIG_FRAME_POINTER */
  7405. +
  7406. +static void notrace walk_stackframe(struct task_struct *task,
  7407. + struct pt_regs *regs, bool (*fn)(unsigned long, void *), void *arg)
  7408. +{
  7409. + unsigned long sp, pc;
  7410. + unsigned long *ksp;
  7411. +
  7412. + if (regs) {
  7413. + sp = GET_USP(regs);
  7414. + pc = GET_IP(regs);
  7415. + } else if (task == NULL || task == current) {
  7416. + const register unsigned long current_sp __asm__ ("sp");
  7417. + sp = current_sp;
  7418. + pc = (unsigned long)walk_stackframe;
  7419. + } else {
  7420. + /* task blocked in __switch_to */
  7421. + sp = task->thread.sp;
  7422. + pc = task->thread.ra;
  7423. + }
  7424. +
  7425. + if (unlikely(sp & 0x7))
  7426. + return;
  7427. +
  7428. + ksp = (unsigned long *)sp;
  7429. + while (!kstack_end(ksp)) {
  7430. + if (__kernel_text_address(pc) && unlikely(fn(pc, arg))) {
  7431. + break;
  7432. + }
  7433. + pc = (*ksp++) - 0x4;
  7434. + }
  7435. +}
  7436. +
  7437. +#endif /* CONFIG_FRAME_POINTER */
  7438. +
  7439. +
  7440. +static bool print_trace_address(unsigned long pc, void *arg)
  7441. +{
  7442. + print_ip_sym(pc);
  7443. + return false;
  7444. +}
  7445. +
  7446. +void show_stack(struct task_struct *task, unsigned long *sp)
  7447. +{
  7448. + printk("Call Trace:\n");
  7449. + walk_stackframe(task, NULL, print_trace_address, NULL);
  7450. +}
  7451. +
  7452. +
  7453. +static bool save_wchan(unsigned long pc, void *arg)
  7454. +{
  7455. + if (!in_sched_functions(pc)) {
  7456. + unsigned long *p = arg;
  7457. + *p = pc;
  7458. + return true;
  7459. + }
  7460. + return false;
  7461. +}
  7462. +
  7463. +unsigned long get_wchan(struct task_struct *task)
  7464. +{
  7465. + unsigned long pc;
  7466. + pc = 0;
  7467. + if (likely(task && task != current && task->state != TASK_RUNNING)) {
  7468. + walk_stackframe(task, NULL, save_wchan, &pc);
  7469. + }
  7470. + return pc;
  7471. +}
  7472. +
  7473. +
  7474. +#ifdef CONFIG_STACKTRACE
  7475. +
  7476. +static bool __save_trace(unsigned long pc, void *arg, bool nosched)
  7477. +{
  7478. + struct stack_trace *trace = arg;
  7479. +
  7480. + if (unlikely(nosched && in_sched_functions(pc)))
  7481. + return false;
  7482. + if (unlikely(trace->skip > 0)) {
  7483. + trace->skip--;
  7484. + return false;
  7485. + }
  7486. +
  7487. + trace->entries[trace->nr_entries++] = pc;
  7488. + return (trace->nr_entries >= trace->max_entries);
  7489. +}
  7490. +
  7491. +static bool save_trace(unsigned long pc, void *arg)
  7492. +{
  7493. + return __save_trace(pc, arg, false);
  7494. +}
  7495. +
  7496. +/*
  7497. + * Save stack-backtrace addresses into a stack_trace buffer.
  7498. + */
  7499. +void save_stack_trace_tsk(struct task_struct *tsk, struct stack_trace *trace)
  7500. +{
  7501. + walk_stackframe(tsk, NULL, save_trace, trace);
  7502. + if (trace->nr_entries < trace->max_entries)
  7503. + trace->entries[trace->nr_entries++] = ULONG_MAX;
  7504. +}
  7505. +EXPORT_SYMBOL_GPL(save_stack_trace_tsk);
  7506. +
  7507. +void save_stack_trace(struct stack_trace *trace)
  7508. +{
  7509. + save_stack_trace_tsk(NULL, trace);
  7510. +}
  7511. +EXPORT_SYMBOL_GPL(save_stack_trace);
  7512. +
  7513. +#endif /* CONFIG_STACKTRACE */
  7514. diff -Nur linux-4.6.2/arch/riscv/kernel/syscall_table.c linux-4.6.2.riscv/arch/riscv/kernel/syscall_table.c
  7515. --- linux-4.6.2/arch/riscv/kernel/syscall_table.c 1970-01-01 01:00:00.000000000 +0100
  7516. +++ linux-4.6.2.riscv/arch/riscv/kernel/syscall_table.c 2017-03-04 02:48:34.166888015 +0100
  7517. @@ -0,0 +1,10 @@
  7518. +#include <linux/syscalls.h>
  7519. +
  7520. +#include <asm/syscalls.h>
  7521. +
  7522. +#undef __SYSCALL
  7523. +#define __SYSCALL(nr, call) [nr] = (call),
  7524. +
  7525. +void *sys_call_table[__NR_syscalls] = {
  7526. +#include <asm/unistd.h>
  7527. +};
  7528. diff -Nur linux-4.6.2/arch/riscv/kernel/sys_riscv.c linux-4.6.2.riscv/arch/riscv/kernel/sys_riscv.c
  7529. --- linux-4.6.2/arch/riscv/kernel/sys_riscv.c 1970-01-01 01:00:00.000000000 +0100
  7530. +++ linux-4.6.2.riscv/arch/riscv/kernel/sys_riscv.c 2017-03-04 02:48:34.166888015 +0100
  7531. @@ -0,0 +1,70 @@
  7532. +#include <linux/syscalls.h>
  7533. +#include <asm/unistd.h>
  7534. +
  7535. +SYSCALL_DEFINE6(mmap, unsigned long, addr, unsigned long, len,
  7536. + unsigned long, prot, unsigned long, flags,
  7537. + unsigned long, fd, off_t, offset)
  7538. +{
  7539. + if (unlikely(offset & (~PAGE_MASK)))
  7540. + return -EINVAL;
  7541. + return sys_mmap_pgoff(addr, len, prot, flags, fd, offset >> PAGE_SHIFT);
  7542. +}
  7543. +
  7544. +#ifndef CONFIG_64BIT
  7545. +SYSCALL_DEFINE6(mmap2, unsigned long, addr, unsigned long, len,
  7546. + unsigned long, prot, unsigned long, flags,
  7547. + unsigned long, fd, off_t, offset)
  7548. +{
  7549. + /* Note that the shift for mmap2 is constant (12),
  7550. + regardless of PAGE_SIZE */
  7551. + if (unlikely(offset & (~PAGE_MASK >> 12)))
  7552. + return -EINVAL;
  7553. + return sys_mmap_pgoff(addr, len, prot, flags, fd,
  7554. + offset >> (PAGE_SHIFT - 12));
  7555. +}
  7556. +#endif /* !CONFIG_64BIT */
  7557. +
  7558. +#ifdef CONFIG_RV_SYSRISCV_ATOMIC
  7559. +SYSCALL_DEFINE4(sysriscv, unsigned long, cmd, unsigned long, arg1,
  7560. + unsigned long, arg2, unsigned long, arg3)
  7561. +{
  7562. + unsigned long flags;
  7563. + unsigned long prev;
  7564. + unsigned int *ptr;
  7565. + unsigned int err;
  7566. +
  7567. + switch (cmd) {
  7568. + case RISCV_ATOMIC_CMPXCHG:
  7569. + ptr = (unsigned int *)arg1;
  7570. + if (!access_ok(VERIFY_WRITE, ptr, sizeof(unsigned int)))
  7571. + return -EFAULT;
  7572. +
  7573. + preempt_disable();
  7574. + raw_local_irq_save(flags);
  7575. + err = __get_user(prev, ptr);
  7576. + if (likely(!err && prev == arg2))
  7577. + err = __put_user(arg3, ptr);
  7578. + raw_local_irq_restore(flags);
  7579. + preempt_enable();
  7580. +
  7581. + return unlikely(err) ? err : prev;
  7582. +
  7583. + case RISCV_ATOMIC_CMPXCHG64:
  7584. + ptr = (unsigned int *)arg1;
  7585. + if (!access_ok(VERIFY_WRITE, ptr, sizeof(unsigned long)))
  7586. + return -EFAULT;
  7587. +
  7588. + preempt_disable();
  7589. + raw_local_irq_save(flags);
  7590. + err = __get_user(prev, ptr);
  7591. + if (likely(!err && prev == arg2))
  7592. + err = __put_user(arg3, ptr);
  7593. + raw_local_irq_restore(flags);
  7594. + preempt_enable();
  7595. +
  7596. + return unlikely(err) ? err : prev;
  7597. + }
  7598. +
  7599. + return -EINVAL;
  7600. +}
  7601. +#endif /* CONFIG_RV_SYSRISCV_ATOMIC */
  7602. diff -Nur linux-4.6.2/arch/riscv/kernel/time.c linux-4.6.2.riscv/arch/riscv/kernel/time.c
  7603. --- linux-4.6.2/arch/riscv/kernel/time.c 1970-01-01 01:00:00.000000000 +0100
  7604. +++ linux-4.6.2.riscv/arch/riscv/kernel/time.c 2017-03-04 02:48:34.166888015 +0100
  7605. @@ -0,0 +1,88 @@
  7606. +#include <linux/clocksource.h>
  7607. +#include <linux/clockchips.h>
  7608. +#include <linux/interrupt.h>
  7609. +#include <linux/irq.h>
  7610. +#include <linux/delay.h>
  7611. +
  7612. +#include <asm/irq.h>
  7613. +#include <asm/csr.h>
  7614. +#include <asm/sbi.h>
  7615. +#include <asm/delay.h>
  7616. +
  7617. +unsigned long timebase;
  7618. +
  7619. +static DEFINE_PER_CPU(struct clock_event_device, clock_event);
  7620. +
  7621. +static int riscv_timer_set_next_event(unsigned long delta,
  7622. + struct clock_event_device *evdev)
  7623. +{
  7624. + sbi_set_timer(get_cycles() + delta);
  7625. + return 0;
  7626. +}
  7627. +
  7628. +static int riscv_timer_set_oneshot(struct clock_event_device *evt)
  7629. +{
  7630. + /* no-op; only one mode */
  7631. + return 0;
  7632. +}
  7633. +
  7634. +static int riscv_timer_set_shutdown(struct clock_event_device *evt)
  7635. +{
  7636. + /* can't stop the clock! */
  7637. + return 0;
  7638. +}
  7639. +
  7640. +static cycle_t riscv_rdtime(struct clocksource *cs)
  7641. +{
  7642. + return get_cycles();
  7643. +}
  7644. +
  7645. +static struct clocksource riscv_clocksource = {
  7646. + .name = "riscv_clocksource",
  7647. + .rating = 300,
  7648. + .read = riscv_rdtime,
  7649. +#ifdef CONFIG_64BITS
  7650. + .mask = CLOCKSOURCE_MASK(64),
  7651. +#else
  7652. + .mask = CLOCKSOURCE_MASK(32),
  7653. +#endif /* CONFIG_64BITS */
  7654. + .flags = CLOCK_SOURCE_IS_CONTINUOUS,
  7655. +};
  7656. +
  7657. +void riscv_timer_interrupt(void)
  7658. +{
  7659. + int cpu = smp_processor_id();
  7660. + struct clock_event_device *evdev = &per_cpu(clock_event, cpu);
  7661. + evdev->event_handler(evdev);
  7662. +}
  7663. +
  7664. +void __init init_clockevent(void)
  7665. +{
  7666. + int cpu = smp_processor_id();
  7667. + struct clock_event_device *ce = &per_cpu(clock_event, cpu);
  7668. +
  7669. + *ce = (struct clock_event_device){
  7670. + .name = "riscv_timer_clockevent",
  7671. + .features = CLOCK_EVT_FEAT_ONESHOT,
  7672. + .rating = 300,
  7673. + .cpumask = cpumask_of(cpu),
  7674. + .set_next_event = riscv_timer_set_next_event,
  7675. + .set_state_oneshot = riscv_timer_set_oneshot,
  7676. + .set_state_shutdown = riscv_timer_set_shutdown,
  7677. + };
  7678. +
  7679. + clockevents_config_and_register(ce, sbi_timebase(), 100, 0x7fffffff);
  7680. +}
  7681. +
  7682. +void __init time_init(void)
  7683. +{
  7684. + timebase = sbi_timebase();
  7685. + lpj_fine = timebase;
  7686. + do_div(lpj_fine, HZ);
  7687. +
  7688. + clocksource_register_hz(&riscv_clocksource, timebase);
  7689. + init_clockevent();
  7690. +
  7691. + /* Enable timer interrupts. */
  7692. + csr_set(sie, SIE_STIE);
  7693. +}
  7694. diff -Nur linux-4.6.2/arch/riscv/kernel/traps.c linux-4.6.2.riscv/arch/riscv/kernel/traps.c
  7695. --- linux-4.6.2/arch/riscv/kernel/traps.c 1970-01-01 01:00:00.000000000 +0100
  7696. +++ linux-4.6.2.riscv/arch/riscv/kernel/traps.c 2017-03-04 02:48:34.166888015 +0100
  7697. @@ -0,0 +1,146 @@
  7698. +#include <linux/kernel.h>
  7699. +#include <linux/init.h>
  7700. +#include <linux/sched.h>
  7701. +#include <linux/signal.h>
  7702. +#include <linux/kdebug.h>
  7703. +#include <linux/uaccess.h>
  7704. +#include <linux/mm.h>
  7705. +#include <linux/module.h>
  7706. +
  7707. +#include <asm/processor.h>
  7708. +#include <asm/ptrace.h>
  7709. +#include <asm/csr.h>
  7710. +
  7711. +int show_unhandled_signals = 1;
  7712. +
  7713. +extern asmlinkage void handle_exception(void);
  7714. +
  7715. +static DEFINE_SPINLOCK(die_lock);
  7716. +
  7717. +void die(struct pt_regs *regs, const char *str)
  7718. +{
  7719. + static int die_counter;
  7720. + int ret;
  7721. +
  7722. + oops_enter();
  7723. +
  7724. + spin_lock_irq(&die_lock);
  7725. + console_verbose();
  7726. + bust_spinlocks(1);
  7727. +
  7728. + pr_emerg("%s [#%d]\n", str, ++die_counter);
  7729. + print_modules();
  7730. + show_regs(regs);
  7731. +
  7732. + ret = notify_die(DIE_OOPS, str, regs, 0, regs->scause, SIGSEGV);
  7733. +
  7734. + bust_spinlocks(0);
  7735. + add_taint(TAINT_DIE, LOCKDEP_NOW_UNRELIABLE);
  7736. + spin_unlock_irq(&die_lock);
  7737. + oops_exit();
  7738. +
  7739. + if (in_interrupt())
  7740. + panic("Fatal exception in interrupt");
  7741. + if (panic_on_oops)
  7742. + panic("Fatal exception");
  7743. + if (ret != NOTIFY_STOP)
  7744. + do_exit(SIGSEGV);
  7745. +}
  7746. +
  7747. +static inline void do_trap_siginfo(int signo, int code,
  7748. + unsigned long addr, struct task_struct *tsk)
  7749. +{
  7750. + siginfo_t info;
  7751. +
  7752. + info.si_signo = signo;
  7753. + info.si_errno = 0;
  7754. + info.si_code = code;
  7755. + info.si_addr = (void __user *)addr;
  7756. + force_sig_info(signo, &info, tsk);
  7757. +}
  7758. +
  7759. +void do_trap(struct pt_regs *regs, int signo, int code,
  7760. + unsigned long addr, struct task_struct *tsk)
  7761. +{
  7762. + if (show_unhandled_signals && unhandled_signal(tsk, signo)
  7763. + && printk_ratelimit()) {
  7764. + pr_info("%s[%d]: unhandled signal %d code 0x%x at 0x" REG_FMT,
  7765. + tsk->comm, task_pid_nr(tsk), signo, code, addr);
  7766. + print_vma_addr(KERN_CONT " in ", GET_IP(regs));
  7767. + pr_cont("\n");
  7768. + show_regs(regs);
  7769. + }
  7770. +
  7771. + do_trap_siginfo(signo, code, addr, tsk);
  7772. +}
  7773. +
  7774. +static void do_trap_error(struct pt_regs *regs, int signo, int code,
  7775. + unsigned long addr, const char *str)
  7776. +{
  7777. + if (user_mode(regs)) {
  7778. + do_trap(regs, signo, code, addr, current);
  7779. + } else {
  7780. + if (!fixup_exception(regs))
  7781. + die(regs, str);
  7782. + }
  7783. +}
  7784. +
  7785. +#define DO_ERROR_INFO(name, signo, code, str) \
  7786. +asmlinkage void name(struct pt_regs *regs) \
  7787. +{ \
  7788. + do_trap_error(regs, signo, code, regs->sepc, "Oops - " str); \
  7789. +}
  7790. +
  7791. +DO_ERROR_INFO(do_trap_unknown,
  7792. + SIGILL, ILL_ILLTRP, "unknown exception");
  7793. +DO_ERROR_INFO(do_trap_amo_misaligned,
  7794. + SIGBUS, BUS_ADRALN, "AMO address misaligned");
  7795. +DO_ERROR_INFO(do_trap_insn_misaligned,
  7796. + SIGBUS, BUS_ADRALN, "instruction address misaligned");
  7797. +DO_ERROR_INFO(do_trap_insn_illegal,
  7798. + SIGILL, ILL_ILLOPC, "illegal instruction");
  7799. +
  7800. +asmlinkage void do_trap_break(struct pt_regs *regs)
  7801. +{
  7802. +#ifdef CONFIG_GENERIC_BUG
  7803. + if (!user_mode(regs)) {
  7804. + enum bug_trap_type type;
  7805. +
  7806. + type = report_bug(regs->sepc, regs);
  7807. + switch (type) {
  7808. + case BUG_TRAP_TYPE_NONE:
  7809. + break;
  7810. + case BUG_TRAP_TYPE_WARN:
  7811. + regs->sepc += sizeof(bug_insn_t);
  7812. + return;
  7813. + case BUG_TRAP_TYPE_BUG:
  7814. + die(regs, "Kernel BUG");
  7815. + }
  7816. + }
  7817. +#endif /* CONFIG_GENERIC_BUG */
  7818. +
  7819. + do_trap_siginfo(SIGTRAP, TRAP_BRKPT, regs->sepc, current);
  7820. + regs->sepc += 0x4;
  7821. +}
  7822. +
  7823. +#ifdef CONFIG_GENERIC_BUG
  7824. +int is_valid_bugaddr(unsigned long pc)
  7825. +{
  7826. + bug_insn_t insn;
  7827. +
  7828. + if (pc < PAGE_OFFSET)
  7829. + return 0;
  7830. + if (probe_kernel_address((bug_insn_t __user *)pc, insn))
  7831. + return 0;
  7832. + return (insn == __BUG_INSN);
  7833. +}
  7834. +#endif /* CONFIG_GENERIC_BUG */
  7835. +
  7836. +void __init trap_init(void)
  7837. +{
  7838. + /* Set sup0 scratch register to 0, indicating to exception vector
  7839. + that we are presently executing in the kernel */
  7840. + csr_write(sscratch, 0);
  7841. + /* Set the exception vector address */
  7842. + csr_write(stvec, &handle_exception);
  7843. +}
  7844. diff -Nur linux-4.6.2/arch/riscv/kernel/vdso/.gitignore linux-4.6.2.riscv/arch/riscv/kernel/vdso/.gitignore
  7845. --- linux-4.6.2/arch/riscv/kernel/vdso/.gitignore 1970-01-01 01:00:00.000000000 +0100
  7846. +++ linux-4.6.2.riscv/arch/riscv/kernel/vdso/.gitignore 2017-03-04 02:48:34.166888015 +0100
  7847. @@ -0,0 +1 @@
  7848. +vdso.lds
  7849. diff -Nur linux-4.6.2/arch/riscv/kernel/vdso/Makefile linux-4.6.2.riscv/arch/riscv/kernel/vdso/Makefile
  7850. --- linux-4.6.2/arch/riscv/kernel/vdso/Makefile 1970-01-01 01:00:00.000000000 +0100
  7851. +++ linux-4.6.2.riscv/arch/riscv/kernel/vdso/Makefile 2017-03-04 02:48:34.166888015 +0100
  7852. @@ -0,0 +1,61 @@
  7853. +# Derived from arch/{arm64,tile}/kernel/vdso/Makefile
  7854. +
  7855. +obj-vdso := sigreturn.o
  7856. +
  7857. +# Build rules
  7858. +targets := $(obj-vdso) vdso.so vdso.so.dbg
  7859. +obj-vdso := $(addprefix $(obj)/, $(obj-vdso))
  7860. +
  7861. +#ccflags-y := -shared -fno-common -fno-builtin
  7862. +#ccflags-y += -nostdlib -Wl,-soname=linux-vdso.so.1 \
  7863. + $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
  7864. +
  7865. +CFLAGS_vdso.so = $(c_flags)
  7866. +CFLAGS_vdso.so.dbg = -shared -s -Wl,-soname=linux-vdso.so.1 \
  7867. + $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
  7868. +CFLAGS_vdso_syms.o = -r
  7869. +
  7870. +obj-y += vdso.o
  7871. +
  7872. +# We also create a special relocatable object that should mirror the symbol
  7873. +# table and layout of the linked DSO. With ld -R we can then refer to
  7874. +# these symbols in the kernel code rather than hand-coded addresses.
  7875. +extra-y += vdso.lds vdso-syms.o
  7876. +$(obj)/built-in.o: $(obj)/vdso-syms.o
  7877. +$(obj)/built-in.o: ld_flags += -R $(obj)/vdso-syms.o
  7878. +
  7879. +CPPFLAGS_vdso.lds += -P -C -U$(ARCH)
  7880. +
  7881. +# Force dependency
  7882. +$(obj)/vdso.o : $(obj)/vdso.so
  7883. +
  7884. +# Link rule for the *.so file; *.lds must be first
  7885. +$(obj)/vdso.so.dbg: $(src)/vdso.lds $(obj-vdso)
  7886. + $(call if_changed,vdsold)
  7887. +$(obj)/vdso-syms.o: $(src)/vdso.lds $(obj-vdso)
  7888. + $(call if_changed,vdsold)
  7889. +
  7890. +# Strip rule for the *.so file
  7891. +$(obj)/%.so: OBJCOPYFLAGS := -S
  7892. +$(obj)/%.so: $(obj)/%.so.dbg FORCE
  7893. + $(call if_changed,objcopy)
  7894. +
  7895. +# Assembly rules for the *.S files
  7896. +$(obj-vdso): %.o: %.S
  7897. + $(call if_changed_dep,vdsoas)
  7898. +
  7899. +# Actual build commands
  7900. +quiet_cmd_vdsold = VDSOLD $@
  7901. + cmd_vdsold = $(CC) $(c_flags) -nostdlib $(CFLAGS_$(@F)) -Wl,-n -Wl,-T $^ -o $@
  7902. +quiet_cmd_vdsoas = VDSOAS $@
  7903. + cmd_vdsoas = $(CC) $(a_flags) -c -o $@ $<
  7904. +
  7905. +# Install commands for the unstripped file
  7906. +quiet_cmd_vdso_install = INSTALL $@
  7907. + cmd_vdso_install = cp $(obj)/$@.dbg $(MODLIB)/vdso/$@
  7908. +
  7909. +vdso.so: $(obj)/vdso.so.dbg
  7910. + @mkdir -p $(MODLIB)/vdso
  7911. + $(call cmd,vdso_install)
  7912. +
  7913. +vdso_install: vdso.so
  7914. diff -Nur linux-4.6.2/arch/riscv/kernel/vdso/sigreturn.S linux-4.6.2.riscv/arch/riscv/kernel/vdso/sigreturn.S
  7915. --- linux-4.6.2/arch/riscv/kernel/vdso/sigreturn.S 1970-01-01 01:00:00.000000000 +0100
  7916. +++ linux-4.6.2.riscv/arch/riscv/kernel/vdso/sigreturn.S 2017-03-04 02:48:34.166888015 +0100
  7917. @@ -0,0 +1,11 @@
  7918. +#include <linux/linkage.h>
  7919. +#include <asm/unistd.h>
  7920. +
  7921. + .text
  7922. +ENTRY(__vdso_rt_sigreturn)
  7923. + .cfi_startproc
  7924. + .cfi_signal_frame
  7925. + li a7, __NR_rt_sigreturn
  7926. + scall
  7927. + .cfi_endproc
  7928. +ENDPROC(__vdso_rt_sigreturn)
  7929. diff -Nur linux-4.6.2/arch/riscv/kernel/vdso/vdso.lds.S linux-4.6.2.riscv/arch/riscv/kernel/vdso/vdso.lds.S
  7930. --- linux-4.6.2/arch/riscv/kernel/vdso/vdso.lds.S 1970-01-01 01:00:00.000000000 +0100
  7931. +++ linux-4.6.2.riscv/arch/riscv/kernel/vdso/vdso.lds.S 2017-03-04 02:48:34.166888015 +0100
  7932. @@ -0,0 +1,63 @@
  7933. +OUTPUT_ARCH(riscv)
  7934. +
  7935. +SECTIONS
  7936. +{
  7937. + . = SIZEOF_HEADERS;
  7938. +
  7939. + .hash : { *(.hash) } :text
  7940. + .gnu.hash : { *(.gnu.hash) }
  7941. + .dynsym : { *(.dynsym) }
  7942. + .dynstr : { *(.dynstr) }
  7943. + .gnu.version : { *(.gnu.version) }
  7944. + .gnu.version_d : { *(.gnu.version_d) }
  7945. + .gnu.version_r : { *(.gnu.version_r) }
  7946. +
  7947. + .note : { *(.note.*) } :text :note
  7948. + .dynamic : { *(.dynamic) } :text :dynamic
  7949. +
  7950. + .eh_frame_hdr : { *(.eh_frame_hdr) } :text :eh_frame_hdr
  7951. + .eh_frame : { KEEP (*(.eh_frame)) } :text
  7952. +
  7953. + .rodata : { *(.rodata .rodata.* .gnu.linkonce.r.*) }
  7954. +
  7955. + /*
  7956. + * This linker script is used both with -r and with -shared.
  7957. + * For the layouts to match, we need to skip more than enough
  7958. + * space for the dynamic symbol table, etc. If this amount is
  7959. + * insufficient, ld -shared will error; simply increase it here.
  7960. + */
  7961. + . = 0x800;
  7962. + .text : { *(.text .text.*) } :text
  7963. +
  7964. + .data : {
  7965. + *(.got.plt) *(.got)
  7966. + *(.data .data.* .gnu.linkonce.d.*)
  7967. + *(.dynbss)
  7968. + *(.bss .bss.* .gnu.linkonce.b.*)
  7969. + }
  7970. +}
  7971. +
  7972. +/*
  7973. + * We must supply the ELF program headers explicitly to get just one
  7974. + * PT_LOAD segment, and set the flags explicitly to make segments read-only.
  7975. + */
  7976. +PHDRS
  7977. +{
  7978. + text PT_LOAD FLAGS(5) FILEHDR PHDRS; /* PF_R|PF_X */
  7979. + dynamic PT_DYNAMIC FLAGS(4); /* PF_R */
  7980. + note PT_NOTE FLAGS(4); /* PF_R */
  7981. + eh_frame_hdr PT_GNU_EH_FRAME;
  7982. +}
  7983. +
  7984. +/*
  7985. + * This controls what symbols we export from the DSO.
  7986. + */
  7987. +VERSION
  7988. +{
  7989. + LINUX_2.6 {
  7990. + global:
  7991. + __vdso_rt_sigreturn;
  7992. + local: *;
  7993. + };
  7994. +}
  7995. +
  7996. diff -Nur linux-4.6.2/arch/riscv/kernel/vdso/vdso.S linux-4.6.2.riscv/arch/riscv/kernel/vdso/vdso.S
  7997. --- linux-4.6.2/arch/riscv/kernel/vdso/vdso.S 1970-01-01 01:00:00.000000000 +0100
  7998. +++ linux-4.6.2.riscv/arch/riscv/kernel/vdso/vdso.S 2017-03-04 02:48:34.166888015 +0100
  7999. @@ -0,0 +1,14 @@
  8000. +#include <linux/init.h>
  8001. +#include <linux/linkage.h>
  8002. +#include <asm/page.h>
  8003. +
  8004. + __PAGE_ALIGNED_DATA
  8005. +
  8006. + .globl vdso_start, vdso_end
  8007. + .balign PAGE_SIZE
  8008. +vdso_start:
  8009. + .incbin "arch/riscv/kernel/vdso/vdso.so"
  8010. + .balign PAGE_SIZE
  8011. +vdso_end:
  8012. +
  8013. + .previous
  8014. diff -Nur linux-4.6.2/arch/riscv/kernel/vdso.c linux-4.6.2.riscv/arch/riscv/kernel/vdso.c
  8015. --- linux-4.6.2/arch/riscv/kernel/vdso.c 1970-01-01 01:00:00.000000000 +0100
  8016. +++ linux-4.6.2.riscv/arch/riscv/kernel/vdso.c 2017-03-04 02:48:34.166888015 +0100
  8017. @@ -0,0 +1,106 @@
  8018. +#include <linux/mm.h>
  8019. +#include <linux/slab.h>
  8020. +#include <linux/binfmts.h>
  8021. +#include <linux/err.h>
  8022. +
  8023. +#include <asm/vdso.h>
  8024. +
  8025. +extern char vdso_start[], vdso_end[];
  8026. +
  8027. +static unsigned int vdso_pages;
  8028. +static struct page **vdso_pagelist;
  8029. +
  8030. +/*
  8031. + * The vDSO data page.
  8032. + */
  8033. +static union {
  8034. + struct vdso_data data;
  8035. + u8 page[PAGE_SIZE];
  8036. +} vdso_data_store __page_aligned_data;
  8037. +struct vdso_data *vdso_data = &vdso_data_store.data;
  8038. +
  8039. +static int __init vdso_init(void)
  8040. +{
  8041. + unsigned int i;
  8042. +
  8043. + vdso_pages = (vdso_end - vdso_start) >> PAGE_SHIFT;
  8044. + vdso_pagelist = kzalloc(sizeof(struct page *) * (vdso_pages + 1), GFP_KERNEL);
  8045. + if (unlikely(vdso_pagelist == NULL)) {
  8046. + pr_err("vdso: pagelist allocation failed\n");
  8047. + return -ENOMEM;
  8048. + }
  8049. +
  8050. + for (i = 0; i < vdso_pages; i++) {
  8051. + struct page *pg;
  8052. + pg = virt_to_page(vdso_start + (i << PAGE_SHIFT));
  8053. + ClearPageReserved(pg);
  8054. + vdso_pagelist[i] = pg;
  8055. + }
  8056. + vdso_pagelist[i] = virt_to_page(vdso_data);
  8057. +
  8058. + return 0;
  8059. +}
  8060. +arch_initcall(vdso_init);
  8061. +
  8062. +int arch_setup_additional_pages(struct linux_binprm *bprm,
  8063. + int uses_interp)
  8064. +{
  8065. + struct mm_struct *mm = current->mm;
  8066. + unsigned long vdso_base, vdso_len;
  8067. + int ret;
  8068. +
  8069. + vdso_len = (vdso_pages + 1) << PAGE_SHIFT;
  8070. +
  8071. + down_write(&mm->mmap_sem);
  8072. + vdso_base = get_unmapped_area(NULL, 0, vdso_len, 0, 0);
  8073. + if (unlikely(IS_ERR_VALUE(vdso_base))) {
  8074. + ret = vdso_base;
  8075. + goto end;
  8076. + }
  8077. +
  8078. + /*
  8079. + * Put vDSO base into mm struct. We need to do this before calling
  8080. + * install_special_mapping or the perf counter mmap tracking code
  8081. + * will fail to recognise it as a vDSO (since arch_vma_name fails).
  8082. + */
  8083. + mm->context.vdso = (void *)vdso_base;
  8084. +
  8085. + ret = install_special_mapping(mm, vdso_base, vdso_len,
  8086. + (VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC),
  8087. + vdso_pagelist);
  8088. +
  8089. + if (unlikely(ret)) {
  8090. + mm->context.vdso = NULL;
  8091. + }
  8092. +
  8093. +end:
  8094. + up_write(&mm->mmap_sem);
  8095. + return ret;
  8096. +}
  8097. +
  8098. +const char *arch_vma_name(struct vm_area_struct *vma)
  8099. +{
  8100. + if (vma->vm_mm && (vma->vm_start == (long)vma->vm_mm->context.vdso)) {
  8101. + return "[vdso]";
  8102. + }
  8103. + return NULL;
  8104. +}
  8105. +
  8106. +/*
  8107. + * Function stubs to prevent linker errors when AT_SYSINFO_EHDR is defined
  8108. + */
  8109. +
  8110. +int in_gate_area_no_mm(unsigned long addr)
  8111. +{
  8112. + return 0;
  8113. +}
  8114. +
  8115. +int in_gate_area(struct mm_struct *mm, unsigned long addr)
  8116. +{
  8117. + return 0;
  8118. +}
  8119. +
  8120. +struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
  8121. +{
  8122. + return NULL;
  8123. +}
  8124. diff -Nur linux-4.6.2/arch/riscv/kernel/vmlinux.lds.S linux-4.6.2.riscv/arch/riscv/kernel/vmlinux.lds.S
  8125. --- linux-4.6.2/arch/riscv/kernel/vmlinux.lds.S 1970-01-01 01:00:00.000000000 +0100
  8126. +++ linux-4.6.2.riscv/arch/riscv/kernel/vmlinux.lds.S 2017-03-04 02:48:34.166888015 +0100
  8127. @@ -0,0 +1,75 @@
  8128. +#define LOAD_OFFSET PAGE_OFFSET
  8129. +#include <asm/vmlinux.lds.h>
  8130. +#include <asm/page.h>
  8131. +#include <asm/cache.h>
  8132. +#include <asm/thread_info.h>
  8133. +
  8134. +OUTPUT_ARCH(riscv)
  8135. +ENTRY(_start)
  8136. +
  8137. +jiffies = jiffies_64;
  8138. +
  8139. +SECTIONS
  8140. +{
  8141. + /* Beginning of code and text segment */
  8142. + . = LOAD_OFFSET;
  8143. + _start = .;
  8144. + __init_begin = .;
  8145. + HEAD_TEXT_SECTION
  8146. + INIT_TEXT_SECTION(PAGE_SIZE)
  8147. + INIT_DATA_SECTION(16)
  8148. + /* we have to discard exit text and such at runtime, not link time */
  8149. + .exit.text :
  8150. + {
  8151. + EXIT_TEXT
  8152. + }
  8153. + .exit.data :
  8154. + {
  8155. + EXIT_DATA
  8156. + }
  8157. + PERCPU_SECTION(L1_CACHE_BYTES)
  8158. + __init_end = .;
  8159. +
  8160. + .text : {
  8161. + _text = .;
  8162. + _stext = .;
  8163. + TEXT_TEXT
  8164. + SCHED_TEXT
  8165. + LOCK_TEXT
  8166. + KPROBES_TEXT
  8167. + ENTRY_TEXT
  8168. + IRQENTRY_TEXT
  8169. + *(.fixup)
  8170. + _etext = .;
  8171. + }
  8172. +
  8173. + /* Start of data section */
  8174. + _sdata = .;
  8175. + RO_DATA_SECTION(PAGE_SIZE)
  8176. + RW_DATA_SECTION(0x40, PAGE_SIZE, THREAD_SIZE)
  8177. + .sdata : {
  8178. + _gp = . + 0x800;
  8179. + *(.sdata*)
  8180. + }
  8181. + .srodata : {
  8182. + *(.srodata*)
  8183. + }
  8184. + /* End of data section */
  8185. + _edata = .;
  8186. +
  8187. + BSS_SECTION(0x20, 0, 0x20)
  8188. +
  8189. + EXCEPTION_TABLE(0x10)
  8190. + NOTES
  8191. +
  8192. + .rel.dyn : {
  8193. + *(.rel.dyn*)
  8194. + }
  8195. +
  8196. + _end = .;
  8197. +
  8198. + STABS_DEBUG
  8199. + DWARF_DEBUG
  8200. +
  8201. + DISCARDS
  8202. +}
  8203. diff -Nur linux-4.6.2/arch/riscv/lib/ashldi3.c linux-4.6.2.riscv/arch/riscv/lib/ashldi3.c
  8204. --- linux-4.6.2/arch/riscv/lib/ashldi3.c 1970-01-01 01:00:00.000000000 +0100
  8205. +++ linux-4.6.2.riscv/arch/riscv/lib/ashldi3.c 2017-03-04 02:48:34.166888015 +0100
  8206. @@ -0,0 +1,28 @@
  8207. +#include <linux/export.h>
  8208. +
  8209. +#include "libgcc.h"
  8210. +
  8211. +long long __ashldi3(long long u, word_type b)
  8212. +{
  8213. + DWunion uu, w;
  8214. + word_type bm;
  8215. +
  8216. + if (b == 0)
  8217. + return u;
  8218. +
  8219. + uu.ll = u;
  8220. + bm = 32 - b;
  8221. +
  8222. + if (bm <= 0) {
  8223. + w.s.low = 0;
  8224. + w.s.high = (unsigned int) uu.s.low << -bm;
  8225. + } else {
  8226. + const unsigned int carries = (unsigned int) uu.s.low >> bm;
  8227. +
  8228. + w.s.low = (unsigned int) uu.s.low << b;
  8229. + w.s.high = ((unsigned int) uu.s.high << b) | carries;
  8230. + }
  8231. +
  8232. + return w.ll;
  8233. +}
  8234. +EXPORT_SYMBOL(__ashldi3);
  8235. diff -Nur linux-4.6.2/arch/riscv/lib/ashrdi3.c linux-4.6.2.riscv/arch/riscv/lib/ashrdi3.c
  8236. --- linux-4.6.2/arch/riscv/lib/ashrdi3.c 1970-01-01 01:00:00.000000000 +0100
  8237. +++ linux-4.6.2.riscv/arch/riscv/lib/ashrdi3.c 2017-03-04 02:48:34.166888015 +0100
  8238. @@ -0,0 +1,30 @@
  8239. +#include <linux/export.h>
  8240. +
  8241. +#include "libgcc.h"
  8242. +
  8243. +long long __ashrdi3(long long u, word_type b)
  8244. +{
  8245. + DWunion uu, w;
  8246. + word_type bm;
  8247. +
  8248. + if (b == 0)
  8249. + return u;
  8250. +
  8251. + uu.ll = u;
  8252. + bm = 32 - b;
  8253. +
  8254. + if (bm <= 0) {
  8255. + /* w.s.high = 1..1 or 0..0 */
  8256. + w.s.high =
  8257. + uu.s.high >> 31;
  8258. + w.s.low = uu.s.high >> -bm;
  8259. + } else {
  8260. + const unsigned int carries = (unsigned int) uu.s.high << bm;
  8261. +
  8262. + w.s.high = uu.s.high >> b;
  8263. + w.s.low = ((unsigned int) uu.s.low >> b) | carries;
  8264. + }
  8265. +
  8266. + return w.ll;
  8267. +}
  8268. +EXPORT_SYMBOL(__ashrdi3);
  8269. diff -Nur linux-4.6.2/arch/riscv/lib/delay.c linux-4.6.2.riscv/arch/riscv/lib/delay.c
  8270. --- linux-4.6.2/arch/riscv/lib/delay.c 1970-01-01 01:00:00.000000000 +0100
  8271. +++ linux-4.6.2.riscv/arch/riscv/lib/delay.c 2017-03-04 02:48:34.166888015 +0100
  8272. @@ -0,0 +1,24 @@
  8273. +#include <linux/delay.h>
  8274. +#include <linux/param.h>
  8275. +#include <linux/timex.h>
  8276. +#include <linux/export.h>
  8277. +
  8278. +void __delay(unsigned long cycles)
  8279. +{
  8280. + cycle_t t0 = get_cycles();
  8281. + while ((unsigned long)(get_cycles() - t0) < cycles)
  8282. + cpu_relax();
  8283. +}
  8284. +
  8285. +void udelay(unsigned long usecs)
  8286. +{
  8287. + __delay((unsigned long)(((u64)usecs * timebase) / 1000000UL));
  8288. +
  8289. +}
  8290. +EXPORT_SYMBOL(udelay);
  8291. +
  8292. +void ndelay(unsigned long nsecs)
  8293. +{
  8294. + __delay((unsigned long)(((u64)nsecs * timebase) / 1000000000UL));
  8295. +}
  8296. +EXPORT_SYMBOL(ndelay);
  8297. diff -Nur linux-4.6.2/arch/riscv/lib/libgcc.h linux-4.6.2.riscv/arch/riscv/lib/libgcc.h
  8298. --- linux-4.6.2/arch/riscv/lib/libgcc.h 1970-01-01 01:00:00.000000000 +0100
  8299. +++ linux-4.6.2.riscv/arch/riscv/lib/libgcc.h 2017-03-04 02:48:34.170888098 +0100
  8300. @@ -0,0 +1,32 @@
  8301. +#ifndef __ASM_LIBGCC_H
  8302. +#define __ASM_LIBGCC_H
  8303. +
  8304. +#include <asm/byteorder.h>
  8305. +
  8306. +typedef int word_type __attribute__ ((mode (__word__)));
  8307. +
  8308. +#ifdef __BIG_ENDIAN
  8309. +struct DWstruct {
  8310. + int high, low;
  8311. +};
  8312. +#elif defined(__LITTLE_ENDIAN)
  8313. +struct DWstruct {
  8314. + int low, high;
  8315. +};
  8316. +#else
  8317. +#error I feel sick.
  8318. +#endif
  8319. +
  8320. +typedef union {
  8321. + struct DWstruct s;
  8322. + long long ll;
  8323. +} DWunion;
  8324. +
  8325. +extern long long __ashldi3(long long u, word_type b);
  8326. +extern long long __ashrdi3(long long u, word_type b);
  8327. +extern word_type __cmpdi2(long long a, long long b);
  8328. +extern long long __lshrdi3(long long u, word_type b);
  8329. +extern long long __muldi3(long long u, long long v);
  8330. +extern word_type __ucmpdi2(unsigned long long a, unsigned long long b);
  8331. +
  8332. +#endif /* __ASM_LIBGCC_H */
  8333. diff -Nur linux-4.6.2/arch/riscv/lib/lshrdi3.c linux-4.6.2.riscv/arch/riscv/lib/lshrdi3.c
  8334. --- linux-4.6.2/arch/riscv/lib/lshrdi3.c 1970-01-01 01:00:00.000000000 +0100
  8335. +++ linux-4.6.2.riscv/arch/riscv/lib/lshrdi3.c 2017-03-04 02:48:34.170888098 +0100
  8336. @@ -0,0 +1,28 @@
  8337. +#include <linux/export.h>
  8338. +
  8339. +#include "libgcc.h"
  8340. +
  8341. +long long __lshrdi3(long long u, word_type b)
  8342. +{
  8343. + DWunion uu, w;
  8344. + word_type bm;
  8345. +
  8346. + if (b == 0)
  8347. + return u;
  8348. +
  8349. + uu.ll = u;
  8350. + bm = 32 - b;
  8351. +
  8352. + if (bm <= 0) {
  8353. + w.s.high = 0;
  8354. + w.s.low = (unsigned int) uu.s.high >> -bm;
  8355. + } else {
  8356. + const unsigned int carries = (unsigned int) uu.s.high << bm;
  8357. +
  8358. + w.s.high = (unsigned int) uu.s.high >> b;
  8359. + w.s.low = ((unsigned int) uu.s.low >> b) | carries;
  8360. + }
  8361. +
  8362. + return w.ll;
  8363. +}
  8364. +EXPORT_SYMBOL(__lshrdi3);
  8365. diff -Nur linux-4.6.2/arch/riscv/lib/Makefile linux-4.6.2.riscv/arch/riscv/lib/Makefile
  8366. --- linux-4.6.2/arch/riscv/lib/Makefile 1970-01-01 01:00:00.000000000 +0100
  8367. +++ linux-4.6.2.riscv/arch/riscv/lib/Makefile 2017-03-04 02:48:34.166888015 +0100
  8368. @@ -0,0 +1,5 @@
  8369. +lib-y := delay.o memcpy.o memset.o uaccess.o
  8370. +
  8371. +ifeq ($(CONFIG_64BIT),)
  8372. +lib-y += ashldi3.o ashrdi3.o lshrdi3.o
  8373. +endif
  8374. diff -Nur linux-4.6.2/arch/riscv/lib/memcpy.S linux-4.6.2.riscv/arch/riscv/lib/memcpy.S
  8375. --- linux-4.6.2/arch/riscv/lib/memcpy.S 1970-01-01 01:00:00.000000000 +0100
  8376. +++ linux-4.6.2.riscv/arch/riscv/lib/memcpy.S 2017-03-04 02:48:34.170888098 +0100
  8377. @@ -0,0 +1,85 @@
  8378. +#include <linux/linkage.h>
  8379. +#include <asm/asm.h>
  8380. +
  8381. +/* void *memcpy(void *, const void *, size_t) */
  8382. +ENTRY(memcpy)
  8383. + move t6, a0 /* Preserve return value */
  8384. +
  8385. + /* Defer to byte-oriented copy for small sizes */
  8386. + sltiu a3, a2, 128
  8387. + bnez a3, 4f
  8388. + /* Use word-oriented copy only if low-order bits match */
  8389. + andi a3, t6, SZREG-1
  8390. + andi a4, a1, SZREG-1
  8391. + bne a3, a4, 4f
  8392. +
  8393. + beqz a3, 2f /* Skip if already aligned */
  8394. + /* Round to nearest double word-aligned address
  8395. + greater than or equal to start address */
  8396. + andi a3, a1, ~(SZREG-1)
  8397. + addi a3, a3, SZREG
  8398. + /* Handle initial misalignment */
  8399. + sub a4, a3, a1
  8400. +1:
  8401. + lb a5, 0(a1)
  8402. + addi a1, a1, 1
  8403. + sb a5, 0(t6)
  8404. + addi t6, t6, 1
  8405. + bltu a1, a3, 1b
  8406. + sub a2, a2, a4 /* Update count */
  8407. +
  8408. +2:
  8409. + andi a4, a2, ~((16*SZREG)-1)
  8410. + beqz a4, 4f
  8411. + add a3, a1, a4
  8412. +3:
  8413. + REG_L a4, 0(a1)
  8414. + REG_L a5, SZREG(a1)
  8415. + REG_L a6, 2*SZREG(a1)
  8416. + REG_L a7, 3*SZREG(a1)
  8417. + REG_L t0, 4*SZREG(a1)
  8418. + REG_L t1, 5*SZREG(a1)
  8419. + REG_L t2, 6*SZREG(a1)
  8420. + REG_L t3, 7*SZREG(a1)
  8421. + REG_L t4, 8*SZREG(a1)
  8422. + REG_L t5, 9*SZREG(a1)
  8423. + REG_S a4, 0(t6)
  8424. + REG_S a5, SZREG(t6)
  8425. + REG_S a6, 2*SZREG(t6)
  8426. + REG_S a7, 3*SZREG(t6)
  8427. + REG_S t0, 4*SZREG(t6)
  8428. + REG_S t1, 5*SZREG(t6)
  8429. + REG_S t2, 6*SZREG(t6)
  8430. + REG_S t3, 7*SZREG(t6)
  8431. + REG_S t4, 8*SZREG(t6)
  8432. + REG_S t5, 9*SZREG(t6)
  8433. + REG_L a4, 10*SZREG(a1)
  8434. + REG_L a5, 11*SZREG(a1)
  8435. + REG_L a6, 12*SZREG(a1)
  8436. + REG_L a7, 13*SZREG(a1)
  8437. + REG_L t0, 14*SZREG(a1)
  8438. + REG_L t1, 15*SZREG(a1)
  8439. + addi a1, a1, 16*SZREG
  8440. + REG_S a4, 10*SZREG(t6)
  8441. + REG_S a5, 11*SZREG(t6)
  8442. + REG_S a6, 12*SZREG(t6)
  8443. + REG_S a7, 13*SZREG(t6)
  8444. + REG_S t0, 14*SZREG(t6)
  8445. + REG_S t1, 15*SZREG(t6)
  8446. + addi t6, t6, 16*SZREG
  8447. + bltu a1, a3, 3b
  8448. + andi a2, a2, (16*SZREG)-1 /* Update count */
  8449. +
  8450. +4:
  8451. + /* Handle trailing misalignment */
  8452. + beqz a2, 6f
  8453. + add a3, a1, a2
  8454. +5:
  8455. + lb a4, 0(a1)
  8456. + addi a1, a1, 1
  8457. + sb a4, 0(t6)
  8458. + addi t6, t6, 1
  8459. + bltu a1, a3, 5b
  8460. +6:
  8461. + ret
  8462. +END(memcpy)
  8463. diff -Nur linux-4.6.2/arch/riscv/lib/memset.S linux-4.6.2.riscv/arch/riscv/lib/memset.S
  8464. --- linux-4.6.2/arch/riscv/lib/memset.S 1970-01-01 01:00:00.000000000 +0100
  8465. +++ linux-4.6.2.riscv/arch/riscv/lib/memset.S 2017-03-04 02:48:34.170888098 +0100
  8466. @@ -0,0 +1,104 @@
  8467. +#include <linux/linkage.h>
  8468. +#include <asm/asm.h>
  8469. +
  8470. +/* void *memset(void *, int, size_t) */
  8471. +ENTRY(memset)
  8472. + move t0, a0 /* Preserve return value */
  8473. +
  8474. + /* Defer to byte-oriented fill for small sizes */
  8475. + sltiu a3, a2, 16
  8476. + bnez a3, 4f
  8477. +
  8478. + /* Round to nearest XLEN-aligned address
  8479. + greater than or equal to start address */
  8480. + addi a3, t0, SZREG-1
  8481. + andi a3, a3, ~(SZREG-1)
  8482. + beq a3, t0, 2f /* Skip if already aligned */
  8483. + /* Handle initial misalignment */
  8484. + sub a4, a3, t0
  8485. +1:
  8486. + sb a1, 0(t0)
  8487. + addi t0, t0, 1
  8488. + bltu t0, a3, 1b
  8489. + sub a2, a2, a4 /* Update count */
  8490. +
  8491. +2: /* Duff's device with 32 XLEN stores per iteration */
  8492. + /* Broadcast value into all bytes */
  8493. + andi a1, a1, 0xff
  8494. + slli a3, a1, 8
  8495. + or a1, a3, a1
  8496. + slli a3, a1, 16
  8497. + or a1, a3, a1
  8498. +#ifdef CONFIG_64BIT
  8499. + slli a3, a1, 32
  8500. + or a1, a3, a1
  8501. +#endif
  8502. +
  8503. + /* Calculate end address */
  8504. + andi a4, a2, ~(SZREG-1)
  8505. + add a3, t0, a4
  8506. +
  8507. + andi a4, a4, 31*SZREG /* Calculate remainder */
  8508. + beqz a4, 3f /* Shortcut if no remainder */
  8509. + neg a4, a4
  8510. + addi a4, a4, 32*SZREG /* Calculate initial offset */
  8511. +
  8512. + /* Adjust start address with offset */
  8513. + sub t0, t0, a4
  8514. +
  8515. + /* Jump into loop body */
  8516. + /* Assumes 32-bit instruction lengths */
  8517. + la a5, 3f
  8518. +#ifdef CONFIG_64BIT
  8519. + srli a4, a4, 1
  8520. +#endif
  8521. + add a5, a5, a4
  8522. + jr a5
  8523. +3:
  8524. + REG_S a1, 0(t0)
  8525. + REG_S a1, SZREG(t0)
  8526. + REG_S a1, 2*SZREG(t0)
  8527. + REG_S a1, 3*SZREG(t0)
  8528. + REG_S a1, 4*SZREG(t0)
  8529. + REG_S a1, 5*SZREG(t0)
  8530. + REG_S a1, 6*SZREG(t0)
  8531. + REG_S a1, 7*SZREG(t0)
  8532. + REG_S a1, 8*SZREG(t0)
  8533. + REG_S a1, 9*SZREG(t0)
  8534. + REG_S a1, 10*SZREG(t0)
  8535. + REG_S a1, 11*SZREG(t0)
  8536. + REG_S a1, 12*SZREG(t0)
  8537. + REG_S a1, 13*SZREG(t0)
  8538. + REG_S a1, 14*SZREG(t0)
  8539. + REG_S a1, 15*SZREG(t0)
  8540. + REG_S a1, 16*SZREG(t0)
  8541. + REG_S a1, 17*SZREG(t0)
  8542. + REG_S a1, 18*SZREG(t0)
  8543. + REG_S a1, 19*SZREG(t0)
  8544. + REG_S a1, 20*SZREG(t0)
  8545. + REG_S a1, 21*SZREG(t0)
  8546. + REG_S a1, 22*SZREG(t0)
  8547. + REG_S a1, 23*SZREG(t0)
  8548. + REG_S a1, 24*SZREG(t0)
  8549. + REG_S a1, 25*SZREG(t0)
  8550. + REG_S a1, 26*SZREG(t0)
  8551. + REG_S a1, 27*SZREG(t0)
  8552. + REG_S a1, 28*SZREG(t0)
  8553. + REG_S a1, 29*SZREG(t0)
  8554. + REG_S a1, 30*SZREG(t0)
  8555. + REG_S a1, 31*SZREG(t0)
  8556. + addi t0, t0, 32*SZREG
  8557. + bltu t0, a3, 3b
  8558. + andi a2, a2, SZREG-1 /* Update count */
  8559. +
  8560. +4:
  8561. + /* Handle trailing misalignment */
  8562. + beqz a2, 6f
  8563. + add a3, t0, a2
  8564. +5:
  8565. + sb a1, 0(t0)
  8566. + addi t0, t0, 1
  8567. + bltu t0, a3, 5b
  8568. +6:
  8569. + ret
  8570. +END(memset)
  8571. diff -Nur linux-4.6.2/arch/riscv/lib/uaccess.S linux-4.6.2.riscv/arch/riscv/lib/uaccess.S
  8572. --- linux-4.6.2/arch/riscv/lib/uaccess.S 1970-01-01 01:00:00.000000000 +0100
  8573. +++ linux-4.6.2.riscv/arch/riscv/lib/uaccess.S 2017-03-04 02:48:34.170888098 +0100
  8574. @@ -0,0 +1,125 @@
  8575. +#include <linux/linkage.h>
  8576. +#include <asm/asm.h>
  8577. +#include <asm/csr.h>
  8578. +
  8579. + .altmacro
  8580. + .macro fixup op reg addr lbl
  8581. + LOCAL _epc
  8582. +_epc:
  8583. + \op \reg, \addr
  8584. + .section __ex_table,"a"
  8585. + .balign SZPTR
  8586. + PTR _epc, \lbl
  8587. + .previous
  8588. + .endm
  8589. +
  8590. +ENTRY(__copy_user)
  8591. +
  8592. +#ifdef CONFIG_RV_PUM
  8593. + /* Enable access to user memory */
  8594. + li t6, SR_PUM
  8595. + csrc sstatus, t6
  8596. +#endif
  8597. +
  8598. + add a3, a1, a2
  8599. + /* Use word-oriented copy only if low-order bits match */
  8600. + andi t0, a0, SZREG-1
  8601. + andi t1, a1, SZREG-1
  8602. + bne t0, t1, 2f
  8603. +
  8604. + addi t0, a1, SZREG-1
  8605. + andi t1, a3, ~(SZREG-1)
  8606. + andi t0, t0, ~(SZREG-1)
  8607. + /* a3: terminal address of source region
  8608. + * t0: lowest XLEN-aligned address in source
  8609. + * t1: highest XLEN-aligned address in source
  8610. + */
  8611. + bgeu t0, t1, 2f
  8612. + bltu a1, t0, 4f
  8613. +1:
  8614. + fixup REG_L, t2, (a1), 10f
  8615. + fixup REG_S, t2, (a0), 10f
  8616. + addi a1, a1, SZREG
  8617. + addi a0, a0, SZREG
  8618. + bltu a1, t1, 1b
  8619. +2:
  8620. + bltu a1, a3, 5f
  8621. +
  8622. +3:
  8623. +#ifdef CONFIG_RV_PUM
  8624. + /* Disable access to user memory */
  8625. + csrs sstatus, t6
  8626. +#endif
  8627. + li a0, 0
  8628. + ret
  8629. +4: /* Edge case: unalignment */
  8630. + fixup lbu, t2, (a1), 10f
  8631. + fixup sb, t2, (a0), 10f
  8632. + addi a1, a1, 1
  8633. + addi a0, a0, 1
  8634. + bltu a1, t0, 4b
  8635. + j 1b
  8636. +5: /* Edge case: remainder */
  8637. + fixup lbu, t2, (a1), 10f
  8638. + fixup sb, t2, (a0), 10f
  8639. + addi a1, a1, 1
  8640. + addi a0, a0, 1
  8641. + bltu a1, a3, 5b
  8642. + j 3b
  8643. +ENDPROC(__copy_user)
  8644. +
  8645. +
  8646. +ENTRY(__clear_user)
  8647. +
  8648. +#ifdef CONFIG_RV_PUM
  8649. + /* Enable access to user memory */
  8650. + li t6, SR_PUM
  8651. + csrc sstatus, t6
  8652. +#endif
  8653. +
  8654. + add a3, a0, a1
  8655. + addi t0, a0, SZREG-1
  8656. + andi t1, a3, ~(SZREG-1)
  8657. + andi t0, t0, ~(SZREG-1)
  8658. + /* a3: terminal address of target region
  8659. + * t0: lowest doubleword-aligned address in target region
  8660. + * t1: highest doubleword-aligned address in target region
  8661. + */
  8662. + bgeu t0, t1, 2f
  8663. + bltu a0, t0, 4f
  8664. +1:
  8665. + fixup REG_S, zero, (a0), 10f
  8666. + addi a0, a0, SZREG
  8667. + bltu a0, t1, 1b
  8668. +2:
  8669. + bltu a0, a3, 5f
  8670. +
  8671. +3:
  8672. +#ifdef CONFIG_RV_PUM
  8673. + /* Disable access to user memory */
  8674. + csrs sstatus, t6
  8675. +#endif
  8676. + li a0, 0
  8677. + ret
  8678. +4: /* Edge case: unalignment */
  8679. + fixup sb, zero, (a0), 10f
  8680. + addi a0, a0, 1
  8681. + bltu a0, t0, 4b
  8682. + j 1b
  8683. +5: /* Edge case: remainder */
  8684. + fixup sb, zero, (a0), 10f
  8685. + addi a0, a0, 1
  8686. + bltu a0, a3, 5b
  8687. + j 3b
  8688. +ENDPROC(__clear_user)
  8689. +
  8690. + .section .fixup,"ax"
  8691. + .balign 4
  8692. +10:
  8693. +#ifdef CONFIG_RV_PUM
  8694. + /* Disable access to user memory */
  8695. + csrs sstatus, t6
  8696. +#endif
  8697. + sub a0, a3, a0
  8698. + ret
  8699. + .previous
  8700. diff -Nur linux-4.6.2/arch/riscv/Makefile linux-4.6.2.riscv/arch/riscv/Makefile
  8701. --- linux-4.6.2/arch/riscv/Makefile 1970-01-01 01:00:00.000000000 +0100
  8702. +++ linux-4.6.2.riscv/arch/riscv/Makefile 2017-03-04 02:48:34.162887952 +0100
  8703. @@ -0,0 +1,70 @@
  8704. +# BK Id: %F% %I% %G% %U% %#%
  8705. +#
  8706. +# This file is included by the global makefile so that you can add your own
  8707. +# architecture-specific flags and dependencies. Remember to do have actions
  8708. +# for "archclean" and "archdep" for cleaning up and making dependencies for
  8709. +# this architecture
  8710. +#
  8711. +# This file is subject to the terms and conditions of the GNU General Public
  8712. +# License. See the file "COPYING" in the main directory of this archive
  8713. +# for more details.
  8714. +#
  8715. +# Copyright (C) 1994 by Linus Torvalds
  8716. +# Modifications for the RISC-V architecture:
  8717. +# Quan Nguyen <quannguyen@eecs.berkeley.edu>
  8718. +# Albert Ou <a_ou@eecs.berkeley.edu>
  8719. +#
  8720. +# Based on:
  8721. +# arch/score/Makefile
  8722. +
  8723. +LDFLAGS :=
  8724. +OBJCOPYFLAGS := -O binary
  8725. +LDFLAGS_vmlinux :=
  8726. +
  8727. +ifeq ($(ARCH),riscv)
  8728. + KBUILD_DEFCONFIG = riscv64_spike
  8729. +else
  8730. + KBUILD_DEFCONFIG = $(ARCH)_spike
  8731. +endif
  8732. +
  8733. +export BITS
  8734. +ifeq ($(CONFIG_64BIT),y)
  8735. + BITS := 64
  8736. + UTS_MACHINE := riscv64
  8737. +
  8738. + KBUILD_CFLAGS += -mabi=lp64
  8739. + KBUILD_AFLAGS += -mabi=lp64
  8740. + KBUILD_MARCH = rv64im
  8741. + LDFLAGS += -melf64lriscv
  8742. +else
  8743. + BITS := 32
  8744. + UTS_MACHINE := riscv32
  8745. +
  8746. + KBUILD_CFLAGS += -mabi=ilp32
  8747. + KBUILD_AFLAGS += -mabi=ilp32
  8748. + KBUILD_MARCH = rv32im
  8749. + LDFLAGS += -melf32lriscv
  8750. +endif
  8751. +
  8752. +ifeq ($(CONFIG_RV_ATOMIC),y)
  8753. + KBUILD_RV_ATOMIC = a
  8754. +endif
  8755. +
  8756. +KBUILD_CFLAGS += -Wall
  8757. +
  8758. +ifeq ($(CONFIG_RVC),y)
  8759. + KBUILD_RVC = c
  8760. +endif
  8761. +
  8762. +KBUILD_AFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_RV_ATOMIC)fd$(KBUILD_RVC)
  8763. +
  8764. +KBUILD_CFLAGS += -march=$(KBUILD_MARCH)$(KBUILD_RV_ATOMIC)$(KBUILD_RVC)
  8765. +KBUILD_CFLAGS += -mno-save-restore
  8766. +
  8767. +head-y := arch/riscv/kernel/head.o
  8768. +
  8769. +core-y += arch/riscv/kernel/ arch/riscv/mm/
  8770. +
  8771. +libs-y += arch/riscv/lib/
  8772. +
  8773. +all: vmlinux
  8774. diff -Nur linux-4.6.2/arch/riscv/mm/extable.c linux-4.6.2.riscv/arch/riscv/mm/extable.c
  8775. --- linux-4.6.2/arch/riscv/mm/extable.c 1970-01-01 01:00:00.000000000 +0100
  8776. +++ linux-4.6.2.riscv/arch/riscv/mm/extable.c 2017-03-04 02:48:34.170888098 +0100
  8777. @@ -0,0 +1,14 @@
  8778. +#include <linux/module.h>
  8779. +#include <linux/uaccess.h>
  8780. +
  8781. +int fixup_exception(struct pt_regs *regs)
  8782. +{
  8783. + const struct exception_table_entry *fixup;
  8784. +
  8785. + fixup = search_exception_tables(regs->sepc);
  8786. + if (fixup) {
  8787. + regs->sepc = fixup->fixup;
  8788. + return 1;
  8789. + }
  8790. + return 0;
  8791. +}
  8792. diff -Nur linux-4.6.2/arch/riscv/mm/fault.c linux-4.6.2.riscv/arch/riscv/mm/fault.c
  8793. --- linux-4.6.2/arch/riscv/mm/fault.c 1970-01-01 01:00:00.000000000 +0100
  8794. +++ linux-4.6.2.riscv/arch/riscv/mm/fault.c 2017-03-04 02:48:34.170888098 +0100
  8795. @@ -0,0 +1,250 @@
  8796. +#include <linux/mm.h>
  8797. +#include <linux/kernel.h>
  8798. +#include <linux/interrupt.h>
  8799. +#include <linux/perf_event.h>
  8800. +#include <linux/signal.h>
  8801. +#include <linux/uaccess.h>
  8802. +
  8803. +#include <asm/pgalloc.h>
  8804. +#include <asm/ptrace.h>
  8805. +#include <asm/uaccess.h>
  8806. +
  8807. +/*
  8808. + * This routine handles page faults. It determines the address and the
  8809. + * problem, and then passes it off to one of the appropriate routines.
  8810. + */
  8811. +asmlinkage void do_page_fault(struct pt_regs *regs)
  8812. +{
  8813. + struct task_struct *tsk;
  8814. + struct vm_area_struct *vma;
  8815. + struct mm_struct *mm;
  8816. + unsigned long addr, cause;
  8817. + unsigned int flags = FAULT_FLAG_ALLOW_RETRY | FAULT_FLAG_KILLABLE;
  8818. + int fault, code = SEGV_MAPERR;
  8819. +
  8820. + cause = regs->scause;
  8821. + addr = regs->sbadaddr;
  8822. +
  8823. + tsk = current;
  8824. + mm = tsk->mm;
  8825. +
  8826. + /*
  8827. + * Fault-in kernel-space virtual memory on-demand.
  8828. + * The 'reference' page table is init_mm.pgd.
  8829. + *
  8830. + * NOTE! We MUST NOT take any locks for this case. We may
  8831. + * be in an interrupt or a critical region, and should
  8832. + * only copy the information from the master page table,
  8833. + * nothing more.
  8834. + */
  8835. + if (unlikely((addr >= VMALLOC_START) && (addr <= VMALLOC_END)))
  8836. + goto vmalloc_fault;
  8837. +
  8838. + /* Enable interrupts if they were enabled in the parent context. */
  8839. + if (likely(regs->sstatus & SR_PIE))
  8840. + local_irq_enable();
  8841. +
  8842. + /*
  8843. + * If we're in an interrupt, have no user context, or are running
  8844. + * in an atomic region, then we must not take the fault.
  8845. + */
  8846. + if (unlikely(faulthandler_disabled() || !mm))
  8847. + goto no_context;
  8848. +
  8849. + if (user_mode(regs))
  8850. + flags |= FAULT_FLAG_USER;
  8851. +
  8852. + perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS, 1, regs, addr);
  8853. +
  8854. +retry:
  8855. + down_read(&mm->mmap_sem);
  8856. + vma = find_vma(mm, addr);
  8857. + if (unlikely(!vma))
  8858. + goto bad_area;
  8859. + if (likely(vma->vm_start <= addr))
  8860. + goto good_area;
  8861. + if (unlikely(!(vma->vm_flags & VM_GROWSDOWN)))
  8862. + goto bad_area;
  8863. + if (unlikely(expand_stack(vma, addr)))
  8864. + goto bad_area;
  8865. +
  8866. + /*
  8867. + * Ok, we have a good vm_area for this memory access, so
  8868. + * we can handle it.
  8869. + */
  8870. +good_area:
  8871. + code = SEGV_ACCERR;
  8872. +
  8873. + switch (cause) {
  8874. + case EXC_INST_ACCESS:
  8875. + if (!(vma->vm_flags & VM_EXEC))
  8876. + goto bad_area;
  8877. + break;
  8878. + case EXC_LOAD_ACCESS:
  8879. + if (!(vma->vm_flags & VM_READ))
  8880. + goto bad_area;
  8881. + break;
  8882. + case EXC_STORE_ACCESS:
  8883. + if (!(vma->vm_flags & VM_WRITE))
  8884. + goto bad_area;
  8885. + flags |= FAULT_FLAG_WRITE;
  8886. + break;
  8887. + default:
  8888. + panic("%s: unhandled cause %lu", __func__, cause);
  8889. + }
  8890. +
  8891. + /*
  8892. + * If for any reason at all we could not handle the fault,
  8893. + * make sure we exit gracefully rather than endlessly redo
  8894. + * the fault.
  8895. + */
  8896. + fault = handle_mm_fault(mm, vma, addr, flags);
  8897. +
  8898. + /*
  8899. + * If we need to retry but a fatal signal is pending, handle the
  8900. + * signal first. We do not need to release the mmap_sem because it
  8901. + * would already be released in __lock_page_or_retry in mm/filemap.c.
  8902. + */
  8903. + if ((fault & VM_FAULT_RETRY) && fatal_signal_pending(tsk))
  8904. + return;
  8905. +
  8906. + if (unlikely(fault & VM_FAULT_ERROR)) {
  8907. + if (fault & VM_FAULT_OOM)
  8908. + goto out_of_memory;
  8909. + else if (fault & VM_FAULT_SIGBUS)
  8910. + goto do_sigbus;
  8911. + BUG();
  8912. + }
  8913. +
  8914. + /*
  8915. + * Major/minor page fault accounting is only done on the
  8916. + * initial attempt. If we go through a retry, it is extremely
  8917. + * likely that the page will be found in page cache at that point.
  8918. + */
  8919. + if (flags & FAULT_FLAG_ALLOW_RETRY) {
  8920. + if (fault & VM_FAULT_MAJOR) {
  8921. + tsk->maj_flt++;
  8922. + perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MAJ, 1, regs, addr);
  8923. + } else {
  8924. + tsk->min_flt++;
  8925. + perf_sw_event(PERF_COUNT_SW_PAGE_FAULTS_MIN, 1, regs, addr);
  8926. + }
  8927. + if (fault & VM_FAULT_RETRY) {
  8928. + /*
  8929. + * Clear FAULT_FLAG_ALLOW_RETRY to avoid any risk
  8930. + * of starvation.
  8931. + */
  8932. + flags &= ~(FAULT_FLAG_ALLOW_RETRY);
  8933. + flags |= FAULT_FLAG_TRIED;
  8934. +
  8935. + /*
  8936. + * No need to up_read(&mm->mmap_sem) as we would
  8937. + * have already released it in __lock_page_or_retry
  8938. + * in mm/filemap.c.
  8939. + */
  8940. + goto retry;
  8941. + }
  8942. + }
  8943. +
  8944. + up_read(&mm->mmap_sem);
  8945. + return;
  8946. +
  8947. + /*
  8948. + * Something tried to access memory that isn't in our memory map.
  8949. + * Fix it, but check if it's kernel or user first.
  8950. + */
  8951. +bad_area:
  8952. + up_read(&mm->mmap_sem);
  8953. + /* User mode accesses just cause a SIGSEGV */
  8954. + if (user_mode(regs)) {
  8955. + do_trap(regs, SIGSEGV, code, addr, tsk);
  8956. + return;
  8957. + }
  8958. +
  8959. +no_context:
  8960. + /* Are we prepared to handle this kernel fault? */
  8961. + if (fixup_exception(regs)) {
  8962. + return;
  8963. + }
  8964. +
  8965. + /*
  8966. + * Oops. The kernel tried to access some bad page. We'll have to
  8967. + * terminate things with extreme prejudice.
  8968. + */
  8969. + bust_spinlocks(1);
  8970. + pr_alert("Unable to handle kernel %s at virtual address " REG_FMT "\n",
  8971. + (addr < PAGE_SIZE) ? "NULL pointer dereference" :
  8972. + "paging request", addr);
  8973. + die(regs, "Oops");
  8974. + do_exit(SIGKILL);
  8975. +
  8976. + /*
  8977. + * We ran out of memory, call the OOM killer, and return the userspace
  8978. + * (which will retry the fault, or kill us if we got oom-killed).
  8979. + */
  8980. +out_of_memory:
  8981. + up_read(&mm->mmap_sem);
  8982. + if (!user_mode(regs))
  8983. + goto no_context;
  8984. + pagefault_out_of_memory();
  8985. + return;
  8986. +
  8987. +do_sigbus:
  8988. + up_read(&mm->mmap_sem);
  8989. + /* Kernel mode? Handle exceptions or die */
  8990. + if (!user_mode(regs))
  8991. + goto no_context;
  8992. + do_trap(regs, SIGBUS, BUS_ADRERR, addr, tsk);
  8993. + return;
  8994. +
  8995. +vmalloc_fault:
  8996. + {
  8997. + pgd_t *pgd, *pgd_k;
  8998. + pud_t *pud, *pud_k;
  8999. + pmd_t *pmd, *pmd_k;
  9000. + pte_t *pte_k;
  9001. + int index;
  9002. +
  9003. + if (user_mode(regs))
  9004. + goto bad_area;
  9005. +
  9006. + /*
  9007. + * Synchronize this task's top level page-table
  9008. + * with the 'reference' page table.
  9009. + *
  9010. + * Do _not_ use "tsk->active_mm->pgd" here.
  9011. + * We might be inside an interrupt in the middle
  9012. + * of a task switch.
  9013. + */
  9014. + index = pgd_index(addr);
  9015. + pgd = (pgd_t *)pfn_to_virt(csr_read(sptbr)) + index;
  9016. + pgd_k = init_mm.pgd + index;
  9017. +
  9018. + if (!pgd_present(*pgd_k))
  9019. + goto no_context;
  9020. + set_pgd(pgd, *pgd_k);
  9021. +
  9022. + pud = pud_offset(pgd, addr);
  9023. + pud_k = pud_offset(pgd_k, addr);
  9024. + if (!pud_present(*pud_k))
  9025. + goto no_context;
  9026. +
  9027. + /* Since the vmalloc area is global, it is unnecessary
  9028. + to copy individual PTEs */
  9029. + pmd = pmd_offset(pud, addr);
  9030. + pmd_k = pmd_offset(pud_k, addr);
  9031. + if (!pmd_present(*pmd_k))
  9032. + goto no_context;
  9033. + set_pmd(pmd, *pmd_k);
  9034. +
  9035. + /* Make sure the actual PTE exists as well to
  9036. + * catch kernel vmalloc-area accesses to non-mapped
  9037. + * addresses. If we don't do this, this will just
  9038. + * silently loop forever.
  9039. + */
  9040. + pte_k = pte_offset_kernel(pmd_k, addr);
  9041. + if (!pte_present(*pte_k))
  9042. + goto no_context;
  9043. + return;
  9044. + }
  9045. +}
  9046. diff -Nur linux-4.6.2/arch/riscv/mm/init.c linux-4.6.2.riscv/arch/riscv/mm/init.c
  9047. --- linux-4.6.2/arch/riscv/mm/init.c 1970-01-01 01:00:00.000000000 +0100
  9048. +++ linux-4.6.2.riscv/arch/riscv/mm/init.c 2017-03-04 02:48:34.170888098 +0100
  9049. @@ -0,0 +1,84 @@
  9050. +#include <linux/init.h>
  9051. +#include <linux/mm.h>
  9052. +#include <linux/bootmem.h>
  9053. +#include <linux/initrd.h>
  9054. +#include <linux/memblock.h>
  9055. +#include <linux/swap.h>
  9056. +
  9057. +#include <asm/tlbflush.h>
  9058. +#include <asm/sections.h>
  9059. +#include <asm/pgtable.h>
  9060. +#include <asm/io.h>
  9061. +
  9062. +#ifdef CONFIG_NUMA
  9063. +static void __init zone_sizes_init(void)
  9064. +{
  9065. + unsigned long zones_size[MAX_NR_ZONES];
  9066. + int nid;
  9067. +
  9068. + memset(zones_size, 0, sizeof(zones_size));
  9069. +
  9070. + for_each_online_node(nid) {
  9071. + pg_data_t *pgdat;
  9072. + unsigned long start_pfn, end_pfn;
  9073. +
  9074. + pgdat = NODE_DATA(nid);
  9075. + start_pfn = pgdat->bdata->node_min_pfn;
  9076. + end_pfn = pgdat->bdata->node_low_pfn;
  9077. + memblock_add_node(start_pfn,
  9078. + PFN_PHYS(end_pfn - start_pfn), nid);
  9079. + }
  9080. +
  9081. + zones_size[ZONE_NORMAL] = pfn_base + max_mapnr;
  9082. + free_area_init_nodes(zones_size);
  9083. +}
  9084. +#else
  9085. +static void __init zone_sizes_init(void)
  9086. +{
  9087. + unsigned long zones_size[MAX_NR_ZONES];
  9088. +
  9089. + memset(zones_size, 0, sizeof(zones_size));
  9090. + memblock_add_node(PFN_PHYS(pfn_base), PFN_PHYS(max_mapnr), 0);
  9091. + zones_size[ZONE_NORMAL] = pfn_base + max_mapnr;
  9092. + free_area_init_nodes(zones_size);
  9093. +}
  9094. +#endif /* CONFIG_NUMA */
  9095. +
  9096. +void setup_zero_page(void)
  9097. +{
  9098. + memset((void *)empty_zero_page, 0, PAGE_SIZE);
  9099. +}
  9100. +
  9101. +void __init paging_init(void)
  9102. +{
  9103. + init_mm.pgd = (pgd_t *)pfn_to_virt(csr_read(sptbr));
  9104. +
  9105. + setup_zero_page();
  9106. + local_flush_tlb_all();
  9107. + zone_sizes_init();
  9108. +}
  9109. +
  9110. +void __init mem_init(void)
  9111. +{
  9112. +#ifdef CONFIG_FLATMEM
  9113. + BUG_ON(!mem_map);
  9114. +#endif /* CONFIG_FLATMEM */
  9115. +
  9116. + high_memory = (void *)(__va(PFN_PHYS(max_low_pfn)));
  9117. + free_all_bootmem();
  9118. +
  9119. + mem_init_print_info(NULL);
  9120. +}
  9121. +
  9122. +void free_initmem(void)
  9123. +{
  9124. + free_initmem_default(0);
  9125. +}
  9126. +
  9127. +#ifdef CONFIG_BLK_DEV_INITRD
  9128. +void free_initrd_mem(unsigned long start, unsigned long end)
  9129. +{
  9130. +// free_reserved_area(start, end, 0, "initrd");
  9131. +}
  9132. +#endif /* CONFIG_BLK_DEV_INITRD */
  9133. +
  9134. diff -Nur linux-4.6.2/arch/riscv/mm/ioremap.c linux-4.6.2.riscv/arch/riscv/mm/ioremap.c
  9135. --- linux-4.6.2/arch/riscv/mm/ioremap.c 1970-01-01 01:00:00.000000000 +0100
  9136. +++ linux-4.6.2.riscv/arch/riscv/mm/ioremap.c 2017-03-04 02:48:34.170888098 +0100
  9137. @@ -0,0 +1,81 @@
  9138. +#include <linux/export.h>
  9139. +#include <linux/mm.h>
  9140. +#include <linux/vmalloc.h>
  9141. +#include <linux/io.h>
  9142. +
  9143. +#include <asm/pgtable.h>
  9144. +
  9145. +/*
  9146. + * Remap an arbitrary physical address space into the kernel virtual
  9147. + * address space. Needed when the kernel wants to access high addresses
  9148. + * directly.
  9149. + *
  9150. + * NOTE! We need to allow non-page-aligned mappings too: we will obviously
  9151. + * have to convert them into an offset in a page-aligned mapping, but the
  9152. + * caller shouldn't need to know that small detail.
  9153. + */
  9154. +static void __iomem *__ioremap_caller(phys_addr_t addr, size_t size,
  9155. + pgprot_t prot, void *caller)
  9156. +{
  9157. + phys_addr_t last_addr;
  9158. + unsigned long offset, vaddr;
  9159. + struct vm_struct *area;
  9160. +
  9161. + /* Disallow wrap-around or zero size */
  9162. + last_addr = addr + size - 1;
  9163. + if (!size || last_addr < addr) {
  9164. + return NULL;
  9165. + }
  9166. +
  9167. + /* Page-align mappings */
  9168. + offset = addr & (~PAGE_MASK);
  9169. + addr &= PAGE_MASK;
  9170. + size = PAGE_ALIGN(size + offset);
  9171. +
  9172. + area = get_vm_area_caller(size, VM_IOREMAP, caller);
  9173. + if (!area) {
  9174. + return NULL;
  9175. + }
  9176. + vaddr = (unsigned long)area->addr;
  9177. +
  9178. + if (ioremap_page_range(vaddr, vaddr + size, addr, prot)) {
  9179. + free_vm_area(area);
  9180. + return NULL;
  9181. + }
  9182. +
  9183. + return (void __iomem *)(vaddr + offset);
  9184. +}
  9185. +
  9186. +/*
  9187. + * ioremap - map bus memory into CPU space
  9188. + * @offset: bus address of the memory
  9189. + * @size: size of the resource to map
  9190. + *
  9191. + * ioremap performs a platform specific sequence of operations to
  9192. + * make bus memory CPU accessible via the readb/readw/readl/writeb/
  9193. + * writew/writel functions and the other mmio helpers. The returned
  9194. + * address is not guaranteed to be usable directly as a virtual
  9195. + * address.
  9196. + *
  9197. + * Must be freed with iounmap.
  9198. + */
  9199. +void __iomem *ioremap(phys_addr_t offset, unsigned long size)
  9200. +{
  9201. + return __ioremap_caller(offset, size, PAGE_KERNEL,
  9202. + __builtin_return_address(0));
  9203. +}
  9204. +EXPORT_SYMBOL(ioremap);
  9205. +
  9206. +
  9207. +/**
  9208. + * iounmap - Free a IO remapping
  9209. + * @addr: virtual address from ioremap_*
  9210. + *
  9211. + * Caller must ensure there is only one unmapping for the same pointer.
  9212. + */
  9213. +void iounmap(void __iomem *addr)
  9214. +{
  9215. + vunmap((void *)((unsigned long)addr & PAGE_MASK));
  9216. +}
  9217. +EXPORT_SYMBOL(iounmap);
  9218. +
  9219. diff -Nur linux-4.6.2/arch/riscv/mm/Makefile linux-4.6.2.riscv/arch/riscv/mm/Makefile
  9220. --- linux-4.6.2/arch/riscv/mm/Makefile 1970-01-01 01:00:00.000000000 +0100
  9221. +++ linux-4.6.2.riscv/arch/riscv/mm/Makefile 2017-03-04 02:48:34.170888098 +0100
  9222. @@ -0,0 +1 @@
  9223. +obj-y := init.o fault.o extable.o ioremap.o
  9224. diff -Nur linux-4.6.2/.gitignore linux-4.6.2.riscv/.gitignore
  9225. --- linux-4.6.2/.gitignore 2016-06-08 03:23:53.000000000 +0200
  9226. +++ linux-4.6.2.riscv/.gitignore 2017-03-04 02:48:34.162887952 +0100
  9227. @@ -1,114 +1,11 @@
  9228. -#
  9229. -# NOTE! Don't add files that are generated in specific
  9230. -# subdirectories here. Add them in the ".gitignore" file
  9231. -# in that subdirectory instead.
  9232. -#
  9233. -# NOTE! Please use 'git ls-files -i --exclude-standard'
  9234. -# command after changing this file, to see if there are
  9235. -# any tracked files which get ignored after the change.
  9236. -#
  9237. -# Normal rules
  9238. -#
  9239. -.*
  9240. -*.o
  9241. -*.o.*
  9242. -*.a
  9243. -*.s
  9244. -*.ko
  9245. -*.so
  9246. -*.so.dbg
  9247. -*.mod.c
  9248. -*.i
  9249. -*.lst
  9250. -*.symtypes
  9251. -*.order
  9252. -*.elf
  9253. -*.bin
  9254. -*.tar
  9255. -*.gz
  9256. -*.bz2
  9257. -*.lzma
  9258. -*.xz
  9259. -*.lz4
  9260. -*.lzo
  9261. -*.patch
  9262. -*.gcno
  9263. -modules.builtin
  9264. -Module.symvers
  9265. -*.dwo
  9266. -*.su
  9267. +# Ignore everything...
  9268. +*
  9269. -#
  9270. -# Top-level generic files
  9271. -#
  9272. -/tags
  9273. -/TAGS
  9274. -/linux
  9275. -/vmlinux
  9276. -/vmlinux.32
  9277. -/vmlinux-gdb.py
  9278. -/vmlinuz
  9279. -/System.map
  9280. -/Module.markers
  9281. -
  9282. -#
  9283. -# Debian directory (make deb-pkg)
  9284. -#
  9285. -/debian/
  9286. -
  9287. -#
  9288. -# tar directory (make tar*-pkg)
  9289. -#
  9290. -/tar-install/
  9291. -
  9292. -#
  9293. -# git files that we don't want to ignore even it they are dot-files
  9294. -#
  9295. +# Then include just this.
  9296. +!arch/
  9297. !.gitignore
  9298. -!.mailmap
  9299. -
  9300. -#
  9301. -# Generated include files
  9302. -#
  9303. -include/config
  9304. -include/generated
  9305. -arch/*/include/generated
  9306. -
  9307. -# stgit generated dirs
  9308. -patches-*
  9309. -
  9310. -# quilt's files
  9311. -patches
  9312. -series
  9313. -
  9314. -# cscope files
  9315. -cscope.*
  9316. -ncscope.*
  9317. -
  9318. -# gnu global files
  9319. -GPATH
  9320. -GRTAGS
  9321. -GSYMS
  9322. -GTAGS
  9323. -
  9324. -# id-utils files
  9325. -ID
  9326. -
  9327. -*.orig
  9328. -*~
  9329. -\#*#
  9330. -
  9331. -#
  9332. -# Leavings from module signing
  9333. -#
  9334. -extra_certificates
  9335. -signing_key.pem
  9336. -signing_key.priv
  9337. -signing_key.x509
  9338. -x509.genkey
  9339. +!README.md
  9340. -# Kconfig presets
  9341. -all.config
  9342. +# The arch/.gitignore and arch/riscv/.gitignore have patterns to un-ignore the
  9343. +# appropriate files.
  9344. -# Kdevelop4
  9345. -*.kdev4
  9346. diff -Nur linux-4.6.2/README.md linux-4.6.2.riscv/README.md
  9347. --- linux-4.6.2/README.md 1970-01-01 01:00:00.000000000 +0100
  9348. +++ linux-4.6.2.riscv/README.md 2017-03-04 02:48:34.162887952 +0100
  9349. @@ -0,0 +1,72 @@
  9350. +# Linux/RISC-V
  9351. +
  9352. +This is a port of Linux kernel for the [RISC-V](http://riscv.org/)
  9353. +instruction set architecture.
  9354. +Development is currently based on the
  9355. +[4.6 longterm branch](https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git/log/?h=linux-4.6.y).
  9356. +
  9357. +
  9358. +## Obtaining kernel sources
  9359. +
  9360. +### Master
  9361. +
  9362. +Overlay the `riscv` architecture-specific subtree onto an upstream release:
  9363. +
  9364. + $ curl -L https://cdn.kernel.org/pub/linux/kernel/v4.x/linux-4.6.2.tar.xz | tar -xJ
  9365. + $ cd linux-4.6.2
  9366. + $ git init
  9367. + $ git remote add -t master origin https://github.com/riscv/riscv-linux.git
  9368. + $ git fetch
  9369. + $ git checkout -f -t origin/master
  9370. +
  9371. +Note that the `-t <branch>` option minimizes the history fetched.
  9372. +To add another branch:
  9373. +
  9374. + $ git remote set-branches --add origin <branch>
  9375. + $ git fetch
  9376. +
  9377. +### Full kernel source trees
  9378. +
  9379. +For convenience, full kernel source trees are maintained on separate
  9380. +branches tracking
  9381. +[linux-stable](https://git.kernel.org/cgit/linux/kernel/git/stable/linux-stable.git):
  9382. +
  9383. +* `linux-4.6.y-riscv`
  9384. +* `linux-3.14.y-riscv` (historical)
  9385. +
  9386. +## Building the kernel image
  9387. +
  9388. +1. Create kernel configuration based on architecture defaults:
  9389. +
  9390. + $ make ARCH=riscv defconfig
  9391. +
  9392. +1. Optionally edit the configuration via an ncurses interface:
  9393. +
  9394. + $ make ARCH=riscv menuconfig
  9395. +
  9396. +1. Build the uncompressed kernel image:
  9397. +
  9398. + $ make -j4 ARCH=riscv vmlinux
  9399. +
  9400. +1. Boot the kernel in the functional simulator, optionally specifying a
  9401. + raw disk image for the root filesystem:
  9402. +
  9403. + $ spike +disk=path/to/root.img bbl vmlinux
  9404. +
  9405. + `bbl` (the Berkeley Boot Loader) is available from the
  9406. + [riscv-pk](https://github.com/riscv/riscv-pk) repository.
  9407. +
  9408. +## Exporting kernel headers
  9409. +
  9410. +The `riscv-gnu-toolchain` repository includes a copy of the kernel header files.
  9411. +If the userspace API has changed, export the updated headers to the
  9412. +`riscv-gnu-toolchain` source directory:
  9413. +
  9414. + $ make ARCH=riscv headers_check
  9415. + $ make ARCH=riscv INSTALL_HDR_PATH=path/to/riscv-gnu-toolchain/linux-headers headers_install
  9416. +
  9417. +Rebuild `riscv64-unknown-linux-gnu-gcc` with the `linux` target:
  9418. +
  9419. + $ cd path/to/riscv-gnu-toolchain
  9420. + $ make linux
  9421. +