apic_internal.h 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149
  1. /*
  2. * APIC support - internal interfaces
  3. *
  4. * Copyright (c) 2004-2005 Fabrice Bellard
  5. * Copyright (c) 2011 Jan Kiszka, Siemens AG
  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 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 <http://www.gnu.org/licenses/>
  19. */
  20. #ifndef QEMU_APIC_INTERNAL_H
  21. #define QEMU_APIC_INTERNAL_H
  22. #include "exec/memory.h"
  23. #include "sysbus.h"
  24. #include "qemu/timer.h"
  25. /* APIC Local Vector Table */
  26. #define APIC_LVT_TIMER 0
  27. #define APIC_LVT_THERMAL 1
  28. #define APIC_LVT_PERFORM 2
  29. #define APIC_LVT_LINT0 3
  30. #define APIC_LVT_LINT1 4
  31. #define APIC_LVT_ERROR 5
  32. #define APIC_LVT_NB 6
  33. /* APIC delivery modes */
  34. #define APIC_DM_FIXED 0
  35. #define APIC_DM_LOWPRI 1
  36. #define APIC_DM_SMI 2
  37. #define APIC_DM_NMI 4
  38. #define APIC_DM_INIT 5
  39. #define APIC_DM_SIPI 6
  40. #define APIC_DM_EXTINT 7
  41. /* APIC destination mode */
  42. #define APIC_DESTMODE_FLAT 0xf
  43. #define APIC_DESTMODE_CLUSTER 1
  44. #define APIC_TRIGGER_EDGE 0
  45. #define APIC_TRIGGER_LEVEL 1
  46. #define APIC_LVT_TIMER_PERIODIC (1<<17)
  47. #define APIC_LVT_MASKED (1<<16)
  48. #define APIC_LVT_LEVEL_TRIGGER (1<<15)
  49. #define APIC_LVT_REMOTE_IRR (1<<14)
  50. #define APIC_INPUT_POLARITY (1<<13)
  51. #define APIC_SEND_PENDING (1<<12)
  52. #define ESR_ILLEGAL_ADDRESS (1 << 7)
  53. #define APIC_SV_DIRECTED_IO (1<<12)
  54. #define APIC_SV_ENABLE (1<<8)
  55. #define VAPIC_ENABLE_BIT 0
  56. #define VAPIC_ENABLE_MASK (1 << VAPIC_ENABLE_BIT)
  57. #define MAX_APICS 255
  58. #define MSI_SPACE_SIZE 0x100000
  59. typedef struct APICCommonState APICCommonState;
  60. #define TYPE_APIC_COMMON "apic-common"
  61. #define APIC_COMMON(obj) \
  62. OBJECT_CHECK(APICCommonState, (obj), TYPE_APIC_COMMON)
  63. #define APIC_COMMON_CLASS(klass) \
  64. OBJECT_CLASS_CHECK(APICCommonClass, (klass), TYPE_APIC_COMMON)
  65. #define APIC_COMMON_GET_CLASS(obj) \
  66. OBJECT_GET_CLASS(APICCommonClass, (obj), TYPE_APIC_COMMON)
  67. typedef struct APICCommonClass
  68. {
  69. SysBusDeviceClass parent_class;
  70. void (*init)(APICCommonState *s);
  71. void (*set_base)(APICCommonState *s, uint64_t val);
  72. void (*set_tpr)(APICCommonState *s, uint8_t val);
  73. uint8_t (*get_tpr)(APICCommonState *s);
  74. void (*enable_tpr_reporting)(APICCommonState *s, bool enable);
  75. void (*vapic_base_update)(APICCommonState *s);
  76. void (*external_nmi)(APICCommonState *s);
  77. void (*pre_save)(APICCommonState *s);
  78. void (*post_load)(APICCommonState *s);
  79. } APICCommonClass;
  80. struct APICCommonState {
  81. SysBusDevice busdev;
  82. MemoryRegion io_memory;
  83. X86CPU *cpu;
  84. uint32_t apicbase;
  85. uint8_t id;
  86. uint8_t arb_id;
  87. uint8_t tpr;
  88. uint32_t spurious_vec;
  89. uint8_t log_dest;
  90. uint8_t dest_mode;
  91. uint32_t isr[8]; /* in service register */
  92. uint32_t tmr[8]; /* trigger mode register */
  93. uint32_t irr[8]; /* interrupt request register */
  94. uint32_t lvt[APIC_LVT_NB];
  95. uint32_t esr; /* error register */
  96. uint32_t icr[2];
  97. uint32_t divide_conf;
  98. int count_shift;
  99. uint32_t initial_count;
  100. int64_t initial_count_load_time;
  101. int64_t next_time;
  102. int idx;
  103. QEMUTimer *timer;
  104. int64_t timer_expiry;
  105. int sipi_vector;
  106. int wait_for_sipi;
  107. uint32_t vapic_control;
  108. DeviceState *vapic;
  109. hwaddr vapic_paddr; /* note: persistence via kvmvapic */
  110. };
  111. typedef struct VAPICState {
  112. uint8_t tpr;
  113. uint8_t isr;
  114. uint8_t zero;
  115. uint8_t irr;
  116. uint8_t enabled;
  117. } QEMU_PACKED VAPICState;
  118. extern bool apic_report_tpr_access;
  119. void apic_report_irq_delivered(int delivered);
  120. bool apic_next_timer(APICCommonState *s, int64_t current_time);
  121. void apic_enable_tpr_access_reporting(DeviceState *d, bool enable);
  122. void apic_enable_vapic(DeviceState *d, hwaddr paddr);
  123. void vapic_report_tpr_access(DeviceState *dev, void *cpu, target_ulong ip,
  124. TPRAccess access);
  125. #endif /* !QEMU_APIC_INTERNAL_H */