FreeBSD/Linux Kernel Cross Reference
sys/chips/frc.c
1 /*
2 * Mach Operating System
3 * Copyright (c) 1993,1992 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: frc.c,v $
29 * Revision 2.10 93/11/17 16:11:27 dbg
30 * Changed mmap routines to return physical address instead of
31 * physical page number.
32 * [93/06/16 dbg]
33 *
34 * Revision 2.9 93/08/10 15:18:26 mrt
35 * Made frc's accessible to kernel code via frc_address[].
36 * [93/07/20 cmaeda]
37 *
38 * Revision 2.8 93/05/17 10:27:00 rvb
39 * Type casts, etc to quiet gcc 2.3.3 warnings
40 *
41 * Revision 2.7 93/05/10 20:07:53 rvb
42 * Fixed types.
43 * [93/05/06 09:58:36 af]
44 *
45 * Revision 2.6 93/03/26 17:58:49 mrt
46 * Removed all uses of minor().
47 * [93/03/17 af]
48 *
49 * Revision 2.5 93/01/24 13:55:13 danner
50 * Sandro's fixes to danner's fixes to mattz's fixes.
51 * [93/01/17 mrt]
52 *
53 * Revision 2.4 93/01/14 17:16:25 danner
54 * Fixed mattz's open of nonexistenent frc problem.
55 * [93/01/14 danner]
56 *
57 * Corrected type of frc_std.
58 * [93/01/14 danner]
59 *
60 * Revision 2.3 92/05/05 10:53:00 danner
61 * Added frc_set_address(), to customize it.
62 * Makes NSC's boards happy (any TC box).
63 * [92/04/13 jcb]
64 *
65 * Revision 2.2 92/04/01 15:14:23 rpd
66 * Created, based on maxine's counter.
67 * [92/03/10 af]
68 *
69 */
70 /*
71 * File: frc.c
72 * Author: Alessandro Forin, Carnegie Mellon University
73 * Date: 3/92
74 *
75 * Generic, mappable free running counter driver.
76 */
77
78 #include <frc.h>
79 #if NFRC > 0
80
81 #include <mach/std_types.h>
82 #include <chips/busses.h>
83 #include <device/device_types.h>
84
85 /*
86 * Machine defines
87 * All you need to do to get this working on a
88 * random box is to define one macro and provide
89 * the correct virtual address.
90 */
91 #include <platforms.h>
92 #ifdef DECSTATION
93 #define btop(x) mips_btop(x)
94 #endif /* DECSTATION */
95
96 /*
97 * Autoconf info
98 */
99
100 static vm_offset_t frc_std[NFRC] = { 0 };
101 static vm_size_t frc_offset[NFRC] = { 0 };
102 static struct bus_device *frc_info[NFRC];
103 static boolean_t frc_probe(vm_offset_t,struct bus_ctlr *);
104 static void frc_attach(struct bus_device *);
105
106 struct bus_driver frc_driver =
107 { frc_probe, 0, frc_attach, 0, frc_std, "frc", frc_info, };
108
109 /*
110 * Externally visible functions
111 */
112 io_return_t frc_openclose(int,int); /* user */
113 vm_offset_t frc_mmap(int,vm_offset_t,vm_prot_t);
114 void frc_set_address(int,vm_size_t);
115
116 /*
117 * FRC's in kernel virtual memory. For in-kernel timestamps.
118 */
119 vm_offset_t frc_address[NFRC];
120
121 /* machine-specific setups */
122 void
123 frc_set_address(
124 int unit,
125 vm_size_t offset)
126 {
127 if (unit < NFRC) {
128 frc_offset[unit] = offset;
129 }
130 }
131
132
133 /*
134 * Probe chip to see if it is there
135 */
136 static boolean_t frc_probe (
137 vm_offset_t reg,
138 struct bus_ctlr *ui)
139 {
140 /* see if something present at the given address */
141 if (check_memory(reg, 0)) {
142 frc_address[ui->unit] = 0;
143 return FALSE;
144 }
145 frc_std[ui->unit] = (vm_offset_t) reg;
146 printf("[mappable] ");
147 return TRUE;
148 }
149
150 static void
151 frc_attach (
152 struct bus_device *ui)
153 {
154 if (ui->unit < NFRC) {
155 frc_address[ui->unit] =
156 (vm_offset_t) frc_std[ui->unit] + frc_offset[ui->unit];
157 printf(": free running counter %d at kernel vaddr 0x%x",
158 ui->unit, frc_address[ui->unit]);
159 }
160 else
161 panic("frc: unknown unit number"); /* shouldn't happen */
162 }
163
164 int frc_intr()
165 {
166 /* we do not expect interrupts */
167 panic("frc_intr");
168 }
169
170 io_return_t
171 frc_openclose(
172 int dev,
173 int flag)
174 {
175 if (frc_std[dev])
176 return D_SUCCESS;
177 else
178 return D_NO_SUCH_DEVICE;
179 }
180
181 vm_offset_t
182 frc_mmap(
183 int dev,
184 vm_offset_t off,
185 vm_prot_t prot)
186 {
187 vm_offset_t addr;
188 if ((prot & VM_PROT_WRITE) || (off >= PAGE_SIZE) )
189 return -1;
190 addr = (vm_offset_t) frc_std[dev] + frc_offset[dev];
191 return pmap_extract(pmap_kernel(), addr);
192 }
193
194 #endif
Cache object: 09199e32a19857fadea1b3bde264a0d1
|