KVM
Classes | Macros | Functions
ioapic.h File Reference
#include <linux/kvm_host.h>
#include <kvm/iodev.h>
#include "irq.h"
Include dependency graph for ioapic.h:
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  dest_map
 
struct  rtc_status
 
union  kvm_ioapic_redirect_entry
 
struct  kvm_ioapic
 

Macros

#define IOAPIC_NUM_PINS   KVM_IOAPIC_NUM_PINS
 
#define MAX_NR_RESERVED_IOAPIC_PINS   KVM_MAX_IRQ_ROUTES
 
#define IOAPIC_VERSION_ID   0x11 /* IOAPIC version */
 
#define IOAPIC_EDGE_TRIG   0
 
#define IOAPIC_LEVEL_TRIG   1
 
#define IOAPIC_DEFAULT_BASE_ADDRESS   0xfec00000
 
#define IOAPIC_MEM_LENGTH   0x100
 
#define IOAPIC_REG_SELECT   0x00
 
#define IOAPIC_REG_WINDOW   0x10
 
#define IOAPIC_REG_APIC_ID   0x00 /* x86 IOAPIC only */
 
#define IOAPIC_REG_VERSION   0x01
 
#define IOAPIC_REG_ARB_ID   0x02 /* x86 IOAPIC only */
 
#define IOAPIC_FIXED   0x0
 
#define IOAPIC_LOWEST_PRIORITY   0x1
 
#define IOAPIC_PMI   0x2
 
#define IOAPIC_NMI   0x4
 
#define IOAPIC_INIT   0x5
 
#define IOAPIC_EXTINT   0x7
 
#define RTC_GSI   8
 
#define ASSERT(x)   do { } while (0)
 

Functions

static int ioapic_in_kernel (struct kvm *kvm)
 
void kvm_rtc_eoi_tracking_restore_one (struct kvm_vcpu *vcpu)
 
void kvm_ioapic_update_eoi (struct kvm_vcpu *vcpu, int vector, int trigger_mode)
 
int kvm_ioapic_init (struct kvm *kvm)
 
void kvm_ioapic_destroy (struct kvm *kvm)
 
int kvm_ioapic_set_irq (struct kvm_ioapic *ioapic, int irq, int irq_source_id, int level, bool line_status)
 
void kvm_ioapic_clear_all (struct kvm_ioapic *ioapic, int irq_source_id)
 
void kvm_get_ioapic (struct kvm *kvm, struct kvm_ioapic_state *state)
 
void kvm_set_ioapic (struct kvm *kvm, struct kvm_ioapic_state *state)
 
void kvm_ioapic_scan_entry (struct kvm_vcpu *vcpu, ulong *ioapic_handled_vectors)
 
void kvm_scan_ioapic_routes (struct kvm_vcpu *vcpu, ulong *ioapic_handled_vectors)
 

Macro Definition Documentation

◆ ASSERT

#define ASSERT (   x)    do { } while (0)

Definition at line 101 of file ioapic.h.

◆ IOAPIC_DEFAULT_BASE_ADDRESS

#define IOAPIC_DEFAULT_BASE_ADDRESS   0xfec00000

Definition at line 18 of file ioapic.h.

◆ IOAPIC_EDGE_TRIG

#define IOAPIC_EDGE_TRIG   0

Definition at line 15 of file ioapic.h.

◆ IOAPIC_EXTINT

#define IOAPIC_EXTINT   0x7

Definition at line 36 of file ioapic.h.

◆ IOAPIC_FIXED

#define IOAPIC_FIXED   0x0

Definition at line 31 of file ioapic.h.

◆ IOAPIC_INIT

#define IOAPIC_INIT   0x5

Definition at line 35 of file ioapic.h.

◆ IOAPIC_LEVEL_TRIG

#define IOAPIC_LEVEL_TRIG   1

Definition at line 16 of file ioapic.h.

◆ IOAPIC_LOWEST_PRIORITY

#define IOAPIC_LOWEST_PRIORITY   0x1

Definition at line 32 of file ioapic.h.

◆ IOAPIC_MEM_LENGTH

#define IOAPIC_MEM_LENGTH   0x100

Definition at line 19 of file ioapic.h.

◆ IOAPIC_NMI

#define IOAPIC_NMI   0x4

Definition at line 34 of file ioapic.h.

◆ IOAPIC_NUM_PINS

#define IOAPIC_NUM_PINS   KVM_IOAPIC_NUM_PINS

Definition at line 12 of file ioapic.h.

◆ IOAPIC_PMI

#define IOAPIC_PMI   0x2

Definition at line 33 of file ioapic.h.

◆ IOAPIC_REG_APIC_ID

