//-------------------------------------------------------------- int _McChDir(void *rpc_buf) { g_nameParam_t *nP = (g_nameParam_t *)rpc_buf; register int status, r; SifDmaTransfer_t dmaStruct; int intStatus; #ifdef DEBUG DPRINTF("mcserv: _McChDir port%d slot%d newdir %s\n", nP->port, nP->slot, nP->name); #endif r = McChDir(nP->port, nP->slot, nP->name, (char *)mcserv_buf); dmaStruct.src = (void *)mcserv_buf; dmaStruct.dest = (void *)nP->mcT; dmaStruct.size = 1024; dmaStruct.attr = 0; CpuSuspendIntr(&intStatus); status = sceSifSetDma(&dmaStruct, 1); CpuResumeIntr(intStatus); while (sceSifDmaStat(status) >= 0) DelayThread(100); return r; }
//-------------------------------------------------------------- int _McGetInfo2(void *rpc_buf) { g_descParam_t *dP = (g_descParam_t *)rpc_buf; register int status, mc_free, r; g_endParam2_t eP; SifDmaTransfer_t dmaStruct; int intStatus; #ifdef DEBUG DPRINTF("mcserv: _McGetInfo2 port%d slot%d\n", dP->port, dP->slot); #endif mc_free = 0; r = McDetectCard2(dP->port, dP->slot); if (dP->origin > 0) eP.fastIO1_size = McGetMcType(dP->port, dP->slot); if (r < -1) { eP.fastIO2_size = 0; eP.flag = 0; goto dma_transfer; } if (dP->offset > 0) { mc_free = McGetFreeClusters(dP->port, dP->slot); if (mc_free < 0) eP.fastIO2_size = 0; else eP.fastIO2_size = mc_free; } if (dP->size > 0) { eP.flag = 0; if (McGetFormat(dP->port, dP->slot) > 0) eP.flag = 1; } dma_transfer: dmaStruct.src = (void *)&eP; dmaStruct.dest = (void *)dP->param; dmaStruct.size = sizeof (g_endParam2_t); dmaStruct.attr = 0; CpuSuspendIntr(&intStatus); status = sceSifSetDma(&dmaStruct, 1); CpuResumeIntr(intStatus); while (sceSifDmaStat(status) >= 0) DelayThread(100); if (mc_free < 0) return mc_free; return r; }
//-------------------------------------------------------------- int _McGetDir(void *rpc_buf) { g_nameParam_t *nP = (g_nameParam_t *)rpc_buf; register int status, file_entries, flags, r; SifDmaTransfer_t dmaStruct; int intStatus; #ifdef DEBUG DPRINTF("mcserv: _McGetDir port%d slot%d dir %s flags %d maxent %d mcT addr %x\n", nP->port, nP->slot, nP->name, nP->flags, nP->maxent, (int)nP->mcT); #endif status = 0; file_entries = 0; flags = nP->flags; nP->maxent--; while (nP->maxent > -1) { r = McGetDir(nP->port, nP->slot, nP->name, flags & 0xffff, 1, (mcTable_t *)mcserv_buf); if (r < 0) return r; if (r == 0) goto dma_wait; file_entries++; dmaStruct.src = (void *)mcserv_buf; dmaStruct.dest = (void *)nP->mcT; dmaStruct.size = sizeof (mcTable_t); dmaStruct.attr = 0; CpuSuspendIntr(&intStatus); status = sceSifSetDma(&dmaStruct, 1); CpuResumeIntr(intStatus); flags = 1; nP->mcT++; nP->maxent--; } dma_wait: if (status == 0) return file_entries; while (sceSifDmaStat(status) >= 0) DelayThread(100); return file_entries; }
//------------------------------------------------------------------------- void *cbrpc_cdsearchfile(u32 fno, void *buf, int size) { // CD Search File RPC callback SifDmaTransfer_t dmat; int r, oldstate; void *ee_addr; char *p; SearchFilePkt_t *pkt = (SearchFilePkt_t *)buf; SearchFilePkt2_t *pkt2 = (SearchFilePkt2_t *)buf; SearchFilePktl_t *pktl = (SearchFilePktl_t *)buf; int pktsize = 0; if (size == sizeof(SearchFilePkt2_t)) { ee_addr = (void *)pkt2->dest; // Search File: Called from Not Dual_layer Version p = (void *)&pkt2->name[0]; pktsize = sizeof(cdl_file_t); r = sceCdSearchFile((cd_file_t *)buf, p); pkt2->cdfile.flag = 0; } else { if (size > sizeof(SearchFilePkt2_t)) { // Search File: Called from Dual_layer Version ee_addr = (void *)pktl->dest; p = (char *)&pktl->name[0]; pktsize = sizeof(cdl_file_t); r = sceCdLayerSearchFile((cdl_file_t *)buf, p, pktl->layer); pktl->cdfile.flag = 0; } else { // Search File: Called from Old Library ee_addr = (void *)pkt->dest; p = (char *)&pkt->name[0]; pktsize = sizeof(cd_file_t); r = sceCdSearchFile((cd_file_t *)buf, p); } } dmat.dest = (void *)ee_addr; dmat.size = pktsize; dmat.src = (void *)buf; dmat.attr = 0; CpuSuspendIntr(&oldstate); while (!sceSifSetDma(&dmat, 1)); CpuResumeIntr(oldstate); //while (sceSifDmaStat >= 0); *(int *)buf = r; return buf; }
unsigned int pkoSetSifDma(void *dest, void *src, unsigned int length, unsigned int mode) { struct t_SifDmaTransfer sendData; int oldIrq; int id; sendData.src = (unsigned int *)src; sendData.dest = (unsigned int *)dest; sendData.size = length; sendData.attr = mode; CpuSuspendIntr(&oldIrq); id = sceSifSetDma(&sendData, 1); CpuResumeIntr(oldIrq); return id; }
//-------------------------------------------------------------- void sysmemSendEE(void *buf, void *EE_addr, int size) { SifDmaTransfer_t dmat; int oldstate, id; size += 3; size &= 0xfffffffc; dmat.dest = (void *)EE_addr; dmat.size = size; dmat.src = (void *)buf; dmat.attr = 0; id = 0; while (!id) { CpuSuspendIntr(&oldstate); id = sceSifSetDma(&dmat, 1); CpuResumeIntr(oldstate); } while (sceSifDmaStat(id) >= 0); }
static void DmaSendEE(void) { int dma_stat; dma_stat = sceSifDmaStat(sifdma_id); if(dma_stat >= 0) { if( (frame_count % 240) == 0) { M_KPRINTF("DMA Busy ID = %08x ret = %d\n", sifdma_id, dma_stat); M_KPRINTF(" SB_STAT = %08x\n", SB_STAT); } } else { u32 port, slot; u32 sifdma_count = 1; /* This is where the 128*2 bytes of 'garbage' gets sent to EE. I believe that only 16 bytes should have been sent, used for checking which ports/slots are open on the EE (padGetConnection). However someone made a mistake and sent 128 bytes instead :-) Its the first 112 (128-16) bytes of padState[0][0] which gets sent along with the sif_buffer, which I think clearly indicates that sending 128 bytes is an error. - Lukasz */ sif_buffer[0]++; sif_buffer[1] = pad_portdata[0]; sif_buffer[2] = pad_portdata[1]; if( (sif_buffer[0] % 2) == 0) sifdma_td[0].dest = pad_ee_addr + 128; else sifdma_td[0].dest = pad_ee_addr; sifdma_td[0].src = sif_buffer; sifdma_td[0].size = 128; sifdma_td[0].attr = 0; for(port=0; port < 2; port++) { for(slot=0; slot < 4; slot++) { if( (openSlots[port] >> slot) & 1 ) { padState_t *p = &padState[port][slot]; // Setup EE pad data p->ee_pdata.frame = p->frame; p->ee_pdata.findPadRetries = p->findPadRetries; p->ee_pdata.modeConfig = p->modeConfig; p->ee_pdata.modeCurId = p->modeCurId; p->ee_pdata.model = p->model; p->ee_pdata.buttonDataReady = p->buttonDataReady; p->ee_pdata.nrOfModes = p->numModes; p->ee_pdata.modeCurOffs = p->modeCurOffs; p->ee_pdata.nrOfActuators = p->numActuators; p->ee_pdata.numActComb = p->numActComb; p->ee_pdata.val_c6 = p->val_c6; p->ee_pdata.mode = p->mode; p->ee_pdata.lock = p->lock; p->ee_pdata.actDirSize = p->ee_actDirectSize; p->ee_pdata.state = p->state; p->ee_pdata.reqState = p->reqState; p->ee_pdata.currentTask = p->currentTask; p->frame++; p->ee_pdata.runTask = p->runTask; p->ee_pdata.actDirData[0] = p->ee_actDirectData.data32[0]; p->ee_pdata.actDirData[1] = p->ee_actDirectData.data32[1]; p->ee_pdata.actAlignData[0] = p->ee_actAlignData.data32[0]; p->ee_pdata.actAlignData[1] = p->ee_actAlignData.data32[1]; p->ee_pdata.actData[0] = p->actData.data32[0]; p->ee_pdata.actData[1] = p->actData.data32[1]; p->ee_pdata.actData[2] = p->actData.data32[2]; p->ee_pdata.actData[3] = p->actData.data32[3]; p->ee_pdata.combData[0] = p->combData.data32[0]; p->ee_pdata.combData[1] = p->combData.data32[1]; p->ee_pdata.combData[2] = p->combData.data32[2]; p->ee_pdata.combData[3] = p->combData.data32[3]; p->ee_pdata.modeTable[0] = p->modeTable.data32[0]; p->ee_pdata.modeTable[1] = p->modeTable.data32[1]; p->ee_pdata.stat70bit = p->stat70bit; if( p->buttonDataReady == 1) { p->ee_pdata.length = setupEEButtonData(port, slot, p); } else { p->ee_pdata.length = 0; } if( (p->frame & 1) == 0) sifdma_td[sifdma_count].dest = (void*)p->padarea_ee_addr; else sifdma_td[sifdma_count].dest = (void*)(p->padarea_ee_addr + 128); sifdma_td[sifdma_count].src = &p->ee_pdata; sifdma_td[sifdma_count].size = 128; sifdma_td[sifdma_count].attr = 0; sifdma_count++; } } } if(sifdma_count != 0) { int intr_state; CpuSuspendIntr(&intr_state); sifdma_id = sceSifSetDma( sifdma_td, sifdma_count); CpuResumeIntr(intr_state); if(sifdma_id == 0) M_KPRINTF("sceSifSetDma failed\n"); } } }
//-------------------------------------------------------------- int _McRead2(void *rpc_buf) { g_descParam_t *dP = (g_descParam_t *)rpc_buf; register int file_offset, status; register int left_to_read, size_readed, size_to_read; g_endParam2_t eP; SifDmaTransfer_t dmaStruct; int intStatus; void *eedata; #ifdef DEBUG DPRINTF("mcserv: _McRead2 fd %d ee buffer addr %x size %d\n", dP->fd, (int)dP->buffer, dP->size); #endif eP.fastIO1_size = 0; eP.fastIO2_size = 0; eP.fastIO1_eeaddr = NULL; eP.fastIO2_eeaddr = NULL; size_readed = 0; file_offset = 0; eedata = dP->buffer; eP.fastIO1_size = dP->size; if (dP->size > 64) eP.fastIO1_size = (((u32)(eedata)-1) & 0xffffffc0) - ((u32)(eedata) - 64); eP.fastIO2_size = (dP->size - eP.fastIO1_size) & 0x3f; left_to_read = (dP->size - eP.fastIO1_size) - eP.fastIO2_size; if (eP.fastIO2_size != 0) eP.fastIO2_eeaddr = (void *)(eedata + eP.fastIO1_size + left_to_read); if (eP.fastIO1_size != 0) { size_readed = McRead(dP->fd, eP.fastIO1_data, eP.fastIO1_size); if (size_readed < 0) { eP.fastIO1_size = 0; eP.fastIO2_size = 0; goto dma_transfer2; } else { file_offset = size_readed; eP.fastIO1_eeaddr = eedata; eedata += size_readed; if (size_readed != eP.fastIO1_size) { eP.fastIO1_size = size_readed; eP.fastIO2_size = 0; size_readed = 0; goto dma_transfer2; } else size_readed = 0; } } while (left_to_read > 0) { size_to_read = left_to_read; if (left_to_read > MCSERV_BUFSIZE) size_to_read = MCSERV_BUFSIZE; size_readed = McRead(dP->fd, mcserv_buf, size_to_read); if (size_readed < 0) { eP.fastIO2_size = 0; goto dma_transfer2; } if (size_readed == size_to_read) { dmaStruct.size = size_readed; goto dma_transfer; } eP.fastIO2_size = size_readed & 0x3f; if ((size_readed & 0x3f) != 0) { eP.fastIO2_eeaddr = (void *)(eedata + (size_readed & 0xffffffc0)); memcpy(eP.fastIO2_data, (void *)(mcserv_buf + (size_readed & 0xffffffc0)), size_readed & 0x3f); } if (eP.fastIO2_size == size_readed) goto skip_dma_transfer; dmaStruct.size = size_readed - eP.fastIO2_size; dma_transfer: dmaStruct.src = (void *)mcserv_buf; dmaStruct.dest = (void *)eedata; dmaStruct.attr = 0; CpuSuspendIntr(&intStatus); sceSifSetDma(&dmaStruct, 1); CpuResumeIntr(intStatus); skip_dma_transfer: file_offset += size_readed; left_to_read -= size_readed; eedata += size_readed; if (size_to_read != size_readed) { size_readed = 0; goto dma_transfer2; } size_readed = 0; } if (eP.fastIO2_size == 0) goto dma_transfer2; size_readed = McRead(dP->fd, eP.fastIO2_data, eP.fastIO2_size); if (size_readed < 0) { eP.fastIO2_size = 0; goto dma_transfer2; } file_offset += size_readed; eP.fastIO2_size = size_readed; size_readed = 0; dma_transfer2: dmaStruct.src = (void *)&eP; dmaStruct.dest = (void *)dP->param; dmaStruct.size = sizeof (g_endParam2_t); dmaStruct.attr = 0; CpuSuspendIntr(&intStatus); status = sceSifSetDma(&dmaStruct, 1); CpuResumeIntr(intStatus); while (sceSifDmaStat(status) >= 0) DelayThread(100); if (size_readed != 0) return size_readed; return file_offset; }
//-------------------------------------------------------------- int _McReadPage(void *rpc_buf) { g_descParam_t *dP = (g_descParam_t *)rpc_buf; g_endParam_t eP; register int status, fastsize, r, i, j; SifDmaTransfer_t dmaStruct; int intStatus; #ifdef DEBUG DPRINTF("mcserv: _McReadPage port%d slot%d page %d\n", dP->port, dP->slot, dP->fd); #endif eP.fastIO1_eeaddr = dP->buffer; fastsize = ((u32)dP->buffer) & 0xf; dP->port = (dP->port & 1) + 2; if (McGetMcType(dP->port, dP->slot) == 2) { r = 0; McReadPage(dP->port, dP->slot, dP->fd, (void *)(mcserv_buf + fastsize)); } else { memset((void *)(mcserv_buf + fastsize), 0, 512); r = McReadPS1PDACard(dP->port, dP->slot, dP->fd, (void *)(mcserv_buf + fastsize)); } if (fastsize == 0) goto fullpage; i = 0; j = fastsize; while (j < 16) { eP.fastIO1_data[i] = mcserv_buf[j]; j++; i++; } j = 0; if (fastsize > 0) { while (j < 16) { eP.fastIO1_data[i] = mcserv_buf[512 + j]; j++; i++; } } dmaStruct.src = (void *)(mcserv_buf + 16); dmaStruct.dest = (void *)(dP->buffer - (fastsize - 16)); dmaStruct.size = 496; dmaStruct.attr = 0; goto dma_transfer; fullpage: dmaStruct.src = (void *)mcserv_buf; dmaStruct.dest = (void *)dP->buffer; dmaStruct.size = 512; dmaStruct.attr = 0; dma_transfer: CpuSuspendIntr(&intStatus); status = sceSifSetDma(&dmaStruct, 1); CpuResumeIntr(intStatus); dmaStruct.src = (void *)&eP; dmaStruct.dest = (void *)dP->param; dmaStruct.size = sizeof (g_endParam_t); dmaStruct.attr = 0; CpuSuspendIntr(&intStatus); status = sceSifSetDma(&dmaStruct, 1); CpuResumeIntr(intStatus); while (sceSifDmaStat(status) >= 0) DelayThread(100); return r; }