| 1 | // ========== Copyright Header Begin ========================================== |
| 2 | // |
| 3 | // OpenSPARC T2 Processor File: sam_rtlif.cpp |
| 4 | // Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved |
| 5 | // 4150 Network Circle, Santa Clara, California 95054, U.S.A. |
| 6 | // |
| 7 | // * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 8 | // |
| 9 | // This program is free software; you can redistribute it and/or modify |
| 10 | // it under the terms of the GNU General Public License as published by |
| 11 | // the Free Software Foundation; version 2 of the License. |
| 12 | // |
| 13 | // This program is distributed in the hope that it will be useful, |
| 14 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 15 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 16 | // GNU General Public License for more details. |
| 17 | // |
| 18 | // You should have received a copy of the GNU General Public License |
| 19 | // along with this program; if not, write to the Free Software |
| 20 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 21 | // |
| 22 | // For the avoidance of doubt, and except that if any non-GPL license |
| 23 | // choice is available it will apply instead, Sun elects to use only |
| 24 | // the General Public License version 2 (GPLv2) at this time for any |
| 25 | // software where a choice of GPL license versions is made |
| 26 | // available with the language indicating that GPLv2 or any later version |
| 27 | // may be used, or where a choice of which version of the GPL is applied is |
| 28 | // otherwise unspecified. |
| 29 | // |
| 30 | // Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 31 | // CA 95054 USA or visit www.sun.com if you need additional information or |
| 32 | // have any questions. |
| 33 | // |
| 34 | // ========== Copyright Header End ============================================ |
| 35 | // ========== Copyright Header Begin ========================================== |
| 36 | // |
| 37 | // OpenSPARC T2 Processor File: sam_rtlif.cpp |
| 38 | // Copyright (C) 1995-2007 Sun Microsystems, Inc. All Rights Reserved |
| 39 | // 4150 Network Circle, Santa Clara, California 95054, U.S.A. |
| 40 | // |
| 41 | // * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
| 42 | // |
| 43 | // This program is free software; you can redistribute it and/or modify |
| 44 | // it under the terms of the GNU General Public License as published by |
| 45 | // the Free Software Foundation; version 2 of the License. |
| 46 | // |
| 47 | // This program is distributed in the hope that it will be useful, |
| 48 | // but WITHOUT ANY WARRANTY; without even the implied warranty of |
| 49 | // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
| 50 | // GNU General Public License for more details. |
| 51 | // |
| 52 | // You should have received a copy of the GNU General Public License |
| 53 | // along with this program; if not, write to the Free Software |
| 54 | // Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 55 | // |
| 56 | // For the avoidance of doubt, and except that if any non-GPL license |
| 57 | // choice is available it will apply instead, Sun elects to use only |
| 58 | // the General Public License version 2 (GPLv2) at this time for any |
| 59 | // software where a choice of GPL license versions is made |
| 60 | // available with the language indicating that GPLv2 or any later version |
| 61 | // may be used, or where a choice of which version of the GPL is applied is |
| 62 | // otherwise unspecified. |
| 63 | // |
| 64 | // Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
| 65 | // CA 95054 USA or visit www.sun.com if you need additional information or |
| 66 | // have any questions. |
| 67 | // |
| 68 | // ========== Copyright Header End ============================================ |
| 69 | // These are functions that must be implement for RTL |
| 70 | |
| 71 | #include "loader.h" |
| 72 | #include "sharedmem.h" |
| 73 | |
| 74 | #include "niu_debug_functions.h" |
| 75 | |
| 76 | extern sharedmem *shmem; |
| 77 | |
| 78 | unsigned int compute_crc(unsigned char *buf, int len) { |
| 79 | static unsigned int poly = 0xedb88320; |
| 80 | unsigned int crc = 0xffffffff; |
| 81 | for(int i=0;i<len;i++) { |
| 82 | crc = crc ^ buf[i]; |
| 83 | for(int j=0;j<8; j++) |
| 84 | crc = (crc >> 1) ^ ((crc & 0x1) ? poly : 0); |
| 85 | } |
| 86 | return ~crc; |
| 87 | } |
| 88 | |
| 89 | /// MMI APIs |
| 90 | |
| 91 | int mmi_map_physio(uint64_t base, uint64_t size, void* obj, mmi_access access) { |
| 92 | // For testing |
| 93 | module_info.base = base; |
| 94 | module_info.size = size; |
| 95 | module_info.access_fn = access; |
| 96 | //////// |
| 97 | |
| 98 | // RTL stuff goes here. |
| 99 | printf("mmi_map_physio called!\n"); |
| 100 | |
| 101 | return 0; |
| 102 | } |
| 103 | |
| 104 | void mmi_memread(uint64_t paddr, uint8_t * data, uint64_t size, SAM_DeviceId sam_id) { |
| 105 | printf("mmi_memread: %llx %llx\n", paddr, size); |
| 106 | shmem->sii_read_req(paddr, data, size); |
| 107 | printf("MMI_MEMREAD: ADDR:%llx\n", paddr); |
| 108 | niu_debug_hex_dump("MMI_MEMREAD", data, size); |
| 109 | fflush(stdout); |
| 110 | } |
| 111 | |
| 112 | void mmi_memwrite(uint64_t paddr, const uint8_t * data, uint64_t size, SAM_DeviceId sam_id) { |
| 113 | printf("mmi_memwrite: %llx %llx\n", paddr, size); |
| 114 | niu_debug_hex_dump("MMI_MEMWRITE", data, size); |
| 115 | shmem->sii_write_req(paddr, (unsigned char*)data, size); |
| 116 | } |
| 117 | |
| 118 | int netsim_connect(const char *netswitch) { |
| 119 | printf("netsim_connect: %s\n", netswitch); |
| 120 | // RTL stuff |
| 121 | return 0; |
| 122 | } |
| 123 | |
| 124 | int netsim_close(int fd) { |
| 125 | printf("netsim_close: %d\n", fd); |
| 126 | // RTL stuff |
| 127 | return 0; |
| 128 | } |
| 129 | |
| 130 | extern "C" int netsim_getmsg (int fd, char * buf, int maxlen, swtchdr * hdr) { |
| 131 | // RTL stuff |
| 132 | fd--; |
| 133 | int size; |
| 134 | |
| 135 | if(fd == 0) |
| 136 | shmem->rx0_wait_packet(size, (unsigned char*) buf); |
| 137 | else |
| 138 | shmem->rx1_wait_packet(size, (unsigned char*) buf); |
| 139 | |
| 140 | hdr->pkt_type = 0; |
| 141 | hdr->pkt_len = size; |
| 142 | |
| 143 | if(fd == 0) |
| 144 | niu_debug_hex_dump("NETSIM_GETMSG P0", (unsigned char *)buf, size); |
| 145 | else |
| 146 | niu_debug_hex_dump("NETSIM_GETMSG P1", (unsigned char *)buf, size); |
| 147 | |
| 148 | return size; |
| 149 | } |
| 150 | |
| 151 | extern "C" int netsim_putmsg (int fd, char * buf, int len, swtchdr * hdr) { |
| 152 | // RTL stuff |
| 153 | fd--; |
| 154 | printf("NETSIM_PUTMSG: Port %d \n", fd); |
| 155 | |
| 156 | //Add CRC ; sam does not compute CRC |
| 157 | unsigned int crc = compute_crc((unsigned char*)buf, len-4); |
| 158 | for(int i=0;i<4;i++) |
| 159 | buf[len+i-4] = (crc >> (i*8)) & 0xff; |
| 160 | |
| 161 | niu_debug_hex_dump("NETSIM_PUTMSG", (unsigned char *)buf, len); |
| 162 | |
| 163 | if(fd == 0) |
| 164 | shmem->tx0_send_packet(len,(unsigned char *)buf); |
| 165 | else |
| 166 | shmem->tx1_send_packet(len,(unsigned char *)buf); |
| 167 | |
| 168 | return len; |
| 169 | } |
| 170 | |
| 171 | int ncu_interrupt(uint32_t cpuid, uint32_t data) { |
| 172 | printf("ncu_interrup: %x %x \n", cpuid, data); |
| 173 | shmem->deliverInterrupt(data); |
| 174 | return 0; |
| 175 | } |
| 176 | |
| 177 | |