113206Sgabeblack@google.com/*
213206Sgabeblack@google.com * Copyright 2018 Google, Inc.
313206Sgabeblack@google.com *
413206Sgabeblack@google.com * Redistribution and use in source and binary forms, with or without
513206Sgabeblack@google.com * modification, are permitted provided that the following conditions are
613206Sgabeblack@google.com * met: redistributions of source code must retain the above copyright
713206Sgabeblack@google.com * notice, this list of conditions and the following disclaimer;
813206Sgabeblack@google.com * redistributions in binary form must reproduce the above copyright
913206Sgabeblack@google.com * notice, this list of conditions and the following disclaimer in the
1013206Sgabeblack@google.com * documentation and/or other materials provided with the distribution;
1113206Sgabeblack@google.com * neither the name of the copyright holders nor the names of its
1213206Sgabeblack@google.com * contributors may be used to endorse or promote products derived from
1313206Sgabeblack@google.com * this software without specific prior written permission.
1413206Sgabeblack@google.com *
1513206Sgabeblack@google.com * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
1613206Sgabeblack@google.com * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
1713206Sgabeblack@google.com * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
1813206Sgabeblack@google.com * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
1913206Sgabeblack@google.com * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
2013206Sgabeblack@google.com * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
2113206Sgabeblack@google.com * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
2213206Sgabeblack@google.com * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
2313206Sgabeblack@google.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
2413206Sgabeblack@google.com * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2513206Sgabeblack@google.com * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2613206Sgabeblack@google.com *
2713206Sgabeblack@google.com * Authors: Gabe Black
2813206Sgabeblack@google.com */
2913206Sgabeblack@google.com
3013206Sgabeblack@google.com#ifndef __SYSTEMC_CORE_SENSITIVITY_HH__
3113206Sgabeblack@google.com#define __SYSTEMC_CORE_SENSITIVITY_HH__
3213206Sgabeblack@google.com
3313206Sgabeblack@google.com#include <set>
3413206Sgabeblack@google.com#include <vector>
3513206Sgabeblack@google.com
3613206Sgabeblack@google.com#include "sim/eventq.hh"
3713206Sgabeblack@google.com#include "systemc/core/sched_event.hh"
3813206Sgabeblack@google.com#include "systemc/ext/core/sc_module.hh"
3913260Sgabeblack@google.com#include "systemc/ext/core/sc_port.hh"
4013206Sgabeblack@google.com
4113206Sgabeblack@google.comnamespace sc_core
4213206Sgabeblack@google.com{
4313206Sgabeblack@google.com
4413206Sgabeblack@google.comclass sc_event;
4513206Sgabeblack@google.comclass sc_event_and_list;
4613206Sgabeblack@google.comclass sc_event_or_list;
4713206Sgabeblack@google.comclass sc_event_finder;
4813206Sgabeblack@google.comclass sc_export_base;
4913206Sgabeblack@google.comclass sc_interface;
5013206Sgabeblack@google.comclass sc_port_base;
5113206Sgabeblack@google.com
5213206Sgabeblack@google.com} // namespace sc_core
5313206Sgabeblack@google.com
5413206Sgabeblack@google.comnamespace sc_gem5
5513206Sgabeblack@google.com{
5613206Sgabeblack@google.com
5713206Sgabeblack@google.comclass Process;
5813206Sgabeblack@google.comclass Event;
5913206Sgabeblack@google.com
6013206Sgabeblack@google.com/*
6113206Sgabeblack@google.com * Common sensitivity interface.
6213206Sgabeblack@google.com */
6313206Sgabeblack@google.com
6413206Sgabeblack@google.comclass Sensitivity
6513206Sgabeblack@google.com{
6613206Sgabeblack@google.com  protected:
6713206Sgabeblack@google.com    Process *process;
6813206Sgabeblack@google.com
6913206Sgabeblack@google.com    Sensitivity(Process *p) : process(p) {}
7013206Sgabeblack@google.com    virtual ~Sensitivity() {}
7113206Sgabeblack@google.com
7213206Sgabeblack@google.com    virtual void addToEvent(const ::sc_core::sc_event *e) = 0;
7313206Sgabeblack@google.com    virtual void delFromEvent(const ::sc_core::sc_event *e) = 0;
7413206Sgabeblack@google.com
7513206Sgabeblack@google.com  public:
7613206Sgabeblack@google.com    virtual void clear() = 0;
7713206Sgabeblack@google.com
7813206Sgabeblack@google.com    void satisfy();
7913304Sgabeblack@google.com    virtual bool notifyWork(Event *e);
8013304Sgabeblack@google.com    bool notify(Event *e);
8113206Sgabeblack@google.com
8213260Sgabeblack@google.com    enum Category
8313260Sgabeblack@google.com    {
8413260Sgabeblack@google.com        Static,
8513288Sgabeblack@google.com        Dynamic
8613260Sgabeblack@google.com    };
8713260Sgabeblack@google.com
8813260Sgabeblack@google.com    virtual Category category() = 0;
8913208Sgabeblack@google.com
9013208Sgabeblack@google.com    bool ofMethod();
9113206Sgabeblack@google.com};
9213206Sgabeblack@google.com
9313206Sgabeblack@google.com
9413206Sgabeblack@google.com/*
9513288Sgabeblack@google.com * Dynamic vs. static sensitivity.
9613206Sgabeblack@google.com */
9713206Sgabeblack@google.com
9813206Sgabeblack@google.comclass DynamicSensitivity : virtual public Sensitivity
9913206Sgabeblack@google.com{
10013206Sgabeblack@google.com  protected:
10113206Sgabeblack@google.com    DynamicSensitivity(Process *p) : Sensitivity(p) {}
10213206Sgabeblack@google.com
10313206Sgabeblack@google.com    void addToEvent(const ::sc_core::sc_event *e) override;
10413206Sgabeblack@google.com    void delFromEvent(const ::sc_core::sc_event *e) override;
10513206Sgabeblack@google.com
10613206Sgabeblack@google.com  public:
10713260Sgabeblack@google.com    Category category() override { return Dynamic; }
10813206Sgabeblack@google.com};
10913206Sgabeblack@google.com
11013206Sgabeblack@google.comtypedef std::vector<DynamicSensitivity *> DynamicSensitivities;
11113206Sgabeblack@google.com
11213206Sgabeblack@google.com
11313206Sgabeblack@google.comclass StaticSensitivity : virtual public Sensitivity
11413206Sgabeblack@google.com{
11513206Sgabeblack@google.com  protected:
11613206Sgabeblack@google.com    StaticSensitivity(Process *p) : Sensitivity(p) {}
11713206Sgabeblack@google.com
11813206Sgabeblack@google.com    void addToEvent(const ::sc_core::sc_event *e) override;
11913206Sgabeblack@google.com    void delFromEvent(const ::sc_core::sc_event *e) override;
12013206Sgabeblack@google.com
12113206Sgabeblack@google.com  public:
12213260Sgabeblack@google.com    Category category() override { return Static; }
12313206Sgabeblack@google.com};
12413206Sgabeblack@google.com
12513206Sgabeblack@google.comtypedef std::vector<StaticSensitivity *> StaticSensitivities;
12613206Sgabeblack@google.com
12713206Sgabeblack@google.com
12813206Sgabeblack@google.com/*
12913207Sgabeblack@google.com * Sensitivity to an event or events, which can be static or dynamic.
13013206Sgabeblack@google.com */
13113206Sgabeblack@google.com
13213206Sgabeblack@google.comclass SensitivityEvent : virtual public Sensitivity
13313206Sgabeblack@google.com{
13413206Sgabeblack@google.com  protected:
13513206Sgabeblack@google.com    const ::sc_core::sc_event *event;
13613206Sgabeblack@google.com
13713206Sgabeblack@google.com    SensitivityEvent(Process *p, const ::sc_core::sc_event *e=nullptr) :
13813206Sgabeblack@google.com        Sensitivity(p), event(e)
13913206Sgabeblack@google.com    {}
14013206Sgabeblack@google.com
14113206Sgabeblack@google.com  public:
14213206Sgabeblack@google.com    void clear() override { delFromEvent(event); }
14313206Sgabeblack@google.com};
14413206Sgabeblack@google.com
14513207Sgabeblack@google.comclass SensitivityEvents : virtual public Sensitivity
14613207Sgabeblack@google.com{
14713207Sgabeblack@google.com  protected:
14813207Sgabeblack@google.com    std::set<const ::sc_core::sc_event *> events;
14913207Sgabeblack@google.com
15013207Sgabeblack@google.com    SensitivityEvents(Process *p) : Sensitivity(p) {}
15113207Sgabeblack@google.com    SensitivityEvents(
15213207Sgabeblack@google.com            Process *p, const std::set<const ::sc_core::sc_event *> &s) :
15313207Sgabeblack@google.com        Sensitivity(p), events(s)
15413207Sgabeblack@google.com    {}
15513207Sgabeblack@google.com
15613207Sgabeblack@google.com  public:
15713207Sgabeblack@google.com    void
15813207Sgabeblack@google.com    clear() override
15913207Sgabeblack@google.com    {
16013207Sgabeblack@google.com        for (auto event: events)
16113207Sgabeblack@google.com            delFromEvent(event);
16213207Sgabeblack@google.com    }
16313207Sgabeblack@google.com
16413207Sgabeblack@google.com    void
16513207Sgabeblack@google.com    addEvent(const ::sc_core::sc_event *event)
16613207Sgabeblack@google.com    {
16713207Sgabeblack@google.com        events.insert(event);
16813207Sgabeblack@google.com        addToEvent(event);
16913207Sgabeblack@google.com    }
17013207Sgabeblack@google.com};
17113207Sgabeblack@google.com
17213206Sgabeblack@google.com
17313206Sgabeblack@google.com/*
17413206Sgabeblack@google.com * Static sensitivities.
17513206Sgabeblack@google.com */
17613206Sgabeblack@google.com
17713207Sgabeblack@google.comvoid newStaticSensitivityEvent(Process *p, const sc_core::sc_event *e);
17813207Sgabeblack@google.comvoid newStaticSensitivityInterface(Process *p, const sc_core::sc_interface *i);
17913207Sgabeblack@google.comvoid newStaticSensitivityPort(Process *p, const sc_core::sc_port_base *pb);
18013207Sgabeblack@google.comvoid newStaticSensitivityExport(
18113207Sgabeblack@google.com        Process *p, const sc_core::sc_export_base *exp);
18213207Sgabeblack@google.comvoid newStaticSensitivityFinder(
18313207Sgabeblack@google.com        Process *p, const sc_core::sc_event_finder *f);
18413207Sgabeblack@google.com
18513207Sgabeblack@google.com
18613206Sgabeblack@google.comclass StaticSensitivityEvent :
18713206Sgabeblack@google.com    public StaticSensitivity, public SensitivityEvent
18813206Sgabeblack@google.com{
18913207Sgabeblack@google.com    friend void newStaticSensitivityEvent(
19013207Sgabeblack@google.com            Process *p, const sc_core::sc_event *e);
19113207Sgabeblack@google.com
19213207Sgabeblack@google.com  protected:
19313206Sgabeblack@google.com    StaticSensitivityEvent(Process *p, const sc_core::sc_event *e) :
19413206Sgabeblack@google.com        Sensitivity(p), StaticSensitivity(p), SensitivityEvent(p, e)
19513206Sgabeblack@google.com    {}
19613206Sgabeblack@google.com};
19713206Sgabeblack@google.com
19813206Sgabeblack@google.comclass StaticSensitivityInterface :
19913206Sgabeblack@google.com    public StaticSensitivity, public SensitivityEvent
20013206Sgabeblack@google.com{
20113207Sgabeblack@google.com    friend void newStaticSensitivityInterface(
20213207Sgabeblack@google.com            Process *p, const sc_core::sc_interface *i);
20313207Sgabeblack@google.com  protected:
20413207Sgabeblack@google.com    StaticSensitivityInterface(Process *p, const sc_core::sc_interface *i);
20513206Sgabeblack@google.com};
20613206Sgabeblack@google.com
20713207Sgabeblack@google.comclass StaticSensitivityPort :
20813207Sgabeblack@google.com    public StaticSensitivity, public SensitivityEvents
20913206Sgabeblack@google.com{
21013207Sgabeblack@google.com    friend void newStaticSensitivityPort(
21113207Sgabeblack@google.com            Process *p, const sc_core::sc_port_base *pb);
21213206Sgabeblack@google.com
21313207Sgabeblack@google.com  protected:
21413207Sgabeblack@google.com    StaticSensitivityPort(Process *p) :
21513207Sgabeblack@google.com        Sensitivity(p), StaticSensitivity(p), SensitivityEvents(p)
21613206Sgabeblack@google.com    {}
21713206Sgabeblack@google.com};
21813206Sgabeblack@google.com
21913206Sgabeblack@google.comclass StaticSensitivityExport :
22013206Sgabeblack@google.com    public StaticSensitivity, public SensitivityEvent
22113206Sgabeblack@google.com{
22213206Sgabeblack@google.com  private:
22313207Sgabeblack@google.com    friend void newStaticSensitivityExport(
22413207Sgabeblack@google.com            Process *p, const sc_core::sc_export_base *exp);
22513207Sgabeblack@google.com
22613207Sgabeblack@google.com    StaticSensitivityExport(Process *p, const sc_core::sc_export_base *exp);
22713207Sgabeblack@google.com};
22813207Sgabeblack@google.com
22913207Sgabeblack@google.com
23013207Sgabeblack@google.comclass StaticSensitivityFinder :
23113207Sgabeblack@google.com    public StaticSensitivity, public SensitivityEvents
23213207Sgabeblack@google.com{
23313207Sgabeblack@google.com  private:
23413207Sgabeblack@google.com    const sc_core::sc_event_finder *finder;
23513207Sgabeblack@google.com
23613207Sgabeblack@google.com    friend void newStaticSensitivityFinder(
23713207Sgabeblack@google.com            Process *p, const sc_core::sc_event_finder *f);
23813207Sgabeblack@google.com
23913207Sgabeblack@google.com    StaticSensitivityFinder(Process *p, const sc_core::sc_event_finder *f) :
24013207Sgabeblack@google.com        Sensitivity(p), StaticSensitivity(p), SensitivityEvents(p), finder(f)
24113207Sgabeblack@google.com    {}
24213206Sgabeblack@google.com
24313206Sgabeblack@google.com  public:
24413207Sgabeblack@google.com    const ::sc_core::sc_event &find(::sc_core::sc_interface *i);
24513206Sgabeblack@google.com};
24613206Sgabeblack@google.com
24713206Sgabeblack@google.com
24813206Sgabeblack@google.com/*
24913206Sgabeblack@google.com * Dynamic sensitivities.
25013206Sgabeblack@google.com */
25113206Sgabeblack@google.com
25213207Sgabeblack@google.comvoid newDynamicSensitivityEvent(Process *p, const sc_core::sc_event *e);
25313207Sgabeblack@google.comvoid newDynamicSensitivityEventOrList(
25413207Sgabeblack@google.com        Process *p, const sc_core::sc_event_or_list *eol);
25513207Sgabeblack@google.comvoid newDynamicSensitivityEventAndList(
25613207Sgabeblack@google.com        Process *p, const sc_core::sc_event_and_list *eal);
25713207Sgabeblack@google.com
25813206Sgabeblack@google.comclass DynamicSensitivityEvent :
25913206Sgabeblack@google.com    public DynamicSensitivity, public SensitivityEvent
26013206Sgabeblack@google.com{
26113207Sgabeblack@google.com  private:
26213207Sgabeblack@google.com    friend void newDynamicSensitivityEvent(
26313207Sgabeblack@google.com            Process *p, const sc_core::sc_event *e);
26413207Sgabeblack@google.com
26513206Sgabeblack@google.com    DynamicSensitivityEvent(Process *p, const sc_core::sc_event *e) :
26613206Sgabeblack@google.com        Sensitivity(p), DynamicSensitivity(p), SensitivityEvent(p, e)
26713206Sgabeblack@google.com    {}
26813206Sgabeblack@google.com};
26913206Sgabeblack@google.com
27013207Sgabeblack@google.comclass DynamicSensitivityEventOrList :
27113207Sgabeblack@google.com    public DynamicSensitivity, public SensitivityEvents
27213206Sgabeblack@google.com{
27313206Sgabeblack@google.com  private:
27413207Sgabeblack@google.com    friend void newDynamicSensitivityEventOrList(
27513207Sgabeblack@google.com            Process *p, const sc_core::sc_event_or_list *eol);
27613206Sgabeblack@google.com
27713206Sgabeblack@google.com    DynamicSensitivityEventOrList(
27813206Sgabeblack@google.com            Process *p, const sc_core::sc_event_or_list *eol);
27913206Sgabeblack@google.com
28013304Sgabeblack@google.com    bool notifyWork(Event *e) override;
28113206Sgabeblack@google.com};
28213206Sgabeblack@google.com
28313206Sgabeblack@google.com//XXX This sensitivity can't be reused. To reset it, it has to be deleted and
28413206Sgabeblack@google.com//recreated. That works for dynamic sensitivities, but not for static.
28513206Sgabeblack@google.com//Fortunately processes can't be statically sensitive to sc_event_and_lists.
28613207Sgabeblack@google.comclass DynamicSensitivityEventAndList :
28713207Sgabeblack@google.com    public DynamicSensitivity, public SensitivityEvents
28813206Sgabeblack@google.com{
28913206Sgabeblack@google.com  private:
29013207Sgabeblack@google.com    friend void newDynamicSensitivityEventAndList(
29113207Sgabeblack@google.com            Process *p, const sc_core::sc_event_and_list *eal);
29213206Sgabeblack@google.com
29313206Sgabeblack@google.com    DynamicSensitivityEventAndList(
29413206Sgabeblack@google.com            Process *p, const sc_core::sc_event_and_list *eal);
29513206Sgabeblack@google.com
29613304Sgabeblack@google.com    bool notifyWork(Event *e) override;
29713206Sgabeblack@google.com};
29813206Sgabeblack@google.com
29913206Sgabeblack@google.com} // namespace sc_gem5
30013206Sgabeblack@google.com
30113206Sgabeblack@google.com#endif  //__SYSTEMC_CORE_SENSITIVITY_HH__
302