Subject: Re: Device driver softc questions
To: Steven Grunza <>
From: Jaromír <>
List: tech-kern
Date: 03/16/2001 10:07:15
The memory for device is allocated by autoconf machinery. Do you
recall the cfattach struct of a device ? You specify
size of device-private data, probe and attach function.
Memory of the specified size is allocated and made available
to appropriate driver. There is 'self' argument to the
attach function, which points to the allocated memory.

Note that the device-specific softc should contain at least 'struct
device foo', as the first member.

I hope this helps.


Steven Grunza wrote:
[ Charset ISO-8859-1 unsupported, converting... ]
> In the attach() routine, the second parameter is a pointer to a
> structure that appears to be called a softc.  This structure appears to
> hold information for the driver.  Where (in the source code) is the
> memory for this structure allocated?
> For instance in /sys/dev/pci/puc.c line 63 the definition for "struct
> puc_softc" is created.  In line 147 of puc_attach() a local pointer
> called sc is created on the stack and set to point to the second
> parameter passed into the puc_attach() function.  This local stack
> pointer is then used to update this puc_softc structure.
> But where is a pointer to this struct puc_softc saved so the driver can
> get to it later?  This driver doesn't have puc_open() and
> puc_close() calls but how would they figure out where the struct
> puc_softc is located?
> For now I'm going to just use a global pointer to it but there's got to
> be a better (more correct) way....
> --
> "Luke, you're going to find that many | Steven Grunza
> of the truths we cling to depend      | voice:  (856) 787 - 2759
> greatly on our own point of view."    | fax:    (856) 866 - 2033
>  - Obi Wan Kenobi, Return of the Jedi | e-mail:

Jaromir Dolecek <>
 ***  Wanna a real operating system ? Go and get NetBSD, dammit!  ***