#define IOAPIC_REG_APIC_ID   0x00 /* x86 IOAPIC only */

Definition at line 26 of file ioapic.h.

◆ IOAPIC_REG_ARB_ID

#define IOAPIC_REG_ARB_ID   0x02 /* x86 IOAPIC only */

Definition at line 28 of file ioapic.h.

◆ IOAPIC_REG_SELECT

#define IOAPIC_REG_SELECT   0x00

Definition at line 22 of file ioapic.h.

◆ IOAPIC_REG_VERSION

#define IOAPIC_REG_VERSION   0x01

Definition at line 27 of file ioapic.h.

◆ IOAPIC_REG_WINDOW

#define IOAPIC_REG_WINDOW   0x10

Definition at line 23 of file ioapic.h.

◆ IOAPIC_VERSION_ID

#define IOAPIC_VERSION_ID   0x11 /* IOAPIC version */

Definition at line 14 of file ioapic.h.

◆ MAX_NR_RESERVED_IOAPIC_PINS

#define MAX_NR_RESERVED_IOAPIC_PINS   KVM_MAX_IRQ_ROUTES

Definition at line 13 of file ioapic.h.

◆ RTC_GSI

#define RTC_GSI   8

Definition at line 38 of file ioapic.h.

Function Documentation

◆ ioapic_in_kernel()

static int ioapic_in_kernel ( struct kvm *  kvm)
inlinestatic

Definition at line 104 of file ioapic.h.

105 {
106  return irqchip_kernel(kvm);
107 }
static int irqchip_kernel(struct kvm *kvm)
Definition: irq.h:76
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_get_ioapic()

void kvm_get_ioapic ( struct kvm *  kvm,
struct kvm_ioapic_state *  state 
)

Definition at line 755 of file ioapic.c.

756 {
757  struct kvm_ioapic *ioapic = kvm->arch.vioapic;
758 
759  spin_lock(&ioapic->lock);
760  memcpy(state, ioapic, sizeof(struct kvm_ioapic_state));
761  state->irr &= ~ioapic->irr_delivered;
762  spin_unlock(&ioapic->lock);
763 }
struct kvm * kvm
Definition: ioapic.h:83
spinlock_t lock
Definition: ioapic.h:84
u32 irr_delivered
Definition: ioapic.h:88
int state
Definition: xen.h:0
Here is the caller graph for this function:

◆ kvm_ioapic_clear_all()

void kvm_ioapic_clear_all ( struct kvm_ioapic ioapic,
int  irq_source_id 
)

Definition at line 502 of file ioapic.c.

503 {
504  int i;
505 
506  spin_lock(&ioapic->lock);
507  for (i = 0; i < KVM_IOAPIC_NUM_PINS; i++)
508  __clear_bit(irq_source_id, &ioapic->irq_states[i]);
509  spin_unlock(&ioapic->lock);
510 }
unsigned long irq_states[IOAPIC_NUM_PINS]
Definition: ioapic.h:81
Here is the caller graph for this function:

◆ kvm_ioapic_destroy()

void kvm_ioapic_destroy ( struct kvm *  kvm)

Definition at line 740 of file ioapic.c.

741 {
742  struct kvm_ioapic *ioapic = kvm->arch.vioapic;
743 
744  if (!ioapic)
745  return;
746 
747  cancel_delayed_work_sync(&ioapic->eoi_inject);
748  mutex_lock(&kvm->slots_lock);
749  kvm_io_bus_unregister_dev(kvm, KVM_MMIO_BUS, &ioapic->dev);
750  mutex_unlock(&kvm->slots_lock);
751  kvm->arch.vioapic = NULL;
752  kfree(ioapic);
753 }
int kvm_io_bus_unregister_dev(struct kvm *kvm, enum kvm_bus bus_idx, struct kvm_io_device *dev)
Definition: kvm_main.c:5941
struct delayed_work eoi_inject
Definition: ioapic.h:86
struct kvm_io_device dev
Definition: ioapic.h:82
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_ioapic_init()

int kvm_ioapic_init ( struct kvm *  kvm)

Definition at line 714 of file ioapic.c.

