PS2SDK
PS2 Homebrew Libraries
dvrmisc.c
1 /*
2 # _____ ___ ____ ___ ____
3 # ____| | ____| | | |____|
4 # | ___| |____ ___| ____| | \ PS2DEV Open Source Project.
5 #-----------------------------------------------------------------------
6 # Copyright 2021-2021, 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 <stdbool.h>
12 #include "iomanX.h"
13 #include "loadcore.h"
14 #include "pvrdrv.h"
15 #include "stdio.h"
16 #include "sysclib.h"
17 #include "thbase.h"
18 #include "thsemap.h"
19 #include "speedregs.h"
20 #include "errno.h"
21 
22 #define MODNAME "DVRMISC"
23 #ifdef DEBUG
24 #define DPRINTF(x...) printf(MODNAME ": " x)
25 #else
26 #define DPRINTF(x...)
27 #endif
28 
29 extern int module_start(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi);
30 extern int module_stop(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi);
31 extern int dvrmisc_df_init(iomanX_iop_device_t *dev);
32 extern int dvrmisc_df_exit(iomanX_iop_device_t *dev);
33 extern int dvrmisc_df_ioctl(iomanX_iop_file_t *f, int cmd, void *param);
34 extern int dvrmisc_df_devctl(iomanX_iop_file_t *a1, const char *name, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
35 extern int dvrmisc_df_ioctl2(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
36 extern int dvrioctl2_nop(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
37 extern int dvrioctl2_version(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
38 extern int dvrioctl2_led_hdd_rec(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
39 extern int dvrioctl2_led_dvd_rec(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
40 extern int dvrioctl2_get_sircs(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
41 extern int dvrioctl2_get_time(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
42 extern int dvrioctl2_set_timezone(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
43 extern int dvrioctl2_save_preset_info(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
44 extern int dvrioctl2_load_preset_info(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
45 extern int dvrioctl2_test_dev_rst(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
46 extern int dvrioctl2_test_sdram_chk(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
47 extern int dvrioctl2_test_mpe_chk(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
48 extern int dvrioctl2_test_mpd_chk(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
49 extern int dvrioctl2_test_vdec_chk(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
50 extern int dvrioctl2_partition_free(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
51 extern int dvrioctl2_buzzer(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
52 extern int dvrioctl2_clr_preset_info(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
53 extern int dvrioctl2_get_vbi_err_rate(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
54 extern int dvrioctl2_update_dvrp_firmware(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
55 extern int dvrioctl2_flash_write_status(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
56 extern int dvrioctl2_set_device_key(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
57 extern int dvrioctl2_get_device_key(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
58 extern int dvrioctl2_set_dv_nodeid(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
59 extern int dvrioctl2_get_dv_nodeid(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
60 extern int dvrioctl2_diag_test(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
61 
62 #ifdef DVRMISC_CFW_EXTENSIONS
63 extern int dvrioctl2_cfw_ping(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
64 extern int dvrioctl2_cfw_get_max_lba48(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
65 extern int dvrioctl2_cfw_mem_peek_poke(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
66 #endif
67 
68 struct DevctlCmdTbl_t
69 {
70  u16 cmd;
71  int (*fn)(iomanX_iop_file_t *f, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen);
72 } DevctlCmdTbl[] =
73  {
74  {0x5668, &dvrioctl2_get_sircs},
75  {0x5666, &dvrioctl2_led_hdd_rec},
76  {0x5667, &dvrioctl2_led_dvd_rec},
77  {0x5669, &dvrioctl2_get_time},
78  {0x566A, &dvrioctl2_set_timezone},
79  {0x566B, &dvrioctl2_save_preset_info},
80  {0x566C, &dvrioctl2_load_preset_info},
81  {0x5664, &dvrioctl2_nop},
82  {0x5665, &dvrioctl2_version},
83  {0x566D, &dvrioctl2_test_dev_rst},
84  {0x566E, &dvrioctl2_test_sdram_chk},
85  {0x566F, &dvrioctl2_test_mpe_chk},
86  {0x5670, &dvrioctl2_test_mpd_chk},
87  {0x5671, &dvrioctl2_test_vdec_chk},
88  {0x5672, &dvrioctl2_partition_free},
89  {0x5673, &dvrioctl2_buzzer},
90  {0x5674, &dvrioctl2_clr_preset_info},
91  {0x5675, &dvrioctl2_get_vbi_err_rate},
92  {0x5676, &dvrioctl2_update_dvrp_firmware},
93  {0x5677, &dvrioctl2_flash_write_status},
94  {0x5678, &dvrioctl2_set_device_key},
95  {0x5679, &dvrioctl2_get_device_key},
96  {0x567A, &dvrioctl2_set_dv_nodeid},
97  {0x567B, &dvrioctl2_get_dv_nodeid},
98  {0x5682, &dvrioctl2_diag_test},
99 #ifdef DVRMISC_CFW_EXTENSIONS
100  {0x5690, &dvrioctl2_cfw_ping},
101  {0x5691, &dvrioctl2_cfw_get_max_lba48},
102  {0x5692, &dvrioctl2_cfw_mem_peek_poke},
103 #endif
104 
105 };
106 
107 IOMANX_RETURN_VALUE_IMPL(EUNSUP);
108 
109 static iomanX_iop_device_ops_t DvrFuncTbl =
110  {
111  &dvrmisc_df_init, // init
112  &dvrmisc_df_exit, // deinit
113  IOMANX_RETURN_VALUE(EUNSUP), // format
114  IOMANX_RETURN_VALUE(EUNSUP), // open
115  IOMANX_RETURN_VALUE(EUNSUP), // close
116  IOMANX_RETURN_VALUE(EUNSUP), // read
117  IOMANX_RETURN_VALUE(EUNSUP), // write
118  IOMANX_RETURN_VALUE(EUNSUP), // lseek
119  &dvrmisc_df_ioctl, // ioctl
120  IOMANX_RETURN_VALUE(EUNSUP), // remove
121  IOMANX_RETURN_VALUE(EUNSUP), // mkdir
122  IOMANX_RETURN_VALUE(EUNSUP), // rmdir
123  IOMANX_RETURN_VALUE(EUNSUP), // dopen
124  IOMANX_RETURN_VALUE(EUNSUP), // dclose
125  IOMANX_RETURN_VALUE(EUNSUP), // dread
126  IOMANX_RETURN_VALUE(EUNSUP), // getstat
127  IOMANX_RETURN_VALUE(EUNSUP), // chstat
128  IOMANX_RETURN_VALUE(EUNSUP), // rename
129  IOMANX_RETURN_VALUE(EUNSUP), // chdir
130  IOMANX_RETURN_VALUE(EUNSUP), // sync
131  IOMANX_RETURN_VALUE(EUNSUP), // mount
132  IOMANX_RETURN_VALUE(EUNSUP), // umount
133  IOMANX_RETURN_VALUE_S64(EUNSUP), // lseek64
134  &dvrmisc_df_devctl, // devctl
135  IOMANX_RETURN_VALUE(EUNSUP), // symlink
136  IOMANX_RETURN_VALUE(EUNSUP), // readlink
137  &dvrmisc_df_ioctl2, // ioctl2
138  };
139 static iomanX_iop_device_t DVRMISC = {
140  .name = "dvr_misc",
141  .desc = "Digital Video Recorder MISC task",
142  .type = (IOP_DT_FS | IOP_DT_FSEXT),
143  .ops = &DvrFuncTbl,
144 };
145 s32 sema_id;
146 char SBUF[16384];
147 
148 // Based off of DESR / PSX DVR system software version 1.31.
149 // Added additional functions from DESR / PSX DVR system software version 2.11.
150 IRX_ID(MODNAME, 1, 1);
151 
152 int _start(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi)
153 {
154  if (argc >= 0)
155  return module_start(argc, argv, startaddr, mi);
156  else
157  return module_stop(argc, argv, startaddr, mi);
158 }
159 
160 int module_start(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi)
161 {
162  int i;
163 
164  (void)argc;
165  (void)argv;
166  (void)startaddr;
167 
168  for (i = 0; i < 30000; ++i) {
169  if (((*((vu32 *)0xB0004230)) & 4) != 0)
170  break;
171  DelayThread(1000);
172  }
173  if (i == 30000) {
174  DPRINTF("MISC task of DVRP is not running...\n");
175  return MODULE_NO_RESIDENT_END;
176  } else {
177  if (iomanX_AddDrv(&DVRMISC) != 0)
178  return MODULE_NO_RESIDENT_END;
179  }
180 #if 0
181  return MODULE_REMOVABLE_END;
182 #else
183  if (mi && ((mi->newflags & 2) != 0))
184  mi->newflags |= 0x10;
185  return MODULE_RESIDENT_END;
186 #endif
187 }
188 
189 int module_stop(int argc, char *argv[], void *startaddr, ModuleInfo_t *mi)
190 {
191  (void)argc;
192  (void)argv;
193  (void)startaddr;
194  (void)mi;
195 
196  if (iomanX_DelDrv(DVRMISC.name) != 0)
197  return MODULE_REMOVABLE_END;
198  return MODULE_NO_RESIDENT_END;
199 }
200 
201 int dvrmisc_df_init(iomanX_iop_device_t *dev)
202 {
203  int v1;
204  iop_sema_t v3;
205 
206  (void)dev;
207 
208  v3.attr = 0;
209  v3.initial = 1;
210  v3.max = 1;
211  v3.option = 0;
212  v1 = CreateSema(&v3);
213  if (v1 < 0)
214  return -1;
215  sema_id = v1;
216  return 0;
217 }
218 
219 int dvrmisc_df_exit(iomanX_iop_device_t *dev)
220 {
221  (void)dev;
222 
223  if (DeleteSema(sema_id) != 0)
224  return -1;
225  return 0;
226 }
227 
228 int dvrmisc_df_ioctl(iomanX_iop_file_t *f, int cmd, void *param)
229 {
230  (void)f;
231  (void)cmd;
232  (void)param;
233 
234  WaitSema(sema_id);
235  SignalSema(sema_id);
236  return -EINVAL;
237 }
238 
239 int dvrmisc_df_devctl(
240  iomanX_iop_file_t *a1,
241  const char *name,
242  int cmd,
243  void *arg,
244  unsigned int arglen,
245  void *buf,
246  unsigned int buflen)
247 {
248  int v10;
249  unsigned int v11;
250  unsigned int v12;
251 
252  (void)name;
253 
254  v10 = 0;
255  v11 = 0;
256  WaitSema(sema_id);
257  v12 = 0;
258  while (DevctlCmdTbl[v12].cmd != cmd) {
259  v12 = ++v11;
260  if (v11 >= sizeof(DevctlCmdTbl) / sizeof(DevctlCmdTbl[0]))
261  goto LABEL_5;
262  }
263  v10 = DevctlCmdTbl[v12].fn(a1, cmd, arg, arglen, buf, buflen);
264 LABEL_5:
265  if (v11 == sizeof(DevctlCmdTbl) / sizeof(DevctlCmdTbl[0]))
266  v10 = -EINVAL;
267  SignalSema(sema_id);
268  return v10;
269 }
270 
271 int dvrmisc_df_ioctl2(
273  int cmd,
274  void *arg,
275  unsigned int arglen,
276  void *buf,
277  unsigned int buflen)
278 {
279 
280  (void)f;
281  (void)cmd;
282  (void)arg;
283  (void)arglen;
284  (void)buf;
285  (void)buflen;
286 
287  WaitSema(sema_id);
288  SignalSema(sema_id);
289  return -EINVAL;
290 }
291 
292 int dvrioctl2_nop(iomanX_iop_file_t *a1, int cmd, void *arg, unsigned int arglen, void *buf, unsigned int buflen)
293 {
294  drvdrv_exec_cmd_ack cmdack;
295 
296  (void)a1;
297  (void)cmd;
298  (void)arg;
299  (void)arglen;
300  (void)buf;
301  (void)buflen;
302 
303  cmdack.command = 0x5101;
304  cmdack.input_word_count = 0;
305  if (DvrdrvExecCmdAck(&cmdack)) {
306  DPRINTF("dvrioctl2_nop -> Handshake error!\n");
307  return -EIO;
308  } else {
309  if (cmdack.ack_status_ack) {
310  DPRINTF("dvrioctl2_nop -> Status error!\n");
311  return -EADV;
312  }
313  }
314  return 0;
315 }
316 
317 int dvrioctl2_version(
318  iomanX_iop_file_t *a1,
319  int cmd,
320  void *arg,
321  unsigned int arglen,
322  void *buf,
323  unsigned int buflen)
324 {
325  drvdrv_exec_cmd_ack cmdack;
326 
327  (void)a1;
328  (void)cmd;
329  (void)arg;
330  (void)arglen;
331  (void)buflen;
332 
333  cmdack.command = 0x5102;
334  cmdack.input_word_count = 0;
335  if (DvrdrvExecCmdAck(&cmdack)) {
336  DPRINTF("dvrioctl2_version -> Handshake error!\n");
337  return -EIO;
338  } else if (cmdack.ack_status_ack) {
339  DPRINTF("dvrioctl2_version -> Status error!\n");
340  return -EADV;
341  } else {
342  *(u16 *)buf = cmdack.output_word[0];
343  *((u16 *)buf + 1) = cmdack.output_word[1];
344  }
345  return 0;
346 }
347 
348 int dvrioctl2_led_hdd_rec(
349  iomanX_iop_file_t *a1,
350  int cmd,
351  void *arg,
352  unsigned int arglen,
353  void *buf,
354  unsigned int buflen)
355 {
356  drvdrv_exec_cmd_ack cmdack;
357 
358  (void)a1;
359  (void)cmd;
360  (void)arglen;
361  (void)buf;
362  (void)buflen;
363 
364  cmdack.command = 0x5104;
365  cmdack.input_word_count = 1;
366  cmdack.input_word[0] = *(u16 *)arg;
367  if (DvrdrvExecCmdAck(&cmdack)) {
368  DPRINTF("dvrioctl2_led_hdd_rec -> Handshake error!\n");
369  return -EIO;
370  } else {
371  if (cmdack.ack_status_ack) {
372  DPRINTF("dvrioctl2_led_hdd_rec -> Status error!\n");
373  return -EADV;
374  }
375  }
376  return 0;
377 }
378 
379 int dvrioctl2_led_dvd_rec(
380  iomanX_iop_file_t *a1,
381  int cmd,
382  void *arg,
383  unsigned int arglen,
384  void *buf,
385  unsigned int buflen)
386 {
387  drvdrv_exec_cmd_ack cmdack;
388 
389  (void)a1;
390  (void)cmd;
391  (void)arglen;
392  (void)buf;
393  (void)buflen;
394 
395  cmdack.command = 0x5106;
396  cmdack.input_word_count = 1;
397  cmdack.input_word[0] = *(u16 *)arg;
398  if (DvrdrvExecCmdAck(&cmdack)) {
399  DPRINTF("dvrioctl2_led_dvd_rec -> Handshake error!\n");
400  return -EIO;
401  } else {
402  if (cmdack.ack_status_ack) {
403  DPRINTF("dvrioctl2_led_dvd_rec -> Status error!\n");
404  return -EADV;
405  }
406  }
407  return 0;
408 }
409 
410 int dvrioctl2_get_sircs(
411  iomanX_iop_file_t *a1,
412  int cmd,
413  void *arg,
414  unsigned int arglen,
415  void *buf,
416  unsigned int buflen)
417 {
418  drvdrv_exec_cmd_ack cmdack;
419 
420  (void)a1;
421  (void)cmd;
422  (void)arg;
423  (void)arglen;
424  (void)buflen;
425 
426  cmdack.command = 0x5107;
427  cmdack.input_word_count = 0;
428  if (DvrdrvExecCmdAck(&cmdack)) {
429  DPRINTF("dvrioctl2_get_sircs -> Handshake error!\n");
430  return -EIO;
431  } else if (cmdack.ack_status_ack) {
432  DPRINTF("dvrioctl2_get_sircs -> Status error!\n");
433  return -EADV;
434  } else {
435  *(u16 *)buf = cmdack.output_word[0];
436  *((u16 *)buf + 1) = cmdack.output_word[1];
437  *((u16 *)buf + 2) = cmdack.output_word[2];
438  *((u16 *)buf + 3) = cmdack.output_word[3];
439  *((u16 *)buf + 4) = cmdack.output_word[4];
440  }
441  return 0;
442 }
443 
444 int dvrioctl2_get_time(
445  iomanX_iop_file_t *a1,
446  int cmd,
447  void *arg,
448  unsigned int arglen,
449  void *buf,
450  unsigned int buflen)
451 {
452  drvdrv_exec_cmd_ack cmdack;
453 
454  (void)a1;
455  (void)cmd;
456  (void)arg;
457  (void)arglen;
458  (void)buflen;
459 
460  cmdack.command = 0x5108;
461  cmdack.input_word_count = 0;
462  if (DvrdrvExecCmdAck(&cmdack)) {
463  DPRINTF("dvrioctl2_get_time -> Handshake error!\n");
464  return -EIO;
465  } else if (cmdack.ack_status_ack) {
466  DPRINTF("dvrioctl2_get_time -> Status error!\n");
467  return -EADV;
468  } else {
469  *(u8 *)buf = cmdack.output_word[0];
470  *((u8 *)buf + 1) = cmdack.output_word[1];
471  *((u8 *)buf + 2) = cmdack.output_word[2];
472  *((u8 *)buf + 3) = cmdack.output_word[3];
473  *((u8 *)buf + 5) = cmdack.output_word[5];
474  *((u8 *)buf + 6) = cmdack.output_word[6];
475  *((u8 *)buf + 7) = cmdack.output_word[7];
476  }
477  return 0;
478 }
479 
480 int dvrioctl2_set_timezone(
481  iomanX_iop_file_t *a1,
482  int cmd,
483  void *arg,
484  unsigned int arglen,
485  void *buf,
486  unsigned int buflen)
487 {
488  drvdrv_exec_cmd_ack cmdack;
489 
490  (void)a1;
491  (void)cmd;
492  (void)arglen;
493  (void)buf;
494  (void)buflen;
495 
496  cmdack.command = 0x5109;
497  cmdack.input_word[0] = *(u16 *)arg;
498  cmdack.input_word_count = 2;
499  cmdack.input_word[1] = *((u16 *)arg + 1);
500  if (DvrdrvExecCmdAck(&cmdack)) {
501  DPRINTF("dvrioctl2_set_timezone -> Handshake error!\n");
502  return -EIO;
503  } else {
504  if (cmdack.ack_status_ack) {
505  DPRINTF("dvrioctl2_set_timezone -> Status error!\n");
506  return -EADV;
507  }
508  }
509  return 0;
510 }
511 
512 int dvrioctl2_save_preset_info(
513  iomanX_iop_file_t *a1,
514  int cmd,
515  void *arg,
516  unsigned int arglen,
517  void *buf,
518  unsigned int buflen)
519 {
520  drvdrv_exec_cmd_ack cmdack;
521 
522  (void)a1;
523  (void)cmd;
524  (void)arg;
525  (void)arglen;
526  (void)buf;
527  (void)buflen;
528 
529  cmdack.command = 0x510A;
530  cmdack.input_word_count = 0;
531  cmdack.timeout = 15000000;
532  if (DvrdrvExecCmdAckComp(&cmdack)) {
533  DPRINTF("dvrioctl2_save_preset_info -> Handshake error!\n");
534  return -EIO;
535  } else if (cmdack.ack_status_ack || cmdack.comp_status) {
536  DPRINTF("dvrioctl2_save_preset_info -> Status error!\n");
537  return -EADV;
538  }
539  return 0;
540 }
541 
542 int dvrioctl2_load_preset_info(
543  iomanX_iop_file_t *a1,
544  int cmd,
545  void *arg,
546  unsigned int arglen,
547  void *buf,
548  unsigned int buflen)
549 {
550  drvdrv_exec_cmd_ack cmdack;
551 
552  (void)a1;
553  (void)cmd;
554  (void)arg;
555  (void)arglen;
556  (void)buf;
557  (void)buflen;
558 
559  cmdack.command = 0x510B;
560  cmdack.input_word_count = 0;
561  cmdack.timeout = 15000000;
562  if (DvrdrvExecCmdAckComp(&cmdack)) {
563  DPRINTF("dvrioctl2_load_preset_info -> Handshake error!\n");
564  return -EIO;
565  } else if (cmdack.ack_status_ack || cmdack.comp_status) {
566  DPRINTF("dvrioctl2_load_preset_info -> Status error!\n");
567  return -EADV;
568  }
569  return 0;
570 }
571 
572 int dvrioctl2_test_dev_rst(
573  iomanX_iop_file_t *a1,
574  int cmd,
575  void *arg,
576  unsigned int arglen,
577  void *buf,
578  unsigned int buflen)
579 {
580  drvdrv_exec_cmd_ack cmdack;
581 
582  (void)a1;
583  (void)cmd;
584  (void)arg;
585  (void)arglen;
586  (void)buf;
587  (void)buflen;
588 
589  cmdack.command = 0x510C;
590  cmdack.input_word_count = 0;
591  cmdack.timeout = 15000000;
592  if (DvrdrvExecCmdAckComp(&cmdack)) {
593  DPRINTF("dvrioctl2_test_dev_rst -> Handshake error!\n");
594  return -EIO;
595  } else if (cmdack.ack_status_ack || cmdack.comp_status) {
596  DPRINTF("dvrioctl2_test_dev_rst -> Status error!\n");
597  return -EADV;
598  }
599  return 0;
600 }
601 
602 int dvrioctl2_test_sdram_chk(
603  iomanX_iop_file_t *a1,
604  int cmd,
605  void *arg,
606  unsigned int arglen,
607  void *buf,
608  unsigned int buflen)
609 {
610  drvdrv_exec_cmd_ack cmdack;
611 
612  (void)a1;
613  (void)cmd;
614  (void)arg;
615  (void)arglen;
616  (void)buflen;
617 
618  cmdack.command = 0x510D;
619  cmdack.input_word_count = 0;
620  cmdack.timeout = 20000000;
621  if (DvrdrvExecCmdAckComp(&cmdack)) {
622  DPRINTF("dvrioctl2_test_sdram_chk -> Handshake error!\n");
623  return -EIO;
624  } else if (cmdack.ack_status_ack || cmdack.comp_status) {
625  DPRINTF("dvrioctl2_test_sdram_chk -> Status error!\n");
626  return -EADV;
627  } else {
628  *(u32 *)buf = (cmdack.return_result_word[0] << 16) + cmdack.return_result_word[1];
629  *((u32 *)buf + 1) = (cmdack.return_result_word[2] << 16) + cmdack.return_result_word[3];
630  *((u32 *)buf + 2) = (cmdack.return_result_word[4] << 16) + cmdack.return_result_word[5];
631  }
632  return 0;
633 }
634 
635 int dvrioctl2_test_mpe_chk(
636  iomanX_iop_file_t *a1,
637  int cmd,
638  void *arg,
639  unsigned int arglen,
640  void *buf,
641  unsigned int buflen)
642 {
643  drvdrv_exec_cmd_ack cmdack;
644 
645  (void)a1;
646  (void)cmd;
647  (void)arg;
648  (void)arglen;
649  (void)buflen;
650 
651  cmdack.command = 0x510E;
652  cmdack.input_word_count = 0;
653  cmdack.timeout = 15000000;
654  if (DvrdrvExecCmdAckComp(&cmdack)) {
655  DPRINTF("dvrioctl2_test_mpe_chk -> Handshake error!\n");
656  return -EIO;
657  } else if (cmdack.ack_status_ack || cmdack.comp_status) {
658  DPRINTF("dvrioctl2_test_mpe_chk -> Status error!\n");
659  return -EADV;
660  } else {
661  *(u16 *)buf = cmdack.return_result_word[0];
662  }
663  return 0;
664 }
665 
666 int dvrioctl2_test_mpd_chk(
667  iomanX_iop_file_t *a1,
668  int cmd,
669  void *arg,
670  unsigned int arglen,
671  void *buf,
672  unsigned int buflen)
673 {
674  drvdrv_exec_cmd_ack cmdack;
675 
676  (void)a1;
677  (void)cmd;
678  (void)arg;
679  (void)arglen;
680  (void)buflen;
681 
682  cmdack.command = 0x510F;
683  cmdack.input_word_count = 0;
684  cmdack.timeout = 15000000;
685  if (DvrdrvExecCmdAckComp(&cmdack)) {
686  DPRINTF("dvrioctl2_test_mpd_chk -> Handshake error!\n");
687  return -EIO;
688  } else if (cmdack.ack_status_ack || cmdack.comp_status) {
689  DPRINTF("dvrioctl2_test_mpd_chk -> Status error!\n");
690  return -EADV;
691  } else {
692  *(u16 *)buf = cmdack.return_result_word[0];
693  }
694  return 0;
695 }
696 
697 int dvrioctl2_test_vdec_chk(
698  iomanX_iop_file_t *a1,
699  int cmd,
700  void *arg,
701  unsigned int arglen,
702  void *buf,
703  unsigned int buflen)
704 {
705  drvdrv_exec_cmd_ack cmdack;
706 
707  (void)a1;
708  (void)cmd;
709  (void)arg;
710  (void)arglen;
711  (void)buf;
712  (void)buflen;
713 
714  cmdack.command = 0x5110;
715  cmdack.input_word_count = 0;
716  cmdack.timeout = 15000000;
717  if (DvrdrvExecCmdAckComp(&cmdack)) {
718  DPRINTF("dvrioctl2_test_vdec_chk -> Handshake error!\n");
719  return -EIO;
720  } else if (cmdack.ack_status_ack || cmdack.comp_status) {
721  DPRINTF("dvrioctl2_test_vdec_chk -> Status error!\n");
722  return -EADV;
723  }
724  return 0;
725 }
726 
727 int dvrioctl2_partition_free(
728  iomanX_iop_file_t *a1,
729  int cmd,
730  void *arg,
731  unsigned int arglen,
732  void *buf,
733  unsigned int buflen)
734 {
735  int v7;
736  int v8;
737  int v9;
738  s64 v10;
739 
740  (void)a1;
741  (void)cmd;
742  (void)arglen;
743  (void)buflen;
744 
745  v7 = iomanX_devctl((const char *)arg, 0x5002, 0, 0, 0, 0);
746  v8 = v7;
747  if (v7 < 0) {
748  DPRINTF("dvrioctl2_partition_free : Cannot execute PDIOC_ZONEFREE.,%d\n", v7);
749  return -EIO;
750  }
751  v9 = iomanX_devctl((const char *)arg, 0x5001, 0, 0, 0, 0);
752  v10 = v8 * (s64)v9;
753  if (v9 < 0) {
754  DPRINTF("dvrioctl2_partition_free : Cannot execute PDIOC_ZONESZ.,%d\n", v9);
755  return -EIO;
756  }
757  *(u64 *)buf = v10;
758  if (*(s64 *)buf <= 0x7FFFFFF) {
759  *(u32 *)buf = 0;
760  *((u32 *)buf + 1) = 0;
761  } else {
762  *(u32 *)buf = v10 - 0x8000000;
763  *((u32 *)buf + 1) = (v10 >> 32) - 1 + ((unsigned int)(v10 - 0x8000000) < 0xF8000000);
764  }
765  return 0;
766 }
767 
768 int dvrioctl2_buzzer(
769  iomanX_iop_file_t *a1,
770  int cmd,
771  void *arg,
772  unsigned int arglen,
773  void *buf,
774  unsigned int buflen)
775 {
776  drvdrv_exec_cmd_ack cmdack;
777 
778  (void)a1;
779  (void)cmd;
780  (void)arg;
781  (void)arglen;
782  (void)buf;
783  (void)buflen;
784 
785  cmdack.command = 0x5111;
786  cmdack.input_word_count = 0;
787  if (DvrdrvExecCmdAck(&cmdack)) {
788  DPRINTF("dvrioctl2_buzzer -> Handshake error!\n");
789  return -EIO;
790  } else {
791  if (cmdack.ack_status_ack) {
792  DPRINTF("dvrioctl2_buzzer -> Status error!\n");
793  return -EADV;
794  }
795  }
796  return 0;
797 }
798 
799 int dvrioctl2_clr_preset_info(
800  iomanX_iop_file_t *a1,
801  int cmd,
802  void *arg,
803  unsigned int arglen,
804  void *buf,
805  unsigned int buflen)
806 {
807  drvdrv_exec_cmd_ack cmdack;
808 
809  (void)a1;
810  (void)cmd;
811  (void)arg;
812  (void)arglen;
813  (void)buf;
814  (void)buflen;
815 
816  cmdack.command = 0x5112;
817  cmdack.input_word_count = 0;
818  cmdack.timeout = 20000000;
819  if (DvrdrvExecCmdAckComp(&cmdack)) {
820  DPRINTF("dvrioctl2_clr_preset_info -> Handshake error!\n");
821  return -EIO;
822  } else {
823  if (cmdack.ack_status_ack) {
824  DPRINTF("dvrioctl2_clr_preset_info -> Status error!\n");
825  return -EADV;
826  }
827  }
828  return 0;
829 }
830 
831 int dvrioctl2_get_vbi_err_rate(
832  iomanX_iop_file_t *a1,
833  int cmd,
834  void *arg,
835  unsigned int arglen,
836  void *buf,
837  unsigned int buflen)
838 {
839  drvdrv_exec_cmd_ack cmdack;
840 
841  (void)a1;
842  (void)cmd;
843  (void)arg;
844  (void)arglen;
845  (void)buflen;
846 
847  cmdack.command = 0x5113;
848  cmdack.input_word_count = 0;
849  if (DvrdrvExecCmdAck(&cmdack)) {
850  DPRINTF("dvrioctl2_get_vbi_err_rate -> Handshake error!\n");
851  return -EIO;
852  } else {
853  if (cmdack.ack_status_ack) {
854  DPRINTF("dvrioctl2_get_vbi_err_rate -> Status error!\n");
855  return -EADV;
856  } else {
857  *(u32 *)buf = (cmdack.output_word[0] << 16) + cmdack.output_word[1];
858  *((u32 *)buf + 1) = (cmdack.output_word[2] << 16) + cmdack.output_word[3];
859  }
860  }
861  return 0;
862 }
863 
864 int dvrioctl2_update_dvrp_firmware(
865  iomanX_iop_file_t *a1,
866  int cmd,
867  void *arg,
868  unsigned int arglen,
869  void *buf,
870  unsigned int buflen)
871 {
872  int read_offset;
873  int checksum;
874  int retval;
875  int update_fd;
876  int update_size;
877  int i;
878  drvdrv_exec_cmd_ack cmdack;
879 
880  (void)a1;
881  (void)cmd;
882  (void)buf;
883  (void)buflen;
884 
885  read_offset = 0;
886  checksum = 0;
887  retval = -EPERM;
888  update_fd = iomanX_open((const char *)arg, 1, 0x49, arglen);
889  if (update_fd < 0) {
890  retval = -ENOENT;
891  goto LABEL_38;
892  }
893  update_size = iomanX_lseek(update_fd, 0, 2);
894  if (iomanX_lseek(update_fd, 0, 0) < 0)
895  goto LABEL_38;
896  cmdack.command = 0x5114;
897  cmdack.input_word[0] = update_size >> 16;
898  cmdack.input_word[1] = update_size;
899  cmdack.input_word_count = 2;
900  cmdack.timeout = 10000000;
901  if (DvrdrvExecCmdAckComp(&cmdack)) {
902  DPRINTF("FLASH_DATA_TOTALSIZE -> Handshake error!\n");
903  LABEL_37:
904  retval = -EIO;
905  goto LABEL_38;
906  }
907  if (cmdack.ack_status_ack) {
908  DPRINTF("FLASH_DATA_TOTALSIZE -> Status error!\n");
909  goto LABEL_37;
910  }
911  if (cmdack.comp_status) {
912  DPRINTF("FLASH_DATA_TOTALSIZE -> Status error!\n");
913  goto LABEL_37;
914  }
915  if (update_size != (cmdack.return_result_word[0] << 16) + cmdack.return_result_word[1])
916  DPRINTF("Size of firmware is not equal to Size of buffer on DVRP memory.\n");
917  for (i = 0x3FFF;; i = 0x3FFF) {
918  char *v13;
919  int read_size;
920  int j;
921  v13 = &SBUF[0x3FFF];
922  do {
923  *v13 = 0;
924  --i;
925  --v13;
926  } while (i >= 0);
927  read_size = iomanX_read(update_fd, SBUF, 0x4000);
928  if (read_size <= 0)
929  break;
930  cmdack.command = 0x5115;
931  cmdack.input_word[0] = read_offset >> 16;
932  cmdack.input_word[1] = read_offset;
933  cmdack.input_word_count = 2;
934  cmdack.input_buffer = SBUF;
935  cmdack.input_buffer_length = read_size;
936  cmdack.timeout = 10000000;
937  if (DvrdrvExecCmdAckDmaSendComp(&cmdack)) {
938  DPRINTF("MISCCMD_FLASH_DATA_DOWNLOAD -> Handshake error!\n");
939  goto LABEL_37;
940  }
941  if (cmdack.ack_status_ack || (read_offset += read_size, cmdack.comp_status)) {
942  DPRINTF("MISCCMD_FLASH_DATA_DOWNLOAD -> Status error!\n");
943  goto LABEL_37;
944  }
945  for (j = 0; j < read_size; ++j) {
946  checksum += (u8)SBUF[j];
947  }
948  }
949  cmdack.command = 0x5116;
950  cmdack.input_word[0] = update_size >> 16;
951  cmdack.input_word[2] = checksum >> 16;
952  cmdack.input_word[1] = update_size;
953  cmdack.input_word[3] = checksum;
954  cmdack.input_word[4] = 0;
955  cmdack.input_word[5] = 0;
956  cmdack.input_word_count = 6;
957  cmdack.timeout = 10000000;
958  if (DvrdrvExecCmdAckComp(&cmdack)) {
959  DPRINTF("MISCCMD_FLASH_DATA_CHECKSUM -> Handshake error!\n");
960  goto LABEL_37;
961  }
962  if (cmdack.ack_status_ack) {
963  DPRINTF("MISCCMD_FLASH_DATA_CHECKSUM -> ACK Status error!\n");
964  } else {
965  if (cmdack.comp_status) {
966  retval = -EADV;
967  DPRINTF("MISCCMD_FLASH_DATA_CHECKSUM -> COMP Status error!\n");
968  DPRINTF(
969  "Check sum error! IOP:%08X,DVRP:%08X\n",
970  checksum,
971  (cmdack.return_result_word[0] << 16) | cmdack.return_result_word[1]);
972  goto LABEL_38;
973  }
974  cmdack.command = 0x5117;
975  cmdack.input_word_count = 0;
976  cmdack.timeout = 10000000;
977  if (DvrdrvExecCmdAckComp(&cmdack)) {
978  DPRINTF("MISCCMD_FLASH_DATA_WRITE -> Handshake error!\n");
979  goto LABEL_37;
980  }
981  if (cmdack.ack_status_ack) {
982  DPRINTF("MISCCMD_FLASH_DATA_WRITE -> ACK Status error!\n");
983  } else {
984  retval = 0;
985  if (!cmdack.comp_status)
986  goto LABEL_38;
987  DPRINTF("MISCCMD_FLASH_DATA_WRITE -> COMP Status error!\n");
988  }
989  }
990  retval = -EADV;
991 LABEL_38:
992  iomanX_close(update_fd);
993  return retval;
994 }
995 
996 int dvrioctl2_flash_write_status(
997  iomanX_iop_file_t *a1,
998  int cmd,
999  void *arg,
1000  unsigned int arglen,
1001  void *buf,
1002  unsigned int buflen)
1003 {
1004  drvdrv_exec_cmd_ack cmdack;
1005 
1006  (void)a1;
1007  (void)cmd;
1008  (void)arg;
1009  (void)arglen;
1010  (void)buflen;
1011 
1012  cmdack.command = 0x5118;
1013  cmdack.input_word_count = 0;
1014  if (DvrdrvExecCmdAck(&cmdack)) {
1015  DPRINTF("dvrioctl2_flash_write_status -> Handshake error!\n");
1016  return -EIO;
1017  } else if (cmdack.ack_status_ack) {
1018  DPRINTF("dvrioctl2_flash_write_status -> Status error!\n");
1019  return -EADV;
1020  } else {
1021  *(u16 *)buf = cmdack.output_word[0];
1022  *((u16 *)buf + 1) = cmdack.output_word[1];
1023  }
1024  return 0;
1025 }
1026 
1027 int dvrioctl2_set_device_key(
1028  iomanX_iop_file_t *a1,
1029  int cmd,
1030  void *arg,
1031  unsigned int arglen,
1032  void *buf,
1033  unsigned int buflen)
1034 {
1035  int cmdack_err;
1036  int bsize;
1037  int *byteswap_tmp2;
1038  int *byteswap_tmp;
1039  int *byteswap_tmp_end;
1040  int cmdack_err3;
1041  int cmdack_err2;
1042  drvdrv_exec_cmd_ack cmdack;
1043 
1044  DPRINTF(
1045  "dvrioctl2_set_device_key (io=%p,cmd=%08X,argp=%p,arglen=%u,bufp=%p,buflen=%u)\n",
1046  a1,
1047  cmd,
1048  arg,
1049  arglen,
1050  buf,
1051  buflen);
1052  cmdack.command = 0x511B;
1053  cmdack.input_word[0] = 0;
1054  cmdack.input_word[1] = 456;
1055  cmdack.input_word_count = 2;
1056  cmdack.timeout = 10000000;
1057  DPRINTF("dvrcmd.cmd_p[0]:%x\n", 0);
1058  DPRINTF("dvrcmd.cmd_p[1]:%x\n", 456);
1059  cmdack_err = DvrdrvExecCmdAckComp(&cmdack);
1060  DPRINTF("dvrcmd.ack_p[0]:%x\n", cmdack.ack_status_ack);
1061  if (cmdack_err) {
1062  DPRINTF("DEVKEY_TOTALSIZE -> Handshake error!\n");
1063  return -EIO;
1064  }
1065  if (cmdack.ack_status_ack || cmdack.comp_status) {
1066  DPRINTF("DEVKEY_TOTALSIZE -> Status error!\n");
1067  return -EIO;
1068  }
1069  bsize = (cmdack.return_result_word[0] << 16) + cmdack.return_result_word[1];
1070  if (bsize != 456)
1071  DPRINTF("Size of firmware is not equal to Size of buffer on DVRP memory.\n");
1072  DPRINTF("FSIZE:%08X\n", 456);
1073  DPRINTF("BSIZE:%08X\n", bsize);
1074  cmdack.command = 0x511C;
1075  ((u32 *)SBUF)[0] = *(u32 *)"XESD";
1076  byteswap_tmp2 = (int *)&SBUF[4];
1077  byteswap_tmp = (int *)arg;
1078  byteswap_tmp_end = (int *)((char *)arg + 448);
1079  do {
1080  byteswap_tmp2[0] = byteswap_tmp[0];
1081  byteswap_tmp2[1] = byteswap_tmp[1];
1082  byteswap_tmp2[2] = byteswap_tmp[2];
1083  byteswap_tmp2[3] = byteswap_tmp[3];
1084  byteswap_tmp += 4;
1085  byteswap_tmp2 += 4;
1086  } while (byteswap_tmp != byteswap_tmp_end);
1087  *byteswap_tmp2 = *byteswap_tmp;
1088  cmdack.input_word_count = 2;
1089  cmdack.input_word[0] = 0;
1090  cmdack.input_word[1] = 0;
1091  cmdack.input_buffer = &SBUF;
1092  cmdack.input_buffer_length = 456;
1093  cmdack.timeout = 10000000;
1094  cmdack_err3 = DvrdrvExecCmdAckDmaSendComp(&cmdack);
1095  DPRINTF("dvrcmd.ack_p[0]:%x\n", cmdack.ack_status_ack);
1096  if (cmdack_err3) {
1097  DPRINTF("MISCCMD_DEVKEY_DOWNLOAD -> Handshake error!\n");
1098  return -EIO;
1099  }
1100  if (cmdack.ack_status_ack) {
1101  DPRINTF("MISCCMD_DEVKEY_DOWNLOAD -> Status error!\n");
1102  return -EIO;
1103  }
1104  if (cmdack.comp_status) {
1105  DPRINTF("MISCCMD_DEVKEY_DOWNLOAD -> Status error!\n");
1106  return -EIO;
1107  }
1108  cmdack.command = 0x5119;
1109  cmdack.input_word_count = 0;
1110  cmdack.timeout = 10000000;
1111  cmdack_err2 = DvrdrvExecCmdAckComp(&cmdack);
1112  DPRINTF("dvrcmd.ack_p[0]:%x\n", cmdack.ack_status_ack);
1113  if (cmdack_err2) {
1114  DPRINTF("MISCCMD_SAVE_DEVKEY_INFO -> Handshake error!\n");
1115  return -EIO;
1116  }
1117  if (cmdack.ack_status_ack) {
1118  DPRINTF("MISCCMD_SAVE_DEVKEY_INFO -> Status error!\n");
1119  return -EADV;
1120  }
1121  if (cmdack.comp_status) {
1122  DPRINTF("MISCCMD_SAVE_DEVKEY_INFO -> Status error!\n");
1123  return -EIO;
1124  }
1125  return 0;
1126 }
1127 
1128 int dvrioctl2_get_device_key(
1129  iomanX_iop_file_t *a1,
1130  int cmd,
1131  void *arg,
1132  unsigned int arglen,
1133  void *buf,
1134  unsigned int buflen)
1135 {
1136  int v6;
1137  u16 *return_result_word;
1138  int busywait;
1139  drvdrv_exec_cmd_ack cmdack;
1140  u8 v27[8];
1141 
1142  (void)a1;
1143  (void)cmd;
1144  (void)arg;
1145  (void)arglen;
1146  (void)buflen;
1147 
1148  cmdack.command = 0x511A;
1149  cmdack.input_word[0] = 0;
1150  cmdack.input_word[1] = 4;
1151  cmdack.input_word_count = 2;
1152  cmdack.timeout = 15000000;
1153  if (DvrdrvExecCmdAckComp(&cmdack)) {
1154  DPRINTF("MISCCMD_GET_DEVKEY_INFO -> Handshake error!\n");
1155  return -EIO;
1156  }
1157  if (cmdack.ack_status_ack) {
1158  DPRINTF("MISCCMD_GET_DEVKEY_INFO -> Status error!\n");
1159  return -EADV;
1160  }
1161  if (cmdack.comp_status) {
1162  DPRINTF("MISCCMD_GET_DEVKEY_INFO -> Status error!\n");
1163  return -EIO;
1164  }
1165  v6 = 0;
1166  return_result_word = cmdack.return_result_word;
1167  do {
1168  u8 *v8;
1169  v8 = &v27[v6];
1170  v6 += 2;
1171  v8[0] = (*return_result_word & 0xFF00) >> 8;
1172  v8[1] = (*return_result_word & 0x00FF);
1173  return_result_word += 1;
1174  } while (v6 < 4);
1175  busywait = 2;
1176  do {
1177  } while (busywait-- >= 0);
1178  if (memcmp(v27, "XESD", 4) == 0) {
1179  int v13;
1180  u16 *in_word_tmp;
1181  u16 v17;
1182  int v18;
1183  int v19;
1184  unsigned int v20;
1185  v13 = 0;
1186  in_word_tmp = &cmdack.return_result_word[2];
1187  do {
1188  u8 *v15;
1189  v15 = (u8 *)buf + v13;
1190  v13 += 2;
1191  v15[0] = (*in_word_tmp & 0xFF00) >> 8;
1192  v15[1] = (*in_word_tmp & 0x00FF);
1193  in_word_tmp += 1;
1194  } while (v13 < 4);
1195  v17 = 4;
1196  v18 = 224;
1197  v19 = 0;
1198  v20 = 224;
1199  while (1) {
1200  int v21;
1201  int v22;
1202  v21 = v18;
1203  if (v20 >= 0x11)
1204  v21 = 16;
1205  cmdack.command = 0x511A;
1206  cmdack.input_word[0] = v17;
1207  cmdack.input_word[1] = v21;
1208  cmdack.input_word_count = 2;
1209  cmdack.timeout = 30000000;
1210  if (DvrdrvExecCmdAckComp(&cmdack)) {
1211  DPRINTF("MISCCMD_GET_DEVKEY_INFO -> Handshake error!\n");
1212  return -EIO;
1213  }
1214  if (cmdack.ack_status_ack) {
1215  DPRINTF("MISCCMD_GET_DEVKEY_INFO -> Status error!\n");
1216  return -EADV;
1217  }
1218  v22 = 1;
1219  if (cmdack.comp_status) {
1220  DPRINTF("MISCCMD_GET_DEVKEY_INFO -> Status error!\n");
1221  return -EIO;
1222  }
1223  if ((u16)v21 + 1 > 1) {
1224  u16 *in_word_tmp2;
1225  in_word_tmp2 = cmdack.return_result_word;
1226  do {
1227  u8 *v24;
1228  v24 = (u8 *)buf + v19;
1229  v19 += 2;
1230  v22 += 1;
1231  v24[4] = (*in_word_tmp2 & 0xFF00) >> 8;
1232  v24[5] = (*in_word_tmp2 & 0x00FF);
1233  in_word_tmp2 += 1;
1234  } while (v22 < (u16)v21 + 1);
1235  }
1236  v18 -= v21;
1237  v20 = (u16)v18;
1238  v17 += v21;
1239  if (!(u16)v18)
1240  return 0;
1241  }
1242  }
1243  return -EADV;
1244 }
1245 
1246 int dvrioctl2_set_dv_nodeid(
1247  iomanX_iop_file_t *a1,
1248  int cmd,
1249  void *arg,
1250  unsigned int arglen,
1251  void *buf,
1252  unsigned int buflen)
1253 {
1254  unsigned int argwalked;
1255  drvdrv_exec_cmd_ack cmdack;
1256 
1257  (void)a1;
1258  (void)cmd;
1259  (void)buf;
1260  (void)buflen;
1261 
1262  argwalked = 0;
1263  cmdack.command = 0x511D;
1264  if (arglen) {
1265  u8 *inword_tmp;
1266  inword_tmp = ((u8 *)&cmdack.input_word[0]);
1267  do {
1268  u8 *inword_tmp2;
1269  inword_tmp2 = ((u8 *)arg + argwalked);
1270  inword_tmp[0] = inword_tmp2[1];
1271  inword_tmp[1] = inword_tmp2[0];
1272  inword_tmp += 2;
1273  argwalked += 2;
1274  } while (argwalked < arglen);
1275  }
1276  cmdack.input_word_count = 4;
1277  cmdack.timeout = 10000000;
1278  if (DvrdrvExecCmdAckComp(&cmdack)) {
1279  DPRINTF("MISCCMD_SAVE_DV_NODEID -> Handshake error!\n");
1280  return -EIO;
1281  }
1282  if (cmdack.ack_status_ack) {
1283  DPRINTF("MISCCMD_SAVE_DV_NODEID -> Status error!\n");
1284  return -EADV;
1285  }
1286  if (cmdack.comp_status) {
1287  DPRINTF("MISCCMD_SAVE_DV_NODEID -> Status error!\n");
1288  return -EIO;
1289  }
1290  return 0;
1291 }
1292 
1293 int dvrioctl2_get_dv_nodeid(
1294  iomanX_iop_file_t *a1,
1295  int cmd,
1296  void *arg,
1297  unsigned int arglen,
1298  void *buf,
1299  unsigned int buflen)
1300 {
1301  unsigned int bufwalked;
1302  drvdrv_exec_cmd_ack cmdack;
1303 
1304  (void)a1;
1305  (void)cmd;
1306  (void)arg;
1307  (void)arglen;
1308 
1309  cmdack.command = 0x511E;
1310  cmdack.input_word_count = 0;
1311  cmdack.timeout = 15000000;
1312  if (DvrdrvExecCmdAckComp(&cmdack)) {
1313  DPRINTF("MISCCMD_GET_DV_NODEID -> Handshake error!\n");
1314  return -EIO;
1315  }
1316  if (cmdack.ack_status_ack) {
1317  DPRINTF("MISCCMD_GET_DV_NODEID -> Status error!\n");
1318  return -EADV;
1319  }
1320  if (cmdack.comp_status) {
1321  DPRINTF("MISCCMD_GET_DV_NODEID -> Status error!\n");
1322  return -EIO;
1323  }
1324  bufwalked = 0;
1325  if (buflen) {
1326  u16 *return_result_word;
1327  int bufbusyloop;
1328 
1329  return_result_word = cmdack.return_result_word;
1330  do {
1331  char *buftmp;
1332  buftmp = (char *)buf + bufwalked;
1333  bufwalked += 2;
1334  buftmp[0] = (*return_result_word & 0xFF00) >> 8;
1335  buftmp[1] = (*return_result_word & 0x00FF);
1336  return_result_word += 1;
1337  } while (bufwalked < buflen);
1338 
1339  bufbusyloop = 0;
1340  while ((unsigned int)(bufbusyloop++) < buflen)
1341  ;
1342  }
1343  return 0;
1344 }
1345 #ifdef DEBUG
1346 int test_count = 0;
1347 #endif
1348 int dvrioctl2_diag_test(
1349  iomanX_iop_file_t *a1,
1350  int cmd,
1351  void *arg,
1352  unsigned int arglen,
1353  void *buf,
1354  unsigned int buflen)
1355 {
1356  int cmdack_err;
1357 #ifdef DEBUG
1358  int testcnt_tmp;
1359 #endif
1360  int outbuf_cnt;
1361  u16 *outbuf_tmp;
1362  drvdrv_exec_cmd_ack cmdack;
1363 
1364  (void)a1;
1365  (void)cmd;
1366  (void)arglen;
1367  (void)buflen;
1368 
1369  cmdack.command = 0x511F;
1370  cmdack.input_word[0] = *(u16 *)arg;
1371  cmdack.input_word[1] = *((u16 *)arg + 1);
1372  cmdack.input_word[2] = *((u16 *)arg + 2);
1373  cmdack.input_word[3] = *((u16 *)arg + 3);
1374  cmdack.input_word[4] = *((u16 *)arg + 4);
1375  cmdack.input_word_count = 5;
1376  cmdack.timeout = 120000000;
1377  if (cmdack.input_word[2]) {
1378  DPRINTF("------------------- > SetTO:%d msec\n", 120000);
1379  cmdack.timeout = 10000000 * cmdack.input_word[2];
1380  }
1381  DPRINTF("arg : %4x", cmdack.input_word[0]);
1382  DPRINTF(" %4x", cmdack.input_word[1]);
1383  DPRINTF(" %4x ", cmdack.input_word[2]);
1384  DPRINTF(" SetTimeOutTo : %d usec\n", cmdack.timeout);
1385  cmdack_err = DvrdrvExecCmdAckComp(&cmdack);
1386 #ifdef DEBUG
1387  testcnt_tmp = test_count++;
1388 #endif
1389  DPRINTF(
1390  "cmd ID : %d -------------------- TEST VERSION - diag test -------------------- r %d -- c %d\n",
1391  31,
1392  cmdack_err,
1393  testcnt_tmp);
1394  DPRINTF("diag_test dvrcmd.ack_p[0]:%x\n", cmdack.ack_status_ack);
1395  DPRINTF("diag_test dvrcmd.phase:%x\n", cmdack.phase);
1396  if (cmdack_err) {
1397  DPRINTF("dvrioctl2_diag_test -> Handshake error!\n");
1398  return -EIO;
1399  }
1400  if (cmdack.ack_status_ack) {
1401  DPRINTF("dvrioctl2_diag_test -> Status error in ACK! param:%04x\n", cmdack.ack_status_ack);
1402  return -EADV;
1403  }
1404  if (cmdack.comp_status) {
1405  DPRINTF("dvrioctl2_diag_test -> Status error in COMP! param:%04x\n", cmdack.comp_status);
1406  return -EADV;
1407  }
1408  outbuf_cnt = 0;
1409  DPRINTF("---------------------------- return buffer\n");
1410  outbuf_tmp = (u16 *)&cmdack.return_result_word[0];
1411  do {
1412  outbuf_cnt += 1;
1413  DPRINTF(" %4x", *outbuf_tmp);
1414  *(u16 *)buf = *outbuf_tmp;
1415  outbuf_tmp += 1;
1416  buf = (char *)buf + 2;
1417  } while (outbuf_cnt < 16);
1418  DPRINTF("\n");
1419  return 0;
1420 }
1421 
1422 #ifdef DVRMISC_CFW_EXTENSIONS
1423 int dvrioctl2_cfw_ping(
1424  iomanX_iop_file_t *a1,
1425  int cmd,
1426  void *arg,
1427  unsigned int arglen,
1428  void *buf,
1429  unsigned int buflen)
1430 {
1431  drvdrv_exec_cmd_ack cmdack;
1432 
1433  cmdack.command = 0x5130;
1434  cmdack.input_word_count = 0;
1435  if (DvrdrvExecCmdAck(&cmdack)) {
1436  DPRINTF("dvrioctl2_cfw_ping -> Handshake error!\n");
1437  return -EIO;
1438  } else {
1439  if (cmdack.ack_status_ack) {
1440  DPRINTF("dvrioctl2_cfw_ping -> Status error!\n");
1441  return (int)(s16)cmdack.ack_status_ack;
1442  }
1443  }
1444  return 0;
1445 }
1446 
1447 int dvrioctl2_cfw_get_max_lba48(
1448  iomanX_iop_file_t *a1,
1449  int cmd,
1450  void *arg,
1451  unsigned int arglen,
1452  void *buf,
1453  unsigned int buflen)
1454 {
1455  drvdrv_exec_cmd_ack cmdack;
1456 
1457  if ((arglen < 2) || (buflen < 10)) {
1458  DPRINTF("dvrioctl2_cfw_get_max_lba48 -> invalid buffer length!\n");
1459  return -EINVAL;
1460  }
1461 
1462  cmdack.command = 0x5131;
1463  cmdack.input_word[0] = *(u16 *)arg;
1464  cmdack.input_word_count = 1;
1465  if (DvrdrvExecCmdAck(&cmdack)) {
1466  DPRINTF("dvrioctl2_cfw_get_max_lba48 -> Handshake error!\n");
1467  return -EIO;
1468  } else if (cmdack.ack_status_ack) {
1469  return (int)(s16)cmdack.ack_status_ack;
1470  } else {
1471  *(u16 *)buf = cmdack.output_word[0];
1472  *((u16 *)buf + 1) = cmdack.output_word[1];
1473  *((u16 *)buf + 2) = cmdack.output_word[2];
1474  *((u16 *)buf + 3) = cmdack.output_word[3];
1475  }
1476  return 0;
1477 }
1478 
1479 int dvrioctl2_cfw_mem_peek_poke(
1480  iomanX_iop_file_t *a1,
1481  int cmd,
1482  void *arg,
1483  unsigned int arglen,
1484  void *buf,
1485  unsigned int buflen)
1486 {
1487  drvdrv_exec_cmd_ack cmdack;
1488 
1489  if ((arglen < 14) || (buflen < 10)) {
1490  DPRINTF("dvrioctl2_cfw_mem_peek_poke -> invalid buffer length!\n");
1491  return -EINVAL;
1492  }
1493 
1494  cmdack.command = 0x5132;
1495  cmdack.input_word[0] = *(u16 *)arg;
1496  cmdack.input_word[1] = *((u16 *)arg + 1);
1497  cmdack.input_word[2] = *((u16 *)arg + 2);
1498  cmdack.input_word[3] = *((u16 *)arg + 3);
1499  cmdack.input_word[4] = *((u16 *)arg + 4);
1500  cmdack.input_word[5] = *((u16 *)arg + 5);
1501  cmdack.input_word[6] = *((u16 *)arg + 6);
1502  cmdack.input_word_count = 7;
1503  if (DvrdrvExecCmdAck(&cmdack)) {
1504  DPRINTF("dvrioctl2_cfw_mem_peek_poke -> Handshake error!\n");
1505  return -EIO;
1506  } else if (cmdack.ack_status_ack) {
1507  DPRINTF("dvrioctl2_cfw_mem_peek_poke -> Status error!\n");
1508  return (int)(s16)cmdack.ack_status_ack;
1509  } else {
1510  *(u16 *)buf = cmdack.output_word[0];
1511  *((u16 *)buf + 1) = cmdack.output_word[1];
1512  *((u16 *)buf + 2) = cmdack.output_word[2];
1513  *((u16 *)buf + 3) = cmdack.output_word[3];
1514  }
1515  return 0;
1516 }
1517 #endif
iomanX.h
_ModuleInfo::newflags
u16 newflags
Definition: loadcore.h:36
speedregs.h
IOP_DT_FSEXT
#define IOP_DT_FSEXT
Definition: iomanX.h:66
EUNSUP
#define EUNSUP
Definition: errno.h:117
thbase.h
iop_sema_t
Definition: thsemap.h:38
_iomanX_iop_file
Definition: iomanX.h:70
sysclib.h
EPERM
#define EPERM
Definition: errno.h:21
EADV
#define EADV
Definition: errno.h:151
EIO
#define EIO
Definition: errno.h:29
loadcore.h
ENOENT
#define ENOENT
Definition: errno.h:23
pvrdrv.h
_iomanX_iop_device_ops
Definition: iomanX.h:95
thsemap.h
_iomanX_iop_device
Definition: iomanX.h:81
stdio.h
EINVAL
#define EINVAL
Definition: errno.h:63
DevctlCmdTbl_t
Definition: xesdrv.c:198
_ModuleInfo
Definition: loadcore.h:31
errno.h