beat_wrapper.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289
  1. /*
  2. * Beat hypervisor call I/F
  3. *
  4. * (C) Copyright 2007 TOSHIBA CORPORATION
  5. *
  6. * This code is based on arch/powerpc/platforms/pseries/plpar_wrapper.h.
  7. *
  8. * This program is free software; you can redistribute it and/or modify
  9. * it under the terms of the GNU General Public License as published by
  10. * the Free Software Foundation; either version 2 of the License, or
  11. * (at your option) any later version.
  12. *
  13. * This program is distributed in the hope that it will be useful,
  14. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  15. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  16. * GNU General Public License for more details.
  17. *
  18. * You should have received a copy of the GNU General Public License along
  19. * with this program; if not, write to the Free Software Foundation, Inc.,
  20. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  21. */
  22. #ifndef BEAT_HCALL
  23. #include "beat_syscall.h"
  24. /* defined in hvCall.S */
  25. extern s64 beat_hcall_norets(u64 opcode, ...);
  26. extern s64 beat_hcall_norets8(u64 opcode, u64 arg1, u64 arg2, u64 arg3,
  27. u64 arg4, u64 arg5, u64 arg6, u64 arg7, u64 arg8);
  28. extern s64 beat_hcall1(u64 opcode, u64 retbuf[1], ...);
  29. extern s64 beat_hcall2(u64 opcode, u64 retbuf[2], ...);
  30. extern s64 beat_hcall3(u64 opcode, u64 retbuf[3], ...);
  31. extern s64 beat_hcall4(u64 opcode, u64 retbuf[4], ...);
  32. extern s64 beat_hcall5(u64 opcode, u64 retbuf[5], ...);
  33. extern s64 beat_hcall6(u64 opcode, u64 retbuf[6], ...);
  34. static inline s64 beat_downcount_of_interrupt(u64 plug_id)
  35. {
  36. return beat_hcall_norets(HV_downcount_of_interrupt, plug_id);
  37. }
  38. static inline s64 beat_set_interrupt_mask(u64 index,
  39. u64 val0, u64 val1, u64 val2, u64 val3)
  40. {
  41. return beat_hcall_norets(HV_set_interrupt_mask, index,
  42. val0, val1, val2, val3);
  43. }
  44. static inline s64 beat_destruct_irq_plug(u64 plug_id)
  45. {
  46. return beat_hcall_norets(HV_destruct_irq_plug, plug_id);
  47. }
  48. static inline s64 beat_construct_and_connect_irq_plug(u64 plug_id,
  49. u64 outlet_id)
  50. {
  51. return beat_hcall_norets(HV_construct_and_connect_irq_plug, plug_id,
  52. outlet_id);
  53. }
  54. static inline s64 beat_detect_pending_interrupts(u64 index, u64 *retbuf)
  55. {
  56. return beat_hcall4(HV_detect_pending_interrupts, retbuf, index);
  57. }
  58. static inline s64 beat_pause(u64 style)
  59. {
  60. return beat_hcall_norets(HV_pause, style);
  61. }
  62. static inline s64 beat_read_htab_entries(u64 htab_id, u64 index, u64 *retbuf)
  63. {
  64. return beat_hcall5(HV_read_htab_entries, retbuf, htab_id, index);
  65. }
  66. static inline s64 beat_insert_htab_entry(u64 htab_id, u64 group,
  67. u64 bitmask, u64 hpte_v, u64 hpte_r, u64 *slot)
  68. {
  69. u64 dummy[3];
  70. s64 ret;
  71. ret = beat_hcall3(HV_insert_htab_entry, dummy, htab_id, group,
  72. bitmask, hpte_v, hpte_r);
  73. *slot = dummy[0];
  74. return ret;
  75. }
  76. static inline s64 beat_write_htab_entry(u64 htab_id, u64 slot,
  77. u64 hpte_v, u64 hpte_r, u64 mask_v, u64 mask_r,
  78. u64 *ret_v, u64 *ret_r)
  79. {
  80. u64 dummy[2];
  81. s64 ret;
  82. ret = beat_hcall2(HV_write_htab_entry, dummy, htab_id, slot,
  83. hpte_v, hpte_r, mask_v, mask_r);
  84. *ret_v = dummy[0];
  85. *ret_r = dummy[1];
  86. return ret;
  87. }
  88. static inline s64 beat_insert_htab_entry3(u64 htab_id, u64 group,
  89. u64 hpte_v, u64 hpte_r, u64 mask_v, u64 value_v, u64 *slot)
  90. {
  91. u64 dummy[1];
  92. s64 ret;
  93. ret = beat_hcall1(HV_insert_htab_entry3, dummy, htab_id, group,
  94. hpte_v, hpte_r, mask_v, value_v);
  95. *slot = dummy[0];
  96. return ret;
  97. }
  98. static inline s64 beat_invalidate_htab_entry3(u64 htab_id, u64 group,
  99. u64 va, u64 pss)
  100. {
  101. return beat_hcall_norets(HV_invalidate_htab_entry3,
  102. htab_id, group, va, pss);
  103. }
  104. static inline s64 beat_update_htab_permission3(u64 htab_id, u64 group,
  105. u64 va, u64 pss, u64 ptel_mask, u64 ptel_value)
  106. {
  107. return beat_hcall_norets(HV_update_htab_permission3,
  108. htab_id, group, va, pss, ptel_mask, ptel_value);
  109. }
  110. static inline s64 beat_clear_htab3(u64 htab_id)
  111. {
  112. return beat_hcall_norets(HV_clear_htab3, htab_id);
  113. }
  114. static inline void beat_shutdown_logical_partition(u64 code)
  115. {
  116. (void)beat_hcall_norets(HV_shutdown_logical_partition, code);
  117. }
  118. static inline s64 beat_rtc_write(u64 time_from_epoch)
  119. {
  120. return beat_hcall_norets(HV_rtc_write, time_from_epoch);
  121. }
  122. static inline s64 beat_rtc_read(u64 *time_from_epoch)
  123. {
  124. u64 dummy[1];
  125. s64 ret;
  126. ret = beat_hcall1(HV_rtc_read, dummy);
  127. *time_from_epoch = dummy[0];
  128. return ret;
  129. }
  130. #define BEAT_NVRW_CNT (sizeof(u64) * 6)
  131. static inline s64 beat_eeprom_write(u64 index, u64 length, u8 *buffer)
  132. {
  133. u64 b[6];
  134. if (length > BEAT_NVRW_CNT)
  135. return -1;
  136. memcpy(b, buffer, sizeof(b));
  137. return beat_hcall_norets8(HV_eeprom_write, index, length,
  138. b[0], b[1], b[2], b[3], b[4], b[5]);
  139. }
  140. static inline s64 beat_eeprom_read(u64 index, u64 length, u8 *buffer)
  141. {
  142. u64 b[6];
  143. s64 ret;
  144. if (length > BEAT_NVRW_CNT)
  145. return -1;
  146. ret = beat_hcall6(HV_eeprom_read, b, index, length);
  147. memcpy(buffer, b, length);
  148. return ret;
  149. }
  150. static inline s64 beat_set_dabr(u64 value, u64 style)
  151. {
  152. return beat_hcall_norets(HV_set_dabr, value, style);
  153. }
  154. static inline s64 beat_get_characters_from_console(u64 termno, u64 *len,
  155. u8 *buffer)
  156. {
  157. u64 dummy[3];
  158. s64 ret;
  159. ret = beat_hcall3(HV_get_characters_from_console, dummy, termno, len);
  160. *len = dummy[0];
  161. memcpy(buffer, dummy + 1, *len);
  162. return ret;
  163. }
  164. static inline s64 beat_put_characters_to_console(u64 termno, u64 len,
  165. u8 *buffer)
  166. {
  167. u64 b[2];
  168. memcpy(b, buffer, len);
  169. return beat_hcall_norets(HV_put_characters_to_console, termno, len,
  170. b[0], b[1]);
  171. }
  172. static inline s64 beat_get_spe_privileged_state_1_registers(
  173. u64 id, u64 offsetof, u64 *value)
  174. {
  175. u64 dummy[1];
  176. s64 ret;
  177. ret = beat_hcall1(HV_get_spe_privileged_state_1_registers, dummy, id,
  178. offsetof);
  179. *value = dummy[0];
  180. return ret;
  181. }
  182. static inline s64 beat_set_irq_mask_for_spe(u64 id, u64 class, u64 mask)
  183. {
  184. return beat_hcall_norets(HV_set_irq_mask_for_spe, id, class, mask);
  185. }
  186. static inline s64 beat_clear_interrupt_status_of_spe(u64 id, u64 class,
  187. u64 mask)
  188. {
  189. return beat_hcall_norets(HV_clear_interrupt_status_of_spe,
  190. id, class, mask);
  191. }
  192. static inline s64 beat_set_spe_privileged_state_1_registers(
  193. u64 id, u64 offsetof, u64 value)
  194. {
  195. return beat_hcall_norets(HV_set_spe_privileged_state_1_registers,
  196. id, offsetof, value);
  197. }
  198. static inline s64 beat_get_interrupt_status_of_spe(u64 id, u64 class, u64 *val)
  199. {
  200. u64 dummy[1];
  201. s64 ret;
  202. ret = beat_hcall1(HV_get_interrupt_status_of_spe, dummy, id, class);
  203. *val = dummy[0];
  204. return ret;
  205. }
  206. static inline s64 beat_put_iopte(u64 ioas_id, u64 io_addr, u64 real_addr,
  207. u64 ioid, u64 flags)
  208. {
  209. return beat_hcall_norets(HV_put_iopte, ioas_id, io_addr, real_addr,
  210. ioid, flags);
  211. }
  212. static inline s64 beat_construct_event_receive_port(u64 *port)
  213. {
  214. u64 dummy[1];
  215. s64 ret;
  216. ret = beat_hcall1(HV_construct_event_receive_port, dummy);
  217. *port = dummy[0];
  218. return ret;
  219. }
  220. static inline s64 beat_destruct_event_receive_port(u64 port)
  221. {
  222. s64 ret;
  223. ret = beat_hcall_norets(HV_destruct_event_receive_port, port);
  224. return ret;
  225. }
  226. static inline s64 beat_create_repository_node(u64 path[4], u64 data[2])
  227. {
  228. s64 ret;
  229. ret = beat_hcall_norets(HV_create_repository_node2,
  230. path[0], path[1], path[2], path[3], data[0], data[1]);
  231. return ret;
  232. }
  233. static inline s64 beat_get_repository_node_value(u64 lpid, u64 path[4],
  234. u64 data[2])
  235. {
  236. s64 ret;
  237. ret = beat_hcall2(HV_get_repository_node_value2, data,
  238. lpid, path[0], path[1], path[2], path[3]);
  239. return ret;
  240. }
  241. #endif