Home | History | Annotate | Line # | Download | only in fdt
      1 /*	$NetBSD: fdt_dma.h,v 1.2 2026/01/25 20:09:45 yurix 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 	FDT_DMA_NO_XFER		/* dma operation without data transfer */
     46 };
     47 
     48 struct fdtbus_dma_opt {
     49 	int opt_bus_width;	/* Bus width */
     50 	int opt_burst_len;	/* Burst length */
     51 	int opt_swap;		/* Enable data swapping */
     52 	int opt_dblbuf;		/* Enable double buffering */
     53 	int opt_wrap_len;	/* Address wrap-around window */
     54 };
     55 
     56 struct fdtbus_dma_req {
     57 	bus_dma_segment_t *dreq_segs;	/* Memory */
     58 	int dreq_nsegs;
     59 
     60 	void *dreq_data;		/* Controller-specific ancillary data */
     61 	int dreq_datalen;		/* Size of dreq_data */
     62 
     63 	bus_addr_t dreq_dev_phys;	/* Device */
     64 	int dreq_sel;			/* Device selector */
     65 
     66 	enum fdtbus_dma_dir dreq_dir;	/* Transfer direction */
     67 
     68 	int dreq_block_irq;		/* Enable IRQ at end of block */
     69 	int dreq_block_multi;		/* Enable multiple block transfers */
     70 	int dreq_flow;			/* Enable flow control */
     71 
     72 	struct fdtbus_dma_opt dreq_mem_opt;	/* Memory options */
     73 	struct fdtbus_dma_opt dreq_dev_opt;	/* Device options */
     74 };
     75 
     76 struct fdtbus_dma_controller_func {
     77 	void *	(*acquire)(device_t, const void *, size_t,
     78 			   void (*)(void *), void *);
     79 	void	(*release)(device_t, void *);
     80 	int	(*transfer)(device_t, void *, struct fdtbus_dma_req *);
     81 	void	(*halt)(device_t, void *);
     82 };
     83 
     84 int		fdtbus_register_dma_controller(device_t, int,
     85 		    const struct fdtbus_dma_controller_func *);
     86 
     87 struct fdtbus_dma *
     88 		fdtbus_dma_get(int, const char *, void (*)(void *), void *);
     89 struct fdtbus_dma *
     90 		fdtbus_dma_get_index(int, u_int, void (*)(void *), void *);
     91 void		fdtbus_dma_put(struct fdtbus_dma *);
     92 int		fdtbus_dma_transfer(struct fdtbus_dma *,
     93 		    struct fdtbus_dma_req *);
     94 void		fdtbus_dma_halt(struct fdtbus_dma *);
     95 
     96 #endif /* _DEV_FDT_FDT_DMA_H_ */
     97