Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- struct ddr_io {
- TAILQ_ENTRY(ddr_io) io_entry;
- /* io shizz goes in here, ie dma and buf info */
- };
- struct ddr_slot {
- TAILQ_ENTRY(ddr_slot) slot_entry;
- int slot_idx; /* 0-31 */
- struct ddr_io *slot_io;
- };
- ddr_init()
- {
- struct ddr_slot *s;
- int i;
- mutex_init(&sc->sc_post_mtx);
- mutex_init(&sc->sc_isr_mtx);
- TAILQ_INIT(&sc->sc_deferred);
- mutex_init(&sc->sc_deferred_mtx);
- TAILQ_INIT(&sc->sc_slot_free);
- mutex_init(&sc->sc_slot_mtx);
- sc->sc_slots = malloc(32 * sizeof(struct ddr_slot));
- for (i = 0; i < 32; i++) {
- s = &sc->sc_slots[i];
- s->slot_idx = i;
- TAILQ_INSERT_TAIL(&sc->sc_free_slots, s);
- }
- }
- struct ddr_slot *
- ddr_get_slot(struct ddr_softc *sc)
- {
- struct ddr_slot *s;
- mutex_enter(sc->sc_slot_mtx);
- s = TAILQ_FIRST(&sc->sc_slot_free);
- if (s != NULL)
- TAILQ_REMOVE(&sc->sc_slot_free, s, slot_entry);
- mutex_exit(sc->sc_slot_mtx);
- }
- void
- ddr_post(struct ddr_softc *sc, struct ddr_slot *s)
- {
- mutex_enter(sc->sc_post_mtx);
- ddi_put32(s->slot_io->addr | s->slot_idx);
- ddi_put32(s->slot_io->payload);
- mutex_exit(sc->sc_post_mtx);
- }
- ddr_io()
- {
- struct ddr_slot *s;
- struct ddr_io *io;
- io = kmem_cache_alloc();
- /* fill in io structure */
- /* map io into the io structure */
- s = ddr_get_slot(sc);
- if (s == NULL) {
- mutex_enter(sc->sc_deferred_mtx);
- TAILQ_INSERT_TAIL(&sc->sc_deferred, io);
- mutex_exit(sc->sc_deferred_mtx);
- } else {
- s->slot_io = io;
- ddr_post(sc, s);
- }
- return (IO STARTED);
- }
- int
- ddr_isr(void *xsc)
- {
- struct ddr_softc *sc = xsc;
- struct ddr_slot *s;
- struct ddr_io *io;
- int rv = INTR_DONE_NOITHING;
- u_int32_t done;
- int i;
- TAILQ_HEAD(, ddr_slots) free_slots = TAILQ_INITIALIZER(ddr_slots);
- mutex_enter(&sc->sc_isr_mtx);
- while ((done = ddi_get32(donemask)) != 0) {
- for (i = 0; i < 32 && done; i++) {
- if (done & (1 << i)) {
- s = &sc->sc_slots[i];
- complete(s->slot_io);
- TAILQ_INSERT_TAIL(&free_slots, s);
- }
- }
- rv = INTR_DONE_STUFF;
- }
- mutex_exit(&sc->sc_isr_mtx);
- if (rv != INTR_DONE_NOITHING) {
- mutex_enter(&sc->sc_deferred_mtx);
- while ((s = TAILQ_FIRST(&free_slots) != NULL &&
- (io = TAILQ_FIRST(&sc->sc_deferred) != NULL)) {
- TAILQ_REMOVE(&free_slots, s, slot_entry);
- TAILQ_REMOVE(&sc->sc_deferred, io, io_entry);
- s->slot_io = io;
- ddr_post(io);
- }
- mutex_exit(&sc->sc_deferred_mtx);
- if (!TAILQ_EMPTY(&free_list)) {
- mutex_enter(&sc->sc_slot_mtx);
- while ((s = TAILQ_FIRST(&free_slots)) != NULL) {
- TAILQ_REMOVE(&free_slots, s, slot_entry);
- TAILQ_INSERT_TAIL(&sc->sc_free_slots, s);
- }
- mutex_exit(&sc->sc_slot_mtx);
- }
- }
- return (rv);
- }
Add Comment
Please, Sign In to add comment