Subject: RE: devnos and dv_unit.
To: 'Ben Harris' , Aaditya Rai <ARai@rhapsodynetworks.com>
From: Aaditya Rai <ARai@rhapsodynetworks.com>
List: tech-kern
Date: 10/16/2001 08:24:49
Much clearer now, Thanks!

Aaditya.

-----Original Message-----
From: Ben Harris [mailto:bjh21@netbsd.org]
Sent: Monday, October 15, 2001 4:05 PM
To: ARai@rhapsodynetworks.com
Cc: tech-kern@netbsd.org
Subject: Re: devnos and dv_unit.


In article
<45BEF1D68145D51186C100B0D0AABE6510492D@med.corp.rhapsodynetworks.com> you
write:
>I have a newbie question. How can one read the device tree..? Moreover,
lets
>say that the autoconf code detects 2 cards for my driver, and passes me the
>unit numbers for these cards (say, 0 and 1) in dv_unit. Lets also assume
>that my driver interprets a devno from userland as "top 2 bits are the card
>number". 
>
>How will someone in the userland make devnos for my cards (given that they
>cant find the respective unit numbers, unless I provide an ioctl)...?

I'm not quite sure what you mean, so I'll give you a general overview of how
the unit number gets passed around:

At attach time, driver gets unit number from autoconfig machinary, and
displays it for the user as part of the device name (e.g. foo1).

User creates a device node (or several) in /dev using MAKEDEV, which
knows which major number your device uses, and how to encode the unit number
into the minor number (e.g. ./MAKEDEV foo1, creating /dev/foo1 with major
number 42 and minor number 1).

User either provides the name of your device to a program directly (fooctl
-f foo1 ingest), or puts it in a config file (/etc/foo.conf) or whatever.

That program opens /dev/foo1, which causes the kernel to look up your device
in cdevsw (or bdevsw if it's a buffered device), and call its open routine,
passing it the major and minor number, from which it can work out the unit
number.

Is that clear?

-- 
Ben Harris
<bjh21@netbsd.org>
Portmaster, NetBSD/arm26
<URL:http://www.netbsd.org/Ports/arm26/>