[BACK]Return to i8253.h CVS log [TXT][DIR] Up to [local] / src / usr.sbin / vmd

File: [local] / src / usr.sbin / vmd / i8253.h (download)

Revision 1.10, Thu Sep 1 22:01:40 2022 UTC (21 months, 1 week ago) by dv
Branch: MAIN
CVS Tags: OPENBSD_7_5_BASE, OPENBSD_7_5, OPENBSD_7_4_BASE, OPENBSD_7_4, OPENBSD_7_3_BASE, OPENBSD_7_3, OPENBSD_7_2_BASE, OPENBSD_7_2, HEAD
Changes since 1.9: +2 -1 lines

vmm(4): send all port io emulation to userland

Simplify things by sending any io exits from IN/OUT instructions
to userland instead of trying to emulate anything in the kernel.
vmm was sending most pertinent exits to vmd anyways, so this
functionally changes little.

An added benefit is this solves an issue reported by tb@ where i386
OpenBSD guests would probe for a pc keyboard repeatedly and cause
excessive vm exits. (The emulation in vmm was not properly handling
these port reads.)

While here, make the assignment of the VEI_DIR_{IN,OUT} enum values
not assume the underlying integer the compiler may assign.

ok mlarkin@

/* $OpenBSD: i8253.h,v 1.10 2022/09/01 22:01:40 dv Exp $ */
/*
 * Copyright (c) 2016 Mike Larkin <mlarkin@openbsd.org>
 *
 * Permission to use, copy, modify, and distribute this software for any
 * purpose with or without fee is hereby granted, provided that the above
 * copyright notice and this permission notice appear in all copies.
 *
 * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
 * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
 * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
 * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
 * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
 * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
 * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
 */

/*
 * Emulated i8253 PIT (counter)
 */
#define TIMER_BASE	0x40	/* 8253 timer 0 */
#define TIMER_CTRL	0x43	/* 8253 timer control */
#define NS_PER_TICK	(1000000000 / TIMER_FREQ)
#define TIMER_RB_COUNT	0x20	/* read back count value */
#define TIMER_RB_STATUS	0x10	/* read back status */
#define TIMER_RB_C0	0x2	/* read back channel 0 */
#define TIMER_RB_C1	0x4	/* read back channel 1 */
#define TIMER_RB_C2	0x8	/* read back channel 1 */
#define PCKBC_AUX	0x61	/* PC keyboard aux port for i8253 misc access */

/* i8253 registers */
struct i8253_channel {
	struct timespec ts;	/* timer start time */
	uint16_t start;		/* starting value */
	uint16_t olatch;	/* output latch */
	uint16_t ilatch;	/* input latch */
	uint8_t last_r;		/* last read byte (MSB/LSB) */
	uint8_t last_w;		/* last written byte (MSB/LSB) */
	uint8_t mode;		/* counter mode */
	uint8_t rbs;		/* channel is in readback status mode */
	struct event timer;	/* timer event for this counter */
	uint32_t vm_id;		/* owning VM id */
	int in_use;		/* denotes if this counter was ever used */
	uint8_t state;		/* 0 if channel is counting, 1 if fired */
};

void i8253_init(uint32_t);
void i8253_reset(uint8_t);
void i8253_fire(int, short, void *);
int i8253_dump(int);
int i8253_restore(int, uint32_t);
uint8_t vcpu_exit_i8253(struct vm_run_params *);
uint8_t vcpu_exit_i8253_misc(struct vm_run_params *);
void i8253_do_readback(uint32_t);
void i8253_stop(void);
void i8253_start(void);