Index: ipcsrv.c =================================================================== RCS file: /home/routefree/ng/depot/sw/rvl/os/ios/ipcsrv.c,v retrieving revision 1.20 retrieving revision 1.20.12.1 diff -r1.20 -r1.20.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 < 211c219 < IOSResourceRequest *req; --- > IOSResourceRequest *req = NULL; 214a223 > u32 reqValid = 0; 216,221c225,226 < /* 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; 225a231 > req = (IOSResourceRequest*)iosPhysicalToVirtual(req); 228d233 < req = (IOSResourceRequest*)iosPhysicalToVirtual(req); 237c242,246 < 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); 238a248,258 > 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); > 242c262 < --- > } 243a264,265 > IPC_LOG("CLOSE: fd=%d q=0x%x\n", fd, __ipcMQ); > 247a270,273 > 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); 254c280,283 < 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); 255a285 > iosInvalidateDCache(req->args.write.inPtr, req->args.write.inLen); 260a291,293 > IPC_LOG("SEEK: fd=%d offset=0x%x whence=%d q=0x%x\n", > fd, req->args.seek.offset, req->args.seek.whence, __ipcMQ); > 265a299,303 > 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); 267,268c305,306 < 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); 272a311,312 > iosInvalidateDCache(req->args.ioctl.inPtr, req->args.ioctl.inLen); > iosInvalidateDCache(req->args.ioctl.outPtr, req->args.ioctl.outLen); 284a325 > u32 rcount, wcount; 287,288c328,333 < 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); 289a335 > CHECK_PPC_BUFFER(v->vector, (rcount + wcount) * sizeof(IOSIoVector)); 291a338 > iosInvalidateDCache(&v->vector[0], (rcount + wcount) * sizeof(IOSIoVector)); 293,297c340,341 < 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); 298a343 > iosInvalidateDCache(v->vector[i].base, v->vector[i].length); 301,303c346 < rv = iosIoctlvAsync(fd, req->args.ioctlv.cmd, < req->args.ioctlv.readCount, < req->args.ioctlv.writeCount, --- > rv = iosIoctlvAsync(fd, req->args.ioctlv.cmd, rcount, wcount, 313,314c356,357 < if (rv < 0) < { --- > end: > if (reqValid && rv < 0) { 320c363,366 < 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. > */ 322a369 > 332,333d378 < IPC_LOG("sample IPC server\n"); < 377c422 < IPC_LOG("Got REPLY\n"); --- > IPC_LOG("Got REPLY: rv=%d\n", req->status); 411,412c456,457 < if (__inFlight < sizeof(__responses.buf) < / sizeof(__responses.buf[0]) - 1) --- > if (__inFlight < (sizeof(__responses.buf) > / sizeof(__responses.buf[0]) - 1)) 416a462,463 > } else { > IPC_LOG("max inflight = %d limit reached\n", sizeof(__responses.buf)/ sizeof(__responses.buf[0]));