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