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