host1x_bo.h 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. /*
  2. * Tegra host1x Memory Management Abstraction header
  3. *
  4. * Copyright (c) 2012-2013, NVIDIA Corporation.
  5. *
  6. * This program is free software; you can redistribute it and/or modify it
  7. * under the terms and conditions of the GNU General Public License,
  8. * version 2, as published by the Free Software Foundation.
  9. *
  10. * This program is distributed in the hope it will be useful, but WITHOUT
  11. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  12. * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
  13. * more details.
  14. *
  15. * You should have received a copy of the GNU General Public License
  16. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  17. */
  18. #ifndef _HOST1X_BO_H
  19. #define _HOST1X_BO_H
  20. struct host1x_bo;
  21. struct host1x_bo_ops {
  22. struct host1x_bo *(*get)(struct host1x_bo *bo);
  23. void (*put)(struct host1x_bo *bo);
  24. dma_addr_t (*pin)(struct host1x_bo *bo, struct sg_table **sgt);
  25. void (*unpin)(struct host1x_bo *bo, struct sg_table *sgt);
  26. void *(*mmap)(struct host1x_bo *bo);
  27. void (*munmap)(struct host1x_bo *bo, void *addr);
  28. void *(*kmap)(struct host1x_bo *bo, unsigned int pagenum);
  29. void (*kunmap)(struct host1x_bo *bo, unsigned int pagenum, void *addr);
  30. };
  31. struct host1x_bo {
  32. const struct host1x_bo_ops *ops;
  33. };
  34. static inline void host1x_bo_init(struct host1x_bo *bo,
  35. const struct host1x_bo_ops *ops)
  36. {
  37. bo->ops = ops;
  38. }
  39. static inline struct host1x_bo *host1x_bo_get(struct host1x_bo *bo)
  40. {
  41. return bo->ops->get(bo);
  42. }
  43. static inline void host1x_bo_put(struct host1x_bo *bo)
  44. {
  45. bo->ops->put(bo);
  46. }
  47. static inline dma_addr_t host1x_bo_pin(struct host1x_bo *bo,
  48. struct sg_table **sgt)
  49. {
  50. return bo->ops->pin(bo, sgt);
  51. }
  52. static inline void host1x_bo_unpin(struct host1x_bo *bo, struct sg_table *sgt)
  53. {
  54. bo->ops->unpin(bo, sgt);
  55. }
  56. static inline void *host1x_bo_mmap(struct host1x_bo *bo)
  57. {
  58. return bo->ops->mmap(bo);
  59. }
  60. static inline void host1x_bo_munmap(struct host1x_bo *bo, void *addr)
  61. {
  62. bo->ops->munmap(bo, addr);
  63. }
  64. static inline void *host1x_bo_kmap(struct host1x_bo *bo, unsigned int pagenum)
  65. {
  66. return bo->ops->kmap(bo, pagenum);
  67. }
  68. static inline void host1x_bo_kunmap(struct host1x_bo *bo,
  69. unsigned int pagenum, void *addr)
  70. {
  71. bo->ops->kunmap(bo, pagenum, addr);
  72. }
  73. #endif