Chinaunix首页 | 论坛 | 博客
  • 博客访问: 626041
  • 博文数量: 121
  • 博客积分: 8469
  • 博客等级: 中将
  • 技术积分: 1065
  • 用 户 组: 普通用户
  • 注册时间: 2008-07-03 10:32
文章分类

全部博文(121)

文章存档

2013年(1)

2012年(15)

2010年(2)

2009年(8)

2008年(95)

我的朋友

分类: LINUX

2008-07-22 13:49:16

引言

    计算机上的设备都是连接到bus上的而我们知道一颗CPU它的端口数目是有限,各种各样的设备直接连接CPU的bus上是无法想象的,这直接导致计算机总 线的发展。对于解决这个瓶颈的办法是让一个中间人负责对CPU总线时分复用,其余的设备大都不是直接连接到CPU bus上的而是连在中间人那里。列举个最著名的“中间人”:PCI总线。理由很简单通用PC几乎清一色PCI总线,置于PCI总线我不做介绍。我要介绍的 是Linux下描述直接连接CPU bus的机制以及它与driver之间的关系。

    Platform device是linux上一种具有自我管理功能的一个subsystem。它包含了一些基于port的legacy device以及一些host bridge 连接外部总线的设备再者就是embedded system中的许多设备也是platform device。不管是什么设备,只要它属于platform device都有一个共同的特点:
       CPU bus直接寻址
还有一种很少的情况:platform device连接在其他bus的某个segment上但是它的registers是直接寻址的

    Plarform  device会有一个名字用于driver binding(在注册driver的时候会查找driver的目标设备的bus位置,这个过程称为driver binding),另外IRQ以及地址空间等资源也要给出 。下面给出platform  device的相关数据结构:
struct platform_device {
        const char      *name;
        u32             id;
        struct device   dev;
        u32             num_resources;
        struct resource *resource;
};
     Platform device是一种device自己是不会做事情的,要有人为它做事情,那就是platform driver。下面介绍platform driver。

    platform driver遵循linux系统的driver model(这个内容是很大的内容有兴趣的可以自己学习)。对于device的discovery/enumerate都不是driver自己完成的而是 有由系统的driver注册机制完成。driver编写人员只要将注册必须的数据结构初始化并调用注册driver的kernel API就可以了。以下是driver的数据结构:
struct platform_driver {
        int (*probe)(struct platform_device *);
        int (*remove)(struct platform_device *);
        void (*shutdown)(struct platform_device *);
        int (*suspend)(struct platform_device *, pm_message_t state);
        int (*suspend_late)(struct platform_device *, pm_message_t state);
        int (*resume_early)(struct platform_device *);
        int (*resume)(struct platform_device *);
        struct device_driver driver;
};

API:
int platform_device_register(struct platform_device *pdev);
int platform_add_devices(struct platform_device **pdevs, int ndev);
int platform_driver_register(struct platform_driver *drv);

更为详尽的信息可以查看Linuxkernel以及driver方面的书籍。
阅读(1647) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~