187ecb68bSpbrook #ifndef QEMU_IRQ_H 287ecb68bSpbrook #define QEMU_IRQ_H 387ecb68bSpbrook 4*e72a7f65SBALATON Zoltan #include "qom/object.h" 5*e72a7f65SBALATON Zoltan 6d537cf6cSpbrook /* Generic IRQ/GPIO pin infrastructure. */ 7d537cf6cSpbrook 8615c4895SAndreas Färber #define TYPE_IRQ "irq" 9*e72a7f65SBALATON Zoltan OBJECT_DECLARE_SIMPLE_TYPE(IRQState, IRQ) 10*e72a7f65SBALATON Zoltan 11*e72a7f65SBALATON Zoltan struct IRQState { 12*e72a7f65SBALATON Zoltan Object parent_obj; 13*e72a7f65SBALATON Zoltan 14*e72a7f65SBALATON Zoltan qemu_irq_handler handler; 15*e72a7f65SBALATON Zoltan void *opaque; 16*e72a7f65SBALATON Zoltan int n; 17*e72a7f65SBALATON 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 37*e72a7f65SBALATON Zoltan /* 38*e72a7f65SBALATON Zoltan * Init a single IRQ. The irq is assigned with a handler, an opaque data 39*e72a7f65SBALATON Zoltan * and the interrupt number. 40*e72a7f65SBALATON Zoltan */ 41*e72a7f65SBALATON Zoltan void qemu_init_irq(IRQState *irq, qemu_irq_handler handler, void *opaque, 42*e72a7f65SBALATON Zoltan int n); 43*e72a7f65SBALATON Zoltan 441e5b31e6SPeter A. G. Crosthwaite /* Returns an array of N IRQs. Each IRQ is assigned the argument handler and 451e5b31e6SPeter A. G. Crosthwaite * opaque data. 461e5b31e6SPeter A. G. Crosthwaite */ 47d537cf6cSpbrook qemu_irq *qemu_allocate_irqs(qemu_irq_handler handler, void *opaque, int n); 481e5b31e6SPeter A. G. Crosthwaite 49a8a9d30bSMarcel Apfelbaum /* 50a8a9d30bSMarcel Apfelbaum * Allocates a single IRQ. The irq is assigned with a handler, an opaque 51a8a9d30bSMarcel Apfelbaum * data and the interrupt number. 52a8a9d30bSMarcel Apfelbaum */ 53a8a9d30bSMarcel Apfelbaum qemu_irq qemu_allocate_irq(qemu_irq_handler handler, void *opaque, int n); 54a8a9d30bSMarcel Apfelbaum 551e5b31e6SPeter A. G. Crosthwaite /* Extends an Array of IRQs. Old IRQs have their handlers and opaque data 561e5b31e6SPeter A. G. Crosthwaite * preserved. New IRQs are assigned the argument handler and opaque data. 571e5b31e6SPeter A. G. Crosthwaite */ 581e5b31e6SPeter A. G. Crosthwaite qemu_irq *qemu_extend_irqs(qemu_irq *old, int n_old, qemu_irq_handler handler, 591e5b31e6SPeter A. G. Crosthwaite void *opaque, int n); 601e5b31e6SPeter A. G. Crosthwaite 61f173d57aSPeter Crosthwaite void qemu_free_irqs(qemu_irq *s, int n); 62a8a9d30bSMarcel Apfelbaum void qemu_free_irq(qemu_irq irq); 63d537cf6cSpbrook 64b50a6563Sbalrog /* Returns a new IRQ with opposite polarity. */ 65b50a6563Sbalrog qemu_irq qemu_irq_invert(qemu_irq irq); 6687ecb68bSpbrook 6720288345SPaolo Bonzini /* For internal use in qtest. Similar to qemu_irq_split, but operating 6820288345SPaolo Bonzini on an existing vector of qemu_irq. */ 6920288345SPaolo Bonzini void qemu_irq_intercept_in(qemu_irq *gpio_in, qemu_irq_handler handler, int n); 7020288345SPaolo Bonzini 71faf7c6deSPeter Maydell /** 72faf7c6deSPeter Maydell * qemu_irq_is_connected: Return true if IRQ line is wired up 73faf7c6deSPeter Maydell * 74faf7c6deSPeter Maydell * If a qemu_irq has a device on the other (receiving) end of it, 75faf7c6deSPeter Maydell * return true; otherwise return false. 76faf7c6deSPeter Maydell * 77faf7c6deSPeter Maydell * Usually device models don't need to care whether the machine model 78faf7c6deSPeter Maydell * has wired up their outbound qemu_irq lines, because functions like 79faf7c6deSPeter Maydell * qemu_set_irq() silently do nothing if there is nothing on the other 80faf7c6deSPeter Maydell * end of the line. However occasionally a device model will want to 81faf7c6deSPeter Maydell * provide default behaviour if its output is left floating, and 82faf7c6deSPeter Maydell * it can use this function to identify when that is the case. 83faf7c6deSPeter Maydell */ 84faf7c6deSPeter Maydell static inline bool qemu_irq_is_connected(qemu_irq irq) 85faf7c6deSPeter Maydell { 86faf7c6deSPeter Maydell return irq != NULL; 87faf7c6deSPeter Maydell } 88faf7c6deSPeter Maydell 8987ecb68bSpbrook #endif 90