What is device Driver
A kernel module
• Manages the low-level I/O operations of a hardware
device
• Written with standard interfaces
• Devices are organized into the device tree, a hierarchy
of devices
What's Solaris Kernel?
A program that manages system resources
• Provides applications with essential system services,
such as virtual memory, scheduling, etc...
• Can be divided into two parts:
> kernel
> I/O subsystem
• Device drivers are loadable kernel modules
Solaris Kernel
User level
Application programs
Kernel
level
Process
Device Configuration File
Necessary for not self-identifying devices; not
necessary for PCI devices
• Named as *.conf
• Should contain the names of this device and its parent
• For example, in dummy.conf:
> name=”dummy” parent=”pseudo”;
Compile the Driver
• Must use -D_KERNEL_ option
• For Sun Studio user
#cc -D_KERNEL_ -c dummy.c
#/usr/ccs/bin/ld -r -o dummy dummy.o
• For gcc user
#gcc -D_KERNEL_ -ffreestanding -nodefaultlibs -c
dummy.c
#/usr/ccs/bin/ld -r -o dummy dummy.o
Install the Driver
• Driver directory is /kernel/drv (/usr/kernel/drv, etc)
• Must become root to install
#cp dummy /kernel/drv/dummy
#cp dummy.conf /kernel/drv
Add and Remove the Driver
• To add a driver
# add_drv dummy
• For a real hardware driver, you may also need to
use -c and -i option. See add_drv(1M)
• To remove
# rem_drv dummy
Load and Unload the Driver
• The driver is automatically loaded when its device is
accessed
• You can also load/unload it manually
• To load a driver
# modload dummy
• To unload, get the module id in the system, then
unload it
#modinfo | grep dummy
#modunload -i id
Test Step-by-step
• #modinfo
• #grep dummy /etc/name_to_major
• #mdb -k
> dummy`_init $m
• #prtconf -P
• #cat /devices/pseudo/dummy*
• #echo hello > 'ls /devices/pseudo/dummy*'
• #rem_drv dummy
No comments:
Post a Comment