vmod/vmodttl: fixed bug related to luns not ordered and/or not starting from zero.
[ht-drivers.git] / include / general_drvr.h
blob4136d1e04f4d8869740084c63f9b724e6fe67813
1 /**
2 * @file general_drvr.h
4 * @brief General driver definitions. For kernel space only.
6 * @author Yury GEORGIEVSKIY
8 * @date June, 2008
10 * <long description>
12 * @version 1.0 ygeorige 27/06/2008 Creation date.
14 #ifndef _GENERAL_DRVR_HEADER_H_INCLUDE_
15 #define _GENERAL_DRVR_HEADER_H_INCLUDE_
17 /*! @name Handy size operators
19 * Tnks to Linux kernel src
21 //@{
22 #ifndef KB
23 # define KB (1024UL)
24 #endif
26 #ifndef MB
27 #define MB (1024UL*KB)
28 #endif
30 #ifndef GB
31 #define GB (1024UL*MB)
32 #endif
34 #ifndef B2KB
35 #define B2KB(x) ((x) / 1024)
36 #endif
38 #ifndef B2MB
39 #define B2MB(x) (B2KB (B2KB (x)))
40 #endif
41 //@}
43 #ifndef memzero
44 #define memzero(_buf, _len) memset(_buf, 0, _len)
45 #endif
47 #if defined (__linux__) && defined(__KERNEL__)
48 /* for Linux kernel only */
50 #include <linux/vmalloc.h>
51 #include <linux/pci.h> /* for pci interface */
52 #include <data_tables.h> /* for 'bar_rdwr_t' && 'bar_map_t' */
54 /*! @name PCI BAR offsets
56 //@{
57 //!< they are in linux/pci_regs.h:83
58 //@}
60 //!< Get bar number [0 - 5] from the BAR offset
61 #define PCI_BAR(_bar) ((_bar - PCI_BASE_ADDRESS_0) >> 2)
63 //!< BAR bitmask (bits [5 4 3 2 1 0])
64 #define PCI_BAR_BIT(_bar) (1<<PCI_BAR(_bar))
66 #define MEM_BOUND (128*KB) /**< in bytes! what to use kmalloc or vmalloc */
68 /*! @name drvr_utils.c functions
70 //@{
71 int map_bars(struct list_head*, struct pci_dev*, int, char*);
72 int unmap_bars(struct list_head *, int);
73 bar_map_t* get_bar_descr(struct list_head*, int);
74 void bar_read(bar_map_t*, bar_rdwr_t*);
75 void bar_write(bar_map_t*, bar_rdwr_t*);
77 void _mmio_insb_shift(void __iomem*, u8*, int);
78 void _mmio_insw_shift(void __iomem*, u16*, int);
79 void _mmio_insl_shift(void __iomem*, u32*, int);
81 void _mmio_outsb_shift(void __iomem*, const u8*, int);
82 void _mmio_outsw_shift(void __iomem*, const u16*, int);
83 void _mmio_outsl_shift(void __iomem*, const u32*, int);
85 char* sysbrk(unsigned long);
86 void sysfree(char *, unsigned long);
87 //@}
90 /*! @name drvr_load_file.c functions
92 //@{
93 char* read_info_file(char*, int*);
94 //@}
96 //!< PCI device initialization on a run
97 /**
98 * INIT_PCI_DEVICE - macro used to initialize a specific pci device
100 * @param ptr - <B>struct pci_device_id</B> to init.
101 * @param vend - the 16 bit PCI Vendor ID
102 * @parma dev - the 16 bit PCI Device ID
104 * This macro is used to initialize 'on a run' a <B>struct pci_device_id</B>
105 * that matches a specific device. The subvendor and subdevice fields will be
106 * set to @b PCI_ANY_ID.
108 #define INIT_PCI_DEVICE(ptr, vend, dev) \
109 do { \
110 (ptr)->vendor = (vend); \
111 (ptr)->device = (dev); \
112 (ptr)->subvendor = PCI_ANY_ID; \
113 (ptr)->subdevice = PCI_ANY_ID; \
114 } while (0)
116 #endif /* (__linux__) && defined(__KERNEL__) */
117 #endif /* _GENERAL_DRVR_HEADER_H_INCLUDE_ */