android_pmem.h 5.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166
  1. /* include/linux/android_pmem.h
  2. *
  3. * Copyright (C) 2007 Google, Inc.
  4. *
  5. * This software is licensed under the terms of the GNU General Public
  6. * License version 2, as published by the Free Software Foundation, and
  7. * may be copied, distributed, and modified under those terms.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. */
  15. #ifndef _ANDROID_PMEM_H_
  16. #define _ANDROID_PMEM_H_
  17. #include <linux/fs.h>
  18. #define PMEM_KERNEL_TEST_MAGIC 0xc0
  19. #define PMEM_KERNEL_TEST_NOMINAL_TEST_IOCTL \
  20. _IO(PMEM_KERNEL_TEST_MAGIC, 1)
  21. #define PMEM_KERNEL_TEST_ADVERSARIAL_TEST_IOCTL \
  22. _IO(PMEM_KERNEL_TEST_MAGIC, 2)
  23. #define PMEM_KERNEL_TEST_HUGE_ALLOCATION_TEST_IOCTL \
  24. _IO(PMEM_KERNEL_TEST_MAGIC, 3)
  25. #define PMEM_KERNEL_TEST_FREE_UNALLOCATED_TEST_IOCTL \
  26. _IO(PMEM_KERNEL_TEST_MAGIC, 4)
  27. #define PMEM_KERNEL_TEST_LARGE_REGION_NUMBER_TEST_IOCTL \
  28. _IO(PMEM_KERNEL_TEST_MAGIC, 5)
  29. #define PMEM_IOCTL_MAGIC 'p'
  30. #define PMEM_GET_PHYS _IOW(PMEM_IOCTL_MAGIC, 1, unsigned int)
  31. #define PMEM_MAP _IOW(PMEM_IOCTL_MAGIC, 2, unsigned int)
  32. #define PMEM_GET_SIZE _IOW(PMEM_IOCTL_MAGIC, 3, unsigned int)
  33. #define PMEM_UNMAP _IOW(PMEM_IOCTL_MAGIC, 4, unsigned int)
  34. /* This ioctl will allocate pmem space, backing the file, it will fail
  35. * if the file already has an allocation, pass it the len as the argument
  36. * to the ioctl */
  37. #define PMEM_ALLOCATE _IOW(PMEM_IOCTL_MAGIC, 5, unsigned int)
  38. /* This will connect a one pmem file to another, pass the file that is already
  39. * backed in memory as the argument to the ioctl
  40. */
  41. #define PMEM_CONNECT _IOW(PMEM_IOCTL_MAGIC, 6, unsigned int)
  42. /* Returns the total size of the pmem region it is sent to as a pmem_region
  43. * struct (with offset set to 0).
  44. */
  45. #define PMEM_GET_TOTAL_SIZE _IOW(PMEM_IOCTL_MAGIC, 7, unsigned int)
  46. /* Revokes gpu registers and resets the gpu. Pass a pointer to the
  47. * start of the mapped gpu regs (the vaddr returned by mmap) as the argument.
  48. */
  49. #define HW3D_REVOKE_GPU _IOW(PMEM_IOCTL_MAGIC, 8, unsigned int)
  50. #define HW3D_GRANT_GPU _IOW(PMEM_IOCTL_MAGIC, 9, unsigned int)
  51. #define HW3D_WAIT_FOR_INTERRUPT _IOW(PMEM_IOCTL_MAGIC, 10, unsigned int)
  52. #define PMEM_CLEAN_INV_CACHES _IOW(PMEM_IOCTL_MAGIC, 11, unsigned int)
  53. #define PMEM_CLEAN_CACHES _IOW(PMEM_IOCTL_MAGIC, 12, unsigned int)
  54. #define PMEM_INV_CACHES _IOW(PMEM_IOCTL_MAGIC, 13, unsigned int)
  55. #define PMEM_GET_FREE_SPACE _IOW(PMEM_IOCTL_MAGIC, 14, unsigned int)
  56. #define PMEM_ALLOCATE_ALIGNED _IOW(PMEM_IOCTL_MAGIC, 15, unsigned int)
  57. struct pmem_region {
  58. unsigned long offset;
  59. unsigned long len;
  60. };
  61. struct pmem_addr {
  62. unsigned long vaddr;
  63. unsigned long offset;
  64. unsigned long length;
  65. };
  66. struct pmem_freespace {
  67. unsigned long total;
  68. unsigned long largest;
  69. };
  70. struct pmem_allocation {
  71. unsigned long size;
  72. unsigned int align;
  73. };
  74. #ifdef __KERNEL__
  75. int get_pmem_file(unsigned int fd, unsigned long *start, unsigned long *vstart,
  76. unsigned long *end, struct file **filp);
  77. int get_pmem_fd(int fd, unsigned long *start, unsigned long *end);
  78. int get_pmem_user_addr(struct file *file, unsigned long *start,
  79. unsigned long *end);
  80. void put_pmem_file(struct file* file);
  81. void put_pmem_fd(int fd);
  82. void flush_pmem_fd(int fd, unsigned long start, unsigned long len);
  83. void flush_pmem_file(struct file *file, unsigned long start, unsigned long len);
  84. int pmem_cache_maint(struct file *file, unsigned int cmd,
  85. struct pmem_addr *pmem_addr);
  86. enum pmem_allocator_type {
  87. /* Zero is a default in platform PMEM structures in the board files,
  88. * when the "allocator_type" structure element is not explicitly
  89. * defined
  90. */
  91. PMEM_ALLOCATORTYPE_BITMAP = 0, /* forced to be zero here */
  92. PMEM_ALLOCATORTYPE_SYSTEM,
  93. PMEM_ALLOCATORTYPE_ALLORNOTHING,
  94. PMEM_ALLOCATORTYPE_BUDDYBESTFIT,
  95. PMEM_ALLOCATORTYPE_MAX,
  96. };
  97. /* kernel api names for board specific data structures */
  98. #define PMEM_KERNEL_EBI1_DATA_NAME "pmem_kernel_ebi1"
  99. #define PMEM_KERNEL_SMI_DATA_NAME "pmem_kernel_smi"
  100. struct android_pmem_platform_data
  101. {
  102. const char* name;
  103. /* size of memory region */
  104. unsigned long size;
  105. enum pmem_allocator_type allocator_type;
  106. /* treated as a 'hidden' variable in the board files. Can be
  107. * set, but default is the system init value of 0 which becomes a
  108. * quantum of 4K pages.
  109. */
  110. unsigned int quantum;
  111. /* set to indicate maps of this region should be cached, if a mix of
  112. * cached and uncached is desired, set this and open the device with
  113. * O_SYNC to get an uncached region */
  114. unsigned cached;
  115. /* The MSM7k has bits to enable a write buffer in the bus controller*/
  116. unsigned buffered;
  117. /* which memory type (i.e. SMI, EBI1) this PMEM device is backed by */
  118. unsigned memory_type;
  119. /*
  120. * function to be called when the number of allocations goes from
  121. * 0 -> 1
  122. */
  123. int (*request_region)(void *);
  124. /*
  125. * function to be called when the number of allocations goes from
  126. * 1 -> 0
  127. */
  128. int (*release_region)(void *);
  129. /*
  130. * function to be called upon pmem registration
  131. */
  132. void *(*setup_region)(void);
  133. /*
  134. * indicates that this region should be mapped/unmaped as needed
  135. */
  136. int map_on_demand;
  137. };
  138. int pmem_setup(struct android_pmem_platform_data *pdata,
  139. long (*ioctl)(struct file *, unsigned int, unsigned long),
  140. int (*release)(struct inode *, struct file *));
  141. int pmem_remap(struct pmem_region *region, struct file *file,
  142. unsigned operation);
  143. #endif /* __KERNEL__ */
  144. #endif //_ANDROID_PPP_H_