Home | History | Annotate | Line # | Download | only in fdt
fdt_dma.h revision 1.1
      1 /*	$NetBSD: fdt_dma.h,v 1.1 2025/09/06 20:11:30 thorpej Exp $	*/
      2 
      3 /*-
      4  * Copyright (c) 2015 Jared D. McNeill <jmcneill (at) invisible.ca>
      5  * All rights reserved.
      6  *
      7  * Redistribution and use in source and binary forms, with or without
      8  * modification, are permitted provided that the following conditions
      9  * are met:
     10  * 1. Redistributions of source code must retain the above copyright
     11  *    notice, this list of conditions and the following disclaimer.
     12  * 2. Redistributions in binary form must reproduce the above copyright
     13  *    notice, this list of conditions and the following disclaimer in the
     14  *    documentation and/or other materials provided with the distribution.
     15  *
     16  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
     17  * IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
     18  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
     19  * IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
     20  * INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING,
     21  * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
     22  * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
     23  * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
     24  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
     25  * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
     26  * SUCH DAMAGE.
     27  */
     28 
     29 #ifndef _DEV_FDT_FDT_DMA_H_
     30 #define	_DEV_FDT_FDT_DMA_H_
     31 
     32 #include <sys/bus.h>
     33 #include <sys/device.h>
     34 
     35 struct fdtbus_dma_controller;
     36 
     37 struct fdtbus_dma {
     38 	struct fdtbus_dma_controller *dma_dc;
     39 	void *dma_priv;
     40 };
     41 
     42 enum fdtbus_dma_dir {
     43 	FDT_DMA_READ,		/* device -> memory */
     44 	FDT_DMA_WRITE		/* memory -> device */
     45 };
     46 
     47 struct fdtbus_dma_opt {
     48 	int opt_bus_width;	/* Bus width */
     49 	int opt_burst_len;	/* Burst length */
     50 	int opt_swap;		/* Enable data swapping */
     51 	int opt_dblbuf;		/* Enable double buffering */
     52 	int opt_wrap_len;	/* Address wrap-around window */
     53 };
     54 
     55 struct fdtbus_dma_req {
     56 	bus_dma_segment_t *dreq_segs;	/* Memory */
     57 	int dreq_nsegs;
     58 
     59 	bus_addr_t dreq_dev_phys;	/* Device */
     60 	int dreq_sel;			/* Device selector */
     61 
     62 	enum fdtbus_dma_dir dreq_dir;	/* Transfer direction */
     63 
     64 	int dreq_block_irq;		/* Enable IRQ at end of block */
     65 	int dreq_block_multi;		/* Enable multiple block transfers */
     66 	int dreq_flow;			/* Enable flow control */
     67 
     68 	struct fdtbus_dma_opt dreq_mem_opt;	/* Memory options */
     69 	struct fdtbus_dma_opt dreq_dev_opt;	/* Device options */
     70 };
     71 
     72 struct fdtbus_dma_controller_func {
     73 	void *	(*acquire)(device_t, const void *, size_t,
     74 			   void (*)(void *), void *);
     75 	void	(*release)(device_t, void *);
     76 	int	(*transfer)(device_t, void *, struct fdtbus_dma_req *);
     77 	void	(*halt)(device_t, void *);
     78 };
     79 
     80 int		fdtbus_register_dma_controller(device_t, int,
     81 		    const struct fdtbus_dma_controller_func *);
     82 
     83 struct fdtbus_dma *
     84 		fdtbus_dma_get(int, const char *, void (*)(void *), void *);
     85 struct fdtbus_dma *
     86 		fdtbus_dma_get_index(int, u_int, void (*)(void *), void *);
     87 void		fdtbus_dma_put(struct fdtbus_dma *);
     88 int		fdtbus_dma_transfer(struct fdtbus_dma *,
     89 		    struct fdtbus_dma_req *);
     90 void		fdtbus_dma_halt(struct fdtbus_dma *);
     91 
     92 #endif /* _DEV_FDT_FDT_DMA_H_ */
     93