2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
4 * @APPLE_LICENSE_HEADER_START@
6 * Copyright (c) 1999-2003 Apple Computer, Inc. All Rights Reserved.
8 * This file contains Original Code and/or Modifications of Original Code
9 * as defined in and that are subject to the Apple Public Source License
10 * Version 2.0 (the 'License'). You may not use this file except in
11 * compliance with the License. Please obtain a copy of the License at
12 * http://www.opensource.apple.com/apsl/ and read it before using this
15 * The Original Code and all software distributed under the License are
16 * distributed on an 'AS IS' basis, WITHOUT WARRANTY OF ANY KIND, EITHER
17 * EXPRESS OR IMPLIED, AND APPLE HEREBY DISCLAIMS ALL SUCH WARRANTIES,
18 * INCLUDING WITHOUT LIMITATION, ANY WARRANTIES OF MERCHANTABILITY,
19 * FITNESS FOR A PARTICULAR PURPOSE, QUIET ENJOYMENT OR NON-INFRINGEMENT.
20 * Please see the License for the specific language governing rights and
21 * limitations under the License.
23 * @APPLE_LICENSE_HEADER_END@
31 * Revision 1.1.1.1 1998/09/22 21:05:34 wsanchez
32 * Import of Mac OS X kernel (~semeria)
34 * Revision 1.1.1.1 1998/03/07 02:25:54 wsanchez
35 * Import of OSF Mach kernel (~mburg)
37 * Revision 1.1.6.1 1996/09/17 16:26:58 bruel
38 * use standalone includes only
39 * [1996/09/17 15:38:08 bruel]
41 * Revision 1.1.4.1 1996/02/02 12:16:40 emcmanus
42 * Copied from nmk20b5_shared.
43 * [1996/02/01 16:56:11 emcmanus]
45 * Revision 1.1.2.1 1995/12/30 17:12:07 emcmanus
46 * Renamed from i386/etap_map.c and made this file machine-independent.
47 * Delete declarations of event_table and subs_table, now declared with
48 * different types in etap_macros.h.
49 * [1995/12/30 17:03:55 emcmanus]
51 * Revision 1.1.2.4 1995/10/09 17:07:21 devrcs
52 * Merged in RT3_SHARED ETAP code.
53 * [1995/09/13 18:48:15 joe]
55 * Revision 1.1.2.3 1995/09/18 19:10:05 devrcs
56 * Merged in RT3_SHARED ETAP code.
57 * [1995/09/13 18:48:15 joe]
59 * Revision 1.1.2.2 1995/01/10 04:51:59 devrcs
60 * mk6 CR801 - merge up from nmk18b4 to nmk18b7
61 * tweak signatures, a la osc1.3b26
62 * [1994/12/09 20:38:32 dwm]
64 * mk6 CR801 - new file for mk6_shared from cnmk_shared.
65 * [1994/12/01 21:11:35 dwm]
67 * Revision 1.1.2.1 1994/10/21 18:35:57 joe
68 * Initial ETAP submission
69 * [1994/10/20 19:21:39 joe]
76 * Pseudo-device driver to calculate the virtual addresses
77 * of all mappable ETAP buffers and tables: event table,
78 * subsystem table, cumulative buffer and monitor buffers.
82 * Minor device number representation:
84 * 0 = ETAP_TABLE_EVENT
85 * 1 = ETAP_TABLE_SUBSYSTEM
86 * 2 = ETAP_BUFFER_CUMULATIVE
87 * 3 & up = a specific monitor buffer
93 #include <mach/vm_prot.h>
94 #include <mach/vm_param.h>
95 #include <mach/kern_return.h>
97 #include <device/io_req.h>
98 #include <device/dev_hdr.h>
101 #include <kern/etap_options.h>
102 #include <mach/etap.h>
103 #include <kern/etap_map.h>
106 #if ETAP_LOCK_ACCUMULATE
107 extern cumulative_buffer_t cbuff
;
108 #endif /* ETAP_LOCK_ACCUMULATE */
111 extern monitor_buffer_t mbuff
[];
112 #endif /* ETAP_MONITOR */
116 * etap_map_open - Check for valid minor device
125 int buffer
= minor(dev
);
127 if (buffer
>= ETAP_MAX_DEVICES
)
128 return(D_NO_SUCH_DEVICE
);
139 int buffer
= minor(dev
);
143 * Check request validity
146 if (prot
& VM_PROT_WRITE
)
147 return(KERN_PROTECTION_FAILURE
);
149 if (buffer
< 0 || buffer
>= ETAP_MAX_DEVICES
)
150 return(KERN_INVALID_ARGUMENT
);
153 case ETAP_TABLE_EVENT
:
154 addr
= trunc_page((char *) event_table
) + off
;
156 case ETAP_TABLE_SUBSYSTEM
:
157 addr
= trunc_page((char *) subs_table
) + off
;
159 case ETAP_BUFFER_CUMULATIVE
:
160 #if ETAP_LOCK_ACCUMULATE
161 addr
= (vm_offset_t
) cbuff
+ off
;
163 #else /* ETAP_LOCK_ACCUMULATE */
164 return(KERN_INVALID_ARGUMENT
);
165 #endif /* ETAP_LOCK_ACCUMULATE */
169 addr
= (vm_offset_t
) mbuff
[buffer
- 3] + off
;
171 #else /* ETAP_MONITOR */
172 return(KERN_INVALID_ARGUMENT
);
173 #endif /* ETAP_MONITOR */
176 return machine_btop(pmap_extract(pmap_kernel(), addr
));