715 {
716  struct kvm_ioapic *ioapic;
717  int ret;
718 
719  ioapic = kzalloc(sizeof(struct kvm_ioapic), GFP_KERNEL_ACCOUNT);
720  if (!ioapic)
721  return -ENOMEM;
722  spin_lock_init(&ioapic->lock);
723  INIT_DELAYED_WORK(&ioapic->eoi_inject, kvm_ioapic_eoi_inject_work);
724  kvm->arch.vioapic = ioapic;
725  kvm_ioapic_reset(ioapic);
727  ioapic->kvm = kvm;
728  mutex_lock(&kvm->slots_lock);
729  ret = kvm_io_bus_register_dev(kvm, KVM_MMIO_BUS, ioapic->base_address,
730  IOAPIC_MEM_LENGTH, &ioapic->dev);
731  mutex_unlock(&kvm->slots_lock);
732  if (ret < 0) {
733  kvm->arch.vioapic = NULL;
734  kfree(ioapic);
735  }
736 
737  return ret;
738 }
static void kvm_ioapic_eoi_inject_work(struct work_struct *work)
Definition: ioapic.c:512
static void kvm_ioapic_reset(struct kvm_ioapic *ioapic)
Definition: ioapic.c:693
static const struct kvm_io_device_ops ioapic_mmio_ops
Definition: ioapic.c:709
#define IOAPIC_MEM_LENGTH
Definition: ioapic.h:19
static void kvm_iodevice_init(struct kvm_io_device *dev, const struct kvm_io_device_ops *ops)
Definition: iodev.h:36
int kvm_io_bus_register_dev(struct kvm *kvm, enum kvm_bus bus_idx, gpa_t addr, int len, struct kvm_io_device *dev)
Definition: kvm_main.c:5897
u64 base_address
Definition: ioapic.h:75
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_ioapic_scan_entry()

void kvm_ioapic_scan_entry ( struct kvm_vcpu *  vcpu,
ulong *  ioapic_handled_vectors 
)

Definition at line 278 of file ioapic.c.

