欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久

打開(kāi)APP
userphoto
未登錄

開(kāi)通VIP,暢享免費電子書(shū)等14項超值服

開(kāi)通VIP
Linux2.6內核驅動(dòng)移植2
Linux2.6內核驅動(dòng)移植2

隨著(zhù)Linux2.6的發(fā)布,由于2.6內核做了教的改動(dòng),各個(gè)設備的驅動(dòng)程序在不同程度上要進(jìn)行改寫(xiě)。為了方便各位Linux愛(ài)好者我把自己整理的這分文檔share出來(lái)。該文當列舉了2.6內核同以前版本的絕大多數變化,可惜的是由于時(shí)間和精力有限沒(méi)有詳細列出各個(gè)函數的用法。
特別聲明:該文檔中的內容來(lái)自http://lwn.net,該網(wǎng)也上也有各個(gè)函數的較為詳細的說(shuō)明可供各位參考。如果需要該文檔的word版的朋友, 請mail到weiriver@sohu.com索取。 

1、 使用新的入口 
必須包含 <linux/init.h>
module_init(your_init_func);
module_exit(your_exit_func);
老版本:int init_module(void);
void cleanup_module(voi);
2.4中兩種都可以用,對如后面的入口函數不必要顯示包含任何頭文件。

2、 GPL 
MODULE_LICENSE("Dual BSD/GPL");
老版本:MODULE_LICENSE("GPL"); 

3、 模塊參數 
必須顯式包含<linux/moduleparam.h>
module_param(name, type, perm);
module_param_named(name, value, type, perm);
參數定義
module_param_string(name, string, len, perm);
module_param_array(name, type, num, perm);
老版本:MODULE_PARM(variable,type);
MODULE_PARM_DESC(variable,type); 

4、 模塊別名 
MODULE_ALIAS("alias-name");
這是新增的,在老版本中需在/etc/modules.conf配置,現在在代碼中就可以實(shí)現。 

5、 模塊計數 
int try_module_get(&module);
module_put();
老版本:MOD_INC_USE_COUNT 和 MOD_DEC_USE_COUNT 

6、 符號導出 
只有顯示的導出符號才能被其他模塊使用,默認不導出所有的符號,不必使用EXPORT_NO_SYMBOL*
老板本:默認導出所有的符號,除非使用**PORT_NO_SYMBOLS 

7、 內核版本檢查 
需要在多個(gè)文件中包含<linux/module.h>時(shí),不必定義__NO_VERSION__
老版本:在多個(gè)文件中包含<linux/module.h>時(shí),除在主文件外的其他文件中必須定義__NO_VERSION__,防止版本重復定義。 

8、 設備號 
kdev_t被廢除不可用,新的dev_t拓展到了32位,12位主設備號,20位次設備號。
unsigned int iminor(struct inode *inode);
unsigned int imajor(struct inode *inode);
老版本:8位主設備號,8位次設備號
int MAJOR(kdev_t dev);
int MINOR(kdev_t dev); 

9、 內存分配頭文件變更 
所有的內存分配函數包含在頭文件<linux/slab.h>,而原來(lái)的<linux/malloc.h>不存在
老版本:內存分配函數包含在頭文件<linux/malloc.h>

10、 結構體的初試化 
gcc開(kāi)始采用ANSI C的struct結構體的初始化形式:
static struct some_structure = {
.field1 = value,
.field2 = value,
...
};
老版本:非標準的初試化形式
static struct some_structure = {
field1: value,
field2: value,
...
}; 

11、 用戶(hù)模式幫助器
int call_usermodehelper(char *path, char **argv, char **envp,
int wait);
新增wait參數 

12、 request_module() 
request_module("foo-device-%d", number);
老版本:
char module_name[32];
printf(module_name, "foo-device-%d", number);
request_module(module_name); 

13、 dev_t引發(fā)的字符設備的變化 

1、取主次設備號為
unsigned iminor(struct inode *inode);
unsigned imajor(struct inode *inode);

2、老的register_chrdev()用法沒(méi)變,保持向后兼容,但不能訪(fǎng)問(wèn)設備號大于256的設備。

3、新的接口為

a)注冊字符設備范圍
int register_chrdev_region(dev_t from, unsigned count, char *name); 

