Linux Device Driver Sum Up 2

34 pages

Please download to get full document.

View again

of 34
All materials on our website are shared by users. If you have any questions about copyright issues, please report us to resolve them. We are always happy to assist you.
   :XJKZQ+ZSHYNTSX  +ZSHYNTSare for doing device i/o, to/from the i/o ports #include char inb(int port); char inw(int port); char outb(char val, int port); char outw(char val, int port);  +ZSHYNTSfor allocating small amounts of memory ( void *kmalloc(int size, int priority); void kfree_s(void *obj, int size); void kfree(void *obj); the priority is either :  GFP_KERNEL - for normal cases   GFP_ATOMIC - for allocating mem inside i
            :XJKZQ + ZSHYNTSX     + ZSHYNTS  are for doing device i/o, to/from the i/o ports  #include <asm/io.h> char inb(int port);char inw(int port);char outb(char val, int port);char outw(char val, int port);    + ZSHYNTS  for allocating small amounts of memory (<4096 bytes)   #include <linux/malloc.h> void *kmalloc(int size, int priority);void kfree_s(void *obj, int size);void kfree(void *obj);the priority is either:    GFP _KERNEL - for normal cases     GFP _ATOMIC - for allocating mem inside interrupts     + ZSHYNTS  for allocating larger amounts of memory, such as device buffers   #include <linux/mm.h> void *vmalloc(long size);void vfree(void *obj);     #include <linux/kernel.h> int printk(char *fmt, ...);    to copy data to/from user space    #include <asm/segment.h> unsigned char get_fs_byte(const char *addr);unsigned short get_fs_word(const short *addr);unsigned long get_fs_long(const int *addr);void put_fs_byte(char val, char *addr);void put_fs_word(short val, short *addr);void put_fs_long(long val, int *addr);void memcpy_fromfs(void *to, void *from, unsigned long len);void memcpy_tofs(void *to, void *from, unsigned long len);    to set, clear, save and restore the interrupt enable flag   #include <asm/system.h> void sti();void cli();void save_flags(unsigned long flags);void restore_flags(unsigned long flags);     )W N[J W 'F XNHX     SJJI  YT \ W NYJ F S  NSYN F QN_ F YNTS  W TZYNSJ    In order that the device driver is correctly initialized whenthe operating system is booted, the xxx_init() routine must beexecuted.    To ensure this happens, add the following line to the end of thechr_drv_init() function in the/usr/src/linux/driver/char/mem.c file:  mem_start = xxx_init(mem_start); and resave the file back to disk.      xxx_init()  XMTZQI  KN W XY  H F QQ  register_chrdev()  YT  W JLNXYJ W  NYXJQK F SI F [TNI  IJ[NHJ  SZRGJ W  HTSYJSYNTS    7 JYZ W SX       NK  ST  TYMJ W  HM F W F HYJ W  IJ[NHJ  M F X  W JLNXYJ W JI \ NYM  YMJ  X F RJ  R FO T W  SZRGJ W      STS   NK  YMJ  H F QQ  K F NQX U W JXZR F GQ^  GJH F ZXJ F STYMJ W  HM F W F HYJ W  IJ[NHJ  M F X F Q W J F I^ F QQTH F YJI  YM F Y  R FO T W  SZRGJ W      SJJI  YT \ W NYJ  KZSHYNTSX  YT  KNQQ  NS  YMJ  XY W ZHY  KNQJDT U J W F YNTSX  XY W ZHYZ W J       :XNSL . SYJ WW Z U YX     SJJI  YT \ W NYJ F S  NSYJ WW Z U Y  XJ W [NHJ  W TZYNSJ .8 7     P JJ U NS  RNSI  YM F Y  NSYJ WW Z U YX F W J F X^SHM W TSTZX    YMJ^  H F S  THHZ W F Y F S^  YNRJ  void foo_interrupt(unsigned int irq, struct pt_reg *reg);    N WV  NX  YMJ  SZRGJ W  TK  YMJ  N WV \ MNHM  Y W NLLJ W JI  YMNX  W TZYNSJ    W JLX  NX F HT U ^  TK  YMJ (5 :  W JLNXYJ W X      5.   Kernel modules      from a source file mod.c of a kernel module, you compile it with gcc -Wall -O2-c mod.c      O nce you get the compiled mod.o , you can become root and install it to arunning kernel using insmod mod.o , and remove it from the kernel using rmmod mod .      M ost modules does not do a lot of things when being loaded. They just register some functions to the kernel, so that when the functionalities are needed, those
Related Search
We Need Your Support
Thank you for visiting our website and your interest in our free products and services. We are nonprofit website to share and download documents. To the running of this website, we need your help to support us.

Thanks to everyone for your continued support.

No, Thanks