beat_wrapper.h 7.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291
  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 <linux/string.h>
  24. #include "beat_syscall.h"
  25. /* defined in hvCall.S */
  26. extern s64 beat_hcall_norets(u64 opcode, ...);
  27. extern s64 beat_hcall_norets8(u64 opcode, u64 arg1, u64 arg2, u64 arg3,
  28. u64 arg4, u64 arg5, u64 arg6, u64 arg7, u64 arg8);
  29. extern s64 beat_hcall1(u64 opcode, u64 retbuf[1], ...);
  30. extern s64 beat_hcall2(u64 opcode, u64 retbuf[2], ...);
  31. extern s64 beat_hcall3(u64 opcode, u64 retbuf[3], ...);
  32. extern s64 beat_hcall4(u64 opcode, u64 retbuf[4], ...);
  33. extern s64 beat_hcall5(u64 opcode, u64 retbuf[5], ...);
  34. extern s64 beat_hcall6(u64 opcode, u64 retbuf[6], ...);
  35. static inline s64 beat_downcount_of_interrupt(u64 plug_id)
  36. {
  37. return beat_hcall_norets(HV_downcount_of_interrupt, plug_id);
  38. }
  39. static inline s64 beat_set_interrupt_mask(u64 index,
  40. u64 val0, u64 val1, u64 val2, u64 val3)
  41. {
  42. return beat_hcall_norets(HV_set_interrupt_mask, index,
  43. val0, val1, val2, val3);
  44. }
  45. static inline s64 beat_destruct_irq_plug(u64 plug_id)
  46. {
  47. return beat_hcall_norets(HV_destruct_irq_plug, plug_id);
  48. }
  49. static inline s64 beat_construct_and_connect_irq_plug(u64 plug_id,
  50. u64 outlet_id)
  51. {
  52. return beat_hcall_norets(HV_construct_and_connect_irq_plug, plug_id,
  53. outlet_id);
  54. }
  55. static inline s64 beat_detect_pending_interrupts(u64 index, u64 *retbuf)
  56. {
  57. return beat_hcall4(HV_detect_pending_interrupts, retbuf, index);
  58. }
  59. static inline s64 beat_pause(u64 style)
  60. {
  61. return beat_hcall_norets(HV_pause, style);
  62. }
  63. static inline s64 beat_read_htab_entries(u64 htab_id, u64 index, u64 *retbuf)
  64. {
  65. return beat_hcall5(HV_read_htab_entries, retbuf, htab_id, index);
  66. }
  67. static inline s64 beat_insert_htab_entry(u64 htab_id, u64 group,
  68. u64 bitmask, u64 hpte_v, u64 hpte_r, u64 *slot)
  69. {
  70. u64 dummy[3];
  71. s64 ret;
  72. ret = beat_hcall3(HV_insert_htab_entry, dummy, htab_id, group,
  73. bitmask, hpte_v, hpte_r);
  74. *slot = dummy[0];
  75. return ret;
  76. }
  77. static inline s64 beat_write_htab_entry(u64 htab_id, u64 slot,
  78. u64 hpte_v, u64 hpte_r, u64 mask_v, u64 mask_r,
  79. u64 *ret_v, u64 *ret_r)
  80. {
  81. u64 dummy[2];
  82. s64 ret;
  83. ret = beat_hcall2(HV_write_htab_entry, dummy, htab_id, slot,
  84. hpte_v, hpte_r, mask_v, mask_r);
  85. *ret_v = dummy[0];
  86. *ret_r = dummy[1];
  87. return ret;
  88. }
  89. static inline s64 beat_insert_htab_entry3(u64 htab_id, u64 group,
  90. u64 hpte_v, u64 hpte_r, u64 mask_v, u64 value_v, u64 *slot)
  91. {
  92. u64 dummy[1];
  93. s64 ret;
  94. ret = beat_hcall1(HV_insert_htab_entry3, dummy, htab_id, group,
  95. hpte_v, hpte_r, mask_v, value_v);
  96. *slot = dummy[0];
  97. return ret;
  98. }
  99. static inline s64 beat_invalidate_htab_entry3(u64 htab_id, u64 group,
  100. u64 va, u64 pss)
  101. {
  102. return beat_hcall_norets(HV_invalidate_htab_entry3,
  103. htab_id, group, va, pss);
  104. }
  105. static inline s64 beat_update_htab_permission3(u64 htab_id, u64 group,
  106. u64 va, u64 pss, u64 ptel_mask, u64 ptel_value)
  107. {
  108. return beat_hcall_norets(HV_update_htab_permission3,
  109. htab_id, group, va, pss, ptel_mask, ptel_value);
  110. }
  111. static inline s64 beat_clear_htab3(u64 htab_id)
  112. {
  113. return beat_hcall_norets(HV_clear_htab3, htab_id);
  114. }
  115. static inline void beat_shutdown_logical_partition(u64 code)
  116. {
  117. (void)beat_hcall_norets(HV_shutdown_logical_partition, code);
  118. }
  119. static inline s64 beat_rtc_write(u64 time_from_epoch)
  120. {
  121. return beat_hcall_norets(HV_rtc_write, time_from_epoch);
  122. }
  123. static inline s64 beat_rtc_read(u64 *time_from_epoch)
  124. {
  125. u64 dummy[1];
  126. s64 ret;
  127. ret = beat_hcall1(HV_rtc_read, dummy);
  128. *time_from_epoch = dummy[0];
  129. return ret;
  130. }
  131. #define BEAT_NVRW_CNT (sizeof(u64) * 6)
  132. static inline s64 beat_eeprom_write(u64 index, u64 length, u8 *buffer)
  133. {
  134. u64 b[6];
  135. if (length > BEAT_NVRW_CNT)
  136. return -1;
  137. memcpy(b, buffer, sizeof(b));
  138. return beat_hcall_norets8(HV_eeprom_write, index, length,
  139. b[0], b[1], b[2], b[3], b[4], b[5]);
  140. }
  141. static inline s64 beat_eeprom_read(u64 index, u64 length, u8 *buffer)
  142. {
  143. u64 b[6];
  144. s64 ret;
  145. if (length > BEAT_NVRW_CNT)
  146. return -1;
  147. ret = beat_hcall6(HV_eeprom_read, b, index, length);
  148. memcpy(buffer, b, length);
  149. return ret;
  150. }
  151. static inline s64 beat_set_dabr(u64 value, u64 style)
  152. {
  153. return beat_hcall_norets(HV_set_dabr, value, style);
  154. }
  155. static inline s64 beat_get_characters_from_console(u64 termno, u64 *len,
  156. u8 *buffer)
  157. {
  158. u64 dummy[3];
  159. s64 ret;
  160. ret = beat_hcall3(HV_get_characters_from_console, dummy, termno, len);
  161. *len = dummy[0];
  162. memcpy(buffer, dummy + 1, *len);
  163. return ret;
  164. }
  165. static inline s64 beat_put_characters_to_console(u64 termno, u64 len,
  166. u8 *buffer)
  167. {
  168. u64 b[2];
  169. memcpy(b, buffer, len);
  170. return beat_hcall_norets(HV_put_characters_to_console, termno, len,
  171. b[0], b[1]);
  172. }
  173. static inline s64 beat_get_spe_privileged_state_1_registers(
  174. u64 id, u64 offsetof, u64 *value)
  175. {
  176. u64 dummy[1];
  177. s64 ret;
  178. ret = beat_hcall1(HV_get_spe_privileged_state_1_registers, dummy, id,
  179. offsetof);
  180. *value = dummy[0];
  181. return ret;
  182. }
  183. static inline s64 beat_set_irq_mask_for_spe(u64 id, u64 class, u64 mask)
  184. {
  185. return beat_hcall_norets(HV_set_irq_mask_for_spe, id, class, mask);
  186. }
  187. static inline s64 beat_clear_interrupt_status_of_spe(u64 id, u64 class,
  188. u64 mask)
  189. {
  190. return beat_hcall_norets(HV_clear_interrupt_status_of_spe,
  191. id, class, mask);
  192. }
  193. static inline s64 beat_set_spe_privileged_state_1_registers(
  194. u64 id, u64 offsetof, u64 value)
  195. {
  196. return beat_hcall_norets(HV_set_spe_privileged_state_1_registers,
  197. id, offsetof, value);
  198. }
  199. static inline s64 beat_get_interrupt_status_of_spe(u64 id, u64 class, u64 *val)
  200. {
  201. u64 dummy[1];
  202. s64 ret;
  203. ret = beat_hcall1(HV_get_interrupt_status_of_spe, dummy, id, class);
  204. *val = dummy[0];
  205. return ret;
  206. }
  207. static inline s64 beat_put_iopte(u64 ioas_id, u64 io_addr, u64 real_addr,
  208. u64 ioid, u64 flags)
  209. {
  210. return beat_hcall_norets(HV_put_iopte, ioas_id, io_addr, real_addr,
  211. ioid, flags);
  212. }
  213. static inline s64 beat_construct_event_receive_port(u64 *port)
  214. {
  215. u64 dummy[1];
  216. s64 ret;
  217. ret = beat_hcall1(HV_construct_event_receive_port, dummy);
  218. *port = dummy[0];
  219. return ret;
  220. }
  221. static inline s64 beat_destruct_event_receive_port(u64 port)
  222. {
  223. s64 ret;
  224. ret = beat_hcall_norets(HV_destruct_event_receive_port, port);
  225. return ret;
  226. }
  227. static inline s64 beat_create_repository_node(u64 path[4], u64 data[2])
  228. {
  229. s64 ret;
  230. ret = beat_hcall_norets(HV_create_repository_node2,
  231. path[0], path[1], path[2], path[3], data[0], data[1]);
  232. return ret;
  233. }
  234. static inline s64 beat_get_repository_node_value(u64 lpid, u64 path[4],
  235. u64 data[2])
  236. {
  237. s64 ret;
  238. ret = beat_hcall2(HV_get_repository_node_value2, data,
  239. lpid, path[0], path[1], path[2], path[3]);
  240. return ret;
  241. }
  242. #endif