Index: ipcsrv.c =================================================================== RCS file: /home/routefree/ng/depot/sw/rvl/os/ios/ipcsrv.c,v retrieving revision 1.15 retrieving revision 1.15.18.1 diff -r1.15 -r1.15.18.1 11a12,13 > #include > #include 19a22,24 > extern void iosInvalidateDCache(void *ptr, u32 bytes); > extern void iosFlushDCache(void *ptr, u32 bytes); > 21c26 < # define IPC_LOG(...) printf("SRV: " __VA_ARGS__) --- > # define IPC_LOG(...) printf("IPC: " __VA_ARGS__) 30,35d34 < < // TBD: { < #define IOP_DDR_START 0x0 < #define IOP_DDR_END 0xffffffff < // } in iop.h < 38,40d36 < // } TBD < void < iosInvalidateDCache(void *ptr, u32 bytes); 42,43c38,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) 62d71 < 215c224 < IOSResourceRequest *req; --- > IOSResourceRequest *req = NULL; 218a228 > u32 reqValid = 0; 220,225c230,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; 229a236 > req = (IOSResourceRequest*)iosPhysicalToVirtual(req); 232d238 < req = (IOSResourceRequest*)iosPhysicalToVirtual(req); 241c247,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); 242a253,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); > 246c267 < --- > } 247a269,270 > IPC_LOG("CLOSE: fd=%d q=0x%x\n", fd, __ipcMQ); > 251a275,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); 258c285,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); 259a290 > iosInvalidateDCache(req->args.write.inPtr, req->args.write.inLen); 264a296,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); > 269a304,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); 271,272c310,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); 276a316,317 > iosInvalidateDCache(req->args.ioctl.inPtr, req->args.ioctl.inLen); > iosInvalidateDCache(req->args.ioctl.outPtr, req->args.ioctl.outLen); 288a330 > u32 rcount, wcount; 291,292c333,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); 293a340 > CHECK_PPC_BUFFER(v->vector, (rcount + wcount) * sizeof(IOSIoVector)); 295a343 > iosInvalidateDCache(&v->vector[0], (rcount + wcount) * sizeof(IOSIoVector)); 297,301c345,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); 302a348 > iosInvalidateDCache(v->vector[i].base, v->vector[i].length); 305,307c351 < rv = iosIoctlvAsync(fd, req->args.ioctlv.cmd, < req->args.ioctlv.readCount, < req->args.ioctlv.writeCount, --- > rv = iosIoctlvAsync(fd, req->args.ioctlv.cmd, rcount, wcount, 317,318c361,362 < if (rv < 0) < { --- > end: > if (reqValid && rv < 0) { 324c368,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. > */ 327a375 > extern IOSError iosSetThreadPriority(IOSThreadId id, u32 priority); 336,337d383 < IPC_LOG("sample IPC server\n"); < 376c422 < IPC_LOG("Got REPLY\n"); --- > IPC_LOG("Got REPLY: rv=%d\n", req->status); 410,411c456,457 < if (__inFlight < sizeof(__responses.buf) < / sizeof(__responses.buf[0]) - 1) --- > if (__inFlight < (sizeof(__responses.buf) > / sizeof(__responses.buf[0]) - 1)) 415a462,463 > } else { > IPC_LOG("max inflight = %d limit reached\n", sizeof(__responses.buf)/ sizeof(__responses.buf[0]));