279 {
280  struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic;
281  struct dest_map *dest_map = &ioapic->rtc_status.dest_map;
282  union kvm_ioapic_redirect_entry *e;
283  int index;
284 
285  spin_lock(&ioapic->lock);
286 
287  /* Make sure we see any missing RTC EOI */
288  if (test_bit(vcpu->vcpu_id, dest_map->map))
289  __set_bit(dest_map->vectors[vcpu->vcpu_id],
290  ioapic_handled_vectors);
291 
292  for (index = 0; index < IOAPIC_NUM_PINS; index++) {
293  e = &ioapic->redirtbl[index];
294  if (e->fields.trig_mode == IOAPIC_LEVEL_TRIG ||
295  kvm_irq_has_notifier(ioapic->kvm, KVM_IRQCHIP_IOAPIC, index) ||
296  index == RTC_GSI) {
297  u16 dm = kvm_lapic_irq_dest_mode(!!e->fields.dest_mode);
298 
299  if (kvm_apic_match_dest(vcpu, NULL, APIC_DEST_NOSHORT,
300  e->fields.dest_id, dm) ||
302  __set_bit(e->fields.vector,
303  ioapic_handled_vectors);
304  }
305  }
306  spin_unlock(&ioapic->lock);
307 }
#define RTC_GSI
Definition: ioapic.h:38
#define IOAPIC_NUM_PINS
Definition: ioapic.h:12
#define IOAPIC_LEVEL_TRIG
Definition: ioapic.h:16
bool kvm_apic_pending_eoi(struct kvm_vcpu *vcpu, int vector)
Definition: lapic.c:110
bool kvm_apic_match_dest(struct kvm_vcpu *vcpu, struct kvm_lapic *source, int shorthand, unsigned int dest, int dest_mode)
Definition: lapic.c:1067
#define APIC_DEST_NOSHORT
Definition: lapic.h:16
u8 vectors[KVM_MAX_VCPU_IDS]
Definition: ioapic.h:48
struct rtc_status rtc_status
Definition: ioapic.h:85
union kvm_ioapic_redirect_entry redirtbl[IOAPIC_NUM_PINS]
Definition: ioapic.h:80
struct dest_map dest_map
Definition: ioapic.h:54
Definition: ioapic.h:57
u8 trig_mode
Definition: ioapic.h:66
u8 dest_mode
Definition: ioapic.h:62
u8 vector
Definition: ioapic.h:60
struct kvm_ioapic_redirect_entry::@1 fields
u8 dest_id
Definition: ioapic.h:70
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_ioapic_set_irq()

int kvm_ioapic_set_irq ( struct kvm_ioapic ioapic,
int  irq,
int  irq_source_id,
int  level,
bool  line_status 
)

Definition at line 485 of file ioapic.c.

487 {
488  int ret, irq_level;
489 
490  BUG_ON(irq < 0 || irq >= IOAPIC_NUM_PINS);
491 
492  spin_lock(&ioapic->lock);
493  irq_level = __kvm_irq_line_state(&ioapic->irq_states[irq],
494  irq_source_id, level);
495  ret = ioapic_set_irq(ioapic, irq, irq_level, line_status);
496 
497  spin_unlock(&ioapic->lock);
498 
499  return ret;
500 }
static int ioapic_set_irq(struct kvm_ioapic *ioapic, unsigned int irq, int irq_level, bool line_status)
Definition: ioapic.c:206
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_ioapic_update_eoi()

void kvm_ioapic_update_eoi ( struct kvm_vcpu *  vcpu,
int  vector,
int  trigger_mode 
)

Definition at line 579 of file ioapic.c.

580 {
581  int i;
582  struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic;
583 
584  spin_lock(&ioapic->lock);
585  rtc_irq_eoi(ioapic, vcpu, vector);
586  for (i = 0; i < IOAPIC_NUM_PINS; i++) {
587  union kvm_ioapic_redirect_entry *ent = &ioapic->redirtbl[i];
588 
589  if (ent->fields.vector != vector)
590  continue;
591  kvm_ioapic_update_eoi_one(vcpu, ioapic, trigger_mode, i);
592  }
593  spin_unlock(&ioapic->lock);
594 }
static void rtc_irq_eoi(struct kvm_ioapic *ioapic, struct kvm_vcpu *vcpu, int vector)
Definition: ioapic.c:161
static void kvm_ioapic_update_eoi_one(struct kvm_vcpu *vcpu, struct kvm_ioapic *ioapic, int trigger_mode, int pin)
Definition: ioapic.c:531
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_rtc_eoi_tracking_restore_one()

void kvm_rtc_eoi_tracking_restore_one ( struct kvm_vcpu *  vcpu)

Definition at line 139 of file ioapic.c.

140 {
141  struct kvm_ioapic *ioapic = vcpu->kvm->arch.vioapic;
142 
143  spin_lock(&ioapic->lock);
145  spin_unlock(&ioapic->lock);
146 }
static void __rtc_irq_eoi_tracking_restore_one(struct kvm_vcpu *vcpu)
Definition: ioapic.c:109
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_scan_ioapic_routes()

void kvm_scan_ioapic_routes ( struct kvm_vcpu *  vcpu,
ulong *  ioapic_handled_vectors 
)

Definition at line 412 of file irq_comm.c.

414 {
415  struct kvm *kvm = vcpu->kvm;
416  struct kvm_kernel_irq_routing_entry *entry;
417  struct kvm_irq_routing_table *table;
418  u32 i, nr_ioapic_pins;
419  int idx;
420 
421  idx = srcu_read_lock(&kvm->irq_srcu);
422  table = srcu_dereference(kvm->irq_routing, &kvm->irq_srcu);
423  nr_ioapic_pins = min_t(u32, table->nr_rt_entries,
424  kvm->arch.nr_reserved_ioapic_pins);
425  for (i = 0; i < nr_ioapic_pins; ++i) {
426  hlist_for_each_entry(entry, &table->map[i], link) {
427  struct kvm_lapic_irq irq;
428 
429  if (entry->type != KVM_IRQ_ROUTING_MSI)
430  continue;
431 
432  kvm_set_msi_irq(vcpu->kvm, entry, &irq);
433 
434  if (irq.trig_mode &&
436  irq.dest_id, irq.dest_mode) ||
437  kvm_apic_pending_eoi(vcpu, irq.vector)))
438  __set_bit(irq.vector, ioapic_handled_vectors);
439  }
440  }
441  srcu_read_unlock(&kvm->irq_srcu, idx);
442 }
void kvm_set_msi_irq(struct kvm *kvm, struct kvm_kernel_irq_routing_entry *e, struct kvm_lapic_irq *irq)
Definition: irq_comm.c:104
Here is the call graph for this function:
Here is the caller graph for this function:

◆ kvm_set_ioapic()

void kvm_set_ioapic ( struct kvm *  kvm,
struct kvm_ioapic_state *  state 
)

Definition at line 765 of file ioapic.c.

766 {
767  struct kvm_ioapic *ioapic = kvm->arch.vioapic;
768 
769  spin_lock(&ioapic->lock);
770  memcpy(ioapic, state, sizeof(struct kvm_ioapic_state));
771  ioapic->irr = 0;
772  ioapic->irr_delivered = 0;
774  kvm_ioapic_inject_all(ioapic, state->irr);
775  spin_unlock(&ioapic->lock);
776 }
static void kvm_ioapic_inject_all(struct kvm_ioapic *ioapic, unsigned long irr)
Definition: ioapic.c:266
u32 irr
Definition: ioapic.h:78
void kvm_make_scan_ioapic_request(struct kvm *kvm)
Definition: x86.c:10520
Here is the call graph for this function:
Here is the caller graph for this function: