etherbus.hh revision 4981
111247Sradhika.jagtap@ARM.com/*
211247Sradhika.jagtap@ARM.com * Copyright (c) 2002-2005 The Regents of The University of Michigan
311247Sradhika.jagtap@ARM.com * All rights reserved.
411247Sradhika.jagtap@ARM.com *
511247Sradhika.jagtap@ARM.com * Redistribution and use in source and binary forms, with or without
611247Sradhika.jagtap@ARM.com * modification, are permitted provided that the following conditions are
711247Sradhika.jagtap@ARM.com * met: redistributions of source code must retain the above copyright
811247Sradhika.jagtap@ARM.com * notice, this list of conditions and the following disclaimer;
911247Sradhika.jagtap@ARM.com * redistributions in binary form must reproduce the above copyright
1011247Sradhika.jagtap@ARM.com * notice, this list of conditions and the following disclaimer in the
1111247Sradhika.jagtap@ARM.com * documentation and/or other materials provided with the distribution;
1211247Sradhika.jagtap@ARM.com * neither the name of the copyright holders nor the names of its
1311247Sradhika.jagtap@ARM.com * contributors may be used to endorse or promote products derived from
1411247Sradhika.jagtap@ARM.com * this software without specific prior written permission.
1511247Sradhika.jagtap@ARM.com *
1611247Sradhika.jagtap@ARM.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1711247Sradhika.jagtap@ARM.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1811247Sradhika.jagtap@ARM.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1911247Sradhika.jagtap@ARM.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
2011247Sradhika.jagtap@ARM.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2111247Sradhika.jagtap@ARM.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2211247Sradhika.jagtap@ARM.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2311247Sradhika.jagtap@ARM.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2411247Sradhika.jagtap@ARM.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2511247Sradhika.jagtap@ARM.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2611247Sradhika.jagtap@ARM.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2711247Sradhika.jagtap@ARM.com *
2811247Sradhika.jagtap@ARM.com * Authors: Nathan Binkert
2911247Sradhika.jagtap@ARM.com */
3011247Sradhika.jagtap@ARM.com
3111247Sradhika.jagtap@ARM.com/* @file
3211247Sradhika.jagtap@ARM.com * Device module for modelling an ethernet hub
3311247Sradhika.jagtap@ARM.com */
3411247Sradhika.jagtap@ARM.com
3511247Sradhika.jagtap@ARM.com#ifndef __ETHERBUS_H__
3611247Sradhika.jagtap@ARM.com#define __ETHERBUS_H__
3711247Sradhika.jagtap@ARM.com
3811247Sradhika.jagtap@ARM.com#include "sim/eventq.hh"
3911247Sradhika.jagtap@ARM.com#include "dev/etherpkt.hh"
4011247Sradhika.jagtap@ARM.com#include "dev/etherobject.hh"
4111247Sradhika.jagtap@ARM.com#include "params/EtherBus.hh"
4211247Sradhika.jagtap@ARM.com#include "sim/sim_object.hh"
4311247Sradhika.jagtap@ARM.com
4411247Sradhika.jagtap@ARM.comclass EtherDump;
4511247Sradhika.jagtap@ARM.comclass EtherInt;
4611247Sradhika.jagtap@ARM.comclass EtherBus : public EtherObject
4711247Sradhika.jagtap@ARM.com{
4811247Sradhika.jagtap@ARM.com  protected:
4911247Sradhika.jagtap@ARM.com    typedef std::list<EtherInt *> devlist_t;
5011247Sradhika.jagtap@ARM.com    devlist_t devlist;
5111247Sradhika.jagtap@ARM.com    double ticksPerByte;
5211247Sradhika.jagtap@ARM.com    bool loopback;
5311247Sradhika.jagtap@ARM.com
5411247Sradhika.jagtap@ARM.com  protected:
5511247Sradhika.jagtap@ARM.com    class DoneEvent : public Event
5611247Sradhika.jagtap@ARM.com    {
5711247Sradhika.jagtap@ARM.com      protected:
5811247Sradhika.jagtap@ARM.com        EtherBus *bus;
5911247Sradhika.jagtap@ARM.com
6011247Sradhika.jagtap@ARM.com      public:
6111247Sradhika.jagtap@ARM.com        DoneEvent(EventQueue *q, EtherBus *b)
6211247Sradhika.jagtap@ARM.com            : Event(q), bus(b) {}
6311247Sradhika.jagtap@ARM.com        virtual void process() { bus->txDone(); }
6411247Sradhika.jagtap@ARM.com        virtual const char *description() { return "ethernet bus completion"; }
6511247Sradhika.jagtap@ARM.com    };
6611247Sradhika.jagtap@ARM.com
6711247Sradhika.jagtap@ARM.com    DoneEvent event;
6811247Sradhika.jagtap@ARM.com    EthPacketPtr packet;
6911247Sradhika.jagtap@ARM.com    EtherInt *sender;
7011247Sradhika.jagtap@ARM.com    EtherDump *dump;
7111247Sradhika.jagtap@ARM.com
7211247Sradhika.jagtap@ARM.com  public:
7311247Sradhika.jagtap@ARM.com    typedef EtherBusParams Params;
7411247Sradhika.jagtap@ARM.com    EtherBus(const Params *p);
7511247Sradhika.jagtap@ARM.com    virtual ~EtherBus() {}
7611247Sradhika.jagtap@ARM.com
7711247Sradhika.jagtap@ARM.com    const Params *
7811247Sradhika.jagtap@ARM.com    params() const
7911247Sradhika.jagtap@ARM.com    {
8011247Sradhika.jagtap@ARM.com        return dynamic_cast<const Params *>(_params);
8111247Sradhika.jagtap@ARM.com    }
8211247Sradhika.jagtap@ARM.com
8311247Sradhika.jagtap@ARM.com    void txDone();
8411247Sradhika.jagtap@ARM.com    void reg(EtherInt *dev);
8511247Sradhika.jagtap@ARM.com    bool busy() const { return (bool)packet; }
8611247Sradhika.jagtap@ARM.com    bool send(EtherInt *sender, EthPacketPtr &packet);
8711247Sradhika.jagtap@ARM.com    virtual EtherInt *getEthPort(const std::string &if_name, int idx);
8811247Sradhika.jagtap@ARM.com};
8911247Sradhika.jagtap@ARM.com
9011247Sradhika.jagtap@ARM.com#endif // __ETHERBUS_H__
9111247Sradhika.jagtap@ARM.com