Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 1 | /* |
| 2 | * The USB Monitor, inspired by Dave Harding's USBMon. |
Pete Zaitcev | da5ca00 | 2005-08-16 15:16:46 -0700 | [diff] [blame] | 3 | * |
| 4 | * Copyright (C) 2005 Pete Zaitcev (zaitcev@redhat.com) |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 5 | */ |
| 6 | |
| 7 | #ifndef __USB_MON_H |
| 8 | #define __USB_MON_H |
| 9 | |
| 10 | #include <linux/list.h> |
| 11 | #include <linux/slab.h> |
| 12 | #include <linux/kref.h> |
| 13 | /* #include <linux/usb.h> */ /* We use struct pointers only in this header */ |
| 14 | |
| 15 | #define TAG "usbmon" |
| 16 | |
| 17 | struct mon_bus { |
| 18 | struct list_head bus_link; |
| 19 | spinlock_t lock; |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 20 | struct usb_bus *u_bus; |
| 21 | |
| 22 | int text_inited; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 23 | struct dentry *dent_s; /* Debugging file */ |
| 24 | struct dentry *dent_t; /* Text interface file */ |
Alan Stern | 4d6cd48 | 2006-08-30 11:35:21 -0400 | [diff] [blame] | 25 | int uses_dma; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 26 | |
| 27 | /* Ref */ |
| 28 | int nreaders; /* Under mon_lock AND mbus->lock */ |
| 29 | struct list_head r_list; /* Chain of readers (usually one) */ |
| 30 | struct kref ref; /* Under mon_lock */ |
| 31 | |
| 32 | /* Stats */ |
Pete Zaitcev | 5b1c674 | 2006-06-09 20:10:10 -0700 | [diff] [blame] | 33 | unsigned int cnt_events; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 34 | unsigned int cnt_text_lost; |
| 35 | }; |
| 36 | |
| 37 | /* |
| 38 | * An instance of a process which opened a file (but can fork later) |
| 39 | */ |
| 40 | struct mon_reader { |
| 41 | struct list_head r_link; |
| 42 | struct mon_bus *m_bus; |
| 43 | void *r_data; /* Use container_of instead? */ |
| 44 | |
| 45 | void (*rnf_submit)(void *data, struct urb *urb); |
Pete Zaitcev | 12e72fe | 2006-06-09 22:03:32 -0700 | [diff] [blame] | 46 | void (*rnf_error)(void *data, struct urb *urb, int error); |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 47 | void (*rnf_complete)(void *data, struct urb *urb); |
| 48 | }; |
| 49 | |
| 50 | void mon_reader_add(struct mon_bus *mbus, struct mon_reader *r); |
| 51 | void mon_reader_del(struct mon_bus *mbus, struct mon_reader *r); |
| 52 | |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 53 | struct mon_bus *mon_bus_lookup(unsigned int num); |
| 54 | |
| 55 | int /*bool*/ mon_text_add(struct mon_bus *mbus, const struct usb_bus *ubus); |
| 56 | void mon_text_del(struct mon_bus *mbus); |
| 57 | // void mon_bin_add(struct mon_bus *); |
| 58 | |
| 59 | int __init mon_text_init(void); |
Pete Zaitcev | 21641e3 | 2007-02-20 10:37:52 -0800 | [diff] [blame] | 60 | void mon_text_exit(void); |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 61 | int __init mon_bin_init(void); |
Pete Zaitcev | 21641e3 | 2007-02-20 10:37:52 -0800 | [diff] [blame] | 62 | void mon_bin_exit(void); |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 63 | |
Pete Zaitcev | 0256839 | 2005-08-15 16:53:57 -0700 | [diff] [blame] | 64 | /* |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 65 | * DMA interface. |
| 66 | * |
| 67 | * XXX The vectored side needs a serious re-thinking. Abstracting vectors, |
| 68 | * like in Paolo's original patch, produces a double pkmap. We need an idea. |
| 69 | */ |
Pete Zaitcev | 0256839 | 2005-08-15 16:53:57 -0700 | [diff] [blame] | 70 | extern char mon_dmapeek(unsigned char *dst, dma_addr_t dma_addr, int len); |
| 71 | |
Pete Zaitcev | 6f23ee1 | 2006-12-30 22:43:10 -0800 | [diff] [blame] | 72 | struct mon_reader_bin; |
| 73 | extern void mon_dmapeek_vec(const struct mon_reader_bin *rp, |
| 74 | unsigned int offset, dma_addr_t dma_addr, unsigned int len); |
| 75 | extern unsigned int mon_copy_to_buff(const struct mon_reader_bin *rp, |
| 76 | unsigned int offset, const unsigned char *from, unsigned int len); |
| 77 | |
| 78 | /* |
| 79 | */ |
Arjan van de Ven | 4186ecf | 2006-01-11 15:55:29 +0100 | [diff] [blame] | 80 | extern struct mutex mon_lock; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 81 | |
Luiz Fernando N. Capitulino | 066202d | 2006-08-05 20:37:11 -0300 | [diff] [blame] | 82 | extern const struct file_operations mon_fops_stat; |
Linus Torvalds | 1da177e | 2005-04-16 15:20:36 -0700 | [diff] [blame] | 83 | |
| 84 | #endif /* __USB_MON_H */ |