2
0

acpi.h 6.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206
  1. #ifndef QEMU_HW_ACPI_H
  2. #define QEMU_HW_ACPI_H
  3. /*
  4. * Copyright (c) 2009 Isaku Yamahata <yamahata at valinux co jp>
  5. * VA Linux Systems Japan K.K.
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, see
  19. * <http://www.gnu.org/licenses/>.
  20. */
  21. #include "qemu/notify.h"
  22. #include "exec/memory.h"
  23. #include "hw/acpi/acpi_dev_interface.h"
  24. /*
  25. * current device naming scheme supports up to 256 memory devices
  26. */
  27. #define ACPI_MAX_RAM_SLOTS 256
  28. /* from linux include/acpi/actype.h */
  29. /* Default ACPI register widths */
  30. #define ACPI_GPE_REGISTER_WIDTH 8
  31. #define ACPI_PM1_REGISTER_WIDTH 16
  32. #define ACPI_PM2_REGISTER_WIDTH 8
  33. #define ACPI_PM_TIMER_WIDTH 32
  34. /* PC-style peripherals (also used by other machines). */
  35. #define ACPI_PM_PROP_S3_DISABLED "disable_s3"
  36. #define ACPI_PM_PROP_S4_DISABLED "disable_s4"
  37. #define ACPI_PM_PROP_S4_VAL "s4_val"
  38. #define ACPI_PM_PROP_SCI_INT "sci_int"
  39. #define ACPI_PM_PROP_ACPI_ENABLE_CMD "acpi_enable_cmd"
  40. #define ACPI_PM_PROP_ACPI_DISABLE_CMD "acpi_disable_cmd"
  41. #define ACPI_PM_PROP_PM_IO_BASE "pm_io_base"
  42. #define ACPI_PM_PROP_GPE0_BLK "gpe0_blk"
  43. #define ACPI_PM_PROP_GPE0_BLK_LEN "gpe0_blk_len"
  44. #define ACPI_PM_PROP_ACPI_PCIHP_BRIDGE "acpi-pci-hotplug-with-bridge-support"
  45. #define ACPI_PM_PROP_ACPI_PCI_ROOTHP "acpi-root-pci-hotplug"
  46. /* PM Timer ticks per second (HZ) */
  47. #define PM_TIMER_FREQUENCY 3579545
  48. /* ACPI fixed hardware registers */
  49. /* from linux/drivers/acpi/acpica/aclocal.h */
  50. /* Masks used to access the bit_registers */
  51. /* PM1x_STS */
  52. #define ACPI_BITMASK_TIMER_STATUS 0x0001
  53. #define ACPI_BITMASK_BUS_MASTER_STATUS 0x0010
  54. #define ACPI_BITMASK_GLOBAL_LOCK_STATUS 0x0020
  55. #define ACPI_BITMASK_POWER_BUTTON_STATUS 0x0100
  56. #define ACPI_BITMASK_SLEEP_BUTTON_STATUS 0x0200
  57. #define ACPI_BITMASK_RT_CLOCK_STATUS 0x0400
  58. #define ACPI_BITMASK_PCIEXP_WAKE_STATUS 0x4000 /* ACPI 3.0 */
  59. #define ACPI_BITMASK_WAKE_STATUS 0x8000
  60. #define ACPI_BITMASK_ALL_FIXED_STATUS (\
  61. ACPI_BITMASK_TIMER_STATUS | \
  62. ACPI_BITMASK_BUS_MASTER_STATUS | \
  63. ACPI_BITMASK_GLOBAL_LOCK_STATUS | \
  64. ACPI_BITMASK_POWER_BUTTON_STATUS | \
  65. ACPI_BITMASK_SLEEP_BUTTON_STATUS | \
  66. ACPI_BITMASK_RT_CLOCK_STATUS | \
  67. ACPI_BITMASK_WAKE_STATUS)
  68. /* PM1x_EN */
  69. #define ACPI_BITMASK_TIMER_ENABLE 0x0001
  70. #define ACPI_BITMASK_GLOBAL_LOCK_ENABLE 0x0020
  71. #define ACPI_BITMASK_POWER_BUTTON_ENABLE 0x0100
  72. #define ACPI_BITMASK_SLEEP_BUTTON_ENABLE 0x0200
  73. #define ACPI_BITMASK_RT_CLOCK_ENABLE 0x0400
  74. #define ACPI_BITMASK_PCIEXP_WAKE_DISABLE 0x4000 /* ACPI 3.0 */
  75. #define ACPI_BITMASK_PM1_COMMON_ENABLED ( \
  76. ACPI_BITMASK_RT_CLOCK_ENABLE | \
  77. ACPI_BITMASK_POWER_BUTTON_ENABLE | \
  78. ACPI_BITMASK_GLOBAL_LOCK_ENABLE | \
  79. ACPI_BITMASK_TIMER_ENABLE)
  80. /* PM1x_CNT */
  81. #define ACPI_BITMASK_SCI_ENABLE 0x0001
  82. #define ACPI_BITMASK_BUS_MASTER_RLD 0x0002
  83. #define ACPI_BITMASK_GLOBAL_LOCK_RELEASE 0x0004
  84. #define ACPI_BITMASK_SLEEP_TYPE 0x1C00
  85. #define ACPI_BITMASK_SLEEP_ENABLE 0x2000
  86. /* PM2_CNT */
  87. #define ACPI_BITMASK_ARB_DISABLE 0x0001
  88. /* structs */
  89. typedef struct ACPIPMTimer ACPIPMTimer;
  90. typedef struct ACPIPM1EVT ACPIPM1EVT;
  91. typedef struct ACPIPM1CNT ACPIPM1CNT;
  92. typedef struct ACPIGPE ACPIGPE;
  93. typedef struct ACPIREGS ACPIREGS;
  94. typedef void (*acpi_update_sci_fn)(ACPIREGS *ar);
  95. struct ACPIPMTimer {
  96. QEMUTimer *timer;
  97. MemoryRegion io;
  98. int64_t overflow_time;
  99. acpi_update_sci_fn update_sci;
  100. };
  101. struct ACPIPM1EVT {
  102. MemoryRegion io;
  103. uint16_t sts;
  104. uint16_t en;
  105. acpi_update_sci_fn update_sci;
  106. };
  107. struct ACPIPM1CNT {
  108. MemoryRegion io;
  109. uint16_t cnt;
  110. uint8_t s4_val;
  111. bool acpi_only;
  112. };
  113. struct ACPIGPE {
  114. uint8_t len;
  115. uint8_t *sts;
  116. uint8_t *en;
  117. };
  118. struct ACPIREGS {
  119. ACPIPMTimer tmr;
  120. ACPIGPE gpe;
  121. struct {
  122. ACPIPM1EVT evt;
  123. ACPIPM1CNT cnt;
  124. } pm1;
  125. Notifier wakeup;
  126. };
  127. /* Return whether ACPI subsystem is built in */
  128. bool acpi_builtin(void);
  129. /* PM_TMR */
  130. void acpi_pm_tmr_update(ACPIREGS *ar, bool enable);
  131. void acpi_pm_tmr_calc_overflow_time(ACPIREGS *ar);
  132. void acpi_pm_tmr_init(ACPIREGS *ar, acpi_update_sci_fn update_sci,
  133. MemoryRegion *parent);
  134. void acpi_pm_tmr_reset(ACPIREGS *ar);
  135. /* PM1a_EVT: piix and ich9 don't implement PM1b. */
  136. uint16_t acpi_pm1_evt_get_sts(ACPIREGS *ar);
  137. void acpi_pm1_evt_power_down(ACPIREGS *ar);
  138. void acpi_pm1_evt_reset(ACPIREGS *ar);
  139. void acpi_pm1_evt_init(ACPIREGS *ar, acpi_update_sci_fn update_sci,
  140. MemoryRegion *parent);
  141. /* PM1a_CNT: piix and ich9 don't implement PM1b CNT. */
  142. void acpi_pm1_cnt_init(ACPIREGS *ar, MemoryRegion *parent,
  143. bool disable_s3, bool disable_s4, uint8_t s4_val,
  144. bool acpi_only);
  145. void acpi_pm1_cnt_update(ACPIREGS *ar,
  146. bool sci_enable, bool sci_disable);
  147. void acpi_pm1_cnt_reset(ACPIREGS *ar);
  148. /* GPE0 */
  149. void acpi_gpe_init(ACPIREGS *ar, uint8_t len);
  150. void acpi_gpe_reset(ACPIREGS *ar);
  151. void acpi_gpe_ioport_writeb(ACPIREGS *ar, uint32_t addr, uint32_t val);
  152. uint32_t acpi_gpe_ioport_readb(ACPIREGS *ar, uint32_t addr);
  153. void acpi_send_gpe_event(ACPIREGS *ar, qemu_irq irq,
  154. AcpiEventStatusBits status);
  155. void acpi_update_sci(ACPIREGS *acpi_regs, qemu_irq irq);
  156. /* acpi.c */
  157. extern char unsigned *acpi_tables;
  158. extern size_t acpi_tables_len;
  159. uint8_t *acpi_table_first(void);
  160. uint8_t *acpi_table_next(uint8_t *current);
  161. unsigned acpi_table_len(void *current);
  162. void acpi_table_add(const QemuOpts *opts, Error **errp);
  163. typedef struct AcpiSlicOem AcpiSlicOem;
  164. struct AcpiSlicOem {
  165. char *id;
  166. char *table_id;
  167. };
  168. int acpi_get_slic_oem(AcpiSlicOem *oem);
  169. #endif /* QEMU_HW_ACPI_H */