资源简介
经典linux驱动程序开发 第四版的配套代码可以下载了,如果有什么问题,欢迎反馈
代码片段和文件信息
/*
* A virtual bus for LDD sample code devices to plug into. This
* code is heavily borrowed from drivers/base/sys.c
*
* Copyright (C) 2001 Alessandro Rubini and Jonathan Corbet
* Copyright (C) 2001 O‘Reilly & Associates
*
* The source code in this file can be freely used adapted
* and redistributed in source or binary form so long as an
* acknowledgment appears in derived source files. The citation
* should list that the code comes from the book “Linux Device
* Drivers“ by Alessandro Rubini and Jonathan Corbet published
* by O‘Reilly & Associates. No warranty is attached;
* we cannot take responsibility for errors or fitness for use.
*
*/
/* $Id: lddbus.cv 1.9 2004/09/26 08:12:27 gregkh Exp $ */
#include
#include
#include
#include
#include
#include “lddbus.h“
MODULE_AUTHOR(“Jonathan Corbet“);
MODULE_LICENSE(“Dual BSD/GPL“);
static char *Version = “$Revision: 1.9 $“;
/*
* Respond to hotplug events.
*/
static int ldd_uevent(struct device *dev struct kobj_uevent_env *env)
{
return add_uevent_var(env “LDDBUS_VERSION=%s“ Version);
}
/*
* Match LDD devices to drivers. Just do a simple name test.
*/
static int ldd_match(struct device *dev struct device_driver *driver)
{
return !strncmp(dev_name(dev) driver->name strlen(driver->name));
}
/*
* The LDD bus device.
*/
static void ldd_bus_release(struct device *dev)
{
printk(KERN_DEBUG “lddbus release\n“);
}
struct device ldd_bus = {
.init_name = “ldd0“
.release = ldd_bus_release
};
/*
* And the bus type.
*/
struct bus_type ldd_bus_type = {
.name = “ldd“
.match = ldd_match
.uevent = ldd_uevent
};
/*
* Export a simple attribute.
*/
static ssize_t show_bus_version(struct bus_type *bus char *buf)
{
return snprintf(buf PAGE_SIZE “%s\n“ Version);
}
static BUS_ATTR(version S_IRUGO show_bus_version NULL);
/*
* LDD devices.
*/
/*
* For now no references to LDDbus devices go out which are not
* tracked via the module reference count so we use a no-op
* release function.
*/
static void ldd_dev_release(struct device *dev)
{ }
int register_ldd_device(struct ldd_device *ldddev)
{
ldddev->dev.bus = &ldd_bus_type;
ldddev->dev.parent = &ldd_bus;
ldddev->dev.release = ldd_dev_release;
dev_set_name(&ldddev->dev “%s“ ldddev->name);
return device_register(&ldddev->dev);
}
EXPORT_SYMBOL(register_ldd_device);
void unregister_ldd_device(struct ldd_device *ldddev)
{
device_unregister(&ldddev->dev);
}
EXPORT_SYMBOL(unregister_ldd_device);
/*
* Crude driver interface.
*/
static ssize_t show_version(struct device_driver *driver char *buf)
{
struct ldd_driver *ldriver = to_ldd_driver(driver);
sprintf(buf “%s\n“ ldriver->version);
return strlen(buf);
}
int register_ldd_driver(struct ldd_driver *driver)
{
int ret;
driver->driver.bus = &ldd_bus_type;
ret = driver_register(&driver->driver);
if (ret)
return ret;
driver->version_attr.attr.
属性 大小 日期 时间 名称
----------- --------- ---------- ----- ----
目录 0 2014-02-12 14:58 ldd4-master\
文件 1091 2014-02-12 14:58 ldd4-master\LICENSE
文件 289 2014-02-12 14:58 ldd4-master\Makefile
目录 0 2014-02-12 14:58 ldd4-master\include\
文件 855 2014-02-12 14:58 ldd4-master\include\lddbus.h
目录 0 2014-02-12 14:58 ldd4-master\lddbus\
文件 717 2014-02-12 14:58 ldd4-master\lddbus\Makefile
文件 3874 2014-02-12 14:58 ldd4-master\lddbus\lddbus.c
目录 0 2014-02-12 14:58 ldd4-master\misc-modules\
文件 987 2014-02-12 14:58 ldd4-master\misc-modules\Makefile
文件 2230 2014-02-12 14:58 ldd4-master\misc-modules\complete.c
文件 2121 2014-02-12 14:58 ldd4-master\misc-modules\faulty.c
文件 335 2014-02-12 14:58 ldd4-master\misc-modules\hello.c
文件 1130 2014-02-12 14:58 ldd4-master\misc-modules\hellop.c
文件 6482 2014-02-12 14:58 ldd4-master\misc-modules\jiq.c
文件 7569 2014-02-12 14:58 ldd4-master\misc-modules\jit.c
文件 2269 2014-02-12 14:58 ldd4-master\misc-modules\kdataalign.c
文件 1465 2014-02-12 14:58 ldd4-master\misc-modules\kdatasize.c
文件 2044 2014-02-12 14:58 ldd4-master\misc-modules\seq.c
文件 6200 2014-02-12 14:58 ldd4-master\misc-modules\silly.c
文件 2287 2014-02-12 14:58 ldd4-master\misc-modules\sleepy.c
目录 0 2014-02-12 14:58 ldd4-master\misc-progs\
文件 300 2014-02-12 14:58 ldd4-master\misc-progs\Makefile
文件 1483 2014-02-12 14:58 ldd4-master\misc-progs\asynctest.c
文件 2088 2014-02-12 14:58 ldd4-master\misc-progs\dataalign.c
文件 1287 2014-02-12 14:58 ldd4-master\misc-progs\datasize.c
文件 676 2014-02-12 14:58 ldd4-master\misc-progs\gdbline
文件 2576 2014-02-12 14:58 ldd4-master\misc-progs\inp.c
文件 882 2014-02-12 14:58 ldd4-master\misc-progs\load50.c
文件 1975 2014-02-12 14:58 ldd4-master\misc-progs\mapcmp.c
文件 2170 2014-02-12 14:58 ldd4-master\misc-progs\mapper.c
............此处省略85个文件信息
评论
共有 条评论