tport.cc revision 3284:917750443a75
1/*
2 * Copyright (c) 2006 The Regents of The University of Michigan
3 * All rights reserved.
4 *
5 * Redistribution and use in source and binary forms, with or without
6 * modification, are permitted provided that the following conditions are
7 * met: redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer;
9 * redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution;
12 * neither the name of the copyright holders nor the names of its
13 * contributors may be used to endorse or promote products derived from
14 * this software without specific prior written permission.
15 *
16 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
17 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
18 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
19 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
20 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
21 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
22 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
23 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
24 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
25 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
26 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
27 *
28 * Authors: Ali Saidi
29 */
30
31#include "mem/tport.hh"
32
33void
34SimpleTimingPort::recvFunctional(Packet *pkt)
35{
36    //First check queued events
37    std::list<Packet *>::iterator i = transmitList.begin();
38    std::list<Packet *>::iterator end = transmitList.end();
39    for (; i != end; ++i) {
40        Packet * target = *i;
41        // If the target contains data, and it overlaps the
42        // probed request, need to update data
43        if (target->intersect(pkt)) {
44            uint8_t* pkt_data;
45            uint8_t* write_data;
46            int data_size;
47            if (target->getAddr() < pkt->getAddr()) {
48                int offset = pkt->getAddr() - target->getAddr();
49                            pkt_data = pkt->getPtr<uint8_t>();
50                            write_data = target->getPtr<uint8_t>() + offset;
51                            data_size = target->getSize() - offset;
52                            assert(data_size > 0);
53                            if (data_size > pkt->getSize())
54                                data_size = pkt->getSize();
55            } else {
56                int offset = target->getAddr() - pkt->getAddr();
57                pkt_data = pkt->getPtr<uint8_t>() + offset;
58                write_data = target->getPtr<uint8_t>();
59                data_size = pkt->getSize() - offset;
60                assert(data_size > pkt->getSize());
61                if (data_size > target->getSize())
62                    data_size = target->getSize();
63            }
64
65            if (pkt->isWrite()) {
66                memcpy(pkt_data, write_data, data_size);
67            } else {
68                memcpy(write_data, pkt_data, data_size);
69            }
70        }
71    }
72    //Then just do an atomic access and throw away the returned latency
73    recvAtomic(pkt);
74}
75
76bool
77SimpleTimingPort::recvTiming(Packet *pkt)
78{
79    // If the device is only a slave, it should only be sending
80    // responses, which should never get nacked.  There used to be
81    // code to hanldle nacks here, but I'm pretty sure it didn't work
82    // correctly with the drain code, so that would need to be fixed
83    // if we ever added it back.
84    assert(pkt->result != Packet::Nacked);
85    Tick latency = recvAtomic(pkt);
86    // turn packet around to go back to requester if response expected
87    if (pkt->needsResponse()) {
88        pkt->makeTimingResponse();
89        sendTimingLater(pkt, latency);
90    }
91    return true;
92}
93
94void
95SimpleTimingPort::recvRetry()
96{
97    assert(outTiming > 0);
98    assert(!transmitList.empty());
99    if (sendTiming(transmitList.front())) {
100        transmitList.pop_front();
101        outTiming--;
102        DPRINTF(Bus, "No Longer waiting on retry\n");
103        if (!transmitList.empty())
104            sendTimingLater(transmitList.front(), 1);
105    }
106
107    if (transmitList.empty() && drainEvent) {
108        drainEvent->process();
109        drainEvent = NULL;
110    }
111}
112
113void
114SimpleTimingPort::SendEvent::process()
115{
116    assert(port->outTiming > 0);
117    if (!port->transmitList.empty() && port->transmitList.front() != packet) {
118        //We are not the head of the list
119        port->transmitList.push_back(packet);
120    } else if (port->sendTiming(packet)) {
121        // send successful
122        if (port->transmitList.size()) {
123            port->transmitList.pop_front();
124            port->outTiming--;
125           if (!port->transmitList.empty())
126                port->sendTimingLater(port->transmitList.front(), 1);
127        }
128        if (port->transmitList.empty() && port->drainEvent) {
129            port->drainEvent->process();
130            port->drainEvent = NULL;
131        }
132    } else {
133        // send unsuccessful (due to flow control).  Will get retry
134        // callback later; save for then if not already
135        DPRINTF(Bus, "Waiting on retry\n");
136        if (!(port->transmitList.front() == packet))
137            port->transmitList.push_back(packet);
138    }
139}
140
141
142unsigned int
143SimpleTimingPort::drain(Event *de)
144{
145    if (outTiming == 0 && transmitList.size() == 0)
146        return 0;
147    drainEvent = de;
148    return 1;
149}
150