clock_domain.cc revision 10000
16145Snate@binkert.org/*
26145Snate@binkert.org * Copyright (c) 2013 ARM Limited
36145Snate@binkert.org * Copyright (c) 2013 Cornell University
46145Snate@binkert.org * All rights reserved
56145Snate@binkert.org *
66145Snate@binkert.org * The license below extends only to copyright in the software and shall
76145Snate@binkert.org * not be construed as granting a license to any other intellectual
86145Snate@binkert.org * property including but not limited to intellectual property relating
96145Snate@binkert.org * to a hardware implementation of the functionality of the software
106145Snate@binkert.org * licensed hereunder.  You may use the software subject to the license
116145Snate@binkert.org * terms below provided that you ensure that this notice is replicated
126145Snate@binkert.org * unmodified and in its entirety in all distributions of the software,
136145Snate@binkert.org * modified or unmodified, in source code or in binary form.
146145Snate@binkert.org *
156145Snate@binkert.org * Redistribution and use in source and binary forms, with or without
166145Snate@binkert.org * modification, are permitted provided that the following conditions are
176145Snate@binkert.org * met: redistributions of source code must retain the above copyright
186145Snate@binkert.org * notice, this list of conditions and the following disclaimer;
196145Snate@binkert.org * redistributions in binary form must reproduce the above copyright
206145Snate@binkert.org * notice, this list of conditions and the following disclaimer in the
216145Snate@binkert.org * documentation and/or other materials provided with the distribution;
226145Snate@binkert.org * neither the name of the copyright holders nor the names of its
236145Snate@binkert.org * contributors may be used to endorse or promote products derived from
246145Snate@binkert.org * this software without specific prior written permission.
256145Snate@binkert.org *
266145Snate@binkert.org * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
276145Snate@binkert.org * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
286145Snate@binkert.org * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
297039Snate@binkert.org * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
307039Snate@binkert.org * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
316145Snate@binkert.org * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
329208Snilay@cs.wisc.edu * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
339208Snilay@cs.wisc.edu * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
349181Spower.jg@gmail.com * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
357002Snate@binkert.org * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
367002Snate@binkert.org * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
377002Snate@binkert.org *
387039Snate@binkert.org * Authors: Vasileios Spiliopoulos
397039Snate@binkert.org *          Akash Bagdia
407039Snate@binkert.org *          Andreas Hansson
417039Snate@binkert.org *          Christopher Torng
427039Snate@binkert.org */
437039Snate@binkert.org
447039Snate@binkert.org#include "debug/ClockDomain.hh"
456145Snate@binkert.org#include "params/ClockDomain.hh"
468090Snilay@cs.wisc.edu#include "params/DerivedClockDomain.hh"
476285Snate@binkert.org#include "params/SrcClockDomain.hh"
487039Snate@binkert.org#include "sim/clock_domain.hh"
497039Snate@binkert.org#include "sim/voltage_domain.hh"
507039Snate@binkert.org#include "sim/clocked_object.hh"
517039Snate@binkert.org
527039Snate@binkert.orgdouble
536145Snate@binkert.orgClockDomain::voltage() const
547039Snate@binkert.org{
556285Snate@binkert.org    return _voltageDomain->voltage();
569208Snilay@cs.wisc.edu}
576145Snate@binkert.org
587039Snate@binkert.orgSrcClockDomain::SrcClockDomain(const Params *p) :
599208Snilay@cs.wisc.edu    ClockDomain(p, p->voltage_domain)
609208Snilay@cs.wisc.edu{
619208Snilay@cs.wisc.edu    clockPeriod(p->clock);
6210563Sandreas.hansson@arm.com}
637039Snate@binkert.org
647039Snate@binkert.orgvoid
657039Snate@binkert.orgSrcClockDomain::clockPeriod(Tick clock_period)
667039Snate@binkert.org{
677039Snate@binkert.org    if (clock_period == 0) {
687039Snate@binkert.org        fatal("%s has a clock period of zero\n", name());
699208Snilay@cs.wisc.edu    }
707039Snate@binkert.org
716145Snate@binkert.org    // Align all members to the current tick
726145Snate@binkert.org    for (auto m = members.begin(); m != members.end(); ++m) {
737039Snate@binkert.org        (*m)->updateClockPeriod();
749208Snilay@cs.wisc.edu    }
756285Snate@binkert.org
769181Spower.jg@gmail.com    _clockPeriod = clock_period;
777039Snate@binkert.org
787039Snate@binkert.org    DPRINTF(ClockDomain,
797039Snate@binkert.org            "Setting clock period to %d ticks for source clock %s\n",
807039Snate@binkert.org            _clockPeriod, name());
817039Snate@binkert.org
826285Snate@binkert.org    // inform any derived clocks they need to updated their period
836285Snate@binkert.org    for (auto c = children.begin(); c != children.end(); ++c) {
849208Snilay@cs.wisc.edu        (*c)->updateClockPeriod();
857039Snate@binkert.org    }
866285Snate@binkert.org}
877039Snate@binkert.org
886285Snate@binkert.orgSrcClockDomain *
896285Snate@binkert.orgSrcClockDomainParams::create()
907039Snate@binkert.org{
919208Snilay@cs.wisc.edu    return new SrcClockDomain(this);
926285Snate@binkert.org}
936285Snate@binkert.org
946285Snate@binkert.orgDerivedClockDomain::DerivedClockDomain(const Params *p) :
956285Snate@binkert.org    ClockDomain(p, p->clk_domain->voltageDomain()),
967039Snate@binkert.org    parent(*p->clk_domain),
977039Snate@binkert.org    clockDivider(p->clk_divider)
986285Snate@binkert.org{
997039Snate@binkert.org    // Ensure that clock divider setting works as frequency divider and never
1006285Snate@binkert.org    // work as frequency multiplier
1016145Snate@binkert.org    if (clockDivider < 1) {
1027039Snate@binkert.org       fatal("Clock divider param cannot be less than 1");
1037039Snate@binkert.org    }
1046145Snate@binkert.org
1057039Snate@binkert.org    // let the parent keep track of this derived domain so that it can
1067039Snate@binkert.org    // propagate changes
1077039Snate@binkert.org    parent.addDerivedDomain(this);
1086145Snate@binkert.org
1096145Snate@binkert.org    // update our clock period based on the parents clock
1107039Snate@binkert.org    updateClockPeriod();
1117039Snate@binkert.org}
1126145Snate@binkert.org
1137039Snate@binkert.orgvoid
1146145Snate@binkert.orgDerivedClockDomain::updateClockPeriod()
1156145Snate@binkert.org{
1167039Snate@binkert.org    // Align all members to the current tick
117    for (auto m = members.begin(); m != members.end(); ++m) {
118        (*m)->updateClockPeriod();
119    }
120
121    // recalculate the clock period, relying on the fact that changes
122    // propagate downwards in the tree
123    _clockPeriod = parent.clockPeriod() * clockDivider;
124
125    DPRINTF(ClockDomain,
126            "Setting clock period to %d ticks for derived clock %s\n",
127            _clockPeriod, name());
128
129    // inform any derived clocks
130    for (auto c = children.begin(); c != children.end(); ++c) {
131        (*c)->updateClockPeriod();
132    }
133}
134
135DerivedClockDomain *
136DerivedClockDomainParams::create()
137{
138    return new DerivedClockDomain(this);
139}
140