vmm_ioport.c revision 263744
1263035Stychon/*- 2263035Stychon * Copyright (c) 2014 Tycho Nightingale <tycho.nightingale@pluribusnetworks.com> 3263035Stychon * All rights reserved. 4263035Stychon * 5263035Stychon * Redistribution and use in source and binary forms, with or without 6263035Stychon * modification, are permitted provided that the following conditions 7263035Stychon * are met: 8263035Stychon * 1. Redistributions of source code must retain the above copyright 9263035Stychon * notice, this list of conditions and the following disclaimer. 10263035Stychon * 2. Redistributions in binary form must reproduce the above copyright 11263035Stychon * notice, this list of conditions and the following disclaimer in the 12263035Stychon * documentation and/or other materials provided with the distribution. 13263035Stychon * 14263035Stychon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND 15263035Stychon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16263035Stychon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17263035Stychon * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18263035Stychon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19263035Stychon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20263035Stychon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21263035Stychon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22263035Stychon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23263035Stychon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24263035Stychon * SUCH DAMAGE. 25263035Stychon */ 26263035Stychon 27263035Stychon#include <sys/cdefs.h> 28263035Stychon__FBSDID("$FreeBSD: head/sys/amd64/vmm/vmm_ioport.c 263744 2014-03-25 19:20:34Z tychon $"); 29263035Stychon 30263035Stychon#include <sys/param.h> 31263035Stychon#include <sys/types.h> 32263035Stychon#include <sys/queue.h> 33263035Stychon#include <sys/cpuset.h> 34263035Stychon#include <sys/systm.h> 35263035Stychon 36263035Stychon#include <machine/vmm.h> 37263035Stychon 38263035Stychon#include "vatpic.h" 39263744Stychon#include "vatpit.h" 40263035Stychon#include "vmm_ioport.h" 41263035Stychon 42263035Stychon#define MAX_IOPORTS 1280 43263035Stychon 44263035Stychonioport_handler_func_t ioport_handler[MAX_IOPORTS] = { 45263744Stychon [TIMER_MODE] = vatpit_handler, 46263744Stychon [TIMER_CNTR0] = vatpit_handler, 47263744Stychon [TIMER_CNTR1] = vatpit_handler, 48263744Stychon [TIMER_CNTR2] = vatpit_handler, 49263035Stychon [IO_ICU1] = vatpic_master_handler, 50263035Stychon [IO_ICU1 + ICU_IMR_OFFSET] = vatpic_master_handler, 51263035Stychon [IO_ICU2] = vatpic_slave_handler, 52263035Stychon [IO_ICU2 + ICU_IMR_OFFSET] = vatpic_slave_handler, 53263035Stychon [IO_ELCR1] = vatpic_elc_handler, 54263035Stychon [IO_ELCR2] = vatpic_elc_handler, 55263035Stychon}; 56263035Stychon 57263035Stychonint 58263035Stychonemulate_ioport(struct vm *vm, int vcpuid, struct vm_exit *vmexit) 59263035Stychon{ 60263035Stychon ioport_handler_func_t handler; 61263035Stychon 62263035Stychon if (vmexit->u.inout.port >= MAX_IOPORTS) 63263035Stychon return (-1); 64263035Stychon 65263035Stychon handler = ioport_handler[vmexit->u.inout.port]; 66263035Stychon if (handler == NULL) 67263035Stychon return (-1); 68263035Stychon 69263035Stychon return ((*handler)(vm, vcpuid, vmexit)); 70263035Stychon} 71