quirks.c 227 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057105810591060106110621063106410651066106710681069107010711072107310741075107610771078107910801081108210831084108510861087108810891090109110921093109410951096109710981099110011011102110311041105110611071108110911101111111211131114111511161117111811191120112111221123112411251126112711281129113011311132113311341135113611371138113911401141114211431144114511461147114811491150115111521153115411551156115711581159116011611162116311641165116611671168116911701171117211731174117511761177117811791180118111821183118411851186118711881189119011911192119311941195119611971198119912001201120212031204120512061207120812091210121112121213121412151216121712181219122012211222122312241225122612271228122912301231123212331234123512361237123812391240124112421243124412451246124712481249125012511252125312541255125612571258125912601261126212631264126512661267126812691270127112721273127412751276127712781279128012811282128312841285128612871288128912901291129212931294129512961297129812991300130113021303130413051306130713081309131013111312131313141315131613171318131913201321132213231324132513261327132813291330133113321333133413351336133713381339134013411342134313441345134613471348134913501351135213531354135513561357135813591360136113621363136413651366136713681369137013711372137313741375137613771378137913801381138213831384138513861387138813891390139113921393139413951396139713981399140014011402140314041405140614071408140914101411141214131414141514161417141814191420142114221423142414251426142714281429143014311432143314341435143614371438143914401441144214431444144514461447144814491450145114521453145414551456145714581459146014611462146314641465146614671468146914701471147214731474147514761477147814791480148114821483148414851486148714881489149014911492149314941495149614971498149915001501150215031504150515061507150815091510151115121513151415151516151715181519152015211522152315241525152615271528152915301531153215331534153515361537153815391540154115421543154415451546154715481549155015511552155315541555155615571558155915601561156215631564156515661567156815691570157115721573157415751576157715781579158015811582158315841585158615871588158915901591159215931594159515961597159815991600160116021603160416051606160716081609161016111612161316141615161616171618161916201621162216231624162516261627162816291630163116321633163416351636163716381639164016411642164316441645164616471648164916501651165216531654165516561657165816591660166116621663166416651666166716681669167016711672167316741675167616771678167916801681168216831684168516861687168816891690169116921693169416951696169716981699170017011702170317041705170617071708170917101711171217131714171517161717171817191720172117221723172417251726172717281729173017311732173317341735173617371738173917401741174217431744174517461747174817491750175117521753175417551756175717581759176017611762176317641765176617671768176917701771177217731774177517761777177817791780178117821783178417851786178717881789179017911792179317941795179617971798179918001801180218031804180518061807180818091810181118121813181418151816181718181819182018211822182318241825182618271828182918301831183218331834183518361837183818391840184118421843184418451846184718481849185018511852185318541855185618571858185918601861186218631864186518661867186818691870187118721873187418751876187718781879188018811882188318841885188618871888188918901891189218931894189518961897189818991900190119021903190419051906190719081909191019111912191319141915191619171918191919201921192219231924192519261927192819291930193119321933193419351936193719381939194019411942194319441945194619471948194919501951195219531954195519561957195819591960196119621963196419651966196719681969197019711972197319741975197619771978197919801981198219831984198519861987198819891990199119921993199419951996199719981999200020012002200320042005200620072008200920102011201220132014201520162017201820192020202120222023202420252026202720282029203020312032203320342035203620372038203920402041204220432044204520462047204820492050205120522053205420552056205720582059206020612062206320642065206620672068206920702071207220732074207520762077207820792080208120822083208420852086208720882089209020912092209320942095209620972098209921002101210221032104210521062107210821092110211121122113211421152116211721182119212021212122212321242125212621272128212921302131213221332134213521362137213821392140214121422143214421452146214721482149215021512152215321542155215621572158215921602161216221632164216521662167216821692170217121722173217421752176217721782179218021812182218321842185218621872188218921902191219221932194219521962197219821992200220122022203220422052206220722082209221022112212221322142215221622172218221922202221222222232224222522262227222822292230223122322233223422352236223722382239224022412242224322442245224622472248224922502251225222532254225522562257225822592260226122622263226422652266226722682269227022712272227322742275227622772278227922802281228222832284228522862287228822892290229122922293229422952296229722982299230023012302230323042305230623072308230923102311231223132314231523162317231823192320232123222323232423252326232723282329233023312332233323342335233623372338233923402341234223432344234523462347234823492350235123522353235423552356235723582359236023612362236323642365236623672368236923702371237223732374237523762377237823792380238123822383238423852386238723882389239023912392239323942395239623972398239924002401240224032404240524062407240824092410241124122413241424152416241724182419242024212422242324242425242624272428242924302431243224332434243524362437243824392440244124422443244424452446244724482449245024512452245324542455245624572458245924602461246224632464246524662467246824692470247124722473247424752476247724782479248024812482248324842485248624872488248924902491249224932494249524962497249824992500250125022503250425052506250725082509251025112512251325142515251625172518251925202521252225232524252525262527252825292530253125322533253425352536253725382539254025412542254325442545254625472548254925502551255225532554255525562557255825592560256125622563256425652566256725682569257025712572257325742575257625772578257925802581258225832584258525862587258825892590259125922593259425952596259725982599260026012602260326042605260626072608260926102611261226132614261526162617261826192620262126222623262426252626262726282629263026312632263326342635263626372638263926402641264226432644264526462647264826492650265126522653265426552656265726582659266026612662266326642665266626672668266926702671267226732674267526762677267826792680268126822683268426852686268726882689269026912692269326942695269626972698269927002701270227032704270527062707270827092710271127122713271427152716271727182719272027212722272327242725272627272728272927302731273227332734273527362737273827392740274127422743274427452746274727482749275027512752275327542755275627572758275927602761276227632764276527662767276827692770277127722773277427752776277727782779278027812782278327842785278627872788278927902791279227932794279527962797279827992800280128022803280428052806280728082809281028112812281328142815281628172818281928202821282228232824282528262827282828292830283128322833283428352836283728382839284028412842284328442845284628472848284928502851285228532854285528562857285828592860286128622863286428652866286728682869287028712872287328742875287628772878287928802881288228832884288528862887288828892890289128922893289428952896289728982899290029012902290329042905290629072908290929102911291229132914291529162917291829192920292129222923292429252926292729282929293029312932293329342935293629372938293929402941294229432944294529462947294829492950295129522953295429552956295729582959296029612962296329642965296629672968296929702971297229732974297529762977297829792980298129822983298429852986298729882989299029912992299329942995299629972998299930003001300230033004300530063007300830093010301130123013301430153016301730183019302030213022302330243025302630273028302930303031303230333034303530363037303830393040304130423043304430453046304730483049305030513052305330543055305630573058305930603061306230633064306530663067306830693070307130723073307430753076307730783079308030813082308330843085308630873088308930903091309230933094309530963097309830993100310131023103310431053106310731083109311031113112311331143115311631173118311931203121312231233124312531263127312831293130313131323133313431353136313731383139314031413142314331443145314631473148314931503151315231533154315531563157315831593160316131623163316431653166316731683169317031713172317331743175317631773178317931803181318231833184318531863187318831893190319131923193319431953196319731983199320032013202320332043205320632073208320932103211321232133214321532163217321832193220322132223223322432253226322732283229323032313232323332343235323632373238323932403241324232433244324532463247324832493250325132523253325432553256325732583259326032613262326332643265326632673268326932703271327232733274327532763277327832793280328132823283328432853286328732883289329032913292329332943295329632973298329933003301330233033304330533063307330833093310331133123313331433153316331733183319332033213322332333243325332633273328332933303331333233333334333533363337333833393340334133423343334433453346334733483349335033513352335333543355335633573358335933603361336233633364336533663367336833693370337133723373337433753376337733783379338033813382338333843385338633873388338933903391339233933394339533963397339833993400340134023403340434053406340734083409341034113412341334143415341634173418341934203421342234233424342534263427342834293430343134323433343434353436343734383439344034413442344334443445344634473448344934503451345234533454345534563457345834593460346134623463346434653466346734683469347034713472347334743475347634773478347934803481348234833484348534863487348834893490349134923493349434953496349734983499350035013502350335043505350635073508350935103511351235133514351535163517351835193520352135223523352435253526352735283529353035313532353335343535353635373538353935403541354235433544354535463547354835493550355135523553355435553556355735583559356035613562356335643565356635673568356935703571357235733574357535763577357835793580358135823583358435853586358735883589359035913592359335943595359635973598359936003601360236033604360536063607360836093610361136123613361436153616361736183619362036213622362336243625362636273628362936303631363236333634363536363637363836393640364136423643364436453646364736483649365036513652365336543655365636573658365936603661366236633664366536663667366836693670367136723673367436753676367736783679368036813682368336843685368636873688368936903691369236933694369536963697369836993700370137023703370437053706370737083709371037113712371337143715371637173718371937203721372237233724372537263727372837293730373137323733373437353736373737383739374037413742374337443745374637473748374937503751375237533754375537563757375837593760376137623763376437653766376737683769377037713772377337743775377637773778377937803781378237833784378537863787378837893790379137923793379437953796379737983799380038013802380338043805380638073808380938103811381238133814381538163817381838193820382138223823382438253826382738283829383038313832383338343835383638373838383938403841384238433844384538463847384838493850385138523853385438553856385738583859386038613862386338643865386638673868386938703871387238733874387538763877387838793880388138823883388438853886388738883889389038913892389338943895389638973898389939003901390239033904390539063907390839093910391139123913391439153916391739183919392039213922392339243925392639273928392939303931393239333934393539363937393839393940394139423943394439453946394739483949395039513952395339543955395639573958395939603961396239633964396539663967396839693970397139723973397439753976397739783979398039813982398339843985398639873988398939903991399239933994399539963997399839994000400140024003400440054006400740084009401040114012401340144015401640174018401940204021402240234024402540264027402840294030403140324033403440354036403740384039404040414042404340444045404640474048404940504051405240534054405540564057405840594060406140624063406440654066406740684069407040714072407340744075407640774078407940804081408240834084408540864087408840894090409140924093409440954096409740984099410041014102410341044105410641074108410941104111411241134114411541164117411841194120412141224123412441254126412741284129413041314132413341344135413641374138413941404141414241434144414541464147414841494150415141524153415441554156415741584159416041614162416341644165416641674168416941704171417241734174417541764177417841794180418141824183418441854186418741884189419041914192419341944195419641974198419942004201420242034204420542064207420842094210421142124213421442154216421742184219422042214222422342244225422642274228422942304231423242334234423542364237423842394240424142424243424442454246424742484249425042514252425342544255425642574258425942604261426242634264426542664267426842694270427142724273427442754276427742784279428042814282428342844285428642874288428942904291429242934294429542964297429842994300430143024303430443054306430743084309431043114312431343144315431643174318431943204321432243234324432543264327432843294330433143324333433443354336433743384339434043414342434343444345434643474348434943504351435243534354435543564357435843594360436143624363436443654366436743684369437043714372437343744375437643774378437943804381438243834384438543864387438843894390439143924393439443954396439743984399440044014402440344044405440644074408440944104411441244134414441544164417441844194420442144224423442444254426442744284429443044314432443344344435443644374438443944404441444244434444444544464447444844494450445144524453445444554456445744584459446044614462446344644465446644674468446944704471447244734474447544764477447844794480448144824483448444854486448744884489449044914492449344944495449644974498449945004501450245034504450545064507450845094510451145124513451445154516451745184519452045214522452345244525452645274528452945304531453245334534453545364537453845394540454145424543454445454546454745484549455045514552455345544555455645574558455945604561456245634564456545664567456845694570457145724573457445754576457745784579458045814582458345844585458645874588458945904591459245934594459545964597459845994600460146024603460446054606460746084609461046114612461346144615461646174618461946204621462246234624462546264627462846294630463146324633463446354636463746384639464046414642464346444645464646474648464946504651465246534654465546564657465846594660466146624663466446654666466746684669467046714672467346744675467646774678467946804681468246834684468546864687468846894690469146924693469446954696469746984699470047014702470347044705470647074708470947104711471247134714471547164717471847194720472147224723472447254726472747284729473047314732473347344735473647374738473947404741474247434744474547464747474847494750475147524753475447554756475747584759476047614762476347644765476647674768476947704771477247734774477547764777477847794780478147824783478447854786478747884789479047914792479347944795479647974798479948004801480248034804480548064807480848094810481148124813481448154816481748184819482048214822482348244825482648274828482948304831483248334834483548364837483848394840484148424843484448454846484748484849485048514852485348544855485648574858485948604861486248634864486548664867486848694870487148724873487448754876487748784879488048814882488348844885488648874888488948904891489248934894489548964897489848994900490149024903490449054906490749084909491049114912491349144915491649174918491949204921492249234924492549264927492849294930493149324933493449354936493749384939494049414942494349444945494649474948494949504951495249534954495549564957495849594960496149624963496449654966496749684969497049714972497349744975497649774978497949804981498249834984498549864987498849894990499149924993499449954996499749984999500050015002500350045005500650075008500950105011501250135014501550165017501850195020502150225023502450255026502750285029503050315032503350345035503650375038503950405041504250435044504550465047504850495050505150525053505450555056505750585059506050615062506350645065506650675068506950705071507250735074507550765077507850795080508150825083508450855086508750885089509050915092509350945095509650975098509951005101510251035104510551065107510851095110511151125113511451155116511751185119512051215122512351245125512651275128512951305131513251335134513551365137513851395140514151425143514451455146514751485149515051515152515351545155515651575158515951605161516251635164516551665167516851695170517151725173517451755176517751785179518051815182518351845185518651875188518951905191519251935194519551965197519851995200520152025203520452055206520752085209521052115212521352145215521652175218521952205221522252235224522552265227522852295230523152325233523452355236523752385239524052415242524352445245524652475248524952505251525252535254525552565257525852595260526152625263526452655266526752685269527052715272527352745275527652775278527952805281528252835284528552865287528852895290529152925293529452955296529752985299530053015302530353045305530653075308530953105311531253135314531553165317531853195320532153225323532453255326532753285329533053315332533353345335533653375338533953405341534253435344534553465347534853495350535153525353535453555356535753585359536053615362536353645365536653675368536953705371537253735374537553765377537853795380538153825383538453855386538753885389539053915392539353945395539653975398539954005401540254035404540554065407540854095410541154125413541454155416541754185419542054215422542354245425542654275428542954305431543254335434543554365437543854395440544154425443544454455446544754485449545054515452545354545455545654575458545954605461546254635464546554665467546854695470547154725473547454755476547754785479548054815482548354845485548654875488548954905491549254935494549554965497549854995500550155025503550455055506550755085509551055115512551355145515551655175518551955205521552255235524552555265527552855295530553155325533553455355536553755385539554055415542554355445545554655475548554955505551555255535554555555565557555855595560556155625563556455655566556755685569557055715572557355745575557655775578557955805581558255835584558555865587558855895590559155925593559455955596559755985599560056015602560356045605560656075608560956105611561256135614561556165617561856195620562156225623562456255626562756285629563056315632563356345635563656375638563956405641564256435644564556465647564856495650565156525653565456555656565756585659566056615662566356645665566656675668566956705671567256735674567556765677567856795680568156825683568456855686568756885689569056915692569356945695569656975698569957005701570257035704570557065707570857095710571157125713571457155716571757185719572057215722572357245725572657275728572957305731573257335734573557365737573857395740574157425743574457455746574757485749575057515752575357545755575657575758575957605761576257635764576557665767576857695770577157725773577457755776577757785779578057815782578357845785578657875788578957905791579257935794579557965797579857995800580158025803580458055806580758085809581058115812581358145815581658175818581958205821582258235824582558265827582858295830583158325833583458355836583758385839584058415842584358445845584658475848584958505851585258535854585558565857585858595860586158625863586458655866586758685869587058715872587358745875587658775878587958805881588258835884588558865887588858895890589158925893589458955896589758985899590059015902590359045905590659075908590959105911591259135914591559165917591859195920592159225923592459255926592759285929593059315932593359345935593659375938593959405941594259435944594559465947594859495950595159525953595459555956595759585959596059615962596359645965596659675968596959705971597259735974597559765977597859795980598159825983598459855986598759885989599059915992599359945995599659975998599960006001600260036004600560066007600860096010601160126013601460156016601760186019602060216022602360246025602660276028602960306031603260336034603560366037603860396040604160426043604460456046604760486049605060516052605360546055605660576058605960606061606260636064606560666067606860696070607160726073607460756076607760786079608060816082608360846085608660876088608960906091609260936094609560966097609860996100610161026103610461056106610761086109611061116112611361146115611661176118611961206121612261236124612561266127612861296130613161326133613461356136613761386139614061416142614361446145614661476148614961506151615261536154615561566157615861596160616161626163616461656166616761686169617061716172617361746175617661776178617961806181618261836184618561866187618861896190619161926193619461956196619761986199620062016202620362046205620662076208620962106211621262136214621562166217621862196220622162226223622462256226622762286229623062316232623362346235623662376238623962406241624262436244624562466247624862496250625162526253625462556256625762586259626062616262626362646265626662676268626962706271627262736274627562766277627862796280628162826283628462856286628762886289629062916292629362946295629662976298629963006301630263036304630563066307630863096310631163126313631463156316
  1. // SPDX-License-Identifier: GPL-2.0
  2. /*
  3. * This file contains work-arounds for many known PCI hardware bugs.
  4. * Devices present only on certain architectures (host bridges et cetera)
  5. * should be handled in arch-specific code.
  6. *
  7. * Note: any quirks for hotpluggable devices must _NOT_ be declared __init.
  8. *
  9. * Copyright (c) 1999 Martin Mares <mj@ucw.cz>
  10. *
  11. * Init/reset quirks for USB host controllers should be in the USB quirks
  12. * file, where their drivers can use them.
  13. */
  14. #include <linux/bitfield.h>
  15. #include <linux/types.h>
  16. #include <linux/kernel.h>
  17. #include <linux/export.h>
  18. #include <linux/pci.h>
  19. #include <linux/isa-dma.h> /* isa_dma_bridge_buggy */
  20. #include <linux/init.h>
  21. #include <linux/delay.h>
  22. #include <linux/acpi.h>
  23. #include <linux/dmi.h>
  24. #include <linux/ioport.h>
  25. #include <linux/sched.h>
  26. #include <linux/ktime.h>
  27. #include <linux/mm.h>
  28. #include <linux/nvme.h>
  29. #include <linux/platform_data/x86/apple.h>
  30. #include <linux/pm_runtime.h>
  31. #include <linux/suspend.h>
  32. #include <linux/switchtec.h>
  33. #include "pci.h"
  34. /*
  35. * Retrain the link of a downstream PCIe port by hand if necessary.
  36. *
  37. * This is needed at least where a downstream port of the ASMedia ASM2824
  38. * Gen 3 switch is wired to the upstream port of the Pericom PI7C9X2G304
  39. * Gen 2 switch, and observed with the Delock Riser Card PCI Express x1 >
  40. * 2 x PCIe x1 device, P/N 41433, plugged into the SiFive HiFive Unmatched
  41. * board.
  42. *
  43. * In such a configuration the switches are supposed to negotiate the link
  44. * speed of preferably 5.0GT/s, falling back to 2.5GT/s. However the link
  45. * continues switching between the two speeds indefinitely and the data
  46. * link layer never reaches the active state, with link training reported
  47. * repeatedly active ~84% of the time. Forcing the target link speed to
  48. * 2.5GT/s with the upstream ASM2824 device makes the two switches talk to
  49. * each other correctly however. And more interestingly retraining with a
  50. * higher target link speed afterwards lets the two successfully negotiate
  51. * 5.0GT/s.
  52. *
  53. * With the ASM2824 we can rely on the otherwise optional Data Link Layer
  54. * Link Active status bit and in the failed link training scenario it will
  55. * be off along with the Link Bandwidth Management Status indicating that
  56. * hardware has changed the link speed or width in an attempt to correct
  57. * unreliable link operation. For a port that has been left unconnected
  58. * both bits will be clear. So use this information to detect the problem
  59. * rather than polling the Link Training bit and watching out for flips or
  60. * at least the active status.
  61. *
  62. * Since the exact nature of the problem isn't known and in principle this
  63. * could trigger where an ASM2824 device is downstream rather upstream,
  64. * apply this erratum workaround to any downstream ports as long as they
  65. * support Link Active reporting and have the Link Control 2 register.
  66. * Restrict the speed to 2.5GT/s then with the Target Link Speed field,
  67. * request a retrain and check the result.
  68. *
  69. * If this turns out successful and we know by the Vendor:Device ID it is
  70. * safe to do so, then lift the restriction, letting the devices negotiate
  71. * a higher speed. Also check for a similar 2.5GT/s speed restriction the
  72. * firmware may have already arranged and lift it with ports that already
  73. * report their data link being up.
  74. *
  75. * Otherwise revert the speed to the original setting and request a retrain
  76. * again to remove any residual state, ignoring the result as it's supposed
  77. * to fail anyway.
  78. *
  79. * Return 0 if the link has been successfully retrained. Return an error
  80. * if retraining was not needed or we attempted a retrain and it failed.
  81. */
  82. int pcie_failed_link_retrain(struct pci_dev *dev)
  83. {
  84. static const struct pci_device_id ids[] = {
  85. { PCI_VDEVICE(ASMEDIA, 0x2824) }, /* ASMedia ASM2824 */
  86. {}
  87. };
  88. u16 lnksta, lnkctl2;
  89. int ret = -ENOTTY;
  90. if (!pci_is_pcie(dev) || !pcie_downstream_port(dev) ||
  91. !pcie_cap_has_lnkctl2(dev) || !dev->link_active_reporting)
  92. return ret;
  93. pcie_capability_read_word(dev, PCI_EXP_LNKCTL2, &lnkctl2);
  94. pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
  95. if ((lnksta & (PCI_EXP_LNKSTA_LBMS | PCI_EXP_LNKSTA_DLLLA)) ==
  96. PCI_EXP_LNKSTA_LBMS) {
  97. u16 oldlnkctl2 = lnkctl2;
  98. pci_info(dev, "broken device, retraining non-functional downstream link at 2.5GT/s\n");
  99. lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS;
  100. lnkctl2 |= PCI_EXP_LNKCTL2_TLS_2_5GT;
  101. pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, lnkctl2);
  102. ret = pcie_retrain_link(dev, false);
  103. if (ret) {
  104. pci_info(dev, "retraining failed\n");
  105. pcie_capability_write_word(dev, PCI_EXP_LNKCTL2,
  106. oldlnkctl2);
  107. pcie_retrain_link(dev, true);
  108. return ret;
  109. }
  110. pcie_capability_read_word(dev, PCI_EXP_LNKSTA, &lnksta);
  111. }
  112. if ((lnksta & PCI_EXP_LNKSTA_DLLLA) &&
  113. (lnkctl2 & PCI_EXP_LNKCTL2_TLS) == PCI_EXP_LNKCTL2_TLS_2_5GT &&
  114. pci_match_id(ids, dev)) {
  115. u32 lnkcap;
  116. pci_info(dev, "removing 2.5GT/s downstream link speed restriction\n");
  117. pcie_capability_read_dword(dev, PCI_EXP_LNKCAP, &lnkcap);
  118. lnkctl2 &= ~PCI_EXP_LNKCTL2_TLS;
  119. lnkctl2 |= lnkcap & PCI_EXP_LNKCAP_SLS;
  120. pcie_capability_write_word(dev, PCI_EXP_LNKCTL2, lnkctl2);
  121. ret = pcie_retrain_link(dev, false);
  122. if (ret) {
  123. pci_info(dev, "retraining failed\n");
  124. return ret;
  125. }
  126. }
  127. return ret;
  128. }
  129. static ktime_t fixup_debug_start(struct pci_dev *dev,
  130. void (*fn)(struct pci_dev *dev))
  131. {
  132. if (initcall_debug)
  133. pci_info(dev, "calling %pS @ %i\n", fn, task_pid_nr(current));
  134. return ktime_get();
  135. }
  136. static void fixup_debug_report(struct pci_dev *dev, ktime_t calltime,
  137. void (*fn)(struct pci_dev *dev))
  138. {
  139. ktime_t delta, rettime;
  140. unsigned long long duration;
  141. rettime = ktime_get();
  142. delta = ktime_sub(rettime, calltime);
  143. duration = (unsigned long long) ktime_to_ns(delta) >> 10;
  144. if (initcall_debug || duration > 10000)
  145. pci_info(dev, "%pS took %lld usecs\n", fn, duration);
  146. }
  147. static void pci_do_fixups(struct pci_dev *dev, struct pci_fixup *f,
  148. struct pci_fixup *end)
  149. {
  150. ktime_t calltime;
  151. for (; f < end; f++)
  152. if ((f->class == (u32) (dev->class >> f->class_shift) ||
  153. f->class == (u32) PCI_ANY_ID) &&
  154. (f->vendor == dev->vendor ||
  155. f->vendor == (u16) PCI_ANY_ID) &&
  156. (f->device == dev->device ||
  157. f->device == (u16) PCI_ANY_ID)) {
  158. void (*hook)(struct pci_dev *dev);
  159. #ifdef CONFIG_HAVE_ARCH_PREL32_RELOCATIONS
  160. hook = offset_to_ptr(&f->hook_offset);
  161. #else
  162. hook = f->hook;
  163. #endif
  164. calltime = fixup_debug_start(dev, hook);
  165. hook(dev);
  166. fixup_debug_report(dev, calltime, hook);
  167. }
  168. }
  169. extern struct pci_fixup __start_pci_fixups_early[];
  170. extern struct pci_fixup __end_pci_fixups_early[];
  171. extern struct pci_fixup __start_pci_fixups_header[];
  172. extern struct pci_fixup __end_pci_fixups_header[];
  173. extern struct pci_fixup __start_pci_fixups_final[];
  174. extern struct pci_fixup __end_pci_fixups_final[];
  175. extern struct pci_fixup __start_pci_fixups_enable[];
  176. extern struct pci_fixup __end_pci_fixups_enable[];
  177. extern struct pci_fixup __start_pci_fixups_resume[];
  178. extern struct pci_fixup __end_pci_fixups_resume[];
  179. extern struct pci_fixup __start_pci_fixups_resume_early[];
  180. extern struct pci_fixup __end_pci_fixups_resume_early[];
  181. extern struct pci_fixup __start_pci_fixups_suspend[];
  182. extern struct pci_fixup __end_pci_fixups_suspend[];
  183. extern struct pci_fixup __start_pci_fixups_suspend_late[];
  184. extern struct pci_fixup __end_pci_fixups_suspend_late[];
  185. static bool pci_apply_fixup_final_quirks;
  186. void pci_fixup_device(enum pci_fixup_pass pass, struct pci_dev *dev)
  187. {
  188. struct pci_fixup *start, *end;
  189. switch (pass) {
  190. case pci_fixup_early:
  191. start = __start_pci_fixups_early;
  192. end = __end_pci_fixups_early;
  193. break;
  194. case pci_fixup_header:
  195. start = __start_pci_fixups_header;
  196. end = __end_pci_fixups_header;
  197. break;
  198. case pci_fixup_final:
  199. if (!pci_apply_fixup_final_quirks)
  200. return;
  201. start = __start_pci_fixups_final;
  202. end = __end_pci_fixups_final;
  203. break;
  204. case pci_fixup_enable:
  205. start = __start_pci_fixups_enable;
  206. end = __end_pci_fixups_enable;
  207. break;
  208. case pci_fixup_resume:
  209. start = __start_pci_fixups_resume;
  210. end = __end_pci_fixups_resume;
  211. break;
  212. case pci_fixup_resume_early:
  213. start = __start_pci_fixups_resume_early;
  214. end = __end_pci_fixups_resume_early;
  215. break;
  216. case pci_fixup_suspend:
  217. start = __start_pci_fixups_suspend;
  218. end = __end_pci_fixups_suspend;
  219. break;
  220. case pci_fixup_suspend_late:
  221. start = __start_pci_fixups_suspend_late;
  222. end = __end_pci_fixups_suspend_late;
  223. break;
  224. default:
  225. /* stupid compiler warning, you would think with an enum... */
  226. return;
  227. }
  228. pci_do_fixups(dev, start, end);
  229. }
  230. EXPORT_SYMBOL(pci_fixup_device);
  231. static int __init pci_apply_final_quirks(void)
  232. {
  233. struct pci_dev *dev = NULL;
  234. u8 cls = 0;
  235. u8 tmp;
  236. if (pci_cache_line_size)
  237. pr_info("PCI: CLS %u bytes\n", pci_cache_line_size << 2);
  238. pci_apply_fixup_final_quirks = true;
  239. for_each_pci_dev(dev) {
  240. pci_fixup_device(pci_fixup_final, dev);
  241. /*
  242. * If arch hasn't set it explicitly yet, use the CLS
  243. * value shared by all PCI devices. If there's a
  244. * mismatch, fall back to the default value.
  245. */
  246. if (!pci_cache_line_size) {
  247. pci_read_config_byte(dev, PCI_CACHE_LINE_SIZE, &tmp);
  248. if (!cls)
  249. cls = tmp;
  250. if (!tmp || cls == tmp)
  251. continue;
  252. pci_info(dev, "CLS mismatch (%u != %u), using %u bytes\n",
  253. cls << 2, tmp << 2,
  254. pci_dfl_cache_line_size << 2);
  255. pci_cache_line_size = pci_dfl_cache_line_size;
  256. }
  257. }
  258. if (!pci_cache_line_size) {
  259. pr_info("PCI: CLS %u bytes, default %u\n", cls << 2,
  260. pci_dfl_cache_line_size << 2);
  261. pci_cache_line_size = cls ? cls : pci_dfl_cache_line_size;
  262. }
  263. return 0;
  264. }
  265. fs_initcall_sync(pci_apply_final_quirks);
  266. /*
  267. * Decoding should be disabled for a PCI device during BAR sizing to avoid
  268. * conflict. But doing so may cause problems on host bridge and perhaps other
  269. * key system devices. For devices that need to have mmio decoding always-on,
  270. * we need to set the dev->mmio_always_on bit.
  271. */
  272. static void quirk_mmio_always_on(struct pci_dev *dev)
  273. {
  274. dev->mmio_always_on = 1;
  275. }
  276. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_ANY_ID, PCI_ANY_ID,
  277. PCI_CLASS_BRIDGE_HOST, 8, quirk_mmio_always_on);
  278. /*
  279. * The Mellanox Tavor device gives false positive parity errors. Disable
  280. * parity error reporting.
  281. */
  282. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_TAVOR, pci_disable_parity);
  283. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_MELLANOX, PCI_DEVICE_ID_MELLANOX_TAVOR_BRIDGE, pci_disable_parity);
  284. /*
  285. * Deal with broken BIOSes that neglect to enable passive release,
  286. * which can cause problems in combination with the 82441FX/PPro MTRRs
  287. */
  288. static void quirk_passive_release(struct pci_dev *dev)
  289. {
  290. struct pci_dev *d = NULL;
  291. unsigned char dlc;
  292. /*
  293. * We have to make sure a particular bit is set in the PIIX3
  294. * ISA bridge, so we have to go out and find it.
  295. */
  296. while ((d = pci_get_device(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371SB_0, d))) {
  297. pci_read_config_byte(d, 0x82, &dlc);
  298. if (!(dlc & 1<<1)) {
  299. pci_info(d, "PIIX3: Enabling Passive Release\n");
  300. dlc |= 1<<1;
  301. pci_write_config_byte(d, 0x82, dlc);
  302. }
  303. }
  304. }
  305. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, quirk_passive_release);
  306. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, quirk_passive_release);
  307. #ifdef CONFIG_X86_32
  308. /*
  309. * The VIA VP2/VP3/MVP3 seem to have some 'features'. There may be a
  310. * workaround but VIA don't answer queries. If you happen to have good
  311. * contacts at VIA ask them for me please -- Alan
  312. *
  313. * This appears to be BIOS not version dependent. So presumably there is a
  314. * chipset level fix.
  315. */
  316. static void quirk_isa_dma_hangs(struct pci_dev *dev)
  317. {
  318. if (!isa_dma_bridge_buggy) {
  319. isa_dma_bridge_buggy = 1;
  320. pci_info(dev, "Activating ISA DMA hang workarounds\n");
  321. }
  322. }
  323. /*
  324. * It's not totally clear which chipsets are the problematic ones. We know
  325. * 82C586 and 82C596 variants are affected.
  326. */
  327. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_0, quirk_isa_dma_hangs);
  328. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C596, quirk_isa_dma_hangs);
  329. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371SB_0, quirk_isa_dma_hangs);
  330. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1533, quirk_isa_dma_hangs);
  331. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_CBUS_1, quirk_isa_dma_hangs);
  332. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_CBUS_2, quirk_isa_dma_hangs);
  333. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NEC, PCI_DEVICE_ID_NEC_CBUS_3, quirk_isa_dma_hangs);
  334. #endif
  335. #ifdef CONFIG_HAS_IOPORT
  336. /*
  337. * Intel NM10 "Tiger Point" LPC PM1a_STS.BM_STS must be clear
  338. * for some HT machines to use C4 w/o hanging.
  339. */
  340. static void quirk_tigerpoint_bm_sts(struct pci_dev *dev)
  341. {
  342. u32 pmbase;
  343. u16 pm1a;
  344. pci_read_config_dword(dev, 0x40, &pmbase);
  345. pmbase = pmbase & 0xff80;
  346. pm1a = inw(pmbase);
  347. if (pm1a & 0x10) {
  348. pci_info(dev, FW_BUG "Tiger Point LPC.BM_STS cleared\n");
  349. outw(0x10, pmbase);
  350. }
  351. }
  352. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_TGP_LPC, quirk_tigerpoint_bm_sts);
  353. #endif
  354. /* Chipsets where PCI->PCI transfers vanish or hang */
  355. static void quirk_nopcipci(struct pci_dev *dev)
  356. {
  357. if ((pci_pci_problems & PCIPCI_FAIL) == 0) {
  358. pci_info(dev, "Disabling direct PCI/PCI transfers\n");
  359. pci_pci_problems |= PCIPCI_FAIL;
  360. }
  361. }
  362. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_5597, quirk_nopcipci);
  363. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_496, quirk_nopcipci);
  364. static void quirk_nopciamd(struct pci_dev *dev)
  365. {
  366. u8 rev;
  367. pci_read_config_byte(dev, 0x08, &rev);
  368. if (rev == 0x13) {
  369. /* Erratum 24 */
  370. pci_info(dev, "Chipset erratum: Disabling direct PCI/AGP transfers\n");
  371. pci_pci_problems |= PCIAGP_FAIL;
  372. }
  373. }
  374. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8151_0, quirk_nopciamd);
  375. /* Triton requires workarounds to be used by the drivers */
  376. static void quirk_triton(struct pci_dev *dev)
  377. {
  378. if ((pci_pci_problems&PCIPCI_TRITON) == 0) {
  379. pci_info(dev, "Limiting direct PCI/PCI transfers\n");
  380. pci_pci_problems |= PCIPCI_TRITON;
  381. }
  382. }
  383. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437, quirk_triton);
  384. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82437VX, quirk_triton);
  385. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82439, quirk_triton);
  386. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82439TX, quirk_triton);
  387. /*
  388. * VIA Apollo KT133 needs PCI latency patch
  389. * Made according to a Windows driver-based patch by George E. Breese;
  390. * see PCI Latency Adjust on http://www.viahardware.com/download/viatweak.shtm
  391. * Also see http://www.au-ja.org/review-kt133a-1-en.phtml for the info on
  392. * which Mr Breese based his work.
  393. *
  394. * Updated based on further information from the site and also on
  395. * information provided by VIA
  396. */
  397. static void quirk_vialatency(struct pci_dev *dev)
  398. {
  399. struct pci_dev *p;
  400. u8 busarb;
  401. /*
  402. * Ok, we have a potential problem chipset here. Now see if we have
  403. * a buggy southbridge.
  404. */
  405. p = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, NULL);
  406. if (p != NULL) {
  407. /*
  408. * 0x40 - 0x4f == 686B, 0x10 - 0x2f == 686A;
  409. * thanks Dan Hollis.
  410. * Check for buggy part revisions
  411. */
  412. if (p->revision < 0x40 || p->revision > 0x42)
  413. goto exit;
  414. } else {
  415. p = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231, NULL);
  416. if (p == NULL) /* No problem parts */
  417. goto exit;
  418. /* Check for buggy part revisions */
  419. if (p->revision < 0x10 || p->revision > 0x12)
  420. goto exit;
  421. }
  422. /*
  423. * Ok we have the problem. Now set the PCI master grant to occur
  424. * every master grant. The apparent bug is that under high PCI load
  425. * (quite common in Linux of course) you can get data loss when the
  426. * CPU is held off the bus for 3 bus master requests. This happens
  427. * to include the IDE controllers....
  428. *
  429. * VIA only apply this fix when an SB Live! is present but under
  430. * both Linux and Windows this isn't enough, and we have seen
  431. * corruption without SB Live! but with things like 3 UDMA IDE
  432. * controllers. So we ignore that bit of the VIA recommendation..
  433. */
  434. pci_read_config_byte(dev, 0x76, &busarb);
  435. /*
  436. * Set bit 4 and bit 5 of byte 76 to 0x01
  437. * "Master priority rotation on every PCI master grant"
  438. */
  439. busarb &= ~(1<<5);
  440. busarb |= (1<<4);
  441. pci_write_config_byte(dev, 0x76, busarb);
  442. pci_info(dev, "Applying VIA southbridge workaround\n");
  443. exit:
  444. pci_dev_put(p);
  445. }
  446. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8363_0, quirk_vialatency);
  447. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8371_1, quirk_vialatency);
  448. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8361, quirk_vialatency);
  449. /* Must restore this on a resume from RAM */
  450. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8363_0, quirk_vialatency);
  451. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8371_1, quirk_vialatency);
  452. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8361, quirk_vialatency);
  453. /* VIA Apollo VP3 needs ETBF on BT848/878 */
  454. static void quirk_viaetbf(struct pci_dev *dev)
  455. {
  456. if ((pci_pci_problems&PCIPCI_VIAETBF) == 0) {
  457. pci_info(dev, "Limiting direct PCI/PCI transfers\n");
  458. pci_pci_problems |= PCIPCI_VIAETBF;
  459. }
  460. }
  461. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C597_0, quirk_viaetbf);
  462. static void quirk_vsfx(struct pci_dev *dev)
  463. {
  464. if ((pci_pci_problems&PCIPCI_VSFX) == 0) {
  465. pci_info(dev, "Limiting direct PCI/PCI transfers\n");
  466. pci_pci_problems |= PCIPCI_VSFX;
  467. }
  468. }
  469. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C576, quirk_vsfx);
  470. /*
  471. * ALi Magik requires workarounds to be used by the drivers that DMA to AGP
  472. * space. Latency must be set to 0xA and Triton workaround applied too.
  473. * [Info kindly provided by ALi]
  474. */
  475. static void quirk_alimagik(struct pci_dev *dev)
  476. {
  477. if ((pci_pci_problems&PCIPCI_ALIMAGIK) == 0) {
  478. pci_info(dev, "Limiting direct PCI/PCI transfers\n");
  479. pci_pci_problems |= PCIPCI_ALIMAGIK|PCIPCI_TRITON;
  480. }
  481. }
  482. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1647, quirk_alimagik);
  483. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M1651, quirk_alimagik);
  484. /* Natoma has some interesting boundary conditions with Zoran stuff at least */
  485. static void quirk_natoma(struct pci_dev *dev)
  486. {
  487. if ((pci_pci_problems&PCIPCI_NATOMA) == 0) {
  488. pci_info(dev, "Limiting direct PCI/PCI transfers\n");
  489. pci_pci_problems |= PCIPCI_NATOMA;
  490. }
  491. }
  492. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82441, quirk_natoma);
  493. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443LX_0, quirk_natoma);
  494. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443LX_1, quirk_natoma);
  495. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_0, quirk_natoma);
  496. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_1, quirk_natoma);
  497. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443BX_2, quirk_natoma);
  498. /*
  499. * This chip can cause PCI parity errors if config register 0xA0 is read
  500. * while DMAs are occurring.
  501. */
  502. static void quirk_citrine(struct pci_dev *dev)
  503. {
  504. dev->cfg_size = 0xA0;
  505. }
  506. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM, PCI_DEVICE_ID_IBM_CITRINE, quirk_citrine);
  507. /*
  508. * This chip can cause bus lockups if config addresses above 0x600
  509. * are read or written.
  510. */
  511. static void quirk_nfp6000(struct pci_dev *dev)
  512. {
  513. dev->cfg_size = 0x600;
  514. }
  515. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NETRONOME, PCI_DEVICE_ID_NETRONOME_NFP4000, quirk_nfp6000);
  516. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NETRONOME, PCI_DEVICE_ID_NETRONOME_NFP6000, quirk_nfp6000);
  517. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NETRONOME, PCI_DEVICE_ID_NETRONOME_NFP5000, quirk_nfp6000);
  518. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NETRONOME, PCI_DEVICE_ID_NETRONOME_NFP6000_VF, quirk_nfp6000);
  519. /* On IBM Crocodile ipr SAS adapters, expand BAR to system page size */
  520. static void quirk_extend_bar_to_page(struct pci_dev *dev)
  521. {
  522. int i;
  523. for (i = 0; i < PCI_STD_NUM_BARS; i++) {
  524. struct resource *r = &dev->resource[i];
  525. const char *r_name = pci_resource_name(dev, i);
  526. if (r->flags & IORESOURCE_MEM && resource_size(r) < PAGE_SIZE) {
  527. r->end = PAGE_SIZE - 1;
  528. r->start = 0;
  529. r->flags |= IORESOURCE_UNSET;
  530. pci_info(dev, "%s %pR: expanded to page size\n",
  531. r_name, r);
  532. }
  533. }
  534. }
  535. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_IBM, 0x034a, quirk_extend_bar_to_page);
  536. /*
  537. * S3 868 and 968 chips report region size equal to 32M, but they decode 64M.
  538. * If it's needed, re-allocate the region.
  539. */
  540. static void quirk_s3_64M(struct pci_dev *dev)
  541. {
  542. struct resource *r = &dev->resource[0];
  543. if ((r->start & 0x3ffffff) || r->end != r->start + 0x3ffffff) {
  544. r->flags |= IORESOURCE_UNSET;
  545. r->start = 0;
  546. r->end = 0x3ffffff;
  547. }
  548. }
  549. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_S3, PCI_DEVICE_ID_S3_868, quirk_s3_64M);
  550. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_S3, PCI_DEVICE_ID_S3_968, quirk_s3_64M);
  551. static void quirk_io(struct pci_dev *dev, int pos, unsigned int size,
  552. const char *name)
  553. {
  554. u32 region;
  555. struct pci_bus_region bus_region;
  556. struct resource *res = dev->resource + pos;
  557. const char *res_name = pci_resource_name(dev, pos);
  558. pci_read_config_dword(dev, PCI_BASE_ADDRESS_0 + (pos << 2), &region);
  559. if (!region)
  560. return;
  561. res->name = pci_name(dev);
  562. res->flags = region & ~PCI_BASE_ADDRESS_IO_MASK;
  563. res->flags |=
  564. (IORESOURCE_IO | IORESOURCE_PCI_FIXED | IORESOURCE_SIZEALIGN);
  565. region &= ~(size - 1);
  566. /* Convert from PCI bus to resource space */
  567. bus_region.start = region;
  568. bus_region.end = region + size - 1;
  569. pcibios_bus_to_resource(dev->bus, res, &bus_region);
  570. pci_info(dev, FW_BUG "%s %pR: %s quirk\n", res_name, res, name);
  571. }
  572. /*
  573. * Some CS5536 BIOSes (for example, the Soekris NET5501 board w/ comBIOS
  574. * ver. 1.33 20070103) don't set the correct ISA PCI region header info.
  575. * BAR0 should be 8 bytes; instead, it may be set to something like 8k
  576. * (which conflicts w/ BAR1's memory range).
  577. *
  578. * CS553x's ISA PCI BARs may also be read-only (ref:
  579. * https://bugzilla.kernel.org/show_bug.cgi?id=85991 - Comment #4 forward).
  580. */
  581. static void quirk_cs5536_vsa(struct pci_dev *dev)
  582. {
  583. static char *name = "CS5536 ISA bridge";
  584. if (pci_resource_len(dev, 0) != 8) {
  585. quirk_io(dev, 0, 8, name); /* SMB */
  586. quirk_io(dev, 1, 256, name); /* GPIO */
  587. quirk_io(dev, 2, 64, name); /* MFGPT */
  588. pci_info(dev, "%s bug detected (incorrect header); workaround applied\n",
  589. name);
  590. }
  591. }
  592. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_CS5536_ISA, quirk_cs5536_vsa);
  593. static void quirk_io_region(struct pci_dev *dev, int port,
  594. unsigned int size, int nr, const char *name)
  595. {
  596. u16 region;
  597. struct pci_bus_region bus_region;
  598. struct resource *res = dev->resource + nr;
  599. pci_read_config_word(dev, port, &region);
  600. region &= ~(size - 1);
  601. if (!region)
  602. return;
  603. res->name = pci_name(dev);
  604. res->flags = IORESOURCE_IO;
  605. /* Convert from PCI bus to resource space */
  606. bus_region.start = region;
  607. bus_region.end = region + size - 1;
  608. pcibios_bus_to_resource(dev->bus, res, &bus_region);
  609. /*
  610. * "res" is typically a bridge window resource that's not being
  611. * used for a bridge window, so it's just a place to stash this
  612. * non-standard resource. Printing "nr" or pci_resource_name() of
  613. * it doesn't really make sense.
  614. */
  615. if (!pci_claim_resource(dev, nr))
  616. pci_info(dev, "quirk: %pR claimed by %s\n", res, name);
  617. }
  618. /*
  619. * ATI Northbridge setups MCE the processor if you even read somewhere
  620. * between 0x3b0->0x3bb or read 0x3d3
  621. */
  622. static void quirk_ati_exploding_mce(struct pci_dev *dev)
  623. {
  624. pci_info(dev, "ATI Northbridge, reserving I/O ports 0x3b0 to 0x3bb\n");
  625. /* Mae rhaid i ni beidio ag edrych ar y lleoliadiau I/O hyn */
  626. request_region(0x3b0, 0x0C, "RadeonIGP");
  627. request_region(0x3d3, 0x01, "RadeonIGP");
  628. }
  629. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS100, quirk_ati_exploding_mce);
  630. /*
  631. * In the AMD NL platform, this device ([1022:7912]) has a class code of
  632. * PCI_CLASS_SERIAL_USB_XHCI (0x0c0330), which means the xhci driver will
  633. * claim it. The same applies on the VanGogh platform device ([1022:163a]).
  634. *
  635. * But the dwc3 driver is a more specific driver for this device, and we'd
  636. * prefer to use it instead of xhci. To prevent xhci from claiming the
  637. * device, change the class code to 0x0c03fe, which the PCI r3.0 spec
  638. * defines as "USB device (not host controller)". The dwc3 driver can then
  639. * claim it based on its Vendor and Device ID.
  640. */
  641. static void quirk_amd_dwc_class(struct pci_dev *pdev)
  642. {
  643. u32 class = pdev->class;
  644. if (class != PCI_CLASS_SERIAL_USB_DEVICE) {
  645. /* Use "USB Device (not host controller)" class */
  646. pdev->class = PCI_CLASS_SERIAL_USB_DEVICE;
  647. pci_info(pdev,
  648. "PCI class overridden (%#08x -> %#08x) so dwc3 driver can claim this instead of xhci\n",
  649. class, pdev->class);
  650. }
  651. }
  652. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_NL_USB,
  653. quirk_amd_dwc_class);
  654. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VANGOGH_USB,
  655. quirk_amd_dwc_class);
  656. /*
  657. * Synopsys USB 3.x host HAPS platform has a class code of
  658. * PCI_CLASS_SERIAL_USB_XHCI, and xhci driver can claim it. However, these
  659. * devices should use dwc3-haps driver. Change these devices' class code to
  660. * PCI_CLASS_SERIAL_USB_DEVICE to prevent the xhci-pci driver from claiming
  661. * them.
  662. */
  663. static void quirk_synopsys_haps(struct pci_dev *pdev)
  664. {
  665. u32 class = pdev->class;
  666. switch (pdev->device) {
  667. case PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3:
  668. case PCI_DEVICE_ID_SYNOPSYS_HAPSUSB3_AXI:
  669. case PCI_DEVICE_ID_SYNOPSYS_HAPSUSB31:
  670. pdev->class = PCI_CLASS_SERIAL_USB_DEVICE;
  671. pci_info(pdev, "PCI class overridden (%#08x -> %#08x) so dwc3 driver can claim this instead of xhci\n",
  672. class, pdev->class);
  673. break;
  674. }
  675. }
  676. DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_VENDOR_ID_SYNOPSYS, PCI_ANY_ID,
  677. PCI_CLASS_SERIAL_USB_XHCI, 0,
  678. quirk_synopsys_haps);
  679. /*
  680. * Let's make the southbridge information explicit instead of having to
  681. * worry about people probing the ACPI areas, for example.. (Yes, it
  682. * happens, and if you read the wrong ACPI register it will put the machine
  683. * to sleep with no way of waking it up again. Bummer).
  684. *
  685. * ALI M7101: Two IO regions pointed to by words at
  686. * 0xE0 (64 bytes of ACPI registers)
  687. * 0xE2 (32 bytes of SMB registers)
  688. */
  689. static void quirk_ali7101_acpi(struct pci_dev *dev)
  690. {
  691. quirk_io_region(dev, 0xE0, 64, PCI_BRIDGE_RESOURCES, "ali7101 ACPI");
  692. quirk_io_region(dev, 0xE2, 32, PCI_BRIDGE_RESOURCES+1, "ali7101 SMB");
  693. }
  694. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AL, PCI_DEVICE_ID_AL_M7101, quirk_ali7101_acpi);
  695. static void piix4_io_quirk(struct pci_dev *dev, const char *name, unsigned int port, unsigned int enable)
  696. {
  697. u32 devres;
  698. u32 mask, size, base;
  699. pci_read_config_dword(dev, port, &devres);
  700. if ((devres & enable) != enable)
  701. return;
  702. mask = (devres >> 16) & 15;
  703. base = devres & 0xffff;
  704. size = 16;
  705. for (;;) {
  706. unsigned int bit = size >> 1;
  707. if ((bit & mask) == bit)
  708. break;
  709. size = bit;
  710. }
  711. /*
  712. * For now we only print it out. Eventually we'll want to
  713. * reserve it (at least if it's in the 0x1000+ range), but
  714. * let's get enough confirmation reports first.
  715. */
  716. base &= -size;
  717. pci_info(dev, "%s PIO at %04x-%04x\n", name, base, base + size - 1);
  718. }
  719. static void piix4_mem_quirk(struct pci_dev *dev, const char *name, unsigned int port, unsigned int enable)
  720. {
  721. u32 devres;
  722. u32 mask, size, base;
  723. pci_read_config_dword(dev, port, &devres);
  724. if ((devres & enable) != enable)
  725. return;
  726. base = devres & 0xffff0000;
  727. mask = (devres & 0x3f) << 16;
  728. size = 128 << 16;
  729. for (;;) {
  730. unsigned int bit = size >> 1;
  731. if ((bit & mask) == bit)
  732. break;
  733. size = bit;
  734. }
  735. /*
  736. * For now we only print it out. Eventually we'll want to
  737. * reserve it, but let's get enough confirmation reports first.
  738. */
  739. base &= -size;
  740. pci_info(dev, "%s MMIO at %04x-%04x\n", name, base, base + size - 1);
  741. }
  742. /*
  743. * PIIX4 ACPI: Two IO regions pointed to by longwords at
  744. * 0x40 (64 bytes of ACPI registers)
  745. * 0x90 (16 bytes of SMB registers)
  746. * and a few strange programmable PIIX4 device resources.
  747. */
  748. static void quirk_piix4_acpi(struct pci_dev *dev)
  749. {
  750. u32 res_a;
  751. quirk_io_region(dev, 0x40, 64, PCI_BRIDGE_RESOURCES, "PIIX4 ACPI");
  752. quirk_io_region(dev, 0x90, 16, PCI_BRIDGE_RESOURCES+1, "PIIX4 SMB");
  753. /* Device resource A has enables for some of the other ones */
  754. pci_read_config_dword(dev, 0x5c, &res_a);
  755. piix4_io_quirk(dev, "PIIX4 devres B", 0x60, 3 << 21);
  756. piix4_io_quirk(dev, "PIIX4 devres C", 0x64, 3 << 21);
  757. /* Device resource D is just bitfields for static resources */
  758. /* Device 12 enabled? */
  759. if (res_a & (1 << 29)) {
  760. piix4_io_quirk(dev, "PIIX4 devres E", 0x68, 1 << 20);
  761. piix4_mem_quirk(dev, "PIIX4 devres F", 0x6c, 1 << 7);
  762. }
  763. /* Device 13 enabled? */
  764. if (res_a & (1 << 30)) {
  765. piix4_io_quirk(dev, "PIIX4 devres G", 0x70, 1 << 20);
  766. piix4_mem_quirk(dev, "PIIX4 devres H", 0x74, 1 << 7);
  767. }
  768. piix4_io_quirk(dev, "PIIX4 devres I", 0x78, 1 << 20);
  769. piix4_io_quirk(dev, "PIIX4 devres J", 0x7c, 1 << 20);
  770. }
  771. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82371AB_3, quirk_piix4_acpi);
  772. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82443MX_3, quirk_piix4_acpi);
  773. #define ICH_PMBASE 0x40
  774. #define ICH_ACPI_CNTL 0x44
  775. #define ICH4_ACPI_EN 0x10
  776. #define ICH6_ACPI_EN 0x80
  777. #define ICH4_GPIOBASE 0x58
  778. #define ICH4_GPIO_CNTL 0x5c
  779. #define ICH4_GPIO_EN 0x10
  780. #define ICH6_GPIOBASE 0x48
  781. #define ICH6_GPIO_CNTL 0x4c
  782. #define ICH6_GPIO_EN 0x10
  783. /*
  784. * ICH4, ICH4-M, ICH5, ICH5-M ACPI: Three IO regions pointed to by longwords at
  785. * 0x40 (128 bytes of ACPI, GPIO & TCO registers)
  786. * 0x58 (64 bytes of GPIO I/O space)
  787. */
  788. static void quirk_ich4_lpc_acpi(struct pci_dev *dev)
  789. {
  790. u8 enable;
  791. /*
  792. * The check for PCIBIOS_MIN_IO is to ensure we won't create a conflict
  793. * with low legacy (and fixed) ports. We don't know the decoding
  794. * priority and can't tell whether the legacy device or the one created
  795. * here is really at that address. This happens on boards with broken
  796. * BIOSes.
  797. */
  798. pci_read_config_byte(dev, ICH_ACPI_CNTL, &enable);
  799. if (enable & ICH4_ACPI_EN)
  800. quirk_io_region(dev, ICH_PMBASE, 128, PCI_BRIDGE_RESOURCES,
  801. "ICH4 ACPI/GPIO/TCO");
  802. pci_read_config_byte(dev, ICH4_GPIO_CNTL, &enable);
  803. if (enable & ICH4_GPIO_EN)
  804. quirk_io_region(dev, ICH4_GPIOBASE, 64, PCI_BRIDGE_RESOURCES+1,
  805. "ICH4 GPIO");
  806. }
  807. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, quirk_ich4_lpc_acpi);
  808. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AB_0, quirk_ich4_lpc_acpi);
  809. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, quirk_ich4_lpc_acpi);
  810. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_10, quirk_ich4_lpc_acpi);
  811. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, quirk_ich4_lpc_acpi);
  812. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, quirk_ich4_lpc_acpi);
  813. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, quirk_ich4_lpc_acpi);
  814. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, quirk_ich4_lpc_acpi);
  815. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, quirk_ich4_lpc_acpi);
  816. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_1, quirk_ich4_lpc_acpi);
  817. static void ich6_lpc_acpi_gpio(struct pci_dev *dev)
  818. {
  819. u8 enable;
  820. pci_read_config_byte(dev, ICH_ACPI_CNTL, &enable);
  821. if (enable & ICH6_ACPI_EN)
  822. quirk_io_region(dev, ICH_PMBASE, 128, PCI_BRIDGE_RESOURCES,
  823. "ICH6 ACPI/GPIO/TCO");
  824. pci_read_config_byte(dev, ICH6_GPIO_CNTL, &enable);
  825. if (enable & ICH6_GPIO_EN)
  826. quirk_io_region(dev, ICH6_GPIOBASE, 64, PCI_BRIDGE_RESOURCES+1,
  827. "ICH6 GPIO");
  828. }
  829. static void ich6_lpc_generic_decode(struct pci_dev *dev, unsigned int reg,
  830. const char *name, int dynsize)
  831. {
  832. u32 val;
  833. u32 size, base;
  834. pci_read_config_dword(dev, reg, &val);
  835. /* Enabled? */
  836. if (!(val & 1))
  837. return;
  838. base = val & 0xfffc;
  839. if (dynsize) {
  840. /*
  841. * This is not correct. It is 16, 32 or 64 bytes depending on
  842. * register D31:F0:ADh bits 5:4.
  843. *
  844. * But this gets us at least _part_ of it.
  845. */
  846. size = 16;
  847. } else {
  848. size = 128;
  849. }
  850. base &= ~(size-1);
  851. /*
  852. * Just print it out for now. We should reserve it after more
  853. * debugging.
  854. */
  855. pci_info(dev, "%s PIO at %04x-%04x\n", name, base, base+size-1);
  856. }
  857. static void quirk_ich6_lpc(struct pci_dev *dev)
  858. {
  859. /* Shared ACPI/GPIO decode with all ICH6+ */
  860. ich6_lpc_acpi_gpio(dev);
  861. /* ICH6-specific generic IO decode */
  862. ich6_lpc_generic_decode(dev, 0x84, "LPC Generic IO decode 1", 0);
  863. ich6_lpc_generic_decode(dev, 0x88, "LPC Generic IO decode 2", 1);
  864. }
  865. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_0, quirk_ich6_lpc);
  866. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, quirk_ich6_lpc);
  867. static void ich7_lpc_generic_decode(struct pci_dev *dev, unsigned int reg,
  868. const char *name)
  869. {
  870. u32 val;
  871. u32 mask, base;
  872. pci_read_config_dword(dev, reg, &val);
  873. /* Enabled? */
  874. if (!(val & 1))
  875. return;
  876. /* IO base in bits 15:2, mask in bits 23:18, both are dword-based */
  877. base = val & 0xfffc;
  878. mask = (val >> 16) & 0xfc;
  879. mask |= 3;
  880. /*
  881. * Just print it out for now. We should reserve it after more
  882. * debugging.
  883. */
  884. pci_info(dev, "%s PIO at %04x (mask %04x)\n", name, base, mask);
  885. }
  886. /* ICH7-10 has the same common LPC generic IO decode registers */
  887. static void quirk_ich7_lpc(struct pci_dev *dev)
  888. {
  889. /* We share the common ACPI/GPIO decode with ICH6 */
  890. ich6_lpc_acpi_gpio(dev);
  891. /* And have 4 ICH7+ generic decodes */
  892. ich7_lpc_generic_decode(dev, 0x84, "ICH7 LPC Generic IO decode 1");
  893. ich7_lpc_generic_decode(dev, 0x88, "ICH7 LPC Generic IO decode 2");
  894. ich7_lpc_generic_decode(dev, 0x8c, "ICH7 LPC Generic IO decode 3");
  895. ich7_lpc_generic_decode(dev, 0x90, "ICH7 LPC Generic IO decode 4");
  896. }
  897. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_0, quirk_ich7_lpc);
  898. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_1, quirk_ich7_lpc);
  899. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH7_31, quirk_ich7_lpc);
  900. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_0, quirk_ich7_lpc);
  901. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_2, quirk_ich7_lpc);
  902. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_3, quirk_ich7_lpc);
  903. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_1, quirk_ich7_lpc);
  904. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH8_4, quirk_ich7_lpc);
  905. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_2, quirk_ich7_lpc);
  906. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_4, quirk_ich7_lpc);
  907. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_7, quirk_ich7_lpc);
  908. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH9_8, quirk_ich7_lpc);
  909. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH10_1, quirk_ich7_lpc);
  910. /*
  911. * VIA ACPI: One IO region pointed to by longword at
  912. * 0x48 or 0x20 (256 bytes of ACPI registers)
  913. */
  914. static void quirk_vt82c586_acpi(struct pci_dev *dev)
  915. {
  916. if (dev->revision & 0x10)
  917. quirk_io_region(dev, 0x48, 256, PCI_BRIDGE_RESOURCES,
  918. "vt82c586 ACPI");
  919. }
  920. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_vt82c586_acpi);
  921. /*
  922. * VIA VT82C686 ACPI: Three IO region pointed to by (long)words at
  923. * 0x48 (256 bytes of ACPI registers)
  924. * 0x70 (128 bytes of hardware monitoring register)
  925. * 0x90 (16 bytes of SMB registers)
  926. */
  927. static void quirk_vt82c686_acpi(struct pci_dev *dev)
  928. {
  929. quirk_vt82c586_acpi(dev);
  930. quirk_io_region(dev, 0x70, 128, PCI_BRIDGE_RESOURCES+1,
  931. "vt82c686 HW-mon");
  932. quirk_io_region(dev, 0x90, 16, PCI_BRIDGE_RESOURCES+2, "vt82c686 SMB");
  933. }
  934. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_vt82c686_acpi);
  935. /*
  936. * VIA VT8235 ISA Bridge: Two IO regions pointed to by words at
  937. * 0x88 (128 bytes of power management registers)
  938. * 0xd0 (16 bytes of SMB registers)
  939. */
  940. static void quirk_vt8235_acpi(struct pci_dev *dev)
  941. {
  942. quirk_io_region(dev, 0x88, 128, PCI_BRIDGE_RESOURCES, "vt8235 PM");
  943. quirk_io_region(dev, 0xd0, 16, PCI_BRIDGE_RESOURCES+1, "vt8235 SMB");
  944. }
  945. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, quirk_vt8235_acpi);
  946. /*
  947. * TI XIO2000a PCIe-PCI Bridge erroneously reports it supports fast
  948. * back-to-back: Disable fast back-to-back on the secondary bus segment
  949. */
  950. static void quirk_xio2000a(struct pci_dev *dev)
  951. {
  952. struct pci_dev *pdev;
  953. u16 command;
  954. pci_warn(dev, "TI XIO2000a quirk detected; secondary bus fast back-to-back transfers disabled\n");
  955. list_for_each_entry(pdev, &dev->subordinate->devices, bus_list) {
  956. pci_read_config_word(pdev, PCI_COMMAND, &command);
  957. if (command & PCI_COMMAND_FAST_BACK)
  958. pci_write_config_word(pdev, PCI_COMMAND, command & ~PCI_COMMAND_FAST_BACK);
  959. }
  960. }
  961. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_TI, PCI_DEVICE_ID_TI_XIO2000A,
  962. quirk_xio2000a);
  963. #ifdef CONFIG_X86_IO_APIC
  964. #include <asm/io_apic.h>
  965. /*
  966. * VIA 686A/B: If an IO-APIC is active, we need to route all on-chip
  967. * devices to the external APIC.
  968. *
  969. * TODO: When we have device-specific interrupt routers, this code will go
  970. * away from quirks.
  971. */
  972. static void quirk_via_ioapic(struct pci_dev *dev)
  973. {
  974. u8 tmp;
  975. if (nr_ioapics < 1)
  976. tmp = 0; /* nothing routed to external APIC */
  977. else
  978. tmp = 0x1f; /* all known bits (4-0) routed to external APIC */
  979. pci_info(dev, "%s VIA external APIC routing\n",
  980. tmp ? "Enabling" : "Disabling");
  981. /* Offset 0x58: External APIC IRQ output control */
  982. pci_write_config_byte(dev, 0x58, tmp);
  983. }
  984. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic);
  985. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_ioapic);
  986. /*
  987. * VIA 8237: Some BIOSes don't set the 'Bypass APIC De-Assert Message' Bit.
  988. * This leads to doubled level interrupt rates.
  989. * Set this bit to get rid of cycle wastage.
  990. * Otherwise uncritical.
  991. */
  992. static void quirk_via_vt8237_bypass_apic_deassert(struct pci_dev *dev)
  993. {
  994. u8 misc_control2;
  995. #define BYPASS_APIC_DEASSERT 8
  996. pci_read_config_byte(dev, 0x5B, &misc_control2);
  997. if (!(misc_control2 & BYPASS_APIC_DEASSERT)) {
  998. pci_info(dev, "Bypassing VIA 8237 APIC De-Assert Message\n");
  999. pci_write_config_byte(dev, 0x5B, misc_control2|BYPASS_APIC_DEASSERT);
  1000. }
  1001. }
  1002. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert);
  1003. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_vt8237_bypass_apic_deassert);
  1004. /*
  1005. * The AMD IO-APIC can hang the box when an APIC IRQ is masked.
  1006. * We check all revs >= B0 (yet not in the pre production!) as the bug
  1007. * is currently marked NoFix
  1008. *
  1009. * We have multiple reports of hangs with this chipset that went away with
  1010. * noapic specified. For the moment we assume it's the erratum. We may be wrong
  1011. * of course. However the advice is demonstrably good even if so.
  1012. */
  1013. static void quirk_amd_ioapic(struct pci_dev *dev)
  1014. {
  1015. if (dev->revision >= 0x02) {
  1016. pci_warn(dev, "I/O APIC: AMD Erratum #22 may be present. In the event of instability try\n");
  1017. pci_warn(dev, " : booting with the \"noapic\" option\n");
  1018. }
  1019. }
  1020. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_VIPER_7410, quirk_amd_ioapic);
  1021. #endif /* CONFIG_X86_IO_APIC */
  1022. #if defined(CONFIG_ARM64) && defined(CONFIG_PCI_ATS)
  1023. static void quirk_cavium_sriov_rnm_link(struct pci_dev *dev)
  1024. {
  1025. /* Fix for improper SR-IOV configuration on Cavium cn88xx RNM device */
  1026. if (dev->subsystem_device == 0xa118)
  1027. dev->sriov->link = dev->devfn;
  1028. }
  1029. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CAVIUM, 0xa018, quirk_cavium_sriov_rnm_link);
  1030. #endif
  1031. /*
  1032. * Some settings of MMRBC can lead to data corruption so block changes.
  1033. * See AMD 8131 HyperTransport PCI-X Tunnel Revision Guide
  1034. */
  1035. static void quirk_amd_8131_mmrbc(struct pci_dev *dev)
  1036. {
  1037. if (dev->subordinate && dev->revision <= 0x12) {
  1038. pci_info(dev, "AMD8131 rev %x detected; disabling PCI-X MMRBC\n",
  1039. dev->revision);
  1040. dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MMRBC;
  1041. }
  1042. }
  1043. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_amd_8131_mmrbc);
  1044. /*
  1045. * FIXME: it is questionable that quirk_via_acpi() is needed. It shows up
  1046. * as an ISA bridge, and does not support the PCI_INTERRUPT_LINE register
  1047. * at all. Therefore it seems like setting the pci_dev's IRQ to the value
  1048. * of the ACPI SCI interrupt is only done for convenience.
  1049. * -jgarzik
  1050. */
  1051. static void quirk_via_acpi(struct pci_dev *d)
  1052. {
  1053. u8 irq;
  1054. /* VIA ACPI device: SCI IRQ line in PCI config byte 0x42 */
  1055. pci_read_config_byte(d, 0x42, &irq);
  1056. irq &= 0xf;
  1057. if (irq && (irq != 2))
  1058. d->irq = irq;
  1059. }
  1060. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C586_3, quirk_via_acpi);
  1061. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686_4, quirk_via_acpi);
  1062. /* VIA bridges which have VLink */
  1063. static int via_vlink_dev_lo = -1, via_vlink_dev_hi = 18;
  1064. static void quirk_via_bridge(struct pci_dev *dev)
  1065. {
  1066. /* See what bridge we have and find the device ranges */
  1067. switch (dev->device) {
  1068. case PCI_DEVICE_ID_VIA_82C686:
  1069. /*
  1070. * The VT82C686 is special; it attaches to PCI and can have
  1071. * any device number. All its subdevices are functions of
  1072. * that single device.
  1073. */
  1074. via_vlink_dev_lo = PCI_SLOT(dev->devfn);
  1075. via_vlink_dev_hi = PCI_SLOT(dev->devfn);
  1076. break;
  1077. case PCI_DEVICE_ID_VIA_8237:
  1078. case PCI_DEVICE_ID_VIA_8237A:
  1079. via_vlink_dev_lo = 15;
  1080. break;
  1081. case PCI_DEVICE_ID_VIA_8235:
  1082. via_vlink_dev_lo = 16;
  1083. break;
  1084. case PCI_DEVICE_ID_VIA_8231:
  1085. case PCI_DEVICE_ID_VIA_8233_0:
  1086. case PCI_DEVICE_ID_VIA_8233A:
  1087. case PCI_DEVICE_ID_VIA_8233C_0:
  1088. via_vlink_dev_lo = 17;
  1089. break;
  1090. }
  1091. }
  1092. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C686, quirk_via_bridge);
  1093. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8231, quirk_via_bridge);
  1094. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233_0, quirk_via_bridge);
  1095. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233A, quirk_via_bridge);
  1096. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8233C_0, quirk_via_bridge);
  1097. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235, quirk_via_bridge);
  1098. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, quirk_via_bridge);
  1099. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237A, quirk_via_bridge);
  1100. /*
  1101. * quirk_via_vlink - VIA VLink IRQ number update
  1102. * @dev: PCI device
  1103. *
  1104. * If the device we are dealing with is on a PIC IRQ we need to ensure that
  1105. * the IRQ line register which usually is not relevant for PCI cards, is
  1106. * actually written so that interrupts get sent to the right place.
  1107. *
  1108. * We only do this on systems where a VIA south bridge was detected, and
  1109. * only for VIA devices on the motherboard (see quirk_via_bridge above).
  1110. */
  1111. static void quirk_via_vlink(struct pci_dev *dev)
  1112. {
  1113. u8 irq, new_irq;
  1114. /* Check if we have VLink at all */
  1115. if (via_vlink_dev_lo == -1)
  1116. return;
  1117. new_irq = dev->irq;
  1118. /* Don't quirk interrupts outside the legacy IRQ range */
  1119. if (!new_irq || new_irq > 15)
  1120. return;
  1121. /* Internal device ? */
  1122. if (dev->bus->number != 0 || PCI_SLOT(dev->devfn) > via_vlink_dev_hi ||
  1123. PCI_SLOT(dev->devfn) < via_vlink_dev_lo)
  1124. return;
  1125. /*
  1126. * This is an internal VLink device on a PIC interrupt. The BIOS
  1127. * ought to have set this but may not have, so we redo it.
  1128. */
  1129. pci_read_config_byte(dev, PCI_INTERRUPT_LINE, &irq);
  1130. if (new_irq != irq) {
  1131. pci_info(dev, "VIA VLink IRQ fixup, from %d to %d\n",
  1132. irq, new_irq);
  1133. udelay(15); /* unknown if delay really needed */
  1134. pci_write_config_byte(dev, PCI_INTERRUPT_LINE, new_irq);
  1135. }
  1136. }
  1137. DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_VIA, PCI_ANY_ID, quirk_via_vlink);
  1138. /*
  1139. * VIA VT82C598 has its device ID settable and many BIOSes set it to the ID
  1140. * of VT82C597 for backward compatibility. We need to switch it off to be
  1141. * able to recognize the real type of the chip.
  1142. */
  1143. static void quirk_vt82c598_id(struct pci_dev *dev)
  1144. {
  1145. pci_write_config_byte(dev, 0xfc, 0);
  1146. pci_read_config_word(dev, PCI_DEVICE_ID, &dev->device);
  1147. }
  1148. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_82C597_0, quirk_vt82c598_id);
  1149. /*
  1150. * CardBus controllers have a legacy base address that enables them to
  1151. * respond as i82365 pcmcia controllers. We don't want them to do this
  1152. * even if the Linux CardBus driver is not loaded, because the Linux i82365
  1153. * driver does not (and should not) handle CardBus.
  1154. */
  1155. static void quirk_cardbus_legacy(struct pci_dev *dev)
  1156. {
  1157. pci_write_config_dword(dev, PCI_CB_LEGACY_MODE_BASE, 0);
  1158. }
  1159. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_ANY_ID, PCI_ANY_ID,
  1160. PCI_CLASS_BRIDGE_CARDBUS, 8, quirk_cardbus_legacy);
  1161. DECLARE_PCI_FIXUP_CLASS_RESUME_EARLY(PCI_ANY_ID, PCI_ANY_ID,
  1162. PCI_CLASS_BRIDGE_CARDBUS, 8, quirk_cardbus_legacy);
  1163. /*
  1164. * Following the PCI ordering rules is optional on the AMD762. I'm not sure
  1165. * what the designers were smoking but let's not inhale...
  1166. *
  1167. * To be fair to AMD, it follows the spec by default, it's BIOS people who
  1168. * turn it off!
  1169. */
  1170. static void quirk_amd_ordering(struct pci_dev *dev)
  1171. {
  1172. u32 pcic;
  1173. pci_read_config_dword(dev, 0x4C, &pcic);
  1174. if ((pcic & 6) != 6) {
  1175. pcic |= 6;
  1176. pci_warn(dev, "BIOS failed to enable PCI standards compliance; fixing this error\n");
  1177. pci_write_config_dword(dev, 0x4C, pcic);
  1178. pci_read_config_dword(dev, 0x84, &pcic);
  1179. pcic |= (1 << 23); /* Required in this mode */
  1180. pci_write_config_dword(dev, 0x84, pcic);
  1181. }
  1182. }
  1183. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering);
  1184. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_FE_GATE_700C, quirk_amd_ordering);
  1185. /*
  1186. * DreamWorks-provided workaround for Dunord I-3000 problem
  1187. *
  1188. * This card decodes and responds to addresses not apparently assigned to
  1189. * it. We force a larger allocation to ensure that nothing gets put too
  1190. * close to it.
  1191. */
  1192. static void quirk_dunord(struct pci_dev *dev)
  1193. {
  1194. struct resource *r = &dev->resource[1];
  1195. r->flags |= IORESOURCE_UNSET;
  1196. r->start = 0;
  1197. r->end = 0xffffff;
  1198. }
  1199. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_DUNORD, PCI_DEVICE_ID_DUNORD_I3000, quirk_dunord);
  1200. /*
  1201. * i82380FB mobile docking controller: its PCI-to-PCI bridge is subtractive
  1202. * decoding (transparent), and does indicate this in the ProgIf.
  1203. * Unfortunately, the ProgIf value is wrong - 0x80 instead of 0x01.
  1204. */
  1205. static void quirk_transparent_bridge(struct pci_dev *dev)
  1206. {
  1207. dev->transparent = 1;
  1208. }
  1209. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82380FB, quirk_transparent_bridge);
  1210. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TOSHIBA, 0x605, quirk_transparent_bridge);
  1211. /*
  1212. * Common misconfiguration of the MediaGX/Geode PCI master that will reduce
  1213. * PCI bandwidth from 70MB/s to 25MB/s. See the GXM/GXLV/GX1 datasheets
  1214. * found at http://www.national.com/analog for info on what these bits do.
  1215. * <christer@weinigel.se>
  1216. */
  1217. static void quirk_mediagx_master(struct pci_dev *dev)
  1218. {
  1219. u8 reg;
  1220. pci_read_config_byte(dev, 0x41, &reg);
  1221. if (reg & 2) {
  1222. reg &= ~2;
  1223. pci_info(dev, "Fixup for MediaGX/Geode Slave Disconnect Boundary (0x41=0x%02x)\n",
  1224. reg);
  1225. pci_write_config_byte(dev, 0x41, reg);
  1226. }
  1227. }
  1228. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master);
  1229. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_CYRIX, PCI_DEVICE_ID_CYRIX_PCI_MASTER, quirk_mediagx_master);
  1230. /*
  1231. * Ensure C0 rev restreaming is off. This is normally done by the BIOS but
  1232. * in the odd case it is not the results are corruption hence the presence
  1233. * of a Linux check.
  1234. */
  1235. static void quirk_disable_pxb(struct pci_dev *pdev)
  1236. {
  1237. u16 config;
  1238. if (pdev->revision != 0x04) /* Only C0 requires this */
  1239. return;
  1240. pci_read_config_word(pdev, 0x40, &config);
  1241. if (config & (1<<6)) {
  1242. config &= ~(1<<6);
  1243. pci_write_config_word(pdev, 0x40, config);
  1244. pci_info(pdev, "C0 revision 450NX. Disabling PCI restreaming\n");
  1245. }
  1246. }
  1247. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb);
  1248. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82454NX, quirk_disable_pxb);
  1249. static void quirk_amd_ide_mode(struct pci_dev *pdev)
  1250. {
  1251. /* set SBX00/Hudson-2 SATA in IDE mode to AHCI mode */
  1252. u8 tmp;
  1253. pci_read_config_byte(pdev, PCI_CLASS_DEVICE, &tmp);
  1254. if (tmp == 0x01) {
  1255. pci_read_config_byte(pdev, 0x40, &tmp);
  1256. pci_write_config_byte(pdev, 0x40, tmp|1);
  1257. pci_write_config_byte(pdev, 0x9, 1);
  1258. pci_write_config_byte(pdev, 0xa, 6);
  1259. pci_write_config_byte(pdev, 0x40, tmp);
  1260. pdev->class = PCI_CLASS_STORAGE_SATA_AHCI;
  1261. pci_info(pdev, "set SATA to AHCI mode\n");
  1262. }
  1263. }
  1264. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode);
  1265. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP600_SATA, quirk_amd_ide_mode);
  1266. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode);
  1267. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_IXP700_SATA, quirk_amd_ide_mode);
  1268. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SATA_IDE, quirk_amd_ide_mode);
  1269. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_HUDSON2_SATA_IDE, quirk_amd_ide_mode);
  1270. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, 0x7900, quirk_amd_ide_mode);
  1271. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AMD, 0x7900, quirk_amd_ide_mode);
  1272. /* Serverworks CSB5 IDE does not fully support native mode */
  1273. static void quirk_svwks_csb5ide(struct pci_dev *pdev)
  1274. {
  1275. u8 prog;
  1276. pci_read_config_byte(pdev, PCI_CLASS_PROG, &prog);
  1277. if (prog & 5) {
  1278. prog &= ~5;
  1279. pdev->class &= ~5;
  1280. pci_write_config_byte(pdev, PCI_CLASS_PROG, prog);
  1281. /* PCI layer will sort out resources */
  1282. }
  1283. }
  1284. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_CSB5IDE, quirk_svwks_csb5ide);
  1285. /* Intel 82801CAM ICH3-M datasheet says IDE modes must be the same */
  1286. static void quirk_ide_samemode(struct pci_dev *pdev)
  1287. {
  1288. u8 prog;
  1289. pci_read_config_byte(pdev, PCI_CLASS_PROG, &prog);
  1290. if (((prog & 1) && !(prog & 4)) || ((prog & 4) && !(prog & 1))) {
  1291. pci_info(pdev, "IDE mode mismatch; forcing legacy mode\n");
  1292. prog &= ~5;
  1293. pdev->class &= ~5;
  1294. pci_write_config_byte(pdev, PCI_CLASS_PROG, prog);
  1295. }
  1296. }
  1297. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_10, quirk_ide_samemode);
  1298. /* Some ATA devices break if put into D3 */
  1299. static void quirk_no_ata_d3(struct pci_dev *pdev)
  1300. {
  1301. pdev->dev_flags |= PCI_DEV_FLAGS_NO_D3;
  1302. }
  1303. /* Quirk the legacy ATA devices only. The AHCI ones are ok */
  1304. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_SERVERWORKS, PCI_ANY_ID,
  1305. PCI_CLASS_STORAGE_IDE, 8, quirk_no_ata_d3);
  1306. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_ATI, PCI_ANY_ID,
  1307. PCI_CLASS_STORAGE_IDE, 8, quirk_no_ata_d3);
  1308. /* ALi loses some register settings that we cannot then restore */
  1309. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_AL, PCI_ANY_ID,
  1310. PCI_CLASS_STORAGE_IDE, 8, quirk_no_ata_d3);
  1311. /* VIA comes back fine but we need to keep it alive or ACPI GTM failures
  1312. occur when mode detecting */
  1313. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_VIA, PCI_ANY_ID,
  1314. PCI_CLASS_STORAGE_IDE, 8, quirk_no_ata_d3);
  1315. /*
  1316. * This was originally an Alpha-specific thing, but it really fits here.
  1317. * The i82375 PCI/EISA bridge appears as non-classified. Fix that.
  1318. */
  1319. static void quirk_eisa_bridge(struct pci_dev *dev)
  1320. {
  1321. dev->class = PCI_CLASS_BRIDGE_EISA << 8;
  1322. }
  1323. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82375, quirk_eisa_bridge);
  1324. /*
  1325. * On ASUS P4B boards, the SMBus PCI Device within the ICH2/4 southbridge
  1326. * is not activated. The myth is that Asus said that they do not want the
  1327. * users to be irritated by just another PCI Device in the Win98 device
  1328. * manager. (see the file prog/hotplug/README.p4b in the lm_sensors
  1329. * package 2.7.0 for details)
  1330. *
  1331. * The SMBus PCI Device can be activated by setting a bit in the ICH LPC
  1332. * bridge. Unfortunately, this device has no subvendor/subdevice ID. So it
  1333. * becomes necessary to do this tweak in two steps -- the chosen trigger
  1334. * is either the Host bridge (preferred) or on-board VGA controller.
  1335. *
  1336. * Note that we used to unhide the SMBus that way on Toshiba laptops
  1337. * (Satellite A40 and Tecra M2) but then found that the thermal management
  1338. * was done by SMM code, which could cause unsynchronized concurrent
  1339. * accesses to the SMBus registers, with potentially bad effects. Thus you
  1340. * should be very careful when adding new entries: if SMM is accessing the
  1341. * Intel SMBus, this is a very good reason to leave it hidden.
  1342. *
  1343. * Likewise, many recent laptops use ACPI for thermal management. If the
  1344. * ACPI DSDT code accesses the SMBus, then Linux should not access it
  1345. * natively, and keeping the SMBus hidden is the right thing to do. If you
  1346. * are about to add an entry in the table below, please first disassemble
  1347. * the DSDT and double-check that there is no code accessing the SMBus.
  1348. */
  1349. static int asus_hides_smbus;
  1350. static void asus_hides_smbus_hostbridge(struct pci_dev *dev)
  1351. {
  1352. if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_ASUSTEK)) {
  1353. if (dev->device == PCI_DEVICE_ID_INTEL_82845_HB)
  1354. switch (dev->subsystem_device) {
  1355. case 0x8025: /* P4B-LX */
  1356. case 0x8070: /* P4B */
  1357. case 0x8088: /* P4B533 */
  1358. case 0x1626: /* L3C notebook */
  1359. asus_hides_smbus = 1;
  1360. }
  1361. else if (dev->device == PCI_DEVICE_ID_INTEL_82845G_HB)
  1362. switch (dev->subsystem_device) {
  1363. case 0x80b1: /* P4GE-V */
  1364. case 0x80b2: /* P4PE */
  1365. case 0x8093: /* P4B533-V */
  1366. asus_hides_smbus = 1;
  1367. }
  1368. else if (dev->device == PCI_DEVICE_ID_INTEL_82850_HB)
  1369. switch (dev->subsystem_device) {
  1370. case 0x8030: /* P4T533 */
  1371. asus_hides_smbus = 1;
  1372. }
  1373. else if (dev->device == PCI_DEVICE_ID_INTEL_7205_0)
  1374. switch (dev->subsystem_device) {
  1375. case 0x8070: /* P4G8X Deluxe */
  1376. asus_hides_smbus = 1;
  1377. }
  1378. else if (dev->device == PCI_DEVICE_ID_INTEL_E7501_MCH)
  1379. switch (dev->subsystem_device) {
  1380. case 0x80c9: /* PU-DLS */
  1381. asus_hides_smbus = 1;
  1382. }
  1383. else if (dev->device == PCI_DEVICE_ID_INTEL_82855GM_HB)
  1384. switch (dev->subsystem_device) {
  1385. case 0x1751: /* M2N notebook */
  1386. case 0x1821: /* M5N notebook */
  1387. case 0x1897: /* A6L notebook */
  1388. asus_hides_smbus = 1;
  1389. }
  1390. else if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB)
  1391. switch (dev->subsystem_device) {
  1392. case 0x184b: /* W1N notebook */
  1393. case 0x186a: /* M6Ne notebook */
  1394. asus_hides_smbus = 1;
  1395. }
  1396. else if (dev->device == PCI_DEVICE_ID_INTEL_82865_HB)
  1397. switch (dev->subsystem_device) {
  1398. case 0x80f2: /* P4P800-X */
  1399. asus_hides_smbus = 1;
  1400. }
  1401. else if (dev->device == PCI_DEVICE_ID_INTEL_82915GM_HB)
  1402. switch (dev->subsystem_device) {
  1403. case 0x1882: /* M6V notebook */
  1404. case 0x1977: /* A6VA notebook */
  1405. asus_hides_smbus = 1;
  1406. }
  1407. } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_HP)) {
  1408. if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB)
  1409. switch (dev->subsystem_device) {
  1410. case 0x088C: /* HP Compaq nc8000 */
  1411. case 0x0890: /* HP Compaq nc6000 */
  1412. asus_hides_smbus = 1;
  1413. }
  1414. else if (dev->device == PCI_DEVICE_ID_INTEL_82865_HB)
  1415. switch (dev->subsystem_device) {
  1416. case 0x12bc: /* HP D330L */
  1417. case 0x12bd: /* HP D530 */
  1418. case 0x006a: /* HP Compaq nx9500 */
  1419. asus_hides_smbus = 1;
  1420. }
  1421. else if (dev->device == PCI_DEVICE_ID_INTEL_82875_HB)
  1422. switch (dev->subsystem_device) {
  1423. case 0x12bf: /* HP xw4100 */
  1424. asus_hides_smbus = 1;
  1425. }
  1426. } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_SAMSUNG)) {
  1427. if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB)
  1428. switch (dev->subsystem_device) {
  1429. case 0xC00C: /* Samsung P35 notebook */
  1430. asus_hides_smbus = 1;
  1431. }
  1432. } else if (unlikely(dev->subsystem_vendor == PCI_VENDOR_ID_COMPAQ)) {
  1433. if (dev->device == PCI_DEVICE_ID_INTEL_82855PM_HB)
  1434. switch (dev->subsystem_device) {
  1435. case 0x0058: /* Compaq Evo N620c */
  1436. asus_hides_smbus = 1;
  1437. }
  1438. else if (dev->device == PCI_DEVICE_ID_INTEL_82810_IG3)
  1439. switch (dev->subsystem_device) {
  1440. case 0xB16C: /* Compaq Deskpro EP 401963-001 (PCA# 010174) */
  1441. /* Motherboard doesn't have Host bridge
  1442. * subvendor/subdevice IDs, therefore checking
  1443. * its on-board VGA controller */
  1444. asus_hides_smbus = 1;
  1445. }
  1446. else if (dev->device == PCI_DEVICE_ID_INTEL_82801DB_2)
  1447. switch (dev->subsystem_device) {
  1448. case 0x00b8: /* Compaq Evo D510 CMT */
  1449. case 0x00b9: /* Compaq Evo D510 SFF */
  1450. case 0x00ba: /* Compaq Evo D510 USDT */
  1451. /* Motherboard doesn't have Host bridge
  1452. * subvendor/subdevice IDs and on-board VGA
  1453. * controller is disabled if an AGP card is
  1454. * inserted, therefore checking USB UHCI
  1455. * Controller #1 */
  1456. asus_hides_smbus = 1;
  1457. }
  1458. else if (dev->device == PCI_DEVICE_ID_INTEL_82815_CGC)
  1459. switch (dev->subsystem_device) {
  1460. case 0x001A: /* Compaq Deskpro EN SSF P667 815E */
  1461. /* Motherboard doesn't have host bridge
  1462. * subvendor/subdevice IDs, therefore checking
  1463. * its on-board VGA controller */
  1464. asus_hides_smbus = 1;
  1465. }
  1466. }
  1467. }
  1468. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845_HB, asus_hides_smbus_hostbridge);
  1469. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82845G_HB, asus_hides_smbus_hostbridge);
  1470. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82850_HB, asus_hides_smbus_hostbridge);
  1471. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82865_HB, asus_hides_smbus_hostbridge);
  1472. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82875_HB, asus_hides_smbus_hostbridge);
  1473. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_7205_0, asus_hides_smbus_hostbridge);
  1474. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7501_MCH, asus_hides_smbus_hostbridge);
  1475. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855PM_HB, asus_hides_smbus_hostbridge);
  1476. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82855GM_HB, asus_hides_smbus_hostbridge);
  1477. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82915GM_HB, asus_hides_smbus_hostbridge);
  1478. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82810_IG3, asus_hides_smbus_hostbridge);
  1479. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_2, asus_hides_smbus_hostbridge);
  1480. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82815_CGC, asus_hides_smbus_hostbridge);
  1481. static void asus_hides_smbus_lpc(struct pci_dev *dev)
  1482. {
  1483. u16 val;
  1484. if (likely(!asus_hides_smbus))
  1485. return;
  1486. pci_read_config_word(dev, 0xF2, &val);
  1487. if (val & 0x8) {
  1488. pci_write_config_word(dev, 0xF2, val & (~0x8));
  1489. pci_read_config_word(dev, 0xF2, &val);
  1490. if (val & 0x8)
  1491. pci_info(dev, "i801 SMBus device continues to play 'hide and seek'! 0x%x\n",
  1492. val);
  1493. else
  1494. pci_info(dev, "Enabled i801 SMBus device\n");
  1495. }
  1496. }
  1497. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, asus_hides_smbus_lpc);
  1498. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, asus_hides_smbus_lpc);
  1499. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, asus_hides_smbus_lpc);
  1500. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asus_hides_smbus_lpc);
  1501. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc);
  1502. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc);
  1503. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc);
  1504. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801AA_0, asus_hides_smbus_lpc);
  1505. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_0, asus_hides_smbus_lpc);
  1506. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801BA_0, asus_hides_smbus_lpc);
  1507. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_0, asus_hides_smbus_lpc);
  1508. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801CA_12, asus_hides_smbus_lpc);
  1509. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801DB_12, asus_hides_smbus_lpc);
  1510. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82801EB_0, asus_hides_smbus_lpc);
  1511. /* It appears we just have one such device. If not, we have a warning */
  1512. static void __iomem *asus_rcba_base;
  1513. static void asus_hides_smbus_lpc_ich6_suspend(struct pci_dev *dev)
  1514. {
  1515. u32 rcba;
  1516. if (likely(!asus_hides_smbus))
  1517. return;
  1518. WARN_ON(asus_rcba_base);
  1519. pci_read_config_dword(dev, 0xF0, &rcba);
  1520. /* use bits 31:14, 16 kB aligned */
  1521. asus_rcba_base = ioremap(rcba & 0xFFFFC000, 0x4000);
  1522. if (asus_rcba_base == NULL)
  1523. return;
  1524. }
  1525. static void asus_hides_smbus_lpc_ich6_resume_early(struct pci_dev *dev)
  1526. {
  1527. u32 val;
  1528. if (likely(!asus_hides_smbus || !asus_rcba_base))
  1529. return;
  1530. /* read the Function Disable register, dword mode only */
  1531. val = readl(asus_rcba_base + 0x3418);
  1532. /* enable the SMBus device */
  1533. writel(val & 0xFFFFFFF7, asus_rcba_base + 0x3418);
  1534. }
  1535. static void asus_hides_smbus_lpc_ich6_resume(struct pci_dev *dev)
  1536. {
  1537. if (likely(!asus_hides_smbus || !asus_rcba_base))
  1538. return;
  1539. iounmap(asus_rcba_base);
  1540. asus_rcba_base = NULL;
  1541. pci_info(dev, "Enabled ICH6/i801 SMBus device\n");
  1542. }
  1543. static void asus_hides_smbus_lpc_ich6(struct pci_dev *dev)
  1544. {
  1545. asus_hides_smbus_lpc_ich6_suspend(dev);
  1546. asus_hides_smbus_lpc_ich6_resume_early(dev);
  1547. asus_hides_smbus_lpc_ich6_resume(dev);
  1548. }
  1549. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6);
  1550. DECLARE_PCI_FIXUP_SUSPEND(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6_suspend);
  1551. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6_resume);
  1552. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ICH6_1, asus_hides_smbus_lpc_ich6_resume_early);
  1553. /* SiS 96x south bridge: BIOS typically hides SMBus device... */
  1554. static void quirk_sis_96x_smbus(struct pci_dev *dev)
  1555. {
  1556. u8 val = 0;
  1557. pci_read_config_byte(dev, 0x77, &val);
  1558. if (val & 0x10) {
  1559. pci_info(dev, "Enabling SiS 96x SMBus\n");
  1560. pci_write_config_byte(dev, 0x77, val & ~0x10);
  1561. }
  1562. }
  1563. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus);
  1564. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus);
  1565. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus);
  1566. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus);
  1567. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_961, quirk_sis_96x_smbus);
  1568. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_962, quirk_sis_96x_smbus);
  1569. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_963, quirk_sis_96x_smbus);
  1570. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_LPC, quirk_sis_96x_smbus);
  1571. /*
  1572. * ... This is further complicated by the fact that some SiS96x south
  1573. * bridges pretend to be 85C503/5513 instead. In that case see if we
  1574. * spotted a compatible north bridge to make sure.
  1575. * (pci_find_device() doesn't work yet)
  1576. *
  1577. * We can also enable the sis96x bit in the discovery register..
  1578. */
  1579. #define SIS_DETECT_REGISTER 0x40
  1580. static void quirk_sis_503(struct pci_dev *dev)
  1581. {
  1582. u8 reg;
  1583. u16 devid;
  1584. pci_read_config_byte(dev, SIS_DETECT_REGISTER, &reg);
  1585. pci_write_config_byte(dev, SIS_DETECT_REGISTER, reg | (1 << 6));
  1586. pci_read_config_word(dev, PCI_DEVICE_ID, &devid);
  1587. if (((devid & 0xfff0) != 0x0960) && (devid != 0x0018)) {
  1588. pci_write_config_byte(dev, SIS_DETECT_REGISTER, reg);
  1589. return;
  1590. }
  1591. /*
  1592. * Ok, it now shows up as a 96x. Run the 96x quirk by hand in case
  1593. * it has already been processed. (Depends on link order, which is
  1594. * apparently not guaranteed)
  1595. */
  1596. dev->device = devid;
  1597. quirk_sis_96x_smbus(dev);
  1598. }
  1599. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503);
  1600. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_SI, PCI_DEVICE_ID_SI_503, quirk_sis_503);
  1601. /*
  1602. * On ASUS A8V and A8V Deluxe boards, the onboard AC97 audio controller
  1603. * and MC97 modem controller are disabled when a second PCI soundcard is
  1604. * present. This patch, tweaking the VT8237 ISA bridge, enables them.
  1605. * -- bjd
  1606. */
  1607. static void asus_hides_ac97_lpc(struct pci_dev *dev)
  1608. {
  1609. u8 val;
  1610. int asus_hides_ac97 = 0;
  1611. if (likely(dev->subsystem_vendor == PCI_VENDOR_ID_ASUSTEK)) {
  1612. if (dev->device == PCI_DEVICE_ID_VIA_8237)
  1613. asus_hides_ac97 = 1;
  1614. }
  1615. if (!asus_hides_ac97)
  1616. return;
  1617. pci_read_config_byte(dev, 0x50, &val);
  1618. if (val & 0xc0) {
  1619. pci_write_config_byte(dev, 0x50, val & (~0xc0));
  1620. pci_read_config_byte(dev, 0x50, &val);
  1621. if (val & 0xc0)
  1622. pci_info(dev, "Onboard AC97/MC97 devices continue to play 'hide and seek'! 0x%x\n",
  1623. val);
  1624. else
  1625. pci_info(dev, "Enabled onboard AC97/MC97 devices\n");
  1626. }
  1627. }
  1628. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc);
  1629. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8237, asus_hides_ac97_lpc);
  1630. #if defined(CONFIG_ATA) || defined(CONFIG_ATA_MODULE)
  1631. /*
  1632. * If we are using libata we can drive this chip properly but must do this
  1633. * early on to make the additional device appear during the PCI scanning.
  1634. */
  1635. static void quirk_jmicron_ata(struct pci_dev *pdev)
  1636. {
  1637. u32 conf1, conf5, class;
  1638. u8 hdr;
  1639. /* Only poke fn 0 */
  1640. if (PCI_FUNC(pdev->devfn))
  1641. return;
  1642. pci_read_config_dword(pdev, 0x40, &conf1);
  1643. pci_read_config_dword(pdev, 0x80, &conf5);
  1644. conf1 &= ~0x00CFF302; /* Clear bit 1, 8, 9, 12-19, 22, 23 */
  1645. conf5 &= ~(1 << 24); /* Clear bit 24 */
  1646. switch (pdev->device) {
  1647. case PCI_DEVICE_ID_JMICRON_JMB360: /* SATA single port */
  1648. case PCI_DEVICE_ID_JMICRON_JMB362: /* SATA dual ports */
  1649. case PCI_DEVICE_ID_JMICRON_JMB364: /* SATA dual ports */
  1650. /* The controller should be in single function ahci mode */
  1651. conf1 |= 0x0002A100; /* Set 8, 13, 15, 17 */
  1652. break;
  1653. case PCI_DEVICE_ID_JMICRON_JMB365:
  1654. case PCI_DEVICE_ID_JMICRON_JMB366:
  1655. /* Redirect IDE second PATA port to the right spot */
  1656. conf5 |= (1 << 24);
  1657. fallthrough;
  1658. case PCI_DEVICE_ID_JMICRON_JMB361:
  1659. case PCI_DEVICE_ID_JMICRON_JMB363:
  1660. case PCI_DEVICE_ID_JMICRON_JMB369:
  1661. /* Enable dual function mode, AHCI on fn 0, IDE fn1 */
  1662. /* Set the class codes correctly and then direct IDE 0 */
  1663. conf1 |= 0x00C2A1B3; /* Set 0, 1, 4, 5, 7, 8, 13, 15, 17, 22, 23 */
  1664. break;
  1665. case PCI_DEVICE_ID_JMICRON_JMB368:
  1666. /* The controller should be in single function IDE mode */
  1667. conf1 |= 0x00C00000; /* Set 22, 23 */
  1668. break;
  1669. }
  1670. pci_write_config_dword(pdev, 0x40, conf1);
  1671. pci_write_config_dword(pdev, 0x80, conf5);
  1672. /* Update pdev accordingly */
  1673. pci_read_config_byte(pdev, PCI_HEADER_TYPE, &hdr);
  1674. pdev->hdr_type = hdr & PCI_HEADER_TYPE_MASK;
  1675. pdev->multifunction = FIELD_GET(PCI_HEADER_TYPE_MFD, hdr);
  1676. pci_read_config_dword(pdev, PCI_CLASS_REVISION, &class);
  1677. pdev->class = class >> 8;
  1678. }
  1679. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB360, quirk_jmicron_ata);
  1680. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, quirk_jmicron_ata);
  1681. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB362, quirk_jmicron_ata);
  1682. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, quirk_jmicron_ata);
  1683. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB364, quirk_jmicron_ata);
  1684. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata);
  1685. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata);
  1686. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata);
  1687. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB369, quirk_jmicron_ata);
  1688. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB360, quirk_jmicron_ata);
  1689. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB361, quirk_jmicron_ata);
  1690. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB362, quirk_jmicron_ata);
  1691. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB363, quirk_jmicron_ata);
  1692. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB364, quirk_jmicron_ata);
  1693. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB365, quirk_jmicron_ata);
  1694. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB366, quirk_jmicron_ata);
  1695. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB368, quirk_jmicron_ata);
  1696. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_JMICRON, PCI_DEVICE_ID_JMICRON_JMB369, quirk_jmicron_ata);
  1697. #endif
  1698. static void quirk_jmicron_async_suspend(struct pci_dev *dev)
  1699. {
  1700. if (dev->multifunction) {
  1701. device_disable_async_suspend(&dev->dev);
  1702. pci_info(dev, "async suspend disabled to avoid multi-function power-on ordering issue\n");
  1703. }
  1704. }
  1705. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_CLASS_STORAGE_IDE, 8, quirk_jmicron_async_suspend);
  1706. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_JMICRON, PCI_ANY_ID, PCI_CLASS_STORAGE_SATA_AHCI, 0, quirk_jmicron_async_suspend);
  1707. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_JMICRON, 0x2362, quirk_jmicron_async_suspend);
  1708. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_JMICRON, 0x236f, quirk_jmicron_async_suspend);
  1709. #ifdef CONFIG_X86_IO_APIC
  1710. static void quirk_alder_ioapic(struct pci_dev *pdev)
  1711. {
  1712. int i;
  1713. if ((pdev->class >> 8) != 0xff00)
  1714. return;
  1715. /*
  1716. * The first BAR is the location of the IO-APIC... we must
  1717. * not touch this (and it's already covered by the fixmap), so
  1718. * forcibly insert it into the resource tree.
  1719. */
  1720. if (pci_resource_start(pdev, 0) && pci_resource_len(pdev, 0))
  1721. insert_resource(&iomem_resource, &pdev->resource[0]);
  1722. /*
  1723. * The next five BARs all seem to be rubbish, so just clean
  1724. * them out.
  1725. */
  1726. for (i = 1; i < PCI_STD_NUM_BARS; i++)
  1727. memset(&pdev->resource[i], 0, sizeof(pdev->resource[i]));
  1728. }
  1729. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EESSC, quirk_alder_ioapic);
  1730. #endif
  1731. static void quirk_no_msi(struct pci_dev *dev)
  1732. {
  1733. pci_info(dev, "avoiding MSI to work around a hardware defect\n");
  1734. dev->no_msi = 1;
  1735. }
  1736. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4386, quirk_no_msi);
  1737. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4387, quirk_no_msi);
  1738. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4388, quirk_no_msi);
  1739. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4389, quirk_no_msi);
  1740. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x438a, quirk_no_msi);
  1741. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x438b, quirk_no_msi);
  1742. static void quirk_pcie_mch(struct pci_dev *pdev)
  1743. {
  1744. pdev->no_msi = 1;
  1745. }
  1746. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7520_MCH, quirk_pcie_mch);
  1747. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7320_MCH, quirk_pcie_mch);
  1748. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_E7525_MCH, quirk_pcie_mch);
  1749. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_HUAWEI, 0x1610, PCI_CLASS_BRIDGE_PCI, 8, quirk_pcie_mch);
  1750. /*
  1751. * HiSilicon KunPeng920 and KunPeng930 have devices appear as PCI but are
  1752. * actually on the AMBA bus. These fake PCI devices can support SVA via
  1753. * SMMU stall feature, by setting dma-can-stall for ACPI platforms.
  1754. *
  1755. * Normally stalling must not be enabled for PCI devices, since it would
  1756. * break the PCI requirement for free-flowing writes and may lead to
  1757. * deadlock. We expect PCI devices to support ATS and PRI if they want to
  1758. * be fault-tolerant, so there's no ACPI binding to describe anything else,
  1759. * even when a "PCI" device turns out to be a regular old SoC device
  1760. * dressed up as a RCiEP and normal rules don't apply.
  1761. */
  1762. static void quirk_huawei_pcie_sva(struct pci_dev *pdev)
  1763. {
  1764. struct property_entry properties[] = {
  1765. PROPERTY_ENTRY_BOOL("dma-can-stall"),
  1766. {},
  1767. };
  1768. if (pdev->revision != 0x21 && pdev->revision != 0x30)
  1769. return;
  1770. pdev->pasid_no_tlp = 1;
  1771. /*
  1772. * Set the dma-can-stall property on ACPI platforms. Device tree
  1773. * can set it directly.
  1774. */
  1775. if (!pdev->dev.of_node &&
  1776. device_create_managed_software_node(&pdev->dev, properties, NULL))
  1777. pci_warn(pdev, "could not add stall property");
  1778. }
  1779. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_HUAWEI, 0xa250, quirk_huawei_pcie_sva);
  1780. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_HUAWEI, 0xa251, quirk_huawei_pcie_sva);
  1781. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_HUAWEI, 0xa255, quirk_huawei_pcie_sva);
  1782. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_HUAWEI, 0xa256, quirk_huawei_pcie_sva);
  1783. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_HUAWEI, 0xa258, quirk_huawei_pcie_sva);
  1784. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_HUAWEI, 0xa259, quirk_huawei_pcie_sva);
  1785. /*
  1786. * It's possible for the MSI to get corrupted if SHPC and ACPI are used
  1787. * together on certain PXH-based systems.
  1788. */
  1789. static void quirk_pcie_pxh(struct pci_dev *dev)
  1790. {
  1791. dev->no_msi = 1;
  1792. pci_warn(dev, "PXH quirk detected; SHPC device MSI disabled\n");
  1793. }
  1794. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXHD_0, quirk_pcie_pxh);
  1795. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXHD_1, quirk_pcie_pxh);
  1796. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0, quirk_pcie_pxh);
  1797. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1, quirk_pcie_pxh);
  1798. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXHV, quirk_pcie_pxh);
  1799. /*
  1800. * Some Intel PCI Express chipsets have trouble with downstream device
  1801. * power management.
  1802. */
  1803. static void quirk_intel_pcie_pm(struct pci_dev *dev)
  1804. {
  1805. pci_pm_d3hot_delay = 120;
  1806. dev->no_d1d2 = 1;
  1807. }
  1808. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e2, quirk_intel_pcie_pm);
  1809. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e3, quirk_intel_pcie_pm);
  1810. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e4, quirk_intel_pcie_pm);
  1811. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e5, quirk_intel_pcie_pm);
  1812. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e6, quirk_intel_pcie_pm);
  1813. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25e7, quirk_intel_pcie_pm);
  1814. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25f7, quirk_intel_pcie_pm);
  1815. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25f8, quirk_intel_pcie_pm);
  1816. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25f9, quirk_intel_pcie_pm);
  1817. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x25fa, quirk_intel_pcie_pm);
  1818. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2601, quirk_intel_pcie_pm);
  1819. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2602, quirk_intel_pcie_pm);
  1820. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2603, quirk_intel_pcie_pm);
  1821. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2604, quirk_intel_pcie_pm);
  1822. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2605, quirk_intel_pcie_pm);
  1823. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2606, quirk_intel_pcie_pm);
  1824. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2607, quirk_intel_pcie_pm);
  1825. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2608, quirk_intel_pcie_pm);
  1826. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2609, quirk_intel_pcie_pm);
  1827. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x260a, quirk_intel_pcie_pm);
  1828. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x260b, quirk_intel_pcie_pm);
  1829. static void quirk_d3hot_delay(struct pci_dev *dev, unsigned int delay)
  1830. {
  1831. if (dev->d3hot_delay >= delay)
  1832. return;
  1833. dev->d3hot_delay = delay;
  1834. pci_info(dev, "extending delay after power-on from D3hot to %d msec\n",
  1835. dev->d3hot_delay);
  1836. }
  1837. static void quirk_radeon_pm(struct pci_dev *dev)
  1838. {
  1839. if (dev->subsystem_vendor == PCI_VENDOR_ID_APPLE &&
  1840. dev->subsystem_device == 0x00e2)
  1841. quirk_d3hot_delay(dev, 20);
  1842. }
  1843. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x6741, quirk_radeon_pm);
  1844. /*
  1845. * NVIDIA Ampere-based HDA controllers can wedge the whole device if a bus
  1846. * reset is performed too soon after transition to D0, extend d3hot_delay
  1847. * to previous effective default for all NVIDIA HDA controllers.
  1848. */
  1849. static void quirk_nvidia_hda_pm(struct pci_dev *dev)
  1850. {
  1851. quirk_d3hot_delay(dev, 20);
  1852. }
  1853. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
  1854. PCI_CLASS_MULTIMEDIA_HD_AUDIO, 8,
  1855. quirk_nvidia_hda_pm);
  1856. /*
  1857. * Ryzen5/7 XHCI controllers fail upon resume from runtime suspend or s2idle.
  1858. * https://bugzilla.kernel.org/show_bug.cgi?id=205587
  1859. *
  1860. * The kernel attempts to transition these devices to D3cold, but that seems
  1861. * to be ineffective on the platforms in question; the PCI device appears to
  1862. * remain on in D3hot state. The D3hot-to-D0 transition then requires an
  1863. * extended delay in order to succeed.
  1864. */
  1865. static void quirk_ryzen_xhci_d3hot(struct pci_dev *dev)
  1866. {
  1867. quirk_d3hot_delay(dev, 20);
  1868. }
  1869. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x15e0, quirk_ryzen_xhci_d3hot);
  1870. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x15e1, quirk_ryzen_xhci_d3hot);
  1871. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x1639, quirk_ryzen_xhci_d3hot);
  1872. #ifdef CONFIG_X86_IO_APIC
  1873. static int dmi_disable_ioapicreroute(const struct dmi_system_id *d)
  1874. {
  1875. noioapicreroute = 1;
  1876. pr_info("%s detected: disable boot interrupt reroute\n", d->ident);
  1877. return 0;
  1878. }
  1879. static const struct dmi_system_id boot_interrupt_dmi_table[] = {
  1880. /*
  1881. * Systems to exclude from boot interrupt reroute quirks
  1882. */
  1883. {
  1884. .callback = dmi_disable_ioapicreroute,
  1885. .ident = "ASUSTek Computer INC. M2N-LR",
  1886. .matches = {
  1887. DMI_MATCH(DMI_SYS_VENDOR, "ASUSTek Computer INC."),
  1888. DMI_MATCH(DMI_PRODUCT_NAME, "M2N-LR"),
  1889. },
  1890. },
  1891. {}
  1892. };
  1893. /*
  1894. * Boot interrupts on some chipsets cannot be turned off. For these chipsets,
  1895. * remap the original interrupt in the Linux kernel to the boot interrupt, so
  1896. * that a PCI device's interrupt handler is installed on the boot interrupt
  1897. * line instead.
  1898. */
  1899. static void quirk_reroute_to_boot_interrupts_intel(struct pci_dev *dev)
  1900. {
  1901. dmi_check_system(boot_interrupt_dmi_table);
  1902. if (noioapicquirk || noioapicreroute)
  1903. return;
  1904. dev->irq_reroute_variant = INTEL_IRQ_REROUTE_VARIANT;
  1905. pci_info(dev, "rerouting interrupts for [%04x:%04x]\n",
  1906. dev->vendor, dev->device);
  1907. }
  1908. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80333_0, quirk_reroute_to_boot_interrupts_intel);
  1909. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80333_1, quirk_reroute_to_boot_interrupts_intel);
  1910. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0, quirk_reroute_to_boot_interrupts_intel);
  1911. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0, quirk_reroute_to_boot_interrupts_intel);
  1912. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1, quirk_reroute_to_boot_interrupts_intel);
  1913. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXHV, quirk_reroute_to_boot_interrupts_intel);
  1914. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80332_0, quirk_reroute_to_boot_interrupts_intel);
  1915. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80332_1, quirk_reroute_to_boot_interrupts_intel);
  1916. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80333_0, quirk_reroute_to_boot_interrupts_intel);
  1917. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80333_1, quirk_reroute_to_boot_interrupts_intel);
  1918. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB2_0, quirk_reroute_to_boot_interrupts_intel);
  1919. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_0, quirk_reroute_to_boot_interrupts_intel);
  1920. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXH_1, quirk_reroute_to_boot_interrupts_intel);
  1921. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PXHV, quirk_reroute_to_boot_interrupts_intel);
  1922. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80332_0, quirk_reroute_to_boot_interrupts_intel);
  1923. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_80332_1, quirk_reroute_to_boot_interrupts_intel);
  1924. /*
  1925. * On some chipsets we can disable the generation of legacy INTx boot
  1926. * interrupts.
  1927. */
  1928. /*
  1929. * IO-APIC1 on 6300ESB generates boot interrupts, see Intel order no
  1930. * 300641-004US, section 5.7.3.
  1931. *
  1932. * Core IO on Xeon E5 1600/2600/4600, see Intel order no 326509-003.
  1933. * Core IO on Xeon E5 v2, see Intel order no 329188-003.
  1934. * Core IO on Xeon E7 v2, see Intel order no 329595-002.
  1935. * Core IO on Xeon E5 v3, see Intel order no 330784-003.
  1936. * Core IO on Xeon E7 v3, see Intel order no 332315-001US.
  1937. * Core IO on Xeon E5 v4, see Intel order no 333810-002US.
  1938. * Core IO on Xeon E7 v4, see Intel order no 332315-001US.
  1939. * Core IO on Xeon D-1500, see Intel order no 332051-001.
  1940. * Core IO on Xeon Scalable, see Intel order no 610950.
  1941. */
  1942. #define INTEL_6300_IOAPIC_ABAR 0x40 /* Bus 0, Dev 29, Func 5 */
  1943. #define INTEL_6300_DISABLE_BOOT_IRQ (1<<14)
  1944. #define INTEL_CIPINTRC_CFG_OFFSET 0x14C /* Bus 0, Dev 5, Func 0 */
  1945. #define INTEL_CIPINTRC_DIS_INTX_ICH (1<<25)
  1946. static void quirk_disable_intel_boot_interrupt(struct pci_dev *dev)
  1947. {
  1948. u16 pci_config_word;
  1949. u32 pci_config_dword;
  1950. if (noioapicquirk)
  1951. return;
  1952. switch (dev->device) {
  1953. case PCI_DEVICE_ID_INTEL_ESB_10:
  1954. pci_read_config_word(dev, INTEL_6300_IOAPIC_ABAR,
  1955. &pci_config_word);
  1956. pci_config_word |= INTEL_6300_DISABLE_BOOT_IRQ;
  1957. pci_write_config_word(dev, INTEL_6300_IOAPIC_ABAR,
  1958. pci_config_word);
  1959. break;
  1960. case 0x3c28: /* Xeon E5 1600/2600/4600 */
  1961. case 0x0e28: /* Xeon E5/E7 V2 */
  1962. case 0x2f28: /* Xeon E5/E7 V3,V4 */
  1963. case 0x6f28: /* Xeon D-1500 */
  1964. case 0x2034: /* Xeon Scalable Family */
  1965. pci_read_config_dword(dev, INTEL_CIPINTRC_CFG_OFFSET,
  1966. &pci_config_dword);
  1967. pci_config_dword |= INTEL_CIPINTRC_DIS_INTX_ICH;
  1968. pci_write_config_dword(dev, INTEL_CIPINTRC_CFG_OFFSET,
  1969. pci_config_dword);
  1970. break;
  1971. default:
  1972. return;
  1973. }
  1974. pci_info(dev, "disabled boot interrupts on device [%04x:%04x]\n",
  1975. dev->vendor, dev->device);
  1976. }
  1977. /*
  1978. * Device 29 Func 5 Device IDs of IO-APIC
  1979. * containing ABAR—APIC1 Alternate Base Address Register
  1980. */
  1981. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_10,
  1982. quirk_disable_intel_boot_interrupt);
  1983. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_ESB_10,
  1984. quirk_disable_intel_boot_interrupt);
  1985. /*
  1986. * Device 5 Func 0 Device IDs of Core IO modules/hubs
  1987. * containing Coherent Interface Protocol Interrupt Control
  1988. *
  1989. * Device IDs obtained from volume 2 datasheets of commented
  1990. * families above.
  1991. */
  1992. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x3c28,
  1993. quirk_disable_intel_boot_interrupt);
  1994. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0e28,
  1995. quirk_disable_intel_boot_interrupt);
  1996. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2f28,
  1997. quirk_disable_intel_boot_interrupt);
  1998. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x6f28,
  1999. quirk_disable_intel_boot_interrupt);
  2000. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2034,
  2001. quirk_disable_intel_boot_interrupt);
  2002. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, 0x3c28,
  2003. quirk_disable_intel_boot_interrupt);
  2004. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, 0x0e28,
  2005. quirk_disable_intel_boot_interrupt);
  2006. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, 0x2f28,
  2007. quirk_disable_intel_boot_interrupt);
  2008. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, 0x6f28,
  2009. quirk_disable_intel_boot_interrupt);
  2010. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_INTEL, 0x2034,
  2011. quirk_disable_intel_boot_interrupt);
  2012. /* Disable boot interrupts on HT-1000 */
  2013. #define BC_HT1000_FEATURE_REG 0x64
  2014. #define BC_HT1000_PIC_REGS_ENABLE (1<<0)
  2015. #define BC_HT1000_MAP_IDX 0xC00
  2016. #define BC_HT1000_MAP_DATA 0xC01
  2017. static void quirk_disable_broadcom_boot_interrupt(struct pci_dev *dev)
  2018. {
  2019. u32 pci_config_dword;
  2020. u8 irq;
  2021. if (noioapicquirk)
  2022. return;
  2023. pci_read_config_dword(dev, BC_HT1000_FEATURE_REG, &pci_config_dword);
  2024. pci_write_config_dword(dev, BC_HT1000_FEATURE_REG, pci_config_dword |
  2025. BC_HT1000_PIC_REGS_ENABLE);
  2026. for (irq = 0x10; irq < 0x10 + 32; irq++) {
  2027. outb(irq, BC_HT1000_MAP_IDX);
  2028. outb(0x00, BC_HT1000_MAP_DATA);
  2029. }
  2030. pci_write_config_dword(dev, BC_HT1000_FEATURE_REG, pci_config_dword);
  2031. pci_info(dev, "disabled boot interrupts on device [%04x:%04x]\n",
  2032. dev->vendor, dev->device);
  2033. }
  2034. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000SB, quirk_disable_broadcom_boot_interrupt);
  2035. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT1000SB, quirk_disable_broadcom_boot_interrupt);
  2036. /* Disable boot interrupts on AMD and ATI chipsets */
  2037. /*
  2038. * NOIOAMODE needs to be disabled to disable "boot interrupts". For AMD 8131
  2039. * rev. A0 and B0, NOIOAMODE needs to be disabled anyway to fix IO-APIC mode
  2040. * (due to an erratum).
  2041. */
  2042. #define AMD_813X_MISC 0x40
  2043. #define AMD_813X_NOIOAMODE (1<<0)
  2044. #define AMD_813X_REV_B1 0x12
  2045. #define AMD_813X_REV_B2 0x13
  2046. static void quirk_disable_amd_813x_boot_interrupt(struct pci_dev *dev)
  2047. {
  2048. u32 pci_config_dword;
  2049. if (noioapicquirk)
  2050. return;
  2051. if ((dev->revision == AMD_813X_REV_B1) ||
  2052. (dev->revision == AMD_813X_REV_B2))
  2053. return;
  2054. pci_read_config_dword(dev, AMD_813X_MISC, &pci_config_dword);
  2055. pci_config_dword &= ~AMD_813X_NOIOAMODE;
  2056. pci_write_config_dword(dev, AMD_813X_MISC, pci_config_dword);
  2057. pci_info(dev, "disabled boot interrupts on device [%04x:%04x]\n",
  2058. dev->vendor, dev->device);
  2059. }
  2060. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_disable_amd_813x_boot_interrupt);
  2061. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_disable_amd_813x_boot_interrupt);
  2062. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8132_BRIDGE, quirk_disable_amd_813x_boot_interrupt);
  2063. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8132_BRIDGE, quirk_disable_amd_813x_boot_interrupt);
  2064. #define AMD_8111_PCI_IRQ_ROUTING 0x56
  2065. static void quirk_disable_amd_8111_boot_interrupt(struct pci_dev *dev)
  2066. {
  2067. u16 pci_config_word;
  2068. if (noioapicquirk)
  2069. return;
  2070. pci_read_config_word(dev, AMD_8111_PCI_IRQ_ROUTING, &pci_config_word);
  2071. if (!pci_config_word) {
  2072. pci_info(dev, "boot interrupts on device [%04x:%04x] already disabled\n",
  2073. dev->vendor, dev->device);
  2074. return;
  2075. }
  2076. pci_write_config_word(dev, AMD_8111_PCI_IRQ_ROUTING, 0);
  2077. pci_info(dev, "disabled boot interrupts on device [%04x:%04x]\n",
  2078. dev->vendor, dev->device);
  2079. }
  2080. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_SMBUS, quirk_disable_amd_8111_boot_interrupt);
  2081. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8111_SMBUS, quirk_disable_amd_8111_boot_interrupt);
  2082. #endif /* CONFIG_X86_IO_APIC */
  2083. /*
  2084. * Toshiba TC86C001 IDE controller reports the standard 8-byte BAR0 size
  2085. * but the PIO transfers won't work if BAR0 falls at the odd 8 bytes.
  2086. * Re-allocate the region if needed...
  2087. */
  2088. static void quirk_tc86c001_ide(struct pci_dev *dev)
  2089. {
  2090. struct resource *r = &dev->resource[0];
  2091. if (r->start & 0x8) {
  2092. r->flags |= IORESOURCE_UNSET;
  2093. r->start = 0;
  2094. r->end = 0xf;
  2095. }
  2096. }
  2097. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TOSHIBA_2,
  2098. PCI_DEVICE_ID_TOSHIBA_TC86C001_IDE,
  2099. quirk_tc86c001_ide);
  2100. /*
  2101. * PLX PCI 9050 PCI Target bridge controller has an erratum that prevents the
  2102. * local configuration registers accessible via BAR0 (memory) or BAR1 (i/o)
  2103. * being read correctly if bit 7 of the base address is set.
  2104. * The BAR0 or BAR1 region may be disabled (size 0) or enabled (size 128).
  2105. * Re-allocate the regions to a 256-byte boundary if necessary.
  2106. */
  2107. static void quirk_plx_pci9050(struct pci_dev *dev)
  2108. {
  2109. unsigned int bar;
  2110. /* Fixed in revision 2 (PCI 9052). */
  2111. if (dev->revision >= 2)
  2112. return;
  2113. for (bar = 0; bar <= 1; bar++)
  2114. if (pci_resource_len(dev, bar) == 0x80 &&
  2115. (pci_resource_start(dev, bar) & 0x80)) {
  2116. struct resource *r = &dev->resource[bar];
  2117. pci_info(dev, "Re-allocating PLX PCI 9050 BAR %u to length 256 to avoid bit 7 bug\n",
  2118. bar);
  2119. r->flags |= IORESOURCE_UNSET;
  2120. r->start = 0;
  2121. r->end = 0xff;
  2122. }
  2123. }
  2124. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_PLX, PCI_DEVICE_ID_PLX_9050,
  2125. quirk_plx_pci9050);
  2126. /*
  2127. * The following Meilhaus (vendor ID 0x1402) device IDs (amongst others)
  2128. * may be using the PLX PCI 9050: 0x0630, 0x0940, 0x0950, 0x0960, 0x100b,
  2129. * 0x1400, 0x140a, 0x140b, 0x14e0, 0x14ea, 0x14eb, 0x1604, 0x1608, 0x160c,
  2130. * 0x168f, 0x2000, 0x2600, 0x3000, 0x810a, 0x810b.
  2131. *
  2132. * Currently, device IDs 0x2000 and 0x2600 are used by the Comedi "me_daq"
  2133. * driver.
  2134. */
  2135. DECLARE_PCI_FIXUP_HEADER(0x1402, 0x2000, quirk_plx_pci9050);
  2136. DECLARE_PCI_FIXUP_HEADER(0x1402, 0x2600, quirk_plx_pci9050);
  2137. static void quirk_netmos(struct pci_dev *dev)
  2138. {
  2139. unsigned int num_parallel = (dev->subsystem_device & 0xf0) >> 4;
  2140. unsigned int num_serial = dev->subsystem_device & 0xf;
  2141. /*
  2142. * These Netmos parts are multiport serial devices with optional
  2143. * parallel ports. Even when parallel ports are present, they
  2144. * are identified as class SERIAL, which means the serial driver
  2145. * will claim them. To prevent this, mark them as class OTHER.
  2146. * These combo devices should be claimed by parport_serial.
  2147. *
  2148. * The subdevice ID is of the form 0x00PS, where <P> is the number
  2149. * of parallel ports and <S> is the number of serial ports.
  2150. */
  2151. switch (dev->device) {
  2152. case PCI_DEVICE_ID_NETMOS_9835:
  2153. /* Well, this rule doesn't hold for the following 9835 device */
  2154. if (dev->subsystem_vendor == PCI_VENDOR_ID_IBM &&
  2155. dev->subsystem_device == 0x0299)
  2156. return;
  2157. fallthrough;
  2158. case PCI_DEVICE_ID_NETMOS_9735:
  2159. case PCI_DEVICE_ID_NETMOS_9745:
  2160. case PCI_DEVICE_ID_NETMOS_9845:
  2161. case PCI_DEVICE_ID_NETMOS_9855:
  2162. if (num_parallel) {
  2163. pci_info(dev, "Netmos %04x (%u parallel, %u serial); changing class SERIAL to OTHER (use parport_serial)\n",
  2164. dev->device, num_parallel, num_serial);
  2165. dev->class = (PCI_CLASS_COMMUNICATION_OTHER << 8) |
  2166. (dev->class & 0xff);
  2167. }
  2168. }
  2169. }
  2170. DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_VENDOR_ID_NETMOS, PCI_ANY_ID,
  2171. PCI_CLASS_COMMUNICATION_SERIAL, 8, quirk_netmos);
  2172. static void quirk_e100_interrupt(struct pci_dev *dev)
  2173. {
  2174. u16 command, pmcsr;
  2175. u8 __iomem *csr;
  2176. u8 cmd_hi;
  2177. switch (dev->device) {
  2178. /* PCI IDs taken from drivers/net/e100.c */
  2179. case 0x1029:
  2180. case 0x1030 ... 0x1034:
  2181. case 0x1038 ... 0x103E:
  2182. case 0x1050 ... 0x1057:
  2183. case 0x1059:
  2184. case 0x1064 ... 0x106B:
  2185. case 0x1091 ... 0x1095:
  2186. case 0x1209:
  2187. case 0x1229:
  2188. case 0x2449:
  2189. case 0x2459:
  2190. case 0x245D:
  2191. case 0x27DC:
  2192. break;
  2193. default:
  2194. return;
  2195. }
  2196. /*
  2197. * Some firmware hands off the e100 with interrupts enabled,
  2198. * which can cause a flood of interrupts if packets are
  2199. * received before the driver attaches to the device. So
  2200. * disable all e100 interrupts here. The driver will
  2201. * re-enable them when it's ready.
  2202. */
  2203. pci_read_config_word(dev, PCI_COMMAND, &command);
  2204. if (!(command & PCI_COMMAND_MEMORY) || !pci_resource_start(dev, 0))
  2205. return;
  2206. /*
  2207. * Check that the device is in the D0 power state. If it's not,
  2208. * there is no point to look any further.
  2209. */
  2210. if (dev->pm_cap) {
  2211. pci_read_config_word(dev, dev->pm_cap + PCI_PM_CTRL, &pmcsr);
  2212. if ((pmcsr & PCI_PM_CTRL_STATE_MASK) != PCI_D0)
  2213. return;
  2214. }
  2215. /* Convert from PCI bus to resource space. */
  2216. csr = ioremap(pci_resource_start(dev, 0), 8);
  2217. if (!csr) {
  2218. pci_warn(dev, "Can't map e100 registers\n");
  2219. return;
  2220. }
  2221. cmd_hi = readb(csr + 3);
  2222. if (cmd_hi == 0) {
  2223. pci_warn(dev, "Firmware left e100 interrupts enabled; disabling\n");
  2224. writeb(1, csr + 3);
  2225. }
  2226. iounmap(csr);
  2227. }
  2228. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_INTEL, PCI_ANY_ID,
  2229. PCI_CLASS_NETWORK_ETHERNET, 8, quirk_e100_interrupt);
  2230. /*
  2231. * The 82575 and 82598 may experience data corruption issues when transitioning
  2232. * out of L0S. To prevent this we need to disable L0S on the PCIe link.
  2233. */
  2234. static void quirk_disable_aspm_l0s(struct pci_dev *dev)
  2235. {
  2236. pci_info(dev, "Disabling L0s\n");
  2237. pci_disable_link_state(dev, PCIE_LINK_STATE_L0S);
  2238. }
  2239. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10a7, quirk_disable_aspm_l0s);
  2240. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10a9, quirk_disable_aspm_l0s);
  2241. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10b6, quirk_disable_aspm_l0s);
  2242. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10c6, quirk_disable_aspm_l0s);
  2243. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10c7, quirk_disable_aspm_l0s);
  2244. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10c8, quirk_disable_aspm_l0s);
  2245. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10d6, quirk_disable_aspm_l0s);
  2246. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10db, quirk_disable_aspm_l0s);
  2247. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10dd, quirk_disable_aspm_l0s);
  2248. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10e1, quirk_disable_aspm_l0s);
  2249. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10ec, quirk_disable_aspm_l0s);
  2250. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10f1, quirk_disable_aspm_l0s);
  2251. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x10f4, quirk_disable_aspm_l0s);
  2252. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1508, quirk_disable_aspm_l0s);
  2253. static void quirk_disable_aspm_l0s_l1(struct pci_dev *dev)
  2254. {
  2255. pci_info(dev, "Disabling ASPM L0s/L1\n");
  2256. pci_disable_link_state(dev, PCIE_LINK_STATE_L0S | PCIE_LINK_STATE_L1);
  2257. }
  2258. /*
  2259. * ASM1083/1085 PCIe-PCI bridge devices cause AER timeout errors on the
  2260. * upstream PCIe root port when ASPM is enabled. At least L0s mode is affected;
  2261. * disable both L0s and L1 for now to be safe.
  2262. */
  2263. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ASMEDIA, 0x1080, quirk_disable_aspm_l0s_l1);
  2264. /*
  2265. * Some Pericom PCIe-to-PCI bridges in reverse mode need the PCIe Retrain
  2266. * Link bit cleared after starting the link retrain process to allow this
  2267. * process to finish.
  2268. *
  2269. * Affected devices: PI7C9X110, PI7C9X111SL, PI7C9X130. See also the
  2270. * Pericom Errata Sheet PI7C9X111SLB_errata_rev1.2_102711.pdf.
  2271. */
  2272. static void quirk_enable_clear_retrain_link(struct pci_dev *dev)
  2273. {
  2274. dev->clear_retrain_link = 1;
  2275. pci_info(dev, "Enable PCIe Retrain Link quirk\n");
  2276. }
  2277. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_PERICOM, 0xe110, quirk_enable_clear_retrain_link);
  2278. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_PERICOM, 0xe111, quirk_enable_clear_retrain_link);
  2279. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_PERICOM, 0xe130, quirk_enable_clear_retrain_link);
  2280. static void fixup_rev1_53c810(struct pci_dev *dev)
  2281. {
  2282. u32 class = dev->class;
  2283. /*
  2284. * rev 1 ncr53c810 chips don't set the class at all which means
  2285. * they don't get their resources remapped. Fix that here.
  2286. */
  2287. if (class)
  2288. return;
  2289. dev->class = PCI_CLASS_STORAGE_SCSI << 8;
  2290. pci_info(dev, "NCR 53c810 rev 1 PCI class overridden (%#08x -> %#08x)\n",
  2291. class, dev->class);
  2292. }
  2293. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NCR, PCI_DEVICE_ID_NCR_53C810, fixup_rev1_53c810);
  2294. /* Enable 1k I/O space granularity on the Intel P64H2 */
  2295. static void quirk_p64h2_1k_io(struct pci_dev *dev)
  2296. {
  2297. u16 en1k;
  2298. pci_read_config_word(dev, 0x40, &en1k);
  2299. if (en1k & 0x200) {
  2300. pci_info(dev, "Enable I/O Space to 1KB granularity\n");
  2301. dev->io_window_1k = 1;
  2302. }
  2303. }
  2304. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x1460, quirk_p64h2_1k_io);
  2305. /*
  2306. * Under some circumstances, AER is not linked with extended capabilities.
  2307. * Force it to be linked by setting the corresponding control bit in the
  2308. * config space.
  2309. */
  2310. static void quirk_nvidia_ck804_pcie_aer_ext_cap(struct pci_dev *dev)
  2311. {
  2312. uint8_t b;
  2313. if (pci_read_config_byte(dev, 0xf41, &b) == 0) {
  2314. if (!(b & 0x20)) {
  2315. pci_write_config_byte(dev, 0xf41, b | 0x20);
  2316. pci_info(dev, "Linking AER extended capability\n");
  2317. }
  2318. }
  2319. }
  2320. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
  2321. quirk_nvidia_ck804_pcie_aer_ext_cap);
  2322. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
  2323. quirk_nvidia_ck804_pcie_aer_ext_cap);
  2324. static void quirk_via_cx700_pci_parking_caching(struct pci_dev *dev)
  2325. {
  2326. /*
  2327. * Disable PCI Bus Parking and PCI Master read caching on CX700
  2328. * which causes unspecified timing errors with a VT6212L on the PCI
  2329. * bus leading to USB2.0 packet loss.
  2330. *
  2331. * This quirk is only enabled if a second (on the external PCI bus)
  2332. * VT6212L is found -- the CX700 core itself also contains a USB
  2333. * host controller with the same PCI ID as the VT6212L.
  2334. */
  2335. /* Count VT6212L instances */
  2336. struct pci_dev *p = pci_get_device(PCI_VENDOR_ID_VIA,
  2337. PCI_DEVICE_ID_VIA_8235_USB_2, NULL);
  2338. uint8_t b;
  2339. /*
  2340. * p should contain the first (internal) VT6212L -- see if we have
  2341. * an external one by searching again.
  2342. */
  2343. p = pci_get_device(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8235_USB_2, p);
  2344. if (!p)
  2345. return;
  2346. pci_dev_put(p);
  2347. if (pci_read_config_byte(dev, 0x76, &b) == 0) {
  2348. if (b & 0x40) {
  2349. /* Turn off PCI Bus Parking */
  2350. pci_write_config_byte(dev, 0x76, b ^ 0x40);
  2351. pci_info(dev, "Disabling VIA CX700 PCI parking\n");
  2352. }
  2353. }
  2354. if (pci_read_config_byte(dev, 0x72, &b) == 0) {
  2355. if (b != 0) {
  2356. /* Turn off PCI Master read caching */
  2357. pci_write_config_byte(dev, 0x72, 0x0);
  2358. /* Set PCI Master Bus time-out to "1x16 PCLK" */
  2359. pci_write_config_byte(dev, 0x75, 0x1);
  2360. /* Disable "Read FIFO Timer" */
  2361. pci_write_config_byte(dev, 0x77, 0x0);
  2362. pci_info(dev, "Disabling VIA CX700 PCI caching\n");
  2363. }
  2364. }
  2365. }
  2366. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, 0x324e, quirk_via_cx700_pci_parking_caching);
  2367. static void quirk_brcm_5719_limit_mrrs(struct pci_dev *dev)
  2368. {
  2369. u32 rev;
  2370. pci_read_config_dword(dev, 0xf4, &rev);
  2371. /* Only CAP the MRRS if the device is a 5719 A0 */
  2372. if (rev == 0x05719000) {
  2373. int readrq = pcie_get_readrq(dev);
  2374. if (readrq > 2048)
  2375. pcie_set_readrq(dev, 2048);
  2376. }
  2377. }
  2378. DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_BROADCOM,
  2379. PCI_DEVICE_ID_TIGON3_5719,
  2380. quirk_brcm_5719_limit_mrrs);
  2381. /*
  2382. * Originally in EDAC sources for i82875P: Intel tells BIOS developers to
  2383. * hide device 6 which configures the overflow device access containing the
  2384. * DRBs - this is where we expose device 6.
  2385. * http://www.x86-secret.com/articles/tweak/pat/patsecrets-2.htm
  2386. */
  2387. static void quirk_unhide_mch_dev6(struct pci_dev *dev)
  2388. {
  2389. u8 reg;
  2390. if (pci_read_config_byte(dev, 0xF4, &reg) == 0 && !(reg & 0x02)) {
  2391. pci_info(dev, "Enabling MCH 'Overflow' Device\n");
  2392. pci_write_config_byte(dev, 0xF4, reg | 0x02);
  2393. }
  2394. }
  2395. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82865_HB,
  2396. quirk_unhide_mch_dev6);
  2397. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82875_HB,
  2398. quirk_unhide_mch_dev6);
  2399. #ifdef CONFIG_PCI_MSI
  2400. /*
  2401. * Some chipsets do not support MSI. We cannot easily rely on setting
  2402. * PCI_BUS_FLAGS_NO_MSI in its bus flags because there are actually some
  2403. * other buses controlled by the chipset even if Linux is not aware of it.
  2404. * Instead of setting the flag on all buses in the machine, simply disable
  2405. * MSI globally.
  2406. */
  2407. static void quirk_disable_all_msi(struct pci_dev *dev)
  2408. {
  2409. pci_no_msi();
  2410. pci_warn(dev, "MSI quirk detected; MSI disabled\n");
  2411. }
  2412. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_GCNB_LE, quirk_disable_all_msi);
  2413. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS400_200, quirk_disable_all_msi);
  2414. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_RS480, quirk_disable_all_msi);
  2415. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT3336, quirk_disable_all_msi);
  2416. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT3351, quirk_disable_all_msi);
  2417. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_VT3364, quirk_disable_all_msi);
  2418. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, PCI_DEVICE_ID_VIA_8380_0, quirk_disable_all_msi);
  2419. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SI, 0x0761, quirk_disable_all_msi);
  2420. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SAMSUNG, 0xa5e3, quirk_disable_all_msi);
  2421. /* Disable MSI on chipsets that are known to not support it */
  2422. static void quirk_disable_msi(struct pci_dev *dev)
  2423. {
  2424. if (dev->subordinate) {
  2425. pci_warn(dev, "MSI quirk detected; subordinate MSI disabled\n");
  2426. dev->subordinate->bus_flags |= PCI_BUS_FLAGS_NO_MSI;
  2427. }
  2428. }
  2429. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8131_BRIDGE, quirk_disable_msi);
  2430. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_VIA, 0xa238, quirk_disable_msi);
  2431. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x5a3f, quirk_disable_msi);
  2432. /*
  2433. * The APC bridge device in AMD 780 family northbridges has some random
  2434. * OEM subsystem ID in its vendor ID register (erratum 18), so instead
  2435. * we use the possible vendor/device IDs of the host bridge for the
  2436. * declared quirk, and search for the APC bridge by slot number.
  2437. */
  2438. static void quirk_amd_780_apc_msi(struct pci_dev *host_bridge)
  2439. {
  2440. struct pci_dev *apc_bridge;
  2441. apc_bridge = pci_get_slot(host_bridge->bus, PCI_DEVFN(1, 0));
  2442. if (apc_bridge) {
  2443. if (apc_bridge->device == 0x9602)
  2444. quirk_disable_msi(apc_bridge);
  2445. pci_dev_put(apc_bridge);
  2446. }
  2447. }
  2448. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x9600, quirk_amd_780_apc_msi);
  2449. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AMD, 0x9601, quirk_amd_780_apc_msi);
  2450. /*
  2451. * Go through the list of HyperTransport capabilities and return 1 if a HT
  2452. * MSI capability is found and enabled.
  2453. */
  2454. static int msi_ht_cap_enabled(struct pci_dev *dev)
  2455. {
  2456. int pos, ttl = PCI_FIND_CAP_TTL;
  2457. pos = pci_find_ht_capability(dev, HT_CAPTYPE_MSI_MAPPING);
  2458. while (pos && ttl--) {
  2459. u8 flags;
  2460. if (pci_read_config_byte(dev, pos + HT_MSI_FLAGS,
  2461. &flags) == 0) {
  2462. pci_info(dev, "Found %s HT MSI Mapping\n",
  2463. flags & HT_MSI_FLAGS_ENABLE ?
  2464. "enabled" : "disabled");
  2465. return (flags & HT_MSI_FLAGS_ENABLE) != 0;
  2466. }
  2467. pos = pci_find_next_ht_capability(dev, pos,
  2468. HT_CAPTYPE_MSI_MAPPING);
  2469. }
  2470. return 0;
  2471. }
  2472. /* Check the HyperTransport MSI mapping to know whether MSI is enabled or not */
  2473. static void quirk_msi_ht_cap(struct pci_dev *dev)
  2474. {
  2475. if (!msi_ht_cap_enabled(dev))
  2476. quirk_disable_msi(dev);
  2477. }
  2478. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_SERVERWORKS, PCI_DEVICE_ID_SERVERWORKS_HT2000_PCIE,
  2479. quirk_msi_ht_cap);
  2480. /*
  2481. * The nVidia CK804 chipset may have 2 HT MSI mappings. MSI is supported
  2482. * if the MSI capability is set in any of these mappings.
  2483. */
  2484. static void quirk_nvidia_ck804_msi_ht_cap(struct pci_dev *dev)
  2485. {
  2486. struct pci_dev *pdev;
  2487. /*
  2488. * Check HT MSI cap on this chipset and the root one. A single one
  2489. * having MSI is enough to be sure that MSI is supported.
  2490. */
  2491. pdev = pci_get_slot(dev->bus, 0);
  2492. if (!pdev)
  2493. return;
  2494. if (!msi_ht_cap_enabled(pdev))
  2495. quirk_msi_ht_cap(dev);
  2496. pci_dev_put(pdev);
  2497. }
  2498. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_DEVICE_ID_NVIDIA_CK804_PCIE,
  2499. quirk_nvidia_ck804_msi_ht_cap);
  2500. /* Force enable MSI mapping capability on HT bridges */
  2501. static void ht_enable_msi_mapping(struct pci_dev *dev)
  2502. {
  2503. int pos, ttl = PCI_FIND_CAP_TTL;
  2504. pos = pci_find_ht_capability(dev, HT_CAPTYPE_MSI_MAPPING);
  2505. while (pos && ttl--) {
  2506. u8 flags;
  2507. if (pci_read_config_byte(dev, pos + HT_MSI_FLAGS,
  2508. &flags) == 0) {
  2509. pci_info(dev, "Enabling HT MSI Mapping\n");
  2510. pci_write_config_byte(dev, pos + HT_MSI_FLAGS,
  2511. flags | HT_MSI_FLAGS_ENABLE);
  2512. }
  2513. pos = pci_find_next_ht_capability(dev, pos,
  2514. HT_CAPTYPE_MSI_MAPPING);
  2515. }
  2516. }
  2517. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_SERVERWORKS,
  2518. PCI_DEVICE_ID_SERVERWORKS_HT1000_PXB,
  2519. ht_enable_msi_mapping);
  2520. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_AMD, PCI_DEVICE_ID_AMD_8132_BRIDGE,
  2521. ht_enable_msi_mapping);
  2522. /*
  2523. * The P5N32-SLI motherboards from Asus have a problem with MSI
  2524. * for the MCP55 NIC. It is not yet determined whether the MSI problem
  2525. * also affects other devices. As for now, turn off MSI for this device.
  2526. */
  2527. static void nvenet_msi_disable(struct pci_dev *dev)
  2528. {
  2529. const char *board_name = dmi_get_system_info(DMI_BOARD_NAME);
  2530. if (board_name &&
  2531. (strstr(board_name, "P5N32-SLI PREMIUM") ||
  2532. strstr(board_name, "P5N32-E SLI"))) {
  2533. pci_info(dev, "Disabling MSI for MCP55 NIC on P5N32-SLI\n");
  2534. dev->no_msi = 1;
  2535. }
  2536. }
  2537. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA,
  2538. PCI_DEVICE_ID_NVIDIA_NVENET_15,
  2539. nvenet_msi_disable);
  2540. /*
  2541. * PCIe spec r6.0 sec 6.1.4.3 says that if MSI/MSI-X is enabled, the device
  2542. * can't use INTx interrupts. Tegra's PCIe Root Ports don't generate MSI
  2543. * interrupts for PME and AER events; instead only INTx interrupts are
  2544. * generated. Though Tegra's PCIe Root Ports can generate MSI interrupts
  2545. * for other events, since PCIe specification doesn't support using a mix of
  2546. * INTx and MSI/MSI-X, it is required to disable MSI interrupts to avoid port
  2547. * service drivers registering their respective ISRs for MSIs.
  2548. */
  2549. static void pci_quirk_nvidia_tegra_disable_rp_msi(struct pci_dev *dev)
  2550. {
  2551. dev->no_msi = 1;
  2552. }
  2553. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x1ad0,
  2554. PCI_CLASS_BRIDGE_PCI, 8,
  2555. pci_quirk_nvidia_tegra_disable_rp_msi);
  2556. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x1ad1,
  2557. PCI_CLASS_BRIDGE_PCI, 8,
  2558. pci_quirk_nvidia_tegra_disable_rp_msi);
  2559. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x1ad2,
  2560. PCI_CLASS_BRIDGE_PCI, 8,
  2561. pci_quirk_nvidia_tegra_disable_rp_msi);
  2562. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0bf0,
  2563. PCI_CLASS_BRIDGE_PCI, 8,
  2564. pci_quirk_nvidia_tegra_disable_rp_msi);
  2565. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0bf1,
  2566. PCI_CLASS_BRIDGE_PCI, 8,
  2567. pci_quirk_nvidia_tegra_disable_rp_msi);
  2568. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0e1c,
  2569. PCI_CLASS_BRIDGE_PCI, 8,
  2570. pci_quirk_nvidia_tegra_disable_rp_msi);
  2571. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0e1d,
  2572. PCI_CLASS_BRIDGE_PCI, 8,
  2573. pci_quirk_nvidia_tegra_disable_rp_msi);
  2574. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0e12,
  2575. PCI_CLASS_BRIDGE_PCI, 8,
  2576. pci_quirk_nvidia_tegra_disable_rp_msi);
  2577. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0e13,
  2578. PCI_CLASS_BRIDGE_PCI, 8,
  2579. pci_quirk_nvidia_tegra_disable_rp_msi);
  2580. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0fae,
  2581. PCI_CLASS_BRIDGE_PCI, 8,
  2582. pci_quirk_nvidia_tegra_disable_rp_msi);
  2583. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x0faf,
  2584. PCI_CLASS_BRIDGE_PCI, 8,
  2585. pci_quirk_nvidia_tegra_disable_rp_msi);
  2586. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x10e5,
  2587. PCI_CLASS_BRIDGE_PCI, 8,
  2588. pci_quirk_nvidia_tegra_disable_rp_msi);
  2589. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x10e6,
  2590. PCI_CLASS_BRIDGE_PCI, 8,
  2591. pci_quirk_nvidia_tegra_disable_rp_msi);
  2592. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x229a,
  2593. PCI_CLASS_BRIDGE_PCI, 8,
  2594. pci_quirk_nvidia_tegra_disable_rp_msi);
  2595. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x229c,
  2596. PCI_CLASS_BRIDGE_PCI, 8,
  2597. pci_quirk_nvidia_tegra_disable_rp_msi);
  2598. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_NVIDIA, 0x229e,
  2599. PCI_CLASS_BRIDGE_PCI, 8,
  2600. pci_quirk_nvidia_tegra_disable_rp_msi);
  2601. /*
  2602. * Some versions of the MCP55 bridge from Nvidia have a legacy IRQ routing
  2603. * config register. This register controls the routing of legacy
  2604. * interrupts from devices that route through the MCP55. If this register
  2605. * is misprogrammed, interrupts are only sent to the BSP, unlike
  2606. * conventional systems where the IRQ is broadcast to all online CPUs. Not
  2607. * having this register set properly prevents kdump from booting up
  2608. * properly, so let's make sure that we have it set correctly.
  2609. * Note that this is an undocumented register.
  2610. */
  2611. static void nvbridge_check_legacy_irq_routing(struct pci_dev *dev)
  2612. {
  2613. u32 cfg;
  2614. if (!pci_find_capability(dev, PCI_CAP_ID_HT))
  2615. return;
  2616. pci_read_config_dword(dev, 0x74, &cfg);
  2617. if (cfg & ((1 << 2) | (1 << 15))) {
  2618. pr_info("Rewriting IRQ routing register on MCP55\n");
  2619. cfg &= ~((1 << 2) | (1 << 15));
  2620. pci_write_config_dword(dev, 0x74, cfg);
  2621. }
  2622. }
  2623. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA,
  2624. PCI_DEVICE_ID_NVIDIA_MCP55_BRIDGE_V0,
  2625. nvbridge_check_legacy_irq_routing);
  2626. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_NVIDIA,
  2627. PCI_DEVICE_ID_NVIDIA_MCP55_BRIDGE_V4,
  2628. nvbridge_check_legacy_irq_routing);
  2629. static int ht_check_msi_mapping(struct pci_dev *dev)
  2630. {
  2631. int pos, ttl = PCI_FIND_CAP_TTL;
  2632. int found = 0;
  2633. /* Check if there is HT MSI cap or enabled on this device */
  2634. pos = pci_find_ht_capability(dev, HT_CAPTYPE_MSI_MAPPING);
  2635. while (pos && ttl--) {
  2636. u8 flags;
  2637. if (found < 1)
  2638. found = 1;
  2639. if (pci_read_config_byte(dev, pos + HT_MSI_FLAGS,
  2640. &flags) == 0) {
  2641. if (flags & HT_MSI_FLAGS_ENABLE) {
  2642. if (found < 2) {
  2643. found = 2;
  2644. break;
  2645. }
  2646. }
  2647. }
  2648. pos = pci_find_next_ht_capability(dev, pos,
  2649. HT_CAPTYPE_MSI_MAPPING);
  2650. }
  2651. return found;
  2652. }
  2653. static int host_bridge_with_leaf(struct pci_dev *host_bridge)
  2654. {
  2655. struct pci_dev *dev;
  2656. int pos;
  2657. int i, dev_no;
  2658. int found = 0;
  2659. dev_no = host_bridge->devfn >> 3;
  2660. for (i = dev_no + 1; i < 0x20; i++) {
  2661. dev = pci_get_slot(host_bridge->bus, PCI_DEVFN(i, 0));
  2662. if (!dev)
  2663. continue;
  2664. /* found next host bridge? */
  2665. pos = pci_find_ht_capability(dev, HT_CAPTYPE_SLAVE);
  2666. if (pos != 0) {
  2667. pci_dev_put(dev);
  2668. break;
  2669. }
  2670. if (ht_check_msi_mapping(dev)) {
  2671. found = 1;
  2672. pci_dev_put(dev);
  2673. break;
  2674. }
  2675. pci_dev_put(dev);
  2676. }
  2677. return found;
  2678. }
  2679. #define PCI_HT_CAP_SLAVE_CTRL0 4 /* link control */
  2680. #define PCI_HT_CAP_SLAVE_CTRL1 8 /* link control to */
  2681. static int is_end_of_ht_chain(struct pci_dev *dev)
  2682. {
  2683. int pos, ctrl_off;
  2684. int end = 0;
  2685. u16 flags, ctrl;
  2686. pos = pci_find_ht_capability(dev, HT_CAPTYPE_SLAVE);
  2687. if (!pos)
  2688. goto out;
  2689. pci_read_config_word(dev, pos + PCI_CAP_FLAGS, &flags);
  2690. ctrl_off = ((flags >> 10) & 1) ?
  2691. PCI_HT_CAP_SLAVE_CTRL0 : PCI_HT_CAP_SLAVE_CTRL1;
  2692. pci_read_config_word(dev, pos + ctrl_off, &ctrl);
  2693. if (ctrl & (1 << 6))
  2694. end = 1;
  2695. out:
  2696. return end;
  2697. }
  2698. static void nv_ht_enable_msi_mapping(struct pci_dev *dev)
  2699. {
  2700. struct pci_dev *host_bridge;
  2701. int pos;
  2702. int i, dev_no;
  2703. int found = 0;
  2704. dev_no = dev->devfn >> 3;
  2705. for (i = dev_no; i >= 0; i--) {
  2706. host_bridge = pci_get_slot(dev->bus, PCI_DEVFN(i, 0));
  2707. if (!host_bridge)
  2708. continue;
  2709. pos = pci_find_ht_capability(host_bridge, HT_CAPTYPE_SLAVE);
  2710. if (pos != 0) {
  2711. found = 1;
  2712. break;
  2713. }
  2714. pci_dev_put(host_bridge);
  2715. }
  2716. if (!found)
  2717. return;
  2718. /* don't enable end_device/host_bridge with leaf directly here */
  2719. if (host_bridge == dev && is_end_of_ht_chain(host_bridge) &&
  2720. host_bridge_with_leaf(host_bridge))
  2721. goto out;
  2722. /* root did that ! */
  2723. if (msi_ht_cap_enabled(host_bridge))
  2724. goto out;
  2725. ht_enable_msi_mapping(dev);
  2726. out:
  2727. pci_dev_put(host_bridge);
  2728. }
  2729. static void ht_disable_msi_mapping(struct pci_dev *dev)
  2730. {
  2731. int pos, ttl = PCI_FIND_CAP_TTL;
  2732. pos = pci_find_ht_capability(dev, HT_CAPTYPE_MSI_MAPPING);
  2733. while (pos && ttl--) {
  2734. u8 flags;
  2735. if (pci_read_config_byte(dev, pos + HT_MSI_FLAGS,
  2736. &flags) == 0) {
  2737. pci_info(dev, "Disabling HT MSI Mapping\n");
  2738. pci_write_config_byte(dev, pos + HT_MSI_FLAGS,
  2739. flags & ~HT_MSI_FLAGS_ENABLE);
  2740. }
  2741. pos = pci_find_next_ht_capability(dev, pos,
  2742. HT_CAPTYPE_MSI_MAPPING);
  2743. }
  2744. }
  2745. static void __nv_msi_ht_cap_quirk(struct pci_dev *dev, int all)
  2746. {
  2747. struct pci_dev *host_bridge;
  2748. int pos;
  2749. int found;
  2750. if (!pci_msi_enabled())
  2751. return;
  2752. /* check if there is HT MSI cap or enabled on this device */
  2753. found = ht_check_msi_mapping(dev);
  2754. /* no HT MSI CAP */
  2755. if (found == 0)
  2756. return;
  2757. /*
  2758. * HT MSI mapping should be disabled on devices that are below
  2759. * a non-HyperTransport host bridge. Locate the host bridge.
  2760. */
  2761. host_bridge = pci_get_domain_bus_and_slot(pci_domain_nr(dev->bus), 0,
  2762. PCI_DEVFN(0, 0));
  2763. if (host_bridge == NULL) {
  2764. pci_warn(dev, "nv_msi_ht_cap_quirk didn't locate host bridge\n");
  2765. return;
  2766. }
  2767. pos = pci_find_ht_capability(host_bridge, HT_CAPTYPE_SLAVE);
  2768. if (pos != 0) {
  2769. /* Host bridge is to HT */
  2770. if (found == 1) {
  2771. /* it is not enabled, try to enable it */
  2772. if (all)
  2773. ht_enable_msi_mapping(dev);
  2774. else
  2775. nv_ht_enable_msi_mapping(dev);
  2776. }
  2777. goto out;
  2778. }
  2779. /* HT MSI is not enabled */
  2780. if (found == 1)
  2781. goto out;
  2782. /* Host bridge is not to HT, disable HT MSI mapping on this device */
  2783. ht_disable_msi_mapping(dev);
  2784. out:
  2785. pci_dev_put(host_bridge);
  2786. }
  2787. static void nv_msi_ht_cap_quirk_all(struct pci_dev *dev)
  2788. {
  2789. return __nv_msi_ht_cap_quirk(dev, 1);
  2790. }
  2791. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_AL, PCI_ANY_ID, nv_msi_ht_cap_quirk_all);
  2792. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_AL, PCI_ANY_ID, nv_msi_ht_cap_quirk_all);
  2793. static void nv_msi_ht_cap_quirk_leaf(struct pci_dev *dev)
  2794. {
  2795. return __nv_msi_ht_cap_quirk(dev, 0);
  2796. }
  2797. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, nv_msi_ht_cap_quirk_leaf);
  2798. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID, nv_msi_ht_cap_quirk_leaf);
  2799. static void quirk_msi_intx_disable_bug(struct pci_dev *dev)
  2800. {
  2801. dev->dev_flags |= PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG;
  2802. }
  2803. static void quirk_msi_intx_disable_ati_bug(struct pci_dev *dev)
  2804. {
  2805. struct pci_dev *p;
  2806. /*
  2807. * SB700 MSI issue will be fixed at HW level from revision A21;
  2808. * we need check PCI REVISION ID of SMBus controller to get SB700
  2809. * revision.
  2810. */
  2811. p = pci_get_device(PCI_VENDOR_ID_ATI, PCI_DEVICE_ID_ATI_SBX00_SMBUS,
  2812. NULL);
  2813. if (!p)
  2814. return;
  2815. if ((p->revision < 0x3B) && (p->revision >= 0x30))
  2816. dev->dev_flags |= PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG;
  2817. pci_dev_put(p);
  2818. }
  2819. static void quirk_msi_intx_disable_qca_bug(struct pci_dev *dev)
  2820. {
  2821. /* AR816X/AR817X/E210X MSI is fixed at HW level from revision 0x18 */
  2822. if (dev->revision < 0x18) {
  2823. pci_info(dev, "set MSI_INTX_DISABLE_BUG flag\n");
  2824. dev->dev_flags |= PCI_DEV_FLAGS_MSI_INTX_DISABLE_BUG;
  2825. }
  2826. }
  2827. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
  2828. PCI_DEVICE_ID_TIGON3_5780,
  2829. quirk_msi_intx_disable_bug);
  2830. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
  2831. PCI_DEVICE_ID_TIGON3_5780S,
  2832. quirk_msi_intx_disable_bug);
  2833. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
  2834. PCI_DEVICE_ID_TIGON3_5714,
  2835. quirk_msi_intx_disable_bug);
  2836. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
  2837. PCI_DEVICE_ID_TIGON3_5714S,
  2838. quirk_msi_intx_disable_bug);
  2839. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
  2840. PCI_DEVICE_ID_TIGON3_5715,
  2841. quirk_msi_intx_disable_bug);
  2842. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_BROADCOM,
  2843. PCI_DEVICE_ID_TIGON3_5715S,
  2844. quirk_msi_intx_disable_bug);
  2845. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4390,
  2846. quirk_msi_intx_disable_ati_bug);
  2847. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4391,
  2848. quirk_msi_intx_disable_ati_bug);
  2849. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4392,
  2850. quirk_msi_intx_disable_ati_bug);
  2851. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4393,
  2852. quirk_msi_intx_disable_ati_bug);
  2853. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4394,
  2854. quirk_msi_intx_disable_ati_bug);
  2855. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4373,
  2856. quirk_msi_intx_disable_bug);
  2857. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4374,
  2858. quirk_msi_intx_disable_bug);
  2859. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x4375,
  2860. quirk_msi_intx_disable_bug);
  2861. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1062,
  2862. quirk_msi_intx_disable_bug);
  2863. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1063,
  2864. quirk_msi_intx_disable_bug);
  2865. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x2060,
  2866. quirk_msi_intx_disable_bug);
  2867. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x2062,
  2868. quirk_msi_intx_disable_bug);
  2869. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1073,
  2870. quirk_msi_intx_disable_bug);
  2871. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1083,
  2872. quirk_msi_intx_disable_bug);
  2873. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1090,
  2874. quirk_msi_intx_disable_qca_bug);
  2875. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x1091,
  2876. quirk_msi_intx_disable_qca_bug);
  2877. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x10a0,
  2878. quirk_msi_intx_disable_qca_bug);
  2879. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0x10a1,
  2880. quirk_msi_intx_disable_qca_bug);
  2881. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATTANSIC, 0xe091,
  2882. quirk_msi_intx_disable_qca_bug);
  2883. /*
  2884. * Amazon's Annapurna Labs 1c36:0031 Root Ports don't support MSI-X, so it
  2885. * should be disabled on platforms where the device (mistakenly) advertises it.
  2886. *
  2887. * Notice that this quirk also disables MSI (which may work, but hasn't been
  2888. * tested), since currently there is no standard way to disable only MSI-X.
  2889. *
  2890. * The 0031 device id is reused for other non Root Port device types,
  2891. * therefore the quirk is registered for the PCI_CLASS_BRIDGE_PCI class.
  2892. */
  2893. static void quirk_al_msi_disable(struct pci_dev *dev)
  2894. {
  2895. dev->no_msi = 1;
  2896. pci_warn(dev, "Disabling MSI/MSI-X\n");
  2897. }
  2898. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_AMAZON_ANNAPURNA_LABS, 0x0031,
  2899. PCI_CLASS_BRIDGE_PCI, 8, quirk_al_msi_disable);
  2900. #endif /* CONFIG_PCI_MSI */
  2901. /*
  2902. * Allow manual resource allocation for PCI hotplug bridges via
  2903. * pci=hpmemsize=nnM and pci=hpiosize=nnM parameters. For some PCI-PCI
  2904. * hotplug bridges, like PLX 6254 (former HINT HB6), kernel fails to
  2905. * allocate resources when hotplug device is inserted and PCI bus is
  2906. * rescanned.
  2907. */
  2908. static void quirk_hotplug_bridge(struct pci_dev *dev)
  2909. {
  2910. dev->is_hotplug_bridge = 1;
  2911. }
  2912. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_HINT, 0x0020, quirk_hotplug_bridge);
  2913. /*
  2914. * This is a quirk for the Ricoh MMC controller found as a part of some
  2915. * multifunction chips.
  2916. *
  2917. * This is very similar and based on the ricoh_mmc driver written by
  2918. * Philip Langdale. Thank you for these magic sequences.
  2919. *
  2920. * These chips implement the four main memory card controllers (SD, MMC,
  2921. * MS, xD) and one or both of CardBus or FireWire.
  2922. *
  2923. * It happens that they implement SD and MMC support as separate
  2924. * controllers (and PCI functions). The Linux SDHCI driver supports MMC
  2925. * cards but the chip detects MMC cards in hardware and directs them to the
  2926. * MMC controller - so the SDHCI driver never sees them.
  2927. *
  2928. * To get around this, we must disable the useless MMC controller. At that
  2929. * point, the SDHCI controller will start seeing them. It seems to be the
  2930. * case that the relevant PCI registers to deactivate the MMC controller
  2931. * live on PCI function 0, which might be the CardBus controller or the
  2932. * FireWire controller, depending on the particular chip in question
  2933. *
  2934. * This has to be done early, because as soon as we disable the MMC controller
  2935. * other PCI functions shift up one level, e.g. function #2 becomes function
  2936. * #1, and this will confuse the PCI core.
  2937. */
  2938. #ifdef CONFIG_MMC_RICOH_MMC
  2939. static void ricoh_mmc_fixup_rl5c476(struct pci_dev *dev)
  2940. {
  2941. u8 write_enable;
  2942. u8 write_target;
  2943. u8 disable;
  2944. /*
  2945. * Disable via CardBus interface
  2946. *
  2947. * This must be done via function #0
  2948. */
  2949. if (PCI_FUNC(dev->devfn))
  2950. return;
  2951. pci_read_config_byte(dev, 0xB7, &disable);
  2952. if (disable & 0x02)
  2953. return;
  2954. pci_read_config_byte(dev, 0x8E, &write_enable);
  2955. pci_write_config_byte(dev, 0x8E, 0xAA);
  2956. pci_read_config_byte(dev, 0x8D, &write_target);
  2957. pci_write_config_byte(dev, 0x8D, 0xB7);
  2958. pci_write_config_byte(dev, 0xB7, disable | 0x02);
  2959. pci_write_config_byte(dev, 0x8E, write_enable);
  2960. pci_write_config_byte(dev, 0x8D, write_target);
  2961. pci_notice(dev, "proprietary Ricoh MMC controller disabled (via CardBus function)\n");
  2962. pci_notice(dev, "MMC cards are now supported by standard SDHCI controller\n");
  2963. }
  2964. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C476, ricoh_mmc_fixup_rl5c476);
  2965. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_RL5C476, ricoh_mmc_fixup_rl5c476);
  2966. static void ricoh_mmc_fixup_r5c832(struct pci_dev *dev)
  2967. {
  2968. u8 write_enable;
  2969. u8 disable;
  2970. /*
  2971. * Disable via FireWire interface
  2972. *
  2973. * This must be done via function #0
  2974. */
  2975. if (PCI_FUNC(dev->devfn))
  2976. return;
  2977. /*
  2978. * RICOH 0xe822 and 0xe823 SD/MMC card readers fail to recognize
  2979. * certain types of SD/MMC cards. Lowering the SD base clock
  2980. * frequency from 200Mhz to 50Mhz fixes this issue.
  2981. *
  2982. * 0x150 - SD2.0 mode enable for changing base clock
  2983. * frequency to 50Mhz
  2984. * 0xe1 - Base clock frequency
  2985. * 0x32 - 50Mhz new clock frequency
  2986. * 0xf9 - Key register for 0x150
  2987. * 0xfc - key register for 0xe1
  2988. */
  2989. if (dev->device == PCI_DEVICE_ID_RICOH_R5CE822 ||
  2990. dev->device == PCI_DEVICE_ID_RICOH_R5CE823) {
  2991. pci_write_config_byte(dev, 0xf9, 0xfc);
  2992. pci_write_config_byte(dev, 0x150, 0x10);
  2993. pci_write_config_byte(dev, 0xf9, 0x00);
  2994. pci_write_config_byte(dev, 0xfc, 0x01);
  2995. pci_write_config_byte(dev, 0xe1, 0x32);
  2996. pci_write_config_byte(dev, 0xfc, 0x00);
  2997. pci_notice(dev, "MMC controller base frequency changed to 50Mhz.\n");
  2998. }
  2999. pci_read_config_byte(dev, 0xCB, &disable);
  3000. if (disable & 0x02)
  3001. return;
  3002. pci_read_config_byte(dev, 0xCA, &write_enable);
  3003. pci_write_config_byte(dev, 0xCA, 0x57);
  3004. pci_write_config_byte(dev, 0xCB, disable | 0x02);
  3005. pci_write_config_byte(dev, 0xCA, write_enable);
  3006. pci_notice(dev, "proprietary Ricoh MMC controller disabled (via FireWire function)\n");
  3007. pci_notice(dev, "MMC cards are now supported by standard SDHCI controller\n");
  3008. }
  3009. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C832, ricoh_mmc_fixup_r5c832);
  3010. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5C832, ricoh_mmc_fixup_r5c832);
  3011. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5CE822, ricoh_mmc_fixup_r5c832);
  3012. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5CE822, ricoh_mmc_fixup_r5c832);
  3013. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5CE823, ricoh_mmc_fixup_r5c832);
  3014. DECLARE_PCI_FIXUP_RESUME_EARLY(PCI_VENDOR_ID_RICOH, PCI_DEVICE_ID_RICOH_R5CE823, ricoh_mmc_fixup_r5c832);
  3015. #endif /*CONFIG_MMC_RICOH_MMC*/
  3016. #ifdef CONFIG_DMAR_TABLE
  3017. #define VTUNCERRMSK_REG 0x1ac
  3018. #define VTD_MSK_SPEC_ERRORS (1 << 31)
  3019. /*
  3020. * This is a quirk for masking VT-d spec-defined errors to platform error
  3021. * handling logic. Without this, platforms using Intel 7500, 5500 chipsets
  3022. * (and the derivative chipsets like X58 etc) seem to generate NMI/SMI (based
  3023. * on the RAS config settings of the platform) when a VT-d fault happens.
  3024. * The resulting SMI caused the system to hang.
  3025. *
  3026. * VT-d spec-related errors are already handled by the VT-d OS code, so no
  3027. * need to report the same error through other channels.
  3028. */
  3029. static void vtd_mask_spec_errors(struct pci_dev *dev)
  3030. {
  3031. u32 word;
  3032. pci_read_config_dword(dev, VTUNCERRMSK_REG, &word);
  3033. pci_write_config_dword(dev, VTUNCERRMSK_REG, word | VTD_MSK_SPEC_ERRORS);
  3034. }
  3035. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x342e, vtd_mask_spec_errors);
  3036. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x3c28, vtd_mask_spec_errors);
  3037. #endif
  3038. static void fixup_ti816x_class(struct pci_dev *dev)
  3039. {
  3040. u32 class = dev->class;
  3041. /* TI 816x devices do not have class code set when in PCIe boot mode */
  3042. dev->class = PCI_CLASS_MULTIMEDIA_VIDEO << 8;
  3043. pci_info(dev, "PCI class overridden (%#08x -> %#08x)\n",
  3044. class, dev->class);
  3045. }
  3046. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_TI, 0xb800,
  3047. PCI_CLASS_NOT_DEFINED, 8, fixup_ti816x_class);
  3048. /*
  3049. * Some PCIe devices do not work reliably with the claimed maximum
  3050. * payload size supported.
  3051. */
  3052. static void fixup_mpss_256(struct pci_dev *dev)
  3053. {
  3054. dev->pcie_mpss = 1; /* 256 bytes */
  3055. }
  3056. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SOLARFLARE,
  3057. PCI_DEVICE_ID_SOLARFLARE_SFC4000A_0, fixup_mpss_256);
  3058. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SOLARFLARE,
  3059. PCI_DEVICE_ID_SOLARFLARE_SFC4000A_1, fixup_mpss_256);
  3060. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SOLARFLARE,
  3061. PCI_DEVICE_ID_SOLARFLARE_SFC4000B, fixup_mpss_256);
  3062. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_ASMEDIA, 0x0612, fixup_mpss_256);
  3063. /*
  3064. * Intel 5000 and 5100 Memory controllers have an erratum with read completion
  3065. * coalescing (which is enabled by default on some BIOSes) and MPS of 256B.
  3066. * Since there is no way of knowing what the PCIe MPS on each fabric will be
  3067. * until all of the devices are discovered and buses walked, read completion
  3068. * coalescing must be disabled. Unfortunately, it cannot be re-enabled because
  3069. * it is possible to hotplug a device with MPS of 256B.
  3070. */
  3071. static void quirk_intel_mc_errata(struct pci_dev *dev)
  3072. {
  3073. int err;
  3074. u16 rcc;
  3075. if (pcie_bus_config == PCIE_BUS_TUNE_OFF ||
  3076. pcie_bus_config == PCIE_BUS_DEFAULT)
  3077. return;
  3078. /*
  3079. * Intel erratum specifies bits to change but does not say what
  3080. * they are. Keeping them magical until such time as the registers
  3081. * and values can be explained.
  3082. */
  3083. err = pci_read_config_word(dev, 0x48, &rcc);
  3084. if (err) {
  3085. pci_err(dev, "Error attempting to read the read completion coalescing register\n");
  3086. return;
  3087. }
  3088. if (!(rcc & (1 << 10)))
  3089. return;
  3090. rcc &= ~(1 << 10);
  3091. err = pci_write_config_word(dev, 0x48, rcc);
  3092. if (err) {
  3093. pci_err(dev, "Error attempting to write the read completion coalescing register\n");
  3094. return;
  3095. }
  3096. pr_info_once("Read completion coalescing disabled due to hardware erratum relating to 256B MPS\n");
  3097. }
  3098. /* Intel 5000 series memory controllers and ports 2-7 */
  3099. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25c0, quirk_intel_mc_errata);
  3100. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25d0, quirk_intel_mc_errata);
  3101. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25d4, quirk_intel_mc_errata);
  3102. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25d8, quirk_intel_mc_errata);
  3103. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e2, quirk_intel_mc_errata);
  3104. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e3, quirk_intel_mc_errata);
  3105. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e4, quirk_intel_mc_errata);
  3106. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e5, quirk_intel_mc_errata);
  3107. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e6, quirk_intel_mc_errata);
  3108. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25e7, quirk_intel_mc_errata);
  3109. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25f7, quirk_intel_mc_errata);
  3110. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25f8, quirk_intel_mc_errata);
  3111. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25f9, quirk_intel_mc_errata);
  3112. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x25fa, quirk_intel_mc_errata);
  3113. /* Intel 5100 series memory controllers and ports 2-7 */
  3114. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65c0, quirk_intel_mc_errata);
  3115. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e2, quirk_intel_mc_errata);
  3116. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e3, quirk_intel_mc_errata);
  3117. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e4, quirk_intel_mc_errata);
  3118. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e5, quirk_intel_mc_errata);
  3119. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e6, quirk_intel_mc_errata);
  3120. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65e7, quirk_intel_mc_errata);
  3121. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65f7, quirk_intel_mc_errata);
  3122. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65f8, quirk_intel_mc_errata);
  3123. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65f9, quirk_intel_mc_errata);
  3124. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x65fa, quirk_intel_mc_errata);
  3125. /*
  3126. * Ivytown NTB BAR sizes are misreported by the hardware due to an erratum.
  3127. * To work around this, query the size it should be configured to by the
  3128. * device and modify the resource end to correspond to this new size.
  3129. */
  3130. static void quirk_intel_ntb(struct pci_dev *dev)
  3131. {
  3132. int rc;
  3133. u8 val;
  3134. rc = pci_read_config_byte(dev, 0x00D0, &val);
  3135. if (rc)
  3136. return;
  3137. dev->resource[2].end = dev->resource[2].start + ((u64) 1 << val) - 1;
  3138. rc = pci_read_config_byte(dev, 0x00D1, &val);
  3139. if (rc)
  3140. return;
  3141. dev->resource[4].end = dev->resource[4].start + ((u64) 1 << val) - 1;
  3142. }
  3143. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x0e08, quirk_intel_ntb);
  3144. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x0e0d, quirk_intel_ntb);
  3145. /*
  3146. * Some BIOS implementations leave the Intel GPU interrupts enabled, even
  3147. * though no one is handling them (e.g., if the i915 driver is never
  3148. * loaded). Additionally the interrupt destination is not set up properly
  3149. * and the interrupt ends up -somewhere-.
  3150. *
  3151. * These spurious interrupts are "sticky" and the kernel disables the
  3152. * (shared) interrupt line after 100,000+ generated interrupts.
  3153. *
  3154. * Fix it by disabling the still enabled interrupts. This resolves crashes
  3155. * often seen on monitor unplug.
  3156. */
  3157. #define I915_DEIER_REG 0x4400c
  3158. static void disable_igfx_irq(struct pci_dev *dev)
  3159. {
  3160. void __iomem *regs = pci_iomap(dev, 0, 0);
  3161. if (regs == NULL) {
  3162. pci_warn(dev, "igfx quirk: Can't iomap PCI device\n");
  3163. return;
  3164. }
  3165. /* Check if any interrupt line is still enabled */
  3166. if (readl(regs + I915_DEIER_REG) != 0) {
  3167. pci_warn(dev, "BIOS left Intel GPU interrupts enabled; disabling\n");
  3168. writel(0, regs + I915_DEIER_REG);
  3169. }
  3170. pci_iounmap(dev, regs);
  3171. }
  3172. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0042, disable_igfx_irq);
  3173. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0046, disable_igfx_irq);
  3174. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x004a, disable_igfx_irq);
  3175. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0102, disable_igfx_irq);
  3176. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0106, disable_igfx_irq);
  3177. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x010a, disable_igfx_irq);
  3178. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0152, disable_igfx_irq);
  3179. /*
  3180. * PCI devices which are on Intel chips can skip the 10ms delay
  3181. * before entering D3 mode.
  3182. */
  3183. static void quirk_remove_d3hot_delay(struct pci_dev *dev)
  3184. {
  3185. dev->d3hot_delay = 0;
  3186. }
  3187. /* C600 Series devices do not need 10ms d3hot_delay */
  3188. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0412, quirk_remove_d3hot_delay);
  3189. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0c00, quirk_remove_d3hot_delay);
  3190. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x0c0c, quirk_remove_d3hot_delay);
  3191. /* Lynxpoint-H PCH devices do not need 10ms d3hot_delay */
  3192. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c02, quirk_remove_d3hot_delay);
  3193. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c18, quirk_remove_d3hot_delay);
  3194. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c1c, quirk_remove_d3hot_delay);
  3195. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c20, quirk_remove_d3hot_delay);
  3196. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c22, quirk_remove_d3hot_delay);
  3197. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c26, quirk_remove_d3hot_delay);
  3198. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c2d, quirk_remove_d3hot_delay);
  3199. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c31, quirk_remove_d3hot_delay);
  3200. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c3a, quirk_remove_d3hot_delay);
  3201. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c3d, quirk_remove_d3hot_delay);
  3202. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x8c4e, quirk_remove_d3hot_delay);
  3203. /* Intel Cherrytrail devices do not need 10ms d3hot_delay */
  3204. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2280, quirk_remove_d3hot_delay);
  3205. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x2298, quirk_remove_d3hot_delay);
  3206. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x229c, quirk_remove_d3hot_delay);
  3207. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x22b0, quirk_remove_d3hot_delay);
  3208. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x22b5, quirk_remove_d3hot_delay);
  3209. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x22b7, quirk_remove_d3hot_delay);
  3210. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x22b8, quirk_remove_d3hot_delay);
  3211. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x22d8, quirk_remove_d3hot_delay);
  3212. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x22dc, quirk_remove_d3hot_delay);
  3213. /*
  3214. * Some devices may pass our check in pci_intx_mask_supported() if
  3215. * PCI_COMMAND_INTX_DISABLE works though they actually do not properly
  3216. * support this feature.
  3217. */
  3218. static void quirk_broken_intx_masking(struct pci_dev *dev)
  3219. {
  3220. dev->broken_intx_masking = 1;
  3221. }
  3222. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CHELSIO, 0x0030,
  3223. quirk_broken_intx_masking);
  3224. DECLARE_PCI_FIXUP_FINAL(0x1814, 0x0601, /* Ralink RT2800 802.11n PCI */
  3225. quirk_broken_intx_masking);
  3226. DECLARE_PCI_FIXUP_FINAL(0x1b7c, 0x0004, /* Ceton InfiniTV4 */
  3227. quirk_broken_intx_masking);
  3228. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_CREATIVE, PCI_DEVICE_ID_CREATIVE_20K2,
  3229. quirk_broken_intx_masking);
  3230. /*
  3231. * Realtek RTL8169 PCI Gigabit Ethernet Controller (rev 10)
  3232. * Subsystem: Realtek RTL8169/8110 Family PCI Gigabit Ethernet NIC
  3233. *
  3234. * RTL8110SC - Fails under PCI device assignment using DisINTx masking.
  3235. */
  3236. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REALTEK, 0x8169,
  3237. quirk_broken_intx_masking);
  3238. /*
  3239. * Intel i40e (XL710/X710) 10/20/40GbE NICs all have broken INTx masking,
  3240. * DisINTx can be set but the interrupt status bit is non-functional.
  3241. */
  3242. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1572, quirk_broken_intx_masking);
  3243. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1574, quirk_broken_intx_masking);
  3244. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1580, quirk_broken_intx_masking);
  3245. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1581, quirk_broken_intx_masking);
  3246. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1583, quirk_broken_intx_masking);
  3247. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1584, quirk_broken_intx_masking);
  3248. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1585, quirk_broken_intx_masking);
  3249. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1586, quirk_broken_intx_masking);
  3250. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1587, quirk_broken_intx_masking);
  3251. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1588, quirk_broken_intx_masking);
  3252. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1589, quirk_broken_intx_masking);
  3253. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x158a, quirk_broken_intx_masking);
  3254. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x158b, quirk_broken_intx_masking);
  3255. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x37d0, quirk_broken_intx_masking);
  3256. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x37d1, quirk_broken_intx_masking);
  3257. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x37d2, quirk_broken_intx_masking);
  3258. static u16 mellanox_broken_intx_devs[] = {
  3259. PCI_DEVICE_ID_MELLANOX_HERMON_SDR,
  3260. PCI_DEVICE_ID_MELLANOX_HERMON_DDR,
  3261. PCI_DEVICE_ID_MELLANOX_HERMON_QDR,
  3262. PCI_DEVICE_ID_MELLANOX_HERMON_DDR_GEN2,
  3263. PCI_DEVICE_ID_MELLANOX_HERMON_QDR_GEN2,
  3264. PCI_DEVICE_ID_MELLANOX_HERMON_EN,
  3265. PCI_DEVICE_ID_MELLANOX_HERMON_EN_GEN2,
  3266. PCI_DEVICE_ID_MELLANOX_CONNECTX_EN,
  3267. PCI_DEVICE_ID_MELLANOX_CONNECTX_EN_T_GEN2,
  3268. PCI_DEVICE_ID_MELLANOX_CONNECTX_EN_GEN2,
  3269. PCI_DEVICE_ID_MELLANOX_CONNECTX_EN_5_GEN2,
  3270. PCI_DEVICE_ID_MELLANOX_CONNECTX2,
  3271. PCI_DEVICE_ID_MELLANOX_CONNECTX3,
  3272. PCI_DEVICE_ID_MELLANOX_CONNECTX3_PRO,
  3273. };
  3274. #define CONNECTX_4_CURR_MAX_MINOR 99
  3275. #define CONNECTX_4_INTX_SUPPORT_MINOR 14
  3276. /*
  3277. * Check ConnectX-4/LX FW version to see if it supports legacy interrupts.
  3278. * If so, don't mark it as broken.
  3279. * FW minor > 99 means older FW version format and no INTx masking support.
  3280. * FW minor < 14 means new FW version format and no INTx masking support.
  3281. */
  3282. static void mellanox_check_broken_intx_masking(struct pci_dev *pdev)
  3283. {
  3284. __be32 __iomem *fw_ver;
  3285. u16 fw_major;
  3286. u16 fw_minor;
  3287. u16 fw_subminor;
  3288. u32 fw_maj_min;
  3289. u32 fw_sub_min;
  3290. int i;
  3291. for (i = 0; i < ARRAY_SIZE(mellanox_broken_intx_devs); i++) {
  3292. if (pdev->device == mellanox_broken_intx_devs[i]) {
  3293. pdev->broken_intx_masking = 1;
  3294. return;
  3295. }
  3296. }
  3297. /*
  3298. * Getting here means Connect-IB cards and up. Connect-IB has no INTx
  3299. * support so shouldn't be checked further
  3300. */
  3301. if (pdev->device == PCI_DEVICE_ID_MELLANOX_CONNECTIB)
  3302. return;
  3303. if (pdev->device != PCI_DEVICE_ID_MELLANOX_CONNECTX4 &&
  3304. pdev->device != PCI_DEVICE_ID_MELLANOX_CONNECTX4_LX)
  3305. return;
  3306. /* For ConnectX-4 and ConnectX-4LX, need to check FW support */
  3307. if (pci_enable_device_mem(pdev)) {
  3308. pci_warn(pdev, "Can't enable device memory\n");
  3309. return;
  3310. }
  3311. fw_ver = ioremap(pci_resource_start(pdev, 0), 4);
  3312. if (!fw_ver) {
  3313. pci_warn(pdev, "Can't map ConnectX-4 initialization segment\n");
  3314. goto out;
  3315. }
  3316. /* Reading from resource space should be 32b aligned */
  3317. fw_maj_min = ioread32be(fw_ver);
  3318. fw_sub_min = ioread32be(fw_ver + 1);
  3319. fw_major = fw_maj_min & 0xffff;
  3320. fw_minor = fw_maj_min >> 16;
  3321. fw_subminor = fw_sub_min & 0xffff;
  3322. if (fw_minor > CONNECTX_4_CURR_MAX_MINOR ||
  3323. fw_minor < CONNECTX_4_INTX_SUPPORT_MINOR) {
  3324. pci_warn(pdev, "ConnectX-4: FW %u.%u.%u doesn't support INTx masking, disabling. Please upgrade FW to %d.14.1100 and up for INTx support\n",
  3325. fw_major, fw_minor, fw_subminor, pdev->device ==
  3326. PCI_DEVICE_ID_MELLANOX_CONNECTX4 ? 12 : 14);
  3327. pdev->broken_intx_masking = 1;
  3328. }
  3329. iounmap(fw_ver);
  3330. out:
  3331. pci_disable_device(pdev);
  3332. }
  3333. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_MELLANOX, PCI_ANY_ID,
  3334. mellanox_check_broken_intx_masking);
  3335. static void quirk_no_bus_reset(struct pci_dev *dev)
  3336. {
  3337. dev->dev_flags |= PCI_DEV_FLAGS_NO_BUS_RESET;
  3338. }
  3339. /*
  3340. * Some NVIDIA GPU devices do not work with bus reset, SBR needs to be
  3341. * prevented for those affected devices.
  3342. */
  3343. static void quirk_nvidia_no_bus_reset(struct pci_dev *dev)
  3344. {
  3345. if ((dev->device & 0xffc0) == 0x2340)
  3346. quirk_no_bus_reset(dev);
  3347. }
  3348. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
  3349. quirk_nvidia_no_bus_reset);
  3350. /*
  3351. * Some Atheros AR9xxx and QCA988x chips do not behave after a bus reset.
  3352. * The device will throw a Link Down error on AER-capable systems and
  3353. * regardless of AER, config space of the device is never accessible again
  3354. * and typically causes the system to hang or reset when access is attempted.
  3355. * https://lore.kernel.org/r/20140923210318.498dacbd@dualc.maya.org/
  3356. */
  3357. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATHEROS, 0x0030, quirk_no_bus_reset);
  3358. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATHEROS, 0x0032, quirk_no_bus_reset);
  3359. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATHEROS, 0x003c, quirk_no_bus_reset);
  3360. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATHEROS, 0x0033, quirk_no_bus_reset);
  3361. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATHEROS, 0x0034, quirk_no_bus_reset);
  3362. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ATHEROS, 0x003e, quirk_no_bus_reset);
  3363. /*
  3364. * Root port on some Cavium CN8xxx chips do not successfully complete a bus
  3365. * reset when used with certain child devices. After the reset, config
  3366. * accesses to the child may fail.
  3367. */
  3368. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_CAVIUM, 0xa100, quirk_no_bus_reset);
  3369. /*
  3370. * Some TI KeyStone C667X devices do not support bus/hot reset. The PCIESS
  3371. * automatically disables LTSSM when Secondary Bus Reset is received and
  3372. * the device stops working. Prevent bus reset for these devices. With
  3373. * this change, the device can be assigned to VMs with VFIO, but it will
  3374. * leak state between VMs. Reference
  3375. * https://e2e.ti.com/support/processors/f/791/t/954382
  3376. */
  3377. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TI, 0xb005, quirk_no_bus_reset);
  3378. static void quirk_no_pm_reset(struct pci_dev *dev)
  3379. {
  3380. /*
  3381. * We can't do a bus reset on root bus devices, but an ineffective
  3382. * PM reset may be better than nothing.
  3383. */
  3384. if (!pci_is_root_bus(dev->bus))
  3385. dev->dev_flags |= PCI_DEV_FLAGS_NO_PM_RESET;
  3386. }
  3387. /*
  3388. * Some AMD/ATI GPUS (HD8570 - Oland) report that a D3hot->D0 transition
  3389. * causes a reset (i.e., they advertise NoSoftRst-). This transition seems
  3390. * to have no effect on the device: it retains the framebuffer contents and
  3391. * monitor sync. Advertising this support makes other layers, like VFIO,
  3392. * assume pci_reset_function() is viable for this device. Mark it as
  3393. * unavailable to skip it when testing reset methods.
  3394. */
  3395. DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_VENDOR_ID_ATI, PCI_ANY_ID,
  3396. PCI_CLASS_DISPLAY_VGA, 8, quirk_no_pm_reset);
  3397. /*
  3398. * Spectrum-{1,2,3,4} devices report that a D3hot->D0 transition causes a reset
  3399. * (i.e., they advertise NoSoftRst-). However, this transition does not have
  3400. * any effect on the device: It continues to be operational and network ports
  3401. * remain up. Advertising this support makes it seem as if a PM reset is viable
  3402. * for these devices. Mark it as unavailable to skip it when testing reset
  3403. * methods.
  3404. */
  3405. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MELLANOX, 0xcb84, quirk_no_pm_reset);
  3406. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MELLANOX, 0xcf6c, quirk_no_pm_reset);
  3407. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MELLANOX, 0xcf70, quirk_no_pm_reset);
  3408. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MELLANOX, 0xcf80, quirk_no_pm_reset);
  3409. /*
  3410. * Thunderbolt controllers with broken MSI hotplug signaling:
  3411. * Entire 1st generation (Light Ridge, Eagle Ridge, Light Peak) and part
  3412. * of the 2nd generation (Cactus Ridge 4C up to revision 1, Port Ridge).
  3413. */
  3414. static void quirk_thunderbolt_hotplug_msi(struct pci_dev *pdev)
  3415. {
  3416. if (pdev->is_hotplug_bridge &&
  3417. (pdev->device != PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C ||
  3418. pdev->revision <= 1))
  3419. pdev->no_msi = 1;
  3420. }
  3421. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LIGHT_RIDGE,
  3422. quirk_thunderbolt_hotplug_msi);
  3423. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_EAGLE_RIDGE,
  3424. quirk_thunderbolt_hotplug_msi);
  3425. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_LIGHT_PEAK,
  3426. quirk_thunderbolt_hotplug_msi);
  3427. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C,
  3428. quirk_thunderbolt_hotplug_msi);
  3429. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_PORT_RIDGE,
  3430. quirk_thunderbolt_hotplug_msi);
  3431. #ifdef CONFIG_ACPI
  3432. /*
  3433. * Apple: Shutdown Cactus Ridge Thunderbolt controller.
  3434. *
  3435. * On Apple hardware the Cactus Ridge Thunderbolt controller needs to be
  3436. * shutdown before suspend. Otherwise the native host interface (NHI) will not
  3437. * be present after resume if a device was plugged in before suspend.
  3438. *
  3439. * The Thunderbolt controller consists of a PCIe switch with downstream
  3440. * bridges leading to the NHI and to the tunnel PCI bridges.
  3441. *
  3442. * This quirk cuts power to the whole chip. Therefore we have to apply it
  3443. * during suspend_noirq of the upstream bridge.
  3444. *
  3445. * Power is automagically restored before resume. No action is needed.
  3446. */
  3447. static void quirk_apple_poweroff_thunderbolt(struct pci_dev *dev)
  3448. {
  3449. acpi_handle bridge, SXIO, SXFP, SXLV;
  3450. if (!x86_apple_machine)
  3451. return;
  3452. if (pci_pcie_type(dev) != PCI_EXP_TYPE_UPSTREAM)
  3453. return;
  3454. /*
  3455. * SXIO/SXFP/SXLF turns off power to the Thunderbolt controller.
  3456. * We don't know how to turn it back on again, but firmware does,
  3457. * so we can only use SXIO/SXFP/SXLF if we're suspending via
  3458. * firmware.
  3459. */
  3460. if (!pm_suspend_via_firmware())
  3461. return;
  3462. bridge = ACPI_HANDLE(&dev->dev);
  3463. if (!bridge)
  3464. return;
  3465. /*
  3466. * SXIO and SXLV are present only on machines requiring this quirk.
  3467. * Thunderbolt bridges in external devices might have the same
  3468. * device ID as those on the host, but they will not have the
  3469. * associated ACPI methods. This implicitly checks that we are at
  3470. * the right bridge.
  3471. */
  3472. if (ACPI_FAILURE(acpi_get_handle(bridge, "DSB0.NHI0.SXIO", &SXIO))
  3473. || ACPI_FAILURE(acpi_get_handle(bridge, "DSB0.NHI0.SXFP", &SXFP))
  3474. || ACPI_FAILURE(acpi_get_handle(bridge, "DSB0.NHI0.SXLV", &SXLV)))
  3475. return;
  3476. pci_info(dev, "quirk: cutting power to Thunderbolt controller...\n");
  3477. /* magic sequence */
  3478. acpi_execute_simple_method(SXIO, NULL, 1);
  3479. acpi_execute_simple_method(SXFP, NULL, 0);
  3480. msleep(300);
  3481. acpi_execute_simple_method(SXLV, NULL, 0);
  3482. acpi_execute_simple_method(SXIO, NULL, 0);
  3483. acpi_execute_simple_method(SXLV, NULL, 0);
  3484. }
  3485. DECLARE_PCI_FIXUP_SUSPEND_LATE(PCI_VENDOR_ID_INTEL,
  3486. PCI_DEVICE_ID_INTEL_CACTUS_RIDGE_4C,
  3487. quirk_apple_poweroff_thunderbolt);
  3488. #endif
  3489. /*
  3490. * Following are device-specific reset methods which can be used to
  3491. * reset a single function if other methods (e.g. FLR, PM D0->D3) are
  3492. * not available.
  3493. */
  3494. static int reset_intel_82599_sfp_virtfn(struct pci_dev *dev, bool probe)
  3495. {
  3496. /*
  3497. * http://www.intel.com/content/dam/doc/datasheet/82599-10-gbe-controller-datasheet.pdf
  3498. *
  3499. * The 82599 supports FLR on VFs, but FLR support is reported only
  3500. * in the PF DEVCAP (sec 9.3.10.4), not in the VF DEVCAP (sec 9.5).
  3501. * Thus we must call pcie_flr() directly without first checking if it is
  3502. * supported.
  3503. */
  3504. if (!probe)
  3505. pcie_flr(dev);
  3506. return 0;
  3507. }
  3508. #define SOUTH_CHICKEN2 0xc2004
  3509. #define PCH_PP_STATUS 0xc7200
  3510. #define PCH_PP_CONTROL 0xc7204
  3511. #define MSG_CTL 0x45010
  3512. #define NSDE_PWR_STATE 0xd0100
  3513. #define IGD_OPERATION_TIMEOUT 10000 /* set timeout 10 seconds */
  3514. static int reset_ivb_igd(struct pci_dev *dev, bool probe)
  3515. {
  3516. void __iomem *mmio_base;
  3517. unsigned long timeout;
  3518. u32 val;
  3519. if (probe)
  3520. return 0;
  3521. mmio_base = pci_iomap(dev, 0, 0);
  3522. if (!mmio_base)
  3523. return -ENOMEM;
  3524. iowrite32(0x00000002, mmio_base + MSG_CTL);
  3525. /*
  3526. * Clobbering SOUTH_CHICKEN2 register is fine only if the next
  3527. * driver loaded sets the right bits. However, this's a reset and
  3528. * the bits have been set by i915 previously, so we clobber
  3529. * SOUTH_CHICKEN2 register directly here.
  3530. */
  3531. iowrite32(0x00000005, mmio_base + SOUTH_CHICKEN2);
  3532. val = ioread32(mmio_base + PCH_PP_CONTROL) & 0xfffffffe;
  3533. iowrite32(val, mmio_base + PCH_PP_CONTROL);
  3534. timeout = jiffies + msecs_to_jiffies(IGD_OPERATION_TIMEOUT);
  3535. do {
  3536. val = ioread32(mmio_base + PCH_PP_STATUS);
  3537. if ((val & 0xb0000000) == 0)
  3538. goto reset_complete;
  3539. msleep(10);
  3540. } while (time_before(jiffies, timeout));
  3541. pci_warn(dev, "timeout during reset\n");
  3542. reset_complete:
  3543. iowrite32(0x00000002, mmio_base + NSDE_PWR_STATE);
  3544. pci_iounmap(dev, mmio_base);
  3545. return 0;
  3546. }
  3547. /* Device-specific reset method for Chelsio T4-based adapters */
  3548. static int reset_chelsio_generic_dev(struct pci_dev *dev, bool probe)
  3549. {
  3550. u16 old_command;
  3551. u16 msix_flags;
  3552. /*
  3553. * If this isn't a Chelsio T4-based device, return -ENOTTY indicating
  3554. * that we have no device-specific reset method.
  3555. */
  3556. if ((dev->device & 0xf000) != 0x4000)
  3557. return -ENOTTY;
  3558. /*
  3559. * If this is the "probe" phase, return 0 indicating that we can
  3560. * reset this device.
  3561. */
  3562. if (probe)
  3563. return 0;
  3564. /*
  3565. * T4 can wedge if there are DMAs in flight within the chip and Bus
  3566. * Master has been disabled. We need to have it on till the Function
  3567. * Level Reset completes. (BUS_MASTER is disabled in
  3568. * pci_reset_function()).
  3569. */
  3570. pci_read_config_word(dev, PCI_COMMAND, &old_command);
  3571. pci_write_config_word(dev, PCI_COMMAND,
  3572. old_command | PCI_COMMAND_MASTER);
  3573. /*
  3574. * Perform the actual device function reset, saving and restoring
  3575. * configuration information around the reset.
  3576. */
  3577. pci_save_state(dev);
  3578. /*
  3579. * T4 also suffers a Head-Of-Line blocking problem if MSI-X interrupts
  3580. * are disabled when an MSI-X interrupt message needs to be delivered.
  3581. * So we briefly re-enable MSI-X interrupts for the duration of the
  3582. * FLR. The pci_restore_state() below will restore the original
  3583. * MSI-X state.
  3584. */
  3585. pci_read_config_word(dev, dev->msix_cap+PCI_MSIX_FLAGS, &msix_flags);
  3586. if ((msix_flags & PCI_MSIX_FLAGS_ENABLE) == 0)
  3587. pci_write_config_word(dev, dev->msix_cap+PCI_MSIX_FLAGS,
  3588. msix_flags |
  3589. PCI_MSIX_FLAGS_ENABLE |
  3590. PCI_MSIX_FLAGS_MASKALL);
  3591. pcie_flr(dev);
  3592. /*
  3593. * Restore the configuration information (BAR values, etc.) including
  3594. * the original PCI Configuration Space Command word, and return
  3595. * success.
  3596. */
  3597. pci_restore_state(dev);
  3598. pci_write_config_word(dev, PCI_COMMAND, old_command);
  3599. return 0;
  3600. }
  3601. #define PCI_DEVICE_ID_INTEL_82599_SFP_VF 0x10ed
  3602. #define PCI_DEVICE_ID_INTEL_IVB_M_VGA 0x0156
  3603. #define PCI_DEVICE_ID_INTEL_IVB_M2_VGA 0x0166
  3604. /*
  3605. * The Samsung SM961/PM961 controller can sometimes enter a fatal state after
  3606. * FLR where config space reads from the device return -1. We seem to be
  3607. * able to avoid this condition if we disable the NVMe controller prior to
  3608. * FLR. This quirk is generic for any NVMe class device requiring similar
  3609. * assistance to quiesce the device prior to FLR.
  3610. *
  3611. * NVMe specification: https://nvmexpress.org/resources/specifications/
  3612. * Revision 1.0e:
  3613. * Chapter 2: Required and optional PCI config registers
  3614. * Chapter 3: NVMe control registers
  3615. * Chapter 7.3: Reset behavior
  3616. */
  3617. static int nvme_disable_and_flr(struct pci_dev *dev, bool probe)
  3618. {
  3619. void __iomem *bar;
  3620. u16 cmd;
  3621. u32 cfg;
  3622. if (dev->class != PCI_CLASS_STORAGE_EXPRESS ||
  3623. pcie_reset_flr(dev, PCI_RESET_PROBE) || !pci_resource_start(dev, 0))
  3624. return -ENOTTY;
  3625. if (probe)
  3626. return 0;
  3627. bar = pci_iomap(dev, 0, NVME_REG_CC + sizeof(cfg));
  3628. if (!bar)
  3629. return -ENOTTY;
  3630. pci_read_config_word(dev, PCI_COMMAND, &cmd);
  3631. pci_write_config_word(dev, PCI_COMMAND, cmd | PCI_COMMAND_MEMORY);
  3632. cfg = readl(bar + NVME_REG_CC);
  3633. /* Disable controller if enabled */
  3634. if (cfg & NVME_CC_ENABLE) {
  3635. u32 cap = readl(bar + NVME_REG_CAP);
  3636. unsigned long timeout;
  3637. /*
  3638. * Per nvme_disable_ctrl() skip shutdown notification as it
  3639. * could complete commands to the admin queue. We only intend
  3640. * to quiesce the device before reset.
  3641. */
  3642. cfg &= ~(NVME_CC_SHN_MASK | NVME_CC_ENABLE);
  3643. writel(cfg, bar + NVME_REG_CC);
  3644. /*
  3645. * Some controllers require an additional delay here, see
  3646. * NVME_QUIRK_DELAY_BEFORE_CHK_RDY. None of those are yet
  3647. * supported by this quirk.
  3648. */
  3649. /* Cap register provides max timeout in 500ms increments */
  3650. timeout = ((NVME_CAP_TIMEOUT(cap) + 1) * HZ / 2) + jiffies;
  3651. for (;;) {
  3652. u32 status = readl(bar + NVME_REG_CSTS);
  3653. /* Ready status becomes zero on disable complete */
  3654. if (!(status & NVME_CSTS_RDY))
  3655. break;
  3656. msleep(100);
  3657. if (time_after(jiffies, timeout)) {
  3658. pci_warn(dev, "Timeout waiting for NVMe ready status to clear after disable\n");
  3659. break;
  3660. }
  3661. }
  3662. }
  3663. pci_iounmap(dev, bar);
  3664. pcie_flr(dev);
  3665. return 0;
  3666. }
  3667. /*
  3668. * Some NVMe controllers such as Intel DC P3700 and Solidigm P44 Pro will
  3669. * timeout waiting for ready status to change after NVMe enable if the driver
  3670. * starts interacting with the device too soon after FLR. A 250ms delay after
  3671. * FLR has heuristically proven to produce reliably working results for device
  3672. * assignment cases.
  3673. */
  3674. static int delay_250ms_after_flr(struct pci_dev *dev, bool probe)
  3675. {
  3676. if (probe)
  3677. return pcie_reset_flr(dev, PCI_RESET_PROBE);
  3678. pcie_reset_flr(dev, PCI_RESET_DO_RESET);
  3679. msleep(250);
  3680. return 0;
  3681. }
  3682. #define PCI_DEVICE_ID_HINIC_VF 0x375E
  3683. #define HINIC_VF_FLR_TYPE 0x1000
  3684. #define HINIC_VF_FLR_CAP_BIT (1UL << 30)
  3685. #define HINIC_VF_OP 0xE80
  3686. #define HINIC_VF_FLR_PROC_BIT (1UL << 18)
  3687. #define HINIC_OPERATION_TIMEOUT 15000 /* 15 seconds */
  3688. /* Device-specific reset method for Huawei Intelligent NIC virtual functions */
  3689. static int reset_hinic_vf_dev(struct pci_dev *pdev, bool probe)
  3690. {
  3691. unsigned long timeout;
  3692. void __iomem *bar;
  3693. u32 val;
  3694. if (probe)
  3695. return 0;
  3696. bar = pci_iomap(pdev, 0, 0);
  3697. if (!bar)
  3698. return -ENOTTY;
  3699. /* Get and check firmware capabilities */
  3700. val = ioread32be(bar + HINIC_VF_FLR_TYPE);
  3701. if (!(val & HINIC_VF_FLR_CAP_BIT)) {
  3702. pci_iounmap(pdev, bar);
  3703. return -ENOTTY;
  3704. }
  3705. /* Set HINIC_VF_FLR_PROC_BIT for the start of FLR */
  3706. val = ioread32be(bar + HINIC_VF_OP);
  3707. val = val | HINIC_VF_FLR_PROC_BIT;
  3708. iowrite32be(val, bar + HINIC_VF_OP);
  3709. pcie_flr(pdev);
  3710. /*
  3711. * The device must recapture its Bus and Device Numbers after FLR
  3712. * in order generate Completions. Issue a config write to let the
  3713. * device capture this information.
  3714. */
  3715. pci_write_config_word(pdev, PCI_VENDOR_ID, 0);
  3716. /* Firmware clears HINIC_VF_FLR_PROC_BIT when reset is complete */
  3717. timeout = jiffies + msecs_to_jiffies(HINIC_OPERATION_TIMEOUT);
  3718. do {
  3719. val = ioread32be(bar + HINIC_VF_OP);
  3720. if (!(val & HINIC_VF_FLR_PROC_BIT))
  3721. goto reset_complete;
  3722. msleep(20);
  3723. } while (time_before(jiffies, timeout));
  3724. val = ioread32be(bar + HINIC_VF_OP);
  3725. if (!(val & HINIC_VF_FLR_PROC_BIT))
  3726. goto reset_complete;
  3727. pci_warn(pdev, "Reset dev timeout, FLR ack reg: %#010x\n", val);
  3728. reset_complete:
  3729. pci_iounmap(pdev, bar);
  3730. return 0;
  3731. }
  3732. static const struct pci_dev_reset_methods pci_dev_reset_methods[] = {
  3733. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_82599_SFP_VF,
  3734. reset_intel_82599_sfp_virtfn },
  3735. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IVB_M_VGA,
  3736. reset_ivb_igd },
  3737. { PCI_VENDOR_ID_INTEL, PCI_DEVICE_ID_INTEL_IVB_M2_VGA,
  3738. reset_ivb_igd },
  3739. { PCI_VENDOR_ID_SAMSUNG, 0xa804, nvme_disable_and_flr },
  3740. { PCI_VENDOR_ID_INTEL, 0x0953, delay_250ms_after_flr },
  3741. { PCI_VENDOR_ID_INTEL, 0x0a54, delay_250ms_after_flr },
  3742. { PCI_VENDOR_ID_SOLIDIGM, 0xf1ac, delay_250ms_after_flr },
  3743. { PCI_VENDOR_ID_CHELSIO, PCI_ANY_ID,
  3744. reset_chelsio_generic_dev },
  3745. { PCI_VENDOR_ID_HUAWEI, PCI_DEVICE_ID_HINIC_VF,
  3746. reset_hinic_vf_dev },
  3747. { 0 }
  3748. };
  3749. /*
  3750. * These device-specific reset methods are here rather than in a driver
  3751. * because when a host assigns a device to a guest VM, the host may need
  3752. * to reset the device but probably doesn't have a driver for it.
  3753. */
  3754. int pci_dev_specific_reset(struct pci_dev *dev, bool probe)
  3755. {
  3756. const struct pci_dev_reset_methods *i;
  3757. for (i = pci_dev_reset_methods; i->reset; i++) {
  3758. if ((i->vendor == dev->vendor ||
  3759. i->vendor == (u16)PCI_ANY_ID) &&
  3760. (i->device == dev->device ||
  3761. i->device == (u16)PCI_ANY_ID))
  3762. return i->reset(dev, probe);
  3763. }
  3764. return -ENOTTY;
  3765. }
  3766. static void quirk_dma_func0_alias(struct pci_dev *dev)
  3767. {
  3768. if (PCI_FUNC(dev->devfn) != 0)
  3769. pci_add_dma_alias(dev, PCI_DEVFN(PCI_SLOT(dev->devfn), 0), 1);
  3770. }
  3771. /*
  3772. * https://bugzilla.redhat.com/show_bug.cgi?id=605888
  3773. *
  3774. * Some Ricoh devices use function 0 as the PCIe requester ID for DMA.
  3775. */
  3776. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_RICOH, 0xe832, quirk_dma_func0_alias);
  3777. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_RICOH, 0xe476, quirk_dma_func0_alias);
  3778. /* Some Glenfly chips use function 0 as the PCIe Requester ID for DMA */
  3779. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_GLENFLY, 0x3d40, quirk_dma_func0_alias);
  3780. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_GLENFLY, 0x3d41, quirk_dma_func0_alias);
  3781. static void quirk_dma_func1_alias(struct pci_dev *dev)
  3782. {
  3783. if (PCI_FUNC(dev->devfn) != 1)
  3784. pci_add_dma_alias(dev, PCI_DEVFN(PCI_SLOT(dev->devfn), 1), 1);
  3785. }
  3786. /*
  3787. * Marvell 88SE9123 uses function 1 as the requester ID for DMA. In some
  3788. * SKUs function 1 is present and is a legacy IDE controller, in other
  3789. * SKUs this function is not present, making this a ghost requester.
  3790. * https://bugzilla.kernel.org/show_bug.cgi?id=42679
  3791. */
  3792. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9120,
  3793. quirk_dma_func1_alias);
  3794. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9123,
  3795. quirk_dma_func1_alias);
  3796. /* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c136 */
  3797. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9125,
  3798. quirk_dma_func1_alias);
  3799. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9128,
  3800. quirk_dma_func1_alias);
  3801. /* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c14 */
  3802. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9130,
  3803. quirk_dma_func1_alias);
  3804. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9170,
  3805. quirk_dma_func1_alias);
  3806. /* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c47 + c57 */
  3807. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9172,
  3808. quirk_dma_func1_alias);
  3809. /* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c59 */
  3810. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x917a,
  3811. quirk_dma_func1_alias);
  3812. /* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c78 */
  3813. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9182,
  3814. quirk_dma_func1_alias);
  3815. /* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c134 */
  3816. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9183,
  3817. quirk_dma_func1_alias);
  3818. /* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c46 */
  3819. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x91a0,
  3820. quirk_dma_func1_alias);
  3821. /* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c135 */
  3822. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9215,
  3823. quirk_dma_func1_alias);
  3824. /* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c127 */
  3825. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9220,
  3826. quirk_dma_func1_alias);
  3827. /* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c49 */
  3828. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9230,
  3829. quirk_dma_func1_alias);
  3830. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_MARVELL_EXT, 0x9235,
  3831. quirk_dma_func1_alias);
  3832. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TTI, 0x0642,
  3833. quirk_dma_func1_alias);
  3834. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_TTI, 0x0645,
  3835. quirk_dma_func1_alias);
  3836. /* https://bugs.gentoo.org/show_bug.cgi?id=497630 */
  3837. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_JMICRON,
  3838. PCI_DEVICE_ID_JMICRON_JMB388_ESD,
  3839. quirk_dma_func1_alias);
  3840. /* https://bugzilla.kernel.org/show_bug.cgi?id=42679#c117 */
  3841. DECLARE_PCI_FIXUP_HEADER(0x1c28, /* Lite-On */
  3842. 0x0122, /* Plextor M6E (Marvell 88SS9183)*/
  3843. quirk_dma_func1_alias);
  3844. /*
  3845. * Some devices DMA with the wrong devfn, not just the wrong function.
  3846. * quirk_fixed_dma_alias() uses this table to create fixed aliases, where
  3847. * the alias is "fixed" and independent of the device devfn.
  3848. *
  3849. * For example, the Adaptec 3405 is a PCIe card with an Intel 80333 I/O
  3850. * processor. To software, this appears as a PCIe-to-PCI/X bridge with a
  3851. * single device on the secondary bus. In reality, the single exposed
  3852. * device at 0e.0 is the Address Translation Unit (ATU) of the controller
  3853. * that provides a bridge to the internal bus of the I/O processor. The
  3854. * controller supports private devices, which can be hidden from PCI config
  3855. * space. In the case of the Adaptec 3405, a private device at 01.0
  3856. * appears to be the DMA engine, which therefore needs to become a DMA
  3857. * alias for the device.
  3858. */
  3859. static const struct pci_device_id fixed_dma_alias_tbl[] = {
  3860. { PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x0285,
  3861. PCI_VENDOR_ID_ADAPTEC2, 0x02bb), /* Adaptec 3405 */
  3862. .driver_data = PCI_DEVFN(1, 0) },
  3863. { PCI_DEVICE_SUB(PCI_VENDOR_ID_ADAPTEC2, 0x0285,
  3864. PCI_VENDOR_ID_ADAPTEC2, 0x02bc), /* Adaptec 3805 */
  3865. .driver_data = PCI_DEVFN(1, 0) },
  3866. { 0 }
  3867. };
  3868. static void quirk_fixed_dma_alias(struct pci_dev *dev)
  3869. {
  3870. const struct pci_device_id *id;
  3871. id = pci_match_id(fixed_dma_alias_tbl, dev);
  3872. if (id)
  3873. pci_add_dma_alias(dev, id->driver_data, 1);
  3874. }
  3875. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ADAPTEC2, 0x0285, quirk_fixed_dma_alias);
  3876. /*
  3877. * A few PCIe-to-PCI bridges fail to expose a PCIe capability, resulting in
  3878. * using the wrong DMA alias for the device. Some of these devices can be
  3879. * used as either forward or reverse bridges, so we need to test whether the
  3880. * device is operating in the correct mode. We could probably apply this
  3881. * quirk to PCI_ANY_ID, but for now we'll just use known offenders. The test
  3882. * is for a non-root, non-PCIe bridge where the upstream device is PCIe and
  3883. * is not a PCIe-to-PCI bridge, then @pdev is actually a PCIe-to-PCI bridge.
  3884. */
  3885. static void quirk_use_pcie_bridge_dma_alias(struct pci_dev *pdev)
  3886. {
  3887. if (!pci_is_root_bus(pdev->bus) &&
  3888. pdev->hdr_type == PCI_HEADER_TYPE_BRIDGE &&
  3889. !pci_is_pcie(pdev) && pci_is_pcie(pdev->bus->self) &&
  3890. pci_pcie_type(pdev->bus->self) != PCI_EXP_TYPE_PCI_BRIDGE)
  3891. pdev->dev_flags |= PCI_DEV_FLAG_PCIE_BRIDGE_ALIAS;
  3892. }
  3893. /* ASM1083/1085, https://bugzilla.kernel.org/show_bug.cgi?id=44881#c46 */
  3894. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_ASMEDIA, 0x1080,
  3895. quirk_use_pcie_bridge_dma_alias);
  3896. /* Tundra 8113, https://bugzilla.kernel.org/show_bug.cgi?id=44881#c43 */
  3897. DECLARE_PCI_FIXUP_HEADER(0x10e3, 0x8113, quirk_use_pcie_bridge_dma_alias);
  3898. /* ITE 8892, https://bugzilla.kernel.org/show_bug.cgi?id=73551 */
  3899. DECLARE_PCI_FIXUP_HEADER(0x1283, 0x8892, quirk_use_pcie_bridge_dma_alias);
  3900. /* ITE 8893 has the same problem as the 8892 */
  3901. DECLARE_PCI_FIXUP_HEADER(0x1283, 0x8893, quirk_use_pcie_bridge_dma_alias);
  3902. /* Intel 82801, https://bugzilla.kernel.org/show_bug.cgi?id=44881#c49 */
  3903. DECLARE_PCI_FIXUP_HEADER(0x8086, 0x244e, quirk_use_pcie_bridge_dma_alias);
  3904. /*
  3905. * MIC x200 NTB forwards PCIe traffic using multiple alien RIDs. They have to
  3906. * be added as aliases to the DMA device in order to allow buffer access
  3907. * when IOMMU is enabled. Following devfns have to match RIT-LUT table
  3908. * programmed in the EEPROM.
  3909. */
  3910. static void quirk_mic_x200_dma_alias(struct pci_dev *pdev)
  3911. {
  3912. pci_add_dma_alias(pdev, PCI_DEVFN(0x10, 0x0), 1);
  3913. pci_add_dma_alias(pdev, PCI_DEVFN(0x11, 0x0), 1);
  3914. pci_add_dma_alias(pdev, PCI_DEVFN(0x12, 0x3), 1);
  3915. }
  3916. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2260, quirk_mic_x200_dma_alias);
  3917. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2264, quirk_mic_x200_dma_alias);
  3918. /*
  3919. * Intel Visual Compute Accelerator (VCA) is a family of PCIe add-in devices
  3920. * exposing computational units via Non Transparent Bridges (NTB, PEX 87xx).
  3921. *
  3922. * Similarly to MIC x200, we need to add DMA aliases to allow buffer access
  3923. * when IOMMU is enabled. These aliases allow computational unit access to
  3924. * host memory. These aliases mark the whole VCA device as one IOMMU
  3925. * group.
  3926. *
  3927. * All possible slot numbers (0x20) are used, since we are unable to tell
  3928. * what slot is used on other side. This quirk is intended for both host
  3929. * and computational unit sides. The VCA devices have up to five functions
  3930. * (four for DMA channels and one additional).
  3931. */
  3932. static void quirk_pex_vca_alias(struct pci_dev *pdev)
  3933. {
  3934. const unsigned int num_pci_slots = 0x20;
  3935. unsigned int slot;
  3936. for (slot = 0; slot < num_pci_slots; slot++)
  3937. pci_add_dma_alias(pdev, PCI_DEVFN(slot, 0x0), 5);
  3938. }
  3939. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2954, quirk_pex_vca_alias);
  3940. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2955, quirk_pex_vca_alias);
  3941. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2956, quirk_pex_vca_alias);
  3942. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2958, quirk_pex_vca_alias);
  3943. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x2959, quirk_pex_vca_alias);
  3944. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x295A, quirk_pex_vca_alias);
  3945. /*
  3946. * The IOMMU and interrupt controller on Broadcom Vulcan/Cavium ThunderX2 are
  3947. * associated not at the root bus, but at a bridge below. This quirk avoids
  3948. * generating invalid DMA aliases.
  3949. */
  3950. static void quirk_bridge_cavm_thrx2_pcie_root(struct pci_dev *pdev)
  3951. {
  3952. pdev->dev_flags |= PCI_DEV_FLAGS_BRIDGE_XLATE_ROOT;
  3953. }
  3954. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM, 0x9000,
  3955. quirk_bridge_cavm_thrx2_pcie_root);
  3956. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_BROADCOM, 0x9084,
  3957. quirk_bridge_cavm_thrx2_pcie_root);
  3958. /*
  3959. * Intersil/Techwell TW686[4589]-based video capture cards have an empty (zero)
  3960. * class code. Fix it.
  3961. */
  3962. static void quirk_tw686x_class(struct pci_dev *pdev)
  3963. {
  3964. u32 class = pdev->class;
  3965. /* Use "Multimedia controller" class */
  3966. pdev->class = (PCI_CLASS_MULTIMEDIA_OTHER << 8) | 0x01;
  3967. pci_info(pdev, "TW686x PCI class overridden (%#08x -> %#08x)\n",
  3968. class, pdev->class);
  3969. }
  3970. DECLARE_PCI_FIXUP_CLASS_EARLY(0x1797, 0x6864, PCI_CLASS_NOT_DEFINED, 8,
  3971. quirk_tw686x_class);
  3972. DECLARE_PCI_FIXUP_CLASS_EARLY(0x1797, 0x6865, PCI_CLASS_NOT_DEFINED, 8,
  3973. quirk_tw686x_class);
  3974. DECLARE_PCI_FIXUP_CLASS_EARLY(0x1797, 0x6868, PCI_CLASS_NOT_DEFINED, 8,
  3975. quirk_tw686x_class);
  3976. DECLARE_PCI_FIXUP_CLASS_EARLY(0x1797, 0x6869, PCI_CLASS_NOT_DEFINED, 8,
  3977. quirk_tw686x_class);
  3978. /*
  3979. * Some devices have problems with Transaction Layer Packets with the Relaxed
  3980. * Ordering Attribute set. Such devices should mark themselves and other
  3981. * device drivers should check before sending TLPs with RO set.
  3982. */
  3983. static void quirk_relaxedordering_disable(struct pci_dev *dev)
  3984. {
  3985. dev->dev_flags |= PCI_DEV_FLAGS_NO_RELAXED_ORDERING;
  3986. pci_info(dev, "Disable Relaxed Ordering Attributes to avoid PCIe Completion erratum\n");
  3987. }
  3988. /*
  3989. * Intel Xeon processors based on Broadwell/Haswell microarchitecture Root
  3990. * Complex have a Flow Control Credit issue which can cause performance
  3991. * problems with Upstream Transaction Layer Packets with Relaxed Ordering set.
  3992. */
  3993. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f01, PCI_CLASS_NOT_DEFINED, 8,
  3994. quirk_relaxedordering_disable);
  3995. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f02, PCI_CLASS_NOT_DEFINED, 8,
  3996. quirk_relaxedordering_disable);
  3997. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f03, PCI_CLASS_NOT_DEFINED, 8,
  3998. quirk_relaxedordering_disable);
  3999. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f04, PCI_CLASS_NOT_DEFINED, 8,
  4000. quirk_relaxedordering_disable);
  4001. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f05, PCI_CLASS_NOT_DEFINED, 8,
  4002. quirk_relaxedordering_disable);
  4003. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f06, PCI_CLASS_NOT_DEFINED, 8,
  4004. quirk_relaxedordering_disable);
  4005. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f07, PCI_CLASS_NOT_DEFINED, 8,
  4006. quirk_relaxedordering_disable);
  4007. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f08, PCI_CLASS_NOT_DEFINED, 8,
  4008. quirk_relaxedordering_disable);
  4009. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f09, PCI_CLASS_NOT_DEFINED, 8,
  4010. quirk_relaxedordering_disable);
  4011. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f0a, PCI_CLASS_NOT_DEFINED, 8,
  4012. quirk_relaxedordering_disable);
  4013. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f0b, PCI_CLASS_NOT_DEFINED, 8,
  4014. quirk_relaxedordering_disable);
  4015. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f0c, PCI_CLASS_NOT_DEFINED, 8,
  4016. quirk_relaxedordering_disable);
  4017. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f0d, PCI_CLASS_NOT_DEFINED, 8,
  4018. quirk_relaxedordering_disable);
  4019. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x6f0e, PCI_CLASS_NOT_DEFINED, 8,
  4020. quirk_relaxedordering_disable);
  4021. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f01, PCI_CLASS_NOT_DEFINED, 8,
  4022. quirk_relaxedordering_disable);
  4023. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f02, PCI_CLASS_NOT_DEFINED, 8,
  4024. quirk_relaxedordering_disable);
  4025. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f03, PCI_CLASS_NOT_DEFINED, 8,
  4026. quirk_relaxedordering_disable);
  4027. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f04, PCI_CLASS_NOT_DEFINED, 8,
  4028. quirk_relaxedordering_disable);
  4029. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f05, PCI_CLASS_NOT_DEFINED, 8,
  4030. quirk_relaxedordering_disable);
  4031. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f06, PCI_CLASS_NOT_DEFINED, 8,
  4032. quirk_relaxedordering_disable);
  4033. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f07, PCI_CLASS_NOT_DEFINED, 8,
  4034. quirk_relaxedordering_disable);
  4035. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f08, PCI_CLASS_NOT_DEFINED, 8,
  4036. quirk_relaxedordering_disable);
  4037. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f09, PCI_CLASS_NOT_DEFINED, 8,
  4038. quirk_relaxedordering_disable);
  4039. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f0a, PCI_CLASS_NOT_DEFINED, 8,
  4040. quirk_relaxedordering_disable);
  4041. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f0b, PCI_CLASS_NOT_DEFINED, 8,
  4042. quirk_relaxedordering_disable);
  4043. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f0c, PCI_CLASS_NOT_DEFINED, 8,
  4044. quirk_relaxedordering_disable);
  4045. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f0d, PCI_CLASS_NOT_DEFINED, 8,
  4046. quirk_relaxedordering_disable);
  4047. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_INTEL, 0x2f0e, PCI_CLASS_NOT_DEFINED, 8,
  4048. quirk_relaxedordering_disable);
  4049. /*
  4050. * The AMD ARM A1100 (aka "SEATTLE") SoC has a bug in its PCIe Root Complex
  4051. * where Upstream Transaction Layer Packets with the Relaxed Ordering
  4052. * Attribute clear are allowed to bypass earlier TLPs with Relaxed Ordering
  4053. * set. This is a violation of the PCIe 3.0 Transaction Ordering Rules
  4054. * outlined in Section 2.4.1 (PCI Express(r) Base Specification Revision 3.0
  4055. * November 10, 2010). As a result, on this platform we can't use Relaxed
  4056. * Ordering for Upstream TLPs.
  4057. */
  4058. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_AMD, 0x1a00, PCI_CLASS_NOT_DEFINED, 8,
  4059. quirk_relaxedordering_disable);
  4060. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_AMD, 0x1a01, PCI_CLASS_NOT_DEFINED, 8,
  4061. quirk_relaxedordering_disable);
  4062. DECLARE_PCI_FIXUP_CLASS_EARLY(PCI_VENDOR_ID_AMD, 0x1a02, PCI_CLASS_NOT_DEFINED, 8,
  4063. quirk_relaxedordering_disable);
  4064. /*
  4065. * Per PCIe r3.0, sec 2.2.9, "Completion headers must supply the same
  4066. * values for the Attribute as were supplied in the header of the
  4067. * corresponding Request, except as explicitly allowed when IDO is used."
  4068. *
  4069. * If a non-compliant device generates a completion with a different
  4070. * attribute than the request, the receiver may accept it (which itself
  4071. * seems non-compliant based on sec 2.3.2), or it may handle it as a
  4072. * Malformed TLP or an Unexpected Completion, which will probably lead to a
  4073. * device access timeout.
  4074. *
  4075. * If the non-compliant device generates completions with zero attributes
  4076. * (instead of copying the attributes from the request), we can work around
  4077. * this by disabling the "Relaxed Ordering" and "No Snoop" attributes in
  4078. * upstream devices so they always generate requests with zero attributes.
  4079. *
  4080. * This affects other devices under the same Root Port, but since these
  4081. * attributes are performance hints, there should be no functional problem.
  4082. *
  4083. * Note that Configuration Space accesses are never supposed to have TLP
  4084. * Attributes, so we're safe waiting till after any Configuration Space
  4085. * accesses to do the Root Port fixup.
  4086. */
  4087. static void quirk_disable_root_port_attributes(struct pci_dev *pdev)
  4088. {
  4089. struct pci_dev *root_port = pcie_find_root_port(pdev);
  4090. if (!root_port) {
  4091. pci_warn(pdev, "PCIe Completion erratum may cause device errors\n");
  4092. return;
  4093. }
  4094. pci_info(root_port, "Disabling No Snoop/Relaxed Ordering Attributes to avoid PCIe Completion erratum in %s\n",
  4095. dev_name(&pdev->dev));
  4096. pcie_capability_clear_word(root_port, PCI_EXP_DEVCTL,
  4097. PCI_EXP_DEVCTL_RELAX_EN |
  4098. PCI_EXP_DEVCTL_NOSNOOP_EN);
  4099. }
  4100. /*
  4101. * The Chelsio T5 chip fails to copy TLP Attributes from a Request to the
  4102. * Completion it generates.
  4103. */
  4104. static void quirk_chelsio_T5_disable_root_port_attributes(struct pci_dev *pdev)
  4105. {
  4106. /*
  4107. * This mask/compare operation selects for Physical Function 4 on a
  4108. * T5. We only need to fix up the Root Port once for any of the
  4109. * PFs. PF[0..3] have PCI Device IDs of 0x50xx, but PF4 is uniquely
  4110. * 0x54xx so we use that one.
  4111. */
  4112. if ((pdev->device & 0xff00) == 0x5400)
  4113. quirk_disable_root_port_attributes(pdev);
  4114. }
  4115. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_CHELSIO, PCI_ANY_ID,
  4116. quirk_chelsio_T5_disable_root_port_attributes);
  4117. /*
  4118. * pci_acs_ctrl_enabled - compare desired ACS controls with those provided
  4119. * by a device
  4120. * @acs_ctrl_req: Bitmask of desired ACS controls
  4121. * @acs_ctrl_ena: Bitmask of ACS controls enabled or provided implicitly by
  4122. * the hardware design
  4123. *
  4124. * Return 1 if all ACS controls in the @acs_ctrl_req bitmask are included
  4125. * in @acs_ctrl_ena, i.e., the device provides all the access controls the
  4126. * caller desires. Return 0 otherwise.
  4127. */
  4128. static int pci_acs_ctrl_enabled(u16 acs_ctrl_req, u16 acs_ctrl_ena)
  4129. {
  4130. if ((acs_ctrl_req & acs_ctrl_ena) == acs_ctrl_req)
  4131. return 1;
  4132. return 0;
  4133. }
  4134. /*
  4135. * AMD has indicated that the devices below do not support peer-to-peer
  4136. * in any system where they are found in the southbridge with an AMD
  4137. * IOMMU in the system. Multifunction devices that do not support
  4138. * peer-to-peer between functions can claim to support a subset of ACS.
  4139. * Such devices effectively enable request redirect (RR) and completion
  4140. * redirect (CR) since all transactions are redirected to the upstream
  4141. * root complex.
  4142. *
  4143. * https://lore.kernel.org/r/201207111426.q6BEQTbh002928@mail.maya.org/
  4144. * https://lore.kernel.org/r/20120711165854.GM25282@amd.com/
  4145. * https://lore.kernel.org/r/20121005130857.GX4009@amd.com/
  4146. *
  4147. * 1002:4385 SBx00 SMBus Controller
  4148. * 1002:439c SB7x0/SB8x0/SB9x0 IDE Controller
  4149. * 1002:4383 SBx00 Azalia (Intel HDA)
  4150. * 1002:439d SB7x0/SB8x0/SB9x0 LPC host controller
  4151. * 1002:4384 SBx00 PCI to PCI Bridge
  4152. * 1002:4399 SB7x0/SB8x0/SB9x0 USB OHCI2 Controller
  4153. *
  4154. * https://bugzilla.kernel.org/show_bug.cgi?id=81841#c15
  4155. *
  4156. * 1022:780f [AMD] FCH PCI Bridge
  4157. * 1022:7809 [AMD] FCH USB OHCI Controller
  4158. */
  4159. static int pci_quirk_amd_sb_acs(struct pci_dev *dev, u16 acs_flags)
  4160. {
  4161. #ifdef CONFIG_ACPI
  4162. struct acpi_table_header *header = NULL;
  4163. acpi_status status;
  4164. /* Targeting multifunction devices on the SB (appears on root bus) */
  4165. if (!dev->multifunction || !pci_is_root_bus(dev->bus))
  4166. return -ENODEV;
  4167. /* The IVRS table describes the AMD IOMMU */
  4168. status = acpi_get_table("IVRS", 0, &header);
  4169. if (ACPI_FAILURE(status))
  4170. return -ENODEV;
  4171. acpi_put_table(header);
  4172. /* Filter out flags not applicable to multifunction */
  4173. acs_flags &= (PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_EC | PCI_ACS_DT);
  4174. return pci_acs_ctrl_enabled(acs_flags, PCI_ACS_RR | PCI_ACS_CR);
  4175. #else
  4176. return -ENODEV;
  4177. #endif
  4178. }
  4179. static bool pci_quirk_cavium_acs_match(struct pci_dev *dev)
  4180. {
  4181. if (!pci_is_pcie(dev) || pci_pcie_type(dev) != PCI_EXP_TYPE_ROOT_PORT)
  4182. return false;
  4183. switch (dev->device) {
  4184. /*
  4185. * Effectively selects all downstream ports for whole ThunderX1
  4186. * (which represents 8 SoCs).
  4187. */
  4188. case 0xa000 ... 0xa7ff: /* ThunderX1 */
  4189. case 0xaf84: /* ThunderX2 */
  4190. case 0xb884: /* ThunderX3 */
  4191. return true;
  4192. default:
  4193. return false;
  4194. }
  4195. }
  4196. static int pci_quirk_cavium_acs(struct pci_dev *dev, u16 acs_flags)
  4197. {
  4198. if (!pci_quirk_cavium_acs_match(dev))
  4199. return -ENOTTY;
  4200. /*
  4201. * Cavium Root Ports don't advertise an ACS capability. However,
  4202. * the RTL internally implements similar protection as if ACS had
  4203. * Source Validation, Request Redirection, Completion Redirection,
  4204. * and Upstream Forwarding features enabled. Assert that the
  4205. * hardware implements and enables equivalent ACS functionality for
  4206. * these flags.
  4207. */
  4208. return pci_acs_ctrl_enabled(acs_flags,
  4209. PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF);
  4210. }
  4211. static int pci_quirk_xgene_acs(struct pci_dev *dev, u16 acs_flags)
  4212. {
  4213. /*
  4214. * X-Gene Root Ports matching this quirk do not allow peer-to-peer
  4215. * transactions with others, allowing masking out these bits as if they
  4216. * were unimplemented in the ACS capability.
  4217. */
  4218. return pci_acs_ctrl_enabled(acs_flags,
  4219. PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF);
  4220. }
  4221. /*
  4222. * Many Zhaoxin Root Ports and Switch Downstream Ports have no ACS capability.
  4223. * But the implementation could block peer-to-peer transactions between them
  4224. * and provide ACS-like functionality.
  4225. */
  4226. static int pci_quirk_zhaoxin_pcie_ports_acs(struct pci_dev *dev, u16 acs_flags)
  4227. {
  4228. if (!pci_is_pcie(dev) ||
  4229. ((pci_pcie_type(dev) != PCI_EXP_TYPE_ROOT_PORT) &&
  4230. (pci_pcie_type(dev) != PCI_EXP_TYPE_DOWNSTREAM)))
  4231. return -ENOTTY;
  4232. /*
  4233. * Future Zhaoxin Root Ports and Switch Downstream Ports will
  4234. * implement ACS capability in accordance with the PCIe Spec.
  4235. */
  4236. switch (dev->device) {
  4237. case 0x0710 ... 0x071e:
  4238. case 0x0721:
  4239. case 0x0723 ... 0x0752:
  4240. return pci_acs_ctrl_enabled(acs_flags,
  4241. PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF);
  4242. }
  4243. return false;
  4244. }
  4245. /*
  4246. * Many Intel PCH Root Ports do provide ACS-like features to disable peer
  4247. * transactions and validate bus numbers in requests, but do not provide an
  4248. * actual PCIe ACS capability. This is the list of device IDs known to fall
  4249. * into that category as provided by Intel in Red Hat bugzilla 1037684.
  4250. */
  4251. static const u16 pci_quirk_intel_pch_acs_ids[] = {
  4252. /* Ibexpeak PCH */
  4253. 0x3b42, 0x3b43, 0x3b44, 0x3b45, 0x3b46, 0x3b47, 0x3b48, 0x3b49,
  4254. 0x3b4a, 0x3b4b, 0x3b4c, 0x3b4d, 0x3b4e, 0x3b4f, 0x3b50, 0x3b51,
  4255. /* Cougarpoint PCH */
  4256. 0x1c10, 0x1c11, 0x1c12, 0x1c13, 0x1c14, 0x1c15, 0x1c16, 0x1c17,
  4257. 0x1c18, 0x1c19, 0x1c1a, 0x1c1b, 0x1c1c, 0x1c1d, 0x1c1e, 0x1c1f,
  4258. /* Pantherpoint PCH */
  4259. 0x1e10, 0x1e11, 0x1e12, 0x1e13, 0x1e14, 0x1e15, 0x1e16, 0x1e17,
  4260. 0x1e18, 0x1e19, 0x1e1a, 0x1e1b, 0x1e1c, 0x1e1d, 0x1e1e, 0x1e1f,
  4261. /* Lynxpoint-H PCH */
  4262. 0x8c10, 0x8c11, 0x8c12, 0x8c13, 0x8c14, 0x8c15, 0x8c16, 0x8c17,
  4263. 0x8c18, 0x8c19, 0x8c1a, 0x8c1b, 0x8c1c, 0x8c1d, 0x8c1e, 0x8c1f,
  4264. /* Lynxpoint-LP PCH */
  4265. 0x9c10, 0x9c11, 0x9c12, 0x9c13, 0x9c14, 0x9c15, 0x9c16, 0x9c17,
  4266. 0x9c18, 0x9c19, 0x9c1a, 0x9c1b,
  4267. /* Wildcat PCH */
  4268. 0x9c90, 0x9c91, 0x9c92, 0x9c93, 0x9c94, 0x9c95, 0x9c96, 0x9c97,
  4269. 0x9c98, 0x9c99, 0x9c9a, 0x9c9b,
  4270. /* Patsburg (X79) PCH */
  4271. 0x1d10, 0x1d12, 0x1d14, 0x1d16, 0x1d18, 0x1d1a, 0x1d1c, 0x1d1e,
  4272. /* Wellsburg (X99) PCH */
  4273. 0x8d10, 0x8d11, 0x8d12, 0x8d13, 0x8d14, 0x8d15, 0x8d16, 0x8d17,
  4274. 0x8d18, 0x8d19, 0x8d1a, 0x8d1b, 0x8d1c, 0x8d1d, 0x8d1e,
  4275. /* Lynx Point (9 series) PCH */
  4276. 0x8c90, 0x8c92, 0x8c94, 0x8c96, 0x8c98, 0x8c9a, 0x8c9c, 0x8c9e,
  4277. };
  4278. static bool pci_quirk_intel_pch_acs_match(struct pci_dev *dev)
  4279. {
  4280. int i;
  4281. /* Filter out a few obvious non-matches first */
  4282. if (!pci_is_pcie(dev) || pci_pcie_type(dev) != PCI_EXP_TYPE_ROOT_PORT)
  4283. return false;
  4284. for (i = 0; i < ARRAY_SIZE(pci_quirk_intel_pch_acs_ids); i++)
  4285. if (pci_quirk_intel_pch_acs_ids[i] == dev->device)
  4286. return true;
  4287. return false;
  4288. }
  4289. static int pci_quirk_intel_pch_acs(struct pci_dev *dev, u16 acs_flags)
  4290. {
  4291. if (!pci_quirk_intel_pch_acs_match(dev))
  4292. return -ENOTTY;
  4293. if (dev->dev_flags & PCI_DEV_FLAGS_ACS_ENABLED_QUIRK)
  4294. return pci_acs_ctrl_enabled(acs_flags,
  4295. PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF);
  4296. return pci_acs_ctrl_enabled(acs_flags, 0);
  4297. }
  4298. /*
  4299. * These QCOM Root Ports do provide ACS-like features to disable peer
  4300. * transactions and validate bus numbers in requests, but do not provide an
  4301. * actual PCIe ACS capability. Hardware supports source validation but it
  4302. * will report the issue as Completer Abort instead of ACS Violation.
  4303. * Hardware doesn't support peer-to-peer and each Root Port is a Root
  4304. * Complex with unique segment numbers. It is not possible for one Root
  4305. * Port to pass traffic to another Root Port. All PCIe transactions are
  4306. * terminated inside the Root Port.
  4307. */
  4308. static int pci_quirk_qcom_rp_acs(struct pci_dev *dev, u16 acs_flags)
  4309. {
  4310. return pci_acs_ctrl_enabled(acs_flags,
  4311. PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF);
  4312. }
  4313. /*
  4314. * Each of these NXP Root Ports is in a Root Complex with a unique segment
  4315. * number and does provide isolation features to disable peer transactions
  4316. * and validate bus numbers in requests, but does not provide an ACS
  4317. * capability.
  4318. */
  4319. static int pci_quirk_nxp_rp_acs(struct pci_dev *dev, u16 acs_flags)
  4320. {
  4321. return pci_acs_ctrl_enabled(acs_flags,
  4322. PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF);
  4323. }
  4324. static int pci_quirk_al_acs(struct pci_dev *dev, u16 acs_flags)
  4325. {
  4326. if (pci_pcie_type(dev) != PCI_EXP_TYPE_ROOT_PORT)
  4327. return -ENOTTY;
  4328. /*
  4329. * Amazon's Annapurna Labs root ports don't include an ACS capability,
  4330. * but do include ACS-like functionality. The hardware doesn't support
  4331. * peer-to-peer transactions via the root port and each has a unique
  4332. * segment number.
  4333. *
  4334. * Additionally, the root ports cannot send traffic to each other.
  4335. */
  4336. acs_flags &= ~(PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF);
  4337. return acs_flags ? 0 : 1;
  4338. }
  4339. /*
  4340. * Sunrise Point PCH root ports implement ACS, but unfortunately as shown in
  4341. * the datasheet (Intel 100 Series Chipset Family PCH Datasheet, Vol. 2,
  4342. * 12.1.46, 12.1.47)[1] this chipset uses dwords for the ACS capability and
  4343. * control registers whereas the PCIe spec packs them into words (Rev 3.0,
  4344. * 7.16 ACS Extended Capability). The bit definitions are correct, but the
  4345. * control register is at offset 8 instead of 6 and we should probably use
  4346. * dword accesses to them. This applies to the following PCI Device IDs, as
  4347. * found in volume 1 of the datasheet[2]:
  4348. *
  4349. * 0xa110-0xa11f Sunrise Point-H PCI Express Root Port #{0-16}
  4350. * 0xa167-0xa16a Sunrise Point-H PCI Express Root Port #{17-20}
  4351. *
  4352. * N.B. This doesn't fix what lspci shows.
  4353. *
  4354. * The 100 series chipset specification update includes this as errata #23[3].
  4355. *
  4356. * The 200 series chipset (Union Point) has the same bug according to the
  4357. * specification update (Intel 200 Series Chipset Family Platform Controller
  4358. * Hub, Specification Update, January 2017, Revision 001, Document# 335194-001,
  4359. * Errata 22)[4]. Per the datasheet[5], root port PCI Device IDs for this
  4360. * chipset include:
  4361. *
  4362. * 0xa290-0xa29f PCI Express Root port #{0-16}
  4363. * 0xa2e7-0xa2ee PCI Express Root port #{17-24}
  4364. *
  4365. * Mobile chipsets are also affected, 7th & 8th Generation
  4366. * Specification update confirms ACS errata 22, status no fix: (7th Generation
  4367. * Intel Processor Family I/O for U/Y Platforms and 8th Generation Intel
  4368. * Processor Family I/O for U Quad Core Platforms Specification Update,
  4369. * August 2017, Revision 002, Document#: 334660-002)[6]
  4370. * Device IDs from I/O datasheet: (7th Generation Intel Processor Family I/O
  4371. * for U/Y Platforms and 8th Generation Intel ® Processor Family I/O for U
  4372. * Quad Core Platforms, Vol 1 of 2, August 2017, Document#: 334658-003)[7]
  4373. *
  4374. * 0x9d10-0x9d1b PCI Express Root port #{1-12}
  4375. *
  4376. * [1] https://www.intel.com/content/www/us/en/chipsets/100-series-chipset-datasheet-vol-2.html
  4377. * [2] https://www.intel.com/content/www/us/en/chipsets/100-series-chipset-datasheet-vol-1.html
  4378. * [3] https://www.intel.com/content/www/us/en/chipsets/100-series-chipset-spec-update.html
  4379. * [4] https://www.intel.com/content/www/us/en/chipsets/200-series-chipset-pch-spec-update.html
  4380. * [5] https://www.intel.com/content/www/us/en/chipsets/200-series-chipset-pch-datasheet-vol-1.html
  4381. * [6] https://www.intel.com/content/www/us/en/processors/core/7th-gen-core-family-mobile-u-y-processor-lines-i-o-spec-update.html
  4382. * [7] https://www.intel.com/content/www/us/en/processors/core/7th-gen-core-family-mobile-u-y-processor-lines-i-o-datasheet-vol-1.html
  4383. */
  4384. static bool pci_quirk_intel_spt_pch_acs_match(struct pci_dev *dev)
  4385. {
  4386. if (!pci_is_pcie(dev) || pci_pcie_type(dev) != PCI_EXP_TYPE_ROOT_PORT)
  4387. return false;
  4388. switch (dev->device) {
  4389. case 0xa110 ... 0xa11f: case 0xa167 ... 0xa16a: /* Sunrise Point */
  4390. case 0xa290 ... 0xa29f: case 0xa2e7 ... 0xa2ee: /* Union Point */
  4391. case 0x9d10 ... 0x9d1b: /* 7th & 8th Gen Mobile */
  4392. return true;
  4393. }
  4394. return false;
  4395. }
  4396. #define INTEL_SPT_ACS_CTRL (PCI_ACS_CAP + 4)
  4397. static int pci_quirk_intel_spt_pch_acs(struct pci_dev *dev, u16 acs_flags)
  4398. {
  4399. int pos;
  4400. u32 cap, ctrl;
  4401. if (!pci_quirk_intel_spt_pch_acs_match(dev))
  4402. return -ENOTTY;
  4403. pos = dev->acs_cap;
  4404. if (!pos)
  4405. return -ENOTTY;
  4406. /* see pci_acs_flags_enabled() */
  4407. pci_read_config_dword(dev, pos + PCI_ACS_CAP, &cap);
  4408. acs_flags &= (cap | PCI_ACS_EC);
  4409. pci_read_config_dword(dev, pos + INTEL_SPT_ACS_CTRL, &ctrl);
  4410. return pci_acs_ctrl_enabled(acs_flags, ctrl);
  4411. }
  4412. static int pci_quirk_mf_endpoint_acs(struct pci_dev *dev, u16 acs_flags)
  4413. {
  4414. /*
  4415. * SV, TB, and UF are not relevant to multifunction endpoints.
  4416. *
  4417. * Multifunction devices are only required to implement RR, CR, and DT
  4418. * in their ACS capability if they support peer-to-peer transactions.
  4419. * Devices matching this quirk have been verified by the vendor to not
  4420. * perform peer-to-peer with other functions, allowing us to mask out
  4421. * these bits as if they were unimplemented in the ACS capability.
  4422. */
  4423. return pci_acs_ctrl_enabled(acs_flags,
  4424. PCI_ACS_SV | PCI_ACS_TB | PCI_ACS_RR |
  4425. PCI_ACS_CR | PCI_ACS_UF | PCI_ACS_DT);
  4426. }
  4427. static int pci_quirk_rciep_acs(struct pci_dev *dev, u16 acs_flags)
  4428. {
  4429. /*
  4430. * Intel RCiEP's are required to allow p2p only on translated
  4431. * addresses. Refer to Intel VT-d specification, r3.1, sec 3.16,
  4432. * "Root-Complex Peer to Peer Considerations".
  4433. */
  4434. if (pci_pcie_type(dev) != PCI_EXP_TYPE_RC_END)
  4435. return -ENOTTY;
  4436. return pci_acs_ctrl_enabled(acs_flags,
  4437. PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF);
  4438. }
  4439. static int pci_quirk_brcm_acs(struct pci_dev *dev, u16 acs_flags)
  4440. {
  4441. /*
  4442. * iProc PAXB Root Ports don't advertise an ACS capability, but
  4443. * they do not allow peer-to-peer transactions between Root Ports.
  4444. * Allow each Root Port to be in a separate IOMMU group by masking
  4445. * SV/RR/CR/UF bits.
  4446. */
  4447. return pci_acs_ctrl_enabled(acs_flags,
  4448. PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF);
  4449. }
  4450. /*
  4451. * Wangxun 40G/25G/10G/1G NICs have no ACS capability, but on
  4452. * multi-function devices, the hardware isolates the functions by
  4453. * directing all peer-to-peer traffic upstream as though PCI_ACS_RR and
  4454. * PCI_ACS_CR were set.
  4455. * SFxxx 1G NICs(em).
  4456. * RP1000/RP2000 10G NICs(sp).
  4457. * FF5xxx 40G/25G/10G NICs(aml).
  4458. */
  4459. static int pci_quirk_wangxun_nic_acs(struct pci_dev *dev, u16 acs_flags)
  4460. {
  4461. switch (dev->device) {
  4462. case 0x0100 ... 0x010F: /* EM */
  4463. case 0x1001: case 0x2001: /* SP */
  4464. case 0x5010: case 0x5025: case 0x5040: /* AML */
  4465. case 0x5110: case 0x5125: case 0x5140: /* AML */
  4466. return pci_acs_ctrl_enabled(acs_flags,
  4467. PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF);
  4468. }
  4469. return false;
  4470. }
  4471. static const struct pci_dev_acs_enabled {
  4472. u16 vendor;
  4473. u16 device;
  4474. int (*acs_enabled)(struct pci_dev *dev, u16 acs_flags);
  4475. } pci_dev_acs_enabled[] = {
  4476. { PCI_VENDOR_ID_ATI, 0x4385, pci_quirk_amd_sb_acs },
  4477. { PCI_VENDOR_ID_ATI, 0x439c, pci_quirk_amd_sb_acs },
  4478. { PCI_VENDOR_ID_ATI, 0x4383, pci_quirk_amd_sb_acs },
  4479. { PCI_VENDOR_ID_ATI, 0x439d, pci_quirk_amd_sb_acs },
  4480. { PCI_VENDOR_ID_ATI, 0x4384, pci_quirk_amd_sb_acs },
  4481. { PCI_VENDOR_ID_ATI, 0x4399, pci_quirk_amd_sb_acs },
  4482. { PCI_VENDOR_ID_AMD, 0x780f, pci_quirk_amd_sb_acs },
  4483. { PCI_VENDOR_ID_AMD, 0x7809, pci_quirk_amd_sb_acs },
  4484. { PCI_VENDOR_ID_SOLARFLARE, 0x0903, pci_quirk_mf_endpoint_acs },
  4485. { PCI_VENDOR_ID_SOLARFLARE, 0x0923, pci_quirk_mf_endpoint_acs },
  4486. { PCI_VENDOR_ID_SOLARFLARE, 0x0A03, pci_quirk_mf_endpoint_acs },
  4487. { PCI_VENDOR_ID_INTEL, 0x10C6, pci_quirk_mf_endpoint_acs },
  4488. { PCI_VENDOR_ID_INTEL, 0x10DB, pci_quirk_mf_endpoint_acs },
  4489. { PCI_VENDOR_ID_INTEL, 0x10DD, pci_quirk_mf_endpoint_acs },
  4490. { PCI_VENDOR_ID_INTEL, 0x10E1, pci_quirk_mf_endpoint_acs },
  4491. { PCI_VENDOR_ID_INTEL, 0x10F1, pci_quirk_mf_endpoint_acs },
  4492. { PCI_VENDOR_ID_INTEL, 0x10F7, pci_quirk_mf_endpoint_acs },
  4493. { PCI_VENDOR_ID_INTEL, 0x10F8, pci_quirk_mf_endpoint_acs },
  4494. { PCI_VENDOR_ID_INTEL, 0x10F9, pci_quirk_mf_endpoint_acs },
  4495. { PCI_VENDOR_ID_INTEL, 0x10FA, pci_quirk_mf_endpoint_acs },
  4496. { PCI_VENDOR_ID_INTEL, 0x10FB, pci_quirk_mf_endpoint_acs },
  4497. { PCI_VENDOR_ID_INTEL, 0x10FC, pci_quirk_mf_endpoint_acs },
  4498. { PCI_VENDOR_ID_INTEL, 0x1507, pci_quirk_mf_endpoint_acs },
  4499. { PCI_VENDOR_ID_INTEL, 0x1514, pci_quirk_mf_endpoint_acs },
  4500. { PCI_VENDOR_ID_INTEL, 0x151C, pci_quirk_mf_endpoint_acs },
  4501. { PCI_VENDOR_ID_INTEL, 0x1529, pci_quirk_mf_endpoint_acs },
  4502. { PCI_VENDOR_ID_INTEL, 0x152A, pci_quirk_mf_endpoint_acs },
  4503. { PCI_VENDOR_ID_INTEL, 0x154D, pci_quirk_mf_endpoint_acs },
  4504. { PCI_VENDOR_ID_INTEL, 0x154F, pci_quirk_mf_endpoint_acs },
  4505. { PCI_VENDOR_ID_INTEL, 0x1551, pci_quirk_mf_endpoint_acs },
  4506. { PCI_VENDOR_ID_INTEL, 0x1558, pci_quirk_mf_endpoint_acs },
  4507. /* 82580 */
  4508. { PCI_VENDOR_ID_INTEL, 0x1509, pci_quirk_mf_endpoint_acs },
  4509. { PCI_VENDOR_ID_INTEL, 0x150E, pci_quirk_mf_endpoint_acs },
  4510. { PCI_VENDOR_ID_INTEL, 0x150F, pci_quirk_mf_endpoint_acs },
  4511. { PCI_VENDOR_ID_INTEL, 0x1510, pci_quirk_mf_endpoint_acs },
  4512. { PCI_VENDOR_ID_INTEL, 0x1511, pci_quirk_mf_endpoint_acs },
  4513. { PCI_VENDOR_ID_INTEL, 0x1516, pci_quirk_mf_endpoint_acs },
  4514. { PCI_VENDOR_ID_INTEL, 0x1527, pci_quirk_mf_endpoint_acs },
  4515. /* 82576 */
  4516. { PCI_VENDOR_ID_INTEL, 0x10C9, pci_quirk_mf_endpoint_acs },
  4517. { PCI_VENDOR_ID_INTEL, 0x10E6, pci_quirk_mf_endpoint_acs },
  4518. { PCI_VENDOR_ID_INTEL, 0x10E7, pci_quirk_mf_endpoint_acs },
  4519. { PCI_VENDOR_ID_INTEL, 0x10E8, pci_quirk_mf_endpoint_acs },
  4520. { PCI_VENDOR_ID_INTEL, 0x150A, pci_quirk_mf_endpoint_acs },
  4521. { PCI_VENDOR_ID_INTEL, 0x150D, pci_quirk_mf_endpoint_acs },
  4522. { PCI_VENDOR_ID_INTEL, 0x1518, pci_quirk_mf_endpoint_acs },
  4523. { PCI_VENDOR_ID_INTEL, 0x1526, pci_quirk_mf_endpoint_acs },
  4524. /* 82575 */
  4525. { PCI_VENDOR_ID_INTEL, 0x10A7, pci_quirk_mf_endpoint_acs },
  4526. { PCI_VENDOR_ID_INTEL, 0x10A9, pci_quirk_mf_endpoint_acs },
  4527. { PCI_VENDOR_ID_INTEL, 0x10D6, pci_quirk_mf_endpoint_acs },
  4528. /* I350 */
  4529. { PCI_VENDOR_ID_INTEL, 0x1521, pci_quirk_mf_endpoint_acs },
  4530. { PCI_VENDOR_ID_INTEL, 0x1522, pci_quirk_mf_endpoint_acs },
  4531. { PCI_VENDOR_ID_INTEL, 0x1523, pci_quirk_mf_endpoint_acs },
  4532. { PCI_VENDOR_ID_INTEL, 0x1524, pci_quirk_mf_endpoint_acs },
  4533. /* 82571 (Quads omitted due to non-ACS switch) */
  4534. { PCI_VENDOR_ID_INTEL, 0x105E, pci_quirk_mf_endpoint_acs },
  4535. { PCI_VENDOR_ID_INTEL, 0x105F, pci_quirk_mf_endpoint_acs },
  4536. { PCI_VENDOR_ID_INTEL, 0x1060, pci_quirk_mf_endpoint_acs },
  4537. { PCI_VENDOR_ID_INTEL, 0x10D9, pci_quirk_mf_endpoint_acs },
  4538. /* I219 */
  4539. { PCI_VENDOR_ID_INTEL, 0x15b7, pci_quirk_mf_endpoint_acs },
  4540. { PCI_VENDOR_ID_INTEL, 0x15b8, pci_quirk_mf_endpoint_acs },
  4541. { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, pci_quirk_rciep_acs },
  4542. /* QCOM QDF2xxx root ports */
  4543. { PCI_VENDOR_ID_QCOM, 0x0400, pci_quirk_qcom_rp_acs },
  4544. { PCI_VENDOR_ID_QCOM, 0x0401, pci_quirk_qcom_rp_acs },
  4545. /* QCOM SA8775P root port */
  4546. { PCI_VENDOR_ID_QCOM, 0x0115, pci_quirk_qcom_rp_acs },
  4547. /* HXT SD4800 root ports. The ACS design is same as QCOM QDF2xxx */
  4548. { PCI_VENDOR_ID_HXT, 0x0401, pci_quirk_qcom_rp_acs },
  4549. /* Intel PCH root ports */
  4550. { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, pci_quirk_intel_pch_acs },
  4551. { PCI_VENDOR_ID_INTEL, PCI_ANY_ID, pci_quirk_intel_spt_pch_acs },
  4552. { 0x19a2, 0x710, pci_quirk_mf_endpoint_acs }, /* Emulex BE3-R */
  4553. { 0x10df, 0x720, pci_quirk_mf_endpoint_acs }, /* Emulex Skyhawk-R */
  4554. /* Cavium ThunderX */
  4555. { PCI_VENDOR_ID_CAVIUM, PCI_ANY_ID, pci_quirk_cavium_acs },
  4556. /* Cavium multi-function devices */
  4557. { PCI_VENDOR_ID_CAVIUM, 0xA026, pci_quirk_mf_endpoint_acs },
  4558. { PCI_VENDOR_ID_CAVIUM, 0xA059, pci_quirk_mf_endpoint_acs },
  4559. { PCI_VENDOR_ID_CAVIUM, 0xA060, pci_quirk_mf_endpoint_acs },
  4560. /* APM X-Gene */
  4561. { PCI_VENDOR_ID_AMCC, 0xE004, pci_quirk_xgene_acs },
  4562. /* Ampere Computing */
  4563. { PCI_VENDOR_ID_AMPERE, 0xE005, pci_quirk_xgene_acs },
  4564. { PCI_VENDOR_ID_AMPERE, 0xE006, pci_quirk_xgene_acs },
  4565. { PCI_VENDOR_ID_AMPERE, 0xE007, pci_quirk_xgene_acs },
  4566. { PCI_VENDOR_ID_AMPERE, 0xE008, pci_quirk_xgene_acs },
  4567. { PCI_VENDOR_ID_AMPERE, 0xE009, pci_quirk_xgene_acs },
  4568. { PCI_VENDOR_ID_AMPERE, 0xE00A, pci_quirk_xgene_acs },
  4569. { PCI_VENDOR_ID_AMPERE, 0xE00B, pci_quirk_xgene_acs },
  4570. { PCI_VENDOR_ID_AMPERE, 0xE00C, pci_quirk_xgene_acs },
  4571. /* Broadcom multi-function device */
  4572. { PCI_VENDOR_ID_BROADCOM, 0x16D7, pci_quirk_mf_endpoint_acs },
  4573. { PCI_VENDOR_ID_BROADCOM, 0x1750, pci_quirk_mf_endpoint_acs },
  4574. { PCI_VENDOR_ID_BROADCOM, 0x1751, pci_quirk_mf_endpoint_acs },
  4575. { PCI_VENDOR_ID_BROADCOM, 0x1752, pci_quirk_mf_endpoint_acs },
  4576. { PCI_VENDOR_ID_BROADCOM, 0x1760, pci_quirk_mf_endpoint_acs },
  4577. { PCI_VENDOR_ID_BROADCOM, 0x1761, pci_quirk_mf_endpoint_acs },
  4578. { PCI_VENDOR_ID_BROADCOM, 0x1762, pci_quirk_mf_endpoint_acs },
  4579. { PCI_VENDOR_ID_BROADCOM, 0x1763, pci_quirk_mf_endpoint_acs },
  4580. { PCI_VENDOR_ID_BROADCOM, 0xD714, pci_quirk_brcm_acs },
  4581. /* Amazon Annapurna Labs */
  4582. { PCI_VENDOR_ID_AMAZON_ANNAPURNA_LABS, 0x0031, pci_quirk_al_acs },
  4583. /* Zhaoxin multi-function devices */
  4584. { PCI_VENDOR_ID_ZHAOXIN, 0x3038, pci_quirk_mf_endpoint_acs },
  4585. { PCI_VENDOR_ID_ZHAOXIN, 0x3104, pci_quirk_mf_endpoint_acs },
  4586. { PCI_VENDOR_ID_ZHAOXIN, 0x9083, pci_quirk_mf_endpoint_acs },
  4587. /* NXP root ports, xx=16, 12, or 08 cores */
  4588. /* LX2xx0A : without security features + CAN-FD */
  4589. { PCI_VENDOR_ID_NXP, 0x8d81, pci_quirk_nxp_rp_acs },
  4590. { PCI_VENDOR_ID_NXP, 0x8da1, pci_quirk_nxp_rp_acs },
  4591. { PCI_VENDOR_ID_NXP, 0x8d83, pci_quirk_nxp_rp_acs },
  4592. /* LX2xx0C : security features + CAN-FD */
  4593. { PCI_VENDOR_ID_NXP, 0x8d80, pci_quirk_nxp_rp_acs },
  4594. { PCI_VENDOR_ID_NXP, 0x8da0, pci_quirk_nxp_rp_acs },
  4595. { PCI_VENDOR_ID_NXP, 0x8d82, pci_quirk_nxp_rp_acs },
  4596. /* LX2xx0E : security features + CAN */
  4597. { PCI_VENDOR_ID_NXP, 0x8d90, pci_quirk_nxp_rp_acs },
  4598. { PCI_VENDOR_ID_NXP, 0x8db0, pci_quirk_nxp_rp_acs },
  4599. { PCI_VENDOR_ID_NXP, 0x8d92, pci_quirk_nxp_rp_acs },
  4600. /* LX2xx0N : without security features + CAN */
  4601. { PCI_VENDOR_ID_NXP, 0x8d91, pci_quirk_nxp_rp_acs },
  4602. { PCI_VENDOR_ID_NXP, 0x8db1, pci_quirk_nxp_rp_acs },
  4603. { PCI_VENDOR_ID_NXP, 0x8d93, pci_quirk_nxp_rp_acs },
  4604. /* LX2xx2A : without security features + CAN-FD */
  4605. { PCI_VENDOR_ID_NXP, 0x8d89, pci_quirk_nxp_rp_acs },
  4606. { PCI_VENDOR_ID_NXP, 0x8da9, pci_quirk_nxp_rp_acs },
  4607. { PCI_VENDOR_ID_NXP, 0x8d8b, pci_quirk_nxp_rp_acs },
  4608. /* LX2xx2C : security features + CAN-FD */
  4609. { PCI_VENDOR_ID_NXP, 0x8d88, pci_quirk_nxp_rp_acs },
  4610. { PCI_VENDOR_ID_NXP, 0x8da8, pci_quirk_nxp_rp_acs },
  4611. { PCI_VENDOR_ID_NXP, 0x8d8a, pci_quirk_nxp_rp_acs },
  4612. /* LX2xx2E : security features + CAN */
  4613. { PCI_VENDOR_ID_NXP, 0x8d98, pci_quirk_nxp_rp_acs },
  4614. { PCI_VENDOR_ID_NXP, 0x8db8, pci_quirk_nxp_rp_acs },
  4615. { PCI_VENDOR_ID_NXP, 0x8d9a, pci_quirk_nxp_rp_acs },
  4616. /* LX2xx2N : without security features + CAN */
  4617. { PCI_VENDOR_ID_NXP, 0x8d99, pci_quirk_nxp_rp_acs },
  4618. { PCI_VENDOR_ID_NXP, 0x8db9, pci_quirk_nxp_rp_acs },
  4619. { PCI_VENDOR_ID_NXP, 0x8d9b, pci_quirk_nxp_rp_acs },
  4620. /* Zhaoxin Root/Downstream Ports */
  4621. { PCI_VENDOR_ID_ZHAOXIN, PCI_ANY_ID, pci_quirk_zhaoxin_pcie_ports_acs },
  4622. /* Wangxun nics */
  4623. { PCI_VENDOR_ID_WANGXUN, PCI_ANY_ID, pci_quirk_wangxun_nic_acs },
  4624. { 0 }
  4625. };
  4626. /*
  4627. * pci_dev_specific_acs_enabled - check whether device provides ACS controls
  4628. * @dev: PCI device
  4629. * @acs_flags: Bitmask of desired ACS controls
  4630. *
  4631. * Returns:
  4632. * -ENOTTY: No quirk applies to this device; we can't tell whether the
  4633. * device provides the desired controls
  4634. * 0: Device does not provide all the desired controls
  4635. * >0: Device provides all the controls in @acs_flags
  4636. */
  4637. int pci_dev_specific_acs_enabled(struct pci_dev *dev, u16 acs_flags)
  4638. {
  4639. const struct pci_dev_acs_enabled *i;
  4640. int ret;
  4641. /*
  4642. * Allow devices that do not expose standard PCIe ACS capabilities
  4643. * or control to indicate their support here. Multi-function express
  4644. * devices which do not allow internal peer-to-peer between functions,
  4645. * but do not implement PCIe ACS may wish to return true here.
  4646. */
  4647. for (i = pci_dev_acs_enabled; i->acs_enabled; i++) {
  4648. if ((i->vendor == dev->vendor ||
  4649. i->vendor == (u16)PCI_ANY_ID) &&
  4650. (i->device == dev->device ||
  4651. i->device == (u16)PCI_ANY_ID)) {
  4652. ret = i->acs_enabled(dev, acs_flags);
  4653. if (ret >= 0)
  4654. return ret;
  4655. }
  4656. }
  4657. return -ENOTTY;
  4658. }
  4659. /* Config space offset of Root Complex Base Address register */
  4660. #define INTEL_LPC_RCBA_REG 0xf0
  4661. /* 31:14 RCBA address */
  4662. #define INTEL_LPC_RCBA_MASK 0xffffc000
  4663. /* RCBA Enable */
  4664. #define INTEL_LPC_RCBA_ENABLE (1 << 0)
  4665. /* Backbone Scratch Pad Register */
  4666. #define INTEL_BSPR_REG 0x1104
  4667. /* Backbone Peer Non-Posted Disable */
  4668. #define INTEL_BSPR_REG_BPNPD (1 << 8)
  4669. /* Backbone Peer Posted Disable */
  4670. #define INTEL_BSPR_REG_BPPD (1 << 9)
  4671. /* Upstream Peer Decode Configuration Register */
  4672. #define INTEL_UPDCR_REG 0x1014
  4673. /* 5:0 Peer Decode Enable bits */
  4674. #define INTEL_UPDCR_REG_MASK 0x3f
  4675. static int pci_quirk_enable_intel_lpc_acs(struct pci_dev *dev)
  4676. {
  4677. u32 rcba, bspr, updcr;
  4678. void __iomem *rcba_mem;
  4679. /*
  4680. * Read the RCBA register from the LPC (D31:F0). PCH root ports
  4681. * are D28:F* and therefore get probed before LPC, thus we can't
  4682. * use pci_get_slot()/pci_read_config_dword() here.
  4683. */
  4684. pci_bus_read_config_dword(dev->bus, PCI_DEVFN(31, 0),
  4685. INTEL_LPC_RCBA_REG, &rcba);
  4686. if (!(rcba & INTEL_LPC_RCBA_ENABLE))
  4687. return -EINVAL;
  4688. rcba_mem = ioremap(rcba & INTEL_LPC_RCBA_MASK,
  4689. PAGE_ALIGN(INTEL_UPDCR_REG));
  4690. if (!rcba_mem)
  4691. return -ENOMEM;
  4692. /*
  4693. * The BSPR can disallow peer cycles, but it's set by soft strap and
  4694. * therefore read-only. If both posted and non-posted peer cycles are
  4695. * disallowed, we're ok. If either are allowed, then we need to use
  4696. * the UPDCR to disable peer decodes for each port. This provides the
  4697. * PCIe ACS equivalent of PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF
  4698. */
  4699. bspr = readl(rcba_mem + INTEL_BSPR_REG);
  4700. bspr &= INTEL_BSPR_REG_BPNPD | INTEL_BSPR_REG_BPPD;
  4701. if (bspr != (INTEL_BSPR_REG_BPNPD | INTEL_BSPR_REG_BPPD)) {
  4702. updcr = readl(rcba_mem + INTEL_UPDCR_REG);
  4703. if (updcr & INTEL_UPDCR_REG_MASK) {
  4704. pci_info(dev, "Disabling UPDCR peer decodes\n");
  4705. updcr &= ~INTEL_UPDCR_REG_MASK;
  4706. writel(updcr, rcba_mem + INTEL_UPDCR_REG);
  4707. }
  4708. }
  4709. iounmap(rcba_mem);
  4710. return 0;
  4711. }
  4712. /* Miscellaneous Port Configuration register */
  4713. #define INTEL_MPC_REG 0xd8
  4714. /* MPC: Invalid Receive Bus Number Check Enable */
  4715. #define INTEL_MPC_REG_IRBNCE (1 << 26)
  4716. static void pci_quirk_enable_intel_rp_mpc_acs(struct pci_dev *dev)
  4717. {
  4718. u32 mpc;
  4719. /*
  4720. * When enabled, the IRBNCE bit of the MPC register enables the
  4721. * equivalent of PCI ACS Source Validation (PCI_ACS_SV), which
  4722. * ensures that requester IDs fall within the bus number range
  4723. * of the bridge. Enable if not already.
  4724. */
  4725. pci_read_config_dword(dev, INTEL_MPC_REG, &mpc);
  4726. if (!(mpc & INTEL_MPC_REG_IRBNCE)) {
  4727. pci_info(dev, "Enabling MPC IRBNCE\n");
  4728. mpc |= INTEL_MPC_REG_IRBNCE;
  4729. pci_write_config_word(dev, INTEL_MPC_REG, mpc);
  4730. }
  4731. }
  4732. /*
  4733. * Currently this quirk does the equivalent of
  4734. * PCI_ACS_SV | PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_UF
  4735. *
  4736. * TODO: This quirk also needs to do equivalent of PCI_ACS_TB,
  4737. * if dev->external_facing || dev->untrusted
  4738. */
  4739. static int pci_quirk_enable_intel_pch_acs(struct pci_dev *dev)
  4740. {
  4741. if (!pci_quirk_intel_pch_acs_match(dev))
  4742. return -ENOTTY;
  4743. if (pci_quirk_enable_intel_lpc_acs(dev)) {
  4744. pci_warn(dev, "Failed to enable Intel PCH ACS quirk\n");
  4745. return 0;
  4746. }
  4747. pci_quirk_enable_intel_rp_mpc_acs(dev);
  4748. dev->dev_flags |= PCI_DEV_FLAGS_ACS_ENABLED_QUIRK;
  4749. pci_info(dev, "Intel PCH root port ACS workaround enabled\n");
  4750. return 0;
  4751. }
  4752. static int pci_quirk_enable_intel_spt_pch_acs(struct pci_dev *dev)
  4753. {
  4754. int pos;
  4755. u32 cap, ctrl;
  4756. if (!pci_quirk_intel_spt_pch_acs_match(dev))
  4757. return -ENOTTY;
  4758. pos = dev->acs_cap;
  4759. if (!pos)
  4760. return -ENOTTY;
  4761. pci_read_config_dword(dev, pos + PCI_ACS_CAP, &cap);
  4762. pci_read_config_dword(dev, pos + INTEL_SPT_ACS_CTRL, &ctrl);
  4763. ctrl |= (cap & PCI_ACS_SV);
  4764. ctrl |= (cap & PCI_ACS_RR);
  4765. ctrl |= (cap & PCI_ACS_CR);
  4766. ctrl |= (cap & PCI_ACS_UF);
  4767. if (pci_ats_disabled() || dev->external_facing || dev->untrusted)
  4768. ctrl |= (cap & PCI_ACS_TB);
  4769. pci_write_config_dword(dev, pos + INTEL_SPT_ACS_CTRL, ctrl);
  4770. pci_info(dev, "Intel SPT PCH root port ACS workaround enabled\n");
  4771. return 0;
  4772. }
  4773. static int pci_quirk_disable_intel_spt_pch_acs_redir(struct pci_dev *dev)
  4774. {
  4775. int pos;
  4776. u32 cap, ctrl;
  4777. if (!pci_quirk_intel_spt_pch_acs_match(dev))
  4778. return -ENOTTY;
  4779. pos = dev->acs_cap;
  4780. if (!pos)
  4781. return -ENOTTY;
  4782. pci_read_config_dword(dev, pos + PCI_ACS_CAP, &cap);
  4783. pci_read_config_dword(dev, pos + INTEL_SPT_ACS_CTRL, &ctrl);
  4784. ctrl &= ~(PCI_ACS_RR | PCI_ACS_CR | PCI_ACS_EC);
  4785. pci_write_config_dword(dev, pos + INTEL_SPT_ACS_CTRL, ctrl);
  4786. pci_info(dev, "Intel SPT PCH root port workaround: disabled ACS redirect\n");
  4787. return 0;
  4788. }
  4789. static const struct pci_dev_acs_ops {
  4790. u16 vendor;
  4791. u16 device;
  4792. int (*enable_acs)(struct pci_dev *dev);
  4793. int (*disable_acs_redir)(struct pci_dev *dev);
  4794. } pci_dev_acs_ops[] = {
  4795. { PCI_VENDOR_ID_INTEL, PCI_ANY_ID,
  4796. .enable_acs = pci_quirk_enable_intel_pch_acs,
  4797. },
  4798. { PCI_VENDOR_ID_INTEL, PCI_ANY_ID,
  4799. .enable_acs = pci_quirk_enable_intel_spt_pch_acs,
  4800. .disable_acs_redir = pci_quirk_disable_intel_spt_pch_acs_redir,
  4801. },
  4802. };
  4803. int pci_dev_specific_enable_acs(struct pci_dev *dev)
  4804. {
  4805. const struct pci_dev_acs_ops *p;
  4806. int i, ret;
  4807. for (i = 0; i < ARRAY_SIZE(pci_dev_acs_ops); i++) {
  4808. p = &pci_dev_acs_ops[i];
  4809. if ((p->vendor == dev->vendor ||
  4810. p->vendor == (u16)PCI_ANY_ID) &&
  4811. (p->device == dev->device ||
  4812. p->device == (u16)PCI_ANY_ID) &&
  4813. p->enable_acs) {
  4814. ret = p->enable_acs(dev);
  4815. if (ret >= 0)
  4816. return ret;
  4817. }
  4818. }
  4819. return -ENOTTY;
  4820. }
  4821. int pci_dev_specific_disable_acs_redir(struct pci_dev *dev)
  4822. {
  4823. const struct pci_dev_acs_ops *p;
  4824. int i, ret;
  4825. for (i = 0; i < ARRAY_SIZE(pci_dev_acs_ops); i++) {
  4826. p = &pci_dev_acs_ops[i];
  4827. if ((p->vendor == dev->vendor ||
  4828. p->vendor == (u16)PCI_ANY_ID) &&
  4829. (p->device == dev->device ||
  4830. p->device == (u16)PCI_ANY_ID) &&
  4831. p->disable_acs_redir) {
  4832. ret = p->disable_acs_redir(dev);
  4833. if (ret >= 0)
  4834. return ret;
  4835. }
  4836. }
  4837. return -ENOTTY;
  4838. }
  4839. /*
  4840. * The PCI capabilities list for Intel DH895xCC VFs (device ID 0x0443) with
  4841. * QuickAssist Technology (QAT) is prematurely terminated in hardware. The
  4842. * Next Capability pointer in the MSI Capability Structure should point to
  4843. * the PCIe Capability Structure but is incorrectly hardwired as 0 terminating
  4844. * the list.
  4845. */
  4846. static void quirk_intel_qat_vf_cap(struct pci_dev *pdev)
  4847. {
  4848. int pos, i = 0, ret;
  4849. u8 next_cap;
  4850. u16 reg16, *cap;
  4851. struct pci_cap_saved_state *state;
  4852. /* Bail if the hardware bug is fixed */
  4853. if (pdev->pcie_cap || pci_find_capability(pdev, PCI_CAP_ID_EXP))
  4854. return;
  4855. /* Bail if MSI Capability Structure is not found for some reason */
  4856. pos = pci_find_capability(pdev, PCI_CAP_ID_MSI);
  4857. if (!pos)
  4858. return;
  4859. /*
  4860. * Bail if Next Capability pointer in the MSI Capability Structure
  4861. * is not the expected incorrect 0x00.
  4862. */
  4863. pci_read_config_byte(pdev, pos + 1, &next_cap);
  4864. if (next_cap)
  4865. return;
  4866. /*
  4867. * PCIe Capability Structure is expected to be at 0x50 and should
  4868. * terminate the list (Next Capability pointer is 0x00). Verify
  4869. * Capability Id and Next Capability pointer is as expected.
  4870. * Open-code some of set_pcie_port_type() and pci_cfg_space_size_ext()
  4871. * to correctly set kernel data structures which have already been
  4872. * set incorrectly due to the hardware bug.
  4873. */
  4874. pos = 0x50;
  4875. pci_read_config_word(pdev, pos, &reg16);
  4876. if (reg16 == (0x0000 | PCI_CAP_ID_EXP)) {
  4877. u32 status;
  4878. #ifndef PCI_EXP_SAVE_REGS
  4879. #define PCI_EXP_SAVE_REGS 7
  4880. #endif
  4881. int size = PCI_EXP_SAVE_REGS * sizeof(u16);
  4882. pdev->pcie_cap = pos;
  4883. pci_read_config_word(pdev, pos + PCI_EXP_FLAGS, &reg16);
  4884. pdev->pcie_flags_reg = reg16;
  4885. pci_read_config_word(pdev, pos + PCI_EXP_DEVCAP, &reg16);
  4886. pdev->pcie_mpss = reg16 & PCI_EXP_DEVCAP_PAYLOAD;
  4887. pdev->cfg_size = PCI_CFG_SPACE_EXP_SIZE;
  4888. ret = pci_read_config_dword(pdev, PCI_CFG_SPACE_SIZE, &status);
  4889. if ((ret != PCIBIOS_SUCCESSFUL) || (PCI_POSSIBLE_ERROR(status)))
  4890. pdev->cfg_size = PCI_CFG_SPACE_SIZE;
  4891. if (pci_find_saved_cap(pdev, PCI_CAP_ID_EXP))
  4892. return;
  4893. /* Save PCIe cap */
  4894. state = kzalloc(sizeof(*state) + size, GFP_KERNEL);
  4895. if (!state)
  4896. return;
  4897. state->cap.cap_nr = PCI_CAP_ID_EXP;
  4898. state->cap.cap_extended = 0;
  4899. state->cap.size = size;
  4900. cap = (u16 *)&state->cap.data[0];
  4901. pcie_capability_read_word(pdev, PCI_EXP_DEVCTL, &cap[i++]);
  4902. pcie_capability_read_word(pdev, PCI_EXP_LNKCTL, &cap[i++]);
  4903. pcie_capability_read_word(pdev, PCI_EXP_SLTCTL, &cap[i++]);
  4904. pcie_capability_read_word(pdev, PCI_EXP_RTCTL, &cap[i++]);
  4905. pcie_capability_read_word(pdev, PCI_EXP_DEVCTL2, &cap[i++]);
  4906. pcie_capability_read_word(pdev, PCI_EXP_LNKCTL2, &cap[i++]);
  4907. pcie_capability_read_word(pdev, PCI_EXP_SLTCTL2, &cap[i++]);
  4908. hlist_add_head(&state->next, &pdev->saved_cap_space);
  4909. }
  4910. }
  4911. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x443, quirk_intel_qat_vf_cap);
  4912. /*
  4913. * FLR may cause the following to devices to hang:
  4914. *
  4915. * AMD Starship/Matisse HD Audio Controller 0x1487
  4916. * AMD Starship USB 3.0 Host Controller 0x148c
  4917. * AMD Matisse USB 3.0 Host Controller 0x149c
  4918. * Intel 82579LM Gigabit Ethernet Controller 0x1502
  4919. * Intel 82579V Gigabit Ethernet Controller 0x1503
  4920. * Mediatek MT7922 802.11ax PCI Express Wireless Network Adapter
  4921. */
  4922. static void quirk_no_flr(struct pci_dev *dev)
  4923. {
  4924. dev->dev_flags |= PCI_DEV_FLAGS_NO_FLR_RESET;
  4925. }
  4926. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_AMD, 0x1487, quirk_no_flr);
  4927. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_AMD, 0x148c, quirk_no_flr);
  4928. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_AMD, 0x149c, quirk_no_flr);
  4929. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_AMD, 0x7901, quirk_no_flr);
  4930. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1502, quirk_no_flr);
  4931. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1503, quirk_no_flr);
  4932. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_MEDIATEK, 0x0616, quirk_no_flr);
  4933. /* FLR may cause the SolidRun SNET DPU (rev 0x1) to hang */
  4934. static void quirk_no_flr_snet(struct pci_dev *dev)
  4935. {
  4936. if (dev->revision == 0x1)
  4937. quirk_no_flr(dev);
  4938. }
  4939. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SOLIDRUN, 0x1000, quirk_no_flr_snet);
  4940. static void quirk_no_ext_tags(struct pci_dev *pdev)
  4941. {
  4942. struct pci_host_bridge *bridge = pci_find_host_bridge(pdev->bus);
  4943. if (!bridge)
  4944. return;
  4945. bridge->no_ext_tags = 1;
  4946. pci_info(pdev, "disabling Extended Tags (this device can't handle them)\n");
  4947. pci_walk_bus(bridge->bus, pci_configure_extended_tags, NULL);
  4948. }
  4949. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_3WARE, 0x1004, quirk_no_ext_tags);
  4950. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0132, quirk_no_ext_tags);
  4951. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0140, quirk_no_ext_tags);
  4952. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0141, quirk_no_ext_tags);
  4953. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0142, quirk_no_ext_tags);
  4954. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0144, quirk_no_ext_tags);
  4955. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0420, quirk_no_ext_tags);
  4956. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_SERVERWORKS, 0x0422, quirk_no_ext_tags);
  4957. #ifdef CONFIG_PCI_ATS
  4958. static void quirk_no_ats(struct pci_dev *pdev)
  4959. {
  4960. pci_info(pdev, "disabling ATS\n");
  4961. pdev->ats_cap = 0;
  4962. }
  4963. /*
  4964. * Some devices require additional driver setup to enable ATS. Don't use
  4965. * ATS for those devices as ATS will be enabled before the driver has had a
  4966. * chance to load and configure the device.
  4967. */
  4968. static void quirk_amd_harvest_no_ats(struct pci_dev *pdev)
  4969. {
  4970. if (pdev->device == 0x15d8) {
  4971. if (pdev->revision == 0xcf &&
  4972. pdev->subsystem_vendor == 0xea50 &&
  4973. (pdev->subsystem_device == 0xce19 ||
  4974. pdev->subsystem_device == 0xcc10 ||
  4975. pdev->subsystem_device == 0xcc08))
  4976. quirk_no_ats(pdev);
  4977. } else {
  4978. quirk_no_ats(pdev);
  4979. }
  4980. }
  4981. /* AMD Stoney platform GPU */
  4982. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x98e4, quirk_amd_harvest_no_ats);
  4983. /* AMD Iceland dGPU */
  4984. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x6900, quirk_amd_harvest_no_ats);
  4985. /* AMD Navi10 dGPU */
  4986. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x7310, quirk_amd_harvest_no_ats);
  4987. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x7312, quirk_amd_harvest_no_ats);
  4988. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x7318, quirk_amd_harvest_no_ats);
  4989. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x7319, quirk_amd_harvest_no_ats);
  4990. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x731a, quirk_amd_harvest_no_ats);
  4991. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x731b, quirk_amd_harvest_no_ats);
  4992. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x731e, quirk_amd_harvest_no_ats);
  4993. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x731f, quirk_amd_harvest_no_ats);
  4994. /* AMD Navi14 dGPU */
  4995. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x7340, quirk_amd_harvest_no_ats);
  4996. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x7341, quirk_amd_harvest_no_ats);
  4997. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x7347, quirk_amd_harvest_no_ats);
  4998. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x734f, quirk_amd_harvest_no_ats);
  4999. /* AMD Raven platform iGPU */
  5000. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ATI, 0x15d8, quirk_amd_harvest_no_ats);
  5001. /*
  5002. * Intel IPU E2000 revisions before C0 implement incorrect endianness
  5003. * in ATS Invalidate Request message body. Disable ATS for those devices.
  5004. */
  5005. static void quirk_intel_e2000_no_ats(struct pci_dev *pdev)
  5006. {
  5007. if (pdev->revision < 0x20)
  5008. quirk_no_ats(pdev);
  5009. }
  5010. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1451, quirk_intel_e2000_no_ats);
  5011. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1452, quirk_intel_e2000_no_ats);
  5012. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1453, quirk_intel_e2000_no_ats);
  5013. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1454, quirk_intel_e2000_no_ats);
  5014. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1455, quirk_intel_e2000_no_ats);
  5015. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1457, quirk_intel_e2000_no_ats);
  5016. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x1459, quirk_intel_e2000_no_ats);
  5017. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x145a, quirk_intel_e2000_no_ats);
  5018. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_INTEL, 0x145c, quirk_intel_e2000_no_ats);
  5019. #endif /* CONFIG_PCI_ATS */
  5020. /* Freescale PCIe doesn't support MSI in RC mode */
  5021. static void quirk_fsl_no_msi(struct pci_dev *pdev)
  5022. {
  5023. if (pci_pcie_type(pdev) == PCI_EXP_TYPE_ROOT_PORT)
  5024. pdev->no_msi = 1;
  5025. }
  5026. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_FREESCALE, PCI_ANY_ID, quirk_fsl_no_msi);
  5027. /*
  5028. * Although not allowed by the spec, some multi-function devices have
  5029. * dependencies of one function (consumer) on another (supplier). For the
  5030. * consumer to work in D0, the supplier must also be in D0. Create a
  5031. * device link from the consumer to the supplier to enforce this
  5032. * dependency. Runtime PM is allowed by default on the consumer to prevent
  5033. * it from permanently keeping the supplier awake.
  5034. */
  5035. static void pci_create_device_link(struct pci_dev *pdev, unsigned int consumer,
  5036. unsigned int supplier, unsigned int class,
  5037. unsigned int class_shift)
  5038. {
  5039. struct pci_dev *supplier_pdev;
  5040. if (PCI_FUNC(pdev->devfn) != consumer)
  5041. return;
  5042. supplier_pdev = pci_get_domain_bus_and_slot(pci_domain_nr(pdev->bus),
  5043. pdev->bus->number,
  5044. PCI_DEVFN(PCI_SLOT(pdev->devfn), supplier));
  5045. if (!supplier_pdev || (supplier_pdev->class >> class_shift) != class) {
  5046. pci_dev_put(supplier_pdev);
  5047. return;
  5048. }
  5049. if (device_link_add(&pdev->dev, &supplier_pdev->dev,
  5050. DL_FLAG_STATELESS | DL_FLAG_PM_RUNTIME))
  5051. pci_info(pdev, "D0 power state depends on %s\n",
  5052. pci_name(supplier_pdev));
  5053. else
  5054. pci_err(pdev, "Cannot enforce power dependency on %s\n",
  5055. pci_name(supplier_pdev));
  5056. pm_runtime_allow(&pdev->dev);
  5057. pci_dev_put(supplier_pdev);
  5058. }
  5059. /*
  5060. * Create device link for GPUs with integrated HDA controller for streaming
  5061. * audio to attached displays.
  5062. */
  5063. static void quirk_gpu_hda(struct pci_dev *hda)
  5064. {
  5065. pci_create_device_link(hda, 1, 0, PCI_BASE_CLASS_DISPLAY, 16);
  5066. }
  5067. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_ATI, PCI_ANY_ID,
  5068. PCI_CLASS_MULTIMEDIA_HD_AUDIO, 8, quirk_gpu_hda);
  5069. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_AMD, PCI_ANY_ID,
  5070. PCI_CLASS_MULTIMEDIA_HD_AUDIO, 8, quirk_gpu_hda);
  5071. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
  5072. PCI_CLASS_MULTIMEDIA_HD_AUDIO, 8, quirk_gpu_hda);
  5073. /*
  5074. * Create device link for GPUs with integrated USB xHCI Host
  5075. * controller to VGA.
  5076. */
  5077. static void quirk_gpu_usb(struct pci_dev *usb)
  5078. {
  5079. pci_create_device_link(usb, 2, 0, PCI_BASE_CLASS_DISPLAY, 16);
  5080. }
  5081. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
  5082. PCI_CLASS_SERIAL_USB, 8, quirk_gpu_usb);
  5083. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_ATI, PCI_ANY_ID,
  5084. PCI_CLASS_SERIAL_USB, 8, quirk_gpu_usb);
  5085. /*
  5086. * Create device link for GPUs with integrated Type-C UCSI controller
  5087. * to VGA. Currently there is no class code defined for UCSI device over PCI
  5088. * so using UNKNOWN class for now and it will be updated when UCSI
  5089. * over PCI gets a class code.
  5090. */
  5091. #define PCI_CLASS_SERIAL_UNKNOWN 0x0c80
  5092. static void quirk_gpu_usb_typec_ucsi(struct pci_dev *ucsi)
  5093. {
  5094. pci_create_device_link(ucsi, 3, 0, PCI_BASE_CLASS_DISPLAY, 16);
  5095. }
  5096. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
  5097. PCI_CLASS_SERIAL_UNKNOWN, 8,
  5098. quirk_gpu_usb_typec_ucsi);
  5099. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_ATI, PCI_ANY_ID,
  5100. PCI_CLASS_SERIAL_UNKNOWN, 8,
  5101. quirk_gpu_usb_typec_ucsi);
  5102. /*
  5103. * Enable the NVIDIA GPU integrated HDA controller if the BIOS left it
  5104. * disabled. https://devtalk.nvidia.com/default/topic/1024022
  5105. */
  5106. static void quirk_nvidia_hda(struct pci_dev *gpu)
  5107. {
  5108. u8 hdr_type;
  5109. u32 val;
  5110. /* There was no integrated HDA controller before MCP89 */
  5111. if (gpu->device < PCI_DEVICE_ID_NVIDIA_GEFORCE_320M)
  5112. return;
  5113. /* Bit 25 at offset 0x488 enables the HDA controller */
  5114. pci_read_config_dword(gpu, 0x488, &val);
  5115. if (val & BIT(25))
  5116. return;
  5117. pci_info(gpu, "Enabling HDA controller\n");
  5118. pci_write_config_dword(gpu, 0x488, val | BIT(25));
  5119. /* The GPU becomes a multi-function device when the HDA is enabled */
  5120. pci_read_config_byte(gpu, PCI_HEADER_TYPE, &hdr_type);
  5121. gpu->multifunction = FIELD_GET(PCI_HEADER_TYPE_MFD, hdr_type);
  5122. }
  5123. DECLARE_PCI_FIXUP_CLASS_HEADER(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
  5124. PCI_BASE_CLASS_DISPLAY, 16, quirk_nvidia_hda);
  5125. DECLARE_PCI_FIXUP_CLASS_RESUME_EARLY(PCI_VENDOR_ID_NVIDIA, PCI_ANY_ID,
  5126. PCI_BASE_CLASS_DISPLAY, 16, quirk_nvidia_hda);
  5127. /*
  5128. * Some IDT switches incorrectly flag an ACS Source Validation error on
  5129. * completions for config read requests even though PCIe r4.0, sec
  5130. * 6.12.1.1, says that completions are never affected by ACS Source
  5131. * Validation. Here's the text of IDT 89H32H8G3-YC, erratum #36:
  5132. *
  5133. * Item #36 - Downstream port applies ACS Source Validation to Completions
  5134. * Section 6.12.1.1 of the PCI Express Base Specification 3.1 states that
  5135. * completions are never affected by ACS Source Validation. However,
  5136. * completions received by a downstream port of the PCIe switch from a
  5137. * device that has not yet captured a PCIe bus number are incorrectly
  5138. * dropped by ACS Source Validation by the switch downstream port.
  5139. *
  5140. * The workaround suggested by IDT is to issue a config write to the
  5141. * downstream device before issuing the first config read. This allows the
  5142. * downstream device to capture its bus and device numbers (see PCIe r4.0,
  5143. * sec 2.2.9), thus avoiding the ACS error on the completion.
  5144. *
  5145. * However, we don't know when the device is ready to accept the config
  5146. * write, so we do config reads until we receive a non-Config Request Retry
  5147. * Status, then do the config write.
  5148. *
  5149. * To avoid hitting the erratum when doing the config reads, we disable ACS
  5150. * SV around this process.
  5151. */
  5152. int pci_idt_bus_quirk(struct pci_bus *bus, int devfn, u32 *l, int timeout)
  5153. {
  5154. int pos;
  5155. u16 ctrl = 0;
  5156. bool found;
  5157. struct pci_dev *bridge = bus->self;
  5158. pos = bridge->acs_cap;
  5159. /* Disable ACS SV before initial config reads */
  5160. if (pos) {
  5161. pci_read_config_word(bridge, pos + PCI_ACS_CTRL, &ctrl);
  5162. if (ctrl & PCI_ACS_SV)
  5163. pci_write_config_word(bridge, pos + PCI_ACS_CTRL,
  5164. ctrl & ~PCI_ACS_SV);
  5165. }
  5166. found = pci_bus_generic_read_dev_vendor_id(bus, devfn, l, timeout);
  5167. /* Write Vendor ID (read-only) so the endpoint latches its bus/dev */
  5168. if (found)
  5169. pci_bus_write_config_word(bus, devfn, PCI_VENDOR_ID, 0);
  5170. /* Re-enable ACS_SV if it was previously enabled */
  5171. if (ctrl & PCI_ACS_SV)
  5172. pci_write_config_word(bridge, pos + PCI_ACS_CTRL, ctrl);
  5173. return found;
  5174. }
  5175. /*
  5176. * Microsemi Switchtec NTB uses devfn proxy IDs to move TLPs between
  5177. * NT endpoints via the internal switch fabric. These IDs replace the
  5178. * originating Requester ID TLPs which access host memory on peer NTB
  5179. * ports. Therefore, all proxy IDs must be aliased to the NTB device
  5180. * to permit access when the IOMMU is turned on.
  5181. */
  5182. static void quirk_switchtec_ntb_dma_alias(struct pci_dev *pdev)
  5183. {
  5184. void __iomem *mmio;
  5185. struct ntb_info_regs __iomem *mmio_ntb;
  5186. struct ntb_ctrl_regs __iomem *mmio_ctrl;
  5187. u64 partition_map;
  5188. u8 partition;
  5189. int pp;
  5190. if (pci_enable_device(pdev)) {
  5191. pci_err(pdev, "Cannot enable Switchtec device\n");
  5192. return;
  5193. }
  5194. mmio = pci_iomap(pdev, 0, 0);
  5195. if (mmio == NULL) {
  5196. pci_disable_device(pdev);
  5197. pci_err(pdev, "Cannot iomap Switchtec device\n");
  5198. return;
  5199. }
  5200. pci_info(pdev, "Setting Switchtec proxy ID aliases\n");
  5201. mmio_ntb = mmio + SWITCHTEC_GAS_NTB_OFFSET;
  5202. mmio_ctrl = (void __iomem *) mmio_ntb + SWITCHTEC_NTB_REG_CTRL_OFFSET;
  5203. partition = ioread8(&mmio_ntb->partition_id);
  5204. partition_map = ioread32(&mmio_ntb->ep_map);
  5205. partition_map |= ((u64) ioread32(&mmio_ntb->ep_map + 4)) << 32;
  5206. partition_map &= ~(1ULL << partition);
  5207. for (pp = 0; pp < (sizeof(partition_map) * 8); pp++) {
  5208. struct ntb_ctrl_regs __iomem *mmio_peer_ctrl;
  5209. u32 table_sz = 0;
  5210. int te;
  5211. if (!(partition_map & (1ULL << pp)))
  5212. continue;
  5213. pci_dbg(pdev, "Processing partition %d\n", pp);
  5214. mmio_peer_ctrl = &mmio_ctrl[pp];
  5215. table_sz = ioread16(&mmio_peer_ctrl->req_id_table_size);
  5216. if (!table_sz) {
  5217. pci_warn(pdev, "Partition %d table_sz 0\n", pp);
  5218. continue;
  5219. }
  5220. if (table_sz > 512) {
  5221. pci_warn(pdev,
  5222. "Invalid Switchtec partition %d table_sz %d\n",
  5223. pp, table_sz);
  5224. continue;
  5225. }
  5226. for (te = 0; te < table_sz; te++) {
  5227. u32 rid_entry;
  5228. u8 devfn;
  5229. rid_entry = ioread32(&mmio_peer_ctrl->req_id_table[te]);
  5230. devfn = (rid_entry >> 1) & 0xFF;
  5231. pci_dbg(pdev,
  5232. "Aliasing Partition %d Proxy ID %02x.%d\n",
  5233. pp, PCI_SLOT(devfn), PCI_FUNC(devfn));
  5234. pci_add_dma_alias(pdev, devfn, 1);
  5235. }
  5236. }
  5237. pci_iounmap(pdev, mmio);
  5238. pci_disable_device(pdev);
  5239. }
  5240. #define SWITCHTEC_QUIRK(vid) \
  5241. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_MICROSEMI, vid, \
  5242. PCI_CLASS_BRIDGE_OTHER, 8, quirk_switchtec_ntb_dma_alias)
  5243. SWITCHTEC_QUIRK(0x8531); /* PFX 24xG3 */
  5244. SWITCHTEC_QUIRK(0x8532); /* PFX 32xG3 */
  5245. SWITCHTEC_QUIRK(0x8533); /* PFX 48xG3 */
  5246. SWITCHTEC_QUIRK(0x8534); /* PFX 64xG3 */
  5247. SWITCHTEC_QUIRK(0x8535); /* PFX 80xG3 */
  5248. SWITCHTEC_QUIRK(0x8536); /* PFX 96xG3 */
  5249. SWITCHTEC_QUIRK(0x8541); /* PSX 24xG3 */
  5250. SWITCHTEC_QUIRK(0x8542); /* PSX 32xG3 */
  5251. SWITCHTEC_QUIRK(0x8543); /* PSX 48xG3 */
  5252. SWITCHTEC_QUIRK(0x8544); /* PSX 64xG3 */
  5253. SWITCHTEC_QUIRK(0x8545); /* PSX 80xG3 */
  5254. SWITCHTEC_QUIRK(0x8546); /* PSX 96xG3 */
  5255. SWITCHTEC_QUIRK(0x8551); /* PAX 24XG3 */
  5256. SWITCHTEC_QUIRK(0x8552); /* PAX 32XG3 */
  5257. SWITCHTEC_QUIRK(0x8553); /* PAX 48XG3 */
  5258. SWITCHTEC_QUIRK(0x8554); /* PAX 64XG3 */
  5259. SWITCHTEC_QUIRK(0x8555); /* PAX 80XG3 */
  5260. SWITCHTEC_QUIRK(0x8556); /* PAX 96XG3 */
  5261. SWITCHTEC_QUIRK(0x8561); /* PFXL 24XG3 */
  5262. SWITCHTEC_QUIRK(0x8562); /* PFXL 32XG3 */
  5263. SWITCHTEC_QUIRK(0x8563); /* PFXL 48XG3 */
  5264. SWITCHTEC_QUIRK(0x8564); /* PFXL 64XG3 */
  5265. SWITCHTEC_QUIRK(0x8565); /* PFXL 80XG3 */
  5266. SWITCHTEC_QUIRK(0x8566); /* PFXL 96XG3 */
  5267. SWITCHTEC_QUIRK(0x8571); /* PFXI 24XG3 */
  5268. SWITCHTEC_QUIRK(0x8572); /* PFXI 32XG3 */
  5269. SWITCHTEC_QUIRK(0x8573); /* PFXI 48XG3 */
  5270. SWITCHTEC_QUIRK(0x8574); /* PFXI 64XG3 */
  5271. SWITCHTEC_QUIRK(0x8575); /* PFXI 80XG3 */
  5272. SWITCHTEC_QUIRK(0x8576); /* PFXI 96XG3 */
  5273. SWITCHTEC_QUIRK(0x4000); /* PFX 100XG4 */
  5274. SWITCHTEC_QUIRK(0x4084); /* PFX 84XG4 */
  5275. SWITCHTEC_QUIRK(0x4068); /* PFX 68XG4 */
  5276. SWITCHTEC_QUIRK(0x4052); /* PFX 52XG4 */
  5277. SWITCHTEC_QUIRK(0x4036); /* PFX 36XG4 */
  5278. SWITCHTEC_QUIRK(0x4028); /* PFX 28XG4 */
  5279. SWITCHTEC_QUIRK(0x4100); /* PSX 100XG4 */
  5280. SWITCHTEC_QUIRK(0x4184); /* PSX 84XG4 */
  5281. SWITCHTEC_QUIRK(0x4168); /* PSX 68XG4 */
  5282. SWITCHTEC_QUIRK(0x4152); /* PSX 52XG4 */
  5283. SWITCHTEC_QUIRK(0x4136); /* PSX 36XG4 */
  5284. SWITCHTEC_QUIRK(0x4128); /* PSX 28XG4 */
  5285. SWITCHTEC_QUIRK(0x4200); /* PAX 100XG4 */
  5286. SWITCHTEC_QUIRK(0x4284); /* PAX 84XG4 */
  5287. SWITCHTEC_QUIRK(0x4268); /* PAX 68XG4 */
  5288. SWITCHTEC_QUIRK(0x4252); /* PAX 52XG4 */
  5289. SWITCHTEC_QUIRK(0x4236); /* PAX 36XG4 */
  5290. SWITCHTEC_QUIRK(0x4228); /* PAX 28XG4 */
  5291. SWITCHTEC_QUIRK(0x4352); /* PFXA 52XG4 */
  5292. SWITCHTEC_QUIRK(0x4336); /* PFXA 36XG4 */
  5293. SWITCHTEC_QUIRK(0x4328); /* PFXA 28XG4 */
  5294. SWITCHTEC_QUIRK(0x4452); /* PSXA 52XG4 */
  5295. SWITCHTEC_QUIRK(0x4436); /* PSXA 36XG4 */
  5296. SWITCHTEC_QUIRK(0x4428); /* PSXA 28XG4 */
  5297. SWITCHTEC_QUIRK(0x4552); /* PAXA 52XG4 */
  5298. SWITCHTEC_QUIRK(0x4536); /* PAXA 36XG4 */
  5299. SWITCHTEC_QUIRK(0x4528); /* PAXA 28XG4 */
  5300. SWITCHTEC_QUIRK(0x5000); /* PFX 100XG5 */
  5301. SWITCHTEC_QUIRK(0x5084); /* PFX 84XG5 */
  5302. SWITCHTEC_QUIRK(0x5068); /* PFX 68XG5 */
  5303. SWITCHTEC_QUIRK(0x5052); /* PFX 52XG5 */
  5304. SWITCHTEC_QUIRK(0x5036); /* PFX 36XG5 */
  5305. SWITCHTEC_QUIRK(0x5028); /* PFX 28XG5 */
  5306. SWITCHTEC_QUIRK(0x5100); /* PSX 100XG5 */
  5307. SWITCHTEC_QUIRK(0x5184); /* PSX 84XG5 */
  5308. SWITCHTEC_QUIRK(0x5168); /* PSX 68XG5 */
  5309. SWITCHTEC_QUIRK(0x5152); /* PSX 52XG5 */
  5310. SWITCHTEC_QUIRK(0x5136); /* PSX 36XG5 */
  5311. SWITCHTEC_QUIRK(0x5128); /* PSX 28XG5 */
  5312. SWITCHTEC_QUIRK(0x5200); /* PAX 100XG5 */
  5313. SWITCHTEC_QUIRK(0x5284); /* PAX 84XG5 */
  5314. SWITCHTEC_QUIRK(0x5268); /* PAX 68XG5 */
  5315. SWITCHTEC_QUIRK(0x5252); /* PAX 52XG5 */
  5316. SWITCHTEC_QUIRK(0x5236); /* PAX 36XG5 */
  5317. SWITCHTEC_QUIRK(0x5228); /* PAX 28XG5 */
  5318. SWITCHTEC_QUIRK(0x5300); /* PFXA 100XG5 */
  5319. SWITCHTEC_QUIRK(0x5384); /* PFXA 84XG5 */
  5320. SWITCHTEC_QUIRK(0x5368); /* PFXA 68XG5 */
  5321. SWITCHTEC_QUIRK(0x5352); /* PFXA 52XG5 */
  5322. SWITCHTEC_QUIRK(0x5336); /* PFXA 36XG5 */
  5323. SWITCHTEC_QUIRK(0x5328); /* PFXA 28XG5 */
  5324. SWITCHTEC_QUIRK(0x5400); /* PSXA 100XG5 */
  5325. SWITCHTEC_QUIRK(0x5484); /* PSXA 84XG5 */
  5326. SWITCHTEC_QUIRK(0x5468); /* PSXA 68XG5 */
  5327. SWITCHTEC_QUIRK(0x5452); /* PSXA 52XG5 */
  5328. SWITCHTEC_QUIRK(0x5436); /* PSXA 36XG5 */
  5329. SWITCHTEC_QUIRK(0x5428); /* PSXA 28XG5 */
  5330. SWITCHTEC_QUIRK(0x5500); /* PAXA 100XG5 */
  5331. SWITCHTEC_QUIRK(0x5584); /* PAXA 84XG5 */
  5332. SWITCHTEC_QUIRK(0x5568); /* PAXA 68XG5 */
  5333. SWITCHTEC_QUIRK(0x5552); /* PAXA 52XG5 */
  5334. SWITCHTEC_QUIRK(0x5536); /* PAXA 36XG5 */
  5335. SWITCHTEC_QUIRK(0x5528); /* PAXA 28XG5 */
  5336. #define SWITCHTEC_PCI100X_QUIRK(vid) \
  5337. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_EFAR, vid, \
  5338. PCI_CLASS_BRIDGE_OTHER, 8, quirk_switchtec_ntb_dma_alias)
  5339. SWITCHTEC_PCI100X_QUIRK(0x1001); /* PCI1001XG4 */
  5340. SWITCHTEC_PCI100X_QUIRK(0x1002); /* PCI1002XG4 */
  5341. SWITCHTEC_PCI100X_QUIRK(0x1003); /* PCI1003XG4 */
  5342. SWITCHTEC_PCI100X_QUIRK(0x1004); /* PCI1004XG4 */
  5343. SWITCHTEC_PCI100X_QUIRK(0x1005); /* PCI1005XG4 */
  5344. SWITCHTEC_PCI100X_QUIRK(0x1006); /* PCI1006XG4 */
  5345. /*
  5346. * The PLX NTB uses devfn proxy IDs to move TLPs between NT endpoints.
  5347. * These IDs are used to forward responses to the originator on the other
  5348. * side of the NTB. Alias all possible IDs to the NTB to permit access when
  5349. * the IOMMU is turned on.
  5350. */
  5351. static void quirk_plx_ntb_dma_alias(struct pci_dev *pdev)
  5352. {
  5353. pci_info(pdev, "Setting PLX NTB proxy ID aliases\n");
  5354. /* PLX NTB may use all 256 devfns */
  5355. pci_add_dma_alias(pdev, 0, 256);
  5356. }
  5357. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_PLX, 0x87b0, quirk_plx_ntb_dma_alias);
  5358. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_PLX, 0x87b1, quirk_plx_ntb_dma_alias);
  5359. /*
  5360. * On Lenovo Thinkpad P50 SKUs with a Nvidia Quadro M1000M, the BIOS does
  5361. * not always reset the secondary Nvidia GPU between reboots if the system
  5362. * is configured to use Hybrid Graphics mode. This results in the GPU
  5363. * being left in whatever state it was in during the *previous* boot, which
  5364. * causes spurious interrupts from the GPU, which in turn causes us to
  5365. * disable the wrong IRQ and end up breaking the touchpad. Unsurprisingly,
  5366. * this also completely breaks nouveau.
  5367. *
  5368. * Luckily, it seems a simple reset of the Nvidia GPU brings it back to a
  5369. * clean state and fixes all these issues.
  5370. *
  5371. * When the machine is configured in Dedicated display mode, the issue
  5372. * doesn't occur. Fortunately the GPU advertises NoReset+ when in this
  5373. * mode, so we can detect that and avoid resetting it.
  5374. */
  5375. static void quirk_reset_lenovo_thinkpad_p50_nvgpu(struct pci_dev *pdev)
  5376. {
  5377. void __iomem *map;
  5378. int ret;
  5379. if (pdev->subsystem_vendor != PCI_VENDOR_ID_LENOVO ||
  5380. pdev->subsystem_device != 0x222e ||
  5381. !pci_reset_supported(pdev))
  5382. return;
  5383. if (pci_enable_device_mem(pdev))
  5384. return;
  5385. /*
  5386. * Based on nvkm_device_ctor() in
  5387. * drivers/gpu/drm/nouveau/nvkm/engine/device/base.c
  5388. */
  5389. map = pci_iomap(pdev, 0, 0x23000);
  5390. if (!map) {
  5391. pci_err(pdev, "Can't map MMIO space\n");
  5392. goto out_disable;
  5393. }
  5394. /*
  5395. * Make sure the GPU looks like it's been POSTed before resetting
  5396. * it.
  5397. */
  5398. if (ioread32(map + 0x2240c) & 0x2) {
  5399. pci_info(pdev, FW_BUG "GPU left initialized by EFI, resetting\n");
  5400. ret = pci_reset_bus(pdev);
  5401. if (ret < 0)
  5402. pci_err(pdev, "Failed to reset GPU: %d\n", ret);
  5403. }
  5404. iounmap(map);
  5405. out_disable:
  5406. pci_disable_device(pdev);
  5407. }
  5408. DECLARE_PCI_FIXUP_CLASS_FINAL(PCI_VENDOR_ID_NVIDIA, 0x13b1,
  5409. PCI_CLASS_DISPLAY_VGA, 8,
  5410. quirk_reset_lenovo_thinkpad_p50_nvgpu);
  5411. /*
  5412. * Device [1b21:2142]
  5413. * When in D0, PME# doesn't get asserted when plugging USB 3.0 device.
  5414. */
  5415. static void pci_fixup_no_d0_pme(struct pci_dev *dev)
  5416. {
  5417. pci_info(dev, "PME# does not work under D0, disabling it\n");
  5418. dev->pme_support &= ~(PCI_PM_CAP_PME_D0 >> PCI_PM_CAP_PME_SHIFT);
  5419. }
  5420. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_ASMEDIA, 0x2142, pci_fixup_no_d0_pme);
  5421. /*
  5422. * Device 12d8:0x400e [OHCI] and 12d8:0x400f [EHCI]
  5423. *
  5424. * These devices advertise PME# support in all power states but don't
  5425. * reliably assert it.
  5426. *
  5427. * These devices also advertise MSI, but documentation (PI7C9X440SL.pdf)
  5428. * says "The MSI Function is not implemented on this device" in chapters
  5429. * 7.3.27, 7.3.29-7.3.31.
  5430. */
  5431. static void pci_fixup_no_msi_no_pme(struct pci_dev *dev)
  5432. {
  5433. #ifdef CONFIG_PCI_MSI
  5434. pci_info(dev, "MSI is not implemented on this device, disabling it\n");
  5435. dev->no_msi = 1;
  5436. #endif
  5437. pci_info(dev, "PME# is unreliable, disabling it\n");
  5438. dev->pme_support = 0;
  5439. }
  5440. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_PERICOM, 0x400e, pci_fixup_no_msi_no_pme);
  5441. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_PERICOM, 0x400f, pci_fixup_no_msi_no_pme);
  5442. static void apex_pci_fixup_class(struct pci_dev *pdev)
  5443. {
  5444. pdev->class = (PCI_CLASS_SYSTEM_OTHER << 8) | pdev->class;
  5445. }
  5446. DECLARE_PCI_FIXUP_CLASS_HEADER(0x1ac1, 0x089a,
  5447. PCI_CLASS_NOT_DEFINED, 8, apex_pci_fixup_class);
  5448. /*
  5449. * Pericom PI7C9X2G404/PI7C9X2G304/PI7C9X2G303 switch erratum E5 -
  5450. * ACS P2P Request Redirect is not functional
  5451. *
  5452. * When ACS P2P Request Redirect is enabled and bandwidth is not balanced
  5453. * between upstream and downstream ports, packets are queued in an internal
  5454. * buffer until CPLD packet. The workaround is to use the switch in store and
  5455. * forward mode.
  5456. */
  5457. #define PI7C9X2Gxxx_MODE_REG 0x74
  5458. #define PI7C9X2Gxxx_STORE_FORWARD_MODE BIT(0)
  5459. static void pci_fixup_pericom_acs_store_forward(struct pci_dev *pdev)
  5460. {
  5461. struct pci_dev *upstream;
  5462. u16 val;
  5463. /* Downstream ports only */
  5464. if (pci_pcie_type(pdev) != PCI_EXP_TYPE_DOWNSTREAM)
  5465. return;
  5466. /* Check for ACS P2P Request Redirect use */
  5467. if (!pdev->acs_cap)
  5468. return;
  5469. pci_read_config_word(pdev, pdev->acs_cap + PCI_ACS_CTRL, &val);
  5470. if (!(val & PCI_ACS_RR))
  5471. return;
  5472. upstream = pci_upstream_bridge(pdev);
  5473. if (!upstream)
  5474. return;
  5475. pci_read_config_word(upstream, PI7C9X2Gxxx_MODE_REG, &val);
  5476. if (!(val & PI7C9X2Gxxx_STORE_FORWARD_MODE)) {
  5477. pci_info(upstream, "Setting PI7C9X2Gxxx store-forward mode to avoid ACS erratum\n");
  5478. pci_write_config_word(upstream, PI7C9X2Gxxx_MODE_REG, val |
  5479. PI7C9X2Gxxx_STORE_FORWARD_MODE);
  5480. }
  5481. }
  5482. /*
  5483. * Apply fixup on enable and on resume, in order to apply the fix up whenever
  5484. * ACS configuration changes or switch mode is reset
  5485. */
  5486. DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_PERICOM, 0x2404,
  5487. pci_fixup_pericom_acs_store_forward);
  5488. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_PERICOM, 0x2404,
  5489. pci_fixup_pericom_acs_store_forward);
  5490. DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_PERICOM, 0x2304,
  5491. pci_fixup_pericom_acs_store_forward);
  5492. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_PERICOM, 0x2304,
  5493. pci_fixup_pericom_acs_store_forward);
  5494. DECLARE_PCI_FIXUP_ENABLE(PCI_VENDOR_ID_PERICOM, 0x2303,
  5495. pci_fixup_pericom_acs_store_forward);
  5496. DECLARE_PCI_FIXUP_RESUME(PCI_VENDOR_ID_PERICOM, 0x2303,
  5497. pci_fixup_pericom_acs_store_forward);
  5498. static void nvidia_ion_ahci_fixup(struct pci_dev *pdev)
  5499. {
  5500. pdev->dev_flags |= PCI_DEV_FLAGS_HAS_MSI_MASKING;
  5501. }
  5502. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_NVIDIA, 0x0ab8, nvidia_ion_ahci_fixup);
  5503. static void rom_bar_overlap_defect(struct pci_dev *dev)
  5504. {
  5505. pci_info(dev, "working around ROM BAR overlap defect\n");
  5506. dev->rom_bar_overlap = 1;
  5507. }
  5508. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1533, rom_bar_overlap_defect);
  5509. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1536, rom_bar_overlap_defect);
  5510. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1537, rom_bar_overlap_defect);
  5511. DECLARE_PCI_FIXUP_EARLY(PCI_VENDOR_ID_INTEL, 0x1538, rom_bar_overlap_defect);
  5512. #ifdef CONFIG_PCIEASPM
  5513. /*
  5514. * Several Intel DG2 graphics devices advertise that they can only tolerate
  5515. * 1us latency when transitioning from L1 to L0, which may prevent ASPM L1
  5516. * from being enabled. But in fact these devices can tolerate unlimited
  5517. * latency. Override their Device Capabilities value to allow ASPM L1 to
  5518. * be enabled.
  5519. */
  5520. static void aspm_l1_acceptable_latency(struct pci_dev *dev)
  5521. {
  5522. u32 l1_lat = FIELD_GET(PCI_EXP_DEVCAP_L1, dev->devcap);
  5523. if (l1_lat < 7) {
  5524. dev->devcap |= FIELD_PREP(PCI_EXP_DEVCAP_L1, 7);
  5525. pci_info(dev, "ASPM: overriding L1 acceptable latency from %#x to 0x7\n",
  5526. l1_lat);
  5527. }
  5528. }
  5529. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x4f80, aspm_l1_acceptable_latency);
  5530. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x4f81, aspm_l1_acceptable_latency);
  5531. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x4f82, aspm_l1_acceptable_latency);
  5532. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x4f83, aspm_l1_acceptable_latency);
  5533. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x4f84, aspm_l1_acceptable_latency);
  5534. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x4f85, aspm_l1_acceptable_latency);
  5535. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x4f86, aspm_l1_acceptable_latency);
  5536. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x4f87, aspm_l1_acceptable_latency);
  5537. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x4f88, aspm_l1_acceptable_latency);
  5538. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x5690, aspm_l1_acceptable_latency);
  5539. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x5691, aspm_l1_acceptable_latency);
  5540. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x5692, aspm_l1_acceptable_latency);
  5541. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x5693, aspm_l1_acceptable_latency);
  5542. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x5694, aspm_l1_acceptable_latency);
  5543. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x5695, aspm_l1_acceptable_latency);
  5544. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56a0, aspm_l1_acceptable_latency);
  5545. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56a1, aspm_l1_acceptable_latency);
  5546. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56a2, aspm_l1_acceptable_latency);
  5547. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56a3, aspm_l1_acceptable_latency);
  5548. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56a4, aspm_l1_acceptable_latency);
  5549. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56a5, aspm_l1_acceptable_latency);
  5550. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56a6, aspm_l1_acceptable_latency);
  5551. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56b0, aspm_l1_acceptable_latency);
  5552. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56b1, aspm_l1_acceptable_latency);
  5553. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56c0, aspm_l1_acceptable_latency);
  5554. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x56c1, aspm_l1_acceptable_latency);
  5555. #endif
  5556. #ifdef CONFIG_PCIE_DPC
  5557. /*
  5558. * Intel Ice Lake, Tiger Lake and Alder Lake BIOS has a bug that clears
  5559. * the DPC RP PIO Log Size of the integrated Thunderbolt PCIe Root
  5560. * Ports.
  5561. */
  5562. static void dpc_log_size(struct pci_dev *dev)
  5563. {
  5564. u16 dpc, val;
  5565. dpc = pci_find_ext_capability(dev, PCI_EXT_CAP_ID_DPC);
  5566. if (!dpc)
  5567. return;
  5568. pci_read_config_word(dev, dpc + PCI_EXP_DPC_CAP, &val);
  5569. if (!(val & PCI_EXP_DPC_CAP_RP_EXT))
  5570. return;
  5571. if (FIELD_GET(PCI_EXP_DPC_RP_PIO_LOG_SIZE, val) == 0) {
  5572. pci_info(dev, "Overriding RP PIO Log Size to 4\n");
  5573. dev->dpc_rp_log_size = 4;
  5574. }
  5575. }
  5576. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x461f, dpc_log_size);
  5577. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x462f, dpc_log_size);
  5578. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x463f, dpc_log_size);
  5579. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x466e, dpc_log_size);
  5580. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x8a1d, dpc_log_size);
  5581. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x8a1f, dpc_log_size);
  5582. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x8a21, dpc_log_size);
  5583. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x8a23, dpc_log_size);
  5584. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a23, dpc_log_size);
  5585. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a25, dpc_log_size);
  5586. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a27, dpc_log_size);
  5587. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a29, dpc_log_size);
  5588. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2b, dpc_log_size);
  5589. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2d, dpc_log_size);
  5590. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a2f, dpc_log_size);
  5591. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0x9a31, dpc_log_size);
  5592. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0xa72f, dpc_log_size);
  5593. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0xa73f, dpc_log_size);
  5594. DECLARE_PCI_FIXUP_HEADER(PCI_VENDOR_ID_INTEL, 0xa76e, dpc_log_size);
  5595. #endif
  5596. /*
  5597. * For a PCI device with multiple downstream devices, its driver may use
  5598. * a flattened device tree to describe the downstream devices.
  5599. * To overlay the flattened device tree, the PCI device and all its ancestor
  5600. * devices need to have device tree nodes on system base device tree. Thus,
  5601. * before driver probing, it might need to add a device tree node as the final
  5602. * fixup.
  5603. */
  5604. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5020, of_pci_make_dev_node);
  5605. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_XILINX, 0x5021, of_pci_make_dev_node);
  5606. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_REDHAT, 0x0005, of_pci_make_dev_node);
  5607. /*
  5608. * Devices known to require a longer delay before first config space access
  5609. * after reset recovery or resume from D3cold:
  5610. *
  5611. * VideoPropulsion (aka Genroco) Torrent QN16e MPEG QAM Modulator
  5612. */
  5613. static void pci_fixup_d3cold_delay_1sec(struct pci_dev *pdev)
  5614. {
  5615. pdev->d3cold_delay = 1000;
  5616. }
  5617. DECLARE_PCI_FIXUP_FINAL(0x5555, 0x0004, pci_fixup_d3cold_delay_1sec);
  5618. #ifdef CONFIG_PCIEAER
  5619. static void pci_mask_replay_timer_timeout(struct pci_dev *pdev)
  5620. {
  5621. struct pci_dev *parent = pci_upstream_bridge(pdev);
  5622. u32 val;
  5623. if (!parent || !parent->aer_cap)
  5624. return;
  5625. pci_info(parent, "mask Replay Timer Timeout Correctable Errors due to %s hardware defect",
  5626. pci_name(pdev));
  5627. pci_read_config_dword(parent, parent->aer_cap + PCI_ERR_COR_MASK, &val);
  5628. val |= PCI_ERR_COR_REP_TIMER;
  5629. pci_write_config_dword(parent, parent->aer_cap + PCI_ERR_COR_MASK, val);
  5630. }
  5631. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_GLI, 0x9750, pci_mask_replay_timer_timeout);
  5632. DECLARE_PCI_FIXUP_FINAL(PCI_VENDOR_ID_GLI, 0x9755, pci_mask_replay_timer_timeout);
  5633. #endif