Index: ipcsrv.c =================================================================== RCS file: /home/routefree/ng/depot/sw/rvl/os/ios/ipcsrv.c,v retrieving revision 1.18 retrieving revision 1.18.12.1 diff -r1.18 -r1.18.12.1 12a13 > #include 20a22,24 > extern void iosInvalidateDCache(void *ptr, u32 bytes); > extern void iosFlushDCache(void *ptr, u32 bytes); > 22c26 < # define IPC_LOG(...) printf("SRV: " __VA_ARGS__) --- > # define IPC_LOG(...) printf("IPC: " __VA_ARGS__) 31,36d34 < < // TBD: { < #define IOP_DDR_START 0x0 < #define IOP_DDR_END 0xffffffff < // } in iop.h < 39,41d36 < // } TBD < void < iosInvalidateDCache(void *ptr, u32 bytes); 43,44c38,53 < void < iosFlushDCache(void *ptr, u32 bytes); --- > #define REGION_IN_RANGE(p0, p1, s, e) \ > ( ((p0) <= (p1)) && ((p0) >= ((s)) && ((p1) <= (e))) ) > > #define CHECK_PPC_BUFFER(ptr, len) \ > do {\ > if (len) { \ > if (!REGION_IN_RANGE((u32)ptr, (u32)((u32)ptr + len) , \ > DDR_BASE, IOP_GDDR3_START + DI_DMA_SP_SIZE) \ > && !REGION_IN_RANGE((u32)ptr, (u32) ((u32)ptr + len), \ > NAPA_BASE, NAPA_BASE + NAPA_SIZE)) { \ > printf("IPC: failed buf check: ptr=%08x len=%d\n", ptr, len); \ > rv = IOS_ERROR_ACCESS; \ > goto end; \ > } \ > } \ > } while (0) 63d71 < 216c224 < IOSResourceRequest *req; --- > IOSResourceRequest *req = NULL; 219a228 > u32 reqValid = 0; 221,226c230,231 < /* Check that v is in DRAM */ < if (!IN_RANGE(v, IOP_DDR_START, IOP_DDR_END)) < { < IPC_LOG("ERROR Out of range: %u\n", v); < goto end; < } --- > CHECK_PPC_BUFFER(v, sizeof(IOSResourceRequest)); > reqValid = 1; 230a236 > req = (IOSResourceRequest*)iosPhysicalToVirtual(req); 233d238 < req = (IOSResourceRequest*)iosPhysicalToVirtual(req); 242c247,251 < iosInvalidateDCache((void*)req->args.open.path, IOS_PATH_MAX + 1); --- > { > u32 len = 0; > u8 *path = NULL; > > CHECK_PPC_BUFFER(req->args.open.path, IOS_PATH_MAX + 1); 243a253,263 > iosInvalidateDCache((void*)req->args.open.path, IOS_PATH_MAX + 1); > path = (u8 *)req->args.open.path; > len = strnlen(path, IOS_PATH_MAX + 1); > if (len > IOS_PATH_MAX) { > printf("IPC: failed open path check: path=%s len=%d\n", path, len); > rv = IOS_ERROR_INVALID; > goto end; > } > IPC_LOG("OPEN: path=%s, flags=%d, q=0x%x\n", > req->args.open.path, req->args.open.flags, __ipcMQ); > 247c267 < --- > } 248a269,270 > IPC_LOG("CLOSE: fd=%d q=0x%x\n", fd, __ipcMQ); > 252a275,278 > IPC_LOG("READ: fd=%d buf=0x%x len=%d q=0x%x\n", > fd, req->args.read.outPtr, req->args.read.outLen, __ipcMQ); > > CHECK_PPC_BUFFER(req->args.read.outPtr, req->args.read.outLen); 259c285,288 < iosInvalidateDCache(req->args.write.inPtr, req->args.write.inLen); --- > IPC_LOG("WRITE: fd=%d buf=0x%x len=%d q=0x%x\n", > fd, req->args.write.inPtr, req->args.write.inLen, __ipcMQ); > > CHECK_PPC_BUFFER(req->args.write.inPtr, req->args.write.inLen); 260a290 > iosInvalidateDCache(req->args.write.inPtr, req->args.write.inLen); 265a296,298 > IPC_LOG("SEEK: fd=%d offset=0x%x whence=%d q=0x%x\n", > fd, req->args.seek.offset, req->args.seek.whence, __ipcMQ); > 270a304,308 > IPC_LOG("IOCTL: fd=%d cmd=%d inbuf=0x%x inlen=%d outbuf=0x%x " > "outLen=%d q=0x%x\n", > fd, req->args.ioctl.cmd, req->args.ioctl.inPtr, > req->args.ioctl.inLen, req->args.ioctl.outPtr, > req->args.ioctl.outLen, __ipcMQ); 272,273c310,311 < iosInvalidateDCache(req->args.ioctl.inPtr, req->args.ioctl.inLen); < iosInvalidateDCache(req->args.ioctl.outPtr, req->args.ioctl.outLen); --- > CHECK_PPC_BUFFER(req->args.ioctl.inPtr, req->args.ioctl.inLen); > CHECK_PPC_BUFFER(req->args.ioctl.outPtr, req->args.ioctl.outLen); 277a316,317 > iosInvalidateDCache(req->args.ioctl.inPtr, req->args.ioctl.inLen); > iosInvalidateDCache(req->args.ioctl.outPtr, req->args.ioctl.outLen); 289a330 > u32 rcount, wcount; 292,293c333,338 < iosInvalidateDCache(&v->vector[0], (req->args.ioctlv.writeCount + < req->args.ioctlv.readCount) * sizeof(IOSIoVector)); --- > rcount = v->readCount; > wcount = v->writeCount; > > IPC_LOG("IOCTLV: fd=%d cmd=%d rcount=%d wcount=%d vector=0x%x q=0x%x\n", > fd, req->args.ioctlv.cmd, rcount, wcount, > req->args.ioctlv.vector, __ipcMQ); 294a340 > CHECK_PPC_BUFFER(v->vector, (rcount + wcount) * sizeof(IOSIoVector)); 296a343 > iosInvalidateDCache(&v->vector[0], (rcount + wcount) * sizeof(IOSIoVector)); 298,302c345,346 < for (i = 0; < i < (req->args.ioctlv.writeCount + req->args.ioctlv.readCount); < ++i) < { < iosInvalidateDCache(v->vector[i].base, v->vector[i].length); --- > for (i = 0; i < (rcount + wcount); ++i) { > CHECK_PPC_BUFFER(v->vector[i].base, v->vector[i].length); 303a348 > iosInvalidateDCache(v->vector[i].base, v->vector[i].length); 306,308c351 < rv = iosIoctlvAsync(fd, req->args.ioctlv.cmd, < req->args.ioctlv.readCount, < req->args.ioctlv.writeCount, --- > rv = iosIoctlvAsync(fd, req->args.ioctlv.cmd, rcount, wcount, 318,319c361,362 < if (rv < 0) < { --- > end: > if (reqValid && rv < 0) { 325c368,371 < end: --- > /* If request is invalid, it is ignored. No reply is sent. This > * will stall further IPC requests. This is probably OK, because > * getting an invalid request is a fatal error. > */ 327a374 > 337,338d383 < IPC_LOG("sample IPC server\n"); < 379c424 < IPC_LOG("Got REPLY\n"); --- > IPC_LOG("Got REPLY: rv=%d\n", req->status); 413,414c458,459 < if (__inFlight < sizeof(__responses.buf) < / sizeof(__responses.buf[0]) - 1) --- > if (__inFlight < (sizeof(__responses.buf) > / sizeof(__responses.buf[0]) - 1)) 418a464,465 > } else { > IPC_LOG("max inflight = %d limit reached\n", sizeof(__responses.buf)/ sizeof(__responses.buf[0]));