Statistics
| Branch: | Revision:

root / hw / apic_internal.h @ 43997225

History | View | Annotate | Download (4.7 kB)

1 dae01685 Jan Kiszka
/*
2 dae01685 Jan Kiszka
 *  APIC support - internal interfaces
3 dae01685 Jan Kiszka
 *
4 dae01685 Jan Kiszka
 *  Copyright (c) 2004-2005 Fabrice Bellard
5 dae01685 Jan Kiszka
 *  Copyright (c) 2011      Jan Kiszka, Siemens AG
6 dae01685 Jan Kiszka
 *
7 dae01685 Jan Kiszka
 * This library is free software; you can redistribute it and/or
8 dae01685 Jan Kiszka
 * modify it under the terms of the GNU Lesser General Public
9 dae01685 Jan Kiszka
 * License as published by the Free Software Foundation; either
10 dae01685 Jan Kiszka
 * version 2 of the License, or (at your option) any later version.
11 dae01685 Jan Kiszka
 *
12 dae01685 Jan Kiszka
 * This library is distributed in the hope that it will be useful,
13 dae01685 Jan Kiszka
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 dae01685 Jan Kiszka
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 dae01685 Jan Kiszka
 * Lesser General Public License for more details.
16 dae01685 Jan Kiszka
 *
17 dae01685 Jan Kiszka
 * You should have received a copy of the GNU Lesser General Public
18 dae01685 Jan Kiszka
 * License along with this library; if not, see <http://www.gnu.org/licenses/>
19 dae01685 Jan Kiszka
 */
20 dae01685 Jan Kiszka
#ifndef QEMU_APIC_INTERNAL_H
21 dae01685 Jan Kiszka
#define QEMU_APIC_INTERNAL_H
22 dae01685 Jan Kiszka
23 dae01685 Jan Kiszka
#include "memory.h"
24 dae01685 Jan Kiszka
#include "sysbus.h"
25 dae01685 Jan Kiszka
#include "qemu-timer.h"
26 dae01685 Jan Kiszka
27 dae01685 Jan Kiszka
/* APIC Local Vector Table */
28 dae01685 Jan Kiszka
#define APIC_LVT_TIMER                  0
29 dae01685 Jan Kiszka
#define APIC_LVT_THERMAL                1
30 dae01685 Jan Kiszka
#define APIC_LVT_PERFORM                2
31 dae01685 Jan Kiszka
#define APIC_LVT_LINT0                  3
32 dae01685 Jan Kiszka
#define APIC_LVT_LINT1                  4
33 dae01685 Jan Kiszka
#define APIC_LVT_ERROR                  5
34 dae01685 Jan Kiszka
#define APIC_LVT_NB                     6
35 dae01685 Jan Kiszka
36 dae01685 Jan Kiszka
/* APIC delivery modes */
37 dae01685 Jan Kiszka
#define APIC_DM_FIXED                   0
38 dae01685 Jan Kiszka
#define APIC_DM_LOWPRI                  1
39 dae01685 Jan Kiszka
#define APIC_DM_SMI                     2
40 dae01685 Jan Kiszka
#define APIC_DM_NMI                     4
41 dae01685 Jan Kiszka
#define APIC_DM_INIT                    5
42 dae01685 Jan Kiszka
#define APIC_DM_SIPI                    6
43 dae01685 Jan Kiszka
#define APIC_DM_EXTINT                  7
44 dae01685 Jan Kiszka
45 dae01685 Jan Kiszka
/* APIC destination mode */
46 dae01685 Jan Kiszka
#define APIC_DESTMODE_FLAT              0xf
47 dae01685 Jan Kiszka
#define APIC_DESTMODE_CLUSTER           1
48 dae01685 Jan Kiszka
49 dae01685 Jan Kiszka
#define APIC_TRIGGER_EDGE               0
50 dae01685 Jan Kiszka
#define APIC_TRIGGER_LEVEL              1
51 dae01685 Jan Kiszka
52 dae01685 Jan Kiszka
#define APIC_LVT_TIMER_PERIODIC         (1<<17)
53 dae01685 Jan Kiszka
#define APIC_LVT_MASKED                 (1<<16)
54 dae01685 Jan Kiszka
#define APIC_LVT_LEVEL_TRIGGER          (1<<15)
55 dae01685 Jan Kiszka
#define APIC_LVT_REMOTE_IRR             (1<<14)
56 dae01685 Jan Kiszka
#define APIC_INPUT_POLARITY             (1<<13)
57 dae01685 Jan Kiszka
#define APIC_SEND_PENDING               (1<<12)
58 dae01685 Jan Kiszka
59 dae01685 Jan Kiszka
#define ESR_ILLEGAL_ADDRESS (1 << 7)
60 dae01685 Jan Kiszka
61 dae01685 Jan Kiszka
#define APIC_SV_DIRECTED_IO             (1<<12)
62 dae01685 Jan Kiszka
#define APIC_SV_ENABLE                  (1<<8)
63 dae01685 Jan Kiszka
64 e5ad936b Jan Kiszka
#define VAPIC_ENABLE_BIT                0
65 e5ad936b Jan Kiszka
#define VAPIC_ENABLE_MASK               (1 << VAPIC_ENABLE_BIT)
66 e5ad936b Jan Kiszka
67 dae01685 Jan Kiszka
#define MAX_APICS 255
68 dae01685 Jan Kiszka
69 dae01685 Jan Kiszka
#define MSI_SPACE_SIZE                  0x100000
70 dae01685 Jan Kiszka
71 dae01685 Jan Kiszka
typedef struct APICCommonState APICCommonState;
72 dae01685 Jan Kiszka
73 999e12bb Anthony Liguori
#define TYPE_APIC_COMMON "apic-common"
74 999e12bb Anthony Liguori
#define APIC_COMMON(obj) \
75 999e12bb Anthony Liguori
     OBJECT_CHECK(APICCommonState, (obj), TYPE_APIC_COMMON)
