common.h 3.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108
  1. #ifndef _PCIDRIVER_COMMON_H
  2. #define _PCIDRIVER_COMMON_H
  3. #include "pcilib_types.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. dev_t devno; /* device number (major and minor) */
  38. struct pci_dev *pdev; /* PCI device */
  39. struct class_device *class_dev; /* Class device */
  40. struct cdev cdev; /* char device struct */
  41. int mmap_mode; /* current mmap mode */
  42. int mmap_area; /* current PCI mmap area */
  43. #ifdef ENABLE_IRQ
  44. int irq_enabled; /* Non-zero if IRQ is enabled */
  45. int irq_count; /* Just an IRQ counter */
  46. wait_queue_head_t irq_queues[ PCIDRIVER_INT_MAXSOURCES ];
  47. /* One queue per interrupt source */
  48. atomic_t irq_outstanding[ PCIDRIVER_INT_MAXSOURCES ];
  49. /* Outstanding interrupts per queue */
  50. volatile unsigned int *bars_kmapped[6]; /* PCI BARs mmapped in kernel space */
  51. #endif
  52. spinlock_t kmemlist_lock; /* Spinlock to lock kmem list operations */
  53. struct list_head kmem_list; /* List of 'kmem_list_entry's associated with this device */
  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. /*************************************************************************/
  65. /* Some nice defines that make code more readable */
  66. /* This is to print nice info in the log */
  67. #ifdef DEBUG
  68. #define mod_info( args... ) \
  69. do { printk( KERN_INFO "%s - %s : ", MODNAME , __FUNCTION__ );\
  70. printk( args ); } while(0)
  71. #define mod_info_dbg( args... ) \
  72. do { printk( KERN_INFO "%s - %s : ", MODNAME , __FUNCTION__ );\
  73. printk( args ); } while(0)
  74. #else
  75. #define mod_info( args... ) \
  76. do { printk( KERN_INFO "%s: ", MODNAME );\
  77. printk( args ); } while(0)
  78. #define mod_info_dbg( args... )
  79. #endif
  80. #define mod_crit( args... ) \
  81. do { printk( KERN_CRIT "%s: ", MODNAME );\
  82. printk( args ); } while(0)
  83. #define MIN(a, b) ((a) < (b) ? (a) : (b))
  84. #endif