2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * The contents of this file constitute Original Code as defined in and
7 * are subject to the Apple Public Source License Version 1.1 (the
8 * "License"). You may not use this file except in compliance with the
9 * License. Please obtain a copy of the License at
10 * http://www.apple.com/publicsource and read it before using this file.
12 * This Original Code and all software distributed under the License are
13 * distributed on an "AS IS" basis, WITHOUT WARRANTY OF ANY KIND, EITHER
14 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
15 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
16 * FITNESS FOR A PARTICULAR PURPOSE OR NON-INFRINGEMENT. Please see the
17 * License for the specific language governing rights and limitations
20 * @APPLE_LICENSE_HEADER_END@
28 * Revision 1.1.1.1 1998/09/22 21:05:34 wsanchez
29 * Import of Mac OS X kernel (~semeria)
31 * Revision 1.1.1.1 1998/03/07 02:25:54 wsanchez
32 * Import of OSF Mach kernel (~mburg)
34 * Revision 1.1.6.1 1996/09/17 16:26:58 bruel
35 * use standalone includes only
36 * [1996/09/17 15:38:08 bruel]
38 * Revision 1.1.4.1 1996/02/02 12:16:40 emcmanus
39 * Copied from nmk20b5_shared.
40 * [1996/02/01 16:56:11 emcmanus]
42 * Revision 1.1.2.1 1995/12/30 17:12:07 emcmanus
43 * Renamed from i386/etap_map.c and made this file machine-independent.
44 * Delete declarations of event_table and subs_table, now declared with
45 * different types in etap_macros.h.
46 * [1995/12/30 17:03:55 emcmanus]
48 * Revision 1.1.2.4 1995/10/09 17:07:21 devrcs
49 * Merged in RT3_SHARED ETAP code.
50 * [1995/09/13 18:48:15 joe]
52 * Revision 1.1.2.3 1995/09/18 19:10:05 devrcs
53 * Merged in RT3_SHARED ETAP code.
54 * [1995/09/13 18:48:15 joe]
56 * Revision 1.1.2.2 1995/01/10 04:51:59 devrcs
57 * mk6 CR801 - merge up from nmk18b4 to nmk18b7
58 * tweak signatures, a la osc1.3b26
59 * [1994/12/09 20:38:32 dwm]
61 * mk6 CR801 - new file for mk6_shared from cnmk_shared.
62 * [1994/12/01 21:11:35 dwm]
64 * Revision 1.1.2.1 1994/10/21 18:35:57 joe
65 * Initial ETAP submission
66 * [1994/10/20 19:21:39 joe]
73 * Pseudo-device driver to calculate the virtual addresses
74 * of all mappable ETAP buffers and tables: event table,
75 * subsystem table, cumulative buffer and monitor buffers.
79 * Minor device number representation:
81 * 0 = ETAP_TABLE_EVENT
82 * 1 = ETAP_TABLE_SUBSYSTEM
83 * 2 = ETAP_BUFFER_CUMULATIVE
84 * 3 & up = a specific monitor buffer
90 #include <mach/vm_prot.h>
91 #include <mach/vm_param.h>
92 #include <mach/kern_return.h>
94 #include <device/io_req.h>
95 #include <device/dev_hdr.h>
98 #include <kern/etap_options.h>
99 #include <mach/etap.h>
100 #include <kern/etap_map.h>
103 #if ETAP_LOCK_ACCUMULATE
104 extern cumulative_buffer_t cbuff
;
105 #endif /* ETAP_LOCK_ACCUMULATE */
108 extern monitor_buffer_t mbuff
[];
109 #endif /* ETAP_MONITOR */
113 * etap_map_open - Check for valid minor device
122 int buffer
= minor(dev
);
124 if (buffer
>= ETAP_MAX_DEVICES
)
125 return(D_NO_SUCH_DEVICE
);
136 int buffer
= minor(dev
);
140 * Check request validity
143 if (prot
& VM_PROT_WRITE
)
144 return(KERN_PROTECTION_FAILURE
);
146 if (buffer
< 0 || buffer
>= ETAP_MAX_DEVICES
)
147 return(KERN_INVALID_ARGUMENT
);
150 case ETAP_TABLE_EVENT
:
151 addr
= trunc_page((char *) event_table
) + off
;
153 case ETAP_TABLE_SUBSYSTEM
:
154 addr
= trunc_page((char *) subs_table
) + off
;
156 case ETAP_BUFFER_CUMULATIVE
:
157 #if ETAP_LOCK_ACCUMULATE
158 addr
= (vm_offset_t
) cbuff
+ off
;
160 #else /* ETAP_LOCK_ACCUMULATE */
161 return(KERN_INVALID_ARGUMENT
);
162 #endif /* ETAP_LOCK_ACCUMULATE */
166 addr
= (vm_offset_t
) mbuff
[buffer
- 3] + off
;
168 #else /* ETAP_MONITOR */
169 return(KERN_INVALID_ARGUMENT
);
170 #endif /* ETAP_MONITOR */
173 return machine_btop(pmap_extract(pmap_kernel(), addr
));