Guest User

Untitled

a guest
Jun 22nd, 2018
103
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.61 KB | None | 0 0
  1. struct ddr_io {
  2. TAILQ_ENTRY(ddr_io) io_entry;
  3. /* io shizz goes in here, ie dma and buf info */
  4. };
  5.  
  6. struct ddr_slot {
  7. TAILQ_ENTRY(ddr_slot) slot_entry;
  8. int slot_idx; /* 0-31 */
  9. struct ddr_io *slot_io;
  10. };
  11.  
  12. ddr_init()
  13. {
  14. struct ddr_slot *s;
  15. int i;
  16.  
  17. mutex_init(&sc->sc_post_mtx);
  18. mutex_init(&sc->sc_isr_mtx);
  19.  
  20. TAILQ_INIT(&sc->sc_deferred);
  21. mutex_init(&sc->sc_deferred_mtx);
  22.  
  23. TAILQ_INIT(&sc->sc_slot_free);
  24. mutex_init(&sc->sc_slot_mtx);
  25. sc->sc_slots = malloc(32 * sizeof(struct ddr_slot));
  26.  
  27. for (i = 0; i < 32; i++) {
  28. s = &sc->sc_slots[i];
  29. s->slot_idx = i;
  30. TAILQ_INSERT_TAIL(&sc->sc_free_slots, s);
  31. }
  32. }
  33.  
  34. struct ddr_slot *
  35. ddr_get_slot(struct ddr_softc *sc)
  36. {
  37. struct ddr_slot *s;
  38.  
  39. mutex_enter(sc->sc_slot_mtx);
  40. s = TAILQ_FIRST(&sc->sc_slot_free);
  41. if (s != NULL)
  42. TAILQ_REMOVE(&sc->sc_slot_free, s, slot_entry);
  43. mutex_exit(sc->sc_slot_mtx);
  44. }
  45.  
  46. void
  47. ddr_post(struct ddr_softc *sc, struct ddr_slot *s)
  48. {
  49. mutex_enter(sc->sc_post_mtx);
  50. ddi_put32(s->slot_io->addr | s->slot_idx);
  51. ddi_put32(s->slot_io->payload);
  52. mutex_exit(sc->sc_post_mtx);
  53. }
  54.  
  55. ddr_io()
  56. {
  57. struct ddr_slot *s;
  58. struct ddr_io *io;
  59.  
  60. io = kmem_cache_alloc();
  61.  
  62. /* fill in io structure */
  63. /* map io into the io structure */
  64.  
  65. s = ddr_get_slot(sc);
  66. if (s == NULL) {
  67. mutex_enter(sc->sc_deferred_mtx);
  68. TAILQ_INSERT_TAIL(&sc->sc_deferred, io);
  69. mutex_exit(sc->sc_deferred_mtx);
  70. } else {
  71. s->slot_io = io;
  72. ddr_post(sc, s);
  73. }
  74.  
  75. return (IO STARTED);
  76. }
  77.  
  78. int
  79. ddr_isr(void *xsc)
  80. {
  81. struct ddr_softc *sc = xsc;
  82. struct ddr_slot *s;
  83. struct ddr_io *io;
  84. int rv = INTR_DONE_NOITHING;
  85. u_int32_t done;
  86. int i;
  87. TAILQ_HEAD(, ddr_slots) free_slots = TAILQ_INITIALIZER(ddr_slots);
  88.  
  89. mutex_enter(&sc->sc_isr_mtx);
  90. while ((done = ddi_get32(donemask)) != 0) {
  91. for (i = 0; i < 32 && done; i++) {
  92. if (done & (1 << i)) {
  93. s = &sc->sc_slots[i];
  94. complete(s->slot_io);
  95. TAILQ_INSERT_TAIL(&free_slots, s);
  96. }
  97. }
  98. rv = INTR_DONE_STUFF;
  99. }
  100. mutex_exit(&sc->sc_isr_mtx);
  101.  
  102. if (rv != INTR_DONE_NOITHING) {
  103. mutex_enter(&sc->sc_deferred_mtx);
  104. while ((s = TAILQ_FIRST(&free_slots) != NULL &&
  105. (io = TAILQ_FIRST(&sc->sc_deferred) != NULL)) {
  106. TAILQ_REMOVE(&free_slots, s, slot_entry);
  107. TAILQ_REMOVE(&sc->sc_deferred, io, io_entry);
  108.  
  109. s->slot_io = io;
  110. ddr_post(io);
  111. }
  112. mutex_exit(&sc->sc_deferred_mtx);
  113.  
  114. if (!TAILQ_EMPTY(&free_list)) {
  115. mutex_enter(&sc->sc_slot_mtx);
  116. while ((s = TAILQ_FIRST(&free_slots)) != NULL) {
  117. TAILQ_REMOVE(&free_slots, s, slot_entry);
  118. TAILQ_INSERT_TAIL(&sc->sc_free_slots, s);
  119. }
  120. mutex_exit(&sc->sc_slot_mtx);
  121. }
  122. }
  123.  
  124. return (rv);
  125. }
Add Comment
Please, Sign In to add comment