187ecb68bSpbrook #ifndef QEMU_IRQ_H 287ecb68bSpbrook #define QEMU_IRQ_H 387ecb68bSpbrook 4e72a7f65SBALATON Zoltan #include "qom/object.h" 5e72a7f65SBALATON Zoltan 6d537cf6cSpbrook /* Generic IRQ/GPIO pin infrastructure. */ 7d537cf6cSpbrook 8615c4895SAndreas Färber #define TYPE_IRQ "irq" 9e72a7f65SBALATON Zoltan OBJECT_DECLARE_SIMPLE_TYPE(IRQState, IRQ) 10e72a7f65SBALATON Zoltan 11e72a7f65SBALATON Zoltan struct IRQState { 12e72a7f65SBALATON Zoltan Object parent_obj; 13e72a7f65SBALATON Zoltan 14e72a7f65SBALATON Zoltan qemu_irq_handler handler; 15e72a7f65SBALATON Zoltan void *opaque; 16e72a7f65SBALATON Zoltan int n; 17e72a7f65SBALATON Zoltan }; 18615c4895SAndreas Färber 19d537cf6cSpbrook void qemu_set_irq(qemu_irq irq, int level); 20d537cf6cSpbrook 21d537cf6cSpbrook static inline void qemu_irq_raise(qemu_irq irq) 22d537cf6cSpbrook { 23d537cf6cSpbrook qemu_set_irq(irq, 1); 24d537cf6cSpbrook } 25d537cf6cSpbrook 26d537cf6cSpbrook static inline void qemu_irq_lower(qemu_irq irq) 27d537cf6cSpbrook { 28d537cf6cSpbrook qemu_set_irq(irq, 0); 29d537cf6cSpbrook } 30d537cf6cSpbrook 31106627d0Sbalrog static inline void qemu_irq_pulse(qemu_irq irq) 32106627d0Sbalrog { 33106627d0Sbalrog qemu_set_irq(irq, 1); 34106627d0Sbalrog qemu_set_irq(irq, 0); 35106627d0Sbalrog } 36106627d0Sbalrog 37e72a7f65SBALATON Zoltan /* 38e72a7f65SBALATON Zoltan * Init a single IRQ. The irq is assigned with a handler, an opaque data 39e72a7f65SBALATON Zoltan * and the interrupt number. 40e72a7f65SBALATON Zoltan */ 41e72a7f65SBALATON Zoltan void qemu_init_irq(IRQState *irq, qemu_irq_handler handler, void *opaque, 42e72a7f65SBALATON Zoltan int n); 43e72a7f65SBALATON Zoltan 44*c17943b0SPhilippe Mathieu-Daudé /** 45*c17943b0SPhilippe Mathieu-Daudé * qemu_init_irqs: Initialize an array of IRQs. 46*c17943b0SPhilippe Mathieu-Daudé * 47*c17943b0SPhilippe Mathieu-Daudé * @irq: Array of IRQs to initialize 48*c17943b0SPhilippe Mathieu-Daudé * @count: number of IRQs to initialize 49*c17943b0SPhilippe Mathieu-Daudé * @handler: handler to assign to each IRQ 50*c17943b0SPhilippe Mathieu-Daudé * @opaque: opaque data to pass to @handler 51*c17943b0SPhilippe Mathieu-Daudé */ 52*c17943b0SPhilippe Mathieu-Daudé void qemu_init_irqs(IRQState irq[], size_t count, 53*c17943b0SPhilippe Mathieu-Daudé qemu_irq_handler handler, void *opaque); 54*c17943b0SPhilippe Mathieu-Daudé 551e5b31e6SPeter A. G. Crosthwaite /* Returns an array of N IRQs. Each IRQ is assigned the argument handler and 561e5b31e6SPeter A. G. Crosthwaite * opaque data. 571e5b31e6SPeter A. G. Crosthwaite */ 58d537cf6cSpbrook qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n); 591e5b31e6SPeter A. G. Crosthwaite 60a8a9d30bSMarcel Apfelbaum /* 61a8a9d30bSMarcel Apfelbaum * Allocates a single IRQ. The irq is assigned with a handler, an opaque 62a8a9d30bSMarcel Apfelbaum * data and the interrupt number. 63a8a9d30bSMarcel Apfelbaum */ 64a8a9d30bSMarcel Apfelbaum qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque, int n); 65a8a9d30bSMarcel Apfelbaum 661e5b31e6SPeter A. G. Crosthwaite /* Extends an Array of IRQs. Old IRQs have their handlers and opaque data 671e5b31e6SPeter A. G. Crosthwaite * preserved. New IRQs are assigned the argument handler and opaque data. 681e5b31e6SPeter A. G. Crosthwaite */ 691e5b31e6SPeter A. G. Crosthwaite qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler handler, 701e5b31e6SPeter A. G. Crosthwaite void *opaque, int n); 711e5b31e6SPeter A. G. Crosthwaite 72f173d57aSPeter Crosthwaite void qemu_free_irqs(qemu_irq *s, int n); 73a8a9d30bSMarcel Apfelbaum void qemu_free_irq(qemu_irq irq); 74d537cf6cSpbrook 75b50a6563Sbalrog /* Returns a new IRQ with opposite polarity. */ 76b50a6563Sbalrog qemu_irq qemu_irq_invert(qemu_irq irq); 7787ecb68bSpbrook 7820288345SPaolo Bonzini /* For internal use in qtest. Similar to qemu_irq_split, but operating 7920288345SPaolo Bonzini on an existing vector of qemu_irq. */ 8020288345SPaolo Bonzini void qemu_irq_intercept_in(qemu_irq *gpio_in, qemu_irq_handler handler, int n); 8120288345SPaolo Bonzini 82faf7c6deSPeter Maydell /** 83faf7c6deSPeter Maydell * qemu_irq_is_connected: Return true if IRQ line is wired up 84faf7c6deSPeter Maydell * 85faf7c6deSPeter Maydell * If a qemu_irq has a device on the other (receiving) end of it, 86faf7c6deSPeter Maydell * return true; otherwise return false. 87faf7c6deSPeter Maydell * 88faf7c6deSPeter Maydell * Usually device models don't need to care whether the machine model 89faf7c6deSPeter Maydell * has wired up their outbound qemu_irq lines, because functions like 90faf7c6deSPeter Maydell * qemu_set_irq() silently do nothing if there is nothing on the other 91faf7c6deSPeter Maydell * end of the line. However occasionally a device model will want to 92faf7c6deSPeter Maydell * provide default behaviour if its output is left floating, and 93faf7c6deSPeter Maydell * it can use this function to identify when that is the case. 94faf7c6deSPeter Maydell */ 95faf7c6deSPeter Maydell static inline bool qemu_irq_is_connected(qemu_irq irq) 96faf7c6deSPeter Maydell { 97faf7c6deSPeter Maydell return irq != NULL; 98faf7c6deSPeter Maydell } 99faf7c6deSPeter Maydell 10087ecb68bSpbrook #endif 101