76 999e12bb Anthony Liguori
#define APIC_COMMON_CLASS(klass) \
77 999e12bb Anthony Liguori
     OBJECT_CLASS_CHECK(APICCommonClass, (klass), TYPE_APIC_COMMON)
78 999e12bb Anthony Liguori
#define APIC_COMMON_GET_CLASS(obj) \
79 999e12bb Anthony Liguori
     OBJECT_GET_CLASS(APICCommonClass, (obj), TYPE_APIC_COMMON)
80 999e12bb Anthony Liguori
81 999e12bb Anthony Liguori
typedef struct APICCommonClass
82 999e12bb Anthony Liguori
{
83 999e12bb Anthony Liguori
    SysBusDeviceClass parent_class;
84 999e12bb Anthony Liguori
85 999e12bb Anthony Liguori
    void (*init)(APICCommonState *s);
86 999e12bb Anthony Liguori
    void (*set_base)(APICCommonState *s, uint64_t val);
87 999e12bb Anthony Liguori
    void (*set_tpr)(APICCommonState *s, uint8_t val);
88 e5ad936b Jan Kiszka
    uint8_t (*get_tpr)(APICCommonState *s);
89 e5ad936b Jan Kiszka
    void (*enable_tpr_reporting)(APICCommonState *s, bool enable);
90 e5ad936b Jan Kiszka
    void (*vapic_base_update)(APICCommonState *s);
91 999e12bb Anthony Liguori
    void (*external_nmi)(APICCommonState *s);
92 e5ad936b Jan Kiszka
    void (*pre_save)(APICCommonState *s);
93 999e12bb Anthony Liguori
    void (*post_load)(APICCommonState *s);
94 999e12bb Anthony Liguori
} APICCommonClass;
95 999e12bb Anthony Liguori
96 dae01685 Jan Kiszka
struct APICCommonState {
97 dae01685 Jan Kiszka
    SysBusDevice busdev;
98 dae01685 Jan Kiszka
    MemoryRegion io_memory;
99 dae01685 Jan Kiszka
    void *cpu_env;
100 dae01685 Jan Kiszka
    uint32_t apicbase;
101 dae01685 Jan Kiszka
    uint8_t id;
102 dae01685 Jan Kiszka
    uint8_t arb_id;
103 dae01685 Jan Kiszka
    uint8_t tpr;
104 dae01685 Jan Kiszka
    uint32_t spurious_vec;
105 dae01685 Jan Kiszka
    uint8_t log_dest;
106 dae01685 Jan Kiszka
    uint8_t dest_mode;
107 dae01685 Jan Kiszka
    uint32_t isr[8];  /* in service register */
108 dae01685 Jan Kiszka
    uint32_t tmr[8];  /* trigger mode register */
109 dae01685 Jan Kiszka
    uint32_t irr[8]; /* interrupt request register */
110 dae01685 Jan Kiszka
    uint32_t lvt[APIC_LVT_NB];
111 dae01685 Jan Kiszka
    uint32_t esr; /* error register */
112 dae01685 Jan Kiszka
    uint32_t icr[2];
113 dae01685 Jan Kiszka
114 dae01685 Jan Kiszka
    uint32_t divide_conf;
115 dae01685 Jan Kiszka
    int count_shift;
116 dae01685 Jan Kiszka
    uint32_t initial_count;
117 dae01685 Jan Kiszka
    int64_t initial_count_load_time;
118 dae01685 Jan Kiszka
    int64_t next_time;
119 dae01685 Jan Kiszka
    int idx;
120 dae01685 Jan Kiszka
    QEMUTimer *timer;
121 7a380ca3 Jan Kiszka
    int64_t timer_expiry;
122 dae01685 Jan Kiszka
    int sipi_vector;
123 dae01685 Jan Kiszka
    int wait_for_sipi;
124 e5ad936b Jan Kiszka
125 e5ad936b Jan Kiszka
    uint32_t vapic_control;
126 e5ad936b Jan Kiszka
    DeviceState *vapic;
127 e5ad936b Jan Kiszka
    target_phys_addr_t vapic_paddr; /* note: persistence via kvmvapic */
128 dae01685 Jan Kiszka
};
129 dae01685 Jan Kiszka
130 e5ad936b Jan Kiszka
typedef struct VAPICState {
131 e5ad936b Jan Kiszka
    uint8_t tpr;
132 e5ad936b Jan Kiszka
    uint8_t isr;
133 e5ad936b Jan Kiszka
    uint8_t zero;
134 e5ad936b Jan Kiszka
    uint8_t irr;
135 e5ad936b Jan Kiszka
    uint8_t enabled;
136 e5ad936b Jan Kiszka
} QEMU_PACKED VAPICState;
137 e5ad936b Jan Kiszka
138 e5ad936b Jan Kiszka
extern bool apic_report_tpr_access;
139 e5ad936b Jan Kiszka
140 dae01685 Jan Kiszka
void apic_report_irq_delivered(int delivered);
141 7a380ca3 Jan Kiszka
bool apic_next_timer(APICCommonState *s, int64_t current_time);
142 e5ad936b Jan Kiszka
void apic_enable_tpr_access_reporting(DeviceState *d, bool enable);
143 e5ad936b Jan Kiszka
void apic_enable_vapic(DeviceState *d, target_phys_addr_t paddr);
144 e5ad936b Jan Kiszka
void apic_poll_irq(DeviceState *d);
145 e5ad936b Jan Kiszka
146 e5ad936b Jan Kiszka
void vapic_report_tpr_access(DeviceState *dev, void *cpu, target_ulong ip,
147 e5ad936b Jan Kiszka
                             TPRAccess access);
148 dae01685 Jan Kiszka
149 dae01685 Jan Kiszka
#endif /* !QEMU_APIC_INTERNAL_H */