免费注册 查看新帖 |

Chinaunix

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

求pci驱动程序代码! [复制链接]

liuhuizhangyi 该用户已被删除
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2008-04-01 19:05 |只看该作者 |倒序浏览
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
24
15-16赛季CBA联赛之北京
日期:2018-08-17 18:43:33技术图书徽章
日期:2018-08-22 12:53:57技术图书徽章
日期:2018-08-22 12:54:20技术图书徽章
日期:2018-08-22 12:54:3015-16赛季CBA联赛之福建
日期:2018-10-19 16:58:1619周年集字徽章-庆
日期:2019-08-27 13:28:5619周年集字徽章-19
日期:2019-08-27 13:31:2619周年集字徽章-19
日期:2019-08-27 13:31:2615-16赛季CBA联赛之同曦
日期:2019-09-05 12:03:2819周年集字徽章-周
日期:2019-09-06 18:54:5415-16赛季CBA联赛之上海
日期:2018-07-25 11:55:2615-16赛季CBA联赛之青岛
日期:2018-07-10 14:13:18
2 [报告]
发表于 2008-04-01 19:05 |只看该作者

  1. /*
  2. * 与PCI函数进行交互的简单KLD
  3. *
  4. * Murray Stokely
  5. */

  6. #include <sys/param.h>        /* kernel.h中使用的定义 */
  7. #include <sys/module.h>
  8. #include <sys/systm.h>
  9. #include <sys/errno.h>
  10. #include <sys/kernel.h>       /* 模块初始化中使用的类型 */
  11. #include <sys/conf.h>     /* cdevsw结构 */
  12. #include <sys/uio.h>      /* uio结构 */
  13. #include <sys/malloc.h>
  14. #include <sys/bus.h>      /* pci总线用到的结构、原型 */

  15. #include <machine/bus.h>
  16. #include <sys/rman.h>
  17. #include <machine/resource.h>

  18. #include <dev/pci/pcivar.h>   /* 为了使用get_pci宏! */
  19. #include <dev/pci/pcireg.h>

  20. /* softc保存我们每个实例的数据。 */
  21. struct mypci_softc {
  22.     device_t    my_dev;
  23.     struct cdev *my_cdev;
  24. };

  25. /* 函数原型 */
  26. static d_open_t     mypci_open;
  27. static d_close_t    mypci_close;
  28. static d_read_t     mypci_read;
  29. static d_write_t    mypci_write;

  30. /* 字符设备入口点 */

  31. static struct cdevsw mypci_cdevsw = {
  32.     .d_version =    D_VERSION,
  33.     .d_open =   mypci_open,
  34.     .d_close =  mypci_close,
  35.     .d_read =   mypci_read,
  36.     .d_write =  mypci_write,
  37.     .d_name =   "mypci",
  38. };

  39. /*
  40. * 在cdevsw例程中,我们通过结构体cdev中的成员si_drv1找出我们的softc。
  41. * 当我们建立/dev项时,在我们的已附着的例程中,
  42. * 我们设置这个变量指向我们的softc。
  43. */

  44. int
  45. mypci_open(struct cdev *dev, int oflags, int devtype, d_thread_t *td)
  46. {
  47.     struct mypci_softc *sc;

  48.     /* Look up our softc. */
  49.     sc = dev->si_drv1;
  50.     device_printf(sc->my_dev, "Opened successfully.\n");
  51.     return (0);
  52. }

  53. int
  54. mypci_close(struct cdev *dev, int fflag, int devtype, d_thread_t *td)
  55. {
  56.     struct mypci_softc *sc;

  57.     /* Look up our softc. */
  58.     sc = dev->si_drv1;
  59.     device_printf(sc->my_dev, "Closed.\n");
  60.     return (0);
  61. }

  62. int
  63. mypci_read(struct cdev *dev, struct uio *uio, int ioflag)
  64. {
  65.     struct mypci_softc *sc;

  66.     /* Look up our softc. */
  67.     sc = dev->si_drv1;
  68.     device_printf(sc->my_dev, "Asked to read %d bytes.\n", uio->uio_resid);
  69.     return (0);
  70. }

  71. int
  72. mypci_write(struct cdev *dev, struct uio *uio, int ioflag)
  73. {
  74.     struct mypci_softc *sc;

  75.     /* Look up our softc. */
  76.     sc = dev->si_drv1;
  77.     device_printf(sc->my_dev, "Asked to write %d bytes.\n", uio->uio_resid);
  78.     return (0);
  79. }

  80. /* PCI支持函数 */

  81. /*
  82. * 将某个设置的标识与这个驱动程序支持的标识相比较。
  83. * 如果相符,设置描述字符并返回成功。
  84. */
  85. static int
  86. mypci_probe(device_t dev)
  87. {

  88.     device_printf(dev, "MyPCI Probe\nVendor ID : 0x%x\nDevice ID : 0x%x\n",
  89.         pci_get_vendor(dev), pci_get_device(dev));

  90.     if (pci_get_vendor(dev) == 0x11c1) {
  91.         printf("We've got the Winmodem, probe successful!\n");
  92.         device_set_desc(dev, "WinModem");
  93.         return (BUS_PROBE_DEFAULT);
  94.     }
  95.     return (ENXIO);
  96. }

  97. /* 只有当探测成功时才调用连接函数 */

  98. static int
  99. mypci_attach(device_t dev)
  100. {
  101.     struct mypci_softc *sc;

  102.     printf("MyPCI Attach for : deviceID : 0x%x\n", pci_get_devid(dev));

  103.     /* Look up our softc and initialize its fields. */
  104.     sc = device_get_softc(dev);
  105.     sc->my_dev = dev;

  106.     /*
  107.      * Create a /dev entry for this device.  The kernel will assign us
  108.      * a major number automatically.  We use the unit number of this
  109.      * device as the minor number and name the character device
  110.      * "mypci<unit>".
  111.      */
  112.     sc->my_cdev = make_dev(&mypci_cdevsw, device_get_unit(dev),
  113.         UID_ROOT, GID_WHEEL, 0600, "mypci%u", device_get_unit(dev));
  114.     sc->my_cdev->si_drv1 = sc;
  115.     printf("Mypci device loaded.\n");
  116.     return (0);
  117. }

  118. /* 分离设备。 */

  119. static int
  120. mypci_detach(device_t dev)
  121. {
  122.     struct mypci_softc *sc;

  123.     /* Teardown the state in our softc created in our attach routine. */
  124.     sc = device_get_softc(dev);
  125.     destroy_dev(sc->my_cdev);
  126.     printf("Mypci detach!\n");
  127.     return (0);
  128. }

  129. /* 系统关闭期间在sync之后调用。 */

  130. static int
  131. mypci_shutdown(device_t dev)
  132. {

  133.     printf("Mypci shutdown!\n");
  134.     return (0);
  135. }

  136. /*
  137. * 设备挂起例程。
  138. */
  139. static int
  140. mypci_suspend(device_t dev)
  141. {

  142.     printf("Mypci suspend!\n");
  143.     return (0);
  144. }

  145. /*
  146. * 设备恢复(重新开始)例程。
  147. */
  148. static int
  149. mypci_resume(device_t dev)
  150. {

  151.     printf("Mypci resume!\n");
  152.     return (0);
  153. }

  154. static device_method_t mypci_methods[] = {
  155.     /* 设备接口 */
  156.     DEVMETHOD(device_probe,     mypci_probe),
  157.     DEVMETHOD(device_attach,    mypci_attach),
  158.     DEVMETHOD(device_detach,    mypci_detach),
  159.     DEVMETHOD(device_shutdown,  mypci_shutdown),
  160.     DEVMETHOD(device_suspend,   mypci_suspend),
  161.     DEVMETHOD(device_resume,    mypci_resume),

  162.     { 0, 0 }
  163. };

  164. static devclass_t mypci_devclass;

  165. DEFINE_CLASS_0(mypci, mypci_driver, mypci_methods, sizeof(struct mypci_softc));
  166. DRIVER_MODULE(mypci, pci, mypci_driver, mypci_devclass, 0, 0);

