00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00046 #include "StdAfx.h"
00047 #include "AliM1543C_usb.h"
00048 #include "System.h"
00049
00050 u32 usb_cfg_data[64] = {
00051 0x523710b9,
00052 0x02800000,
00053 0x0c031003,
00054 0x00000000,
00055 0x00000000,
00056 0x00000000,
00057 0x00000000,
00058 0x00000000,
00059 0x00000000,
00060 0x00000000,
00061 0x00000000,
00062 0x00000000,
00063 0x00000000,
00064 0x00000000,
00065 0x00000000,
00066 0x500001ff,
00067 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
00068 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
00069 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
00070 };
00071
00072 u32 usb_cfg_mask[64] = {
00073 0x00000000,
00074 0x00000157,
00075 0x00000000,
00076 0x0000ffff,
00077 0xfffff000,
00078 0x00000000,
00079 0x00000000,
00080 0x00000000,
00081 0x00000000,
00082 0x00000000,
00083 0x00000000,
00084 0x00000000,
00085 0x00000000,
00086 0x00000000,
00087 0x00000000,
00088 0x000000ff,
00089 0x04100000,
00090 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
00091 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
00092 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
00093 };
00094
00098 CAliM1543C_usb::CAliM1543C_usb(CConfigurator* cfg, CSystem* c, int pcibus,
00099 int pcidev) : CPCIDevice(cfg, c, pcibus, pcidev)
00100 {
00101 add_function(0, usb_cfg_data, usb_cfg_mask);
00102
00103 ResetPCI();
00104
00105 state.usb_data[0x34 / 4] = 0x2edf;
00106 state.usb_data[0x48 / 4] = 0x01000003;
00107
00108 printf("%s: $Id: AliM1543C_usb.cpp,v 1.6 2008/03/14 15:30:50 iamcamiel Exp $\n",
00109 devid_string);
00110 }
00111
00112 CAliM1543C_usb::~CAliM1543C_usb()
00113 { }
00114 u32 CAliM1543C_usb::ReadMem_Bar(int func, int bar, u32 address, int dsize)
00115 {
00116 u32 data = 0;
00117 switch(bar)
00118 {
00119 case 0: data = usb_hci_read(address, dsize); break;
00120 default: printf("%%USB-W-READBAR: Bad BAR %d selected.\n", bar);
00121 }
00122
00123 return data;
00124 }
00125
00126 void CAliM1543C_usb::WriteMem_Bar(int func, int bar, u32 address, int dsize,
00127 u32 data)
00128 {
00129 switch(bar)
00130 {
00131 case 0: usb_hci_write(address, dsize, data); break;
00132 default: printf("%%USB-W-WRITEBAR: Bad BAR %d selected.\n", bar);
00133 }
00134
00135 return;
00136 }
00137
00138 u64 CAliM1543C_usb::usb_hci_read(u64 address, int dsize)
00139 {
00140 u64 data = 0;
00141 if(dsize != 32)
00142 printf("%%USB-W-HCIREAD: Non dword read, returning 32 bits anyway.\n");
00143 switch(address)
00144 {
00145 case 0:
00146 data = 0x00000110;
00147 break;
00148
00149 case 4:
00150 case 8:
00151 case 0x0c:
00152 case 0x10:
00153 case 0x14:
00154 case 0x18:
00155 case 0x1c:
00156 case 0x20:
00157 case 0x24:
00158 case 0x28:
00159 case 0x2c:
00160 case 0x30:
00161 case 0x34:
00162 case 0x38:
00163 case 0x3c:
00164 case 0x40:
00165 case 0x44:
00166 case 0x48:
00167 case 0x4c:
00168 case 0x50:
00169 case 0x54:
00170 case 0x58:
00171 case 0x5c:
00172 case 0x100:
00173 case 0x104:
00174 case 0x108:
00175 case 0x10c:
00176 data = state.usb_data[address / 4];
00177 break;
00178
00179 default:
00180 printf("%%USB-W-HCIREAD: Reading from unknown address %x. Ignoring.\n",
00181 (int) address);
00182 }
00183
00184 return data;
00185 }
00186
00187 void CAliM1543C_usb::usb_hci_write(u64 address, int dsize, u64 data)
00188 {
00189 if(dsize != 32)
00190 printf("%%USB-W-HCIWRITE: Non dword write, writing 32 bits anyway.\n");
00191 switch(address)
00192 {
00193 case 4:
00194 case 8:
00195 case 0x0c:
00196 case 0x10:
00197 case 0x14:
00198 case 0x18:
00199 case 0x1c:
00200 case 0x20:
00201 case 0x24:
00202 case 0x28:
00203 case 0x2c:
00204 case 0x30:
00205 case 0x34:
00206 case 0x38:
00207 case 0x3c:
00208 case 0x40:
00209 case 0x44:
00210 case 0x48:
00211 case 0x4c:
00212 case 0x50:
00213 case 0x54:
00214 case 0x58:
00215 case 0x5c:
00216 case 0x100:
00217 case 0x104:
00218 case 0x108:
00219 case 0x10c:
00220 state.usb_data[address / 4] = data;
00221 break;
00222
00223 default:
00224 printf("%%USB-W-HCIWRITE: Writing to unknown address %x. Ignoring.\n",
00225 (int) address);
00226 }
00227 }
00228
00229 static u32 usb_magic1 = 0x9000432B;
00230 static u32 usb_magic2 = 0xB2340009;
00231
00235 int CAliM1543C_usb::SaveState(FILE* f)
00236 {
00237 long ss = sizeof(state);
00238 int res;
00239
00240 if(res = CPCIDevice::SaveState(f))
00241 return res;
00242
00243 fwrite(&usb_magic1, sizeof(u32), 1, f);
00244 fwrite(&ss, sizeof(long), 1, f);
00245 fwrite(&state, sizeof(state), 1, f);
00246 fwrite(&usb_magic2, sizeof(u32), 1, f);
00247 printf("%s: %d bytes saved.\n", devid_string, (int) ss);
00248 return 0;
00249 }
00250
00254 int CAliM1543C_usb::RestoreState(FILE* f)
00255 {
00256 long ss;
00257 u32 m1;
00258 u32 m2;
00259 int res;
00260 size_t r;
00261
00262 if(res = CPCIDevice::RestoreState(f))
00263 return res;
00264
00265 r = fread(&m1, sizeof(u32), 1, f);
00266 if(r != 1)
00267 {
00268 printf("%s: unexpected end of file!\n", devid_string);
00269 return -1;
00270 }
00271
00272 if(m1 != usb_magic1)
00273 {
00274 printf("%s: MAGIC 1 does not match!\n", devid_string);
00275 return -1;
00276 }
00277
00278 fread(&ss, sizeof(long), 1, f);
00279 if(r != 1)
00280 {
00281 printf("%s: unexpected end of file!\n", devid_string);
00282 return -1;
00283 }
00284
00285 if(ss != sizeof(state))
00286 {
00287 printf("%s: STRUCT SIZE does not match!\n", devid_string);
00288 return -1;
00289 }
00290
00291 fread(&state, sizeof(state), 1, f);
00292 if(r != 1)
00293 {
00294 printf("%s: unexpected end of file!\n", devid_string);
00295 return -1;
00296 }
00297
00298 r = fread(&m2, sizeof(u32), 1, f);
00299 if(r != 1)
00300 {
00301 printf("%s: unexpected end of file!\n", devid_string);
00302 return -1;
00303 }
00304
00305 if(m2 != usb_magic2)
00306 {
00307 printf("%s: MAGIC 1 does not match!\n", devid_string);
00308 return -1;
00309 }
00310
00311 printf("%s: %d bytes restored.\n", devid_string, (int) ss);
00312 return 0;
00313 }