|
|
1.1 root 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 [email protected]
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: * Author: David B. Golub, Carnegie Mellon University
28: * Date: 10/88
29: */
30:
31: #ifndef _IO_REQ_
32: #define _IO_REQ_
33:
34: #include <mach/boolean.h>
35: #include <mach/port.h>
36: #include <mach/message.h>
37: #include <mach/vm_param.h>
38: #include <kern/kalloc.h>
39: #include <kern/lock.h>
40: #include <vm/vm_page.h>
41: #include <device/device_types.h>
42: #include <device/dev_hdr.h>
43:
44: #include <kern/macro_help.h>
45:
46: /*
47: * IO request element, queued on device for delayed replies.
48: */
49: struct io_req {
50: struct io_req * io_next; /* next, ... */
51: struct io_req * io_prev; /* prev pointers: link in done,
52: defered, or in-progress list */
53: mach_device_t io_device; /* pointer to open-device structure */
54: char * io_dev_ptr; /* pointer to driver structure -
55: filled in by driver if necessary */
56: int io_unit; /* unit number ('minor') of device */
57: int io_op; /* IO operation */
58: dev_mode_t io_mode; /* operation mode (wait, truncate) */
59: recnum_t io_recnum; /* starting record number for
60: random-access devices */
61:
62: union io_un {
63: io_buf_ptr_t data; /* data, for IO requests */
64: } io_un;
65: #define io_data io_un.data
66:
67: long io_count; /* amount requested */
68: long io_alloc_size; /* amount allocated */
69: long io_residual; /* amount NOT done */
70: io_return_t io_error; /* error code */
71: boolean_t (*io_done)(); /* call when done - returns TRUE
72: if IO really finished */
73: struct ipc_port *io_reply_port; /* reply port, for asynchronous
74: messages */
75: mach_msg_type_name_t io_reply_port_type;
76: /* send or send-once right? */
77: struct io_req * io_link; /* forward link (for driver header) */
78: struct io_req * io_rlink; /* reverse link (for driver header) */
79: vm_map_copy_t io_copy; /* vm_map_copy obj. for this op. */
80: long io_total; /* total op size, for write */
81: decl_simple_lock_data(,io_req_lock)
82: /* Lock for this structure */
83: long io_physrec; /* mapping to the physical block
84: number */
85: long io_rectotal; /* total number of blocks to move */
86: };
87: typedef struct io_req * io_req_t;
88:
89: /*
90: * LOCKING NOTE: Operations on io_req's are in general single threaded by
91: * the invoking code, obviating the need for a lock. The usual IO_CALL
92: * path through the code is: Initiating thread hands io_req to device driver,
93: * driver passes it to io_done thread, io_done thread sends reply message. No
94: * locking is needed in this sequence. Unfortunately, a synchronous wait
95: * for a buffer requires a lock to avoid problems if the wait and interrupt
96: * happen simultaneously on different processors.
97: */
98:
99: #define ior_lock(ior) simple_lock(&(ior)->io_req_lock)
100: #define ior_unlock(ior) simple_unlock(&(ior)->io_req_lock)
101:
102: /*
103: * Flags and operations
104: */
105:
106: #define IO_WRITE 0x00000000 /* operation is write */
107: #define IO_READ 0x00000001 /* operation is read */
108: #define IO_OPEN 0x00000002 /* operation is open */
109: #define IO_DONE 0x00000100 /* operation complete */
110: #define IO_ERROR 0x00000200 /* error on operation */
111: #define IO_BUSY 0x00000400 /* operation in progress */
112: #define IO_WANTED 0x00000800 /* wakeup when no longer BUSY */
113: #define IO_BAD 0x00001000 /* bad disk block */
114: #define IO_CALL 0x00002000 /* call io_done_thread when done */
115: #define IO_INBAND 0x00004000 /* mig call was inband */
116: #define IO_INTERNAL 0x00008000 /* internal, device-driver specific */
117: #define IO_LOANED 0x00010000 /* ior loaned by another module */
118:
119: #define IO_SPARE_START 0x00020000 /* start of spare flags */
120:
121: /*
122: * Standard completion routine for io_requests.
123: */
124: void iodone(/* io_req_t */);
125:
126: /*
127: * Macros to allocate and free IORs - will convert to zones later.
128: */
129: #define io_req_alloc(ior,size) \
130: MACRO_BEGIN \
131: (ior) = (io_req_t)kalloc(sizeof(struct io_req)); \
132: simple_lock_init(&(ior)->io_req_lock); \
133: MACRO_END
134:
135: #define io_req_free(ior) \
136: (kfree((vm_offset_t)(ior), sizeof(struct io_req)))
137:
138:
139: zone_t io_inband_zone; /* for inband reads */
140:
141: #endif _IO_REQ_
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.