WWDC2000 Session 203

Transcript

Kind: captions Language: en whenever a transition occurs like like we had one about two years ago in terms of i/o from USB to USB and firewire that always causes some heartache for customers for developers because you've got to do some work for Apple because we have to do all this work to to get it out there that also gives rise to great opportunities and and we think that the people who really grab this on are the ones that are ventually successful so here's again here again Apple is presenting you with another opportunity to write drivers from Mac os10 because all the customers that now start upgrading to Mac os10 in the next year are going to need peripherals with the appropriate drivers to make sure that it works and I think the people the developers that really give them these drivers will be the one eventually that come out on top so we're presenting you with an opportunity here to get into details of Mac OS 10 and writing drivers by the way this session is entirely devoted to writing ten drivers I'd like to welcome William Cullen William is the tech lead for mac OS 10 and in fact he's the one who's been doing all this hard work to make sure that can fire wire in BP for works really well well thanks Mike good afternoon I'm going to be talking to you about as a set how to write drivers for 0 sin Phi Y drivers I'm also want to go briefly what is in BP for what's in the CD that that you have now what will be in the air is 10 public beta let me relieve that so that falls it's talking to you a bit about the things that we haven't done yet the things aren't in PP for and give you some pointers to the kind of things that might change in the future really want to make sure that you have the basic idea of how you're going to start writing firewire drivers and echo x10 explain briefly how driver matching works so we can make sure that that your driver gets loaded for your device not for some else's device and start running and do the right things I'm also showing you here where were you able to find the SDK that isn't actually you don't have an XP k ready for you yet but if you check this URL will be sure to point out where you can get it and of course really important the fire code is open source it's part of Darwin if you get the right device driver please sign up for Darwin get get the source use the source Luke it's a lot easier if you can see how we're doing things see how you should do things as well ok so how does how things work the firewire drivers in oh it's 10 the use iokit I based the code on the OS 9 architecture this lead to call the source code over to 10 then converted it to fit into I ok it's where did you see pops class which made a lot of things much easier for me in d before it's implemented as a set of kernel extensions that are loaded up when a driver needs to fire wire services there's three main kernel extensions for fire in DP for the i/o flywire family docx this is the core of firewire it's where it's the codifies all the basic services of fire hardware independent for everything then we have two drivers for the two different types of flight controller chips that we've used at Apple in our various computers Apple Inc X is the driver for the texas instruments pti links controller chip that's the controller chip is used in the gloom white 33 and also in the pci pci apple cart that we also i think still sell kind of obsolete but available I think finally Apple SW Oh XVI the driver for the PCI ohci file I standard all our current machines that have firewire built in they're all using versions of its open standard for this driver is for all the current machine okay so so what's in DP for driver matching and loading is all done mouse for x y devices so if you if you have a driver for your device and use with me correctly this should hold on i'll do yet let's hope you'll be freaking out to be fork and load drivers the right devices get and running so the core services for the firewire are pretty nearly complete you can do most of the things you need to do is file ir of sending packages heating packets allocating address spaces which what the writers on the bar spending our fast things are what the bus topology is all that kind of useful stuff that you need to do the apple inc's driver is complete it handles everything that i believe it needs to handle I probably ought to the bugs but shows that the skylight yoicks see I controller is not too far along you exploded on a bit later newer new machines as the asynchronous packet handling is all complete but the isochronous like at handling isn't done yet which kind of means you can't do pv development example using a no api controller so you need to get a link cards apps were doing that we also threw in a prototype for file itís driver that we wrote to make sure that the core services have all been right right thing and sure we had all these interaction with our kits and the file system all sorted out and done correctly well quite sure whether we should be shipping a generic destroyer in the future we put anybody before because long have any other drivers so we're going to have so if you have opinions about that perhaps you give feedback to JS file i/o at apple com whether we should have a driver tonight driver or just do what we didn't know it's nine of leaving the driver for each discipline it's accurate to do themselves based on code we provide of them the bossing MVP floorings well might envy people we don't have any documentation yet written for for the swat flies in DB for sort of a 10 we don't even have very good header documentation yet so that's kind of something that bear in mind again sign up sort of the darwin get the people source and you can figure out what we're doing for the public visa of course we will be adding most of the things that you'd expect risk for complete information will be splitting apart the described earlier oath into the SUV sync services that's generic for a few devices and a separate hardest driver or leave it out completely depending on how we decide to do that that's in apps something oh it's 9 has you have separate service efficiency services for all the devices that use that standard we're also after I the SVP services that are used by DV camcorders an mram kind of stuff will be of course providing a DV driver just as you do in micro s9 and also protocol drive driver support of lysis started working on fire hours and quite sure what is what protocol drivers were so I didn't instrument of the first it's a fini the thing you remember about firewire is that fire is the bus it's a peer-to-peer you can connect tipple Macintoshes together and they can talk to each other protocol drivers a way of setting things up so each Mac knows what services other max would provide it for providing because they've had a driver loaded to match them tort suits I'm also going to be improving the I should really take config Ron services selectmen CSR because that's what they call them a current source code services to read the configuration rom from a device services to add stuff to the macintosh config rom for other devices to read so that they know what services the max can do for them we'll also be adding booting from fire dis drive that's one of the things that isn't in 10 you have a destroyer but we can't boot from it and build anessa caves will document it fun is looking a bit beyond the Republic visa and I'm line getting a bit bit vague enough we want to provide a DC services for in the same way that we do festively too because in the past I've only being camcorders that seeded the ABC News ABC protocol in the future camcorders again Phil but also in LAN audio devices and AV hard disk now all those three different kind of devices they all a based on the ABC standards so we want to provide services to do that so you can then build on for double devices we're going to try em lam support of course if you so we'll demo yesterday that looks pretty exciting the huge bandwidth available for audio hundreds of channels for the pro guys it's a straight to them and it's also going to be nice for home home theater stuff it's less able is great power management also is not be before and probably won't be in the public Peter either really that's most important for powerbook that like to control tower and all our machine so when is fire fire lights why our drivers fitting for the whole big picture of Mac OS 10 well is just a little tiny box down in the bottom corner underneath iokit notice that there's a dotted line it goes across and then up separating the maternal and I okay it from rest of the colonel that little right hand side kind of the upper side implies that a an adequate driver can actually get provide services straits applications that can go through BS e or networking or the file system if that makes sense for your kind of device which is often the case for fly devices because a lot of the really fun stuff camcorders again cameras and lan and so on are the kind of things that good old-fashioned unix isn't retail be interested in and the colonel just doesn't honor he's know about it put them up into application okay so i want to go so here is show you how i like it goes through the process of getting a driver running when your device is connected to the mac initially when the machine starts up i hope it will look to all the hardware that's on the nap motherboard and it'll find a file a controller of some kind it allowed to be the apple links when we say the links for ppi controller or the one of many ohci controllers so the air cute matching system will then lowes hyperlinks or ohci as appropriate Apple Inc's and ohci are subclasses of hi-fi our controller which remember is the into the corrals the fire services system that sells a subclass from I'll file but I have firewire bus which is a great abstract view of the fire so first thing happens you plug your device in that will cause a battery set will go and scan the bus find that there's a vise sword is a device now and we like it then create a standard objects for communicating with firewire devices which week allow so I device pretty logical it in turn will then look at the device read it's configs rom and see what unit directories are in the wrong the unit directories aware firewire devices will be store information on what kind of device it is who makes this kind of information that you need so for each unit directory that we find the file I device object finds in the device we create the file I unit object again kind of objects as we create to represent the unit directory now who gets kind of more interesting yeah okay matching system now looks at the entries in the units directory figures out what kind of unit it is and a little bit of luck it's a device that fits a driver's been installed for an out point will load up your driver attach it to the firewire unit and then your drivers can start running talk to the device and got it does its thing for example if it was a hard disk your driver would then have to tell the aisle kits file system services but it's a hard disk partitions and so on and the file system will then pick up to it and start reading writing sexist I was going to go into my feet about how fast this entitilitus it works there's a session tomorrow that will really go into that and great detail okay Doug another device in of course we create another file I device object at that one mouth again we look unit director ease and create a unit by unit objects three threats even fine perhaps you find tuna directories because it's some kind of multifunctional device we can actually think of an example of one except for a Macintosh Maddox automatic Macintosh she had several protocol drivers lowliest perhaps em LAN driver maybe an IP driver then they would have unit directory speak to those protocol drivers and other max on the Nets work on the bus feeding that max rom would create a unit object for each of those units so that the right device trailer can be matched up with each unit I've got one in grey dimming because we're going to concentrate on one side again the appropriate driver is found loaded starts running now suppose this is a device that doesn't communicate with the rest of the colonel perhaps it's a camcorder it's a scanner it's a printer something that applications whether the top when you want to talk to so that's the colonel isn't want to talk to I ok provides services for applications outside the terminal you get notified of kinds of devices that they're interested in appearing inside the colonel and when they see that they can then go and find a core foundation plug in to represent that device outside the colonel the plug in then have to ask the unit driver inside the colonel to create what we call our user client which is a internal object that provides services to get cross the colonel boundary between the plugin outside the terminal and unit driver inside the colonel so I just highlighted the pieces that you would need to write for two kinds of devices on the right something like a hard disk it's pretty straightforward you write a device driver inside the colonel gets loaded it talks the file system and essentially you have one object to worry about if you're doing a device the right size for a device that you'd like to ride direct access to applications outside the colonel I think standing thinking for you need to do a little bit more work you need to write your internal right driver you also need to write piece of extra code so you declined to cross the colonel boundary and you almost certainly want to write a coronation plug-in outside the kernel for any application that wants to talk to your device to go through you probably shouldn't directly you could directly from applications go to the user climb inside the colonel but its architectural form is certainly going to be better for you and for everybody to have a plug-in a plenty of the life rather than building people applications one thing that we have to do for the public pizza that I invention was make its left hand side threes three-stage seeing a little easier by providing our own unit driver and user client inside the kernel that you can plug in to say i want the standard one I don't know anything I mean it's certainly any special high-performance communication I can stick with the service we provide which should be pretty fast anyway I think absolutely fine for scanners printers probably m lambda Michael's as well maybe okay so as I mentioned earlier the firewire controller is the heart of the firewire family it does most of the hardware independent works that it needs to be done to get far why are up and running and get your device is going be able talk two devices much light as you have these other devices there are bus management it does address space management inside the Mac that's where you have you want to have firewire addresses inside the map your device can talk to to send status kind of things of course glad I controller provides methods for transmitting and receiving packets those asynchronous am I talk honest if you're writing a protocol driver where you're making the max perform a service for people other devices on the bus then your critical driver will match the flight controller because that'll that's what provides services it needs to change the update see macintosh rom and Alex address space as I mentioned earlier Apple Inc's and I oh wo XVI varies the harbor drivers access the Macintosh Hardware there are subclasses of Iowa i/o controller that implements the actual hardware registered actually necessary to send packets see transmits packets handling truck silhouette hardware stuff biostar why device 1 the device in the bar this is the object that handles some of the fiddly bits about firewire that we really really don't want to have to bother with it tracks the note idea of your device and whence the bus reset and noo tidies of writers can change but you still have the same file I device to talk to it'll just and certainly no thats note ideas changed when it sends a pectus these packets over the bus for matching of flour why device if your device driver wants to do that we only provide two very basic pieces information the vendor ID of the device and the goo is the globally unique ID of the device neither of those really are terribly useful for matching their either by the general vendor ID and every device to make whatever kind of videos can have the same vendor ID oh it's incredibly specific utu ideas let me a driver for that one device an entire universe which probably isn't sells a useful hello there could be uses there was a question in eric erickson JS presentation yesterday where some of our thing about i have having tender 10 Macintoshes network tech together with a firewire and he had a firewire hard disks that he wanted 20 mount on one lakh now one way of doing that at least now it's 10 might be to use the gilead of the disk drive and have a driver that only matches that one disk drives and have that driver only on one of the Macintoshes the others will match the drives who's got the wrong do et tu ID the max that you want to use the drive will match it because it has like dat but that's pretty esoteric really the main job of the firewire device object is to look at the device was wrong pick out all unit director ease and create publish I love sci-fi our units creature those direct directories for dry it your own drivers to match arm so I Oh fire unit said one penis rectory and device from typically there will only be one you know directory and the rights wrong but the spec allows for and we allow them all for flower unit we provide much more useful matching a driver can match on the unit's spec ID unit software version and also the vendor ID in tu ID which we going to brought up from the file I device is the provider for most flywire drivers for devices since it has the information on what kind of protocol the Unitec ID in software versions that the device can handle YY device to fly our unit really are only different in how they are where they fit in the IOC hierarchy and in the matching information the boats rise from iOS firewire knob which provides methods for all things you want to do with the device of sending packets to it is he packing it we see packets from it and so so can i hack it you have what's essentially likes the name registry in mac OS 9 but a lot more sophisticated and I've had fun taking bunch of that for a Flywire the main Eric its service claim we call it is the part of the iokit registry issues the matching so all the objects that I create that can be involved in matching are in that part of the packet registry for the matching functions of latakia to work on so those are I apply our controller for protocol drivers I will file I device hapless a specific device drivers I'll fly our unit for most device drivers I also implemented a second plane in registry which I use to keep track of the bus topology of firewire bus in other words which device is connected with other device physically by the cable which is useful for Sigma outlets speed you can send to it as a slow device the community fast devices then rust the fly our plane might be ways look to check us out happening and maybe you look user if you want to so this is only intended to represent the topology of the network and not the functionality for services are provided it only has the aisle flywire controller objects the so I device effect essentially was my castle itself and all the other devices that have been found on it are on the bar so now I'd like to to show you the registry in those ten in action first I'm going to bring up a very useful application that we having did before call the IRS tree Explorer it's a very simple application to shows you what's in the registry when you when it starts up its our top showing the service plane I'm going to switch the plane I'm going to display to the firewire plane so that we can see what the bus looks like right now has nothing connected to the mat right now so on a front side we see what's available there's the apple flower LTI objects the max only own internal hardware and then there's four other objects the registry service I we don't know they're always there and explain see ohci driver seemed you have a whole bunch of properties being displayed down here I'll just move it you can see if the Creta what's going on we have the node ID has a neck massage and it tells us it's a number this application is built with Coco it was stunning what's funny over it was sudden it's very simple application one of the things that we didn't do was show numbers with hex which probably makes something a little clearer we just shows normal decimal representations also keep in the registry for people to look at the self ID packets that that nose went out at the last bus reset which you might you can use to that look at these speed as the device have fee the rom of advice Dom normal escapes course of the neck and such have here some showing bit of the I ok it's matching since the ohci controller is a pci device its provider class the thing that it talks do to talk with hardware is I know pci device please kind of where you expect here I see I've match on pci class of 00 10 which i guess is is the right thing for lexi i buy more information about what kernel extensions this driver is loaded from let it from the apples swhc I extension what is more more matching information it's all a lot of stuff here for seeing how your device got matched is a good one to check week after the objects will be expects no power oops yo a TI now I pick the delights in we're going to go and look and try and find the right driver for this I just want to just my BP showing you yes this is the XML files being displayed by the XML browser for our prototype ftp to this driver as a root property the date when we last looked on it the module said it is let's say to the file it lives in it's a it's a MACO binary all executables loaded into the kernel hearty knockos don't support PSN inside the colonel here the drivers specifying that it needs to serve with firewire services to run we just going to back backwards urls to keep names unique calm to apple pie our family the device drive a lot to use our spiral family finally the personality of the driver it is serial matching information was used to load the correct driver specifies what class should be created when it's device is detected on the bus io swe ftp to HD drive it's a CD to or dis right io imports specifies what kind of objects the driver needs to directly talk to it needs socks to the smile our units to communicate if a score for matching so if we have several drivers that all match use a probe score glide over the highest protocol with one will get loaded in use finally the two pieces of information that we're going to matching this driver the unit's tech ID from the unit directory and the unit software version from the indirect tree okay so close that now I'll get in ok this dialog pops up it's being cops up by legacy Explorer application you wouldn't normally see it whatever to explore our application is done is doing is its author allocate to tell it anytime anything changes in the adequate registry and where does it asked me if I so I want to see this update sure I want to see what what's changed now we're still looking at the firewire registry plane you now house file as I file I devices of these roots of the bus so those guys being route now little arrow on the right shows that we can if over and see what elected to these guys have a trysting feature they actually have a second fire in size and for some reason that doesn't have a link doesn't have a row i can read so i represent that simply by an io registry entry and i just show what little information I have on that which is the fire information node ID and the speed of device and the self ID packet and what's down the end we have the HCI driver again so we're smell along the route because this guy's route 11 it back to finding scenic drive got mounted pretty encouraging and if i switch to the service plane track down to the firewire stuff instead of claims Apple swhc I will always be the first thing of the file airplane because it colliding services it's everybody else connected to it in the service plane is the flight of ice cream fighting the disk drive so I devices created fire units for the one unit directory inside the device I ok has looked at the unit spec ID in it software version good outlet to the extensions and so did the one we wanted the HD drive driver just driver for this guy who's then done the work acting up to this file system in this case that means creating this little driving up objects banner I oh actually drive objects let me have a media objects it's kind of goes on for a long time partition skiing couple of partitions you got a partition others drive there's a lot of objects for the file system again she needs no bad stuff is a talk tomorrow on that finally let's dismount this again okay the which application is going to change and now if i mix back down to flower again drivers feel connected things look pretty much the same so far but since the unmounted the disk from the file system the file system objects have all been cleaned up and run away see there's no right hand arrows who cares no more higher level devices in the registry anymore we unplug this it alone clean up the rest of the IQ I'm clean now that's just having the one flower OPI device driver waiting for selected to appear that surface if we a pixel my demonstration of hierarchy registry see how it works a file I fit into that how your drivers will fit in as well now i've put about the objects get created to represent how everything fits fitted together to your things you can talk to to torture device how do you actually do things how do you send packets to see packets sorting a book about in the similar way to how things are done in micro x line I have a objects call the i/o SW come on this is an absolute abject representing issuing a command to the flight hardware the base object handles all the threads blocking scheduling completion call back stuff that's needed we'll handle SMP in the future should we do such a thing I have loads of dr classes from this base class to do interesting flywire things you can do to make subclasses of ayothaya i come on are they think come on for sending and receiving suspending a synchronous asynchronous packets that over the bar and but come on for doing buck management stuff like allocating local addresses setting who zoo route is those sort of functions that of buff wide other important objects that I have is for doing isochronous transfers 3 isochronous packets are transferred over fly wire is to the sort of separate from devices there's channel that suck in those packets sent over so I have an object represent a channel that's been used for communicating have one for each of darkness channels being allocated its job is to go to expand which that channel has been configured to use make sure that after bus reset all the right register reads and writes locks are done to reserve the bandwidth again offer but reset also to handle what happens if the channel can't be reallocated notify everybody who registered interest in that channel what channel is in for things that are using the channel these other obscure object call the isochronous Paul there's a port for the transmitter on the channel and one or more for every every everything that's listings that channel each second of channel when you you create a channel in you crave sport looks like you give the ports to the channel and then once travel being configured with who's talking who's listening you can ankle methods in the channel to start and stop transmitting and it'll call each port that's configured to use it to tell that port stop listening stop spending and stuff for that if you are using isochronous transfers you'll need to find a subclass to this object that knows how to tell your device to start missing stop listening start transmitting sub transmitting maybe change the date distinct same weather and of course you also need to create if the Macintosh is going to be taking partners chuckling at Stanford you also need to create a local effects on a support to represent the data coming in and going out for the Macintosh this is the object that you give a DPL program just the same detailed programs as you may written already in mac OS 9 this object looks after those for you it compiles them feeding into the hardware start some stocks them i keeps hardware for them the nice thing about dcl is that it tells us what data is going to be transferred we can we compile it and you know which tasks the detail Paragon came from so we can pick up further on up the hardware and configure the colonel virtual memory system so that the data flowing in and out over the bus go straight to your applications it doesn't have to go into the kernel and get copied out there's lots of interrupts from passing about you get there displayed some weights right started to where it belongs without any interaction from the cpu door with the flight controller hardware which is very important for keeping up Peter rates on high speed devices like camcorders so that was 10 and the other terrifying single the colonel the colonel boundary necklace mine he has the application heat to read application in the system heat for kind of common stuff like slice drivers and they were distinct but not great of thing Colonel Colonel boundaries a bit like that better vision between application system heat but it's much more rigidly enforced boundary really need to be aware of it make sure you know how you're going to get data across that boundary ideally use services inc resides don't have to worry about too much but if you doing interesting things you may need to consider that if you remember going right back noticing two different vices think logged in should your device using the kernel extensions to control your device can you just do all your work outside of the colonel to kind of figure out the answer to that question you want to consider four main points about what your driver does what your patients expect to use the drivers do because performance you need it's a driver used by the colonel example hadas if you want your hardest to get max about a file system which is in the colonel then you need two divided a kernel driver to touch the fastest and otherwise you just don't get mounted if your drive is going to be used simultaneously by many applications of tasks running in the system then it might make sense to put it in the kernel to allow these differ applications to all access at the same time if you have maybe they use for many applications at different times like a printer print all the same time then that would be something that you would put out of the colonel even though a different times when applications music but these duffield hardware you're driving me access to the harbor in trucks in the back that's the firewire I think I've solutely can be knows because we control of the Flywire hardware because if you would drive if you're writing a the driver for a pci card from at the fitting into the firewire system then that would have to be a colonel extension because it's used by the Kurama when it's going to handle primary interrupts finally you need to synchronize between several applications that are running at the same time an example would be audio if you're mixing several audio channels together from different applications when you've all to come out together you may need to do stuff in the kernel to make sure that everything is scheduled correctly there are some examples of weddings belong a storage disk drive they belong on the colonel yes right kernel driver scanner sprinters don't belong in the kernel you really want to do it yes plugin will certainly provide ftp to services out its Colonel CTU's and I'm pretty confident we be providing even lower level flies access few outside the colonel so you can just stay out how the colonel and afterwards I kernel extensions and if thats singing a kind of device a CD RS you see you recording machines when it's being a CD drive you just a normal CD in it you want to be in the kernel so that you can fit into the file system and your users can see what's in that CD writer make sure it's the right CD the other hand when you're recording a CD your you feel like some let's look like you should be outside the colonel you have one application writing a city at a time you don't want the fastest and find the mountain CD as you write satyam that would be pretty pretty terrible so you looks like you for you end up with two drivers the kernel driver for mounting regular corded CDs and use a driver for a places like toast to talk to recording which means you have to worry about sharing make sure that two drivers don't conflict finally high performance isochronous bass clan critical applications like camcorders we have a prototype for DV camcorder driver that didn't quite make it easy for which is currently implemented inside the colonel we didn't the Colonel's who we knew it works in the colonel but it wouldn't be nice to have that nodding the Colonel's because again only one application using the camcorder at a time things on the colonel owner has very application and i'm pretty confident that using dcl we can get enough data rates through we don't really need to be in the colonel however lapse something I I need to verify safe to conclude fire in BP for is working progress it's not finished but there's a lot of functionality there you can do plenty of stuff you can certainly write slightest driver because we manage to do that open source get the source the Darwin site doesn't actually have the ftp to just drive source on it at the moment so i think we'll kind of saw that outcomes help you there the firewire family code definitely is all where I checked earlier this week keep in our out on our webpage see how we're getting on with stuff I'm sure you'll be updating as time goes on remember the architecture is like mac OS 9 supply oh I it's not the same you do have to change a code but you shouldn't need to redesign fundamentally how your driver works if you have a driver that's sort of follow the right no its nine slides rules you should find that you just go through your code look at cause you're making two to the Firefly oh I 09 move over to equivalent cause and 10 and things should be all work that's works for me if it'll work for you too of course flower Britain iokit and my code in C++ which means that call my objects that at least that Harley driver needs to be in C++ so that you can call my code so it doesn't mean to say that you have to convert all you have big company driver but about all of the extra seats people to see first class you only need to convert the pieces that interact with I ok the Clio get CM people's club actually work together quite well finally be aware of the colonel boundary if you're playing fast and loose from the system meeting application heat your driver and the applications that talk to your driver you're going to have to do bit more work you know it's 10 to get across the colonel boundary you