adreno_ringbuffer.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. /* Copyright (c) 2002,2007-2013, The Linux Foundation. All rights reserved.
  2. *
  3. * This program is free software; you can redistribute it and/or modify
  4. * it under the terms of the GNU General Public License version 2 and
  5. * only version 2 as published by the Free Software Foundation.
  6. *
  7. * This program is distributed in the hope that it will be useful,
  8. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  9. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  10. * GNU General Public License for more details.
  11. *
  12. */
  13. #ifndef __ADRENO_RINGBUFFER_H
  14. #define __ADRENO_RINGBUFFER_H
  15. /*
  16. * Adreno ringbuffer sizes in bytes - these are converted to
  17. * the appropriate log2 values in the code
  18. */
  19. #define KGSL_RB_SIZE (32 * 1024)
  20. /* CP timestamp register */
  21. #define REG_CP_TIMESTAMP REG_SCRATCH_REG0
  22. struct kgsl_device;
  23. struct kgsl_device_private;
  24. struct adreno_ringbuffer {
  25. struct kgsl_device *device;
  26. uint32_t flags;
  27. struct kgsl_memdesc buffer_desc;
  28. /*ringbuffer size */
  29. unsigned int sizedwords;
  30. unsigned int wptr; /* write pointer offset in dwords from baseaddr */
  31. unsigned int global_ts;
  32. };
  33. #define GSL_RB_WRITE(device, ring, gpuaddr, data) \
  34. do { \
  35. *ring = data; \
  36. wmb(); \
  37. kgsl_cffdump_setmem(device, gpuaddr, data, 4); \
  38. ring++; \
  39. gpuaddr += sizeof(uint); \
  40. } while (0)
  41. /* enable timestamp (...scratch0) memory shadowing */
  42. #define GSL_RB_MEMPTRS_SCRATCH_MASK 0x1
  43. /*
  44. * protected mode error checking below register address 0x800
  45. * note: if CP_INTERRUPT packet is used then checking needs
  46. * to change to below register address 0x7C8
  47. */
  48. #define GSL_RB_PROTECTED_MODE_CONTROL 0x200001F2
  49. int adreno_ringbuffer_issueibcmds(struct kgsl_device_private *dev_priv,
  50. struct kgsl_context *context,
  51. struct kgsl_cmdbatch *cmdbatch,
  52. uint32_t *timestamp);
  53. int adreno_ringbuffer_submitcmd(struct adreno_device *adreno_dev,
  54. struct kgsl_cmdbatch *cmdbatch);
  55. int adreno_ringbuffer_init(struct kgsl_device *device);
  56. int adreno_ringbuffer_warm_start(struct adreno_ringbuffer *rb);
  57. int adreno_ringbuffer_cold_start(struct adreno_ringbuffer *rb);
  58. void adreno_ringbuffer_stop(struct adreno_ringbuffer *rb);
  59. void adreno_ringbuffer_close(struct adreno_ringbuffer *rb);
  60. unsigned int adreno_ringbuffer_issuecmds(struct kgsl_device *device,
  61. struct adreno_context *drawctxt,
  62. unsigned int flags,
  63. unsigned int *cmdaddr,
  64. int sizedwords);
  65. void adreno_ringbuffer_submit(struct adreno_ringbuffer *rb);
  66. void kgsl_cp_intrcallback(struct kgsl_device *device);
  67. unsigned int *adreno_ringbuffer_allocspace(struct adreno_ringbuffer *rb,
  68. struct adreno_context *context,
  69. unsigned int numcmds);
  70. int adreno_ringbuffer_read_pfp_ucode(struct kgsl_device *device);
  71. int adreno_ringbuffer_read_pm4_ucode(struct kgsl_device *device);
  72. static inline int adreno_ringbuffer_count(struct adreno_ringbuffer *rb,
  73. unsigned int rptr)
  74. {
  75. if (rb->wptr >= rptr)
  76. return rb->wptr - rptr;
  77. return rb->wptr + rb->sizedwords - rptr;
  78. }
  79. /* Increment a value by 4 bytes with wrap-around based on size */
  80. static inline unsigned int adreno_ringbuffer_inc_wrapped(unsigned int val,
  81. unsigned int size)
  82. {
  83. return (val + sizeof(unsigned int)) % size;
  84. }
  85. /* Decrement a value by 4 bytes with wrap-around based on size */
  86. static inline unsigned int adreno_ringbuffer_dec_wrapped(unsigned int val,
  87. unsigned int size)
  88. {
  89. return (val + size - sizeof(unsigned int)) % size;
  90. }
  91. #endif /* __ADRENO_RINGBUFFER_H */