b)動(dòng)態(tài)申請主設備號
int alloc_chrdev_region(dev_t *dev, unsigned baseminor, unsigned count, char *name);
看了這兩個(gè)函數郁悶吧^_^!怎么和file_operations結構聯(lián)系起來(lái)???別急!

c)包含 <linux/cdev.h>,利用struct cdev和file_operations連接
struct cdev *cdev_alloc(void);
void cdev_init(struct cdev *cdev, struct file_operations *fops);
int cdev_add(struct cdev *cdev, dev_t dev, unsigned count);
(分別為,申請cdev結構,和fops連接,將設備加入到系統中!好復雜?。。?br> 
d)void cdev_del(struct cdev *cdev);
只有在cdev_add執行成功才可運行。 

e)輔助函數
kobject_put(&cdev->kobj);
struct kobject *cdev_get(struct cdev *cdev);
void cdev_put(struct cdev *cdev);
這一部分變化和新增的/sys/dev有一定的關(guān)聯(lián)。

14、 新增對/proc的訪(fǎng)問(wèn)操作 

<linux/seq_file.h>
以前的/proc中只能得到string, seq_file操作能得到如long等多種數據。
相關(guān)函數:
static struct seq_operations 必須實(shí)現這個(gè)類(lèi)似file_operations得數據中得各個(gè)成員函數。
seq_printf();
int seq_putc(struct seq_file *m, char c);
int seq_puts(struct seq_file *m, const char *s);
int seq_escape(struct seq_file *m, const char *s, const char *esc);
int seq_path(struct seq_file *m, struct vfsmount *mnt,
struct dentry *dentry, char *esc);
seq_open(file, &ct_seq_ops);
等等 

15、 底層內存分配 
1、<linux/malloc.h>頭文件改為<linux/slab.h>
2、分配標志GFP_BUFFER被取消,取而代之的是GFP_NOIO 和 GFP_NOFS
3、新增__GFP_REPEAT,__GFP_NOFAIL,__GFP_NORETRY分配標志
4、頁(yè)面分配函數alloc_pages(),get_free_page()被包含在<linux/gfp.h>中
5、對NUMA系統新增了幾個(gè)函數:
a) struct page *alloc_pages_node(int node_id,
unsigned int gfp_mask,
unsigned int order);
b) void free_hot_page(struct page *page);
c) void free_cold_page(struct page *page);
6、 新增Memory pools
<linux/mempool.h>
mempool_t *mempool_create(int min_nr,
mempool_alloc_t *alloc_fn,
mempool_free_t *free_fn,
void *pool_data);
void *mempool_alloc(mempool_t *pool, int gfp_mask);
void mempool_free(void *element, mempool_t *pool);
int mempool_resize(mempool_t *pool, int new_min_nr, int gfp_mask); 

16、 per-CPU變量 
get_cpu_var();
put_cpu_var();
void *alloc_percpu(type);
void free_percpu(const void *);
per_cpu_ptr(void *ptr, int cpu)
get_cpu_ptr(ptr)
put_cpu_ptr(ptr)
老版本使用
DEFINE_PER_CPU(type, name);
EXPORT_PER_CPU_SYMBOL(name);
EXPORT_PER_CPU_SYMBOL_GPL(name);
DECLARE_PER_CPU(type, name);
DEFINE_PER_CPU(int, mypcint);
2.6內核采用了可剝奪得調度方式這些宏都不安全。 

17、 內核時(shí)間變化 

1、現在的各個(gè)平臺的HZ為
Alpha: 1024/1200; ARM: 100/128/200/1000; CRIS: 100; i386: 1000; IA-64: 1024; M68K: 100; M68K-nommu: 50-1000; MIPS: 100/128/1000; MIPS64: 100; PA-RISC: 100/1000; PowerPC32: 100; PowerPC64: 1000; S/390: 100; SPARC32: 100; SPARC64: 100; SuperH: 100/1000; UML: 100; v850: 24-100; x86-64: 1000.
2、由于HZ的變化,原來(lái)的jiffies計數器很快就溢出了,引入了新的計數器jiffies_64
3、#include <linux/jiffies.h>
u64 my_time = get_jiffies_64();
4、新的時(shí)間結構增加了納秒成員變量
struct timespec current_kernel_time(void);
5、他的timer函數沒(méi)變,新增
void add_timer_on(struct timer_list *timer, int cpu);
6、新增納秒級延時(shí)函數
ndelay();
7、POSIX clocks 參考kernel/posix-timers.c 

