intr.h 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980
  1. /*
  2. * Copyright (c) 2017 Richard Braun.
  3. *
  4. * This program is free software: you can redistribute it and/or modify
  5. * it under the terms of the GNU General Public License as published by
  6. * the Free Software Foundation, either version 3 of the License, or
  7. * (at your option) any later version.
  8. *
  9. * This program is distributed in the hope that it will be useful,
  10. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. * GNU General Public License for more details.
  13. *
  14. * You should have received a copy of the GNU General Public License
  15. * along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. *
  17. *
  18. * Machine-independent interrupt management.
  19. */
  20. #ifndef KERN_INTR_H
  21. #define KERN_INTR_H
  22. #include <kern/init.h>
  23. /*
  24. * Type for interrupt handler functions.
  25. *
  26. * Return codes :
  27. * - 0 Interrupt successfully handled
  28. * - EAGAIN Spurious interrupt
  29. */
  30. typedef int (*intr_handler_fn_t) (void *);
  31. /*
  32. * Operations of an interrupt controller.
  33. *
  34. * Operations for interrupts targeting the same processor are serialized.
  35. */
  36. struct intr_ops
  37. {
  38. void (*enable) (void *, uint32_t, uint32_t);
  39. void (*disable) (void *, uint32_t);
  40. void (*eoi) (void *, uint32_t);
  41. };
  42. /*
  43. * Register an interrupt controller.
  44. *
  45. * This function isn't thread-safe and can only be called during system
  46. * initialization.
  47. */
  48. void intr_register_ctl (const struct intr_ops *ops, void *priv,
  49. uint32_t first_intr, uint32_t last_intr);
  50. // Register/unregister an interrupt handler.
  51. int intr_register (uint32_t intr, intr_handler_fn_t fn, void *arg);
  52. void intr_unregister (uint32_t intr, intr_handler_fn_t fn);
  53. // Handle an interrupt.
  54. void intr_handle (uint32_t intr);
  55. // Set an interrupt as handled.
  56. void intr_eoi (uint32_t intr);
  57. /*
  58. * This init operation provides :
  59. * - registration of interrupt controllers and handlers
  60. */
  61. INIT_OP_DECLARE (intr_bootstrap);
  62. /*
  63. * This init operation provides :
  64. * - all interrupt controllers have been registered
  65. * - module fully initialized
  66. */
  67. INIT_OP_DECLARE (intr_setup);
  68. #endif