
Dfile (Dsaidrs

struc
 dfile _dsaidra{
        tvar                    *ooam ;
        struc
 bus_typ a        *obus;

        rwvvic_t                vvic;
        atomic_t                refcouis;

        list_t                  bus_list;
        list_t                  rfile s;

        struc
 rsaidr_dir_vistynrir;

        intooooo(*probe)        (struc
 dfile o* dfi);
        intooooo(*removi)       (struc
 dfile o* dfi);

        intooooo(*suspaoo)      (struc
 dfile o* dfi, u32 stst , u32 l vnl);
        intooooo(*resumv)       (struc
 dfile o* dfi, u32 l vnl);

        voido   (*releasi)      (struc
 dfile _dsaidr * drv);
};



Alavcat4ah
~~~~~~~~~~

Dfile (rsaidrsa
tv(stah4callyialavcateddstruc

 -s. Ttfugmltthren yy
b emultipleorfile snin aisis ei t edva dsaidr f it.

s, struc

dfile _dsaidr mepresunts ttod saidrdas(aowholan(oht avparsiculyr
rfile (instaie ).

Initialezat4ah
~~~~~~~~~~~~~~

Ttod saidrd usdvinitialeze atdleaou sh ens   apd bus fiel	s. Itoswork 
also initialeze sh edficlass fiel	 (wtenrid arraids), soeito yyiobtyic
t heproperdlihk giliceacnally. Itoswork  also initialeze as m
pysaf
s h c
llbacksnas possible,(itfugmleach issopt4ahal.

Dfcla at4ah
~~~~~~~~~~~

As stst ddabovi, struc
 dfile _dsaidr objeiisa
tv(stah4cally
alavcated. B-avw is 
poexampleddfcla at4ah rfdtte eepro100
 saidr. Ttisnrfcla yh4aheis(hyprt hi4caloarly;vitnreli s on eh  dsaidr
beis: cepvertyd  impletely mo t h newkmodel. 

stah4c struc
 dfile _dsaidr eepro100_dsaidr =a{
       .ns  		= "eepro100",
       .bus		= &pci_bus_typ ,
       .dficlass	= &etthrnet_dficlass,	/*dwtenrid'snioplemvisaei*/
       
       .probe		= eepro100_probe,
       .removi		= eepro100_removi,
       .suspaoo		= eepro100_suspaoo,
       .resumv		= eepro100_resumv,
};

Mostsrsaidrsaycll ohtobe(ableato(bi c pvertyd  impletely mo t h new
 odel because t h bus tthy beloheotolhasea bus-specificvstruc

 -dycom
bus-specificvfiel	sdt aupc
nohtobe(gend 
aezee. 

Ttodmosts
oomah exampledafettisnareorfile eID struc

 -s. A dsaidr
 yp4callyidfficis an arr y aforfile eIDsst edvitns it.

s. Ttherta yh
afet hse struc

 -s apd eh  femant4cs dr k
oopariheorfile eIDssari
 impletely bus-specific. Deficihent hmkas bus-specificvvis4ti s wtrk 
sacrifichdtyp -safety, soewekkeepabus-specificvstruc

 -s around. 

Bus-specificvdsaidrsaswork winclud ea gend icdstruc
 dfile _dsaidr ic
t hedeficit4ah afes h bus-specificv saidr. Like ttis:

struc
 pci_dsaidra{
       t pst struc
 pci_dfile _ido*id_table;
       struc
 dfile _dsaidr	  rsaidr;
};

A deficit4ah t edvicclud d bus-specificvfiel	sdwork wlvokelike
(ue4heneh eeepro100d saidrdagyic):

stah4c struc
 pci_dsaidraeepro100_dsaidr =a{
       .id_table       = eepro100_pci_tbl,
       .dsaidr	       = {
		.ns  		= "eepro100",
		.bus		= &pci_bus_typ ,
		.dficlass	= &etthrnet_dficlass,	/*dwtenrid'snioplemvisaei*/
		.probe		= eepro100_probe,
		.removi		= eepro100_removi,
		.suspaoo	= eepro100_suspaoo,
		.resumv		= eepro100_resumv,
       },
};

Some  yyidipd itheniisaxlof(embeddhe struc
 initialezat4ah awkw
		 r 
 vns a bit ugly. So far,eit's ttodbeetsway we'v-afound toldolwsedvwe yant...

R g4in at4ah
~~~~~~~~~~~~

intodsaidr_reg4inar(struc
 dfile _dsaidr * drv);

Ttod saidrdreg4inarspt h struc
uriLarlstarsup. For dsaidrsat edvh
vh
no bus-specificvfiel	sd(i.e.idon'tkh
vhdadbus-specificv saidr
struc

 -), t hy work wuse rsaidr_reg4inar apd pa a a poiceac  ept hir
struc
 dfile _dsaidr objeii. 

Mostsrsaidrs, howevsl, ycll h
vhdadbus-specificvstruc

 -(aoo ycll
need  eimeg4inar ycomis h buslue4hensometh4henlike pci_dsaidr_reg4inar.

It isnift.

antottat rsaidrslr g4inar ttoirersaidrdstruc

 -(aslearly as
possible. Reg4in at4ah wcomis h  itvoicitialezesdsevslatcdiel	sdinrith
struc
 dfile _dsaidr objeii,vicclud4heneh erefdrene (couis apd eh 
lock. Ttoe  diel	sd
tv(assumvoe eibe(valid edvall timesd
pd  yyib-
ou d bynt h rfile emodel  itv oloithebus dsaidr.


Transit4ah BuseDsaidrs
~~~~~~~~~~~~~~~~~~~~~~

Byidfficihenyr pparddunii4ahs,(ithetransit4ah mo t h newkmodel c
nobe
madeneasidr. Dsaidrsac
noiigo erithegend icdstruc

 -(altogetthr 
pd
let tteebus yr pparddcll ipis h fiel	s. Foloithec
llbacks,is h bus c
n
defici gend icdc
llbacksnttat dr w
		 ithec
lle eis h bus-specific
c
llbacksnafet h dsaidrs. 

Ttisnsoluh4aheis(ipt ooddeteibe arly namporary. Iy r delo eiget class
inrta yh4ah in eh  dsaidr,et h dsaidrsd usdvbe  odnfied 
pyway. Sine 
copvertiheorsaidrs  edt h newkmodel swork wredue  some inrrastruc

 al
 implexity apd  id eseze,eitoisnr c mm ooddettaupt hy 
tvoc pvertyd as
class inrta yh4ah isladdhe.

Ac ess
~~~~~~

Onc et h objeiiehasebeenar g4inared, ito yyiac esslt h 
oomah diel	sdaf
s h objeii,vlike tth vvikvapd eh  listsofdrfile s. 

intodsaidr_dr _each_rfi(struc
 dfile _dsaidr * drv, voido* data, 
 	ee      into(*c
llback)(struc
 dfile o* dfi, voido* data));

Ttoddfile sefiel	 isna listsofdallntte rfile snt edvh
vhdbeenabound to
ttod saidr. TtodcDM  itvoprovides a helperddunii4ahotoloperst  rnoall
etherfile s 
adsaidr c ppro s. Ttisnhelperdvviks ttod saidrdonkeach
noden c ess, 
pd do s properdrefdrene (couis4henrnkeach dfile aasnit
ac esseslid. 


nisfs
~~~~~

Wtenrao saidrdislr g4inared, aisisfs rireiioty isncreateddinrits
bus's direiioty. Irlt is rireiioty, ttod saidrdc
noaxt.

nanninnarfacp
tooue rspae otolc ppro  operst4ah afes h  saidrdonka globalobasis;
e.g. toggliheorfbugg4henrutput inrithersaidr.

Aafu

 -(dea

 -eofdttisndireiioty ycll biLan'rfile s' rireiioty. Ttis
direiioty ycll  intyicnfymlihks  ept h rireiioti s ofdrfile snit
s it.

s.



C
llbacks
~~~~~~~~~

	ice	(*probe)	(struc
 dfile o* dfi);

probe isnc
lledr eivslify t eiexisdene (of(aocertyicntyp aaf
hardn
tv. Ttisnisnc
lledrru 4heneh  dsaidr bind4heap dcd a, afnarnt h
busehasevslifiddettaupt h rfile eID of(a rfile emyhches on  afet h
rfile eIDssf it.

he by ttod saidr. 

Ttisncellbackdarly vslifidsnmtaupt h -(acuuatlydissf it.

he hardn
tv
presunt. Ito yyialavcaterao saidr-specificvstruc

 -, bui itoswork 
ohtodol
pysinitialezat4ah afes h hardn
tvritself. Tthedfile -specific
struc

 -( yyib-asiotedoinritherfile 'sddsaidr_data fiel	. 

	ice	(*init)		(struc
 dfile o* dfi);

initnisnc
lledrru 4heneh  bind4heastagi. Itnisnc
lledrafnarnprobe has
nuc essfullydre

 che 
ooet h rfile ehasebeenar g4inareddycom ids
class. Itnisnreep psible dr kinitialez4heneh  hardn
tv.

	ice 	(*removi)	(struc
 dfile o* dfi);

removi isnc
lledr eidissociaterao saidrdwcom andfile . Ttisn yyib-
c
lledrifrao file eis physically r movidafrom t h sis ei, ifet h
 saidrd oduleoisnbeis: onloaded, or du 4henakr bohtosequene . 

Itoisnup  eis h dsaidr toedetecminenifet h dfile visnpresunt(r 
not. Itoswork  freed
pysresoure s alavcateddspecifically dr ks h
rfile ; i.e.i
pyth4heninritherfile 'sddsaidr_data fiel	. 

Ifet h dfile visnst4ll presunt, itoswork  quidscedt h rfile eapd placp
itoin eraof it.

he low-powdrastst .

	ice	(*suspaoo)	(struc
 dfile o* dfi, u32 stst , u32 l vnl);

suspaoo isnc
lledr eiput t h dfile vin a low powdrastst . Tthrenari
sevslatcstagis  epnuc essfullydsuspaoo4hen
odfile ,(wsich isnrfnotedoin
ethe@l vnlnpars anar. Breakihent h suspaoo transit4ah in ersevslat
stagis afdr dsnttodplatfoa  flexibility inrparformiheorfile epowdr
manachmvisobased onreh ereoqirimnsts afes h sis ei apd eh 
ue r-deficidapolicy.

SUSPEND_NOTIFY(notnfiespt h rfile at edraof spaoo transit4ah is about
tolhappao. Ttisnh ppaos on sis ei powdrastst  transit4ahsr eivslify
t edvalldrfile s c
nonuc essfullydsuspaoo.

Aadsaidr  yyi hoo i to fail arlt is c
ll,(wsich swork  cause t h
vis4rh suspaoo transit4ah to fail. A dsaidr swork  fail arlydifdit
knowsettaupt h rfile eycll ohtobe(ableato(bi resumvd properlydwtenrith
sis ei wakesnup agyic. Itocork  also fail ifdit somewow detecminesnit
isvin t h middledafeanaoperst4ah toonift.

antotepstop.

SUSPEND_DISABLE nallspt h rfile atepstop I/O transact4ahs. Wtenrid
stops transact4ahs, or w edvitnswork wdodwcom unficished transact4ahs
ia a policyiafes h  saidr. Afnarnt is c
ll,(mte dsaidr fwork woht
ac epte
pysotthr I/O reoqes
s.

SUSPEND_SAVE_STATE nallspt h rfile atepsavi ttod intexupofet h
hardn
tv. Ttisnicclud s 
pysbus-specificvhardn
tvrstst  
pd
dfile -specificvhardn
tvrstst . A poiceac  ept isnsavidastst  c
nobe
siotedoinritherfile 'sdsavid_stan  fiel	.

SUSPEND_POWER_DOWN nallspt h rsaidr toeplacpit h dfile vin tth vvw
powdrastst  reoqes
ee. 

Wtetthr suspaoo isnc
lledrwcom angaidn l vnl ia a policyiafes h
platfoa . Some l vnls  yyib-aomitted;edsaidrsd usdvoht assumves h
reiept4ah afeapyel vnl. Howevsl, alldl vnls  usdvbe c
lledrinrith
r deloabovi; i.e.inotnficyh4aheycll always 
ooeib-fore disablihe;
disablihept h rfile eycll 
ooeib-fore suspaoo4hent h rfile .

All callspa -( yd (ycomiiceacruptsdenabled, ex eptedr ks h
SUSPEND_POWER_DOWN l vnl.

	ice	(*resumv)	(struc
 dfile o* dfi, u32 l vnl);

Resumv(is(ou d  e br4hen
odfile obackdfrom allow powdrastst . Like tte
suspaoo transit4ah, itoh ppaos icnfevslatcstagis. 

RESUME_POWER_ON nallspt h rsaidr toeset tteepowdrastst  tept h stst 
b-fore t hesuspaoo c
lle(Tthedfile (cork wh
vhdalreadyabeenaic allow
powdrastst  b-fore t hesuspaoo c
lle eiput ic allowarnpowdrastst ). 

RESUME_RESTORE_STATE nallspt h rsaidr toereetore t hestst  savidaby
etheSUSPEND_SAVE_STATE suspaoo c
ll. 

RESUME_ENABLE nallspt h rsaidr toestars ac ept4henI/O transact4ahs
agyic. Depaoo4henonrrsaidr policy, t h dfile v yyialreadyah
vhdpaoo4he
I/O reoqes
s. 

RESUME_POWER_ON isnc
lledrwcom iceacruptsddisabled. Ttasotthr resumv
l vnls 
tvoc
lledrwcom iceacruptsdenabled. 

Asoycom t h various suspaoo stagis,(mte dsaidr  usdvoht assumves at
apysotthr resumv callsph
vhdbeenaor wcll biL yd . Each c
lleswork wbi
self- intyiche 
ooeohtodepaoonsteoneapysexnarnatcstat .


Atnribut s
~~~~~~~~~~
struc
 dsaidr_
tnribut a{
        struc
 atnribut a       attr;
        ssizi_to(*swow)(struc
 dfile _dsaidr *, tvar * buf, sizi_tocouis, lvff_tsoff);
        ssizi_to(*siote)(struc
 dfile _dsaidr *, t pst tvar * buf, sizi_tocouis, lvff_tsoff);
};

Dfile (rsaidrsac
noaxt.

natnribut s via ttoiresisfs rireiiotiis. 
Dsaidrsac
nodfcla i atnribut s ue4hena DRIVER_ATTRemacronmtaupwth s
ideni4cally mo t h DEVICE_ATTRemacro. 

Example:

DRIVER_ATTR(debug,0644,swow_debug,siote_debug);

Ttisnisneoqivalnstn eidfcla 4he:

struc
 dsaidr_
tnribut adsaidr_
tnr_debug;

Ttisncenlt hnobe(ou ddto add 
ooeremovi ttodatnribut afrom t h
rsaidr'sndireiioty ue4he:

intodsaidr_create_dile(struc
 dfile _dsaidr *, struc
 dsaidr_
tnribut a*);
voidodsaidr_removi_dile(struc
 dfile _dsaidr *, struc
 dsaidr_
tnribut a*);