18、 工作隊列(workqueue)

1、任務(wù)隊列(task queue )接口函數都被取消,新增了workqueue接口函數
struct workqueue_struct *create_workqueue(const char *name);
DECLARE_WORK(name, void (*function)(void *), void *data);
INIT_WORK(struct work_struct *work,
void (*function)(void *), void *data);
PREPARE_WORK(struct work_struct *work,
void (*function)(void *), void *data);
2、申明struct work_struct結構
int queue_work(struct workqueue_struct *queue,
struct work_struct *work);
int queue_delayed_work(struct workqueue_struct *queue,
struct work_struct *work,
unsigned long delay);
int cancel_delayed_work(struct work_struct *work);
void flush_workqueue(struct workqueue_struct *queue);
void destroy_workqueue(struct workqueue_struct *queue);
int schedule_work(struct work_struct *work);
int schedule_delayed_work(struct work_struct *work, unsigned long delay); 

19、 新增創(chuàng )建VFS的"libfs"

libfs給創(chuàng )建一個(gè)新的文件系統提供了大量的API.
主要是對struct file_system_type的實(shí)現。
參考源代碼:
drivers/hotplug/pci_hotplug_core.c
drivers/usb/core/inode.c
drivers/oprofile/oprofilefs.c
fs/ramfs/inode.c
fs/nfsd/nfsctl.c (simple_fill_super() example) 

20、 DMA的變化 

未變化的有:
void *pci_alloc_consistent(struct pci_dev *dev, size_t size,
dma_addr_t *dma_handle);
void pci_free_consistent(struct pci_dev *dev, size_t size,
void *cpu_addr, dma_addr_t dma_handle);
變化的有:
1、 void *dma_alloc_coherent(struct device *dev, size_t size,
dma_addr_t *dma_handle, int flag);
void dma_free_coherent(struct device *dev, size_t size,
void *cpu_addr, dma_addr_t dma_handle);
2、列舉了映射方向:
enum dma_data_direction {
DMA_BIDIRECTIONAL = 0,
DMA_TO_DEVICE = 1,
DMA_FROM_DEVICE = 2,
DMA_NONE = 3,
};
3、單映射
dma_addr_t dma_map_single(struct device *dev, void *addr,
size_t size,
enum dma_data_direction direction);
void dma_unmap_single(struct device *dev, dma_addr_t dma_addr,
size_t size,
enum dma_data_direction direction);
4、頁(yè)面映射
dma_addr_t dma_map_page(struct device *dev, struct page *page,
unsigned long offset, size_t size,
enum dma_data_direction direction);
void dma_unmap_page(struct device *dev, dma_addr_t dma_addr,
size_t size,
enum dma_data_direction direction);
5、有關(guān)scatter/gather的函數:
int dma_map_sg(struct device *dev, struct scatterlist *sg,
int nents, enum dma_data_direction direction);
void dma_unmap_sg(struct device *dev, struct scatterlist *sg,
int nhwentries, enum dma_data_direction direction);
6、非一致性映射(Noncoherent DMA mappings)
void *dma_alloc_noncoherent(struct device *dev, size_t size,
dma_addr_t *dma_handle, int flag);
void dma_sync_single_range(struct device *dev, dma_addr_t dma_handle,
unsigned long offset, size_t size,
enum dma_data_direction direction);
void dma_free_noncoherent(struct device *dev, size_t size,
void *cpu_addr, dma_addr_t dma_handle);
7、DAC (double address cycle)
int pci_dac_set_dma_mask(struct pci_dev *dev, u64 mask);
void pci_dac_dma_sync_single(struct pci_dev *dev,
dma64_addr_t dma_addr,
size_t len, int direction); 

21、 互斥 

