]> git.saurik.com Git - apple/xnu.git/blame - osfmk/kern/etap_map.c
xnu-124.13.tar.gz
[apple/xnu.git] / osfmk / kern / etap_map.c
CommitLineData
1c79356b
A
1/*
2 * Copyright (c) 2000 Apple Computer, Inc. All rights reserved.
3 *
4 * @APPLE_LICENSE_HEADER_START@
5 *
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.
11 *
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
18 * under the License.
19 *
20 * @APPLE_LICENSE_HEADER_END@
21 */
22/*
23 * @OSF_COPYRIGHT@
24 */
25/*
26 * HISTORY
27 *
28 * Revision 1.1.1.1 1998/09/22 21:05:34 wsanchez
29 * Import of Mac OS X kernel (~semeria)
30 *
31 * Revision 1.1.1.1 1998/03/07 02:25:54 wsanchez
32 * Import of OSF Mach kernel (~mburg)
33 *
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]
37 *
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]
41 *
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]
47 *
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]
51 *
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]
55 *
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]
60 *
61 * mk6 CR801 - new file for mk6_shared from cnmk_shared.
62 * [1994/12/01 21:11:35 dwm]
63 *
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]
67 *
68 * $EndLog$
69 */
70/*
71 * File : etap_map.c
72 *
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.
76 *
77 */
78/*
79 * Minor device number representation:
80 *
81 * 0 = ETAP_TABLE_EVENT
82 * 1 = ETAP_TABLE_SUBSYSTEM
83 * 2 = ETAP_BUFFER_CUMULATIVE
84 * 3 & up = a specific monitor buffer
85 *
86 */
87
88#include <types.h>
89
90#include <mach/vm_prot.h>
91#include <mach/vm_param.h>
92#include <mach/kern_return.h>
93#include <vm/pmap.h>
94#include <device/io_req.h>
95#include <device/dev_hdr.h>
96
97#include <cpus.h>
98#include <kern/etap_options.h>
99#include <mach/etap.h>
100#include <kern/etap_map.h>
101
102
103#if ETAP_LOCK_ACCUMULATE
104extern cumulative_buffer_t cbuff;
105#endif /* ETAP_LOCK_ACCUMULATE */
106
107#if ETAP_MONITOR
108extern monitor_buffer_t mbuff[];
109#endif /* ETAP_MONITOR */
110
111
112/*
113 * etap_map_open - Check for valid minor device
114 */
115
116io_return_t
117etap_map_open(
118 dev_t dev,
119 dev_mode_t flags,
120 io_req_t ior)
121{
122 int buffer = minor(dev);
123
124 if (buffer >= ETAP_MAX_DEVICES)
125 return(D_NO_SUCH_DEVICE);
126
127 return(D_SUCCESS);
128}
129
130vm_offset_t
131etap_map_mmap (
132 dev_t dev,
133 vm_offset_t off,
134 vm_prot_t prot)
135{
136 int buffer = minor(dev);
137 vm_offset_t addr;
138
139 /*
140 * Check request validity
141 */
142
143 if (prot & VM_PROT_WRITE)
144 return(KERN_PROTECTION_FAILURE);
145
146 if (buffer < 0 || buffer >= ETAP_MAX_DEVICES)
147 return(KERN_INVALID_ARGUMENT);
148
149 switch(buffer) {
150 case ETAP_TABLE_EVENT :
151 addr = trunc_page((char *) event_table) + off;
152 break;
153 case ETAP_TABLE_SUBSYSTEM :
154 addr = trunc_page((char *) subs_table) + off;
155 break;
156 case ETAP_BUFFER_CUMULATIVE :
157#if ETAP_LOCK_ACCUMULATE
158 addr = (vm_offset_t) cbuff + off;
159 break;
160#else /* ETAP_LOCK_ACCUMULATE */
161 return(KERN_INVALID_ARGUMENT);
162#endif /* ETAP_LOCK_ACCUMULATE */
163
164 default :
165#if ETAP_MONITOR
166 addr = (vm_offset_t) mbuff[buffer - 3] + off;
167 break;
168#else /* ETAP_MONITOR */
169 return(KERN_INVALID_ARGUMENT);
170#endif /* ETAP_MONITOR */
171
172 }
173 return machine_btop(pmap_extract(pmap_kernel(), addr));
174}