compat.h 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758
  1. /**
  2. *
  3. * @file compat.h
  4. * @author Michael Stapelberg
  5. * @date 2009-04-05
  6. * @brief Contains compatibility definitions for the different linux kernel versions to avoid
  7. * putting ifdefs all over the driver code.
  8. *
  9. */
  10. #ifndef _COMPAT_H
  11. #define _COMPAT_H
  12. #include <linux/version.h>
  13. /* Check macros and kernel version first */
  14. #ifndef KERNEL_VERSION
  15. # error "No KERNEL_VERSION macro! Stopping."
  16. #endif
  17. #ifndef LINUX_VERSION_CODE
  18. # error "No LINUX_VERSION_CODE macro! Stopping."
  19. #endif
  20. #if LINUX_VERSION_CODE < KERNEL_VERSION(3,2,0)
  21. # error "Linux 3.2 and latter are supported"
  22. #endif
  23. /* VM_RESERVED is removed in 3.7-rc1 */
  24. #ifndef VM_RESERVED
  25. # define VM_RESERVED (VM_DONTEXPAND | VM_DONTDUMP)
  26. #endif
  27. #if LINUX_VERSION_CODE >= KERNEL_VERSION(3,8,0)
  28. # define __devinit
  29. # define __devexit
  30. # define __devinitdata
  31. #endif
  32. #if LINUX_VERSION_CODE >= KERNEL_VERSION(4,9,0)
  33. # define get_user_pages_compat(vma, nr, pages) get_user_pages(vma, nr, FOLL_WRITE, pages, NULL)
  34. #elif LINUX_VERSION_CODE >= KERNEL_VERSION(4,6,0)
  35. # define get_user_pages_compat(vma, nr, pages) get_user_pages(vma, nr, 1, 0, pages, NULL)
  36. #elif (LINUX_VERSION_CODE >= KERNEL_VERSION(4,4,159))
  37. // Looks like some updates from 4.9 were backported to 4.4 LTS kernel. On Ubuntu, at least 4.4.159 needs this variant
  38. # define get_user_pages_compat(vma, nr, pages) get_user_pages(current, current->mm, vma, nr, FOLL_WRITE, pages, NULL)
  39. #else
  40. # define get_user_pages_compat(vma, nr, pages) get_user_pages(current, current->mm, vma, nr, 1, 0, pages, NULL)
  41. #endif
  42. #if LINUX_VERSION_CODE >= KERNEL_VERSION(5,5,0)
  43. # define ioremap_nocache ioremap
  44. // ioremap_nocache and ioremap are now platform independent and identical, as of
  45. // Kernel Version 5.5
  46. // https://lore.kernel.org/linux-mips/20191209194819.GA28157@lst.de/T/
  47. #endif
  48. #endif