免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 1234 | 回复: 0
打印 上一主题 下一主题

solaris device driver 1 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2007-05-14 12:44 |只看该作者 |倒序浏览
"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 25  2006 c0d0p0 ->
[email=../../devices/pci@0,0/pci-ide@7,1/ide@0/cmdk@0,0:q]../../devices/pci@0,0/pci-ide@7,1/ide@0/cmdk@0,0:q[/email]
lrwxrwxrwx   1 root     root          50 Feb 25  2006 c0d0s0 ->
[email=../../devices/pci@0,0/pci-ide@7,1/ide@0/cmdk@0,0:a]../../devices/pci@0,0/pci-ide@7,1/ide@0/cmdk@0,0:a[/email]
lrwxrwxrwx   1 root     root          44 May  9 19:37 c2t0d0s7 ->
[email=../../devices/pci@0,0/pci1000,30@10/sd@0,0:h]../../devices/pci@0,0/pci1000,30@10/sd@0,0:h[/email]

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
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP