FreeBSD/Linux Kernel Cross Reference
sys/device/io_req.h
1 /*
2 * Mach Operating System
3 * Copyright (c) 1991,1990,1989,1988 Carnegie Mellon University
4 * All Rights Reserved.
5 *
6 * Permission to use, copy, modify and distribute this software and its
7 * documentation is hereby granted, provided that both the copyright
8 * notice and this permission notice appear in all copies of the
9 * software, derivative works or modified versions, and any portions
10 * thereof, and that both notices appear in supporting documentation.
11 *
12 * CARNEGIE MELLON ALLOWS FREE USE OF THIS SOFTWARE IN ITS "AS IS"
13 * CONDITION. CARNEGIE MELLON DISCLAIMS ANY LIABILITY OF ANY KIND FOR
14 * ANY DAMAGES WHATSOEVER RESULTING FROM THE USE OF THIS SOFTWARE.
15 *
16 * Carnegie Mellon requests users of this software to return to
17 *
18 * Software Distribution Coordinator or Software.Distribution@CS.CMU.EDU
19 * School of Computer Science
20 * Carnegie Mellon University
21 * Pittsburgh PA 15213-3890
22 *
23 * any improvements or extensions that they make and grant Carnegie Mellon
24 * the rights to redistribute these changes.
25 */
26 /*
27 * HISTORY
28 * $Log: io_req.h,v $
29 * Revision 2.14 92/05/21 17:09:32 jfriedl
30 * Changed cast of kfree's first arg in io_req_free() to
31 * vm_offset_t from char* to mach reality (and shush gcc warnings).
32 * [92/05/16 jfriedl]
33 *
34 * Revision 2.13 92/01/03 20:03:43 dbg
35 * Rename io_lock to io_req_lock to avoid conflict with io_lock
36 * macro for ipc_objects.
37 * [91/10/21 dbg]
38 *
39 * Revision 2.12 91/08/28 11:11:24 jsb
40 * Removed semicolon after decl_simple_lock_data in io_req declaration.
41 * [91/08/16 15:31:22 jsb]
42 *
43 * Add lock and associated macros to io_req structure.
44 * [91/08/12 17:28:46 dlb]
45 *
46 * Add io_total for use by writes - io_count is for each driver
47 * operation, io_total is for the entire device_write.
48 * [91/08/05 17:34:49 dlb]
49 *
50 * Add io_copy field to remember vm_map_copy_t that must be discarded
51 * when a mapped (not inline) device_write completes.
52 * [91/07/31 14:43:07 dlb]
53 *
54 * Revision 2.11 91/08/03 18:17:39 jsb
55 * Added IO_LOANED flag, initially for norma_ipc support.
56 * Loaned ior's are returned directly at interrupt level;
57 * see iodone() for details.
58 * [91/07/27 22:28:29 jsb]
59 *
60 * Revision 2.10 91/05/14 15:58:41 mrt
61 * Correcting copyright
62 *
63 * Revision 2.9 91/05/13 06:02:25 af
64 * Added IO_INTERNAL, for use when an io_request packet is used
65 * just for synchronization purposes.
66 * [91/03/11 af]
67 *
68 * Revision 2.8 91/02/05 17:09:49 mrt
69 * Changed to new Mach copyright
70 * [91/01/31 17:29:53 mrt]
71 *
72 * Revision 2.7 90/06/02 14:48:08 rpd
73 * Converted to new IPC. Removed io_dev_port.
74 * [90/03/26 21:56:39 rpd]
75 *
76 * Revision 2.6 90/05/03 15:19:09 dbg
77 * Add spare flags definition for device-dependent uses.
78 * [90/03/14 dbg]
79 *
80 * Revision 2.5 90/01/11 11:42:13 dbg
81 * De-lint.
82 * [89/12/06 dbg]
83 *
84 * Revision 2.4 89/09/08 11:24:30 dbg
85 * Allocate io_req elements from kalloc pool, to allow a
86 * variable-length vm_page_t array at the end of the io_req_t.
87 * [89/08/14 dbg]
88 *
89 * Changed 'dev_hdr_t' to 'device_t'.
90 * [89/08/01 dbg]
91 *
92 * Revision 2.3 89/08/31 16:18:51 rwd
93 * Added io_inband_zone
94 * [89/08/15 rwd]
95 *
96 * Revision 2.2 89/08/05 16:06:50 rwd
97 * Added IO_INBAND.
98 * [89/08/04 rwd]
99 *
100 * 10-Oct-88 David Golub (dbg) at Carnegie-Mellon University
101 * Created.
102 *
103 */
104 /*
105 * Author: David B. Golub, Carnegie Mellon University
106 * Date: 10/88
107 */
108
109 #ifndef _IO_REQ_
110 #define _IO_REQ_
111
112 #include <mach/boolean.h>
113 #include <mach/port.h>
114 #include <mach/message.h>
115 #include <mach/vm_param.h>
116 #include <kern/kalloc.h>
117 #include <kern/lock.h>
118 #include <vm/vm_page.h>
119 #include <device/device_types.h>
120 #include <device/dev_hdr.h>
121
122 #include <kern/macro_help.h>
123
124 /*
125 * IO request element, queued on device for delayed replies.
126 */
127 struct io_req {
128 struct io_req * io_next; /* next, ... */
129 struct io_req * io_prev; /* prev pointers: link in done,
130 defered, or in-progress list */
131 device_t io_device; /* pointer to open-device structure */
132 char * io_dev_ptr; /* pointer to driver structure -
133 filled in by driver if necessary */
134 int io_unit; /* unit number ('minor') of device */
135 int io_op; /* IO operation */
136 dev_mode_t io_mode; /* operation mode (wait, truncate) */
137 recnum_t io_recnum; /* starting record number for
138 random-access devices */
139
140 union io_un {
141 io_buf_ptr_t data; /* data, for IO requests */
142 } io_un;
143 #define io_data io_un.data
144
145 long io_count; /* amount requested */
146 long io_alloc_size; /* amount allocated */
147 long io_residual; /* amount NOT done */
148 io_return_t io_error; /* error code */
149 boolean_t (*io_done)(); /* call when done - returns TRUE
150 if IO really finished */
151 struct ipc_port *io_reply_port; /* reply port, for asynchronous
152 messages */
153 mach_msg_type_name_t io_reply_port_type;
154 /* send or send-once right? */
155 struct io_req * io_link; /* forward link (for driver header) */
156 struct io_req * io_rlink; /* reverse link (for driver header) */
157 vm_map_copy_t io_copy; /* vm_map_copy obj. for this op. */
158 long io_total; /* total op size, for write */
159 decl_simple_lock_data(,io_req_lock)
160 /* Lock for this structure */
161 };
162 typedef struct io_req * io_req_t;
163
164 /*
165 * LOCKING NOTE: Operations on io_req's are in general single threaded by
166 * the invoking code, obviating the need for a lock. The usual IO_CALL
167 * path through the code is: Initiating thread hands io_req to device driver,
168 * driver passes it to io_done thread, io_done thread sends reply message. No
169 * locking is needed in this sequence. Unfortunately, a synchronous wait
170 * for a buffer requires a lock to avoid problems if the wait and interrupt
171 * happen simultaneously on different processors.
172 */
173
174 #define ior_lock(ior) simple_lock(&(ior)->io_req_lock)
175 #define ior_unlock(ior) simple_unlock(&(ior)->io_req_lock)
176
177 /*
178 * Flags and operations
179 */
180
181 #define IO_WRITE 0x00000000 /* operation is write */
182 #define IO_READ 0x00000001 /* operation is read */
183 #define IO_OPEN 0x00000002 /* operation is open */
184 #define IO_DONE 0x00000100 /* operation complete */
185 #define IO_ERROR 0x00000200 /* error on operation */
186 #define IO_BUSY 0x00000400 /* operation in progress */
187 #define IO_WANTED 0x00000800 /* wakeup when no longer BUSY */
188 #define IO_BAD 0x00001000 /* bad disk block */
189 #define IO_CALL 0x00002000 /* call io_done_thread when done */
190 #define IO_INBAND 0x00004000 /* mig call was inband */
191 #define IO_INTERNAL 0x00008000 /* internal, device-driver specific */
192 #define IO_LOANED 0x00010000 /* ior loaned by another module */
193
194 #define IO_SPARE_START 0x00020000 /* start of spare flags */
195
196 /*
197 * Standard completion routine for io_requests.
198 */
199 void iodone(/* io_req_t */);
200
201 /*
202 * Macros to allocate and free IORs - will convert to zones later.
203 */
204 #define io_req_alloc(ior,size) \
205 MACRO_BEGIN \
206 (ior) = (io_req_t)kalloc(sizeof(struct io_req)); \
207 simple_lock_init(&(ior)->io_req_lock); \
208 MACRO_END
209
210 #define io_req_free(ior) \
211 (kfree((vm_offset_t)(ior), sizeof(struct io_req)))
212
213
214 zone_t io_inband_zone; /* for inband reads */
215
216 #endif _IO_REQ_
Cache object: 9a38618042d61a25f9869bf870915504
|