pic_cpu.c 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. /*
  2. * OpenRISC Programmable Interrupt Controller support.
  3. *
  4. * Copyright (c) 2011-2012 Jia Liu <proljc@gmail.com>
  5. * Feng Gao <gf91597@gmail.com>
  6. *
  7. * This library is free software; you can redistribute it and/or
  8. * modify it under the terms of the GNU Lesser General Public
  9. * License as published by the Free Software Foundation; either
  10. * version 2.1 of the License, or (at your option) any later version.
  11. *
  12. * This library is distributed in the hope that it will be useful,
  13. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  14. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  15. * Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public
  18. * License along with this library; if not, see <http://www.gnu.org/licenses/>.
  19. */
  20. #include "qemu/osdep.h"
  21. #include "hw/irq.h"
  22. #include "cpu.h"
  23. /* OpenRISC pic handler */
  24. static void openrisc_pic_cpu_handler(void *opaque, int irq, int level)
  25. {
  26. OpenRISCCPU *cpu = (OpenRISCCPU *)opaque;
  27. CPUState *cs = CPU(cpu);
  28. uint32_t irq_bit;
  29. if (irq > 31 || irq < 0) {
  30. return;
  31. }
  32. irq_bit = 1U << irq;
  33. if (level) {
  34. cpu->env.picsr |= irq_bit;
  35. } else {
  36. cpu->env.picsr &= ~irq_bit;
  37. }
  38. if (cpu->env.picsr & cpu->env.picmr) {
  39. cpu_interrupt(cs, CPU_INTERRUPT_HARD);
  40. } else {
  41. cpu_reset_interrupt(cs, CPU_INTERRUPT_HARD);
  42. cpu->env.picsr = 0;
  43. }
  44. }
  45. void cpu_openrisc_pic_init(OpenRISCCPU *cpu)
  46. {
  47. int i;
  48. qemu_irq *qi;
  49. qi = qemu_allocate_irqs(openrisc_pic_cpu_handler, cpu, NR_IRQS);
  50. for (i = 0; i < NR_IRQS; i++) {
  51. cpu->env.irq[i] = qi[i];
  52. }
  53. }