复制代码


代码没细看,不知道这个合不合兄弟的口味?
liuhuizhangyi 该用户已被删除
3 [报告]
发表于 2008-04-01 19:06 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽
liuhuizhangyi 该用户已被删除
4 [报告]
发表于 2008-04-02 11:10 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
24
15-16赛季CBA联赛之北京
日期:2018-08-17 18:43:33技术图书徽章
日期:2018-08-22 12:53:57技术图书徽章
日期:2018-08-22 12:54:20技术图书徽章
日期:2018-08-22 12:54:3015-16赛季CBA联赛之福建
日期:2018-10-19 16:58:1619周年集字徽章-庆
日期:2019-08-27 13:28:5619周年集字徽章-19
日期:2019-08-27 13:31:2619周年集字徽章-19
日期:2019-08-27 13:31:2615-16赛季CBA联赛之同曦
日期:2019-09-05 12:03:2819周年集字徽章-周
日期:2019-09-06 18:54:5415-16赛季CBA联赛之上海
日期:2018-07-25 11:55:2615-16赛季CBA联赛之青岛
日期:2018-07-10 14:13:18
5 [报告]
发表于 2008-04-02 15:48 |只看该作者
Google下,应该可以找得到吧.
liuhuizhangyi 该用户已被删除
6 [报告]
发表于 2008-04-03 08:57 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
7 [报告]
发表于 2008-04-05 04:36 |只看该作者
内核里面超多的阿~~
liuhuizhangyi 该用户已被删除
8 [报告]
发表于 2008-04-06 20:30 |只看该作者
提示: 作者被禁止或删除 内容自动屏蔽

论坛徽章:
0
9 [报告]
发表于 2008-04-07 00:47 |只看该作者

论坛徽章:
0
10 [报告]
发表于 2008-04-07 20:53 |只看该作者

LINUX下PCI9054的驱动

同求一份LINUX下PCI9054的驱动
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

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

清除 Cookies - ChinaUnix - Archiver - WAP - TOP