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);
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);
367void mcman_deinitPS2com(
void)
369#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
370 SecrSetMcCommandHandler(0);
371 SecrSetMcDevIDHandler(0);
376void 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;
397void 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);
417int 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;
457int 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;
546 return sceMcResNoFormat;
550int McWritePage(
int port,
int slot,
int page,
void *pagebuf,
void *eccbuf)
552 register int retries;
553#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
554 register int index,
count;
555 u8 *p_pagebuf = (u8 *)pagebuf;
556 u8 *p = mcman_sio2packet.out_dma.addr;
561#ifdef BUILDING_XFROMMAN
565 memcpy(page_buf, pagebuf, 512);
566 memcpy(page_buf + 512, eccbuf, 16);
569#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
570 count = (mcman_devinfos[port][slot].pagesize + 127) >> 7;
576#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
578 mcman_cardchanged(port, slot);
580 sio2packet_add(port, slot, 0xffffffff, NULL);
581 sio2packet_add(port, slot, 0x03, (u8 *)&page);
584 while (index <
count) {
585 sio2packet_add(port, slot, 0x0a, (u8 *)&p_pagebuf[index << 7]);
589 if (mcman_devinfos[port][slot].cardflags & CF_USE_ECC) {
591 sio2packet_add(port, slot, 0x0e, eccbuf);
593 sio2packet_add(port, slot, 0xfffffffe, NULL);
595 mcsio2_transfer(port, slot, &mcman_sio2packet);
597 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000) || (p[8] != 0x5a))
601 while (index <
count) {
602 if (p[0x94 + 128 + 1 + ((index + (index << 3)) << 4)] != 0x5a)
610 if (mcman_devinfos[port][slot].cardflags & CF_USE_ECC) {
613 if (p[5 + ((index + (index << 3)) << 4) + mcman_sparesize(port, slot)] != 0x5a)
617 sio2packet_add(port, slot, 0xffffffff, NULL);
618 sio2packet_add(port, slot, 0x0c, NULL);
619 sio2packet_add(port, slot, 0xfffffffe, NULL);
621 mcsio2_transfer(port, slot, &mcman_sio2packet);
623 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000) || (p[3] != 0x5a))
625#elif defined(BUILDING_VMCMAN)
626 if (mcman_iomanx_backing_write(port, slot, page, pagebuf, eccbuf))
628#elif defined(BUILDING_XFROMMAN)
629 if (flash_page_write(&dev9_flash_info, page, page_buf))
633 return sceMcResSucceed;
635 }
while (++retries < 5);
637#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
641 return sceMcResFailReplace;
645 return sceMcResNoFormat;
647 return sceMcResFailReplace;
652int mcman_readpage(
int port,
int slot,
int page,
void *buf,
void *eccbuf)
654#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
655 register int index,
count, retries, r, i;
656 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
657 u8 *
pbuf = (u8 *)buf;
658 u8 *pecc = (u8 *)eccbuf;
659 u8 *p = mcman_sio2packet.out_dma.addr;
661 count = (mcdi->pagesize + 127) >> 7;
667 mcman_cardchanged(port, slot);
669 sio2packet_add(port, slot, 0xffffffff, NULL);
670 sio2packet_add(port, slot, 0x04, (u8 *)&page);
674 while (index <
count) {
675 sio2packet_add(port, slot, 0x0b, NULL);
680 if (mcdi->cardflags & CF_USE_ECC)
681 sio2packet_add(port, slot, 0x0f, NULL);
683 sio2packet_add(port, slot, 0x0c, NULL);
684 sio2packet_add(port, slot, 0xfffffffe, NULL);
686 mcsio2_transfer(port, slot, &mcman_sio2packet);
688 if (((mcman_sio2packet.stat6c & 0xF000) != 0x1000)
690 || (p[0x94 + 0x2cf] != 0x5a))
695 while (index <
count) {
697 r = mcman_calcEDC(&p[0x94 + ((index + (index << 3)) << 4)], 128) & 0xFF;
698 if (r != p[0x94 + 128 + ((index + (index << 3)) << 4)])
707 while (index <
count) {
708 for (i=0; i<128; i++)
709 pbuf[(index << 7) + i] = p[0x94 + ((index + (index << 3)) << 4) + i];
714 memcpy(pecc, &p[0x94 + ((
count + (
count << 3)) << 4)] , mcman_sparesize(port, slot));
717 }
while (++retries < 5);
720 return sceMcResSucceed;
721#elif defined(BUILDING_VMCMAN)
722 if (!mcman_iomanx_backing_read(port, slot, page, buf, eccbuf)) {
723 return sceMcResSucceed;
725#elif defined(BUILDING_XFROMMAN)
730 if (!flash_page_read(&dev9_flash_info, page, 1, page_buf))
734 memcpy(buf, page_buf, 512);
738 memcpy(eccbuf, page_buf + 512, 16);
740 return sceMcResSucceed;
743 return sceMcResChangedCard;
747int McGetCardSpec(
int port,
int slot, s16 *pagesize, u16 *blocksize,
int *cardsize, u8 *flags)
749#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
750 register int retries, r;
751 u8 *p = mcman_sio2packet.out_dma.addr;
753 DPRINTF(
"McGetCardSpec sio2cmd port%d slot%d\n", port, slot);
757 sio2packet_add(port, slot, 0xffffffff, NULL);
758 sio2packet_add(port, slot, 0x07, NULL);
759 sio2packet_add(port, slot, 0xfffffffe, NULL);
764 mcsio2_transfer(port, slot, &mcman_sio2packet);
766 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[12] == 0x5a)) {
768 r = mcman_calcEDC(&p[3], 8) & 0xFF;
772 }
while (++retries < 5);
776 return sceMcResChangedCard;
779 *pagesize = (p[4] << 8) + p[3];
780 *blocksize = (p[6] << 8) + p[5];
781 *cardsize = (p[8] << 8) + p[7] + (p[9] << 16) + (p[10] << 24);
783#elif defined(BUILDING_VMCMAN)
784 if (mcman_iomanx_backing_getcardspec(port, slot, pagesize, blocksize, cardsize, flags))
785 return sceMcResFailDetect2;
786#elif defined(BUILDING_XFROMMAN)
789 flash_get_info(&dev9_flash_info);
791 *blocksize = dev9_flash_info.block_pages;
792 *cardsize = dev9_flash_info.blocks * dev9_flash_info.block_pages;
793 *flags = 0x22 | CF_BAD_BLOCK;
794 if (dev9_flash_info.page_bytes != 512)
795 *flags |= CF_USE_ECC;
797 DPRINTF(
"McGetCardSpec sio2cmd pagesize=%d blocksize=%u cardsize=%d flags%x\n", *pagesize, *blocksize, *cardsize, *flags);
800 return sceMcResSucceed;
804int mcman_resetauth(
int port,
int slot)
806#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
807 register int retries;
809 DPRINTF(
"mcman_resetauth sio2cmd port%d slot%d\n", port, slot);
811 sio2packet_add(port, slot, 0xffffffff, NULL);
812 sio2packet_add(port, slot, 0x11, NULL);
813 sio2packet_add(port, slot, 0xfffffffe, NULL);
818 mcsio2_transfer(port, slot, &mcman_sio2packet);
820 if ((mcman_sio2packet.stat6c & 0xF000) == 0x1000)
823 }
while (++retries < 5);
826 DPRINTF(
"mcman_resetauth sio2cmd card changed!\n");
828 return sceMcResChangedCard;
831 DPRINTF(
"mcman_resetauth sio2cmd succeeded\n");
837 return sceMcResSucceed;
841int mcman_probePS2Card2(
int port,
int slot)
843#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
844 register int retries, r;
845 u8 *p = mcman_sio2packet.out_dma.addr;
847 DPRINTF(
"mcman_probePS2Card2 sio2cmd port%d slot%d\n", port, slot);
851 sio2packet_add(port, slot, 0xffffffff, NULL);
852 sio2packet_add(port, slot, 0x09, NULL);
853 sio2packet_add(port, slot, 0xfffffffe, NULL);
855 mcsio2_transfer(port, slot, &mcman_sio2packet);
857 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[4] != 0x66))
859 }
while (++retries < 5);
863 return sceMcResFailDetect;
867 r = McGetFormat(port, slot);
870 DPRINTF(
"mcman_probePS2Card2 succeeded\n");
872 return sceMcResSucceed;
876 DPRINTF(
"mcman_probePS2Card2 sio2cmd failed (no format)\n");
878 return sceMcResNoFormat;
882 DPRINTF(
"mcman_probePS2Card2 sio2cmd failed (mc detection failed)\n");
884 if (!McGetFormat(port, slot))
886 mcman_probePS2Card(port, slot);
888 if (McGetFormat(port, slot) > 0)
889 return sceMcResSucceed;
890 if (McGetFormat(port, slot) < 0)
891 return sceMcResNoFormat;
895 return sceMcResFailDetect2;
899int mcman_probePS2Card(
int port,
int slot)
902#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
903 register int retries;
904 u8 *p = mcman_sio2packet.out_dma.addr;
909 DPRINTF(
"mcman_probePS2Card sio2cmd port%d slot%d\n", port, slot);
911 r = mcman_cardchanged(port, slot);
912 if (r == sceMcResSucceed) {
913 r = McGetFormat(port, slot);
914#ifdef BUILDING_DONGLEMAN
915 if (r != 0 && port == 0) {
916 DPRINTF(
"mcman_probePS2Card:[McGetFormat() != 0]: calling authdongle(2, %d, %d)\n", slot, mcman_getcnum(port, slot));
917 SecrAuthDongle(2, slot, mcman_getcnum(port, slot));
922 DPRINTF(
"mcman_probePS2Card sio2cmd succeeded\n");
924 return sceMcResSucceed;
928 DPRINTF(
"mcman_probePS2Card sio2cmd failed (no format)\n");
930 return sceMcResNoFormat;
934#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
935 if (mcman_resetauth(port, slot) != sceMcResSucceed) {
936 DPRINTF(
"mcman_probePS2Card sio2cmd failed (auth reset failed)\n");
938 return sceMcResFailResetAuth;
941#ifdef BUILDING_DONGLEMAN
943 DPRINTF(
"mcman_probePS2Card: SecrAuthDongle(2, %d, %d)\n", slot, mcman_getcnum(port, slot));
944 if (SecrAuthDongle(2, slot, mcman_getcnum(port, slot)) == 0) {
945 DPRINTF(
"mcman_probePS2Card SecrAuthDongle Failed\n");
947 return sceMcResFailAuth;
950 else if (SecrAuthCard(port + 2, slot, mcman_getcnum(port, slot)) == 0) {
951 DPRINTF(
"mcman_probePS2Card sio2cmd failed (auth failed)\n");
953 return sceMcResFailAuth;
956 if (SecrAuthCard(port + 2, slot, mcman_getcnum(port, slot)) == 0) {
957 DPRINTF(
"mcman_probePS2Card sio2cmd failed (auth failed)\n");
959 return sceMcResFailAuth;
965 sio2packet_add(port, slot, 0xffffffff, NULL);
966 sio2packet_add(port, slot, 0x09, NULL);
967 sio2packet_add(port, slot, 0xfffffffe, NULL);
969 mcsio2_transfer(port, slot, &mcman_sio2packet);
971 if (((mcman_sio2packet.stat6c & 0xF000) == 0x1000) && (p[4] != 0x66))
973 }
while (++retries < 5);
976 DPRINTF(
"mcman_probePS2Card sio2cmd failed (mc detection failed)\n");
977 return sceMcResFailDetect;
981 mcman_clearcache(port, slot);
983#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
984 sio2packet_add(port, slot, 0xffffffff, NULL);
985 sio2packet_add(port, slot, 0x08, NULL);
986 sio2packet_add(port, slot, 0xfffffffe, NULL);
990 mcsio2_transfer(port, slot, &mcman_sio2packet);
992 if ((mcman_sio2packet.stat6c & 0xF000) != 0x1000)
997 }
while (++retries < 5);
1000 DPRINTF(
"mcman_probePS2Card sio2cmd failed (mc detection failed)\n");
1002 return sceMcResFailDetect2;
1006 r = mcman_setdevinfos(port, slot);
1008 DPRINTF(
"mcman_probePS2Card sio2cmd card changed!\n");
1009 return sceMcResChangedCard;
1011 if (r != sceMcResNoFormat) {
1012 DPRINTF(
"mcman_probePS2Card sio2cmd failed (mc detection failed)\n");
1013 return sceMcResFailDetect2;
1016 DPRINTF(
"mcman_probePS2Card sio2cmd succeeded\n");
1022int mcman_probePS1Card2(
int port,
int slot)
1024#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1025 register int retries;
1026 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1028 DPRINTF(
"mcman_probePS1Card2 port%d slot%d\n", port, slot);
1030 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1031 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2)) | 0x000c0340;
1032 mcman_sio2packet_PS1PDA.in_size = 3;
1033 mcman_sio2packet_PS1PDA.out_size = 3;
1035 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1036 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1037 mcman_sio2inbufs_PS1PDA[1] = 0x52;
1041 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1044 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1046 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1047 DelayThread(mcman_timerthick - (hi >> 3));
1049 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1051 mcman_timercount = GetTimerCounter(timer_ID);
1052 mcman_timerthick = 0;
1054 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1055 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a)) {
1058 }
while (++retries < 5);
1063 if (mcman_sio2outbufs_PS1PDA[1] == 0) {
1064 if (mcdi->cardform > 0)
1065 return sceMcResSucceed;
1066 else if (mcdi->cardform < 0)
1067 return sceMcResNoFormat;
1069 else if (mcman_sio2outbufs_PS1PDA[1] != 8) {
1081int mcman_probePS1Card(
int port,
int slot)
1083#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1084 register int i, r, retries;
1085 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1088 DPRINTF(
"mcman_probePS1Card port%d slot%d\n", port, slot);
1090 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1091 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2)) | 0x000c0340;
1092 mcman_sio2packet_PS1PDA.in_size = 3;
1093 mcman_sio2packet_PS1PDA.out_size = 3;
1095 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1096 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1097 mcman_sio2inbufs_PS1PDA[1] = 0x52;
1101 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1104 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1106 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1107 DelayThread(mcman_timerthick - (hi >> 3));
1109 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1111 mcman_timercount = GetTimerCounter(timer_ID);
1112 mcman_timerthick = 0;
1114 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1115 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a)) {
1118 }
while (++retries < 5);
1123 if (mcman_sio2outbufs_PS1PDA[1] == 0) {
1124 if (mcdi->cardform != 0)
1125 return sceMcResSucceed;
1127 return sceMcResNoFormat;
1129 else if (mcman_sio2outbufs_PS1PDA[1] != 8) {
1133 mcman_clearcache(port, slot);
1135 p = (u32 *)&mcman_sio2outbufs_PS1PDA[124];
1136 for (i = 31; i >= 0; i--)
1139 r = McWritePS1PDACard(port, slot, 63, mcman_sio2outbufs_PS1PDA);
1143 r = mcman_setPS1devinfos(port, slot);
1145 return sceMcResChangedCard;
1151 return sceMcResSucceed;
1156int mcman_probePDACard(
int port,
int slot)
1158#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1159 register int retries;
1161 DPRINTF(
"mcman_probePDACard port%d slot%d\n", port, slot);
1163 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1164 mcman_sio2packet_PS1PDA.regdata[0] = (port & 3) | 0x00140540;
1165 mcman_sio2packet_PS1PDA.in_size = 5;
1166 mcman_sio2packet_PS1PDA.out_size = 5;
1168 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1169 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1170 mcman_sio2inbufs_PS1PDA[1] = 0x58;
1174 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1176 if ((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000)
1179 }
while (++retries < 5);
1188 return sceMcResSucceed;
1192int McWritePS1PDACard(
int port,
int slot,
int page,
void *buf)
1194#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1195 register int i, retries;
1196 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1201 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1202 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2) & 3) | 0x02288a40;
1203 mcman_sio2packet_PS1PDA.in_size = 138;
1204 mcman_sio2packet_PS1PDA.out_size = 138;
1205 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1207 for (i = 0; i < 20; i++) {
1208 if (mcdi->bad_block_list[i] == page)
1212 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1213 mcman_sio2inbufs_PS1PDA[1] = 0x57;
1214 mcman_sio2inbufs_PS1PDA[4] = (u8)(page >> 8);
1215 mcman_sio2inbufs_PS1PDA[5] = (u8)page;
1218 for (i = 0; i < 128; i++)
1219 mcman_sio2inbufs_PS1PDA[6 + i] = p[i];
1221 mcman_sio2inbufs_PS1PDA[4 + 130] = mcman_calcEDC(&mcman_sio2inbufs_PS1PDA[4], 130);
1225 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1228 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1230 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1231 DelayThread(mcman_timerthick - (hi >> 3));
1233 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1235 mcman_timercount = GetTimerCounter(timer_ID);
1236 mcman_timerthick = 20000;
1238 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1239 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a) \
1240 && (mcman_sio2outbufs_PS1PDA[3] == 0x5d) \
1241 && (mcman_sio2outbufs_PS1PDA[137] == 0x47)) {
1244 }
while (++retries < 5);
1247 return sceMcResNoEntry;
1249 if ((mcman_sio2outbufs_PS1PDA[1] != 0) && (mcman_sio2outbufs_PS1PDA[1] != 8))
1250 return sceMcResFullDevice;
1258 return sceMcResSucceed;
1262int McReadPS1PDACard(
int port,
int slot,
int page,
void *buf)
1264#if !defined(BUILDING_XFROMMAN) && !defined(BUILDING_VMCMAN)
1265 register int i, retries;
1266 register MCDevInfo *mcdi = &mcman_devinfos[port][slot];
1271 mcman_sio2packet_PS1PDA.regdata[0] = 0;
1272 mcman_sio2packet_PS1PDA.regdata[0] = (((port & 1) + 2) & 3) | 0x02308c40;
1273 mcman_sio2packet_PS1PDA.in_size = 140;
1274 mcman_sio2packet_PS1PDA.out_size = 140;
1275 mcman_sio2packet_PS1PDA.regdata[1] = 0;
1277 for (i = 0; i < 20; i++) {
1278 if (mcdi->bad_block_list[i] == page)
1282 mcman_sio2inbufs_PS1PDA[0] = 0x81;
1283 mcman_sio2inbufs_PS1PDA[1] = 0x52;
1284 mcman_sio2inbufs_PS1PDA[4] = (u8)(page >> 8);
1285 mcman_sio2inbufs_PS1PDA[5] = (u8)page;
1289 mcman_timercount = (u32)(GetTimerCounter(timer_ID) - mcman_timercount);
1292 long_multiply(mcman_timercount, 0x3e0f83e1, &hi, &lo);
1294 if (((u32)(hi >> 3) < (u32)mcman_timerthick))
1295 DelayThread(mcman_timerthick - (hi >> 3));
1297 mcsio2_transfer(port, slot, &mcman_sio2packet_PS1PDA);
1299 mcman_timercount = GetTimerCounter(timer_ID);
1300 mcman_timerthick = 10000;
1302 if (((mcman_sio2packet_PS1PDA.stat6c & 0xf000) == 0x1000) \
1303 && (mcman_sio2outbufs_PS1PDA[2] == 0x5a) \
1304 && (mcman_sio2outbufs_PS1PDA[3] == 0x5d) \
1305 && (mcman_sio2outbufs_PS1PDA[4] == 0x00) \
1306 && (mcman_sio2outbufs_PS1PDA[6] == 0x5c) \
1307 && (mcman_sio2outbufs_PS1PDA[7] == 0x5d) \
1308 && (mcman_sio2outbufs_PS1PDA[139] == 0x47)) {
1310 if (mcman_sio2outbufs_PS1PDA[138] == (mcman_calcEDC(&mcman_sio2outbufs_PS1PDA[8], 130) & 0xff))
1313 }
while (++retries < 5);
1316 return sceMcResNoEntry;
1319 for (i = 0; i < 128; i++)
1320 p[i] = mcman_sio2outbufs_PS1PDA[10 + i];
1322 if ((mcman_sio2outbufs_PS1PDA[1] != 0) && (mcman_sio2outbufs_PS1PDA[1] != 8))
1323 return sceMcResDeniedPermit;
1331 return sceMcResSucceed;
u32 count
start sector of fragmented bd/file