12 #include "mcman-internal.h"
14 #ifdef BUILDING_XFROMMAN
18 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
20 static u8 mcman_wdmabufs[0x0b * 0x90];
21 static u8 mcman_rdmabufs[0x0b * 0x90];
24 static u8 mcman_sio2inbufs_PS1PDA[0x90];
25 u8 mcman_sio2outbufs_PS1PDA[0x90];
27 static u32 mcman_timercount;
28 static int mcman_timerthick;
33 static const u8 mcman_cmdtable[36] = {
55 static void (*sio2packet_add_func)(
int port,
int slot,
int cmd, u8 *buf,
int pos);
56 static void sio2packet_add_wdma_u32(
int port,
int slot,
int cmd, u8 *buf,
int pos);
57 static void sio2packet_add_pagedata_out(
int port,
int slot,
int cmd, u8 *buf,
int pos);
58 static void sio2packet_add_pagedata_in(
int port,
int slot,
int cmd, u8 *buf,
int pos);
59 static void sio2packet_add_ecc_in(
int port,
int slot,
int cmd, u8 *buf,
int pos);
60 static void sio2packet_add_ecc_out(
int port,
int slot,
int cmd, u8 *buf,
int pos);
61 static void sio2packet_add_wdma_5a(
int port,
int slot,
int cmd, u8 *buf,
int pos);
62 static void sio2packet_add_wdma_00(
int port,
int slot,
int cmd, u8 *buf,
int pos);
63 static void sio2packet_add_wdma_u8(
int port,
int slot,
int cmd, u8 *buf,
int pos);
64 static void sio2packet_add_do_nothing(
int port,
int slot,
int cmd, u8 *buf,
int pos);
67 static 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
87 void 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);
131 static 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);
147 static void sio2packet_add_pagedata_out(
int port,
int slot,
int cmd, u8 *buf,
int pos)
155 u8 *p = mcman_sio2packet.in_dma.addr + pos;
161 static 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);
180 static 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;
204 static 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;
224 static void sio2packet_add_wdma_5a(
int port,
int slot,
int cmd, u8 *buf,
int pos)
232 u8 *p = mcman_sio2packet.in_dma.addr + pos;
238 static void sio2packet_add_wdma_00(
int port,
int slot,
int cmd, u8 *buf,
int pos)
245 u8 *p = mcman_sio2packet.in_dma.addr + pos;
252 static void sio2packet_add_wdma_u8(
int port,
int slot,
int cmd, u8 *buf,
int pos)
258 u8 *p = mcman_sio2packet.in_dma.addr + pos;
264 static 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);
328 void 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);
351 #ifdef BUILDING_DONGLEMAN
353 sema_hakama.attr = 1;
354 sema_hakama.initial = 1;
356 sema_hakama.option = 0;
357 sema_hakama_id = CreateSema(&sema_hakama);
360 #elif defined(BUILDING_XFROMMAN)
362 flash_get_info(&dev9_flash_info);
367 void mcman_deinitPS2com(
void)
369 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
370 SecrSetMcCommandHandler(0);
371 SecrSetMcDevIDHandler(0);
376 void mcman_initPS1PDAcom(
void)
378 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
379 memset((
void *)&mcman_sio2packet_PS1PDA, 0,
sizeof (mcman_sio2packet_PS1PDA));
381 mcman_sio2packet_PS1PDA.port_ctrl1[0] = 0xffc00505;
382 mcman_sio2packet_PS1PDA.port_ctrl1[1] = 0xffc00505;
383 mcman_sio2packet_PS1PDA.port_ctrl1[2] = 0xffc00505;
384 mcman_sio2packet_PS1PDA.port_ctrl1[3] = 0xffc00505;
386 mcman_sio2packet_PS1PDA.port_ctrl2[0] = 0x000201f4 & ~0x03000000;
387 mcman_sio2packet_PS1PDA.port_ctrl2[1] = 0x000201f4 & ~0x03000000;
388 mcman_sio2packet_PS1PDA.port_ctrl2[2] = 0x000201f4 & ~0x03000000;
389 mcman_sio2packet_PS1PDA.port_ctrl2[3] = 0x000201f4 & ~0x03000000;
391 mcman_sio2packet_PS1PDA.in = (u8 *)&mcman_sio2inbufs_PS1PDA;
392 mcman_sio2packet_PS1PDA.out = (u8 *)&mcman_sio2outbufs_PS1PDA;
397 void mcman_deinitPS1PDAcom(
void)
402 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
408 DPRINTF(
"secrman_mc_command port%d slot%d\n", port, slot);
410 r = mcsio2_transfer(port, slot, sio2data);
417 int mcman_cardchanged(
int port,
int slot)
419 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
420 register int retries;
421 u8 *p = mcman_sio2packet.out_dma.addr;
423 DPRINTF(
"mcman_cardchanged sio2cmd port%d slot%d\n", port, slot);
425 sio2packet_add(port, slot, 0xffffffff, NULL);
426 sio2packet_add(port, slot, 0x00, NULL);
427 sio2packet_add(port, slot, 0xfffffffe, NULL);
431 mcsio2_transfer(port, slot, &mcman_sio2packet);
433 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[3] != 0x66))
436 }
while (++retries < 5);
439 DPRINTF(
"mcman_cardchanged sio2cmd card changed!\n");
440 return sceMcResChangedCard;
443 DPRINTF(
"mcman_cardchanged sio2cmd succeeded\n");
449 #if defined(BUILDING_VMCMAN)
450 return sceMcResChangedCard;
452 return sceMcResSucceed;
457 int mcman_eraseblock(
int port,
int slot,
int block,
void **pagebuf,
void *eccbuf)
459 register int retries, size, ecc_offset;
462 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
463 u8 *p = mcman_sio2packet.out_dma.addr;
466 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
468 page = block * mcdi->blocksize;
470 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
471 sio2packet_add(port, slot, 0xffffffff, NULL);
472 sio2packet_add(port, slot, 0x02, (u8 *)&page);
473 sio2packet_add(port, slot, 0x0d, NULL);
474 sio2packet_add(port, slot, 0xfffffffe, NULL);
479 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
480 mcsio2_transfer(port, slot, &mcman_sio2packet);
482 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000) || (p[8] != 0x5a))
487 #elif defined(BUILDING_VMCMAN)
488 if (!mcman_iomanx_backing_erase(port, slot, page))
490 #elif defined(BUILDING_XFROMMAN)
491 if (!flash_page_erase(&dev9_flash_info, page))
494 }
while (++retries < 5);
497 return sceMcResChangedCard;
499 if (pagebuf && eccbuf) {
500 mcman_wmemset(eccbuf, 32, 0);
503 while (page < mcdi->blocksize) {
504 ecc_offset = page * mcdi->pagesize;
507 ecc_offset = ecc_offset >> 5;
508 p_ecc = (
void *)((u8 *)eccbuf + ecc_offset);
510 while (size < mcdi->pagesize) {
512 McDataChecksum((
void *)((u8 *)(*pagebuf) + size), p_ecc);
514 p_ecc = (
void *)((u8 *)p_ecc + 3);
521 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
522 sio2packet_add(port, slot, 0xffffffff, NULL);
523 sio2packet_add(port, slot, 0x01, NULL);
524 sio2packet_add(port, slot, 0xfffffffe, NULL);
528 mcsio2_transfer(port, slot, &mcman_sio2packet);
530 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000))
535 return sceMcResSucceed;
537 }
while (++retries < 100);
542 return sceMcResFailReplace;
545 return sceMcResNoFormat;
548 return sceMcResSucceed;
553 int McWritePage(
int port,
int slot,
int page,
void *pagebuf,
void *eccbuf)
555 register int retries;
556 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
557 register int index,
count;
558 u8 *p_pagebuf = (u8 *)pagebuf;
559 u8 *p = mcman_sio2packet.out_dma.addr;
564 #ifdef BUILDING_XFROMMAN
568 memcpy(page_buf, pagebuf, 512);
569 memcpy(page_buf + 512, eccbuf, 16);
572 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
573 count = (mcman_devinfos[port][slot].pagesize + 127) >> 7;
579 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
581 mcman_cardchanged(port, slot);
583 sio2packet_add(port, slot, 0xffffffff, NULL);
584 sio2packet_add(port, slot, 0x03, (u8 *)&page);
587 while (index <
count) {
588 sio2packet_add(port, slot, 0x0a, (u8 *)&p_pagebuf[index << 7]);
592 if (mcman_devinfos[port][slot].cardflags & CF_USE_ECC) {
594 sio2packet_add(port, slot, 0x0e, eccbuf);
596 sio2packet_add(port, slot, 0xfffffffe, NULL);
598 mcsio2_transfer(port, slot, &mcman_sio2packet);
600 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000) || (p[8] != 0x5a))
604 while (index <
count) {
605 if (p[0x94 + 128 + 1 + ((index + (index << 3)) << 4)] != 0x5a)
613 if (mcman_devinfos[port][slot].cardflags & CF_USE_ECC) {
616 if (p[5 + ((index + (index << 3)) << 4) + mcman_sparesize(port, slot)] != 0x5a)
620 sio2packet_add(port, slot, 0xffffffff, NULL);
621 sio2packet_add(port, slot, 0x0c, NULL);
622 sio2packet_add(port, slot, 0xfffffffe, NULL);
624 mcsio2_transfer(port, slot, &mcman_sio2packet);
626 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000) || (p[3] != 0x5a))
628 #elif defined(BUILDING_VMCMAN)
629 if (mcman_iomanx_backing_write(port, slot, page, pagebuf, eccbuf))
631 #elif defined(BUILDING_XFROMMAN)
632 if (flash_page_write(&dev9_flash_info, page, page_buf))
636 return sceMcResSucceed;
638 }
while (++retries < 5);
640 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
644 return sceMcResFailReplace;
648 return sceMcResNoFormat;
650 return sceMcResFailReplace;
655 int mcman_readpage(
int port,
int slot,
int page,
void *buf,
void *eccbuf)
657 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
658 register int index,
count, retries, r, i;
659 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
660 u8 *
pbuf = (u8 *)buf;
661 u8 *pecc = (u8 *)eccbuf;
662 u8 *p = mcman_sio2packet.out_dma.addr;
664 count = (mcdi->pagesize + 127) >> 7;
670 mcman_cardchanged(port, slot);
672 sio2packet_add(port, slot, 0xffffffff, NULL);
673 sio2packet_add(port, slot, 0x04, (u8 *)&page);
677 while (index <
count) {
678 sio2packet_add(port, slot, 0x0b, NULL);
683 if (mcdi->cardflags & CF_USE_ECC)
684 sio2packet_add(port, slot, 0x0f, NULL);
686 sio2packet_add(port, slot, 0x0c, NULL);
687 sio2packet_add(port, slot, 0xfffffffe, NULL);
689 mcsio2_transfer(port, slot, &mcman_sio2packet);
691 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000)
693 || (p[0x94 + 0x2cf] != 0x5a))
698 while (index <
count) {
700 r = mcman_calcEDC(&p[0x94 + ((index + (index << 3)) << 4)], 128) & 0xFF;
701 if (r != p[0x94 + 128 + ((index + (index << 3)) << 4)])
710 while (index <
count) {
711 for (i=0; i<128; i++)
712 pbuf[(index << 7) + i] = p[0x94 + ((index + (index << 3)) << 4) + i];
717 memcpy(pecc, &p[0x94 + ((
count + (
count << 3)) << 4)] , mcman_sparesize(port, slot));
720 }
while (++retries < 5);
723 return sceMcResSucceed;
724 #elif defined(BUILDING_VMCMAN)
725 if (!mcman_iomanx_backing_read(port, slot, page, buf, eccbuf)) {
726 return sceMcResSucceed;
728 #elif defined(BUILDING_XFROMMAN)
733 if (!flash_page_read(&dev9_flash_info, page, 1, page_buf))
737 memcpy(buf, page_buf, 512);
741 memcpy(eccbuf, page_buf + 512, 16);
743 return sceMcResSucceed;
746 return sceMcResChangedCard;
750 int McGetCardSpec(
int port,
int slot, s16 *pagesize, u16 *blocksize,
int *cardsize, u8 *flags)
752 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
753 register int retries, r;
754 u8 *p = mcman_sio2packet.out_dma.addr;
756 DPRINTF(
"McGetCardSpec sio2cmd port%d slot%d\n", port, slot);
760 sio2packet_add(port, slot, 0xffffffff, NULL);
761 sio2packet_add(port, slot, 0x07, NULL);
762 sio2packet_add(port, slot, 0xfffffffe, NULL);
767 mcsio2_transfer(port, slot, &mcman_sio2packet);
769 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[12] == 0x5a)) {
771 r = mcman_calcEDC(&p[3], 8) & 0xFF;
775 }
while (++retries < 5);
779 return sceMcResChangedCard;
782 *pagesize = (p[4] << 8) + p[3];
783 *blocksize = (p[6] << 8) + p[5];
784 *cardsize = (p[8] << 8) + p[7] + (p[9] << 16) + (p[10] << 24);
786 #elif defined(BUILDING_VMCMAN)
787 if (mcman_iomanx_backing_getcardspec(port, slot, pagesize, blocksize, cardsize, flags))
788 return sceMcResFailDetect2;
789 #elif defined(BUILDING_XFROMMAN)
792 flash_get_info(&dev9_flash_info);
794 *blocksize = dev9_flash_info.block_pages;
795 *cardsize = dev9_flash_info.blocks * dev9_flash_info.block_pages;
796 *flags = 0x22 | CF_BAD_BLOCK;
797 if (dev9_flash_info.page_bytes != 512)
798 *flags |= CF_USE_ECC;
800 DPRINTF(
"McGetCardSpec sio2cmd pagesize=%d blocksize=%u cardsize=%d flags%x\n", *pagesize, *blocksize, *cardsize, *flags);
803 return sceMcResSucceed;
807 int mcman_resetauth(
int port,
int slot)
809 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
810 register int retries;
812 DPRINTF(
"mcman_resetauth sio2cmd port%d slot%d\n", port, slot);
814 sio2packet_add(port, slot, 0xffffffff, NULL);
815 sio2packet_add(port, slot, 0x11, NULL);
816 sio2packet_add(port, slot, 0xfffffffe, NULL);
821 mcsio2_transfer(port, slot, &mcman_sio2packet);
823 if ((mcman_sio2packet.stat6c & 0xF000) == 0x1000)
826 }
while (++retries < 5);
829 DPRINTF(
"mcman_resetauth sio2cmd card changed!\n");
831 return sceMcResChangedCard;
834 DPRINTF(
"mcman_resetauth sio2cmd succeeded\n");
840 return sceMcResSucceed;
844 int mcman_probePS2Card2(
int port,
int slot)
846 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
847 register int retries, r;
848 u8 *p = mcman_sio2packet.out_dma.addr;
850 DPRINTF(
"mcman_probePS2Card2 sio2cmd port%d slot%d\n", port, slot);
854 sio2packet_add(port, slot, 0xffffffff, NULL);
855 sio2packet_add(port, slot, 0x09, NULL);
856 sio2packet_add(port, slot, 0xfffffffe, NULL);
858 mcsio2_transfer(port, slot, &mcman_sio2packet);
860 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[4] != 0x66))
862 }
while (++retries < 5);
866 return sceMcResFailDetect;
870 r = McGetFormat(port, slot);
873 DPRINTF(
"mcman_probePS2Card2 succeeded\n");
875 return sceMcResSucceed;
879 DPRINTF(
"mcman_probePS2Card2 sio2cmd failed (no format)\n");
881 return sceMcResNoFormat;
885 DPRINTF(
"mcman_probePS2Card2 sio2cmd failed (mc detection failed)\n");
887 if (!McGetFormat(port, slot))
889 mcman_probePS2Card(port, slot);
891 if (McGetFormat(port, slot) > 0)
892 return sceMcResSucceed;
893 if (McGetFormat(port, slot) < 0)
894 return sceMcResNoFormat;
898 return sceMcResFailDetect2;
902 int mcman_probePS2Card(
int port,
int slot)
905 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
906 register int retries;
907 u8 *p = mcman_sio2packet.out_dma.addr;
912 DPRINTF(
"mcman_probePS2Card sio2cmd port%d slot%d\n", port, slot);
914 r = mcman_cardchanged(port, slot);
915 if (r == sceMcResSucceed) {
916 r = McGetFormat(port, slot);
917 #ifdef BUILDING_DONGLEMAN
918 if (r != 0 && port == 0) {
919 DPRINTF(
"mcman_probePS2Card:[McGetFormat() != 0]: calling authdongle(2, %d, %d)\n", slot, mcman_getcnum(port, slot));
920 SecrAuthDongle(2, slot, mcman_getcnum(port, slot));
925 DPRINTF(
"mcman_probePS2Card sio2cmd succeeded\n");
926 return sceMcResSucceed;
930 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
931 if (mcman_resetauth(port, slot) != sceMcResSucceed) {
932 DPRINTF(
"mcman_probePS2Card sio2cmd failed (auth reset failed)\n");
934 return sceMcResFailResetAuth;
937 #ifdef BUILDING_DONGLEMAN
939 DPRINTF(
"mcman_probePS2Card: SecrAuthDongle(2, %d, %d)\n", slot, mcman_getcnum(port, slot));
940 if (SecrAuthDongle(2, slot, mcman_getcnum(port, slot)) == 0) {
941 DPRINTF(
"mcman_probePS2Card SecrAuthDongle Failed\n");
943 return sceMcResFailAuth;
946 else if (SecrAuthCard(port + 2, slot, mcman_getcnum(port, slot)) == 0) {
947 DPRINTF(
"mcman_probePS2Card sio2cmd failed (auth failed)\n");
949 return sceMcResFailAuth;
952 if (SecrAuthCard(port + 2, slot, mcman_getcnum(port, slot)) == 0) {
953 DPRINTF(
"mcman_probePS2Card sio2cmd failed (auth failed)\n");
955 return sceMcResFailAuth;
961 sio2packet_add(port, slot, 0xffffffff, NULL);
962 sio2packet_add(port, slot, 0x09, NULL);
963 sio2packet_add(port, slot, 0xfffffffe, NULL);
965 mcsio2_transfer(port, slot, &mcman_sio2packet);
967 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[4] != 0x66))
969 }
while (++retries < 5);
972 DPRINTF(
"mcman_probePS2Card sio2cmd failed (mc detection failed)\n");
973 return sceMcResFailDetect;
977 mcman_clearcache(port, slot);
979 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
980 sio2packet_add(port, slot, 0xffffffff, NULL);
981 sio2packet_add(port, slot, 0x08, NULL);
982 sio2packet_add(port, slot, 0xfffffffe, NULL);
986 mcsio2_transfer(port, slot, &mcman_sio2packet);
988 if ((mcman_sio2packet.stat6c & 0xF000) != 0x1000)
993 }
while (++retries < 5);
996 DPRINTF(
"mcman_probePS2Card sio2cmd failed (mc detection failed)\n");
998 return sceMcResFailDetect2;
1002 r = mcman_setdevinfos(port, slot);
1004 DPRINTF(
"mcman_probePS2Card sio2cmd card changed!\n");
1005 return sceMcResChangedCard;
1007 if (r != sceMcResNoFormat) {
1008 DPRINTF(
"mcman_probePS2Card sio2cmd failed (mc detection failed)\n");
1009 return sceMcResFailDetect2;
1012 DPRINTF(
"mcman_probePS2Card sio2cmd succeeded\n");
1018 int mcman_probePS1Card2(
int port,
int slot)
1020 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1021 register int retries;
1022 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1024 DPRINTF(
"mcman_probePS1Card2 port%d slot%d\n", port, slot);
1026 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1027 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2)) | 0x000c0340;
1028 mcman_sio2packet_PS1PDA.in_size = 3;
1029 mcman_sio2packet_PS1PDA.out_size = 3;
1031 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1032 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1033 mcman_sio2inbufs_PS1PDA[1] = 0x52;
1037 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1040 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1042 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1043 DelayThread(mcman_timerthick - (hi >> 3));
1045 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1047 mcman_timercount = GetTimerCounter(timer_ID);
1048 mcman_timerthick = 0;
1050 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1051 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a)) {
1054 }
while (++retries < 5);
1059 if (mcman_sio2outbufs_PS1PDA[1] == 0) {
1060 if (mcdi->cardform > 0)
1061 return sceMcResSucceed;
1062 else if (mcdi->cardform < 0)
1063 return sceMcResNoFormat;
1065 else if (mcman_sio2outbufs_PS1PDA[1] != 8) {
1077 int mcman_probePS1Card(
int port,
int slot)
1079 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1080 register int i, r, retries;
1081 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1084 DPRINTF(
"mcman_probePS1Card port%d slot%d\n", port, slot);
1086 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1087 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2)) | 0x000c0340;
1088 mcman_sio2packet_PS1PDA.in_size = 3;
1089 mcman_sio2packet_PS1PDA.out_size = 3;
1091 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1092 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1093 mcman_sio2inbufs_PS1PDA[1] = 0x52;
1097 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1100 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1102 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1103 DelayThread(mcman_timerthick - (hi >> 3));
1105 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1107 mcman_timercount = GetTimerCounter(timer_ID);
1108 mcman_timerthick = 0;
1110 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1111 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a)) {
1114 }
while (++retries < 5);
1119 if (mcman_sio2outbufs_PS1PDA[1] == 0) {
1120 if (mcdi->cardform != 0)
1121 return sceMcResSucceed;
1123 return sceMcResNoFormat;
1125 else if (mcman_sio2outbufs_PS1PDA[1] != 8) {
1129 mcman_clearcache(port, slot);
1131 p = (u32 *)&mcman_sio2outbufs_PS1PDA[124];
1132 for (i = 31; i >= 0; i--)
1135 r = McWritePS1PDACard(port, slot, 63, mcman_sio2outbufs_PS1PDA);
1139 r = mcman_setPS1devinfos(port, slot);
1141 return sceMcResChangedCard;
1147 return sceMcResSucceed;
1152 int mcman_probePDACard(
int port,
int slot)
1154 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1155 register int retries;
1157 DPRINTF(
"mcman_probePDACard port%d slot%d\n", port, slot);
1159 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1160 mcman_sio2packet_PS1PDA.regdata[0] = (port & 3) | 0x00140540;
1161 mcman_sio2packet_PS1PDA.in_size = 5;
1162 mcman_sio2packet_PS1PDA.out_size = 5;
1164 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1165 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1166 mcman_sio2inbufs_PS1PDA[1] = 0x58;
1170 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1172 if ((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000)
1175 }
while (++retries < 5);
1184 return sceMcResSucceed;
1188 int McWritePS1PDACard(
int port,
int slot,
int page,
void *buf)
1190 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1191 register int i, retries;
1192 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1197 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1198 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2) & 3) | 0x02288a40;
1199 mcman_sio2packet_PS1PDA.in_size = 138;
1200 mcman_sio2packet_PS1PDA.out_size = 138;
1201 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1203 for (i = 0; i < 20; i++) {
1204 if (mcdi->bad_block_list[i] == page)
1208 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1209 mcman_sio2inbufs_PS1PDA[1] = 0x57;
1210 mcman_sio2inbufs_PS1PDA[4] = (u8)(page >> 8);
1211 mcman_sio2inbufs_PS1PDA[5] = (u8)page;
1214 for (i = 0; i < 128; i++)
1215 mcman_sio2inbufs_PS1PDA[6 + i] = p[i];
1217 mcman_sio2inbufs_PS1PDA[4 + 130] = mcman_calcEDC(&mcman_sio2inbufs_PS1PDA[4], 130);
1221 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1224 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1226 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1227 DelayThread(mcman_timerthick - (hi >> 3));
1229 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1231 mcman_timercount = GetTimerCounter(timer_ID);
1232 mcman_timerthick = 20000;
1234 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1235 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a) \
1236 && (mcman_sio2outbufs_PS1PDA[3] == 0x5d) \
1237 && (mcman_sio2outbufs_PS1PDA[137] == 0x47)) {
1240 }
while (++retries < 5);
1243 return sceMcResNoEntry;
1245 if ((mcman_sio2outbufs_PS1PDA[1] != 0) && (mcman_sio2outbufs_PS1PDA[1] != 8))
1246 return sceMcResFullDevice;
1254 return sceMcResSucceed;
1258 int McReadPS1PDACard(
int port,
int slot,
int page,
void *buf)
1260 #if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1261 register int i, retries;
1262 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1267 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1268 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2) & 3) | 0x02308c40;
1269 mcman_sio2packet_PS1PDA.in_size = 140;
1270 mcman_sio2packet_PS1PDA.out_size = 140;
1271 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1273 for (i = 0; i < 20; i++) {
1274 if (mcdi->bad_block_list[i] == page)
1278 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1279 mcman_sio2inbufs_PS1PDA[1] = 0x52;
1280 mcman_sio2inbufs_PS1PDA[4] = (u8)(page >> 8);
1281 mcman_sio2inbufs_PS1PDA[5] = (u8)page;
1285 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1288 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1290 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1291 DelayThread(mcman_timerthick - (hi >> 3));
1293 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1295 mcman_timercount = GetTimerCounter(timer_ID);
1296 mcman_timerthick = 10000;
1298 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1299 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a) \
1300 && (mcman_sio2outbufs_PS1PDA[3] == 0x5d) \
1301 && (mcman_sio2outbufs_PS1PDA[4] == 0x00) \
1302 && (mcman_sio2outbufs_PS1PDA[6] == 0x5c) \
1303 && (mcman_sio2outbufs_PS1PDA[7] == 0x5d) \
1304 && (mcman_sio2outbufs_PS1PDA[139] == 0x47)) {
1306 if (mcman_sio2outbufs_PS1PDA[138] == (mcman_calcEDC(&mcman_sio2outbufs_PS1PDA[8], 130) & 0xff))
1309 }
while (++retries < 5);
1312 return sceMcResNoEntry;
1315 for (i = 0; i < 128; i++)
1316 p[i] = mcman_sio2outbufs_PS1PDA[10 + i];
1318 if ((mcman_sio2outbufs_PS1PDA[1] != 0) && (mcman_sio2outbufs_PS1PDA[1] != 8))
1319 return sceMcResDeniedPermit;
1327 return sceMcResSucceed;