/* * lcibuf.h -- definitions for the lci buffer driver and listen driver * by Anthony Petillo * examples copied from Alessandro Rubini * */ #ifndef _LCIBUF_H_ #define _LCIBUF_H_ #include /* needed for the _IOW etc stuff used later */ /* version dependencies have been confined to a separate file */ #include "sysdep.h" //#include /* * Macros to help debugging */ #undef PDEBUG /* undef it, just in case */ #ifdef DDEBUG # ifdef __KERNEL__ /* This one if debugging is on, and kernel space */ # define PDEBUG(fmt, args...) printk( KERN_DEBUG "lci: " fmt, ## args) # else /* This one for user space */ # define PDEBUG(fmt, args...) fprintf(stderr, fmt, ## args) # endif #else # define PDEBUG(fmt, args...) /* not debugging: nothing */ #endif #ifdef CONFIG_DEVFS_FS /* only if enabled, to avoid errors in 2.0 */ #include #else typedef void * devfs_handle_t; /* avoid #ifdef inside the structure */ #endif /* * This is somehow a hack: avoid ifdefs in the cleanup code by declaring * an empty procedure as a placeholder for devfs_unregister. This is * only done *unless* was included, as that * header already implements placeholder for all the devfs functions */ /*............................................... degin-tag devfs-ifdef */ #ifndef DEVFS_FL_DEFAULT extern inline void devfs_unregister(devfs_handle_t de) {} #endif extern devfs_handle_t lcibuf_devfs_dir; typedef struct tag_lci_device { char * pbuf; /* memory allocated for buffer - circular queue */ char * pbuf_end; /* end of buffer pointer */ char * volatile head; char * volatile tail; unsigned int size; /* size of the buffer */ struct semaphore sem; /* mutual exclusion semaphore */ volatile unsigned int usage_count; /* number open */ volatile unsigned int rdwr_count; /* number open read/write */ int stop_buffering_in_direct; /* if true, stop buffering input data in direct mode */ struct wait_queue * in_queue; struct proc_dir_entry *ent; // used with lwbuf proc entries, mainly to // update the size of the buffer type_port port_type; } type_lci_device; /* * Split minors in two parts */ #define TYPE(dev) (MINOR(dev) >> 4) /* high nibble */ #define NUM(dev) (MINOR(dev) & 0xf) /* low nibble */ /* * The different configurable parameters */ extern int lcibuf_major; /* main.c */ /* * Ioctl definitions */ /* Use 'k' as magic number */ #define LCIBUF_IOC_MAGIC 'k' #define LCI_LISTEN_IOC_MAGIC 'j' // lci buffer functions #define LCIBUF_IOCRESET _IO(LCIBUF_IOC_MAGIC, 0) #define LCIBUF_IOCSIZE _IO(LCIBUF_IOC_MAGIC, 1) #define LCIBUF_IOCBUFFERING _IO(LCIBUF_IOC_MAGIC, 2) // lci listen functions #define LCI_LISTEN_IOCRESET _IO(LCI_LISTEN_IOC_MAGIC, 0) /* * S means "Set" through a ptr, * T means "Tell" directly with the argument value * G means "Get": reply by setting through a pointer * Q means "Query": response is on the return value * X means "eXchange": G and S atomically * H means "sHift": T and Q atomically */ //#define LCIBUF_IOCSQUANTUM _IOW(LCIBUF_IOC_MAGIC, 1, scull_quantum) //#define LCIBUF_IOCSQSET _IOW(LCIBUF_IOC_MAGIC, 2, scull_qset) //#define LCIBUF_IOCTQUANTUM _IO(LCIBUF_IOC_MAGIC, 3) //#define LCIBUF_IOCTQSET _IO(LCIBUF_IOC_MAGIC, 4) //#define LCIBUF_IOCGQUANTUM _IOR(LCIBUF_IOC_MAGIC, 5, scull_quantum) //#define LCIBUF_IOCGQSET _IOR(LCIBUF_IOC_MAGIC, 6, scull_qset) //#define LCIBUF_IOCQQUANTUM _IO(LCIBUF_IOC_MAGIC, 7) //#define LCIBUF_IOCQQSET _IO(LCIBUF_IOC_MAGIC, 8) //#define LCIBUF_IOCXQUANTUM _IOWR(LCIBUF_IOC_MAGIC, 9, scull_quantum) //#define LCIBUF_IOCXQSET _IOWR(LCIBUF_IOC_MAGIC,10, scull_qset) //#define LCIBUF_IOCHQUANTUM _IO(LCIBUF_IOC_MAGIC, 11) //#define LCIBUF_IOCHQSET _IO(LCIBUF_IOC_MAGIC, 12) /* * The other entities only have "Tell" and "Query", because they're * not printed in the book, and there's no need to have all six. * (The previous stuff was only there to show different ways to do it. */ #define LCIBUF_P_IOCTSIZE _IO(LCIBUF_IOC_MAGIC, 13) #define LCIBUF_P_IOCQSIZE _IO(LCIBUF_IOC_MAGIC, 14) /* ... more to come */ #define LCIBUF_IOCHARDRESET _IO(LCIBUF_IOC_MAGIC, 15) /* debugging tool */ #define LCIBUF_IOC_MAXNR 15 #define LCI_LISTEN_IOC_MAXNR 15 #endif /* _LCIBUF_H_ */