PS2SDK
PS2 Homebrew Libraries
xesdrv.c
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright ps2dev - http://www.ps2dev.org
7 # Licenced under Academic Free License version 2.0
8 # Review ps2sdk README & LICENSE files for further details.
9 */
10 
11 #include "errno.h"
12 #include "irx_imports.h"
13 #include "loadcore.h"
14 #define MODNAME "XESDRV"
15 
16 #ifdef DEBUG
17 #define DPRINTF(x...) printf(MODNAME ": " x)
18 #else
19 #define DPRINTF(x...)
20 #endif
21 
22 static int module_start(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi);
23 static int module_stop(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi);
24 static int esdrv_df_init(iomanX_iop_device_t *dev);
25 static int esdrv_df_exit(iomanX_iop_device_t *dev);
26 static int esdrv_df_ioctl(iomanX_iop_file_t *f, int cmd, void *param);
27 static int esdrv_df_devctl(
28  iomanX_iop_file_t *f, const char *name, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
29 static int
30 esdrv_df_ioctl2(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
31 static int
32 esioctl2_func_1(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
33 static int
34 esioctl2_func_10(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
35 static int
36 esioctl2_func_2(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
37 static int
38 esioctl2_func_3(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
39 static int
40 esioctl2_func_4(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
41 static int
42 esioctl2_func_5(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
43 static int
44 esioctl2_func_6(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
45 static int
46 esioctl2_func_7(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
47 static int
48 esioctl2_func_8(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
49 static int
50 esioctl2_func_9(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
51 static int
52 esioctl2_func_a(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
53 static int
54 esioctl2_func_b(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
55 static int
56 esioctl2_func_c(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
57 static int
58 esioctl2_func_d(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
59 static int
60 esioctl2_func_e(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
61 static int
62 esioctl2_func_f(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
63 
64 typedef struct es_regs_
65 {
66  vu8 r_es00;
67  vu8 padding01;
68  vu8 r_es02;
69  vu8 padding03;
70  vu8 r_es04;
71  vu8 padding05;
72  vu8 r_es06;
73  vu8 padding07;
74  vu8 r_es08;
75  vu8 padding09;
76  vu8 padding0A;
77  vu8 padding0B;
78  vu8 r_es0C;
79  vu8 padding0D;
80  vu8 r_es0E;
81  vu8 padding0F;
82  vu8 r_es10;
83  vu8 padding11;
84  vu8 r_es12;
85  vu8 padding13;
86  vu8 r_es14;
87  vu8 padding15;
88  vu8 padding16;
89  vu8 padding17;
90  vu8 r_es18;
91  vu8 padding19;
92  vu8 r_es1A;
93  vu8 padding1B;
94  vu8 r_es1C;
95  vu8 padding1D;
96  vu8 padding1E;
97  vu8 padding1F;
98  vu8 r_es20;
99  vu8 padding21;
100  vu8 r_es22;
101  vu8 padding23;
102  vu8 padding24;
103  vu8 padding25;
104  vu8 padding26;
105  vu8 padding27;
106  vu8 r_es28;
107  vu8 padding29;
108  vu8 r_es2A;
109  vu8 padding2B;
110  vu8 r_es2C;
111  vu8 padding2D;
112  vu8 padding2E;
113  vu8 padding2F;
114  vu8 padding30;
115  vu8 padding31;
116  vu8 padding32;
117  vu8 padding33;
118  vu8 r_es34;
119  vu8 padding35;
120  vu8 r_es36;
121  vu8 padding37;
122  vu8 r_es38;
123  vu8 padding39;
124  vu8 r_es3A;
125  vu8 padding3B;
126  vu8 r_es3C;
127  vu8 padding3D;
128  vu8 r_es3E;
129  vu8 padding3F;
130  vu8 r_es40;
131  vu8 padding41;
132  vu8 r_es42;
133  vu8 padding43;
134  vu8 r_es44;
135  vu8 padding45;
136  vu8 r_es46;
137  vu8 padding47;
138  vu8 r_es48;
139  vu8 padding49;
140  vu8 r_es4A;
141  vu8 padding4B;
142  vu8 r_es4C;
143  vu8 padding4D;
144  vu8 r_es4E;
145  vu8 padding4F;
146  vu8 r_es50;
147  vu8 padding51;
148  vu8 r_es52;
149  vu8 padding53;
150  vu8 r_es54;
151  vu8 padding55;
152  vu8 r_es56;
153  vu8 padding57;
154  vu8 r_es58;
155  vu8 padding59;
156  vu8 r_es5A;
157  vu8 padding5B;
158  vu8 r_es5C;
159  vu8 padding5D;
160  vu8 r_es5E;
161  vu8 padding5F;
162  vu8 r_es60;
163  vu8 padding61;
164  vu8 r_es62;
165  vu8 padding63;
166  vu8 r_es64;
167  vu8 padding65;
168  vu8 r_es66;
169  vu8 padding67;
170  vu8 r_es68;
171  vu8 padding69;
172  vu8 r_es6A;
173  vu8 padding6B;
174  vu8 r_es6C;
175  vu8 padding6D;
176  vu8 r_es6E;
177  vu8 padding6F;
178  vu8 r_es70;
179  vu8 padding71;
180  vu8 r_es72;
181  vu8 padding73;
182  vu8 r_es74;
183  vu8 padding75;
184  vu8 r_es76;
185  vu8 padding77;
186  vu8 r_es78;
187  vu8 padding79;
188  vu8 r_es7A;
189  vu8 padding7B;
190  vu8 r_es7C;
191  vu8 padding7D;
192  vu8 r_es7E;
193  vu8 padding7F;
194 } es_regs_t;
195 
196 static es_regs_t *const es_regs = (void *)0xBF415000;
197 
199 {
200  u16 cmd;
201  int (*fn)(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
202 } DevctlCmdTbl[16] = {
203  {0x5464, &esioctl2_func_1},
204  {0x5465, &esioctl2_func_2},
205  {0x5466, &esioctl2_func_3},
206  {0x5467, &esioctl2_func_4},
207  {0x5468, &esioctl2_func_5},
208  {0x5469, &esioctl2_func_6},
209  {0x546A, &esioctl2_func_7},
210  {0x546B, &esioctl2_func_8},
211  {0x546C, &esioctl2_func_9},
212  {0x546D, &esioctl2_func_a},
213  {0x546E, &esioctl2_func_b},
214  {0x546F, &esioctl2_func_c},
215  {0x5470, &esioctl2_func_d},
216  {0x5471, &esioctl2_func_e},
217  {0x5472, &esioctl2_func_f},
218  {0x5473, &esioctl2_func_10},
219 };
220 
221 IOMANX_RETURN_VALUE_IMPL(ENOTSUP);
222 
223 static iomanX_iop_device_ops_t DvrFuncTbl = {
224  &esdrv_df_init, // init
225  &esdrv_df_exit, // deinit
226  IOMANX_RETURN_VALUE(ENOTSUP), // format
227  IOMANX_RETURN_VALUE(ENOTSUP), // open
228  IOMANX_RETURN_VALUE(ENOTSUP), // close
229  IOMANX_RETURN_VALUE(ENOTSUP), // read
230  IOMANX_RETURN_VALUE(ENOTSUP), // write
231  IOMANX_RETURN_VALUE(ENOTSUP), // lseek
232  &esdrv_df_ioctl, // ioctl
233  IOMANX_RETURN_VALUE(ENOTSUP), // remove
234  IOMANX_RETURN_VALUE(ENOTSUP), // mkdir
235  IOMANX_RETURN_VALUE(ENOTSUP), // rmdir
236  IOMANX_RETURN_VALUE(ENOTSUP), // dopen
237  IOMANX_RETURN_VALUE(ENOTSUP), // dclose
238  IOMANX_RETURN_VALUE(ENOTSUP), // dread
239  IOMANX_RETURN_VALUE(ENOTSUP), // getstat
240  IOMANX_RETURN_VALUE(ENOTSUP), // chstat
241  IOMANX_RETURN_VALUE(ENOTSUP), // rename
242  IOMANX_RETURN_VALUE(ENOTSUP), // chdir
243  IOMANX_RETURN_VALUE(ENOTSUP), // sync
244  IOMANX_RETURN_VALUE(ENOTSUP), // mount
245  IOMANX_RETURN_VALUE(ENOTSUP), // umount
246  IOMANX_RETURN_VALUE_S64(ENOTSUP), // lseek64
247  &esdrv_df_devctl, // devctl
248  IOMANX_RETURN_VALUE(ENOTSUP), // symlink
249  IOMANX_RETURN_VALUE(ENOTSUP), // readlink
250  &esdrv_df_ioctl2, // ioctl2
251 };
252 static iomanX_iop_device_t ESDRV = {
253  .name = "es_drv",
254  .desc = "PSX ES DRIVER",
255  .type = (IOP_DT_FS | IOP_DT_FSEXT),
256  .ops = &DvrFuncTbl,
257 };
258 static s32 sema_id;
259 
260 // Based off of DESR / PSX DVR system software version 2.11.
261 IRX_ID(MODNAME, 1, 1);
262 
263 int _start(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi)
264 {
265  if ( argc >= 0 )
266  return module_start(argc, argv, startaddr, mi);
267  else
268  return module_stop(argc, argv, startaddr, mi);
269 }
270 
271 static int module_start(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi)
272 {
273  (void)argc;
274  (void)argv;
275  (void)startaddr;
276 
277  if ( iomanX_AddDrv(&ESDRV) != 0 )
278  return MODULE_NO_RESIDENT_END;
279 #if 0
280  return MODULE_REMOVABLE_END;
281 #else
282  if ( mi && ((mi->newflags & 2) != 0) )
283  mi->newflags |= 0x10;
284  return MODULE_RESIDENT_END;
285 #endif
286 }
287 
288 static int module_stop(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi)
289 {
290  (void)argc;
291  (void)argv;
292  (void)startaddr;
293  (void)mi;
294 
295  if ( iomanX_DelDrv(ESDRV.name) != 0 )
296  return MODULE_REMOVABLE_END;
297  return MODULE_NO_RESIDENT_END;
298 }
299 
300 static int esdrv_df_init(iomanX_iop_device_t *dev)
301 {
302  int sema_id_tmp;
303  iop_sema_t semaparam;
304 
305  (void)dev;
306 
307  semaparam.attr = 0;
308  semaparam.initial = 1;
309  semaparam.max = 1;
310  semaparam.option = 0;
311  sema_id_tmp = CreateSema(&semaparam);
312  if ( sema_id_tmp < 0 )
313  return -1;
314  sema_id = sema_id_tmp;
315  return 0;
316 }
317 
318 static int esdrv_df_exit(iomanX_iop_device_t *dev)
319 {
320  (void)dev;
321 
322  if ( DeleteSema(sema_id) != 0 )
323  return -1;
324  return 0;
325 }
326 
327 static int esdrv_df_ioctl(iomanX_iop_file_t *f, int cmd, void *param)
328 {
329  (void)f;
330  (void)cmd;
331  (void)param;
332 
333  WaitSema(sema_id);
334  SignalSema(sema_id);
335  return -EINVAL;
336 }
337 
338 static int esdrv_df_devctl(
339  iomanX_iop_file_t *f, const char *name, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
340 {
341  int retres;
342  unsigned int i;
343 
344  (void)name;
345 
346  WaitSema(sema_id);
347  retres = -EINVAL;
348  for ( i = 0; i < (sizeof(DevctlCmdTbl) / sizeof(DevctlCmdTbl[0])); i += 1 )
349  {
350  if ( DevctlCmdTbl[i].cmd == cmd )
351  {
352  retres = DevctlCmdTbl[i].fn(f, cmd, arg, arglen, buf, buflen);
353  break;
354  }
355  }
356  SignalSema(sema_id);
357  return retres;
358 }
359 
360 static int
361 esdrv_df_ioctl2(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
362 {
363  (void)f;
364  (void)cmd;
365  (void)arg;
366  (void)arglen;
367  (void)buf;
368  (void)buflen;
369 
370  WaitSema(sema_id);
371  SignalSema(sema_id);
372  return -EINVAL;
373 }
374 
375 static void EsAcsSetAaryptorIoMode(void)
376 {
377  es_regs->r_es0C = 0;
378 }
379 
380 #if 0
381 static u8 EsAcsGetAaryptorIoMode(void)
382 {
383  return es_regs->r_es0C;
384 }
385 #endif
386 
387 static void EsAcsAaryptorIoEnable(void)
388 {
389  es_regs->r_es0C |= 1;
390 }
391 
392 #if 0
393 static void EsAcsAaryptorIoDisable(void)
394 {
395  es_regs->r_es0C &= ~1;
396 }
397 #endif
398 
399 #if 0
400 static u8 EsAcsIsAaryptorIoEnable(void)
401 {
402  return es_regs->r_es0C & 1;
403 }
404 #endif
405 
406 static void EsAcsSetBbryptorIoMode(void)
407 {
408  es_regs->r_es0E = 0x58;
409 }
410 
411 #if 0
412 static u8 EsAcsGetBbryptorIoMode(void)
413 {
414  return es_regs->r_es0E;
415 }
416 #endif
417 
418 static void EsAcsBbryptorIoEnable(void)
419 {
420  es_regs->r_es0E |= 1;
421 }
422 
423 #if 0
424 static u8 EsAcsIsBbryptorIoEnable(void)
425 {
426  return es_regs->r_es0E & 1;
427 }
428 #endif
429 
430 #if 0
431 static void EsAcsBbryptorIoDisable(void)
432 {
433  es_regs->r_es0E &= ~1;
434 }
435 #endif
436 
437 #if 0
438 static u8 EsAcsGetProcessCall(void)
439 {
440  return es_regs->r_es28;
441 }
442 #endif
443 
444 static void EsAcsAaStreamOn(void)
445 {
446  es_regs->r_es28 = 2;
447 }
448 
449 #if 0
450 static u8 EsAcsIsAaStreamOn(void)
451 {
452  return es_regs->r_es28 & 2;
453 }
454 #endif
455 
456 static void EsAcsAaTreminate(void)
457 {
458  es_regs->r_es2C = 2;
459 }
460 
461 #if 0
462 static u8 EsAcsIsAaEmpty(void)
463 {
464  return es_regs->r_es1C & 2;
465 }
466 #endif
467 
468 static u8 EsAcsGetStatusAaEmpty(void)
469 {
470  return es_regs->r_es1C & 2;
471 }
472 
473 static u8 EsAcsIsAaComplete(void)
474 {
475  return es_regs->r_es1A & 2;
476 }
477 
478 static void EsAcsSetAaCompleteIntrClear(void)
479 {
480  es_regs->r_es1A &= 2;
481 }
482 
483 static u8 EsAcsIsAaPckError(void)
484 {
485  return es_regs->r_es18 & 2;
486 }
487 
488 static void EsAcsSetAaPckErrorIntrClear(void)
489 {
490  es_regs->r_es18 &= 2;
491 }
492 
493 static void EsAcsBbStreamOn(void)
494 {
495  es_regs->r_es28 = 1;
496 }
497 
498 #if 0
499 static u8 EsAcsIsBbStreamOn(void)
500 {
501  return es_regs->r_es28 & 1;
502 }
503 #endif
504 
505 static void EsAcsBbTreminate(void)
506 {
507  es_regs->r_es2C = 1;
508 }
509 
510 static u8 EsAcsIsBbComplete(void)
511 {
512  return es_regs->r_es1A & 1;
513 }
514 
515 static void EsAcsSetBbCompleteIntrClear(void)
516 {
517  es_regs->r_es1A &= 1;
518 }
519 
520 static u8 EsAcsIsBbPckError(void)
521 {
522  return es_regs->r_es18 & 1;
523 }
524 
525 static void EsAcsSetBbPckErrorIntrClear(void)
526 {
527  es_regs->r_es18 &= 1;
528 }
529 
530 #if 0
531 static u8 EsAcsIsBbEmpty(void)
532 {
533  return es_regs->r_es1C & 1;
534 }
535 #endif
536 
537 #if 0
538 static void EsAcsBbThroughEnable(void)
539 {
540  es_regs->r_es08 |= 8;
541 }
542 #endif
543 
544 static void EsAcsBbThroughDisable(void)
545 {
546  es_regs->r_es08 &= ~8;
547 }
548 
549 static u8 EsAcsIsBbBlockThrough(void)
550 {
551  return es_regs->r_es08 & 8;
552 }
553 
554 #if 0
555 static u8 EsAcsGetStatusBbPesScrambleControl(void)
556 {
557  u8 r_es22;
558 
559  r_es22 = es_regs->r_es22;
560  es_regs->r_es22 = r_es22 & 0xC;
561  return (u8)(r_es22 & 0xC) >> 2;
562 }
563 #endif
564 
565 static u8 EsAcsGetStatusBbEmpty(void)
566 {
567  return es_regs->r_es1C & 1;
568 }
569 
570 #if 0
571 static int EsAcsGetSerialNumber(void)
572 {
573  return es_regs->r_es3E | (es_regs->r_es38 << 24) | (es_regs->r_es3A << 16) | (es_regs->r_es3C << 8);
574 }
575 #endif
576 
577 #if 0
578 static void EsAcsSetSerialNumber(unsigned int a1)
579 {
580  es_regs->r_es38 = (a1 >> 24) & 0xFF;
581  es_regs->r_es3A = (a1 >> 16) & 0xFF;
582  es_regs->r_es3C = (a1 >> 8) & 0xFF;
583  es_regs->r_es3E = a1 & 0xFF;
584 }
585 #endif
586 
587 static void EsAcsSetSerialNumberReg1(u8 a1)
588 {
589  es_regs->r_es38 = a1;
590 }
591 
592 static void EsAcsSetSerialNumberReg2(u8 a1)
593 {
594  es_regs->r_es3A = a1;
595 }
596 
597 static void EsAcsSetSerialNumberReg3(u8 a1)
598 {
599  es_regs->r_es3C = a1;
600 }
601 
602 static void EsAcsSetSerialNumberReg4(u8 a1)
603 {
604  es_regs->r_es3E = a1;
605 }
606 
607 #if 0
608 static u8 EsAcsGetStatusA(void)
609 {
610  return es_regs->r_es20;
611 }
612 #endif
613 
614 #if 0
615 static u8 EsAcsIsBbStatusInit(void)
616 {
617  return (es_regs->r_es20 & 0xF) == 0;
618 }
619 #endif
620 
621 static u8 EsAcsIsBbStatusIdle(void)
622 {
623  return (es_regs->r_es20 & 0xF) == 1;
624 }
625 
626 #if 0
627 static u8 EsAcsIsBbStatusNn(void)
628 {
629  return (es_regs->r_es20 & 0xF) == 2;
630 }
631 #endif
632 
633 static u8 EsAcsIsBbStatusUUTT(void)
634 {
635  return (es_regs->r_es20 & 0xF) == 3;
636 }
637 
638 #if 0
639 static u8 EsAcsIsBbStatusDec(void)
640 {
641  return (es_regs->r_es20 & 0xF) == 4;
642 }
643 #endif
644 
645 #if 0
646 static u8 EsAcsIsBbStatusRandom(void)
647 {
648  return (es_regs->r_es20 & 0xF) == 6;
649 }
650 #endif
651 
652 static void EsAcsSetSdeData(u8 a1)
653 {
654  es_regs->r_es34 = a1;
655 }
656 
657 static void EsAcsAllIntDisableA(void)
658 {
659  es_regs->r_es10 = 0;
660 }
661 
662 static void EsAcsAllIntDisableB(void)
663 {
664  es_regs->r_es12 = 0;
665 }
666 
667 static void EsAcsAllIntDisableC(void)
668 {
669  es_regs->r_es14 = 0;
670 }
671 
672 static void EsAcsAllIntDisable(void)
673 {
674  EsAcsAllIntDisableA();
675  EsAcsAllIntDisableB();
676  EsAcsAllIntDisableC();
677 }
678 
679 static void EsAcsAllIntStatClearA(void)
680 {
681  es_regs->r_es18 = 0x9F;
682 }
683 
684 static void EsAcsAllIntStatClearB(void)
685 {
686  es_regs->r_es1A = 0xDF;
687 }
688 
689 static void EsAcsAllIntStatClearC(void)
690 {
691  es_regs->r_es1C = 0x83;
692 }
693 
694 static void EsAcsAllIntStatClear(void)
695 {
696  EsAcsAllIntStatClearA();
697  EsAcsAllIntStatClearB();
698  EsAcsAllIntStatClearC();
699 }
700 
701 #if 0
702 static void EsAcsIntEnableInitComplete(void)
703 {
704  es_regs->r_es12 |= 0x40;
705 }
706 #endif
707 
708 #if 0
709 static void EsAcsIntDisableInitComplete(void)
710 {
711  es_regs->r_es12 &= ~0x40;
712 }
713 #endif
714 
715 #if 0
716 static void EsAcsIntEnableProcessRandom(void)
717 {
718  es_regs->r_es14 |= 0x80;
719 }
720 #endif
721 
722 #if 0
723 static void EsAcsIntDisableProcessRandom(void)
724 {
725  es_regs->r_es14 &= ~0x80;
726 }
727 #endif
728 
729 #if 0
730 static void EsAcsIntEnableNnInvalid(void)
731 {
732  es_regs->r_es10 |= 0x10;
733 }
734 #endif
735 
736 #if 0
737 static void EsAcsIntDisableNnInvalid(void)
738 {
739  es_regs->r_es10 &= ~0x10;
740 }
741 #endif
742 
743 #if 0
744 static void EsAcsIntEnableNnRevoked(void)
745 {
746  es_regs->r_es10 |= 8;
747 }
748 #endif
749 
750 #if 0
751 static void EsAcsIntDisableNnRevoked(void)
752 {
753  es_regs->r_es10 &= ~8;
754 }
755 #endif
756 
757 #if 0
758 static void EsAcsIntEnableNnReplaced(void)
759 {
760  es_regs->r_es10 |= 4;
761 }
762 #endif
763 
764 #if 0
765 static void EsAcsIntDisableNnReplaced(void)
766 {
767  es_regs->r_es10 &= ~4;
768 }
769 #endif
770 
771 #if 0
772 static void EsAcsIntEnableNnComplete(void)
773 {
774  es_regs->r_es12 |= 0x10;
775 }
776 #endif
777 
778 #if 0
779 static void EsAcsIntDisableNnComplete(void)
780 {
781  es_regs->r_es12 &= ~0x10;
782 }
783 #endif
784 
785 #if 0
786 static void EsAcsIntEnableProcessNn(void)
787 {
788  EsAcsIntEnableNnInvalid();
789  EsAcsIntEnableNnRevoked();
790  EsAcsIntEnableNnReplaced();
791  EsAcsIntEnableNnComplete();
792 }
793 #endif
794 
795 #if 0
796 static void EsAcsIntDisableProcessNn(void)
797 {
798  EsAcsIntDisableNnInvalid();
799  EsAcsIntDisableNnRevoked();
800  EsAcsIntDisableNnReplaced();
801  EsAcsIntDisableNnComplete();
802 }
803 #endif
804 
805 #if 0
806 static void EsAcsIntEnableUUComplete(void)
807 {
808  es_regs->r_es12 |= 8;
809 }
810 #endif
811 
812 #if 0
813 static void EsAcsIntDisableUUComplete(void)
814 {
815  es_regs->r_es12 &= ~8;
816 }
817 #endif
818 
819 #if 0
820 static void EsAcsIntEnableProcessUU(void)
821 {
822  EsAcsIntEnableUUComplete();
823 }
824 #endif
825 
826 #if 0
827 static void EsAcsIntDisableProcessUU(void)
828 {
829  EsAcsIntDisableUUComplete();
830 }
831 #endif
832 
833 #if 0
834 static void EsAcsIntEnableTTComplete(void)
835 {
836  es_regs->r_es12 |= 4;
837 }
838 #endif
839 
840 #if 0
841 static void EsAcsIntDisableTTComplete(void)
842 {
843  es_regs->r_es12 &= ~4;
844 }
845 #endif
846 
847 #if 0
848 static void EsAcsIntEnableProcessTT(void)
849 {
850  EsAcsIntEnableTTComplete();
851 }
852 #endif
853 
854 #if 0
855 static void EsAcsIntDisableProcessTT(void)
856 {
857  EsAcsIntDisableTTComplete();
858 }
859 #endif
860 
861 #if 0
862 static void EsAcsIntEnableBbEmpty(void)
863 {
864  es_regs->r_es14 |= 1;
865 }
866 #endif
867 
868 #if 0
869 static void EsAcsIntDisableBbEmpty(void)
870 {
871  es_regs->r_es14 &= ~1;
872 }
873 #endif
874 
875 #if 0
876 static void EsAcsIntEnableBbPackErr(void)
877 {
878  es_regs->r_es10 |= 1;
879 }
880 #endif
881 
882 #if 0
883 static void EsAcsIntDisableBbPackErr(void)
884 {
885  es_regs->r_es10 &= ~1;
886 }
887 #endif
888 
889 #if 0
890 static void EsAcsIntEnableAaPackErr(void)
891 {
892  es_regs->r_es10 |= 2;
893 }
894 #endif
895 
896 #if 0
897 static void EsAcsIntDisableAaPackErr(void)
898 {
899  es_regs->r_es10 &= ~2;
900 }
901 #endif
902 
903 static void EsAcsSoftReset(void)
904 {
905  es_regs->r_es00 = 0x80;
906 }
907 
908 static void EsAcsInitTerminate(void)
909 {
910  es_regs->r_es2C = 0x40;
911 }
912 
913 static void EsAcsSetInitComplete(void)
914 {
915  es_regs->r_es1A &= 0x40;
916 }
917 
918 static void EsAcsRandSeedSn(void)
919 {
920  es_regs->r_es08 |= 0x10;
921 }
922 
923 static u8 EsAcsIsAccessProhibit(void)
924 {
925  return es_regs->r_es22 & 0x80;
926 }
927 
928 static u8 EsAcsIsInidecError(void)
929 {
930  return es_regs->r_es18 & 0x80;
931 }
932 
933 static void EsAcsSetInidecErrorIntrClear(void)
934 {
935  es_regs->r_es18 &= 0x80;
936 }
937 
938 static u8 EsAcsIsLrsComplete(void)
939 {
940  return es_regs->r_es1A & 0x80;
941 }
942 
943 static void EsAcsSetLrsComplete(void)
944 {
945  es_regs->r_es1A &= 0x80;
946 }
947 
948 static u8 EsAcsIsInitComplete(void)
949 {
950  return es_regs->r_es1A & 0x40;
951 }
952 
953 static void EsAcsStartRandom(void)
954 {
955  es_regs->r_es2A = 0x80;
956 }
957 
958 static u8 EsAcsIsRandomComplete(void)
959 {
960  return es_regs->r_es1C & 0x80;
961 }
962 
963 static void EsAcsSetRandomComplete(void)
964 {
965  es_regs->r_es1C &= 0x80;
966 }
967 
968 static void EsAcsStartNn(void)
969 {
970  es_regs->r_es28 = 0x10;
971 }
972 
973 static void EsAcsTerminateNn(void)
974 {
975  es_regs->r_es2C = 0x10;
976 }
977 
978 static u8 EsAcsIsNnInvalid(void)
979 {
980  return es_regs->r_es18 & 0x10;
981 }
982 
983 static u8 EsAcsIsNnRevoked(void)
984 {
985  return es_regs->r_es18 & 8;
986 }
987 
988 static u8 EsAcsIsNnReplaced(void)
989 {
990  return es_regs->r_es18 & 4;
991 }
992 
993 static u8 EsAcsIsNnComplete(void)
994 {
995  return es_regs->r_es1A & 0x10;
996 }
997 
998 static void EsAcsSetNnInvalid(void)
999 {
1000  es_regs->r_es18 &= 0x10;
1001 }
1002 
1003 static void EsAcsSetNnRevoked(void)
1004 {
1005  es_regs->r_es18 &= 8;
1006 }
1007 
1008 static void EsAcsSetNnReplaced(void)
1009 {
1010  es_regs->r_es18 &= 4;
1011 }
1012 
1013 static void EsAcsSetNnComplete(void)
1014 {
1015  es_regs->r_es1A &= 0x10;
1016 }
1017 
1018 static void EsAcsSetNnIntrAllClear(void)
1019 {
1020  EsAcsSetNnInvalid();
1021  EsAcsSetNnRevoked();
1022  EsAcsSetNnReplaced();
1023  EsAcsSetNnComplete();
1024 }
1025 
1026 static void EsAcsSetNnPacksUsed(u8 a1)
1027 {
1028  es_regs->r_es36 = a1;
1029 }
1030 
1031 static void EsAcsSetNnValidationData(const u8 *a1)
1032 {
1033  es_regs->r_es40 = *a1;
1034  es_regs->r_es42 = a1[1];
1035  es_regs->r_es44 = a1[2];
1036  es_regs->r_es46 = a1[3];
1037  es_regs->r_es48 = a1[4];
1038  es_regs->r_es4A = a1[5];
1039  es_regs->r_es4C = a1[6];
1040  es_regs->r_es4E = a1[7];
1041 }
1042 
1043 static void EsAcsStartUU(void)
1044 {
1045  es_regs->r_es28 = 8;
1046 }
1047 
1048 static void EsAcsStartTT(void)
1049 {
1050  es_regs->r_es28 = 4;
1051 }
1052 
1053 static u8 EsAcsIsUUComplete(void)
1054 {
1055  return es_regs->r_es1A & 8;
1056 }
1057 
1058 static u8 EsAcsIsTTComplete(void)
1059 {
1060  return es_regs->r_es1A & 4;
1061 }
1062 
1063 static void EsAcsSetUUComplete(void)
1064 {
1065  es_regs->r_es1A = 8;
1066 }
1067 
1068 static void EsAcsSetTTComplete(void)
1069 {
1070  es_regs->r_es1A = 4;
1071 }
1072 
1073 static void EsAcsSetBbryptedTitleKey(void)
1074 {
1075  es_regs->r_es08 |= 4;
1076 }
1077 
1078 static void EsAcsSetRandomTitleKey(void)
1079 {
1080  es_regs->r_es08 &= ~4;
1081 }
1082 
1083 static void EsAcsSetMediaId(const u8 *a1)
1084 {
1085  es_regs->r_es50 = a1[0];
1086  es_regs->r_es52 = a1[1];
1087  es_regs->r_es54 = a1[2];
1088  es_regs->r_es56 = a1[3];
1089  es_regs->r_es58 = a1[4];
1090  es_regs->r_es5A = a1[5];
1091  es_regs->r_es5C = a1[6];
1092  es_regs->r_es5E = a1[7];
1093 }
1094 
1095 static void EsAcsSetTTe(const u8 *a1)
1096 {
1097  es_regs->r_es60 = a1[0];
1098  es_regs->r_es62 = a1[1];
1099  es_regs->r_es64 = a1[2];
1100  es_regs->r_es66 = a1[3];
1101  es_regs->r_es68 = a1[4];
1102  es_regs->r_es6A = a1[5];
1103  es_regs->r_es6C = a1[6];
1104  es_regs->r_es6E = a1[7];
1105 }
1106 
1107 static void EsAcsGetTTe(u8 *a1)
1108 {
1109  a1[0] = (u8)(es_regs->r_es70);
1110  a1[1] = (u8)(es_regs->r_es72);
1111  a1[2] = (u8)(es_regs->r_es74);
1112  a1[3] = (u8)(es_regs->r_es76);
1113  a1[4] = (u8)(es_regs->r_es78);
1114  a1[5] = (u8)(es_regs->r_es7A);
1115  a1[6] = (u8)(es_regs->r_es7C);
1116  a1[7] = (u8)(es_regs->r_es7E);
1117 }
1118 
1119 #if 0
1120 static u8 EsAcsGetIntrSrcA(void)
1121 {
1122  return es_regs->r_es18;
1123 }
1124 #endif
1125 
1126 #if 0
1127 static u8 EsAcsGetIntrSrcB(void)
1128 {
1129  return es_regs->r_es1A;
1130 }
1131 #endif
1132 
1133 #if 0
1134 static u8 EsAcsGetIntrSrcC(void)
1135 {
1136  return es_regs->r_es1C;
1137 }
1138 #endif
1139 
1140 static u8 EsAcsGetChipVersion(void)
1141 {
1142  return es_regs->r_es02;
1143 }
1144 
1145 static u8 EsAcsGetRevision1(void)
1146 {
1147  return es_regs->r_es04;
1148 }
1149 
1150 static u8 EsAcsGetRevision2(void)
1151 {
1152  return es_regs->r_es06;
1153 }
1154 
1155 #if 0
1156 static u16 EsAcsGetReg(int a1)
1157 {
1158  return *(u16 *)(&es_regs->r_es00 + a1);
1159 }
1160 #endif
1161 
1162 #if 0
1163 static void EsAcsSetReg(u8 a1, u8 a2)
1164 {
1165  *(u16 *)(&es_regs->r_es00 + a1) = a2;
1166 }
1167 #endif
1168 
1169 static u8 EsDrvNnResultCheck(void)
1170 {
1171  if ( EsAcsIsNnInvalid() != 0 )
1172  {
1173  return 4;
1174  }
1175  if ( EsAcsIsNnRevoked() != 0 )
1176  {
1177  return 3;
1178  }
1179  if ( EsAcsIsNnReplaced() != 0 )
1180  {
1181  return 2;
1182  }
1183  if ( EsAcsIsNnComplete() != 0 )
1184  {
1185  return 1;
1186  }
1187  return 0;
1188 }
1189 
1190 static void EsDrvSoftReset(void)
1191 {
1192  EsAcsSoftReset();
1193  DelayThread(1000);
1194 }
1195 
1196 static void EsDrvSetSerialNumber(u8 *a1)
1197 {
1198  EsAcsSetSerialNumberReg1(a1[0]);
1199  EsAcsSetSerialNumberReg2(a1[1]);
1200  EsAcsSetSerialNumberReg3(a1[2]);
1201  EsAcsSetSerialNumberReg4(a1[3]);
1202 }
1203 
1204 static u8 EsDrvSetSde(u8 *a1)
1205 {
1206  s16 i;
1207 
1208  EsAcsSetInidecErrorIntrClear();
1209  EsAcsSetLrsComplete();
1210  for ( i = 0; i < 0x1be; i += 1 )
1211  {
1212  EsAcsSetSdeData(a1[i]);
1213  if ( i == 0x1bd )
1214  break;
1215  if ( EsAcsIsAccessProhibit() != 0 )
1216  return -1;
1217  }
1218  DelayThread(5000);
1219  return 0;
1220 }
1221 
1222 static u8 EsDrvCheckSdeProcess(int a1)
1223 {
1224  if ( EsAcsIsInidecError() )
1225  {
1226  EsAcsSetInidecErrorIntrClear();
1227  return -1;
1228  }
1229  if ( EsAcsIsLrsComplete() == 0 )
1230  {
1231  return -1;
1232  }
1233  EsAcsSetLrsComplete();
1234  DelayThread(a1);
1235  return 0;
1236 }
1237 
1238 static u8 EsDrvTrmntInitProcess(void)
1239 {
1240  u16 i;
1241 
1242  EsAcsSetInitComplete();
1243  EsAcsInitTerminate();
1244  for ( i = 0; i < 0x65; i += 1 )
1245  {
1246  if ( EsAcsIsInitComplete() )
1247  {
1248  EsAcsSetInitComplete();
1249  return 0;
1250  }
1251  DelayThread(100000);
1252  }
1253  return -1;
1254 }
1255 
1256 static void EsDrvCmpltInitProcess(void)
1257 {
1258  EsAcsRandSeedSn();
1259  EsAcsSetAaryptorIoMode();
1260  EsAcsSetBbryptorIoMode();
1261  EsAcsAllIntDisable();
1262  EsAcsAllIntStatClear();
1263  EsAcsAaryptorIoEnable();
1264  EsAcsBbryptorIoEnable();
1265 }
1266 
1267 static u8 EsDrvRndNnCheck(void)
1268 {
1269  if ( EsAcsIsBbStatusIdle() == 0 )
1270  return -1;
1271  return 0;
1272 }
1273 
1274 static u8 EsDrvRandom(void)
1275 {
1276  int i;
1277 
1278  for ( i = 0; i < 15; ++i )
1279  {
1280  u16 j;
1281 
1282  j = 0;
1283  EsAcsSetRandomComplete();
1284  EsAcsStartRandom();
1285  for ( j = 0; j < 6; j += 1 )
1286  {
1287  if ( EsAcsIsRandomComplete() )
1288  {
1289  return 0;
1290  }
1291  DelayThread(2);
1292  }
1293  return -1;
1294  }
1295  return 0;
1296 }
1297 
1298 static void EsDrvSetNnParam(u8 a1, const u8 *a2)
1299 {
1300  EsAcsSetNnPacksUsed(a1);
1301  EsAcsSetNnValidationData(a2);
1302 }
1303 
1304 static void EsDrvSetNnStart(void)
1305 {
1306  EsAcsSetNnIntrAllClear();
1307  EsAcsBbThroughDisable();
1308  EsAcsStartNn();
1309 }
1310 
1311 static int EsDrvStartNnCheckStat(void)
1312 {
1313  return EsDrvNnResultCheck();
1314 }
1315 
1316 static void EsDrvSetNnStop(void)
1317 {
1318  DelayThread(1000);
1319 }
1320 
1321 static int EsDrvStopNnCheckStat(void)
1322 {
1323  u8 retval;
1324 
1325  retval = EsDrvNnResultCheck();
1326  if ( retval != 1 )
1327  {
1328  int i;
1329 
1330  EsAcsTerminateNn();
1331  for ( i = 0; i < 10; i += 1 )
1332  {
1333  retval = EsDrvNnResultCheck();
1334  if ( retval != 0 )
1335  break;
1336  DelayThread(1000);
1337  }
1338  }
1339  EsAcsSetNnIntrAllClear();
1340  return retval;
1341 }
1342 
1343 static u8 EsDrvSetUUStart(const u8 *a1)
1344 {
1345  if ( EsAcsIsBbStatusUUTT() == 0 )
1346  {
1347  return -1;
1348  }
1349  EsAcsBbThroughDisable();
1350  EsAcsSetMediaId(a1);
1351  EsAcsSetUUComplete();
1352  EsAcsStartUU();
1353  return 0;
1354 }
1355 
1356 static u8 EsDrvCmpltUUProcess(void)
1357 {
1358  u16 i;
1359 
1360  for ( i = 0; i < 0x65; i += 1 )
1361  {
1362  if ( EsAcsIsUUComplete() )
1363  {
1364  EsAcsSetUUComplete();
1365  return 0;
1366  }
1367  DelayThread(10000);
1368  }
1369  return -1;
1370 }
1371 
1372 static u8 EsDrvSetTTStart(u8 a1, const u8 *a2)
1373 {
1374  if ( a1 )
1375  {
1376  EsAcsSetBbryptedTitleKey();
1377  EsAcsSetTTe(a2);
1378  }
1379  else
1380  {
1381  EsAcsSetRandomTitleKey();
1382  }
1383  EsAcsSetTTComplete();
1384  EsAcsStartTT();
1385  return 0;
1386 }
1387 
1388 static u8 EsDrvCmpltTTProcess(u8 a1, u8 *a2)
1389 {
1390  u16 i;
1391 
1392  for ( i = 0; i < 0x65; i += 1 )
1393  {
1394  if ( EsAcsIsTTComplete() )
1395  {
1396  EsAcsSetTTComplete();
1397  if ( !a1 )
1398  {
1399  EsAcsGetTTe(a2);
1400  }
1401  return 0;
1402  }
1403  DelayThread(10000);
1404  }
1405  return -1;
1406 }
1407 
1408 static u8 EsDrvBbStart(void)
1409 {
1410  if ( EsAcsIsBbBlockThrough() != 0 )
1411  {
1412  return -1;
1413  }
1414  EsAcsSetBbPckErrorIntrClear();
1415  EsAcsSetBbCompleteIntrClear();
1416  EsAcsBbStreamOn();
1417  return 0;
1418 }
1419 
1420 static int EsDrvBbBsCheck(void)
1421 {
1422  if ( EsAcsIsBbPckError() != 0 )
1423  {
1424  EsAcsSetBbPckErrorIntrClear();
1425  return 1;
1426  }
1427  return 0;
1428 }
1429 
1430 static u8 EsDrvBbStop(void)
1431 {
1432  u16 i;
1433 
1434  EsAcsBbTreminate();
1435  for ( i = 0; i < 0x65; i += 1 )
1436  {
1437  if ( EsAcsIsBbComplete() )
1438  {
1439  EsAcsSetBbCompleteIntrClear();
1440  return 0;
1441  }
1442  DelayThread(100000);
1443  }
1444  return -1;
1445 }
1446 
1447 static void EsDrvAaStart(void)
1448 {
1449  EsAcsSetAaPckErrorIntrClear();
1450  EsAcsSetAaCompleteIntrClear();
1451  EsAcsAaStreamOn();
1452 }
1453 
1454 static int EsDrvAaBsCheck(void)
1455 {
1456  if ( EsAcsIsAaPckError() != 0 )
1457  {
1458  EsAcsSetAaPckErrorIntrClear();
1459  return 1;
1460  }
1461  return 0;
1462 }
1463 
1464 static u8 EsDrvAaStop(void)
1465 {
1466  u16 i;
1467 
1468  EsAcsAaTreminate();
1469  for ( i = 0; i < 0x65; i += 1 )
1470  {
1471  if ( EsAcsIsAaComplete() )
1472  {
1473  EsAcsSetAaCompleteIntrClear();
1474  return 0;
1475  }
1476  DelayThread(100000);
1477  }
1478  return -1;
1479 }
1480 
1481 #if 0
1482 static void EsDrvBbFifoClear(void)
1483 {
1484  if ( !EsAcsIsBbBlockThrough() )
1485  {
1486  EsAcsIntDisableBbPackErr();
1487  EsAcsBbTreminate();
1488  }
1489 }
1490 #endif
1491 
1492 #if 0
1493 static void EsDrvAaFifoClear(void)
1494 {
1495  EsAcsAaTreminate();
1496 }
1497 #endif
1498 
1499 #if 0
1500 static int EsDrvGetBbPesScrambleControl(void)
1501 {
1502  return EsAcsGetStatusBbPesScrambleControl();
1503 }
1504 #endif
1505 
1506 static int EsDrvAaEmptyCheck(void)
1507 {
1508  return EsAcsGetStatusAaEmpty() == 0;
1509 }
1510 
1511 static int EsDrvBbEmptyCheck(void)
1512 {
1513  return EsAcsGetStatusBbEmpty() == 0;
1514 }
1515 
1516 static int EsDrvGetChipVersion(void)
1517 {
1518  return EsAcsGetChipVersion();
1519 }
1520 
1521 static int EsDrvGetRevision1(void)
1522 {
1523  return EsAcsGetRevision1();
1524 }
1525 
1526 static int EsDrvGetRevision2(void)
1527 {
1528  return EsAcsGetRevision2();
1529 }
1530 
1531 #if 0
1532 static int EsDrvGetReg(int a1)
1533 {
1534  return EsAcsGetReg(a1);
1535 }
1536 #endif
1537 
1538 #if 0
1539 static void EsDrvSetReg(u8 a1, u8 a2)
1540 {
1541  EsAcsSetReg(a1, a2);
1542 }
1543 #endif
1544 
1545 static int
1546 esioctl2_func_1(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1547 {
1548  (void)f;
1549  (void)cmd;
1550  (void)arg;
1551  (void)arglen;
1552  (void)buflen;
1553 
1554  *(u8 *)buf = EsDrvGetChipVersion();
1555  *((u8 *)buf + 1) = EsDrvGetRevision1();
1556  *((u8 *)buf + 2) = EsDrvGetRevision2();
1557  return 0;
1558 }
1559 
1560 static int
1561 esioctl2_func_10(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1562 {
1563  (void)f;
1564  (void)cmd;
1565  (void)arg;
1566  (void)arglen;
1567  (void)buflen;
1568 
1569  *(u32 *)buf = 0x4071200;
1570  return 0;
1571 }
1572 
1573 static int
1574 esioctl2_func_2(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1575 {
1576  (void)f;
1577  (void)cmd;
1578  (void)arg;
1579  (void)arglen;
1580  (void)buf;
1581  (void)buflen;
1582 
1583  return 0;
1584 }
1585 
1586 static int
1587 esioctl2_func_3(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1588 {
1589  (void)f;
1590  (void)cmd;
1591  (void)arg;
1592  (void)arglen;
1593  (void)buf;
1594  (void)buflen;
1595 
1596  return 0;
1597 }
1598 
1599 static int
1600 esioctl2_func_4(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1601 {
1602  (void)f;
1603  (void)cmd;
1604  (void)arglen;
1605  (void)buf;
1606  (void)buflen;
1607 
1608  EsDrvSoftReset();
1609  EsDrvSetSerialNumber((u8 *)arg);
1610  if ( EsDrvSetSde((u8 *)arg + 4) != 0 )
1611  {
1612  return -EPERM;
1613  }
1614  if (
1615  EsDrvCheckSdeProcess(((*((u8 *)arg + 452) << 16) & 0x1FFFF) | (u16)(*((u8 *)arg + 451) << 8) | *((u8 *)arg + 450))
1616  != 0 )
1617  {
1618  return -ENOENT;
1619  }
1620  if ( EsDrvTrmntInitProcess() != 0 )
1621  {
1622  return -ESRCH;
1623  }
1624  EsDrvCmpltInitProcess();
1625  return 0;
1626 }
1627 
1628 static int
1629 esioctl2_func_5(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1630 {
1631  (void)f;
1632  (void)cmd;
1633  (void)arg;
1634  (void)arglen;
1635  (void)buf;
1636  (void)buflen;
1637 
1638  if ( EsDrvRndNnCheck() )
1639  return -EINTR;
1640  if ( EsDrvRandom() != 0 )
1641  return -EIO;
1642  return 0;
1643 }
1644 
1645 static int
1646 esioctl2_func_6(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1647 {
1648  (void)f;
1649  (void)cmd;
1650  (void)arglen;
1651  (void)buf;
1652  (void)buflen;
1653 
1654  if ( EsDrvRndNnCheck() != 0 )
1655  {
1656  return -EINTR;
1657  }
1658  if ( (unsigned int)*(u8 *)arg - 1 >= 0x10 )
1659  {
1660  return -EAGAIN;
1661  }
1662  EsDrvSetNnParam(*(u8 *)arg, (u8 *)arg + 1);
1663  EsDrvSetNnStart();
1664  return 0;
1665 }
1666 
1667 static int
1668 esioctl2_func_7(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1669 {
1670  (void)f;
1671  (void)cmd;
1672  (void)arg;
1673  (void)arglen;
1674  (void)buflen;
1675 
1676  *(u8 *)buf = EsDrvStartNnCheckStat();
1677  return 0;
1678 }
1679 
1680 static int
1681 esioctl2_func_8(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1682 {
1683  (void)f;
1684  (void)cmd;
1685  (void)arg;
1686  (void)arglen;
1687  (void)buflen;
1688 
1689  EsDrvSetNnStop();
1690  *(u8 *)buf = EsDrvStopNnCheckStat();
1691  return 0;
1692 }
1693 
1694 static int
1695 esioctl2_func_9(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1696 {
1697  int i;
1698 
1699  (void)f;
1700  (void)cmd;
1701  (void)arglen;
1702  (void)buflen;
1703 
1704  if ( EsDrvSetUUStart((u8 *)arg) != 0 )
1705  {
1706  return -ENXIO;
1707  }
1708  if ( EsDrvCmpltUUProcess() != 0 )
1709  {
1710  return -E2BIG;
1711  }
1712  // cppcheck-suppress knownConditionTrueFalse
1713  if ( EsDrvSetTTStart(*((u8 *)arg + 8), (u8 *)arg + 9) != 0 )
1714  {
1715  return -ENOEXEC;
1716  }
1717  if ( EsDrvCmpltTTProcess(*((u8 *)arg + 8), (u8 *)arg + 9) != 0 )
1718  {
1719  return -EBADF;
1720  }
1721 
1722  for ( i = 0; i < 8; i += 1 )
1723  {
1724  ((u8 *)buf)[i] = ((u8 *)arg)[i + 9];
1725  }
1726  return 0;
1727 }
1728 
1729 static int
1730 esioctl2_func_a(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1731 {
1732  (void)f;
1733  (void)cmd;
1734  (void)arg;
1735  (void)arglen;
1736  (void)buf;
1737  (void)buflen;
1738 
1739  EsDrvAaStart();
1740  return 0;
1741 }
1742 
1743 static int
1744 esioctl2_func_b(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1745 {
1746  (void)f;
1747  (void)cmd;
1748  (void)arg;
1749  (void)arglen;
1750  (void)buflen;
1751 
1752  *(u8 *)buf = EsDrvAaBsCheck();
1753  *((u8 *)buf + 1) = EsDrvAaEmptyCheck();
1754  return 0;
1755 }
1756 
1757 static int
1758 esioctl2_func_c(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1759 {
1760  (void)f;
1761  (void)cmd;
1762  (void)arg;
1763  (void)arglen;
1764  (void)buf;
1765  (void)buflen;
1766 
1767  if ( EsDrvAaStop() != 0 )
1768  return -ECHILD;
1769  return 0;
1770 }
1771 
1772 static int
1773 esioctl2_func_d(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1774 {
1775  (void)f;
1776  (void)cmd;
1777  (void)arg;
1778  (void)arglen;
1779  (void)buf;
1780  (void)buflen;
1781 
1782  EsDrvBbStart();
1783  return 0;
1784 }
1785 
1786 static int
1787 esioctl2_func_e(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1788 {
1789  (void)f;
1790  (void)cmd;
1791  (void)arg;
1792  (void)arglen;
1793  (void)buflen;
1794 
1795  *(u8 *)buf = EsDrvBbBsCheck();
1796  *((u8 *)buf + 1) = EsDrvBbEmptyCheck();
1797  return 0;
1798 }
1799 
1800 static int
1801 esioctl2_func_f(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
1802 {
1803  (void)f;
1804  (void)cmd;
1805  (void)arg;
1806  (void)arglen;
1807  (void)buf;
1808  (void)buflen;
1809 
1810  if ( EsDrvBbStop() != 0 )
1811  return -ECHILD;
1812  return 0;
1813 }
_ModuleInfo::newflags
u16 newflags
Definition: loadcore.h:36
IOP_DT_FSEXT
#define IOP_DT_FSEXT
Definition: iomanX.h:66
iop_sema_t
Definition: thsemap.h:38
_iomanX_iop_file
Definition: iomanX.h:70
EPERM
#define EPERM
Definition: errno.h:21
ENXIO
#define ENXIO
Definition: errno.h:31
EIO
#define EIO
Definition: errno.h:29
loadcore.h
ENOEXEC
#define ENOEXEC
Definition: errno.h:35
ENOENT
#define ENOENT
Definition: errno.h:23
EAGAIN
#define EAGAIN
Definition: errno.h:41
ENOTSUP
#define ENOTSUP
Definition: errno.h:259
_iomanX_iop_device_ops
Definition: iomanX.h:95
ECHILD
#define ECHILD
Definition: errno.h:39
_iomanX_iop_device
Definition: iomanX.h:81
E2BIG
#define E2BIG
Definition: errno.h:33
EBADF
#define EBADF
Definition: errno.h:37
ESRCH
#define ESRCH
Definition: errno.h:25
EINTR
#define EINTR
Definition: errno.h:27
EINVAL
#define EINVAL
Definition: errno.h:63
DevctlCmdTbl_t
Definition: xesdrv.c:198
_ModuleInfo
Definition: loadcore.h:31
errno.h
es_regs_
Definition: xesdrv.c:64