Home

File Index

All Tags

Tags by File

Tags referrers

file: scull.h


  1 /*
  2 * scull.h -- definitions for the 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 * $Id: scull.h,v 1.15 2004/11/04 17:51:18 rubini Exp $
 16 */

 17
 18 #ifndef _SCULL_H_
 19 #define /*X*/ _SCULL_H_
 20
 21 #include <linux/ioctl.h> /* needed for the _IOW etc stuff used later */
 22
 23 /*
 24 * Macros to help debugging
 25 */

 26
 27 #undef PDEBUG             /* undef it, just in case */
 28 #ifdef SCULL_DEBUG
 29 # ifdef __KERNEL__
 30     /* This one if debugging is on, and kernel space */
 31 # define /*X*/ PDEBUG(fmt, args...) printk( KERN_DEBUG "scull: " fmt, ## args)
 32 # else
 33     /* This one for user space */
 34 # define /*X*/ PDEBUG(fmt, args...) fprintf(stderr, fmt, ## args)
 35 # endif
 36 #else
 37 # define /*X*/ PDEBUG(fmt, args...) /* not debugging: nothing */
 38 #endif
 39
 40 #undef PDEBUGG
 41 #define /*X*/ PDEBUGG(fmt, args...) /* nothing: it's a placeholder */
 42
 43 #ifndef SCULL_MAJOR
 44 #define /*X*/ SCULL_MAJOR 0   /* dynamic major by default */
 45 #endif
 46
 47 #ifndef SCULL_NR_DEVS
 48 #define /*X*/ SCULL_NR_DEVS 4    /* scull0 through scull3 */
 49 #endif
 50
 51 #ifndef SCULL_P_NR_DEVS
 52 #define /*X*/ SCULL_P_NR_DEVS 4  /* scullpipe0 through scullpipe3 */
 53 #endif
 54
 55 /*
 56 * The bare device is a variable-length region of memory.
 57 * Use a linked list of indirect blocks.
 58 *
 59 * "scull_dev->data" points to an array of pointers, each
 60 * pointer refers to a memory area of SCULL_QUANTUM bytes.
 61 *
 62 * The array (quantum-set) is SCULL_QSET long.
 63 */

 64 #ifndef SCULL_QUANTUM
 65 #define /*X*/ SCULL_QUANTUM 4000
 66 #endif
 67
 68 #ifndef SCULL_QSET
 69 #define /*X*/ SCULL_QSET    1000
 70 #endif
 71
 72 /*
 73 * The pipe device is a simple circular buffer. Here its default size
 74 */

 75 #ifndef SCULL_P_BUFFER
 76 #define /*X*/ SCULL_P_BUFFER 4000
 77 #endif
 78
 79 /*
 80 * Representation of scull quantum sets.
 81 */

 82 struct /*X*/ scull_qset {
 83         void **data;
 84         struct scull_qset *next;
 85 };
 86
 87 struct /*X*/ scull_dev {
 88         struct scull_qset *data;  /* Pointer to first quantum set */
 89         int quantum;              /* the current quantum size */
 90         int qset;                 /* the current array size */
 91         unsigned long size;       /* amount of data stored here */
 92         unsigned int access_key;  /* used by sculluid and scullpriv */
 93         struct mutex mutex;     /* mutual exclusion semaphore     */
 94         struct cdev cdev;          /* Char device structure                */
 95 };
 96
 97 /*
 98 * Split minors in two parts
 99 */

100 #define /*X*/ TYPE(minor)        (((minor) >> 4) & 0xf)        /* high nibble */
101 #define /*X*/ NUM(minor)        ((minor) & 0xf)                /* low  nibble */
102
103
104 /*
105 * The different configurable parameters
106 */

107 extern int scull_major;     /* main.c */
108 extern int scull_nr_devs;
109 extern int scull_quantum;
110 extern int scull_qset;
111
112 extern int scull_p_buffer;        /* pipe.c */
113
114
115 /*
116 * Prototypes for shared functions
117 */

118
119 int     scull_p_init(dev_t dev);
120 void    scull_p_cleanup(void);
121 int     scull_access_init(dev_t dev);
122 void    scull_access_cleanup(void);
123
124 int     scull_trim(struct scull_dev *dev);
125
126 ssize_t scull_read(struct file *filp, char __user *buf, size_t count,
127                   loff_t *f_pos);
128 ssize_t scull_write(struct file *filp, const char __user *buf, size_t count,
129                    loff_t *f_pos);
130 loff_t  scull_llseek(struct file *filp, loff_t off, int whence);
131 long     scull_ioctl(struct file *filp,
132                    unsigned int cmd, unsigned long arg);
133
134
135 /*
136 * Ioctl definitions
137 */

138
139 /* Use 'k' as magic number */
140 #define /*X*/ SCULL_IOC_MAGIC  'k'
141 /* Please use a different 8-bit number in your code */
142
143 #define /*X*/ SCULL_IOCRESET    _IO(SCULL_IOC_MAGIC, 0)
144
145 /*
146 * S means "Set" through a ptr,
147 * T means "Tell" directly with the argument value
148 * G means "Get": reply by setting through a pointer
149 * Q means "Query": response is on the return value
150 * X means "eXchange": switch G and S atomically
151 * H means "sHift": switch T and Q atomically
152 */

153 #define /*X*/ SCULL_IOCSQUANTUM _IOW(SCULL_IOC_MAGIC,  1, int)
154 #define /*X*/ SCULL_IOCSQSET    _IOW(SCULL_IOC_MAGIC,  2, int)
155 #define /*X*/ SCULL_IOCTQUANTUM _IO(SCULL_IOC_MAGIC,   3)
156 #define /*X*/ SCULL_IOCTQSET    _IO(SCULL_IOC_MAGIC,   4)
157 #define /*X*/ SCULL_IOCGQUANTUM _IOR(SCULL_IOC_MAGIC,  5, int)
158 #define /*X*/ SCULL_IOCGQSET    _IOR(SCULL_IOC_MAGIC,  6, int)
159 #define /*X*/ SCULL_IOCQQUANTUM _IO(SCULL_IOC_MAGIC,   7)
160 #define /*X*/ SCULL_IOCQQSET    _IO(SCULL_IOC_MAGIC,   8)
161 #define /*X*/ SCULL_IOCXQUANTUM _IOWR(SCULL_IOC_MAGIC, 9, int)
162 #define /*X*/ SCULL_IOCXQSET    _IOWR(SCULL_IOC_MAGIC,10, int)
163 #define /*X*/ SCULL_IOCHQUANTUM _IO(SCULL_IOC_MAGIC,  11)
164 #define /*X*/ SCULL_IOCHQSET    _IO(SCULL_IOC_MAGIC,  12)
165
166 /*
167 * The other entities only have "Tell" and "Query", because they're
168 * not printed in the book, and there's no need to have all six.
169 * (The previous stuff was only there to show different ways to do it.
170 */

171 #define /*X*/ SCULL_P_IOCTSIZE _IO(SCULL_IOC_MAGIC,   13)
172 #define /*X*/ SCULL_P_IOCQSIZE _IO(SCULL_IOC_MAGIC,   14)
173 /* ... more to come */
174
175 #define /*X*/ SCULL_IOC_MAXNR 14
176
177 #endif /* _SCULL_H_ */


Home

File Index

All Tags

Tags by File

Tags referrers

C to HTML Conversion by ctoohtml