1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
|
/*
* CDDL HEADER START
*
* The contents of this file are subject to the terms of the
* Common Development and Distribution License (the "License").
* You may not use this file except in compliance with the License.
*
* You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
* or http://www.opensolaris.org/os/licensing.
* See the License for the specific language governing permissions
* and limitations under the License.
*
* When distributing Covered Code, include this CDDL HEADER in each
* file and include the License file at usr/src/OPENSOLARIS.LICENSE.
* If applicable, add the following below this CDDL HEADER, with the
* fields enclosed by brackets "[]" replaced with your own identifying
* information: Portions Copyright [yyyy] [name of copyright owner]
*
* CDDL HEADER END
*/
/*
* Copyright 2005 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
* Copyright (c) 2016 by Delphix. All rights reserved.
*/
#pragma ident "%Z%%M% %I% %E% SMI"
#include <sys/types.h>
#include <sys/kmem.h>
#include <sys/systm.h>
#include <sys/ddi.h>
#include <sys/sunddi.h>
#include <sys/sunndi.h>
#include <sys/ddidmareq.h>
#include <sys/ddi_impldefs.h>
#include <sys/ndi_impldefs.h>
#include <sys/fcode.h>
/*
* We want to call the attachment point's dma ctl op, not its parent's
* dma ctl op, so we have to code this ourselves.
*/
int
fc_ddi_dma_alloc_handle(dev_info_t *dip, ddi_dma_attr_t *attr,
int (*waitfp)(caddr_t), caddr_t arg, ddi_dma_handle_t *handlep)
{
int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_attr_t *,
int (*)(caddr_t), caddr_t, ddi_dma_handle_t *);
funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_allochdl;
return ((*funcp)(dip, dip, attr, waitfp, arg, handlep));
}
int
fc_ddi_dma_buf_bind_handle(ddi_dma_handle_t handle, struct buf *bp,
uint_t flags, int (*waitfp)(caddr_t), caddr_t arg,
ddi_dma_cookie_t *cookiep, uint_t *ccountp)
{
struct ddi_dma_req dmareq;
ddi_dma_impl_t *hp;
dev_info_t *dip;
int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_handle_t,
struct ddi_dma_req *, ddi_dma_cookie_t *, uint_t *);
hp = (ddi_dma_impl_t *)handle;
dip = hp->dmai_rdip;
dmareq.dmar_flags = flags;
dmareq.dmar_fp = waitfp;
dmareq.dmar_arg = arg;
dmareq.dmar_object.dmao_size = (uint_t)bp->b_bcount;
if ((bp->b_flags & (B_PAGEIO|B_REMAPPED)) == B_PAGEIO) {
dmareq.dmar_object.dmao_type = DMA_OTYP_PAGES;
dmareq.dmar_object.dmao_obj.pp_obj.pp_pp = bp->b_pages;
dmareq.dmar_object.dmao_obj.pp_obj.pp_offset =
(uint_t)(((uintptr_t)bp->b_un.b_addr) & MMU_PAGEOFFSET);
} else {
dmareq.dmar_object.dmao_obj.virt_obj.v_addr = bp->b_un.b_addr;
if ((bp->b_flags & (B_SHADOW|B_REMAPPED)) == B_SHADOW) {
dmareq.dmar_object.dmao_obj.virt_obj.v_priv =
bp->b_shadow;
dmareq.dmar_object.dmao_type = DMA_OTYP_BUFVADDR;
} else {
dmareq.dmar_object.dmao_type =
(bp->b_flags & (B_PHYS | B_REMAPPED))?
DMA_OTYP_BUFVADDR : DMA_OTYP_VADDR;
dmareq.dmar_object.dmao_obj.virt_obj.v_priv = NULL;
}
/*
* If the buffer has no proc pointer, or the proc
* struct has the kernel address space, or the buffer has
* been marked B_REMAPPED (meaning that it is now
* mapped into the kernel's address space), then
* the address space is kas (kernel address space).
*/
if (bp->b_proc == NULL || bp->b_proc->p_as == &kas ||
(bp->b_flags & B_REMAPPED) != 0) {
dmareq.dmar_object.dmao_obj.virt_obj.v_as = 0;
} else {
dmareq.dmar_object.dmao_obj.virt_obj.v_as =
bp->b_proc->p_as;
}
}
funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_bindhdl;
return ((*funcp)(dip, dip, handle, &dmareq, cookiep, ccountp));
}
int
fc_ddi_dma_unbind_handle(ddi_dma_handle_t handle)
{
int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_handle_t);
ddi_dma_impl_t *hp;
dev_info_t *dip;
hp = (ddi_dma_impl_t *)handle;
dip = hp->dmai_rdip;
funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_unbindhdl;
return ((*funcp)(dip, dip, handle));
}
void
fc_ddi_dma_free_handle(ddi_dma_handle_t *handlep)
{
int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_handle_t);
ddi_dma_impl_t *hp;
dev_info_t *dip;
hp = (ddi_dma_impl_t *)*handlep;
dip = hp->dmai_rdip;
funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_freehdl;
(void) (*funcp)(dip, dip, *handlep);
}
int
fc_ddi_dma_sync(ddi_dma_handle_t h, off_t o, size_t l, uint_t whom)
{
ddi_dma_impl_t *hp = (ddi_dma_impl_t *)h;
dev_info_t *dip;
int (*funcp)(dev_info_t *, dev_info_t *, ddi_dma_handle_t, off_t,
size_t, uint_t);
/*
* the DMA nexus driver will set DMP_NOSYNC if the
* platform does not require any sync operation. For
* example if the memory is uncached or consistent
* and without any I/O write buffers involved.
*/
if ((hp->dmai_rflags & DMP_NOSYNC) == DMP_NOSYNC)
return (DDI_SUCCESS);
dip = hp->dmai_rdip;
funcp = DEVI(dip)->devi_ops->devo_bus_ops->bus_dma_flush;
return ((*funcp)(dip, dip, h, o, l, whom));
}
/*
* Create untyped properties, just like 1275 properties.
* XXX: Assumes property encoding is the natural byte order.
*/
int
fc_ndi_prop_update(dev_t match_dev, dev_info_t *dip,
char *name, uchar_t *data, uint_t nelements)
{
return (ddi_prop_update_common(match_dev, dip,
DDI_PROP_HW_DEF | DDI_PROP_TYPE_ANY,
name, data, nelements, ddi_prop_fm_encode_bytes));
}
|