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