solaris device driver 1
"device driver tutorial" study -->dummy driver.1. driver interface
Solaris driver modules should use DDI/DKI(Device Driver Interface, Driver-kernel Interface).Adevice driver declares its general entry points in its dev_ops(9S) structure.Adriver declares entry points for routines that are related to character or block data in its cb_ops(9S) structure.
2. device tree
device files in /devices are called device tree. prtconf could be used to see graphic representation of the tree. A file in the device tree which is not a directory represent either a character device or block device.
3. Character and Block devices
A block device can contain addressable, reusable data. An example of a block device is a file system. Any device can be character device. Disks hava both block and character interfaces.
1) device names.
bash-3.00# ls -l /dev/dsk/
lrwxrwxrwx 1 root root 50 Feb 252006 c0d0p0 ->
../../devices/pci@0,0/pci-ide@7,1/ide@0/cmdk@0,0:q
lrwxrwxrwx 1 root root 50 Feb 252006 c0d0s0 ->
../../devices/pci@0,0/pci-ide@7,1/ide@0/cmdk@0,0:a
lrwxrwxrwx 1 root root 44 May9 19:37 c2t0d0s7 ->
../../devices/pci@0,0/pci1000,30@10/sd@0,0:h
c0 --> controller 0.
t0 --> Target 0. On SCSI controllers, this value is the disk number.
d0 --> SCSI LUN. This value indicates a virtual partitioning of a target or single physical device.
s7 --> Slice 7 on the target disk.
p0 --> ?
/device shows the physical names of the devices.
2) Device numbers
The major number is chosen when the driver installed. The kernel uses the major number to associate the I/O request with the correct driver code. The kernel uses this association to decide which driver to execute when the user reads or writes the device file. "/etc/name_to_major"
The minor number is assigned int the driver. The minor number must map each driver to a specific device instance. Minor numbers ususally refer to sub-devices.
4. Write driver
1) man. use (9E) in man.
man ioctl.9e or man -s 9e ioctl.
man driver.conf
driver.conf should end with ';', or "could not attach" error may happen.
2) build the driver.
cc -D_KERNEL -c dummy.c
ld -r -o dummy dummy.o
cp dummy.conf /usr/kernel/drv
cp dummy /tmp
ln -s /tmp/dummy /usr/kernel/drv/dummy
add_drv dummy
cat /devices/pseudo/dummy@*
echo hello > \355\253ls /devices/pseudo/dummy@*\355\253
rem_drv dummy
3) bug On solaris 10.
line 206 in /usr/include/sys/ddi_implfuncs.h comment out to remove compile errors.
4) driver entry point.
- configuration Entry points. _init(9E), _info,_fini
- Autoconfiguration Entry points. attach, detach, getinfo, prop_op
- User context Entry Points. open, close, write, read.
5) Driver data structure
dev_ops -->device operation structure.
cb_ops-->character and block operation structure.
modldrv -->module linkage structure.
本文来自ChinaUnix博客,如果查看原文请点:http://blog.chinaunix.net/u1/38597/showart_300836.html
页:
[1]