Linux kernel & device driver programming

Cross-Referenced Linux and Device Driver Code

[ source navigation ] [ diff markup ] [ identifier search ] [ freetext search ] [ file search ]
Version: [ 2.6.11.8 ] [ 2.6.25 ] [ 2.6.25.8 ] [ 2.6.31.13 ] Architecture: [ i386 ]
  1 /* -*- C -*-
  2  * scullc.h -- definitions for the scullc char module
  3  *
  4  * Copyright (C) 2001 Alessandro Rubini and Jonathan Corbet
  5  * Copyright (C) 2001 O'Reilly & Associates
  6  *
  7  * The source code in this file can be freely used, adapted,
  8  * and redistributed in source or binary form, so long as an
  9  * acknowledgment appears in derived source files.  The citation
 10  * should list that the code comes from the book "Linux Device
 11  * Drivers" by Alessandro Rubini and Jonathan Corbet, published
 12  * by O'Reilly & Associates.   No warranty is attached;
 13  * we cannot take responsibility for errors or fitness for use.
 14  */
 15 
 16 #include <linux/ioctl.h>
 17 #include <linux/cdev.h>
 18 
 19 /*
 20  * Macros to help debugging
 21  */
 22 
 23 #undef PDEBUG             /* undef it, just in case */
 24 #ifdef SCULLC_DEBUG
 25 #  ifdef __KERNEL__
 26      /* This one if debugging is on, and kernel space */
 27 #    define PDEBUG(fmt, args...) printk( KERN_DEBUG "scullc: " fmt, ## args)
 28 #  else
 29      /* This one for user space */
 30 #    define PDEBUG(fmt, args...) fprintf(stderr, fmt, ## args)
 31 #  endif
 32 #else
 33 #  define PDEBUG(fmt, args...) /* not debugging: nothing */
 34 #endif
 35 
 36 #undef PDEBUGG
 37 #define PDEBUGG(fmt, args...) /* nothing: it's a placeholder */
 38 
 39 #define SCULLC_MAJOR 0   /* dynamic major by default */
 40 
 41 #define SCULLC_DEVS 4    /* scullc0 through scullc3 */
 42 
 43 /*
 44  * The bare device is a variable-length region of memory.
 45  * Use a linked list of indirect blocks.
 46  *
 47  * "scullc_dev->data" points to an array of pointers, each
 48  * pointer refers to a memory page.
 49  *
 50  * The array (quantum-set) is SCULLC_QSET long.
 51  */
 52 #define SCULLC_QUANTUM  4000 /* use a quantum size like scull */
 53 #define SCULLC_QSET     500
 54 
 55 struct scullc_dev {
 56         void **data;
 57         struct scullc_dev *next;  /* next listitem */
 58         int vmas;                 /* active mappings */
 59         int quantum;              /* the current allocation size */
 60         int qset;                 /* the current array size */
 61         size_t size;              /* 32-bit will suffice */
 62         struct semaphore sem;     /* Mutual exclusion */
 63         struct cdev cdev;
 64 };
 65 
 66 extern struct scullc_dev *scullc_devices;
 67 
 68 extern struct file_operations scullc_fops;
 69 
 70 /*
 71  * The different configurable parameters
 72  */
 73 extern int scullc_major;     /* main.c */
 74 extern int scullc_devs;
 75 extern int scullc_order;
 76 extern int scullc_qset;
 77 
 78 /*
 79  * Prototypes for shared functions
 80  */
 81 int scullc_trim(struct scullc_dev *dev);
 82 struct scullc_dev *scullc_follow(struct scullc_dev *dev, int n);
 83 
 84 
 85 #ifdef SCULLC_DEBUG
 86 #  define SCULLC_USE_PROC
 87 #endif
 88 
 89 /*
 90  * Ioctl definitions
 91  */
 92 
 93 /* Use 'K' as magic number */
 94 #define SCULLC_IOC_MAGIC  'K'
 95 
 96 #define SCULLC_IOCRESET    _IO(SCULLC_IOC_MAGIC, 0)
 97 
 98 /*
 99  * S means "Set" through a ptr,
100  * T means "Tell" directly
101  * G means "Get" (to a pointed var)
102  * Q means "Query", response is on the return value
103  * X means "eXchange": G and S atomically
104  * H means "sHift": T and Q atomically
105  */
106 #define SCULLC_IOCSQUANTUM _IOW(SCULLC_IOC_MAGIC,  1, int)
107 #define SCULLC_IOCTQUANTUM _IO(SCULLC_IOC_MAGIC,   2)
108 #define SCULLC_IOCGQUANTUM _IOR(SCULLC_IOC_MAGIC,  3, int)
109 #define SCULLC_IOCQQUANTUM _IO(SCULLC_IOC_MAGIC,   4)
110 #define SCULLC_IOCXQUANTUM _IOWR(SCULLC_IOC_MAGIC, 5, int)
111 #define SCULLC_IOCHQUANTUM _IO(SCULLC_IOC_MAGIC,   6)
112 #define SCULLC_IOCSQSET    _IOW(SCULLC_IOC_MAGIC,  7, int)
113 #define SCULLC_IOCTQSET    _IO(SCULLC_IOC_MAGIC,   8)
114 #define SCULLC_IOCGQSET    _IOR(SCULLC_IOC_MAGIC,  9, int)
115 #define SCULLC_IOCQQSET    _IO(SCULLC_IOC_MAGIC,  10)
116 #define SCULLC_IOCXQSET    _IOWR(SCULLC_IOC_MAGIC,11, int)
117 #define SCULLC_IOCHQSET    _IO(SCULLC_IOC_MAGIC,  12)
118 
119 #define SCULLC_IOC_MAXNR 12
120 
121 
122 
123 
  This page was automatically generated by the LXR engine.