1 / 17

UQC152H3 Advanced OS

UQC152H3 Advanced OS. Writing a Device Driver. The SCULL Device Driver. Simple Character Utility for Loading Localities 6 devices types Scull-03 Scullpipe0-3 Scullsingle Scullpriv Sculluid Scullwuid. Types of SCULL. Scull0-3 Global & persistent, can be opened many times Scullpipe0-3

hue
Download Presentation

UQC152H3 Advanced OS

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. UQC152H3 Advanced OS Writing a Device Driver

  2. The SCULL Device Driver • Simple Character Utility for Loading Localities • 6 devices types • Scull-03 • Scullpipe0-3 • Scullsingle • Scullpriv • Sculluid • Scullwuid

  3. Types of SCULL • Scull0-3 • Global & persistent, can be opened many times • Scullpipe0-3 • Works like a normal pipe – example of blocking • Scullsingle, scullpriv, sculluid, scullwuid • Access versions of scull

  4. Major and Minor numbers • Major number used for device identification • Minor used by device • Use <linux/fs.h> • Register_chdev(unsigned int major, const char *name, struct file_ops *fops); • Registers major number in static array of devices 128 entries!

  5. Mknod –creating a file access point • Once we have a device table entry we need some way for programs and utilities to access it. • Use mknod to create file access point • mknod /dev/scull c 127 0 Device name Device type Minor number Major number

  6. Dynamic Allocation of Major Numbers • It is better to use dynamic allocation of major numbers • Use register_chrdev with intial arg=0 • There is a limited number of driver numbers • Many are already taken • Requires script to run mknod

  7. Dynamically creating a file node

  8. Dynamically creating a file node

  9. Deregistering devices • Unloaded drivers should be de-registered using • Unregister_chrdev(unsigned int major, const char * name); • Can cause procs problems if not de-registered

  10. dev_t and k_dev • System passes the major number to called code through the major number • Passed as i_rdev in struct inode • i_rdev is 16 bits • Only allows 256 minor numbers • Can’t be changed!

  11. kdev_t • Linux kernels greater then 1.2 has introduced kdev_t • It allows larger minor numbers • It has a number of macros • MAJOR, get a major dev_t from kdev_t • MINOR, get a minor dev_t from kdev_t • MKDEV return a kdev_t from a dev_t

  12. File Operations • Pointed to from struct file • lseek • read , write & readdir • Select • mmap • ioctl • open & release • fsync & fasync • check_media_change & revalidate

  13. Struct file • Very important kernel data structure • Not the same of FILE of library calls • Has • Pointer to file operations • Flag data • Read/write position • Inode • Mode

  14. Which minor number?

  15. Opening a device • Open does the following • Check for errors – device not ready? • Initialises the device if this is the first open call • Identifies the minor numbers – selects correct file op • Allocates private data • Increments the usage count

  16. Close or release method • This should • Decrement the usage count • Deallocate anything allocated by open • Last one out – turn off the lights! void scull_release (struct inode *inode, struct file *filp){ MOD_DEC_USE_COUNT;}

More Related