RubyPort.hh revision 6876:a658c315512c
1 2/* 3 * Copyright (c) 2009 Advanced Micro Devices, Inc. 4 * All rights reserved. 5 * 6 * Redistribution and use in source and binary forms, with or without 7 * modification, are permitted provided that the following conditions are 8 * met: redistributions of source code must retain the above copyright 9 * notice, this list of conditions and the following disclaimer; 10 * redistributions in binary form must reproduce the above copyright 11 * notice, this list of conditions and the following disclaimer in the 12 * documentation and/or other materials provided with the distribution; 13 * neither the name of the copyright holders nor the names of its 14 * contributors may be used to endorse or promote products derived from 15 * this software without specific prior written permission. 16 * 17 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS 18 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT 19 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR 20 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT 21 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, 22 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT 23 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, 24 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY 25 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT 26 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 */ 29 30#ifndef RUBYPORT_H 31#define RUBYPORT_H 32 33#include "mem/ruby/libruby.hh" 34#include <string> 35#include <assert.h> 36 37#include "mem/mem_object.hh" 38#include "mem/tport.hh" 39 40#include "params/RubyPort.hh" 41 42using namespace std; 43 44class MessageBuffer; 45class AbstractController; 46 47class RubyPort : public MemObject { 48public: 49 typedef RubyPortParams Params; 50 RubyPort(const Params *p); 51 virtual ~RubyPort() {} 52 53 Port *getPort(const std::string &if_name, int idx); 54 55 virtual int64_t makeRequest(const RubyRequest & request) = 0; 56 57 void registerHitCallback(void (*hit_callback)(int64_t request_id)) { 58 assert(m_hit_callback == NULL); // can't assign hit_callback twice 59 m_hit_callback = hit_callback; 60 } 61 62protected: 63 const string m_name; 64 void (*m_hit_callback)(int64_t); 65 66 int64_t makeUniqueRequestID() { 67 // The request ID is generated by combining the port ID with a request count 68 // so that request IDs can be formed concurrently by multiple threads. 69 // IDs are formed as follows: 70 // 71 // 72 // 0 PortID Request Count 73 // +----+---------------+-----------------------------------------------------+ 74 // | 63 | 62-48 | 47-0 | 75 // +----+---------------+-----------------------------------------------------+ 76 // 77 // 78 // This limits the system to a maximum of 2^11 == 2048 components 79 // and 2^48 ~= 3x10^14 requests per component 80 81 int64_t id = (static_cast<uint64_t>(m_port_id) << 48) | m_request_cnt; 82 m_request_cnt++; 83 // assert((m_request_cnt & (1<<48)) == 0); 84 return id; 85 } 86 87 int m_version; 88 AbstractController* m_controller; 89 MessageBuffer* m_mandatory_q_ptr; 90 91private: 92 static uint16_t m_num_ports; 93 uint16_t m_port_id; 94 uint64_t m_request_cnt; 95}; 96 97#endif 98