1*0Sstevel@tonic-gate /*
2*0Sstevel@tonic-gate * CDDL HEADER START
3*0Sstevel@tonic-gate *
4*0Sstevel@tonic-gate * The contents of this file are subject to the terms of the
5*0Sstevel@tonic-gate * Common Development and Distribution License, Version 1.0 only
6*0Sstevel@tonic-gate * (the "License"). You may not use this file except in compliance
7*0Sstevel@tonic-gate * with the License.
8*0Sstevel@tonic-gate *
9*0Sstevel@tonic-gate * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10*0Sstevel@tonic-gate * or http://www.opensolaris.org/os/licensing.
11*0Sstevel@tonic-gate * See the License for the specific language governing permissions
12*0Sstevel@tonic-gate * and limitations under the License.
13*0Sstevel@tonic-gate *
14*0Sstevel@tonic-gate * When distributing Covered Code, include this CDDL HEADER in each
15*0Sstevel@tonic-gate * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16*0Sstevel@tonic-gate * If applicable, add the following below this CDDL HEADER, with the
17*0Sstevel@tonic-gate * fields enclosed by brackets "[]" replaced with your own identifying
18*0Sstevel@tonic-gate * information: Portions Copyright [yyyy] [name of copyright owner]
19*0Sstevel@tonic-gate *
20*0Sstevel@tonic-gate * CDDL HEADER END
21*0Sstevel@tonic-gate */
22*0Sstevel@tonic-gate /*
23*0Sstevel@tonic-gate * Copyright (c) 1999-2001 by Sun Microsystems, Inc.
24*0Sstevel@tonic-gate * All rights reserved.
25*0Sstevel@tonic-gate */
26*0Sstevel@tonic-gate
27*0Sstevel@tonic-gate #pragma ident "%Z%%M% %I% %E% SMI"
28*0Sstevel@tonic-gate
29*0Sstevel@tonic-gate #include <sys/types.h>
30*0Sstevel@tonic-gate #include <sys/debug.h>
31*0Sstevel@tonic-gate #include <sys/cmn_err.h>
32*0Sstevel@tonic-gate #include <sys/kmem.h>
33*0Sstevel@tonic-gate #include <sys/sysmacros.h>
34*0Sstevel@tonic-gate #include <sys/buf.h>
35*0Sstevel@tonic-gate #include <sys/user.h>
36*0Sstevel@tonic-gate #include <sys/proc.h>
37*0Sstevel@tonic-gate #include <sys/systm.h>
38*0Sstevel@tonic-gate #include <sys/vmsystm.h>
39*0Sstevel@tonic-gate #include <sys/mman.h>
40*0Sstevel@tonic-gate #include <sys/vm.h>
41*0Sstevel@tonic-gate #include <sys/ddi.h>
42*0Sstevel@tonic-gate
43*0Sstevel@tonic-gate #include <vm/as.h>
44*0Sstevel@tonic-gate #include <vm/page.h>
45*0Sstevel@tonic-gate
46*0Sstevel@tonic-gate /*
47*0Sstevel@tonic-gate * Prepare for raw I/O request - derived from default_physio()
48*0Sstevel@tonic-gate * This is the 'setup' portion of physio, limited to dealing
49*0Sstevel@tonic-gate * with unstructured access to a single range of user space addresses.
50*0Sstevel@tonic-gate *
51*0Sstevel@tonic-gate * This is quite limited in functionality compared to physio().
52*0Sstevel@tonic-gate *
53*0Sstevel@tonic-gate * 1. allocate and return buf header
54*0Sstevel@tonic-gate * 2. lock down user pages and verify access protections
55*0Sstevel@tonic-gate *
56*0Sstevel@tonic-gate * Use B_READ (S_WRITE) for unstructured access. (We don't know the
57*0Sstevel@tonic-gate * direction of the transfer, so use the safest.)
58*0Sstevel@tonic-gate */
59*0Sstevel@tonic-gate
60*0Sstevel@tonic-gate int
fc_physio_setup(struct buf ** bpp,void * io_base,size_t io_len)61*0Sstevel@tonic-gate fc_physio_setup(struct buf **bpp, void *io_base, size_t io_len)
62*0Sstevel@tonic-gate {
63*0Sstevel@tonic-gate struct proc *procp;
64*0Sstevel@tonic-gate struct as *asp;
65*0Sstevel@tonic-gate int error = 0;
66*0Sstevel@tonic-gate page_t **pplist;
67*0Sstevel@tonic-gate struct buf *bp = *bpp;
68*0Sstevel@tonic-gate
69*0Sstevel@tonic-gate bp = getrbuf(KM_SLEEP);
70*0Sstevel@tonic-gate bp->b_iodone = NULL;
71*0Sstevel@tonic-gate bp->b_resid = 0;
72*0Sstevel@tonic-gate *bpp = bp;
73*0Sstevel@tonic-gate
74*0Sstevel@tonic-gate /* segflg *is always* UIO_USERSPACE for us */
75*0Sstevel@tonic-gate procp = ttoproc(curthread);
76*0Sstevel@tonic-gate asp = procp->p_as;
77*0Sstevel@tonic-gate
78*0Sstevel@tonic-gate ASSERT(SEMA_HELD(&bp->b_sem));
79*0Sstevel@tonic-gate
80*0Sstevel@tonic-gate bp->b_error = 0;
81*0Sstevel@tonic-gate bp->b_proc = procp;
82*0Sstevel@tonic-gate
83*0Sstevel@tonic-gate bp->b_flags = B_BUSY | B_PHYS | B_READ;
84*0Sstevel@tonic-gate bp->b_edev = 0;
85*0Sstevel@tonic-gate bp->b_lblkno = 0;
86*0Sstevel@tonic-gate
87*0Sstevel@tonic-gate /*
88*0Sstevel@tonic-gate * Don't count on b_addr remaining untouched by the
89*0Sstevel@tonic-gate * code below (it may be reset because someone does
90*0Sstevel@tonic-gate * a bp_mapin on the buffer).
91*0Sstevel@tonic-gate */
92*0Sstevel@tonic-gate bp->b_un.b_addr = io_base;
93*0Sstevel@tonic-gate bp->b_bcount = io_len;
94*0Sstevel@tonic-gate
95*0Sstevel@tonic-gate error = as_pagelock(asp, &pplist, io_base, io_len, S_WRITE);
96*0Sstevel@tonic-gate
97*0Sstevel@tonic-gate if (error != 0) {
98*0Sstevel@tonic-gate bp->b_flags |= B_ERROR;
99*0Sstevel@tonic-gate bp->b_error = error;
100*0Sstevel@tonic-gate bp->b_flags &= ~(B_BUSY|B_WANTED|B_PHYS);
101*0Sstevel@tonic-gate freerbuf(bp);
102*0Sstevel@tonic-gate *bpp = NULL;
103*0Sstevel@tonic-gate return (error);
104*0Sstevel@tonic-gate }
105*0Sstevel@tonic-gate
106*0Sstevel@tonic-gate bp->b_shadow = pplist;
107*0Sstevel@tonic-gate if (pplist != NULL) {
108*0Sstevel@tonic-gate bp->b_flags |= B_SHADOW;
109*0Sstevel@tonic-gate }
110*0Sstevel@tonic-gate return (0);
111*0Sstevel@tonic-gate }
112*0Sstevel@tonic-gate
113*0Sstevel@tonic-gate /*
114*0Sstevel@tonic-gate * unlock the pages and free the buf header, if we allocated it.
115*0Sstevel@tonic-gate */
116*0Sstevel@tonic-gate void
fc_physio_free(struct buf ** bpp,void * io_base,size_t io_len)117*0Sstevel@tonic-gate fc_physio_free(struct buf **bpp, void *io_base, size_t io_len)
118*0Sstevel@tonic-gate {
119*0Sstevel@tonic-gate struct buf *bp = *bpp;
120*0Sstevel@tonic-gate page_t **pplist = NULL;
121*0Sstevel@tonic-gate
122*0Sstevel@tonic-gate /*
123*0Sstevel@tonic-gate * unlock the pages
124*0Sstevel@tonic-gate */
125*0Sstevel@tonic-gate
126*0Sstevel@tonic-gate if (bp->b_flags & B_SHADOW)
127*0Sstevel@tonic-gate pplist = bp->b_shadow;
128*0Sstevel@tonic-gate
129*0Sstevel@tonic-gate as_pageunlock(bp->b_proc->p_as, pplist, io_base, io_len, S_WRITE);
130*0Sstevel@tonic-gate
131*0Sstevel@tonic-gate bp->b_flags &= ~(B_BUSY|B_WANTED|B_PHYS|B_SHADOW);
132*0Sstevel@tonic-gate
133*0Sstevel@tonic-gate freerbuf(bp);
134*0Sstevel@tonic-gate *bpp = NULL;
135*0Sstevel@tonic-gate }
136