新增seqlock主要用于:
1、少量的數據保護
2、數據比較簡(jiǎn)單(沒(méi)有指針),并且使用頻率很高
3、對不產(chǎn)生任何副作用的數據的訪(fǎng)問(wèn)
4、訪(fǎng)問(wèn)時(shí)寫(xiě)者不被餓死
<linux/seqlock.h>
初始化
seqlock_t lock1 = SEQLOCK_UNLOCKED;
或seqlock_t lock2; seqlock_init(&lock2);
void write_seqlock(seqlock_t *sl);
void write_sequnlock(seqlock_t *sl);
int write_tryseqlock(seqlock_t *sl);
void write_seqlock_irqsave(seqlock_t *sl, long flags);
void write_sequnlock_irqrestore(seqlock_t *sl, long flags);
void write_seqlock_irq(seqlock_t *sl);
void write_sequnlock_irq(seqlock_t *sl);
void write_seqlock_bh(seqlock_t *sl);
void write_sequnlock_bh(seqlock_t *sl);
unsigned int read_seqbegin(seqlock_t *sl);
int read_seqretry(seqlock_t *sl, unsigned int iv);
unsigned int read_seqbegin_irqsave(seqlock_t *sl, long flags);
int read_seqretry_irqrestore(seqlock_t *sl, unsigned int iv, long flags); 

22、 內核可剝奪 

<linux/preempt.h>
preempt_disable();
preempt_enable_no_resched();
preempt_enable_noresched();
preempt_check_resched(); 

23、 眠和喚醒 

1、原來(lái)的函數可用,新增下列函數:
prepare_to_wait_exclusive();
prepare_to_wait();
2、等待隊列的變化
typedef int (*wait_queue_func_t)(wait_queue_t *wait,
unsigned mode, int sync);
void init_waitqueue_func_entry(wait_queue_t *queue,
wait_queue_func_t func); 

24、 新增完成事件(completion events) 

<linux/completion.h>
init_completion(&my_comp);
void wait_for_completion(struct completion *comp);
void complete(struct completion *comp);
void complete_all(struct completion *comp); 

25、 RCU(Read-copy-update)

rcu_read_lock();
void call_rcu(struct rcu_head *head, void (*func)(void *arg),
void *arg);

26、 中斷處理 

1、中斷處理有返回值了。
IRQ_RETVAL(handled);
2、cli(), sti(), save_flags(), 和 restore_flags()不再有效,應該使用local_save_flags() 或local_irq_disable()。
3、synchronize_irq()函數有改動(dòng)
4、新增int can_request_irq(unsigned int irq, unsigned long flags);
5、 request_irq() 和free_irq() 從 <linux/sched.h>改到了 <linux/interrupt.h> 

27、 異步I/O(AIO) 

<linux/aio.h>
ssize_t (*aio_read) (struct kiocb *iocb, char __user *buffer,
size_t count, loff_t pos);
ssize_t (*aio_write) (struct kiocb *iocb, const char __user *buffer,
size_t count, loff_t pos);
int (*aio_fsync) (struct kiocb *, int datasync);
新增到了file_operation結構中。
is_sync_kiocb(struct kiocb *iocb);
int aio_complete(struct kiocb *iocb, long res, long res2);

28、 網(wǎng)絡(luò )驅動(dòng) 

1、struct net_device *alloc_netdev(int sizeof_priv, const char *name,
void (*setup)(struct net_device *));
struct net_device *alloc_etherdev(int sizeof_priv);
2、新增NAPI(New API)
void netif_rx_schedule(struct net_device *dev);
void netif_rx_complete(struct net_device *dev);
int netif_rx_ni(struct sk_buff *skb);
(老版本為netif_rx())

29、 USB驅動(dòng) 

老版本struct usb_driver取消了,新的結構體為
struct usb_class_driver {
char *name;
struct file_operations *fops;
mode_t mode;
int minor_base;
};
int usb_submit_urb(struct urb *urb, int mem_flags);
int (*probe) (struct usb_inte***ce *intf,
const struct usb_device_id *id);

30、 block I/O 層 

這一部分做的改動(dòng)最大。不祥敘。

31、 mmap()

int remap_page_range(struct vm_area_struct *vma, unsigned long from,
unsigned long to, unsigned long size,
pgprot_t prot);
int io_remap_page_range(struct vm_area_struct *vma, unsigned long from,
unsigned long to, unsigned long size,
pgprot_t prot);
struct page *(*nopage)(struct vm_area_struct *area,
unsigned long address,
int *type);
int (*populate)(struct vm_area_struct *area, unsigned long address,
unsigned long len, pgprot_t prot, unsigned long pgoff,
int nonblock);
int install_page(struct mm_struct *mm, struct vm_area_struct *vma,
unsigned long addr, struct page *page,
pgprot_t prot);
struct page *vmalloc_to_page(void *address); 

