host.fuc 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. /*
  2. * Copyright 2013 Red Hat Inc.
  3. *
  4. * Permission is hereby granted, free of charge, to any person obtaining a
  5. * copy of this software and associated documentation files (the "Software"),
  6. * to deal in the Software without restriction, including without limitation
  7. * the rights to use, copy, modify, merge, publish, distribute, sublicense,
  8. * and/or sell copies of the Software, and to permit persons to whom the
  9. * Software is furnished to do so, subject to the following conditions:
  10. *
  11. * The above copyright notice and this permission notice shall be included in
  12. * all copies or substantial portions of the Software.
  13. *
  14. * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
  15. * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
  16. * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
  17. * THE COPYRIGHT HOLDER(S) OR AUTHOR(S) BE LIABLE FOR ANY CLAIM, DAMAGES OR
  18. * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
  19. * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
  20. * OTHER DEALINGS IN THE SOFTWARE.
  21. *
  22. * Authors: Ben Skeggs
  23. */
  24. #ifdef INCLUDE_PROC
  25. process(PROC_HOST, #host_init, #host_recv)
  26. #endif
  27. /******************************************************************************
  28. * HOST data segment
  29. *****************************************************************************/
  30. #ifdef INCLUDE_DATA
  31. // HOST (R)FIFO packet format
  32. .equ #fifo_process 0x00
  33. .equ #fifo_message 0x04
  34. .equ #fifo_data0 0x08
  35. .equ #fifo_data1 0x0c
  36. // HOST HOST->PWR queue description
  37. .equ #fifo_qlen 4 // log2(size of queue entry in bytes)
  38. .equ #fifo_qnum 3 // log2(max number of entries in queue)
  39. .equ #fifo_qmaskb (1 << #fifo_qnum) // max number of entries in queue
  40. .equ #fifo_qmaskp (#fifo_qmaskb - 1)
  41. .equ #fifo_qmaskf ((#fifo_qmaskb << 1) - 1)
  42. .equ #fifo_qsize (1 << (#fifo_qlen + #fifo_qnum))
  43. fifo_queue: .skip 128 // #fifo_qsize
  44. // HOST PWR->HOST queue description
  45. .equ #rfifo_qlen 4 // log2(size of queue entry in bytes)
  46. .equ #rfifo_qnum 3 // log2(max number of entries in queue)
  47. .equ #rfifo_qmaskb (1 << #rfifo_qnum) // max number of entries in queue
  48. .equ #rfifo_qmaskp (#rfifo_qmaskb - 1)
  49. .equ #rfifo_qmaskf ((#rfifo_qmaskb << 1) - 1)
  50. .equ #rfifo_qsize (1 << (#rfifo_qlen + #rfifo_qnum))
  51. rfifo_queue: .skip 128 // #rfifo_qsize
  52. #endif
  53. /******************************************************************************
  54. * HOST code segment
  55. *****************************************************************************/
  56. #ifdef INCLUDE_CODE
  57. // HOST->PWR comms - dequeue message(s) for process(es) from FIFO
  58. //
  59. // $r15 - current (host)
  60. // $r0 - zero
  61. host_send:
  62. nv_iord($r1, NV_PPWR_FIFO_GET(0))
  63. nv_iord($r2, NV_PPWR_FIFO_PUT(0))
  64. cmp b32 $r1 $r2
  65. bra e #host_send_done
  66. // calculate address of message
  67. and $r14 $r1 #fifo_qmaskp
  68. shl b32 $r14 $r14 #fifo_qlen
  69. add b32 $r14 #fifo_queue
  70. // read message data, and pass to appropriate process
  71. ld b32 $r11 D[$r14 + #fifo_data1]
  72. ld b32 $r12 D[$r14 + #fifo_data0]
  73. ld b32 $r13 D[$r14 + #fifo_message]
  74. ld b32 $r14 D[$r14 + #fifo_process]
  75. call(send)
  76. // increment GET
  77. add b32 $r1 0x1
  78. and $r14 $r1 #fifo_qmaskf
  79. nv_iowr(NV_PPWR_FIFO_GET(0), $r14)
  80. bra #host_send
  81. host_send_done:
  82. ret
  83. // PWR->HOST comms - enqueue message for HOST to RFIFO
  84. //
  85. // $r15 - current (host)
  86. // $r14 - process
  87. // $r13 - message
  88. // $r12 - message data 0
  89. // $r11 - message data 1
  90. // $r0 - zero
  91. host_recv:
  92. // message from intr handler == HOST->PWR comms pending
  93. mov $r1 (PROC_KERN & 0x0000ffff)
  94. sethi $r1 (PROC_KERN & 0xffff0000)
  95. cmp b32 $r14 $r1
  96. bra e #host_send
  97. // wait for space in RFIFO
  98. host_recv_wait:
  99. nv_iord($r1, NV_PPWR_RFIFO_GET)
  100. nv_iord($r2, NV_PPWR_RFIFO_PUT)
  101. xor $r1 #rfifo_qmaskb
  102. cmp b32 $r1 $r2
  103. bra e #host_recv_wait
  104. and $r3 $r2 #rfifo_qmaskp
  105. shl b32 $r3 #rfifo_qlen
  106. add b32 $r3 #rfifo_queue
  107. // enqueue message
  108. st b32 D[$r3 + #fifo_data1] $r11
  109. st b32 D[$r3 + #fifo_data0] $r12
  110. st b32 D[$r3 + #fifo_message] $r13
  111. st b32 D[$r3 + #fifo_process] $r14
  112. add b32 $r2 0x1
  113. and $r2 #rfifo_qmaskf
  114. nv_iowr(NV_PPWR_RFIFO_PUT, $r2)
  115. // notify host of pending message
  116. mov $r2 NV_PPWR_INTR_TRIGGER_USER0
  117. nv_iowr(NV_PPWR_INTR_TRIGGER, $r2)
  118. ret
  119. // $r15 - current (host)
  120. // $r0 - zero
  121. host_init:
  122. // store each fifo's base/size in H2D/D2H scratch regs
  123. mov $r1 #fifo_qsize
  124. shl b32 $r1 16
  125. or $r1 #fifo_queue
  126. nv_iowr(NV_PPWR_H2D, $r1);
  127. mov $r1 #rfifo_qsize
  128. shl b32 $r1 16
  129. or $r1 #rfifo_queue
  130. nv_iowr(NV_PPWR_D2H, $r1);
  131. // enable fifo subintr for first fifo
  132. mov $r1 1
  133. nv_iowr(NV_PPWR_FIFO_INTR_EN, $r1)
  134. ret
  135. #endif