1 /* $OpenBSD: i8253.h,v 1.9 2018/04/26 17:10:10 mlarkin Exp $ */ 2 /* 3 * Copyright (c) 2016 Mike Larkin <mlarkin@openbsd.org> 4 * 5 * Permission to use, copy, modify, and distribute this software for any 6 * purpose with or without fee is hereby granted, provided that the above 7 * copyright notice and this permission notice appear in all copies. 8 * 9 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES 10 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF 11 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR 12 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES 13 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN 14 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF 15 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. 16 */ 17 18 /* 19 * Emulated i8253 PIT (counter) 20 */ 21 #define TIMER_BASE 0x40 /* 8253 timer 0 */ 22 #define TIMER_CTRL 0x43 /* 8253 timer control */ 23 #define NS_PER_TICK (1000000000 / TIMER_FREQ) 24 #define TIMER_RB_COUNT 0x20 /* read back count value */ 25 #define TIMER_RB_STATUS 0x10 /* read back status */ 26 #define TIMER_RB_C0 0x2 /* read back channel 0 */ 27 #define TIMER_RB_C1 0x4 /* read back channel 1 */ 28 #define TIMER_RB_C2 0x8 /* read back channel 1 */ 29 30 /* i8253 registers */ 31 struct i8253_channel { 32 struct timespec ts; /* timer start time */ 33 uint16_t start; /* starting value */ 34 uint16_t olatch; /* output latch */ 35 uint16_t ilatch; /* input latch */ 36 uint8_t last_r; /* last read byte (MSB/LSB) */ 37 uint8_t last_w; /* last written byte (MSB/LSB) */ 38 uint8_t mode; /* counter mode */ 39 uint8_t rbs; /* channel is in readback status mode */ 40 struct event timer; /* timer event for this counter */ 41 uint32_t vm_id; /* owning VM id */ 42 int in_use; /* denotes if this counter was ever used */ 43 uint8_t state; /* 0 if channel is counting, 1 if fired */ 44 }; 45 46 void i8253_init(uint32_t); 47 void i8253_reset(uint8_t); 48 void i8253_fire(int, short, void *); 49 int i8253_dump(int); 50 int i8253_restore(int, uint32_t); 51 uint8_t vcpu_exit_i8253(struct vm_run_params *); 52 uint8_t vcpu_exit_i8253_misc(struct vm_run_params *); 53 void i8253_do_readback(uint32_t); 54 void i8253_stop(void); 55 void i8253_start(void); 56