console.cc revision 12237
14126SN/A/* 28295Snate@binkert.org * Copyright (c) 2014 ARM Limited 34126SN/A * All rights reserved 44126SN/A * 54126SN/A * The license below extends only to copyright in the software and shall 64126SN/A * not be construed as granting a license to any other intellectual 74126SN/A * property including but not limited to intellectual property relating 84126SN/A * to a hardware implementation of the functionality of the software 94126SN/A * licensed hereunder. You may use the software subject to the license 104126SN/A * terms below provided that you ensure that this notice is replicated 114126SN/A * unmodified and in its entirety in all distributions of the software, 124126SN/A * modified or unmodified, in source code or in binary form. 134126SN/A * 144126SN/A * Redistribution and use in source and binary forms, with or without 154126SN/A * modification, are permitted provided that the following conditions are 164126SN/A * met: redistributions of source code must retain the above copyright 174126SN/A * notice, this list of conditions and the following disclaimer; 184126SN/A * redistributions in binary form must reproduce the above copyright 194126SN/A * notice, this list of conditions and the following disclaimer in the 204126SN/A * documentation and/or other materials provided with the distribution; 214126SN/A * neither the name of the copyright holders nor the names of its 224126SN/A * contributors may be used to endorse or promote products derived from 234126SN/A * this software without specific prior written permission. 244126SN/A * 254126SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 264126SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 274126SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 284126SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 294126SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 308296Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 318296Snate@binkert.org * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 3211802Sandreas.sandberg@arm.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 338295Snate@binkert.org * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 348296Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 354126SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 3611766Sandreas.sandberg@arm.com * 3711802Sandreas.sandberg@arm.com * Authors: Andreas Sandberg 3811802Sandreas.sandberg@arm.com */ 3911766Sandreas.sandberg@arm.com 408296Snate@binkert.org#include "dev/virtio/console.hh" 416126SN/A 4211802Sandreas.sandberg@arm.com#include "debug/VIOConsole.hh" 438296Snate@binkert.org#include "params/VirtIOConsole.hh" 444126SN/A#include "sim/system.hh" 456001SN/A 4611802Sandreas.sandberg@arm.comVirtIOConsole::VirtIOConsole(Params *params) 4711802Sandreas.sandberg@arm.com : VirtIODeviceBase(params, ID_CONSOLE, sizeof(Config), F_SIZE), 486001SN/A qRecv(params->system->physProxy, params->qRecvSize, *this), 498295Snate@binkert.org qTrans(params->system->physProxy, params->qTransSize, *this), 508295Snate@binkert.org device(*params->device), callbackDataAvail(qRecv) 518295Snate@binkert.org{ 526001SN/A registerQueue(qRecv); 538295Snate@binkert.org registerQueue(qTrans); 548295Snate@binkert.org 558295Snate@binkert.org config.cols = 80; 568295Snate@binkert.org config.rows = 24; 5711788Sandreas.sandberg@arm.com 5811802Sandreas.sandberg@arm.com device.regInterfaceCallback(&callbackDataAvail); 598295Snate@binkert.org} 608296Snate@binkert.org 618296Snate@binkert.org 6210169SCurtis.Dunham@arm.comVirtIOConsole::~VirtIOConsole() 6310169SCurtis.Dunham@arm.com{ 648296Snate@binkert.org} 658296Snate@binkert.orgvoid 668296Snate@binkert.orgVirtIOConsole::readConfig(PacketPtr pkt, Addr cfgOffset) 678296Snate@binkert.org{ 688295Snate@binkert.org Config cfg_out; 698295Snate@binkert.org cfg_out.rows = htov_legacy(config.rows); 708295Snate@binkert.org cfg_out.cols = htov_legacy(config.cols); 718295Snate@binkert.org 728295Snate@binkert.org readConfigBlob(pkt, cfgOffset, (uint8_t *)&cfg_out); 738295Snate@binkert.org} 748295Snate@binkert.org 758295Snate@binkert.orgvoid 768296Snate@binkert.orgVirtIOConsole::TermRecvQueue::trySend() 778295Snate@binkert.org{ 7811802Sandreas.sandberg@arm.com DPRINTF(VIOConsole, "trySend\n"); 798986SAli.Saidi@ARM.com 808296Snate@binkert.org // Send data as long as the terminal has outgoing data and we can 818296Snate@binkert.org // get free descriptors (i.e., there are buffers available to 828296Snate@binkert.org // send) from the guest. 836001SN/A VirtDescriptor *d; 848296Snate@binkert.org while (parent.device.dataAvailable() && (d = consumeDescriptor())) { 858296Snate@binkert.org DPRINTF(VIOConsole, "Got descriptor (len: %i)\n", d->size()); 868296Snate@binkert.org size_t len(0); 878296Snate@binkert.org while (parent.device.dataAvailable() && len < d->size()) { 886001SN/A uint8_t in(parent.device.readData()); 898296Snate@binkert.org d->chainWrite(len, &in, sizeof(uint8_t)); 906001SN/A ++len; 918296Snate@binkert.org } 928296Snate@binkert.org 938296Snate@binkert.org // Tell the guest that we are done with this descriptor. 948296Snate@binkert.org produceDescriptor(d, len); 958296Snate@binkert.org parent.kick(); 968296Snate@binkert.org } 978296Snate@binkert.org} 988296Snate@binkert.org 9911802Sandreas.sandberg@arm.comvoid 1009042SMitchell.Hayenga@ARM.comVirtIOConsole::TermTransQueue::onNotifyDescriptor(VirtDescriptor *desc) 1018296Snate@binkert.org{ 1028296Snate@binkert.org DPRINTF(VIOConsole, "Got input data descriptor (len: %i)\n", 1038296Snate@binkert.org desc->size()); 1048296Snate@binkert.org 1058296Snate@binkert.org // Copy the data from the guest and forward it to the 1068296Snate@binkert.org // terminal. 10711788Sandreas.sandberg@arm.com const size_t size(desc->chainSize()); 1088296Snate@binkert.org uint8_t data[size]; 1096001SN/A desc->chainRead(0, data, size); 1106001SN/A for (int i = 0; i < desc->size(); ++i) 1118296Snate@binkert.org parent.device.writeData(data[i]); 1128296Snate@binkert.org 1137527SN/A // Tell the guest that we are done with this descriptor. 1147527SN/A produceDescriptor(desc, 0); 1157802SN/A parent.kick(); 1167802SN/A} 1177802SN/A 1187527SN/AVirtIOConsole * 1198296Snate@binkert.orgVirtIOConsoleParams::create() 1208296Snate@binkert.org{ 1218296Snate@binkert.org return new VirtIOConsole(this); 12211802Sandreas.sandberg@arm.com} 1238295Snate@binkert.org