common.h 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110
  1. #ifndef _PCIDRIVER_COMMON_H
  2. #define _PCIDRIVER_COMMON_H
  3. #include "../pcilib/kmem.h"
  4. /*************************************************************************/
  5. /* Private data types and structures */
  6. /* Define an entry in the kmem list (this list is per device) */
  7. /* This list keeps references to the allocated kernel buffers */
  8. typedef struct {
  9. int id;
  10. enum dma_data_direction direction;
  11. struct list_head list;
  12. dma_addr_t dma_handle;
  13. unsigned long cpua;
  14. unsigned long size;
  15. unsigned long type;
  16. unsigned long align;
  17. unsigned long use;
  18. unsigned long item;
  19. spinlock_t lock;
  20. unsigned long mode;
  21. unsigned long refs;
  22. struct class_device_attribute sysfs_attr; /* initialized when adding the entry */
  23. } pcidriver_kmem_entry_t;
  24. /* Define an entry in the umem list (this list is per device) */
  25. /* This list keeps references to the SG lists for each mapped userspace region */
  26. typedef struct {
  27. int id;
  28. struct list_head list;
  29. unsigned int nr_pages; /* number of pages for this user memeory area */
  30. struct page **pages; /* list of pointers to the pages */
  31. unsigned int nents; /* actual entries in the scatter/gatter list (NOT nents for the map function, but the result) */
  32. struct scatterlist *sg; /* list of sg entries */
  33. struct class_device_attribute sysfs_attr; /* initialized when adding the entry */
  34. } pcidriver_umem_entry_t;
  35. /* Hold the driver private data */
  36. typedef struct {
  37. int devid; /* the device id */
  38. dev_t devno; /* device number (major and minor) */
  39. struct pci_dev *pdev; /* PCI device */
  40. struct class_device *class_dev; /* Class device */
  41. struct cdev cdev; /* char device struct */
  42. int mmap_mode; /* current mmap mode */
  43. int mmap_area; /* current PCI mmap area */
  44. #ifdef ENABLE_IRQ
  45. int irq_enabled; /* Non-zero if IRQ is enabled */
  46. int irq_count; /* Just an IRQ counter */
  47. wait_queue_head_t irq_queues[ PCIDRIVER_INT_MAXSOURCES ]; /* One queue per interrupt source */
  48. atomic_t irq_outstanding[ PCIDRIVER_INT_MAXSOURCES ]; /* Outstanding interrupts per queue */
  49. volatile unsigned int *bars_kmapped[6]; /* PCI BARs mmapped in kernel space */
  50. #endif
  51. spinlock_t kmemlist_lock; /* Spinlock to lock kmem list operations */
  52. struct list_head kmem_list; /* List of 'kmem_list_entry's associated with this device */
  53. pcidriver_kmem_entry_t *kmem_last_sync; /* Last accessed kmem entry */
  54. atomic_t kmem_count; /* id for next kmem entry */
  55. int kmem_cur_id; /* Currently selected kmem buffer, for mmap */
  56. spinlock_t umemlist_lock; /* Spinlock to lock umem list operations */
  57. struct list_head umem_list; /* List of 'umem_list_entry's associated with this device */
  58. atomic_t umem_count; /* id for next umem entry */
  59. int msi_mode; /* Flag specifying if interrupt have been initialized in MSI mode */
  60. atomic_t refs; /* Reference counter */
  61. } pcidriver_privdata_t;
  62. void pcidriver_module_get(pcidriver_privdata_t *privdata);
  63. void pcidriver_module_put(pcidriver_privdata_t *privdata);
  64. pcidriver_privdata_t *pcidriver_get_privdata(int devid);
  65. void pcidriver_put_privdata(pcidriver_privdata_t *privdata);
  66. /*************************************************************************/
  67. /* Some nice defines that make code more readable */
  68. /* This is to print nice info in the log */
  69. #ifdef DEBUG
  70. #define mod_info( args... ) \
  71. do { printk( KERN_INFO "%s - %s : ", MODNAME , __FUNCTION__ );\
  72. printk( args ); } while(0)
  73. #define mod_info_dbg( args... ) \
  74. do { printk( KERN_INFO "%s - %s : ", MODNAME , __FUNCTION__ );\
  75. printk( args ); } while(0)
  76. #else
  77. #define mod_info( args... ) \
  78. do { printk( KERN_INFO "%s: ", MODNAME );\
  79. printk( args ); } while(0)
  80. #define mod_info_dbg( args... )
  81. #endif
  82. #define mod_crit( args... ) \
  83. do { printk( KERN_CRIT "%s: ", MODNAME );\
  84. printk( args ); } while(0)
  85. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  86. #endif