x86emu_i8254.h revision 1.1.2.2 1 1.1.2.2 matt /* $NetBSD: x86emu_i8254.h,v 1.1.2.2 2008/01/09 01:20:46 matt Exp $ */
2 1.1.2.2 matt
3 1.1.2.2 matt /*-
4 1.1.2.2 matt * Copyright (c) 2007 Joerg Sonnenberger <joerg (at) NetBSD.org>.
5 1.1.2.2 matt * All rights reserved.
6 1.1.2.2 matt *
7 1.1.2.2 matt * Redistribution and use in source and binary forms, with or without
8 1.1.2.2 matt * modification, are permitted provided that the following conditions
9 1.1.2.2 matt * are met:
10 1.1.2.2 matt *
11 1.1.2.2 matt * 1. Redistributions of source code must retain the above copyright
12 1.1.2.2 matt * notice, this list of conditions and the following disclaimer.
13 1.1.2.2 matt * 2. Redistributions in binary form must reproduce the above copyright
14 1.1.2.2 matt * notice, this list of conditions and the following disclaimer in
15 1.1.2.2 matt * the documentation and/or other materials provided with the
16 1.1.2.2 matt * distribution.
17 1.1.2.2 matt *
18 1.1.2.2 matt * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 1.1.2.2 matt * ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 1.1.2.2 matt * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
21 1.1.2.2 matt * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
22 1.1.2.2 matt * COPYRIGHT HOLDERS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,
23 1.1.2.2 matt * INCIDENTAL, SPECIAL, EXEMPLARY OR CONSEQUENTIAL DAMAGES (INCLUDING,
24 1.1.2.2 matt * BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
25 1.1.2.2 matt * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED
26 1.1.2.2 matt * AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
27 1.1.2.2 matt * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
28 1.1.2.2 matt * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29 1.1.2.2 matt * SUCH DAMAGE.
30 1.1.2.2 matt */
31 1.1.2.2 matt
32 1.1.2.2 matt #ifndef _X86EMU_X86EMU_I8254_H
33 1.1.2.2 matt #define _X86EMU_X86EMU_I8254_H
34 1.1.2.2 matt
35 1.1.2.2 matt #include <sys/time.h>
36 1.1.2.2 matt
37 1.1.2.2 matt #ifndef _KERNEL
38 1.1.2.2 matt # include <stdbool.h>
39 1.1.2.2 matt #else
40 1.1.2.2 matt # include <sys/types.h>
41 1.1.2.2 matt #endif
42 1.1.2.2 matt
43 1.1.2.2 matt struct x86emu_i8254_timer {
44 1.1.2.2 matt /* Tick when the counter was started, 0 if it is inactive */
45 1.1.2.2 matt uint64_t start_tick;
46 1.1.2.2 matt
47 1.1.2.2 matt /* GATE is raised */
48 1.1.2.2 matt bool gate_high;
49 1.1.2.2 matt
50 1.1.2.2 matt /* The initial value of the counter */
51 1.1.2.2 matt uint16_t active_counter;
52 1.1.2.2 matt
53 1.1.2.2 matt /* The current mode as bit pattern */
54 1.1.2.2 matt uint8_t active_mode;
55 1.1.2.2 matt
56 1.1.2.2 matt /* The current setting of the BCD flag */
57 1.1.2.2 matt bool active_is_bcd;
58 1.1.2.2 matt
59 1.1.2.2 matt /* Latched counter */
60 1.1.2.2 matt uint16_t latched_counter;
61 1.1.2.2 matt bool counter_is_latched;
62 1.1.2.2 matt
63 1.1.2.2 matt /* Latched status */
64 1.1.2.2 matt uint8_t latched_status;
65 1.1.2.2 matt bool status_is_latched;
66 1.1.2.2 matt
67 1.1.2.2 matt /* Read counter */
68 1.1.2.2 matt bool read_lsb, read_msb;
69 1.1.2.2 matt
70 1.1.2.2 matt /* Write counter */
71 1.1.2.2 matt uint8_t rw_status;
72 1.1.2.2 matt uint16_t new_counter;
73 1.1.2.2 matt uint8_t new_mode;
74 1.1.2.2 matt bool new_is_bcd;
75 1.1.2.2 matt bool null_count;
76 1.1.2.2 matt
77 1.1.2.2 matt bool write_lsb, write_msb;
78 1.1.2.2 matt };
79 1.1.2.2 matt
80 1.1.2.2 matt struct x86emu_i8254 {
81 1.1.2.2 matt struct x86emu_i8254_timer timer[3];
82 1.1.2.2 matt struct timespec base_time;
83 1.1.2.2 matt
84 1.1.2.2 matt void (*gettime)(struct timespec *);
85 1.1.2.2 matt };
86 1.1.2.2 matt
87 1.1.2.2 matt __BEGIN_DECLS
88 1.1.2.2 matt
89 1.1.2.2 matt void x86emu_i8254_init(struct x86emu_i8254 *, void (*)(struct timespec *));
90 1.1.2.2 matt uint8_t x86emu_i8254_inb(struct x86emu_i8254 *, uint16_t);
91 1.1.2.2 matt void x86emu_i8254_outb(struct x86emu_i8254 *, uint16_t, uint8_t);
92 1.1.2.2 matt bool x86emu_i8254_claim_port(struct x86emu_i8254 *, uint16_t);
93 1.1.2.2 matt
94 1.1.2.2 matt __END_DECLS
95 1.1.2.2 matt
96 1.1.2.2 matt #endif
97