linux_compat.h
上传用户:jlfgdled
上传日期:2013-04-10
资源大小:33168k
文件大小:8k
源码类别:

Linux/Unix编程

开发平台:

Unix_Linux

  1. /* drivers/message/fusion/linux_compat.h */
  2. #ifndef FUSION_LINUX_COMPAT_H
  3. #define FUSION_LINUX_COMPAT_H
  4. /*{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  5. #include <linux/version.h>
  6. #include <linux/config.h>
  7. #include <linux/kernel.h>
  8. #include <linux/pci.h>
  9. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  10. #ifndef rwlock_init
  11. #define rwlock_init(x) do { *(x) = RW_LOCK_UNLOCKED; } while(0)
  12. #endif
  13. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,4,0)
  14. #define SET_NICE(current,x) do {(current)->nice = (x);} while (0)
  15. #else
  16. #define SET_NICE(current,x)
  17. #endif
  18. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,0)
  19. #define pci_enable_device(pdev) (0)
  20. #define SCSI_DATA_UNKNOWN 0
  21. #define SCSI_DATA_WRITE 1
  22. #define SCSI_DATA_READ 2
  23. #define SCSI_DATA_NONE 3
  24. #endif
  25. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,4)
  26. #define pci_set_dma_mask(pdev, mask) (0)
  27. #define scsi_set_pci_device(sh, pdev) (0)
  28. #endif
  29. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,0)
  30. # if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
  31. typedef unsigned int dma_addr_t;
  32. # endif
  33. #else
  34. # if LINUX_VERSION_CODE < KERNEL_VERSION(2,3,42)
  35. typedef unsigned int dma_addr_t;
  36. # endif
  37. #endif
  38. #if LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18)
  39. /*{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  40. /* This block snipped from lk-2.2.18/include/linux/init.h { */
  41. /*
  42.  * Used for initialization calls..
  43.  */
  44. typedef int (*initcall_t)(void);
  45. typedef void (*exitcall_t)(void);
  46. #define __init_call __attribute__ ((unused,__section__ (".initcall.init")))
  47. #define __exit_call __attribute__ ((unused,__section__ (".exitcall.exit")))
  48. extern initcall_t __initcall_start, __initcall_end;
  49. #define __initcall(fn)
  50. static initcall_t __initcall_##fn __init_call = fn
  51. #define __exitcall(fn)
  52. static exitcall_t __exitcall_##fn __exit_call = fn
  53. #ifdef MODULE
  54. /* These macros create a dummy inline: gcc 2.9x does not count alias
  55.  as usage, hence the `unused function' warning when __init functions
  56.  are declared static. We use the dummy __*_module_inline functions
  57.  both to kill the warning and check the type of the init/cleanup
  58.  function. */
  59. typedef int (*__init_module_func_t)(void);
  60. typedef void (*__cleanup_module_func_t)(void);
  61. #define module_init(x) 
  62. int init_module(void) __attribute__((alias(#x))); 
  63. extern inline __init_module_func_t __init_module_inline(void) 
  64. { return x; }
  65. #define module_exit(x) 
  66. void cleanup_module(void) __attribute__((alias(#x))); 
  67. extern inline __cleanup_module_func_t __cleanup_module_inline(void) 
  68. { return x; }
  69. #else
  70. #define module_init(x) __initcall(x);
  71. #define module_exit(x) __exitcall(x);
  72. #endif
  73. /* } block snipped from lk-2.2.18/include/linux/init.h */
  74. /* This block snipped from lk-2.2.18/include/linux/sched.h { */
  75. /*
  76.  * Used prior to schedule_timeout calls..
  77.  */
  78. #define __set_current_state(state_value) do { current->state = state_value; } while (0)
  79. #ifdef __SMP__
  80. #define set_current_state(state_value) do { __set_current_state(state_value); mb(); } while (0)
  81. #else
  82. #define set_current_state(state_value) __set_current_state(state_value)
  83. #endif
  84. /* } block snipped from lk-2.2.18/include/linux/sched.h */
  85. /* procfs compat stuff... */
  86. #define proc_mkdir(x,y) create_proc_entry(x, S_IFDIR, y)
  87. /* MUTEX compat stuff... */
  88. #define DECLARE_MUTEX(name) struct semaphore name=MUTEX
  89. #define DECLARE_MUTEX_LOCKED(name) struct semaphore name=MUTEX_LOCKED
  90. #define init_MUTEX(x) *(x)=MUTEX
  91. #define init_MUTEX_LOCKED(x) *(x)=MUTEX_LOCKED
  92. /* Wait queues. */
  93. #define DECLARE_WAIT_QUEUE_HEAD(name)
  94. struct wait_queue * (name) = NULL
  95. #define DECLARE_WAITQUEUE(name, task)
  96. struct wait_queue (name) = { (task), NULL }
  97. #if defined(__sparc__) && defined(__sparc_v9__)
  98. /* The sparc64 ioremap implementation is wrong in 2.2.x,
  99.  * but fixing it would break all of the drivers which
  100.  * workaround it.  Fixed in 2.3.x onward. -DaveM
  101.  */
  102. #define ARCH_IOREMAP(base) ((unsigned long) (base))
  103. #else
  104. #define ARCH_IOREMAP(base) ioremap(base)
  105. #endif
  106. /*=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  107. #else /* LINUX_VERSION_CODE must be >= KERNEL_VERSION(2,2,18) */
  108. /* No ioremap bugs in >2.3.x kernels. */
  109. #define ARCH_IOREMAP(base) ioremap(base)
  110. /*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  111. #endif /* LINUX_VERSION_CODE < KERNEL_VERSION(2,2,18) */
  112. /*
  113.  * Inclined to use:
  114.  *   #if LINUX_VERSION_CODE < KERNEL_VERSION(2,4,10)
  115.  * here, but MODULE_LICENSE defined in 2.4.9-6 and 2.4.9-13
  116.  * breaks the rule:-(
  117.  */
  118. #ifndef MODULE_LICENSE
  119. #define MODULE_LICENSE(license)
  120. #endif
  121. /* PCI/driver subsystem { */
  122. #ifndef pci_for_each_dev
  123. #define pci_for_each_dev(dev) for((dev)=pci_devices; (dev)!=NULL; (dev)=(dev)->next)
  124. #define pci_peek_next_dev(dev) ((dev)->next ? (dev)->next : NULL)
  125. #define DEVICE_COUNT_RESOURCE           6
  126. #define PCI_BASEADDR_FLAGS(idx)         base_address[idx]
  127. #define PCI_BASEADDR_START(idx)         base_address[idx] & ~0xFUL
  128. /*
  129.  * We have to keep track of the original value using
  130.  * a temporary, and not by just sticking pdev->base_address[x]
  131.  * back.  pdev->base_address[x] is an opaque cookie that can
  132.  * be used by the PCI implementation on a given Linux port
  133.  * for any purpose. -DaveM
  134.  */
  135. #define PCI_BASEADDR_SIZE(__pdev, __idx) 
  136. ({ unsigned int size, tmp; 
  137. pci_read_config_dword(__pdev, PCI_BASE_ADDRESS_0 + (4*(__idx)), &tmp); 
  138. pci_write_config_dword(__pdev, PCI_BASE_ADDRESS_0 + (4*(__idx)), 0xffffffff); 
  139. pci_read_config_dword(__pdev, PCI_BASE_ADDRESS_0 + (4*(__idx)), &size); 
  140. pci_write_config_dword(__pdev, PCI_BASE_ADDRESS_0 + (4*(__idx)), tmp); 
  141. (4 - size); 
  142. })
  143. #else
  144. #define pci_peek_next_dev(dev) ((dev) != pci_dev_g(&pci_devices) ? pci_dev_g((dev)->global_list.next) : NULL)
  145. #define PCI_BASEADDR_FLAGS(idx)         resource[idx].flags
  146. #define PCI_BASEADDR_START(idx)         resource[idx].start
  147. #define PCI_BASEADDR_SIZE(dev,idx)      (dev)->resource[idx].end - (dev)->resource[idx].start + 1
  148. #endif /* } ifndef pci_for_each_dev */
  149. /* Compatability for the 2.3.x PCI DMA API. */
  150. #ifndef PCI_DMA_BIDIRECTIONAL
  151. /*{-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  152. #define PCI_DMA_BIDIRECTIONAL 0
  153. #define PCI_DMA_TODEVICE 1
  154. #define PCI_DMA_FROMDEVICE 2
  155. #define PCI_DMA_NONE 3
  156. #ifdef __KERNEL__
  157. #include <asm/page.h>
  158. /* Pure 2^n version of get_order */
  159. static __inline__ int __get_order(unsigned long size)
  160. {
  161. int order;
  162. size = (size-1) >> (PAGE_SHIFT-1);
  163. order = -1;
  164. do {
  165. size >>= 1;
  166. order++;
  167. } while (size);
  168. return order;
  169. }
  170. #endif
  171. #define pci_alloc_consistent(hwdev, size, dma_handle) 
  172. ({ void *__ret = (void *)__get_free_pages(GFP_ATOMIC, __get_order(size)); 
  173. if (__ret != NULL) { 
  174. memset(__ret, 0, size); 
  175. *(dma_handle) = virt_to_bus(__ret); 
  176. __ret; 
  177. })
  178. #define pci_free_consistent(hwdev, size, vaddr, dma_handle) 
  179. free_pages((unsigned long)vaddr, __get_order(size))
  180. #define pci_map_single(hwdev, ptr, size, direction) 
  181. virt_to_bus(ptr);
  182. #define pci_unmap_single(hwdev, dma_addr, size, direction) 
  183. do { /* Nothing to do */ } while (0)
  184. #define pci_map_sg(hwdev, sg, nents, direction) (nents)
  185. #define pci_unmap_sg(hwdev, sg, nents, direction) 
  186. do { /* Nothing to do */ } while(0)
  187. #define sg_dma_address(sg) (virt_to_bus((sg)->address))
  188. #define sg_dma_len(sg) ((sg)->length)
  189. /*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  190. #endif /* PCI_DMA_BIDIRECTIONAL */
  191. /*
  192.  *  With the new command queuing code in the SCSI mid-layer we no longer have
  193.  *  to hold the io_request_lock spin lock when calling the scsi_done routine.
  194.  *  For now we only do this with the 2.5.1 kernel or newer.
  195.  */
  196. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,1)
  197.         #define MPT_HOST_LOCK(flags)
  198.         #define MPT_HOST_UNLOCK(flags)
  199. #else
  200.         #define MPT_HOST_LOCK(flags) 
  201.                 spin_lock_irqsave(&io_request_lock, flags)
  202.         #define MPT_HOST_UNLOCK(flags) 
  203.                 spin_unlock_irqrestore(&io_request_lock, flags)
  204. #endif
  205. /*
  206.  *  We use our new error handling code if the kernel version is 2.5.1 or newer.
  207.  */
  208. #if LINUX_VERSION_CODE >= KERNEL_VERSION(2,5,1)
  209.         #define MPT_SCSI_USE_NEW_EH
  210. #endif
  211. /*}-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=*/
  212. #endif /* _LINUX_COMPAT_H */