console.hh revision 10389
11689SN/A/* 27598Sminkyu.jeong@arm.com * Copyright (c) 2014 ARM Limited 37598Sminkyu.jeong@arm.com * All rights reserved 47598Sminkyu.jeong@arm.com * 57598Sminkyu.jeong@arm.com * The license below extends only to copyright in the software and shall 67598Sminkyu.jeong@arm.com * not be construed as granting a license to any other intellectual 77598Sminkyu.jeong@arm.com * property including but not limited to intellectual property relating 87598Sminkyu.jeong@arm.com * to a hardware implementation of the functionality of the software 97598Sminkyu.jeong@arm.com * licensed hereunder. You may use the software subject to the license 107598Sminkyu.jeong@arm.com * terms below provided that you ensure that this notice is replicated 117598Sminkyu.jeong@arm.com * unmodified and in its entirety in all distributions of the software, 127598Sminkyu.jeong@arm.com * modified or unmodified, in source code or in binary form. 137598Sminkyu.jeong@arm.com * 142326SN/A * Redistribution and use in source and binary forms, with or without 151689SN/A * modification, are permitted provided that the following conditions are 161689SN/A * met: redistributions of source code must retain the above copyright 171689SN/A * notice, this list of conditions and the following disclaimer; 181689SN/A * redistributions in binary form must reproduce the above copyright 191689SN/A * notice, this list of conditions and the following disclaimer in the 201689SN/A * documentation and/or other materials provided with the distribution; 211689SN/A * neither the name of the copyright holders nor the names of its 221689SN/A * contributors may be used to endorse or promote products derived from 231689SN/A * this software without specific prior written permission. 241689SN/A * 251689SN/A * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 261689SN/A * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 271689SN/A * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 281689SN/A * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 291689SN/A * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 301689SN/A * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 311689SN/A * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 321689SN/A * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 331689SN/A * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 341689SN/A * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 351689SN/A * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 361689SN/A * 371689SN/A * Authors: Andreas Sandberg 381689SN/A */ 392665Ssaidi@eecs.umich.edu 402665Ssaidi@eecs.umich.edu#ifndef __DEV_VIRTIO_CONSOLE_HH__ 411689SN/A#define __DEV_VIRTIO_CONSOLE_HH__ 421689SN/A 431060SN/A#include "dev/virtio/base.hh" 441060SN/A#include "dev/terminal.hh" 451689SN/A 461060SN/Astruct VirtIOConsoleParams; 471060SN/A 481060SN/A/** 496658Snate@binkert.org * VirtIO console 502292SN/A * 511717SN/A * The VirtIO console uses the following queues: 528229Snate@binkert.org * -# Port0 receive (from host to guest) 535529Snate@binkert.org * -# Port0 transmit (from guest to host) 541060SN/A * -# Control receive (optional) 556221Snate@binkert.org * -# Control transmit (optional) 566221Snate@binkert.org * -# Port1 receive (optional) 571681SN/A * -# Port1 transmit (optional) 585529Snate@binkert.org * 592873Sktlim@umich.edu * This implementation implements the minimum of features for one 604329Sktlim@umich.edu * port, which means that the multiport feature is not announced and 614329Sktlim@umich.edu * only queue 0 and 1 are available. 624329Sktlim@umich.edu * 632292SN/A * @see https://github.com/rustyrussell/virtio-spec 642292SN/A * @see http://docs.oasis-open.org/virtio/virtio/v1.0/virtio-v1.0.html 652292SN/A */ 662292SN/Aclass VirtIOConsole : public VirtIODeviceBase 672820Sktlim@umich.edu{ 682292SN/A public: 692820Sktlim@umich.edu typedef VirtIOConsoleParams Params; 702820Sktlim@umich.edu VirtIOConsole(Params *params); 715529Snate@binkert.org virtual ~VirtIOConsole(); 722307SN/A 731060SN/A void readConfig(PacketPtr pkt, Addr cfgOffset); 742292SN/A 752292SN/A protected: 762292SN/A /** 771060SN/A * Console configuration structure 781060SN/A * 791060SN/A * @note This needs to be changed if the multiport feature is 801060SN/A * announced! 811060SN/A */ 821060SN/A struct Config { 831681SN/A uint16_t cols; 846221Snate@binkert.org uint16_t rows; 856221Snate@binkert.org } M5_ATTR_PACKED; 866221Snate@binkert.org 876221Snate@binkert.org /** Currently active configuration (host byte order) */ 882292SN/A Config config; 892292SN/A 902820Sktlim@umich.edu /** VirtIO device ID */ 912820Sktlim@umich.edu static const DeviceId ID_CONSOLE = 0x03; 922292SN/A 932292SN/A /** @{ 942820Sktlim@umich.edu * @name Feature bits 952820Sktlim@umich.edu */ 962292SN/A /** Provides the size information */ 972292SN/A static const FeatureBits F_SIZE = 0x01; 982292SN/A /** Supports the multi-port interface */ 992292SN/A static const FeatureBits F_MULTIPORT = 0x02; 1002292SN/A /** @} */ 1012292SN/A 1022292SN/A 1032292SN/A protected: 1041060SN/A /** 1051060SN/A * Virtqueue for data going from the host to the guest. 1061681SN/A */ 1071062SN/A class TermRecvQueue 1082292SN/A : public VirtQueue 1091062SN/A { 1102301SN/A public: 1112301SN/A TermRecvQueue(PortProxy &proxy, uint16_t size, VirtIOConsole &_parent) 1121062SN/A : VirtQueue(proxy, size), parent(_parent) {} 1132727Sktlim@umich.edu virtual ~TermRecvQueue() {} 1141062SN/A 1151062SN/A void onNotify() { trySend(); } 1161062SN/A 1171062SN/A /** Try to send data pending data from the terminal. */ 1181062SN/A void trySend(); 1191062SN/A 1201062SN/A std::string name() const { return parent.name() + ".qRecv"; } 1211062SN/A 1221062SN/A protected: 1231062SN/A VirtIOConsole &parent; 1241062SN/A }; 1251062SN/A /** Receive queue for port 0 */ 1261062SN/A TermRecvQueue qRecv; 1271062SN/A 1281062SN/A /** 1291062SN/A * Virtqueue for data going from the guest to the host. 1301062SN/A */ 1311062SN/A class TermTransQueue 1321062SN/A : public VirtQueue 1331062SN/A { 1341062SN/A public: 1351062SN/A TermTransQueue(PortProxy &proxy, uint16_t size, VirtIOConsole &_parent) 1361062SN/A : VirtQueue(proxy, size), parent(_parent) {} 1371062SN/A virtual ~TermTransQueue() {} 1381062SN/A 1391062SN/A void onNotifyDescriptor(VirtDescriptor *desc); 1401062SN/A 1411062SN/A std::string name() const { return parent.name() + ".qTrans"; } 1421062SN/A 1431062SN/A protected: 1441062SN/A VirtIOConsole &parent; 1451062SN/A }; 1461062SN/A /** Transmit queue for port 0 */ 1471062SN/A TermTransQueue qTrans; 1481062SN/A 1491062SN/A protected: 1501062SN/A Terminal &term; 1511062SN/A MakeCallback<VirtIOConsole::TermRecvQueue, 1521062SN/A &VirtIOConsole::TermRecvQueue::trySend> callbackDataAvail; 1531062SN/A}; 1541062SN/A 1552292SN/A#endif // __DEV_VIRTIO_CONSOLE_HH__ 1562292SN/A