114270Sgabeblack@google.com/* 214270Sgabeblack@google.com * Copyright 2019 Google, Inc. 314270Sgabeblack@google.com * 414270Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without 514270Sgabeblack@google.com * modification, are permitted provided that the following conditions are 614270Sgabeblack@google.com * met: redistributions of source code must retain the above copyright 714270Sgabeblack@google.com * notice, this list of conditions and the following disclaimer; 814270Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright 914270Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the 1014270Sgabeblack@google.com * documentation and/or other materials provided with the distribution; 1114270Sgabeblack@google.com * neither the name of the copyright holders nor the names of its 1214270Sgabeblack@google.com * contributors may be used to endorse or promote products derived from 1314270Sgabeblack@google.com * this software without specific prior written permission. 1414270Sgabeblack@google.com * 1514270Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 1614270Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 1714270Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 1814270Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 1914270Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 2014270Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 2114270Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 2214270Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 2314270Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 2414270Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 2514270Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 2614270Sgabeblack@google.com * 2714270Sgabeblack@google.com * Authors: Gabe Black 2814270Sgabeblack@google.com */ 2914270Sgabeblack@google.com 3014270Sgabeblack@google.com#ifndef __DEV_INTPIN_HH__ 3114270Sgabeblack@google.com#define __DEV_INTPIN_HH__ 3214270Sgabeblack@google.com 3314270Sgabeblack@google.com#include "sim/port.hh" 3414270Sgabeblack@google.com 3514270Sgabeblack@google.comclass IntSourcePinBase; 3614270Sgabeblack@google.com 3714270Sgabeblack@google.comclass IntSinkPinBase : public Port 3814270Sgabeblack@google.com{ 3914270Sgabeblack@google.com protected: 4014270Sgabeblack@google.com friend IntSourcePinBase; 4114270Sgabeblack@google.com 4214270Sgabeblack@google.com IntSourcePinBase *source = nullptr; 4314270Sgabeblack@google.com 4414270Sgabeblack@google.com int _number = 0; 4514270Sgabeblack@google.com bool _state = false; 4614270Sgabeblack@google.com 4714270Sgabeblack@google.com IntSinkPinBase(const std::string &_name, PortID _id, int num) : 4814270Sgabeblack@google.com Port(_name, _id), _number(num) 4914270Sgabeblack@google.com {} 5014270Sgabeblack@google.com 5114270Sgabeblack@google.com virtual void raiseOnDevice() = 0; 5214270Sgabeblack@google.com virtual void lowerOnDevice() = 0; 5314270Sgabeblack@google.com 5414270Sgabeblack@google.com void 5514270Sgabeblack@google.com raise() 5614270Sgabeblack@google.com { 5714270Sgabeblack@google.com _state = true; 5814270Sgabeblack@google.com raiseOnDevice(); 5914270Sgabeblack@google.com } 6014270Sgabeblack@google.com 6114270Sgabeblack@google.com void 6214270Sgabeblack@google.com lower() 6314270Sgabeblack@google.com { 6414270Sgabeblack@google.com _state = false; 6514270Sgabeblack@google.com lowerOnDevice(); 6614270Sgabeblack@google.com } 6714270Sgabeblack@google.com 6814270Sgabeblack@google.com public: 6914270Sgabeblack@google.com int number() { return _number; } 7014270Sgabeblack@google.com bool state() { return _state; } 7114270Sgabeblack@google.com 7214270Sgabeblack@google.com void bind(Port &peer) override; 7314270Sgabeblack@google.com void unbind() override; 7414270Sgabeblack@google.com}; 7514270Sgabeblack@google.com 7614270Sgabeblack@google.comtemplate <class Device> 7714270Sgabeblack@google.comclass IntSinkPin : public IntSinkPinBase 7814270Sgabeblack@google.com{ 7914270Sgabeblack@google.com private: 8014270Sgabeblack@google.com Device *device = nullptr; 8114270Sgabeblack@google.com 8214270Sgabeblack@google.com void raiseOnDevice() override { device->raiseInterruptPin(number()); } 8314270Sgabeblack@google.com void lowerOnDevice() override { device->lowerInterruptPin(number()); } 8414270Sgabeblack@google.com 8514270Sgabeblack@google.com public: 8614270Sgabeblack@google.com IntSinkPin(const std::string &_name, PortID _id, Device *dev, int num) : 8714270Sgabeblack@google.com IntSinkPinBase(_name, _id, num), device(dev) {} 8814270Sgabeblack@google.com IntSinkPin(const std::string &_name, PortID _id, Device *dev) : 8914270Sgabeblack@google.com IntSinkPin(_name, _id, dev, _id) {} 9014270Sgabeblack@google.com}; 9114270Sgabeblack@google.com 9214270Sgabeblack@google.comclass IntSourcePinBase : public Port 9314270Sgabeblack@google.com{ 9414270Sgabeblack@google.com private: 9514270Sgabeblack@google.com IntSinkPinBase *sink = nullptr; 9614270Sgabeblack@google.com bool _state = false; 9714270Sgabeblack@google.com 9814270Sgabeblack@google.com public: 9914270Sgabeblack@google.com IntSourcePinBase(const std::string &_name, PortID _id, bool def_state) : 10014270Sgabeblack@google.com Port(_name, _id), _state(def_state) 10114270Sgabeblack@google.com {} 10214270Sgabeblack@google.com 10314270Sgabeblack@google.com void raise() { sink->raise(); } 10414270Sgabeblack@google.com void lower() { sink->lower(); } 10514270Sgabeblack@google.com 10614270Sgabeblack@google.com void bind(Port &peer) override; 10714270Sgabeblack@google.com void unbind() override; 10814270Sgabeblack@google.com}; 10914270Sgabeblack@google.com 11014270Sgabeblack@google.comtemplate <class Device> 11114270Sgabeblack@google.comclass IntSourcePin : public IntSourcePinBase 11214270Sgabeblack@google.com{ 11314270Sgabeblack@google.com public: 11414270Sgabeblack@google.com IntSourcePin(const std::string &_name, PortID _id, Device *owner, 11514270Sgabeblack@google.com bool def_state=false) : 11614270Sgabeblack@google.com IntSourcePinBase(_name, _id, def_state) 11714270Sgabeblack@google.com {} 11814270Sgabeblack@google.com}; 11914270Sgabeblack@google.com 12014270Sgabeblack@google.com#endif //__DEV_INTPIN_HH__ 121