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

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

Revision 1.5, Thu Sep 1 22:01:40 2022 UTC (21 months 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
Changes since 1.4: +6 -3 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: i8259.h,v 1.5 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.
 */

#include <sys/types.h>

#include <machine/vmmvar.h>

#define MASTER			0
#define SLAVE			1

#define ELCR0			0x4D0
#define ELCR1			0x4D1

#define ICW1_ICW4		(0x1 << 0)
#define ICW1_SNGL		(0x1 << 1)
#define ICW1_ADI		(0x1 << 2)
#define ICW1_LTIM		(0x1 << 3)
#define ICW1_INIT		(0x1 << 4)
#define ICW1_IVA1		(0x1 << 5)
#define ICW1_IVA2		(0x1 << 6)
#define ICW1_IVA3		(0x1 << 7)
#define ICW4_UP			(0x1 << 0)
#define ICW4_AEOI		(0x1 << 1)
#define ICW4_MS			(0x1 << 2)
#define ICW4_BUF		(0x1 << 3)
#define ICW4_SNFM		(0x1 << 4)

#define OCW_SELECT		(0x1 << 3)

#define OCW2_ROTATE_AEOI_CLEAR	0x00
#define OCW2_EOI		0x20
#define OCW2_NOP		0x40
#define OCW2_SEOI		0x60
#define OCW2_ROTATE_AEOI_SET	0x80
#define OCW2_ROTATE_NSEOI	0xA0
#define OCW2_SET_LOWPRIO	0xC0
#define OCW2_ROTATE_SEOI	0xE0
#define OCW3_RIS		(0x1 << 0)
#define OCW3_RR			(0x1 << 1)
#define OCW3_POLL		(0x1 << 2)
#define OCW3_ACTION		(0x1 << 3)
#define OCW3_SMM		(0x1 << 5)
#define OCW3_SMACTION		(0x1 << 6)

/* PIC functions called by device emulation code */
void i8259_assert_irq(uint8_t);
void i8259_deassert_irq(uint8_t);

/* PIC functions called by vcpu run loop code */
int i8259_get_next_irq(uint8_t *);

/* PIC functions called by the in/out exit handler */
uint8_t vcpu_exit_i8259(struct vm_run_params *);

void i8259_init(void);
uint16_t i8259_ack(void);
uint8_t i8259_is_pending(void);
int i8259_restore(int);
int i8259_dump(int);

/* ELCR functions */
void pic_set_elcr(uint8_t, uint8_t);
uint8_t vcpu_exit_elcr(struct vm_run_params *);