Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: PCIATA driver matching



Hi Ernesto,

It's probably easiest to just let IOKit do your matching and starting for you. You are on the right track with implementing your driver stack. Most PCI-ATA controller chips implement 2 ATA controllers in the chip. So the driver structure is like you created, you need some sort of driver to match the chip, do any necessary initialization, then create nubs for each bus present in the chip. At Apple, I call this the "Root" driver, so it would be called AppleXYZRoot.kext. This is usually derived from IOService and matches by name the "pci-xyz,abc" device and vendor property.

When the root driver loads it initializes the chip, extends the interrupt tree and then creates the nubs for each bus and copies down any properties needed, like addresses, interrupt numbers, bus ID and stuff. Then it calls nub->registerService() to invoke IOKit's matching. Usually, that's all it needs to do. The "nubs" are just that, attachment points and don't generally have much functional code in them.

IOKit will then look for a kext that has the necessary properties to match the nubs just registered. That should be the ones derived from IOATAController (or in your case, IOPCIATA, which in turn derives from IOATAController). At Apple, I always call this the "ATA" driver, so it would be AppleXYZATA.kext.

Your "root" driver shouldn't need to create any instances of your "ata" driver. Let IOKit do that for you.


At 10:00 PM -0800 12/22/02, email@hidden wrote:

Message: 1
Date: Sun, 22 Dec 2002 03:33:54 -0500
Subject: PCIATA driver matching
From: Ernesto Corvi <email@hidden>
To: email@hidden

I'm fudging with a ATA PCI adapter here, and there's something
regarding the IOKit ATA family that
I don't quite follow. The hardware is a 2 channel ATA/100 PCI card. So
I wrote 2 classes:

com.bleh.ata.controller derived from IOService whose requested provider
is a IOPCIDevice.
com.bleh.ata.driver derived from IOPCIATA whose requested provider is a
com.bleh.ata.controller.

The .controller class uses the standard IOPCIMatch against the
vendor/device id. Once the match
happens, it creates .driver nubs, one per channel, calls the init
function on the .driver, attaches the nub
to the .controller class, and finally calls registerService on the nub.

So far so good. The problem is that after running it, the start()
function on the .driver never happens,
as if nothing is matched against it. So I end up with a IO registry
like this:

+--- pci1234,12 <class IOPCIDevice>
{ ... }
|
+--- com.bleh.ata.controller <class com.bleh.ata.controller>
{ ... }
|
+ --- com.bleh.ata.driver <class com.bleh.ata.driver>
| { ... }
+ --- com.bleh.ata.driver <class com.bleh.ata.driver>
{ ... }

So, my question is what do I need to match the 'com.bleh.ata.driver'
against so it gets started and I get to
spawn the IOATADevice nubs? Can it be anything? What is anything? Can I
call start() directly?

Oh, one bug? I found while writing this is that when calling the init()
function on my .driver class, after
creating an instance of it with 'new', if I try to IOLog( "%s init",
getName() ); as the first piece of code on the
init() routine, it will cause a kernel panic everytime. The culprit
being getName() for some reason.

TIA,
Ernesto.

--__--__--

Message: 2
Date: Sun, 22 Dec 2002 10:54:01 -0800
Subject: Re: PCIATA driver matching
Cc: email@hidden
To: Ernesto Corvi <email@hidden>
From: Eric Brown <email@hidden>

On Sunday, December 22, 2002, at 12:33 AM, Ernesto Corvi wrote:

I'm fudging with a ATA PCI adapter here, and there's something
regarding the IOKit ATA family that
I don't quite follow. The hardware is a 2 channel ATA/100 PCI card. So
I wrote 2 classes:

com.bleh.ata.controller derived from IOService whose requested
> provider is a IOPCIDevice.
com.bleh.ata.driver derived from IOPCIATA whose requested provider is
a com.bleh.ata.controller.

The .controller class uses the standard IOPCIMatch against the
vendor/device id. Once the match
happens, it creates .driver nubs, one per channel, calls the init
function on the .driver, attaches the nub
to the .controller class, and finally calls registerService on the nub.

So far so good. The problem is that after running it, the start()
function on the .driver never happens,
as if nothing is matched against it. So I end up with a IO registry
like this:

+--- pci1234,12 <class IOPCIDevice>
{ ... }
|
+--- com.bleh.ata.controller <class com.bleh.ata.controller>
{ ... }
|
+ --- com.bleh.ata.driver <class com.bleh.ata.driver>
| { ... }
+ --- com.bleh.ata.driver <class com.bleh.ata.driver>
{ ... }

So, my question is what do I need to match the 'com.bleh.ata.driver'
against so it gets started and I get to
spawn the IOATADevice nubs? Can it be anything? What is anything? Can
I call start() directly?


It is the responsibility of the code that allocates the IOService
instance to do everything necessary to start the driver (i.e. init(),
attach(), start()). So if you depend on IOKit matching to create your
driver instance, IOKit will take care of it since it allocated your
class. However if you are allocating nubs yourself, it is your
responsibility for calling start(). To make that easier, there's an
IOService function startCandidate() that will call both attach() and
start() on your nub. It will also clean up by calling detach() if
start() fails.

Also, since you are creating your driver nubs, there is no need to set
up matching criteria for them. That is only needed for cases like your
controller class that need to be automatically created.

Oh, one bug? I found while writing this is that when calling the
init() function on my .driver class, after
creating an instance of it with 'new', if I try to IOLog( "%s init",
getName() ); as the first piece of code on the
init() routine, it will cause a kernel panic everytime. The culprit
being getName() for some reason.



Definitely seems like a bug. I believe that the name information comes
from the registry, so it might be that getName() will fail until the
service has been attached to its provider. But calling getName()
should never cause a panic().

- Eric

--__--__--

--

---------------------
I make stuff go.
---------------------

Larry Barras
Apple Computer Inc.
1 Infinite Loop
MS: 306-2TC
Cupertino, CA 95014
(408) 974-3220
_______________________________________________
darwin-development mailing list | email@hidden
Help/Unsubscribe/Archives: http://www.lists.apple.com/mailman/listinfo/darwin-development
Do not post admin requests to the list. They will be ignored.



Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.