Lines Matching +full:pin +full:- +full:val
1 /*-
2 * SPDX-License-Identifier: BSD-2-Clause
54 #define VATPIC_LOCK(vatpic) mtx_lock_spin(&((vatpic)->mtx))
55 #define VATPIC_UNLOCK(vatpic) mtx_unlock_spin(&((vatpic)->mtx))
56 #define VATPIC_LOCKED(vatpic) mtx_owned(&((vatpic)->mtx))
72 bool sfn; /* special fully-nested mode */
80 int acnt[8]; /* sum of pin asserts and deasserts */
94 VM_CTR0((vatpic)->vm, fmt)
97 VM_CTR1((vatpic)->vm, fmt, a1)
100 VM_CTR2((vatpic)->vm, fmt, a1, a2)
103 VM_CTR3((vatpic)->vm, fmt, a1, a2, a3)
106 VM_CTR4((vatpic)->vm, fmt, a1, a2, a3, a4)
112 for (tmpvar = 0, pinvar = (atpic->lowprio + 1) & 0x7; \
116 static void vatpic_set_pinstate(struct vatpic *vatpic, int pin, bool newstate);
122 if (atpic == &vatpic->atpic[0]) in master_atpic()
131 int bit, pin; in vatpic_get_highest_isrpin() local
134 ATPIC_PIN_FOREACH(pin, atpic, i) { in vatpic_get_highest_isrpin()
135 bit = (1 << pin); in vatpic_get_highest_isrpin()
137 if (atpic->service & bit) { in vatpic_get_highest_isrpin()
140 * cleared by a non-specific EOI in Special Mask Mode. in vatpic_get_highest_isrpin()
142 if (atpic->smm && (atpic->mask & bit) != 0) in vatpic_get_highest_isrpin()
145 return (pin); in vatpic_get_highest_isrpin()
149 return (-1); in vatpic_get_highest_isrpin()
156 int bit, pin, tmp; in vatpic_get_highest_irrpin() local
159 * In 'Special Fully-Nested Mode' when an interrupt request from in vatpic_get_highest_irrpin()
163 serviced = atpic->service; in vatpic_get_highest_irrpin()
164 if (atpic->sfn) in vatpic_get_highest_irrpin()
173 if (atpic->smm) in vatpic_get_highest_irrpin()
176 ATPIC_PIN_FOREACH(pin, atpic, tmp) { in vatpic_get_highest_irrpin()
177 bit = 1 << pin; in vatpic_get_highest_irrpin()
188 * the corresponding 'pin' to the caller. in vatpic_get_highest_irrpin()
190 if ((atpic->request & bit) != 0 && (atpic->mask & bit) == 0) in vatpic_get_highest_irrpin()
191 return (pin); in vatpic_get_highest_irrpin()
194 return (-1); in vatpic_get_highest_irrpin()
201 int pin; in vatpic_notify_intr() local
208 atpic = &vatpic->atpic[1]; in vatpic_notify_intr()
209 if (!atpic->intr_raised && in vatpic_notify_intr()
210 (pin = vatpic_get_highest_irrpin(atpic)) != -1) { in vatpic_notify_intr()
211 VATPIC_CTR4(vatpic, "atpic slave notify pin = %d " in vatpic_notify_intr()
212 "(imr 0x%x irr 0x%x isr 0x%x)", pin, in vatpic_notify_intr()
213 atpic->mask, atpic->request, atpic->service); in vatpic_notify_intr()
218 atpic->intr_raised = true; in vatpic_notify_intr()
224 atpic->mask, atpic->request, atpic->service); in vatpic_notify_intr()
230 atpic = &vatpic->atpic[0]; in vatpic_notify_intr()
231 if (!atpic->intr_raised && in vatpic_notify_intr()
232 (pin = vatpic_get_highest_irrpin(atpic)) != -1) { in vatpic_notify_intr()
233 VATPIC_CTR4(vatpic, "atpic master notify pin = %d " in vatpic_notify_intr()
234 "(imr 0x%x irr 0x%x isr 0x%x)", pin, in vatpic_notify_intr()
235 atpic->mask, atpic->request, atpic->service); in vatpic_notify_intr()
262 atpic->intr_raised = true; in vatpic_notify_intr()
263 lapic_set_local_intr(vatpic->vm, NULL, APIC_LVT_LINT0); in vatpic_notify_intr()
264 vioapic_pulse_irq(vatpic->vm, 0); in vatpic_notify_intr()
268 atpic->mask, atpic->request, atpic->service); in vatpic_notify_intr()
273 vatpic_icw1(struct vatpic *vatpic, struct atpic *atpic, uint8_t val) in vatpic_icw1() argument
275 VATPIC_CTR1(vatpic, "atpic icw1 0x%x", val); in vatpic_icw1()
277 atpic->ready = false; in vatpic_icw1()
279 atpic->icw_num = 1; in vatpic_icw1()
280 atpic->request = 0; in vatpic_icw1()
281 atpic->mask = 0; in vatpic_icw1()
282 atpic->lowprio = 7; in vatpic_icw1()
283 atpic->rd_cmd_reg = 0; in vatpic_icw1()
284 atpic->poll = 0; in vatpic_icw1()
285 atpic->smm = 0; in vatpic_icw1()
287 if ((val & ICW1_SNGL) != 0) { in vatpic_icw1()
289 return (-1); in vatpic_icw1()
292 if ((val & ICW1_IC4) == 0) { in vatpic_icw1()
294 return (-1); in vatpic_icw1()
297 atpic->icw_num++; in vatpic_icw1()
303 vatpic_icw2(struct vatpic *vatpic, struct atpic *atpic, uint8_t val) in vatpic_icw2() argument
305 VATPIC_CTR1(vatpic, "atpic icw2 0x%x", val); in vatpic_icw2()
307 atpic->irq_base = val & 0xf8; in vatpic_icw2()
309 atpic->icw_num++; in vatpic_icw2()
315 vatpic_icw3(struct vatpic *vatpic, struct atpic *atpic, uint8_t val) in vatpic_icw3() argument
317 VATPIC_CTR1(vatpic, "atpic icw3 0x%x", val); in vatpic_icw3()
319 atpic->icw_num++; in vatpic_icw3()
325 vatpic_icw4(struct vatpic *vatpic, struct atpic *atpic, uint8_t val) in vatpic_icw4() argument
327 VATPIC_CTR1(vatpic, "atpic icw4 0x%x", val); in vatpic_icw4()
329 if ((val & ICW4_8086) == 0) { in vatpic_icw4()
331 return (-1); in vatpic_icw4()
334 if ((val & ICW4_AEOI) != 0) in vatpic_icw4()
335 atpic->aeoi = true; in vatpic_icw4()
337 if ((val & ICW4_SFNM) != 0) { in vatpic_icw4()
339 atpic->sfn = true; in vatpic_icw4()
342 "mode on slave atpic: %#x", val); in vatpic_icw4()
346 atpic->icw_num = 0; in vatpic_icw4()
347 atpic->ready = true; in vatpic_icw4()
353 vatpic_ocw1(struct vatpic *vatpic, struct atpic *atpic, uint8_t val) in vatpic_ocw1() argument
355 VATPIC_CTR1(vatpic, "atpic ocw1 0x%x", val); in vatpic_ocw1()
357 atpic->mask = val & 0xff; in vatpic_ocw1()
363 vatpic_ocw2(struct vatpic *vatpic, struct atpic *atpic, uint8_t val) in vatpic_ocw2() argument
365 VATPIC_CTR1(vatpic, "atpic ocw2 0x%x", val); in vatpic_ocw2()
367 atpic->rotate = ((val & OCW2_R) != 0); in vatpic_ocw2()
369 if ((val & OCW2_EOI) != 0) { in vatpic_ocw2()
372 if ((val & OCW2_SL) != 0) { in vatpic_ocw2()
374 isr_bit = val & 0x7; in vatpic_ocw2()
376 /* non-specific EOI */ in vatpic_ocw2()
380 if (isr_bit != -1) { in vatpic_ocw2()
381 atpic->service &= ~(1 << isr_bit); in vatpic_ocw2()
383 if (atpic->rotate) in vatpic_ocw2()
384 atpic->lowprio = isr_bit; in vatpic_ocw2()
386 } else if ((val & OCW2_SL) != 0 && atpic->rotate == true) { in vatpic_ocw2()
388 atpic->lowprio = val & 0x7; in vatpic_ocw2()
395 vatpic_ocw3(struct vatpic *vatpic, struct atpic *atpic, uint8_t val) in vatpic_ocw3() argument
397 VATPIC_CTR1(vatpic, "atpic ocw3 0x%x", val); in vatpic_ocw3()
399 if (val & OCW3_ESMM) { in vatpic_ocw3()
400 atpic->smm = val & OCW3_SMM ? 1 : 0; in vatpic_ocw3()
403 atpic->smm ? "enabled" : "disabled"); in vatpic_ocw3()
406 if (val & OCW3_RR) { in vatpic_ocw3()
408 atpic->rd_cmd_reg = val & OCW3_RIS; in vatpic_ocw3()
411 atpic->poll = ((val & OCW3_P) != 0); in vatpic_ocw3()
418 vatpic_set_pinstate(struct vatpic *vatpic, int pin, bool newstate) in vatpic_set_pinstate() argument
424 KASSERT(pin >= 0 && pin < 16, in vatpic_set_pinstate()
425 ("vatpic_set_pinstate: invalid pin number %d", pin)); in vatpic_set_pinstate()
429 atpic = &vatpic->atpic[pin >> 3]; in vatpic_set_pinstate()
431 oldcnt = atpic->acnt[pin & 0x7]; in vatpic_set_pinstate()
433 atpic->acnt[pin & 0x7]++; in vatpic_set_pinstate()
435 atpic->acnt[pin & 0x7]--; in vatpic_set_pinstate()
436 newcnt = atpic->acnt[pin & 0x7]; in vatpic_set_pinstate()
439 VATPIC_CTR2(vatpic, "atpic pin%d: bad acnt %d", pin, newcnt); in vatpic_set_pinstate()
442 level = ((vatpic->elc[pin >> 3] & (1 << (pin & 0x7))) != 0); in vatpic_set_pinstate()
446 VATPIC_CTR1(vatpic, "atpic pin%d: asserted", pin); in vatpic_set_pinstate()
447 atpic->request |= (1 << (pin & 0x7)); in vatpic_set_pinstate()
450 VATPIC_CTR1(vatpic, "atpic pin%d: deasserted", pin); in vatpic_set_pinstate()
452 atpic->request &= ~(1 << (pin & 0x7)); in vatpic_set_pinstate()
454 VATPIC_CTR3(vatpic, "atpic pin%d: %s, ignored, acnt %d", in vatpic_set_pinstate()
455 pin, newstate ? "asserted" : "deasserted", newcnt); in vatpic_set_pinstate()
471 atpic = &vatpic->atpic[irq >> 3]; in vatpic_set_irqstate()
473 if (atpic->ready == false) in vatpic_set_irqstate()
542 vatpic->elc[irq >> 3] |= 1 << (irq & 0x7); in vatpic_set_irq_trigger()
544 vatpic->elc[irq >> 3] &= ~(1 << (irq & 0x7)); in vatpic_set_irq_trigger()
556 int pin; in vatpic_pending_intr() local
560 atpic = &vatpic->atpic[0]; in vatpic_pending_intr()
564 pin = vatpic_get_highest_irrpin(atpic); in vatpic_pending_intr()
565 if (pin == 2) { in vatpic_pending_intr()
566 atpic = &vatpic->atpic[1]; in vatpic_pending_intr()
567 pin = vatpic_get_highest_irrpin(atpic); in vatpic_pending_intr()
574 if (pin == -1) in vatpic_pending_intr()
575 pin = 7; in vatpic_pending_intr()
577 KASSERT(pin >= 0 && pin <= 7, ("%s: invalid pin %d", __func__, pin)); in vatpic_pending_intr()
578 *vecptr = atpic->irq_base + pin; in vatpic_pending_intr()
584 vatpic_pin_accepted(struct atpic *atpic, int pin) in vatpic_pin_accepted() argument
586 atpic->intr_raised = false; in vatpic_pin_accepted()
588 if (atpic->acnt[pin] == 0) in vatpic_pin_accepted()
589 atpic->request &= ~(1 << pin); in vatpic_pin_accepted()
591 if (atpic->aeoi == true) { in vatpic_pin_accepted()
592 if (atpic->rotate == true) in vatpic_pin_accepted()
593 atpic->lowprio = pin; in vatpic_pin_accepted()
595 atpic->service |= (1 << pin); in vatpic_pin_accepted()
603 int pin; in vatpic_intr_accepted() local
609 pin = vector & 0x7; in vatpic_intr_accepted()
611 if ((vector & ~0x7) == vatpic->atpic[1].irq_base) { in vatpic_intr_accepted()
612 vatpic_pin_accepted(&vatpic->atpic[1], pin); in vatpic_intr_accepted()
617 vatpic_pin_accepted(&vatpic->atpic[0], 2); in vatpic_intr_accepted()
619 vatpic_pin_accepted(&vatpic->atpic[0], pin); in vatpic_intr_accepted()
631 int pin; in vatpic_read() local
635 if (atpic->poll) { in vatpic_read()
636 atpic->poll = 0; in vatpic_read()
637 pin = vatpic_get_highest_irrpin(atpic); in vatpic_read()
638 if (pin >= 0) { in vatpic_read()
639 vatpic_pin_accepted(atpic, pin); in vatpic_read()
640 *eax = 0x80 | pin; in vatpic_read()
647 *eax = atpic->mask; in vatpic_read()
649 if (atpic->rd_cmd_reg == OCW3_RIS) { in vatpic_read()
651 *eax = atpic->service; in vatpic_read()
654 *eax = atpic->request; in vatpic_read()
670 uint8_t val; in vatpic_write() local
673 val = *eax; in vatpic_write()
678 switch (atpic->icw_num) { in vatpic_write()
680 error = vatpic_icw2(vatpic, atpic, val); in vatpic_write()
683 error = vatpic_icw3(vatpic, atpic, val); in vatpic_write()
686 error = vatpic_icw4(vatpic, atpic, val); in vatpic_write()
689 error = vatpic_ocw1(vatpic, atpic, val); in vatpic_write()
693 if (val & (1 << 4)) in vatpic_write()
694 error = vatpic_icw1(vatpic, atpic, val); in vatpic_write()
696 if (atpic->ready) { in vatpic_write()
697 if (val & (1 << 3)) in vatpic_write()
698 error = vatpic_ocw3(vatpic, atpic, val); in vatpic_write()
700 error = vatpic_ocw2(vatpic, atpic, val); in vatpic_write()
704 if (atpic->ready) in vatpic_write()
720 atpic = &vatpic->atpic[0]; in vatpic_master_handler()
723 return (-1); in vatpic_master_handler()
740 atpic = &vatpic->atpic[1]; in vatpic_slave_handler()
743 return (-1); in vatpic_slave_handler()
763 return (-1); in vatpic_elc_handler()
769 *eax = vatpic->elc[0]; in vatpic_elc_handler()
771 *eax = vatpic->elc[1]; in vatpic_elc_handler()
784 vatpic->elc[0] = (*eax & 0xf8); in vatpic_elc_handler()
786 vatpic->elc[1] = (*eax & 0xde); in vatpic_elc_handler()
800 vatpic->vm = vm; in vatpic_init()
802 mtx_init(&vatpic->mtx, "vatpic lock", NULL, MTX_SPIN); in vatpic_init()
810 mtx_destroy(&vatpic->mtx); in vatpic_cleanup()
822 for (i = 0; i < nitems(vatpic->atpic); i++) { in vatpic_snapshot()
823 atpic = &vatpic->atpic[i]; in vatpic_snapshot()
825 SNAPSHOT_VAR_OR_LEAVE(atpic->ready, meta, ret, done); in vatpic_snapshot()
826 SNAPSHOT_VAR_OR_LEAVE(atpic->icw_num, meta, ret, done); in vatpic_snapshot()
827 SNAPSHOT_VAR_OR_LEAVE(atpic->rd_cmd_reg, meta, ret, done); in vatpic_snapshot()
829 SNAPSHOT_VAR_OR_LEAVE(atpic->aeoi, meta, ret, done); in vatpic_snapshot()
830 SNAPSHOT_VAR_OR_LEAVE(atpic->poll, meta, ret, done); in vatpic_snapshot()
831 SNAPSHOT_VAR_OR_LEAVE(atpic->rotate, meta, ret, done); in vatpic_snapshot()
832 SNAPSHOT_VAR_OR_LEAVE(atpic->sfn, meta, ret, done); in vatpic_snapshot()
833 SNAPSHOT_VAR_OR_LEAVE(atpic->irq_base, meta, ret, done); in vatpic_snapshot()
834 SNAPSHOT_VAR_OR_LEAVE(atpic->request, meta, ret, done); in vatpic_snapshot()
835 SNAPSHOT_VAR_OR_LEAVE(atpic->service, meta, ret, done); in vatpic_snapshot()
836 SNAPSHOT_VAR_OR_LEAVE(atpic->mask, meta, ret, done); in vatpic_snapshot()
837 SNAPSHOT_VAR_OR_LEAVE(atpic->smm, meta, ret, done); in vatpic_snapshot()
839 SNAPSHOT_BUF_OR_LEAVE(atpic->acnt, sizeof(atpic->acnt), in vatpic_snapshot()
841 SNAPSHOT_VAR_OR_LEAVE(atpic->lowprio, meta, ret, done); in vatpic_snapshot()
842 SNAPSHOT_VAR_OR_LEAVE(atpic->intr_raised, meta, ret, done); in vatpic_snapshot()
845 SNAPSHOT_BUF_OR_LEAVE(vatpic->elc, sizeof(vatpic->elc), in vatpic_snapshot()