pallet_size = (1<<depth) * sizeof (uint16_t);
palette_size = (1<<depth) * sizeof (uint16_t);
pxa2x0_lcd_new_screen(struct pxa2x0_lcd_softc *sc,    int depth){	struct pxa2x0_lcd_screen *scr = NULL;	int width, height;	bus_size_t size;        int error, pallet_size;	int busdma_flag = (cold ? BUS_DMA_NOWAIT : BUS_DMA_WAITOK);	struct lcd_dma_descriptor *desc;	paddr_t buf_pa, desc_pa;	width = sc->geometry->panel_width;	height = sc->geometry->panel_height;	pallet_size = 0;	switch (depth) {	case 1:	case 2:	case 4:	case 8:		pallet_size = (1<<depth) * sizeof (uint16_t);		/* FALLTHROUGH */	case 16:		size = roundup(width,4)*depth/8 * height;		break;	default:		printf("%s: Unknown depth (%d)\n", sc->dev.dv_xname, depth);		return NULL;	}	scr = malloc(sizeof *scr, M_DEVBUF, 	    (cold ? M_NOWAIT : M_WAITOK));	if (scr == NULL)		return NULL;	bzero (scr, sizeof *scr);	scr->nsegs = 0;	scr->depth = depth;	scr->buf_size = size;	scr->buf_va = NULL;	size = roundup(size,16) + 3 * sizeof (struct lcd_dma_descriptor)	    + pallet_size;        error = bus_dmamem_alloc(sc->dma_tag, size, 16, 0,	    scr->segs, 1, &(scr->nsegs), busdma_flag);        if (error || scr->nsegs != 1) {		/* XXX: Actually we can handle nsegs>1 case by means                   of multiple DMA descriptors for a panel.  it will                   makes code here a bit hairly */		goto bad;        }	error = bus_dmamem_map(sc->dma_tag, scr->segs, scr->nsegs,	    size, (caddr_t *)&(scr->buf_va), busdma_flag | BUS_DMA_COHERENT);	if (error)		goto bad;	memset (scr->buf_va, 0, scr->buf_size);	/* map memory for DMA */	if (bus_dmamap_create(sc->dma_tag, 1024*1024*2, 1, 	    1024*1024*2, 0,  busdma_flag, &scr->dma))		goto bad;	error = bus_dmamap_load(sc->dma_tag, scr->dma,	    scr->buf_va, size, NULL, busdma_flag);	if (error) {		goto bad;	}	buf_pa = scr->segs[0].ds_addr;	desc_pa = buf_pa + roundup(size, PAGE_SIZE) - 3*sizeof *desc;	/* make descriptors at the top of mapped memory */	desc = (struct lcd_dma_descriptor *)(		(caddr_t)(scr->buf_va) + roundup(size, PAGE_SIZE) -			  3*sizeof *desc);	desc[0].fdadr = desc_pa;	desc[0].fsadr = buf_pa;	desc[0].ldcmd = scr->buf_size;	if (pallet_size) {		init_pallet((uint16_t *)((char *)desc - pallet_size), depth);		desc[2].fdadr = desc_pa; /* chain to panel 0 */		desc[2].fsadr = desc_pa - pallet_size;		desc[2].ldcmd = pallet_size | LDCMD_PAL;	}	if (sc->geometry->panel_info & LCDPANEL_DUAL) {		/* Dual panel */		desc[1].fdadr = desc_pa + sizeof *desc;		desc[1].fsadr = buf_pa + scr->buf_size/2;		desc[0].ldcmd = desc[1].ldcmd = scr->buf_size/2;	}#if 0	desc[0].ldcmd |= LDCMD_SOFINT;	desc[1].ldcmd |= LDCMD_SOFINT;#endif	scr->dma_desc = desc;	scr->dma_desc_pa = desc_pa;	scr->map_size = size;		/* used when unmap this. */	LIST_INSERT_HEAD(&(sc->screens), scr, link);	sc->n_screens++;	return scr; bad:	if (scr) {		if (scr->buf_va)			bus_dmamem_unmap(sc->dma_tag, scr->buf_va, size);		if (scr->nsegs)			bus_dmamem_free(sc->dma_tag, scr->segs, scr->nsegs);		free(scr, M_DEVBUF);	}	return NULL;}