Lines Matching refs:s

42 static void pic_lock(struct kvm_pic *s)  in pic_lock()  argument
43 __acquires(&s->lock) in pic_lock()
45 spin_lock(&s->lock); in pic_lock()
48 static void pic_unlock(struct kvm_pic *s) in pic_unlock() argument
49 __releases(&s->lock) in pic_unlock()
51 bool wakeup = s->wakeup_needed; in pic_unlock()
55 s->wakeup_needed = false; in pic_unlock()
57 spin_unlock(&s->lock); in pic_unlock()
60 kvm_for_each_vcpu(i, vcpu, s->kvm) { in pic_unlock()
70 static void pic_clear_isr(struct kvm_kpic_state *s, int irq) in pic_clear_isr() argument
72 s->isr &= ~(1 << irq); in pic_clear_isr()
73 if (s != &s->pics_state->pics[0]) in pic_clear_isr()
81 pic_unlock(s->pics_state); in pic_clear_isr()
82 kvm_notify_acked_irq(s->pics_state->kvm, SELECT_PIC(irq), irq); in pic_clear_isr()
83 pic_lock(s->pics_state); in pic_clear_isr()
89 static inline int pic_set_irq1(struct kvm_kpic_state *s, int irq, int level) in pic_set_irq1() argument
93 if (s->elcr & mask) /* level triggered */ in pic_set_irq1()
95 ret = !(s->irr & mask); in pic_set_irq1()
96 s->irr |= mask; in pic_set_irq1()
97 s->last_irr |= mask; in pic_set_irq1()
99 s->irr &= ~mask; in pic_set_irq1()
100 s->last_irr &= ~mask; in pic_set_irq1()
104 if ((s->last_irr & mask) == 0) { in pic_set_irq1()
105 ret = !(s->irr & mask); in pic_set_irq1()
106 s->irr |= mask; in pic_set_irq1()
108 s->last_irr |= mask; in pic_set_irq1()
110 s->last_irr &= ~mask; in pic_set_irq1()
112 return (s->imr & mask) ? -1 : ret; in pic_set_irq1()
119 static inline int get_priority(struct kvm_kpic_state *s, int mask) in get_priority() argument
125 while ((mask & (1 << ((priority + s->priority_add) & 7))) == 0) in get_priority()
133 static int pic_get_irq(struct kvm_kpic_state *s) in pic_get_irq() argument
137 mask = s->irr & ~s->imr; in pic_get_irq()
138 priority = get_priority(s, mask); in pic_get_irq()
146 mask = s->isr; in pic_get_irq()
147 if (s->special_fully_nested_mode && s == &s->pics_state->pics[0]) in pic_get_irq()
149 cur_priority = get_priority(s, mask); in pic_get_irq()
154 return (priority + s->priority_add) & 7; in pic_get_irq()
163 static void pic_update_irq(struct kvm_pic *s) in pic_update_irq() argument
167 irq2 = pic_get_irq(&s->pics[1]); in pic_update_irq()
172 pic_set_irq1(&s->pics[0], 2, 1); in pic_update_irq()
173 pic_set_irq1(&s->pics[0], 2, 0); in pic_update_irq()
175 irq = pic_get_irq(&s->pics[0]); in pic_update_irq()
176 pic_irq_request(s->kvm, irq >= 0); in pic_update_irq()
179 void kvm_pic_update_irq(struct kvm_pic *s) in kvm_pic_update_irq() argument
181 pic_lock(s); in kvm_pic_update_irq()
182 pic_update_irq(s); in kvm_pic_update_irq()
183 pic_unlock(s); in kvm_pic_update_irq()
186 int kvm_pic_set_irq(struct kvm_pic *s, int irq, int irq_source_id, int level) in kvm_pic_set_irq() argument
192 pic_lock(s); in kvm_pic_set_irq()
193 irq_level = __kvm_irq_line_state(&s->irq_states[irq], in kvm_pic_set_irq()
195 ret = pic_set_irq1(&s->pics[irq >> 3], irq & 7, irq_level); in kvm_pic_set_irq()
196 pic_update_irq(s); in kvm_pic_set_irq()
197 trace_kvm_pic_set_irq(irq >> 3, irq & 7, s->pics[irq >> 3].elcr, in kvm_pic_set_irq()
198 s->pics[irq >> 3].imr, ret == 0); in kvm_pic_set_irq()
199 pic_unlock(s); in kvm_pic_set_irq()
204 void kvm_pic_clear_all(struct kvm_pic *s, int irq_source_id) in kvm_pic_clear_all() argument
208 pic_lock(s); in kvm_pic_clear_all()
210 __clear_bit(irq_source_id, &s->irq_states[i]); in kvm_pic_clear_all()
211 pic_unlock(s); in kvm_pic_clear_all()
217 static inline void pic_intack(struct kvm_kpic_state *s, int irq) in pic_intack() argument
219 s->isr |= 1 << irq; in pic_intack()
223 if (!(s->elcr & (1 << irq))) in pic_intack()
224 s->irr &= ~(1 << irq); in pic_intack()
226 if (s->auto_eoi) { in pic_intack()
227 if (s->rotate_on_auto_eoi) in pic_intack()
228 s->priority_add = (irq + 1) & 7; in pic_intack()
229 pic_clear_isr(s, irq); in pic_intack()
237 struct kvm_pic *s = kvm->arch.vpic; in kvm_pic_read_irq() local
239 s->output = 0; in kvm_pic_read_irq()
241 pic_lock(s); in kvm_pic_read_irq()
242 irq = pic_get_irq(&s->pics[0]); in kvm_pic_read_irq()
244 pic_intack(&s->pics[0], irq); in kvm_pic_read_irq()
246 irq2 = pic_get_irq(&s->pics[1]); in kvm_pic_read_irq()
248 pic_intack(&s->pics[1], irq2); in kvm_pic_read_irq()
254 intno = s->pics[1].irq_base + irq2; in kvm_pic_read_irq()
256 intno = s->pics[0].irq_base + irq; in kvm_pic_read_irq()
262 intno = s->pics[0].irq_base + irq; in kvm_pic_read_irq()
264 pic_update_irq(s); in kvm_pic_read_irq()
265 pic_unlock(s); in kvm_pic_read_irq()
270 static void kvm_pic_reset(struct kvm_kpic_state *s) in kvm_pic_reset() argument
275 u8 edge_irr = s->irr & ~s->elcr; in kvm_pic_reset()
278 s->last_irr = 0; in kvm_pic_reset()
279 s->irr &= s->elcr; in kvm_pic_reset()
280 s->imr = 0; in kvm_pic_reset()
281 s->priority_add = 0; in kvm_pic_reset()
282 s->special_mask = 0; in kvm_pic_reset()
283 s->read_reg_select = 0; in kvm_pic_reset()
284 if (!s->init4) { in kvm_pic_reset()
285 s->special_fully_nested_mode = 0; in kvm_pic_reset()
286 s->auto_eoi = 0; in kvm_pic_reset()
288 s->init_state = 1; in kvm_pic_reset()
290 kvm_for_each_vcpu(i, vcpu, s->pics_state->kvm) in kvm_pic_reset()
302 pic_clear_isr(s, irq); in kvm_pic_reset()
307 struct kvm_kpic_state *s = opaque; in pic_ioport_write() local
313 s->init4 = val & 1; in pic_ioport_write()
319 kvm_pic_reset(s); in pic_ioport_write()
322 s->poll = 1; in pic_ioport_write()
324 s->read_reg_select = val & 1; in pic_ioport_write()
326 s->special_mask = (val >> 5) & 1; in pic_ioport_write()
332 s->rotate_on_auto_eoi = cmd >> 2; in pic_ioport_write()
336 priority = get_priority(s, s->isr); in pic_ioport_write()
338 irq = (priority + s->priority_add) & 7; in pic_ioport_write()
340 s->priority_add = (irq + 1) & 7; in pic_ioport_write()
341 pic_clear_isr(s, irq); in pic_ioport_write()
342 pic_update_irq(s->pics_state); in pic_ioport_write()
347 pic_clear_isr(s, irq); in pic_ioport_write()
348 pic_update_irq(s->pics_state); in pic_ioport_write()
351 s->priority_add = (val + 1) & 7; in pic_ioport_write()
352 pic_update_irq(s->pics_state); in pic_ioport_write()
356 s->priority_add = (irq + 1) & 7; in pic_ioport_write()
357 pic_clear_isr(s, irq); in pic_ioport_write()
358 pic_update_irq(s->pics_state); in pic_ioport_write()
365 switch (s->init_state) { in pic_ioport_write()
367 u8 imr_diff = s->imr ^ val, in pic_ioport_write()
368 off = (s == &s->pics_state->pics[0]) ? 0 : 8; in pic_ioport_write()
369 s->imr = val; in pic_ioport_write()
373 s->pics_state->kvm, in pic_ioport_write()
376 !!(s->imr & (1 << irq))); in pic_ioport_write()
377 pic_update_irq(s->pics_state); in pic_ioport_write()
381 s->irq_base = val & 0xf8; in pic_ioport_write()
382 s->init_state = 2; in pic_ioport_write()
385 if (s->init4) in pic_ioport_write()
386 s->init_state = 3; in pic_ioport_write()
388 s->init_state = 0; in pic_ioport_write()
391 s->special_fully_nested_mode = (val >> 4) & 1; in pic_ioport_write()
392 s->auto_eoi = (val >> 1) & 1; in pic_ioport_write()
393 s->init_state = 0; in pic_ioport_write()
398 static u32 pic_poll_read(struct kvm_kpic_state *s, u32 addr1) in pic_poll_read() argument
402 ret = pic_get_irq(s); in pic_poll_read()
405 s->pics_state->pics[0].isr &= ~(1 << 2); in pic_poll_read()
406 s->pics_state->pics[0].irr &= ~(1 << 2); in pic_poll_read()
408 s->irr &= ~(1 << ret); in pic_poll_read()
409 pic_clear_isr(s, ret); in pic_poll_read()
411 pic_update_irq(s->pics_state); in pic_poll_read()
414 pic_update_irq(s->pics_state); in pic_poll_read()
422 struct kvm_kpic_state *s = opaque; in pic_ioport_read() local
425 if (s->poll) { in pic_ioport_read()
426 ret = pic_poll_read(s, addr); in pic_ioport_read()
427 s->poll = 0; in pic_ioport_read()
430 if (s->read_reg_select) in pic_ioport_read()
431 ret = s->isr; in pic_ioport_read()
433 ret = s->irr; in pic_ioport_read()
435 ret = s->imr; in pic_ioport_read()
441 struct kvm_kpic_state *s = opaque; in elcr_ioport_write() local
442 s->elcr = val & s->elcr_mask; in elcr_ioport_write()
447 struct kvm_kpic_state *s = opaque; in elcr_ioport_read() local
448 return s->elcr; in elcr_ioport_read()
451 static int picdev_write(struct kvm_pic *s, in picdev_write() argument
463 pic_lock(s); in picdev_write()
464 pic_ioport_write(&s->pics[0], addr, data); in picdev_write()
465 pic_unlock(s); in picdev_write()
469 pic_lock(s); in picdev_write()
470 pic_ioport_write(&s->pics[1], addr, data); in picdev_write()
471 pic_unlock(s); in picdev_write()
475 pic_lock(s); in picdev_write()
476 elcr_ioport_write(&s->pics[addr & 1], data); in picdev_write()
477 pic_unlock(s); in picdev_write()
485 static int picdev_read(struct kvm_pic *s, in picdev_read() argument
500 pic_lock(s); in picdev_read()
501 *data = pic_ioport_read(&s->pics[addr >> 7], addr); in picdev_read()
502 pic_unlock(s); in picdev_read()
506 pic_lock(s); in picdev_read()
507 *data = elcr_ioport_read(&s->pics[addr & 1]); in picdev_read()
508 pic_unlock(s); in picdev_read()
563 struct kvm_pic *s = kvm->arch.vpic; in pic_irq_request() local
565 if (!s->output) in pic_irq_request()
566 s->wakeup_needed = true; in pic_irq_request()
567 s->output = level; in pic_irq_request()
587 struct kvm_pic *s; in kvm_pic_init() local
590 s = kzalloc(sizeof(struct kvm_pic), GFP_KERNEL_ACCOUNT); in kvm_pic_init()
591 if (!s) in kvm_pic_init()
593 spin_lock_init(&s->lock); in kvm_pic_init()
594 s->kvm = kvm; in kvm_pic_init()
595 s->pics[0].elcr_mask = 0xf8; in kvm_pic_init()
596 s->pics[1].elcr_mask = 0xde; in kvm_pic_init()
597 s->pics[0].pics_state = s; in kvm_pic_init()
598 s->pics[1].pics_state = s; in kvm_pic_init()
603 kvm_iodevice_init(&s->dev_master, &picdev_master_ops); in kvm_pic_init()
604 kvm_iodevice_init(&s->dev_slave, &picdev_slave_ops); in kvm_pic_init()
605 kvm_iodevice_init(&s->dev_elcr, &picdev_elcr_ops); in kvm_pic_init()
608 &s->dev_master); in kvm_pic_init()
612 ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, 0xa0, 2, &s->dev_slave); in kvm_pic_init()
616 ret = kvm_io_bus_register_dev(kvm, KVM_PIO_BUS, 0x4d0, 2, &s->dev_elcr); in kvm_pic_init()
622 kvm->arch.vpic = s; in kvm_pic_init()
627 kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &s->dev_slave); in kvm_pic_init()
630 kvm_io_bus_unregister_dev(kvm, KVM_PIO_BUS, &s->dev_master); in kvm_pic_init()
635 kfree(s); in kvm_pic_init()