linux如何知道自己写的驱动被注册成/dev目录下的什么文件,初学,大家指教。

green__hand 2008-08-23 12:03:31
linux如何知道自己写的驱动被注册成/dev目录下的什么文件,在驱动中哪部分实现,用什么宏声明?


我要把我的驱动注册成/dev目录下的文件,要在驱动中添加什么?
...全文
375 10 打赏 收藏 转发到动态 举报
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
nevil 2008-08-27
  • 打赏
  • 举报
回复
register_chrdev_region或alloc_chrdev_region函数中会有你注册的设备名.
无知者无谓 2008-08-27
  • 打赏
  • 举报
回复
驱动里面都会有一个dev_t的,看看它吧
unbutun 2008-08-27
  • 打赏
  • 举报
回复
主要是想知道struct platform_device 结构体是干什么的,完成什么机制?
unbutun 2008-08-24
  • 打赏
  • 举报
回复
哦,我已经找到了不过不是在我改驱动的那个文件,是在这个框架的核心部分。


不知道那种标准的字符设备、块设备是在哪里做的,^_^。



BTW:在看驱动时涉及到了


static struct platform_device davinci_audio_device = {
.name = DAVINCI_AUDIO_NAME,
.dev = {
.driver_data = &audio_state,
.release = audio_free,
},
.id = 0,
};


想问一下这个平台设备在驱动这套机制里是做什么的?有什么用?
jerrykinki 2008-08-24
  • 打赏
  • 举报
回复
在你驱动的初始化函数中应该有注册设备的代码.
unbutun 2008-08-24
  • 打赏
  • 举报
回复
这个主次设备号的东西我知道,我是想问,我改的驱动中,就是oss音频驱动框架里把一个芯片的驱动注册成两个/dev下的设备,即:dsp和mixer。我想问的是这个dsp的名字和mixer这个名字是在哪里实现的,是在我改驱动那部分还是在这个框架的核心里设置的,搜了一下那个alloc_chrdev_region函数,没发现在我这部分里有。
joyself 2008-08-24
  • 打赏
  • 举报
回复
http://zh-kernel.org/pipermail/linux-kernel/2008-August/006615.html
http://zh-kernel.org/pipermail/linux-kernel/2008-August/006616.html


还有就是Understanding the Linux kernel这本书里讲到了:

13.3.1.2. Dynamic device file creation
The Linux kernel can create the device files dynamically: there is no need to fill the /dev directory with the device files of every conceivable hardware device, because the device files can be created "on demand." Thanks to the device driver model, the kernel 2.6 offers a very simple way to do so. A set of User Mode programs, collectively known as the udev toolset, must be installed in the system. At the system startup the /dev directory is emptied, then a udev program scans the subdirectories of /sys/class looking for the dev files. For each such file, which represents a combination of major and minor number for a logical device supported by the kernel, the program creates a corresponding device file in /dev. It also assigns device filenames and creates symbolic links according to a configuration file, in such a way to resemble the traditional naming scheme for Unix device files. Eventually, /dev is filled with the device files of all devices supported by the kernel on this system, and nothing else.

Often a device file is created after the system has been initialized. This happens either when a module containing a device driver for a still unsupported device is loaded, or when a hot-pluggable devicesuch as a USB peripheralis plugged in the system. The udev toolset can automatically create the corresponding device file, because the device driver model supports device hotplugging . Whenever a new device is discovered, the kernel spawns a new process that executes the User Mode /sbin/hotplug shell script,
  • passing to it any useful information on the discovered device as environment variables. The User Mode scripts usually reads a configuration file and takes care of any operation required to complete the initialization of the new device. If udev is installed, the script also creates the proper device file in the /dev directory.

unbutun 2008-08-23
  • 打赏
  • 举报
回复
mark
jerrykinki 2008-08-23
  • 打赏
  • 举报
回复
去看看devfs_mk_dir等相关函数的使用.
pottichu 2008-08-23
  • 打赏
  • 举报
回复
http://www.deansys.com/doc/ldd3/ch03s02.html

你看看 ldd3 就都明白了.

如果你发出 ls -l 命令, 你会看到在设备文件项中有 2 个数(由一个逗号分隔)在最后修改日期前面, 这里通常是文件长度出现的地方. 这些数字是给特殊设备的主次设备编号. 下面的列表显示了一个典型系统上出现的几个设备. 它们的主编号是 1, 4, 7, 和 10, 而次编号是 1, 3, 5, 64, 65, 和 129.

crw-rw-rw- 1 root root 1, 3 Apr 11 2002 null
crw------- 1 root root 10, 1 Apr 11 2002 psaux
crw------- 1 root root 4, 1 Oct 28 03:04 tty1
crw-rw-rw- 1 root tty 4, 64 Apr 11 2002 ttys0
crw-rw---- 1 root uucp 4, 65 Apr 11 2002 ttyS1
crw--w---- 1 vcsa tty 7, 1 Apr 11 2002 vcs1
crw--w---- 1 vcsa tty 7,129 Apr 11 2002 vcsa1
crw-rw-rw- 1 root root 1, 5 Apr 11 2002 zero



而在驱动中回定义主次设备号.

4,441

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 内核源代码研究区
社区管理员
  • 内核源代码研究区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