12#include "mcman-internal.h"
14#ifdef BUILDING_XFROMMAN
18#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
20static u8 mcman_wdmabufs[0x0b * 0x90];
21static u8 mcman_rdmabufs[0x0b * 0x90];
24static u8 mcman_sio2inbufs_PS1PDA[0x90];
25u8 mcman_sio2outbufs_PS1PDA[0x90];
27static u32 mcman_timercount;
28static int mcman_timerthick;
33static const u8 mcman_cmdtable[36] = {
55static void (*sio2packet_add_func)(
int port,
int slot,
int cmd, u8 *buf,
int pos);
56static void sio2packet_add_wdma_u32(
int port,
int slot,
int cmd, u8 *buf,
int pos);
57static void sio2packet_add_pagedata_out(
int port,
int slot,
int cmd, u8 *buf,
int pos);
58static void sio2packet_add_pagedata_in(
int port,
int slot,
int cmd, u8 *buf,
int pos);
59static void sio2packet_add_ecc_in(
int port,
int slot,
int cmd, u8 *buf,
int pos);
60static void sio2packet_add_ecc_out(
int port,
int slot,
int cmd, u8 *buf,
int pos);
61static void sio2packet_add_wdma_5a(
int port,
int slot,
int cmd, u8 *buf,
int pos);
62static void sio2packet_add_wdma_00(
int port,
int slot,
int cmd, u8 *buf,
int pos);
63static void sio2packet_add_wdma_u8(
int port,
int slot,
int cmd, u8 *buf,
int pos);
64static void sio2packet_add_do_nothing(
int port,
int slot,
int cmd, u8 *buf,
int pos);
67static void *sio2packet_add_funcs_array[16] = {
68 (
void *)sio2packet_add_wdma_00,
69 (
void *)sio2packet_add_wdma_u32,
70 (
void *)sio2packet_add_wdma_u32,
71 (
void *)sio2packet_add_wdma_u32,
72 (
void *)sio2packet_add_wdma_u8,
73 (
void *)sio2packet_add_do_nothing,
74 (
void *)sio2packet_add_do_nothing,
75 (
void *)sio2packet_add_wdma_5a,
76 (
void *)sio2packet_add_do_nothing,
77 (
void *)sio2packet_add_pagedata_in,
78 (
void *)sio2packet_add_pagedata_out,
79 (
void *)sio2packet_add_do_nothing,
80 (
void *)sio2packet_add_do_nothing,
81 (
void *)sio2packet_add_ecc_in,
82 (
void *)sio2packet_add_ecc_out,
83 (
void *)sio2packet_add_wdma_u8
87void sio2packet_add(
int port,
int slot,
int cmd, u8 *buf)
91 if ((
unsigned int)cmd == 0xffffffff) {
92 mcman_sio2packet.in_dma.count = 0;
96 if (mcman_sio2packet.in_dma.count < 0xb) {
100 if ((
unsigned int)cmd == 0xfffffffe) {
101 mcman_sio2packet.regdata[mcman_sio2packet.in_dma.count] = 0;
102 mcman_sio2packet.out_dma.count = mcman_sio2packet.in_dma.count;
106 regdata = (((port & 1) + 2) & 3) | 0x70;
107 regdata |= mcman_cmdtable[(cmd << 1) + 1] << 18;
108 regdata |= mcman_cmdtable[(cmd << 1) + 1] << 8;
110 mcman_sio2packet.regdata[mcman_sio2packet.in_dma.count] = regdata;
112 pos = ((mcman_sio2packet.in_dma.count + (mcman_sio2packet.in_dma.count << 3)) << 4);
114 mcman_sio2packet.in_dma.count++;
116 p = mcman_sio2packet.in_dma.addr + pos;
118 p[1] = mcman_cmdtable[cmd << 1];
120 if (((cmd - 1) >= 16) || ((cmd - 1) < 0))
123 sio2packet_add_func = (
void*)sio2packet_add_funcs_array[(cmd - 1)];
124 (sio2packet_add_func)(port, slot, cmd, buf, pos);
131static void sio2packet_add_wdma_u32(
int port,
int slot,
int cmd, u8 *buf,
int pos)
137 u8 *p = mcman_sio2packet.in_dma.addr + pos;
142 p[6] = mcman_calcEDC(&p[2], 4);
147static void sio2packet_add_pagedata_out(
int port,
int slot,
int cmd, u8 *buf,
int pos)
155 u8 *p = mcman_sio2packet.in_dma.addr + pos;
161static void sio2packet_add_pagedata_in(
int port,
int slot,
int cmd, u8 *buf,
int pos)
169 u8 *p = mcman_sio2packet.in_dma.addr + pos;
172 for (i=0; i<128; i++)
175 p[3 + 128] = mcman_calcEDC(&buf[0], 128);
180static void sio2packet_add_ecc_in(
int port,
int slot,
int cmd, u8 *buf,
int pos)
183 register u32 regdata;
185 u8 *p = mcman_sio2packet.in_dma.addr + pos;
187 p[2] = mcman_sparesize(port, slot);
189 for (i=0; i<(p[2] & 0xff); i++)
192 p[3 + p[2]] = mcman_calcEDC(&buf[0], p[2]);
194 regdata = (p[2] + mcman_cmdtable[(cmd << 1) + 1]) << 18;
195 regdata |= mcman_sio2packet.regdata[mcman_sio2packet.in_dma.count-1] & ~0x07fc0000;
196 regdata &= ~0x0001ff00;
197 regdata |= (p[2] + mcman_cmdtable[(cmd << 1) + 1]) << 8;
199 mcman_sio2packet.regdata[mcman_sio2packet.in_dma.count-1] = regdata;
204static void sio2packet_add_ecc_out(
int port,
int slot,
int cmd, u8 *buf,
int pos)
209 register u32 regdata;
210 u8 *p = mcman_sio2packet.in_dma.addr + pos;
212 p[2] = mcman_sparesize(port, slot);
214 regdata = (p[2] + mcman_cmdtable[(cmd << 1) + 1]) << 18;
215 regdata |= mcman_sio2packet.regdata[mcman_sio2packet.in_dma.count-1] & ~0x07fc0000;
216 regdata &= ~0x0001ff00;
217 regdata |= (p[2] + mcman_cmdtable[(cmd << 1) + 1]) << 8;
219 mcman_sio2packet.regdata[mcman_sio2packet.in_dma.count-1] = regdata;
224static void sio2packet_add_wdma_5a(
int port,
int slot,
int cmd, u8 *buf,
int pos)
232 u8 *p = mcman_sio2packet.in_dma.addr + pos;
238static void sio2packet_add_wdma_00(
int port,
int slot,
int cmd, u8 *buf,
int pos)
245 u8 *p = mcman_sio2packet.in_dma.addr + pos;
252static void sio2packet_add_wdma_u8(
int port,
int slot,
int cmd, u8 *buf,
int pos)
258 u8 *p = mcman_sio2packet.in_dma.addr + pos;
264static void sio2packet_add_do_nothing(
int port,
int slot,
int cmd, u8 *buf,
int pos)
278#ifdef BUILDING_XMCMAN
283 DPRINTF(
"mcsio2_transfer port%d slot%d\n", port, slot);
290 port_ctrl[(port & 1) + 2] = slot;
292 sio2_mc_transfer_init();
293 sio2_mtap_change_slot(port_ctrl);
294 r = sio2_transfer(sio2data);
295 sio2_transfer_reset();
297 DPRINTF(
"mcsio2_transfer returns %d\n", r);
307 u8 *p = (u8 *)(sio2data->in_dma.addr);
309 DPRINTF(
"mcsio2_transfer port%d slot%d cmd = %02x %02x %02x ", port, slot, p[0], p[1], p[2]);
311 p = (u8 *)(sio2data->in);
312 DPRINTF(
"mcsio2_transfer for secrman port%d slot%d cmd = %02x %02x %02x ", port, slot, p[0], p[1], p[2]);
317 sio2_mc_transfer_init();
318 r = sio2_transfer(sio2data);
320 DPRINTF(
"returns %d\n", r);
328void mcman_initPS2com(
void)
330#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
331 mcman_wmemset((
void *)&mcman_sio2packet,
sizeof (mcman_sio2packet), 0);
333 mcman_sio2packet.port_ctrl1[2] = 0xff020405;
334 mcman_sio2packet.port_ctrl1[3] = 0xff020405;
335 mcman_sio2packet.port_ctrl2[2] = 0x0005ffff & ~0x03000000;
336 mcman_sio2packet.port_ctrl2[3] = 0x0005ffff & ~0x03000000;
338 mcman_sio2packet.in_dma.addr = &mcman_wdmabufs;
339 mcman_sio2packet.in_dma.size = 0x24;
341 mcman_sio2packet.out_dma.addr = &mcman_rdmabufs;
342 mcman_sio2packet.out_dma.size = 0x24;
344 DPRINTF(
"mcman_initPS2com registering secrman_mc_command callback\n");
345 SecrSetMcCommandHandler((
void *)secrman_mc_command);
347 DPRINTF(
"mcman_initPS2com registering mcman_getcnum callback\n");
349 SecrSetMcDevIDHandler((
void *)mcman_getcnum);
350#elif defined(BUILDING_XFROMMAN)
352 flash_get_info(&dev9_flash_info);
357void mcman_deinitPS2com(
void)
359#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
360 SecrSetMcCommandHandler(0);
361 SecrSetMcDevIDHandler(0);
366void mcman_initPS1PDAcom(
void)
368#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
369 memset((
void *)&mcman_sio2packet_PS1PDA, 0,
sizeof (mcman_sio2packet_PS1PDA));
371 mcman_sio2packet_PS1PDA.port_ctrl1[0] = 0xffc00505;
372 mcman_sio2packet_PS1PDA.port_ctrl1[1] = 0xffc00505;
373 mcman_sio2packet_PS1PDA.port_ctrl1[2] = 0xffc00505;
374 mcman_sio2packet_PS1PDA.port_ctrl1[3] = 0xffc00505;
376 mcman_sio2packet_PS1PDA.port_ctrl2[0] = 0x000201f4 & ~0x03000000;
377 mcman_sio2packet_PS1PDA.port_ctrl2[1] = 0x000201f4 & ~0x03000000;
378 mcman_sio2packet_PS1PDA.port_ctrl2[2] = 0x000201f4 & ~0x03000000;
379 mcman_sio2packet_PS1PDA.port_ctrl2[3] = 0x000201f4 & ~0x03000000;
381 mcman_sio2packet_PS1PDA.in = (u8 *)&mcman_sio2inbufs_PS1PDA;
382 mcman_sio2packet_PS1PDA.out = (u8 *)&mcman_sio2outbufs_PS1PDA;
387void mcman_deinitPS1PDAcom(
void)
392#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
398 DPRINTF(
"secrman_mc_command port%d slot%d\n", port, slot);
400 r = mcsio2_transfer(port, slot, sio2data);
407int mcman_cardchanged(
int port,
int slot)
409#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
410 register int retries;
411 u8 *p = mcman_sio2packet.out_dma.addr;
413 DPRINTF(
"mcman_cardchanged sio2cmd port%d slot%d\n", port, slot);
415 sio2packet_add(port, slot, 0xffffffff, NULL);
416 sio2packet_add(port, slot, 0x00, NULL);
417 sio2packet_add(port, slot, 0xfffffffe, NULL);
421 mcsio2_transfer(port, slot, &mcman_sio2packet);
423 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[3] != 0x66))
426 }
while (++retries < 5);
429 DPRINTF(
"mcman_cardchanged sio2cmd card changed!\n");
430 return sceMcResChangedCard;
433 DPRINTF(
"mcman_cardchanged sio2cmd succeeded\n");
439#if defined(BUILDING_VMCMAN)
440 return sceMcResChangedCard;
442 return sceMcResSucceed;
447int mcman_eraseblock(
int port,
int slot,
int block,
void **pagebuf,
void *eccbuf)
449 register int retries, size, ecc_offset;
451#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
452 u8 *p = mcman_sio2packet.out_dma.addr;
455 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
457 page = block * mcdi->blocksize;
459#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
460 sio2packet_add(port, slot, 0xffffffff, NULL);
461 sio2packet_add(port, slot, 0x02, (u8 *)&page);
462 sio2packet_add(port, slot, 0x0d, NULL);
463 sio2packet_add(port, slot, 0xfffffffe, NULL);
468#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
469 mcsio2_transfer(port, slot, &mcman_sio2packet);
471 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000) || (p[8] != 0x5a))
476#elif defined(BUILDING_VMCMAN)
477 if (!mcman_iomanx_backing_erase(port, slot, page))
479#elif defined(BUILDING_XFROMMAN)
480 if (!flash_page_erase(&dev9_flash_info, page))
483 }
while (++retries < 5);
486 return sceMcResChangedCard;
488 if (pagebuf && eccbuf) {
489 mcman_wmemset(eccbuf, 32, 0);
492 while (page < mcdi->blocksize) {
493 ecc_offset = page * mcdi->pagesize;
496 ecc_offset = ecc_offset >> 5;
497 p_ecc = (
void *)((u8 *)eccbuf + ecc_offset);
499 while (size < mcdi->pagesize) {
501 McDataChecksum((
void *)((u8 *)(*pagebuf) + size), p_ecc);
503 p_ecc = (
void *)((u8 *)p_ecc + 3);
510#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
511 sio2packet_add(port, slot, 0xffffffff, NULL);
512 sio2packet_add(port, slot, 0x01, NULL);
513 sio2packet_add(port, slot, 0xfffffffe, NULL);
517 mcsio2_transfer(port, slot, &mcman_sio2packet);
519 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000))
523 return sceMcResSucceed;
524 }
while (++retries < 100);
527 return sceMcResFailReplace;
530 return sceMcResNoFormat;
534int McWritePage(
int port,
int slot,
int page,
void *pagebuf,
void *eccbuf)
536 register int retries;
537#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
538 register int index,
count;
539 u8 *p_pagebuf = (u8 *)pagebuf;
540 u8 *p = mcman_sio2packet.out_dma.addr;
543#ifdef BUILDING_XFROMMAN
547 memcpy(page_buf, pagebuf, 512);
548 memcpy(page_buf + 512, eccbuf, 16);
551#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
552 count = (mcman_devinfos[port][slot].pagesize + 127) >> 7;
558#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
560 mcman_cardchanged(port, slot);
562 sio2packet_add(port, slot, 0xffffffff, NULL);
563 sio2packet_add(port, slot, 0x03, (u8 *)&page);
566 while (index <
count) {
567 sio2packet_add(port, slot, 0x0a, (u8 *)&p_pagebuf[index << 7]);
571 if (mcman_devinfos[port][slot].cardflags & CF_USE_ECC) {
573 sio2packet_add(port, slot, 0x0e, eccbuf);
575 sio2packet_add(port, slot, 0xfffffffe, NULL);
577 mcsio2_transfer(port, slot, &mcman_sio2packet);
579 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000) || (p[8] != 0x5a))
583 while (index <
count) {
584 if (p[0x94 + 128 + 1 + ((index + (index << 3)) << 4)] != 0x5a)
592 if (mcman_devinfos[port][slot].cardflags & CF_USE_ECC) {
595 if (p[5 + ((index + (index << 3)) << 4) + mcman_sparesize(port, slot)] != 0x5a)
599 sio2packet_add(port, slot, 0xffffffff, NULL);
600 sio2packet_add(port, slot, 0x0c, NULL);
601 sio2packet_add(port, slot, 0xfffffffe, NULL);
603 mcsio2_transfer(port, slot, &mcman_sio2packet);
605 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000) || (p[3] != 0x5a))
607#elif defined(BUILDING_VMCMAN)
608 if (mcman_iomanx_backing_write(port, slot, page, pagebuf, eccbuf))
610#elif defined(BUILDING_XFROMMAN)
611 if (flash_page_write(&dev9_flash_info, page, page_buf))
614 return sceMcResSucceed;
616 }
while (++retries < 5);
618#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
620 return sceMcResFailReplace;
622 return sceMcResNoFormat;
624 return sceMcResFailReplace;
629int mcman_readpage(
int port,
int slot,
int page,
void *buf,
void *eccbuf)
631#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
632 register int index,
count, retries, r, i;
633 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
634 u8 *
pbuf = (u8 *)buf;
635 u8 *pecc = (u8 *)eccbuf;
636 u8 *p = mcman_sio2packet.out_dma.addr;
638 count = (mcdi->pagesize + 127) >> 7;
644 mcman_cardchanged(port, slot);
646 sio2packet_add(port, slot, 0xffffffff, NULL);
647 sio2packet_add(port, slot, 0x04, (u8 *)&page);
651 while (index <
count) {
652 sio2packet_add(port, slot, 0x0b, NULL);
657 if (mcdi->cardflags & CF_USE_ECC)
658 sio2packet_add(port, slot, 0x0f, NULL);
660 sio2packet_add(port, slot, 0x0c, NULL);
661 sio2packet_add(port, slot, 0xfffffffe, NULL);
663 mcsio2_transfer(port, slot, &mcman_sio2packet);
665 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000)
667 || (p[0x94 + 0x2cf] != 0x5a))
672 while (index <
count) {
674 r = mcman_calcEDC(&p[0x94 + ((index + (index << 3)) << 4)], 128) & 0xFF;
675 if (r != p[0x94 + 128 + ((index + (index << 3)) << 4)])
684 while (index <
count) {
685 for (i=0; i<128; i++)
686 pbuf[(index << 7) + i] = p[0x94 + ((index + (index << 3)) << 4) + i];
691 memcpy(pecc, &p[0x94 + ((
count + (
count << 3)) << 4)] , mcman_sparesize(port, slot));
694 }
while (++retries < 5);
697 return sceMcResSucceed;
698#elif defined(BUILDING_VMCMAN)
699 if (!mcman_iomanx_backing_read(port, slot, page, buf, eccbuf)) {
700 return sceMcResSucceed;
702#elif defined(BUILDING_XFROMMAN)
707 if (!flash_page_read(&dev9_flash_info, page, 1, page_buf))
711 memcpy(buf, page_buf, 512);
715 memcpy(eccbuf, page_buf + 512, 16);
717 return sceMcResSucceed;
720 return sceMcResChangedCard;
724int McGetCardSpec(
int port,
int slot, s16 *pagesize, u16 *blocksize,
int *cardsize, u8 *flags)
726#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
727 register int retries, r;
728 u8 *p = mcman_sio2packet.out_dma.addr;
730 DPRINTF(
"McGetCardSpec sio2cmd port%d slot%d\n", port, slot);
732 sio2packet_add(port, slot, 0xffffffff, NULL);
733 sio2packet_add(port, slot, 0x07, NULL);
734 sio2packet_add(port, slot, 0xfffffffe, NULL);
739 mcsio2_transfer(port, slot, &mcman_sio2packet);
741 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[12] == 0x5a)) {
743 r = mcman_calcEDC(&p[3], 8) & 0xFF;
747 }
while (++retries < 5);
750 return sceMcResChangedCard;
752 *pagesize = (p[4] << 8) + p[3];
753 *blocksize = (p[6] << 8) + p[5];
754 *cardsize = (p[8] << 8) + p[7] + (p[9] << 16) + (p[10] << 24);
756#elif defined(BUILDING_VMCMAN)
757 if (mcman_iomanx_backing_getcardspec(port, slot, pagesize, blocksize, cardsize, flags))
758 return sceMcResFailDetect2;
759#elif defined(BUILDING_XFROMMAN)
762 flash_get_info(&dev9_flash_info);
764 *blocksize = dev9_flash_info.block_pages;
765 *cardsize = dev9_flash_info.blocks * dev9_flash_info.block_pages;
766 *flags = 0x22 | CF_BAD_BLOCK;
767 if (dev9_flash_info.page_bytes != 512)
768 *flags |= CF_USE_ECC;
771 DPRINTF(
"McGetCardSpec sio2cmd pagesize=%d blocksize=%u cardsize=%d flags%x\n", *pagesize, *blocksize, *cardsize, *flags);
773 return sceMcResSucceed;
777int mcman_resetauth(
int port,
int slot)
779#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
780 register int retries;
782 DPRINTF(
"mcman_resetauth sio2cmd port%d slot%d\n", port, slot);
784 sio2packet_add(port, slot, 0xffffffff, NULL);
785 sio2packet_add(port, slot, 0x11, NULL);
786 sio2packet_add(port, slot, 0xfffffffe, NULL);
791 mcsio2_transfer(port, slot, &mcman_sio2packet);
793 if ((mcman_sio2packet.stat6c & 0xF000) == 0x1000)
796 }
while (++retries < 5);
799 DPRINTF(
"mcman_resetauth sio2cmd card changed!\n");
801 return sceMcResChangedCard;
804 DPRINTF(
"mcman_resetauth sio2cmd succeeded\n");
810 return sceMcResSucceed;
814int mcman_probePS2Card2(
int port,
int slot)
816#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
817 register int retries, r;
818 u8 *p = mcman_sio2packet.out_dma.addr;
820 DPRINTF(
"mcman_probePS2Card2 sio2cmd port%d slot%d\n", port, slot);
824 sio2packet_add(port, slot, 0xffffffff, NULL);
825 sio2packet_add(port, slot, 0x09, NULL);
826 sio2packet_add(port, slot, 0xfffffffe, NULL);
828 mcsio2_transfer(port, slot, &mcman_sio2packet);
830 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[4] != 0x66))
832 }
while (++retries < 5);
835 return sceMcResFailDetect;
838 r = McGetFormat(port, slot);
841 DPRINTF(
"mcman_probePS2Card2 succeeded\n");
843 return sceMcResSucceed;
847 DPRINTF(
"mcman_probePS2Card2 sio2cmd failed (no format)\n");
849 return sceMcResNoFormat;
853 DPRINTF(
"mcman_probePS2Card2 sio2cmd failed (mc detection failed)\n");
855 if (!McGetFormat(port, slot))
857 mcman_probePS2Card(port, slot);
859 if (McGetFormat(port, slot) > 0)
860 return sceMcResSucceed;
861 if (McGetFormat(port, slot) < 0)
862 return sceMcResNoFormat;
865 return sceMcResFailDetect2;
869int mcman_probePS2Card(
int port,
int slot)
872#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
873 register int retries;
874 u8 *p = mcman_sio2packet.out_dma.addr;
877 DPRINTF(
"mcman_probePS2Card sio2cmd port%d slot%d\n", port, slot);
879 r = mcman_cardchanged(port, slot);
880 if (r == sceMcResSucceed) {
881 r = McGetFormat(port, slot);
884 DPRINTF(
"mcman_probePS2Card sio2cmd succeeded\n");
886 return sceMcResSucceed;
890 DPRINTF(
"mcman_probePS2Card sio2cmd failed (no format)\n");
892 return sceMcResNoFormat;
896#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
897 if (mcman_resetauth(port, slot) != sceMcResSucceed) {
898 DPRINTF(
"mcman_probePS2Card sio2cmd failed (auth reset failed)\n");
900 return sceMcResFailResetAuth;
903 if (SecrAuthCard(port + 2, slot, mcman_getcnum(port, slot)) == 0) {
904 DPRINTF(
"mcman_probePS2Card sio2cmd failed (auth failed)\n");
906 return sceMcResFailAuth;
911 sio2packet_add(port, slot, 0xffffffff, NULL);
912 sio2packet_add(port, slot, 0x09, NULL);
913 sio2packet_add(port, slot, 0xfffffffe, NULL);
915 mcsio2_transfer(port, slot, &mcman_sio2packet);
917 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[4] != 0x66))
919 }
while (++retries < 5);
922 DPRINTF(
"mcman_probePS2Card sio2cmd failed (mc detection failed)\n");
923 return sceMcResFailDetect;
927 mcman_clearcache(port, slot);
929#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
930 sio2packet_add(port, slot, 0xffffffff, NULL);
931 sio2packet_add(port, slot, 0x08, NULL);
932 sio2packet_add(port, slot, 0xfffffffe, NULL);
936 mcsio2_transfer(port, slot, &mcman_sio2packet);
938 if ((mcman_sio2packet.stat6c & 0xF000) != 0x1000)
943 }
while (++retries < 5);
946 DPRINTF(
"mcman_probePS2Card sio2cmd failed (mc detection failed)\n");
948 return sceMcResFailDetect2;
952 r = mcman_setdevinfos(port, slot);
954 DPRINTF(
"mcman_probePS2Card sio2cmd card changed!\n");
955 return sceMcResChangedCard;
957 if (r != sceMcResNoFormat) {
958 DPRINTF(
"mcman_probePS2Card sio2cmd failed (mc detection failed)\n");
959 return sceMcResFailDetect2;
962 DPRINTF(
"mcman_probePS2Card sio2cmd succeeded\n");
968int mcman_probePS1Card2(
int port,
int slot)
970#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
971 register int retries;
972 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
974 DPRINTF(
"mcman_probePS1Card2 port%d slot%d\n", port, slot);
976 mcman_sio2packet_PS1PDA.regdata[0] = 0;
977 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2)) | 0x000c0340;
978 mcman_sio2packet_PS1PDA.in_size = 3;
979 mcman_sio2packet_PS1PDA.out_size = 3;
981 mcman_sio2packet_PS1PDA.regdata[1] = 0;
982 mcman_sio2inbufs_PS1PDA[0] = 0x81;
983 mcman_sio2inbufs_PS1PDA[1] = 0x52;
987 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
990 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
992 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
993 DelayThread(mcman_timerthick - (hi >> 3));
995 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
997 mcman_timercount = GetTimerCounter(timer_ID);
998 mcman_timerthick = 0;
1000 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1001 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a)) {
1004 }
while (++retries < 5);
1009 if (mcman_sio2outbufs_PS1PDA[1] == 0) {
1010 if (mcdi->cardform > 0)
1011 return sceMcResSucceed;
1012 else if (mcdi->cardform < 0)
1013 return sceMcResNoFormat;
1015 else if (mcman_sio2outbufs_PS1PDA[1] != 8) {
1027int mcman_probePS1Card(
int port,
int slot)
1029#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1030 register int i, r, retries;
1031 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1034 DPRINTF(
"mcman_probePS1Card port%d slot%d\n", port, slot);
1036 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1037 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2)) | 0x000c0340;
1038 mcman_sio2packet_PS1PDA.in_size = 3;
1039 mcman_sio2packet_PS1PDA.out_size = 3;
1041 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1042 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1043 mcman_sio2inbufs_PS1PDA[1] = 0x52;
1047 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1050 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1052 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1053 DelayThread(mcman_timerthick - (hi >> 3));
1055 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1057 mcman_timercount = GetTimerCounter(timer_ID);
1058 mcman_timerthick = 0;
1060 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1061 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a)) {
1064 }
while (++retries < 5);
1069 if (mcman_sio2outbufs_PS1PDA[1] == 0) {
1070 if (mcdi->cardform != 0)
1071 return sceMcResSucceed;
1073 return sceMcResNoFormat;
1075 else if (mcman_sio2outbufs_PS1PDA[1] != 8) {
1079 mcman_clearcache(port, slot);
1081 p = (u32 *)&mcman_sio2outbufs_PS1PDA[124];
1082 for (i = 31; i >= 0; i--)
1085 r = McWritePS1PDACard(port, slot, 63, mcman_sio2outbufs_PS1PDA);
1089 r = mcman_setPS1devinfos(port, slot);
1091 return sceMcResChangedCard;
1097 return sceMcResSucceed;
1102int mcman_probePDACard(
int port,
int slot)
1104#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1105 register int retries;
1107 DPRINTF(
"mcman_probePDACard port%d slot%d\n", port, slot);
1109 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1110 mcman_sio2packet_PS1PDA.regdata[0] = (port & 3) | 0x00140540;
1111 mcman_sio2packet_PS1PDA.in_size = 5;
1112 mcman_sio2packet_PS1PDA.out_size = 5;
1114 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1115 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1116 mcman_sio2inbufs_PS1PDA[1] = 0x58;
1120 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1122 if ((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000)
1125 }
while (++retries < 5);
1134 return sceMcResSucceed;
1138int McWritePS1PDACard(
int port,
int slot,
int page,
void *buf)
1140#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1141 register int i, retries;
1142 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1147 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1148 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2) & 3) | 0x02288a40;
1149 mcman_sio2packet_PS1PDA.in_size = 138;
1150 mcman_sio2packet_PS1PDA.out_size = 138;
1151 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1153 for (i = 0; i < 20; i++) {
1154 if (mcdi->bad_block_list[i] == page)
1158 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1159 mcman_sio2inbufs_PS1PDA[1] = 0x57;
1160 mcman_sio2inbufs_PS1PDA[4] = (u8)(page >> 8);
1161 mcman_sio2inbufs_PS1PDA[5] = (u8)page;
1164 for (i = 0; i < 128; i++)
1165 mcman_sio2inbufs_PS1PDA[6 + i] = p[i];
1167 mcman_sio2inbufs_PS1PDA[4 + 130] = mcman_calcEDC(&mcman_sio2inbufs_PS1PDA[4], 130);
1171 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1174 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1176 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1177 DelayThread(mcman_timerthick - (hi >> 3));
1179 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1181 mcman_timercount = GetTimerCounter(timer_ID);
1182 mcman_timerthick = 20000;
1184 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1185 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a) \
1186 && (mcman_sio2outbufs_PS1PDA[3] == 0x5d) \
1187 && (mcman_sio2outbufs_PS1PDA[137] == 0x47)) {
1190 }
while (++retries < 5);
1193 return sceMcResNoEntry;
1195 if ((mcman_sio2outbufs_PS1PDA[1] != 0) && (mcman_sio2outbufs_PS1PDA[1] != 8))
1196 return sceMcResFullDevice;
1204 return sceMcResSucceed;
1208int McReadPS1PDACard(
int port,
int slot,
int page,
void *buf)
1210#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1211 register int i, retries;
1212 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1217 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1218 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2) & 3) | 0x02308c40;
1219 mcman_sio2packet_PS1PDA.in_size = 140;
1220 mcman_sio2packet_PS1PDA.out_size = 140;
1221 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1223 for (i = 0; i < 20; i++) {
1224 if (mcdi->bad_block_list[i] == page)
1228 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1229 mcman_sio2inbufs_PS1PDA[1] = 0x52;
1230 mcman_sio2inbufs_PS1PDA[4] = (u8)(page >> 8);
1231 mcman_sio2inbufs_PS1PDA[5] = (u8)page;
1235 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1238 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1240 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1241 DelayThread(mcman_timerthick - (hi >> 3));
1243 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1245 mcman_timercount = GetTimerCounter(timer_ID);
1246 mcman_timerthick = 10000;
1248 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1249 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a) \
1250 && (mcman_sio2outbufs_PS1PDA[3] == 0x5d) \
1251 && (mcman_sio2outbufs_PS1PDA[4] == 0x00) \
1252 && (mcman_sio2outbufs_PS1PDA[6] == 0x5c) \
1253 && (mcman_sio2outbufs_PS1PDA[7] == 0x5d) \
1254 && (mcman_sio2outbufs_PS1PDA[139] == 0x47)) {
1256 if (mcman_sio2outbufs_PS1PDA[138] == (mcman_calcEDC(&mcman_sio2outbufs_PS1PDA[8], 130) & 0xff))
1259 }
while (++retries < 5);
1262 return sceMcResNoEntry;
1265 for (i = 0; i < 128; i++)
1266 p[i] = mcman_sio2outbufs_PS1PDA[10 + i];
1268 if ((mcman_sio2outbufs_PS1PDA[1] != 0) && (mcman_sio2outbufs_PS1PDA[1] != 8))
1269 return sceMcResDeniedPermit;
1277 return sceMcResSucceed;
u32 count
start sector of fragmented bd/file