atkbdc.c revision 268934
1264916Stychon/*- 2264916Stychon * Copyright (c) 2014 Tycho Nightingale <tycho.nightingale@pluribusnetworks.com> 3264916Stychon * All rights reserved. 4264916Stychon * 5264916Stychon * Redistribution and use in source and binary forms, with or without 6264916Stychon * modification, are permitted provided that the following conditions 7264916Stychon * are met: 8264916Stychon * 1. Redistributions of source code must retain the above copyright 9264916Stychon * notice, this list of conditions and the following disclaimer. 10264916Stychon * 2. Redistributions in binary form must reproduce the above copyright 11264916Stychon * notice, this list of conditions and the following disclaimer in the 12264916Stychon * documentation and/or other materials provided with the distribution. 13264916Stychon * 14264916Stychon * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND 15264916Stychon * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 16264916Stychon * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 17264916Stychon * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE 18264916Stychon * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 19264916Stychon * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 20264916Stychon * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 21264916Stychon * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 22264916Stychon * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 23264916Stychon * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 24264916Stychon * SUCH DAMAGE. 25264916Stychon */ 26264916Stychon 27264916Stychon#include <sys/cdefs.h> 28264916Stychon__FBSDID("$FreeBSD: stable/10/usr.sbin/bhyve/atkbdc.c 268934 2014-07-21 02:17:28Z jhb $"); 29264916Stychon 30264916Stychon#include <sys/types.h> 31264916Stychon 32264916Stychon#include <machine/vmm.h> 33264916Stychon 34264916Stychon#include <stdio.h> 35264916Stychon 36264916Stychon#include "inout.h" 37264916Stychon#include "pci_lpc.h" 38264916Stychon 39264916Stychon#define KBD_DATA_PORT 0x60 40264916Stychon 41264916Stychon#define KBD_STS_CTL_PORT 0x64 42268934Sjhb#define KBD_SYS_FLAG 0x4 43264916Stychon 44264916Stychon#define KBDC_RESET 0xfe 45264916Stychon 46264916Stychonstatic int 47264916Stychonatkbdc_data_handler(struct vmctx *ctx, int vcpu, int in, int port, int bytes, 48264916Stychon uint32_t *eax, void *arg) 49264916Stychon{ 50264916Stychon if (bytes != 1) 51264916Stychon return (INOUT_ERROR); 52264916Stychon 53264916Stychon *eax = 0; 54264916Stychon 55264916Stychon return (INOUT_OK); 56264916Stychon} 57264916Stychon 58264916Stychonstatic int 59264916Stychonatkbdc_sts_ctl_handler(struct vmctx *ctx, int vcpu, int in, int port, 60264916Stychon int bytes, uint32_t *eax, void *arg) 61264916Stychon{ 62264916Stychon int retval; 63264916Stychon 64264916Stychon if (bytes != 1) 65264916Stychon return (INOUT_ERROR); 66264916Stychon 67264916Stychon retval = INOUT_OK; 68264916Stychon if (in) { 69268934Sjhb *eax = KBD_SYS_FLAG; /* system passed POST */ 70264916Stychon } else { 71264916Stychon switch (*eax) { 72264916Stychon case KBDC_RESET: /* Pulse "reset" line. */ 73264916Stychon retval = INOUT_RESET; 74264916Stychon break; 75264916Stychon } 76264916Stychon } 77264916Stychon 78264916Stychon return (retval); 79264916Stychon} 80264916Stychon 81264916StychonINOUT_PORT(atkdbc, KBD_DATA_PORT, IOPORT_F_INOUT, atkbdc_data_handler); 82264916StychonSYSRES_IO(KBD_DATA_PORT, 1); 83264916StychonINOUT_PORT(atkbdc, KBD_STS_CTL_PORT, IOPORT_F_INOUT, 84264916Stychon atkbdc_sts_ctl_handler); 85264916StychonSYSRES_IO(KBD_STS_CTL_PORT, 1); 86