xref: /titanic_41/usr/src/uts/sun4/io/efcode/fc_ddi.c (revision 70025d765b044c6d8594bb965a2247a61e991a99)
1 /*
2  * CDDL HEADER START
3  *
4  * The contents of this file are subject to the terms of the
5  * Common Development and Distribution License, Version 1.0 only
6  * (the "License").  You may not use this file except in compliance
7  * with the License.
8  *
9  * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10  * or http://www.opensolaris.org/os/licensing.
11  * See the License for the specific language governing permissions
12  * and limitations under the License.
13  *
14  * When distributing Covered Code, include this CDDL HEADER in each
15  * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16  * If applicable, add the following below this CDDL HEADER, with the
17  * fields enclosed by brackets "[]" replaced with your own identifying
18  * information: Portions Copyright [yyyy] [name of copyright owner]
19  *
20  * CDDL HEADER END
21  */
22 /*
23  * Copyright 1999, 2002 Sun Microsystems, Inc.  All rights reserved.
24  * Use is subject to license terms.
25  */
26 
27 #pragma ident	"%Z%%M%	%I%	%E% SMI"
28 
29 #include <sys/types.h>
30 #include <sys/kmem.h>
31 #include <sys/systm.h>
32 #include <sys/ddi.h>
33 #include <sys/sunddi.h>
34 #include <sys/sunndi.h>
35 #include <sys/ddidmareq.h>
36 #include <sys/ddi_impldefs.h>
37 #include <sys/ndi_impldefs.h>
38 #include <sys/fcode.h>
39 
40 /*
41  * We want to call the attachment point's dma ctl op, not his parent's
42  * dma ctl op, so we have to code this ourselves. (the dma setup functions
43  * already implement this functionality for us.)
44  */
45 int
46 fc_ddi_dma_htoc(dev_info_t *ap, ddi_dma_handle_t h, off_t o,
47 	ddi_dma_cookie_t *c)
48 {
49 	int (*fp)();
50 
51 	fp = DEVI(ap)->devi_ops->devo_bus_ops->bus_dma_ctl;
52 	return ((*fp) (ap, ap, h, DDI_DMA_HTOC, &o, 0, (caddr_t *)c, 0));
53 }
54 
55 int
56 fc_ddi_dma_free(dev_info_t *ap, ddi_dma_handle_t h)
57 {
58 	int (*fp)();
59 
60 	fp = DEVI(ap)->devi_ops->devo_bus_ops->bus_dma_ctl;
61 	return ((*fp) (ap, ap, h, DDI_DMA_FREE, 0, 0, 0, 0));
62 }
63 
64 int
65 fc_ddi_dma_sync(ddi_dma_handle_t h, off_t o, size_t l, uint_t whom)
66 {
67 	ddi_dma_impl_t *hp = (ddi_dma_impl_t *)h;
68 	dev_info_t *dip;
69 	int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_handle_t, off_t,
70 		size_t, uint_t);
71 
72 	/*
73 	 * the DMA nexus driver will set DMP_NOSYNC if the
74 	 * platform does not require any sync operation. For
75 	 * example if the memory is uncached or consistent
76 	 * and without any I/O write buffers involved.
77 	 */
78 	if ((hp->dmai_rflags & DMP_NOSYNC) == DMP_NOSYNC)
79 		return (DDI_SUCCESS);
80 
81 	dip = hp->dmai_rdip;
82 	funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_flush;
83 	return ((*funcp)(dip, dip, h, o, l, whom));
84 }
85 
86 /*
87  * Create untyped properties, just like 1275 properties.
88  * XXX: Assumes property encoding is the natural byte order.
89  */
90 int
91 fc_ndi_prop_update(dev_t match_dev, dev_info_t *dip,
92     char *name, uchar_t *data, uint_t nelements)
93 {
94 	return (ddi_prop_update_common(match_dev, dip,
95 	    DDI_PROP_HW_DEF | DDI_PROP_TYPE_ANY,
96 	    name, data, nelements, ddi_prop_fm_encode_bytes));
97 }
98