|
|
1.1 root 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 [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: * File: frc.c
28: * Author: Alessandro Forin, Carnegie Mellon University
29: * Date: 3/92
30: *
31: * Generic, mappable free running counter driver.
32: */
33:
34: #include <frc.h>
35: #if NFRC > 0
36:
37: #include <mach/std_types.h>
38: #include <chips/busses.h>
39: #include <device/device_types.h>
40:
41: /*
42: * Machine defines
43: * All you need to do to get this working on a
44: * random box is to define one macro and provide
45: * the correct virtual address.
46: */
47: #include <platforms.h>
48: #ifdef DECSTATION
49: #define btop(x) mips_btop(x)
50: #endif /* DECSTATION */
51:
52: /*
53: * Autoconf info
54: */
55:
56: static vm_offset_t frc_std[NFRC] = { 0 };
57: static vm_size_t frc_offset[NFRC] = { 0 };
58: static struct bus_device *frc_info[NFRC];
59: static int frc_probe(vm_offset_t,struct bus_ctlr *);
60: static void frc_attach(struct bus_device *);
61:
62: struct bus_driver frc_driver =
63: { frc_probe, 0, frc_attach, 0, frc_std, "frc", frc_info, };
64:
65: /*
66: * Externally visible functions
67: */
68: io_return_t frc_openclose(int,int); /* user */
69: vm_offset_t frc_mmap(int,vm_offset_t,vm_prot_t);
70: void frc_set_address(int,vm_size_t);
71:
72: /*
73: * FRC's in kernel virtual memory. For in-kernel timestamps.
74: */
75: vm_offset_t frc_address[NFRC];
76:
77: /* machine-specific setups */
78: void
79: frc_set_address(
80: int unit,
81: vm_size_t offset)
82: {
83: if (unit < NFRC) {
84: frc_offset[unit] = offset;
85: }
86: }
87:
88:
89: /*
90: * Probe chip to see if it is there
91: */
92: static frc_probe (
93: vm_offset_t reg,
94: struct bus_ctlr *ui)
95: {
96: /* see if something present at the given address */
97: if (check_memory(reg, 0)) {
98: frc_address[ui->unit] = 0;
99: return 0;
100: }
101: frc_std[ui->unit] = (vm_offset_t) reg;
102: printf("[mappable] ");
103: return 1;
104: }
105:
106: static void
107: frc_attach (
108: struct bus_device *ui)
109: {
110: if (ui->unit < NFRC) {
111: frc_address[ui->unit] =
112: (vm_offset_t) frc_std[ui->unit] + frc_offset[ui->unit];
113: printf(": free running counter %d at kernel vaddr 0x%x",
114: ui->unit, frc_address[ui->unit]);
115: }
116: else
117: panic("frc: unknown unit number"); /* shouldn't happen */
118: }
119:
120: int frc_intr()
121: {
122: /* we do not expect interrupts */
123: panic("frc_intr");
124: }
125:
126: io_return_t
127: frc_openclose(
128: int dev,
129: int flag)
130: {
131: if (frc_std[dev])
132: return D_SUCCESS;
133: else
134: return D_NO_SUCH_DEVICE;
135: }
136:
137: vm_offset_t
138: frc_mmap(
139: int dev,
140: vm_offset_t off,
141: vm_prot_t prot)
142: {
143: vm_offset_t addr;
144: if ((prot & VM_PROT_WRITE) || (off >= PAGE_SIZE) )
145: return (-1);
146: addr = (vm_offset_t) frc_std[dev] + frc_offset[dev];
147: return btop(pmap_extract(pmap_kernel(), addr));
148: }
149:
150: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.