qemu.h 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112
  1. /*
  2. * Copyright (C) 2008 The Android Open Source Project
  3. *
  4. * Licensed under the Apache License, Version 2.0 (the "License");
  5. * you may not use this file except in compliance with the License.
  6. * You may obtain a copy of the License at
  7. *
  8. * http://www.apache.org/licenses/LICENSE-2.0
  9. *
  10. * Unless required by applicable law or agreed to in writing, software
  11. * distributed under the License is distributed on an "AS IS" BASIS,
  12. * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  13. * See the License for the specific language governing permissions and
  14. * limitations under the License.
  15. */
  16. #ifndef _libs_hardware_qemu_h
  17. #define _libs_hardware_qemu_h
  18. #ifdef __cplusplus
  19. extern "C" {
  20. #endif
  21. #ifdef QEMU_HARDWARE
  22. /* returns 1 iff we're running in the emulator */
  23. extern int qemu_check(void);
  24. /* a structure used to hold enough state to connect to a given
  25. * QEMU communication channel, either through a qemud socket or
  26. * a serial port.
  27. *
  28. * initialize the structure by zero-ing it out
  29. */
  30. typedef struct {
  31. char is_inited;
  32. char is_available;
  33. char is_qemud;
  34. char is_qemud_old;
  35. char is_tty;
  36. int fd;
  37. char device[32];
  38. } QemuChannel;
  39. /* try to open a qemu communication channel.
  40. * returns a file descriptor on success, or -1 in case of
  41. * error.
  42. *
  43. * 'channel' must be a QemuChannel structure that is empty
  44. * on the first call. You can call this function several
  45. * time to re-open the channel using the same 'channel'
  46. * object to speed things a bit.
  47. */
  48. extern int qemu_channel_open( QemuChannel* channel,
  49. const char* name,
  50. int mode );
  51. /* create a command made of a 4-hexchar prefix followed
  52. * by the content. the prefix contains the content's length
  53. * in hexadecimal coding.
  54. *
  55. * 'buffer' must be at last 6 bytes
  56. * returns -1 in case of overflow, or the command's total length
  57. * otherwise (i.e. content length + 4)
  58. */
  59. extern int qemu_command_format( char* buffer,
  60. int buffer_size,
  61. const char* format,
  62. ... );
  63. /* directly sends a command through the 'hw-control' channel.
  64. * this will open the channel, send the formatted command, then
  65. * close the channel automatically.
  66. * returns 0 on success, or -1 on error.
  67. */
  68. extern int qemu_control_command( const char* fmt, ... );
  69. /* sends a question to the hw-control channel, then receive an answer in
  70. * a user-allocated buffer. returns the length of the answer, or -1
  71. * in case of error.
  72. *
  73. * 'question' *must* have been formatted through qemu_command_format
  74. */
  75. extern int qemu_control_query( const char* question, int questionlen,
  76. char* answer, int answersize );
  77. #endif /* QEMU_HARDWARE */
  78. /* use QEMU_FALLBACK(call) to call a QEMU-specific callback */
  79. /* use QEMU_FALLBACK_VOID(call) if the function returns void */
  80. #ifdef QEMU_HARDWARE
  81. # define QEMU_FALLBACK(x) \
  82. do { \
  83. if (qemu_check()) \
  84. return qemu_ ## x ; \
  85. } while (0)
  86. # define QEMU_FALLBACK_VOID(x) \
  87. do { \
  88. if (qemu_check()) { \
  89. qemu_ ## x ; \
  90. return; \
  91. } \
  92. } while (0)
  93. #else
  94. # define QEMU_FALLBACK(x) ((void)0)
  95. # define QEMU_FALLBACK_VOID(x) ((void)0)
  96. #endif
  97. #ifdef __cplusplus
  98. }
  99. #endif
  100. #endif /* _libs_hardware_qemu_h */