32、 零拷貝塊I/O(Zero-copy block I/O) 

struct bio *bio_map_user(struct block_device *bdev,
unsigned long uaddr,
unsigned int len,
int write_to_vm);
void bio_unmap_user(struct bio *bio, int write_to_vm);
int get_user_pages(struct task_struct *task,
struct mm_struct *mm,
unsigned long start,
int len,
int write,
int force,
struct page **pages,
struct vm_area_struct **vmas); 

33、 高端內存操作kmaps 

void *kmap_atomic(struct page *page, enum km_type type);
void kunmap_atomic(void *address, enum km_type type);
struct page *kmap_atomic_to_page(void *address);
老版本:kmap() 和 kunmap()。

34、 驅動(dòng)模型

主要用于設備管理。
1、 sysfs
2、 Kobjects 

A unified device number allocator 

Traditionally, device drivers have added their devices to the system with calls to register_chrdev() or register_blkdev(). These functions served two functions: allocating a portion of the device number space, and ****** specific devices available to user space. In 2.6, things changed a bit. For character devices, register_chrdev() was replaced by the combination of alloc_chrdev_region(), which allocates device numbers, and cdev_add(), which attaches a device to a specific number. On the block side, register_blkdev() has become optional, but it can still be used to allocate a block major number. The association of block devices with numbers is done with add_disk(). 

In other words, the allocation of device number space and the association of specific numbers with devices have been split in the 2.6 kernel. Matt Mackall was looking at the allocation side recently, where he notice* * **ir amount of duplicated code between the char and block implementations. The current code is also unable to perform dynamic allocation of major numbers outside of the traditional 0..255 range. So Matt put together a patch which cleans things up a bit. 

The new allocation scheme relies on simple linked lists. When a new device number request comes in, the code searches the (sorted) list to see if the request can be satisfied. If so, a new entry is added to the list, and the starting device number is returned. This work is done by the new function register_dev(): 

  int register_dev(dev_t base, dev_t top, int size, const char *name,
           struct list_head *list, dev_t *ret);
This function requests that a range of size numbers be allocated from the given list. The first number should fall between base and top; if a suitable range is found, that first number will be returned in ret. The list is a simple, list_head structure which is initially empty; the caller must provide locking to prevent concurrent calls to register_dev() using the same list. 

The new inte***ce works; it also replaces a fair amount of common code in the char and block code. Other than some quibbles about potential performance problems resulting from the linear list search algorithm (which should not really matter, since device number allocation is a rare operation), there seem to be no real objections to the new scheme. So it may find its way into a -mm kernel before too long. 

A future change would allow the dynamic allocation of device numbers in the expanded range; for now, dynamic major numbers are allocated from 254 in descending order, as has been done for many years. The patch also retains the register_chrdev() and register_blkdev() inte***ces in a compatibility mode - even though both were essentially obsolete even before the change. At some point in the future, there may be an attempt to deprecate those inte***ces; that move would force changes in a great many drivers. 
本站僅提供存儲服務(wù),所有內容均由用戶(hù)發(fā)布,如發(fā)現有害或侵權內容,請點(diǎn)擊舉報。
打開(kāi)APP,閱讀全文并永久保存 查看更多類(lèi)似文章
猜你喜歡
類(lèi)似文章
Linux內核DMA機制 - ShangShuWu
DS18B20 driver for Linux
platform設備led(ok6410)
Linux設備驅動(dòng)程序學(xué)習(1)-字符設備驅動(dòng)程序 - Linux設備驅動(dòng)程序 - Tek...
CSDN技術(shù)中心 Linux 2.6 驅動(dòng)設計快速入門(mén)!
字符設備驅動(dòng)程序及數據結構簡(jiǎn)介
更多類(lèi)似文章 >>
生活服務(wù)
分享 收藏 導長(cháng)圖 關(guān)注 下載文章
綁定賬號成功
后續可登錄賬號暢享VIP特權!
如果VIP功能使用有故障,
可點(diǎn)擊這里聯(lián)系客服!

聯(lián)系客服

欧美性猛交XXXX免费看蜜桃,成人网18免费韩国,亚洲国产成人精品区综合,欧美日韩一区二区三区高清不卡,亚洲综合一区二区精品久久