int read_ppm_row(int fd, int const row, int const cols, int const rows, int const maxval, int const format) { #if !(defined(LCD_STRIDEFORMAT) && LCD_STRIDEFORMAT == VERTICAL_STRIDE) (void) rows; #endif int col; int r, g, b; switch (format) { case PPM_FORMAT: for (col = 0; col < cols; ++col) { r = ppm_getuint(fd); g = ppm_getuint(fd); b = ppm_getuint(fd); if (r == PLUGIN_ERROR || g == PLUGIN_ERROR || b == PLUGIN_ERROR) { return PLUGIN_ERROR; } *BUFADDR(col, row, cols, rows) = LCD_RGBPACK( (255 / maxval) * r, (255 / maxval) * g, (255 / maxval) * b); } break; case RPPM_FORMAT: for (col = 0; col < cols; ++col) { r = ppm_getrawsample(fd, maxval); g = ppm_getrawsample(fd, maxval); b = ppm_getrawsample(fd, maxval); if (r == PLUGIN_ERROR || g == PLUGIN_ERROR || b == PLUGIN_ERROR) { return PLUGIN_ERROR; } *BUFADDR(col, row, cols, rows) = LCD_RGBPACK( (255 / maxval) * r, (255 / maxval) * g, (255 / maxval) * b); } break; default: ppm_error("What?!"); return PLUGIN_ERROR; } return 1; }
void efe_init_tx_ring(efe_t *efep) { efe_ring_t *rp; ASSERT(mutex_owned(&efep->efe_txlock)); rp = efep->efe_tx_ring; for (int i = 0; i < DESCLEN(rp); ++i) { efe_desc_t *dp = GETDESC(rp, i); efe_buf_t *bp = GETBUF(rp, i); PUTDESC16(rp, &dp->d_status, 0); PUTDESC16(rp, &dp->d_len, 0); PUTDESC32(rp, &dp->d_bufaddr, BUFADDR(bp)); PUTDESC16(rp, &dp->d_buflen, BUFLEN(bp)); PUTDESC16(rp, &dp->d_control, 0); PUTDESC32(rp, &dp->d_next, NEXTDESCADDR(rp, i)); SYNCDESC(rp, i, DDI_DMA_SYNC_FORDEV); } efep->efe_tx_desc = 0; efep->efe_tx_sent = 0; PUTCSR(efep, CSR_PTCDAR, DESCADDR(rp, 0)); }
void cs428x_free(void *addr, void *ptr, int pool) { struct cs428x_softc *sc; struct cs428x_dma **pp, *p; sc = addr; for (pp = &sc->sc_dmas; (p = *pp) != NULL; pp = &p->next) { if (BUFADDR(p) == ptr) { bus_dmamap_unload(sc->sc_dmatag, p->map); bus_dmamap_destroy(sc->sc_dmatag, p->map); bus_dmamem_unmap(sc->sc_dmatag, p->addr, p->size); bus_dmamem_free(sc->sc_dmatag, p->segs, p->nsegs); free(p->dum, pool); *pp = p->next; free(p, pool); return; } } }
paddr_t cs428x_mappage(void *addr, void *mem, off_t off, int prot) { struct cs428x_softc *sc; struct cs428x_dma *p; sc = addr; if (off < 0) return -1; for (p = sc->sc_dmas; p && BUFADDR(p) != mem; p = p->next) ; if (p == NULL) { DPRINTF(("cs428x_mappage: bad buffer address\n")); return -1; } return (bus_dmamem_mmap(sc->sc_dmatag, p->segs, p->nsegs, off, prot, BUS_DMA_WAITOK)); }
void * cs428x_malloc(void *addr, int direction, size_t size, int pool, int flags) { struct cs428x_softc *sc; struct cs428x_dma *p; int error; sc = addr; p = malloc(sizeof(*p), pool, flags); if (p == NULL) return 0; error = cs428x_allocmem(sc, size, pool, flags, p); if (error) { free(p, pool); return 0; } p->next = sc->sc_dmas; sc->sc_dmas = p; return BUFADDR(p); }